Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/ui/cocoa/new_tab_button.mm

Issue 1751153002: Adjust new tab button path to get crisp line along top edge (Mac). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/new_tab_button.h" 5 #import "chrome/browser/ui/cocoa/new_tab_button.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/mac/sdk_forward_declarations.h" 8 #include "base/mac/sdk_forward_declarations.h"
9 #import "chrome/browser/ui/cocoa/image_button_cell.h" 9 #import "chrome/browser/ui/cocoa/image_button_cell.h"
10 #include "chrome/browser/ui/cocoa/tabs/tab_view.h" 10 #include "chrome/browser/ui/cocoa/tabs/tab_view.h"
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 [imageRep setRenderingOption:renderingOption]; 353 [imageRep setRenderingOption:renderingOption];
354 354
355 NSImage* newTabButtonImage = 355 NSImage* newTabButtonImage =
356 [[[NSImage alloc] initWithSize:NSMakeSize(34, 17)] autorelease]; 356 [[[NSImage alloc] initWithSize:NSMakeSize(34, 17)] autorelease];
357 [newTabButtonImage setCacheMode:NSImageCacheAlways]; 357 [newTabButtonImage setCacheMode:NSImageCacheAlways];
358 [newTabButtonImage addRepresentation:imageRep]; 358 [newTabButtonImage addRepresentation:imageRep];
359 359
360 return newTabButtonImage; 360 return newTabButtonImage;
361 } 361 }
362 362
363 + (NSBezierPath*)newTabButtonBezierPathWithInset:(CGFloat)inset { 363 + (NSBezierPath*)newTabButtonBezierPathWithInset:(int)inset
364 lineWidth:(CGFloat)lineWidth {
364 NSBezierPath* bezierPath = [NSBezierPath bezierPath]; 365 NSBezierPath* bezierPath = [NSBezierPath bezierPath];
365 366
366 // Bottom edge. 367 // Bottom edge.
367 [bezierPath moveToPoint:NSMakePoint(19 - inset, 1.2825 + inset)]; 368 [bezierPath moveToPoint:NSMakePoint(19 - inset, 1.2825 + inset)];
368 [bezierPath lineToPoint:NSMakePoint(10.45 + inset, 1.2825 + inset)]; 369 [bezierPath lineToPoint:NSMakePoint(10.45 + inset, 1.2825 + inset)];
369 370
370 // Lower-left corner. 371 // Lower-left corner.
371 [bezierPath curveToPoint:NSMakePoint(6.08 + inset, 2.85 + inset) 372 [bezierPath curveToPoint:NSMakePoint(6.08 + inset, 2.85 + inset)
372 controlPoint1:NSMakePoint(10.1664 + inset, 1.3965 + inset) 373 controlPoint1:NSMakePoint(10.1664 + inset, 1.3965 + inset)
373 controlPoint2:NSMakePoint(7.89222 + inset, 0.787708 + inset)]; 374 controlPoint2:NSMakePoint(7.89222 + inset, 0.787708 + inset)];
374 375
375 // Left side. 376 // Left side.
376 [bezierPath lineToPoint:NSMakePoint(0.7125 + inset, 14.25 - inset)]; 377 [bezierPath lineToPoint:NSMakePoint(0.7125 + inset, 14.25 - inset)];
377 378
378 // Upper-left corner. 379 // Upper-left corner.
379 [bezierPath curveToPoint:NSMakePoint(1.71 + inset, 16.2688 - inset) 380 const float topEdgeY = 16.2688;
381 [bezierPath curveToPoint:NSMakePoint(1.71 + inset, topEdgeY - inset)
380 controlPoint1:NSMakePoint(0.246496 + inset, 15.2613 - inset) 382 controlPoint1:NSMakePoint(0.246496 + inset, 15.2613 - inset)
381 controlPoint2:NSMakePoint(0.916972 + inset, 16.3489 - inset)]; 383 controlPoint2:NSMakePoint(0.916972 + inset, 16.3489 - inset)];
382 384
383 // Top edge. 385 // Top edge.
384 [bezierPath lineToPoint:NSMakePoint(23.275 - inset, 16.2688 - inset)]; 386 [bezierPath lineToPoint:NSMakePoint(23.275 - inset, topEdgeY - inset)];
385 387
386 // Upper right corner. 388 // Upper right corner.
387 [bezierPath curveToPoint:NSMakePoint(27.645 - inset, 14.7012 - inset) 389 [bezierPath curveToPoint:NSMakePoint(27.645 - inset, 14.7012 - inset)
388 controlPoint1:NSMakePoint(26.4376 - inset, 16.3305 - inset) 390 controlPoint1:NSMakePoint(26.4376 - inset, 16.3305 - inset)
389 controlPoint2:NSMakePoint(26.9257 - inset, 15.8059 - inset)]; 391 controlPoint2:NSMakePoint(26.9257 - inset, 15.8059 - inset)];
390 392
391 // Right side. 393 // Right side.
392 [bezierPath lineToPoint:NSMakePoint(32.9543 - inset, 3.62561 + inset)]; 394 [bezierPath lineToPoint:NSMakePoint(32.9543 - inset, 3.62561 + inset)];
393 395
394 // Lower right corner. 396 // Lower right corner.
395 [bezierPath curveToPoint:NSMakePoint(32.015 - inset, 1.2825 + inset) 397 [bezierPath curveToPoint:NSMakePoint(32.015 - inset, 1.2825 + inset)
396 controlPoint1:NSMakePoint(34.069 - inset, 1.45303 + inset) 398 controlPoint1:NSMakePoint(34.069 - inset, 1.45303 + inset)
397 controlPoint2:NSMakePoint(31.0348 - inset, 1.31455 + inset)]; 399 controlPoint2:NSMakePoint(31.0348 - inset, 1.31455 + inset)];
398 400
399 [bezierPath closePath]; 401 [bezierPath closePath];
400 402
403 // On non-Retina machines, adjust the path so that the top line rests along
404 // a pixel line (to get a crisp line on the display).
405 if (lineWidth == 1) {
406 NSAffineTransform* translateTransform = [NSAffineTransform transform];
407 [translateTransform translateXBy:0
408 yBy:0.5 - (topEdgeY - trunc(topEdgeY))];
409 [bezierPath transformUsingAffineTransform:translateTransform];
410 }
411
412 [bezierPath setLineWidth:lineWidth];
413
401 return bezierPath; 414 return bezierPath;
402 } 415 }
403 416
404 + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep { 417 + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep {
405 [[NSGraphicsContext currentContext] 418 [[NSGraphicsContext currentContext]
406 cr_setPatternPhase:[imageRep patternPhasePosition] 419 cr_setPatternPhase:[imageRep patternPhasePosition]
407 forView:[imageRep destView]]; 420 forView:[imageRep destView]];
408 421
409 NSBezierPath* bezierPath = [self newTabButtonBezierPathWithInset:0];
410 CGContextRef context = static_cast<CGContextRef>( 422 CGContextRef context = static_cast<CGContextRef>(
411 [[NSGraphicsContext currentContext] graphicsPort]); 423 [[NSGraphicsContext currentContext] graphicsPort]);
412 CGFloat lineWidth = LineWidthFromContext(context); 424 CGFloat lineWidth = LineWidthFromContext(context);
413 [bezierPath setLineWidth:lineWidth]; 425 NSBezierPath* bezierPath = [self newTabButtonBezierPathWithInset:0
426 lineWidth:lineWidth];
414 427
415 if ([imageRep fillColor]) { 428 if ([imageRep fillColor]) {
416 [[imageRep fillColor] set]; 429 [[imageRep fillColor] set];
417 [bezierPath fill]; 430 [bezierPath fill];
418 } 431 }
419 432
420 static NSColor* strokeColor = 433 static NSColor* strokeColor =
421 [[NSColor colorWithCalibratedWhite:0 alpha:0.4] retain]; 434 [[NSColor colorWithCalibratedWhite:0 alpha:0.4] retain];
422 [strokeColor set]; 435 [strokeColor set];
423 [bezierPath stroke]; 436 [bezierPath stroke];
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 481
469 case RenderingOption::INLAY_LIGHTEN: 482 case RenderingOption::INLAY_LIGHTEN:
470 [lightColor set]; 483 [lightColor set];
471 inset = 1; 484 inset = 1;
472 break; 485 break;
473 486
474 case RenderingOption::NORMAL: 487 case RenderingOption::NORMAL:
475 break; 488 break;
476 } 489 }
477 if (inset != -1) { 490 if (inset != -1) {
478 bezierPath = [self newTabButtonBezierPathWithInset:inset]; 491 bezierPath = [self newTabButtonBezierPathWithInset:inset
479 [bezierPath setLineWidth:lineWidth]; 492 lineWidth:lineWidth];
480 [bezierPath fill]; 493 [bezierPath fill];
481 } 494 }
482 } 495 }
483 496
484 - (NSImage*)imageWithFillColor:(NSColor*)fillColor { 497 - (NSImage*)imageWithFillColor:(NSColor*)fillColor {
485 NSImage* image = 498 NSImage* image =
486 [[[NSImage alloc] initWithSize:NSMakeSize(34, 17)] autorelease]; 499 [[[NSImage alloc] initWithSize:NSMakeSize(34, 17)] autorelease];
487 500
488 [image lockFocus]; 501 [image lockFocus];
489 [fillColor set]; 502 [fillColor set];
490 [[NewTabButton newTabButtonBezierPathWithInset:0] fill]; 503 CGContextRef context = static_cast<CGContextRef>(
504 [[NSGraphicsContext currentContext] graphicsPort]);
505 CGFloat lineWidth = LineWidthFromContext(context);
506 [[NewTabButton newTabButtonBezierPathWithInset:0 lineWidth:lineWidth] fill];
491 [image unlockFocus]; 507 [image unlockFocus];
492 return image; 508 return image;
493 } 509 }
494 510
495 @end 511 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698