Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(715)

Side by Side Diff: mash/wm/bridge/wm_window_mus.cc

Issue 1984293002: Random fixes for mash bridge classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mash/wm/bridge/wm_window_mus.h ('k') | mash/wm/container_ids.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mash/wm/bridge/wm_window_mus.h" 5 #include "mash/wm/bridge/wm_window_mus.h"
6 6
7 #include "ash/wm/common/container_finder.h" 7 #include "ash/wm/common/container_finder.h"
8 #include "ash/wm/common/window_state.h" 8 #include "ash/wm/common/window_state.h"
9 #include "ash/wm/common/wm_layout_manager.h" 9 #include "ash/wm/common/wm_layout_manager.h"
10 #include "ash/wm/common/wm_window_observer.h" 10 #include "ash/wm/common/wm_window_observer.h"
(...skipping 12 matching lines...) Expand all
23 #include "ui/views/widget/widget_delegate.h" 23 #include "ui/views/widget/widget_delegate.h"
24 24
25 MUS_DECLARE_WINDOW_PROPERTY_TYPE(mash::wm::WmWindowMus*); 25 MUS_DECLARE_WINDOW_PROPERTY_TYPE(mash::wm::WmWindowMus*);
26 26
27 namespace mash { 27 namespace mash {
28 namespace wm { 28 namespace wm {
29 29
30 MUS_DEFINE_OWNED_WINDOW_PROPERTY_KEY(mash::wm::WmWindowMus, 30 MUS_DEFINE_OWNED_WINDOW_PROPERTY_KEY(mash::wm::WmWindowMus,
31 kWmWindowKey, 31 kWmWindowKey,
32 nullptr); 32 nullptr);
33 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(int, kShellWindowIdKey, -1);
34
35 namespace { 33 namespace {
36 34
37 mus::Window* GetMusWindowByShellId(mus::Window* window, int id) {
38 if (window->GetLocalProperty(kShellWindowIdKey) == id)
39 return window;
40
41 for (mus::Window* child : window->children()) {
42 mus::Window* result = GetMusWindowByShellId(child, id);
43 if (result)
44 return result;
45 }
46 return nullptr;
47 }
48
49 // This classes is used so that the WindowState constructor can be made 35 // This classes is used so that the WindowState constructor can be made
50 // protected. GetWindowState() is the only place that should be creating 36 // protected. GetWindowState() is the only place that should be creating
51 // WindowState. 37 // WindowState.
52 class WindowStateMus : public ash::wm::WindowState { 38 class WindowStateMus : public ash::wm::WindowState {
53 public: 39 public:
54 explicit WindowStateMus(ash::wm::WmWindow* window) 40 explicit WindowStateMus(ash::wm::WmWindow* window)
55 : ash::wm::WindowState(window) {} 41 : ash::wm::WindowState(window) {}
56 ~WindowStateMus() override {} 42 ~WindowStateMus() override {}
57 43
58 private: 44 private:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 144
159 ash::wm::WmRootWindowController* WmWindowMus::GetRootWindowController() { 145 ash::wm::WmRootWindowController* WmWindowMus::GetRootWindowController() {
160 return GetRootWindowControllerMus(); 146 return GetRootWindowControllerMus();
161 } 147 }
162 148
163 ash::wm::WmGlobals* WmWindowMus::GetGlobals() const { 149 ash::wm::WmGlobals* WmWindowMus::GetGlobals() const {
164 return WmGlobalsMus::Get(); 150 return WmGlobalsMus::Get();
165 } 151 }
166 152
167 void WmWindowMus::SetShellWindowId(int id) { 153 void WmWindowMus::SetShellWindowId(int id) {
168 window_->set_local_id(id); 154 shell_window_id_ = id;
169 } 155 }
170 156
171 int WmWindowMus::GetShellWindowId() const { 157 int WmWindowMus::GetShellWindowId() const {
172 return window_->local_id(); 158 return shell_window_id_;
173 } 159 }
174 160
175 ui::wm::WindowType WmWindowMus::GetType() const { 161 ui::wm::WindowType WmWindowMus::GetType() const {
176 return GetWmWindowType(window_); 162 return GetWmWindowType(window_);
177 } 163 }
178 164
179 ui::Layer* WmWindowMus::GetLayer() { 165 ui::Layer* WmWindowMus::GetLayer() {
180 // TODO(sky): this function should be nuked entirely. 166 // TODO(sky): this function should be nuked entirely.
181 NOTIMPLEMENTED(); 167 NOTIMPLEMENTED();
182 return widget_ ? widget_->GetLayer() : nullptr; 168 return widget_ ? widget_->GetLayer() : nullptr;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 322
337 void WmWindowMus::SetVisibilityAnimationDuration(base::TimeDelta delta) { 323 void WmWindowMus::SetVisibilityAnimationDuration(base::TimeDelta delta) {
338 NOTIMPLEMENTED(); 324 NOTIMPLEMENTED();
339 } 325 }
340 326
341 void WmWindowMus::Animate(::wm::WindowAnimationType type) { 327 void WmWindowMus::Animate(::wm::WindowAnimationType type) {
342 NOTIMPLEMENTED(); 328 NOTIMPLEMENTED();
343 } 329 }
344 330
345 void WmWindowMus::SetBounds(const gfx::Rect& bounds) { 331 void WmWindowMus::SetBounds(const gfx::Rect& bounds) {
346 if (layout_manager_adapter_) 332 if (window_->parent()) {
347 layout_manager_adapter_->layout_manager()->SetChildBounds(this, bounds); 333 WmWindowMus* parent = WmWindowMus::Get(window_->parent());
348 else 334 if (parent->layout_manager_adapter_) {
349 window_->SetBounds(bounds); 335 parent->layout_manager_adapter_->layout_manager()->SetChildBounds(this,
336 bounds);
337 return;
338 }
339 }
340 SetBoundsDirect(bounds);
350 } 341 }
351 342
352 void WmWindowMus::SetBoundsWithTransitionDelay(const gfx::Rect& bounds, 343 void WmWindowMus::SetBoundsWithTransitionDelay(const gfx::Rect& bounds,
353 base::TimeDelta delta) { 344 base::TimeDelta delta) {
354 NOTIMPLEMENTED(); 345 NOTIMPLEMENTED();
355 SetBounds(bounds); 346 SetBounds(bounds);
356 } 347 }
357 348
358 void WmWindowMus::SetBoundsDirect(const gfx::Rect& bounds) { 349 void WmWindowMus::SetBoundsDirect(const gfx::Rect& bounds) {
359 window_->SetBounds(bounds); 350 window_->SetBounds(bounds);
(...skipping 12 matching lines...) Expand all
372 363
373 void WmWindowMus::SetBoundsInScreen(const gfx::Rect& bounds_in_screen, 364 void WmWindowMus::SetBoundsInScreen(const gfx::Rect& bounds_in_screen,
374 const display::Display& dst_display) { 365 const display::Display& dst_display) {
375 // TODO(sky): need to find WmRootWindowControllerMus for dst_display and 366 // TODO(sky): need to find WmRootWindowControllerMus for dst_display and
376 // convert. 367 // convert.
377 NOTIMPLEMENTED(); 368 NOTIMPLEMENTED();
378 SetBounds(ConvertRectFromScreen(bounds_in_screen)); 369 SetBounds(ConvertRectFromScreen(bounds_in_screen));
379 } 370 }
380 371
381 gfx::Rect WmWindowMus::GetBoundsInScreen() const { 372 gfx::Rect WmWindowMus::GetBoundsInScreen() const {
382 return ConvertRectToScreen(window_->bounds()); 373 return ConvertRectToScreen(gfx::Rect(window_->bounds().size()));
383 } 374 }
384 375
385 const gfx::Rect& WmWindowMus::GetBounds() const { 376 const gfx::Rect& WmWindowMus::GetBounds() const {
386 return window_->bounds(); 377 return window_->bounds();
387 } 378 }
388 379
389 gfx::Rect WmWindowMus::GetTargetBounds() { 380 gfx::Rect WmWindowMus::GetTargetBounds() {
390 NOTIMPLEMENTED(); 381 NOTIMPLEMENTED();
391 return window_->bounds(); 382 return window_->bounds();
392 } 383 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 return window_->HasFocus(); 494 return window_->HasFocus();
504 } 495 }
505 496
506 bool WmWindowMus::IsActive() const { 497 bool WmWindowMus::IsActive() const {
507 mus::Window* focused = window_->connection()->GetFocusedWindow(); 498 mus::Window* focused = window_->connection()->GetFocusedWindow();
508 return focused && window_->Contains(focused); 499 return focused && window_->Contains(focused);
509 } 500 }
510 501
511 void WmWindowMus::Activate() { 502 void WmWindowMus::Activate() {
512 window_->SetFocus(); 503 window_->SetFocus();
504 ash::wm::WmWindow* top_level = GetToplevelWindow();
505 if (!top_level)
506 return;
507
508 // TODO(sky): mus should do this too.
509 GetMusWindow(top_level)->MoveToFront();
513 } 510 }
514 511
515 void WmWindowMus::Deactivate() { 512 void WmWindowMus::Deactivate() {
516 if (IsActive()) 513 if (IsActive())
517 window_->connection()->ClearFocus(); 514 window_->connection()->ClearFocus();
518 } 515 }
519 516
520 void WmWindowMus::SetFullscreen() { 517 void WmWindowMus::SetFullscreen() {
521 SetWindowShowState(window_, mus::mojom::ShowState::FULLSCREEN); 518 SetWindowShowState(window_, mus::mojom::ShowState::FULLSCREEN);
522 } 519 }
523 520
524 void WmWindowMus::Maximize() { 521 void WmWindowMus::Maximize() {
525 SetWindowShowState(window_, mus::mojom::ShowState::MAXIMIZED); 522 SetWindowShowState(window_, mus::mojom::ShowState::MAXIMIZED);
526 } 523 }
527 524
528 void WmWindowMus::Minimize() { 525 void WmWindowMus::Minimize() {
529 SetWindowShowState(window_, mus::mojom::ShowState::MINIMIZED); 526 SetWindowShowState(window_, mus::mojom::ShowState::MINIMIZED);
530 } 527 }
531 528
532 void WmWindowMus::Unminimize() { 529 void WmWindowMus::Unminimize() {
533 SetWindowShowState(window_, MojomWindowShowStateFromUI(restore_show_state_)); 530 SetWindowShowState(window_, MojomWindowShowStateFromUI(restore_show_state_));
534 restore_show_state_ = ui::SHOW_STATE_DEFAULT; 531 restore_show_state_ = ui::SHOW_STATE_DEFAULT;
535 } 532 }
536 533
537 std::vector<ash::wm::WmWindow*> WmWindowMus::GetChildren() { 534 std::vector<ash::wm::WmWindow*> WmWindowMus::GetChildren() {
538 return FromMusWindows(window_->children()); 535 return FromMusWindows(window_->children());
539 } 536 }
540 537
541 ash::wm::WmWindow* WmWindowMus::GetChildByShellWindowId(int id) { 538 ash::wm::WmWindow* WmWindowMus::GetChildByShellWindowId(int id) {
542 return Get(GetMusWindowByShellId(window_, id)); 539 if (id == shell_window_id_)
540 return this;
541 for (mus::Window* child : window_->children()) {
542 ash::wm::WmWindow* result = Get(child)->GetChildByShellWindowId(id);
543 if (result)
544 return result;
545 }
546 return nullptr;
543 } 547 }
544 548
545 void WmWindowMus::SnapToPixelBoundaryIfNecessary() { 549 void WmWindowMus::SnapToPixelBoundaryIfNecessary() {
546 NOTIMPLEMENTED(); 550 NOTIMPLEMENTED();
547 } 551 }
548 552
549 void WmWindowMus::AddObserver(ash::wm::WmWindowObserver* observer) { 553 void WmWindowMus::AddObserver(ash::wm::WmWindowObserver* observer) {
550 observers_.AddObserver(observer); 554 observers_.AddObserver(observer);
551 } 555 }
552 556
553 void WmWindowMus::RemoveObserver(ash::wm::WmWindowObserver* observer) { 557 void WmWindowMus::RemoveObserver(ash::wm::WmWindowObserver* observer) {
554 observers_.RemoveObserver(observer); 558 observers_.RemoveObserver(observer);
555 } 559 }
556 560
557 void WmWindowMus::NotifyStackingChanged() {
558 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_,
559 OnWindowStackingChanged(this));
560 }
561
562 void WmWindowMus::OnTreeChanged(const TreeChangeParams& params) { 561 void WmWindowMus::OnTreeChanged(const TreeChangeParams& params) {
563 ash::wm::WmWindowObserver::TreeChangeParams wm_params; 562 ash::wm::WmWindowObserver::TreeChangeParams wm_params;
564 wm_params.target = Get(params.target); 563 wm_params.target = Get(params.target);
565 wm_params.new_parent = Get(params.new_parent); 564 wm_params.new_parent = Get(params.new_parent);
566 wm_params.old_parent = Get(params.old_parent); 565 wm_params.old_parent = Get(params.old_parent);
567 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_, 566 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_,
568 OnWindowTreeChanged(this, wm_params)); 567 OnWindowTreeChanged(this, wm_params));
569 } 568 }
570 569
571 void WmWindowMus::OnWindowReordered(mus::Window* window, 570 void WmWindowMus::OnWindowReordered(mus::Window* window,
572 mus::Window* relative_window, 571 mus::Window* relative_window,
573 mus::mojom::OrderDirection direction) { 572 mus::mojom::OrderDirection direction) {
574 if (!window_->parent()) 573 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_,
575 return; 574 OnWindowStackingChanged(this));
576
577 static_cast<WmWindowMus*>(Get(window_->parent()))->NotifyStackingChanged();
578 } 575 }
579 576
580 void WmWindowMus::OnWindowSharedPropertyChanged( 577 void WmWindowMus::OnWindowSharedPropertyChanged(
581 mus::Window* window, 578 mus::Window* window,
582 const std::string& name, 579 const std::string& name,
583 const std::vector<uint8_t>* old_data, 580 const std::vector<uint8_t>* old_data,
584 const std::vector<uint8_t>* new_data) { 581 const std::vector<uint8_t>* new_data) {
582 if (name == mus::mojom::WindowManager::kShowState_Property)
583 GetWindowState()->OnWindowShowStateChanged();
584
585 // Deal with always on top and snap. 585 // Deal with always on top and snap.
586 NOTIMPLEMENTED(); 586 NOTIMPLEMENTED();
587 } 587 }
588 588
589 void WmWindowMus::OnWindowBoundsChanged(mus::Window* window, 589 void WmWindowMus::OnWindowBoundsChanged(mus::Window* window,
590 const gfx::Rect& old_bounds, 590 const gfx::Rect& old_bounds,
591 const gfx::Rect& new_bounds) { 591 const gfx::Rect& new_bounds) {
592 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_, 592 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_,
593 OnWindowBoundsChanged(this, old_bounds, new_bounds)); 593 OnWindowBoundsChanged(this, old_bounds, new_bounds));
594 } 594 }
595 595
596 void WmWindowMus::OnWindowDestroying(mus::Window* window) { 596 void WmWindowMus::OnWindowDestroying(mus::Window* window) {
597 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_, 597 FOR_EACH_OBSERVER(ash::wm::WmWindowObserver, observers_,
598 OnWindowDestroying(this)); 598 OnWindowDestroying(this));
599 } 599 }
600 600
601 } // namespace wm 601 } // namespace wm
602 } // namespace mash 602 } // namespace mash
OLDNEW
« no previous file with comments | « mash/wm/bridge/wm_window_mus.h ('k') | mash/wm/container_ids.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698