Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / app_list / views / cached_label.cc
blob4499842d842a0f210b8c5d80a2dd16218ced2fd6
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);
32 Label::OnPaint(&canvas);
33 image_ = gfx::ImageSkia(canvas.ExtractImageRep());
34 needs_repaint_ = false;
37 #if defined(OS_WIN)
38 void CachedLabel::OnPaint(gfx::Canvas* canvas) {
39 PaintToBackingImage();
40 canvas->DrawImageInt(image_, 0, 0);
42 #endif
44 void CachedLabel::OnDeviceScaleFactorChanged(
45 float device_scale_factor) {
46 Invalidate();
47 View::OnDeviceScaleFactorChanged(device_scale_factor);
50 } // namespace app_list