search_result_page_anchored_dialog.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2020 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 ASH_APP_LIST_VIEWS_SEARCH_RESULT_PAGE_ANCHORED_DIALOG_H_
  5. #define ASH_APP_LIST_VIEWS_SEARCH_RESULT_PAGE_ANCHORED_DIALOG_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "base/scoped_multi_source_observation.h"
  9. #include "ui/views/view_observer.h"
  10. #include "ui/views/widget/widget.h"
  11. #include "ui/views/widget/widget_observer.h"
  12. namespace gfx {
  13. class Rect;
  14. }
  15. namespace views {
  16. class WidgetDelegate;
  17. }
  18. namespace ash {
  19. // A helper to keep track and manage bounds of a dialog window anchored to the
  20. // search results app list page.
  21. class SearchResultPageAnchoredDialog : public views::WidgetObserver,
  22. public views::ViewObserver {
  23. public:
  24. // Creates a widget for the provided dialog delegate view.
  25. // |dialog| - The dialog delegate view whose widget this should manage.
  26. // |host_view| - The view that is "hosting" the dialog - the dialog widget
  27. // will be parented by the host view's widget, and the dialog will be
  28. // positioned relative to this view's bounds.
  29. // |callback| - A closure called when the dialog widget gets closed. The
  30. // callback will not be called when the SearchResultPageAnchoredDialog
  31. // gets destroyed,
  32. SearchResultPageAnchoredDialog(std::unique_ptr<views::WidgetDelegate> dialog,
  33. views::View* host_view,
  34. base::OnceClosure callback);
  35. SearchResultPageAnchoredDialog(const SearchResultPageAnchoredDialog& other) =
  36. delete;
  37. SearchResultPageAnchoredDialog& operator=(
  38. const SearchResultPageAnchoredDialog& other) = delete;
  39. ~SearchResultPageAnchoredDialog() override;
  40. // Repositions the dialog widget bounds relative to the current host view
  41. // bounds.
  42. void UpdateBounds();
  43. // Adjusts the vertical translate offset to be used during search results page
  44. // animation. The default offset follows the search box bounds translation
  45. // within the host view bounds.
  46. float AdjustVerticalTransformOffset(float default_offset);
  47. // views::WidgetObserver:
  48. void OnWidgetDestroying(views::Widget* widget) override;
  49. void OnWidgetBoundsChanged(views::Widget* widget,
  50. const gfx::Rect& new_bounds) override;
  51. // views::ViewObserver:
  52. void OnViewBoundsChanged(views::View* observed_view) override;
  53. void OnViewPreferredSizeChanged(views::View* observed_view) override;
  54. views::Widget* widget() { return widget_; }
  55. private:
  56. views::Widget* widget_ = nullptr;
  57. views::View* const host_view_;
  58. base::OnceClosure callback_;
  59. base::ScopedMultiSourceObservation<views::Widget, views::WidgetObserver>
  60. widget_observations_{this};
  61. base::ScopedMultiSourceObservation<views::View, views::ViewObserver>
  62. view_observations_{this};
  63. };
  64. } // namespace ash
  65. #endif // ASH_APP_LIST_VIEWS_SEARCH_RESULT_PAGE_ANCHORED_DIALOG_H_