NodeWrapperFactory.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <LibWeb/Bindings/DocumentWrapper.h>
  27. #include <LibWeb/Bindings/DocumentTypeWrapper.h>
  28. #include <LibWeb/Bindings/HTMLAnchorElementWrapper.h>
  29. #include <LibWeb/Bindings/HTMLBodyElementWrapper.h>
  30. #include <LibWeb/Bindings/HTMLBRElementWrapper.h>
  31. #include <LibWeb/Bindings/HTMLCanvasElementWrapper.h>
  32. #include <LibWeb/Bindings/HTMLElementWrapper.h>
  33. #include <LibWeb/Bindings/HTMLFormElementWrapper.h>
  34. #include <LibWeb/Bindings/HTMLHeadElementWrapper.h>
  35. #include <LibWeb/Bindings/HTMLHeadingElementWrapper.h>
  36. #include <LibWeb/Bindings/HTMLHRElementWrapper.h>
  37. #include <LibWeb/Bindings/HTMLHtmlElementWrapper.h>
  38. #include <LibWeb/Bindings/HTMLIFrameElementWrapper.h>
  39. #include <LibWeb/Bindings/HTMLImageElementWrapper.h>
  40. #include <LibWeb/Bindings/HTMLInputElementWrapper.h>
  41. #include <LibWeb/Bindings/HTMLLinkElementWrapper.h>
  42. #include <LibWeb/Bindings/HTMLObjectElementWrapper.h>
  43. #include <LibWeb/Bindings/HTMLScriptElementWrapper.h>
  44. #include <LibWeb/Bindings/HTMLStyleElementWrapper.h>
  45. #include <LibWeb/Bindings/HTMLTableCellElementWrapper.h>
  46. #include <LibWeb/Bindings/HTMLTableElementWrapper.h>
  47. #include <LibWeb/Bindings/HTMLTableRowElementWrapper.h>
  48. #include <LibWeb/Bindings/HTMLTitleElementWrapper.h>
  49. #include <LibWeb/Bindings/NodeWrapper.h>
  50. #include <LibWeb/DOM/Document.h>
  51. #include <LibWeb/HTML/HTMLAnchorElement.h>
  52. #include <LibWeb/HTML/HTMLBodyElement.h>
  53. #include <LibWeb/HTML/HTMLBRElement.h>
  54. #include <LibWeb/HTML/HTMLCanvasElement.h>
  55. #include <LibWeb/HTML/HTMLFormElement.h>
  56. #include <LibWeb/HTML/HTMLHeadElement.h>
  57. #include <LibWeb/HTML/HTMLHeadingElement.h>
  58. #include <LibWeb/HTML/HTMLHRElement.h>
  59. #include <LibWeb/HTML/HTMLHtmlElement.h>
  60. #include <LibWeb/HTML/HTMLIFrameElement.h>
  61. #include <LibWeb/HTML/HTMLImageElement.h>
  62. #include <LibWeb/HTML/HTMLInputElement.h>
  63. #include <LibWeb/HTML/HTMLLinkElement.h>
  64. #include <LibWeb/HTML/HTMLObjectElement.h>
  65. #include <LibWeb/HTML/HTMLScriptElement.h>
  66. #include <LibWeb/HTML/HTMLStyleElement.h>
  67. #include <LibWeb/HTML/HTMLTableCellElement.h>
  68. #include <LibWeb/HTML/HTMLTableElement.h>
  69. #include <LibWeb/HTML/HTMLTableRowElement.h>
  70. #include <LibWeb/HTML/HTMLTitleElement.h>
  71. #include <LibWeb/DOM/Node.h>
  72. namespace Web {
  73. namespace Bindings {
  74. NodeWrapper* wrap(JS::GlobalObject& global_object, DOM::Node& node)
  75. {
  76. if (is<DOM::Document>(node))
  77. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::Document>(node)));
  78. if (is<DOM::DocumentType>(node))
  79. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::DocumentType>(node)));
  80. if (is<HTMLAnchorElement>(node))
  81. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLAnchorElement>(node)));
  82. if (is<HTMLBodyElement>(node))
  83. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLBodyElement>(node)));
  84. if (is<HTMLBRElement>(node))
  85. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLBRElement>(node)));
  86. if (is<HTMLCanvasElement>(node))
  87. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLCanvasElement>(node)));
  88. if (is<HTMLFormElement>(node))
  89. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLFormElement>(node)));
  90. if (is<HTMLHeadElement>(node))
  91. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLHeadElement>(node)));
  92. if (is<HTMLHeadingElement>(node))
  93. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLHeadingElement>(node)));
  94. if (is<HTMLHRElement>(node))
  95. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLHRElement>(node)));
  96. if (is<HTMLHtmlElement>(node))
  97. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLHtmlElement>(node)));
  98. if (is<HTMLIFrameElement>(node))
  99. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLIFrameElement>(node)));
  100. if (is<HTMLImageElement>(node))
  101. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLImageElement>(node)));
  102. if (is<HTMLInputElement>(node))
  103. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLInputElement>(node)));
  104. if (is<HTMLLinkElement>(node))
  105. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLLinkElement>(node)));
  106. if (is<HTMLObjectElement>(node))
  107. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLObjectElement>(node)));
  108. if (is<HTMLScriptElement>(node))
  109. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLScriptElement>(node)));
  110. if (is<HTMLStyleElement>(node))
  111. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLStyleElement>(node)));
  112. if (is<HTMLTableCellElement>(node))
  113. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLTableCellElement>(node)));
  114. if (is<HTMLTableElement>(node))
  115. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLTableElement>(node)));
  116. if (is<HTMLTableRowElement>(node))
  117. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLTableRowElement>(node)));
  118. if (is<HTMLTitleElement>(node))
  119. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLTitleElement>(node)));
  120. if (is<HTMLElement>(node))
  121. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTMLElement>(node)));
  122. if (is<DOM::Element>(node))
  123. return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::Element>(node)));
  124. return static_cast<NodeWrapper*>(wrap_impl(global_object, node));
  125. }
  126. }
  127. }