summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/touch
diff options
context:
space:
mode:
authorbryeung@google.com <bryeung@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 16:41:40 +0000
committerbryeung@google.com <bryeung@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 16:41:40 +0000
commit4fe042fe3682218e390de37034adfc31b3829fca (patch)
tree9752ee26b48e380b37503ac893c0f24824d422df /chrome/browser/ui/touch
parentdf9a6e01402dc07755bc0da0f9863e4f2ee578e7 (diff)
downloadchromium_src-4fe042fe3682218e390de37034adfc31b3829fca.zip
chromium_src-4fe042fe3682218e390de37034adfc31b3829fca.tar.gz
chromium_src-4fe042fe3682218e390de37034adfc31b3829fca.tar.bz2
Add the virtual keyboard to BrowserFrameChromeos.
BUG=none TEST=focusing a text field shows the placeholder keyboard Review URL: http://codereview.chromium.org/5747001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69142 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/touch')
-rw-r--r--chrome/browser/ui/touch/frame/browser_non_client_frame_view_factory_touch.cc23
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.cc117
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.h45
3 files changed, 185 insertions, 0 deletions
diff --git a/chrome/browser/ui/touch/frame/browser_non_client_frame_view_factory_touch.cc b/chrome/browser/ui/touch/frame/browser_non_client_frame_view_factory_touch.cc
new file mode 100644
index 0000000..5223640
--- /dev/null
+++ b/chrome/browser/ui/touch/frame/browser_non_client_frame_view_factory_touch.cc
@@ -0,0 +1,23 @@
+// Copyright (c) 2010 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/views/frame/browser_non_client_frame_view.h"
+
+#include "chrome/browser/ui/touch/frame/touch_browser_frame_view.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+
+namespace browser {
+
+BrowserNonClientFrameView* CreateBrowserNonClientFrameView(
+ BrowserFrame* frame, BrowserView* browser_view) {
+ if (browser_view->IsBrowserTypePopup()) {
+ // TODO(anicolao): implement popups for touch
+ NOTIMPLEMENTED();
+ return NULL;
+ } else {
+ return new TouchBrowserFrameView(frame, browser_view);
+ }
+}
+
+} // browser
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
new file mode 100644
index 0000000..2b14ec6
--- /dev/null
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc
@@ -0,0 +1,117 @@
+// Copyright (c) 2010 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/frame/touch_browser_frame_view.h"
+
+#include <algorithm>
+
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/renderer_host/site_instance.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/views/dom_view.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_type.h"
+#include "chrome/common/url_constants.h"
+#include "gfx/rect.h"
+
+namespace {
+
+const int kKeyboardHeight = 300;
+
+} // namespace
+
+///////////////////////////////////////////////////////////////////////////////
+// TouchBrowserFrameView, public:
+
+TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
+ BrowserView* browser_view)
+ : OpaqueBrowserFrameView(frame, browser_view),
+ keyboard_(NULL) {
+ registrar_.Add(this,
+ NotificationType::NAV_ENTRY_COMMITTED,
+ NotificationService::AllSources());
+ registrar_.Add(this,
+ NotificationType::FOCUS_CHANGED_IN_PAGE,
+ NotificationService::AllSources());
+}
+
+TouchBrowserFrameView::~TouchBrowserFrameView() {
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// TouchBrowserFrameView, protected:
+int TouchBrowserFrameView::GetReservedHeight() const {
+ if (keyboard_ && keyboard_->IsVisible()) {
+ return kKeyboardHeight;
+ }
+ return 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// TouchBrowserFrameView, private:
+
+void TouchBrowserFrameView::InitVirtualKeyboard() {
+ if (keyboard_)
+ return;
+
+ keyboard_ = new DOMView;
+
+ Profile* keyboard_profile = browser_view()->browser()->profile();
+ DCHECK(keyboard_profile) << "Profile required for virtual keyboard.";
+
+ GURL keyboard_url(chrome::kChromeUIKeyboardURL);
+ keyboard_->Init(keyboard_profile,
+ SiteInstance::CreateSiteInstanceForURL(keyboard_profile, keyboard_url));
+ keyboard_->LoadURL(keyboard_url);
+
+ keyboard_->SetVisible(false);
+ AddChildView(keyboard_);
+}
+
+void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) {
+ if (should_show_keyboard)
+ InitVirtualKeyboard();
+
+ // Don't do any extra work until we have shown the keyboard.
+ if (!keyboard_)
+ return;
+
+ if (should_show_keyboard == keyboard_->IsVisible())
+ return;
+
+ keyboard_->SetVisible(should_show_keyboard);
+
+ // Because the NonClientFrameView is a sibling of the ClientView,
+ // we rely on the parent to properly resize the ClientView.
+ GetParent()->Layout();
+}
+
+void TouchBrowserFrameView::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) {
+ // Only modify the keyboard state if the notification is coming from
+ // a source within the same Browser.
+ Browser* browser = browser_view()->browser();
+ Source<RenderViewHost> specific_source(source);
+ for (int i = 0; i < browser->tab_count(); ++i) {
+ if (browser->GetTabContentsAt(i)->render_view_host() ==
+ specific_source.ptr()) {
+ UpdateKeyboardAndLayout(*Details<const bool>(details).ptr());
+ break;
+ }
+ }
+ } else {
+ DCHECK(type == NotificationType::NAV_ENTRY_COMMITTED);
+
+ // TODO(bryeung): this is hiding the keyboard for the very first page
+ // load after browser startup when the page has an input element focused
+ // to start with. It would be nice to fix, but not critical.
+
+ // Everything else we have registered for should hide the keyboard.
+ UpdateKeyboardAndLayout(false);
+ }
+}
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
new file mode 100644
index 0000000..12d9328
--- /dev/null
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2010 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.
+
+#ifndef CHROME_BROWSER_UI_TOUCH_FRAME_TOUCH_BROWSER_FRAME_VIEW_H_
+#define CHROME_BROWSER_UI_TOUCH_FRAME_TOUCH_BROWSER_FRAME_VIEW_H_
+#pragma once
+
+#include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
+
+class BrowserFrame;
+class BrowserView;
+class DOMView;
+class NotificationDetails;
+class NotificationSource;
+
+class TouchBrowserFrameView : public OpaqueBrowserFrameView,
+ public NotificationObserver {
+ public:
+ // Constructs a non-client view for an BrowserFrame.
+ TouchBrowserFrameView(BrowserFrame* frame, BrowserView* browser_view);
+ virtual ~TouchBrowserFrameView();
+
+ protected:
+ // Overridden from OpaqueBrowserFrameView
+ virtual int GetReservedHeight() const;
+
+ private:
+ virtual void InitVirtualKeyboard();
+ virtual void UpdateKeyboardAndLayout(bool should_show_keyboard);
+
+ // Overridden from NotificationObserver.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ DOMView* keyboard_;
+ NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(TouchBrowserFrameView);
+};
+
+#endif // CHROME_BROWSER_UI_TOUCH_FRAME_TOUCH_BROWSER_FRAME_VIEW_H_