Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #import "base/cocoa_protocols_mac.h" | 6 #import "base/cocoa_protocols_mac.h" |
| 7 #include "base/scoped_nsobject.h" | 7 #include "base/scoped_nsobject.h" |
| 8 | 8 |
| 9 class BookmarkModel; | 9 class BookmarkModel; |
| 10 class BookmarkNode; | 10 class BookmarkNode; |
| 11 @class BookmarkBubbleController; | 11 @class BookmarkBubbleController; |
| 12 | 12 |
| 13 // Protocol for a BookmarkBubbleController's (BBC's) delegate. | 13 // Protocol for a BookmarkBubbleController's (BBC's) delegate. |
| 14 @protocol BookmarkBubbleControllerDelegate | 14 @protocol BookmarkBubbleControllerDelegate |
| 15 | 15 |
| 16 // The bubble asks the delegate to perform an edit when needed. | 16 // The bubble asks the delegate to perform an edit when needed. |
| 17 - (void)editBookmarkNode:(const BookmarkNode*)node; | 17 - (void)editBookmarkNode:(const BookmarkNode*)node; |
| 18 | 18 |
| 19 // The bubble tells its delegate when it's done and can be deallocated. | |
| 20 - (void)doneWithBubbleController:(BookmarkBubbleController*)controller; | |
| 21 | |
| 22 @end | 19 @end |
| 23 | 20 |
| 24 // Controller for the bookmark bubble. The bookmark bubble is a | 21 // Controller for the bookmark bubble. The bookmark bubble is a |
| 25 // bubble that pops up when clicking on the STAR next to the URL to | 22 // bubble that pops up when clicking on the STAR next to the URL to |
| 26 // add or remove it as a bookmark. This bubble allows for editing of | 23 // add or remove it as a bookmark. This bubble allows for editing of |
| 27 // the bookmark in various ways (name, folder, etc.) | 24 // the bookmark in various ways (name, folder, etc.) |
| 28 // | 25 @interface BookmarkBubbleController : NSWindowController<NSWindowDelegate> { |
| 29 // The bubble is stored in a nib as a view, not as a window, so we can | |
| 30 // make it an actual bubble. There is no nib-rific way to encode a | |
| 31 // NSBorderlessWindowMask NSWindow, and the style of an NSWindow can't | |
| 32 // be set other than init time. To deal, we create the NSWindow | |
| 33 // programatically, but encode the view in a nib. Thus, | |
| 34 // BookmarkBubbleController is an NSViewController, not an | |
| 35 // NSWindowController. | |
| 36 @interface BookmarkBubbleController : NSViewController<NSWindowDelegate> { | |
| 37 @private | 26 @private |
| 38 // Unexpected for this controller, perhaps, but our window does NOT | |
| 39 // come from a nib. | |
| 40 scoped_nsobject<NSWindow> window_; | |
| 41 | |
| 42 id<BookmarkBubbleControllerDelegate> delegate_; // weak like other delegates | 27 id<BookmarkBubbleControllerDelegate> delegate_; // weak like other delegates |
| 43 NSWindow* parentWindow_; // weak | 28 NSWindow* parentWindow_; // weak |
| 44 NSPoint topLeftForBubble_; | 29 NSPoint topLeftForBubble_; // weak |
|
Scott Hess - ex-Googler
2009/10/26 19:45:21
Probably don't need weak on NSPoint.
| |
| 45 | 30 |
| 46 // Both weak; owned by the current browser's profile | 31 // Both weak; owned by the current browser's profile |
| 47 BookmarkModel* model_; | 32 BookmarkModel* model_; // weak |
| 48 const BookmarkNode* node_; | 33 const BookmarkNode* node_; // weak |
| 49 | 34 |
| 50 // A mapping from titles to nodes so we only have to walk this once. | 35 // A mapping from titles to nodes so we only have to walk this once. |
| 51 scoped_nsobject<NSMutableArray> titleMapping_; | 36 scoped_nsobject<NSMutableArray> titleMapping_; |
| 52 | 37 |
| 53 BOOL alreadyBookmarked_; | 38 BOOL alreadyBookmarked_; |
| 54 scoped_nsobject<NSString> chooseAnotherFolder_; | 39 scoped_nsobject<NSString> chooseAnotherFolder_; |
| 55 | 40 |
| 56 IBOutlet NSTextField* bigTitle_; // "Bookmark" or "Bookmark Added!" | 41 IBOutlet NSTextField* bigTitle_; // "Bookmark" or "Bookmark Added!" |
| 57 IBOutlet NSTextField* nameTextField_; | 42 IBOutlet NSTextField* nameTextField_; |
| 58 IBOutlet NSComboBox* folderComboBox_; | 43 IBOutlet NSComboBox* folderComboBox_; |
| 59 } | 44 } |
| 60 | 45 |
| 61 // |node| is the bookmark node we edit in this bubble. | 46 // |node| is the bookmark node we edit in this bubble. |
| 62 // |alreadyBookmarked| tells us if the node was bookmarked before the | 47 // |alreadyBookmarked| tells us if the node was bookmarked before the |
| 63 // user clicked on the star. (if NO, this is a brand new bookmark). | 48 // user clicked on the star. (if NO, this is a brand new bookmark). |
| 64 // The owner of this object is responsible for showing the bubble if | 49 // The owner of this object is responsible for showing the bubble if |
| 65 // it desires it to be visible on the screen. It is not shown by the | 50 // it desires it to be visible on the screen. It is not shown by the |
| 66 // init routine. Closing of the window happens implicitly on dealloc. | 51 // init routine. Closing of the window happens implicitly on dealloc. |
| 67 - (id)initWithDelegate:(id<BookmarkBubbleControllerDelegate>)delegate | 52 - (id)initWithDelegate:(id<BookmarkBubbleControllerDelegate>)delegate |
| 68 parentWindow:(NSWindow*)parentWindow | 53 parentWindow:(NSWindow*)parentWindow |
| 69 topLeftForBubble:(NSPoint)topLeftForBubble | 54 topLeftForBubble:(NSPoint)topLeftForBubble |
| 70 model:(BookmarkModel*)model | 55 model:(BookmarkModel*)model |
| 71 node:(const BookmarkNode*)node | 56 node:(const BookmarkNode*)node |
| 72 alreadyBookmarked:(BOOL)alreadyBookmarked; | 57 alreadyBookmarked:(BOOL)alreadyBookmarked; |
| 73 | 58 |
| 74 - (void)showWindow; | |
| 75 | |
| 76 // Actions for buttons in the dialog. | 59 // Actions for buttons in the dialog. |
| 77 - (IBAction)edit:(id)sender; | 60 - (IBAction)edit:(id)sender; |
| 78 - (IBAction)close:(id)sender; | 61 - (IBAction)ok:(id)sender; |
| 79 - (IBAction)remove:(id)sender; | 62 - (IBAction)remove:(id)sender; |
| 63 - (IBAction)cancel:(id)sender; | |
| 80 | 64 |
| 81 @end | 65 @end |
| 82 | 66 |
| 83 | 67 |
| 84 // Exposed only for unit testing. | 68 // Exposed only for unit testing. |
| 85 @interface BookmarkBubbleController(ExposedForUnitTesting) | 69 @interface BookmarkBubbleController(ExposedForUnitTesting) |
| 86 - (NSWindow*)createBubbleWindow; | |
| 87 - (void)fillInFolderList; | 70 - (void)fillInFolderList; |
| 88 - (BOOL)windowHasBeenClosed; | |
| 89 - (void)addFolderNodes:(const BookmarkNode*)parent toComboBox:(NSComboBox*)box; | 71 - (void)addFolderNodes:(const BookmarkNode*)parent toComboBox:(NSComboBox*)box; |
| 90 - (void)updateBookmarkNode; | 72 - (void)updateBookmarkNode; |
| 91 - (void)setTitle:(NSString *)title parentFolder:(NSString*)folder; | 73 - (void)setTitle:(NSString*)title parentFolder:(NSString*)folder; |
| 92 - (NSString*)chooseAnotherFolderString; | 74 - (NSString*)chooseAnotherFolderString; |
| 75 - (NSComboBox*)folderComboBox; | |
| 93 @end | 76 @end |
| 94 | 77 |
| 95 // Also private but I need to declare them specially for @synthesize to work. | 78 |
| 96 @interface BookmarkBubbleController () | 79 |
| 97 @property (readonly) id delegate; | 80 |
| 98 @property (readonly) NSComboBox* folderComboBox; | 81 |
| 99 @end | |
| OLD | NEW |