modal_dialog_host.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2013 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. #ifndef COMPONENTS_WEB_MODAL_MODAL_DIALOG_HOST_H_
  5. #define COMPONENTS_WEB_MODAL_MODAL_DIALOG_HOST_H_
  6. #include "components/web_modal/web_modal_export.h"
  7. #include "ui/gfx/native_widget_types.h"
  8. namespace gfx {
  9. class Point;
  10. class Size;
  11. } // namespace gfx
  12. namespace web_modal {
  13. // Observer to be implemented to update modal dialogs when the host indicates
  14. // their position needs to be changed.
  15. class WEB_MODAL_EXPORT ModalDialogHostObserver {
  16. public:
  17. virtual ~ModalDialogHostObserver();
  18. virtual void OnPositionRequiresUpdate() = 0;
  19. // The host must call this method on each observer before destruction.
  20. virtual void OnHostDestroying() = 0;
  21. };
  22. // Interface for supporting positioning of modal dialogs over a window/widget.
  23. class WEB_MODAL_EXPORT ModalDialogHost {
  24. public:
  25. virtual ~ModalDialogHost();
  26. // Returns the view against which the dialog is positioned and parented.
  27. virtual gfx::NativeView GetHostView() const = 0;
  28. // Gets the position for the dialog in coordinates relative to the host view.
  29. virtual gfx::Point GetDialogPosition(const gfx::Size& size) = 0;
  30. // Returns whether a dialog currently about to be shown should be activated.
  31. virtual bool ShouldActivateDialog() const;
  32. // Add/remove observer. The host must implement these methods, store the
  33. // observers in a list, and call OnHostDestroying() on each before host
  34. // destruction. See https://crbug.com/1170577
  35. virtual void AddObserver(ModalDialogHostObserver* observer) = 0;
  36. virtual void RemoveObserver(ModalDialogHostObserver* observer) = 0;
  37. };
  38. } // namespace web_modal
  39. #endif // COMPONENTS_WEB_MODAL_MODAL_DIALOG_HOST_H_