Chromium Code Reviews| Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm |
| diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm |
| index 28e72bc717112c85a01ded3fc1d9c84ace8727e9..ecd256c2bae8dd85e3fb2d17a4f1cb06f2db6368 100644 |
| --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm |
| +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm |
| @@ -9,6 +9,7 @@ |
| #import "chrome/browser/ui/cocoa/image_utils.h" |
| #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| +#import "chrome/common/extensions/extension_switch_utils.h" |
| #import "third_party/mozilla/NSPasteboard+Utils.h" |
| namespace { |
| @@ -25,10 +26,17 @@ const CGFloat kLeftDecorationXOffset = 5.0; |
| // TODO(shess): Why is this different from |kLeftDecorationXOffset|? |
| // |kDecorationOuterXOffset|? |
| const CGFloat kRightDecorationXOffset = 5.0; |
| +const CGFloat kScriptBadgeRightDecorationXOffset = 9.0; |
| + |
| +inline CGFloat RightDecorationXOffset() { |
|
Scott Hess - ex-Googler
2012/09/12 22:54:08
Shouldn't need inline. It's static to this file,
Jeffrey Yasskin
2012/09/14 22:13:45
Done.
|
| + return extensions::switch_utils::AreScriptBadgesEnabled() ? |
| + kScriptBadgeRightDecorationXOffset : kRightDecorationXOffset; |
| +} |
| // The amount of padding on either side reserved for drawing |
| // decorations. [Views has |kItemPadding| == 3.] |
| const CGFloat kDecorationHorizontalPad = 3.0; |
| +const CGFloat kScriptBadgeDecorationHorizontalPad = 9.0; |
| // How long to wait for mouse-up on the location icon before assuming |
| // that the user wants to drag. |
| @@ -42,7 +50,7 @@ const NSTimeInterval kLocationIconDragTimeout = 0.25; |
| // while |decoration_frames| will be the corresponding frames. |
| // |x_edge| describes the edge to layout the decorations against |
| // (|NSMinXEdge| or |NSMaxXEdge|). |initial_padding| is the padding |
| -// from the edge of |cell_frame| (|kDecorationHorizontalPad| is used |
| +// from the edge of |cell_frame| (|+decorationHorizontalPad| is used |
| // between decorations). |
| void CalculatePositionsHelper( |
| NSRect frame, |
| @@ -85,7 +93,7 @@ void CalculatePositionsHelper( |
| DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| // Adjust padding for between decorations. |
| - padding = kDecorationHorizontalPad; |
| + padding = [AutocompleteTextFieldCell decorationHorizontalPad]; |
| } |
| } |
| } |
| @@ -125,7 +133,7 @@ size_t CalculatePositionsInFrame( |
| // Layout |right_decorations| against the RHS. |
| CalculatePositionsHelper(frame, right_decorations, |
| - NSMaxXEdge, kRightDecorationXOffset, |
| + NSMaxXEdge, RightDecorationXOffset(), |
| decorations, decoration_frames, &frame); |
| DCHECK_EQ(decorations->size(), decoration_frames->size()); |
| @@ -136,6 +144,15 @@ size_t CalculatePositionsInFrame( |
| decoration_frames->end()); |
| *remaining_frame = frame; |
| + if (extensions::switch_utils::AreScriptBadgesEnabled()) { |
| + // Keep the padding distance between the right-most decoration and the edit |
| + // box, so that any decoration background isn't overwritten by the edit |
| + // box's background. |
| + NSRect dummy; |
| + NSDivideRect(frame, &dummy, remaining_frame, |
| + [AutocompleteTextFieldCell decorationHorizontalPad], |
| + NSMaxXEdge); |
| + } |
| return left_count; |
| } |
| @@ -143,6 +160,11 @@ size_t CalculatePositionsInFrame( |
| @implementation AutocompleteTextFieldCell |
| ++ (CGFloat)decorationHorizontalPad { |
| + return extensions::switch_utils::AreScriptBadgesEnabled() ? |
| + kScriptBadgeDecorationHorizontalPad : kDecorationHorizontalPad; |
| +} |
| + |
| - (CGFloat)baselineAdjust { |
| return kBaselineAdjust; |
| } |
| @@ -239,7 +261,8 @@ size_t CalculatePositionsInFrame( |
| if (!index) { |
| minX = NSMinX(cellFrame); |
| } else { |
| - minX = NSMinX(decorationFrames[index]) - kDecorationHorizontalPad; |
| + minX = NSMinX(decorationFrames[index]) - |
| + [AutocompleteTextFieldCell decorationHorizontalPad]; |
| } |
| } |
| @@ -253,7 +276,8 @@ size_t CalculatePositionsInFrame( |
| if (index == decorations.size() - 1) { |
| maxX = NSMaxX(cellFrame); |
| } else { |
| - maxX = NSMaxX(decorationFrames[index]) + kDecorationHorizontalPad; |
| + maxX = NSMaxX(decorationFrames[index]) + |
| + [AutocompleteTextFieldCell decorationHorizontalPad]; |
| } |
| } |