| 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" |
| 11 #include "ash/common/wm/forwarding_layer_delegate.h" |
| 11 #include "ash/display/window_tree_host_manager.h" | 12 #include "ash/display/window_tree_host_manager.h" |
| 12 #include "ash/screen_util.h" | 13 #include "ash/screen_util.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 16 #include "ui/aura/client/aura_constants.h" | 17 #include "ui/aura/client/aura_constants.h" |
| 17 #include "ui/aura/client/screen_position_client.h" | 18 #include "ui/aura/client/screen_position_client.h" |
| 18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 19 #include "ui/aura/window_delegate.h" | 20 #include "ui/aura/window_delegate.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
| 21 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
| 22 #include "ui/compositor/layer.h" | 23 #include "ui/compositor/layer.h" |
| 23 #include "ui/compositor/layer_tree_owner.h" | 24 #include "ui/compositor/layer_tree_owner.h" |
| 24 #include "ui/compositor/paint_context.h" | 25 #include "ui/compositor/paint_context.h" |
| 25 #include "ui/compositor/scoped_layer_animation_settings.h" | 26 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 26 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 28 #include "ui/wm/core/shadow_types.h" | 29 #include "ui/wm/core/shadow_types.h" |
| 29 #include "ui/wm/core/window_util.h" | 30 #include "ui/wm/core/window_util.h" |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 | 33 |
| 33 // This keeps track of the drag window's state. It creates/destroys/updates | 34 // This keeps track of the drag window's state. It creates/destroys/updates |
| 34 // bounds and opacity based on the current bounds. | 35 // bounds and opacity based on the current bounds. |
| 35 class DragWindowController::DragWindowDetails : public aura::WindowDelegate { | 36 class DragWindowController::DragWindowDetails |
| 37 : public aura::WindowDelegate, |
| 38 public ::wm::LayerDelegateFactory { |
| 36 public: | 39 public: |
| 37 DragWindowDetails(const display::Display& display, | 40 DragWindowDetails(const display::Display& display, |
| 38 aura::Window* original_window) | 41 aura::Window* original_window) |
| 39 : root_window_(Shell::GetInstance() | 42 : root_window_(Shell::GetInstance() |
| 40 ->window_tree_host_manager() | 43 ->window_tree_host_manager() |
| 41 ->GetRootWindowForDisplayId(display.id())) {} | 44 ->GetRootWindowForDisplayId(display.id())) {} |
| 42 | 45 |
| 43 ~DragWindowDetails() override { | 46 ~DragWindowDetails() override { |
| 44 delete drag_window_; | 47 delete drag_window_; |
| 45 DCHECK(!drag_window_); | 48 DCHECK(!drag_window_); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 108 |
| 106 // Fade the window in. | 109 // Fade the window in. |
| 107 ui::Layer* drag_layer = drag_window_->layer(); | 110 ui::Layer* drag_layer = drag_window_->layer(); |
| 108 drag_layer->SetOpacity(0); | 111 drag_layer->SetOpacity(0); |
| 109 ui::ScopedLayerAnimationSettings scoped_setter(drag_layer->GetAnimator()); | 112 ui::ScopedLayerAnimationSettings scoped_setter(drag_layer->GetAnimator()); |
| 110 drag_layer->SetOpacity(1); | 113 drag_layer->SetOpacity(1); |
| 111 } | 114 } |
| 112 | 115 |
| 113 void RecreateWindowLayers(aura::Window* original_window) { | 116 void RecreateWindowLayers(aura::Window* original_window) { |
| 114 DCHECK(!layer_owner_.get()); | 117 DCHECK(!layer_owner_.get()); |
| 115 layer_owner_ = ::wm::MirrorLayers(original_window, true /* sync_bounds */); | 118 layer_owner_ = ::wm::RecreateLayers(original_window, this); |
| 116 // Place the layer at (0, 0) of the DragWindowController's window. | 119 // Place the layer at (0, 0) of the DragWindowController's window. |
| 117 gfx::Rect layer_bounds = layer_owner_->root()->bounds(); | 120 gfx::Rect layer_bounds = layer_owner_->root()->bounds(); |
| 118 layer_bounds.set_origin(gfx::Point(0, 0)); | 121 layer_bounds.set_origin(gfx::Point(0, 0)); |
| 119 layer_owner_->root()->SetBounds(layer_bounds); | 122 layer_owner_->root()->SetBounds(layer_bounds); |
| 120 layer_owner_->root()->SetVisible(false); | 123 layer_owner_->root()->SetVisible(false); |
| 124 // Detach it from the current container. |
| 125 layer_owner_->root()->parent()->Remove(layer_owner_->root()); |
| 121 } | 126 } |
| 122 | 127 |
| 123 void SetOpacity(const aura::Window* original_window, float opacity) { | 128 void SetOpacity(const aura::Window* original_window, float opacity) { |
| 124 ui::Layer* layer = drag_window_->layer(); | 129 ui::Layer* layer = drag_window_->layer(); |
| 125 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); | 130 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); |
| 126 layer->SetOpacity(opacity); | 131 layer->SetOpacity(opacity); |
| 127 layer_owner_->root()->SetOpacity(1.0f); | 132 layer_owner_->root()->SetOpacity(1.0f); |
| 128 } | 133 } |
| 129 | 134 |
| 130 // aura::WindowDelegate: | 135 // aura::WindowDelegate: |
| 136 ui::LayerDelegate* CreateDelegate(ui::Layer* foo, ui::Layer* layer) override { |
| 137 if (!layer || !layer->delegate()) |
| 138 return nullptr; |
| 139 wm::ForwardingLayerDelegate* new_delegate = |
| 140 new wm::ForwardingLayerDelegate(foo, layer); |
| 141 delegates_.push_back(base::WrapUnique(new_delegate)); |
| 142 return new_delegate; |
| 143 } |
| 144 |
| 145 // aura::WindowDelegate: |
| 131 gfx::Size GetMinimumSize() const override { return gfx::Size(); } | 146 gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
| 132 gfx::Size GetMaximumSize() const override { return gfx::Size(); } | 147 gfx::Size GetMaximumSize() const override { return gfx::Size(); } |
| 133 void OnBoundsChanged(const gfx::Rect& old_bounds, | 148 void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 134 const gfx::Rect& new_bounds) override {} | 149 const gfx::Rect& new_bounds) override {} |
| 135 gfx::NativeCursor GetCursor(const gfx::Point& point) override { | 150 gfx::NativeCursor GetCursor(const gfx::Point& point) override { |
| 136 return gfx::kNullCursor; | 151 return gfx::kNullCursor; |
| 137 } | 152 } |
| 138 int GetNonClientComponent(const gfx::Point& point) const override { | 153 int GetNonClientComponent(const gfx::Point& point) const override { |
| 139 return HTNOWHERE; | 154 return HTNOWHERE; |
| 140 } | 155 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 155 DCHECK_EQ(drag_window_, window); | 170 DCHECK_EQ(drag_window_, window); |
| 156 drag_window_ = nullptr; | 171 drag_window_ = nullptr; |
| 157 } | 172 } |
| 158 | 173 |
| 159 aura::Window* root_window_; | 174 aura::Window* root_window_; |
| 160 | 175 |
| 161 aura::Window* drag_window_ = nullptr; // Owned by the container. | 176 aura::Window* drag_window_ = nullptr; // Owned by the container. |
| 162 | 177 |
| 163 aura::Window* original_window_ = nullptr; | 178 aura::Window* original_window_ = nullptr; |
| 164 | 179 |
| 180 std::vector<std::unique_ptr<wm::ForwardingLayerDelegate>> delegates_; |
| 181 |
| 165 // The copy of window_->layer() and its descendants. | 182 // The copy of window_->layer() and its descendants. |
| 166 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; | 183 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; |
| 167 | 184 |
| 168 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); | 185 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); |
| 169 }; | 186 }; |
| 170 | 187 |
| 171 // static | 188 // static |
| 172 float DragWindowController::GetDragWindowOpacity( | 189 float DragWindowController::GetDragWindowOpacity( |
| 173 const gfx::Rect& window_bounds, | 190 const gfx::Rect& window_bounds, |
| 174 const gfx::Rect& visible_bounds) { | 191 const gfx::Rect& visible_bounds) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 layers.pop_back(); | 261 layers.pop_back(); |
| 245 if (layer->delegate()) | 262 if (layer->delegate()) |
| 246 layer->delegate()->OnPaintLayer(context); | 263 layer->delegate()->OnPaintLayer(context); |
| 247 for (auto* child : layer->children()) | 264 for (auto* child : layer->children()) |
| 248 layers.push_back(child); | 265 layers.push_back(child); |
| 249 } | 266 } |
| 250 } | 267 } |
| 251 } | 268 } |
| 252 | 269 |
| 253 } // namespace ash | 270 } // namespace ash |
| OLD | NEW |