| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #import "base/mac/scoped_nsobject.h" | 11 #import "base/mac/scoped_nsobject.h" |
| 12 #include "base/mac/sdk_forward_declarations.h" | 12 #include "base/mac/sdk_forward_declarations.h" |
| 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | |
| 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
| 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h" | |
| 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" | 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
| 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
| 18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 19 #import "chrome/browser/ui/cocoa/view_id_util.h" | 17 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 20 #include "components/bookmarks/browser/bookmark_model.h" | 18 #include "components/bookmarks/browser/bookmark_model.h" |
| 21 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
| 22 #include "ui/base/clipboard/clipboard_util_mac.h" | 20 #include "ui/base/clipboard/clipboard_util_mac.h" |
| 23 #include "ui/base/cocoa/cocoa_base_utils.h" | 21 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 24 #import "ui/base/cocoa/nsview_additions.h" | 22 #import "ui/base/cocoa/nsview_additions.h" |
| 25 #include "ui/base/material_design/material_design_controller.h" | |
| 26 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 23 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 27 | 24 |
| 28 using base::UserMetricsAction; | 25 using base::UserMetricsAction; |
| 29 using bookmarks::BookmarkNode; | 26 using bookmarks::BookmarkNode; |
| 30 | 27 |
| 31 // The opacity of the bookmark button drag image. | 28 // The opacity of the bookmark button drag image. |
| 32 static const CGFloat kDragImageOpacity = 0.7; | 29 static const CGFloat kDragImageOpacity = 0.7; |
| 33 | 30 |
| 34 namespace { | 31 namespace { |
| 35 // We need a class variable to track the current dragged button to enable | 32 // We need a class variable to track the current dragged button to enable |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 // to open menu"). | 350 // to open menu"). |
| 354 - (void)mouseEntered:(NSEvent*)event { | 351 - (void)mouseEntered:(NSEvent*)event { |
| 355 [delegate_ mouseEnteredButton:self event:event]; | 352 [delegate_ mouseEnteredButton:self event:event]; |
| 356 } | 353 } |
| 357 | 354 |
| 358 // See comments above mouseEntered:. | 355 // See comments above mouseEntered:. |
| 359 - (void)mouseExited:(NSEvent*)event { | 356 - (void)mouseExited:(NSEvent*)event { |
| 360 [delegate_ mouseExitedButton:self event:event]; | 357 [delegate_ mouseExitedButton:self event:event]; |
| 361 } | 358 } |
| 362 | 359 |
| 363 - (void)mouseDown:(NSEvent*)theEvent { | |
| 364 // Clicking on a bookmark button in Material Design should highlight it. | |
| 365 const int kCellTag = [[self cell] tag]; | |
| 366 if (kCellTag == kMaterialStandardButtonTypeWithLimitedClickFeedback && | |
| 367 [self isEnabled]) { | |
| 368 [self highlight:YES]; | |
| 369 } | |
| 370 [super mouseDown:theEvent]; | |
| 371 } | |
| 372 | |
| 373 - (void)mouseMoved:(NSEvent*)theEvent { | 360 - (void)mouseMoved:(NSEvent*)theEvent { |
| 374 if ([delegate_ respondsToSelector:@selector(mouseMoved:)]) | 361 if ([delegate_ respondsToSelector:@selector(mouseMoved:)]) |
| 375 [id(delegate_) mouseMoved:theEvent]; | 362 [id(delegate_) mouseMoved:theEvent]; |
| 376 } | 363 } |
| 377 | 364 |
| 378 - (void)mouseDragged:(NSEvent*)theEvent { | 365 - (void)mouseDragged:(NSEvent*)theEvent { |
| 379 if ([delegate_ respondsToSelector:@selector(mouseDragged:)]) | 366 if ([delegate_ respondsToSelector:@selector(mouseDragged:)]) |
| 380 [id(delegate_) mouseDragged:theEvent]; | 367 [id(delegate_) mouseDragged:theEvent]; |
| 381 } | 368 } |
| 382 | 369 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 // CoreAnimation is enabled. | 418 // CoreAnimation is enabled. |
| 432 return YES; | 419 return YES; |
| 433 } | 420 } |
| 434 | 421 |
| 435 - (void)drawRect:(NSRect)rect { | 422 - (void)drawRect:(NSRect)rect { |
| 436 NSView* bookmarkBarToolbarView = [[self superview] superview]; | 423 NSView* bookmarkBarToolbarView = [[self superview] superview]; |
| 437 [self cr_drawUsingAncestor:bookmarkBarToolbarView inRect:(NSRect)rect]; | 424 [self cr_drawUsingAncestor:bookmarkBarToolbarView inRect:(NSRect)rect]; |
| 438 [super drawRect:rect]; | 425 [super drawRect:rect]; |
| 439 } | 426 } |
| 440 | 427 |
| 441 - (void)updateIconToMatchTheme { | |
| 442 if (!ui::MaterialDesignController::IsModeMaterial() || ![self isFolder]) { | |
| 443 return; | |
| 444 } | |
| 445 | |
| 446 // During testing, the window might not be a browser window, and the | |
| 447 // superview might not be a BookmarkBarView. | |
| 448 if (![[self window] respondsToSelector:@selector(hasDarkTheme)] || | |
| 449 ![[self superview] isKindOfClass:[BookmarkBarView class]]) { | |
| 450 return; | |
| 451 } | |
| 452 | |
| 453 BookmarkBarView* bookmarkBarView = | |
| 454 base::mac::ObjCCastStrict<BookmarkBarView>([self superview]); | |
| 455 BookmarkBarController* bookmarkBarController = [bookmarkBarView controller]; | |
| 456 BOOL darkTheme = [[self window] hasDarkTheme]; | |
| 457 NSImage* theImage = nil; | |
| 458 // Make sure the "off the side" button gets the chevron icon. | |
| 459 if ([bookmarkBarController offTheSideButton] == self) { | |
| 460 theImage = [bookmarkBarController offTheSideButtonImage:darkTheme]; | |
| 461 } else { | |
| 462 theImage = [bookmarkBarController faviconForNode:[self bookmarkNode] | |
| 463 forADarkTheme:darkTheme]; | |
| 464 } | |
| 465 | |
| 466 [[self cell] setImage:theImage]; | |
| 467 } | |
| 468 | |
| 469 - (void)viewDidMoveToWindow { | 428 - (void)viewDidMoveToWindow { |
| 470 [super viewDidMoveToWindow]; | 429 [super viewDidMoveToWindow]; |
| 471 if ([self window]) { | 430 if ([self window]) { |
| 472 // The new window may have different main window status. | 431 // The new window may have different main window status. |
| 473 // This happens when the view is moved into a TabWindowOverlayWindow for | 432 // This happens when the view is moved into a TabWindowOverlayWindow for |
| 474 // tab dragging. | 433 // tab dragging. |
| 475 [self updateIconToMatchTheme]; | |
| 476 [self windowDidChangeActive]; | 434 [self windowDidChangeActive]; |
| 477 } | 435 } |
| 478 } | 436 } |
| 479 | 437 |
| 480 // ThemedWindowDrawing implementation. | 438 // ThemedWindowDrawing implementation. |
| 481 | 439 |
| 482 - (void)windowDidChangeTheme { | 440 - (void)windowDidChangeTheme { |
| 483 [self updateIconToMatchTheme]; | |
| 484 [self setNeedsDisplay:YES]; | 441 [self setNeedsDisplay:YES]; |
| 485 } | 442 } |
| 486 | 443 |
| 487 - (void)windowDidChangeActive { | 444 - (void)windowDidChangeActive { |
| 488 [self setNeedsDisplay:YES]; | 445 [self setNeedsDisplay:YES]; |
| 489 } | 446 } |
| 490 | 447 |
| 491 - (void)installCustomTrackingArea { | 448 - (void)installCustomTrackingArea { |
| 492 const NSTrackingAreaOptions options = | 449 const NSTrackingAreaOptions options = |
| 493 NSTrackingActiveAlways | | 450 NSTrackingActiveAlways | |
| (...skipping 28 matching lines...) Expand all Loading... |
| 522 [[cell clipPathForFrame:bounds inView:self] setClip]; | 479 [[cell clipPathForFrame:bounds inView:self] setClip]; |
| 523 [cell drawWithFrame:bounds inView:self]; | 480 [cell drawWithFrame:bounds inView:self]; |
| 524 | 481 |
| 525 CGContextEndTransparencyLayer(cgContext); | 482 CGContextEndTransparencyLayer(cgContext); |
| 526 [image unlockFocus]; | 483 [image unlockFocus]; |
| 527 | 484 |
| 528 return image.autorelease(); | 485 return image.autorelease(); |
| 529 } | 486 } |
| 530 | 487 |
| 531 @end | 488 @end |
| OLD | NEW |