Class HtmlContainer
- Namespace
- TheArtOfDev.HtmlRenderer.WPF
- Assembly
- StockSharp.Xaml.dll
Low level handling of Html Renderer logic, this class is used by HtmlParser,
HtmlLabel and HtmlRender.
public sealed class HtmlContainer : IDisposable
- Inheritance
-
HtmlContainer
- Implements
- Inherited Members
- Extension Methods
Constructors
HtmlContainer()
Init.
public HtmlContainer()
Properties
ActualSize
The actual size of the rendered html (after layout)
public Size ActualSize { get; }
Property Value
AvoidAsyncImagesLoading
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.
public bool AvoidAsyncImagesLoading { get; set; }
Property Value
Remarks
Asynchronously image loading allows to unblock html rendering while image is downloaded or loaded from disk using IO
ports to achieve better performance.
Asynchronously image loading should be avoided when the full html content must be available during render, like render to image.
AvoidImagesLateLoading
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.
public bool AvoidImagesLateLoading { get; set; }
Property Value
Remarks
Images late loading improve performance if the page contains image outside the visible scroll area, especially if there is large
amount of images, as all image loading is delayed (downloading and loading into memory).
Late image loading may effect the layout and actual size as image without set size will not have actual size until they are loaded
resulting in layout change during user scroll.
Early image loading may also effect the layout if image without known size above the current scroll location are loaded as they
will push the html elements down.
CssData
the parsed stylesheet data used for handling the html
public CssData CssData { get; }
Property Value
IsContextMenuEnabled
Is the build-in context menu enabled and will be shown on mouse right click (default - true)
public bool IsContextMenuEnabled { get; set; }
Property Value
IsSelectionEnabled
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.
public bool IsSelectionEnabled { get; set; }
Property Value
Location
The top-left most location of the rendered html.
This will offset the top-left corner of the rendered html.
public Point Location { get; set; }
Property Value
MaxSize
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).
public Size MaxSize { get; set; }
Property Value
ScrollOffset
The scroll offset of the html.
This will adjust the rendered html by the given offset so the content will be "scrolled".
public Point ScrollOffset { get; set; }
Property Value
Examples
Element that is rendered at location (50,100) with offset of (0,200) will not be rendered as it will be at -100 therefore outside the client Rect.
SelectedHtml
Copy the currently selected html segment with style.
public string SelectedHtml { get; }
Property Value
SelectedText
Get the currently selected text segment in the html.
public string SelectedText { get; }
Property Value
Methods
Clear()
Clear the content of the HTML container releasing any resources used to render previously existing content.
public void Clear()
ClearSelection()
Clear the current selection.
public void ClearSelection()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetAttributeAt(Point, 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.
public string GetAttributeAt(Point location, string attribute)
Parameters
location
Pointthe location to find the attribute at
attribute
stringthe attribute key to get value by
Returns
- string
found attribute value or null if not found
GetElementRectangle(string)
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.
public Rect? GetElementRectangle(string elementId)
Parameters
elementId
stringthe id of the element to get its Rect
Returns
- Rect?
the Rect of the element or null if not found
GetHtml(HtmlGenerationStyle)
Get html from the current DOM tree with style if requested.
public string GetHtml(HtmlGenerationStyle styleGen = HtmlGenerationStyle.Inline)
Parameters
styleGen
HtmlGenerationStyleOptional: controls the way styles are generated when html is generated (default: Inline)
Returns
- string
generated html
GetLinkAt(Point)
Get css link href at the given x,y location.
public string GetLinkAt(Point location)
Parameters
location
Pointthe location to find the link at
Returns
- string
css link href if exists or null
GetLinks()
Get all the links in the HTML with the element Rect and href data.
public List<LinkElementData<Rect>> GetLinks()
Returns
- List<LinkElementData<Rect>>
collection of all the links in the HTML
HandleKeyDown(Control, KeyEventArgs)
Handle key down event for selection and copy.
public void HandleKeyDown(Control parent, KeyEventArgs e)
Parameters
parent
Controlthe control hosting the html to invalidate
e
KeyEventArgsthe pressed key
HandleMouseDoubleClick(Control, MouseEventArgs)
Handle mouse double click to select word under the mouse.
public void HandleMouseDoubleClick(Control parent, MouseEventArgs e)
Parameters
parent
Controlthe control hosting the html to set cursor and invalidate
e
MouseEventArgsmouse event args
HandleMouseDown(Control, MouseEventArgs)
Handle mouse down to handle selection.
public void HandleMouseDown(Control parent, MouseEventArgs e)
Parameters
parent
Controlthe control hosting the html to invalidate
e
MouseEventArgsthe mouse event args
HandleMouseLeave(Control)
Handle mouse leave to handle hover cursor.
public void HandleMouseLeave(Control parent)
Parameters
parent
Controlthe control hosting the html to set cursor and invalidate
HandleMouseMove(Control, Point)
Handle mouse move to handle hover cursor and text selection.
public void HandleMouseMove(Control parent, Point mousePos)
Parameters
parent
Controlthe control hosting the html to set cursor and invalidate
mousePos
Pointthe mouse event args
HandleMouseUp(Control, MouseButtonEventArgs)
Handle mouse up to handle selection and link click.
public void HandleMouseUp(Control parent, MouseButtonEventArgs e)
Parameters
parent
Controlthe control hosting the html to invalidate
e
MouseButtonEventArgsthe mouse event args
PerformLayout()
Measures the bounds of box and children, recursively.
public void PerformLayout()
PerformPaint(DrawingContext, Rect)
Render the html using the given device.
public void PerformPaint(DrawingContext g, Rect clip)
Parameters
g
DrawingContextthe device to use to render
clip
Rectthe clip rectangle of the html container
SetHtml(string, CssData)
Init with optional document and stylesheet.
public void SetHtml(string htmlSource, CssData baseCssData = null)
Parameters
htmlSource
stringthe html to init with, init empty if not given
baseCssData
CssDataoptional: the stylesheet to init with, init default if not given
Events
ImageLoad
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.
public event EventHandler<HtmlImageLoadEventArgs> ImageLoad
Event Type
LinkClicked
Raised when the user clicks on a link in the html.
Allows canceling the execution of the link.
public event EventHandler<HtmlLinkClickedEventArgs> LinkClicked
Event Type
LoadComplete
Raised when the set html document has been fully loaded.
Allows manipulation of the html dom, scroll position, etc.
public event EventHandler LoadComplete
Event Type
Refresh
Raised when html renderer requires refresh of the control hosting (invalidation and re-layout).
public event EventHandler<HtmlRefreshEventArgs> Refresh
Event Type
Remarks
There is no guarantee that the event will be raised on the main thread, it can be raised on thread-pool thread.
RenderError
Raised when an error occurred during html rendering.
public event EventHandler<HtmlRenderErrorEventArgs> RenderError
Event Type
Remarks
There is no guarantee that the event will be raised on the main thread, it can be raised on thread-pool thread.
ScrollChange
Raised when Html Renderer request scroll to specific location.
This can occur on document anchor click.
public event EventHandler<HtmlScrollEventArgs> ScrollChange
Event Type
StylesheetLoad
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.
public event EventHandler<HtmlStylesheetLoadEventArgs> StylesheetLoad