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

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: Sync'd to ToT. 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
142 // BookmarkButtonBase ---------------------------------------------------------
143
144 // Base class for text buttons used on the bookmark bar.
145
146 class BookmarkButtonBase : public views::TextButton {
147 public:
148 BookmarkButtonBase(views::ButtonListener* listener,
149 const string16& title)
150 : TextButton(listener, title) {
151 show_animation_.reset(new ui::SlideAnimation(this));
152 if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) {
153 // For some reason during testing the events generated by animating
154 // throw off the test. So, don't animate while testing.
155 show_animation_->Reset(1);
156 } else {
157 show_animation_->Show();
158 }
159 }
160
161 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE {
162 return e.type() == ui::ET_GESTURE_TAP ||
163 e.type() == ui::ET_GESTURE_TAP_DOWN ||
164 event_utils::IsPossibleDispositionEvent(e);
165 }
166
167 private:
168 scoped_ptr<ui::SlideAnimation> show_animation_;
169
170 DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase);
171 };
172
138 // BookmarkButton ------------------------------------------------------------- 173 // BookmarkButton -------------------------------------------------------------
139 174
140 // Buttons used for the bookmarks on the bookmark bar. 175 // Buttons used for the bookmarks on the bookmark bar.
141 176
142 class BookmarkButton : public views::TextButton { 177 class BookmarkButton : public BookmarkButtonBase {
143 public: 178 public:
144 // The internal view class name. 179 // The internal view class name.
145 static const char kViewClassName[]; 180 static const char kViewClassName[];
146 181
147 BookmarkButton(views::ButtonListener* listener, 182 BookmarkButton(views::ButtonListener* listener,
148 const GURL& url, 183 const GURL& url,
149 const string16& title, 184 const string16& title,
150 Profile* profile) 185 Profile* profile)
151 : TextButton(listener, title), 186 : BookmarkButtonBase(listener, title),
152 url_(url), 187 url_(url),
153 profile_(profile) { 188 profile_(profile) {
154 show_animation_.reset(new ui::SlideAnimation(this));
155 if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) {
156 // For some reason during testing the events generated by animating
157 // throw off the test. So, don't animate while testing.
158 show_animation_->Reset(1);
159 } else {
160 show_animation_->Show();
161 }
162 } 189 }
163 190
164 virtual bool GetTooltipText(const gfx::Point& p, 191 virtual bool GetTooltipText(const gfx::Point& p,
165 string16* tooltip) const OVERRIDE { 192 string16* tooltip) const OVERRIDE {
166 gfx::Point location(p); 193 gfx::Point location(p);
167 ConvertPointToScreen(this, &location); 194 ConvertPointToScreen(this, &location);
168 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( 195 *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle(
169 location, url_, text(), profile_, GetWidget()->GetNativeView()); 196 location, url_, text(), profile_, GetWidget()->GetNativeView());
170 return !tooltip->empty(); 197 return !tooltip->empty();
171 } 198 }
172 199
173 virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE {
174 return e.type() == ui::ET_GESTURE_TAP ||
175 e.type() == ui::ET_GESTURE_TAP_DOWN ||
176 event_utils::IsPossibleDispositionEvent(e);
177 }
178
179 virtual std::string GetClassName() const OVERRIDE { 200 virtual std::string GetClassName() const OVERRIDE {
180 return kViewClassName; 201 return kViewClassName;
181 } 202 }
182 203
183 private: 204 private:
184 const GURL& url_; 205 const GURL& url_;
185 Profile* profile_; 206 Profile* profile_;
186 scoped_ptr<ui::SlideAnimation> show_animation_;
187 207
188 DISALLOW_COPY_AND_ASSIGN(BookmarkButton); 208 DISALLOW_COPY_AND_ASSIGN(BookmarkButton);
189 }; 209 };
190 210
191 // static for BookmarkButton 211 // static for BookmarkButton
192 const char BookmarkButton::kViewClassName[] = 212 const char BookmarkButton::kViewClassName[] =
193 "browser/ui/views/bookmarks/BookmarkButton"; 213 "browser/ui/views/bookmarks/BookmarkButton";
194 214
215 // ShortcutButton -------------------------------------------------------------
216
217 // Buttons used for the shortcuts on the bookmark bar.
218
219 class ShortcutButton : public BookmarkButtonBase {
220 public:
221 // The internal view class name.
222 static const char kViewClassName[];
223
224 ShortcutButton(views::ButtonListener* listener,
225 const string16& title)
226 : BookmarkButtonBase(listener, title) {
227 }
228
229 virtual std::string GetClassName() const OVERRIDE {
230 return kViewClassName;
231 }
232
233 private:
234 scoped_ptr<ui::SlideAnimation> show_animation_;
235
236 DISALLOW_COPY_AND_ASSIGN(ShortcutButton);
237 };
238
239 // static for ShortcutButton
240 const char ShortcutButton::kViewClassName[] =
241 "browser/ui/views/bookmarks/ShortcutButton";
242
195 // BookmarkFolderButton ------------------------------------------------------- 243 // BookmarkFolderButton -------------------------------------------------------
196 244
197 // Buttons used for folders on the bookmark bar, including the 'other folders' 245 // Buttons used for folders on the bookmark bar, including the 'other folders'
198 // button. 246 // button.
199 class BookmarkFolderButton : public views::MenuButton { 247 class BookmarkFolderButton : public views::MenuButton {
200 public: 248 public:
201 BookmarkFolderButton(views::ButtonListener* listener, 249 BookmarkFolderButton(views::ButtonListener* listener,
202 const string16& title, 250 const string16& title,
203 views::MenuButtonListener* menu_button_listener, 251 views::MenuButtonListener* menu_button_listener,
204 bool show_menu_marker) 252 bool show_menu_marker)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 423 }
376 return *kFolderIcon; 424 return *kFolderIcon;
377 } 425 }
378 426
379 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) 427 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
380 : page_navigator_(NULL), 428 : page_navigator_(NULL),
381 model_(NULL), 429 model_(NULL),
382 bookmark_menu_(NULL), 430 bookmark_menu_(NULL),
383 bookmark_drop_menu_(NULL), 431 bookmark_drop_menu_(NULL),
384 other_bookmarked_button_(NULL), 432 other_bookmarked_button_(NULL),
433 apps_page_shortcut_(NULL),
385 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), 434 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)),
386 overflow_button_(NULL), 435 overflow_button_(NULL),
387 instructions_(NULL), 436 instructions_(NULL),
388 bookmarks_separator_view_(NULL), 437 bookmarks_separator_view_(NULL),
389 browser_(browser), 438 browser_(browser),
390 browser_view_(browser_view), 439 browser_view_(browser_view),
391 infobar_visible_(false), 440 infobar_visible_(false),
392 throbbing_view_(NULL), 441 throbbing_view_(NULL),
393 bookmark_bar_state_(BookmarkBar::SHOW), 442 bookmark_bar_state_(BookmarkBar::SHOW),
394 animating_detached_(false) { 443 animating_detached_(false) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 // The minimum width of the bookmark bar should at least contain the overflow 644 // The minimum width of the bookmark bar should at least contain the overflow
596 // button, by which one can access all the Bookmark Bar items, and the "Other 645 // button, by which one can access all the Bookmark Bar items, and the "Other
597 // Bookmarks" folder, along with appropriate margins and button padding. 646 // Bookmarks" folder, along with appropriate margins and button padding.
598 int width = kLeftMargin; 647 int width = kLeftMargin;
599 648
600 if (bookmark_bar_state_ == BookmarkBar::DETACHED) { 649 if (bookmark_bar_state_ == BookmarkBar::DETACHED) {
601 double current_state = 1 - size_animation_->GetCurrentValue(); 650 double current_state = 1 - size_animation_->GetCurrentValue();
602 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state); 651 width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state);
603 } 652 }
604 653
605 gfx::Size other_bookmarked_pref = 654 gfx::Size other_bookmarked_pref;
606 other_bookmarked_button_->GetPreferredSize(); 655 if (other_bookmarked_button_->visible())
607 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 656 other_bookmarked_pref = other_bookmarked_button_->GetPreferredSize();
608 gfx::Size bookmarks_separator_pref = 657 gfx::Size overflow_pref;
609 bookmarks_separator_view_->GetPreferredSize(); 658 if (overflow_button_->visible())
659 overflow_pref = overflow_button_->GetPreferredSize();
660 gfx::Size bookmarks_separator_pref;
661 if (bookmarks_separator_view_->visible())
662 bookmarks_separator_pref = bookmarks_separator_view_->GetPreferredSize();
663 gfx::Size apps_page_shortcut_pref;
664 if (apps_page_shortcut_->visible())
665 apps_page_shortcut_pref = apps_page_shortcut_->GetPreferredSize();
610 666
611 width += other_bookmarked_pref.width() + kButtonPadding + 667 width += other_bookmarked_pref.width() + kButtonPadding +
668 apps_page_shortcut_pref.width() + kButtonPadding +
612 overflow_pref.width() + kButtonPadding + 669 overflow_pref.width() + kButtonPadding +
613 bookmarks_separator_pref.width(); 670 bookmarks_separator_pref.width();
614 671
615 return gfx::Size(width, browser_defaults::kBookmarkBarHeight); 672 return gfx::Size(width, browser_defaults::kBookmarkBarHeight);
616 } 673 }
617 674
618 void BookmarkBarView::Layout() { 675 void BookmarkBarView::Layout() {
619 LayoutItems(false); 676 LayoutItems(false);
620 } 677 }
621 678
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 } 1098 }
1042 1099
1043 bookmark_menu_ = new BookmarkMenuController(browser_, 1100 bookmark_menu_ = new BookmarkMenuController(browser_,
1044 page_navigator_, GetWidget(), node, start_index); 1101 page_navigator_, GetWidget(), node, start_index);
1045 bookmark_menu_->set_observer(this); 1102 bookmark_menu_->set_observer(this);
1046 bookmark_menu_->RunMenuAt(this, false); 1103 bookmark_menu_->RunMenuAt(this, false);
1047 } 1104 }
1048 1105
1049 void BookmarkBarView::ButtonPressed(views::Button* sender, 1106 void BookmarkBarView::ButtonPressed(views::Button* sender,
1050 const ui::Event& event) { 1107 const ui::Event& event) {
1108 if (sender->tag() == kAppsShortcutButtonTag) {
1109 chrome::ShowAppLauncherPage(browser_);
1110 content::RecordAction(
1111 UserMetricsAction("ClickedBookmarkBarAppsShortcutButton"));
1112 return;
1113 }
1114
1051 const BookmarkNode* node; 1115 const BookmarkNode* node;
1052 if (sender->tag() == kOtherFolderButtonTag) { 1116 if (sender->tag() == kOtherFolderButtonTag) {
1053 node = model_->other_node(); 1117 node = model_->other_node();
1054 } else { 1118 } else {
1055 int index = GetIndexOf(sender); 1119 int index = GetIndexOf(sender);
1056 DCHECK_NE(-1, index); 1120 DCHECK_NE(-1, index);
1057 node = model_->bookmark_bar_node()->GetChild(index); 1121 node = model_->bookmark_bar_node()->GetChild(index);
1058 } 1122 }
1059 DCHECK(page_navigator_); 1123 DCHECK(page_navigator_);
1060 1124
(...skipping 22 matching lines...) Expand all
1083 if (!model_->IsLoaded()) { 1147 if (!model_->IsLoaded()) {
1084 // Don't do anything if the model isn't loaded. 1148 // Don't do anything if the model isn't loaded.
1085 return; 1149 return;
1086 } 1150 }
1087 1151
1088 const BookmarkNode* parent = NULL; 1152 const BookmarkNode* parent = NULL;
1089 std::vector<const BookmarkNode*> nodes; 1153 std::vector<const BookmarkNode*> nodes;
1090 if (source == other_bookmarked_button_) { 1154 if (source == other_bookmarked_button_) {
1091 parent = model_->other_node(); 1155 parent = model_->other_node();
1092 // Do this so the user can open all bookmarks. BookmarkContextMenu makes 1156 // Do this so the user can open all bookmarks. BookmarkContextMenu makes
1093 // sure the user can edit/delete the node in this case. 1157 // sure the user can't edit/delete the node in this case.
1094 nodes.push_back(parent); 1158 nodes.push_back(parent);
1095 } else if (source != this) { 1159 } else if (source != this && source != apps_page_shortcut_) {
1096 // User clicked on one of the bookmark buttons, find which one they 1160 // User clicked on one of the bookmark buttons, find which one they
1097 // clicked on. 1161 // clicked on, except for the apps page shortcut, which must behave as if
1162 // the user clicked on the bookmark bar background.
1098 int bookmark_button_index = GetIndexOf(source); 1163 int bookmark_button_index = GetIndexOf(source);
1099 DCHECK(bookmark_button_index != -1 && 1164 DCHECK(bookmark_button_index != -1 &&
1100 bookmark_button_index < GetBookmarkButtonCount()); 1165 bookmark_button_index < GetBookmarkButtonCount());
1101 const BookmarkNode* node = 1166 const BookmarkNode* node =
1102 model_->bookmark_bar_node()->GetChild(bookmark_button_index); 1167 model_->bookmark_bar_node()->GetChild(bookmark_button_index);
1103 nodes.push_back(node); 1168 nodes.push_back(node);
1104 parent = node->parent(); 1169 parent = node->parent();
1105 } else { 1170 } else {
1106 parent = model_->bookmark_bar_node(); 1171 parent = model_->bookmark_bar_node();
1107 nodes.push_back(parent); 1172 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 1196 // Child views are traversed in the order they are added. Make sure the order
1132 // they are added matches the visual order. 1197 // they are added matches the visual order.
1133 overflow_button_ = CreateOverflowButton(); 1198 overflow_button_ = CreateOverflowButton();
1134 AddChildView(overflow_button_); 1199 AddChildView(overflow_button_);
1135 1200
1136 other_bookmarked_button_ = CreateOtherBookmarkedButton(); 1201 other_bookmarked_button_ = CreateOtherBookmarkedButton();
1137 // We'll re-enable when the model is loaded. 1202 // We'll re-enable when the model is loaded.
1138 other_bookmarked_button_->SetEnabled(false); 1203 other_bookmarked_button_->SetEnabled(false);
1139 AddChildView(other_bookmarked_button_); 1204 AddChildView(other_bookmarked_button_);
1140 1205
1206 apps_page_shortcut_ = CreateAppsPageShortcutButton();
1207 AddChildView(apps_page_shortcut_);
1208 profile_pref_registrar_.Init(browser_->profile()->GetPrefs());
1209 profile_pref_registrar_.Add(
1210 prefs::kShowAppsShortcutInBookmarkBar,
1211 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityChanged,
1212 base::Unretained(this)));
1213 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut());
1214
1141 bookmarks_separator_view_ = new ButtonSeparatorView(); 1215 bookmarks_separator_view_ = new ButtonSeparatorView();
1142 AddChildView(bookmarks_separator_view_); 1216 AddChildView(bookmarks_separator_view_);
1143 #if defined(USE_ASH) 1217 #if defined(USE_ASH)
1144 // Ash does not paint the bookmarks separator line because it looks odd on 1218 // 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. 1219 // the flat background. We keep it present for layout, but don't draw it.
1146 bookmarks_separator_view_->SetVisible(false); 1220 bookmarks_separator_view_->SetVisible(false);
1147 #endif 1221 #endif
1148 1222
1149 instructions_ = new BookmarkBarInstructionsView(this); 1223 instructions_ = new BookmarkBarInstructionsView(this);
1150 AddChildView(instructions_); 1224 AddChildView(instructions_);
1151 1225
1152 set_context_menu_controller(this); 1226 set_context_menu_controller(this);
1153 1227
1154 size_animation_.reset(new ui::SlideAnimation(this)); 1228 size_animation_.reset(new ui::SlideAnimation(this));
1155 1229
1156 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); 1230 model_ = BookmarkModelFactory::GetForProfile(browser_->profile());
1157 if (model_) { 1231 if (model_) {
1158 model_->AddObserver(this); 1232 model_->AddObserver(this);
1159 if (model_->IsLoaded()) 1233 if (model_->IsLoaded())
1160 Loaded(model_, false); 1234 Loaded(model_, false);
1161 // else case: we'll receive notification back from the BookmarkModel when 1235 // else case: we'll receive notification back from the BookmarkModel when
1162 // done loading, then we'll populate the bar. 1236 // done loading, then we'll populate the bar.
1163 } 1237 }
1164 } 1238 }
1165 1239
1166 int BookmarkBarView::GetBookmarkButtonCount() { 1240 int BookmarkBarView::GetBookmarkButtonCount() {
1167 // We contain four non-bookmark button views: other bookmarks, bookmarks 1241 // We contain four non-bookmark button views: other bookmarks, bookmarks
1168 // separator, chevrons (for overflow), and the instruction label. 1242 // separator, chevrons (for overflow), apps page, and the instruction label.
1169 return child_count() - 4; 1243 return child_count() - 5;
1170 } 1244 }
1171 1245
1172 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { 1246 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) {
1173 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); 1247 DCHECK(index >= 0 && index < GetBookmarkButtonCount());
1174 return static_cast<views::TextButton*>(child_at(index)); 1248 return static_cast<views::TextButton*>(child_at(index));
1175 } 1249 }
1176 1250
1177 int BookmarkBarView::GetFirstHiddenNodeIndex() { 1251 int BookmarkBarView::GetFirstHiddenNodeIndex() {
1178 const int bb_count = GetBookmarkButtonCount(); 1252 const int bb_count = GetBookmarkButtonCount();
1179 for (int i = 0; i < bb_count; ++i) { 1253 for (int i = 0; i < bb_count; ++i) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 return button; 1297 return button;
1224 } else { 1298 } else {
1225 views::MenuButton* button = new BookmarkFolderButton( 1299 views::MenuButton* button = new BookmarkFolderButton(
1226 this, node->GetTitle(), this, false); 1300 this, node->GetTitle(), this, false);
1227 button->SetIcon(GetFolderIcon()); 1301 button->SetIcon(GetFolderIcon());
1228 ConfigureButton(node, button); 1302 ConfigureButton(node, button);
1229 return button; 1303 return button;
1230 } 1304 }
1231 } 1305 }
1232 1306
1307 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() {
1308 views::TextButton* button = new ShortcutButton(
1309 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME));
1310 button->SetTooltipText(l10n_util::GetStringUTF16(
1311 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP));
1312 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1313 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1314 button->SetIcon(*rb.GetImageSkiaNamed(IDR_WEBSTORE_ICON_16));
1315 button->set_context_menu_controller(this);
1316 button->set_tag(kAppsShortcutButtonTag);
1317 button->SetEnabled(true);
sky 2013/02/28 21:50:31 Enabled is this default.
beaudoin 2013/03/04 23:30:14 Done.
1318 return button;
1319 }
1320
1233 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, 1321 void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
1234 views::TextButton* button) { 1322 views::TextButton* button) {
1235 button->SetText(node->GetTitle()); 1323 button->SetText(node->GetTitle());
1236 button->SetAccessibleName(node->GetTitle()); 1324 button->SetAccessibleName(node->GetTitle());
1237 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); 1325 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1238 // We don't always have a theme provider (ui tests, for example). 1326 // We don't always have a theme provider (ui tests, for example).
1239 if (GetThemeProvider()) { 1327 if (GetThemeProvider()) {
1240 button->SetEnabledColor(GetThemeProvider()->GetColor( 1328 button->SetEnabledColor(GetThemeProvider()->GetColor(
1241 ThemeProperties::COLOR_BOOKMARK_TEXT)); 1329 ThemeProperties::COLOR_BOOKMARK_TEXT));
1242 } 1330 }
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 GetBookmarkButton(i)->SetEnabledColor(text_color); 1626 GetBookmarkButton(i)->SetEnabledColor(text_color);
1539 other_bookmarked_button()->SetEnabledColor(text_color); 1627 other_bookmarked_button()->SetEnabledColor(text_color);
1540 } 1628 }
1541 1629
1542 void BookmarkBarView::UpdateOtherBookmarksVisibility() { 1630 void BookmarkBarView::UpdateOtherBookmarksVisibility() {
1543 bool has_other_children = !model_->other_node()->empty(); 1631 bool has_other_children = !model_->other_node()->empty();
1544 if (has_other_children == other_bookmarked_button_->visible()) 1632 if (has_other_children == other_bookmarked_button_->visible())
1545 return; 1633 return;
1546 other_bookmarked_button_->SetVisible(has_other_children); 1634 other_bookmarked_button_->SetVisible(has_other_children);
1547 #if !defined(USE_ASH) 1635 #if !defined(USE_ASH)
1548 bookmarks_separator_view_->SetVisible(has_other_children); 1636 bookmarks_separator_view_->SetVisible(has_other_children);
sky 2013/02/28 21:50:31 Shouldn't the visibility of the separator view be
beaudoin 2013/03/04 23:30:14 Extracted it to its own method since its visibilit
1549 #endif 1637 #endif
1550 Layout(); 1638 Layout();
1551 SchedulePaint(); 1639 SchedulePaint();
1552 } 1640 }
1553 1641
1554 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { 1642 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) {
1555 gfx::Size prefsize; 1643 gfx::Size prefsize;
1556 if (!parent() && !compute_bounds_only) 1644 if (!parent() && !compute_bounds_only)
1557 return prefsize; 1645 return prefsize;
1558 1646
(...skipping 18 matching lines...) Expand all
1577 // also matches how we layout infobars. 1665 // also matches how we layout infobars.
1578 y += View::height() - browser_defaults::kBookmarkBarHeight; 1666 y += View::height() - browser_defaults::kBookmarkBarHeight;
1579 height += browser_defaults::kBookmarkBarHeight; 1667 height += browser_defaults::kBookmarkBarHeight;
1580 } 1668 }
1581 1669
1582 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? 1670 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ?
1583 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); 1671 other_bookmarked_button_->GetPreferredSize() : gfx::Size();
1584 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); 1672 gfx::Size overflow_pref = overflow_button_->GetPreferredSize();
1585 gfx::Size bookmarks_separator_pref = 1673 gfx::Size bookmarks_separator_pref =
1586 bookmarks_separator_view_->GetPreferredSize(); 1674 bookmarks_separator_view_->GetPreferredSize();
1675 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ?
1676 apps_page_shortcut_->GetPreferredSize() : gfx::Size();
1587 1677
1588 int max_x = width - overflow_pref.width() - kButtonPadding - 1678 int max_x = width - overflow_pref.width() - kButtonPadding -
1589 bookmarks_separator_pref.width(); 1679 bookmarks_separator_pref.width();
1590 if (other_bookmarked_button_->visible()) 1680 if (other_bookmarked_button_->visible())
1591 max_x -= other_bookmarked_pref.width() + kButtonPadding; 1681 max_x -= other_bookmarked_pref.width() + kButtonPadding;
1682 if (apps_page_shortcut_->visible())
1683 max_x -= apps_page_shortcut_pref.width() + kButtonPadding;
1592 1684
1593 // Next, layout out the buttons. Any buttons that are placed beyond the 1685 // Next, layout out the buttons. Any buttons that are placed beyond the
1594 // visible region and made invisible. 1686 // visible region and made invisible.
1595 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { 1687 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) {
1596 gfx::Size pref = instructions_->GetPreferredSize(); 1688 gfx::Size pref = instructions_->GetPreferredSize();
1597 if (!compute_bounds_only) { 1689 if (!compute_bounds_only) {
1598 instructions_->SetBounds( 1690 instructions_->SetBounds(
1599 x + kInstructionsPadding, y, 1691 x + kInstructionsPadding, y,
1600 std::min(static_cast<int>(pref.width()), 1692 std::min(static_cast<int>(pref.width()),
1601 max_x - x), 1693 max_x - x),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 1742
1651 // The other bookmarks button. 1743 // The other bookmarks button.
1652 if (other_bookmarked_button_->visible()) { 1744 if (other_bookmarked_button_->visible()) {
1653 if (!compute_bounds_only) { 1745 if (!compute_bounds_only) {
1654 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), 1746 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(),
1655 height); 1747 height);
1656 } 1748 }
1657 x += other_bookmarked_pref.width() + kButtonPadding; 1749 x += other_bookmarked_pref.width() + kButtonPadding;
1658 } 1750 }
1659 1751
1752 // The app page shortcut button.
1753 if (apps_page_shortcut_->visible()) {
1754 if (!compute_bounds_only) {
1755 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(),
1756 height);
1757 }
1758 x += apps_page_shortcut_pref.width() + kButtonPadding;
1759 }
1760
1660 // Set the preferred size computed so far. 1761 // Set the preferred size computed so far.
1661 if (compute_bounds_only) { 1762 if (compute_bounds_only) {
1662 x += kRightMargin; 1763 x += kRightMargin;
1663 prefsize.set_width(x); 1764 prefsize.set_width(x);
1664 if (IsDetached()) { 1765 if (IsDetached()) {
1665 x += static_cast<int>( 1766 x += static_cast<int>(
1666 kNewtabHorizontalPadding * (1 - size_animation_->GetCurrentValue())); 1767 kNewtabHorizontalPadding * (1 - size_animation_->GetCurrentValue()));
1667 prefsize.set_height( 1768 prefsize.set_height(
1668 browser_defaults::kBookmarkBarHeight + 1769 browser_defaults::kBookmarkBarHeight +
1669 static_cast<int>( 1770 static_cast<int>(
1670 (chrome::kNTPBookmarkBarHeight - 1771 (chrome::kNTPBookmarkBarHeight -
1671 browser_defaults::kBookmarkBarHeight) * 1772 browser_defaults::kBookmarkBarHeight) *
1672 (1 - size_animation_->GetCurrentValue()))); 1773 (1 - size_animation_->GetCurrentValue())));
1673 } else { 1774 } else {
1674 prefsize.set_height( 1775 prefsize.set_height(
1675 static_cast<int>( 1776 static_cast<int>(
1676 browser_defaults::kBookmarkBarHeight * 1777 browser_defaults::kBookmarkBarHeight *
1677 size_animation_->GetCurrentValue())); 1778 size_animation_->GetCurrentValue()));
1678 } 1779 }
1679 } 1780 }
1680 return prefsize; 1781 return prefsize;
1681 } 1782 }
1783
1784 bool BookmarkBarView::ShouldShowAppsShortcut() const {
1785 return chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()) &&
1786 browser_->profile()->GetPrefs()->GetBoolean(
1787 prefs::kShowAppsShortcutInBookmarkBar);
1788 }
1789
1790 void BookmarkBarView::OnAppsPageShortcutVisibilityChanged() {
1791 DCHECK(apps_page_shortcut_);
1792 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut());
1793 Layout();
1794 }
1795
1796 bool BookmarkBarView::IsAppsShortcutVisibleForTesting() const {
1797 DCHECK(apps_page_shortcut_);
1798 return apps_page_shortcut_->visible();
1799 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698