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