Title: [196888] trunk/Source
Revision
196888
Author
[email protected]
Date
2016-02-21 18:33:29 -0800 (Sun, 21 Feb 2016)

Log Message

Refactor LazyEventListener creation to separate Element and Document cases
https://bugs.webkit.org/show_bug.cgi?id=154231

Reviewed by Andreas Kling.

Source/WebCore:

* bindings/js/JSLazyEventListener.cpp:
(WebCore::JSLazyEventListener::create): Added. Newly factored to separate
Element, Document, and DOMWindow with overloading.
(WebCore::JSLazyEventListener::createForNode): Deleted.
(WebCore::JSLazyEventListener::createForDOMWindow): Deleted.

* bindings/js/JSLazyEventListener.h: Replaced the separate createForNode
and createForDOMWindow functions with a single overloaded function create,
which takes an Element, Document, or DOMWindow. Also changed indentation
to match the style guide.

* dom/Attr.h: Added newly needed forward class declaration.

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::setAttributeEventListener): Deleted.
* dom/ContainerNode.h: Deleted setAttributeEventListener override; it's now
done separately by Element and Document.

* dom/Document.cpp:
(WebCore::Document::setAttributeEventListener): Added. Makes the lazy event
listener and calls through to the base class's setAttributeEventListener.
(WebCore::Document::setWindowAttributeEventListener): Updated to call just
create instead of createForDOMWindow.

* dom/Document.h: Removed some unneeded forward declarations. Added the
overload for setAttributeEventListener. Removed a no longer useful comment.

* dom/Element.cpp:
(WebCore::Element::setAttributeEventListener): Added. Makes the lazy event
listener and calls through to the base class's setAttributeEventListener.

* dom/Element.h: Removed some unneeded forward declarations. Added the
overload for setAttributeEventListener.

* dom/Node.h: Removed many unneeded forward declarations.

* dom/NodeRareData.h: Added one forward declaration.

* editing/Editor.h: Added one forward declaration.

Source/WebKit/win:

* WebView.h: Forward declare KeyboardEvent.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (196887 => 196888)


--- trunk/Source/WebCore/ChangeLog	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/ChangeLog	2016-02-22 02:33:29 UTC (rev 196888)
@@ -1,3 +1,50 @@
+2016-02-21  Darin Adler  <[email protected]>
+
+        Refactor LazyEventListener creation to separate Element and Document cases
+        https://bugs.webkit.org/show_bug.cgi?id=154231
+
+        Reviewed by Andreas Kling.
+
+        * bindings/js/JSLazyEventListener.cpp:
+        (WebCore::JSLazyEventListener::create): Added. Newly factored to separate
+        Element, Document, and DOMWindow with overloading.
+        (WebCore::JSLazyEventListener::createForNode): Deleted.
+        (WebCore::JSLazyEventListener::createForDOMWindow): Deleted.
+
+        * bindings/js/JSLazyEventListener.h: Replaced the separate createForNode
+        and createForDOMWindow functions with a single overloaded function create,
+        which takes an Element, Document, or DOMWindow. Also changed indentation
+        to match the style guide.
+
+        * dom/Attr.h: Added newly needed forward class declaration.
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::setAttributeEventListener): Deleted.
+        * dom/ContainerNode.h: Deleted setAttributeEventListener override; it's now
+        done separately by Element and Document.
+
+        * dom/Document.cpp:
+        (WebCore::Document::setAttributeEventListener): Added. Makes the lazy event
+        listener and calls through to the base class's setAttributeEventListener.
+        (WebCore::Document::setWindowAttributeEventListener): Updated to call just
+        create instead of createForDOMWindow.
+
+        * dom/Document.h: Removed some unneeded forward declarations. Added the
+        overload for setAttributeEventListener. Removed a no longer useful comment.
+
+        * dom/Element.cpp:
+        (WebCore::Element::setAttributeEventListener): Added. Makes the lazy event
+        listener and calls through to the base class's setAttributeEventListener.
+
+        * dom/Element.h: Removed some unneeded forward declarations. Added the
+        overload for setAttributeEventListener.
+
+        * dom/Node.h: Removed many unneeded forward declarations.
+
+        * dom/NodeRareData.h: Added one forward declaration.
+
+        * editing/Editor.h: Added one forward declaration.
+
 2016-02-21  Daniel Bates  <[email protected]>
 
         CSP: Violation report should include column number

