HtmlContainer

TheArtOfDev.HtmlRenderer.WPF

Low level handling of Html Renderer logic, this class is used by HtmlParser, HtmlLabel and HtmlRender.

Implements: IDisposable

Constructors

HtmlContainer()

Init.

Properties

ActualSize : Size

The actual size of the rendered html (after layout)

AvoidAsyncImagesLoading : bool

Gets or sets a value indicating if image asynchronous loading should be avoided (default - false). True - images are loaded synchronously during html parsing. False - images are loaded asynchronously to html parsing when downloaded from URL or loaded from disk.

AvoidImagesLateLoading : bool

Gets or sets a value indicating if image loading only when visible should be avoided (default - false). True - images are loaded as soon as the html is parsed. False - images that are not visible because of scroll location are not loaded until they are scrolled to.

CssData : CssData

the parsed stylesheet data used for handling the html

HtmlContainerInt : HtmlContainerInt

The internal core html container

IsContextMenuEnabled : bool

Is the build-in context menu enabled and will be shown on mouse right click (default - true)

IsSelectionEnabled : bool

Is content selection is enabled for the rendered html (default - true). If set to 'false' the rendered html will be static only with ability to click on links.

Location : Point

The top-left most location of the rendered html. This will offset the top-left corner of the rendered html.

MaxSize : Size

The max width and height of the rendered html. The max width will effect the html layout wrapping lines, resize images and tables where possible. The max height does NOT effect layout, but will not render outside it (clip).ActualSize can be exceed the max size by layout restrictions (unwrappable line, set image size, etc.). Set zero for unlimited (width\height separately).

ScrollOffset : Point

The scroll offset of the html. This will adjust the rendered html by the given offset so the content will be "scrolled".

SelectedHtml : string

Copy the currently selected html segment with style.

SelectedText : string

Get the currently selected text segment in the html.

Methods

Clear()

Clear the content of the HTML container releasing any resources used to render previously existing content.

ClearSelection()

Clear the current selection.

CreateKeyEevent(KeyEventArgs) : RKeyEvent

Create HtmlRenderer key event from WPF key event.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

GetAttributeAt(Point, string) : string

Get attribute value of element at the given x,y location by given key. If more than one element exist with the attribute at the location the inner most is returned.

location
the location to find the attribute at
attribute
the attribute key to get value by

Returns: found attribute value or null if not found

GetElementRectangle(string) : Rect?

Get the Rect of html element as calculated by html layout. Element if found by id (id attribute on the html element). Note: to get the screen Rect you need to adjust by the hosting control.

elementId
the id of the element to get its Rect

Returns: the Rect of the element or null if not found

GetHtml(HtmlGenerationStyle) : string

Get html from the current DOM tree with style if requested.

styleGen
Optional: controls the way styles are generated when html is generated (default: Inline)

Returns: generated html

GetLinkAt(Point) : string

Get css link href at the given x,y location.

location
the location to find the link at

Returns: css link href if exists or null

HandleKeyDown(Control, KeyEventArgs)

Handle key down event for selection and copy.

parent
the control hosting the html to invalidate
e
the pressed key
HandleMouseDoubleClick(Control, MouseEventArgs)

Handle mouse double click to select word under the mouse.

parent
the control hosting the html to set cursor and invalidate
e
mouse event args
HandleMouseDown(Control, MouseEventArgs)

Handle mouse down to handle selection.

parent
the control hosting the html to invalidate
e
the mouse event args
HandleMouseLeave(Control)

Handle mouse leave to handle hover cursor.

parent
the control hosting the html to set cursor and invalidate
HandleMouseMove(Control, Point)

Handle mouse move to handle hover cursor and text selection.

parent
the control hosting the html to set cursor and invalidate
mousePos
the mouse event args
HandleMouseUp(Control, MouseButtonEventArgs)

Handle mouse up to handle selection and link click.

parent
the control hosting the html to invalidate
e
the mouse event args
PerformLayout()

Measures the bounds of box and children, recursively.

PerformPaint(DrawingContext, Rect)

Render the html using the given device.

g
the device to use to render
clip
the clip rectangle of the html container
SetHtml(string, CssData)

Init with optional document and stylesheet.

htmlSource
the html to init with, init empty if not given
baseCssData
optional: the stylesheet to init with, init default if not given

Events

ImageLoad : EventHandler<HtmlImageLoadEventArgs>

Raised when an image is about to be loaded by file path or URI. This event allows to provide the image manually, if not handled the image will be loaded from file or download from URI.

LinkClicked : EventHandler<HtmlLinkClickedEventArgs>

Raised when the user clicks on a link in the html. Allows canceling the execution of the link.

LoadComplete : EventHandler

Raised when the set html document has been fully loaded. Allows manipulation of the html dom, scroll position, etc.

Refresh : EventHandler<HtmlRefreshEventArgs>

Raised when html renderer requires refresh of the control hosting (invalidation and re-layout).

RenderError : EventHandler<HtmlRenderErrorEventArgs>

Raised when an error occurred during html rendering.

ScrollChange : EventHandler<HtmlScrollEventArgs>

Raised when Html Renderer request scroll to specific location. This can occur on document anchor click.

StylesheetLoad : EventHandler<HtmlStylesheetLoadEventArgs>

Raised when a stylesheet is about to be loaded by file path or URI by link element. This event allows to provide the stylesheet manually or provide new source (file or Uri) to load from. If no alternative data is provided the original source will be used.

Fields

_htmlContainerInt : HtmlContainerInt

The internal core html container