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 #include "chrome/browser/ui/touch/keyboard/keyboard_manager.h" | |
6 | |
7 #include "chrome/browser/profiles/profile.h" | |
8 #include "chrome/browser/profiles/profile_manager.h" | |
9 #include "chrome/browser/ui/browser_list.h" | |
10 #include "chrome/browser/ui/views/dom_view.h" | |
11 #include "chrome/common/extensions/extension_messages.h" | |
12 #include "chrome/common/url_constants.h" | |
13 #include "content/browser/site_instance.h" | |
14 #include "content/browser/tab_contents/tab_contents.h" | |
15 #include "ui/base/animation/slide_animation.h" | |
16 #include "ui/gfx/interpolated_transform.h" | |
17 #include "views/widget/widget.h" | |
18 | |
19 namespace { | |
20 | |
21 const int kDefaultKeyboardHeight = 300; | |
22 const int kKeyboardSlideDuration = 300; // In milliseconds | |
23 | |
24 } // namespace | |
25 | |
26 // TODO(sad): Is the default profile always going to be the one we want? | |
27 | |
28 KeyboardManager::KeyboardManager() | |
29 : views::Widget::Widget(), | |
30 dom_view_(new DOMView), | |
31 ALLOW_THIS_IN_INITIALIZER_LIST( | |
32 extension_dispatcher_(ProfileManager::GetDefaultProfile(), this)), | |
33 target_(NULL) { | |
34 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | |
35 params.transparent = true; | |
36 Init(params); | |
37 | |
38 Profile* profile = ProfileManager::GetDefaultProfile(); | |
39 GURL keyboard_url(chrome::kChromeUIKeyboardURL); | |
40 dom_view_->Init(profile, | |
41 SiteInstance::CreateSiteInstanceForURL(profile, keyboard_url)); | |
42 dom_view_->LoadURL(keyboard_url); | |
43 dom_view_->SetVisible(true); | |
44 | |
45 SetContentsView(dom_view_); | |
46 | |
47 Observe(dom_view_->tab_contents()); | |
48 | |
49 animation_.reset(new ui::SlideAnimation(this)); | |
50 animation_->SetTweenType(ui::Tween::LINEAR); | |
51 animation_->SetSlideDuration(kKeyboardSlideDuration); | |
52 } | |
53 | |
54 KeyboardManager::~KeyboardManager() { | |
55 // TODO(sad): Do anything? | |
56 } | |
57 | |
58 void KeyboardManager::ShowKeyboardForWidget(views::Widget* widget) { | |
59 // TODO(sad): There needs to be some way of resetting |target_| if/when it is | |
60 // destroyed. | |
61 target_ = widget; | |
62 | |
63 // TODO(sad): Use the configurable height for the keyboard, instead of always | |
64 // using the default height. | |
65 gfx::Rect rect = target_->GetWindowScreenBounds(); | |
66 rect.set_y(rect.height() - kDefaultKeyboardHeight); | |
67 rect.set_height(kDefaultKeyboardHeight); | |
68 SetBounds(rect); | |
69 | |
70 transform_.reset(new ui::InterpolatedTranslation( | |
71 gfx::Point(0, kDefaultKeyboardHeight), gfx::Point(), 0.0, 1.0)); | |
72 | |
Ian Vollick
2011/07/04 20:12:00
If the UI is rotated on its side, will setting the
sadrul
2011/07/04 20:21:19
The way orientation will happen, in my mind, is th
| |
73 GetRootView()->SetTransform( | |
74 transform_->Interpolate(animation_->GetCurrentValue())); | |
75 animation_->Show(); | |
76 | |
77 MoveToTop(); | |
78 Show(); | |
79 } | |
80 | |
81 void KeyboardManager::Hide() { | |
82 animation_->Hide(); | |
83 } | |
84 | |
85 bool KeyboardManager::OnKeyEvent(const views::KeyEvent& event) { | |
86 return target_ ? target_->OnKeyEvent(event) : false; | |
87 } | |
88 | |
89 void KeyboardManager::AnimationProgressed(const ui::Animation* animation) { | |
90 GetRootView()->SetTransform( | |
91 transform_->Interpolate(animation_->GetCurrentValue())); | |
92 } | |
93 | |
94 void KeyboardManager::AnimationEnded(const ui::Animation* animation) { | |
95 if (animation_->GetCurrentValue() < 0.01) | |
96 Widget::Hide(); | |
97 } | |
98 | |
99 bool KeyboardManager::OnMessageReceived(const IPC::Message& message) { | |
100 bool handled = true; | |
101 IPC_BEGIN_MESSAGE_MAP(KeyboardManager, message) | |
102 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
103 IPC_MESSAGE_UNHANDLED(handled = false) | |
104 IPC_END_MESSAGE_MAP() | |
105 return handled; | |
106 } | |
107 | |
108 void KeyboardManager::OnRequest( | |
109 const ExtensionHostMsg_Request_Params& request) { | |
110 extension_dispatcher_.Dispatch(request, | |
111 dom_view_->tab_contents()->render_view_host()); | |
112 } | |
113 | |
114 Browser* KeyboardManager::GetBrowser() { | |
115 // TODO(sad): Find a better way. Perhaps just return NULL, and fix | |
116 // SendKeyboardEventInputFunction::GetTopLevelWidget to somehow interact with | |
117 // the WM to find the top level widget? | |
118 return BrowserList::FindTabbedBrowser( | |
119 ProfileManager::GetDefaultProfile(), true); | |
120 } | |
121 | |
122 gfx::NativeView KeyboardManager::GetNativeViewOfHost() { | |
123 return dom_view_->native_view(); | |
124 } | |
125 | |
126 TabContents* KeyboardManager::GetAssociatedTabContents() const { | |
127 return dom_view_->tab_contents(); | |
128 } | |
129 | |
130 // static | |
131 KeyboardManager* KeyboardManager::GetInstance() { | |
132 return Singleton<KeyboardManager>::get(); | |
133 } | |
OLD | NEW |