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/views/controls/button/button.h"
13 #include "ui/views/view.h"
21 // Container view for the frame caption buttons. It performs the appropriate
22 // action when a caption button is clicked.
23 class ASH_EXPORT FrameCaptionButtonContainerView
25 public views::ButtonListener
,
26 public FrameSizeButtonDelegate
{
28 static const char kViewClassName
[];
30 // Whether the frame can be minimized (either via the maximize/restore button
31 // or via a dedicated button).
32 enum MinimizeAllowed
{
37 // |frame| is the views::Widget that the caption buttons act on.
38 // |minimize_allowed| indicates whether the frame can be minimized (either via
39 // the maximize/restore button or via a dedicated button).
40 FrameCaptionButtonContainerView(views::Widget
* frame
,
41 MinimizeAllowed minimize_allowed
);
42 virtual ~FrameCaptionButtonContainerView();
47 explicit TestApi(FrameCaptionButtonContainerView
* container_view
)
48 : container_view_(container_view
) {
51 FrameCaptionButton
* minimize_button() const {
52 return container_view_
->minimize_button_
;
55 FrameCaptionButton
* size_button() const {
56 return container_view_
->size_button_
;
59 FrameCaptionButton
* close_button() const {
60 return container_view_
->close_button_
;
64 FrameCaptionButtonContainerView
* container_view_
;
66 DISALLOW_COPY_AND_ASSIGN(TestApi
);
69 // Sets the resource ids of the images to paint the button for |icon|. The
70 // FrameCaptionButtonContainerView will keep track of the images to use for
71 // |icon| even if none of the buttons currently use |icon|.
72 void SetButtonImages(CaptionButtonIcon icon
,
74 int inactive_icon_image_id
,
75 int hovered_background_image_id
,
76 int pressed_background_image_id
);
78 // Sets whether the buttons should be painted as active. Does not schedule
80 void SetPaintAsActive(bool paint_as_active
);
82 // Tell the window controls to reset themselves to the normal state.
83 void ResetWindowControls();
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;
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();
96 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
97 virtual void Layout() OVERRIDE
;
98 virtual const char* GetClassName() const OVERRIDE
;
101 friend class FrameCaptionButtonContainerViewTest
;
103 struct ButtonIconIds
{
105 ButtonIconIds(int icon_id
,
106 int inactive_icon_id
,
107 int hovered_background_id
,
108 int pressed_background_id
);
112 int inactive_icon_image_id
;
113 int hovered_background_image_id
;
114 int pressed_background_image_id
;
117 // Sets |button|'s icon to |icon|. If |animate| is ANIMATE_YES, the button
118 // will crossfade to the new icon. If |animate| is ANIMATE_NO and
119 // |icon| == |button|->icon(), the crossfade animation is progressed to the
121 void SetButtonIcon(FrameCaptionButton
* button
,
122 CaptionButtonIcon icon
,
125 // views::ButtonListener:
126 virtual void ButtonPressed(views::Button
* sender
,
127 const ui::Event
& event
) OVERRIDE
;
129 // FrameSizeButtonDelegate:
130 virtual bool IsMinimizeButtonVisible() const OVERRIDE
;
131 virtual void SetButtonsToNormal(Animate animate
) OVERRIDE
;
132 virtual void SetButtonIcons(CaptionButtonIcon minimize_button_icon
,
133 CaptionButtonIcon close_button_icon
,
134 Animate animate
) OVERRIDE
;
135 virtual const FrameCaptionButton
* GetButtonClosestTo(
136 const gfx::Point
& position_in_screen
) const OVERRIDE
;
137 virtual void SetHoveredAndPressedButtons(
138 const FrameCaptionButton
* to_hover
,
139 const FrameCaptionButton
* to_press
) OVERRIDE
;
141 // The widget that the buttons act on.
142 views::Widget
* frame_
;
144 // The buttons. In the normal button style, at most one of |minimize_button_|
145 // and |size_button_| is visible.
146 FrameCaptionButton
* minimize_button_
;
147 FrameCaptionButton
* size_button_
;
148 FrameCaptionButton
* close_button_
;
150 // Mapping of the images needed to paint a button for each of the values of
151 // CaptionButtonIcon.
152 std::map
<CaptionButtonIcon
, ButtonIconIds
> button_icon_id_map_
;
154 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView
);
159 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_