Title: [137277] trunk/Source/WebCore
Revision
137277
Author
morr...@google.com
Date
2012-12-11 02:36:24 -0800 (Tue, 11 Dec 2012)

Log Message

IsActiveFlag, IsHoverFlag, InActiveChainFlag can be unified.
https://bugs.webkit.org/show_bug.cgi?id=103697

Reviewed by Ryosuke Niwa.

To save two more NodeFlags bits, this patch inroduces
UserActionElementSet to get IsLinkFlag, IsHoverFlag,
InActiveChainFlag together. These three old flags are replaced by
UserActionElementSet::ElementFlags and UserActionElementSet
collection which tracks elements which are flagged with one of
a ElementFlags.

When marking an element as active for example, WebKit sets
UserActionElementSet::IsActiveFlag to the element and store it
into corresponding element set of the document. This set maintains
marked elements and corresponding flags for each elements.

UserActionElementSet can be seen as a yet another rare data for
these flags. However, the following characteristics of these flags
make adding a new data structure on Document an attractive
alternative:

- UserActionElementSet is maintained for each Document instead of a
  global collecton. This fits element lifetime better.

- The number of elements which have these flags is generally
  small, and a group of elements for each flag is largely overlapped
  due to its nature. This property keeps the set small, and lets
  flag retrieval efficient. On majority of the elements, all these
  flags are false thus the check is done by just checking
  IsInUserActionFlag.

As a bonus, isFocused flag, which was on NodeRareData, is also moved to this model.

No new tests, covered by existing test.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.xcodeproj/project.pbxproj:
* dom/DOMAllInOne.cpp:
* dom/Document.cpp:
(WebCore::Document::removedLastRef):
(WebCore::Document::updateHoverActiveState):
* dom/Document.h:
(WebCore::Document::userActionElements): Added.
(Document):
* dom/Node.cpp:
(WebCore::Node::detach):
* dom/Node.h:
(WebCore):
(WebCore::Node::isUserActionElement): Added.
(WebCore::Node::setUserActionElement): Added.
(Node):
(WebCore::Node::active): Switched to UserActionElementSet.
(WebCore::Node::inActiveChain): Switched to UserActionElementSet.
(WebCore::Node::hovered): Switched to UserActionElementSet.
(WebCore::Node::focused): Switched to UserActionElementSet.
(WebCore::Node::setFocus): Switched to UserActionElementSet.
(WebCore::Node::setActive): Switched to UserActionElementSet.
(WebCore::Node::setHovered): Switched to UserActionElementSet.
* dom/NodeRareData.h:
(WebCore::NodeRareData::NodeRareData):
(NodeRareData):
* dom/UserActionElementSet.cpp: Added.
(WebCore):
(WebCore::UserActionElementSet::instanceFor):
(WebCore::UserActionElementSet::UserActionElementSet):
(WebCore::UserActionElementSet::~UserActionElementSet):
(WebCore::UserActionElementSet::didDetach):
(WebCore::UserActionElementSet::documentDidRemoveLastRef):
(WebCore::UserActionElementSet::hasFlags):
(WebCore::UserActionElementSet::setFlags):
(WebCore::UserActionElementSet::clearFlags):
* dom/UserActionElementSet.h: Added.
(WebCore):
(UserActionElementSet):
(WebCore::UserActionElementSet::create):
(WebCore::UserActionElementSet::isFocused):
(WebCore::UserActionElementSet::setFocused):
(WebCore::UserActionElementSet::isActive):
(WebCore::UserActionElementSet::setActive):
(WebCore::UserActionElementSet::isInActiveChain):
(WebCore::UserActionElementSet::setInActiveChain):
(WebCore::UserActionElementSet::isHovered):
(WebCore::UserActionElementSet::setHovered):
(WebCore::UserActionElementSet::setFlags):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (137276 => 137277)


--- trunk/Source/WebCore/CMakeLists.txt	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/CMakeLists.txt	2012-12-11 10:36:24 UTC (rev 137277)
@@ -1236,6 +1236,7 @@
     dom/TreeWalker.cpp
     dom/UIEvent.cpp
     dom/UIEventWithKeyState.cpp
+    dom/UserActionElementSet.cpp
     dom/UserGestureIndicator.cpp
     dom/UserTypingGestureIndicator.cpp
     dom/ViewportArguments.cpp

Modified: trunk/Source/WebCore/ChangeLog (137276 => 137277)


