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
3 // found in the LICENSE file.
5 #include "ui/app_list/views/cached_label.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/base/layout.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/views/widget/widget.h"
14 CachedLabel::CachedLabel()
15 : needs_repaint_(true) {
18 void CachedLabel::PaintToBackingImage() {
19 if (image_
.size() == size() && !needs_repaint_
)
22 bool is_opaque
= SkColorGetA(background_color()) == 0xFF;
24 ui::GetScaleFactorForNativeView(GetWidget()->GetNativeView());
25 gfx::Canvas
canvas(size(), scale_factor
, is_opaque
);
26 // If a background is provided, it will initialize the canvas in
27 // View::OnPaintBackground(). Otherwise, the background must be set here.
30 GetLocalBounds(), background_color(), SkXfermode::kSrc_Mode
);
33 Label::OnPaint(&canvas
);
35 image_
= gfx::ImageSkia(canvas
.ExtractImageRep());
36 needs_repaint_
= false;
40 void CachedLabel::OnPaint(gfx::Canvas
* canvas
) {
41 PaintToBackingImage();
42 canvas
->DrawImageInt(image_
, 0, 0);
46 void CachedLabel::OnDeviceScaleFactorChanged(
47 float device_scale_factor
) {
49 Label::OnDeviceScaleFactorChanged(device_scale_factor
);
52 } // namespace app_list