Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / ui / keyboard / keyboard_controller_proxy.h
blob0884cd91bb0b440e6e1ccafda1c0af19b8447c83
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.
5 #ifndef UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_
6 #define UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_
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"
13 namespace aura {
14 class Window;
16 namespace content {
17 class BrowserContext;
18 class SiteInstance;
19 class WebContents;
21 namespace gfx {
22 class Rect;
24 namespace ui {
25 class InputMethod;
28 namespace keyboard {
30 // A proxy used by the KeyboardController to get access to the virtual
31 // keyboard window.
32 class KEYBOARD_EXPORT KeyboardControllerProxy {
33 public:
34 class TestApi {
35 public:
36 explicit TestApi(KeyboardControllerProxy* proxy) : proxy_(proxy) {}
38 const content::WebContents* keyboard_contents() {
39 return proxy_->keyboard_contents_.get();
42 private:
43 KeyboardControllerProxy* proxy_;
45 DISALLOW_COPY_AND_ASSIGN(TestApi);
48 KeyboardControllerProxy();
49 virtual ~KeyboardControllerProxy();
51 // Gets the virtual keyboard window. Ownership of the returned Window remains
52 // with the proxy.
53 virtual aura::Window* GetKeyboardWindow();
55 // Whether the keyboard window is created. The keyboard window is tied to a
56 // WebContent so we can just check if the WebContent is created or not.
57 virtual bool HasKeyboardWindow() const;
59 // Gets the InputMethod that will provide notifications about changes in the
60 // text input context.
61 virtual ui::InputMethod* GetInputMethod() = 0;
63 // Requests the audio input from microphone for speech input.
64 virtual void RequestAudioInput(content::WebContents* web_contents,
65 const content::MediaStreamRequest& request,
66 const content::MediaResponseCallback& callback) = 0;
68 // Shows the container window of the keyboard. The default implementation
69 // simply shows the container. An overridden implementation can set up
70 // necessary animation, or delay the visibility change as it desires.
71 virtual void ShowKeyboardContainer(aura::Window* container);
73 // Hides the container window of the keyboard. The default implementation
74 // simply hides the container. An overridden implementation can set up
75 // necesasry animation, or delay the visibility change as it desires.
76 virtual void HideKeyboardContainer(aura::Window* container);
78 // Updates the type of the focused text input box.
79 virtual void SetUpdateInputType(ui::TextInputType type);
81 // Ensures caret in current work area (not occluded by virtual keyboard
82 // window).
83 virtual void EnsureCaretInWorkArea();
85 // Loads system virtual keyboard. Noop if the current virtual keyboard is
86 // system virtual keyboard.
87 virtual void LoadSystemKeyboard();
89 // Reloads virtual keyboard URL if the current keyboard's web content URL is
90 // different. The URL can be different if user switch from password field to
91 // any other type input field.
92 // At password field, the system virtual keyboard is forced to load even if
93 // the current IME provides a customized virtual keyboard. This is needed to
94 // prevent IME virtual keyboard logging user's password. Once user switch to
95 // other input fields, the virtual keyboard should switch back to the IME
96 // provided keyboard, or keep using the system virtual keyboard if IME doesn't
97 // provide one.
98 virtual void ReloadKeyboardIfNeeded();
100 protected:
101 // Gets the BrowserContext to use for creating the WebContents hosting the
102 // keyboard.
103 virtual content::BrowserContext* GetBrowserContext() = 0;
105 // The implementation can choose to setup the WebContents before the virtual
106 // keyboard page is loaded (e.g. install a WebContentsObserver).
107 // SetupWebContents() is called right after creating the WebContents, before
108 // loading the keyboard page.
109 virtual void SetupWebContents(content::WebContents* contents);
111 private:
112 friend class TestApi;
114 // Loads the web contents for the given |url|.
115 void LoadContents(const GURL& url);
117 // Gets the virtual keyboard URL (either the default URL or IME override URL).
118 const GURL& GetVirtualKeyboardUrl();
120 const GURL default_url_;
122 scoped_ptr<content::WebContents> keyboard_contents_;
124 DISALLOW_COPY_AND_ASSIGN(KeyboardControllerProxy);
127 } // namespace keyboard
129 #endif // UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_