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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 /////////////////////////////////////////////////////////////////////////////// | 102 /////////////////////////////////////////////////////////////////////////////// |
103 // StickyKeysOverlayView | 103 // StickyKeysOverlayView |
104 class StickyKeysOverlayView : public views::WidgetDelegateView { | 104 class StickyKeysOverlayView : public views::WidgetDelegateView { |
105 public: | 105 public: |
106 StickyKeysOverlayView(); | 106 StickyKeysOverlayView(); |
107 | 107 |
108 ~StickyKeysOverlayView() override; | 108 ~StickyKeysOverlayView() override; |
109 | 109 |
110 // views::WidgetDelegateView overrides: | 110 // views::WidgetDelegateView overrides: |
111 void OnPaint(gfx::Canvas* canvas) override; | 111 void OnPaint(gfx::Canvas* canvas) override; |
112 void DeleteDelegate() override; | |
113 | 112 |
114 void SetKeyState(ui::EventFlags modifier, StickyKeyState state); | 113 void SetKeyState(ui::EventFlags modifier, StickyKeyState state); |
115 | 114 |
116 StickyKeyState GetKeyState(ui::EventFlags modifier); | 115 StickyKeyState GetKeyState(ui::EventFlags modifier); |
117 | 116 |
118 void SetModifierVisible(ui::EventFlags modifier, bool visible); | 117 void SetModifierVisible(ui::EventFlags modifier, bool visible); |
119 bool GetModifierVisible(ui::EventFlags modifier); | 118 bool GetModifierVisible(ui::EventFlags modifier); |
120 | 119 |
121 private: | 120 private: |
122 void AddKeyLabel(ui::EventFlags modifier, const std::string& key_label); | 121 void AddKeyLabel(ui::EventFlags modifier, const std::string& key_label); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 StickyKeysOverlayView::~StickyKeysOverlayView() {} | 159 StickyKeysOverlayView::~StickyKeysOverlayView() {} |
161 | 160 |
162 void StickyKeysOverlayView::OnPaint(gfx::Canvas* canvas) { | 161 void StickyKeysOverlayView::OnPaint(gfx::Canvas* canvas) { |
163 SkPaint paint; | 162 SkPaint paint; |
164 paint.setStyle(SkPaint::kFill_Style); | 163 paint.setStyle(SkPaint::kFill_Style); |
165 paint.setColor(SkColorSetARGB(0xB3, 0x55, 0x55, 0x55)); | 164 paint.setColor(SkColorSetARGB(0xB3, 0x55, 0x55, 0x55)); |
166 canvas->DrawRoundRect(GetLocalBounds(), 2, paint); | 165 canvas->DrawRoundRect(GetLocalBounds(), 2, paint); |
167 views::WidgetDelegateView::OnPaint(canvas); | 166 views::WidgetDelegateView::OnPaint(canvas); |
168 } | 167 } |
169 | 168 |
170 void StickyKeysOverlayView::DeleteDelegate() { | |
171 // The ownership of a WidgetDelegateView is kind of tricky. It has the | |
172 // lifetime semantics of both a View and a WidgetDelegate. We should just rely | |
173 // on the Views semantics and do nothing here. This object will be deleted | |
174 // when the parent widget is deleted. | |
175 } | |
176 | |
177 void StickyKeysOverlayView::SetKeyState(ui::EventFlags modifier, | 169 void StickyKeysOverlayView::SetKeyState(ui::EventFlags modifier, |
178 StickyKeyState state) { | 170 StickyKeyState state) { |
179 ModifierLabelMap::iterator it = modifier_label_map_.find(modifier); | 171 ModifierLabelMap::iterator it = modifier_label_map_.find(modifier); |
180 DCHECK(it != modifier_label_map_.end()); | 172 DCHECK(it != modifier_label_map_.end()); |
181 if (it != modifier_label_map_.end()) { | 173 if (it != modifier_label_map_.end()) { |
182 StickyKeyOverlayLabel* label = it->second; | 174 StickyKeyOverlayLabel* label = it->second; |
183 label->SetKeyState(state); | 175 label->SetKeyState(state); |
184 } | 176 } |
185 } | 177 } |
186 | 178 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 void StickyKeysOverlay::SetModifierKeyState(ui::EventFlags modifier, | 272 void StickyKeysOverlay::SetModifierKeyState(ui::EventFlags modifier, |
281 StickyKeyState state) { | 273 StickyKeyState state) { |
282 overlay_view_->SetKeyState(modifier, state); | 274 overlay_view_->SetKeyState(modifier, state); |
283 } | 275 } |
284 | 276 |
285 StickyKeyState StickyKeysOverlay::GetModifierKeyState( | 277 StickyKeyState StickyKeysOverlay::GetModifierKeyState( |
286 ui::EventFlags modifier) { | 278 ui::EventFlags modifier) { |
287 return overlay_view_->GetKeyState(modifier); | 279 return overlay_view_->GetKeyState(modifier); |
288 } | 280 } |
289 | 281 |
290 views::Widget* StickyKeysOverlay::GetWidgetForTesting() { | |
291 return overlay_widget_.get(); | |
292 } | |
293 | |
294 gfx::Rect StickyKeysOverlay::CalculateOverlayBounds() { | 282 gfx::Rect StickyKeysOverlay::CalculateOverlayBounds() { |
295 int x = is_visible_ ? kHorizontalOverlayOffset : -widget_size_.width(); | 283 int x = is_visible_ ? kHorizontalOverlayOffset : -widget_size_.width(); |
296 return gfx::Rect(gfx::Point(x, kVerticalOverlayOffset), widget_size_); | 284 return gfx::Rect(gfx::Point(x, kVerticalOverlayOffset), widget_size_); |
297 } | 285 } |
298 | 286 |
299 void StickyKeysOverlay::OnLayerAnimationEnded( | 287 void StickyKeysOverlay::OnLayerAnimationEnded( |
300 ui::LayerAnimationSequence* sequence) { | 288 ui::LayerAnimationSequence* sequence) { |
301 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 289 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
302 if (animator) | 290 if (animator) |
303 animator->RemoveObserver(this); | 291 animator->RemoveObserver(this); |
304 if (!is_visible_) | 292 if (!is_visible_) |
305 overlay_widget_->Hide(); | 293 overlay_widget_->Hide(); |
306 } | 294 } |
307 | 295 |
308 void StickyKeysOverlay::OnLayerAnimationAborted( | 296 void StickyKeysOverlay::OnLayerAnimationAborted( |
309 ui::LayerAnimationSequence* sequence) { | 297 ui::LayerAnimationSequence* sequence) { |
310 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 298 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
311 if (animator) | 299 if (animator) |
312 animator->RemoveObserver(this); | 300 animator->RemoveObserver(this); |
313 } | 301 } |
314 | 302 |
315 void StickyKeysOverlay::OnLayerAnimationScheduled( | 303 void StickyKeysOverlay::OnLayerAnimationScheduled( |
316 ui::LayerAnimationSequence* sequence) { | 304 ui::LayerAnimationSequence* sequence) { |
317 } | 305 } |
318 | 306 |
319 } // namespace ash | 307 } // namespace ash |
OLD | NEW |