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

Side by Side Diff: ui/views/corewm/window_animations.cc

Issue 12342028: make menus, bubbles, etc. top level windows on aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixes Created 7 years, 9 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 | Annotate | Revision Log
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 "ui/views/corewm/window_animations.h" 5 #include "ui/views/corewm/window_animations.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/time.h" 17 #include "base/time.h"
18 #include "ui/aura/client/aura_constants.h" 18 #include "ui/aura/client/aura_constants.h"
19 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
20 #include "ui/aura/window_delegate.h"
20 #include "ui/aura/window_observer.h" 21 #include "ui/aura/window_observer.h"
21 #include "ui/aura/window_property.h" 22 #include "ui/aura/window_property.h"
22 #include "ui/compositor/compositor_observer.h" 23 #include "ui/compositor/compositor_observer.h"
23 #include "ui/compositor/layer.h" 24 #include "ui/compositor/layer.h"
24 #include "ui/compositor/layer_animation_observer.h" 25 #include "ui/compositor/layer_animation_observer.h"
25 #include "ui/compositor/layer_animation_sequence.h" 26 #include "ui/compositor/layer_animation_sequence.h"
26 #include "ui/compositor/layer_animator.h" 27 #include "ui/compositor/layer_animator.h"
27 #include "ui/compositor/scoped_layer_animation_settings.h" 28 #include "ui/compositor/scoped_layer_animation_settings.h"
28 #include "ui/gfx/interpolated_transform.h" 29 #include "ui/gfx/interpolated_transform.h"
30 #include "ui/gfx/rect_conversions.h"
29 #include "ui/gfx/screen.h" 31 #include "ui/gfx/screen.h"
30 #include "ui/gfx/vector3d_f.h" 32 #include "ui/gfx/vector3d_f.h"
31 #include "ui/views/corewm/corewm_switches.h" 33 #include "ui/views/corewm/corewm_switches.h"
32 #include "ui/views/corewm/window_util.h" 34 #include "ui/views/corewm/window_util.h"
33 #include "ui/views/view.h" 35 #include "ui/views/view.h"
34 #include "ui/views/widget/widget.h" 36 #include "ui/views/widget/widget.h"
35 37
36 DECLARE_WINDOW_PROPERTY_TYPE(int) 38 DECLARE_WINDOW_PROPERTY_TYPE(int)
37 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationType) 39 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationType)
38 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationTransition) 40 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationTransition)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 window_->AddObserver(this); 125 window_->AddObserver(this);
124 } 126 }
125 virtual ~HidingWindowAnimationObserver() { 127 virtual ~HidingWindowAnimationObserver() {
126 STLDeleteElements(&layers_); 128 STLDeleteElements(&layers_);
127 } 129 }
128 130
129 private: 131 private:
130 // Overridden from ui::ImplicitAnimationObserver: 132 // Overridden from ui::ImplicitAnimationObserver:
131 virtual void OnImplicitAnimationsCompleted() OVERRIDE { 133 virtual void OnImplicitAnimationsCompleted() OVERRIDE {
132 // Window may have been destroyed by this point. 134 // Window may have been destroyed by this point.
133 if (window_) 135 if (window_) {
136 if (window_->delegate())
137 window_->delegate()->OnWindowHidingAnimationCompleted();
134 window_->RemoveObserver(this); 138 window_->RemoveObserver(this);
139 }
135 delete this; 140 delete this;
136 } 141 }
137 142
138 // Overridden from aura::WindowObserver: 143 // Overridden from aura::WindowObserver:
139 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { 144 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
140 DCHECK_EQ(window, window_); 145 DCHECK_EQ(window, window_);
141 DCHECK(layers_.empty()); 146 DCHECK(layers_.empty());
142 AcquireAllLayers(window_); 147 AcquireAllLayers(window_);
143 148
144 // If the Widget has views with layers, then it is necessary to take 149 // If the Widget has views with layers, then it is necessary to take
(...skipping 27 matching lines...) Expand all
172 } 177 }
173 } 178 }
174 } 179 }
175 180
176 aura::Window* window_; 181 aura::Window* window_;
177 std::vector<ui::Layer*> layers_; 182 std::vector<ui::Layer*> layers_;
178 183
179 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); 184 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver);
180 }; 185 };
181 186
187 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) {
188 const Layer* root = layer;
189 while (root->parent())
190 root = root->parent();
191 layer->GetTargetTransformRelativeTo(root, transform);
192 }
193
194 gfx::Rect GetLayerWorldBoundsAfterTransform(ui::Layer* layer,
195 const gfx::Transform& transform) {
196 gfx::Transform in_world = transform;
197 GetTransformRelativeToRoot(layer, &in_world);
198
199 gfx::RectF transformed = layer->bounds();
200 in_world.TransformRect(&transformed);
201
202 return gfx::ToEnclosingRect(transformed);
203 }
204
205 // Augment the host window so that the enclosing bounds of the full
206 // animation will fit inside of it.
207 void AugmentWindowSize(aura::Window* window,
208 const gfx::Transform& start_transform,
209 const gfx::Transform& end_transform) {
210 gfx::Rect world_at_start =
211 GetLayerWorldBoundsAfterTransform(window->layer(), start_transform);
212 gfx::Rect world_at_end =
213 GetLayerWorldBoundsAfterTransform(window->layer(), end_transform);
214 gfx::Rect union_in_window_space =
215 gfx::UnionRects(world_at_start, world_at_end);
216 gfx::Rect current_bounds = window->bounds();
217 gfx::Rect result(union_in_window_space.x() - current_bounds.x(),
218 union_in_window_space.y() - current_bounds.y(),
219 union_in_window_space.width() - current_bounds.width(),
220 union_in_window_space.height() - current_bounds.height());
221 if (window->delegate())
222 window->delegate()->SetHostTransitionBounds(result);
223 }
224
182 // Shows a window using an animation, animating its opacity from 0.f to 1.f, 225 // Shows a window using an animation, animating its opacity from 0.f to 1.f,
183 // its visibility to true, and its transform from |start_transform| to 226 // its visibility to true, and its transform from |start_transform| to
184 // |end_transform|. 227 // |end_transform|.
185 void AnimateShowWindowCommon(aura::Window* window, 228 void AnimateShowWindowCommon(aura::Window* window,
186 const gfx::Transform& start_transform, 229 const gfx::Transform& start_transform,
187 const gfx::Transform& end_transform) { 230 const gfx::Transform& end_transform) {
188 window->layer()->set_delegate(window); 231 window->layer()->set_delegate(window);
232
233 AugmentWindowSize(window, start_transform, end_transform);
234
189 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 235 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
190 window->layer()->SetTransform(start_transform); 236 window->layer()->SetTransform(start_transform);
191 window->layer()->SetVisible(true); 237 window->layer()->SetVisible(true);
192 238
193 { 239 {
194 // Property sets within this scope will be implicitly animated. 240 // Property sets within this scope will be implicitly animated.
195 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 241 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
196 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); 242 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window);
197 if (duration.ToInternalValue() > 0) 243 if (duration.ToInternalValue() > 0)
198 settings.SetTransitionDuration(duration); 244 settings.SetTransitionDuration(duration);
199 245
200 window->layer()->SetTransform(end_transform); 246 window->layer()->SetTransform(end_transform);
201 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); 247 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
202 } 248 }
203 } 249 }
204 250
205 // Hides a window using an animation, animating its opacity from 1.f to 0.f, 251 // Hides a window using an animation, animating its opacity from 1.f to 0.f,
206 // its visibility to false, and its transform to |end_transform|. 252 // its visibility to false, and its transform to |end_transform|.
207 void AnimateHideWindowCommon(aura::Window* window, 253 void AnimateHideWindowCommon(aura::Window* window,
208 const gfx::Transform& end_transform) { 254 const gfx::Transform& end_transform) {
255 AugmentWindowSize(window, gfx::Transform(), end_transform);
209 window->layer()->set_delegate(NULL); 256 window->layer()->set_delegate(NULL);
210 257
211 // Property sets within this scope will be implicitly animated. 258 // Property sets within this scope will be implicitly animated.
212 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 259 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
213 settings.AddObserver(new HidingWindowAnimationObserver(window)); 260 settings.AddObserver(new HidingWindowAnimationObserver(window));
214 261
215 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); 262 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window);
216 if (duration.ToInternalValue() > 0) 263 if (duration.ToInternalValue() > 0)
217 settings.SetTransitionDuration(duration); 264 settings.SetTransitionDuration(duration);
218 265
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 532
486 bool WindowAnimationsDisabled(aura::Window* window) { 533 bool WindowAnimationsDisabled(aura::Window* window) {
487 return (window && 534 return (window &&
488 window->GetProperty(aura::client::kAnimationsDisabledKey)) || 535 window->GetProperty(aura::client::kAnimationsDisabledKey)) ||
489 CommandLine::ForCurrentProcess()->HasSwitch( 536 CommandLine::ForCurrentProcess()->HasSwitch(
490 switches::kWindowAnimationsDisabled); 537 switches::kWindowAnimationsDisabled);
491 } 538 }
492 539
493 } // namespace corewm 540 } // namespace corewm
494 } // namespace views 541 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698