| OLD | NEW |
| (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 #ifndef CHROME_BROWSER_UI_VIEWS_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H
_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H
_ | |
| 7 | |
| 8 #include <set> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "components/web_modal/modal_dialog_host.h" | |
| 12 #include "components/web_modal/single_web_contents_dialog_manager.h" | |
| 13 #include "ui/gfx/native_widget_types.h" | |
| 14 #include "ui/views/widget/widget_observer.h" | |
| 15 | |
| 16 namespace views { | |
| 17 class Widget; | |
| 18 } | |
| 19 | |
| 20 // Class for parenting a tab-modal views dialog off of a views browser. | |
| 21 class NativeWebContentsModalDialogManagerViews | |
| 22 : public web_modal::SingleWebContentsDialogManager, | |
| 23 public web_modal::ModalDialogHostObserver, | |
| 24 public views::WidgetObserver { | |
| 25 public: | |
| 26 NativeWebContentsModalDialogManagerViews( | |
| 27 gfx::NativeWindow dialog, | |
| 28 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate); | |
| 29 | |
| 30 ~NativeWebContentsModalDialogManagerViews() override; | |
| 31 | |
| 32 // Sets up this object to manage the |dialog_|. Registers for closing events | |
| 33 // in order to notify the delegate. | |
| 34 void ManageDialog(); | |
| 35 | |
| 36 // web_modal::SingleWebContentsDialogManager: | |
| 37 void Show() override; | |
| 38 void Hide() override; | |
| 39 void Close() override; | |
| 40 void Focus() override; | |
| 41 void Pulse() override; | |
| 42 | |
| 43 // web_modal::ModalDialogHostObserver: | |
| 44 void OnPositionRequiresUpdate() override; | |
| 45 void OnHostDestroying() override; | |
| 46 | |
| 47 // views::WidgetObserver: | |
| 48 | |
| 49 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget | |
| 50 // is explicitly closed, the destruction occurs within the same call | |
| 51 // stack. This avoids event races that lead to non-deterministic destruction | |
| 52 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden | |
| 53 // because OnWidgetClosing is *only* invoked on explicit close, not when the | |
| 54 // widget is implicitly destroyed due to its parent being closed. This | |
| 55 // situation occurs with app windows. WidgetClosing removes the observer, so | |
| 56 // only one of these two functions is ever invoked for a given widget. | |
| 57 void OnWidgetClosing(views::Widget* widget) override; | |
| 58 void OnWidgetDestroying(views::Widget* widget) override; | |
| 59 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override; | |
| 60 gfx::NativeWindow dialog() override; | |
| 61 | |
| 62 private: | |
| 63 static views::Widget* GetWidget(gfx::NativeWindow dialog); | |
| 64 void WidgetClosing(views::Widget* widget); | |
| 65 | |
| 66 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_; | |
| 67 gfx::NativeWindow dialog_; | |
| 68 web_modal::WebContentsModalDialogHost* host_; | |
| 69 bool host_destroying_; | |
| 70 std::set<views::Widget*> observed_widgets_; | |
| 71 std::set<views::Widget*> shown_widgets_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); | |
| 74 }; | |
| 75 | |
| 76 #endif // CHROME_BROWSER_UI_VIEWS_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEW
S_H_ | |
| OLD | NEW |