| OLD | NEW |
| 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 <X11/Xlib.h> | 5 #include <X11/Xlib.h> |
| 6 #undef Bool | 6 #undef Bool |
| 7 #undef FocusIn | 7 #undef FocusIn |
| 8 #undef FocusOut | 8 #undef FocusOut |
| 9 #undef None | 9 #undef None |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
| 27 #include "ui/events/test/events_test_utils_x11.h" | 27 #include "ui/events/test/events_test_utils_x11.h" |
| 28 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
| 29 | 29 |
| 30 namespace ui { | 30 namespace ui { |
| 31 namespace { | 31 namespace { |
| 32 typedef chromeos::IBusEngineHandlerInterface::KeyEventDoneCallback | 32 typedef chromeos::IBusEngineHandlerInterface::KeyEventDoneCallback |
| 33 KeyEventCallback; | 33 KeyEventCallback; |
| 34 | 34 |
| 35 uint32 GetOffsetInUTF16(const std::string& utf8_string, uint32 utf8_offset) { | 35 uint32 GetOffsetInUTF16(const std::string& utf8_string, uint32 utf8_offset) { |
| 36 string16 utf16_string = UTF8ToUTF16(utf8_string); | 36 base::string16 utf16_string = UTF8ToUTF16(utf8_string); |
| 37 DCHECK_LT(utf8_offset, utf16_string.size()); | 37 DCHECK_LT(utf8_offset, utf16_string.size()); |
| 38 base::i18n::UTF16CharIterator char_iterator(&utf16_string); | 38 base::i18n::UTF16CharIterator char_iterator(&utf16_string); |
| 39 for (size_t i = 0; i < utf8_offset; ++i) | 39 for (size_t i = 0; i < utf8_offset; ++i) |
| 40 char_iterator.Advance(); | 40 char_iterator.Advance(); |
| 41 return char_iterator.array_pos(); | 41 return char_iterator.array_pos(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 bool IsEqualXKeyEvent(const XEvent& e1, const XEvent& e2) { | 44 bool IsEqualXKeyEvent(const XEvent& e1, const XEvent& e2) { |
| 45 if ((e1.type == KeyPress && e2.type == KeyPress) || | 45 if ((e1.type == KeyPress && e2.type == KeyPress) || |
| 46 (e1.type == KeyRelease && e2.type == KeyRelease)) { | 46 (e1.type == KeyRelease && e2.type == KeyRelease)) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 const CompositionText& composition) OVERRIDE { | 250 const CompositionText& composition) OVERRIDE { |
| 251 composition_text_ = composition; | 251 composition_text_ = composition; |
| 252 } | 252 } |
| 253 virtual void ConfirmCompositionText() OVERRIDE { | 253 virtual void ConfirmCompositionText() OVERRIDE { |
| 254 confirmed_text_ = composition_text_; | 254 confirmed_text_ = composition_text_; |
| 255 composition_text_.Clear(); | 255 composition_text_.Clear(); |
| 256 } | 256 } |
| 257 virtual void ClearCompositionText() OVERRIDE { | 257 virtual void ClearCompositionText() OVERRIDE { |
| 258 composition_text_.Clear(); | 258 composition_text_.Clear(); |
| 259 } | 259 } |
| 260 virtual void InsertText(const string16& text) OVERRIDE { | 260 virtual void InsertText(const base::string16& text) OVERRIDE { |
| 261 inserted_text_ = text; | 261 inserted_text_ = text; |
| 262 } | 262 } |
| 263 virtual void InsertChar(char16 ch, int flags) OVERRIDE { | 263 virtual void InsertChar(char16 ch, int flags) OVERRIDE { |
| 264 inserted_char_ = ch; | 264 inserted_char_ = ch; |
| 265 inserted_char_flags_ = flags; | 265 inserted_char_flags_ = flags; |
| 266 } | 266 } |
| 267 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE { | 267 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE { |
| 268 return static_cast<gfx::NativeWindow>(NULL); | 268 return static_cast<gfx::NativeWindow>(NULL); |
| 269 } | 269 } |
| 270 virtual TextInputType GetTextInputType() const OVERRIDE { | 270 virtual TextInputType GetTextInputType() const OVERRIDE { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 295 return false; | 295 return false; |
| 296 } | 296 } |
| 297 virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE { | 297 virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE { |
| 298 *range = selection_range_; | 298 *range = selection_range_; |
| 299 return true; | 299 return true; |
| 300 } | 300 } |
| 301 | 301 |
| 302 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE { return fals
e; } | 302 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE { return fals
e; } |
| 303 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE { return false; } | 303 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE { return false; } |
| 304 virtual bool GetTextFromRange(const gfx::Range& range, | 304 virtual bool GetTextFromRange(const gfx::Range& range, |
| 305 string16* text) const OVERRIDE { | 305 base::string16* text) const OVERRIDE { |
| 306 *text = surrounding_text_.substr(range.GetMin(), range.length()); | 306 *text = surrounding_text_.substr(range.GetMin(), range.length()); |
| 307 return true; | 307 return true; |
| 308 } | 308 } |
| 309 virtual void OnInputMethodChanged() OVERRIDE { | 309 virtual void OnInputMethodChanged() OVERRIDE { |
| 310 ++on_input_method_changed_call_count_; | 310 ++on_input_method_changed_call_count_; |
| 311 } | 311 } |
| 312 virtual bool ChangeTextDirectionAndLayoutAlignment( | 312 virtual bool ChangeTextDirectionAndLayoutAlignment( |
| 313 base::i18n::TextDirection direction) OVERRIDE { return false; } | 313 base::i18n::TextDirection direction) OVERRIDE { return false; } |
| 314 virtual void ExtendSelectionAndDelete(size_t before, | 314 virtual void ExtendSelectionAndDelete(size_t before, |
| 315 size_t after) OVERRIDE { } | 315 size_t after) OVERRIDE { } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // ui::internal::InputMethodDelegate functions. | 352 // ui::internal::InputMethodDelegate functions. |
| 353 base::NativeEvent dispatched_native_event_; | 353 base::NativeEvent dispatched_native_event_; |
| 354 ui::EventType dispatched_fabricated_event_type_; | 354 ui::EventType dispatched_fabricated_event_type_; |
| 355 ui::KeyboardCode dispatched_fabricated_event_key_code_; | 355 ui::KeyboardCode dispatched_fabricated_event_key_code_; |
| 356 int dispatched_fabricated_event_flags_; | 356 int dispatched_fabricated_event_flags_; |
| 357 | 357 |
| 358 // Variables for remembering the parameters that are passed to | 358 // Variables for remembering the parameters that are passed to |
| 359 // ui::TextInputClient functions. | 359 // ui::TextInputClient functions. |
| 360 CompositionText composition_text_; | 360 CompositionText composition_text_; |
| 361 CompositionText confirmed_text_; | 361 CompositionText confirmed_text_; |
| 362 string16 inserted_text_; | 362 base::string16 inserted_text_; |
| 363 char16 inserted_char_; | 363 char16 inserted_char_; |
| 364 unsigned int on_input_method_changed_call_count_; | 364 unsigned int on_input_method_changed_call_count_; |
| 365 int inserted_char_flags_; | 365 int inserted_char_flags_; |
| 366 | 366 |
| 367 // Variables that will be returned from the ui::TextInputClient functions. | 367 // Variables that will be returned from the ui::TextInputClient functions. |
| 368 TextInputType input_type_; | 368 TextInputType input_type_; |
| 369 TextInputMode input_mode_; | 369 TextInputMode input_mode_; |
| 370 bool can_compose_inline_; | 370 bool can_compose_inline_; |
| 371 gfx::Rect caret_bounds_; | 371 gfx::Rect caret_bounds_; |
| 372 gfx::Range text_range_; | 372 gfx::Range text_range_; |
| 373 gfx::Range selection_range_; | 373 gfx::Range selection_range_; |
| 374 string16 surrounding_text_; | 374 base::string16 surrounding_text_; |
| 375 | 375 |
| 376 scoped_ptr<chromeos::MockIMEEngineHandler> mock_ime_engine_handler_; | 376 scoped_ptr<chromeos::MockIMEEngineHandler> mock_ime_engine_handler_; |
| 377 scoped_ptr<chromeos::MockIMECandidateWindowHandler> | 377 scoped_ptr<chromeos::MockIMECandidateWindowHandler> |
| 378 mock_ime_candidate_window_handler_; | 378 mock_ime_candidate_window_handler_; |
| 379 | 379 |
| 380 DISALLOW_COPY_AND_ASSIGN(InputMethodIBusTest); | 380 DISALLOW_COPY_AND_ASSIGN(InputMethodIBusTest); |
| 381 }; | 381 }; |
| 382 | 382 |
| 383 // Tests public APIs in ui::InputMethod first. | 383 // Tests public APIs in ui::InputMethod first. |
| 384 | 384 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 // bounds are changed or not. | 592 // bounds are changed or not. |
| 593 EXPECT_EQ( | 593 EXPECT_EQ( |
| 594 4, | 594 4, |
| 595 mock_ime_candidate_window_handler_->set_cursor_bounds_call_count()); | 595 mock_ime_candidate_window_handler_->set_cursor_bounds_call_count()); |
| 596 } | 596 } |
| 597 | 597 |
| 598 TEST_F(InputMethodIBusTest, ExtractCompositionTextTest_NoAttribute) { | 598 TEST_F(InputMethodIBusTest, ExtractCompositionTextTest_NoAttribute) { |
| 599 const char kSampleText[] = "Sample Text"; | 599 const char kSampleText[] = "Sample Text"; |
| 600 const uint32 kCursorPos = 2UL; | 600 const uint32 kCursorPos = 2UL; |
| 601 | 601 |
| 602 const string16 utf16_string = UTF8ToUTF16(kSampleText); | 602 const base::string16 utf16_string = UTF8ToUTF16(kSampleText); |
| 603 chromeos::IBusText ibus_text; | 603 chromeos::IBusText ibus_text; |
| 604 ibus_text.set_text(kSampleText); | 604 ibus_text.set_text(kSampleText); |
| 605 | 605 |
| 606 CompositionText composition_text; | 606 CompositionText composition_text; |
| 607 ime_->ExtractCompositionText(ibus_text, kCursorPos, &composition_text); | 607 ime_->ExtractCompositionText(ibus_text, kCursorPos, &composition_text); |
| 608 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); | 608 EXPECT_EQ(UTF8ToUTF16(kSampleText), composition_text.text); |
| 609 // If there is no selection, |selection| represents cursor position. | 609 // If there is no selection, |selection| represents cursor position. |
| 610 EXPECT_EQ(kCursorPos, composition_text.selection.start()); | 610 EXPECT_EQ(kCursorPos, composition_text.selection.start()); |
| 611 EXPECT_EQ(kCursorPos, composition_text.selection.end()); | 611 EXPECT_EQ(kCursorPos, composition_text.selection.end()); |
| 612 // If there is no underline, |underlines| contains one underline and it is | 612 // If there is no underline, |underlines| contains one underline and it is |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 ime_->ResetContext(); | 1018 ime_->ResetContext(); |
| 1019 | 1019 |
| 1020 // Do callback. | 1020 // Do callback. |
| 1021 mock_ime_engine_handler_->last_passed_callback().Run(true); | 1021 mock_ime_engine_handler_->last_passed_callback().Run(true); |
| 1022 | 1022 |
| 1023 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); | 1023 EXPECT_EQ(0, ime_->process_key_event_post_ime_call_count()); |
| 1024 } | 1024 } |
| 1025 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). | 1025 // TODO(nona): Introduce ProcessKeyEventPostIME tests(crbug.com/156593). |
| 1026 | 1026 |
| 1027 } // namespace ui | 1027 } // namespace ui |
| OLD | NEW |