| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/sticky_keys/sticky_keys_overlay.h" | 5 #include "ash/sticky_keys/sticky_keys_overlay.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/sticky_keys/sticky_keys_controller.h" | 9 #include "ash/sticky_keys/sticky_keys_controller.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 public: | 47 public: |
| 48 explicit StickyKeyOverlayLabel(const std::string& key_name); | 48 explicit StickyKeyOverlayLabel(const std::string& key_name); |
| 49 | 49 |
| 50 virtual ~StickyKeyOverlayLabel(); | 50 virtual ~StickyKeyOverlayLabel(); |
| 51 | 51 |
| 52 StickyKeyState state() const { return state_; } | 52 StickyKeyState state() const { return state_; } |
| 53 | 53 |
| 54 void SetKeyState(StickyKeyState state); | 54 void SetKeyState(StickyKeyState state); |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 // views::Label overrides: | |
| 58 virtual void PaintText(gfx::Canvas* canvas, | |
| 59 const base::string16& text, | |
| 60 const gfx::Rect& text_bounds, | |
| 61 int flags) OVERRIDE; | |
| 62 | |
| 63 StickyKeyState state_; | 57 StickyKeyState state_; |
| 64 | 58 |
| 65 DISALLOW_COPY_AND_ASSIGN(StickyKeyOverlayLabel); | 59 DISALLOW_COPY_AND_ASSIGN(StickyKeyOverlayLabel); |
| 66 }; | 60 }; |
| 67 | 61 |
| 68 StickyKeyOverlayLabel::StickyKeyOverlayLabel(const std::string& key_name) | 62 StickyKeyOverlayLabel::StickyKeyOverlayLabel(const std::string& key_name) |
| 69 : state_(STICKY_KEY_STATE_DISABLED) { | 63 : state_(STICKY_KEY_STATE_DISABLED) { |
| 70 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 64 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 71 | 65 |
| 72 SetText(base::UTF8ToUTF16(key_name)); | 66 SetText(base::UTF8ToUTF16(key_name)); |
| 73 SetHorizontalAlignment(gfx::ALIGN_LEFT); | 67 SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 74 SetFontList(rb->GetFontList(kKeyLabelFontStyle)); | 68 SetFontList(rb->GetFontList(kKeyLabelFontStyle)); |
| 75 SetAutoColorReadabilityEnabled(false); | 69 SetAutoColorReadabilityEnabled(false); |
| 76 SetFocusable(false); | 70 SetFocusable(false); |
| 77 SetEnabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); | 71 SetEnabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); |
| 78 SetDisabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); | 72 SetDisabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); |
| 73 // Use a transparent background color to avoid subpixel rendering. |
| 74 SetBackgroundColor(SK_ColorTRANSPARENT); |
| 79 } | 75 } |
| 80 | 76 |
| 81 StickyKeyOverlayLabel::~StickyKeyOverlayLabel() { | 77 StickyKeyOverlayLabel::~StickyKeyOverlayLabel() { |
| 82 } | 78 } |
| 83 | 79 |
| 84 void StickyKeyOverlayLabel::SetKeyState(StickyKeyState state) { | 80 void StickyKeyOverlayLabel::SetKeyState(StickyKeyState state) { |
| 85 state_ = state; | 81 state_ = state; |
| 86 SkColor label_color; | 82 SkColor label_color; |
| 87 int style; | 83 int style; |
| 88 switch (state) { | 84 switch (state) { |
| 89 case STICKY_KEY_STATE_ENABLED: | 85 case STICKY_KEY_STATE_ENABLED: |
| 90 style = gfx::Font::NORMAL; | 86 style = gfx::Font::NORMAL; |
| 91 label_color = SkColorSetA(enabled_color(), 0xFF); | 87 label_color = SkColorSetA(enabled_color(), 0xFF); |
| 92 break; | 88 break; |
| 93 case STICKY_KEY_STATE_LOCKED: | 89 case STICKY_KEY_STATE_LOCKED: |
| 94 style = gfx::Font::UNDERLINE; | 90 style = gfx::Font::UNDERLINE; |
| 95 label_color = SkColorSetA(enabled_color(), 0xFF); | 91 label_color = SkColorSetA(enabled_color(), 0xFF); |
| 96 break; | 92 break; |
| 97 default: | 93 default: |
| 98 style = gfx::Font::NORMAL; | 94 style = gfx::Font::NORMAL; |
| 99 label_color = SkColorSetA(enabled_color(), 0x80); | 95 label_color = SkColorSetA(enabled_color(), 0x80); |
| 100 } | 96 } |
| 101 | 97 |
| 102 SetEnabledColor(label_color); | 98 SetEnabledColor(label_color); |
| 103 SetDisabledColor(label_color); | 99 SetDisabledColor(label_color); |
| 104 SetFontList(font_list().DeriveWithStyle(style)); | 100 SetFontList(font_list().DeriveWithStyle(style)); |
| 105 } | 101 } |
| 106 | 102 |
| 107 void StickyKeyOverlayLabel::PaintText(gfx::Canvas* canvas, | |
| 108 const base::string16& text, | |
| 109 const gfx::Rect& text_bounds, | |
| 110 int flags) { | |
| 111 views::Label::PaintText(canvas, | |
| 112 text, | |
| 113 text_bounds, | |
| 114 flags | gfx::Canvas::NO_SUBPIXEL_RENDERING); | |
| 115 } | |
| 116 | |
| 117 | |
| 118 /////////////////////////////////////////////////////////////////////////////// | 103 /////////////////////////////////////////////////////////////////////////////// |
| 119 // StickyKeyOverlayLabel | 104 // StickyKeysOverlayView |
| 120 class StickyKeysOverlayView : public views::WidgetDelegateView { | 105 class StickyKeysOverlayView : public views::WidgetDelegateView { |
| 121 public: | 106 public: |
| 122 StickyKeysOverlayView(); | 107 StickyKeysOverlayView(); |
| 123 | 108 |
| 124 virtual ~StickyKeysOverlayView(); | 109 virtual ~StickyKeysOverlayView(); |
| 125 | 110 |
| 126 // views::WidgetDelegateView overrides: | 111 // views::WidgetDelegateView overrides: |
| 127 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 112 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 128 | 113 |
| 129 void SetKeyState(ui::EventFlags modifier, StickyKeyState state); | 114 void SetKeyState(ui::EventFlags modifier, StickyKeyState state); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 297 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| 313 if (animator) | 298 if (animator) |
| 314 animator->RemoveObserver(this); | 299 animator->RemoveObserver(this); |
| 315 } | 300 } |
| 316 | 301 |
| 317 void StickyKeysOverlay::OnLayerAnimationScheduled( | 302 void StickyKeysOverlay::OnLayerAnimationScheduled( |
| 318 ui::LayerAnimationSequence* sequence) { | 303 ui::LayerAnimationSequence* sequence) { |
| 319 } | 304 } |
| 320 | 305 |
| 321 } // namespace ash | 306 } // namespace ash |
| OLD | NEW |