WindowExtensions
A set of useful extension methods for the Window class.
using AngleSharp.Css;
using AngleSharp.Dom;
using AngleSharp.Dom.Collections;
using AngleSharp.Dom.Css;
using System;
using System.Collections.Generic;
using System.Linq;
namespace AngleSharp.Extensions
{
internal static class WindowExtensions
{
public static CssStyleDeclaration ComputeDefaultStyle(this IWindow window, IElement element)
{
throw new NotImplementedException();
}
public static CssStyleDeclaration ComputeRawStyle(this IWindow window, IElement element)
{
throw new NotImplementedException();
}
public static CssStyleDeclaration ComputeUsedStyle(this IWindow window, IElement element)
{
throw new NotImplementedException();
}
public static CssStyleDeclaration ComputeCascadedStyle(this StyleCollection styleCollection, IElement element)
{
CssStyleDeclaration cssStyleDeclaration = new CssStyleDeclaration();
foreach (CssStyleRule item in styleCollection.SortBySpecifity(element)) {
CssStyleDeclaration style = item.Style;
cssStyleDeclaration.SetDeclarations(style.Declarations);
}
return cssStyleDeclaration;
}
public static StyleCollection GetStyleCollection(this IWindow window)
{
RenderDevice device = new RenderDevice(window.OuterWidth, window.OuterHeight);
return new StyleCollection(window.Document.GetStyleSheets().OfType<CssStyleSheet>(), device);
}
private static IEnumerable<CssStyleRule> SortBySpecifity(this IEnumerable<CssStyleRule> rules, IElement element)
{
return from m in rules
where m.Selector.Match(element)
orderby m.Selector.Specifity
select m;
}
}
}