Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: ash/sticky_keys/sticky_keys_overlay.cc

Issue 754763005: Speculative fix for sticky keys overlay crash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
112 113
113 void SetKeyState(ui::EventFlags modifier, StickyKeyState state); 114 void SetKeyState(ui::EventFlags modifier, StickyKeyState state);
114 115
115 StickyKeyState GetKeyState(ui::EventFlags modifier); 116 StickyKeyState GetKeyState(ui::EventFlags modifier);
116 117
117 void SetModifierVisible(ui::EventFlags modifier, bool visible); 118 void SetModifierVisible(ui::EventFlags modifier, bool visible);
118 bool GetModifierVisible(ui::EventFlags modifier); 119 bool GetModifierVisible(ui::EventFlags modifier);
119 120
120 private: 121 private:
121 void AddKeyLabel(ui::EventFlags modifier, const std::string& key_label); 122 void AddKeyLabel(ui::EventFlags modifier, const std::string& key_label);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 StickyKeysOverlayView::~StickyKeysOverlayView() {} 160 StickyKeysOverlayView::~StickyKeysOverlayView() {}
160 161
161 void StickyKeysOverlayView::OnPaint(gfx::Canvas* canvas) { 162 void StickyKeysOverlayView::OnPaint(gfx::Canvas* canvas) {
162 SkPaint paint; 163 SkPaint paint;
163 paint.setStyle(SkPaint::kFill_Style); 164 paint.setStyle(SkPaint::kFill_Style);
164 paint.setColor(SkColorSetARGB(0xB3, 0x55, 0x55, 0x55)); 165 paint.setColor(SkColorSetARGB(0xB3, 0x55, 0x55, 0x55));
165 canvas->DrawRoundRect(GetLocalBounds(), 2, paint); 166 canvas->DrawRoundRect(GetLocalBounds(), 2, paint);
166 views::WidgetDelegateView::OnPaint(canvas); 167 views::WidgetDelegateView::OnPaint(canvas);
167 } 168 }
168 169
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
169 void StickyKeysOverlayView::SetKeyState(ui::EventFlags modifier, 177 void StickyKeysOverlayView::SetKeyState(ui::EventFlags modifier,
170 StickyKeyState state) { 178 StickyKeyState state) {
171 ModifierLabelMap::iterator it = modifier_label_map_.find(modifier); 179 ModifierLabelMap::iterator it = modifier_label_map_.find(modifier);
172 DCHECK(it != modifier_label_map_.end()); 180 DCHECK(it != modifier_label_map_.end());
173 if (it != modifier_label_map_.end()) { 181 if (it != modifier_label_map_.end()) {
174 StickyKeyOverlayLabel* label = it->second; 182 StickyKeyOverlayLabel* label = it->second;
175 label->SetKeyState(state); 183 label->SetKeyState(state);
176 } 184 }
177 } 185 }
178 186
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 void StickyKeysOverlay::SetModifierKeyState(ui::EventFlags modifier, 280 void StickyKeysOverlay::SetModifierKeyState(ui::EventFlags modifier,
273 StickyKeyState state) { 281 StickyKeyState state) {
274 overlay_view_->SetKeyState(modifier, state); 282 overlay_view_->SetKeyState(modifier, state);
275 } 283 }
276 284
277 StickyKeyState StickyKeysOverlay::GetModifierKeyState( 285 StickyKeyState StickyKeysOverlay::GetModifierKeyState(
278 ui::EventFlags modifier) { 286 ui::EventFlags modifier) {
279 return overlay_view_->GetKeyState(modifier); 287 return overlay_view_->GetKeyState(modifier);
280 } 288 }
281 289
290 views::Widget* StickyKeysOverlay::GetWidgetForTesting() {
291 return overlay_widget_.get();
292 }
293
282 gfx::Rect StickyKeysOverlay::CalculateOverlayBounds() { 294 gfx::Rect StickyKeysOverlay::CalculateOverlayBounds() {
283 int x = is_visible_ ? kHorizontalOverlayOffset : -widget_size_.width(); 295 int x = is_visible_ ? kHorizontalOverlayOffset : -widget_size_.width();
284 return gfx::Rect(gfx::Point(x, kVerticalOverlayOffset), widget_size_); 296 return gfx::Rect(gfx::Point(x, kVerticalOverlayOffset), widget_size_);
285 } 297 }
286 298
287 void StickyKeysOverlay::OnLayerAnimationEnded( 299 void StickyKeysOverlay::OnLayerAnimationEnded(
288 ui::LayerAnimationSequence* sequence) { 300 ui::LayerAnimationSequence* sequence) {
289 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); 301 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator();
290 if (animator) 302 if (animator)
291 animator->RemoveObserver(this); 303 animator->RemoveObserver(this);
292 if (!is_visible_) 304 if (!is_visible_)
293 overlay_widget_->Hide(); 305 overlay_widget_->Hide();
294 } 306 }
295 307
296 void StickyKeysOverlay::OnLayerAnimationAborted( 308 void StickyKeysOverlay::OnLayerAnimationAborted(
297 ui::LayerAnimationSequence* sequence) { 309 ui::LayerAnimationSequence* sequence) {
298 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); 310 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator();
299 if (animator) 311 if (animator)
300 animator->RemoveObserver(this); 312 animator->RemoveObserver(this);
301 } 313 }
302 314
303 void StickyKeysOverlay::OnLayerAnimationScheduled( 315 void StickyKeysOverlay::OnLayerAnimationScheduled(
304 ui::LayerAnimationSequence* sequence) { 316 ui::LayerAnimationSequence* sequence) {
305 } 317 }
306 318
307 } // namespace ash 319 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698