Commit 2c935f0b authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Remove now-unused constrained window code.

BUG=895514, 845389

Change-Id: I7e44184c8a88b3e905fe26fd131a4900969c8f48
Reviewed-on: https://chromium-review.googlesource.com/c/1287326
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: default avatarSidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602916}
parent b057832f
...@@ -1968,19 +1968,6 @@ jumbo_split_static_library("ui") { ...@@ -1968,19 +1968,6 @@ jumbo_split_static_library("ui") {
"cocoa/confirm_quit.h", "cocoa/confirm_quit.h",
"cocoa/confirm_quit_panel_controller.h", "cocoa/confirm_quit_panel_controller.h",
"cocoa/confirm_quit_panel_controller.mm", "cocoa/confirm_quit_panel_controller.mm",
"cocoa/constrained_window/constrained_window_control_utils.h",
"cocoa/constrained_window/constrained_window_control_utils.mm",
"cocoa/constrained_window/constrained_window_custom_sheet.h",
"cocoa/constrained_window/constrained_window_custom_sheet.mm",
"cocoa/constrained_window/constrained_window_mac.h",
"cocoa/constrained_window/constrained_window_mac.mm",
"cocoa/constrained_window/constrained_window_sheet.h",
"cocoa/constrained_window/constrained_window_sheet_controller.h",
"cocoa/constrained_window/constrained_window_sheet_controller.mm",
"cocoa/constrained_window/constrained_window_sheet_info.h",
"cocoa/constrained_window/constrained_window_sheet_info.mm",
"cocoa/constrained_window/constrained_window_web_dialog_sheet.h",
"cocoa/constrained_window/constrained_window_web_dialog_sheet.mm",
"cocoa/dock_icon.h", "cocoa/dock_icon.h",
"cocoa/dock_icon.mm", "cocoa/dock_icon.mm",
"cocoa/first_run_dialog.h", "cocoa/first_run_dialog.h",
...@@ -2051,8 +2038,6 @@ jumbo_split_static_library("ui") { ...@@ -2051,8 +2038,6 @@ jumbo_split_static_library("ui") {
"cocoa/share_menu_controller.mm", "cocoa/share_menu_controller.mm",
"cocoa/simple_message_box_cocoa.h", "cocoa/simple_message_box_cocoa.h",
"cocoa/simple_message_box_cocoa.mm", "cocoa/simple_message_box_cocoa.mm",
"cocoa/single_web_contents_dialog_manager_cocoa.h",
"cocoa/single_web_contents_dialog_manager_cocoa.mm",
"cocoa/status_icons/status_icon_mac.h", "cocoa/status_icons/status_icon_mac.h",
"cocoa/status_icons/status_icon_mac.mm", "cocoa/status_icons/status_icon_mac.mm",
"cocoa/status_icons/status_tray_mac.h", "cocoa/status_icons/status_tray_mac.h",
...@@ -2075,8 +2060,6 @@ jumbo_split_static_library("ui") { ...@@ -2075,8 +2060,6 @@ jumbo_split_static_library("ui") {
"cocoa/touchbar/web_textfield_touch_bar_controller.mm", "cocoa/touchbar/web_textfield_touch_bar_controller.mm",
"cocoa/ui_localizer.h", "cocoa/ui_localizer.h",
"cocoa/ui_localizer.mm", "cocoa/ui_localizer.mm",
"cocoa/web_contents_modal_dialog_host_cocoa.h",
"cocoa/web_contents_modal_dialog_host_cocoa.mm",
"cocoa/window_size_autosaver.h", "cocoa/window_size_autosaver.h",
"cocoa/window_size_autosaver.mm", "cocoa/window_size_autosaver.mm",
"views/apps/chrome_app_window_client_views_mac.mm", "views/apps/chrome_app_window_client_views_mac.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 CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_CONTROL_UTILS_H_
#define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_CONTROL_UTILS_H_
#import <Cocoa/Cocoa.h>
#include "ui/base/resource/resource_bundle.h"
namespace constrained_window {
// Creates a label control.
NSTextField* CreateLabel();
// Helper function to create constrained window label string with the given
// font and alignment.
NSAttributedString* GetAttributedLabelString(
NSString* string,
ui::ResourceBundle::FontStyle fontStyle,
NSTextAlignment alignment,
NSLineBreakMode lineBreakMode);
// Create a new NSTextField and add it to the specified parent.
NSTextField* AddTextField(NSView* parent,
const base::string16& message,
const ui::ResourceBundle::FontStyle& font_style);
// Add the given button to the specified parent and customize it
// according to the parameters.
void AddButton(NSView* parent,
NSButton* button,
int title_id,
id target,
SEL action,
BOOL should_auto_size);
// Determine the frame required to fit the content of a string. Uses the
// provided height and width as preferred dimensions, where a value of
// 0.0 indicates no preference.
NSRect ComputeFrame(NSAttributedString* text, CGFloat width, CGFloat height);
} // namespace constrained_window
#endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_CONTROL_UTILS_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 "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_utils.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "skia/ext/skia_utils_mac.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
#include "ui/base/l10n/l10n_util_mac.h"
namespace constrained_window {
NSTextField* CreateLabel() {
NSTextField* label =
[[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease];
[label setEditable:NO];
[label setSelectable:NO];
[label setBezeled:NO];
[label setDrawsBackground:NO];
return label;
}
NSAttributedString* GetAttributedLabelString(
NSString* string,
ui::ResourceBundle::FontStyle fontStyle,
NSTextAlignment alignment,
NSLineBreakMode lineBreakMode) {
if (!string)
return nil;
const gfx::Font& font =
ui::ResourceBundle::GetSharedInstance().GetFont(fontStyle);
base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
[[NSMutableParagraphStyle alloc] init]);
[paragraphStyle setAlignment:alignment];
[paragraphStyle setLineBreakMode:lineBreakMode];
NSDictionary* attributes = @{
NSFontAttributeName: font.GetNativeFont(),
NSParagraphStyleAttributeName: paragraphStyle.get()
};
return [[[NSAttributedString alloc] initWithString:string
attributes:attributes] autorelease];
}
NSTextField* AddTextField(NSView* parent,
const base::string16& message,
const ui::ResourceBundle::FontStyle& font_style) {
NSTextField* textField = constrained_window::CreateLabel();
[textField
setAttributedStringValue:constrained_window::GetAttributedLabelString(
base::SysUTF16ToNSString(message),
font_style, NSNaturalTextAlignment,
NSLineBreakByWordWrapping)];
[parent addSubview:textField];
return textField;
}
void AddButton(NSView* parent,
NSButton* button,
int title_id,
id target,
SEL action,
BOOL should_auto_size) {
if (title_id)
[button setTitle:l10n_util::GetNSString(title_id)];
[button setTarget:target];
[button setAction:action];
[parent addSubview:button];
if (should_auto_size)
[GTMUILocalizerAndLayoutTweaker sizeToFitView:button];
}
NSRect ComputeFrame(NSAttributedString* text, CGFloat width, CGFloat height) {
NSRect frame =
[text boundingRectWithSize:NSMakeSize(width, height)
options:NSStringDrawingUsesLineFragmentOrigin];
// boundingRectWithSize: is known to underestimate the width, so
// additional padding needs to be added.
static const CGFloat kTextViewPadding = 10;
frame.size.width += kTextViewPadding;
return frame;
}
} // namespace constrained_window
// 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 CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_CUSTOM_SHEET_H_
#define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_CUSTOM_SHEET_H_
#import <Cocoa/Cocoa.h>
#import "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h"
// Represents a custom sheet. The sheet's window is shown without using the
// system |beginSheet:...| API.
@interface CustomConstrainedWindowSheet : NSObject<ConstrainedWindowSheet> {
@protected
base::scoped_nsobject<NSWindow> customWindow_;
BOOL useSimpleAnimations_;
}
- (id)initWithCustomWindow:(NSWindow*)customWindow;
// Defaults to NO, unless hardware that has problems with the standard
// animations is detected.
// The standard animation uses private CGS APIs, which can crash the window
// server. https://crbug.com/515627#c75
- (void)setUseSimpleAnimations:(BOOL)simpleAnimations;
@end
#endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_CUSTOM_SHEET_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 "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
#import <IOKit/IOKitLib.h>
#include "base/mac/mach_logging.h"
#include "base/mac/scoped_ioobject.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
#import "ui/base/cocoa/constrained_window/constrained_window_animation.h"
namespace {
// Length of the animation in seconds.
const NSTimeInterval kSheetAnimationDuration = 0.18;
// If the machine has a DisplayLink device attached, the WindowServer has a
// tendency to crash https://crbug.com/755516. To avoid this, probe the
// IOKit registry for a DisplayLink service, and turn on useSimpleAnimations_
// if one is found. The result of this is not cached, in case the hardware
// is attached after the first ConstrainedWindow is shown.
bool HasDisplayLinkDevice() {
// The |matching| reference is consumed by IOServiceGetMatchingServices().
CFDictionaryRef matching = IOServiceMatching("DisplayLinkFramebuffer");
base::mac::ScopedIOObject<io_iterator_t> it;
kern_return_t kr = IOServiceGetMatchingServices(
kIOMasterPortDefault, matching, it.InitializeInto());
if (kr != KERN_SUCCESS) {
MACH_LOG(ERROR, kr) << "IOServiceGetMatchingServices";
return false;
}
base::mac::ScopedIOObject<io_object_t> object(IOIteratorNext(it));
return object != IO_OBJECT_NULL;
}
} // namespace
@implementation CustomConstrainedWindowSheet
- (id)initWithCustomWindow:(NSWindow*)customWindow {
if ((self = [super init])) {
customWindow_.reset([customWindow retain]);
useSimpleAnimations_ = HasDisplayLinkDevice();
}
return self;
}
- (void)setUseSimpleAnimations:(BOOL)simpleAnimations {
useSimpleAnimations_ = simpleAnimations;
}
- (void)showSheetForWindow:(NSWindow*)window {
base::scoped_nsobject<NSAnimation> animation;
if (useSimpleAnimations_) {
[customWindow_ setAlphaValue:0.0];
} else {
animation.reset(
[[ConstrainedWindowAnimationShow alloc] initWithWindow:customWindow_]);
}
[window addChildWindow:customWindow_
ordered:NSWindowAbove];
[self unhideSheet];
[self updateSheetPosition];
[customWindow_ makeKeyAndOrderFront:nil];
if (useSimpleAnimations_) {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:kSheetAnimationDuration];
[[customWindow_ animator] setAlphaValue:1.0];
[NSAnimationContext endGrouping];
} else {
[animation startAnimation];
}
}
- (void)closeSheetWithAnimation:(BOOL)withAnimation {
if (withAnimation) {
base::scoped_nsobject<NSAnimation> animation;
if (useSimpleAnimations_) {
// Use a blocking animation, rather than -[NSWindow animator].
NSArray* animationArray = @[ @{
NSViewAnimationTargetKey : customWindow_,
NSViewAnimationEffectKey : NSViewAnimationFadeOutEffect,
} ];
animation.reset(
[[NSViewAnimation alloc] initWithViewAnimations:animationArray]);
[animation setDuration:kSheetAnimationDuration];
[animation setAnimationBlockingMode:NSAnimationBlocking];
} else {
animation.reset([[ConstrainedWindowAnimationHide alloc]
initWithWindow:customWindow_]);
}
[animation startAnimation];
}
[[customWindow_ parentWindow] removeChildWindow:customWindow_];
[customWindow_ close];
}
- (void)hideSheet {
// Hide the sheet window, and any of its direct child windows, by setting the
// alpha to 0. This technique is used instead of -orderOut: because that may
// cause a Spaces change or window ordering change.
[customWindow_ setAlphaValue:0.0];
for (NSWindow* window : [customWindow_ childWindows]) {
[window setAlphaValue:0.0];
}
}
- (void)unhideSheet {
[customWindow_ setAlphaValue:1.0];
for (NSWindow* window : [customWindow_ childWindows]) {
[window setAlphaValue:1.0];
}
}
- (void)pulseSheet {
base::scoped_nsobject<NSAnimation> animation(
[[ConstrainedWindowAnimationPulse alloc] initWithWindow:customWindow_]);
[animation startAnimation];
}
- (void)makeSheetKeyAndOrderFront {
[customWindow_ makeKeyAndOrderFront:nil];
}
- (void)updateSheetPosition {
ConstrainedWindowSheetController* controller =
[ConstrainedWindowSheetController controllerForSheet:self];
NSPoint origin = [controller originForSheet:self
withWindowSize:[customWindow_ frame].size];
[customWindow_ setFrameOrigin:origin];
}
- (void)resizeWithNewSize:(NSSize)size {
// NOOP
}
- (NSWindow*)sheetWindow {
return customWindow_;
}
@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.
#ifndef CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_H_
#define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
namespace content {
class WebContents;
}
class ConstrainedWindowMac;
class SingleWebContentsDialogManagerCocoa;
@protocol ConstrainedWindowSheet;
// A delegate for a constrained window. The delegate is notified when the
// window closes.
class ConstrainedWindowMacDelegate {
public:
virtual void OnConstrainedWindowClosed(ConstrainedWindowMac* window) = 0;
};
// Creates a ConstrainedWindowMac, shows the dialog, and returns it.
std::unique_ptr<ConstrainedWindowMac> CreateAndShowWebModalDialogMac(
ConstrainedWindowMacDelegate* delegate,
content::WebContents* web_contents,
id<ConstrainedWindowSheet> sheet);
// Creates a ConstrainedWindowMac and returns it.
std::unique_ptr<ConstrainedWindowMac> CreateWebModalDialogMac(
ConstrainedWindowMacDelegate* delegate,
content::WebContents* web_contents,
id<ConstrainedWindowSheet> sheet);
// Constrained window implementation for Mac.
// Normally an instance of this class is owned by the delegate. The delegate
// should delete the instance when the window is closed.
class ConstrainedWindowMac {
public:
ConstrainedWindowMac(ConstrainedWindowMacDelegate* delegate,
content::WebContents* web_contents,
id<ConstrainedWindowSheet> sheet);
~ConstrainedWindowMac();
// Shows the constrained window.
void ShowWebContentsModalDialog();
// Closes the constrained window.
void CloseWebContentsModalDialog();
SingleWebContentsDialogManagerCocoa* manager() const { return manager_; }
void set_manager(SingleWebContentsDialogManagerCocoa* manager) {
manager_ = manager;
}
id<ConstrainedWindowSheet> sheet() const { return sheet_.get(); }
// Called by |manager_| when the dialog is closing.
void OnDialogClosing();
// Whether or not the dialog was shown. If the dialog is auto-resizable, it
// is hidden until its WebContents initially loads.
bool DialogWasShown();
private:
// Gets the dialog manager for |web_contents_|.
web_modal::WebContentsModalDialogManager* GetDialogManager();
ConstrainedWindowMacDelegate* delegate_; // weak, owns us.
SingleWebContentsDialogManagerCocoa* manager_; // weak, owned by WCMDM.
content::WebContents* web_contents_; // weak, owned by dialog initiator.
base::scoped_nsprotocol<id<ConstrainedWindowSheet>> sheet_;
std::unique_ptr<SingleWebContentsDialogManagerCocoa> native_manager_;
};
#endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_MAC_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.
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
#include <memory>
#include <utility>
#include "base/logging.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h"
#import "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h"
#include "components/guest_view/browser/guest_view_base.h"
#include "content/public/browser/browser_thread.h"
using web_modal::WebContentsModalDialogManager;
std::unique_ptr<ConstrainedWindowMac> CreateAndShowWebModalDialogMac(
ConstrainedWindowMacDelegate* delegate,
content::WebContents* web_contents,
id<ConstrainedWindowSheet> sheet) {
ConstrainedWindowMac* window =
new ConstrainedWindowMac(delegate, web_contents, sheet);
window->ShowWebContentsModalDialog();
return std::unique_ptr<ConstrainedWindowMac>(window);
}
std::unique_ptr<ConstrainedWindowMac> CreateWebModalDialogMac(
ConstrainedWindowMacDelegate* delegate,
content::WebContents* web_contents,
id<ConstrainedWindowSheet> sheet) {
return std::unique_ptr<ConstrainedWindowMac>(
new ConstrainedWindowMac(delegate, web_contents, sheet));
}
ConstrainedWindowMac::ConstrainedWindowMac(
ConstrainedWindowMacDelegate* delegate,
content::WebContents* web_contents,
id<ConstrainedWindowSheet> sheet)
: delegate_(delegate),
sheet_([sheet retain]) {
DCHECK(sheet);
// |web_contents| may be embedded within a chain of nested GuestViews. If it
// is, follow the chain of embedders to the outermost WebContents and use it.
web_contents_ =
guest_view::GuestViewBase::GetTopLevelWebContents(web_contents);
native_manager_.reset(
new SingleWebContentsDialogManagerCocoa(this, sheet_.get(),
GetDialogManager()));
}
ConstrainedWindowMac::~ConstrainedWindowMac() {
CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
native_manager_.reset();
DCHECK(!manager_);
}
void ConstrainedWindowMac::ShowWebContentsModalDialog() {
std::unique_ptr<SingleWebContentsDialogManagerCocoa> dialog_manager;
dialog_manager = std::move(native_manager_);
GetDialogManager()->ShowDialogWithManager(
[sheet_.get() sheetWindow], std::move(dialog_manager));
}
void ConstrainedWindowMac::CloseWebContentsModalDialog() {
if (manager_)
manager_->Close();
}
void ConstrainedWindowMac::OnDialogClosing() {
if (delegate_)
delegate_->OnConstrainedWindowClosed(this);
}
bool ConstrainedWindowMac::DialogWasShown() {
// If the dialog was shown, |native_manager_| would have been released.
return !native_manager_;
}
WebContentsModalDialogManager* ConstrainedWindowMac::GetDialogManager() {
DCHECK(web_contents_);
WebContentsModalDialogManager* dialog_manager =
WebContentsModalDialogManager::FromWebContents(web_contents_);
// If WebContentsModalDialogManager::CreateForWebContents(web_contents_) was
// never called, then the manager will be null. E.g., for browser tabs,
// TabHelpers::AttachTabHelpers() calls CreateForWebContents(). It is invalid
// to show a dialog on some kinds of WebContents. Crash cleanly in that case.
CHECK(dialog_manager);
return dialog_manager;
}
// 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.
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/web_contents.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "url/gurl.h"
using ::testing::NiceMock;
namespace {
class ConstrainedWindowDelegateMock : public ConstrainedWindowMacDelegate {
public:
MOCK_METHOD1(OnConstrainedWindowClosed, void(ConstrainedWindowMac*));
};
} // namespace
class ConstrainedWindowMacTest : public InProcessBrowserTest {
public:
ConstrainedWindowMacTest()
: InProcessBrowserTest(),
tab0_(NULL),
tab1_(NULL),
controller_(NULL),
tab_view0_(NULL),
tab_view1_(NULL) {
sheet_window_.reset([[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, 30, 30)
styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO]);
[sheet_window_ setReleasedWhenClosed:NO];
sheet_.reset([[CustomConstrainedWindowSheet alloc]
initWithCustomWindow:sheet_window_]);
[sheet_ hideSheet];
}
void SetUpOnMainThread() override {
AddTabAtIndex(1, GURL("about:blank"), ui::PAGE_TRANSITION_LINK);
tab0_ = browser()->tab_strip_model()->GetWebContentsAt(0);
tab1_ = browser()->tab_strip_model()->GetWebContentsAt(1);
EXPECT_EQ(tab1_, browser()->tab_strip_model()->GetActiveWebContents());
controller_ = [BrowserWindowController browserWindowControllerForWindow:
browser()->window()->GetNativeWindow()];
EXPECT_TRUE(controller_);
tab_view0_ = [[controller_ tabStripController] viewAtIndex:0];
EXPECT_TRUE(tab_view0_);
tab_view1_ = [[controller_ tabStripController] viewAtIndex:1];
EXPECT_TRUE(tab_view1_);
}
protected:
base::scoped_nsobject<CustomConstrainedWindowSheet> sheet_;
base::scoped_nsobject<NSWindow> sheet_window_;
content::WebContents* tab0_;
content::WebContents* tab1_;
BrowserWindowController* controller_;
NSView* tab_view0_;
NSView* tab_view1_;
};
// Test that a sheet added to a inactive tab is not shown until the
// tab is activated.
IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInInactiveTab) {
// Show dialog in non active tab.
NiceMock<ConstrainedWindowDelegateMock> delegate;
std::unique_ptr<ConstrainedWindowMac> dialog =
CreateAndShowWebModalDialogMac(&delegate, tab0_, sheet_);
EXPECT_EQ(0.0, [sheet_window_ alphaValue]);
// Switch to inactive tab.
browser()->tab_strip_model()->ActivateTabAt(0, true);
EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
dialog->CloseWebContentsModalDialog();
}
// If a tab has never been shown then the associated tab view for the web
// content will not be created. Verify that adding a constrained window to such
// a tab works correctly.
IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, ShowInUninitializedTab) {
content::WebContents::CreateParams create_params(browser()->profile());
create_params.initially_hidden = true;
std::unique_ptr<content::WebContents> web_contents(
content::WebContents::Create(create_params));
chrome::AddWebContents(browser(), NULL, std::move(web_contents),
WindowOpenDisposition::NEW_BACKGROUND_TAB, gfx::Rect(),
false);
content::WebContents* tab2 =
browser()->tab_strip_model()->GetWebContentsAt(2);
ASSERT_TRUE(tab2);
EXPECT_FALSE([tab2->GetNativeView() superview]);
// Show dialog and verify that it's not visible yet.
NiceMock<ConstrainedWindowDelegateMock> delegate;
std::unique_ptr<ConstrainedWindowMac> dialog =
CreateAndShowWebModalDialogMac(&delegate, tab2, sheet_);
EXPECT_FALSE([sheet_window_ isVisible]);
// Activate the tab and verify that the constrained window is shown.
browser()->tab_strip_model()->ActivateTabAt(2, true);
EXPECT_TRUE([tab2->GetNativeView() superview]);
EXPECT_TRUE([sheet_window_ isVisible]);
EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
dialog->CloseWebContentsModalDialog();
}
// Test that adding a sheet disables tab dragging.
IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabDragging) {
NiceMock<ConstrainedWindowDelegateMock> delegate;
std::unique_ptr<ConstrainedWindowMac> dialog =
CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_);
// Verify that the dialog disables dragging.
EXPECT_TRUE([controller_ isTabDraggable:tab_view0_]);
EXPECT_FALSE([controller_ isTabDraggable:tab_view1_]);
dialog->CloseWebContentsModalDialog();
}
// Test that closing a browser window with a sheet works.
IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowClose) {
NiceMock<ConstrainedWindowDelegateMock> delegate;
std::unique_ptr<ConstrainedWindowMac> dialog(
CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_));
EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
// Close the browser window.
base::scoped_nsobject<NSWindow> browser_window(
[browser()->window()->GetNativeWindow() retain]);
EXPECT_TRUE([browser_window isVisible]);
[browser()->window()->GetNativeWindow() performClose:nil];
EXPECT_FALSE([browser_window isVisible]);
}
// Test that closing a tab with a sheet works.
IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, TabClose) {
NiceMock<ConstrainedWindowDelegateMock> delegate;
std::unique_ptr<ConstrainedWindowMac> dialog(
CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_));
EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
// Close the tab.
TabStripModel* tab_strip = browser()->tab_strip_model();
EXPECT_EQ(2, tab_strip->count());
EXPECT_TRUE(tab_strip->CloseWebContentsAt(1,
TabStripModel::CLOSE_USER_GESTURE));
EXPECT_EQ(1, tab_strip->count());
}
// Test that the sheet is still visible after entering and exiting fullscreen.
IN_PROC_BROWSER_TEST_F(ConstrainedWindowMacTest, BrowserWindowFullscreen) {
NiceMock<ConstrainedWindowDelegateMock> delegate;
std::unique_ptr<ConstrainedWindowMac> dialog(
CreateAndShowWebModalDialogMac(&delegate, tab1_, sheet_));
EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
// Toggle fullscreen twice: one for entering and one for exiting.
// Check to see if the sheet is visible.
for (int i = 0; i < 2; i++) {
{
// NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. Wait for the
// notification before testing the sheet's visibility.
std::unique_ptr<FullscreenNotificationObserver> waiter(
new FullscreenNotificationObserver());
browser()
->exclusive_access_manager()
->fullscreen_controller()
->ToggleBrowserFullscreenMode();
waiter->Wait();
}
EXPECT_EQ(1.0, [sheet_window_ alphaValue]);
}
dialog->CloseWebContentsModalDialog();
}
// 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 CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_H_
#define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_H_
#import <Cocoa/Cocoa.h>
// Protocol for a sheet to be showing using |ConstrainedWindowSheetController|.
@protocol ConstrainedWindowSheet<NSObject>
- (void)showSheetForWindow:(NSWindow*)window;
- (void)closeSheetWithAnimation:(BOOL)withAnimation;
- (void)hideSheet;
- (void)unhideSheet;
- (void)pulseSheet;
- (void)makeSheetKeyAndOrderFront;
- (void)updateSheetPosition;
- (void)resizeWithNewSize:(NSSize)size;
@property(readonly, nonatomic) NSWindow* sheetWindow;
@end
#endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_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.
#ifndef CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include <memory>
#include <vector>
#include "base/mac/scoped_nsobject.h"
namespace web_modal {
class WebContentsModalDialogHost;
}
class WebContentsModalDialogHostCocoa;
@protocol ConstrainedWindowSheet;
// This class manages multiple tab modal sheets for a single parent window. Each
// tab can have a single sheet and only the active tab's sheet will be visible.
// A tab in this case is the |parentView| passed to |-showSheet:forParentView:|.
@interface ConstrainedWindowSheetController : NSObject {
@private
base::scoped_nsobject<NSMutableArray> sheets_;
base::scoped_nsobject<NSWindow> parentWindow_;
base::scoped_nsobject<NSView> activeView_;
// Flag to prevent the sheet from updating its position if it's hidden during
// fullscreen. Otherwise, we will get janky movements during the animation.
BOOL isSheetHiddenForFullscreen_;
// Class that bridges the cross-platform web_modal APIs to the Cocoa sheet
// controller.
std::unique_ptr<WebContentsModalDialogHostCocoa> dialogHost_;
}
@property(readonly, nonatomic)
web_modal::WebContentsModalDialogHost* dialogHost;
@property(readonly, nonatomic) NSWindow* parentWindow;
// Returns a sheet controller for |parentWindow|. If a sheet controller does not
// exist yet then one will be created.
+ (ConstrainedWindowSheetController*)
controllerForParentWindow:(NSWindow*)parentWindow;
// Find a controller that's managing the given sheet. If no such controller
// exists then nil is returned.
+ (ConstrainedWindowSheetController*)
controllerForSheet:(id<ConstrainedWindowSheet>)sheet;
// Find the sheet attached to the given overlay window.
+ (id<ConstrainedWindowSheet>)sheetForOverlayWindow:(NSWindow*)overlayWindow;
// Shows the given sheet over |parentView|.
- (void)showSheet:(id<ConstrainedWindowSheet>)sheet
forParentView:(NSView*)parentView;
// Hides |sheet| over the active view.
- (void)hideSheet:(id<ConstrainedWindowSheet>)sheet;
// Hides and unhides the sheet at the beginning and end of fullscreen
// transition. |hideSheetForFullscreenTransition| gets called at the beginning
// of the transition and |unhideSheetForFullscreenTransition| gets called at
// the end.
- (void)hideSheetForFullscreenTransition;
- (void)unhideSheetForFullscreenTransition;
// Calculates the position of the sheet for the given window size.
- (NSPoint)originForSheet:(id<ConstrainedWindowSheet>)sheet
withWindowSize:(NSSize)size;
// Closes the given sheet.
- (void)closeSheet:(id<ConstrainedWindowSheet>)sheet;
// Run a pulse animation for the given sheet. This does nothing if the sheet
// is not visible.
- (void)pulseSheet:(id<ConstrainedWindowSheet>)sheet;
// Gets the number of sheets attached to the controller's window.
- (int)sheetCount;
// The size of the overlay window, which can be used to determine a preferred
// maximum size for a dialog that should be contained within |parentView|.
- (NSSize)overlayWindowSizeForParentView:(NSView*)parentView;
@end
#endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_CONTROLLER_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.
#ifndef CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_INFO_H_
#define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_INFO_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
@protocol ConstrainedWindowSheet;
// Information about a single sheet managed by
// ConstrainedWindowSheetController. Note, this is a private class not meant for
// public use.
@interface ConstrainedWindowSheetInfo : NSObject {
@private
base::scoped_nsprotocol<id<ConstrainedWindowSheet>> sheet_;
base::scoped_nsobject<NSView> parentView_;
base::scoped_nsobject<NSWindow> overlayWindow_;
BOOL sheetDidShow_;
}
@property(nonatomic, readonly) id<ConstrainedWindowSheet> sheet;
@property(nonatomic, readonly) NSView* parentView;
@property(nonatomic, readonly) NSWindow* overlayWindow;
@property(nonatomic, assign) BOOL sheetDidShow;
// Initializes a info object with for the given |sheet| and associated
// |parentView| and |overlayWindow|.
- (id)initWithSheet:(id<ConstrainedWindowSheet>)sheet
parentView:(NSView*)parentView
overlayWindow:(NSWindow*)overlayWindow;
// Hides the sheet and the associated overlay window. Hiding is done in such
// a way as to not disturb the window cycle order.
- (void)hideSheet;
// Shows the sheet and the associated overlay window.
- (void)showSheet;
@end
#endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_SHEET_INFO_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.
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_info.h"
#include "base/mac/foundation_util.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h"
#include "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
@implementation ConstrainedWindowSheetInfo
@synthesize sheetDidShow = sheetDidShow_;
- (id)initWithSheet:(id<ConstrainedWindowSheet>)sheet
parentView:(NSView*)parentView
overlayWindow:(NSWindow*)overlayWindow {
if ((self = [super init])) {
sheet_.reset([sheet retain]);
parentView_.reset([parentView retain]);
overlayWindow_.reset([overlayWindow retain]);
}
return self;
}
- (id<ConstrainedWindowSheet>)sheet {
return sheet_;
}
- (NSView*)parentView {
return parentView_;
}
- (NSWindow*)overlayWindow {
return overlayWindow_;
}
- (void)hideSheet {
[sheet_ hideSheet];
// Overlay window is already invisible so just stop accepting mouse events.
[overlayWindow_ setIgnoresMouseEvents:YES];
// Make sure the now invisible sheet doesn't keep keyboard focus
[[overlayWindow_ parentWindow] makeKeyWindow];
}
- (void)showSheet {
[overlayWindow_ setIgnoresMouseEvents:NO];
if (sheetDidShow_) {
[sheet_ unhideSheet];
} else {
[sheet_ showSheetForWindow:overlayWindow_];
sheetDidShow_ = YES;
}
// The call to -addChildWindow:ordered: below works around a macOS bug
// (rdar://35418050) in 10.12 through (at least) 10.13.1: If a window (A) has
// a child window (B), and B has a sheet (C), then adding another child
// window (D) to A causes the sheet (C) to move behind its parent (B).
//
// This happens when the client certificate selector appears and then, after
// a timeout, the status bubble appears to indicate that the page is still
// loading.
//
// ╭────────────────────────────╮
// │ Browser window (A) │
// │ ┌───┬───────────────────┬──┼─┐
// │ │ │ Cert selector (C) │ │ │
// │ │ ╰───────────────────╯ │ │
// ╭ ├─┼─────╮ Overlay window (B) │ │
// ├ ╰─┼─────┴────────────────────╯ │
// │ └────────────────────────────┘
// ╰ Status bubble (D)
//
// Explicitly adding the sheet as a child window seems to let it participate
// in the window ordering process that happens when the root window gains a
// child so that it stays in front of its parent as expected.
if (NSWindow* sheet = [overlayWindow_ attachedSheet])
[overlayWindow_ addChildWindow:sheet ordered:NSWindowAbove];
[sheet_ makeSheetKeyAndOrderFront];
}
@end
// Copyright 2014 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 CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_WEB_DIALOG_SHEET_H_
#define CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_WEB_DIALOG_SHEET_H_
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
namespace ui {
class WebDialogDelegate;
}
// Represents a custom sheet for web dialog.
@interface WebDialogConstrainedWindowSheet : CustomConstrainedWindowSheet {
@private
NSSize current_size_;
ui::WebDialogDelegate* web_dialog_delegate_; // Weak.
}
- (id)initWithCustomWindow:(NSWindow*)customWindow
webDialogDelegate:(ui::WebDialogDelegate*)delegate;
@end
#endif // CHROME_BROWSER_UI_COCOA_CONSTRAINED_WINDOW_CONSTRAINED_WINDOW_WEB_DIALOG_SHEET_H_
// Copyright 2014 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 "chrome/browser/ui/cocoa/constrained_window/constrained_window_web_dialog_sheet.h"
#import "ui/base/cocoa/window_size_constants.h"
#include "ui/gfx/geometry/size.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
@implementation WebDialogConstrainedWindowSheet
- (id)initWithCustomWindow:(NSWindow*)customWindow
webDialogDelegate:(ui::WebDialogDelegate*)delegate {
if (self = [super initWithCustomWindow:customWindow]) {
current_size_ = ui::kWindowSizeDeterminedLater.size;
web_dialog_delegate_ = delegate;
}
return self;
}
- (void)updateSheetPosition {
if (web_dialog_delegate_) {
gfx::Size size;
web_dialog_delegate_->GetDialogSize(&size);
// If the dialog has autoresizing enabled, |size| will be empty. Use the
// last known dialog size.
NSSize content_size = size.IsEmpty() ? current_size_ :
NSMakeSize(size.width(), size.height());
[customWindow_ setContentSize:content_size];
}
[super updateSheetPosition];
}
- (void)resizeWithNewSize:(NSSize)size {
DCHECK(size.height > 0 && size.width > 0);
current_size_ = size;
[customWindow_ setContentSize:current_size_];
// self's updateSheetPosition() sets |customWindow_|'s contentSize to a
// fixed dialog size. Here, we want to resize to |size| instead. Use
// super rather than self to bypass the setContentSize() call for the fixed
// size.
[super updateSheetPosition];
}
@end
// Copyright 2015 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 CHROME_BROWSER_UI_COCOA_SINGLE_WEB_CONTENTS_DIALOG_MANAGER_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_SINGLE_WEB_CONTENTS_DIALOG_MANAGER_COCOA_H_
#import "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "components/web_modal/single_web_contents_dialog_manager.h"
class ConstrainedWindowMac;
@protocol ConstrainedWindowSheet;
// Cocoa implementation of web_modal::SingleWebContentsDialogManager for showing
// native Cocoa sheet dialogs (of various kinds).
class SingleWebContentsDialogManagerCocoa
: public web_modal::SingleWebContentsDialogManager {
public:
SingleWebContentsDialogManagerCocoa(
ConstrainedWindowMac* client,
id<ConstrainedWindowSheet> sheet,
web_modal::SingleWebContentsDialogManagerDelegate* delegate);
~SingleWebContentsDialogManagerCocoa() override;
// SingleWebContentsDialogManager overrides.
void Show() override;
void Hide() override;
void Close() override;
void Focus() override;
void Pulse() override;
void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override;
gfx::NativeWindow dialog() override;
private:
// Weak. Legacy DialogManager-style delegate interface that Cocoa uses.
ConstrainedWindowMac* client_;
base::scoped_nsprotocol<id<ConstrainedWindowSheet>> sheet_;
// Weak. Owns this.
web_modal::SingleWebContentsDialogManagerDelegate* delegate_;
// Weak. Owned by parent window.
web_modal::WebContentsModalDialogHost* host_;
DISALLOW_COPY_AND_ASSIGN(SingleWebContentsDialogManagerCocoa);
};
#endif // CHROME_BROWSER_UI_COCOA_SINGLE_WEB_CONTENTS_DIALOG_MANAGER_COCOA_H_
// Copyright 2015 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 "chrome/browser/ui/cocoa/single_web_contents_dialog_manager_cocoa.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_mac.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
#include "components/web_modal/web_contents_modal_dialog_host.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/web_contents.h"
SingleWebContentsDialogManagerCocoa::SingleWebContentsDialogManagerCocoa(
ConstrainedWindowMac* client,
id<ConstrainedWindowSheet> sheet,
web_modal::SingleWebContentsDialogManagerDelegate* delegate)
: client_(client),
sheet_([sheet retain]),
delegate_(delegate),
host_(nullptr) {
DCHECK(client);
client->set_manager(this);
}
SingleWebContentsDialogManagerCocoa::~SingleWebContentsDialogManagerCocoa() {
}
void SingleWebContentsDialogManagerCocoa::Show() {
// If a dialog is initially shown on a hidden/background WebContents, the
// |delegate_| will defer the Show() until the WebContents is shown. If the
// defer happens during tab closure or tab dragging, a suspected data race or
// ObserverList ordering may result in |host_| being null here. If the tab is
// closing anyway, it doesn't matter. For tab dragging, avoid a crash, but the
// user may have to switch tabs again to see the dialog. See
// http://crbug.com/514826 for details.
if (!host_)
return;
NSView* parent_view = host_->GetHostView().GetNativeNSView();
// Note that simply [parent_view window] for an inactive tab is nil. However,
// the following should always be non-nil for all WebContents containers.
NSWindow* parent_window = delegate_->GetWebContents()
->GetTopLevelNativeWindow()
.GetNativeNSWindow();
[[ConstrainedWindowSheetController controllerForParentWindow:parent_window]
showSheet:sheet_ forParentView:parent_view];
}
void SingleWebContentsDialogManagerCocoa::Hide() {
NSWindow* parent_window = delegate_->GetWebContents()
->GetTopLevelNativeWindow()
.GetNativeNSWindow();
[[ConstrainedWindowSheetController controllerForParentWindow:parent_window]
hideSheet:sheet_];
}
void SingleWebContentsDialogManagerCocoa::Close() {
[[ConstrainedWindowSheetController controllerForSheet:sheet_]
closeSheet:sheet_];
client_->set_manager(nullptr);
bool dialog_was_open = client_->DialogWasShown();
client_->OnDialogClosing(); // |client_| might delete itself here.
if (dialog_was_open)
delegate_->WillClose(dialog()); // Deletes |this|.
}
void SingleWebContentsDialogManagerCocoa::Focus() {
}
void SingleWebContentsDialogManagerCocoa::Pulse() {
[[ConstrainedWindowSheetController controllerForSheet:sheet_]
pulseSheet:sheet_];
}
void SingleWebContentsDialogManagerCocoa::HostChanged(
web_modal::WebContentsModalDialogHost* new_host) {
// No need to observe the host. For Cocoa, the constrained window controller
// will reposition the dialog when necessary. The host can also never change.
// Tabs showing a dialog can not be dragged off a Cocoa browser window.
// However, closing a tab with a dialog open will set the host back to null.
DCHECK_NE(!!host_, !!new_host);
host_ = new_host;
}
gfx::NativeWindow SingleWebContentsDialogManagerCocoa::dialog() {
return [sheet_ sheetWindow];
}
// Copyright 2015 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 CHROME_BROWSER_UI_COCOA_WEB_CONTENTS_MODAL_DIALOG_HOST_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_WEB_CONTENTS_MODAL_DIALOG_HOST_COCOA_H_
#include "base/macros.h"
#include "components/web_modal/web_contents_modal_dialog_host.h"
@class ConstrainedWindowSheetController;
// In a Cocoa browser, the modal dialog host is a simple bridge to the
// ConstrainedWindowSheetController to get the dialog size and parent window.
class WebContentsModalDialogHostCocoa
: public web_modal::WebContentsModalDialogHost {
public:
explicit WebContentsModalDialogHostCocoa(
ConstrainedWindowSheetController* sheet_controller);
~WebContentsModalDialogHostCocoa() override;
// web_modal::ModalDialogHost:
gfx::NativeView GetHostView() const override;
gfx::Point GetDialogPosition(const gfx::Size& size) override;
bool ShouldActivateDialog() const override;
void AddObserver(web_modal::ModalDialogHostObserver* observer) override;
void RemoveObserver(web_modal::ModalDialogHostObserver* observer) override;
// web_modal::WebContentsModalDialogHost:
gfx::Size GetMaximumDialogSize() override;
private:
ConstrainedWindowSheetController* sheet_controller_; // Weak. Owns |this|.
DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogHostCocoa);
};
#endif // CHROME_BROWSER_UI_COCOA_WEB_CONTENTS_MODAL_DIALOG_HOST_COCOA_H_
// Copyright 2015 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 "chrome/browser/ui/cocoa/web_contents_modal_dialog_host_cocoa.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/tab_dialogs.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
WebContentsModalDialogHostCocoa::WebContentsModalDialogHostCocoa(
ConstrainedWindowSheetController* sheet_controller)
: sheet_controller_(sheet_controller) {
}
WebContentsModalDialogHostCocoa::~WebContentsModalDialogHostCocoa() {
// Toolkit-Views calls OnHostDestroying on observers here, but the Cocoa host
// doesn't need to be observed.
}
gfx::NativeView WebContentsModalDialogHostCocoa::GetHostView() const {
// To avoid the constrained window controller having to know about the browser
// view layout, use the active tab in the parent window.
NSWindow* parent_window = [sheet_controller_ parentWindow];
Browser* browser = chrome::FindBrowserWithWindow(parent_window);
// This could be null for packaged app windows, but this dialog host is
// currently only used for browsers.
DCHECK(browser);
content::WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
DCHECK(web_contents);
TabDialogs* tab_dialogs = TabDialogs::FromWebContents(web_contents);
DCHECK(tab_dialogs);
// Note this returns the WebContents' superview, so it doesn't really matter
// which WebContents inside the browser we actually chose above.
return tab_dialogs->GetDialogParentView();
}
gfx::Point WebContentsModalDialogHostCocoa::GetDialogPosition(
const gfx::Size& size) {
// Dialogs are always re-positioned by the constrained window sheet controller
// so nothing interesting to return yet.
return gfx::Point();
}
bool WebContentsModalDialogHostCocoa::ShouldActivateDialog() const {
return [[sheet_controller_ parentWindow] isMainWindow];
}
void WebContentsModalDialogHostCocoa::AddObserver(
web_modal::ModalDialogHostObserver* observer) {
NOTREACHED();
}
void WebContentsModalDialogHostCocoa::RemoveObserver(
web_modal::ModalDialogHostObserver* observer) {
NOTREACHED();
}
gfx::Size WebContentsModalDialogHostCocoa::GetMaximumDialogSize() {
// The dialog should try to fit within the overlay for the web contents.
// Note that, for things like print preview, this is just a suggested maximum.
return gfx::Size([sheet_controller_
overlayWindowSizeForParentView:GetHostView().GetNativeNSView()]);
}
...@@ -1964,7 +1964,6 @@ test("browser_tests") { ...@@ -1964,7 +1964,6 @@ test("browser_tests") {
# TODO(crbug/845389): Re-Enable the following, which were temporarily # TODO(crbug/845389): Re-Enable the following, which were temporarily
# omitted from the build, but are still in use. # omitted from the build, but are still in use.
# "../browser/ui/cocoa/constrained_window/constrained_window_mac_browsertest.mm",
# "../browser/ui/cocoa/page_info/page_info_bubble_views_mac_browsertest.mm", # "../browser/ui/cocoa/page_info/page_info_bubble_views_mac_browsertest.mm",
] ]
sources -= [ sources -= [
...@@ -4127,7 +4126,6 @@ test("unit_tests") { ...@@ -4127,7 +4126,6 @@ test("unit_tests") {
"../browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller_unittest.mm", "../browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller_unittest.mm",
"../browser/ui/cocoa/color_panel_cocoa_unittest.mm", "../browser/ui/cocoa/color_panel_cocoa_unittest.mm",
"../browser/ui/cocoa/confirm_quit_panel_controller_unittest.mm", "../browser/ui/cocoa/confirm_quit_panel_controller_unittest.mm",
"../browser/ui/cocoa/constrained_window/constrained_window_sheet_controller_unittest.mm",
"../browser/ui/cocoa/find_pasteboard_unittest.mm", "../browser/ui/cocoa/find_pasteboard_unittest.mm",
"../browser/ui/cocoa/first_run_dialog_controller_unittest.mm", "../browser/ui/cocoa/first_run_dialog_controller_unittest.mm",
"../browser/ui/cocoa/history_menu_bridge_unittest.mm", "../browser/ui/cocoa/history_menu_bridge_unittest.mm",
......
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