Screen.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Rect.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/Bindings/ScreenPrototype.h>
  9. #include <LibWeb/CSS/Screen.h>
  10. #include <LibWeb/DOM/Document.h>
  11. #include <LibWeb/Page/Page.h>
  12. namespace Web::CSS {
  13. JS::NonnullGCPtr<Screen> Screen::create(HTML::Window& window)
  14. {
  15. return window.heap().allocate<Screen>(window.realm(), window);
  16. }
  17. Screen::Screen(HTML::Window& window)
  18. : PlatformObject(window.realm())
  19. , m_window(window)
  20. {
  21. set_prototype(&Bindings::ensure_web_prototype<Bindings::ScreenPrototype>(window.realm(), "Screen"));
  22. }
  23. void Screen::visit_edges(Cell::Visitor& visitor)
  24. {
  25. Base::visit_edges(visitor);
  26. visitor.visit(m_window.ptr());
  27. }
  28. Gfx::IntRect Screen::screen_rect() const
  29. {
  30. auto screen_rect_in_css_pixels = window().page()->web_exposed_screen_area();
  31. return {
  32. screen_rect_in_css_pixels.x().value(),
  33. screen_rect_in_css_pixels.y().value(),
  34. screen_rect_in_css_pixels.width().value(),
  35. screen_rect_in_css_pixels.height().value()
  36. };
  37. }
  38. }