OLD | NEW |
---|---|
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 Loading... | |
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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 if (infobar_visible_) | 836 if (infobar_visible_) |
837 return detached_overlap; | 837 return detached_overlap; |
838 | 838 |
839 // When detached with no infobar, animate the overlap between the attached and | 839 // When detached with no infobar, animate the overlap between the attached and |
840 // detached states. | 840 // detached states. |
841 return detached_overlap + static_cast<int>( | 841 return detached_overlap + static_cast<int>( |
842 (attached_overlap - detached_overlap) * | 842 (attached_overlap - detached_overlap) * |
843 size_animation_.GetCurrentValue()); | 843 size_animation_.GetCurrentValue()); |
844 } | 844 } |
845 | 845 |
846 int BookmarkBarView::GetPreferredHeight() const { | |
847 int height = 0; | |
848 for (int i = 0; i < child_count(); ++i) { | |
849 const views::View* view = child_at(i); | |
850 if (view->visible()) { | |
851 gfx::Size pref = view->GetPreferredSize(); | |
852 height = std::max(pref.height(), height); | |
853 } | |
854 } | |
855 return std::max(height, chrome::kMinimumBookmarkBarHeight); | |
856 } | |
857 | |
846 gfx::Size BookmarkBarView::GetPreferredSize() const { | 858 gfx::Size BookmarkBarView::GetPreferredSize() const { |
847 gfx::Size prefsize; | 859 gfx::Size prefsize; |
860 int preferred_height = GetPreferredHeight(); | |
848 if (IsDetached()) { | 861 if (IsDetached()) { |
849 prefsize.set_height( | 862 prefsize.set_height( |
850 chrome::kBookmarkBarHeight + | 863 preferred_height + |
851 static_cast<int>( | 864 static_cast<int>( |
852 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * | 865 (chrome::kNTPMinimumBookmarkBarHeight - preferred_height) * |
sky
2016/08/16 21:56:13
Might this line and line 899 go negative now. I gu
kylix_rd
2016/08/17 15:39:02
Unless the font pushes preferred_height > kNTPMini
| |
853 (1 - size_animation_.GetCurrentValue()))); | 866 (1 - size_animation_.GetCurrentValue()))); |
854 } else { | 867 } else { |
855 prefsize.set_height(static_cast<int>(chrome::kBookmarkBarHeight * | 868 prefsize.set_height(static_cast<int>(preferred_height * |
856 size_animation_.GetCurrentValue())); | 869 size_animation_.GetCurrentValue())); |
857 } | 870 } |
858 return prefsize; | 871 return prefsize; |
859 } | 872 } |
860 | 873 |
861 bool BookmarkBarView::CanProcessEventsWithinSubtree() const { | 874 bool BookmarkBarView::CanProcessEventsWithinSubtree() const { |
862 // If the bookmark bar is attached and the omnibox popup is open (on top of | 875 // If the bookmark bar is attached and the omnibox popup is open (on top of |
863 // the bar), prevent events from targeting the bookmark bar or any of its | 876 // the bar), prevent events from targeting the bookmark bar or any of its |
864 // descendants. This will prevent hovers/clicks just above the omnibox popup | 877 // descendants. This will prevent hovers/clicks just above the omnibox popup |
865 // from activating the top few pixels of items on the bookmark bar. | 878 // from activating the top few pixels of items on the bookmark bar. |
866 if (!IsDetached() && browser_view_ && | 879 if (!IsDetached() && browser_view_ && |
867 browser_view_->GetLocationBar()->GetOmniboxView()->model()-> | 880 browser_view_->GetLocationBar()->GetOmniboxView()->model()-> |
868 popup_model()->IsOpen()) { | 881 popup_model()->IsOpen()) { |
869 return false; | 882 return false; |
870 } | 883 } |
871 return true; | 884 return true; |
872 } | 885 } |
873 | 886 |
874 gfx::Size BookmarkBarView::GetMinimumSize() const { | 887 gfx::Size BookmarkBarView::GetMinimumSize() const { |
875 // The minimum width of the bookmark bar should at least contain the overflow | 888 // The minimum width of the bookmark bar should at least contain the overflow |
876 // button, by which one can access all the Bookmark Bar items, and the "Other | 889 // button, by which one can access all the Bookmark Bar items, and the "Other |
877 // Bookmarks" folder, along with appropriate margins and button padding. | 890 // Bookmarks" folder, along with appropriate margins and button padding. |
878 // It should also contain the Managed and/or Supervised Bookmarks folders, | 891 // It should also contain the Managed and/or Supervised Bookmarks folders, |
879 // if they are visible. | 892 // if they are visible. |
880 int width = GetHorizontalMargin(); | 893 int width = GetHorizontalMargin(); |
881 | 894 |
882 int height = chrome::kBookmarkBarHeight; | 895 int height = GetPreferredHeight(); |
883 if (IsDetached()) { | 896 if (IsDetached()) { |
884 double current_state = 1 - size_animation_.GetCurrentValue(); | 897 double current_state = 1 - size_animation_.GetCurrentValue(); |
885 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); | 898 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); |
886 height += static_cast<int>( | 899 height += static_cast<int>((chrome::kNTPMinimumBookmarkBarHeight - height) * |
887 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * | 900 current_state); |
888 current_state); | |
889 } | 901 } |
890 | 902 |
891 if (managed_bookmarks_button_->visible()) { | 903 if (managed_bookmarks_button_->visible()) { |
892 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); | 904 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); |
893 width += size.width() + kButtonPadding; | 905 width += size.width() + kButtonPadding; |
894 } | 906 } |
895 if (supervised_bookmarks_button_->visible()) { | 907 if (supervised_bookmarks_button_->visible()) { |
896 gfx::Size size = supervised_bookmarks_button_->GetPreferredSize(); | 908 gfx::Size size = supervised_bookmarks_button_->GetPreferredSize(); |
897 width += size.width() + kButtonPadding; | 909 width += size.width() + kButtonPadding; |
898 } | 910 } |
(...skipping 19 matching lines...) Expand all Loading... | |
918 | 930 |
919 void BookmarkBarView::Layout() { | 931 void BookmarkBarView::Layout() { |
920 // Skip layout during destruction, when no model exists. | 932 // Skip layout during destruction, when no model exists. |
921 if (!model_) | 933 if (!model_) |
922 return; | 934 return; |
923 | 935 |
924 int x = GetHorizontalMargin(); | 936 int x = GetHorizontalMargin(); |
925 int top_margin = IsDetached() ? kDetachedTopMargin : 0; | 937 int top_margin = IsDetached() ? kDetachedTopMargin : 0; |
926 int y = top_margin; | 938 int y = top_margin; |
927 int width = View::width() - 2 * GetHorizontalMargin(); | 939 int width = View::width() - 2 * GetHorizontalMargin(); |
928 int height = chrome::kBookmarkBarHeight - kBottomMargin; | 940 int preferred_height = GetPreferredHeight(); |
941 int height = preferred_height - kBottomMargin; | |
929 int separator_margin = kSeparatorMargin; | 942 int separator_margin = kSeparatorMargin; |
930 | 943 |
931 if (IsDetached()) { | 944 if (IsDetached()) { |
932 double current_state = 1 - size_animation_.GetCurrentValue(); | 945 double current_state = 1 - size_animation_.GetCurrentValue(); |
933 x += static_cast<int>(kNewTabHorizontalPadding * current_state); | 946 x += static_cast<int>(kNewTabHorizontalPadding * current_state); |
934 y += (View::height() - chrome::kBookmarkBarHeight) / 2; | 947 y += (View::height() - preferred_height) / 2; |
935 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); | 948 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); |
936 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); | 949 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); |
937 } else { | 950 } else { |
938 // For the attached appearance, pin the content to the bottom of the bar | 951 // For the attached appearance, pin the content to the bottom of the bar |
939 // when animating in/out, as shrinking its height instead looks weird. This | 952 // when animating in/out, as shrinking its height instead looks weird. This |
940 // also matches how we layout infobars. | 953 // also matches how we layout infobars. |
941 y += View::height() - chrome::kBookmarkBarHeight; | 954 y += View::height() - preferred_height; |
942 } | 955 } |
943 | 956 |
944 gfx::Size other_bookmarks_pref = other_bookmarks_button_->visible() ? | 957 gfx::Size other_bookmarks_pref = other_bookmarks_button_->visible() ? |
945 other_bookmarks_button_->GetPreferredSize() : gfx::Size(); | 958 other_bookmarks_button_->GetPreferredSize() : gfx::Size(); |
946 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); | 959 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
947 gfx::Size bookmarks_separator_pref = | 960 gfx::Size bookmarks_separator_pref = |
948 bookmarks_separator_view_->GetPreferredSize(); | 961 bookmarks_separator_view_->GetPreferredSize(); |
949 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? | 962 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? |
950 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); | 963 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); |
951 | 964 |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1650 base::Bind(&BookmarkBarView::OnShowManagedBookmarksPrefChanged, | 1663 base::Bind(&BookmarkBarView::OnShowManagedBookmarksPrefChanged, |
1651 base::Unretained(this))); | 1664 base::Unretained(this))); |
1652 apps_page_shortcut_->SetVisible( | 1665 apps_page_shortcut_->SetVisible( |
1653 chrome::ShouldShowAppsShortcutInBookmarkBar(browser_->profile())); | 1666 chrome::ShouldShowAppsShortcutInBookmarkBar(browser_->profile())); |
1654 | 1667 |
1655 bookmarks_separator_view_ = new ButtonSeparatorView(); | 1668 bookmarks_separator_view_ = new ButtonSeparatorView(); |
1656 AddChildView(bookmarks_separator_view_); | 1669 AddChildView(bookmarks_separator_view_); |
1657 UpdateBookmarksSeparatorVisibility(); | 1670 UpdateBookmarksSeparatorVisibility(); |
1658 | 1671 |
1659 instructions_ = new BookmarkBarInstructionsView(this); | 1672 instructions_ = new BookmarkBarInstructionsView(this); |
1673 instructions_->SetBorder(views::Border::CreateEmptyBorder( | |
1674 kButtonPaddingVertical, 0, kButtonPaddingVertical, 0)); | |
1660 AddChildView(instructions_); | 1675 AddChildView(instructions_); |
1661 | 1676 |
1662 set_context_menu_controller(this); | 1677 set_context_menu_controller(this); |
1663 | 1678 |
1664 model_ = BookmarkModelFactory::GetForBrowserContext(browser_->profile()); | 1679 model_ = BookmarkModelFactory::GetForBrowserContext(browser_->profile()); |
1665 managed_ = ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); | 1680 managed_ = ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); |
1666 if (model_) { | 1681 if (model_) { |
1667 model_->AddObserver(this); | 1682 model_->AddObserver(this); |
1668 if (model_->loaded()) | 1683 if (model_->loaded()) |
1669 BookmarkModelLoaded(model_, false); | 1684 BookmarkModelLoaded(model_, false); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2174 return; | 2189 return; |
2175 apps_page_shortcut_->SetVisible(visible); | 2190 apps_page_shortcut_->SetVisible(visible); |
2176 UpdateBookmarksSeparatorVisibility(); | 2191 UpdateBookmarksSeparatorVisibility(); |
2177 LayoutAndPaint(); | 2192 LayoutAndPaint(); |
2178 } | 2193 } |
2179 | 2194 |
2180 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2195 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
2181 if (UpdateOtherAndManagedButtonsVisibility()) | 2196 if (UpdateOtherAndManagedButtonsVisibility()) |
2182 LayoutAndPaint(); | 2197 LayoutAndPaint(); |
2183 } | 2198 } |
OLD | NEW |