Просмотр исходного кода

LibHTML: Add layout() overrides for LayoutText and LayoutBlock.

Andreas Kling 6 лет назад
Родитель
Сommit
2e2b97dc8a

+ 7 - 0
LibHTML/Layout/LayoutBlock.cpp

@@ -9,3 +9,10 @@ LayoutBlock::LayoutBlock(Element& element)
 LayoutBlock::~LayoutBlock()
 {
 }
+
+void LayoutBlock::layout()
+{
+    LayoutNode::layout();
+
+
+}

+ 2 - 0
LibHTML/Layout/LayoutBlock.h

@@ -11,5 +11,7 @@ public:
 
     virtual const char* class_name() const override { return "LayoutBlock"; }
 
+    virtual void layout() override;
+
 private:
 };

+ 4 - 0
LibHTML/Layout/LayoutNode.h

@@ -25,6 +25,8 @@ public:
     bool is_anonymous() const { return !m_node; }
     const Node* node() const { return m_node; }
 
+    const LayoutNode* parent_layout_node() const { return m_parent_node; }
+
     LayoutNode* next_sibling() { return m_next_sibling; }
     LayoutNode* previous_sibling() { return m_previous_sibling; }
     LayoutNode* first_child() { return m_first_child; }
@@ -34,6 +36,8 @@ public:
     const LayoutNode* first_child() const { return m_first_child; }
     const LayoutNode* last_child() const { return m_last_child; }
 
+    bool has_children() const { return m_first_child; }
+
     void append_child(Retained<LayoutNode>);
 
     void set_next_sibling(LayoutNode* node) { m_next_sibling = node; }

+ 11 - 0
LibHTML/Layout/LayoutText.cpp

@@ -26,3 +26,14 @@ const String& LayoutText::text() const
         return one_space;
     return node().data();
 }
+
+void LayoutText::compute_runs()
+{
+
+}
+
+void LayoutText::layout()
+{
+    ASSERT(!has_children());
+    compute_runs();
+}

+ 11 - 0
LibHTML/Layout/LayoutText.h

@@ -14,6 +14,17 @@ public:
 
     virtual const char* class_name() const override { return "LayoutText"; }
     virtual bool is_text() const final { return true; }
+    virtual void layout() override;
+
+    struct Run {
+        Point pos;
+        String text;
+    };
+
+    const Vector<Run>& runs() const { return m_runs; }
 
 private:
+    void compute_runs();
+
+    Vector<Run> m_runs;
 };

+ 3 - 0
LibHTML/test.cpp

@@ -17,12 +17,15 @@ int main(int argc, char** argv)
 
     doc->build_layout_tree();
     ASSERT(doc->layout_node());
+
+    printf("\033[33;1mLayout tree before layout:\033[0m\n");
     dump_tree(*doc->layout_node());
 
     auto frame = make<Frame>();
     frame->set_document(doc);
     frame->layout();
 
+    printf("\033[33;1mLayout tree after layout:\033[0m\n");
     dump_tree(*doc->layout_node());
     return 0;
 }