wm_test_helper.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2013 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. #include "ui/wm/test/wm_test_helper.h"
  5. #include <memory>
  6. #include <utility>
  7. #include "base/memory/ptr_util.h"
  8. #include "build/build_config.h"
  9. #include "ui/aura/client/default_capture_client.h"
  10. #include "ui/aura/test/test_focus_client.h"
  11. #include "ui/aura/test/test_screen.h"
  12. #include "ui/aura/window.h"
  13. #include "ui/platform_window/platform_window_init_properties.h"
  14. #include "ui/wm/core/compound_event_filter.h"
  15. #include "ui/wm/core/default_activation_client.h"
  16. #include "ui/wm/core/wm_state.h"
  17. namespace wm {
  18. WMTestHelper::WMTestHelper(const gfx::Size& default_window_size) {
  19. wm_state_ = std::make_unique<WMState>();
  20. if (!display::Screen::HasScreen()) {
  21. test_screen_ = base::WrapUnique(aura::TestScreen::Create(gfx::Size()));
  22. display::Screen::SetScreenInstance(test_screen_.get());
  23. }
  24. host_ = aura::WindowTreeHost::Create(
  25. ui::PlatformWindowInitProperties{gfx::Rect(default_window_size)});
  26. host_->InitHost();
  27. aura::client::SetWindowParentingClient(host_->window(), this);
  28. focus_client_ =
  29. std::make_unique<aura::test::TestFocusClient>(host_->window());
  30. root_window_event_filter_ = std::make_unique<wm::CompoundEventFilter>();
  31. host_->window()->AddPreTargetHandler(root_window_event_filter_.get());
  32. new wm::DefaultActivationClient(host_->window());
  33. capture_client_ =
  34. std::make_unique<aura::client::DefaultCaptureClient>(host_->window());
  35. }
  36. WMTestHelper::~WMTestHelper() {
  37. host_->window()->RemovePreTargetHandler(root_window_event_filter_.get());
  38. if (test_screen_)
  39. display::Screen::SetScreenInstance(nullptr);
  40. }
  41. aura::Window* WMTestHelper::GetDefaultParent(aura::Window* window,
  42. const gfx::Rect& bounds) {
  43. return host_->window();
  44. }
  45. } // namespace wm