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

Side by Side Diff: ui/views/painter.cc

Issue 2714753002: Improve appearance of focus rings at fractional scales. (Closed)
Patch Set: rebase Created 3 years, 9 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 | « ui/views/painter.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 "ui/views/painter.h" 5 #include "ui/views/painter.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 void DashedFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { 114 void DashedFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
115 gfx::Rect rect(size); 115 gfx::Rect rect(size);
116 rect.Inset(insets_); 116 rect.Inset(insets_);
117 canvas->DrawFocusRect(rect); 117 canvas->DrawFocusRect(rect);
118 } 118 }
119 119
120 // SolidFocusPainter ----------------------------------------------------------- 120 // SolidFocusPainter -----------------------------------------------------------
121 121
122 class SolidFocusPainter : public Painter { 122 class SolidFocusPainter : public Painter {
123 public: 123 public:
124 SolidFocusPainter(SkColor color, 124 SolidFocusPainter(SkColor color, int thickness, const gfx::InsetsF& insets);
125 SkScalar thickness,
126 const gfx::InsetsF& insets);
127 ~SolidFocusPainter() override; 125 ~SolidFocusPainter() override;
128 126
129 // Painter: 127 // Painter:
130 gfx::Size GetMinimumSize() const override; 128 gfx::Size GetMinimumSize() const override;
131 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override; 129 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override;
132 130
133 private: 131 private:
134 const SkColor color_; 132 const SkColor color_;
135 const SkScalar thickness_; 133 const int thickness_;
136 const gfx::InsetsF insets_; 134 const gfx::InsetsF insets_;
137 135
138 DISALLOW_COPY_AND_ASSIGN(SolidFocusPainter); 136 DISALLOW_COPY_AND_ASSIGN(SolidFocusPainter);
139 }; 137 };
140 138
141 SolidFocusPainter::SolidFocusPainter(SkColor color, 139 SolidFocusPainter::SolidFocusPainter(SkColor color,
142 SkScalar thickness, 140 int thickness,
143 const gfx::InsetsF& insets) 141 const gfx::InsetsF& insets)
144 : color_(color), thickness_(thickness), insets_(insets) {} 142 : color_(color), thickness_(thickness), insets_(insets) {}
145 143
146 SolidFocusPainter::~SolidFocusPainter() { 144 SolidFocusPainter::~SolidFocusPainter() {
147 } 145 }
148 146
149 gfx::Size SolidFocusPainter::GetMinimumSize() const { 147 gfx::Size SolidFocusPainter::GetMinimumSize() const {
150 return gfx::Size(); 148 return gfx::Size();
151 } 149 }
152 150
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 346
349 // static 347 // static
350 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( 348 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter(
351 SkColor color, 349 SkColor color,
352 const gfx::Insets& insets) { 350 const gfx::Insets& insets) {
353 // Before Canvas::DrawSolidFocusRect correctly inset the rect's bounds based 351 // Before Canvas::DrawSolidFocusRect correctly inset the rect's bounds based
354 // on the thickness, callers had to add 1 to the bottom and right insets. 352 // on the thickness, callers had to add 1 to the bottom and right insets.
355 // Subtract that here so it works the same way with the new 353 // Subtract that here so it works the same way with the new
356 // Canvas::DrawSolidFocusRect. 354 // Canvas::DrawSolidFocusRect.
357 const gfx::Insets corrected_insets = insets - gfx::Insets(0, 0, 1, 1); 355 const gfx::Insets corrected_insets = insets - gfx::Insets(0, 0, 1, 1);
358 return base::MakeUnique<SolidFocusPainter>(color, SkIntToScalar(1), 356 return base::MakeUnique<SolidFocusPainter>(color, 1, corrected_insets);
359 corrected_insets);
360 } 357 }
361 358
362 // static 359 // static
363 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( 360 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter(
364 SkColor color, 361 SkColor color,
365 float thickness, 362 int thickness,
366 const gfx::InsetsF& insets) { 363 const gfx::InsetsF& insets) {
367 return base::MakeUnique<SolidFocusPainter>(color, SkFloatToScalar(thickness), 364 return base::MakeUnique<SolidFocusPainter>(color, thickness, insets);
368 insets);
369 } 365 }
370 366
371 // HorizontalPainter ---------------------------------------------------------- 367 // HorizontalPainter ----------------------------------------------------------
372 368
373 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { 369 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) {
374 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 370 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
375 for (int i = 0; i < 3; ++i) 371 for (int i = 0; i < 3; ++i)
376 images_[i] = rb.GetImageNamed(image_resource_names[i]).ToImageSkia(); 372 images_[i] = rb.GetImageNamed(image_resource_names[i]).ToImageSkia();
377 DCHECK_EQ(images_[LEFT]->height(), images_[CENTER]->height()); 373 DCHECK_EQ(images_[LEFT]->height(), images_[CENTER]->height());
378 DCHECK_EQ(images_[LEFT]->height(), images_[RIGHT]->height()); 374 DCHECK_EQ(images_[LEFT]->height(), images_[RIGHT]->height());
(...skipping 15 matching lines...) Expand all
394 canvas->DrawImageInt(*images_[LEFT], 0, 0); 390 canvas->DrawImageInt(*images_[LEFT], 0, 0);
395 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), 391 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(),
396 0); 392 0);
397 canvas->TileImageInt( 393 canvas->TileImageInt(
398 *images_[CENTER], images_[LEFT]->width(), 0, 394 *images_[CENTER], images_[LEFT]->width(), 0,
399 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), 395 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(),
400 images_[LEFT]->height()); 396 images_[LEFT]->height());
401 } 397 }
402 398
403 } // namespace views 399 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/painter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698