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

Unified Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm

Issue 2874923002: Omnibox UI Experiments: Port vertical margin experiment to Cocoa. (Closed)
Patch Set: make constexpr Created 3 years, 7 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/omnibox/omnibox_popup_cell.mm
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm
index 9a43b648de56e43a734937f9848d3558ee9e61af..268f23ffee1a6ac87ff57dbdd4697d543e5c9b46 100644
--- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm
+++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm
@@ -13,6 +13,7 @@
#include "base/mac/foundation_util.h"
#include "base/mac/objc_property_releaser.h"
#include "base/mac/scoped_nsobject.h"
+#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
@@ -21,6 +22,7 @@
#include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
#import "chrome/browser/ui/cocoa/themed_window.h"
#include "chrome/grit/generated_resources.h"
+#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_popup_model.h"
#include "components/omnibox/browser/suggestion_answer.h"
#include "skia/ext/skia_utils_mac.h"
@@ -31,14 +33,21 @@
namespace {
-// How far to offset text.
-const CGFloat kVerticalTextPadding = 3.0;
+// Extra padding beyond the vertical text padding.
+constexpr CGFloat kMaterialExtraVerticalImagePadding = 2.0;
-const CGFloat kMaterialVerticalImagePadding = 5.0;
+constexpr CGFloat kMaterialTextStartOffset = 27.0;
-const CGFloat kMaterialTextStartOffset = 27.0;
+constexpr CGFloat kMaterialImageXOffset = 6.0;
-const CGFloat kMaterialImageXOffset = 6.0;
+// Returns the margin that should appear at the top and bottom of the result.
+CGFloat GetVerticalMargin() {
+ constexpr CGFloat kDefaultVerticalMargin = 3.0;
+
+ return base::GetFieldTrialParamByFeatureAsInt(
+ omnibox::kUIExperimentVerticalMargin,
+ OmniboxFieldTrial::kUIVerticalMarginParam, kDefaultVerticalMargin);
+}
// Flips the given |rect| in context of the given |frame|.
NSRect FlipIfRTL(NSRect rect, NSRect frame) {
@@ -480,7 +489,8 @@ NSAttributedString* CreateClassifiedAttributedString(
isDarkTheme ? [cellData incognitoImage] : [cellData image];
imageRect.size = [theImage size];
imageRect.origin.x += kMaterialImageXOffset + [tableView contentLeftPadding];
- imageRect.origin.y += kMaterialVerticalImagePadding;
+ imageRect.origin.y +=
+ GetVerticalMargin() + kMaterialExtraVerticalImagePadding;
[theImage drawInRect:FlipIfRTL(imageRect, cellFrame)
fromRect:NSZeroRect
operation:NSCompositeSourceOver
@@ -490,7 +500,7 @@ NSAttributedString* CreateClassifiedAttributedString(
NSPoint origin =
NSMakePoint(kMaterialTextStartOffset + [tableView contentLeftPadding],
- kVerticalTextPadding);
+ GetVerticalMargin());
if ([cellData matchType] == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) {
// Tail suggestions are rendered with a prefix (usually ellipsis), which
// appear vertically stacked.
@@ -507,9 +517,9 @@ NSAttributedString* CreateClassifiedAttributedString(
if (descriptionMaxWidth > 0) {
if ([cellData isAnswer]) {
- origin =
- NSMakePoint(kMaterialTextStartOffset + [tableView contentLeftPadding],
- kContentLineHeight - kVerticalTextPadding);
+ origin = NSMakePoint(
+ kMaterialTextStartOffset + [tableView contentLeftPadding],
+ [OmniboxPopupCell getContentTextHeight] - GetVerticalMargin());
CGFloat imageSize = [tableView answerLineHeight];
NSRect imageRect =
NSMakeRect(NSMinX(cellFrame) + origin.x, NSMinY(cellFrame) + origin.y,
@@ -521,7 +531,7 @@ NSAttributedString* CreateClassifiedAttributedString(
respectFlipped:YES
hints:nil];
if ([cellData answerImage]) {
- origin.x += imageSize + kMaterialVerticalImagePadding;
+ origin.x += imageSize + kMaterialImageXOffset;
// Have to nudge the baseline down 1pt in Material Design for the text
// that follows, so that it's the same as the bottom of the image.
@@ -685,4 +695,9 @@ NSAttributedString* CreateClassifiedAttributedString(
return NSWidth(cellFrame) - kMaterialTextStartOffset;
}
++ (CGFloat)getContentTextHeight {
+ constexpr CGFloat kDefaultTextHeight = 19;
+ return kDefaultTextHeight + 2 * GetVerticalMargin();
+}
+
@end
« no previous file with comments | « chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h ('k') | chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698