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

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: Minor typo. 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;
218 - (void)addButtonsToView; 217 - (void)addButtonsToView;
218 - (BOOL)setOtherBookmarksButtonVisibility;
219 - (BOOL)setAppsPageShortcutButtonVisibility;
220 - (BookmarkButton*)customBookmarkButtonForCell:(NSCell*)cell;
221 - (void)createOtherBookmarksButton;
222 - (void)createAppsPageShortcutButton;
223 - (void)openAppsPage:(id)sender;
219 - (void)centerNoItemsLabel; 224 - (void)centerNoItemsLabel;
225 - (void)positionRightSideButtons;
220 - (void)watchForExitEvent:(BOOL)watch; 226 - (void)watchForExitEvent:(BOOL)watch;
221 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; 227 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate;
222 228
223 @end 229 @end
224 230
225 @implementation BookmarkBarController 231 @implementation BookmarkBarController
226 232
227 @synthesize currentState = currentState_; 233 @synthesize currentState = currentState_;
228 @synthesize lastState = lastState_; 234 @synthesize lastState = lastState_;
229 @synthesize isAnimationRunning = isAnimationRunning_; 235 @synthesize isAnimationRunning = isAnimationRunning_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 return contextMenuController_.get(); 290 return contextMenuController_.get();
285 } 291 }
286 292
287 - (void)pulseBookmarkNotification:(NSNotification*)notification { 293 - (void)pulseBookmarkNotification:(NSNotification*)notification {
288 NSDictionary* dict = [notification userInfo]; 294 NSDictionary* dict = [notification userInfo];
289 const BookmarkNode* node = NULL; 295 const BookmarkNode* node = NULL;
290 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey]; 296 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey];
291 DCHECK(value); 297 DCHECK(value);
292 if (value) 298 if (value)
293 node = static_cast<const BookmarkNode*>([value pointerValue]); 299 node = static_cast<const BookmarkNode*>([value pointerValue]);
294 NSNumber* number = [dict 300 NSNumber* number = [dict objectForKey:bookmark_button::kBookmarkPulseFlagKey];
295 objectForKey:bookmark_button::kBookmarkPulseFlagKey];
296 DCHECK(number); 301 DCHECK(number);
297 BOOL doPulse = number ? [number boolValue] : NO; 302 BOOL doPulse = number ? [number boolValue] : NO;
298 303
299 // 3 cases: 304 // 3 cases:
300 // button on the bar: flash it 305 // button on the bar: flash it
301 // button in "other bookmarks" folder: flash other bookmarks 306 // button in "other bookmarks" folder: flash other bookmarks
302 // button in "off the side" folder: flash the chevron 307 // button in "off the side" folder: flash the chevron
303 for (BookmarkButton* button in [self buttons]) { 308 for (BookmarkButton* button in [self buttons]) {
304 if ([button bookmarkNode] == node) { 309 if ([button bookmarkNode] == node) {
305 [button setIsContinuousPulsing:doPulse]; 310 [button setIsContinuousPulsing:doPulse];
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 name:kWillEnterFullscreenNotification 396 name:kWillEnterFullscreenNotification
392 object:nil]; 397 object:nil];
393 [[NSNotificationCenter defaultCenter] 398 [[NSNotificationCenter defaultCenter]
394 addObserver:self 399 addObserver:self
395 selector:@selector(willEnterOrLeaveFullscreen:) 400 selector:@selector(willEnterOrLeaveFullscreen:)
396 name:kWillLeaveFullscreenNotification 401 name:kWillLeaveFullscreenNotification
397 object:nil]; 402 object:nil];
398 403
399 // Don't pass ourself along (as 'self') until our init is completely 404 // Don't pass ourself along (as 'self') until our init is completely
400 // done. Thus, this call is (almost) last. 405 // done. Thus, this call is (almost) last.
401 bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_)); 406 bridge_.reset(new BookmarkBarBridge(browser_->profile(), self,
407 bookmarkModel_));
402 } 408 }
403 409
404 // Called by our main view (a BookmarkBarView) when it gets moved to a 410 // Called by our main view (a BookmarkBarView) when it gets moved to a
405 // window. We perform operations which need to know the relevant 411 // 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 412 // window (e.g. watch for a window close) so they can't be performed
407 // earlier (such as in awakeFromNib). 413 // earlier (such as in awakeFromNib).
408 - (void)viewDidMoveToWindow { 414 - (void)viewDidMoveToWindow {
409 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 415 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
410 416
411 // Remove any existing notifications before registering for new ones. 417 // 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]; 477 [buttonView_ setFrame:buttonViewFrame];
472 } 478 }
473 479
474 // We don't change a preference; we only change visibility. Preference changing 480 // We don't change a preference; we only change visibility. Preference changing
475 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We 481 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We
476 // simply update based on what we're told. 482 // simply update based on what we're told.
477 - (void)updateVisibility { 483 - (void)updateVisibility {
478 [self showBookmarkBarWithAnimation:NO]; 484 [self showBookmarkBarWithAnimation:NO];
479 } 485 }
480 486
487 - (void)updateAppsPageShortcutButtonVisibility {
488 [self setAppsPageShortcutButtonVisibility];
489 [self reconfigureBookmarkBar];
490 }
491
481 - (void)updateHiddenState { 492 - (void)updateHiddenState {
482 BOOL oldHidden = [[self view] isHidden]; 493 BOOL oldHidden = [[self view] isHidden];
483 BOOL newHidden = ![self isVisible]; 494 BOOL newHidden = ![self isVisible];
484 if (oldHidden != newHidden) 495 if (oldHidden != newHidden)
485 [[self view] setHidden:newHidden]; 496 [[self view] setHidden:newHidden];
486 } 497 }
487 498
488 - (void)setBookmarkBarEnabled:(BOOL)enabled { 499 - (void)setBookmarkBarEnabled:(BOOL)enabled {
489 if (enabled != barIsEnabled_) { 500 if (enabled != barIsEnabled_) {
490 barIsEnabled_ = enabled; 501 barIsEnabled_ = enabled;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 DCHECK([[self view] isKindOfClass:[AnimatableView class]]); 714 DCHECK([[self view] isKindOfClass:[AnimatableView class]]);
704 return (AnimatableView*)[self view]; 715 return (AnimatableView*)[self view];
705 } 716 }
706 717
707 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation { 718 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation {
708 return currentState_ == BookmarkBar::DETACHED ? 719 return currentState_ == BookmarkBar::DETACHED ?
709 bookmark_utils::LAUNCH_DETACHED_BAR : 720 bookmark_utils::LAUNCH_DETACHED_BAR :
710 bookmark_utils::LAUNCH_ATTACHED_BAR; 721 bookmark_utils::LAUNCH_ATTACHED_BAR;
711 } 722 }
712 723
713 // Position the off-the-side chevron to the left of the otherBookmarks button, 724 // 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. 725 - (void)positionRightSideButtons {
715 - (void)positionOffTheSideButton { 726 int maxX = NSMaxX([[self buttonView] bounds]) -
716 NSRect frame = [offTheSideButton_ frame]; 727 bookmarks::kBookmarkHorizontalPadding;
728 int right = maxX;
729
730 int ignored = 0;
731 NSRect frame = [self frameForBookmarkButtonFromCell:
732 [appsPageShortcutButton_ cell] xOffset:&ignored];
733 if (![appsPageShortcutButton_ isHidden]) {
734 right -= NSWidth(frame);
735 frame.origin.x = right;
736 } else {
737 frame.origin.x = maxX - NSWidth(frame);
738 }
739 [appsPageShortcutButton_ setFrame:frame];
740
741 frame = [self frameForBookmarkButtonFromCell:
742 [otherBookmarksButton_ cell] xOffset:&ignored];
743 if (![otherBookmarksButton_ isHidden]) {
744 right -= NSWidth(frame);
745 frame.origin.x = right;
746 } else {
747 frame.origin.x = maxX - NSWidth(frame);
748 }
749 [otherBookmarksButton_ setFrame:frame];
750
751 frame = [offTheSideButton_ frame];
717 frame.size.height = bookmarks::kBookmarkFolderButtonHeight; 752 frame.size.height = bookmarks::kBookmarkFolderButtonHeight;
718 if (otherBookmarksButton_.get() && ![otherBookmarksButton_ isHidden]) { 753 right -= frame.size.width;
719 frame.origin.x = ([otherBookmarksButton_ frame].origin.x - 754 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]; 755 [offTheSideButton_ setFrame:frame];
726 } 756 }
727 757
728 // Configure the off-the-side button (e.g. specify the node range, 758 // Configure the off-the-side button (e.g. specify the node range,
729 // check if we should enable or disable it, etc). 759 // check if we should enable or disable it, etc).
730 - (void)configureOffTheSideButtonContentsAndVisibility { 760 - (void)configureOffTheSideButtonContentsAndVisibility {
731 // If deleting a button while off-the-side is open, buttons may be 761 // If deleting a button while off-the-side is open, buttons may be
732 // promoted from off-the-side to the bar. Accomodate. 762 // promoted from off-the-side to the bar. Accomodate.
733 if (folderController_ && 763 if (folderController_ &&
734 ([folderController_ parentButton] == offTheSideButton_)) { 764 ([folderController_ parentButton] == offTheSideButton_)) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } else { 1105 } else {
1076 // Make the button do something 1106 // Make the button do something
1077 [button setTarget:self]; 1107 [button setTarget:self];
1078 [button setAction:@selector(openBookmark:)]; 1108 [button setAction:@selector(openBookmark:)];
1079 if (node->is_url()) 1109 if (node->is_url())
1080 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]]; 1110 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]];
1081 } 1111 }
1082 return [[button.get() retain] autorelease]; 1112 return [[button.get() retain] autorelease];
1083 } 1113 }
1084 1114
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 1115 // Add bookmark buttons to the view only if they are completely
1098 // visible and don't overlap the "other bookmarks". Remove buttons 1116 // visible and don't overlap the "other bookmarks". Remove buttons
1099 // which are clipped. Called when building the bookmark bar the first time. 1117 // which are clipped. Called when building the bookmark bar the first time.
1100 - (void)addButtonsToView { 1118 - (void)addButtonsToView {
1101 displayedButtonCount_ = 0; 1119 displayedButtonCount_ = 0;
1102 NSMutableArray* buttons = [self buttons]; 1120 NSMutableArray* buttons = [self buttons];
1103 for (NSButton* button in buttons) { 1121 for (NSButton* button in buttons) {
1104 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - 1122 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) -
1105 bookmarks::kBookmarkHorizontalPadding)) 1123 bookmarks::kBookmarkHorizontalPadding))
1106 break; 1124 break;
(...skipping 12 matching lines...) Expand all
1119 // whether it ended up visible. 1137 // whether it ended up visible.
1120 - (BOOL)setOtherBookmarksButtonVisibility { 1138 - (BOOL)setOtherBookmarksButtonVisibility {
1121 if (!otherBookmarksButton_.get()) 1139 if (!otherBookmarksButton_.get())
1122 return NO; 1140 return NO;
1123 1141
1124 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); 1142 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty();
1125 [otherBookmarksButton_ setHidden:!visible]; 1143 [otherBookmarksButton_ setHidden:!visible];
1126 return visible; 1144 return visible;
1127 } 1145 }
1128 1146
1129 // Create the button for "Other Bookmarks" on the right of the bar. 1147 // Shows or hides the Apps button as appropriate, and returns whether it ended
1148 // up visible.
1149 - (BOOL)setAppsPageShortcutButtonVisibility {
1150 if (!appsPageShortcutButton_.get())
1151 return NO;
1152
1153 BOOL visible = bookmarkModel_->IsLoaded() &&
1154 chrome::search::IsInstantExtendedAPIEnabled() &&
1155 browser_->profile()->GetPrefs()->GetBoolean(
1156 prefs::kShowAppsShortcutInBookmarkBar);
1157 [appsPageShortcutButton_ setHidden:!visible];
1158 return visible;
1159 }
1160
1161 // Creates a bookmark bar button that does not correspond to a regular bookmark
1162 // or folder. It is used by the "Other Bookmarks" and the "Apps" buttons.
1163 - (BookmarkButton*)customBookmarkButtonForCell:(NSCell*)cell {
1164 BookmarkButton* button = [[BookmarkButton alloc] init];
1165 [[button draggableButton] setDraggable:NO];
1166 [[button draggableButton] setActsOnMouseDown:YES];
1167 // Peg at right; keep same height as bar.
1168 [button setAutoresizingMask:(NSViewMinXMargin)];
1169 [button setCell:cell];
1170 [button setDelegate:self];
1171 [button setTarget:self];
1172 // Make sure this button, like all other BookmarkButtons, lives
1173 // until the end of the current event loop.
1174 [[button retain] autorelease];
1175 return button;
1176 }
1177
1178 // Creates the button for "Other Bookmarks", but does not position it.
1130 - (void)createOtherBookmarksButton { 1179 - (void)createOtherBookmarksButton {
1131 // Can't create this until the model is loaded, but only need to 1180 // Can't create this until the model is loaded, but only need to
1132 // create it once. 1181 // create it once.
1133 if (otherBookmarksButton_.get()) { 1182 if (otherBookmarksButton_.get()) {
1134 [self setOtherBookmarksButtonVisibility]; 1183 [self setOtherBookmarksButtonVisibility];
1135 return; 1184 return;
1136 } 1185 }
1137 1186
1138 // TODO(jrg): remove duplicate code
1139 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; 1187 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()];
1140 int ignored = 0; 1188 otherBookmarksButton_.reset([self customBookmarkButtonForCell:cell]);
1141 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&ignored]; 1189 [otherBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)];
1142 frame.origin.x = [[self buttonView] bounds].size.width - frame.size.width; 1190 view_id_util::SetID(otherBookmarksButton_.get(), VIEW_ID_OTHER_BOOKMARKS);
1143 frame.origin.x -= bookmarks::kBookmarkHorizontalPadding; 1191 [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 1192
1162 [self setOtherBookmarksButtonVisibility]; 1193 [self setOtherBookmarksButtonVisibility];
1194 }
1163 1195
1164 // Now that it's here, move the chevron over. 1196 // Creates the button for "Apps", but does not position it.
1165 [self positionOffTheSideButton]; 1197 - (void)createAppsPageShortcutButton {
1198 // Can't create this until the model is loaded, but only need to
1199 // create it once.
1200 if (appsPageShortcutButton_.get()) {
1201 [self setAppsPageShortcutButtonVisibility];
1202 return;
1203 }
1204
1205 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1206 NSString* text = l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME);
1207 NSImage* image = rb.GetNativeImageNamed(IDR_WEBSTORE_ICON_16).ToNSImage();
1208 NSCell* cell = [self cellForCustomButtonWithText:text
1209 image:image];
1210 appsPageShortcutButton_.reset([self customBookmarkButtonForCell:cell]);
1211 [appsPageShortcutButton_ setAction:@selector(openAppsPage:)];
1212 NSString* tooltip =
1213 l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP);
1214 [appsPageShortcutButton_ setToolTip:tooltip];
1215 [buttonView_ addSubview:appsPageShortcutButton_.get()];
1216
1217 [self setAppsPageShortcutButtonVisibility];
1218 }
1219
1220 - (void)openAppsPage:(id)sender {
1221 chrome::ShowAppLauncherPage(browser_);
1222 bookmark_utils::RecordAppsPageOpen([self bookmarkLaunchLocation]);
1166 } 1223 }
1167 1224
1168 // To avoid problems with sync, changes that may impact the current 1225 // To avoid problems with sync, changes that may impact the current
1169 // bookmark (e.g. deletion) make sure context menus are closed. This 1226 // bookmark (e.g. deletion) make sure context menus are closed. This
1170 // prevents deleting a node which no longer exists. 1227 // prevents deleting a node which no longer exists.
1171 - (void)cancelMenuTracking { 1228 - (void)cancelMenuTracking {
1172 [contextMenuController_ cancelTracking]; 1229 [contextMenuController_ cancelTracking];
1173 } 1230 }
1174 1231
1175 - (void)moveToState:(BookmarkBar::State)nextState 1232 - (void)moveToState:(BookmarkBar::State)nextState
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 } 1318 }
1262 1319
1263 // Delegate method for |AnimatableView| (a superclass of 1320 // Delegate method for |AnimatableView| (a superclass of
1264 // |BookmarkBarToolbarView|). 1321 // |BookmarkBarToolbarView|).
1265 - (void)animationDidEnd:(NSAnimation*)animation { 1322 - (void)animationDidEnd:(NSAnimation*)animation {
1266 [self finalizeState]; 1323 [self finalizeState];
1267 } 1324 }
1268 1325
1269 - (void)reconfigureBookmarkBar { 1326 - (void)reconfigureBookmarkBar {
1270 [self redistributeButtonsOnBarAsNeeded]; 1327 [self redistributeButtonsOnBarAsNeeded];
1271 [self positionOffTheSideButton]; 1328 [self positionRightSideButtons];
1272 [self configureOffTheSideButtonContentsAndVisibility]; 1329 [self configureOffTheSideButtonContentsAndVisibility];
1273 [self centerNoItemsLabel]; 1330 [self centerNoItemsLabel];
1274 } 1331 }
1275 1332
1276 // Determine if the given |view| can completely fit within the constraint of 1333 // 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 1334 // 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 1335 // width. If the minimum width is not achievable then hide the view. Return YES
1279 // if the view was hidden. 1336 // if the view was hidden.
1280 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX { 1337 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX {
1281 BOOL wasHidden = NO; 1338 BOOL wasHidden = NO;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 1419
1363 // Calculates the final position of the last button in the bar. 1420 // Calculates the final position of the last button in the bar.
1364 // We can't just use [[self buttons] lastObject] frame] because the button 1421 // We can't just use [[self buttons] lastObject] frame] because the button
1365 // may be animating currently. 1422 // may be animating currently.
1366 - (NSRect)finalRectOfLastButton { 1423 - (NSRect)finalRectOfLastButton {
1367 return [self finalRectOfButton:[[self buttons] lastObject]]; 1424 return [self finalRectOfButton:[[self buttons] lastObject]];
1368 } 1425 }
1369 1426
1370 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { 1427 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible {
1371 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); 1428 CGFloat maxViewX = NSMaxX([buttonView_ bounds]);
1372 // If necessary, pull in the width to account for the Other Bookmarks button. 1429 // If necessary, pull in the width to account for the Other Bookmarks or Apps
1373 if ([self setOtherBookmarksButtonVisibility]) { 1430 // button.
1374 maxViewX = [otherBookmarksButton_.get() frame].origin.x - 1431 const BOOL otherButtonVisible = [self setOtherBookmarksButtonVisibility];
1432 const BOOL appsButtonVisible = [self setAppsPageShortcutButtonVisibility];
1433 if (otherButtonVisible || appsButtonVisible) {
1434 BookmarkButton* leftMostRightAlignedButton = otherButtonVisible ?
1435 otherBookmarksButton_.get() : appsPageShortcutButton_.get();
1436 maxViewX = [leftMostRightAlignedButton frame].origin.x -
1375 bookmarks::kBookmarkRightMargin; 1437 bookmarks::kBookmarkRightMargin;
1376 } 1438 }
1377 1439
1378 [self positionOffTheSideButton]; 1440 [self positionRightSideButtons];
1379 // If we're already overflowing, then we need to account for the chevron. 1441 // If we're already overflowing, then we need to account for the chevron.
1380 if (visible) { 1442 if (visible) {
1381 maxViewX = 1443 maxViewX =
1382 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; 1444 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin;
1383 } 1445 }
1384 1446
1385 return maxViewX; 1447 return maxViewX;
1386 } 1448 }
1387 1449
1388 - (void)redistributeButtonsOnBarAsNeeded { 1450 - (void)redistributeButtonsOnBarAsNeeded {
1389 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); 1451 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node();
1390 NSInteger barCount = node->child_count(); 1452 NSInteger barCount = node->child_count();
1391 1453
1392 // Determine the current maximum extent of the visible buttons. 1454 // Determine the current maximum extent of the visible buttons.
1393 [self positionOffTheSideButton]; 1455 [self positionRightSideButtons];
1394 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible: 1456 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:
1395 (barCount > displayedButtonCount_)]; 1457 (barCount > displayedButtonCount_)];
1396 1458
1397 // As a result of pasting or dragging, the bar may now have more buttons 1459 // 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 1460 // than will fit so remove any which overflow. They will be shown in
1399 // the off-the-side folder. 1461 // the off-the-side folder.
1400 while (displayedButtonCount_ > 0) { 1462 while (displayedButtonCount_ > 0) {
1401 BookmarkButton* button = [buttons_ lastObject]; 1463 BookmarkButton* button = [buttons_ lastObject];
1402 if (NSMaxX([self finalRectOfLastButton]) < maxViewX) 1464 if (NSMaxX([self finalRectOfLastButton]) < maxViewX)
1403 break; 1465 break;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self]; 1555 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
1494 [pboard setString:@"" forType:NSStringPboardType]; 1556 [pboard setString:@"" forType:NSStringPboardType];
1495 } 1557 }
1496 1558
1497 // Return an autoreleased NSCell suitable for a bookmark button. 1559 // Return an autoreleased NSCell suitable for a bookmark button.
1498 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. 1560 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1499 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node { 1561 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node {
1500 NSImage* image = node ? [self faviconForNode:node] : nil; 1562 NSImage* image = node ? [self faviconForNode:node] : nil;
1501 BookmarkButtonCell* cell = 1563 BookmarkButtonCell* cell =
1502 [BookmarkButtonCell buttonCellForNode:node 1564 [BookmarkButtonCell buttonCellForNode:node
1503 menuController:contextMenuController_ 1565 text:nil
1504 cellText:nil 1566 image:image
1505 cellImage:image]; 1567 menuController:contextMenuController_];
1506 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; 1568 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1507 1569
1508 // Note: a quirk of setting a cell's text color is that it won't work 1570 // Note: a quirk of setting a cell's text color is that it won't work
1571 // until the cell is associated with a button, so we can't theme the cell yet.
1572
1573 return cell;
1574 }
1575
1576 // Return an autoreleased NSCell suitable for a special button displayed on the
1577 // bookmark bar that is not attached to any bookmark node.
1578 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1579 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text
1580 image:(NSImage*)image {
1581 BookmarkButtonCell* cell =
1582 [BookmarkButtonCell buttonCellWithText:text
1583 image:image
1584 menuController:contextMenuController_];
1585 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1586
1587 // 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. 1588 // until the cell is associated with a button, so we can't theme the cell yet.
1510 1589
1511 return cell; 1590 return cell;
1512 } 1591 }
1513 1592
1514 // Returns a frame appropriate for the given bookmark cell, suitable 1593 // Returns a frame appropriate for the given bookmark cell, suitable
1515 // for creating an NSButton that will contain it. |xOffset| is the X 1594 // 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 1595 // offset for the frame; it is increased to be an appropriate X offset
1517 // for the next button. 1596 // for the next button.
1518 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell 1597 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 if (!themeProvider) 1667 if (!themeProvider)
1589 return; 1668 return;
1590 NSColor* color = 1669 NSColor* color =
1591 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT, 1670 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT,
1592 true); 1671 true);
1593 for (BookmarkButton* button in buttons_.get()) { 1672 for (BookmarkButton* button in buttons_.get()) {
1594 BookmarkButtonCell* cell = [button cell]; 1673 BookmarkButtonCell* cell = [button cell];
1595 [cell setTextColor:color]; 1674 [cell setTextColor:color];
1596 } 1675 }
1597 [[otherBookmarksButton_ cell] setTextColor:color]; 1676 [[otherBookmarksButton_ cell] setTextColor:color];
1677 [[appsPageShortcutButton_ cell] setTextColor:color];
1598 } 1678 }
1599 1679
1600 // Return YES if the event indicates an exit from the bookmark bar 1680 // 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. 1681 // 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 1682 // At this time we are watching the area that includes all popup
1603 // bookmark folder windows. 1683 // bookmark folder windows.
1604 - (BOOL)isEventAnExitEvent:(NSEvent*)event { 1684 - (BOOL)isEventAnExitEvent:(NSEvent*)event {
1605 NSWindow* eventWindow = [event window]; 1685 NSWindow* eventWindow = [event window];
1606 NSWindow* myWindow = [[self view] window]; 1686 NSWindow* myWindow = [[self view] window];
1607 switch ([event type]) { 1687 switch ([event type]) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 // See: http://crbug.com/36614 1973 // See: http://crbug.com/36614
1894 if (folderController_) 1974 if (folderController_)
1895 [self closeAllBookmarkFolders]; 1975 [self closeAllBookmarkFolders];
1896 1976
1897 // Brute force nuke and build. 1977 // Brute force nuke and build.
1898 savedFrameWidth_ = NSWidth([[self view] frame]); 1978 savedFrameWidth_ = NSWidth([[self view] frame]);
1899 const BookmarkNode* node = model->bookmark_bar_node(); 1979 const BookmarkNode* node = model->bookmark_bar_node();
1900 [self clearBookmarkBar]; 1980 [self clearBookmarkBar];
1901 [self addNodesToButtonList:node]; 1981 [self addNodesToButtonList:node];
1902 [self createOtherBookmarksButton]; 1982 [self createOtherBookmarksButton];
1983 [self createAppsPageShortcutButton];
1903 [self updateTheme:[[[self view] window] themeProvider]]; 1984 [self updateTheme:[[[self view] window] themeProvider]];
1904 [self positionOffTheSideButton]; 1985 [self positionRightSideButtons];
1905 [self addNonBookmarkButtonsToView];
1906 [self addButtonsToView]; 1986 [self addButtonsToView];
1907 [self configureOffTheSideButtonContentsAndVisibility]; 1987 [self configureOffTheSideButtonContentsAndVisibility];
1908 [self reconfigureBookmarkBar]; 1988 [self reconfigureBookmarkBar];
1909 } 1989 }
1910 1990
1911 - (void)beingDeleted:(BookmarkModel*)model { 1991 - (void)beingDeleted:(BookmarkModel*)model {
1912 // The browser may be being torn down; little is safe to do. As an 1992 // 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. 1993 // example, it may not be safe to clear the pasteboard.
1914 // http://crbug.com/38665 1994 // http://crbug.com/38665
1915 } 1995 }
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 - (id<BookmarkButtonControllerProtocol>)controllerForNode: 2623 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
2544 (const BookmarkNode*)node { 2624 (const BookmarkNode*)node {
2545 // See if it's in the bar, then if it is in the hierarchy of visible 2625 // See if it's in the bar, then if it is in the hierarchy of visible
2546 // folder menus. 2626 // folder menus.
2547 if (bookmarkModel_->bookmark_bar_node() == node) 2627 if (bookmarkModel_->bookmark_bar_node() == node)
2548 return self; 2628 return self;
2549 return [folderController_ controllerForNode:node]; 2629 return [folderController_ controllerForNode:node];
2550 } 2630 }
2551 2631
2552 @end 2632 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698