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/wm_shelf.h" | 5 #include "ash/common/shelf/wm_shelf.h" |
6 | 6 |
7 #include "ash/common/shelf/shelf_controller.h" | 7 #include "ash/common/shelf/shelf_controller.h" |
8 #include "ash/common/shelf/shelf_delegate.h" | 8 #include "ash/common/shelf/shelf_delegate.h" |
9 #include "ash/common/shelf/shelf_layout_manager.h" | 9 #include "ash/common/shelf/shelf_layout_manager.h" |
10 #include "ash/common/shelf/shelf_locking_manager.h" | 10 #include "ash/common/shelf/shelf_locking_manager.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 void WmShelf::DestroyShelfWidget() { | 134 void WmShelf::DestroyShelfWidget() { |
135 shelf_widget_.reset(); | 135 shelf_widget_.reset(); |
136 } | 136 } |
137 | 137 |
138 void WmShelf::CreateShelfView() { | 138 void WmShelf::CreateShelfView() { |
139 DCHECK(shelf_layout_manager_); | 139 DCHECK(shelf_layout_manager_); |
140 DCHECK(shelf_widget_); | 140 DCHECK(shelf_widget_); |
141 DCHECK(!shelf_view_); | 141 DCHECK(!shelf_view_); |
142 shelf_view_ = shelf_widget_->CreateShelfView(); | 142 shelf_view_ = shelf_widget_->CreateShelfView(); |
143 shelf_locking_manager_.reset(new ShelfLockingManager(this)); | 143 shelf_locking_manager_.reset(new ShelfLockingManager(this)); |
144 WmShell::Get()->shelf_controller()->NotifyShelfCreated(this); | 144 Shell::Get()->shelf_controller()->NotifyShelfCreated(this); |
145 } | 145 } |
146 | 146 |
147 void WmShelf::ShutdownShelf() { | 147 void WmShelf::ShutdownShelf() { |
148 DCHECK(shelf_view_); | 148 DCHECK(shelf_view_); |
149 shelf_locking_manager_.reset(); | 149 shelf_locking_manager_.reset(); |
150 shelf_view_ = nullptr; | 150 shelf_view_ = nullptr; |
151 } | 151 } |
152 | 152 |
153 bool WmShelf::IsShelfInitialized() const { | 153 bool WmShelf::IsShelfInitialized() const { |
154 return !!shelf_view_; | 154 return !!shelf_view_; |
(...skipping 13 matching lines...) Expand all Loading... |
168 if (shelf_locking_manager_->is_locked() && | 168 if (shelf_locking_manager_->is_locked() && |
169 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 169 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { |
170 shelf_locking_manager_->set_stored_alignment(alignment); | 170 shelf_locking_manager_->set_stored_alignment(alignment); |
171 return; | 171 return; |
172 } | 172 } |
173 | 173 |
174 alignment_ = alignment; | 174 alignment_ = alignment; |
175 // The ShelfWidget notifies the ShelfView of the alignment change. | 175 // The ShelfWidget notifies the ShelfView of the alignment change. |
176 shelf_widget_->OnShelfAlignmentChanged(); | 176 shelf_widget_->OnShelfAlignmentChanged(); |
177 shelf_layout_manager_->LayoutShelf(); | 177 shelf_layout_manager_->LayoutShelf(); |
178 WmShell::Get()->shelf_controller()->NotifyShelfAlignmentChanged(this); | 178 Shell::Get()->shelf_controller()->NotifyShelfAlignmentChanged(this); |
179 Shell::GetInstance()->NotifyShelfAlignmentChanged( | 179 Shell::GetInstance()->NotifyShelfAlignmentChanged( |
180 GetWindow()->GetRootWindow()); | 180 GetWindow()->GetRootWindow()); |
181 } | 181 } |
182 | 182 |
183 bool WmShelf::IsHorizontalAlignment() const { | 183 bool WmShelf::IsHorizontalAlignment() const { |
184 switch (alignment_) { | 184 switch (alignment_) { |
185 case SHELF_ALIGNMENT_BOTTOM: | 185 case SHELF_ALIGNMENT_BOTTOM: |
186 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 186 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
187 return true; | 187 return true; |
188 case SHELF_ALIGNMENT_LEFT: | 188 case SHELF_ALIGNMENT_LEFT: |
(...skipping 24 matching lines...) Expand all Loading... |
213 return IsHorizontalAlignment() ? horizontal : vertical; | 213 return IsHorizontalAlignment() ? horizontal : vertical; |
214 } | 214 } |
215 | 215 |
216 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { | 216 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { |
217 DCHECK(shelf_layout_manager_); | 217 DCHECK(shelf_layout_manager_); |
218 | 218 |
219 if (auto_hide_behavior_ == auto_hide_behavior) | 219 if (auto_hide_behavior_ == auto_hide_behavior) |
220 return; | 220 return; |
221 | 221 |
222 auto_hide_behavior_ = auto_hide_behavior; | 222 auto_hide_behavior_ = auto_hide_behavior; |
223 WmShell::Get()->shelf_controller()->NotifyShelfAutoHideBehaviorChanged(this); | 223 Shell::Get()->shelf_controller()->NotifyShelfAutoHideBehaviorChanged(this); |
224 Shell::GetInstance()->NotifyShelfAutoHideBehaviorChanged( | 224 Shell::GetInstance()->NotifyShelfAutoHideBehaviorChanged( |
225 GetWindow()->GetRootWindow()); | 225 GetWindow()->GetRootWindow()); |
226 } | 226 } |
227 | 227 |
228 ShelfAutoHideState WmShelf::GetAutoHideState() const { | 228 ShelfAutoHideState WmShelf::GetAutoHideState() const { |
229 return shelf_layout_manager_->auto_hide_state(); | 229 return shelf_layout_manager_->auto_hide_state(); |
230 } | 230 } |
231 | 231 |
232 void WmShelf::UpdateAutoHideState() { | 232 void WmShelf::UpdateAutoHideState() { |
233 shelf_layout_manager_->UpdateAutoHideState(); | 233 shelf_layout_manager_->UpdateAutoHideState(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 } | 265 } |
266 | 266 |
267 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | 267 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { |
268 if (!shelf_widget_) | 268 if (!shelf_widget_) |
269 return gfx::Rect(); | 269 return gfx::Rect(); |
270 return shelf_widget_->GetScreenBoundsOfItemIconForWindow(window); | 270 return shelf_widget_->GetScreenBoundsOfItemIconForWindow(window); |
271 } | 271 } |
272 | 272 |
273 // static | 273 // static |
274 void WmShelf::LaunchShelfItem(int item_index) { | 274 void WmShelf::LaunchShelfItem(int item_index) { |
275 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); | 275 ShelfModel* shelf_model = Shell::Get()->shelf_model(); |
276 const ShelfItems& items = shelf_model->items(); | 276 const ShelfItems& items = shelf_model->items(); |
277 int item_count = shelf_model->item_count(); | 277 int item_count = shelf_model->item_count(); |
278 int indexes_left = item_index >= 0 ? item_index : item_count; | 278 int indexes_left = item_index >= 0 ? item_index : item_count; |
279 int found_index = -1; | 279 int found_index = -1; |
280 | 280 |
281 // Iterating until we have hit the index we are interested in which | 281 // Iterating until we have hit the index we are interested in which |
282 // is true once indexes_left becomes negative. | 282 // is true once indexes_left becomes negative. |
283 for (int i = 0; i < item_count && indexes_left >= 0; i++) { | 283 for (int i = 0; i < item_count && indexes_left >= 0; i++) { |
284 if (items[i].type != TYPE_APP_LIST) { | 284 if (items[i].type != TYPE_APP_LIST) { |
285 found_index = i; | 285 found_index = i; |
286 indexes_left--; | 286 indexes_left--; |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
290 // There are two ways how found_index can be valid: a.) the nth item was | 290 // There are two ways how found_index can be valid: a.) the nth item was |
291 // found (which is true when indexes_left is -1) or b.) the last item was | 291 // found (which is true when indexes_left is -1) or b.) the last item was |
292 // requested (which is true when index was passed in as a negative number). | 292 // requested (which is true when index was passed in as a negative number). |
293 if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { | 293 if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { |
294 // Then set this one as active (or advance to the next item of its kind). | 294 // Then set this one as active (or advance to the next item of its kind). |
295 ActivateShelfItem(found_index); | 295 ActivateShelfItem(found_index); |
296 } | 296 } |
297 } | 297 } |
298 | 298 |
299 // static | 299 // static |
300 void WmShelf::ActivateShelfItem(int item_index) { | 300 void WmShelf::ActivateShelfItem(int item_index) { |
301 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); | 301 ShelfModel* shelf_model = Shell::Get()->shelf_model(); |
302 const ShelfItem& item = shelf_model->items()[item_index]; | 302 const ShelfItem& item = shelf_model->items()[item_index]; |
303 mojom::ShelfItemDelegate* item_delegate = | 303 mojom::ShelfItemDelegate* item_delegate = |
304 shelf_model->GetShelfItemDelegate(item.id); | 304 shelf_model->GetShelfItemDelegate(item.id); |
305 std::unique_ptr<ui::Event> event = base::MakeUnique<ui::KeyEvent>( | 305 std::unique_ptr<ui::Event> event = base::MakeUnique<ui::KeyEvent>( |
306 ui::ET_KEY_RELEASED, ui::VKEY_UNKNOWN, ui::EF_NONE); | 306 ui::ET_KEY_RELEASED, ui::VKEY_UNKNOWN, ui::EF_NONE); |
307 item_delegate->ItemSelected(std::move(event), display::kInvalidDisplayId, | 307 item_delegate->ItemSelected(std::move(event), display::kInvalidDisplayId, |
308 LAUNCH_FROM_UNKNOWN, base::Bind(&NoopCallback)); | 308 LAUNCH_FROM_UNKNOWN, base::Bind(&NoopCallback)); |
309 } | 309 } |
310 | 310 |
311 bool WmShelf::ProcessGestureEvent(const ui::GestureEvent& event) { | 311 bool WmShelf::ProcessGestureEvent(const ui::GestureEvent& event) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 378 |
379 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, | 379 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, |
380 AnimationChangeType change_type) { | 380 AnimationChangeType change_type) { |
381 if (background_type == GetBackgroundType()) | 381 if (background_type == GetBackgroundType()) |
382 return; | 382 return; |
383 for (auto& observer : observers_) | 383 for (auto& observer : observers_) |
384 observer.OnBackgroundTypeChanged(background_type, change_type); | 384 observer.OnBackgroundTypeChanged(background_type, change_type); |
385 } | 385 } |
386 | 386 |
387 } // namespace ash | 387 } // namespace ash |
OLD | NEW |