Chromium Code Reviews| 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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 } | 649 } |
| 650 | 650 |
| 651 // Returns a shadow tree node for legacy shadow trees, a child of the | 651 // Returns a shadow tree node for legacy shadow trees, a child of the |
| 652 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. | 652 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. |
| 653 static Node* NonBoundaryShadowTreeRootNode(const Position& position) { | 653 static Node* NonBoundaryShadowTreeRootNode(const Position& position) { |
| 654 return position.AnchorNode() && !position.AnchorNode()->IsShadowRoot() | 654 return position.AnchorNode() && !position.AnchorNode()->IsShadowRoot() |
| 655 ? position.AnchorNode()->NonBoundaryShadowTreeRootNode() | 655 ? position.AnchorNode()->NonBoundaryShadowTreeRootNode() |
| 656 : nullptr; | 656 : nullptr; |
| 657 } | 657 } |
| 658 | 658 |
| 659 void FrameSelection::SelectAll() { | 659 void FrameSelection::SelectAll(EUserTriggered user_triggered) { |
| 660 if (isHTMLSelectElement(GetDocument().FocusedElement())) { | 660 if (isHTMLSelectElement(GetDocument().FocusedElement())) { |
| 661 HTMLSelectElement* select_element = | 661 HTMLSelectElement* select_element = |
| 662 toHTMLSelectElement(GetDocument().FocusedElement()); | 662 toHTMLSelectElement(GetDocument().FocusedElement()); |
| 663 if (select_element->CanSelectAll()) { | 663 if (select_element->CanSelectAll()) { |
| 664 select_element->SelectAll(); | 664 select_element->SelectAll(); |
| 665 return; | 665 return; |
| 666 } | 666 } |
| 667 } | 667 } |
| 668 | 668 |
| 669 Node* root = nullptr; | 669 Node* root = nullptr; |
| 670 Node* select_start_target = nullptr; | 670 Node* select_start_target = nullptr; |
| 671 if (ComputeVisibleSelectionInDOMTree().IsContentEditable()) { | 671 if (user_triggered == kUserTriggered && IsHidden()) { |
| 672 // Hidden selection appears as no selection to user, in which case user- | |
| 673 // triggered SelectAll should act as if there is no selection. | |
| 674 root = GetDocument().documentElement(); | |
| 675 select_start_target = GetDocument().body(); | |
| 676 } else if (ComputeVisibleSelectionInDOMTree().IsContentEditable()) { | |
| 672 root = HighestEditableRoot(ComputeVisibleSelectionInDOMTree().Start()); | 677 root = HighestEditableRoot(ComputeVisibleSelectionInDOMTree().Start()); |
| 673 if (Node* shadow_root = NonBoundaryShadowTreeRootNode( | 678 if (Node* shadow_root = NonBoundaryShadowTreeRootNode( |
| 674 ComputeVisibleSelectionInDOMTree().Start())) | 679 ComputeVisibleSelectionInDOMTree().Start())) |
| 675 select_start_target = shadow_root->OwnerShadowHost(); | 680 select_start_target = shadow_root->OwnerShadowHost(); |
| 676 else | 681 else |
| 677 select_start_target = root; | 682 select_start_target = root; |
| 678 } else { | 683 } else { |
| 679 root = NonBoundaryShadowTreeRootNode( | 684 root = NonBoundaryShadowTreeRootNode( |
| 680 ComputeVisibleSelectionInDOMTree().Start()); | 685 ComputeVisibleSelectionInDOMTree().Start()); |
| 681 if (root) { | 686 if (root) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 696 // The frame may be detached due to selectstart event. | 701 // The frame may be detached due to selectstart event. |
| 697 if (!IsAvailable()) { | 702 if (!IsAvailable()) { |
| 698 // Reached by editing/selection/selectstart_detach_frame.html | 703 // Reached by editing/selection/selectstart_detach_frame.html |
| 699 return; | 704 return; |
| 700 } | 705 } |
| 701 // |root| may be detached due to selectstart event. | 706 // |root| may be detached due to selectstart event. |
| 702 if (!root->isConnected() || expected_document != root->GetDocument()) | 707 if (!root->isConnected() || expected_document != root->GetDocument()) |
| 703 return; | 708 return; |
| 704 } | 709 } |
| 705 | 710 |
| 711 // TODO(editing-dev): Should we pass in user_triggered? | |
|
yosin_UTC9
2017/05/19 02:19:36
Duplicated to L717? Or, do we want to pass |user_t
Xiaocheng
2017/05/19 02:25:51
Not duplicate. SetSelection() takes an |option| wh
| |
| 706 SetSelection(SelectionInDOMTree::Builder() | 712 SetSelection(SelectionInDOMTree::Builder() |
| 707 .SelectAllChildren(*root) | 713 .SelectAllChildren(*root) |
| 708 .SetIsHandleVisible(IsHandleVisible()) | 714 .SetIsHandleVisible(IsHandleVisible()) |
| 709 .Build()); | 715 .Build()); |
| 710 SelectFrameElementInParentIfFullySelected(); | 716 SelectFrameElementInParentIfFullySelected(); |
| 717 // TODO(editing-dev): Should we pass in user_triggered? | |
| 711 NotifyTextControlOfSelectionChange(kUserTriggered); | 718 NotifyTextControlOfSelectionChange(kUserTriggered); |
| 712 } | 719 } |
| 713 | 720 |
| 714 bool FrameSelection::SetSelectedRange(const EphemeralRange& range, | 721 bool FrameSelection::SetSelectedRange(const EphemeralRange& range, |
| 715 TextAffinity affinity, | 722 TextAffinity affinity, |
| 716 SelectionDirectionalMode directional, | 723 SelectionDirectionalMode directional, |
| 717 SetSelectionOptions options) { | 724 SetSelectionOptions options) { |
| 718 if (range.IsNull()) | 725 if (range.IsNull()) |
| 719 return false; | 726 return false; |
| 720 SetSelection(SelectionInDOMTree::Builder() | 727 SetSelection(SelectionInDOMTree::Builder() |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1218 } | 1225 } |
| 1219 | 1226 |
| 1220 void showTree(const blink::FrameSelection* sel) { | 1227 void showTree(const blink::FrameSelection* sel) { |
| 1221 if (sel) | 1228 if (sel) |
| 1222 sel->ShowTreeForThis(); | 1229 sel->ShowTreeForThis(); |
| 1223 else | 1230 else |
| 1224 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1231 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
| 1225 } | 1232 } |
| 1226 | 1233 |
| 1227 #endif | 1234 #endif |
| OLD | NEW |