OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/wm/aura/wm_window_aura.h" | |
6 | |
7 #include "ash/ash_constants.h" | |
8 #include "ash/common/wm/window_state.h" | |
9 #include "ash/common/wm/wm_layout_manager.h" | |
10 #include "ash/common/wm/wm_window_observer.h" | |
11 #include "ash/common/wm/wm_window_property.h" | |
12 #include "ash/screen_util.h" | |
13 #include "ash/shelf/shelf_util.h" | |
14 #include "ash/shell.h" | |
15 #include "ash/wm/aura/aura_layout_manager_adapter.h" | |
16 #include "ash/wm/aura/wm_globals_aura.h" | |
17 #include "ash/wm/aura/wm_root_window_controller_aura.h" | |
18 #include "ash/wm/resize_shadow_controller.h" | |
19 #include "ash/wm/window_animations.h" | |
20 #include "ash/wm/window_properties.h" | |
21 #include "ash/wm/window_state_aura.h" | |
22 #include "ash/wm/window_util.h" | |
23 #include "base/memory/ptr_util.h" | |
24 #include "ui/aura/client/aura_constants.h" | |
25 #include "ui/aura/client/window_tree_client.h" | |
26 #include "ui/aura/layout_manager.h" | |
27 #include "ui/aura/window.h" | |
28 #include "ui/aura/window_delegate.h" | |
29 #include "ui/aura/window_property.h" | |
30 #include "ui/base/hit_test.h" | |
31 #include "ui/compositor/layer_tree_owner.h" | |
32 #include "ui/compositor/scoped_layer_animation_settings.h" | |
33 #include "ui/display/screen.h" | |
34 #include "ui/gfx/geometry/insets.h" | |
35 #include "ui/views/widget/widget.h" | |
36 #include "ui/wm/core/coordinate_conversion.h" | |
37 #include "ui/wm/core/easy_resize_window_targeter.h" | |
38 #include "ui/wm/core/visibility_controller.h" | |
39 #include "ui/wm/core/window_util.h" | |
40 | |
41 DECLARE_WINDOW_PROPERTY_TYPE(ash::wm::WmWindowAura*); | |
42 | |
43 namespace ash { | |
44 namespace wm { | |
45 | |
46 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ash::wm::WmWindowAura, kWmWindowKey, nullptr); | |
47 | |
48 namespace { | |
49 | |
50 // A tentative class to set the bounds on the window. | |
51 // TODO(oshima): Once all logic is cleaned up, move this to the real layout | |
52 // manager with proper friendship. | |
53 class BoundsSetter : public aura::LayoutManager { | |
54 public: | |
55 BoundsSetter() {} | |
56 ~BoundsSetter() override {} | |
57 | |
58 // aura::LayoutManager overrides: | |
59 void OnWindowResized() override {} | |
60 void OnWindowAddedToLayout(aura::Window* child) override {} | |
61 void OnWillRemoveWindowFromLayout(aura::Window* child) override {} | |
62 void OnWindowRemovedFromLayout(aura::Window* child) override {} | |
63 void OnChildWindowVisibilityChanged(aura::Window* child, | |
64 bool visible) override {} | |
65 void SetChildBounds(aura::Window* child, | |
66 const gfx::Rect& requested_bounds) override {} | |
67 | |
68 void SetBounds(aura::Window* window, const gfx::Rect& bounds) { | |
69 SetChildBoundsDirect(window, bounds); | |
70 } | |
71 | |
72 private: | |
73 DISALLOW_COPY_AND_ASSIGN(BoundsSetter); | |
74 }; | |
75 | |
76 } // namespace | |
77 | |
78 WmWindowAura::WmWindowAura(aura::Window* window) | |
79 : window_(window), | |
80 // Mirrors that of aura::Window. | |
81 observers_(base::ObserverList<WmWindowObserver>::NOTIFY_EXISTING_ONLY) { | |
82 window_->AddObserver(this); | |
83 window_->SetProperty(kWmWindowKey, this); | |
84 } | |
85 | |
86 // static | |
87 const WmWindow* WmWindowAura::Get(const aura::Window* window) { | |
88 if (!window) | |
89 return nullptr; | |
90 | |
91 const WmWindow* wm_window = window->GetProperty(kWmWindowKey); | |
92 if (wm_window) | |
93 return wm_window; | |
94 // WmWindowAura is owned by the aura::Window. | |
95 // TODO(sky): fix constness. | |
96 return new WmWindowAura(const_cast<aura::Window*>(window)); | |
97 } | |
98 | |
99 // static | |
100 std::vector<WmWindow*> WmWindowAura::FromAuraWindows( | |
101 const std::vector<aura::Window*>& aura_windows) { | |
102 std::vector<WmWindow*> result(aura_windows.size()); | |
103 for (size_t i = 0; i < aura_windows.size(); ++i) | |
104 result[i] = Get(aura_windows[i]); | |
105 return result; | |
106 } | |
107 | |
108 // static | |
109 const aura::Window* WmWindowAura::GetAuraWindow(const WmWindow* wm_window) { | |
110 return wm_window ? static_cast<const WmWindowAura*>(wm_window)->aura_window() | |
111 : nullptr; | |
112 } | |
113 | |
114 const WmWindow* WmWindowAura::GetRootWindow() const { | |
115 return Get(window_->GetRootWindow()); | |
116 } | |
117 | |
118 WmRootWindowController* WmWindowAura::GetRootWindowController() { | |
119 aura::Window* root = window_->GetRootWindow(); | |
120 return root ? WmRootWindowControllerAura::Get(root) : nullptr; | |
121 } | |
122 | |
123 WmGlobals* WmWindowAura::GetGlobals() const { | |
124 return WmGlobals::Get(); | |
125 } | |
126 | |
127 void WmWindowAura::SetName(const char* name) { | |
128 window_->SetName(name); | |
129 } | |
130 | |
131 base::string16 WmWindowAura::GetTitle() const { | |
132 return window_->title(); | |
133 } | |
134 | |
135 void WmWindowAura::SetShellWindowId(int id) { | |
136 window_->set_id(id); | |
137 } | |
138 | |
139 int WmWindowAura::GetShellWindowId() const { | |
140 return window_->id(); | |
141 } | |
142 | |
143 ui::wm::WindowType WmWindowAura::GetType() const { | |
144 return window_->type(); | |
145 } | |
146 | |
147 ui::Layer* WmWindowAura::GetLayer() { | |
148 return window_->layer(); | |
149 } | |
150 | |
151 display::Display WmWindowAura::GetDisplayNearestWindow() { | |
152 return display::Screen::GetScreen()->GetDisplayNearestWindow(window_); | |
153 } | |
154 | |
155 bool WmWindowAura::HasNonClientArea() { | |
156 return window_->delegate() ? true : false; | |
157 } | |
158 | |
159 int WmWindowAura::GetNonClientComponent(const gfx::Point& location) { | |
160 return window_->delegate() | |
161 ? window_->delegate()->GetNonClientComponent(location) | |
162 : HTNOWHERE; | |
163 } | |
164 | |
165 gfx::Point WmWindowAura::ConvertPointToTarget(const WmWindow* target, | |
166 const gfx::Point& point) const { | |
167 gfx::Point result(point); | |
168 aura::Window::ConvertPointToTarget(window_, GetAuraWindow(target), &result); | |
169 return result; | |
170 } | |
171 | |
172 gfx::Point WmWindowAura::ConvertPointToScreen(const gfx::Point& point) const { | |
173 gfx::Point result(point); | |
174 ::wm::ConvertPointToScreen(window_, &result); | |
175 return result; | |
176 } | |
177 | |
178 gfx::Point WmWindowAura::ConvertPointFromScreen(const gfx::Point& point) const { | |
179 gfx::Point result(point); | |
180 ::wm::ConvertPointFromScreen(window_, &result); | |
181 return result; | |
182 } | |
183 | |
184 gfx::Rect WmWindowAura::ConvertRectToScreen(const gfx::Rect& rect) const { | |
185 return ScreenUtil::ConvertRectToScreen(window_, rect); | |
186 } | |
187 | |
188 gfx::Rect WmWindowAura::ConvertRectFromScreen(const gfx::Rect& rect) const { | |
189 return ScreenUtil::ConvertRectFromScreen(window_, rect); | |
190 } | |
191 | |
192 gfx::Size WmWindowAura::GetMinimumSize() const { | |
193 return window_->delegate() ? window_->delegate()->GetMinimumSize() | |
194 : gfx::Size(); | |
195 } | |
196 | |
197 gfx::Size WmWindowAura::GetMaximumSize() const { | |
198 return window_->delegate() ? window_->delegate()->GetMaximumSize() | |
199 : gfx::Size(); | |
200 } | |
201 | |
202 bool WmWindowAura::GetTargetVisibility() const { | |
203 return window_->TargetVisibility(); | |
204 } | |
205 | |
206 bool WmWindowAura::IsVisible() const { | |
207 return window_->IsVisible(); | |
208 } | |
209 | |
210 void WmWindowAura::SetOpacity(float opacity) { | |
211 window_->layer()->SetOpacity(opacity); | |
212 } | |
213 | |
214 float WmWindowAura::GetTargetOpacity() const { | |
215 return window_->layer()->GetTargetOpacity(); | |
216 } | |
217 | |
218 void WmWindowAura::SetTransform(const gfx::Transform& transform) { | |
219 window_->SetTransform(transform); | |
220 } | |
221 | |
222 gfx::Transform WmWindowAura::GetTargetTransform() const { | |
223 return window_->layer()->GetTargetTransform(); | |
224 } | |
225 | |
226 bool WmWindowAura::IsSystemModal() const { | |
227 return window_->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM; | |
228 } | |
229 | |
230 bool WmWindowAura::GetBoolProperty(WmWindowProperty key) { | |
231 switch (key) { | |
232 case WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY: | |
233 return window_->GetProperty(kSnapChildrenToPixelBoundary); | |
234 | |
235 case WmWindowProperty::ALWAYS_ON_TOP: | |
236 return window_->GetProperty(aura::client::kAlwaysOnTopKey); | |
237 | |
238 default: | |
239 NOTREACHED(); | |
240 break; | |
241 } | |
242 | |
243 return false; | |
244 } | |
245 | |
246 int WmWindowAura::GetIntProperty(WmWindowProperty key) { | |
247 if (key == WmWindowProperty::SHELF_ID) | |
248 return GetShelfIDForWindow(window_); | |
249 | |
250 if (key == WmWindowProperty::TOP_VIEW_INSET) | |
251 return window_->GetProperty(aura::client::kTopViewInset); | |
252 | |
253 NOTREACHED(); | |
254 return 0; | |
255 } | |
256 | |
257 const WindowState* WmWindowAura::GetWindowState() const { | |
258 return ash::wm::GetWindowState(window_); | |
259 } | |
260 | |
261 WmWindow* WmWindowAura::GetToplevelWindow() { | |
262 return Get(window_->GetToplevelWindow()); | |
263 } | |
264 | |
265 void WmWindowAura::SetParentUsingContext(WmWindow* context, | |
266 const gfx::Rect& screen_bounds) { | |
267 aura::client::ParentWindowWithContext(window_, GetAuraWindow(context), | |
268 screen_bounds); | |
269 } | |
270 | |
271 void WmWindowAura::AddChild(WmWindow* window) { | |
272 window_->AddChild(GetAuraWindow(window)); | |
273 } | |
274 | |
275 WmWindow* WmWindowAura::GetParent() { | |
276 return Get(window_->parent()); | |
277 } | |
278 | |
279 const WmWindow* WmWindowAura::GetTransientParent() const { | |
280 return Get(::wm::GetTransientParent(window_)); | |
281 } | |
282 | |
283 std::vector<WmWindow*> WmWindowAura::GetTransientChildren() { | |
284 return FromAuraWindows(::wm::GetTransientChildren(window_)); | |
285 } | |
286 | |
287 void WmWindowAura::SetLayoutManager( | |
288 std::unique_ptr<WmLayoutManager> layout_manager) { | |
289 // |window_| takes ownership of AuraLayoutManagerAdapter. | |
290 window_->SetLayoutManager( | |
291 new AuraLayoutManagerAdapter(std::move(layout_manager))); | |
292 } | |
293 | |
294 WmLayoutManager* WmWindowAura::GetLayoutManager() { | |
295 return static_cast<AuraLayoutManagerAdapter*>(window_->layout_manager()) | |
296 ->wm_layout_manager(); | |
297 } | |
298 | |
299 void WmWindowAura::SetVisibilityAnimationType(int type) { | |
300 ::wm::SetWindowVisibilityAnimationType(window_, type); | |
301 } | |
302 | |
303 void WmWindowAura::SetVisibilityAnimationDuration(base::TimeDelta delta) { | |
304 ::wm::SetWindowVisibilityAnimationDuration(window_, delta); | |
305 } | |
306 | |
307 void WmWindowAura::SetVisibilityAnimationTransition( | |
308 ::wm::WindowVisibilityAnimationTransition transition) { | |
309 ::wm::SetWindowVisibilityAnimationTransition(window_, transition); | |
310 } | |
311 | |
312 void WmWindowAura::Animate(::wm::WindowAnimationType type) { | |
313 ::wm::AnimateWindow(window_, type); | |
314 } | |
315 | |
316 void WmWindowAura::StopAnimatingProperty( | |
317 ui::LayerAnimationElement::AnimatableProperty property) { | |
318 window_->layer()->GetAnimator()->StopAnimatingProperty(property); | |
319 } | |
320 | |
321 void WmWindowAura::SetChildWindowVisibilityChangesAnimated() { | |
322 ::wm::SetChildWindowVisibilityChangesAnimated(window_); | |
323 } | |
324 | |
325 void WmWindowAura::SetMasksToBounds(bool value) { | |
326 window_->layer()->SetMasksToBounds(value); | |
327 } | |
328 | |
329 void WmWindowAura::SetBounds(const gfx::Rect& bounds) { | |
330 window_->SetBounds(bounds); | |
331 } | |
332 | |
333 void WmWindowAura::SetBoundsWithTransitionDelay(const gfx::Rect& bounds, | |
334 base::TimeDelta delta) { | |
335 if (::wm::WindowAnimationsDisabled(window_)) { | |
336 window_->SetBounds(bounds); | |
337 return; | |
338 } | |
339 | |
340 ui::ScopedLayerAnimationSettings settings(window_->layer()->GetAnimator()); | |
341 settings.SetTransitionDuration(delta); | |
342 window_->SetBounds(bounds); | |
343 } | |
344 | |
345 void WmWindowAura::SetBoundsDirect(const gfx::Rect& bounds) { | |
346 BoundsSetter().SetBounds(window_, bounds); | |
347 SnapWindowToPixelBoundary(window_); | |
348 } | |
349 | |
350 void WmWindowAura::SetBoundsDirectAnimated(const gfx::Rect& bounds) { | |
351 const int kBoundsChangeSlideDurationMs = 120; | |
352 | |
353 ui::Layer* layer = window_->layer(); | |
354 ui::ScopedLayerAnimationSettings slide_settings(layer->GetAnimator()); | |
355 slide_settings.SetPreemptionStrategy( | |
356 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
357 slide_settings.SetTransitionDuration( | |
358 base::TimeDelta::FromMilliseconds(kBoundsChangeSlideDurationMs)); | |
359 SetBoundsDirect(bounds); | |
360 } | |
361 | |
362 void WmWindowAura::SetBoundsDirectCrossFade(const gfx::Rect& bounds) { | |
363 const gfx::Rect old_bounds = window_->bounds(); | |
364 | |
365 // Create fresh layers for the window and all its children to paint into. | |
366 // Takes ownership of the old layer and all its children, which will be | |
367 // cleaned up after the animation completes. | |
368 // Specify |set_bounds| to true here to keep the old bounds in the child | |
369 // windows of |window|. | |
370 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner = | |
371 ::wm::RecreateLayers(window_, nullptr); | |
372 ui::Layer* old_layer = old_layer_owner->root(); | |
373 DCHECK(old_layer); | |
374 ui::Layer* new_layer = window_->layer(); | |
375 | |
376 // Resize the window to the new size, which will force a layout and paint. | |
377 SetBoundsDirect(bounds); | |
378 | |
379 // Ensure the higher-resolution layer is on top. | |
380 bool old_on_top = (old_bounds.width() > bounds.width()); | |
381 if (old_on_top) | |
382 old_layer->parent()->StackBelow(new_layer, old_layer); | |
383 else | |
384 old_layer->parent()->StackAbove(new_layer, old_layer); | |
385 | |
386 CrossFadeAnimation(window_, std::move(old_layer_owner), gfx::Tween::EASE_OUT); | |
387 } | |
388 | |
389 void WmWindowAura::SetBoundsInScreen(const gfx::Rect& bounds_in_screen, | |
390 const display::Display& dst_display) { | |
391 window_->SetBoundsInScreen(bounds_in_screen, dst_display); | |
392 } | |
393 | |
394 gfx::Rect WmWindowAura::GetBoundsInScreen() const { | |
395 return window_->GetBoundsInScreen(); | |
396 } | |
397 | |
398 const gfx::Rect& WmWindowAura::GetBounds() const { | |
399 return window_->bounds(); | |
400 } | |
401 | |
402 gfx::Rect WmWindowAura::GetTargetBounds() { | |
403 return window_->GetTargetBounds(); | |
404 } | |
405 | |
406 void WmWindowAura::ClearRestoreBounds() { | |
407 window_->ClearProperty(aura::client::kRestoreBoundsKey); | |
408 } | |
409 | |
410 void WmWindowAura::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { | |
411 window_->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); | |
412 } | |
413 | |
414 gfx::Rect WmWindowAura::GetRestoreBoundsInScreen() const { | |
415 return *window_->GetProperty(aura::client::kRestoreBoundsKey); | |
416 } | |
417 | |
418 bool WmWindowAura::Contains(const WmWindow* other) const { | |
419 return other | |
420 ? window_->Contains( | |
421 static_cast<const WmWindowAura*>(other)->window_) | |
422 : false; | |
423 } | |
424 | |
425 void WmWindowAura::SetShowState(ui::WindowShowState show_state) { | |
426 window_->SetProperty(aura::client::kShowStateKey, show_state); | |
427 } | |
428 | |
429 ui::WindowShowState WmWindowAura::GetShowState() const { | |
430 return window_->GetProperty(aura::client::kShowStateKey); | |
431 } | |
432 | |
433 void WmWindowAura::SetRestoreShowState(ui::WindowShowState show_state) { | |
434 window_->SetProperty(aura::client::kRestoreShowStateKey, show_state); | |
435 } | |
436 | |
437 void WmWindowAura::SetLockedToRoot(bool value) { | |
438 window_->SetProperty(kStayInSameRootWindowKey, value); | |
439 } | |
440 | |
441 void WmWindowAura::SetCapture() { | |
442 window_->SetCapture(); | |
443 } | |
444 | |
445 bool WmWindowAura::HasCapture() { | |
446 return window_->HasCapture(); | |
447 } | |
448 | |
449 void WmWindowAura::ReleaseCapture() { | |
450 window_->ReleaseCapture(); | |
451 } | |
452 | |
453 bool WmWindowAura::HasRestoreBounds() const { | |
454 return window_->GetProperty(aura::client::kRestoreBoundsKey) != nullptr; | |
455 } | |
456 | |
457 bool WmWindowAura::CanMaximize() const { | |
458 return window_->GetProperty(aura::client::kCanMaximizeKey); | |
459 } | |
460 | |
461 bool WmWindowAura::CanMinimize() const { | |
462 return window_->GetProperty(aura::client::kCanMinimizeKey); | |
463 } | |
464 | |
465 bool WmWindowAura::CanResize() const { | |
466 return window_->GetProperty(aura::client::kCanResizeKey); | |
467 } | |
468 | |
469 bool WmWindowAura::CanActivate() const { | |
470 return ::wm::CanActivateWindow(window_); | |
471 } | |
472 | |
473 void WmWindowAura::StackChildAtTop(WmWindow* child) { | |
474 window_->StackChildAtTop(GetAuraWindow(child)); | |
475 } | |
476 | |
477 void WmWindowAura::StackChildAtBottom(WmWindow* child) { | |
478 window_->StackChildAtBottom(GetAuraWindow(child)); | |
479 } | |
480 | |
481 void WmWindowAura::StackChildAbove(WmWindow* child, WmWindow* target) { | |
482 window_->StackChildAbove(GetAuraWindow(child), GetAuraWindow(target)); | |
483 } | |
484 | |
485 void WmWindowAura::StackChildBelow(WmWindow* child, WmWindow* target) { | |
486 window_->StackChildBelow(GetAuraWindow(child), GetAuraWindow(target)); | |
487 } | |
488 | |
489 void WmWindowAura::SetAlwaysOnTop(bool value) { | |
490 window_->SetProperty(aura::client::kAlwaysOnTopKey, value); | |
491 } | |
492 | |
493 bool WmWindowAura::IsAlwaysOnTop() const { | |
494 return window_->GetProperty(aura::client::kAlwaysOnTopKey); | |
495 } | |
496 | |
497 void WmWindowAura::Hide() { | |
498 window_->Hide(); | |
499 } | |
500 | |
501 void WmWindowAura::Show() { | |
502 window_->Show(); | |
503 } | |
504 | |
505 void WmWindowAura::CloseWidget() { | |
506 DCHECK(views::Widget::GetWidgetForNativeView(window_)); | |
507 views::Widget::GetWidgetForNativeView(window_)->Close(); | |
508 } | |
509 | |
510 bool WmWindowAura::IsFocused() const { | |
511 return window_->HasFocus(); | |
512 } | |
513 | |
514 bool WmWindowAura::IsActive() const { | |
515 return IsActiveWindow(window_); | |
516 } | |
517 | |
518 void WmWindowAura::Activate() { | |
519 ActivateWindow(window_); | |
520 } | |
521 | |
522 void WmWindowAura::Deactivate() { | |
523 DeactivateWindow(window_); | |
524 } | |
525 | |
526 void WmWindowAura::SetFullscreen() { | |
527 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
528 } | |
529 | |
530 void WmWindowAura::Maximize() { | |
531 return window_->SetProperty(aura::client::kShowStateKey, | |
532 ui::SHOW_STATE_MAXIMIZED); | |
533 } | |
534 | |
535 void WmWindowAura::Minimize() { | |
536 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); | |
537 } | |
538 | |
539 void WmWindowAura::Unminimize() { | |
540 window_->SetProperty( | |
541 aura::client::kShowStateKey, | |
542 window_->GetProperty(aura::client::kRestoreShowStateKey)); | |
543 window_->ClearProperty(aura::client::kRestoreShowStateKey); | |
544 } | |
545 | |
546 std::vector<WmWindow*> WmWindowAura::GetChildren() { | |
547 return FromAuraWindows(window_->children()); | |
548 } | |
549 | |
550 WmWindow* WmWindowAura::GetChildByShellWindowId(int id) { | |
551 return Get(window_->GetChildById(id)); | |
552 } | |
553 | |
554 void WmWindowAura::ShowResizeShadow(int component) { | |
555 ResizeShadowController* resize_shadow_controller = | |
556 Shell::GetInstance()->resize_shadow_controller(); | |
557 if (resize_shadow_controller) | |
558 resize_shadow_controller->ShowShadow(window_, component); | |
559 } | |
560 | |
561 void WmWindowAura::HideResizeShadow() { | |
562 ResizeShadowController* resize_shadow_controller = | |
563 Shell::GetInstance()->resize_shadow_controller(); | |
564 if (resize_shadow_controller) | |
565 resize_shadow_controller->HideShadow(window_); | |
566 } | |
567 | |
568 void WmWindowAura::SetBoundsInScreenBehaviorForChildren( | |
569 BoundsInScreenBehavior behavior) { | |
570 window_->SetProperty( | |
571 kUsesScreenCoordinatesKey, | |
572 behavior == BoundsInScreenBehavior::USE_SCREEN_COORDINATES); | |
573 } | |
574 | |
575 void WmWindowAura::SetSnapsChildrenToPhysicalPixelBoundary() { | |
576 wm::SetSnapsChildrenToPhysicalPixelBoundary(window_); | |
577 } | |
578 | |
579 void WmWindowAura::SnapToPixelBoundaryIfNecessary() { | |
580 SnapWindowToPixelBoundary(window_); | |
581 } | |
582 | |
583 void WmWindowAura::SetChildrenUseExtendedHitRegion() { | |
584 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize, | |
585 -kResizeOutsideBoundsSize, | |
586 -kResizeOutsideBoundsSize); | |
587 gfx::Insets touch_extend = | |
588 mouse_extend.Scale(kResizeOutsideBoundsScaleForTouch); | |
589 window_->SetEventTargeter(base::WrapUnique( | |
590 new ::wm::EasyResizeWindowTargeter(window_, mouse_extend, touch_extend))); | |
591 } | |
592 | |
593 void WmWindowAura::SetDescendantsStayInSameRootWindow(bool value) { | |
594 window_->SetProperty(kStayInSameRootWindowKey, true); | |
595 } | |
596 | |
597 void WmWindowAura::AddObserver(WmWindowObserver* observer) { | |
598 observers_.AddObserver(observer); | |
599 } | |
600 | |
601 void WmWindowAura::RemoveObserver(WmWindowObserver* observer) { | |
602 observers_.RemoveObserver(observer); | |
603 } | |
604 | |
605 WmWindowAura::~WmWindowAura() { | |
606 window_->RemoveObserver(this); | |
607 } | |
608 | |
609 void WmWindowAura::OnWindowHierarchyChanged( | |
610 const HierarchyChangeParams& params) { | |
611 WmWindowObserver::TreeChangeParams wm_params; | |
612 wm_params.target = Get(params.target); | |
613 wm_params.new_parent = Get(params.new_parent); | |
614 wm_params.old_parent = Get(params.old_parent); | |
615 FOR_EACH_OBSERVER(WmWindowObserver, observers_, | |
616 OnWindowTreeChanged(this, wm_params)); | |
617 } | |
618 | |
619 void WmWindowAura::OnWindowStackingChanged(aura::Window* window) { | |
620 FOR_EACH_OBSERVER(WmWindowObserver, observers_, | |
621 OnWindowStackingChanged(this)); | |
622 } | |
623 | |
624 void WmWindowAura::OnWindowPropertyChanged(aura::Window* window, | |
625 const void* key, | |
626 intptr_t old) { | |
627 if (key == aura::client::kShowStateKey) { | |
628 ash::wm::GetWindowState(window_)->OnWindowShowStateChanged(); | |
629 return; | |
630 } | |
631 WmWindowProperty wm_property; | |
632 if (key == kSnapChildrenToPixelBoundary) { | |
633 wm_property = WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY; | |
634 } else if (key == aura::client::kAlwaysOnTopKey) { | |
635 wm_property = WmWindowProperty::ALWAYS_ON_TOP; | |
636 } else if (key == kShelfID) { | |
637 wm_property = WmWindowProperty::SHELF_ID; | |
638 } else if (key == aura::client::kTopViewInset) { | |
639 wm_property = WmWindowProperty::TOP_VIEW_INSET; | |
640 } else { | |
641 return; | |
642 } | |
643 FOR_EACH_OBSERVER(WmWindowObserver, observers_, | |
644 OnWindowPropertyChanged(this, wm_property)); | |
645 } | |
646 | |
647 void WmWindowAura::OnWindowBoundsChanged(aura::Window* window, | |
648 const gfx::Rect& old_bounds, | |
649 const gfx::Rect& new_bounds) { | |
650 FOR_EACH_OBSERVER(WmWindowObserver, observers_, | |
651 OnWindowBoundsChanged(this, old_bounds, new_bounds)); | |
652 } | |
653 | |
654 void WmWindowAura::OnWindowDestroying(aura::Window* window) { | |
655 FOR_EACH_OBSERVER(WmWindowObserver, observers_, OnWindowDestroying(this)); | |
656 } | |
657 | |
658 void WmWindowAura::OnWindowVisibilityChanging(aura::Window* window, | |
659 bool visible) { | |
660 FOR_EACH_OBSERVER(WmWindowObserver, observers_, | |
661 OnWindowVisibilityChanging(this, visible)); | |
662 } | |
663 | |
664 void WmWindowAura::OnWindowTitleChanged(aura::Window* window) { | |
665 FOR_EACH_OBSERVER(WmWindowObserver, observers_, OnWindowTitleChanged(this)); | |
666 } | |
667 | |
668 } // namespace wm | |
669 } // namespace ash | |
OLD | NEW |