| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_bar_view.h" | 5 #import "chrome/browser/cocoa/bookmark_bar_view.h" |
| 6 | 6 |
| 7 #import "chrome/browser/cocoa/bookmark_bar_controller.h" | 7 #import "chrome/browser/cocoa/bookmark_bar_controller.h" |
| 8 #import "chrome/browser/cocoa/bookmark_button.h" | 8 #import "chrome/browser/cocoa/bookmark_button.h" |
| 9 #import "third_party/GTM/AppKit/GTMTheme.h" | 9 #import "third_party/GTM/AppKit/GTMTheme.h" |
| 10 #import "third_party/mozilla/include/NSPasteboard+Utils.h" | 10 #import "third_party/mozilla/include/NSPasteboard+Utils.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // Mouse down events on the bookmark bar should not allow dragging the parent | 65 // Mouse down events on the bookmark bar should not allow dragging the parent |
| 66 // window around. | 66 // window around. |
| 67 - (BOOL)mouseDownCanMoveWindow { | 67 - (BOOL)mouseDownCanMoveWindow { |
| 68 return NO; | 68 return NO; |
| 69 } | 69 } |
| 70 | 70 |
| 71 -(NSTextField*)noItemTextfield { | 71 -(NSTextField*)noItemTextfield { |
| 72 return noItemTextfield_; | 72 return noItemTextfield_; |
| 73 } | 73 } |
| 74 | 74 |
| 75 -(void)drawRect:(NSRect)dirtyRect { |
| 76 [super drawRect:dirtyRect]; |
| 77 |
| 78 // Draw the bookmark-button-dragging drop indicator if necessary. |
| 79 if (dropIndicatorShown_) { |
| 80 const CGFloat kBarWidth = 1; |
| 81 const CGFloat kBarHalfWidth = kBarWidth / 2.0; |
| 82 const CGFloat kBarVertPad = 4; |
| 83 const CGFloat kBarOpacity = 0.85; |
| 84 |
| 85 // Prevent the indicator from being clipped on the left. |
| 86 CGFloat xLeft = MAX(dropIndicatorPosition_ - kBarHalfWidth, 0); |
| 87 |
| 88 NSRect uglyBlackBar = |
| 89 NSMakeRect(xLeft, kBarVertPad, |
| 90 kBarWidth, NSHeight([self bounds]) - 2 * kBarVertPad); |
| 91 NSColor* uglyBlackBarColor = |
| 92 [[self gtm_theme] textColorForStyle:GTMThemeStyleBookmarksBarButton |
| 93 state:GTMThemeStateActiveWindow]; |
| 94 [[uglyBlackBarColor colorWithAlphaComponent:kBarOpacity] setFill]; |
| 95 [[NSBezierPath bezierPathWithRect:uglyBlackBar] fill]; |
| 96 } |
| 97 } |
| 98 |
| 75 // NSDraggingDestination methods | 99 // NSDraggingDestination methods |
| 76 | 100 |
| 77 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info { | 101 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info { |
| 78 if ([[info draggingPasteboard] containsURLData]) | 102 if ([[info draggingPasteboard] containsURLData]) |
| 79 return NSDragOperationCopy; | 103 return NSDragOperationCopy; |
| 80 if ([[info draggingPasteboard] dataForType:kBookmarkButtonDragType]) | 104 if ([[info draggingPasteboard] dataForType:kBookmarkButtonDragType]) { |
| 105 NSData* data = [[info draggingPasteboard] |
| 106 dataForType:kBookmarkButtonDragType]; |
| 107 // [info draggingSource] is nil if not the same application. |
| 108 if (data && [info draggingSource]) { |
| 109 // Find the position of the drop indicator. |
| 110 BookmarkButton* button = nil; |
| 111 [data getBytes:&button length:sizeof(button)]; |
| 112 CGFloat x = |
| 113 [controller_ indicatorPosForDragOfButton:button |
| 114 toPoint:[info draggingLocation]]; |
| 115 |
| 116 // Need an update if the indicator wasn't previously shown or if it has |
| 117 // moved. |
| 118 if (!dropIndicatorShown_ || dropIndicatorPosition_ != x) { |
| 119 dropIndicatorShown_ = YES; |
| 120 dropIndicatorPosition_ = x; |
| 121 [self setNeedsDisplay:YES]; |
| 122 } |
| 123 } |
| 124 |
| 81 return NSDragOperationMove; | 125 return NSDragOperationMove; |
| 126 } |
| 82 return NSDragOperationNone; | 127 return NSDragOperationNone; |
| 83 } | 128 } |
| 84 | 129 |
| 130 - (void)draggingExited:(id<NSDraggingInfo>)info { |
| 131 // Regardless of the type of dragging which ended, we need to get rid of the |
| 132 // drop indicator if one was shown. |
| 133 if (dropIndicatorShown_) { |
| 134 dropIndicatorShown_ = NO; |
| 135 [self setNeedsDisplay:YES]; |
| 136 } |
| 137 } |
| 138 |
| 139 - (void)draggingEnded:(id<NSDraggingInfo>)info { |
| 140 // For now, we just call |-draggingExited:|. |
| 141 [self draggingExited:info]; |
| 142 } |
| 143 |
| 85 - (BOOL)wantsPeriodicDraggingUpdates { | 144 - (BOOL)wantsPeriodicDraggingUpdates { |
| 86 // TODO(port): This should probably return |YES| and the controller should | 145 // TODO(port): This should probably return |YES| and the controller should |
| 87 // slide the existing bookmark buttons interactively to the side to make | 146 // slide the existing bookmark buttons interactively to the side to make |
| 88 // room for the about-to-be-dropped bookmark. | 147 // room for the about-to-be-dropped bookmark. |
| 89 return NO; | 148 return NO; |
| 90 } | 149 } |
| 91 | 150 |
| 92 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info { | 151 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)info { |
| 93 // For now it's the same as draggingEntered:. | 152 // For now it's the same as draggingEntered:. |
| 94 // TODO(jrg): once we return YES for wantsPeriodicDraggingUpdates, | 153 // TODO(jrg): once we return YES for wantsPeriodicDraggingUpdates, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 @end // @implementation BookmarkBarView | 204 @end // @implementation BookmarkBarView |
| 146 | 205 |
| 147 | 206 |
| 148 @implementation BookmarkBarView(TestingAPI) | 207 @implementation BookmarkBarView(TestingAPI) |
| 149 | 208 |
| 150 - (void)setController:(id)controller { | 209 - (void)setController:(id)controller { |
| 151 controller_ = controller; | 210 controller_ = controller; |
| 152 } | 211 } |
| 153 | 212 |
| 154 @end // @implementation BookmarkBarView(TestingAPI) | 213 @end // @implementation BookmarkBarView(TestingAPI) |
| OLD | NEW |