diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-27 01:57:06 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-27 01:57:06 +0000 |
commit | aa101967206133025370eae0b55fb6c8a530ba38 (patch) | |
tree | f951de5675d3b92d3bce40ac8cc486165ca8e269 /ui | |
parent | ac81900d20d230ffd31fc262b3b3298f55084494 (diff) | |
download | chromium_src-aa101967206133025370eae0b55fb6c8a530ba38.zip chromium_src-aa101967206133025370eae0b55fb6c8a530ba38.tar.gz chromium_src-aa101967206133025370eae0b55fb6c8a530ba38.tar.bz2 |
ash: Draw shadows for text in uber tray.
This adds drop shadows to the labels in the system tray
(e.g. clock and input method).
BUG=120172
TEST=manual: see screenshot in bug
Review URL: https://chromiumcodereview.appspot.com/9773041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129096 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/controls/label.cc | 27 | ||||
-rw-r--r-- | ui/views/controls/label.h | 48 |
2 files changed, 61 insertions, 14 deletions
diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc index 5cbae64..bbaad85 100644 --- a/ui/views/controls/label.cc +++ b/ui/views/controls/label.cc @@ -89,6 +89,20 @@ void Label::SetBackgroundColor(const SkColor& color) { RecalculateColors(); } +void Label::SetShadowColors(SkColor enabled_color, SkColor disabled_color) { + enabled_shadow_color_ = enabled_color; + disabled_shadow_color_ = disabled_color; + has_shadow_ = true; +} + +void Label::SetShadowOffset(int x, int y) { + shadow_offset_.SetPoint(x, y); +} + +void Label::ClearEmbellishing() { + has_shadow_ = false; +} + void Label::SetHorizontalAlignment(Alignment alignment) { // If the View's UI layout is right-to-left and directionality_mode_ is // USE_UI_DIRECTIONALITY, we need to flip the alignment so that the alignment @@ -258,6 +272,15 @@ void Label::PaintText(gfx::Canvas* canvas, const string16& text, const gfx::Rect& text_bounds, int flags) { + if (has_shadow_) { + canvas->DrawStringInt( + text, font_, + enabled() ? enabled_shadow_color_ : disabled_shadow_color_, + text_bounds.x() + shadow_offset_.x(), + text_bounds.y() + shadow_offset_.y(), + text_bounds.width(), text_bounds.height(), + flags); + } canvas->DrawStringInt(text, font_, enabled() ? actual_enabled_color_ : actual_disabled_color_, text_bounds.x(), text_bounds.y(), text_bounds.width(), @@ -359,6 +382,10 @@ void Label::Init(const string16& text, const gfx::Font& font) { directionality_mode_ = USE_UI_DIRECTIONALITY; paint_as_focused_ = false; has_focus_border_ = false; + enabled_shadow_color_ = 0; + disabled_shadow_color_ = 0; + shadow_offset_.SetPoint(1, 1); + has_shadow_ = false; SetText(text); } diff --git a/ui/views/controls/label.h b/ui/views/controls/label.h index b64baf2..ab41bbdb 100644 --- a/ui/views/controls/label.h +++ b/ui/views/controls/label.h @@ -57,19 +57,19 @@ class VIEWS_EXPORT Label : public View { Label(const string16& text, const gfx::Font& font); virtual ~Label(); - // Set the font. + // Sets the font. virtual void SetFont(const gfx::Font& font); - // Set the label text. + // Sets the label text. void SetText(const string16& text); - // Set URL Value - text_ is set to spec(). + // Sets URL Value - text_ is set to spec(). void SetURL(const GURL& url); - // Return the font used by this label. + // Returns the font used by this label. gfx::Font font() const { return font_; } - // Return the label text. + // Returns the label text. string16 text() const { return text_; }; // Enables or disables auto-color-readability (enabled by default). If this @@ -78,18 +78,27 @@ class VIEWS_EXPORT Label : public View { // ensure that the foreground colors are readable over the background color. void SetAutoColorReadabilityEnabled(bool enabled); - // Set the color. This will automatically force the color to be readable + // Sets the color. This will automatically force the color to be readable // over the current background color. virtual void SetEnabledColor(const SkColor& color); void SetDisabledColor(const SkColor& color); SkColor enabled_color() const { return actual_enabled_color_; } - // Set the background color. This won't be explicitly drawn, but the label + // Sets the background color. This won't be explicitly drawn, but the label // will force the text color to be readable over it. void SetBackgroundColor(const SkColor& color); - // Set horizontal alignment. If the locale is RTL, and the directionality + // Enables a drop shadow underneath the text. + void SetShadowColors(SkColor enabled_color, SkColor disabled_color); + + // Sets the drop shadow's offset from the text. + void SetShadowOffset(int x, int y); + + // Disables shadows. + void ClearEmbellishing(); + + // Sets horizontal alignment. If the locale is RTL, and the directionality // mode is USE_UI_DIRECTIONALITY, the alignment is flipped around. // // Caveat: for labels originating from a web page, the directionality mode @@ -100,7 +109,7 @@ class VIEWS_EXPORT Label : public View { Alignment horizontal_alignment() const { return horiz_alignment_; } - // Set the directionality mode. The directionality mode is initialized to + // Sets the directionality mode. The directionality mode is initialized to // USE_UI_DIRECTIONALITY when the label is constructed. USE_UI_DIRECTIONALITY // applies to every label that originates from the Chrome UI. However, if the // label originates from a web page, its directionality is auto-detected. @@ -112,18 +121,18 @@ class VIEWS_EXPORT Label : public View { return directionality_mode_; } - // Set whether the label text can wrap on multiple lines. + // Sets whether the label text can wrap on multiple lines. // Default is false. void SetMultiLine(bool multi_line); - // Return whether the label text can wrap on multiple lines. + // Returns whether the label text can wrap on multiple lines. bool is_multi_line() const { return is_multi_line_; } - // Set whether the label text can be split on words. + // Sets whether the label text can be split on words. // Default is false. This only works when is_multi_line is true. void SetAllowCharacterBreak(bool allow_character_break); - // Set whether the label text should be elided in the middle (if necessary). + // Sets whether the label text should be elided in the middle (if necessary). // The default is to elide at the end. // NOTE: This is not supported for multi-line strings. void SetElideInMiddle(bool elide_in_middle); @@ -166,7 +175,7 @@ class VIEWS_EXPORT Label : public View { virtual int GetBaseline() const OVERRIDE; // Overridden to compute the size required to display this label. virtual gfx::Size GetPreferredSize() OVERRIDE; - // Return the height necessary to display this label with the provided width. + // Returns the height necessary to display this label with the provided width. // This method is used to layout multi-line labels. It is equivalent to // GetPreferredSize().height() if the receiver is not multi-line. virtual int GetHeightForWidth(int w) OVERRIDE; @@ -279,6 +288,17 @@ class VIEWS_EXPORT Label : public View { // might not have because it is not itself focusable. bool has_focus_border_; + // Colors for shadow. + SkColor enabled_shadow_color_; + SkColor disabled_shadow_color_; + + // Space between text and shadow. + gfx::Point shadow_offset_; + + // Should a shadow be drawn behind the text? + bool has_shadow_; + + DISALLOW_COPY_AND_ASSIGN(Label); }; |