OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/mac_util.h" | 7 #include "base/mac/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 #include "chrome/browser/bookmarks/bookmark_utils.h" | 10 #include "chrome/browser/bookmarks/bookmark_utils.h" |
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
13 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 13 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
14 #include "content/browser/user_metrics.h" | 14 #include "content/browser/user_metrics.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
17 #include "content/common/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util_mac.h" | 19 #include "ui/base/l10n/l10n_util_mac.h" |
20 | 20 |
21 | 21 |
22 // Simple class to watch for tab creation/destruction and close the bubble. | 22 // Simple class to watch for tab creation/destruction and close the bubble. |
23 // Bridge between Chrome-style notifications and ObjC-style notifications. | 23 // Bridge between Chrome-style notifications and ObjC-style notifications. |
24 class BookmarkBubbleNotificationBridge : public content::NotificationObserver { | 24 class BookmarkBubbleNotificationBridge : public content::NotificationObserver { |
25 public: | 25 public: |
26 BookmarkBubbleNotificationBridge(BookmarkBubbleController* controller, | 26 BookmarkBubbleNotificationBridge(BookmarkBubbleController* controller, |
27 SEL selector); | 27 SEL selector); |
28 virtual ~BookmarkBubbleNotificationBridge() {} | 28 virtual ~BookmarkBubbleNotificationBridge() {} |
29 void Observe(int type, | 29 void Observe(int type, |
30 const content::NotificationSource& source, | 30 const content::NotificationSource& source, |
31 const content::NotificationDetails& details); | 31 const content::NotificationDetails& details); |
32 private: | 32 private: |
33 content::NotificationRegistrar registrar_; | 33 content::NotificationRegistrar registrar_; |
34 BookmarkBubbleController* controller_; // weak; owns us. | 34 BookmarkBubbleController* controller_; // weak; owns us. |
35 SEL selector_; // SEL sent to controller_ on notification. | 35 SEL selector_; // SEL sent to controller_ on notification. |
36 }; | 36 }; |
37 | 37 |
38 BookmarkBubbleNotificationBridge::BookmarkBubbleNotificationBridge( | 38 BookmarkBubbleNotificationBridge::BookmarkBubbleNotificationBridge( |
39 BookmarkBubbleController* controller, SEL selector) | 39 BookmarkBubbleController* controller, SEL selector) |
40 : controller_(controller), selector_(selector) { | 40 : controller_(controller), selector_(selector) { |
41 // registrar_ will automatically RemoveAll() when destroyed so we | 41 // registrar_ will automatically RemoveAll() when destroyed so we |
42 // don't need to do so explicitly. | 42 // don't need to do so explicitly. |
43 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 43 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, |
44 NotificationService::AllSources()); | 44 content::NotificationService::AllSources()); |
45 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, | 45 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
46 NotificationService::AllSources()); | 46 content::NotificationService::AllSources()); |
47 } | 47 } |
48 | 48 |
49 // At this time all notifications instigate the same behavior (go | 49 // At this time all notifications instigate the same behavior (go |
50 // away) so we don't bother checking which notification came in. | 50 // away) so we don't bother checking which notification came in. |
51 void BookmarkBubbleNotificationBridge::Observe( | 51 void BookmarkBubbleNotificationBridge::Observe( |
52 int type, | 52 int type, |
53 const content::NotificationSource& source, | 53 const content::NotificationSource& source, |
54 const content::NotificationDetails& details) { | 54 const content::NotificationDetails& details) { |
55 [controller_ performSelector:selector_ withObject:controller_]; | 55 [controller_ performSelector:selector_ withObject:controller_]; |
56 } | 56 } |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; | 413 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; |
414 DCHECK(idx != -1); | 414 DCHECK(idx != -1); |
415 [folderPopUpButton_ selectItemAtIndex:idx]; | 415 [folderPopUpButton_ selectItemAtIndex:idx]; |
416 } | 416 } |
417 | 417 |
418 - (NSPopUpButton*)folderPopUpButton { | 418 - (NSPopUpButton*)folderPopUpButton { |
419 return folderPopUpButton_; | 419 return folderPopUpButton_; |
420 } | 420 } |
421 | 421 |
422 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) | 422 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) |
OLD | NEW |