Repository navigation
Expand file tree
/
Copy pathrender_document.hpp
More file actions
58 lines (48 loc) · 2.49 KB
/
Copy pathrender_document.hpp
File metadata and controls
58 lines (48 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include "document.hpp"
#include "paint_executor.hpp"
#include "render_tree.hpp"
#include "resource.hpp"
#include "image.hpp"
#include "css_stylesheet.hpp"
#include "visual_state.hpp"
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
namespace aetheris::rendering {
class RenderDocument {
public:
static RenderDocument create(std::string_view html, std::string_view css, float viewport_width, ResourceCache* resources = nullptr, std::string_view source_url = {});
// Builds from an already-parsed document, so a host can run scripts that
// mutate the DOM before layout.
static RenderDocument create_from_document(Document document, std::string_view css, float viewport_width, ResourceCache* resources = nullptr, std::string_view source_url = {});
static std::optional<RenderDocument> create_from_resources(std::string_view document_url, std::string_view stylesheet_url, float viewport_width, ResourceCache& resources);
static std::optional<RenderDocument> create_from_resources(std::string_view document_url, std::vector<std::string> const& stylesheet_urls, float viewport_width, ResourceCache& resources);
ResourceCache& resources() { return m_resources; }
ResourceCache const& resources() const { return m_resources; }
std::string const& source_url() const { return m_source_url; }
Document const& document() const { return m_document; }
LayoutNode const& layout_root() const { return *m_layout_root; }
RenderTree const& render_tree() const { return m_render_tree; }
SoftwareSurface render_to_surface(int width, int height, Color clear_color = { 0, 0, 0, 0 }) const;
// Rebuilds layout and the render tree from the (possibly mutated) document.
void relayout();
void apply_visual_state(VisualInteractionState const& interaction_state, float viewport_width);
std::size_t visual_generation() const { return m_visual_generation; }
private:
Document m_document;
std::unique_ptr<LayoutNode> m_layout_root;
RenderTree m_render_tree;
CssStyleSheet m_stylesheet;
float m_viewport_width { 0 };
std::size_t m_visual_generation { 0 };
RenderDocument(Document document, std::unique_ptr<LayoutNode> layout_root, RenderTree render_tree, CssStyleSheet sheet);
void resolve_images(LayoutNode&);
std::string resolve_resource_key(std::string const& reference) const;
ResourceCache m_resources;
ImageCache m_images;
std::string m_source_url;
};
} // namespace aetheris::rendering