| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/bookmark_button.h" | 5 #import "chrome/browser/cocoa/bookmark_button.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #import "base/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model.h" | 8 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 9 #import "chrome/browser/cocoa/bookmark_button_cell.h" | 9 #import "chrome/browser/cocoa/bookmark_button_cell.h" |
| 10 #import "chrome/browser/cocoa/browser_window_controller.h" | 10 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 11 #import "chrome/browser/cocoa/view_id_util.h" | 11 #import "chrome/browser/cocoa/view_id_util.h" |
| 12 | 12 |
| 13 // The opacity of the bookmark button drag image. | 13 // The opacity of the bookmark button drag image. |
| 14 static const CGFloat kDragImageOpacity = 0.7; | 14 static const CGFloat kDragImageOpacity = 0.7; |
| 15 | 15 |
| 16 |
| 17 namespace bookmark_button { |
| 18 |
| 19 const NSString* kPulseBookmarkButtonNotification = |
| 20 @"PulseBookmarkButtonNotification"; |
| 21 const NSString* kBookmarkKey = @"BookmarkKey"; |
| 22 const NSString* kBookmarkPulseFlagKey = @"BookmarkPulseFlagKey"; |
| 23 |
| 24 }; |
| 25 |
| 16 @interface BookmarkButton(Private) | 26 @interface BookmarkButton(Private) |
| 17 | 27 |
| 18 // Make a drag image for the button. | 28 // Make a drag image for the button. |
| 19 - (NSImage*)dragImage; | 29 - (NSImage*)dragImage; |
| 20 | 30 |
| 21 @end // @interface BookmarkButton(Private) | 31 @end // @interface BookmarkButton(Private) |
| 22 | 32 |
| 23 | 33 |
| 24 @implementation BookmarkButton | 34 @implementation BookmarkButton |
| 25 | 35 |
| 26 @synthesize delegate = delegate_; | 36 @synthesize delegate = delegate_; |
| 27 | 37 |
| 28 - (id)initWithFrame:(NSRect)frameRect { | 38 - (id)initWithFrame:(NSRect)frameRect { |
| 29 // BookmarkButton's ViewID may be changed to VIEW_ID_OTHER_BOOKMARKS in | 39 // BookmarkButton's ViewID may be changed to VIEW_ID_OTHER_BOOKMARKS in |
| 30 // BookmarkBarController, so we can't just override -viewID method to return | 40 // BookmarkBarController, so we can't just override -viewID method to return |
| 31 // it. | 41 // it. |
| 32 if ((self = [super initWithFrame:frameRect])) | 42 if ((self = [super initWithFrame:frameRect])) |
| 33 view_id_util::SetID(self, VIEW_ID_BOOKMARK_BAR_ELEMENT); | 43 view_id_util::SetID(self, VIEW_ID_BOOKMARK_BAR_ELEMENT); |
| 34 return self; | 44 return self; |
| 35 } | 45 } |
| 36 | 46 |
| 37 - (void)dealloc { | 47 - (void)dealloc { |
| 48 if ([[self cell] respondsToSelector:@selector(safelyStopPulsing)]) |
| 49 [[self cell] safelyStopPulsing]; |
| 38 view_id_util::UnsetID(self); | 50 view_id_util::UnsetID(self); |
| 39 [super dealloc]; | 51 [super dealloc]; |
| 40 } | 52 } |
| 41 | 53 |
| 42 - (const BookmarkNode*)bookmarkNode { | 54 - (const BookmarkNode*)bookmarkNode { |
| 43 return [[self cell] bookmarkNode]; | 55 return [[self cell] bookmarkNode]; |
| 44 } | 56 } |
| 45 | 57 |
| 46 - (BOOL)isFolder { | 58 - (BOOL)isFolder { |
| 47 const BookmarkNode* node = [self bookmarkNode]; | 59 const BookmarkNode* node = [self bookmarkNode]; |
| 48 return (node && node->is_folder()); | 60 return (node && node->is_folder()); |
| 49 } | 61 } |
| 50 | 62 |
| 51 - (BOOL)isEmpty { | 63 - (BOOL)isEmpty { |
| 52 return [self bookmarkNode] ? NO : YES; | 64 return [self bookmarkNode] ? NO : YES; |
| 53 } | 65 } |
| 54 | 66 |
| 67 - (void)setIsContinuousPulsing:(BOOL)flag { |
| 68 [[self cell] setIsContinuousPulsing:flag]; |
| 69 } |
| 70 |
| 71 - (BOOL)isContinuousPulsing { |
| 72 return [[self cell] isContinuousPulsing]; |
| 73 } |
| 74 |
| 55 // By default, NSButton ignores middle-clicks. | 75 // By default, NSButton ignores middle-clicks. |
| 56 // But we want them. | 76 // But we want them. |
| 57 - (void)otherMouseUp:(NSEvent*)event { | 77 - (void)otherMouseUp:(NSEvent*)event { |
| 58 [self performClick:self]; | 78 [self performClick:self]; |
| 59 } | 79 } |
| 60 | 80 |
| 61 // Overridden from DraggableButton. | 81 // Overridden from DraggableButton. |
| 62 - (void)beginDrag:(NSEvent*)event { | 82 - (void)beginDrag:(NSEvent*)event { |
| 63 // Don't allow a drag of the empty node. | 83 // Don't allow a drag of the empty node. |
| 64 // The empty node is a placeholder for "(empty)", to be revisited. | 84 // The empty node is a placeholder for "(empty)", to be revisited. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 [image drawAtPoint:NSMakePoint(0, 0) | 179 [image drawAtPoint:NSMakePoint(0, 0) |
| 160 fromRect:NSMakeRect(0, 0, NSWidth(bounds), NSHeight(bounds)) | 180 fromRect:NSMakeRect(0, 0, NSWidth(bounds), NSHeight(bounds)) |
| 161 operation:NSCompositeSourceOver | 181 operation:NSCompositeSourceOver |
| 162 fraction:kDragImageOpacity]; | 182 fraction:kDragImageOpacity]; |
| 163 | 183 |
| 164 [dragImage unlockFocus]; | 184 [dragImage unlockFocus]; |
| 165 return dragImage; | 185 return dragImage; |
| 166 } | 186 } |
| 167 | 187 |
| 168 @end // @implementation BookmarkButton(Private) | 188 @end // @implementation BookmarkButton(Private) |
| OLD | NEW |