Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/touch/frame/touch_browser_frame_view.h" | 5 #include "chrome/browser/ui/touch/frame/touch_browser_frame_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/renderer_host/site_instance.h" | 10 #include "chrome/browser/renderer_host/site_instance.h" |
| 11 #include "chrome/browser/tab_contents/navigation_controller.h" | |
| 11 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/views/dom_view.h" | 14 #include "chrome/browser/ui/views/dom_view.h" |
| 14 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 16 #include "chrome/common/notification_type.h" | 17 #include "chrome/common/notification_type.h" |
| 17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 18 #include "gfx/rect.h" | 19 #include "gfx/rect.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const int kKeyboardHeight = 300; | 23 const int kKeyboardHeight = 300; |
| 23 | 24 |
| 24 } // namespace | 25 } // namespace |
| 25 | 26 |
| 26 /////////////////////////////////////////////////////////////////////////////// | 27 /////////////////////////////////////////////////////////////////////////////// |
| 27 // TouchBrowserFrameView, public: | 28 // TouchBrowserFrameView, public: |
| 28 | 29 |
| 29 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, | 30 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, |
| 30 BrowserView* browser_view) | 31 BrowserView* browser_view) |
| 31 : OpaqueBrowserFrameView(frame, browser_view), | 32 : OpaqueBrowserFrameView(frame, browser_view), |
| 33 keyboard_showing_(false), | |
| 32 keyboard_(NULL) { | 34 keyboard_(NULL) { |
| 33 registrar_.Add(this, | 35 registrar_.Add(this, |
| 34 NotificationType::NAV_ENTRY_COMMITTED, | 36 NotificationType::NAV_ENTRY_COMMITTED, |
| 35 NotificationService::AllSources()); | 37 NotificationService::AllSources()); |
| 36 registrar_.Add(this, | 38 registrar_.Add(this, |
| 37 NotificationType::FOCUS_CHANGED_IN_PAGE, | 39 NotificationType::FOCUS_CHANGED_IN_PAGE, |
| 38 NotificationService::AllSources()); | 40 NotificationService::AllSources()); |
| 39 } | 41 } |
| 40 | 42 |
| 41 TouchBrowserFrameView::~TouchBrowserFrameView() { | 43 TouchBrowserFrameView::~TouchBrowserFrameView() { |
| 42 } | 44 } |
| 43 | 45 |
| 44 /////////////////////////////////////////////////////////////////////////////// | 46 /////////////////////////////////////////////////////////////////////////////// |
| 45 // TouchBrowserFrameView, protected: | 47 // TouchBrowserFrameView, protected: |
| 46 int TouchBrowserFrameView::GetReservedHeight() const { | 48 int TouchBrowserFrameView::GetReservedHeight() const { |
| 47 if (keyboard_ && keyboard_->IsVisible()) { | 49 if (keyboard_showing_) |
| 48 return kKeyboardHeight; | 50 return kKeyboardHeight; |
| 49 } | 51 |
| 50 return 0; | 52 return 0; |
| 51 } | 53 } |
| 52 | 54 |
| 53 /////////////////////////////////////////////////////////////////////////////// | 55 /////////////////////////////////////////////////////////////////////////////// |
| 54 // TouchBrowserFrameView, private: | 56 // TouchBrowserFrameView, private: |
| 55 | 57 |
| 56 void TouchBrowserFrameView::InitVirtualKeyboard() { | 58 void TouchBrowserFrameView::InitVirtualKeyboard() { |
| 57 if (keyboard_) | 59 if (keyboard_) |
| 58 return; | 60 return; |
| 59 | 61 |
| 60 keyboard_ = new DOMView; | 62 keyboard_ = new DOMView; |
| 61 | 63 |
| 62 Profile* keyboard_profile = browser_view()->browser()->profile(); | 64 Profile* keyboard_profile = browser_view()->browser()->profile(); |
| 63 DCHECK(keyboard_profile) << "Profile required for virtual keyboard."; | 65 DCHECK(keyboard_profile) << "Profile required for virtual keyboard."; |
| 64 | 66 |
| 65 GURL keyboard_url(chrome::kChromeUIKeyboardURL); | 67 GURL keyboard_url(chrome::kChromeUIKeyboardURL); |
| 66 keyboard_->Init(keyboard_profile, | 68 keyboard_->Init(keyboard_profile, |
| 67 SiteInstance::CreateSiteInstanceForURL(keyboard_profile, keyboard_url)); | 69 SiteInstance::CreateSiteInstanceForURL(keyboard_profile, keyboard_url)); |
| 68 keyboard_->LoadURL(keyboard_url); | 70 keyboard_->LoadURL(keyboard_url); |
| 69 | 71 |
| 70 keyboard_->SetVisible(false); | 72 keyboard_->SetVisible(false); |
| 71 AddChildView(keyboard_); | 73 AddChildView(keyboard_); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) { | 76 void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) { |
| 75 if (should_show_keyboard) | 77 if (should_show_keyboard) |
| 76 InitVirtualKeyboard(); | 78 InitVirtualKeyboard(); |
| 77 | 79 |
| 78 // Don't do any extra work until we have shown the keyboard. | 80 // Don't do any extra work until we have shown the keyboard. |
| 79 if (!keyboard_) | 81 if (!keyboard_) |
|
sky
2010/12/15 17:05:33
Why do we need this check?
bryeung
2010/12/15 18:02:01
As discussed in the other CL, if we want to be ign
sky
2010/12/15 18:11:49
In that case won't should_show_keyboard_ == keyboa
| |
| 80 return; | 82 return; |
| 81 | 83 |
| 82 if (should_show_keyboard == keyboard_->IsVisible()) | 84 if (should_show_keyboard == keyboard_->IsVisible()) |
|
sky
2010/12/15 17:05:33
Shouldn't this be keyboard_showing_ ?
bryeung
2010/12/15 18:02:01
I thought it would be better to rely on the actual
| |
| 83 return; | 85 return; |
| 84 | 86 |
| 87 keyboard_showing_ = should_show_keyboard; | |
| 88 | |
| 89 keyboard_->SetBounds(GetBoundsForReservedArea()); | |
| 85 keyboard_->SetVisible(should_show_keyboard); | 90 keyboard_->SetVisible(should_show_keyboard); |
| 86 | 91 |
| 87 // Because the NonClientFrameView is a sibling of the ClientView, | 92 // Because the NonClientFrameView is a sibling of the ClientView, we rely on |
| 88 // we rely on the parent to properly resize the ClientView. | 93 // the parent to resize the ClientView instead of resizing it directly. |
| 89 GetParent()->Layout(); | 94 GetParent()->Layout(); |
| 90 } | 95 } |
| 91 | 96 |
| 92 void TouchBrowserFrameView::Observe(NotificationType type, | 97 void TouchBrowserFrameView::Observe(NotificationType type, |
| 93 const NotificationSource& source, | 98 const NotificationSource& source, |
| 94 const NotificationDetails& details) { | 99 const NotificationDetails& details) { |
| 100 Browser* browser = browser_view()->browser(); | |
| 95 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { | 101 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { |
| 96 // Only modify the keyboard state if the notification is coming from | 102 // Only modify the keyboard state if the notification is coming from |
| 97 // a source within the same Browser. | 103 // a source within the same Browser. |
| 98 Browser* browser = browser_view()->browser(); | |
| 99 Source<RenderViewHost> specific_source(source); | 104 Source<RenderViewHost> specific_source(source); |
| 100 for (int i = 0; i < browser->tab_count(); ++i) { | 105 for (int i = 0; i < browser->tab_count(); ++i) { |
| 101 if (browser->GetTabContentsAt(i)->render_view_host() == | 106 if (browser->GetTabContentsAt(i)->render_view_host() == |
| 102 specific_source.ptr()) { | 107 specific_source.ptr()) { |
| 103 UpdateKeyboardAndLayout(*Details<const bool>(details).ptr()); | 108 UpdateKeyboardAndLayout(*Details<const bool>(details).ptr()); |
| 104 break; | 109 break; |
| 105 } | 110 } |
| 106 } | 111 } |
| 107 } else { | 112 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { |
| 108 DCHECK(type == NotificationType::NAV_ENTRY_COMMITTED); | 113 Browser* source_browser = Browser::GetBrowserForController( |
| 109 | 114 Source<NavigationController>(source).ptr(), NULL); |
| 110 // TODO(bryeung): this is hiding the keyboard for the very first page | 115 // If the Browser for the keyboard has navigated, hide the keyboard. |
| 111 // load after browser startup when the page has an input element focused | 116 if (source_browser == browser) { |
| 112 // to start with. It would be nice to fix, but not critical. | 117 UpdateKeyboardAndLayout(false); |
| 113 | 118 } |
| 114 // Everything else we have registered for should hide the keyboard. | |
| 115 UpdateKeyboardAndLayout(false); | |
| 116 } | 119 } |
| 117 } | 120 } |
| OLD | NEW |