window_preview.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2018 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_SHELF_WINDOW_PREVIEW_H_
  5. #define ASH_SHELF_WINDOW_PREVIEW_H_
  6. #include "ui/views/view.h"
  7. namespace aura {
  8. class Window;
  9. }
  10. namespace views {
  11. class ImageButton;
  12. class Label;
  13. } // namespace views
  14. namespace ash {
  15. class WindowPreviewView;
  16. // A view used by the shelf which shows a mirror view of the the window
  17. // associated with the window of the shelf icon where the mouse is hovered over.
  18. // The view is also contains a button which closes the window if clicked. Other
  19. // click events will activate the window and dismiss the bubble which holds this
  20. // view.
  21. class WindowPreview : public views::View {
  22. public:
  23. class Delegate {
  24. public:
  25. // Returns the maximum ratio across all current preview windows.
  26. virtual float GetMaxPreviewRatio() const = 0;
  27. // Notify the delegate that the preview has closed.
  28. virtual void OnPreviewDismissed(WindowPreview* preview) = 0;
  29. // Notify the delegate that the preview has been activated.
  30. virtual void OnPreviewActivated(WindowPreview* preview) = 0;
  31. protected:
  32. virtual ~Delegate() {}
  33. };
  34. WindowPreview(aura::Window* window, Delegate* delegate);
  35. WindowPreview(const WindowPreview&) = delete;
  36. WindowPreview& operator=(const WindowPreview&) = delete;
  37. ~WindowPreview() override;
  38. // views::View:
  39. gfx::Size CalculatePreferredSize() const override;
  40. void Layout() override;
  41. bool OnMousePressed(const ui::MouseEvent& event) override;
  42. const char* GetClassName() const override;
  43. void OnThemeChanged() override;
  44. const WindowPreviewView* preview_view() const { return preview_view_; }
  45. private:
  46. // All the preview containers have the same size.
  47. gfx::Size GetPreviewContainerSize() const;
  48. void CloseButtonPressed();
  49. // Child views.
  50. views::ImageButton* close_button_ = nullptr;
  51. views::Label* title_ = nullptr;
  52. views::View* preview_container_view_ = nullptr;
  53. WindowPreviewView* preview_view_ = nullptr;
  54. // Unowned pointer to the delegate. The delegate should outlive this instance.
  55. Delegate* delegate_;
  56. };
  57. } // namespace ash
  58. #endif // ASH_SHELF_WINDOW_PREVIEW_H_