Screen.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGfx/Rect.h>
  8. #include <LibWeb/Bindings/PlatformObject.h>
  9. #include <LibWeb/DOM/EventTarget.h>
  10. #include <LibWeb/Forward.h>
  11. #include <LibWeb/HTML/Window.h>
  12. namespace Web::CSS {
  13. class Screen final : public DOM::EventTarget {
  14. WEB_PLATFORM_OBJECT(Screen, DOM::EventTarget);
  15. JS_DECLARE_ALLOCATOR(Screen);
  16. public:
  17. [[nodiscard]] static JS::NonnullGCPtr<Screen> create(HTML::Window&);
  18. i32 width() const { return screen_rect().width(); }
  19. i32 height() const { return screen_rect().height(); }
  20. i32 avail_width() const { return screen_rect().width(); }
  21. i32 avail_height() const { return screen_rect().height(); }
  22. u32 color_depth() const { return 24; }
  23. u32 pixel_depth() const { return 24; }
  24. JS::NonnullGCPtr<ScreenOrientation> orientation();
  25. bool is_extended() const;
  26. void set_onchange(JS::GCPtr<WebIDL::CallbackType> event_handler);
  27. JS::GCPtr<WebIDL::CallbackType> onchange();
  28. private:
  29. explicit Screen(HTML::Window&);
  30. virtual void initialize(JS::Realm&) override;
  31. virtual void visit_edges(Cell::Visitor&) override;
  32. HTML::Window const& window() const { return *m_window; }
  33. Gfx::IntRect screen_rect() const;
  34. JS::NonnullGCPtr<HTML::Window> m_window;
  35. JS::GCPtr<ScreenOrientation> m_orientation;
  36. };
  37. }