diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-18 05:46:29 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-18 05:46:29 +0000 |
commit | 779aae5fa525671293b0db3ddad27cc3811a362a (patch) | |
tree | cc943534ce00344cfd998db989985de37a7e8927 /chrome/renderer/render_view_unittest.cc | |
parent | c285cf2c3dc3eb128541f07065974010dae1b408 (diff) | |
download | chromium_src-779aae5fa525671293b0db3ddad27cc3811a362a.zip chromium_src-779aae5fa525671293b0db3ddad27cc3811a362a.tar.gz chromium_src-779aae5fa525671293b0db3ddad27cc3811a362a.tar.bz2 |
A tricky fix for Issue 1845.
This change is a very tricky fix for Issue 1845 in chromium: cant alignt text to the right using right shift and right ctrl.This change consists of two parts listed below.
1. Emulating the implementation of Safari that changes the text-direction of an input element.
Safari uses context menus to change the text direction. This change adds an IPC message 'ViewMsg_SetTextDirection', which notifies the new text direction. Also, it adds two functions: RenderWidgetHost::UpdateTextDirection() and RenderWidgetHost::NotifyTextDirection(). They encapsulate the new IPC message so that we can use them both when we presses a set of keys and when we add context-menu items which change the text direction.
2. Calling the above interface when pressing right-shift and right-control keys, or when left-shift and left-control keys.
This modifies the RenderWidgetHostViewWin::OnKeyEvent() function and call the above text-direction interfaces when a user finishes pressing the keys. As you can imagine, if we send an IPC message every time when we receive a WM_KEYDOWN event, we continue sending IPC messages while a user is pressing the keys.
BUG=1845
Review URL: http://codereview.chromium.org/39252
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11953 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/render_view_unittest.cc')
-rw-r--r-- | chrome/renderer/render_view_unittest.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc index e81cf4f..a643052 100644 --- a/chrome/renderer/render_view_unittest.cc +++ b/chrome/renderer/render_view_unittest.cc @@ -317,3 +317,51 @@ TEST_F(RenderViewTest, ImeComposition) { } } } + +// Test that the RenderView::OnSetTextDirection() function can change the text +// direction of the selected input element. +TEST_F(RenderViewTest, OnSetTextDirection) { + // Load an HTML page consisting of a <textarea> element and a <div> element. + // This test changes the text direction of the <textarea> element, and + // writes the values of its 'dir' attribute and its 'direction' property to + // verify that the text direction is changed. + view_->set_delay_seconds_for_form_state_sync(0); + LoadHTML("<html>" + "<head>" + "</head>" + "<body>" + "<textarea id=\"test\"></textarea>" + "<div id=\"result\" contenteditable=\"true\"></div>" + "</body>" + "</html>"); + render_thread_.sink().ClearMessages(); + + static const struct { + WebTextDirection direction; + const wchar_t* expected_result; + } kTextDirection[] = { + {WEB_TEXT_DIRECTION_RTL, L"\x000A" L"rtl,rtl"}, + {WEB_TEXT_DIRECTION_LTR, L"\x000A" L"ltr,ltr"}, + }; + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) { + // Set the text direction of the <textarea> element. + ExecuteJavaScript("document.getElementById('test').focus();"); + view_->OnSetTextDirection(kTextDirection[i].direction); + + // Write the values of its DOM 'dir' attribute and its CSS 'direction' + // property to the <div> element. + ExecuteJavaScript("var result = document.getElementById('result');" + "var node = document.getElementById('test');" + "var style = getComputedStyle(node, null);" + "result.innerText =" + " node.getAttribute('dir') + ',' +" + " style.getPropertyValue('direction');"); + + // Copy the document content to std::wstring and compare with the + // expected result. + const int kMaxOutputCharacters = 16; + std::wstring output; + GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); + EXPECT_EQ(output, kTextDirection[i].expected_result); + } +} |