Skip to content

Commit 013a36c

Browse files
author
ArthurHub
committed
add LoadComplete event on when set html if fully parsed and layouted
1 parent 103232b commit 013a36c

9 files changed

Lines changed: 147 additions & 22 deletions

File tree

‎Source/Demo/WPF/MainControl.xaml.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public MainControl()
6363
_htmlPanel.LinkClicked += OnLinkClicked;
6464
_htmlPanel.StylesheetLoad += HtmlRenderingHelper.OnStylesheetLoad;
6565
_htmlPanel.ImageLoad += HtmlRenderingHelper.OnImageLoad;
66+
_htmlPanel.LoadComplete += (sender, args) => _htmlPanel.ScrollToElement("C4");
6667

6768
_htmlTooltipLabel.AvoidImagesLateLoading = true;
6869
_htmlTooltipLabel.StylesheetLoad += HtmlRenderingHelper.OnStylesheetLoad;

‎Source/Demo/WinForms/MainControl.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public MainControl()
5858
_htmlPanel.StylesheetLoad += DemoUtils.OnStylesheetLoad;
5959
_htmlPanel.ImageLoad += HtmlRenderingHelper.OnImageLoad;
6060
_htmlToolTip.ImageLoad += HtmlRenderingHelper.OnImageLoad;
61+
_htmlPanel.LoadComplete += (sender, args) => _htmlPanel.ScrollToElement("C4");
6162

6263
_htmlToolTip.SetToolTip(_htmlPanel, Resources.Tooltip);
6364

‎Source/HtmlRenderer.PdfSharp/HtmlContainer.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public HtmlContainer()
4747
_htmlContainerInt.AvoidImagesLateLoading = true;
4848
}
4949

50+
/// <summary>
51+
/// Raised when the set html document has been fully loaded.<br/>
52+
/// Allows manipulation of the html dom, scroll position, etc.
53+
/// </summary>
54+
public event EventHandler LoadComplete
55+
{
56+
add { _htmlContainerInt.LoadComplete += value; }
57+
remove { _htmlContainerInt.LoadComplete -= value; }
58+
}
59+
5060
/// <summary>
5161
/// Raised when an error occurred during html rendering.<br/>
5262
/// </summary>

‎Source/HtmlRenderer.WPF/HtmlContainer.cs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ public HtmlContainer()
5151
_htmlContainerInt = new HtmlContainerInt(WpfAdapter.Instance);
5252
}
5353

54+
/// <summary>
55+
/// Raised when the set html document has been fully loaded.<br/>
56+
/// Allows manipulation of the html dom, scroll position, etc.
57+
/// </summary>
58+
public event EventHandler LoadComplete
59+
{
60+
add { _htmlContainerInt.LoadComplete += value; }
61+
remove { _htmlContainerInt.LoadComplete -= value; }
62+
}
63+
5464
/// <summary>
5565
/// Raised when the user clicks on a link in the html.<br/>
5666
/// Allows canceling the execution of the link.
@@ -407,7 +417,7 @@ public void HandleMouseDoubleClick(Control parent, MouseEventArgs e)
407417
public void HandleMouseMove(Control parent, Point mousePos)
408418
{
409419
ArgChecker.AssertArgNotNull(parent, "parent");
410-
420+
411421
_htmlContainerInt.HandleMouseMove(new ControlAdapter(parent), Utils.Convert(mousePos));
412422
}
413423

‎Source/HtmlRenderer.WPF/HtmlControl.cs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class HtmlControl : Control
8181
public static readonly DependencyProperty BaseStylesheetProperty = DependencyProperty.Register("BaseStylesheet", typeof(string), typeof(HtmlControl), new PropertyMetadata(null, OnDependencyProperty_valueChanged));
8282
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(HtmlControl), new PropertyMetadata(null, OnDependencyProperty_valueChanged));
8383

