forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrop_shadow_label.cc
57 lines (46 loc) · 1.77 KB
/
drop_shadow_label.cc
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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 "ui/app_list/drop_shadow_label.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/insets.h"
namespace app_list {
DropShadowLabel::DropShadowLabel() {
}
DropShadowLabel::~DropShadowLabel() {
}
void DropShadowLabel::SetTextShadows(int shadow_count,
const gfx::ShadowValue* shadows) {
text_shadows_.clear();
if (shadow_count && shadows) {
for (int i = 0; i < shadow_count; ++i)
text_shadows_.push_back(shadows[i]);
}
}
gfx::Insets DropShadowLabel::GetInsets() const {
gfx::Insets insets = views::Label::GetInsets();
gfx::Insets shadow_margin = gfx::ShadowValue::GetMargin(text_shadows_);
// Negate |shadow_margin| to convert it to a padding insets needed inside
// the bounds and combine with label's insets.
insets += -shadow_margin;
return insets;
}
void DropShadowLabel::PaintText(gfx::Canvas* canvas,
const string16& text,
const gfx::Rect& text_bounds,
int flags) {
SkColor text_color = enabled() ? enabled_color() : disabled_color();
canvas->DrawStringWithShadows(text,
font(),
text_color,
text_bounds,
flags,
text_shadows_);
if (HasFocus() || paint_as_focused()) {
gfx::Rect focus_bounds = text_bounds;
focus_bounds.Inset(-views::Label::kFocusBorderPadding,
-views::Label::kFocusBorderPadding);
canvas->DrawFocusRect(focus_bounds);
}
}
} // namespace app_list