HTMLImageElement.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const
  13. {
  14. auto style = resolver.resolve_style(*this, parent_style);
  15. auto display_property = style->property("display");
  16. String display = display_property.has_value() ? display_property.release_value()->to_string() : "inline";
  17. if (display == "none")
  18. return nullptr;
  19. return adopt(*new LayoutImage(*this, move(style)));
  20. }
  21. const GraphicsBitmap* HTMLImageElement::bitmap() const
  22. {
  23. if (!m_bitmap) {
  24. URL src_url = document().complete_url(this->src());
  25. if (src_url.protocol() == "file") {
  26. m_bitmap = GraphicsBitmap::load_from_file(src_url.path());
  27. } else {
  28. // FIXME: Implement! This whole thing should be at a different layer though..
  29. ASSERT_NOT_REACHED();
  30. }
  31. }
  32. return m_bitmap;
  33. }