DomUtils

TheArtOfDev.HtmlRenderer.Core.Utils

Utility class for traversing DOM structure and execution stuff on it.

Методы

CollectSelectedBoxes(CssBox, Dictionary<CssBox, bool>, Dictionary<CssBox, bool>) : bool

Collect the boxes that have at least one word down the hierarchy that is selected recursively. Use to handle boxes that are between selected words but don't have selected word inside.

box
the box to check its sub-tree
selectedBoxes
the hash to add the selected boxes to
maybeBoxes
used to handle boxes that are between selected words but don't have selected word inside

Возвращает: is the current box is in selected sub-tree

CollectSelectedBoxes(CssBox) : Dictionary<CssBox, bool>

Collect the boxes that have at least one word down the hierarchy that is selected recursively.

root
the box to check its sub-tree

Возвращает: the collection to add the selected tags to

ContainsInlinesOnly(CssBox) : bool

Check if the given box contains only inline child boxes.

box
the box to check

Возвращает: true - only inline child boxes, false - otherwise

ContainsNamedBox(CssBox) : bool

Check if the given box has a names child box (has html tag) recursively.

box
the box to check

Возвращает: true - in sub-tree there is a named box, false - otherwise

FindParent(CssBox, string, CssBox) : CssBox

Recursively searches for the parent with the specified HTML Tag name

root
tagName
box
GenerateBoxTree(CssBox, StringBuilder, int)

Generate textual tree representation of the css boxes tree starting from the given root. Used for debugging html parsing.

box
the box to generate for
builder
the string builder to generate to
indent
the current indent level to set indent of generated text
GenerateBoxTree(CssBox) : string

Generate textual tree representation of the css boxes tree starting from the given root. Used for debugging html parsing.

root
the root to generate tree from

Возвращает: generated tree

GenerateHtml(CssBox, HtmlGenerationStyle, bool) : string

Generate html from the given DOM tree. Generate all the style inside the html, in header or for every tag depending on value.

root
the box of the html generate html from
styleGen
Optional: controls the way styles are generated when html is generated
onlySelected
Optional: true - generate only selected html subset, false - generate all (default - false)

Возвращает: generated html

GetAllLinkBoxes(CssBox, List<CssBox>)

Collect all link boxes found in the HTML tree.

box
the box to start search from
linkBoxes
collection to add all link boxes to
GetAttribute(CssBox, string) : string

Get attribute value by given key starting search from given box, search up the tree until attribute found or root.

box
the box to start lookup at
attribute
the attribute to get

Возвращает: the value of the attribute or null if not found

GetBoxById(CssBox, string) : CssBox

Get css box under the given sub-tree with the given id.

box
the box to start search from
id
the id to find the box by

Возвращает: css box if exists or null

GetCssBox(CssBox, RPoint, bool) : CssBox

Get css box under the given sub-tree at the given x,y location, get the inner most. the location must be in correct scroll offset.

box
the box to start search from
location
the location to find the box by
visible
Optional: if to get only visible boxes (default - true)

Возвращает: css link box if exists or null

GetCssBoxWord(CssBox, RPoint) : CssRect

Get css word box under the given sub-tree at the given x,y location. the location must be in correct scroll offset.

box
the box to start search from
location
the location to find the box at

Возвращает: css word box if exists or null

GetCssBoxWord(CssLineBox, RPoint) : CssRect

Get css word box under the given sub-tree at the given x,y location. the location must be in correct scroll offset.

lineBox
the line box to search in
location
the location to find the box at

Возвращает: css word box if exists or null

GetCssLineBox(CssBox, RPoint) : CssLineBox

Get css line box under the given sub-tree at the given y location or the nearest line from the top. the location must be in correct scroll offset.

box
the box to start search from
location
the location to find the box at

Возвращает: css word box if exists or null

GetCssLineBoxByWord(CssRect) : CssLineBox

Find the css line box that the given word is in.

word
the word to search for it's line box

Возвращает: line box that the word is in

GetNextSibling(CssBox) : CssBox

Gets the next sibling of this box.

Возвращает: Box before this one on the tree. Null if its the first

GetPreviousContainingBlockSibling(CssBox) : CssBox

Gets the previous sibling of this box.

Возвращает: Box before this one on the tree. Null if its the first

GetPreviousSibling(CssBox) : CssBox

Gets the previous sibling of this box.

Возвращает: Box before this one on the tree. Null if its the first

GetSelectedPlainText(CssBox) : string

Get selected plain text of the given html sub-tree.

root
the DOM box to get selected text from its sub-tree

Возвращает: the selected plain text string

GetSelectedPlainText(StringBuilder, CssBox) : int

Get selected plain text of the given html sub-tree. Append all the selected words.

sb
the builder to append the selected text to
box
the DOM box to get selected text from its sub-tree

Возвращает: the index of the last word appended

GetSelectedWord(CssRect, bool) : string

Get the selected word with respect to partial selected words.

rect
the word to append
selectedText
is to get selected text or all the text in the word
GetSelectionRoot(CssBox, Dictionary<CssBox, bool>) : CssBox

find the box the is the root of selected boxes (the first box to contain multiple selected boxes)

root
the root of the boxes tree
selectedBoxes
the selected boxes to find selection root in

Возвращает: the box that is the root of selected boxes

IsBoxHasWhitespace(CssBox) : bool

fix word space for first word in inline tag.

box
the box to check
IsInBox(CssBox, RPoint) : bool

Check if the given location is inside the given box deep. Check inner boxes and all lines that the given box spans to.

box
the box to check
location
the location to check

Возвращает: true - location inside the box, false - otherwise

StripDefaultStyles(CssBox, Dictionary<string, string>) : Dictionary<string, string>

Clean the given style collection by removing default styles so only custom styles remain. Return new collection where the old remains unchanged.

box
the box the styles apply to, used to know the default style
tagStyles
the collection of styles to clean

Возвращает: new cleaned styles collection

WriteHtml(CssParser, StringBuilder, CssBox, HtmlGenerationStyle, Dictionary<CssBox, bool>, CssBox)

Write the given html DOM sub-tree into the given string builder. If are given write html only from those tags.

cssParser
used to parse CSS data
sb
the string builder to write html into
box
the html sub-tree to write
styleGen
Controls the way styles are generated when html is generated
selectedBoxes
Control if to generate only selected boxes, if given only boxes found in hash will be generated
selectionRoot
the box the is the root of selected boxes (the first box to contain multiple selected boxes)
WriteHtmlTag(CssParser, StringBuilder, CssBox, HtmlGenerationStyle)

Write the given html tag with all its attributes and styles.

cssParser
used to parse CSS data
sb
the string builder to write html into
box
the css box with the html tag to write
styleGen
Controls the way styles are generated when html is generated
WriteStylesheet(StringBuilder, CssData)

Write stylesheet data inline into the html.

sb
the string builder to write stylesheet into
cssData
the css data to write to the head