Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm

Issue 10834279: Give request-to-act badges a grey background, and increase spacing to make it fit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Avoid changing Mac edit field width when script badges disabled Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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];
}
}

Powered by Google App Engine
This is Rietveld 408576698