SVGTextContentElement.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Utf16View.h>
  7. #include <LibJS/Runtime/Completion.h>
  8. #include <LibJS/Runtime/Utf16String.h>
  9. #include <LibWeb/DOM/Document.h>
  10. #include <LibWeb/SVG/SVGTextContentElement.h>
  11. namespace Web::SVG {
  12. SVGTextContentElement::SVGTextContentElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  13. : SVGGraphicsElement(document, move(qualified_name))
  14. {
  15. }
  16. JS::ThrowCompletionOr<void> SVGTextContentElement::initialize(JS::Realm& realm)
  17. {
  18. MUST_OR_THROW_OOM(Base::initialize(realm));
  19. set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGTextContentElementPrototype>(realm, "SVGTextContentElement"));
  20. return {};
  21. }
  22. // https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars
  23. WebIDL::ExceptionOr<int> SVGTextContentElement::get_number_of_chars() const
  24. {
  25. auto chars = TRY_OR_THROW_OOM(vm(), utf8_to_utf16(child_text_content()));
  26. return static_cast<int>(chars.size());
  27. }
  28. }