Title: [207040] trunk
Revision
207040
Author
cdu...@apple.com
Date
2016-10-10 21:33:56 -0700 (Mon, 10 Oct 2016)

Log Message

Add support for languagechange event
https://bugs.webkit.org/show_bug.cgi?id=163222

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline several W3C tests now that more checks are passing.

* web-platform-tests/html/dom/interfaces-expected.txt:
* web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window-expected.txt:

Source/WebCore:

Add support for languagechange event:
- https://html.spec.whatwg.org/#dom-navigator-languages

Firefox and Chrome already support this.

Test: fast/dom/window-languagechange-event.html

* dom/EventNames.h:
* html/HTMLAttributeNames.in:
* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::createWindowEventHandlerNameMap):
* page/DOMWindow.cpp:
(WebCore::languagesChangedCallback):
(WebCore::DOMWindow::DOMWindow):
(WebCore::DOMWindow::~DOMWindow):
(WebCore::DOMWindow::languagesChanged):
(WebCore::DOMWindow::canShowModalDialog): Deleted.
(WebCore::DOMWindow::removeEventListener): Deleted.
* page/DOMWindow.h:
* page/WindowEventHandlers.idl:

LayoutTests:

Add layout test coverage.

* fast/dom/window-languagechange-event-expected.txt: Added.
* fast/dom/window-languagechange-event.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (207039 => 207040)


--- trunk/LayoutTests/ChangeLog	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/LayoutTests/ChangeLog	2016-10-11 04:33:56 UTC (rev 207040)
@@ -1,3 +1,15 @@
+2016-10-10  Chris Dumez  <cdu...@apple.com>
+
+        Add support for languagechange event
+        https://bugs.webkit.org/show_bug.cgi?id=163222
+
+        Reviewed by Ryosuke Niwa.
+
+        Add layout test coverage.
+
+        * fast/dom/window-languagechange-event-expected.txt: Added.
+        * fast/dom/window-languagechange-event.html: Added.
+
 2016-10-10  Nan Wang  <n_w...@apple.com>
 
         AX: Expose invalid status for input types with that information

Added: trunk/LayoutTests/fast/dom/window-languagechange-event-expected.txt (0 => 207040)


--- trunk/LayoutTests/fast/dom/window-languagechange-event-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/window-languagechange-event-expected.txt	2016-10-11 04:33:56 UTC (rev 207040)
@@ -0,0 +1,12 @@
+Tests the languagechange event.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS navigator.language is "en-US"
+* received languagechange event
+PASS navigator.language is "fr-FR"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/window-languagechange-event.html (0 => 207040)


--- trunk/LayoutTests/fast/dom/window-languagechange-event.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/window-languagechange-event.html	2016-10-11 04:33:56 UTC (rev 207040)
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description("Tests the languagechange event.");
+jsTestIsAsync = true;
+
+internals.setUserPreferredLanguages(["en-US"]);
+
+shouldBeEqualToString("navigator.language", "en-US");
+
+window._onlanguagechange_ = function() {
+    debug("* received languagechange event");
+
+    shouldBeEqualToString("navigator.language", "fr-FR");
+
+    window._onlanguagechange_ = null;
+
+    finishJSTest();
+}
+
+internals.setUserPreferredLanguages(["fr-FR"]);
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (207039 => 207040)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-10-11 04:33:56 UTC (rev 207040)
@@ -1,3 +1,15 @@
+2016-10-10  Chris Dumez  <cdu...@apple.com>
+
+        Add support for languagechange event
+        https://bugs.webkit.org/show_bug.cgi?id=163222
+
+        Reviewed by Ryosuke Niwa.
+
+        Rebaseline several W3C tests now that more checks are passing.
+
+        * web-platform-tests/html/dom/interfaces-expected.txt:
+        * web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window-expected.txt:
+
 2016-10-10  Ryan Haddad  <ryanhad...@apple.com>
 
         Add baseline for two tests imported with r206999.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt (207039 => 207040)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt	2016-10-11 04:33:56 UTC (rev 207040)
