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