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/common/workspace/phantom_window_controller.h" | 5 #include "ash/wm/common/workspace/phantom_window_controller.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "ash/wm/common/root_window_finder.h" | 9 #include "ash/wm/common/root_window_finder.h" |
10 #include "ash/wm/common/wm_lookup.h" | 10 #include "ash/wm/common/wm_lookup.h" |
11 #include "ash/wm/common/wm_root_window_controller.h" | 11 #include "ash/wm/common/wm_root_window_controller.h" |
12 #include "ash/wm/common/wm_shell_window_ids.h" | 12 #include "ash/wm/common/wm_shell_window_ids.h" |
13 #include "ash/wm/common/wm_window.h" | 13 #include "ash/wm/common/wm_window.h" |
14 #include "grit/ash_wm_common_resources.h" | 14 #include "grit/ash_resources.h" |
15 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
16 #include "ui/compositor/scoped_layer_animation_settings.h" | 16 #include "ui/compositor/scoped_layer_animation_settings.h" |
17 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
18 #include "ui/views/painter.h" | 18 #include "ui/views/painter.h" |
19 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
21 | 21 |
22 namespace ash { | 22 namespace ash { |
23 namespace { | 23 namespace { |
24 | 24 |
25 // The duration of the show animation. | 25 // The duration of the show animation. |
26 const int kAnimationDurationMs = 200; | 26 const int kAnimationDurationMs = 200; |
27 | 27 |
28 // The size of the phantom window at the beginning of the show animation in | 28 // The size of the phantom window at the beginning of the show animation in |
29 // relation to the size of the phantom window at the end of the animation. | 29 // relation to the size of the phantom window at the end of the animation. |
30 const float kStartBoundsRatio = 0.85f; | 30 const float kStartBoundsRatio = 0.85f; |
31 | 31 |
32 // The amount of pixels that the phantom window's shadow should extend past | 32 // The amount of pixels that the phantom window's shadow should extend past |
33 // the bounds passed into Show(). | 33 // the bounds passed into Show(). |
34 const int kShadowThickness = 15; | 34 const int kShadowThickness = 15; |
35 | 35 |
36 // The minimum size of a phantom window including the shadow. The minimum size | 36 // The minimum size of a phantom window including the shadow. The minimum size |
37 // is derived from the size of the IDR_ASH_WM_COMMON_PHANTOM_WINDOW image | 37 // is derived from the size of the IDR_AURA_PHANTOM_WINDOW image assets. |
38 // assets. | |
39 const int kMinSizeWithShadow = 100; | 38 const int kMinSizeWithShadow = 100; |
40 | 39 |
41 // Adjusts the phantom window's bounds so that the bounds: | 40 // Adjusts the phantom window's bounds so that the bounds: |
42 // - Include the size of the shadow. | 41 // - Include the size of the shadow. |
43 // - Have a size equal to or larger than the minimum phantom window size. | 42 // - Have a size equal to or larger than the minimum phantom window size. |
44 gfx::Rect GetAdjustedBounds(const gfx::Rect& bounds) { | 43 gfx::Rect GetAdjustedBounds(const gfx::Rect& bounds) { |
45 int x_inset = std::max( | 44 int x_inset = std::max( |
46 static_cast<int>(ceil((kMinSizeWithShadow - bounds.width()) / 2.0f)), | 45 static_cast<int>(ceil((kMinSizeWithShadow - bounds.width()) / 2.0f)), |
47 kShadowThickness); | 46 kShadowThickness); |
48 int y_inset = std::max( | 47 int y_inset = std::max( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 wm::WmWindow* phantom_widget_window = | 125 wm::WmWindow* phantom_widget_window = |
127 wm::WmLookup::Get()->GetWindowForWidget(phantom_widget.get()); | 126 wm::WmLookup::Get()->GetWindowForWidget(phantom_widget.get()); |
128 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow); | 127 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow); |
129 phantom_widget->SetBounds(bounds_in_screen); | 128 phantom_widget->SetBounds(bounds_in_screen); |
130 // TODO(sky): I suspect this is never true, verify that. | 129 // TODO(sky): I suspect this is never true, verify that. |
131 if (phantom_widget_window->GetParent() == window_->GetParent()) { | 130 if (phantom_widget_window->GetParent() == window_->GetParent()) { |
132 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, | 131 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, |
133 window_); | 132 window_); |
134 } | 133 } |
135 | 134 |
136 const int kImages[] = IMAGE_GRID(IDR_ASH_WM_COMMON_PHANTOM_WINDOW); | 135 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW); |
137 views::Painter* background_painter = | 136 views::Painter* background_painter = |
138 views::Painter::CreateImageGridPainter(kImages); | 137 views::Painter::CreateImageGridPainter(kImages); |
139 views::View* content_view = new views::View; | 138 views::View* content_view = new views::View; |
140 content_view->set_background( | 139 content_view->set_background( |
141 views::Background::CreateBackgroundPainter(true, background_painter)); | 140 views::Background::CreateBackgroundPainter(true, background_painter)); |
142 phantom_widget->SetContentsView(content_view); | 141 phantom_widget->SetContentsView(content_view); |
143 | 142 |
144 // Show the widget after all the setups. | 143 // Show the widget after all the setups. |
145 phantom_widget->Show(); | 144 phantom_widget->Show(); |
146 | 145 |
147 // Fade the window in. | 146 // Fade the window in. |
148 ui::Layer* widget_layer = phantom_widget_window->GetLayer(); | 147 ui::Layer* widget_layer = phantom_widget_window->GetLayer(); |
149 widget_layer->SetOpacity(0); | 148 widget_layer->SetOpacity(0); |
150 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); | 149 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); |
151 scoped_setter.SetTransitionDuration( | 150 scoped_setter.SetTransitionDuration( |
152 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 151 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
153 widget_layer->SetOpacity(1); | 152 widget_layer->SetOpacity(1); |
154 | 153 |
155 return phantom_widget; | 154 return phantom_widget; |
156 } | 155 } |
157 | 156 |
158 } // namespace ash | 157 } // namespace ash |
OLD | NEW |