| OLD | NEW |
| (Empty) |
| 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 | |
| 5 #ifndef ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ | |
| 6 #define ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "ash/frame/caption_buttons/frame_size_button_delegate.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "ui/gfx/animation/animation_delegate.h" | |
| 14 #include "ui/views/controls/button/button.h" | |
| 15 #include "ui/views/view.h" | |
| 16 | |
| 17 namespace gfx { | |
| 18 class SlideAnimation; | |
| 19 enum class VectorIconId; | |
| 20 } | |
| 21 | |
| 22 namespace views { | |
| 23 class Widget; | |
| 24 } | |
| 25 | |
| 26 namespace ash { | |
| 27 | |
| 28 // Container view for the frame caption buttons. It performs the appropriate | |
| 29 // action when a caption button is clicked. | |
| 30 class ASH_EXPORT FrameCaptionButtonContainerView | |
| 31 : public views::View, | |
| 32 public views::ButtonListener, | |
| 33 public FrameSizeButtonDelegate, | |
| 34 public gfx::AnimationDelegate { | |
| 35 public: | |
| 36 static const char kViewClassName[]; | |
| 37 | |
| 38 // |frame| is the views::Widget that the caption buttons act on. | |
| 39 explicit FrameCaptionButtonContainerView(views::Widget* frame); | |
| 40 ~FrameCaptionButtonContainerView() override; | |
| 41 | |
| 42 // For testing. | |
| 43 class ASH_EXPORT TestApi { | |
| 44 public: | |
| 45 explicit TestApi(FrameCaptionButtonContainerView* container_view) | |
| 46 : container_view_(container_view) {} | |
| 47 | |
| 48 void EndAnimations(); | |
| 49 | |
| 50 FrameCaptionButton* minimize_button() const { | |
| 51 return container_view_->minimize_button_; | |
| 52 } | |
| 53 | |
| 54 FrameCaptionButton* size_button() const { | |
| 55 return container_view_->size_button_; | |
| 56 } | |
| 57 | |
| 58 FrameCaptionButton* close_button() const { | |
| 59 return container_view_->close_button_; | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 FrameCaptionButtonContainerView* container_view_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(TestApi); | |
| 66 }; | |
| 67 | |
| 68 // Sets the id of the vector image to paint the button for |icon|. The | |
| 69 // FrameCaptionButtonContainerView will keep track of the image to use for | |
| 70 // |icon| even if none of the buttons currently use |icon|. | |
| 71 void SetButtonImage(CaptionButtonIcon icon, gfx::VectorIconId icon_image_id); | |
| 72 | |
| 73 // Sets whether the buttons should be painted as active. Does not schedule | |
| 74 // a repaint. | |
| 75 void SetPaintAsActive(bool paint_as_active); | |
| 76 | |
| 77 // Sets whether the buttons should be painted in a lighter color (for use on | |
| 78 // dark backgrounds). | |
| 79 void SetUseLightImages(bool light); | |
| 80 | |
| 81 // Tell the window controls to reset themselves to the normal state. | |
| 82 void ResetWindowControls(); | |
| 83 | |
| 84 // Determines the window HT* code for the caption button at |point|. Returns | |
| 85 // HTNOWHERE if |point| is not over any of the caption buttons. |point| must | |
| 86 // be in the coordinates of the FrameCaptionButtonContainerView. | |
| 87 int NonClientHitTest(const gfx::Point& point) const; | |
| 88 | |
| 89 // Updates the size button's visibility based on whether |frame_| can be | |
| 90 // maximized and if maximize mode is enabled. A parent view should relayout | |
| 91 // to reflect the change in visibility. | |
| 92 void UpdateSizeButtonVisibility(); | |
| 93 | |
| 94 // Sets the size of the buttons in this container. | |
| 95 void SetButtonSize(const gfx::Size& size); | |
| 96 | |
| 97 // views::View: | |
| 98 gfx::Size GetPreferredSize() const override; | |
| 99 void Layout() override; | |
| 100 const char* GetClassName() const override; | |
| 101 | |
| 102 // gfx::AnimationDelegate: | |
| 103 void AnimationEnded(const gfx::Animation* animation) override; | |
| 104 void AnimationProgressed(const gfx::Animation* animation) override; | |
| 105 | |
| 106 private: | |
| 107 friend class FrameCaptionButtonContainerViewTest; | |
| 108 | |
| 109 // Sets |button|'s icon to |icon|. If |animate| is ANIMATE_YES, the button | |
| 110 // will crossfade to the new icon. If |animate| is ANIMATE_NO and | |
| 111 // |icon| == |button|->icon(), the crossfade animation is progressed to the | |
| 112 // end. | |
| 113 void SetButtonIcon(FrameCaptionButton* button, | |
| 114 CaptionButtonIcon icon, | |
| 115 Animate animate); | |
| 116 | |
| 117 // Returns true if maximize mode is not enabled, and |frame_| widget delegate | |
| 118 // can be maximized. | |
| 119 bool ShouldSizeButtonBeVisible() const; | |
| 120 | |
| 121 // views::ButtonListener: | |
| 122 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 123 | |
| 124 // FrameSizeButtonDelegate: | |
| 125 bool IsMinimizeButtonVisible() const override; | |
| 126 void SetButtonsToNormal(Animate animate) override; | |
| 127 void SetButtonIcons(CaptionButtonIcon minimize_button_icon, | |
| 128 CaptionButtonIcon close_button_icon, | |
| 129 Animate animate) override; | |
| 130 const FrameCaptionButton* GetButtonClosestTo( | |
| 131 const gfx::Point& position_in_screen) const override; | |
| 132 void SetHoveredAndPressedButtons(const FrameCaptionButton* to_hover, | |
| 133 const FrameCaptionButton* to_press) override; | |
| 134 | |
| 135 // The widget that the buttons act on. | |
| 136 views::Widget* frame_; | |
| 137 | |
| 138 // The buttons. In the normal button style, at most one of |minimize_button_| | |
| 139 // and |size_button_| is visible. | |
| 140 FrameCaptionButton* minimize_button_; | |
| 141 FrameCaptionButton* size_button_; | |
| 142 FrameCaptionButton* close_button_; | |
| 143 | |
| 144 // Mapping of the image ID needed to paint a button for each of the values of | |
| 145 // CaptionButtonIcon. | |
| 146 std::map<CaptionButtonIcon, gfx::VectorIconId> button_icon_id_map_; | |
| 147 | |
| 148 // Animation that affects the position of |minimize_button_| and the | |
| 149 // visibility of |size_button_|. | |
| 150 std::unique_ptr<gfx::SlideAnimation> maximize_mode_animation_; | |
| 151 | |
| 152 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView); | |
| 153 }; | |
| 154 | |
| 155 } // namespace ash | |
| 156 | |
| 157 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ | |
| OLD | NEW |