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.
5 #ifndef ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
6 #define ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
10 #include "ash/ash_export.h"
11 #include "ash/frame/caption_buttons/frame_size_button_delegate.h"
12 #include "ui/gfx/animation/animation_delegate.h"
13 #include "ui/views/controls/button/button.h"
14 #include "ui/views/view.h"
26 // Container view for the frame caption buttons. It performs the appropriate
27 // action when a caption button is clicked.
28 class ASH_EXPORT FrameCaptionButtonContainerView
30 public views::ButtonListener
,
31 public FrameSizeButtonDelegate
,
32 public gfx::AnimationDelegate
{
34 static const char kViewClassName
[];
36 // Whether the frame can be minimized (either via the maximize/restore button
37 // or via a dedicated button).
38 enum MinimizeAllowed
{
43 // |frame| is the views::Widget that the caption buttons act on.
44 // |minimize_allowed| indicates whether the frame can be minimized (either via
45 // the maximize/restore button or via a dedicated button).
46 FrameCaptionButtonContainerView(views::Widget
* frame
,
47 MinimizeAllowed minimize_allowed
);
48 virtual ~FrameCaptionButtonContainerView();
51 class ASH_EXPORT TestApi
{
53 explicit TestApi(FrameCaptionButtonContainerView
* container_view
)
54 : container_view_(container_view
) {
59 FrameCaptionButton
* minimize_button() const {
60 return container_view_
->minimize_button_
;
63 FrameCaptionButton
* size_button() const {
64 return container_view_
->size_button_
;
67 FrameCaptionButton
* close_button() const {
68 return container_view_
->close_button_
;
72 FrameCaptionButtonContainerView
* container_view_
;
74 DISALLOW_COPY_AND_ASSIGN(TestApi
);
77 // Sets the resource ids of the images to paint the button for |icon|. The
78 // FrameCaptionButtonContainerView will keep track of the images to use for
79 // |icon| even if none of the buttons currently use |icon|.
80 void SetButtonImages(CaptionButtonIcon icon
,
82 int inactive_icon_image_id
,
83 int hovered_background_image_id
,
84 int pressed_background_image_id
);
86 // Sets whether the buttons should be painted as active. Does not schedule
88 void SetPaintAsActive(bool paint_as_active
);
90 // Tell the window controls to reset themselves to the normal state.
91 void ResetWindowControls();
93 // Determines the window HT* code for the caption button at |point|. Returns
94 // HTNOWHERE if |point| is not over any of the caption buttons. |point| must
95 // be in the coordinates of the FrameCaptionButtonContainerView.
96 int NonClientHitTest(const gfx::Point
& point
) const;
98 // Updates the size button's visibility based on whether |frame_| can be
99 // maximized and if maximize mode is enabled. A parent view should relayout
100 // to reflect the change in visibility.
101 void UpdateSizeButtonVisibility();
104 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
105 virtual void Layout() OVERRIDE
;
106 virtual const char* GetClassName() const OVERRIDE
;
108 // Overridden from gfx::AnimationDelegate:
109 virtual void AnimationEnded(const gfx::Animation
* animation
) OVERRIDE
;
110 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
113 friend class FrameCaptionButtonContainerViewTest
;
115 struct ButtonIconIds
{
117 ButtonIconIds(int icon_id
,
118 int inactive_icon_id
,
119 int hovered_background_id
,
120 int pressed_background_id
);
124 int inactive_icon_image_id
;
125 int hovered_background_image_id
;
126 int pressed_background_image_id
;
129 // Sets |button|'s icon to |icon|. If |animate| is ANIMATE_YES, the button
130 // will crossfade to the new icon. If |animate| is ANIMATE_NO and
131 // |icon| == |button|->icon(), the crossfade animation is progressed to the
133 void SetButtonIcon(FrameCaptionButton
* button
,
134 CaptionButtonIcon icon
,
137 // Returns true if maximize mode is not enabled, and |frame_| widget delegate
139 bool ShouldSizeButtonBeVisible() const;
141 // views::ButtonListener:
142 virtual void ButtonPressed(views::Button
* sender
,
143 const ui::Event
& event
) OVERRIDE
;
145 // FrameSizeButtonDelegate:
146 virtual bool IsMinimizeButtonVisible() const OVERRIDE
;
147 virtual void SetButtonsToNormal(Animate animate
) OVERRIDE
;
148 virtual void SetButtonIcons(CaptionButtonIcon minimize_button_icon
,
149 CaptionButtonIcon close_button_icon
,
150 Animate animate
) OVERRIDE
;
151 virtual const FrameCaptionButton
* GetButtonClosestTo(
152 const gfx::Point
& position_in_screen
) const OVERRIDE
;
153 virtual void SetHoveredAndPressedButtons(
154 const FrameCaptionButton
* to_hover
,
155 const FrameCaptionButton
* to_press
) OVERRIDE
;
157 // The widget that the buttons act on.
158 views::Widget
* frame_
;
160 // The buttons. In the normal button style, at most one of |minimize_button_|
161 // and |size_button_| is visible.
162 FrameCaptionButton
* minimize_button_
;
163 FrameCaptionButton
* size_button_
;
164 FrameCaptionButton
* close_button_
;
166 // Mapping of the images needed to paint a button for each of the values of
167 // CaptionButtonIcon.
168 std::map
<CaptionButtonIcon
, ButtonIconIds
> button_icon_id_map_
;
170 // Animation that affects the position of |minimize_button_| and the
171 // visibility of |size_button_|.
172 scoped_ptr
<gfx::SlideAnimation
> maximize_mode_animation_
;
174 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView
);
179 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_