Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Unified Diff: third_party/WebKit/Source/core/editing/VisibleUnits.cpp

Issue 1636373002: Make associatedLayoutObjectOf() to handle ::first-letter pseudo-element correctly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-01-28T14:03:04 Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e45c27ce9e207c853062b2b555e161f6284c40bd 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -2171,28 +2171,30 @@ 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;
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.
+ ASSERT(layoutTextFragment->isRemainingTextLayoutObject());
tkent 2016/01/29 00:56:09 This ASSERT isn't helpful because layoutTextFragme
yosin_UTC9 2016/01/29 03:45:12 Done.
+ if (layoutTextFragment->fragmentLength() && static_cast<unsigned>(offsetInNode) >= layoutTextFragment->start())
+ return layoutObject;
+ LayoutObject* firstLetterLayoutObject = layoutTextFragment->firstLetterPseudoElement()->layoutObject();
tkent 2016/01/29 00:56:09 nullptr-check for firstLetterLayoutObject is remov
yosin_UTC9 2016/01/29 03:45:12 Yes, it is intentional. This case should not be ha
+ // 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)

Powered by Google App Engine
This is Rietveld 408576698