Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/ui/views/frame/browser_view_layout.cc

Issue 12036075: alternate ntp: fix website page jankiness when suggestions show and top bars are hidden (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed all comments Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // Showing instant extended suggestions causes us to temporarily hide any
263 // visible bookmark bar and infobars. In turn, this hiding would normally
264 // cause the content below the suggestions to shift upwards, which looks
265 // surprising (since from the user's perspective, we're "covering" rather than
266 // "removing" the bookmark bar/infobars). To prevent this, we save off the
267 // content origin here, then once we finish laying things out, force the
268 // contents to continue to display from that origin.
269 const chrome::search::Mode& mode = browser()->search_model()->mode();
270 views::WebView* contents = browser_view_->contents_container_;
271 gfx::Point old_contents_origin;
272 if (mode.is_search_suggestions() && mode.is_origin_default() &&
273 // Bookmark bar is visible now but will be hidden during layout.
274 ((active_bookmark_bar_ && active_bookmark_bar_->visible() &&
275 browser()->bookmark_bar_state() == BookmarkBar::HIDDEN) ||
276 // Infobar container is visible now but will be hidden during layout.
277 (browser_view_->infobar_container_->visible() && !InfobarVisible()))) {
278 old_contents_origin = contents->bounds().origin();
279 views::View::ConvertPointToTarget(contents->parent(), browser_view_,
280 &old_contents_origin);
281 }
282
260 vertical_layout_rect_ = browser_view_->GetLocalBounds(); 283 vertical_layout_rect_ = browser_view_->GetLocalBounds();
261 int top = LayoutTabStripRegion(); 284 int top = LayoutTabStripRegion();
262 if (browser_view_->IsTabStripVisible()) { 285 if (browser_view_->IsTabStripVisible()) {
263 int x = browser_view_->tabstrip_->GetMirroredX() + 286 int x = browser_view_->tabstrip_->GetMirroredX() +
264 browser_view_->GetMirroredX() + 287 browser_view_->GetMirroredX() +
265 browser_view_->frame()->GetThemeBackgroundXInset(); 288 browser_view_->frame()->GetThemeBackgroundXInset();
266 browser_view_->tabstrip_->SetBackgroundOffset(gfx::Point(x, 289 browser_view_->tabstrip_->SetBackgroundOffset(gfx::Point(x,
267 browser_view_->frame()->GetTabStripInsets(false).top)); 290 browser_view_->frame()->GetTabStripInsets(false).top));
268 } 291 }
269 top = LayoutToolbar(top); 292 top = LayoutToolbar(top);
270 top = LayoutBookmarkAndInfoBars(top); 293 top = LayoutBookmarkAndInfoBars(top);
271 // During immersive mode reveal the content stays near the top of the view. 294 // During immersive mode reveal the content stays near the top of the view.
272 if (browser_view_->immersive_mode_controller()->IsRevealed()) { 295 if (browser_view_->immersive_mode_controller()->IsRevealed()) {
273 top = browser_view_->tabstrip_->y(); 296 top = browser_view_->tabstrip_->y();
274 if (!browser_view_->immersive_mode_controller()->hide_tab_indicators()) 297 if (!browser_view_->immersive_mode_controller()->hide_tab_indicators())
275 top += TabStrip::GetImmersiveHeight(); 298 top += TabStrip::GetImmersiveHeight();
276 } 299 }
277 300
278 int bottom = LayoutDownloadShelf(browser_view_->height()); 301 int bottom = LayoutDownloadShelf(browser_view_->height());
279 int active_top_margin = GetTopMarginForActiveContent(); 302 int active_top_margin = GetTopMarginForActiveContent();
280 top -= active_top_margin; 303 top -= active_top_margin;
281 contents_container_->SetActiveTopMargin(active_top_margin); 304 contents_container_->SetActiveTopMargin(active_top_margin);
282 LayoutTabContents(top, bottom); 305 LayoutTabContents(top, bottom);
306
307 // If previous origin of contents page relative to |BrowserView| needs to be
308 // preserved, set the vertical difference between new and previous origins as
309 // the active top margin in contents container, so that the contents don't
310 // shift up due to hiding of bookmark and info bars.
Peter Kasting 2013/01/29 00:36:29 Nit: How about just: // Now set the contents to d
kuan 2013/01/29 01:00:11 Done.
311 if (active_top_margin == 0 && !old_contents_origin.IsOrigin()) {
312 gfx::Point new_contents_origin(contents->bounds().origin());
313 views::View::ConvertPointToTarget(contents->parent(), browser_view_,
314 &new_contents_origin);
315 active_top_margin = old_contents_origin.y() - new_contents_origin.y();
316 DCHECK_GE(active_top_margin, 0);
317 int preview_height = contents_container_->preview_height();
318 // Only preserve the previous content origin if:
319 // - suggesions are not ready yet i.e. |preview_height| is 0
320 // - suggestions completely cover the bookmark bar/infobars that are hidden.
Peter Kasting 2013/01/29 00:36:29 Nit: This confused me for a while. See if this ex
kuan 2013/01/29 01:00:11 Done. The zero-preview-height case was what i tri
321 if (preview_height == 0 || active_top_margin < preview_height)
322 contents_container_->SetActiveTopMargin(active_top_margin);
323 }
324
283 // This must be done _after_ we lay out the WebContents since this 325 // 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 326 // 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 327 // must be laid out within, and that code depends on the
286 // TabContentsContainer's bounds being up to date. 328 // TabContentsContainer's bounds being up to date.
287 if (browser()->HasFindBarController()) { 329 if (browser()->HasFindBarController()) {
288 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( 330 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary(
289 gfx::Rect(), true); 331 gfx::Rect(), true);
290 } 332 }
291 } 333 }
292 334
(...skipping 20 matching lines...) Expand all
313 tabstrip->SetVisible(false); 355 tabstrip->SetVisible(false);
314 tabstrip->SetBounds(0, 0, 0, 0); 356 tabstrip->SetBounds(0, 0, 0, 0);
315 return 0; 357 return 0;
316 } 358 }
317 // This retrieves the bounds for the tab strip based on whether or not we show 359 // 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. 360 // anything to the left of it, like the incognito avatar.
319 gfx::Rect tabstrip_bounds( 361 gfx::Rect tabstrip_bounds(
320 browser_view_->frame()->GetBoundsForTabStrip(tabstrip)); 362 browser_view_->frame()->GetBoundsForTabStrip(tabstrip));
321 gfx::Point tabstrip_origin(tabstrip_bounds.origin()); 363 gfx::Point tabstrip_origin(tabstrip_bounds.origin());
322 views::View::ConvertPointToTarget(browser_view_->parent(), browser_view_, 364 views::View::ConvertPointToTarget(browser_view_->parent(), browser_view_,
323 &tabstrip_origin); 365 &tabstrip_origin);
324 tabstrip_bounds.set_origin(tabstrip_origin); 366 tabstrip_bounds.set_origin(tabstrip_origin);
325 367
326 tabstrip->SetVisible(true); 368 tabstrip->SetVisible(true);
327 tabstrip->SetBoundsRect(tabstrip_bounds); 369 tabstrip->SetBoundsRect(tabstrip_bounds);
328 int bottom = tabstrip_bounds.bottom(); 370 int bottom = tabstrip_bounds.bottom();
329 371
330 // The metro window switcher sits at the far right edge of the tabstrip 372 // The metro window switcher sits at the far right edge of the tabstrip
331 // a |kWindowSwitcherOffsetX| pixels from the right edge. 373 // a |kWindowSwitcherOffsetX| pixels from the right edge.
332 // Only visible if there is more than one type of window to switch between. 374 // 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 375 // TODO(mad): update this code when more window types than just incognito
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 538 }
497 return bottom; 539 return bottom;
498 } 540 }
499 541
500 bool BrowserViewLayout::InfobarVisible() const { 542 bool BrowserViewLayout::InfobarVisible() const {
501 views::View* infobar_container = browser_view_->infobar_container_; 543 views::View* infobar_container = browser_view_->infobar_container_;
502 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. 544 // NOTE: Can't check if the size IsEmpty() since it's always 0-width.
503 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && 545 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) &&
504 (infobar_container->GetPreferredSize().height() != 0); 546 (infobar_container->GetPreferredSize().height() != 0);
505 } 547 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.cc ('k') | chrome/browser/ui/views/frame/contents_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698