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 "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/renderer_host/render_view_host.h" | 8 #include "chrome/browser/renderer_host/render_view_host.h" |
| 9 #include "chrome/browser/tab_contents/navigation_controller.h" | 9 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 11 #include "chrome/browser/tabs/tab_strip_model.h" | |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 12 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h" | 14 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 14 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 15 #include "chrome/common/notification_type.h" | 17 #include "chrome/common/notification_type.h" |
| 16 #include "gfx/rect.h" | 18 #include "gfx/rect.h" |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 const int kKeyboardHeight = 300; | 22 const int kKeyboardHeight = 300; |
| 21 | 23 |
| 24 PropertyAccessor<bool>* GetFocusedStateAccessor() { | |
| 25 static PropertyAccessor<bool> state; | |
| 26 return &state; | |
| 27 } | |
| 28 | |
| 22 } // namespace | 29 } // namespace |
| 23 | 30 |
| 24 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
| 25 // TouchBrowserFrameView, public: | 32 // TouchBrowserFrameView, public: |
| 26 | 33 |
| 27 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, | 34 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, |
| 28 BrowserView* browser_view) | 35 BrowserView* browser_view) |
| 29 : OpaqueBrowserFrameView(frame, browser_view), | 36 : OpaqueBrowserFrameView(frame, browser_view), |
| 30 keyboard_showing_(false), | 37 keyboard_showing_(false), |
| 31 keyboard_(NULL) { | 38 keyboard_(NULL) { |
| 32 registrar_.Add(this, | 39 registrar_.Add(this, |
| 33 NotificationType::NAV_ENTRY_COMMITTED, | 40 NotificationType::NAV_ENTRY_COMMITTED, |
| 34 NotificationService::AllSources()); | 41 NotificationService::AllSources()); |
| 35 registrar_.Add(this, | 42 registrar_.Add(this, |
| 36 NotificationType::FOCUS_CHANGED_IN_PAGE, | 43 NotificationType::FOCUS_CHANGED_IN_PAGE, |
| 37 NotificationService::AllSources()); | 44 NotificationService::AllSources()); |
| 45 registrar_.Add(this, | |
| 46 NotificationType::TAB_CONTENTS_DESTROYED, | |
| 47 NotificationService::AllSources()); | |
| 48 | |
| 49 browser_view->browser()->tabstrip_model()->AddObserver(this); | |
| 38 } | 50 } |
| 39 | 51 |
| 40 TouchBrowserFrameView::~TouchBrowserFrameView() { | 52 TouchBrowserFrameView::~TouchBrowserFrameView() { |
| 53 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); | |
| 41 } | 54 } |
| 42 | 55 |
| 43 void TouchBrowserFrameView::Layout() { | 56 void TouchBrowserFrameView::Layout() { |
| 44 OpaqueBrowserFrameView::Layout(); | 57 OpaqueBrowserFrameView::Layout(); |
| 45 | 58 |
| 46 if (!keyboard_) | 59 if (!keyboard_) |
| 47 return; | 60 return; |
| 48 | 61 |
| 49 keyboard_->SetVisible(keyboard_showing_); | 62 keyboard_->SetVisible(keyboard_showing_); |
| 50 keyboard_->SetBounds(GetBoundsForReservedArea()); | 63 keyboard_->SetBounds(GetBoundsForReservedArea()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 104 |
| 92 // The keyboard that pops up may end up hiding the text entry. So make sure | 105 // The keyboard that pops up may end up hiding the text entry. So make sure |
| 93 // the renderer scrolls when necessary to keep the textfield visible. | 106 // the renderer scrolls when necessary to keep the textfield visible. |
| 94 if (keyboard_showing_) { | 107 if (keyboard_showing_) { |
| 95 RenderViewHost* host = | 108 RenderViewHost* host = |
| 96 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); | 109 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); |
| 97 host->ScrollFocusedEditableNodeIntoView(); | 110 host->ScrollFocusedEditableNodeIntoView(); |
| 98 } | 111 } |
| 99 } | 112 } |
| 100 | 113 |
| 114 void TouchBrowserFrameView::TabSelectedAt(TabContentsWrapper* old_contents, | |
| 115 TabContentsWrapper* new_contents, | |
| 116 int index, | |
| 117 bool user_gesture) { | |
| 118 TabContents* contents = new_contents->tab_contents(); | |
| 119 UpdateKeyboardAndLayout(GetFocusedStateAccessor()->GetProperty( | |
| 120 contents->property_bag())); | |
| 121 } | |
| 122 | |
| 123 | |
| 101 void TouchBrowserFrameView::Observe(NotificationType type, | 124 void TouchBrowserFrameView::Observe(NotificationType type, |
| 102 const NotificationSource& source, | 125 const NotificationSource& source, |
| 103 const NotificationDetails& details) { | 126 const NotificationDetails& details) { |
| 104 Browser* browser = browser_view()->browser(); | 127 Browser* browser = browser_view()->browser(); |
| 105 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { | 128 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { |
| 106 // Only modify the keyboard state if the currently active tab sent the | 129 // Only modify the keyboard state if the currently active tab sent the |
| 107 // notification. | 130 // notification. |
| 108 const TabContents* tab_contents = browser->GetSelectedTabContents(); | 131 TabContents* tab_contents = browser->GetSelectedTabContents(); |
| 109 if (tab_contents && | 132 if (tab_contents) { |
| 110 tab_contents->render_view_host() == | 133 const bool editable = *Details<const bool>(details).ptr(); |
| 111 Source<RenderViewHost>(source).ptr()) | 134 if (tab_contents->render_view_host() == |
| 112 UpdateKeyboardAndLayout(*Details<const bool>(details).ptr()); | 135 Source<RenderViewHost>(source).ptr()) |
| 136 UpdateKeyboardAndLayout(editable); | |
| 137 | |
| 138 // Save the state of the focused field so that the keyboard visibility | |
| 139 // can be determined after tab switching. | |
| 140 GetFocusedStateAccessor()->SetProperty( | |
|
sky
2011/01/26 16:40:08
This code is problematic if focus changes on a bac
sadrul
2011/01/26 17:43:10
Indeed! I made the change to update the property-b
| |
| 141 tab_contents->property_bag(), editable); | |
| 142 } | |
| 113 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { | 143 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { |
| 114 Browser* source_browser = Browser::GetBrowserForController( | 144 Browser* source_browser = Browser::GetBrowserForController( |
| 115 Source<NavigationController>(source).ptr(), NULL); | 145 Source<NavigationController>(source).ptr(), NULL); |
| 116 // If the Browser for the keyboard has navigated, hide the keyboard. | 146 // If the Browser for the keyboard has navigated, hide the keyboard. |
| 117 if (source_browser == browser) | 147 if (source_browser == browser) |
| 118 UpdateKeyboardAndLayout(false); | 148 UpdateKeyboardAndLayout(false); |
| 149 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { | |
| 150 GetFocusedStateAccessor()->DeleteProperty( | |
| 151 Source<TabContents>(source).ptr()->property_bag()); | |
| 119 } | 152 } |
| 120 } | 153 } |
| OLD | NEW |