OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef VIEWS_IME_MOCK_INPUT_METHOD_H_ |
| 6 #define VIEWS_IME_MOCK_INPUT_METHOD_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" |
| 11 #include "views/ime/input_method_base.h" |
| 12 #include "views/view.h" |
| 13 |
| 14 namespace views { |
| 15 |
| 16 // A mock InputMethod implementation for testing purpose. |
| 17 class MockInputMethod : public InputMethodBase { |
| 18 public: |
| 19 MockInputMethod(); |
| 20 virtual ~MockInputMethod(); |
| 21 |
| 22 // Overridden from InputMethod: |
| 23 virtual void Init(Widget* widget) OVERRIDE; |
| 24 virtual void DispatchKeyEvent(const KeyEvent& key) OVERRIDE; |
| 25 virtual void OnTextInputTypeChanged(View* view) OVERRIDE; |
| 26 virtual void OnCaretBoundsChanged(View* view) OVERRIDE; |
| 27 virtual void CancelComposition(View* view) OVERRIDE; |
| 28 virtual std::string GetInputLocale() OVERRIDE; |
| 29 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; |
| 30 virtual bool IsActive() OVERRIDE; |
| 31 |
| 32 bool focus_changed() const { return focus_changed_; } |
| 33 bool text_input_type_changed() const { return text_input_type_changed_; } |
| 34 bool caret_bounds_changed() const { return caret_bounds_changed_; } |
| 35 bool cancel_composition_called() const { return cancel_composition_called_; } |
| 36 |
| 37 // Clears all internal states and result. |
| 38 void Clear(); |
| 39 |
| 40 void SetCompositionTextForNextKey(const ui::CompositionText& composition); |
| 41 void SetResultTextForNextKey(const string16& result); |
| 42 |
| 43 void SetInputLocale(const std::string& locale); |
| 44 void SetInputTextDirection(base::i18n::TextDirection direction); |
| 45 void SetActive(bool active); |
| 46 |
| 47 private: |
| 48 // Overridden from InputMethodBase. |
| 49 virtual void FocusedViewWillChange() OVERRIDE; |
| 50 |
| 51 // Clears boolean states defined below. |
| 52 void ClearStates(); |
| 53 |
| 54 // Clears only composition information and result text. |
| 55 void ClearResult(); |
| 56 |
| 57 // Composition information for the next key event. It'll be cleared |
| 58 // automatically after dispatching the next key event. |
| 59 ui::CompositionText composition_; |
| 60 bool composition_changed_; |
| 61 |
| 62 // Result text for the next key event. It'll be cleared automatically after |
| 63 // dispatching the next key event. |
| 64 string16 result_text_; |
| 65 |
| 66 // Record call state of corresponding methods. They will be set to false |
| 67 // automatically before dispatching a key event. |
| 68 bool focus_changed_; |
| 69 bool text_input_type_changed_; |
| 70 bool caret_bounds_changed_; |
| 71 bool cancel_composition_called_; |
| 72 |
| 73 // To mock corresponding input method prooperties. |
| 74 std::string locale_; |
| 75 base::i18n::TextDirection direction_; |
| 76 bool active_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(MockInputMethod); |
| 79 }; |
| 80 |
| 81 } // namespace views |
| 82 |
| 83 #endif // VIEWS_IME_MOCK_INPUT_METHOD_H_ |
OLD | NEW |