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

Unified Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

Issue 273223002: views: Make view::Views::GetPreferredSize() const. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
index fce7df82977b04d38eac162680755e06daad9a46..87cbe071def01afa96f6101ed893f9bff6fe2a12 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -395,7 +395,7 @@ class BookmarkBarView::ButtonSeparatorView : public views::View {
GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR));
}
- virtual gfx::Size GetPreferredSize() OVERRIDE {
+ virtual gfx::Size GetPreferredSize() const OVERRIDE {
// We get the full height of the bookmark bar, so that the height returned
// here doesn't matter.
return gfx::Size(kSeparatorWidth, 1);
@@ -664,8 +664,45 @@ int BookmarkBarView::GetToolbarOverlap() const {
size_animation_->GetCurrentValue());
}
-gfx::Size BookmarkBarView::GetPreferredSize() {
- return LayoutItems(true);
+gfx::Size BookmarkBarView::GetPreferredSize() const {
sky 2014/05/13 16:13:57 The width of the bookmark bar is forced to that of
Elliot Glaysher 2014/05/14 00:48:58 Done.
+ int x = kLeftMargin;
+ if (IsDetached()) {
+ double current_state = 1 - size_animation_->GetCurrentValue();
+ x += static_cast<int>(kNewtabHorizontalPadding * current_state);
+ }
+
+ if (apps_page_shortcut_->visible())
+ x += apps_page_shortcut_->GetPreferredSize().width() + kButtonPadding;
+
+ for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
+ const views::View* child = child_at(i);
+ gfx::Size pref = child->GetPreferredSize();
+ x += pref.width() + kButtonPadding;
+ }
+
+ // Layout the right side buttons.
+ x += kButtonPadding;
+ x += overflow_button_->GetPreferredSize().width();
+ if (bookmarks_separator_view_->visible())
+ x += bookmarks_separator_view_->GetPreferredSize().width();
+ if (other_bookmarked_button_->visible())
+ x += other_bookmarked_button_->GetPreferredSize().width() + kButtonPadding;
+
+ x += kRightMargin;
+
+ gfx::Size prefsize;
+ prefsize.set_width(x);
+ if (IsDetached()) {
+ prefsize.set_height(
+ chrome::kBookmarkBarHeight +
+ static_cast<int>(
+ (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) *
+ (1 - size_animation_->GetCurrentValue())));
+ } else {
+ prefsize.set_height(static_cast<int>(chrome::kBookmarkBarHeight *
+ size_animation_->GetCurrentValue()));
+ }
+ return prefsize;
}
bool BookmarkBarView::HitTestRect(const gfx::Rect& rect) const {
@@ -681,7 +718,7 @@ bool BookmarkBarView::HitTestRect(const gfx::Rect& rect) const {
return DetachableToolbarView::HitTestRect(rect);
}
-gfx::Size BookmarkBarView::GetMinimumSize() {
+gfx::Size BookmarkBarView::GetMinimumSize() const {
// The minimum width of the bookmark bar should at least contain the overflow
// button, by which one can access all the Bookmark Bar items, and the "Other
// Bookmarks" folder, along with appropriate margins and button padding.
@@ -718,7 +755,7 @@ gfx::Size BookmarkBarView::GetMinimumSize() {
}
void BookmarkBarView::Layout() {
- LayoutItems(false);
+ LayoutItems();
}
void BookmarkBarView::ViewHierarchyChanged(
@@ -1299,7 +1336,7 @@ void BookmarkBarView::Init() {
}
}
-int BookmarkBarView::GetBookmarkButtonCount() {
+int BookmarkBarView::GetBookmarkButtonCount() const {
// We contain four non-bookmark button views: other bookmarks, bookmarks
// separator, chevrons (for overflow), apps page, and the instruction label.
return child_count() - 5;
@@ -1714,10 +1751,9 @@ void BookmarkBarView::UpdateBookmarksSeparatorVisibility() {
other_bookmarked_button_->visible());
}
-gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) {
- gfx::Size prefsize;
- if (!parent() && !compute_bounds_only)
- return prefsize;
+void BookmarkBarView::LayoutItems() {
+ if (!parent())
+ return;
int x = kLeftMargin;
int top_margin = IsDetached() ? kDetachedTopMargin : 0;
@@ -1757,36 +1793,29 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) {
// Start with the apps page shortcut button.
if (apps_page_shortcut_->visible()) {
- if (!compute_bounds_only) {
- apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(),
- height);
- }
+ apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(),
+ height);
x += apps_page_shortcut_pref.width() + kButtonPadding;
}
// Then go through the bookmark buttons.
if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) {
gfx::Size pref = instructions_->GetPreferredSize();
- if (!compute_bounds_only) {
- instructions_->SetBounds(
- x + kInstructionsPadding, y,
- std::min(static_cast<int>(pref.width()),
- max_x - x),
- height);
- instructions_->SetVisible(true);
- }
+ instructions_->SetBounds(
+ x + kInstructionsPadding, y,
+ std::min(static_cast<int>(pref.width()),
+ max_x - x),
+ height);
+ instructions_->SetVisible(true);
} else {
- if (!compute_bounds_only)
- instructions_->SetVisible(false);
+ instructions_->SetVisible(false);
for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
views::View* child = child_at(i);
gfx::Size pref = child->GetPreferredSize();
int next_x = x + pref.width() + kButtonPadding;
- if (!compute_bounds_only) {
- child->SetVisible(next_x < max_x);
- child->SetBounds(x, y, pref.width(), height);
- }
+ child->SetVisible(next_x < max_x);
+ child->SetBounds(x, y, pref.width(), height);
x = next_x;
}
}
@@ -1796,58 +1825,30 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) {
child_at(GetBookmarkButtonCount() - 1)->visible());
// Layout the right side buttons.
- if (!compute_bounds_only)
- x = max_x + kButtonPadding;
- else
- x += kButtonPadding;
+ x = max_x + kButtonPadding;
// The overflow button.
- if (!compute_bounds_only) {
- overflow_button_->SetBounds(x, y, overflow_pref.width(), height);
- overflow_button_->SetVisible(!all_visible);
- }
+ overflow_button_->SetBounds(x, y, overflow_pref.width(), height);
+ overflow_button_->SetVisible(!all_visible);
x += overflow_pref.width();
// Separator.
if (bookmarks_separator_view_->visible()) {
- if (!compute_bounds_only) {
- bookmarks_separator_view_->SetBounds(x,
- y - top_margin,
- bookmarks_separator_pref.width(),
- height + top_margin + kBottomMargin -
- separator_margin);
- }
+ bookmarks_separator_view_->SetBounds(x,
+ y - top_margin,
+ bookmarks_separator_pref.width(),
+ height + top_margin + kBottomMargin -
+ separator_margin);
x += bookmarks_separator_pref.width();
}
// The other bookmarks button.
if (other_bookmarked_button_->visible()) {
- if (!compute_bounds_only) {
- other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
- height);
- }
+ other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
+ height);
x += other_bookmarked_pref.width() + kButtonPadding;
}
-
- // Set the preferred size computed so far.
- if (compute_bounds_only) {
- x += kRightMargin;
- prefsize.set_width(x);
- if (IsDetached()) {
- x += static_cast<int>(kNewtabHorizontalPadding *
- (1 - size_animation_->GetCurrentValue()));
- prefsize.set_height(
- chrome::kBookmarkBarHeight +
- static_cast<int>(
- (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) *
- (1 - size_animation_->GetCurrentValue())));
- } else {
- prefsize.set_height(static_cast<int>(chrome::kBookmarkBarHeight *
- size_animation_->GetCurrentValue()));
- }
- }
- return prefsize;
}
void BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged() {

Powered by Google App Engine
This is Rietveld 408576698