OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/shelf/shelf_widget.h" | 5 #include "ash/shelf/shelf_widget.h" |
6 | 6 |
7 #include "ash/animation/animation_change_type.h" | 7 #include "ash/animation/animation_change_type.h" |
8 #include "ash/focus_cycler.h" | 8 #include "ash/focus_cycler.h" |
9 #include "ash/public/cpp/window_properties.h" | 9 #include "ash/public/cpp/window_properties.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
11 #include "ash/session/session_controller.h" | 11 #include "ash/session/session_controller.h" |
12 #include "ash/shelf/app_list_button.h" | 12 #include "ash/shelf/app_list_button.h" |
13 #include "ash/shelf/shelf.h" | 13 #include "ash/shelf/shelf.h" |
14 #include "ash/shelf/shelf_background_animator_observer.h" | 14 #include "ash/shelf/shelf_background_animator_observer.h" |
15 #include "ash/shelf/shelf_constants.h" | 15 #include "ash/shelf/shelf_constants.h" |
16 #include "ash/shelf/shelf_layout_manager.h" | 16 #include "ash/shelf/shelf_layout_manager.h" |
17 #include "ash/shelf/shelf_view.h" | 17 #include "ash/shelf/shelf_view.h" |
18 #include "ash/shell.h" | 18 #include "ash/shell.h" |
19 #include "ash/system/status_area_layout_manager.h" | 19 #include "ash/system/status_area_layout_manager.h" |
20 #include "ash/system/status_area_widget.h" | 20 #include "ash/system/status_area_widget.h" |
21 #include "ash/wm_window.h" | |
22 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
23 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
25 #include "ui/gfx/skbitmap_operations.h" | 24 #include "ui/gfx/skbitmap_operations.h" |
26 #include "ui/views/accessible_pane_view.h" | 25 #include "ui/views/accessible_pane_view.h" |
27 #include "ui/views/layout/fill_layout.h" | 26 #include "ui/views/layout/fill_layout.h" |
28 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
29 #include "ui/views/widget/widget_delegate.h" | 28 #include "ui/views/widget/widget_delegate.h" |
| 29 #include "ui/wm/core/coordinate_conversion.h" |
30 | 30 |
31 namespace ash { | 31 namespace ash { |
32 | 32 |
33 // The contents view of the Shelf. This view contains ShelfView and | 33 // The contents view of the Shelf. This view contains ShelfView and |
34 // sizes it to the width of the shelf minus the size of the status area. | 34 // sizes it to the width of the shelf minus the size of the status area. |
35 class ShelfWidget::DelegateView : public views::WidgetDelegate, | 35 class ShelfWidget::DelegateView : public views::WidgetDelegate, |
36 public views::AccessiblePaneView, | 36 public views::AccessiblePaneView, |
37 public ShelfBackgroundAnimatorObserver { | 37 public ShelfBackgroundAnimatorObserver { |
38 public: | 38 public: |
39 explicit DelegateView(ShelfWidget* shelf); | 39 explicit DelegateView(ShelfWidget* shelf); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { | 116 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { |
117 opaque_background_.SetBounds(GetLocalBounds()); | 117 opaque_background_.SetBounds(GetLocalBounds()); |
118 opaque_foreground_.SetBounds(GetLocalBounds()); | 118 opaque_foreground_.SetBounds(GetLocalBounds()); |
119 } | 119 } |
120 | 120 |
121 void ShelfWidget::DelegateView::UpdateShelfBackground(SkColor color) { | 121 void ShelfWidget::DelegateView::UpdateShelfBackground(SkColor color) { |
122 opaque_background_.SetColor(color); | 122 opaque_background_.SetColor(color); |
123 } | 123 } |
124 | 124 |
125 ShelfWidget::ShelfWidget(WmWindow* shelf_container, Shelf* shelf) | 125 ShelfWidget::ShelfWidget(aura::Window* shelf_container, Shelf* shelf) |
126 : shelf_(shelf), | 126 : shelf_(shelf), |
127 status_area_widget_(nullptr), | 127 status_area_widget_(nullptr), |
128 delegate_view_(new DelegateView(this)), | 128 delegate_view_(new DelegateView(this)), |
129 shelf_view_(new ShelfView(Shell::Get()->shelf_model(), shelf_, this)), | 129 shelf_view_(new ShelfView(Shell::Get()->shelf_model(), shelf_, this)), |
130 background_animator_(SHELF_BACKGROUND_DEFAULT, | 130 background_animator_(SHELF_BACKGROUND_DEFAULT, |
131 shelf_, | 131 shelf_, |
132 Shell::Get()->wallpaper_controller()), | 132 Shell::Get()->wallpaper_controller()), |
133 activating_as_fallback_(false) { | 133 activating_as_fallback_(false) { |
134 DCHECK(shelf_container); | 134 DCHECK(shelf_container); |
135 DCHECK(shelf_); | 135 DCHECK(shelf_); |
136 | 136 |
137 views::Widget::InitParams params( | 137 views::Widget::InitParams params( |
138 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 138 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
139 params.name = "ShelfWidget"; | 139 params.name = "ShelfWidget"; |
140 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 140 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
141 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 141 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
142 params.delegate = delegate_view_; | 142 params.delegate = delegate_view_; |
143 shelf_container->GetRootWindowController() | 143 RootWindowController::ForWindow(shelf_container) |
144 ->ConfigureWidgetInitParamsForContainer( | 144 ->ConfigureWidgetInitParamsForContainer(this, shelf_container->id(), |
145 this, shelf_container->aura_window()->id(), ¶ms); | 145 ¶ms); |
146 Init(params); | 146 Init(params); |
147 | 147 |
148 // The shelf should not take focus when initially shown. | 148 // The shelf should not take focus when initially shown. |
149 set_focus_on_creation(false); | 149 set_focus_on_creation(false); |
150 SetContentsView(delegate_view_); | 150 SetContentsView(delegate_view_); |
151 delegate_view_->SetParentLayer(GetLayer()); | 151 delegate_view_->SetParentLayer(GetLayer()); |
152 | 152 |
153 // The shelf view observes the shelf model and creates icons as items are | 153 // The shelf view observes the shelf model and creates icons as items are |
154 // added to the model. | 154 // added to the model. |
155 shelf_view_->Init(); | 155 shelf_view_->Init(); |
156 GetContentsView()->AddChildView(shelf_view_); | 156 GetContentsView()->AddChildView(shelf_view_); |
157 | 157 |
158 shelf_layout_manager_ = new ShelfLayoutManager(this, shelf_); | 158 shelf_layout_manager_ = new ShelfLayoutManager(this, shelf_); |
159 shelf_layout_manager_->AddObserver(this); | 159 shelf_layout_manager_->AddObserver(this); |
160 shelf_container->aura_window()->SetLayoutManager(shelf_layout_manager_); | 160 shelf_container->SetLayoutManager(shelf_layout_manager_); |
161 background_animator_.PaintBackground( | 161 background_animator_.PaintBackground( |
162 shelf_layout_manager_->GetShelfBackgroundType(), | 162 shelf_layout_manager_->GetShelfBackgroundType(), |
163 AnimationChangeType::IMMEDIATE); | 163 AnimationChangeType::IMMEDIATE); |
164 | 164 |
165 views::Widget::AddObserver(this); | 165 views::Widget::AddObserver(this); |
166 | 166 |
167 // Calls back into |this| and depends on |shelf_view_|. | 167 // Calls back into |this| and depends on |shelf_view_|. |
168 background_animator_.AddObserver(this); | 168 background_animator_.AddObserver(this); |
169 background_animator_.AddObserver(delegate_view_); | 169 background_animator_.AddObserver(delegate_view_); |
170 } | 170 } |
171 | 171 |
172 ShelfWidget::~ShelfWidget() { | 172 ShelfWidget::~ShelfWidget() { |
173 // Must call Shutdown() before destruction. | 173 // Must call Shutdown() before destruction. |
174 DCHECK(!status_area_widget_); | 174 DCHECK(!status_area_widget_); |
175 background_animator_.RemoveObserver(delegate_view_); | 175 background_animator_.RemoveObserver(delegate_view_); |
176 background_animator_.RemoveObserver(this); | 176 background_animator_.RemoveObserver(this); |
177 Shell::Get()->focus_cycler()->RemoveWidget(this); | 177 Shell::Get()->focus_cycler()->RemoveWidget(this); |
178 SetFocusCycler(nullptr); | 178 SetFocusCycler(nullptr); |
179 RemoveObserver(this); | 179 RemoveObserver(this); |
180 } | 180 } |
181 | 181 |
182 void ShelfWidget::CreateStatusAreaWidget(WmWindow* status_container) { | 182 void ShelfWidget::CreateStatusAreaWidget(aura::Window* status_container) { |
183 DCHECK(status_container); | 183 DCHECK(status_container); |
184 DCHECK(!status_area_widget_); | 184 DCHECK(!status_area_widget_); |
185 status_area_widget_ = | 185 status_area_widget_ = new StatusAreaWidget(status_container, shelf_); |
186 new StatusAreaWidget(status_container->aura_window(), shelf_); | |
187 status_area_widget_->CreateTrayViews(); | 186 status_area_widget_->CreateTrayViews(); |
188 // NOTE: Container may be hidden depending on login/display state. | 187 // NOTE: Container may be hidden depending on login/display state. |
189 status_area_widget_->Show(); | 188 status_area_widget_->Show(); |
190 Shell::Get()->focus_cycler()->AddWidget(status_area_widget_); | 189 Shell::Get()->focus_cycler()->AddWidget(status_area_widget_); |
191 background_animator_.AddObserver(status_area_widget_); | 190 background_animator_.AddObserver(status_area_widget_); |
192 status_container->aura_window()->SetLayoutManager( | 191 status_container->SetLayoutManager(new StatusAreaLayoutManager(this)); |
193 new StatusAreaLayoutManager(this)); | |
194 } | 192 } |
195 | 193 |
196 void ShelfWidget::SetPaintsBackground(ShelfBackgroundType background_type, | 194 void ShelfWidget::SetPaintsBackground(ShelfBackgroundType background_type, |
197 AnimationChangeType change_type) { | 195 AnimationChangeType change_type) { |
198 background_animator_.PaintBackground(background_type, change_type); | 196 background_animator_.PaintBackground(background_type, change_type); |
199 } | 197 } |
200 | 198 |
201 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 199 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
202 return background_animator_.target_background_type(); | 200 return background_animator_.target_background_type(); |
203 } | 201 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (status_area_widget_) { | 271 if (status_area_widget_) { |
274 background_animator_.RemoveObserver(status_area_widget_); | 272 background_animator_.RemoveObserver(status_area_widget_); |
275 Shell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); | 273 Shell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); |
276 status_area_widget_->Shutdown(); | 274 status_area_widget_->Shutdown(); |
277 status_area_widget_ = nullptr; | 275 status_area_widget_ = nullptr; |
278 } | 276 } |
279 | 277 |
280 CloseNow(); | 278 CloseNow(); |
281 } | 279 } |
282 | 280 |
283 void ShelfWidget::UpdateIconPositionForPanel(WmWindow* panel) { | 281 void ShelfWidget::UpdateIconPositionForPanel(aura::Window* panel) { |
284 ShelfID id = | 282 ShelfID id = ShelfID::Deserialize(panel->GetProperty(kShelfIDKey)); |
285 ShelfID::Deserialize(panel->aura_window()->GetProperty(kShelfIDKey)); | |
286 if (id.IsNull()) | 283 if (id.IsNull()) |
287 return; | 284 return; |
288 | 285 |
289 WmWindow* shelf_window = WmWindow::Get(this->GetNativeWindow()); | 286 aura::Window* shelf_window = this->GetNativeWindow(); |
290 shelf_view_->UpdatePanelIconPosition( | 287 gfx::Rect bounds = panel->GetBoundsInScreen(); |
291 id, shelf_window->ConvertRectFromScreen(panel->GetBoundsInScreen()) | 288 ::wm::ConvertRectFromScreen(shelf_window, &bounds); |
292 .CenterPoint()); | 289 shelf_view_->UpdatePanelIconPosition(id, bounds.CenterPoint()); |
293 } | 290 } |
294 | 291 |
295 gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | 292 gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow( |
296 ShelfID id = | 293 aura::Window* window) { |
297 ShelfID::Deserialize(window->aura_window()->GetProperty(kShelfIDKey)); | 294 ShelfID id = ShelfID::Deserialize(window->GetProperty(kShelfIDKey)); |
298 if (id.IsNull()) | 295 if (id.IsNull()) |
299 return gfx::Rect(); | 296 return gfx::Rect(); |
300 | 297 |
301 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); | 298 gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id)); |
302 gfx::Point screen_origin; | 299 gfx::Point screen_origin; |
303 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); | 300 views::View::ConvertPointToScreen(shelf_view_, &screen_origin); |
304 return gfx::Rect(screen_origin.x() + bounds.x(), | 301 return gfx::Rect(screen_origin.x() + bounds.x(), |
305 screen_origin.y() + bounds.y(), bounds.width(), | 302 screen_origin.y() + bounds.y(), bounds.width(), |
306 bounds.height()); | 303 bounds.height()); |
307 } | 304 } |
(...skipping 19 matching lines...) Expand all Loading... |
327 void ShelfWidget::UpdateShelfItemBackground(SkColor color) { | 324 void ShelfWidget::UpdateShelfItemBackground(SkColor color) { |
328 shelf_view_->UpdateShelfItemBackground(color); | 325 shelf_view_->UpdateShelfItemBackground(color); |
329 } | 326 } |
330 | 327 |
331 void ShelfWidget::WillDeleteShelfLayoutManager() { | 328 void ShelfWidget::WillDeleteShelfLayoutManager() { |
332 shelf_layout_manager_->RemoveObserver(this); | 329 shelf_layout_manager_->RemoveObserver(this); |
333 shelf_layout_manager_ = nullptr; | 330 shelf_layout_manager_ = nullptr; |
334 } | 331 } |
335 | 332 |
336 } // namespace ash | 333 } // namespace ash |
OLD | NEW |