Commit 4e85c112 authored by sadrul@chromium.org's avatar sadrul@chromium.org

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
parent 64cd59ca
...@@ -154,12 +154,16 @@ class TestInterstitialPage : public InterstitialPage { ...@@ -154,12 +154,16 @@ class TestInterstitialPage : public InterstitialPage {
return html_contents_; return html_contents_;
} }
// Exposing render_view_host() to be public; it is declared as protected in // Exposing render_view_host() and tab() to be public; they are declared as
// the superclass. // protected in the superclass.
virtual RenderViewHost* render_view_host() { virtual RenderViewHost* render_view_host() {
return InterstitialPage::render_view_host(); return InterstitialPage::render_view_host();
} }
virtual TabContents* tab() {
return InterstitialPage::tab();
}
bool HasFocus() { bool HasFocus() {
return render_view_host()->view()->HasFocus(); return render_view_host()->view()->HasFocus();
} }
...@@ -168,7 +172,7 @@ class TestInterstitialPage : public InterstitialPage { ...@@ -168,7 +172,7 @@ class TestInterstitialPage : public InterstitialPage {
virtual void FocusedNodeChanged(bool is_editable_node) { virtual void FocusedNodeChanged(bool is_editable_node) {
NotificationService::current()->Notify( NotificationService::current()->Notify(
NotificationType::FOCUS_CHANGED_IN_PAGE, NotificationType::FOCUS_CHANGED_IN_PAGE,
Source<RenderViewHost>(render_view_host()), Source<TabContents>(tab()),
Details<const bool>(&is_editable_node)); Details<const bool>(&is_editable_node));
} }
...@@ -487,8 +491,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) { ...@@ -487,8 +491,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) {
ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
browser(), ui::VKEY_TAB, false, false, false, false, browser(), ui::VKEY_TAB, false, false, false, false,
NotificationType::FOCUS_CHANGED_IN_PAGE, NotificationType::FOCUS_CHANGED_IN_PAGE,
NotificationSource(Source<RenderViewHost>( NotificationSource(Source<TabContents>(
browser()->GetSelectedTabContents()->render_view_host())), browser()->GetSelectedTabContents())),
details)); details));
} else { } else {
// On the last tab key press, the focus returns to the browser. // On the last tab key press, the focus returns to the browser.
...@@ -526,8 +530,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) { ...@@ -526,8 +530,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) {
ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
browser(), ui::VKEY_TAB, false, true, false, false, browser(), ui::VKEY_TAB, false, true, false, false,
NotificationType::FOCUS_CHANGED_IN_PAGE, NotificationType::FOCUS_CHANGED_IN_PAGE,
NotificationSource(Source<RenderViewHost>( NotificationSource(Source<TabContents>(
browser()->GetSelectedTabContents()->render_view_host())), browser()->GetSelectedTabContents())),
details)); details));
} else { } else {
// On the last tab key press, the focus returns to the browser. // On the last tab key press, the focus returns to the browser.
...@@ -606,8 +610,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { ...@@ -606,8 +610,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
NotificationService::AllSources(); NotificationService::AllSources();
if (j < arraysize(kExpElementIDs) - 1) { if (j < arraysize(kExpElementIDs) - 1) {
notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE;
notification_source = Source<RenderViewHost>( notification_source = Source<TabContents>(
interstitial_page->render_view_host()); interstitial_page->tab());
} else { } else {
// On the last tab key press, the focus returns to the browser. // On the last tab key press, the focus returns to the browser.
notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER;
...@@ -637,8 +641,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { ...@@ -637,8 +641,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
NotificationService::AllSources(); NotificationService::AllSources();
if (j < arraysize(kExpElementIDs) - 1) { if (j < arraysize(kExpElementIDs) - 1) {
notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE;
notification_source = Source<RenderViewHost>( notification_source = Source<TabContents>(
interstitial_page->render_view_host()); interstitial_page->tab());
} else { } else {
// On the last tab key press, the focus returns to the browser. // On the last tab key press, the focus returns to the browser.
notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER;
......
...@@ -3141,7 +3141,7 @@ void TabContents::DidInsertCSS() { ...@@ -3141,7 +3141,7 @@ void TabContents::DidInsertCSS() {
void TabContents::FocusedNodeChanged(bool is_editable_node) { void TabContents::FocusedNodeChanged(bool is_editable_node) {
NotificationService::current()->Notify( NotificationService::current()->Notify(
NotificationType::FOCUS_CHANGED_IN_PAGE, NotificationType::FOCUS_CHANGED_IN_PAGE,
Source<RenderViewHost>(render_view_host()), Source<TabContents>(this),
Details<const bool>(&is_editable_node)); Details<const bool>(&is_editable_node));
} }
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
#include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/tab_contents.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/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/touch/frame/keyboard_container_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/notification_service.h" #include "chrome/common/notification_service.h"
...@@ -19,6 +21,11 @@ namespace { ...@@ -19,6 +21,11 @@ namespace {
const int kKeyboardHeight = 300; const int kKeyboardHeight = 300;
PropertyAccessor<bool>* GetFocusedStateAccessor() {
static PropertyAccessor<bool> state;
return &state;
}
} // namespace } // namespace
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -35,9 +42,15 @@ TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, ...@@ -35,9 +42,15 @@ TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
registrar_.Add(this, registrar_.Add(this,
NotificationType::FOCUS_CHANGED_IN_PAGE, NotificationType::FOCUS_CHANGED_IN_PAGE,
NotificationService::AllSources()); NotificationService::AllSources());
registrar_.Add(this,
NotificationType::TAB_CONTENTS_DESTROYED,
NotificationService::AllSources());
browser_view->browser()->tabstrip_model()->AddObserver(this);
} }
TouchBrowserFrameView::~TouchBrowserFrameView() { TouchBrowserFrameView::~TouchBrowserFrameView() {
browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
} }
void TouchBrowserFrameView::Layout() { void TouchBrowserFrameView::Layout() {
...@@ -98,6 +111,17 @@ void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) { ...@@ -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, void TouchBrowserFrameView::Observe(NotificationType type,
const NotificationSource& source, const NotificationSource& source,
const NotificationDetails& details) { const NotificationDetails& details) {
...@@ -105,16 +129,26 @@ void TouchBrowserFrameView::Observe(NotificationType type, ...@@ -105,16 +129,26 @@ void TouchBrowserFrameView::Observe(NotificationType type,
if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) {
// Only modify the keyboard state if the currently active tab sent the // Only modify the keyboard state if the currently active tab sent the
// notification. // notification.
const TabContents* tab_contents = browser->GetSelectedTabContents(); const TabContents* current_tab = browser->GetSelectedTabContents();
if (tab_contents && TabContents* source_tab = Source<TabContents>(source).ptr();
tab_contents->render_view_host() == const bool editable = *Details<const bool>(details).ptr();
Source<RenderViewHost>(source).ptr())
UpdateKeyboardAndLayout(*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) { } else if (type == NotificationType::NAV_ENTRY_COMMITTED) {
Browser* source_browser = Browser::GetBrowserForController( Browser* source_browser = Browser::GetBrowserForController(
Source<NavigationController>(source).ptr(), NULL); Source<NavigationController>(source).ptr(), NULL);
// If the Browser for the keyboard has navigated, hide the keyboard. // If the Browser for the keyboard has navigated, hide the keyboard.
if (source_browser == browser) if (source_browser == browser)
UpdateKeyboardAndLayout(false); UpdateKeyboardAndLayout(false);
} else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
GetFocusedStateAccessor()->DeleteProperty(
Source<TabContents>(source).ptr()->property_bag());
} }
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" #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_observer.h"
#include "chrome/common/notification_registrar.h" #include "chrome/common/notification_registrar.h"
...@@ -17,6 +18,7 @@ class NotificationDetails; ...@@ -17,6 +18,7 @@ class NotificationDetails;
class NotificationSource; class NotificationSource;
class TouchBrowserFrameView : public OpaqueBrowserFrameView, class TouchBrowserFrameView : public OpaqueBrowserFrameView,
public TabStripModelObserver,
public NotificationObserver { public NotificationObserver {
public: public:
// Constructs a non-client view for an BrowserFrame. // Constructs a non-client view for an BrowserFrame.
...@@ -34,6 +36,12 @@ class TouchBrowserFrameView : public OpaqueBrowserFrameView, ...@@ -34,6 +36,12 @@ class TouchBrowserFrameView : public OpaqueBrowserFrameView,
virtual void InitVirtualKeyboard(); virtual void InitVirtualKeyboard();
virtual void UpdateKeyboardAndLayout(bool should_show_keyboard); 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. // Overridden from NotificationObserver.
virtual void Observe(NotificationType type, virtual void Observe(NotificationType type,
const NotificationSource& source, const NotificationSource& source,
......
...@@ -519,9 +519,10 @@ class NotificationType { ...@@ -519,9 +519,10 @@ class NotificationType {
// guaranteed to be valid after the notification. // guaranteed to be valid after the notification.
WEB_CACHE_STATS_OBSERVED, WEB_CACHE_STATS_OBSERVED,
// The focused element inside a page has changed. The source is the render // The focused element inside a page has changed. The source is the
// view host for the page. The details are a Details<const bool> that // TabContents containing the render view host for the page. The details is
// indicates whether or not an editable node was focused. // a Details<const bool> that indicates whether or not an editable node was
// focused.
FOCUS_CHANGED_IN_PAGE, FOCUS_CHANGED_IN_PAGE,
// Notification posted from ExecuteJavascriptInWebFrameNotifyResult. The // Notification posted from ExecuteJavascriptInWebFrameNotifyResult. The
......
...@@ -612,10 +612,10 @@ void CrashTab(TabContents* tab) { ...@@ -612,10 +612,10 @@ void CrashTab(TabContents* tab) {
Source<RenderProcessHost>(rph)); Source<RenderProcessHost>(rph));
} }
void WaitForFocusChange(RenderViewHost* rvh) { void WaitForFocusChange(TabContents* tab_contents) {
TestNotificationObserver observer; TestNotificationObserver observer;
RegisterAndWait(&observer, NotificationType::FOCUS_CHANGED_IN_PAGE, RegisterAndWait(&observer, NotificationType::FOCUS_CHANGED_IN_PAGE,
Source<RenderViewHost>(rvh)); Source<TabContents>(tab_contents));
} }
void WaitForFocusInBrowser(Browser* browser) { void WaitForFocusInBrowser(Browser* browser) {
......
...@@ -199,8 +199,8 @@ AppModalDialog* WaitForAppModalDialog(); ...@@ -199,8 +199,8 @@ AppModalDialog* WaitForAppModalDialog();
// Causes the specified tab to crash. Blocks until it is crashed. // Causes the specified tab to crash. Blocks until it is crashed.
void CrashTab(TabContents* tab); void CrashTab(TabContents* tab);
// Waits for the focus to change in the specified RenderViewHost. // Waits for the focus to change in the specified tab.
void WaitForFocusChange(RenderViewHost* rvh); void WaitForFocusChange(TabContents* tab_contents);
// Waits for the renderer to return focus to the browser (happens through tab // Waits for the renderer to return focus to the browser (happens through tab
// traversal). // traversal).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment