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

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

Issue 2374183004: Make non-null VisibleSelections creatable only by createVisibleSelection[Deprecated] (Closed)
Patch Set: Fix mac compile error Created 4 years, 2 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 159 }
160 160
161 const VisibleSelectionInFlatTree& FrameSelection::selectionInFlatTree() const 161 const VisibleSelectionInFlatTree& FrameSelection::selectionInFlatTree() const
162 { 162 {
163 return visibleSelection<EditingInFlatTreeStrategy>(); 163 return visibleSelection<EditingInFlatTreeStrategy>();
164 } 164 }
165 165
166 void FrameSelection::moveTo(const VisiblePosition &pos, EUserTriggered userTrigg ered, CursorAlignOnScroll align) 166 void FrameSelection::moveTo(const VisiblePosition &pos, EUserTriggered userTrigg ered, CursorAlignOnScroll align)
167 { 167 {
168 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered ; 168 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered ;
169 setSelection(VisibleSelection(pos, pos, selection().isDirectional()), option s, align); 169 setSelection(createVisibleSelectionDeprecated(pos, pos, selection().isDirect ional()), options, align);
170 } 170 }
171 171
172 void FrameSelection::moveTo(const Position &pos, TextAffinity affinity) 172 void FrameSelection::moveTo(const Position &pos, TextAffinity affinity)
173 { 173 {
174 SetSelectionOptions options = CloseTyping | ClearTypingStyle; 174 SetSelectionOptions options = CloseTyping | ClearTypingStyle;
175 setSelection(VisibleSelection(pos, affinity, selection().isDirectional()), o ptions); 175 setSelection(createVisibleSelectionDeprecated(pos, affinity, selection().isD irectional()), options);
176 } 176 }
177 177
178 // TODO(xiaochengh): We should not use reference to return value. 178 // TODO(xiaochengh): We should not use reference to return value.
179 template <typename Strategy> 179 template <typename Strategy>
180 static void adjustEndpointsAtBidiBoundary(VisiblePositionTemplate<Strategy>& vis ibleBase, VisiblePositionTemplate<Strategy>& visibleExtent) 180 static void adjustEndpointsAtBidiBoundary(VisiblePositionTemplate<Strategy>& vis ibleBase, VisiblePositionTemplate<Strategy>& visibleExtent)
181 { 181 {
182 DCHECK(visibleBase.isValid()); 182 DCHECK(visibleBase.isValid());
183 DCHECK(visibleExtent.isValid()); 183 DCHECK(visibleExtent.isValid());
184 184
185 RenderedPosition base(visibleBase); 185 RenderedPosition base(visibleBase);
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 // This method's purpose is it to make it easier to select iframes (in order to delete them). Don't do anything if the iframe isn't deletable. 816 // This method's purpose is it to make it easier to select iframes (in order to delete them). Don't do anything if the iframe isn't deletable.
817 if (!blink::hasEditableStyle(*ownerElementParent)) 817 if (!blink::hasEditableStyle(*ownerElementParent))
818 return; 818 return;
819 819
820 // Create compute positions before and after the element. 820 // Create compute positions before and after the element.
821 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); 821 unsigned ownerElementNodeIndex = ownerElement->nodeIndex();
822 VisiblePosition beforeOwnerElement = createVisiblePosition(Position(ownerEle mentParent, ownerElementNodeIndex)); 822 VisiblePosition beforeOwnerElement = createVisiblePosition(Position(ownerEle mentParent, ownerElementNodeIndex));
823 VisiblePosition afterOwnerElement = createVisiblePosition(Position(ownerElem entParent, ownerElementNodeIndex + 1), VP_UPSTREAM_IF_POSSIBLE); 823 VisiblePosition afterOwnerElement = createVisiblePosition(Position(ownerElem entParent, ownerElementNodeIndex + 1), VP_UPSTREAM_IF_POSSIBLE);
824 824
825 // Focus on the parent frame, and then select from before this element to af ter. 825 // Focus on the parent frame, and then select from before this element to af ter.
826 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); 826 VisibleSelection newSelection = createVisibleSelectionDeprecated(beforeOwner Element, afterOwnerElement);
827 page->focusController().setFocusedFrame(parent); 827 page->focusController().setFocusedFrame(parent);
828 // setFocusedFrame can dispatch synchronous focus/blur events. The document 828 // setFocusedFrame can dispatch synchronous focus/blur events. The document
829 // tree might be modified. 829 // tree might be modified.
830 if (newSelection.isNonOrphanedCaretOrRange()) 830 if (newSelection.isNonOrphanedCaretOrRange())
831 toLocalFrame(parent)->selection().setSelection(newSelection); 831 toLocalFrame(parent)->selection().setSelection(newSelection);
832 } 832 }
833 833
834 // Returns a shadow tree node for legacy shadow trees, a child of the 834 // Returns a shadow tree node for legacy shadow trees, a child of the
835 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. 835 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
836 static Node* nonBoundaryShadowTreeRootNode(const Position& position) 836 static Node* nonBoundaryShadowTreeRootNode(const Position& position)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 893
894 bool FrameSelection::setSelectedRange(const EphemeralRange& range, TextAffinity affinity, SelectionDirectionalMode directional, SetSelectionOptions options) 894 bool FrameSelection::setSelectedRange(const EphemeralRange& range, TextAffinity affinity, SelectionDirectionalMode directional, SetSelectionOptions options)
895 { 895 {
896 if (range.isNull()) 896 if (range.isNull())
897 return false; 897 return false;
898 m_selectionEditor->resetLogicalRange(); 898 m_selectionEditor->resetLogicalRange();
899 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree 899 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree
900 // can be modified by event handlers, we should create |Range| object before 900 // can be modified by event handlers, we should create |Range| object before
901 // calling it. 901 // calling it.
902 Range* logicalRange = createRange(range); 902 Range* logicalRange = createRange(range);
903 VisibleSelection newSelection(range.startPosition(), range.endPosition(), af finity, directional == SelectionDirectionalMode::Directional); 903 VisibleSelection newSelection = createVisibleSelectionDeprecated(range.start Position(), range.endPosition(), affinity, directional == SelectionDirectionalMo de::Directional);
904 setSelection(newSelection, options); 904 setSelection(newSelection, options);
905 m_selectionEditor->setLogicalRange(logicalRange); 905 m_selectionEditor->setLogicalRange(logicalRange);
906 return true; 906 return true;
907 } 907 }
908 908
909 Range* FrameSelection::firstRange() const 909 Range* FrameSelection::firstRange() const
910 { 910 {
911 return m_selectionEditor->firstRange(); 911 return m_selectionEditor->firstRange();
912 } 912 }
913 913
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 1207
1208 Document* document = m_frame->document(); 1208 Document* document = m_frame->document();
1209 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi ngEnabled(); 1209 bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsi ngEnabled();
1210 if (!isNone() || !(blink::hasEditableStyle(*document) || caretBrowsing)) 1210 if (!isNone() || !(blink::hasEditableStyle(*document) || caretBrowsing))
1211 return; 1211 return;
1212 1212
1213 Element* documentElement = document->documentElement(); 1213 Element* documentElement = document->documentElement();
1214 if (!documentElement) 1214 if (!documentElement)
1215 return; 1215 return;
1216 if (HTMLBodyElement* body = Traversal<HTMLBodyElement>::firstChild(*document Element)) 1216 if (HTMLBodyElement* body = Traversal<HTMLBodyElement>::firstChild(*document Element))
1217 setSelection(VisibleSelection(firstPositionInOrBeforeNode(body), TextAff inity::Downstream)); 1217 setSelection(createVisibleSelectionDeprecated(firstPositionInOrBeforeNod e(body), TextAffinity::Downstream));
1218 } 1218 }
1219 1219
1220 // TODO(yoichio): We should have LocalFrame having FrameCaret, 1220 // TODO(yoichio): We should have LocalFrame having FrameCaret,
1221 // Editor and PendingSelection using FrameCaret directly 1221 // Editor and PendingSelection using FrameCaret directly
1222 // and get rid of this. 1222 // and get rid of this.
1223 bool FrameSelection::shouldShowBlockCursor() const 1223 bool FrameSelection::shouldShowBlockCursor() const
1224 { 1224 {
1225 return m_frameCaret->shouldShowBlockCursor(); 1225 return m_frameCaret->shouldShowBlockCursor();
1226 } 1226 }
1227 1227
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 } 1287 }
1288 1288
1289 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) 1289 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position)
1290 { 1290 {
1291 static const EWordSide wordSideList[2] = { RightWordIfOnBoundary, LeftWordIf OnBoundary }; 1291 static const EWordSide wordSideList[2] = { RightWordIfOnBoundary, LeftWordIf OnBoundary };
1292 for (EWordSide wordSide : wordSideList) { 1292 for (EWordSide wordSide : wordSideList) {
1293 VisiblePosition start = startOfWord(position, wordSide); 1293 VisiblePosition start = startOfWord(position, wordSide);
1294 VisiblePosition end = endOfWord(position, wordSide); 1294 VisiblePosition end = endOfWord(position, wordSide);
1295 String text = plainText(EphemeralRange(start.deepEquivalent(), end.deepE quivalent())); 1295 String text = plainText(EphemeralRange(start.deepEquivalent(), end.deepE quivalent()));
1296 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1296 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1297 setSelection(VisibleSelection(start, end), WordGranularity); 1297 setSelection(createVisibleSelectionDeprecated(start, end), WordGranu larity);
1298 return true; 1298 return true;
1299 } 1299 }
1300 } 1300 }
1301 1301
1302 return false; 1302 return false;
1303 } 1303 }
1304 1304
1305 GranularityStrategy* FrameSelection::granularityStrategy() 1305 GranularityStrategy* FrameSelection::granularityStrategy()
1306 { 1306 {
1307 // We do lazy initalization for m_granularityStrategy, because if we 1307 // We do lazy initalization for m_granularityStrategy, because if we
(...skipping 22 matching lines...) Expand all
1330 VisibleSelection newSelection = granularityStrategy()->updateExtent(contents Point, m_frame); 1330 VisibleSelection newSelection = granularityStrategy()->updateExtent(contents Point, m_frame);
1331 setSelection( 1331 setSelection(
1332 newSelection, 1332 newSelection,
1333 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSe lection::DoNotClearStrategy | UserTriggered, 1333 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSe lection::DoNotClearStrategy | UserTriggered,
1334 CursorAlignOnScroll::IfNeeded, 1334 CursorAlignOnScroll::IfNeeded,
1335 CharacterGranularity); 1335 CharacterGranularity);
1336 } 1336 }
1337 1337
1338 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, con st VisiblePosition& extentPosition, TextGranularity granularity) 1338 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, con st VisiblePosition& extentPosition, TextGranularity granularity)
1339 { 1339 {
1340 VisibleSelection newSelection(basePosition, extentPosition); 1340 VisibleSelection newSelection = createVisibleSelectionDeprecated(basePositio n, extentPosition);
1341 newSelection.expandUsingGranularity(granularity); 1341 newSelection.expandUsingGranularity(granularity);
1342 1342
1343 if (newSelection.isNone()) 1343 if (newSelection.isNone())
1344 return; 1344 return;
1345 1345
1346 setSelection(newSelection, granularity); 1346 setSelection(newSelection, granularity);
1347 } 1347 }
1348 1348
1349 void FrameSelection::updateIfNeeded() 1349 void FrameSelection::updateIfNeeded()
1350 { 1350 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 1397
1398 void showTree(const blink::FrameSelection* sel) 1398 void showTree(const blink::FrameSelection* sel)
1399 { 1399 {
1400 if (sel) 1400 if (sel)
1401 sel->showTreeForThis(); 1401 sel->showTreeForThis();
1402 else 1402 else
1403 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1403 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1404 } 1404 }
1405 1405
1406 #endif 1406 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698