OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 | 40 |
41 static inline LayoutObject* rendererFromPosition(const Position& position) | 41 static inline LayoutObject* rendererFromPosition(const Position& position) |
42 { | 42 { |
43 ASSERT(position.isNotNull()); | 43 ASSERT(position.isNotNull()); |
44 Node* rendererNode = nullptr; | 44 Node* rendererNode = nullptr; |
45 switch (position.anchorType()) { | 45 switch (position.anchorType()) { |
46 case Position::PositionIsOffsetInAnchor: | 46 case Position::PositionIsOffsetInAnchor: |
47 rendererNode = position.computeNodeAfterPosition(); | 47 rendererNode = position.computeNodeAfterPosition(); |
48 if (!rendererNode || !rendererNode->renderer()) | 48 if (!rendererNode || !rendererNode->layoutObject()) |
49 rendererNode = position.anchorNode()->lastChild(); | 49 rendererNode = position.anchorNode()->lastChild(); |
50 break; | 50 break; |
51 | 51 |
52 case Position::PositionIsBeforeAnchor: | 52 case Position::PositionIsBeforeAnchor: |
53 case Position::PositionIsAfterAnchor: | 53 case Position::PositionIsAfterAnchor: |
54 break; | 54 break; |
55 | 55 |
56 case Position::PositionIsBeforeChildren: | 56 case Position::PositionIsBeforeChildren: |
57 rendererNode = position.anchorNode()->firstChild(); | 57 rendererNode = position.anchorNode()->firstChild(); |
58 break; | 58 break; |
59 case Position::PositionIsAfterChildren: | 59 case Position::PositionIsAfterChildren: |
60 rendererNode = position.anchorNode()->lastChild(); | 60 rendererNode = position.anchorNode()->lastChild(); |
61 break; | 61 break; |
62 } | 62 } |
63 if (!rendererNode || !rendererNode->renderer()) | 63 if (!rendererNode || !rendererNode->layoutObject()) |
64 rendererNode = position.anchorNode(); | 64 rendererNode = position.anchorNode(); |
65 return rendererNode->renderer(); | 65 return rendererNode->layoutObject(); |
66 } | 66 } |
67 | 67 |
68 RenderedPosition::RenderedPosition(const VisiblePosition& position) | 68 RenderedPosition::RenderedPosition(const VisiblePosition& position) |
69 : m_renderer(nullptr) | 69 : m_renderer(nullptr) |
70 , m_inlineBox(nullptr) | 70 , m_inlineBox(nullptr) |
71 , m_offset(0) | 71 , m_offset(0) |
72 , m_prevLeafChild(uncachedInlineBox()) | 72 , m_prevLeafChild(uncachedInlineBox()) |
73 , m_nextLeafChild(uncachedInlineBox()) | 73 , m_nextLeafChild(uncachedInlineBox()) |
74 { | 74 { |
75 if (position.isNull()) | 75 if (position.isNull()) |
76 return; | 76 return; |
77 position.getInlineBoxAndOffset(m_inlineBox, m_offset); | 77 position.getInlineBoxAndOffset(m_inlineBox, m_offset); |
78 if (m_inlineBox) | 78 if (m_inlineBox) |
79 m_renderer = &m_inlineBox->renderer(); | 79 m_renderer = &m_inlineBox->layoutObject(); |
80 else | 80 else |
81 m_renderer = rendererFromPosition(position.deepEquivalent()); | 81 m_renderer = rendererFromPosition(position.deepEquivalent()); |
82 } | 82 } |
83 | 83 |
84 RenderedPosition::RenderedPosition(const Position& position, EAffinity affinity) | 84 RenderedPosition::RenderedPosition(const Position& position, EAffinity affinity) |
85 : m_renderer(nullptr) | 85 : m_renderer(nullptr) |
86 , m_inlineBox(nullptr) | 86 , m_inlineBox(nullptr) |
87 , m_offset(0) | 87 , m_offset(0) |
88 , m_prevLeafChild(uncachedInlineBox()) | 88 , m_prevLeafChild(uncachedInlineBox()) |
89 , m_nextLeafChild(uncachedInlineBox()) | 89 , m_nextLeafChild(uncachedInlineBox()) |
90 { | 90 { |
91 if (position.isNull()) | 91 if (position.isNull()) |
92 return; | 92 return; |
93 position.getInlineBoxAndOffset(affinity, m_inlineBox, m_offset); | 93 position.getInlineBoxAndOffset(affinity, m_inlineBox, m_offset); |
94 if (m_inlineBox) | 94 if (m_inlineBox) |
95 m_renderer = &m_inlineBox->renderer(); | 95 m_renderer = &m_inlineBox->layoutObject(); |
96 else | 96 else |
97 m_renderer = rendererFromPosition(position); | 97 m_renderer = rendererFromPosition(position); |
98 } | 98 } |
99 | 99 |
100 InlineBox* RenderedPosition::prevLeafChild() const | 100 InlineBox* RenderedPosition::prevLeafChild() const |
101 { | 101 { |
102 if (m_prevLeafChild == uncachedInlineBox()) | 102 if (m_prevLeafChild == uncachedInlineBox()) |
103 m_prevLeafChild = m_inlineBox->prevLeafChildIgnoringLineBreak(); | 103 m_prevLeafChild = m_inlineBox->prevLeafChildIgnoringLineBreak(); |
104 return m_prevLeafChild; | 104 return m_prevLeafChild; |
105 } | 105 } |
(...skipping 26 matching lines...) Expand all Loading... |
132 | 132 |
133 RenderedPosition RenderedPosition::leftBoundaryOfBidiRun(unsigned char bidiLevel
OfRun) | 133 RenderedPosition RenderedPosition::leftBoundaryOfBidiRun(unsigned char bidiLevel
OfRun) |
134 { | 134 { |
135 if (!m_inlineBox || bidiLevelOfRun > m_inlineBox->bidiLevel()) | 135 if (!m_inlineBox || bidiLevelOfRun > m_inlineBox->bidiLevel()) |
136 return RenderedPosition(); | 136 return RenderedPosition(); |
137 | 137 |
138 InlineBox* box = m_inlineBox; | 138 InlineBox* box = m_inlineBox; |
139 do { | 139 do { |
140 InlineBox* prev = box->prevLeafChildIgnoringLineBreak(); | 140 InlineBox* prev = box->prevLeafChildIgnoringLineBreak(); |
141 if (!prev || prev->bidiLevel() < bidiLevelOfRun) | 141 if (!prev || prev->bidiLevel() < bidiLevelOfRun) |
142 return RenderedPosition(&box->renderer(), box, box->caretLeftmostOff
set()); | 142 return RenderedPosition(&box->layoutObject(), box, box->caretLeftmos
tOffset()); |
143 box = prev; | 143 box = prev; |
144 } while (box); | 144 } while (box); |
145 | 145 |
146 ASSERT_NOT_REACHED(); | 146 ASSERT_NOT_REACHED(); |
147 return RenderedPosition(); | 147 return RenderedPosition(); |
148 } | 148 } |
149 | 149 |
150 RenderedPosition RenderedPosition::rightBoundaryOfBidiRun(unsigned char bidiLeve
lOfRun) | 150 RenderedPosition RenderedPosition::rightBoundaryOfBidiRun(unsigned char bidiLeve
lOfRun) |
151 { | 151 { |
152 if (!m_inlineBox || bidiLevelOfRun > m_inlineBox->bidiLevel()) | 152 if (!m_inlineBox || bidiLevelOfRun > m_inlineBox->bidiLevel()) |
153 return RenderedPosition(); | 153 return RenderedPosition(); |
154 | 154 |
155 InlineBox* box = m_inlineBox; | 155 InlineBox* box = m_inlineBox; |
156 do { | 156 do { |
157 InlineBox* next = box->nextLeafChildIgnoringLineBreak(); | 157 InlineBox* next = box->nextLeafChildIgnoringLineBreak(); |
158 if (!next || next->bidiLevel() < bidiLevelOfRun) | 158 if (!next || next->bidiLevel() < bidiLevelOfRun) |
159 return RenderedPosition(&box->renderer(), box, box->caretRightmostOf
fset()); | 159 return RenderedPosition(&box->layoutObject(), box, box->caretRightmo
stOffset()); |
160 box = next; | 160 box = next; |
161 } while (box); | 161 } while (box); |
162 | 162 |
163 ASSERT_NOT_REACHED(); | 163 ASSERT_NOT_REACHED(); |
164 return RenderedPosition(); | 164 return RenderedPosition(); |
165 } | 165 } |
166 | 166 |
167 bool RenderedPosition::atLeftBoundaryOfBidiRun(ShouldMatchBidiLevel shouldMatchB
idiLevel, unsigned char bidiLevelOfRun) const | 167 bool RenderedPosition::atLeftBoundaryOfBidiRun(ShouldMatchBidiLevel shouldMatchB
idiLevel, unsigned char bidiLevelOfRun) const |
168 { | 168 { |
169 if (!m_inlineBox) | 169 if (!m_inlineBox) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 return false; | 204 return false; |
205 } | 205 } |
206 | 206 |
207 Position RenderedPosition::positionAtLeftBoundaryOfBiDiRun() const | 207 Position RenderedPosition::positionAtLeftBoundaryOfBiDiRun() const |
208 { | 208 { |
209 ASSERT(atLeftBoundaryOfBidiRun()); | 209 ASSERT(atLeftBoundaryOfBidiRun()); |
210 | 210 |
211 if (atLeftmostOffsetInBox()) | 211 if (atLeftmostOffsetInBox()) |
212 return createLegacyEditingPosition(m_renderer->node(), m_offset); | 212 return createLegacyEditingPosition(m_renderer->node(), m_offset); |
213 | 213 |
214 return createLegacyEditingPosition(nextLeafChild()->renderer().node(), nextL
eafChild()->caretLeftmostOffset()); | 214 return createLegacyEditingPosition(nextLeafChild()->layoutObject().node(), n
extLeafChild()->caretLeftmostOffset()); |
215 } | 215 } |
216 | 216 |
217 Position RenderedPosition::positionAtRightBoundaryOfBiDiRun() const | 217 Position RenderedPosition::positionAtRightBoundaryOfBiDiRun() const |
218 { | 218 { |
219 ASSERT(atRightBoundaryOfBidiRun()); | 219 ASSERT(atRightBoundaryOfBidiRun()); |
220 | 220 |
221 if (atRightmostOffsetInBox()) | 221 if (atRightmostOffsetInBox()) |
222 return createLegacyEditingPosition(m_renderer->node(), m_offset); | 222 return createLegacyEditingPosition(m_renderer->node(), m_offset); |
223 | 223 |
224 return createLegacyEditingPosition(prevLeafChild()->renderer().node(), prevL
eafChild()->caretRightmostOffset()); | 224 return createLegacyEditingPosition(prevLeafChild()->layoutObject().node(), p
revLeafChild()->caretRightmostOffset()); |
225 } | 225 } |
226 | 226 |
227 IntRect RenderedPosition::absoluteRect(LayoutUnit* extraWidthToEndOfLine) const | 227 IntRect RenderedPosition::absoluteRect(LayoutUnit* extraWidthToEndOfLine) const |
228 { | 228 { |
229 if (isNull()) | 229 if (isNull()) |
230 return IntRect(); | 230 return IntRect(); |
231 | 231 |
232 IntRect localRect = pixelSnappedIntRect(m_renderer->localCaretRect(m_inlineB
ox, m_offset, extraWidthToEndOfLine)); | 232 IntRect localRect = pixelSnappedIntRect(m_renderer->localCaretRect(m_inlineB
ox, m_offset, extraWidthToEndOfLine)); |
233 return localRect == IntRect() ? IntRect() : m_renderer->localToAbsoluteQuad(
FloatRect(localRect)).enclosingBoundingBox(); | 233 return localRect == IntRect() ? IntRect() : m_renderer->localToAbsoluteQuad(
FloatRect(localRect)).enclosingBoundingBox(); |
234 } | 234 } |
(...skipping 16 matching lines...) Expand all Loading... |
251 bool layoutObjectContainsPosition(LayoutObject* target, const Position& position
) | 251 bool layoutObjectContainsPosition(LayoutObject* target, const Position& position
) |
252 { | 252 { |
253 for (LayoutObject* renderer = rendererFromPosition(position); renderer && re
nderer->node(); renderer = renderer->parent()) { | 253 for (LayoutObject* renderer = rendererFromPosition(position); renderer && re
nderer->node(); renderer = renderer->parent()) { |
254 if (renderer == target) | 254 if (renderer == target) |
255 return true; | 255 return true; |
256 } | 256 } |
257 return false; | 257 return false; |
258 } | 258 } |
259 | 259 |
260 }; | 260 }; |
OLD | NEW |