@@ -1351,7 +1351,7 @@
 FAIL HTMLBodyElement interface: attribute onbeforeprint assert_true: The prototype object must have a property "onbeforeprint" expected true got false
 PASS HTMLBodyElement interface: attribute onbeforeunload 
 PASS HTMLBodyElement interface: attribute onhashchange 
-FAIL HTMLBodyElement interface: attribute onlanguagechange assert_true: The prototype object must have a property "onlanguagechange" expected true got false
+PASS HTMLBodyElement interface: attribute onlanguagechange 
 PASS HTMLBodyElement interface: attribute onmessage 
 PASS HTMLBodyElement interface: attribute onoffline 
 PASS HTMLBodyElement interface: attribute ononline 
@@ -1372,7 +1372,7 @@
 FAIL HTMLBodyElement interface: document.createElement("body") must inherit property "onbeforeprint" with the proper type (7) assert_inherits: property "onbeforeprint" not found in prototype chain
 PASS HTMLBodyElement interface: document.createElement("body") must inherit property "onbeforeunload" with the proper type (8) 
 PASS HTMLBodyElement interface: document.createElement("body") must inherit property "onhashchange" with the proper type (9) 
-FAIL HTMLBodyElement interface: document.createElement("body") must inherit property "onlanguagechange" with the proper type (10) assert_inherits: property "onlanguagechange" not found in prototype chain
+PASS HTMLBodyElement interface: document.createElement("body") must inherit property "onlanguagechange" with the proper type (10) 
 PASS HTMLBodyElement interface: document.createElement("body") must inherit property "onmessage" with the proper type (11) 
 PASS HTMLBodyElement interface: document.createElement("body") must inherit property "onoffline" with the proper type (12) 
 PASS HTMLBodyElement interface: document.createElement("body") must inherit property "ononline" with the proper type (13) 
@@ -5039,7 +5039,7 @@
 FAIL Window interface: attribute onbeforeprint assert_own_property: The global object must have a property "onbeforeprint" expected property "onbeforeprint" missing
 PASS Window interface: attribute onbeforeunload 
 PASS Window interface: attribute onhashchange 
-FAIL Window interface: attribute onlanguagechange assert_own_property: The global object must have a property "onlanguagechange" expected property "onlanguagechange" missing
+PASS Window interface: attribute onlanguagechange 
 PASS Window interface: attribute onmessage 
 PASS Window interface: attribute onoffline 
 PASS Window interface: attribute ononline 
@@ -5166,7 +5166,7 @@
 FAIL Window interface: window must inherit property "onbeforeprint" with the proper type (99) assert_own_property: expected property "onbeforeprint" missing
 PASS Window interface: window must inherit property "onbeforeunload" with the proper type (100) 
 PASS Window interface: window must inherit property "onhashchange" with the proper type (101) 
-FAIL Window interface: window must inherit property "onlanguagechange" with the proper type (102) assert_own_property: expected property "onlanguagechange" missing
+PASS Window interface: window must inherit property "onlanguagechange" with the proper type (102) 
 PASS Window interface: window must inherit property "onmessage" with the proper type (103) 
 PASS Window interface: window must inherit property "onoffline" with the proper type (104) 
 PASS Window interface: window must inherit property "ononline" with the proper type (105) 
@@ -5717,7 +5717,7 @@
 FAIL HTMLFrameSetElement interface: attribute onbeforeprint assert_true: The prototype object must have a property "onbeforeprint" expected true got false
 PASS HTMLFrameSetElement interface: attribute onbeforeunload 
 PASS HTMLFrameSetElement interface: attribute onhashchange 
-FAIL HTMLFrameSetElement interface: attribute onlanguagechange assert_true: The prototype object must have a property "onlanguagechange" expected true got false
+PASS HTMLFrameSetElement interface: attribute onlanguagechange 
 PASS HTMLFrameSetElement interface: attribute onmessage 
 PASS HTMLFrameSetElement interface: attribute onoffline 
 PASS HTMLFrameSetElement interface: attribute ononline 
@@ -5734,7 +5734,7 @@
 FAIL HTMLFrameSetElement interface: document.createElement("frameset") must inherit property "onbeforeprint" with the proper type (3) assert_inherits: property "onbeforeprint" not found in prototype chain
 PASS HTMLFrameSetElement interface: document.createElement("frameset") must inherit property "onbeforeunload" with the proper type (4) 
 PASS HTMLFrameSetElement interface: document.createElement("frameset") must inherit property "onhashchange" with the proper type (5) 
