Changeset 150715 in webkit


Ignore:
Timestamp:
May 26, 2013 7:29:15 AM (11 years ago)
Author:
akling@apple.com
Message:

Move "active" state logic from Node to Element.
<http://webkit.org/b/116785>

Reviewed by Antti Koivisto.

Resolve another 7 year old FIXME by merging the "active" state logic from Node and ContainerNode
and moving it all to Element instead.

  • dom/UserActionElementSet.h:

(WebCore::UserActionElementSet::isActive):
(WebCore::UserActionElementSet::setActive):

  • dom/ContainerNode.cpp:
  • dom/ContainerNode.h:
  • dom/Node.cpp:
  • dom/Node.h:
  • dom/Element.h:

(WebCore::Element::active):

  • dom/Element.cpp:

(WebCore::Element::isUserActionElementActive):
(WebCore::Element::setActive):

Moved here from Node/ContainerNode.

  • accessibility/AccessibilityNodeObject.cpp:

(WebCore::AccessibilityNodeObject::isPressed):

  • dom/Document.cpp:

(WebCore::Document::setFocusedNode):
(WebCore::Document::updateHoverActiveState):

  • rendering/RenderTheme.cpp:

(WebCore::RenderTheme::isPressed):
(WebCore::RenderTheme::isSpinUpButtonPartPressed):

  • rendering/RenderThemeMac.mm:

(WebCore::getMediaUIPartStateFlags):
(WebCore::RenderThemeMac::updatePressedState):

  • platform/qt/RenderThemeQt.cpp:

(WebCore::RenderThemeQt::getMediaControlForegroundColor):

Check that the inspected Node is an Element before asking if it's active.

  • html/HTMLAnchorElement.cpp:

(WebCore::HTMLAnchorElement::setActive):

Call the right superclass.

  • html/HTMLAnchorElement.h:
  • html/HTMLLabelElement.h:
  • html/shadow/MediaControlElementTypes.h:

Sprinkle OVERRIDE>

