summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/styled_text_field_cell.mm
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-17 23:46:48 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-17 23:46:48 +0000
commit050ca6425e4997dfe1baffb1c2f5dc59821e2b83 (patch)
tree2f754ed0cb43b73accf160176d6a6c57606aecc7 /chrome/browser/cocoa/styled_text_field_cell.mm
parent58611c0e9426c0fa30465102ef5436fca7ed439d (diff)
downloadchromium_src-050ca6425e4997dfe1baffb1c2f5dc59821e2b83.zip
chromium_src-050ca6425e4997dfe1baffb1c2f5dc59821e2b83.tar.gz
chromium_src-050ca6425e4997dfe1baffb1c2f5dc59821e2b83.tar.bz2
[Mac] Round off omnibox and popup.
Round off the omnibox corners like adjacent toolbar buttons. Round off the popup corners reflection-like. Put back the slight gap between them. BUG=45762 TEST=Above stuff. Findbar field should not be rounded. Review URL: http://codereview.chromium.org/2863007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50169 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/styled_text_field_cell.mm')
-rw-r--r--chrome/browser/cocoa/styled_text_field_cell.mm41
1 files changed, 29 insertions, 12 deletions
diff --git a/chrome/browser/cocoa/styled_text_field_cell.mm b/chrome/browser/cocoa/styled_text_field_cell.mm
index d9416e9..64fc0e4 100644
--- a/chrome/browser/cocoa/styled_text_field_cell.mm
+++ b/chrome/browser/cocoa/styled_text_field_cell.mm
@@ -14,29 +14,41 @@
namespace {
NSBezierPath* RectPathWithInset(const NSRect frame,
- const CGFloat inset) {
+ const CGFloat inset,
+ const CGFloat outerRadius) {
const NSRect insetFrame = NSInsetRect(frame, inset, inset);
- return [NSBezierPath bezierPathWithRect:insetFrame];
+ if (outerRadius > 0.0) {
+ return [NSBezierPath bezierPathWithRoundedRect:insetFrame
+ xRadius:outerRadius - inset
+ yRadius:outerRadius - inset];
+ } else {
+ return [NSBezierPath bezierPathWithRect:insetFrame];
+ }
}
// Similar to |NSRectFill()|, additionally sets |color| as the fill
-// color.
+// color. |outerRadius| greater than 0.0 uses rounded corners, with
+// inset backed out of the radius.
void FillRectWithInset(const NSRect frame,
const CGFloat inset,
+ const CGFloat outerRadius,
NSColor* color) {
- NSBezierPath* path = RectPathWithInset(frame, inset);
+ NSBezierPath* path = RectPathWithInset(frame, inset, outerRadius);
[color setFill];
[path fill];
}
// Similar to |NSFrameRectWithWidth()|, additionally sets |color| as
-// the stroke color (as opposed to the fill color).
+// the stroke color (as opposed to the fill color). |outerRadius|
+// greater than 0.0 uses rounded corners, with inset backed out of the
+// radius.
void FrameRectWithInset(const NSRect frame,
const CGFloat inset,
+ const CGFloat outerRadius,
const CGFloat lineWidth,
NSColor* color) {
const CGFloat finalInset = inset + (lineWidth / 2.0);
- NSBezierPath* path = RectPathWithInset(frame, finalInset);
+ NSBezierPath* path = RectPathWithInset(frame, finalInset, outerRadius);
[color setStroke];
[path setLineWidth:lineWidth];
[path stroke];
@@ -69,6 +81,10 @@ private:
return 0.0;
}
+- (CGFloat)cornerRadius {
+ return 0.0;
+}
+
// Returns the same value as textCursorFrameForFrame, but does not call it
// directly to avoid potential infinite loops.
- (NSRect)textFrameForFrame:(NSRect)cellFrame {
@@ -105,6 +121,7 @@ private:
// TODO(shess): This inset is also reflected by |kFieldVisualInset|
// in autocomplete_popup_view_mac.mm.
const NSRect frame = NSInsetRect(cellFrame, 0, 1);
+ const CGFloat radius = [self cornerRadius];
// Paint button background image if there is one (otherwise the border won't
// look right).
@@ -121,7 +138,7 @@ private:
// NOTE(shess): This seems like it should be using a 0.0 inset,
// but AFAICT using a 0.5 inset is important in mixing the
// toolbar background and the omnibox background.
- FillRectWithInset(frame, 0.5, backgroundImageColor);
+ FillRectWithInset(frame, 0.5, radius, backgroundImageColor);
}
// Draw the outer stroke (over the background).
@@ -130,11 +147,11 @@ private:
active ? BrowserThemeProvider::COLOR_TOOLBAR_BUTTON_STROKE :
BrowserThemeProvider::COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE,
true);
- FrameRectWithInset(frame, 0.0, 1.0, strokeColor);
+ FrameRectWithInset(frame, 0.0, radius, 1.0, strokeColor);
}
// Fill interior with background color.
- FillRectWithInset(frame, 1.0, [self backgroundColor]);
+ FillRectWithInset(frame, 1.0, radius, [self backgroundColor]);
// Draw the shadow. For the rounded-rect case, the shadow needs to
// slightly turn in at the corners. |shadowFrame| is at the same
@@ -143,17 +160,17 @@ private:
// will clip the bottom and right edges (and corner).
{
ScopedSaveGraphicsState state;
- [RectPathWithInset(frame, 1.0) addClip];
+ [RectPathWithInset(frame, 1.0, radius) addClip];
const NSRect shadowFrame = NSOffsetRect(frame, 0.5, 0.5);
NSColor* shadowShade = [NSColor colorWithCalibratedWhite:0.0 alpha:0.05];
- FrameRectWithInset(shadowFrame, 0.5, 1.0, shadowShade);
+ FrameRectWithInset(shadowFrame, 0.5, radius - 0.5, 1.0, shadowShade);
}
// Draw the focus ring if needed.
if ([self showsFirstResponder]) {
NSColor* color =
[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5];
- FrameRectWithInset(frame, 0.0, 2.0, color);
+ FrameRectWithInset(frame, 0.0, radius, 2.0, color);
}
[self drawInteriorWithFrame:cellFrame inView:controlView];