Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.mm

Issue 306293006: Introduce ChromeBookmarkClientFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@364865
Patch Set: Add missing dependency in components/policy/policy_browser.gypi Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 10 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // folder" item in the pop up. 47 // folder" item in the pop up.
48 static ChooseAnotherFolder* object = nil; 48 static ChooseAnotherFolder* object = nil;
49 if (!object) { 49 if (!object) {
50 object = [[ChooseAnotherFolder alloc] init]; 50 object = [[ChooseAnotherFolder alloc] init];
51 } 51 }
52 return object; 52 return object;
53 } 53 }
54 54
55 - (id)initWithParentWindow:(NSWindow*)parentWindow 55 - (id)initWithParentWindow:(NSWindow*)parentWindow
56 client:(ChromeBookmarkClient*)client 56 client:(ChromeBookmarkClient*)client
57 model:(BookmarkModel*)model
57 node:(const BookmarkNode*)node 58 node:(const BookmarkNode*)node
58 alreadyBookmarked:(BOOL)alreadyBookmarked { 59 alreadyBookmarked:(BOOL)alreadyBookmarked {
59 DCHECK(client); 60 DCHECK(client);
60 DCHECK(node); 61 DCHECK(node);
61 if ((self = [super initWithWindowNibPath:@"BookmarkBubble" 62 if ((self = [super initWithWindowNibPath:@"BookmarkBubble"
62 parentWindow:parentWindow 63 parentWindow:parentWindow
63 anchoredAt:NSZeroPoint])) { 64 anchoredAt:NSZeroPoint])) {
64 client_ = client; 65 client_ = client;
66 model_ = model;
65 node_ = node; 67 node_ = node;
66 alreadyBookmarked_ = alreadyBookmarked; 68 alreadyBookmarked_ = alreadyBookmarked;
67 } 69 }
68 return self; 70 return self;
69 } 71 }
70 72
71 - (void)awakeFromNib { 73 - (void)awakeFromNib {
72 [super awakeFromNib]; 74 [super awakeFromNib];
73 75
74 [[nameTextField_ cell] setUsesSingleLineMode:YES]; 76 [[nameTextField_ cell] setUsesSingleLineMode:YES];
(...skipping 21 matching lines...) Expand all
96 syncPromoHeight - [syncPromoController_ borderWidth]; 98 syncPromoHeight - [syncPromoController_ borderWidth];
97 [[self window] setFrame:bubbleFrame display:YES]; 99 [[self window] setFrame:bubbleFrame display:YES];
98 } 100 }
99 } 101 }
100 102
101 // If this is a new bookmark somewhere visible (e.g. on the bookmark 103 // If this is a new bookmark somewhere visible (e.g. on the bookmark
102 // bar), pulse it. Else, call ourself recursively with our parent 104 // bar), pulse it. Else, call ourself recursively with our parent
103 // until we find something visible to pulse. 105 // until we find something visible to pulse.
104 - (void)startPulsingBookmarkButton:(const BookmarkNode*)node { 106 - (void)startPulsingBookmarkButton:(const BookmarkNode*)node {
105 while (node) { 107 while (node) {
106 if ((node->parent() == client_->model()->bookmark_bar_node()) || 108 if ((node->parent() == model_->bookmark_bar_node()) ||
107 (node->parent() == client_->managed_node()) || 109 (node->parent() == client_->managed_node()) ||
108 (node == client_->model()->other_node())) { 110 (node == model_->other_node())) {
109 pulsingBookmarkNode_ = node; 111 pulsingBookmarkNode_ = node;
110 bookmarkObserver_->StartObservingNode(pulsingBookmarkNode_); 112 bookmarkObserver_->StartObservingNode(pulsingBookmarkNode_);
111 NSValue *value = [NSValue valueWithPointer:node]; 113 NSValue *value = [NSValue valueWithPointer:node];
112 NSDictionary *dict = [NSDictionary 114 NSDictionary *dict = [NSDictionary
113 dictionaryWithObjectsAndKeys:value, 115 dictionaryWithObjectsAndKeys:value,
114 bookmark_button::kBookmarkKey, 116 bookmark_button::kBookmarkKey,
115 [NSNumber numberWithBool:YES], 117 [NSNumber numberWithBool:YES],
116 bookmark_button::kBookmarkPulseFlagKey, 118 bookmark_button::kBookmarkPulseFlagKey,
117 nil]; 119 nil];
118 [[NSNotificationCenter defaultCenter] 120 [[NSNotificationCenter defaultCenter]
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 l10n_util::GetNSString(IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED); 192 l10n_util::GetNSString(IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED);
191 [bigTitle_ setStringValue:title]; 193 [bigTitle_ setStringValue:title];
192 } 194 }
193 195
194 [self fillInFolderList]; 196 [self fillInFolderList];
195 197
196 // Ping me when things change out from under us. Unlike a normal 198 // Ping me when things change out from under us. Unlike a normal
197 // dialog, the bookmark bubble's cancel: means "don't add this as a 199 // dialog, the bookmark bubble's cancel: means "don't add this as a
198 // bookmark", not "cancel editing". We must take extra care to not 200 // bookmark", not "cancel editing". We must take extra care to not
199 // touch the bookmark in this selector. 201 // touch the bookmark in this selector.
200 bookmarkObserver_.reset(new BookmarkModelObserverForCocoa( 202 bookmarkObserver_.reset(
201 client_->model(), 203 new BookmarkModelObserverForCocoa(model_, ^(BOOL nodeWasDeleted) {
202 ^(BOOL nodeWasDeleted) {
203 // If a watched node was deleted, the pointer to the pulsing button 204 // If a watched node was deleted, the pointer to the pulsing button
204 // is likely stale. 205 // is likely stale.
205 if (nodeWasDeleted) 206 if (nodeWasDeleted)
206 pulsingBookmarkNode_ = NULL; 207 pulsingBookmarkNode_ = NULL;
207 [self dismissWithoutEditing:nil]; 208 [self dismissWithoutEditing:nil];
208 })); 209 }));
209 bookmarkObserver_->StartObservingNode(node_); 210 bookmarkObserver_->StartObservingNode(node_);
210 211
211 // Pulse something interesting on the bookmark bar. 212 // Pulse something interesting on the bookmark bar.
212 [self startPulsingBookmarkButton:node_]; 213 [self startPulsingBookmarkButton:node_];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 if (!alreadyBookmarked_) { 249 if (!alreadyBookmarked_) {
249 // |-remove:| calls |-close| so don't do it. 250 // |-remove:| calls |-close| so don't do it.
250 [self remove:sender]; 251 [self remove:sender];
251 } else { 252 } else {
252 [self ok:sender]; 253 [self ok:sender];
253 } 254 }
254 } 255 }
255 256
256 - (IBAction)remove:(id)sender { 257 - (IBAction)remove:(id)sender {
257 [self stopPulsingBookmarkButton]; 258 [self stopPulsingBookmarkButton];
258 bookmark_utils::RemoveAllBookmarks(client_->model(), node_->url()); 259 bookmark_utils::RemoveAllBookmarks(model_, node_->url());
259 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); 260 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"));
260 node_ = NULL; // no longer valid 261 node_ = NULL; // no longer valid
261 [self ok:sender]; 262 [self ok:sender];
262 } 263 }
263 264
264 // The controller is the target of the pop up button box action so it can 265 // The controller is the target of the pop up button box action so it can
265 // handle when "choose another folder" was picked. 266 // handle when "choose another folder" was picked.
266 - (IBAction)folderChanged:(id)sender { 267 - (IBAction)folderChanged:(id)sender {
267 DCHECK([sender isEqual:folderPopUpButton_]); 268 DCHECK([sender isEqual:folderPopUpButton_]);
268 // It is possible that due to model change our parent window has been closed 269 // It is possible that due to model change our parent window has been closed
(...skipping 25 matching lines...) Expand all
294 295
295 // Look at the dialog; if the user has changed anything, update the 296 // Look at the dialog; if the user has changed anything, update the
296 // bookmark node to reflect this. 297 // bookmark node to reflect this.
297 - (void)updateBookmarkNode { 298 - (void)updateBookmarkNode {
298 if (!node_) return; 299 if (!node_) return;
299 300
300 // First the title... 301 // First the title...
301 NSString* oldTitle = base::SysUTF16ToNSString(node_->GetTitle()); 302 NSString* oldTitle = base::SysUTF16ToNSString(node_->GetTitle());
302 NSString* newTitle = [nameTextField_ stringValue]; 303 NSString* newTitle = [nameTextField_ stringValue];
303 if (![oldTitle isEqual:newTitle]) { 304 if (![oldTitle isEqual:newTitle]) {
304 client_->model()->SetTitle(node_, base::SysNSStringToUTF16(newTitle)); 305 model_->SetTitle(node_, base::SysNSStringToUTF16(newTitle));
305 content::RecordAction( 306 content::RecordAction(
306 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); 307 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble"));
307 } 308 }
308 // Then the parent folder. 309 // Then the parent folder.
309 const BookmarkNode* oldParent = node_->parent(); 310 const BookmarkNode* oldParent = node_->parent();
310 NSMenuItem* selectedItem = [folderPopUpButton_ selectedItem]; 311 NSMenuItem* selectedItem = [folderPopUpButton_ selectedItem];
311 id representedObject = [selectedItem representedObject]; 312 id representedObject = [selectedItem representedObject];
312 if ([representedObject isEqual:[[self class] chooseAnotherFolderObject]]) { 313 if ([representedObject isEqual:[[self class] chooseAnotherFolderObject]]) {
313 // "Choose another folder..." 314 // "Choose another folder..."
314 return; 315 return;
315 } 316 }
316 const BookmarkNode* newParent = 317 const BookmarkNode* newParent =
317 static_cast<const BookmarkNode*>([representedObject pointerValue]); 318 static_cast<const BookmarkNode*>([representedObject pointerValue]);
318 DCHECK(newParent); 319 DCHECK(newParent);
319 if (oldParent != newParent) { 320 if (oldParent != newParent) {
320 int index = newParent->child_count(); 321 int index = newParent->child_count();
321 client_->model()->Move(node_, newParent, index); 322 model_->Move(node_, newParent, index);
322 content::RecordAction(UserMetricsAction("BookmarkBubble_ChangeParent")); 323 content::RecordAction(UserMetricsAction("BookmarkBubble_ChangeParent"));
323 } 324 }
324 } 325 }
325 326
326 // Fill in all information related to the folder pop up button. 327 // Fill in all information related to the folder pop up button.
327 - (void)fillInFolderList { 328 - (void)fillInFolderList {
328 [nameTextField_ setStringValue:base::SysUTF16ToNSString(node_->GetTitle())]; 329 [nameTextField_ setStringValue:base::SysUTF16ToNSString(node_->GetTitle())];
329 DCHECK([folderPopUpButton_ numberOfItems] == 0); 330 DCHECK([folderPopUpButton_ numberOfItems] == 0);
330 [self addFolderNodes:client_->model()->root_node() 331 [self addFolderNodes:model_->root_node()
331 toPopUpButton:folderPopUpButton_ 332 toPopUpButton:folderPopUpButton_
332 indentation:0]; 333 indentation:0];
333 NSMenu* menu = [folderPopUpButton_ menu]; 334 NSMenu* menu = [folderPopUpButton_ menu];
334 NSString* title = [[self class] chooseAnotherFolderString]; 335 NSString* title = [[self class] chooseAnotherFolderString];
335 NSMenuItem *item = [menu addItemWithTitle:title 336 NSMenuItem *item = [menu addItemWithTitle:title
336 action:NULL 337 action:NULL
337 keyEquivalent:@""]; 338 keyEquivalent:@""];
338 ChooseAnotherFolder* obj = [[self class] chooseAnotherFolderObject]; 339 ChooseAnotherFolder* obj = [[self class] chooseAnotherFolderObject];
339 [item setRepresentedObject:obj]; 340 [item setRepresentedObject:obj];
340 // Finally, select the current parent. 341 // Finally, select the current parent.
(...skipping 14 matching lines...) Expand all
355 + (NSString*)chooseAnotherFolderString { 356 + (NSString*)chooseAnotherFolderString {
356 return l10n_util::GetNSStringWithFixup( 357 return l10n_util::GetNSStringWithFixup(
357 IDS_BOOKMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER); 358 IDS_BOOKMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER);
358 } 359 }
359 360
360 // For the given folder node, walk the tree and add folder names to 361 // For the given folder node, walk the tree and add folder names to
361 // the given pop up button. 362 // the given pop up button.
362 - (void)addFolderNodes:(const BookmarkNode*)parent 363 - (void)addFolderNodes:(const BookmarkNode*)parent
363 toPopUpButton:(NSPopUpButton*)button 364 toPopUpButton:(NSPopUpButton*)button
364 indentation:(int)indentation { 365 indentation:(int)indentation {
365 if (!client_->model()->is_root_node(parent)) { 366 if (!model_->is_root_node(parent)) {
366 NSString* title = base::SysUTF16ToNSString(parent->GetTitle()); 367 NSString* title = base::SysUTF16ToNSString(parent->GetTitle());
367 NSMenu* menu = [button menu]; 368 NSMenu* menu = [button menu];
368 NSMenuItem* item = [menu addItemWithTitle:title 369 NSMenuItem* item = [menu addItemWithTitle:title
369 action:NULL 370 action:NULL
370 keyEquivalent:@""]; 371 keyEquivalent:@""];
371 [item setRepresentedObject:[NSValue valueWithPointer:parent]]; 372 [item setRepresentedObject:[NSValue valueWithPointer:parent]];
372 [item setIndentationLevel:indentation]; 373 [item setIndentationLevel:indentation];
373 ++indentation; 374 ++indentation;
374 } 375 }
375 for (int i = 0; i < parent->child_count(); i++) { 376 for (int i = 0; i < parent->child_count(); i++) {
(...skipping 22 matching lines...) Expand all
398 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; 399 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue];
399 DCHECK(idx != -1); 400 DCHECK(idx != -1);
400 [folderPopUpButton_ selectItemAtIndex:idx]; 401 [folderPopUpButton_ selectItemAtIndex:idx];
401 } 402 }
402 403
403 - (NSPopUpButton*)folderPopUpButton { 404 - (NSPopUpButton*)folderPopUpButton {
404 return folderPopUpButton_; 405 return folderPopUpButton_;
405 } 406 }
406 407
407 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) 408 @end // implementation BookmarkBubbleController(ExposedForUnitTesting)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698