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 <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
26 #include "chrome/browser/sync/profile_sync_service_factory.h" | 26 #include "chrome/browser/sync/profile_sync_service_factory.h" |
27 #include "chrome/browser/themes/theme_properties.h" | 27 #include "chrome/browser/themes/theme_properties.h" |
28 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" | 28 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" |
29 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" | 29 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
30 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 30 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
31 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
32 #include "chrome/browser/ui/chrome_pages.h" | 32 #include "chrome/browser/ui/chrome_pages.h" |
33 #include "chrome/browser/ui/search/search.h" | |
33 #include "chrome/browser/ui/search/search_model.h" | 34 #include "chrome/browser/ui/search/search_model.h" |
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
35 #include "chrome/browser/ui/view_ids.h" | 36 #include "chrome/browser/ui/view_ids.h" |
36 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h" | 37 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h" |
37 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" | 38 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" |
38 #include "chrome/browser/ui/views/event_utils.h" | 39 #include "chrome/browser/ui/views/event_utils.h" |
39 #include "chrome/browser/ui/views/frame/browser_view.h" | 40 #include "chrome/browser/ui/views/frame/browser_view.h" |
40 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 41 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
41 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 42 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
42 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 // is only needed locally. | 141 // is only needed locally. |
141 static const int kSearchNewTabBookmarkBarHeight = 36; | 142 static const int kSearchNewTabBookmarkBarHeight = 36; |
142 | 143 |
143 // TODO(kuan): change BookmarkBarView::kNewtabHorizontalPadding and | 144 // TODO(kuan): change BookmarkBarView::kNewtabHorizontalPadding and |
144 // BookmarkBarView::kNewtabVerticalPadding to these new values when search_ntp | 145 // BookmarkBarView::kNewtabVerticalPadding to these new values when search_ntp |
145 // replaces ntp4; for now, while both versions exist, these new values are only | 146 // replaces ntp4; for now, while both versions exist, these new values are only |
146 // needed locally. | 147 // needed locally. |
147 static const int kSearchNewTabHorizontalPadding = 0; | 148 static const int kSearchNewTabHorizontalPadding = 0; |
148 static const int kSearchNewTabVerticalPadding = 0; | 149 static const int kSearchNewTabVerticalPadding = 0; |
149 | 150 |
151 // Tag for the 'Apps Shortcut' button. | |
152 static const int kAppsShortcutButtonTag = 2; | |
153 | |
150 namespace { | 154 namespace { |
151 | 155 |
156 // BookmarkButtonBase ----------------------------------------------- | |
157 | |
158 // Base class for text buttons used on the bookmark bar. | |
159 | |
160 class BookmarkButtonBase : public views::TextButton { | |
161 public: | |
162 BookmarkButtonBase(views::ButtonListener* listener, | |
163 const string16& title) | |
164 : TextButton(listener, title) { | |
165 show_animation_.reset(new ui::SlideAnimation(this)); | |
166 if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) { | |
167 // For some reason during testing the events generated by anima | |
168 // throw off the test. So, don't animate while testing. | |
169 show_animation_->Reset(1); | |
170 } else { | |
171 show_animation_->Show(); | |
172 } | |
173 } | |
174 | |
175 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { | |
176 return e.type() == ui::ET_GESTURE_TAP || | |
177 e.type() == ui::ET_GESTURE_TAP_DOWN || | |
178 event_utils::IsPossibleDispositionEvent(e); | |
179 } | |
180 | |
181 private: | |
182 scoped_ptr<ui::SlideAnimation> show_animation_; | |
183 | |
184 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); | |
185 }; | |
186 | |
152 // BookmarkButton ------------------------------------------------------------- | 187 // BookmarkButton ------------------------------------------------------------- |
153 | 188 |
154 // Buttons used for the bookmarks on the bookmark bar. | 189 // Buttons used for the bookmarks on the bookmark bar. |
155 | 190 |
156 class BookmarkButton : public views::TextButton { | 191 class BookmarkButton : public BookmarkButtonBase { |
157 public: | 192 public: |
158 // The internal view class name. | 193 // The internal view class name. |
159 static const char kViewClassName[]; | 194 static const char kViewClassName[]; |
160 | 195 |
161 BookmarkButton(views::ButtonListener* listener, | 196 BookmarkButton(views::ButtonListener* listener, |
162 const GURL& url, | 197 const GURL& url, |
163 const string16& title, | 198 const string16& title, |
164 Profile* profile) | 199 Profile* profile) |
165 : TextButton(listener, title), | 200 : BookmarkButtonBase(listener, title), |
166 url_(url), | 201 url_(url), |
167 profile_(profile) { | 202 profile_(profile) { |
168 show_animation_.reset(new ui::SlideAnimation(this)); | |
169 if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) { | |
170 // For some reason during testing the events generated by animating | |
171 // throw off the test. So, don't animate while testing. | |
172 show_animation_->Reset(1); | |
173 } else { | |
174 show_animation_->Show(); | |
175 } | |
176 } | 203 } |
177 | 204 |
178 virtual bool GetTooltipText(const gfx::Point& p, | 205 virtual bool GetTooltipText(const gfx::Point& p, |
179 string16* tooltip) const OVERRIDE { | 206 string16* tooltip) const OVERRIDE { |
180 gfx::Point location(p); | 207 gfx::Point location(p); |
181 ConvertPointToScreen(this, &location); | 208 ConvertPointToScreen(this, &location); |
182 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( | 209 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( |
183 location, url_, text(), profile_, GetWidget()->GetNativeView()); | 210 location, url_, text(), profile_, GetWidget()->GetNativeView()); |
184 return !tooltip->empty(); | 211 return !tooltip->empty(); |
185 } | 212 } |
186 | 213 |
187 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { | |
188 return e.type() == ui::ET_GESTURE_TAP || | |
189 e.type() == ui::ET_GESTURE_TAP_DOWN || | |
190 event_utils::IsPossibleDispositionEvent(e); | |
191 } | |
192 | |
193 virtual std::string GetClassName() const OVERRIDE { | 214 virtual std::string GetClassName() const OVERRIDE { |
194 return kViewClassName; | 215 return kViewClassName; |
195 } | 216 } |
196 | 217 |
197 private: | 218 private: |
198 const GURL& url_; | 219 const GURL& url_; |
199 Profile* profile_; | 220 Profile* profile_; |
200 scoped_ptr<ui::SlideAnimation> show_animation_; | |
201 | 221 |
202 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | 222 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
203 }; | 223 }; |
204 | 224 |
205 // static for BookmarkButton | 225 // static for BookmarkButton |
206 const char BookmarkButton::kViewClassName[] = | 226 const char BookmarkButton::kViewClassName[] = |
207 "browser/ui/views/bookmarks/BookmarkButton"; | 227 "browser/ui/views/bookmarks/BookmarkButton"; |
208 | 228 |
229 // ShortcutButton ------------------------------------------------------------- | |
230 | |
231 // Buttons used for the shortcuts on the bookmark bar. | |
232 | |
233 class ShortcutButton : public BookmarkButtonBase { | |
234 public: | |
235 // The internal view class name. | |
236 static const char kViewClassName[]; | |
237 | |
238 ShortcutButton(views::ButtonListener* listener, | |
239 const string16& title) | |
240 : BookmarkButtonBase(listener, title) { | |
241 } | |
242 | |
243 virtual std::string GetClassName() const OVERRIDE { | |
244 return kViewClassName; | |
245 } | |
246 | |
247 private: | |
248 | |
249 DISALLOW_COPY_AND_ASSIGN(ShortcutButton); | |
250 }; | |
251 | |
252 // static for ShortcutButton | |
253 const char ShortcutButton::kViewClassName[] = | |
254 "browser/ui/views/bookmarks/ShortcutButton"; | |
255 | |
209 // BookmarkFolderButton ------------------------------------------------------- | 256 // BookmarkFolderButton ------------------------------------------------------- |
210 | 257 |
211 // Buttons used for folders on the bookmark bar, including the 'other folders' | 258 // Buttons used for folders on the bookmark bar, including the 'other folders' |
212 // button. | 259 // button. |
213 class BookmarkFolderButton : public views::MenuButton { | 260 class BookmarkFolderButton : public views::MenuButton { |
214 public: | 261 public: |
215 BookmarkFolderButton(views::ButtonListener* listener, | 262 BookmarkFolderButton(views::ButtonListener* listener, |
216 const string16& title, | 263 const string16& title, |
217 views::MenuButtonListener* menu_button_listener, | 264 views::MenuButtonListener* menu_button_listener, |
218 bool show_menu_marker) | 265 bool show_menu_marker) |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 } | 446 } |
400 return *kFolderIcon; | 447 return *kFolderIcon; |
401 } | 448 } |
402 | 449 |
403 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) | 450 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
404 : page_navigator_(NULL), | 451 : page_navigator_(NULL), |
405 model_(NULL), | 452 model_(NULL), |
406 bookmark_menu_(NULL), | 453 bookmark_menu_(NULL), |
407 bookmark_drop_menu_(NULL), | 454 bookmark_drop_menu_(NULL), |
408 other_bookmarked_button_(NULL), | 455 other_bookmarked_button_(NULL), |
456 apps_page_shortcut_(NULL), | |
409 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), | 457 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), |
410 overflow_button_(NULL), | 458 overflow_button_(NULL), |
411 instructions_(NULL), | 459 instructions_(NULL), |
412 bookmarks_separator_view_(NULL), | 460 bookmarks_separator_view_(NULL), |
413 browser_(browser), | 461 browser_(browser), |
414 browser_view_(browser_view), | 462 browser_view_(browser_view), |
415 infobar_visible_(false), | 463 infobar_visible_(false), |
416 throbbing_view_(NULL), | 464 throbbing_view_(NULL), |
417 bookmark_bar_state_(BookmarkBar::SHOW), | 465 bookmark_bar_state_(BookmarkBar::SHOW), |
418 animating_detached_(false) { | 466 animating_detached_(false) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 // button, by which one can access all the Bookmark Bar items, and the "Other | 668 // button, by which one can access all the Bookmark Bar items, and the "Other |
621 // Bookmarks" folder, along with appropriate margins and button padding. | 669 // Bookmarks" folder, along with appropriate margins and button padding. |
622 int width = kLeftMargin; | 670 int width = kLeftMargin; |
623 | 671 |
624 if (bookmark_bar_state_ == BookmarkBar::DETACHED) { | 672 if (bookmark_bar_state_ == BookmarkBar::DETACHED) { |
625 double current_state = 1 - size_animation_->GetCurrentValue(); | 673 double current_state = 1 - size_animation_->GetCurrentValue(); |
626 width += 2 * static_cast<int>(GetNewtabHorizontalPadding( | 674 width += 2 * static_cast<int>(GetNewtabHorizontalPadding( |
627 browser_->search_model()->mode()) * current_state); | 675 browser_->search_model()->mode()) * current_state); |
628 } | 676 } |
629 | 677 |
630 gfx::Size other_bookmarked_pref = | 678 gfx::Size other_bookmarked_pref; |
631 other_bookmarked_button_->GetPreferredSize(); | 679 if (other_bookmarked_button_->visible()) |
632 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); | 680 other_bookmarked_pref = other_bookmarked_button_->GetPreferredSize(); |
633 gfx::Size bookmarks_separator_pref = | 681 gfx::Size overflow_pref; |
634 bookmarks_separator_view_->GetPreferredSize(); | 682 if (overflow_button_->visible()) |
683 overflow_pref = overflow_button_->GetPreferredSize(); | |
684 gfx::Size bookmarks_separator_pref; | |
685 if (bookmarks_separator_view_->visible()) | |
686 bookmarks_separator_pref = bookmarks_separator_view_->GetPreferredSize(); | |
635 | 687 |
688 gfx::Size apps_page_shortcut_pref; | |
689 if (apps_page_shortcut_->visible()) | |
690 apps_page_shortcut_pref = apps_page_shortcut_->GetPreferredSize(); | |
636 width += other_bookmarked_pref.width() + kButtonPadding + | 691 width += other_bookmarked_pref.width() + kButtonPadding + |
692 apps_page_shortcut_pref.width() + kButtonPadding + | |
637 overflow_pref.width() + kButtonPadding + | 693 overflow_pref.width() + kButtonPadding + |
638 bookmarks_separator_pref.width(); | 694 bookmarks_separator_pref.width(); |
639 | 695 |
640 return gfx::Size(width, browser_defaults::kBookmarkBarHeight); | 696 return gfx::Size(width, browser_defaults::kBookmarkBarHeight); |
641 } | 697 } |
642 | 698 |
643 void BookmarkBarView::Layout() { | 699 void BookmarkBarView::Layout() { |
644 LayoutItems(false); | 700 LayoutItems(false); |
645 } | 701 } |
646 | 702 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 | 1123 |
1068 bookmark_utils::RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); | 1124 bookmark_utils::RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); |
1069 bookmark_menu_ = new BookmarkMenuController(browser_, | 1125 bookmark_menu_ = new BookmarkMenuController(browser_, |
1070 page_navigator_, GetWidget(), node, start_index); | 1126 page_navigator_, GetWidget(), node, start_index); |
1071 bookmark_menu_->set_observer(this); | 1127 bookmark_menu_->set_observer(this); |
1072 bookmark_menu_->RunMenuAt(this, false); | 1128 bookmark_menu_->RunMenuAt(this, false); |
1073 } | 1129 } |
1074 | 1130 |
1075 void BookmarkBarView::ButtonPressed(views::Button* sender, | 1131 void BookmarkBarView::ButtonPressed(views::Button* sender, |
1076 const ui::Event& event) { | 1132 const ui::Event& event) { |
1133 if (sender->tag() == kAppsShortcutButtonTag) { | |
1134 chrome::ShowAppLauncherPage(browser_); | |
1135 bookmark_utils::RecordAppsPageOpen(GetBookmarkLaunchLocation()); | |
1136 return; | |
1137 } | |
1138 | |
1077 const BookmarkNode* node; | 1139 const BookmarkNode* node; |
1078 if (sender->tag() == kOtherFolderButtonTag) { | 1140 if (sender->tag() == kOtherFolderButtonTag) { |
1079 node = model_->other_node(); | 1141 node = model_->other_node(); |
1080 } else { | 1142 } else { |
1081 int index = GetIndexOf(sender); | 1143 int index = GetIndexOf(sender); |
1082 DCHECK_NE(-1, index); | 1144 DCHECK_NE(-1, index); |
1083 node = model_->bookmark_bar_node()->GetChild(index); | 1145 node = model_->bookmark_bar_node()->GetChild(index); |
1084 } | 1146 } |
1085 DCHECK(page_navigator_); | 1147 DCHECK(page_navigator_); |
1086 | 1148 |
(...skipping 19 matching lines...) Expand all Loading... | |
1106 if (!model_->IsLoaded()) { | 1168 if (!model_->IsLoaded()) { |
1107 // Don't do anything if the model isn't loaded. | 1169 // Don't do anything if the model isn't loaded. |
1108 return; | 1170 return; |
1109 } | 1171 } |
1110 | 1172 |
1111 const BookmarkNode* parent = NULL; | 1173 const BookmarkNode* parent = NULL; |
1112 std::vector<const BookmarkNode*> nodes; | 1174 std::vector<const BookmarkNode*> nodes; |
1113 if (source == other_bookmarked_button_) { | 1175 if (source == other_bookmarked_button_) { |
1114 parent = model_->other_node(); | 1176 parent = model_->other_node(); |
1115 // Do this so the user can open all bookmarks. BookmarkContextMenu makes | 1177 // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
1116 // sure the user can edit/delete the node in this case. | 1178 // sure the user can't edit/delete the node in this case. |
1117 nodes.push_back(parent); | 1179 nodes.push_back(parent); |
1118 } else if (source != this) { | 1180 } else if (source != this && source != apps_page_shortcut_) { |
1119 // User clicked on one of the bookmark buttons, find which one they | 1181 // User clicked on one of the bookmark buttons, find which one they |
1120 // clicked on. | 1182 // clicked on, except for the apps page shortcut, which must behave as if |
1183 // the user clicked on the bookmark bar background. | |
1121 int bookmark_button_index = GetIndexOf(source); | 1184 int bookmark_button_index = GetIndexOf(source); |
1122 DCHECK(bookmark_button_index != -1 && | 1185 DCHECK(bookmark_button_index != -1 && |
1123 bookmark_button_index < GetBookmarkButtonCount()); | 1186 bookmark_button_index < GetBookmarkButtonCount()); |
1124 const BookmarkNode* node = | 1187 const BookmarkNode* node = |
1125 model_->bookmark_bar_node()->GetChild(bookmark_button_index); | 1188 model_->bookmark_bar_node()->GetChild(bookmark_button_index); |
1126 nodes.push_back(node); | 1189 nodes.push_back(node); |
1127 parent = node->parent(); | 1190 parent = node->parent(); |
1128 } else { | 1191 } else { |
1129 parent = model_->bookmark_bar_node(); | 1192 parent = model_->bookmark_bar_node(); |
1130 nodes.push_back(parent); | 1193 nodes.push_back(parent); |
(...skipping 23 matching lines...) Expand all Loading... | |
1154 // Child views are traversed in the order they are added. Make sure the order | 1217 // Child views are traversed in the order they are added. Make sure the order |
1155 // they are added matches the visual order. | 1218 // they are added matches the visual order. |
1156 overflow_button_ = CreateOverflowButton(); | 1219 overflow_button_ = CreateOverflowButton(); |
1157 AddChildView(overflow_button_); | 1220 AddChildView(overflow_button_); |
1158 | 1221 |
1159 other_bookmarked_button_ = CreateOtherBookmarkedButton(); | 1222 other_bookmarked_button_ = CreateOtherBookmarkedButton(); |
1160 // We'll re-enable when the model is loaded. | 1223 // We'll re-enable when the model is loaded. |
1161 other_bookmarked_button_->SetEnabled(false); | 1224 other_bookmarked_button_->SetEnabled(false); |
1162 AddChildView(other_bookmarked_button_); | 1225 AddChildView(other_bookmarked_button_); |
1163 | 1226 |
1227 apps_page_shortcut_ = CreateAppsPageShortcutButton(); | |
1228 AddChildView(apps_page_shortcut_); | |
1229 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); | |
1230 profile_pref_registrar_.Add( | |
1231 prefs::kShowAppsShortcutInBookmarkBar, | |
1232 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityChanged, | |
1233 base::Unretained(this))); | |
1234 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut()); | |
1235 | |
1164 bookmarks_separator_view_ = new ButtonSeparatorView(); | 1236 bookmarks_separator_view_ = new ButtonSeparatorView(); |
1165 AddChildView(bookmarks_separator_view_); | 1237 AddChildView(bookmarks_separator_view_); |
1166 #if defined(USE_ASH) | 1238 UpdateBookmarksSeparatorVisibility(); |
1167 // Ash does not paint the bookmarks separator line because it looks odd on | |
1168 // the flat background. We keep it present for layout, but don't draw it. | |
1169 bookmarks_separator_view_->SetVisible(false); | |
1170 #endif | |
1171 | 1239 |
1172 instructions_ = new BookmarkBarInstructionsView(this); | 1240 instructions_ = new BookmarkBarInstructionsView(this); |
1173 AddChildView(instructions_); | 1241 AddChildView(instructions_); |
1174 | 1242 |
1175 set_context_menu_controller(this); | 1243 set_context_menu_controller(this); |
1176 | 1244 |
1177 size_animation_.reset(new ui::SlideAnimation(this)); | 1245 size_animation_.reset(new ui::SlideAnimation(this)); |
1178 | 1246 |
1179 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); | 1247 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); |
1180 if (model_) { | 1248 if (model_) { |
1181 model_->AddObserver(this); | 1249 model_->AddObserver(this); |
1182 if (model_->IsLoaded()) | 1250 if (model_->IsLoaded()) |
1183 Loaded(model_, false); | 1251 Loaded(model_, false); |
1184 // else case: we'll receive notification back from the BookmarkModel when | 1252 // else case: we'll receive notification back from the BookmarkModel when |
1185 // done loading, then we'll populate the bar. | 1253 // done loading, then we'll populate the bar. |
1186 } | 1254 } |
1187 } | 1255 } |
1188 | 1256 |
1189 int BookmarkBarView::GetBookmarkButtonCount() { | 1257 int BookmarkBarView::GetBookmarkButtonCount() { |
1190 // We contain four non-bookmark button views: other bookmarks, bookmarks | 1258 // We contain four non-bookmark button views: other bookmarks, bookmarks |
1191 // separator, chevrons (for overflow), and the instruction label. | 1259 // separator, chevrons (for overflow), apps page, and the instruction label. |
1192 return child_count() - 4; | 1260 return child_count() - 5; |
1193 } | 1261 } |
1194 | 1262 |
1195 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { | 1263 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { |
1196 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); | 1264 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); |
1197 return static_cast<views::TextButton*>(child_at(index)); | 1265 return static_cast<views::TextButton*>(child_at(index)); |
1198 } | 1266 } |
1199 | 1267 |
1200 bookmark_utils::BookmarkLaunchLocation | 1268 bookmark_utils::BookmarkLaunchLocation |
1201 BookmarkBarView::GetBookmarkLaunchLocation() const { | 1269 BookmarkBarView::GetBookmarkLaunchLocation() const { |
1202 return IsDetached() ? bookmark_utils::LAUNCH_DETACHED_BAR : | 1270 return IsDetached() ? bookmark_utils::LAUNCH_DETACHED_BAR : |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 return button; | 1320 return button; |
1253 } else { | 1321 } else { |
1254 views::MenuButton* button = new BookmarkFolderButton( | 1322 views::MenuButton* button = new BookmarkFolderButton( |
1255 this, node->GetTitle(), this, false); | 1323 this, node->GetTitle(), this, false); |
1256 button->SetIcon(GetFolderIcon()); | 1324 button->SetIcon(GetFolderIcon()); |
1257 ConfigureButton(node, button); | 1325 ConfigureButton(node, button); |
1258 return button; | 1326 return button; |
1259 } | 1327 } |
1260 } | 1328 } |
1261 | 1329 |
1330 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() { | |
1331 views::TextButton* button = new ShortcutButton( | |
1332 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); | |
1333 button->SetTooltipText(l10n_util::GetStringUTF16( | |
1334 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); | |
1335 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); | |
1336 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
1337 button->SetIcon(*rb.GetImageSkiaNamed(IDR_WEBSTORE_ICON_16)); | |
1338 button->set_context_menu_controller(this); | |
1339 button->set_tag(kAppsShortcutButtonTag); | |
1340 return button; | |
1341 } | |
1342 | |
1262 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, | 1343 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, |
1263 views::TextButton* button) { | 1344 views::TextButton* button) { |
1264 button->SetText(node->GetTitle()); | 1345 button->SetText(node->GetTitle()); |
1265 button->SetAccessibleName(node->GetTitle()); | 1346 button->SetAccessibleName(node->GetTitle()); |
1266 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); | 1347 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
1267 // We don't always have a theme provider (ui tests, for example). | 1348 // We don't always have a theme provider (ui tests, for example). |
1268 if (GetThemeProvider()) { | 1349 if (GetThemeProvider()) { |
1269 button->SetEnabledColor(GetThemeProvider()->GetColor( | 1350 button->SetEnabledColor(GetThemeProvider()->GetColor( |
1270 ThemeProperties::COLOR_BOOKMARK_TEXT)); | 1351 ThemeProperties::COLOR_BOOKMARK_TEXT)); |
1271 } | 1352 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1566 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 1647 for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
1567 GetBookmarkButton(i)->SetEnabledColor(text_color); | 1648 GetBookmarkButton(i)->SetEnabledColor(text_color); |
1568 other_bookmarked_button()->SetEnabledColor(text_color); | 1649 other_bookmarked_button()->SetEnabledColor(text_color); |
1569 } | 1650 } |
1570 | 1651 |
1571 void BookmarkBarView::UpdateOtherBookmarksVisibility() { | 1652 void BookmarkBarView::UpdateOtherBookmarksVisibility() { |
1572 bool has_other_children = !model_->other_node()->empty(); | 1653 bool has_other_children = !model_->other_node()->empty(); |
1573 if (has_other_children == other_bookmarked_button_->visible()) | 1654 if (has_other_children == other_bookmarked_button_->visible()) |
1574 return; | 1655 return; |
1575 other_bookmarked_button_->SetVisible(has_other_children); | 1656 other_bookmarked_button_->SetVisible(has_other_children); |
1576 #if !defined(USE_ASH) | 1657 UpdateBookmarksSeparatorVisibility(); |
1577 bookmarks_separator_view_->SetVisible(has_other_children); | |
1578 #endif | |
1579 Layout(); | 1658 Layout(); |
1580 SchedulePaint(); | 1659 SchedulePaint(); |
1581 } | 1660 } |
1582 | 1661 |
1662 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { | |
1663 #if !defined(USE_ASH) | |
1664 bookmarks_separator_view_->SetVisible( | |
1665 other_bookmarked_button_->visible() || | |
1666 apps_page_shortcut_->visible()); | |
1667 #else | |
1668 // Ash does not paint the bookmarks separator line because it looks odd on | |
sky
2013/03/05 01:42:58
This ifdef is wrong, it needs to be based on the H
beaudoin
2013/03/05 16:13:18
Done, but note that this ifdef was used previously
| |
1669 // the flat background. We keep it present for layout, but don't draw it. | |
1670 bookmarks_separator_view_->SetVisible(false); | |
1671 #endif | |
1672 } | |
1673 | |
1583 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { | 1674 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { |
1584 gfx::Size prefsize; | 1675 gfx::Size prefsize; |
1585 if (!parent() && !compute_bounds_only) | 1676 if (!parent() && !compute_bounds_only) |
1586 return prefsize; | 1677 return prefsize; |
1587 | 1678 |
1588 const chrome::search::Mode& mode = browser_->search_model()->mode(); | 1679 const chrome::search::Mode& mode = browser_->search_model()->mode(); |
1589 int x = kLeftMargin; | 1680 int x = kLeftMargin; |
1590 int top_margin = IsDetached() ? | 1681 int top_margin = IsDetached() ? |
1591 (mode.is_ntp() ? kSearchDetachedTopMargin : kDetachedTopMargin) : 0; | 1682 (mode.is_ntp() ? kSearchDetachedTopMargin : kDetachedTopMargin) : 0; |
1592 int y = top_margin; | 1683 int y = top_margin; |
(...skipping 15 matching lines...) Expand all Loading... | |
1608 // also matches how we layout infobars. | 1699 // also matches how we layout infobars. |
1609 y += View::height() - browser_defaults::kBookmarkBarHeight; | 1700 y += View::height() - browser_defaults::kBookmarkBarHeight; |
1610 height += browser_defaults::kBookmarkBarHeight; | 1701 height += browser_defaults::kBookmarkBarHeight; |
1611 } | 1702 } |
1612 | 1703 |
1613 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? | 1704 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? |
1614 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); | 1705 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); |
1615 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); | 1706 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
1616 gfx::Size bookmarks_separator_pref = | 1707 gfx::Size bookmarks_separator_pref = |
1617 bookmarks_separator_view_->GetPreferredSize(); | 1708 bookmarks_separator_view_->GetPreferredSize(); |
1709 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? | |
1710 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); | |
1618 | 1711 |
1619 int max_x = width - overflow_pref.width() - kButtonPadding - | 1712 int max_x = width - overflow_pref.width() - kButtonPadding - |
1620 bookmarks_separator_pref.width(); | 1713 bookmarks_separator_pref.width(); |
1621 if (other_bookmarked_button_->visible()) | 1714 if (other_bookmarked_button_->visible()) |
1622 max_x -= other_bookmarked_pref.width() + kButtonPadding; | 1715 max_x -= other_bookmarked_pref.width() + kButtonPadding; |
1716 if (apps_page_shortcut_->visible()) | |
1717 max_x -= apps_page_shortcut_pref.width() + kButtonPadding; | |
1623 | 1718 |
1624 // Next, layout out the buttons. Any buttons that are placed beyond the | 1719 // Next, layout out the buttons. Any buttons that are placed beyond the |
1625 // visible region and made invisible. | 1720 // visible region and made invisible. |
1626 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { | 1721 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { |
1627 gfx::Size pref = instructions_->GetPreferredSize(); | 1722 gfx::Size pref = instructions_->GetPreferredSize(); |
1628 if (!compute_bounds_only) { | 1723 if (!compute_bounds_only) { |
1629 instructions_->SetBounds( | 1724 instructions_->SetBounds( |
1630 x + kInstructionsPadding, y, | 1725 x + kInstructionsPadding, y, |
1631 std::min(static_cast<int>(pref.width()), | 1726 std::min(static_cast<int>(pref.width()), |
1632 max_x - x), | 1727 max_x - x), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1681 | 1776 |
1682 // The other bookmarks button. | 1777 // The other bookmarks button. |
1683 if (other_bookmarked_button_->visible()) { | 1778 if (other_bookmarked_button_->visible()) { |
1684 if (!compute_bounds_only) { | 1779 if (!compute_bounds_only) { |
1685 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), | 1780 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), |
1686 height); | 1781 height); |
1687 } | 1782 } |
1688 x += other_bookmarked_pref.width() + kButtonPadding; | 1783 x += other_bookmarked_pref.width() + kButtonPadding; |
1689 } | 1784 } |
1690 | 1785 |
1786 // The app page shortcut button. | |
1787 if (apps_page_shortcut_->visible()) { | |
1788 if (!compute_bounds_only) { | |
1789 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), | |
1790 height); | |
1791 } | |
1792 x += apps_page_shortcut_pref.width() + kButtonPadding; | |
1793 } | |
1794 | |
1691 // Set the preferred size computed so far. | 1795 // Set the preferred size computed so far. |
1692 if (compute_bounds_only) { | 1796 if (compute_bounds_only) { |
1693 x += kRightMargin; | 1797 x += kRightMargin; |
1694 prefsize.set_width(x); | 1798 prefsize.set_width(x); |
1695 if (IsDetached()) { | 1799 if (IsDetached()) { |
1696 x += static_cast<int>(GetNewtabHorizontalPadding(mode) * | 1800 x += static_cast<int>(GetNewtabHorizontalPadding(mode) * |
1697 (1 - size_animation_->GetCurrentValue())); | 1801 (1 - size_animation_->GetCurrentValue())); |
1698 int ntp_bookmark_bar_height = mode.is_ntp() ? | 1802 int ntp_bookmark_bar_height = mode.is_ntp() ? |
1699 kSearchNewTabBookmarkBarHeight : chrome::kNTPBookmarkBarHeight; | 1803 kSearchNewTabBookmarkBarHeight : chrome::kNTPBookmarkBarHeight; |
1700 prefsize.set_height( | 1804 prefsize.set_height( |
1701 browser_defaults::kBookmarkBarHeight + | 1805 browser_defaults::kBookmarkBarHeight + |
1702 static_cast<int>( | 1806 static_cast<int>( |
1703 (ntp_bookmark_bar_height - | 1807 (ntp_bookmark_bar_height - |
1704 browser_defaults::kBookmarkBarHeight) * | 1808 browser_defaults::kBookmarkBarHeight) * |
1705 (1 - size_animation_->GetCurrentValue()))); | 1809 (1 - size_animation_->GetCurrentValue()))); |
1706 } else { | 1810 } else { |
1707 prefsize.set_height( | 1811 prefsize.set_height( |
1708 static_cast<int>( | 1812 static_cast<int>( |
1709 browser_defaults::kBookmarkBarHeight * | 1813 browser_defaults::kBookmarkBarHeight * |
1710 size_animation_->GetCurrentValue())); | 1814 size_animation_->GetCurrentValue())); |
1711 } | 1815 } |
1712 } | 1816 } |
1713 return prefsize; | 1817 return prefsize; |
1714 } | 1818 } |
1819 | |
1820 bool BookmarkBarView::ShouldShowAppsShortcut() const { | |
1821 return chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()) && | |
1822 browser_->profile()->GetPrefs()->GetBoolean( | |
1823 prefs::kShowAppsShortcutInBookmarkBar); | |
1824 } | |
1825 | |
1826 void BookmarkBarView::OnAppsPageShortcutVisibilityChanged() { | |
1827 DCHECK(apps_page_shortcut_); | |
1828 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut()); | |
sky
2013/03/05 01:42:58
Don't you also need to invoke UpdateBookmarksSepar
beaudoin
2013/03/05 16:13:18
Done.
| |
1829 Layout(); | |
1830 } | |
OLD | NEW |