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 // |frame| is the views::Widget that the caption buttons act on.
37 explicit FrameCaptionButtonContainerView(views::Widget
* frame
);
38 ~FrameCaptionButtonContainerView() override
;
41 class ASH_EXPORT TestApi
{
43 explicit TestApi(FrameCaptionButtonContainerView
* container_view
)
44 : container_view_(container_view
) {
49 FrameCaptionButton
* minimize_button() const {
50 return container_view_
->minimize_button_
;
53 FrameCaptionButton
* size_button() const {
54 return container_view_
->size_button_
;
57 FrameCaptionButton
* close_button() const {
58 return container_view_
->close_button_
;
62 FrameCaptionButtonContainerView
* container_view_
;
64 DISALLOW_COPY_AND_ASSIGN(TestApi
);
67 // Sets the resource ids of the images to paint the button for |icon|. The
68 // FrameCaptionButtonContainerView will keep track of the images to use for
69 // |icon| even if none of the buttons currently use |icon|.
70 void SetButtonImages(CaptionButtonIcon icon
,
72 int hovered_background_image_id
,
73 int pressed_background_image_id
);
75 // Sets whether the buttons should be painted as active. Does not schedule
77 void SetPaintAsActive(bool paint_as_active
);
79 // Tell the window controls to reset themselves to the normal state.
80 void ResetWindowControls();
82 // Determines the window HT* code for the caption button at |point|. Returns
83 // HTNOWHERE if |point| is not over any of the caption buttons. |point| must
84 // be in the coordinates of the FrameCaptionButtonContainerView.
85 int NonClientHitTest(const gfx::Point
& point
) const;
87 // Updates the size button's visibility based on whether |frame_| can be
88 // maximized and if maximize mode is enabled. A parent view should relayout
89 // to reflect the change in visibility.
90 void UpdateSizeButtonVisibility();
93 gfx::Size
GetPreferredSize() const override
;
94 void Layout() override
;
95 const char* GetClassName() const override
;
97 // Overridden from gfx::AnimationDelegate:
98 void AnimationEnded(const gfx::Animation
* animation
) override
;
99 void AnimationProgressed(const gfx::Animation
* animation
) override
;
102 friend class FrameCaptionButtonContainerViewTest
;
104 struct ButtonIconIds
{
106 ButtonIconIds(int icon_id
,
107 int hovered_background_id
,
108 int pressed_background_id
);
112 int hovered_background_image_id
;
113 int pressed_background_image_id
;
116 // Sets |button|'s icon to |icon|. If |animate| is ANIMATE_YES, the button
117 // will crossfade to the new icon. If |animate| is ANIMATE_NO and
118 // |icon| == |button|->icon(), the crossfade animation is progressed to the
120 void SetButtonIcon(FrameCaptionButton
* button
,
121 CaptionButtonIcon icon
,
124 // Returns true if maximize mode is not enabled, and |frame_| widget delegate
126 bool ShouldSizeButtonBeVisible() const;
128 // views::ButtonListener:
129 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
131 // FrameSizeButtonDelegate:
132 bool IsMinimizeButtonVisible() const override
;
133 void SetButtonsToNormal(Animate animate
) override
;
134 void SetButtonIcons(CaptionButtonIcon minimize_button_icon
,
135 CaptionButtonIcon close_button_icon
,
136 Animate animate
) override
;
137 const FrameCaptionButton
* GetButtonClosestTo(
138 const gfx::Point
& position_in_screen
) const override
;
139 void SetHoveredAndPressedButtons(const FrameCaptionButton
* to_hover
,
140 const FrameCaptionButton
* to_press
) override
;
142 // The widget that the buttons act on.
143 views::Widget
* frame_
;
145 // The buttons. In the normal button style, at most one of |minimize_button_|
146 // and |size_button_| is visible.
147 FrameCaptionButton
* minimize_button_
;
148 FrameCaptionButton
* size_button_
;
149 FrameCaptionButton
* close_button_
;
151 // Mapping of the images needed to paint a button for each of the values of
152 // CaptionButtonIcon.
153 std::map
<CaptionButtonIcon
, ButtonIconIds
> button_icon_id_map_
;
155 // Animation that affects the position of |minimize_button_| and the
156 // visibility of |size_button_|.
157 scoped_ptr
<gfx::SlideAnimation
> maximize_mode_animation_
;
159 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView
);
164 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_