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/common/shelf/shelf.h" | 5 #include "ash/common/shelf/shelf.h" |
| 6 #include "ash/common/shelf/shelf_delegate.h" |
6 #include "ash/common/shelf/shelf_layout_manager.h" | 7 #include "ash/common/shelf/shelf_layout_manager.h" |
| 8 #include "ash/common/shelf/shelf_locking_manager.h" |
| 9 #include "ash/common/shelf/shelf_widget.h" |
7 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
8 #include "ash/common/shelf/wm_shelf_observer.h" | 11 #include "ash/common/shelf/wm_shelf_observer.h" |
9 #include "ash/common/wm_lookup.h" | 12 #include "ash/common/wm_lookup.h" |
| 13 #include "ash/common/wm_shell.h" |
| 14 #include "ash/common/wm_window.h" |
10 #include "base/logging.h" | 15 #include "base/logging.h" |
11 | 16 |
12 namespace ash { | 17 namespace ash { |
13 | 18 |
14 void WmShelf::SetShelf(Shelf* shelf) { | 19 void WmShelf::SetShelf(Shelf* shelf) { |
15 DCHECK(!shelf_); | 20 DCHECK(!shelf_); |
16 DCHECK(shelf); | 21 DCHECK(shelf); |
17 shelf_ = shelf; | 22 shelf_ = shelf; |
| 23 DCHECK(shelf_layout_manager_); |
| 24 shelf_locking_manager_.reset(new ShelfLockingManager(this)); |
| 25 // When the shelf is created the alignment is unlocked. Chrome will update the |
| 26 // alignment later from preferences. |
| 27 alignment_ = SHELF_ALIGNMENT_BOTTOM; |
18 } | 28 } |
19 | 29 |
20 void WmShelf::ClearShelf() { | 30 void WmShelf::ClearShelf() { |
21 DCHECK(shelf_); | 31 DCHECK(shelf_); |
| 32 shelf_locking_manager_.reset(); |
22 shelf_ = nullptr; | 33 shelf_ = nullptr; |
23 } | 34 } |
24 | 35 |
25 void WmShelf::SetShelfLayoutManager(ShelfLayoutManager* manager) { | 36 void WmShelf::SetShelfLayoutManager(ShelfLayoutManager* manager) { |
26 DCHECK(!shelf_layout_manager_); | 37 DCHECK(!shelf_layout_manager_); |
27 DCHECK(manager); | 38 DCHECK(manager); |
28 shelf_layout_manager_ = manager; | 39 shelf_layout_manager_ = manager; |
29 shelf_layout_manager_->AddObserver(this); | 40 shelf_layout_manager_->AddObserver(this); |
30 } | 41 } |
31 | 42 |
32 WmWindow* WmShelf::GetWindow() { | 43 WmWindow* WmShelf::GetWindow() { |
33 // Use |shelf_layout_manager_| to access ShelfWidget because it is set before | 44 // Use |shelf_layout_manager_| to access ShelfWidget because it is set before |
34 // before the Shelf instance is available. | 45 // before the Shelf instance is available. |
35 return WmLookup::Get()->GetWindowForWidget( | 46 return WmLookup::Get()->GetWindowForWidget( |
36 shelf_layout_manager_->shelf_widget()); | 47 shelf_layout_manager_->shelf_widget()); |
37 } | 48 } |
38 | 49 |
39 ShelfAlignment WmShelf::GetAlignment() const { | 50 void WmShelf::SetAlignment(ShelfAlignment alignment) { |
40 return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED; | 51 DCHECK(shelf_layout_manager_); |
41 } | |
42 | 52 |
43 void WmShelf::SetAlignment(ShelfAlignment alignment) { | 53 if (alignment_ == alignment) |
44 shelf_->SetAlignment(alignment); | 54 return; |
| 55 |
| 56 if (shelf_locking_manager_->is_locked() && |
| 57 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { |
| 58 shelf_locking_manager_->set_stored_alignment(alignment); |
| 59 return; |
| 60 } |
| 61 |
| 62 alignment_ = alignment; |
| 63 // The ShelfWidget notifies the ShelfView of the alignment change. |
| 64 shelf_layout_manager_->shelf_widget()->OnShelfAlignmentChanged(); |
| 65 WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(shelf_); |
| 66 WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); |
| 67 // ShelfLayoutManager will resize the shelf. |
45 } | 68 } |
46 | 69 |
47 bool WmShelf::IsHorizontalAlignment() const { | 70 bool WmShelf::IsHorizontalAlignment() const { |
48 switch (GetAlignment()) { | 71 switch (alignment_) { |
49 case SHELF_ALIGNMENT_BOTTOM: | 72 case SHELF_ALIGNMENT_BOTTOM: |
50 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 73 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
51 return true; | 74 return true; |
52 case SHELF_ALIGNMENT_LEFT: | 75 case SHELF_ALIGNMENT_LEFT: |
53 case SHELF_ALIGNMENT_RIGHT: | 76 case SHELF_ALIGNMENT_RIGHT: |
54 return false; | 77 return false; |
55 } | 78 } |
56 NOTREACHED(); | 79 NOTREACHED(); |
57 return true; | 80 return true; |
58 } | 81 } |
59 | 82 |
60 int WmShelf::SelectValueForShelfAlignment(int bottom, | 83 int WmShelf::SelectValueForShelfAlignment(int bottom, |
61 int left, | 84 int left, |
62 int right) const { | 85 int right) const { |
63 switch (GetAlignment()) { | 86 switch (alignment_) { |
64 case SHELF_ALIGNMENT_BOTTOM: | 87 case SHELF_ALIGNMENT_BOTTOM: |
65 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 88 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
66 return bottom; | 89 return bottom; |
67 case SHELF_ALIGNMENT_LEFT: | 90 case SHELF_ALIGNMENT_LEFT: |
68 return left; | 91 return left; |
69 case SHELF_ALIGNMENT_RIGHT: | 92 case SHELF_ALIGNMENT_RIGHT: |
70 return right; | 93 return right; |
71 } | 94 } |
72 NOTREACHED(); | 95 NOTREACHED(); |
73 return bottom; | 96 return bottom; |
74 } | 97 } |
75 | 98 |
76 int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const { | 99 int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const { |
77 return IsHorizontalAlignment() ? horizontal : vertical; | 100 return IsHorizontalAlignment() ? horizontal : vertical; |
78 } | 101 } |
79 | 102 |
80 ShelfAutoHideBehavior WmShelf::GetAutoHideBehavior() const { | 103 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { |
81 return shelf_->auto_hide_behavior(); | 104 DCHECK(shelf_layout_manager_); |
82 } | |
83 | 105 |
84 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { | 106 if (auto_hide_behavior_ == auto_hide_behavior) |
85 shelf_->SetAutoHideBehavior(behavior); | 107 return; |
| 108 |
| 109 auto_hide_behavior_ = auto_hide_behavior; |
| 110 WmShell::Get()->shelf_delegate()->OnShelfAutoHideBehaviorChanged(shelf_); |
| 111 WmShell::Get()->NotifyShelfAutoHideBehaviorChanged( |
| 112 GetWindow()->GetRootWindow()); |
86 } | 113 } |
87 | 114 |
88 ShelfAutoHideState WmShelf::GetAutoHideState() const { | 115 ShelfAutoHideState WmShelf::GetAutoHideState() const { |
89 return shelf_layout_manager_->auto_hide_state(); | 116 return shelf_layout_manager_->auto_hide_state(); |
90 } | 117 } |
91 | 118 |
92 void WmShelf::UpdateAutoHideState() { | 119 void WmShelf::UpdateAutoHideState() { |
93 shelf_layout_manager_->UpdateAutoHideState(); | 120 shelf_layout_manager_->UpdateAutoHideState(); |
94 } | 121 } |
95 | 122 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 184 |
158 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const { | 185 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const { |
159 return shelf_layout_manager_->shelf_widget()->status_area_widget(); | 186 return shelf_layout_manager_->shelf_widget()->status_area_widget(); |
160 } | 187 } |
161 | 188 |
162 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { | 189 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { |
163 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); | 190 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); |
164 } | 191 } |
165 | 192 |
166 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { | 193 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { |
167 return shelf_->shelf_locking_manager_for_testing(); | 194 return shelf_locking_manager_.get(); |
168 } | 195 } |
169 | 196 |
170 ShelfView* WmShelf::GetShelfViewForTesting() { | 197 ShelfView* WmShelf::GetShelfViewForTesting() { |
171 return shelf_->shelf_view_for_testing(); | 198 return shelf_->shelf_view_for_testing(); |
172 } | 199 } |
173 | 200 |
| 201 ShelfWidget* WmShelf::GetShelfWidgetForTesting() { |
| 202 return shelf_layout_manager_->shelf_widget(); |
| 203 } |
| 204 |
174 WmShelf::WmShelf() {} | 205 WmShelf::WmShelf() {} |
175 | 206 |
176 WmShelf::~WmShelf() {} | 207 WmShelf::~WmShelf() {} |
177 | 208 |
178 void WmShelf::WillDeleteShelfLayoutManager() { | 209 void WmShelf::WillDeleteShelfLayoutManager() { |
179 DCHECK(shelf_layout_manager_); | 210 DCHECK(shelf_layout_manager_); |
180 shelf_layout_manager_->RemoveObserver(this); | 211 shelf_layout_manager_->RemoveObserver(this); |
181 shelf_layout_manager_ = nullptr; | 212 shelf_layout_manager_ = nullptr; |
182 } | 213 } |
183 | 214 |
184 void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { | 215 void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { |
185 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 216 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
186 WillChangeVisibilityState(new_state)); | 217 WillChangeVisibilityState(new_state)); |
187 } | 218 } |
188 | 219 |
189 void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | 220 void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |
190 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 221 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
191 OnAutoHideStateChanged(new_state)); | 222 OnAutoHideStateChanged(new_state)); |
192 } | 223 } |
193 | 224 |
194 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, | 225 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, |
195 BackgroundAnimatorChangeType change_type) { | 226 BackgroundAnimatorChangeType change_type) { |
196 if (background_type == GetBackgroundType()) | 227 if (background_type == GetBackgroundType()) |
197 return; | 228 return; |
198 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 229 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
199 OnBackgroundTypeChanged(background_type, change_type)); | 230 OnBackgroundTypeChanged(background_type, change_type)); |
200 } | 231 } |
201 | 232 |
202 } // namespace ash | 233 } // namespace ash |
OLD | NEW |