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/base/ime/text_input_type.h" 11 #include "ui/keyboard/keyboard_export.h" 12 13 namespace aura { 14 class Window; 15 } 16 namespace content { 17 class BrowserContext; 18 class SiteInstance; 19 class WebContents; 20 } 21 namespace gfx { 22 class Rect; 23 } 24 namespace ui { 25 class InputMethod; 26 } 27 28 namespace keyboard { 29 30 // A proxy used by the KeyboardController to get access to the virtual 31 // keyboard window. 32 class KEYBOARD_EXPORT KeyboardControllerProxy { 33 public: 34 KeyboardControllerProxy(); 35 virtual ~KeyboardControllerProxy(); 36 37 // Gets the virtual keyboard window. Ownership of the returned Window remains 38 // with the proxy. 39 virtual aura::Window* GetKeyboardWindow(); 40 41 // Sets the override content url. 42 void SetOverrideContentUrl(const GURL& url); 43 44 // Whether the keyboard window is resizing from its web contents. resizing_from_contents()45 bool resizing_from_contents() const { return resizing_from_contents_; } 46 47 // Sets the flag of whether the keyboard window is resizing from 48 // its web contents. set_resizing_from_contents(bool resizing)49 void set_resizing_from_contents(bool resizing) { 50 resizing_from_contents_ = resizing; 51 } 52 53 // Gets the InputMethod that will provide notifications about changes in the 54 // text input context. 55 virtual ui::InputMethod* GetInputMethod() = 0; 56 57 // Requests the audio input from microphone for speech input. 58 virtual void RequestAudioInput(content::WebContents* web_contents, 59 const content::MediaStreamRequest& request, 60 const content::MediaResponseCallback& callback) = 0; 61 62 // Shows the container window of the keyboard. The default implementation 63 // simply shows the container. An overridden implementation can set up 64 // necessary animation, or delay the visibility change as it desires. 65 virtual void ShowKeyboardContainer(aura::Window* container); 66 67 // Hides the container window of the keyboard. The default implementation 68 // simply hides the container. An overridden implementation can set up 69 // necesasry animation, or delay the visibility change as it desires. 70 virtual void HideKeyboardContainer(aura::Window* container); 71 72 // Updates the type of the focused text input box. The default implementation 73 // calls OnTextInputBoxFocused javascript function through webui to update the 74 // type the of focused input box. 75 virtual void SetUpdateInputType(ui::TextInputType type); 76 77 protected: 78 // Gets the BrowserContext to use for creating the WebContents hosting the 79 // keyboard. 80 virtual content::BrowserContext* GetBrowserContext() = 0; 81 82 // The implementation can choose to setup the WebContents before the virtual 83 // keyboard page is loaded (e.g. install a WebContentsObserver). 84 // SetupWebContents() is called right after creating the WebContents, before 85 // loading the keyboard page. 86 virtual void SetupWebContents(content::WebContents* contents); 87 88 private: 89 // Reloads the web contents to the valid url from GetValidUrl(). 90 void ReloadContents(); 91 92 // Gets the valid url from default url or override url. 93 const GURL& GetValidUrl(); 94 95 const GURL default_url_; 96 GURL override_url_; 97 98 scoped_ptr<content::WebContents> keyboard_contents_; 99 100 // Whether the current keyboard window is resizing from its web content. 101 bool resizing_from_contents_; 102 103 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerProxy); 104 }; 105 106 } // namespace keyboard 107 108 #endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_ 109