Chromium Code Reviews| Index: chrome/browser/ui/touch/keyboard/keyboard_manager.cc |
| diff --git a/chrome/browser/ui/touch/keyboard/keyboard_manager.cc b/chrome/browser/ui/touch/keyboard/keyboard_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..da6c19eb805f68e4445ac7cdc30fb3d14498fccc |
| --- /dev/null |
| +++ b/chrome/browser/ui/touch/keyboard/keyboard_manager.cc |
| @@ -0,0 +1,133 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/touch/keyboard/keyboard_manager.h" |
| + |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/browser/ui/views/dom_view.h" |
| +#include "chrome/common/extensions/extension_messages.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "content/browser/site_instance.h" |
| +#include "content/browser/tab_contents/tab_contents.h" |
| +#include "ui/base/animation/slide_animation.h" |
| +#include "ui/gfx/interpolated_transform.h" |
| +#include "views/widget/widget.h" |
| + |
| +namespace { |
| + |
| +const int kDefaultKeyboardHeight = 300; |
| +const int kKeyboardSlideDuration = 300; // In milliseconds |
| + |
| +} // namespace |
| + |
| +// TODO(sad): Is the default profile always going to be the one we want? |
| + |
| +KeyboardManager::KeyboardManager() |
| + : views::Widget::Widget(), |
| + dom_view_(new DOMView), |
| + ALLOW_THIS_IN_INITIALIZER_LIST( |
| + extension_dispatcher_(ProfileManager::GetDefaultProfile(), this)), |
| + target_(NULL) { |
| + views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| + params.transparent = true; |
| + Init(params); |
| + |
| + Profile* profile = ProfileManager::GetDefaultProfile(); |
| + GURL keyboard_url(chrome::kChromeUIKeyboardURL); |
| + dom_view_->Init(profile, |
| + SiteInstance::CreateSiteInstanceForURL(profile, keyboard_url)); |
| + dom_view_->LoadURL(keyboard_url); |
| + dom_view_->SetVisible(true); |
| + |
| + SetContentsView(dom_view_); |
| + |
| + Observe(dom_view_->tab_contents()); |
| + |
| + animation_.reset(new ui::SlideAnimation(this)); |
| + animation_->SetTweenType(ui::Tween::LINEAR); |
| + animation_->SetSlideDuration(kKeyboardSlideDuration); |
| +} |
| + |
| +KeyboardManager::~KeyboardManager() { |
| + // TODO(sad): Do anything? |
| +} |
| + |
| +void KeyboardManager::ShowKeyboardForWidget(views::Widget* widget) { |
| + // TODO(sad): There needs to be some way of resetting |target_| if/when it is |
| + // destroyed. |
| + target_ = widget; |
| + |
| + // TODO(sad): Use the configurable height for the keyboard, instead of always |
| + // using the default height. |
| + gfx::Rect rect = target_->GetWindowScreenBounds(); |
| + rect.set_y(rect.height() - kDefaultKeyboardHeight); |
| + rect.set_height(kDefaultKeyboardHeight); |
| + SetBounds(rect); |
| + |
| + transform_.reset(new ui::InterpolatedTranslation( |
| + gfx::Point(0, kDefaultKeyboardHeight), gfx::Point(), 0.0, 1.0)); |
| + |
|
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
|
| + GetRootView()->SetTransform( |
| + transform_->Interpolate(animation_->GetCurrentValue())); |
| + animation_->Show(); |
| + |
| + MoveToTop(); |
| + Show(); |
| +} |
| + |
| +void KeyboardManager::Hide() { |
| + animation_->Hide(); |
| +} |
| + |
| +bool KeyboardManager::OnKeyEvent(const views::KeyEvent& event) { |
| + return target_ ? target_->OnKeyEvent(event) : false; |
| +} |
| + |
| +void KeyboardManager::AnimationProgressed(const ui::Animation* animation) { |
| + GetRootView()->SetTransform( |
| + transform_->Interpolate(animation_->GetCurrentValue())); |
| +} |
| + |
| +void KeyboardManager::AnimationEnded(const ui::Animation* animation) { |
| + if (animation_->GetCurrentValue() < 0.01) |
| + Widget::Hide(); |
| +} |
| + |
| +bool KeyboardManager::OnMessageReceived(const IPC::Message& message) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(KeyboardManager, message) |
| + IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| + IPC_MESSAGE_UNHANDLED(handled = false) |
| + IPC_END_MESSAGE_MAP() |
| + return handled; |
| +} |
| + |
| +void KeyboardManager::OnRequest( |
| + const ExtensionHostMsg_Request_Params& request) { |
| + extension_dispatcher_.Dispatch(request, |
| + dom_view_->tab_contents()->render_view_host()); |
| +} |
| + |
| +Browser* KeyboardManager::GetBrowser() { |
| + // TODO(sad): Find a better way. Perhaps just return NULL, and fix |
| + // SendKeyboardEventInputFunction::GetTopLevelWidget to somehow interact with |
| + // the WM to find the top level widget? |
| + return BrowserList::FindTabbedBrowser( |
| + ProfileManager::GetDefaultProfile(), true); |
| +} |
| + |
| +gfx::NativeView KeyboardManager::GetNativeViewOfHost() { |
| + return dom_view_->native_view(); |
| +} |
| + |
| +TabContents* KeyboardManager::GetAssociatedTabContents() const { |
| + return dom_view_->tab_contents(); |
| +} |
| + |
| +// static |
| +KeyboardManager* KeyboardManager::GetInstance() { |
| + return Singleton<KeyboardManager>::get(); |
| +} |