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

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 1675163002: Rename ComposedTree to FlatTree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip Created 4 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 { 111 {
112 } 112 }
113 113
114 template <> 114 template <>
115 VisiblePosition FrameSelection::originalBase<EditingStrategy>() const 115 VisiblePosition FrameSelection::originalBase<EditingStrategy>() const
116 { 116 {
117 return m_originalBase; 117 return m_originalBase;
118 } 118 }
119 119
120 template <> 120 template <>
121 VisiblePositionInComposedTree FrameSelection::originalBase<EditingInComposedTree Strategy>() const 121 VisiblePositionInFlatTree FrameSelection::originalBase<EditingInFlatTreeStrategy >() const
122 { 122 {
123 return m_originalBaseInComposedTree; 123 return m_originalBaseInFlatTree;
124 } 124 }
125 125
126 // TODO(yosin): To avoid undefined symbols in clang, we explicitly 126 // TODO(yosin): To avoid undefined symbols in clang, we explicitly
127 // have specialized version of |FrameSelection::visibleSelection<Strategy>| 127 // have specialized version of |FrameSelection::visibleSelection<Strategy>|
128 // before |FrameSelection::selection()| which refers this. 128 // before |FrameSelection::selection()| which refers this.
129 template <> 129 template <>
130 const VisibleSelection& FrameSelection::visibleSelection<EditingStrategy>() cons t 130 const VisibleSelection& FrameSelection::visibleSelection<EditingStrategy>() cons t
131 { 131 {
132 return m_selectionEditor->visibleSelection<EditingStrategy>(); 132 return m_selectionEditor->visibleSelection<EditingStrategy>();
133 } 133 }
134 134
135 template <> 135 template <>
136 const VisibleSelectionInComposedTree& FrameSelection::visibleSelection<EditingIn ComposedTreeStrategy>() const 136 const VisibleSelectionInFlatTree& FrameSelection::visibleSelection<EditingInFlat TreeStrategy>() const
137 { 137 {
138 return m_selectionEditor->visibleSelection<EditingInComposedTreeStrategy>(); 138 return m_selectionEditor->visibleSelection<EditingInFlatTreeStrategy>();
139 } 139 }
140 140
141 Element* FrameSelection::rootEditableElementOrDocumentElement() const 141 Element* FrameSelection::rootEditableElementOrDocumentElement() const
142 { 142 {
143 Element* selectionRoot = selection().rootEditableElement(); 143 Element* selectionRoot = selection().rootEditableElement();
144 return selectionRoot ? selectionRoot : m_frame->document()->documentElement( ); 144 return selectionRoot ? selectionRoot : m_frame->document()->documentElement( );
145 } 145 }
146 146
147 ContainerNode* FrameSelection::rootEditableElementOrTreeScopeRootNode() const 147 ContainerNode* FrameSelection::rootEditableElementOrTreeScopeRootNode() const
148 { 148 {
149 Element* selectionRoot = selection().rootEditableElement(); 149 Element* selectionRoot = selection().rootEditableElement();
150 if (selectionRoot) 150 if (selectionRoot)
151 return selectionRoot; 151 return selectionRoot;
152 152
153 Node* node = selection().base().computeContainerNode(); 153 Node* node = selection().base().computeContainerNode();
154 return node ? &node->treeScope().rootNode() : 0; 154 return node ? &node->treeScope().rootNode() : 0;
155 } 155 }
156 156
157 const VisibleSelection& FrameSelection::selection() const 157 const VisibleSelection& FrameSelection::selection() const
158 { 158 {
159 return visibleSelection<EditingStrategy>(); 159 return visibleSelection<EditingStrategy>();
160 } 160 }
161 161
162 const VisibleSelectionInComposedTree& FrameSelection::selectionInComposedTree() const 162 const VisibleSelectionInFlatTree& FrameSelection::selectionInFlatTree() const
163 { 163 {
164 return visibleSelection<EditingInComposedTreeStrategy>(); 164 return visibleSelection<EditingInFlatTreeStrategy>();
165 } 165 }
166 166
167 void FrameSelection::moveTo(const VisiblePosition &pos, EUserTriggered userTrigg ered, CursorAlignOnScroll align) 167 void FrameSelection::moveTo(const VisiblePosition &pos, EUserTriggered userTrigg ered, CursorAlignOnScroll align)
168 { 168 {
169 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered ; 169 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered ;
170 setSelection(VisibleSelection(pos, pos, selection().isDirectional()), option s, align); 170 setSelection(VisibleSelection(pos, pos, selection().isDirectional()), option s, align);
171 } 171 }
172 172
173 void FrameSelection::moveTo(const VisiblePosition &base, const VisiblePosition & extent, EUserTriggered userTriggered) 173 void FrameSelection::moveTo(const VisiblePosition &base, const VisiblePosition & extent, EUserTriggered userTriggered)
174 { 174 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return; 252 return;
253 253
254 setSelection(newSelection, granularity); 254 setSelection(newSelection, granularity);
255 } 255 }
256 256
257 void FrameSelection::setNonDirectionalSelectionIfNeeded(const VisibleSelection& passedNewSelection, TextGranularity granularity, EndPointsAdjustmentMode endpoin tsAdjustmentMode) 257 void FrameSelection::setNonDirectionalSelectionIfNeeded(const VisibleSelection& passedNewSelection, TextGranularity granularity, EndPointsAdjustmentMode endpoin tsAdjustmentMode)
258 { 258 {
259 setNonDirectionalSelectionIfNeededAlgorithm<EditingStrategy>(passedNewSelect ion, granularity, endpointsAdjustmentMode); 259 setNonDirectionalSelectionIfNeededAlgorithm<EditingStrategy>(passedNewSelect ion, granularity, endpointsAdjustmentMode);
260 } 260 }
261 261
262 void FrameSelection::setNonDirectionalSelectionIfNeeded(const VisibleSelectionIn ComposedTree& passedNewSelection, TextGranularity granularity, EndPointsAdjustme ntMode endpointsAdjustmentMode) 262 void FrameSelection::setNonDirectionalSelectionIfNeeded(const VisibleSelectionIn FlatTree& passedNewSelection, TextGranularity granularity, EndPointsAdjustmentMo de endpointsAdjustmentMode)
263 { 263 {
264 setNonDirectionalSelectionIfNeededAlgorithm<EditingInComposedTreeStrategy>(p assedNewSelection, granularity, endpointsAdjustmentMode); 264 setNonDirectionalSelectionIfNeededAlgorithm<EditingInFlatTreeStrategy>(passe dNewSelection, granularity, endpointsAdjustmentMode);
265 } 265 }
266 266
267 template <typename Strategy> 267 template <typename Strategy>
268 void FrameSelection::setSelectionAlgorithm(const VisibleSelectionTemplate<Strate gy>& newSelection, SetSelectionOptions options, CursorAlignOnScroll align, TextG ranularity granularity) 268 void FrameSelection::setSelectionAlgorithm(const VisibleSelectionTemplate<Strate gy>& newSelection, SetSelectionOptions options, CursorAlignOnScroll align, TextG ranularity granularity)
269 { 269 {
270 if (m_granularityStrategy && (options & FrameSelection::DoNotClearStrategy) == 0) 270 if (m_granularityStrategy && (options & FrameSelection::DoNotClearStrategy) == 0)
271 m_granularityStrategy->Clear(); 271 m_granularityStrategy->Clear();
272 bool closeTyping = options & CloseTyping; 272 bool closeTyping = options & CloseTyping;
273 bool shouldClearTypingStyle = options & ClearTypingStyle; 273 bool shouldClearTypingStyle = options & ClearTypingStyle;
274 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); 274 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 updateAppearance(); 337 updateAppearance();
338 } 338 }
339 339
340 // Always clear the x position used for vertical arrow navigation. 340 // Always clear the x position used for vertical arrow navigation.
341 // It will be restored by the vertical arrow navigation code if necessary. 341 // It will be restored by the vertical arrow navigation code if necessary.
342 m_selectionEditor->resetXPosForVerticalArrowNavigation(); 342 m_selectionEditor->resetXPosForVerticalArrowNavigation();
343 RefPtrWillBeRawPtr<LocalFrame> protector(m_frame.get()); 343 RefPtrWillBeRawPtr<LocalFrame> protector(m_frame.get());
344 // This may dispatch a synchronous focus-related events. 344 // This may dispatch a synchronous focus-related events.
345 selectFrameElementInParentIfFullySelected(); 345 selectFrameElementInParentIfFullySelected();
346 notifyLayoutObjectOfSelectionChange(userTriggered); 346 notifyLayoutObjectOfSelectionChange(userTriggered);
347 // If the selections are same in the DOM tree but not in the composed tree, 347 // If the selections are same in the DOM tree but not in the flat tree,
348 // don't fire events. For example, if the selection crosses shadow tree 348 // don't fire events. For example, if the selection crosses shadow tree
349 // boundary, selection for the DOM tree is shrunk while that for the 349 // boundary, selection for the DOM tree is shrunk while that for the
350 // composed tree is not. Additionally, this case occurs in some edge cases. 350 // flat tree is not. Additionally, this case occurs in some edge cases.
351 // See also: editing/pasteboard/4076267-3.html 351 // See also: editing/pasteboard/4076267-3.html
352 if (oldSelection == m_selectionEditor->visibleSelection<Strategy>()) { 352 if (oldSelection == m_selectionEditor->visibleSelection<Strategy>()) {
353 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid() ; 353 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid() ;
354 return; 354 return;
355 } 355 }
356 m_frame->editor().respondToChangedSelection(oldSelectionInDOMTree, options); 356 m_frame->editor().respondToChangedSelection(oldSelectionInDOMTree, options);
357 if (userTriggered == UserTriggered) { 357 if (userTriggered == UserTriggered) {
358 ScrollAlignment alignment; 358 ScrollAlignment alignment;
359 359
360 if (m_frame->editor().behavior().shouldCenterAlignWhenSelectionIsReveale d()) 360 if (m_frame->editor().behavior().shouldCenterAlignWhenSelectionIsReveale d())
361 alignment = (align == CursorAlignOnScroll::Always) ? ScrollAlignment ::alignCenterAlways : ScrollAlignment::alignCenterIfNeeded; 361 alignment = (align == CursorAlignOnScroll::Always) ? ScrollAlignment ::alignCenterAlways : ScrollAlignment::alignCenterIfNeeded;
362 else 362 else
363 alignment = (align == CursorAlignOnScroll::Always) ? ScrollAlignment ::alignTopAlways : ScrollAlignment::alignToEdgeIfNeeded; 363 alignment = (align == CursorAlignOnScroll::Always) ? ScrollAlignment ::alignTopAlways : ScrollAlignment::alignToEdgeIfNeeded;
364 364
365 revealSelection(alignment, RevealExtent); 365 revealSelection(alignment, RevealExtent);
366 } 366 }
367 367
368 notifyAccessibilityForSelectionChange(); 368 notifyAccessibilityForSelectionChange();
369 notifyCompositorForSelectionChange(); 369 notifyCompositorForSelectionChange();
370 notifyEventHandlerForSelectionChange(); 370 notifyEventHandlerForSelectionChange();
371 m_frame->localDOMWindow()->enqueueDocumentEvent(Event::create(EventTypeNames ::selectionchange)); 371 m_frame->localDOMWindow()->enqueueDocumentEvent(Event::create(EventTypeNames ::selectionchange));
372 } 372 }
373 373
374 void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec tionOptions options, CursorAlignOnScroll align, TextGranularity granularity) 374 void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec tionOptions options, CursorAlignOnScroll align, TextGranularity granularity)
375 { 375 {
376 setSelectionAlgorithm<EditingStrategy>(newSelection, options, align, granula rity); 376 setSelectionAlgorithm<EditingStrategy>(newSelection, options, align, granula rity);
377 } 377 }
378 378
379 void FrameSelection::setSelection(const VisibleSelectionInComposedTree& newSelec tion, SetSelectionOptions options, CursorAlignOnScroll align, TextGranularity gr anularity) 379 void FrameSelection::setSelection(const VisibleSelectionInFlatTree& newSelection , SetSelectionOptions options, CursorAlignOnScroll align, TextGranularity granul arity)
380 { 380 {
381 setSelectionAlgorithm<EditingInComposedTreeStrategy>(newSelection, options, align, granularity); 381 setSelectionAlgorithm<EditingInFlatTreeStrategy>(newSelection, options, alig n, granularity);
382 } 382 }
383 383
384 static bool removingNodeRemovesPosition(Node& node, const Position& position) 384 static bool removingNodeRemovesPosition(Node& node, const Position& position)
385 { 385 {
386 if (!position.anchorNode()) 386 if (!position.anchorNode())
387 return false; 387 return false;
388 388
389 if (position.anchorNode() == node) 389 if (position.anchorNode() == node)
390 return true; 390 return true;
391 391
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 return false; 759 return false;
760 760
761 const PositionTemplate<Strategy> start = visibleStart.deepEquivalent(); 761 const PositionTemplate<Strategy> start = visibleStart.deepEquivalent();
762 const PositionTemplate<Strategy> end = visibleEnd.deepEquivalent(); 762 const PositionTemplate<Strategy> end = visibleEnd.deepEquivalent();
763 const PositionTemplate<Strategy> pos = visiblePos.deepEquivalent(); 763 const PositionTemplate<Strategy> pos = visiblePos.deepEquivalent();
764 return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0; 764 return start.compareTo(pos) <= 0 && pos.compareTo(end) <= 0;
765 } 765 }
766 766
767 bool FrameSelection::contains(const LayoutPoint& point) 767 bool FrameSelection::contains(const LayoutPoint& point)
768 { 768 {
769 if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled()) 769 if (RuntimeEnabledFeatures::selectionForFlatTreeEnabled())
770 return containsAlgorithm<EditingInComposedTreeStrategy>(point); 770 return containsAlgorithm<EditingInFlatTreeStrategy>(point);
771 return containsAlgorithm<EditingStrategy>(point); 771 return containsAlgorithm<EditingStrategy>(point);
772 } 772 }
773 773
774 // Workaround for the fact that it's hard to delete a frame. 774 // Workaround for the fact that it's hard to delete a frame.
775 // Call this after doing user-triggered selections to make it easy to delete the frame you entirely selected. 775 // Call this after doing user-triggered selections to make it easy to delete the frame you entirely selected.
776 // Can't do this implicitly as part of every setSelection call because in some c ontexts it might not be good 776 // Can't do this implicitly as part of every setSelection call because in some c ontexts it might not be good
777 // for the focus to move to another frame. So instead we call it from places whe re we are selecting with the 777 // for the focus to move to another frame. So instead we call it from places whe re we are selecting with the
778 // mouse or the keyboard after setting the selection. 778 // mouse or the keyboard after setting the selection.
779 void FrameSelection::selectFrameElementInParentIfFullySelected() 779 void FrameSelection::selectFrameElementInParentIfFullySelected()
780 { 780 {
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 String extractSelectedTextAlgorithm(const FrameSelection& selection, TextIterato rBehavior behavior) 1125 String extractSelectedTextAlgorithm(const FrameSelection& selection, TextIterato rBehavior behavior)
1126 { 1126 {
1127 const VisibleSelectionTemplate<Strategy> visibleSelection = selection.visibl eSelection<Strategy>(); 1127 const VisibleSelectionTemplate<Strategy> visibleSelection = selection.visibl eSelection<Strategy>();
1128 const EphemeralRangeTemplate<Strategy> range = visibleSelection.toNormalized EphemeralRange(); 1128 const EphemeralRangeTemplate<Strategy> range = visibleSelection.toNormalized EphemeralRange();
1129 // We remove '\0' characters because they are not visibly rendered to the us er. 1129 // We remove '\0' characters because they are not visibly rendered to the us er.
1130 return plainText(range, behavior).replace(0, ""); 1130 return plainText(range, behavior).replace(0, "");
1131 } 1131 }
1132 1132
1133 static String extractSelectedText(const FrameSelection& selection, TextIteratorB ehavior behavior) 1133 static String extractSelectedText(const FrameSelection& selection, TextIteratorB ehavior behavior)
1134 { 1134 {
1135 if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled()) 1135 if (RuntimeEnabledFeatures::selectionForFlatTreeEnabled())
1136 return extractSelectedTextAlgorithm<EditingInComposedTreeStrategy>(selec tion, behavior); 1136 return extractSelectedTextAlgorithm<EditingInFlatTreeStrategy>(selection , behavior);
1137 return extractSelectedTextAlgorithm<EditingStrategy>(selection, behavior); 1137 return extractSelectedTextAlgorithm<EditingStrategy>(selection, behavior);
1138 } 1138 }
1139 1139
1140 template <typename Strategy> 1140 template <typename Strategy>
1141 static String extractSelectedHTMLAlgorithm(const FrameSelection& selection) 1141 static String extractSelectedHTMLAlgorithm(const FrameSelection& selection)
1142 { 1142 {
1143 const VisibleSelectionTemplate<Strategy> visibleSelection = selection.visibl eSelection<Strategy>(); 1143 const VisibleSelectionTemplate<Strategy> visibleSelection = selection.visibl eSelection<Strategy>();
1144 const EphemeralRangeTemplate<Strategy> range = visibleSelection.toNormalized EphemeralRange(); 1144 const EphemeralRangeTemplate<Strategy> range = visibleSelection.toNormalized EphemeralRange();
1145 return createMarkup(range.startPosition(), range.endPosition(), AnnotateForI nterchange, ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); 1145 return createMarkup(range.startPosition(), range.endPosition(), AnnotateForI nterchange, ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs);
1146 } 1146 }
1147 1147
1148 String FrameSelection::selectedHTMLForClipboard() const 1148 String FrameSelection::selectedHTMLForClipboard() const
1149 { 1149 {
1150 if (!RuntimeEnabledFeatures::selectionForComposedTreeEnabled()) 1150 if (!RuntimeEnabledFeatures::selectionForFlatTreeEnabled())
1151 return extractSelectedHTMLAlgorithm<EditingStrategy>(*this); 1151 return extractSelectedHTMLAlgorithm<EditingStrategy>(*this);
1152 return extractSelectedHTMLAlgorithm<EditingInComposedTreeStrategy>(*this); 1152 return extractSelectedHTMLAlgorithm<EditingInFlatTreeStrategy>(*this);
1153 } 1153 }
1154 1154
1155 String FrameSelection::selectedText(TextIteratorBehavior behavior) const 1155 String FrameSelection::selectedText(TextIteratorBehavior behavior) const
1156 { 1156 {
1157 return extractSelectedText(*this, behavior); 1157 return extractSelectedText(*this, behavior);
1158 } 1158 }
1159 1159
1160 String FrameSelection::selectedTextForClipboard() const 1160 String FrameSelection::selectedTextForClipboard() const
1161 { 1161 {
1162 if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageTex t()) 1162 if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageTex t())
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 } 1320 }
1321 1321
1322 #endif 1322 #endif
1323 1323
1324 DEFINE_TRACE(FrameSelection) 1324 DEFINE_TRACE(FrameSelection)
1325 { 1325 {
1326 visitor->trace(m_frame); 1326 visitor->trace(m_frame);
1327 visitor->trace(m_pendingSelection); 1327 visitor->trace(m_pendingSelection);
1328 visitor->trace(m_selectionEditor); 1328 visitor->trace(m_selectionEditor);
1329 visitor->trace(m_originalBase); 1329 visitor->trace(m_originalBase);
1330 visitor->trace(m_originalBaseInComposedTree); 1330 visitor->trace(m_originalBaseInFlatTree);
1331 visitor->trace(m_previousCaretNode); 1331 visitor->trace(m_previousCaretNode);
1332 visitor->trace(m_typingStyle); 1332 visitor->trace(m_typingStyle);
1333 } 1333 }
1334 1334
1335 void FrameSelection::setCaretRectNeedsUpdate() 1335 void FrameSelection::setCaretRectNeedsUpdate()
1336 { 1336 {
1337 if (m_caretRectDirty) 1337 if (m_caretRectDirty)
1338 return; 1338 return;
1339 m_caretRectDirty = true; 1339 m_caretRectDirty = true;
1340 1340
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 1425
1426 void showTree(const blink::FrameSelection* sel) 1426 void showTree(const blink::FrameSelection* sel)
1427 { 1427 {
1428 if (sel) 1428 if (sel)
1429 sel->showTreeForThis(); 1429 sel->showTreeForThis();
1430 else 1430 else
1431 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1431 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1432 } 1432 }
1433 1433
1434 #endif 1434 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698