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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // The color gradient value for the middle of the divider. | 124 // The color gradient value for the middle of the divider. |
125 static const SkColor kMiddleDividerColor = SkColorSetRGB(194, 205, 212); | 125 static const SkColor kMiddleDividerColor = SkColorSetRGB(194, 205, 212); |
126 | 126 |
127 // Number of pixels the attached bookmark bar overlaps with the toolbar. | 127 // Number of pixels the attached bookmark bar overlaps with the toolbar. |
128 static const int kToolbarAttachedBookmarkBarOverlap = 3; | 128 static const int kToolbarAttachedBookmarkBarOverlap = 3; |
129 | 129 |
130 // Margins around the content. | 130 // Margins around the content. |
131 static const int kDetachedTopMargin = 1; // When attached, we use 0 and let the | 131 static const int kDetachedTopMargin = 1; // When attached, we use 0 and let the |
132 // toolbar above serve as the margin. | 132 // toolbar above serve as the margin. |
133 static const int kBottomMargin = 2; | 133 static const int kBottomMargin = 2; |
134 static const int kLeftMargin = 1; | 134 // The margin at the start and end of the bar, in dp, indexed by MD mode. |
135 static const int kRightMargin = 1; | 135 static const int kHorizontalMargin[] = {1, 4, 4}; |
136 | 136 |
137 // Padding between buttons. | 137 // Padding between buttons. |
138 static const int kButtonPadding = 0; | 138 static const int kButtonPadding = 0; |
139 | 139 |
140 // Color of the drop indicator. | 140 // Color of the drop indicator. |
141 static const SkColor kDropIndicatorColor = SK_ColorBLACK; | 141 static const SkColor kDropIndicatorColor = SK_ColorBLACK; |
142 | 142 |
143 // Width of the drop indicator. | 143 // Width of the drop indicator. |
144 static const int kDropIndicatorWidth = 2; | 144 static const int kDropIndicatorWidth = 2; |
145 | 145 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 namespace { | 181 namespace { |
182 | 182 |
183 // To enable/disable BookmarkBar animations during testing. In production | 183 // To enable/disable BookmarkBar animations during testing. In production |
184 // animations are enabled by default. | 184 // animations are enabled by default. |
185 bool animations_enabled = true; | 185 bool animations_enabled = true; |
186 | 186 |
187 gfx::ImageSkia* GetImageSkiaNamed(int id) { | 187 gfx::ImageSkia* GetImageSkiaNamed(int id) { |
188 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); | 188 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); |
189 } | 189 } |
190 | 190 |
| 191 int GetHorizontalMargin() { |
| 192 return kHorizontalMargin[ui::MaterialDesignController::GetMode()]; |
| 193 } |
| 194 |
191 // BookmarkButtonBase ----------------------------------------------- | 195 // BookmarkButtonBase ----------------------------------------------- |
192 | 196 |
193 // Base class for buttons used on the bookmark bar. | 197 // Base class for buttons used on the bookmark bar. |
194 | 198 |
195 class BookmarkButtonBase : public views::LabelButton { | 199 class BookmarkButtonBase : public views::LabelButton { |
196 public: | 200 public: |
197 BookmarkButtonBase(views::ButtonListener* listener, | 201 BookmarkButtonBase(views::ButtonListener* listener, |
198 const base::string16& title) | 202 const base::string16& title) |
199 : LabelButton(listener, title) { | 203 : LabelButton(listener, title) { |
200 SetElideBehavior(kElideBehavior); | 204 SetElideBehavior(kElideBehavior); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 243 |
240 class BookmarkButton : public BookmarkButtonBase { | 244 class BookmarkButton : public BookmarkButtonBase { |
241 public: | 245 public: |
242 // The internal view class name. | 246 // The internal view class name. |
243 static const char kViewClassName[]; | 247 static const char kViewClassName[]; |
244 | 248 |
245 BookmarkButton(views::ButtonListener* listener, | 249 BookmarkButton(views::ButtonListener* listener, |
246 const GURL& url, | 250 const GURL& url, |
247 const base::string16& title, | 251 const base::string16& title, |
248 Profile* profile) | 252 Profile* profile) |
249 : BookmarkButtonBase(listener, title), | 253 : BookmarkButtonBase(listener, title), url_(url), profile_(profile) {} |
250 url_(url), | |
251 profile_(profile) { | |
252 } | |
253 | 254 |
254 bool GetTooltipText(const gfx::Point& p, | 255 bool GetTooltipText(const gfx::Point& p, |
255 base::string16* tooltip) const override { | 256 base::string16* tooltip) const override { |
256 gfx::Point location(p); | 257 gfx::Point location(p); |
257 ConvertPointToScreen(this, &location); | 258 ConvertPointToScreen(this, &location); |
258 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( | 259 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( |
259 GetWidget(), location, url_, GetText(), profile_); | 260 GetWidget(), location, url_, GetText(), profile_); |
260 return !tooltip->empty(); | 261 return !tooltip->empty(); |
261 } | 262 } |
262 | 263 |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 } | 802 } |
802 return true; | 803 return true; |
803 } | 804 } |
804 | 805 |
805 gfx::Size BookmarkBarView::GetMinimumSize() const { | 806 gfx::Size BookmarkBarView::GetMinimumSize() const { |
806 // The minimum width of the bookmark bar should at least contain the overflow | 807 // The minimum width of the bookmark bar should at least contain the overflow |
807 // button, by which one can access all the Bookmark Bar items, and the "Other | 808 // button, by which one can access all the Bookmark Bar items, and the "Other |
808 // Bookmarks" folder, along with appropriate margins and button padding. | 809 // Bookmarks" folder, along with appropriate margins and button padding. |
809 // It should also contain the Managed and/or Supervised Bookmarks folders, | 810 // It should also contain the Managed and/or Supervised Bookmarks folders, |
810 // if they are visible. | 811 // if they are visible. |
811 int width = kLeftMargin; | 812 int width = GetHorizontalMargin(); |
812 | 813 |
813 int height = chrome::kBookmarkBarHeight; | 814 int height = chrome::kBookmarkBarHeight; |
814 if (IsDetached()) { | 815 if (IsDetached()) { |
815 double current_state = 1 - size_animation_->GetCurrentValue(); | 816 double current_state = 1 - size_animation_->GetCurrentValue(); |
816 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); | 817 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); |
817 height += static_cast<int>( | 818 height += static_cast<int>( |
818 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * | 819 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * |
819 current_state); | 820 current_state); |
820 } | 821 } |
821 | 822 |
(...skipping 23 matching lines...) Expand all Loading... |
845 } | 846 } |
846 | 847 |
847 return gfx::Size(width, height); | 848 return gfx::Size(width, height); |
848 } | 849 } |
849 | 850 |
850 void BookmarkBarView::Layout() { | 851 void BookmarkBarView::Layout() { |
851 // Skip layout during destruction, when no model exists. | 852 // Skip layout during destruction, when no model exists. |
852 if (!model_) | 853 if (!model_) |
853 return; | 854 return; |
854 | 855 |
855 int x = kLeftMargin; | 856 int x = GetHorizontalMargin(); |
856 int top_margin = IsDetached() ? kDetachedTopMargin : 0; | 857 int top_margin = IsDetached() ? kDetachedTopMargin : 0; |
857 int y = top_margin; | 858 int y = top_margin; |
858 int width = View::width() - kRightMargin - kLeftMargin; | 859 int width = View::width() - 2 * GetHorizontalMargin(); |
859 int height = chrome::kBookmarkBarHeight - kBottomMargin; | 860 int height = chrome::kBookmarkBarHeight - kBottomMargin; |
860 int separator_margin = kSeparatorMargin; | 861 int separator_margin = kSeparatorMargin; |
861 | 862 |
862 if (IsDetached()) { | 863 if (IsDetached()) { |
863 double current_state = 1 - size_animation_->GetCurrentValue(); | 864 double current_state = 1 - size_animation_->GetCurrentValue(); |
864 x += static_cast<int>(kNewTabHorizontalPadding * current_state); | 865 x += static_cast<int>(kNewTabHorizontalPadding * current_state); |
865 y += (View::height() - chrome::kBookmarkBarHeight) / 2; | 866 y += (View::height() - chrome::kBookmarkBarHeight) / 2; |
866 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); | 867 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); |
867 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); | 868 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); |
868 } else { | 869 } else { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 drop_info_->location.operation != 0 && drop_info_->location.index != -1 && | 1004 drop_info_->location.operation != 0 && drop_info_->location.index != -1 && |
1004 drop_info_->location.button_type != DROP_OVERFLOW && | 1005 drop_info_->location.button_type != DROP_OVERFLOW && |
1005 !drop_info_->location.on) { | 1006 !drop_info_->location.on) { |
1006 int index = drop_info_->location.index; | 1007 int index = drop_info_->location.index; |
1007 DCHECK(index <= GetBookmarkButtonCount()); | 1008 DCHECK(index <= GetBookmarkButtonCount()); |
1008 int x = 0; | 1009 int x = 0; |
1009 int y = 0; | 1010 int y = 0; |
1010 int h = height(); | 1011 int h = height(); |
1011 if (index == GetBookmarkButtonCount()) { | 1012 if (index == GetBookmarkButtonCount()) { |
1012 if (index == 0) { | 1013 if (index == 0) { |
1013 x = kLeftMargin; | 1014 x = GetHorizontalMargin(); |
1014 } else { | 1015 } else { |
1015 x = GetBookmarkButton(index - 1)->x() + | 1016 x = GetBookmarkButton(index - 1)->x() + |
1016 GetBookmarkButton(index - 1)->width(); | 1017 GetBookmarkButton(index - 1)->width(); |
1017 } | 1018 } |
1018 } else { | 1019 } else { |
1019 x = GetBookmarkButton(index)->x(); | 1020 x = GetBookmarkButton(index)->x(); |
1020 } | 1021 } |
1021 if (GetBookmarkButtonCount() > 0 && GetBookmarkButton(0)->visible()) { | 1022 if (GetBookmarkButtonCount() > 0 && GetBookmarkButton(0)->visible()) { |
1022 y = GetBookmarkButton(0)->y(); | 1023 y = GetBookmarkButton(0)->y(); |
1023 h = GetBookmarkButton(0)->height(); | 1024 h = GetBookmarkButton(0)->height(); |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 return; | 2090 return; |
2090 apps_page_shortcut_->SetVisible(visible); | 2091 apps_page_shortcut_->SetVisible(visible); |
2091 UpdateBookmarksSeparatorVisibility(); | 2092 UpdateBookmarksSeparatorVisibility(); |
2092 LayoutAndPaint(); | 2093 LayoutAndPaint(); |
2093 } | 2094 } |
2094 | 2095 |
2095 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2096 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
2096 if (UpdateOtherAndManagedButtonsVisibility()) | 2097 if (UpdateOtherAndManagedButtonsVisibility()) |
2097 LayoutAndPaint(); | 2098 LayoutAndPaint(); |
2098 } | 2099 } |
OLD | NEW |