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 |
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); | |
sky
2011/01/25 19:15:21
You need to remove this observer at some point.
sadrul
2011/01/25 21:11:50
Done.
| |
38 } | 42 } |
39 | 43 |
40 TouchBrowserFrameView::~TouchBrowserFrameView() { | 44 TouchBrowserFrameView::~TouchBrowserFrameView() { |
41 } | 45 } |
42 | 46 |
43 void TouchBrowserFrameView::Layout() { | 47 void TouchBrowserFrameView::Layout() { |
44 OpaqueBrowserFrameView::Layout(); | 48 OpaqueBrowserFrameView::Layout(); |
45 | 49 |
46 if (!keyboard_) | 50 if (!keyboard_) |
47 return; | 51 return; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 | 95 |
92 // The keyboard that pops up may end up hiding the text entry. So make sure | 96 // 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. | 97 // the renderer scrolls when necessary to keep the textfield visible. |
94 if (keyboard_showing_) { | 98 if (keyboard_showing_) { |
95 RenderViewHost* host = | 99 RenderViewHost* host = |
96 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); | 100 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); |
97 host->ScrollFocusedEditableNodeIntoView(); | 101 host->ScrollFocusedEditableNodeIntoView(); |
98 } | 102 } |
99 } | 103 } |
100 | 104 |
105 void TouchBrowserFrameView::TabSelectedAt(TabContentsWrapper* old_contents, | |
106 TabContentsWrapper* new_contents, | |
107 int index, | |
108 bool user_gesture) { | |
109 TabContents* contents = new_contents->tab_contents(); | |
110 UpdateKeyboardAndLayout(contents->selected_field_is_editable()); | |
111 } | |
112 | |
113 | |
101 void TouchBrowserFrameView::Observe(NotificationType type, | 114 void TouchBrowserFrameView::Observe(NotificationType type, |
102 const NotificationSource& source, | 115 const NotificationSource& source, |
103 const NotificationDetails& details) { | 116 const NotificationDetails& details) { |
104 Browser* browser = browser_view()->browser(); | 117 Browser* browser = browser_view()->browser(); |
105 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { | 118 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { |
106 // Only modify the keyboard state if the currently active tab sent the | 119 // Only modify the keyboard state if the currently active tab sent the |
107 // notification. | 120 // notification. |
108 const TabContents* tab_contents = browser->GetSelectedTabContents(); | 121 const TabContents* tab_contents = browser->GetSelectedTabContents(); |
109 if (tab_contents && | 122 if (tab_contents && |
110 tab_contents->render_view_host() == | 123 tab_contents->render_view_host() == |
111 Source<RenderViewHost>(source).ptr()) | 124 Source<RenderViewHost>(source).ptr()) |
112 UpdateKeyboardAndLayout(*Details<const bool>(details).ptr()); | 125 UpdateKeyboardAndLayout(*Details<const bool>(details).ptr()); |
113 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { | 126 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { |
114 Browser* source_browser = Browser::GetBrowserForController( | 127 Browser* source_browser = Browser::GetBrowserForController( |
115 Source<NavigationController>(source).ptr(), NULL); | 128 Source<NavigationController>(source).ptr(), NULL); |
116 // If the Browser for the keyboard has navigated, hide the keyboard. | 129 // If the Browser for the keyboard has navigated, hide the keyboard. |
117 if (source_browser == browser) | 130 if (source_browser == browser) |
118 UpdateKeyboardAndLayout(false); | 131 UpdateKeyboardAndLayout(false); |
119 } | 132 } |
120 } | 133 } |
OLD | NEW |