Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/aura/wm_window_aura.h" | 5 #include "ash/wm/aura/wm_window_aura.h" |
| 6 | 6 |
| 7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
| 8 #include "ash/shelf/shelf_util.h" | 8 #include "ash/shelf/shelf_util.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/aura/aura_layout_manager_adapter.h" | 10 #include "ash/wm/aura/aura_layout_manager_adapter.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/client/window_tree_client.h" | 23 #include "ui/aura/client/window_tree_client.h" |
| 24 #include "ui/aura/layout_manager.h" | 24 #include "ui/aura/layout_manager.h" |
| 25 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 26 #include "ui/aura/window_delegate.h" | 26 #include "ui/aura/window_delegate.h" |
| 27 #include "ui/aura/window_property.h" | 27 #include "ui/aura/window_property.h" |
| 28 #include "ui/base/hit_test.h" | 28 #include "ui/base/hit_test.h" |
| 29 #include "ui/compositor/layer_tree_owner.h" | 29 #include "ui/compositor/layer_tree_owner.h" |
| 30 #include "ui/compositor/scoped_layer_animation_settings.h" | 30 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 31 #include "ui/display/screen.h" | 31 #include "ui/display/screen.h" |
| 32 #include "ui/views/widget/widget.h" | |
| 32 #include "ui/wm/core/coordinate_conversion.h" | 33 #include "ui/wm/core/coordinate_conversion.h" |
| 33 #include "ui/wm/core/window_util.h" | 34 #include "ui/wm/core/window_util.h" |
| 34 | 35 |
| 35 DECLARE_WINDOW_PROPERTY_TYPE(ash::wm::WmWindowAura*); | 36 DECLARE_WINDOW_PROPERTY_TYPE(ash::wm::WmWindowAura*); |
| 36 | 37 |
| 37 namespace ash { | 38 namespace ash { |
| 38 namespace wm { | 39 namespace wm { |
| 39 | 40 |
| 40 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ash::wm::WmWindowAura, kWmWindowKey, nullptr); | 41 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ash::wm::WmWindowAura, kWmWindowKey, nullptr); |
| 41 | 42 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 71 | 72 |
| 72 WmWindowAura::WmWindowAura(aura::Window* window) | 73 WmWindowAura::WmWindowAura(aura::Window* window) |
| 73 : window_(window), | 74 : window_(window), |
| 74 // Mirrors that of aura::Window. | 75 // Mirrors that of aura::Window. |
| 75 observers_(base::ObserverList<WmWindowObserver>::NOTIFY_EXISTING_ONLY) { | 76 observers_(base::ObserverList<WmWindowObserver>::NOTIFY_EXISTING_ONLY) { |
| 76 window_->AddObserver(this); | 77 window_->AddObserver(this); |
| 77 window_->SetProperty(kWmWindowKey, this); | 78 window_->SetProperty(kWmWindowKey, this); |
| 78 } | 79 } |
| 79 | 80 |
| 80 // static | 81 // static |
| 81 WmWindow* WmWindowAura::Get(aura::Window* window) { | 82 const WmWindow* WmWindowAura::Get(const aura::Window* window) { |
| 82 if (!window) | 83 if (!window) |
| 83 return nullptr; | 84 return nullptr; |
| 84 | 85 |
| 85 WmWindow* wm_window = window->GetProperty(kWmWindowKey); | 86 const WmWindow* wm_window = window->GetProperty(kWmWindowKey); |
| 86 if (wm_window) | 87 if (wm_window) |
| 87 return wm_window; | 88 return wm_window; |
| 88 // WmWindowAura is owned by the aura::Window. | 89 // WmWindowAura is owned by the aura::Window. |
| 89 return new WmWindowAura(window); | 90 // TODO(sky): fix constness. |
| 91 return new WmWindowAura(const_cast<aura::Window*>(window)); | |
| 90 } | 92 } |
| 91 | 93 |
| 92 // static | 94 // static |
| 93 std::vector<WmWindow*> WmWindowAura::FromAuraWindows( | 95 std::vector<WmWindow*> WmWindowAura::FromAuraWindows( |
| 94 const std::vector<aura::Window*>& aura_windows) { | 96 const std::vector<aura::Window*>& aura_windows) { |
| 95 std::vector<WmWindow*> result(aura_windows.size()); | 97 std::vector<WmWindow*> result(aura_windows.size()); |
| 96 for (size_t i = 0; i < aura_windows.size(); ++i) | 98 for (size_t i = 0; i < aura_windows.size(); ++i) |
| 97 result[i] = Get(aura_windows[i]); | 99 result[i] = Get(aura_windows[i]); |
| 98 return result; | 100 return result; |
| 99 } | 101 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 110 | 112 |
| 111 WmRootWindowController* WmWindowAura::GetRootWindowController() { | 113 WmRootWindowController* WmWindowAura::GetRootWindowController() { |
| 112 aura::Window* root = window_->GetRootWindow(); | 114 aura::Window* root = window_->GetRootWindow(); |
| 113 return root ? WmRootWindowControllerAura::Get(root) : nullptr; | 115 return root ? WmRootWindowControllerAura::Get(root) : nullptr; |
| 114 } | 116 } |
| 115 | 117 |
| 116 WmGlobals* WmWindowAura::GetGlobals() const { | 118 WmGlobals* WmWindowAura::GetGlobals() const { |
| 117 return WmGlobals::Get(); | 119 return WmGlobals::Get(); |
| 118 } | 120 } |
| 119 | 121 |
| 122 base::string16 WmWindowAura::GetTitle() const { | |
| 123 return window_->title(); | |
| 124 } | |
| 125 | |
| 120 void WmWindowAura::SetShellWindowId(int id) { | 126 void WmWindowAura::SetShellWindowId(int id) { |
| 121 window_->set_id(id); | 127 window_->set_id(id); |
| 122 } | 128 } |
| 123 | 129 |
| 124 int WmWindowAura::GetShellWindowId() const { | 130 int WmWindowAura::GetShellWindowId() const { |
| 125 return window_->id(); | 131 return window_->id(); |
| 126 } | 132 } |
| 127 | 133 |
| 128 ui::wm::WindowType WmWindowAura::GetType() const { | 134 ui::wm::WindowType WmWindowAura::GetType() const { |
| 129 return window_->type(); | 135 return window_->type(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 } | 191 } |
| 186 | 192 |
| 187 bool WmWindowAura::GetTargetVisibility() const { | 193 bool WmWindowAura::GetTargetVisibility() const { |
| 188 return window_->TargetVisibility(); | 194 return window_->TargetVisibility(); |
| 189 } | 195 } |
| 190 | 196 |
| 191 bool WmWindowAura::IsVisible() const { | 197 bool WmWindowAura::IsVisible() const { |
| 192 return window_->IsVisible(); | 198 return window_->IsVisible(); |
| 193 } | 199 } |
| 194 | 200 |
| 201 void WmWindowAura::SetOpacity(float opacity) { | |
| 202 window_->layer()->SetOpacity(opacity); | |
| 203 } | |
| 204 | |
| 205 float WmWindowAura::GetTargetOpacity() const { | |
| 206 return window_->layer()->GetTargetOpacity(); | |
| 207 } | |
| 208 | |
| 209 void WmWindowAura::SetTransform(const gfx::Transform& transform) { | |
| 210 window_->SetTransform(transform); | |
| 211 } | |
| 212 | |
| 213 gfx::Transform WmWindowAura::GetTargetTransform() const { | |
| 214 return window_->layer()->GetTargetTransform(); | |
| 215 } | |
| 216 | |
| 195 bool WmWindowAura::IsSystemModal() const { | 217 bool WmWindowAura::IsSystemModal() const { |
| 196 return window_->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM; | 218 return window_->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_SYSTEM; |
| 197 } | 219 } |
| 198 | 220 |
| 199 bool WmWindowAura::GetBoolProperty(WmWindowProperty key) { | 221 bool WmWindowAura::GetBoolProperty(WmWindowProperty key) { |
| 200 switch (key) { | 222 switch (key) { |
| 201 case WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUDARY: | 223 case WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUDARY: |
| 202 return window_->GetProperty(kSnapChildrenToPixelBoundary); | 224 return window_->GetProperty(kSnapChildrenToPixelBoundary); |
| 203 | 225 |
| 204 case WmWindowProperty::ALWAYS_ON_TOP: | 226 case WmWindowProperty::ALWAYS_ON_TOP: |
| 205 return window_->GetProperty(aura::client::kAlwaysOnTopKey); | 227 return window_->GetProperty(aura::client::kAlwaysOnTopKey); |
| 206 | 228 |
| 207 default: | 229 default: |
| 208 NOTREACHED(); | 230 NOTREACHED(); |
| 209 break; | 231 break; |
| 210 } | 232 } |
| 211 | 233 |
| 212 return false; | 234 return false; |
| 213 } | 235 } |
| 214 | 236 |
| 215 int WmWindowAura::GetIntProperty(WmWindowProperty key) { | 237 int WmWindowAura::GetIntProperty(WmWindowProperty key) { |
| 216 if (key == WmWindowProperty::SHELF_ID) | 238 if (key == WmWindowProperty::SHELF_ID) |
| 217 return GetShelfIDForWindow(window_); | 239 return GetShelfIDForWindow(window_); |
| 218 | 240 |
| 241 if (key == WmWindowProperty::TOP_VIEW_INSET) | |
| 242 return window_->GetProperty(aura::client::kTopViewInset); | |
| 243 | |
| 219 NOTREACHED(); | 244 NOTREACHED(); |
| 220 return 0; | 245 return 0; |
| 221 } | 246 } |
| 222 | 247 |
| 223 const WindowState* WmWindowAura::GetWindowState() const { | 248 const WindowState* WmWindowAura::GetWindowState() const { |
| 224 return ash::wm::GetWindowState(window_); | 249 return ash::wm::GetWindowState(window_); |
| 225 } | 250 } |
| 226 | 251 |
| 227 WmWindow* WmWindowAura::GetToplevelWindow() { | 252 WmWindow* WmWindowAura::GetToplevelWindow() { |
| 228 return Get(window_->GetToplevelWindow()); | 253 return Get(window_->GetToplevelWindow()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 } | 288 } |
| 264 | 289 |
| 265 void WmWindowAura::SetVisibilityAnimationType(int type) { | 290 void WmWindowAura::SetVisibilityAnimationType(int type) { |
| 266 ::wm::SetWindowVisibilityAnimationType(window_, type); | 291 ::wm::SetWindowVisibilityAnimationType(window_, type); |
| 267 } | 292 } |
| 268 | 293 |
| 269 void WmWindowAura::SetVisibilityAnimationDuration(base::TimeDelta delta) { | 294 void WmWindowAura::SetVisibilityAnimationDuration(base::TimeDelta delta) { |
| 270 ::wm::SetWindowVisibilityAnimationDuration(window_, delta); | 295 ::wm::SetWindowVisibilityAnimationDuration(window_, delta); |
| 271 } | 296 } |
| 272 | 297 |
| 298 void WmWindowAura::SetVisibilityAnimationTransition( | |
| 299 ::wm::WindowVisibilityAnimationTransition transition) { | |
| 300 ::wm::SetWindowVisibilityAnimationTransition(window_, transition); | |
| 301 } | |
| 302 | |
| 273 void WmWindowAura::Animate(::wm::WindowAnimationType type) { | 303 void WmWindowAura::Animate(::wm::WindowAnimationType type) { |
| 274 ::wm::AnimateWindow(window_, type); | 304 ::wm::AnimateWindow(window_, type); |
| 275 } | 305 } |
| 276 | 306 |
| 307 void WmWindowAura::StopAnimatingProperty( | |
| 308 ui::LayerAnimationElement::AnimatableProperty property) { | |
| 309 window_->layer()->GetAnimator()->StopAnimatingProperty(property); | |
| 310 } | |
| 311 | |
| 277 void WmWindowAura::SetBounds(const gfx::Rect& bounds) { | 312 void WmWindowAura::SetBounds(const gfx::Rect& bounds) { |
| 278 window_->SetBounds(bounds); | 313 window_->SetBounds(bounds); |
| 279 } | 314 } |
| 280 | 315 |
| 281 void WmWindowAura::SetBoundsWithTransitionDelay(const gfx::Rect& bounds, | 316 void WmWindowAura::SetBoundsWithTransitionDelay(const gfx::Rect& bounds, |
| 282 base::TimeDelta delta) { | 317 base::TimeDelta delta) { |
| 283 if (::wm::WindowAnimationsDisabled(window_)) { | 318 if (::wm::WindowAnimationsDisabled(window_)) { |
| 284 window_->SetBounds(bounds); | 319 window_->SetBounds(bounds); |
| 285 return; | 320 return; |
| 286 } | 321 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 } | 478 } |
| 444 | 479 |
| 445 void WmWindowAura::Hide() { | 480 void WmWindowAura::Hide() { |
| 446 window_->Hide(); | 481 window_->Hide(); |
| 447 } | 482 } |
| 448 | 483 |
| 449 void WmWindowAura::Show() { | 484 void WmWindowAura::Show() { |
| 450 window_->Show(); | 485 window_->Show(); |
| 451 } | 486 } |
| 452 | 487 |
| 488 void WmWindowAura::Close() { | |
| 489 views::Widget::GetWidgetForNativeView(window_)->Close(); | |
|
James Cook
2016/05/27 00:02:51
This seems a little dangerous to me, since not eve
sky
2016/05/27 03:18:03
Both it is.
| |
| 490 } | |
| 491 | |
| 453 bool WmWindowAura::IsFocused() const { | 492 bool WmWindowAura::IsFocused() const { |
| 454 return window_->HasFocus(); | 493 return window_->HasFocus(); |
| 455 } | 494 } |
| 456 | 495 |
| 457 bool WmWindowAura::IsActive() const { | 496 bool WmWindowAura::IsActive() const { |
| 458 return IsActiveWindow(window_); | 497 return IsActiveWindow(window_); |
| 459 } | 498 } |
| 460 | 499 |
| 461 void WmWindowAura::Activate() { | 500 void WmWindowAura::Activate() { |
| 462 ActivateWindow(window_); | 501 ActivateWindow(window_); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 ash::wm::GetWindowState(window_)->OnWindowShowStateChanged(); | 585 ash::wm::GetWindowState(window_)->OnWindowShowStateChanged(); |
| 547 return; | 586 return; |
| 548 } | 587 } |
| 549 WmWindowProperty wm_property; | 588 WmWindowProperty wm_property; |
| 550 if (key == kSnapChildrenToPixelBoundary) { | 589 if (key == kSnapChildrenToPixelBoundary) { |
| 551 wm_property = WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUDARY; | 590 wm_property = WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUDARY; |
| 552 } else if (key == aura::client::kAlwaysOnTopKey) { | 591 } else if (key == aura::client::kAlwaysOnTopKey) { |
| 553 wm_property = WmWindowProperty::ALWAYS_ON_TOP; | 592 wm_property = WmWindowProperty::ALWAYS_ON_TOP; |
| 554 } else if (key == kShelfID) { | 593 } else if (key == kShelfID) { |
| 555 wm_property = WmWindowProperty::SHELF_ID; | 594 wm_property = WmWindowProperty::SHELF_ID; |
| 595 } else if (key == aura::client::kTopViewInset) { | |
| 596 wm_property = WmWindowProperty::TOP_VIEW_INSET; | |
| 556 } else { | 597 } else { |
| 557 return; | 598 return; |
| 558 } | 599 } |
| 559 FOR_EACH_OBSERVER(WmWindowObserver, observers_, | 600 FOR_EACH_OBSERVER(WmWindowObserver, observers_, |
| 560 OnWindowPropertyChanged(this, wm_property)); | 601 OnWindowPropertyChanged(this, wm_property)); |
| 561 } | 602 } |
| 562 | 603 |
| 563 void WmWindowAura::OnWindowBoundsChanged(aura::Window* window, | 604 void WmWindowAura::OnWindowBoundsChanged(aura::Window* window, |
| 564 const gfx::Rect& old_bounds, | 605 const gfx::Rect& old_bounds, |
| 565 const gfx::Rect& new_bounds) { | 606 const gfx::Rect& new_bounds) { |
| 566 FOR_EACH_OBSERVER(WmWindowObserver, observers_, | 607 FOR_EACH_OBSERVER(WmWindowObserver, observers_, |
| 567 OnWindowBoundsChanged(this, old_bounds, new_bounds)); | 608 OnWindowBoundsChanged(this, old_bounds, new_bounds)); |
| 568 } | 609 } |
| 569 | 610 |
| 570 void WmWindowAura::OnWindowDestroying(aura::Window* window) { | 611 void WmWindowAura::OnWindowDestroying(aura::Window* window) { |
| 571 FOR_EACH_OBSERVER(WmWindowObserver, observers_, OnWindowDestroying(this)); | 612 FOR_EACH_OBSERVER(WmWindowObserver, observers_, OnWindowDestroying(this)); |
| 572 } | 613 } |
| 573 | 614 |
| 574 void WmWindowAura::OnWindowVisibilityChanging(aura::Window* window, | 615 void WmWindowAura::OnWindowVisibilityChanging(aura::Window* window, |
| 575 bool visible) { | 616 bool visible) { |
| 576 FOR_EACH_OBSERVER(WmWindowObserver, observers_, | 617 FOR_EACH_OBSERVER(WmWindowObserver, observers_, |
| 577 OnWindowVisibilityChanging(this, visible)); | 618 OnWindowVisibilityChanging(this, visible)); |
| 578 } | 619 } |
| 579 | 620 |
| 621 void WmWindowAura::OnWindowTitleChanged(aura::Window* window) { | |
| 622 FOR_EACH_OBSERVER(WmWindowObserver, observers_, OnWindowTitleChanged(this)); | |
| 623 } | |
| 624 | |
| 580 } // namespace wm | 625 } // namespace wm |
| 581 } // namespace ash | 626 } // namespace ash |
| OLD | NEW |