Commit 81ba4130 authored by mlamouri@chromium.org's avatar mlamouri@chromium.org

Implement languagechange event, fired when accept languages changes.

Spec: http://www.whatwg.org/specs/web-apps/current-work/multipage/section-index.html#event-languagechange

BUG=365123

Review URL: https://codereview.chromium.org/284793003

git-svn-id: svn://svn.chromium.org/blink/trunk@175135 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 2053033a
...@@ -99,6 +99,7 @@ PASS oldChildWindow.oninvalid is newChildWindow.oninvalid ...@@ -99,6 +99,7 @@ PASS oldChildWindow.oninvalid is newChildWindow.oninvalid
PASS oldChildWindow.onkeydown is newChildWindow.onkeydown PASS oldChildWindow.onkeydown is newChildWindow.onkeydown
PASS oldChildWindow.onkeypress is newChildWindow.onkeypress PASS oldChildWindow.onkeypress is newChildWindow.onkeypress
PASS oldChildWindow.onkeyup is newChildWindow.onkeyup PASS oldChildWindow.onkeyup is newChildWindow.onkeyup
PASS oldChildWindow.onlanguagechange is newChildWindow.onlanguagechange
PASS oldChildWindow.onload is newChildWindow.onload PASS oldChildWindow.onload is newChildWindow.onload
PASS oldChildWindow.onloadeddata is newChildWindow.onloadeddata PASS oldChildWindow.onloadeddata is newChildWindow.onloadeddata
PASS oldChildWindow.onloadedmetadata is newChildWindow.onloadedmetadata PASS oldChildWindow.onloadedmetadata is newChildWindow.onloadedmetadata
......
...@@ -99,6 +99,7 @@ PASS childWindow.oninvalid is null ...@@ -99,6 +99,7 @@ PASS childWindow.oninvalid is null
PASS childWindow.onkeydown is null PASS childWindow.onkeydown is null
PASS childWindow.onkeypress is null PASS childWindow.onkeypress is null
PASS childWindow.onkeyup is null PASS childWindow.onkeyup is null
PASS childWindow.onlanguagechange is null
PASS childWindow.onload is null PASS childWindow.onload is null
PASS childWindow.onloadeddata is null PASS childWindow.onloadeddata is null
PASS childWindow.onloadedmetadata is null PASS childWindow.onloadedmetadata is null
......
...@@ -98,6 +98,7 @@ PASS childWindow.oninvalid is null ...@@ -98,6 +98,7 @@ PASS childWindow.oninvalid is null
PASS childWindow.onkeydown is null PASS childWindow.onkeydown is null
PASS childWindow.onkeypress is null PASS childWindow.onkeypress is null
PASS childWindow.onkeyup is null PASS childWindow.onkeyup is null
PASS childWindow.onlanguagechange is null
PASS childWindow.onload is null PASS childWindow.onload is null
PASS childWindow.onloadeddata is null PASS childWindow.onloadeddata is null
PASS childWindow.onloadedmetadata is null PASS childWindow.onloadedmetadata is null
......
<!DOCTYPE html>
<html>
<body>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
test(function() {
assert_true('language' in window.navigator);
assert_false('languages' in window.navigator);
assert_true('onlanguagechange' in window);
}, "Test that NavigatorLanguage API is present in window");
test(function() {
var received = false;
window.onlanguagechange = function() {
received = true;
}
window.testRunner.setAcceptLanguages('klingon');
assert_true(received);
}, "Test that the languagechange event fires on window.onlanguagechange");
test(function() {
var received = false;
window.addEventListener('languagechange', function() {
received = true;
});
window.testRunner.setAcceptLanguages('klingon-FR');
assert_true(received);
}, "Test that the languagechange event fires on window.addEventListener('languagechange')");
test(function() {
window.received = false; // We need a global variable here.
document.body.setAttribute('onlanguagechange', 'window.received = true;');
window.testRunner.setAcceptLanguages('klingon-US');
assert_true(window.received);
}, "Test that the languagechange event fires on body onlanguagechange attribute");
test(function() {
window.received = 0; // We need a global variable here.
var fromWindowHandler = false;
document.body.setAttribute('onlanguagechange', 'window.received++;');
window.onlanguagechange = function() {
received++;
fromWindowHandler = true;
}
window.testRunner.setAcceptLanguages('klingon');
assert_equals(window.received, 1);
assert_true(fromWindowHandler);
window.received = 0;
fromWindowHandler = false;
window.onlanguagechange = function() {
received++;
fromWindowHandler = true;
}
document.body.setAttribute('onlanguagechange', 'window.received++;');
window.testRunner.setAcceptLanguages('klingon-FR');
assert_equals(window.received, 1);
assert_false(fromWindowHandler);
}, "Test that the languagechange event fires on body onlanguagechange attribute XOR window.onlanguagechange");
test(function() {
var eventsCount = 0;
window.onlanguagechange = function() {
eventsCount++;
}
window.testRunner.setAcceptLanguages('klingon-US');
window.testRunner.setAcceptLanguages('klingon-US');
assert_equals(eventsCount, 1);
}, "Test that changing the language to the same value doesn't fire an event.")
test(function() {
window.addEventListener('languagechange', function(e) {
assert_false(e.cancelable);
assert_false(e.bubbles);
});
window.testRunner.setAcceptLanguages('klingon');
}, "Test properties of the fired event.");
</script>
</body>
</html>
...@@ -103,6 +103,7 @@ invalid ...@@ -103,6 +103,7 @@ invalid
keydown keydown
keypress keypress
keyup keyup
languagechange
levelchange levelchange
load load
loadeddata loadeddata
......
...@@ -37,6 +37,7 @@ namespace WebCore { ...@@ -37,6 +37,7 @@ namespace WebCore {
namespace DOMWindowEventHandlers { namespace DOMWindowEventHandlers {
DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(beforeunload); DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(beforeunload);
DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(hashchange); DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(hashchange);
DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(languagechange);
DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(message); DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(message);
DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(offline); DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(offline);
DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(online); DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(online);
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
//attribute EventHandler onbeforeprint; //attribute EventHandler onbeforeprint;
attribute EventHandler onbeforeunload; attribute EventHandler onbeforeunload;
attribute EventHandler onhashchange; attribute EventHandler onhashchange;
attribute EventHandler onlanguagechange;
attribute EventHandler onmessage; attribute EventHandler onmessage;
attribute EventHandler onoffline; attribute EventHandler onoffline;
attribute EventHandler ononline; attribute EventHandler ononline;
......
...@@ -211,6 +211,7 @@ oninvalid ...@@ -211,6 +211,7 @@ oninvalid
onkeydown onkeydown
onkeypress onkeypress
onkeyup onkeyup
onlanguagechange
onload onload
onloadeddata onloadeddata
onloadedmetadata onloadedmetadata
......
...@@ -148,6 +148,8 @@ void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicStri ...@@ -148,6 +148,8 @@ void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicStri
document().setWindowAttributeEventListener(EventTypeNames::online, createAttributeEventListener(document().frame(), name, value)); document().setWindowAttributeEventListener(EventTypeNames::online, createAttributeEventListener(document().frame(), name, value));
else if (name == onofflineAttr) else if (name == onofflineAttr)
document().setWindowAttributeEventListener(EventTypeNames::offline, createAttributeEventListener(document().frame(), name, value)); document().setWindowAttributeEventListener(EventTypeNames::offline, createAttributeEventListener(document().frame(), name, value));
else if (name == onlanguagechangeAttr)
document().setWindowAttributeEventListener(EventTypeNames::languagechange, createAttributeEventListener(document().frame(), name, value));
else else
HTMLElement::parseAttribute(name, value); HTMLElement::parseAttribute(name, value);
} }
......
...@@ -145,6 +145,8 @@ void HTMLFrameSetElement::parseAttribute(const QualifiedName& name, const Atomic ...@@ -145,6 +145,8 @@ void HTMLFrameSetElement::parseAttribute(const QualifiedName& name, const Atomic
document().setWindowAttributeEventListener(EventTypeNames::offline, createAttributeEventListener(document().frame(), name, value)); document().setWindowAttributeEventListener(EventTypeNames::offline, createAttributeEventListener(document().frame(), name, value));
else if (name == onpopstateAttr) else if (name == onpopstateAttr)
document().setWindowAttributeEventListener(EventTypeNames::popstate, createAttributeEventListener(document().frame(), name, value)); document().setWindowAttributeEventListener(EventTypeNames::popstate, createAttributeEventListener(document().frame(), name, value));
else if (name == onlanguagechangeAttr)
document().setWindowAttributeEventListener(EventTypeNames::languagechange, createAttributeEventListener(document().frame(), name, value));
else else
HTMLElement::parseAttribute(name, value); HTMLElement::parseAttribute(name, value);
} }
......
...@@ -531,6 +531,17 @@ void Page::didCommitLoad(LocalFrame* frame) ...@@ -531,6 +531,17 @@ void Page::didCommitLoad(LocalFrame* frame)
} }
} }
void Page::acceptLanguagesChanged()
{
Vector< RefPtr<LocalFrame> > frames;
for (LocalFrame* frame = mainFrame(); frame; frame = frame->tree().traverseNext())
frames.append(frame);
for (unsigned i = 0; i < frames.size(); ++i)
frames[i]->domWindow()->dispatchEvent(Event::create(EventTypeNames::languagechange));
}
PageLifecycleNotifier& Page::lifecycleNotifier() PageLifecycleNotifier& Page::lifecycleNotifier()
{ {
return static_cast<PageLifecycleNotifier&>(LifecycleContext<Page>::lifecycleNotifier()); return static_cast<PageLifecycleNotifier&>(LifecycleContext<Page>::lifecycleNotifier());
......
...@@ -213,6 +213,8 @@ public: ...@@ -213,6 +213,8 @@ public:
void didCommitLoad(LocalFrame*); void didCommitLoad(LocalFrame*);
void acceptLanguagesChanged();
static void networkStateChanged(bool online); static void networkStateChanged(bool online);
PassOwnPtr<LifecycleNotifier<Page> > createLifecycleNotifier(); PassOwnPtr<LifecycleNotifier<Page> > createLifecycleNotifier();
......
...@@ -901,6 +901,10 @@ void WebViewImpl::getSelectionRootBounds(WebRect& bounds) const ...@@ -901,6 +901,10 @@ void WebViewImpl::getSelectionRootBounds(WebRect& bounds) const
void WebViewImpl::acceptLanguagesChanged() void WebViewImpl::acceptLanguagesChanged()
{ {
if (!page())
return;
page()->acceptLanguagesChanged();
} }
bool WebViewImpl::handleKeyEvent(const WebKeyboardEvent& event) bool WebViewImpl::handleKeyEvent(const WebKeyboardEvent& event)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment