- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / frame / opaque_browser_frame_view_layout.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 CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_
6 #define CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_
7
8 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
9 #include "ui/views/layout/layout_manager.h"
10 #include "ui/views/window/frame_buttons.h"
11
12 class NewAvatarButton;
13 class OpaqueBrowserFrameViewLayoutDelegate;
14
15 namespace views {
16 class ImageButton;
17 class Label;
18 }
19
20 // Calculates the position of the widgets in the opaque browser frame view.
21 //
22 // This is separated out for testing reasons. OpaqueBrowserFrameView has tight
23 // dependencies with Browser and classes that depend on Browser.
24 class OpaqueBrowserFrameViewLayout : public views::LayoutManager {
25  public:
26   explicit OpaqueBrowserFrameViewLayout(
27       OpaqueBrowserFrameViewLayoutDelegate* delegate);
28   virtual ~OpaqueBrowserFrameViewLayout();
29
30   // Whether we should add the (minimize,maximize,close) buttons. Can be false
31   // on Windows 8 in metro mode.
32   static bool ShouldAddDefaultCaptionButtons();
33
34   // Configures the button ordering in the frame.
35   void SetButtonOrdering(
36       const std::vector<views::FrameButton>& leading_buttons,
37       const std::vector<views::FrameButton>& trailing_buttons);
38
39   gfx::Rect GetBoundsForTabStrip(
40       const gfx::Size& tabstrip_preferred_size,
41       int available_width) const;
42
43   gfx::Size GetMinimumSize(int available_width) const;
44
45   // Returns the bounds of the window required to display the content area at
46   // the specified bounds.
47   gfx::Rect GetWindowBoundsForClientBounds(
48       const gfx::Rect& client_bounds) const;
49
50   // Returns the thickness of the border that makes up the window frame edges.
51   // This does not include any client edge.  If |restored| is true, acts as if
52   // the window is restored regardless of the real mode.
53   int FrameBorderThickness(bool restored) const;
54
55   // Returns the thickness of the entire nonclient left, right, and bottom
56   // borders, including both the window frame and any client edge.
57   int NonClientBorderThickness() const;
58
59   // Returns the height of the entire nonclient top border, including the window
60   // frame, any title area, and any connected client edge.  If |restored| is
61   // true, acts as if the window is restored regardless of the real mode.
62   int NonClientTopBorderHeight(bool restored) const;
63
64   int GetTabStripInsetsTop(bool restored) const;
65
66   // Returns the y-coordinate of the caption buttons.  If |restored| is true,
67   // acts as if the window is restored regardless of the real mode.
68   int CaptionButtonY(bool restored) const;
69
70   // Returns the thickness of the 3D edge along the bottom of the titlebar.  If
71   // |restored| is true, acts as if the window is restored regardless of the
72   // real mode.
73   int TitlebarBottomThickness(bool restored) const;
74
75   // Returns the bounds of the titlebar icon (or where the icon would be if
76   // there was one).
77   gfx::Rect IconBounds() const;
78
79   // Returns the bounds of the client area for the specified view size.
80   gfx::Rect CalculateClientAreaBounds(int width, int height) const;
81
82   void set_extra_caption_y(int extra_caption_y) {
83     extra_caption_y_ = extra_caption_y;
84   }
85
86   void set_window_caption_spacing(int window_caption_spacing) {
87     window_caption_spacing_ = window_caption_spacing;
88   }
89
90   const gfx::Rect& client_view_bounds() const { return client_view_bounds_; }
91
92  private:
93   // Whether a specific button should be inserted on the leading or trailing
94   // side.
95   enum ButtonAlignment {
96     ALIGN_LEADING,
97     ALIGN_TRAILING
98   };
99
100   // Layout various sub-components of this view.
101   void LayoutWindowControls(views::View* host);
102   void LayoutTitleBar(views::View* host);
103   void LayoutAvatar();
104   void LayoutNewStyleAvatar(views::View* host);
105
106   void ConfigureButton(views::View* host,
107                        views::FrameButton button_id,
108                        ButtonAlignment align,
109                        int caption_y);
110
111   // Sets the visibility of all buttons associated with |button_id| to false.
112   void HideButton(views::FrameButton button_id);
113
114   // Adds a window caption button to either the leading or trailing side.
115   void SetBoundsForButton(views::View* host,
116                           views::ImageButton* button,
117                           ButtonAlignment align,
118                           int caption_y);
119
120   // Internal implementation of ViewAdded() and ViewRemoved().
121   void SetView(int id, views::View* view);
122
123   // Overriden from views::LayoutManager:
124   virtual void Layout(views::View* host) OVERRIDE;
125   virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE;
126   virtual void ViewAdded(views::View* host, views::View* view) OVERRIDE;
127   virtual void ViewRemoved(views::View* host, views::View* view) OVERRIDE;
128
129   OpaqueBrowserFrameViewLayoutDelegate* delegate_;
130
131   // The layout rect of the avatar icon, if visible.
132   gfx::Rect avatar_bounds_;
133
134   // The bounds of the ClientView.
135   gfx::Rect client_view_bounds_;
136
137   // The layout of the window icon, if visible.
138   gfx::Rect window_icon_bounds_;
139
140   // How far from the leading/trailing edge of the view the next window control
141   // should be placed.
142   int leading_button_start_;
143   int trailing_button_start_;
144
145   // The size of the window buttons, and the avatar menu item (if any). This
146   // does not count labels or other elements that should be counted in a
147   // minimal frame.
148   int minimum_size_for_buttons_;
149
150   // Whether any of the window control buttons were packed on the leading.
151   bool has_leading_buttons_;
152   bool has_trailing_buttons_;
153
154   // Extra offset from the top of the frame to the top of the window control
155   // buttons. Configurable based on platform and whether we are under test.
156   int extra_caption_y_;
157
158   // Extra offset between the individual window caption buttons.
159   int window_caption_spacing_;
160
161   // Window controls.
162   views::ImageButton* minimize_button_;
163   views::ImageButton* maximize_button_;
164   views::ImageButton* restore_button_;
165   views::ImageButton* close_button_;
166
167   views::View* window_icon_;
168   views::Label* window_title_;
169
170   views::View* avatar_label_;
171   views::View* avatar_button_;
172   NewAvatarButton* new_avatar_button_;
173
174   std::vector<views::FrameButton> leading_buttons_;
175   std::vector<views::FrameButton> trailing_buttons_;
176
177   DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayout);
178 };
179
180 #endif  // CHROME_BROWSER_UI_VIEWS_FRAME_OPAQUE_BROWSER_FRAME_VIEW_LAYOUT_H_