Screen.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_DEFINE_ALLOCATOR(Screen);
  14. JS::NonnullGCPtr<Screen> Screen::create(HTML::Window& window)
  15. {
  16. return window.heap().allocate<Screen>(window.realm(), window);
  17. }
  18. Screen::Screen(HTML::Window& window)
  19. : PlatformObject(window.realm())
  20. , m_window(window)
  21. {
  22. }
  23. void Screen::initialize(JS::Realm& realm)
  24. {
  25. Base::initialize(realm);
  26. WEB_SET_PROTOTYPE_FOR_INTERFACE(Screen);
  27. }
  28. void Screen::visit_edges(Cell::Visitor& visitor)
  29. {
  30. Base::visit_edges(visitor);
  31. visitor.visit(m_window);
  32. }
  33. Gfx::IntRect Screen::screen_rect() const
  34. {
  35. auto screen_rect_in_css_pixels = window().page().web_exposed_screen_area();
  36. return {
  37. screen_rect_in_css_pixels.x().to_int(),
  38. screen_rect_in_css_pixels.y().to_int(),
  39. screen_rect_in_css_pixels.width().to_int(),
  40. screen_rect_in_css_pixels.height().to_int()
  41. };
  42. }
  43. }