Index: chrome/browser/ui/views/frame/touch_browser_frame_view.cc |
diff --git a/chrome/browser/ui/views/frame/touch_browser_frame_view.cc b/chrome/browser/ui/views/frame/touch_browser_frame_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2706173137d5b37287c1405798626f0b7f23bfc6 |
--- /dev/null |
+++ b/chrome/browser/ui/views/frame/touch_browser_frame_view.cc |
@@ -0,0 +1,106 @@ |
+// 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/touch_browser_frame_view.h" |
+ |
+#include <algorithm> |
+ |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/renderer_host/site_instance.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" |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+// TouchBrowserFrameView, public: |
+ |
+TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, |
+ BrowserView* browser_view) |
+ : OpaqueBrowserFrameView(frame, browser_view) { |
+ registrar_.Add(this, |
sky
2010/12/09 22:19:03
initialize keyboard_ to NULL here.
bryeung
2010/12/10 17:23:19
Done.
|
+ NotificationType::NAV_ENTRY_COMMITTED, |
+ NotificationService::AllSources()); |
+ registrar_.Add(this, |
+ NotificationType::FOCUS_CHANGED_IN_PAGE, |
+ NotificationService::AllSources()); |
+} |
+ |
+TouchBrowserFrameView::~TouchBrowserFrameView() { |
+} |
+ |
+void TouchBrowserFrameView::Layout() { |
+ OpaqueBrowserFrameView::Layout(); |
+ |
+ if (keyboard_ && keyboard_->IsVisible()) { |
+ gfx::Rect* client_view_bounds = this->client_view_bounds(); |
sky
2010/12/09 22:19:03
Adjusting the height in this manner is subtle and
bryeung
2010/12/10 17:23:19
Done.
|
+ int keyboard_height = 200; |
+ client_view_bounds->set_height( |
+ std::max(0, client_view_bounds->height() - keyboard_height)); |
+ |
+ keyboard_->SetBounds(client_view_bounds->x(), |
+ client_view_bounds->y() + client_view_bounds->height(), |
+ client_view_bounds->width(), keyboard_height); |
+ keyboard_->Layout(); |
+ } |
+} |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+// TouchBrowserFrameView, private: |
+ |
+void TouchBrowserFrameView::InitVirtualKeyboard() { |
+ if (keyboard_) |
+ return; |
+ |
+ keyboard_ = new DOMView; |
+ |
+ Profile* keyboard_profile = GetBrowserView()->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 we have not created the keyboard yet, then we can safely skip |
+ // this method as must be trying to hide it. |
+ if (!keyboard_) { |
+ DCHECK(!should_show_keyboard); |
+ return; |
+ } |
+ |
+ keyboard_->SetVisible(should_show_keyboard); |
+ Layout(); |
+ |
+ // Because the NonClientFrameView is a sibling of the ClientView, |
+ // we rely on the parent to properly resize the ClientView. |
+ GetParent()->Layout(); |
sky
2010/12/09 22:19:03
Shouldn't this result in a Layout on this class to
bryeung
2010/12/10 17:23:19
Yep, you're right. I'll use a smaller hammer :-)
|
+} |
+ |
+void TouchBrowserFrameView::Observe(NotificationType type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) { |
+ if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { |
+ InitVirtualKeyboard(); |
+ const bool is_editable_node = *Details<const bool>(details).ptr(); |
+ if (is_editable_node != keyboard_->IsVisible()) { |
sky
2010/12/09 22:19:03
Rather than having the check here, wouldn't it be
bryeung
2010/12/10 17:23:19
Yes: good idea. Done.
|
+ UpdateKeyboardAndLayout(is_editable_node); |
+ } |
+ } else { |
sky
2010/12/09 22:19:03
You should at least have a DCHECK here on the type
bryeung
2010/12/10 17:23:19
Done.
|
+ // 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); |
+ } |
+} |