OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/wm/panels/panel_layout_manager.h" | 5 #include "ash/wm/panels/panel_layout_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "third_party/skia/include/core/SkColor.h" | 26 #include "third_party/skia/include/core/SkColor.h" |
27 #include "third_party/skia/include/core/SkPath.h" | 27 #include "third_party/skia/include/core/SkPath.h" |
28 #include "ui/aura/client/window_parenting_client.h" | 28 #include "ui/aura/client/window_parenting_client.h" |
29 #include "ui/aura/window_delegate.h" | 29 #include "ui/aura/window_delegate.h" |
30 #include "ui/compositor/scoped_layer_animation_settings.h" | 30 #include "ui/compositor/scoped_layer_animation_settings.h" |
31 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
32 #include "ui/gfx/geometry/rect.h" | 32 #include "ui/gfx/geometry/rect.h" |
33 #include "ui/gfx/geometry/vector2d.h" | 33 #include "ui/gfx/geometry/vector2d.h" |
34 #include "ui/views/background.h" | 34 #include "ui/views/background.h" |
35 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 36 #include "ui/wm/core/coordinate_conversion.h" |
36 #include "ui/wm/core/window_util.h" | 37 #include "ui/wm/core/window_util.h" |
37 #include "ui/wm/public/activation_client.h" | 38 #include "ui/wm/public/activation_client.h" |
38 | 39 |
39 using aura::Window; | 40 using aura::Window; |
40 | 41 |
41 namespace ash { | 42 namespace ash { |
42 namespace { | 43 namespace { |
43 | 44 |
44 const int kPanelIdealSpacing = 4; | 45 const int kPanelIdealSpacing = 4; |
45 | 46 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 max_major(0), | 108 max_major(0), |
108 major_pos(0), | 109 major_pos(0), |
109 major_length(0), | 110 major_length(0), |
110 window(nullptr), | 111 window(nullptr), |
111 slide_in(false) {} | 112 slide_in(false) {} |
112 | 113 |
113 int min_major; | 114 int min_major; |
114 int max_major; | 115 int max_major; |
115 int major_pos; | 116 int major_pos; |
116 int major_length; | 117 int major_length; |
117 WmWindow* window; | 118 Window* window; |
118 bool slide_in; | 119 bool slide_in; |
119 }; | 120 }; |
120 | 121 |
121 bool CompareWindowMajor(const VisiblePanelPositionInfo& win1, | 122 bool CompareWindowMajor(const VisiblePanelPositionInfo& win1, |
122 const VisiblePanelPositionInfo& win2) { | 123 const VisiblePanelPositionInfo& win2) { |
123 return win1.major_pos < win2.major_pos; | 124 return win1.major_pos < win2.major_pos; |
124 } | 125 } |
125 | 126 |
126 void FanOutPanels(std::vector<VisiblePanelPositionInfo>::iterator first, | 127 void FanOutPanels(std::vector<VisiblePanelPositionInfo>::iterator first, |
127 std::vector<VisiblePanelPositionInfo>::iterator last) { | 128 std::vector<VisiblePanelPositionInfo>::iterator last) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 offset.set_x(kPanelSlideInOffset); | 177 offset.set_x(kPanelSlideInOffset); |
177 else | 178 else |
178 offset.set_y(kPanelSlideInOffset); | 179 offset.set_y(kPanelSlideInOffset); |
179 return offset; | 180 return offset; |
180 } | 181 } |
181 | 182 |
182 } // namespace | 183 } // namespace |
183 | 184 |
184 class PanelCalloutWidget : public views::Widget { | 185 class PanelCalloutWidget : public views::Widget { |
185 public: | 186 public: |
186 explicit PanelCalloutWidget(WmWindow* container) : background_(nullptr) { | 187 explicit PanelCalloutWidget(Window* container) : background_(nullptr) { |
187 InitWidget(container); | 188 InitWidget(container); |
188 } | 189 } |
189 | 190 |
190 // Updates the bounds based on the shelf alignment. | 191 // Updates the bounds based on the shelf alignment. |
191 void UpdateBounds(WmShelf* shelf) { | 192 void UpdateBounds(WmShelf* shelf) { |
192 WmWindow* window = WmWindow::Get(this->GetNativeWindow()); | 193 Window* window = this->GetNativeWindow(); |
193 gfx::Rect callout_bounds = window->GetBounds(); | 194 gfx::Rect callout_bounds = window->bounds(); |
194 if (shelf->IsHorizontalAlignment()) { | 195 if (shelf->IsHorizontalAlignment()) { |
195 callout_bounds.set_width(kArrowWidth); | 196 callout_bounds.set_width(kArrowWidth); |
196 callout_bounds.set_height(kArrowHeight); | 197 callout_bounds.set_height(kArrowHeight); |
197 } else { | 198 } else { |
198 callout_bounds.set_width(kArrowHeight); | 199 callout_bounds.set_width(kArrowHeight); |
199 callout_bounds.set_height(kArrowWidth); | 200 callout_bounds.set_height(kArrowWidth); |
200 } | 201 } |
201 WmWindow* parent = window->GetParent(); | 202 Window* parent = window->parent(); |
202 // It's important this go through WmWindow and not Widget. Going through | 203 // It's important this go through WmWindow and not Widget. Going through |
203 // Widget means it may move do a different screen, we don't want that. | 204 // Widget means it may move do a different screen, we don't want that. |
204 window->SetBounds(callout_bounds); | 205 window->SetBounds(callout_bounds); |
205 // Setting the bounds should not trigger changing the parent. | 206 // Setting the bounds should not trigger changing the parent. |
206 DCHECK_EQ(parent, window->GetParent()); | 207 DCHECK_EQ(parent, window->parent()); |
207 if (background_->alignment() != shelf->alignment()) { | 208 if (background_->alignment() != shelf->alignment()) { |
208 background_->set_alignment(shelf->alignment()); | 209 background_->set_alignment(shelf->alignment()); |
209 SchedulePaintInRect(gfx::Rect(callout_bounds.size())); | 210 SchedulePaintInRect(gfx::Rect(callout_bounds.size())); |
210 } | 211 } |
211 } | 212 } |
212 | 213 |
213 private: | 214 private: |
214 void InitWidget(WmWindow* parent) { | 215 void InitWidget(Window* parent) { |
215 views::Widget::InitParams params; | 216 views::Widget::InitParams params; |
216 params.type = views::Widget::InitParams::TYPE_POPUP; | 217 params.type = views::Widget::InitParams::TYPE_POPUP; |
217 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 218 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
218 params.keep_on_top = true; | 219 params.keep_on_top = true; |
219 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 220 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
220 params.bounds = parent->ConvertRectToScreen(gfx::Rect()); | 221 ::wm::ConvertRectToScreen(parent, ¶ms.bounds); |
221 params.bounds.set_width(kArrowWidth); | 222 params.bounds.set_width(kArrowWidth); |
222 params.bounds.set_height(kArrowHeight); | 223 params.bounds.set_height(kArrowHeight); |
223 params.accept_events = false; | 224 params.accept_events = false; |
224 parent->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | 225 RootWindowController::ForWindow(parent) |
225 this, parent->aura_window()->id(), ¶ms); | 226 ->ConfigureWidgetInitParamsForContainer(this, parent->id(), ¶ms); |
226 set_focus_on_creation(false); | 227 set_focus_on_creation(false); |
227 Init(params); | 228 Init(params); |
228 WmWindow* widget_window = WmWindow::Get(this->GetNativeWindow()); | 229 Window* widget_window = this->GetNativeWindow(); |
229 DCHECK_EQ(widget_window->GetRootWindow(), parent->GetRootWindow()); | 230 DCHECK_EQ(widget_window->GetRootWindow(), parent->GetRootWindow()); |
230 views::View* content_view = new views::View; | 231 views::View* content_view = new views::View; |
231 background_ = new CalloutWidgetBackground; | 232 background_ = new CalloutWidgetBackground; |
232 content_view->set_background(background_); | 233 content_view->set_background(background_); |
233 SetContentsView(content_view); | 234 SetContentsView(content_view); |
234 widget_window->GetLayer()->SetOpacity(0); | 235 widget_window->layer()->SetOpacity(0); |
235 } | 236 } |
236 | 237 |
237 // Weak pointer owned by this widget's content view. | 238 // Weak pointer owned by this widget's content view. |
238 CalloutWidgetBackground* background_; | 239 CalloutWidgetBackground* background_; |
239 | 240 |
240 DISALLOW_COPY_AND_ASSIGN(PanelCalloutWidget); | 241 DISALLOW_COPY_AND_ASSIGN(PanelCalloutWidget); |
241 }; | 242 }; |
242 | 243 |
243 views::Widget* PanelLayoutManager::PanelInfo::CalloutWidget() { | 244 views::Widget* PanelLayoutManager::PanelInfo::CalloutWidget() { |
244 return callout_widget; | 245 return callout_widget; |
245 } | 246 } |
246 | 247 |
247 //////////////////////////////////////////////////////////////////////////////// | 248 //////////////////////////////////////////////////////////////////////////////// |
248 // PanelLayoutManager public implementation: | 249 // PanelLayoutManager public implementation: |
249 PanelLayoutManager::PanelLayoutManager(WmWindow* panel_container) | 250 PanelLayoutManager::PanelLayoutManager(Window* panel_container) |
250 : panel_container_(panel_container), | 251 : panel_container_(panel_container), |
251 root_window_controller_(panel_container->GetRootWindowController()), | 252 root_window_controller_(RootWindowController::ForWindow(panel_container)), |
252 in_add_window_(false), | 253 in_add_window_(false), |
253 in_layout_(false), | 254 in_layout_(false), |
254 show_callout_widgets_(true), | 255 show_callout_widgets_(true), |
255 dragged_panel_(nullptr), | 256 dragged_panel_(nullptr), |
256 shelf_(nullptr), | 257 shelf_(nullptr), |
257 last_active_panel_(nullptr), | 258 last_active_panel_(nullptr), |
258 keyboard_observer_(this), | 259 keyboard_observer_(this), |
259 weak_factory_(this) { | 260 weak_factory_(this) { |
260 DCHECK(panel_container); | 261 DCHECK(panel_container); |
261 Shell::Get()->activation_client()->AddObserver(this); | 262 Shell::Get()->activation_client()->AddObserver(this); |
262 ShellPort::Get()->AddDisplayObserver(this); | 263 ShellPort::Get()->AddDisplayObserver(this); |
263 Shell::Get()->AddShellObserver(this); | 264 Shell::Get()->AddShellObserver(this); |
264 } | 265 } |
265 | 266 |
266 PanelLayoutManager::~PanelLayoutManager() { | 267 PanelLayoutManager::~PanelLayoutManager() { |
267 Shutdown(); | 268 Shutdown(); |
268 } | 269 } |
269 | 270 |
270 // static | 271 // static |
271 PanelLayoutManager* PanelLayoutManager::Get(WmWindow* window) { | 272 PanelLayoutManager* PanelLayoutManager::Get(Window* window) { |
272 if (!window) | 273 if (!window) |
273 return nullptr; | 274 return nullptr; |
274 | 275 |
275 return static_cast<PanelLayoutManager*>( | 276 return static_cast<PanelLayoutManager*>( |
276 window->GetRootWindow() | 277 window->GetRootWindow() |
277 ->aura_window() | |
278 ->GetChildById(kShellWindowId_PanelContainer) | 278 ->GetChildById(kShellWindowId_PanelContainer) |
279 ->layout_manager()); | 279 ->layout_manager()); |
280 } | 280 } |
281 | 281 |
282 void PanelLayoutManager::Shutdown() { | 282 void PanelLayoutManager::Shutdown() { |
283 if (shelf_) { | 283 if (shelf_) { |
284 shelf_->RemoveObserver(this); | 284 shelf_->RemoveObserver(this); |
285 shelf_ = nullptr; | 285 shelf_ = nullptr; |
286 } | 286 } |
287 for (PanelList::iterator iter = panel_windows_.begin(); | 287 for (PanelList::iterator iter = panel_windows_.begin(); |
288 iter != panel_windows_.end(); ++iter) { | 288 iter != panel_windows_.end(); ++iter) { |
289 delete iter->callout_widget; | 289 delete iter->callout_widget; |
290 } | 290 } |
291 panel_windows_.clear(); | 291 panel_windows_.clear(); |
292 Shell::Get()->activation_client()->RemoveObserver(this); | 292 Shell::Get()->activation_client()->RemoveObserver(this); |
293 ShellPort::Get()->RemoveDisplayObserver(this); | 293 ShellPort::Get()->RemoveDisplayObserver(this); |
294 Shell::Get()->RemoveShellObserver(this); | 294 Shell::Get()->RemoveShellObserver(this); |
295 } | 295 } |
296 | 296 |
297 void PanelLayoutManager::StartDragging(WmWindow* panel) { | 297 void PanelLayoutManager::StartDragging(Window* panel) { |
298 DCHECK(!dragged_panel_); | 298 DCHECK(!dragged_panel_); |
299 dragged_panel_ = panel; | 299 dragged_panel_ = panel; |
300 Relayout(); | 300 Relayout(); |
301 } | 301 } |
302 | 302 |
303 void PanelLayoutManager::FinishDragging() { | 303 void PanelLayoutManager::FinishDragging() { |
304 dragged_panel_ = nullptr; | 304 dragged_panel_ = nullptr; |
305 Relayout(); | 305 Relayout(); |
306 } | 306 } |
307 | 307 |
308 void PanelLayoutManager::SetShelf(WmShelf* shelf) { | 308 void PanelLayoutManager::SetShelf(WmShelf* shelf) { |
309 DCHECK(!shelf_); | 309 DCHECK(!shelf_); |
310 shelf_ = shelf; | 310 shelf_ = shelf; |
311 shelf_->AddObserver(this); | 311 shelf_->AddObserver(this); |
312 WillChangeVisibilityState(shelf_->GetVisibilityState()); | 312 WillChangeVisibilityState(shelf_->GetVisibilityState()); |
313 } | 313 } |
314 | 314 |
315 void PanelLayoutManager::ToggleMinimize(WmWindow* panel) { | 315 void PanelLayoutManager::ToggleMinimize(Window* panel) { |
316 DCHECK(panel->GetParent() == panel_container_); | 316 DCHECK(panel->parent() == panel_container_); |
317 wm::WindowState* window_state = panel->GetWindowState(); | 317 wm::WindowState* window_state = wm::GetWindowState(panel); |
318 if (window_state->IsMinimized()) | 318 if (window_state->IsMinimized()) |
319 window_state->Restore(); | 319 window_state->Restore(); |
320 else | 320 else |
321 window_state->Minimize(); | 321 window_state->Minimize(); |
322 } | 322 } |
323 | 323 |
324 void PanelLayoutManager::SetShowCalloutWidgets(bool show) { | 324 void PanelLayoutManager::SetShowCalloutWidgets(bool show) { |
325 if (show_callout_widgets_ == show) | 325 if (show_callout_widgets_ == show) |
326 return; | 326 return; |
327 show_callout_widgets_ = show; | 327 show_callout_widgets_ = show; |
328 UpdateCallouts(); | 328 UpdateCallouts(); |
329 } | 329 } |
330 | 330 |
331 views::Widget* PanelLayoutManager::GetCalloutWidgetForPanel(WmWindow* panel) { | 331 views::Widget* PanelLayoutManager::GetCalloutWidgetForPanel(Window* panel) { |
332 DCHECK(panel->GetParent() == panel_container_); | 332 DCHECK(panel->parent() == panel_container_); |
333 PanelList::iterator found = | 333 PanelList::iterator found = |
334 std::find(panel_windows_.begin(), panel_windows_.end(), panel); | 334 std::find(panel_windows_.begin(), panel_windows_.end(), panel); |
335 DCHECK(found != panel_windows_.end()); | 335 DCHECK(found != panel_windows_.end()); |
336 return found->callout_widget; | 336 return found->callout_widget; |
337 } | 337 } |
338 | 338 |
339 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
340 // PanelLayoutManager, aura::LayoutManager implementation: | 340 // PanelLayoutManager, aura::LayoutManager implementation: |
341 void PanelLayoutManager::OnWindowResized() { | 341 void PanelLayoutManager::OnWindowResized() { |
342 Relayout(); | 342 Relayout(); |
(...skipping 13 matching lines...) Expand all Loading... |
356 // TODO(varkha): Updating bounds during a drag can cause problems and a more | 356 // TODO(varkha): Updating bounds during a drag can cause problems and a more |
357 // general solution is needed. See http://crbug.com/251813 . | 357 // general solution is needed. See http://crbug.com/251813 . |
358 Window* old_parent = child->parent(); | 358 Window* old_parent = child->parent(); |
359 aura::client::ParentWindowWithContext( | 359 aura::client::ParentWindowWithContext( |
360 child, child, child->GetRootWindow()->GetBoundsInScreen()); | 360 child, child, child->GetRootWindow()->GetBoundsInScreen()); |
361 wm::ReparentTransientChildrenOfChild(child, old_parent, child->parent()); | 361 wm::ReparentTransientChildrenOfChild(child, old_parent, child->parent()); |
362 DCHECK(child->parent()->id() != kShellWindowId_PanelContainer); | 362 DCHECK(child->parent()->id() != kShellWindowId_PanelContainer); |
363 return; | 363 return; |
364 } | 364 } |
365 PanelInfo panel_info; | 365 PanelInfo panel_info; |
366 panel_info.window = WmWindow::Get(child); | 366 panel_info.window = child; |
367 panel_info.callout_widget = new PanelCalloutWidget(panel_container_); | 367 panel_info.callout_widget = new PanelCalloutWidget(panel_container_); |
368 panel_info.slide_in = WmWindow::Get(child) != dragged_panel_; | 368 panel_info.slide_in = child != dragged_panel_; |
369 panel_windows_.push_back(panel_info); | 369 panel_windows_.push_back(panel_info); |
370 child->AddObserver(this); | 370 child->AddObserver(this); |
371 wm::GetWindowState(child)->AddObserver(this); | 371 wm::GetWindowState(child)->AddObserver(this); |
372 Relayout(); | 372 Relayout(); |
373 } | 373 } |
374 | 374 |
375 void PanelLayoutManager::OnWillRemoveWindowFromLayout(Window* child) {} | 375 void PanelLayoutManager::OnWillRemoveWindowFromLayout(Window* child) {} |
376 | 376 |
377 void PanelLayoutManager::OnWindowRemovedFromLayout(Window* child) { | 377 void PanelLayoutManager::OnWindowRemovedFromLayout(Window* child) { |
378 if (child->type() == ui::wm::WINDOW_TYPE_POPUP) | 378 if (child->type() == ui::wm::WINDOW_TYPE_POPUP) |
379 return; | 379 return; |
380 | 380 |
381 PanelList::iterator found = std::find( | 381 PanelList::iterator found = |
382 panel_windows_.begin(), panel_windows_.end(), WmWindow::Get(child)); | 382 std::find(panel_windows_.begin(), panel_windows_.end(), child); |
383 if (found != panel_windows_.end()) { | 383 if (found != panel_windows_.end()) { |
384 delete found->callout_widget; | 384 delete found->callout_widget; |
385 panel_windows_.erase(found); | 385 panel_windows_.erase(found); |
386 } | 386 } |
387 if (restore_windows_on_shelf_visible_) | 387 if (restore_windows_on_shelf_visible_) |
388 restore_windows_on_shelf_visible_->Remove(child); | 388 restore_windows_on_shelf_visible_->Remove(child); |
389 child->RemoveObserver(this); | 389 child->RemoveObserver(this); |
390 wm::GetWindowState(child)->RemoveObserver(this); | 390 wm::GetWindowState(child)->RemoveObserver(this); |
391 | 391 |
392 if (dragged_panel_ == WmWindow::Get(child)) | 392 if (dragged_panel_ == child) |
393 dragged_panel_ = nullptr; | 393 dragged_panel_ = nullptr; |
394 | 394 |
395 if (last_active_panel_ == WmWindow::Get(child)) | 395 if (last_active_panel_ == child) |
396 last_active_panel_ = nullptr; | 396 last_active_panel_ = nullptr; |
397 | 397 |
398 Relayout(); | 398 Relayout(); |
399 } | 399 } |
400 | 400 |
401 void PanelLayoutManager::OnChildWindowVisibilityChanged(Window* child, | 401 void PanelLayoutManager::OnChildWindowVisibilityChanged(Window* child, |
402 bool visible) { | 402 bool visible) { |
403 if (visible) | 403 if (visible) |
404 wm::GetWindowState(child)->Restore(); | 404 wm::GetWindowState(child)->Restore(); |
405 Relayout(); | 405 Relayout(); |
406 } | 406 } |
407 | 407 |
408 void PanelLayoutManager::SetChildBounds(Window* child, | 408 void PanelLayoutManager::SetChildBounds(Window* child, |
409 const gfx::Rect& requested_bounds) { | 409 const gfx::Rect& requested_bounds) { |
410 gfx::Rect bounds(requested_bounds); | 410 gfx::Rect bounds(requested_bounds); |
411 const gfx::Rect& max_bounds = panel_container_->GetRootWindow()->GetBounds(); | 411 const gfx::Rect& max_bounds = panel_container_->GetRootWindow()->bounds(); |
412 const int max_width = max_bounds.width() * kMaxWidthFactor; | 412 const int max_width = max_bounds.width() * kMaxWidthFactor; |
413 const int max_height = max_bounds.height() * kMaxHeightFactor; | 413 const int max_height = max_bounds.height() * kMaxHeightFactor; |
414 if (bounds.width() > max_width) | 414 if (bounds.width() > max_width) |
415 bounds.set_width(max_width); | 415 bounds.set_width(max_width); |
416 if (bounds.height() > max_height) | 416 if (bounds.height() > max_height) |
417 bounds.set_height(max_height); | 417 bounds.set_height(max_height); |
418 | 418 |
419 // Reposition dragged panel in the panel order. | 419 // Reposition dragged panel in the panel order. |
420 if (dragged_panel_ == WmWindow::Get(child)) { | 420 if (dragged_panel_ == child) { |
421 PanelList::iterator dragged_panel_iter = | 421 PanelList::iterator dragged_panel_iter = |
422 std::find(panel_windows_.begin(), panel_windows_.end(), dragged_panel_); | 422 std::find(panel_windows_.begin(), panel_windows_.end(), dragged_panel_); |
423 DCHECK(dragged_panel_iter != panel_windows_.end()); | 423 DCHECK(dragged_panel_iter != panel_windows_.end()); |
424 PanelList::iterator new_position; | 424 PanelList::iterator new_position; |
425 for (new_position = panel_windows_.begin(); | 425 for (new_position = panel_windows_.begin(); |
426 new_position != panel_windows_.end(); ++new_position) { | 426 new_position != panel_windows_.end(); ++new_position) { |
427 const gfx::Rect& bounds = (*new_position).window->GetBounds(); | 427 const gfx::Rect& bounds = (*new_position).window->bounds(); |
428 if (bounds.x() + bounds.width() / 2 <= requested_bounds.x()) | 428 if (bounds.x() + bounds.width() / 2 <= requested_bounds.x()) |
429 break; | 429 break; |
430 } | 430 } |
431 if (new_position != dragged_panel_iter) { | 431 if (new_position != dragged_panel_iter) { |
432 PanelInfo dragged_panel_info = *dragged_panel_iter; | 432 PanelInfo dragged_panel_info = *dragged_panel_iter; |
433 panel_windows_.erase(dragged_panel_iter); | 433 panel_windows_.erase(dragged_panel_iter); |
434 panel_windows_.insert(new_position, dragged_panel_info); | 434 panel_windows_.insert(new_position, dragged_panel_info); |
435 } | 435 } |
436 } | 436 } |
437 // Respect the minimum size of the window. | 437 // Respect the minimum size of the window. |
(...skipping 13 matching lines...) Expand all Loading... |
451 | 451 |
452 void PanelLayoutManager::OnOverviewModeEnded() { | 452 void PanelLayoutManager::OnOverviewModeEnded() { |
453 Relayout(); | 453 Relayout(); |
454 } | 454 } |
455 | 455 |
456 void PanelLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) { | 456 void PanelLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) { |
457 if (root_window_controller_->GetWindow() == root_window) | 457 if (root_window_controller_->GetWindow() == root_window) |
458 Relayout(); | 458 Relayout(); |
459 } | 459 } |
460 | 460 |
461 void PanelLayoutManager::OnVirtualKeyboardStateChanged( | 461 void PanelLayoutManager::OnVirtualKeyboardStateChanged(bool activated, |
462 bool activated, | 462 Window* root_window) { |
463 aura::Window* root_window) { | 463 UpdateKeyboardObserverFromStateChanged(activated, root_window, |
464 UpdateKeyboardObserverFromStateChanged( | 464 panel_container_->GetRootWindow(), |
465 activated, root_window, panel_container_->GetRootWindow()->aura_window(), | 465 &keyboard_observer_); |
466 &keyboard_observer_); | |
467 } | 466 } |
468 | 467 |
469 ///////////////////////////////////////////////////////////////////////////// | 468 ///////////////////////////////////////////////////////////////////////////// |
470 // PanelLayoutManager, WindowObserver implementation: | 469 // PanelLayoutManager, WindowObserver implementation: |
471 | 470 |
472 void PanelLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 471 void PanelLayoutManager::OnWindowPropertyChanged(Window* window, |
473 const void* key, | 472 const void* key, |
474 intptr_t old) { | 473 intptr_t old) { |
475 // Trigger a relayout to position the panels whenever the panel icon is set | 474 // Trigger a relayout to position the panels whenever the panel icon is set |
476 // or changes. | 475 // or changes. |
477 if (key == kShelfIDKey) | 476 if (key == kShelfIDKey) |
478 Relayout(); | 477 Relayout(); |
479 } | 478 } |
480 | 479 |
481 ///////////////////////////////////////////////////////////////////////////// | 480 ///////////////////////////////////////////////////////////////////////////// |
482 // PanelLayoutManager, WindowStateObserver implementation: | 481 // PanelLayoutManager, WindowStateObserver implementation: |
(...skipping 16 matching lines...) Expand all Loading... |
499 if (window_state->IsMinimized()) | 498 if (window_state->IsMinimized()) |
500 MinimizePanel(window_state->window()); | 499 MinimizePanel(window_state->window()); |
501 else | 500 else |
502 RestorePanel(window_state->window()); | 501 RestorePanel(window_state->window()); |
503 } | 502 } |
504 | 503 |
505 //////////////////////////////////////////////////////////////////////////////// | 504 //////////////////////////////////////////////////////////////////////////////// |
506 // PanelLayoutManager, aura::client::ActivationChangeObserver implementation: | 505 // PanelLayoutManager, aura::client::ActivationChangeObserver implementation: |
507 | 506 |
508 void PanelLayoutManager::OnWindowActivated(ActivationReason reason, | 507 void PanelLayoutManager::OnWindowActivated(ActivationReason reason, |
509 aura::Window* gained_active, | 508 Window* gained_active, |
510 aura::Window* lost_active) { | 509 Window* lost_active) { |
511 WmWindow* wm_gained_active = WmWindow::Get(gained_active); | |
512 // Ignore if the panel that is not managed by this was activated. | 510 // Ignore if the panel that is not managed by this was activated. |
513 if (wm_gained_active && | 511 if (gained_active && gained_active->type() == ui::wm::WINDOW_TYPE_PANEL && |
514 wm_gained_active->GetType() == ui::wm::WINDOW_TYPE_PANEL && | 512 gained_active->parent() == panel_container_) { |
515 wm_gained_active->GetParent() == panel_container_) { | 513 UpdateStacking(gained_active); |
516 UpdateStacking(wm_gained_active); | |
517 UpdateCallouts(); | 514 UpdateCallouts(); |
518 } | 515 } |
519 } | 516 } |
520 | 517 |
521 //////////////////////////////////////////////////////////////////////////////// | 518 //////////////////////////////////////////////////////////////////////////////// |
522 // PanelLayoutManager, WmDisplayObserver::Observer implementation: | 519 // PanelLayoutManager, WmDisplayObserver::Observer implementation: |
523 | 520 |
524 void PanelLayoutManager::OnDisplayConfigurationChanged() { | 521 void PanelLayoutManager::OnDisplayConfigurationChanged() { |
525 Relayout(); | 522 Relayout(); |
526 } | 523 } |
527 | 524 |
528 //////////////////////////////////////////////////////////////////////////////// | 525 //////////////////////////////////////////////////////////////////////////////// |
529 // PanelLayoutManager, ShelfLayoutManagerObserver implementation: | 526 // PanelLayoutManager, ShelfLayoutManagerObserver implementation: |
530 | 527 |
531 void PanelLayoutManager::WillChangeVisibilityState( | 528 void PanelLayoutManager::WillChangeVisibilityState( |
532 ShelfVisibilityState new_state) { | 529 ShelfVisibilityState new_state) { |
533 // On entering / leaving full screen mode the shelf visibility state is | 530 // On entering / leaving full screen mode the shelf visibility state is |
534 // changed to / from SHELF_HIDDEN. In this state, panel windows should hide | 531 // changed to / from SHELF_HIDDEN. In this state, panel windows should hide |
535 // to allow the full-screen application to use the full screen. | 532 // to allow the full-screen application to use the full screen. |
536 bool shelf_hidden = new_state == ash::SHELF_HIDDEN; | 533 bool shelf_hidden = new_state == ash::SHELF_HIDDEN; |
537 if (!shelf_hidden) { | 534 if (!shelf_hidden) { |
538 if (restore_windows_on_shelf_visible_) { | 535 if (restore_windows_on_shelf_visible_) { |
539 std::unique_ptr<aura::WindowTracker> restore_windows( | 536 std::unique_ptr<aura::WindowTracker> restore_windows( |
540 std::move(restore_windows_on_shelf_visible_)); | 537 std::move(restore_windows_on_shelf_visible_)); |
541 for (aura::Window* window : restore_windows->windows()) | 538 for (Window* window : restore_windows->windows()) |
542 RestorePanel(window); | 539 RestorePanel(window); |
543 } | 540 } |
544 return; | 541 return; |
545 } | 542 } |
546 | 543 |
547 if (restore_windows_on_shelf_visible_) | 544 if (restore_windows_on_shelf_visible_) |
548 return; | 545 return; |
549 std::unique_ptr<aura::WindowTracker> minimized_windows( | 546 std::unique_ptr<aura::WindowTracker> minimized_windows( |
550 new aura::WindowTracker); | 547 new aura::WindowTracker); |
551 for (PanelList::iterator iter = panel_windows_.begin(); | 548 for (PanelList::iterator iter = panel_windows_.begin(); |
552 iter != panel_windows_.end();) { | 549 iter != panel_windows_.end();) { |
553 WmWindow* window = iter->window; | 550 Window* window = iter->window; |
554 // Minimizing a panel window may remove it from the panel_windows_ list. | 551 // Minimizing a panel window may remove it from the panel_windows_ list. |
555 // Advance the iterator before minimizing it: http://crbug.com/393047. | 552 // Advance the iterator before minimizing it: http://crbug.com/393047. |
556 ++iter; | 553 ++iter; |
557 if (window != dragged_panel_ && window->IsVisible()) { | 554 if (window != dragged_panel_ && window->IsVisible()) { |
558 minimized_windows->Add(window->aura_window()); | 555 minimized_windows->Add(window); |
559 window->GetWindowState()->Minimize(); | 556 wm::GetWindowState(window)->Minimize(); |
560 } | 557 } |
561 } | 558 } |
562 restore_windows_on_shelf_visible_ = std::move(minimized_windows); | 559 restore_windows_on_shelf_visible_ = std::move(minimized_windows); |
563 } | 560 } |
564 | 561 |
565 void PanelLayoutManager::OnShelfIconPositionsChanged() { | 562 void PanelLayoutManager::OnShelfIconPositionsChanged() { |
566 // TODO: As this is called for every animation step now. Relayout needs to be | 563 // TODO: As this is called for every animation step now. Relayout needs to be |
567 // updated to use current icon position instead of use the ideal bounds so | 564 // updated to use current icon position instead of use the ideal bounds so |
568 // that the panels slide with their icons instead of jumping. | 565 // that the panels slide with their icons instead of jumping. |
569 Relayout(); | 566 Relayout(); |
570 } | 567 } |
571 | 568 |
572 //////////////////////////////////////////////////////////////////////////////// | 569 //////////////////////////////////////////////////////////////////////////////// |
573 // PanelLayoutManager private implementation: | 570 // PanelLayoutManager private implementation: |
574 | 571 |
575 void PanelLayoutManager::MinimizePanel(aura::Window* panel) { | 572 void PanelLayoutManager::MinimizePanel(Window* panel) { |
576 // Clusterfuzz can trigger panel accelerators before the shelf is created. | 573 // Clusterfuzz can trigger panel accelerators before the shelf is created. |
577 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. | 574 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. |
578 if (!shelf_) | 575 if (!shelf_) |
579 return; | 576 return; |
580 | 577 |
581 ::wm::SetWindowVisibilityAnimationType( | 578 ::wm::SetWindowVisibilityAnimationType( |
582 panel, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 579 panel, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
583 ui::Layer* layer = panel->layer(); | 580 ui::Layer* layer = panel->layer(); |
584 ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator()); | 581 ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator()); |
585 panel_slide_settings.SetPreemptionStrategy( | 582 panel_slide_settings.SetPreemptionStrategy( |
586 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 583 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
587 panel_slide_settings.SetTransitionDuration( | 584 panel_slide_settings.SetTransitionDuration( |
588 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); | 585 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); |
589 gfx::Rect bounds(panel->bounds()); | 586 gfx::Rect bounds(panel->bounds()); |
590 bounds.Offset(GetSlideInAnimationOffset(shelf_->GetAlignment())); | 587 bounds.Offset(GetSlideInAnimationOffset(shelf_->GetAlignment())); |
591 SetChildBoundsDirect(panel, bounds); | 588 SetChildBoundsDirect(panel, bounds); |
592 panel->Hide(); | 589 panel->Hide(); |
593 layer->SetOpacity(0); | 590 layer->SetOpacity(0); |
594 if (::wm::IsActiveWindow(panel)) | 591 if (::wm::IsActiveWindow(panel)) |
595 ::wm::DeactivateWindow(panel); | 592 ::wm::DeactivateWindow(panel); |
596 Relayout(); | 593 Relayout(); |
597 } | 594 } |
598 | 595 |
599 void PanelLayoutManager::RestorePanel(aura::Window* panel) { | 596 void PanelLayoutManager::RestorePanel(Window* panel) { |
600 PanelList::iterator found = std::find( | 597 PanelList::iterator found = |
601 panel_windows_.begin(), panel_windows_.end(), WmWindow::Get(panel)); | 598 std::find(panel_windows_.begin(), panel_windows_.end(), panel); |
602 DCHECK(found != panel_windows_.end()); | 599 DCHECK(found != panel_windows_.end()); |
603 found->slide_in = true; | 600 found->slide_in = true; |
604 Relayout(); | 601 Relayout(); |
605 } | 602 } |
606 | 603 |
607 void PanelLayoutManager::Relayout() { | 604 void PanelLayoutManager::Relayout() { |
608 if (!shelf_ || !shelf_->GetWindow()) | 605 if (!shelf_ || !shelf_->GetWindow()) |
609 return; | 606 return; |
610 | 607 |
611 // Suppress layouts during overview mode because changing window bounds | 608 // Suppress layouts during overview mode because changing window bounds |
612 // interfered with overview mode animations. However, layouts need to be done | 609 // interfered with overview mode animations. However, layouts need to be done |
613 // when the WindowSelectorController is restoring minimized windows so that | 610 // when the WindowSelectorController is restoring minimized windows so that |
614 // they actually become visible. | 611 // they actually become visible. |
615 WindowSelectorController* window_selector_controller = | 612 WindowSelectorController* window_selector_controller = |
616 Shell::Get()->window_selector_controller(); | 613 Shell::Get()->window_selector_controller(); |
617 if (in_layout_ || | 614 if (in_layout_ || |
618 (window_selector_controller->IsSelecting() && | 615 (window_selector_controller->IsSelecting() && |
619 !window_selector_controller->IsRestoringMinimizedWindows())) { | 616 !window_selector_controller->IsRestoringMinimizedWindows())) { |
620 return; | 617 return; |
621 } | 618 } |
622 | 619 |
623 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 620 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
624 | 621 |
625 const bool horizontal = shelf_->IsHorizontalAlignment(); | 622 const bool horizontal = shelf_->IsHorizontalAlignment(); |
626 gfx::Rect shelf_bounds = panel_container_->ConvertRectFromScreen( | 623 gfx::Rect shelf_bounds = shelf_->GetWindow()->GetBoundsInScreen(); |
627 shelf_->GetWindow()->GetBoundsInScreen()); | 624 ::wm::ConvertRectFromScreen(panel_container_, &shelf_bounds); |
628 int panel_start_bounds = kPanelIdealSpacing; | 625 int panel_start_bounds = kPanelIdealSpacing; |
629 int panel_end_bounds = | 626 int panel_end_bounds = |
630 horizontal ? panel_container_->GetBounds().width() - kPanelIdealSpacing | 627 horizontal ? panel_container_->bounds().width() - kPanelIdealSpacing |
631 : panel_container_->GetBounds().height() - kPanelIdealSpacing; | 628 : panel_container_->bounds().height() - kPanelIdealSpacing; |
632 WmWindow* active_panel = nullptr; | 629 Window* active_panel = nullptr; |
633 std::vector<VisiblePanelPositionInfo> visible_panels; | 630 std::vector<VisiblePanelPositionInfo> visible_panels; |
634 for (PanelList::iterator iter = panel_windows_.begin(); | 631 for (PanelList::iterator iter = panel_windows_.begin(); |
635 iter != panel_windows_.end(); ++iter) { | 632 iter != panel_windows_.end(); ++iter) { |
636 WmWindow* panel = iter->window; | 633 Window* panel = iter->window; |
637 iter->callout_widget->UpdateBounds(shelf_); | 634 iter->callout_widget->UpdateBounds(shelf_); |
638 | 635 |
639 // Consider the dragged panel as part of the layout as long as it is | 636 // Consider the dragged panel as part of the layout as long as it is |
640 // touching the shelf. | 637 // touching the shelf. |
641 if ((!panel->IsVisible() && !iter->slide_in) || | 638 if ((!panel->IsVisible() && !iter->slide_in) || |
642 (panel == dragged_panel_ && | 639 (panel == dragged_panel_ && |
643 !BoundsAdjacent(panel->GetBounds(), shelf_bounds))) { | 640 !BoundsAdjacent(panel->bounds(), shelf_bounds))) { |
644 continue; | 641 continue; |
645 } | 642 } |
646 | 643 |
647 // If the shelf is currently hidden (full-screen mode), minimize panel until | 644 // If the shelf is currently hidden (full-screen mode), minimize panel until |
648 // full-screen mode is exited. When a panel is dragged from another display | 645 // full-screen mode is exited. When a panel is dragged from another display |
649 // the shelf state does not update before the panel is added so we exclude | 646 // the shelf state does not update before the panel is added so we exclude |
650 // the dragged panel. | 647 // the dragged panel. |
651 if (panel != dragged_panel_ && restore_windows_on_shelf_visible_) { | 648 if (panel != dragged_panel_ && restore_windows_on_shelf_visible_) { |
652 panel->GetWindowState()->Minimize(); | 649 wm::GetWindowState(panel)->Minimize(); |
653 restore_windows_on_shelf_visible_->Add(panel->aura_window()); | 650 restore_windows_on_shelf_visible_->Add(panel); |
654 continue; | 651 continue; |
655 } | 652 } |
656 | 653 |
657 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel); | 654 gfx::Rect icon_bounds = |
| 655 shelf_->GetScreenBoundsOfItemIconForWindow(WmWindow::Get(panel)); |
658 | 656 |
659 // If both the icon width and height are 0 then there is no icon in the | 657 // If both the icon width and height are 0 then there is no icon in the |
660 // shelf. If the shelf is hidden, one of the height or width will be | 658 // shelf. If the shelf is hidden, one of the height or width will be |
661 // 0 but the position in the shelf and major dimension is still reported | 659 // 0 but the position in the shelf and major dimension is still reported |
662 // correctly and the panel can be aligned above where the hidden icon is. | 660 // correctly and the panel can be aligned above where the hidden icon is. |
663 if (icon_bounds.width() == 0 && icon_bounds.height() == 0) | 661 if (icon_bounds.width() == 0 && icon_bounds.height() == 0) |
664 continue; | 662 continue; |
665 | 663 |
666 if (panel->IsFocused() || | 664 if (panel->HasFocus() || panel->Contains(wm::GetFocusedWindow())) { |
667 panel->Contains(WmWindow::Get(wm::GetFocusedWindow()))) { | |
668 DCHECK(!active_panel); | 665 DCHECK(!active_panel); |
669 active_panel = panel; | 666 active_panel = panel; |
670 } | 667 } |
671 icon_bounds = panel_container_->ConvertRectFromScreen(icon_bounds); | 668 ::wm::ConvertRectFromScreen(panel_container_, &icon_bounds); |
672 gfx::Point icon_origin = icon_bounds.origin(); | 669 gfx::Point icon_origin = icon_bounds.origin(); |
673 VisiblePanelPositionInfo position_info; | 670 VisiblePanelPositionInfo position_info; |
674 int icon_start = horizontal ? icon_origin.x() : icon_origin.y(); | 671 int icon_start = horizontal ? icon_origin.x() : icon_origin.y(); |
675 int icon_end = | 672 int icon_end = |
676 icon_start + (horizontal ? icon_bounds.width() : icon_bounds.height()); | 673 icon_start + (horizontal ? icon_bounds.width() : icon_bounds.height()); |
677 position_info.major_length = | 674 position_info.major_length = |
678 horizontal ? panel->GetBounds().width() : panel->GetBounds().height(); | 675 horizontal ? panel->bounds().width() : panel->bounds().height(); |
679 position_info.min_major = | 676 position_info.min_major = |
680 std::max(panel_start_bounds + position_info.major_length / 2, | 677 std::max(panel_start_bounds + position_info.major_length / 2, |
681 icon_end - position_info.major_length / 2); | 678 icon_end - position_info.major_length / 2); |
682 position_info.max_major = | 679 position_info.max_major = |
683 std::min(icon_start + position_info.major_length / 2, | 680 std::min(icon_start + position_info.major_length / 2, |
684 panel_end_bounds - position_info.major_length / 2); | 681 panel_end_bounds - position_info.major_length / 2); |
685 position_info.major_pos = (icon_start + icon_end) / 2; | 682 position_info.major_pos = (icon_start + icon_end) / 2; |
686 position_info.window = panel; | 683 position_info.window = panel; |
687 position_info.slide_in = iter->slide_in; | 684 position_info.slide_in = iter->slide_in; |
688 iter->slide_in = false; | 685 iter->slide_in = false; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 bool on_shelf = visible_panels[i].window->GetTargetBounds() == bounds; | 719 bool on_shelf = visible_panels[i].window->GetTargetBounds() == bounds; |
723 | 720 |
724 if (horizontal) { | 721 if (horizontal) { |
725 bounds.set_x(visible_panels[i].major_pos - | 722 bounds.set_x(visible_panels[i].major_pos - |
726 visible_panels[i].major_length / 2); | 723 visible_panels[i].major_length / 2); |
727 } else { | 724 } else { |
728 bounds.set_y(visible_panels[i].major_pos - | 725 bounds.set_y(visible_panels[i].major_pos - |
729 visible_panels[i].major_length / 2); | 726 visible_panels[i].major_length / 2); |
730 } | 727 } |
731 | 728 |
732 ui::Layer* layer = visible_panels[i].window->GetLayer(); | 729 ui::Layer* layer = visible_panels[i].window->layer(); |
733 if (slide_in) { | 730 if (slide_in) { |
734 // New windows shift up from the shelf into position and fade in. | 731 // New windows shift up from the shelf into position and fade in. |
735 layer->SetOpacity(0); | 732 layer->SetOpacity(0); |
736 gfx::Rect initial_bounds(bounds); | 733 gfx::Rect initial_bounds(bounds); |
737 initial_bounds.Offset(GetSlideInAnimationOffset(shelf_->alignment())); | 734 initial_bounds.Offset(GetSlideInAnimationOffset(shelf_->alignment())); |
738 SetChildBoundsDirect(visible_panels[i].window->aura_window(), | 735 SetChildBoundsDirect(visible_panels[i].window, initial_bounds); |
739 initial_bounds); | |
740 // Set on shelf so that the panel animates into its target position. | 736 // Set on shelf so that the panel animates into its target position. |
741 on_shelf = true; | 737 on_shelf = true; |
742 } | 738 } |
743 | 739 |
744 if (on_shelf) { | 740 if (on_shelf) { |
745 ui::ScopedLayerAnimationSettings panel_slide_settings( | 741 ui::ScopedLayerAnimationSettings panel_slide_settings( |
746 layer->GetAnimator()); | 742 layer->GetAnimator()); |
747 panel_slide_settings.SetPreemptionStrategy( | 743 panel_slide_settings.SetPreemptionStrategy( |
748 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 744 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
749 panel_slide_settings.SetTransitionDuration( | 745 panel_slide_settings.SetTransitionDuration( |
750 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); | 746 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); |
751 SetChildBoundsDirect(visible_panels[i].window->aura_window(), bounds); | 747 SetChildBoundsDirect(visible_panels[i].window, bounds); |
752 if (slide_in) { | 748 if (slide_in) { |
753 layer->SetOpacity(1); | 749 layer->SetOpacity(1); |
754 visible_panels[i].window->Show(); | 750 visible_panels[i].window->Show(); |
755 } | 751 } |
756 } else { | 752 } else { |
757 // If the shelf moved don't animate, move immediately to the new | 753 // If the shelf moved don't animate, move immediately to the new |
758 // target location. | 754 // target location. |
759 SetChildBoundsDirect(visible_panels[i].window->aura_window(), bounds); | 755 SetChildBoundsDirect(visible_panels[i].window, bounds); |
760 } | 756 } |
761 } | 757 } |
762 | 758 |
763 UpdateStacking(active_panel); | 759 UpdateStacking(active_panel); |
764 UpdateCallouts(); | 760 UpdateCallouts(); |
765 } | 761 } |
766 | 762 |
767 void PanelLayoutManager::UpdateStacking(WmWindow* active_panel) { | 763 void PanelLayoutManager::UpdateStacking(Window* active_panel) { |
768 // Clusterfuzz can trigger panel accelerators before the shelf is created. | 764 // Clusterfuzz can trigger panel accelerators before the shelf is created. |
769 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. | 765 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. |
770 if (!shelf_) | 766 if (!shelf_) |
771 return; | 767 return; |
772 | 768 |
773 if (!active_panel) { | 769 if (!active_panel) { |
774 if (!last_active_panel_) | 770 if (!last_active_panel_) |
775 return; | 771 return; |
776 active_panel = last_active_panel_; | 772 active_panel = last_active_panel_; |
777 } | 773 } |
778 | 774 |
779 // We want to to stack the panels like a deck of cards: | 775 // We want to to stack the panels like a deck of cards: |
780 // ,--,--,--,-------.--.--. | 776 // ,--,--,--,-------.--.--. |
781 // | | | | | | | | 777 // | | | | | | | |
782 // | | | | | | | | 778 // | | | | | | | |
783 // | 779 // |
784 // We use the middle of each panel to figure out how to stack the panels. This | 780 // We use the middle of each panel to figure out how to stack the panels. This |
785 // allows us to update the stacking when a panel is being dragged around by | 781 // allows us to update the stacking when a panel is being dragged around by |
786 // the titlebar--even though it doesn't update the shelf icon positions, we | 782 // the titlebar--even though it doesn't update the shelf icon positions, we |
787 // still want the visual effect. | 783 // still want the visual effect. |
788 std::map<int, WmWindow*> window_ordering; | 784 std::map<int, Window*> window_ordering; |
789 const bool horizontal = shelf_->IsHorizontalAlignment(); | 785 const bool horizontal = shelf_->IsHorizontalAlignment(); |
790 for (PanelList::const_iterator it = panel_windows_.begin(); | 786 for (PanelList::const_iterator it = panel_windows_.begin(); |
791 it != panel_windows_.end(); ++it) { | 787 it != panel_windows_.end(); ++it) { |
792 gfx::Rect bounds = it->window->GetBounds(); | 788 const gfx::Rect& bounds = it->window->bounds(); |
793 window_ordering.insert( | 789 window_ordering.insert( |
794 std::make_pair(horizontal ? bounds.x() + bounds.width() / 2 | 790 std::make_pair(horizontal ? bounds.x() + bounds.width() / 2 |
795 : bounds.y() + bounds.height() / 2, | 791 : bounds.y() + bounds.height() / 2, |
796 it->window)); | 792 it->window)); |
797 } | 793 } |
798 | 794 |
799 WmWindow* previous_panel = nullptr; | 795 Window* previous_panel = nullptr; |
800 for (std::map<int, WmWindow*>::const_iterator it = window_ordering.begin(); | 796 for (std::map<int, Window*>::const_iterator it = window_ordering.begin(); |
801 it != window_ordering.end() && it->second != active_panel; ++it) { | 797 it != window_ordering.end() && it->second != active_panel; ++it) { |
802 if (previous_panel) | 798 if (previous_panel) |
803 panel_container_->StackChildAbove(it->second, previous_panel); | 799 panel_container_->StackChildAbove(it->second, previous_panel); |
804 previous_panel = it->second; | 800 previous_panel = it->second; |
805 } | 801 } |
806 | 802 |
807 previous_panel = nullptr; | 803 previous_panel = nullptr; |
808 for (std::map<int, WmWindow*>::const_reverse_iterator it = | 804 for (std::map<int, Window*>::const_reverse_iterator it = |
809 window_ordering.rbegin(); | 805 window_ordering.rbegin(); |
810 it != window_ordering.rend() && it->second != active_panel; ++it) { | 806 it != window_ordering.rend() && it->second != active_panel; ++it) { |
811 if (previous_panel) | 807 if (previous_panel) |
812 panel_container_->StackChildAbove(it->second, previous_panel); | 808 panel_container_->StackChildAbove(it->second, previous_panel); |
813 previous_panel = it->second; | 809 previous_panel = it->second; |
814 } | 810 } |
815 | 811 |
816 panel_container_->StackChildAtTop(active_panel); | 812 panel_container_->StackChildAtTop(active_panel); |
817 if (dragged_panel_ && dragged_panel_->GetParent() == panel_container_) | 813 if (dragged_panel_ && dragged_panel_->parent() == panel_container_) |
818 panel_container_->StackChildAtTop(dragged_panel_); | 814 panel_container_->StackChildAtTop(dragged_panel_); |
819 last_active_panel_ = active_panel; | 815 last_active_panel_ = active_panel; |
820 } | 816 } |
821 | 817 |
822 void PanelLayoutManager::UpdateCallouts() { | 818 void PanelLayoutManager::UpdateCallouts() { |
823 // Clusterfuzz can trigger panel accelerators before the shelf is created. | 819 // Clusterfuzz can trigger panel accelerators before the shelf is created. |
824 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. | 820 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. |
825 if (!shelf_) | 821 if (!shelf_) |
826 return; | 822 return; |
827 | 823 |
828 const bool horizontal = shelf_->IsHorizontalAlignment(); | 824 const bool horizontal = shelf_->IsHorizontalAlignment(); |
829 for (PanelList::iterator iter = panel_windows_.begin(); | 825 for (PanelList::iterator iter = panel_windows_.begin(); |
830 iter != panel_windows_.end(); ++iter) { | 826 iter != panel_windows_.end(); ++iter) { |
831 WmWindow* panel = iter->window; | 827 Window* panel = iter->window; |
832 views::Widget* callout_widget = iter->callout_widget; | 828 views::Widget* callout_widget = iter->callout_widget; |
833 WmWindow* callout_widget_window = | 829 Window* callout_widget_window = callout_widget->GetNativeWindow(); |
834 WmWindow::Get(callout_widget->GetNativeWindow()); | |
835 | 830 |
836 gfx::Rect current_bounds = panel->GetBoundsInScreen(); | 831 gfx::Rect current_bounds = panel->GetBoundsInScreen(); |
837 gfx::Rect bounds = | 832 gfx::Rect bounds = panel->GetTargetBounds(); |
838 panel->GetParent()->ConvertRectToScreen(panel->GetTargetBounds()); | 833 ::wm::ConvertRectToScreen(panel->parent(), &bounds); |
839 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel); | 834 gfx::Rect icon_bounds = |
840 if (icon_bounds.IsEmpty() || !panel->GetLayer()->GetTargetVisibility() || | 835 shelf_->GetScreenBoundsOfItemIconForWindow(WmWindow::Get(panel)); |
| 836 if (icon_bounds.IsEmpty() || !panel->layer()->GetTargetVisibility() || |
841 panel == dragged_panel_ || !show_callout_widgets_) { | 837 panel == dragged_panel_ || !show_callout_widgets_) { |
842 callout_widget->Hide(); | 838 callout_widget->Hide(); |
843 callout_widget_window->GetLayer()->SetOpacity(0); | 839 callout_widget_window->layer()->SetOpacity(0); |
844 continue; | 840 continue; |
845 } | 841 } |
846 | 842 |
847 gfx::Rect callout_bounds = callout_widget->GetWindowBoundsInScreen(); | 843 gfx::Rect callout_bounds = callout_widget->GetWindowBoundsInScreen(); |
848 gfx::Vector2d slide_vector = bounds.origin() - current_bounds.origin(); | 844 gfx::Vector2d slide_vector = bounds.origin() - current_bounds.origin(); |
849 int slide_distance = horizontal ? slide_vector.x() : slide_vector.y(); | 845 int slide_distance = horizontal ? slide_vector.x() : slide_vector.y(); |
850 int distance_until_over_panel = 0; | 846 int distance_until_over_panel = 0; |
851 if (horizontal) { | 847 if (horizontal) { |
852 callout_bounds.set_x(icon_bounds.x() + | 848 callout_bounds.set_x(icon_bounds.x() + |
853 (icon_bounds.width() - callout_bounds.width()) / 2); | 849 (icon_bounds.width() - callout_bounds.width()) / 2); |
854 distance_until_over_panel = | 850 distance_until_over_panel = |
855 std::max(current_bounds.x() - callout_bounds.x(), | 851 std::max(current_bounds.x() - callout_bounds.x(), |
856 callout_bounds.right() - current_bounds.right()); | 852 callout_bounds.right() - current_bounds.right()); |
857 } else { | 853 } else { |
858 callout_bounds.set_y(icon_bounds.y() + | 854 callout_bounds.set_y(icon_bounds.y() + |
859 (icon_bounds.height() - callout_bounds.height()) / | 855 (icon_bounds.height() - callout_bounds.height()) / |
860 2); | 856 2); |
861 distance_until_over_panel = | 857 distance_until_over_panel = |
862 std::max(current_bounds.y() - callout_bounds.y(), | 858 std::max(current_bounds.y() - callout_bounds.y(), |
863 callout_bounds.bottom() - current_bounds.bottom()); | 859 callout_bounds.bottom() - current_bounds.bottom()); |
864 } | 860 } |
865 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT) | 861 if (shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT) |
866 callout_bounds.set_x(bounds.x() - callout_bounds.width()); | 862 callout_bounds.set_x(bounds.x() - callout_bounds.width()); |
867 else if (shelf_->GetAlignment() == SHELF_ALIGNMENT_RIGHT) | 863 else if (shelf_->GetAlignment() == SHELF_ALIGNMENT_RIGHT) |
868 callout_bounds.set_x(bounds.right()); | 864 callout_bounds.set_x(bounds.right()); |
869 else | 865 else |
870 callout_bounds.set_y(bounds.bottom()); | 866 callout_bounds.set_y(bounds.bottom()); |
871 callout_bounds = callout_widget_window->GetParent()->ConvertRectFromScreen( | 867 ::wm::ConvertRectFromScreen(callout_widget_window->parent(), |
872 callout_bounds); | 868 &callout_bounds); |
873 | 869 |
874 SetChildBoundsDirect(callout_widget_window->aura_window(), callout_bounds); | 870 SetChildBoundsDirect(callout_widget_window, callout_bounds); |
875 DCHECK_EQ(panel_container_, callout_widget_window->GetParent()); | 871 DCHECK_EQ(panel_container_, callout_widget_window->parent()); |
876 DCHECK_EQ(panel_container_, panel->GetParent()); | 872 DCHECK_EQ(panel_container_, panel->parent()); |
877 panel_container_->StackChildAbove(callout_widget_window, panel); | 873 panel_container_->StackChildAbove(callout_widget_window, panel); |
878 | 874 |
879 ui::Layer* layer = callout_widget_window->GetLayer(); | 875 ui::Layer* layer = callout_widget_window->layer(); |
880 // If the panel is not over the callout position or has just become visible | 876 // If the panel is not over the callout position or has just become visible |
881 // then fade in the callout. | 877 // then fade in the callout. |
882 if ((distance_until_over_panel > 0 || layer->GetTargetOpacity() < 1)) { | 878 if ((distance_until_over_panel > 0 || layer->GetTargetOpacity() < 1)) { |
883 if (distance_until_over_panel > 0 && | 879 if (distance_until_over_panel > 0 && |
884 slide_distance >= distance_until_over_panel) { | 880 slide_distance >= distance_until_over_panel) { |
885 // If the panel is not yet over the callout, then delay fading in | 881 // If the panel is not yet over the callout, then delay fading in |
886 // the callout until after the panel should be over it. | 882 // the callout until after the panel should be over it. |
887 int delay = kPanelSlideDurationMilliseconds * | 883 int delay = kPanelSlideDurationMilliseconds * |
888 distance_until_over_panel / slide_distance; | 884 distance_until_over_panel / slide_distance; |
889 layer->SetOpacity(0); | 885 layer->SetOpacity(0); |
(...skipping 14 matching lines...) Expand all Loading... |
904 // state where the widget is visible but the opacity is 0. | 900 // state where the widget is visible but the opacity is 0. |
905 callout_widget->Show(); | 901 callout_widget->Show(); |
906 } | 902 } |
907 } | 903 } |
908 | 904 |
909 //////////////////////////////////////////////////////////////////////////////// | 905 //////////////////////////////////////////////////////////////////////////////// |
910 // keyboard::KeyboardControllerObserver implementation: | 906 // keyboard::KeyboardControllerObserver implementation: |
911 | 907 |
912 void PanelLayoutManager::OnKeyboardBoundsChanging( | 908 void PanelLayoutManager::OnKeyboardBoundsChanging( |
913 const gfx::Rect& keyboard_bounds) { | 909 const gfx::Rect& keyboard_bounds) { |
914 gfx::Rect parent_bounds = panel_container_->GetBounds(); | 910 const gfx::Rect& parent_bounds = panel_container_->bounds(); |
915 int available_space = parent_bounds.height() - keyboard_bounds.height(); | 911 int available_space = parent_bounds.height() - keyboard_bounds.height(); |
916 for (PanelList::iterator iter = panel_windows_.begin(); | 912 for (PanelList::iterator iter = panel_windows_.begin(); |
917 iter != panel_windows_.end(); ++iter) { | 913 iter != panel_windows_.end(); ++iter) { |
918 WmWindow* panel = iter->window; | 914 Window* panel = iter->window; |
919 wm::WindowState* panel_state = panel->GetWindowState(); | 915 wm::WindowState* panel_state = wm::GetWindowState(panel); |
920 if (keyboard_bounds.height() > 0) { | 916 if (keyboard_bounds.height() > 0) { |
921 // Save existing bounds, so that we can restore them when the keyboard | 917 // Save existing bounds, so that we can restore them when the keyboard |
922 // hides. | 918 // hides. |
923 panel_state->SaveCurrentBoundsForRestore(); | 919 panel_state->SaveCurrentBoundsForRestore(); |
924 | 920 |
925 gfx::Rect panel_bounds = | 921 gfx::Rect panel_bounds = panel->GetTargetBounds(); |
926 panel->GetParent()->ConvertRectToScreen(panel->GetTargetBounds()); | 922 ::wm::ConvertRectToScreen(panel->parent(), &panel_bounds); |
927 int delta = panel_bounds.height() - available_space; | 923 int delta = panel_bounds.height() - available_space; |
928 // Ensure panels are not pushed above the parent boundaries, shrink any | 924 // Ensure panels are not pushed above the parent boundaries, shrink any |
929 // panels that violate this constraint. | 925 // panels that violate this constraint. |
930 if (delta > 0) { | 926 if (delta > 0) { |
931 SetChildBoundsDirect( | 927 SetChildBoundsDirect( |
932 panel->aura_window(), | 928 panel, |
933 gfx::Rect(panel_bounds.x(), panel_bounds.y() + delta, | 929 gfx::Rect(panel_bounds.x(), panel_bounds.y() + delta, |
934 panel_bounds.width(), panel_bounds.height() - delta)); | 930 panel_bounds.width(), panel_bounds.height() - delta)); |
935 } | 931 } |
936 } else if (panel_state->HasRestoreBounds()) { | 932 } else if (panel_state->HasRestoreBounds()) { |
937 // Keyboard hidden, restore original bounds if they exist. | 933 // Keyboard hidden, restore original bounds if they exist. |
938 SetChildBoundsDirect(panel->aura_window(), | 934 SetChildBoundsDirect(panel, panel_state->GetRestoreBoundsInScreen()); |
939 panel_state->GetRestoreBoundsInScreen()); | |
940 } | 935 } |
941 } | 936 } |
942 // This bounds change will have caused a change to the Shelf which does not | 937 // This bounds change will have caused a change to the Shelf which does not |
943 // propogate automatically to this class, so manually recalculate bounds. | 938 // propogate automatically to this class, so manually recalculate bounds. |
944 OnWindowResized(); | 939 OnWindowResized(); |
945 } | 940 } |
946 | 941 |
947 void PanelLayoutManager::OnKeyboardClosed() { | 942 void PanelLayoutManager::OnKeyboardClosed() { |
948 keyboard_observer_.RemoveAll(); | 943 keyboard_observer_.RemoveAll(); |
949 } | 944 } |
950 | 945 |
951 } // namespace ash | 946 } // namespace ash |
OLD | NEW |