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

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

Issue 12310109: 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/tabs/tab_strip_model.h" 34 #include "chrome/browser/ui/tabs/tab_strip_model.h"
34 #include "chrome/browser/ui/view_ids.h" 35 #include "chrome/browser/ui/view_ids.h"
35 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h" 36 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h"
36 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" 37 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
37 #include "chrome/browser/ui/views/event_utils.h" 38 #include "chrome/browser/ui/views/event_utils.h"
38 #include "chrome/browser/ui/views/frame/browser_view.h" 39 #include "chrome/browser/ui/views/frame/browser_view.h"
39 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 40 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
40 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" 41 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
41 #include "chrome/common/chrome_notification_types.h" 42 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/chrome_switches.h" 43 #include "chrome/common/chrome_switches.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 127
127 // Starting x-coordinate of the separator line within a separator. 128 // Starting x-coordinate of the separator line within a separator.
128 static const int kSeparatorStartX = 2; 129 static const int kSeparatorStartX = 2;
129 130
130 // Left-padding for the instructional text. 131 // Left-padding for the instructional text.
131 static const int kInstructionsPadding = 6; 132 static const int kInstructionsPadding = 6;
132 133
133 // Tag for the 'Other bookmarks' button. 134 // Tag for the 'Other bookmarks' button.
134 static const int kOtherFolderButtonTag = 1; 135 static const int kOtherFolderButtonTag = 1;
135 136
137 // Tag for the 'Apps Shortcut' button.
138 static const int kAppsShortcutButtonTag = 2;
139
136 namespace { 140 namespace {
137 141
138 // BookmarkButton ------------------------------------------------------------- 142 // BookmarkButton -------------------------------------------------------------
139 143
140 // Buttons used for the bookmarks on the bookmark bar. 144 // Buttons used for the bookmarks on the bookmark bar.
141 145
142 class BookmarkButton : public views::TextButton { 146 class BookmarkButton : public views::TextButton {
143 public: 147 public:
144 // The internal view class name. 148 // The internal view class name.
145 static const char kViewClassName[]; 149 static const char kViewClassName[];
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 owner_->StopThrobbing(true); 260 owner_->StopThrobbing(true);
257 return views::MenuButton::OnMousePressed(e); 261 return views::MenuButton::OnMousePressed(e);
258 } 262 }
259 263
260 private: 264 private:
261 BookmarkBarView* owner_; 265 BookmarkBarView* owner_;
262 266
263 DISALLOW_COPY_AND_ASSIGN(OverFlowButton); 267 DISALLOW_COPY_AND_ASSIGN(OverFlowButton);
264 }; 268 };
265 269
270 // ShortcutButton -------------------------------------------------------------
271
272 // Buttons used for the shortcuts on the bookmark bar.
273
274 class ShortcutButton : public views::TextButton {
Alexei Svitkine (slow) 2013/02/25 21:13:29 Should this implement GetTooltipText()?
MAD 2013/02/25 21:41:01 No need for tooltip, the name of the shortcut is a
275 public:
276 // The internal view class name.
277 static const char kViewClassName[];
278
279 ShortcutButton(views::ButtonListener* listener,
280 const string16& title)
281 : TextButton(listener, title) {
282 show_animation_.reset(new ui::SlideAnimation(this));
283 if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) {
Alexei Svitkine (slow) 2013/02/25 21:13:29 It seems most of this logic is identical to Bookma
MAD 2013/02/25 21:41:01 I thought about it, but I recently got slapped on
284 // For some reason during testing the events generated by animating
285 // throw off the test. So, don't animate while testing.
286 show_animation_->Reset(1);
287 } else {
288 show_animation_->Show();
289 }
290 }
291
292 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE {
293 return e.type() == ui::ET_GESTURE_TAP ||
294 e.type() == ui::ET_GESTURE_TAP_DOWN ||
295 event_utils::IsPossibleDispositionEvent(e);
296 }
297
298 virtual std::string GetClassName() const OVERRIDE {
299 return kViewClassName;
300 }
301
302 private:
303 scoped_ptr<ui::SlideAnimation> show_animation_;
304
305 DISALLOW_COPY_AND_ASSIGN(ShortcutButton);
306 };
307
308 // static for ShortcutButton
309 const char ShortcutButton::kViewClassName[] =
310 "browser/ui/views/bookmarks/ShortcutButton";
311
266 void RecordAppLaunch(Profile* profile, GURL url) { 312 void RecordAppLaunch(Profile* profile, GURL url) {
267 DCHECK(profile->GetExtensionService()); 313 DCHECK(profile->GetExtensionService());
268 if (!profile->GetExtensionService()->IsInstalledApp(url)) 314 if (!profile->GetExtensionService()->IsInstalledApp(url))
269 return; 315 return;
270 316
271 AppLauncherHandler::RecordAppLaunchType( 317 AppLauncherHandler::RecordAppLaunchType(
272 extension_misc::APP_LAUNCH_BOOKMARK_BAR); 318 extension_misc::APP_LAUNCH_BOOKMARK_BAR);
273 } 319 }
274 320
275 } // namespace 321 } // namespace
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 421 }
376 return *kFolderIcon; 422 return *kFolderIcon;
377 } 423 }
378 424
379 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) 425 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
380 : page_navigator_(NULL), 426 : page_navigator_(NULL),
381 model_(NULL), 427 model_(NULL),
382 bookmark_menu_(NULL), 428 bookmark_menu_(NULL),
383 bookmark_drop_menu_(NULL), 429 bookmark_drop_menu_(NULL),
384 other_bookmarked_button_(NULL), 430 other_bookmarked_button_(NULL),
431 apps_page_shortcut_(NULL),
385 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), 432 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)),
386 overflow_button_(NULL), 433 overflow_button_(NULL),
387 instructions_(NULL), 434 instructions_(NULL),
388 bookmarks_separator_view_(NULL), 435 bookmarks_separator_view_(NULL),
389 browser_(browser), 436 browser_(browser),
390 browser_view_(browser_view), 437 browser_view_(browser_view),
391 infobar_visible_(false), 438 infobar_visible_(false),
392 throbbing_view_(NULL), 439 throbbing_view_(NULL),
393 bookmark_bar_state_(BookmarkBar::SHOW), 440 bookmark_bar_state_(BookmarkBar::SHOW),
394 animating_detached_(false) { 441 animating_detached_(false) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 if (bookmark_bar_state_ == BookmarkBar::DETACHED) { 647 if (bookmark_bar_state_ == BookmarkBar::DETACHED) {
601 double current_state = 1 - size_animation_->GetCurrentValue(); 648 double current_state = 1 - size_animation_->GetCurrentValue();
602 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state); 649 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state);
603 } 650 }
604 651
605 gfx::Size other_bookmarked_pref = 652 gfx::Size other_bookmarked_pref =
606 other_bookmarked_button_->GetPreferredSize(); 653 other_bookmarked_button_->GetPreferredSize();
607 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 654 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
608 gfx::Size bookmarks_separator_pref = 655 gfx::Size bookmarks_separator_pref =
609 bookmarks_separator_view_->GetPreferredSize(); 656 bookmarks_separator_view_->GetPreferredSize();
657 gfx::Size apps_page_shortcut_pref =
658 apps_page_shortcut_->GetPreferredSize();
610 659
611 width += other_bookmarked_pref.width() + kButtonPadding + 660 width += other_bookmarked_pref.width() + kButtonPadding +
661 apps_page_shortcut_pref.width() + kButtonPadding +
612 overflow_pref.width() + kButtonPadding + 662 overflow_pref.width() + kButtonPadding +
613 bookmarks_separator_pref.width(); 663 bookmarks_separator_pref.width();
614 664
615 return gfx::Size(width, browser_defaults::kBookmarkBarHeight); 665 return gfx::Size(width, browser_defaults::kBookmarkBarHeight);
616 } 666 }
617 667
618 void BookmarkBarView::Layout() { 668 void BookmarkBarView::Layout() {
619 LayoutItems(false); 669 LayoutItems(false);
620 } 670 }
621 671
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 } 1072 }
1023 } 1073 }
1024 return true; 1074 return true;
1025 } 1075 }
1026 1076
1027 void BookmarkBarView::OnMenuButtonClicked(views::View* view, 1077 void BookmarkBarView::OnMenuButtonClicked(views::View* view,
1028 const gfx::Point& point) { 1078 const gfx::Point& point) {
1029 const BookmarkNode* node; 1079 const BookmarkNode* node;
1030 1080
1031 int start_index = 0; 1081 int start_index = 0;
1032 if (view == other_bookmarked_button_) { 1082 if (view == other_bookmarked_button_ || view == apps_page_shortcut_) {
1083 // We want the same menu for both, so use the other node since the app
1084 // shortcut doesn't have a node.
1033 node = model_->other_node(); 1085 node = model_->other_node();
1034 } else if (view == overflow_button_) { 1086 } else if (view == overflow_button_) {
1035 node = model_->bookmark_bar_node(); 1087 node = model_->bookmark_bar_node();
1036 start_index = GetFirstHiddenNodeIndex(); 1088 start_index = GetFirstHiddenNodeIndex();
1037 } else { 1089 } else {
1038 int button_index = GetIndexOf(view); 1090 int button_index = GetIndexOf(view);
1039 DCHECK_NE(-1, button_index); 1091 DCHECK_NE(-1, button_index);
1040 node = model_->bookmark_bar_node()->GetChild(button_index); 1092 node = model_->bookmark_bar_node()->GetChild(button_index);
1041 } 1093 }
1042 1094
1043 bookmark_menu_ = new BookmarkMenuController(browser_, 1095 bookmark_menu_ = new BookmarkMenuController(browser_,
1044 page_navigator_, GetWidget(), node, start_index); 1096 page_navigator_, GetWidget(), node, start_index);
1045 bookmark_menu_->set_observer(this); 1097 bookmark_menu_->set_observer(this);
1046 bookmark_menu_->RunMenuAt(this, false); 1098 bookmark_menu_->RunMenuAt(this, false);
1047 } 1099 }
1048 1100
1049 void BookmarkBarView::ButtonPressed(views::Button* sender, 1101 void BookmarkBarView::ButtonPressed(views::Button* sender,
1050 const ui::Event& event) { 1102 const ui::Event& event) {
1103 if (sender->tag() == kAppsShortcutButtonTag) {
1104 chrome::ShowAppLauncherPage(browser_);
1105 return;
1106 }
1107
1051 const BookmarkNode* node; 1108 const BookmarkNode* node;
1052 if (sender->tag() == kOtherFolderButtonTag) { 1109 if (sender->tag() == kOtherFolderButtonTag) {
1053 node = model_->other_node(); 1110 node = model_->other_node();
1054 } else { 1111 } else {
1055 int index = GetIndexOf(sender); 1112 int index = GetIndexOf(sender);
1056 DCHECK_NE(-1, index); 1113 DCHECK_NE(-1, index);
1057 node = model_->bookmark_bar_node()->GetChild(index); 1114 node = model_->bookmark_bar_node()->GetChild(index);
1058 } 1115 }
1059 DCHECK(page_navigator_); 1116 DCHECK(page_navigator_);
1060 1117
(...skipping 22 matching lines...) Expand all
1083 if (!model_->IsLoaded()) { 1140 if (!model_->IsLoaded()) {
1084 // Don't do anything if the model isn't loaded. 1141 // Don't do anything if the model isn't loaded.
1085 return; 1142 return;
1086 } 1143 }
1087 1144
1088 const BookmarkNode* parent = NULL; 1145 const BookmarkNode* parent = NULL;
1089 std::vector<const BookmarkNode*> nodes; 1146 std::vector<const BookmarkNode*> nodes;
1090 if (source == other_bookmarked_button_) { 1147 if (source == other_bookmarked_button_) {
1091 parent = model_->other_node(); 1148 parent = model_->other_node();
1092 // Do this so the user can open all bookmarks. BookmarkContextMenu makes 1149 // Do this so the user can open all bookmarks. BookmarkContextMenu makes
1093 // sure the user can edit/delete the node in this case. 1150 // sure the user can't edit/delete the node in this case.
1094 nodes.push_back(parent); 1151 nodes.push_back(parent);
1095 } else if (source != this) { 1152 } else if (source != this && source != apps_page_shortcut_) {
1096 // User clicked on one of the bookmark buttons, find which one they 1153 // User clicked on one of the bookmark buttons, find which one they
1097 // clicked on. 1154 // clicked on, except for the apps page shortcut, which must behave as if
1155 // the user clicked on the bookmark bar background.
1098 int bookmark_button_index = GetIndexOf(source); 1156 int bookmark_button_index = GetIndexOf(source);
1099 DCHECK(bookmark_button_index != -1 && 1157 DCHECK(bookmark_button_index != -1 &&
1100 bookmark_button_index < GetBookmarkButtonCount()); 1158 bookmark_button_index < GetBookmarkButtonCount());
1101 const BookmarkNode* node = 1159 const BookmarkNode* node =
1102 model_->bookmark_bar_node()->GetChild(bookmark_button_index); 1160 model_->bookmark_bar_node()->GetChild(bookmark_button_index);
1103 nodes.push_back(node); 1161 nodes.push_back(node);
1104 parent = node->parent(); 1162 parent = node->parent();
1105 } else { 1163 } else {
1106 parent = model_->bookmark_bar_node(); 1164 parent = model_->bookmark_bar_node();
1107 nodes.push_back(parent); 1165 nodes.push_back(parent);
(...skipping 23 matching lines...) Expand all
1131 // Child views are traversed in the order they are added. Make sure the order 1189 // Child views are traversed in the order they are added. Make sure the order
1132 // they are added matches the visual order. 1190 // they are added matches the visual order.
1133 overflow_button_ = CreateOverflowButton(); 1191 overflow_button_ = CreateOverflowButton();
1134 AddChildView(overflow_button_); 1192 AddChildView(overflow_button_);
1135 1193
1136 other_bookmarked_button_ = CreateOtherBookmarkedButton(); 1194 other_bookmarked_button_ = CreateOtherBookmarkedButton();
1137 // We'll re-enable when the model is loaded. 1195 // We'll re-enable when the model is loaded.
1138 other_bookmarked_button_->SetEnabled(false); 1196 other_bookmarked_button_->SetEnabled(false);
1139 AddChildView(other_bookmarked_button_); 1197 AddChildView(other_bookmarked_button_);
1140 1198
1199 apps_page_shortcut_ = CreateAppsPageShortcutButton();
1200 AddChildView(apps_page_shortcut_);
1201 profile_pref_registrar_.Init(browser_->profile()->GetPrefs());
1202 profile_pref_registrar_.Add(
1203 prefs::kShowAppsShortcutInBookmarkBar,
1204 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityChanged,
1205 base::Unretained(this)));
1206 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut());
1207
1141 bookmarks_separator_view_ = new ButtonSeparatorView(); 1208 bookmarks_separator_view_ = new ButtonSeparatorView();
1142 AddChildView(bookmarks_separator_view_); 1209 AddChildView(bookmarks_separator_view_);
1143 #if defined(USE_ASH) 1210 #if defined(USE_ASH)
1144 // Ash does not paint the bookmarks separator line because it looks odd on 1211 // Ash does not paint the bookmarks separator line because it looks odd on
1145 // the flat background. We keep it present for layout, but don't draw it. 1212 // the flat background. We keep it present for layout, but don't draw it.
1146 bookmarks_separator_view_->SetVisible(false); 1213 bookmarks_separator_view_->SetVisible(false);
1147 #endif 1214 #endif
1148 1215
1149 instructions_ = new BookmarkBarInstructionsView(this); 1216 instructions_ = new BookmarkBarInstructionsView(this);
1150 AddChildView(instructions_); 1217 AddChildView(instructions_);
1151 1218
1152 set_context_menu_controller(this); 1219 set_context_menu_controller(this);
1153 1220
1154 size_animation_.reset(new ui::SlideAnimation(this)); 1221 size_animation_.reset(new ui::SlideAnimation(this));
1155 1222
1156 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); 1223 model_ = BookmarkModelFactory::GetForProfile(browser_->profile());
1157 if (model_) { 1224 if (model_) {
1158 model_->AddObserver(this); 1225 model_->AddObserver(this);
1159 if (model_->IsLoaded()) 1226 if (model_->IsLoaded())
1160 Loaded(model_, false); 1227 Loaded(model_, false);
1161 // else case: we'll receive notification back from the BookmarkModel when 1228 // else case: we'll receive notification back from the BookmarkModel when
1162 // done loading, then we'll populate the bar. 1229 // done loading, then we'll populate the bar.
1163 } 1230 }
1164 } 1231 }
1165 1232
1166 int BookmarkBarView::GetBookmarkButtonCount() { 1233 int BookmarkBarView::GetBookmarkButtonCount() {
1167 // We contain four non-bookmark button views: other bookmarks, bookmarks 1234 // We contain four non-bookmark button views: other bookmarks, bookmarks
1168 // separator, chevrons (for overflow), and the instruction label. 1235 // separator, chevrons (for overflow), apps page, and the instruction label.
1169 return child_count() - 4; 1236 return child_count() - 5;
1170 } 1237 }
1171 1238
1172 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { 1239 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) {
1173 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1240 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
1174 return static_cast<views::TextButton*>(child_at(index)); 1241 return static_cast<views::TextButton*>(child_at(index));
1175 } 1242 }
1176 1243
1177 int BookmarkBarView::GetFirstHiddenNodeIndex() { 1244 int BookmarkBarView::GetFirstHiddenNodeIndex() {
1178 const int bb_count = GetBookmarkButtonCount(); 1245 const int bb_count = GetBookmarkButtonCount();
1179 for (int i = 0; i < bb_count; ++i) { 1246 for (int i = 0; i < bb_count; ++i) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 return button; 1290 return button;
1224 } else { 1291 } else {
1225 views::MenuButton* button = new BookmarkFolderButton( 1292 views::MenuButton* button = new BookmarkFolderButton(
1226 this, node->GetTitle(), this, false); 1293 this, node->GetTitle(), this, false);
1227 button->SetIcon(GetFolderIcon()); 1294 button->SetIcon(GetFolderIcon());
1228 ConfigureButton(node, button); 1295 ConfigureButton(node, button);
1229 return button; 1296 return button;
1230 } 1297 }
1231 } 1298 }
1232 1299
1300 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() {
1301 views::TextButton* button = new ShortcutButton(
1302 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME));
1303 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1304 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1305 button->SetIcon(*rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16));
1306 button->set_context_menu_controller(this);
1307 button->set_tag(kAppsShortcutButtonTag);
1308 button->SetEnabled(true);
1309 return button;
1310 }
1311
1233 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, 1312 void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
1234 views::TextButton* button) { 1313 views::TextButton* button) {
1235 button->SetText(node->GetTitle()); 1314 button->SetText(node->GetTitle());
1236 button->SetAccessibleName(node->GetTitle()); 1315 button->SetAccessibleName(node->GetTitle());
1237 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); 1316 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1238 // We don't always have a theme provider (ui tests, for example). 1317 // We don't always have a theme provider (ui tests, for example).
1239 if (GetThemeProvider()) { 1318 if (GetThemeProvider()) {
1240 button->SetEnabledColor(GetThemeProvider()->GetColor( 1319 button->SetEnabledColor(GetThemeProvider()->GetColor(
1241 ThemeProperties::COLOR_BOOKMARK_TEXT)); 1320 ThemeProperties::COLOR_BOOKMARK_TEXT));
1242 } 1321 }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 // also matches how we layout infobars. 1656 // also matches how we layout infobars.
1578 y += View::height() - browser_defaults::kBookmarkBarHeight; 1657 y += View::height() - browser_defaults::kBookmarkBarHeight;
1579 height += browser_defaults::kBookmarkBarHeight; 1658 height += browser_defaults::kBookmarkBarHeight;
1580 } 1659 }
1581 1660
1582 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? 1661 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ?
1583 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); 1662 other_bookmarked_button_->GetPreferredSize() : gfx::Size();
1584 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 1663 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
1585 gfx::Size bookmarks_separator_pref = 1664 gfx::Size bookmarks_separator_pref =
1586 bookmarks_separator_view_->GetPreferredSize(); 1665 bookmarks_separator_view_->GetPreferredSize();
1666 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ?
1667 apps_page_shortcut_->GetPreferredSize() : gfx::Size();
1587 1668
1588 int max_x = width - overflow_pref.width() - kButtonPadding - 1669 int max_x = width - overflow_pref.width() - kButtonPadding -
1589 bookmarks_separator_pref.width(); 1670 bookmarks_separator_pref.width();
1590 if (other_bookmarked_button_->visible()) 1671 if (other_bookmarked_button_->visible())
1591 max_x -= other_bookmarked_pref.width() + kButtonPadding; 1672 max_x -= other_bookmarked_pref.width() + kButtonPadding;
1673 if (apps_page_shortcut_->visible())
1674 max_x -= apps_page_shortcut_pref.width() + kButtonPadding;
1592 1675
1593 // Next, layout out the buttons. Any buttons that are placed beyond the 1676 // Next, layout out the buttons. Any buttons that are placed beyond the
1594 // visible region and made invisible. 1677 // visible region and made invisible.
1595 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { 1678 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) {
1596 gfx::Size pref = instructions_->GetPreferredSize(); 1679 gfx::Size pref = instructions_->GetPreferredSize();
1597 if (!compute_bounds_only) { 1680 if (!compute_bounds_only) {
1598 instructions_->SetBounds( 1681 instructions_->SetBounds(
1599 x + kInstructionsPadding, y, 1682 x + kInstructionsPadding, y,
1600 std::min(static_cast<int>(pref.width()), 1683 std::min(static_cast<int>(pref.width()),
1601 max_x - x), 1684 max_x - x),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 1733
1651 // The other bookmarks button. 1734 // The other bookmarks button.
1652 if (other_bookmarked_button_->visible()) { 1735 if (other_bookmarked_button_->visible()) {
1653 if (!compute_bounds_only) { 1736 if (!compute_bounds_only) {
1654 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), 1737 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
1655 height); 1738 height);
1656 } 1739 }
1657 x += other_bookmarked_pref.width() + kButtonPadding; 1740 x += other_bookmarked_pref.width() + kButtonPadding;
1658 } 1741 }
1659 1742
1743 // The app page shortcut button.
1744 if (apps_page_shortcut_->visible()) {
1745 if (!compute_bounds_only) {
1746 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(),
1747 height);
1748 }
1749 x += apps_page_shortcut_pref.width() + kButtonPadding;
1750 }
1751
1660 // Set the preferred size computed so far. 1752 // Set the preferred size computed so far.
1661 if (compute_bounds_only) { 1753 if (compute_bounds_only) {
1662 x += kRightMargin; 1754 x += kRightMargin;
1663 prefsize.set_width(x); 1755 prefsize.set_width(x);
1664 if (IsDetached()) { 1756 if (IsDetached()) {
1665 x += static_cast<int>( 1757 x += static_cast<int>(
1666 kNewtabHorizontalPadding * (1 - size_animation_->GetCurrentValue())); 1758 kNewtabHorizontalPadding * (1 - size_animation_->GetCurrentValue()));
1667 prefsize.set_height( 1759 prefsize.set_height(
1668 browser_defaults::kBookmarkBarHeight + 1760 browser_defaults::kBookmarkBarHeight +
1669 static_cast<int>( 1761 static_cast<int>(
1670 (chrome::kNTPBookmarkBarHeight - 1762 (chrome::kNTPBookmarkBarHeight -
1671 browser_defaults::kBookmarkBarHeight) * 1763 browser_defaults::kBookmarkBarHeight) *
1672 (1 - size_animation_->GetCurrentValue()))); 1764 (1 - size_animation_->GetCurrentValue())));
1673 } else { 1765 } else {
1674 prefsize.set_height( 1766 prefsize.set_height(
1675 static_cast<int>( 1767 static_cast<int>(
1676 browser_defaults::kBookmarkBarHeight * 1768 browser_defaults::kBookmarkBarHeight *
1677 size_animation_->GetCurrentValue())); 1769 size_animation_->GetCurrentValue()));
1678 } 1770 }
1679 } 1771 }
1680 return prefsize; 1772 return prefsize;
1681 } 1773 }
1774
1775 bool BookmarkBarView::ShouldShowAppsShortcut() {
1776 return chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()) &&
1777 browser_->profile()->GetPrefs()->GetBoolean(
1778 prefs::kShowAppsShortcutInBookmarkBar);
1779 }
1780
1781 void BookmarkBarView::OnAppsPageShortcutVisibilityChanged() {
1782 DCHECK(apps_page_shortcut_);
1783 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut());
1784 Layout();
1785 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698