Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ash / frame / caption_buttons / frame_caption_button_container_view.h
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.
4
5 #ifndef ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
6 #define ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
7
8 #include <map>
9
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"
15
16 namespace gfx {
17 class SlideAnimation;
18 }
19
20 namespace views {
21 class Widget;
22 }
23
24 namespace ash {
25
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[];
35
36   // Whether the frame can be minimized (either via the maximize/restore button
37   // or via a dedicated button).
38   enum MinimizeAllowed {
39     MINIMIZE_ALLOWED,
40     MINIMIZE_DISALLOWED
41   };
42
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();
49
50   // For testing.
51   class ASH_EXPORT TestApi {
52    public:
53     explicit TestApi(FrameCaptionButtonContainerView* container_view)
54         : container_view_(container_view) {
55     }
56
57     void EndAnimations();
58
59     FrameCaptionButton* minimize_button() const {
60       return container_view_->minimize_button_;
61     }
62
63     FrameCaptionButton* size_button() const {
64       return container_view_->size_button_;
65     }
66
67     FrameCaptionButton* close_button() const {
68       return container_view_->close_button_;
69     }
70
71    private:
72     FrameCaptionButtonContainerView* container_view_;
73
74     DISALLOW_COPY_AND_ASSIGN(TestApi);
75   };
76
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,
81                        int icon_image_id,
82                        int inactive_icon_image_id,
83                        int hovered_background_image_id,
84                        int pressed_background_image_id);
85
86   // Sets whether the buttons should be painted as active. Does not schedule
87   // a repaint.
88   void SetPaintAsActive(bool paint_as_active);
89
90   // Tell the window controls to reset themselves to the normal state.
91   void ResetWindowControls();
92
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;
97
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();
102
103   // views::View:
104   virtual gfx::Size GetPreferredSize() const OVERRIDE;
105   virtual void Layout() OVERRIDE;
106   virtual const char* GetClassName() const OVERRIDE;
107
108   // Overridden from gfx::AnimationDelegate:
109   virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
110   virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
111
112  private:
113   friend class FrameCaptionButtonContainerViewTest;
114
115   struct ButtonIconIds {
116     ButtonIconIds();
117     ButtonIconIds(int icon_id,
118                   int inactive_icon_id,
119                   int hovered_background_id,
120                   int pressed_background_id);
121     ~ButtonIconIds();
122
123     int icon_image_id;
124     int inactive_icon_image_id;
125     int hovered_background_image_id;
126     int pressed_background_image_id;
127   };
128
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
132   // end.
133   void SetButtonIcon(FrameCaptionButton* button,
134                      CaptionButtonIcon icon,
135                      Animate animate);
136
137   // Returns true if maximize mode is not enabled, and |frame_| widget delegate
138   // can be maximized.
139   bool ShouldSizeButtonBeVisible() const;
140
141   // views::ButtonListener:
142   virtual void ButtonPressed(views::Button* sender,
143                              const ui::Event& event) OVERRIDE;
144
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;
156
157   // The widget that the buttons act on.
158   views::Widget* frame_;
159
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_;
165
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_;
169
170   // Animation that affects the position of |minimize_button_| and the
171   // visibility of |size_button_|.
172   scoped_ptr<gfx::SlideAnimation> maximize_mode_animation_;
173
174   DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView);
175 };
176
177 }  // namespace ash
178
179 #endif  // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_