OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/frame/browser_view_layout.h" | 5 #include "chrome/browser/ui/views/frame/browser_view_layout.h" |
6 | 6 |
7 #include "base/observer_list.h" | 7 #include "base/observer_list.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/find_bar/find_bar.h" | 10 #include "chrome/browser/ui/find_bar/find_bar.h" |
11 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 11 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
12 #include "chrome/browser/ui/search/search_model.h" | 12 #include "chrome/browser/ui/search/search_model.h" |
13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 13 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
14 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 14 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
15 #include "chrome/browser/ui/views/frame/browser_frame.h" | 15 #include "chrome/browser/ui/views/frame/browser_frame.h" |
16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
17 #include "chrome/browser/ui/views/frame/contents_container.h" | 17 #include "chrome/browser/ui/views/frame/contents_container.h" |
18 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" | 18 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" |
19 #include "chrome/browser/ui/views/frame/overlay_container.h" | 19 #include "chrome/browser/ui/views/frame/overlay_container.h" |
20 #include "chrome/browser/ui/views/frame/top_container_view.h" | 20 #include "chrome/browser/ui/views/frame/top_container_view.h" |
21 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 21 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
22 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 22 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
23 #include "chrome/browser/ui/views/toolbar_view.h" | |
24 #include "chrome/browser/ui/web_contents_modal_dialog_host.h" | 23 #include "chrome/browser/ui/web_contents_modal_dialog_host.h" |
25 #include "ui/base/hit_test.h" | 24 #include "ui/base/hit_test.h" |
26 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
27 #include "ui/gfx/scrollbar_size.h" | 26 #include "ui/gfx/scrollbar_size.h" |
28 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
29 #include "ui/views/controls/single_split_view.h" | |
30 #include "ui/views/controls/webview/webview.h" | 28 #include "ui/views/controls/webview/webview.h" |
31 | 29 |
32 using views::View; | 30 using views::View; |
33 | 31 |
34 namespace { | 32 namespace { |
35 | 33 |
36 // The visible height of the shadow above the tabs. Clicks in this area are | 34 // The visible height of the shadow above the tabs. Clicks in this area are |
37 // treated as clicks to the frame, rather than clicks to the tab. | 35 // treated as clicks to the frame, rather than clicks to the tab. |
38 const int kTabShadowSize = 2; | 36 const int kTabShadowSize = 2; |
39 // The number of pixels the bookmark bar should overlap the spacer by if the | 37 // The number of pixels the bookmark bar should overlap the spacer by if the |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 }; | 99 }; |
102 | 100 |
103 // static | 101 // static |
104 const int BrowserViewLayout::kToolbarTabStripVerticalOverlap = 3; | 102 const int BrowserViewLayout::kToolbarTabStripVerticalOverlap = 3; |
105 | 103 |
106 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
107 // BrowserViewLayout, public: | 105 // BrowserViewLayout, public: |
108 | 106 |
109 BrowserViewLayout::BrowserViewLayout() | 107 BrowserViewLayout::BrowserViewLayout() |
110 : browser_(NULL), | 108 : browser_(NULL), |
| 109 delegate_(NULL), |
111 browser_view_(NULL), | 110 browser_view_(NULL), |
| 111 top_container_(NULL), |
| 112 tab_strip_(NULL), |
| 113 toolbar_(NULL), |
112 bookmark_bar_(NULL), | 114 bookmark_bar_(NULL), |
113 infobar_container_(NULL), | 115 infobar_container_(NULL), |
114 contents_split_(NULL), | 116 contents_split_(NULL), |
115 contents_container_(NULL), | 117 contents_container_(NULL), |
116 overlay_container_(NULL), | 118 overlay_container_(NULL), |
| 119 window_switcher_button_(NULL), |
117 download_shelf_(NULL), | 120 download_shelf_(NULL), |
| 121 immersive_mode_controller_(NULL), |
118 dialog_host_(new WebContentsModalDialogHostViews(this)), | 122 dialog_host_(new WebContentsModalDialogHostViews(this)), |
119 web_contents_modal_dialog_top_y_(-1) { | 123 web_contents_modal_dialog_top_y_(-1) { |
120 } | 124 } |
121 | 125 |
122 BrowserViewLayout::~BrowserViewLayout() { | 126 BrowserViewLayout::~BrowserViewLayout() { |
123 } | 127 } |
124 | 128 |
125 void BrowserViewLayout::Init(Browser* browser, | 129 void BrowserViewLayout::Init( |
126 BrowserView* browser_view, | 130 Browser* browser, |
127 InfoBarContainerView* infobar_container, | 131 BrowserViewLayoutDelegate* delegate, |
128 views::SingleSplitView* contents_split, | 132 BrowserView* browser_view, |
129 ContentsContainer* contents_container, | 133 views::View* top_container, |
130 OverlayContainer* overlay_container) { | 134 TabStrip* tab_strip, |
| 135 views::View* toolbar, |
| 136 InfoBarContainerView* infobar_container, |
| 137 views::View* contents_split, |
| 138 ContentsContainer* contents_container, |
| 139 OverlayContainer* overlay_container, |
| 140 ImmersiveModeController* immersive_mode_controller) { |
131 browser_ = browser; | 141 browser_ = browser; |
| 142 delegate_ = delegate; |
132 browser_view_ = browser_view; | 143 browser_view_ = browser_view; |
| 144 top_container_ = top_container; |
| 145 tab_strip_ = tab_strip; |
| 146 toolbar_ = toolbar; |
133 infobar_container_ = infobar_container; | 147 infobar_container_ = infobar_container; |
134 contents_split_ = contents_split; | 148 contents_split_ = contents_split; |
135 contents_container_ = contents_container; | 149 contents_container_ = contents_container; |
136 overlay_container_ = overlay_container; | 150 overlay_container_ = overlay_container; |
| 151 immersive_mode_controller_ = immersive_mode_controller; |
137 } | 152 } |
138 | 153 |
139 WebContentsModalDialogHost* | 154 WebContentsModalDialogHost* |
140 BrowserViewLayout::GetWebContentsModalDialogHost() { | 155 BrowserViewLayout::GetWebContentsModalDialogHost() { |
141 return dialog_host_.get(); | 156 return dialog_host_.get(); |
142 } | 157 } |
143 | 158 |
144 gfx::Size BrowserViewLayout::GetMinimumSize() { | 159 gfx::Size BrowserViewLayout::GetMinimumSize() { |
145 gfx::Size tabstrip_size( | 160 gfx::Size tabstrip_size( |
146 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? | 161 browser()->SupportsWindowFeature(Browser::FEATURE_TABSTRIP) ? |
147 browser_view_->tabstrip_->GetMinimumSize() : gfx::Size()); | 162 tab_strip_->GetMinimumSize() : gfx::Size()); |
148 BrowserNonClientFrameView::TabStripInsets tab_strip_insets( | 163 BrowserNonClientFrameView::TabStripInsets tab_strip_insets( |
149 browser_view_->frame()->GetTabStripInsets(false)); | 164 browser_view_->frame()->GetTabStripInsets(false)); |
150 gfx::Size toolbar_size( | 165 gfx::Size toolbar_size( |
151 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || | 166 (browser()->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || |
152 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? | 167 browser()->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) ? |
153 browser_view_->toolbar_->GetMinimumSize() : gfx::Size()); | 168 toolbar_->GetMinimumSize() : gfx::Size()); |
154 if (tabstrip_size.height() && toolbar_size.height()) | 169 if (tabstrip_size.height() && toolbar_size.height()) |
155 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); | 170 toolbar_size.Enlarge(0, -kToolbarTabStripVerticalOverlap); |
156 gfx::Size bookmark_bar_size; | 171 gfx::Size bookmark_bar_size; |
157 if (bookmark_bar_ && | 172 if (bookmark_bar_ && |
158 bookmark_bar_->visible() && | 173 bookmark_bar_->visible() && |
159 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { | 174 browser()->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR)) { |
160 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); | 175 bookmark_bar_size = bookmark_bar_->GetMinimumSize(); |
161 bookmark_bar_size.Enlarge(0, | 176 bookmark_bar_size.Enlarge(0, |
162 -(views::NonClientFrameView::kClientEdgeThickness + | 177 -(views::NonClientFrameView::kClientEdgeThickness + |
163 bookmark_bar_->GetToolbarOverlap(true))); | 178 bookmark_bar_->GetToolbarOverlap(true))); |
(...skipping 18 matching lines...) Expand all Loading... |
182 // basically implies the "user-perceived content area" of the browser | 197 // basically implies the "user-perceived content area" of the browser |
183 // window excluding the vertical scrollbar. The "user-perceived content area" | 198 // window excluding the vertical scrollbar. The "user-perceived content area" |
184 // excludes the detached bookmark bar (in the New Tab case) and any infobars | 199 // excludes the detached bookmark bar (in the New Tab case) and any infobars |
185 // since they are not _visually_ connected to the Toolbar. | 200 // since they are not _visually_ connected to the Toolbar. |
186 | 201 |
187 // First determine the bounding box of the content area in Widget | 202 // First determine the bounding box of the content area in Widget |
188 // coordinates. | 203 // coordinates. |
189 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget( | 204 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget( |
190 contents_container_->GetLocalBounds()); | 205 contents_container_->GetLocalBounds()); |
191 | 206 |
192 TopContainerView* top_container = browser_view_->top_container(); | 207 gfx::Rect top_container_bounds = top_container_->ConvertRectToWidget( |
193 gfx::Rect top_container_bounds = top_container->ConvertRectToWidget( | 208 top_container_->GetLocalBounds()); |
194 top_container->GetLocalBounds()); | |
195 | 209 |
196 // The find bar is positioned 1 pixel above the bottom of the top container so | 210 // The find bar is positioned 1 pixel above the bottom of the top container so |
197 // that it occludes the border between the content area and the top container | 211 // that it occludes the border between the content area and the top container |
198 // and looks connected to the top container. | 212 // and looks connected to the top container. |
199 int find_bar_y = top_container_bounds.bottom() - 1; | 213 int find_bar_y = top_container_bounds.bottom() - 1; |
200 | 214 |
201 // Grow the height of |bounding_box| by the height of any elements between | 215 // Grow the height of |bounding_box| by the height of any elements between |
202 // the top container and |contents_container_| such as the detached bookmark | 216 // the top container and |contents_container_| such as the detached bookmark |
203 // bar and any infobars. | 217 // bar and any infobars. |
204 int height_delta = bounding_box.y() - find_bar_y; | 218 int height_delta = bounding_box.y() - find_bar_y; |
205 bounding_box.set_y(find_bar_y); | 219 bounding_box.set_y(find_bar_y); |
206 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta)); | 220 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta)); |
207 | 221 |
208 // Finally decrease the width of the bounding box by the width of | 222 // Finally decrease the width of the bounding box by the width of |
209 // the vertical scroll bar. | 223 // the vertical scroll bar. |
210 int scrollbar_width = gfx::scrollbar_size(); | 224 int scrollbar_width = gfx::scrollbar_size(); |
211 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); | 225 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); |
212 if (base::i18n::IsRTL()) | 226 if (base::i18n::IsRTL()) |
213 bounding_box.set_x(bounding_box.x() + scrollbar_width); | 227 bounding_box.set_x(bounding_box.x() + scrollbar_width); |
214 | 228 |
215 return bounding_box; | 229 return bounding_box; |
216 } | 230 } |
217 | 231 |
218 bool BrowserViewLayout::IsPositionInWindowCaption( | 232 bool BrowserViewLayout::IsPositionInWindowCaption( |
219 const gfx::Point& point) { | 233 const gfx::Point& point) { |
220 TabStrip* tabstrip = browser_view_->tabstrip_; | |
221 // Tab strip may transiently have no parent between the RemoveChildView() and | 234 // Tab strip may transiently have no parent between the RemoveChildView() and |
222 // AddChildView() caused by reparenting during an immersive mode reveal. | 235 // AddChildView() caused by reparenting during an immersive mode reveal. |
223 // During this window report that the point didn't hit a tab. | 236 // During this window report that the point didn't hit a tab. |
224 if (!tabstrip->parent()) | 237 if (!tab_strip_->parent()) |
225 return true; | 238 return true; |
226 gfx::Point tabstrip_point(point); | 239 gfx::Point tabstrip_point(point); |
227 views::View::ConvertPointToTarget(browser_view_, tabstrip, &tabstrip_point); | 240 views::View::ConvertPointToTarget(browser_view_, tab_strip_, &tabstrip_point); |
228 return tabstrip->IsPositionInWindowCaption(tabstrip_point); | 241 return tab_strip_->IsPositionInWindowCaption(tabstrip_point); |
229 } | 242 } |
230 | 243 |
231 int BrowserViewLayout::NonClientHitTest( | 244 int BrowserViewLayout::NonClientHitTest( |
232 const gfx::Point& point) { | 245 const gfx::Point& point) { |
233 // Since the TabStrip only renders in some parts of the top of the window, | 246 // Since the TabStrip only renders in some parts of the top of the window, |
234 // the un-obscured area is considered to be part of the non-client caption | 247 // the un-obscured area is considered to be part of the non-client caption |
235 // area of the window. So we need to treat hit-tests in these regions as | 248 // area of the window. So we need to treat hit-tests in these regions as |
236 // hit-tests of the titlebar. | 249 // hit-tests of the titlebar. |
237 | 250 |
238 views::View* parent = browser_view_->parent(); | 251 views::View* parent = browser_view_->parent(); |
239 | 252 |
240 gfx::Point point_in_browser_view_coords(point); | 253 gfx::Point point_in_browser_view_coords(point); |
241 views::View::ConvertPointToTarget( | 254 views::View::ConvertPointToTarget( |
242 parent, browser_view_, &point_in_browser_view_coords); | 255 parent, browser_view_, &point_in_browser_view_coords); |
243 gfx::Point test_point(point); | 256 gfx::Point test_point(point); |
244 | 257 |
245 // Determine if the TabStrip exists and is capable of being clicked on. We | 258 // Determine if the TabStrip exists and is capable of being clicked on. We |
246 // might be a popup window without a TabStrip. | 259 // might be a popup window without a TabStrip. |
247 if (browser_view_->IsTabStripVisible()) { | 260 if (browser_view_->IsTabStripVisible()) { |
248 // See if the mouse pointer is within the bounds of the TabStrip. | 261 // See if the mouse pointer is within the bounds of the TabStrip. |
249 if (ConvertedHitTest(parent, browser_view_->tabstrip_, &test_point)) { | 262 if (ConvertedHitTest(parent, tab_strip_, &test_point)) { |
250 if (browser_view_->tabstrip_->IsPositionInWindowCaption(test_point)) | 263 if (tab_strip_->IsPositionInWindowCaption(test_point)) |
251 return HTCAPTION; | 264 return HTCAPTION; |
252 return HTCLIENT; | 265 return HTCLIENT; |
253 } | 266 } |
254 | 267 |
255 // The top few pixels of the TabStrip are a drop-shadow - as we're pretty | 268 // The top few pixels of the TabStrip are a drop-shadow - as we're pretty |
256 // starved of dragable area, let's give it to window dragging (this also | 269 // starved of dragable area, let's give it to window dragging (this also |
257 // makes sense visually). | 270 // makes sense visually). |
258 if (!browser_view_->IsMaximized() && | 271 if (!browser_view_->IsMaximized() && |
259 (point_in_browser_view_coords.y() < | 272 (point_in_browser_view_coords.y() < |
260 (browser_view_->tabstrip_->y() + kTabShadowSize))) { | 273 (tab_strip_->y() + kTabShadowSize))) { |
261 // We return HTNOWHERE as this is a signal to our containing | 274 // We return HTNOWHERE as this is a signal to our containing |
262 // NonClientView that it should figure out what the correct hit-test | 275 // NonClientView that it should figure out what the correct hit-test |
263 // code is given the mouse position... | 276 // code is given the mouse position... |
264 return HTNOWHERE; | 277 return HTNOWHERE; |
265 } | 278 } |
266 } | 279 } |
267 | 280 |
268 // If the point's y coordinate is below the top of the toolbar and otherwise | 281 // If the point's y coordinate is below the top of the toolbar and otherwise |
269 // within the bounds of this view, the point is considered to be within the | 282 // within the bounds of this view, the point is considered to be within the |
270 // client area. | 283 // client area. |
271 gfx::Rect bv_bounds = browser_view_->bounds(); | 284 gfx::Rect bv_bounds = browser_view_->bounds(); |
272 bv_bounds.Offset(0, browser_view_->toolbar_->y()); | 285 bv_bounds.Offset(0, toolbar_->y()); |
273 bv_bounds.set_height(bv_bounds.height() - browser_view_->toolbar_->y()); | 286 bv_bounds.set_height(bv_bounds.height() - toolbar_->y()); |
274 if (bv_bounds.Contains(point)) | 287 if (bv_bounds.Contains(point)) |
275 return HTCLIENT; | 288 return HTCLIENT; |
276 | 289 |
277 // If the point's y coordinate is above the top of the toolbar, but not in | 290 // If the point's y coordinate is above the top of the toolbar, but not in |
278 // the tabstrip (per previous checking in this function), then we consider it | 291 // the tabstrip (per previous checking in this function), then we consider it |
279 // in the window caption (e.g. the area to the right of the tabstrip | 292 // in the window caption (e.g. the area to the right of the tabstrip |
280 // underneath the window controls). However, note that we DO NOT return | 293 // underneath the window controls). However, note that we DO NOT return |
281 // HTCAPTION here, because when the window is maximized the window controls | 294 // HTCAPTION here, because when the window is maximized the window controls |
282 // will fall into this space (since the BrowserView is sized to entire size | 295 // will fall into this space (since the BrowserView is sized to entire size |
283 // of the window at that point), and the HTCAPTION value will cause the | 296 // of the window at that point), and the HTCAPTION value will cause the |
284 // window controls not to work. So we return HTNOWHERE so that the caller | 297 // window controls not to work. So we return HTNOWHERE so that the caller |
285 // will hit-test the window controls before finally falling back to | 298 // will hit-test the window controls before finally falling back to |
286 // HTCAPTION. | 299 // HTCAPTION. |
287 bv_bounds = browser_view_->bounds(); | 300 bv_bounds = browser_view_->bounds(); |
288 bv_bounds.set_height(browser_view_->toolbar_->y()); | 301 bv_bounds.set_height(toolbar_->y()); |
289 if (bv_bounds.Contains(point)) | 302 if (bv_bounds.Contains(point)) |
290 return HTNOWHERE; | 303 return HTNOWHERE; |
291 | 304 |
292 // If the point is somewhere else, delegate to the default implementation. | 305 // If the point is somewhere else, delegate to the default implementation. |
293 return browser_view_->views::ClientView::NonClientHitTest(point); | 306 return browser_view_->views::ClientView::NonClientHitTest(point); |
294 } | 307 } |
295 | 308 |
296 ////////////////////////////////////////////////////////////////////////////// | 309 ////////////////////////////////////////////////////////////////////////////// |
297 // BrowserViewLayout, views::LayoutManager implementation: | 310 // BrowserViewLayout, views::LayoutManager implementation: |
298 | 311 |
299 void BrowserViewLayout::Layout(views::View* host) { | 312 void BrowserViewLayout::Layout(views::View* browser_view) { |
300 vertical_layout_rect_ = browser_view_->GetLocalBounds(); | 313 vertical_layout_rect_ = browser_view->GetLocalBounds(); |
301 int top = LayoutTabStripRegion(); | 314 int top = LayoutTabStripRegion(browser_view); |
302 if (browser_view_->IsTabStripVisible()) { | 315 if (delegate_->IsTabStripVisible()) { |
303 int x = browser_view_->tabstrip_->GetMirroredX() + | 316 int x = tab_strip_->GetMirroredX() + |
304 browser_view_->GetMirroredX() + | 317 browser_view_->GetMirroredX() + |
305 browser_view_->frame()->GetThemeBackgroundXInset(); | 318 browser_view_->frame()->GetThemeBackgroundXInset(); |
306 browser_view_->tabstrip_->SetBackgroundOffset(gfx::Point(x, | 319 tab_strip_->SetBackgroundOffset( |
307 browser_view_->frame()->GetTabStripInsets(false).top)); | 320 gfx::Point(x, browser_view_->frame()->GetTabStripInsets(false).top)); |
308 } | 321 } |
309 top = LayoutToolbar(top); | 322 top = LayoutToolbar(top); |
310 | 323 |
| 324 web_contents_modal_dialog_top_y_ = |
| 325 top + browser_view->y() - kConstrainedWindowOverlap; |
| 326 |
311 // Overlay container requires updated toolbar bounds to determine its | 327 // Overlay container requires updated toolbar bounds to determine its |
312 // position, and needs to be laid out before: | 328 // position, and needs to be laid out before: |
313 // - GetTopMarginForActiveContent(), which calls GetInstantUIState() to check | 329 // - GetTopMarginForActiveContent(), which calls GetInstantUIState() to check |
314 // if overlay container is visible | 330 // if overlay container is visible |
315 // - LayoutInfoBar(): children of infobar container will layout and call | 331 // - LayoutInfoBar(): children of infobar container will layout and call |
316 // BrowserView::DrawInfoBarArrows(), which checks if overlay container is | 332 // BrowserView::DrawInfoBarArrows(), which checks if overlay container is |
317 // visible. | 333 // visible. |
318 LayoutOverlayContainer(); | 334 LayoutOverlayContainer(); |
319 | 335 |
320 top = LayoutBookmarkAndInfoBars(top); | 336 top = LayoutBookmarkAndInfoBars(top); |
321 | 337 |
322 // Top container requires updated toolbar and bookmark bar to compute size. | 338 // Top container requires updated toolbar and bookmark bar to compute size. |
323 browser_view_->top_container_->SetSize( | 339 top_container_->SetSize(top_container_->GetPreferredSize()); |
324 browser_view_->top_container_->GetPreferredSize()); | |
325 | 340 |
326 int bottom = LayoutDownloadShelf(browser_view_->height()); | 341 int bottom = LayoutDownloadShelf(browser_view->height()); |
327 // Treat a detached bookmark bar as if the web contents container is shifted | 342 // Treat a detached bookmark bar as if the web contents container is shifted |
328 // upwards and overlaps it. | 343 // upwards and overlaps it. |
329 top -= GetContentsOffsetForBookmarkBar(); | 344 top -= GetContentsOffsetForBookmarkBar(); |
330 LayoutContentsSplitView(top, bottom); | 345 LayoutContentsSplitView(top, bottom); |
331 | 346 |
332 // Instant extended can put suggestions in a web view, which can require an | 347 // Instant extended can put suggestions in a web view, which can require an |
333 // offset to align with the omnibox. This offset must be recomputed after | 348 // offset to align with the omnibox. This offset must be recomputed after |
334 // split view layout to account for infobar heights. | 349 // split view layout to account for infobar heights. |
335 int active_top_margin = GetTopMarginForActiveContent(); | 350 int active_top_margin = GetTopMarginForActiveContent(); |
336 if (contents_container_->SetActiveTopMargin(active_top_margin)) | 351 if (contents_container_->SetActiveTopMargin(active_top_margin)) |
(...skipping 14 matching lines...) Expand all Loading... |
351 | 366 |
352 // Return the preferred size which is the size required to give each | 367 // Return the preferred size which is the size required to give each |
353 // children their respective preferred size. | 368 // children their respective preferred size. |
354 gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) { | 369 gfx::Size BrowserViewLayout::GetPreferredSize(views::View* host) { |
355 return gfx::Size(); | 370 return gfx::Size(); |
356 } | 371 } |
357 | 372 |
358 ////////////////////////////////////////////////////////////////////////////// | 373 ////////////////////////////////////////////////////////////////////////////// |
359 // BrowserViewLayout, private: | 374 // BrowserViewLayout, private: |
360 | 375 |
361 int BrowserViewLayout::LayoutTabStripRegion() { | 376 int BrowserViewLayout::LayoutTabStripRegion(views::View* browser_view) { |
362 TabStrip* tabstrip = browser_view_->tabstrip_; | 377 if (!delegate_->IsTabStripVisible()) { |
363 if (!browser_view_->IsTabStripVisible()) { | 378 tab_strip_->SetVisible(false); |
364 tabstrip->SetVisible(false); | 379 tab_strip_->SetBounds(0, 0, 0, 0); |
365 tabstrip->SetBounds(0, 0, 0, 0); | |
366 return 0; | 380 return 0; |
367 } | 381 } |
368 // This retrieves the bounds for the tab strip based on whether or not we show | 382 // This retrieves the bounds for the tab strip based on whether or not we show |
369 // anything to the left of it, like the incognito avatar. | 383 // anything to the left of it, like the incognito avatar. |
370 gfx::Rect tabstrip_bounds( | 384 gfx::Rect tabstrip_bounds(delegate_->GetBoundsForTabStrip(tab_strip_)); |
371 browser_view_->frame()->GetBoundsForTabStrip(tabstrip)); | |
372 gfx::Point tabstrip_origin(tabstrip_bounds.origin()); | 385 gfx::Point tabstrip_origin(tabstrip_bounds.origin()); |
373 views::View::ConvertPointToTarget(browser_view_->parent(), browser_view_, | 386 views::View::ConvertPointToTarget( |
374 &tabstrip_origin); | 387 browser_view->parent(), browser_view, &tabstrip_origin); |
375 tabstrip_bounds.set_origin(tabstrip_origin); | 388 tabstrip_bounds.set_origin(tabstrip_origin); |
376 | 389 |
377 tabstrip->SetVisible(true); | 390 tab_strip_->SetVisible(true); |
378 tabstrip->SetBoundsRect(tabstrip_bounds); | 391 tab_strip_->SetBoundsRect(tabstrip_bounds); |
379 int bottom = tabstrip_bounds.bottom(); | 392 int bottom = tabstrip_bounds.bottom(); |
380 | 393 |
381 // The metro window switcher sits at the far right edge of the tabstrip | 394 // The metro window switcher sits at the far right edge of the tabstrip |
382 // a |kWindowSwitcherOffsetX| pixels from the right edge. | 395 // a |kWindowSwitcherOffsetX| pixels from the right edge. |
383 // Only visible if there is more than one type of window to switch between. | 396 // Only visible if there is more than one type of window to switch between. |
384 // TODO(mad): update this code when more window types than just incognito | 397 // TODO(mad): update this code when more window types than just incognito |
385 // and regular are available. | 398 // and regular are available. |
386 views::Button* switcher_button = browser_view_->window_switcher_button_; | 399 views::View* switcher_button = window_switcher_button_; |
387 if (switcher_button) { | 400 if (switcher_button) { |
388 if (browser()->profile()->HasOffTheRecordProfile() && | 401 if (browser()->profile()->HasOffTheRecordProfile() && |
389 chrome::FindBrowserWithProfile( | 402 chrome::FindBrowserWithProfile( |
390 browser()->profile()->GetOriginalProfile(), | 403 browser()->profile()->GetOriginalProfile(), |
391 browser()->host_desktop_type()) != NULL) { | 404 browser()->host_desktop_type()) != NULL) { |
392 switcher_button->SetVisible(true); | 405 switcher_button->SetVisible(true); |
393 int width = browser_view_->width(); | 406 int width = browser_view->width(); |
394 gfx::Size ps = switcher_button->GetPreferredSize(); | 407 gfx::Size ps = switcher_button->GetPreferredSize(); |
395 if (width > ps.width()) { | 408 if (width > ps.width()) { |
396 switcher_button->SetBounds(width - ps.width() - kWindowSwitcherOffsetX, | 409 switcher_button->SetBounds(width - ps.width() - kWindowSwitcherOffsetX, |
397 0, | 410 0, |
398 ps.width(), | 411 ps.width(), |
399 ps.height()); | 412 ps.height()); |
400 } | 413 } |
401 } else { | 414 } else { |
402 // We hide the button if the incognito profile is not alive. | 415 // We hide the button if the incognito profile is not alive. |
403 // Note that Layout() is not called to all browser windows automatically | 416 // Note that Layout() is not called to all browser windows automatically |
404 // when a profile goes away but we rely in the metro_driver.dll to call | 417 // when a profile goes away but we rely in the metro_driver.dll to call |
405 // ::SetWindowPos( , .. SWP_SHOWWINDOW) which causes this function to | 418 // ::SetWindowPos( , .. SWP_SHOWWINDOW) which causes this function to |
406 // be called again. This works both in showing or hidding the button. | 419 // be called again. This works both in showing or hidding the button. |
407 switcher_button->SetVisible(false); | 420 switcher_button->SetVisible(false); |
408 } | 421 } |
409 } | 422 } |
410 | 423 |
411 return bottom; | 424 return bottom; |
412 } | 425 } |
413 | 426 |
414 int BrowserViewLayout::LayoutToolbar(int top) { | 427 int BrowserViewLayout::LayoutToolbar(int top) { |
415 ToolbarView* toolbar = browser_view_->toolbar_; | |
416 int browser_view_width = vertical_layout_rect_.width(); | 428 int browser_view_width = vertical_layout_rect_.width(); |
417 bool toolbar_visible = browser_view_->IsToolbarVisible(); | 429 bool toolbar_visible = delegate_->IsToolbarVisible(); |
418 toolbar->location_bar()->SetLocationEntryFocusable(toolbar_visible); | |
419 int y = top; | 430 int y = top; |
420 y -= (toolbar_visible && browser_view_->IsTabStripVisible()) ? | 431 y -= (toolbar_visible && delegate_->IsTabStripVisible()) ? |
421 kToolbarTabStripVerticalOverlap : 0; | 432 kToolbarTabStripVerticalOverlap : 0; |
422 int height = toolbar_visible ? toolbar->GetPreferredSize().height() : 0; | 433 int height = toolbar_visible ? toolbar_->GetPreferredSize().height() : 0; |
423 toolbar->SetVisible(toolbar_visible); | 434 toolbar_->SetVisible(toolbar_visible); |
424 toolbar->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); | 435 toolbar_->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); |
425 | 436 |
426 return y + height; | 437 return y + height; |
427 } | 438 } |
428 | 439 |
429 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) { | 440 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) { |
430 web_contents_modal_dialog_top_y_ = | |
431 top + browser_view_->y() - kConstrainedWindowOverlap; | |
432 if (bookmark_bar_) { | 441 if (bookmark_bar_) { |
433 // If we're showing the Bookmark bar in detached style, then we | 442 // If we're showing the Bookmark bar in detached style, then we |
434 // need to show any Info bar _above_ the Bookmark bar, since the | 443 // need to show any Info bar _above_ the Bookmark bar, since the |
435 // Bookmark bar is styled to look like it's part of the page. | 444 // Bookmark bar is styled to look like it's part of the page. |
436 if (bookmark_bar_->IsDetached()) | 445 if (bookmark_bar_->IsDetached()) |
437 return LayoutBookmarkBar(LayoutInfoBar(top)); | 446 return LayoutBookmarkBar(LayoutInfoBar(top)); |
438 // Otherwise, Bookmark bar first, Info bar second. | 447 // Otherwise, Bookmark bar first, Info bar second. |
439 top = std::max(browser_view_->toolbar_->bounds().bottom(), | 448 top = std::max(toolbar_->bounds().bottom(), LayoutBookmarkBar(top)); |
440 LayoutBookmarkBar(top)); | |
441 } | 449 } |
442 return LayoutInfoBar(top); | 450 return LayoutInfoBar(top); |
443 } | 451 } |
444 | 452 |
445 int BrowserViewLayout::LayoutBookmarkBar(int top) { | 453 int BrowserViewLayout::LayoutBookmarkBar(int top) { |
446 int y = top; | 454 int y = top; |
447 if (!browser_view_->IsBookmarkBarVisible()) { | 455 if (!delegate_->IsBookmarkBarVisible()) { |
448 bookmark_bar_->SetVisible(false); | 456 bookmark_bar_->SetVisible(false); |
449 // TODO(jamescook): Don't change the bookmark bar height when it is | 457 // TODO(jamescook): Don't change the bookmark bar height when it is |
450 // invisible, so we can use its height for layout even in that state. | 458 // invisible, so we can use its height for layout even in that state. |
451 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0); | 459 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0); |
452 return y; | 460 return y; |
453 } | 461 } |
454 | 462 |
455 bookmark_bar_->set_infobar_visible(InfobarVisible()); | 463 bookmark_bar_->set_infobar_visible(InfobarVisible()); |
456 int bookmark_bar_height = bookmark_bar_->GetPreferredSize().height(); | 464 int bookmark_bar_height = bookmark_bar_->GetPreferredSize().height(); |
457 y -= views::NonClientFrameView::kClientEdgeThickness + | 465 y -= views::NonClientFrameView::kClientEdgeThickness + |
458 bookmark_bar_->GetToolbarOverlap(false); | 466 bookmark_bar_->GetToolbarOverlap(false); |
459 bookmark_bar_->SetVisible(true); | 467 bookmark_bar_->SetVisible(true); |
460 bookmark_bar_->SetBounds(vertical_layout_rect_.x(), y, | 468 bookmark_bar_->SetBounds(vertical_layout_rect_.x(), y, |
461 vertical_layout_rect_.width(), | 469 vertical_layout_rect_.width(), |
462 bookmark_bar_height); | 470 bookmark_bar_height); |
463 return y + bookmark_bar_height; | 471 return y + bookmark_bar_height; |
464 } | 472 } |
465 | 473 |
466 int BrowserViewLayout::LayoutInfoBar(int top) { | 474 int BrowserViewLayout::LayoutInfoBar(int top) { |
467 // In immersive fullscreen, the infobar always starts near the top of the | 475 // In immersive fullscreen, the infobar always starts near the top of the |
468 // screen, just under the "light bar" rectangular stripes. | 476 // screen, just under the "light bar" rectangular stripes. |
469 if (browser_view_->immersive_mode_controller_->IsEnabled()) { | 477 if (immersive_mode_controller_->IsEnabled()) { |
470 top = browser_view_->immersive_mode_controller_->ShouldHideTabIndicators() ? | 478 top = immersive_mode_controller_->ShouldHideTabIndicators() |
471 browser_view_->y() : | 479 ? browser_view_->y() |
472 browser_view_->y() + TabStrip::GetImmersiveHeight(); | 480 : browser_view_->y() + TabStrip::GetImmersiveHeight(); |
473 } | 481 } |
474 InfoBarContainerView* infobar_container = browser_view_->infobar_container_; | 482 // Raise the |infobar_container_| by its vertical overlap. |
475 // Raise the |infobar_container| by its vertical overlap. | 483 infobar_container_->SetVisible(InfobarVisible()); |
476 infobar_container->SetVisible(InfobarVisible()); | |
477 int height; | 484 int height; |
478 int overlapped_top = top - infobar_container->GetVerticalOverlap(&height); | 485 int overlapped_top = top - infobar_container_->GetVerticalOverlap(&height); |
479 infobar_container->SetBounds(vertical_layout_rect_.x(), | 486 infobar_container_->SetBounds(vertical_layout_rect_.x(), |
480 overlapped_top, | 487 overlapped_top, |
481 vertical_layout_rect_.width(), | 488 vertical_layout_rect_.width(), |
482 height); | 489 height); |
483 return overlapped_top + height; | 490 return overlapped_top + height; |
484 } | 491 } |
485 | 492 |
486 void BrowserViewLayout::LayoutContentsSplitView(int top, int bottom) { | 493 void BrowserViewLayout::LayoutContentsSplitView(int top, int bottom) { |
487 // |contents_split_| contains web page contents and devtools. | 494 // |contents_split_| contains web page contents and devtools. |
488 // See browser_view.h for details. | 495 // See browser_view.h for details. |
489 gfx::Rect contents_split_bounds(vertical_layout_rect_.x(), | 496 gfx::Rect contents_split_bounds(vertical_layout_rect_.x(), |
490 top, | 497 top, |
491 vertical_layout_rect_.width(), | 498 vertical_layout_rect_.width(), |
492 std::max(0, bottom - top)); | 499 std::max(0, bottom - top)); |
493 contents_split_->SetBoundsRect(contents_split_bounds); | 500 contents_split_->SetBoundsRect(contents_split_bounds); |
494 } | 501 } |
495 | 502 |
496 void BrowserViewLayout::LayoutOverlayContainer() { | 503 void BrowserViewLayout::LayoutOverlayContainer() { |
497 bool full_height = overlay_container_->IsOverlayFullHeight(); | 504 bool full_height = overlay_container_->IsOverlayFullHeight(); |
498 int preferred_height = 0; | 505 int preferred_height = 0; |
499 if (!full_height) | 506 if (!full_height) |
500 preferred_height = overlay_container_->GetPreferredSize().height(); | 507 preferred_height = overlay_container_->GetPreferredSize().height(); |
501 overlay_container_->SetVisible(full_height || preferred_height > 0); | 508 overlay_container_->SetVisible(full_height || preferred_height > 0); |
502 if (!overlay_container_->visible()) | 509 if (!overlay_container_->visible()) |
503 return; | 510 return; |
504 ToolbarView* toolbar = browser_view_->toolbar_; | 511 gfx::Point bottom_edge(0, toolbar_->bounds().bottom()); |
505 gfx::Point bottom_edge(0, toolbar->bounds().bottom()); | |
506 views::View::ConvertPointToTarget( | 512 views::View::ConvertPointToTarget( |
507 toolbar->parent(), browser_view_, &bottom_edge); | 513 toolbar_->parent(), browser_view_, &bottom_edge); |
508 // Overlaps with the toolbar like the attached bookmark bar would, so as to | 514 // Overlaps with the toolbar like the attached bookmark bar would, so as to |
509 // completely obscure the attached bookmark bar if it were visible. | 515 // completely obscure the attached bookmark bar if it were visible. |
510 bottom_edge.Offset(0, | 516 bottom_edge.Offset(0, |
511 -(views::NonClientFrameView::kClientEdgeThickness + | 517 -(views::NonClientFrameView::kClientEdgeThickness + |
512 BookmarkBarView::kToolbarAttachedBookmarkBarOverlap)); | 518 BookmarkBarView::kToolbarAttachedBookmarkBarOverlap)); |
513 gfx::Rect rect(vertical_layout_rect_); | 519 gfx::Rect rect(vertical_layout_rect_); |
514 rect.Inset(0, bottom_edge.y(), 0, 0); | 520 rect.Inset(0, bottom_edge.y(), 0, 0); |
515 if (!full_height && preferred_height < rect.height()) | 521 if (!full_height && preferred_height < rect.height()) |
516 rect.set_height(preferred_height); | 522 rect.set_height(preferred_height); |
517 overlay_container_->SetBoundsRect(rect); | 523 overlay_container_->SetBoundsRect(rect); |
(...skipping 16 matching lines...) Expand all Loading... |
534 return bookmark_bar_->height() - | 540 return bookmark_bar_->height() - |
535 views::NonClientFrameView::kClientEdgeThickness; | 541 views::NonClientFrameView::kClientEdgeThickness; |
536 } | 542 } |
537 | 543 |
538 int BrowserViewLayout::GetTopMarginForActiveContent() { | 544 int BrowserViewLayout::GetTopMarginForActiveContent() { |
539 // During an immersive reveal, if instant extended is showing suggestions | 545 // During an immersive reveal, if instant extended is showing suggestions |
540 // in the main active web view, ensure that active web view appears aligned | 546 // in the main active web view, ensure that active web view appears aligned |
541 // with the bottom of the omnibox. | 547 // with the bottom of the omnibox. |
542 InstantUIState instant_ui_state = GetInstantUIState(); | 548 InstantUIState instant_ui_state = GetInstantUIState(); |
543 if (instant_ui_state == kInstantUIFullPageResults && | 549 if (instant_ui_state == kInstantUIFullPageResults && |
544 browser_view_->immersive_mode_controller()->IsRevealed()) | 550 immersive_mode_controller_->IsRevealed()) |
545 return GetTopMarginForImmersiveInstant(); | 551 return GetTopMarginForImmersiveInstant(); |
546 | 552 |
547 // Usually we only use a margin if there's a detached bookmarks bar. | 553 // Usually we only use a margin if there's a detached bookmarks bar. |
548 return GetContentsOffsetForBookmarkBar(); | 554 return GetContentsOffsetForBookmarkBar(); |
549 } | 555 } |
550 | 556 |
551 int BrowserViewLayout::GetTopMarginForImmersiveInstant() { | 557 int BrowserViewLayout::GetTopMarginForImmersiveInstant() { |
552 // Compute the position of the bottom edge of the top container views, | 558 // Compute the position of the bottom edge of the top container views, |
553 // expressed as an offset in the coordinates of |contents_container_|, | 559 // expressed as an offset in the coordinates of |contents_container_|, |
554 // because the offset will be applied in |contents_container_| layout. | 560 // because the offset will be applied in |contents_container_| layout. |
555 // NOTE: This requires contents_split_ layout to be complete, as the | 561 // NOTE: This requires contents_split_ layout to be complete, as the |
556 // coordinate system conversion depends on the contents_split_ origin. | 562 // coordinate system conversion depends on the contents_split_ origin. |
557 gfx::Point bottom_edge(0, browser_view_->top_container_->height()); | 563 gfx::Point bottom_edge(0, top_container_->height()); |
558 views::View::ConvertPointToTarget(browser_view_->top_container_, | 564 views::View::ConvertPointToTarget(top_container_, |
559 contents_container_, | 565 contents_container_, |
560 &bottom_edge); | 566 &bottom_edge); |
561 return bottom_edge.y(); | 567 return bottom_edge.y(); |
562 } | 568 } |
563 | 569 |
564 BrowserViewLayout::InstantUIState BrowserViewLayout::GetInstantUIState() { | 570 BrowserViewLayout::InstantUIState BrowserViewLayout::GetInstantUIState() { |
565 if (!browser()->search_model()->mode().is_search()) | 571 if (!browser()->search_model()->mode().is_search()) |
566 return kInstantUINone; | 572 return kInstantUINone; |
567 | 573 |
568 // If the search suggestions are already being displayed in the overlay | 574 // If the search suggestions are already being displayed in the overlay |
569 // contents then return kInstantUIOverlay. | 575 // contents then return kInstantUIOverlay. |
570 if (overlay_container_->visible()) | 576 if (overlay_container_->visible()) |
571 return kInstantUIOverlay; | 577 return kInstantUIOverlay; |
572 | 578 |
573 // Top bars stay visible until the results page notifies Chrome it is ready. | 579 // Top bars stay visible until the results page notifies Chrome it is ready. |
574 if (browser()->search_model()->top_bars_visible()) | 580 if (browser()->search_model()->top_bars_visible()) |
575 return kInstantUINone; | 581 return kInstantUINone; |
576 | 582 |
577 return kInstantUIFullPageResults; | 583 return kInstantUIFullPageResults; |
578 } | 584 } |
579 | 585 |
580 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { | 586 int BrowserViewLayout::LayoutDownloadShelf(int bottom) { |
581 // Re-layout the shelf either if it is visible or if its close animation | 587 if (delegate_->DownloadShelfNeedsLayout()) { |
582 // is currently running. | |
583 if (browser_view_->IsDownloadShelfVisible() || | |
584 (download_shelf_ && download_shelf_->IsClosing())) { | |
585 bool visible = browser()->SupportsWindowFeature( | 588 bool visible = browser()->SupportsWindowFeature( |
586 Browser::FEATURE_DOWNLOADSHELF); | 589 Browser::FEATURE_DOWNLOADSHELF); |
587 DCHECK(download_shelf_); | 590 DCHECK(download_shelf_); |
588 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; | 591 int height = visible ? download_shelf_->GetPreferredSize().height() : 0; |
589 download_shelf_->SetVisible(visible); | 592 download_shelf_->SetVisible(visible); |
590 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, | 593 download_shelf_->SetBounds(vertical_layout_rect_.x(), bottom - height, |
591 vertical_layout_rect_.width(), height); | 594 vertical_layout_rect_.width(), height); |
592 download_shelf_->Layout(); | 595 download_shelf_->Layout(); |
593 bottom -= height; | 596 bottom -= height; |
594 } | 597 } |
595 return bottom; | 598 return bottom; |
596 } | 599 } |
597 | 600 |
598 bool BrowserViewLayout::InfobarVisible() const { | 601 bool BrowserViewLayout::InfobarVisible() const { |
599 // Cast to a views::View to access GetPreferredSize(). | 602 // Cast to a views::View to access GetPreferredSize(). |
600 views::View* infobar_container = infobar_container_; | 603 views::View* infobar_container = infobar_container_; |
601 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 604 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
602 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 605 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
603 (infobar_container->GetPreferredSize().height() != 0); | 606 (infobar_container->GetPreferredSize().height() != 0); |
604 } | 607 } |
OLD | NEW |