| Index: chrome/browser/ui/views/mac/web_contents_modal_dialog_manager_views_mac.mm
|
| diff --git a/chrome/browser/ui/views/mac/web_contents_modal_dialog_manager_views_mac.mm b/chrome/browser/ui/views/mac/web_contents_modal_dialog_manager_views_mac.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..43258e6eabe11467fd82eec99b2c43cc8bb97e1e
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/mac/web_contents_modal_dialog_manager_views_mac.mm
|
| @@ -0,0 +1,110 @@
|
| +// Copyright (c) 2016 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/views/mac/web_contents_modal_dialog_manager_views_mac.h"
|
| +
|
| +#import <Cocoa/Cocoa.h>
|
| +
|
| +#include "base/mac/scoped_nsobject.h"
|
| +#import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet.h"
|
| +#include "components/guest_view/browser/guest_view_base.h"
|
| +#include "components/web_modal/web_contents_modal_dialog_manager.h"
|
| +#include "ui/gfx/mac/coordinate_conversion.h"
|
| +
|
| +
|
| +SingleWebContentsDialogManagerViewsMac::SingleWebContentsDialogManagerViewsMac(
|
| + id<ConstrainedWindowSheet> sheet,
|
| + content::WebContents* web_contents)
|
| + : sheet_([sheet retain]),
|
| + visible_(false) {
|
| + web_contents =
|
| + guest_view::GuestViewBase::GetTopLevelWebContents(web_contents);
|
| + delegate_ = web_modal::WebContentsModalDialogManager::FromWebContents(
|
| + web_contents);
|
| +}
|
| +
|
| +SingleWebContentsDialogManagerViewsMac::
|
| + ~SingleWebContentsDialogManagerViewsMac() {}
|
| +
|
| +void SingleWebContentsDialogManagerViewsMac::UpdateSheetPosition() {
|
| + if (!visible_)
|
| + return;
|
| +
|
| + // Combine the size of the browser window and the size of the tab view (which
|
| + // will be horizontally smaller because devtools are opened) to position
|
| + // the certificate viewer correctly.
|
| + int windowWidth = [delegate_->GetWebContents()->GetTopLevelNativeWindow()
|
| + frame].size.width;
|
| + NSRect tabViewSize = ScreenRectToNSRect(
|
| + delegate_->GetWebContents()->GetContainerBounds());
|
| + NSRect size = [[sheet_ sheetWindow] frameRectForContentRect:
|
| + NSMakeRect(tabViewSize.origin.x, tabViewSize.origin.y, windowWidth,
|
| + tabViewSize.size.height)];
|
| + [[sheet_ sheetWindow] setFrame:size display:YES];
|
| +}
|
| +
|
| +void SingleWebContentsDialogManagerViewsMac::Unhide() {
|
| + if (visible_)
|
| + return;
|
| + visible_ = true;
|
| + UpdateSheetPosition();
|
| + [sheet_ unhideSheet];
|
| +}
|
| +
|
| +void SingleWebContentsDialogManagerViewsMac::Show() {
|
| + if (visible_)
|
| + return;
|
| + visible_ = true;
|
| +
|
| + content::WebContents* web_contents = delegate_->GetWebContents();
|
| + if (!web_contents)
|
| + return;
|
| +
|
| + [[sheet_ sheetWindow] setStyleMask:NSBorderlessWindowMask];
|
| + [[sheet_ sheetWindow] setMovable:NO];
|
| + [[sheet_ sheetWindow] setAlphaValue:0.0];
|
| + [[sheet_ sheetWindow] setIgnoresMouseEvents:NO];
|
| +
|
| + NSWindow* parent_window = web_contents->GetTopLevelNativeWindow();
|
| + [parent_window addChildWindow:[sheet_ sheetWindow] ordered:NSWindowAbove];
|
| +
|
| + UpdateSheetPosition();
|
| + [sheet_ showSheetForWindow:[sheet_ sheetWindow]];
|
| +}
|
| +
|
| +void SingleWebContentsDialogManagerViewsMac::Hide() {
|
| + if (!visible_)
|
| + return;
|
| + visible_ = false;
|
| +
|
| + [sheet_ hideSheet];
|
| +}
|
| +
|
| +void SingleWebContentsDialogManagerViewsMac::Close() {
|
| + delegate_->WillClose(dialog());
|
| + NSWindow* parent_window =
|
| + delegate_->GetWebContents()->GetTopLevelNativeWindow();
|
| + [parent_window removeChildWindow:[sheet_ sheetWindow]];
|
| + [sheet_ closeSheetWithAnimation:true];
|
| + [[sheet_ sheetWindow] close];
|
| + [[sheet_ sheetWindow] setIgnoresMouseEvents:YES];
|
| + [sheet_ release];
|
| +}
|
| +
|
| +void SingleWebContentsDialogManagerViewsMac::Focus() {
|
| + // NOOP
|
| +}
|
| +
|
| +void SingleWebContentsDialogManagerViewsMac::Pulse() {
|
| + [sheet_ pulseSheet];
|
| +}
|
| +
|
| +gfx::NativeWindow SingleWebContentsDialogManagerViewsMac::dialog() {
|
| + return [sheet_ sheetWindow];
|
| +}
|
| +
|
| +void SingleWebContentsDialogManagerViewsMac::HostChanged(
|
| + web_modal::WebContentsModalDialogHost* new_host) {
|
| + NOTIMPLEMENTED();
|
| +}
|
|
|