Chromium Code Reviews| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 #include "components/search_engines/template_url_service.h" | 63 #include "components/search_engines/template_url_service.h" |
| 64 #include "components/translate/core/browser/language_state.h" | 64 #include "components/translate/core/browser/language_state.h" |
| 65 #include "components/ui/zoom/zoom_controller.h" | 65 #include "components/ui/zoom/zoom_controller.h" |
| 66 #include "components/ui/zoom/zoom_event_manager.h" | 66 #include "components/ui/zoom/zoom_event_manager.h" |
| 67 #include "content/public/browser/render_widget_host_view.h" | 67 #include "content/public/browser/render_widget_host_view.h" |
| 68 #include "content/public/browser/web_contents.h" | 68 #include "content/public/browser/web_contents.h" |
| 69 #include "extensions/browser/extension_registry.h" | 69 #include "extensions/browser/extension_registry.h" |
| 70 #include "extensions/common/feature_switch.h" | 70 #include "extensions/common/feature_switch.h" |
| 71 #include "grit/components_scaled_resources.h" | 71 #include "grit/components_scaled_resources.h" |
| 72 #include "grit/theme_resources.h" | 72 #include "grit/theme_resources.h" |
| 73 #include "third_party/skia/include/core/SkPath.h" | |
| 74 #include "third_party/skia/include/pathops/SkPathOps.h" | |
| 73 #include "ui/accessibility/ax_view_state.h" | 75 #include "ui/accessibility/ax_view_state.h" |
| 74 #include "ui/base/dragdrop/drag_drop_types.h" | 76 #include "ui/base/dragdrop/drag_drop_types.h" |
| 75 #include "ui/base/l10n/l10n_util.h" | 77 #include "ui/base/l10n/l10n_util.h" |
| 76 #include "ui/base/resource/material_design/material_design_controller.h" | 78 #include "ui/base/resource/material_design/material_design_controller.h" |
| 77 #include "ui/base/resource/resource_bundle.h" | 79 #include "ui/base/resource/resource_bundle.h" |
| 78 #include "ui/base/theme_provider.h" | 80 #include "ui/base/theme_provider.h" |
| 79 #include "ui/compositor/paint_recorder.h" | 81 #include "ui/compositor/paint_recorder.h" |
| 80 #include "ui/events/event.h" | 82 #include "ui/events/event.h" |
| 81 #include "ui/gfx/animation/slide_animation.h" | 83 #include "ui/gfx/animation/slide_animation.h" |
| 82 #include "ui/gfx/canvas.h" | 84 #include "ui/gfx/canvas.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 96 | 98 |
| 97 #if !defined(OS_CHROMEOS) | 99 #if !defined(OS_CHROMEOS) |
| 98 #include "chrome/browser/ui/views/first_run_bubble.h" | 100 #include "chrome/browser/ui/views/first_run_bubble.h" |
| 99 #endif | 101 #endif |
| 100 | 102 |
| 101 using content::WebContents; | 103 using content::WebContents; |
| 102 using views::View; | 104 using views::View; |
| 103 | 105 |
| 104 namespace { | 106 namespace { |
| 105 | 107 |
| 108 // Removes the current image scaling on |canvas|, returning the scale value. | |
| 109 // Also adjusts |rect| based on the scaling. Call canvas->Restore() to return | |
| 110 // to default scaling. | |
| 111 float SetupScaledPainting(gfx::Canvas* canvas, gfx::RectF* rect) { | |
| 112 const float display_scale = canvas->image_scale(); | |
| 113 canvas->Save(); | |
| 114 SkScalar scale_factor = 1.0f / display_scale; | |
| 115 canvas->sk_canvas()->scale(scale_factor, scale_factor); | |
| 116 | |
| 117 const float kOffset = 0.5f; | |
| 118 rect->Scale(display_scale); | |
| 119 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset); | |
| 120 rect->Inset(insets); | |
|
Evan Stade
2015/10/09 20:00:24
you can just do rect->Inset(kOffset, kOffset)
jonross
2015/10/19 20:29:02
Done.
| |
| 121 | |
| 122 return display_scale; | |
| 123 } | |
| 124 | |
| 125 // Draws a filled rect in the native coordinates of the display. Where |bounds| | |
| 126 // is in the coordinate space of LocationBarView. The actual rect drawn will be | |
| 127 // reduced by the region of |bounds| required to render a one pixel thick | |
| 128 // border. | |
| 129 void DrawScaledBackgroundRect(gfx::Canvas* canvas, | |
| 130 SkColor color, | |
| 131 gfx::Rect bounds) { | |
| 132 gfx::RectF border_rect_f(bounds); | |
| 133 const float display_scale = SetupScaledPainting(canvas, &border_rect_f); | |
| 134 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale); | |
| 135 | |
| 136 SkPath path; | |
| 137 path.addRoundRect(gfx::RectFToSkRect(border_rect_f), kCornerRadius, | |
| 138 kCornerRadius); | |
| 139 | |
| 140 SkPaint stroke_paint; | |
| 141 stroke_paint.setStyle(SkPaint::Style::kStroke_Style); | |
| 142 stroke_paint.setStrokeWidth(1); | |
| 143 | |
| 144 SkPath stroke_path; | |
| 145 stroke_paint.getFillPath(path, &stroke_path); | |
| 146 | |
| 147 SkPath fill_path; | |
| 148 Op(path, stroke_path, kDifference_SkPathOp, &fill_path); | |
| 149 | |
| 150 SkPaint paint; | |
| 151 paint.setStyle(SkPaint::kFill_Style); | |
| 152 paint.setColor(color); | |
| 153 paint.setAntiAlias(true); | |
| 154 | |
| 155 canvas->sk_canvas()->drawPath(fill_path, paint); | |
| 156 canvas->Restore(); | |
| 157 } | |
| 158 | |
| 159 // Draws a one pixel thick border in the native coordinates of the display. | |
| 160 // Where |bounds| is in the coordinate space of LocationBarView. If |round| the | |
| 161 // drawn rect will have rounded corners. | |
| 162 void DrawScaledBorderRect(gfx::Canvas* canvas, | |
| 163 SkColor color, | |
| 164 gfx::Rect bounds, | |
| 165 bool round) { | |
| 166 gfx::RectF border_rect_f(bounds); | |
| 167 const float display_scale = SetupScaledPainting(canvas, &border_rect_f); | |
| 168 | |
| 169 SkPaint paint; | |
| 170 paint.setStyle(SkPaint::Style::kStroke_Style); | |
| 171 paint.setColor(color); | |
| 172 paint.setAntiAlias(true); | |
| 173 | |
| 174 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale); | |
| 175 if (round) { | |
| 176 canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f), | |
| 177 kCornerRadius, kCornerRadius, paint); | |
| 178 } else { | |
| 179 canvas->sk_canvas()->drawRect(gfx::RectFToSkRect(border_rect_f), paint); | |
| 180 } | |
| 181 canvas->Restore(); | |
| 182 } | |
| 183 | |
| 106 int GetEditLeadingInternalSpace() { | 184 int GetEditLeadingInternalSpace() { |
| 107 // The textfield has 1 px of whitespace before the text in the RTL case only. | 185 // The textfield has 1 px of whitespace before the text in the RTL case only. |
| 108 return base::i18n::IsRTL() ? 1 : 0; | 186 return base::i18n::IsRTL() ? 1 : 0; |
| 109 } | 187 } |
| 110 | 188 |
| 111 } // namespace | 189 } // namespace |
| 112 | 190 |
| 113 | 191 |
| 114 // LocationBarView ----------------------------------------------------------- | 192 // LocationBarView ----------------------------------------------------------- |
| 115 | 193 |
| (...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1246 // Explicitly focus the omnibox so a focus ring will be displayed around it on | 1324 // Explicitly focus the omnibox so a focus ring will be displayed around it on |
| 1247 // Windows. | 1325 // Windows. |
| 1248 omnibox_view_->SetFocus(); | 1326 omnibox_view_->SetFocus(); |
| 1249 } | 1327 } |
| 1250 | 1328 |
| 1251 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 1329 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 1252 View::OnPaint(canvas); | 1330 View::OnPaint(canvas); |
| 1253 | 1331 |
| 1254 // Fill the location bar background color behind the border. Parts of the | 1332 // 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 | 1333 // 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. | 1334 // the omnibox background, so we can't just blindly fill our entire bounds. |
|
Evan Stade
2015/10/09 20:34:38
I don't think this is still true for material mode
jonross
2015/10/19 20:29:02
Done.
| |
| 1257 gfx::Rect bounds(GetContentsBounds()); | 1335 gfx::Rect bounds(GetContentsBounds()); |
| 1258 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); | 1336 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); |
| 1259 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); | 1337 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND)); |
| 1260 if (is_popup_mode_) { | 1338 if (is_popup_mode_) { |
| 1261 canvas->FillRect(bounds, color); | 1339 canvas->FillRect(bounds, color); |
| 1340 } else if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 1341 DrawScaledBackgroundRect(canvas, color, bounds); | |
| 1262 } else { | 1342 } else { |
| 1263 SkPaint paint; | 1343 SkPaint paint; |
| 1264 paint.setStyle(SkPaint::kFill_Style); | 1344 paint.setStyle(SkPaint::kFill_Style); |
| 1265 paint.setColor(color); | 1345 paint.setColor(color); |
| 1266 const int kBorderCornerRadius = 2; | 1346 const int kBorderCornerRadius = 2; |
| 1267 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); | 1347 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); |
| 1268 } | 1348 } |
| 1269 | 1349 |
| 1270 // The border itself will be drawn in PaintChildren() since it includes an | 1350 // The border itself will be drawn in PaintChildren() since it includes an |
| 1271 // inner shadow which should be drawn over the contents. | 1351 // inner shadow which should be drawn over the contents. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1283 if (show_focus_rect_ && HasFocus()) | 1363 if (show_focus_rect_ && HasFocus()) |
| 1284 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); | 1364 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); |
| 1285 | 1365 |
| 1286 // Maximized popup windows don't draw the horizontal edges. We implement this | 1366 // 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. | 1367 // by simply expanding the paint area outside the view by the edge thickness. |
| 1288 gfx::Rect border_rect(GetContentsBounds()); | 1368 gfx::Rect border_rect(GetContentsBounds()); |
| 1289 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) | 1369 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) |
| 1290 border_rect.Inset(-kPopupEdgeThickness, 0); | 1370 border_rect.Inset(-kPopupEdgeThickness, 0); |
| 1291 | 1371 |
| 1292 if (ui::MaterialDesignController::IsModeMaterial()) { | 1372 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 1293 gfx::Canvas* canvas = recorder.canvas(); | 1373 DrawScaledBorderRect(recorder.canvas(), |
| 1294 const float display_scale = canvas->image_scale(); | 1374 SkColorSetARGB(0x4D, 0x00, 0x00, 0x00), border_rect, |
| 1295 canvas->Save(); | 1375 !is_popup_mode_); |
|
Peter Kasting
2015/10/12 23:45:44
In the MD world, I don't think we actually need to
jonross
2015/10/19 20:29:02
Done.
| |
| 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 { | 1376 } else { |
| 1316 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), | 1377 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), |
| 1317 border_rect); | 1378 border_rect); |
| 1318 } | 1379 } |
| 1319 } | 1380 } |
| 1320 | 1381 |
| 1321 //////////////////////////////////////////////////////////////////////////////// | 1382 //////////////////////////////////////////////////////////////////////////////// |
| 1322 // LocationBarView, private views::ButtonListener implementation: | 1383 // LocationBarView, private views::ButtonListener implementation: |
| 1323 | 1384 |
| 1324 void LocationBarView::ButtonPressed(views::Button* sender, | 1385 void LocationBarView::ButtonPressed(views::Button* sender, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1422 | 1483 |
| 1423 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1484 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
| 1424 const SearchModel::State& new_state) { | 1485 const SearchModel::State& new_state) { |
| 1425 const bool visible = !GetToolbarModel()->input_in_progress() && | 1486 const bool visible = !GetToolbarModel()->input_in_progress() && |
| 1426 new_state.voice_search_supported; | 1487 new_state.voice_search_supported; |
| 1427 if (mic_search_view_->visible() != visible) { | 1488 if (mic_search_view_->visible() != visible) { |
| 1428 mic_search_view_->SetVisible(visible); | 1489 mic_search_view_->SetVisible(visible); |
| 1429 Layout(); | 1490 Layout(); |
| 1430 } | 1491 } |
| 1431 } | 1492 } |
| OLD | NEW |