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/drag_window_controller.h" | 5 #include "ash/wm/drag_window_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 void Update(aura::Window* original_window, | 51 void Update(aura::Window* original_window, |
52 const gfx::Rect& bounds_in_screen, | 52 const gfx::Rect& bounds_in_screen, |
53 const gfx::Point& drag_location_in_screen) { | 53 const gfx::Point& drag_location_in_screen) { |
54 gfx::Rect root_bounds_in_screen = root_window_->GetBoundsInScreen(); | 54 gfx::Rect root_bounds_in_screen = root_window_->GetBoundsInScreen(); |
55 if (!root_bounds_in_screen.Intersects(bounds_in_screen)) { | 55 if (!root_bounds_in_screen.Intersects(bounds_in_screen)) { |
56 delete drag_window_; | 56 delete drag_window_; |
57 // Make sure drag_window_ is reset so that new drag window will be created | 57 // Make sure drag_window_ is reset so that new drag window will be created |
58 // when it becomes necessary again. | 58 // when it becomes necessary again. |
59 DCHECK(!drag_window_); | 59 DCHECK(!drag_window_); |
60 layer_owner_.reset(); | 60 layer_owner_.reset(); |
| 61 delegates_.clear(); // Stop observing layers. |
61 return; | 62 return; |
62 } | 63 } |
63 if (!drag_window_) | 64 if (!drag_window_) |
64 CreateDragWindow(original_window, bounds_in_screen); | 65 CreateDragWindow(original_window, bounds_in_screen); |
65 | 66 |
66 gfx::Rect bounds_in_root = ScreenUtil::ConvertRectFromScreen( | 67 gfx::Rect bounds_in_root = ScreenUtil::ConvertRectFromScreen( |
67 drag_window_->parent(), bounds_in_screen); | 68 drag_window_->parent(), bounds_in_screen); |
68 drag_window_->SetBounds(bounds_in_root); | 69 drag_window_->SetBounds(bounds_in_root); |
69 if (root_bounds_in_screen.Contains(drag_location_in_screen)) { | 70 if (root_bounds_in_screen.Contains(drag_location_in_screen)) { |
70 SetOpacity(original_window, 1.f); | 71 SetOpacity(original_window, 1.f); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 109 |
109 // Fade the window in. | 110 // Fade the window in. |
110 ui::Layer* drag_layer = drag_window_->layer(); | 111 ui::Layer* drag_layer = drag_window_->layer(); |
111 drag_layer->SetOpacity(0); | 112 drag_layer->SetOpacity(0); |
112 ui::ScopedLayerAnimationSettings scoped_setter(drag_layer->GetAnimator()); | 113 ui::ScopedLayerAnimationSettings scoped_setter(drag_layer->GetAnimator()); |
113 drag_layer->SetOpacity(1); | 114 drag_layer->SetOpacity(1); |
114 } | 115 } |
115 | 116 |
116 void RecreateWindowLayers(aura::Window* original_window) { | 117 void RecreateWindowLayers(aura::Window* original_window) { |
117 DCHECK(!layer_owner_.get()); | 118 DCHECK(!layer_owner_.get()); |
118 layer_owner_ = ::wm::RecreateLayers(original_window, this); | 119 layer_owner_ = ::wm::MirrorLayers(original_window, this); |
119 // Place the layer at (0, 0) of the DragWindowController's window. | 120 // Place the layer at (0, 0) of the DragWindowController's window. |
120 gfx::Rect layer_bounds = layer_owner_->root()->bounds(); | 121 gfx::Rect layer_bounds = layer_owner_->root()->bounds(); |
121 layer_bounds.set_origin(gfx::Point(0, 0)); | 122 layer_bounds.set_origin(gfx::Point(0, 0)); |
122 layer_owner_->root()->SetBounds(layer_bounds); | 123 layer_owner_->root()->SetBounds(layer_bounds); |
123 layer_owner_->root()->SetVisible(false); | 124 layer_owner_->root()->SetVisible(false); |
124 // Detach it from the current container. | |
125 layer_owner_->root()->parent()->Remove(layer_owner_->root()); | |
126 } | 125 } |
127 | 126 |
128 void SetOpacity(const aura::Window* original_window, float opacity) { | 127 void SetOpacity(const aura::Window* original_window, float opacity) { |
129 ui::Layer* layer = drag_window_->layer(); | 128 ui::Layer* layer = drag_window_->layer(); |
130 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); | 129 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); |
131 layer->SetOpacity(opacity); | 130 layer->SetOpacity(opacity); |
132 layer_owner_->root()->SetOpacity(1.0f); | 131 layer_owner_->root()->SetOpacity(1.0f); |
133 } | 132 } |
134 | 133 |
135 // aura::WindowDelegate: | 134 // wm::LayerDelegateFactory: |
136 ui::LayerDelegate* CreateDelegate(ui::Layer* foo, ui::Layer* layer) override { | 135 ui::LayerDelegate* CreateDelegate(ui::Layer* new_layer, |
| 136 ui::Layer* layer) override { |
137 if (!layer || !layer->delegate()) | 137 if (!layer || !layer->delegate()) |
138 return nullptr; | 138 return nullptr; |
139 wm::ForwardingLayerDelegate* new_delegate = | 139 wm::ForwardingLayerDelegate* new_delegate = |
140 new wm::ForwardingLayerDelegate(foo, layer); | 140 new wm::ForwardingLayerDelegate(new_layer, layer); |
141 delegates_.push_back(base::WrapUnique(new_delegate)); | 141 delegates_.push_back(base::WrapUnique(new_delegate)); |
142 return new_delegate; | 142 return new_delegate; |
143 } | 143 } |
144 | 144 |
145 // aura::WindowDelegate: | 145 // aura::WindowDelegate: |
146 gfx::Size GetMinimumSize() const override { return gfx::Size(); } | 146 gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
147 gfx::Size GetMaximumSize() const override { return gfx::Size(); } | 147 gfx::Size GetMaximumSize() const override { return gfx::Size(); } |
148 void OnBoundsChanged(const gfx::Rect& old_bounds, | 148 void OnBoundsChanged(const gfx::Rect& old_bounds, |
149 const gfx::Rect& new_bounds) override {} | 149 const gfx::Rect& new_bounds) override {} |
150 gfx::NativeCursor GetCursor(const gfx::Point& point) override { | 150 gfx::NativeCursor GetCursor(const gfx::Point& point) override { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 layers.pop_back(); | 261 layers.pop_back(); |
262 if (layer->delegate()) | 262 if (layer->delegate()) |
263 layer->delegate()->OnPaintLayer(context); | 263 layer->delegate()->OnPaintLayer(context); |
264 for (auto* child : layer->children()) | 264 for (auto* child : layer->children()) |
265 layers.push_back(child); | 265 layers.push_back(child); |
266 } | 266 } |
267 } | 267 } |
268 } | 268 } |
269 | 269 |
270 } // namespace ash | 270 } // namespace ash |
OLD | NEW |