39
39
40
40
namespace WebCore {
41
41
42
+ #if USE(APPLE_INTERNAL_SDK) && PLATFORM(MAC)
43
+ #import < WebKitAdditions/CaretRectComputationAdditions.cpp>
44
+ #else
45
+ int caretWidth ()
46
+ {
47
+ #if PLATFORM(IOS_FAMILY)
48
+ return 2 ; // This value should be kept in sync with UIKit. See <rdar://problem/15580601>.
49
+ #else
50
+ return 1 ;
51
+ #endif
52
+ }
53
+ #endif
54
+
42
55
static LayoutRect computeCaretRectForEmptyElement (const RenderBoxModelObject& renderer, LayoutUnit width, LayoutUnit textIndentOffset, CaretRectMode caretRectMode)
43
56
{
44
57
ASSERT (!renderer.firstChild () || renderer.firstChild ()->isPseudoElement ());
@@ -92,18 +105,18 @@ static LayoutRect computeCaretRectForEmptyElement(const RenderBoxModelObject& re
92
105
x -= textIndentOffset / 2 ;
93
106
break ;
94
107
case AlignRight:
95
- x = maxX - caretWidth;
108
+ x = maxX - caretWidth () ;
96
109
if (!currentStyle.isLeftToRightDirection ())
97
110
x -= textIndentOffset;
98
111
break ;
99
112
}
100
- x = std::min (x, std::max<LayoutUnit>(maxX - caretWidth, 0 ));
113
+ x = std::min (x, std::max<LayoutUnit>(maxX - caretWidth () , 0 ));
101
114
102
115
auto lineHeight = renderer.lineHeight (true , currentStyle.isHorizontalWritingMode () ? HorizontalLine : VerticalLine, PositionOfInteriorLineBoxes);
103
116
auto height = std::min (lineHeight, LayoutUnit { currentStyle.metricsOfPrimaryFont ().height () });
104
117
auto y = renderer.paddingTop () + renderer.borderTop () + (lineHeight > height ? (lineHeight - height) / 2 : LayoutUnit { });
105
118
106
- auto rect = LayoutRect (x, y, caretWidth, height);
119
+ auto rect = LayoutRect (x, y, caretWidth () , height);
107
120
108
121
if (caretRectMode == CaretRectMode::ExpandToEndOfLine)
109
122
rect.shiftMaxXEdgeTo (width);
@@ -121,9 +134,9 @@ static LayoutRect computeCaretRectForLinePosition(const InlineIterator::LineBoxI
121
134
122
135
// Distribute the caret's width to either side of the offset.
123
136
float left = logicalLeftPosition;
124
- int caretWidthLeftOfOffset = caretWidth / 2 ;
137
+ int caretWidthLeftOfOffset = caretWidth () / 2 ;
125
138
left -= caretWidthLeftOfOffset;
126
- int caretWidthRightOfOffset = caretWidth - caretWidthLeftOfOffset;
139
+ int caretWidthRightOfOffset = caretWidth () - caretWidthLeftOfOffset;
127
140
left = roundf (left);
128
141
129
142
float lineLeft = lineSelectionRect.x ();
@@ -154,13 +167,13 @@ static LayoutRect computeCaretRectForLinePosition(const InlineIterator::LineBoxI
154
167
155
168
if (rightAligned) {
156
169
left = std::max (left, leftEdge);
157
- left = std::min (left, lineRight - caretWidth);
170
+ left = std::min (left, lineRight - caretWidth () );
158
171
} else {
159
172
left = std::min (left, rightEdge - caretWidthRightOfOffset);
160
173
left = std::max (left, lineLeft);
161
174
}
162
175
163
- auto rect = IntRect (left, top, caretWidth, height);
176
+ auto rect = IntRect (left, top, caretWidth () , height);
164
177
165
178
if (caretRectMode == CaretRectMode::ExpandToEndOfLine)
166
179
rect.shiftMaxXEdgeTo (lineRight);
@@ -207,12 +220,12 @@ static LayoutRect computeCaretRectForSVGInlineText(const InlineBoxAndOffset& box
207
220
if (caretOffset < textBox.start () + textBox.len ()) {
208
221
LayoutRect rect = textBox.localSelectionRect (caretOffset, caretOffset + 1 );
209
222
LayoutUnit x = textBox.isLeftToRightDirection () ? rect.x () : rect.maxX ();
210
- return LayoutRect (x, rect.y (), caretWidth, rect.height ());
223
+ return LayoutRect (x, rect.y (), caretWidth () , rect.height ());
211
224
}
212
225
213
226
LayoutRect rect = textBox.localSelectionRect (caretOffset - 1 , caretOffset);
214
227
LayoutUnit x = textBox.isLeftToRightDirection () ? rect.maxX () : rect.x ();
215
- return { x, rect.y (), caretWidth, rect.height () };
228
+ return { x, rect.y (), caretWidth () , rect.height () };
216
229
}
217
230
218
231
static LayoutRect computeCaretRectForBox (const RenderBox& renderer, const InlineBoxAndOffset& boxAndOffset, CaretRectMode caretRectMode)
@@ -222,11 +235,11 @@ static LayoutRect computeCaretRectForBox(const RenderBox& renderer, const Inline
222
235
// They never refer to children.
223
236
// FIXME: Paint the carets inside empty blocks differently than the carets before/after elements.
224
237
225
- LayoutRect rect (renderer.location (), LayoutSize (caretWidth, renderer.height ()));
238
+ LayoutRect rect (renderer.location (), LayoutSize (caretWidth () , renderer.height ()));
226
239
bool ltr = boxAndOffset.box ? boxAndOffset.box ->isLeftToRightDirection () : renderer.style ().isLeftToRightDirection ();
227
240
228
241
if ((!boxAndOffset.offset ) ^ ltr)
229
- rect.move (LayoutSize (renderer.width () - caretWidth, 0_lu));
242
+ rect.move (LayoutSize (renderer.width () - caretWidth () , 0_lu));
230
243
231
244
if (boxAndOffset.box ) {
232
245
auto lineBox = boxAndOffset.box ->lineBox ();
0 commit comments