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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm

Issue 12550006: Mac: Add a shortcut to open the Apps page from the bookmark bar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased 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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // Determine the nature of the bookmark bar contents based on the number of 207 // Determine the nature of the bookmark bar contents based on the number of
208 // buttons showing. If too many then show the off-the-side list, if none 208 // buttons showing. If too many then show the off-the-side list, if none
209 // then show the no items label. 209 // then show the no items label.
210 - (void)reconfigureBookmarkBar; 210 - (void)reconfigureBookmarkBar;
211 211
212 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu; 212 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu;
213 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu; 213 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu;
214 - (void)tagEmptyMenu:(NSMenu*)menu; 214 - (void)tagEmptyMenu:(NSMenu*)menu;
215 - (void)clearMenuTagMap; 215 - (void)clearMenuTagMap;
216 - (int)preferredHeight; 216 - (int)preferredHeight;
217 - (void)addNonBookmarkButtonsToView;
Alexei Svitkine (slow) 2013/03/11 14:31:04 Nit: Can you add all the new private methods you'r
beaudoin 2013/03/11 21:02:14 This section misses quite a few of the private met
218 - (void)addButtonsToView; 217 - (void)addButtonsToView;
219 - (void)centerNoItemsLabel; 218 - (void)centerNoItemsLabel;
220 - (void)watchForExitEvent:(BOOL)watch; 219 - (void)watchForExitEvent:(BOOL)watch;
221 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; 220 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate;
222 221
223 @end 222 @end
224 223
225 @implementation BookmarkBarController 224 @implementation BookmarkBarController
226 225
227 @synthesize currentState = currentState_; 226 @synthesize currentState = currentState_;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 return contextMenuController_.get(); 283 return contextMenuController_.get();
285 } 284 }
286 285
287 - (void)pulseBookmarkNotification:(NSNotification*)notification { 286 - (void)pulseBookmarkNotification:(NSNotification*)notification {
288 NSDictionary* dict = [notification userInfo]; 287 NSDictionary* dict = [notification userInfo];
289 const BookmarkNode* node = NULL; 288 const BookmarkNode* node = NULL;
290 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey]; 289 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey];
291 DCHECK(value); 290 DCHECK(value);
292 if (value) 291 if (value)
293 node = static_cast<const BookmarkNode*>([value pointerValue]); 292 node = static_cast<const BookmarkNode*>([value pointerValue]);
294 NSNumber* number = [dict 293 NSNumber* number = [dict objectForKey:bookmark_button::kBookmarkPulseFlagKey];
295 objectForKey:bookmark_button::kBookmarkPulseFlagKey];
296 DCHECK(number); 294 DCHECK(number);
297 BOOL doPulse = number ? [number boolValue] : NO; 295 BOOL doPulse = number ? [number boolValue] : NO;
298 296
299 // 3 cases: 297 // 3 cases:
300 // button on the bar: flash it 298 // button on the bar: flash it
301 // button in "other bookmarks" folder: flash other bookmarks 299 // button in "other bookmarks" folder: flash other bookmarks
302 // button in "off the side" folder: flash the chevron 300 // button in "off the side" folder: flash the chevron
303 for (BookmarkButton* button in [self buttons]) { 301 for (BookmarkButton* button in [self buttons]) {
304 if ([button bookmarkNode] == node) { 302 if ([button bookmarkNode] == node) {
305 [button setIsContinuousPulsing:doPulse]; 303 [button setIsContinuousPulsing:doPulse];
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 name:kWillEnterFullscreenNotification 389 name:kWillEnterFullscreenNotification
392 object:nil]; 390 object:nil];
393 [[NSNotificationCenter defaultCenter] 391 [[NSNotificationCenter defaultCenter]
394 addObserver:self 392 addObserver:self
395 selector:@selector(willEnterOrLeaveFullscreen:) 393 selector:@selector(willEnterOrLeaveFullscreen:)
396 name:kWillLeaveFullscreenNotification 394 name:kWillLeaveFullscreenNotification
397 object:nil]; 395 object:nil];
398 396
399 // Don't pass ourself along (as 'self') until our init is completely 397 // Don't pass ourself along (as 'self') until our init is completely
400 // done. Thus, this call is (almost) last. 398 // done. Thus, this call is (almost) last.
401 bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_)); 399 bridge_.reset(new BookmarkBarBridge(browser_->profile(), self,
400 bookmarkModel_));
402 } 401 }
403 402
404 // Called by our main view (a BookmarkBarView) when it gets moved to a 403 // Called by our main view (a BookmarkBarView) when it gets moved to a
405 // window. We perform operations which need to know the relevant 404 // window. We perform operations which need to know the relevant
406 // window (e.g. watch for a window close) so they can't be performed 405 // window (e.g. watch for a window close) so they can't be performed
407 // earlier (such as in awakeFromNib). 406 // earlier (such as in awakeFromNib).
408 - (void)viewDidMoveToWindow { 407 - (void)viewDidMoveToWindow {
409 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 408 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
410 409
411 // Remove any existing notifications before registering for new ones. 410 // Remove any existing notifications before registering for new ones.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 [buttonView_ setFrame:buttonViewFrame]; 470 [buttonView_ setFrame:buttonViewFrame];
472 } 471 }
473 472
474 // We don't change a preference; we only change visibility. Preference changing 473 // We don't change a preference; we only change visibility. Preference changing
475 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We 474 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We
476 // simply update based on what we're told. 475 // simply update based on what we're told.
477 - (void)updateVisibility { 476 - (void)updateVisibility {
478 [self showBookmarkBarWithAnimation:NO]; 477 [self showBookmarkBarWithAnimation:NO];
479 } 478 }
480 479
480 - (void)updateAppsPageShortcutButtonVisibility {
481 [self setAppsPageShortcutButtonVisibility];
482 [self reconfigureBookmarkBar];
483 }
484
481 - (void)updateHiddenState { 485 - (void)updateHiddenState {
482 BOOL oldHidden = [[self view] isHidden]; 486 BOOL oldHidden = [[self view] isHidden];
483 BOOL newHidden = ![self isVisible]; 487 BOOL newHidden = ![self isVisible];
484 if (oldHidden != newHidden) 488 if (oldHidden != newHidden)
485 [[self view] setHidden:newHidden]; 489 [[self view] setHidden:newHidden];
486 } 490 }
487 491
488 - (void)setBookmarkBarEnabled:(BOOL)enabled { 492 - (void)setBookmarkBarEnabled:(BOOL)enabled {
489 if (enabled != barIsEnabled_) { 493 if (enabled != barIsEnabled_) {
490 barIsEnabled_ = enabled; 494 barIsEnabled_ = enabled;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 DCHECK([[self view] isKindOfClass:[AnimatableView class]]); 707 DCHECK([[self view] isKindOfClass:[AnimatableView class]]);
704 return (AnimatableView*)[self view]; 708 return (AnimatableView*)[self view];
705 } 709 }
706 710
707 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation { 711 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation {
708 return currentState_ == BookmarkBar::DETACHED ? 712 return currentState_ == BookmarkBar::DETACHED ?
709 bookmark_utils::LAUNCH_DETACHED_BAR : 713 bookmark_utils::LAUNCH_DETACHED_BAR :
710 bookmark_utils::LAUNCH_ATTACHED_BAR; 714 bookmark_utils::LAUNCH_ATTACHED_BAR;
711 } 715 }
712 716
713 // Position the off-the-side chevron to the left of the otherBookmarks button, 717 // Position the right-side buttons including the off-the-side chevron.
714 // unless it's hidden in which case it's right aligned on top of it. 718 - (void)positionRightSideButtons {
715 - (void)positionOffTheSideButton { 719 int maxX = NSMaxX([[self buttonView] bounds]) -
716 NSRect frame = [offTheSideButton_ frame]; 720 bookmarks::kBookmarkHorizontalPadding;
721 int right = maxX;
722
723 int ignored = 0;
724 NSRect frame = [self frameForBookmarkButtonFromCell:
725 [appsPageShortcutButton_ cell] xOffset:&ignored];
726 if (![appsPageShortcutButton_ isHidden]) {
727 right -= NSWidth(frame);
728 frame.origin.x = right;
729 } else {
730 frame.origin.x = maxX - NSWidth(frame);
731 }
732 [appsPageShortcutButton_ setFrame:frame];
733
734 frame = [self frameForBookmarkButtonFromCell:
735 [otherBookmarksButton_ cell] xOffset:&ignored];
736 if (![otherBookmarksButton_ isHidden]) {
737 right -= NSWidth(frame);
738 frame.origin.x = right;
739 } else {
740 frame.origin.x = maxX - NSWidth(frame);
741 }
742 [otherBookmarksButton_ setFrame:frame];
743
744 frame = [offTheSideButton_ frame];
717 frame.size.height = bookmarks::kBookmarkFolderButtonHeight; 745 frame.size.height = bookmarks::kBookmarkFolderButtonHeight;
718 if (otherBookmarksButton_.get() && ![otherBookmarksButton_ isHidden]) { 746 right -= frame.size.width;
719 frame.origin.x = ([otherBookmarksButton_ frame].origin.x - 747 frame.origin.x = right;
720 (frame.size.width +
721 bookmarks::kBookmarkHorizontalPadding));
722 } else {
723 frame.origin.x = (NSMaxX([otherBookmarksButton_ frame]) - frame.size.width);
724 }
725 [offTheSideButton_ setFrame:frame]; 748 [offTheSideButton_ setFrame:frame];
726 } 749 }
727 750
728 // Configure the off-the-side button (e.g. specify the node range, 751 // Configure the off-the-side button (e.g. specify the node range,
729 // check if we should enable or disable it, etc). 752 // check if we should enable or disable it, etc).
730 - (void)configureOffTheSideButtonContentsAndVisibility { 753 - (void)configureOffTheSideButtonContentsAndVisibility {
731 // If deleting a button while off-the-side is open, buttons may be 754 // If deleting a button while off-the-side is open, buttons may be
732 // promoted from off-the-side to the bar. Accomodate. 755 // promoted from off-the-side to the bar. Accomodate.
733 if (folderController_ && 756 if (folderController_ &&
734 ([folderController_ parentButton] == offTheSideButton_)) { 757 ([folderController_ parentButton] == offTheSideButton_)) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } else { 1098 } else {
1076 // Make the button do something 1099 // Make the button do something
1077 [button setTarget:self]; 1100 [button setTarget:self];
1078 [button setAction:@selector(openBookmark:)]; 1101 [button setAction:@selector(openBookmark:)];
1079 if (node->is_url()) 1102 if (node->is_url())
1080 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]]; 1103 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]];
1081 } 1104 }
1082 return [[button.get() retain] autorelease]; 1105 return [[button.get() retain] autorelease];
1083 } 1106 }
1084 1107
1085 // Add non-bookmark buttons to the view. This includes the chevron
1086 // and the "other bookmarks" button. Technically "other bookmarks" is
1087 // a bookmark button but it is treated specially. Only needs to be
1088 // called when these buttons are new or when the bookmark bar is
1089 // cleared (e.g. on a loaded: call). Unlike addButtonsToView below,
1090 // we don't need to add/remove these dynamically in response to window
1091 // resize.
1092 - (void)addNonBookmarkButtonsToView {
1093 [buttonView_ addSubview:otherBookmarksButton_.get()];
1094 [buttonView_ addSubview:offTheSideButton_];
1095 }
1096
1097 // Add bookmark buttons to the view only if they are completely 1108 // Add bookmark buttons to the view only if they are completely
1098 // visible and don't overlap the "other bookmarks". Remove buttons 1109 // visible and don't overlap the "other bookmarks". Remove buttons
1099 // which are clipped. Called when building the bookmark bar the first time. 1110 // which are clipped. Called when building the bookmark bar the first time.
1100 - (void)addButtonsToView { 1111 - (void)addButtonsToView {
1101 displayedButtonCount_ = 0; 1112 displayedButtonCount_ = 0;
1102 NSMutableArray* buttons = [self buttons]; 1113 NSMutableArray* buttons = [self buttons];
1103 for (NSButton* button in buttons) { 1114 for (NSButton* button in buttons) {
1104 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - 1115 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) -
1105 bookmarks::kBookmarkHorizontalPadding)) 1116 bookmarks::kBookmarkHorizontalPadding))
1106 break; 1117 break;
(...skipping 12 matching lines...) Expand all
1119 // whether it ended up visible. 1130 // whether it ended up visible.
1120 - (BOOL)setOtherBookmarksButtonVisibility { 1131 - (BOOL)setOtherBookmarksButtonVisibility {
1121 if (!otherBookmarksButton_.get()) 1132 if (!otherBookmarksButton_.get())
1122 return NO; 1133 return NO;
1123 1134
1124 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); 1135 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty();
1125 [otherBookmarksButton_ setHidden:!visible]; 1136 [otherBookmarksButton_ setHidden:!visible];
1126 return visible; 1137 return visible;
1127 } 1138 }
1128 1139
1129 // Create the button for "Other Bookmarks" on the right of the bar. 1140 // Shows or hides the Apps button as appropriate, and returns whether it ended
1141 // up visible.
1142 - (BOOL)setAppsPageShortcutButtonVisibility {
1143 if (!appsPageShortcutButton_.get())
1144 return NO;
1145
1146 BOOL visible = bookmarkModel_->IsLoaded() &&
1147 chrome::search::IsInstantExtendedAPIEnabled() &&
1148 browser_->profile()->GetPrefs()->GetBoolean(
1149 prefs::kShowAppsShortcutInBookmarkBar);
1150 [appsPageShortcutButton_ setHidden:!visible];
1151 return visible;
1152 }
1153
1154 // Creates a bookmark bar button that does not correspond to a regular bookmark
1155 // or folder. It is used by the "Other Bookmarks" and the "Apps" buttons.
1156 - (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell {
Alexei Svitkine (slow) 2013/03/11 14:31:04 Nit: This doesn't actually follow the Cocoa create
beaudoin 2013/03/11 21:02:14 Done.
1157 BookmarkButton* button = [[BookmarkButton alloc] init];
1158 [[button draggableButton] setDraggable:NO];
1159 [[button draggableButton] setActsOnMouseDown:YES];
1160 // Peg at right; keep same height as bar.
1161 [button setAutoresizingMask:(NSViewMinXMargin)];
1162 [button setCell:cell];
1163 [button setDelegate:self];
1164 [button setTarget:self];
1165 // Make sure this button, like all other BookmarkButtons, lives
1166 // until the end of the current event loop.
1167 [[button retain] autorelease];
1168 return button;
1169 }
1170
1171 // Creates the button for "Other Bookmarks", but does not position it.
1130 - (void)createOtherBookmarksButton { 1172 - (void)createOtherBookmarksButton {
1131 // Can't create this until the model is loaded, but only need to 1173 // Can't create this until the model is loaded, but only need to
1132 // create it once. 1174 // create it once.
1133 if (otherBookmarksButton_.get()) { 1175 if (otherBookmarksButton_.get()) {
1134 [self setOtherBookmarksButtonVisibility]; 1176 [self setOtherBookmarksButtonVisibility];
1135 return; 1177 return;
1136 } 1178 }
1137 1179
1138 // TODO(jrg): remove duplicate code
1139 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; 1180 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()];
1140 int ignored = 0; 1181 otherBookmarksButton_.reset([self createCustomBookmarkButtonForCell:cell]);
1141 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&ignored]; 1182 [otherBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)];
1142 frame.origin.x = [[self buttonView] bounds].size.width - frame.size.width; 1183 view_id_util::SetID(otherBookmarksButton_.get(), VIEW_ID_OTHER_BOOKMARKS);
1143 frame.origin.x -= bookmarks::kBookmarkHorizontalPadding; 1184 [buttonView_ addSubview:otherBookmarksButton_.get()];
1144 BookmarkButton* button = [[BookmarkButton alloc] initWithFrame:frame];
1145 [[button draggableButton] setDraggable:NO];
1146 [[button draggableButton] setActsOnMouseDown:YES];
1147 otherBookmarksButton_.reset(button);
1148 view_id_util::SetID(button, VIEW_ID_OTHER_BOOKMARKS);
1149
1150 // Make sure this button, like all other BookmarkButtons, lives
1151 // until the end of the current event loop.
1152 [[button retain] autorelease];
1153
1154 // Peg at right; keep same height as bar.
1155 [button setAutoresizingMask:(NSViewMinXMargin)];
1156 [button setCell:cell];
1157 [button setDelegate:self];
1158 [button setTarget:self];
1159 [button setAction:@selector(openBookmarkFolderFromButton:)];
1160 [buttonView_ addSubview:button];
1161 1185
1162 [self setOtherBookmarksButtonVisibility]; 1186 [self setOtherBookmarksButtonVisibility];
1187 }
1163 1188
1164 // Now that it's here, move the chevron over. 1189 // Creates the button for "Apps", but does not position it.
1165 [self positionOffTheSideButton]; 1190 - (void)createAppsPageShortcutButton {
1191 // Can't create this until the model is loaded, but only need to
1192 // create it once.
1193 if (appsPageShortcutButton_.get()) {
1194 [self setAppsPageShortcutButtonVisibility];
1195 return;
1196 }
1197
1198 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1199 NSString* text = l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME);
1200 NSImage* image = rb.GetNativeImageNamed(IDR_WEBSTORE_ICON_16).ToNSImage();
1201 NSCell* cell = [self cellForCustomButton:text
1202 withImage:image];
1203 appsPageShortcutButton_.reset([self createCustomBookmarkButtonForCell:cell]);
1204 [appsPageShortcutButton_ setAction:@selector(openAppsPage:)];
1205 NSString* tooltip =
1206 l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP);
1207 [appsPageShortcutButton_ setToolTip:tooltip];
1208 [buttonView_ addSubview:appsPageShortcutButton_.get()];
1209
1210 [self setAppsPageShortcutButtonVisibility];
1211 }
1212
1213 - (IBAction)openAppsPage:(id)sender {
Alexei Svitkine (slow) 2013/03/11 14:31:04 Nit: This doesn't need to be an IBAction, change t
beaudoin 2013/03/11 21:02:14 Done.
1214 chrome::ShowAppLauncherPage(browser_);
1215 bookmark_utils::RecordAppsPageOpen([self bookmarkLaunchLocation]);
1166 } 1216 }
1167 1217
1168 // To avoid problems with sync, changes that may impact the current 1218 // To avoid problems with sync, changes that may impact the current
1169 // bookmark (e.g. deletion) make sure context menus are closed. This 1219 // bookmark (e.g. deletion) make sure context menus are closed. This
1170 // prevents deleting a node which no longer exists. 1220 // prevents deleting a node which no longer exists.
1171 - (void)cancelMenuTracking { 1221 - (void)cancelMenuTracking {
1172 [contextMenuController_ cancelTracking]; 1222 [contextMenuController_ cancelTracking];
1173 } 1223 }
1174 1224
1175 - (void)moveToState:(BookmarkBar::State)nextState 1225 - (void)moveToState:(BookmarkBar::State)nextState
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 } 1311 }
1262 1312
1263 // Delegate method for |AnimatableView| (a superclass of 1313 // Delegate method for |AnimatableView| (a superclass of
1264 // |BookmarkBarToolbarView|). 1314 // |BookmarkBarToolbarView|).
1265 - (void)animationDidEnd:(NSAnimation*)animation { 1315 - (void)animationDidEnd:(NSAnimation*)animation {
1266 [self finalizeState]; 1316 [self finalizeState];
1267 } 1317 }
1268 1318
1269 - (void)reconfigureBookmarkBar { 1319 - (void)reconfigureBookmarkBar {
1270 [self redistributeButtonsOnBarAsNeeded]; 1320 [self redistributeButtonsOnBarAsNeeded];
1271 [self positionOffTheSideButton]; 1321 [self positionRightSideButtons];
1272 [self configureOffTheSideButtonContentsAndVisibility]; 1322 [self configureOffTheSideButtonContentsAndVisibility];
1273 [self centerNoItemsLabel]; 1323 [self centerNoItemsLabel];
1274 } 1324 }
1275 1325
1276 // Determine if the given |view| can completely fit within the constraint of 1326 // Determine if the given |view| can completely fit within the constraint of
1277 // maximum x, given by |maxViewX|, and, if not, narrow the view up to a minimum 1327 // maximum x, given by |maxViewX|, and, if not, narrow the view up to a minimum
1278 // width. If the minimum width is not achievable then hide the view. Return YES 1328 // width. If the minimum width is not achievable then hide the view. Return YES
1279 // if the view was hidden. 1329 // if the view was hidden.
1280 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX { 1330 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX {
1281 BOOL wasHidden = NO; 1331 BOOL wasHidden = NO;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 1412
1363 // Calculates the final position of the last button in the bar. 1413 // Calculates the final position of the last button in the bar.
1364 // We can't just use [[self buttons] lastObject] frame] because the button 1414 // We can't just use [[self buttons] lastObject] frame] because the button
1365 // may be animating currently. 1415 // may be animating currently.
1366 - (NSRect)finalRectOfLastButton { 1416 - (NSRect)finalRectOfLastButton {
1367 return [self finalRectOfButton:[[self buttons] lastObject]]; 1417 return [self finalRectOfButton:[[self buttons] lastObject]];
1368 } 1418 }
1369 1419
1370 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { 1420 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible {
1371 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); 1421 CGFloat maxViewX = NSMaxX([buttonView_ bounds]);
1372 // If necessary, pull in the width to account for the Other Bookmarks button. 1422 // If necessary, pull in the width to account for the Other Bookmarks or Apps
1373 if ([self setOtherBookmarksButtonVisibility]) { 1423 // button.
1374 maxViewX = [otherBookmarksButton_.get() frame].origin.x - 1424 const BOOL otherButtonVisible = [self setOtherBookmarksButtonVisibility];
1425 const BOOL appsButtonVisible = [self setAppsPageShortcutButtonVisibility];
1426 if (otherButtonVisible || appsButtonVisible) {
1427 BookmarkButton* leftMostRightAlignedButton = otherButtonVisible ?
1428 otherBookmarksButton_.get() : appsPageShortcutButton_.get();
1429 maxViewX = [leftMostRightAlignedButton frame].origin.x -
1375 bookmarks::kBookmarkRightMargin; 1430 bookmarks::kBookmarkRightMargin;
1376 } 1431 }
1377 1432
1378 [self positionOffTheSideButton]; 1433 [self positionRightSideButtons];
1379 // If we're already overflowing, then we need to account for the chevron. 1434 // If we're already overflowing, then we need to account for the chevron.
1380 if (visible) { 1435 if (visible) {
1381 maxViewX = 1436 maxViewX =
1382 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; 1437 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin;
1383 } 1438 }
1384 1439
1385 return maxViewX; 1440 return maxViewX;
1386 } 1441 }
1387 1442
1388 - (void)redistributeButtonsOnBarAsNeeded { 1443 - (void)redistributeButtonsOnBarAsNeeded {
1389 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); 1444 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node();
1390 NSInteger barCount = node->child_count(); 1445 NSInteger barCount = node->child_count();
1391 1446
1392 // Determine the current maximum extent of the visible buttons. 1447 // Determine the current maximum extent of the visible buttons.
1393 [self positionOffTheSideButton]; 1448 [self positionRightSideButtons];
1394 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible: 1449 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:
1395 (barCount > displayedButtonCount_)]; 1450 (barCount > displayedButtonCount_)];
1396 1451
1397 // As a result of pasting or dragging, the bar may now have more buttons 1452 // As a result of pasting or dragging, the bar may now have more buttons
1398 // than will fit so remove any which overflow. They will be shown in 1453 // than will fit so remove any which overflow. They will be shown in
1399 // the off-the-side folder. 1454 // the off-the-side folder.
1400 while (displayedButtonCount_ > 0) { 1455 while (displayedButtonCount_ > 0) {
1401 BookmarkButton* button = [buttons_ lastObject]; 1456 BookmarkButton* button = [buttons_ lastObject];
1402 if (NSMaxX([self finalRectOfLastButton]) < maxViewX) 1457 if (NSMaxX([self finalRectOfLastButton]) < maxViewX)
1403 break; 1458 break;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 [pboard setString:@"" forType:NSStringPboardType]; 1549 [pboard setString:@"" forType:NSStringPboardType];
1495 } 1550 }
1496 1551
1497 // Return an autoreleased NSCell suitable for a bookmark button. 1552 // Return an autoreleased NSCell suitable for a bookmark button.
1498 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. 1553 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1499 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node { 1554 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node {
1500 NSImage* image = node ? [self faviconForNode:node] : nil; 1555 NSImage* image = node ? [self faviconForNode:node] : nil;
1501 BookmarkButtonCell* cell = 1556 BookmarkButtonCell* cell =
1502 [BookmarkButtonCell buttonCellForNode:node 1557 [BookmarkButtonCell buttonCellForNode:node
1503 menuController:contextMenuController_ 1558 menuController:contextMenuController_
1504 cellText:nil 1559 text:nil
1505 cellImage:image]; 1560 image:image];
1506 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; 1561 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1507 1562
1508 // Note: a quirk of setting a cell's text color is that it won't work 1563 // Note: a quirk of setting a cell's text color is that it won't work
1564 // until the cell is associated with a button, so we can't theme the cell yet.
1565
1566 return cell;
1567 }
1568
1569 // Return an autoreleased NSCell suitable for a special button displayed on the
1570 // bookmark bar that is not attached to any bookmark node.
1571 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1572 - (BookmarkButtonCell*)cellForCustomButton:(NSString*)text
Alexei Svitkine (slow) 2013/03/11 14:31:04 Nit: rename to -cellForCustomButtonWithText:image:
beaudoin 2013/03/11 21:02:14 Done.
1573 withImage:(NSImage*)image {
1574 BookmarkButtonCell* cell =
1575 [BookmarkButtonCell buttonCellWithMenuController:contextMenuController_
1576 text:text
1577 image:image];
1578 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1579
1580 // Note: a quirk of setting a cell's text color is that it won't work
1509 // until the cell is associated with a button, so we can't theme the cell yet. 1581 // until the cell is associated with a button, so we can't theme the cell yet.
1510 1582
1511 return cell; 1583 return cell;
1512 } 1584 }
1513 1585
1514 // Returns a frame appropriate for the given bookmark cell, suitable 1586 // Returns a frame appropriate for the given bookmark cell, suitable
1515 // for creating an NSButton that will contain it. |xOffset| is the X 1587 // for creating an NSButton that will contain it. |xOffset| is the X
1516 // offset for the frame; it is increased to be an appropriate X offset 1588 // offset for the frame; it is increased to be an appropriate X offset
1517 // for the next button. 1589 // for the next button.
1518 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell 1590 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 if (!themeProvider) 1660 if (!themeProvider)
1589 return; 1661 return;
1590 NSColor* color = 1662 NSColor* color =
1591 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT, 1663 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT,
1592 true); 1664 true);
1593 for (BookmarkButton* button in buttons_.get()) { 1665 for (BookmarkButton* button in buttons_.get()) {
1594 BookmarkButtonCell* cell = [button cell]; 1666 BookmarkButtonCell* cell = [button cell];
1595 [cell setTextColor:color]; 1667 [cell setTextColor:color];
1596 } 1668 }
1597 [[otherBookmarksButton_ cell] setTextColor:color]; 1669 [[otherBookmarksButton_ cell] setTextColor:color];
1670 [[appsPageShortcutButton_ cell] setTextColor:color];
1598 } 1671 }
1599 1672
1600 // Return YES if the event indicates an exit from the bookmark bar 1673 // Return YES if the event indicates an exit from the bookmark bar
1601 // folder menus. E.g. "click outside" of the area we are watching. 1674 // folder menus. E.g. "click outside" of the area we are watching.
1602 // At this time we are watching the area that includes all popup 1675 // At this time we are watching the area that includes all popup
1603 // bookmark folder windows. 1676 // bookmark folder windows.
1604 - (BOOL)isEventAnExitEvent:(NSEvent*)event { 1677 - (BOOL)isEventAnExitEvent:(NSEvent*)event {
1605 NSWindow* eventWindow = [event window]; 1678 NSWindow* eventWindow = [event window];
1606 NSWindow* myWindow = [[self view] window]; 1679 NSWindow* myWindow = [[self view] window];
1607 switch ([event type]) { 1680 switch ([event type]) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 // See: http://crbug.com/36614 1966 // See: http://crbug.com/36614
1894 if (folderController_) 1967 if (folderController_)
1895 [self closeAllBookmarkFolders]; 1968 [self closeAllBookmarkFolders];
1896 1969
1897 // Brute force nuke and build. 1970 // Brute force nuke and build.
1898 savedFrameWidth_ = NSWidth([[self view] frame]); 1971 savedFrameWidth_ = NSWidth([[self view] frame]);
1899 const BookmarkNode* node = model->bookmark_bar_node(); 1972 const BookmarkNode* node = model->bookmark_bar_node();
1900 [self clearBookmarkBar]; 1973 [self clearBookmarkBar];
1901 [self addNodesToButtonList:node]; 1974 [self addNodesToButtonList:node];
1902 [self createOtherBookmarksButton]; 1975 [self createOtherBookmarksButton];
1976 [self createAppsPageShortcutButton];
1903 [self updateTheme:[[[self view] window] themeProvider]]; 1977 [self updateTheme:[[[self view] window] themeProvider]];
1904 [self positionOffTheSideButton]; 1978 [self positionRightSideButtons];
1905 [self addNonBookmarkButtonsToView];
1906 [self addButtonsToView]; 1979 [self addButtonsToView];
1907 [self configureOffTheSideButtonContentsAndVisibility]; 1980 [self configureOffTheSideButtonContentsAndVisibility];
1908 [self reconfigureBookmarkBar]; 1981 [self reconfigureBookmarkBar];
1909 } 1982 }
1910 1983
1911 - (void)beingDeleted:(BookmarkModel*)model { 1984 - (void)beingDeleted:(BookmarkModel*)model {
1912 // The browser may be being torn down; little is safe to do. As an 1985 // The browser may be being torn down; little is safe to do. As an
1913 // example, it may not be safe to clear the pasteboard. 1986 // example, it may not be safe to clear the pasteboard.
1914 // http://crbug.com/38665 1987 // http://crbug.com/38665
1915 } 1988 }
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 - (id<BookmarkButtonControllerProtocol>)controllerForNode: 2616 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
2544 (const BookmarkNode*)node { 2617 (const BookmarkNode*)node {
2545 // See if it's in the bar, then if it is in the hierarchy of visible 2618 // See if it's in the bar, then if it is in the hierarchy of visible
2546 // folder menus. 2619 // folder menus.
2547 if (bookmarkModel_->bookmark_bar_node() == node) 2620 if (bookmarkModel_->bookmark_bar_node() == node)
2548 return self; 2621 return self;
2549 return [folderController_ controllerForNode:node]; 2622 return [folderController_ controllerForNode:node];
2550 } 2623 }
2551 2624
2552 @end 2625 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698