| 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 "mash/wm/bridge/wm_window_mus.h" | |
| 6 | |
| 7 #include "ash/common/wm/container_finder.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 "components/mus/public/cpp/property_type_converters.h" | |
| 13 #include "components/mus/public/cpp/window.h" | |
| 14 #include "components/mus/public/cpp/window_property.h" | |
| 15 #include "components/mus/public/cpp/window_tree_client.h" | |
| 16 #include "components/mus/public/interfaces/window_manager.mojom.h" | |
| 17 #include "mash/wm/bridge/mus_layout_manager_adapter.h" | |
| 18 #include "mash/wm/bridge/wm_globals_mus.h" | |
| 19 #include "mash/wm/bridge/wm_root_window_controller_mus.h" | |
| 20 #include "mash/wm/property_util.h" | |
| 21 #include "ui/aura/mus/mus_util.h" | |
| 22 #include "ui/base/hit_test.h" | |
| 23 #include "ui/display/display.h" | |
| 24 #include "ui/views/widget/widget.h" | |
| 25 #include "ui/views/widget/widget_delegate.h" | |
| 26 | |
| 27 MUS_DECLARE_WINDOW_PROPERTY_TYPE(mash::wm::WmWindowMus*); | |
| 28 | |
| 29 // TODO(sky): fully implement this. Making DVLOG as too spammy to be useful. | |
| 30 #undef NOTIMPLEMENTED | |
| 31 #define NOTIMPLEMENTED() DVLOG(1) << "notimplemented" | |
| 32 | |
| 33 namespace mash { | |
| 34 namespace wm { | |
| 35 | |
| 36 MUS_DEFINE_OWNED_WINDOW_PROPERTY_KEY(mash::wm::WmWindowMus, | |
| 37 kWmWindowKey, | |
| 38 nullptr); | |
| 39 namespace { | |
| 40 | |
| 41 // This classes is used so that the WindowState constructor can be made | |
| 42 // protected. GetWindowState() is the only place that should be creating | |
| 43 // WindowState. | |
| 44 class WindowStateMus : public ash::wm::WindowState { | |
| 45 public: | |
| 46 explicit WindowStateMus(ash::wm::WmWindow* window) | |
| 47 : ash::wm::WindowState(window) {} | |
| 48 ~WindowStateMus() override {} | |
| 49 | |
| 50 private: | |
| 51 DISALLOW_COPY_AND_ASSIGN(WindowStateMus); | |
| 52 }; | |
| 53 | |
| 54 ui::WindowShowState UIWindowShowStateFromMojom(mus::mojom::ShowState state) { | |
| 55 switch (state) { | |
| 56 case mus::mojom::ShowState::DEFAULT: | |
| 57 return ui::SHOW_STATE_DEFAULT; | |
| 58 case mus::mojom::ShowState::NORMAL: | |
| 59 return ui::SHOW_STATE_NORMAL; | |
| 60 case mus::mojom::ShowState::MINIMIZED: | |
| 61 return ui::SHOW_STATE_MINIMIZED; | |
| 62 case mus::mojom::ShowState::MAXIMIZED: | |
| 63 return ui::SHOW_STATE_MAXIMIZED; | |
| 64 case mus::mojom::ShowState::INACTIVE: | |
| 65 return ui::SHOW_STATE_INACTIVE; | |
| 66 case mus::mojom::ShowState::FULLSCREEN: | |
| 67 return ui::SHOW_STATE_FULLSCREEN; | |
| 68 case mus::mojom::ShowState::DOCKED: | |
| 69 return ui::SHOW_STATE_DOCKED; | |
| 70 default: | |
| 71 break; | |
| 72 } | |
| 73 return ui::SHOW_STATE_DEFAULT; | |
| 74 } | |
| 75 | |
| 76 mus::mojom::ShowState MojomWindowShowStateFromUI(ui::WindowShowState state) { | |
| 77 switch (state) { | |
| 78 case ui::SHOW_STATE_DEFAULT: | |
| 79 return mus::mojom::ShowState::DEFAULT; | |
| 80 case ui::SHOW_STATE_NORMAL: | |
| 81 return mus::mojom::ShowState::NORMAL; | |
| 82 case ui::SHOW_STATE_MINIMIZED: | |
| 83 return mus::mojom::ShowState::MINIMIZED; | |
| 84 case ui::SHOW_STATE_MAXIMIZED: | |
| 85 return mus::mojom::ShowState::MAXIMIZED; | |
| 86 case ui::SHOW_STATE_INACTIVE: | |
| 87 return mus::mojom::ShowState::INACTIVE; | |
| 88 case ui::SHOW_STATE_FULLSCREEN: | |
| 89 return mus::mojom::ShowState::FULLSCREEN; | |
| 90 case ui::SHOW_STATE_DOCKED: | |
| 91 return mus::mojom::ShowState::DOCKED; | |
| 92 default: | |
| 93 break; | |
| 94 } | |
| 95 return mus::mojom::ShowState::DEFAULT; | |
| 96 } | |
| 97 | |
| 98 } // namespace | |
| 99 | |
| 100 WmWindowMus::WmWindowMus(mus::Window* window) | |
| 101 : window_(window), | |
| 102 // Matches aura, see aura::Window for details. | |
| 103 observers_( | |
| 104 base::ObserverList<ash::wm::WmWindowObserver>::NOTIFY_EXISTING_ONLY) { | |
| 105 window_->AddObserver(this); | |
| 106 window_->SetLocalProperty(kWmWindowKey, this); | |
| 107 window_state_.reset(new WindowStateMus(this)); | |
| 108 } | |
| 109 | |
| 110 WmWindowMus::~WmWindowMus() { | |
| 111 window_->RemoveObserver(this); | |
| 112 } | |
| 113 | |
| 114 // static | |
| 115 WmWindowMus* WmWindowMus::Get(mus::Window* window) { | |
| 116 if (!window) | |
| 117 return nullptr; | |
| 118 | |
| 119 wm::WmWindowMus* wm_window = window->GetLocalProperty(kWmWindowKey); | |
| 120 if (wm_window) | |
| 121 return wm_window; | |
| 122 // WmWindowMus is owned by the mus::Window. | |
| 123 return new WmWindowMus(window); | |
| 124 } | |
| 125 | |
| 126 // static | |
| 127 WmWindowMus* WmWindowMus::Get(views::Widget* widget) { | |
| 128 return WmWindowMus::Get(aura::GetMusWindow(widget->GetNativeView())); | |
| 129 } | |
| 130 | |
| 131 // static | |
| 132 const mus::Window* WmWindowMus::GetMusWindow( | |
| 133 const ash::wm::WmWindow* wm_window) { | |
| 134 return static_cast<const WmWindowMus*>(wm_window)->mus_window(); | |
| 135 } | |
| 136 | |
| 137 // static | |
| 138 std::vector<ash::wm::WmWindow*> WmWindowMus::FromMusWindows( | |
| 139 const std::vector<mus::Window*>& mus_windows) { | |
| 140 std::vector<ash::wm::WmWindow*> result(mus_windows.size()); | |
| 141 for (size_t i = 0; i < mus_windows.size(); ++i) | |
| 142 result[i] = Get(mus_windows[i]); | |
| 143 return result; | |
| 144 } | |
| 145 | |
| 146 const WmRootWindowControllerMus* WmWindowMus::GetRootWindowControllerMus() | |
| 147 const { | |
| 148 return WmRootWindowControllerMus::Get(window_->GetRoot()); | |
| 149 } | |
| 150 | |
| 151 bool WmWindowMus::ShouldUseExtendedHitRegion() const { | |
| 152 const WmWindowMus* parent = Get(window_->parent()); | |
| 153 return parent && parent->children_use_extended_hit_region_; | |
| 154 } | |
| 155 | |
| 156 const ash::wm::WmWindow* WmWindowMus::GetRootWindow() const { | |
| 157 return Get(window_->GetRoot()); | |
| 158 } | |
| 159 | |
| 160 ash::wm::WmRootWindowController* WmWindowMus::GetRootWindowController() { | |
| 161 return GetRootWindowControllerMus(); | |
| 162 } | |
| 163 | |
| 164 ash::wm::WmGlobals* WmWindowMus::GetGlobals() const { | |
| 165 return WmGlobalsMus::Get(); | |
| 166 } | |
| 167 | |
| 168 void WmWindowMus::SetName(const char* name) { | |
| 169 if (name) { | |
| 170 window_->SetSharedProperty<std::string>( | |
| 171 mus::mojom::WindowManager::kName_Property, std::string(name)); | |
| 172 } else { | |
| 173 window_->ClearSharedProperty(mus::mojom::WindowManager::kName_Property); | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 base::string16 WmWindowMus::GetTitle() const { | |
| 178 return GetWindowTitle(window_); | |
| 179 } | |
| 180 | |
| 181 void WmWindowMus::SetShellWindowId(int id) { | |
| 182 shell_window_id_ = id; | |
| 183 } | |
| 184 | |
| 185 int WmWindowMus::GetShellWindowId() const { | |
| 186 return shell_window_id_; | |
| 187 } | |
| 188 | |
| 189 ui::wm::WindowType WmWindowMus::GetType() const { | |
| 190 return GetWmWindowType(window_); | |
| 191 } | |
| 192 | |
| 193 ui::Layer* WmWindowMus::GetLayer() { | |
| 194 // TODO(sky): this function should be nuked entirely. | |
| 195 NOTIMPLEMENTED(); | |
| 196 return widget_ ? widget_->GetLayer() : nullptr; | |
| 197 } | |
| 198 | |
| 199 display::Display WmWindowMus::GetDisplayNearestWindow() { | |
| 200 // TODO(sky): deal with null rwc. | |
| 201 return GetRootWindowControllerMus()->GetDisplay(); | |
| 202 } | |
| 203 | |
| 204 bool WmWindowMus::HasNonClientArea() { | |
| 205 return widget_ ? true : false; | |
| 206 } | |
| 207 | |
| 208 int WmWindowMus::GetNonClientComponent(const gfx::Point& location) { | |
| 209 return widget_ ? widget_->GetNonClientComponent(location) : HTNOWHERE; | |
| 210 } | |
| 211 | |
| 212 gfx::Point WmWindowMus::ConvertPointToTarget(const WmWindow* target, | |
| 213 const gfx::Point& point) const { | |
| 214 const mus::Window* target_window = GetMusWindow(target); | |
| 215 if (target_window->Contains(window_)) { | |
| 216 gfx::Point result(point); | |
| 217 const mus::Window* window = window_; | |
| 218 while (window != target_window) { | |
| 219 result += window->bounds().origin().OffsetFromOrigin(); | |
| 220 window = window->parent(); | |
| 221 } | |
| 222 return result; | |
| 223 } | |
| 224 if (window_->Contains(target_window)) { | |
| 225 gfx::Point result(point); | |
| 226 result -= | |
| 227 target->ConvertPointToTarget(this, gfx::Point()).OffsetFromOrigin(); | |
| 228 return result; | |
| 229 } | |
| 230 // Different roots. | |
| 231 gfx::Point point_in_screen = | |
| 232 GetRootWindowControllerMus()->ConvertPointToScreen(this, point); | |
| 233 return AsWmWindowMus(target) | |
| 234 ->GetRootWindowControllerMus() | |
| 235 ->ConvertPointFromScreen(AsWmWindowMus(target), point_in_screen); | |
| 236 } | |
| 237 | |
| 238 gfx::Point WmWindowMus::ConvertPointToScreen(const gfx::Point& point) const { | |
| 239 return GetRootWindowControllerMus()->ConvertPointToScreen(this, point); | |
| 240 } | |
| 241 | |
| 242 gfx::Point WmWindowMus::ConvertPointFromScreen(const gfx::Point& point) const { | |
| 243 return GetRootWindowControllerMus()->ConvertPointFromScreen(this, point); | |
| 244 } | |
| 245 | |
| 246 gfx::Rect WmWindowMus::ConvertRectToScreen(const gfx::Rect& rect) const { | |
| 247 return gfx::Rect(ConvertPointToScreen(rect.origin()), rect.size()); | |
| 248 } | |
| 249 | |
| 250 gfx::Rect WmWindowMus::ConvertRectFromScreen(const gfx::Rect& rect) const { | |
| 251 return gfx::Rect(ConvertPointFromScreen(rect.origin()), rect.size()); | |
| 252 } | |
| 253 | |
| 254 gfx::Size WmWindowMus::GetMinimumSize() const { | |
| 255 return widget_ ? widget_->GetMinimumSize() : gfx::Size(); | |
| 256 } | |
| 257 | |
| 258 gfx::Size WmWindowMus::GetMaximumSize() const { | |
| 259 return widget_ ? widget_->GetMaximumSize() : gfx::Size(); | |
| 260 } | |
| 261 | |
| 262 bool WmWindowMus::GetTargetVisibility() const { | |
| 263 // TODO: need animation support: http://crbug.com/615087. | |
| 264 NOTIMPLEMENTED(); | |
| 265 return window_->visible(); | |
| 266 } | |
| 267 | |
| 268 bool WmWindowMus::IsVisible() const { | |
| 269 return window_->visible(); | |
| 270 } | |
| 271 | |
| 272 void WmWindowMus::SetOpacity(float opacity) { | |
| 273 window_->SetOpacity(opacity); | |
| 274 } | |
| 275 | |
| 276 float WmWindowMus::GetTargetOpacity() const { | |
| 277 // TODO: need animation support: http://crbug.com/615087. | |
| 278 return window_->opacity(); | |
| 279 } | |
| 280 | |
| 281 void WmWindowMus::SetTransform(const gfx::Transform& transform) { | |
| 282 // TODO: mus needs to support transforms: http://crbug.com/615089. | |
| 283 NOTIMPLEMENTED(); | |
| 284 } | |
| 285 | |
| 286 gfx::Transform WmWindowMus::GetTargetTransform() const { | |
| 287 // TODO: need animation support: http://crbug.com/615087. | |
| 288 return gfx::Transform(); | |
| 289 } | |
| 290 | |
| 291 bool WmWindowMus::IsSystemModal() const { | |
| 292 NOTIMPLEMENTED(); | |
| 293 return false; | |
| 294 } | |
| 295 | |
| 296 bool WmWindowMus::GetBoolProperty(ash::wm::WmWindowProperty key) { | |
| 297 switch (key) { | |
| 298 case ash::wm::WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY: | |
| 299 return snap_children_to_pixel_boundary_; | |
| 300 | |
| 301 case ash::wm::WmWindowProperty::ALWAYS_ON_TOP: | |
| 302 return IsAlwaysOnTop(); | |
| 303 | |
| 304 default: | |
| 305 NOTREACHED(); | |
| 306 break; | |
| 307 } | |
| 308 | |
| 309 NOTREACHED(); | |
| 310 return false; | |
| 311 } | |
| 312 | |
| 313 int WmWindowMus::GetIntProperty(ash::wm::WmWindowProperty key) { | |
| 314 if (key == ash::wm::WmWindowProperty::SHELF_ID) { | |
| 315 NOTIMPLEMENTED(); | |
| 316 return 0; | |
| 317 } | |
| 318 | |
| 319 if (key == ash::wm::WmWindowProperty::TOP_VIEW_INSET) { | |
| 320 // TODO: need support for TOP_VIEW_INSET: http://crbug.com/615100. | |
| 321 NOTIMPLEMENTED(); | |
| 322 return 0; | |
| 323 } | |
| 324 | |
| 325 NOTREACHED(); | |
| 326 return 0; | |
| 327 } | |
| 328 | |
| 329 const ash::wm::WindowState* WmWindowMus::GetWindowState() const { | |
| 330 return window_state_.get(); | |
| 331 } | |
| 332 | |
| 333 ash::wm::WmWindow* WmWindowMus::GetToplevelWindow() { | |
| 334 return WmGlobalsMus::GetToplevelAncestor(window_); | |
| 335 } | |
| 336 | |
| 337 void WmWindowMus::SetParentUsingContext(WmWindow* context, | |
| 338 const gfx::Rect& screen_bounds) { | |
| 339 GetDefaultParent(context, this, screen_bounds)->AddChild(this); | |
| 340 } | |
| 341 | |
| 342 void WmWindowMus::AddChild(WmWindow* window) { | |
| 343 window_->AddChild(GetMusWindow(window)); | |
| 344 } | |
| 345 | |
| 346 ash::wm::WmWindow* WmWindowMus::GetParent() { | |
| 347 return Get(window_->parent()); | |
| 348 } | |
| 349 | |
| 350 const ash::wm::WmWindow* WmWindowMus::GetTransientParent() const { | |
| 351 return Get(window_->transient_parent()); | |
| 352 } | |
| 353 | |
| 354 std::vector<ash::wm::WmWindow*> WmWindowMus::GetTransientChildren() { | |
| 355 return FromMusWindows(window_->transient_children()); | |
| 356 } | |
| 357 | |
| 358 void WmWindowMus::SetLayoutManager( | |
| 359 std::unique_ptr<ash::wm::WmLayoutManager> layout_manager) { | |
| 360 if (layout_manager) { | |
| 361 layout_manager_adapter_.reset( | |
| 362 new MusLayoutManagerAdapter(window_, std::move(layout_manager))); | |
| 363 } else { | |
| 364 layout_manager_adapter_.reset(); | |
| 365 } | |
| 366 } | |
| 367 | |
| 368 ash::wm::WmLayoutManager* WmWindowMus::GetLayoutManager() { | |
| 369 return layout_manager_adapter_ ? layout_manager_adapter_->layout_manager() | |
| 370 : nullptr; | |
| 371 } | |
| 372 | |
| 373 void WmWindowMus::SetVisibilityAnimationType(int type) { | |
| 374 // TODO: need animation support: http://crbug.com/615087. | |
| 375 NOTIMPLEMENTED(); | |
| 376 } | |
| 377 | |
| 378 void WmWindowMus::SetVisibilityAnimationDuration(base::TimeDelta delta) { | |
| 379 // TODO: need animation support: http://crbug.com/615087. | |
| 380 NOTIMPLEMENTED(); | |
| 381 } | |
| 382 | |
| 383 void WmWindowMus::SetVisibilityAnimationTransition( | |
| 384 ::wm::WindowVisibilityAnimationTransition transition) { | |
| 385 // TODO: need animation support: http://crbug.com/615087. | |
| 386 NOTIMPLEMENTED(); | |
| 387 } | |
| 388 | |
| 389 void WmWindowMus::Animate(::wm::WindowAnimationType type) { | |
| 390 // TODO: need animation support: http://crbug.com/615087. | |
| 391 NOTIMPLEMENTED(); | |
| 392 } | |
| 393 | |
| 394 void WmWindowMus::StopAnimatingProperty( | |
| 395 ui::LayerAnimationElement::AnimatableProperty property) { | |
| 396 // TODO: need animation support: http://crbug.com/615087. | |
| 397 NOTIMPLEMENTED(); | |
| 398 } | |
| 399 | |
| 400 void WmWindowMus::SetChildWindowVisibilityChangesAnimated() { | |
| 401 // TODO: need animation support: http://crbug.com/615087. | |
| 402 NOTIMPLEMENTED(); | |
| 403 } | |
| 404 | |
| 405 void WmWindowMus::SetMasksToBounds(bool value) { | |
| 406 // TODO: mus needs mask to bounds support: http://crbug.com/615550. | |
| 407 NOTIMPLEMENTED(); | |
| 408 } | |
| 409 | |
| 410 void WmWindowMus::SetBounds(const gfx::Rect& bounds) { | |
| 411 if (window_->parent()) { | |
| 412 WmWindowMus* parent = WmWindowMus::Get(window_->parent()); | |
| 413 if (parent->layout_manager_adapter_) { | |
| 414 parent->layout_manager_adapter_->layout_manager()->SetChildBounds(this, | |
| 415 bounds); | |
| 416 return; | |
| 417 } | |
| 418 } | |
| 419 SetBoundsDirect(bounds); | |
| 420 } | |
| 421 | |
| 422 void WmWindowMus::SetBoundsWithTransitionDelay(const gfx::Rect& bounds, | |
| 423 base::TimeDelta delta) { | |
| 424 // TODO: need animation support: http://crbug.com/615087. | |
| 425 NOTIMPLEMENTED(); | |
| 426 SetBounds(bounds); | |
| 427 } | |
| 428 | |
| 429 void WmWindowMus::SetBoundsDirect(const gfx::Rect& bounds) { | |
| 430 window_->SetBounds(bounds); | |
| 431 SnapToPixelBoundaryIfNecessary(); | |
| 432 } | |
| 433 | |
| 434 void WmWindowMus::SetBoundsDirectAnimated(const gfx::Rect& bounds) { | |
| 435 // TODO: need animation support: http://crbug.com/615087. | |
| 436 NOTIMPLEMENTED(); | |
| 437 SetBoundsDirect(bounds); | |
| 438 } | |
| 439 | |
| 440 void WmWindowMus::SetBoundsDirectCrossFade(const gfx::Rect& bounds) { | |
| 441 // TODO: need animation support: http://crbug.com/615087. | |
| 442 NOTIMPLEMENTED(); | |
| 443 SetBoundsDirect(bounds); | |
| 444 } | |
| 445 | |
| 446 void WmWindowMus::SetBoundsInScreen(const gfx::Rect& bounds_in_screen, | |
| 447 const display::Display& dst_display) { | |
| 448 // TODO: SetBoundsInScreen isn't fully implemented yet, | |
| 449 // http://crbug.com/615552. | |
| 450 NOTIMPLEMENTED(); | |
| 451 SetBounds(ConvertRectFromScreen(bounds_in_screen)); | |
| 452 } | |
| 453 | |
| 454 gfx::Rect WmWindowMus::GetBoundsInScreen() const { | |
| 455 return ConvertRectToScreen(gfx::Rect(window_->bounds().size())); | |
| 456 } | |
| 457 | |
| 458 const gfx::Rect& WmWindowMus::GetBounds() const { | |
| 459 return window_->bounds(); | |
| 460 } | |
| 461 | |
| 462 gfx::Rect WmWindowMus::GetTargetBounds() { | |
| 463 // TODO: need animation support: http://crbug.com/615087. | |
| 464 NOTIMPLEMENTED(); | |
| 465 return window_->bounds(); | |
| 466 } | |
| 467 | |
| 468 void WmWindowMus::ClearRestoreBounds() { | |
| 469 restore_bounds_in_screen_.reset(); | |
| 470 } | |
| 471 | |
| 472 void WmWindowMus::SetRestoreBoundsInScreen(const gfx::Rect& bounds) { | |
| 473 restore_bounds_in_screen_.reset(new gfx::Rect(bounds)); | |
| 474 } | |
| 475 | |
| 476 gfx::Rect WmWindowMus::GetRestoreBoundsInScreen() const { | |
| 477 return *restore_bounds_in_screen_; | |
| 478 } | |
| 479 | |
| 480 bool WmWindowMus::Contains(const ash::wm::WmWindow* other) const { | |
| 481 return other | |
| 482 ? window_->Contains( | |
| 483 static_cast<const WmWindowMus*>(other)->window_) | |
| 484 : false; | |
| 485 } | |
| 486 | |
| 487 void WmWindowMus::SetShowState(ui::WindowShowState show_state) { | |
| 488 SetWindowShowState(window_, MojomWindowShowStateFromUI(show_state)); | |
| 489 } | |
| 490 | |
| 491 ui::WindowShowState WmWindowMus::GetShowState() const { | |
| 492 return UIWindowShowStateFromMojom(GetWindowShowState(window_)); | |
| 493 } | |
| 494 | |
| 495 void WmWindowMus::SetRestoreShowState(ui::WindowShowState show_state) { | |
| 496 restore_show_state_ = show_state; | |
| 497 } | |
| 498 | |
| 499 void WmWindowMus::SetLockedToRoot(bool value) { | |
| 500 // TODO(sky): there is no getter for this. Investigate where used. | |
| 501 NOTIMPLEMENTED(); | |
| 502 } | |
| 503 | |
| 504 void WmWindowMus::SetCapture() { | |
| 505 window_->SetCapture(); | |
| 506 } | |
| 507 | |
| 508 bool WmWindowMus::HasCapture() { | |
| 509 return window_->HasCapture(); | |
| 510 } | |
| 511 | |
| 512 void WmWindowMus::ReleaseCapture() { | |
| 513 window_->ReleaseCapture(); | |
| 514 } | |
| 515 | |
| 516 bool WmWindowMus::HasRestoreBounds() const { | |
| 517 return restore_bounds_in_screen_.get() != nullptr; | |
| 518 } | |
| 519 | |
| 520 bool WmWindowMus::CanMaximize() const { | |
| 521 return widget_ ? widget_->widget_delegate()->CanMaximize() : false; | |
| 522 } | |
| 523 | |
| 524 bool WmWindowMus::CanMinimize() const { | |
| 525 return widget_ ? widget_->widget_delegate()->CanMinimize() : false; | |
| 526 } | |
| 527 | |
| 528 bool WmWindowMus::CanResize() const { | |
| 529 return widget_ ? widget_->widget_delegate()->CanResize() : false; | |
| 530 } | |
| 531 | |
| 532 bool WmWindowMus::CanActivate() const { | |
| 533 // TODO(sky): this isn't quite right. Should key off CanFocus(), which is not | |
| 534 // replicated. | |
| 535 return widget_ != nullptr; | |
| 536 } | |
| 537 | |
| 538 void WmWindowMus::StackChildAtTop(ash::wm::WmWindow* child) { | |
| 539 GetMusWindow(child)->MoveToFront(); | |
| 540 } | |
| 541 | |
| 542 void WmWindowMus::StackChildAtBottom(ash::wm::WmWindow* child) { | |
| 543 GetMusWindow(child)->MoveToBack(); | |
| 544 } | |
| 545 | |
| 546 void WmWindowMus::StackChildAbove(ash::wm::WmWindow* child, | |
| 547 ash::wm::WmWindow* target) { | |
| 548 GetMusWindow(child)->Reorder(GetMusWindow(target), | |
| 549 mus::mojom::OrderDirection::ABOVE); | |
| 550 } | |
| 551 | |
| 552 void WmWindowMus::StackChildBelow(WmWindow* child, WmWindow* target) { | |
| 553 GetMusWindow(child)->Reorder(GetMusWindow(target), | |
| 554 mus::mojom::OrderDirection::BELOW); | |
| 555 } | |
| 556 | |
| 557 void WmWindowMus::SetAlwaysOnTop(bool value) { | |
| 558 mash::wm::SetAlwaysOnTop(window_, value); | |
| 559 } | |
| 560 | |
| 561 bool WmWindowMus::IsAlwaysOnTop() const { | |
| 562 return mash::wm::IsAlwaysOnTop(window_); | |
| 563 } | |
| 564 | |
| 565 void WmWindowMus::Hide() { | |
| 566 window_->SetVisible(false); | |
| 567 } | |
| 568 | |
| 569 void WmWindowMus::Show() { | |
| 570 window_->SetVisible(true); | |
| 571 } | |
| 572 | |
| 573 void WmWindowMus::CloseWidget() { | |
| 574 DCHECK(widget_); | |
| 575 // Allow the client to service the close request for remote widgets. | |
| 576 if (widget_creation_type_ == WidgetCreationType::FOR_CLIENT) | |
| 577 window_->RequestClose(); | |
| 578 else | |
| 579 widget_->Close(); | |
| 580 } | |
| 581 | |
| 582 bool WmWindowMus::IsFocused() const { | |
| 583 return window_->HasFocus(); | |
| 584 } | |
| 585 | |
| 586 bool WmWindowMus::IsActive() const { | |
| 587 mus::Window* focused = window_->window_tree()->GetFocusedWindow(); | |
| 588 return focused && window_->Contains(focused); | |
| 589 } | |
| 590 | |
| 591 void WmWindowMus::Activate() { | |
| 592 window_->SetFocus(); | |
| 593 ash::wm::WmWindow* top_level = GetToplevelWindow(); | |
| 594 if (!top_level) | |
| 595 return; | |
| 596 | |
| 597 // TODO(sky): mus should do this too. | |
| 598 GetMusWindow(top_level)->MoveToFront(); | |
| 599 } | |
| 600 | |
| 601 void WmWindowMus::Deactivate() { | |
| 602 if (IsActive()) | |
| 603 window_->window_tree()->ClearFocus(); | |
| 604 } | |
| 605 | |
| 606 void WmWindowMus::SetFullscreen() { | |
| 607 SetWindowShowState(window_, mus::mojom::ShowState::FULLSCREEN); | |
| 608 } | |
| 609 | |
| 610 void WmWindowMus::Maximize() { | |
| 611 SetWindowShowState(window_, mus::mojom::ShowState::MAXIMIZED); | |
| 612 } | |
| 613 | |
| 614 void WmWindowMus::Minimize() { | |
| 615 SetWindowShowState(window_, mus::mojom::ShowState::MINIMIZED); | |
| 616 } | |
| 617 | |
| 618 void WmWindowMus::Unminimize() { | |
| 619 SetWindowShowState(window_, MojomWindowShowStateFromUI(restore_show_state_)); | |
| 620 restore_show_state_ = ui::SHOW_STATE_DEFAULT; | |
| 621 } | |
| 622 | |
| 623 std::vector<ash::wm::WmWindow*> WmWindowMus::GetChildren() { | |
| 624 return FromMusWindows(window_->children()); | |
| 625 } | |
| 626 | |
| 627 ash::wm::WmWindow* WmWindowMus::GetChildByShellWindowId(int id) { | |
| 628 if (id == shell_window_id_) | |
| 629 return this; | |
| 630 for (mus::Window* child : window_->children()) { | |
| 631 ash::wm::WmWindow* result = Get(child)->GetChildByShellWindowId(id); | |
| 632 if (result) | |
| 633 return result; | |
| 634 } | |
| 635 return nullptr; | |
| 636 } | |
| 637 | |
| 638 void WmWindowMus::ShowResizeShadow(int component) { | |
| 639 NOTIMPLEMENTED(); | |
| 640 } | |
| 641 | |
| 642 void WmWindowMus::HideResizeShadow() { | |
| 643 NOTIMPLEMENTED(); | |
| 644 } | |
| 645 | |
| 646 void WmWindowMus::SetBoundsInScreenBehaviorForChildren( | |
| 647 ash::wm::WmWindow::BoundsInScreenBehavior behavior) { | |
| 648 // TODO: SetBoundsInScreen isn't fully implemented yet, | |
| 649 // http://crbug.com/615552. | |
| 650 NOTIMPLEMENTED(); | |
| 651 } | |
| 652 | |
| 653 void WmWindowMus::SetSnapsChildrenToPhysicalPixelBoundary() { | |
| 654 if (snap_children_to_pixel_boundary_) | |
| 655 return; | |
| 656 | |
| 657 snap_children_to_pixel_boundary_ = true; | |
| 658 FOR_EACH_OBSERVER( | |
| 659 ash::wm::WmWindowObserver, observers_, | |
| 660 OnWindowPropertyChanged( | |
| 661 this, ash::wm::WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); | |
| 662 } | |
| 663 | |
| 664 void WmWindowMus::SnapToPixelBoundaryIfNecessary() { | |
| 665 WmWindowMus* parent = Get(window_->parent()); | |
| 666 if (parent && parent->snap_children_to_pixel_boundary_) { | |
| 667 // TODO: implement snap to pixel: http://crbug.com/615554. | |
| 668 NOTIMPLEMENTED(); | |
| 669 } | |
| 670 } | |
| 671 | |
| 672 void WmWindowMus::SetChildrenUseExtendedHitRegion() { | |
| 673 children_use_extended_hit_region_ = true; | |
| 674 } | |
| 675 | |
| 676 void WmWindowMus::SetDescendantsStayInSameRootWindow(bool value) { | |
| 677 // TODO: this logic feeds into SetBoundsInScreen(), which is not implemented: | |
| 678 // http://crbug.com/615552. | |
| 679 NOTIMPLEMENTED(); | |
| 680 } | |
| 681 | |
| 682 void WmWindowMus::AddObserver(ash::wm::WmWindowObserver* observer) { | |
| 683 observers_.AddObserver(observer); | |
| 684 } | |
| 685 | |
| 686 void WmWindowMus::RemoveObserver(ash::wm::WmWindowObserver* observer) { | |
| 687 observers_.RemoveObserver(observer); | |
| 688 } | |
| 689 | |
| 690 void WmWindowMus::OnTreeChanged(const TreeChangeParams& params) { | |
| 691 ash::wm::WmWindowObserver::TreeChangeParams wm_params; | |
| 692 wm_params.target = Get(params.target); | |
| 693 wm_params.new_parent = Get(params.new_parent); | |
| 694 wm_params.old_parent = Get(params.old_parent); | |
| 695 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_, | |
| 696 OnWindowTreeChanged(this, wm_params)); | |
| 697 } | |
| 698 | |
| 699 void WmWindowMus::OnWindowReordered(mus::Window* window, | |
| 700 mus::Window* relative_window, | |
| 701 mus::mojom::OrderDirection direction) { | |
| 702 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_, | |
| 703 OnWindowStackingChanged(this)); | |
| 704 } | |
| 705 | |
| 706 void WmWindowMus::OnWindowSharedPropertyChanged( | |
| 707 mus::Window* window, | |
| 708 const std::string& name, | |
| 709 const std::vector<uint8_t>* old_data, | |
| 710 const std::vector<uint8_t>* new_data) { | |
| 711 if (name == mus::mojom::WindowManager::kShowState_Property) { | |
| 712 GetWindowState()->OnWindowShowStateChanged(); | |
| 713 return; | |
| 714 } | |
| 715 if (name == mus::mojom::WindowManager::kAlwaysOnTop_Property) { | |
| 716 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_, | |
| 717 OnWindowPropertyChanged( | |
| 718 this, ash::wm::WmWindowProperty::ALWAYS_ON_TOP)); | |
| 719 return; | |
| 720 } | |
| 721 | |
| 722 // Deal with snap to pixel. | |
| 723 NOTIMPLEMENTED(); | |
| 724 } | |
| 725 | |
| 726 void WmWindowMus::OnWindowBoundsChanged(mus::Window* window, | |
| 727 const gfx::Rect& old_bounds, | |
| 728 const gfx::Rect& new_bounds) { | |
| 729 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_, | |
| 730 OnWindowBoundsChanged(this, old_bounds, new_bounds)); | |
| 731 } | |
| 732 | |
| 733 void WmWindowMus::OnWindowDestroying(mus::Window* window) { | |
| 734 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_, | |
| 735 OnWindowDestroying(this)); | |
| 736 } | |
| 737 | |
| 738 } // namespace wm | |
| 739 } // namespace mash | |
| OLD | NEW |