summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 17:26:34 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 17:26:34 +0000
commit8c66c5ae2f67738941f4476fd7d5111a89c337ba (patch)
treec18d8c1e0e4f707c51554558466cb74204a1b393
parent1abd61f7cb060fb1e5ccd1546ac1aa157a1801a5 (diff)
downloadchromium_src-8c66c5ae2f67738941f4476fd7d5111a89c337ba.zip
chromium_src-8c66c5ae2f67738941f4476fd7d5111a89c337ba.tar.gz
chromium_src-8c66c5ae2f67738941f4476fd7d5111a89c337ba.tar.bz2
Make scrollbars and other controls tint/untint upon main window gaining
focus on Mac. This entails the following: - getting notifications that the main window has become or lost key window status (in BrowserWindowController) [new] - ... which tells the RenderWidgetHostView(Mac) to (de)activate [new] - ... which tells the RenderWidgetHost to (de)activate [new] - ... which sends a ViewMsg_SetActive message [new message] to the RenderView [new] - ... which tells the WebView(Impl) to (de)activate [new] - ... which tells its page()'s FocusController to (de)activate [new] - ... which is now in WebKit-land. N.B.: "Activate" is the nomenclature used in WebKit; "focus"/"blur" can sometimes (kind of) mean the same thing, but is ambiguous, since "focus" has a more specific meaning. Added a WebView unit test, which currently only tests to make sure that SetActive() (and IsActive() [also new]) work correctly. The changes to the other classes aren't very testable since they don't actually do anything (other than pass things along). BUG=12507 TEST=webkit/glue/webkit_unittest.cc Patch by viettrungluu@gmail.com (see http://codereview.chromium.org/159048 ), r=avi git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21284 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--AUTHORS1
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm23
-rw-r--r--chrome/browser/renderer_host/render_widget_host.cc4
-rw-r--r--chrome/browser/renderer_host/render_widget_host.h3
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view.h3
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.h1
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.mm5
-rw-r--r--chrome/browser/renderer_host/test/test_render_view_host.cc4
-rw-r--r--chrome/browser/renderer_host/test/test_render_view_host.h1
-rw-r--r--chrome/common/render_messages_internal.h5
-rw-r--r--chrome/renderer/render_view.cc6
-rw-r--r--chrome/renderer/render_view.h5
-rw-r--r--webkit/glue/webview.h6
-rw-r--r--webkit/glue/webview_impl.cc11
-rw-r--r--webkit/glue/webview_impl.h3
-rw-r--r--webkit/glue/webview_unittest.cc26
-rw-r--r--webkit/tools/test_shell/test_shell.gyp1
17 files changed, 107 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index bec4735..576a7ab 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -44,3 +44,4 @@ Jacob Mandelson <jacob@mandelson.org>
Yuri Gorobets <yuri.gorobets@gmail.com>
Paul Wicks <pwicks86@gmail.com>
Thiago Farina <thiago.farina@gmail.com>
+Viet-Trung Luu <viettrungluu@gmail.com>
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index f016420..30054d0 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -14,6 +14,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/encoding_menu_controller.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/browser/tabs/tab_strip_model.h"
@@ -310,6 +311,28 @@ willPositionSheet:(NSWindow*)sheet
[self applyTheme];
}
+// Called when we are activated (when we gain focus).
+- (void)windowDidBecomeKey:(NSNotification*)notification {
+ // We need to activate the controls (in the "WebView"). To do this, get the
+ // selected TabContents's RenderWidgetHostViewMac and tell it to activate.
+ if (TabContents* contents = browser_->GetSelectedTabContents()) {
+ if (RenderWidgetHostView* rwhv = contents->render_widget_host_view())
+ rwhv->SetActive(true);
+ }
+}
+
+// Called when we are deactivated (when we lose focus).
+- (void)windowDidResignKey:(NSNotification*)notification {
+ // We need to deactivate the controls (in the "WebView"). To do this, get the
+ // selected TabContents's RenderWidgetHostView and tell it to deactivate.
+ if (TabContents* contents = browser_->GetSelectedTabContents()) {
+ if (RenderWidgetHostView* rwhv = contents->render_widget_host_view())
+ rwhv->SetActive(false);
+ }
+}
+
+
+
// Called when the user clicks the zoom button (or selects it from the Window
// menu). Zoom to the appropriate size based on the content. Make sure we
// enforce a minimum width to ensure websites with small intrinsic widths
diff --git a/chrome/browser/renderer_host/render_widget_host.cc b/chrome/browser/renderer_host/render_widget_host.cc
index 8328d02..8328d60 100644
--- a/chrome/browser/renderer_host/render_widget_host.cc
+++ b/chrome/browser/renderer_host/render_widget_host.cc
@@ -488,6 +488,10 @@ gfx::Rect RenderWidgetHost::GetRootWindowResizerRect() const {
return gfx::Rect();
}
+void RenderWidgetHost::SetActive(bool active) {
+ Send(new ViewMsg_SetActive(routing_id(), active));
+}
+
void RenderWidgetHost::Destroy() {
NotificationService::current()->Notify(
NotificationType::RENDER_WIDGET_HOST_DESTROYED,
diff --git a/chrome/browser/renderer_host/render_widget_host.h b/chrome/browser/renderer_host/render_widget_host.h
index 74fe24e..b1e6e8a 100644
--- a/chrome/browser/renderer_host/render_widget_host.h
+++ b/chrome/browser/renderer_host/render_widget_host.h
@@ -328,6 +328,9 @@ class RenderWidgetHost : public IPC::Channel::Listener,
// And to also expose it to the RenderWidgetHostView.
virtual gfx::Rect GetRootWindowResizerRect() const;
+ // Sets the active state (i.e., control tints).
+ virtual void SetActive(bool active);
+
protected:
// Internal implementation of the public Forward*Event() methods.
void ForwardInputEvent(
diff --git a/chrome/browser/renderer_host/render_widget_host_view.h b/chrome/browser/renderer_host/render_widget_host_view.h
index 5685067..31f1f64 100644
--- a/chrome/browser/renderer_host/render_widget_host_view.h
+++ b/chrome/browser/renderer_host/render_widget_host_view.h
@@ -155,6 +155,9 @@ class RenderWidgetHostView {
// Get the view's window's position on the screen.
virtual gfx::Rect GetRootWindowRect() = 0;
+
+ // Set the view's active state (i.e., tint state of controls).
+ virtual void SetActive(bool active) = 0;
#endif
#if defined(OS_LINUX)
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h
index 6c705db..a693377 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.h
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h
@@ -105,6 +105,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
const std::vector<WebMenuItem>& items);
virtual gfx::Rect GetWindowRect();
virtual gfx::Rect GetRootWindowRect();
+ virtual void SetActive(bool active);
void KillSelf();
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
index 6585c76..21345e3 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
@@ -381,6 +381,11 @@ gfx::Rect RenderWidgetHostViewMac::GetRootWindowRect() {
return NSRectToRect(bounds, [[cocoa_view_ window] screen]);
}
+void RenderWidgetHostViewMac::SetActive(bool active) {
+ if (render_widget_host_)
+ render_widget_host_->SetActive(active);
+}
+
// RenderWidgetHostViewCocoa ---------------------------------------------------
diff --git a/chrome/browser/renderer_host/test/test_render_view_host.cc b/chrome/browser/renderer_host/test/test_render_view_host.cc
index b682916..b527eae 100644
--- a/chrome/browser/renderer_host/test/test_render_view_host.cc
+++ b/chrome/browser/renderer_host/test/test_render_view_host.cc
@@ -85,6 +85,10 @@ gfx::Rect TestRenderWidgetHostView::GetWindowRect() {
gfx::Rect TestRenderWidgetHostView::GetRootWindowRect() {
return gfx::Rect();
}
+
+void TestRenderWidgetHostView::SetActive(bool active) {
+ // <viettrungluu@gmail.com>: Do I need to do anything here?
+}
#endif
void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) {
diff --git a/chrome/browser/renderer_host/test/test_render_view_host.h b/chrome/browser/renderer_host/test/test_render_view_host.h
index aa24b0c..6ea898b 100644
--- a/chrome/browser/renderer_host/test/test_render_view_host.h
+++ b/chrome/browser/renderer_host/test/test_render_view_host.h
@@ -79,6 +79,7 @@ class TestRenderWidgetHostView : public RenderWidgetHostView {
const std::vector<WebMenuItem>& items) {}
virtual gfx::Rect GetWindowRect();
virtual gfx::Rect GetRootWindowRect();
+ virtual void SetActive(bool active);
#endif
#if defined(OS_LINUX)
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 301bf34..040cd11 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -594,6 +594,11 @@ IPC_BEGIN_MESSAGES(View)
// width.
IPC_MESSAGE_ROUTED0(ViewMsg_EnableIntrinsicWidthChangedMode)
+ // Activate/deactivate the RenderView (i.e., set its controls' tint
+ // accordingly, etc.).
+ IPC_MESSAGE_ROUTED1(ViewMsg_SetActive,
+ bool /* active */)
+
//---------------------------------------------------------------------------
// Utility process messages:
// These are messages from the browser to the utility process. They're here
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 22671ce..34a415f 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -423,6 +423,7 @@ void RenderView::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_EnableIntrinsicWidthChangedMode,
OnEnableIntrinsicWidthChangedMode)
IPC_MESSAGE_HANDLER(ViewMsg_SetRendererPrefs, OnSetRendererPrefs)
+ IPC_MESSAGE_HANDLER(ViewMsg_SetActive, OnSetActive)
// Have the super handle all other messages.
IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
@@ -2845,6 +2846,11 @@ void RenderView::OnSetBackground(const SkBitmap& background) {
SetBackground(background);
}
+void RenderView::OnSetActive(bool active) {
+ if (webview())
+ webview()->SetActive(active);
+}
+
void RenderView::SendExtensionRequest(const std::string& name,
const std::string& args,
int request_id,
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 9d8705a..7624620 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -380,7 +380,6 @@ class RenderView : public RenderWidget,
// RenderWidget override.
virtual void OnResize(const gfx::Size& new_size,
const gfx::Rect& resizer_rect);
-
// RenderWidget override
virtual void DidPaint();
@@ -587,6 +586,10 @@ class RenderView : public RenderWidget,
// a custom background.
void OnSetBackground(const SkBitmap& background);
+ // Activate/deactivate the RenderView (i.e., set its controls' tint
+ // accordingly, etc.).
+ void OnSetActive(bool active);
+
// Attempt to upload the file that we are trying to process if any.
// Reset the pending file upload data if the form was successfully
// posted.
diff --git a/webkit/glue/webview.h b/webkit/glue/webview.h
index 81d0094..565143d 100644
--- a/webkit/glue/webview.h
+++ b/webkit/glue/webview.h
@@ -230,6 +230,12 @@ class WebView : public WebKit::WebWidget {
virtual void SetIsTransparent(bool is_transparent) = 0;
virtual bool GetIsTransparent() const = 0;
+ // Updates the WebView's active state (i.e., control tints).
+ virtual void SetActive(bool active) = 0;
+
+ // Gets the WebView's active state (i.e., state of control tints).
+ virtual bool IsActive() = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(WebView);
};
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc
index 0556ac8..04c18ef 100644
--- a/webkit/glue/webview_impl.cc
+++ b/webkit/glue/webview_impl.cc
@@ -1796,6 +1796,17 @@ bool WebViewImpl::GetIsTransparent() const {
return is_transparent_;
}
+void WebViewImpl::SetActive(bool active) {
+ if (page() && page()->focusController())
+ page()->focusController()->setActive(active);
+}
+
+bool WebViewImpl::IsActive() {
+ return (page() && page()->focusController())
+ ? page()->focusController()->isActive()
+ : false;
+}
+
void WebViewImpl::DidCommitLoad(bool* is_new_navigation) {
if (is_new_navigation)
*is_new_navigation = observed_new_navigation_;
diff --git a/webkit/glue/webview_impl.h b/webkit/glue/webview_impl.h
index 6c2f883..92dd080 100644
--- a/webkit/glue/webview_impl.h
+++ b/webkit/glue/webview_impl.h
@@ -131,6 +131,9 @@ class WebViewImpl : public WebView, public base::RefCounted<WebViewImpl> {
virtual void SetIsTransparent(bool is_transparent);
virtual bool GetIsTransparent() const;
+ virtual void SetActive(bool active);
+ virtual bool IsActive();
+
// WebViewImpl
const WebKit::WebPoint& last_mouse_down_point() const {
diff --git a/webkit/glue/webview_unittest.cc b/webkit/glue/webview_unittest.cc
new file mode 100644
index 0000000..c3ae5c2
--- /dev/null
+++ b/webkit/glue/webview_unittest.cc
@@ -0,0 +1,26 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/glue/webview.h"
+#include "webkit/tools/test_shell/test_shell_test.h"
+
+class WebViewTest : public TestShellTest {
+};
+
+TEST_F(WebViewTest, GetContentAsPlainText) {
+ WebView* view = test_shell_->webView();
+ ASSERT_TRUE(view != 0);
+
+ view->SetActive(true);
+ EXPECT_TRUE(view->IsActive());
+
+ view->SetActive(false);
+ EXPECT_FALSE(view->IsActive());
+
+ view->SetActive(true);
+ EXPECT_TRUE(view->IsActive());
+}
+
+// TODO(viettrungluu): add more tests
diff --git a/webkit/tools/test_shell/test_shell.gyp b/webkit/tools/test_shell/test_shell.gyp
index 8313eff..2746641 100644
--- a/webkit/tools/test_shell/test_shell.gyp
+++ b/webkit/tools/test_shell/test_shell.gyp
@@ -475,6 +475,7 @@
'../../glue/resource_fetcher_unittest.cc',
'../../glue/unittest_test_server.h',
'../../glue/webcursor_unittest.cc',
+ '../../glue/webview_unittest.cc',
'../../glue/webframe_unittest.cc',
'../../glue/webplugin_impl_unittest.cc',
'../webcore_unit_tests/BMPImageDecoder_unittest.cpp',