diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 22:27:21 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 22:27:21 +0000 |
commit | 4e85c1127c87f1a9b9dd47292eea9bf36bb763a2 (patch) | |
tree | 2cc9cb42516de16c901463de6fa75db814cf0728 /chrome/browser/ui | |
parent | 64cd59ca5e1113b67a4728acf9d35cdcf009f7a2 (diff) | |
download | chromium_src-4e85c1127c87f1a9b9dd47292eea9bf36bb763a2.zip chromium_src-4e85c1127c87f1a9b9dd47292eea9bf36bb763a2.tar.gz chromium_src-4e85c1127c87f1a9b9dd47292eea9bf36bb763a2.tar.bz2 |
keyboard: Update the visibility after tab-switch.
BUG=70784
TEST=manually, see bug
Review URL: http://codereview.chromium.org/6277020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72705 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/touch/frame/touch_browser_frame_view.cc | 44 | ||||
-rw-r--r-- | chrome/browser/ui/touch/frame/touch_browser_frame_view.h | 8 |
2 files changed, 47 insertions, 5 deletions
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 545f31c..3838b4f 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) { @@ -105,16 +129,26 @@ void TouchBrowserFrameView::Observe(NotificationType type, if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { // 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()); + const TabContents* current_tab = browser->GetSelectedTabContents(); + TabContents* source_tab = Source<TabContents>(source).ptr(); + const bool editable = *Details<const bool>(details).ptr(); + + if (current_tab == source_tab) { + UpdateKeyboardAndLayout(editable); + } + + // Save the state of the focused field so that the keyboard visibility + // can be determined after tab switching. + 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()); } } diff --git a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h index 35da0b5..c06600f 100644 --- a/chrome/browser/ui/touch/frame/touch_browser_frame_view.h +++ b/chrome/browser/ui/touch/frame/touch_browser_frame_view.h @@ -7,6 +7,7 @@ #pragma once #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" +#include "chrome/browser/tabs/tab_strip_model_observer.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" @@ -17,6 +18,7 @@ class NotificationDetails; class NotificationSource; class TouchBrowserFrameView : public OpaqueBrowserFrameView, + public TabStripModelObserver, public NotificationObserver { public: // Constructs a non-client view for an BrowserFrame. @@ -34,6 +36,12 @@ class TouchBrowserFrameView : public OpaqueBrowserFrameView, virtual void InitVirtualKeyboard(); virtual void UpdateKeyboardAndLayout(bool should_show_keyboard); + // Overrridden from TabStripModelObserver. + virtual void TabSelectedAt(TabContentsWrapper* old_contents, + TabContentsWrapper* new_contents, + int index, + bool user_gesture); + // Overridden from NotificationObserver. virtual void Observe(NotificationType type, const NotificationSource& source, |