diff options
author | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 22:45:45 +0000 |
---|---|---|
committer | gspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 22:45:45 +0000 |
commit | c766a168bb731fc8618b0a202935c75fe67494ee (patch) | |
tree | 08687e47fef17d785a3e5f9df1478973a80edee9 /chrome/browser/chromeos/drop_shadow_label.cc | |
parent | 971b3c5679671ae9f08190a54d7cd0ed30ec9cfb (diff) | |
download | chromium_src-c766a168bb731fc8618b0a202935c75fe67494ee.zip chromium_src-c766a168bb731fc8618b0a202935c75fe67494ee.tar.gz chromium_src-c766a168bb731fc8618b0a202935c75fe67494ee.tar.bz2 |
Adding support for ChromeOS snapshot window titles and favicons.
TEST=build and ran with chromeos-wm
BUG=chromium-os:2866, chromium-os:2867
Review URL: http://codereview.chromium.org/2857005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51305 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/drop_shadow_label.cc')
-rw-r--r-- | chrome/browser/chromeos/drop_shadow_label.cc | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/drop_shadow_label.cc b/chrome/browser/chromeos/drop_shadow_label.cc new file mode 100644 index 0000000..5c5fa30 --- /dev/null +++ b/chrome/browser/chromeos/drop_shadow_label.cc @@ -0,0 +1,79 @@ +// Copyright (c) 2010 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/browser/chromeos/drop_shadow_label.h" + +#include "gfx/canvas.h" +#include "gfx/color_utils.h" + +using views::Label; + +namespace chromeos { + +static const int kDefaultDropShadowSize = 2; + +// Default color is black. +static const SkColor kDefaultColor = 0x000000; + +static const float kShadowOpacity = 0.2; + +DropShadowLabel::DropShadowLabel() : Label() { + Init(); +} + +void DropShadowLabel::Init() { + drop_shadow_size_ = kDefaultDropShadowSize; +} + +void DropShadowLabel::SetDropShadowSize(int drop_shadow_size) { + if (drop_shadow_size != drop_shadow_size_) { + drop_shadow_size_ = drop_shadow_size; + invalidate_text_size(); + SchedulePaint(); + } +} + +void DropShadowLabel::PaintText(gfx::Canvas* canvas, + const std::wstring& text, + const gfx::Rect& text_bounds, + int flags) { + if (drop_shadow_size_ > 0) { + SkColor color = SkColorSetARGB(kShadowOpacity * SkColorGetA(GetColor()), + SkColorGetR(kDefaultColor), + SkColorGetG(kDefaultColor), + SkColorGetB(kDefaultColor)); + for (int i = 0; i < drop_shadow_size_; i++) { + canvas->DrawStringInt(text, font(), color, + text_bounds.x() + i, text_bounds.y(), + text_bounds.width(), text_bounds.height(), flags); + canvas->DrawStringInt(text, font(), color, + text_bounds.x() + i, text_bounds.y() + i, + text_bounds.width(), text_bounds.height(), flags); + canvas->DrawStringInt(text, font(), color, + text_bounds.x(), text_bounds.y() + i, + text_bounds.width(), text_bounds.height(), flags); + } + } + + canvas->DrawStringInt(text, font(), GetColor(), + text_bounds.x(), text_bounds.y(), + text_bounds.width(), text_bounds.height(), flags); + + if (HasFocus() || paint_as_focused()) { + gfx::Rect focus_bounds = text_bounds; + focus_bounds.Inset(-Label::kFocusBorderPadding, + -Label::kFocusBorderPadding); + canvas->DrawFocusRect(focus_bounds.x(), focus_bounds.y(), + focus_bounds.width(), focus_bounds.height()); + } +} + +gfx::Size DropShadowLabel::GetTextSize() const { + gfx::Size text_size = Label::GetTextSize(); + text_size.SetSize(text_size.width() + drop_shadow_size_, + text_size.height() + drop_shadow_size_); + return text_size; +} + +} // namespace chromeos |