Chromium Code Reviews| 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; |
|
kylix_rd
2016/08/05 18:32:09
This value is inconsistent with the other buttons'
| |
| 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 // If this is the instructions view, enlarge it's height by the same | |
|
Peter Kasting
2016/08/05 21:23:00
Nit: its
kylix_rd
2016/08/08 15:33:21
Done.
| |
| 853 // padding as the other buttons. This is necessary if the instructions | |
| 854 // view is the only visible view. | |
|
Peter Kasting
2016/08/05 21:23:00
This comment confuses me a bit. Are we basically
| |
| 855 if (view == instructions_) | |
| 856 pref.Enlarge(0, kButtonPaddingVertical * 2); | |
|
Peter Kasting
2016/08/05 21:23:00
What if we just set this as an empty border on the
kylix_rd
2016/08/08 15:33:21
The instructions view doesn't respect the set bord
Peter Kasting
2016/08/08 19:10:01
It seems offhand like part of the problem there is
| |
| 857 height = std::max(pref.height(), height); | |
| 858 } | |
| 859 } | |
| 860 return std::max(height, chrome::kBookmarkBarHeight); | |
| 861 } | |
| 862 | |
| 846 gfx::Size BookmarkBarView::GetPreferredSize() const { | 863 gfx::Size BookmarkBarView::GetPreferredSize() const { |
| 847 gfx::Size prefsize; | 864 gfx::Size prefsize; |
| 848 if (IsDetached()) { | 865 if (IsDetached()) { |
| 866 int padded_height = GetPreferredHeight(); | |
| 849 prefsize.set_height( | 867 prefsize.set_height( |
| 850 chrome::kBookmarkBarHeight + | 868 padded_height + |
| 851 static_cast<int>( | 869 static_cast<int>((chrome::kNTPBookmarkBarHeight - padded_height) * |
| 852 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * | 870 (1 - size_animation_.GetCurrentValue()))); |
| 853 (1 - size_animation_.GetCurrentValue()))); | |
| 854 } else { | 871 } else { |
| 855 prefsize.set_height(static_cast<int>(chrome::kBookmarkBarHeight * | 872 prefsize.set_height(static_cast<int>((GetPreferredHeight()) * |
|
Peter Kasting
2016/08/05 21:23:00
Nit: No need for extra parens
kylix_rd
2016/08/08 15:33:21
Done.
| |
| 856 size_animation_.GetCurrentValue())); | 873 size_animation_.GetCurrentValue())); |
| 857 } | 874 } |
| 858 return prefsize; | 875 return prefsize; |
| 859 } | 876 } |
| 860 | 877 |
| 861 bool BookmarkBarView::CanProcessEventsWithinSubtree() const { | 878 bool BookmarkBarView::CanProcessEventsWithinSubtree() const { |
| 862 // If the bookmark bar is attached and the omnibox popup is open (on top of | 879 // 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 | 880 // 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 | 881 // descendants. This will prevent hovers/clicks just above the omnibox popup |
| 865 // from activating the top few pixels of items on the bookmark bar. | 882 // from activating the top few pixels of items on the bookmark bar. |
| 866 if (!IsDetached() && browser_view_ && | 883 if (!IsDetached() && browser_view_ && |
| 867 browser_view_->GetLocationBar()->GetOmniboxView()->model()-> | 884 browser_view_->GetLocationBar()->GetOmniboxView()->model()-> |
| 868 popup_model()->IsOpen()) { | 885 popup_model()->IsOpen()) { |
| 869 return false; | 886 return false; |
| 870 } | 887 } |
| 871 return true; | 888 return true; |
| 872 } | 889 } |
| 873 | 890 |
| 874 gfx::Size BookmarkBarView::GetMinimumSize() const { | 891 gfx::Size BookmarkBarView::GetMinimumSize() const { |
| 875 // The minimum width of the bookmark bar should at least contain the overflow | 892 // 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 | 893 // button, by which one can access all the Bookmark Bar items, and the "Other |
| 877 // Bookmarks" folder, along with appropriate margins and button padding. | 894 // Bookmarks" folder, along with appropriate margins and button padding. |
| 878 // It should also contain the Managed and/or Supervised Bookmarks folders, | 895 // It should also contain the Managed and/or Supervised Bookmarks folders, |
| 879 // if they are visible. | 896 // if they are visible. |
| 880 int width = GetHorizontalMargin(); | 897 int width = GetHorizontalMargin(); |
| 881 | 898 |
| 882 int height = chrome::kBookmarkBarHeight; | 899 int height = GetPreferredHeight(); |
| 883 if (IsDetached()) { | 900 if (IsDetached()) { |
| 884 double current_state = 1 - size_animation_.GetCurrentValue(); | 901 double current_state = 1 - size_animation_.GetCurrentValue(); |
| 885 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); | 902 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); |
| 886 height += static_cast<int>( | 903 height += static_cast<int>( |
| 887 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * | 904 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * |
| 888 current_state); | 905 current_state); |
| 889 } | 906 } |
| 890 | 907 |
| 891 if (managed_bookmarks_button_->visible()) { | 908 if (managed_bookmarks_button_->visible()) { |
| 892 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); | 909 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 918 | 935 |
| 919 void BookmarkBarView::Layout() { | 936 void BookmarkBarView::Layout() { |
| 920 // Skip layout during destruction, when no model exists. | 937 // Skip layout during destruction, when no model exists. |
| 921 if (!model_) | 938 if (!model_) |
| 922 return; | 939 return; |
| 923 | 940 |
| 924 int x = GetHorizontalMargin(); | 941 int x = GetHorizontalMargin(); |
| 925 int top_margin = IsDetached() ? kDetachedTopMargin : 0; | 942 int top_margin = IsDetached() ? kDetachedTopMargin : 0; |
| 926 int y = top_margin; | 943 int y = top_margin; |
| 927 int width = View::width() - 2 * GetHorizontalMargin(); | 944 int width = View::width() - 2 * GetHorizontalMargin(); |
| 928 int height = chrome::kBookmarkBarHeight - kBottomMargin; | 945 int height = GetPreferredHeight() - kBottomMargin; |
| 929 int separator_margin = kSeparatorMargin; | 946 int separator_margin = kSeparatorMargin; |
| 930 | 947 |
| 931 if (IsDetached()) { | 948 if (IsDetached()) { |
| 932 double current_state = 1 - size_animation_.GetCurrentValue(); | 949 double current_state = 1 - size_animation_.GetCurrentValue(); |
| 933 x += static_cast<int>(kNewTabHorizontalPadding * current_state); | 950 x += static_cast<int>(kNewTabHorizontalPadding * current_state); |
| 934 y += (View::height() - chrome::kBookmarkBarHeight) / 2; | 951 y += (View::height() - chrome::kBookmarkBarHeight) / 2; |
| 935 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); | 952 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); |
| 936 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); | 953 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); |
| 937 } else { | 954 } else { |
| 938 // For the attached appearance, pin the content to the bottom of the bar | 955 // 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 | 956 // when animating in/out, as shrinking its height instead looks weird. This |
| 940 // also matches how we layout infobars. | 957 // also matches how we layout infobars. |
| 941 y += View::height() - chrome::kBookmarkBarHeight; | 958 y += View::height() - GetPreferredHeight(); |
| 942 } | 959 } |
| 943 | 960 |
| 944 gfx::Size other_bookmarks_pref = other_bookmarks_button_->visible() ? | 961 gfx::Size other_bookmarks_pref = other_bookmarks_button_->visible() ? |
| 945 other_bookmarks_button_->GetPreferredSize() : gfx::Size(); | 962 other_bookmarks_button_->GetPreferredSize() : gfx::Size(); |
| 946 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); | 963 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
| 947 gfx::Size bookmarks_separator_pref = | 964 gfx::Size bookmarks_separator_pref = |
| 948 bookmarks_separator_view_->GetPreferredSize(); | 965 bookmarks_separator_view_->GetPreferredSize(); |
| 949 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? | 966 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? |
| 950 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); | 967 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); |
| 951 | 968 |
| (...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2174 return; | 2191 return; |
| 2175 apps_page_shortcut_->SetVisible(visible); | 2192 apps_page_shortcut_->SetVisible(visible); |
| 2176 UpdateBookmarksSeparatorVisibility(); | 2193 UpdateBookmarksSeparatorVisibility(); |
| 2177 LayoutAndPaint(); | 2194 LayoutAndPaint(); |
| 2178 } | 2195 } |
| 2179 | 2196 |
| 2180 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2197 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
| 2181 if (UpdateOtherAndManagedButtonsVisibility()) | 2198 if (UpdateOtherAndManagedButtonsVisibility()) |
| 2182 LayoutAndPaint(); | 2199 LayoutAndPaint(); |
| 2183 } | 2200 } |
| OLD | NEW |