Chromium Code Reviews| Index: Source/core/dom/Position.cpp |
| diff --git a/Source/core/dom/Position.cpp b/Source/core/dom/Position.cpp |
| index 68fc3ac705d545b561cbff4d8e78c1867d51bd6c..48795ba2cc3fe38c8dfe31fb56a7c832f20020ec 100644 |
| --- a/Source/core/dom/Position.cpp |
| +++ b/Source/core/dom/Position.cpp |
| @@ -580,24 +580,26 @@ bool PositionAlgorithm<Strategy>::atEndOfTree() const |
| return !Strategy::parent(*anchorNode()) && m_offset >= lastOffsetForEditing(anchorNode()); |
| } |
| -template <typename Strategy> |
| -int PositionAlgorithm<Strategy>::renderedOffset() const |
| +static int renderedOffsetOf(const Position& position) |
| { |
| - if (!anchorNode()->isTextNode()) |
| - return m_offset; |
| + // TODO(yosin) We should compute offset for |AfterAnchor| and |
| + // |AfterChildren|. |
| + int offset = position.deprecatedOffset(); |
| + if (!position.anchorNode()->isTextNode()) |
| + return offset; |
| - if (!anchorNode()->layoutObject()) |
| - return m_offset; |
| + if (!position.anchorNode()->layoutObject()) |
| + return offset; |
| int result = 0; |
| - LayoutText* textLayoutObject = toLayoutText(anchorNode()->layoutObject()); |
| + LayoutText* textLayoutObject = toLayoutText(position.anchorNode()->layoutObject()); |
| for (InlineTextBox *box = textLayoutObject->firstTextBox(); box; box = box->nextTextBox()) { |
| int start = box->start(); |
| int end = box->start() + box->len(); |
| - if (m_offset < start) |
| + if (offset < start) |
| return result; |
| - if (m_offset <= end) { |
| - result += m_offset - start; |
| + if (offset <= end) { |
| + result += offset - start; |
| return result; |
| } |
| result += box->len(); |
| @@ -1055,17 +1057,16 @@ bool PositionAlgorithm<Strategy>::isRenderedCharacter() const |
| return false; |
| } |
| -template <typename Strategy> |
| -bool PositionAlgorithm<Strategy>::rendersInDifferentPosition(const PositionAlgorithm<Strategy> &pos) const |
| +bool rendersInDifferentPosition(const Position& position1, const Position& position2) |
| { |
| - if (isNull() || pos.isNull()) |
| + if (position1.isNull() || position2.isNull()) |
| return false; |
| - LayoutObject* layoutObject = anchorNode()->layoutObject(); |
| + LayoutObject* layoutObject = position1.anchorNode()->layoutObject(); |
| if (!layoutObject) |
| return false; |
| - LayoutObject* posLayoutObject = pos.anchorNode()->layoutObject(); |
| + LayoutObject* posLayoutObject = position2.anchorNode()->layoutObject(); |
| if (!posLayoutObject) |
| return false; |
| @@ -1073,49 +1074,49 @@ bool PositionAlgorithm<Strategy>::rendersInDifferentPosition(const PositionAlgor |
| || posLayoutObject->style()->visibility() != VISIBLE) |
| return false; |
| - if (anchorNode() == pos.anchorNode()) { |
| - if (isHTMLBRElement(*anchorNode())) |
| + if (position1.anchorNode() == position2.anchorNode()) { |
| + if (isHTMLBRElement(*position1.anchorNode())) |
| return false; |
| - if (m_offset == pos.deprecatedEditingOffset()) |
| + if (position1.deprecatedOffset() == position2.deprecatedEditingOffset()) |
|
tkent
2015/08/03 08:16:29
Comparing deprecatedOffset and deprecatedEditingOf
yosin_UTC9
2015/08/03 08:27:41
This patch simplify replaces |m_offset| to |deprec
|
| return false; |
| - if (!anchorNode()->isTextNode() && !pos.anchorNode()->isTextNode()) { |
| - if (m_offset != pos.deprecatedEditingOffset()) |
| + if (!position1.anchorNode()->isTextNode() && !position2.anchorNode()->isTextNode()) { |
| + if (position1.deprecatedOffset() != position2.deprecatedEditingOffset()) |
| return true; |
| } |
| } |
| - if (isHTMLBRElement(*anchorNode()) && pos.isCandidate()) |
| + if (isHTMLBRElement(*position1.anchorNode()) && position2.isCandidate()) |
| return true; |
| - if (isHTMLBRElement(*pos.anchorNode()) && isCandidate()) |
| + if (isHTMLBRElement(*position2.anchorNode()) && position1.isCandidate()) |
| return true; |
| - if (!inSameContainingBlockFlowElement(anchorNode(), pos.anchorNode())) |
| + if (!inSameContainingBlockFlowElement(position1.anchorNode(), position2.anchorNode())) |
| return true; |
| - if (anchorNode()->isTextNode() && !inRenderedText()) |
| + if (position1.anchorNode()->isTextNode() && !position1.inRenderedText()) |
| return false; |
| - if (pos.anchorNode()->isTextNode() && !pos.inRenderedText()) |
| + if (position2.anchorNode()->isTextNode() && !position2.inRenderedText()) |
| return false; |
| - int thisRenderedOffset = renderedOffset(); |
| - int posRenderedOffset = pos.renderedOffset(); |
| + int renderedOffset1 = renderedOffsetOf(position1); |
| + int renderedOffset2 = renderedOffsetOf(position2); |
| - if (layoutObject == posLayoutObject && thisRenderedOffset == posRenderedOffset) |
| + if (layoutObject == posLayoutObject && renderedOffset1 == renderedOffset2) |
| return false; |
| - InlineBoxPosition boxPosition1 = computeInlineBoxPosition(DOWNSTREAM); |
| - InlineBoxPosition boxPosition2 = pos.computeInlineBoxPosition(DOWNSTREAM); |
| + InlineBoxPosition boxPosition1 = position1.computeInlineBoxPosition(DOWNSTREAM); |
| + InlineBoxPosition boxPosition2 = position2.computeInlineBoxPosition(DOWNSTREAM); |
| WTF_LOG(Editing, "layoutObject: %p [%p]\n", layoutObject, boxPosition1.inlineBox); |
| - WTF_LOG(Editing, "thisRenderedOffset: %d\n", thisRenderedOffset); |
| + WTF_LOG(Editing, "renderedOffset1: %d\n", renderedOffset1); |
| WTF_LOG(Editing, "posLayoutObject: %p [%p]\n", posLayoutObject, boxPosition2.inlineBox); |
| - WTF_LOG(Editing, "posRenderedOffset: %d\n", posRenderedOffset); |
| - WTF_LOG(Editing, "node min/max: %d:%d\n", caretMinOffset(anchorNode()), caretMaxOffset(anchorNode())); |
| - WTF_LOG(Editing, "pos node min/max: %d:%d\n", caretMinOffset(pos.anchorNode()), caretMaxOffset(pos.anchorNode())); |
| + WTF_LOG(Editing, "renderedOffset2: %d\n", renderedOffset2); |
| + WTF_LOG(Editing, "node min/max: %d:%d\n", caretMinOffset(position1.anchorNode()), caretMaxOffset(position1.anchorNode())); |
| + WTF_LOG(Editing, "pos node min/max: %d:%d\n", caretMinOffset(position2.anchorNode()), caretMaxOffset(position2.anchorNode())); |
| WTF_LOG(Editing, "----------------------------------------------------------------------\n"); |
| if (!boxPosition1.inlineBox || !boxPosition2.inlineBox) { |
| @@ -1126,13 +1127,13 @@ bool PositionAlgorithm<Strategy>::rendersInDifferentPosition(const PositionAlgor |
| return true; |
| } |
| - if (nextRenderedEditable(anchorNode()) == pos.anchorNode() |
| - && thisRenderedOffset == caretMaxOffset(anchorNode()) && !posRenderedOffset) { |
| + if (nextRenderedEditable(position1.anchorNode()) == position2.anchorNode() |
| + && renderedOffset1 == caretMaxOffset(position1.anchorNode()) && !renderedOffset2) { |
| return false; |
| } |
| - if (previousRenderedEditable(anchorNode()) == pos.anchorNode() |
| - && !thisRenderedOffset && posRenderedOffset == caretMaxOffset(pos.anchorNode())) { |
| + if (previousRenderedEditable(position1.anchorNode()) == position2.anchorNode() |
| + && !renderedOffset1 && renderedOffset2 == caretMaxOffset(position2.anchorNode())) { |
| return false; |
| } |