| 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" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 - (NSImage*)dragImage; | 52 - (NSImage*)dragImage; |
| 53 | 53 |
| 54 - (void)installCustomTrackingArea; | 54 - (void)installCustomTrackingArea; |
| 55 | 55 |
| 56 @end // @interface BookmarkButton(Private) | 56 @end // @interface BookmarkButton(Private) |
| 57 | 57 |
| 58 @implementation BookmarkButton | 58 @implementation BookmarkButton |
| 59 | 59 |
| 60 @synthesize delegate = delegate_; | 60 @synthesize delegate = delegate_; |
| 61 @synthesize acceptsTrackIn = acceptsTrackIn_; | 61 @synthesize acceptsTrackIn = acceptsTrackIn_; |
| 62 @synthesize backgroundColor = backgroundColor_; |
| 62 | 63 |
| 63 - (id)initWithFrame:(NSRect)frameRect { | 64 - (id)initWithFrame:(NSRect)frameRect { |
| 64 // BookmarkButton's ViewID may be changed to VIEW_ID_OTHER_BOOKMARKS in | 65 // BookmarkButton's ViewID may be changed to VIEW_ID_OTHER_BOOKMARKS in |
| 65 // BookmarkBarController, so we can't just override -viewID method to return | 66 // BookmarkBarController, so we can't just override -viewID method to return |
| 66 // it. | 67 // it. |
| 67 if ((self = [super initWithFrame:frameRect])) { | 68 if ((self = [super initWithFrame:frameRect])) { |
| 68 view_id_util::SetID(self, VIEW_ID_BOOKMARK_BAR_ELEMENT); | 69 view_id_util::SetID(self, VIEW_ID_BOOKMARK_BAR_ELEMENT); |
| 69 [self installCustomTrackingArea]; | 70 [self installCustomTrackingArea]; |
| 70 } | 71 } |
| 71 return self; | 72 return self; |
| 72 } | 73 } |
| 73 | 74 |
| 74 - (void)dealloc { | 75 - (void)dealloc { |
| 75 if ([[self cell] respondsToSelector:@selector(safelyStopPulsing)]) | 76 if ([[self cell] respondsToSelector:@selector(safelyStopPulsing)]) |
| 76 [[self cell] safelyStopPulsing]; | 77 [[self cell] safelyStopPulsing]; |
| 77 view_id_util::UnsetID(self); | 78 view_id_util::UnsetID(self); |
| 78 | 79 |
| 79 if (area_) { | 80 if (area_) { |
| 80 [self removeTrackingArea:area_]; | 81 [self removeTrackingArea:area_]; |
| 81 [area_ release]; | 82 [area_ release]; |
| 82 } | 83 } |
| 83 | 84 |
| 85 [backgroundColor_ release]; |
| 86 |
| 84 [super dealloc]; | 87 [super dealloc]; |
| 85 } | 88 } |
| 86 | 89 |
| 87 - (const BookmarkNode*)bookmarkNode { | 90 - (const BookmarkNode*)bookmarkNode { |
| 88 return [[self cell] bookmarkNode]; | 91 return [[self cell] bookmarkNode]; |
| 89 } | 92 } |
| 90 | 93 |
| 91 - (BOOL)isFolder { | 94 - (BOOL)isFolder { |
| 92 const BookmarkNode* node = [self bookmarkNode]; | 95 const BookmarkNode* node = [self bookmarkNode]; |
| 93 return (node && node->is_folder()); | 96 return (node && node->is_folder()); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 420 } |
| 418 | 421 |
| 419 - (BOOL)isOpaque { | 422 - (BOOL)isOpaque { |
| 420 // Make this control opaque so that sub-pixel anti-aliasing works when | 423 // Make this control opaque so that sub-pixel anti-aliasing works when |
| 421 // CoreAnimation is enabled. | 424 // CoreAnimation is enabled. |
| 422 return YES; | 425 return YES; |
| 423 } | 426 } |
| 424 | 427 |
| 425 - (void)drawRect:(NSRect)rect { | 428 - (void)drawRect:(NSRect)rect { |
| 426 NSView* bookmarkBarToolbarView = [[self superview] superview]; | 429 NSView* bookmarkBarToolbarView = [[self superview] superview]; |
| 427 [self cr_drawUsingAncestor:bookmarkBarToolbarView inRect:(NSRect)rect]; | 430 if (backgroundColor_) { |
| 431 [backgroundColor_ set]; |
| 432 NSRectFill(rect); |
| 433 } else { |
| 434 [self cr_drawUsingAncestor:bookmarkBarToolbarView inRect:(NSRect)rect]; |
| 435 } |
| 428 [super drawRect:rect]; | 436 [super drawRect:rect]; |
| 429 } | 437 } |
| 430 | 438 |
| 431 - (void)updateIconToMatchTheme { | 439 - (void)updateIconToMatchTheme { |
| 432 if (!ui::MaterialDesignController::IsModeMaterial()) { | 440 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 433 return; | 441 return; |
| 434 } | 442 } |
| 435 | 443 |
| 436 // During testing, the window might not be a browser window, and the | 444 // During testing, the window might not be a browser window, and the |
| 437 // superview might not be a BookmarkBarView. | 445 // superview might not be a BookmarkBarView. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 [[cell clipPathForFrame:bounds inView:self] setClip]; | 526 [[cell clipPathForFrame:bounds inView:self] setClip]; |
| 519 [cell drawWithFrame:bounds inView:self]; | 527 [cell drawWithFrame:bounds inView:self]; |
| 520 | 528 |
| 521 CGContextEndTransparencyLayer(cgContext); | 529 CGContextEndTransparencyLayer(cgContext); |
| 522 [image unlockFocus]; | 530 [image unlockFocus]; |
| 523 | 531 |
| 524 return image.autorelease(); | 532 return image.autorelease(); |
| 525 } | 533 } |
| 526 | 534 |
| 527 @end | 535 @end |
| OLD | NEW |