diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-02 04:17:45 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-02 04:17:45 +0000 |
commit | bb2fdf3619b0462a05e864763b2232114c2a140a (patch) | |
tree | 4d8de598ab50cbbd2237f6937ea449aa73016ae5 /content | |
parent | 0487fd9c189d6a9684ea8df076dab6e7394a2d55 (diff) | |
download | chromium_src-bb2fdf3619b0462a05e864763b2232114c2a140a.zip chromium_src-bb2fdf3619b0462a05e864763b2232114c2a140a.tar.gz chromium_src-bb2fdf3619b0462a05e864763b2232114c2a140a.tar.bz2 |
Flash Mac: Fix escape to exit fullscreen
On tmz.com, pressing escape to exit fullscreen Flash would cause the currently playing movie to close.
The problem was that the fullscreen window was closing on a key down event and the key up event was going to the parent site.
My fix is to suppress the key up event on the parent view.
BUG=155492
Review URL: https://chromiumcodereview.appspot.com/11188027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
3 files changed, 74 insertions, 1 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_mac.h b/content/browser/renderer_host/render_widget_host_view_mac.h index 569fa86..c43d779 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.h +++ b/content/browser/renderer_host/render_widget_host_view_mac.h @@ -142,9 +142,16 @@ class RenderWidgetHostViewMacEditCommandHelper; // The scale factor of the display this view is in. float deviceScaleFactor_; + + // If true then escape key down events are suppressed until the first escape + // key up event. (The up event is suppressed as well). This is used by the + // flash fullscreen code to avoid sending a key up event without a matching + // key down event. + BOOL suppressNextEscapeKeyUp_; } @property(nonatomic, readonly) NSRange selectedRange; +@property(nonatomic, readonly) BOOL suppressNextEscapeKeyUp; - (void)setCanBeKeyView:(BOOL)can; - (void)setTakesFocusOnlyOnMouseDown:(BOOL)b; @@ -421,6 +428,10 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase { return pepper_fullscreen_window_; } + RenderWidgetHostViewMac* fullscreen_parent_host_view() const { + return fullscreen_parent_host_view_; + } + private: friend class RenderWidgetHostView; @@ -463,6 +474,8 @@ class RenderWidgetHostViewMac : public RenderWidgetHostViewBase { // The fullscreen window used for pepper flash. scoped_nsobject<NSWindow> pepper_fullscreen_window_; scoped_nsobject<FullscreenWindowManager> fullscreen_window_manager_; + // Our parent host view, if this is fullscreen. NULL otherwise. + RenderWidgetHostViewMac* fullscreen_parent_host_view_; // List of pending swaps for deferred acking: // pairs of (route_id, gpu_host_id). diff --git a/content/browser/renderer_host/render_widget_host_view_mac.mm b/content/browser/renderer_host/render_widget_host_view_mac.mm index fcc2088..1e2ef8e 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac.mm @@ -290,7 +290,8 @@ RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) can_compose_inline_(true), is_loading_(false), is_hidden_(false), - weak_factory_(this) { + weak_factory_(this), + fullscreen_parent_host_view_(NULL) { // |cocoa_view_| owns us and we will be deleted when |cocoa_view_| // goes away. Since we autorelease it, our caller must put // |GetNativeView()| into the view hierarchy right after calling us. @@ -347,6 +348,8 @@ void RenderWidgetHostViewMac::InitAsPopup( // will enter fullscreen instead. void RenderWidgetHostViewMac::InitAsFullscreen( RenderWidgetHostView* reference_host_view) { + fullscreen_parent_host_view_ = + static_cast<RenderWidgetHostViewMac*>(reference_host_view); NSWindow* parent_window = nil; if (reference_host_view) parent_window = [reference_host_view->GetNativeView() window]; @@ -1528,6 +1531,7 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { @implementation RenderWidgetHostViewCocoa @synthesize selectedRange = selectedRange_; +@synthesize suppressNextEscapeKeyUp = suppressNextEscapeKeyUp_; @synthesize markedRange = markedRange_; - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { @@ -1879,10 +1883,21 @@ void RenderWidgetHostViewMac::SetTextInputActive(bool active) { if (event.type == NativeWebKeyboardEvent::RawKeyDown && event.windowsKeyCode == ui::VKEY_ESCAPE && renderWidgetHostView_->pepper_fullscreen_window()) { + RenderWidgetHostViewMac* parent = + renderWidgetHostView_->fullscreen_parent_host_view(); + if (parent) + parent->cocoa_view()->suppressNextEscapeKeyUp_ = YES; widgetHost->Shutdown(); return; } + // Suppress the escape key up event if necessary. + if (event.windowsKeyCode == ui::VKEY_ESCAPE && suppressNextEscapeKeyUp_) { + if (event.type == NativeWebKeyboardEvent::KeyUp) + suppressNextEscapeKeyUp_ = NO; + return; + } + // We only handle key down events and just simply forward other events. if ([theEvent type] != NSKeyDown) { widgetHost->ForwardKeyboardEvent(event); diff --git a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm index da105df..9330454 100644 --- a/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm +++ b/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm @@ -7,8 +7,13 @@ #include "base/mac/scoped_nsautorelease_pool.h" #include "base/utf_string_conversions.h" #include "content/browser/browser_thread_impl.h" +#include "content/browser/renderer_host/render_widget_host_delegate.h" #include "content/browser/renderer_host/test_render_view_host.h" #include "content/common/gpu/gpu_messages.h" +#include "content/public/browser/notification_types.h" +#include "content/public/test/mock_render_process_host.h" +#include "content/public/test/test_browser_context.h" +#include "content/public/test/test_utils.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/test/cocoa_test_event_utils.h" #import "ui/base/test/ui_cocoa_test_helper.h" @@ -18,6 +23,12 @@ namespace content { namespace { +class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { + public: + MockRenderWidgetHostDelegate() {} + virtual ~MockRenderWidgetHostDelegate() {} +}; + // Generates the |length| of composition rectangle vector and save them to // |output|. It starts from |origin| and each rectangle contains |unit_size|. void GenerateCompositionRectArray(const gfx::Point& origin, @@ -252,6 +263,40 @@ TEST_F(RenderWidgetHostViewMacTest, Fullscreen) { EXPECT_TRUE(rwhv_mac_->pepper_fullscreen_window()); } +// Verify that escape key down in fullscreen mode suppressed the keyup event on +// the parent. +TEST_F(RenderWidgetHostViewMacTest, FullscreenCloseOnEscape) { + // Use our own RWH since we need to destroy it. + MockRenderWidgetHostDelegate delegate; + TestBrowserContext browser_context; + MockRenderProcessHost* process_host = + new MockRenderProcessHost(&browser_context); + // Owned by its |cocoa_view()|. + RenderWidgetHostImpl* rwh = new RenderWidgetHostImpl( + &delegate, process_host, MSG_ROUTING_NONE); + RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>( + RenderWidgetHostView::CreateViewForWidget(rwh)); + + view->InitAsFullscreen(rwhv_mac_); + + WindowedNotificationObserver observer( + NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, + Source<RenderWidgetHost>(rwh)); + EXPECT_FALSE([rwhv_mac_->cocoa_view() suppressNextEscapeKeyUp]); + + // Escape key down. Should close window and set |suppressNextEscapeKeyUp| on + // the parent. + [view->cocoa_view() keyEvent: + cocoa_test_event_utils::KeyEventWithKeyCode(53, 27, NSKeyDown, 0)]; + observer.Wait(); + EXPECT_TRUE([rwhv_mac_->cocoa_view() suppressNextEscapeKeyUp]); + + // Escape key up on the parent should clear |suppressNextEscapeKeyUp|. + [rwhv_mac_->cocoa_view() keyEvent: + cocoa_test_event_utils::KeyEventWithKeyCode(53, 27, NSKeyUp, 0)]; + EXPECT_FALSE([rwhv_mac_->cocoa_view() suppressNextEscapeKeyUp]); +} + TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { const string16 kDummyString = UTF8ToUTF16("hogehoge"); const size_t kDummyOffset = 0; |