summaryrefslogtreecommitdiffstats
path: root/chrome/common/icon_with_badge_image_source.cc
blob: d3d785b9fcd8fb33897b86269bf881799bd5ba03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/icon_with_badge_image_source.h"

#include "chrome/common/badge_util.h"
//#include "ui/base/layout.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"

IconWithBadgeImageSource::IconWithBadgeImageSource(
    const gfx::ImageSkia& icon,
    const gfx::Size& icon_size,
    const gfx::Size& spacing,
    const std::string& text,
    const SkColor& text_color,
    const SkColor& background_color,
    extensions::ActionInfo::Type action_type)
        : gfx::CanvasImageSource(icon_size, false),
          icon_(icon),
          spacing_(spacing),
          text_(text),
          text_color_(text_color),
          background_color_(background_color),
          action_type_(action_type) {
}

IconWithBadgeImageSource::~IconWithBadgeImageSource() {}

void IconWithBadgeImageSource::Draw(gfx::Canvas* canvas) {
  canvas->DrawImageInt(icon_, 0, 0, SkPaint());
  gfx::Rect bounds(size_.width() + spacing_.width(),
                   size_.height() + spacing_.height());

  // Draw a badge on the provided browser action icon's canvas.
  badge_util::PaintBadge(canvas, bounds, text_, text_color_,
                         background_color_, size_.width(),
                         action_type_);
}