Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
prepare committed Mar 18, 2019
2 parents 8ebde52 + 91711b8 commit e9bbc3d
Show file tree
Hide file tree
Showing 47 changed files with 1,229 additions and 436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace LayoutFarm.Composers
{
public abstract class CustomCssBoxGenerator
{
public abstract CssBox CreateCssBox(LayoutFarm.WebDom.DomElement tag,
public abstract CssBox CreateCssBox(HtmlElement tag,
CssBox parentBox,
BoxSpec spec,
HtmlHost host);
public static CssBox CreateWrapper(HtmlHost htmlhost,
object owner,
RenderElement renderElement,
public static CssBox CreateCssWrapper(HtmlHost htmlhost,
object owner,
RenderElement renderElement,
BoxSpec spec,
bool isInline)
{
Expand Down
38 changes: 13 additions & 25 deletions Source/LayoutFarm.HtmlComposer/1_Composers/1_Builder/HtmlHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,14 @@ public void UpdateChildBoxes(WebDom.Impl.HtmlElement parentElement, bool fullmod
//for public
UpdateChildBoxes((HtmlElement)parentElement, fullmode);
}
public CssBox CreateBox(CssBox parentBox, WebDom.Impl.HtmlElement childElement, bool fullmode)
public CssBox CreateCssBox(CssBox parentBox, WebDom.Impl.HtmlElement childElement, bool fullmode)
{
return CreateBoxInternal(parentBox, (HtmlElement)childElement, fullmode);
return CreateCssBoxInternal(parentBox, (HtmlElement)childElement, fullmode);
}
//-------------



//
internal void ChildRequestImage(ImageBinder binder, HtmlVisualRoot visualRoot, object reqFrom, bool _sync)
internal void ChildRequestImage(ImageBinder binder, object reqFrom)
{
if (_requestImage != null)
{
Expand All @@ -224,10 +222,9 @@ internal void ChildRequestImage(ImageBinder binder, HtmlVisualRoot visualRoot, o
_requestImage(this, resReq);
}
}
internal ITextService GetTextService()
{
return _textservice;
}

internal ITextService GetTextService() => _textservice;

internal void EnqueueCssUpdate(CssBox box)
{
_waitForUpdateBoxes.Add(box);
Expand Down Expand Up @@ -379,14 +376,14 @@ internal void UpdateChildBoxes(HtmlElement parentElement, bool fullmode)

if (fullmode)
{
CssBox box = CreateBoxInternal(hostBox, childElement, fullmode);
CssBox box = CreateCssBoxInternal(hostBox, childElement, fullmode);
}
else
{
CssBox existingCssBox = HtmlElement.InternalGetPrincipalBox(childElement);
if (existingCssBox == null)
{
CreateBoxInternal(hostBox, childElement, fullmode);
CreateCssBoxInternal(hostBox, childElement, fullmode);
}
else
{
Expand Down Expand Up @@ -427,10 +424,9 @@ internal void UpdateChildBoxes(HtmlElement parentElement, bool fullmode)

CssBox CreateBoxInternal(HtmlElement parentElement, HtmlElement childElement, bool fullmode)
{
CssBox hostBox = HtmlElement.InternalGetPrincipalBox(parentElement);
return CreateBoxInternal(hostBox, childElement, fullmode);
return CreateCssBoxInternal(HtmlElement.InternalGetPrincipalBox(parentElement), childElement, fullmode);
}
CssBox CreateBoxInternal(CssBox parentBox, HtmlElement childElement, bool fullmode)
CssBox CreateCssBoxInternal(CssBox parentBox, HtmlElement childElement, bool fullmode)
{
//-----------------------------------------
//1. create new box
Expand Down Expand Up @@ -493,17 +489,9 @@ CssBox CreateBoxInternal(CssBox parentBox, HtmlElement childElement, bool fullmo
break;
//---------------------------------------------------
case WellKnownDomNodeName.select:
newBox = this.CreateCustomCssBox(parentBox, childElement, childElement.Spec);
if (newBox != null)
{
childElement.SetPrincipalBox(newBox);
return newBox;
}
goto default; //else goto default ***
case WellKnownDomNodeName.canvas:
case WellKnownDomNodeName.input:

newBox = this.CreateCustomCssBox(parentBox, childElement, childElement.Spec);
newBox = CreateCustomCssBox(parentBox, childElement, childElement.Spec);
if (newBox != null)
{
childElement.SetPrincipalBox(newBox);
Expand Down Expand Up @@ -610,12 +598,12 @@ CssBox CreateImageBox(CssBox parent, HtmlElement childElement)


CssBox CreateCustomCssBox(CssBox parent,
LayoutFarm.WebDom.DomElement tag,
HtmlElement htmlElem,
BoxSpec boxspec)
{
for (int i = _generators.Count - 1; i >= 0; --i)
{
CssBox newbox = _generators[i].CreateCssBox(tag, parent, boxspec, this);
CssBox newbox = _generators[i].CreateCssBox(htmlElem, parent, boxspec, this);
if (newbox != null)
{
return newbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public override void ClearAllChildren()
}
protected override void DrawBoxContent(DrawBoard canvas, Rectangle updateArea)
{
//TODO: review here,


//TODO: review here,
if (_myHtmlVisualRoot == null) { return; }

bool useBackbuffer = canvas.IsGpuDrawBoard;
Expand Down Expand Up @@ -72,7 +70,7 @@ protected override void DrawBoxContent(DrawBoard canvas, Rectangle updateArea)

float backupViewportW = painter.ViewportWidth; //backup
float backupViewportH = painter.ViewportHeight; //backup

painter.AttachTo(_builtInBackBuffer); //*** switch to builtInBackbuffer
painter.SetViewportSize(this.Width, this.Height);

Expand All @@ -81,20 +79,27 @@ protected override void DrawBoxContent(DrawBoard canvas, Rectangle updateArea)
_invalidateRect = new Rectangle(0, 0, Width, Height);
}

painter.PushLocalClipArea(
#if DEBUG
//System.Diagnostics.Debug.WriteLine("inv_rect:" + _invalidateRect + "," + painter.ToString());
#endif
if (painter.PushLocalClipArea(
_invalidateRect.Left, _invalidateRect.Top,
_invalidateRect.Width, _invalidateRect.Height);
_invalidateRect.Width, _invalidateRect.Height))
{


//for debug , test clear with random color
#if DEBUG
//painter.Clear(Color.FromArgb(255, dbugRandom.Next(0, 255), dbugRandom.Next(0, 255), dbugRandom.Next(0, 255)));
//for debug , test clear with random color
//another useful technique to see latest clear area frame-by-frame => use random color
painter.Clear(Color.FromArgb(255, dbugRandom.Next(0, 255), dbugRandom.Next(0, 255), dbugRandom.Next(0, 255)));
#endif
painter.Clear(Color.White);
//painter.Clear(Color.White);

_myHtmlVisualRoot.PerformPaint(painter);
_myHtmlVisualRoot.PerformPaint(painter);
}

painter.PopLocalClipArea();

//
_builtInBackBuffer.IsValid = true;
_hasAccumRect = false;

Expand Down Expand Up @@ -139,8 +144,15 @@ protected override void DrawBoxContent(DrawBoard canvas, Rectangle updateArea)
#if DEBUG
//System.Diagnostics.Debug.WriteLine(">> 500x500");
painter.dbugDrawDiagonalBox(Color.Blue, this.X, this.Y, this.Width, this.Height);

//for debug , test clear with random color
//another useful technique to see latest clear area frame-by-frame => use random color
//painter.Clear(Color.FromArgb(255, dbugRandom.Next(0, 255), dbugRandom.Next(0, 255), dbugRandom.Next(0, 255)));
#endif

#if DEBUG
System.Diagnostics.Debug.WriteLine("inv_rect:" + _invalidateRect + "," + painter.ToString());
#endif
//painter.SetClipRect(new Rectangle(0, 0, 200, 200));
_myHtmlVisualRoot.PerformPaint(painter);
#if DEBUG
Expand All @@ -159,14 +171,18 @@ public override void ChildrenHitTestCore(HitChain hitChain)
//
public int HtmlHeight => (int)_myHtmlVisualRoot.ActualHeight;
//
protected override void OnInvalidateGraphicsNoti(Rectangle totalBounds)
protected override void OnInvalidateGraphicsNoti(bool fromMe, ref Rectangle totalBounds)
{
#if DEBUG

#endif
//------
if (_builtInBackBuffer != null)
{
//TODO: review here,
//in this case, we copy to another rect
//since we don't want the offset to effect the total bounds
if (!fromMe)
{
totalBounds.Offset(-this.X, -this.Y);
}

_builtInBackBuffer.IsValid = false;

if (!_hasAccumRect)
Expand All @@ -179,10 +195,12 @@ protected override void OnInvalidateGraphicsNoti(Rectangle totalBounds)
_invalidateRect = Rectangle.Union(_invalidateRect, totalBounds);
}
}

else
{
totalBounds.Offset(this.X, this.Y);
}
//base.OnInvalidateGraphicsNoti(totalBounds);//skip
}

}
}

static class PaintVisitorStock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ public override void ContainerInvalidateGraphics()
{
_containerInvalidateGfxHandler(this, EventArgs.Empty);
}
protected override void OnRequestImage(ImageBinder binder, object reqFrom, bool _sync)
protected override void OnRequestImage(ImageBinder binder, object reqFrom)
{
//send request to host
if (binder.State == BinderState.Unload)
{
_htmlhost.ChildRequestImage(binder, this, reqFrom, _sync);
_htmlhost.ChildRequestImage(binder, reqFrom);
}
}
protected override void OnRequestScrollView(CssBox box)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void SetInnerBox(CssBox innerBox)
//add relation between viewpanel and scroll bar
_vscRelation = new ScrollingRelation(_vscbar.SliderBox, _scrollView);
//----------------------
CssBox scBarWrapCssBox = LayoutFarm.Composers.CustomCssBoxGenerator.CreateWrapper(
CssBox scBarWrapCssBox = LayoutFarm.Composers.CustomCssBoxGenerator.CreateCssWrapper(
_htmlhost,
_vscbar,
_vscbar.GetPrimaryRenderElement((RootGraphic)this.GetInternalRootGfx()),
Expand All @@ -89,7 +89,7 @@ public void SetInnerBox(CssBox innerBox)
_hscRelation = new ScrollingRelation(_hscbar.SliderBox, _scrollView);
//----------------------

CssBox scBarWrapCssBox = LayoutFarm.Composers.CustomCssBoxGenerator.CreateWrapper(
CssBox scBarWrapCssBox = LayoutFarm.Composers.CustomCssBoxGenerator.CreateCssWrapper(
_htmlhost,
_hscbar,
_hscbar.GetPrimaryRenderElement((RootGraphic)this.GetInternalRootGfx()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public static RootGraphic GetInternalRootGfx(this CssBox cssbox)

class CssIsolateBox : CssBox
{

public CssIsolateBox(BoxSpec spec, RootGraphic rootgfx)
: base(spec, new CssBoxRootGfxBridge(rootgfx))
{
Expand All @@ -40,17 +39,8 @@ class RenderElementBridgeCssBox : CssBox
{
_containerElement = containerElement;
}
public override void InvalidateGraphics(Rectangle clientArea)
{
//send to container element
//#if DEBUG
// System.Diagnostics.Debug.WriteLine("re-bridge_cssbox_invalidateGfx:" + clientArea.ToString());
//#endif
//clientArea.Offset(_containerElement.X, _containerElement.Y);
_containerElement.InvalidateParentGraphics(clientArea);
}
public override void InvalidateGraphics(Rectangle clientArea) => _containerElement.InvalidateParentGraphics(clientArea);
public LayoutFarm.RenderElement ContainerElement => _containerElement;

protected override void GetGlobalLocationImpl(out float globalX, out float globalY)
{
Point p = _containerElement.GetGlobalLocation();
Expand Down
54 changes: 48 additions & 6 deletions Source/LayoutFarm.HtmlComposer/4_WebDom/HtmlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using LayoutFarm.WebDom;
namespace LayoutFarm.Composers
{

public class HtmlDocument : LayoutFarm.WebDom.Impl.HtmlDocument
{
//implementation specific...
//foc custom elements
Dictionary<string, CreateCssBoxDelegate> _registeredCustomElemenGens = new Dictionary<string, CreateCssBoxDelegate>();
internal HtmlDocument(HtmlBoxes.HtmlHost host)
Expand All @@ -23,19 +25,53 @@ internal HtmlDocument(HtmlBoxes.HtmlHost host, UniqueStringTable sharedUniqueStr
this.SetRootElement(new HtmlRootElement(this));
//TODO: test only
#if DEBUG
this.RegisterCustomElement("fivespace", CustomBoxGenSample1.CreateCssBox);
this.RegisterCustomElement("custom_div", CustomBoxGenSample1.CreateCssBox);
#endif
}

internal HtmlBoxes.HtmlHost Host { get; private set; }

public override DomElement CreateElement(string prefix, string localName)
{
//actual implementation
var htmlElement = new HtmlElement(this,
AddStringIfNotExists(prefix),
AddStringIfNotExists(localName));
htmlElement.WellknownElementName = WellKnownDomNodeMap.EvaluateTagName(htmlElement.LocalName);
//actual dom implementation ***

HtmlElement htmlElement = null;
switch (localName)
{
case "img":
{
htmlElement = new HtmlImageElement(
this,
AddStringIfNotExists(prefix),
AddStringIfNotExists(localName));
}
break;
case "input":
{
//input type
htmlElement = new HtmlInputElement(
this,
AddStringIfNotExists(prefix),
AddStringIfNotExists(localName));
}
break;
case "option":
{
htmlElement = new HtmlOptionElement(
this,
AddStringIfNotExists(prefix),
AddStringIfNotExists(localName));
}
break;
default:
{
htmlElement = new HtmlElement(this,
AddStringIfNotExists(prefix),
AddStringIfNotExists(localName));
htmlElement.WellknownElementName = WellKnownDomNodeMap.EvaluateTagName(htmlElement.LocalName);
}
break;
}
return htmlElement;
}
public override DomNode CreateDocumentNodeElement()
Expand Down Expand Up @@ -78,5 +114,11 @@ public bool TryGetCustomBoxGenerator(string customElementName, out CreateCssBoxD
{
return _registeredCustomElemenGens.TryGetValue(customElementName, out cssBoxGen);
}
public ImageBinder GetImageBinder(string imgurl)
{
ImageBinder imgBinder = new ImageBinder(imgurl);
Host.ChildRequestImage(imgBinder, null);
return imgBinder;
}
}
}
Loading

0 comments on commit e9bbc3d

Please sign in to comment.