Commit 7dfcc5cc authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RWHVMac: Remove InitAsFullscreen support

The NOTREACHED() in InitAsFullscreen has failed appear in crashes, so I
suspect that this has been dead code for a while now.

Bug: 821651
Change-Id: Ia057b630b8ebb89bc570884979bbd855156e4bf1
Reviewed-on: https://chromium-review.googlesource.com/982580
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547345}
parent 32df8e53
......@@ -568,15 +568,6 @@ void ExtractUnderlines(NSAttributedString* string,
latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0);
// Force fullscreen windows to close on Escape so they won't keep the keyboard
// grabbed or be stuck onscreen if the renderer is hanging.
if (event.GetType() == NativeWebKeyboardEvent::kRawKeyDown &&
event.windows_key_code == ui::VKEY_ESCAPE &&
renderWidgetHostView_->pepper_fullscreen_window()) {
widgetHost->ShutdownAndDestroyWidget(true);
return;
}
// If there are multiple widgets on the page (such as when there are
// out-of-process iframes), pick the one that should process this event.
if (widgetHost->delegate())
......
......@@ -39,7 +39,6 @@ namespace ui {
class ScopedPasswordInputEnabler;
}
@class FullscreenWindowManager;
@protocol RenderWidgetHostViewMacDelegate;
@class RenderWidgetHostViewCocoa;
......@@ -267,12 +266,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
mouse_wheel_phase_handler_.set_mouse_wheel_end_dispatch_timeout(timeout);
}
NSWindow* pepper_fullscreen_window() const {
return pepper_fullscreen_window_;
}
CONTENT_EXPORT void release_pepper_fullscreen_window_for_testing();
// Update the size, scale factor, color profile, vsync parameters, and any
// other properties of the NSView or its NSScreen. Propagate these to the
// RenderWidgetHostImpl as well.
......@@ -406,12 +399,6 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
// RenderWidgetHostViewGuest.
bool is_guest_view_hack_;
// The fullscreen window used for pepper flash.
base::scoped_nsobject<NSWindow> pepper_fullscreen_window_;
base::scoped_nsobject<FullscreenWindowManager> fullscreen_window_manager_;
// Our parent host view, if this is fullscreen. NULL otherwise.
RenderWidgetHostViewMac* fullscreen_parent_host_view_;
// Display link for getting vsync info.
scoped_refptr<ui::DisplayLinkMac> display_link_;
......
......@@ -42,7 +42,6 @@
#import "ui/base/clipboard/clipboard_util_mac.h"
#include "ui/base/cocoa/animation_utils.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#import "ui/base/cocoa/fullscreen_window_manager.h"
#import "ui/base/cocoa/secure_password_input.h"
#include "ui/base/cocoa/text_services_context_menu.h"
#include "ui/display/display.h"
......@@ -55,24 +54,6 @@ using blink::WebInputEvent;
using blink::WebMouseEvent;
using blink::WebGestureEvent;
// A window subclass that allows the fullscreen window to become main and gain
// keyboard focus. This is only used for pepper flash. Normal fullscreen is
// handled by the browser.
@interface PepperFlashFullscreenWindow : NSWindow
@end
@implementation PepperFlashFullscreenWindow
- (BOOL)canBecomeKeyWindow {
return YES;
}
- (BOOL)canBecomeMainWindow {
return YES;
}
@end
namespace content {
////////////////////////////////////////////////////////////////////////////////
......@@ -285,65 +266,10 @@ void RenderWidgetHostViewMac::InitAsPopup(
ns_view_bridge_->InitAsPopup(pos, popup_type_);
}
// This function creates the fullscreen window and hides the dock and menubar if
// necessary. Note, this codepath is only used for pepper flash when
// pp::FlashFullScreen::SetFullscreen() is called. If
// pp::FullScreen::SetFullscreen() is called then the entire browser window
// will enter fullscreen instead.
void RenderWidgetHostViewMac::InitAsFullscreen(
RenderWidgetHostView* reference_host_view) {
// TODO(ccameron): Delete this if it isn't used.
// This path appears never to be reached.
NOTREACHED();
RenderWidgetHostViewMac* parent_view =
static_cast<RenderWidgetHostViewMac*>(reference_host_view);
NSWindow* parent_window = nil;
if (parent_view)
parent_window = [parent_view->cocoa_view() window];
NSScreen* screen = [parent_window screen];
if (!screen)
screen = [NSScreen mainScreen];
pepper_fullscreen_window_.reset([[PepperFlashFullscreenWindow alloc]
initWithContentRect:[screen frame]
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO]);
[pepper_fullscreen_window_ setLevel:NSFloatingWindowLevel];
[pepper_fullscreen_window_ setReleasedWhenClosed:NO];
[cocoa_view() setCanBeKeyView:YES];
[cocoa_view() setFrame:[[pepper_fullscreen_window_ contentView] bounds]];
[cocoa_view() setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
// If the pepper fullscreen window isn't opaque then there are performance
// issues when it's on the discrete GPU and the Chrome window is being drawn
// to. http://crbug.com/171911
[pepper_fullscreen_window_ setOpaque:YES];
// Note that this forms a reference cycle between the fullscreen window and
// the rwhvmac: The PepperFlashFullscreenWindow retains cocoa_view(),
// but cocoa_view() keeps pepper_fullscreen_window_ in an instance variable.
// This cycle is normally broken when -keyEvent: receives an <esc> key, which
// explicitly calls Shutdown on the host(), which calls
// Destroy() on RWHVMac, which drops the reference to
// pepper_fullscreen_window_.
[[pepper_fullscreen_window_ contentView] addSubview:cocoa_view()];
// Note that this keeps another reference to pepper_fullscreen_window_.
fullscreen_window_manager_.reset([[FullscreenWindowManager alloc]
initWithWindow:pepper_fullscreen_window_.get()
desiredScreen:screen]);
[fullscreen_window_manager_ enterFullscreenMode];
[pepper_fullscreen_window_ makeKeyAndOrderFront:nil];
}
void RenderWidgetHostViewMac::release_pepper_fullscreen_window_for_testing() {
// See comment in InitAsFullscreen(): There is a reference cycle between
// rwhvmac and fullscreen window, which is usually broken by hitting <esc>.
// Tests that test pepper fullscreen mode without sending an <esc> event
// need to call this method to break the reference cycle.
[fullscreen_window_manager_ exitFullscreenMode];
fullscreen_window_manager_.reset();
[pepper_fullscreen_window_ close];
pepper_fullscreen_window_.reset();
}
void RenderWidgetHostViewMac::UpdateDisplayVSyncParameters() {
......@@ -652,15 +578,6 @@ void RenderWidgetHostViewMac::Destroy() {
ns_view_bridge_->Destroy();
ns_view_bridge_.reset();
[fullscreen_window_manager_ exitFullscreenMode];
fullscreen_window_manager_.reset();
[pepper_fullscreen_window_ close];
// This can be called as part of processing the window's responder
// chain, for instance |-performKeyEquivalent:|. In that case the
// object needs to survive until the stack unwinds.
pepper_fullscreen_window_.autorelease();
// Delete the delegated frame state, which will reach back into
// host().
browser_compositor_.reset();
......
......@@ -491,87 +491,6 @@ TEST_F(RenderWidgetHostViewMacTest, NSTextInputClientConformance) {
EXPECT_EQ(0u, actualRange.length);
}
// Disabled to see if InitAsFullscreen is ever reached.
TEST_F(RenderWidgetHostViewMacTest, Fullscreen_DISABLED) {
rwhv_mac_->InitAsFullscreen(nullptr);
EXPECT_TRUE(rwhv_mac_->pepper_fullscreen_window());
// Break the reference cycle caused by pepper_fullscreen_window() without
// an <esc> event. See comment in
// release_pepper_fullscreen_window_for_testing().
rwhv_mac_->release_pepper_fullscreen_window_for_testing();
}
// Verify that escape key down in fullscreen mode suppressed the keyup event on
// the parent.
// Disabled to see if InitAsFullscreen is ever reached.
TEST_F(RenderWidgetHostViewMacTest, FullscreenCloseOnEscape_DISABLED) {
// Use our own RWH since we need to destroy it.
MockRenderWidgetHostDelegate delegate;
int32_t routing_id = process_host_->GetNextRoutingID();
// Owned by its |cocoa_view()|.
MockRenderWidgetHostImpl* rwh = MockRenderWidgetHostImpl::Create(
&delegate, process_host_.get(), routing_id);
RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(rwh, false);
view->InitAsFullscreen(rwhv_mac_);
WindowedNotificationObserver observer(
NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
Source<RenderWidgetHost>(rwh));
EXPECT_TRUE([rwhv_mac_->cocoa_view() suppressNextKeyUpForTesting:53]);
[rwhv_mac_->cocoa_view() keyEvent:cocoa_test_event_utils::KeyEventWithKeyCode(
53, 27, NSKeyDown, 0)];
EXPECT_FALSE([rwhv_mac_->cocoa_view() suppressNextKeyUpForTesting:53]);
[rwhv_mac_->cocoa_view()
keyEvent:cocoa_test_event_utils::KeyEventWithKeyCode(53, 27, NSKeyUp, 0)];
EXPECT_TRUE([rwhv_mac_->cocoa_view() suppressNextKeyUpForTesting:53]);
// Escape key down. Should close window, but the key up for the escape
// should not affect the parent.
[view->cocoa_view() keyEvent:
cocoa_test_event_utils::KeyEventWithKeyCode(53, 27, NSKeyDown, 0)];
observer.Wait();
EXPECT_TRUE([rwhv_mac_->cocoa_view() suppressNextKeyUpForTesting:53]);
// Escape key down on the parent should clear the suppression.
[rwhv_mac_->cocoa_view() keyEvent:cocoa_test_event_utils::KeyEventWithKeyCode(
53, 27, NSKeyDown, 0)];
EXPECT_FALSE([rwhv_mac_->cocoa_view() suppressNextKeyUpForTesting:53]);
}
// Test that command accelerators which destroy the fullscreen window
// don't crash when forwarded via the window's responder machinery.
// Disabled to see if InitAsFullscreen is ever reached.
TEST_F(RenderWidgetHostViewMacTest, AcceleratorDestroy_DISABLED) {
// Use our own RWH since we need to destroy it.
MockRenderWidgetHostDelegate delegate;
TestBrowserContext browser_context;
int32_t routing_id = process_host_->GetNextRoutingID();
// Owned by its |cocoa_view()|.
MockRenderWidgetHostImpl* rwh = MockRenderWidgetHostImpl::Create(
&delegate, process_host_.get(), routing_id);
RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(rwh, false);
view->InitAsFullscreen(rwhv_mac_);
WindowedNotificationObserver observer(
NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
Source<RenderWidgetHost>(rwh));
// Key equivalents are only sent to the renderer if the window is key.
ui::test::ScopedFakeNSWindowFocus key_window_faker;
[[view->cocoa_view() window] makeKeyWindow];
// Command-ESC will destroy the view, while the window is still in
// |-performKeyEquivalent:|. There are other cases where this can
// happen, Command-ESC is the easiest to trigger.
[[view->cocoa_view() window] performKeyEquivalent:
cocoa_test_event_utils::KeyEventWithKeyCode(
53, 27, NSKeyDown, NSCommandKeyMask)];
observer.Wait();
}
// Test that NSEvent of private use character won't generate keypress event
// http://crbug.com/459089
TEST_F(RenderWidgetHostViewMacTest, FilterNonPrintableCharacter) {
......@@ -2100,68 +2019,6 @@ TEST_F(InputMethodMacTest, MonitorCompositionRangeForActiveWidget) {
EXPECT_FALSE(message->monitor_request());
}
// Ensure RenderWidgetHostViewMac claims hotkeys when AppKit spams the UI with
// -performKeyEquivalent:, but only when the window is key.
// Flaky: https://crbug.com/792907
TEST_F(RenderWidgetHostViewMacTest, DISABLED_ForwardKeyEquivalentsOnlyIfKey) {
int32_t routing_id = process_host_->GetNextRoutingID();
// Owned by its |cocoa_view()|.
MockRenderWidgetHostImpl* host = MockRenderWidgetHostImpl::Create(
&delegate_, process_host_.get(), routing_id);
RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac(host, false);
EXPECT_CALL(*host, Focus()).Times(2);
EXPECT_CALL(*host, Blur());
// This test needs an NSWindow. |rwhv_cocoa_| isn't in one, but going
// fullscreen conveniently puts it in one.
EXPECT_FALSE([view->cocoa_view() window]);
view->InitAsFullscreen(nullptr);
NSWindow* window = [view->cocoa_view() window];
EXPECT_TRUE(window);
base::RunLoop().RunUntilIdle();
MockWidgetInputHandler::MessageVector events =
host->GetAndResetDispatchedMessages();
ui::test::ScopedFakeNSWindowFocus key_window_faker;
EXPECT_FALSE([window isKeyWindow]);
base::RunLoop().RunUntilIdle();
events = host->GetAndResetDispatchedMessages();
EXPECT_EQ(0U, events.size());
// Cmd+x.
NSEvent* key_down =
cocoa_test_event_utils::KeyEventWithType(NSKeyDown, NSCommandKeyMask);
// Sending while not key should forward along the responder chain (e.g. to the
// mainMenu). Note the event is being sent to the NSWindow, which may also ask
// other parts of the UI to handle it, but in the test they should all say
// "NO" as well.
EXPECT_FALSE([window performKeyEquivalent:key_down]);
base::RunLoop().RunUntilIdle();
events = host->GetAndResetDispatchedMessages();
EXPECT_EQ(0U, events.size());
// Make key and send again. Event should be seen.
[window makeKeyWindow];
EXPECT_TRUE([window isKeyWindow]);
base::RunLoop().RunUntilIdle();
events = host->GetAndResetDispatchedMessages();
// -performKeyEquivalent: now returns YES to prevent further propagation, and
// the event is sent to the renderer.
EXPECT_TRUE([window performKeyEquivalent:key_down]);
base::RunLoop().RunUntilIdle();
events = host->GetAndResetDispatchedMessages();
EXPECT_EQ("RawKeyDown Char", GetMessageNames(events));
view->release_pepper_fullscreen_window_for_testing();
// Clean up.
host->ShutdownAndDestroyWidget(true);
}
TEST_F(RenderWidgetHostViewMacTest, ClearCompositorFrame) {
BrowserCompositorMac* browser_compositor =
rwhv_mac_->BrowserCompositorForTesting();
......
......@@ -125,8 +125,6 @@ component("base") {
"cocoa/focus_tracker.mm",
"cocoa/focus_window_set.h",
"cocoa/focus_window_set.mm",
"cocoa/fullscreen_window_manager.h",
"cocoa/fullscreen_window_manager.mm",
"cocoa/hover_button.h",
"cocoa/hover_button.mm",
"cocoa/hover_image_button.h",
......@@ -850,7 +848,6 @@ test("ui_base_unittests") {
"cocoa/controls/hyperlink_button_cell_unittest.mm",
"cocoa/controls/hyperlink_text_view_unittest.mm",
"cocoa/focus_tracker_unittest.mm",
"cocoa/fullscreen_window_manager_unittest.mm",
"cocoa/hover_button_unittest.mm",
"cocoa/hover_image_button_unittest.mm",
"cocoa/menu_controller_unittest.mm",
......
// Copyright (c) 2012 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.
#ifndef UI_BASE_COCOA_FULLSCREEN_WINDOW_MANAGER_H_
#define UI_BASE_COCOA_FULLSCREEN_WINDOW_MANAGER_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "ui/base/ui_base_export.h"
// A utility class to manage the fullscreen mode for a given window. This class
// also updates the window frame if the screen changes.
UI_BASE_EXPORT
@interface FullscreenWindowManager : NSObject {
@private
base::scoped_nsobject<NSWindow> window_;
// Explicitly keep track of the screen we want to position the window in.
// This is better than using -[NSWindow screen] because that might change if
// the screen changes to a low resolution.
base::scoped_nsobject<NSScreen> desiredScreen_;
base::mac::FullScreenMode fullscreenMode_;
BOOL fullscreenActive_;
}
- (id)initWithWindow:(NSWindow*)window
desiredScreen:(NSScreen*)desiredScreen;
// Enables fullscreen mode which causes the menubar and dock to be hidden as
// needed.
- (void)enterFullscreenMode;
// Exists fullscreen mode which stops hiding the menubar and dock.
- (void)exitFullscreenMode;
@end
#endif // UI_BASE_COCOA_FULLSCREEN_WINDOW_MANAGER_H_
// Copyright (c) 2012 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.
#import "ui/base/cocoa/fullscreen_window_manager.h"
namespace {
// Get the screen with the menu bar.
NSScreen* GetMenuBarScreen() {
// Documentation in NSScreen says that the first object in
// +[NSScreen screens] is the menu bar screen.
NSArray *screens = [NSScreen screens];
if ([screens count])
return [screens objectAtIndex:0];
return nil;
}
// Get the screen with the dock.
NSScreen* GetDockScreen() {
NSArray *screens = [NSScreen screens];
NSUInteger count = [screens count];
if (count == 0)
return NULL;
if (count == 1)
return [screens objectAtIndex:0];
for (NSUInteger i = 1; i < count; ++i) {
NSScreen* screen = [screens objectAtIndex:i];
// This screen is not the menu bar screen since it's not index 0. Therefore,
// the only reason that the frame would not match the visible frame is if
// the dock is on the screen.
if (!NSEqualRects([screen frame], [screen visibleFrame]))
return screen;
}
return [screens objectAtIndex:0];
}
} // namespace
@interface FullscreenWindowManager()
- (void)onScreenChanged:(NSNotification*)note;
- (void)update;
@end
@implementation FullscreenWindowManager
- (id)initWithWindow:(NSWindow*)window
desiredScreen:(NSScreen*)desiredScreen {
if ((self = [super init])) {
window_.reset([window retain]);
desiredScreen_.reset([desiredScreen retain]);
fullscreenMode_ = base::mac::kFullScreenModeNormal;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(onScreenChanged:)
name:NSApplicationDidChangeScreenParametersNotification
object:NSApp];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self exitFullscreenMode];
[super dealloc];
}
- (void)enterFullscreenMode {
if (fullscreenActive_)
return;
fullscreenActive_ = true;
[self update];
}
- (void)exitFullscreenMode {
if (!fullscreenActive_)
return;
fullscreenActive_ = false;
[self update];
}
- (void)onScreenChanged:(NSNotification*)note {
[self update];
}
- (void)update {
// From OS X 10.10, NSApplicationDidChangeScreenParametersNotification is sent
// when displaying a fullscreen window, which should normally only be sent if
// the monitor resolution has changed or new display is detected.
if (![[NSScreen screens] containsObject:desiredScreen_])
desiredScreen_.reset([[window_ screen] retain]);
base::mac::FullScreenMode newMode;
if (!fullscreenActive_)
newMode = base::mac::kFullScreenModeNormal;
else if ([desiredScreen_ isEqual:GetMenuBarScreen()])
newMode = base::mac::kFullScreenModeHideAll;
else if ([desiredScreen_ isEqual:GetDockScreen()])
newMode = base::mac::kFullScreenModeHideDock;
else
newMode = base::mac::kFullScreenModeNormal;
if (fullscreenMode_ != newMode) {
if (fullscreenMode_ != base::mac::kFullScreenModeNormal)
base::mac::ReleaseFullScreen(fullscreenMode_);
if (newMode != base::mac::kFullScreenModeNormal)
base::mac::RequestFullScreen(newMode);
fullscreenMode_ = newMode;
}
if (fullscreenActive_)
[window_ setFrame:[desiredScreen_ frame] display:YES];
}
@end
// Copyright (c) 2012 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.
#import "ui/base/cocoa/fullscreen_window_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "ui/base/test/cocoa_helper.h"
typedef ui::CocoaTest FullscreenWindowManagerTest;
TEST_F(FullscreenWindowManagerTest, EnterExit) {
base::scoped_nsobject<FullscreenWindowManager> manager(
[[FullscreenWindowManager alloc] initWithWindow:test_window()
desiredScreen:[NSScreen mainScreen]]);
NSApplicationPresentationOptions current_options =
[NSApp presentationOptions];
EXPECT_EQ(NSApplicationPresentationDefault, current_options);
[manager enterFullscreenMode];
current_options = [NSApp presentationOptions];
EXPECT_EQ(static_cast<NSApplicationPresentationOptions>(
NSApplicationPresentationHideDock |
NSApplicationPresentationHideMenuBar),
current_options);
[manager exitFullscreenMode];
current_options = [NSApp presentationOptions];
EXPECT_EQ(NSApplicationPresentationDefault, current_options);
}
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