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

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

Issue 2437873008: Get rid of flat tree version of createVisibleSelection() taking two VisiblePosition (Closed)
Patch Set: 2016-10-24T13:35:49 Created 4 years, 1 month 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 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 return; 938 return;
939 939
940 // Create compute positions before and after the element. 940 // Create compute positions before and after the element.
941 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); 941 unsigned ownerElementNodeIndex = ownerElement->nodeIndex();
942 VisiblePosition beforeOwnerElement = createVisiblePosition( 942 VisiblePosition beforeOwnerElement = createVisiblePosition(
943 Position(ownerElementParent, ownerElementNodeIndex)); 943 Position(ownerElementParent, ownerElementNodeIndex));
944 VisiblePosition afterOwnerElement = createVisiblePosition( 944 VisiblePosition afterOwnerElement = createVisiblePosition(
945 Position(ownerElementParent, ownerElementNodeIndex + 1), 945 Position(ownerElementParent, ownerElementNodeIndex + 1),
946 VP_UPSTREAM_IF_POSSIBLE); 946 VP_UPSTREAM_IF_POSSIBLE);
947 947
948 SelectionInDOMTree::Builder builder;
949 builder
950 .setBaseAndExtentDeprecated(beforeOwnerElement.deepEquivalent(),
951 afterOwnerElement.deepEquivalent())
952 .setAffinity(beforeOwnerElement.affinity());
953
948 // Focus on the parent frame, and then select from before this element to 954 // Focus on the parent frame, and then select from before this element to
949 // after. 955 // after.
950 VisibleSelection newSelection = 956 VisibleSelection newSelection = createVisibleSelection(builder.build());
951 createVisibleSelection(beforeOwnerElement, afterOwnerElement);
952 page->focusController().setFocusedFrame(parent); 957 page->focusController().setFocusedFrame(parent);
953 // setFocusedFrame can dispatch synchronous focus/blur events. The document 958 // setFocusedFrame can dispatch synchronous focus/blur events. The document
954 // tree might be modified. 959 // tree might be modified.
955 if (newSelection.isNonOrphanedCaretOrRange()) 960 if (newSelection.isNonOrphanedCaretOrRange())
956 toLocalFrame(parent)->selection().setSelection(newSelection); 961 toLocalFrame(parent)->selection().setSelection(newSelection);
957 } 962 }
958 963
959 // Returns a shadow tree node for legacy shadow trees, a child of the 964 // Returns a shadow tree node for legacy shadow trees, a child of the
960 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. 965 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
961 static Node* nonBoundaryShadowTreeRootNode(const Position& position) { 966 static Node* nonBoundaryShadowTreeRootNode(const Position& position) {
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 1385
1381 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) { 1386 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) {
1382 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary, 1387 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary,
1383 LeftWordIfOnBoundary}; 1388 LeftWordIfOnBoundary};
1384 for (EWordSide wordSide : wordSideList) { 1389 for (EWordSide wordSide : wordSideList) {
1385 VisiblePosition start = startOfWord(position, wordSide); 1390 VisiblePosition start = startOfWord(position, wordSide);
1386 VisiblePosition end = endOfWord(position, wordSide); 1391 VisiblePosition end = endOfWord(position, wordSide);
1387 String text = 1392 String text =
1388 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent())); 1393 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent()));
1389 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { 1394 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) {
1390 setSelection(createVisibleSelection(start, end), 1395 setSelection(
1391 CloseTyping | ClearTypingStyle, 1396 createVisibleSelection(SelectionInDOMTree::Builder()
1392 CursorAlignOnScroll::IfNeeded, WordGranularity); 1397 .collapse(start.toPositionWithAffinity())
1398 .extend(end.deepEquivalent())
1399 .build()),
1400 CloseTyping | ClearTypingStyle, CursorAlignOnScroll::IfNeeded,
1401 WordGranularity);
1393 return true; 1402 return true;
1394 } 1403 }
1395 } 1404 }
1396 1405
1397 return false; 1406 return false;
1398 } 1407 }
1399 1408
1400 GranularityStrategy* FrameSelection::granularityStrategy() { 1409 GranularityStrategy* FrameSelection::granularityStrategy() {
1401 // We do lazy initalization for m_granularityStrategy, because if we 1410 // We do lazy initalization for m_granularityStrategy, because if we
1402 // initialize it right in the constructor - the correct settings may not be 1411 // initialize it right in the constructor - the correct settings may not be
(...skipping 18 matching lines...) Expand all
1421 return; 1430 return;
1422 1431
1423 VisibleSelection newSelection = 1432 VisibleSelection newSelection =
1424 granularityStrategy()->updateExtent(contentsPoint, m_frame); 1433 granularityStrategy()->updateExtent(contentsPoint, m_frame);
1425 setSelection(newSelection, 1434 setSelection(newSelection,
1426 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | 1435 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
1427 FrameSelection::DoNotClearStrategy | UserTriggered, 1436 FrameSelection::DoNotClearStrategy | UserTriggered,
1428 CursorAlignOnScroll::IfNeeded, CharacterGranularity); 1437 CursorAlignOnScroll::IfNeeded, CharacterGranularity);
1429 } 1438 }
1430 1439
1440 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take
1441 // two |IntPoint| instead of two |VisiblePosition| like
1442 // |moveRangeSelectionExtent()|.
1431 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, 1443 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition,
1432 const VisiblePosition& extentPosition, 1444 const VisiblePosition& extentPosition,
1433 TextGranularity granularity) { 1445 TextGranularity granularity) {
1434 VisibleSelection newSelection = 1446 SelectionInDOMTree::Builder builder;
1435 createVisibleSelection(basePosition, extentPosition); 1447 builder
1448 .setBaseAndExtent(basePosition.deepEquivalent(),
Xiaocheng 2016/10/24 06:58:49 Is it guaranteed to have non-null basePosition and
yosin_UTC9 2016/10/24 07:40:17 Oops, No. We should use setBaseAndExtentDeprecate
1449 extentPosition.deepEquivalent())
1450 .setAffinity(basePosition.affinity());
1451 VisibleSelection newSelection = createVisibleSelection(builder.build());
1436 newSelection.expandUsingGranularity(granularity); 1452 newSelection.expandUsingGranularity(granularity);
1437 1453
1438 if (newSelection.isNone()) 1454 if (newSelection.isNone())
1439 return; 1455 return;
1440 1456
1441 setSelection(newSelection, CloseTyping | ClearTypingStyle, 1457 setSelection(newSelection, CloseTyping | ClearTypingStyle,
1442 CursorAlignOnScroll::IfNeeded, granularity); 1458 CursorAlignOnScroll::IfNeeded, granularity);
1443 } 1459 }
1444 1460
1445 void FrameSelection::updateIfNeeded() { 1461 void FrameSelection::updateIfNeeded() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1485 } 1501 }
1486 1502
1487 void showTree(const blink::FrameSelection* sel) { 1503 void showTree(const blink::FrameSelection* sel) {
1488 if (sel) 1504 if (sel)
1489 sel->showTreeForThis(); 1505 sel->showTreeForThis();
1490 else 1506 else
1491 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1507 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1492 } 1508 }
1493 1509
1494 #endif 1510 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698