| OLD | NEW |
| (Empty) |
| 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_PROXY_H_ | |
| 6 #define UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_ | |
| 7 | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "content/public/common/media_stream_request.h" | |
| 10 #include "ui/aura/window_observer.h" | |
| 11 #include "ui/base/ime/text_input_type.h" | |
| 12 #include "ui/keyboard/keyboard_export.h" | |
| 13 | |
| 14 namespace aura { | |
| 15 class Window; | |
| 16 } | |
| 17 namespace content { | |
| 18 class BrowserContext; | |
| 19 class SiteInstance; | |
| 20 class WebContents; | |
| 21 } | |
| 22 namespace gfx { | |
| 23 class Rect; | |
| 24 } | |
| 25 namespace ui { | |
| 26 class InputMethod; | |
| 27 } | |
| 28 namespace wm { | |
| 29 class Shadow; | |
| 30 } | |
| 31 | |
| 32 namespace keyboard { | |
| 33 | |
| 34 class KeyboardController; | |
| 35 | |
| 36 // A proxy used by the KeyboardController to get access to the virtual | |
| 37 // keyboard window. | |
| 38 class KEYBOARD_EXPORT KeyboardControllerProxy : public aura::WindowObserver { | |
| 39 public: | |
| 40 class TestApi { | |
| 41 public: | |
| 42 explicit TestApi(KeyboardControllerProxy* proxy) : proxy_(proxy) {} | |
| 43 | |
| 44 const content::WebContents* keyboard_contents() { | |
| 45 return proxy_->keyboard_contents_.get(); | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 KeyboardControllerProxy* proxy_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
| 52 }; | |
| 53 | |
| 54 explicit KeyboardControllerProxy(content::BrowserContext* context); | |
| 55 ~KeyboardControllerProxy() override; | |
| 56 | |
| 57 // Gets the virtual keyboard window. Ownership of the returned Window remains | |
| 58 // with the proxy. | |
| 59 virtual aura::Window* GetKeyboardWindow(); | |
| 60 | |
| 61 // Whether the keyboard window is created. The keyboard window is tied to a | |
| 62 // WebContent so we can just check if the WebContent is created or not. | |
| 63 virtual bool HasKeyboardWindow() const; | |
| 64 | |
| 65 // Gets the InputMethod that will provide notifications about changes in the | |
| 66 // text input context. | |
| 67 virtual ui::InputMethod* GetInputMethod() = 0; | |
| 68 | |
| 69 // Requests the audio input from microphone for speech input. | |
| 70 virtual void RequestAudioInput(content::WebContents* web_contents, | |
| 71 const content::MediaStreamRequest& request, | |
| 72 const content::MediaResponseCallback& callback) = 0; | |
| 73 | |
| 74 // Shows the container window of the keyboard. The default implementation | |
| 75 // simply shows the container. An overridden implementation can set up | |
| 76 // necessary animation, or delay the visibility change as it desires. | |
| 77 virtual void ShowKeyboardContainer(aura::Window* container); | |
| 78 | |
| 79 // Hides the container window of the keyboard. The default implementation | |
| 80 // simply hides the container. An overridden implementation can set up | |
| 81 // necesasry animation, or delay the visibility change as it desires. | |
| 82 virtual void HideKeyboardContainer(aura::Window* container); | |
| 83 | |
| 84 // Updates the type of the focused text input box. | |
| 85 virtual void SetUpdateInputType(ui::TextInputType type); | |
| 86 | |
| 87 // Ensures caret in current work area (not occluded by virtual keyboard | |
| 88 // window). | |
| 89 virtual void EnsureCaretInWorkArea(); | |
| 90 | |
| 91 // Loads system virtual keyboard. Noop if the current virtual keyboard is | |
| 92 // system virtual keyboard. | |
| 93 virtual void LoadSystemKeyboard(); | |
| 94 | |
| 95 // Reloads virtual keyboard URL if the current keyboard's web content URL is | |
| 96 // different. The URL can be different if user switch from password field to | |
| 97 // any other type input field. | |
| 98 // At password field, the system virtual keyboard is forced to load even if | |
| 99 // the current IME provides a customized virtual keyboard. This is needed to | |
| 100 // prevent IME virtual keyboard logging user's password. Once user switch to | |
| 101 // other input fields, the virtual keyboard should switch back to the IME | |
| 102 // provided keyboard, or keep using the system virtual keyboard if IME doesn't | |
| 103 // provide one. | |
| 104 virtual void ReloadKeyboardIfNeeded(); | |
| 105 | |
| 106 // KeyboardController owns KeyboardControllerProxy so KeyboardControllerProxy | |
| 107 // or its subclasses should not take ownership of the |controller|. | |
| 108 // |controller| can be null when KeyboardController is destroying. | |
| 109 virtual void SetController(KeyboardController* controller); | |
| 110 | |
| 111 protected: | |
| 112 // The implementation can choose to setup the WebContents before the virtual | |
| 113 // keyboard page is loaded (e.g. install a WebContentsObserver). | |
| 114 // SetupWebContents() is called right after creating the WebContents, before | |
| 115 // loading the keyboard page. | |
| 116 virtual void SetupWebContents(content::WebContents* contents); | |
| 117 | |
| 118 // aura::WindowObserver overrides: | |
| 119 void OnWindowBoundsChanged(aura::Window* window, | |
| 120 const gfx::Rect& old_bounds, | |
| 121 const gfx::Rect& new_bounds) override; | |
| 122 void OnWindowDestroyed(aura::Window* window) override; | |
| 123 | |
| 124 content::BrowserContext* browser_context() { return browser_context_; } | |
| 125 KeyboardController* keyboard_controller() { return keyboard_controller_; } | |
| 126 | |
| 127 private: | |
| 128 friend class TestApi; | |
| 129 | |
| 130 // Loads the web contents for the given |url|. | |
| 131 void LoadContents(const GURL& url); | |
| 132 | |
| 133 // Gets the virtual keyboard URL (either the default URL or IME override URL). | |
| 134 const GURL& GetVirtualKeyboardUrl(); | |
| 135 | |
| 136 // The BrowserContext to use for creating the WebContents hosting the | |
| 137 // keyboard. | |
| 138 content::BrowserContext* browser_context_; | |
| 139 | |
| 140 const GURL default_url_; | |
| 141 keyboard::KeyboardController* keyboard_controller_; | |
| 142 | |
| 143 scoped_ptr<content::WebContents> keyboard_contents_; | |
| 144 scoped_ptr<wm::Shadow> shadow_; | |
| 145 | |
| 146 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerProxy); | |
| 147 }; | |
| 148 | |
| 149 } // namespace keyboard | |
| 150 | |
| 151 #endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_ | |
| OLD | NEW |