Skip to content

Commit 1e01ecc

Browse files
committed
Omnibox/Views: Remove LocationBarView stroke for touch mode.
This patch removes the 1px outline on LocationBarView and switches to using a views::FocusRing in touch mode. See screenshots - https://drive.google.com/file/d/1g4O_mh4oPb8PJIAb7pjDq0rK32KIUUvP/view?usp=sharing [email protected] (cherry picked from commit b167f41) Bug: 801583, 829574 Change-Id: I6498ff15d3b1be6a03cab92e9aae8971b54c358e Reviewed-on: https://chromium-review.googlesource.com/1002716 Commit-Queue: Patti <[email protected]> Reviewed-by: Michael Wasserman <[email protected]> Reviewed-by: Peter Kasting <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#550935} Reviewed-on: https://chromium-review.googlesource.com/1015456 Reviewed-by: Patti <[email protected]> Cr-Commit-Position: refs/branch-heads/3396@{#73} Cr-Branched-From: 9ef2aa8-refs/heads/master@{#550428}
1 parent d8acff3 commit 1e01ecc

16 files changed

+191
-100
lines changed

chrome/browser/ui/layout_constants.cc

+1-7
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,7 @@ int GetLayoutConstant(LayoutConstant constant) {
5858
case LOCATION_BAR_ICON_SIZE:
5959
return touch_optimized_material ? 20 : 16;
6060
case LOCATION_BAR_ICON_INTERIOR_PADDING:
61-
if (touch_optimized_material) {
62-
// TODO(crbug.com/801583): This should actually be 8, but until
63-
// LocationBarView is updated to remove its stroke, subtract the dips
64-
// reserved for the stroke first.
65-
return 7;
66-
}
67-
return 4;
61+
return touch_optimized_material ? 8 : 4;
6862
case TABSTRIP_NEW_TAB_BUTTON_SPACING: {
6963
// In non-touch optimized UI, we make the new tab button overlap with the
7064
// last tab in the tabstrip (i.e negative spacing). However, in

chrome/browser/ui/omnibox/omnibox_theme.cc

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ ui::NativeTheme::ColorId GetLegacyColorId(ui::NativeTheme* native_theme,
6565
: NativeId::kColorId_LinkEnabled;
6666
case OmniboxPart::LOCATION_BAR_TEXT_DEFAULT:
6767
return NativeId::kColorId_TextfieldDefaultColor;
68+
case OmniboxPart::LOCATION_BAR_FOCUS_RING:
69+
return NativeId::kColorId_FocusedBorderColor;
6870
case OmniboxPart::RESULTS_BACKGROUND:
6971
return NormalHoveredSelected(
7072
state, NativeId::kColorId_ResultsTableNormalBackground,
@@ -229,6 +231,8 @@ SkColor GetOmniboxColor(OmniboxPart part,
229231
return GetSecurityChipColor(tint, state);
230232
case OmniboxPart::LOCATION_BAR_SELECTED_KEYWORD:
231233
return dark ? gfx::kGoogleGrey100 : gfx::kGoogleBlue600;
234+
case OmniboxPart::LOCATION_BAR_FOCUS_RING:
235+
return dark ? gfx::kGoogleBlueDark600 : gfx::kGoogleBlue600;
232236
case OmniboxPart::RESULTS_BACKGROUND:
233237
// The spec calls for transparent black (or white) overlays for hover (6%)
234238
// and select (8%), which can overlap (for 14%). Pre-blend these with the

chrome/browser/ui/omnibox/omnibox_theme.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum class OmniboxPart {
1717
LOCATION_BAR_SELECTED_KEYWORD,
1818
LOCATION_BAR_TEXT_DEFAULT,
1919
LOCATION_BAR_TEXT_DIMMED,
20+
LOCATION_BAR_FOCUS_RING,
2021

2122
RESULTS_BACKGROUND, // Background of the results dropdown.
2223
RESULTS_ICON,

chrome/browser/ui/views/find_bar_host.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,8 @@ gfx::Rect FindBarHost::GetDialogPosition(gfx::Rect avoid_overlapping_rect) {
265265
if (widget_bounds.IsEmpty())
266266
return gfx::Rect();
267267

268-
gfx::Insets insets =
269-
view()->border()->GetInsets() -
270-
gfx::Insets(0, BackgroundWith1PxBorder::kLocationBarBorderThicknessDip);
268+
gfx::Insets insets = view()->border()->GetInsets() -
269+
gfx::Insets(0, LocationBarView::GetBorderThicknessDip());
271270

272271
// Ask the view how large an area it needs to draw on.
273272
gfx::Size prefsize = view()->GetPreferredSize();

chrome/browser/ui/views/harmony/chrome_layout_provider.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ bool ChromeLayoutProvider::IsHarmonyMode() const {
122122
int ChromeLayoutProvider::GetCornerRadiusMetric(
123123
ChromeEmphasisMetric emphasis_metric,
124124
const gfx::Rect& bounds) const {
125-
// Outside of MD (refresh) mode, just stick to the current fixed value.
126-
return emphasis_metric == EMPHASIS_HIGH ? 0 : 4;
125+
// Use the current fixed value for non-EMPHASIS_HIGH.
126+
return emphasis_metric == EMPHASIS_HIGH
127+
? std::min(bounds.width(), bounds.height()) / 2
128+
: 4;
127129
}
128130

129131
int ChromeLayoutProvider::GetShadowElevationMetric(

chrome/browser/ui/views/location_bar/background_with_1_px_border.cc

+8-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
66

77
#include "cc/paint/paint_flags.h"
8+
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
89
#include "third_party/skia/include/core/SkPath.h"
910
#include "third_party/skia/include/pathops/SkPathOps.h"
1011
#include "ui/base/material_design/material_design_controller.h"
@@ -19,11 +20,6 @@ BackgroundWith1PxBorder::BackgroundWith1PxBorder(SkColor background,
1920
SetNativeControlColor(background);
2021
}
2122

22-
// static
23-
bool BackgroundWith1PxBorder::IsRounded() {
24-
return ui::MaterialDesignController::IsNewerMaterialUi();
25-
}
26-
2723
void BackgroundWith1PxBorder::PaintFocusRing(gfx::Canvas* canvas,
2824
ui::NativeTheme* theme,
2925
const gfx::Rect& local_bounds) {
@@ -42,7 +38,7 @@ void BackgroundWith1PxBorder::Paint(gfx::Canvas* canvas,
4238
}
4339

4440
float BackgroundWith1PxBorder::GetBorderRadius(int height_in_px) const {
45-
if (IsRounded()) {
41+
if (LocationBarView::IsRounded()) {
4642
// This method returns the inner radius of the border, so subtract 1 pixel
4743
// off the final border radius since the border thickness is always 1px.
4844
return height_in_px / 2.f - 1;
@@ -60,13 +56,12 @@ void BackgroundWith1PxBorder::Paint(gfx::Canvas* canvas,
6056
gfx::RectF border_rect_f(bounds);
6157
border_rect_f.Scale(scale);
6258

63-
// Inset by |kLocationBarBorderThicknessDip|, then draw the border along the
64-
// outside edge of the result. Make sure the inset amount is a whole number so
65-
// the border will still be aligned to the pixel grid. std::floor is chosen
66-
// here to ensure the border will be fully contained within the
67-
// |kLocationBarBorderThicknessDip| region.
68-
border_rect_f.Inset(
69-
gfx::InsetsF(std::floor(kLocationBarBorderThicknessDip * scale)));
59+
// Inset by |kBorderThicknessDip|, then draw the border along the outside edge
60+
// of the result. Make sure the inset amount is a whole number so the border
61+
// will still be aligned to the pixel grid. std::floor is chosen here to
62+
// ensure the border will be fully contained within the |kBorderThicknessDip|
63+
// region.
64+
border_rect_f.Inset(gfx::InsetsF(std::floor(kBorderThicknessDip * scale)));
7065

7166
SkRRect inner_rect(SkRRect::MakeRectXY(gfx::RectFToSkRect(border_rect_f),
7267
inner_border_radius,

chrome/browser/ui/views/location_bar/background_with_1_px_border.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,17 @@ class View;
2121
// BackgroundWith1PxBorder renders a solid background color, with a one pixel
2222
// border with rounded corners. This accounts for the scaling of the canvas, so
2323
// that the border is one pixel regardless of display scaling.
24+
// TODO(patricialor): Delete this & replace with CreateRoundRectWith1PxPainter.
2425
class BackgroundWith1PxBorder : public views::Background {
2526
public:
26-
// The thickness of the location bar's border in DIP.
27-
static constexpr int kLocationBarBorderThicknessDip = 1;
27+
// The thickness of the border in DIP.
28+
static constexpr int kBorderThicknessDip = 1;
2829

2930
// The legacy (non touch/material) border radius.
3031
static constexpr int kLegacyBorderRadiusPx = 2;
3132

3233
BackgroundWith1PxBorder(SkColor background, SkColor border);
3334

34-
// Whether the OmniboxBackgroundBorder is a pill shape.
35-
static bool IsRounded();
36-
3735
void set_blend_mode(SkBlendMode blend_mode) { blend_mode_ = blend_mode; }
3836

3937
// Paints a blue focus ring that draws over the top of the existing border.

chrome/browser/ui/views/location_bar/bubble_icon_view.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ SkColor BubbleIconView::GetInkDropBaseColor() const {
205205
}
206206

207207
std::unique_ptr<views::InkDropMask> BubbleIconView::CreateInkDropMask() const {
208-
if (!BackgroundWith1PxBorder::IsRounded())
208+
if (!LocationBarView::IsRounded())
209209
return nullptr;
210210
return std::make_unique<views::RoundRectInkDropMask>(size(), gfx::Insets(),
211211
height() / 2.f);

chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ SkColor IconLabelBubbleView::GetInkDropBaseColor() const {
307307

308308
std::unique_ptr<views::InkDropMask> IconLabelBubbleView::CreateInkDropMask()
309309
const {
310-
if (!BackgroundWith1PxBorder::IsRounded())
310+
if (!LocationBarView::IsRounded())
311311
return nullptr;
312312
return std::make_unique<views::RoundRectInkDropMask>(
313313
ink_drop_container_->size(), gfx::Insets(),

chrome/browser/ui/views/location_bar/keyword_hint_view.cc

+12-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ KeywordHintView::KeywordHintView(views::ButtonListener* listener,
4343
constexpr int kPaddingInsideBorder = 5;
4444
// Even though the border is 1 px thick visibly, it takes 1 DIP logically for
4545
// the non-rounded style.
46-
const int horizontal_padding = BackgroundWith1PxBorder::IsRounded()
46+
const int horizontal_padding = LocationBarView::IsRounded()
4747
? GetCornerRadius()
4848
: kPaddingInsideBorder + 1;
4949
chip_label_->SetBorder(
@@ -132,7 +132,7 @@ void KeywordHintView::SetKeyword(const base::string16& keyword) {
132132
}
133133

134134
gfx::Insets KeywordHintView::GetInsets() const {
135-
if (!BackgroundWith1PxBorder::IsRounded())
135+
if (!LocationBarView::IsRounded())
136136
return gfx::Insets(0,
137137
GetLayoutConstant(LOCATION_BAR_ICON_INTERIOR_PADDING));
138138

@@ -175,7 +175,7 @@ void KeywordHintView::Layout() {
175175
gfx::Size leading_size(leading_label_->GetPreferredSize());
176176
leading_label_->SetBounds(GetInsets().left(), 0,
177177
show_labels ? leading_size.width() : 0, height());
178-
const int chip_height = BackgroundWith1PxBorder::IsRounded()
178+
const int chip_height = LocationBarView::IsRounded()
179179
? GetLayoutConstant(LOCATION_BAR_ICON_SIZE) +
180180
chip_container_->GetInsets().height()
181181
: height();
@@ -197,18 +197,19 @@ gfx::Size KeywordHintView::CalculatePreferredSize() const {
197197
}
198198

199199
void KeywordHintView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
200-
if (!BackgroundWith1PxBorder::IsRounded())
201-
return;
202-
const int chip_corner_radius = GetCornerRadius();
203-
chip_label_->SetBorder(views::CreateEmptyBorder(
204-
gfx::Insets(GetInsets().top(), chip_corner_radius, GetInsets().bottom(),
205-
chip_corner_radius)));
200+
if (LocationBarView::IsRounded()) {
201+
const int chip_corner_radius = GetCornerRadius();
202+
chip_label_->SetBorder(views::CreateEmptyBorder(
203+
gfx::Insets(GetInsets().top(), chip_corner_radius, GetInsets().bottom(),
204+
chip_corner_radius)));
205+
}
206+
views::Button::OnBoundsChanged(previous_bounds);
206207
}
207208

208209
views::Label* KeywordHintView::CreateLabel(SkColor text_color,
209210
SkColor background_color) {
210211
views::Label* label =
211-
new views::Label(base::string16(), BackgroundWith1PxBorder::IsRounded()
212+
new views::Label(base::string16(), LocationBarView::IsRounded()
212213
? CONTEXT_OMNIBOX_DECORATION
213214
: CONTEXT_OMNIBOX_PRIMARY);
214215
label->SetEnabledColor(text_color);
@@ -218,7 +219,7 @@ views::Label* KeywordHintView::CreateLabel(SkColor text_color,
218219
}
219220

220221
int KeywordHintView::GetCornerRadius() const {
221-
if (!BackgroundWith1PxBorder::IsRounded())
222+
if (!LocationBarView::IsRounded())
222223
return GetLayoutConstant(LOCATION_BAR_BUBBLE_CORNER_RADIUS);
223224
return chip_container_->height() / 2;
224225
}

0 commit comments

Comments
 (0)