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

Side by Side Diff: ash/system/web_notification/ash_popup_alignment_delegate.cc

Issue 1659283002: ash: Explicitly teach various components about ShelfLayoutManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ozone-ui-event-platform-event
Patch Set: . Created 4 years, 10 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/system/web_notification/ash_popup_alignment_delegate.h" 5 #include "ash/system/web_notification/ash_popup_alignment_delegate.h"
6 6
7 #include "ash/display/window_tree_host_manager.h" 7 #include "ash/display/window_tree_host_manager.h"
8 #include "ash/screen_util.h" 8 #include "ash/screen_util.h"
9 #include "ash/shelf/shelf_constants.h" 9 #include "ash/shelf/shelf_constants.h"
10 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
(...skipping 14 matching lines...) Expand all
25 25
26 const int kToastMarginX = 3; 26 const int kToastMarginX = 3;
27 27
28 // If there should be no margin for the first item, this value needs to be 28 // If there should be no margin for the first item, this value needs to be
29 // substracted to flush the message to the shelf (the width of the border + 29 // substracted to flush the message to the shelf (the width of the border +
30 // shadow). 30 // shadow).
31 const int kNoToastMarginBorderAndShadowOffset = 2; 31 const int kNoToastMarginBorderAndShadowOffset = 2;
32 32
33 } 33 }
34 34
35 AshPopupAlignmentDelegate::AshPopupAlignmentDelegate() 35 AshPopupAlignmentDelegate::AshPopupAlignmentDelegate(ShelfLayoutManager* shelf)
36 : screen_(NULL), root_window_(NULL), shelf_(NULL), system_tray_height_(0) { 36 : screen_(NULL), root_window_(NULL), shelf_(shelf), system_tray_height_(0) {
37 shelf_->AddObserver(this);
37 } 38 }
38 39
39 AshPopupAlignmentDelegate::~AshPopupAlignmentDelegate() { 40 AshPopupAlignmentDelegate::~AshPopupAlignmentDelegate() {
40 if (screen_) 41 if (screen_)
41 screen_->RemoveObserver(this); 42 screen_->RemoveObserver(this);
42 Shell::GetInstance()->RemoveShellObserver(this); 43 Shell::GetInstance()->RemoveShellObserver(this);
43 if (shelf_) 44 if (shelf_)
sky 2016/02/03 00:01:42 Remove this conditional as shelf_ is always non-nu
sadrul 2016/02/03 02:07:58 Done. (fixed up the rest of the code to not check
44 shelf_->RemoveObserver(this); 45 shelf_->RemoveObserver(this);
45 } 46 }
46 47
47 void AshPopupAlignmentDelegate::StartObserving(gfx::Screen* screen, 48 void AshPopupAlignmentDelegate::StartObserving(gfx::Screen* screen,
48 const gfx::Display& display) { 49 const gfx::Display& display) {
49 screen_ = screen; 50 screen_ = screen;
50 work_area_ = display.work_area(); 51 work_area_ = display.work_area();
51 root_window_ = ash::Shell::GetInstance() 52 root_window_ = ash::Shell::GetInstance()
52 ->window_tree_host_manager() 53 ->window_tree_host_manager()
53 ->GetRootWindowForDisplayId(display.id()); 54 ->GetRootWindowForDisplayId(display.id());
54 UpdateShelf();
55 screen->AddObserver(this); 55 screen->AddObserver(this);
56 Shell::GetInstance()->AddShellObserver(this); 56 Shell::GetInstance()->AddShellObserver(this);
57 if (system_tray_height_ > 0) 57 if (system_tray_height_ > 0)
58 UpdateWorkArea(); 58 UpdateWorkArea();
59 } 59 }
60 60
61 void AshPopupAlignmentDelegate::SetSystemTrayHeight(int height) { 61 void AshPopupAlignmentDelegate::SetSystemTrayHeight(int height) {
62 system_tray_height_ = height; 62 system_tray_height_ = height;
63 63
64 // If the shelf is shown during auto-hide state, the distance from the edge 64 // If the shelf is shown during auto-hide state, the distance from the edge
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 void AshPopupAlignmentDelegate::RecomputeAlignment( 114 void AshPopupAlignmentDelegate::RecomputeAlignment(
115 const gfx::Display& display) { 115 const gfx::Display& display) {
116 // Nothing needs to be done. 116 // Nothing needs to be done.
117 } 117 }
118 118
119 ShelfAlignment AshPopupAlignmentDelegate::GetAlignment() const { 119 ShelfAlignment AshPopupAlignmentDelegate::GetAlignment() const {
120 return shelf_ ? shelf_->GetAlignment() : SHELF_ALIGNMENT_BOTTOM; 120 return shelf_ ? shelf_->GetAlignment() : SHELF_ALIGNMENT_BOTTOM;
121 } 121 }
122 122
123 void AshPopupAlignmentDelegate::UpdateShelf() {
124 if (shelf_)
125 return;
126
127 shelf_ = ShelfLayoutManager::ForShelf(root_window_);
128 if (shelf_)
129 shelf_->AddObserver(this);
130 }
131
132 gfx::Display AshPopupAlignmentDelegate::GetCurrentDisplay() const { 123 gfx::Display AshPopupAlignmentDelegate::GetCurrentDisplay() const {
133 return gfx::Screen::GetScreen()->GetDisplayNearestWindow( 124 return gfx::Screen::GetScreen()->GetDisplayNearestWindow(
134 shelf_->shelf_widget()->GetNativeView()); 125 shelf_->shelf_widget()->GetNativeView());
135 } 126 }
136 127
137 void AshPopupAlignmentDelegate::UpdateWorkArea() { 128 void AshPopupAlignmentDelegate::UpdateWorkArea() {
138 work_area_ = shelf_->user_work_area_bounds(); 129 work_area_ = shelf_->user_work_area_bounds();
139 DoUpdateIfPossible(); 130 DoUpdateIfPossible();
140 } 131 }
141 132
142 void AshPopupAlignmentDelegate::OnDisplayWorkAreaInsetsChanged() { 133 void AshPopupAlignmentDelegate::OnDisplayWorkAreaInsetsChanged() {
143 UpdateShelf();
144 UpdateWorkArea(); 134 UpdateWorkArea();
145 } 135 }
146 136
147 void AshPopupAlignmentDelegate::WillChangeVisibilityState( 137 void AshPopupAlignmentDelegate::WillChangeVisibilityState(
148 ShelfVisibilityState new_state) { 138 ShelfVisibilityState new_state) {
149 UpdateWorkArea(); 139 UpdateWorkArea();
150 } 140 }
151 141
152 void AshPopupAlignmentDelegate::OnAutoHideStateChanged( 142 void AshPopupAlignmentDelegate::OnAutoHideStateChanged(
153 ShelfAutoHideState new_state) { 143 ShelfAutoHideState new_state) {
154 UpdateWorkArea(); 144 UpdateWorkArea();
155 } 145 }
156 146
157 void AshPopupAlignmentDelegate::OnDisplayAdded( 147 void AshPopupAlignmentDelegate::OnDisplayAdded(
158 const gfx::Display& new_display) { 148 const gfx::Display& new_display) {
159 } 149 }
160 150
161 void AshPopupAlignmentDelegate::OnDisplayRemoved( 151 void AshPopupAlignmentDelegate::OnDisplayRemoved(
162 const gfx::Display& old_display) { 152 const gfx::Display& old_display) {
163 } 153 }
164 154
165 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged( 155 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged(
166 const gfx::Display& display, 156 const gfx::Display& display,
167 uint32_t metrics) { 157 uint32_t metrics) {
168 UpdateShelf();
169 if (shelf_ && GetCurrentDisplay().id() == display.id()) 158 if (shelf_ && GetCurrentDisplay().id() == display.id())
170 UpdateWorkArea(); 159 UpdateWorkArea();
171 } 160 }
172 161
173 } // namespace ash 162 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698