summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host
diff options
context:
space:
mode:
authorhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-25 04:31:11 +0000
committerhbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-25 04:31:11 +0000
commit07f95333a47323bfbd65c8443e0fcc470956cb27 (patch)
tree9b49d3de4d7f454b03c59ba11ae33e09d2d06621 /chrome/browser/renderer_host
parent039169f20b03406981e7417761f62dde08eb23ab (diff)
downloadchromium_src-07f95333a47323bfbd65c8443e0fcc470956cb27.zip
chromium_src-07f95333a47323bfbd65c8443e0fcc470956cb27.tar.gz
chromium_src-07f95333a47323bfbd65c8443e0fcc470956cb27.tar.bz2
A tricky fix for Issue 1845 (Take 2).
This is almost the same change as <http://codereview.chromium.org/39252/show>, which caused a build break on a Linux buildbot while compiling my new template function in "chrome/common/render_messages.h". Even though I was not able to reproduce the build errors on my Linux box, I removed this function and use the int type in my IPC message 'ViewMsg_SetTextDirection'. BUG=1845 Review URL: http://codereview.chromium.org/42495 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12434 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r--chrome/browser/renderer_host/render_widget_host.cc18
-rw-r--r--chrome/browser/renderer_host/render_widget_host.h37
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_win.cc20
3 files changed, 74 insertions, 1 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc
index 83d7bcf..b761d42 100644
--- a/chrome/browser/renderer_host/render_widget_host.cc
+++ b/chrome/browser/renderer_host/render_widget_host.cc
@@ -17,6 +17,7 @@
#include "chrome/views/view.h"
#include "webkit/glue/webcursor.h"
#include "webkit/glue/webinputevent.h"
+#include "webkit/glue/webtextdirection.h"
#if defined(OS_WIN)
#include "base/gfx/gdi_util.h"
@@ -53,7 +54,9 @@ RenderWidgetHost::RenderWidgetHost(RenderProcessHost* process,
mouse_move_pending_(false),
needs_repainting_on_restore_(false),
is_unresponsive_(false),
- view_being_painted_(false) {
+ view_being_painted_(false),
+ text_direction_updated_(false),
+ text_direction_(WEB_TEXT_DIRECTION_LTR) {
if (routing_id_ == MSG_ROUTING_NONE)
routing_id_ = process_->GetNextRoutingID();
@@ -352,6 +355,19 @@ void RenderWidgetHost::RendererExited() {
BackingStoreManager::RemoveBackingStore(this);
}
+void RenderWidgetHost::UpdateTextDirection(WebTextDirection direction) {
+ text_direction_updated_ = true;
+ text_direction_ = direction;
+}
+
+void RenderWidgetHost::NotifyTextDirection() {
+ if (text_direction_updated_) {
+ text_direction_updated_ = false;
+ Send(new ViewMsg_SetTextDirection(routing_id(),
+ static_cast<int>(text_direction_)));
+ }
+}
+
gfx::Rect RenderWidgetHost::GetRootWindowResizerRect() const {
return gfx::Rect();
}
diff --git a/chrome/browser/renderer_host/render_widget_host.h b/chrome/browser/renderer_host/render_widget_host.h
index 59235d0..7ec1638 100644
--- a/chrome/browser/renderer_host/render_widget_host.h
+++ b/chrome/browser/renderer_host/render_widget_host.h
@@ -15,6 +15,7 @@
#include "chrome/common/native_web_keyboard_event.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
#include "webkit/glue/webinputevent.h"
+#include "webkit/glue/webtextdirection.h"
namespace gfx {
class Rect;
@@ -211,6 +212,38 @@ class RenderWidgetHost : public IPC::Channel::Listener {
void ForwardWheelEvent(const WebMouseWheelEvent& wheel_event);
void ForwardKeyboardEvent(const NativeWebKeyboardEvent& key_event);
+ // Update the text direction of the focused input element and notify it to a
+ // renderer process.
+ // These functions have two usage scenarios: changing the text direction
+ // from a menu (as Safari does), and; changing the text direction when a user
+ // presses a set of keys (as IE and Firefox do).
+ // 1. Change the text direction from a menu.
+ // In this scenario, we receive a menu event only once and we should update
+ // the text direction immediately when a user chooses a menu item. So, we
+ // should call both functions at once as listed in the following snippet.
+ // void RenderViewHost::SetTextDirection(WebTextDirection direction) {
+ // UpdateTextDirection(direction);
+ // NotifyTextDirection();
+ // }
+ // 2. Change the text direction when pressing a set of keys.
+ // Becauses of auto-repeat, we may receive the same key-press event many
+ // times while we presses the keys and it is nonsense to send the same IPC
+ // messsage every time when we receive a key-press event.
+ // To suppress the number of IPC messages, we just update the text direction
+ // when receiving a key-press event and send an IPC message when we release
+ // the keys as listed in the following snippet.
+ // if (key_event.type == WebKeyboardEvent::KEY_DOWN) {
+ // if (key_event.windows_key_code == 'A' &&
+ // key_event.modifiers == WebKeyboardEvent::CTRL_KEY) {
+ // UpdateTextDirection(dir);
+ // }
+ // } else if (key_event.type == WebKeyboardEvent::KEY_UP) {
+ // NotifyTextDirection();
+ // }
+ // Note: we cannot undo this change for compatibility with Firefox and IE.
+ void UpdateTextDirection(WebTextDirection direction);
+ void NotifyTextDirection();
+
// This is for derived classes to give us access to the resizer rect.
// And to also expose it to the RenderWidgetHostView.
virtual gfx::Rect GetRootWindowResizerRect() const;
@@ -363,6 +396,10 @@ class RenderWidgetHost : public IPC::Channel::Listener {
// back to whatever unhandled handler instead of the returned version.
KeyQueue key_queue_;
+ // Set when we update the text direction of the selected input element.
+ bool text_direction_updated_;
+ WebTextDirection text_direction_;
+
DISALLOW_COPY_AND_ASSIGN(RenderWidgetHost);
};
diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc
index 12dc1ba..52751ea 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_win.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc
@@ -823,6 +823,26 @@ LRESULT RenderWidgetHostViewWin::OnKeyEvent(UINT message, WPARAM wparam,
return ::SendMessage(parent_hwnd_, message, wparam, lparam);
}
+ if (wparam == VK_SHIFT || wparam == VK_CONTROL) {
+ // Bug 1845: we need to update the text direction when a user releases
+ // either a right-shift key or a right-control key after pressing both of
+ // them. So, we just update the text direction while a user is pressing the
+ // keys, and we notify the text direction when a user releases either of
+ // them.
+ if (message == WM_KEYDOWN) {
+ const int kKeyDownMask = 0x8000;
+ if ((GetKeyState(VK_RSHIFT) & kKeyDownMask) &&
+ (GetKeyState(VK_RCONTROL) & kKeyDownMask)) {
+ render_widget_host_->UpdateTextDirection(WEB_TEXT_DIRECTION_RTL);
+ } else if ((GetKeyState(VK_LSHIFT) & kKeyDownMask) &&
+ (GetKeyState(VK_LCONTROL) & kKeyDownMask)) {
+ render_widget_host_->UpdateTextDirection(WEB_TEXT_DIRECTION_LTR);
+ }
+ } else if (message == WM_KEYUP) {
+ render_widget_host_->NotifyTextDirection();
+ }
+ }
+
render_widget_host_->ForwardKeyboardEvent(
NativeWebKeyboardEvent(m_hWnd, message, wparam, lparam));
return 0;