- add sources.
[platform/framework/web/crosswalk.git] / src / ash / wm / 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_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
6 #define ASH_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
7
8 #include "ash/ash_export.h"
9 #include "ui/gfx/image/image_skia.h"
10 #include "ui/views/controls/button/button.h"
11 #include "ui/views/view.h"
12
13 namespace views {
14 class CustomButton;
15 class Widget;
16 }
17
18 namespace ash {
19
20 // Container view for the frame caption buttons. It performs the appropriate
21 // action when a caption button is clicked.
22 class ASH_EXPORT FrameCaptionButtonContainerView
23     : public views::View,
24       public views::ButtonListener {
25  public:
26   static const char kViewClassName[];
27
28   // Whether the frame can be minimized (either via the maximize/restore button
29   // or via a dedicated button).
30   enum MinimizeAllowed {
31     MINIMIZE_ALLOWED,
32     MINIMIZE_DISALLOWED
33   };
34   enum HeaderStyle {
35     // Dialogs, panels, packaged apps, tabbed maximized/fullscreen browser
36     // windows.
37     HEADER_STYLE_SHORT,
38
39     // Restored tabbed browser windows, popups for browser windows, restored
40     // hosted app windows, popups for hosted app windows.
41     HEADER_STYLE_TALL,
42
43     // AppNonClientFrameViewAsh.
44     HEADER_STYLE_MAXIMIZED_HOSTED_APP
45   };
46
47   // |frame| is the views::Widget that the caption buttons act on.
48   // |minimize_allowed| indicates whether the frame can be minimized (either via
49   // the maximize/restore button or via a dedicated button).
50   FrameCaptionButtonContainerView(views::Widget* frame,
51                                   MinimizeAllowed minimize_allowed);
52   virtual ~FrameCaptionButtonContainerView();
53
54   // For testing.
55   class TestApi {
56    public:
57     explicit TestApi(FrameCaptionButtonContainerView* container_view)
58         : container_view_(container_view) {
59     }
60
61     views::CustomButton* minimize_button() const {
62       return container_view_->minimize_button_;
63     }
64
65     views::CustomButton* size_button() const {
66       return container_view_->size_button_;
67     }
68
69     views::CustomButton* close_button() const {
70       return container_view_->close_button_;
71     }
72
73    private:
74     FrameCaptionButtonContainerView* container_view_;
75
76     DISALLOW_COPY_AND_ASSIGN(TestApi);
77   };
78
79   // Tell the window controls to reset themselves to the normal state.
80   void ResetWindowControls();
81
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;
86
87   // Sets the header style.
88   void set_header_style(HeaderStyle header_style) {
89     header_style_ = header_style;
90   }
91
92   // views::View overrides:
93   virtual gfx::Size GetPreferredSize() OVERRIDE;
94   virtual void Layout() OVERRIDE;
95   virtual const char* GetClassName() const OVERRIDE;
96   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
97
98  private:
99   friend class FrameCaptionButtonContainerViewTest;
100
101   // Returns the distance between buttons which are next to each other. A
102   // negative value is returned if the buttons overlap.
103   int GetDistanceBetweenButtons() const;
104
105   // Returns the inset of the leftmost visible button from the view's border
106   // (if any).
107   int GetLeftInset() const;
108
109   // Returns the inset of the rightmost visible button from the view's border
110   // (if any).
111   int GetRightInset() const;
112
113   // views::ButtonListener override:
114   virtual void ButtonPressed(views::Button* sender,
115                              const ui::Event& event) OVERRIDE;
116
117   // Methods specific to normal button style -----------------------------------
118   //
119   // Sets the images for a button based on the given ids.
120   void SetButtonImages(views::CustomButton* button,
121                        int normal_image_id,
122                        int hot_image_id,
123                        int pushed_image_id);
124
125   // The widget that the buttons act on.
126   views::Widget* frame_;
127
128   // The close button separator.
129   gfx::ImageSkia button_separator_;
130
131   HeaderStyle header_style_;
132
133   // The buttons. In the normal button style, at most one of |minimize_button_|
134   // and |size_button_| is visible.
135   views::CustomButton* minimize_button_;
136   views::CustomButton* size_button_;
137   views::CustomButton* close_button_;
138
139   DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView);
140 };
141
142 }  // namesapace ash
143
144 #endif  // ASH_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_