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_delegate.h" | 7 #include "ash/common/shelf/shelf_delegate.h" |
8 #include "ash/common/shelf/shelf_item_delegate.h" | 8 #include "ash/common/shelf/shelf_item_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" |
11 #include "ash/common/shelf/shelf_model.h" | 11 #include "ash/common/shelf/shelf_model.h" |
12 #include "ash/common/shelf/shelf_widget.h" | 12 #include "ash/common/shelf/shelf_widget.h" |
13 #include "ash/common/shelf/wm_shelf_observer.h" | 13 #include "ash/common/shelf/wm_shelf_observer.h" |
14 #include "ash/common/shell_window_ids.h" | 14 #include "ash/common/shell_window_ids.h" |
| 15 #include "ash/common/system/tray/system_tray_delegate.h" |
15 #include "ash/common/wm_lookup.h" | 16 #include "ash/common/wm_lookup.h" |
16 #include "ash/common/wm_root_window_controller.h" | 17 #include "ash/common/wm_root_window_controller.h" |
17 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
18 #include "ash/common/wm_window.h" | 19 #include "ash/common/wm_window.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
21 | 22 |
22 namespace ash { | 23 namespace ash { |
23 | 24 |
24 // static | 25 // static |
25 WmShelf* WmShelf::ForWindow(WmWindow* window) { | 26 WmShelf* WmShelf::ForWindow(WmWindow* window) { |
26 return window->GetRootWindowController()->GetShelf(); | 27 return window->GetRootWindowController()->GetShelf(); |
27 } | 28 } |
28 | 29 |
| 30 // static |
| 31 bool WmShelf::CanChangeShelfAlignment() { |
| 32 if (WmShell::Get()->system_tray_delegate()->IsUserSupervised()) |
| 33 return false; |
| 34 |
| 35 LoginStatus login_status = |
| 36 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); |
| 37 |
| 38 switch (login_status) { |
| 39 case LoginStatus::LOCKED: |
| 40 // Shelf alignment changes can be requested while being locked, but will |
| 41 // be applied upon unlock. |
| 42 case LoginStatus::USER: |
| 43 case LoginStatus::OWNER: |
| 44 return true; |
| 45 case LoginStatus::PUBLIC: |
| 46 case LoginStatus::SUPERVISED: |
| 47 case LoginStatus::GUEST: |
| 48 case LoginStatus::KIOSK_APP: |
| 49 case LoginStatus::NOT_LOGGED_IN: |
| 50 return false; |
| 51 } |
| 52 |
| 53 NOTREACHED(); |
| 54 return false; |
| 55 } |
| 56 |
29 void WmShelf::CreateShelfWidget(WmWindow* root) { | 57 void WmShelf::CreateShelfWidget(WmWindow* root) { |
30 DCHECK(!shelf_widget_); | 58 DCHECK(!shelf_widget_); |
31 WmWindow* shelf_container = | 59 WmWindow* shelf_container = |
32 root->GetChildByShellWindowId(kShellWindowId_ShelfContainer); | 60 root->GetChildByShellWindowId(kShellWindowId_ShelfContainer); |
33 shelf_widget_.reset(new ShelfWidget(shelf_container, this)); | 61 shelf_widget_.reset(new ShelfWidget(shelf_container, this)); |
34 | 62 |
35 DCHECK(!shelf_layout_manager_); | 63 DCHECK(!shelf_layout_manager_); |
36 shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); | 64 shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); |
37 shelf_layout_manager_->AddObserver(this); | 65 shelf_layout_manager_->AddObserver(this); |
38 | 66 |
(...skipping 16 matching lines...) Expand all Loading... |
55 | 83 |
56 void WmShelf::InitializeShelf() { | 84 void WmShelf::InitializeShelf() { |
57 DCHECK(shelf_layout_manager_); | 85 DCHECK(shelf_layout_manager_); |
58 DCHECK(shelf_widget_); | 86 DCHECK(shelf_widget_); |
59 DCHECK(!shelf_view_); | 87 DCHECK(!shelf_view_); |
60 shelf_view_ = shelf_widget_->CreateShelfView(); | 88 shelf_view_ = shelf_widget_->CreateShelfView(); |
61 shelf_locking_manager_.reset(new ShelfLockingManager(this)); | 89 shelf_locking_manager_.reset(new ShelfLockingManager(this)); |
62 // When the shelf is created the alignment is unlocked. Chrome will update the | 90 // When the shelf is created the alignment is unlocked. Chrome will update the |
63 // alignment later from preferences. | 91 // alignment later from preferences. |
64 alignment_ = SHELF_ALIGNMENT_BOTTOM; | 92 alignment_ = SHELF_ALIGNMENT_BOTTOM; |
65 // NOTE: The delegate may access WmShelf. | 93 WmShell::Get()->shelf_controller()->NotifyShelfCreated(this); |
66 WmShell::Get()->shelf_delegate()->OnShelfCreated(this); | |
67 } | 94 } |
68 | 95 |
69 void WmShelf::ShutdownShelf() { | 96 void WmShelf::ShutdownShelf() { |
70 DCHECK(shelf_view_); | 97 DCHECK(shelf_view_); |
71 shelf_locking_manager_.reset(); | 98 shelf_locking_manager_.reset(); |
72 shelf_view_ = nullptr; | 99 shelf_view_ = nullptr; |
73 WmShell::Get()->shelf_delegate()->OnShelfDestroyed(this); | |
74 } | 100 } |
75 | 101 |
76 bool WmShelf::IsShelfInitialized() const { | 102 bool WmShelf::IsShelfInitialized() const { |
77 return !!shelf_view_; | 103 return !!shelf_view_; |
78 } | 104 } |
79 | 105 |
80 WmWindow* WmShelf::GetWindow() { | 106 WmWindow* WmShelf::GetWindow() { |
81 return WmLookup::Get()->GetWindowForWidget(shelf_widget_.get()); | 107 return WmLookup::Get()->GetWindowForWidget(shelf_widget_.get()); |
82 } | 108 } |
83 | 109 |
84 void WmShelf::SetAlignment(ShelfAlignment alignment) { | 110 void WmShelf::SetAlignment(ShelfAlignment alignment) { |
85 DCHECK(shelf_layout_manager_); | 111 DCHECK(shelf_layout_manager_); |
86 DCHECK(shelf_locking_manager_); | 112 DCHECK(shelf_locking_manager_); |
87 | 113 |
88 if (alignment_ == alignment) | 114 if (alignment_ == alignment) |
89 return; | 115 return; |
90 | 116 |
91 if (shelf_locking_manager_->is_locked() && | 117 if (shelf_locking_manager_->is_locked() && |
92 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 118 alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { |
93 shelf_locking_manager_->set_stored_alignment(alignment); | 119 shelf_locking_manager_->set_stored_alignment(alignment); |
94 return; | 120 return; |
95 } | 121 } |
96 | 122 |
97 alignment_ = alignment; | 123 alignment_ = alignment; |
98 // The ShelfWidget notifies the ShelfView of the alignment change. | 124 // The ShelfWidget notifies the ShelfView of the alignment change. |
99 shelf_widget_->OnShelfAlignmentChanged(); | 125 shelf_widget_->OnShelfAlignmentChanged(); |
100 WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(this); | |
101 shelf_layout_manager_->LayoutShelf(); | 126 shelf_layout_manager_->LayoutShelf(); |
| 127 WmShell::Get()->shelf_controller()->NotifyShelfAlignmentChanged(this); |
102 WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); | 128 WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); |
103 } | 129 } |
104 | 130 |
105 bool WmShelf::IsHorizontalAlignment() const { | 131 bool WmShelf::IsHorizontalAlignment() const { |
106 switch (alignment_) { | 132 switch (alignment_) { |
107 case SHELF_ALIGNMENT_BOTTOM: | 133 case SHELF_ALIGNMENT_BOTTOM: |
108 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 134 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
109 return true; | 135 return true; |
110 case SHELF_ALIGNMENT_LEFT: | 136 case SHELF_ALIGNMENT_LEFT: |
111 case SHELF_ALIGNMENT_RIGHT: | 137 case SHELF_ALIGNMENT_RIGHT: |
(...skipping 23 matching lines...) Expand all Loading... |
135 return IsHorizontalAlignment() ? horizontal : vertical; | 161 return IsHorizontalAlignment() ? horizontal : vertical; |
136 } | 162 } |
137 | 163 |
138 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { | 164 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { |
139 DCHECK(shelf_layout_manager_); | 165 DCHECK(shelf_layout_manager_); |
140 | 166 |
141 if (auto_hide_behavior_ == auto_hide_behavior) | 167 if (auto_hide_behavior_ == auto_hide_behavior) |
142 return; | 168 return; |
143 | 169 |
144 auto_hide_behavior_ = auto_hide_behavior; | 170 auto_hide_behavior_ = auto_hide_behavior; |
145 WmShell::Get()->shelf_delegate()->OnShelfAutoHideBehaviorChanged(this); | 171 WmShell::Get()->shelf_controller()->NotifyShelfAutoHideBehaviorChanged(this); |
146 WmShell::Get()->NotifyShelfAutoHideBehaviorChanged( | 172 WmShell::Get()->NotifyShelfAutoHideBehaviorChanged( |
147 GetWindow()->GetRootWindow()); | 173 GetWindow()->GetRootWindow()); |
148 } | 174 } |
149 | 175 |
150 ShelfAutoHideState WmShelf::GetAutoHideState() const { | 176 ShelfAutoHideState WmShelf::GetAutoHideState() const { |
151 return shelf_layout_manager_->auto_hide_state(); | 177 return shelf_layout_manager_->auto_hide_state(); |
152 } | 178 } |
153 | 179 |
154 void WmShelf::UpdateAutoHideState() { | 180 void WmShelf::UpdateAutoHideState() { |
155 shelf_layout_manager_->UpdateAutoHideState(); | 181 shelf_layout_manager_->UpdateAutoHideState(); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 323 |
298 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, | 324 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, |
299 BackgroundAnimatorChangeType change_type) { | 325 BackgroundAnimatorChangeType change_type) { |
300 if (background_type == GetBackgroundType()) | 326 if (background_type == GetBackgroundType()) |
301 return; | 327 return; |
302 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 328 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
303 OnBackgroundTypeChanged(background_type, change_type)); | 329 OnBackgroundTypeChanged(background_type, change_type)); |
304 } | 330 } |
305 | 331 |
306 } // namespace ash | 332 } // namespace ash |
OLD | NEW |