| 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" |
| 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
| 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h" |
| 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" | 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
| 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
| 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 17 #import "chrome/browser/ui/cocoa/view_id_util.h" | 19 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 18 #include "components/bookmarks/browser/bookmark_model.h" | 20 #include "components/bookmarks/browser/bookmark_model.h" |
| 19 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 20 #include "ui/base/clipboard/clipboard_util_mac.h" | 22 #include "ui/base/clipboard/clipboard_util_mac.h" |
| 21 #include "ui/base/cocoa/cocoa_base_utils.h" | 23 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 22 #import "ui/base/cocoa/nsview_additions.h" | 24 #import "ui/base/cocoa/nsview_additions.h" |
| 25 #include "ui/base/material_design/material_design_controller.h" |
| 23 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 26 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 24 | 27 |
| 25 using base::UserMetricsAction; | 28 using base::UserMetricsAction; |
| 26 using bookmarks::BookmarkNode; | 29 using bookmarks::BookmarkNode; |
| 27 | 30 |
| 28 // The opacity of the bookmark button drag image. | 31 // The opacity of the bookmark button drag image. |
| 29 static const CGFloat kDragImageOpacity = 0.7; | 32 static const CGFloat kDragImageOpacity = 0.7; |
| 30 | 33 |
| 31 namespace { | 34 namespace { |
| 32 // We need a class variable to track the current dragged button to enable | 35 // 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... |
| 350 // to open menu"). | 353 // to open menu"). |
| 351 - (void)mouseEntered:(NSEvent*)event { | 354 - (void)mouseEntered:(NSEvent*)event { |
| 352 [delegate_ mouseEnteredButton:self event:event]; | 355 [delegate_ mouseEnteredButton:self event:event]; |
| 353 } | 356 } |
| 354 | 357 |
| 355 // See comments above mouseEntered:. | 358 // See comments above mouseEntered:. |
| 356 - (void)mouseExited:(NSEvent*)event { | 359 - (void)mouseExited:(NSEvent*)event { |
| 357 [delegate_ mouseExitedButton:self event:event]; | 360 [delegate_ mouseExitedButton:self event:event]; |
| 358 } | 361 } |
| 359 | 362 |
| 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 |
| 360 - (void)mouseMoved:(NSEvent*)theEvent { | 373 - (void)mouseMoved:(NSEvent*)theEvent { |
| 361 if ([delegate_ respondsToSelector:@selector(mouseMoved:)]) | 374 if ([delegate_ respondsToSelector:@selector(mouseMoved:)]) |
| 362 [id(delegate_) mouseMoved:theEvent]; | 375 [id(delegate_) mouseMoved:theEvent]; |
| 363 } | 376 } |
| 364 | 377 |
| 365 - (void)mouseDragged:(NSEvent*)theEvent { | 378 - (void)mouseDragged:(NSEvent*)theEvent { |
| 366 if ([delegate_ respondsToSelector:@selector(mouseDragged:)]) | 379 if ([delegate_ respondsToSelector:@selector(mouseDragged:)]) |
| 367 [id(delegate_) mouseDragged:theEvent]; | 380 [id(delegate_) mouseDragged:theEvent]; |
| 368 } | 381 } |
| 369 | 382 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // CoreAnimation is enabled. | 431 // CoreAnimation is enabled. |
| 419 return YES; | 432 return YES; |
| 420 } | 433 } |
| 421 | 434 |
| 422 - (void)drawRect:(NSRect)rect { | 435 - (void)drawRect:(NSRect)rect { |
| 423 NSView* bookmarkBarToolbarView = [[self superview] superview]; | 436 NSView* bookmarkBarToolbarView = [[self superview] superview]; |
| 424 [self cr_drawUsingAncestor:bookmarkBarToolbarView inRect:(NSRect)rect]; | 437 [self cr_drawUsingAncestor:bookmarkBarToolbarView inRect:(NSRect)rect]; |
| 425 [super drawRect:rect]; | 438 [super drawRect:rect]; |
| 426 } | 439 } |
| 427 | 440 |
| 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 |
| 428 - (void)viewDidMoveToWindow { | 469 - (void)viewDidMoveToWindow { |
| 429 [super viewDidMoveToWindow]; | 470 [super viewDidMoveToWindow]; |
| 430 if ([self window]) { | 471 if ([self window]) { |
| 431 // The new window may have different main window status. | 472 // The new window may have different main window status. |
| 432 // This happens when the view is moved into a TabWindowOverlayWindow for | 473 // This happens when the view is moved into a TabWindowOverlayWindow for |
| 433 // tab dragging. | 474 // tab dragging. |
| 475 [self updateIconToMatchTheme]; |
| 434 [self windowDidChangeActive]; | 476 [self windowDidChangeActive]; |
| 435 } | 477 } |
| 436 } | 478 } |
| 437 | 479 |
| 438 // ThemedWindowDrawing implementation. | 480 // ThemedWindowDrawing implementation. |
| 439 | 481 |
| 440 - (void)windowDidChangeTheme { | 482 - (void)windowDidChangeTheme { |
| 483 [self updateIconToMatchTheme]; |
| 441 [self setNeedsDisplay:YES]; | 484 [self setNeedsDisplay:YES]; |
| 442 } | 485 } |
| 443 | 486 |
| 444 - (void)windowDidChangeActive { | 487 - (void)windowDidChangeActive { |
| 445 [self setNeedsDisplay:YES]; | 488 [self setNeedsDisplay:YES]; |
| 446 } | 489 } |
| 447 | 490 |
| 448 - (void)installCustomTrackingArea { | 491 - (void)installCustomTrackingArea { |
| 449 const NSTrackingAreaOptions options = | 492 const NSTrackingAreaOptions options = |
| 450 NSTrackingActiveAlways | | 493 NSTrackingActiveAlways | |
| (...skipping 28 matching lines...) Expand all Loading... |
| 479 [[cell clipPathForFrame:bounds inView:self] setClip]; | 522 [[cell clipPathForFrame:bounds inView:self] setClip]; |
| 480 [cell drawWithFrame:bounds inView:self]; | 523 [cell drawWithFrame:bounds inView:self]; |
| 481 | 524 |
| 482 CGContextEndTransparencyLayer(cgContext); | 525 CGContextEndTransparencyLayer(cgContext); |
| 483 [image unlockFocus]; | 526 [image unlockFocus]; |
| 484 | 527 |
| 485 return image.autorelease(); | 528 return image.autorelease(); |
| 486 } | 529 } |
| 487 | 530 |
| 488 @end | 531 @end |
| OLD | NEW |