84+
public static readonly RoutedEvent LoadCompleteEvent = EventManager.RegisterRoutedEvent("LoadComplete", RoutingStrategy.Bubble, typeof(RoutedEventHandler<EventArgs>), typeof(HtmlControl));
8485
public static readonly RoutedEvent LinkClickedEvent = EventManager.RegisterRoutedEvent("LinkClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler<HtmlLinkClickedEventArgs>), typeof(HtmlControl));
8586
public static readonly RoutedEvent RenderErrorEvent = EventManager.RegisterRoutedEvent("RenderError", RoutingStrategy.Bubble, typeof(RoutedEventHandler<HtmlRenderErrorEventArgs>), typeof(HtmlControl));
8687
public static readonly RoutedEvent RefreshEvent = EventManager.RegisterRoutedEvent("Refresh", RoutingStrategy.Bubble, typeof(RoutedEventHandler<HtmlRefreshEventArgs>), typeof(HtmlControl));
@@ -99,13 +100,24 @@ protected HtmlControl()
99100
SnapsToDevicePixels = false;
100101

101102
_htmlContainer = new HtmlContainer();
103+
_htmlContainer.LoadComplete += OnLoadComplete;
102104
_htmlContainer.LinkClicked += OnLinkClicked;
103105
_htmlContainer.RenderError += OnRenderError;
104106
_htmlContainer.Refresh += OnRefresh;
105107
_htmlContainer.StylesheetLoad += OnStylesheetLoad;
106108
_htmlContainer.ImageLoad += OnImageLoad;
107109
}
108110

111+
/// <summary>
112+
/// Raised when the set html document has been fully loaded.<br/>
113+
/// Allows manipulation of the html dom, scroll position, etc.
114+
/// </summary>
115+
public event RoutedEventHandler LoadComplete
116+
{
117+
add { AddHandler(LoadCompleteEvent, value); }
118+
remove { RemoveHandler(LoadCompleteEvent, value); }
119+
}
120+
109121
/// <summary>
110122
/// Raised when the user clicks on a link in the html.<br/>
111123
/// Allows canceling the execution of the link.
@@ -371,6 +383,15 @@ protected override void OnKeyDown(KeyEventArgs e)
371383
_htmlContainer.HandleKeyDown(this, e);
372384
}
373385

386+
/// <summary>
387+
/// Propagate the LoadComplete event from root container.
388+
/// </summary>
389+
protected virtual void OnLoadComplete(EventArgs e)
390+
{
391+
RoutedEventArgs newEventArgs = new RoutedEvenArgs<EventArgs>(LoadCompleteEvent, this, e);
392+
RaiseEvent(newEventArgs);
393+
}
394+
374395
/// <summary>
375396
/// Propagate the LinkClicked event from root container.
376397
/// </summary>
@@ -482,6 +503,14 @@ private static void OnDependencyProperty_valueChanged(DependencyObject dependenc
482503

483504
#region Private event handlers
484505

506+
private void OnLoadComplete(object sender, EventArgs e)
507+
{
508+
if (CheckAccess())
509+
OnLoadComplete(e);
510+
else
511+
Dispatcher.Invoke(new Action<HtmlLinkClickedEventArgs>(OnLinkClicked), e);
512+
}
513+
485514
private void OnLinkClicked(object sender, HtmlLinkClickedEventArgs e)
486515
{
487516
if (CheckAccess())

‎Source/HtmlRenderer.WinForms/HtmlContainer.cs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public HtmlContainer()
5555
_htmlContainerInt = new HtmlContainerInt(WinFormsAdapter.Instance);
5656
}
5757

58+
/// <summary>
59+
/// Raised when the set html document has been fully loaded.<br/>
60+
/// Allows manipulation of the html dom, scroll position, etc.
61+
/// </summary>
62+
public event EventHandler LoadComplete
63+
{
64+
add { HtmlContainerInt.LoadComplete += value; }
65+
remove { HtmlContainerInt.LoadComplete -= value; }
66+
}
67+
5868
/// <summary>
5969
/// Raised when the user clicks on a link in the html.<br/>
6070
/// Allows canceling the execution of the link.

‎Source/HtmlRenderer.WinForms/HtmlLabel.cs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public HtmlLabel()
132132
_htmlContainer = new HtmlContainer();
133133
_htmlContainer.AvoidImagesLateLoading = true;
134134
_htmlContainer.MaxSize = MaximumSize;
135+
_htmlContainer.LoadComplete += OnLoadComplete;
135136
_htmlContainer.LinkClicked += OnLinkClicked;
136137
_htmlContainer.RenderError += OnRenderError;
137138
_htmlContainer.Refresh += OnRefresh;
@@ -147,6 +148,12 @@ public HtmlLabel()
147148
[Category("Property Changed")]
148149
public event EventHandler BorderStyleChanged;
149150

151+
/// <summary>
152+
/// Raised when the set html document has been fully loaded.<br/>
153+
/// Allows manipulation of the html dom, scroll position, etc.
154+
/// </summary>
155+
public event EventHandler LoadComplete;
156+
150157
/// <summary>
151158
/// Raised when the user clicks on a link in the html.<br/>
152159
/// Allows canceling the execution of the link.
@@ -578,6 +585,16 @@ protected virtual void OnBorderStyleChanged(EventArgs e)
578585
handler(this, e);
579586
}
580587

