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
PASS oldChildWindow.onkeydown is newChildWindow.onkeydown
PASS oldChildWindow.onkeypress is newChildWindow.onkeypress
PASS oldChildWindow.onkeyup is newChildWindow.onkeyup
PASS oldChildWindow.onlanguagechange is newChildWindow.onlanguagechange
PASS oldChildWindow.onload is newChildWindow.onload
PASS oldChildWindow.onloadeddata is newChildWindow.onloadeddata
PASS oldChildWindow.onloadedmetadata is newChildWindow.onloadedmetadata
......
......@@ -99,6 +99,7 @@ PASS childWindow.oninvalid is null
PASS childWindow.onkeydown is null
PASS childWindow.onkeypress is null
PASS childWindow.onkeyup is null
PASS childWindow.onlanguagechange is null
PASS childWindow.onload is null
PASS childWindow.onloadeddata is null
PASS childWindow.onloadedmetadata is null
......
......@@ -98,6 +98,7 @@ PASS childWindow.oninvalid is null
PASS childWindow.onkeydown is null
PASS childWindow.onkeypress is null
PASS childWindow.onkeyup is null
PASS childWindow.onlanguagechange is null
PASS childWindow.onload is null
PASS childWindow.onloadeddata 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
keydown
keypress
keyup
languagechange
levelchange
load
loadeddata
......
......@@ -37,6 +37,7 @@ namespace WebCore {
namespace DOMWindowEventHandlers {
DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(beforeunload);
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(offline);
DEFINE_STATIC_WINDOW_ATTRIBUTE_EVENT_LISTENER(online);
......
......@@ -38,6 +38,7 @@
//attribute EventHandler onbeforeprint;
attribute EventHandler onbeforeunload;
attribute EventHandler onhashchange;
attribute EventHandler onlanguagechange;
attribute EventHandler onmessage;
attribute EventHandler onoffline;
attribute EventHandler ononline;
......
......@@ -211,6 +211,7 @@ oninvalid
onkeydown
onkeypress
onkeyup
onlanguagechange
onload
onloadeddata
onloadedmetadata
......
......@@ -148,6 +148,8 @@ void HTMLBodyElement::parseAttribute(const QualifiedName& name, const AtomicStri
document().setWindowAttributeEventListener(EventTypeNames::online, createAttributeEventListener(document().frame(), name, value));
else if (name == onofflineAttr)
document().setWindowAttributeEventListener(EventTypeNames::offline, createAttributeEventListener(document().frame(), name, value));
else if (name == onlanguagechangeAttr)
document().setWindowAttributeEventListener(EventTypeNames::languagechange, createAttributeEventListener(document().frame(), name, value));
else
HTMLElement::parseAttribute(name, value);
}
......
......@@ -145,6 +145,8 @@ void HTMLFrameSetElement::parseAttribute(const QualifiedName& name, const Atomic
document().setWindowAttributeEventListener(EventTypeNames::offline, createAttributeEventListener(document().frame(), name, value));
else if (name == onpopstateAttr)
document().setWindowAttributeEventListener(EventTypeNames::popstate, createAttributeEventListener(document().frame(), name, value));
else if (name == onlanguagechangeAttr)
document().setWindowAttributeEventListener(EventTypeNames::languagechange, createAttributeEventListener(document().frame(), name, value));
else
HTMLElement::parseAttribute(name, value);
}
......
......@@ -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()
{
return static_cast<PageLifecycleNotifier&>(LifecycleContext<Page>::lifecycleNotifier());
......
......@@ -213,6 +213,8 @@ public:
void didCommitLoad(LocalFrame*);
void acceptLanguagesChanged();
static void networkStateChanged(bool online);
PassOwnPtr<LifecycleNotifier<Page> > createLifecycleNotifier();
......
......@@ -901,6 +901,10 @@ void WebViewImpl::getSelectionRootBounds(WebRect& bounds) const
void WebViewImpl::acceptLanguagesChanged()
{
if (!page())
return;
page()->acceptLanguagesChanged();
}
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