| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/dock/docked_window_layout_manager.h" | 5 #include "ash/wm/dock/docked_window_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
| 8 #include "ash/shelf/shelf.h" | 8 #include "ash/shelf/shelf.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" |
| 11 #include "ash/shelf/shelf_layout_manager_observer.h" | |
| 12 #include "ash/shelf/shelf_types.h" | 11 #include "ash/shelf/shelf_types.h" |
| 13 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
| 14 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 15 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
| 16 #include "ash/wm/coordinate_conversion.h" | 15 #include "ash/wm/coordinate_conversion.h" |
| 17 #include "ash/wm/window_animations.h" | 16 #include "ash/wm/window_animations.h" |
| 18 #include "ash/wm/window_properties.h" | 17 #include "ash/wm/window_properties.h" |
| 19 #include "ash/wm/window_resizer.h" | 18 #include "ash/wm/window_resizer.h" |
| 20 #include "ash/wm/window_state.h" | 19 #include "ash/wm/window_state.h" |
| 21 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 51 // static | 50 // static |
| 52 const int DockedWindowLayoutManager::kMinDockGap = 2; | 51 const int DockedWindowLayoutManager::kMinDockGap = 2; |
| 53 // static | 52 // static |
| 54 const int DockedWindowLayoutManager::kIdealWidth = 250; | 53 const int DockedWindowLayoutManager::kIdealWidth = 250; |
| 55 const int kMinimumHeight = 250; | 54 const int kMinimumHeight = 250; |
| 56 const int kSlideDurationMs = 120; | 55 const int kSlideDurationMs = 120; |
| 57 const int kFadeDurationMs = 60; | 56 const int kFadeDurationMs = 60; |
| 58 const int kMinimizeDurationMs = 720; | 57 const int kMinimizeDurationMs = 720; |
| 59 | 58 |
| 60 class DockedBackgroundWidget : public views::Widget, | 59 class DockedBackgroundWidget : public views::Widget, |
| 61 public BackgroundAnimatorDelegate, | 60 public BackgroundAnimatorDelegate { |
| 62 public ShelfLayoutManagerObserver { | |
| 63 public: | 61 public: |
| 64 explicit DockedBackgroundWidget(aura::Window* container) | 62 explicit DockedBackgroundWidget(aura::Window* container) |
| 65 : alignment_(DOCKED_ALIGNMENT_NONE), | 63 : alignment_(DOCKED_ALIGNMENT_NONE), |
| 66 background_animator_(this, 0, kShelfBackgroundAlpha), | 64 background_animator_(this, 0, kShelfBackgroundAlpha), |
| 67 alpha_(0), | 65 alpha_(0), |
| 68 opaque_background_(ui::LAYER_SOLID_COLOR), | 66 opaque_background_(ui::LAYER_SOLID_COLOR), |
| 69 visible_background_type_(SHELF_BACKGROUND_DEFAULT), | 67 visible_background_type_(SHELF_BACKGROUND_DEFAULT), |
| 70 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { | 68 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { |
| 71 Shelf* shelf = Shelf::ForWindow(container); | |
| 72 visible_background_type_ = shelf->shelf_widget()->GetBackgroundType(); | |
| 73 shelf->shelf_layout_manager()->AddObserver(this); | |
| 74 | |
| 75 InitWidget(container); | 69 InitWidget(container); |
| 76 } | 70 } |
| 77 | 71 |
| 78 ~DockedBackgroundWidget() override { | |
| 79 Shelf* shelf = Shelf::ForWindow(GetNativeWindow()); | |
| 80 if (shelf && shelf->shelf_layout_manager()) | |
| 81 shelf->shelf_layout_manager()->RemoveObserver(this); | |
| 82 } | |
| 83 | |
| 84 // Sets widget bounds and sizes opaque background layer to fill the widget. | 72 // Sets widget bounds and sizes opaque background layer to fill the widget. |
| 85 void SetBackgroundBounds(const gfx::Rect bounds, DockedAlignment alignment) { | 73 void SetBackgroundBounds(const gfx::Rect bounds, DockedAlignment alignment) { |
| 86 SetBounds(bounds); | 74 SetBounds(bounds); |
| 87 opaque_background_.SetBounds(gfx::Rect(bounds.size())); | 75 opaque_background_.SetBounds(gfx::Rect(bounds.size())); |
| 88 alignment_ = alignment; | 76 alignment_ = alignment; |
| 89 } | 77 } |
| 90 | 78 |
| 91 private: | 79 // Sets the background type. Starts an animation to transition to |
| 80 // |background_type| if the widget is visible. If the widget is not visible, |
| 81 // the animation is postponed till the widget becomes visible. |
| 82 void SetBackgroundType(ShelfBackgroundType background_type, |
| 83 BackgroundAnimatorChangeType change_type) { |
| 84 visible_background_type_ = background_type; |
| 85 visible_background_change_type_ = change_type; |
| 86 if (IsVisible()) |
| 87 UpdateBackground(); |
| 88 } |
| 89 |
| 92 // views::Widget: | 90 // views::Widget: |
| 93 void OnNativeWidgetVisibilityChanged(bool visible) override { | 91 void OnNativeWidgetVisibilityChanged(bool visible) override { |
| 94 views::Widget::OnNativeWidgetVisibilityChanged(visible); | 92 views::Widget::OnNativeWidgetVisibilityChanged(visible); |
| 95 UpdateBackground(); | 93 UpdateBackground(); |
| 96 } | 94 } |
| 97 | 95 |
| 98 void OnNativeWidgetPaint(const ui::PaintContext& context) override { | 96 void OnNativeWidgetPaint(const ui::PaintContext& context) override { |
| 99 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size()); | 97 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size()); |
| 100 ui::PaintRecorder recorder(context, local_window_bounds.size()); | 98 ui::PaintRecorder recorder(context, local_window_bounds.size()); |
| 101 const gfx::ImageSkia& shelf_background( | 99 const gfx::ImageSkia& shelf_background( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 119 local_window_bounds.width() - shelf_background.width(), | 117 local_window_bounds.width() - shelf_background.width(), |
| 120 local_window_bounds.height(), false, paint); | 118 local_window_bounds.height(), false, paint); |
| 121 } | 119 } |
| 122 | 120 |
| 123 // BackgroundAnimatorDelegate: | 121 // BackgroundAnimatorDelegate: |
| 124 void UpdateBackground(int alpha) override { | 122 void UpdateBackground(int alpha) override { |
| 125 alpha_ = alpha; | 123 alpha_ = alpha; |
| 126 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); | 124 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); |
| 127 } | 125 } |
| 128 | 126 |
| 129 // ShelfLayoutManagerObserver: | 127 private: |
| 130 void OnBackgroundUpdated(ShelfBackgroundType background_type, | |
| 131 BackgroundAnimatorChangeType change_type) override { | |
| 132 // Sets the background type. Starts an animation to transition to | |
| 133 // |background_type| if the widget is visible. If the widget is not visible, | |
| 134 // the animation is postponed till the widget becomes visible. | |
| 135 visible_background_type_ = background_type; | |
| 136 visible_background_change_type_ = change_type; | |
| 137 if (IsVisible()) | |
| 138 UpdateBackground(); | |
| 139 } | |
| 140 | |
| 141 void InitWidget(aura::Window* parent) { | 128 void InitWidget(aura::Window* parent) { |
| 142 views::Widget::InitParams params; | 129 views::Widget::InitParams params; |
| 143 params.type = views::Widget::InitParams::TYPE_POPUP; | 130 params.type = views::Widget::InitParams::TYPE_POPUP; |
| 144 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 131 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 145 params.keep_on_top = false; | 132 params.keep_on_top = false; |
| 146 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 133 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 147 params.parent = parent; | 134 params.parent = parent; |
| 148 params.accept_events = false; | 135 params.accept_events = false; |
| 149 set_focus_on_creation(false); | 136 set_focus_on_creation(false); |
| 150 Init(params); | 137 Init(params); |
| 151 SetVisibilityChangedAnimationsEnabled(false); | 138 SetVisibilityChangedAnimationsEnabled(false); |
| 152 GetNativeWindow()->SetProperty(kStayInSameRootWindowKey, true); | 139 GetNativeWindow()->SetProperty(kStayInSameRootWindowKey, true); |
| 153 opaque_background_.SetColor(SK_ColorBLACK); | 140 opaque_background_.SetColor(SK_ColorBLACK); |
| 154 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); | 141 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); |
| 155 opaque_background_.SetOpacity(0.0f); | 142 opaque_background_.SetOpacity(0.0f); |
| 156 GetNativeWindow()->layer()->Add(&opaque_background_); | 143 GetNativeWindow()->layer()->Add(&opaque_background_); |
| 144 Hide(); |
| 157 | 145 |
| 158 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 146 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 159 gfx::ImageSkia shelf_background = | 147 gfx::ImageSkia shelf_background = |
| 160 *rb.GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); | 148 *rb.GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); |
| 161 shelf_background_left_ = gfx::ImageSkiaOperations::CreateRotatedImage( | 149 shelf_background_left_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 162 shelf_background, SkBitmapOperations::ROTATION_90_CW); | 150 shelf_background, SkBitmapOperations::ROTATION_90_CW); |
| 163 shelf_background_right_ = gfx::ImageSkiaOperations::CreateRotatedImage( | 151 shelf_background_right_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 164 shelf_background, SkBitmapOperations::ROTATION_270_CW); | 152 shelf_background, SkBitmapOperations::ROTATION_270_CW); |
| 165 | |
| 166 // Stack the background below any windows already in the dock container. | |
| 167 parent->StackChildAtBottom(GetNativeWindow()); | |
| 168 } | 153 } |
| 169 | 154 |
| 170 // Transitions to |visible_background_type_| if the widget is visible and to | 155 // Transitions to |visible_background_type_| if the widget is visible and to |
| 171 // SHELF_BACKGROUND_DEFAULT if it is not. | 156 // SHELF_BACKGROUND_DEFAULT if it is not. |
| 172 void UpdateBackground() { | 157 void UpdateBackground() { |
| 173 ShelfBackgroundType background_type = IsVisible() ? | 158 ShelfBackgroundType background_type = IsVisible() ? |
| 174 visible_background_type_ : SHELF_BACKGROUND_DEFAULT; | 159 visible_background_type_ : SHELF_BACKGROUND_DEFAULT; |
| 175 BackgroundAnimatorChangeType change_type = IsVisible() ? | 160 BackgroundAnimatorChangeType change_type = IsVisible() ? |
| 176 visible_background_change_type_ : BACKGROUND_CHANGE_IMMEDIATE; | 161 visible_background_change_type_ : BACKGROUND_CHANGE_IMMEDIATE; |
| 177 | 162 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 }; | 394 }; |
| 410 | 395 |
| 411 //////////////////////////////////////////////////////////////////////////////// | 396 //////////////////////////////////////////////////////////////////////////////// |
| 412 // DockedWindowLayoutManager public implementation: | 397 // DockedWindowLayoutManager public implementation: |
| 413 DockedWindowLayoutManager::DockedWindowLayoutManager( | 398 DockedWindowLayoutManager::DockedWindowLayoutManager( |
| 414 aura::Window* dock_container, | 399 aura::Window* dock_container, |
| 415 WorkspaceController* workspace_controller) | 400 WorkspaceController* workspace_controller) |
| 416 : SnapToPixelLayoutManager(dock_container), | 401 : SnapToPixelLayoutManager(dock_container), |
| 417 dock_container_(dock_container), | 402 dock_container_(dock_container), |
| 418 in_layout_(false), | 403 in_layout_(false), |
| 419 dragged_window_(nullptr), | 404 dragged_window_(NULL), |
| 420 is_dragged_window_docked_(false), | 405 is_dragged_window_docked_(false), |
| 421 is_dragged_from_dock_(false), | 406 is_dragged_from_dock_(false), |
| 422 shelf_(nullptr), | 407 shelf_(NULL), |
| 423 workspace_controller_(workspace_controller), | 408 workspace_controller_(workspace_controller), |
| 424 in_fullscreen_(workspace_controller_->GetWindowState() == | 409 in_fullscreen_(workspace_controller_->GetWindowState() == |
| 425 WORKSPACE_WINDOW_STATE_FULL_SCREEN), | 410 WORKSPACE_WINDOW_STATE_FULL_SCREEN), |
| 426 docked_width_(0), | 411 docked_width_(0), |
| 427 alignment_(DOCKED_ALIGNMENT_NONE), | 412 alignment_(DOCKED_ALIGNMENT_NONE), |
| 428 preferred_alignment_(DOCKED_ALIGNMENT_NONE), | 413 preferred_alignment_(DOCKED_ALIGNMENT_NONE), |
| 429 event_source_(DOCKED_ACTION_SOURCE_UNKNOWN), | 414 event_source_(DOCKED_ACTION_SOURCE_UNKNOWN), |
| 430 last_active_window_(nullptr), | 415 last_active_window_(NULL), |
| 431 last_action_time_(base::Time::Now()), | 416 last_action_time_(base::Time::Now()), |
| 432 background_widget_(nullptr) { | 417 background_widget_(new DockedBackgroundWidget(dock_container_)) { |
| 433 DCHECK(dock_container); | 418 DCHECK(dock_container); |
| 434 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 419 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> |
| 435 AddObserver(this); | 420 AddObserver(this); |
| 436 Shell::GetInstance()->AddShellObserver(this); | 421 Shell::GetInstance()->AddShellObserver(this); |
| 437 } | 422 } |
| 438 | 423 |
| 439 DockedWindowLayoutManager::~DockedWindowLayoutManager() { | 424 DockedWindowLayoutManager::~DockedWindowLayoutManager() { |
| 440 Shutdown(); | 425 Shutdown(); |
| 441 } | 426 } |
| 442 | 427 |
| 443 void DockedWindowLayoutManager::Shutdown() { | 428 void DockedWindowLayoutManager::Shutdown() { |
| 444 background_widget_.reset(); | 429 if (shelf_ && shelf_->shelf_layout_manager()) { |
| 445 shelf_observer_.reset(); | 430 shelf_->shelf_layout_manager()->RemoveObserver(this); |
| 446 shelf_ = nullptr; | 431 shelf_observer_.reset(); |
| 432 } |
| 433 shelf_ = NULL; |
| 447 for (size_t i = 0; i < dock_container_->children().size(); ++i) { | 434 for (size_t i = 0; i < dock_container_->children().size(); ++i) { |
| 448 aura::Window* child = dock_container_->children()[i]; | 435 aura::Window* child = dock_container_->children()[i]; |
| 449 child->RemoveObserver(this); | 436 child->RemoveObserver(this); |
| 450 wm::GetWindowState(child)->RemoveObserver(this); | 437 wm::GetWindowState(child)->RemoveObserver(this); |
| 451 } | 438 } |
| 452 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 439 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> |
| 453 RemoveObserver(this); | 440 RemoveObserver(this); |
| 454 Shell::GetInstance()->RemoveShellObserver(this); | 441 Shell::GetInstance()->RemoveShellObserver(this); |
| 455 } | 442 } |
| 456 | 443 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 DCHECK(!IsPopupOrTransient(dragged_window_)); | 510 DCHECK(!IsPopupOrTransient(dragged_window_)); |
| 524 if (is_dragged_window_docked_) | 511 if (is_dragged_window_docked_) |
| 525 OnDraggedWindowUndocked(); | 512 OnDraggedWindowUndocked(); |
| 526 DCHECK (!is_dragged_window_docked_); | 513 DCHECK (!is_dragged_window_docked_); |
| 527 // Stop observing a window unless it is docked container's child in which | 514 // Stop observing a window unless it is docked container's child in which |
| 528 // case it needs to keep being observed after the drag completes. | 515 // case it needs to keep being observed after the drag completes. |
| 529 if (dragged_window_->parent() != dock_container_) { | 516 if (dragged_window_->parent() != dock_container_) { |
| 530 dragged_window_->RemoveObserver(this); | 517 dragged_window_->RemoveObserver(this); |
| 531 wm::GetWindowState(dragged_window_)->RemoveObserver(this); | 518 wm::GetWindowState(dragged_window_)->RemoveObserver(this); |
| 532 if (last_active_window_ == dragged_window_) | 519 if (last_active_window_ == dragged_window_) |
| 533 last_active_window_ = nullptr; | 520 last_active_window_ = NULL; |
| 534 } else { | 521 } else { |
| 535 // If this is the first window that got docked by a move update alignment. | 522 // If this is the first window that got docked by a move update alignment. |
| 536 if (alignment_ == DOCKED_ALIGNMENT_NONE) | 523 if (alignment_ == DOCKED_ALIGNMENT_NONE) |
| 537 alignment_ = GetEdgeNearestWindow(dragged_window_); | 524 alignment_ = GetEdgeNearestWindow(dragged_window_); |
| 538 // A window is no longer dragged and is a child. | 525 // A window is no longer dragged and is a child. |
| 539 // When a window becomes a child at drag start this is | 526 // When a window becomes a child at drag start this is |
| 540 // the only opportunity we will have to enforce a window | 527 // the only opportunity we will have to enforce a window |
| 541 // count limit so do it here. | 528 // count limit so do it here. |
| 542 MaybeMinimizeChildrenExcept(dragged_window_); | 529 MaybeMinimizeChildrenExcept(dragged_window_); |
| 543 } | 530 } |
| 544 dragged_window_ = nullptr; | 531 dragged_window_ = NULL; |
| 545 dragged_bounds_ = gfx::Rect(); | 532 dragged_bounds_ = gfx::Rect(); |
| 546 Relayout(); | 533 Relayout(); |
| 547 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 534 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
| 548 RecordUmaAction(action, source); | 535 RecordUmaAction(action, source); |
| 549 } | 536 } |
| 550 | 537 |
| 551 void DockedWindowLayoutManager::SetShelf(Shelf* shelf) { | 538 void DockedWindowLayoutManager::SetShelf(Shelf* shelf) { |
| 552 DCHECK(!shelf_); | 539 DCHECK(!shelf_); |
| 553 shelf_ = shelf; | 540 shelf_ = shelf; |
| 554 shelf_observer_.reset(new ShelfWindowObserver(this)); | 541 if (shelf_->shelf_layout_manager()) { |
| 542 shelf_->shelf_layout_manager()->AddObserver(this); |
| 543 shelf_observer_.reset(new ShelfWindowObserver(this)); |
| 544 } |
| 555 } | 545 } |
| 556 | 546 |
| 557 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( | 547 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( |
| 558 const aura::Window* window) const { | 548 const aura::Window* window) const { |
| 559 const gfx::Rect& bounds(window->GetBoundsInScreen()); | 549 const gfx::Rect& bounds(window->GetBoundsInScreen()); |
| 560 | 550 |
| 561 // Test overlap with an existing docked area first. | 551 // Test overlap with an existing docked area first. |
| 562 if (docked_bounds_.Intersects(bounds) && | 552 if (docked_bounds_.Intersects(bounds) && |
| 563 alignment_ != DOCKED_ALIGNMENT_NONE) { | 553 alignment_ != DOCKED_ALIGNMENT_NONE) { |
| 564 // A window is being added to other docked windows (on the same side). | 554 // A window is being added to other docked windows (on the same side). |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 // change alignment during the drag. They also cannot be set to be the | 707 // change alignment during the drag. They also cannot be set to be the |
| 718 // |last_active_window_|. | 708 // |last_active_window_|. |
| 719 if (child == dragged_window_) | 709 if (child == dragged_window_) |
| 720 return; | 710 return; |
| 721 // If this is the last window, set alignment and maximize the workspace. | 711 // If this is the last window, set alignment and maximize the workspace. |
| 722 if (!IsAnyWindowDocked()) { | 712 if (!IsAnyWindowDocked()) { |
| 723 alignment_ = DOCKED_ALIGNMENT_NONE; | 713 alignment_ = DOCKED_ALIGNMENT_NONE; |
| 724 UpdateDockedWidth(0); | 714 UpdateDockedWidth(0); |
| 725 } | 715 } |
| 726 if (last_active_window_ == child) | 716 if (last_active_window_ == child) |
| 727 last_active_window_ = nullptr; | 717 last_active_window_ = NULL; |
| 728 child->RemoveObserver(this); | 718 child->RemoveObserver(this); |
| 729 wm::GetWindowState(child)->RemoveObserver(this); | 719 wm::GetWindowState(child)->RemoveObserver(this); |
| 730 Relayout(); | 720 Relayout(); |
| 731 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 721 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
| 732 } | 722 } |
| 733 | 723 |
| 734 void DockedWindowLayoutManager::OnChildWindowVisibilityChanged( | 724 void DockedWindowLayoutManager::OnChildWindowVisibilityChanged( |
| 735 aura::Window* child, | 725 aura::Window* child, |
| 736 bool visible) { | 726 bool visible) { |
| 737 if (IsPopupOrTransient(child)) | 727 if (IsPopupOrTransient(child)) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 alignment_ = DOCKED_ALIGNMENT_RIGHT; | 814 alignment_ = DOCKED_ALIGNMENT_RIGHT; |
| 825 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && | 815 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && |
| 826 shelf_alignment == SHELF_ALIGNMENT_RIGHT) { | 816 shelf_alignment == SHELF_ALIGNMENT_RIGHT) { |
| 827 alignment_ = DOCKED_ALIGNMENT_LEFT; | 817 alignment_ = DOCKED_ALIGNMENT_LEFT; |
| 828 } | 818 } |
| 829 Relayout(); | 819 Relayout(); |
| 830 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); | 820 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); |
| 831 } | 821 } |
| 832 | 822 |
| 833 ///////////////////////////////////////////////////////////////////////////// | 823 ///////////////////////////////////////////////////////////////////////////// |
| 824 // DockedWindowLayoutManager, ShelfLayoutManagerObserver implementation: |
| 825 void DockedWindowLayoutManager::OnBackgroundUpdated( |
| 826 ShelfBackgroundType background_type, |
| 827 BackgroundAnimatorChangeType change_type) { |
| 828 background_widget_->SetBackgroundType(background_type, change_type); |
| 829 } |
| 830 |
| 831 ///////////////////////////////////////////////////////////////////////////// |
| 834 // DockedWindowLayoutManager, WindowStateObserver implementation: | 832 // DockedWindowLayoutManager, WindowStateObserver implementation: |
| 835 | 833 |
| 836 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( | 834 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( |
| 837 wm::WindowState* window_state, | 835 wm::WindowState* window_state, |
| 838 wm::WindowStateType old_type) { | 836 wm::WindowStateType old_type) { |
| 839 aura::Window* window = window_state->window(); | 837 aura::Window* window = window_state->window(); |
| 840 if (IsPopupOrTransient(window)) | 838 if (IsPopupOrTransient(window)) |
| 841 return; | 839 return; |
| 842 // The window property will still be set, but no actual change will occur | 840 // The window property will still be set, but no actual change will occur |
| 843 // until OnFullscreenStateChange is called when exiting fullscreen. | 841 // until OnFullscreenStateChange is called when exiting fullscreen. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 ::wm::SetWindowVisibilityAnimationType(window, animation_type); | 885 ::wm::SetWindowVisibilityAnimationType(window, animation_type); |
| 888 } | 886 } |
| 889 | 887 |
| 890 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { | 888 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 891 if (dragged_window_ == window) { | 889 if (dragged_window_ == window) { |
| 892 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); | 890 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); |
| 893 DCHECK(!dragged_window_); | 891 DCHECK(!dragged_window_); |
| 894 DCHECK(!is_dragged_window_docked_); | 892 DCHECK(!is_dragged_window_docked_); |
| 895 } | 893 } |
| 896 if (window == last_active_window_) | 894 if (window == last_active_window_) |
| 897 last_active_window_ = nullptr; | 895 last_active_window_ = NULL; |
| 898 RecordUmaAction(DOCKED_ACTION_CLOSE, event_source_); | 896 RecordUmaAction(DOCKED_ACTION_CLOSE, event_source_); |
| 899 } | 897 } |
| 900 | 898 |
| 899 |
| 901 //////////////////////////////////////////////////////////////////////////////// | 900 //////////////////////////////////////////////////////////////////////////////// |
| 902 // DockedWindowLayoutManager, aura::client::ActivationChangeObserver | 901 // DockedWindowLayoutManager, aura::client::ActivationChangeObserver |
| 903 // implementation: | 902 // implementation: |
| 904 | 903 |
| 905 void DockedWindowLayoutManager::OnWindowActivated( | 904 void DockedWindowLayoutManager::OnWindowActivated( |
| 906 aura::client::ActivationChangeObserver::ActivationReason reason, | 905 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 907 aura::Window* gained_active, | 906 aura::Window* gained_active, |
| 908 aura::Window* lost_active) { | 907 aura::Window* lost_active) { |
| 909 if (gained_active && IsPopupOrTransient(gained_active)) | 908 if (gained_active && IsPopupOrTransient(gained_active)) |
| 910 return; | 909 return; |
| 911 // Ignore if the window that is not managed by this was activated. | 910 // Ignore if the window that is not managed by this was activated. |
| 912 aura::Window* ancestor = nullptr; | 911 aura::Window* ancestor = NULL; |
| 913 for (aura::Window* parent = gained_active; | 912 for (aura::Window* parent = gained_active; |
| 914 parent; parent = parent->parent()) { | 913 parent; parent = parent->parent()) { |
| 915 if (parent->parent() == dock_container_) { | 914 if (parent->parent() == dock_container_) { |
| 916 ancestor = parent; | 915 ancestor = parent; |
| 917 break; | 916 break; |
| 918 } | 917 } |
| 919 } | 918 } |
| 920 if (ancestor) | 919 if (ancestor) |
| 921 UpdateStacking(ancestor); | 920 UpdateStacking(ancestor); |
| 922 } | 921 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 } | 1068 } |
| 1070 | 1069 |
| 1071 void DockedWindowLayoutManager::Relayout() { | 1070 void DockedWindowLayoutManager::Relayout() { |
| 1072 if (in_layout_) | 1071 if (in_layout_) |
| 1073 return; | 1072 return; |
| 1074 if (alignment_ == DOCKED_ALIGNMENT_NONE && !is_dragged_window_docked_) | 1073 if (alignment_ == DOCKED_ALIGNMENT_NONE && !is_dragged_window_docked_) |
| 1075 return; | 1074 return; |
| 1076 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 1075 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
| 1077 | 1076 |
| 1078 gfx::Rect dock_bounds = dock_container_->GetBoundsInScreen(); | 1077 gfx::Rect dock_bounds = dock_container_->GetBoundsInScreen(); |
| 1079 aura::Window* active_window = nullptr; | 1078 aura::Window* active_window = NULL; |
| 1080 std::vector<WindowWithHeight> visible_windows; | 1079 std::vector<WindowWithHeight> visible_windows; |
| 1081 for (size_t i = 0; i < dock_container_->children().size(); ++i) { | 1080 for (size_t i = 0; i < dock_container_->children().size(); ++i) { |
| 1082 aura::Window* window(dock_container_->children()[i]); | 1081 aura::Window* window(dock_container_->children()[i]); |
| 1083 | 1082 |
| 1084 if (!IsWindowDocked(window) || window == dragged_window_) | 1083 if (!IsWindowDocked(window) || window == dragged_window_) |
| 1085 continue; | 1084 continue; |
| 1086 | 1085 |
| 1087 // If the shelf is currently hidden (full-screen mode), hide window until | 1086 // If the shelf is currently hidden (full-screen mode), hide window until |
| 1088 // full-screen mode is exited. | 1087 // full-screen mode is exited. |
| 1089 if (in_fullscreen_) { | 1088 if (in_fullscreen_) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 int new_width = ideal_docked_width; | 1199 int new_width = ideal_docked_width; |
| 1201 if (visible_windows->empty() || | 1200 if (visible_windows->empty() || |
| 1202 (visible_windows->size() == 1 && | 1201 (visible_windows->size() == 1 && |
| 1203 (*visible_windows)[0].window() == dragged_window_)) { | 1202 (*visible_windows)[0].window() == dragged_window_)) { |
| 1204 new_width = 0; | 1203 new_width = 0; |
| 1205 } | 1204 } |
| 1206 UpdateDockedWidth(new_width); | 1205 UpdateDockedWidth(new_width); |
| 1207 // Sort windows by their center positions and fan out overlapping | 1206 // Sort windows by their center positions and fan out overlapping |
| 1208 // windows. | 1207 // windows. |
| 1209 std::sort(visible_windows->begin(), visible_windows->end(), | 1208 std::sort(visible_windows->begin(), visible_windows->end(), |
| 1210 CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : nullptr, | 1209 CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : NULL, |
| 1211 dock_container_, delta)); | 1210 dock_container_, |
| 1211 delta)); |
| 1212 for (std::vector<WindowWithHeight>::iterator iter = visible_windows->begin(); | 1212 for (std::vector<WindowWithHeight>::iterator iter = visible_windows->begin(); |
| 1213 iter != visible_windows->end(); ++iter) { | 1213 iter != visible_windows->end(); ++iter) { |
| 1214 aura::Window* window = iter->window(); | 1214 aura::Window* window = iter->window(); |
| 1215 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen( | 1215 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen( |
| 1216 dock_container_, window->GetTargetBounds()); | 1216 dock_container_, window->GetTargetBounds()); |
| 1217 // A window is extended or shrunk to be as close as possible to the ideal | 1217 // A window is extended or shrunk to be as close as possible to the ideal |
| 1218 // docked area width. Windows that were resized by a user are kept at their | 1218 // docked area width. Windows that were resized by a user are kept at their |
| 1219 // existing size. | 1219 // existing size. |
| 1220 // This also enforces the min / max restrictions on the docked area width. | 1220 // This also enforces the min / max restrictions on the docked area width. |
| 1221 bounds.set_width(GetWindowWidthCloseTo( | 1221 bounds.set_width(GetWindowWidthCloseTo( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 docked_bounds_ = bounds + | 1285 docked_bounds_ = bounds + |
| 1286 dock_container_->GetBoundsInScreen().OffsetFromOrigin(); | 1286 dock_container_->GetBoundsInScreen().OffsetFromOrigin(); |
| 1287 FOR_EACH_OBSERVER( | 1287 FOR_EACH_OBSERVER( |
| 1288 DockedWindowLayoutManagerObserver, | 1288 DockedWindowLayoutManagerObserver, |
| 1289 observer_list_, | 1289 observer_list_, |
| 1290 OnDockBoundsChanging(bounds, reason)); | 1290 OnDockBoundsChanging(bounds, reason)); |
| 1291 // Show or hide background for docked area. | 1291 // Show or hide background for docked area. |
| 1292 gfx::Rect background_bounds(docked_bounds_); | 1292 gfx::Rect background_bounds(docked_bounds_); |
| 1293 if (shelf_observer_) | 1293 if (shelf_observer_) |
| 1294 background_bounds.Subtract(shelf_observer_->shelf_bounds_in_screen()); | 1294 background_bounds.Subtract(shelf_observer_->shelf_bounds_in_screen()); |
| 1295 if (docked_width_ > 0) { | 1295 background_widget_->SetBackgroundBounds(background_bounds, alignment_); |
| 1296 if (!background_widget_) | 1296 if (docked_width_ > 0) |
| 1297 background_widget_.reset(new DockedBackgroundWidget(dock_container_)); | |
| 1298 background_widget_->SetBackgroundBounds(background_bounds, alignment_); | |
| 1299 background_widget_->Show(); | 1297 background_widget_->Show(); |
| 1300 } else if (background_widget_) { | 1298 else |
| 1301 background_widget_->Hide(); | 1299 background_widget_->Hide(); |
| 1302 } | |
| 1303 } | 1300 } |
| 1304 | 1301 |
| 1305 void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) { | 1302 void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) { |
| 1306 if (!active_window) { | 1303 if (!active_window) { |
| 1307 if (!last_active_window_) | 1304 if (!last_active_window_) |
| 1308 return; | 1305 return; |
| 1309 active_window = last_active_window_; | 1306 active_window = last_active_window_; |
| 1310 } | 1307 } |
| 1311 | 1308 |
| 1312 // Windows are stacked like a deck of cards: | 1309 // Windows are stacked like a deck of cards: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1328 if (!IsWindowDocked(*it) || | 1325 if (!IsWindowDocked(*it) || |
| 1329 ((*it) == dragged_window_ && !is_dragged_window_docked_)) { | 1326 ((*it) == dragged_window_ && !is_dragged_window_docked_)) { |
| 1330 continue; | 1327 continue; |
| 1331 } | 1328 } |
| 1332 gfx::Rect bounds = (*it)->bounds(); | 1329 gfx::Rect bounds = (*it)->bounds(); |
| 1333 window_ordering.insert(std::make_pair(bounds.y() + bounds.height() / 2, | 1330 window_ordering.insert(std::make_pair(bounds.y() + bounds.height() / 2, |
| 1334 *it)); | 1331 *it)); |
| 1335 } | 1332 } |
| 1336 int active_center_y = active_window->bounds().CenterPoint().y(); | 1333 int active_center_y = active_window->bounds().CenterPoint().y(); |
| 1337 | 1334 |
| 1338 aura::Window* previous_window = nullptr; | 1335 aura::Window* previous_window = NULL; |
| 1339 for (std::map<int, aura::Window*>::const_iterator it = | 1336 for (std::map<int, aura::Window*>::const_iterator it = |
| 1340 window_ordering.begin(); | 1337 window_ordering.begin(); |
| 1341 it != window_ordering.end() && it->first < active_center_y; ++it) { | 1338 it != window_ordering.end() && it->first < active_center_y; ++it) { |
| 1342 if (previous_window) | 1339 if (previous_window) |
| 1343 dock_container_->StackChildAbove(it->second, previous_window); | 1340 dock_container_->StackChildAbove(it->second, previous_window); |
| 1344 previous_window = it->second; | 1341 previous_window = it->second; |
| 1345 } | 1342 } |
| 1346 for (std::map<int, aura::Window*>::const_reverse_iterator it = | 1343 for (std::map<int, aura::Window*>::const_reverse_iterator it = |
| 1347 window_ordering.rbegin(); | 1344 window_ordering.rbegin(); |
| 1348 it != window_ordering.rend() && it->first > active_center_y; ++it) { | 1345 it != window_ordering.rend() && it->first > active_center_y; ++it) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1362 | 1359 |
| 1363 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1360 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
| 1364 const gfx::Rect& keyboard_bounds) { | 1361 const gfx::Rect& keyboard_bounds) { |
| 1365 // This bounds change will have caused a change to the Shelf which does not | 1362 // This bounds change will have caused a change to the Shelf which does not |
| 1366 // propagate automatically to this class, so manually recalculate bounds. | 1363 // propagate automatically to this class, so manually recalculate bounds. |
| 1367 Relayout(); | 1364 Relayout(); |
| 1368 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1365 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
| 1369 } | 1366 } |
| 1370 | 1367 |
| 1371 } // namespace ash | 1368 } // namespace ash |
| OLD | NEW |