Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1157)

Side by Side Diff: components/constrained_window/native_web_contents_modal_dialog_manager_views_mac.mm

Issue 1779383002: MacViews: Remove constrained window dependencies for certificate viewer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rsesek@ review - merge displayForWebContents & initWithCertificate, etc. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/constrained_window/native_web_contents_modal_dialog_manager _views_mac.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "components/constrained_window/constrained_window_views.h"
10 #include "components/guest_view/browser/guest_view_base.h"
11 #include "components/web_modal/web_contents_modal_dialog_manager.h"
12 #include "content/public/browser/web_contents.h"
13 #import "ui/gfx/mac/coordinate_conversion.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/views/widget/widget_delegate.h"
16
17 using web_modal::WebContentsModalDialogManager;
18 using web_modal::SingleWebContentsDialogManager;
19
20 namespace {
21
22 // Sets visibility and mouse events for a Cocoa NSWindow* and an attached sheet.
23 void SetSheetVisible(gfx::NativeWindow overlay, bool visible) {
24 CGFloat alpha = visible ? 1.0 : 0.0;
25 BOOL ignore_events = visible ? NO : YES;
26
27 // Don't allow interaction with the tab underneath the overlay.
28 [overlay setIgnoresMouseEvents:ignore_events];
29
30 [[overlay attachedSheet] setAlphaValue:alpha];
31 [[overlay attachedSheet] setIgnoresMouseEvents:ignore_events];
32 }
33
34 } // namespace
35
36 namespace constrained_window {
37
38 NativeWebContentsModalDialogManagerViewsMac::
39 NativeWebContentsModalDialogManagerViewsMac(
40 gfx::NativeWindow dialog,
41 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate)
42 : NativeWebContentsModalDialogManagerViews(dialog, native_delegate) {}
43
44 // NativeWebContentsModalDialogManagerViews:
45 void NativeWebContentsModalDialogManagerViewsMac::OnPositionRequiresUpdate() {
46 NativeWebContentsModalDialogManagerViews::OnPositionRequiresUpdate();
47
48 views::Widget* widget = GetWidget(dialog());
49 // Because the animation of SFCertificatePanel will change depending on the
50 // size of the parent, i.e. |widget|, make sure its size is the same as the
51 // area under the Chrome UI. The origin of the dialog then also needs to be
52 // updated to position the certificate viewer in the middle horizontally.
53 content::WebContents* web_contents = native_delegate()->GetWebContents();
54 CGFloat window_width =
55 NSWidth([web_contents->GetTopLevelNativeWindow() frame]);
56 gfx::Rect tab_view_size = web_contents->GetContainerBounds();
57 widget->SetBounds(gfx::Rect(tab_view_size.x(),
58 widget->GetWindowBoundsInScreen().y(),
59 window_width, tab_view_size.height()));
60 }
61
62 void NativeWebContentsModalDialogManagerViewsMac::ShowWidget(
63 views::Widget* widget) {
64 NSWindow* dialog_window = widget->GetNativeWindow();
65 [dialog_window setAlphaValue:0.0];
66 // Because |dialog_window| is transparent, it won't accept mouse events until
67 // ignoresMouseEvents is set. NSWindows start off accepting mouse events only
68 // in non-transparent areas - setting this explicitly will make the NSWindow
69 // accept mouse events everywhere regardless of window transparency.
70 [dialog_window setIgnoresMouseEvents:NO];
71
72 // Detect whether this is the first call to open the dialog. If yes, do this
73 // via the normal views method. If not, overlay and sheet are both already
74 // opened, and should be invisible, so return the sheet to full opacity.
75 if (![dialog_window attachedSheet]) {
76 NativeWebContentsModalDialogManagerViews::ShowWidget(widget);
77 // Make sure the dialog is sized correctly for the correct animations.
78 OnPositionRequiresUpdate();
79 return;
80 }
81
82 // Account for window resizes that happen while another tab is open.
83 OnPositionRequiresUpdate();
84 SetSheetVisible(dialog_window, true);
85 }
86
87 void NativeWebContentsModalDialogManagerViewsMac::HideWidget(
88 views::Widget* widget) {
89 NSWindow* dialog_window = widget->GetNativeWindow();
90 // Avoid views::Widget::Hide(), as a call to orderOut: on a NSWindow with an
91 // attached sheet will close the sheet. Instead, just set the sheet to 0
92 // opacity and don't accept click events.
93 SetSheetVisible(dialog_window, false);
94 }
95
96 } // namespace constrained_window
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698