diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-30 01:18:53 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-30 01:18:53 +0000 |
commit | 1c9b850eb0957f322756bc4bfcfbd0065bf27a49 (patch) | |
tree | 2c2ad174afe3f9fbb040272b46bb04955d3638b9 | |
parent | 735fa6fa1662461f9857edc8a1f0abe056b4f61e (diff) | |
download | chromium_src-1c9b850eb0957f322756bc4bfcfbd0065bf27a49.zip chromium_src-1c9b850eb0957f322756bc4bfcfbd0065bf27a49.tar.gz chromium_src-1c9b850eb0957f322756bc4bfcfbd0065bf27a49.tar.bz2 |
[Mac] Modify -[AcceleratedPluginView acceptsFirstResponder] to check if its superview accepts first responder.
BUG=64256
TEST=Turn on instant. Type homestarrunner.com into the omnibox. Click on the plugin. Instant results should commit.
TEST=Should not regress Issue 60318. See test case in that bug.
Review URL: http://codereview.chromium.org/5347002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67643 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm | 113 |
2 files changed, 99 insertions, 21 deletions
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 d37ad89..1afe94c 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -466,8 +466,11 @@ static CVReturn DrawOneAcceleratedPluginCallback( } - (BOOL)acceptsFirstResponder { - // Accept first responder if the first responder isn't the RWHVMac. - return [[self window] firstResponder] != [self superview]; + // Accept first responder if the first responder isn't the RWHVMac, and if the + // RWHVMac accepts first responder. If the RWHVMac does not accept first + // responder, do not accept on its behalf. + return ([[self window] firstResponder] != [self superview] && + [[self superview] acceptsFirstResponder]); } - (BOOL)becomeFirstResponder { diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm b/chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm index de84d07..7ae9e25 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac_unittest.mm @@ -6,6 +6,7 @@ #include "chrome/browser/browser_thread.h" #import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "chrome/browser/cocoa/test_event_utils.h" #include "chrome/browser/renderer_host/test/test_render_view_host.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,6 +24,33 @@ class RenderWidgetHostViewMacTest : public RenderViewHostTestHarness { rwhv_cocoa_ = [rwhv_mac_->native_view() retain]; } protected: + // Adds an accelerated plugin view to |rwhv_cocoa_|. Returns a handle to the + // newly-added view. Callers must ensure that a UI thread is present and + // running before calling this function. + gfx::PluginWindowHandle AddAcceleratedPluginView(int w, int h) { + // Create an accelerated view the size of the rhwvmac. + [rwhv_cocoa_ setFrame:NSMakeRect(0, 0, w, h)]; + gfx::PluginWindowHandle accelerated_handle = + rwhv_mac_->AllocateFakePluginWindowHandle(/*opaque=*/false, + /*root=*/false); + rwhv_mac_->AcceleratedSurfaceSetIOSurface(accelerated_handle, w, h, 0); + + // The accelerated view isn't shown until it has a valid rect and has been + // painted to. + rwhv_mac_->AcceleratedSurfaceBuffersSwapped(accelerated_handle, 0, 0, 0, 0); + webkit_glue::WebPluginGeometry geom; + gfx::Rect rect(0, 0, w, h); + geom.window = accelerated_handle; + geom.window_rect = rect; + geom.clip_rect = rect; + geom.visible = true; + geom.rects_valid = true; + rwhv_mac_->MovePluginWindows( + std::vector<webkit_glue::WebPluginGeometry>(1, geom)); + + return accelerated_handle; + } + RenderWidgetHostViewMac* rwhv_mac_; RenderWidgetHostViewCocoa* rwhv_cocoa_; @@ -39,25 +67,7 @@ TEST_F(RenderWidgetHostViewMacTest, FocusAcceleratedView) { new BrowserThread(BrowserThread::UI, MessageLoop::current())); int w = 400, h = 300; - // Create an accelerated view the size of the rhwvmac. - [rwhv_cocoa_ setFrame:NSMakeRect(0, 0, w, h)]; - gfx::PluginWindowHandle accelerated_handle = - rwhv_mac_->AllocateFakePluginWindowHandle(/*opaque=*/false, - /*root=*/false); - rwhv_mac_->AcceleratedSurfaceSetIOSurface(accelerated_handle, w, h, 0); - - // The accelerated view isn't shown until it has a valid rect and has been - // painted to. - rwhv_mac_->AcceleratedSurfaceBuffersSwapped(accelerated_handle, 0, 0, 0, 0); - webkit_glue::WebPluginGeometry geom; - gfx::Rect rect(0, 0, w, h); - geom.window = accelerated_handle; - geom.window_rect = rect; - geom.clip_rect = rect; - geom.visible = true; - geom.rects_valid = true; - rwhv_mac_->MovePluginWindows( - std::vector<webkit_glue::WebPluginGeometry>(1, geom)); + gfx::PluginWindowHandle accelerated_handle = AddAcceleratedPluginView(w, h); EXPECT_FALSE([rwhv_cocoa_ isHidden]); NSView* accelerated_view = static_cast<NSView*>( rwhv_mac_->ViewForPluginWindowHandle(accelerated_handle)); @@ -88,3 +98,68 @@ TEST_F(RenderWidgetHostViewMacTest, FocusAcceleratedView) { // Clean up. rwhv_mac_->DestroyFakePluginWindowHandle(accelerated_handle); } + +TEST_F(RenderWidgetHostViewMacTest, AcceptsFirstResponder) { + // The RWHVCocoa should normally accept first responder status. + EXPECT_TRUE([rwhv_cocoa_ acceptsFirstResponder]); + + // Unless we tell it not to. + rwhv_mac_->SetTakesFocusOnlyOnMouseDown(true); + EXPECT_FALSE([rwhv_cocoa_ acceptsFirstResponder]); + + // But we can set things back to the way they were originally. + rwhv_mac_->SetTakesFocusOnlyOnMouseDown(false); + EXPECT_TRUE([rwhv_cocoa_ acceptsFirstResponder]); +} + +TEST_F(RenderWidgetHostViewMacTest, TakesFocusOnMouseDown) { + scoped_nsobject<NSWindow> window([[CocoaTestHelperWindow alloc] init]); + [[window contentView] addSubview:rwhv_cocoa_]; + + // Even if the RWHVCocoa disallows first responder, clicking on it gives it + // focus. + [window makeFirstResponder:nil]; + ASSERT_NE(rwhv_cocoa_, [window firstResponder]); + + rwhv_mac_->SetTakesFocusOnlyOnMouseDown(true); + EXPECT_FALSE([rwhv_cocoa_ acceptsFirstResponder]); + + std::pair<NSEvent*, NSEvent*> clicks = + test_event_utils::MouseClickInView(rwhv_cocoa_, 1); + [rwhv_cocoa_ mouseDown:clicks.first]; + EXPECT_EQ(rwhv_cocoa_, [window firstResponder]); +} + +// Regression test for http://crbug.com/64256 +TEST_F(RenderWidgetHostViewMacTest, TakesFocusOnMouseDownWithAcceleratedView) { + // The accelerated view methods want to be called on the UI thread. + scoped_ptr<BrowserThread> ui_thread_( + new BrowserThread(BrowserThread::UI, MessageLoop::current())); + + int w = 400, h = 300; + gfx::PluginWindowHandle accelerated_handle = AddAcceleratedPluginView(w, h); + EXPECT_FALSE([rwhv_cocoa_ isHidden]); + NSView* accelerated_view = static_cast<NSView*>( + rwhv_mac_->ViewForPluginWindowHandle(accelerated_handle)); + EXPECT_FALSE([accelerated_view isHidden]); + + // Add the RWHVCocoa to the window and remove first responder status. + scoped_nsobject<NSWindow> window([[CocoaTestHelperWindow alloc] init]); + [[window contentView] addSubview:rwhv_cocoa_]; + [window makeFirstResponder:nil]; + EXPECT_NE(rwhv_cocoa_, [window firstResponder]); + + // Tell the RWHVMac to not accept first responder status. The accelerated + // view should also stop accepting first responder. + rwhv_mac_->SetTakesFocusOnlyOnMouseDown(true); + EXPECT_FALSE([accelerated_view acceptsFirstResponder]); + + // A click on the accelerated view should focus the RWHVCocoa. + std::pair<NSEvent*, NSEvent*> clicks = + test_event_utils::MouseClickInView(accelerated_view, 1); + [rwhv_cocoa_ mouseDown:clicks.first]; + EXPECT_EQ(rwhv_cocoa_, [window firstResponder]); + + // Clean up. + rwhv_mac_->DestroyFakePluginWindowHandle(accelerated_handle); +} |