| OLD | NEW |
| 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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 276 |
| 277 innerContentAnimationsEnabled_ = YES; | 277 innerContentAnimationsEnabled_ = YES; |
| 278 stateAnimationsEnabled_ = YES; | 278 stateAnimationsEnabled_ = YES; |
| 279 | 279 |
| 280 // Register for theme changes, bookmark button pulsing, ... | 280 // Register for theme changes, bookmark button pulsing, ... |
| 281 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 281 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 282 [defaultCenter addObserver:self | 282 [defaultCenter addObserver:self |
| 283 selector:@selector(themeDidChangeNotification:) | 283 selector:@selector(themeDidChangeNotification:) |
| 284 name:kBrowserThemeDidChangeNotification | 284 name:kBrowserThemeDidChangeNotification |
| 285 object:nil]; | 285 object:nil]; |
| 286 [defaultCenter addObserver:self | |
| 287 selector:@selector(pulseBookmarkNotification:) | |
| 288 name:bookmark_button::kPulseBookmarkButtonNotification | |
| 289 object:nil]; | |
| 290 | 286 |
| 291 contextMenuController_.reset( | 287 contextMenuController_.reset( |
| 292 [[BookmarkContextMenuCocoaController alloc] | 288 [[BookmarkContextMenuCocoaController alloc] |
| 293 initWithBookmarkBarController:self]); | 289 initWithBookmarkBarController:self]); |
| 294 | 290 |
| 295 // This call triggers an -awakeFromNib, which builds the bar, which might | 291 // This call triggers an -awakeFromNib, which builds the bar, which might |
| 296 // use |folderImage_| and |contextMenuController_|. Ensure it happens after | 292 // use |folderImage_| and |contextMenuController_|. Ensure it happens after |
| 297 // |folderImage_| is loaded and |contextMenuController_| is created. | 293 // |folderImage_| is loaded and |contextMenuController_| is created. |
| 298 [[self animatableView] setResizeDelegate:resizeDelegate]; | 294 [[self animatableView] setResizeDelegate:resizeDelegate]; |
| 299 } | 295 } |
| 300 return self; | 296 return self; |
| 301 } | 297 } |
| 302 | 298 |
| 303 - (Browser*)browser { | 299 - (Browser*)browser { |
| 304 return browser_; | 300 return browser_; |
| 305 } | 301 } |
| 306 | 302 |
| 307 - (BookmarkContextMenuCocoaController*)menuController { | 303 - (BookmarkContextMenuCocoaController*)menuController { |
| 308 return contextMenuController_.get(); | 304 return contextMenuController_.get(); |
| 309 } | 305 } |
| 310 | 306 |
| 311 - (void)pulseBookmarkNotification:(NSNotification*)notification { | 307 - (void)pulseBookmarkNode:(const BookmarkNode*)node doPulse:(BOOL)doPulse { |
| 312 NSDictionary* dict = [notification userInfo]; | |
| 313 const BookmarkNode* node = NULL; | |
| 314 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey]; | |
| 315 DCHECK(value); | |
| 316 if (value) | |
| 317 node = static_cast<const BookmarkNode*>([value pointerValue]); | |
| 318 NSNumber* number = [dict objectForKey:bookmark_button::kBookmarkPulseFlagKey]; | |
| 319 DCHECK(number); | |
| 320 BOOL doPulse = number ? [number boolValue] : NO; | |
| 321 | |
| 322 // 3 cases: | 308 // 3 cases: |
| 323 // button on the bar: flash it | 309 // button on the bar: flash it |
| 324 // button in "other bookmarks" folder: flash other bookmarks | 310 // button in "other bookmarks" folder: flash other bookmarks |
| 325 // button in "off the side" folder: flash the chevron | 311 // button in "off the side" folder: flash the chevron |
| 326 for (BookmarkButton* button in [self buttons]) { | 312 for (BookmarkButton* button in [self buttons]) { |
| 327 if ([button bookmarkNode] == node) { | 313 if ([button bookmarkNode] == node) { |
| 328 [button setIsContinuousPulsing:doPulse]; | 314 [button setIsContinuousPulsing:doPulse]; |
| 329 return; | 315 return; |
| 330 } | 316 } |
| 331 } | 317 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 342 return; | 328 return; |
| 343 } | 329 } |
| 344 if (node->parent() == bookmarkModel_->bookmark_bar_node()) { | 330 if (node->parent() == bookmarkModel_->bookmark_bar_node()) { |
| 345 [offTheSideButton_ setIsContinuousPulsing:doPulse]; | 331 [offTheSideButton_ setIsContinuousPulsing:doPulse]; |
| 346 return; | 332 return; |
| 347 } | 333 } |
| 348 | 334 |
| 349 NOTREACHED() << "no bookmark button found to pulse!"; | 335 NOTREACHED() << "no bookmark button found to pulse!"; |
| 350 } | 336 } |
| 351 | 337 |
| 338 - (const BookmarkNode*)startPulsingBookmarkNode:(const BookmarkNode*)node { |
| 339 // Find the closest parent that is visible on the bar. |
| 340 while (node) { |
| 341 if ((node->parent() == bookmarkModel_->bookmark_bar_node()) || |
| 342 (node->parent() == managedBookmarkService_->managed_node()) || |
| 343 (node->parent() == managedBookmarkService_->supervised_node()) || |
| 344 (node == bookmarkModel_->other_node())) { |
| 345 [self pulseBookmarkNode:node doPulse:YES]; |
| 346 return node; |
| 347 } |
| 348 node = node->parent(); |
| 349 } |
| 350 return nullptr; |
| 351 } |
| 352 |
| 353 - (void)stopPulsingBookmarkNode:(const BookmarkNode*)node { |
| 354 [self pulseBookmarkNode:node doPulse:NO]; |
| 355 } |
| 356 |
| 352 - (void)dealloc { | 357 - (void)dealloc { |
| 353 [self browserWillBeDestroyed]; | 358 [self browserWillBeDestroyed]; |
| 354 [super dealloc]; | 359 [super dealloc]; |
| 355 } | 360 } |
| 356 | 361 |
| 357 - (void)browserWillBeDestroyed { | 362 - (void)browserWillBeDestroyed { |
| 358 // Clear delegate so it doesn't get called during stopAnimation. | 363 // Clear delegate so it doesn't get called during stopAnimation. |
| 359 [[self animatableView] setResizeDelegate:nil]; | 364 [[self animatableView] setResizeDelegate:nil]; |
| 360 | 365 |
| 361 // We better stop any in-flight animation if we're being killed. | 366 // We better stop any in-flight animation if we're being killed. |
| (...skipping 2547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2909 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 2914 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
| 2910 (const BookmarkNode*)node { | 2915 (const BookmarkNode*)node { |
| 2911 // See if it's in the bar, then if it is in the hierarchy of visible | 2916 // See if it's in the bar, then if it is in the hierarchy of visible |
| 2912 // folder menus. | 2917 // folder menus. |
| 2913 if (bookmarkModel_->bookmark_bar_node() == node) | 2918 if (bookmarkModel_->bookmark_bar_node() == node) |
| 2914 return self; | 2919 return self; |
| 2915 return [folderController_ controllerForNode:node]; | 2920 return [folderController_ controllerForNode:node]; |
| 2916 } | 2921 } |
| 2917 | 2922 |
| 2918 @end | 2923 @end |
| OLD | NEW |