Modified: trunk/Source/WebCore/bindings/js/JSLazyEventListener.cpp (196887 => 196888)


--- trunk/Source/WebCore/bindings/js/JSLazyEventListener.cpp	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/bindings/js/JSLazyEventListener.cpp	2016-02-22 02:33:29 UTC (rev 196888)
@@ -142,40 +142,53 @@
     return isSVGEvent ? evtString : eventString;
 }
 
-RefPtr<JSLazyEventListener> JSLazyEventListener::createForNode(ContainerNode& node, const QualifiedName& attributeName, const AtomicString& attributeValue)
+struct JSLazyEventListener::CreationArguments {
+    const QualifiedName& attributeName;
+    const AtomicString& attributeValue;
+    Document& document;
+    ContainerNode* node;
+    JSC::JSObject* wrapper;
+    bool shouldUseSVGEventName;
+};
+
+RefPtr<JSLazyEventListener> JSLazyEventListener::create(const CreationArguments& arguments)
 {
-    if (attributeValue.isNull())
+    if (arguments.attributeValue.isNull())
         return nullptr;
 
-    TextPosition position = TextPosition::minimumPosition();
+    // FIXME: We should be able to provide source information for frameless documents too (e.g. for importing nodes from XMLHttpRequest.responseXML).
+    TextPosition position;
     String sourceURL;
-
-    // FIXME: We should be able to provide source information for frameless documents too (e.g. for importing nodes from XMLHttpRequest.responseXML).
-    if (Frame* frame = node.document().frame()) {
+    if (Frame* frame = arguments.document.frame()) {
         if (!frame->script().canExecuteScripts(AboutToExecuteScript))
             return nullptr;
-
         position = frame->script().eventHandlerPosition();
-        sourceURL = node.document().url().string();
+        sourceURL = arguments.document.url().string();
     }
 
-    return adoptRef(*new JSLazyEventListener(attributeName.localName().string(),
-        eventParameterName(node.isSVGElement()), attributeValue,
-        &node, sourceURL, position, nullptr, mainThreadNormalWorld()));
+    return adoptRef(*new JSLazyEventListener(arguments.attributeName.localName().string(),
+        eventParameterName(arguments.shouldUseSVGEventName), arguments.attributeValue,
+        arguments.node, sourceURL, position, arguments.wrapper, mainThreadNormalWorld()));
 }
 
-RefPtr<JSLazyEventListener> JSLazyEventListener::createForDOMWindow(Frame& frame, const QualifiedName& attributeName, const AtomicString& attributeValue)
+RefPtr<JSLazyEventListener> JSLazyEventListener::create(Element& element, const QualifiedName& attributeName, const AtomicString& attributeValue)
 {
-    if (attributeValue.isNull())
-        return nullptr;
+    return create({ attributeName, attributeValue, element.document(), &element, nullptr, element.isSVGElement() });
+}
 
-    if (!frame.script().canExecuteScripts(AboutToExecuteScript))
-        return nullptr;
+RefPtr<JSLazyEventListener> JSLazyEventListener::create(Document& document, const QualifiedName& attributeName, const AtomicString& attributeValue)
+{
+    // FIXME: This always passes false for "shouldUseSVGEventName". Is that correct for events dispatched to SVG documents?
+    // This has been this way for a long time, but became more obvious when refactoring to separate the Element and Document code paths.
+    return create({ attributeName, attributeValue, document, &document, nullptr, false });
+}
 
-    return adoptRef(*new JSLazyEventListener(attributeName.localName().string(),
-        eventParameterName(frame.document()->isSVGDocument()), attributeValue,
-        nullptr, frame.document()->url().string(), frame.script().eventHandlerPosition(),
-        toJSDOMWindow(&frame, mainThreadNormalWorld()), mainThreadNormalWorld()));
+RefPtr<JSLazyEventListener> JSLazyEventListener::create(DOMWindow& window, const QualifiedName& attributeName, const AtomicString& attributeValue)
+{
+    ASSERT(window.document());
+    auto& document = *window.document();
+    ASSERT(document.frame());
+    return create({ attributeName, attributeValue, document, nullptr, toJSDOMWindow(document.frame(), mainThreadNormalWorld()), document.isSVGDocument() });
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/JSLazyEventListener.h (196887 => 196888)


--- trunk/Source/WebCore/bindings/js/JSLazyEventListener.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/bindings/js/JSLazyEventListener.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -26,32 +26,36 @@
 
 namespace WebCore {
 
-    class ContainerNode;
-    class Frame;
-    class QualifiedName;
+class ContainerNode;
+class DOMWindow;
+class Document;
+class Element;
+class QualifiedName;
 
-    class JSLazyEventListener final : public JSEventListener {
-    public:
-        static RefPtr<JSLazyEventListener> createForNode(ContainerNode&, const QualifiedName& attributeName, const AtomicString& attributeValue);
-        static RefPtr<JSLazyEventListener> createForDOMWindow(Frame&, const QualifiedName& attributeName, const AtomicString& attributeValue);
+class JSLazyEventListener final : public JSEventListener {
+public:
+    static RefPtr<JSLazyEventListener> create(Element&, const QualifiedName& attributeName, const AtomicString& attributeValue);
+    static RefPtr<JSLazyEventListener> create(Document&, const QualifiedName& attributeName, const AtomicString& attributeValue);
+    static RefPtr<JSLazyEventListener> create(DOMWindow&, const QualifiedName& attributeName, const AtomicString& attributeValue);
 
-        virtual ~JSLazyEventListener();
+    virtual ~JSLazyEventListener();
 
-    private:
-        JSLazyEventListener(const String& functionName, const String& eventParameterName, const String& code, ContainerNode*, const String& sourceURL, const TextPosition&, JSC::JSObject* wrapper, DOMWrapperWorld& isolatedWorld);
+private:
+    struct CreationArguments;
+    static RefPtr<JSLazyEventListener> create(const CreationArguments&);
 
-        virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const override;
-        virtual bool wasCreatedFromMarkup() const override { return true; }
+    JSLazyEventListener(const String& functionName, const String& eventParameterName, const String& code, ContainerNode*, const String& sourceURL, const TextPosition&, JSC::JSObject* wrapper, DOMWrapperWorld& isolatedWorld);
 
-        static void create() = delete;
+    virtual JSC::JSObject* initializeJSFunction(ScriptExecutionContext*) const override;
+    virtual bool wasCreatedFromMarkup() const override { return true; }
 
-        mutable String m_functionName;
-        mutable String m_eventParameterName;
-        mutable String m_code;
-        mutable String m_sourceURL;
-        TextPosition m_position;
-        ContainerNode* m_originalNode;
-    };
+    mutable String m_functionName;
+    mutable String m_eventParameterName;
+    mutable String m_code;
+    mutable String m_sourceURL;
+    TextPosition m_position;
+    ContainerNode* m_originalNode;
+};
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/dom/Attr.h (196887 => 196888)


--- trunk/Source/WebCore/dom/Attr.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/Attr.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -30,6 +30,7 @@
 
 namespace WebCore {
 
+class Attribute;
 class CSSStyleDeclaration;
 class MutableStyleProperties;
 

Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (196887 => 196888)


--- trunk/Source/WebCore/dom/ContainerNode.cpp	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp	2016-02-22 02:33:29 UTC (rev 196888)
@@ -38,7 +38,6 @@
 #include "HTMLSlotElement.h"
 #include "HTMLTableRowsCollection.h"
 #include "InlineTextBox.h"
-#include "JSLazyEventListener.h"
 #include "JSNode.h"
 #include "LabelsNodeList.h"
 #include "MutationEvent.h"
@@ -828,11 +827,6 @@
     dispatchChildInsertionEvents(child);
 }
 
-void ContainerNode::setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& attributeValue)
-{
-    setAttributeEventListener(eventType, JSLazyEventListener::createForNode(*this, attributeName, attributeValue));
-}
-
 Element* ContainerNode::querySelector(const String& selectors, ExceptionCode& ec)
 {
     if (SelectorQuery* selectorQuery = document().selectorQueryForString(selectors, ec))

Modified: trunk/Source/WebCore/dom/ContainerNode.h (196887 => 196888)


--- trunk/Source/WebCore/dom/ContainerNode.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/ContainerNode.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -31,9 +31,7 @@
 namespace WebCore {
 
 class HTMLCollection;
-class NodeList;
-class NodeOrString;
-class QualifiedName;
+class RadioNodeList;
 class RenderElement;
 
 class NoEventDispatchAssertion {
@@ -124,9 +122,6 @@
 
     void disconnectDescendantFrames();
 
-    using Node::setAttributeEventListener;
-    void setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
-
     RenderElement* renderer() const;
 
     // Return a bounding box in absolute coordinates enclosing this node and all its descendants.

Modified: trunk/Source/WebCore/dom/Document.cpp (196887 => 196888)


--- trunk/Source/WebCore/dom/Document.cpp	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/Document.cpp	2016-02-22 02:33:29 UTC (rev 196888)
@@ -4078,6 +4078,11 @@
     ASSERT(m_domWindow->frame() == m_frame);
 }
 
+void Document::setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& attributeValue)
+{
+    setAttributeEventListener(eventType, JSLazyEventListener::create(*this, attributeName, attributeValue));
+}
+
 void Document::setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener)
 {
     if (!m_domWindow)
@@ -4087,9 +4092,9 @@
 
 void Document::setWindowAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& attributeValue)
 {
-    if (!m_frame)
+    if (!m_domWindow)
         return;
-    setWindowAttributeEventListener(eventType, JSLazyEventListener::createForDOMWindow(*m_frame, attributeName, attributeValue));
+    setWindowAttributeEventListener(eventType, JSLazyEventListener::create(*m_domWindow, attributeName, attributeValue));
 }
 
 EventListener* Document::getWindowAttributeEventListener(const AtomicString& eventType)

Modified: trunk/Source/WebCore/dom/Document.h (196887 => 196888)


--- trunk/Source/WebCore/dom/Document.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/Document.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -93,10 +93,7 @@
 class DocumentParser;
 class DocumentSharedObjectPool;
 class DocumentType;
-class Element;
 class EntityReference;
-class Event;
-class EventListener;
 class ExtensionStyleSheets;
 class FloatRect;
 class FloatQuad;
@@ -141,7 +138,6 @@
 class ProcessingInstruction;
 class QualifiedName;
 class Range;
-class RegisteredEventListener;
 class RenderView;
 class RenderFullScreen;
 class ScriptableDocumentParser;
@@ -726,10 +722,6 @@
 
     MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const LayoutPoint&, const PlatformMouseEvent&);
 
-    /* Newly proposed CSS3 mechanism for selecting alternate
-       stylesheets using the DOM. May be subject to change as
-       spec matures. - dwh
-    */
     String preferredStylesheetSet() const;
     String selectedStylesheetSet() const;
     void setSelectedStylesheetSet(const String&);
@@ -1322,6 +1314,9 @@
     bool hasHadActiveMediaStreamTrack() const { return m_hasHadActiveMediaStreamTrack; }
 #endif
 
+    using ContainerNode::setAttributeEventListener;
+    void setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
+
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);

