Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/VisibleUnits.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp |
| index 358c9b1ae37eaa29b6eab16bc94b8caa69b7b1c1..1dc372711f28c0413df1308baea10b38d3362fcd 100644 |
| --- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp |
| +++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp |
| @@ -2171,28 +2171,40 @@ VisiblePosition visiblePositionForContentsPoint(const IntPoint& contentsPoint, L |
| // TODO(yosin): We should use |associatedLayoutObjectOf()| in "VisibleUnits.cpp" |
| // where it takes |LayoutObject| from |Position|. |
| -static LayoutObject* associatedLayoutObjectOf(const Node& node, int offsetInNode) |
| +LayoutObject* associatedLayoutObjectOf(const Node& node, int offsetInNode) |
| { |
| ASSERT(offsetInNode >= 0); |
| LayoutObject* layoutObject = node.layoutObject(); |
| if (!node.isTextNode() || !layoutObject || !toLayoutText(layoutObject)->isTextFragment()) |
| return layoutObject; |
| + // ::first-letter pseudo element yields following layout objects. |
| + // |Text::layoutObject()| returns |LayoutTextFragment| for first-letter |
| + // patter, e.g. "B\n", or remaining part "abc". |
|
tkent
2016/01/29 03:52:16
patter -> part?
I don't understand what you mean
yosin_UTC9
2016/01/29 05:27:45
Add more explanation about first-letter.
|
| + // Note: Remaining part can be empty if all characters in first-letter, e.g. |
| + // "(a)". |
| + // LayoutBlockFlow {DIV} at (0,0) size 784x55 |
| + // LayoutInline {<pseudo:first-letter>} at (0,0) size 22x53 |
| + // LayoutTextFragment (anonymous) at (0,1) size 22x53 |
| + // text run at (0,1) width 22: "a" |
| + // LayoutTextFragment {#text} at (21,30) size 16x17 |
| + // text run at (21,30) width 16: "bc" |
| LayoutTextFragment* layoutTextFragment = toLayoutTextFragment(layoutObject); |
| - if (layoutTextFragment->isRemainingTextLayoutObject()) { |
| - if (static_cast<unsigned>(offsetInNode) >= layoutTextFragment->start()) |
| - return layoutObject; |
| - LayoutObject* firstLetterLayoutObject = layoutTextFragment->firstLetterPseudoElement()->layoutObject(); |
| - if (!firstLetterLayoutObject) |
| - return nullptr; |
| - // TODO(yosin): We're not sure when |firstLetterLayoutObject| has |
| - // multiple child layout object. |
| - ASSERT(firstLetterLayoutObject->slowFirstChild() == firstLetterLayoutObject->slowLastChild()); |
| - return firstLetterLayoutObject->slowFirstChild(); |
| - } |
| - // TODO(yosin): We should rename |LayoutTextFramge::length()| instead of |
| - // |end()|, once |LayoutTextFramge| has it. See http://crbug.com/545789 |
| - ASSERT(static_cast<unsigned>(offsetInNode) <= layoutTextFragment->start() + layoutTextFragment->fragmentLength()); |
| - return layoutTextFragment; |
| + if (!layoutTextFragment->isRemainingTextLayoutObject()) { |
| + // In case of there are no visible characters after first letter, e.g. |
| + // "B\n" |
| + ASSERT(static_cast<unsigned>(offsetInNode) <= layoutTextFragment->start() + layoutTextFragment->fragmentLength()); |
| + return layoutTextFragment; |
| + } |
| + // In case of |node| contains first-letter only, e.g. <div>"a" "bc"</div> |
| + // we have "a" is associated to |LayoutTextFragment| with |
| + // |isRemainingTextLayoutObject()| == true and |fragmentLength()| == 0. |
| + if (layoutTextFragment->fragmentLength() && static_cast<unsigned>(offsetInNode) >= layoutTextFragment->start()) |
| + return layoutObject; |
| + LayoutObject* firstLetterLayoutObject = layoutTextFragment->firstLetterPseudoElement()->layoutObject(); |
| + // TODO(yosin): We're not sure when |firstLetterLayoutObject| has |
| + // multiple child layout object. |
| + ASSERT(firstLetterLayoutObject->slowFirstChild() == firstLetterLayoutObject->slowLastChild()); |
| + return firstLetterLayoutObject->slowFirstChild(); |
| } |
| int caretMinOffset(const Node* node) |