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/common/wm/workspace/phantom_window_controller.h" | 5 #include "ash/common/wm/workspace/phantom_window_controller.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
10 #include "ash/common/wm/root_window_finder.h" | 10 #include "ash/common/wm/root_window_finder.h" |
11 #include "ash/common/wm/wm_lookup.h" | 11 #include "ash/common/wm_lookup.h" |
12 #include "ash/common/wm/wm_root_window_controller.h" | 12 #include "ash/common/wm_root_window_controller.h" |
13 #include "ash/common/wm/wm_window.h" | 13 #include "ash/common/wm_window.h" |
14 #include "grit/ash_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 { |
(...skipping 30 matching lines...) Expand all Loading... |
54 } | 54 } |
55 | 55 |
56 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget| | 56 // Starts an animation of |widget| to |new_bounds_in_screen|. No-op if |widget| |
57 // is NULL. | 57 // is NULL. |
58 void AnimateToBounds(views::Widget* widget, | 58 void AnimateToBounds(views::Widget* widget, |
59 const gfx::Rect& new_bounds_in_screen) { | 59 const gfx::Rect& new_bounds_in_screen) { |
60 if (!widget) | 60 if (!widget) |
61 return; | 61 return; |
62 | 62 |
63 ui::ScopedLayerAnimationSettings scoped_setter( | 63 ui::ScopedLayerAnimationSettings scoped_setter( |
64 wm::WmLookup::Get() | 64 WmLookup::Get()->GetWindowForWidget(widget)->GetLayer()->GetAnimator()); |
65 ->GetWindowForWidget(widget) | |
66 ->GetLayer() | |
67 ->GetAnimator()); | |
68 scoped_setter.SetTweenType(gfx::Tween::EASE_IN); | 65 scoped_setter.SetTweenType(gfx::Tween::EASE_IN); |
69 scoped_setter.SetPreemptionStrategy( | 66 scoped_setter.SetPreemptionStrategy( |
70 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 67 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
71 scoped_setter.SetTransitionDuration( | 68 scoped_setter.SetTransitionDuration( |
72 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 69 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
73 widget->SetBounds(new_bounds_in_screen); | 70 widget->SetBounds(new_bounds_in_screen); |
74 } | 71 } |
75 | 72 |
76 } // namespace | 73 } // namespace |
77 | 74 |
78 // PhantomWindowController ---------------------------------------------------- | 75 // PhantomWindowController ---------------------------------------------------- |
79 | 76 |
80 PhantomWindowController::PhantomWindowController(wm::WmWindow* window) | 77 PhantomWindowController::PhantomWindowController(WmWindow* window) |
81 : window_(window) {} | 78 : window_(window) {} |
82 | 79 |
83 PhantomWindowController::~PhantomWindowController() {} | 80 PhantomWindowController::~PhantomWindowController() {} |
84 | 81 |
85 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { | 82 void PhantomWindowController::Show(const gfx::Rect& bounds_in_screen) { |
86 gfx::Rect adjusted_bounds_in_screen = GetAdjustedBounds(bounds_in_screen); | 83 gfx::Rect adjusted_bounds_in_screen = GetAdjustedBounds(bounds_in_screen); |
87 if (adjusted_bounds_in_screen == target_bounds_in_screen_) | 84 if (adjusted_bounds_in_screen == target_bounds_in_screen_) |
88 return; | 85 return; |
89 target_bounds_in_screen_ = adjusted_bounds_in_screen; | 86 target_bounds_in_screen_ = adjusted_bounds_in_screen; |
90 | 87 |
91 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; | 88 gfx::Rect start_bounds_in_screen = target_bounds_in_screen_; |
92 int start_width = std::max( | 89 int start_width = std::max( |
93 kMinSizeWithShadow, | 90 kMinSizeWithShadow, |
94 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio)); | 91 static_cast<int>(start_bounds_in_screen.width() * kStartBoundsRatio)); |
95 int start_height = std::max( | 92 int start_height = std::max( |
96 kMinSizeWithShadow, | 93 kMinSizeWithShadow, |
97 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio)); | 94 static_cast<int>(start_bounds_in_screen.height() * kStartBoundsRatio)); |
98 start_bounds_in_screen.Inset( | 95 start_bounds_in_screen.Inset( |
99 floor((start_bounds_in_screen.width() - start_width) / 2.0f), | 96 floor((start_bounds_in_screen.width() - start_width) / 2.0f), |
100 floor((start_bounds_in_screen.height() - start_height) / 2.0f)); | 97 floor((start_bounds_in_screen.height() - start_height) / 2.0f)); |
101 phantom_widget_ = | 98 phantom_widget_ = |
102 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_), | 99 CreatePhantomWidget(wm::GetRootWindowMatching(target_bounds_in_screen_), |
103 start_bounds_in_screen); | 100 start_bounds_in_screen); |
104 | 101 |
105 AnimateToBounds(phantom_widget_.get(), target_bounds_in_screen_); | 102 AnimateToBounds(phantom_widget_.get(), target_bounds_in_screen_); |
106 } | 103 } |
107 | 104 |
108 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( | 105 std::unique_ptr<views::Widget> PhantomWindowController::CreatePhantomWidget( |
109 wm::WmWindow* root_window, | 106 WmWindow* root_window, |
110 const gfx::Rect& bounds_in_screen) { | 107 const gfx::Rect& bounds_in_screen) { |
111 std::unique_ptr<views::Widget> phantom_widget(new views::Widget); | 108 std::unique_ptr<views::Widget> phantom_widget(new views::Widget); |
112 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 109 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
113 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 110 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
114 // PhantomWindowController is used by FrameMaximizeButton to highlight the | 111 // PhantomWindowController is used by FrameMaximizeButton to highlight the |
115 // launcher button. Put the phantom in the same window as the launcher so that | 112 // launcher button. Put the phantom in the same window as the launcher so that |
116 // the phantom is visible. | 113 // the phantom is visible. |
117 params.keep_on_top = true; | 114 params.keep_on_top = true; |
118 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 115 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
119 params.name = "PhantomWindow"; | 116 params.name = "PhantomWindow"; |
120 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( | 117 root_window->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( |
121 phantom_widget.get(), kShellWindowId_ShelfContainer, ¶ms); | 118 phantom_widget.get(), kShellWindowId_ShelfContainer, ¶ms); |
122 phantom_widget->set_focus_on_creation(false); | 119 phantom_widget->set_focus_on_creation(false); |
123 phantom_widget->Init(params); | 120 phantom_widget->Init(params); |
124 phantom_widget->SetVisibilityChangedAnimationsEnabled(false); | 121 phantom_widget->SetVisibilityChangedAnimationsEnabled(false); |
125 wm::WmWindow* phantom_widget_window = | 122 WmWindow* phantom_widget_window = |
126 wm::WmLookup::Get()->GetWindowForWidget(phantom_widget.get()); | 123 WmLookup::Get()->GetWindowForWidget(phantom_widget.get()); |
127 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow); | 124 phantom_widget_window->SetShellWindowId(kShellWindowId_PhantomWindow); |
128 phantom_widget->SetBounds(bounds_in_screen); | 125 phantom_widget->SetBounds(bounds_in_screen); |
129 // TODO(sky): I suspect this is never true, verify that. | 126 // TODO(sky): I suspect this is never true, verify that. |
130 if (phantom_widget_window->GetParent() == window_->GetParent()) { | 127 if (phantom_widget_window->GetParent() == window_->GetParent()) { |
131 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, | 128 phantom_widget_window->GetParent()->StackChildAbove(phantom_widget_window, |
132 window_); | 129 window_); |
133 } | 130 } |
134 | 131 |
135 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW); | 132 const int kImages[] = IMAGE_GRID(IDR_AURA_PHANTOM_WINDOW); |
136 views::Painter* background_painter = | 133 views::Painter* background_painter = |
(...skipping 11 matching lines...) Expand all Loading... |
148 widget_layer->SetOpacity(0); | 145 widget_layer->SetOpacity(0); |
149 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); | 146 ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator()); |
150 scoped_setter.SetTransitionDuration( | 147 scoped_setter.SetTransitionDuration( |
151 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 148 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
152 widget_layer->SetOpacity(1); | 149 widget_layer->SetOpacity(1); |
153 | 150 |
154 return phantom_widget; | 151 return phantom_widget; |
155 } | 152 } |
156 | 153 |
157 } // namespace ash | 154 } // namespace ash |
OLD | NEW |