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/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | |
10 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_sync_promo_controller.h" | 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_sync_promo_controller.h" |
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 14 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
16 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 15 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
17 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
18 #include "components/bookmarks/browser/bookmark_model.h" | 17 #include "components/bookmarks/browser/bookmark_model.h" |
19 #include "components/bookmarks/browser/bookmark_utils.h" | 18 #include "components/bookmarks/browser/bookmark_utils.h" |
| 19 #include "components/bookmarks/managed/managed_bookmark_service.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/user_metrics.h" | 23 #include "content/public/browser/user_metrics.h" |
24 #include "ui/base/l10n/l10n_util_mac.h" | 24 #include "ui/base/l10n/l10n_util_mac.h" |
25 | 25 |
26 using base::UserMetricsAction; | 26 using base::UserMetricsAction; |
27 using bookmarks::BookmarkModel; | 27 using bookmarks::BookmarkModel; |
28 using bookmarks::BookmarkNode; | 28 using bookmarks::BookmarkNode; |
29 | 29 |
(...skipping 17 matching lines...) Expand all Loading... |
47 // Singleton object to act as a representedObject for the "choose another | 47 // Singleton object to act as a representedObject for the "choose another |
48 // folder" item in the pop up. | 48 // folder" item in the pop up. |
49 static ChooseAnotherFolder* object = nil; | 49 static ChooseAnotherFolder* object = nil; |
50 if (!object) { | 50 if (!object) { |
51 object = [[ChooseAnotherFolder alloc] init]; | 51 object = [[ChooseAnotherFolder alloc] init]; |
52 } | 52 } |
53 return object; | 53 return object; |
54 } | 54 } |
55 | 55 |
56 - (id)initWithParentWindow:(NSWindow*)parentWindow | 56 - (id)initWithParentWindow:(NSWindow*)parentWindow |
57 client:(ChromeBookmarkClient*)client | 57 managed:(bookmarks::ManagedBookmarkService*)managed |
58 model:(BookmarkModel*)model | 58 model:(BookmarkModel*)model |
59 node:(const BookmarkNode*)node | 59 node:(const BookmarkNode*)node |
60 alreadyBookmarked:(BOOL)alreadyBookmarked { | 60 alreadyBookmarked:(BOOL)alreadyBookmarked { |
61 DCHECK(client); | 61 DCHECK(managed); |
62 DCHECK(node); | 62 DCHECK(node); |
63 if ((self = [super initWithWindowNibPath:@"BookmarkBubble" | 63 if ((self = [super initWithWindowNibPath:@"BookmarkBubble" |
64 parentWindow:parentWindow | 64 parentWindow:parentWindow |
65 anchoredAt:NSZeroPoint])) { | 65 anchoredAt:NSZeroPoint])) { |
66 client_ = client; | 66 managed_ = managed; |
67 model_ = model; | 67 model_ = model; |
68 node_ = node; | 68 node_ = node; |
69 alreadyBookmarked_ = alreadyBookmarked; | 69 alreadyBookmarked_ = alreadyBookmarked; |
70 } | 70 } |
71 return self; | 71 return self; |
72 } | 72 } |
73 | 73 |
74 - (void)awakeFromNib { | 74 - (void)awakeFromNib { |
75 [super awakeFromNib]; | 75 [super awakeFromNib]; |
76 | 76 |
(...skipping 23 matching lines...) Expand all Loading... |
100 [[self window] setFrame:bubbleFrame display:YES]; | 100 [[self window] setFrame:bubbleFrame display:YES]; |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 // If this is a new bookmark somewhere visible (e.g. on the bookmark | 104 // If this is a new bookmark somewhere visible (e.g. on the bookmark |
105 // bar), pulse it. Else, call ourself recursively with our parent | 105 // bar), pulse it. Else, call ourself recursively with our parent |
106 // until we find something visible to pulse. | 106 // until we find something visible to pulse. |
107 - (void)startPulsingBookmarkButton:(const BookmarkNode*)node { | 107 - (void)startPulsingBookmarkButton:(const BookmarkNode*)node { |
108 while (node) { | 108 while (node) { |
109 if ((node->parent() == model_->bookmark_bar_node()) || | 109 if ((node->parent() == model_->bookmark_bar_node()) || |
110 (node->parent() == client_->managed_node()) || | 110 (node->parent() == managed_->managed_node()) || |
111 (node->parent() == client_->supervised_node()) || | 111 (node->parent() == managed_->supervised_node()) || |
112 (node == model_->other_node())) { | 112 (node == model_->other_node())) { |
113 pulsingBookmarkNode_ = node; | 113 pulsingBookmarkNode_ = node; |
114 bookmarkObserver_->StartObservingNode(pulsingBookmarkNode_); | 114 bookmarkObserver_->StartObservingNode(pulsingBookmarkNode_); |
115 NSValue *value = [NSValue valueWithPointer:node]; | 115 NSValue *value = [NSValue valueWithPointer:node]; |
116 NSDictionary *dict = [NSDictionary | 116 NSDictionary *dict = [NSDictionary |
117 dictionaryWithObjectsAndKeys:value, | 117 dictionaryWithObjectsAndKeys:value, |
118 bookmark_button::kBookmarkKey, | 118 bookmark_button::kBookmarkKey, |
119 [NSNumber numberWithBool:YES], | 119 [NSNumber numberWithBool:YES], |
120 bookmark_button::kBookmarkPulseFlagKey, | 120 bookmark_button::kBookmarkPulseFlagKey, |
121 nil]; | 121 nil]; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 NSMenuItem* item = [menu addItemWithTitle:title | 373 NSMenuItem* item = [menu addItemWithTitle:title |
374 action:NULL | 374 action:NULL |
375 keyEquivalent:@""]; | 375 keyEquivalent:@""]; |
376 [item setRepresentedObject:[NSValue valueWithPointer:parent]]; | 376 [item setRepresentedObject:[NSValue valueWithPointer:parent]]; |
377 [item setIndentationLevel:indentation]; | 377 [item setIndentationLevel:indentation]; |
378 ++indentation; | 378 ++indentation; |
379 } | 379 } |
380 for (int i = 0; i < parent->child_count(); i++) { | 380 for (int i = 0; i < parent->child_count(); i++) { |
381 const BookmarkNode* child = parent->GetChild(i); | 381 const BookmarkNode* child = parent->GetChild(i); |
382 if (child->is_folder() && child->IsVisible() && | 382 if (child->is_folder() && child->IsVisible() && |
383 client_->CanBeEditedByUser(child)) { | 383 managed_->CanBeEditedByUser(child)) { |
384 [self addFolderNodes:child | 384 [self addFolderNodes:child |
385 toPopUpButton:button | 385 toPopUpButton:button |
386 indentation:indentation]; | 386 indentation:indentation]; |
387 } | 387 } |
388 } | 388 } |
389 } | 389 } |
390 | 390 |
391 - (void)setTitle:(NSString*)title parentFolder:(const BookmarkNode*)parent { | 391 - (void)setTitle:(NSString*)title parentFolder:(const BookmarkNode*)parent { |
392 [nameTextField_ setStringValue:title]; | 392 [nameTextField_ setStringValue:title]; |
393 [self setParentFolderSelection:parent]; | 393 [self setParentFolderSelection:parent]; |
394 } | 394 } |
395 | 395 |
396 // Pick a specific parent node in the selection by finding the right | 396 // Pick a specific parent node in the selection by finding the right |
397 // pop up button index. | 397 // pop up button index. |
398 - (void)setParentFolderSelection:(const BookmarkNode*)parent { | 398 - (void)setParentFolderSelection:(const BookmarkNode*)parent { |
399 // Expectation: There is a parent mapping for all items in the | 399 // Expectation: There is a parent mapping for all items in the |
400 // folderPopUpButton except the last one ("Choose another folder..."). | 400 // folderPopUpButton except the last one ("Choose another folder..."). |
401 NSMenu* menu = [folderPopUpButton_ menu]; | 401 NSMenu* menu = [folderPopUpButton_ menu]; |
402 NSValue* parentValue = [NSValue valueWithPointer:parent]; | 402 NSValue* parentValue = [NSValue valueWithPointer:parent]; |
403 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; | 403 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; |
404 DCHECK(idx != -1); | 404 DCHECK(idx != -1); |
405 [folderPopUpButton_ selectItemAtIndex:idx]; | 405 [folderPopUpButton_ selectItemAtIndex:idx]; |
406 } | 406 } |
407 | 407 |
408 - (NSPopUpButton*)folderPopUpButton { | 408 - (NSPopUpButton*)folderPopUpButton { |
409 return folderPopUpButton_; | 409 return folderPopUpButton_; |
410 } | 410 } |
411 | 411 |
412 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) | 412 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) |
OLD | NEW |