Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

Issue 12386088: Add a shortcut to open the Apps page from the bookmark bar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 scoped_ptr<ui::SlideAnimation> show_animation_;
sky 2013/03/04 22:16:50 This isn't needed, right?
beaudoin 2013/03/04 23:30:21 Done.
249
250 DISALLOW_COPY_AND_ASSIGN(ShortcutButton);
251 };
252
253 // static for ShortcutButton
254 const char ShortcutButton::kViewClassName[] =
255 "browser/ui/views/bookmarks/ShortcutButton";
256
209 // BookmarkFolderButton ------------------------------------------------------- 257 // BookmarkFolderButton -------------------------------------------------------
210 258
211 // Buttons used for folders on the bookmark bar, including the 'other folders' 259 // Buttons used for folders on the bookmark bar, including the 'other folders'
212 // button. 260 // button.
213 class BookmarkFolderButton : public views::MenuButton { 261 class BookmarkFolderButton : public views::MenuButton {
214 public: 262 public:
215 BookmarkFolderButton(views::ButtonListener* listener, 263 BookmarkFolderButton(views::ButtonListener* listener,
216 const string16& title, 264 const string16& title,
217 views::MenuButtonListener* menu_button_listener, 265 views::MenuButtonListener* menu_button_listener,
218 bool show_menu_marker) 266 bool show_menu_marker)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 447 }
400 return *kFolderIcon; 448 return *kFolderIcon;
401 } 449 }
402 450
403 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) 451 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
404 : page_navigator_(NULL), 452 : page_navigator_(NULL),
405 model_(NULL), 453 model_(NULL),
406 bookmark_menu_(NULL), 454 bookmark_menu_(NULL),
407 bookmark_drop_menu_(NULL), 455 bookmark_drop_menu_(NULL),
408 other_bookmarked_button_(NULL), 456 other_bookmarked_button_(NULL),
457 apps_page_shortcut_(NULL),
409 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), 458 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)),
410 overflow_button_(NULL), 459 overflow_button_(NULL),
411 instructions_(NULL), 460 instructions_(NULL),
412 bookmarks_separator_view_(NULL), 461 bookmarks_separator_view_(NULL),
413 browser_(browser), 462 browser_(browser),
414 browser_view_(browser_view), 463 browser_view_(browser_view),
415 infobar_visible_(false), 464 infobar_visible_(false),
416 throbbing_view_(NULL), 465 throbbing_view_(NULL),
417 bookmark_bar_state_(BookmarkBar::SHOW), 466 bookmark_bar_state_(BookmarkBar::SHOW),
418 animating_detached_(false) { 467 animating_detached_(false) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 // button, by which one can access all the Bookmark Bar items, and the "Other 669 // button, by which one can access all the Bookmark Bar items, and the "Other
621 // Bookmarks" folder, along with appropriate margins and button padding. 670 // Bookmarks" folder, along with appropriate margins and button padding.
622 int width = kLeftMargin; 671 int width = kLeftMargin;
623 672
624 if (bookmark_bar_state_ == BookmarkBar::DETACHED) { 673 if (bookmark_bar_state_ == BookmarkBar::DETACHED) {
625 double current_state = 1 - size_animation_->GetCurrentValue(); 674 double current_state = 1 - size_animation_->GetCurrentValue();
626 width += 2 * static_cast<int>(GetNewtabHorizontalPadding( 675 width += 2 * static_cast<int>(GetNewtabHorizontalPadding(
627 browser_->search_model()->mode()) * current_state); 676 browser_->search_model()->mode()) * current_state);
628 } 677 }
629 678
630 gfx::Size other_bookmarked_pref = 679 gfx::Size other_bookmarked_pref;
631 other_bookmarked_button_->GetPreferredSize(); 680 if (other_bookmarked_button_->visible())
632 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 681 other_bookmarked_pref = other_bookmarked_button_->GetPreferredSize();
633 gfx::Size bookmarks_separator_pref = 682 gfx::Size overflow_pref;
634 bookmarks_separator_view_->GetPreferredSize(); 683 if (overflow_button_->visible())
684 overflow_pref = overflow_button_->GetPreferredSize();
685 gfx::Size bookmarks_separator_pref;
686 if (bookmarks_separator_view_->visible())
687 bookmarks_separator_pref = bookmarks_separator_view_->GetPreferredSize();
sky 2013/03/04 22:16:50 spacing
beaudoin 2013/03/04 23:30:21 Done.
635 688
689 gfx::Size apps_page_shortcut_pref;
690 if (apps_page_shortcut_->visible())
691 apps_page_shortcut_pref = apps_page_shortcut_->GetPreferredSize();
636 width += other_bookmarked_pref.width() + kButtonPadding + 692 width += other_bookmarked_pref.width() + kButtonPadding +
693 apps_page_shortcut_pref.width() + kButtonPadding +
637 overflow_pref.width() + kButtonPadding + 694 overflow_pref.width() + kButtonPadding +
638 bookmarks_separator_pref.width(); 695 bookmarks_separator_pref.width();
639 696
640 return gfx::Size(width, browser_defaults::kBookmarkBarHeight); 697 return gfx::Size(width, browser_defaults::kBookmarkBarHeight);
641 } 698 }
642 699
643 void BookmarkBarView::Layout() { 700 void BookmarkBarView::Layout() {
644 LayoutItems(false); 701 LayoutItems(false);
645 } 702 }
646 703
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 1124
1068 bookmark_utils::RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); 1125 bookmark_utils::RecordBookmarkFolderOpen(GetBookmarkLaunchLocation());
1069 bookmark_menu_ = new BookmarkMenuController(browser_, 1126 bookmark_menu_ = new BookmarkMenuController(browser_,
1070 page_navigator_, GetWidget(), node, start_index); 1127 page_navigator_, GetWidget(), node, start_index);
1071 bookmark_menu_->set_observer(this); 1128 bookmark_menu_->set_observer(this);
1072 bookmark_menu_->RunMenuAt(this, false); 1129 bookmark_menu_->RunMenuAt(this, false);
1073 } 1130 }
1074 1131
1075 void BookmarkBarView::ButtonPressed(views::Button* sender, 1132 void BookmarkBarView::ButtonPressed(views::Button* sender,
1076 const ui::Event& event) { 1133 const ui::Event& event) {
1134 if (sender->tag() == kAppsShortcutButtonTag) {
1135 chrome::ShowAppLauncherPage(browser_);
1136 content::RecordAction(
1137 UserMetricsAction("ClickedBookmarkBarAppsShortcutButton"));
Alexei Svitkine (slow) 2013/03/04 20:56:04 Can you move this UMA action to bookmark_utils.cc
tfarina 2013/03/04 22:19:47 if you do, can you try to put in c/b/ui/bookmark_u
tfarina 2013/03/04 22:20:41 oops, this should c/b/ui/bookmarks/bookmark_utils
beaudoin 2013/03/04 23:30:21 Extracted to a method, but I did not move the book
1138 return;
1139 }
1140
1077 const BookmarkNode* node; 1141 const BookmarkNode* node;
1078 if (sender->tag() == kOtherFolderButtonTag) { 1142 if (sender->tag() == kOtherFolderButtonTag) {
1079 node = model_->other_node(); 1143 node = model_->other_node();
1080 } else { 1144 } else {
1081 int index = GetIndexOf(sender); 1145 int index = GetIndexOf(sender);
1082 DCHECK_NE(-1, index); 1146 DCHECK_NE(-1, index);
1083 node = model_->bookmark_bar_node()->GetChild(index); 1147 node = model_->bookmark_bar_node()->GetChild(index);
1084 } 1148 }
1085 DCHECK(page_navigator_); 1149 DCHECK(page_navigator_);
1086 1150
(...skipping 19 matching lines...) Expand all
1106 if (!model_->IsLoaded()) { 1170 if (!model_->IsLoaded()) {
1107 // Don't do anything if the model isn't loaded. 1171 // Don't do anything if the model isn't loaded.
1108 return; 1172 return;
1109 } 1173 }
1110 1174
1111 const BookmarkNode* parent = NULL; 1175 const BookmarkNode* parent = NULL;
1112 std::vector<const BookmarkNode*> nodes; 1176 std::vector<const BookmarkNode*> nodes;
1113 if (source == other_bookmarked_button_) { 1177 if (source == other_bookmarked_button_) {
1114 parent = model_->other_node(); 1178 parent = model_->other_node();
1115 // Do this so the user can open all bookmarks. BookmarkContextMenu makes 1179 // Do this so the user can open all bookmarks. BookmarkContextMenu makes
1116 // sure the user can edit/delete the node in this case. 1180 // sure the user can't edit/delete the node in this case.
1117 nodes.push_back(parent); 1181 nodes.push_back(parent);
1118 } else if (source != this) { 1182 } else if (source != this && source != apps_page_shortcut_) {
1119 // User clicked on one of the bookmark buttons, find which one they 1183 // User clicked on one of the bookmark buttons, find which one they
1120 // clicked on. 1184 // clicked on, except for the apps page shortcut, which must behave as if
1185 // the user clicked on the bookmark bar background.
1121 int bookmark_button_index = GetIndexOf(source); 1186 int bookmark_button_index = GetIndexOf(source);
1122 DCHECK(bookmark_button_index != -1 && 1187 DCHECK(bookmark_button_index != -1 &&
1123 bookmark_button_index < GetBookmarkButtonCount()); 1188 bookmark_button_index < GetBookmarkButtonCount());
1124 const BookmarkNode* node = 1189 const BookmarkNode* node =
1125 model_->bookmark_bar_node()->GetChild(bookmark_button_index); 1190 model_->bookmark_bar_node()->GetChild(bookmark_button_index);
1126 nodes.push_back(node); 1191 nodes.push_back(node);
1127 parent = node->parent(); 1192 parent = node->parent();
1128 } else { 1193 } else {
1129 parent = model_->bookmark_bar_node(); 1194 parent = model_->bookmark_bar_node();
1130 nodes.push_back(parent); 1195 nodes.push_back(parent);
(...skipping 23 matching lines...) Expand all
1154 // Child views are traversed in the order they are added. Make sure the order 1219 // Child views are traversed in the order they are added. Make sure the order
1155 // they are added matches the visual order. 1220 // they are added matches the visual order.
1156 overflow_button_ = CreateOverflowButton(); 1221 overflow_button_ = CreateOverflowButton();
1157 AddChildView(overflow_button_); 1222 AddChildView(overflow_button_);
1158 1223
1159 other_bookmarked_button_ = CreateOtherBookmarkedButton(); 1224 other_bookmarked_button_ = CreateOtherBookmarkedButton();
1160 // We'll re-enable when the model is loaded. 1225 // We'll re-enable when the model is loaded.
1161 other_bookmarked_button_->SetEnabled(false); 1226 other_bookmarked_button_->SetEnabled(false);
1162 AddChildView(other_bookmarked_button_); 1227 AddChildView(other_bookmarked_button_);
1163 1228
1229 apps_page_shortcut_ = CreateAppsPageShortcutButton();
1230 AddChildView(apps_page_shortcut_);
1231 profile_pref_registrar_.Init(browser_->profile()->GetPrefs());
1232 profile_pref_registrar_.Add(
1233 prefs::kShowAppsShortcutInBookmarkBar,
1234 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityChanged,
1235 base::Unretained(this)));
1236 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut());
1237
1164 bookmarks_separator_view_ = new ButtonSeparatorView(); 1238 bookmarks_separator_view_ = new ButtonSeparatorView();
1165 AddChildView(bookmarks_separator_view_); 1239 AddChildView(bookmarks_separator_view_);
1166 #if defined(USE_ASH) 1240 #if defined(USE_ASH)
1167 // Ash does not paint the bookmarks separator line because it looks odd on 1241 // 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. 1242 // the flat background. We keep it present for layout, but don't draw it.
1169 bookmarks_separator_view_->SetVisible(false); 1243 bookmarks_separator_view_->SetVisible(false);
1170 #endif 1244 #endif
1171 1245
1172 instructions_ = new BookmarkBarInstructionsView(this); 1246 instructions_ = new BookmarkBarInstructionsView(this);
1173 AddChildView(instructions_); 1247 AddChildView(instructions_);
1174 1248
1175 set_context_menu_controller(this); 1249 set_context_menu_controller(this);
1176 1250
1177 size_animation_.reset(new ui::SlideAnimation(this)); 1251 size_animation_.reset(new ui::SlideAnimation(this));
1178 1252
1179 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); 1253 model_ = BookmarkModelFactory::GetForProfile(browser_->profile());
1180 if (model_) { 1254 if (model_) {
1181 model_->AddObserver(this); 1255 model_->AddObserver(this);
1182 if (model_->IsLoaded()) 1256 if (model_->IsLoaded())
1183 Loaded(model_, false); 1257 Loaded(model_, false);
1184 // else case: we'll receive notification back from the BookmarkModel when 1258 // else case: we'll receive notification back from the BookmarkModel when
1185 // done loading, then we'll populate the bar. 1259 // done loading, then we'll populate the bar.
1186 } 1260 }
1187 } 1261 }
1188 1262
1189 int BookmarkBarView::GetBookmarkButtonCount() { 1263 int BookmarkBarView::GetBookmarkButtonCount() {
1190 // We contain four non-bookmark button views: other bookmarks, bookmarks 1264 // We contain four non-bookmark button views: other bookmarks, bookmarks
1191 // separator, chevrons (for overflow), and the instruction label. 1265 // separator, chevrons (for overflow), apps page, and the instruction label.
1192 return child_count() - 4; 1266 return child_count() - 5;
1193 } 1267 }
1194 1268
1195 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { 1269 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) {
1196 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1270 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
1197 return static_cast<views::TextButton*>(child_at(index)); 1271 return static_cast<views::TextButton*>(child_at(index));
1198 } 1272 }
1199 1273
1200 bookmark_utils::BookmarkLaunchLocation 1274 bookmark_utils::BookmarkLaunchLocation
1201 BookmarkBarView::GetBookmarkLaunchLocation() const { 1275 BookmarkBarView::GetBookmarkLaunchLocation() const {
1202 return IsDetached() ? bookmark_utils::LAUNCH_DETACHED_BAR : 1276 return IsDetached() ? bookmark_utils::LAUNCH_DETACHED_BAR :
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 return button; 1326 return button;
1253 } else { 1327 } else {
1254 views::MenuButton* button = new BookmarkFolderButton( 1328 views::MenuButton* button = new BookmarkFolderButton(
1255 this, node->GetTitle(), this, false); 1329 this, node->GetTitle(), this, false);
1256 button->SetIcon(GetFolderIcon()); 1330 button->SetIcon(GetFolderIcon());
1257 ConfigureButton(node, button); 1331 ConfigureButton(node, button);
1258 return button; 1332 return button;
1259 } 1333 }
1260 } 1334 }
1261 1335
1336 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() {
1337 views::TextButton* button = new ShortcutButton(
1338 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME));
1339 button->SetTooltipText(l10n_util::GetStringUTF16(
1340 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP));
1341 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1342 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1343 button->SetIcon(*rb.GetImageSkiaNamed(IDR_WEBSTORE_ICON_16));
1344 button->set_context_menu_controller(this);
1345 button->set_tag(kAppsShortcutButtonTag);
1346 button->SetEnabled(true);
1347 return button;
1348 }
1349
1262 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, 1350 void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
1263 views::TextButton* button) { 1351 views::TextButton* button) {
1264 button->SetText(node->GetTitle()); 1352 button->SetText(node->GetTitle());
1265 button->SetAccessibleName(node->GetTitle()); 1353 button->SetAccessibleName(node->GetTitle());
1266 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); 1354 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1267 // We don't always have a theme provider (ui tests, for example). 1355 // We don't always have a theme provider (ui tests, for example).
1268 if (GetThemeProvider()) { 1356 if (GetThemeProvider()) {
1269 button->SetEnabledColor(GetThemeProvider()->GetColor( 1357 button->SetEnabledColor(GetThemeProvider()->GetColor(
1270 ThemeProperties::COLOR_BOOKMARK_TEXT)); 1358 ThemeProperties::COLOR_BOOKMARK_TEXT));
1271 } 1359 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 // also matches how we layout infobars. 1696 // also matches how we layout infobars.
1609 y += View::height() - browser_defaults::kBookmarkBarHeight; 1697 y += View::height() - browser_defaults::kBookmarkBarHeight;
1610 height += browser_defaults::kBookmarkBarHeight; 1698 height += browser_defaults::kBookmarkBarHeight;
1611 } 1699 }
1612 1700
1613 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? 1701 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ?
1614 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); 1702 other_bookmarked_button_->GetPreferredSize() : gfx::Size();
1615 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 1703 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
1616 gfx::Size bookmarks_separator_pref = 1704 gfx::Size bookmarks_separator_pref =
1617 bookmarks_separator_view_->GetPreferredSize(); 1705 bookmarks_separator_view_->GetPreferredSize();
1706 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ?
1707 apps_page_shortcut_->GetPreferredSize() : gfx::Size();
1618 1708
1619 int max_x = width - overflow_pref.width() - kButtonPadding - 1709 int max_x = width - overflow_pref.width() - kButtonPadding -
1620 bookmarks_separator_pref.width(); 1710 bookmarks_separator_pref.width();
1621 if (other_bookmarked_button_->visible()) 1711 if (other_bookmarked_button_->visible())
1622 max_x -= other_bookmarked_pref.width() + kButtonPadding; 1712 max_x -= other_bookmarked_pref.width() + kButtonPadding;
1713 if (apps_page_shortcut_->visible())
1714 max_x -= apps_page_shortcut_pref.width() + kButtonPadding;
1623 1715
1624 // Next, layout out the buttons. Any buttons that are placed beyond the 1716 // Next, layout out the buttons. Any buttons that are placed beyond the
1625 // visible region and made invisible. 1717 // visible region and made invisible.
1626 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { 1718 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) {
1627 gfx::Size pref = instructions_->GetPreferredSize(); 1719 gfx::Size pref = instructions_->GetPreferredSize();
1628 if (!compute_bounds_only) { 1720 if (!compute_bounds_only) {
1629 instructions_->SetBounds( 1721 instructions_->SetBounds(
1630 x + kInstructionsPadding, y, 1722 x + kInstructionsPadding, y,
1631 std::min(static_cast<int>(pref.width()), 1723 std::min(static_cast<int>(pref.width()),
1632 max_x - x), 1724 max_x - x),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 1773
1682 // The other bookmarks button. 1774 // The other bookmarks button.
1683 if (other_bookmarked_button_->visible()) { 1775 if (other_bookmarked_button_->visible()) {
1684 if (!compute_bounds_only) { 1776 if (!compute_bounds_only) {
1685 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), 1777 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
1686 height); 1778 height);
1687 } 1779 }
1688 x += other_bookmarked_pref.width() + kButtonPadding; 1780 x += other_bookmarked_pref.width() + kButtonPadding;
1689 } 1781 }
1690 1782
1783 // The app page shortcut button.
1784 if (apps_page_shortcut_->visible()) {
1785 if (!compute_bounds_only) {
1786 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(),
1787 height);
1788 }
1789 x += apps_page_shortcut_pref.width() + kButtonPadding;
1790 }
1791
1691 // Set the preferred size computed so far. 1792 // Set the preferred size computed so far.
1692 if (compute_bounds_only) { 1793 if (compute_bounds_only) {
1693 x += kRightMargin; 1794 x += kRightMargin;
1694 prefsize.set_width(x); 1795 prefsize.set_width(x);
1695 if (IsDetached()) { 1796 if (IsDetached()) {
1696 x += static_cast<int>(GetNewtabHorizontalPadding(mode) * 1797 x += static_cast<int>(GetNewtabHorizontalPadding(mode) *
1697 (1 - size_animation_->GetCurrentValue())); 1798 (1 - size_animation_->GetCurrentValue()));
1698 int ntp_bookmark_bar_height = mode.is_ntp() ? 1799 int ntp_bookmark_bar_height = mode.is_ntp() ?
1699 kSearchNewTabBookmarkBarHeight : chrome::kNTPBookmarkBarHeight; 1800 kSearchNewTabBookmarkBarHeight : chrome::kNTPBookmarkBarHeight;
1700 prefsize.set_height( 1801 prefsize.set_height(
1701 browser_defaults::kBookmarkBarHeight + 1802 browser_defaults::kBookmarkBarHeight +
1702 static_cast<int>( 1803 static_cast<int>(
1703 (ntp_bookmark_bar_height - 1804 (ntp_bookmark_bar_height -
1704 browser_defaults::kBookmarkBarHeight) * 1805 browser_defaults::kBookmarkBarHeight) *
1705 (1 - size_animation_->GetCurrentValue()))); 1806 (1 - size_animation_->GetCurrentValue())));
1706 } else { 1807 } else {
1707 prefsize.set_height( 1808 prefsize.set_height(
1708 static_cast<int>( 1809 static_cast<int>(
1709 browser_defaults::kBookmarkBarHeight * 1810 browser_defaults::kBookmarkBarHeight *
1710 size_animation_->GetCurrentValue())); 1811 size_animation_->GetCurrentValue()));
1711 } 1812 }
1712 } 1813 }
1713 return prefsize; 1814 return prefsize;
1714 } 1815 }
1816
1817 bool BookmarkBarView::ShouldShowAppsShortcut() const {
1818 return chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()) &&
1819 browser_->profile()->GetPrefs()->GetBoolean(
1820 prefs::kShowAppsShortcutInBookmarkBar);
1821 }
1822
1823 void BookmarkBarView::OnAppsPageShortcutVisibilityChanged() {
1824 DCHECK(apps_page_shortcut_);
1825 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut());
1826 Layout();
1827 }
1828
1829 bool BookmarkBarView::IsAppsShortcutVisibleForTesting() const {
1830 DCHECK(apps_page_shortcut_);
1831 return apps_page_shortcut_->visible();
1832 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698