OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/aura/wm_shelf_aura.h" | 5 #include "ash/aura/wm_shelf_aura.h" |
6 | 6 |
7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
8 #include "ash/common/shelf/wm_shelf_observer.h" | 8 #include "ash/common/shelf/wm_shelf_observer.h" |
9 #include "ash/common/wm_window.h" | 9 #include "ash/common/wm_window.h" |
10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
12 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
13 | 13 |
14 namespace ash { | 14 namespace ash { |
15 | 15 |
16 WmShelfAura::WmShelfAura(Shelf* shelf) | 16 WmShelfAura::WmShelfAura() {} |
17 : shelf_(shelf), shelf_layout_manager_(shelf->shelf_layout_manager()) { | 17 |
| 18 WmShelfAura::~WmShelfAura() {} |
| 19 |
| 20 void WmShelfAura::SetShelfLayoutManager( |
| 21 ShelfLayoutManager* shelf_layout_manager) { |
| 22 DCHECK(!shelf_layout_manager_); |
| 23 shelf_layout_manager_ = shelf_layout_manager; |
18 shelf_layout_manager_->AddObserver(this); | 24 shelf_layout_manager_->AddObserver(this); |
| 25 } |
| 26 |
| 27 void WmShelfAura::SetShelf(Shelf* shelf) { |
| 28 DCHECK(!shelf_); |
| 29 shelf_ = shelf; |
19 shelf_->AddIconObserver(this); | 30 shelf_->AddIconObserver(this); |
20 } | 31 } |
21 | 32 |
22 WmShelfAura::~WmShelfAura() { | 33 void WmShelfAura::Shutdown() { |
23 shelf_->RemoveIconObserver(this); | 34 if (shelf_) { |
24 if (shelf_layout_manager_) | 35 shelf_->RemoveIconObserver(this); |
25 shelf_layout_manager_->RemoveObserver(this); | 36 shelf_ = nullptr; |
| 37 } |
| 38 |
| 39 ResetShelfLayoutManager(); |
26 } | 40 } |
27 | 41 |
28 // static | 42 // static |
29 Shelf* WmShelfAura::GetShelf(WmShelf* shelf) { | 43 Shelf* WmShelfAura::GetShelf(WmShelf* shelf) { |
30 return static_cast<WmShelfAura*>(shelf)->shelf_; | 44 return static_cast<WmShelfAura*>(shelf)->shelf_; |
31 } | 45 } |
32 | 46 |
| 47 void WmShelfAura::ResetShelfLayoutManager() { |
| 48 if (!shelf_layout_manager_) |
| 49 return; |
| 50 shelf_layout_manager_->RemoveObserver(this); |
| 51 shelf_layout_manager_ = nullptr; |
| 52 } |
| 53 |
33 WmWindow* WmShelfAura::GetWindow() { | 54 WmWindow* WmShelfAura::GetWindow() { |
34 return WmWindowAura::Get(shelf_->shelf_widget()->GetNativeView()); | 55 return WmWindowAura::Get(shelf_->shelf_widget()->GetNativeView()); |
35 } | 56 } |
36 | 57 |
37 ShelfAlignment WmShelfAura::GetAlignment() const { | 58 ShelfAlignment WmShelfAura::GetAlignment() const { |
38 return shelf_->alignment(); | 59 return shelf_->alignment(); |
39 } | 60 } |
40 | 61 |
41 ShelfBackgroundType WmShelfAura::GetBackgroundType() const { | 62 ShelfBackgroundType WmShelfAura::GetBackgroundType() const { |
42 return shelf_->shelf_widget()->GetBackgroundType(); | 63 return shelf_->shelf_widget()->GetBackgroundType(); |
(...skipping 19 matching lines...) Expand all Loading... |
62 | 83 |
63 void WmShelfAura::AddObserver(WmShelfObserver* observer) { | 84 void WmShelfAura::AddObserver(WmShelfObserver* observer) { |
64 observers_.AddObserver(observer); | 85 observers_.AddObserver(observer); |
65 } | 86 } |
66 | 87 |
67 void WmShelfAura::RemoveObserver(WmShelfObserver* observer) { | 88 void WmShelfAura::RemoveObserver(WmShelfObserver* observer) { |
68 observers_.RemoveObserver(observer); | 89 observers_.RemoveObserver(observer); |
69 } | 90 } |
70 | 91 |
71 void WmShelfAura::WillDeleteShelfLayoutManager() { | 92 void WmShelfAura::WillDeleteShelfLayoutManager() { |
72 shelf_layout_manager_->RemoveObserver(this); | 93 ResetShelfLayoutManager(); |
73 shelf_layout_manager_ = nullptr; | |
74 } | 94 } |
75 | 95 |
76 void WmShelfAura::OnBackgroundUpdated( | 96 void WmShelfAura::OnBackgroundUpdated( |
77 ShelfBackgroundType background_type, | 97 ShelfBackgroundType background_type, |
78 BackgroundAnimatorChangeType change_type) { | 98 BackgroundAnimatorChangeType change_type) { |
79 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 99 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
80 OnBackgroundUpdated(background_type, change_type)); | 100 OnBackgroundUpdated(background_type, change_type)); |
81 } | 101 } |
82 | 102 |
83 void WmShelfAura::WillChangeVisibilityState(ShelfVisibilityState new_state) { | 103 void WmShelfAura::WillChangeVisibilityState(ShelfVisibilityState new_state) { |
84 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 104 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
85 WillChangeVisibilityState(new_state)); | 105 WillChangeVisibilityState(new_state)); |
86 } | 106 } |
87 | 107 |
88 void WmShelfAura::OnShelfIconPositionsChanged() { | 108 void WmShelfAura::OnShelfIconPositionsChanged() { |
89 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged()); | 109 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged()); |
90 } | 110 } |
91 | 111 |
92 } // namespace ash | 112 } // namespace ash |
OLD | NEW |