OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list/views/cached_label.h" | 5 #include "ui/app_list/views/cached_label.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/base/layout.h" |
8 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
9 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/views/widget/widget.h" |
10 | 12 |
11 namespace app_list { | 13 namespace app_list { |
12 | 14 |
13 CachedLabel::CachedLabel() | 15 CachedLabel::CachedLabel() |
14 : needs_repaint_(true) { | 16 : needs_repaint_(true) { |
15 } | 17 } |
16 | 18 |
17 void CachedLabel::PaintToBackingImage() { | 19 void CachedLabel::PaintToBackingImage() { |
18 if (image_.size() == size() && !needs_repaint_) | 20 if (image_.size() == size() && !needs_repaint_) |
19 return; | 21 return; |
20 | 22 |
21 bool is_opaque = SkColorGetA(background_color()) == 0xFF; | 23 bool is_opaque = SkColorGetA(background_color()) == 0xFF; |
22 gfx::Canvas canvas(size(), 1.0f, is_opaque); | 24 float scale_factor = |
| 25 ui::GetScaleFactorForNativeView(GetWidget()->GetNativeView()); |
| 26 gfx::Canvas canvas(size(), scale_factor, is_opaque); |
23 // If a background is provided, it will initialize the canvas in | 27 // If a background is provided, it will initialize the canvas in |
24 // View::OnPaintBackground(). Otherwise, the background must be set here. | 28 // View::OnPaintBackground(). Otherwise, the background must be set here. |
25 if (!background()) { | 29 if (!background()) { |
26 canvas.FillRect( | 30 canvas.FillRect( |
27 GetLocalBounds(), background_color(), SkXfermode::kSrc_Mode); | 31 GetLocalBounds(), background_color(), SkXfermode::kSrc_Mode); |
28 } | 32 } |
29 Label::OnPaint(&canvas); | 33 Label::OnPaint(&canvas); |
30 image_ = gfx::ImageSkia(canvas.ExtractImageRep()); | 34 image_ = gfx::ImageSkia(canvas.ExtractImageRep()); |
31 needs_repaint_ = false; | 35 needs_repaint_ = false; |
32 } | 36 } |
33 | 37 |
34 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
35 void CachedLabel::OnPaint(gfx::Canvas* canvas) { | 39 void CachedLabel::OnPaint(gfx::Canvas* canvas) { |
36 PaintToBackingImage(); | 40 PaintToBackingImage(); |
37 canvas->DrawImageInt(image_, 0, 0); | 41 canvas->DrawImageInt(image_, 0, 0); |
38 } | 42 } |
39 #endif | 43 #endif |
40 | 44 |
| 45 void CachedLabel::OnDeviceScaleFactorChanged( |
| 46 float device_scale_factor) { |
| 47 Invalidate(); |
| 48 View::OnDeviceScaleFactorChanged(device_scale_factor); |
| 49 } |
| 50 |
41 } // namespace app_list | 51 } // namespace app_list |
OLD | NEW |