Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/browser_finder.h" | 7 #include "chrome/browser/ui/browser_finder.h" |
| 8 #include "chrome/browser/ui/find_bar/find_bar.h" | 8 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 9 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 9 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 10 #include "chrome/browser/ui/search/search_model.h" | |
| 10 #include "chrome/browser/ui/view_ids.h" | 11 #include "chrome/browser/ui/view_ids.h" |
| 11 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 12 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| 12 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 13 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_frame.h" | 14 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| 14 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "chrome/browser/ui/views/frame/contents_container.h" | 16 #include "chrome/browser/ui/views/frame/contents_container.h" |
| 16 #include "chrome/browser/ui/views/immersive_mode_controller.h" | 17 #include "chrome/browser/ui/views/immersive_mode_controller.h" |
| 17 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 18 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
| 18 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 19 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 19 #include "chrome/browser/ui/views/toolbar_view.h" | 20 #include "chrome/browser/ui/views/toolbar_view.h" |
| 20 #include "ui/base/hit_test.h" | 21 #include "ui/base/hit_test.h" |
| 21 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
| 22 #include "ui/gfx/scrollbar_size.h" | 23 #include "ui/gfx/scrollbar_size.h" |
| 23 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" |
| 24 #include "ui/views/controls/single_split_view.h" | 25 #include "ui/views/controls/single_split_view.h" |
| 26 #include "ui/views/controls/webview/webview.h" | |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 // The visible height of the shadow above the tabs. Clicks in this area are | 30 // The visible height of the shadow above the tabs. Clicks in this area are |
| 29 // treated as clicks to the frame, rather than clicks to the tab. | 31 // treated as clicks to the frame, rather than clicks to the tab. |
| 30 const int kTabShadowSize = 2; | 32 const int kTabShadowSize = 2; |
| 31 // The vertical overlap between the TabStrip and the Toolbar. | 33 // The vertical overlap between the TabStrip and the Toolbar. |
| 32 const int kToolbarTabStripVerticalOverlap = 3; | 34 const int kToolbarTabStripVerticalOverlap = 3; |
| 33 // The number of pixels the bookmark bar should overlap the spacer by if the | 35 // The number of pixels the bookmark bar should overlap the spacer by if the |
| 34 // spacer is visible. | 36 // spacer is visible. |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 252 |
| 251 void BrowserViewLayout::ViewRemoved(views::View* host, views::View* view) { | 253 void BrowserViewLayout::ViewRemoved(views::View* host, views::View* view) { |
| 252 switch (view->id()) { | 254 switch (view->id()) { |
| 253 case VIEW_ID_BOOKMARK_BAR: | 255 case VIEW_ID_BOOKMARK_BAR: |
| 254 active_bookmark_bar_ = NULL; | 256 active_bookmark_bar_ = NULL; |
| 255 break; | 257 break; |
| 256 } | 258 } |
| 257 } | 259 } |
| 258 | 260 |
| 259 void BrowserViewLayout::Layout(views::View* host) { | 261 void BrowserViewLayout::Layout(views::View* host) { |
| 262 // If pinned bookmark bar and infobars are hidden because suggestions are | |
| 263 // showing on a website page, the real estate released by the hidden bars | |
| 264 // after this layout will cause the contents to shift up visually, resulting | |
| 265 // in jankiness. To prevent the contents from shifting up, remember its | |
| 266 // origin (relative to |BrowserView|) before this layout starts, so that it | |
| 267 // can be restored after this layout finishes. | |
| 268 // Another way to preserve the contents page position is to determine the | |
| 269 // total height of all hidden bars. While that's possible with bookmark bar | |
| 270 // (i.e active_bookmark_bar_->height() - | |
| 271 // views::NonClientFrameView::kClientEdgeThickness + | |
| 272 // active_bookmark_bar_->GetToolbarOverlap(false)), | |
| 273 // it's not possible with infobar container. By the time Layout() is called, | |
| 274 // infobar container has already hidden all its bars, causing its | |
| 275 // GetVerticalOverlap() to return 0; as a result, the actual height of the | |
| 276 // infobars without the overlap cannot be determined. | |
|
Peter Kasting
2013/01/28 21:51:00
This comment confused the heck out of me.
How abo
kuan
2013/01/29 00:17:08
Done.
| |
| 277 const chrome::search::Mode& mode = browser()->search_model()->mode(); | |
| 278 views::WebView* contents = browser_view_->contents_container_; | |
| 279 gfx::Point old_contents_origin; | |
| 280 if (mode.is_search_suggestions() && mode.is_origin_default() && | |
| 281 // Bookmark bar is visible now but will be hidden during layout. | |
| 282 ((active_bookmark_bar_ && active_bookmark_bar_->visible() && | |
| 283 browser()->bookmark_bar_state() == BookmarkBar::HIDDEN) || | |
| 284 // Infobar container is visible now but will be hidden during layout. | |
| 285 (browser_view_->infobar_container_->visible() && !InfobarVisible()))) { | |
| 286 old_contents_origin = contents->bounds().origin(); | |
| 287 views::View::ConvertPointToTarget(contents->parent(), browser_view_, | |
| 288 &old_contents_origin); | |
| 289 } | |
| 290 | |
| 260 vertical_layout_rect_ = browser_view_->GetLocalBounds(); | 291 vertical_layout_rect_ = browser_view_->GetLocalBounds(); |
| 261 int top = LayoutTabStripRegion(); | 292 int top = LayoutTabStripRegion(); |
| 262 if (browser_view_->IsTabStripVisible()) { | 293 if (browser_view_->IsTabStripVisible()) { |
| 263 int x = browser_view_->tabstrip_->GetMirroredX() + | 294 int x = browser_view_->tabstrip_->GetMirroredX() + |
| 264 browser_view_->GetMirroredX() + | 295 browser_view_->GetMirroredX() + |
| 265 browser_view_->frame()->GetThemeBackgroundXInset(); | 296 browser_view_->frame()->GetThemeBackgroundXInset(); |
| 266 browser_view_->tabstrip_->SetBackgroundOffset(gfx::Point(x, | 297 browser_view_->tabstrip_->SetBackgroundOffset(gfx::Point(x, |
| 267 browser_view_->frame()->GetTabStripInsets(false).top)); | 298 browser_view_->frame()->GetTabStripInsets(false).top)); |
| 268 } | 299 } |
| 269 top = LayoutToolbar(top); | 300 top = LayoutToolbar(top); |
| 270 top = LayoutBookmarkAndInfoBars(top); | 301 top = LayoutBookmarkAndInfoBars(top); |
| 271 // During immersive mode reveal the content stays near the top of the view. | 302 // During immersive mode reveal the content stays near the top of the view. |
| 272 if (browser_view_->immersive_mode_controller()->IsRevealed()) { | 303 if (browser_view_->immersive_mode_controller()->IsRevealed()) { |
| 273 top = browser_view_->tabstrip_->y(); | 304 top = browser_view_->tabstrip_->y(); |
| 274 if (!browser_view_->immersive_mode_controller()->hide_tab_indicators()) | 305 if (!browser_view_->immersive_mode_controller()->hide_tab_indicators()) |
| 275 top += TabStrip::GetImmersiveHeight(); | 306 top += TabStrip::GetImmersiveHeight(); |
| 276 } | 307 } |
| 277 | 308 |
| 278 int bottom = LayoutDownloadShelf(browser_view_->height()); | 309 int bottom = LayoutDownloadShelf(browser_view_->height()); |
| 279 int active_top_margin = GetTopMarginForActiveContent(); | 310 int active_top_margin = GetTopMarginForActiveContent(); |
| 280 top -= active_top_margin; | 311 top -= active_top_margin; |
| 281 contents_container_->SetActiveTopMargin(active_top_margin); | 312 contents_container_->SetActiveTopMargin(active_top_margin); |
| 282 LayoutTabContents(top, bottom); | 313 LayoutTabContents(top, bottom); |
| 314 | |
| 315 // If previous origin of contents page relative to |BrowserView| needs to be | |
| 316 // preserved, set the vertical difference between new and previous origins as | |
| 317 // the active top margin in contents container, so that the contents don't | |
| 318 // shift up due to hiding of bookmark and info bars. | |
| 319 if (active_top_margin == 0 && !old_contents_origin.IsOrigin()) { | |
| 320 gfx::Point new_contents_origin(contents->bounds().origin()); | |
| 321 views::View::ConvertPointToTarget(contents->parent(), browser_view_, | |
| 322 &new_contents_origin); | |
| 323 active_top_margin = old_contents_origin.y() - new_contents_origin.y(); | |
| 324 DCHECK_GE(active_top_margin, 0); | |
| 325 // If ContentsContainer::SetPreview() has not been called yet, preview | |
| 326 // height will be 0, in which case, preserve the previous contents y origin, | |
| 327 // so that it can be restored in an upcoming Layout() call after the preview | |
| 328 // has been set. | |
| 329 // Otherwise, if preview is set, preserve previous contents origin only if | |
| 330 // preview is taller than all hidden bars, so as to prevent a blank area | |
| 331 // from showing above the contents (i.e. below the preview). | |
| 332 // Note that if Layout() is triggered by hiding of: | |
| 333 // - bookmark bar, preview would have been set because bookmark bar state is | |
| 334 // updated from |Browser| after |InstantPreviewControllerView| receives | |
| 335 // the notification that preview is ready and sets it. | |
| 336 // - infobars, there's no guarantee that preview has been set; if infobar | |
| 337 // container receives instant-preview-ready notification before | |
| 338 // |InstantPreviewControllerView|, there won't be preview here yet; | |
| 339 // hence the speical handling of the 0 preview height case. | |
|
Peter Kasting
2013/01/28 21:51:00
Again, all these comments are really confusing. D
kuan
2013/01/29 00:17:08
Done. i apologize my attempt to explain everythin
| |
| 340 int preview_height = contents_container_->preview_height(); | |
| 341 if (preview_height == 0 || active_top_margin < preview_height) | |
| 342 contents_container_->SetActiveTopMargin(active_top_margin); | |
| 343 } | |
| 344 | |
| 283 // This must be done _after_ we lay out the WebContents since this | 345 // This must be done _after_ we lay out the WebContents since this |
| 284 // code calls back into us to find the bounding box the find bar | 346 // code calls back into us to find the bounding box the find bar |
| 285 // must be laid out within, and that code depends on the | 347 // must be laid out within, and that code depends on the |
| 286 // TabContentsContainer's bounds being up to date. | 348 // TabContentsContainer's bounds being up to date. |
| 287 if (browser()->HasFindBarController()) { | 349 if (browser()->HasFindBarController()) { |
| 288 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( | 350 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( |
| 289 gfx::Rect(), true); | 351 gfx::Rect(), true); |
| 290 } | 352 } |
| 291 } | 353 } |
| 292 | 354 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 313 tabstrip->SetVisible(false); | 375 tabstrip->SetVisible(false); |
| 314 tabstrip->SetBounds(0, 0, 0, 0); | 376 tabstrip->SetBounds(0, 0, 0, 0); |
| 315 return 0; | 377 return 0; |
| 316 } | 378 } |
| 317 // This retrieves the bounds for the tab strip based on whether or not we show | 379 // This retrieves the bounds for the tab strip based on whether or not we show |
| 318 // anything to the left of it, like the incognito avatar. | 380 // anything to the left of it, like the incognito avatar. |
| 319 gfx::Rect tabstrip_bounds( | 381 gfx::Rect tabstrip_bounds( |
| 320 browser_view_->frame()->GetBoundsForTabStrip(tabstrip)); | 382 browser_view_->frame()->GetBoundsForTabStrip(tabstrip)); |
| 321 gfx::Point tabstrip_origin(tabstrip_bounds.origin()); | 383 gfx::Point tabstrip_origin(tabstrip_bounds.origin()); |
| 322 views::View::ConvertPointToTarget(browser_view_->parent(), browser_view_, | 384 views::View::ConvertPointToTarget(browser_view_->parent(), browser_view_, |
| 323 &tabstrip_origin); | 385 &tabstrip_origin); |
| 324 tabstrip_bounds.set_origin(tabstrip_origin); | 386 tabstrip_bounds.set_origin(tabstrip_origin); |
| 325 | 387 |
| 326 tabstrip->SetVisible(true); | 388 tabstrip->SetVisible(true); |
| 327 tabstrip->SetBoundsRect(tabstrip_bounds); | 389 tabstrip->SetBoundsRect(tabstrip_bounds); |
| 328 int bottom = tabstrip_bounds.bottom(); | 390 int bottom = tabstrip_bounds.bottom(); |
| 329 | 391 |
| 330 // The metro window switcher sits at the far right edge of the tabstrip | 392 // The metro window switcher sits at the far right edge of the tabstrip |
| 331 // a |kWindowSwitcherOffsetX| pixels from the right edge. | 393 // a |kWindowSwitcherOffsetX| pixels from the right edge. |
| 332 // Only visible if there is more than one type of window to switch between. | 394 // Only visible if there is more than one type of window to switch between. |
| 333 // TODO(mad): update this code when more window types than just incognito | 395 // TODO(mad): update this code when more window types than just incognito |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 } | 558 } |
| 497 return bottom; | 559 return bottom; |
| 498 } | 560 } |
| 499 | 561 |
| 500 bool BrowserViewLayout::InfobarVisible() const { | 562 bool BrowserViewLayout::InfobarVisible() const { |
| 501 views::View* infobar_container = browser_view_->infobar_container_; | 563 views::View* infobar_container = browser_view_->infobar_container_; |
| 502 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. | 564 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. |
| 503 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && | 565 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && |
| 504 (infobar_container->GetPreferredSize().height() != 0); | 566 (infobar_container->GetPreferredSize().height() != 0); |
| 505 } | 567 } |
| OLD | NEW |