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

Side by Side Diff: Source/core/editing/VisibleSelection.cpp

Issue 1202153004: Enable selection for the composed tree (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rename the flag Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/VisibleSelection.h ('k') | Source/core/layout/LayoutView.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 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 didChange(); 152 didChange();
153 } 153 }
154 #endif 154 #endif
155 155
156 VisibleSelection VisibleSelection::selectionFromContentsOfNode(Node* node) 156 VisibleSelection VisibleSelection::selectionFromContentsOfNode(Node* node)
157 { 157 {
158 ASSERT(!editingIgnoresContent(node)); 158 ASSERT(!editingIgnoresContent(node));
159 return VisibleSelection(firstPositionInNode(node), lastPositionInNode(node), DOWNSTREAM); 159 return VisibleSelection(firstPositionInNode(node), lastPositionInNode(node), DOWNSTREAM);
160 } 160 }
161 161
162 SelectionType VisibleSelection::selectionTypeInComposedTree() const
163 {
164 return selectionType(m_startInComposedTree, m_endInComposedTree);
165 }
166
162 void VisibleSelection::setBase(const Position& position) 167 void VisibleSelection::setBase(const Position& position)
163 { 168 {
164 Position oldBase = m_base; 169 Position oldBase = m_base;
165 m_base = position; 170 m_base = position;
166 validate(); 171 validate();
167 if (m_base != oldBase) 172 if (m_base != oldBase)
168 didChange(); 173 didChange();
169 } 174 }
170 175
171 void VisibleSelection::setBase(const PositionInComposedTree& position) 176 void VisibleSelection::setBase(const PositionInComposedTree& position)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 Position oldBase = m_base; 347 Position oldBase = m_base;
343 Position oldExtent = m_extent; 348 Position oldExtent = m_extent;
344 Position oldStart = m_start; 349 Position oldStart = m_start;
345 Position oldEnd = m_end; 350 Position oldEnd = m_end;
346 validate(granularity); 351 validate(granularity);
347 if (m_base != oldBase || m_extent != oldExtent || m_start != oldStart || m_e nd != oldEnd) 352 if (m_base != oldBase || m_extent != oldExtent || m_start != oldStart || m_e nd != oldEnd)
348 didChange(); 353 didChange();
349 return true; 354 return true;
350 } 355 }
351 356
357 bool VisibleSelection::expandUsingGranularityInComposedTree(TextGranularity gran ularity)
358 {
359 m_base = toPositionInDOMTree(baseInComposedTree());
360 m_extent = toPositionInDOMTree(extentInComposedTree());
361 return expandUsingGranularity(granularity);
362 }
363
352 static PassRefPtrWillBeRawPtr<Range> makeSearchRange(const Position& pos) 364 static PassRefPtrWillBeRawPtr<Range> makeSearchRange(const Position& pos)
353 { 365 {
354 Node* node = pos.deprecatedNode(); 366 Node* node = pos.deprecatedNode();
355 if (!node) 367 if (!node)
356 return nullptr; 368 return nullptr;
357 Document& document = node->document(); 369 Document& document = node->document();
358 if (!document.documentElement()) 370 if (!document.documentElement())
359 return nullptr; 371 return nullptr;
360 Element* boundary = enclosingBlockFlowElement(*node); 372 Element* boundary = enclosingBlockFlowElement(*node);
361 if (!boundary) 373 if (!boundary)
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 { 604 {
593 if (start.isNull()) { 605 if (start.isNull()) {
594 ASSERT(end.isNull()); 606 ASSERT(end.isNull());
595 return NoSelection; 607 return NoSelection;
596 } 608 }
597 if (start == end || start.upstream() == end.upstream()) 609 if (start == end || start.upstream() == end.upstream())
598 return CaretSelection; 610 return CaretSelection;
599 return RangeSelection; 611 return RangeSelection;
600 } 612 }
601 613
614 SelectionType VisibleSelection::selectionType(const PositionInComposedTree& star t, const PositionInComposedTree& end)
615 {
616 if (start.isNull()) {
617 ASSERT(end.isNull());
618 return NoSelection;
619 }
620 if (start == end || start.upstream() == end.upstream())
621 return CaretSelection;
622 return RangeSelection;
623 }
624
602 void VisibleSelection::updateSelectionType() 625 void VisibleSelection::updateSelectionType()
603 { 626 {
604 m_selectionType = selectionType(m_start, m_end); 627 m_selectionType = selectionType(m_start, m_end);
605 628
606 // Affinity only makes sense for a caret 629 // Affinity only makes sense for a caret
607 if (m_selectionType != CaretSelection) 630 if (m_selectionType != CaretSelection)
608 m_affinity = DOWNSTREAM; 631 m_affinity = DOWNSTREAM;
609 } 632 }
610 633
611 static Node* enclosingShadowHost(Node* node) 634 static Node* enclosingShadowHost(Node* node)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } else { 789 } else {
767 m_start = extent; 790 m_start = extent;
768 m_end = base; 791 m_end = base;
769 } 792 }
770 m_selectionType = base == extent ? CaretSelection : RangeSelection; 793 m_selectionType = base == extent ? CaretSelection : RangeSelection;
771 m_startInComposedTree = toPositionInComposedTree(m_start); 794 m_startInComposedTree = toPositionInComposedTree(m_start);
772 m_endInComposedTree = toPositionInComposedTree(m_end); 795 m_endInComposedTree = toPositionInComposedTree(m_end);
773 didChange(); 796 didChange();
774 } 797 }
775 798
799 void VisibleSelection::setWithoutValidation(const PositionInComposedTree& base, const PositionInComposedTree& extent)
800 {
801 setWithoutValidation(toPositionInDOMTree(base), toPositionInDOMTree(extent)) ;
802 }
803
776 static PositionInComposedTree adjustPositionInComposedTreeForStart(const Positio nInComposedTree& position, Node* shadowHost) 804 static PositionInComposedTree adjustPositionInComposedTreeForStart(const Positio nInComposedTree& position, Node* shadowHost)
777 { 805 {
778 if (isEnclosedBy(position, *shadowHost)) { 806 if (isEnclosedBy(position, *shadowHost)) {
779 if (position.anchorType() == PositionInComposedTree::PositionIsBeforeChi ldren) 807 if (position.anchorType() == PositionInComposedTree::PositionIsBeforeChi ldren)
780 return PositionInComposedTree::beforeNode(shadowHost); 808 return PositionInComposedTree::beforeNode(shadowHost);
781 return PositionInComposedTree::afterNode(shadowHost); 809 return PositionInComposedTree::afterNode(shadowHost);
782 } 810 }
783 811
784 // We use |firstChild|'s after instead of beforeAllChildren for backward 812 // We use |firstChild|'s after instead of beforeAllChildren for backward
785 // compatibility. The positions are same but the anchors would be different, 813 // compatibility. The positions are same but the anchors would be different,
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 return PositionWithAffinity(); 1060 return PositionWithAffinity();
1033 1061
1034 FloatPoint absolutePoint = targetNode->layoutObject()->localToAbsolute(F loatPoint(selectionEndPoint)); 1062 FloatPoint absolutePoint = targetNode->layoutObject()->localToAbsolute(F loatPoint(selectionEndPoint));
1035 selectionEndPoint = roundedLayoutPoint(editableElement->layoutObject()-> absoluteToLocal(absolutePoint)); 1063 selectionEndPoint = roundedLayoutPoint(editableElement->layoutObject()-> absoluteToLocal(absolutePoint));
1036 targetNode = editableElement; 1064 targetNode = editableElement;
1037 } 1065 }
1038 1066
1039 return targetNode->layoutObject()->positionForPoint(selectionEndPoint); 1067 return targetNode->layoutObject()->positionForPoint(selectionEndPoint);
1040 } 1068 }
1041 1069
1042
1043 bool VisibleSelection::isContentEditable() const 1070 bool VisibleSelection::isContentEditable() const
1044 { 1071 {
1045 return isEditablePosition(start()); 1072 return isEditablePosition(start());
1046 } 1073 }
1047 1074
1048 bool VisibleSelection::hasEditableStyle() const 1075 bool VisibleSelection::hasEditableStyle() const
1049 { 1076 {
1050 return isEditablePosition(start(), ContentIsEditable, DoNotUpdateStyle); 1077 return isEditablePosition(start(), ContentIsEditable, DoNotUpdateStyle);
1051 } 1078 }
1052 1079
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 { 1151 {
1125 if (!isValidPosition(m_base) || !isValidPosition(m_extent) || !isValidPositi on(m_start) || !isValidPosition(m_end)) 1152 if (!isValidPosition(m_base) || !isValidPosition(m_extent) || !isValidPositi on(m_start) || !isValidPosition(m_end))
1126 validate(); 1153 validate();
1127 } 1154 }
1128 1155
1129 bool VisibleSelection::InDOMTree::equalSelections(const VisibleSelection& select ion1, const VisibleSelection& selection2) 1156 bool VisibleSelection::InDOMTree::equalSelections(const VisibleSelection& select ion1, const VisibleSelection& selection2)
1130 { 1157 {
1131 return selection1 == selection2; 1158 return selection1 == selection2;
1132 } 1159 }
1133 1160
1161 bool VisibleSelection::InComposedTree::equalSelections(const VisibleSelection& a , const VisibleSelection& b)
1162 {
1163 return a.startInComposedTree() == b.startInComposedTree() && a.endInComposed Tree() == b.endInComposedTree() && a.affinity() == b.affinity() && a.isBaseFirst () == b.isBaseFirst() && a.isDirectional() == b.isDirectional();
1164 }
1165
1134 #ifndef NDEBUG 1166 #ifndef NDEBUG
1135 1167
1136 void VisibleSelection::debugPosition(const char* message) const 1168 void VisibleSelection::debugPosition(const char* message) const
1137 { 1169 {
1138 fprintf(stderr, "VisibleSelection (%s) ===============\n", message); 1170 fprintf(stderr, "VisibleSelection (%s) ===============\n", message);
1139 1171
1140 if (m_baseIsFirst) { 1172 if (m_baseIsFirst) {
1141 m_start.debugPosition("start: "); 1173 m_start.debugPosition("start: ");
1142 m_base.debugPosition("base: "); 1174 m_base.debugPosition("base: ");
1143 m_end.debugPosition("end: "); 1175 m_end.debugPosition("end: ");
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 sel.showTreeForThis(); 1240 sel.showTreeForThis();
1209 } 1241 }
1210 1242
1211 void showTree(const blink::VisibleSelection* sel) 1243 void showTree(const blink::VisibleSelection* sel)
1212 { 1244 {
1213 if (sel) 1245 if (sel)
1214 sel->showTreeForThis(); 1246 sel->showTreeForThis();
1215 } 1247 }
1216 1248
1217 #endif 1249 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleSelection.h ('k') | Source/core/layout/LayoutView.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698