Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1811)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 1368363003: Programmatically render the omnibox border (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Corner Rounding Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 void LocationBarView::PaintChildren(const ui::PaintContext& context) { 1261 void LocationBarView::PaintChildren(const ui::PaintContext& context) {
1260 View::PaintChildren(context); 1262 View::PaintChildren(context);
1261 1263
1262 ui::PaintRecorder recorder(context, size()); 1264 ui::PaintRecorder recorder(context, size());
1263 1265
1264 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need 1266 // For non-InstantExtendedAPI cases, if necessary, show focus rect. As we need
1265 // the focus rect to appear on top of children we paint here rather than 1267 // the focus rect to appear on top of children we paint here rather than
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());
Peter Kasting 2015/09/29 18:12:37 Nit: recorder.canvas() is used a lot in this funct
jonross 2015/09/29 18:37:56 Done.
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 const float display_scale = recorder.canvas()->image_scale();
1281 recorder.canvas()->Save();
1282 SkScalar scale_factor = 1.0f / display_scale;
1283 recorder.canvas()->sk_canvas()->scale(scale_factor, scale_factor);
1284
1285 SkPaint paint;
1286 paint.setStyle(SkPaint::Style::kStroke_Style);
1287 paint.setColor(SkColorSetARGB(0x40, 0x00, 0x00, 0x00));
1288 paint.setStrokeWidth(1);
1289 paint.setAntiAlias(true);
1290
1291 const float kOffset = 0.5f;
1292 gfx::RectF border_rect_f(border_rect);
1293 border_rect_f.Scale(display_scale);
Peter Kasting 2015/09/29 18:12:37 Wow, how did it work at all in 2x without this?
jonross 2015/09/29 18:37:56 I goofed. I had it at one point. Accidentally remo
1294 gfx::InsetsF insets(kOffset, kOffset, kOffset, kOffset);
1295 border_rect_f.Inset(insets);
1296
1297 const SkScalar kCornerRadius = SkDoubleToScalar(2.5f * display_scale);
1298 recorder.canvas()->sk_canvas()->drawRoundRect(
1299 gfx::RectFToSkRect(border_rect_f), kCornerRadius, kCornerRadius, paint);
1300 recorder.canvas()->Restore();
1301 } else {
1302 views::Painter::PaintPainterAt(recorder.canvas(), border_painter_.get(),
1303 border_rect);
1304 }
1278 } 1305 }
1279 1306
1280 //////////////////////////////////////////////////////////////////////////////// 1307 ////////////////////////////////////////////////////////////////////////////////
1281 // LocationBarView, private views::ButtonListener implementation: 1308 // LocationBarView, private views::ButtonListener implementation:
1282 1309
1283 void LocationBarView::ButtonPressed(views::Button* sender, 1310 void LocationBarView::ButtonPressed(views::Button* sender,
1284 const ui::Event& event) { 1311 const ui::Event& event) {
1285 DCHECK_EQ(mic_search_view_, sender); 1312 DCHECK_EQ(mic_search_view_, sender);
1286 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT); 1313 command_updater()->ExecuteCommand(IDC_TOGGLE_SPEECH_INPUT);
1287 } 1314 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 1408
1382 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1409 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1383 const SearchModel::State& new_state) { 1410 const SearchModel::State& new_state) {
1384 const bool visible = !GetToolbarModel()->input_in_progress() && 1411 const bool visible = !GetToolbarModel()->input_in_progress() &&
1385 new_state.voice_search_supported; 1412 new_state.voice_search_supported;
1386 if (mic_search_view_->visible() != visible) { 1413 if (mic_search_view_->visible() != visible) {
1387 mic_search_view_->SetVisible(visible); 1414 mic_search_view_->SetVisible(visible);
1388 Layout(); 1415 Layout();
1389 } 1416 }
1390 } 1417 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698