Chromium Code Reviews| Index: chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm |
| diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm |
| index a2ad4effcfd93fcd85b962bd3b500f5609c0c9b9..7e71011556d5265c088f219fc28df03b15840754 100644 |
| --- a/chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm |
| +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm |
| @@ -6,8 +6,10 @@ |
| #include "base/logging.h" |
| #include "base/mac/scoped_nsobject.h" |
| +#include "chrome/browser/ui/cocoa/l10n_util.h" |
| #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| #include "skia/ext/skia_utils_mac.h" |
| +#import "ui/base/cocoa/nsview_additions.h" |
| #import "ui/base/cocoa/tracking_area.h" |
| #include "ui/gfx/color_palette.h" |
| #include "ui/gfx/font.h" |
| @@ -16,7 +18,9 @@ |
| namespace { |
| -// Gray values for the bubble decoration divider. |
| +// Layout and color values for the vertical divider. |
| +const CGFloat kDividerHeight = 16.0; |
| +const CGFloat kDividerPadding = 6.0; // Between the divider and label. |
| const CGFloat kDividerGray = 0xFFA6A6A6; |
| const CGFloat kDividerGrayIncognito = 0xFFDFDFDF; |
| @@ -159,6 +163,10 @@ LocationBarDecoration::~LocationBarDecoration() { |
| [accessibility_view_.get() removeFromSuperview]; |
| } |
| +CGFloat LocationBarDecoration::DividerPadding() const { |
| + return kDividerPadding; |
| +} |
| + |
| bool LocationBarDecoration::IsVisible() const { |
| return visible_; |
| } |
| @@ -406,12 +414,55 @@ SkColor LocationBarDecoration::GetMaterialIconColor( |
| return location_bar_is_dark ? SK_ColorWHITE : gfx::kChromeIconGrey; |
| } |
| -NSColor* LocationBarDecoration::GetDividerColor( |
| - bool location_bar_is_dark) const { |
| +void LocationBarDecoration::DrawDivider(NSView* control_view, |
| + NSRect decoration_frame, |
| + CGFloat alpha) const { |
| + if (alpha == 0.0) { |
| + return; |
| + } |
| + |
| + NSBezierPath* line = [NSBezierPath bezierPath]; |
| + |
| + CGFloat line_width = [control_view cr_lineWidth]; |
| + [line setLineWidth:line_width]; |
| + |
| + const BOOL is_rtl = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); |
| + NSPoint divider_origin = NSZeroPoint; |
| + divider_origin.x = is_rtl ? NSMinX(decoration_frame) + DividerPadding() |
| + : NSMaxX(decoration_frame) - DividerPadding(); |
| + // Screen pixels lay between integral coordinates in user space. If you |
| + // draw a line from (16, 16) to (16, 32), Core Graphics maps that line to |
| + // the pixels that lay along x=16.5. In order to achieve a line that |
| + // appears to lay along x=16, CG will perform dithering. To get a crisp |
| + // line, you have to specify x=16.5, so translating by 1/2 the 1-pixel |
| + // line width creates the crisp line we want. We subtract to better center |
| + // the line between the label and URL. |
| + divider_origin.x -= line_width / 2.; |
| + CGFloat divider_y_frame_offset = |
| + (NSHeight(decoration_frame) - kDividerHeight) / 2.0; |
| + divider_origin.y = NSMinY(decoration_frame) + divider_y_frame_offset; |
| + // Adjust the divider origin by 1/2 a point to visually center the |
| + // divider vertically on Retina. |
| + if (line_width < 1) { |
|
spqchan
2017/05/05 23:00:15
[optional nit]: No curly braces
shrike
2017/05/05 23:07:08
Yeah, for simple if statements I opt for curly bra
|
| + divider_origin.y -= 0.5; |
| + } |
| + [line moveToPoint:divider_origin]; |
| + [line relativeLineToPoint:NSMakePoint(0, kDividerHeight)]; |
| + |
| + NSColor* divider_color = nil; |
| + bool location_bar_is_dark = |
| + [[control_view window] inIncognitoModeWithSystemTheme]; |
| if (location_bar_is_dark) { |
|
spqchan
2017/05/05 23:00:15
[optional nit]: No curly braces
|
| - return skia::SkColorToSRGBNSColor(kDividerGrayIncognito); |
| + divider_color = skia::SkColorToSRGBNSColor(kDividerGrayIncognito); |
| + } else { |
| + divider_color = skia::SkColorToSRGBNSColor(kDividerGray); |
| + } |
| + |
| + if (alpha < 1) { |
| + divider_color = [divider_color colorWithAlphaComponent:alpha]; |
|
spqchan
2017/05/05 23:00:15
[optional nit]: No curly braces
|
| } |
| - return skia::SkColorToSRGBNSColor(kDividerGray); |
| + [divider_color set]; |
| + [line stroke]; |
| } |
| const gfx::VectorIcon* LocationBarDecoration::GetMaterialVectorIcon() const { |