Changeset 150733 in webkit


Ignore:
Timestamp:
May 26, 2013 7:07:54 PM (11 years ago)
Author:
akling@apple.com
Message:

Turn TreeScope::focusedNode() into focusedElement().
<http://webkit.org/b/116802>

Reviewed by Darin Adler.

For the hundredth time, only Elements can be focused!

This change mostly reverts r121079 since that made things unnecessarily complicated
just to tweak the behavior of ShadowRoot.activeElement, an API that we don't expose.
Finding a TreeScope's focused element now does a simple walk up the parent chain instead
of running the full Shadow DOM re-targeting algorithm.

(WebCore::TreeScope::focusedElement):

Simplify and return Element* instead of Node*.

  • dom/TreeScope.h:
  • dom/TreeScope.cpp:

(WebCore::focusedFrameOwnerElement):

Make this return Element* as the name already suggested.

  • dom/Document.cpp:

(WebCore::Document::removeFocusedNodeOfSubtree):

  • dom/Element.cpp:

(WebCore::Element::blur):

  • dom/ShadowRoot.h:

(WebCore::ShadowRoot::activeElement):

  • html/HTMLDocument.cpp:

(WebCore::HTMLDocument::activeElement):

Simplified call sites that were paranoid about getting a non-Element focused node.

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150731 r150733  
     12013-05-26  Andreas Kling  <akling@apple.com>
     2
     3        Turn TreeScope::focusedNode() into focusedElement().
     4        <http://webkit.org/b/116802>
     5
     6        Reviewed by Darin Adler.
     7
     8        For the hundredth time, only Elements can be focused!
     9
     10        This change mostly reverts r121079 since that made things unnecessarily complicated
     11        just to tweak the behavior of ShadowRoot.activeElement, an API that we don't expose.
     12        Finding a TreeScope's focused element now does a simple walk up the parent chain instead
     13        of running the full Shadow DOM re-targeting algorithm.
     14
     15        (WebCore::TreeScope::focusedElement):
     16
     17            Simplify and return Element* instead of Node*.
     18
     19        * dom/TreeScope.h:
     20        * dom/TreeScope.cpp:
     21        (WebCore::focusedFrameOwnerElement):
     22
     23            Make this return Element* as the name already suggested.
     24
     25        * dom/Document.cpp:
     26        (WebCore::Document::removeFocusedNodeOfSubtree):
     27        * dom/Element.cpp:
     28        (WebCore::Element::blur):
     29        * dom/ShadowRoot.h:
     30        (WebCore::ShadowRoot::activeElement):
     31        * html/HTMLDocument.cpp:
     32        (WebCore::HTMLDocument::activeElement):
     33
     34            Simplified call sites that were paranoid about getting a non-Element focused node.
     35
    1362013-05-26  Dean Jackson  <dino@apple.com>
    237
  • trunk/Source/WebCore/dom/Document.cpp

    r150722 r150733  
    32703270        return;
    32713271
    3272     Node* focusedNode = node->treeScope()->focusedNode();
    3273     if (!focusedNode)
     3272    Element* focusedElement = node->treeScope()->focusedElement();
     3273    if (!focusedElement)
    32743274        return;
    32753275
    32763276    bool nodeInSubtree = false;
    32773277    if (amongChildrenOnly)
    3278         nodeInSubtree = focusedNode->isDescendantOf(node);
     3278        nodeInSubtree = focusedElement->isDescendantOf(node);
    32793279    else
    3280         nodeInSubtree = (focusedNode == node) || focusedNode->isDescendantOf(node);
     3280        nodeInSubtree = (focusedElement == node) || focusedElement->isDescendantOf(node);
    32813281   
    32823282    if (nodeInSubtree)
  • trunk/Source/WebCore/dom/Element.cpp

    r150722 r150733  
    21512151    cancelFocusAppearanceUpdate();
    21522152    Document* doc = document();
    2153     if (treeScope()->focusedNode() == this) {
     2153    if (treeScope()->focusedElement() == this) {
    21542154        if (doc->frame())
    21552155            doc->frame()->page()->focusController()->setFocusedElement(0, doc->frame());
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r150480 r150733  
    102102inline Element* ShadowRoot::activeElement() const
    103103{
    104     if (Node* node = treeScope()->focusedNode())
    105         return node->isElementNode() ? toElement(node) : 0;
    106     return 0;
     104    return treeScope()->focusedElement();
    107105}
    108106
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r150187 r150733  
    11/*
    22 * Copyright (C) 2011 Google Inc. All Rights Reserved.
    3  * Copyright (C) 2012 Apple Inc. All rights reserved.
     3 * Copyright (C) 2012, 2013 Apple Inc. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    3333#include "Document.h"
    3434#include "Element.h"
    35 #include "EventPathWalker.h"
    3635#include "FocusController.h"
    3736#include "Frame.h"
     
    4443#include "HitTestResult.h"
    4544#include "IdTargetObserverRegistry.h"
    46 #include "InsertionPoint.h"
    4745#include "NodeTraversal.h"
    4846#include "Page.h"
     
    383381}
    384382
    385 static Node* focusedFrameOwnerElement(Frame* focusedFrame, Frame* currentFrame)
     383static Element* focusedFrameOwnerElement(Frame* focusedFrame, Frame* currentFrame)
    386384{
    387385    for (; focusedFrame; focusedFrame = focusedFrame->tree()->parent()) {
     
    392390}
    393391
    394 Node* TreeScope::focusedNode()
     392Element* TreeScope::focusedElement()
    395393{
    396394    Document* document = rootNode()->document();
    397395    Node* node = document->focusedNode();
    398     if (!node && document->page())
    399         node = focusedFrameOwnerElement(document->page()->focusController()->focusedFrame(), document->frame());
    400     if (!node)
    401         return 0;
    402     Vector<Node*> targetStack;
    403     for (EventPathWalker walker(node); walker.node(); walker.moveToParent()) {
    404         Node* node = walker.node();
    405         if (targetStack.isEmpty())
    406             targetStack.append(node);
    407         else if (walker.isVisitingInsertionPointInReprojection())
    408             targetStack.append(targetStack.last());
    409         if (node == rootNode())
    410             return targetStack.last();
    411         if (node->isShadowRoot()) {
    412             ASSERT(!targetStack.isEmpty());
    413             targetStack.removeLast();
    414         }
    415     }
    416     return 0;
     396
     397    ASSERT(!node || node->isElementNode());
     398    Element* element = toElement(node);
     399
     400    if (!element && document->page())
     401        element = focusedFrameOwnerElement(document->page()->focusController()->focusedFrame(), document->frame());
     402    if (!element)
     403        return 0;
     404    TreeScope* treeScope = element->treeScope();
     405    while (treeScope != this && treeScope != document) {
     406        element = toShadowRoot(treeScope->rootNode())->host();
     407        treeScope = element->treeScope();
     408    }
     409    if (this != treeScope)
     410        return 0;
     411    return element;
    417412}
    418413
  • trunk/Source/WebCore/dom/TreeScope.h

    r150713 r150733  
    5555    void setParentTreeScope(TreeScope*);
    5656
    57     Node* focusedNode();
     57    Element* focusedElement();
    5858    Element* getElementById(const AtomicString&) const;
    5959    const Vector<Element*>* getAllElementsById(const AtomicString&) const;
  • trunk/Source/WebCore/html/HTMLDocument.cpp

    r149705 r150733  
    140140Element* HTMLDocument::activeElement()
    141141{
    142     if (Node* node = treeScope()->focusedNode())
    143         return node->isElementNode() ? toElement(node) : body();
     142    if (Element* element = treeScope()->focusedElement())
     143        return element;
    144144    return body();
    145145}
Note: See TracChangeset for help on using the changeset viewer.