1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/**
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* (C) 2008 Torch Mobile Inc. All rights reserved.
* (http://www.torchmobile.com/)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "third_party/blink/renderer/core/layout/layout_text_control_multi_line.h"
#include "third_party/blink/renderer/core/html/forms/html_text_area_element.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h"
namespace blink {
LayoutTextControlMultiLine::LayoutTextControlMultiLine(
HTMLTextAreaElement* element)
: LayoutTextControl(element) {
DCHECK(element);
}
LayoutTextControlMultiLine::~LayoutTextControlMultiLine() = default;
bool LayoutTextControlMultiLine::NodeAtPoint(
HitTestResult& result,
const HitTestLocation& hit_test_location,
const PhysicalOffset& accumulated_offset,
HitTestAction hit_test_action) {
if (!LayoutTextControl::NodeAtPoint(result, hit_test_location,
accumulated_offset, hit_test_action))
return false;
const LayoutObject* stop_node = result.GetHitTestRequest().GetStopNode();
if (stop_node && stop_node->NodeForHitTest() == result.InnerNode())
return true;
if (result.InnerNode() == GetNode() ||
result.InnerNode() == InnerEditorElement())
HitInnerEditorElement(result, hit_test_location, accumulated_offset);
return true;
}
float LayoutTextControlMultiLine::GetAvgCharWidth(
const AtomicString& family) const {
// Match the default system font to the width of MS Shell Dlg, the default
// font for textareas in Firefox, Safari Win and IE for some encodings (in
// IE, the default font is encoding specific). 1229 is the avgCharWidth
// value in the OS/2 table for Courier New.
if (LayoutTheme::GetTheme().NeedsHackForTextControlWithFontFamily(family))
return ScaleEmToUnits(1229);
return LayoutTextControl::GetAvgCharWidth(family);
}
LayoutUnit LayoutTextControlMultiLine::PreferredContentLogicalWidth(
float char_width) const {
int factor = ToHTMLTextAreaElement(GetNode())->cols();
return static_cast<LayoutUnit>(ceilf(char_width * factor)) +
ScrollbarThickness();
}
LayoutUnit LayoutTextControlMultiLine::ComputeControlLogicalHeight(
LayoutUnit line_height,
LayoutUnit non_content_height) const {
return line_height * ToHTMLTextAreaElement(GetNode())->rows() +
non_content_height;
}
LayoutUnit LayoutTextControlMultiLine::BaselinePosition(
FontBaseline baseline_type,
bool first_line,
LineDirectionMode direction,
LinePositionMode line_position_mode) const {
return LayoutBox::BaselinePosition(baseline_type, first_line, direction,
line_position_mode);
}
LayoutObject* LayoutTextControlMultiLine::LayoutSpecialExcludedChild(
bool relayout_children,
SubtreeLayoutScope& layout_scope) {
LayoutObject* placeholder_layout_object =
LayoutTextControl::LayoutSpecialExcludedChild(relayout_children,
layout_scope);
if (!placeholder_layout_object)
return nullptr;
if (!placeholder_layout_object->IsBox())
return placeholder_layout_object;
LayoutBox* placeholder_box = ToLayoutBox(placeholder_layout_object);
placeholder_box->LayoutIfNeeded();
placeholder_box->SetX(BorderLeft() + PaddingLeft());
placeholder_box->SetY(BorderTop() + PaddingTop());
return placeholder_layout_object;
}
LayoutUnit LayoutTextControlMultiLine::ScrollWidth() const {
// If in preview state, fake the scroll width to prevent that any information
// about the suggested content can be derived from the size.
if (!GetTextControlElement()->SuggestedValue().IsEmpty())
return ClientWidth();
return LayoutTextControl::ScrollWidth();
}
LayoutUnit LayoutTextControlMultiLine::ScrollHeight() const {
// If in preview state, fake the scroll height to prevent that any information
// about the suggested content can be derived from the size.
if (!GetTextControlElement()->SuggestedValue().IsEmpty())
return ClientHeight();
return LayoutTextControl::ScrollHeight();
}
} // namespace blink
|