Skip to content

Commit

Permalink
Revert https://codereview.chromium.org/105673008/ because the CL was …
Browse files Browse the repository at this point in the history
…causing a crash (http://crbug.com/335068)

BUG=335068
TEST=Crash stops occuring
TBR=pkotwicz

Review URL: https://codereview.chromium.org/130413004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245913 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
pkotwicz@chromium.org committed Jan 20, 2014
1 parent 6d4b66c commit 0d31625
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 129 deletions.
2 changes: 1 addition & 1 deletion ash/system/tray/tray_background_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void TrayBackgroundView::InitializeBubbleAnimations(
views::corewm::SetWindowVisibilityAnimationTransition(
bubble_widget->GetNativeWindow(),
views::corewm::ANIMATE_HIDE);
views::corewm::SetWindowHideAnimationDuration(
views::corewm::SetWindowVisibilityAnimationDuration(
bubble_widget->GetNativeWindow(),
base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS));
}
Expand Down
42 changes: 22 additions & 20 deletions ash/wm/dock/docked_window_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,6 @@ void DockedWindowLayoutManager::FinishDragging(DockedAction action,
wm::GetWindowState(dragged_window_)->RemoveObserver(this);
if (last_active_window_ == dragged_window_)
last_active_window_ = NULL;

views::corewm::SetWindowShowAnimationDuration(dragged_window_,
base::TimeDelta());
} else {
// If this is the first window that got docked by a move update alignment.
if (alignment_ == DOCKED_ALIGNMENT_NONE)
Expand All @@ -534,9 +531,6 @@ void DockedWindowLayoutManager::FinishDragging(DockedAction action,
// the only opportunity we will have to enforce a window
// count limit so do it here.
MaybeMinimizeChildrenExcept(dragged_window_);

views::corewm::SetWindowShowAnimationDuration(dragged_window_,
base::TimeDelta::FromMilliseconds(kFadeDurationMs));
}
dragged_window_ = NULL;
dragged_bounds_ = gfx::Rect();
Expand Down Expand Up @@ -673,8 +667,6 @@ void DockedWindowLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
wm::GetWindowState(child)->AddObserver(this);
Relayout();
UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED);
views::corewm::SetWindowShowAnimationDuration(child,
base::TimeDelta::FromMilliseconds(kFadeDurationMs));
}

void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
Expand All @@ -696,7 +688,6 @@ void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) {
wm::GetWindowState(child)->RemoveObserver(this);
Relayout();
UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED);
views::corewm::SetWindowShowAnimationDuration(child, base::TimeDelta());
}

void DockedWindowLayoutManager::OnChildWindowVisibilityChanged(
Expand Down Expand Up @@ -835,6 +826,21 @@ void DockedWindowLayoutManager::OnWindowBoundsChanged(
Relayout();
}

void DockedWindowLayoutManager::OnWindowVisibilityChanging(
aura::Window* window, bool visible) {
if (IsPopupOrTransient(window))
return;
int animation_type = views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT;
if (visible) {
animation_type = views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DROP;
views::corewm::SetWindowVisibilityAnimationDuration(
window, base::TimeDelta::FromMilliseconds(kFadeDurationMs));
} else if (wm::GetWindowState(window)->IsMinimized()) {
animation_type = WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE;
}
views::corewm::SetWindowVisibilityAnimationType(window, animation_type);
}

void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) {
if (dragged_window_ == window) {
FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN);
Expand Down Expand Up @@ -893,25 +899,21 @@ void DockedWindowLayoutManager::MaybeMinimizeChildrenExcept(
if (available_room > room_needed) {
available_room -= room_needed;
} else {
// Slow down the minimize animation.
views::corewm::SetWindowHideAnimationDuration(
window,
// Slow down minimizing animations. Lock duration so that it is not
// overridden by other ScopedLayerAnimationSettings down the stack.
ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kMinimizeDurationMs));
settings.LockTransitionDuration();
wm::GetWindowState(window)->Minimize();
views::corewm::SetWindowHideAnimationDuration(window, base::TimeDelta());
}
}
}