--- trunk/Source/WebCore/ChangeLog	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/ChangeLog	2012-12-11 10:36:24 UTC (rev 137277)
@@ -1,3 +1,94 @@
+2012-12-11  Hajime Morrita  <morr...@google.com>
+
+        IsActiveFlag, IsHoverFlag, InActiveChainFlag can be unified.
+        https://bugs.webkit.org/show_bug.cgi?id=103697
+
+        Reviewed by Ryosuke Niwa.
+
+        To save two more NodeFlags bits, this patch inroduces
+        UserActionElementSet to get IsLinkFlag, IsHoverFlag,
+        InActiveChainFlag together. These three old flags are replaced by
+        UserActionElementSet::ElementFlags and UserActionElementSet
+        collection which tracks elements which are flagged with one of
+        a ElementFlags.
+
+        When marking an element as active for example, WebKit sets
+        UserActionElementSet::IsActiveFlag to the element and store it
+        into corresponding element set of the document. This set maintains
+        marked elements and corresponding flags for each elements.
+
+        UserActionElementSet can be seen as a yet another rare data for
+        these flags. However, the following characteristics of these flags
+        make adding a new data structure on Document an attractive
+        alternative:
+
+        - UserActionElementSet is maintained for each Document instead of a
+          global collecton. This fits element lifetime better.
+
+        - The number of elements which have these flags is generally
+          small, and a group of elements for each flag is largely overlapped
+          due to its nature. This property keeps the set small, and lets
+          flag retrieval efficient. On majority of the elements, all these
+          flags are false thus the check is done by just checking
+          IsInUserActionFlag.
+
+        As a bonus, isFocused flag, which was on NodeRareData, is also moved to this model.
+
+        No new tests, covered by existing test.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/DOMAllInOne.cpp:
+        * dom/Document.cpp:
+        (WebCore::Document::removedLastRef):
+        (WebCore::Document::updateHoverActiveState):
+        * dom/Document.h:
+        (WebCore::Document::userActionElements): Added.
+        (Document):
+        * dom/Node.cpp:
+        (WebCore::Node::detach):
+        * dom/Node.h:
+        (WebCore):
+        (WebCore::Node::isUserActionElement): Added.
+        (WebCore::Node::setUserActionElement): Added.
+        (Node):
+        (WebCore::Node::active): Switched to UserActionElementSet.
+        (WebCore::Node::inActiveChain): Switched to UserActionElementSet.
+        (WebCore::Node::hovered): Switched to UserActionElementSet.
+        (WebCore::Node::focused): Switched to UserActionElementSet.
+        (WebCore::Node::setFocus): Switched to UserActionElementSet.
+        (WebCore::Node::setActive): Switched to UserActionElementSet.
+        (WebCore::Node::setHovered): Switched to UserActionElementSet.
+        * dom/NodeRareData.h:
+        (WebCore::NodeRareData::NodeRareData):
+        (NodeRareData):
+        * dom/UserActionElementSet.cpp: Added.
+        (WebCore):
+        (WebCore::UserActionElementSet::instanceFor):
+        (WebCore::UserActionElementSet::UserActionElementSet):
+        (WebCore::UserActionElementSet::~UserActionElementSet):
+        (WebCore::UserActionElementSet::didDetach):
+        (WebCore::UserActionElementSet::documentDidRemoveLastRef):
+        (WebCore::UserActionElementSet::hasFlags):
+        (WebCore::UserActionElementSet::setFlags):
+        (WebCore::UserActionElementSet::clearFlags):
+        * dom/UserActionElementSet.h: Added.
+        (WebCore):
+        (UserActionElementSet):
+        (WebCore::UserActionElementSet::create):
+        (WebCore::UserActionElementSet::isFocused):
+        (WebCore::UserActionElementSet::setFocused):
+        (WebCore::UserActionElementSet::isActive):
+        (WebCore::UserActionElementSet::setActive):
+        (WebCore::UserActionElementSet::isInActiveChain):
+        (WebCore::UserActionElementSet::setInActiveChain):
+        (WebCore::UserActionElementSet::isHovered):
+        (WebCore::UserActionElementSet::setHovered):
+        (WebCore::UserActionElementSet::setFlags):
+
 2012-12-11  Kent Tamura  <tk...@chromium.org>
 
         INPUT_MULTIPLE_FIELDS_UI: Disable focus navigation by right/left keys in RTL locales

Modified: trunk/Source/WebCore/GNUmakefile.list.am (137276 => 137277)


--- trunk/Source/WebCore/GNUmakefile.list.am	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2012-12-11 10:36:24 UTC (rev 137277)
@@ -2965,6 +2965,8 @@
 	Source/WebCore/dom/UIEvent.h \
 	Source/WebCore/dom/UIEventWithKeyState.cpp \
 	Source/WebCore/dom/UIEventWithKeyState.h \
