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

Side by Side Diff: ash/wm/dock/docked_window_layout_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698