HTMLImageElement.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <LibHTML/CSS/StyleResolver.h>
  2. #include <LibHTML/DOM/Document.h>
  3. #include <LibHTML/DOM/HTMLImageElement.h>
  4. #include <LibHTML/Layout/LayoutImage.h>
  5. HTMLImageElement::HTMLImageElement(Document& document, const String& tag_name)
  6. : HTMLElement(document, tag_name)
  7. {
  8. }
  9. HTMLImageElement::~HTMLImageElement()
  10. {
  11. }
  12. void HTMLImageElement::parse_attribute(const String& name, const String& value)
  13. {
  14. if (name == "src")
  15. load_image(value);
  16. }
  17. void HTMLImageElement::load_image(const String& src)
  18. {
  19. URL src_url = document().complete_url(src);
  20. if (src_url.protocol() == "file") {
  21. m_bitmap = GraphicsBitmap::load_from_file(src_url.path());
  22. } else {
  23. // FIXME: Implement! This whole thing should be at a different layer though..
  24. ASSERT_NOT_REACHED();
  25. }
  26. }
  27. RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const
  28. {
  29. auto style = resolver.resolve_style(*this, parent_style);
  30. auto display_property = style->property("display");
  31. String display = display_property.has_value() ? display_property.release_value()->to_string() : "inline";
  32. if (display == "none")
  33. return nullptr;
  34. return adopt(*new LayoutImage(*this, move(style)));
  35. }
  36. const GraphicsBitmap* HTMLImageElement::bitmap() const
  37. {
  38. return m_bitmap;
  39. }