OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/chrome/browser/ui/tabs/tab_util.h" |
| 6 |
| 7 #include <sys/sysctl.h> |
| 8 |
| 9 namespace { |
| 10 |
| 11 // Constants for inset and control points for tab shape. |
| 12 const CGFloat kInsetMultiplier = 2.0 / 3.0; |
| 13 const CGFloat kControlPoint1Multiplier = 1.0 / 3.0; |
| 14 const CGFloat kControlPoint2Multiplier = 3.0 / 8.0; |
| 15 |
| 16 } // anonymous namespace |
| 17 |
| 18 namespace ios_internal { |
| 19 namespace tab_util { |
| 20 |
| 21 UIBezierPath* tabBezierPathForRect(CGRect rect) { |
| 22 const CGFloat lineWidth = 1.0; |
| 23 const CGFloat halfLineWidth = lineWidth / 2.0; |
| 24 |
| 25 // Outset by halfLineWidth in order to draw on pixels rather than on borders |
| 26 // (which would cause blurry pixels). Offset instead of outset vertically, |
| 27 // otherwise clipping will occur. |
| 28 rect = CGRectInset(rect, -halfLineWidth, 0); |
| 29 rect.origin.y += halfLineWidth; |
| 30 |
| 31 CGPoint bottomLeft = |
| 32 CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect) - (2 * lineWidth)); |
| 33 CGPoint bottomRight = |
| 34 CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect) - (2 * lineWidth)); |
| 35 CGPoint topRight = CGPointMake( |
| 36 CGRectGetMaxX(rect) - (kInsetMultiplier * CGRectGetHeight(rect)), |
| 37 CGRectGetMinY(rect)); |
| 38 CGPoint topLeft = CGPointMake( |
| 39 CGRectGetMinX(rect) + (kInsetMultiplier * CGRectGetHeight(rect)), |
| 40 CGRectGetMinY(rect)); |
| 41 |
| 42 CGFloat baseControlPointOutset = |
| 43 CGRectGetHeight(rect) * kControlPoint1Multiplier; |
| 44 CGFloat bottomControlPointInset = |
| 45 CGRectGetHeight(rect) * kControlPoint2Multiplier; |
| 46 |
| 47 // Outset many of these values by lineWidth to cause the fill to bleed outside |
| 48 // the clip area. |
| 49 UIBezierPath* path = [UIBezierPath bezierPath]; |
| 50 [path moveToPoint:CGPointMake(bottomLeft.x - lineWidth, |
| 51 bottomLeft.y + (2 * lineWidth))]; |
| 52 [path addLineToPoint:CGPointMake(bottomLeft.x - lineWidth, bottomLeft.y)]; |
| 53 [path addLineToPoint:bottomLeft]; |
| 54 [path addCurveToPoint:topLeft |
| 55 controlPoint1:CGPointMake(bottomLeft.x + baseControlPointOutset, |
| 56 bottomLeft.y) |
| 57 controlPoint2:CGPointMake(topLeft.x - bottomControlPointInset, |
| 58 topLeft.y)]; |
| 59 [path addLineToPoint:topRight]; |
| 60 [path addCurveToPoint:bottomRight |
| 61 controlPoint1:CGPointMake(topRight.x + bottomControlPointInset, |
| 62 topRight.y) |
| 63 controlPoint2:CGPointMake(bottomRight.x - baseControlPointOutset, |
| 64 bottomRight.y)]; |
| 65 [path addLineToPoint:CGPointMake(bottomRight.x + lineWidth, bottomRight.y)]; |
| 66 [path addLineToPoint:CGPointMake(bottomRight.x + lineWidth, |
| 67 bottomRight.y + (2 * lineWidth))]; |
| 68 return path; |
| 69 } |
| 70 |
| 71 } // namespace tab_util |
| 72 } // namespace ios_internal |
OLD | NEW |