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_delegate.h" |
| 7 #include "ash/common/shelf/shelf_item_delegate.h" |
7 #include "ash/common/shelf/shelf_layout_manager.h" | 8 #include "ash/common/shelf/shelf_layout_manager.h" |
8 #include "ash/common/shelf/shelf_locking_manager.h" | 9 #include "ash/common/shelf/shelf_locking_manager.h" |
| 10 #include "ash/common/shelf/shelf_model.h" |
9 #include "ash/common/shelf/shelf_widget.h" | 11 #include "ash/common/shelf/shelf_widget.h" |
10 #include "ash/common/shelf/wm_shelf.h" | 12 #include "ash/common/shelf/wm_shelf.h" |
11 #include "ash/common/shelf/wm_shelf_observer.h" | 13 #include "ash/common/shelf/wm_shelf_observer.h" |
12 #include "ash/common/wm_lookup.h" | 14 #include "ash/common/wm_lookup.h" |
| 15 #include "ash/common/wm_root_window_controller.h" |
13 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
14 #include "ash/common/wm_window.h" | 17 #include "ash/common/wm_window.h" |
15 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "ui/gfx/geometry/rect.h" |
16 | 20 |
17 namespace ash { | 21 namespace ash { |
18 | 22 |
| 23 // static |
| 24 WmShelf* WmShelf::ForWindow(WmWindow* window) { |
| 25 return window->GetRootWindowController()->GetShelf(); |
| 26 } |
| 27 |
19 void WmShelf::SetShelf(Shelf* shelf) { | 28 void WmShelf::SetShelf(Shelf* shelf) { |
20 DCHECK(!shelf_); | 29 DCHECK(!shelf_); |
21 DCHECK(shelf); | 30 DCHECK(shelf); |
22 shelf_ = shelf; | 31 shelf_ = shelf; |
23 DCHECK(shelf_layout_manager_); | 32 DCHECK(shelf_layout_manager_); |
24 shelf_locking_manager_.reset(new ShelfLockingManager(this)); | 33 shelf_locking_manager_.reset(new ShelfLockingManager(this)); |
25 // When the shelf is created the alignment is unlocked. Chrome will update the | 34 // When the shelf is created the alignment is unlocked. Chrome will update the |
26 // alignment later from preferences. | 35 // alignment later from preferences. |
27 alignment_ = SHELF_ALIGNMENT_BOTTOM; | 36 alignment_ = SHELF_ALIGNMENT_BOTTOM; |
28 } | 37 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 157 |
149 gfx::Rect WmShelf::GetIdealBounds() { | 158 gfx::Rect WmShelf::GetIdealBounds() { |
150 return shelf_layout_manager_->GetIdealBounds(); | 159 return shelf_layout_manager_->GetIdealBounds(); |
151 } | 160 } |
152 | 161 |
153 gfx::Rect WmShelf::GetUserWorkAreaBounds() const { | 162 gfx::Rect WmShelf::GetUserWorkAreaBounds() const { |
154 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() | 163 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() |
155 : gfx::Rect(); | 164 : gfx::Rect(); |
156 } | 165 } |
157 | 166 |
158 void WmShelf::UpdateIconPositionForWindow(WmWindow* window) { | 167 void WmShelf::UpdateIconPositionForPanel(WmWindow* panel) { |
159 shelf_->UpdateIconPositionForWindow(window); | 168 shelf_layout_manager_->shelf_widget()->UpdateIconPositionForPanel(panel); |
160 } | 169 } |
161 | 170 |
162 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | 171 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { |
163 return shelf_->GetScreenBoundsOfItemIconForWindow(window); | 172 if (!shelf_layout_manager_) |
| 173 return gfx::Rect(); |
| 174 return shelf_layout_manager_->shelf_widget() |
| 175 ->GetScreenBoundsOfItemIconForWindow(window); |
| 176 } |
| 177 |
| 178 // static |
| 179 void WmShelf::LaunchShelfItem(int item_index) { |
| 180 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); |
| 181 const ShelfItems& items = shelf_model->items(); |
| 182 int item_count = shelf_model->item_count(); |
| 183 int indexes_left = item_index >= 0 ? item_index : item_count; |
| 184 int found_index = -1; |
| 185 |
| 186 // Iterating until we have hit the index we are interested in which |
| 187 // is true once indexes_left becomes negative. |
| 188 for (int i = 0; i < item_count && indexes_left >= 0; i++) { |
| 189 if (items[i].type != TYPE_APP_LIST) { |
| 190 found_index = i; |
| 191 indexes_left--; |
| 192 } |
| 193 } |
| 194 |
| 195 // There are two ways how found_index can be valid: a.) the nth item was |
| 196 // found (which is true when indexes_left is -1) or b.) the last item was |
| 197 // requested (which is true when index was passed in as a negative number). |
| 198 if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { |
| 199 // Then set this one as active (or advance to the next item of its kind). |
| 200 ActivateShelfItem(found_index); |
| 201 } |
| 202 } |
| 203 |
| 204 // static |
| 205 void WmShelf::ActivateShelfItem(int item_index) { |
| 206 // We pass in a keyboard event which will then trigger a switch to the |
| 207 // next item if the current one is already active. |
| 208 ui::KeyEvent event(ui::ET_KEY_RELEASED, |
| 209 ui::VKEY_UNKNOWN, // The actual key gets ignored. |
| 210 ui::EF_NONE); |
| 211 |
| 212 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); |
| 213 const ShelfItem& item = shelf_model->items()[item_index]; |
| 214 ShelfItemDelegate* item_delegate = shelf_model->GetShelfItemDelegate(item.id); |
| 215 item_delegate->ItemSelected(event); |
164 } | 216 } |
165 | 217 |
166 bool WmShelf::ProcessGestureEvent(const ui::GestureEvent& event) { | 218 bool WmShelf::ProcessGestureEvent(const ui::GestureEvent& event) { |
167 // Can be called at login screen. | 219 // Can be called at login screen. |
168 if (!shelf_layout_manager_) | 220 if (!shelf_layout_manager_) |
169 return false; | 221 return false; |
170 return shelf_layout_manager_->ProcessGestureEvent(event); | 222 return shelf_layout_manager_->ProcessGestureEvent(event); |
171 } | 223 } |
172 | 224 |
173 void WmShelf::AddObserver(WmShelfObserver* observer) { | 225 void WmShelf::AddObserver(WmShelfObserver* observer) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 276 |
225 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, | 277 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, |
226 BackgroundAnimatorChangeType change_type) { | 278 BackgroundAnimatorChangeType change_type) { |
227 if (background_type == GetBackgroundType()) | 279 if (background_type == GetBackgroundType()) |
228 return; | 280 return; |
229 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 281 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
230 OnBackgroundTypeChanged(background_type, change_type)); | 282 OnBackgroundTypeChanged(background_type, change_type)); |
231 } | 283 } |
232 | 284 |
233 } // namespace ash | 285 } // namespace ash |
OLD | NEW |