OLD | NEW |
---|---|
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 Loading... | |
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 void DrawScaledRoundRect(gfx::Canvas* canvas, | |
Peter Kasting
2015/10/08 21:33:06
Nit: I'd add a comment about what this does, in pa
jonross
2015/10/09 15:59:24
Done.
| |
107 SkPaint::Style style, | |
108 SkColor color, | |
109 gfx::Rect bounds) { | |
110 const float display_scale = canvas->image_scale(); | |
111 canvas->Save(); | |
112 SkScalar scale_factor = 1.0f / display_scale; | |
113 canvas->sk_canvas()->scale(scale_factor, scale_factor); | |
114 | |
115 SkPaint paint; | |
116 paint.setStyle(style); | |
117 paint.setColor(color); | |
118 paint.setAntiAlias(true); | |
119 | |
120 const float kOffset = 0.5f; | |
121 gfx::RectF border_rect_f(bounds); | |
122 border_rect_f.Scale(display_scale); | |
123 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset); | |
124 border_rect_f.Inset(insets); | |
125 | |
126 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale); | |
127 canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f), | |
128 kCornerRadius, kCornerRadius, paint); | |
129 canvas->Restore(); | |
130 } | |
131 | |
106 int GetEditLeadingInternalSpace() { | 132 int GetEditLeadingInternalSpace() { |
107 // The textfield has 1 px of whitespace before the text in the RTL case only. | 133 // The textfield has 1 px of whitespace before the text in the RTL case only. |
108 return base::i18n::IsRTL() ? 1 : 0; | 134 return base::i18n::IsRTL() ? 1 : 0; |
109 } | 135 } |
110 | 136 |
111 } // namespace | 137 } // namespace |
112 | 138 |
113 | 139 |
114 // LocationBarView ----------------------------------------------------------- | 140 // LocationBarView ----------------------------------------------------------- |
115 | 141 |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1252 View::OnPaint(canvas); | 1278 View::OnPaint(canvas); |
1253 | 1279 |
1254 // Fill the location bar background color behind the border. Parts of the | 1280 // 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 | 1281 // 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. | 1282 // the omnibox background, so we can't just blindly fill our entire bounds. |
1257 gfx::Rect bounds(GetContentsBounds()); | 1283 gfx::Rect bounds(GetContentsBounds()); |
1258 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); | 1284 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); |
1259 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); | 1285 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); |
1260 if (is_popup_mode_) { | 1286 if (is_popup_mode_) { |
1261 canvas->FillRect(bounds, color); | 1287 canvas->FillRect(bounds, color); |
1288 } else if (ui::MaterialDesignController::IsModeMaterial()) { | |
1289 DrawScaledRoundRect(canvas, SkPaint::kFill_Style, color, bounds); | |
1262 } else { | 1290 } else { |
1263 SkPaint paint; | 1291 SkPaint paint; |
1264 paint.setStyle(SkPaint::kFill_Style); | 1292 paint.setStyle(SkPaint::kFill_Style); |
1265 paint.setColor(color); | 1293 paint.setColor(color); |
1266 const int kBorderCornerRadius = 2; | 1294 const int kBorderCornerRadius = 2; |
1267 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1295 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
1268 } | 1296 } |
1269 | 1297 |
1270 // The border itself will be drawn in PaintChildren() since it includes an | 1298 // The border itself will be drawn in PaintChildren() since it includes an |
1271 // inner shadow which should be drawn over the contents. | 1299 // inner shadow which should be drawn over the contents. |
(...skipping 11 matching lines...) Expand all Loading... | |
1283 if (show_focus_rect_ && HasFocus()) | 1311 if (show_focus_rect_ && HasFocus()) |
1284 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); | 1312 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); |
1285 | 1313 |
1286 // Maximized popup windows don't draw the horizontal edges. We implement this | 1314 // 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. | 1315 // by simply expanding the paint area outside the view by the edge thickness. |
1288 gfx::Rect border_rect(GetContentsBounds()); | 1316 gfx::Rect border_rect(GetContentsBounds()); |
1289 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) | 1317 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) |
1290 border_rect.Inset(-kPopupEdgeThickness, 0); | 1318 border_rect.Inset(-kPopupEdgeThickness, 0); |
1291 | 1319 |
1292 if (ui::MaterialDesignController::IsModeMaterial()) { | 1320 if (ui::MaterialDesignController::IsModeMaterial()) { |
1293 gfx::Canvas* canvas = recorder.canvas(); | 1321 DrawScaledRoundRect(recorder.canvas(), SkPaint::Style::kStroke_Style, |
1294 const float display_scale = canvas->image_scale(); | 1322 SkColorSetARGB(0x40, 0x00, 0x00, 0x00), border_rect); |
Peter Kasting
2015/10/08 21:33:06
I don't think this is right for popup windows, whe
jonross
2015/10/09 15:14:17
I looked at the spec, to get the desired alpha ble
Peter Kasting
2015/10/09 16:03:32
That's what I thought.
There are several ways to
| |
1295 canvas->Save(); | |
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 { | 1323 } else { |
1316 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), | 1324 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), |
1317 border_rect); | 1325 border_rect); |
1318 } | 1326 } |
1319 } | 1327 } |
1320 | 1328 |
1321 //////////////////////////////////////////////////////////////////////////////// | 1329 //////////////////////////////////////////////////////////////////////////////// |
1322 // LocationBarView, private views::ButtonListener implementation: | 1330 // LocationBarView, private views::ButtonListener implementation: |
1323 | 1331 |
1324 void LocationBarView::ButtonPressed(views::Button* sender, | 1332 void LocationBarView::ButtonPressed(views::Button* sender, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1422 | 1430 |
1423 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1431 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1424 const SearchModel::State& new_state) { | 1432 const SearchModel::State& new_state) { |
1425 const bool visible = !GetToolbarModel()->input_in_progress() && | 1433 const bool visible = !GetToolbarModel()->input_in_progress() && |
1426 new_state.voice_search_supported; | 1434 new_state.voice_search_supported; |
1427 if (mic_search_view_->visible() != visible) { | 1435 if (mic_search_view_->visible() != visible) { |
1428 mic_search_view_->SetVisible(visible); | 1436 mic_search_view_->SetVisible(visible); |
1429 Layout(); | 1437 Layout(); |
1430 } | 1438 } |
1431 } | 1439 } |
OLD | NEW |