Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: ui/base/ime/input_method_ibus.cc

Issue 11956008: Move SetCursorLocation bypass code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit tests Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/base/ime/input_method_ibus.h" 5 #include "ui/base/ime/input_method_ibus.h"
6 6
7 #include <X11/X.h> 7 #include <X11/X.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 #include <X11/Xutil.h> 9 #include <X11/Xutil.h>
10 #undef FocusIn 10 #undef FocusIn
(...skipping 10 matching lines...) Expand all
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 #include "base/third_party/icu/icu_utf.h" 23 #include "base/third_party/icu/icu_utf.h"
24 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
25 #include "chromeos/dbus/dbus_thread_manager.h" 25 #include "chromeos/dbus/dbus_thread_manager.h"
26 #include "chromeos/dbus/ibus/ibus_client.h" 26 #include "chromeos/dbus/ibus/ibus_client.h"
27 #include "chromeos/dbus/ibus/ibus_input_context_client.h" 27 #include "chromeos/dbus/ibus/ibus_input_context_client.h"
28 #include "chromeos/dbus/ibus/ibus_text.h" 28 #include "chromeos/dbus/ibus/ibus_text.h"
29 #include "ui/base/events/event_constants.h" 29 #include "ui/base/events/event_constants.h"
30 #include "ui/base/events/event_utils.h" 30 #include "ui/base/events/event_utils.h"
31 #include "ui/base/ime/ibus_client.h"
32 #include "ui/base/ime/text_input_client.h" 31 #include "ui/base/ime/text_input_client.h"
33 #include "ui/base/keycodes/keyboard_code_conversion.h" 32 #include "ui/base/keycodes/keyboard_code_conversion.h"
34 #include "ui/base/keycodes/keyboard_code_conversion_x.h" 33 #include "ui/base/keycodes/keyboard_code_conversion_x.h"
35 #include "ui/base/keycodes/keyboard_codes.h" 34 #include "ui/base/keycodes/keyboard_codes.h"
36 #include "ui/gfx/rect.h" 35 #include "ui/gfx/rect.h"
37 36
38 namespace { 37 namespace {
39 38
40 const int kIBusReleaseMask = 1 << 30; 39 const int kIBusReleaseMask = 1 << 30;
41 const char kClientName[] = "chrome"; 40 const char kClientName[] = "chrome";
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return chromeos::DBusThreadManager::Get()->GetIBusInputContextClient(); 72 return chromeos::DBusThreadManager::Get()->GetIBusInputContextClient();
74 } 73 }
75 74
76 } // namespace 75 } // namespace
77 76
78 namespace ui { 77 namespace ui {
79 78
80 // InputMethodIBus implementation ----------------------------------------- 79 // InputMethodIBus implementation -----------------------------------------
81 InputMethodIBus::InputMethodIBus( 80 InputMethodIBus::InputMethodIBus(
82 internal::InputMethodDelegate* delegate) 81 internal::InputMethodDelegate* delegate)
83 : ibus_client_(new internal::IBusClient), 82 : input_context_state_(INPUT_CONTEXT_STOP),
84 input_context_state_(INPUT_CONTEXT_STOP),
85 create_input_context_fail_count_(0), 83 create_input_context_fail_count_(0),
86 context_focused_(false), 84 context_focused_(false),
87 composing_text_(false), 85 composing_text_(false),
88 composition_changed_(false), 86 composition_changed_(false),
89 suppress_next_result_(false), 87 suppress_next_result_(false),
90 current_keyevent_id_(0), 88 current_keyevent_id_(0),
91 weak_ptr_factory_(this) { 89 weak_ptr_factory_(this) {
92 SetDelegate(delegate); 90 SetDelegate(delegate);
93 } 91 }
94 92
95 InputMethodIBus::~InputMethodIBus() { 93 InputMethodIBus::~InputMethodIBus() {
96 AbandonAllPendingKeyEvents(); 94 AbandonAllPendingKeyEvents();
97 if (IsContextReady()) 95 if (IsContextReady())
98 DestroyContext(); 96 DestroyContext();
99 if (GetInputContextClient()) 97 if (GetInputContextClient())
100 GetInputContextClient()->SetInputContextHandler(NULL); 98 GetInputContextClient()->SetInputContextHandler(NULL);
101 } 99 }
102 100
103 void InputMethodIBus::set_ibus_client(
104 scoped_ptr<internal::IBusClient> new_client) {
105 ibus_client_.swap(new_client);
106 }
107
108 internal::IBusClient* InputMethodIBus::ibus_client() const {
109 return ibus_client_.get();
110 }
111
112 void InputMethodIBus::OnFocus() { 101 void InputMethodIBus::OnFocus() {
113 InputMethodBase::OnFocus(); 102 InputMethodBase::OnFocus();
114 UpdateContextFocusState(); 103 UpdateContextFocusState();
115 } 104 }
116 105
117 void InputMethodIBus::OnBlur() { 106 void InputMethodIBus::OnBlur() {
118 ConfirmCompositionText(); 107 ConfirmCompositionText();
119 InputMethodBase::OnBlur(); 108 InputMethodBase::OnBlur();
120 UpdateContextFocusState(); 109 UpdateContextFocusState();
121 } 110 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 IBusKeyEventFromNativeKeyEvent( 149 IBusKeyEventFromNativeKeyEvent(
161 native_event, &ibus_keyval, &ibus_keycode, &ibus_state); 150 native_event, &ibus_keyval, &ibus_keycode, &ibus_state);
162 151
163 // If |context_| is not usable, then we can only dispatch the key event as is. 152 // If |context_| is not usable, then we can only dispatch the key event as is.
164 // We also dispatch the key event directly if the current text input type is 153 // We also dispatch the key event directly if the current text input type is
165 // TEXT_INPUT_TYPE_PASSWORD, to bypass the input method. 154 // TEXT_INPUT_TYPE_PASSWORD, to bypass the input method.
166 // Note: We need to send the key event to ibus even if the |context_| is not 155 // Note: We need to send the key event to ibus even if the |context_| is not
167 // enabled, so that ibus can have a chance to enable the |context_|. 156 // enabled, so that ibus can have a chance to enable the |context_|.
168 if (!context_focused_ || 157 if (!context_focused_ ||
169 GetTextInputType() == TEXT_INPUT_TYPE_PASSWORD || 158 GetTextInputType() == TEXT_INPUT_TYPE_PASSWORD ||
170 ibus_client_->GetInputMethodType() == 159 !GetInputContextClient() ||
171 internal::IBusClient::INPUT_METHOD_XKB_LAYOUT) { 160 GetInputContextClient()->IsXKBLayout()) {
172 if (native_event->type == KeyPress) 161 if (native_event->type == KeyPress)
173 ProcessUnfilteredKeyPressEvent(native_event, ibus_keyval); 162 ProcessUnfilteredKeyPressEvent(native_event, ibus_keyval);
174 else 163 else
175 DispatchKeyEventPostIME(native_event); 164 DispatchKeyEventPostIME(native_event);
176 return; 165 return;
177 } 166 }
178 167
179 pending_key_events_.insert(current_keyevent_id_); 168 pending_key_events_.insert(current_keyevent_id_);
180 169
181 // Since |native_event| might be treated as XEvent whose size is bigger than 170 // Since |native_event| might be treated as XEvent whose size is bigger than
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // The current text input type should not be NONE if |context_| is focused. 209 // The current text input type should not be NONE if |context_| is focused.
221 DCHECK(!IsTextInputTypeNone()); 210 DCHECK(!IsTextInputTypeNone());
222 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds(); 211 const gfx::Rect rect = GetTextInputClient()->GetCaretBounds();
223 212
224 gfx::Rect composition_head; 213 gfx::Rect composition_head;
225 if (!GetTextInputClient()->GetCompositionCharacterBounds(0, 214 if (!GetTextInputClient()->GetCompositionCharacterBounds(0,
226 &composition_head)) { 215 &composition_head)) {
227 composition_head = rect; 216 composition_head = rect;
228 } 217 }
229 218
230 // This function runs asynchronously. 219 chromeos::ibus::Rect rect_ibus(rect.x(),
231 ibus_client_->SetCursorLocation(rect, composition_head); 220 rect.y(),
221 rect.width(),
222 rect.height());
satorux1 2013/01/29 05:16:08 maybe: chromeos::ibus::Rect rect_ibus = chromeos
Seigo Nonaka 2013/01/30 06:00:07 We can't introduce FromGfxRect function into chrom
223 chromeos::ibus::Rect composition_head_ibus(composition_head.x(),
224 composition_head.y(),
225 composition_head.width(),
226 composition_head.height());
227 GetInputContextClient()->SetCursorLocation(rect_ibus, composition_head_ibus);
232 228
233 ui::Range text_range; 229 ui::Range text_range;
234 ui::Range selection_range; 230 ui::Range selection_range;
235 string16 surrounding_text; 231 string16 surrounding_text;
236 if (!GetTextInputClient()->GetTextRange(&text_range) || 232 if (!GetTextInputClient()->GetTextRange(&text_range) ||
237 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) || 233 !GetTextInputClient()->GetTextFromRange(text_range, &surrounding_text) ||
238 !GetTextInputClient()->GetSelectionRange(&selection_range)) { 234 !GetTextInputClient()->GetSelectionRange(&selection_range)) {
239 previous_surrounding_text_.clear(); 235 previous_surrounding_text_.clear();
240 previous_selection_range_ = ui::Range::InvalidRange(); 236 previous_selection_range_ = ui::Range::InvalidRange();
241 return; 237 return;
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 } 910 }
915 911
916 // Use a black thin underline by default. 912 // Use a black thin underline by default.
917 if (out_composition->underlines.empty()) { 913 if (out_composition->underlines.empty()) {
918 out_composition->underlines.push_back(CompositionUnderline( 914 out_composition->underlines.push_back(CompositionUnderline(
919 0, length, SK_ColorBLACK, false /* thick */)); 915 0, length, SK_ColorBLACK, false /* thick */));
920 } 916 }
921 } 917 }
922 918
923 } // namespace ui 919 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698