Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / app_list / views / cached_label.cc
blobdcf56b3e4260d582639154ba3a8b55bd22641f15
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"
12 namespace app_list {
14 CachedLabel::CachedLabel()
15 : needs_repaint_(true) {
18 void CachedLabel::PaintToBackingImage() {
19 if (image_.size() == size() && !needs_repaint_)
20 return;
22 bool is_opaque = SkColorGetA(background_color()) == 0xFF;
23 float scale_factor =
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.
28 if (!background()) {
29 canvas.FillRect(
30 GetLocalBounds(), background_color(), SkXfermode::kSrc_Mode);
33 Label::OnPaint(&canvas);
35 image_ = gfx::ImageSkia(canvas.ExtractImageRep());
36 needs_repaint_ = false;
39 #if defined(OS_WIN)
40 void CachedLabel::OnPaint(gfx::Canvas* canvas) {
41 PaintToBackingImage();
42 canvas->DrawImageInt(image_, 0, 0);
44 #endif
46 void CachedLabel::OnDeviceScaleFactorChanged(
47 float device_scale_factor) {
48 Invalidate();
49 Label::OnDeviceScaleFactorChanged(device_scale_factor);
52 } // namespace app_list