OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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 CHROME_BROWSER_UI_TOUCH_KEYBOARD_KEYBOARD_MANAGER_H_ | |
6 #define CHROME_BROWSER_UI_TOUCH_KEYBOARD_KEYBOARD_MANAGER_H_ | |
7 #pragma once | |
8 | |
9 #include "base/memory/singleton.h" | |
10 #include "chrome/browser/extensions/extension_function_dispatcher.h" | |
11 #include "chrome/browser/tabs/tab_strip_model_observer.h" | |
12 #include "chrome/browser/ui/browser_list.h" | |
13 #include "content/browser/tab_contents/tab_contents_observer.h" | |
14 #include "content/common/notification_observer.h" | |
15 #include "ui/base/animation/animation_delegate.h" | |
16 #include "views/widget/widget.h" | |
17 | |
18 #if defined(OS_CHROMEOS) | |
19 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | |
20 #endif | |
21 | |
22 namespace IPC { | |
23 class Message; | |
24 } | |
25 | |
26 namespace ui { | |
27 class InterpolatedTransform; | |
28 class SlideAnimation; | |
29 } | |
30 | |
31 namespace views { | |
32 class KeyEvent; | |
33 } | |
34 | |
35 class DOMView; | |
36 class ExtensionHostMsg_Request_Params; | |
37 | |
38 // A singleton object to manage the virtual keyboard. | |
39 class KeyboardManager | |
40 : public views::Widget, | |
41 public ui::AnimationDelegate, | |
42 public BrowserList::Observer, | |
43 public TabContentsObserver, | |
44 public TabStripModelObserver, | |
45 public ExtensionFunctionDispatcher::Delegate, | |
46 #if defined(OS_CHROMEOS) | |
47 public chromeos::input_method::InputMethodManager::VirtualKeyboardObserver , | |
48 #endif | |
49 public NotificationObserver { | |
50 public: | |
51 // Returns the singleton object. | |
52 static KeyboardManager* GetInstance(); | |
53 | |
54 // Show the keyboard for the target widget. The events from the keyboard will | |
55 // be sent to |widget|. | |
56 // TODO(sad): Allow specifying the type of keyboard to show. | |
57 void ShowKeyboardForWidget(views::Widget* widget); | |
58 | |
59 // Overridden from views::Widget | |
60 void Hide() OVERRIDE; | |
61 | |
62 private: | |
63 // Requirement for Singleton | |
64 friend struct DefaultSingletonTraits<KeyboardManager>; | |
65 | |
66 KeyboardManager(); | |
67 virtual ~KeyboardManager(); | |
68 | |
69 // Overridden from views::Widget. | |
70 virtual bool OnKeyEvent(const views::KeyEvent& event) OVERRIDE; | |
71 | |
72 // Overridden from ui::AnimationDelegate: | |
73 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | |
74 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | |
75 | |
76 // Overridden from BrowserList::Observer. | |
77 virtual void OnBrowserAdded(const Browser* browser) OVERRIDE; | |
78 virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE; | |
79 | |
80 // Overridden from TabContentsObserver | |
81 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
82 void OnRequest(const ExtensionHostMsg_Request_Params& params); | |
83 | |
84 // Overridden from TabStripModelObserver. | |
85 virtual void ActiveTabChanged(TabContentsWrapper* old_contents, | |
86 TabContentsWrapper* new_contents, | |
87 int index, | |
88 bool user_gesture); | |
89 | |
90 // ExtensionFunctionDispatcher::Delegate implementation | |
91 virtual Browser* GetBrowser() OVERRIDE; | |
92 virtual gfx::NativeView GetNativeViewOfHost() OVERRIDE; | |
93 virtual TabContents* GetAssociatedTabContents() const OVERRIDE; | |
94 | |
95 #if defined(OS_CHROMEOS) | |
96 // input_method::InputMethodManager::VirtualKeyboardObserver implementation. | |
97 virtual void VirtualKeyboardChanged( | |
98 chromeos::input_method::InputMethodManager* manager, | |
99 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | |
100 const std::string& virtual_keyboard_layout); | |
101 #endif | |
102 | |
103 // NotificationObserver implementation: | |
104 virtual void Observe(NotificationType type, | |
105 const NotificationSource& source, | |
106 const NotificationDetails& details) OVERRIDE; | |
107 | |
108 // The animation. | |
109 scoped_ptr<ui::SlideAnimation> animation_; | |
110 | |
111 // Interpolated transform used during animation. | |
112 scoped_ptr<ui::InterpolatedTransform> transform_; | |
113 | |
114 // The DOM view to host the keyboard. | |
115 DOMView* dom_view_; | |
Peng
2011/07/06 17:50:34
Maybe should use scoped_ptr here? Or delete it in
sadrul
2011/07/06 18:54:19
The Widget/RootView will take ownership of the DOM
Peng
2011/07/06 19:08:48
Thanks for explanation.
| |
116 | |
117 ExtensionFunctionDispatcher extension_dispatcher_; | |
118 | |
119 // The widget the events from the keyboard should be directed to. | |
120 views::Widget* target_; | |
121 | |
122 // Height of the keyboard. | |
123 int keyboard_height_; | |
124 | |
125 NotificationRegistrar registrar_; | |
126 | |
127 DISALLOW_COPY_AND_ASSIGN(KeyboardManager); | |
128 }; | |
129 | |
130 #endif // CHROME_BROWSER_UI_TOUCH_KEYBOARD_KEYBOARD_MANAGER_H_ | |
OLD | NEW |