summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-26 22:27:21 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-26 22:27:21 +0000
commit4e85c1127c87f1a9b9dd47292eea9bf36bb763a2 (patch)
tree2cc9cb42516de16c901463de6fa75db814cf0728 /chrome
parent64cd59ca5e1113b67a4728acf9d35cdcf009f7a2 (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/browser_focus_uitest.cc26
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc2
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.cc44
-rw-r--r--chrome/browser/ui/touch/frame/touch_browser_frame_view.h8
-rw-r--r--chrome/common/notification_type.h7
-rw-r--r--chrome/test/ui_test_utils.cc4
-rw-r--r--chrome/test/ui_test_utils.h4
7 files changed, 71 insertions, 24 deletions
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index 246ccad..9bd27da 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -154,12 +154,16 @@ class TestInterstitialPage : public InterstitialPage {
return html_contents_;
}
- // Exposing render_view_host() to be public; it is declared as protected in
- // the superclass.
+ // Exposing render_view_host() and tab() to be public; they are declared as
+ // protected in the superclass.
virtual RenderViewHost* render_view_host() {
return InterstitialPage::render_view_host();
}
+ virtual TabContents* tab() {
+ return InterstitialPage::tab();
+ }
+
bool HasFocus() {
return render_view_host()->view()->HasFocus();
}
@@ -168,7 +172,7 @@ class TestInterstitialPage : public InterstitialPage {
virtual void FocusedNodeChanged(bool is_editable_node) {
NotificationService::current()->Notify(
NotificationType::FOCUS_CHANGED_IN_PAGE,
- Source<RenderViewHost>(render_view_host()),
+ Source<TabContents>(tab()),
Details<const bool>(&is_editable_node));
}
@@ -487,8 +491,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) {
ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
browser(), ui::VKEY_TAB, false, false, false, false,
NotificationType::FOCUS_CHANGED_IN_PAGE,
- NotificationSource(Source<RenderViewHost>(
- browser()->GetSelectedTabContents()->render_view_host())),
+ NotificationSource(Source<TabContents>(
+ browser()->GetSelectedTabContents())),
details));
} else {
// On the last tab key press, the focus returns to the browser.
@@ -526,8 +530,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversal) {
ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
browser(), ui::VKEY_TAB, false, true, false, false,
NotificationType::FOCUS_CHANGED_IN_PAGE,
- NotificationSource(Source<RenderViewHost>(
- browser()->GetSelectedTabContents()->render_view_host())),
+ NotificationSource(Source<TabContents>(
+ browser()->GetSelectedTabContents())),
details));
} else {
// On the last tab key press, the focus returns to the browser.
@@ -606,8 +610,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
NotificationService::AllSources();
if (j < arraysize(kExpElementIDs) - 1) {
notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE;
- notification_source = Source<RenderViewHost>(
- interstitial_page->render_view_host());
+ notification_source = Source<TabContents>(
+ interstitial_page->tab());
} else {
// On the last tab key press, the focus returns to the browser.
notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER;
@@ -637,8 +641,8 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
NotificationService::AllSources();
if (j < arraysize(kExpElementIDs) - 1) {
notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE;
- notification_source = Source<RenderViewHost>(
- interstitial_page->render_view_host());
+ notification_source = Source<TabContents>(
+ interstitial_page->tab());
} else {
// On the last tab key press, the focus returns to the browser.
notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER;
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index cb494aa..7d1703e 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -3141,7 +3141,7 @@ void TabContents::DidInsertCSS() {
void TabContents::FocusedNodeChanged(bool is_editable_node) {
NotificationService::current()->Notify(
NotificationType::FOCUS_CHANGED_IN_PAGE,
- Source<RenderViewHost>(render_view_host()),
+ Source<TabContents>(this),
Details<const bool>(&is_editable_node));
}
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,
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index fadff2f..ddfe7b3 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -519,9 +519,10 @@ class NotificationType {
// guaranteed to be valid after the notification.
WEB_CACHE_STATS_OBSERVED,
- // The focused element inside a page has changed. The source is the render
- // view host for the page. The details are a Details<const bool> that
- // indicates whether or not an editable node was focused.
+ // The focused element inside a page has changed. The source is the
+ // TabContents containing the render view host for the page. The details is
+ // a Details<const bool> that indicates whether or not an editable node was
+ // focused.
FOCUS_CHANGED_IN_PAGE,
// Notification posted from ExecuteJavascriptInWebFrameNotifyResult. The
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index ad6d8c9..0dd2504 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -612,10 +612,10 @@ void CrashTab(TabContents* tab) {
Source<RenderProcessHost>(rph));
}
-void WaitForFocusChange(RenderViewHost* rvh) {
+void WaitForFocusChange(TabContents* tab_contents) {
TestNotificationObserver observer;
RegisterAndWait(&observer, NotificationType::FOCUS_CHANGED_IN_PAGE,
- Source<RenderViewHost>(rvh));
+ Source<TabContents>(tab_contents));
}
void WaitForFocusInBrowser(Browser* browser) {
diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h
index ad661e9..d6a7cd6 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -199,8 +199,8 @@ AppModalDialog* WaitForAppModalDialog();
// Causes the specified tab to crash. Blocks until it is crashed.
void CrashTab(TabContents* tab);
-// Waits for the focus to change in the specified RenderViewHost.
-void WaitForFocusChange(RenderViewHost* rvh);
+// Waits for the focus to change in the specified tab.
+void WaitForFocusChange(TabContents* tab_contents);
// Waits for the renderer to return focus to the browser (happens through tab
// traversal).