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 gfx::Canvas* canvas = recorder.canvas(); |
| 1281 const float display_scale = canvas->image_scale(); |
| 1282 canvas->Save(); |
| 1283 SkScalar scale_factor = 1.0f / display_scale; |
| 1284 canvas->sk_canvas()->scale(scale_factor, scale_factor); |
| 1285 |
| 1286 SkPaint paint; |
| 1287 paint.setStyle(SkPaint::Style::kStroke_Style); |
| 1288 paint.setColor(SkColorSetARGB(0x40, 0x00, 0x00, 0x00)); |
| 1289 paint.setStrokeWidth(1); |
| 1290 paint.setAntiAlias(true); |
| 1291 |
| 1292 const float kOffset = 0.5f; |
| 1293 gfx::RectF border_rect_f(border_rect); |
| 1294 border_rect_f.Scale(display_scale); |
| 1295 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset); |
| 1296 border_rect_f.Inset(insets); |
| 1297 |
| 1298 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale); |
| 1299 canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(border_rect_f), |
| 1300 kCornerRadius, kCornerRadius, paint); |
| 1301 recorder.canvas()->Restore(); |
| 1302 } else { |
| 1303 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(), |
| 1304 border_rect); |
| 1305 } |
1278 } | 1306 } |
1279 | 1307 |
1280 //////////////////////////////////////////////////////////////////////////////// | 1308 //////////////////////////////////////////////////////////////////////////////// |
1281 // LocationBarView, private views::ButtonListener implementation: | 1309 // LocationBarView, private views::ButtonListener implementation: |
1282 | 1310 |
1283 void LocationBarView::ButtonPressed(views::Button* sender, | 1311 void LocationBarView::ButtonPressed(views::Button* sender, |
1284 const ui::Event& event) { | 1312 const ui::Event& event) { |
1285 DCHECK_EQ(mic_search_view_, sender); | 1313 DCHECK_EQ(mic_search_view_, sender); |
1286 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); | 1314 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); |
1287 } | 1315 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 | 1409 |
1382 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1410 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
1383 const SearchModel::State& new_state) { | 1411 const SearchModel::State& new_state) { |
1384 const bool visible = !GetToolbarModel()->input_in_progress() && | 1412 const bool visible = !GetToolbarModel()->input_in_progress() && |
1385 new_state.voice_search_supported; | 1413 new_state.voice_search_supported; |
1386 if (mic_search_view_->visible() != visible) { | 1414 if (mic_search_view_->visible() != visible) { |
1387 mic_search_view_->SetVisible(visible); | 1415 mic_search_view_->SetVisible(visible); |
1388 Layout(); | 1416 Layout(); |
1389 } | 1417 } |
1390 } | 1418 } |
OLD | NEW |