void DockedWindowLayoutManager::MinimizeDockedWindow(
wm::WindowState* window_state) {
aura::Window* window = window_state->window();
DCHECK(!IsPopupOrTransient(window));
views::corewm::SetWindowVisibilityAnimationType(window,
ash::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
window->Hide();
views::corewm::SetWindowVisibilityAnimationType(window,
views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT);
DCHECK(!IsPopupOrTransient(window_state->window()));
window_state->window()->Hide();
if (window_state->IsActive())
window_state->Deactivate();
RecordUmaAction(DOCKED_ACTION_MINIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN);
Expand Down
2 changes: 2 additions & 0 deletions ash/wm/dock/docked_window_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ class ASH_EXPORT DockedWindowLayoutManager
virtual void OnWindowBoundsChanged(aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) OVERRIDE;
virtual void OnWindowVisibilityChanging(aura::Window* window,
bool visible) OVERRIDE;
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;

// aura::client::ActivationChangeObserver:
Expand Down
26 changes: 11 additions & 15 deletions ash/wm/window_animations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ int64 Round64(float f) {

const int kCrossFadeDurationMS = 200;

void AddLayerAnimationsForMinimize(aura::Window* window,
const base::TimeDelta& duration,
bool show) {
void AddLayerAnimationsForMinimize(aura::Window* window, bool show) {
// Recalculate the transform at restore time since the launcher item may have
// moved while the window was minimized.
gfx::Rect bounds = window->bounds();
Expand Down Expand Up @@ -107,6 +105,9 @@ void AddLayerAnimationsForMinimize(aura::Window* window,

rotation_about_pivot->SetReversed(show);

base::TimeDelta duration = window->layer()->GetAnimator()->
GetTransitionDuration();

scoped_ptr<ui::LayerAnimationElement> transition(
ui::LayerAnimationElement::CreateInterpolatedTransformElement(
rotation_about_pivot.release(), duration));
Expand Down Expand Up @@ -136,11 +137,10 @@ void AnimateShowWindow_Minimize(aura::Window* window) {
window->layer()->set_delegate(window);
window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
base::TimeDelta duration = views::corewm::GetWindowShowAnimationDuration(
window,
base::TimeDelta::FromMilliseconds(kLayerAnimationsForMinimizeDurationMS));
base::TimeDelta duration = base::TimeDelta::FromMilliseconds(
kLayerAnimationsForMinimizeDurationMS);
settings.SetTransitionDuration(duration);
AddLayerAnimationsForMinimize(window, duration, true);
AddLayerAnimationsForMinimize(window, true);

// Now that the window has been restored, we need to clear its animation style
// to default so that normal animation applies.
Expand All @@ -153,15 +153,14 @@ void AnimateHideWindow_Minimize(aura::Window* window) {

// Property sets within this scope will be implicitly animated.
ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
base::TimeDelta duration = views::corewm::GetWindowHideAnimationDuration(
window,
base::TimeDelta::FromMilliseconds(kLayerAnimationsForMinimizeDurationMS));
base::TimeDelta duration = base::TimeDelta::FromMilliseconds(
kLayerAnimationsForMinimizeDurationMS);
settings.SetTransitionDuration(duration);
settings.AddObserver(
views::corewm::CreateHidingWindowAnimationObserver(window));
window->layer()->SetVisible(false);

AddLayerAnimationsForMinimize(window, duration, false);
AddLayerAnimationsForMinimize(window, false);
}

void AnimateShowHideWindowCommon_BrightnessGrayscale(aura::Window* window,
Expand All @@ -184,11 +183,8 @@ void AnimateShowHideWindowCommon_BrightnessGrayscale(aura::Window* window,
window->layer()->SetVisible(true);
}

base::TimeDelta default_duration =
base::TimeDelta duration =
base::TimeDelta::FromMilliseconds(kBrightnessGrayscaleFadeDurationMs);
base::TimeDelta duration = show ?
views::corewm::GetWindowShowAnimationDuration(window, default_duration) :
views::corewm::GetWindowHideAnimationDuration(window, default_duration);

ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
settings.SetTransitionDuration(duration);
Expand Down
103 changes: 103 additions & 0 deletions ash/wm/window_animations_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@ class WindowAnimationsTest : public ash::test::AshTestBase {
DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest);
};

// Listens to animation scheduled notifications. Remembers the transition
// duration of the first sequence.
class MinimizeAnimationObserver : public ui::LayerAnimationObserver {
public:
explicit MinimizeAnimationObserver(ui::LayerAnimator* animator)
: animator_(animator) {
animator_->AddObserver(this);
// RemoveObserver is called when the first animation is scheduled and so
// there should be no need for now to remove it in destructor.
};
base::TimeDelta duration() { return duration_; }

protected:
// ui::LayerAnimationObserver:
virtual void OnLayerAnimationScheduled(
ui::LayerAnimationSequence* sequence) OVERRIDE {
duration_ = animator_->GetTransitionDuration();
animator_->RemoveObserver(this);
}
virtual void OnLayerAnimationEnded(
ui::LayerAnimationSequence* sequence) OVERRIDE {}
virtual void OnLayerAnimationAborted(
ui::LayerAnimationSequence* sequence) OVERRIDE {}

private:
ui::LayerAnimator* animator_;
base::TimeDelta duration_;

DISALLOW_COPY_AND_ASSIGN(MinimizeAnimationObserver);
};

TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) {
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
window->Show();
Expand Down Expand Up @@ -136,5 +167,77 @@ TEST_F(WindowAnimationsTest, CrossFadeToBounds) {
Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
}

TEST_F(WindowAnimationsTest, LockAnimationDuration) {
ui::ScopedAnimationDurationScaleMode normal_duration_mode(
ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);

scoped_ptr<Window> window(CreateTestWindowInShellWithId(0));
Layer* layer = window->layer();
window->SetBounds(gfx::Rect(5, 10, 320, 240));
window->Show();

// Test that it is possible to override transition duration when it is not
// locked.
{
ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator());
settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000));
{
ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator());
// Duration is not locked so it gets overridden.
settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50));
wm::GetWindowState(window.get())->Minimize();
EXPECT_TRUE(layer->GetAnimator()->is_animating());
// Expect duration from the inner scope
EXPECT_EQ(50,
layer->GetAnimator()->GetTransitionDuration().InMilliseconds());
}
window->Show();
layer->GetAnimator()->StopAnimating();
}

// Test that it is possible to lock transition duration
{
ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator());
settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000));
// Duration is locked in outer scope.
settings1.LockTransitionDuration();
{
ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator());
// Transition duration setting is ignored.
settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50));
wm::GetWindowState(window.get())->Minimize();
EXPECT_TRUE(layer->GetAnimator()->is_animating());
// Expect duration from the outer scope
EXPECT_EQ(1000,
layer->GetAnimator()->GetTransitionDuration().InMilliseconds());
}
window->Show();
layer->GetAnimator()->StopAnimating();
}

