StyleValue.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <LibDraw/GraphicsBitmap.h>
  2. #include <LibDraw/PNGLoader.h>
  3. #include <LibHTML/CSS/StyleValue.h>
  4. #include <LibHTML/DOM/Document.h>
  5. #include <LibHTML/Frame.h>
  6. #include <LibHTML/ResourceLoader.h>
  7. StyleValue::StyleValue(Type type)
  8. : m_type(type)
  9. {
  10. }
  11. StyleValue::~StyleValue()
  12. {
  13. }
  14. String IdentifierStyleValue::to_string() const
  15. {
  16. switch (id()) {
  17. case CSS::ValueID::Invalid:
  18. return "(invalid)";
  19. case CSS::ValueID::VendorSpecificLink:
  20. return "-libhtml-link";
  21. default:
  22. ASSERT_NOT_REACHED();
  23. }
  24. }
  25. Color IdentifierStyleValue::to_color(const Document& document) const
  26. {
  27. if (id() == CSS::ValueID::VendorSpecificLink)
  28. return document.link_color();
  29. return {};
  30. }
  31. ImageStyleValue::ImageStyleValue(const URL& url, Document& document)
  32. : StyleValue(Type::Image)
  33. , m_url(url)
  34. , m_document(document.make_weak_ptr())
  35. {
  36. NonnullRefPtr<ImageStyleValue> protector(*this);
  37. ResourceLoader::the().load(url, [this, protector](auto& data) {
  38. if (!m_document)
  39. return;
  40. m_bitmap = load_png_from_memory(data.data(), data.size());
  41. if (!m_bitmap)
  42. return;
  43. // FIXME: Do less than a full repaint if possible?
  44. m_document->frame()->set_needs_display({});
  45. });
  46. }