Index: chrome/browser/ui/touch/frame/touch_browser_frame_view.cc |
diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc |
index 545f31cc28923a2116a3dff889799778bdae21da..6362353be30201d5c7a6bfa1fb50c4f9a2294aa9 100644 |
--- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc |
+++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.cc |
@@ -8,7 +8,9 @@ |
#include "chrome/browser/renderer_host/render_view_host.h" |
#include "chrome/browser/tab_contents/navigation_controller.h" |
#include "chrome/browser/tab_contents/tab_contents.h" |
+#include "chrome/browser/tabs/tab_strip_model.h" |
#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
#include "chrome/browser/ui/touch/frame/keyboard_container_view.h" |
#include "chrome/browser/ui/views/frame/browser_view.h" |
#include "chrome/common/notification_service.h" |
@@ -19,6 +21,11 @@ namespace { |
const int kKeyboardHeight = 300; |
+PropertyAccessor<bool>* GetFocusedStateAccessor() { |
+ static PropertyAccessor<bool> state; |
+ return &state; |
+} |
+ |
} // namespace |
/////////////////////////////////////////////////////////////////////////////// |
@@ -35,9 +42,15 @@ TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, |
registrar_.Add(this, |
NotificationType::FOCUS_CHANGED_IN_PAGE, |
NotificationService::AllSources()); |
+ registrar_.Add(this, |
+ NotificationType::TAB_CONTENTS_DESTROYED, |
+ NotificationService::AllSources()); |
+ |
+ browser_view->browser()->tabstrip_model()->AddObserver(this); |
} |
TouchBrowserFrameView::~TouchBrowserFrameView() { |
+ browser_view()->browser()->tabstrip_model()->RemoveObserver(this); |
} |
void TouchBrowserFrameView::Layout() { |
@@ -98,6 +111,17 @@ void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) { |
} |
} |
+void TouchBrowserFrameView::TabSelectedAt(TabContentsWrapper* old_contents, |
+ TabContentsWrapper* new_contents, |
+ int index, |
+ bool user_gesture) { |
+ TabContents* contents = new_contents->tab_contents(); |
+ bool* editable = GetFocusedStateAccessor()->GetProperty( |
+ contents->property_bag()); |
+ UpdateKeyboardAndLayout(editable ? *editable : false); |
+} |
+ |
+ |
void TouchBrowserFrameView::Observe(NotificationType type, |
const NotificationSource& source, |
const NotificationDetails& details) { |
@@ -106,15 +130,26 @@ void TouchBrowserFrameView::Observe(NotificationType type, |
// Only modify the keyboard state if the currently active tab sent the |
// notification. |
const TabContents* tab_contents = browser->GetSelectedTabContents(); |
- if (tab_contents && |
- tab_contents->render_view_host() == |
- Source<RenderViewHost>(source).ptr()) |
- UpdateKeyboardAndLayout(*Details<const bool>(details).ptr()); |
+ RenderViewHost* host = Source<RenderViewHost>(source).ptr(); |
+ const bool editable = *Details<const bool>(details).ptr(); |
+ |
+ if (tab_contents && tab_contents->render_view_host() == host) { |
+ UpdateKeyboardAndLayout(editable); |
+ } |
+ |
+ // Save the state of the focused field so that the keyboard visibility |
+ // can be determined after tab switching. |
+ TabContents* source_tab = static_cast<TabContents*>(host->delegate()); |
sky
2011/01/26 18:07:43
Casts like this are dangerous. Could we change FOC
brettw
2011/01/26 20:18:07
I agree, we should never have this type of cast.
|
+ GetFocusedStateAccessor()->SetProperty( |
+ source_tab->property_bag(), editable); |
} else if (type == NotificationType::NAV_ENTRY_COMMITTED) { |
Browser* source_browser = Browser::GetBrowserForController( |
Source<NavigationController>(source).ptr(), NULL); |
// If the Browser for the keyboard has navigated, hide the keyboard. |
if (source_browser == browser) |
UpdateKeyboardAndLayout(false); |
+ } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { |
+ GetFocusedStateAccessor()->DeleteProperty( |
+ Source<TabContents>(source).ptr()->property_bag()); |
sadrul
2011/01/26 17:43:10
Or should this be done from TabDetachedAt and TabR
sky
2011/01/26 18:07:43
This is better.
|
} |
} |