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_resources.h" | 14 #include "grit/ash_wm_common_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_AURA_PHANTOM_WINDOW image assets. | 37 // is derived from the size of the IDR_ASH_WM_COMMON_PHANTOM_WINDOW image |
| 38 // assets. |
38 const int kMinSizeWithShadow = 100; | 39 const int kMinSizeWithShadow = 100; |
39 | 40 |
40 // Adjusts the phantom window's bounds so that the bounds: | 41 // Adjusts the phantom window's bounds so that the bounds: |
41 // - Include the size of the shadow. | 42 // - Include the size of the shadow. |
42 // - Have a size equal to or larger than the minimum phantom window size. | 43 // - Have a size equal to or larger than the minimum phantom window size. |
43 gfx::Rect GetAdjustedBounds(const gfx::Rect& bounds) { | 44 gfx::Rect GetAdjustedBounds(const gfx::Rect& bounds) { |
44 int x_inset = std::max( | 45 int x_inset = std::max( |
45 static_cast<int>(ceil((kMinSizeWithShadow - bounds.width()) / 2.0f)), | 46 static_cast<int>(ceil((kMinSizeWithShadow - bounds.width()) / 2.0f)), |
46 kShadowThickness); | 47 kShadowThickness); |
47 int y_inset = std::max( | 48 int y_inset = std::max( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 wm::WmWindow* phantom_widget_window = | 126 wm::WmWindow* phantom_widget_window = |
126 wm::WmLookup::Get()->GetWindowForWidget(phantom_widget.get()); | 127 wm::WmLookup::Get()->GetWindowForWidget(phantom_widget.get()); |
127 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow); | 128 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow); |
128 phantom_widget->SetBounds(bounds_in_screen); | 129 phantom_widget->SetBounds(bounds_in_screen); |
129 // TODO(sky): I suspect this is never true, verify that. | 130 // TODO(sky): I suspect this is never true, verify that. |
130 if (phantom_widget_window->GetParent() == window_->GetParent()) { | 131 if (phantom_widget_window->GetParent() == window_->GetParent()) { |
131 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, | 132 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, |
132 window_); | 133 window_); |
133 } | 134 } |
134 | 135 |
135 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW); | 136 const int kImages[] = IMAGE_GRID(IDR_ASH_WM_COMMON_PHANTOM_WINDOW); |
136 views::Painter* background_painter = | 137 views::Painter* background_painter = |
137 views::Painter::CreateImageGridPainter(kImages); | 138 views::Painter::CreateImageGridPainter(kImages); |
138 views::View* content_view = new views::View; | 139 views::View* content_view = new views::View; |
139 content_view->set_background( | 140 content_view->set_background( |
140 views::Background::CreateBackgroundPainter(true, background_painter)); | 141 views::Background::CreateBackgroundPainter(true, background_painter)); |
141 phantom_widget->SetContentsView(content_view); | 142 phantom_widget->SetContentsView(content_view); |
142 | 143 |
143 // Show the widget after all the setups. | 144 // Show the widget after all the setups. |
144 phantom_widget->Show(); | 145 phantom_widget->Show(); |
145 | 146 |
146 // Fade the window in. | 147 // Fade the window in. |
147 ui::Layer* widget_layer = phantom_widget_window->GetLayer(); | 148 ui::Layer* widget_layer = phantom_widget_window->GetLayer(); |
148 widget_layer->SetOpacity(0); | 149 widget_layer->SetOpacity(0); |
149 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); | 150 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); |
150 scoped_setter.SetTransitionDuration( | 151 scoped_setter.SetTransitionDuration( |
151 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 152 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
152 widget_layer->SetOpacity(1); | 153 widget_layer->SetOpacity(1); |
153 | 154 |
154 return phantom_widget; | 155 return phantom_widget; |
155 } | 156 } |
156 | 157 |
157 } // namespace ash | 158 } // namespace ash |
OLD | NEW |