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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 167 |
167 // Create buttons for all items in the given bookmark node tree. | 168 // Create buttons for all items in the given bookmark node tree. |
168 // Modifies self->buttons_. Do not add more buttons than will fit on the view. | 169 // Modifies self->buttons_. Do not add more buttons than will fit on the view. |
169 - (void)addNodesToButtonList:(const BookmarkNode*)node; | 170 - (void)addNodesToButtonList:(const BookmarkNode*)node; |
170 | 171 |
171 // Create an autoreleased button appropriate for insertion into the bookmark | 172 // Create an autoreleased button appropriate for insertion into the bookmark |
172 // bar. Update |xOffset| with the offset appropriate for the subsequent button. | 173 // bar. Update |xOffset| with the offset appropriate for the subsequent button. |
173 - (BookmarkButton*)buttonForNode:(const BookmarkNode*)node | 174 - (BookmarkButton*)buttonForNode:(const BookmarkNode*)node |
174 xOffset:(int*)xOffset; | 175 xOffset:(int*)xOffset; |
175 | 176 |
| 177 // Find a parent whose button is visible on the bookmark bar. |
| 178 - (BookmarkButton*)bookmarkButtonToPulseForNode:(const BookmarkNode*)node; |
| 179 |
176 // Puts stuff into the final state without animating, stopping a running | 180 // Puts stuff into the final state without animating, stopping a running |
177 // animation if necessary. | 181 // animation if necessary. |
178 - (void)finalizeState; | 182 - (void)finalizeState; |
179 | 183 |
180 // Stops any current animation in its tracks (midway). | 184 // Stops any current animation in its tracks (midway). |
181 - (void)stopCurrentAnimation; | 185 - (void)stopCurrentAnimation; |
182 | 186 |
183 // Show/hide the bookmark bar. | 187 // Show/hide the bookmark bar. |
184 // if |animate| is YES, the changes are made using the animator; otherwise they | 188 // if |animate| is YES, the changes are made using the animator; otherwise they |
185 // are made immediately. | 189 // are made immediately. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 280 |
277 innerContentAnimationsEnabled_ = YES; | 281 innerContentAnimationsEnabled_ = YES; |
278 stateAnimationsEnabled_ = YES; | 282 stateAnimationsEnabled_ = YES; |
279 | 283 |
280 // Register for theme changes, bookmark button pulsing, ... | 284 // Register for theme changes, bookmark button pulsing, ... |
281 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 285 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
282 [defaultCenter addObserver:self | 286 [defaultCenter addObserver:self |
283 selector:@selector(themeDidChangeNotification:) | 287 selector:@selector(themeDidChangeNotification:) |
284 name:kBrowserThemeDidChangeNotification | 288 name:kBrowserThemeDidChangeNotification |
285 object:nil]; | 289 object:nil]; |
286 [defaultCenter addObserver:self | |
287 selector:@selector(pulseBookmarkNotification:) | |
288 name:bookmark_button::kPulseBookmarkButtonNotification | |
289 object:nil]; | |
290 | 290 |
291 contextMenuController_.reset( | 291 contextMenuController_.reset( |
292 [[BookmarkContextMenuCocoaController alloc] | 292 [[BookmarkContextMenuCocoaController alloc] |
293 initWithBookmarkBarController:self]); | 293 initWithBookmarkBarController:self]); |
294 | 294 |
295 // This call triggers an -awakeFromNib, which builds the bar, which might | 295 // This call triggers an -awakeFromNib, which builds the bar, which might |
296 // use |folderImage_| and |contextMenuController_|. Ensure it happens after | 296 // use |folderImage_| and |contextMenuController_|. Ensure it happens after |
297 // |folderImage_| is loaded and |contextMenuController_| is created. | 297 // |folderImage_| is loaded and |contextMenuController_| is created. |
298 [[self animatableView] setResizeDelegate:resizeDelegate]; | 298 [[self animatableView] setResizeDelegate:resizeDelegate]; |
299 } | 299 } |
300 return self; | 300 return self; |
301 } | 301 } |
302 | 302 |
303 - (Browser*)browser { | 303 - (Browser*)browser { |
304 return browser_; | 304 return browser_; |
305 } | 305 } |
306 | 306 |
307 - (BookmarkContextMenuCocoaController*)menuController { | 307 - (BookmarkContextMenuCocoaController*)menuController { |
308 return contextMenuController_.get(); | 308 return contextMenuController_.get(); |
309 } | 309 } |
310 | 310 |
311 - (void)pulseBookmarkNotification:(NSNotification*)notification { | 311 - (BookmarkButton*)bookmarkButtonToPulseForNode:(const BookmarkNode*)node { |
312 NSDictionary* dict = [notification userInfo]; | 312 // Find the closest parent that is visible on the bar. |
313 const BookmarkNode* node = NULL; | 313 while (node) { |
314 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey]; | 314 // Check if we've reached one of the special buttons. Otherwise, if the next |
315 DCHECK(value); | 315 // parent is the boomark bar, find the corresponding button. |
316 if (value) | 316 if ([managedBookmarksButton_ bookmarkNode] == node) |
317 node = static_cast<const BookmarkNode*>([value pointerValue]); | 317 return managedBookmarksButton_; |
318 NSNumber* number = [dict objectForKey:bookmark_button::kBookmarkPulseFlagKey]; | |
319 DCHECK(number); | |
320 BOOL doPulse = number ? [number boolValue] : NO; | |
321 | 318 |
322 // 3 cases: | 319 if ([supervisedBookmarksButton_ bookmarkNode] == node) |
323 // button on the bar: flash it | 320 return supervisedBookmarksButton_; |
324 // button in "other bookmarks" folder: flash other bookmarks | 321 |
325 // button in "off the side" folder: flash the chevron | 322 if ([otherBookmarksButton_ bookmarkNode] == node) |
326 for (BookmarkButton* button in [self buttons]) { | 323 return otherBookmarksButton_; |
327 if ([button bookmarkNode] == node) { | 324 |
328 [button setIsContinuousPulsing:doPulse]; | 325 if ([offTheSideButton_ bookmarkNode] == node) |
329 return; | 326 return offTheSideButton_; |
| 327 |
| 328 if (node->parent() == bookmarkModel_->bookmark_bar_node()) { |
| 329 for (BookmarkButton* button in [self buttons]) { |
| 330 if ([button bookmarkNode] == node) { |
| 331 [button setIsContinuousPulsing:YES]; |
| 332 return button; |
| 333 } |
| 334 } |
330 } | 335 } |
| 336 |
| 337 node = node->parent(); |
331 } | 338 } |
332 if ([managedBookmarksButton_ bookmarkNode] == node) { | 339 NOTREACHED(); |
333 [managedBookmarksButton_ setIsContinuousPulsing:doPulse]; | 340 return nil; |
| 341 } |
| 342 |
| 343 - (void)startPulsingBookmarkNode:(const BookmarkNode*)node { |
| 344 [self stopPulsingBookmarkNode]; |
| 345 |
| 346 pulsingButton_ = [self bookmarkButtonToPulseForNode:node]; |
| 347 if (!pulsingButton_) |
334 return; | 348 return; |
335 } | 349 |
336 if ([supervisedBookmarksButton_ bookmarkNode] == node) { | 350 [pulsingButton_ setIsContinuousPulsing:YES]; |
337 [supervisedBookmarksButton_ setIsContinuousPulsing:doPulse]; | 351 pulsingBookmarkObserver_.reset( |
| 352 new BookmarkModelObserverForCocoa(bookmarkModel_, ^() { |
| 353 // Stop pulsing if anything happened to the node. |
| 354 [self stopPulsingBookmarkNode]; |
| 355 })); |
| 356 pulsingBookmarkObserver_->StartObservingNode(node); |
| 357 } |
| 358 |
| 359 - (void)stopPulsingBookmarkNode { |
| 360 if (!pulsingButton_) |
338 return; | 361 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 | 362 |
349 NOTREACHED() << "no bookmark button found to pulse!"; | 363 [pulsingButton_ setIsContinuousPulsing:NO]; |
| 364 pulsingButton_ = nil; |
| 365 pulsingBookmarkObserver_.reset(); |
350 } | 366 } |
351 | 367 |
352 - (void)dealloc { | 368 - (void)dealloc { |
353 [self browserWillBeDestroyed]; | 369 [self browserWillBeDestroyed]; |
354 [super dealloc]; | 370 [super dealloc]; |
355 } | 371 } |
356 | 372 |
357 - (void)browserWillBeDestroyed { | 373 - (void)browserWillBeDestroyed { |
358 // Clear delegate so it doesn't get called during stopAnimation. | 374 // Clear delegate so it doesn't get called during stopAnimation. |
359 [[self animatableView] setResizeDelegate:nil]; | 375 [[self animatableView] setResizeDelegate:nil]; |
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 return folderTarget_.get(); | 1772 return folderTarget_.get(); |
1757 } | 1773 } |
1758 | 1774 |
1759 - (int)displayedButtonCount { | 1775 - (int)displayedButtonCount { |
1760 return displayedButtonCount_; | 1776 return displayedButtonCount_; |
1761 } | 1777 } |
1762 | 1778 |
1763 // Delete all buttons (bookmarks, chevron, "other bookmarks") from the | 1779 // Delete all buttons (bookmarks, chevron, "other bookmarks") from the |
1764 // bookmark bar; reset knowledge of bookmarks. | 1780 // bookmark bar; reset knowledge of bookmarks. |
1765 - (void)clearBookmarkBar { | 1781 - (void)clearBookmarkBar { |
| 1782 [self stopPulsingBookmarkNode]; |
1766 for (BookmarkButton* button in buttons_.get()) { | 1783 for (BookmarkButton* button in buttons_.get()) { |
1767 [button setDelegate:nil]; | 1784 [button setDelegate:nil]; |
1768 [button removeFromSuperview]; | 1785 [button removeFromSuperview]; |
1769 } | 1786 } |
1770 [buttons_ removeAllObjects]; | 1787 [buttons_ removeAllObjects]; |
1771 [self clearMenuTagMap]; | 1788 [self clearMenuTagMap]; |
1772 displayedButtonCount_ = 0; | 1789 displayedButtonCount_ = 0; |
1773 | 1790 |
1774 // Make sure there are no stale pointers in the pasteboard. This | 1791 // Make sure there are no stale pointers in the pasteboard. This |
1775 // can be important if a bookmark is deleted (via bookmark sync) | 1792 // can be important if a bookmark is deleted (via bookmark sync) |
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2909 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 2926 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
2910 (const BookmarkNode*)node { | 2927 (const BookmarkNode*)node { |
2911 // See if it's in the bar, then if it is in the hierarchy of visible | 2928 // See if it's in the bar, then if it is in the hierarchy of visible |
2912 // folder menus. | 2929 // folder menus. |
2913 if (bookmarkModel_->bookmark_bar_node() == node) | 2930 if (bookmarkModel_->bookmark_bar_node() == node) |
2914 return self; | 2931 return self; |
2915 return [folderController_ controllerForNode:node]; | 2932 return [folderController_ controllerForNode:node]; |
2916 } | 2933 } |
2917 | 2934 |
2918 @end | 2935 @end |
OLD | NEW |