+	Source/WebCore/dom/UserActionElementSet.h \
+	Source/WebCore/dom/UserActionElementSet.cpp \
 	Source/WebCore/dom/UserGestureIndicator.cpp \
 	Source/WebCore/dom/UserGestureIndicator.h \
 	Source/WebCore/dom/UserTypingGestureIndicator.cpp \

Modified: trunk/Source/WebCore/Target.pri (137276 => 137277)


--- trunk/Source/WebCore/Target.pri	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/Target.pri	2012-12-11 10:36:24 UTC (rev 137277)
@@ -472,6 +472,7 @@
     dom/TreeWalker.cpp \
     dom/UIEvent.cpp \
     dom/UIEventWithKeyState.cpp \
+    dom/UserActionElementSet.cpp \
     dom/UserGestureIndicator.cpp \
     dom/UserTypingGestureIndicator.cpp \
     dom/ViewportArguments.cpp \
@@ -1625,6 +1626,7 @@
     dom/Range.h \
     dom/RegisteredEventListener.h \
     dom/RenderedDocumentMarker.h \
+    dom/UserActionElementSet.h \
     dom/ScriptedAnimationController.h \
     dom/ScriptElement.h \
     dom/ScriptExecutionContext.h \

Modified: trunk/Source/WebCore/WebCore.gypi (137276 => 137277)


--- trunk/Source/WebCore/WebCore.gypi	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/WebCore.gypi	2012-12-11 10:36:24 UTC (rev 137277)
@@ -2921,6 +2921,8 @@
             'dom/TreeWalker.h',
             'dom/UIEvent.cpp',
             'dom/UIEventWithKeyState.cpp',
+            'dom/UserActionElementSet.h',
+            'dom/UserActionElementSet.cpp',
             'dom/UserGestureIndicator.cpp',
             'dom/UserTypingGestureIndicator.cpp',
             'dom/ViewportArguments.cpp',

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (137276 => 137277)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-12-11 10:36:24 UTC (rev 137277)
@@ -3876,6 +3876,7 @@
 		A718760E0B2A120100A16ECE /* DragActions.h in Headers */ = {isa = PBXBuildFile; fileRef = A718760D0B2A120100A16ECE /* DragActions.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A71878900B2D04AC00A16ECE /* DragControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */; };
 		A723F77B1484CA4C008C6DBE /* PlatformExportMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = A723F77A1484CA4C008C6DBE /* PlatformExportMacros.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		A72763BF16689BFB002FCACB /* UserActionElementSet.h in Headers */ = {isa = PBXBuildFile; fileRef = A72763BE16689BFB002FCACB /* UserActionElementSet.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A72EA3BB1585CF55004FAA26 /* RefCountedSupplement.h in Headers */ = {isa = PBXBuildFile; fileRef = A72EA3BA1585CF55004FAA26 /* RefCountedSupplement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		A73F95FE12C97BFE0031AAF9 /* RoundedRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A73F95FC12C97BFE0031AAF9 /* RoundedRect.cpp */; };
 		A73F95FF12C97BFE0031AAF9 /* RoundedRect.h in Headers */ = {isa = PBXBuildFile; fileRef = A73F95FD12C97BFE0031AAF9 /* RoundedRect.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -3894,6 +3895,7 @@
 		A75E8B8D0E1DE2D6007F2481 /* FEComponentTransfer.h in Headers */ = {isa = PBXBuildFile; fileRef = A75E8B850E1DE2D6007F2481 /* FEComponentTransfer.h */; };
 		A75E8B8E0E1DE2D6007F2481 /* FEComposite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A75E8B860E1DE2D6007F2481 /* FEComposite.cpp */; };
 		A75E8B8F0E1DE2D6007F2481 /* FEComposite.h in Headers */ = {isa = PBXBuildFile; fileRef = A75E8B870E1DE2D6007F2481 /* FEComposite.h */; };
+		A769E96A16689D0C005D4529 /* UserActionElementSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A769E96916689D0C005D4529 /* UserActionElementSet.cpp */; };
 		A76E5F7F135E0DCF00A69837 /* RenderedDocumentMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = A76E5F7E135E0DCF00A69837 /* RenderedDocumentMarker.h */; };
 		A77979190D6B9D0C003851B9 /* ImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A77979130D6B9D0C003851B9 /* ImageData.cpp */; };
 		A779791A0D6B9D0C003851B9 /* ImageData.h in Headers */ = {isa = PBXBuildFile; fileRef = A77979140D6B9D0C003851B9 /* ImageData.h */; };
