Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/workspace/phantom_window_controller.h" | 5 #include "ash/wm/workspace/phantom_window_controller.h" |
| 6 | 6 |
| 7 #include <math.h> | |
| 8 | |
| 7 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 8 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 10 #include "ash/wm/coordinate_conversion.h" | 12 #include "ash/wm/coordinate_conversion.h" |
| 11 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 14 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 14 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 15 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
| 16 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 17 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 19 #include "ui/views/background.h" | 21 #include "ui/views/background.h" |
| 20 #include "ui/views/painter.h" | 22 #include "ui/views/painter.h" |
| 21 #include "ui/views/view.h" | 23 #include "ui/views/view.h" |
| 22 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 23 | 25 |
| 24 namespace ash { | 26 namespace ash { |
| 25 namespace internal { | 27 namespace internal { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 // The duration of the show animation. | 31 // The duration of the show animation. |
| 30 const int kAnimationDurationMs = 200; | 32 const int kAnimationDurationMs = 200; |
| 31 | 33 |
| 32 // The size of the phantom window at the beginning of the show animation in | 34 // The size of the phantom window at the beginning of the show animation in |
| 33 // relation to the size of the phantom window at the end of the animation when | 35 // relation to the size of the phantom window at the end of the animation when |
| 34 // using the alternate caption button style. | 36 // using the alternate caption button style. |
| 35 const float kAlternateCaptionButtonStyleAnimationInitialBoundsRatio = 0.85f; | 37 const float kAlternateStyleStartBoundsRatio = 0.85f; |
| 36 | 38 |
| 37 // The amount of pixels that the phantom window's shadow should extend past | 39 // The amount of pixels that the phantom window's shadow should extend past |
| 38 // the bounds passed into Show(). There is no shadow when not using the | 40 // the bounds passed into Show(). There is no shadow when not using the |
| 39 // alternate caption button style. | 41 // alternate caption button style. |
| 40 const int kShadowThickness = 60; | 42 const int kAlternateStyleShadowThickness = 15; |
| 43 | |
| 44 // The minimum size of a phantom window including the shadow when using the | |
| 45 // alternate caption button style. The minimum size is derived from the size of | |
| 46 // the IDR_AURA_PHANTOM_WINDOW image assets. | |
| 47 const int kAlternateStyleMinSizeWithShadow = 100; | |
| 41 | 48 |
| 42 // Converts the bounds of a phantom window without a shadow to those of a | 49 // Converts the bounds of a phantom window without a shadow to those of a |
| 43 // phantom window with a shadow. | 50 // phantom window with a shadow. |
| 44 gfx::Rect GetBoundsWithShadow(const gfx::Rect& bounds) { | 51 gfx::Rect GetAdjustedBounds(const gfx::Rect& bounds) { |
| 45 gfx::Rect bounds_with_shadow(bounds); | 52 gfx::Rect adjusted_bounds(bounds); |
| 46 // Phantom windows have a shadow solely when using the alternate caption | 53 if (switches::UseAlternateFrameCaptionButtonStyle()) { |
| 47 // button style. | 54 int x_inset = bounds.width() < kAlternateStyleMinSizeWithShadow ? |
| 48 if (switches::UseAlternateFrameCaptionButtonStyle()) | 55 ceil((kAlternateStyleMinSizeWithShadow - bounds.width()) / 2.0f) : |
| 49 bounds_with_shadow.Inset(-kShadowThickness, -kShadowThickness); | 56 kAlternateStyleShadowThickness; |
| 50 return bounds_with_shadow; | 57 int y_inset = bounds.height() < kAlternateStyleMinSizeWithShadow ? |
| 58 ceil((kAlternateStyleMinSizeWithShadow - bounds.height()) / 2.0f) : | |
| 59 kAlternateStyleShadowThickness; | |
| 60 adjusted_bounds.Inset(-x_inset, -y_inset); | |
| 61 } | |
| 62 return adjusted_bounds; | |
| 51 } | 63 } |
| 52 | 64 |
| 53 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget| | 65 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget| |
| 54 // is NULL. | 66 // is NULL. |
| 55 void AnimateToBounds(views::Widget* widget, | 67 void AnimateToBounds(views::Widget* widget, |
| 56 const gfx::Rect& new_bounds_in_screen) { | 68 const gfx::Rect& new_bounds_in_screen) { |
| 57 if (!widget) | 69 if (!widget) |
| 58 return; | 70 return; |
| 59 | 71 |
| 60 ui::ScopedLayerAnimationSettings scoped_setter( | 72 ui::ScopedLayerAnimationSettings scoped_setter( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 // PhantomWindowController ---------------------------------------------------- | 142 // PhantomWindowController ---------------------------------------------------- |
| 131 | 143 |
| 132 PhantomWindowController::PhantomWindowController(aura::Window* window) | 144 PhantomWindowController::PhantomWindowController(aura::Window* window) |
| 133 : window_(window), | 145 : window_(window), |
| 134 phantom_below_window_(NULL) { | 146 phantom_below_window_(NULL) { |
| 135 } | 147 } |
| 136 | 148 |
| 137 PhantomWindowController::~PhantomWindowController() { | 149 PhantomWindowController::~PhantomWindowController() { |
| 138 } | 150 } |
| 139 | 151 |
| 140 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { | 152 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { |
|
Mr4D (OOO till 08-26)
2014/01/28 17:45:25
Couldn't you get the GetAdjustedBounds only once h
| |
| 141 if (GetBoundsWithShadow(bounds_in_screen) == target_bounds_in_screen_) | 153 if (GetAdjustedBounds(bounds_in_screen) == target_bounds_in_screen_) |
| 142 return; | 154 return; |
| 143 target_bounds_in_screen_ = GetBoundsWithShadow(bounds_in_screen); | 155 target_bounds_in_screen_ = GetAdjustedBounds(bounds_in_screen); |
| 144 | 156 |
| 145 if (switches::UseAlternateFrameCaptionButtonStyle()) { | 157 if (switches::UseAlternateFrameCaptionButtonStyle()) { |
| 146 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; | 158 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; |
| 147 float inset_ratio = | 159 int start_width = std::max( |
| 148 (1.0f - kAlternateCaptionButtonStyleAnimationInitialBoundsRatio) / 2; | 160 kAlternateStyleMinSizeWithShadow, |
| 161 static_cast<int>( | |
| 162 start_bounds_in_screen.width() * kAlternateStyleStartBoundsRatio)); | |
| 163 int start_height = std::max( | |
| 164 kAlternateStyleMinSizeWithShadow, | |
| 165 static_cast<int>( | |
| 166 start_bounds_in_screen.height() * kAlternateStyleStartBoundsRatio)); | |
| 149 start_bounds_in_screen.Inset( | 167 start_bounds_in_screen.Inset( |
| 150 static_cast<int>(start_bounds_in_screen.width() * inset_ratio), | 168 (start_bounds_in_screen.width() - start_width) / 2, |
| 151 static_cast<int>(start_bounds_in_screen.height() * inset_ratio)); | 169 (start_bounds_in_screen.height() - start_height) / 2); |
| 152 phantom_widget_in_target_root_ = CreatePhantomWidget( | 170 phantom_widget_in_target_root_ = CreatePhantomWidget( |
| 153 wm::GetRootWindowMatching(target_bounds_in_screen_), | 171 wm::GetRootWindowMatching(target_bounds_in_screen_), |
| 154 start_bounds_in_screen); | 172 start_bounds_in_screen); |
| 155 | 173 |
| 156 AnimateToBounds(phantom_widget_in_target_root_.get(), | 174 AnimateToBounds(phantom_widget_in_target_root_.get(), |
| 157 target_bounds_in_screen_); | 175 target_bounds_in_screen_); |
| 158 } else { | 176 } else { |
| 159 gfx::Rect start_bounds_in_screen; | 177 gfx::Rect start_bounds_in_screen; |
| 160 if (!phantom_widget_in_target_root_) { | 178 if (!phantom_widget_in_target_root_) { |
| 161 start_bounds_in_screen = | 179 start_bounds_in_screen = GetAdjustedBounds(window_->GetBoundsInScreen()); |
| 162 GetBoundsWithShadow(window_->GetBoundsInScreen()); | |
| 163 } else { | 180 } else { |
| 164 start_bounds_in_screen = | 181 start_bounds_in_screen = |
| 165 phantom_widget_in_target_root_->GetWindowBoundsInScreen(); | 182 phantom_widget_in_target_root_->GetWindowBoundsInScreen(); |
| 166 } | 183 } |
| 167 | 184 |
| 168 aura::Window* target_root = | 185 aura::Window* target_root = |
| 169 wm::GetRootWindowMatching(target_bounds_in_screen_); | 186 wm::GetRootWindowMatching(target_bounds_in_screen_); |
| 170 if (!phantom_widget_in_target_root_ || | 187 if (!phantom_widget_in_target_root_ || |
| 171 phantom_widget_in_target_root_->GetNativeWindow()->GetRootWindow() != | 188 phantom_widget_in_target_root_->GetNativeWindow()->GetRootWindow() != |
| 172 target_root) { | 189 target_root) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); | 270 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); |
| 254 scoped_setter.SetTransitionDuration( | 271 scoped_setter.SetTransitionDuration( |
| 255 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 272 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
| 256 widget_layer->SetOpacity(1); | 273 widget_layer->SetOpacity(1); |
| 257 | 274 |
| 258 return phantom_widget.Pass(); | 275 return phantom_widget.Pass(); |
| 259 } | 276 } |
| 260 | 277 |
| 261 } // namespace internal | 278 } // namespace internal |
| 262 } // namespace ash | 279 } // namespace ash |
| OLD | NEW |