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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 void LocationBarView::Init() { | 180 void LocationBarView::Init() { |
181 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're | 181 // We need to be in a Widget, otherwise GetNativeTheme() may change and we're |
182 // not prepared for that. | 182 // not prepared for that. |
183 DCHECK(GetWidget()); | 183 DCHECK(GetWidget()); |
184 | 184 |
185 if (is_popup_mode_) { | 185 if (is_popup_mode_) { |
186 const int kOmniboxPopupBorderImages[] = | 186 const int kOmniboxPopupBorderImages[] = |
187 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW); | 187 IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER_AND_SHADOW); |
188 border_painter_.reset( | 188 border_painter_.reset( |
189 views::Painter::CreateImageGridPainter(kOmniboxPopupBorderImages)); | 189 views::Painter::CreateImageGridPainter(kOmniboxPopupBorderImages)); |
190 } else { | 190 } else if (!ui::MaterialDesignController::IsModeMaterial()) { |
191 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 191 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
192 const gfx::Insets omnibox_border_insets(14, 9, 14, 9); | 192 const gfx::Insets omnibox_border_insets(14, 9, 14, 9); |
193 border_painter_.reset(views::Painter::CreateImagePainter( | 193 border_painter_.reset(views::Painter::CreateImagePainter( |
194 *rb.GetImageSkiaNamed(IDR_OMNIBOX_BORDER), omnibox_border_insets)); | 194 *rb.GetImageSkiaNamed(IDR_OMNIBOX_BORDER), omnibox_border_insets)); |
195 } | 195 } |
196 | 196 |
197 location_icon_view_ = new LocationIconView(this); | 197 location_icon_view_ = new LocationIconView(this); |
198 location_icon_view_->set_drag_controller(this); | 198 location_icon_view_->set_drag_controller(this); |
199 AddChildView(location_icon_view_); | 199 AddChildView(location_icon_view_); |
200 | 200 |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 bool LocationBarView::HasFocus() const { | 521 bool LocationBarView::HasFocus() const { |
522 return omnibox_view_->model()->has_focus(); | 522 return omnibox_view_->model()->has_focus(); |
523 } | 523 } |
524 | 524 |
525 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { | 525 void LocationBarView::GetAccessibleState(ui::AXViewState* state) { |
526 state->role = ui::AX_ROLE_GROUP; | 526 state->role = ui::AX_ROLE_GROUP; |
527 } | 527 } |
528 | 528 |
529 gfx::Size LocationBarView::GetPreferredSize() const { | 529 gfx::Size LocationBarView::GetPreferredSize() const { |
530 // Compute minimum height. | 530 // Compute minimum height. |
531 gfx::Size min_size(border_painter_->GetMinimumSize()); | 531 gfx::Size min_size; |
532 // For non-material the size of the asset determines the size of the | 532 // For non-material the size of the asset determines the size of the |
533 // LocationBarView. | 533 // LocationBarView. |
534 if (ui::MaterialDesignController::IsModeMaterial()) | 534 if (ui::MaterialDesignController::IsModeMaterial()) |
535 min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT)); | 535 min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT)); |
536 else | |
537 min_size = border_painter_->GetMinimumSize(); | |
536 | 538 |
537 if (!IsInitialized()) | 539 if (!IsInitialized()) |
538 return min_size; | 540 return min_size; |
539 | 541 |
540 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); | 542 min_size.set_height(min_size.height() * size_animation_.GetCurrentValue()); |
541 | 543 |
542 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 544 const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
543 | 545 |
544 // Compute width of omnibox-leading content. | 546 // Compute width of omnibox-leading content. |
545 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | 547 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1266 // OnPaint(). | 1268 // OnPaint(). |
1267 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. | 1269 // Note: |Canvas::DrawFocusRect| paints a dashed rect with gray color. |
1268 if (show_focus_rect_ && HasFocus()) | 1270 if (show_focus_rect_ && HasFocus()) |
1269 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); | 1271 recorder.canvas()->DrawFocusRect(omnibox_view_->bounds()); |
1270 | 1272 |
1271 // Maximized popup windows don't draw the horizontal edges. We implement this | 1273 // Maximized popup windows don't draw the horizontal edges. We implement this |
1272 // by simply expanding the paint area outside the view by the edge thickness. | 1274 // by simply expanding the paint area outside the view by the edge thickness. |
1273 gfx::Rect border_rect(GetContentsBounds()); | 1275 gfx::Rect border_rect(GetContentsBounds()); |
1274 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) | 1276 if (is_popup_mode_ && (GetHorizontalEdgeThickness() == 0)) |
1275 border_rect.Inset(-kPopupEdgeThickness, 0); | 1277 border_rect.Inset(-kPopupEdgeThickness, 0); |
1276 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), | 1278 |
1277 border_rect); | 1279 if (ui::MaterialDesignController::IsModeMaterial()) { |
1280 recorder.canvas()->Save(); | |
1281 SkScalar scale_factor = 1.0f / recorder.canvas()->image_scale(); | |
1282 recorder.canvas()->sk_canvas()->scale(scale_factor, scale_factor); | |
1283 | |
1284 SkPaint paint; | |
1285 paint.setStyle(SkPaint::Style::kStroke_Style); | |
1286 paint.setColor(SkColorSetARGBInline(0x40, 0x0, 0x0, 0x0)); | |
Peter Kasting
2015/09/28 23:01:10
Don't explicitly call the inline version, just use
jonross
2015/09/29 17:25:02
Done.
| |
1287 paint.setStrokeWidth(0); | |
Peter Kasting
2015/09/28 23:01:10
Use stroke width 1 rather than 0.
jonross
2015/09/29 17:25:02
Done.
| |
1288 paint.setAntiAlias(true); | |
1289 | |
1290 const float kOffset = 0.5f; | |
1291 gfx::RectF border_rect_f(border_rect); | |
1292 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset); | |
1293 border_rect_f.Inset(insets); | |
1294 | |
1295 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f); | |
Peter Kasting
2015/09/28 23:01:10
Not sure this is right. This will give the corner
jonross
2015/09/29 17:25:02
Changing the scale of the sk_canvas keeps these co
| |
1296 recorder.canvas()->sk_canvas()->drawRoundRect( | |
1297 gfx::RectFToSkRect(border_rect_f), kCornerRadius, kCornerRadius, paint); | |
1298 recorder.canvas()->Restore(); | |
1299 } else { | |
1300 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), | |
1301 border_rect); | |
1302 } | |
1278 } | 1303 } |
1279 | 1304 |
1280 //////////////////////////////////////////////////////////////////////////////// | 1305 //////////////////////////////////////////////////////////////////////////////// |
1281 // LocationBarView, private views::ButtonListener implementation: | 1306 // LocationBarView, private views::ButtonListener implementation: |
1282 | 1307 |
1283 void LocationBarView::ButtonPressed(views::Button* sender, | 1308 void LocationBarView::ButtonPressed(views::Button* sender, |
1284 const ui::Event& event) { | 1309 const ui::Event& event) { |
1285 DCHECK_EQ(mic_search_view_, sender); | 1310 DCHECK_EQ(mic_search_view_, sender); |
1286 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); | 1311 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); |
1287 } | 1312 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 | 1406 |
1382 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1407 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1383 const SearchModel::State& new_state) { | 1408 const SearchModel::State& new_state) { |
1384 const bool visible = !GetToolbarModel()->input_in_progress() && | 1409 const bool visible = !GetToolbarModel()->input_in_progress() && |
1385 new_state.voice_search_supported; | 1410 new_state.voice_search_supported; |
1386 if (mic_search_view_->visible() != visible) { | 1411 if (mic_search_view_->visible() != visible) { |
1387 mic_search_view_->SetVisible(visible); | 1412 mic_search_view_->SetVisible(visible); |
1388 Layout(); | 1413 Layout(); |
1389 } | 1414 } |
1390 } | 1415 } |
OLD | NEW |