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 "mash/simple_wm/simple_wm.h" | 5 #include "mash/simple_wm/simple_wm.h" |
| 6 | 6 |
| 7 #include "base/observer_list.h" | 7 #include "base/observer_list.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "mash/simple_wm/move_event_handler.h" | 9 #include "mash/simple_wm/move_event_handler.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/aura/layout_manager.h" | 11 #include "ui/aura/layout_manager.h" |
| 12 #include "ui/display/screen_base.h" | 12 #include "ui/display/screen_base.h" |
| 13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/geometry/mojo/geometry.mojom.h" | 14 #include "ui/gfx/geometry/mojo/geometry.mojom.h" |
| 15 #include "ui/views/controls/button/md_text_button.h" | 15 #include "ui/views/controls/button/md_text_button.h" |
| 16 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
| 17 #include "ui/views/mus/aura_init.h" | 17 #include "ui/views/mus/aura_init.h" |
| 18 #include "ui/views/mus/mus_client.h" | 18 #include "ui/views/mus/mus_client.h" |
| 19 #include "ui/views/widget/native_widget_aura.h" | 19 #include "ui/views/widget/native_widget_aura.h" |
| 20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/widget/widget_delegate.h" | 21 #include "ui/views/widget/widget_delegate.h" |
| 22 #include "ui/wm/core/default_activation_client.h" | 22 #include "ui/wm/core/focus_controller.h" |
| 23 | 23 |
| 24 namespace simple_wm { | 24 namespace simple_wm { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const int kNonClientTopHeight = 24; | 28 const int kNonClientTopHeight = 24; |
| 29 const int kNonClientSize = 5; | 29 const int kNonClientSize = 5; |
| 30 const int kNonClientMaximizedTopOverlap = 4; | 30 const int kNonClientMaximizedTopOverlap = 4; |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 window_list_view_->GetWidget()->SetBounds(window_list_view_bounds); | 334 window_list_view_->GetWidget()->SetBounds(window_list_view_bounds); |
| 335 } | 335 } |
| 336 | 336 |
| 337 aura::Window* display_root_; | 337 aura::Window* display_root_; |
| 338 aura::Window* window_root_; | 338 aura::Window* window_root_; |
| 339 SimpleWM::WindowListView* window_list_view_; | 339 SimpleWM::WindowListView* window_list_view_; |
| 340 | 340 |
| 341 DISALLOW_COPY_AND_ASSIGN(DisplayLayoutManager); | 341 DISALLOW_COPY_AND_ASSIGN(DisplayLayoutManager); |
| 342 }; | 342 }; |
| 343 | 343 |
| 344 //////////////////////////////////////////////////////////////////////////////// | |
| 345 // SimpleWM, public: | |
| 346 | |
| 344 SimpleWM::SimpleWM() {} | 347 SimpleWM::SimpleWM() {} |
| 345 | 348 |
| 346 SimpleWM::~SimpleWM() { | 349 SimpleWM::~SimpleWM() { |
| 347 // WindowTreeHost uses state from WindowTreeClient, so destroy it first. | 350 // WindowTreeHost uses state from WindowTreeClient, so destroy it first. |
| 348 window_tree_host_.reset(); | 351 window_tree_host_.reset(); |
| 349 | 352 |
| 350 // WindowTreeClient destruction may callback to us. | 353 // WindowTreeClient destruction may callback to us. |
| 351 window_tree_client_.reset(); | 354 window_tree_client_.reset(); |
| 352 | 355 |
| 353 gpu_.reset(); | 356 gpu_.reset(); |
| 354 | 357 |
| 355 display::Screen::SetScreenInstance(nullptr); | 358 display::Screen::SetScreenInstance(nullptr); |
| 356 } | 359 } |
| 357 | 360 |
| 361 //////////////////////////////////////////////////////////////////////////////// | |
| 362 // SimpleWM, service_manager::Service implementation: | |
| 363 | |
| 358 void SimpleWM::OnStart() { | 364 void SimpleWM::OnStart() { |
| 359 CHECK(!started_); | 365 CHECK(!started_); |
| 360 started_ = true; | 366 started_ = true; |
| 361 screen_ = base::MakeUnique<display::ScreenBase>(); | 367 screen_ = base::MakeUnique<display::ScreenBase>(); |
| 362 display::Screen::SetScreenInstance(screen_.get()); | 368 display::Screen::SetScreenInstance(screen_.get()); |
| 363 aura_init_ = base::MakeUnique<views::AuraInit>( | 369 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 364 context()->connector(), context()->identity(), "views_mus_resources.pak", | 370 context()->connector(), context()->identity(), "views_mus_resources.pak", |
| 365 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER); | 371 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER); |
| 366 gpu_ = ui::Gpu::Create(context()->connector(), nullptr); | 372 gpu_ = ui::Gpu::Create(context()->connector(), nullptr); |
| 367 compositor_context_factory_ = | 373 compositor_context_factory_ = |
| 368 base::MakeUnique<aura::MusContextFactory>(gpu_.get()); | 374 base::MakeUnique<aura::MusContextFactory>(gpu_.get()); |
| 369 aura::Env::GetInstance()->set_context_factory( | 375 aura::Env::GetInstance()->set_context_factory( |
| 370 compositor_context_factory_.get()); | 376 compositor_context_factory_.get()); |
| 371 window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>( | 377 window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>( |
| 372 context()->connector(), this, this); | 378 context()->connector(), this, this); |
| 373 aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client_.get()); | 379 aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client_.get()); |
| 374 window_tree_client_->ConnectAsWindowManager(); | 380 window_tree_client_->ConnectAsWindowManager(); |
| 375 } | 381 } |
| 376 | 382 |
| 377 bool SimpleWM::OnConnect( | 383 bool SimpleWM::OnConnect( |
| 378 const service_manager::ServiceInfo& remote_info, | 384 const service_manager::ServiceInfo& remote_info, |
| 379 service_manager::InterfaceRegistry* registry) { | 385 service_manager::InterfaceRegistry* registry) { |
| 380 return true; | 386 return true; |
| 381 } | 387 } |
| 382 | 388 |
| 389 //////////////////////////////////////////////////////////////////////////////// | |
| 390 // SimpleWM, aura::WindowTreeClientDelegate implementation: | |
| 391 | |
| 383 void SimpleWM::OnEmbed( | 392 void SimpleWM::OnEmbed( |
| 384 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | 393 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 385 // WindowTreeClients configured as the window manager should never get | 394 // WindowTreeClients configured as the window manager should never get |
| 386 // OnEmbed(). | 395 // OnEmbed(). |
| 387 NOTREACHED(); | 396 NOTREACHED(); |
| 388 } | 397 } |
| 389 | 398 |
| 390 void SimpleWM::OnLostConnection(aura::WindowTreeClient* client) { | 399 void SimpleWM::OnLostConnection(aura::WindowTreeClient* client) { |
| 391 window_tree_host_.reset(); | 400 window_tree_host_.reset(); |
| 392 window_tree_client_.reset(); | 401 window_tree_client_.reset(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 404 } | 413 } |
| 405 | 414 |
| 406 aura::client::CaptureClient* SimpleWM::GetCaptureClient() { | 415 aura::client::CaptureClient* SimpleWM::GetCaptureClient() { |
| 407 return wm_state_.capture_controller(); | 416 return wm_state_.capture_controller(); |
| 408 } | 417 } |
| 409 | 418 |
| 410 aura::PropertyConverter* SimpleWM::GetPropertyConverter() { | 419 aura::PropertyConverter* SimpleWM::GetPropertyConverter() { |
| 411 return &property_converter_; | 420 return &property_converter_; |
| 412 } | 421 } |
| 413 | 422 |
| 423 //////////////////////////////////////////////////////////////////////////////// | |
| 424 // SimpleWM, aura::WindowManagerDelegate implementation: | |
| 425 | |
| 414 void SimpleWM::SetWindowManagerClient( | 426 void SimpleWM::SetWindowManagerClient( |
| 415 aura::WindowManagerClient* client) { | 427 aura::WindowManagerClient* client) { |
| 416 window_manager_client_ = client; | 428 window_manager_client_ = client; |
| 417 } | 429 } |
| 418 | 430 |
| 419 bool SimpleWM::OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) { | 431 bool SimpleWM::OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) { |
| 420 FrameView* frame_view = GetFrameViewForClientWindow(window); | 432 FrameView* frame_view = GetFrameViewForClientWindow(window); |
| 421 frame_view->GetWidget()->SetBounds(*bounds); | 433 frame_view->GetWidget()->SetBounds(*bounds); |
| 422 return false; | 434 return false; |
| 423 } | 435 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 | 520 |
| 509 DCHECK(window_manager_client_); | 521 DCHECK(window_manager_client_); |
| 510 window_manager_client_->AddActivationParent(window_root_); | 522 window_manager_client_->AddActivationParent(window_root_); |
| 511 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = | 523 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 512 ui::mojom::FrameDecorationValues::New(); | 524 ui::mojom::FrameDecorationValues::New(); |
| 513 frame_decoration_values->normal_client_area_insets.Set( | 525 frame_decoration_values->normal_client_area_insets.Set( |
| 514 kNonClientTopHeight, kNonClientSize, kNonClientSize, kNonClientSize); | 526 kNonClientTopHeight, kNonClientSize, kNonClientSize, kNonClientSize); |
| 515 frame_decoration_values->max_title_bar_button_width = 0; | 527 frame_decoration_values->max_title_bar_button_width = 0; |
| 516 window_manager_client_->SetFrameDecorationValues( | 528 window_manager_client_->SetFrameDecorationValues( |
| 517 std::move(frame_decoration_values)); | 529 std::move(frame_decoration_values)); |
| 518 new wm::DefaultActivationClient(display_root_); | 530 focus_controller_ = base::MakeUnique<wm::FocusController>(this); |
| 519 aura::client::SetFocusClient(display_root_, &focus_client_); | 531 aura::client::SetFocusClient(display_root_, focus_controller_.get()); |
| 532 aura::client::SetActivationClient(display_root_, focus_controller_.get()); | |
| 533 display_root_->AddPreTargetHandler(focus_controller_.get()); | |
| 520 } | 534 } |
| 521 | 535 |
| 522 void SimpleWM::OnWmDisplayRemoved( | 536 void SimpleWM::OnWmDisplayRemoved( |
| 523 aura::WindowTreeHostMus* window_tree_host) { | 537 aura::WindowTreeHostMus* window_tree_host) { |
| 524 DCHECK_EQ(window_tree_host, window_tree_host_.get()); | 538 DCHECK_EQ(window_tree_host, window_tree_host_.get()); |
| 525 window_root_ = nullptr; | 539 window_root_ = nullptr; |
| 526 window_tree_host_.reset(); | 540 window_tree_host_.reset(); |
| 527 } | 541 } |
| 528 | 542 |
| 529 void SimpleWM::OnWmDisplayModified(const display::Display& display) {} | 543 void SimpleWM::OnWmDisplayModified(const display::Display& display) {} |
| 530 | 544 |
| 531 void SimpleWM::OnWmPerformMoveLoop( | 545 void SimpleWM::OnWmPerformMoveLoop( |
| 532 aura::Window* window, | 546 aura::Window* window, |
| 533 ui::mojom::MoveLoopSource source, | 547 ui::mojom::MoveLoopSource source, |
| 534 const gfx::Point& cursor_location, | 548 const gfx::Point& cursor_location, |
| 535 const base::Callback<void(bool)>& on_done) { | 549 const base::Callback<void(bool)>& on_done) { |
| 536 // Don't care. | 550 // Don't care. |
| 537 } | 551 } |
| 538 | 552 |
| 539 void SimpleWM::OnWmCancelMoveLoop(aura::Window* window) {} | 553 void SimpleWM::OnWmCancelMoveLoop(aura::Window* window) {} |
| 540 | 554 |
| 541 void SimpleWM::OnWmSetClientArea( | 555 void SimpleWM::OnWmSetClientArea( |
| 542 aura::Window* window, | 556 aura::Window* window, |
| 543 const gfx::Insets& insets, | 557 const gfx::Insets& insets, |
| 544 const std::vector<gfx::Rect>& additional_client_areas) {} | 558 const std::vector<gfx::Rect>& additional_client_areas) {} |
| 545 | 559 |
| 560 //////////////////////////////////////////////////////////////////////////////// | |
| 561 // SimpleWM, wm::BaseFocusRules implementation: | |
| 562 | |
| 563 bool SimpleWM::SupportsChildActivation(aura::Window* window) const { | |
| 564 return window == window_root_; | |
|
sky
2017/01/03 23:52:34
Shouldn't you only return true if window is in cli
Ben Goodger (Google)
2017/01/03 23:54:40
The window passed to this function is the parent o
sky
2017/01/04 00:09:58
Ah, got it.
| |
| 565 } | |
| 566 | |
| 567 bool SimpleWM::IsWindowConsideredVisibleForActivation( | |
| 568 aura::Window* window) const { | |
| 569 if (window->IsVisible()) | |
| 570 return true; | |
| 571 | |
| 572 ui::WindowShowState show_state = | |
| 573 window->GetProperty(aura::client::kShowStateKey); | |
| 574 if (show_state == ui::SHOW_STATE_MINIMIZED) | |
| 575 return true; | |
| 576 | |
| 577 return window->TargetVisibility(); | |
| 578 } | |
| 579 | |
| 580 //////////////////////////////////////////////////////////////////////////////// | |
| 581 // SimpleWM, private: | |
| 582 | |
| 546 SimpleWM::FrameView* SimpleWM::GetFrameViewForClientWindow( | 583 SimpleWM::FrameView* SimpleWM::GetFrameViewForClientWindow( |
| 547 aura::Window* client_window) { | 584 aura::Window* client_window) { |
| 548 auto it = client_window_to_frame_view_.find(client_window); | 585 auto it = client_window_to_frame_view_.find(client_window); |
| 549 return it != client_window_to_frame_view_.end() ? it->second : nullptr; | 586 return it != client_window_to_frame_view_.end() ? it->second : nullptr; |
| 550 } | 587 } |
| 551 | 588 |
| 552 void SimpleWM::OnWindowListViewItemActivated(aura::Window* window) { | 589 void SimpleWM::OnWindowListViewItemActivated(aura::Window* window) { |
| 553 window->Show(); | 590 window->Show(); |
| 554 aura::client::ActivationClient* activation_client = | 591 aura::client::ActivationClient* activation_client = |
| 555 aura::client::GetActivationClient(window->GetRootWindow()); | 592 aura::client::GetActivationClient(window->GetRootWindow()); |
| 556 activation_client->ActivateWindow(window); | 593 activation_client->ActivateWindow(window); |
| 557 } | 594 } |
| 558 | 595 |
| 559 } // namespace simple_wm | 596 } // namespace simple_wm |
| OLD | NEW |