@@ -11200,6 +11202,7 @@
 		A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragControllerMac.mm; sourceTree = "<group>"; };
 		A71A70C911AFB02000989D6D /* HTMLMeterElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLMeterElement.idl; sourceTree = "<group>"; };
 		A723F77A1484CA4C008C6DBE /* PlatformExportMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformExportMacros.h; sourceTree = "<group>"; };
+		A72763BE16689BFB002FCACB /* UserActionElementSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserActionElementSet.h; sourceTree = "<group>"; };
 		A72EA3BA1585CF55004FAA26 /* RefCountedSupplement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RefCountedSupplement.h; sourceTree = "<group>"; };
 		A73F95FC12C97BFE0031AAF9 /* RoundedRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RoundedRect.cpp; sourceTree = "<group>"; };
 		A73F95FD12C97BFE0031AAF9 /* RoundedRect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoundedRect.h; sourceTree = "<group>"; };
@@ -11214,6 +11217,7 @@
 		A75E8B850E1DE2D6007F2481 /* FEComponentTransfer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FEComponentTransfer.h; path = filters/FEComponentTransfer.h; sourceTree = "<group>"; };
 		A75E8B860E1DE2D6007F2481 /* FEComposite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FEComposite.cpp; path = filters/FEComposite.cpp; sourceTree = "<group>"; };
 		A75E8B870E1DE2D6007F2481 /* FEComposite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FEComposite.h; path = filters/FEComposite.h; sourceTree = "<group>"; };
+		A769E96916689D0C005D4529 /* UserActionElementSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserActionElementSet.cpp; sourceTree = "<group>"; };
 		A76E5F7E135E0DCF00A69837 /* RenderedDocumentMarker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderedDocumentMarker.h; sourceTree = "<group>"; };
 		A77979130D6B9D0C003851B9 /* ImageData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ImageData.cpp; sourceTree = "<group>"; };
 		A77979140D6B9D0C003851B9 /* ImageData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageData.h; sourceTree = "<group>"; };
@@ -22181,6 +22185,8 @@
 				141B94EE09EC425A000E9413 /* UIEvent.idl */,
 				93354A3B0B24F8C9003F6DEA /* UIEventWithKeyState.cpp */,
 				85031B390A44EFC700F992E0 /* UIEventWithKeyState.h */,
+				A769E96916689D0C005D4529 /* UserActionElementSet.cpp */,
+				A72763BE16689BFB002FCACB /* UserActionElementSet.h */,
 				2542F4D81166C25A00E89A86 /* UserGestureIndicator.cpp */,
 				2542F4D91166C25A00E89A86 /* UserGestureIndicator.h */,
 				BCDF317911F8D683003C5BF8 /* UserTypingGestureIndicator.cpp */,
@@ -25650,6 +25656,7 @@
 				E4AFCFA50DAF29A300F5F55C /* UnitBezier.h in Headers */,
 				D086FE9809D53AAB005BC74D /* UnlinkCommand.h in Headers */,
 				F55B3DDE1251F12D003EF269 /* URLInputType.h in Headers */,
+				A72763BF16689BFB002FCACB /* UserActionElementSet.h in Headers */,
 				656581B209D14EE6000E61D7 /* UserAgentStyleSheets.h in Headers */,
 				003F1FEA11E6AB43008258D9 /* UserContentTypes.h in Headers */,
 				BCACF3BD1072921A00C0C8A3 /* UserContentURLPattern.h in Headers */,
@@ -28782,6 +28789,7 @@
 				B2C3DA4C0D006C1D00EF6F26 /* UnicodeRange.cpp in Sources */,
 				D086FE9909D53AAB005BC74D /* UnlinkCommand.cpp in Sources */,
 				F55B3DDD1251F12D003EF269 /* URLInputType.cpp in Sources */,
+				A769E96A16689D0C005D4529 /* UserActionElementSet.cpp in Sources */,
 				65DF326109D1E199000BE325 /* UserAgentStyleSheetsData.cpp in Sources */,
 				BCACF3BC1072921A00C0C8A3 /* UserContentURLPattern.cpp in Sources */,
 				2542F4DA1166C25A00E89A86 /* UserGestureIndicator.cpp in Sources */,

Modified: trunk/Source/WebCore/dom/DOMAllInOne.cpp (137276 => 137277)


--- trunk/Source/WebCore/dom/DOMAllInOne.cpp	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/dom/DOMAllInOne.cpp	2012-12-11 10:36:24 UTC (rev 137277)
@@ -144,6 +144,7 @@
 #include "TreeWalker.cpp"
 #include "UIEvent.cpp"
 #include "UIEventWithKeyState.cpp"
+#include "UserActionElementSet.cpp"
 #include "UserGestureIndicator.cpp"
 #include "UserTypingGestureIndicator.cpp"
 #include "ViewportArguments.cpp"

