| 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 "components/constrained_window/constrained_window_views.h" | 5 #include "components/constrained_window/constrained_window_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #if defined(OS_MACOSX) | 21 #if defined(OS_MACOSX) |
| 22 #import "components/constrained_window/native_web_contents_modal_dialog_manager_
views_mac.h" | 22 #import "components/constrained_window/native_web_contents_modal_dialog_manager_
views_mac.h" |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 using web_modal::ModalDialogHost; | 25 using web_modal::ModalDialogHost; |
| 26 using web_modal::ModalDialogHostObserver; | 26 using web_modal::ModalDialogHostObserver; |
| 27 | 27 |
| 28 namespace constrained_window { | 28 namespace constrained_window { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 ConstrainedWindowViewsClient* constrained_window_views_client = NULL; | 31 ConstrainedWindowViewsClient* constrained_window_views_client = nullptr; |
| 32 | 32 |
| 33 // The name of a key to store on the window handle to associate | 33 // The name of a key to store on the window handle to associate |
| 34 // WidgetModalDialogHostObserverViews with the Widget. | 34 // WidgetModalDialogHostObserverViews with the Widget. |
| 35 const char* const kWidgetModalDialogHostObserverViewsKey = | 35 const char* const kWidgetModalDialogHostObserverViewsKey = |
| 36 "__WIDGET_MODAL_DIALOG_HOST_OBSERVER_VIEWS__"; | 36 "__WIDGET_MODAL_DIALOG_HOST_OBSERVER_VIEWS__"; |
| 37 | 37 |
| 38 // Applies positioning changes from the ModalDialogHost to the Widget. | 38 // Applies positioning changes from the ModalDialogHost to the Widget. |
| 39 class WidgetModalDialogHostObserverViews | 39 class WidgetModalDialogHostObserverViews |
| 40 : public views::WidgetObserver, | 40 : public views::WidgetObserver, |
| 41 public ModalDialogHostObserver { | 41 public ModalDialogHostObserver { |
| 42 public: | 42 public: |
| 43 WidgetModalDialogHostObserverViews(ModalDialogHost* host, | 43 WidgetModalDialogHostObserverViews(ModalDialogHost* host, |
| 44 views::Widget* target_widget, | 44 views::Widget* target_widget, |
| 45 const char *const native_window_property) | 45 const char *const native_window_property) |
| 46 : host_(host), | 46 : host_(host), |
| 47 target_widget_(target_widget), | 47 target_widget_(target_widget), |
| 48 native_window_property_(native_window_property) { | 48 native_window_property_(native_window_property) { |
| 49 DCHECK(host_); | 49 DCHECK(host_); |
| 50 DCHECK(target_widget_); | 50 DCHECK(target_widget_); |
| 51 host_->AddObserver(this); | 51 host_->AddObserver(this); |
| 52 target_widget_->AddObserver(this); | 52 target_widget_->AddObserver(this); |
| 53 } | 53 } |
| 54 | 54 |
| 55 ~WidgetModalDialogHostObserverViews() override { | 55 ~WidgetModalDialogHostObserverViews() override { |
| 56 if (host_) | 56 if (host_) |
| 57 host_->RemoveObserver(this); | 57 host_->RemoveObserver(this); |
| 58 target_widget_->RemoveObserver(this); | 58 target_widget_->RemoveObserver(this); |
| 59 target_widget_->SetNativeWindowProperty(native_window_property_, NULL); | 59 target_widget_->SetNativeWindowProperty(native_window_property_, nullptr); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // WidgetObserver overrides | 62 // WidgetObserver overrides |
| 63 void OnWidgetClosing(views::Widget* widget) override { delete this; } | 63 void OnWidgetClosing(views::Widget* widget) override { delete this; } |
| 64 | 64 |
| 65 // WebContentsModalDialogHostObserver overrides | 65 // WebContentsModalDialogHostObserver overrides |
| 66 void OnPositionRequiresUpdate() override { | 66 void OnPositionRequiresUpdate() override { |
| 67 UpdateWidgetModalDialogPosition(target_widget_, host_); | 67 UpdateWidgetModalDialogPosition(target_widget_, host_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void OnHostDestroying() override { | 70 void OnHostDestroying() override { |
| 71 host_->RemoveObserver(this); | 71 host_->RemoveObserver(this); |
| 72 host_ = NULL; | 72 host_ = nullptr; |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 ModalDialogHost* host_; | 76 ModalDialogHost* host_; |
| 77 views::Widget* target_widget_; | 77 views::Widget* target_widget_; |
| 78 const char* const native_window_property_; | 78 const char* const native_window_property_; |
| 79 | 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(WidgetModalDialogHostObserverViews); | 80 DISALLOW_COPY_AND_ASSIGN(WidgetModalDialogHostObserverViews); |
| 81 }; | 81 }; |
| 82 | 82 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents) | 193 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents) |
| 194 ->delegate() | 194 ->delegate() |
| 195 ->GetWebContentsModalDialogHost() | 195 ->GetWebContentsModalDialogHost() |
| 196 ->GetHostView()); | 196 ->GetHostView()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog, | 199 views::Widget* CreateBrowserModalDialogViews(views::DialogDelegate* dialog, |
| 200 gfx::NativeWindow parent) { | 200 gfx::NativeWindow parent) { |
| 201 DCHECK_NE(ui::MODAL_TYPE_CHILD, dialog->GetModalType()); | 201 DCHECK_NE(ui::MODAL_TYPE_CHILD, dialog->GetModalType()); |
| 202 DCHECK_NE(ui::MODAL_TYPE_NONE, dialog->GetModalType()); | 202 DCHECK_NE(ui::MODAL_TYPE_NONE, dialog->GetModalType()); |
| 203 DCHECK(!parent || constrained_window_views_client); |
| 203 | 204 |
| 204 DCHECK(constrained_window_views_client); | |
| 205 gfx::NativeView parent_view = | 205 gfx::NativeView parent_view = |
| 206 parent ? constrained_window_views_client->GetDialogHostView(parent) | 206 parent ? constrained_window_views_client->GetDialogHostView(parent) |
| 207 : nullptr; | 207 : nullptr; |
| 208 views::Widget* widget = | 208 views::Widget* widget = |
| 209 views::DialogDelegate::CreateDialogWidget(dialog, NULL, parent_view); | 209 views::DialogDelegate::CreateDialogWidget(dialog, nullptr, parent_view); |
| 210 | 210 |
| 211 bool requires_positioning = dialog->ShouldUseCustomFrame(); | 211 bool requires_positioning = dialog->ShouldUseCustomFrame(); |
| 212 | 212 |
| 213 #if defined(OS_MACOSX) | 213 #if defined(OS_MACOSX) |
| 214 // On Mac, window modal dialogs are displayed as sheets, so their position is | 214 // On Mac, window modal dialogs are displayed as sheets, so their position is |
| 215 // managed by the parent window. | 215 // managed by the parent window. |
| 216 requires_positioning = false; | 216 requires_positioning = false; |
| 217 #endif | 217 #endif |
| 218 | 218 |
| 219 if (!requires_positioning) | 219 if (!requires_positioning) |
| 220 return widget; | 220 return widget; |
| 221 | 221 |
| 222 ModalDialogHost* host = constrained_window_views_client-> | 222 ModalDialogHost* host = |
| 223 GetModalDialogHost(parent); | 223 parent ? constrained_window_views_client->GetModalDialogHost(parent) |
| 224 : nullptr; |
| 224 if (host) { | 225 if (host) { |
| 225 DCHECK_EQ(parent_view, host->GetHostView()); | 226 DCHECK_EQ(parent_view, host->GetHostView()); |
| 226 ModalDialogHostObserver* dialog_host_observer = | 227 ModalDialogHostObserver* dialog_host_observer = |
| 227 new WidgetModalDialogHostObserverViews( | 228 new WidgetModalDialogHostObserverViews( |
| 228 host, widget, kWidgetModalDialogHostObserverViewsKey); | 229 host, widget, kWidgetModalDialogHostObserverViewsKey); |
| 229 dialog_host_observer->OnPositionRequiresUpdate(); | 230 dialog_host_observer->OnPositionRequiresUpdate(); |
| 230 } | 231 } |
| 231 return widget; | 232 return widget; |
| 232 } | 233 } |
| 233 | 234 |
| 234 } // namespace constrained window | 235 } // namespace constrained window |
| OLD | NEW |