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

Side by Side Diff: ash/common/shelf/wm_shelf.cc

Issue 2247503002: mash: Create and show a shelf in mash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup. Created 4 years, 4 months 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 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/wm_shelf.h" 5 #include "ash/common/shelf/wm_shelf.h"
6 6 #include "ash/common/shelf/wm_shelf_observer.h"
7 #include "ash/common/wm_lookup.h"
8 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_layout_manager.h"
7 #include "base/logging.h" 10 #include "base/logging.h"
8 11
9 namespace ash { 12 namespace ash {
10 13
14 void WmShelf::SetShelf(std::unique_ptr<Shelf> shelf) {
15 DCHECK(!shelf_ || !shelf);
16 shelf_ = std::move(shelf);
17 }
18
19 void WmShelf::SetShelfLayoutManager(ShelfLayoutManager* shelf_layout_manager) {
20 DCHECK(!shelf_layout_manager_ || !shelf_layout_manager);
21
22 if (shelf_layout_manager_)
23 shelf_layout_manager_->RemoveObserver(this);
24
25 shelf_layout_manager_ = shelf_layout_manager;
26
27 if (shelf_layout_manager_)
28 shelf_layout_manager_->AddObserver(this);
29 }
30
31 WmWindow* WmShelf::GetWindow() {
32 // Use |shelf_layout_manager_| to access ShelfWidget because it is set before
33 // before the Shelf instance is available.
34 return WmLookup::Get()->GetWindowForWidget(
35 shelf_layout_manager_->shelf_widget());
36 }
37
38 ShelfAlignment WmShelf::GetAlignment() const {
39 return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED;
40 }
41
42 void WmShelf::SetAlignment(ShelfAlignment alignment) {
43 shelf_->SetAlignment(alignment);
44 }
45
11 bool WmShelf::IsHorizontalAlignment() const { 46 bool WmShelf::IsHorizontalAlignment() const {
12 switch (GetAlignment()) { 47 switch (GetAlignment()) {
13 case SHELF_ALIGNMENT_BOTTOM: 48 case SHELF_ALIGNMENT_BOTTOM:
14 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 49 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
15 return true; 50 return true;
16 case SHELF_ALIGNMENT_LEFT: 51 case SHELF_ALIGNMENT_LEFT:
17 case SHELF_ALIGNMENT_RIGHT: 52 case SHELF_ALIGNMENT_RIGHT:
18 return false; 53 return false;
19 } 54 }
20 NOTREACHED(); 55 NOTREACHED();
(...skipping 13 matching lines...) Expand all
34 return right; 69 return right;
35 } 70 }
36 NOTREACHED(); 71 NOTREACHED();
37 return bottom; 72 return bottom;
38 } 73 }
39 74
40 int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const { 75 int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const {
41 return IsHorizontalAlignment() ? horizontal : vertical; 76 return IsHorizontalAlignment() ? horizontal : vertical;
42 } 77 }
43 78
79 ShelfAutoHideBehavior WmShelf::GetAutoHideBehavior() const {
80 return shelf_->auto_hide_behavior();
81 }
82
83 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) {
84 shelf_->SetAutoHideBehavior(behavior);
85 }
86
87 ShelfAutoHideState WmShelf::GetAutoHideState() const {
88 return shelf_layout_manager_->auto_hide_state();
89 }
90
91 void WmShelf::UpdateAutoHideState() {
92 shelf_layout_manager_->UpdateAutoHideState();
93 }
94
95 ShelfBackgroundType WmShelf::GetBackgroundType() const {
96 return shelf_layout_manager_->shelf_widget()->GetBackgroundType();
97 }
98
99 WmDimmerView* WmShelf::CreateDimmerView(bool disable_animations_for_test) {
100 return nullptr;
101 }
102
103 bool WmShelf::IsDimmed() const {
104 return shelf_layout_manager_->shelf_widget()->GetDimsShelf();
105 }
106
107 void WmShelf::SchedulePaint() {
108 // Can be called during shutdown if the overflow bubble is visible.
109 if (shelf_)
110 shelf_->SchedulePaint();
111 }
112
113 bool WmShelf::IsVisible() const {
114 return shelf_->IsVisible();
115 }
116
117 void WmShelf::UpdateVisibilityState() {
118 if (shelf_layout_manager_)
119 shelf_layout_manager_->UpdateVisibilityState();
120 }
121
122 ShelfVisibilityState WmShelf::GetVisibilityState() const {
123 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state()
124 : SHELF_HIDDEN;
125 }
126
127 gfx::Rect WmShelf::GetIdealBounds() {
128 return shelf_layout_manager_->GetIdealBounds();
129 }
130
131 gfx::Rect WmShelf::GetUserWorkAreaBounds() const {
132 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds()
133 : gfx::Rect();
134 }
135
136 void WmShelf::UpdateIconPositionForWindow(WmWindow* window) {
137 shelf_->UpdateIconPositionForWindow(window);
138 }
139
140 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) {
141 return shelf_->GetScreenBoundsOfItemIconForWindow(window);
142 }
143
144 bool WmShelf::ProcessGestureEvent(const ui::GestureEvent& event) {
145 // Can be called at login screen.
146 if (!shelf_layout_manager_)
147 return false;
148 return shelf_layout_manager_->ProcessGestureEvent(event);
149 }
150
151 void WmShelf::AddObserver(WmShelfObserver* observer) {
152 observers_.AddObserver(observer);
153 }
154
155 void WmShelf::RemoveObserver(WmShelfObserver* observer) {
156 observers_.RemoveObserver(observer);
157 }
158
159 void WmShelf::NotifyShelfIconPositionsChanged() {
160 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged());
161 }
162
163 void WmShelf::SetKeyboardBoundsForTesting(const gfx::Rect& bounds) {
164 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds);
165 }
166
167 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() {
168 return shelf_->shelf_locking_manager_for_testing();
169 }
170
171 ShelfView* WmShelf::GetShelfViewForTesting() {
172 return shelf_->shelf_view_for_testing();
173 }
174
175 WmShelf::WmShelf() {}
176
177 WmShelf::~WmShelf() {
178 SetShelfLayoutManager(nullptr);
179 }
180
181 void WmShelf::WillDeleteShelfLayoutManager() {
182 SetShelfLayoutManager(nullptr);
183 }
184
185 void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) {
186 FOR_EACH_OBSERVER(WmShelfObserver, observers_,
187 WillChangeVisibilityState(new_state));
188 }
189
190 void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) {
191 FOR_EACH_OBSERVER(WmShelfObserver, observers_,
192 OnAutoHideStateChanged(new_state));
193 }
194
195 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type,
196 BackgroundAnimatorChangeType change_type) {
197 if (background_type == GetBackgroundType())
198 return;
199 FOR_EACH_OBSERVER(WmShelfObserver, observers_,
200 OnBackgroundTypeChanged(background_type, change_type));
201 }
202
44 } // namespace ash 203 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698