public PresentationSourceFactory(HtmlRenderElementFactory htmlRenderElementFactory, HtmlValueConverter htmlValueConverter, ImageElementContainer imageElementContainer, SvgDefinitionContainer svgDefinitionContainer) { this.htmlRenderElementFactory = htmlRenderElementFactory; this.htmlValueConverter = htmlValueConverter; this.imageElementContainer = imageElementContainer; this.svgDefinitionContainer = svgDefinitionContainer; presentationSources = new List <PresentationSource>(); }
public static void SetHtmlOpacity(this HtmlElement element, double opacity, HtmlValueConverter converter) { if (opacity == 1.0) { element.ClearHtmlStyleProperty("opacity"); } else { element.SetHtmlStyleProperty("opacity", converter.ToImplicitValueString(opacity)); } }
public WebApplicationHost() { RenderQueue renderQueue = new RenderQueue(); HtmlValueConverter htmlValueConverter = new HtmlValueConverter(); SvgValueConverter svgValueConverter = new SvgValueConverter(); SvgDefinitionContainer svgDefinitionContainer = new SvgDefinitionContainer(renderQueue); ImageElementContainer imageElementContainer = new ImageElementContainer(); EmbeddedResourceObjectFactory embeddedResourceObjectFactory = new EmbeddedResourceObjectFactory(htmlValueConverter); HtmlRenderElementFactory htmlRenderElementFactory = new HtmlRenderElementFactory(renderQueue, htmlValueConverter, imageElementContainer, embeddedResourceObjectFactory, svgValueConverter, svgDefinitionContainer); PresentationSourceFactory = new PresentationSourceFactory(htmlRenderElementFactory, htmlValueConverter, imageElementContainer, svgDefinitionContainer); TaskScheduler = new TaskScheduler(); TextMeasurementService = new TextMeasurementService(htmlValueConverter); }
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 static string ToImageString(this HtmlValueConverter converter, Brush brush, Rect targetRect, IRenderElementFactory factory) { if (brush is LinearGradientBrush) { return(converter.ToImageString((LinearGradientBrush)brush, targetRect)); } if (brush is RadialGradientBrush) { return(converter.ToImageString((RadialGradientBrush)brush)); } if (brush is ImageBrush) { return(converter.ToImageString((ImageBrush)brush, factory)); } throw new Granular.Exception("Unexpected brush type \"{0}\"", brush.GetType()); }
public static void SetHtmlSize(this HtmlElement element, Size size, HtmlValueConverter converter) { if (size.Width.IsNaN()) { element.ClearHtmlStyleProperty("width"); } else { element.SetHtmlStyleProperty("width", converter.ToPixelString(size.Width)); } if (size.Height.IsNaN()) { element.ClearHtmlStyleProperty("height"); } else { element.SetHtmlStyleProperty("height", converter.ToPixelString(size.Height)); } }
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(); }
public static void SetHtmlLocation(this HtmlElement element, Point location, HtmlValueConverter converter) { element.SetHtmlStyleProperty("position", "absolute"); element.SetHtmlStyleProperty("left", converter.ToPixelString(location.X)); element.SetHtmlStyleProperty("top", converter.ToPixelString(location.Y)); }
public static void SetHtmlBorderBrush(this HtmlElement element, Brush borderBrush, Size targetSize, IRenderElementFactory factory, HtmlValueConverter converter) { element.ClearHtmlStyleProperty("border-color"); element.ClearHtmlStyleProperty("border-image-source"); if (borderBrush is SolidColorBrush) { element.SetHtmlStyleProperty("border-color", converter.ToColorString((SolidColorBrush)borderBrush)); } else if (borderBrush != null) { element.SetHtmlStyleProperty("border-image-source", converter.ToImageString(borderBrush, new Rect(targetSize), factory)); } }
public static void SetHtmlBounds(this HtmlElement element, Rect bounds, HtmlValueConverter converter) { element.SetHtmlLocation(bounds.Location, converter); element.SetHtmlSize(bounds.Size, converter); }
public static void SetHtmlBackgroundSize(this HtmlElement element, Size size, HtmlValueConverter converter) { if (Size.IsNullOrEmpty(size)) { element.ClearHtmlStyleProperty("background-size"); } else { element.SetHtmlStyleProperty("background-size", converter.ToPixelString(size)); } }
public static void SetHtmlBorderThickness(this HtmlElement element, Thickness borderThickness, HtmlValueConverter converter) { if (borderThickness == Thickness.Zero) { element.ClearHtmlStyleProperty("border-style"); element.ClearHtmlStyleProperty("border-width"); element.ClearHtmlStyleProperty("border-image-slice"); } else { element.SetHtmlStyleProperty("border-style", "solid"); element.SetHtmlStyleProperty("border-width", converter.ToPixelString(borderThickness)); element.SetHtmlStyleProperty("border-image-slice", converter.ToImplicitValueString(borderThickness)); } }
public EmbeddedResourceObjectFactory(HtmlValueConverter converter) { this.converter = converter; objectUrlCache = CacheDictionary <Uri, string> .CreateUsingStringKeys(ResolveObjectUrl, uri => uri.GetAbsoluteUri()); }
public static void SetHtmlFontFamily(this HtmlElement element, FontFamily fontFamily, HtmlValueConverter converter) { if (!fontFamily.FamilyNames.Any()) { element.ClearHtmlStyleProperty("font-family"); } else { element.SetHtmlStyleProperty("font-family", converter.ToFontFamilyNamesString(fontFamily)); } }
public static void SetHtmlBackgroundBounds(this HTMLElement element, Rect bounds, HtmlValueConverter converter) { element.SetHtmlBackgroundLocation(bounds.Location, converter); element.SetHtmlBackgroundSize(bounds.Size, converter); }
public static void SetHtmlBackgroundLocation(this HtmlElement element, Point location, HtmlValueConverter converter) { if (Point.IsNullOrEmpty(location)) { element.ClearHtmlStyleProperty("background-position"); } else { element.SetHtmlStyleProperty("background-position", converter.ToPixelString(location)); } }
public static void SetHtmlFontStretch(this HtmlElement element, System.Windows.FontStretch fontStretch, HtmlValueConverter converter) { if (fontStretch == System.Windows.FontStretch.Normal) { element.ClearHtmlStyleProperty("font-stretch"); } else { element.SetHtmlStyleProperty("font-stretch", converter.ToFontStretchString(fontStretch)); } }
public static void SetHtmlForeground(this HtmlElement element, Brush foreground, HtmlValueConverter converter) { if (foreground == null) { element.ClearHtmlStyleProperty("color"); } else if (foreground is SolidColorBrush) { element.SetHtmlStyleProperty("color", converter.ToColorString((SolidColorBrush)foreground)); } else { throw new Granular.Exception("A \"{0}\" foreground brush is not supported", foreground.GetType()); } }
public static void SetHtmlFontWeight(this HtmlElement element, FontWeight fontWeight, HtmlValueConverter converter) { if (fontWeight == FontWeight.Normal) { element.ClearHtmlStyleProperty("font-weight"); } else { element.SetHtmlStyleProperty("font-weight", converter.ToFontWeightString(fontWeight)); } }
public static void SetHtmlFontStyle(this HtmlElement element, System.Windows.FontStyle fontStyle, HtmlValueConverter converter) { if (fontStyle == System.Windows.FontStyle.Normal) { element.ClearHtmlStyleProperty("font-style"); } else { element.SetHtmlStyleProperty("font-style", converter.ToFontStyleString(fontStyle)); } }
public static void SetHtmlFontSize(this HtmlElement element, double fontSize, HtmlValueConverter converter) { if (fontSize.IsNaN()) { element.ClearHtmlStyleProperty("font-size"); } else { element.SetHtmlStyleProperty("font-size", converter.ToPixelString(fontSize)); } }
public static void SetHtmlBackground(this HtmlElement element, Brush background, Rect targetRect, IRenderElementFactory factory, HtmlValueConverter converter) { element.ClearHtmlStyleProperty("background-color"); element.ClearHtmlStyleProperty("background-image"); if (background is SolidColorBrush) { element.SetHtmlStyleProperty("background-color", converter.ToColorString((SolidColorBrush)background)); } else if (background != null) { element.SetHtmlStyleProperty("background-image", converter.ToImageString(background, targetRect, factory)); } }
public static void SetHtmlVerticalScrollBarVisibility(this HtmlElement element, ScrollBarVisibility scrollBarVisibility, HtmlValueConverter converter) { element.SetHtmlStyleProperty("overflow-y", converter.ToOverflowString(scrollBarVisibility)); }
public static void SetHtmlCornerRadius(this HtmlElement element, CornerRadius cornerRadius, HtmlValueConverter converter) { element.ClearHtmlStyleProperty("border-radius"); element.ClearHtmlStyleProperty("border-top-left-radius"); element.ClearHtmlStyleProperty("border-top-right-radius"); element.ClearHtmlStyleProperty("border-bottom-left-radius"); element.ClearHtmlStyleProperty("border-bottom-right-radius"); if (cornerRadius != CornerRadius.Zero) { if (cornerRadius.IsUniform) { element.SetHtmlStyleProperty("border-radius", converter.ToPixelString(cornerRadius.TopLeft)); } else { element.SetHtmlStyleProperty("border-top-left-radius", converter.ToPixelString(cornerRadius.TopLeft)); element.SetHtmlStyleProperty("border-top-right-radius", converter.ToPixelString(cornerRadius.TopRight)); element.SetHtmlStyleProperty("border-bottom-left-radius", converter.ToPixelString(cornerRadius.BottomLeft)); element.SetHtmlStyleProperty("border-bottom-right-radius", converter.ToPixelString(cornerRadius.BottomRight)); } } }
public static void SetHtmlBackgroundImage(this HtmlElement element, string url, HtmlValueConverter converter, IRenderElementFactory factory) { if (url.IsNullOrEmpty()) { element.ClearHtmlStyleProperty("background-image"); } else { element.SetHtmlStyleProperty("background-image", converter.ToUrlString(url)); } }
public static void SetHtmlTextAlignment(this HtmlElement element, TextAlignment textAlignment, HtmlValueConverter converter) { element.SetHtmlStyleProperty("text-align", converter.ToTextAlignmentString(textAlignment)); }
public static void SetHtmlTransform(this HtmlElement element, Matrix transform, HtmlValueConverter converter) { if (transform == Matrix.Identity) { element.ClearHtmlStyleProperty("transform"); element.ClearHtmlStyleProperty("transform-origin"); } else { element.SetHtmlStyleProperty("transform", converter.ToTransformString(transform)); element.SetHtmlStyleProperty("transform-origin", "0 0"); } }
public TextMeasurementService(HtmlValueConverter converter) { this.converter = converter; }
public static void SetHtmlTextWrapping(this HtmlElement element, TextWrapping textWrapping, HtmlValueConverter converter) { element.SetHtmlStyleProperty("white-space", converter.ToWhiteSpaceString(textWrapping)); }