Screen.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/CSS/ScreenOrientation.h>
  11. #include <LibWeb/DOM/Document.h>
  12. #include <LibWeb/Page/Page.h>
  13. namespace Web::CSS {
  14. JS_DEFINE_ALLOCATOR(Screen);
  15. JS::NonnullGCPtr<Screen> Screen::create(HTML::Window& window)
  16. {
  17. return window.heap().allocate<Screen>(window.realm(), window);
  18. }
  19. Screen::Screen(HTML::Window& window)
  20. : PlatformObject(window.realm())
  21. , m_window(window)
  22. {
  23. }
  24. void Screen::initialize(JS::Realm& realm)
  25. {
  26. Base::initialize(realm);
  27. WEB_SET_PROTOTYPE_FOR_INTERFACE(Screen);
  28. }
  29. void Screen::visit_edges(Cell::Visitor& visitor)
  30. {
  31. Base::visit_edges(visitor);
  32. visitor.visit(m_window);
  33. visitor.visit(m_orientation);
  34. }
  35. Gfx::IntRect Screen::screen_rect() const
  36. {
  37. auto screen_rect_in_css_pixels = window().page().web_exposed_screen_area();
  38. return {
  39. screen_rect_in_css_pixels.x().to_int(),
  40. screen_rect_in_css_pixels.y().to_int(),
  41. screen_rect_in_css_pixels.width().to_int(),
  42. screen_rect_in_css_pixels.height().to_int()
  43. };
  44. }
  45. JS::NonnullGCPtr<ScreenOrientation> Screen::orientation()
  46. {
  47. if (!m_orientation)
  48. m_orientation = ScreenOrientation::create(realm());
  49. return *m_orientation;
  50. }
  51. }