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 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1251 return kViewClassName; | 1251 return kViewClassName; |
| 1252 } | 1252 } |
| 1253 | 1253 |
| 1254 void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 1254 void LocationBarView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 1255 OmniboxPopupView* popup = omnibox_view_->model()->popup_model()->view(); | 1255 OmniboxPopupView* popup = omnibox_view_->model()->popup_model()->view(); |
| 1256 if (popup->IsOpen()) | 1256 if (popup->IsOpen()) |
| 1257 popup->UpdatePopupAppearance(); | 1257 popup->UpdatePopupAppearance(); |
| 1258 } | 1258 } |
| 1259 | 1259 |
| 1260 void LocationBarView::OnFocus() { | 1260 void LocationBarView::OnFocus() { |
| 1261 // Explicitly focus the omnibox so a focus ring will be displayed around it on | |
| 1262 // Windows. | |
| 1263 omnibox_view_->SetFocus(); | 1261 omnibox_view_->SetFocus(); |
| 1264 } | 1262 } |
| 1265 | 1263 |
| 1266 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 1264 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 1267 View::OnPaint(canvas); | 1265 View::OnPaint(canvas); |
| 1268 | 1266 |
| 1269 if (ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_) | 1267 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 1270 return; // The background and border are painted by our Background. | 1268 if (show_focus_rect_ && omnibox_view_->HasFocus()) { |
| 1269 SkPaint paint; | |
| 1270 paint.setAntiAlias(true); | |
| 1271 paint.setColor(GetNativeTheme()->GetSystemColor( | |
| 1272 ui::NativeTheme::NativeTheme::kColorId_FocusedBorderColor)); | |
| 1273 paint.setStyle(SkPaint::kStroke_Style); | |
| 1274 paint.setStrokeWidth(1); | |
|
Peter Kasting
2016/05/20 20:32:49
This will scale up on higher scale factors, which
Evan Stade
2016/05/20 20:54:43
It's my understanding that the focus border is int
Peter Kasting
2016/05/20 20:57:13
Can we double-check that this intentionally differ
| |
| 1275 gfx::RectF focus_rect(GetLocalBounds()); | |
| 1276 focus_rect.Inset(gfx::InsetsF(0.5f)); | |
| 1277 canvas->DrawRoundRect(focus_rect, 2.5f, paint); | |
| 1278 } | |
| 1279 if (!is_popup_mode_) | |
| 1280 return; // The background and border are painted by our Background. | |
| 1281 } | |
| 1271 | 1282 |
| 1272 // Fill the location bar background color behind the border. Parts of the | 1283 // Fill the location bar background color behind the border. Parts of the |
| 1273 // border images are meant to rest atop the toolbar background and parts atop | 1284 // border images are meant to rest atop the toolbar background and parts atop |
| 1274 // the omnibox background, so we can't just blindly fill our entire bounds. | 1285 // the omnibox background, so we can't just blindly fill our entire bounds. |
| 1275 gfx::Rect bounds(GetContentsBounds()); | 1286 gfx::Rect bounds(GetContentsBounds()); |
| 1276 bounds.Inset(GetHorizontalEdgeThickness(), | 1287 bounds.Inset(GetHorizontalEdgeThickness(), |
| 1277 is_popup_mode_ ? 0 : GetVerticalEdgeThickness()); | 1288 is_popup_mode_ ? 0 : GetVerticalEdgeThickness()); |
| 1278 SkColor background_color(GetColor(BACKGROUND)); | 1289 SkColor background_color(GetColor(BACKGROUND)); |
| 1279 if (!is_popup_mode_) { | 1290 if (!is_popup_mode_) { |
| 1280 SkPaint paint; | 1291 SkPaint paint; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1295 | 1306 |
| 1296 void LocationBarView::PaintChildren(const ui::PaintContext& context) { | 1307 void LocationBarView::PaintChildren(const ui::PaintContext& context) { |
| 1297 View::PaintChildren(context); | 1308 View::PaintChildren(context); |
| 1298 | 1309 |
| 1299 ui::PaintRecorder recorder(context, size()); | 1310 ui::PaintRecorder recorder(context, size()); |
| 1300 | 1311 |
| 1301 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need | 1312 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need |
| 1302 // the focus rect to appear on top of children we paint here rather than | 1313 // the focus rect to appear on top of children we paint here rather than |
| 1303 // OnPaint(). | 1314 // OnPaint(). |
| 1304 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 1315 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
| 1305 if (show_focus_rect_ && HasFocus()) | 1316 if (!ui::MaterialDesignController::IsModeMaterial() && show_focus_rect_ && |
| 1317 HasFocus()) { | |
|
Peter Kasting
2016/05/20 20:32:49
Nit: No {} on multiline conditional with single-li
Evan Stade
2016/05/20 22:07:32
Done.
| |
| 1306 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); | 1318 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); |
| 1319 } | |
| 1307 | 1320 |
| 1308 if (!ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_) { | 1321 if (!ui::MaterialDesignController::IsModeMaterial() && !is_popup_mode_) { |
| 1309 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), | 1322 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), |
| 1310 GetContentsBounds()); | 1323 GetContentsBounds()); |
| 1311 } | 1324 } |
| 1312 } | 1325 } |
| 1313 | 1326 |
| 1314 //////////////////////////////////////////////////////////////////////////////// | 1327 //////////////////////////////////////////////////////////////////////////////// |
| 1315 // LocationBarView, private views::DragController implementation: | 1328 // LocationBarView, private views::DragController implementation: |
| 1316 | 1329 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1358 //////////////////////////////////////////////////////////////////////////////// | 1371 //////////////////////////////////////////////////////////////////////////////// |
| 1359 // LocationBarView, private OmniboxEditController implementation: | 1372 // LocationBarView, private OmniboxEditController implementation: |
| 1360 | 1373 |
| 1361 void LocationBarView::OnChanged() { | 1374 void LocationBarView::OnChanged() { |
| 1362 RefreshLocationIcon(); | 1375 RefreshLocationIcon(); |
| 1363 location_icon_view_->set_show_tooltip(!GetOmniboxView()->IsEditingOrEmpty()); | 1376 location_icon_view_->set_show_tooltip(!GetOmniboxView()->IsEditingOrEmpty()); |
| 1364 Layout(); | 1377 Layout(); |
| 1365 SchedulePaint(); | 1378 SchedulePaint(); |
| 1366 } | 1379 } |
| 1367 | 1380 |
| 1368 void LocationBarView::OnSetFocus() { | |
| 1369 GetFocusManager()->SetFocusedView(this); | |
| 1370 } | |
| 1371 | |
| 1372 const ToolbarModel* LocationBarView::GetToolbarModel() const { | 1381 const ToolbarModel* LocationBarView::GetToolbarModel() const { |
| 1373 return delegate_->GetToolbarModel(); | 1382 return delegate_->GetToolbarModel(); |
| 1374 } | 1383 } |
| 1375 | 1384 |
| 1376 //////////////////////////////////////////////////////////////////////////////// | 1385 //////////////////////////////////////////////////////////////////////////////// |
| 1377 // LocationBarView, private DropdownBarHostDelegate implementation: | 1386 // LocationBarView, private DropdownBarHostDelegate implementation: |
| 1378 | 1387 |
| 1379 void LocationBarView::SetFocusAndSelection(bool select_all) { | 1388 void LocationBarView::SetFocusAndSelection(bool select_all) { |
| 1380 FocusLocation(select_all); | 1389 FocusLocation(select_all); |
| 1381 } | 1390 } |
| 1382 | 1391 |
| 1383 //////////////////////////////////////////////////////////////////////////////// | 1392 //////////////////////////////////////////////////////////////////////////////// |
| 1384 // LocationBarView, private TemplateURLServiceObserver implementation: | 1393 // LocationBarView, private TemplateURLServiceObserver implementation: |
| 1385 | 1394 |
| 1386 void LocationBarView::OnTemplateURLServiceChanged() { | 1395 void LocationBarView::OnTemplateURLServiceChanged() { |
| 1387 template_url_service_->RemoveObserver(this); | 1396 template_url_service_->RemoveObserver(this); |
| 1388 template_url_service_ = nullptr; | 1397 template_url_service_ = nullptr; |
| 1389 // If the browser is no longer active, let's not show the info bubble, as this | 1398 // If the browser is no longer active, let's not show the info bubble, as this |
| 1390 // would make the browser the active window again. | 1399 // would make the browser the active window again. |
| 1391 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1400 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
| 1392 ShowFirstRunBubble(); | 1401 ShowFirstRunBubble(); |
| 1393 } | 1402 } |
| OLD | NEW |