Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" | 26 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
| 27 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 27 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
| 28 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h" | 28 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h" |
| 29 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h" | 29 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h" |
| 30 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 30 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
| 31 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" | 31 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
| 32 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controlle r.h" | 32 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_context_menu_cocoa_controlle r.h" |
| 33 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 33 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
| 34 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 34 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
| 35 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" | 35 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" |
| 36 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_model_observer_for_cocoa.h" | |
| 36 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" | 37 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" |
| 37 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 38 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 38 #import "chrome/browser/ui/cocoa/menu_button.h" | 39 #import "chrome/browser/ui/cocoa/menu_button.h" |
| 39 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 40 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
| 40 #import "chrome/browser/ui/cocoa/themed_window.h" | 41 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 41 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 42 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 42 #import "chrome/browser/ui/cocoa/view_id_util.h" | 43 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 43 #import "chrome/browser/ui/cocoa/view_resizer.h" | 44 #import "chrome/browser/ui/cocoa/view_resizer.h" |
| 44 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 45 #include "chrome/common/extensions/extension_constants.h" | 46 #include "chrome/common/extensions/extension_constants.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 | 277 |
| 277 innerContentAnimationsEnabled_ = YES; | 278 innerContentAnimationsEnabled_ = YES; |
| 278 stateAnimationsEnabled_ = YES; | 279 stateAnimationsEnabled_ = YES; |
| 279 | 280 |
| 280 // Register for theme changes, bookmark button pulsing, ... | 281 // Register for theme changes, bookmark button pulsing, ... |
| 281 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 282 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 282 [defaultCenter addObserver:self | 283 [defaultCenter addObserver:self |
| 283 selector:@selector(themeDidChangeNotification:) | 284 selector:@selector(themeDidChangeNotification:) |
| 284 name:kBrowserThemeDidChangeNotification | 285 name:kBrowserThemeDidChangeNotification |
| 285 object:nil]; | 286 object:nil]; |
| 286 [defaultCenter addObserver:self | |
| 287 selector:@selector(pulseBookmarkNotification:) | |
| 288 name:bookmark_button::kPulseBookmarkButtonNotification | |
| 289 object:nil]; | |
| 290 | 287 |
| 291 contextMenuController_.reset( | 288 contextMenuController_.reset( |
| 292 [[BookmarkContextMenuCocoaController alloc] | 289 [[BookmarkContextMenuCocoaController alloc] |
| 293 initWithBookmarkBarController:self]); | 290 initWithBookmarkBarController:self]); |
| 294 | 291 |
| 295 // This call triggers an -awakeFromNib, which builds the bar, which might | 292 // This call triggers an -awakeFromNib, which builds the bar, which might |
| 296 // use |folderImage_| and |contextMenuController_|. Ensure it happens after | 293 // use |folderImage_| and |contextMenuController_|. Ensure it happens after |
| 297 // |folderImage_| is loaded and |contextMenuController_| is created. | 294 // |folderImage_| is loaded and |contextMenuController_| is created. |
| 298 [[self animatableView] setResizeDelegate:resizeDelegate]; | 295 [[self animatableView] setResizeDelegate:resizeDelegate]; |
| 299 } | 296 } |
| 300 return self; | 297 return self; |
| 301 } | 298 } |
| 302 | 299 |
| 303 - (Browser*)browser { | 300 - (Browser*)browser { |
| 304 return browser_; | 301 return browser_; |
| 305 } | 302 } |
| 306 | 303 |
| 307 - (BookmarkContextMenuCocoaController*)menuController { | 304 - (BookmarkContextMenuCocoaController*)menuController { |
| 308 return contextMenuController_.get(); | 305 return contextMenuController_.get(); |
| 309 } | 306 } |
| 310 | 307 |
| 311 - (void)pulseBookmarkNotification:(NSNotification*)notification { | 308 - (BookmarkButton*)bookmarkButtonForNode:(const BookmarkNode*)node { |
|
tapted
2015/08/25 01:13:20
declare this in BookmarkBarController(Private)? -
jackhou1
2015/08/25 04:32:29
Added declaration. The order is pretty inconsisten
tapted
2015/08/25 05:46:34
Acknowledged.
| |
| 312 NSDictionary* dict = [notification userInfo]; | 309 // Find the closest parent that is visible on the bar. |
| 313 const BookmarkNode* node = NULL; | 310 BookmarkButton* result = nil; |
|
tapted
2015/08/25 01:13:20
I think it's more chromeystyle to omit `result` --
jackhou1
2015/08/25 04:32:29
Done.
| |
| 314 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey]; | 311 while (node && !result) { |
| 315 DCHECK(value); | 312 // 3 cases: |
| 316 if (value) | 313 // button on the bar: flash it |
| 317 node = static_cast<const BookmarkNode*>([value pointerValue]); | 314 // button in "other bookmarks" folder: flash other bookmarks |
| 318 NSNumber* number = [dict objectForKey:bookmark_button::kBookmarkPulseFlagKey]; | 315 // button in "off the side" folder: flash the chevron |
| 319 DCHECK(number); | 316 if (node->parent() == bookmarkModel_->bookmark_bar_node()) { |
| 320 BOOL doPulse = number ? [number boolValue] : NO; | 317 for (BookmarkButton* button in [self buttons]) { |
| 318 if ([button bookmarkNode] == node) { | |
| 319 [button setIsContinuousPulsing:YES]; | |
| 320 result = button; | |
| 321 } | |
| 322 } | |
| 323 } else if ([managedBookmarksButton_ bookmarkNode] == node) { | |
|
tapted
2015/08/25 01:13:20
a thought: would the managedBookmarksButton_'s par
jackhou1
2015/08/25 04:32:29
I don't think so, since it works with the otherBoo
| |
| 324 result = managedBookmarksButton_; | |
| 325 } else if ([supervisedBookmarksButton_ bookmarkNode] == node) { | |
| 326 result = supervisedBookmarksButton_; | |
| 327 } else if ([otherBookmarksButton_ bookmarkNode] == node) { | |
| 328 result = otherBookmarksButton_; | |
| 329 } else if (node->parent() == bookmarkModel_->bookmark_bar_node()) { | |
| 330 result = offTheSideButton_; | |
| 331 } | |
| 332 node = node->parent(); | |
| 333 } | |
| 334 return result; | |
| 335 } | |
| 321 | 336 |
| 322 // 3 cases: | 337 - (void)startPulsingBookmarkNode:(const BookmarkNode*)node { |
| 323 // button on the bar: flash it | 338 if (pulsingButton_) |
|
tapted
2015/08/25 01:13:20
Here maybe just start with
pulsingBookmarkObserve
jackhou1
2015/08/25 04:32:29
As per previous comment, I'd prefer keep |pulsingB
| |
| 324 // button in "other bookmarks" folder: flash other bookmarks | 339 [self stopPulsingBookmarkNode]; |
| 325 // button in "off the side" folder: flash the chevron | 340 |
| 326 for (BookmarkButton* button in [self buttons]) { | 341 pulsingButton_ = [self bookmarkButtonForNode:node]; |
| 327 if ([button bookmarkNode] == node) { | 342 if (!pulsingButton_) |
| 328 [button setIsContinuousPulsing:doPulse]; | |
| 329 return; | |
| 330 } | |
| 331 } | |
| 332 if ([managedBookmarksButton_ bookmarkNode] == node) { | |
| 333 [managedBookmarksButton_ setIsContinuousPulsing:doPulse]; | |
| 334 return; | 343 return; |
| 335 } | 344 |
| 336 if ([supervisedBookmarksButton_ bookmarkNode] == node) { | 345 [pulsingButton_ setIsContinuousPulsing:YES]; |
| 337 [supervisedBookmarksButton_ setIsContinuousPulsing:doPulse]; | 346 pulsingBookmarkObserver_.reset( |
| 347 new BookmarkModelObserverForCocoa(bookmarkModel_, ^(BOOL) { | |
| 348 // Stop pulsing if anything happened to the node. | |
| 349 [self stopPulsingBookmarkNode]; | |
| 350 })); | |
| 351 pulsingBookmarkObserver_->StartObservingNode(node); | |
| 352 } | |
| 353 | |
| 354 - (void)stopPulsingBookmarkNode { | |
| 355 if (!pulsingButton_) | |
| 338 return; | 356 return; |
| 339 } | |
| 340 if ([otherBookmarksButton_ bookmarkNode] == node) { | |
| 341 [otherBookmarksButton_ setIsContinuousPulsing:doPulse]; | |
| 342 return; | |
| 343 } | |
| 344 if (node->parent() == bookmarkModel_->bookmark_bar_node()) { | |
| 345 [offTheSideButton_ setIsContinuousPulsing:doPulse]; | |
| 346 return; | |
| 347 } | |
| 348 | 357 |
| 349 NOTREACHED() << "no bookmark button found to pulse!"; | 358 [pulsingButton_ setIsContinuousPulsing:NO]; |
| 359 pulsingButton_ = nil; | |
| 360 pulsingBookmarkObserver_.reset(); | |
| 350 } | 361 } |
| 351 | 362 |
| 352 - (void)dealloc { | 363 - (void)dealloc { |
| 353 [self browserWillBeDestroyed]; | 364 [self browserWillBeDestroyed]; |
| 354 [super dealloc]; | 365 [super dealloc]; |
| 355 } | 366 } |
| 356 | 367 |
| 357 - (void)browserWillBeDestroyed { | 368 - (void)browserWillBeDestroyed { |
| 358 // Clear delegate so it doesn't get called during stopAnimation. | 369 // Clear delegate so it doesn't get called during stopAnimation. |
| 359 [[self animatableView] setResizeDelegate:nil]; | 370 [[self animatableView] setResizeDelegate:nil]; |
| (...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1756 return folderTarget_.get(); | 1767 return folderTarget_.get(); |
| 1757 } | 1768 } |
| 1758 | 1769 |
| 1759 - (int)displayedButtonCount { | 1770 - (int)displayedButtonCount { |
| 1760 return displayedButtonCount_; | 1771 return displayedButtonCount_; |
| 1761 } | 1772 } |
| 1762 | 1773 |
| 1763 // Delete all buttons (bookmarks, chevron, "other bookmarks") from the | 1774 // Delete all buttons (bookmarks, chevron, "other bookmarks") from the |
| 1764 // bookmark bar; reset knowledge of bookmarks. | 1775 // bookmark bar; reset knowledge of bookmarks. |
| 1765 - (void)clearBookmarkBar { | 1776 - (void)clearBookmarkBar { |
| 1777 [self stopPulsingBookmarkNode]; | |
| 1766 for (BookmarkButton* button in buttons_.get()) { | 1778 for (BookmarkButton* button in buttons_.get()) { |
| 1767 [button setDelegate:nil]; | 1779 [button setDelegate:nil]; |
| 1768 [button removeFromSuperview]; | 1780 [button removeFromSuperview]; |
| 1769 } | 1781 } |
| 1770 [buttons_ removeAllObjects]; | 1782 [buttons_ removeAllObjects]; |
| 1771 [self clearMenuTagMap]; | 1783 [self clearMenuTagMap]; |
| 1772 displayedButtonCount_ = 0; | 1784 displayedButtonCount_ = 0; |
| 1773 | 1785 |
| 1774 // Make sure there are no stale pointers in the pasteboard. This | 1786 // Make sure there are no stale pointers in the pasteboard. This |
| 1775 // can be important if a bookmark is deleted (via bookmark sync) | 1787 // can be important if a bookmark is deleted (via bookmark sync) |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2315 - (void)nodeRemoved:(BookmarkModel*)model | 2327 - (void)nodeRemoved:(BookmarkModel*)model |
| 2316 parent:(const BookmarkNode*)oldParent index:(int)index { | 2328 parent:(const BookmarkNode*)oldParent index:(int)index { |
| 2317 // If a context menu is open, close it. | 2329 // If a context menu is open, close it. |
| 2318 [self cancelMenuTracking]; | 2330 [self cancelMenuTracking]; |
| 2319 | 2331 |
| 2320 // Locate the parent node. The parent may not be showing, in which case | 2332 // Locate the parent node. The parent may not be showing, in which case |
| 2321 // we do nothing. | 2333 // we do nothing. |
| 2322 id<BookmarkButtonControllerProtocol> parentController = | 2334 id<BookmarkButtonControllerProtocol> parentController = |
| 2323 [self controllerForNode:oldParent]; | 2335 [self controllerForNode:oldParent]; |
| 2324 [parentController removeButton:index animate:YES]; | 2336 [parentController removeButton:index animate:YES]; |
| 2337 | |
| 2325 // If we go from 1 --> 0 bookmarks we may need to show the | 2338 // If we go from 1 --> 0 bookmarks we may need to show the |
| 2326 // "bookmarks go here" text container. | 2339 // "bookmarks go here" text container. |
| 2327 [self showOrHideNoItemContainerForNode:model->bookmark_bar_node()]; | 2340 [self showOrHideNoItemContainerForNode:model->bookmark_bar_node()]; |
| 2328 // If we deleted the only item on the "off the side" menu we no | 2341 // If we deleted the only item on the "off the side" menu we no |
| 2329 // longer need to show it. | 2342 // longer need to show it. |
| 2330 [self reconfigureBookmarkBar]; | 2343 [self reconfigureBookmarkBar]; |
| 2331 } | 2344 } |
| 2332 | 2345 |
| 2333 // TODO(jrg): linear searching is bad. | 2346 // TODO(jrg): linear searching is bad. |
| 2334 // Need a BookmarkNode-->NSCell mapping. | 2347 // Need a BookmarkNode-->NSCell mapping. |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2909 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 2922 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
| 2910 (const BookmarkNode*)node { | 2923 (const BookmarkNode*)node { |
| 2911 // See if it's in the bar, then if it is in the hierarchy of visible | 2924 // See if it's in the bar, then if it is in the hierarchy of visible |
| 2912 // folder menus. | 2925 // folder menus. |
| 2913 if (bookmarkModel_->bookmark_bar_node() == node) | 2926 if (bookmarkModel_->bookmark_bar_node() == node) |
| 2914 return self; | 2927 return self; |
| 2915 return [folderController_ controllerForNode:node]; | 2928 return [folderController_ controllerForNode:node]; |
| 2916 } | 2929 } |
| 2917 | 2930 |
| 2918 @end | 2931 @end |
| OLD | NEW |