Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2009 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 } | 573 } |
| 574 | 574 |
| 575 template <typename Strategy> | 575 template <typename Strategy> |
| 576 bool PositionAlgorithm<Strategy>::atEndOfTree() const | 576 bool PositionAlgorithm<Strategy>::atEndOfTree() const |
| 577 { | 577 { |
| 578 if (isNull()) | 578 if (isNull()) |
| 579 return true; | 579 return true; |
| 580 return !Strategy::parent(*anchorNode()) && m_offset >= lastOffsetForEditing( anchorNode()); | 580 return !Strategy::parent(*anchorNode()) && m_offset >= lastOffsetForEditing( anchorNode()); |
| 581 } | 581 } |
| 582 | 582 |
| 583 template <typename Strategy> | 583 static int renderedOffsetOf(const Position& position) |
| 584 int PositionAlgorithm<Strategy>::renderedOffset() const | |
| 585 { | 584 { |
| 586 if (!anchorNode()->isTextNode()) | 585 // TODO(yosin) We should compute offset for |AfterAnchor| and |
| 587 return m_offset; | 586 // |AfterChildren|. |
| 587 int offset = position.deprecatedOffset(); | |
| 588 if (!position.anchorNode()->isTextNode()) | |
| 589 return offset; | |
| 588 | 590 |
| 589 if (!anchorNode()->layoutObject()) | 591 if (!position.anchorNode()->layoutObject()) |
| 590 return m_offset; | 592 return offset; |
| 591 | 593 |
| 592 int result = 0; | 594 int result = 0; |
| 593 LayoutText* textLayoutObject = toLayoutText(anchorNode()->layoutObject()); | 595 LayoutText* textLayoutObject = toLayoutText(position.anchorNode()->layoutObj ect()); |
| 594 for (InlineTextBox *box = textLayoutObject->firstTextBox(); box; box = box-> nextTextBox()) { | 596 for (InlineTextBox *box = textLayoutObject->firstTextBox(); box; box = box-> nextTextBox()) { |
| 595 int start = box->start(); | 597 int start = box->start(); |
| 596 int end = box->start() + box->len(); | 598 int end = box->start() + box->len(); |
| 597 if (m_offset < start) | 599 if (offset < start) |
| 598 return result; | 600 return result; |
| 599 if (m_offset <= end) { | 601 if (offset <= end) { |
| 600 result += m_offset - start; | 602 result += offset - start; |
| 601 return result; | 603 return result; |
| 602 } | 604 } |
| 603 result += box->len(); | 605 result += box->len(); |
| 604 } | 606 } |
| 605 return result; | 607 return result; |
| 606 } | 608 } |
| 607 | 609 |
| 608 // Whether or not [node, 0] and [node, lastOffsetForEditing(node)] are their own VisiblePositions. | 610 // Whether or not [node, 0] and [node, lastOffsetForEditing(node)] are their own VisiblePositions. |
| 609 // If true, adjacent candidates are visually distinct. | 611 // If true, adjacent candidates are visually distinct. |
| 610 // FIXME: Disregard nodes with layoutObjects that have no height, as we do in is Candidate. | 612 // FIXME: Disregard nodes with layoutObjects that have no height, as we do in is Candidate. |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1048 // not laid out. Return false. | 1050 // not laid out. Return false. |
| 1049 return false; | 1051 return false; |
| 1050 } | 1052 } |
| 1051 if (m_offset >= static_cast<int>(box->start()) && m_offset < static_cast <int>(box->start() + box->len())) | 1053 if (m_offset >= static_cast<int>(box->start()) && m_offset < static_cast <int>(box->start() + box->len())) |
| 1052 return true; | 1054 return true; |
| 1053 } | 1055 } |
| 1054 | 1056 |
| 1055 return false; | 1057 return false; |
| 1056 } | 1058 } |
| 1057 | 1059 |
| 1058 template <typename Strategy> | 1060 bool rendersInDifferentPosition(const Position& position1, const Position& posit ion2) |
| 1059 bool PositionAlgorithm<Strategy>::rendersInDifferentPosition(const PositionAlgor ithm<Strategy> &pos) const | |
| 1060 { | 1061 { |
| 1061 if (isNull() || pos.isNull()) | 1062 if (position1.isNull() || position2.isNull()) |
| 1062 return false; | 1063 return false; |
| 1063 | 1064 |
| 1064 LayoutObject* layoutObject = anchorNode()->layoutObject(); | 1065 LayoutObject* layoutObject = position1.anchorNode()->layoutObject(); |
| 1065 if (!layoutObject) | 1066 if (!layoutObject) |
| 1066 return false; | 1067 return false; |
| 1067 | 1068 |
| 1068 LayoutObject* posLayoutObject = pos.anchorNode()->layoutObject(); | 1069 LayoutObject* posLayoutObject = position2.anchorNode()->layoutObject(); |
| 1069 if (!posLayoutObject) | 1070 if (!posLayoutObject) |
| 1070 return false; | 1071 return false; |
| 1071 | 1072 |
| 1072 if (layoutObject->style()->visibility() != VISIBLE | 1073 if (layoutObject->style()->visibility() != VISIBLE |
| 1073 || posLayoutObject->style()->visibility() != VISIBLE) | 1074 || posLayoutObject->style()->visibility() != VISIBLE) |
| 1074 return false; | 1075 return false; |
| 1075 | 1076 |
| 1076 if (anchorNode() == pos.anchorNode()) { | 1077 if (position1.anchorNode() == position2.anchorNode()) { |
| 1077 if (isHTMLBRElement(*anchorNode())) | 1078 if (isHTMLBRElement(*position1.anchorNode())) |
| 1078 return false; | 1079 return false; |
| 1079 | 1080 |
| 1080 if (m_offset == pos.deprecatedEditingOffset()) | 1081 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
| |
| 1081 return false; | 1082 return false; |
| 1082 | 1083 |
| 1083 if (!anchorNode()->isTextNode() && !pos.anchorNode()->isTextNode()) { | 1084 if (!position1.anchorNode()->isTextNode() && !position2.anchorNode()->is TextNode()) { |
| 1084 if (m_offset != pos.deprecatedEditingOffset()) | 1085 if (position1.deprecatedOffset() != position2.deprecatedEditingOffse t()) |
| 1085 return true; | 1086 return true; |
| 1086 } | 1087 } |
| 1087 } | 1088 } |
| 1088 | 1089 |
| 1089 if (isHTMLBRElement(*anchorNode()) && pos.isCandidate()) | 1090 if (isHTMLBRElement(*position1.anchorNode()) && position2.isCandidate()) |
| 1090 return true; | 1091 return true; |
| 1091 | 1092 |
| 1092 if (isHTMLBRElement(*pos.anchorNode()) && isCandidate()) | 1093 if (isHTMLBRElement(*position2.anchorNode()) && position1.isCandidate()) |
| 1093 return true; | 1094 return true; |
| 1094 | 1095 |
| 1095 if (!inSameContainingBlockFlowElement(anchorNode(), pos.anchorNode())) | 1096 if (!inSameContainingBlockFlowElement(position1.anchorNode(), position2.anch orNode())) |
| 1096 return true; | 1097 return true; |
| 1097 | 1098 |
| 1098 if (anchorNode()->isTextNode() && !inRenderedText()) | 1099 if (position1.anchorNode()->isTextNode() && !position1.inRenderedText()) |
| 1099 return false; | 1100 return false; |
| 1100 | 1101 |
| 1101 if (pos.anchorNode()->isTextNode() && !pos.inRenderedText()) | 1102 if (position2.anchorNode()->isTextNode() && !position2.inRenderedText()) |
| 1102 return false; | 1103 return false; |
| 1103 | 1104 |
| 1104 int thisRenderedOffset = renderedOffset(); | 1105 int renderedOffset1 = renderedOffsetOf(position1); |
| 1105 int posRenderedOffset = pos.renderedOffset(); | 1106 int renderedOffset2 = renderedOffsetOf(position2); |
| 1106 | 1107 |
| 1107 if (layoutObject == posLayoutObject && thisRenderedOffset == posRenderedOffs et) | 1108 if (layoutObject == posLayoutObject && renderedOffset1 == renderedOffset2) |
| 1108 return false; | 1109 return false; |
| 1109 | 1110 |
| 1110 InlineBoxPosition boxPosition1 = computeInlineBoxPosition(DOWNSTREAM); | 1111 InlineBoxPosition boxPosition1 = position1.computeInlineBoxPosition(DOWNSTRE AM); |
| 1111 InlineBoxPosition boxPosition2 = pos.computeInlineBoxPosition(DOWNSTREAM); | 1112 InlineBoxPosition boxPosition2 = position2.computeInlineBoxPosition(DOWNSTRE AM); |
| 1112 | 1113 |
| 1113 WTF_LOG(Editing, "layoutObject: %p [%p]\n", layoutObject, boxPosit ion1.inlineBox); | 1114 WTF_LOG(Editing, "layoutObject: %p [%p]\n", layoutObject, boxPosit ion1.inlineBox); |
| 1114 WTF_LOG(Editing, "thisRenderedOffset: %d\n", thisRenderedOffset); | 1115 WTF_LOG(Editing, "renderedOffset1: %d\n", renderedOffset1); |
| 1115 WTF_LOG(Editing, "posLayoutObject: %p [%p]\n", posLayoutObject, boxPo sition2.inlineBox); | 1116 WTF_LOG(Editing, "posLayoutObject: %p [%p]\n", posLayoutObject, boxPo sition2.inlineBox); |
| 1116 WTF_LOG(Editing, "posRenderedOffset: %d\n", posRenderedOffset); | 1117 WTF_LOG(Editing, "renderedOffset2: %d\n", renderedOffset2); |
| 1117 WTF_LOG(Editing, "node min/max: %d:%d\n", caretMinOffset(anchorNod e()), caretMaxOffset(anchorNode())); | 1118 WTF_LOG(Editing, "node min/max: %d:%d\n", caretMinOffset(position1 .anchorNode()), caretMaxOffset(position1.anchorNode())); |
| 1118 WTF_LOG(Editing, "pos node min/max: %d:%d\n", caretMinOffset(pos.ancho rNode()), caretMaxOffset(pos.anchorNode())); | 1119 WTF_LOG(Editing, "pos node min/max: %d:%d\n", caretMinOffset(position2 .anchorNode()), caretMaxOffset(position2.anchorNode())); |
| 1119 WTF_LOG(Editing, "---------------------------------------------------------- ------------\n"); | 1120 WTF_LOG(Editing, "---------------------------------------------------------- ------------\n"); |
| 1120 | 1121 |
| 1121 if (!boxPosition1.inlineBox || !boxPosition2.inlineBox) { | 1122 if (!boxPosition1.inlineBox || !boxPosition2.inlineBox) { |
| 1122 return false; | 1123 return false; |
| 1123 } | 1124 } |
| 1124 | 1125 |
| 1125 if (boxPosition1.inlineBox->root() != boxPosition2.inlineBox->root()) { | 1126 if (boxPosition1.inlineBox->root() != boxPosition2.inlineBox->root()) { |
| 1126 return true; | 1127 return true; |
| 1127 } | 1128 } |
| 1128 | 1129 |
| 1129 if (nextRenderedEditable(anchorNode()) == pos.anchorNode() | 1130 if (nextRenderedEditable(position1.anchorNode()) == position2.anchorNode() |
| 1130 && thisRenderedOffset == caretMaxOffset(anchorNode()) && !posRenderedOff set) { | 1131 && renderedOffset1 == caretMaxOffset(position1.anchorNode()) && !rendere dOffset2) { |
| 1131 return false; | 1132 return false; |
| 1132 } | 1133 } |
| 1133 | 1134 |
| 1134 if (previousRenderedEditable(anchorNode()) == pos.anchorNode() | 1135 if (previousRenderedEditable(position1.anchorNode()) == position2.anchorNode () |
| 1135 && !thisRenderedOffset && posRenderedOffset == caretMaxOffset(pos.anchor Node())) { | 1136 && !renderedOffset1 && renderedOffset2 == caretMaxOffset(position2.ancho rNode())) { |
| 1136 return false; | 1137 return false; |
| 1137 } | 1138 } |
| 1138 | 1139 |
| 1139 return true; | 1140 return true; |
| 1140 } | 1141 } |
| 1141 | 1142 |
| 1142 template <typename Strategy> | 1143 template <typename Strategy> |
| 1143 InlineBoxPosition PositionAlgorithm<Strategy>::computeInlineBoxPosition(EAffinit y affinity) const | 1144 InlineBoxPosition PositionAlgorithm<Strategy>::computeInlineBoxPosition(EAffinit y affinity) const |
| 1144 { | 1145 { |
| 1145 return computeInlineBoxPosition(affinity, primaryDirection()); | 1146 return computeInlineBoxPosition(affinity, primaryDirection()); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1552 | 1553 |
| 1553 void showTree(const blink::Position* pos) | 1554 void showTree(const blink::Position* pos) |
| 1554 { | 1555 { |
| 1555 if (pos) | 1556 if (pos) |
| 1556 pos->showTreeForThis(); | 1557 pos->showTreeForThis(); |
| 1557 else | 1558 else |
| 1558 fprintf(stderr, "Cannot showTree for (nil)\n"); | 1559 fprintf(stderr, "Cannot showTree for (nil)\n"); |
| 1559 } | 1560 } |
| 1560 | 1561 |
| 1561 #endif | 1562 #endif |
| OLD | NEW |