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_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" |
6 | 6 |
7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
| 8 #include "base/metrics/user_metrics.h" |
8 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
9 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" | 10 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
14 #import "chrome/browser/ui/cocoa/bubble_sync_promo_controller.h" | 15 #import "chrome/browser/ui/cocoa/bubble_sync_promo_controller.h" |
15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 16 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
16 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 17 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
17 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 18 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
18 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 19 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
19 #include "chrome/grit/chromium_strings.h" | 20 #include "chrome/grit/chromium_strings.h" |
20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
21 #include "components/bookmarks/browser/bookmark_model.h" | 22 #include "components/bookmarks/browser/bookmark_model.h" |
22 #include "components/bookmarks/browser/bookmark_utils.h" | 23 #include "components/bookmarks/browser/bookmark_utils.h" |
23 #include "components/bookmarks/managed/managed_bookmark_service.h" | 24 #include "components/bookmarks/managed/managed_bookmark_service.h" |
24 #include "components/signin/core/browser/signin_metrics.h" | 25 #include "components/signin/core/browser/signin_metrics.h" |
25 #include "content/public/browser/notification_observer.h" | 26 #include "content/public/browser/notification_observer.h" |
26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
27 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/user_metrics.h" | |
29 #include "ui/base/cocoa/cocoa_base_utils.h" | 29 #include "ui/base/cocoa/cocoa_base_utils.h" |
30 #include "ui/base/l10n/l10n_util_mac.h" | 30 #include "ui/base/l10n/l10n_util_mac.h" |
31 | 31 |
32 using base::UserMetricsAction; | 32 using base::UserMetricsAction; |
33 using bookmarks::BookmarkModel; | 33 using bookmarks::BookmarkModel; |
34 using bookmarks::BookmarkNode; | 34 using bookmarks::BookmarkNode; |
35 | 35 |
36 @interface BookmarkBubbleController (PrivateAPI) | 36 @interface BookmarkBubbleController (PrivateAPI) |
37 - (void)updateBookmarkNode; | 37 - (void)updateBookmarkNode; |
38 - (void)fillInFolderList; | 38 - (void)fillInFolderList; |
(...skipping 30 matching lines...) Expand all Loading... |
69 return self; | 69 return self; |
70 } | 70 } |
71 | 71 |
72 - (void)awakeFromNib { | 72 - (void)awakeFromNib { |
73 [super awakeFromNib]; | 73 [super awakeFromNib]; |
74 | 74 |
75 [[nameTextField_ cell] setUsesSingleLineMode:YES]; | 75 [[nameTextField_ cell] setUsesSingleLineMode:YES]; |
76 | 76 |
77 Browser* browser = chrome::FindBrowserWithWindow(self.parentWindow); | 77 Browser* browser = chrome::FindBrowserWithWindow(self.parentWindow); |
78 if (SyncPromoUI::ShouldShowSyncPromo(browser->profile())) { | 78 if (SyncPromoUI::ShouldShowSyncPromo(browser->profile())) { |
79 content::RecordAction( | 79 base::RecordAction( |
80 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble")); | 80 base::UserMetricsAction("Signin_Impression_FromBookmarkBubble")); |
81 | 81 |
82 syncPromoController_.reset( | 82 syncPromoController_.reset( |
83 [[BubbleSyncPromoController alloc] | 83 [[BubbleSyncPromoController alloc] |
84 initWithBrowser:browser | 84 initWithBrowser:browser |
85 promoStringId:IDS_BOOKMARK_SYNC_PROMO_MESSAGE | 85 promoStringId:IDS_BOOKMARK_SYNC_PROMO_MESSAGE |
86 linkStringId:IDS_BOOKMARK_SYNC_PROMO_LINK | 86 linkStringId:IDS_BOOKMARK_SYNC_PROMO_LINK |
87 accessPoint: | 87 accessPoint: |
88 signin_metrics::AccessPoint::ACCESS_POINT_BOOKMARK_BUBBLE]); | 88 signin_metrics::AccessPoint::ACCESS_POINT_BOOKMARK_BUBBLE]); |
89 [syncPromoPlaceholder_ addSubview:[syncPromoController_ view]]; | 89 [syncPromoPlaceholder_ addSubview:[syncPromoController_ view]]; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 194 } |
195 | 195 |
196 // Shows the bookmark editor sheet for more advanced editing. | 196 // Shows the bookmark editor sheet for more advanced editing. |
197 - (void)showEditor { | 197 - (void)showEditor { |
198 [self ok:self]; | 198 [self ok:self]; |
199 // Send the action up through the responder chain. | 199 // Send the action up through the responder chain. |
200 [NSApp sendAction:@selector(editBookmarkNode:) to:nil from:self]; | 200 [NSApp sendAction:@selector(editBookmarkNode:) to:nil from:self]; |
201 } | 201 } |
202 | 202 |
203 - (IBAction)edit:(id)sender { | 203 - (IBAction)edit:(id)sender { |
204 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 204 base::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
205 [self showEditor]; | 205 [self showEditor]; |
206 } | 206 } |
207 | 207 |
208 - (IBAction)ok:(id)sender { | 208 - (IBAction)ok:(id)sender { |
209 [self updateBookmarkNode]; | 209 [self updateBookmarkNode]; |
210 [self close]; | 210 [self close]; |
211 } | 211 } |
212 | 212 |
213 // By implementing this, ESC causes the window to go away. If clicking the | 213 // By implementing this, ESC causes the window to go away. If clicking the |
214 // star was what prompted this bubble to appear (i.e., not already bookmarked), | 214 // star was what prompted this bubble to appear (i.e., not already bookmarked), |
215 // remove the bookmark. | 215 // remove the bookmark. |
216 - (IBAction)cancel:(id)sender { | 216 - (IBAction)cancel:(id)sender { |
217 if (!alreadyBookmarked_) { | 217 if (!alreadyBookmarked_) { |
218 // |-remove:| calls |-close| so don't do it. | 218 // |-remove:| calls |-close| so don't do it. |
219 [self remove:sender]; | 219 [self remove:sender]; |
220 } else { | 220 } else { |
221 [self dismissWithoutEditing:nil]; | 221 [self dismissWithoutEditing:nil]; |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 - (IBAction)remove:(id)sender { | 225 - (IBAction)remove:(id)sender { |
226 bookmarks::RemoveAllBookmarks(model_, node_->url()); | 226 bookmarks::RemoveAllBookmarks(model_, node_->url()); |
227 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | 227 base::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); |
228 node_ = NULL; // no longer valid | 228 node_ = NULL; // no longer valid |
229 [self ok:sender]; | 229 [self ok:sender]; |
230 } | 230 } |
231 | 231 |
232 // The controller is the target of the pop up button box action so it can | 232 // The controller is the target of the pop up button box action so it can |
233 // handle when "choose another folder" was picked. | 233 // handle when "choose another folder" was picked. |
234 - (IBAction)folderChanged:(id)sender { | 234 - (IBAction)folderChanged:(id)sender { |
235 DCHECK([sender isEqual:folderPopUpButton_]); | 235 DCHECK([sender isEqual:folderPopUpButton_]); |
236 // It is possible that due to model change our parent window has been closed | 236 // It is possible that due to model change our parent window has been closed |
237 // but the popup is still showing and able to notify the controller of a | 237 // but the popup is still showing and able to notify the controller of a |
238 // folder change. We ignore the sender in this case. | 238 // folder change. We ignore the sender in this case. |
239 if (!self.parentWindow) | 239 if (!self.parentWindow) |
240 return; | 240 return; |
241 NSMenuItem* selected = [folderPopUpButton_ selectedItem]; | 241 NSMenuItem* selected = [folderPopUpButton_ selectedItem]; |
242 if ([selected representedObject] == | 242 if ([selected representedObject] == |
243 [[self class] chooseAnotherFolderObject]) { | 243 [[self class] chooseAnotherFolderObject]) { |
244 content::RecordAction( | 244 base::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
245 UserMetricsAction("BookmarkBubble_EditFromCombobox")); | |
246 [self showEditor]; | 245 [self showEditor]; |
247 } | 246 } |
248 } | 247 } |
249 | 248 |
250 // The controller is the delegate of the window so it receives did resign key | 249 // The controller is the delegate of the window so it receives did resign key |
251 // notifications. When key is resigned mirror Windows behavior and close the | 250 // notifications. When key is resigned mirror Windows behavior and close the |
252 // window. | 251 // window. |
253 - (void)windowDidResignKey:(NSNotification*)notification { | 252 - (void)windowDidResignKey:(NSNotification*)notification { |
254 NSWindow* window = [self window]; | 253 NSWindow* window = [self window]; |
255 DCHECK_EQ([notification object], window); | 254 DCHECK_EQ([notification object], window); |
256 if ([window isVisible]) { | 255 if ([window isVisible]) { |
257 // If the window isn't visible, it is already closed, and this notification | 256 // If the window isn't visible, it is already closed, and this notification |
258 // has been sent as part of the closing operation, so no need to close. | 257 // has been sent as part of the closing operation, so no need to close. |
259 [self ok:self]; | 258 [self ok:self]; |
260 } | 259 } |
261 } | 260 } |
262 | 261 |
263 // Look at the dialog; if the user has changed anything, update the | 262 // Look at the dialog; if the user has changed anything, update the |
264 // bookmark node to reflect this. | 263 // bookmark node to reflect this. |
265 - (void)updateBookmarkNode { | 264 - (void)updateBookmarkNode { |
266 if (!node_) return; | 265 if (!node_) return; |
267 | 266 |
268 // First the title... | 267 // First the title... |
269 NSString* oldTitle = base::SysUTF16ToNSString(node_->GetTitle()); | 268 NSString* oldTitle = base::SysUTF16ToNSString(node_->GetTitle()); |
270 NSString* newTitle = [nameTextField_ stringValue]; | 269 NSString* newTitle = [nameTextField_ stringValue]; |
271 if (![oldTitle isEqual:newTitle]) { | 270 if (![oldTitle isEqual:newTitle]) { |
272 model_->SetTitle(node_, base::SysNSStringToUTF16(newTitle)); | 271 model_->SetTitle(node_, base::SysNSStringToUTF16(newTitle)); |
273 content::RecordAction( | 272 base::RecordAction(UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
274 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | |
275 } | 273 } |
276 // Then the parent folder. | 274 // Then the parent folder. |
277 const BookmarkNode* oldParent = node_->parent(); | 275 const BookmarkNode* oldParent = node_->parent(); |
278 NSMenuItem* selectedItem = [folderPopUpButton_ selectedItem]; | 276 NSMenuItem* selectedItem = [folderPopUpButton_ selectedItem]; |
279 id representedObject = [selectedItem representedObject]; | 277 id representedObject = [selectedItem representedObject]; |
280 if (representedObject == [[self class] chooseAnotherFolderObject]) { | 278 if (representedObject == [[self class] chooseAnotherFolderObject]) { |
281 // "Choose another folder..." | 279 // "Choose another folder..." |
282 return; | 280 return; |
283 } | 281 } |
284 const BookmarkNode* newParent = | 282 const BookmarkNode* newParent = |
285 static_cast<const BookmarkNode*>([representedObject pointerValue]); | 283 static_cast<const BookmarkNode*>([representedObject pointerValue]); |
286 DCHECK(newParent); | 284 DCHECK(newParent); |
287 if (oldParent != newParent) { | 285 if (oldParent != newParent) { |
288 int index = newParent->child_count(); | 286 int index = newParent->child_count(); |
289 model_->Move(node_, newParent, index); | 287 model_->Move(node_, newParent, index); |
290 content::RecordAction(UserMetricsAction("BookmarkBubble_ChangeParent")); | 288 base::RecordAction(UserMetricsAction("BookmarkBubble_ChangeParent")); |
291 } | 289 } |
292 } | 290 } |
293 | 291 |
294 // Fill in all information related to the folder pop up button. | 292 // Fill in all information related to the folder pop up button. |
295 - (void)fillInFolderList { | 293 - (void)fillInFolderList { |
296 [nameTextField_ setStringValue:base::SysUTF16ToNSString(node_->GetTitle())]; | 294 [nameTextField_ setStringValue:base::SysUTF16ToNSString(node_->GetTitle())]; |
297 DCHECK([folderPopUpButton_ numberOfItems] == 0); | 295 DCHECK([folderPopUpButton_ numberOfItems] == 0); |
298 [self addFolderNodes:model_->root_node() | 296 [self addFolderNodes:model_->root_node() |
299 toPopUpButton:folderPopUpButton_ | 297 toPopUpButton:folderPopUpButton_ |
300 indentation:0]; | 298 indentation:0]; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; | 374 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; |
377 DCHECK(idx != -1); | 375 DCHECK(idx != -1); |
378 [folderPopUpButton_ selectItemAtIndex:idx]; | 376 [folderPopUpButton_ selectItemAtIndex:idx]; |
379 } | 377 } |
380 | 378 |
381 - (NSPopUpButton*)folderPopUpButton { | 379 - (NSPopUpButton*)folderPopUpButton { |
382 return folderPopUpButton_; | 380 return folderPopUpButton_; |
383 } | 381 } |
384 | 382 |
385 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) | 383 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) |
OLD | NEW |