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

Side by Side Diff: ash/wm/drag_window_controller.cc

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

Powered by Google App Engine
This is Rietveld 408576698