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

Side by Side Diff: third_party/WebKit/Source/web/WebLocalFrameImpl.cpp

Issue 2251703002: Introduce EphemeralRange::nodes() helper to traverse over a range. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move default template to right place Created 4 years, 4 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 1636
1637 // Try to find the first focusable node up the chain, which will, for 1637 // Try to find the first focusable node up the chain, which will, for
1638 // example, focus links if we have found text within the link. 1638 // example, focus links if we have found text within the link.
1639 Node* node = activeMatch->firstNode(); 1639 Node* node = activeMatch->firstNode();
1640 if (node && node->isInShadowTree()) { 1640 if (node && node->isInShadowTree()) {
1641 if (Node* host = node->shadowHost()) { 1641 if (Node* host = node->shadowHost()) {
1642 if (isHTMLInputElement(*host) || isHTMLTextAreaElement(*host)) 1642 if (isHTMLInputElement(*host) || isHTMLTextAreaElement(*host))
1643 node = host; 1643 node = host;
1644 } 1644 }
1645 } 1645 }
1646 const EphemeralRange activeMatchRange(activeMatch);
1646 if (node) { 1647 if (node) {
1647 for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*node)) { 1648 for (Node& runner : NodeTraversal::inclusiveAncestorsOf(*node)) {
1648 if (!runner.isElementNode()) 1649 if (!runner.isElementNode())
1649 continue; 1650 continue;
1650 Element& element = toElement(runner); 1651 Element& element = toElement(runner);
1651 if (element.isFocusable()) { 1652 if (element.isFocusable()) {
1652 // Found a focusable parent node. Set the active match as th e 1653 // Found a focusable parent node. Set the active match as th e
1653 // selection and focus to the focusable node. 1654 // selection and focus to the focusable node.
1654 frame()->selection().setSelection(VisibleSelection(Ephemeral Range(activeMatch))); 1655 frame()->selection().setSelection(VisibleSelection(activeMat chRange));
1655 frame()->document()->setFocusedElement(&element, FocusParams (SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); 1656 frame()->document()->setFocusedElement(&element, FocusParams (SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr));
1656 return; 1657 return;
1657 } 1658 }
1658 } 1659 }
1659 } 1660 }
1660 1661
1661 // Iterate over all the nodes in the range until we find a focusable nod e. 1662 // Iterate over all the nodes in the range until we find a focusable nod e.
1662 // This, for example, sets focus to the first link if you search for 1663 // This, for example, sets focus to the first link if you search for
1663 // text and text that is within one or more links. 1664 // text and text that is within one or more links.
1664 node = activeMatch->firstNode(); 1665 for (Node& runner : activeMatchRange.nodes()) {
1665 for (; node && node != activeMatch->pastLastNode(); node = NodeTraversal ::next(*node)) { 1666 if (!runner.isElementNode())
1666 if (!node->isElementNode())
1667 continue; 1667 continue;
1668 Element* element = toElement(node); 1668 Element& element = toElement(runner);
1669 if (element->isFocusable()) { 1669 if (element.isFocusable()) {
1670 frame()->document()->setFocusedElement(element, FocusParams(Sele ctionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); 1670 frame()->document()->setFocusedElement(&element, FocusParams(Sel ectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr));
1671 return; 1671 return;
1672 } 1672 }
1673 } 1673 }
1674 1674
1675 // No node related to the active match was focusable, so set the 1675 // No node related to the active match was focusable, so set the
1676 // active match as the selection (so that when you end the Find session, 1676 // active match as the selection (so that when you end the Find session,
1677 // you'll have the last thing you found highlighted) and make sure that 1677 // you'll have the last thing you found highlighted) and make sure that
1678 // we have nothing focused (otherwise you might have text selected but 1678 // we have nothing focused (otherwise you might have text selected but
1679 // a link focused, which is weird). 1679 // a link focused, which is weird).
1680 frame()->selection().setSelection(VisibleSelection(EphemeralRange(active Match))); 1680 frame()->selection().setSelection(VisibleSelection(activeMatchRange));
1681 frame()->document()->clearFocusedElement(); 1681 frame()->document()->clearFocusedElement();
1682 1682
1683 // Finally clear the active match, for two reasons: 1683 // Finally clear the active match, for two reasons:
1684 // We just finished the find 'session' and we don't want future (potenti ally 1684 // We just finished the find 'session' and we don't want future (potenti ally
1685 // unrelated) find 'sessions' operations to start at the same place. 1685 // unrelated) find 'sessions' operations to start at the same place.
1686 // The WebLocalFrameImpl could get reused and the activeMatch could end up pointing 1686 // The WebLocalFrameImpl could get reused and the activeMatch could end up pointing
1687 // to a document that is no longer valid. Keeping an invalid reference a round 1687 // to a document that is no longer valid. Keeping an invalid reference a round
1688 // is just asking for trouble. 1688 // is just asking for trouble.
1689 m_textFinder->resetActiveMatch(); 1689 m_textFinder->resetActiveMatch();
1690 } 1690 }
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 { 2149 {
2150 frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags)); 2150 frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags));
2151 } 2151 }
2152 2152
2153 void WebLocalFrameImpl::clearActiveFindMatch() 2153 void WebLocalFrameImpl::clearActiveFindMatch()
2154 { 2154 {
2155 ensureTextFinder().clearActiveFindMatch(); 2155 ensureTextFinder().clearActiveFindMatch();
2156 } 2156 }
2157 2157
2158 } // namespace blink 2158 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698