Chromium Code Reviews| Index: components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.mm |
| diff --git a/components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.mm b/components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a12e8982cb8753ccab14e8860435ef30577ddf2b |
| --- /dev/null |
| +++ b/components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.mm |
| @@ -0,0 +1,82 @@ |
| +// 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 "components/constrained_window/constrained_window_views.h" |
| +#include "components/guest_view/browser/guest_view_base.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 constrained_window { |
| + |
| +// 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 |
|
msw
2016/08/22 23:01:19
nit: capitalize Chrome
Patti Lor
2016/08/25 08:25:12
Done.
|
| + // 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]); |
|
msw
2016/08/22 23:01:19
q: could this just use the web_contents->GetContai
Patti Lor
2016/08/25 08:25:12
The width of the WebContents isn't what we want si
msw
2016/08/25 15:30:47
Please add a short comment to that effect. (includ
Patti Lor
2016/08/26 07:38:29
Done.
|
| + 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(); |
| + // 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 NativeWebContentsModalDialogManagerViewsMac::HideWidget( |
| + views::Widget* widget) { |
| + NSWindow* dialog_window = widget->GetNativeWindow(); |
| + // 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); |
| +} |
| + |
| +// Sets visibility and mouse events for the overlay and its sheet. |
| +void NativeWebContentsModalDialogManagerViewsMac::SetSheetVisible( |
|
msw
2016/08/22 23:01:19
Could this just be a file-local anon-namespace hel
Patti Lor
2016/08/25 08:25:12
Done.
|
| + 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]; |
| +} |
| + |
| +} // namespace constrained_window |