| Index: chrome/browser/ui/cocoa/native_web_contents_modal_dialog_manager_views_mac.mm
|
| diff --git a/chrome/browser/ui/cocoa/native_web_contents_modal_dialog_manager_views_mac.mm b/chrome/browser/ui/cocoa/native_web_contents_modal_dialog_manager_views_mac.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..04ce7fd8ecfa40e0f8059cf8e003cde8f0ae004e
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/cocoa/native_web_contents_modal_dialog_manager_views_mac.mm
|
| @@ -0,0 +1,106 @@
|
| +// Copyright 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.
|
| +
|
| +#import <Cocoa/Cocoa.h>
|
| +
|
| +#include "chrome/browser/ui/views/native_web_contents_modal_dialog_manager_views.h"
|
| +#include "components/constrained_window/constrained_window_views.h"
|
| +#include "components/web_modal/web_contents_modal_dialog_manager.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "ui/views/widget/widget.h"
|
| +#include "ui/views/widget/widget_delegate.h"
|
| +
|
| +namespace {
|
| +
|
| +// Class for parenting a Mac Cocoa sheet on a views tab modal dialog off of a
|
| +// views browser, e.g. for tab-modal Cocoa sheets. Since Cocoa sheets are modal
|
| +// to the parent window, the sheet is instead parented to an invisible views
|
| +// overlay window which is tab-modal.
|
| +class NativeWebContentsModalDialogManagerViewsMac
|
| + : public NativeWebContentsModalDialogManagerViews {
|
| + public:
|
| + NativeWebContentsModalDialogManagerViewsMac(
|
| + gfx::NativeWindow dialog,
|
| + web_modal::SingleWebContentsDialogManagerDelegate* native_delegate)
|
| + : NativeWebContentsModalDialogManagerViews(dialog, native_delegate) {}
|
| +
|
| + // NativeWebContentsModalDialogManagerViews:
|
| + void OnPositionRequiresUpdate() override {
|
| + NativeWebContentsModalDialogManagerViews::OnPositionRequiresUpdate();
|
| +
|
| + views::Widget* widget = GetWidget(dialog());
|
| + // Because the animation of SFCertificatePanel will change depending on the
|
| + // size of the parent, i.e. |widget|, make sure its size is the same
|
| + // as the area under the chrome UI. The origin of the dialog then also needs
|
| + // to be updated to position the certificate viewer in the middle
|
| + // horizontally.
|
| + content::WebContents* web_contents = native_delegate()->GetWebContents();
|
| + CGFloat window_width =
|
| + NSWidth([web_contents->GetTopLevelNativeWindow() frame]);
|
| + gfx::Rect tab_view_size = web_contents->GetContainerBounds();
|
| + widget->SetBounds(gfx::Rect(tab_view_size.x(),
|
| + widget->GetWindowBoundsInScreen().y(),
|
| + window_width, tab_view_size.height()));
|
| + }
|
| +
|
| + void ShowWidget(views::Widget* widget) override {
|
| + NSWindow* dialog_window = widget->GetNativeWindow();
|
| + // Detect whether this is the first call to open the dialog. If yes, do this
|
| + // via the normal views method. If not, overlay and sheet are both already
|
| + // opened, and should be invisible, so return the sheet to full opacity.
|
| + if (![dialog_window attachedSheet]) {
|
| + NativeWebContentsModalDialogManagerViews::ShowWidget(widget);
|
| + // Make sure the dialog is sized correctly for the correct animations.
|
| + OnPositionRequiresUpdate();
|
| + return;
|
| + }
|
| +
|
| + // Account for window resizes that happen while another tab is open.
|
| + OnPositionRequiresUpdate();
|
| + [dialog_window setAlphaValue:0.0];
|
| + SetSheetVisible(dialog_window, true);
|
| + }
|
| +
|
| + void HideWidget(views::Widget* widget) override {
|
| + NSWindow* dialog_window = widget->GetNativeWindow();
|
| + if (![dialog_window attachedSheet]) {
|
| + NativeWebContentsModalDialogManagerViews::HideWidget(widget);
|
| + return;
|
| + }
|
| +
|
| + // Avoid views::Widget::Show(), as a call to orderOut: on a NSWindow with an
|
| + // attached sheet will close the sheet. Instead, just set the sheet to 0
|
| + // opacity and don't accept click events.
|
| + SetSheetVisible(dialog_window, false);
|
| + }
|
| +
|
| + private:
|
| + // Sets visibility and mouse events for the overlay and its sheet.
|
| + void SetSheetVisible(gfx::NativeWindow overlay, bool visible) {
|
| + CGFloat alpha = visible ? 1.0 : 0.0;
|
| + BOOL ignore_events = visible ? NO : YES;
|
| +
|
| + // Don't allow interaction with the tab underneath the overlay.
|
| + [overlay setIgnoresMouseEvents:ignore_events];
|
| +
|
| + [[overlay attachedSheet] setAlphaValue:alpha];
|
| + [[overlay attachedSheet] setIgnoresMouseEvents:ignore_events];
|
| + }
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViewsMac);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +namespace web_modal {
|
| +
|
| +SingleWebContentsDialogManager*
|
| +WebContentsModalDialogManager::CreateNativeWebModalOverlayManager(
|
| + gfx::NativeWindow dialog,
|
| + SingleWebContentsDialogManagerDelegate* native_delegate) {
|
| + return new NativeWebContentsModalDialogManagerViewsMac(dialog,
|
| + native_delegate);
|
| +}
|
| +
|
| +} // namespace web_modal
|
|
|