Chromium Code Reviews| 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. | |
|
oshima
2016/10/04 21:06:31
thanks for catching this. i believe this fixes the
| |
| 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()); |
| 119 sync_bounds_ = false; | |
| 118 layer_owner_ = ::wm::RecreateLayers(original_window, this); | 120 layer_owner_ = ::wm::RecreateLayers(original_window, this); |
| 119 // Place the layer at (0, 0) of the DragWindowController's window. | 121 // Place the layer at (0, 0) of the DragWindowController's window. |
| 120 gfx::Rect layer_bounds = layer_owner_->root()->bounds(); | 122 gfx::Rect layer_bounds = layer_owner_->root()->bounds(); |
| 121 layer_bounds.set_origin(gfx::Point(0, 0)); | 123 layer_bounds.set_origin(gfx::Point(0, 0)); |
| 122 layer_owner_->root()->SetBounds(layer_bounds); | 124 layer_owner_->root()->SetBounds(layer_bounds); |
| 123 layer_owner_->root()->SetVisible(false); | 125 layer_owner_->root()->SetVisible(false); |
| 124 // Detach it from the current container. | 126 // Detach it from the current container. |
| 125 layer_owner_->root()->parent()->Remove(layer_owner_->root()); | 127 layer_owner_->root()->parent()->Remove(layer_owner_->root()); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void SetOpacity(const aura::Window* original_window, float opacity) { | 130 void SetOpacity(const aura::Window* original_window, float opacity) { |
| 129 ui::Layer* layer = drag_window_->layer(); | 131 ui::Layer* layer = drag_window_->layer(); |
| 130 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); | 132 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); |
| 131 layer->SetOpacity(opacity); | 133 layer->SetOpacity(opacity); |
| 132 layer_owner_->root()->SetOpacity(1.0f); | 134 layer_owner_->root()->SetOpacity(1.0f); |
| 133 } | 135 } |
| 134 | 136 |
| 135 // aura::WindowDelegate: | 137 // wm::LayerDelegateFactory: |
| 136 ui::LayerDelegate* CreateDelegate(ui::Layer* foo, ui::Layer* layer) override { | 138 ui::LayerDelegate* CreateDelegate(ui::Layer* new_layer, |
| 139 ui::Layer* layer) override { | |
| 137 if (!layer || !layer->delegate()) | 140 if (!layer || !layer->delegate()) |
| 138 return nullptr; | 141 return nullptr; |
| 139 wm::ForwardingLayerDelegate* new_delegate = | 142 wm::ForwardingLayerDelegate* new_delegate = |
| 140 new wm::ForwardingLayerDelegate(foo, layer); | 143 new wm::ForwardingLayerDelegate(new_layer, layer, sync_bounds_); |
| 144 sync_bounds_ = true; | |
| 141 delegates_.push_back(base::WrapUnique(new_delegate)); | 145 delegates_.push_back(base::WrapUnique(new_delegate)); |
| 142 return new_delegate; | 146 return new_delegate; |
| 143 } | 147 } |
| 144 | 148 |
| 145 // aura::WindowDelegate: | 149 // aura::WindowDelegate: |
| 146 gfx::Size GetMinimumSize() const override { return gfx::Size(); } | 150 gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
| 147 gfx::Size GetMaximumSize() const override { return gfx::Size(); } | 151 gfx::Size GetMaximumSize() const override { return gfx::Size(); } |
| 148 void OnBoundsChanged(const gfx::Rect& old_bounds, | 152 void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 149 const gfx::Rect& new_bounds) override {} | 153 const gfx::Rect& new_bounds) override {} |
| 150 gfx::NativeCursor GetCursor(const gfx::Point& point) override { | 154 gfx::NativeCursor GetCursor(const gfx::Point& point) override { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 169 void OnWindowDestroying(aura::Window* window) override { | 173 void OnWindowDestroying(aura::Window* window) override { |
| 170 DCHECK_EQ(drag_window_, window); | 174 DCHECK_EQ(drag_window_, window); |
| 171 drag_window_ = nullptr; | 175 drag_window_ = nullptr; |
| 172 } | 176 } |
| 173 | 177 |
| 174 aura::Window* root_window_; | 178 aura::Window* root_window_; |
| 175 | 179 |
| 176 aura::Window* drag_window_ = nullptr; // Owned by the container. | 180 aura::Window* drag_window_ = nullptr; // Owned by the container. |
| 177 | 181 |
| 178 aura::Window* original_window_ = nullptr; | 182 aura::Window* original_window_ = nullptr; |
| 183 bool sync_bounds_; // Used during cloning. True for all layers but the root. | |
| 179 | 184 |
| 180 std::vector<std::unique_ptr<wm::ForwardingLayerDelegate>> delegates_; | 185 std::vector<std::unique_ptr<wm::ForwardingLayerDelegate>> delegates_; |
| 181 | 186 |
| 182 // The copy of window_->layer() and its descendants. | 187 // The copy of window_->layer() and its descendants. |
| 183 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; | 188 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; |
| 184 | 189 |
| 185 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); | 190 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); |
| 186 }; | 191 }; |
| 187 | 192 |
| 188 // static | 193 // static |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 layers.pop_back(); | 266 layers.pop_back(); |
| 262 if (layer->delegate()) | 267 if (layer->delegate()) |
| 263 layer->delegate()->OnPaintLayer(context); | 268 layer->delegate()->OnPaintLayer(context); |
| 264 for (auto* child : layer->children()) | 269 for (auto* child : layer->children()) |
| 265 layers.push_back(child); | 270 layers.push_back(child); |
| 266 } | 271 } |
| 267 } | 272 } |
| 268 } | 273 } |
| 269 | 274 |
| 270 } // namespace ash | 275 } // namespace ash |
| OLD | NEW |