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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 1394763003: Update LocationBarView Background (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't round popup Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 96
97 #if !defined(OS_CHROMEOS) 97 #if !defined(OS_CHROMEOS)
98 #include "chrome/browser/ui/views/first_run_bubble.h" 98 #include "chrome/browser/ui/views/first_run_bubble.h"
99 #endif 99 #endif
100 100
101 using content::WebContents; 101 using content::WebContents;
102 using views::View; 102 using views::View;
103 103
104 namespace { 104 namespace {
105 105
106 // This draws a rect in the native coordinates of the display. Where |bounds| is
107 // in the coordinate space of LocationBarView, this shall scale accrodingly. If
108 // |round| this will render a rect with rounded corners.
109 void DrawScaledRect(gfx::Canvas* canvas,
110 SkPaint::Style style,
111 SkColor color,
112 gfx::Rect bounds,
113 bool round) {
114 const float display_scale = canvas->image_scale();
115 canvas->Save();
116 SkScalar scale_factor = 1.0f / display_scale;
117 canvas->sk_canvas()->scale(scale_factor, scale_factor);
118
119 SkPaint paint;
120 paint.setStyle(style);
121 paint.setColor(color);
122 paint.setAntiAlias(true);
123
124 const float kOffset = 0.5f;
125 gfx::RectF border_rect_f(bounds);
126 border_rect_f.Scale(display_scale);
127 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset);
128 border_rect_f.Inset(insets);
129
130 if (round) {
131 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale);
132 canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f),
133 kCornerRadius, kCornerRadius, paint);
134 } else {
135 canvas->sk_canvas()->drawRect(gfx::RectFToSkRect(border_rect_f), paint);
136 }
137 canvas->Restore();
138 }
139
106 int GetEditLeadingInternalSpace() { 140 int GetEditLeadingInternalSpace() {
107 // The textfield has 1 px of whitespace before the text in the RTL case only. 141 // The textfield has 1 px of whitespace before the text in the RTL case only.
108 return base::i18n::IsRTL() ? 1 : 0; 142 return base::i18n::IsRTL() ? 1 : 0;
109 } 143 }
110 144
111 } // namespace 145 } // namespace
112 146
113 147
114 // LocationBarView ----------------------------------------------------------- 148 // LocationBarView -----------------------------------------------------------
115 149
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 View::OnPaint(canvas); 1286 View::OnPaint(canvas);
1253 1287
1254 // Fill the location bar background color behind the border. Parts of the 1288 // Fill the location bar background color behind the border. Parts of the
1255 // border images are meant to rest atop the toolbar background and parts atop 1289 // border images are meant to rest atop the toolbar background and parts atop
1256 // the omnibox background, so we can't just blindly fill our entire bounds. 1290 // the omnibox background, so we can't just blindly fill our entire bounds.
1257 gfx::Rect bounds(GetContentsBounds()); 1291 gfx::Rect bounds(GetContentsBounds());
1258 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); 1292 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness());
1259 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); 1293 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND));
1260 if (is_popup_mode_) { 1294 if (is_popup_mode_) {
1261 canvas->FillRect(bounds, color); 1295 canvas->FillRect(bounds, color);
1296 } else if (ui::MaterialDesignController::IsModeMaterial()) {
1297 DrawScaledRect(canvas, SkPaint::kFill_Style, color, bounds, true);
1262 } else { 1298 } else {
1263 SkPaint paint; 1299 SkPaint paint;
1264 paint.setStyle(SkPaint::kFill_Style); 1300 paint.setStyle(SkPaint::kFill_Style);
1265 paint.setColor(color); 1301 paint.setColor(color);
1266 const int kBorderCornerRadius = 2; 1302 const int kBorderCornerRadius = 2;
1267 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1303 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
1268 } 1304 }
1269 1305
1270 // The border itself will be drawn in PaintChildren() since it includes an 1306 // The border itself will be drawn in PaintChildren() since it includes an
1271 // inner shadow which should be drawn over the contents. 1307 // inner shadow which should be drawn over the contents.
(...skipping 11 matching lines...) Expand all
1283 if (show_focus_rect_ && HasFocus()) 1319 if (show_focus_rect_ && HasFocus())
1284 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); 1320 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds());
1285 1321
1286 // Maximized popup windows don't draw the horizontal edges. We implement this 1322 // Maximized popup windows don't draw the horizontal edges. We implement this
1287 // by simply expanding the paint area outside the view by the edge thickness. 1323 // by simply expanding the paint area outside the view by the edge thickness.
1288 gfx::Rect border_rect(GetContentsBounds()); 1324 gfx::Rect border_rect(GetContentsBounds());
1289 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) 1325 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0))
1290 border_rect.Inset(-kPopupEdgeThickness, 0); 1326 border_rect.Inset(-kPopupEdgeThickness, 0);
1291 1327
1292 if (ui::MaterialDesignController::IsModeMaterial()) { 1328 if (ui::MaterialDesignController::IsModeMaterial()) {
1293 gfx::Canvas* canvas = recorder.canvas(); 1329 DrawScaledRect(recorder.canvas(), SkPaint::Style::kStroke_Style,
1294 const float display_scale = canvas->image_scale(); 1330 SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), border_rect,
jonross 2015/10/09 15:59:24 This fixes an incorrect color sampling of the orig
1295 canvas->Save(); 1331 !is_popup_mode_);
1296 SkScalar scale_factor = 1.0f / display_scale;
1297 canvas->sk_canvas()->scale(scale_factor, scale_factor);
1298
1299 SkPaint paint;
1300 paint.setStyle(SkPaint::Style::kStroke_Style);
1301 paint.setColor(SkColorSetARGB(0x40, 0x00, 0x00, 0x00));
1302 paint.setStrokeWidth(1);
1303 paint.setAntiAlias(true);
1304
1305 const float kOffset = 0.5f;
1306 gfx::RectF border_rect_f(border_rect);
1307 border_rect_f.Scale(display_scale);
1308 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset);
1309 border_rect_f.Inset(insets);
1310
1311 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale);
1312 canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f),
1313 kCornerRadius, kCornerRadius, paint);
1314 recorder.canvas()->Restore();
1315 } else { 1332 } else {
1316 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), 1333 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(),
1317 border_rect); 1334 border_rect);
1318 } 1335 }
1319 } 1336 }
1320 1337
1321 //////////////////////////////////////////////////////////////////////////////// 1338 ////////////////////////////////////////////////////////////////////////////////
1322 // LocationBarView, private views::ButtonListener implementation: 1339 // LocationBarView, private views::ButtonListener implementation:
1323 1340
1324 void LocationBarView::ButtonPressed(views::Button* sender, 1341 void LocationBarView::ButtonPressed(views::Button* sender,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 1439
1423 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1440 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1424 const SearchModel::State& new_state) { 1441 const SearchModel::State& new_state) {
1425 const bool visible = !GetToolbarModel()->input_in_progress() && 1442 const bool visible = !GetToolbarModel()->input_in_progress() &&
1426 new_state.voice_search_supported; 1443 new_state.voice_search_supported;
1427 if (mic_search_view_->visible() != visible) { 1444 if (mic_search_view_->visible() != visible) {
1428 mic_search_view_->SetVisible(visible); 1445 mic_search_view_->SetVisible(visible);
1429 Layout(); 1446 Layout();
1430 } 1447 }
1431 } 1448 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698