Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: chrome/browser/ui/touch/frame/touch_browser_frame_view.cc

Issue 6277020: keyboard: Update the visibility after tab-switch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/selected/focused/, and RemoveObserver. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
22 } // namespace 24 } // namespace
23 25
24 /////////////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////////////
25 // TouchBrowserFrameView, public: 27 // TouchBrowserFrameView, public:
26 28
27 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, 29 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
28 BrowserView* browser_view) 30 BrowserView* browser_view)
29 : OpaqueBrowserFrameView(frame, browser_view), 31 : OpaqueBrowserFrameView(frame, browser_view),
30 keyboard_showing_(false), 32 keyboard_showing_(false),
31 keyboard_(NULL) { 33 keyboard_(NULL) {
32 registrar_.Add(this, 34 registrar_.Add(this,
33 NotificationType::NAV_ENTRY_COMMITTED, 35 NotificationType::NAV_ENTRY_COMMITTED,
34 NotificationService::AllSources()); 36 NotificationService::AllSources());
35 registrar_.Add(this, 37 registrar_.Add(this,
36 NotificationType::FOCUS_CHANGED_IN_PAGE, 38 NotificationType::FOCUS_CHANGED_IN_PAGE,
37 NotificationService::AllSources()); 39 NotificationService::AllSources());
40
41 browser_view->browser()->tabstrip_model()->AddObserver(this);
38 } 42 }
39 43
40 TouchBrowserFrameView::~TouchBrowserFrameView() { 44 TouchBrowserFrameView::~TouchBrowserFrameView() {
45 browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
41 } 46 }
42 47
43 void TouchBrowserFrameView::Layout() { 48 void TouchBrowserFrameView::Layout() {
44 OpaqueBrowserFrameView::Layout(); 49 OpaqueBrowserFrameView::Layout();
45 50
46 if (!keyboard_) 51 if (!keyboard_)
47 return; 52 return;
48 53
49 keyboard_->SetVisible(keyboard_showing_); 54 keyboard_->SetVisible(keyboard_showing_);
50 keyboard_->SetBounds(GetBoundsForReservedArea()); 55 keyboard_->SetBounds(GetBoundsForReservedArea());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 96
92 // The keyboard that pops up may end up hiding the text entry. So make sure 97 // 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. 98 // the renderer scrolls when necessary to keep the textfield visible.
94 if (keyboard_showing_) { 99 if (keyboard_showing_) {
95 RenderViewHost* host = 100 RenderViewHost* host =
96 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); 101 browser_view()->browser()->GetSelectedTabContents()->render_view_host();
97 host->ScrollFocusedEditableNodeIntoView(); 102 host->ScrollFocusedEditableNodeIntoView();
98 } 103 }
99 } 104 }
100 105
106 void TouchBrowserFrameView::TabSelectedAt(TabContentsWrapper* old_contents,
107 TabContentsWrapper* new_contents,
108 int index,
109 bool user_gesture) {
110 TabContents* contents = new_contents->tab_contents();
111 UpdateKeyboardAndLayout(contents->focused_field_is_editable());
112 }
113
114
101 void TouchBrowserFrameView::Observe(NotificationType type, 115 void TouchBrowserFrameView::Observe(NotificationType type,
102 const NotificationSource& source, 116 const NotificationSource& source,
103 const NotificationDetails& details) { 117 const NotificationDetails& details) {
104 Browser* browser = browser_view()->browser(); 118 Browser* browser = browser_view()->browser();
105 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { 119 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) {
106 // Only modify the keyboard state if the currently active tab sent the 120 // Only modify the keyboard state if the currently active tab sent the
107 // notification. 121 // notification.
108 const TabContents* tab_contents = browser->GetSelectedTabContents(); 122 const TabContents* tab_contents = browser->GetSelectedTabContents();
109 if (tab_contents && 123 if (tab_contents &&
110 tab_contents->render_view_host() == 124 tab_contents->render_view_host() ==
111 Source<RenderViewHost>(source).ptr()) 125 Source<RenderViewHost>(source).ptr())
112 UpdateKeyboardAndLayout(*Details<const bool>(details).ptr()); 126 UpdateKeyboardAndLayout(*Details<const bool>(details).ptr());
113 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { 127 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) {
114 Browser* source_browser = Browser::GetBrowserForController( 128 Browser* source_browser = Browser::GetBrowserForController(
115 Source<NavigationController>(source).ptr(), NULL); 129 Source<NavigationController>(source).ptr(), NULL);
116 // If the Browser for the keyboard has navigated, hide the keyboard. 130 // If the Browser for the keyboard has navigated, hide the keyboard.
117 if (source_browser == browser) 131 if (source_browser == browser)
118 UpdateKeyboardAndLayout(false); 132 UpdateKeyboardAndLayout(false);
119 } 133 }
120 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698