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

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

Issue 2386073003: Prune createVisibleSelectionDeprecated from FrameSelection (Closed)
Patch Set: Move layout from FrameSelection::setSelectedRange to DOMSelection::addRange 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 152
153 const VisibleSelectionInFlatTree& FrameSelection::selectionInFlatTree() const { 153 const VisibleSelectionInFlatTree& FrameSelection::selectionInFlatTree() const {
154 return visibleSelection<EditingInFlatTreeStrategy>(); 154 return visibleSelection<EditingInFlatTreeStrategy>();
155 } 155 }
156 156
157 void FrameSelection::moveTo(const VisiblePosition& pos, 157 void FrameSelection::moveTo(const VisiblePosition& pos,
158 EUserTriggered userTriggered, 158 EUserTriggered userTriggered,
159 CursorAlignOnScroll align) { 159 CursorAlignOnScroll align) {
160 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered; 160 SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTriggered;
161 setSelection( 161 setSelection(createVisibleSelection(pos, pos, selection().isDirectional()),
162 createVisibleSelectionDeprecated(pos, pos, selection().isDirectional()), 162 options, align);
163 options, align);
164 } 163 }
165 164
166 void FrameSelection::moveTo(const Position& pos, TextAffinity affinity) { 165 void FrameSelection::moveTo(const Position& pos, TextAffinity affinity) {
167 SetSelectionOptions options = CloseTyping | ClearTypingStyle; 166 SetSelectionOptions options = CloseTyping | ClearTypingStyle;
168 setSelection(createVisibleSelectionDeprecated(pos, affinity, 167 setSelection(
169 selection().isDirectional()), 168 createVisibleSelection(pos, affinity, selection().isDirectional()),
170 options); 169 options);
171 } 170 }
172 171
173 // TODO(xiaochengh): We should not use reference to return value. 172 // TODO(xiaochengh): We should not use reference to return value.
174 template <typename Strategy> 173 template <typename Strategy>
175 static void adjustEndpointsAtBidiBoundary( 174 static void adjustEndpointsAtBidiBoundary(
176 VisiblePositionTemplate<Strategy>& visibleBase, 175 VisiblePositionTemplate<Strategy>& visibleBase,
177 VisiblePositionTemplate<Strategy>& visibleExtent) { 176 VisiblePositionTemplate<Strategy>& visibleExtent) {
178 DCHECK(visibleBase.isValid()); 177 DCHECK(visibleBase.isValid());
179 DCHECK(visibleExtent.isValid()); 178 DCHECK(visibleExtent.isValid());
180 179
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 // Create compute positions before and after the element. 898 // Create compute positions before and after the element.
900 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); 899 unsigned ownerElementNodeIndex = ownerElement->nodeIndex();
901 VisiblePosition beforeOwnerElement = createVisiblePosition( 900 VisiblePosition beforeOwnerElement = createVisiblePosition(
902 Position(ownerElementParent, ownerElementNodeIndex)); 901 Position(ownerElementParent, ownerElementNodeIndex));
903 VisiblePosition afterOwnerElement = createVisiblePosition( 902 VisiblePosition afterOwnerElement = createVisiblePosition(
904 Position(ownerElementParent, ownerElementNodeIndex + 1), 903 Position(ownerElementParent, ownerElementNodeIndex + 1),
905 VP_UPSTREAM_IF_POSSIBLE); 904 VP_UPSTREAM_IF_POSSIBLE);
906 905
907 // Focus on the parent frame, and then select from before this element to afte r. 906 // Focus on the parent frame, and then select from before this element to afte r.
908 VisibleSelection newSelection = 907 VisibleSelection newSelection =
909 createVisibleSelectionDeprecated(beforeOwnerElement, afterOwnerElement); 908 createVisibleSelection(beforeOwnerElement, afterOwnerElement);
910 page->focusController().setFocusedFrame(parent); 909 page->focusController().setFocusedFrame(parent);
911 // setFocusedFrame can dispatch synchronous focus/blur events. The document 910 // setFocusedFrame can dispatch synchronous focus/blur events. The document
912 // tree might be modified. 911 // tree might be modified.
913 if (newSelection.isNonOrphanedCaretOrRange()) 912 if (newSelection.isNonOrphanedCaretOrRange())
914 toLocalFrame(parent)->selection().setSelection(newSelection); 913 toLocalFrame(parent)->selection().setSelection(newSelection);
915 } 914 }
916 915
917 // Returns a shadow tree node for legacy shadow trees, a child of the 916 // Returns a shadow tree node for legacy shadow trees, a child of the
918 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. 917 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
919 static Node* nonBoundaryShadowTreeRootNode(const Position& position) { 918 static Node* nonBoundaryShadowTreeRootNode(const Position& position) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 TextAffinity affinity, 984 TextAffinity affinity,
986 SelectionDirectionalMode directional, 985 SelectionDirectionalMode directional,
987 SetSelectionOptions options) { 986 SetSelectionOptions options) {
988 if (range.isNull()) 987 if (range.isNull())
989 return false; 988 return false;
990 m_selectionEditor->resetLogicalRange(); 989 m_selectionEditor->resetLogicalRange();
991 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree 990 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree
992 // can be modified by event handlers, we should create |Range| object before 991 // can be modified by event handlers, we should create |Range| object before
993 // calling it. 992 // calling it.
994 Range* logicalRange = createRange(range); 993 Range* logicalRange = createRange(range);
995 VisibleSelection newSelection = createVisibleSelectionDeprecated( 994 VisibleSelection newSelection = createVisibleSelection(
996 range.startPosition(), range.endPosition(), affinity, 995 range.startPosition(), range.endPosition(), affinity,
997 directional == SelectionDirectionalMode::Directional); 996 directional == SelectionDirectionalMode::Directional);
998 setSelection(newSelection, options); 997 setSelection(newSelection, options);
999 m_selectionEditor->setLogicalRange(logicalRange); 998 m_selectionEditor->setLogicalRange(logicalRange);
1000 return true; 999 return true;
1001 } 1000 }
1002 1001
1003 Range* FrameSelection::firstRange() const { 1002 Range* FrameSelection::firstRange() const {
1004 return m_selectionEditor->firstRange(); 1003 return m_selectionEditor->firstRange();
1005 } 1004 }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 Document* document = m_frame->document(); 1297 Document* document = m_frame->document();
1299 bool caretBrowsing = 1298 bool caretBrowsing =
1300 m_frame->settings() && m_frame->settings()->caretBrowsingEnabled(); 1299 m_frame->settings() && m_frame->settings()->caretBrowsingEnabled();
1301 if (!isNone() || !(blink::hasEditableStyle(*document) || caretBrowsing)) 1300 if (!isNone() || !(blink::hasEditableStyle(*document) || caretBrowsing))
1302 return; 1301 return;
1303 1302
1304 Element* documentElement = document->documentElement(); 1303 Element* documentElement = document->documentElement();
1305 if (!documentElement) 1304 if (!documentElement)
1306 return; 1305 return;
1307 if (HTMLBodyElement* body = 1306 if (HTMLBodyElement* body =
1308 Traversal<HTMLBodyElement>::firstChild(*documentElement)) 1307 Traversal<HTMLBodyElement>::firstChild(*documentElement)) {
1309 setSelection(createVisibleSelectionDeprecated( 1308 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
1310 firstPositionInOrBeforeNode(body), TextAffinity::Downstream)); 1309 // needs to be audited. See http://crbug.com/590369 for more details.
1310 document->updateStyleAndLayoutIgnorePendingStylesheets();
1311
1312 setSelection(createVisibleSelection(firstPositionInOrBeforeNode(body),
1313 TextAffinity::Downstream));
1314 }
1311 } 1315 }
1312 1316
1313 // TODO(yoichio): We should have LocalFrame having FrameCaret, 1317 // TODO(yoichio): We should have LocalFrame having FrameCaret,
1314 // Editor and PendingSelection using FrameCaret directly 1318 // Editor and PendingSelection using FrameCaret directly
1315 // and get rid of this. 1319 // and get rid of this.
1316 bool FrameSelection::shouldShowBlockCursor() const { 1320 bool FrameSelection::shouldShowBlockCursor() const {
1317 return m_frameCaret->shouldShowBlockCursor(); 1321 return m_frameCaret->shouldShowBlockCursor();
1318 } 1322 }
1319 1323
1320 // TODO(yoichio): We should have LocalFrame having FrameCaret, 1324 // TODO(yoichio): We should have LocalFrame having FrameCaret,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 1380
1377 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) { 1381 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) {
1378 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary, 1382 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary,
1379 LeftWordIfOnBoundary}; 1383 LeftWordIfOnBoundary};
1380 for (EWordSide wordSide : wordSideList) { 1384 for (EWordSide wordSide : wordSideList) {
1381 VisiblePosition start = startOfWord(position, wordSide); 1385 VisiblePosition start = startOfWord(position, wordSide);
1382 VisiblePosition end = endOfWord(position, wordSide); 1386 VisiblePosition end = endOfWord(position, wordSide);
1383 String text = 1387 String text =
1384 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent())); 1388 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent()));
1385 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1389 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1386 setSelection(createVisibleSelectionDeprecated(start, end), 1390 setSelection(createVisibleSelection(start, end), WordGranularity);
1387 WordGranularity);
1388 return true; 1391 return true;
1389 } 1392 }
1390 } 1393 }
1391 1394
1392 return false; 1395 return false;
1393 } 1396 }
1394 1397
1395 GranularityStrategy* FrameSelection::granularityStrategy() { 1398 GranularityStrategy* FrameSelection::granularityStrategy() {
1396 // We do lazy initalization for m_granularityStrategy, because if we 1399 // We do lazy initalization for m_granularityStrategy, because if we
1397 // initialize it right in the constructor - the correct settings may not be 1400 // initialize it right in the constructor - the correct settings may not be
(...skipping 22 matching lines...) Expand all
1420 setSelection(newSelection, 1423 setSelection(newSelection,
1421 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | 1424 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
1422 FrameSelection::DoNotClearStrategy | UserTriggered, 1425 FrameSelection::DoNotClearStrategy | UserTriggered,
1423 CursorAlignOnScroll::IfNeeded, CharacterGranularity); 1426 CursorAlignOnScroll::IfNeeded, CharacterGranularity);
1424 } 1427 }
1425 1428
1426 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, 1429 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition,
1427 const VisiblePosition& extentPosition, 1430 const VisiblePosition& extentPosition,
1428 TextGranularity granularity) { 1431 TextGranularity granularity) {
1429 VisibleSelection newSelection = 1432 VisibleSelection newSelection =
1430 createVisibleSelectionDeprecated(basePosition, extentPosition); 1433 createVisibleSelection(basePosition, extentPosition);
1431 newSelection.expandUsingGranularity(granularity); 1434 newSelection.expandUsingGranularity(granularity);
1432 1435
1433 if (newSelection.isNone()) 1436 if (newSelection.isNone())
1434 return; 1437 return;
1435 1438
1436 setSelection(newSelection, granularity); 1439 setSelection(newSelection, granularity);
1437 } 1440 }
1438 1441
1439 void FrameSelection::updateIfNeeded() { 1442 void FrameSelection::updateIfNeeded() {
1440 m_selectionEditor->updateIfNeeded(); 1443 m_selectionEditor->updateIfNeeded();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 } 1481 }
1479 1482
1480 void showTree(const blink::FrameSelection* sel) { 1483 void showTree(const blink::FrameSelection* sel) {
1481 if (sel) 1484 if (sel)
1482 sel->showTreeForThis(); 1485 sel->showTreeForThis();
1483 else 1486 else
1484 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1487 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1485 } 1488 }
1486 1489
1487 #endif 1490 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698