HTMLFrameSetElement.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/HTMLFrameSetElementPrototype.h>
  7. #include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
  8. #include <LibWeb/DOM/Document.h>
  9. #include <LibWeb/HTML/HTMLFrameSetElement.h>
  10. #include <LibWeb/HTML/Window.h>
  11. namespace Web::HTML {
  12. JS_DEFINE_ALLOCATOR(HTMLFrameSetElement);
  13. HTMLFrameSetElement::HTMLFrameSetElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  14. : HTMLElement(document, move(qualified_name))
  15. {
  16. }
  17. HTMLFrameSetElement::~HTMLFrameSetElement() = default;
  18. void HTMLFrameSetElement::adjust_computed_style(CSS::StyleProperties& style)
  19. {
  20. // https://drafts.csswg.org/css-display-3/#unbox
  21. if (style.display().is_contents())
  22. style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::None)));
  23. }
  24. void HTMLFrameSetElement::initialize(JS::Realm& realm)
  25. {
  26. Base::initialize(realm);
  27. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLFrameSetElement);
  28. }
  29. void HTMLFrameSetElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value)
  30. {
  31. HTMLElement::attribute_changed(name, old_value, value);
  32. #undef __ENUMERATE
  33. #define __ENUMERATE(attribute_name, event_name) \
  34. if (name == HTML::AttributeNames::attribute_name) { \
  35. element_event_handler_attribute_changed(event_name, value); \
  36. }
  37. ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE)
  38. #undef __ENUMERATE
  39. }
  40. JS::GCPtr<DOM::EventTarget> HTMLFrameSetElement::global_event_handlers_to_event_target(FlyString const& event_name)
  41. {
  42. // NOTE: This is a little weird, but IIUC document.body.onload actually refers to window.onload
  43. // NOTE: document.body can return either a HTMLBodyElement or HTMLFrameSetElement, so both these elements must support this mapping.
  44. if (DOM::is_window_reflecting_body_element_event_handler(event_name))
  45. return document().window();
  46. return *this;
  47. }
  48. JS::GCPtr<DOM::EventTarget> HTMLFrameSetElement::window_event_handlers_to_event_target()
  49. {
  50. // All WindowEventHandlers on HTMLFrameSetElement (e.g. document.body.onrejectionhandled) are mapped to window.on{event}.
  51. // NOTE: document.body can return either a HTMLBodyElement or HTMLFrameSetElement, so both these elements must support this mapping.
  52. return document().window();
  53. }
  54. }