Commit 9d0ea200 authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Unwind tab-constrained sheets on macOS.

This is no longer used and has been getting increasingly buggy as Chrome
and macOS evolve (see bugs 762915, 983451, 1020622, 1078158, 1098786).
The two uses have since been removed, so remove the support code.

Bug: 1111423
Change-Id: I07b5268dd07c2659ed1bd710bfaae704804e5daf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2347000
Commit-Queue: David Benjamin <davidben@chromium.org>
Auto-Submit: David Benjamin <davidben@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799746}
parent 9914d215
......@@ -12,8 +12,6 @@ static_library("constrained_window") {
"constrained_window_views_client.h",
"native_web_contents_modal_dialog_manager_views.cc",
"native_web_contents_modal_dialog_manager_views.h",
"native_web_contents_modal_dialog_manager_views_mac.h",
"native_web_contents_modal_dialog_manager_views_mac.mm",
"show_modal_dialog_views.cc",
]
......
......@@ -22,10 +22,6 @@
#include "ui/views/widget/widget_observer.h"
#include "ui/views/window/dialog_delegate.h"
#if defined(OS_APPLE)
#import "components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.h"
#endif
using web_modal::ModalDialogHost;
using web_modal::ModalDialogHostObserver;
......@@ -184,28 +180,6 @@ views::Widget* ShowWebModalDialogViews(
return widget;
}
#if defined(OS_APPLE)
views::Widget* ShowWebModalDialogWithOverlayViews(
views::WidgetDelegate* dialog,
content::WebContents* initiator_web_contents,
base::OnceCallback<void(views::Widget*)> show_sheet) {
DCHECK(CurrentClient());
// For embedded WebContents, use the embedder's WebContents for constrained
// window.
content::WebContents* web_contents =
GetTopLevelWebContents(initiator_web_contents);
views::Widget* widget = CreateWebModalDialogViews(dialog, web_contents);
web_modal::WebContentsModalDialogManager* manager =
web_modal::WebContentsModalDialogManager::FromWebContents(web_contents);
std::unique_ptr<web_modal::SingleWebContentsDialogManager> dialog_manager(
new NativeWebContentsModalDialogManagerViewsMac(
widget->GetNativeWindow(), manager, std::move(show_sheet)));
manager->ShowDialogWithManager(widget->GetNativeWindow(),
std::move(dialog_manager));
return widget;
}
#endif
views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
content::WebContents* web_contents) {
DCHECK_EQ(ui::MODAL_TYPE_CHILD, dialog->GetModalType());
......
......@@ -7,7 +7,6 @@
#include <memory>
#include "base/callback_forward.h"
#include "build/build_config.h"
#include "ui/gfx/native_widget_types.h"
......@@ -58,20 +57,6 @@ views::Widget* ShowWebModalDialogViews(
views::WidgetDelegate* dialog,
content::WebContents* initiator_web_contents);
#if defined(OS_APPLE)
// Like ShowWebModalDialogViews, but used to show a native dialog "sheet" on
// Mac. Sheets are always modal to their parent window. To make them tab-modal,
// this provides an invisible tab-modal overlay window managed by
// WebContentsModalDialogManager, which can host a dialog sheet. The caller
// should not create the sheet until |show_sheet| is called, which may be
// synchronous or in a separate event loop iteration. |show_sheet| is passed the
// overlay window the attach the sheet to.
views::Widget* ShowWebModalDialogWithOverlayViews(
views::WidgetDelegate* dialog,
content::WebContents* initiator_web_contents,
base::OnceCallback<void(views::Widget*)> show_sheet);
#endif
// Create a widget for |dialog| that is modal to |web_contents|.
// The modal type of |dialog->GetModalType()| must be ui::MODAL_TYPE_CHILD.
views::Widget* CreateWebModalDialogViews(views::WidgetDelegate* dialog,
......
......@@ -97,7 +97,12 @@ void NativeWebContentsModalDialogManagerViews::Show() {
widget->GetNativeWindow()->parent()));
}
#endif
ShowWidget(widget);
// |host_| may be null during tab drag on Views/Win32.
//
// TODO(https://crbug.com/1119431): This null check may be out of date.
if (host_)
constrained_window::UpdateWebContentsModalDialogPosition(widget, host_);
widget->Show();
if (host_->ShouldActivateDialog())
Focus();
......@@ -110,7 +115,7 @@ void NativeWebContentsModalDialogManagerViews::Show() {
#if !defined(USE_AURA)
// Don't re-animate when switching tabs. Note this is done on Mac only after
// the initial ShowWidget() call above, and then "sticks" for later calls.
// the initial Show() call above, and then "sticks" for later calls.
// TODO(tapted): Consolidate this codepath with Aura.
widget->SetVisibilityAnimationTransition(views::Widget::ANIMATE_HIDE);
#endif
......@@ -123,7 +128,7 @@ void NativeWebContentsModalDialogManagerViews::Hide() {
suspend.reset(new wm::SuspendChildWindowVisibilityAnimations(
widget->GetNativeWindow()->parent()));
#endif
HideWidget(widget);
widget->Hide();
}
void NativeWebContentsModalDialogManagerViews::Close() {
......@@ -195,19 +200,6 @@ gfx::NativeWindow NativeWebContentsModalDialogManagerViews::dialog() {
return dialog_;
}
void NativeWebContentsModalDialogManagerViews::ShowWidget(
views::Widget* widget) {
// |host_| may be NULL during tab drag on Views/Win32.
if (host_)
constrained_window::UpdateWebContentsModalDialogPosition(widget, host_);
widget->Show();
}
void NativeWebContentsModalDialogManagerViews::HideWidget(
views::Widget* widget) {
widget->Hide();
}
views::Widget* NativeWebContentsModalDialogManagerViews::GetWidget(
gfx::NativeWindow dialog) {
views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog);
......
......@@ -66,12 +66,6 @@ class NativeWebContentsModalDialogManagerViews
return native_delegate_;
}
// By default just calls widget->Show() or Hide(), but allows a derived class
// to override in order to hide an alternate way (e.g. if the default hide
// would tear down attached dialogs too early).
virtual void ShowWidget(views::Widget* widget);
virtual void HideWidget(views::Widget* widget);
static views::Widget* GetWidget(gfx::NativeWindow dialog);
private:
......
// 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.
#ifndef COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_MAC_H_
#define COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_MAC_H_
#include "base/callback.h"
#include "components/constrained_window/native_web_contents_modal_dialog_manager_views.h"
namespace web_modal {
class SingleWebContentsDialogManagerDelegate;
}
namespace constrained_window {
// 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,
base::OnceCallback<void(views::Widget*)> show_sheet);
~NativeWebContentsModalDialogManagerViewsMac() override;
// NativeWebContentsModalDialogManagerViews:
void OnPositionRequiresUpdate() override;
void ShowWidget(views::Widget* widget) override;
void HideWidget(views::Widget* widget) override;
private:
base::OnceCallback<void(views::Widget*)> show_sheet_;
DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViewsMac);
};
} // namespace constrained_window
#endif // COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_MAC_H_
// 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.
#include "components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.h"
#import <Cocoa/Cocoa.h>
#include <utility>
#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"
#import "ui/gfx/mac/coordinate_conversion.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
using web_modal::WebContentsModalDialogManager;
using web_modal::SingleWebContentsDialogManager;
namespace {
// Sets visibility and mouse events for a Cocoa NSWindow* and an attached sheet.
void SetSheetVisible(gfx::NativeWindow native_window, bool visible) {
NSWindow* overlay = native_window.GetNativeNSWindow();
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];
}
} // namespace
namespace constrained_window {
NativeWebContentsModalDialogManagerViewsMac::
NativeWebContentsModalDialogManagerViewsMac(
gfx::NativeWindow dialog,
web_modal::SingleWebContentsDialogManagerDelegate* native_delegate,
base::OnceCallback<void(views::Widget*)> show_sheet)
: NativeWebContentsModalDialogManagerViews(dialog, native_delegate),
show_sheet_(std::move(show_sheet)) {}
NativeWebContentsModalDialogManagerViewsMac::
~NativeWebContentsModalDialogManagerViewsMac() = default;
// NativeWebContentsModalDialogManagerViews:
void NativeWebContentsModalDialogManagerViewsMac::OnPositionRequiresUpdate() {
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();
// Note: Can't use WebContents container bounds here because it doesn't
// include the DevTool panel width.
CGFloat window_width = NSWidth(
[web_contents->GetTopLevelNativeWindow().GetNativeNSWindow() 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 NativeWebContentsModalDialogManagerViewsMac::ShowWidget(
views::Widget* widget) {
NSWindow* dialog_window = widget->GetNativeWindow().GetNativeNSWindow();
[dialog_window setAlphaValue:0.0];
// Because |dialog_window| is transparent, it won't accept mouse events until
// ignoresMouseEvents is set. NSWindows start off accepting mouse events only
// in non-transparent areas - setting this explicitly will make the NSWindow
// accept mouse events everywhere regardless of window transparency.
[dialog_window setIgnoresMouseEvents:NO];
// 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();
if (!show_sheet_.is_null())
std::move(show_sheet_).Run(GetWidget(dialog()));
return;
}
// The sheet must already have been shown.
DCHECK(show_sheet_.is_null());
// Account for window resizes that happen while another tab is open.
OnPositionRequiresUpdate();
SetSheetVisible(dialog_window, true);
}
void NativeWebContentsModalDialogManagerViewsMac::HideWidget(
views::Widget* widget) {
NSWindow* dialog_window = widget->GetNativeWindow().GetNativeNSWindow();
// Avoid views::Widget::Hide(), 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);
}
} // namespace constrained_window
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