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

Side by Side Diff: ui/views/controls/focusable_border.cc

Issue 9544001: ui: Let skia do the conversion work for us by using the integer version of set() function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify FocusableBorder::Paint Created 8 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 | Annotate | Revision Log
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/controls/focusable_border.h" 5 #include "ui/views/controls/focusable_border.h"
6 6
7 #include "ui/gfx/canvas.h" 7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/canvas_skia.h" 8 #include "ui/gfx/canvas_skia.h"
9 #include "ui/gfx/insets.h" 9 #include "ui/gfx/insets.h"
10 #include "ui/gfx/native_theme.h" 10 #include "ui/gfx/native_theme.h"
11 #include "ui/gfx/skia_util.h"
11 12
12 namespace { 13 namespace {
13 14
14 // Define the size of the insets 15 // Define the size of the insets
15 const int kTopInsetSize = 4; 16 const int kTopInsetSize = 4;
16 const int kLeftInsetSize = 4; 17 const int kLeftInsetSize = 4;
17 const int kBottomInsetSize = 4; 18 const int kBottomInsetSize = 4;
18 const int kRightInsetSize = 4; 19 const int kRightInsetSize = 4;
19 20
20 } // namespace 21 } // namespace
21 22
22 namespace views { 23 namespace views {
23 24
24 FocusableBorder::FocusableBorder() 25 FocusableBorder::FocusableBorder()
25 : has_focus_(false), 26 : has_focus_(false),
26 insets_(kTopInsetSize, kLeftInsetSize, 27 insets_(kTopInsetSize, kLeftInsetSize,
27 kBottomInsetSize, kRightInsetSize) { 28 kBottomInsetSize, kRightInsetSize) {
28 } 29 }
29 30
30 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) const { 31 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) const {
31 SkRect rect;
32 rect.set(SkIntToScalar(0), SkIntToScalar(0),
33 SkIntToScalar(view.width()), SkIntToScalar(view.height()));
34 SkPath path; 32 SkPath path;
35 path.addRect(rect, SkPath::kCW_Direction); 33 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), SkPath::kCW_Direction);
36 SkPaint paint; 34 SkPaint paint;
37 paint.setStyle(SkPaint::kStroke_Style); 35 paint.setStyle(SkPaint::kStroke_Style);
38 SkColor focus_color = gfx::NativeTheme::instance()->GetSystemColor( 36 SkColor focus_color = gfx::NativeTheme::instance()->GetSystemColor(
39 has_focus_ ? gfx::NativeTheme::kColorId_FocusedBorderColor 37 has_focus_ ? gfx::NativeTheme::kColorId_FocusedBorderColor
40 : gfx::NativeTheme::kColorId_UnfocusedBorderColor); 38 : gfx::NativeTheme::kColorId_UnfocusedBorderColor);
41 paint.setColor(focus_color); 39 paint.setColor(focus_color);
42 paint.setStrokeWidth(SkIntToScalar(2)); 40 paint.setStrokeWidth(SkIntToScalar(2));
43 41
44 canvas->GetSkCanvas()->drawPath(path, paint); 42 canvas->GetSkCanvas()->drawPath(path, paint);
45 } 43 }
46 44
47 void FocusableBorder::GetInsets(gfx::Insets* insets) const { 45 void FocusableBorder::GetInsets(gfx::Insets* insets) const {
48 *insets = insets_; 46 *insets = insets_;
49 } 47 }
50 48
51 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) { 49 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) {
52 insets_.Set(top, left, bottom, right); 50 insets_.Set(top, left, bottom, right);
53 } 51 }
54 52
55 } // namespace views 53 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698