| 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/common/shell_window_ids.h" | 7 #include "ash/common/shell_window_ids.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 // Vertical offset of the overlay from the top left of the screen. | 32 // Vertical offset of the overlay from the top left of the screen. |
| 33 const int kVerticalOverlayOffset = 18; | 33 const int kVerticalOverlayOffset = 18; |
| 34 | 34 |
| 35 // Font style used for modifier key labels. | 35 // Font style used for modifier key labels. |
| 36 const ui::ResourceBundle::FontStyle kKeyLabelFontStyle = | 36 const ui::ResourceBundle::FontStyle kKeyLabelFontStyle = |
| 37 ui::ResourceBundle::LargeFont; | 37 ui::ResourceBundle::LargeFont; |
| 38 | 38 |
| 39 // Duration of slide animation when overlay is shown or hidden. | 39 // Duration of slide animation when overlay is shown or hidden. |
| 40 const int kSlideAnimationDurationMs = 100; | 40 const int kSlideAnimationDurationMs = 100; |
| 41 | |
| 42 } | 41 } |
| 43 | 42 |
| 44 /////////////////////////////////////////////////////////////////////////////// | 43 /////////////////////////////////////////////////////////////////////////////// |
| 45 // StickyKeyOverlayLabel | 44 // StickyKeyOverlayLabel |
| 46 class StickyKeyOverlayLabel : public views::Label { | 45 class StickyKeyOverlayLabel : public views::Label { |
| 47 public: | 46 public: |
| 48 explicit StickyKeyOverlayLabel(const std::string& key_name); | 47 explicit StickyKeyOverlayLabel(const std::string& key_name); |
| 49 | 48 |
| 50 ~StickyKeyOverlayLabel() override; | 49 ~StickyKeyOverlayLabel() override; |
| 51 | 50 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 65 | 64 |
| 66 SetText(base::UTF8ToUTF16(key_name)); | 65 SetText(base::UTF8ToUTF16(key_name)); |
| 67 SetHorizontalAlignment(gfx::ALIGN_LEFT); | 66 SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 68 SetFontList(rb->GetFontList(kKeyLabelFontStyle)); | 67 SetFontList(rb->GetFontList(kKeyLabelFontStyle)); |
| 69 SetAutoColorReadabilityEnabled(false); | 68 SetAutoColorReadabilityEnabled(false); |
| 70 SetEnabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); | 69 SetEnabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); |
| 71 SetDisabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); | 70 SetDisabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); |
| 72 SetSubpixelRenderingEnabled(false); | 71 SetSubpixelRenderingEnabled(false); |
| 73 } | 72 } |
| 74 | 73 |
| 75 StickyKeyOverlayLabel::~StickyKeyOverlayLabel() { | 74 StickyKeyOverlayLabel::~StickyKeyOverlayLabel() {} |
| 76 } | |
| 77 | 75 |
| 78 void StickyKeyOverlayLabel::SetKeyState(StickyKeyState state) { | 76 void StickyKeyOverlayLabel::SetKeyState(StickyKeyState state) { |
| 79 state_ = state; | 77 state_ = state; |
| 80 SkColor label_color; | 78 SkColor label_color; |
| 81 int style; | 79 int style; |
| 82 switch (state) { | 80 switch (state) { |
| 83 case STICKY_KEY_STATE_ENABLED: | 81 case STICKY_KEY_STATE_ENABLED: |
| 84 style = gfx::Font::NORMAL; | 82 style = gfx::Font::NORMAL; |
| 85 label_color = SkColorSetA(enabled_color(), 0xFF); | 83 label_color = SkColorSetA(enabled_color(), 0xFF); |
| 86 break; | 84 break; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 int font_size = font.GetFontSize(); | 135 int font_size = font.GetFontSize(); |
| 138 int font_padding = font.GetHeight() - font.GetBaseline(); | 136 int font_padding = font.GetHeight() - font.GetBaseline(); |
| 139 | 137 |
| 140 // Text should have a margin of 0.5 times the font size on each side, so | 138 // Text should have a margin of 0.5 times the font size on each side, so |
| 141 // the spacing between two labels will be the same as the font size. | 139 // the spacing between two labels will be the same as the font size. |
| 142 int horizontal_spacing = font_size / 2; | 140 int horizontal_spacing = font_size / 2; |
| 143 int vertical_spacing = font_size / 2 - font_padding; | 141 int vertical_spacing = font_size / 2 - font_padding; |
| 144 int child_spacing = font_size - 2 * font_padding; | 142 int child_spacing = font_size - 2 * font_padding; |
| 145 | 143 |
| 146 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, | 144 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, |
| 147 horizontal_spacing, | 145 horizontal_spacing, vertical_spacing, |
| 148 vertical_spacing, | |
| 149 child_spacing)); | 146 child_spacing)); |
| 150 AddKeyLabel(ui::EF_CONTROL_DOWN, | 147 AddKeyLabel(ui::EF_CONTROL_DOWN, |
| 151 l10n_util::GetStringUTF8(IDS_ASH_CONTROL_KEY)); | 148 l10n_util::GetStringUTF8(IDS_ASH_CONTROL_KEY)); |
| 152 AddKeyLabel(ui::EF_ALT_DOWN, | 149 AddKeyLabel(ui::EF_ALT_DOWN, l10n_util::GetStringUTF8(IDS_ASH_ALT_KEY)); |
| 153 l10n_util::GetStringUTF8(IDS_ASH_ALT_KEY)); | 150 AddKeyLabel(ui::EF_SHIFT_DOWN, l10n_util::GetStringUTF8(IDS_ASH_SHIFT_KEY)); |
| 154 AddKeyLabel(ui::EF_SHIFT_DOWN, | |
| 155 l10n_util::GetStringUTF8(IDS_ASH_SHIFT_KEY)); | |
| 156 AddKeyLabel(ui::EF_COMMAND_DOWN, | 151 AddKeyLabel(ui::EF_COMMAND_DOWN, |
| 157 l10n_util::GetStringUTF8(IDS_ASH_SEARCH_KEY)); | 152 l10n_util::GetStringUTF8(IDS_ASH_SEARCH_KEY)); |
| 158 AddKeyLabel(ui::EF_ALTGR_DOWN, | 153 AddKeyLabel(ui::EF_ALTGR_DOWN, l10n_util::GetStringUTF8(IDS_ASH_ALTGR_KEY)); |
| 159 l10n_util::GetStringUTF8(IDS_ASH_ALTGR_KEY)); | 154 AddKeyLabel(ui::EF_MOD3_DOWN, l10n_util::GetStringUTF8(IDS_ASH_MOD3_KEY)); |
| 160 AddKeyLabel(ui::EF_MOD3_DOWN, | |
| 161 l10n_util::GetStringUTF8(IDS_ASH_MOD3_KEY)); | |
| 162 } | 155 } |
| 163 | 156 |
| 164 StickyKeysOverlayView::~StickyKeysOverlayView() {} | 157 StickyKeysOverlayView::~StickyKeysOverlayView() {} |
| 165 | 158 |
| 166 void StickyKeysOverlayView::OnPaint(gfx::Canvas* canvas) { | 159 void StickyKeysOverlayView::OnPaint(gfx::Canvas* canvas) { |
| 167 SkPaint paint; | 160 SkPaint paint; |
| 168 paint.setStyle(SkPaint::kFill_Style); | 161 paint.setStyle(SkPaint::kFill_Style); |
| 169 paint.setColor(SkColorSetARGB(0xB3, 0x55, 0x55, 0x55)); | 162 paint.setColor(SkColorSetARGB(0xB3, 0x55, 0x55, 0x55)); |
| 170 canvas->DrawRoundRect(GetLocalBounds(), 2, paint); | 163 canvas->DrawRoundRect(GetLocalBounds(), 2, paint); |
| 171 views::View::OnPaint(canvas); | 164 views::View::OnPaint(canvas); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 273 |
| 281 bool StickyKeysOverlay::GetModifierVisible(ui::EventFlags modifier) { | 274 bool StickyKeysOverlay::GetModifierVisible(ui::EventFlags modifier) { |
| 282 return overlay_view_->GetModifierVisible(modifier); | 275 return overlay_view_->GetModifierVisible(modifier); |
| 283 } | 276 } |
| 284 | 277 |
| 285 void StickyKeysOverlay::SetModifierKeyState(ui::EventFlags modifier, | 278 void StickyKeysOverlay::SetModifierKeyState(ui::EventFlags modifier, |
| 286 StickyKeyState state) { | 279 StickyKeyState state) { |
| 287 overlay_view_->SetKeyState(modifier, state); | 280 overlay_view_->SetKeyState(modifier, state); |
| 288 } | 281 } |
| 289 | 282 |
| 290 StickyKeyState StickyKeysOverlay::GetModifierKeyState( | 283 StickyKeyState StickyKeysOverlay::GetModifierKeyState(ui::EventFlags modifier) { |
| 291 ui::EventFlags modifier) { | |
| 292 return overlay_view_->GetKeyState(modifier); | 284 return overlay_view_->GetKeyState(modifier); |
| 293 } | 285 } |
| 294 | 286 |
| 295 views::Widget* StickyKeysOverlay::GetWidgetForTesting() { | 287 views::Widget* StickyKeysOverlay::GetWidgetForTesting() { |
| 296 return overlay_widget_.get(); | 288 return overlay_widget_.get(); |
| 297 } | 289 } |
| 298 | 290 |
| 299 gfx::Rect StickyKeysOverlay::CalculateOverlayBounds() { | 291 gfx::Rect StickyKeysOverlay::CalculateOverlayBounds() { |
| 300 int x = is_visible_ ? kHorizontalOverlayOffset : -widget_size_.width(); | 292 int x = is_visible_ ? kHorizontalOverlayOffset : -widget_size_.width(); |
| 301 return gfx::Rect(gfx::Point(x, kVerticalOverlayOffset), widget_size_); | 293 return gfx::Rect(gfx::Point(x, kVerticalOverlayOffset), widget_size_); |
| 302 } | 294 } |
| 303 | 295 |
| 304 void StickyKeysOverlay::OnLayerAnimationEnded( | 296 void StickyKeysOverlay::OnLayerAnimationEnded( |
| 305 ui::LayerAnimationSequence* sequence) { | 297 ui::LayerAnimationSequence* sequence) { |
| 306 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 298 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| 307 if (animator) | 299 if (animator) |
| 308 animator->RemoveObserver(this); | 300 animator->RemoveObserver(this); |
| 309 if (!is_visible_) | 301 if (!is_visible_) |
| 310 overlay_widget_->Hide(); | 302 overlay_widget_->Hide(); |
| 311 } | 303 } |
| 312 | 304 |
| 313 void StickyKeysOverlay::OnLayerAnimationAborted( | 305 void StickyKeysOverlay::OnLayerAnimationAborted( |
| 314 ui::LayerAnimationSequence* sequence) { | 306 ui::LayerAnimationSequence* sequence) { |
| 315 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 307 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| 316 if (animator) | 308 if (animator) |
| 317 animator->RemoveObserver(this); | 309 animator->RemoveObserver(this); |
| 318 } | 310 } |
| 319 | 311 |
| 320 void StickyKeysOverlay::OnLayerAnimationScheduled( | 312 void StickyKeysOverlay::OnLayerAnimationScheduled( |
| 321 ui::LayerAnimationSequence* sequence) { | 313 ui::LayerAnimationSequence* sequence) {} |
| 322 } | |
| 323 | 314 |
| 324 } // namespace ash | 315 } // namespace ash |
| OLD | NEW |