| 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_INPUT_METHOD_H_ | |
| 6 #define VIEWS_IME_INPUT_METHOD_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/i18n/rtl.h" | |
| 13 #include "ui/base/ime/text_input_type.h" | |
| 14 #include "views/views_export.h" | |
| 15 | |
| 16 namespace ui { | |
| 17 class TextInputClient; | |
| 18 } // namespace ui | |
| 19 | |
| 20 namespace views { | |
| 21 | |
| 22 namespace internal { | |
| 23 class InputMethodDelegate; | |
| 24 } // namespace internal | |
| 25 | |
| 26 class KeyEvent; | |
| 27 class View; | |
| 28 class Widget; | |
| 29 | |
| 30 // An interface implemented by an object that encapsulates a native input method | |
| 31 // service provided by the underlying operation system. | |
| 32 // Because on most systems, the system input method service is bound to | |
| 33 // individual native window. On Windows, its HWND, on Linux/Gtk, its GdkWindow. | |
| 34 // And in Views control system, only the top-level NativeWidget has a native | |
| 35 // window that can get keyboard focus. So this API is designed to be bound to | |
| 36 // the top-level NativeWidget. | |
| 37 class VIEWS_EXPORT InputMethod { | |
| 38 public: | |
| 39 virtual ~InputMethod() {} | |
| 40 | |
| 41 // Sets the delegate used by this InputMethod instance. It should only be | |
| 42 // called by the internal NativeWidget or testing code. | |
| 43 virtual void set_delegate(internal::InputMethodDelegate* delegate) = 0; | |
| 44 | |
| 45 // Initialize the InputMethod object and attach it to the given |widget|. | |
| 46 // The |widget| must already be initialized. | |
| 47 virtual void Init(Widget* widget) = 0; | |
| 48 | |
| 49 // Called when the top-level NativeWidget gets keyboard focus. It should only | |
| 50 // be called by the top-level NativeWidget which owns this InputMethod | |
| 51 // instance. | |
| 52 virtual void OnFocus() = 0; | |
| 53 | |
| 54 // Called when the top-level NativeWidget loses keyboard focus. It should only | |
| 55 // be called by the top-level NativeWidget which owns this InputMethod | |
| 56 // instance. | |
| 57 virtual void OnBlur() = 0; | |
| 58 | |
| 59 // Dispatch a key event to the input method. The key event will be dispatched | |
| 60 // back to the caller via InputMethodDelegate::DispatchKeyEventPostIME(), once | |
| 61 // it's processed by the input method. It should only be called by the | |
| 62 // top-level NativeWidget which owns this InputMethod instance, or other | |
| 63 // related platform dependent code, such as a message dispatcher. | |
| 64 virtual void DispatchKeyEvent(const KeyEvent& key) = 0; | |
| 65 | |
| 66 // Called by the focused |view| whenever its text input type is changed. | |
| 67 // Before calling this method, the focused |view| must confirm or clear | |
| 68 // existing composition text and call InputMethod::CancelComposition() when | |
| 69 // necessary. Otherwise unexpected behavior may happen. This method has no | |
| 70 // effect if the |view| is not focused. | |
| 71 virtual void OnTextInputTypeChanged(View* view) = 0; | |
| 72 | |
| 73 // Called by the focused |view| whenever its caret bounds is changed. | |
| 74 // This method has no effect if the |view| is not focused. | |
| 75 virtual void OnCaretBoundsChanged(View* view) = 0; | |
| 76 | |
| 77 // Called by the focused |view| to ask the input method cancel the ongoing | |
| 78 // composition session. This method has no effect if the |view| is not | |
| 79 // focused. | |
| 80 virtual void CancelComposition(View* view) = 0; | |
| 81 | |
| 82 // Returns the locale of current keyboard layout or input method, as a BCP-47 | |
| 83 // tag, or an empty string if the input method cannot provide it. | |
| 84 virtual std::string GetInputLocale() = 0; | |
| 85 | |
| 86 // Returns the text direction of current keyboard layout or input method, or | |
| 87 // base::i18n::UNKNOWN_DIRECTION if the input method cannot provide it. | |
| 88 virtual base::i18n::TextDirection GetInputTextDirection() = 0; | |
| 89 | |
| 90 // Checks if the input method is active, i.e. if it's ready for processing | |
| 91 // keyboard event and generate composition or text result. | |
| 92 // If the input method is inactive, then it's not necessary to inform it the | |
| 93 // changes of caret bounds and text input type. | |
| 94 // Note: character results may still be generated and sent to the text input | |
| 95 // client by calling TextInputClient::InsertChar(), even if the input method | |
| 96 // is not active. | |
| 97 virtual bool IsActive() = 0; | |
| 98 | |
| 99 // Gets the focused text input client. Returns NULL if the Widget is not | |
| 100 // focused, or there is no focused View or the focused View doesn't support | |
| 101 // text input. | |
| 102 virtual ui::TextInputClient* GetTextInputClient() const = 0; | |
| 103 | |
| 104 // Gets the text input type of the focused text input client. Returns | |
| 105 // ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client. | |
| 106 virtual ui::TextInputType GetTextInputType() const = 0; | |
| 107 | |
| 108 // Returns true if the input method is a mock and not real. | |
| 109 virtual bool IsMock() const = 0; | |
| 110 | |
| 111 // TODO(suzhe): Support mouse/touch event. | |
| 112 }; | |
| 113 | |
| 114 } // namespace views | |
| 115 | |
| 116 #endif // VIEWS_IME_INPUT_METHOD_H_ | |
| OLD | NEW |