Modified: trunk/Source/WebCore/dom/Document.cpp (137276 => 137277)


--- trunk/Source/WebCore/dom/Document.cpp	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-12-11 10:36:24 UTC (rev 137277)
@@ -159,6 +159,7 @@
 #include "Timer.h"
 #include "TransformSource.h"
 #include "TreeWalker.h"
+#include "UserActionElementSet.h"
 #include "UserContentURLPattern.h"
 #include "WebCoreMemoryInstrumentation.h"
 #include "WebKitNamedFlow.h"
@@ -692,6 +693,7 @@
         m_titleElement = 0;
         m_documentElement = 0;
         m_contextFeatures = ContextFeatures::defaultSwitch();
+        m_userActionElements.documentDidRemoveLastRef();
 #if ENABLE(FULLSCREEN_API)
         m_fullScreenElement = 0;
         m_fullScreenElementStack.clear();
@@ -5779,7 +5781,7 @@
         for (RenderObject* curr = oldActiveNode->renderer(); curr; curr = curr->parent()) {
             if (curr->node() && !curr->isText()) {
                 curr->node()->setActive(false);
-                curr->node()->clearInActiveChain();
+                m_userActionElements.setInActiveChain(curr->node(), false);
             }
         }
         setActiveNode(0);
@@ -5790,7 +5792,7 @@
             // will need to reference this chain.
             for (RenderObject* curr = newActiveNode->renderer(); curr; curr = curr->parent()) {
                 if (curr->node() && !curr->isText())
-                    curr->node()->setInActiveChain();
+                    m_userActionElements.setInActiveChain(curr->node(), true);
             }
             setActiveNode(newActiveNode);
         }

Modified: trunk/Source/WebCore/dom/Document.h (137276 => 137277)


--- trunk/Source/WebCore/dom/Document.h	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/dom/Document.h	2012-12-11 10:36:24 UTC (rev 137277)
@@ -46,6 +46,7 @@
 #include "StringWithDirection.h"
 #include "Timer.h"
 #include "TreeScope.h"
+#include "UserActionElementSet.h"
 #include "ViewportArguments.h"
 #include <wtf/Deque.h>
 #include <wtf/FixedArray.h>
@@ -682,6 +683,8 @@
 
     bool setFocusedNode(PassRefPtr<Node>);
     Node* focusedNode() const { return m_focusedNode.get(); }
+    UserActionElementSet& userActionElements()  { return m_userActionElements; }
+    const UserActionElementSet& userActionElements() const { return m_userActionElements; }
 
     void getFocusableNodes(Vector<RefPtr<Node> >&);
     
@@ -1327,6 +1330,7 @@
     RefPtr<Node> m_hoverNode;
     RefPtr<Node> m_activeNode;
     RefPtr<Element> m_documentElement;
+    UserActionElementSet m_userActionElements;
 
     uint64_t m_domTreeVersion;
     static uint64_t s_globalTreeVersion;

Modified: trunk/Source/WebCore/dom/Node.cpp (137276 => 137277)


--- trunk/Source/WebCore/dom/Node.cpp	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/dom/Node.cpp	2012-12-11 10:36:24 UTC (rev 137277)
@@ -100,6 +100,7 @@
 #include "TreeScopeAdopter.h"
 #include "UIEvent.h"
 #include "UIEventWithKeyState.h"
+#include "UserActionElementSet.h"
 #include "WebCoreMemoryInstrumentation.h"
 #include "WheelEvent.h"
 #include "WindowEventContext.h"
@@ -899,18 +900,6 @@
     markAncestorsWithChildNeedsStyleRecalc();
 }
 
-void Node::setFocus(bool b)
-{ 
-    if (b || hasRareData())
-        ensureRareData()->setFocused(b);
-}
-
-bool Node::rareDataFocused() const
-{
-    ASSERT(hasRareData());
-    return rareData()->isFocused();
-}
-
 bool Node::supportsFocus() const
 {
     return hasRareData() && rareData()->tabIndexSetExplicitly();
@@ -1160,14 +1149,14 @@
     ASSERT(!renderer());
 
     Document* doc = document();
-    if (hovered())
-        doc->hoveredNodeDetached(this);
-    if (inActiveChain())
-        doc->activeChainNodeDetached(this);
+    if (isUserActionElement()) {
+        if (hovered())
+            doc->hoveredNodeDetached(this);
+        if (inActiveChain())
+            doc->activeChainNodeDetached(this);
+        doc->userActionElements().didDetach(this);
+    }
 
-    clearFlag(IsActiveFlag);
-    clearFlag(IsHoveredFlag);
-    clearFlag(InActiveChainFlag);
     clearFlag(IsAttachedFlag);
 
 #ifndef NDEBUG
@@ -2675,6 +2664,48 @@
     return count;
 }
 
