Chromium Code Reviews| Index: chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm |
| index 2fed9b9645ee72677b6a86613e97b982fb1a75a1..4a5eff6dda7c32f6e797aac7439c210601e98a8b 100644 |
| --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm |
| +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm |
| @@ -6,6 +6,7 @@ |
| #include "base/mac/bundle_locations.h" |
| #include "base/strings/sys_string_conversions.h" |
| +#include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_finder.h" |
| #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
| @@ -54,6 +55,7 @@ using bookmarks::BookmarkNode; |
| } |
| - (id)initWithParentWindow:(NSWindow*)parentWindow |
| + observer:(bookmarks::BookmarkBubbleObserver*)observer |
| managed:(bookmarks::ManagedBookmarkService*)managed |
| model:(BookmarkModel*)model |
| node:(const BookmarkNode*)node |
| @@ -63,6 +65,7 @@ using bookmarks::BookmarkNode; |
| if ((self = [super initWithWindowNibPath:@"BookmarkBubble" |
| parentWindow:parentWindow |
| anchoredAt:NSZeroPoint])) { |
| + bookmarkBubbleObserver_ = observer; |
| managedBookmarkService_ = managed; |
| model_ = model; |
| node_ = node; |
| @@ -101,52 +104,12 @@ using bookmarks::BookmarkNode; |
| } |
| } |
| -// If this is a new bookmark somewhere visible (e.g. on the bookmark |
| -// bar), pulse it. Else, call ourself recursively with our parent |
| -// until we find something visible to pulse. |
| -- (void)startPulsingBookmarkButton:(const BookmarkNode*)node { |
| - while (node) { |
| - if ((node->parent() == model_->bookmark_bar_node()) || |
| - (node->parent() == |
| - managedBookmarkService_->managed_node()) || |
| - (node->parent() == managedBookmarkService_->supervised_node()) || |
| - (node == model_->other_node())) { |
| - pulsingBookmarkNode_ = node; |
| - bookmarkObserver_->StartObservingNode(pulsingBookmarkNode_); |
| - NSValue *value = [NSValue valueWithPointer:node]; |
| - NSDictionary *dict = [NSDictionary |
| - dictionaryWithObjectsAndKeys:value, |
| - bookmark_button::kBookmarkKey, |
| - [NSNumber numberWithBool:YES], |
| - bookmark_button::kBookmarkPulseFlagKey, |
| - nil]; |
| - [[NSNotificationCenter defaultCenter] |
| - postNotificationName:bookmark_button::kPulseBookmarkButtonNotification |
| - object:self |
| - userInfo:dict]; |
| - return; |
| - } |
| - node = node->parent(); |
| - } |
| -} |
| - |
| -- (void)stopPulsingBookmarkButton { |
| - if (!pulsingBookmarkNode_) |
| +- (void)notifyBubbleClosed { |
| + if (!bookmarkBubbleObserver_) |
| return; |
| - NSValue *value = [NSValue valueWithPointer:pulsingBookmarkNode_]; |
| - if (bookmarkObserver_) |
| - bookmarkObserver_->StopObservingNode(pulsingBookmarkNode_); |
| - pulsingBookmarkNode_ = NULL; |
| - NSDictionary *dict = [NSDictionary |
| - dictionaryWithObjectsAndKeys:value, |
| - bookmark_button::kBookmarkKey, |
| - [NSNumber numberWithBool:NO], |
| - bookmark_button::kBookmarkPulseFlagKey, |
| - nil]; |
| - [[NSNotificationCenter defaultCenter] |
| - postNotificationName:bookmark_button::kPulseBookmarkButtonNotification |
| - object:self |
| - userInfo:dict]; |
| + |
| + bookmarkBubbleObserver_->OnBookmarkBubbleHidden(); |
| + bookmarkBubbleObserver_ = nullptr; |
| } |
| // Close the bookmark bubble without changing anything. Unlike a |
| @@ -161,7 +124,7 @@ using bookmarks::BookmarkNode; |
| - (void)windowWillClose:(NSNotification*)notification { |
| // We caught a close so we don't need to watch for the parent closing. |
| bookmarkObserver_.reset(); |
| - [self stopPulsingBookmarkButton]; |
| + [self notifyBubbleClosed]; |
| [super windowWillClose:notification]; |
| } |
| @@ -172,7 +135,6 @@ using bookmarks::BookmarkNode; |
| NSWindow* parentWindow = self.parentWindow; |
| BrowserWindowController* bwc = |
| [BrowserWindowController browserWindowControllerForWindow:parentWindow]; |
| - [bwc lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; |
| InfoBubbleView* bubble = self.bubble; |
| [bubble setArrowLocation:info_bubble::kTopRight]; |
| @@ -202,22 +164,16 @@ using bookmarks::BookmarkNode; |
| // dialog, the bookmark bubble's cancel: means "don't add this as a |
| // bookmark", not "cancel editing". We must take extra care to not |
| // touch the bookmark in this selector. |
| - bookmarkObserver_.reset( |
| - new BookmarkModelObserverForCocoa(model_, ^(BOOL nodeWasDeleted) { |
| - // If a watched node was deleted, the pointer to the pulsing button |
| - // is likely stale. |
| - if (nodeWasDeleted) |
| - pulsingBookmarkNode_ = NULL; |
| - [self dismissWithoutEditing:nil]; |
| - })); |
| + bookmarkObserver_.reset(new BookmarkModelObserverForCocoa(model_, ^(BOOL) { |
|
tapted
2015/08/25 01:13:21
is the BOOL argument to the closure still needed?
jackhou1
2015/08/25 04:32:29
Nope, removed.
|
| + [self dismissWithoutEditing:nil]; |
| + })); |
| bookmarkObserver_->StartObservingNode(node_); |
| - // Pulse something interesting on the bookmark bar. |
| - [self startPulsingBookmarkButton:node_]; |
| - |
| [parentWindow addChildWindow:window ordered:NSWindowAbove]; |
| [window makeKeyAndOrderFront:self]; |
| [self registerKeyStateEventTap]; |
| + |
| + bookmarkBubbleObserver_->OnBookmarkBubbleShown(node_); |
| } |
| - (void)close { |
| @@ -240,7 +196,6 @@ using bookmarks::BookmarkNode; |
| } |
| - (IBAction)ok:(id)sender { |
| - [self stopPulsingBookmarkButton]; // before parent changes |
| [self updateBookmarkNode]; |
| [self close]; |
| } |
| @@ -253,13 +208,11 @@ using bookmarks::BookmarkNode; |
| // |-remove:| calls |-close| so don't do it. |
| [self remove:sender]; |
| } else { |
| - [self stopPulsingBookmarkButton]; |
| [self dismissWithoutEditing:nil]; |
| } |
| } |
| - (IBAction)remove:(id)sender { |
| - [self stopPulsingBookmarkButton]; |
| bookmarks::RemoveAllBookmarks(model_, node_->url()); |
| content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); |
| node_ = NULL; // no longer valid |
| @@ -358,6 +311,10 @@ using bookmarks::BookmarkNode; |
| return syncPromoPlaceholder_; |
| } |
| +- (bookmarks::BookmarkBubbleObserver*)bookmarkBubbleObserver { |
| + return bookmarkBubbleObserver_; |
| +} |
| + |
| + (NSString*)chooseAnotherFolderString { |
| return l10n_util::GetNSStringWithFixup( |
| IDS_BOOKMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER); |