Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_button.mm

Issue 8141003: [Mac] Restore the old bookmark menus now that the experiment is over. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_button.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #import "base/memory/scoped_nsobject.h" 10 #import "base/memory/scoped_nsobject.h"
11 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h"
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
14 #import "chrome/browser/ui/cocoa/view_id_util.h" 15 #import "chrome/browser/ui/cocoa/view_id_util.h"
15 #include "content/browser/user_metrics.h" 16 #include "content/browser/user_metrics.h"
16 17
17 // The opacity of the bookmark button drag image. 18 // The opacity of the bookmark button drag image.
18 static const CGFloat kDragImageOpacity = 0.7; 19 static const CGFloat kDragImageOpacity = 0.7;
19 20
20 21
21 namespace bookmark_button { 22 namespace bookmark_button {
22 23
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 [delegate_ bookmarkDragDidEnd:self 253 [delegate_ bookmarkDragDidEnd:self
253 operation:operation]; 254 operation:operation];
254 // Tell delegate if it should delete us. 255 // Tell delegate if it should delete us.
255 if (operation & NSDragOperationDelete) { 256 if (operation & NSDragOperationDelete) {
256 dragEndScreenLocation_ = aPoint; 257 dragEndScreenLocation_ = aPoint;
257 [delegate_ didDragBookmarkToTrash:self]; 258 [delegate_ didDragBookmarkToTrash:self];
258 } 259 }
259 } 260 }
260 261
261 - (DraggableButtonResult)performMouseDownAction:(NSEvent*)theEvent { 262 - (DraggableButtonResult)performMouseDownAction:(NSEvent*)theEvent {
263 int eventMask = NSLeftMouseUpMask | NSMouseEnteredMask | NSMouseExitedMask |
264 NSLeftMouseDraggedMask;
265
266 BOOL keepGoing = YES;
262 [[self target] performSelector:[self action] withObject:self]; 267 [[self target] performSelector:[self action] withObject:self];
263 self.draggableButton.actionHasFired = YES; 268 self.draggableButton.actionHasFired = YES;
269
270 DraggableButton* insideBtn = nil;
271
272 while (keepGoing) {
273 theEvent = [[self window] nextEventMatchingMask:eventMask];
274 if (!theEvent)
275 continue;
276
277 NSPoint mouseLoc = [self convertPoint:[theEvent locationInWindow]
278 fromView:nil];
279 BOOL isInside = [self mouse:mouseLoc inRect:[self bounds]];
280
281 switch ([theEvent type]) {
282 case NSMouseEntered:
283 case NSMouseExited: {
284 NSView* trackedView = (NSView*)[[theEvent trackingArea] owner];
285 if (trackedView && [trackedView isKindOfClass:[self class]]) {
286 BookmarkButton* btn = static_cast<BookmarkButton*>(trackedView);
287 if (![btn acceptsTrackInFrom:self])
288 break;
289 if ([theEvent type] == NSMouseEntered) {
290 [[NSCursor arrowCursor] set];
291 [[btn cell] mouseEntered:theEvent];
292 insideBtn = btn;
293 } else {
294 [[btn cell] mouseExited:theEvent];
295 if (insideBtn == btn)
296 insideBtn = nil;
297 }
298 }
299 break;
300 }
301 case NSLeftMouseDragged: {
302 if (insideBtn)
303 [insideBtn mouseDragged:theEvent];
304 break;
305 }
306 case NSLeftMouseUp: {
307 self.draggableButton.durationMouseWasDown =
308 [theEvent timestamp] - self.draggableButton.whenMouseDown;
309 if (!isInside && insideBtn && insideBtn != self) {
310 // Has tracked onto another BookmarkButton menu item, and released,
311 // so fire its action.
312 [[insideBtn target] performSelector:[insideBtn action]
313 withObject:insideBtn];
314
315 } else {
316 [self secondaryMouseUpAction:isInside];
317 [[self cell] mouseExited:theEvent];
318 [[insideBtn cell] mouseExited:theEvent];
319 }
320 keepGoing = NO;
321 break;
322 }
323 default:
324 /* Ignore any other kind of event. */
325 break;
326 }
327 }
264 return kDraggableButtonMixinDidWork; 328 return kDraggableButtonMixinDidWork;
265 } 329 }
266 330
331
332
333 // mouseEntered: and mouseExited: are called from our
267 // BookmarkButtonCell. We redirect this information to our delegate. 334 // BookmarkButtonCell. We redirect this information to our delegate.
268 // The controller can then perform menu-like actions (e.g. "hover over 335 // The controller can then perform menu-like actions (e.g. "hover over
269 // to open menu"). 336 // to open menu").
270 - (void)mouseEntered:(NSEvent*)event { 337 - (void)mouseEntered:(NSEvent*)event {
271 [delegate_ mouseEnteredButton:self event:event]; 338 [delegate_ mouseEnteredButton:self event:event];
272 } 339 }
273 340
274 // See comments above mouseEntered:. 341 // See comments above mouseEntered:.
275 - (void)mouseExited:(NSEvent*)event { 342 - (void)mouseExited:(NSEvent*)event {
276 [delegate_ mouseExitedButton:self event:event]; 343 [delegate_ mouseExitedButton:self event:event];
277 } 344 }
278 345
279 - (void)mouseMoved:(NSEvent*)theEvent { 346 - (void)mouseMoved:(NSEvent*)theEvent {
280 if ([delegate_ respondsToSelector:@selector(mouseMoved:)]) 347 if ([delegate_ respondsToSelector:@selector(mouseMoved:)])
281 [id(delegate_) mouseMoved:theEvent]; 348 [id(delegate_) mouseMoved:theEvent];
282 } 349 }
283 350
284 - (void)mouseDragged:(NSEvent*)theEvent { 351 - (void)mouseDragged:(NSEvent*)theEvent {
285 if ([delegate_ respondsToSelector:@selector(mouseDragged:)]) 352 if ([delegate_ respondsToSelector:@selector(mouseDragged:)])
286 [id(delegate_) mouseDragged:theEvent]; 353 [id(delegate_) mouseDragged:theEvent];
287 } 354 }
288 355
289 + (BookmarkButton*)draggedButton { 356 + (BookmarkButton*)draggedButton {
290 return gDraggedButton; 357 return gDraggedButton;
291 } 358 }
292 359
293 - (BOOL)canBecomeKeyView { 360 - (BOOL)canBecomeKeyView {
294 return NO; 361 // If button is an item in a folder menu, don't become key.
362 return ![[self cell] isFolderButtonCell];
295 } 363 }
296 364
297 // This only gets called after a click that wasn't a drag, and only on folders. 365 // This only gets called after a click that wasn't a drag, and only on folders.
298 - (DraggableButtonResult)secondaryMouseUpAction:(BOOL)wasInside { 366 - (DraggableButtonResult)secondaryMouseUpAction:(BOOL)wasInside {
299 const NSTimeInterval kShortClickLength = 0.5; 367 const NSTimeInterval kShortClickLength = 0.5;
300 // Long clicks that end over the folder button result in the menu hiding. 368 // Long clicks that end over the folder button result in the menu hiding.
301 if (wasInside && 369 if (wasInside &&
302 self.draggableButton.durationMouseWasDown > kShortClickLength) { 370 self.draggableButton.durationMouseWasDown > kShortClickLength) {
303 [[self target] performSelector:[self action] withObject:self]; 371 [[self target] performSelector:[self action] withObject:self];
304 } else { 372 } else {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 [image drawAtPoint:NSMakePoint(0, 0) 429 [image drawAtPoint:NSMakePoint(0, 0)
362 fromRect:NSMakeRect(0, 0, NSWidth(bounds), NSHeight(bounds)) 430 fromRect:NSMakeRect(0, 0, NSWidth(bounds), NSHeight(bounds))
363 operation:NSCompositeSourceOver 431 operation:NSCompositeSourceOver
364 fraction:kDragImageOpacity]; 432 fraction:kDragImageOpacity];
365 433
366 [dragImage unlockFocus]; 434 [dragImage unlockFocus];
367 return dragImage; 435 return dragImage;
368 } 436 }
369 437
370 @end // @implementation BookmarkButton(Private) 438 @end // @implementation BookmarkButton(Private)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_button.h ('k') | chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698