+void Node::setFocus(bool flag)
+{
+    if (Document* document = this->document())
+        document->userActionElements().setFocused(this, flag);
+}
+
+void Node::setActive(bool flag, bool)
+{
+    if (Document* document = this->document())
+        document->userActionElements().setActive(this, flag);
+}
+
+void Node::setHovered(bool flag)
+{
+    if (Document* document = this->document())
+        document->userActionElements().setHovered(this, flag);
+}
+
+bool Node::isUserActionElementActive() const
+{
+    ASSERT(isUserActionElement());
+    return document()->userActionElements().isActive(this);
+}
+
+bool Node::isUserActionElementInActiveChain() const
+{
+    ASSERT(isUserActionElement());
+    return document()->userActionElements().isInActiveChain(this);
+}
+
+bool Node::isUserActionElementHovered() const
+{
+    ASSERT(isUserActionElement());
+    return document()->userActionElements().isHovered(this);
+}
+
+bool Node::isUserActionElementFocused() const
+{
+    ASSERT(isUserActionElement());
+    return document()->userActionElements().isFocused(this);
+}
+
 } // namespace WebCore
 
 #ifndef NDEBUG

Modified: trunk/Source/WebCore/dom/Node.h (137276 => 137277)


--- trunk/Source/WebCore/dom/Node.h	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/dom/Node.h	2012-12-11 10:36:24 UTC (rev 137277)
@@ -98,7 +98,7 @@
 
 typedef int ExceptionCode;
 
-const int nodeStyleChangeShift = 17;
+const int nodeStyleChangeShift = 15;
 
 // SyntheticStyleChange means that we need to go through the entire style change logic even though
 // no style property has actually changed. It is used to restructure the tree when, for instance,
@@ -339,10 +339,14 @@
     bool hasID() const;
     bool hasClass() const;
 
-    bool active() const { return getFlag(IsActiveFlag); }
-    bool inActiveChain() const { return getFlag(InActiveChainFlag); }
-    bool hovered() const { return getFlag(IsHoveredFlag); }
-    bool focused() const { return hasRareData() ? rareDataFocused() : false; }
+    bool isUserActionElement() const { return getFlag(IsUserActionElement); }
+    void setUserActionElement(bool flag) { setFlag(flag, IsUserActionElement); }
+
+    bool active() const { return isUserActionElement() && isUserActionElementActive(); }
+    bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); }
+    bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
+    bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
+
     bool attached() const { return getFlag(IsAttachedFlag); }
     void setAttached() { setFlag(IsAttachedFlag); }
     bool needsStyleRecalc() const { return styleChangeType() != NoStyleChange; }
@@ -355,9 +359,6 @@
     void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); }
     void clearChildNeedsStyleRecalc() { clearFlag(ChildNeedsStyleRecalcFlag); }
 
-    void setInActiveChain() { setFlag(InActiveChainFlag); }
-    void clearInActiveChain() { clearFlag(InActiveChainFlag); }
-
     void setNeedsStyleRecalc(StyleChangeType changeType = FullStyleChange);
     void clearNeedsStyleRecalc() { m_nodeFlags &= ~StyleChangeMask; }
     virtual void scheduleSetNeedsStyleRecalc(StyleChangeType changeType = FullStyleChange) { setNeedsStyleRecalc(changeType); }
@@ -385,9 +386,9 @@
     void lazyAttach(ShouldSetAttached = SetAttached);
     void lazyReattach(ShouldSetAttached = SetAttached);
 
-    virtual void setFocus(bool = true);
-    virtual void setActive(bool f = true, bool /*pause*/ = false) { setFlag(f, IsActiveFlag); }
-    virtual void setHovered(bool f = true) { setFlag(f, IsHoveredFlag); }
+    virtual void setFocus(bool flag = true);
+    virtual void setActive(bool flag = true, bool pause = false);
+    virtual void setHovered(bool flag = true);
 
     virtual short tabIndex() const;
 
@@ -682,37 +683,35 @@
         ChildNeedsStyleRecalcFlag = 1 << 7,
         InDocumentFlag = 1 << 8,
         IsLinkFlag = 1 << 9,
-        IsActiveFlag = 1 << 10,
-        IsHoveredFlag = 1 << 11,
-        InActiveChainFlag = 1 << 12,
-        HasRareDataFlag = 1 << 13,
-        IsDocumentFragmentFlag = 1 << 14,
+        IsUserActionElement = 1 << 10,
+        HasRareDataFlag = 1 << 11,
+        IsDocumentFragmentFlag = 1 << 12,
 
         // These bits are used by derived classes, pulled up here so they can
         // be stored in the same memory word as the Node bits above.
