| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/ime/input_method_win.h" | 5 #include "views/ime/input_method_win.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
| 11 #include "views/events/event.h" | 11 #include "views/events/event.h" |
| 12 | 12 |
| 13 namespace views { | 13 namespace views { |
| 14 | 14 |
| 15 InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate) | 15 InputMethodWin::InputMethodWin() |
| 16 : active_(false), | 16 : active_(false), |
| 17 direction_(base::i18n::UNKNOWN_DIRECTION), | 17 direction_(base::i18n::UNKNOWN_DIRECTION), |
| 18 pending_requested_direction_(base::i18n::UNKNOWN_DIRECTION) { | 18 pending_requested_direction_(base::i18n::UNKNOWN_DIRECTION) { |
| 19 set_delegate(delegate); | |
| 20 } | 19 } |
| 21 | 20 |
| 22 InputMethodWin::~InputMethodWin() { | 21 InputMethodWin::~InputMethodWin() { |
| 23 if (widget()) | 22 if (widget()) |
| 24 ime_input_.DisableIME(hwnd()); | 23 ime_input_.DisableIME(hwnd()); |
| 25 } | 24 } |
| 26 | 25 |
| 27 void InputMethodWin::Init(Widget* widget) { | 26 void InputMethodWin::Init(Widget* widget) { |
| 28 InputMethodBase::Init(widget); | 27 InputMethodBase::Init(widget); |
| 29 | 28 |
| 30 // Gets the initial input locale and text direction information. | 29 // Gets the initial input locale and text direction information. |
| 31 OnInputLangChange(0, 0); | 30 OnInputLangChange(0, 0); |
| 32 } | 31 } |
| 33 | 32 |
| 34 void InputMethodWin::OnFocus() { | 33 void InputMethodWin::OnFocus() { |
| 35 DCHECK(!widget_focused()); | 34 DCHECK(!widget_focused()); |
| 36 InputMethodBase::OnFocus(); | 35 InputMethodBase::OnFocus(); |
| 37 UpdateIMEState(); | 36 UpdateIMEState(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 void InputMethodWin::OnBlur() { | 39 void InputMethodWin::OnBlur() { |
| 41 DCHECK(widget_focused()); | 40 DCHECK(widget_focused()); |
| 42 ConfirmCompositionText(); | 41 ConfirmCompositionText(); |
| 43 InputMethodBase::OnBlur(); | 42 InputMethodBase::OnBlur(); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void InputMethodWin::DispatchKeyEvent(const KeyEvent& key) { | 45 bool InputMethodWin::OnKeyEvent(const KeyEvent& key) { |
| 47 // Handles ctrl-shift key to change text direction and layout alignment. | 46 // Handles ctrl-shift key to change text direction and layout alignment. |
| 48 if (ui::ImeInput::IsRTLKeyboardLayoutInstalled() && !IsTextInputTypeNone()) { | 47 if (ui::ImeInput::IsRTLKeyboardLayoutInstalled() && !IsTextInputTypeNone()) { |
| 49 ui::KeyboardCode code = key.key_code(); | 48 ui::KeyboardCode code = key.key_code(); |
| 50 if (key.type() == ui::ET_KEY_PRESSED) { | 49 if (key.type() == ui::ET_KEY_PRESSED) { |
| 51 if (code == ui::VKEY_SHIFT) { | 50 if (code == ui::VKEY_SHIFT) { |
| 52 base::i18n::TextDirection dir; | 51 base::i18n::TextDirection dir; |
| 53 if (ui::ImeInput::IsCtrlShiftPressed(&dir)) | 52 if (ui::ImeInput::IsCtrlShiftPressed(&dir)) |
| 54 pending_requested_direction_ = dir; | 53 pending_requested_direction_ = dir; |
| 55 } else if (code != ui::VKEY_CONTROL) { | 54 } else if (code != ui::VKEY_CONTROL) { |
| 56 pending_requested_direction_ = base::i18n::UNKNOWN_DIRECTION; | 55 pending_requested_direction_ = base::i18n::UNKNOWN_DIRECTION; |
| 57 } | 56 } |
| 58 } else if (key.type() == ui::ET_KEY_RELEASED && | 57 } else if (key.type() == ui::ET_KEY_RELEASED && |
| 59 (code == ui::VKEY_SHIFT || code == ui::VKEY_CONTROL) && | 58 (code == ui::VKEY_SHIFT || code == ui::VKEY_CONTROL) && |
| 60 pending_requested_direction_ != base::i18n::UNKNOWN_DIRECTION) { | 59 pending_requested_direction_ != base::i18n::UNKNOWN_DIRECTION) { |
| 61 GetTextInputClient()->ChangeTextDirectionAndLayoutAlignment( | 60 GetTextInputClient()->ChangeTextDirectionAndLayoutAlignment( |
| 62 pending_requested_direction_); | 61 pending_requested_direction_); |
| 63 pending_requested_direction_ = base::i18n::UNKNOWN_DIRECTION; | 62 pending_requested_direction_ = base::i18n::UNKNOWN_DIRECTION; |
| 64 } | 63 } |
| 65 } | 64 } |
| 66 | 65 return false; |
| 67 DispatchKeyEventPostIME(key); | |
| 68 } | 66 } |
| 69 | 67 |
| 70 void InputMethodWin::OnTextInputTypeChanged(View* view) { | 68 void InputMethodWin::OnTextInputTypeChanged(View* view) { |
| 71 if (IsViewFocused(view)) { | 69 if (IsViewFocused(view)) { |
| 72 ime_input_.CancelIME(hwnd()); | 70 ime_input_.CancelIME(hwnd()); |
| 73 UpdateIMEState(); | 71 UpdateIMEState(); |
| 74 } | 72 } |
| 75 } | 73 } |
| 76 | 74 |
| 77 void InputMethodWin::OnCaretBoundsChanged(View* view) { | 75 void InputMethodWin::OnCaretBoundsChanged(View* view) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 case ui::TEXT_INPUT_TYPE_PASSWORD: | 239 case ui::TEXT_INPUT_TYPE_PASSWORD: |
| 242 ime_input_.DisableIME(hwnd()); | 240 ime_input_.DisableIME(hwnd()); |
| 243 break; | 241 break; |
| 244 default: | 242 default: |
| 245 ime_input_.EnableIME(hwnd()); | 243 ime_input_.EnableIME(hwnd()); |
| 246 break; | 244 break; |
| 247 } | 245 } |
| 248 } | 246 } |
| 249 | 247 |
| 250 } // namespace views | 248 } // namespace views |
| OLD | NEW |