Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_button.h
blob25d73b0d2b6cd781083959cc163595ddf7ca58b6
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
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
6 #include <vector>
7 #import "chrome/browser/ui/cocoa/draggable_button.h"
8 #import "chrome/browser/ui/cocoa/themed_window.h"
9 #include "ui/base/window_open_disposition.h"
11 @class BookmarkBarFolderController;
12 @class BookmarkButton;
13 @class BrowserWindowController;
14 class ThemeService;
16 namespace bookmarks {
17 class BookmarkModel;
18 class BookmarkNode;
21 // Protocol for a BookmarkButton's delegate, responsible for doing
22 // things on behalf of a bookmark button.
23 @protocol BookmarkButtonDelegate
25 // Fill the given pasteboard with appropriate data when the given button is
26 // dragged. Since the delegate has no way of providing pasteboard data later,
27 // all data must actually be put into the pasteboard and not merely promised.
28 - (void)fillPasteboard:(NSPasteboard*)pboard
29 forDragOfButton:(BookmarkButton*)button;
31 // Bookmark buttons pass mouseEntered: and mouseExited: events to
32 // their delegate. This allows the delegate to decide (for example)
33 // which one, if any, should perform a hover-open.
34 - (void)mouseEnteredButton:(id)button event:(NSEvent*)event;
35 - (void)mouseExitedButton:(id)button event:(NSEvent*)event;
37 // Returns YES if a drag operation should lock the fullscreen overlay bar
38 // visibility before starting. For example, dragging a bookmark button should
39 // not lock the overlay if the bookmark bar is currently showing in detached
40 // mode on the NTP.
41 - (BOOL)dragShouldLockBarVisibility;
43 // Returns the top-level window for this button.
44 - (NSWindow*)browserWindow;
46 // Returns YES if the bookmark button can be dragged to the trash, NO otherwise.
47 - (BOOL)canDragBookmarkButtonToTrash:(BookmarkButton*)button;
49 // This is called after the user has dropped the bookmark button on the trash.
50 // The delegate can use this event to delete the bookmark.
51 - (void)didDragBookmarkToTrash:(BookmarkButton*)button;
53 // This is called after the drag has finished, for any reason.
54 // We particularly need this so we can hide bookmark folder menus and stop
55 // doing that hover thing.
56 - (void)bookmarkDragDidEnd:(BookmarkButton*)button
57 operation:(NSDragOperation)operation;
59 @end
62 // Protocol to be implemented by controllers that logically own
63 // bookmark buttons. The controller may be either an NSViewController
64 // or NSWindowController. The BookmarkButton doesn't use this
65 // protocol directly; it is used when BookmarkButton controllers talk
66 // to each other.
68 // Other than the top level owner (the bookmark bar), all bookmark
69 // button controllers have a parent controller.
70 @protocol BookmarkButtonControllerProtocol
72 // Close all bookmark folders, walking up the ownership chain.
73 - (void)closeAllBookmarkFolders;
75 // Close just my bookmark folder.
76 - (void)closeBookmarkFolder:(id)sender;
78 // Return the bookmark model for this controller.
79 - (bookmarks::BookmarkModel*)bookmarkModel;
81 // Perform drag enter/exit operations, such as hover-open and hover-close.
82 - (BOOL)draggingAllowed:(id<NSDraggingInfo>)info;
83 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info;
84 - (void)draggingExited:(id<NSDraggingInfo>)info;
86 // Returns YES if a drag operation should lock the fullscreen overlay bar
87 // visibility before starting. For example, dragging a bookmark button should
88 // not lock the overlay if the bookmark bar is currently showing in detached
89 // mode on the NTP.
90 - (BOOL)dragShouldLockBarVisibility;
92 // Perform the actual DnD of a bookmark or bookmark button.
94 // |point| is in the base coordinate system of the destination window;
95 // |it comes from an id<NSDraggingInfo>. |copy| is YES if a copy is to be
96 // made and inserted into the new location while leaving the bookmark in
97 // the old location, otherwise move the bookmark by removing from its old
98 // location and inserting into the new location.
99 - (BOOL)dragButton:(BookmarkButton*)sourceButton
100 to:(NSPoint)point
101 copy:(BOOL)copy;
103 // Determine if the pasteboard from |info| has dragging data containing
104 // bookmark(s) and perform the drag and return YES, otherwise return NO.
105 - (BOOL)dragBookmarkData:(id<NSDraggingInfo>)info;
107 // Determine if the drag pasteboard has any drag data of type
108 // kBookmarkDictionaryListPboardType and, if so, return those elements
109 // otherwise return an empty vector.
110 - (std::vector<const bookmarks::BookmarkNode*>)retrieveBookmarkNodeData;
112 // Return YES if we should show the drop indicator, else NO. In some
113 // cases (e.g. hover open) we don't want to show the drop indicator.
114 // |point| is in the base coordinate system of the destination window;
115 // |it comes from an id<NSDraggingInfo>.
116 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point;
118 // The x or y coordinate of (the middle of) the indicator to draw for
119 // a drag of the source button to the given point (given in window
120 // coordinates).
121 // |point| is in the base coordinate system of the destination window;
122 // |it comes from an id<NSDraggingInfo>.
123 // TODO(viettrungluu,jrg): instead of this, make buttons move around.
124 // http://crbug.com/35968
125 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point;
127 // Used to tell the controller that room should be made for a drop.
128 - (void)setDropInsertionPos:(CGFloat)where;
130 // Used to tell the controller to stop making room for a drop.
131 - (void)clearDropInsertionPos;
133 // Return the theme service associated with this browser window.
134 - (ThemeService*)themeService;
136 // Called just before a child folder puts itself on screen.
137 - (void)childFolderWillShow:(id<BookmarkButtonControllerProtocol>)child;
139 // Called just before a child folder closes.
140 - (void)childFolderWillClose:(id<BookmarkButtonControllerProtocol>)child;
142 // Return a controller's folder controller for a subfolder, or nil.
143 - (BookmarkBarFolderController*)folderController;
145 // Add a new folder controller as triggered by the given folder button.
146 // If there is a current folder controller, close it.
147 - (void)addNewFolderControllerWithParentButton:(BookmarkButton*)parentButton;
149 // Open all of the nodes for the given node with disposition.
150 - (void)openAll:(const bookmarks::BookmarkNode*)node
151 disposition:(WindowOpenDisposition)disposition;
153 // There are several operations which may affect the contents of a bookmark
154 // button controller after it has been created, primary of which are
155 // cut/paste/delete and drag/drop. Such changes may involve coordinating
156 // the bookmark button contents of two controllers (such as when a bookmark is
157 // dragged from one folder to another). The bookmark bar controller
158 // coordinates in response to notifications propagated by the bookmark model
159 // through BookmarkBarBridge calls. The following three functions are
160 // implemented by the controllers and are dispatched by the bookmark bar
161 // controller in response to notifications coming in from the BookmarkBarBridge.
163 // Add a button for the given node to the bar or folder menu. This is safe
164 // to call when a folder menu window is open as that window will be updated.
165 // And index of -1 means to append to the end (bottom).
166 - (void)addButtonForNode:(const bookmarks::BookmarkNode*)node
167 atIndex:(NSInteger)buttonIndex;
169 // Given a list or |urls| and |titles|, create new bookmark nodes and add
170 // them to the bookmark model such that they will be 1) added to the folder
171 // represented by the button at |point| if it is a folder, or 2) inserted
172 // into the parent of the non-folder bookmark at |point| in front of that
173 // button. Returns YES if at least one bookmark was added.
174 - (BOOL)addURLs:(NSArray*)urls withTitles:(NSArray*)titles at:(NSPoint)point;
176 // Move a button from one place in the menu to another. This is safe
177 // to call when a folder menu window is open as that window will be updated.
178 - (void)moveButtonFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex;
180 // Remove the bookmark button at the given index. Show the poof animation
181 // if |animate:| is YES. It may be obvious, but this is safe
182 // to call when a folder menu window is open as that window will be updated.
183 - (void)removeButton:(NSInteger)buttonIndex animate:(BOOL)poof;
185 // Determine the controller containing the button representing |node|, if any.
186 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
187 (const bookmarks::BookmarkNode*)node;
189 @end // @protocol BookmarkButtonControllerProtocol
192 // Class for bookmark bar buttons that can be drag sources.
193 @interface BookmarkButton : DraggableButton<ThemedWindowDrawing> {
194 @private
195 IBOutlet NSObject<BookmarkButtonDelegate>* delegate_; // Weak.
197 // Saved pointer to the BWC for the browser window that contains this button.
198 // Used to lock and release bar visibility during a drag. The pointer is
199 // saved because the bookmark button is no longer a part of a window at the
200 // end of a drag operation (or, in fact, can be dragged to a completely
201 // different window), so there is no way to retrieve the same BWC object after
202 // a drag.
203 BrowserWindowController* visibilityDelegate_; // weak
205 NSPoint dragMouseOffset_;
206 NSPoint dragEndScreenLocation_;
207 BOOL dragPending_;
208 BOOL acceptsTrackIn_;
209 NSTrackingArea* area_;
212 @property(assign, nonatomic) NSObject<BookmarkButtonDelegate>* delegate;
213 @property(assign, nonatomic) BOOL acceptsTrackIn;
215 // Return the bookmark node associated with this button, or NULL.
216 - (const bookmarks::BookmarkNode*)bookmarkNode;
218 // Return YES if this is a folder button (the node has subnodes).
219 - (BOOL)isFolder;
221 - (void)mouseDragged:(NSEvent*)theEvent;
223 - (BOOL)acceptsTrackInFrom:(id)sender;
225 // At this time we represent an empty folder (e.g. the string
226 // '(empty)') as a disabled button with no associated node.
228 // TODO(jrg): improve; things work but are slightly ugly since "empty"
229 // and "one disabled button" are not the same thing.
230 // http://crbug.com/35967
231 - (BOOL)isEmpty;
233 // Turn on or off pulsing of a bookmark button.
234 // Triggered by the bookmark bubble.
235 - (void)setIsContinuousPulsing:(BOOL)flag;
237 // Return continuous pulse state.
238 - (BOOL)isContinuousPulsing;
240 // Return the location in screen coordinates where the remove animation should
241 // be displayed.
242 - (NSPoint)screenLocationForRemoveAnimation;
244 // The BookmarkButton which is currently being dragged, if any.
245 + (BookmarkButton*)draggedButton;
248 @end // @interface BookmarkButton
251 @interface BookmarkButton(TestingAPI)
252 - (void)beginDrag:(NSEvent*)event;
253 @end