shell_screen.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2014 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 "extensions/shell/browser/shell_screen.h"
  5. #include <stdint.h>
  6. #include <vector>
  7. #include "base/check.h"
  8. #include "extensions/shell/browser/root_window_controller.h"
  9. #include "extensions/shell/browser/shell_desktop_controller_aura.h"
  10. #include "ui/aura/env.h"
  11. #include "ui/aura/window.h"
  12. #include "ui/aura/window_tree_host.h"
  13. #include "ui/display/display.h"
  14. #include "ui/gfx/geometry/rect.h"
  15. #include "ui/gfx/geometry/size.h"
  16. #include "ui/gfx/native_widget_types.h"
  17. namespace extensions {
  18. namespace {
  19. const int64_t kDisplayId = 0;
  20. } // namespace
  21. ShellScreen::ShellScreen(ShellDesktopControllerAura* desktop_controller,
  22. const gfx::Size& size)
  23. : desktop_controller_(desktop_controller) {
  24. DCHECK(!size.IsEmpty());
  25. // Screen is positioned at (0,0).
  26. display::Display display(kDisplayId);
  27. gfx::Rect bounds(size);
  28. display.SetScaleAndBounds(1.0f, bounds);
  29. ProcessDisplayChanged(display, true /* is_primary */);
  30. }
  31. ShellScreen::~ShellScreen() {
  32. DCHECK(!desktop_controller_ || !desktop_controller_->GetPrimaryHost())
  33. << "WindowTreeHost not closed before destroying ShellScreen";
  34. }
  35. void ShellScreen::OnHostResized(aura::WindowTreeHost* host) {
  36. // Based on ash::WindowTreeHostManager.
  37. display::Display display = GetDisplayNearestWindow(host->window());
  38. display.SetSize(host->GetBoundsInPixels().size());
  39. display_list().UpdateDisplay(display);
  40. }
  41. gfx::Point ShellScreen::GetCursorScreenPoint() {
  42. return aura::Env::GetInstance()->last_mouse_location();
  43. }
  44. bool ShellScreen::IsWindowUnderCursor(gfx::NativeWindow window) {
  45. return GetWindowAtScreenPoint(GetCursorScreenPoint()) == window;
  46. }
  47. gfx::NativeWindow ShellScreen::GetWindowAtScreenPoint(const gfx::Point& point) {
  48. return desktop_controller_->GetPrimaryHost()
  49. ->window()
  50. ->GetEventHandlerForPoint(point);
  51. }
  52. display::Display ShellScreen::GetDisplayNearestWindow(
  53. gfx::NativeWindow window) const {
  54. return GetPrimaryDisplay();
  55. }
  56. } // namespace extensions