Screen.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. }
  22. void Screen::initialize(JS::Realm& realm)
  23. {
  24. Base::initialize(realm);
  25. set_prototype(&Bindings::ensure_web_prototype<Bindings::ScreenPrototype>(realm, "Screen"));
  26. }
  27. void Screen::visit_edges(Cell::Visitor& visitor)
  28. {
  29. Base::visit_edges(visitor);
  30. visitor.visit(m_window.ptr());
  31. }
  32. Gfx::IntRect Screen::screen_rect() const
  33. {
  34. auto screen_rect_in_css_pixels = window().page()->web_exposed_screen_area();
  35. return {
  36. screen_rect_in_css_pixels.x().to_int(),
  37. screen_rect_in_css_pixels.y().to_int(),
  38. screen_rect_in_css_pixels.width().to_int(),
  39. screen_rect_in_css_pixels.height().to_int()
  40. };
  41. }
  42. }