Screen.cpp 1.3 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. WebIDL::ExceptionOr<JS::NonnullGCPtr<Screen>> Screen::create(HTML::Window& window)
  14. {
  15. return MUST_OR_THROW_OOM(window.heap().allocate<Screen>(window.realm(), window));
  16. }
  17. Screen::Screen(HTML::Window& window)
  18. : PlatformObject(window.realm())
  19. , m_window(window)
  20. {
  21. }
  22. JS::ThrowCompletionOr<void> Screen::initialize(JS::Realm& realm)
  23. {
  24. MUST_OR_THROW_OOM(Base::initialize(realm));
  25. set_prototype(&Bindings::ensure_web_prototype<Bindings::ScreenPrototype>(realm, "Screen"));
  26. return {};
  27. }
  28. void Screen::visit_edges(Cell::Visitor& visitor)
  29. {
  30. Base::visit_edges(visitor);
  31. visitor.visit(m_window.ptr());
  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().value(),
  38. screen_rect_in_css_pixels.y().value(),
  39. screen_rect_in_css_pixels.width().value(),
  40. screen_rect_in_css_pixels.height().value()
  41. };
  42. }
  43. }