| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/gfx/gdi_util.h" | 8 #include "base/gfx/gdi_util.h" |
| 9 #include "base/gfx/rect.h" | 9 #include "base/gfx/rect.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 if (::IsWindowVisible(window)) { | 58 if (::IsWindowVisible(window)) { |
| 59 const HWND owner = ::GetWindow(window, GW_OWNER); | 59 const HWND owner = ::GetWindow(window, GW_OWNER); |
| 60 if (toplevel_hwnd == owner) { | 60 if (toplevel_hwnd == owner) { |
| 61 ::PostMessage(window, WM_CANCELMODE, 0, 0); | 61 ::PostMessage(window, WM_CANCELMODE, 0, 0); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 return TRUE; | 65 return TRUE; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Returns the text direction according to the keyboard status. |
| 69 // This function retrieves the status of all keys and returns the following |
| 70 // values: |
| 71 // * WEB_TEXT_DIRECTION_RTL |
| 72 // If only a control key and a right-shift key are down. |
| 73 // * WEB_TEXT_DIRECTION_LTR |
| 74 // If only a control key and a left-shift key are down. |
| 75 static bool GetNewTextDirection(WebTextDirection* direction) { |
| 76 uint8_t keystate[256]; |
| 77 if (!GetKeyboardState(&keystate[0])) |
| 78 return false; |
| 79 |
| 80 // To check if a user is pressing only a control key and a right-shift key |
| 81 // (or a left-shift key), we use the steps below: |
| 82 // 1. Check if a user is pressing a control key and a right-shift key (or |
| 83 // a left-shift key). |
| 84 // 2. If the condition 1 is true, we should check if there are any other |
| 85 // keys pressed at the same time. |
| 86 // To ignore the keys checked in 1, we set their status to 0 before |
| 87 // checking the key status. |
| 88 const int kKeyDownMask = 0x80; |
| 89 if ((keystate[VK_CONTROL] & kKeyDownMask) == 0) |
| 90 return false; |
| 91 |
| 92 if (keystate[VK_RSHIFT] & kKeyDownMask) { |
| 93 keystate[VK_RSHIFT] = 0; |
| 94 *direction = WEB_TEXT_DIRECTION_RTL; |
| 95 } else if (keystate[VK_LSHIFT] & kKeyDownMask) { |
| 96 keystate[VK_LSHIFT] = 0; |
| 97 *direction = WEB_TEXT_DIRECTION_LTR; |
| 98 } else { |
| 99 return false; |
| 100 } |
| 101 |
| 102 // Scan the key status to find pressed keys. We should adandon changing the |
| 103 // text direction when there are other pressed keys. |
| 104 // This code is executed only when a user is pressing a control key and a |
| 105 // right-shift key (or a left-shift key), i.e. we should ignore the status of |
| 106 // the keys: VK_SHIFT, VK_CONTROL, VK_RCONTROL, and VK_LCONTROL. |
| 107 // So, we reset their status to 0 and ignore them. |
| 108 keystate[VK_SHIFT] = 0; |
| 109 keystate[VK_CONTROL] = 0; |
| 110 keystate[VK_RCONTROL] = 0; |
| 111 keystate[VK_LCONTROL] = 0; |
| 112 for (int i = 0; i <= VK_PACKET; ++i) { |
| 113 if (keystate[i] & kKeyDownMask) |
| 114 return false; |
| 115 } |
| 116 return true; |
| 117 } |
| 118 |
| 68 } // namespace | 119 } // namespace |
| 69 | 120 |
| 70 // RenderWidgetHostView -------------------------------------------------------- | 121 // RenderWidgetHostView -------------------------------------------------------- |
| 71 | 122 |
| 72 // static | 123 // static |
| 73 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 124 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( |
| 74 RenderWidgetHost* widget) { | 125 RenderWidgetHost* widget) { |
| 75 return new RenderWidgetHostViewWin(widget); | 126 return new RenderWidgetHostViewWin(widget); |
| 76 } | 127 } |
| 77 | 128 |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 if (close_on_deactivate_ && | 892 if (close_on_deactivate_ && |
| 842 (((message == WM_KEYDOWN || message == WM_KEYUP) && (wparam == VK_TAB)) || | 893 (((message == WM_KEYDOWN || message == WM_KEYUP) && (wparam == VK_TAB)) || |
| 843 (message == WM_CHAR && wparam == L'\t'))) { | 894 (message == WM_CHAR && wparam == L'\t'))) { |
| 844 DCHECK(parent_hwnd_); | 895 DCHECK(parent_hwnd_); |
| 845 // First close the pop-up. | 896 // First close the pop-up. |
| 846 SendMessage(WM_CANCELMODE); | 897 SendMessage(WM_CANCELMODE); |
| 847 // Then move the focus by forwarding the tab key to the parent. | 898 // Then move the focus by forwarding the tab key to the parent. |
| 848 return ::SendMessage(parent_hwnd_, message, wparam, lparam); | 899 return ::SendMessage(parent_hwnd_, message, wparam, lparam); |
| 849 } | 900 } |
| 850 | 901 |
| 851 if (wparam == VK_SHIFT || wparam == VK_CONTROL) { | 902 // Bug 1845: we need to update the text direction when a user releases |
| 852 // Bug 1845: we need to update the text direction when a user releases | 903 // either a right-shift key or a right-control key after pressing both of |
| 853 // either a right-shift key or a right-control key after pressing both of | 904 // them. So, we just update the text direction while a user is pressing the |
| 854 // them. So, we just update the text direction while a user is pressing the | 905 // keys, and we notify the text direction when a user releases either of them. |
| 855 // keys, and we notify the text direction when a user releases either of | 906 if (message == WM_KEYDOWN) { |
| 856 // them. | 907 if (wparam == VK_SHIFT) { |
| 857 if (message == WM_KEYDOWN) { | 908 WebTextDirection direction; |
| 858 const int kKeyDownMask = 0x8000; | 909 if (GetNewTextDirection(&direction)) |
| 859 if ((GetKeyState(VK_RSHIFT) & kKeyDownMask) && | 910 render_widget_host_->UpdateTextDirection(direction); |
| 860 (GetKeyState(VK_RCONTROL) & kKeyDownMask)) { | 911 } else if (wparam != VK_CONTROL) { |
| 861 render_widget_host_->UpdateTextDirection(WEB_TEXT_DIRECTION_RTL); | 912 // A user pressed a key except shift and control keys. |
| 862 } else if ((GetKeyState(VK_LSHIFT) & kKeyDownMask) && | 913 // When a user presses a key while he/she holds control and shift keys, |
| 863 (GetKeyState(VK_LCONTROL) & kKeyDownMask)) { | 914 // we adandon sending an IPC message in a succeeding NotifyTextDirection() |
| 864 render_widget_host_->UpdateTextDirection(WEB_TEXT_DIRECTION_LTR); | 915 // call. To adandon it, this call set a flag that prevents sending an IPC |
| 865 } | 916 // message in NotifyTextDirection() only if we are going to send it. |
| 866 } else if (message == WM_KEYUP) { | 917 // So, it is harmless to call this function if we aren't going to send it. |
| 867 render_widget_host_->NotifyTextDirection(); | 918 render_widget_host_->CancelUpdateTextDirection(); |
| 868 } | 919 } |
| 920 } else if (message == WM_KEYUP && |
| 921 (wparam == VK_SHIFT || wparam == VK_CONTROL)) { |
| 922 // We send an IPC message only if we need to update the text direction. |
| 923 render_widget_host_->NotifyTextDirection(); |
| 869 } | 924 } |
| 870 | 925 |
| 871 render_widget_host_->ForwardKeyboardEvent( | 926 render_widget_host_->ForwardKeyboardEvent( |
| 872 NativeWebKeyboardEvent(m_hWnd, message, wparam, lparam)); | 927 NativeWebKeyboardEvent(m_hWnd, message, wparam, lparam)); |
| 873 return 0; | 928 return 0; |
| 874 } | 929 } |
| 875 | 930 |
| 876 LRESULT RenderWidgetHostViewWin::OnWheelEvent(UINT message, WPARAM wparam, | 931 LRESULT RenderWidgetHostViewWin::OnWheelEvent(UINT message, WPARAM wparam, |
| 877 LPARAM lparam, BOOL& handled) { | 932 LPARAM lparam, BOOL& handled) { |
| 878 // Workaround for Thinkpad mousewheel driver. We get mouse wheel/scroll | 933 // Workaround for Thinkpad mousewheel driver. We get mouse wheel/scroll |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 // WM_LBUTTONDOWN. | 1145 // WM_LBUTTONDOWN. |
| 1091 SetFocus(); | 1146 SetFocus(); |
| 1092 } | 1147 } |
| 1093 } | 1148 } |
| 1094 | 1149 |
| 1095 void RenderWidgetHostViewWin::ShutdownHost() { | 1150 void RenderWidgetHostViewWin::ShutdownHost() { |
| 1096 shutdown_factory_.RevokeAll(); | 1151 shutdown_factory_.RevokeAll(); |
| 1097 render_widget_host_->Shutdown(); | 1152 render_widget_host_->Shutdown(); |
| 1098 // Do not touch any members at this point, |this| has been deleted. | 1153 // Do not touch any members at this point, |this| has been deleted. |
| 1099 } | 1154 } |
| OLD | NEW |