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_BASE_H_ |
| 6 #define VIEWS_IME_INPUT_METHOD_BASE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" |
| 11 #include "views/focus/focus_manager.h" |
| 12 #include "views/ime/input_method.h" |
| 13 #include "views/ime/input_method_delegate.h" |
| 14 #include "views/ime/text_input_client.h" |
| 15 |
| 16 namespace views { |
| 17 |
| 18 class View; |
| 19 |
| 20 // A helper class providing functionalities shared among InputMethod |
| 21 // implementations. |
| 22 class InputMethodBase : public InputMethod, |
| 23 public FocusChangeListener { |
| 24 public: |
| 25 InputMethodBase(); |
| 26 virtual ~InputMethodBase(); |
| 27 |
| 28 // Overriden from InputMethod. |
| 29 virtual void set_delegate(internal::InputMethodDelegate* delegate) OVERRIDE; |
| 30 |
| 31 // If a derived class overrides this method, it should call parent's |
| 32 // implementation first. |
| 33 virtual void Init(Widget* widget) OVERRIDE; |
| 34 |
| 35 // Overridden from FocusChangeListener. Derived classes shouldn't override |
| 36 // this method. Override FocusedViewWillChange() and FocusedViewDidChange() |
| 37 // instead. |
| 38 virtual void FocusWillChange(View* focused_before, View* focused) OVERRIDE; |
| 39 |
| 40 protected: |
| 41 // Getters and setters of properties. |
| 42 internal::InputMethodDelegate* delegate() const { return delegate_; } |
| 43 Widget* widget() const { return widget_; } |
| 44 View* focused_view() const { return focused_view_; } |
| 45 |
| 46 // Derived classes should call this method to update Widget's focus state when |
| 47 // the Widget gets or loses keyboard focus. |
| 48 void set_widget_focused(bool focused) { widget_focused_ = focused; } |
| 49 bool widget_focused() const { return widget_focused_; } |
| 50 |
| 51 // Checks if the given View is focused. Returns true only if the View and |
| 52 // the Widget are both focused. |
| 53 bool IsViewFocused(View* view) const; |
| 54 |
| 55 // Gets the focused text input client. Returns NULL if the Widget is not |
| 56 // focused, or there is no focused View or the focused View doesn't support |
| 57 // text input. |
| 58 TextInputClient* GetTextInputClient() const; |
| 59 |
| 60 // Gets the text input type of the focused text input client. Returns |
| 61 // ui::TEXT_INPUT_TYPE_NONE if there is no focused text input client. |
| 62 ui::TextInputType GetTextInputType() const; |
| 63 |
| 64 // Checks if the focused text input client's text input type is |
| 65 // ui::TEXT_INPUT_TYPE_NONE. Also returns true if there is no focused text |
| 66 // input client. |
| 67 bool IsTextInputTypeNone() const; |
| 68 |
| 69 // Convenience method to call the focused text input client's |
| 70 // OnInputMethodChanged() method. It'll only take effect if the current text |
| 71 // input type is not ui::TEXT_INPUT_TYPE_NONE. |
| 72 void OnInputMethodChanged() const; |
| 73 |
| 74 // Convenience method to call delegate_->DispatchKeyEventPostIME(). |
| 75 void DispatchKeyEventPostIME(const KeyEvent& key) const; |
| 76 |
| 77 // Gets the current text input client's caret bounds in Widget's coordinates. |
| 78 // Returns false if the current text input client doesn't support text input. |
| 79 bool GetCaretBoundsInWidget(gfx::Rect* rect) const; |
| 80 |
| 81 // Called just before changing the focused view. Should be overridden by |
| 82 // derived classes. The default implementation does nothing. |
| 83 virtual void FocusedViewWillChange(); |
| 84 |
| 85 // Called just after changing the focused view. Should be overridden by |
| 86 // derived classes. The default implementation does nothing. |
| 87 // Note: It's called just after changing the value of |focused_view_|. As it's |
| 88 // called inside FocusChangeListener's FocusWillChange() method, which is |
| 89 // called by the FocusManager before actually changing the focus, the derived |
| 90 // class should not rely on the actual focus state of the |focused_view_|. |
| 91 virtual void FocusedViewDidChange(); |
| 92 |
| 93 private: |
| 94 internal::InputMethodDelegate* delegate_; |
| 95 Widget* widget_; |
| 96 View* focused_view_; |
| 97 |
| 98 // Indicates if the top-level widget is focused or not. |
| 99 bool widget_focused_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(InputMethodBase); |
| 102 }; |
| 103 |
| 104 } // namespace views |
| 105 |
| 106 #endif // VIEWS_IME_INPUT_METHOD_BASE_H_ |
OLD | NEW |