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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

Issue 2208973003: Add some extra height to bookmark bar if the font wants to be larger (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address various nits from code review comments Created 4 years, 3 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
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/bookmarks/bookmark_bar_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 static const int kSeparatorStartX = 2; 165 static const int kSeparatorStartX = 2;
166 166
167 // Left-padding for the instructional text. 167 // Left-padding for the instructional text.
168 static const int kInstructionsPadding = 6; 168 static const int kInstructionsPadding = 6;
169 169
170 // Tag for the 'Apps Shortcut' button. 170 // Tag for the 'Apps Shortcut' button.
171 static const int kAppsShortcutButtonTag = 2; 171 static const int kAppsShortcutButtonTag = 2;
172 172
173 // Preferred padding between text and edge. 173 // Preferred padding between text and edge.
174 static const int kButtonPaddingHorizontal = 6; 174 static const int kButtonPaddingHorizontal = 6;
175 static const int kButtonPaddingVertical = 4; 175 static const int kButtonPaddingVertical = 5;
176 176
177 static const gfx::ElideBehavior kElideBehavior = gfx::FADE_TAIL; 177 static const gfx::ElideBehavior kElideBehavior = gfx::FADE_TAIL;
178 178
179 namespace { 179 namespace {
180 180
181 // To enable/disable BookmarkBar animations during testing. In production 181 // To enable/disable BookmarkBar animations during testing. In production
182 // animations are enabled by default. 182 // animations are enabled by default.
183 bool animations_enabled = true; 183 bool animations_enabled = true;
184 184
185 gfx::ImageSkia* GetImageSkiaNamed(int id) { 185 gfx::ImageSkia* GetImageSkiaNamed(int id) {
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 if (infobar_visible_) 837 if (infobar_visible_)
838 return detached_overlap; 838 return detached_overlap;
839 839
840 // When detached with no infobar, animate the overlap between the attached and 840 // When detached with no infobar, animate the overlap between the attached and
841 // detached states. 841 // detached states.
842 return detached_overlap + static_cast<int>( 842 return detached_overlap + static_cast<int>(
843 (attached_overlap - detached_overlap) * 843 (attached_overlap - detached_overlap) *
844 size_animation_.GetCurrentValue()); 844 size_animation_.GetCurrentValue());
845 } 845 }
846 846
847 int BookmarkBarView::GetPreferredHeight() const {
848 int height = chrome::kMinimumBookmarkBarHeight;
849 for (int i = 0; i < child_count(); ++i) {
850 const views::View* view = child_at(i);
851 if (view->visible())
852 height = std::max(view->GetPreferredSize().height(), height);
853 }
854 return height;
855 }
856
847 gfx::Size BookmarkBarView::GetPreferredSize() const { 857 gfx::Size BookmarkBarView::GetPreferredSize() const {
848 gfx::Size prefsize; 858 gfx::Size prefsize;
859 int preferred_height = GetPreferredHeight();
849 if (IsDetached()) { 860 if (IsDetached()) {
850 prefsize.set_height( 861 prefsize.set_height(
851 chrome::kBookmarkBarHeight + 862 preferred_height +
852 static_cast<int>( 863 static_cast<int>((chrome::kNTPBookmarkBarHeight - preferred_height) *
853 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * 864 (1 - size_animation_.GetCurrentValue())));
854 (1 - size_animation_.GetCurrentValue())));
855 } else { 865 } else {
856 prefsize.set_height(static_cast<int>(chrome::kBookmarkBarHeight * 866 prefsize.set_height(
857 size_animation_.GetCurrentValue())); 867 static_cast<int>(preferred_height * size_animation_.GetCurrentValue()));
858 } 868 }
859 return prefsize; 869 return prefsize;
860 } 870 }
861 871
862 bool BookmarkBarView::CanProcessEventsWithinSubtree() const { 872 bool BookmarkBarView::CanProcessEventsWithinSubtree() const {
863 // If the bookmark bar is attached and the omnibox popup is open (on top of 873 // If the bookmark bar is attached and the omnibox popup is open (on top of
864 // the bar), prevent events from targeting the bookmark bar or any of its 874 // the bar), prevent events from targeting the bookmark bar or any of its
865 // descendants. This will prevent hovers/clicks just above the omnibox popup 875 // descendants. This will prevent hovers/clicks just above the omnibox popup
866 // from activating the top few pixels of items on the bookmark bar. 876 // from activating the top few pixels of items on the bookmark bar.
867 if (!IsDetached() && browser_view_ && 877 if (!IsDetached() && browser_view_ &&
868 browser_view_->GetLocationBar()->GetOmniboxView()->model()-> 878 browser_view_->GetLocationBar()->GetOmniboxView()->model()->
869 popup_model()->IsOpen()) { 879 popup_model()->IsOpen()) {
870 return false; 880 return false;
871 } 881 }
872 return true; 882 return true;
873 } 883 }
874 884
875 gfx::Size BookmarkBarView::GetMinimumSize() const { 885 gfx::Size BookmarkBarView::GetMinimumSize() const {
876 // The minimum width of the bookmark bar should at least contain the overflow 886 // The minimum width of the bookmark bar should at least contain the overflow
877 // button, by which one can access all the Bookmark Bar items, and the "Other 887 // button, by which one can access all the Bookmark Bar items, and the "Other
878 // Bookmarks" folder, along with appropriate margins and button padding. 888 // Bookmarks" folder, along with appropriate margins and button padding.
879 // It should also contain the Managed and/or Supervised Bookmarks folders, 889 // It should also contain the Managed and/or Supervised Bookmarks folders,
880 // if they are visible. 890 // if they are visible.
881 int width = GetHorizontalMargin(); 891 int width = GetHorizontalMargin();
882 892
883 int height = chrome::kBookmarkBarHeight; 893 int height = GetPreferredHeight();
884 if (IsDetached()) { 894 if (IsDetached()) {
885 double current_state = 1 - size_animation_.GetCurrentValue(); 895 double current_state = 1 - size_animation_.GetCurrentValue();
886 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); 896 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state);
887 height += static_cast<int>( 897 height += static_cast<int>((chrome::kNTPBookmarkBarHeight - height) *
888 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * 898 current_state);
889 current_state);
890 } 899 }
891 900
892 if (managed_bookmarks_button_->visible()) { 901 if (managed_bookmarks_button_->visible()) {
893 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); 902 gfx::Size size = managed_bookmarks_button_->GetPreferredSize();
894 width += size.width() + kButtonPadding; 903 width += size.width() + kButtonPadding;
895 } 904 }
896 if (supervised_bookmarks_button_->visible()) { 905 if (supervised_bookmarks_button_->visible()) {
897 gfx::Size size = supervised_bookmarks_button_->GetPreferredSize(); 906 gfx::Size size = supervised_bookmarks_button_->GetPreferredSize();
898 width += size.width() + kButtonPadding; 907 width += size.width() + kButtonPadding;
899 } 908 }
(...skipping 19 matching lines...) Expand all
919 928
920 void BookmarkBarView::Layout() { 929 void BookmarkBarView::Layout() {
921 // Skip layout during destruction, when no model exists. 930 // Skip layout during destruction, when no model exists.
922 if (!model_) 931 if (!model_)
923 return; 932 return;
924 933
925 int x = GetHorizontalMargin(); 934 int x = GetHorizontalMargin();
926 int top_margin = IsDetached() ? kDetachedTopMargin : 0; 935 int top_margin = IsDetached() ? kDetachedTopMargin : 0;
927 int y = top_margin; 936 int y = top_margin;
928 int width = View::width() - 2 * GetHorizontalMargin(); 937 int width = View::width() - 2 * GetHorizontalMargin();
929 int height = chrome::kBookmarkBarHeight - kBottomMargin; 938 int preferred_height = GetPreferredHeight();
939 int height = preferred_height - kBottomMargin;
930 int separator_margin = kSeparatorMargin; 940 int separator_margin = kSeparatorMargin;
931 941
932 if (IsDetached()) { 942 if (IsDetached()) {
933 double current_state = 1 - size_animation_.GetCurrentValue(); 943 double current_state = 1 - size_animation_.GetCurrentValue();
934 x += static_cast<int>(kNewTabHorizontalPadding * current_state); 944 x += static_cast<int>(kNewTabHorizontalPadding * current_state);
935 y += (View::height() - chrome::kBookmarkBarHeight) / 2; 945 y += (View::height() - preferred_height) / 2;
936 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); 946 width -= static_cast<int>(kNewTabHorizontalPadding * current_state);
937 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); 947 separator_margin -= static_cast<int>(kSeparatorMargin * current_state);
938 } else { 948 } else {
939 // For the attached appearance, pin the content to the bottom of the bar 949 // For the attached appearance, pin the content to the bottom of the bar
940 // when animating in/out, as shrinking its height instead looks weird. This 950 // when animating in/out, as shrinking its height instead looks weird. This
941 // also matches how we layout infobars. 951 // also matches how we layout infobars.
942 y += View::height() - chrome::kBookmarkBarHeight; 952 y += View::height() - preferred_height;
943 } 953 }
944 954
945 gfx::Size other_bookmarks_pref = other_bookmarks_button_->visible() ? 955 gfx::Size other_bookmarks_pref = other_bookmarks_button_->visible() ?
946 other_bookmarks_button_->GetPreferredSize() : gfx::Size(); 956 other_bookmarks_button_->GetPreferredSize() : gfx::Size();
947 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 957 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
948 gfx::Size bookmarks_separator_pref = 958 gfx::Size bookmarks_separator_pref =
949 bookmarks_separator_view_->GetPreferredSize(); 959 bookmarks_separator_view_->GetPreferredSize();
950 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? 960 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ?
951 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); 961 apps_page_shortcut_->GetPreferredSize() : gfx::Size();
952 962
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 base::Bind(&BookmarkBarView::OnShowManagedBookmarksPrefChanged, 1661 base::Bind(&BookmarkBarView::OnShowManagedBookmarksPrefChanged,
1652 base::Unretained(this))); 1662 base::Unretained(this)));
1653 apps_page_shortcut_->SetVisible( 1663 apps_page_shortcut_->SetVisible(
1654 chrome::ShouldShowAppsShortcutInBookmarkBar(browser_->profile())); 1664 chrome::ShouldShowAppsShortcutInBookmarkBar(browser_->profile()));
1655 1665
1656 bookmarks_separator_view_ = new ButtonSeparatorView(); 1666 bookmarks_separator_view_ = new ButtonSeparatorView();
1657 AddChildView(bookmarks_separator_view_); 1667 AddChildView(bookmarks_separator_view_);
1658 UpdateBookmarksSeparatorVisibility(); 1668 UpdateBookmarksSeparatorVisibility();
1659 1669
1660 instructions_ = new BookmarkBarInstructionsView(this); 1670 instructions_ = new BookmarkBarInstructionsView(this);
1671 instructions_->SetBorder(views::Border::CreateEmptyBorder(
1672 kButtonPaddingVertical, 0, kButtonPaddingVertical, 0));
1661 AddChildView(instructions_); 1673 AddChildView(instructions_);
1662 1674
1663 set_context_menu_controller(this); 1675 set_context_menu_controller(this);
1664 1676
1665 model_ = BookmarkModelFactory::GetForBrowserContext(browser_->profile()); 1677 model_ = BookmarkModelFactory::GetForBrowserContext(browser_->profile());
1666 managed_ = ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); 1678 managed_ = ManagedBookmarkServiceFactory::GetForProfile(browser_->profile());
1667 if (model_) { 1679 if (model_) {
1668 model_->AddObserver(this); 1680 model_->AddObserver(this);
1669 if (model_->loaded()) 1681 if (model_->loaded())
1670 BookmarkModelLoaded(model_, false); 1682 BookmarkModelLoaded(model_, false);
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 return; 2187 return;
2176 apps_page_shortcut_->SetVisible(visible); 2188 apps_page_shortcut_->SetVisible(visible);
2177 UpdateBookmarksSeparatorVisibility(); 2189 UpdateBookmarksSeparatorVisibility();
2178 LayoutAndPaint(); 2190 LayoutAndPaint();
2179 } 2191 }
2180 2192
2181 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { 2193 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() {
2182 if (UpdateOtherAndManagedButtonsVisibility()) 2194 if (UpdateOtherAndManagedButtonsVisibility())
2183 LayoutAndPaint(); 2195 LayoutAndPaint();
2184 } 2196 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.h ('k') | chrome/browser/ui/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698