-        IsParsingChildrenFinishedFlag = 1 << 15, // Element
+        IsParsingChildrenFinishedFlag = 1 << 13, // Element
 #if ENABLE(SVG)
-        HasSVGRareDataFlag = 1 << 16, // SVGElement
+        HasSVGRareDataFlag = 1 << 14, // SVGElement
 #endif
 
         StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),
 
-        SelfOrAncestorHasDirAutoFlag = 1 << 19,
+        SelfOrAncestorHasDirAutoFlag = 1 << 17,
 
-        HasNameOrIsEditingTextFlag = 1 << 20,
+        HasNameOrIsEditingTextFlag = 1 << 18,
 
-        InNamedFlowFlag = 1 << 21,
-        HasSyntheticAttrChildNodesFlag = 1 << 22,
-        HasCustomCallbacksFlag = 1 << 23,
-        HasScopedHTMLStyleChildFlag = 1 << 24,
-        HasEventTargetDataFlag = 1 << 25,
-        V8CollectableDuringMinorGCFlag = 1 << 26,
-        IsInsertionPointFlag = 1 << 27,
+        InNamedFlowFlag = 1 << 19,
+        HasSyntheticAttrChildNodesFlag = 1 << 20,
+        HasCustomCallbacksFlag = 1 << 21,
+        HasScopedHTMLStyleChildFlag = 1 << 22,
+        HasEventTargetDataFlag = 1 << 23,
+        V8CollectableDuringMinorGCFlag = 1 << 24,
+        IsInsertionPointFlag = 1 << 25,
 
         DefaultNodeFlags = IsParsingChildrenFinishedFlag
     };
 
-    // 4 bits remaining
+    // 6 bits remaining
 
     bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
     void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); } 
@@ -775,6 +774,11 @@
     bool rendererIsEditable(EditableLevel, UserSelectAllTreatment = UserSelectAllIsAlwaysNonEditable) const;
     bool isEditableToAccessibility(EditableLevel) const;
 
+    bool isUserActionElementActive() const;
+    bool isUserActionElementInActiveChain() const;
+    bool isUserActionElementHovered() const;
+    bool isUserActionElementFocused() const;
+
     void setStyleChange(StyleChangeType);
 
     // Used to share code between lazyAttach and setNeedsStyleRecalc.
@@ -784,7 +788,6 @@
     virtual void derefEventTarget();
 
     virtual PassOwnPtr<NodeRareData> createRareData();
-    bool rareDataFocused() const;
 
     virtual RenderStyle* nonRendererStyle() const { return 0; }
 

Modified: trunk/Source/WebCore/dom/NodeRareData.h (137276 => 137277)


--- trunk/Source/WebCore/dom/NodeRareData.h	2012-12-11 10:31:17 UTC (rev 137276)
+++ trunk/Source/WebCore/dom/NodeRareData.h	2012-12-11 10:36:24 UTC (rev 137277)
@@ -251,7 +251,6 @@
         , m_tabIndex(0)
         , m_childIndex(0)
         , m_tabIndexWasSetExplicitly(false)
-        , m_isFocused(false)
         , m_needsFocusAppearanceUpdateSoonAfterAttach(false)
         , m_styleAffectedByEmpty(false)
         , m_isInCanvasSubtree(false)
@@ -365,16 +364,12 @@
     }
 #endif
 
-    bool isFocused() const { return m_isFocused; }
-    void setFocused(bool focused) { m_isFocused = focused; }
-
     virtual void reportMemoryUsage(MemoryObjectInfo*) const;
 
 protected:
     short m_tabIndex;
     unsigned short m_childIndex;
     bool m_tabIndexWasSetExplicitly : 1;
-    bool m_isFocused : 1;
     bool m_needsFocusAppearanceUpdateSoonAfterAttach : 1;
     bool m_styleAffectedByEmpty : 1;
     bool m_isInCanvasSubtree : 1;

Added: trunk/Source/WebCore/dom/UserActionElementSet.cpp (0 => 137277)


