Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: ash/common/shelf/wm_shelf.cc

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

Powered by Google App Engine
This is Rietveld 408576698