diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-02 16:05:42 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-02 16:05:42 +0000 |
commit | 8a7cc2034c02b3754ebd79349eef9c06e85b9529 (patch) | |
tree | 544f67311938c7caa3c81e52ecb0d6ccc24e1217 | |
parent | 5607d135bef3bb69bf94b16e8b443fa2e759a575 (diff) | |
download | chromium_src-8a7cc2034c02b3754ebd79349eef9c06e85b9529.zip chromium_src-8a7cc2034c02b3754ebd79349eef9c06e85b9529.tar.gz chromium_src-8a7cc2034c02b3754ebd79349eef9c06e85b9529.tar.bz2 |
[Mac] Round the left side of the find bar.
BUG=49798
TEST=Findbar should be rounded left.
Review URL: http://codereview.chromium.org/3212007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58361 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/cocoa/find_bar_text_field_cell.mm | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/styled_text_field_cell.h | 8 | ||||
-rw-r--r-- | chrome/browser/cocoa/styled_text_field_cell.mm | 49 |
3 files changed, 50 insertions, 15 deletions
diff --git a/chrome/browser/cocoa/find_bar_text_field_cell.mm b/chrome/browser/cocoa/find_bar_text_field_cell.mm index 9c41ad5..62f2564 100644 --- a/chrome/browser/cocoa/find_bar_text_field_cell.mm +++ b/chrome/browser/cocoa/find_bar_text_field_cell.mm @@ -44,6 +44,14 @@ CGFloat WidthForResults(NSAttributedString* resultsString) { return kBaselineAdjust; } +- (CGFloat)cornerRadius { + return 4.0; +} + +- (StyledTextFieldCellRoundedFlags)roundedFlags { + return StyledTextFieldCellRoundedLeft; +} + // @synthesize doesn't seem to compile for this transition. - (NSAttributedString*)resultsString { return resultsString_.get(); diff --git a/chrome/browser/cocoa/styled_text_field_cell.h b/chrome/browser/cocoa/styled_text_field_cell.h index a3337f0..5e8e286 100644 --- a/chrome/browser/cocoa/styled_text_field_cell.h +++ b/chrome/browser/cocoa/styled_text_field_cell.h @@ -8,6 +8,11 @@ #import <Cocoa/Cocoa.h> +typedef enum { + StyledTextFieldCellRoundedAll = 0, + StyledTextFieldCellRoundedLeft = 1 +} StyledTextFieldCellRoundedFlags; + // StyledTextFieldCell customizes the look of the standard Cocoa text field. // The border and focus ring are modified, as is the font baseline. Subclasses // can override |drawInteriorWithFrame:inView:| to provide custom drawing for @@ -41,6 +46,9 @@ // Radius of the corners of the field. Defaults to square corners (0.0). - (CGFloat)cornerRadius; +// Which corners of the field to round. Defaults to RoundedAll. +- (StyledTextFieldCellRoundedFlags)roundedFlags; + // Returns YES if a light themed bezel should be drawn under the text field. // Default implementation returns NO. - (BOOL)shouldDrawBezel; diff --git a/chrome/browser/cocoa/styled_text_field_cell.mm b/chrome/browser/cocoa/styled_text_field_cell.mm index 43a2a39..96a6c9f 100644 --- a/chrome/browser/cocoa/styled_text_field_cell.mm +++ b/chrome/browser/cocoa/styled_text_field_cell.mm @@ -10,17 +10,26 @@ #include "chrome/browser/themes/browser_theme_provider.h" #include "gfx/font.h" #include "grit/theme_resources.h" +#import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" namespace { -NSBezierPath* RectPathWithInset(const NSRect frame, +NSBezierPath* RectPathWithInset(StyledTextFieldCellRoundedFlags roundedFlags, + const NSRect frame, const CGFloat inset, const CGFloat outerRadius) { - const NSRect insetFrame = NSInsetRect(frame, inset, inset); + NSRect insetFrame = NSInsetRect(frame, inset, inset); + if (outerRadius > 0.0) { - return [NSBezierPath bezierPathWithRoundedRect:insetFrame - xRadius:outerRadius - inset - yRadius:outerRadius - inset]; + CGFloat leftRadius = outerRadius - inset; + CGFloat rightRadius = + (roundedFlags == StyledTextFieldCellRoundedLeft) ? 0 : leftRadius; + + return [NSBezierPath gtm_bezierPathWithRoundRect:insetFrame + topLeftCornerRadius:leftRadius + topRightCornerRadius:rightRadius + bottomLeftCornerRadius:leftRadius + bottomRightCornerRadius:rightRadius]; } else { return [NSBezierPath bezierPathWithRect:insetFrame]; } @@ -29,11 +38,13 @@ NSBezierPath* RectPathWithInset(const NSRect frame, // Similar to |NSRectFill()|, additionally sets |color| as the fill // color. |outerRadius| greater than 0.0 uses rounded corners, with // inset backed out of the radius. -void FillRectWithInset(const NSRect frame, +void FillRectWithInset(StyledTextFieldCellRoundedFlags roundedFlags, + const NSRect frame, const CGFloat inset, const CGFloat outerRadius, NSColor* color) { - NSBezierPath* path = RectPathWithInset(frame, inset, outerRadius); + NSBezierPath* path = + RectPathWithInset(roundedFlags, frame, inset, outerRadius); [color setFill]; [path fill]; } @@ -42,13 +53,15 @@ void FillRectWithInset(const NSRect frame, // 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, +void FrameRectWithInset(StyledTextFieldCellRoundedFlags roundedFlags, + 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, outerRadius); + NSBezierPath* path = + RectPathWithInset(roundedFlags, frame, finalInset, outerRadius); [color setStroke]; [path setLineWidth:lineWidth]; [path stroke]; @@ -85,6 +98,10 @@ private: return 0.0; } +- (StyledTextFieldCellRoundedFlags)roundedFlags { + return StyledTextFieldCellRoundedAll; +} + - (BOOL)shouldDrawBezel { return NO; } @@ -121,6 +138,7 @@ private: // incorrect. I know that this affects -drawingRectForBounds:. - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { DCHECK([controlView isFlipped]); + StyledTextFieldCellRoundedFlags roundedFlags = [self roundedFlags]; // TODO(shess): This inset is also reflected by |kFieldVisualInset| // in autocomplete_popup_view_mac.mm. @@ -143,7 +161,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, radius, backgroundImageColor); + FillRectWithInset(roundedFlags, frame, 0.5, radius, backgroundImageColor); } // Draw the outer stroke (over the background). @@ -152,11 +170,11 @@ private: active ? BrowserThemeProvider::COLOR_TOOLBAR_BUTTON_STROKE : BrowserThemeProvider::COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE, true); - FrameRectWithInset(frame, 0.0, radius, 1.0, strokeColor); + FrameRectWithInset(roundedFlags, frame, 0.0, radius, 1.0, strokeColor); } // Fill interior with background color. - FillRectWithInset(frame, 1.0, radius, [self backgroundColor]); + FillRectWithInset(roundedFlags, 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 @@ -165,10 +183,11 @@ private: // will clip the bottom and right edges (and corner). { ScopedSaveGraphicsState state; - [RectPathWithInset(frame, 1.0, radius) addClip]; + [RectPathWithInset(roundedFlags, 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, radius - 0.5, 1.0, shadowShade); + FrameRectWithInset(roundedFlags, shadowFrame, 0.5, radius - 0.5, + 1.0, shadowShade); } // Draw optional bezel below bottom stroke. @@ -189,7 +208,7 @@ private: if ([self showsFirstResponder]) { NSColor* color = [[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5]; - FrameRectWithInset(frame, 0.0, radius, 2.0, color); + FrameRectWithInset(roundedFlags, frame, 0.0, radius, 2.0, color); } [self drawInteriorWithFrame:cellFrame inView:controlView]; |