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

Side by Side Diff: Source/core/dom/Position.cpp

Issue 1270023002: CANCEL Untemplatize PositionAlgorithm<Strategy>::rendersInDifferentPosition() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-03T14:53:18 Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « Source/core/dom/Position.h ('k') | Source/core/editing/CompositeEditCommand.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // TODO(yosin) I'm not sure why do we compare
yoichio 2015/08/03 06:19:57 This is not good comment. You should be sure or th
yosin_UTC9 2015/08/03 06:44:06 Done.
1082 // |deprecatedOffset()| and |deprecatedEditingOffset()|.
1083 if (position1.deprecatedOffset() == position2.deprecatedEditingOffset())
1081 return false; 1084 return false;
1082 1085
1083 if (!anchorNode()->isTextNode() && !pos.anchorNode()->isTextNode()) { 1086 if (!position1.anchorNode()->isTextNode() && !position2.anchorNode()->is TextNode()) {
1084 if (m_offset != pos.deprecatedEditingOffset()) 1087 // TODO(yosin) I'm not sure why do we compare
1088 // |deprecatedOffset()| and |deprecatedEditingOffset()|.
1089 if (position1.deprecatedOffset() != position2.deprecatedEditingOffse t())
1085 return true; 1090 return true;
1086 } 1091 }
1087 } 1092 }
1088 1093
1089 if (isHTMLBRElement(*anchorNode()) && pos.isCandidate()) 1094 if (isHTMLBRElement(*position1.anchorNode()) && position2.isCandidate())
1090 return true; 1095 return true;
1091 1096
1092 if (isHTMLBRElement(*pos.anchorNode()) && isCandidate()) 1097 if (isHTMLBRElement(*position2.anchorNode()) && position1.isCandidate())
1093 return true; 1098 return true;
1094 1099
1095 if (!inSameContainingBlockFlowElement(anchorNode(), pos.anchorNode())) 1100 if (!inSameContainingBlockFlowElement(position1.anchorNode(), position2.anch orNode()))
1096 return true; 1101 return true;
1097 1102
1098 if (anchorNode()->isTextNode() && !inRenderedText()) 1103 if (position1.anchorNode()->isTextNode() && !position1.inRenderedText())
1099 return false; 1104 return false;
1100 1105
1101 if (pos.anchorNode()->isTextNode() && !pos.inRenderedText()) 1106 if (position2.anchorNode()->isTextNode() && !position2.inRenderedText())
1102 return false; 1107 return false;
1103 1108
1104 int thisRenderedOffset = renderedOffset(); 1109 int renderedOffset1 = renderedOffsetOf(position1);
1105 int posRenderedOffset = pos.renderedOffset(); 1110 int renderedOffset2 = renderedOffsetOf(position2);
1106 1111
1107 if (layoutObject == posLayoutObject && thisRenderedOffset == posRenderedOffs et) 1112 if (layoutObject == posLayoutObject && renderedOffset1 == renderedOffset2)
1108 return false; 1113 return false;
1109 1114
1110 InlineBoxPosition boxPosition1 = computeInlineBoxPosition(DOWNSTREAM); 1115 InlineBoxPosition boxPosition1 = position1.computeInlineBoxPosition(DOWNSTRE AM);
1111 InlineBoxPosition boxPosition2 = pos.computeInlineBoxPosition(DOWNSTREAM); 1116 InlineBoxPosition boxPosition2 = position2.computeInlineBoxPosition(DOWNSTRE AM);
1112 1117
1113 WTF_LOG(Editing, "layoutObject: %p [%p]\n", layoutObject, boxPosit ion1.inlineBox); 1118 WTF_LOG(Editing, "layoutObject: %p [%p]\n", layoutObject, boxPosit ion1.inlineBox);
1114 WTF_LOG(Editing, "thisRenderedOffset: %d\n", thisRenderedOffset); 1119 WTF_LOG(Editing, "renderedOffset1: %d\n", renderedOffset1);
1115 WTF_LOG(Editing, "posLayoutObject: %p [%p]\n", posLayoutObject, boxPo sition2.inlineBox); 1120 WTF_LOG(Editing, "posLayoutObject: %p [%p]\n", posLayoutObject, boxPo sition2.inlineBox);
1116 WTF_LOG(Editing, "posRenderedOffset: %d\n", posRenderedOffset); 1121 WTF_LOG(Editing, "renderedOffset2: %d\n", renderedOffset2);
1117 WTF_LOG(Editing, "node min/max: %d:%d\n", caretMinOffset(anchorNod e()), caretMaxOffset(anchorNode())); 1122 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())); 1123 WTF_LOG(Editing, "pos node min/max: %d:%d\n", caretMinOffset(position2 .anchorNode()), caretMaxOffset(position2.anchorNode()));
1119 WTF_LOG(Editing, "---------------------------------------------------------- ------------\n"); 1124 WTF_LOG(Editing, "---------------------------------------------------------- ------------\n");
1120 1125
1121 if (!boxPosition1.inlineBox || !boxPosition2.inlineBox) { 1126 if (!boxPosition1.inlineBox || !boxPosition2.inlineBox) {
1122 return false; 1127 return false;
1123 } 1128 }
1124 1129
1125 if (boxPosition1.inlineBox->root() != boxPosition2.inlineBox->root()) { 1130 if (boxPosition1.inlineBox->root() != boxPosition2.inlineBox->root()) {
1126 return true; 1131 return true;
1127 } 1132 }
1128 1133
1129 if (nextRenderedEditable(anchorNode()) == pos.anchorNode() 1134 if (nextRenderedEditable(position1.anchorNode()) == position2.anchorNode()
1130 && thisRenderedOffset == caretMaxOffset(anchorNode()) && !posRenderedOff set) { 1135 && renderedOffset1 == caretMaxOffset(position1.anchorNode()) && !rendere dOffset2) {
1131 return false; 1136 return false;
1132 } 1137 }
1133 1138
1134 if (previousRenderedEditable(anchorNode()) == pos.anchorNode() 1139 if (previousRenderedEditable(position1.anchorNode()) == position2.anchorNode ()
1135 && !thisRenderedOffset && posRenderedOffset == caretMaxOffset(pos.anchor Node())) { 1140 && !renderedOffset1 && renderedOffset2 == caretMaxOffset(position2.ancho rNode())) {
1136 return false; 1141 return false;
1137 } 1142 }
1138 1143
1139 return true; 1144 return true;
1140 } 1145 }
1141 1146
1142 template <typename Strategy> 1147 template <typename Strategy>
1143 InlineBoxPosition PositionAlgorithm<Strategy>::computeInlineBoxPosition(EAffinit y affinity) const 1148 InlineBoxPosition PositionAlgorithm<Strategy>::computeInlineBoxPosition(EAffinit y affinity) const
1144 { 1149 {
1145 return computeInlineBoxPosition(affinity, primaryDirection()); 1150 return computeInlineBoxPosition(affinity, primaryDirection());
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 1557
1553 void showTree(const blink::Position* pos) 1558 void showTree(const blink::Position* pos)
1554 { 1559 {
1555 if (pos) 1560 if (pos)
1556 pos->showTreeForThis(); 1561 pos->showTreeForThis();
1557 else 1562 else
1558 fprintf(stderr, "Cannot showTree for (nil)\n"); 1563 fprintf(stderr, "Cannot showTree for (nil)\n");
1559 } 1564 }
1560 1565
1561 #endif 1566 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Position.h ('k') | Source/core/editing/CompositeEditCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698