| 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_delegate.h" | 5 #include "ash/common/shelf/shelf_delegate.h" |
| 6 #include "ash/common/shelf/shelf_item_delegate.h" | 6 #include "ash/common/shelf/shelf_item_delegate.h" |
| 7 #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" | 8 #include "ash/common/shelf/shelf_locking_manager.h" |
| 9 #include "ash/common/shelf/shelf_model.h" | 9 #include "ash/common/shelf/shelf_model.h" |
| 10 #include "ash/common/shelf/shelf_widget.h" | 10 #include "ash/common/shelf/shelf_widget.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/shelf/wm_shelf_observer.h" | 12 #include "ash/common/shelf/wm_shelf_observer.h" |
| 13 #include "ash/common/shell_window_ids.h" |
| 13 #include "ash/common/wm_lookup.h" | 14 #include "ash/common/wm_lookup.h" |
| 14 #include "ash/common/wm_root_window_controller.h" | 15 #include "ash/common/wm_root_window_controller.h" |
| 15 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 16 #include "ash/common/wm_window.h" | 17 #include "ash/common/wm_window.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 19 | 20 |
| 20 namespace ash { | 21 namespace ash { |
| 21 | 22 |
| 22 // static | 23 // static |
| 23 WmShelf* WmShelf::ForWindow(WmWindow* window) { | 24 WmShelf* WmShelf::ForWindow(WmWindow* window) { |
| 24 return window->GetRootWindowController()->GetShelf(); | 25 return window->GetRootWindowController()->GetShelf(); |
| 25 } | 26 } |
| 26 | 27 |
| 27 void WmShelf::SetShelfLayoutManager(ShelfLayoutManager* manager) { | 28 void WmShelf::CreateShelfWidget(WmWindow* root) { |
| 29 DCHECK(!shelf_widget_); |
| 30 WmWindow* shelf_container = |
| 31 root->GetChildByShellWindowId(kShellWindowId_ShelfContainer); |
| 32 shelf_widget_.reset(new ShelfWidget(shelf_container, this)); |
| 33 |
| 28 DCHECK(!shelf_layout_manager_); | 34 DCHECK(!shelf_layout_manager_); |
| 29 DCHECK(manager); | 35 shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); |
| 30 shelf_layout_manager_ = manager; | |
| 31 shelf_layout_manager_->AddObserver(this); | 36 shelf_layout_manager_->AddObserver(this); |
| 32 DCHECK(manager->shelf_widget()); | 37 |
| 33 shelf_widget_ = manager->shelf_widget(); | 38 // Must occur after |shelf_widget_| is constructed because the system tray |
| 39 // constructors call back into WmShelf::shelf_widget(). |
| 40 DCHECK(!shelf_widget_->status_area_widget()); |
| 41 WmWindow* status_container = |
| 42 root->GetChildByShellWindowId(kShellWindowId_StatusContainer); |
| 43 shelf_widget_->CreateStatusAreaWidget(status_container); |
| 44 } |
| 45 |
| 46 void WmShelf::ShutdownShelfWidget() { |
| 47 if (shelf_widget_) |
| 48 shelf_widget_->Shutdown(); |
| 49 } |
| 50 |
| 51 void WmShelf::DestroyShelfWidget() { |
| 52 shelf_widget_.reset(); |
| 34 } | 53 } |
| 35 | 54 |
| 36 void WmShelf::InitializeShelf() { | 55 void WmShelf::InitializeShelf() { |
| 37 DCHECK(shelf_layout_manager_); | 56 DCHECK(shelf_layout_manager_); |
| 38 DCHECK(shelf_widget_); | 57 DCHECK(shelf_widget_); |
| 39 DCHECK(!shelf_view_); | 58 DCHECK(!shelf_view_); |
| 40 shelf_view_ = shelf_widget_->CreateShelfView(); | 59 shelf_view_ = shelf_widget_->CreateShelfView(); |
| 41 shelf_locking_manager_.reset(new ShelfLockingManager(this)); | 60 shelf_locking_manager_.reset(new ShelfLockingManager(this)); |
| 42 // When the shelf is created the alignment is unlocked. Chrome will update the | 61 // When the shelf is created the alignment is unlocked. Chrome will update the |
| 43 // alignment later from preferences. | 62 // alignment later from preferences. |
| 44 alignment_ = SHELF_ALIGNMENT_BOTTOM; | 63 alignment_ = SHELF_ALIGNMENT_BOTTOM; |
| 45 // NOTE: The delegate may access WmShelf. | 64 // NOTE: The delegate may access WmShelf. |
| 46 WmShell::Get()->shelf_delegate()->OnShelfCreated(this); | 65 WmShell::Get()->shelf_delegate()->OnShelfCreated(this); |
| 47 } | 66 } |
| 48 | 67 |
| 49 void WmShelf::ShutdownShelf() { | 68 void WmShelf::ShutdownShelf() { |
| 50 DCHECK(shelf_view_); | 69 DCHECK(shelf_view_); |
| 51 shelf_locking_manager_.reset(); | 70 shelf_locking_manager_.reset(); |
| 52 shelf_view_ = nullptr; | 71 shelf_view_ = nullptr; |
| 53 WmShell::Get()->shelf_delegate()->OnShelfDestroyed(this); | 72 WmShell::Get()->shelf_delegate()->OnShelfDestroyed(this); |
| 54 } | 73 } |
| 55 | 74 |
| 56 bool WmShelf::IsShelfInitialized() const { | 75 bool WmShelf::IsShelfInitialized() const { |
| 57 return !!shelf_view_; | 76 return !!shelf_view_; |
| 58 } | 77 } |
| 59 | 78 |
| 60 WmWindow* WmShelf::GetWindow() { | 79 WmWindow* WmShelf::GetWindow() { |
| 61 // Use |shelf_layout_manager_| to access ShelfWidget because it is set before | 80 // Use |shelf_layout_manager_| to access ShelfWidget because it is set before |
| 62 // before the Shelf instance is available. | 81 // before the Shelf instance is available. |
| 63 return WmLookup::Get()->GetWindowForWidget( | 82 return WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 64 shelf_layout_manager_->shelf_widget()); | |
| 65 } | 83 } |
| 66 | 84 |
| 67 void WmShelf::SetAlignment(ShelfAlignment alignment) { | 85 void WmShelf::SetAlignment(ShelfAlignment alignment) { |
| 68 DCHECK(shelf_layout_manager_); | 86 DCHECK(shelf_layout_manager_); |
| 69 DCHECK(shelf_locking_manager_); | 87 DCHECK(shelf_locking_manager_); |
| 70 | 88 |
| 71 if (alignment_ == alignment) | 89 if (alignment_ == alignment) |
| 72 return; | 90 return; |
| 73 | 91 |
| 74 if (shelf_locking_manager_->is_locked() && | 92 if (shelf_locking_manager_->is_locked() && |
| 75 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 93 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { |
| 76 shelf_locking_manager_->set_stored_alignment(alignment); | 94 shelf_locking_manager_->set_stored_alignment(alignment); |
| 77 return; | 95 return; |
| 78 } | 96 } |
| 79 | 97 |
| 80 alignment_ = alignment; | 98 alignment_ = alignment; |
| 81 // The ShelfWidget notifies the ShelfView of the alignment change. | 99 // The ShelfWidget notifies the ShelfView of the alignment change. |
| 82 shelf_layout_manager_->shelf_widget()->OnShelfAlignmentChanged(); | 100 shelf_widget_->OnShelfAlignmentChanged(); |
| 83 WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(this); | 101 WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(this); |
| 84 WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); | 102 WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); |
| 85 // ShelfLayoutManager will resize the shelf. | 103 // ShelfLayoutManager will resize the shelf. |
| 86 } | 104 } |
| 87 | 105 |
| 88 bool WmShelf::IsHorizontalAlignment() const { | 106 bool WmShelf::IsHorizontalAlignment() const { |
| 89 switch (alignment_) { | 107 switch (alignment_) { |
| 90 case SHELF_ALIGNMENT_BOTTOM: | 108 case SHELF_ALIGNMENT_BOTTOM: |
| 91 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 109 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 92 return true; | 110 return true; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 150 |
| 133 ShelfAutoHideState WmShelf::GetAutoHideState() const { | 151 ShelfAutoHideState WmShelf::GetAutoHideState() const { |
| 134 return shelf_layout_manager_->auto_hide_state(); | 152 return shelf_layout_manager_->auto_hide_state(); |
| 135 } | 153 } |
| 136 | 154 |
| 137 void WmShelf::UpdateAutoHideState() { | 155 void WmShelf::UpdateAutoHideState() { |
| 138 shelf_layout_manager_->UpdateAutoHideState(); | 156 shelf_layout_manager_->UpdateAutoHideState(); |
| 139 } | 157 } |
| 140 | 158 |
| 141 ShelfBackgroundType WmShelf::GetBackgroundType() const { | 159 ShelfBackgroundType WmShelf::GetBackgroundType() const { |
| 142 return shelf_layout_manager_->shelf_widget()->GetBackgroundType(); | 160 return shelf_widget_->GetBackgroundType(); |
| 143 } | 161 } |
| 144 | 162 |
| 145 WmDimmerView* WmShelf::CreateDimmerView(bool disable_animations_for_test) { | 163 WmDimmerView* WmShelf::CreateDimmerView(bool disable_animations_for_test) { |
| 146 return nullptr; | 164 return nullptr; |
| 147 } | 165 } |
| 148 | 166 |
| 149 bool WmShelf::IsDimmed() const { | 167 bool WmShelf::IsDimmed() const { |
| 150 return shelf_layout_manager_->shelf_widget()->GetDimsShelf(); | 168 return shelf_widget_->GetDimsShelf(); |
| 151 } | 169 } |
| 152 | 170 |
| 153 bool WmShelf::IsVisible() const { | 171 bool WmShelf::IsVisible() const { |
| 154 return shelf_widget_->IsShelfVisible(); | 172 return shelf_widget_->IsShelfVisible(); |
| 155 } | 173 } |
| 156 | 174 |
| 157 void WmShelf::UpdateVisibilityState() { | 175 void WmShelf::UpdateVisibilityState() { |
| 158 if (shelf_layout_manager_) | 176 if (shelf_layout_manager_) |
| 159 shelf_layout_manager_->UpdateVisibilityState(); | 177 shelf_layout_manager_->UpdateVisibilityState(); |
| 160 } | 178 } |
| 161 | 179 |
| 162 ShelfVisibilityState WmShelf::GetVisibilityState() const { | 180 ShelfVisibilityState WmShelf::GetVisibilityState() const { |
| 163 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() | 181 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() |
| 164 : SHELF_HIDDEN; | 182 : SHELF_HIDDEN; |
| 165 } | 183 } |
| 166 | 184 |
| 167 gfx::Rect WmShelf::GetIdealBounds() { | 185 gfx::Rect WmShelf::GetIdealBounds() { |
| 168 return shelf_layout_manager_->GetIdealBounds(); | 186 return shelf_layout_manager_->GetIdealBounds(); |
| 169 } | 187 } |
| 170 | 188 |
| 171 gfx::Rect WmShelf::GetUserWorkAreaBounds() const { | 189 gfx::Rect WmShelf::GetUserWorkAreaBounds() const { |
| 172 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() | 190 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() |
| 173 : gfx::Rect(); | 191 : gfx::Rect(); |
| 174 } | 192 } |
| 175 | 193 |
| 176 void WmShelf::UpdateIconPositionForPanel(WmWindow* panel) { | 194 void WmShelf::UpdateIconPositionForPanel(WmWindow* panel) { |
| 177 shelf_layout_manager_->shelf_widget()->UpdateIconPositionForPanel(panel); | 195 shelf_widget_->UpdateIconPositionForPanel(panel); |
| 178 } | 196 } |
| 179 | 197 |
| 180 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | 198 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { |
| 181 if (!shelf_layout_manager_) | 199 if (!shelf_widget_) |
| 182 return gfx::Rect(); | 200 return gfx::Rect(); |
| 183 return shelf_layout_manager_->shelf_widget() | 201 return shelf_widget_->GetScreenBoundsOfItemIconForWindow(window); |
| 184 ->GetScreenBoundsOfItemIconForWindow(window); | |
| 185 } | 202 } |
| 186 | 203 |
| 187 // static | 204 // static |
| 188 void WmShelf::LaunchShelfItem(int item_index) { | 205 void WmShelf::LaunchShelfItem(int item_index) { |
| 189 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); | 206 ShelfModel* shelf_model = WmShell::Get()->shelf_model(); |
| 190 const ShelfItems& items = shelf_model->items(); | 207 const ShelfItems& items = shelf_model->items(); |
| 191 int item_count = shelf_model->item_count(); | 208 int item_count = shelf_model->item_count(); |
| 192 int indexes_left = item_index >= 0 ? item_index : item_count; | 209 int indexes_left = item_index >= 0 ? item_index : item_count; |
| 193 int found_index = -1; | 210 int found_index = -1; |
| 194 | 211 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 254 |
| 238 void WmShelf::RemoveObserver(WmShelfObserver* observer) { | 255 void WmShelf::RemoveObserver(WmShelfObserver* observer) { |
| 239 observers_.RemoveObserver(observer); | 256 observers_.RemoveObserver(observer); |
| 240 } | 257 } |
| 241 | 258 |
| 242 void WmShelf::NotifyShelfIconPositionsChanged() { | 259 void WmShelf::NotifyShelfIconPositionsChanged() { |
| 243 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged()); | 260 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged()); |
| 244 } | 261 } |
| 245 | 262 |
| 246 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const { | 263 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const { |
| 247 return shelf_layout_manager_->shelf_widget()->status_area_widget(); | 264 return shelf_widget_->status_area_widget(); |
| 248 } | 265 } |
| 249 | 266 |
| 250 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { | 267 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { |
| 251 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); | 268 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); |
| 252 } | 269 } |
| 253 | 270 |
| 254 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { | 271 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { |
| 255 return shelf_locking_manager_.get(); | 272 return shelf_locking_manager_.get(); |
| 256 } | 273 } |
| 257 | 274 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 281 | 298 |
| 282 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, | 299 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, |
| 283 BackgroundAnimatorChangeType change_type) { | 300 BackgroundAnimatorChangeType change_type) { |
| 284 if (background_type == GetBackgroundType()) | 301 if (background_type == GetBackgroundType()) |
| 285 return; | 302 return; |
| 286 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 303 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
| 287 OnBackgroundTypeChanged(background_type, change_type)); | 304 OnBackgroundTypeChanged(background_type, change_type)); |
| 288 } | 305 } |
| 289 | 306 |
| 290 } // namespace ash | 307 } // namespace ash |
| OLD | NEW |