-FAIL HTMLFrameSetElement interface: document.createElement("frameset") must inherit property "onlanguagechange" with the proper type (6) assert_inherits: property "onlanguagechange" not found in prototype chain
+PASS HTMLFrameSetElement interface: document.createElement("frameset") must inherit property "onlanguagechange" with the proper type (6) 
 PASS HTMLFrameSetElement interface: document.createElement("frameset") must inherit property "onmessage" with the proper type (7) 
 PASS HTMLFrameSetElement interface: document.createElement("frameset") must inherit property "onoffline" with the proper type (8) 
 PASS HTMLFrameSetElement interface: document.createElement("frameset") must inherit property "ononline" with the proper type (9) 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window-expected.txt (207039 => 207040)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window-expected.txt	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window-expected.txt	2016-10-11 04:33:56 UTC (rev 207040)
@@ -13,9 +13,7 @@
 }" but got (undefined) undefined
 PASS beforeunload 
 PASS hashchange 
-FAIL languagechange assert_equals: expected (function) function "function f() {
-  return 0;
-}" but got (undefined) undefined
+PASS languagechange 
 PASS message 
 PASS offline 
 PASS online 
@@ -34,7 +32,7 @@
 FAIL beforeprint removal assert_equals: expected (object) null but got (undefined) undefined
 PASS beforeunload removal 
 PASS hashchange removal 
-FAIL languagechange removal assert_equals: expected (object) null but got (undefined) undefined
+PASS languagechange removal 
 PASS message removal 
 PASS offline removal 
 PASS online removal 

Modified: trunk/Source/WebCore/ChangeLog (207039 => 207040)


--- trunk/Source/WebCore/ChangeLog	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/Source/WebCore/ChangeLog	2016-10-11 04:33:56 UTC (rev 207040)
@@ -1,5 +1,33 @@
 2016-10-10  Chris Dumez  <cdu...@apple.com>
 
+        Add support for languagechange event
+        https://bugs.webkit.org/show_bug.cgi?id=163222
+
+        Reviewed by Ryosuke Niwa.
+
+        Add support for languagechange event:
+        - https://html.spec.whatwg.org/#dom-navigator-languages
+
+        Firefox and Chrome already support this.
+
+        Test: fast/dom/window-languagechange-event.html
+
+        * dom/EventNames.h:
+        * html/HTMLAttributeNames.in:
+        * html/HTMLBodyElement.cpp:
+        (WebCore::HTMLBodyElement::createWindowEventHandlerNameMap):
+        * page/DOMWindow.cpp:
+        (WebCore::languagesChangedCallback):
+        (WebCore::DOMWindow::DOMWindow):
+        (WebCore::DOMWindow::~DOMWindow):
+        (WebCore::DOMWindow::languagesChanged):
+        (WebCore::DOMWindow::canShowModalDialog): Deleted.
+        (WebCore::DOMWindow::removeEventListener): Deleted.
+        * page/DOMWindow.h:
+        * page/WindowEventHandlers.idl:
+
+2016-10-10  Chris Dumez  <cdu...@apple.com>
+
         Update GamepadEvent to stop using legacy [ConstructorTemplate=Event]
         https://bugs.webkit.org/show_bug.cgi?id=163243
 

Modified: trunk/Source/WebCore/dom/EventNames.h (207039 => 207040)


--- trunk/Source/WebCore/dom/EventNames.h	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/Source/WebCore/dom/EventNames.h	2016-10-11 04:33:56 UTC (rev 207040)
@@ -132,6 +132,7 @@
     macro(keydown) \
     macro(keypress) \
     macro(keyup) \
+    macro(languagechange) \
     macro(levelchange) \
     macro(load) \
     macro(loadeddata) \

Modified: trunk/Source/WebCore/html/HTMLAttributeNames.in (207039 => 207040)


--- trunk/Source/WebCore/html/HTMLAttributeNames.in	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/Source/WebCore/html/HTMLAttributeNames.in	2016-10-11 04:33:56 UTC (rev 207040)
@@ -224,6 +224,7 @@
 ongesturestart
 ongesturechange
 ongestureend