// Test that duration respects default.
{
// Query default duration.
MinimizeAnimationObserver observer(layer->GetAnimator());
wm::GetWindowState(window.get())->Minimize();
EXPECT_TRUE(layer->GetAnimator()->is_animating());
base::TimeDelta default_duration(observer.duration());
window->Show();
layer->GetAnimator()->StopAnimating();

ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
settings.LockTransitionDuration();
// Setting transition duration is ignored since duration is locked
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000));
wm::GetWindowState(window.get())->Minimize();
EXPECT_TRUE(layer->GetAnimator()->is_animating());
// Expect default duration (200ms for stock ash minimizing animation).
EXPECT_EQ(default_duration.InMilliseconds(),
layer->GetAnimator()->GetTransitionDuration().InMilliseconds());
window->Show();
layer->GetAnimator()->StopAnimating();
}
}

} // namespace internal
} // namespace ash
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/login/login_display_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ void LoginDisplayHostImpl::InitLoginWindowAndView() {
if (login_view_->webui_visible())
OnLoginPromptVisible();

views::corewm::SetWindowHideAnimationDuration(
views::corewm::SetWindowVisibilityAnimationDuration(
login_window_->GetNativeView(),
base::TimeDelta::FromMilliseconds(kLoginFadeoutTransitionDurationMs));
views::corewm::SetWindowVisibilityAnimationTransition(
Expand Down
11 changes: 9 additions & 2 deletions ui/compositor/layer_animator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ gfx::AnimationContainer* GetAnimationContainer() {
LayerAnimator::LayerAnimator(base::TimeDelta transition_duration)
: delegate_(NULL),
preemption_strategy_(IMMEDIATELY_SET_NEW_TARGET),
is_transition_duration_locked_(false),
transition_duration_(transition_duration),
tween_type_(gfx::Tween::LINEAR),
is_started_(false),
Expand Down Expand Up @@ -118,6 +119,10 @@ ANIMATED_PROPERTY(float, BRIGHTNESS, Brightness, float, brightness);
ANIMATED_PROPERTY(float, GRAYSCALE, Grayscale, float, grayscale);
ANIMATED_PROPERTY(SkColor, COLOR, Color, SkColor, color);

base::TimeDelta LayerAnimator::GetTransitionDuration() const {
return transition_duration_;
}

void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) {
delegate_ = delegate;
}
Expand Down Expand Up @@ -798,8 +803,10 @@ void LayerAnimator::OnScheduled(LayerAnimationSequence* sequence) {
sequence->OnScheduled();
}

base::TimeDelta LayerAnimator::GetTransitionDuration() const {
return transition_duration_;
void LayerAnimator::SetTransitionDuration(base::TimeDelta duration) {
if (is_transition_duration_locked_)
return;
transition_duration_ = duration;
}

void LayerAnimator::ClearAnimationsInternal() {
Expand Down
14 changes: 9 additions & 5 deletions ui/compositor/layer_animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class COMPOSITOR_EXPORT LayerAnimator
virtual void SetColor(SkColor color);
SkColor GetTargetColor() const;

// Returns the default length of animations, including adjustment for slow
// animation mode if set.
base::TimeDelta GetTransitionDuration() const;

// Sets the layer animation delegate the animator is associated with. The
// animator does not own the delegate. The layer animator expects a non-NULL
// delegate for most of its operations, so do not call any methods without
Expand Down Expand Up @@ -293,11 +297,7 @@ class COMPOSITOR_EXPORT LayerAnimator
// starting the animation or adding to the queue.
void OnScheduled(LayerAnimationSequence* sequence);

// Returns the default length of animations, including adjustment for slow
// animation mode if set.
base::TimeDelta GetTransitionDuration() const;

// Sets |transition_duration_|.
// Sets |transition_duration_| unless |is_transition_duration_locked_| is set.
void SetTransitionDuration(base::TimeDelta duration);

// Clears the animation queues and notifies any running animations that they
Expand All @@ -319,6 +319,10 @@ class COMPOSITOR_EXPORT LayerAnimator
// Determines how animations are replaced.
PreemptionStrategy preemption_strategy_;

// Whether the length of animations is locked. While it is locked
// SetTransitionDuration does not set |transition_duration_|.
bool is_transition_duration_locked_;

// The default length of animations.
base::TimeDelta transition_duration_;

Expand Down
Loading

0 comments on commit 0d31625

Please sign in to comment.