OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 5 #include <set> |
6 | 6 |
7 #include "chrome/browser/platform_util.h" | 7 #include "chrome/browser/platform_util.h" |
8 #include "chrome/browser/ui/native_web_contents_modal_dialog_manager.h" | 8 #include "chrome/browser/ui/native_web_contents_modal_dialog_manager.h" |
9 #include "chrome/browser/ui/views/constrained_window_views.h" | 9 #include "chrome/browser/ui/views/constrained_window_views.h" |
10 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" | 10 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // We don't necessarily have a RootWindow yet. | 97 // We don't necessarily have a RootWindow yet. |
98 if (widget->GetNativeView()->GetRootWindow()) | 98 if (widget->GetNativeView()->GetRootWindow()) |
99 widget->GetNativeView()->Focus(); | 99 widget->GetNativeView()->Focus(); |
100 #endif | 100 #endif |
101 } | 101 } |
102 | 102 |
103 virtual void PulseDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | 103 virtual void PulseDialog(NativeWebContentsModalDialog dialog) OVERRIDE { |
104 } | 104 } |
105 | 105 |
106 // views::WidgetObserver overrides | 106 // views::WidgetObserver overrides |
| 107 |
| 108 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget |
| 109 // is explicitly closed, the destruction occurs within the same call |
| 110 // stack. This avoids event races that lead to non-deterministic destruction |
| 111 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden |
| 112 // because OnWidgetClosing is *only* invoked on explicit close, not when the |
| 113 // widget is implicitly destroyed due to its parent being closed. This |
| 114 // situation occurs with app windows. WidgetClosing removes the observer, so |
| 115 // only one of these two functions is ever invoked for a given widget. |
107 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { | 116 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { |
| 117 WidgetClosing(widget); |
| 118 } |
| 119 |
| 120 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { |
| 121 WidgetClosing(widget); |
| 122 } |
| 123 |
| 124 private: |
| 125 static views::Widget* GetWidget(NativeWebContentsModalDialog dialog) { |
| 126 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); |
| 127 DCHECK(widget); |
| 128 return widget; |
| 129 } |
| 130 |
| 131 void WidgetClosing(views::Widget* widget) { |
108 #if defined(USE_ASH) | 132 #if defined(USE_ASH) |
109 gfx::NativeView view = platform_util::GetParent(widget->GetNativeView()); | 133 gfx::NativeView view = platform_util::GetParent(widget->GetNativeView()); |
110 // Allow the parent to animate again. | 134 // Allow the parent to animate again. |
111 if (view && view->parent()) | 135 if (view && view->parent()) |
112 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); | 136 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); |
113 #endif | 137 #endif |
114 widget->RemoveObserver(this); | 138 widget->RemoveObserver(this); |
115 native_delegate_->WillClose(widget->GetNativeView()); | 139 native_delegate_->WillClose(widget->GetNativeView()); |
116 observed_widgets_.erase(widget); | 140 observed_widgets_.erase(widget); |
117 } | 141 } |
118 | 142 |
119 private: | |
120 static views::Widget* GetWidget(NativeWebContentsModalDialog dialog) { | |
121 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); | |
122 DCHECK(widget); | |
123 return widget; | |
124 } | |
125 | |
126 NativeWebContentsModalDialogManagerDelegate* native_delegate_; | 143 NativeWebContentsModalDialogManagerDelegate* native_delegate_; |
127 std::set<views::Widget*> observed_widgets_; | 144 std::set<views::Widget*> observed_widgets_; |
128 | 145 |
129 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); | 146 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); |
130 }; | 147 }; |
131 | 148 |
132 } // namespace | 149 } // namespace |
133 | 150 |
134 NativeWebContentsModalDialogManager* WebContentsModalDialogManager:: | 151 NativeWebContentsModalDialogManager* WebContentsModalDialogManager:: |
135 CreateNativeManager( | 152 CreateNativeManager( |
136 NativeWebContentsModalDialogManagerDelegate* native_delegate) { | 153 NativeWebContentsModalDialogManagerDelegate* native_delegate) { |
137 return new NativeWebContentsModalDialogManagerViews(native_delegate); | 154 return new NativeWebContentsModalDialogManagerViews(native_delegate); |
138 } | 155 } |
OLD | NEW |