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 "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/wm/coordinate_conversion.h" | 9 #include "ash/wm/coordinate_conversion.h" |
10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 window_->AddObserver(this); | 83 window_->AddObserver(this); |
84 } | 84 } |
85 | 85 |
86 virtual ~WindowPainter() { | 86 virtual ~WindowPainter() { |
87 if (window_) | 87 if (window_) |
88 window_->RemoveObserver(this); | 88 window_->RemoveObserver(this); |
89 } | 89 } |
90 | 90 |
91 // views::Painter overrides: | 91 // views::Painter overrides: |
92 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE { | 92 virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE { |
93 // TODO(yusukes): Paint child windows of the |window_| correctly. Current | |
94 // code does not paint e.g. web content area in the window. crbug.com/141766 | |
95 if (window_ && window_->delegate()) | 93 if (window_ && window_->delegate()) |
96 window_->delegate()->OnPaint(canvas); | 94 window_->delegate()->OnPaint(canvas); |
97 } | 95 } |
98 | 96 |
99 private: | 97 private: |
100 // aura::WindowObserver overrides: | 98 // aura::WindowObserver overrides: |
101 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { | 99 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { |
102 DCHECK_EQ(window_, window); | 100 DCHECK_EQ(window_, window); |
103 window_ = NULL; | 101 window_ = NULL; |
104 } | 102 } |
105 | 103 |
106 aura::Window* window_; | 104 aura::Window* window_; |
107 | 105 |
108 DISALLOW_COPY_AND_ASSIGN(WindowPainter); | 106 DISALLOW_COPY_AND_ASSIGN(WindowPainter); |
109 }; | 107 }; |
110 | 108 |
111 } // namespace | 109 } // namespace |
112 | 110 |
113 PhantomWindowController::PhantomWindowController(aura::Window* window) | 111 PhantomWindowController::PhantomWindowController(aura::Window* window) |
114 : window_(window), | 112 : window_(window), |
115 phantom_below_window_(NULL), | 113 phantom_below_window_(NULL), |
116 phantom_widget_(NULL), | 114 phantom_widget_(NULL), |
117 style_(STYLE_SHADOW) { | 115 style_(STYLE_SHADOW), |
116 layer_(NULL) { | |
118 } | 117 } |
119 | 118 |
120 PhantomWindowController::~PhantomWindowController() { | 119 PhantomWindowController::~PhantomWindowController() { |
121 Hide(); | 120 Hide(); |
122 } | 121 } |
123 | 122 |
124 void PhantomWindowController::SetDestinationDisplay( | 123 void PhantomWindowController::SetDestinationDisplay( |
125 const gfx::Display& dst_display) { | 124 const gfx::Display& dst_display) { |
126 dst_display_ = dst_display; | 125 dst_display_ = dst_display; |
127 } | 126 } |
128 | 127 |
128 void PhantomWindowController::set_layer(ui::Layer* layer) { | |
129 // Cannot set a layer after the widget is initialized. | |
130 DCHECK(!phantom_widget_); | |
131 layer_ = layer; | |
132 } | |
133 | |
129 void PhantomWindowController::Show(const gfx::Rect& bounds) { | 134 void PhantomWindowController::Show(const gfx::Rect& bounds) { |
135 if (layer_) | |
136 layer_->SetVisible(true); | |
130 if (bounds == bounds_) | 137 if (bounds == bounds_) |
131 return; | 138 return; |
132 bounds_ = bounds; | 139 bounds_ = bounds; |
133 if (!phantom_widget_) { | 140 if (!phantom_widget_) { |
134 // Show the phantom at the bounds of the window. We'll animate to the target | 141 // Show the phantom at the bounds of the window. We'll animate to the target |
135 // bounds. | 142 // bounds. |
136 start_bounds_ = window_->GetBoundsInScreen(); | 143 start_bounds_ = window_->GetBoundsInScreen(); |
137 CreatePhantomWidget(start_bounds_); | 144 CreatePhantomWidget(start_bounds_); |
138 } else { | 145 } else { |
139 start_bounds_ = phantom_widget_->GetWindowBoundsInScreen(); | 146 start_bounds_ = phantom_widget_->GetWindowBoundsInScreen(); |
140 } | 147 } |
141 animation_.reset(new ui::SlideAnimation(this)); | 148 animation_.reset(new ui::SlideAnimation(this)); |
142 animation_->Show(); | 149 animation_->Show(); |
143 } | 150 } |
144 | 151 |
145 void PhantomWindowController::SetBounds(const gfx::Rect& bounds) { | 152 void PhantomWindowController::SetBounds(const gfx::Rect& bounds) { |
146 DCHECK(IsShowing()); | 153 DCHECK(IsShowing()); |
154 if (layer_) | |
155 layer_->SetVisible(true); | |
147 animation_.reset(); | 156 animation_.reset(); |
148 bounds_ = bounds; | 157 bounds_ = bounds; |
149 SetBoundsInternal(bounds); | 158 SetBoundsInternal(bounds); |
150 } | 159 } |
151 | 160 |
152 void PhantomWindowController::Hide() { | 161 void PhantomWindowController::Hide() { |
153 if (phantom_widget_) | 162 if (phantom_widget_) |
154 phantom_widget_->Close(); | 163 phantom_widget_->Close(); |
155 phantom_widget_ = NULL; | 164 phantom_widget_ = NULL; |
165 if (layer_) | |
166 layer_->SetVisible(false); | |
156 } | 167 } |
157 | 168 |
158 bool PhantomWindowController::IsShowing() const { | 169 bool PhantomWindowController::IsShowing() const { |
159 return phantom_widget_ != NULL; | 170 return phantom_widget_ != NULL; |
160 } | 171 } |
161 | 172 |
162 void PhantomWindowController::set_style(Style style) { | 173 void PhantomWindowController::set_style(Style style) { |
163 // Cannot change |style_| after the widget is initialized. | 174 // Cannot change |style_| after the widget is initialized. |
164 DCHECK(!phantom_widget_); | 175 DCHECK(!phantom_widget_); |
165 style_ = style; | 176 style_ = style; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 true, new WindowPainter(window_))); | 220 true, new WindowPainter(window_))); |
210 break; | 221 break; |
211 } | 222 } |
212 phantom_widget_->SetContentsView(content_view); | 223 phantom_widget_->SetContentsView(content_view); |
213 SetBoundsInternal(bounds); | 224 SetBoundsInternal(bounds); |
214 if (phantom_below_window_) | 225 if (phantom_below_window_) |
215 phantom_widget_->StackBelow(phantom_below_window_); | 226 phantom_widget_->StackBelow(phantom_below_window_); |
216 else | 227 else |
217 phantom_widget_->StackAbove(window_); | 228 phantom_widget_->StackAbove(window_); |
218 phantom_widget_->Show(); | 229 phantom_widget_->Show(); |
230 | |
231 if (layer_) { | |
232 // When |window|'s root window and |layer_|'s original root window is not | |
233 // the same (e.g. a phantom window for window dragging), most ui::Layers in | |
234 // |layer_| except the web content area are not rendered at all. To work | |
sky
2012/08/13 20:56:32
This seems weird. Can you talk with Antoine about
Yusuke Sato
2012/08/15 21:18:23
Done. Talked with him and added set_delegate call
| |
235 // around the issue, we continue to use WindowPainter to render non-web | |
236 // content part of the window. | |
237 // TODO(yusukes): Find a way to resolve the issue and remove WindowPainter. | |
238 aura::Window* window = phantom_widget_->GetNativeWindow(); | |
239 window->layer()->Add(layer_); | |
240 window->layer()->StackAtTop(layer_); | |
241 } | |
242 | |
219 // Fade the window in. | 243 // Fade the window in. |
220 ui::Layer* layer = phantom_widget_->GetNativeWindow()->layer(); | 244 ui::Layer* layer = phantom_widget_->GetNativeWindow()->layer(); |
221 layer->SetOpacity(0); | 245 layer->SetOpacity(0); |
222 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); | 246 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator()); |
223 layer->SetOpacity(1); | 247 layer->SetOpacity(1); |
224 } | 248 } |
225 | 249 |
226 void PhantomWindowController::SetBoundsInternal(const gfx::Rect& bounds) { | 250 void PhantomWindowController::SetBoundsInternal(const gfx::Rect& bounds) { |
227 aura::Window* window = phantom_widget_->GetNativeWindow(); | 251 aura::Window* window = phantom_widget_->GetNativeWindow(); |
228 aura::client::ScreenPositionClient* screen_position_client = | 252 aura::client::ScreenPositionClient* screen_position_client = |
229 aura::client::GetScreenPositionClient(window->GetRootWindow()); | 253 aura::client::GetScreenPositionClient(window->GetRootWindow()); |
230 if (screen_position_client && dst_display_.id() != -1) | 254 if (screen_position_client && dst_display_.id() != -1) |
231 screen_position_client->SetBounds(window, bounds, dst_display_); | 255 screen_position_client->SetBounds(window, bounds, dst_display_); |
232 else | 256 else |
233 phantom_widget_->SetBounds(bounds); | 257 phantom_widget_->SetBounds(bounds); |
234 } | 258 } |
235 | 259 |
236 } // namespace internal | 260 } // namespace internal |
237 } // namespace ash | 261 } // namespace ash |
OLD | NEW |