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

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

Issue 2712603007: Select All present even all selectable text has been selected (Closed)
Patch Set: Created 3 years, 9 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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 619 }
620 620
621 // Returns a shadow tree node for legacy shadow trees, a child of the 621 // Returns a shadow tree node for legacy shadow trees, a child of the
622 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees. 622 // ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
623 static Node* nonBoundaryShadowTreeRootNode(const Position& position) { 623 static Node* nonBoundaryShadowTreeRootNode(const Position& position) {
624 return position.anchorNode() && !position.anchorNode()->isShadowRoot() 624 return position.anchorNode() && !position.anchorNode()->isShadowRoot()
625 ? position.anchorNode()->nonBoundaryShadowTreeRootNode() 625 ? position.anchorNode()->nonBoundaryShadowTreeRootNode()
626 : nullptr; 626 : nullptr;
627 } 627 }
628 628
629 void FrameSelection::selectAll() { 629 Node* FrameSelection::selectAllRoot() {
yosin_UTC9 2017/02/27 03:46:40 Since this function returns root node for "SelectA
amaralp 2017/02/27 05:02:18 Renamed to |computeRootNodeForSelectAll()|.
630 if (isHTMLSelectElement(document().focusedElement())) {
631 HTMLSelectElement* selectElement =
632 toHTMLSelectElement(document().focusedElement());
633 if (selectElement->canSelectAll()) {
634 selectElement->selectAll();
635 return;
636 }
637 }
638
639 Node* root = nullptr; 630 Node* root = nullptr;
640 Node* selectStartTarget = nullptr; 631 Node* selectStartTarget = nullptr;
641 if (computeVisibleSelectionInDOMTreeDeprecated().isContentEditable()) { 632 if (computeVisibleSelectionInDOMTreeDeprecated().isContentEditable()) {
642 root = highestEditableRoot( 633 root = highestEditableRoot(
643 computeVisibleSelectionInDOMTreeDeprecated().start()); 634 computeVisibleSelectionInDOMTreeDeprecated().start());
644 if (Node* shadowRoot = nonBoundaryShadowTreeRootNode( 635 if (Node* shadowRoot = nonBoundaryShadowTreeRootNode(
645 computeVisibleSelectionInDOMTreeDeprecated().start())) 636 computeVisibleSelectionInDOMTreeDeprecated().start()))
646 selectStartTarget = shadowRoot->ownerShadowHost(); 637 selectStartTarget = shadowRoot->ownerShadowHost();
647 else 638 else
648 selectStartTarget = root; 639 selectStartTarget = root;
649 } else { 640 } else {
650 root = nonBoundaryShadowTreeRootNode( 641 root = nonBoundaryShadowTreeRootNode(
651 computeVisibleSelectionInDOMTreeDeprecated().start()); 642 computeVisibleSelectionInDOMTreeDeprecated().start());
652 if (root) { 643 if (root) {
653 selectStartTarget = root->ownerShadowHost(); 644 selectStartTarget = root->ownerShadowHost();
654 } else { 645 } else {
655 root = document().documentElement(); 646 root = document().documentElement();
656 selectStartTarget = document().body(); 647 selectStartTarget = document().body();
657 } 648 }
658 } 649 }
659 if (!root || editingIgnoresContent(*root)) 650 if (!root || editingIgnoresContent(*root))
660 return; 651 return nullptr;
661 652
662 if (selectStartTarget) { 653 if (selectStartTarget) {
663 const Document& expectedDocument = document(); 654 const Document& expectedDocument = document();
664 if (selectStartTarget->dispatchEvent(Event::createCancelableBubble( 655 if (selectStartTarget->dispatchEvent(Event::createCancelableBubble(
665 EventTypeNames::selectstart)) != DispatchEventResult::NotCanceled) 656 EventTypeNames::selectstart)) != DispatchEventResult::NotCanceled)
666 return; 657 return nullptr;
667 // |root| may be detached due to selectstart event. 658 // |root| may be detached due to selectstart event.
668 if (!root->isConnected() || expectedDocument != root->document()) 659 if (!root->isConnected() || expectedDocument != root->document())
660 return nullptr;
661 }
662 return root;
663 }
664
665 void FrameSelection::selectAll() {
666 if (isHTMLSelectElement(document().focusedElement())) {
yosin_UTC9 2017/02/27 03:46:40 Since document.focusedElement() can be null, pleas
amaralp 2017/02/27 05:02:18 |isHTMLSelectElement()| already does the null chec
667 HTMLSelectElement* selectElement =
668 toHTMLSelectElement(document().focusedElement());
669 if (selectElement->canSelectAll()) {
670 selectElement->selectAll();
669 return; 671 return;
672 }
670 } 673 }
671 674
675 Node* root = selectAllRoot();
676 if (!root)
677 return;
672 setSelection(SelectionInDOMTree::Builder() 678 setSelection(SelectionInDOMTree::Builder()
673 .selectAllChildren(*root) 679 .selectAllChildren(*root)
674 .setIsHandleVisible(isHandleVisible()) 680 .setIsHandleVisible(isHandleVisible())
675 .build()); 681 .build());
676 selectFrameElementInParentIfFullySelected(); 682 selectFrameElementInParentIfFullySelected();
677 notifyLayoutObjectOfSelectionChange(UserTriggered); 683 notifyLayoutObjectOfSelectionChange(UserTriggered);
678 } 684 }
679 685
686 bool FrameSelection::canSelectAll() {
yosin_UTC9 2017/02/27 03:46:40 It is better to implement in |Editor| class rather
amaralp 2017/02/27 05:02:18 Moved it to |Editor|.
687 if (isHTMLSelectElement(document().focusedElement())) {
yosin_UTC9 2017/02/27 03:46:40 Since document.focusedElement() can be null, pleas
amaralp 2017/02/27 05:02:18 |isHTMLSelectElement()| already does the null chec
688 HTMLSelectElement* selectElement =
689 toHTMLSelectElement(document().focusedElement());
690 if (selectElement->canSelectAll()) {
yosin_UTC9 2017/02/27 03:46:40 nit: We don't need to have braces.
amaralp 2017/02/27 05:02:18 Done.
691 return false;
692 }
693 }
694 Node* root = selectAllRoot();
695 if (!root)
696 return false;
697 return !(selectionInDOMTree().base() == Position::firstPositionInNode(root) &&
698 selectionInDOMTree().extent() == Position::lastPositionInNode(root));
699 }
700
680 bool FrameSelection::setSelectedRange(const EphemeralRange& range, 701 bool FrameSelection::setSelectedRange(const EphemeralRange& range,
681 TextAffinity affinity, 702 TextAffinity affinity,
682 SelectionDirectionalMode directional, 703 SelectionDirectionalMode directional,
683 SetSelectionOptions options) { 704 SetSelectionOptions options) {
684 if (range.isNull()) 705 if (range.isNull())
685 return false; 706 return false;
686 m_selectionEditor->resetLogicalRange(); 707 m_selectionEditor->resetLogicalRange();
687 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree 708 // Since |FrameSeleciton::setSelection()| dispatches events and DOM tree
688 // can be modified by event handlers, we should create |Range| object before 709 // can be modified by event handlers, we should create |Range| object before
689 // calling it. 710 // calling it.
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 } 1211 }
1191 1212
1192 void showTree(const blink::FrameSelection* sel) { 1213 void showTree(const blink::FrameSelection* sel) {
1193 if (sel) 1214 if (sel)
1194 sel->showTreeForThis(); 1215 sel->showTreeForThis();
1195 else 1216 else
1196 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1217 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1197 } 1218 }
1198 1219
1199 #endif 1220 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.h ('k') | third_party/WebKit/Source/web/ContextMenuClientImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698