1 // Copyright (c) 2013 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.
5 #import "chrome/browser/ui/cocoa/rect_path_utils.h"
7 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect.h"
9 namespace rect_path_utils {
11 NSBezierPath* RectPathWithInset(RoundedCornerFlags roundedCornerFlags,
15 const CGFloat outerRadius) {
16 NSRect insetFrame = NSInsetRect(frame, insetX, insetY);
18 if (outerRadius > 0.0) {
19 CGFloat leftRadius = outerRadius - insetX;
21 (roundedCornerFlags == RoundedCornerLeft) ? 0 : leftRadius;
23 return [NSBezierPath gtm_bezierPathWithRoundRect:insetFrame
24 topLeftCornerRadius:leftRadius
25 topRightCornerRadius:rightRadius
26 bottomLeftCornerRadius:leftRadius
27 bottomRightCornerRadius:rightRadius];
29 return [NSBezierPath bezierPathWithRect:insetFrame];
33 // Similar to |NSRectFill()|, additionally sets |color| as the fill
34 // color. |outerRadius| greater than 0.0 uses rounded corners, with
35 // inset backed out of the radius.
36 void FillRectWithInset(RoundedCornerFlags roundedCornerFlags,
40 const CGFloat outerRadius,
43 RectPathWithInset(roundedCornerFlags, frame, insetX, insetY, outerRadius);
48 // Similar to |NSFrameRectWithWidth()|, additionally sets |color| as
49 // the stroke color (as opposed to the fill color). |outerRadius|
50 // greater than 0.0 uses rounded corners, with inset backed out of the
52 void FrameRectWithInset(RoundedCornerFlags roundedCornerFlags,
56 const CGFloat outerRadius,
57 const CGFloat lineWidth,
59 const CGFloat finalInsetX = insetX + (lineWidth / 2.0);
60 const CGFloat finalInsetY = insetY + (lineWidth / 2.0);
62 RectPathWithInset(roundedCornerFlags, frame, finalInsetX, finalInsetY,
65 [path setLineWidth:lineWidth];
69 } // namespace rect_path_utils