| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/page_info/split_block_button.h" | 5 #import "chrome/browser/ui/cocoa/page_info/split_block_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/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 [path appendBezierPathWithArcFromPoint:NSMakePoint(x1, y1) | 58 [path appendBezierPathWithArcFromPoint:NSMakePoint(x1, y1) |
| 59 toPoint:NSMakePoint(x1, y1 - radius) | 59 toPoint:NSMakePoint(x1, y1 - radius) |
| 60 radius:radius]; | 60 radius:radius]; |
| 61 [path appendBezierPathWithArcFromPoint:NSMakePoint(x1, y0) | 61 [path appendBezierPathWithArcFromPoint:NSMakePoint(x1, y0) |
| 62 toPoint:NSMakePoint(x1 - radius, y0) | 62 toPoint:NSMakePoint(x1 - radius, y0) |
| 63 radius:radius]; | 63 radius:radius]; |
| 64 } | 64 } |
| 65 return path.autorelease(); | 65 return path.autorelease(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void DrawBezel(id<ConstrainedWindowButtonDrawableCell>cell, | 68 void DrawBezel(id<ConstrainedWindowButtonDrawableCell> cell, |
| 69 CornerType leftCorners, | 69 CornerType leftCorners, |
| 70 CornerType rightCorners, | 70 CornerType rightCorners, |
| 71 NSRect frame, | 71 NSRect frame, |
| 72 NSView* view) { | 72 NSView* view) { |
| 73 if ([cell isMouseInside]) { | 73 if ([cell isMouseInside]) { |
| 74 base::scoped_nsobject<NSBezierPath> path( | 74 base::scoped_nsobject<NSBezierPath> path( |
| 75 [PathWithCornerStyles(frame, leftCorners, rightCorners) retain]); | 75 [PathWithCornerStyles(frame, leftCorners, rightCorners) retain]); |
| 76 [ConstrainedWindowButton DrawBackgroundAndShadowForPath:path | 76 [ConstrainedWindowButton DrawBackgroundAndShadowForPath:path |
| 77 withCell:cell | 77 withCell:cell |
| 78 inView:view]; | 78 inView:view]; |
| 79 [ConstrainedWindowButton DrawInnerHighlightForPath:path | 79 [ConstrainedWindowButton DrawInnerHighlightForPath:path |
| 80 withCell:cell | 80 withCell:cell |
| 81 inView:view]; | 81 inView:view]; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 } // namespace | 85 } // namespace |
| 86 | 86 |
| 87 // A button cell used by SplitBlockButton, containing the title. | 87 // A button cell used by SplitBlockButton, containing the title. |
| 88 @interface SplitButtonTitleCell : ConstrainedWindowButtonCell | 88 @interface SplitButtonTitleCell : ConstrainedWindowButtonCell |
| 89 - (NSRect)rect; | 89 - (NSRect)rect; |
| 90 @end | 90 @end |
| 91 | 91 |
| 92 // A button cell used by SplitBlockButton, containing the popup menu. | 92 // A button cell used by SplitBlockButton, containing the popup menu. |
| 93 @interface SplitButtonPopUpCell : | 93 @interface SplitButtonPopUpCell |
| 94 NSPopUpButtonCell<ConstrainedWindowButtonDrawableCell> { | 94 : NSPopUpButtonCell<ConstrainedWindowButtonDrawableCell> { |
| 95 @private | 95 @private |
| 96 BOOL isMouseInside_; | 96 BOOL isMouseInside_; |
| 97 base::scoped_nsobject<MenuController> menuController_; | 97 base::scoped_nsobject<MenuController> menuController_; |
| 98 std::unique_ptr<ui::SimpleMenuModel> menuModel_; | 98 std::unique_ptr<ui::SimpleMenuModel> menuModel_; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Designated initializer. | 101 // Designated initializer. |
| 102 - (id)initWithMenuDelegate:(ui::SimpleMenuModel::Delegate*)menuDelegate; | 102 - (id)initWithMenuDelegate:(ui::SimpleMenuModel::Delegate*)menuDelegate; |
| 103 | 103 |
| 104 - (NSRect)rect; | 104 - (NSRect)rect; |
| 105 | 105 |
| 106 @end | 106 @end |
| 107 | 107 |
| 108 @implementation SplitBlockButton | 108 @implementation SplitBlockButton |
| 109 | 109 |
| 110 - (id)initWithMenuDelegate:(ui::SimpleMenuModel::Delegate*)menuDelegate { | 110 - (id)initWithMenuDelegate:(ui::SimpleMenuModel::Delegate*)menuDelegate { |
| 111 if (self = [super initWithFrame:NSZeroRect]) { | 111 if (self = [super initWithFrame:NSZeroRect]) { |
| 112 leftCell_.reset([[SplitButtonTitleCell alloc] init]); | 112 leftCell_.reset([[SplitButtonTitleCell alloc] init]); |
| 113 rightCell_.reset([[SplitButtonPopUpCell alloc] | 113 rightCell_.reset( |
| 114 initWithMenuDelegate:menuDelegate]); | 114 [[SplitButtonPopUpCell alloc] initWithMenuDelegate:menuDelegate]); |
| 115 [leftCell_ setTitle:l10n_util::GetNSString(IDS_PERMISSION_DENY)]; | 115 [leftCell_ setTitle:l10n_util::GetNSString(IDS_PERMISSION_DENY)]; |
| 116 [leftCell_ setEnabled:YES]; | 116 [leftCell_ setEnabled:YES]; |
| 117 [rightCell_ setEnabled:YES]; | 117 [rightCell_ setEnabled:YES]; |
| 118 } | 118 } |
| 119 return self; | 119 return self; |
| 120 } | 120 } |
| 121 | 121 |
| 122 + (Class)cellClass { | 122 + (Class)cellClass { |
| 123 return nil; | 123 return nil; |
| 124 } | 124 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 inView:self]; | 156 inView:self]; |
| 157 | 157 |
| 158 [rightCell_ setControlView:self]; | 158 [rightCell_ setControlView:self]; |
| 159 [rightCell_ drawWithFrame:NSIntersectionRect(rect, [self rightCellRect]) | 159 [rightCell_ drawWithFrame:NSIntersectionRect(rect, [self rightCellRect]) |
| 160 inView:self]; | 160 inView:self]; |
| 161 | 161 |
| 162 // Draw the border. | 162 // Draw the border. |
| 163 path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(rect, 0.5, 0.5) | 163 path = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(rect, 0.5, 0.5) |
| 164 xRadius:radius | 164 xRadius:radius |
| 165 yRadius:radius]; | 165 yRadius:radius]; |
| 166 [ConstrainedWindowButton DrawBorderForPath:path | 166 [ConstrainedWindowButton DrawBorderForPath:path withCell:nil inView:self]; |
| 167 withCell:nil | |
| 168 inView:self]; | |
| 169 } | 167 } |
| 170 | 168 |
| 171 - (void)updateTrackingAreas { | 169 - (void)updateTrackingAreas { |
| 172 [self updateTrackingArea:&leftTrackingArea_ | 170 [self updateTrackingArea:&leftTrackingArea_ |
| 173 forCell:leftCell_ | 171 forCell:leftCell_ |
| 174 withRect:[self leftCellRect]]; | 172 withRect:[self leftCellRect]]; |
| 175 | 173 |
| 176 [self updateTrackingArea:&rightTrackingArea_ | 174 [self updateTrackingArea:&rightTrackingArea_ |
| 177 forCell:rightCell_ | 175 forCell:rightCell_ |
| 178 withRect:[self rightCellRect]]; | 176 withRect:[self rightCellRect]]; |
| 179 } | 177 } |
| 180 | 178 |
| 181 - (void)updateTrackingArea:(ui::ScopedCrTrackingArea*)trackingArea | 179 - (void)updateTrackingArea:(ui::ScopedCrTrackingArea*)trackingArea |
| 182 forCell:(id<ConstrainedWindowButtonDrawableCell>)cell | 180 forCell:(id<ConstrainedWindowButtonDrawableCell>)cell |
| 183 withRect:(NSRect)rect { | 181 withRect:(NSRect)rect { |
| 184 DCHECK(trackingArea); | 182 DCHECK(trackingArea); |
| 185 NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | | 183 NSTrackingAreaOptions options = |
| 186 NSTrackingActiveInActiveApp; | 184 NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp; |
| 187 [self removeTrackingArea:trackingArea->get()]; | 185 [self removeTrackingArea:trackingArea->get()]; |
| 188 trackingArea->reset([[CrTrackingArea alloc] initWithRect:rect | 186 trackingArea->reset([[CrTrackingArea alloc] initWithRect:rect |
| 189 options:options | 187 options:options |
| 190 owner:self | 188 owner:self |
| 191 userInfo:nil]); | 189 userInfo:nil]); |
| 192 [self addTrackingArea:trackingArea->get()]; | 190 [self addTrackingArea:trackingArea->get()]; |
| 193 } | 191 } |
| 194 | 192 |
| 195 - (void)mouseEntered:(NSEvent*)theEvent { | 193 - (void)mouseEntered:(NSEvent*)theEvent { |
| 196 [self mouseMoved:theEvent]; | 194 [self mouseMoved:theEvent]; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 [self setNeedsDisplay:YES]; | 241 [self setNeedsDisplay:YES]; |
| 244 } | 242 } |
| 245 } | 243 } |
| 246 const NSUInteger mask = NSLeftMouseUpMask | NSLeftMouseDraggedMask; | 244 const NSUInteger mask = NSLeftMouseUpMask | NSLeftMouseDraggedMask; |
| 247 theEvent = [[self window] nextEventMatchingMask:mask]; | 245 theEvent = [[self window] nextEventMatchingMask:mask]; |
| 248 } while ([theEvent type] != NSLeftMouseUp); | 246 } while ([theEvent type] != NSLeftMouseUp); |
| 249 } | 247 } |
| 250 | 248 |
| 251 - (MouseLocation)mouseLocationForEvent:(NSEvent*)theEvent { | 249 - (MouseLocation)mouseLocationForEvent:(NSEvent*)theEvent { |
| 252 MouseLocation location = kNotInside; | 250 MouseLocation location = kNotInside; |
| 253 NSPoint mousePoint = [self convertPoint:[theEvent locationInWindow] | 251 NSPoint mousePoint = |
| 254 fromView:nil]; | 252 [self convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 255 if ([self mouse:mousePoint inRect:[leftCell_ rect]]) | 253 if ([self mouse:mousePoint inRect:[leftCell_ rect]]) |
| 256 location = kInsideLeftCell; | 254 location = kInsideLeftCell; |
| 257 else if ([self mouse:mousePoint inRect:[self rightCellRect]]) | 255 else if ([self mouse:mousePoint inRect:[self rightCellRect]]) |
| 258 location = kInsideRightCell; | 256 location = kInsideRightCell; |
| 259 return location; | 257 return location; |
| 260 } | 258 } |
| 261 | 259 |
| 262 - (void)sizeToFit { | 260 - (void)sizeToFit { |
| 263 NSSize leftSize = [leftCell_ cellSize]; | 261 NSSize leftSize = [leftCell_ cellSize]; |
| 264 NSSize rightSize = [rightCell_ cellSize]; | 262 NSSize rightSize = [rightCell_ cellSize]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 282 | 280 |
| 283 // Accessor for Testing. | 281 // Accessor for Testing. |
| 284 - (NSMenu*)menu { | 282 - (NSMenu*)menu { |
| 285 return [rightCell_ menu]; | 283 return [rightCell_ menu]; |
| 286 } | 284 } |
| 287 | 285 |
| 288 @end | 286 @end |
| 289 | 287 |
| 290 @implementation SplitButtonTitleCell | 288 @implementation SplitButtonTitleCell |
| 291 | 289 |
| 292 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView { | 290 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { |
| 293 DrawBezel(self, kRounded, kAngled, frame, controlView); | 291 DrawBezel(self, kRounded, kAngled, frame, controlView); |
| 294 } | 292 } |
| 295 | 293 |
| 296 - (NSRect)rect { | 294 - (NSRect)rect { |
| 297 NSSize size = [self cellSize]; | 295 NSSize size = [self cellSize]; |
| 298 return NSMakeRect(0, 0, std::ceil(size.width), std::ceil(size.height)); | 296 return NSMakeRect(0, 0, std::ceil(size.width), std::ceil(size.height)); |
| 299 } | 297 } |
| 300 | 298 |
| 301 @end | 299 @end |
| 302 | 300 |
| 303 @implementation SplitButtonPopUpCell | 301 @implementation SplitButtonPopUpCell |
| 304 | 302 |
| 305 @synthesize isMouseInside = isMouseInside_; | 303 @synthesize isMouseInside = isMouseInside_; |
| 306 | 304 |
| 307 - (id)initWithMenuDelegate:(ui::SimpleMenuModel::Delegate*)menuDelegate { | 305 - (id)initWithMenuDelegate:(ui::SimpleMenuModel::Delegate*)menuDelegate { |
| 308 if (self = [super initTextCell:@"" pullsDown:YES]) { | 306 if (self = [super initTextCell:@"" pullsDown:YES]) { |
| 309 [self setControlSize:NSSmallControlSize]; | 307 [self setControlSize:NSSmallControlSize]; |
| 310 [self setArrowPosition:NSPopUpArrowAtCenter]; | 308 [self setArrowPosition:NSPopUpArrowAtCenter]; |
| 311 [self setBordered:NO]; | 309 [self setBordered:NO]; |
| 312 [self setBackgroundColor:[NSColor clearColor]]; | 310 [self setBackgroundColor:[NSColor clearColor]]; |
| 313 menuModel_.reset(new ui::SimpleMenuModel(menuDelegate)); | 311 menuModel_.reset(new ui::SimpleMenuModel(menuDelegate)); |
| 314 menuModel_->AddItemWithStringId(0, IDS_PERMISSION_CUSTOMIZE); | 312 menuModel_->AddItemWithStringId(0, IDS_PERMISSION_CUSTOMIZE); |
| 315 menuController_.reset( | 313 menuController_.reset([[MenuController alloc] initWithModel:menuModel_.get() |
| 316 [[MenuController alloc] initWithModel:menuModel_.get() | 314 useWithPopUpButtonCell:NO]); |
| 317 useWithPopUpButtonCell:NO]); | |
| 318 [self setMenu:[menuController_ menu]]; | 315 [self setMenu:[menuController_ menu]]; |
| 319 [self setUsesItemFromMenu:NO]; | 316 [self setUsesItemFromMenu:NO]; |
| 320 } | 317 } |
| 321 return self; | 318 return self; |
| 322 } | 319 } |
| 323 | 320 |
| 324 - (void)drawBorderAndBackgroundWithFrame:(NSRect)frame | 321 - (void)drawBorderAndBackgroundWithFrame:(NSRect)frame |
| 325 inView:(NSView*)controlView { | 322 inView:(NSView*)controlView { |
| 326 // The arrow, which is what should be drawn by the base class, is drawn | 323 // The arrow, which is what should be drawn by the base class, is drawn |
| 327 // during -drawBezelWithFrame. The only way to draw our own border with | 324 // during -drawBezelWithFrame. The only way to draw our own border with |
| 328 // the default arrow is to make the cell unbordered, and draw the border | 325 // the default arrow is to make the cell unbordered, and draw the border |
| 329 // from -drawBorderAndBackgroundWithFrame, rather than simply overriding | 326 // from -drawBorderAndBackgroundWithFrame, rather than simply overriding |
| 330 // -drawBezelWithFrame. | 327 // -drawBezelWithFrame. |
| 331 DrawBezel(self, kAngled, kRounded, frame, controlView); | 328 DrawBezel(self, kAngled, kRounded, frame, controlView); |
| 332 [super drawBorderAndBackgroundWithFrame:NSOffsetRect(frame, -4, 0) | 329 [super drawBorderAndBackgroundWithFrame:NSOffsetRect(frame, -4, 0) |
| 333 inView:controlView]; | 330 inView:controlView]; |
| 334 } | 331 } |
| 335 | 332 |
| 336 - (NSRect)rect { | 333 - (NSRect)rect { |
| 337 NSSize size = [self cellSize]; | 334 NSSize size = [self cellSize]; |
| 338 return NSMakeRect(0, 0, std::ceil(size.width), std::ceil(size.height)); | 335 return NSMakeRect(0, 0, std::ceil(size.width), std::ceil(size.height)); |
| 339 } | 336 } |
| 340 | 337 |
| 341 @end | 338 @end |
| OLD | NEW |