Changeset 150715 in webkit
- Timestamp:
- May 26, 2013 7:29:15 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r150714 r150715 1 2013-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 1 53 2013-05-26 Andreas Kling <akling@apple.com> 2 54 -
trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp
r150710 r150715 635 635 } 636 636 637 return node->active(); 637 if (!node->isElementNode()) 638 return false; 639 return toElement(node)->active(); 638 640 } 639 641 -
trunk/Source/WebCore/dom/ContainerNode.cpp
r150686 r150715 969 969 } 970 970 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 style978 // FIXME: Move to Element979 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 the989 // platform supports immediate invalidations on the ChromeClient, so bail if990 // 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 takes996 // to repaint the "down" state of the control is about the same time as it would take to repaint the997 // "up" state. Once you assume this, you can just delay for 100ms - that time (assuming that after you998 // leave this method, it will be about that long before the flush of the up state happens again).999 #ifdef HAVE_FUNC_USLEEP1000 double startTime = currentTime();1001 #endif1002 1003 // Ensure there are no pending changes1004 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_USLEEP1012 // 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 #endif1017 }1018 }1019 }1020 1021 971 unsigned ContainerNode::childNodeCount() const 1022 972 { -
trunk/Source/WebCore/dom/ContainerNode.h
r150713 r150715 110 110 virtual void detach() OVERRIDE; 111 111 virtual LayoutRect boundingBox() const OVERRIDE; 112 virtual void setActive(bool active = true, bool pause = false) OVERRIDE;113 112 virtual void scheduleSetNeedsStyleRecalc(StyleChangeType = FullStyleChange) OVERRIDE FINAL; 114 113 -
trunk/Source/WebCore/dom/Document.cpp
r150713 r150715 3341 3341 ASSERT(!oldFocusedNode->inDetach()); 3342 3342 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 3347 3348 toElement(oldFocusedNode.get())->setFocus(false); 3349 } 3348 3350 3349 3351 // Dispatch a change event for form control elements that have been edited. … … 5871 5873 if (curr->node()) { 5872 5874 ASSERT(!curr->node()->isTextNode()); 5873 curr->node()->setActive(false); 5875 if (curr->node()->isElementNode()) 5876 toElement(curr->node())->setActive(false); 5874 5877 m_userActionElements.setInActiveChain(curr->node(), false); 5875 5878 } … … 5974 5977 size_t addCount = nodesToAddToChain.size(); 5975 5978 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); 5978 5981 if (ancestor && nodesToAddToChain[i] == ancestor->node()) 5979 5982 sawCommonAncestor = true; -
trunk/Source/WebCore/dom/Element.cpp
r150714 r150715 31 31 #include "CSSParser.h" 32 32 #include "CSSSelectorList.h" 33 #include "Chrome.h" 34 #include "ChromeClient.h" 33 35 #include "ClassList.h" 34 36 #include "ClientRect.h" … … 87 89 #include "htmlediting.h" 88 90 #include <wtf/BitVector.h> 91 #include <wtf/CurrentTime.h> 89 92 #include <wtf/text/CString.h> 90 93 … … 455 458 } 456 459 460 bool Element::isUserActionElementActive() const 461 { 462 ASSERT(isUserActionElement()); 463 return document()->userActionElements().isActive(this); 464 } 465 457 466 bool Element::isUserActionElementFocused() const 458 467 { … … 465 474 ASSERT(isUserActionElement()); 466 475 return document()->userActionElements().isHovered(this); 476 } 477 478 void 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 } 467 524 } 468 525 -
trunk/Source/WebCore/dom/Element.h
r150714 r150715 427 427 virtual const AtomicString& shadowPseudoId() const; 428 428 429 bool active() const { return isUserActionElement() && isUserActionElementActive(); } 429 430 bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); } 430 431 bool focused() const { return isUserActionElement() && isUserActionElementFocused(); } 431 432 433 virtual void setActive(bool flag = true, bool pause = false); 432 434 virtual void setHovered(bool flag = true); 433 435 virtual void setFocus(bool flag); … … 663 665 664 666 private: 667 bool isUserActionElementActive() const; 665 668 bool isUserActionElementFocused() const; 666 669 bool isUserActionElementHovered() const; -
trunk/Source/WebCore/dom/Node.cpp
r150714 r150715 2678 2678 } 2679 2679 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() const2687 {2688 ASSERT(isUserActionElement());2689 return document()->userActionElements().isActive(this);2690 }2691 2692 2680 bool Node::isUserActionElementInActiveChain() const 2693 2681 { -
trunk/Source/WebCore/dom/Node.h
r150714 r150715 359 359 void setUserActionElement(bool flag) { setFlag(flag, IsUserActionElement); } 360 360 361 bool active() const { return isUserActionElement() && isUserActionElementActive(); }362 361 bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); } 363 362 … … 397 396 void lazyAttach(ShouldSetAttached = SetAttached); 398 397 void lazyReattach(ShouldSetAttached = SetAttached); 399 400 virtual void setActive(bool flag = true, bool pause = false);401 398 402 399 enum UserSelectAllTreatment { … … 774 771 bool isEditableToAccessibility(EditableLevel) const; 775 772 776 bool isUserActionElementActive() const;777 773 bool isUserActionElementInActiveChain() const; 778 bool isUserActionElementFocused() const;779 774 780 775 void setStyleChange(StyleChangeType); -
trunk/Source/WebCore/dom/UserActionElementSet.h
r150686 r150715 1 1 /* 2 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 44 45 45 46 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); } 47 48 bool isInActiveChain(const Node* node) { return hasFlags(node, InActiveChainFlag); } 48 49 bool isHovered(const Element* element) { return hasFlags(element, IsHoveredFlag); } 49 50 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); } 51 52 void setInActiveChain(Node* node, bool enable) { setFlags(node, enable, InActiveChainFlag); } 52 53 void setHovered(Element* element, bool enable) { setFlags(element, enable, IsHoveredFlag); } -
trunk/Source/WebCore/html/HTMLAnchorElement.cpp
r149665 r150715 216 216 } 217 217 218 ContainerNode::setActive(down, pause);218 HTMLElement::setActive(down, pause); 219 219 } 220 220 -
trunk/Source/WebCore/html/HTMLAnchorElement.h
r150710 r150715 113 113 virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE; 114 114 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; 116 116 virtual void accessKeyAction(bool sendMouseEvents); 117 117 virtual bool isURLAttribute(const Attribute&) const OVERRIDE; -
trunk/Source/WebCore/html/HTMLLabelElement.h
r150709 r150715 47 47 48 48 // 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; 50 50 virtual void setHovered(bool = true) OVERRIDE; 51 51 -
trunk/Source/WebCore/html/shadow/MediaControlElementTypes.h
r148099 r150715 170 170 171 171 private: 172 void setActive(bool /*flag*/ = true, bool /*pause*/ = false) ;172 void setActive(bool /*flag*/ = true, bool /*pause*/ = false) OVERRIDE FINAL; 173 173 174 174 void startTimer(); -
trunk/Source/WebCore/platform/qt/RenderThemeQt.cpp
r150214 r150715 595 595 return fgColor; 596 596 597 if (o->node() ->active())597 if (o->node() && o->node()->isElementNode() && toElement(o->node())->active()) 598 598 fgColor = fgColor.lighter(); 599 599 -
trunk/Source/WebCore/rendering/RenderTheme.cpp
r150697 r150715 806 806 bool RenderTheme::isPressed(const RenderObject* o) const 807 807 { 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(); 811 811 } 812 812 … … 814 814 { 815 815 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; 821 822 } 822 823 -
trunk/Source/WebCore/rendering/RenderThemeMac.mm
r150697 r150715 253 253 if (isDisabledFormControl(node)) 254 254 flags |= MediaUIPartDisabledFlag; 255 else if (node-> active())255 else if (node->isElementNode() && toElement(node)->active()) 256 256 flags |= MediaUIPartPressedFlag; 257 257 return flags; … … 976 976 { 977 977 bool oldPressed = [cell isHighlighted]; 978 bool pressed = (o->node() && o->node()->active());978 bool pressed = o->node() && o->node()->isElementNode() && toElement(o->node())->active(); 979 979 if (pressed != oldPressed) 980 980 [cell setHighlighted:pressed];
Note: See TracChangeset
for help on using the changeset viewer.