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

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

Issue 2129773002: [CrOS] Initial rough cut of alt-tab window cycling UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: function rename Created 4 years, 5 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
« no previous file with comments | « ash/common/wm/forwarding_layer_delegate.cc ('k') | ash/wm/window_cycle_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/shell_window_ids.h" 10 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/wm/forwarding_layer_delegate.h"
10 #include "ash/display/window_tree_host_manager.h" 12 #include "ash/display/window_tree_host_manager.h"
11 #include "ash/screen_util.h" 13 #include "ash/screen_util.h"
12 #include "ash/shell.h" 14 #include "ash/shell.h"
13 #include "ash/wm/window_util.h" 15 #include "ash/wm/window_util.h"
14 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
15 #include "ui/aura/client/aura_constants.h" 17 #include "ui/aura/client/aura_constants.h"
16 #include "ui/aura/client/screen_position_client.h" 18 #include "ui/aura/client/screen_position_client.h"
17 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
18 #include "ui/aura/window_delegate.h" 20 #include "ui/aura/window_delegate.h"
19 #include "ui/aura/window_event_dispatcher.h" 21 #include "ui/aura/window_event_dispatcher.h"
20 #include "ui/base/hit_test.h" 22 #include "ui/base/hit_test.h"
21 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
22 #include "ui/compositor/layer_tree_owner.h" 24 #include "ui/compositor/layer_tree_owner.h"
23 #include "ui/compositor/paint_context.h" 25 #include "ui/compositor/paint_context.h"
24 #include "ui/compositor/scoped_layer_animation_settings.h" 26 #include "ui/compositor/scoped_layer_animation_settings.h"
25 #include "ui/views/view.h" 27 #include "ui/views/view.h"
26 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
27 #include "ui/wm/core/shadow_types.h" 29 #include "ui/wm/core/shadow_types.h"
28 #include "ui/wm/core/window_util.h" 30 #include "ui/wm/core/window_util.h"
29 31
30 namespace ash { 32 namespace ash {
31 namespace {
32 33
33 // A layer delegate to paint the content of the recreaetd layers 34 // This keeps track of the drag window's state. It creates/destroys/updates
34 // by delegating the paint request to the original delegate. 35 // bounds and opacity based on the current bounds.
35 // It checks if the orignal delegate is still valid by traversing
36 // the original layers.
37 class DragWindowLayerDelegate : public ui::LayerDelegate {
38 public:
39 DragWindowLayerDelegate(aura::Window* original_window,
40 ui::LayerDelegate* delegate)
41 : original_window_(original_window), original_delegate_(delegate) {}
42 ~DragWindowLayerDelegate() override {}
43
44 private:
45 // ui:LayerDelegate:
46 void OnPaintLayer(const ui::PaintContext& context) override {
47 if (!original_delegate_)
48 return;
49 // |original_delegate_| may have already been deleted or
50 // disconnected by this time. Check if |original_delegate_| is still
51 // used by the original_window tree, or skip otherwise.
52 if (IsDelegateValid(original_window_->layer()))
53 original_delegate_->OnPaintLayer(context);
54 else
55 original_delegate_ = nullptr;
56 }
57 void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {}
58 void OnDeviceScaleFactorChanged(float device_scale_factor) override {
59 // Don't tell the original delegate about device scale factor change
60 // on cloned layer because the original layer is still on the same display.
61 }
62 base::Closure PrepareForLayerBoundsChange() override {
63 return base::Closure();
64 }
65
66 bool IsDelegateValid(ui::Layer* layer) {
67 if (layer->delegate() == original_delegate_)
68 return true;
69 for (auto* child : layer->children()) {
70 if (IsDelegateValid(child))
71 return true;
72 }
73 return false;
74 }
75
76 aura::Window* original_window_;
77 ui::LayerDelegate* original_delegate_;
78
79 DISALLOW_COPY_AND_ASSIGN(DragWindowLayerDelegate);
80 };
81
82 } // namespace
83
84 // This keeps tack of the drag window's state. It creates/destory/updates bounds
85 // and opacity based on the current bounds.
86 class DragWindowController::DragWindowDetails 36 class DragWindowController::DragWindowDetails
87 : public aura::WindowDelegate, 37 : public aura::WindowDelegate,
88 public ::wm::LayerDelegateFactory { 38 public ::wm::LayerDelegateFactory {
89 public: 39 public:
90 DragWindowDetails(const display::Display& display, 40 DragWindowDetails(const display::Display& display,
91 aura::Window* original_window) 41 aura::Window* original_window)
92 : root_window_(Shell::GetInstance() 42 : root_window_(Shell::GetInstance()
93 ->window_tree_host_manager() 43 ->window_tree_host_manager()
94 ->GetRootWindowForDisplayId(display.id())) {} 44 ->GetRootWindowForDisplayId(display.id())) {}
95 45
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 ui::Layer* layer = drag_window_->layer(); 129 ui::Layer* layer = drag_window_->layer();
180 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); 130 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator());
181 layer->SetOpacity(opacity); 131 layer->SetOpacity(opacity);
182 layer_owner_->root()->SetOpacity(1.0f); 132 layer_owner_->root()->SetOpacity(1.0f);
183 } 133 }
184 134
185 // aura::WindowDelegate: 135 // aura::WindowDelegate:
186 ui::LayerDelegate* CreateDelegate(ui::LayerDelegate* delegate) override { 136 ui::LayerDelegate* CreateDelegate(ui::LayerDelegate* delegate) override {
187 if (!delegate) 137 if (!delegate)
188 return nullptr; 138 return nullptr;
189 DragWindowLayerDelegate* new_delegate = 139 wm::ForwardingLayerDelegate* new_delegate = new wm::ForwardingLayerDelegate(
190 new DragWindowLayerDelegate(original_window_, delegate); 140 WmWindowAura::Get(original_window_), delegate);
191 delegates_.push_back(base::WrapUnique(new_delegate)); 141 delegates_.push_back(base::WrapUnique(new_delegate));
192 return new_delegate; 142 return new_delegate;
193 } 143 }
194 144
195 // aura::WindowDelegate: 145 // aura::WindowDelegate:
196 gfx::Size GetMinimumSize() const override { return gfx::Size(); } 146 gfx::Size GetMinimumSize() const override { return gfx::Size(); }
197 gfx::Size GetMaximumSize() const override { return gfx::Size(); } 147 gfx::Size GetMaximumSize() const override { return gfx::Size(); }
198 void OnBoundsChanged(const gfx::Rect& old_bounds, 148 void OnBoundsChanged(const gfx::Rect& old_bounds,
199 const gfx::Rect& new_bounds) override {} 149 const gfx::Rect& new_bounds) override {}
200 gfx::NativeCursor GetCursor(const gfx::Point& point) override { 150 gfx::NativeCursor GetCursor(const gfx::Point& point) override {
(...skipping 19 matching lines...) Expand all
220 DCHECK_EQ(drag_window_, window); 170 DCHECK_EQ(drag_window_, window);
221 drag_window_ = nullptr; 171 drag_window_ = nullptr;
222 } 172 }
223 173
224 aura::Window* root_window_; 174 aura::Window* root_window_;
225 175
226 aura::Window* drag_window_ = nullptr; // Owned by the container. 176 aura::Window* drag_window_ = nullptr; // Owned by the container.
227 177
228 aura::Window* original_window_ = nullptr; 178 aura::Window* original_window_ = nullptr;
229 179
230 std::vector<std::unique_ptr<DragWindowLayerDelegate>> delegates_; 180 std::vector<std::unique_ptr<wm::ForwardingLayerDelegate>> delegates_;
231 181
232 // The copy of window_->layer() and its descendants. 182 // The copy of window_->layer() and its descendants.
233 std::unique_ptr<ui::LayerTreeOwner> layer_owner_; 183 std::unique_ptr<ui::LayerTreeOwner> layer_owner_;
234 184
235 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails); 185 DISALLOW_COPY_AND_ASSIGN(DragWindowDetails);
236 }; 186 };
237 187
238 // static 188 // static
239 float DragWindowController::GetDragWindowOpacity( 189 float DragWindowController::GetDragWindowOpacity(
240 const gfx::Rect& window_bounds, 190 const gfx::Rect& window_bounds,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 layers.pop_back(); 261 layers.pop_back();
312 if (layer->delegate()) 262 if (layer->delegate())
313 layer->delegate()->OnPaintLayer(context); 263 layer->delegate()->OnPaintLayer(context);
314 for (auto* child : layer->children()) 264 for (auto* child : layer->children())
315 layers.push_back(child); 265 layers.push_back(child);
316 } 266 }
317 } 267 }
318 } 268 }
319 269
320 } // namespace ash 270 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/forwarding_layer_delegate.cc ('k') | ash/wm/window_cycle_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698