non_client_frame_view_ash.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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
  3. // found in the LICENSE file.
  4. #ifndef ASH_FRAME_NON_CLIENT_FRAME_VIEW_ASH_H_
  5. #define ASH_FRAME_NON_CLIENT_FRAME_VIEW_ASH_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/frame/frame_context_menu_controller.h"
  9. #include "ash/frame/header_view.h"
  10. #include "ash/wm/overview/overview_observer.h"
  11. #include "base/bind.h"
  12. #include "base/memory/weak_ptr.h"
  13. #include "chromeos/ui/frame/highlight_border_overlay.h"
  14. #include "third_party/skia/include/core/SkColor.h"
  15. #include "ui/base/metadata/metadata_header_macros.h"
  16. #include "ui/views/widget/widget.h"
  17. #include "ui/views/window/non_client_view.h"
  18. namespace chromeos {
  19. class FrameCaptionButtonContainerView;
  20. class ImmersiveFullscreenController;
  21. } // namespace chromeos
  22. namespace views {
  23. class Widget;
  24. } // namespace views
  25. namespace ash {
  26. class NonClientFrameViewAshImmersiveHelper;
  27. // A NonClientFrameView used for packaged apps, dialogs and other non-browser
  28. // windows. It supports immersive fullscreen. When in immersive fullscreen, the
  29. // client view takes up the entire widget and the window header is an overlay.
  30. // The window header overlay slides onscreen when the user hovers the mouse at
  31. // the top of the screen. See also views::CustomFrameView and
  32. // BrowserNonClientFrameViewAsh.
  33. class ASH_EXPORT NonClientFrameViewAsh
  34. : public views::NonClientFrameView,
  35. public FrameContextMenuController::Delegate {
  36. public:
  37. METADATA_HEADER(NonClientFrameViewAsh);
  38. // |control_immersive| controls whether ImmersiveFullscreenController is
  39. // created for the NonClientFrameViewAsh; if true and a WindowStateDelegate
  40. // has not been set on the WindowState associated with |frame|, then an
  41. // ImmersiveFullscreenController is created.
  42. explicit NonClientFrameViewAsh(views::Widget* frame);
  43. NonClientFrameViewAsh(const NonClientFrameViewAsh&) = delete;
  44. NonClientFrameViewAsh& operator=(const NonClientFrameViewAsh&) = delete;
  45. ~NonClientFrameViewAsh() override;
  46. static NonClientFrameViewAsh* Get(aura::Window* window);
  47. // Sets the caption button modeland updates the caption buttons.
  48. void SetCaptionButtonModel(
  49. std::unique_ptr<chromeos::CaptionButtonModel> model);
  50. // Inits |immersive_fullscreen_controller| so that the controller reveals
  51. // and hides |header_view_| in immersive fullscreen.
  52. // NonClientFrameViewAsh does not take ownership of
  53. // |immersive_fullscreen_controller|.
  54. void InitImmersiveFullscreenControllerForView(
  55. chromeos::ImmersiveFullscreenController* immersive_fullscreen_controller);
  56. // Sets the active and inactive frame colors. Note the inactive frame color
  57. // will have some transparency added when the frame is drawn.
  58. void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color);
  59. // Get the view of the header.
  60. HeaderView* GetHeaderView();
  61. // Calculate the client bounds for given window bounds.
  62. gfx::Rect GetClientBoundsForWindowBounds(
  63. const gfx::Rect& window_bounds) const;
  64. // views::NonClientFrameView:
  65. gfx::Rect GetBoundsForClientView() const override;
  66. gfx::Rect GetWindowBoundsForClientBounds(
  67. const gfx::Rect& client_bounds) const override;
  68. int NonClientHitTest(const gfx::Point& point) override;
  69. void GetWindowMask(const gfx::Size& size, SkPath* window_mask) override;
  70. void ResetWindowControls() override;
  71. void UpdateWindowIcon() override;
  72. void UpdateWindowTitle() override;
  73. void SizeConstraintsChanged() override;
  74. views::View::Views GetChildrenInZOrder() override;
  75. gfx::Size CalculatePreferredSize() const override;
  76. void Layout() override;
  77. gfx::Size GetMinimumSize() const override;
  78. gfx::Size GetMaximumSize() const override;
  79. void OnThemeChanged() override;
  80. // FrameContextMenuController::Delegate:
  81. bool ShouldShowContextMenu(views::View* source,
  82. const gfx::Point& screen_coords_point) override;
  83. // If |paint| is false, we should not paint the header. Used for overview mode
  84. // with OnOverviewModeStarting() and OnOverviewModeEnded() to hide/show the
  85. // header of v2 and ARC apps.
  86. virtual void SetShouldPaintHeader(bool paint);
  87. // Height from top of window to top of client area.
  88. int NonClientTopBorderHeight() const;
  89. // Expected height from top of window to top of client area when non client
  90. // view is visible.
  91. int NonClientTopBorderPreferredHeight() const;
  92. const views::View* GetAvatarIconViewForTest() const;
  93. SkColor GetActiveFrameColorForTest() const;
  94. SkColor GetInactiveFrameColorForTest() const;
  95. views::Widget* frame() { return frame_; }
  96. bool GetFrameEnabled() const { return frame_enabled_; }
  97. virtual void SetFrameEnabled(bool enabled);
  98. // Sets the callback to toggle the ARC++ resize-lock menu for this container
  99. // if applicable, which will be invoked via the keyboard shortcut.
  100. void SetToggleResizeLockMenuCallback(
  101. base::RepeatingCallback<void()> callback);
  102. base::RepeatingCallback<void()> GetToggleResizeLockMenuCallback() const;
  103. void ClearToggleResizeLockMenuCallback();
  104. protected:
  105. // views::View:
  106. void OnDidSchedulePaint(const gfx::Rect& r) override;
  107. void AddedToWidget() override;
  108. private:
  109. class OverlayView;
  110. friend class NonClientFrameViewAshTestWidgetDelegate;
  111. friend class TestWidgetConstraintsDelegate;
  112. friend class WindowServiceDelegateImplTest;
  113. // views::NonClientFrameView:
  114. bool DoesIntersectRect(const views::View* target,
  115. const gfx::Rect& rect) const override;
  116. // Returns the container for the minimize/maximize/close buttons that is
  117. // held by the HeaderView. Used in testing.
  118. chromeos::FrameCaptionButtonContainerView*
  119. GetFrameCaptionButtonContainerViewForTest();
  120. // Called when |frame_|'s "paint as active" state has changed.
  121. void PaintAsActiveChanged();
  122. // Updates the windows default frame colors if necessary.
  123. void UpdateDefaultFrameColors();
  124. // Generates a nine patch layer painted with a highlight border.
  125. std::unique_ptr<HighlightBorderOverlay> highlight_border_overlay_;
  126. // Not owned.
  127. views::Widget* const frame_;
  128. // View which contains the title and window controls.
  129. HeaderView* header_view_ = nullptr;
  130. OverlayView* overlay_view_ = nullptr;
  131. bool frame_enabled_ = true;
  132. std::unique_ptr<NonClientFrameViewAshImmersiveHelper> immersive_helper_;
  133. std::unique_ptr<FrameContextMenuController> frame_context_menu_controller_;
  134. base::CallbackListSubscription paint_as_active_subscription_ =
  135. frame_->RegisterPaintAsActiveChangedCallback(
  136. base::BindRepeating(&NonClientFrameViewAsh::PaintAsActiveChanged,
  137. base::Unretained(this)));
  138. base::RepeatingCallback<void()> toggle_resize_lock_menu_callback_;
  139. base::WeakPtrFactory<NonClientFrameViewAsh> weak_factory_{this};
  140. };
  141. } // namespace ash
  142. #endif // ASH_FRAME_NON_CLIENT_FRAME_VIEW_ASH_H_