OLD | NEW |
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/display_controller.h" | 7 #include "ash/display/display_controller.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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 const gfx::Display& display) { | 48 const gfx::Display& display) { |
49 screen_ = screen; | 49 screen_ = screen; |
50 work_area_ = display.work_area(); | 50 work_area_ = display.work_area(); |
51 root_window_ = ash::Shell::GetInstance() | 51 root_window_ = ash::Shell::GetInstance() |
52 ->display_controller() | 52 ->display_controller() |
53 ->GetRootWindowForDisplayId(display.id()); | 53 ->GetRootWindowForDisplayId(display.id()); |
54 UpdateShelf(); | 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(display, shelf_->auto_hide_state()); |
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 |
65 // should be reduced by the height of shelf's shown height. | 65 // should be reduced by the height of shelf's shown height. |
66 if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE && | 66 if (shelf_ && shelf_->visibility_state() == SHELF_AUTO_HIDE && |
67 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { | 67 shelf_->auto_hide_state() == SHELF_AUTO_HIDE_SHOWN) { |
68 system_tray_height_ -= kShelfSize - ShelfLayoutManager::kAutoHideSize; | 68 system_tray_height_ -= kShelfSize - ShelfLayoutManager::kAutoHideSize; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 shelf_ = ShelfLayoutManager::ForShelf(root_window_); | 127 shelf_ = ShelfLayoutManager::ForShelf(root_window_); |
128 if (shelf_) | 128 if (shelf_) |
129 shelf_->AddObserver(this); | 129 shelf_->AddObserver(this); |
130 } | 130 } |
131 | 131 |
132 gfx::Display AshPopupAlignmentDelegate::GetCurrentDisplay() const { | 132 gfx::Display AshPopupAlignmentDelegate::GetCurrentDisplay() const { |
133 return Shell::GetScreen()->GetDisplayNearestWindow( | 133 return Shell::GetScreen()->GetDisplayNearestWindow( |
134 shelf_->shelf_widget()->GetNativeView()); | 134 shelf_->shelf_widget()->GetNativeView()); |
135 } | 135 } |
136 | 136 |
137 void AshPopupAlignmentDelegate::UpdateWorkArea() { | 137 void AshPopupAlignmentDelegate::UpdateWorkArea(const gfx::Display& display, |
138 work_area_ = shelf_->non_shelf_bounds(); | 138 ShelfAutoHideState new_state) { |
| 139 work_area_ = display.work_area(); |
| 140 if (Shell::GetInstance()->display_manager()->IsInUnifiedMode()) { |
| 141 gfx::Rect bounds = ScreenUtil::GetShelfDisplayBoundsInScreen( |
| 142 shelf_->shelf_widget()->GetNativeView()); |
| 143 work_area_.Intersect(bounds); |
| 144 } |
| 145 |
| 146 int width = 0; |
| 147 if (shelf_ && (shelf_->visibility_state() == SHELF_AUTO_HIDE) && |
| 148 new_state == SHELF_AUTO_HIDE_SHOWN) { |
| 149 // Since the work_area is already reduced by kAutoHideSize, the inset width |
| 150 // should be just the difference. |
| 151 width = kShelfSize - ShelfLayoutManager::kAutoHideSize; |
| 152 } |
| 153 work_area_.Inset(shelf_->SelectValueForShelfAlignment( |
| 154 gfx::Insets(0, 0, width, 0), |
| 155 gfx::Insets(0, width, 0, 0), |
| 156 gfx::Insets(0, 0, 0, width), |
| 157 gfx::Insets(width, 0, 0, 0))); |
| 158 |
139 DoUpdateIfPossible(); | 159 DoUpdateIfPossible(); |
140 } | 160 } |
141 | 161 |
142 void AshPopupAlignmentDelegate::OnDisplayWorkAreaInsetsChanged() { | 162 void AshPopupAlignmentDelegate::OnDisplayWorkAreaInsetsChanged() { |
143 UpdateShelf(); | 163 UpdateShelf(); |
144 UpdateWorkArea(); | 164 UpdateWorkArea(GetCurrentDisplay(), shelf_->auto_hide_state()); |
145 } | 165 } |
146 | 166 |
147 void AshPopupAlignmentDelegate::OnAutoHideStateChanged( | 167 void AshPopupAlignmentDelegate::OnAutoHideStateChanged( |
148 ShelfAutoHideState new_state) { | 168 ShelfAutoHideState new_state) { |
149 UpdateWorkArea(); | 169 UpdateWorkArea(GetCurrentDisplay(), new_state); |
150 } | 170 } |
151 | 171 |
152 void AshPopupAlignmentDelegate::OnDisplayAdded( | 172 void AshPopupAlignmentDelegate::OnDisplayAdded( |
153 const gfx::Display& new_display) { | 173 const gfx::Display& new_display) { |
154 } | 174 } |
155 | 175 |
156 void AshPopupAlignmentDelegate::OnDisplayRemoved( | 176 void AshPopupAlignmentDelegate::OnDisplayRemoved( |
157 const gfx::Display& old_display) { | 177 const gfx::Display& old_display) { |
158 } | 178 } |
159 | 179 |
160 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged( | 180 void AshPopupAlignmentDelegate::OnDisplayMetricsChanged( |
161 const gfx::Display& display, | 181 const gfx::Display& display, |
162 uint32_t metrics) { | 182 uint32_t metrics) { |
163 UpdateShelf(); | 183 UpdateShelf(); |
164 if (shelf_ && GetCurrentDisplay().id() == display.id()) | 184 if (shelf_ && GetCurrentDisplay().id() == display.id()) |
165 UpdateWorkArea(); | 185 UpdateWorkArea(display, shelf_->auto_hide_state()); |
166 } | 186 } |
167 | 187 |
168 } // namespace ash | 188 } // namespace ash |
OLD | NEW |