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/display/window_tree_host_manager.h" | 9 #include "ash/display/window_tree_host_manager.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
| 16 #include "ui/aura/client/screen_position_client.h" | 16 #include "ui/aura/client/screen_position_client.h" |
| 17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
| 19 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
| 20 #include "ui/base/hit_test.h" | 20 #include "ui/base/hit_test.h" |
| 21 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/layer_tree_owner.h" | 22 #include "ui/compositor/layer_tree_owner.h" |
| 23 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 24 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| 25 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 26 #include "ui/wm/core/shadow_types.h" | 26 #include "ui/wm/core/shadow_types.h" |
| 27 #include "ui/wm/core/window_util.h" | 27 #include "ui/wm/core/window_util.h" |
| 28 | 28 |
| 29 namespace ash { | 29 namespace ash { |
| 30 namespace { | |
| 31 | |
| 32 class DragWindowLayerDelegate : public ui::LayerDelegate { | |
|
sky
2016/05/19 20:06:49
Description
oshima
2016/05/19 23:32:21
Done.
| |
| 33 public: | |
| 34 DragWindowLayerDelegate(ui::LayerDelegate* delegate) | |
|
sky
2016/05/19 20:06:49
How do you know the original delegate remains vali
sky
2016/05/19 20:06:49
explicit
oshima
2016/05/19 23:32:21
You're right. The only way to check, without intro
| |
| 35 : original_delegate_(delegate) {} | |
| 36 ~DragWindowLayerDelegate() override {} | |
| 37 | |
| 38 private: | |
| 39 // ui:LLayerDelegate: | |
| 40 void OnPaintLayer(const ui::PaintContext& context) override { | |
| 41 original_delegate_->OnPaintLayer(context); | |
| 42 } | |
| 43 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} | |
| 44 void OnDeviceScaleFactorChanged(float device_scale_factor) override { | |
| 45 // Don't tell the original delegate about device scale factor change | |
| 46 // on cloned layer because the original layer is still on the same display. | |
| 47 } | |
| 48 base::Closure PrepareForLayerBoundsChange() override { | |
| 49 return base::Closure(); | |
| 50 } | |
| 51 | |
| 52 ui::LayerDelegate* original_delegate_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(DragWindowLayerDelegate); | |
| 55 }; | |
| 56 | |
| 57 } // namespace | |
| 30 | 58 |
| 31 // This keeps tack of the drag window's state. It creates/destory/updates bounds | 59 // This keeps tack of the drag window's state. It creates/destory/updates bounds |
| 32 // and opacity based on the current bounds. | 60 // and opacity based on the current bounds. |
| 33 class DragWindowController::DragWindowDetails : public aura::WindowDelegate { | 61 class DragWindowController::DragWindowDetails |
| 62 : public aura::WindowDelegate, | |
| 63 public ::wm::LayerDelegateFactory { | |
| 34 public: | 64 public: |
| 35 DragWindowDetails(const display::Display& display, | 65 DragWindowDetails(const display::Display& display, |
| 36 aura::Window* original_window) | 66 aura::Window* original_window) |
| 37 : root_window_(Shell::GetInstance() | 67 : root_window_(Shell::GetInstance() |
| 38 ->window_tree_host_manager() | 68 ->window_tree_host_manager() |
| 39 ->GetRootWindowForDisplayId(display.id())) {} | 69 ->GetRootWindowForDisplayId(display.id())) {} |
| 40 | 70 |
| 41 ~DragWindowDetails() override { | 71 ~DragWindowDetails() override { |
| 42 delete drag_window_; | 72 delete drag_window_; |
| 43 DCHECK(!drag_window_); | 73 DCHECK(!drag_window_); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 | 132 |
| 103 // Fade the window in. | 133 // Fade the window in. |
| 104 ui::Layer* drag_layer = drag_window_->layer(); | 134 ui::Layer* drag_layer = drag_window_->layer(); |
| 105 drag_layer->SetOpacity(0); | 135 drag_layer->SetOpacity(0); |
| 106 ui::ScopedLayerAnimationSettings scoped_setter(drag_layer->GetAnimator()); | 136 ui::ScopedLayerAnimationSettings scoped_setter(drag_layer->GetAnimator()); |
| 107 drag_layer->SetOpacity(1); | 137 drag_layer->SetOpacity(1); |
| 108 } | 138 } |
| 109 | 139 |
| 110 void RecreateWindowLayers(aura::Window* original_window) { | 140 void RecreateWindowLayers(aura::Window* original_window) { |
| 111 DCHECK(!layer_owner_.get()); | 141 DCHECK(!layer_owner_.get()); |
| 112 layer_owner_ = ::wm::RecreateLayers(original_window); | 142 layer_owner_ = ::wm::RecreateLayers(original_window, this); |
| 113 // TODO(oshima): Recreated child layers may not have been painted | |
| 114 // yet, and may not be able to paint to because it does not have | |
| 115 // its original delegate. | |
| 116 layer_owner_->root()->set_delegate(original_window->layer()->delegate()); | |
| 117 // Place the layer at (0, 0) of the DragWindowController's window. | 143 // Place the layer at (0, 0) of the DragWindowController's window. |
| 118 gfx::Rect layer_bounds = layer_owner_->root()->bounds(); | 144 gfx::Rect layer_bounds = layer_owner_->root()->bounds(); |
| 119 layer_bounds.set_origin(gfx::Point(0, 0)); | 145 layer_bounds.set_origin(gfx::Point(0, 0)); |
| 120 layer_owner_->root()->SetBounds(layer_bounds); | 146 layer_owner_->root()->SetBounds(layer_bounds); |
| 121 layer_owner_->root()->SetVisible(false); | 147 layer_owner_->root()->SetVisible(false); |
| 122 // Detach it from the current container. | 148 // Detach it from the current container. |
| 123 layer_owner_->root()->parent()->Remove(layer_owner_->root()); | 149 layer_owner_->root()->parent()->Remove(layer_owner_->root()); |
| 124 } | 150 } |
| 125 | 151 |
| 126 void SetOpacity(const aura::Window* original_window, float opacity) { | 152 void SetOpacity(const aura::Window* original_window, float opacity) { |
| 127 ui::Layer* layer = drag_window_->layer(); | 153 ui::Layer* layer = drag_window_->layer(); |
| 128 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); | 154 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); |
| 129 layer->SetOpacity(opacity); | 155 layer->SetOpacity(opacity); |
| 130 layer_owner_->root()->SetOpacity(1.0f); | 156 layer_owner_->root()->SetOpacity(1.0f); |
| 131 } | 157 } |
| 132 | 158 |
| 133 // aura::WindowDelegate: | 159 // aura::WindowDelegate: |
| 160 ui::LayerDelegate* CreateDelegate(ui::LayerDelegate* delegate) override { | |
| 161 DragWindowLayerDelegate* new_delegate = | |
| 162 new DragWindowLayerDelegate(delegate); | |
| 163 delegates_.push_back(base::WrapUnique(new_delegate)); | |
| 164 return new_delegate; | |
| 165 } | |
| 166 | |
| 167 // aura::WindowDelegate: | |
| 134 gfx::Size GetMinimumSize() const override { return gfx::Size(); } | 168 gfx::Size GetMinimumSize() const override { return gfx::Size(); } |
| 135 gfx::Size GetMaximumSize() const override { return gfx::Size(); } | 169 gfx::Size GetMaximumSize() const override { return gfx::Size(); } |
| 136 void OnBoundsChanged(const gfx::Rect& old_bounds, | 170 void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 137 const gfx::Rect& new_bounds) override {} | 171 const gfx::Rect& new_bounds) override {} |
| 138 gfx::NativeCursor GetCursor(const gfx::Point& point) override { | 172 gfx::NativeCursor GetCursor(const gfx::Point& point) override { |
| 139 return gfx::kNullCursor; | 173 return gfx::kNullCursor; |
| 140 } | 174 } |
| 141 int GetNonClientComponent(const gfx::Point& point) const override { | 175 int GetNonClientComponent(const gfx::Point& point) const override { |
| 142 return HTNOWHERE; | 176 return HTNOWHERE; |
| 143 } | 177 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 156 void GetHitTestMask(gfx::Path* mask) const override {} | 190 void GetHitTestMask(gfx::Path* mask) const override {} |
| 157 void OnWindowDestroying(aura::Window* window) override { | 191 void OnWindowDestroying(aura::Window* window) override { |
| 158 DCHECK_EQ(drag_window_, window); | 192 DCHECK_EQ(drag_window_, window); |
| 159 drag_window_ = nullptr; | 193 drag_window_ = nullptr; |
| 160 } | 194 } |
| 161 | 195 |
| 162 aura::Window* root_window_; | 196 aura::Window* root_window_; |
| 163 | 197 |
| 164 aura::Window* drag_window_ = nullptr; // Owned by the container. | 198 aura::Window* drag_window_ = nullptr; // Owned by the container. |
| 165 | 199 |
| 200 std::vector<std::unique_ptr<DragWindowLayerDelegate>> delegates_; | |
| 201 | |
| 166 // The copy of window_->layer() and its descendants. | 202 // The copy of window_->layer() and its descendants. |
| 167 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; | 203 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; |
| 168 | 204 |
| 169 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); | 205 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); |
| 170 }; | 206 }; |
| 171 | 207 |
| 172 // static | 208 // static |
| 173 float DragWindowController::GetDragWindowOpacity( | 209 float DragWindowController::GetDragWindowOpacity( |
| 174 const gfx::Rect& window_bounds, | 210 const gfx::Rect& window_bounds, |
| 175 const gfx::Rect& visible_bounds) { | 211 const gfx::Rect& visible_bounds) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 if (details->layer_owner_) { | 265 if (details->layer_owner_) { |
| 230 if (index == 0) | 266 if (index == 0) |
| 231 return details->layer_owner_.get(); | 267 return details->layer_owner_.get(); |
| 232 index--; | 268 index--; |
| 233 } | 269 } |
| 234 } | 270 } |
| 235 return nullptr; | 271 return nullptr; |
| 236 } | 272 } |
| 237 | 273 |
| 238 } // namespace ash | 274 } // namespace ash |
| OLD | NEW |