| 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 = 15; | 42 const int kAlternateStyleShadowThickness = 15; |
| 41 | 43 |
| 42 // Converts the bounds of a phantom window without a shadow to those of a | 44 // The minimum size of a phantom window including the shadow when using the |
| 43 // phantom window with a shadow. | 45 // alternate caption button style. The minimum size is derived from the size of |
| 44 gfx::Rect GetBoundsWithShadow(const gfx::Rect& bounds) { | 46 // the IDR_AURA_PHANTOM_WINDOW image assets. |
| 45 gfx::Rect bounds_with_shadow(bounds); | 47 const int kAlternateStyleMinSizeWithShadow = 100; |
| 46 // Phantom windows have a shadow solely when using the alternate caption | 48 |
| 47 // button style. | 49 // Adjusts the phantom window's bounds so that the bounds: |
| 48 if (switches::UseAlternateFrameCaptionButtonStyle()) | 50 // - Include the size of the shadow. |
| 49 bounds_with_shadow.Inset(-kShadowThickness, -kShadowThickness); | 51 // - Have a size equal to or larger than the minimize phantom window size. |
| 50 return bounds_with_shadow; | 52 gfx::Rect GetAdjustedBoundsForAlternateStyle(const gfx::Rect& bounds) { |
| 53 int x_inset = std::max( |
| 54 static_cast<int>( |
| 55 ceil((kAlternateStyleMinSizeWithShadow - bounds.width()) / 2.0f)), |
| 56 kAlternateStyleShadowThickness); |
| 57 int y_inset = std::max( |
| 58 static_cast<int>( |
| 59 ceil((kAlternateStyleMinSizeWithShadow - bounds.height()) / 2.0f)), |
| 60 kAlternateStyleShadowThickness); |
| 61 |
| 62 gfx::Rect adjusted_bounds(bounds); |
| 63 adjusted_bounds.Inset(-x_inset, -y_inset); |
| 64 return adjusted_bounds; |
| 51 } | 65 } |
| 52 | 66 |
| 53 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget| | 67 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget| |
| 54 // is NULL. | 68 // is NULL. |
| 55 void AnimateToBounds(views::Widget* widget, | 69 void AnimateToBounds(views::Widget* widget, |
| 56 const gfx::Rect& new_bounds_in_screen) { | 70 const gfx::Rect& new_bounds_in_screen) { |
| 57 if (!widget) | 71 if (!widget) |
| 58 return; | 72 return; |
| 59 | 73 |
| 60 ui::ScopedLayerAnimationSettings scoped_setter( | 74 ui::ScopedLayerAnimationSettings scoped_setter( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 145 |
| 132 PhantomWindowController::PhantomWindowController(aura::Window* window) | 146 PhantomWindowController::PhantomWindowController(aura::Window* window) |
| 133 : window_(window), | 147 : window_(window), |
| 134 phantom_below_window_(NULL) { | 148 phantom_below_window_(NULL) { |
| 135 } | 149 } |
| 136 | 150 |
| 137 PhantomWindowController::~PhantomWindowController() { | 151 PhantomWindowController::~PhantomWindowController() { |
| 138 } | 152 } |
| 139 | 153 |
| 140 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { | 154 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { |
| 141 if (GetBoundsWithShadow(bounds_in_screen) == target_bounds_in_screen_) | 155 if (switches::UseAlternateFrameCaptionButtonStyle()) |
| 156 ShowAlternate(bounds_in_screen); |
| 157 else |
| 158 ShowLegacy(bounds_in_screen); |
| 159 } |
| 160 |
| 161 void PhantomWindowController::ShowAlternate(const gfx::Rect& bounds_in_screen) { |
| 162 gfx::Rect adjusted_bounds_in_screen = |
| 163 GetAdjustedBoundsForAlternateStyle(bounds_in_screen); |
| 164 if (adjusted_bounds_in_screen == target_bounds_in_screen_) |
| 142 return; | 165 return; |
| 143 target_bounds_in_screen_ = GetBoundsWithShadow(bounds_in_screen); | 166 target_bounds_in_screen_ = adjusted_bounds_in_screen; |
| 144 | 167 |
| 145 if (switches::UseAlternateFrameCaptionButtonStyle()) { | 168 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; |
| 146 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; | 169 int start_width = std::max( |
| 147 float inset_ratio = | 170 kAlternateStyleMinSizeWithShadow, |
| 148 (1.0f - kAlternateCaptionButtonStyleAnimationInitialBoundsRatio) / 2; | 171 static_cast<int>( |
| 149 start_bounds_in_screen.Inset( | 172 start_bounds_in_screen.width() * kAlternateStyleStartBoundsRatio)); |
| 150 static_cast<int>(start_bounds_in_screen.width() * inset_ratio), | 173 int start_height = std::max( |
| 151 static_cast<int>(start_bounds_in_screen.height() * inset_ratio)); | 174 kAlternateStyleMinSizeWithShadow, |
| 152 phantom_widget_in_target_root_ = CreatePhantomWidget( | 175 static_cast<int>( |
| 153 wm::GetRootWindowMatching(target_bounds_in_screen_), | 176 start_bounds_in_screen.height() * kAlternateStyleStartBoundsRatio)); |
| 154 start_bounds_in_screen); | 177 start_bounds_in_screen.Inset( |
| 178 floor((start_bounds_in_screen.width() - start_width) / 2.0f), |
| 179 floor((start_bounds_in_screen.height() - start_height) / 2.0f)); |
| 180 phantom_widget_in_target_root_ = CreatePhantomWidget( |
| 181 wm::GetRootWindowMatching(target_bounds_in_screen_), |
| 182 start_bounds_in_screen); |
| 155 | 183 |
| 156 AnimateToBounds(phantom_widget_in_target_root_.get(), | 184 AnimateToBounds(phantom_widget_in_target_root_.get(), |
| 157 target_bounds_in_screen_); | 185 target_bounds_in_screen_); |
| 186 } |
| 187 |
| 188 void PhantomWindowController::ShowLegacy(const gfx::Rect& bounds_in_screen) { |
| 189 if (bounds_in_screen == target_bounds_in_screen_) |
| 190 return; |
| 191 target_bounds_in_screen_ = bounds_in_screen; |
| 192 |
| 193 gfx::Rect start_bounds_in_screen; |
| 194 if (!phantom_widget_in_target_root_) { |
| 195 start_bounds_in_screen = window_->GetBoundsInScreen(); |
| 158 } else { | 196 } else { |
| 159 gfx::Rect start_bounds_in_screen; | 197 start_bounds_in_screen = |
| 160 if (!phantom_widget_in_target_root_) { | 198 phantom_widget_in_target_root_->GetWindowBoundsInScreen(); |
| 161 start_bounds_in_screen = | 199 } |
| 162 GetBoundsWithShadow(window_->GetBoundsInScreen()); | |
| 163 } else { | |
| 164 start_bounds_in_screen = | |
| 165 phantom_widget_in_target_root_->GetWindowBoundsInScreen(); | |
| 166 } | |
| 167 | 200 |
| 168 aura::Window* target_root = | 201 aura::Window* target_root = |
| 169 wm::GetRootWindowMatching(target_bounds_in_screen_); | 202 wm::GetRootWindowMatching(target_bounds_in_screen_); |
| 170 if (!phantom_widget_in_target_root_ || | 203 if (!phantom_widget_in_target_root_ || |
| 171 phantom_widget_in_target_root_->GetNativeWindow()->GetRootWindow() != | 204 phantom_widget_in_target_root_->GetNativeWindow()->GetRootWindow() != |
| 172 target_root) { | 205 target_root) { |
| 173 phantom_widget_in_target_root_ = | 206 phantom_widget_in_target_root_ = |
| 174 CreatePhantomWidget(target_root, start_bounds_in_screen); | 207 CreatePhantomWidget(target_root, start_bounds_in_screen); |
| 175 } | 208 } |
| 176 AnimateToBounds(phantom_widget_in_target_root_.get(), | 209 AnimateToBounds(phantom_widget_in_target_root_.get(), |
| 177 target_bounds_in_screen_); | 210 target_bounds_in_screen_); |
| 178 | 211 |
| 179 // Create a secondary widget in a second screen if |start_bounds_in_screen| | 212 // Create a secondary widget in a second screen if |start_bounds_in_screen| |
| 180 // lies at least partially in another screen. This allows animations to | 213 // lies at least partially in another screen. This allows animations to start |
| 181 // start or restart in one root window and progress to another root. | 214 // or restart in one root window and progress to another root. |
| 182 aura::Window* start_root = | 215 aura::Window* start_root = wm::GetRootWindowMatching(start_bounds_in_screen); |
| 183 wm::GetRootWindowMatching(start_bounds_in_screen); | 216 if (start_root == target_root) { |
| 184 if (start_root == target_root) { | 217 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 185 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 218 for (size_t i = 0; i < root_windows.size(); ++i) { |
| 186 for (size_t i = 0; i < root_windows.size(); ++i) { | 219 if (root_windows[i] != target_root && |
| 187 if (root_windows[i] != target_root && | 220 root_windows[i]->GetBoundsInScreen().Intersects( |
| 188 root_windows[i]->GetBoundsInScreen().Intersects( | 221 start_bounds_in_screen)) { |
| 189 start_bounds_in_screen)) { | 222 start_root = root_windows[i]; |
| 190 start_root = root_windows[i]; | 223 break; |
| 191 break; | |
| 192 } | |
| 193 } | 224 } |
| 194 } | 225 } |
| 195 if (start_root == target_root) { | 226 } |
| 196 phantom_widget_in_start_root_.reset(); | 227 if (start_root == target_root) { |
| 197 } else { | 228 phantom_widget_in_start_root_.reset(); |
| 198 if (!phantom_widget_in_start_root_ || | 229 } else { |
| 199 phantom_widget_in_start_root_->GetNativeWindow()->GetRootWindow() != | 230 if (!phantom_widget_in_start_root_ || |
| 200 start_root) { | 231 phantom_widget_in_start_root_->GetNativeWindow()->GetRootWindow() != |
| 201 phantom_widget_in_start_root_ = | 232 start_root) { |
| 202 CreatePhantomWidget(start_root, start_bounds_in_screen); | 233 phantom_widget_in_start_root_ = |
| 203 } | 234 CreatePhantomWidget(start_root, start_bounds_in_screen); |
| 204 AnimateToBounds(phantom_widget_in_start_root_.get(), | |
| 205 target_bounds_in_screen_); | |
| 206 } | 235 } |
| 236 AnimateToBounds(phantom_widget_in_start_root_.get(), |
| 237 target_bounds_in_screen_); |
| 207 } | 238 } |
| 208 } | 239 } |
| 209 | 240 |
| 210 scoped_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( | 241 scoped_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( |
| 211 aura::Window* root_window, | 242 aura::Window* root_window, |
| 212 const gfx::Rect& bounds_in_screen) { | 243 const gfx::Rect& bounds_in_screen) { |
| 213 scoped_ptr<views::Widget> phantom_widget(new views::Widget); | 244 scoped_ptr<views::Widget> phantom_widget(new views::Widget); |
| 214 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 245 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 215 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 246 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 216 // PhantomWindowController is used by FrameMaximizeButton to highlight the | 247 // PhantomWindowController is used by FrameMaximizeButton to highlight the |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); | 284 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); |
| 254 scoped_setter.SetTransitionDuration( | 285 scoped_setter.SetTransitionDuration( |
| 255 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 286 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
| 256 widget_layer->SetOpacity(1); | 287 widget_layer->SetOpacity(1); |
| 257 | 288 |
| 258 return phantom_widget.Pass(); | 289 return phantom_widget.Pass(); |
| 259 } | 290 } |
| 260 | 291 |
| 261 } // namespace internal | 292 } // namespace internal |
| 262 } // namespace ash | 293 } // namespace ash |
| OLD | NEW |