OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/bookmark_bubble_controller.h" | 5 #import "chrome/browser/cocoa/bookmark_bubble_controller.h" |
6 #include "app/l10n_util_mac.h" | 6 #include "app/l10n_util_mac.h" |
7 #include "base/mac_util.h" | 7 #include "base/mac_util.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #import "chrome/browser/cocoa/bookmark_button.h" |
10 #import "chrome/browser/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/cocoa/browser_window_controller.h" |
11 #import "chrome/browser/cocoa/info_bubble_view.h" | 12 #import "chrome/browser/cocoa/info_bubble_view.h" |
12 #include "chrome/browser/metrics/user_metrics.h" | 13 #include "chrome/browser/metrics/user_metrics.h" |
13 #include "chrome/common/notification_observer.h" | 14 #include "chrome/common/notification_observer.h" |
14 #include "chrome/common/notification_registrar.h" | 15 #include "chrome/common/notification_registrar.h" |
15 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
17 | 18 |
18 | 19 |
19 // Simple class to watch for tab creation/destruction and close the bubble. | 20 // Simple class to watch for tab creation/destruction and close the bubble. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 object:parentWindow_]; | 102 object:parentWindow_]; |
102 } | 103 } |
103 return self; | 104 return self; |
104 } | 105 } |
105 | 106 |
106 - (void)dealloc { | 107 - (void)dealloc { |
107 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 108 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
108 [super dealloc]; | 109 [super dealloc]; |
109 } | 110 } |
110 | 111 |
| 112 // If this is a new bookmark somewhere visible (e.g. on the bookmark |
| 113 // bar), pulse it. Else, call ourself recursively with our parent |
| 114 // until we find something visible to pulse. |
| 115 - (void)startPulsingBookmarkButton:(const BookmarkNode*)node { |
| 116 while (node) { |
| 117 if ((node->GetParent() == model_->GetBookmarkBarNode()) || |
| 118 (node == model_->other_node())) { |
| 119 pulsingBookmarkNode_ = node; |
| 120 NSValue *value = [NSValue valueWithPointer:node]; |
| 121 NSDictionary *dict = [NSDictionary |
| 122 dictionaryWithObjectsAndKeys:value, |
| 123 bookmark_button::kBookmarkKey, |
| 124 [NSNumber numberWithBool:YES], |
| 125 bookmark_button::kBookmarkPulseFlagKey, |
| 126 nil]; |
| 127 [[NSNotificationCenter defaultCenter] |
| 128 postNotificationName:bookmark_button::kPulseBookmarkButtonNotification |
| 129 object:self |
| 130 userInfo:dict]; |
| 131 return; |
| 132 } |
| 133 node = node->GetParent(); |
| 134 } |
| 135 } |
| 136 |
| 137 - (void)stopPulsingBookmarkButton { |
| 138 NSValue *value = [NSValue valueWithPointer:pulsingBookmarkNode_]; |
| 139 pulsingBookmarkNode_ = NULL; |
| 140 NSDictionary *dict = [NSDictionary |
| 141 dictionaryWithObjectsAndKeys:value, |
| 142 bookmark_button::kBookmarkKey, |
| 143 [NSNumber numberWithBool:NO], |
| 144 bookmark_button::kBookmarkPulseFlagKey, |
| 145 nil]; |
| 146 [[NSNotificationCenter defaultCenter] |
| 147 postNotificationName:bookmark_button::kPulseBookmarkButtonNotification |
| 148 object:self |
| 149 userInfo:dict]; |
| 150 } |
| 151 |
111 // Close the bookmark bubble without changing anything. Unlike a | 152 // Close the bookmark bubble without changing anything. Unlike a |
112 // typical dialog's OK/Cancel, where Cancel is "do nothing", all | 153 // typical dialog's OK/Cancel, where Cancel is "do nothing", all |
113 // buttons on the bubble have the capacity to change the bookmark | 154 // buttons on the bubble have the capacity to change the bookmark |
114 // model. This is an IBOutlet-looking entry point to remove the | 155 // model. This is an IBOutlet-looking entry point to remove the |
115 // dialog without touching the model. | 156 // dialog without touching the model. |
116 - (void)dismissWithoutEditing:(id)sender { | 157 - (void)dismissWithoutEditing:(id)sender { |
117 [self close]; | 158 [self close]; |
118 } | 159 } |
119 | 160 |
120 - (void)parentWindowWillClose:(NSNotification*)notification { | 161 - (void)parentWindowWillClose:(NSNotification*)notification { |
121 [self close]; | 162 [self close]; |
122 } | 163 } |
123 | 164 |
124 - (void)windowWillClose:(NSNotification*)notification { | 165 - (void)windowWillClose:(NSNotification*)notification { |
125 // We caught a close so we don't need to watch for the parent closing. | 166 // We caught a close so we don't need to watch for the parent closing. |
126 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 167 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
127 bookmark_observer_.reset(NULL); | 168 bookmark_observer_.reset(NULL); |
128 chrome_observer_.reset(NULL); | 169 chrome_observer_.reset(NULL); |
| 170 [self stopPulsingBookmarkButton]; |
129 [self autorelease]; | 171 [self autorelease]; |
130 } | 172 } |
131 | 173 |
132 // We want this to be a child of a browser window. addChildWindow: | 174 // We want this to be a child of a browser window. addChildWindow: |
133 // (called from this function) will bring the window on-screen; | 175 // (called from this function) will bring the window on-screen; |
134 // unfortunately, [NSWindowController showWindow:] will also bring it | 176 // unfortunately, [NSWindowController showWindow:] will also bring it |
135 // on-screen (but will cause unexpected changes to the window's | 177 // on-screen (but will cause unexpected changes to the window's |
136 // position). We cannot have an addChildWindow: and a subsequent | 178 // position). We cannot have an addChildWindow: and a subsequent |
137 // showWindow:. Thus, we have our own version. | 179 // showWindow:. Thus, we have our own version. |
138 - (void)showWindow:(id)sender { | 180 - (void)showWindow:(id)sender { |
(...skipping 27 matching lines...) Expand all Loading... |
166 // dialog, the bookmark bubble's cancel: means "don't add this as a | 208 // dialog, the bookmark bubble's cancel: means "don't add this as a |
167 // bookmark", not "cancel editing". We must take extra care to not | 209 // bookmark", not "cancel editing". We must take extra care to not |
168 // touch the bookmark in this selector. | 210 // touch the bookmark in this selector. |
169 bookmark_observer_.reset(new BookmarkModelObserverForCocoa( | 211 bookmark_observer_.reset(new BookmarkModelObserverForCocoa( |
170 node_, model_, | 212 node_, model_, |
171 self, | 213 self, |
172 @selector(dismissWithoutEditing:))); | 214 @selector(dismissWithoutEditing:))); |
173 chrome_observer_.reset(new BookmarkBubbleNotificationBridge( | 215 chrome_observer_.reset(new BookmarkBubbleNotificationBridge( |
174 self, @selector(dismissWithoutEditing:))); | 216 self, @selector(dismissWithoutEditing:))); |
175 | 217 |
| 218 // Pulse something interesting on the bookmark bar. |
| 219 [self startPulsingBookmarkButton:node_]; |
| 220 |
176 [window makeKeyAndOrderFront:self]; | 221 [window makeKeyAndOrderFront:self]; |
177 } | 222 } |
178 | 223 |
179 - (void)close { | 224 - (void)close { |
180 [[BrowserWindowController browserWindowControllerForWindow:parentWindow_] | 225 [[BrowserWindowController browserWindowControllerForWindow:parentWindow_] |
181 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; | 226 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
182 [parentWindow_ removeChildWindow:[self window]]; | 227 [parentWindow_ removeChildWindow:[self window]]; |
183 | 228 |
184 // If you quit while the bubble is open, sometimes we get a | 229 // If you quit while the bubble is open, sometimes we get a |
185 // DidResignKey before we get our parent's WindowWillClose and | 230 // DidResignKey before we get our parent's WindowWillClose and |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; | 412 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; |
368 DCHECK(idx != -1); | 413 DCHECK(idx != -1); |
369 [folderPopUpButton_ selectItemAtIndex:idx]; | 414 [folderPopUpButton_ selectItemAtIndex:idx]; |
370 } | 415 } |
371 | 416 |
372 - (NSPopUpButton*)folderPopUpButton { | 417 - (NSPopUpButton*)folderPopUpButton { |
373 return folderPopUpButton_; | 418 return folderPopUpButton_; |
374 } | 419 } |
375 | 420 |
376 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) | 421 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) |
OLD | NEW |