| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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_CONTENT_KEYBOARD_UI_CONTENT_H_ |
| 6 #define UI_KEYBOARD_CONTENT_KEYBOARD_UI_CONTENT_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 #include "ui/keyboard/keyboard_ui.h" |
| 14 |
| 15 namespace aura { |
| 16 class Window; |
| 17 } |
| 18 namespace content { |
| 19 class BrowserContext; |
| 20 class SiteInstance; |
| 21 class WebContents; |
| 22 } |
| 23 namespace gfx { |
| 24 class Rect; |
| 25 } |
| 26 namespace ui { |
| 27 class InputMethod; |
| 28 } |
| 29 namespace wm { |
| 30 class Shadow; |
| 31 } |
| 32 |
| 33 namespace keyboard { |
| 34 |
| 35 class KeyboardController; |
| 36 class WindowBoundsChangeObserver; |
| 37 |
| 38 // An implementation of KeyboardUI that uses a content::WebContents to implement |
| 39 //the keyboard. |
| 40 class KEYBOARD_EXPORT KeyboardUIContent : public KeyboardUI, |
| 41 public aura::WindowObserver { |
| 42 public: |
| 43 class TestApi { |
| 44 public: |
| 45 explicit TestApi(KeyboardUIContent* ui) : ui_(ui) {} |
| 46 |
| 47 const content::WebContents* keyboard_contents() { |
| 48 return ui_->keyboard_contents_.get(); |
| 49 } |
| 50 |
| 51 private: |
| 52 KeyboardUIContent* ui_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(TestApi); |
| 55 }; |
| 56 |
| 57 explicit KeyboardUIContent(content::BrowserContext* context); |
| 58 ~KeyboardUIContent() override; |
| 59 |
| 60 // Requests the audio input from microphone for speech input. |
| 61 virtual void RequestAudioInput(content::WebContents* web_contents, |
| 62 const content::MediaStreamRequest& request, |
| 63 const content::MediaResponseCallback& callback) = 0; |
| 64 |
| 65 // Loads system virtual keyboard. Noop if the current virtual keyboard is |
| 66 // system virtual keyboard. |
| 67 virtual void LoadSystemKeyboard(); |
| 68 |
| 69 // Called when a window being observed changes bounds, to update its insets. |
| 70 void UpdateInsetsForWindow(aura::Window* window); |
| 71 |
| 72 // Overridden from KeyboardUI: |
| 73 aura::Window* GetKeyboardWindow() override; |
| 74 bool HasKeyboardWindow() const override; |
| 75 void ReloadKeyboardIfNeeded() override; |
| 76 void InitInsets(const gfx::Rect& new_bounds) override; |
| 77 void ResetInsets() override; |
| 78 |
| 79 protected: |
| 80 // The implementation can choose to setup the WebContents before the virtual |
| 81 // keyboard page is loaded (e.g. install a WebContentsObserver). |
| 82 // SetupWebContents() is called right after creating the WebContents, before |
| 83 // loading the keyboard page. |
| 84 virtual void SetupWebContents(content::WebContents* contents); |
| 85 |
| 86 // aura::WindowObserver overrides: |
| 87 void OnWindowBoundsChanged(aura::Window* window, |
| 88 const gfx::Rect& old_bounds, |
| 89 const gfx::Rect& new_bounds) override; |
| 90 void OnWindowDestroyed(aura::Window* window) override; |
| 91 |
| 92 content::BrowserContext* browser_context() { return browser_context_; } |
| 93 |
| 94 private: |
| 95 friend class TestApi; |
| 96 |
| 97 // Loads the web contents for the given |url|. |
| 98 void LoadContents(const GURL& url); |
| 99 |
| 100 // Gets the virtual keyboard URL (either the default URL or IME override URL). |
| 101 const GURL& GetVirtualKeyboardUrl(); |
| 102 |
| 103 // Determines whether a particular window should have insets for overscroll. |
| 104 bool ShouldEnableInsets(aura::Window* window); |
| 105 |
| 106 // Adds an observer for tracking changes to a window size or |
| 107 // position while the keyboard is displayed. Any window repositioning |
| 108 // invalidates insets for overscrolling. |
| 109 void AddBoundsChangedObserver(aura::Window* window); |
| 110 |
| 111 // The BrowserContext to use for creating the WebContents hosting the |
| 112 // keyboard. |
| 113 content::BrowserContext* browser_context_; |
| 114 |
| 115 const GURL default_url_; |
| 116 |
| 117 scoped_ptr<content::WebContents> keyboard_contents_; |
| 118 scoped_ptr<wm::Shadow> shadow_; |
| 119 |
| 120 scoped_ptr<WindowBoundsChangeObserver> window_bounds_observer_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(KeyboardUIContent); |
| 123 }; |
| 124 |
| 125 } // namespace keyboard |
| 126 |
| 127 #endif // UI_KEYBOARD_CONTENT_KEYBOARD_UI_CONTENT_H_ |
| OLD | NEW |