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

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: changed mechanism to receive PreviewStateChanged 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 int preview_height = contents_container_->preview_height();
272 gfx::Point old_contents_origin;
273 if (preview_height > 0 && mode.is_search_suggestions() &&
274 mode.is_origin_default()) {
275 old_contents_origin = contents->bounds().origin();
276 views::View::ConvertPointToTarget(contents->parent(), browser_view_,
277 &old_contents_origin);
278 }
279
260 vertical_layout_rect_ = browser_view_->GetLocalBounds(); 280 vertical_layout_rect_ = browser_view_->GetLocalBounds();
261 int top = LayoutTabStripRegion(); 281 int top = LayoutTabStripRegion();
262 if (browser_view_->IsTabStripVisible()) { 282 if (browser_view_->IsTabStripVisible()) {
263 int x = browser_view_->tabstrip_->GetMirroredX() + 283 int x = browser_view_->tabstrip_->GetMirroredX() +
264 browser_view_->GetMirroredX() + 284 browser_view_->GetMirroredX() +
265 browser_view_->frame()->GetThemeBackgroundXInset(); 285 browser_view_->frame()->GetThemeBackgroundXInset();
266 browser_view_->tabstrip_->SetBackgroundOffset(gfx::Point(x, 286 browser_view_->tabstrip_->SetBackgroundOffset(gfx::Point(x,
267 browser_view_->frame()->GetTabStripInsets(false).top)); 287 browser_view_->frame()->GetTabStripInsets(false).top));
268 } 288 }
269 top = LayoutToolbar(top); 289 top = LayoutToolbar(top);
270 top = LayoutBookmarkAndInfoBars(top); 290 top = LayoutBookmarkAndInfoBars(top);
271 // During immersive mode reveal the content stays near the top of the view. 291 // During immersive mode reveal the content stays near the top of the view.
272 if (browser_view_->immersive_mode_controller()->IsRevealed()) { 292 if (browser_view_->immersive_mode_controller()->IsRevealed()) {
273 top = browser_view_->tabstrip_->y(); 293 top = browser_view_->tabstrip_->y();
274 if (!browser_view_->immersive_mode_controller()->hide_tab_indicators()) 294 if (!browser_view_->immersive_mode_controller()->hide_tab_indicators())
275 top += TabStrip::GetImmersiveHeight(); 295 top += TabStrip::GetImmersiveHeight();
276 } 296 }
277 297
278 int bottom = LayoutDownloadShelf(browser_view_->height()); 298 int bottom = LayoutDownloadShelf(browser_view_->height());
279 int active_top_margin = GetTopMarginForActiveContent(); 299 int active_top_margin = GetTopMarginForActiveContent();
280 top -= active_top_margin; 300 top -= active_top_margin;
281 contents_container_->SetActiveTopMargin(active_top_margin); 301 contents_container_->SetActiveTopMargin(active_top_margin);
282 LayoutTabContents(top, bottom); 302 LayoutTabContents(top, bottom);
303
304 // Now set the contents to display at their previous origin if we just hid the
305 // bookmark and/or infobars.
306 if (active_top_margin == 0 && !old_contents_origin.IsOrigin()) {
307 gfx::Point new_contents_origin(contents->bounds().origin());
308 views::View::ConvertPointToTarget(contents->parent(), browser_view_,
309 &new_contents_origin);
310 active_top_margin = old_contents_origin.y() - new_contents_origin.y();
311 // Special case: While normally the suggestions appear to "cover" any
312 // bookmark/infobars, if the suggestions are very short, they might not
313 // fully cover that gap, and leaving the contents at their original height
314 // would leave an odd-looking blank space. In this case, we allow the
315 // contents to go ahead and shift upward.
316 if (active_top_margin > 0 && active_top_margin < preview_height)
317 contents_container_->SetActiveTopMargin(active_top_margin);
318 }
319
283 // This must be done _after_ we lay out the WebContents since this 320 // 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 321 // 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 322 // must be laid out within, and that code depends on the
286 // TabContentsContainer's bounds being up to date. 323 // TabContentsContainer's bounds being up to date.
287 if (browser()->HasFindBarController()) { 324 if (browser()->HasFindBarController()) {
288 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary( 325 browser()->GetFindBarController()->find_bar()->MoveWindowIfNecessary(
289 gfx::Rect(), true); 326 gfx::Rect(), true);
290 } 327 }
291 } 328 }
292 329
(...skipping 20 matching lines...) Expand all
313 tabstrip->SetVisible(false); 350 tabstrip->SetVisible(false);
314 tabstrip->SetBounds(0, 0, 0, 0); 351 tabstrip->SetBounds(0, 0, 0, 0);
315 return 0; 352 return 0;
316 } 353 }
317 // This retrieves the bounds for the tab strip based on whether or not we show 354 // 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. 355 // anything to the left of it, like the incognito avatar.
319 gfx::Rect tabstrip_bounds( 356 gfx::Rect tabstrip_bounds(
320 browser_view_->frame()->GetBoundsForTabStrip(tabstrip)); 357 browser_view_->frame()->GetBoundsForTabStrip(tabstrip));
321 gfx::Point tabstrip_origin(tabstrip_bounds.origin()); 358 gfx::Point tabstrip_origin(tabstrip_bounds.origin());
322 views::View::ConvertPointToTarget(browser_view_->parent(), browser_view_, 359 views::View::ConvertPointToTarget(browser_view_->parent(), browser_view_,
323 &tabstrip_origin); 360 &tabstrip_origin);
324 tabstrip_bounds.set_origin(tabstrip_origin); 361 tabstrip_bounds.set_origin(tabstrip_origin);
325 362
326 tabstrip->SetVisible(true); 363 tabstrip->SetVisible(true);
327 tabstrip->SetBoundsRect(tabstrip_bounds); 364 tabstrip->SetBoundsRect(tabstrip_bounds);
328 int bottom = tabstrip_bounds.bottom(); 365 int bottom = tabstrip_bounds.bottom();
329 366
330 // The metro window switcher sits at the far right edge of the tabstrip 367 // The metro window switcher sits at the far right edge of the tabstrip
331 // a |kWindowSwitcherOffsetX| pixels from the right edge. 368 // a |kWindowSwitcherOffsetX| pixels from the right edge.
332 // Only visible if there is more than one type of window to switch between. 369 // 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 370 // 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 } 533 }
497 return bottom; 534 return bottom;
498 } 535 }
499 536
500 bool BrowserViewLayout::InfobarVisible() const { 537 bool BrowserViewLayout::InfobarVisible() const {
501 views::View* infobar_container = browser_view_->infobar_container_; 538 views::View* infobar_container = browser_view_->infobar_container_;
502 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. 539 // NOTE: Can't check if the size IsEmpty() since it's always 0-width.
503 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && 540 return browser()->SupportsWindowFeature(Browser::FEATURE_INFOBAR) &&
504 (infobar_container->GetPreferredSize().height() != 0); 541 (infobar_container->GetPreferredSize().height() != 0);
505 } 542 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.h ('k') | chrome/browser/ui/views/frame/contents_container.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698