Modified: trunk/Source/WebCore/dom/Element.cpp (196887 => 196888)


--- trunk/Source/WebCore/dom/Element.cpp	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-02-22 02:33:29 UTC (rev 196888)
@@ -59,6 +59,7 @@
 #include "HTMLTemplateElement.h"
 #include "IdChangeInvalidation.h"
 #include "IdTargetObserverRegistry.h"
+#include "JSLazyEventListener.h"
 #include "KeyboardEvent.h"
 #include "MainFrame.h"
 #include "MutationObserverInterestGroup.h"
@@ -1830,6 +1831,11 @@
 #endif
 }
 
+void Element::setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& attributeValue)
+{
+    setAttributeEventListener(eventType, JSLazyEventListener::create(*this, attributeName, attributeValue));
+}
+
 void Element::removeAllEventListeners()
 {
     ContainerNode::removeAllEventListeners();

Modified: trunk/Source/WebCore/dom/Element.h (196887 => 196888)


--- trunk/Source/WebCore/dom/Element.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/Element.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -44,6 +44,7 @@
 class ElementRareData;
 class HTMLDocument;
 class IntSize;
+class KeyboardEvent;
 class Locale;
 class PlatformKeyboardEvent;
 class PlatformMouseEvent;
@@ -51,7 +52,6 @@
 class PseudoElement;
 class RenderNamedFlowFragment;
 class RenderTreePosition;
-class ShadowRoot;
 
 enum SpellcheckAttributeState {
     SpellcheckAttributeTrue,
@@ -499,6 +499,9 @@
 
     virtual void isVisibleInViewportChanged() { }
 
+    using ContainerNode::setAttributeEventListener;
+    void setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
+
 protected:
     Element(const QualifiedName&, Document&, ConstructionType);
 

Modified: trunk/Source/WebCore/dom/Node.h (196887 => 196888)


--- trunk/Source/WebCore/dom/Node.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/Node.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -41,50 +41,28 @@
 
 namespace WebCore {
 
-class Attribute;
-class ClassCollection;
 class ContainerNode;
-class DOMTokenList;
 class Document;
 class Element;
-class Event;
-class EventListener;
 class FloatPoint;
-class Frame;
-class HTMLInputElement;
 class HTMLQualifiedName;
 class HTMLSlotElement;
-class IntRect;
-class KeyboardEvent;
 class MathMLQualifiedName;
-class NSResolver;
-class NameNodeList;
 class NamedNodeMap;
 class NodeList;
 class NodeListsNodeData;
 class NodeOrString;
 class NodeRareData;
 class QualifiedName;
-class RadioNodeList;
-class RegisteredEventListener;
 class RenderBox;
 class RenderBoxModelObject;
 class RenderObject;
 class RenderStyle;
 class SVGQualifiedName;
 class ShadowRoot;
-class TagCollection;
-
-#if ENABLE(INDIE_UI)
-class UIRequestEvent;
-#endif
-    
-#if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
 class TouchEvent;
-#endif
+class UIRequestEvent;
 
-typedef int ExceptionCode;
-
 const int nodeStyleChangeShift = 14;
 
 // SyntheticStyleChange means that we need to go through the entire style change logic even though

Modified: trunk/Source/WebCore/dom/NodeRareData.h (196887 => 196888)


--- trunk/Source/WebCore/dom/NodeRareData.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/dom/NodeRareData.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -43,6 +43,7 @@
 namespace WebCore {
 
 class LabelsNodeList;
+class NameNodeList;
 class RadioNodeList;
 class TreeScope;
 

Modified: trunk/Source/WebCore/editing/Editor.h (196887 => 196888)


--- trunk/Source/WebCore/editing/Editor.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebCore/editing/Editor.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -62,6 +62,7 @@
 class Frame;
 class HTMLElement;
 class HitTestResult;
+class KeyboardEvent;
 class KillRing;
 class Pasteboard;
 class SharedBuffer;

Modified: trunk/Source/WebKit/win/ChangeLog (196887 => 196888)


--- trunk/Source/WebKit/win/ChangeLog	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebKit/win/ChangeLog	2016-02-22 02:33:29 UTC (rev 196888)
@@ -1,3 +1,12 @@
+2016-02-21  Darin Adler  <[email protected]>
+
+        Refactor LazyEventListener creation to separate Element and Document cases
+        https://bugs.webkit.org/show_bug.cgi?id=154231
+
+        Reviewed by Andreas Kling.
+
+        * WebView.h: Forward declare KeyboardEvent.
+
 2016-02-16  Andreas Kling  <[email protected]>
 
         Drop StyleResolver and SelectorQueryCache when entering PageCache.

Modified: trunk/Source/WebKit/win/WebView.h (196887 => 196888)


--- trunk/Source/WebKit/win/WebView.h	2016-02-22 01:55:41 UTC (rev 196887)
+++ trunk/Source/WebKit/win/WebView.h	2016-02-22 02:33:29 UTC (rev 196888)
@@ -59,10 +59,8 @@
     struct GraphicsDeviceAdapter;
 #endif
     class HTMLVideoElement;
-}
-
-namespace WebCore {
     class HistoryItem;
+    class KeyboardEvent;
 }
 
 class FullscreenVideoController;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to