+onlanguagechange
 onload
 onloadeddata
 onloadedmetadata

Modified: trunk/Source/WebCore/html/HTMLBodyElement.cpp (207039 => 207040)


--- trunk/Source/WebCore/html/HTMLBodyElement.cpp	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/Source/WebCore/html/HTMLBodyElement.cpp	2016-10-11 04:33:56 UTC (rev 207040)
@@ -113,6 +113,7 @@
         &onfocusinAttr,
         &onfocusoutAttr,
         &onhashchangeAttr,
+        &onlanguagechangeAttr,
         &onloadAttr,
         &onmessageAttr,
         &onofflineAttr,

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (207039 => 207040)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2016-10-11 04:33:56 UTC (rev 207040)
@@ -69,6 +69,7 @@
 #include "History.h"
 #include "InspectorInstrumentation.h"
 #include "JSMainThreadExecState.h"
+#include "Language.h"
 #include "Location.h"
 #include "MainFrame.h"
 #include "MediaQueryList.h"
@@ -392,6 +393,11 @@
     return page ? page->chrome().canRunModal() : false;
 }
 
+static void languagesChangedCallback(void* context)
+{
+    static_cast<DOMWindow*>(context)->languagesChanged();
+}
+
 void DOMWindow::setCanShowModalDialogOverride(bool allow)
 {
     m_canShowModalDialogOverride = allow;
@@ -416,6 +422,8 @@
 {
     ASSERT(frame());
     ASSERT(DOMWindow::document());
+
+    addLanguageChangeObserver(this, &languagesChangedCallback);
 }
 
 void DOMWindow::didSecureTransitionTo(Document* document)
@@ -464,6 +472,8 @@
     if (m_gamepadEventListenerCount)
         GamepadManager::singleton().unregisterDOMWindow(this);
 #endif
+
+    removeLanguageChangeObserver(this);
 }
 
 DOMWindow* DOMWindow::toDOMWindow()
@@ -1888,6 +1898,12 @@
     return true;
 }
 
+void DOMWindow::languagesChanged()
+{
+    if (auto* document = this->document())
+        document->enqueueWindowEvent(Event::create(eventNames().languagechangeEvent, false, false));
+}
+
 void DOMWindow::dispatchLoadEvent()
 {
     Ref<Event> loadEvent = Event::create(eventNames().loadEvent, false, false);

Modified: trunk/Source/WebCore/page/DOMWindow.h (207039 => 207040)


--- trunk/Source/WebCore/page/DOMWindow.h	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/Source/WebCore/page/DOMWindow.h	2016-10-11 04:33:56 UTC (rev 207040)
@@ -245,6 +245,8 @@
         void postMessageTimerFired(PostMessageTimer&);
         void dispatchMessageEventWithOriginCheck(SecurityOrigin* intendedTargetOrigin, Event&, PassRefPtr<Inspector::ScriptCallStack>);
 
+        void languagesChanged();
+
         void scrollBy(const ScrollToOptions&) const;
         void scrollBy(double x, double y) const;
         void scrollTo(const ScrollToOptions&) const;

Modified: trunk/Source/WebCore/page/WindowEventHandlers.idl (207039 => 207040)


--- trunk/Source/WebCore/page/WindowEventHandlers.idl	2016-10-11 03:39:05 UTC (rev 207039)
+++ trunk/Source/WebCore/page/WindowEventHandlers.idl	2016-10-11 04:33:56 UTC (rev 207040)
@@ -35,7 +35,7 @@
     // [WindowEventHandler] attribute EventHandler onbeforeprint;.
     [WindowEventHandler] attribute EventHandler onbeforeunload;
     [WindowEventHandler] attribute EventHandler onhashchange;
-    // [WindowEventHandler] attribute EventHandler onlanguagechange;.
+    [WindowEventHandler] attribute EventHandler onlanguagechange;
     [WindowEventHandler] attribute EventHandler onmessage;
     [WindowEventHandler] attribute EventHandler onoffline;
     [WindowEventHandler] attribute EventHandler ononline;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to