| Index: chrome/browser/ui/cocoa/web_contents_modal_dialog_host_cocoa.mm
|
| diff --git a/chrome/browser/ui/cocoa/web_contents_modal_dialog_host_cocoa.mm b/chrome/browser/ui/cocoa/web_contents_modal_dialog_host_cocoa.mm
|
| index 82fab3d83c7e3bb1bedded403307e9e14c2bdcc3..b77e262d5e82c4d35c6e03d41a17fed8cc118c22 100644
|
| --- a/chrome/browser/ui/cocoa/web_contents_modal_dialog_host_cocoa.mm
|
| +++ b/chrome/browser/ui/cocoa/web_contents_modal_dialog_host_cocoa.mm
|
| @@ -10,6 +10,7 @@
|
| #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_controller.h"
|
| #include "ui/gfx/geometry/point.h"
|
| #include "ui/gfx/geometry/size.h"
|
| +#import "ui/gfx/mac/coordinate_conversion.h"
|
|
|
| WebContentsModalDialogHostCocoa::WebContentsModalDialogHostCocoa(
|
| ConstrainedWindowSheetController* sheet_controller)
|
| @@ -17,8 +18,13 @@ WebContentsModalDialogHostCocoa::WebContentsModalDialogHostCocoa(
|
| }
|
|
|
| WebContentsModalDialogHostCocoa::~WebContentsModalDialogHostCocoa() {
|
| - // Toolkit-Views calls OnHostDestroying on observers here, but the Cocoa host
|
| - // doesn't need to be observed.
|
| + for (auto& observer : observers_)
|
| + observer.OnHostDestroying();
|
| +}
|
| +
|
| +void WebContentsModalDialogHostCocoa::OnPositionRequiresUpdate() {
|
| + for (auto& observer : observers_)
|
| + observer.OnPositionRequiresUpdate();
|
| }
|
|
|
| gfx::NativeView WebContentsModalDialogHostCocoa::GetHostView() const {
|
| @@ -42,18 +48,39 @@ gfx::NativeView WebContentsModalDialogHostCocoa::GetHostView() const {
|
|
|
| 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();
|
| + // Web-modals go via [sheet_controller_ originForSheet:..]. This is invoked
|
| + // for window-modals, so use the NSWindow sheet APIs.
|
| + NSWindow* native_parent = [sheet_controller_ parentWindow];
|
| + NSRect proposed_rect = [[native_parent contentView] bounds];
|
| + proposed_rect.origin.y = proposed_rect.size.height;
|
| + proposed_rect.size.height = 0;
|
| +
|
| + id parent_delegate = [native_parent delegate];
|
| + if ([parent_delegate
|
| + respondsToSelector:@selector(window:willPositionSheet:usingRect:)]) {
|
| + proposed_rect = [parent_delegate window:native_parent
|
| + willPositionSheet:nil
|
| + usingRect:proposed_rect];
|
| + }
|
| +
|
| + // Center horizontally and flip vertically. Note that origin.x may go
|
| + // negative. (That means it can also go offscreen.)
|
| + return gfx::Point(NSMidX(proposed_rect) - size.width() / 2,
|
| + NSHeight([native_parent frame]) - proposed_rect.origin.y);
|
| +}
|
| +
|
| +gfx::Point WebContentsModalDialogHostCocoa::GetHostPosition() const {
|
| + return gfx::ScreenRectFromNSRect([[sheet_controller_ parentWindow] frame])
|
| + .origin();
|
| }
|
|
|
| void WebContentsModalDialogHostCocoa::AddObserver(
|
| web_modal::ModalDialogHostObserver* observer) {
|
| - NOTREACHED();
|
| + observers_.AddObserver(observer);
|
| }
|
| void WebContentsModalDialogHostCocoa::RemoveObserver(
|
| web_modal::ModalDialogHostObserver* observer) {
|
| - NOTREACHED();
|
| + observers_.RemoveObserver(observer);
|
| }
|
|
|
| gfx::Size WebContentsModalDialogHostCocoa::GetMaximumDialogSize() {
|
|
|