1 // Copyright (c) 2013 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 UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ 6 #define UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ 7 8 #include "base/basictypes.h" 9 #include "base/event_types.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "base/observer_list.h" 12 #include "ui/aura/window_observer.h" 13 #include "ui/base/ime/input_method_observer.h" 14 #include "ui/keyboard/keyboard_export.h" 15 #include "url/gurl.h" 16 17 namespace aura { 18 class Window; 19 } 20 namespace gfx { 21 class Rect; 22 } 23 namespace ui { 24 class InputMethod; 25 class TextInputClient; 26 } 27 28 namespace keyboard { 29 30 class KeyboardControllerObserver; 31 class KeyboardControllerProxy; 32 class KeyboardLayoutManager; 33 34 // Provides control of the virtual keyboard, including providing a container 35 // and controlling visibility. 36 class KEYBOARD_EXPORT KeyboardController : public ui::InputMethodObserver, 37 public aura::WindowObserver { 38 public: 39 // Different ways to hide the keyboard. 40 enum HideReason { 41 // System initiated. 42 HIDE_REASON_AUTOMATIC, 43 // User initiated. 44 HIDE_REASON_MANUAL, 45 }; 46 47 // Takes ownership of |proxy|. 48 explicit KeyboardController(KeyboardControllerProxy* proxy); 49 virtual ~KeyboardController(); 50 51 // Returns the container for the keyboard, which is owned by 52 // KeyboardController. 53 aura::Window* GetContainerWindow(); 54 55 // Sets the override content url. This is used by for input view for extension 56 // IMEs. 57 void SetOverrideContentUrl(const GURL& url); 58 59 // Hides virtual keyboard and notifies observer bounds change. 60 // This function should be called with a delay to avoid layout flicker 61 // when the focus of input field quickly change. |automatic| is true when the 62 // call is made by the system rather than initiated by the user. 63 void HideKeyboard(HideReason reason); 64 65 // Notifies the keyboard observer for keyboard bounds changed. 66 void NotifyKeyboardBoundsChanging(const gfx::Rect& new_bounds); 67 68 // Management of the observer list. 69 virtual void AddObserver(KeyboardControllerObserver* observer); 70 virtual void RemoveObserver(KeyboardControllerObserver* observer); 71 72 KeyboardControllerProxy* proxy() { return proxy_.get(); } 73 74 void set_lock_keyboard(bool lock) { lock_keyboard_ = lock; } 75 76 private: 77 // For access to Observer methods for simulation. 78 friend class KeyboardControllerTest; 79 80 // aura::WindowObserver overrides 81 virtual void OnWindowHierarchyChanged( 82 const HierarchyChangeParams& params) OVERRIDE; 83 84 // InputMethodObserver overrides 85 virtual void OnTextInputTypeChanged( 86 const ui::TextInputClient* client) OVERRIDE {} 87 virtual void OnFocus() OVERRIDE {} 88 virtual void OnBlur() OVERRIDE {} 89 virtual void OnCaretBoundsChanged( 90 const ui::TextInputClient* client) OVERRIDE {} 91 virtual void OnTextInputStateChanged( 92 const ui::TextInputClient* client) OVERRIDE; 93 virtual void OnInputMethodDestroyed( 94 const ui::InputMethod* input_method) OVERRIDE; 95 96 // Returns true if keyboard is scheduled to hide. 97 bool WillHideKeyboard() const; 98 99 scoped_ptr<KeyboardControllerProxy> proxy_; 100 scoped_ptr<aura::Window> container_; 101 ui::InputMethod* input_method_; 102 bool keyboard_visible_; 103 bool lock_keyboard_; 104 105 ObserverList<KeyboardControllerObserver> observer_list_; 106 107 base::WeakPtrFactory<KeyboardController> weak_factory_; 108 109 DISALLOW_COPY_AND_ASSIGN(KeyboardController); 110 }; 111 112 } // namespace keyboard 113 114 #endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_H_ 115