OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 MASH_WM_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ | |
6 #define MASH_WM_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 | |
11 #include "base/macros.h" | |
12 #include "mash/wm/frame/caption_buttons/caption_button_types.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 } | |
20 | |
21 namespace views { | |
22 class Widget; | |
23 } | |
24 | |
25 namespace mash { | |
26 namespace wm { | |
27 | |
28 class FrameCaptionButton; | |
29 | |
30 // Container view for the frame caption buttons. It performs the appropriate | |
31 // action when a caption button is clicked. | |
32 class FrameCaptionButtonContainerView : public views::View, | |
33 public views::ButtonListener, | |
34 public gfx::AnimationDelegate { | |
35 public: | |
36 enum Animate { ANIMATE_YES, ANIMATE_NO }; | |
37 | |
38 static const char kViewClassName[]; | |
39 | |
40 // |frame| is the views::Widget that the caption buttons act on. | |
41 explicit FrameCaptionButtonContainerView(views::Widget* frame); | |
42 ~FrameCaptionButtonContainerView() override; | |
43 | |
44 // Sets the resource ids of the images to paint the button for |icon|. The | |
45 // FrameCaptionButtonContainerView will keep track of the images to use for | |
46 // |icon| even if none of the buttons currently use |icon|. | |
47 void SetButtonImages(CaptionButtonIcon icon, | |
48 int icon_image_id, | |
49 int hovered_background_image_id, | |
50 int pressed_background_image_id); | |
51 | |
52 // Sets whether the buttons should be painted as active. Does not schedule | |
53 // a repaint. | |
54 void SetPaintAsActive(bool paint_as_active); | |
55 | |
56 // Tell the window controls to reset themselves to the normal state. | |
57 void ResetWindowControls(); | |
58 | |
59 // Determines the window HT* code for the caption button at |point|. Returns | |
60 // HTNOWHERE if |point| is not over any of the caption buttons. |point| must | |
61 // be in the coordinates of the FrameCaptionButtonContainerView. | |
62 int NonClientHitTest(const gfx::Point& point) const; | |
63 | |
64 // Updates the size button's visibility based on whether |frame_| can be | |
65 // maximized and if maximize mode is enabled. A parent view should relayout | |
66 // to reflect the change in visibility. | |
67 void UpdateSizeButtonVisibility(); | |
68 | |
69 // views::View: | |
70 gfx::Size GetPreferredSize() const override; | |
71 void Layout() override; | |
72 const char* GetClassName() const override; | |
73 | |
74 // Overridden from gfx::AnimationDelegate: | |
75 void AnimationEnded(const gfx::Animation* animation) override; | |
76 void AnimationProgressed(const gfx::Animation* animation) override; | |
77 | |
78 private: | |
79 friend class FrameCaptionButtonContainerViewTest; | |
80 | |
81 struct ButtonIconIds { | |
82 ButtonIconIds(); | |
83 ButtonIconIds(int icon_id, | |
84 int hovered_background_id, | |
85 int pressed_background_id); | |
86 ~ButtonIconIds(); | |
87 | |
88 int icon_image_id; | |
89 int hovered_background_image_id; | |
90 int pressed_background_image_id; | |
91 }; | |
92 | |
93 // Sets |button|'s icon to |icon|. If |animate| is ANIMATE_YES, the button | |
94 // will crossfade to the new icon. If |animate| is ANIMATE_NO and | |
95 // |icon| == |button|->icon(), the crossfade animation is progressed to the | |
96 // end. | |
97 void SetButtonIcon(FrameCaptionButton* button, | |
98 CaptionButtonIcon icon, | |
99 Animate animate); | |
100 | |
101 // Returns true if maximize mode is not enabled, and |frame_| widget delegate | |
102 // can be maximized. | |
103 bool ShouldSizeButtonBeVisible() const; | |
104 | |
105 void SetButtonsToNormal(Animate animate); | |
106 void SetButtonIcons(CaptionButtonIcon minimize_button_icon, | |
107 CaptionButtonIcon close_button_icon, | |
108 Animate animate); | |
109 | |
110 // views::ButtonListener: | |
111 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
112 | |
113 // The widget that the buttons act on. | |
114 views::Widget* frame_; | |
115 | |
116 // The buttons. In the normal button style, at most one of |minimize_button_| | |
117 // and |size_button_| is visible. | |
118 FrameCaptionButton* minimize_button_; | |
119 FrameCaptionButton* size_button_; | |
120 FrameCaptionButton* close_button_; | |
121 | |
122 // Mapping of the images needed to paint a button for each of the values of | |
123 // CaptionButtonIcon. | |
124 std::map<CaptionButtonIcon, ButtonIconIds> button_icon_id_map_; | |
125 | |
126 // Animation that affects the position of |minimize_button_| and the | |
127 // visibility of |size_button_|. | |
128 std::unique_ptr<gfx::SlideAnimation> maximize_mode_animation_; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView); | |
131 }; | |
132 | |
133 } // namespace wm | |
134 } // namespace mash | |
135 | |
136 #endif // MASH_WM_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ | |
OLD | NEW |