diff options
author | bptato <nincsnevem662@gmail.com> | 2021-08-06 18:35:39 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-08-06 18:35:39 +0200 |
commit | da1f249117ad2a6f02c1ac32208d6ece95508505 (patch) | |
tree | b879b5bc256bc3cb3604fecfefd254c38ed62fc6 /src/html | |
parent | d4fe6539be7d2083260ba9deb012b2db59a121bd (diff) | |
download | chawan-da1f249117ad2a6f02c1ac32208d6ece95508505.tar.gz |
Refactoring in buffer.nim
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 29 | ||||
-rw-r--r-- | src/html/htmlparser.nim | 10 |
2 files changed, 11 insertions, 28 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index b1e1af4c..e5aee036 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -477,30 +477,13 @@ proc applyRules*(document: Document, rules: CSSStylesheet): seq[tuple[e:Element, for child in elem.children: stack.add(child) -proc addBoxes*(elem: Element) = - var b = false - for child in elem.childNodes: - if child.nodeType == ELEMENT_NODE: - if ((Element)child).style.display == DISPLAY_BLOCK: - b = true - break +proc generateBox*(elem: Element) = + if elem.style.display == DISPLAY_INLINE: + discard + for child in elem.childNodes: if child.nodeType == ELEMENT_NODE: - if b: - child.box = CSSBox(display: DISPLAY_BLOCK) - else: - child.box = CSSBox() - -proc generateBoxModel(document: Document) = - var stack: seq[Element] - - stack.add(document.firstElementChild) - document.firstElementChild.box = CSSBox() - while stack.len > 0: - let elem = stack.pop() - elem.addBoxes() - for child in elem.children: - stack.add(child) + Element(child).generateBox() proc applyDefaultStylesheet*(document: Document) = let important = document.applyRules(stylesheet) @@ -508,4 +491,4 @@ proc applyDefaultStylesheet*(document: Document) = rule.e.style.applyProperty(rule.d) rule.e.cssvalues.add(getComputedValue(rule.d)) - document.generateBoxModel() + document.root.generateBox() diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim index f5a8190b..2a652304 100644 --- a/src/html/htmlparser.nim +++ b/src/html/htmlparser.nim @@ -210,7 +210,7 @@ proc processDocumentBody(state: var HTMLParseState) = state.elementNode = state.elementNode.ownerDocument.body proc processDocumentAddNode(state: var HTMLParseState, newNode: Node) = - if state.elementNode.nodeType == ELEMENT_NODE and ((Element)state.elementNode).tagType == TAG_HTML: + if state.elementNode.nodeType == ELEMENT_NODE and state.elementNode.tagType == TAG_HTML: if state.in_body: state.elementNode = state.elementNode.ownerDocument.body else: @@ -272,7 +272,7 @@ proc processDocumentStartElement(state: var HTMLParseState, element: Element, ta if state.elementNode.nodeType == ELEMENT_NODE: case element.tagType of SelfClosingTagTypes: - if Element(state.elementNode).tagType == element.tagType: + if state.elementNode.tagType == element.tagType: processDocumentEndNode(state) of TAG_H1: HTMLHeadingElement(element).rank = 1 @@ -288,7 +288,7 @@ proc processDocumentStartElement(state: var HTMLParseState, element: Element, ta HTMLHeadingElement(element).rank = 6 else: discard - if Element(state.elementNode).tagType == TAG_P and element.tagType in PClosingTagTypes: + if state.elementNode.tagType == TAG_P and element.tagType in PClosingTagTypes: processDocumentEndNode(state) if add: @@ -306,8 +306,8 @@ proc processDocumentEndElement(state: var HTMLParseState, tag: DOMParsedTag) = return if tag.tagid == TAG_BODY: return - if state.elementNode.nodeType == ELEMENT_NODE and tag.tagid != Element(state.elementNode).tagType: - if Element(state.elementNode).tagType in SelfClosingTagTypes: + if state.elementNode.nodeType == ELEMENT_NODE and tag.tagid != state.elementNode.tagType: + if state.elementNode.tagType in SelfClosingTagTypes: processDocumentEndNode(state) processDocumentEndNode(state) |