588+
/// <summary>
589+
/// Propagate the LoadComplete event from root container.
590+
/// </summary>
591+
protected virtual void OnLoadComplete(EventArgs e)
592+
{
593+
var handler = LoadComplete;
594+
if (handler != null)
595+
handler(this, e);
596+
}
597+
581598
/// <summary>
582599
/// Propagate the LinkClicked event from root container.
583600
/// </summary>
@@ -661,6 +678,7 @@ protected override void Dispose(bool disposing)
661678
{
662679
if (_htmlContainer != null)
663680
{
681+
_htmlContainer.LoadComplete -= OnLoadComplete;
664682
_htmlContainer.LinkClicked -= OnLinkClicked;
665683
_htmlContainer.RenderError -= OnRenderError;
666684
_htmlContainer.Refresh -= OnRefresh;
@@ -675,6 +693,11 @@ protected override void Dispose(bool disposing)
675693

676694
#region Private event handlers
677695

696+
private void OnLoadComplete(object sender, EventArgs e)
697+
{
698+
OnLoadComplete(e);
699+
}
700+
678701
private void OnLinkClicked(object sender, HtmlLinkClickedEventArgs e)
679702
{
680703
OnLinkClicked(e);

‎Source/HtmlRenderer.WinForms/HtmlPanel.cs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public HtmlPanel()
119119
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
120120

121121
_htmlContainer = new HtmlContainer();
122+
_htmlContainer.LoadComplete += OnLoadComplete;
122123
_htmlContainer.LinkClicked += OnLinkClicked;
123124
_htmlContainer.RenderError += OnRenderError;
124125
_htmlContainer.Refresh += OnRefresh;
@@ -133,6 +134,12 @@ public HtmlPanel()
133134
[Category("Property Changed")]
134135
public event EventHandler BorderStyleChanged;
135136

137+
/// <summary>
138+
/// Raised when the set html document has been fully loaded.<br/>
139+
/// Allows manipulation of the html dom, scroll position, etc.
140+
/// </summary>
141+
public event EventHandler LoadComplete;
142+
136143
/// <summary>
137144
/// Raised when the user clicks on a link in the html.<br/>
138145
/// Allows canceling the execution of the link.
@@ -617,6 +624,16 @@ protected virtual void OnBorderStyleChanged(EventArgs e)
617624
}
618625
}
619626

627+
/// <summary>
628+
/// Propagate the LoadComplete event from root container.
629+
/// </summary>
630+
protected virtual void OnLoadComplete(EventArgs e)
631+
{
632+
var handler = LoadComplete;
633+
if (handler != null)
634+
handler(this, e);
635+
}
636+
620637
/// <summary>
621638
/// Propagate the LinkClicked event from root container.
622639
/// </summary>
@@ -758,6 +775,7 @@ protected override void Dispose(bool disposing)
758775
{
759776
if (_htmlContainer != null)
760777
{
778+
_htmlContainer.LoadComplete -= OnLoadComplete;
761779
_htmlContainer.LinkClicked -= OnLinkClicked;
762780
_htmlContainer.RenderError -= OnRenderError;
763781
_htmlContainer.Refresh -= OnRefresh;
@@ -773,6 +791,11 @@ protected override void Dispose(bool disposing)
773791

774792
#region Private event handlers
775793

794+
private void OnLoadComplete(object sender, EventArgs e)
795+
{
796+
OnLoadComplete(e);
797+
}
798+
776799
private void OnLinkClicked(object sender, HtmlLinkClickedEventArgs e)
777800
{
778801
OnLinkClicked(e);

0 commit comments

Comments
 (0)