OLD | NEW |
---|---|
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 Loading... | |
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; | |
Xiaocheng
2016/10/21 11:18:36
Let's use setBaseAndExtentDeprecated, since having
yosin_UTC9
2016/10/24 06:19:44
Done
| |
949 if (beforeOwnerElement.isNotNull() && afterOwnerElement.isNotNull()) { | |
950 builder.collapse(beforeOwnerElement.toPositionWithAffinity()) | |
951 .extend(afterOwnerElement.deepEquivalent()); | |
952 } else if (beforeOwnerElement.isNotNull()) { | |
953 builder.collapse(beforeOwnerElement.toPositionWithAffinity()); | |
954 } else if (afterOwnerElement.isNotNull()) { | |
955 builder.collapse(afterOwnerElement.toPositionWithAffinity()); | |
956 } | |
957 | |
948 // Focus on the parent frame, and then select from before this element to | 958 // Focus on the parent frame, and then select from before this element to |
949 // after. | 959 // after. |
950 VisibleSelection newSelection = | 960 VisibleSelection newSelection = createVisibleSelection(builder.build()); |
951 createVisibleSelection(beforeOwnerElement, afterOwnerElement); | |
952 page->focusController().setFocusedFrame(parent); | 961 page->focusController().setFocusedFrame(parent); |
953 // setFocusedFrame can dispatch synchronous focus/blur events. The document | 962 // setFocusedFrame can dispatch synchronous focus/blur events. The document |
954 // tree might be modified. | 963 // tree might be modified. |
955 if (newSelection.isNonOrphanedCaretOrRange()) | 964 if (newSelection.isNonOrphanedCaretOrRange()) |
956 toLocalFrame(parent)->selection().setSelection(newSelection); | 965 toLocalFrame(parent)->selection().setSelection(newSelection); |
957 } | 966 } |
958 | 967 |
959 // Returns a shadow tree node for legacy shadow trees, a child of the | 968 // 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. | 969 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. |
961 static Node* nonBoundaryShadowTreeRootNode(const Position& position) { | 970 static Node* nonBoundaryShadowTreeRootNode(const Position& position) { |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1380 | 1389 |
1381 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) { | 1390 bool FrameSelection::selectWordAroundPosition(const VisiblePosition& position) { |
1382 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary, | 1391 static const EWordSide wordSideList[2] = {RightWordIfOnBoundary, |
1383 LeftWordIfOnBoundary}; | 1392 LeftWordIfOnBoundary}; |
1384 for (EWordSide wordSide : wordSideList) { | 1393 for (EWordSide wordSide : wordSideList) { |
1385 VisiblePosition start = startOfWord(position, wordSide); | 1394 VisiblePosition start = startOfWord(position, wordSide); |
1386 VisiblePosition end = endOfWord(position, wordSide); | 1395 VisiblePosition end = endOfWord(position, wordSide); |
1387 String text = | 1396 String text = |
1388 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent())); | 1397 plainText(EphemeralRange(start.deepEquivalent(), end.deepEquivalent())); |
1389 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { | 1398 if (!text.isEmpty() && !isSeparator(text.characterStartingAt(0))) { |
1390 setSelection(createVisibleSelection(start, end), | 1399 setSelection( |
1391 CloseTyping | ClearTypingStyle, | 1400 createVisibleSelection(SelectionInDOMTree::Builder() |
1392 CursorAlignOnScroll::IfNeeded, WordGranularity); | 1401 .collapse(start.toPositionWithAffinity()) |
1402 .extend(end.deepEquivalent()) | |
1403 .build()), | |
1404 CloseTyping | ClearTypingStyle, CursorAlignOnScroll::IfNeeded, | |
1405 WordGranularity); | |
1393 return true; | 1406 return true; |
1394 } | 1407 } |
1395 } | 1408 } |
1396 | 1409 |
1397 return false; | 1410 return false; |
1398 } | 1411 } |
1399 | 1412 |
1400 GranularityStrategy* FrameSelection::granularityStrategy() { | 1413 GranularityStrategy* FrameSelection::granularityStrategy() { |
1401 // We do lazy initalization for m_granularityStrategy, because if we | 1414 // We do lazy initalization for m_granularityStrategy, because if we |
1402 // initialize it right in the constructor - the correct settings may not be | 1415 // initialize it right in the constructor - the correct settings may not be |
(...skipping 21 matching lines...) Expand all Loading... | |
1424 granularityStrategy()->updateExtent(contentsPoint, m_frame); | 1437 granularityStrategy()->updateExtent(contentsPoint, m_frame); |
1425 setSelection(newSelection, | 1438 setSelection(newSelection, |
1426 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | | 1439 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
1427 FrameSelection::DoNotClearStrategy | UserTriggered, | 1440 FrameSelection::DoNotClearStrategy | UserTriggered, |
1428 CursorAlignOnScroll::IfNeeded, CharacterGranularity); | 1441 CursorAlignOnScroll::IfNeeded, CharacterGranularity); |
1429 } | 1442 } |
1430 | 1443 |
1431 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, | 1444 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, |
1432 const VisiblePosition& extentPosition, | 1445 const VisiblePosition& extentPosition, |
1433 TextGranularity granularity) { | 1446 TextGranularity granularity) { |
1434 VisibleSelection newSelection = | 1447 SelectionInDOMTree::Builder builder; |
1435 createVisibleSelection(basePosition, extentPosition); | 1448 if (basePosition.isNotNull() && extentPosition.isNotNull()) { |
Xiaocheng
2016/10/21 11:18:36
Let's use setBaseAndExtentDeprecated, since having
yosin_UTC9
2016/10/24 06:19:44
Done
| |
1449 builder.collapse(basePosition.toPositionWithAffinity()) | |
1450 .extend(extentPosition.deepEquivalent()); | |
1451 } else if (basePosition.isNotNull()) { | |
1452 builder.collapse(basePosition.toPositionWithAffinity()); | |
1453 } else if (extentPosition.isNotNull()) { | |
1454 builder.collapse(extentPosition.toPositionWithAffinity()); | |
1455 } | |
1456 | |
1457 VisibleSelection newSelection = createVisibleSelection(builder.build()); | |
1436 newSelection.expandUsingGranularity(granularity); | 1458 newSelection.expandUsingGranularity(granularity); |
1437 | 1459 |
1438 if (newSelection.isNone()) | 1460 if (newSelection.isNone()) |
1439 return; | 1461 return; |
1440 | 1462 |
1441 setSelection(newSelection, CloseTyping | ClearTypingStyle, | 1463 setSelection(newSelection, CloseTyping | ClearTypingStyle, |
1442 CursorAlignOnScroll::IfNeeded, granularity); | 1464 CursorAlignOnScroll::IfNeeded, granularity); |
1443 } | 1465 } |
1444 | 1466 |
1445 void FrameSelection::updateIfNeeded() { | 1467 void FrameSelection::updateIfNeeded() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1485 } | 1507 } |
1486 | 1508 |
1487 void showTree(const blink::FrameSelection* sel) { | 1509 void showTree(const blink::FrameSelection* sel) { |
1488 if (sel) | 1510 if (sel) |
1489 sel->showTreeForThis(); | 1511 sel->showTreeForThis(); |
1490 else | 1512 else |
1491 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1513 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1492 } | 1514 } |
1493 | 1515 |
1494 #endif | 1516 #endif |
OLD | NEW |