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