Workaround for xkbcommon dead keys.
[chromium-blink-merge.git] / ui / app_list / views / cached_label.cc
blobeb662eb7178e18af1cc3f07b69d1e8cd8692061e
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/profiler/scoped_tracker.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/base/layout.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/views/widget/widget.h"
13 namespace app_list {
15 CachedLabel::CachedLabel()
16 : needs_repaint_(true) {
19 void CachedLabel::PaintToBackingImage() {
20 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
21 tracked_objects::ScopedTracker tracking_profile1(
22 FROM_HERE_WITH_EXPLICIT_FUNCTION(
23 "431326 CachedLabel::PaintToBackingImage1"));
25 if (image_.size() == size() && !needs_repaint_)
26 return;
28 bool is_opaque = SkColorGetA(background_color()) == 0xFF;
29 float scale_factor =
30 ui::GetScaleFactorForNativeView(GetWidget()->GetNativeView());
31 gfx::Canvas canvas(size(), scale_factor, is_opaque);
32 // If a background is provided, it will initialize the canvas in
33 // View::OnPaintBackground(). Otherwise, the background must be set here.
34 if (!background()) {
35 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
36 tracked_objects::ScopedTracker tracking_profile2(
37 FROM_HERE_WITH_EXPLICIT_FUNCTION(
38 "431326 CachedLabel::PaintToBackingImage2"));
40 canvas.FillRect(
41 GetLocalBounds(), background_color(), SkXfermode::kSrc_Mode);
44 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
45 tracked_objects::ScopedTracker tracking_profile3(
46 FROM_HERE_WITH_EXPLICIT_FUNCTION(
47 "431326 CachedLabel::PaintToBackingImage3"));
49 Label::OnPaint(&canvas);
51 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed.
52 tracked_objects::ScopedTracker tracking_profile4(
53 FROM_HERE_WITH_EXPLICIT_FUNCTION(
54 "431326 CachedLabel::PaintToBackingImage4"));
56 image_ = gfx::ImageSkia(canvas.ExtractImageRep());
57 needs_repaint_ = false;
60 #if defined(OS_WIN)
61 void CachedLabel::OnPaint(gfx::Canvas* canvas) {
62 PaintToBackingImage();
63 canvas->DrawImageInt(image_, 0, 0);
65 #endif
67 void CachedLabel::OnDeviceScaleFactorChanged(
68 float device_scale_factor) {
69 Invalidate();
70 View::OnDeviceScaleFactorChanged(device_scale_factor);
73 } // namespace app_list