Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / ash / frame / caption_buttons / frame_caption_button_container_view.h
blobe5620f56d6f0e2a31955a2c596e534110e500353
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_
8 #include <map>
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"
16 namespace gfx {
17 class SlideAnimation;
20 namespace views {
21 class Widget;
24 namespace ash {
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
29 : public views::View,
30 public views::ButtonListener,
31 public FrameSizeButtonDelegate,
32 public gfx::AnimationDelegate {
33 public:
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;
40 // For testing.
41 class ASH_EXPORT TestApi {
42 public:
43 explicit TestApi(FrameCaptionButtonContainerView* container_view)
44 : container_view_(container_view) {
47 void EndAnimations();
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_;
61 private:
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,
71 int icon_image_id,
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
76 // a repaint.
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();
92 // views::View:
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;
101 private:
102 friend class FrameCaptionButtonContainerViewTest;
104 struct ButtonIconIds {
105 ButtonIconIds();
106 ButtonIconIds(int icon_id,
107 int hovered_background_id,
108 int pressed_background_id);
109 ~ButtonIconIds();
111 int icon_image_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
119 // end.
120 void SetButtonIcon(FrameCaptionButton* button,
121 CaptionButtonIcon icon,
122 Animate animate);
124 // Returns true if maximize mode is not enabled, and |frame_| widget delegate
125 // can be maximized.
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);
162 } // namespace ash
164 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_