- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / frame / browser_view_layout.h
1 // Copyright (c) 2012 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_BROWSER_VIEW_LAYOUT_H_
6 #define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/views/layout/layout_manager.h"
14
15 class BookmarkBarView;
16 class Browser;
17 class BrowserView;
18 class BrowserViewLayoutDelegate;
19 class ContentsContainer;
20 class ImmersiveModeController;
21 class InfoBarContainerView;
22 class TabContentsContainer;
23 class TabStrip;
24
25 namespace gfx {
26 class Point;
27 class Size;
28 }
29
30 namespace views {
31 class SingleSplitView;
32 }
33
34 namespace web_modal {
35 class WebContentsModalDialogHost;
36 }
37
38 // The layout manager used in chrome browser.
39 class BrowserViewLayout : public views::LayoutManager {
40  public:
41   // The vertical overlap between the TabStrip and the Toolbar.
42   static const int kToolbarTabStripVerticalOverlap;
43
44   BrowserViewLayout();
45   virtual ~BrowserViewLayout();
46
47   // Sets all the views to be managed. Takes ownership of |delegate|.
48   // |browser_view| may be NULL in tests.
49   void Init(BrowserViewLayoutDelegate* delegate,
50             Browser* browser,
51             BrowserView* browser_view,
52             views::View* top_container,
53             TabStrip* tab_strip,
54             views::View* toolbar,
55             InfoBarContainerView* infobar_container,
56             views::View* contents_split,
57             ContentsContainer* contents_container,
58             ImmersiveModeController* immersive_mode_controller);
59
60   // Sets or updates views that are not available when |this| is initialized.
61   void set_tab_strip(TabStrip* tab_strip) {
62     tab_strip_ = tab_strip;
63   }
64   void set_bookmark_bar(BookmarkBarView* bookmark_bar) {
65     bookmark_bar_ = bookmark_bar;
66   }
67   void set_download_shelf(views::View* download_shelf) {
68     download_shelf_ = download_shelf;
69   }
70
71   web_modal::WebContentsModalDialogHost* GetWebContentsModalDialogHost();
72
73   // Returns the minimum size of the browser view.
74   gfx::Size GetMinimumSize();
75
76   // Returns the bounding box, in widget coordinates,  for the find bar.
77   gfx::Rect GetFindBarBoundingBox() const;
78
79   // Tests to see if the specified |point| (in nonclient view's coordinates)
80   // is within the views managed by the laymanager. Returns one of
81   // HitTestCompat enum defined in ui/base/hit_test.h.
82   // See also ClientView::NonClientHitTest.
83   int NonClientHitTest(const gfx::Point& point);
84
85   // views::LayoutManager overrides:
86   virtual void Layout(views::View* host) OVERRIDE;
87   virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE;
88
89  private:
90   FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, BrowserViewLayout);
91   FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, Layout);
92   FRIEND_TEST_ALL_PREFIXES(BrowserViewLayoutTest, LayoutDownloadShelf);
93   class WebContentsModalDialogHostViews;
94
95   Browser* browser() { return browser_; }
96
97   // Layout the tab strip region, returns the coordinate of the bottom of the
98   // TabStrip, for laying out subsequent controls.
99   int LayoutTabStripRegion(views::View* browser_view);
100
101   // Layout the following controls, starting at |top|, returns the coordinate
102   // of the bottom of the control, for laying out the next control.
103   int LayoutToolbar(int top);
104   int LayoutBookmarkAndInfoBars(int top, int browser_view_y);
105   int LayoutBookmarkBar(int top);
106   int LayoutInfoBar(int top);
107
108   // Layout the |contents_split_| view between the coordinates |top| and
109   // |bottom|. See browser_view.h for details of the relationship between
110   // |contents_split_| and other views.
111   void LayoutContentsSplitView(int top, int bottom);
112
113   // Updates |top_container_|'s bounds. The new bounds depend on the size of
114   // the bookmark bar and the toolbar.
115   void UpdateTopContainerBounds();
116
117   // Returns the vertical offset for the web contents to account for a
118   // detached bookmarks bar.
119   int GetContentsOffsetForBookmarkBar();
120
121   // Returns the top margin to adjust the contents_container_ by. This is used
122   // to make the bookmark bar and contents_container_ overlap so that the
123   // preview contents hides the bookmark bar.
124   int GetTopMarginForActiveContent();
125
126   // Layout the Download Shelf, returns the coordinate of the top of the
127   // control, for laying out the previous control.
128   int LayoutDownloadShelf(int bottom);
129
130   // Returns true if an infobar is showing.
131   bool InfobarVisible() const;
132
133   // The delegate interface. May be a mock in tests.
134   scoped_ptr<BrowserViewLayoutDelegate> delegate_;
135
136   // The browser from the owning BrowserView.
137   Browser* browser_;
138
139   // The owning BrowserView. May be NULL in tests.
140   // TODO(jamescook): Remove this, use the views::View passed in to Layout().
141   BrowserView* browser_view_;
142
143   // Child views that the layout manager manages.
144   // NOTE: If you add a view, try to add it as a views::View, which makes
145   // testing much easier.
146   views::View* top_container_;
147   TabStrip* tab_strip_;
148   views::View* toolbar_;
149   BookmarkBarView* bookmark_bar_;
150   InfoBarContainerView* infobar_container_;
151   views::View* contents_split_;
152   ContentsContainer* contents_container_;
153   views::View* download_shelf_;
154
155   ImmersiveModeController* immersive_mode_controller_;
156
157   // The bounds within which the vertically-stacked contents of the BrowserView
158   // should be laid out within. This is just the local bounds of the
159   // BrowserView.
160   // TODO(jamescook): Remove this and just use browser_view_->GetLocalBounds().
161   gfx::Rect vertical_layout_rect_;
162
163   // The host for use in positioning the web contents modal dialog.
164   scoped_ptr<WebContentsModalDialogHostViews> dialog_host_;
165
166   // The distance the web contents modal dialog is from the top of the window,
167   // in pixels.
168   int web_contents_modal_dialog_top_y_;
169
170   DISALLOW_COPY_AND_ASSIGN(BrowserViewLayout);
171 };
172
173 #endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_VIEW_LAYOUT_H_