| 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_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ | |
| 6 #define ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "ash/common/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 struct VectorIcon; | |
| 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, | |
| 72 const gfx::VectorIcon& icon_definition); | |
| 73 | |
| 74 // Sets whether the buttons should be painted as active. Does not schedule | |
| 75 // a repaint. | |
| 76 void SetPaintAsActive(bool paint_as_active); | |
| 77 | |
| 78 // Sets whether the buttons should be painted in a lighter color (for use on | |
| 79 // dark backgrounds). | |
| 80 void SetUseLightImages(bool light); | |
| 81 | |
| 82 // Tell the window controls to reset themselves to the normal state. | |
| 83 void ResetWindowControls(); | |
| 84 | |
| 85 // Determines the window HT* code for the caption button at |point|. Returns | |
| 86 // HTNOWHERE if |point| is not over any of the caption buttons. |point| must | |
| 87 // be in the coordinates of the FrameCaptionButtonContainerView. | |
| 88 int NonClientHitTest(const gfx::Point& point) const; | |
| 89 | |
| 90 // Updates the size button's visibility based on whether |frame_| can be | |
| 91 // maximized and if maximize mode is enabled. A parent view should relayout | |
| 92 // to reflect the change in visibility. | |
| 93 void UpdateSizeButtonVisibility(); | |
| 94 | |
| 95 // Sets the size of the buttons in this container. | |
| 96 void SetButtonSize(const gfx::Size& size); | |
| 97 | |
| 98 // views::View: | |
| 99 gfx::Size GetPreferredSize() const override; | |
| 100 void Layout() override; | |
| 101 const char* GetClassName() const override; | |
| 102 | |
| 103 // gfx::AnimationDelegate: | |
| 104 void AnimationEnded(const gfx::Animation* animation) override; | |
| 105 void AnimationProgressed(const gfx::Animation* animation) override; | |
| 106 | |
| 107 private: | |
| 108 friend class FrameCaptionButtonContainerViewTest; | |
| 109 | |
| 110 // Sets |button|'s icon to |icon|. If |animate| is ANIMATE_YES, the button | |
| 111 // will crossfade to the new icon. If |animate| is ANIMATE_NO and | |
| 112 // |icon| == |button|->icon(), the crossfade animation is progressed to the | |
| 113 // end. | |
| 114 void SetButtonIcon(FrameCaptionButton* button, | |
| 115 CaptionButtonIcon icon, | |
| 116 Animate animate); | |
| 117 | |
| 118 // Returns true if maximize mode is not enabled, and |frame_| widget delegate | |
| 119 // can be maximized. | |
| 120 bool ShouldSizeButtonBeVisible() const; | |
| 121 | |
| 122 // views::ButtonListener: | |
| 123 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 124 | |
| 125 // FrameSizeButtonDelegate: | |
| 126 bool IsMinimizeButtonVisible() const override; | |
| 127 void SetButtonsToNormal(Animate animate) override; | |
| 128 void SetButtonIcons(CaptionButtonIcon minimize_button_icon, | |
| 129 CaptionButtonIcon close_button_icon, | |
| 130 Animate animate) override; | |
| 131 const FrameCaptionButton* GetButtonClosestTo( | |
| 132 const gfx::Point& position_in_screen) const override; | |
| 133 void SetHoveredAndPressedButtons(const FrameCaptionButton* to_hover, | |
| 134 const FrameCaptionButton* to_press) override; | |
| 135 | |
| 136 // The widget that the buttons act on. | |
| 137 views::Widget* frame_; | |
| 138 | |
| 139 // The buttons. In the normal button style, at most one of |minimize_button_| | |
| 140 // and |size_button_| is visible. | |
| 141 FrameCaptionButton* minimize_button_; | |
| 142 FrameCaptionButton* size_button_; | |
| 143 FrameCaptionButton* close_button_; | |
| 144 | |
| 145 // Mapping of the image needed to paint a button for each of the values of | |
| 146 // CaptionButtonIcon. | |
| 147 std::map<CaptionButtonIcon, const gfx::VectorIcon*> button_icon_map_; | |
| 148 | |
| 149 // Animation that affects the position of |minimize_button_| and the | |
| 150 // visibility of |size_button_|. | |
| 151 std::unique_ptr<gfx::SlideAnimation> maximize_mode_animation_; | |
| 152 | |
| 153 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView); | |
| 154 }; | |
| 155 | |
| 156 } // namespace ash | |
| 157 | |
| 158 #endif // ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_
H_ | |
| OLD | NEW |