Location:
trunk/Source/WebCore
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150714 r150715  
     12013-05-26  Andreas Kling  <akling@apple.com>
     2
     3        Move "active" state logic from Node to Element.
     4        <http://webkit.org/b/116785>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Resolve another 7 year old FIXME by merging the "active" state logic from Node and ContainerNode
     9        and moving it all to Element instead.
     10
     11        * dom/UserActionElementSet.h:
     12        (WebCore::UserActionElementSet::isActive):
     13        (WebCore::UserActionElementSet::setActive):
     14        * dom/ContainerNode.cpp:
     15        * dom/ContainerNode.h:
     16        * dom/Node.cpp:
     17        * dom/Node.h:
     18        * dom/Element.h:
     19        (WebCore::Element::active):
     20        * dom/Element.cpp:
     21        (WebCore::Element::isUserActionElementActive):
     22        (WebCore::Element::setActive):
     23
     24            Moved here from Node/ContainerNode.
     25
     26        * accessibility/AccessibilityNodeObject.cpp:
     27        (WebCore::AccessibilityNodeObject::isPressed):
     28        * dom/Document.cpp:
     29        (WebCore::Document::setFocusedNode):
     30        (WebCore::Document::updateHoverActiveState):
     31        * rendering/RenderTheme.cpp:
     32        (WebCore::RenderTheme::isPressed):
     33        (WebCore::RenderTheme::isSpinUpButtonPartPressed):
     34        * rendering/RenderThemeMac.mm:
     35        (WebCore::getMediaUIPartStateFlags):
     36        (WebCore::RenderThemeMac::updatePressedState):
     37        * platform/qt/RenderThemeQt.cpp:
     38        (WebCore::RenderThemeQt::getMediaControlForegroundColor):
     39
     40            Check that the inspected Node is an Element before asking if it's active.
     41
     42        * html/HTMLAnchorElement.cpp:
     43        (WebCore::HTMLAnchorElement::setActive):
     44
     45            Call the right superclass.
     46
     47        * html/HTMLAnchorElement.h:
     48        * html/HTMLLabelElement.h:
     49        * html/shadow/MediaControlElementTypes.h:
     50
     51            Sprinkle OVERRIDE>
     52
    1532013-05-26  Andreas Kling  <akling@apple.com>
    254
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp

    r150710 r150715  
    635635    }
    636636
    637     return node->active();
     637    if (!node->isElementNode())
     638        return false;
     639    return toElement(node)->active();
    638640}
    639641
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r150686 r150715  
    969969}
    970970
    971 void ContainerNode::setActive(bool down, bool pause)
    972 {
    973     if (down == active()) return;
    974 
    975     Node::setActive(down);
    976 
    977     // note that we need to recalc the style
    978     // FIXME: Move to Element
    979     if (renderer()) {
    980         bool reactsToPress = renderStyle()->affectedByActive() || (isElementNode() && toElement(this)->childrenAffectedByActive());
    981         if (reactsToPress)
    982             setNeedsStyleRecalc();
    983         if (renderStyle()->hasAppearance()) {
    984             if (renderer()->theme()->stateChanged(renderer(), PressedState))
    985                 reactsToPress = true;
    986         }
    987 
    988         // The rest of this function implements a feature that only works if the
    989         // platform supports immediate invalidations on the ChromeClient, so bail if
    990         // that isn't supported.
    991         if (!document()->page()->chrome().client()->supportsImmediateInvalidation())
    992             return;
    993 
    994         if (reactsToPress && pause) {
    995             // The delay here is subtle.  It relies on an assumption, namely that the amount of time it takes
    996             // to repaint the "down" state of the control is about the same time as it would take to repaint the
    997             // "up" state.  Once you assume this, you can just delay for 100ms - that time (assuming that after you
    998             // leave this method, it will be about that long before the flush of the up state happens again).
    999 #ifdef HAVE_FUNC_USLEEP
    1000             double startTime = currentTime();
    1001 #endif
    1002 
    1003             // Ensure there are no pending changes
    1004             Document::updateStyleForAllDocuments();
    1005             // Do an immediate repaint.
    1006             if (renderer())
    1007                 renderer()->repaint(true);
    1008 
    1009             // FIXME: Find a substitute for usleep for Win32.
    1010             // Better yet, come up with a way of doing this that doesn't use this sort of thing at all.
    1011 #ifdef HAVE_FUNC_USLEEP
    1012             // Now pause for a small amount of time (1/10th of a second from before we repainted in the pressed state)
    1013             double remainingTime = 0.1 - (currentTime() - startTime);
    1014             if (remainingTime > 0)
    1015                 usleep(static_cast<useconds_t>(remainingTime * 1000000.0));
    1016 #endif
    1017         }
    1018     }
    1019 }
    1020 
    1021971unsigned ContainerNode::childNodeCount() const
    1022972{
  • trunk/Source/WebCore/dom/ContainerNode.h

    r150713 r150715  
    110110    virtual void detach() OVERRIDE;
    111111    virtual LayoutRect boundingBox() const OVERRIDE;
    112     virtual void setActive(bool active = true, bool pause = false) OVERRIDE;
    113112    virtual void scheduleSetNeedsStyleRecalc(StyleChangeType = FullStyleChange) OVERRIDE FINAL;
    114113
  • trunk/Source/WebCore/dom/Document.cpp

    r150713 r150715  
    33413341        ASSERT(!oldFocusedNode->inDetach());
    33423342
    3343         if (oldFocusedNode->active())
    3344             oldFocusedNode->setActive(false);
    3345 
    3346         if (oldFocusedNode->isElementNode())
     3343        if (oldFocusedNode->isElementNode()) {
     3344            Element* oldFocusedElement = toElement(oldFocusedNode.get());
     3345            if (oldFocusedElement->active())
     3346                oldFocusedElement->setActive(false);
     3347
    33473348            toElement(oldFocusedNode.get())->setFocus(false);
     3349        }
    33483350
    33493351        // Dispatch a change event for form control elements that have been edited.
     
    58715873            if (curr->node()) {
    58725874                ASSERT(!curr->node()->isTextNode());
    5873                 curr->node()->setActive(false);
     5875                if (curr->node()->isElementNode())
     5876                    toElement(curr->node())->setActive(false);
    58745877                m_userActionElements.setInActiveChain(curr->node(), false);
    58755878            }
     
    59745977    size_t addCount = nodesToAddToChain.size();
    59755978    for (size_t i = 0; i < addCount; ++i) {
    5976         if (allowActiveChanges)
    5977             nodesToAddToChain[i]->setActive(true);
     5979        if (allowActiveChanges && nodesToAddToChain[i]->isElementNode())
     5980            toElement(nodesToAddToChain[i].get())->setActive(true);
    59785981        if (ancestor && nodesToAddToChain[i] == ancestor->node())
    59795982            sawCommonAncestor = true;
  • trunk/Source/WebCore/dom/Element.cpp

    r150714 r150715  
    3131#include "CSSParser.h"
    3232#include "CSSSelectorList.h"
     33#include "Chrome.h"
     34#include "ChromeClient.h"
    3335#include "ClassList.h"
    3436#include "ClientRect.h"
     
    8789#include "htmlediting.h"
    8890#include <wtf/BitVector.h>
     91#include <wtf/CurrentTime.h>
    8992#include <wtf/text/CString.h>
    9093
     
    455458}
    456459
     460bool Element::isUserActionElementActive() const
     461{
     462    ASSERT(isUserActionElement());
     463    return document()->userActionElements().isActive(this);
     464}
     465
    457466bool Element::isUserActionElementFocused() const
    458467{
     
    465474    ASSERT(isUserActionElement());
    466475    return document()->userActionElements().isHovered(this);
     476}
     477
     478void Element::setActive(bool flag, bool pause)
     479{
     480    if (flag == active())
     481        return;
     482
     483    if (Document* document = this->document())
     484        document->userActionElements().setActive(this, flag);
     485
     486    if (!renderer())
     487        return;
     488
     489    bool reactsToPress = renderStyle()->affectedByActive() || childrenAffectedByActive();
     490    if (reactsToPress)
     491        setNeedsStyleRecalc();
     492
     493    if (renderer()->style()->hasAppearance() && renderer()->theme()->stateChanged(renderer(), PressedState))
     494        reactsToPress = true;
     495
     496    // The rest of this function implements a feature that only works if the
     497    // platform supports immediate invalidations on the ChromeClient, so bail if
     498    // that isn't supported.
     499    if (!document()->page()->chrome().client()->supportsImmediateInvalidation())
     500        return;
     501
     502    if (reactsToPress && pause) {
     503        // The delay here is subtle. It relies on an assumption, namely that the amount of time it takes
     504        // to repaint the "down" state of the control is about the same time as it would take to repaint the
     505        // "up" state. Once you assume this, you can just delay for 100ms - that time (assuming that after you
     506        // leave this method, it will be about that long before the flush of the up state happens again).
     507#ifdef HAVE_FUNC_USLEEP
     508        double startTime = currentTime();
     509#endif
     510
     511        Document::updateStyleForAllDocuments();
     512        // Do an immediate repaint.
     513        if (renderer())
     514            renderer()->repaint(true);
     515
     516        // FIXME: Come up with a less ridiculous way of doing this.
     517#ifdef HAVE_FUNC_USLEEP
     518        // Now pause for a small amount of time (1/10th of a second from before we repainted in the pressed state)
     519        double remainingTime = 0.1 - (currentTime() - startTime);
     520        if (remainingTime > 0)
     521            usleep(static_cast<useconds_t>(remainingTime * 1000000.0));
     522#endif
     523    }
    467524}
    468525
  • trunk/Source/WebCore/dom/Element.h

    r150714 r150715  
    427427    virtual const AtomicString& shadowPseudoId() const;
    428428
     429    bool active() const { return isUserActionElement() && isUserActionElementActive(); }
    429430    bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
    430431    bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
    431432
     433    virtual void setActive(bool flag = true, bool pause = false);
    432434    virtual void setHovered(bool flag = true);
    433435    virtual void setFocus(bool flag);
     
    663665
    664666private:
     667    bool isUserActionElementActive() const;
    665668    bool isUserActionElementFocused() const;
    666669    bool isUserActionElementHovered() const;
  • trunk/Source/WebCore/dom/Node.cpp

    r150714 r150715  
    26782678}
    26792679
    2680 void Node::setActive(bool flag, bool)
    2681 {
    2682     if (Document* document = this->document())
    2683         document->userActionElements().setActive(this, flag);
    2684 }
    2685 
    2686 bool Node::isUserActionElementActive() const
    2687 {
    2688     ASSERT(isUserActionElement());
    2689     return document()->userActionElements().isActive(this);
    2690 }
    2691 
    26922680bool Node::isUserActionElementInActiveChain() const
    26932681{
  • trunk/Source/WebCore/dom/Node.h

    r150714 r150715  
    359359    void setUserActionElement(bool flag) { setFlag(flag, IsUserActionElement); }
    360360
    361     bool active() const { return isUserActionElement() && isUserActionElementActive(); }
    362361    bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); }
    363362
     
    397396    void lazyAttach(ShouldSetAttached = SetAttached);
    398397    void lazyReattach(ShouldSetAttached = SetAttached);
    399 
    400     virtual void setActive(bool flag = true, bool pause = false);
    401398
    402399    enum UserSelectAllTreatment {
     
    774771    bool isEditableToAccessibility(EditableLevel) const;
    775772
    776     bool isUserActionElementActive() const;
    777773    bool isUserActionElementInActiveChain() const;
    778     bool isUserActionElementFocused() const;
    779774
    780775    void setStyleChange(StyleChangeType);
  • trunk/Source/WebCore/dom/UserActionElementSet.h

    r150686 r150715  
    11/*
    22 * Copyright (C) 2012 Google Inc. All rights reserved.
     3 * Copyright (C) 2013 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4445
    4546    bool isFocused(const Element* element) { return hasFlags(element, IsFocusedFlag); }
    46     bool isActive(const Node* node) { return hasFlags(node, IsActiveFlag); }
     47    bool isActive(const Element* element) { return hasFlags(element, IsActiveFlag); }
    4748    bool isInActiveChain(const Node* node) { return hasFlags(node, InActiveChainFlag); }
    4849    bool isHovered(const Element* element) { return hasFlags(element, IsHoveredFlag); }
    4950    void setFocused(Element* element, bool enable) { setFlags(element, enable, IsFocusedFlag); }
    50     void setActive(Node* node, bool enable) { setFlags(node, enable, IsActiveFlag); }
     51    void setActive(Element* element, bool enable) { setFlags(element, enable, IsActiveFlag); }
    5152    void setInActiveChain(Node* node, bool enable) { setFlags(node, enable, InActiveChainFlag); }
    5253    void setHovered(Element* element, bool enable) { setFlags(element, enable, IsHoveredFlag); }
  • trunk/Source/WebCore/html/HTMLAnchorElement.cpp

    r149665 r150715  
    216216    }
    217217   
    218     ContainerNode::setActive(down, pause);
     218    HTMLElement::setActive(down, pause);
    219219}
    220220
  • trunk/Source/WebCore/html/HTMLAnchorElement.h

    r150710 r150715  
    113113    virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
    114114    virtual void defaultEventHandler(Event*);
    115     virtual void setActive(bool active = true, bool pause = false);
     115    virtual void setActive(bool active = true, bool pause = false) OVERRIDE FINAL;
    116116    virtual void accessKeyAction(bool sendMouseEvents);
    117117    virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
  • trunk/Source/WebCore/html/HTMLLabelElement.h

    r150709 r150715  
    4747
    4848    // Overridden to update the hover/active state of the corresponding control.
    49     virtual void setActive(bool = true, bool pause = false);
     49    virtual void setActive(bool = true, bool pause = false) OVERRIDE;
    5050    virtual void setHovered(bool = true) OVERRIDE;
    5151
  • trunk/Source/WebCore/html/shadow/MediaControlElementTypes.h

    r148099 r150715  
    170170
    171171private:
    172     void setActive(bool /*flag*/ = true, bool /*pause*/ = false);
     172    void setActive(bool /*flag*/ = true, bool /*pause*/ = false) OVERRIDE FINAL;
    173173
    174174    void startTimer();
  • trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp

    r150214 r150715  
    595595        return fgColor;
    596596
    597     if (o->node()->active())
     597    if (o->node() && o->node()->isElementNode() && toElement(o->node())->active())
    598598        fgColor = fgColor.lighter();
    599599
  • trunk/Source/WebCore/rendering/RenderTheme.cpp

    r150697 r150715  
    806806bool RenderTheme::isPressed(const RenderObject* o) const
    807807{
    808     if (!o->node())
    809         return false;
    810     return o->node()->active();
     808    if (!o->node() || !o->node()->isElementNode())
     809        return false;
     810    return toElement(o->node())->active();
    811811}
    812812
     
    814814{
    815815    Node* node = o->node();
    816     if (!node || !node->active() || !node->isElementNode()
    817         || !toElement(node)->isSpinButtonElement())
    818         return false;
    819     SpinButtonElement* element = static_cast<SpinButtonElement*>(node);
    820     return element->upDownState() == SpinButtonElement::Up;
     816    if (!node || !node->isElementNode())
     817        return false;
     818    Element* element = toElement(node);
     819    if (!element->active() || !element->isSpinButtonElement())
     820        return false;
     821    return static_cast<SpinButtonElement*>(element)->upDownState() == SpinButtonElement::Up;
    821822}
    822823
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r150697 r150715  
    253253    if (isDisabledFormControl(node))
    254254        flags |= MediaUIPartDisabledFlag;
    255     else if (node->active())
     255    else if (node->isElementNode() && toElement(node)->active())
    256256        flags |= MediaUIPartPressedFlag;
    257257    return flags;
     
    976976{
    977977    bool oldPressed = [cell isHighlighted];
    978     bool pressed = (o->node() && o->node()->active());
     978    bool pressed = o->node() && o->node()->isElementNode() && toElement(o->node())->active();
    979979    if (pressed != oldPressed)
    980980        [cell setHighlighted:pressed];
Note: See TracChangeset for help on using the changeset viewer.