summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.mm27
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_cell.mm7
-rw-r--r--chrome/browser/cocoa/styled_text_field_cell.h3
-rw-r--r--chrome/browser/cocoa/styled_text_field_cell.mm41
4 files changed, 55 insertions, 23 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
index a8d494a..d41685b 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
@@ -15,7 +15,6 @@
#include "gfx/rect.h"
#include "grit/theme_resources.h"
#import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h"
-#import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h"
namespace {
@@ -31,6 +30,9 @@ const int kCellHeightAdjust = 7.0;
// buttons.
const CGFloat kPopupRoundingRadius = 3.5;
+// Gap between the field and the popup.
+const CGFloat kPopupFieldGap = 2.0;
+
// How opaque the popup window should be. This matches Windows (see
// autocomplete_popup_contents_view.cc, kGlassPopupTransparency).
const CGFloat kPopupAlpha = 240.0 / 255.0;
@@ -64,6 +66,11 @@ const CGFloat kFieldVisualInset = 1.0;
// borders.
const CGFloat kWindowBorderWidth = 1.0;
+// |AutocompleteButtonCell| and |AutocompleteTextFieldCell| draw their
+// text somewhat differently. The image needs to be adjusted slightly
+// downward to align with the text the same.
+const CGFloat kImageBaselineAdjust = 1.0;
+
// Background colors for different states of the popup elements.
NSColor* BackgroundColor() {
return [[NSColor controlBackgroundColor] colorWithAlphaComponent:kPopupAlpha];
@@ -318,9 +325,12 @@ void AutocompletePopupViewMac::PositionPopup(const CGFloat matrixHeight) {
popupFrame.size.height = matrixHeight * [popup_ userSpaceScaleFactor];
popupFrame.origin.y -= NSHeight(popupFrame) + kWindowBorderWidth;
- // Inset to account for the horizontal border.
+ // Inset to account for the horizontal border drawn by the window.
popupFrame = NSInsetRect(popupFrame, kWindowBorderWidth, 0.0);
+ // Leave a gap between the popup and the field.
+ popupFrame.origin.y -= kPopupFieldGap * [popup_ userSpaceScaleFactor];
+
// Do nothing if the popup is already animating to the given |frame|.
if (NSEqualRects(popupFrame, targetPopupFrame_))
return;
@@ -482,7 +492,7 @@ void AutocompletePopupViewMac::OpenURLForRow(int row, bool force_background) {
if (image) {
NSRect imageRect = cellFrame;
imageRect.size = [image size];
- imageRect.origin.y +=
+ imageRect.origin.y += kImageBaselineAdjust +
floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2);
imageRect.origin.x += kLeftRightMargin;
[image drawInRect:imageRect
@@ -688,15 +698,10 @@ void AutocompletePopupViewMac::OpenURLForRow(int row, bool force_background) {
// This handles drawing the decorations of the rounded popup window,
// calling on NSMatrix to draw the actual contents.
- (void)drawRect:(NSRect)rect {
- // Apparently this expects flipped coordinates, because in order to
- // round the bottom corners visually, I need to specify the top
- // corners here.
NSBezierPath* path =
- [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds]
- topLeftCornerRadius:kPopupRoundingRadius
- topRightCornerRadius:kPopupRoundingRadius
- bottomLeftCornerRadius:0.0
- bottomRightCornerRadius:0.0];
+ [NSBezierPath bezierPathWithRoundedRect:[self bounds]
+ xRadius:kPopupRoundingRadius
+ yRadius:kPopupRoundingRadius];
// Draw the matrix clipped to our border.
[NSGraphicsContext saveGraphicsState];
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
index 7558c70..890e188 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm
@@ -27,6 +27,9 @@ namespace {
const CGFloat kBaselineAdjust = 2.0;
+// Matches the clipping radius of |GradientButtonCell|.
+const CGFloat kCornerRadius = 4.0;
+
// How far to offset the keyword token into the field.
const NSInteger kKeywordXOffset = 3;
@@ -196,6 +199,10 @@ NSAttributedString* AttributedStringForImage(NSImage* anImage,
return kBaselineAdjust;
}
+- (CGFloat)cornerRadius {
+ return kCornerRadius;
+}
+
- (void)setKeywordString:(NSString*)fullString
partialString:(NSString*)partialString
availableWidth:(CGFloat)width {
diff --git a/chrome/browser/cocoa/styled_text_field_cell.h b/chrome/browser/cocoa/styled_text_field_cell.h
index 476f765..7eb12a8 100644
--- a/chrome/browser/cocoa/styled_text_field_cell.h
+++ b/chrome/browser/cocoa/styled_text_field_cell.h
@@ -17,6 +17,9 @@
// override as needed.
- (CGFloat)baselineAdjust;
+// Radius of the corners of the field. Defaults to square corners (0.0).
+- (CGFloat)cornerRadius;
+
// Return the portion of the cell to show the text cursor over. The default
// implementation returns the full |cellFrame|. Subclasses should override this
// method if they add any decorations.
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];