Chromium Code Reviews| Index: ash/sticky_keys/sticky_keys_overlay.cc |
| diff --git a/ash/sticky_keys/sticky_keys_overlay.cc b/ash/sticky_keys/sticky_keys_overlay.cc |
| index 0766ba25ad2e7cdda2ac5ed875254de6622073e0..2751da6d2b1b2c593f06badf827ebe540c586172 100644 |
| --- a/ash/sticky_keys/sticky_keys_overlay.cc |
| +++ b/ash/sticky_keys/sticky_keys_overlay.cc |
| @@ -103,12 +103,16 @@ void StickyKeyOverlayLabel::SetKeyState(StickyKeyState state) { |
| // StickyKeysOverlayView |
| class StickyKeysOverlayView : public views::WidgetDelegateView { |
| public: |
| + // This object is not owned by the views hiearchy or by the widget. The |
| + // StickyKeysOverlay is the only class that should create and destroy this |
| + // view. |
| StickyKeysOverlayView(); |
| ~StickyKeysOverlayView() override; |
| // views::WidgetDelegateView overrides: |
| void OnPaint(gfx::Canvas* canvas) override; |
| + void DeleteDelegate() override; |
| void SetKeyState(ui::EventFlags modifier, StickyKeyState state); |
| @@ -127,6 +131,9 @@ class StickyKeysOverlayView : public views::WidgetDelegateView { |
| }; |
| StickyKeysOverlayView::StickyKeysOverlayView() { |
| + // The parent StickyKeysOverlay object owns this view. |
| + set_owned_by_client(); |
|
James Cook
2014/12/04 22:00:45
Doesn't the WidgetDelegateView constructor do this
Tim Song
2014/12/04 23:53:37
I just realized that there is no reason to inherit
|
| + |
| const gfx::Font& font = |
| ui::ResourceBundle::GetSharedInstance().GetFont(kKeyLabelFontStyle); |
| int font_size = font.GetFontSize(); |
| @@ -166,6 +173,10 @@ void StickyKeysOverlayView::OnPaint(gfx::Canvas* canvas) { |
| views::WidgetDelegateView::OnPaint(canvas); |
| } |
| +void StickyKeysOverlayView::DeleteDelegate() { |
| + // This view object is owned by StickyKeysOverlay, so no-op here. |
| +} |
| + |
| void StickyKeysOverlayView::SetKeyState(ui::EventFlags modifier, |
| StickyKeyState state) { |
| ModifierLabelMap::iterator it = modifier_label_map_.find(modifier); |
| @@ -215,14 +226,14 @@ StickyKeysOverlay::StickyKeysOverlay() |
| params.accept_events = false; |
| params.keep_on_top = true; |
| params.remove_standard_frame = true; |
| - params.delegate = overlay_view_; |
| + params.delegate = overlay_view_.get(); |
| params.bounds = CalculateOverlayBounds(); |
| params.parent = Shell::GetContainer(Shell::GetTargetRootWindow(), |
| kShellWindowId_OverlayContainer); |
| overlay_widget_.reset(new views::Widget); |
| overlay_widget_->Init(params); |
| overlay_widget_->SetVisibilityChangedAnimationsEnabled(false); |
| - overlay_widget_->SetContentsView(overlay_view_); |
| + overlay_widget_->SetContentsView(overlay_view_.get()); |
|
Jun Mukai
2014/12/04 21:58:54
Because overlay_view_ is a WidgetDelegateView, it
Tim Song
2014/12/04 23:53:37
Done. I stopped inheriting from WidgetDelegateView
|
| overlay_widget_->GetNativeView()->SetName("StickyKeysOverlay"); |
| } |
| @@ -279,6 +290,10 @@ StickyKeyState StickyKeysOverlay::GetModifierKeyState( |
| return overlay_view_->GetKeyState(modifier); |
| } |
| +views::Widget* StickyKeysOverlay::GetWidgetForTesting() { |
| + return overlay_widget_.get(); |
| +} |
| + |
| gfx::Rect StickyKeysOverlay::CalculateOverlayBounds() { |
| int x = is_visible_ ? kHorizontalOverlayOffset : -widget_size_.width(); |
| return gfx::Rect(gfx::Point(x, kVerticalOverlayOffset), widget_size_); |