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

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

Issue 14230025: Make the relationship between the find bar position and the top container height more obvious (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 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"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // BrowserViewLayout, public: 106 // BrowserViewLayout, public:
107 107
108 BrowserViewLayout::BrowserViewLayout() 108 BrowserViewLayout::BrowserViewLayout()
109 : browser_(NULL), 109 : browser_(NULL),
110 browser_view_(NULL), 110 browser_view_(NULL),
111 bookmark_bar_(NULL), 111 bookmark_bar_(NULL),
112 infobar_container_(NULL), 112 infobar_container_(NULL),
113 contents_split_(NULL), 113 contents_split_(NULL),
114 contents_container_(NULL), 114 contents_container_(NULL),
115 download_shelf_(NULL), 115 download_shelf_(NULL),
116 find_bar_y_(0),
117 ALLOW_THIS_IN_INITIALIZER_LIST( 116 ALLOW_THIS_IN_INITIALIZER_LIST(
118 dialog_host_(new WebContentsModalDialogHostViews(this))), 117 dialog_host_(new WebContentsModalDialogHostViews(this))),
119 web_contents_modal_dialog_top_y_(-1) { 118 web_contents_modal_dialog_top_y_(-1) {
120 } 119 }
121 120
122 BrowserViewLayout::~BrowserViewLayout() { 121 BrowserViewLayout::~BrowserViewLayout() {
123 } 122 }
124 123
125 void BrowserViewLayout::Init(Browser* browser, 124 void BrowserViewLayout::Init(Browser* browser,
126 BrowserView* browser_view, 125 BrowserView* browser_view,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 int widths[] = { 166 int widths[] = {
168 tabstrip_size.width() + tab_strip_insets.left + tab_strip_insets.right, 167 tabstrip_size.width() + tab_strip_insets.left + tab_strip_insets.right,
169 toolbar_size.width(), 168 toolbar_size.width(),
170 bookmark_bar_size.width(), 169 bookmark_bar_size.width(),
171 contents_size.width() }; 170 contents_size.width() };
172 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]); 171 int min_width = *std::max_element(&widths[0], &widths[arraysize(widths)]);
173 return gfx::Size(min_width, min_height); 172 return gfx::Size(min_width, min_height);
174 } 173 }
175 174
176 gfx::Rect BrowserViewLayout::GetFindBarBoundingBox() const { 175 gfx::Rect BrowserViewLayout::GetFindBarBoundingBox() const {
177 // This function returns the area the Find Bar can be laid out 176 // This function returns the area the Find Bar can be laid out within. This
178 // within. This basically implies the "user-perceived content 177 // basically implies the "user-perceived content area" of the browser
179 // area" of the browser window excluding the vertical 178 // window excluding the vertical scrollbar. The "user-perceived content area"
180 // scrollbar. This is not quite so straightforward as positioning 179 // excludes the detached bookmark bar (in the New Tab case) and any infobars
181 // based on the TabContentsContainer since the BookmarkBarView may 180 // since they are not _visually_ connected to the Toolbar.
182 // be visible but not persistent (in the New Tab case) and we
183 // position the Find Bar over the top of it in that case since the
184 // BookmarkBarView is not _visually_ connected to the Toolbar.
185 181
186 // First determine the bounding box of the content area in Widget 182 // First determine the bounding box of the content area in Widget
187 // coordinates. 183 // coordinates.
188 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget( 184 gfx::Rect bounding_box = contents_container_->ConvertRectToWidget(
189 contents_container_->GetLocalBounds()); 185 contents_container_->GetLocalBounds());
190 186
191 // Adjust the position and size of the bounding box by the find bar offset 187 // The find bar is postioned right below the top container.
192 // calculated during the last Layout. 188 int find_bar_y = browser_view_->y() +
James Cook 2013/04/26 16:14:51 I think this would be clearer if you either did th
pkotwicz 2013/04/27 00:02:43 - Converted explicitly to widget coordinates. - Ad
193 int height_delta = find_bar_y_ - bounding_box.y(); 189 browser_view_->top_container()->bounds().bottom() - 1;
194 bounding_box.set_y(find_bar_y_); 190
191 // Grow the height of |bounding_box| by the height of any elements between
192 // the top container and |contents_container_| such as the detached bookmark
193 // bar and any infobars.
194 int height_delta = find_bar_y - bounding_box.y();
195 bounding_box.set_y(find_bar_y);
195 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta)); 196 bounding_box.set_height(std::max(0, bounding_box.height() + height_delta));
196 197
197 // Finally decrease the width of the bounding box by the width of 198 // Finally decrease the width of the bounding box by the width of
198 // the vertical scroll bar. 199 // the vertical scroll bar.
199 int scrollbar_width = gfx::scrollbar_size(); 200 int scrollbar_width = gfx::scrollbar_size();
200 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width)); 201 bounding_box.set_width(std::max(0, bounding_box.width() - scrollbar_width));
201 if (base::i18n::IsRTL()) 202 if (base::i18n::IsRTL())
202 bounding_box.set_x(bounding_box.x() + scrollbar_width); 203 bounding_box.set_x(bounding_box.x() + scrollbar_width);
203 204
204 return bounding_box; 205 return bounding_box;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 int height = toolbar_visible ? toolbar->GetPreferredSize().height() : 0; 406 int height = toolbar_visible ? toolbar->GetPreferredSize().height() : 0;
406 toolbar->SetVisible(toolbar_visible); 407 toolbar->SetVisible(toolbar_visible);
407 toolbar->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height); 408 toolbar->SetBounds(vertical_layout_rect_.x(), y, browser_view_width, height);
408 409
409 return y + height; 410 return y + height;
410 } 411 }
411 412
412 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) { 413 int BrowserViewLayout::LayoutBookmarkAndInfoBars(int top) {
413 web_contents_modal_dialog_top_y_ = 414 web_contents_modal_dialog_top_y_ =
414 top + browser_view_->y() - kConstrainedWindowOverlap; 415 top + browser_view_->y() - kConstrainedWindowOverlap;
415 find_bar_y_ = top + browser_view_->y() - 1;
416 if (bookmark_bar_) { 416 if (bookmark_bar_) {
417 // If we're showing the Bookmark bar in detached style, then we 417 // If we're showing the Bookmark bar in detached style, then we
418 // need to show any Info bar _above_ the Bookmark bar, since the 418 // need to show any Info bar _above_ the Bookmark bar, since the
419 // Bookmark bar is styled to look like it's part of the page. 419 // Bookmark bar is styled to look like it's part of the page.
420 if (bookmark_bar_->IsDetached()) 420 if (bookmark_bar_->IsDetached())
421 return LayoutBookmarkBar(LayoutInfoBar(top)); 421 return LayoutBookmarkBar(LayoutInfoBar(top));
422 // Otherwise, Bookmark bar first, Info bar second. 422 // Otherwise, Bookmark bar first, Info bar second.
423 top = std::max(browser_view_->toolbar_->bounds().bottom(), 423 top = std::max(browser_view_->toolbar_->bounds().bottom(),
424 LayoutBookmarkBar(top)); 424 LayoutBookmarkBar(top));
425 } 425 }
426 find_bar_y_ = top + browser_view_->y() - 1;
427 return LayoutInfoBar(top); 426 return LayoutInfoBar(top);
428 } 427 }
429 428
430 int BrowserViewLayout::LayoutBookmarkBar(int top) { 429 int BrowserViewLayout::LayoutBookmarkBar(int top) {
431 int y = top; 430 int y = top;
432 if (!browser_view_->IsBookmarkBarVisible()) { 431 if (!browser_view_->IsBookmarkBarVisible()) {
433 bookmark_bar_->SetVisible(false); 432 bookmark_bar_->SetVisible(false);
434 // TODO(jamescook): Don't change the bookmark bar height when it is 433 // TODO(jamescook): Don't change the bookmark bar height when it is
435 // invisible, so we can use its height for layout even in that state. 434 // invisible, so we can use its height for layout even in that state.
436 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0); 435 bookmark_bar_->SetBounds(0, y, browser_view_->width(), 0);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 return bottom; 568 return bottom;
570 } 569 }
571 570
572 bool BrowserViewLayout::InfobarVisible() const { 571 bool BrowserViewLayout::InfobarVisible() const {
573 // Cast to a views::View to access GetPreferredSize(). 572 // Cast to a views::View to access GetPreferredSize().
574 views::View* infobar_container = infobar_container_; 573 views::View* infobar_container = infobar_container_;
575 // NOTE: Can't check if the size IsEmpty() since it's always 0-width. 574 // NOTE: Can't check if the size IsEmpty() since it's always 0-width.
576 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) && 575 return browser_->SupportsWindowFeature(Browser::FEATURE_INFOBAR) &&
577 (infobar_container->GetPreferredSize().height() != 0); 576 (infobar_container->GetPreferredSize().height() != 0);
578 } 577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698