| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromeos.h" | 5 #include "ui/base/ime/input_method_chromeos.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #undef Bool | 8 #undef Bool |
| 9 #undef FocusIn | 9 #undef FocusIn |
| 10 #undef FocusOut | 10 #undef FocusOut |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 | 74 |
| 75 struct ProcessKeyEventPostIMEArgs { | 75 struct ProcessKeyEventPostIMEArgs { |
| 76 ProcessKeyEventPostIMEArgs() : event(NULL), handled(false) {} | 76 ProcessKeyEventPostIMEArgs() : event(NULL), handled(false) {} |
| 77 const ui::KeyEvent* event; | 77 const ui::KeyEvent* event; |
| 78 bool handled; | 78 bool handled; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // Overridden from InputMethodChromeOS: | 81 // Overridden from InputMethodChromeOS: |
| 82 virtual void ProcessKeyEventPostIME(const ui::KeyEvent& key_event, | 82 virtual void ProcessKeyEventPostIME(const ui::KeyEvent& key_event, |
| 83 bool handled) OVERRIDE { | 83 bool handled) override { |
| 84 process_key_event_post_ime_args_.event = &key_event; | 84 process_key_event_post_ime_args_.event = &key_event; |
| 85 process_key_event_post_ime_args_.handled = handled; | 85 process_key_event_post_ime_args_.handled = handled; |
| 86 ++process_key_event_post_ime_call_count_; | 86 ++process_key_event_post_ime_call_count_; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void ResetCallCount() { | 89 void ResetCallCount() { |
| 90 process_key_event_post_ime_call_count_ = 0; | 90 process_key_event_post_ime_call_count_ = 0; |
| 91 } | 91 } |
| 92 | 92 |
| 93 const ProcessKeyEventPostIMEArgs& process_key_event_post_ime_args() const { | 93 const ProcessKeyEventPostIMEArgs& process_key_event_post_ime_args() const { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 public TextInputClient { | 203 public TextInputClient { |
| 204 public: | 204 public: |
| 205 InputMethodChromeOSTest() | 205 InputMethodChromeOSTest() |
| 206 : dispatched_key_event_(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, ui::EF_NONE) { | 206 : dispatched_key_event_(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, ui::EF_NONE) { |
| 207 ResetFlags(); | 207 ResetFlags(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 virtual ~InputMethodChromeOSTest() { | 210 virtual ~InputMethodChromeOSTest() { |
| 211 } | 211 } |
| 212 | 212 |
| 213 virtual void SetUp() OVERRIDE { | 213 virtual void SetUp() override { |
| 214 chromeos::IMEBridge::Initialize(); | 214 chromeos::IMEBridge::Initialize(); |
| 215 | 215 |
| 216 mock_ime_engine_handler_.reset( | 216 mock_ime_engine_handler_.reset( |
| 217 new chromeos::MockIMEEngineHandler()); | 217 new chromeos::MockIMEEngineHandler()); |
| 218 chromeos::IMEBridge::Get()->SetCurrentEngineHandler( | 218 chromeos::IMEBridge::Get()->SetCurrentEngineHandler( |
| 219 mock_ime_engine_handler_.get()); | 219 mock_ime_engine_handler_.get()); |
| 220 | 220 |
| 221 mock_ime_candidate_window_handler_.reset( | 221 mock_ime_candidate_window_handler_.reset( |
| 222 new chromeos::MockIMECandidateWindowHandler()); | 222 new chromeos::MockIMECandidateWindowHandler()); |
| 223 chromeos::IMEBridge::Get()->SetCandidateWindowHandler( | 223 chromeos::IMEBridge::Get()->SetCandidateWindowHandler( |
| 224 mock_ime_candidate_window_handler_.get()); | 224 mock_ime_candidate_window_handler_.get()); |
| 225 | 225 |
| 226 ime_.reset(new TestableInputMethodChromeOS(this)); | 226 ime_.reset(new TestableInputMethodChromeOS(this)); |
| 227 if (switches::IsTextInputFocusManagerEnabled()) | 227 if (switches::IsTextInputFocusManagerEnabled()) |
| 228 TextInputFocusManager::GetInstance()->FocusTextInputClient(this); | 228 TextInputFocusManager::GetInstance()->FocusTextInputClient(this); |
| 229 else | 229 else |
| 230 ime_->SetFocusedTextInputClient(this); | 230 ime_->SetFocusedTextInputClient(this); |
| 231 } | 231 } |
| 232 | 232 |
| 233 virtual void TearDown() OVERRIDE { | 233 virtual void TearDown() override { |
| 234 if (ime_.get()) { | 234 if (ime_.get()) { |
| 235 if (switches::IsTextInputFocusManagerEnabled()) | 235 if (switches::IsTextInputFocusManagerEnabled()) |
| 236 TextInputFocusManager::GetInstance()->BlurTextInputClient(this); | 236 TextInputFocusManager::GetInstance()->BlurTextInputClient(this); |
| 237 else | 237 else |
| 238 ime_->SetFocusedTextInputClient(NULL); | 238 ime_->SetFocusedTextInputClient(NULL); |
| 239 } | 239 } |
| 240 ime_.reset(); | 240 ime_.reset(); |
| 241 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL); | 241 chromeos::IMEBridge::Get()->SetCurrentEngineHandler(NULL); |
| 242 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL); | 242 chromeos::IMEBridge::Get()->SetCandidateWindowHandler(NULL); |
| 243 mock_ime_engine_handler_.reset(); | 243 mock_ime_engine_handler_.reset(); |
| 244 mock_ime_candidate_window_handler_.reset(); | 244 mock_ime_candidate_window_handler_.reset(); |
| 245 chromeos::IMEBridge::Shutdown(); | 245 chromeos::IMEBridge::Shutdown(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 // Overridden from ui::internal::InputMethodDelegate: | 248 // Overridden from ui::internal::InputMethodDelegate: |
| 249 virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) OVERRIDE { | 249 virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { |
| 250 dispatched_key_event_ = event; | 250 dispatched_key_event_ = event; |
| 251 return false; | 251 return false; |
| 252 } | 252 } |
| 253 | 253 |
| 254 // Overridden from ui::TextInputClient: | 254 // Overridden from ui::TextInputClient: |
| 255 virtual void SetCompositionText( | 255 virtual void SetCompositionText( |
| 256 const CompositionText& composition) OVERRIDE { | 256 const CompositionText& composition) override { |
| 257 composition_text_ = composition; | 257 composition_text_ = composition; |
| 258 } | 258 } |
| 259 virtual void ConfirmCompositionText() OVERRIDE { | 259 virtual void ConfirmCompositionText() override { |
| 260 confirmed_text_ = composition_text_; | 260 confirmed_text_ = composition_text_; |
| 261 composition_text_.Clear(); | 261 composition_text_.Clear(); |
| 262 } | 262 } |
| 263 virtual void ClearCompositionText() OVERRIDE { | 263 virtual void ClearCompositionText() override { |
| 264 composition_text_.Clear(); | 264 composition_text_.Clear(); |
| 265 } | 265 } |
| 266 virtual void InsertText(const base::string16& text) OVERRIDE { | 266 virtual void InsertText(const base::string16& text) override { |
| 267 inserted_text_ = text; | 267 inserted_text_ = text; |
| 268 } | 268 } |
| 269 virtual void InsertChar(base::char16 ch, int flags) OVERRIDE { | 269 virtual void InsertChar(base::char16 ch, int flags) override { |
| 270 inserted_char_ = ch; | 270 inserted_char_ = ch; |
| 271 inserted_char_flags_ = flags; | 271 inserted_char_flags_ = flags; |
| 272 } | 272 } |
| 273 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE { | 273 virtual gfx::NativeWindow GetAttachedWindow() const override { |
| 274 return static_cast<gfx::NativeWindow>(NULL); | 274 return static_cast<gfx::NativeWindow>(NULL); |
| 275 } | 275 } |
| 276 virtual TextInputType GetTextInputType() const OVERRIDE { | 276 virtual TextInputType GetTextInputType() const override { |
| 277 return input_type_; | 277 return input_type_; |
| 278 } | 278 } |
| 279 virtual TextInputMode GetTextInputMode() const OVERRIDE { | 279 virtual TextInputMode GetTextInputMode() const override { |
| 280 return input_mode_; | 280 return input_mode_; |
| 281 } | 281 } |
| 282 virtual bool CanComposeInline() const OVERRIDE { | 282 virtual bool CanComposeInline() const override { |
| 283 return can_compose_inline_; | 283 return can_compose_inline_; |
| 284 } | 284 } |
| 285 virtual gfx::Rect GetCaretBounds() const OVERRIDE { | 285 virtual gfx::Rect GetCaretBounds() const override { |
| 286 return caret_bounds_; | 286 return caret_bounds_; |
| 287 } | 287 } |
| 288 virtual bool GetCompositionCharacterBounds(uint32 index, | 288 virtual bool GetCompositionCharacterBounds(uint32 index, |
| 289 gfx::Rect* rect) const OVERRIDE { | 289 gfx::Rect* rect) const override { |
| 290 return false; | 290 return false; |
| 291 } | 291 } |
| 292 virtual bool HasCompositionText() const OVERRIDE { | 292 virtual bool HasCompositionText() const override { |
| 293 CompositionText empty; | 293 CompositionText empty; |
| 294 return composition_text_ != empty; | 294 return composition_text_ != empty; |
| 295 } | 295 } |
| 296 virtual bool GetTextRange(gfx::Range* range) const OVERRIDE { | 296 virtual bool GetTextRange(gfx::Range* range) const override { |
| 297 *range = text_range_; | 297 *range = text_range_; |
| 298 return true; | 298 return true; |
| 299 } | 299 } |
| 300 virtual bool GetCompositionTextRange(gfx::Range* range) const OVERRIDE { | 300 virtual bool GetCompositionTextRange(gfx::Range* range) const override { |
| 301 return false; | 301 return false; |
| 302 } | 302 } |
| 303 virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE { | 303 virtual bool GetSelectionRange(gfx::Range* range) const override { |
| 304 *range = selection_range_; | 304 *range = selection_range_; |
| 305 return true; | 305 return true; |
| 306 } | 306 } |
| 307 | 307 |
| 308 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE { | 308 virtual bool SetSelectionRange(const gfx::Range& range) override { |
| 309 return false; | 309 return false; |
| 310 } | 310 } |
| 311 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE { return false; } | 311 virtual bool DeleteRange(const gfx::Range& range) override { return false; } |
| 312 virtual bool GetTextFromRange(const gfx::Range& range, | 312 virtual bool GetTextFromRange(const gfx::Range& range, |
| 313 base::string16* text) const OVERRIDE { | 313 base::string16* text) const override { |
| 314 *text = surrounding_text_.substr(range.GetMin(), range.length()); | 314 *text = surrounding_text_.substr(range.GetMin(), range.length()); |
| 315 return true; | 315 return true; |
| 316 } | 316 } |
| 317 virtual void OnInputMethodChanged() OVERRIDE { | 317 virtual void OnInputMethodChanged() override { |
| 318 ++on_input_method_changed_call_count_; | 318 ++on_input_method_changed_call_count_; |
| 319 } | 319 } |
| 320 virtual bool ChangeTextDirectionAndLayoutAlignment( | 320 virtual bool ChangeTextDirectionAndLayoutAlignment( |
| 321 base::i18n::TextDirection direction) OVERRIDE { return false; } | 321 base::i18n::TextDirection direction) override { return false; } |
| 322 virtual void ExtendSelectionAndDelete(size_t before, | 322 virtual void ExtendSelectionAndDelete(size_t before, |
| 323 size_t after) OVERRIDE {} | 323 size_t after) override {} |
| 324 virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE {} | 324 virtual void EnsureCaretInRect(const gfx::Rect& rect) override {} |
| 325 virtual void OnCandidateWindowShown() OVERRIDE {} | 325 virtual void OnCandidateWindowShown() override {} |
| 326 virtual void OnCandidateWindowUpdated() OVERRIDE {} | 326 virtual void OnCandidateWindowUpdated() override {} |
| 327 virtual void OnCandidateWindowHidden() OVERRIDE {} | 327 virtual void OnCandidateWindowHidden() override {} |
| 328 virtual bool IsEditingCommandEnabled(int command_id) OVERRIDE { | 328 virtual bool IsEditingCommandEnabled(int command_id) override { |
| 329 return false; | 329 return false; |
| 330 } | 330 } |
| 331 virtual void ExecuteEditingCommand(int command_id) OVERRIDE {} | 331 virtual void ExecuteEditingCommand(int command_id) override {} |
| 332 | 332 |
| 333 bool HasNativeEvent() const { | 333 bool HasNativeEvent() const { |
| 334 return dispatched_key_event_.HasNativeEvent(); | 334 return dispatched_key_event_.HasNativeEvent(); |
| 335 } | 335 } |
| 336 | 336 |
| 337 void ResetFlags() { | 337 void ResetFlags() { |
| 338 dispatched_key_event_ = ui::KeyEvent(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, | 338 dispatched_key_event_ = ui::KeyEvent(ui::ET_UNKNOWN, ui::VKEY_UNKNOWN, |
| 339 ui::EF_NONE); | 339 ui::EF_NONE); |
| 340 | 340 |
| 341 composition_text_.Clear(); | 341 composition_text_.Clear(); |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 ime_->OnCaretBoundsChanged(this); | 938 ime_->OnCaretBoundsChanged(this); |
| 939 EXPECT_EQ(0, | 939 EXPECT_EQ(0, |
| 940 mock_ime_engine_handler_->set_surrounding_text_call_count()); | 940 mock_ime_engine_handler_->set_surrounding_text_call_count()); |
| 941 } | 941 } |
| 942 | 942 |
| 943 class InputMethodChromeOSKeyEventTest : public InputMethodChromeOSTest { | 943 class InputMethodChromeOSKeyEventTest : public InputMethodChromeOSTest { |
| 944 public: | 944 public: |
| 945 InputMethodChromeOSKeyEventTest() {} | 945 InputMethodChromeOSKeyEventTest() {} |
| 946 virtual ~InputMethodChromeOSKeyEventTest() {} | 946 virtual ~InputMethodChromeOSKeyEventTest() {} |
| 947 | 947 |
| 948 virtual void SetUp() OVERRIDE { | 948 virtual void SetUp() override { |
| 949 InputMethodChromeOSTest::SetUp(); | 949 InputMethodChromeOSTest::SetUp(); |
| 950 ime_->Init(true); | 950 ime_->Init(true); |
| 951 } | 951 } |
| 952 | 952 |
| 953 DISALLOW_COPY_AND_ASSIGN(InputMethodChromeOSKeyEventTest); | 953 DISALLOW_COPY_AND_ASSIGN(InputMethodChromeOSKeyEventTest); |
| 954 }; | 954 }; |
| 955 | 955 |
| 956 TEST_F(InputMethodChromeOSKeyEventTest, KeyEventDelayResponseTest) { | 956 TEST_F(InputMethodChromeOSKeyEventTest, KeyEventDelayResponseTest) { |
| 957 const int kFlags = ui::EF_SHIFT_DOWN; | 957 const int kFlags = ui::EF_SHIFT_DOWN; |
| 958 ScopedXI2Event xevent; | 958 ScopedXI2Event xevent; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 ime_->ResetContext(); | 1062 ime_->ResetContext(); |
| 1063 | 1063 |
| 1064 // Do callback. | 1064 // Do callback. |
| 1065 mock_ime_engine_handler_->last_passed_callback().Run(true); | 1065 mock_ime_engine_handler_->last_passed_callback().Run(true); |
| 1066 | 1066 |
| 1067 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); | 1067 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); |
| 1068 } | 1068 } |
| 1069 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). | 1069 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). |
| 1070 | 1070 |
| 1071 } // namespace ui | 1071 } // namespace ui |
| OLD | NEW |