--- trunk/Source/WebCore/dom/UserActionElementSet.cpp	                        (rev 0)
+++ trunk/Source/WebCore/dom/UserActionElementSet.cpp	2012-12-11 10:36:24 UTC (rev 137277)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UserActionElementSet.h"
+
+#include "Document.h"
+#include "Element.h"
+#include "Node.h"
+
+namespace WebCore {
+
+UserActionElementSet::UserActionElementSet()
+{
+}
+
+UserActionElementSet::~UserActionElementSet()
+{
+}
+
+void UserActionElementSet::didDetach(Node* node)
+{
+    ASSERT(node->isUserActionElement());
+    clearFlags(toElement(node), IsActiveFlag | InActiveChainFlag | IsHoveredFlag);
+}
+
+void UserActionElementSet::documentDidRemoveLastRef()
+{
+    m_elements.clear();
+}
+
+bool UserActionElementSet::hasFlags(const Node* node, unsigned flags) const
+{
+    ASSERT(node->isUserActionElement() && node->isElementNode());
+    return hasFlags(toElement(node), flags);
+}
+
+void UserActionElementSet::setFlags(Node* node, unsigned flags)
+{
+    if (!node->isElementNode())
+        return;
+    return setFlags(toElement(node), flags);
+}
+
+void UserActionElementSet::clearFlags(Node* node, unsigned flags)
+{
+    if (!node->isElementNode())
+        return;
+    return clearFlags(toElement(node), flags);
+}
+
+inline bool UserActionElementSet::hasFlags(const Element* element, unsigned flags) const
+{
+    ASSERT(element->isUserActionElement());
+    ElementFlagMap::const_iterator found = m_elements.find(const_cast<Element*>(element));
+    if (found == m_elements.end())
+        return false;
+    return found->value & flags;
+}
+
+inline void UserActionElementSet::clearFlags(Element* element, unsigned flags)
+{
+    if (!element->isUserActionElement()) {
+        ASSERT(m_elements.end() == m_elements.find(element));
+        return;
+    }
+
+    ElementFlagMap::iterator found = m_elements.find(element);
+    if (found == m_elements.end()) {
+        element->setUserActionElement(false);
+        return;
+    }
+
+    unsigned updated = found->value & ~flags;
+    if (!updated) {
+        element->setUserActionElement(false);
+        m_elements.remove(found);
+        return;
+    }
+
+    found->value = updated;
+}
+
+inline void UserActionElementSet::setFlags(Element* element, unsigned flags)
+{
+    ElementFlagMap::iterator result = m_elements.find(element);
+    if (result != m_elements.end()) {
+        ASSERT(element->isUserActionElement());
+        result->value |= flags;
+        return;
+    }
+
+    element->setUserActionElement(true);
+    m_elements.add(element, flags);
+}
+
+}

Added: trunk/Source/WebCore/dom/UserActionElementSet.h (0 => 137277)


--- trunk/Source/WebCore/dom/UserActionElementSet.h	                        (rev 0)
+++ trunk/Source/WebCore/dom/UserActionElementSet.h	2012-12-11 10:36:24 UTC (rev 137277)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UserActionElementSet_h
+#define UserActionElementSet_h
+
+#include <wtf/HashMap.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class Node;
+class Element;
+
+class UserActionElementSet {
+public:
+    static PassOwnPtr<UserActionElementSet> create() { return adoptPtr(new UserActionElementSet()); }
+
+    bool isFocused(const Node* node) { return hasFlags(node, IsFocusedFlag); }
+    bool isActive(const Node* node) { return hasFlags(node, IsActiveFlag); }
+    bool isInActiveChain(const Node* node) { return hasFlags(node, InActiveChainFlag); }
+    bool isHovered(const Node* node) { return hasFlags(node, IsHoveredFlag); }
+    void setFocused(Node* node, bool enable) { setFlags(node, enable, IsFocusedFlag); }
+    void setActive(Node* node, bool enable) { setFlags(node, enable, IsActiveFlag); }
+    void setInActiveChain(Node* node, bool enable) { setFlags(node, enable, InActiveChainFlag); }
+    void setHovered(Node* node, bool enable) { setFlags(node, enable, IsHoveredFlag); }
+
+    UserActionElementSet();
+    ~UserActionElementSet();
+
+    void didDetach(Node*);
+    void documentDidRemoveLastRef();
+
+private:
+    enum ElementFlags {
+        IsActiveFlag      = 1 ,
+        InActiveChainFlag = 1 << 1,
+        IsHoveredFlag     = 1 << 2,
+        IsFocusedFlag     = 1 << 3
+    };
+
+    void setFlags(Node* node, bool enable, unsigned flags) { enable ? setFlags(node, flags) : clearFlags(node, flags); }
+    void setFlags(Node*, unsigned);
+    void clearFlags(Node*, unsigned);
+    bool hasFlags(const Node*, unsigned flags) const;
+
+    void setFlags(Element*, unsigned);
+    void clearFlags(Element*, unsigned);
+    bool hasFlags(const Element*, unsigned flags) const;
+
+    typedef HashMap<RefPtr<Element>, unsigned> ElementFlagMap;
+    ElementFlagMap m_elements;
+};
+
+} // namespace
+
+#endif // UserActionElementSet_h
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to