| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/constrained_window/native_web_contents_modal_dialog_manager
_views_mac.h" | 5 #include "components/constrained_window/native_web_contents_modal_dialog_manager
_views_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "components/constrained_window/constrained_window_views.h" | 9 #include "components/constrained_window/constrained_window_views.h" |
| 10 #include "components/guest_view/browser/guest_view_base.h" | 10 #include "components/guest_view/browser/guest_view_base.h" |
| 11 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 11 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #import "ui/gfx/mac/coordinate_conversion.h" | 13 #import "ui/gfx/mac/coordinate_conversion.h" |
| 14 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 15 #include "ui/views/widget/widget_delegate.h" | 15 #include "ui/views/widget/widget_delegate.h" |
| 16 | 16 |
| 17 using web_modal::WebContentsModalDialogManager; | 17 using web_modal::WebContentsModalDialogManager; |
| 18 using web_modal::SingleWebContentsDialogManager; | 18 using web_modal::SingleWebContentsDialogManager; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Sets visibility and mouse events for a Cocoa NSWindow* and an attached sheet. | 22 // Sets visibility and mouse events for a Cocoa NSWindow* and an attached sheet. |
| 23 void SetSheetVisible(gfx::NativeWindow overlay, bool visible) { | 23 void SetSheetVisible(gfx::NativeWindow overlay, bool visible) { |
| 24 CGFloat alpha = visible ? 1.0 : 0.0; | |
| 25 BOOL ignore_events = visible ? NO : YES; | 24 BOOL ignore_events = visible ? NO : YES; |
| 26 | 25 |
| 27 // Don't allow interaction with the tab underneath the overlay. | 26 // Don't allow interaction with the tab underneath the overlay. |
| 28 [overlay setIgnoresMouseEvents:ignore_events]; | 27 [overlay setIgnoresMouseEvents:ignore_events]; |
| 29 | 28 |
| 30 [[overlay attachedSheet] setAlphaValue:alpha]; | 29 [[overlay attachedSheet] setAlphaValue:visible ? 1.0 : 0.0]; |
| 31 [[overlay attachedSheet] setIgnoresMouseEvents:ignore_events]; | 30 [[overlay attachedSheet] setIgnoresMouseEvents:ignore_events]; |
| 31 |
| 32 if (visible) { |
| 33 // When showing the sheet, re-order the overlay and sheet to be on top of |
| 34 // any other sheet/overlay pairs which may be open at the same time. Without |
| 35 // doing this, the sheet and overlay become obscured behind overlays for |
| 36 // other sheets, which block mouse events intended for the current sheet. |
| 37 NSWindow* parent = [overlay parentWindow]; |
| 38 [parent removeChildWindow:overlay]; |
| 39 [parent addChildWindow:overlay ordered:NSWindowAbove]; |
| 40 [overlay removeChildWindow:[overlay attachedSheet]]; |
| 41 [overlay addChildWindow:[overlay attachedSheet] ordered:NSWindowAbove]; |
| 42 } |
| 32 } | 43 } |
| 33 | 44 |
| 34 } // namespace | 45 } // namespace |
| 35 | 46 |
| 36 namespace constrained_window { | 47 namespace constrained_window { |
| 37 | 48 |
| 38 NativeWebContentsModalDialogManagerViewsMac:: | 49 NativeWebContentsModalDialogManagerViewsMac:: |
| 39 NativeWebContentsModalDialogManagerViewsMac( | 50 NativeWebContentsModalDialogManagerViewsMac( |
| 40 gfx::NativeWindow dialog, | 51 gfx::NativeWindow dialog, |
| 41 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate) | 52 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 void NativeWebContentsModalDialogManagerViewsMac::HideWidget( | 100 void NativeWebContentsModalDialogManagerViewsMac::HideWidget( |
| 90 views::Widget* widget) { | 101 views::Widget* widget) { |
| 91 NSWindow* dialog_window = widget->GetNativeWindow(); | 102 NSWindow* dialog_window = widget->GetNativeWindow(); |
| 92 // Avoid views::Widget::Hide(), as a call to orderOut: on a NSWindow with an | 103 // Avoid views::Widget::Hide(), as a call to orderOut: on a NSWindow with an |
| 93 // attached sheet will close the sheet. Instead, just set the sheet to 0 | 104 // attached sheet will close the sheet. Instead, just set the sheet to 0 |
| 94 // opacity and don't accept click events. | 105 // opacity and don't accept click events. |
| 95 SetSheetVisible(dialog_window, false); | 106 SetSheetVisible(dialog_window, false); |
| 96 } | 107 } |
| 97 | 108 |
| 98 } // namespace constrained_window | 109 } // namespace constrained_window |
| OLD | NEW |