Implement FocusEvent constructor
authorharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 00:37:49 +0000 (00:37 +0000)
committerharaken@chromium.org <haraken@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Feb 2013 00:37:49 +0000 (00:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109170

Reviewed by Adam Barth.

Editor's draft: https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm

FocusEvent constructor should be implemented under a DOM4_EVENTS_CONSTRUCTOR
flag, which is enabled on Chromium and Safari.

Source/WebCore:

Test: fast/events/constructors/focus-event-constructor.html

* dom/FocusEvent.cpp:
(WebCore::FocusEventInit::FocusEventInit):
(WebCore):
(WebCore::FocusEvent::FocusEvent):
* dom/FocusEvent.h:
(FocusEventInit):
(WebCore):
(WebCore::FocusEvent::create):
(FocusEvent):
* dom/FocusEvent.idl:
* page/DOMWindow.idl:

LayoutTests:

* fast/dom/constructed-objects-prototypes-expected.txt:
* fast/events/constructors/focus-event-constructor-expected.txt: Added.
* fast/events/constructors/focus-event-constructor.html: Added.
* platform/efl/TestExpectations:
* platform/gtk/TestExpectations:
* platform/qt/TestExpectations:
* platform/win/TestExpectations:
* platform/wincairo/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142205 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/constructed-objects-prototypes-expected.txt
LayoutTests/fast/events/constructors/focus-event-constructor-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/constructors/focus-event-constructor.html [new file with mode: 0644]
LayoutTests/platform/efl/TestExpectations
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/qt/TestExpectations
LayoutTests/platform/win/TestExpectations
LayoutTests/platform/wincairo/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/dom/FocusEvent.cpp
Source/WebCore/dom/FocusEvent.h
Source/WebCore/dom/FocusEvent.idl
Source/WebCore/page/DOMWindow.idl

index ee6dad5..576d9a5 100644 (file)
@@ -1,3 +1,24 @@
+2013-02-07  Kentaro Hara  <haraken@chromium.org>
+
+        Implement FocusEvent constructor
+        https://bugs.webkit.org/show_bug.cgi?id=109170
+
+        Reviewed by Adam Barth.
+
+        Editor's draft: https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm
+
+        FocusEvent constructor should be implemented under a DOM4_EVENTS_CONSTRUCTOR
+        flag, which is enabled on Chromium and Safari.
+
+        * fast/dom/constructed-objects-prototypes-expected.txt:
+        * fast/events/constructors/focus-event-constructor-expected.txt: Added.
+        * fast/events/constructors/focus-event-constructor.html: Added.
+        * platform/efl/TestExpectations:
+        * platform/gtk/TestExpectations:
+        * platform/qt/TestExpectations:
+        * platform/win/TestExpectations:
+        * platform/wincairo/TestExpectations:
+
 2013-02-07  Elliott Sprehn  <esprehn@chromium.org>
 
         HTML parser should queue MutationRecords for its operations
index 04a0622..26d8e67 100644 (file)
@@ -21,6 +21,8 @@ PASS (new inner.ErrorEvent()).isInner is true
 PASS (new inner.ErrorEvent()).constructor.isInner is true
 PASS (new inner.Event()).isInner is true
 PASS (new inner.Event()).constructor.isInner is true
+PASS (new inner.FocusEvent()).isInner is true
+PASS (new inner.FocusEvent()).constructor.isInner is true
 PASS (new inner.FormData()).isInner is true
 PASS (new inner.FormData()).constructor.isInner is true
 PASS (new inner.HashChangeEvent()).isInner is true
diff --git a/LayoutTests/fast/events/constructors/focus-event-constructor-expected.txt b/LayoutTests/fast/events/constructors/focus-event-constructor-expected.txt
new file mode 100644 (file)
index 0000000..346033e
--- /dev/null
@@ -0,0 +1,56 @@
+This tests the constructor for the FocusEvent DOM class.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS new FocusEvent('eventType').bubbles is false
+PASS new FocusEvent('eventType').cancelable is false
+PASS new FocusEvent('eventType').view is null
+PASS new FocusEvent('eventType').detail is 0
+PASS new FocusEvent('eventType').relatedTarget is null
+PASS new FocusEvent('eventType', { bubbles: false }).bubbles is false
+PASS new FocusEvent('eventType', { bubbles: true }).bubbles is true
+PASS new FocusEvent('eventType', { cancelable: false }).cancelable is false
+PASS new FocusEvent('eventType', { cancelable: true }).cancelable is true
+PASS new FocusEvent('eventType', { view: window }).view is window
+PASS new FocusEvent('eventType', { view: this }).view is this
+PASS new FocusEvent('eventType', { view: testObject }).view is null
+PASS new FocusEvent('eventType', { view: document }).view is null
+PASS new FocusEvent('eventType', { view: undefined }).view is null
+PASS new FocusEvent('eventType', { view: null }).view is null
+PASS new FocusEvent('eventType', { view: false }).view is null
+PASS new FocusEvent('eventType', { view: true }).view is null
+PASS new FocusEvent('eventType', { view: '' }).view is null
+PASS new FocusEvent('eventType', { view: 'chocolate' }).view is null
+PASS new FocusEvent('eventType', { view: 12345 }).view is null
+PASS new FocusEvent('eventType', { view: 18446744073709551615 }).view is null
+PASS new FocusEvent('eventType', { view: NaN }).view is null
+PASS new FocusEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window is false
+PASS new FocusEvent('eventType', { get view() { return 123; } }).view is null
+PASS new FocusEvent('eventType', { get view() { throw 'FocusEvent Error'; } }) threw exception FocusEvent Error.
+PASS new FocusEvent('eventType', { relatedTarget: testDiv }).relatedTarget is testDiv
+PASS new FocusEvent('eventType', { relatedTarget: document }).relatedTarget is document
+PASS new FocusEvent('eventType', { relatedTarget: xhr }).relatedTarget is xhr
+PASS new FocusEvent('eventType', { relatedTarget: window }).relatedTarget is window
+PASS new FocusEvent('eventType', { relatedTarget: testObject }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: undefined }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: null }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: false }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: true }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: '' }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: 'chocolate' }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: 12345 }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: 18446744073709551615 }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: NaN }).relatedTarget is null
+PASS new FocusEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } }).relatedTarget == testDiv is false
+PASS new FocusEvent('eventType', { get relatedTarget() { return 123; } }).relatedTarget is null
+PASS new FocusEvent('eventType', { get relatedTarget() { throw 'FocusEvent Error'; } }) threw exception FocusEvent Error.
+PASS new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).bubbles is true
+PASS new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).cancelable is true
+PASS new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).view is window
+PASS new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).detail is 111
+PASS new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).relatedTarget is testDiv
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/constructors/focus-event-constructor.html b/LayoutTests/fast/events/constructors/focus-event-constructor.html
new file mode 100644 (file)
index 0000000..c304480
--- /dev/null
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+
+description("This tests the constructor for the FocusEvent DOM class.");
+
+var testObject = {nyannyan: 123};
+var testDiv = document.createElement("div");
+var xhr = new XMLHttpRequest;
+
+// No initializer is passed.
+shouldBe("new FocusEvent('eventType').bubbles", "false");
+shouldBe("new FocusEvent('eventType').cancelable", "false");
+shouldBe("new FocusEvent('eventType').view", "null");
+shouldBe("new FocusEvent('eventType').detail", "0");
+shouldBe("new FocusEvent('eventType').relatedTarget", "null");
+
+// bubbles is passed.
+shouldBe("new FocusEvent('eventType', { bubbles: false }).bubbles", "false");
+shouldBe("new FocusEvent('eventType', { bubbles: true }).bubbles", "true");
+
+// cancelable is passed.
+shouldBe("new FocusEvent('eventType', { cancelable: false }).cancelable", "false");
+shouldBe("new FocusEvent('eventType', { cancelable: true }).cancelable", "true");
+
+// view is passed.
+// Window objects.
+shouldBe("new FocusEvent('eventType', { view: window }).view", "window");
+shouldBe("new FocusEvent('eventType', { view: this }).view", "this");
+
+// Non-window objects.
+shouldBe("new FocusEvent('eventType', { view: testObject }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: document }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: undefined }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: null }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: false }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: true }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: '' }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: 'chocolate' }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: 12345 }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: 18446744073709551615 }).view", "null");
+shouldBe("new FocusEvent('eventType', { view: NaN }).view", "null");
+// Note that valueOf() is not called, when the left hand side is evaluated.
+shouldBeFalse("new FocusEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window");
+shouldBe("new FocusEvent('eventType', { get view() { return 123; } }).view", "null");
+shouldThrow("new FocusEvent('eventType', { get view() { throw 'FocusEvent Error'; } })");
+
+// relatedTarget is passed.
+// Valid objects.
+shouldBe("new FocusEvent('eventType', { relatedTarget: testDiv }).relatedTarget", "testDiv");
+shouldBe("new FocusEvent('eventType', { relatedTarget: document }).relatedTarget", "document");
+shouldBe("new FocusEvent('eventType', { relatedTarget: xhr }).relatedTarget", "xhr");
+shouldBe("new FocusEvent('eventType', { relatedTarget: window }).relatedTarget", "window");
+
+// Invalid objects.
+shouldBe("new FocusEvent('eventType', { relatedTarget: testObject }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: false }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: true }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: '' }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: 'chocolate' }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: 12345 }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: 18446744073709551615 }).relatedTarget", "null");
+shouldBe("new FocusEvent('eventType', { relatedTarget: NaN }).relatedTarget", "null");
+// Note that valueOf() is not called, when the left hand side is evaluated.
+shouldBeFalse("new FocusEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } }).relatedTarget == testDiv");
+shouldBe("new FocusEvent('eventType', { get relatedTarget() { return 123; } }).relatedTarget", "null");
+shouldThrow("new FocusEvent('eventType', { get relatedTarget() { throw 'FocusEvent Error'; } })");
+
+// All initializers are passed.
+shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).bubbles", "true");
+shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).cancelable", "true");
+shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).view", "window");
+shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).detail", "111");
+shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).relatedTarget", "testDiv");
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 2ce9e68..1a637c7 100644 (file)
@@ -1247,6 +1247,7 @@ webkit.org/b/107428 fast/events/constructors/mouse-event-constructor.html [ Skip
 webkit.org/b/107428 fast/events/constructors/wheel-event-constructor.html [ Skip ]
 webkit.org/b/107428 fast/events/constructors/keyboard-event-constructor.html [ Skip ]
 webkit.org/b/107428 fast/events/constructors/composition-event-constructor.html [ Skip ]
+webkit.org/b/107428 fast/events/constructors/focus-event-constructor.html [ Skip ]
 
 # Requires support for Web notifications
 webkit.org/b/73544 fast/notifications [ Skip ]
index dc85ad8..b6287de 100644 (file)
@@ -402,6 +402,7 @@ webkit.org/b/107428 fast/events/constructors/mouse-event-constructor.html [ Skip
 webkit.org/b/107428 fast/events/constructors/wheel-event-constructor.html [ Skip ]
 webkit.org/b/107428 fast/events/constructors/keyboard-event-constructor.html [ Skip ]
 webkit.org/b/107428 fast/events/constructors/composition-event-constructor.html [ Skip ]
+webkit.org/b/107428 fast/events/constructors/focus-event-constructor.html [ Skip ]
 
 # No CORS support for media elements is implemented yet.
 webkit.org/b/99037 http/tests/security/video-cross-origin-readback.html [ Failure ]
index 6596aed..8062b3e 100644 (file)
@@ -115,6 +115,7 @@ fast/events/constructors/mouse-event-constructor.html
 fast/events/constructors/composition-event-constructor.html
 fast/events/constructors/wheel-event-constructor.html
 fast/events/constructors/keyboard-event-constructor.html
+fast/events/constructors/focus-event-constructor.html
 
 # ENABLE(INDEXED_DATABASE) is disabled.
 storage/indexeddb
index 18d54da..ea55957 100644 (file)
@@ -1225,6 +1225,7 @@ fast/events/constructors/mouse-event-constructor.html
 fast/events/constructors/composition-event-constructor.html
 fast/events/constructors/wheel-event-constructor.html
 fast/events/constructors/keyboard-event-constructor.html
+fast/events/constructors/focus-event-constructor.html
 
 # Disable until the windows WebKit API supports injecting in the top frame only.
 # https://bugs.webkit.org/show_bug.cgi?id=41800
index 2c4eb89..1c0d685 100644 (file)
@@ -1748,6 +1748,7 @@ fast/events/constructors/mouse-event-constructor.html
 fast/events/constructors/composition-event-constructor.html
 fast/events/constructors/wheel-event-constructor.html
 fast/events/constructors/keyboard-event-constructor.html
+fast/events/constructors/focus-event-constructor.html
 
 # Disable until the windows WebKit API supports injecting in the top frame only.
 # https://bugs.webkit.org/show_bug.cgi?id=41800
index 46fbf85..eff2bbe 100644 (file)
@@ -1,3 +1,29 @@
+2013-02-07  Kentaro Hara  <haraken@chromium.org>
+
+        Implement FocusEvent constructor
+        https://bugs.webkit.org/show_bug.cgi?id=109170
+
+        Reviewed by Adam Barth.
+
+        Editor's draft: https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm
+
+        FocusEvent constructor should be implemented under a DOM4_EVENTS_CONSTRUCTOR
+        flag, which is enabled on Chromium and Safari.
+
+        Test: fast/events/constructors/focus-event-constructor.html
+
+        * dom/FocusEvent.cpp:
+        (WebCore::FocusEventInit::FocusEventInit):
+        (WebCore):
+        (WebCore::FocusEvent::FocusEvent):
+        * dom/FocusEvent.h:
+        (FocusEventInit):
+        (WebCore):
+        (WebCore::FocusEvent::create):
+        (FocusEvent):
+        * dom/FocusEvent.idl:
+        * page/DOMWindow.idl:
+
 2013-02-07  Elliott Sprehn  <esprehn@chromium.org>
 
         HTML parser should queue MutationRecords for its operations
index 622ffd2..d806001 100644 (file)
 
 namespace WebCore {
 
+FocusEventInit::FocusEventInit()
+    : relatedTarget(0)
+{
+}
+
 const AtomicString& FocusEvent::interfaceName() const
 {
     return eventNames().interfaceForFocusEvent;
@@ -51,4 +56,10 @@ FocusEvent::FocusEvent(const AtomicString& type, bool canBubble, bool cancelable
 {
 }
 
+FocusEvent::FocusEvent(const AtomicString& type, const FocusEventInit& initializer)
+    : UIEvent(type, initializer)
+    , m_relatedTarget(initializer.relatedTarget)
+{
+}
+
 } // namespace WebCore
index 5a99fd8..1396cde 100644 (file)
 
 namespace WebCore {
 
+struct FocusEventInit : public UIEventInit {
+    FocusEventInit();
+
+    RefPtr<EventTarget> relatedTarget;
+};
+
 class FocusEvent : public UIEvent {
 public:
     static PassRefPtr<FocusEvent> create()
@@ -43,6 +49,11 @@ public:
         return adoptRef(new FocusEvent(type, canBubble, cancelable, view, detail, relatedTarget));
     }
 
+    static PassRefPtr<FocusEvent> create(const AtomicString& type, const FocusEventInit& initializer)
+    {
+        return adoptRef(new FocusEvent(type, initializer));
+    }
+
     EventTarget* relatedTarget() const { return m_relatedTarget.get(); }
     void setRelatedTarget(PassRefPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; }
 
@@ -52,6 +63,7 @@ public:
 private:
     FocusEvent();
     FocusEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, int, PassRefPtr<EventTarget>);
+    FocusEvent(const AtomicString& type, const FocusEventInit&);
 
     RefPtr<EventTarget> m_relatedTarget;
 };
index 01dac94..fc422c3 100644 (file)
@@ -23,7 +23,9 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-interface FocusEvent : UIEvent
-{
-    readonly attribute EventTarget relatedTarget;
+[
+    ConstructorConditional=DOM4_EVENTS_CONSTRUCTOR,
+    ConstructorTemplate=Event
+] interface FocusEvent : UIEvent {
+    [InitializedByEventConstructor] readonly attribute EventTarget relatedTarget;
 };
index 9921102..0255214 100644 (file)
     attribute CompositionEventConstructor CompositionEvent;
     attribute CustomEventConstructor CustomEvent;
     attribute ErrorEventConstructor ErrorEvent;
+    attribute FocusEventConstructor FocusEvent;
     attribute HashChangeEventConstructor HashChangeEvent;
     attribute KeyboardEventConstructor KeyboardEvent;
     attribute MessageEventConstructor MessageEvent;