| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #include <vector> | 6 #include <vector> |
| 7 #import "chrome/browser/ui/cocoa/draggable_button.h" | 7 #import "chrome/browser/ui/cocoa/draggable_button.h" |
| 8 #include "ui/base/window_open_disposition.h" | 8 #include "ui/base/window_open_disposition.h" |
| 9 | 9 |
| 10 @class BookmarkBarFolderController; | 10 @class BookmarkBarFolderController; |
| 11 @class BookmarkButton; | 11 @class BookmarkButton; |
| 12 class BookmarkNode; | |
| 13 @class BrowserWindowController; | 12 @class BrowserWindowController; |
| 14 class ThemeService; | 13 class ThemeService; |
| 15 | 14 |
| 16 namespace bookmarks { | 15 namespace bookmarks { |
| 17 class BookmarkModel; | 16 class BookmarkModel; |
| 17 class BookmarkNode; |
| 18 } | 18 } |
| 19 | 19 |
| 20 // Protocol for a BookmarkButton's delegate, responsible for doing | 20 // Protocol for a BookmarkButton's delegate, responsible for doing |
| 21 // things on behalf of a bookmark button. | 21 // things on behalf of a bookmark button. |
| 22 @protocol BookmarkButtonDelegate | 22 @protocol BookmarkButtonDelegate |
| 23 | 23 |
| 24 // Fill the given pasteboard with appropriate data when the given button is | 24 // Fill the given pasteboard with appropriate data when the given button is |
| 25 // dragged. Since the delegate has no way of providing pasteboard data later, | 25 // dragged. Since the delegate has no way of providing pasteboard data later, |
| 26 // all data must actually be put into the pasteboard and not merely promised. | 26 // all data must actually be put into the pasteboard and not merely promised. |
| 27 - (void)fillPasteboard:(NSPasteboard*)pboard | 27 - (void)fillPasteboard:(NSPasteboard*)pboard |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 to:(NSPoint)point | 99 to:(NSPoint)point |
| 100 copy:(BOOL)copy; | 100 copy:(BOOL)copy; |
| 101 | 101 |
| 102 // Determine if the pasteboard from |info| has dragging data containing | 102 // Determine if the pasteboard from |info| has dragging data containing |
| 103 // bookmark(s) and perform the drag and return YES, otherwise return NO. | 103 // bookmark(s) and perform the drag and return YES, otherwise return NO. |
| 104 - (BOOL)dragBookmarkData:(id<NSDraggingInfo>)info; | 104 - (BOOL)dragBookmarkData:(id<NSDraggingInfo>)info; |
| 105 | 105 |
| 106 // Determine if the drag pasteboard has any drag data of type | 106 // Determine if the drag pasteboard has any drag data of type |
| 107 // kBookmarkDictionaryListPboardType and, if so, return those elements | 107 // kBookmarkDictionaryListPboardType and, if so, return those elements |
| 108 // otherwise return an empty vector. | 108 // otherwise return an empty vector. |
| 109 - (std::vector<const BookmarkNode*>)retrieveBookmarkNodeData; | 109 - (std::vector<const bookmarks::BookmarkNode*>)retrieveBookmarkNodeData; |
| 110 | 110 |
| 111 // Return YES if we should show the drop indicator, else NO. In some | 111 // Return YES if we should show the drop indicator, else NO. In some |
| 112 // cases (e.g. hover open) we don't want to show the drop indicator. | 112 // cases (e.g. hover open) we don't want to show the drop indicator. |
| 113 // |point| is in the base coordinate system of the destination window; | 113 // |point| is in the base coordinate system of the destination window; |
| 114 // |it comes from an id<NSDraggingInfo>. | 114 // |it comes from an id<NSDraggingInfo>. |
| 115 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point; | 115 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point; |
| 116 | 116 |
| 117 // The x or y coordinate of (the middle of) the indicator to draw for | 117 // The x or y coordinate of (the middle of) the indicator to draw for |
| 118 // a drag of the source button to the given point (given in window | 118 // a drag of the source button to the given point (given in window |
| 119 // coordinates). | 119 // coordinates). |
| (...skipping 19 matching lines...) Expand all Loading... |
| 139 - (void)childFolderWillClose:(id<BookmarkButtonControllerProtocol>)child; | 139 - (void)childFolderWillClose:(id<BookmarkButtonControllerProtocol>)child; |
| 140 | 140 |
| 141 // Return a controller's folder controller for a subfolder, or nil. | 141 // Return a controller's folder controller for a subfolder, or nil. |
| 142 - (BookmarkBarFolderController*)folderController; | 142 - (BookmarkBarFolderController*)folderController; |
| 143 | 143 |
| 144 // Add a new folder controller as triggered by the given folder button. | 144 // Add a new folder controller as triggered by the given folder button. |
| 145 // If there is a current folder controller, close it. | 145 // If there is a current folder controller, close it. |
| 146 - (void)addNewFolderControllerWithParentButton:(BookmarkButton*)parentButton; | 146 - (void)addNewFolderControllerWithParentButton:(BookmarkButton*)parentButton; |
| 147 | 147 |
| 148 // Open all of the nodes for the given node with disposition. | 148 // Open all of the nodes for the given node with disposition. |
| 149 - (void)openAll:(const BookmarkNode*)node | 149 - (void)openAll:(const bookmarks::BookmarkNode*)node |
| 150 disposition:(WindowOpenDisposition)disposition; | 150 disposition:(WindowOpenDisposition)disposition; |
| 151 | 151 |
| 152 // There are several operations which may affect the contents of a bookmark | 152 // There are several operations which may affect the contents of a bookmark |
| 153 // button controller after it has been created, primary of which are | 153 // button controller after it has been created, primary of which are |
| 154 // cut/paste/delete and drag/drop. Such changes may involve coordinating | 154 // cut/paste/delete and drag/drop. Such changes may involve coordinating |
| 155 // the bookmark button contents of two controllers (such as when a bookmark is | 155 // the bookmark button contents of two controllers (such as when a bookmark is |
| 156 // dragged from one folder to another). The bookmark bar controller | 156 // dragged from one folder to another). The bookmark bar controller |
| 157 // coordinates in response to notifications propagated by the bookmark model | 157 // coordinates in response to notifications propagated by the bookmark model |
| 158 // through BookmarkBarBridge calls. The following three functions are | 158 // through BookmarkBarBridge calls. The following three functions are |
| 159 // implemented by the controllers and are dispatched by the bookmark bar | 159 // implemented by the controllers and are dispatched by the bookmark bar |
| 160 // controller in response to notifications coming in from the BookmarkBarBridge. | 160 // controller in response to notifications coming in from the BookmarkBarBridge. |
| 161 | 161 |
| 162 // Add a button for the given node to the bar or folder menu. This is safe | 162 // Add a button for the given node to the bar or folder menu. This is safe |
| 163 // to call when a folder menu window is open as that window will be updated. | 163 // to call when a folder menu window is open as that window will be updated. |
| 164 // And index of -1 means to append to the end (bottom). | 164 // And index of -1 means to append to the end (bottom). |
| 165 - (void)addButtonForNode:(const BookmarkNode*)node | 165 - (void)addButtonForNode:(const bookmarks::BookmarkNode*)node |
| 166 atIndex:(NSInteger)buttonIndex; | 166 atIndex:(NSInteger)buttonIndex; |
| 167 | 167 |
| 168 // Given a list or |urls| and |titles|, create new bookmark nodes and add | 168 // Given a list or |urls| and |titles|, create new bookmark nodes and add |
| 169 // them to the bookmark model such that they will be 1) added to the folder | 169 // them to the bookmark model such that they will be 1) added to the folder |
| 170 // represented by the button at |point| if it is a folder, or 2) inserted | 170 // represented by the button at |point| if it is a folder, or 2) inserted |
| 171 // into the parent of the non-folder bookmark at |point| in front of that | 171 // into the parent of the non-folder bookmark at |point| in front of that |
| 172 // button. Returns YES if at least one bookmark was added. | 172 // button. Returns YES if at least one bookmark was added. |
| 173 - (BOOL)addURLs:(NSArray*)urls withTitles:(NSArray*)titles at:(NSPoint)point; | 173 - (BOOL)addURLs:(NSArray*)urls withTitles:(NSArray*)titles at:(NSPoint)point; |
| 174 | 174 |
| 175 // Move a button from one place in the menu to another. This is safe | 175 // Move a button from one place in the menu to another. This is safe |
| 176 // to call when a folder menu window is open as that window will be updated. | 176 // to call when a folder menu window is open as that window will be updated. |
| 177 - (void)moveButtonFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex; | 177 - (void)moveButtonFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex; |
| 178 | 178 |
| 179 // Remove the bookmark button at the given index. Show the poof animation | 179 // Remove the bookmark button at the given index. Show the poof animation |
| 180 // if |animate:| is YES. It may be obvious, but this is safe | 180 // if |animate:| is YES. It may be obvious, but this is safe |
| 181 // to call when a folder menu window is open as that window will be updated. | 181 // to call when a folder menu window is open as that window will be updated. |
| 182 - (void)removeButton:(NSInteger)buttonIndex animate:(BOOL)poof; | 182 - (void)removeButton:(NSInteger)buttonIndex animate:(BOOL)poof; |
| 183 | 183 |
| 184 // Determine the controller containing the button representing |node|, if any. | 184 // Determine the controller containing the button representing |node|, if any. |
| 185 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 185 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
| 186 (const BookmarkNode*)node; | 186 (const bookmarks::BookmarkNode*)node; |
| 187 | 187 |
| 188 @end // @protocol BookmarkButtonControllerProtocol | 188 @end // @protocol BookmarkButtonControllerProtocol |
| 189 | 189 |
| 190 | 190 |
| 191 // Class for bookmark bar buttons that can be drag sources. | 191 // Class for bookmark bar buttons that can be drag sources. |
| 192 @interface BookmarkButton : DraggableButton { | 192 @interface BookmarkButton : DraggableButton { |
| 193 @private | 193 @private |
| 194 IBOutlet NSObject<BookmarkButtonDelegate>* delegate_; // Weak. | 194 IBOutlet NSObject<BookmarkButtonDelegate>* delegate_; // Weak. |
| 195 | 195 |
| 196 // Saved pointer to the BWC for the browser window that contains this button. | 196 // Saved pointer to the BWC for the browser window that contains this button. |
| 197 // Used to lock and release bar visibility during a drag. The pointer is | 197 // Used to lock and release bar visibility during a drag. The pointer is |
| 198 // saved because the bookmark button is no longer a part of a window at the | 198 // saved because the bookmark button is no longer a part of a window at the |
| 199 // end of a drag operation (or, in fact, can be dragged to a completely | 199 // end of a drag operation (or, in fact, can be dragged to a completely |
| 200 // different window), so there is no way to retrieve the same BWC object after | 200 // different window), so there is no way to retrieve the same BWC object after |
| 201 // a drag. | 201 // a drag. |
| 202 BrowserWindowController* visibilityDelegate_; // weak | 202 BrowserWindowController* visibilityDelegate_; // weak |
| 203 | 203 |
| 204 NSPoint dragMouseOffset_; | 204 NSPoint dragMouseOffset_; |
| 205 NSPoint dragEndScreenLocation_; | 205 NSPoint dragEndScreenLocation_; |
| 206 BOOL dragPending_; | 206 BOOL dragPending_; |
| 207 BOOL acceptsTrackIn_; | 207 BOOL acceptsTrackIn_; |
| 208 NSTrackingArea* area_; | 208 NSTrackingArea* area_; |
| 209 } | 209 } |
| 210 | 210 |
| 211 @property(assign, nonatomic) NSObject<BookmarkButtonDelegate>* delegate; | 211 @property(assign, nonatomic) NSObject<BookmarkButtonDelegate>* delegate; |
| 212 @property(assign, nonatomic) BOOL acceptsTrackIn; | 212 @property(assign, nonatomic) BOOL acceptsTrackIn; |
| 213 | 213 |
| 214 // Return the bookmark node associated with this button, or NULL. | 214 // Return the bookmark node associated with this button, or NULL. |
| 215 - (const BookmarkNode*)bookmarkNode; | 215 - (const bookmarks::BookmarkNode*)bookmarkNode; |
| 216 | 216 |
| 217 // Return YES if this is a folder button (the node has subnodes). | 217 // Return YES if this is a folder button (the node has subnodes). |
| 218 - (BOOL)isFolder; | 218 - (BOOL)isFolder; |
| 219 | 219 |
| 220 - (void)mouseDragged:(NSEvent*)theEvent; | 220 - (void)mouseDragged:(NSEvent*)theEvent; |
| 221 | 221 |
| 222 - (BOOL)acceptsTrackInFrom:(id)sender; | 222 - (BOOL)acceptsTrackInFrom:(id)sender; |
| 223 | 223 |
| 224 // At this time we represent an empty folder (e.g. the string | 224 // At this time we represent an empty folder (e.g. the string |
| 225 // '(empty)') as a disabled button with no associated node. | 225 // '(empty)') as a disabled button with no associated node. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 258 |
| 259 // Key for userInfo dict of a kPulseBookmarkButtonNotification. | 259 // Key for userInfo dict of a kPulseBookmarkButtonNotification. |
| 260 // Value is a [NSValue valueWithPointer:]; pointer is a (const BookmarkNode*). | 260 // Value is a [NSValue valueWithPointer:]; pointer is a (const BookmarkNode*). |
| 261 extern NSString* const kBookmarkKey; | 261 extern NSString* const kBookmarkKey; |
| 262 | 262 |
| 263 // Key for userInfo dict of a kPulseBookmarkButtonNotification. | 263 // Key for userInfo dict of a kPulseBookmarkButtonNotification. |
| 264 // Value is a [NSNumber numberWithBool:] to turn pulsing on or off. | 264 // Value is a [NSNumber numberWithBool:] to turn pulsing on or off. |
| 265 extern NSString* const kBookmarkPulseFlagKey; | 265 extern NSString* const kBookmarkPulseFlagKey; |
| 266 | 266 |
| 267 }; | 267 }; |
| OLD | NEW |