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

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

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Rebase 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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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_ =
120 ::wm::MirrorLayers(original_window, this, true /* sync_bounds */);
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.
125 layer_owner_->root()->parent()->Remove(layer_owner_->root());
126 } 126 }
127 127
128 void SetOpacity(const aura::Window* original_window, float opacity) { 128 void SetOpacity(const aura::Window* original_window, float opacity) {
129 ui::Layer* layer = drag_window_->layer(); 129 ui::Layer* layer = drag_window_->layer();
130 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); 130 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator());
131 layer->SetOpacity(opacity); 131 layer->SetOpacity(opacity);
132 layer_owner_->root()->SetOpacity(1.0f); 132 layer_owner_->root()->SetOpacity(1.0f);
133 } 133 }
134 134
135 // aura::WindowDelegate: 135 // wm::LayerDelegateFactory:
136 ui::LayerDelegate* CreateDelegate(ui::Layer* foo, ui::Layer* layer) override { 136 ui::LayerDelegate* CreateDelegate(ui::Layer* new_layer,
137 ui::Layer* layer) override {
137 if (!layer || !layer->delegate()) 138 if (!layer || !layer->delegate())
138 return nullptr; 139 return nullptr;
139 wm::ForwardingLayerDelegate* new_delegate = 140 wm::ForwardingLayerDelegate* new_delegate =
140 new wm::ForwardingLayerDelegate(foo, layer); 141 new wm::ForwardingLayerDelegate(new_layer, layer);
141 delegates_.push_back(base::WrapUnique(new_delegate)); 142 delegates_.push_back(base::WrapUnique(new_delegate));
142 return new_delegate; 143 return new_delegate;
143 } 144 }
144 145
145 // aura::WindowDelegate: 146 // aura::WindowDelegate:
146 gfx::Size GetMinimumSize() const override { return gfx::Size(); } 147 gfx::Size GetMinimumSize() const override { return gfx::Size(); }
147 gfx::Size GetMaximumSize() const override { return gfx::Size(); } 148 gfx::Size GetMaximumSize() const override { return gfx::Size(); }
148 void OnBoundsChanged(const gfx::Rect& old_bounds, 149 void OnBoundsChanged(const gfx::Rect& old_bounds,
149 const gfx::Rect& new_bounds) override {} 150 const gfx::Rect& new_bounds) override {}
150 gfx::NativeCursor GetCursor(const gfx::Point& point) override { 151 gfx::NativeCursor GetCursor(const gfx::Point& point) override {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 layers.pop_back(); 262 layers.pop_back();
262 if (layer->delegate()) 263 if (layer->delegate())
263 layer->delegate()->OnPaintLayer(context); 264 layer->delegate()->OnPaintLayer(context);
264 for (auto* child : layer->children()) 265 for (auto* child : layer->children())
265 layers.push_back(child); 266 layers.push_back(child);
266 } 267 }
267 } 268 }
268 } 269 }
269 270
270 } // namespace ash 271 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698