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