public void InsertChild(int index, object child) { IHtmlRenderElement childElement = (IHtmlRenderElement)child; if (child is IHtmlDeferredRenderElement) { ((IHtmlDeferredRenderElement)child).HtmlElementCreated += OnChildHtmlElementCreated; } if (IsLoaded) { childElement.Load(); } children.Insert(index, childElement); if (childElement.HtmlElement != null) { if (index > lastDeferredChildIndex) { index = index - deferredChildrenCount; } else { lastDeferredChildIndex++; index = children.Take(index).Count(c => c.HtmlElement != null); } renderQueue.InvokeAsync(() => HtmlElement.InsertChild(index, childElement.HtmlElement)); } else { lastDeferredChildIndex = lastDeferredChildIndex.Max(index); deferredChildrenCount++; } }
public PresentationSource(UIElement rootElement, HtmlRenderElementFactory htmlRenderElementFactory, HtmlValueConverter converter, ImageElementContainer imageElementContainer, SvgDefinitionContainer svgDefinitionContainer) { this.RootElement = rootElement; this.converter = converter; RootElement.IsRootElement = true; MouseDevice = new MouseDevice(this); KeyboardDevice = new KeyboardDevice(this); window = Bridge.Html5.Window.Instance; MouseDevice.CursorChanged += (sender, e) => Bridge.Html5.Window.Document.Body.SetHtmlStyleProperty("cursor", converter.ToCursorString(MouseDevice.Cursor, htmlRenderElementFactory)); Bridge.Html5.Window.Document.Body.SetHtmlStyleProperty("cursor", converter.ToCursorString(MouseDevice.Cursor, htmlRenderElementFactory)); Bridge.Html5.Window.OnKeyDown = OnKeyDown; Bridge.Html5.Window.OnKeyUp = OnKeyUp; Bridge.Html5.Window.OnKeyPress = PreventKeyboardHandled; Bridge.Html5.Window.OnMouseMove = OnMouseMove; Bridge.Html5.Window.OnMouseDown = OnMouseDown; Bridge.Html5.Window.OnMouseUp = OnMouseUp; Bridge.Html5.Window.OnScroll = OnMouseWheel; Bridge.Html5.Window.OnFocus = e => MouseDevice.Activate(); Bridge.Html5.Window.OnBlur = e => MouseDevice.Deactivate(); Bridge.Html5.Window.OnResize = e => SetRootElementSize(); Bridge.Html5.Window.OnClick = PreventMouseHandled; Bridge.Html5.Window.OnContextMenu = PreventMouseHandled; Bridge.Html5.Window.AddEventListener("ondblclick", PreventMouseHandled); Bridge.Html5.Window.AddEventListener("wheel", OnMouseWheel); SetRootElementSize(); ((FrameworkElement)RootElement).Arrange(new Rect(window.InnerWidth, window.InnerHeight)); IHtmlRenderElement renderElement = ((IHtmlRenderElement)RootElement.GetRenderElement(htmlRenderElementFactory)); renderElement.Load(); Bridge.Html5.Window.Document.Body.Style.Overflow = Overflow.Hidden; Bridge.Html5.Window.Document.Body.AppendChild(imageElementContainer.HtmlElement); Bridge.Html5.Window.Document.Body.AppendChild(svgDefinitionContainer.HtmlElement); Bridge.Html5.Window.Document.Body.AppendChild(renderElement.HtmlElement); MouseDevice.Activate(); KeyboardDevice.Activate(); }
public PresentationSource( UIElement rootElement, HtmlRenderElementFactory htmlRenderElementFactory, HtmlValueConverter converter, ImageElementContainer imageElementContainer, SvgDefinitionContainer svgDefinitionContainer) { // TODO: Set SynchronizationContext so that all messages get flushed when async callbacks get completed this.RootElement = rootElement; this.converter = converter; RootElement.IsRootElement = true; MouseDevice = new MouseDevice(this); KeyboardDevice = new KeyboardDevice(this); MouseDevice.CursorChanged += (sender, e) => Window.Body.SetHtmlStyleProperty("cursor", converter.ToCursorString(MouseDevice.Cursor, htmlRenderElementFactory)); Window.Body.SetHtmlStyleProperty("cursor", converter.ToCursorString(MouseDevice.Cursor, htmlRenderElementFactory)); Window.SetApplicationListener(this); var dimensions = SetRootElementSize(); ((FrameworkElement)RootElement).Arrange(new Rect(dimensions.width, dimensions.height)); IHtmlRenderElement renderElement = ((IHtmlRenderElement)RootElement.GetRenderElement(htmlRenderElementFactory)); renderElement.Load(); Window.Body.SetHtmlStyleProperty("overflow", "hidden"); Window.Body.AppendChild(imageElementContainer.HtmlElement); Window.Body.AppendChild(svgDefinitionContainer.HtmlElement); Window.Body.AppendChild(renderElement.HtmlElement); MouseDevice.Activate(); KeyboardDevice.Activate(); }