From dbfec4e82a9227269e27df722c5a6907db56b8bd Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Mon, 7 Jan 2019 21:45:49 +0100 Subject: [PATCH 01/49] Updated reference --- CHANGELOG.md | 7 +++++++ build.cake | 3 --- src/AngleSharp.Css.nuspec | 2 +- src/AngleSharp.Css/AngleSharp.Css.csproj | 3 +-- .../AngleSharp.Performance.Css.csproj | 1 - 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66477500..3afe2649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 0.10.1 + +Released on Monday, January 7 2019. + +- Reference latest AngleSharp +- Updated reference to `System.Encoding.CodePages` (#13) + # 0.10.0 Released on Friday, January 4 2019. diff --git a/build.cake b/build.cake index da10a4bc..d48ce935 100644 --- a/build.cake +++ b/build.cake @@ -16,7 +16,6 @@ using Octokit; var target = Argument("target", "Default"); var configuration = Argument("configuration", "Release"); -var isLocal = BuildSystem.IsLocalBuild; var isRunningOnUnix = IsRunningOnUnix(); var isRunningOnWindows = IsRunningOnWindows(); var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor; @@ -140,7 +139,6 @@ Task("Create-Package") Task("Publish-Package") .IsDependentOn("Create-Package") - .WithCriteria(() => isLocal) .Does(() => { var apiKey = EnvironmentVariable("NUGET_API_KEY"); @@ -162,7 +160,6 @@ Task("Publish-Package") Task("Publish-Release") .IsDependentOn("Publish-Package") - .WithCriteria(() => isLocal) .Does(() => { var githubToken = EnvironmentVariable("GITHUB_API_TOKEN"); diff --git a/src/AngleSharp.Css.nuspec b/src/AngleSharp.Css.nuspec index 02a01122..695a75fc 100644 --- a/src/AngleSharp.Css.nuspec +++ b/src/AngleSharp.Css.nuspec @@ -14,7 +14,7 @@ Copyright 2016-2019, AngleSharp html html5 css css3 dom styling library anglesharp angle - + diff --git a/src/AngleSharp.Css/AngleSharp.Css.csproj b/src/AngleSharp.Css/AngleSharp.Css.csproj index 5a4624fa..7b03ca05 100644 --- a/src/AngleSharp.Css/AngleSharp.Css.csproj +++ b/src/AngleSharp.Css/AngleSharp.Css.csproj @@ -10,8 +10,7 @@ - - + diff --git a/src/AngleSharp.Performance.Css/AngleSharp.Performance.Css.csproj b/src/AngleSharp.Performance.Css/AngleSharp.Performance.Css.csproj index 221c9495..12689649 100644 --- a/src/AngleSharp.Performance.Css/AngleSharp.Performance.Css.csproj +++ b/src/AngleSharp.Performance.Css/AngleSharp.Performance.Css.csproj @@ -16,7 +16,6 @@ - \ No newline at end of file From d031bc56f9f94b2d7acb3fc125d3b8818c92153e Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Mon, 7 Jan 2019 21:46:18 +0100 Subject: [PATCH 02/49] Updated version --- src/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 826852e7..63b93b57 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,6 +2,6 @@ Extends the CSSOM from the core AngleSharp library. AngleSharp.Css - 0.10.0 + 0.10.1 \ No newline at end of file From e70e4156d7f53791a7c2b6986501b288075176d5 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Tue, 8 Jan 2019 00:41:32 +0100 Subject: [PATCH 03/49] Improved CSS serialization, found issue wrt initial issue --- .../Styling/BasicStyling.cs | 6 +-- .../Styling/HtmlCssIntegration.cs | 13 +++++ .../Declarations/BackgroundDeclaration.cs | 12 ++--- .../BackgroundRepeatDeclaration.cs | 54 ++++++++++++++++++- .../Dom/Internal/CssStyleDeclaration.cs | 5 +- src/AngleSharp.Css/Values/BackgroundLayer.cs | 6 +-- 6 files changed, 80 insertions(+), 16 deletions(-) diff --git a/src/AngleSharp.Css.Tests/Styling/BasicStyling.cs b/src/AngleSharp.Css.Tests/Styling/BasicStyling.cs index 07ae271e..ae52a27e 100644 --- a/src/AngleSharp.Css.Tests/Styling/BasicStyling.cs +++ b/src/AngleSharp.Css.Tests/Styling/BasicStyling.cs @@ -119,7 +119,7 @@ public void CssStyleDeclarationUnbound() { var css = ParseDeclarations(String.Empty); css.CssText = "background-color: rgb(255, 0, 0); color: rgb(0, 0, 0)"; - Assert.AreEqual("background: rgba(255, 0, 0, 1); color: rgba(0, 0, 0, 1)", css.CssText); + Assert.AreEqual("background-color: rgba(255, 0, 0, 1); color: rgba(0, 0, 0, 1)", css.CssText); Assert.AreEqual(2, css.Length); } @@ -129,7 +129,7 @@ public void CssStyleDeclarationBoundOutboundDirectionIndirect() var document = ParseDocument(String.Empty); var element = document.CreateElement(); element.SetAttribute("style", "background-color: rgb(255, 0, 0); color: rgb(0, 0, 0)"); - Assert.AreEqual("background: rgba(255, 0, 0, 1); color: rgba(0, 0, 0, 1)", element.GetStyle().CssText); + Assert.AreEqual("background-color: rgba(255, 0, 0, 1); color: rgba(0, 0, 0, 1)", element.GetStyle().CssText); Assert.AreEqual(2, element.GetStyle().Length); } @@ -141,7 +141,7 @@ public void CssStyleDeclarationBoundOutboundDirectionDirect() element.SetAttribute("style", String.Empty); Assert.AreEqual(String.Empty, element.GetStyle().CssText); element.SetAttribute("style", "background-color: rgb(255, 0, 0); color: rgb(0, 0, 0)"); - Assert.AreEqual("background: rgba(255, 0, 0, 1); color: rgba(0, 0, 0, 1)", element.GetStyle().CssText); + Assert.AreEqual("background-color: rgba(255, 0, 0, 1); color: rgba(0, 0, 0, 1)", element.GetStyle().CssText); Assert.AreEqual(2, element.GetStyle().Length); } diff --git a/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs b/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs index c5c7bdd4..f01fed2f 100644 --- a/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs +++ b/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs @@ -403,5 +403,18 @@ public void ExtensionCssWithMultipleElements() Assert.AreEqual("color", color); Assert.AreEqual("rgba(255, 0, 0, 1)", style4.GetPropertyValue(color)); } + + [Test] + public void RemovingPropertiesShouldNotYieldEmptyStyle_Issue14() + { + var dom = ParseDocument(@"
Test
"); + var div = dom.QuerySelector("div"); + var style = div.GetStyle(); + + style.RemoveProperty("background-position-x"); + style.RemoveProperty("background-position-y"); + + Assert.AreEqual("background-color: rgba(0, 0, 0, 0); background-image: none; background-attachment: scroll; background-clip: border-box; background-origin: padding-box; background-repeat: repeat; background-size: auto auto", style.CssText); + } } } diff --git a/src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs b/src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs index ed6cbf00..fc012bb6 100644 --- a/src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs @@ -58,9 +58,9 @@ public ICssValue Convert(StringSource source) { pos = source.Index; - if (layer.Source == null) + if (layer.Image == null) { - layer.Source = source.ParseImageSource(); + layer.Image = source.ParseImageSource(); c = source.SkipSpacesAndComments(); } @@ -158,7 +158,7 @@ public ICssValue[] Split(ICssValue value) return new[] { background.Color, - CreateMultiple(background, m => m.Source), + CreateMultiple(background, m => m.Image), CreateMultiple(background, m => m.Attachment), CreateMultiple(background, m => m.Clip), CreateMultiple(background, m => m.Position.HasValue ? m.Position.Value.X : new Nullable()), @@ -193,7 +193,7 @@ private static ICssValue CreateLayers(CssListValue image, CssListValue attachmen Position = px == null && py == null ? new Nullable() : new Point(px as Length? ?? Length.Zero, py as Length? ?? Length.Zero), Repeat = rx == null && ry == null ? new Nullable() : new ImageRepeats(rx, ry), Size = GetValue(size, i), - Source = image.Items[i], + Image = image.Items[i], }; } @@ -221,13 +221,13 @@ private static ICssValue CreateMultiple(Background background, Func().Select(getValue); - if (values.Any()) + if (values.Any(m => m != null)) { return new CssListValue(values.ToArray()); } } - return null; + return new Initial(null); } } } diff --git a/src/AngleSharp.Css/Declarations/BackgroundRepeatDeclaration.cs b/src/AngleSharp.Css/Declarations/BackgroundRepeatDeclaration.cs index fd4166b2..8a9a3935 100644 --- a/src/AngleSharp.Css/Declarations/BackgroundRepeatDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/BackgroundRepeatDeclaration.cs @@ -2,7 +2,10 @@ namespace AngleSharp.Css.Declarations { using AngleSharp.Css.Converters; using AngleSharp.Css.Dom; + using AngleSharp.Css.Values; + using AngleSharp.Text; using System; + using System.Linq; using static ValueConverters; static class BackgroundRepeatDeclaration @@ -20,8 +23,57 @@ static class BackgroundRepeatDeclaration PropertyNames.BackgroundRepeatY, }; - public static IValueConverter Converter = Or(BackgroundRepeatsConverter.FromList(), AssignInitial(BackgroundRepeat.Repeat)); + public static IValueConverter Converter = new BackgroundRepeatAggregator(); public static PropertyFlags Flags = PropertyFlags.None; + + sealed class BackgroundRepeatAggregator : IValueConverter, IValueAggregator + { + private static readonly IValueConverter converter = Or(BackgroundRepeatsConverter.FromList(), AssignInitial(BackgroundRepeat.Repeat)); + + public ICssValue Convert(StringSource source) + { + return converter.Convert(source); + } + + public ICssValue Merge(ICssValue[] values) + { + var h = values[0] as CssListValue; + var v = values[1] as CssListValue; + + if (h != null && v != null && h.Items.Length == v.Items.Length) + { + var repeats = new ICssValue[h.Items.Length]; + + for (var i = 0; i < repeats.Length; i++) + { + repeats[i] = new ImageRepeats(h.Items[i], v.Items[i]); + } + + return new CssListValue(repeats); + } + + return null; + } + + public ICssValue[] Split(ICssValue value) + { + var list = value as CssListValue; + + if (list != null) + { + var repeats = list.Items.OfType(); + var h = repeats.Select(m => m.Horizontal).ToArray(); + var v = repeats.Select(m => m.Vertical).ToArray(); + return new[] + { + new CssListValue(h), + new CssListValue(v) + }; + } + + return null; + } + } } } diff --git a/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs b/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs index 8ef808ed..87e9e469 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs @@ -109,7 +109,7 @@ public void Update(String value) if (!String.IsNullOrEmpty(value)) { var parser = _context.GetService(); - var decl = parser.ParseDeclaration(value); + var decl = parser?.ParseDeclaration(value); if (decl != null) { @@ -155,12 +155,11 @@ public String ToCssBlock(IStyleFormatter formatter) { count = count + 1; important = important + (longhand.IsImportant ? 1 : 0); - count++; values[i] = longhand.RawValue; } } - if (count == 0 || aggregator == null) + if (count != values.Length || aggregator == null) continue; if (important > 0 && important != count) diff --git a/src/AngleSharp.Css/Values/BackgroundLayer.cs b/src/AngleSharp.Css/Values/BackgroundLayer.cs index 6b29bcec..e71194d0 100644 --- a/src/AngleSharp.Css/Values/BackgroundLayer.cs +++ b/src/AngleSharp.Css/Values/BackgroundLayer.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values struct BackgroundLayer : ICssValue { - public ICssValue Source; + public ICssValue Image; public Point? Position; public ICssValue Size; public ImageRepeats? Repeat; @@ -23,10 +23,10 @@ public String CssText { var sb = StringBuilderPool.Obtain(); - if (Source != null) + if (Image != null) { if (sb.Length > 0) sb.Append(' '); - sb.Append(Source.CssText); + sb.Append(Image.CssText); } if (Position != null) From 631dfa9a6f115cde87ab47799b2558ddfc706757 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 9 Jan 2019 01:09:26 +0100 Subject: [PATCH 04/49] Started outlining all initial values --- src/AngleSharp.Css/Constants/InitialValues.cs | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/AngleSharp.Css/Constants/InitialValues.cs diff --git a/src/AngleSharp.Css/Constants/InitialValues.cs b/src/AngleSharp.Css/Constants/InitialValues.cs new file mode 100644 index 00000000..3d3913ce --- /dev/null +++ b/src/AngleSharp.Css/Constants/InitialValues.cs @@ -0,0 +1,147 @@ +namespace AngleSharp.Css.Constants +{ + using AngleSharp.Css.Dom; + using AngleSharp.Css.Values; + using AngleSharp.Dom; + using System; + + static class InitialValues + { + public static readonly ICssValue ColorDeclaration = Color.Black; + public static readonly ICssValue BackgroundColorDeclaration = Color.Transparent; + public static readonly ICssValue BackgroundImageDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue BackgroundRepeatDeclaration = new ImageRepeats(new Identifier(CssKeywords.Repeat), new Identifier(CssKeywords.Repeat)); + public static readonly ICssValue BackgroundPositionDeclaration = new CssTupleValue(new ICssValue[] { new Length(0, Length.Unit.Percent), new Length(0, Length.Unit.Percent) }); + public static readonly ICssValue BackgroundSizeDeclaration = new BackgroundSize(new Constant(CssKeywords.Auto, Length.Auto), new Constant(CssKeywords.Auto, Length.Auto)); + public static readonly ICssValue BackgroundOriginDeclaration = new Constant(CssKeywords.BorderBox, BoxModel.PaddingBox); + public static readonly ICssValue BackgroundClipDeclaration = new Constant(CssKeywords.BorderBox, BoxModel.BorderBox); + public static readonly ICssValue BackgroundAttachmentDeclaration = new Constant(CssKeywords.Scroll, BackgroundAttachment.Scroll); + public static readonly ICssValue FontStyleDeclaration = new Constant(CssKeywords.Normal, FontStyle.Normal); + public static readonly ICssValue FontVariantDeclaration = new Constant(CssKeywords.Normal, FontVariant.Normal); + public static readonly ICssValue FontWeightDeclaration = new Constant(CssKeywords.Normal, FontWeight.Normal); + public static readonly ICssValue FontStretchDeclaration = new Constant(CssKeywords.Normal, FontStretch.Normal); + public static readonly ICssValue FontSizeDeclaration = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue FontFamilyDeclaration = new StringValue("Times New Roman"); + public static readonly ICssValue LineHeightDeclaration = new Constant(CssKeywords.Normal, Length.Normal); + public static readonly ICssValue BorderTopWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue BorderRightWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue BorderBottomWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue BorderLeftWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue BorderTopStyleDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue BorderRightStyleDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue BorderBottomStyleDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue BorderLeftStyleDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue BorderTopColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue BorderRightColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue BorderBottomColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue BorderLeftColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue ColumnWidthDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue ColumnCountDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue ColumnRuleWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue ColumnRuleStyleDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue ColumnRuleColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue AnimationNameDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue AnimationDurationDeclaration = Time.Zero; + public static readonly ICssValue AnimationTimingFunctionDeclaration = CubicBezierTimingFunction.Ease; + public static readonly ICssValue AnimationDelayDeclaration = Time.Zero; + public static readonly ICssValue AnimationIterationCountDeclaration = new Length(1, Length.Unit.None); + public static readonly ICssValue AnimationDirectionDeclaration = new Constant(CssKeywords.Normal, AnimationDirection.Normal); + public static readonly ICssValue AnimationFillModeDeclaration = new Constant(CssKeywords.None, AnimationFillStyle.None); + public static readonly ICssValue AnimationPlayStateDeclaration = new Constant(CssKeywords.Running, PlayState.Running); + public static readonly ICssValue TransitionDelayDeclaration = Time.Zero; + public static readonly ICssValue TransitionDurationDeclaration = Time.Zero; + public static readonly ICssValue TransitionPropertyDeclaration = new Identifier(CssKeywords.All); + public static readonly ICssValue TransitionTimingFunctionDeclaration = CubicBezierTimingFunction.Ease; + public static readonly ICssValue DirectionDeclaration = new Constant(CssKeywords.Ltr, DirectionMode.Ltr); + public static readonly ICssValue EmptyCellsDeclaration = new Constant(CssKeywords.Show, true); + //flex-grow: 0 + //flex-shrink: 1 + //flex-basis: auto + //float: none + //border-spacing: 0 + //box-shadow: none + //box-sizing: content-box + //break-after: auto + //bottom: auto + //top: auto + //right: auto + //left: auto + //caption-side: top + //cursor: auto + //margin-bottom: 0 + //margin-left: 0 + //margin-right: 0 + //margin-top: 0 + //max-height: none + //max-width: none + //min-height: auto + //min-width: auto + //overflow-wrap: normal + //word-spacing: normal + //word-break: normal + //visibility: visible + //vertical-align: baseline + //opacity: 1.0 + //overflow: visible + //outline-color: invert, for browsers supporting it, currentColor for the other + //outline-style: none + //outline-width: medium + //padding-bottom: 0 + //padding-left: 0 + //padding-right: 0 + //padding-top: 0 + //text-transform: none + //text-shadow: none + //text-rendering: auto + //text-overflow: clip + //text-orientation: mixed + //text-justify: auto + //text-indent: 0 + //text-align: start, or a nameless value that acts as left if direction is ltr, right if direction is rtl if start is not supported by the browser. + //text-align-last: auto + //text-decoration-color: currentcolor + //text-decoration-style: solid + //text-decoration-line: none + //list-style-type: disc + //list-style-position: outside + //list-style-image: none + //line-break: auto + //grid-template-rows: none + //grid-template-columns: none + //grid-template-areas: none + //grid-auto-rows: auto + //grid-auto-columns: auto + //grid-auto-flow: row + //grid-column-gap: 0 + //grid-row-gap: 0 + //column-gap: normal + //row-gap: normal + //page-break-after: auto + //page-break-before: auto + //page-break-inside: auto + //perspective: none + //position: static + //transform: none + //break-inside: auto + //break-before: auto + //clear: none + //clip: auto + //content: normal + //counter-increment: none + //counter-reset: none + //display: inline + //backface-visibility: visible + //border-image-source: none + //border-image-slice: 100% + //border-image-width: 1 + //border-image-outset: 0 + //border-image-repeat: stretch + //align-self: auto + //align-items: normal + //align-content: normal + //justify-content: normal + //justify-items: legacy + //justify-self: auto + //z-index: auto + } +} From 687aa61d655bd0cd35980ed71f6fb1792508ed8f Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Wed, 9 Jan 2019 21:27:33 +0100 Subject: [PATCH 05/49] Implemented many initial values --- src/AngleSharp.Css/Constants/CssKeywords.cs | 10 + src/AngleSharp.Css/Constants/InitialValues.cs | 188 +++++++++--------- 2 files changed, 104 insertions(+), 94 deletions(-) diff --git a/src/AngleSharp.Css/Constants/CssKeywords.cs b/src/AngleSharp.Css/Constants/CssKeywords.cs index 06a3c952..ab226f3a 100644 --- a/src/AngleSharp.Css/Constants/CssKeywords.cs +++ b/src/AngleSharp.Css/Constants/CssKeywords.cs @@ -17,6 +17,11 @@ public static class CssKeywords /// public static readonly String Clip = "clip"; + /// + /// The legacy keyword. + /// + public static readonly String Legacy = "legacy"; + /// /// The normal keyword. /// @@ -151,6 +156,11 @@ public static class CssKeywords /// public static readonly String Auto = "auto"; + /// + /// The mixed keyword. + /// + public static readonly String Mixed = "mixed"; + /// /// The auto-fill keyword. /// diff --git a/src/AngleSharp.Css/Constants/InitialValues.cs b/src/AngleSharp.Css/Constants/InitialValues.cs index 3d3913ce..88665083 100644 --- a/src/AngleSharp.Css/Constants/InitialValues.cs +++ b/src/AngleSharp.Css/Constants/InitialValues.cs @@ -27,10 +27,10 @@ static class InitialValues public static readonly ICssValue BorderRightWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); public static readonly ICssValue BorderBottomWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); public static readonly ICssValue BorderLeftWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue BorderTopStyleDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue BorderRightStyleDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue BorderBottomStyleDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue BorderLeftStyleDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue BorderTopStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue BorderRightStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue BorderBottomStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue BorderLeftStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); public static readonly ICssValue BorderTopColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); public static readonly ICssValue BorderRightColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); public static readonly ICssValue BorderBottomColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); @@ -38,7 +38,7 @@ static class InitialValues public static readonly ICssValue ColumnWidthDeclaration = new Constant(CssKeywords.Auto, Length.Auto); public static readonly ICssValue ColumnCountDeclaration = new Constant(CssKeywords.Auto, Length.Auto); public static readonly ICssValue ColumnRuleWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue ColumnRuleStyleDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue ColumnRuleStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); public static readonly ICssValue ColumnRuleColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); public static readonly ICssValue AnimationNameDeclaration = new Constant(CssKeywords.None, null); public static readonly ICssValue AnimationDurationDeclaration = Time.Zero; @@ -54,94 +54,94 @@ static class InitialValues public static readonly ICssValue TransitionTimingFunctionDeclaration = CubicBezierTimingFunction.Ease; public static readonly ICssValue DirectionDeclaration = new Constant(CssKeywords.Ltr, DirectionMode.Ltr); public static readonly ICssValue EmptyCellsDeclaration = new Constant(CssKeywords.Show, true); - //flex-grow: 0 - //flex-shrink: 1 - //flex-basis: auto - //float: none - //border-spacing: 0 - //box-shadow: none - //box-sizing: content-box - //break-after: auto - //bottom: auto - //top: auto - //right: auto - //left: auto - //caption-side: top - //cursor: auto - //margin-bottom: 0 - //margin-left: 0 - //margin-right: 0 - //margin-top: 0 - //max-height: none - //max-width: none - //min-height: auto - //min-width: auto - //overflow-wrap: normal - //word-spacing: normal - //word-break: normal - //visibility: visible - //vertical-align: baseline - //opacity: 1.0 - //overflow: visible - //outline-color: invert, for browsers supporting it, currentColor for the other - //outline-style: none - //outline-width: medium - //padding-bottom: 0 - //padding-left: 0 - //padding-right: 0 - //padding-top: 0 - //text-transform: none - //text-shadow: none - //text-rendering: auto - //text-overflow: clip - //text-orientation: mixed - //text-justify: auto - //text-indent: 0 - //text-align: start, or a nameless value that acts as left if direction is ltr, right if direction is rtl if start is not supported by the browser. - //text-align-last: auto - //text-decoration-color: currentcolor - //text-decoration-style: solid - //text-decoration-line: none - //list-style-type: disc - //list-style-position: outside - //list-style-image: none - //line-break: auto - //grid-template-rows: none - //grid-template-columns: none - //grid-template-areas: none - //grid-auto-rows: auto - //grid-auto-columns: auto - //grid-auto-flow: row - //grid-column-gap: 0 - //grid-row-gap: 0 - //column-gap: normal - //row-gap: normal - //page-break-after: auto - //page-break-before: auto - //page-break-inside: auto - //perspective: none - //position: static - //transform: none - //break-inside: auto - //break-before: auto - //clear: none - //clip: auto - //content: normal - //counter-increment: none - //counter-reset: none - //display: inline - //backface-visibility: visible - //border-image-source: none - //border-image-slice: 100% - //border-image-width: 1 - //border-image-outset: 0 - //border-image-repeat: stretch - //align-self: auto - //align-items: normal - //align-content: normal - //justify-content: normal - //justify-items: legacy - //justify-self: auto - //z-index: auto + public static readonly ICssValue FlexGrowDeclaration = new Length(0, Length.Unit.None); + public static readonly ICssValue FlexShrinkDeclaration = new Length(1, Length.Unit.None); + public static readonly ICssValue FlexBasisDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue FloatDeclaration = new Constant(CssKeywords.None, Floating.None); + public static readonly ICssValue BorderSpacingDeclaration = Length.Zero; + public static readonly ICssValue BoxShadowDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue BoxSizingDeclaration = new Constant(CssKeywords.ContentBox, BoxModel.ContentBox); + public static readonly ICssValue BreakAfterDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue BreakBeforeDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue BreakInsideDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue PageBreakInsideDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue PageBreakBeforeDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue PageBreakAfterDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue BottomDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue TopDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue LeftDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue RightDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue MinHeightDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue MinWidthDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue MaxHeightDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue MaxWidthDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue MarginLeftDeclaration = Length.Zero; + public static readonly ICssValue MarginBottomDeclaration = Length.Zero; + public static readonly ICssValue MarginRightDeclaration = Length.Zero; + public static readonly ICssValue MarginTopDeclaration = Length.Zero; + public static readonly ICssValue PaddingLeftDeclaration = Length.Zero; + public static readonly ICssValue PaddingBottomDeclaration = Length.Zero; + public static readonly ICssValue PaddingRightDeclaration = Length.Zero; + public static readonly ICssValue PaddingTopDeclaration = Length.Zero; + public static readonly ICssValue CaptionSideDeclaration = new Constant(CssKeywords.Top, true); + public static readonly ICssValue CursorDeclaration = new Constant(CssKeywords.Auto, SystemCursor.Auto); + public static readonly ICssValue OverflowWrapDeclaration = new Constant(CssKeywords.Normal, OverflowWrap.Normal); + public static readonly ICssValue WordSpacingDeclaration = new Constant(CssKeywords.Normal, Length.Normal); + public static readonly ICssValue WordBreakDeclaration = new Constant(CssKeywords.Normal, WordBreak.Normal); + public static readonly ICssValue VisibilityDeclaration = new Constant(CssKeywords.Visible, Visibility.Visible); + public static readonly ICssValue VerticalAlignDeclaration = new Constant(CssKeywords.Baseline, VerticalAlignment.Baseline); + public static readonly ICssValue OpacityDeclaration = new Length(1.0, Length.Unit.None); + public static readonly ICssValue OverflowDeclaration = new Constant(CssKeywords.Visible, OverflowMode.Visible); + public static readonly ICssValue OutlineWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue OutlineStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue OutlineColorDeclaration = new Constant(CssKeywords.Invert, Color.InvertedColor); + public static readonly ICssValue TextTransformDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue TextShadowDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue TextRenderingDeclaration = new Constant(CssKeywords.Auto, null); + public static readonly ICssValue TextOverflowDeclaration = new Constant(CssKeywords.Auto, OverflowMode.Clip); + public static readonly ICssValue TextOrientationDeclaration = new Constant(CssKeywords.Mixed, null); + public static readonly ICssValue TextJustifyDeclaration = new Constant(CssKeywords.Auto, TextJustify.Auto); + public static readonly ICssValue TextIndentDeclaration = Length.Zero; + public static readonly ICssValue TextAlignDeclaration = new Constant(CssKeywords.Left, HorizontalAlignment.Left); + public static readonly ICssValue TextAlignLastDeclaration = new Constant(CssKeywords.Auto, TextAlignLast.Auto); + public static readonly ICssValue TextDecorationLineDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue TextDecorationStyleDeclaration = new Constant(CssKeywords.Solid, LineStyle.Solid); + public static readonly ICssValue TextDecorationColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue ListStyleTypeDeclaration = new Constant(CssKeywords.Disc, ListStyle.Disc); + public static readonly ICssValue ListStylePositionDeclaration = new Constant(CssKeywords.Outside, ListPosition.Outside); + public static readonly ICssValue ListStyleImageDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue LineBreakDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue GridTemplateRowsDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue GridTemplateColumnsDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue GridTemplateAreasDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue GridAutoRowsDeclaration = new Constant(CssKeywords.Auto, null); + public static readonly ICssValue GridAutoColumnsDeclaration = new Constant(CssKeywords.Auto, null); + public static readonly ICssValue GridAutoFlowDeclaration = new Constant(CssKeywords.Row, false); + public static readonly ICssValue GridColumnGapDeclaration = Length.Zero; + public static readonly ICssValue GridRowGapDeclaration = Length.Zero; + public static readonly ICssValue ColumnGapDeclaration = new Constant(CssKeywords.Normal, Length.Normal); + public static readonly ICssValue RowGapDeclaration = new Constant(CssKeywords.Normal, Length.Normal); + public static readonly ICssValue PerspectiveDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue PositionDeclaration = new Constant(CssKeywords.Inline, PositionMode.Static); + public static readonly ICssValue TransformDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue ClearModeDeclaration = new Constant(CssKeywords.None, ClearMode.None); + public static readonly ICssValue ClipDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue ContentDeclaration = new Constant(CssKeywords.Normal, null); + public static readonly ICssValue CounterIncrementDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue CounterResetDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue DisplayDeclaration = new Constant(CssKeywords.Inline, DisplayMode.Inline); + public static readonly ICssValue BackfaceVisibilityDeclaration = new Constant(CssKeywords.Visible, Visibility.Visible); + public static readonly ICssValue BorderImageSourceDeclaration = new Constant(CssKeywords.None, null); + public static readonly ICssValue BorderImageSliceDeclaration = Length.Full; + public static readonly ICssValue BorderImageWidthDeclaration = new Length(1, Length.Unit.None); + public static readonly ICssValue BorderImageOutsetDeclaration = Length.Zero; + public static readonly ICssValue BorderImageRepeatDeclaration = new Constant(CssKeywords.Stretch, BorderRepeat.Stretch); + public static readonly ICssValue AlignSelfDeclaration = new Constant(CssKeywords.Auto, FlexContentMode.Auto); + public static readonly ICssValue AlignItemsDeclaration = new Constant(CssKeywords.Normal, null); + public static readonly ICssValue AlignContentDeclaration = new Constant(CssKeywords.Normal, null); + public static readonly ICssValue JustifyContentDeclaration = new Constant(CssKeywords.Normal, null); + public static readonly ICssValue JustifyItemsDeclaration = new Constant(CssKeywords.Legacy, null); + public static readonly ICssValue JustifySelfDeclaration = new Constant(CssKeywords.Auto, FlexContentMode.Auto); + public static readonly ICssValue ZIndexDeclaration = new Constant(CssKeywords.Auto, Length.Auto); } } From 65de18c1c6708459038aafb963d66a5256994629 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Wed, 23 Jan 2019 11:38:28 +0100 Subject: [PATCH 06/49] test for issue #16 --- .../Declarations/CssBorderProperty.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/AngleSharp.Css.Tests/Declarations/CssBorderProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssBorderProperty.cs index 7353af33..901f8e22 100644 --- a/src/AngleSharp.Css.Tests/Declarations/CssBorderProperty.cs +++ b/src/AngleSharp.Css.Tests/Declarations/CssBorderProperty.cs @@ -1,3 +1,6 @@ +using AngleSharp.Css.Dom; +using AngleSharp.Css.Parser; + namespace AngleSharp.Css.Tests.Declarations { using NUnit.Framework; @@ -554,5 +557,17 @@ public void CssBorderOutSetWithNoColor() Assert.IsTrue(property.HasValue); Assert.AreEqual("1px outset", property.Value); } + + [Test] + public void CssBorderAggregation() + { + var expectedCss = "border: 1px solid rgba(0, 0, 0, 1)"; + var context = BrowsingContext.New(Configuration.Default.WithCss()); + var style = new CssStyleDeclaration(context); + style.SetBorderWidth("1px"); + style.SetBorderStyle("solid"); + style.SetBorderColor("black"); + Assert.AreEqual(expectedCss, style.CssText); + } } } From aecb838f8071ba2c0055a53433a57fe4697c48be Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Thu, 24 Jan 2019 21:54:11 +0100 Subject: [PATCH 07/49] Fixed dep on unit test for publish --- build.cake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.cake b/build.cake index d48ce935..3de873fe 100644 --- a/build.cake +++ b/build.cake @@ -139,6 +139,7 @@ Task("Create-Package") Task("Publish-Package") .IsDependentOn("Create-Package") + .IsDependentOn("Run-Unit-Tests") .Does(() => { var apiKey = EnvironmentVariable("NUGET_API_KEY"); @@ -159,7 +160,8 @@ Task("Publish-Package") }); Task("Publish-Release") - .IsDependentOn("Publish-Package") + .IsDependentOn("Create-Package") + .IsDependentOn("Run-Unit-Tests") .Does(() => { var githubToken = EnvironmentVariable("GITHUB_API_TOKEN"); From 67955baa433241fcfce31b459dd9c9e2c148fd93 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 28 Apr 2019 21:57:49 +0200 Subject: [PATCH 08/49] Updated README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 87e9b723..48820769 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![GitHub Tag](https://img.shields.io/github/tag/AngleSharp/AngleSharp.Css.svg?style=flat-square)](https://github.com/AngleSharp/AngleSharp.Css/releases) [![NuGet Count](https://img.shields.io/nuget/dt/AngleSharp.Css.svg?style=flat-square)](https://www.nuget.org/packages/AngleSharp.Css/) [![Issues Open](https://img.shields.io/github/issues/AngleSharp/AngleSharp.Css.svg?style=flat-square)](https://github.com/AngleSharp/AngleSharp.Css/issues) +[![Gitter Chat](http://img.shields.io/badge/gitter-AngleSharp/AngleSharp-blue.svg?style=flat-square)](https://gitter.im/AngleSharp/AngleSharp) [![StackOverflow Questions](https://img.shields.io/stackexchange/stackoverflow/t/anglesharp.svg?style=flat-square)](https://stackoverflow.com/tags/anglesharp) [![CLA Assistant](https://cla-assistant.io/readme/badge/AngleSharp/AngleSharp.Css?style=flat-square)](https://cla-assistant.io/AngleSharp/AngleSharp.Css) @@ -60,6 +61,16 @@ Participation in the project is highly welcome. For this project the same rules If you have any question, concern, or spot an issue then please report it before opening a pull request. An initial discussion is appreciated regardless of the nature of the problem. +Live discussions can take place in our [Gitter chat](https://gitter.im/AngleSharp/AngleSharp), which supports using GitHub accounts. + +This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. + +For more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct). + +## .NET Foundation + +This project is supported by the [.NET Foundation](https://dotnetfoundation.org). + ## License The MIT License (MIT) From 72540caae1483c112708c860ca5708e2b265ff3c Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Fri, 3 May 2019 09:42:44 +0200 Subject: [PATCH 09/49] Updated changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3afe2649..de1b091d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.12.0 + +Released on Thursday, May 2 2019. + +- Reference latest AngleSharp + # 0.10.1 Released on Monday, January 7 2019. From 8f5d6ae62d15a39ff22ade0fee824ccb1dc1b654 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 09:35:05 +0200 Subject: [PATCH 10/49] Updated AngleSharp --- src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj | 4 ++-- src/AngleSharp.Css.nuspec | 2 +- src/AngleSharp.Css/AngleSharp.Css.csproj | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj b/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj index 8ca64439..64f2ab13 100644 --- a/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj +++ b/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj @@ -13,9 +13,9 @@ - + - + diff --git a/src/AngleSharp.Css.nuspec b/src/AngleSharp.Css.nuspec index 695a75fc..1d8fac72 100644 --- a/src/AngleSharp.Css.nuspec +++ b/src/AngleSharp.Css.nuspec @@ -14,7 +14,7 @@ Copyright 2016-2019, AngleSharp html html5 css css3 dom styling library anglesharp angle - + diff --git a/src/AngleSharp.Css/AngleSharp.Css.csproj b/src/AngleSharp.Css/AngleSharp.Css.csproj index 7b03ca05..70533018 100644 --- a/src/AngleSharp.Css/AngleSharp.Css.csproj +++ b/src/AngleSharp.Css/AngleSharp.Css.csproj @@ -10,7 +10,7 @@ - + From 4c0babb90d1c907f860b455894efdae359e1390d Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 13:16:05 +0200 Subject: [PATCH 11/49] Updated and refactored --- CHANGELOG.md | 1 + .../AngleSharp.Css.Tests.csproj | 1 + .../Extensions/Elements.cs | 23 +++ .../Mocks/DelayedStream.cs | 20 +-- src/AngleSharp.Css/CssStylingService.cs | 5 +- .../Declarations/ContentDeclaration.cs | 50 ++---- .../Dom/ElementCssInlineStyleExtensions.cs | 21 +-- .../Dom/Events/CssErrorEvent.cs | 15 +- src/AngleSharp.Css/Dom/Internal/CssComment.cs | 5 +- .../Dom/Internal/CssMediaQueryList.cs | 15 +- src/AngleSharp.Css/Dom/Internal/CssMedium.cs | 20 +-- .../Dom/Internal/CssProperty.cs | 55 ++----- src/AngleSharp.Css/Dom/Internal/CssRule.cs | 10 +- .../Dom/Internal/CssRuleList.cs | 10 +- .../Dom/Internal/CssStyleDeclaration.cs | 20 +-- .../Dom/Internal/CssStyleSheet.cs | 45 ++---- .../Dom/Internal/DocumentFunction.cs | 10 +- .../Dom/Internal/DocumentFunctions.cs | 5 +- .../Dom/Internal/KeyframeSelector.cs | 10 +- .../Dom/Internal/MediaFeature.cs | 25 +-- src/AngleSharp.Css/Dom/Internal/MediaList.cs | 10 +- .../Dom/Internal/PseudoElement.cs | 149 ++++-------------- .../Dom/Internal/Rules/CssDeclarationRule.cs | 5 +- .../Dom/Internal/Rules/CssDocumentRule.cs | 5 +- .../Dom/Internal/Rules/CssGroupingRule.cs | 5 +- .../Dom/Internal/Rules/CssImportRule.cs | 10 +- .../Dom/Internal/Rules/CssKeyframeRule.cs | 15 +- .../Dom/Internal/Rules/CssMediaRule.cs | 10 +- .../Dom/Internal/Rules/CssPageRule.cs | 15 +- .../Dom/Internal/Rules/CssStyleRule.cs | 15 +- .../Dom/Internal/Rules/CssSupportsRule.cs | 5 +- .../Dom/Internal/Rules/CssUnknownRule.cs | 10 +- .../Dom/Internal/StyleCollection.cs | 5 +- .../Extensions/ElementExtensions.cs | 44 ++++-- src/AngleSharp.Css/Parser/CssParser.cs | 5 +- .../Parser/Tokens/CssCommentToken.cs | 5 +- .../Parser/Tokens/CssStringToken.cs | 5 +- src/AngleSharp.Css/Parser/Tokens/CssToken.cs | 10 +- .../Parser/Tokens/CssUrlToken.cs | 5 +- src/AngleSharp.Css/Values/Angle.cs | 15 +- src/AngleSharp.Css/Values/BackgroundSize.cs | 10 +- src/AngleSharp.Css/Values/BorderImage.cs | 25 +-- src/AngleSharp.Css/Values/BorderImageSlice.cs | 25 +-- .../Values/CalcAddExpression.cs | 15 +- .../Values/CalcDivExpression.cs | 15 +- .../Values/CalcMulExpression.cs | 15 +- .../Values/CalcSubExpression.cs | 15 +- src/AngleSharp.Css/Values/Color.cs | 30 +--- src/AngleSharp.Css/Values/Colors.cs | 5 +- .../Values/CounterDefinition.cs | 20 +-- src/AngleSharp.Css/Values/CounterValue.cs | 15 +- src/AngleSharp.Css/Values/Counters.cs | 10 +- src/AngleSharp.Css/Values/CssChildValue.cs | 15 +- src/AngleSharp.Css/Values/CssListValue.cs | 10 +- src/AngleSharp.Css/Values/Fraction.cs | 15 +- src/AngleSharp.Css/Values/Frequency.cs | 15 +- src/AngleSharp.Css/Values/ImageRepeats.cs | 10 +- src/AngleSharp.Css/Values/Length.cs | 20 +-- src/AngleSharp.Css/Values/LineNames.cs | 10 +- src/AngleSharp.Css/Values/LinearGradient.cs | 15 +- src/AngleSharp.Css/Values/MatrixTransform.cs | 10 +- src/AngleSharp.Css/Values/Periodic.cs | 20 +-- .../Values/PerspectiveTransform.cs | 20 +-- src/AngleSharp.Css/Values/Point.cs | 10 +- src/AngleSharp.Css/Values/Point3.cs | 15 +- src/AngleSharp.Css/Values/RadialGradient.cs | 45 ++---- src/AngleSharp.Css/Values/Resolution.cs | 15 +- src/AngleSharp.Css/Values/RotateTransform.cs | 28 +--- src/AngleSharp.Css/Values/ScaleTransform.cs | 23 +-- src/AngleSharp.Css/Values/SkewTransform.cs | 15 +- .../Values/StepsTimingFunction.cs | 15 +- src/AngleSharp.Css/Values/Time.cs | 15 +- src/AngleSharp.Css/Values/TransformMatrix.cs | 60 ++----- .../Values/TranslateTransform.cs | 28 +--- src/AngleSharp.Css/Values/VarReference.cs | 15 +- src/AngleSharp.Css/Values/VarReferences.cs | 20 +-- .../TestResult.cs | 15 +- .../TestSuite.cs | 15 +- .../AngleSharpParser.cs | 10 +- src/AngleSharp.Performance.Css/CsCssParser.cs | 10 +- src/AngleSharp.Performance.Css/ExCssParser.cs | 10 +- .../StandardTests.cs | 5 +- .../UrlTests.cs | 5 +- 83 files changed, 330 insertions(+), 1118 deletions(-) create mode 100644 src/AngleSharp.Css.Tests/Extensions/Elements.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index de1b091d..1504124e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Released on Thursday, May 2 2019. - Reference latest AngleSharp +- Added extension helper `SetStyle` to modify all styles of many elements (#22) # 0.10.1 diff --git a/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj b/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj index 64f2ab13..db2c258c 100644 --- a/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj +++ b/src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj @@ -13,6 +13,7 @@ + diff --git a/src/AngleSharp.Css.Tests/Extensions/Elements.cs b/src/AngleSharp.Css.Tests/Extensions/Elements.cs new file mode 100644 index 00000000..fca5730d --- /dev/null +++ b/src/AngleSharp.Css.Tests/Extensions/Elements.cs @@ -0,0 +1,23 @@ +namespace AngleSharp.Css.Tests.Extensions +{ + using NUnit.Framework; + using AngleSharp.Css.Dom; + using AngleSharp.Dom; + using System.Linq; + + [TestFixture] + public class ElementsTests + { + [Test] + public void SetAllStyles() + { + var document = "
".ToHtmlDocument(Configuration.Default.WithCss()); + var divs = document.QuerySelectorAll("div"); + divs.SetStyle(style => style.SetBackground("red")); + + Assert.AreEqual("rgba(255, 0, 0, 1)", divs.Skip(0).First().GetStyle().GetBackground()); + Assert.AreEqual("rgba(255, 0, 0, 1)", divs.Skip(1).First().GetStyle().GetBackground()); + Assert.AreEqual("rgba(255, 0, 0, 1)", divs.Skip(2).First().GetStyle().GetBackground()); + } + } +} diff --git a/src/AngleSharp.Css.Tests/Mocks/DelayedStream.cs b/src/AngleSharp.Css.Tests/Mocks/DelayedStream.cs index 9e5ff20c..f0fd3f49 100644 --- a/src/AngleSharp.Css.Tests/Mocks/DelayedStream.cs +++ b/src/AngleSharp.Css.Tests/Mocks/DelayedStream.cs @@ -20,30 +20,18 @@ public DelayedStream(Byte[] content) { } - public override Boolean CanRead - { - get { return _stream.CanRead; } - } + public override Boolean CanRead => _stream.CanRead; - public override Boolean CanSeek - { - get { return _stream.CanSeek; } - } + public override Boolean CanSeek => _stream.CanSeek; - public override Boolean CanWrite - { - get { return _stream.CanWrite; } - } + public override Boolean CanWrite => _stream.CanWrite; public override void Flush() { _stream.Flush(); } - public override Int64 Length - { - get { return _stream.Length; } - } + public override Int64 Length => _stream.Length; public override Int64 Position { diff --git a/src/AngleSharp.Css/CssStylingService.cs b/src/AngleSharp.Css/CssStylingService.cs index 5165e6dd..a334c16c 100644 --- a/src/AngleSharp.Css/CssStylingService.cs +++ b/src/AngleSharp.Css/CssStylingService.cs @@ -26,10 +26,7 @@ public class CssStylingService : IStylingService /// Gets the default stylesheet as specified by the W3C: /// http://www.w3.org/TR/CSS21/sample.html /// - public ICssStyleSheet Default - { - get { return _default ?? (_default = ParseDefault()); } - } + public ICssStyleSheet Default => _default ?? (_default = ParseDefault()); #endregion diff --git a/src/AngleSharp.Css/Declarations/ContentDeclaration.cs b/src/AngleSharp.Css/Declarations/ContentDeclaration.cs index c2b1821c..e08ab7b3 100644 --- a/src/AngleSharp.Css/Declarations/ContentDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/ContentDeclaration.cs @@ -115,10 +115,7 @@ public ContentValue(ICssValue[] modes) _modes = modes; } - public String CssText - { - get { return _modes.Length == 0 ? CssKeywords.None : _modes.Join(" "); } - } + public String CssText => _modes.Length == 0 ? CssKeywords.None : _modes.Join(" "); } private interface IContentMode : ICssValue @@ -131,10 +128,7 @@ private interface IContentMode : ICssValue /// private sealed class NormalContentMode : IContentMode { - public String CssText - { - get { return CssKeywords.Normal; } - } + public String CssText => CssKeywords.Normal; public String Stringify(IElement element) { @@ -148,10 +142,7 @@ public String Stringify(IElement element) /// private sealed class OpenQuoteContentMode : IContentMode { - public String CssText - { - get { return CssKeywords.OpenQuote; } - } + public String CssText => CssKeywords.OpenQuote; public String Stringify(IElement element) { @@ -165,10 +156,7 @@ public String Stringify(IElement element) /// private sealed class CloseQuoteContentMode : IContentMode { - public String CssText - { - get { return CssKeywords.CloseQuote; } - } + public String CssText => CssKeywords.CloseQuote; public String Stringify(IElement element) { @@ -182,10 +170,7 @@ public String Stringify(IElement element) /// private sealed class NoOpenQuoteContentMode : IContentMode { - public String CssText - { - get { return CssKeywords.NoOpenQuote; } - } + public String CssText => CssKeywords.NoOpenQuote; public String Stringify(IElement element) { @@ -199,10 +184,7 @@ public String Stringify(IElement element) /// private sealed class NoCloseQuoteContentMode : IContentMode { - public String CssText - { - get { return CssKeywords.NoCloseQuote; } - } + public String CssText => CssKeywords.NoCloseQuote; public String Stringify(IElement element) { @@ -222,10 +204,7 @@ public TextContentMode(String text) _text = text; } - public String CssText - { - get { return _text.CssString(); } - } + public String CssText => _text.CssString(); public String Stringify(IElement element) { @@ -247,10 +226,7 @@ public CounterContentMode(CounterDefinition counter) _counter = counter; } - public String CssText - { - get { return _counter.CssText; } - } + public String CssText => _counter.CssText; public String Stringify(IElement element) { @@ -271,10 +247,7 @@ public AttributeContentMode(String attribute) _attribute = attribute; } - public String CssText - { - get { return FunctionNames.Attr.CssFunction(_attribute); } - } + public String CssText => FunctionNames.Attr.CssFunction(_attribute); public String Stringify(IElement element) { @@ -296,10 +269,7 @@ public UrlContentMode(UrlReference url) _url = url; } - public String CssText - { - get { return _url.CssText; } - } + public String CssText => _url.CssText; public String Stringify(IElement element) { diff --git a/src/AngleSharp.Css/Dom/ElementCssInlineStyleExtensions.cs b/src/AngleSharp.Css/Dom/ElementCssInlineStyleExtensions.cs index f1f7c340..4ef9b11e 100644 --- a/src/AngleSharp.Css/Dom/ElementCssInlineStyleExtensions.cs +++ b/src/AngleSharp.Css/Dom/ElementCssInlineStyleExtensions.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using AngleSharp.Attributes; using AngleSharp.Dom; @@ -20,26 +20,18 @@ public static class ElementCssInlineStyleExtensions /// [DomName("style")] [DomAccessor(Accessors.Getter)] - public static ICssStyleDeclaration GetStyle(this IElement element) - { - return _styles.GetValue(element, CreateStyle); - } + public static ICssStyleDeclaration GetStyle(this IElement element) => _styles.GetValue(element, CreateStyle); /// /// Sets the style declaration of an element. /// [DomName("style")] [DomAccessor(Accessors.Setter)] - public static void SetStyle(this IElement element, String value) - { - element.SetAttribute(AttributeNames.Style, value); - } + public static void SetStyle(this IElement element, String value) => element.SetAttribute(AttributeNames.Style, value); internal static void UpdateStyle(this IElement element, String value) { - var style = default(ICssStyleDeclaration); - - if (_styles.TryGetValue(element, out style)) + if (_styles.TryGetValue(element, out ICssStyleDeclaration style)) { style.Update(value); } @@ -50,10 +42,7 @@ internal static void UpdateStyle(this IElement element, String value) } } - private static ICssStyleDeclaration CreateStyle(IElement element) - { - return CreateStyle(element, null); - } + private static ICssStyleDeclaration CreateStyle(IElement element) => CreateStyle(element, null); private static ICssStyleDeclaration CreateStyle(IElement element, String source) { diff --git a/src/AngleSharp.Css/Dom/Events/CssErrorEvent.cs b/src/AngleSharp.Css/Dom/Events/CssErrorEvent.cs index 8f1d8d1e..0932a197 100644 --- a/src/AngleSharp.Css/Dom/Events/CssErrorEvent.cs +++ b/src/AngleSharp.Css/Dom/Events/CssErrorEvent.cs @@ -41,26 +41,17 @@ public CssErrorEvent(CssParseError code, TextPosition position) /// /// Gets the position of the error. /// - public TextPosition Position - { - get { return _position; } - } + public TextPosition Position => _position; /// /// Gets the provided error code. /// - public Int32 Code - { - get { return _code.GetCode(); } - } + public Int32 Code => _code.GetCode(); /// /// Gets the associated error message. /// - public String Message - { - get { return _code.GetMessage(); } - } + public String Message => _code.GetMessage(); #endregion } diff --git a/src/AngleSharp.Css/Dom/Internal/CssComment.cs b/src/AngleSharp.Css/Dom/Internal/CssComment.cs index 11deb2ca..91cc0f34 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssComment.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssComment.cs @@ -25,10 +25,7 @@ public CssComment(String data) #region Properties - public String Data - { - get { return _data; } - } + public String Data => _data; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/CssMediaQueryList.cs b/src/AngleSharp.Css/Dom/Internal/CssMediaQueryList.cs index 1ecfa63d..b7b104a9 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssMediaQueryList.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssMediaQueryList.cs @@ -40,20 +40,11 @@ public CssMediaQueryList(IWindow window, IMediaList media) #region Properties - public String MediaText - { - get { return _media.MediaText; } - } + public String MediaText => _media.MediaText; - public IMediaList Media - { - get { return _media; } - } + public IMediaList Media => _media; - public Boolean IsMatched - { - get { return _matched; } - } + public Boolean IsMatched => _matched; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/CssMedium.cs b/src/AngleSharp.Css/Dom/Internal/CssMedium.cs index 50153f9a..0c2e04ff 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssMedium.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssMedium.cs @@ -40,25 +40,13 @@ public CssMedium(String type, Boolean inverse, Boolean exclusive, IEnumerable Features - { - get { return _features; } - } + public IEnumerable Features => _features; - public String Type - { - get { return _type; } - } + public String Type => _type; - public Boolean IsExclusive - { - get { return _exclusive; } - } + public Boolean IsExclusive => _exclusive; - public Boolean IsInverse - { - get { return _inverse; } - } + public Boolean IsInverse => _inverse; public String Constraints { diff --git a/src/AngleSharp.Css/Dom/Internal/CssProperty.cs b/src/AngleSharp.Css/Dom/Internal/CssProperty.cs index 330ad8d3..0dd1d7be 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssProperty.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssProperty.cs @@ -50,40 +50,19 @@ public String Value set { _value = _converter.Convert(value); } } - public Boolean HasValue - { - get { return _value != null; } - } + public Boolean HasValue => _value != null; - public Boolean IsInherited - { - get { return (((_flags & PropertyFlags.Inherited) == PropertyFlags.Inherited) && IsInitial) || (HasValue && _value.CssText.Is(CssKeywords.Inherit)); } - } + public Boolean IsInherited => (((_flags & PropertyFlags.Inherited) == PropertyFlags.Inherited) && IsInitial) || (HasValue && _value.CssText.Is(CssKeywords.Inherit)); - public Boolean CanBeInherited - { - get { return (_flags & PropertyFlags.Inherited) == PropertyFlags.Inherited; } - } + public Boolean CanBeInherited => (_flags & PropertyFlags.Inherited) == PropertyFlags.Inherited; - public Boolean IsAnimatable - { - get { return (_flags & PropertyFlags.Animatable) == PropertyFlags.Animatable; } - } + public Boolean IsAnimatable => (_flags & PropertyFlags.Animatable) == PropertyFlags.Animatable; - public Boolean IsInitial - { - get { return !HasValue || _value.CssText.Is(CssKeywords.Initial); } - } + public Boolean IsInitial => !HasValue || _value.CssText.Is(CssKeywords.Initial); - public Boolean IsShorthand - { - get { return (_flags & PropertyFlags.Shorthand) == PropertyFlags.Shorthand; } - } + public Boolean IsShorthand => (_flags & PropertyFlags.Shorthand) == PropertyFlags.Shorthand; - public String Name - { - get { return _name; } - } + public String Name => _name; public Boolean IsImportant { @@ -91,29 +70,17 @@ public Boolean IsImportant set { _important = value; } } - public String CssText - { - get { return this.ToCss(); } - } + public String CssText => this.ToCss(); #endregion #region Internal Properties - internal Boolean CanBeHashless - { - get { return (_flags & PropertyFlags.Hashless) == PropertyFlags.Hashless; } - } + internal Boolean CanBeHashless => (_flags & PropertyFlags.Hashless) == PropertyFlags.Hashless; - internal Boolean CanBeUnitless - { - get { return (_flags & PropertyFlags.Unitless) == PropertyFlags.Unitless; } - } + internal Boolean CanBeUnitless => (_flags & PropertyFlags.Unitless) == PropertyFlags.Unitless; - internal IValueConverter Converter - { - get { return _converter; } - } + internal IValueConverter Converter => _converter; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/CssRule.cs b/src/AngleSharp.Css/Dom/Internal/CssRule.cs index 6f0d98a0..52c51e24 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssRule.cs @@ -68,15 +68,9 @@ public ICssStyleSheet Owner set { _owner = value; } } - public CssRuleType Type - { - get { return _type; } - } + public CssRuleType Type => _type; - public ICssParser Parser - { - get { return _owner.Context.GetService(); } - } + public ICssParser Parser => _owner.Context.GetService(); #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/CssRuleList.cs b/src/AngleSharp.Css/Dom/Internal/CssRuleList.cs index 27e34b2b..1f0e4c32 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssRuleList.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssRuleList.cs @@ -37,15 +37,9 @@ public ICssRule this[Int32 index] #region Properties - public Boolean HasDeclarativeRules - { - get { return _rules.Any(IsDeclarativeRule); } - } + public Boolean HasDeclarativeRules => _rules.Any(IsDeclarativeRule); - public Int32 Length - { - get { return _rules.Count; } - } + public Int32 Length => _rules.Count; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs b/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs index 87e9e469..16df1fef 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs @@ -62,10 +62,7 @@ public String this[String name] #region Properties - public IEnumerable Declarations - { - get { return _declarations; } - } + public IEnumerable Declarations => _declarations; public String CssText { @@ -73,20 +70,11 @@ public String CssText set { Update(value); RaiseChanged(); } } - public Boolean IsReadOnly - { - get { return _context == null; } - } + public Boolean IsReadOnly => _context == null; - public Int32 Length - { - get { return Declarations.Count(); } - } + public Int32 Length => Declarations.Count(); - public ICssRule Parent - { - get { return _parent; } - } + public ICssRule Parent => _parent; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/CssStyleSheet.cs b/src/AngleSharp.Css/Dom/Internal/CssStyleSheet.cs index 8bb277ea..ea35e3b6 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssStyleSheet.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssStyleSheet.cs @@ -39,35 +39,17 @@ internal CssStyleSheet(IBrowsingContext context, TextSource source) #region Properties - public String Type - { - get { return MimeTypeNames.Css; } - } + public String Type => MimeTypeNames.Css; - public String Title - { - get { return OwnerNode?.GetAttribute(AttributeNames.Title); } - } + public String Title => OwnerNode?.GetAttribute(AttributeNames.Title); - public IMediaList Media - { - get { return _media; } - } + public IMediaList Media => _media; - public ICssRuleList Rules - { - get { return _rules; } - } + public ICssRuleList Rules => _rules; - public IBrowsingContext Context - { - get { return _context; } - } + public IBrowsingContext Context => _context; - public TextSource Source - { - get { return _source; } - } + public TextSource Source => _source; public Boolean IsDisabled { @@ -75,20 +57,11 @@ public Boolean IsDisabled set; } - public IElement OwnerNode - { - get { return _element; } - } + public IElement OwnerNode => _element; - public ICssStyleSheet Parent - { - get { return _parent; } - } + public ICssStyleSheet Parent => _parent; - public ICssRule OwnerRule - { - get { return _owner; } - } + public ICssRule OwnerRule => _owner; public String Href { diff --git a/src/AngleSharp.Css/Dom/Internal/DocumentFunction.cs b/src/AngleSharp.Css/Dom/Internal/DocumentFunction.cs index 935d5bd4..d8312731 100644 --- a/src/AngleSharp.Css/Dom/Internal/DocumentFunction.cs +++ b/src/AngleSharp.Css/Dom/Internal/DocumentFunction.cs @@ -28,15 +28,9 @@ internal DocumentFunction(String name, String data) #region Properties - public String Name - { - get { return _name; } - } + public String Name => _name; - public String Data - { - get { return _data; } - } + public String Data => _data; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/DocumentFunctions.cs b/src/AngleSharp.Css/Dom/Internal/DocumentFunctions.cs index 84a2ccd6..2641c6e8 100644 --- a/src/AngleSharp.Css/Dom/Internal/DocumentFunctions.cs +++ b/src/AngleSharp.Css/Dom/Internal/DocumentFunctions.cs @@ -24,10 +24,7 @@ public IDocumentFunction this[Int32 index] get { return _functions[index]; } } - public Int32 Length - { - get { return _functions.Count; } - } + public Int32 Length => _functions.Count; public IEnumerator GetEnumerator() { diff --git a/src/AngleSharp.Css/Dom/Internal/KeyframeSelector.cs b/src/AngleSharp.Css/Dom/Internal/KeyframeSelector.cs index dad7e376..14ed2e7f 100644 --- a/src/AngleSharp.Css/Dom/Internal/KeyframeSelector.cs +++ b/src/AngleSharp.Css/Dom/Internal/KeyframeSelector.cs @@ -28,15 +28,9 @@ public KeyframeSelector(List stops) #region Properties - public IEnumerable Stops - { - get { return _stops; } - } + public IEnumerable Stops => _stops; - public String Text - { - get { return this.ToCss(); } - } + public String Text => this.ToCss(); #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/MediaFeature.cs b/src/AngleSharp.Css/Dom/Internal/MediaFeature.cs index 3636e8c3..ed97d792 100644 --- a/src/AngleSharp.Css/Dom/Internal/MediaFeature.cs +++ b/src/AngleSharp.Css/Dom/Internal/MediaFeature.cs @@ -32,30 +32,15 @@ internal MediaFeature(String name, String value) #region Properties - public String Name - { - get { return _name; } - } + public String Name => _name; - public Boolean IsMinimum - { - get { return _min; } - } + public Boolean IsMinimum => _min; - public Boolean IsMaximum - { - get { return _max; } - } + public Boolean IsMaximum => _max; - public String Value - { - get { return _value; } - } + public String Value => _value; - public Boolean HasValue - { - get { return _value != null; } - } + public Boolean HasValue => _value != null; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/MediaList.cs b/src/AngleSharp.Css/Dom/Internal/MediaList.cs index 277fa5e8..d6a3d0b4 100644 --- a/src/AngleSharp.Css/Dom/Internal/MediaList.cs +++ b/src/AngleSharp.Css/Dom/Internal/MediaList.cs @@ -40,15 +40,9 @@ public String this[Int32 index] #region Properties - public Int32 Length - { - get { return _media.Count; } - } + public Int32 Length => _media.Count; - public ICssParser Parser - { - get { return _context.GetService(); } - } + public ICssParser Parser => _context.GetService(); public String MediaText { diff --git a/src/AngleSharp.Css/Dom/Internal/PseudoElement.cs b/src/AngleSharp.Css/Dom/Internal/PseudoElement.cs index 504ae6dc..a10df293 100644 --- a/src/AngleSharp.Css/Dom/Internal/PseudoElement.cs +++ b/src/AngleSharp.Css/Dom/Internal/PseudoElement.cs @@ -28,11 +28,8 @@ public PseudoElement(IElement host, String name) #endregion #region Properties - - public IElement AssignedSlot - { - get { return _host.AssignedSlot; } - } + + public IElement AssignedSlot => _host.AssignedSlot; public String Slot { @@ -40,40 +37,21 @@ public String Slot set { } } - public IShadowRoot ShadowRoot - { - get { return _host.ShadowRoot; } - } + public ISourceReference SourceReference => null; - public String Prefix - { - get { return _host.Prefix; } - } + public IShadowRoot ShadowRoot => _host.ShadowRoot; - public String PseudoName - { - get { return _name; } - } + public String Prefix => _host.Prefix; - public String LocalName - { - get { return _host.LocalName; } - } + public String PseudoName => _name; - public String NamespaceUri - { - get { return _host.NamespaceUri; } - } + public String LocalName => _host.LocalName; - public INamedNodeMap Attributes - { - get { return _host.Attributes; } - } + public String NamespaceUri => _host.NamespaceUri; - public ITokenList ClassList - { - get { return _host.ClassList; } - } + public INamedNodeMap Attributes => _host.Attributes; + + public ITokenList ClassList => _host.ClassList; public String ClassName { @@ -99,75 +77,33 @@ public String OuterHtml set { } } - public String TagName - { - get { return _host.TagName; } - } + public String TagName => _host.TagName; - public Boolean IsFocused - { - get { return _host.IsFocused; } - } + public Boolean IsFocused => _host.IsFocused; - public String BaseUri - { - get { return _host.BaseUri; } - } + public String BaseUri => _host.BaseUri; - public Url BaseUrl - { - get { return _host.BaseUrl; } - } + public Url BaseUrl => _host.BaseUrl; - public String NodeName - { - get { return _host.NodeName; } - } + public String NodeName => _host.NodeName; - public INodeList ChildNodes - { - get { return _host.ChildNodes; } - } + public INodeList ChildNodes => _host.ChildNodes; - public IDocument Owner - { - get { return _host.Owner; } - } + public IDocument Owner => _host.Owner; - public IElement ParentElement - { - get { return _host.ParentElement; } - } + public IElement ParentElement => _host.ParentElement; - public INode Parent - { - get { return _host.Parent; } - } + public INode Parent => _host.Parent; - public INode FirstChild - { - get { return _host.FirstChild; } - } + public INode FirstChild => _host.FirstChild; - public INode LastChild - { - get { return _host.LastChild; } - } + public INode LastChild => _host.LastChild; - public INode NextSibling - { - get { return _host.NextSibling; } - } + public INode NextSibling => _host.NextSibling; - public INode PreviousSibling - { - get { return _host.PreviousSibling; } - } + public INode PreviousSibling => _host.PreviousSibling; - public NodeType NodeType - { - get { return NodeType.Element; } - } + public NodeType NodeType => NodeType.Element; public String NodeValue { @@ -181,40 +117,19 @@ public String TextContent set { } } - public Boolean HasChildNodes - { - get { return _host.HasChildNodes; } - } + public Boolean HasChildNodes => _host.HasChildNodes; - public IHtmlCollection Children - { - get { return _host.Children; } - } + public IHtmlCollection Children => _host.Children; - public IElement FirstElementChild - { - get { return _host.FirstElementChild; } - } + public IElement FirstElementChild => _host.FirstElementChild; - public IElement LastElementChild - { - get { return _host.LastElementChild; } - } + public IElement LastElementChild => _host.LastElementChild; - public Int32 ChildElementCount - { - get { return _host.ChildElementCount; } - } + public Int32 ChildElementCount => _host.ChildElementCount; - public IElement NextElementSibling - { - get { return _host.NextElementSibling; } - } + public IElement NextElementSibling => _host.NextElementSibling; - public IElement PreviousElementSibling - { - get { return _host.PreviousElementSibling; } - } + public IElement PreviousElementSibling => _host.PreviousElementSibling; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssDeclarationRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssDeclarationRule.cs index 625c539d..0a4dec43 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssDeclarationRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssDeclarationRule.cs @@ -39,10 +39,7 @@ public String this[String propertyName] get { return GetValue(propertyName); } } - public Int32 Length - { - get { return _declarations.Count; } - } + public Int32 Length => _declarations.Count; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssDocumentRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssDocumentRule.cs index 8305ac42..1a2f2562 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssDocumentRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssDocumentRule.cs @@ -34,10 +34,7 @@ public String ConditionText set { SetConditionText(value, throwOnError: true); } } - public IDocumentFunctions Conditions - { - get { return _conditions; } - } + public IDocumentFunctions Conditions => _conditions; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssGroupingRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssGroupingRule.cs index f1310183..017bc32e 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssGroupingRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssGroupingRule.cs @@ -26,10 +26,7 @@ internal CssGroupingRule(ICssStyleSheet owner, CssRuleType type) #region Properties - public ICssRuleList Rules - { - get { return _rules; } - } + public ICssRuleList Rules => _rules; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssImportRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssImportRule.cs index 14728768..aeaac447 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssImportRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssImportRule.cs @@ -35,15 +35,9 @@ public String Href set { _href = value; } } - IMediaList ICssImportRule.Media - { - get { return _media; } - } + IMediaList ICssImportRule.Media => _media; - public MediaList Media - { - get { return _media; } - } + public MediaList Media => _media; public ICssStyleSheet Sheet { diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframeRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframeRule.cs index 63d9cf4e..29878ade 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframeRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframeRule.cs @@ -34,20 +34,11 @@ public String KeyText set { _selector = KeyframeParser.Parse(value); } } - public IKeyframeSelector Key - { - get { return _selector; } - } + public IKeyframeSelector Key => _selector; - ICssStyleDeclaration ICssKeyframeRule.Style - { - get { return _style; } - } + ICssStyleDeclaration ICssKeyframeRule.Style => _style; - public CssStyleDeclaration Style - { - get { return _style; } - } + public CssStyleDeclaration Style => _style; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssMediaRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssMediaRule.cs index 02d81b8e..702574a4 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssMediaRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssMediaRule.cs @@ -32,15 +32,9 @@ public String ConditionText set { _media.MediaText = value; } } - IMediaList ICssMediaRule.Media - { - get { return _media; } - } + IMediaList ICssMediaRule.Media => _media; - public MediaList Media - { - get { return _media; } - } + public MediaList Media => _media; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs index 8786360a..09ae8ae4 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs @@ -33,20 +33,11 @@ public String SelectorText set { _selector = ParseSelector(value); ; } } - public ISelector Selector - { - get { return _selector; } - } + public ISelector Selector => _selector; - ICssStyleDeclaration ICssPageRule.Style - { - get { return _style; } - } + ICssStyleDeclaration ICssPageRule.Style => _style; - public CssStyleDeclaration Style - { - get { return _style; } - } + public CssStyleDeclaration Style => _style; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssStyleRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssStyleRule.cs index 7994b03e..0a7d3d5a 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssStyleRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssStyleRule.cs @@ -27,10 +27,7 @@ internal CssStyleRule(ICssStyleSheet owner) #region Properties - public ISelector Selector - { - get { return _selector; } - } + public ISelector Selector => _selector; public String SelectorText { @@ -38,15 +35,9 @@ public String SelectorText set { _selector = ParseSelector(value); } } - ICssStyleDeclaration ICssStyleRule.Style - { - get { return _style; } - } + ICssStyleDeclaration ICssStyleRule.Style => _style; - public CssStyleDeclaration Style - { - get { return _style; } - } + public CssStyleDeclaration Style => _style; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssSupportsRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssSupportsRule.cs index 60f3b698..2cf78883 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssSupportsRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssSupportsRule.cs @@ -33,10 +33,7 @@ public String ConditionText set { SetConditionText(value, throwOnError: true); } } - public IConditionFunction Condition - { - get { return _condition; } - } + public IConditionFunction Condition => _condition; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssUnknownRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssUnknownRule.cs index 32ec7621..43c2881e 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssUnknownRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssUnknownRule.cs @@ -29,15 +29,9 @@ public CssUnknownRule(ICssStyleSheet owner, String name, TextView content) #region Properties - public String Name - { - get { return _name; } - } + public String Name => _name; - public TextView Content - { - get { return _content; } - } + public TextView Content => _content; #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/StyleCollection.cs b/src/AngleSharp.Css/Dom/Internal/StyleCollection.cs index 473dc73c..3ea17208 100644 --- a/src/AngleSharp.Css/Dom/Internal/StyleCollection.cs +++ b/src/AngleSharp.Css/Dom/Internal/StyleCollection.cs @@ -28,10 +28,7 @@ public StyleCollection(IEnumerable sheets, IRenderDevice device) #region Properties - public IRenderDevice Device - { - get { return _device; } - } + public IRenderDevice Device => _device; #endregion diff --git a/src/AngleSharp.Css/Extensions/ElementExtensions.cs b/src/AngleSharp.Css/Extensions/ElementExtensions.cs index acf871e8..698e11a5 100644 --- a/src/AngleSharp.Css/Extensions/ElementExtensions.cs +++ b/src/AngleSharp.Css/Extensions/ElementExtensions.cs @@ -169,6 +169,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl { elementHidden = elementStyle.GetDisplay() == "none"; } + if (!String.IsNullOrEmpty(elementStyle.GetVisibility()) && elementHidden != true) { elementHidden = elementStyle.GetVisibility() != "visible"; @@ -190,9 +191,8 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl InnerTextCollection(child, sb, requiredLineBreakCounts, elementStyle); } - if (node is IText) + if (node is IText textElement) { - var textElement = (IText)node; ProcessText(textElement.Data, sb, parentStyle); } else if (node is IHtmlBreakRowElement) @@ -201,9 +201,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl } else if ((node is IHtmlTableCellElement && String.IsNullOrEmpty(elementStyle.GetDisplay())) || elementStyle.GetDisplay() == "table-cell") { - var nextSibling = node.NextSibling as IElement; - - if (nextSibling != null) + if (node.NextSibling is IElement nextSibling) { var nextSiblingCss = nextSibling.ComputeCurrentStyle(); @@ -215,9 +213,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl } else if ((node is IHtmlTableRowElement && String.IsNullOrEmpty(elementStyle.GetDisplay())) || elementStyle.GetDisplay() == "table-row") { - var nextSibling = node.NextSibling as IElement; - - if (nextSibling != null) + if (node.NextSibling is IElement nextSibling) { var nextSiblingCss = nextSibling.ComputeCurrentStyle(); @@ -229,16 +225,14 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl } else if (node is IHtmlParagraphElement) { - var startIndexCount = 0; - requiredLineBreakCounts.TryGetValue(startIndex, out startIndexCount); + requiredLineBreakCounts.TryGetValue(startIndex, out int startIndexCount); if (startIndexCount < 2) { requiredLineBreakCounts[startIndex] = 2; } - var endIndexCount = 0; - requiredLineBreakCounts.TryGetValue(sb.Length, out endIndexCount); + requiredLineBreakCounts.TryGetValue(sb.Length, out int endIndexCount); if (endIndexCount < 2) { @@ -261,16 +255,14 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl if (isBlockLevel.Value) { - var startIndexCount = 0; - requiredLineBreakCounts.TryGetValue(startIndex, out startIndexCount); + requiredLineBreakCounts.TryGetValue(startIndex, out int startIndexCount); if (startIndexCount < 1) { requiredLineBreakCounts[startIndex] = 1; } - var endIndexCount = 0; - requiredLineBreakCounts.TryGetValue(sb.Length, out endIndexCount); + requiredLineBreakCounts.TryGetValue(sb.Length, out int endIndexCount); if (endIndexCount < 1) { @@ -280,6 +272,26 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl } } + /// + /// Sets the style on all elements of the collection. + /// + /// The type of elements. + /// The collection to go over. + /// The action to trigger for each element style. + /// The collection for chaining. + public static IEnumerable SetStyle(this IEnumerable elements, Action change) + where TElement : IElement + { + change = change ?? throw new ArgumentNullException(nameof(change)); + + foreach (var element in elements) + { + change.Invoke(element.GetStyle()); + } + + return elements; + } + private static Boolean HasCssBox(INode node) { switch (node.NodeName) diff --git a/src/AngleSharp.Css/Parser/CssParser.cs b/src/AngleSharp.Css/Parser/CssParser.cs index 63041c3c..5b56e2e8 100644 --- a/src/AngleSharp.Css/Parser/CssParser.cs +++ b/src/AngleSharp.Css/Parser/CssParser.cs @@ -102,10 +102,7 @@ public CssParser(CssParserOptions options, IBrowsingContext context) /// /// Gets the specified options. /// - public CssParserOptions Options - { - get { return _options; } - } + public CssParserOptions Options => _options; #endregion diff --git a/src/AngleSharp.Css/Parser/Tokens/CssCommentToken.cs b/src/AngleSharp.Css/Parser/Tokens/CssCommentToken.cs index 8466f474..d21ffd66 100644 --- a/src/AngleSharp.Css/Parser/Tokens/CssCommentToken.cs +++ b/src/AngleSharp.Css/Parser/Tokens/CssCommentToken.cs @@ -25,10 +25,7 @@ public CssCommentToken(String data, Boolean bad) #region Properties - public Boolean IsBad - { - get { return _bad; } - } + public Boolean IsBad => _bad; #endregion } diff --git a/src/AngleSharp.Css/Parser/Tokens/CssStringToken.cs b/src/AngleSharp.Css/Parser/Tokens/CssStringToken.cs index eed46ca7..348c90f6 100644 --- a/src/AngleSharp.Css/Parser/Tokens/CssStringToken.cs +++ b/src/AngleSharp.Css/Parser/Tokens/CssStringToken.cs @@ -25,10 +25,7 @@ public CssStringToken(String data, Boolean bad = false) #region Properties - public Boolean IsBad - { - get { return _bad; } - } + public Boolean IsBad => _bad; #endregion } diff --git a/src/AngleSharp.Css/Parser/Tokens/CssToken.cs b/src/AngleSharp.Css/Parser/Tokens/CssToken.cs index 1f1bad18..7de428fa 100644 --- a/src/AngleSharp.Css/Parser/Tokens/CssToken.cs +++ b/src/AngleSharp.Css/Parser/Tokens/CssToken.cs @@ -27,15 +27,9 @@ public CssToken(CssTokenType type, String data) #region Properties - public CssTokenType Type - { - get { return _type; } - } + public CssTokenType Type => _type; - public String Data - { - get { return _data; } - } + public String Data => _data; public TextPosition Position { diff --git a/src/AngleSharp.Css/Parser/Tokens/CssUrlToken.cs b/src/AngleSharp.Css/Parser/Tokens/CssUrlToken.cs index a6408a08..bd1bfa09 100644 --- a/src/AngleSharp.Css/Parser/Tokens/CssUrlToken.cs +++ b/src/AngleSharp.Css/Parser/Tokens/CssUrlToken.cs @@ -25,10 +25,7 @@ public CssUrlToken(String data, Boolean bad = false) #region Properties - public Boolean IsBad - { - get { return _bad; } - } + public Boolean IsBad => _bad; #endregion } diff --git a/src/AngleSharp.Css/Values/Angle.cs b/src/AngleSharp.Css/Values/Angle.cs index ef99a9a1..d6c77f85 100644 --- a/src/AngleSharp.Css/Values/Angle.cs +++ b/src/AngleSharp.Css/Values/Angle.cs @@ -66,26 +66,17 @@ public Angle(Double value, Unit unit) /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); } - } + public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); /// /// Gets the value of the angle. /// - public Double Value - { - get { return _value; } - } + public Double Value => _value; /// /// Gets the type of the length. /// - public Unit Type - { - get { return _unit; } - } + public Unit Type => _unit; /// /// Gets the representation of the unit as a string. diff --git a/src/AngleSharp.Css/Values/BackgroundSize.cs b/src/AngleSharp.Css/Values/BackgroundSize.cs index fd47ef96..8a1c54bb 100644 --- a/src/AngleSharp.Css/Values/BackgroundSize.cs +++ b/src/AngleSharp.Css/Values/BackgroundSize.cs @@ -54,18 +54,12 @@ public BackgroundSize(ICssValue width, ICssValue height) /// /// Gets the width of the background. /// - public ICssValue Width - { - get { return _width; } - } + public ICssValue Width => _width; /// /// Gets the height of the background. /// - public ICssValue Height - { - get { return _height; } - } + public ICssValue Height => _height; /// /// Gets the CSS text representation. diff --git a/src/AngleSharp.Css/Values/BorderImage.cs b/src/AngleSharp.Css/Values/BorderImage.cs index 23f75b88..eefaa3bf 100644 --- a/src/AngleSharp.Css/Values/BorderImage.cs +++ b/src/AngleSharp.Css/Values/BorderImage.cs @@ -87,42 +87,27 @@ public String CssText /// /// Gets the associated image value. /// - public ICssValue Image - { - get { return _image; } - } + public ICssValue Image => _image; /// /// Gets the associated slice value. /// - public ICssValue Slice - { - get { return _slice; } - } + public ICssValue Slice => _slice; /// /// Gets the associated width value. /// - public ICssValue Widths - { - get { return _widths; } - } + public ICssValue Widths => _widths; /// /// Gets the associated outset value. /// - public ICssValue Outsets - { - get { return _outsets; } - } + public ICssValue Outsets => _outsets; /// /// Gets the associated repeat value. /// - public ICssValue Repeat - { - get { return _repeat; } - } + public ICssValue Repeat => _repeat; #endregion } diff --git a/src/AngleSharp.Css/Values/BorderImageSlice.cs b/src/AngleSharp.Css/Values/BorderImageSlice.cs index 882cc06f..d6a62586 100644 --- a/src/AngleSharp.Css/Values/BorderImageSlice.cs +++ b/src/AngleSharp.Css/Values/BorderImageSlice.cs @@ -45,42 +45,27 @@ public BorderImageSlice(Length top, Length right, Length bottom, Length left, Bo /// /// Gets the bottom coordinate. /// - public Length Bottom - { - get { return _bottom; } - } + public Length Bottom => _bottom; /// /// Gets the left coordinate. /// - public Length Left - { - get { return _left; } - } + public Length Left => _left; /// /// Gets the top coordinate. /// - public Length Top - { - get { return _top; } - } + public Length Top => _top; /// /// Gets the right coordinate. /// - public Length Right - { - get { return _right; } - } + public Length Right => _right; /// /// Gets if the slice should be filled. /// - public Boolean IsFilled - { - get { return _filled; } - } + public Boolean IsFilled => _filled; /// /// Gets the CSS text representation. diff --git a/src/AngleSharp.Css/Values/CalcAddExpression.cs b/src/AngleSharp.Css/Values/CalcAddExpression.cs index d36b3439..a696b624 100644 --- a/src/AngleSharp.Css/Values/CalcAddExpression.cs +++ b/src/AngleSharp.Css/Values/CalcAddExpression.cs @@ -25,25 +25,16 @@ public CalcAddExpression(ICssValue left, ICssValue right) /// /// Gets the left operand. /// - public ICssValue Left - { - get { return _left; } - } + public ICssValue Left => _left; /// /// Gets the right operand. /// - public ICssValue Right - { - get { return _right; } - } + public ICssValue Right => _right; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_left.CssText, " + ", _right.CssText); } - } + public String CssText => String.Concat(_left.CssText, " + ", _right.CssText); } } diff --git a/src/AngleSharp.Css/Values/CalcDivExpression.cs b/src/AngleSharp.Css/Values/CalcDivExpression.cs index ec26c7d8..9bff853a 100644 --- a/src/AngleSharp.Css/Values/CalcDivExpression.cs +++ b/src/AngleSharp.Css/Values/CalcDivExpression.cs @@ -25,25 +25,16 @@ public CalcDivExpression(ICssValue left, ICssValue right) /// /// Gets the left operand. /// - public ICssValue Left - { - get { return _left; } - } + public ICssValue Left => _left; /// /// Gets the right operand. /// - public ICssValue Right - { - get { return _right; } - } + public ICssValue Right => _right; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_left.CssText, " / ", _right.CssText); } - } + public String CssText => String.Concat(_left.CssText, " / ", _right.CssText); } } diff --git a/src/AngleSharp.Css/Values/CalcMulExpression.cs b/src/AngleSharp.Css/Values/CalcMulExpression.cs index 7e97e51f..442b437d 100644 --- a/src/AngleSharp.Css/Values/CalcMulExpression.cs +++ b/src/AngleSharp.Css/Values/CalcMulExpression.cs @@ -25,25 +25,16 @@ public CalcMulExpression(ICssValue left, ICssValue right) /// /// Gets the left operand. /// - public ICssValue Left - { - get { return _left; } - } + public ICssValue Left => _left; /// /// Gets the right operand. /// - public ICssValue Right - { - get { return _right; } - } + public ICssValue Right => _right; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_left.CssText, " * ", _right.CssText); } - } + public String CssText => String.Concat(_left.CssText, " * ", _right.CssText); } } diff --git a/src/AngleSharp.Css/Values/CalcSubExpression.cs b/src/AngleSharp.Css/Values/CalcSubExpression.cs index 264a8933..152d2f09 100644 --- a/src/AngleSharp.Css/Values/CalcSubExpression.cs +++ b/src/AngleSharp.Css/Values/CalcSubExpression.cs @@ -25,25 +25,16 @@ public CalcSubExpression(ICssValue left, ICssValue right) /// /// Gets the left operand. /// - public ICssValue Left - { - get { return _left; } - } + public ICssValue Left => _left; /// /// Gets the right operand. /// - public ICssValue Right - { - get { return _right; } - } + public ICssValue Right => _right; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_left.CssText, " - ", _right.CssText); } - } + public String CssText => String.Concat(_left.CssText, " - ", _right.CssText); } } diff --git a/src/AngleSharp.Css/Values/Color.cs b/src/AngleSharp.Css/Values/Color.cs index be3dc492..f6c3658d 100644 --- a/src/AngleSharp.Css/Values/Color.cs +++ b/src/AngleSharp.Css/Values/Color.cs @@ -424,50 +424,32 @@ public String CssText /// /// Gets the Int32 value of the color. /// - public Int32 Value - { - get { return _hashcode; } - } + public Int32 Value => _hashcode; /// /// Gets the alpha part of the color. /// - public Byte A - { - get { return _alpha; } - } + public Byte A => _alpha; /// /// Gets the alpha part of the color in percent (0..1). /// - public Double Alpha - { - get { return Math.Round(_alpha / 255.0, 2); } - } + public Double Alpha => Math.Round(_alpha / 255.0, 2); /// /// Gets the red part of the color. /// - public Byte R - { - get { return _red; } - } + public Byte R => _red; /// /// Gets the green part of the color. /// - public Byte G - { - get { return _green; } - } + public Byte G => _green; /// /// Gets the blue part of the color. /// - public Byte B - { - get { return _blue; } - } + public Byte B => _blue; #endregion diff --git a/src/AngleSharp.Css/Values/Colors.cs b/src/AngleSharp.Css/Values/Colors.cs index 7ee5bb50..a4a498e1 100644 --- a/src/AngleSharp.Css/Values/Colors.cs +++ b/src/AngleSharp.Css/Values/Colors.cs @@ -202,10 +202,7 @@ static class Colors /// /// Gets the available color names. /// - public static IEnumerable Names - { - get { return TheColors.Keys; } - } + public static IEnumerable Names => TheColors.Keys; #endregion diff --git a/src/AngleSharp.Css/Values/CounterDefinition.cs b/src/AngleSharp.Css/Values/CounterDefinition.cs index 2fcd1b7d..e1cd61e9 100644 --- a/src/AngleSharp.Css/Values/CounterDefinition.cs +++ b/src/AngleSharp.Css/Values/CounterDefinition.cs @@ -38,34 +38,22 @@ public CounterDefinition(String identifier, String listStyle, String separator) /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_identifier, " ", _listStyle, " ", _separator); } - } + public String CssText => String.Concat(_identifier, " ", _listStyle, " ", _separator); /// /// Gets the identifier of the counter. /// - public String CounterIdentifier - { - get { return _identifier; } - } + public String CounterIdentifier => _identifier; /// /// Gets the style of the counter. /// - public String ListStyle - { - get { return _listStyle; } - } + public String ListStyle => _listStyle; /// /// Gets the defined separator of the counter. /// - public String DefinedSeparator - { - get { return _separator; } - } + public String DefinedSeparator => _separator; #endregion } diff --git a/src/AngleSharp.Css/Values/CounterValue.cs b/src/AngleSharp.Css/Values/CounterValue.cs index e972cdac..fdebff3f 100644 --- a/src/AngleSharp.Css/Values/CounterValue.cs +++ b/src/AngleSharp.Css/Values/CounterValue.cs @@ -35,26 +35,17 @@ public CounterValue(String name, Int32 value) /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_name, " ", _value.ToString()); } - } + public String CssText => String.Concat(_name, " ", _value.ToString()); /// /// Gets the identifier of the counter. /// - public String Name - { - get { return _name; } - } + public String Name => _name; /// /// Gets the value of the counter. /// - public Int32 Value - { - get { return _value; } - } + public Int32 Value => _value; #endregion } diff --git a/src/AngleSharp.Css/Values/Counters.cs b/src/AngleSharp.Css/Values/Counters.cs index 5b5ccd2b..1d0feb01 100644 --- a/src/AngleSharp.Css/Values/Counters.cs +++ b/src/AngleSharp.Css/Values/Counters.cs @@ -31,17 +31,11 @@ public Counters(ICssValue[] counters) /// /// Gets the values of the contained counters. /// - public ICssValue[] Values - { - get { return _counters; } - } + public ICssValue[] Values => _counters; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return _counters != null ? _counters.Join(" ") : CssKeywords.None; } - } + public String CssText => _counters != null ? _counters.Join(" ") : CssKeywords.None; } } diff --git a/src/AngleSharp.Css/Values/CssChildValue.cs b/src/AngleSharp.Css/Values/CssChildValue.cs index 540b0682..88d3409f 100644 --- a/src/AngleSharp.Css/Values/CssChildValue.cs +++ b/src/AngleSharp.Css/Values/CssChildValue.cs @@ -25,25 +25,16 @@ public CssChildValue(ICssValue parent, ICssValue value = null) /// /// Gets the value of the shorthand. /// - public ICssValue Parent - { - get { return _parent; } - } + public ICssValue Parent => _parent; /// /// Gets the value of the longhand, if any. /// - public ICssValue Value - { - get { return _value; } - } + public ICssValue Value => _value; /// /// Gets the text representation of the longhand. /// - public String CssText - { - get { return _value?.CssText ?? String.Empty; } - } + public String CssText => _value?.CssText ?? String.Empty; } } diff --git a/src/AngleSharp.Css/Values/CssListValue.cs b/src/AngleSharp.Css/Values/CssListValue.cs index 2a406e6a..f156cf39 100644 --- a/src/AngleSharp.Css/Values/CssListValue.cs +++ b/src/AngleSharp.Css/Values/CssListValue.cs @@ -26,18 +26,12 @@ public CssListValue(ICssValue[] items) /// /// Gets the contained values. /// - public ICssValue[] Items - { - get { return _items; } - } + public ICssValue[] Items => _items; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return _items.Join(", "); } - } + public String CssText => _items.Join(", "); IEnumerator IEnumerable.GetEnumerator() { diff --git a/src/AngleSharp.Css/Values/Fraction.cs b/src/AngleSharp.Css/Values/Fraction.cs index 3be9cd4b..c52d0dd2 100644 --- a/src/AngleSharp.Css/Values/Fraction.cs +++ b/src/AngleSharp.Css/Values/Fraction.cs @@ -36,26 +36,17 @@ public Fraction(Double value, Unit unit) /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); } - } + public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); /// /// Gets the value of fraction. /// - public Double Value - { - get { return _value; } - } + public Double Value => _value; /// /// Gets the type of the length. /// - public Unit Type - { - get { return _unit; } - } + public Unit Type => _unit; /// /// Gets the representation of the unit as a string. diff --git a/src/AngleSharp.Css/Values/Frequency.cs b/src/AngleSharp.Css/Values/Frequency.cs index d8bbd630..aacce6fc 100644 --- a/src/AngleSharp.Css/Values/Frequency.cs +++ b/src/AngleSharp.Css/Values/Frequency.cs @@ -36,26 +36,17 @@ public Frequency(Double value, Unit unit) /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); } - } + public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); /// /// Gets the value of frequency. /// - public Double Value - { - get { return _value; } - } + public Double Value => _value; /// /// Gets the type of the length. /// - public Unit Type - { - get { return _unit; } - } + public Unit Type => _unit; /// /// Gets the representation of the unit as a string. diff --git a/src/AngleSharp.Css/Values/ImageRepeats.cs b/src/AngleSharp.Css/Values/ImageRepeats.cs index 04f66397..9649d9bb 100644 --- a/src/AngleSharp.Css/Values/ImageRepeats.cs +++ b/src/AngleSharp.Css/Values/ImageRepeats.cs @@ -26,18 +26,12 @@ public ImageRepeats(ICssValue horizontal, ICssValue vertical) /// /// Gets the value of the horizontal repeat component. /// - public ICssValue Horizontal - { - get { return _horizontal; } - } + public ICssValue Horizontal => _horizontal; /// /// Gets the value of the vertical repeat component. /// - public ICssValue Vertical - { - get { return _vertical; } - } + public ICssValue Vertical => _vertical; /// /// Gets the CSS text representation. diff --git a/src/AngleSharp.Css/Values/Length.cs b/src/AngleSharp.Css/Values/Length.cs index 60f8da8c..699f34b1 100644 --- a/src/AngleSharp.Css/Values/Length.cs +++ b/src/AngleSharp.Css/Values/Length.cs @@ -110,35 +110,23 @@ public String CssText /// Gets if the length is given in absolute units. /// Such a length may be converted to pixels. /// - public Boolean IsAbsolute - { - get { return _unit == Unit.In || _unit == Unit.Mm || _unit == Unit.Pc || _unit == Unit.Px || _unit == Unit.Pt || _unit == Unit.Cm; } - } + public Boolean IsAbsolute => _unit == Unit.In || _unit == Unit.Mm || _unit == Unit.Pc || _unit == Unit.Px || _unit == Unit.Pt || _unit == Unit.Cm; /// /// Gets if the length is given in relative units. /// Such a length cannot be converted to pixels. /// - public Boolean IsRelative - { - get { return !IsAbsolute; } - } + public Boolean IsRelative => !IsAbsolute; /// /// Gets the type of the length. /// - public Unit Type - { - get { return _unit; } - } + public Unit Type => _unit; /// /// Gets the value of the length. /// - public Double Value - { - get { return _value; } - } + public Double Value => _value; /// /// Gets the representation of the unit as a string. diff --git a/src/AngleSharp.Css/Values/LineNames.cs b/src/AngleSharp.Css/Values/LineNames.cs index b0374af7..51b58432 100644 --- a/src/AngleSharp.Css/Values/LineNames.cs +++ b/src/AngleSharp.Css/Values/LineNames.cs @@ -24,17 +24,11 @@ public LineNames(IEnumerable names) /// /// Gets the contained line names. /// - public String[] Names - { - get { return _names; } - } + public String[] Names => _names; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return $"[{String.Join(" ", _names)}]"; } - } + public String CssText => $"[{String.Join(" ", _names)}]"; } } diff --git a/src/AngleSharp.Css/Values/LinearGradient.cs b/src/AngleSharp.Css/Values/LinearGradient.cs index daa1ad55..7d5e5504 100644 --- a/src/AngleSharp.Css/Values/LinearGradient.cs +++ b/src/AngleSharp.Css/Values/LinearGradient.cs @@ -100,26 +100,17 @@ public String CssText /// /// Gets the angle of the linear gradient. /// - public ICssValue Angle - { - get { return _angle ?? Values.Angle.Half; } - } + public ICssValue Angle => _angle ?? Values.Angle.Half; /// /// Gets all stops. /// - public GradientStop[] Stops - { - get { return _stops; } - } + public GradientStop[] Stops => _stops; /// /// Gets if the gradient is repeating. /// - public Boolean IsRepeating - { - get { return _repeating; } - } + public Boolean IsRepeating => _repeating; #endregion } diff --git a/src/AngleSharp.Css/Values/MatrixTransform.cs b/src/AngleSharp.Css/Values/MatrixTransform.cs index f8e99e35..1c0cd7b4 100644 --- a/src/AngleSharp.Css/Values/MatrixTransform.cs +++ b/src/AngleSharp.Css/Values/MatrixTransform.cs @@ -30,10 +30,7 @@ internal MatrixTransform(Double[] values) /// /// Gets the name of the function. /// - public String Name - { - get { return _values.Length == 6 ? FunctionNames.Matrix : FunctionNames.Matrix3d; } - } + public String Name => _values.Length == 6 ? FunctionNames.Matrix : FunctionNames.Matrix3d; /// /// Gets the arguments. @@ -56,10 +53,7 @@ public ICssValue[] Arguments /// /// Gets the CSS text representation. /// - public String CssText - { - get { return Name.CssFunction(Arguments.Join(", ")); } - } + public String CssText => Name.CssFunction(Arguments.Join(", ")); /// /// Gets the value of the given index. diff --git a/src/AngleSharp.Css/Values/Periodic.cs b/src/AngleSharp.Css/Values/Periodic.cs index 75fb5f39..9a580093 100644 --- a/src/AngleSharp.Css/Values/Periodic.cs +++ b/src/AngleSharp.Css/Values/Periodic.cs @@ -69,34 +69,22 @@ public String CssText /// /// Gets the first value. /// - public T Top - { - get { return _values.Length > 0 ? _values[0] : default(T); } - } + public T Top => _values.Length > 0 ? _values[0] : default(T); /// /// Gets the second value. /// - public T Right - { - get { return _values.Length > 1 ? _values[1] : Top; } - } + public T Right => _values.Length > 1 ? _values[1] : Top; /// /// Gets the third value. /// - public T Bottom - { - get { return _values.Length > 2 ? _values[2] : Top; } - } + public T Bottom => _values.Length > 2 ? _values[2] : Top; /// /// Gets the fourth value. /// - public T Left - { - get { return _values.Length > 3 ? _values[3] : Right; } - } + public T Left => _values.Length > 3 ? _values[3] : Right; #endregion } diff --git a/src/AngleSharp.Css/Values/PerspectiveTransform.cs b/src/AngleSharp.Css/Values/PerspectiveTransform.cs index 08e4733e..65543201 100644 --- a/src/AngleSharp.Css/Values/PerspectiveTransform.cs +++ b/src/AngleSharp.Css/Values/PerspectiveTransform.cs @@ -29,34 +29,22 @@ internal PerspectiveTransform(ICssValue distance) /// /// Gets the name of the function. /// - public String Name - { - get { return FunctionNames.Perspective; } - } + public String Name => FunctionNames.Perspective; /// /// Gets the arguments. /// - public ICssValue[] Arguments - { - get { return new [] { _distance }; } - } + public ICssValue[] Arguments => new[] { _distance }; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return Name.CssFunction(_distance.CssText); } - } + public String CssText => Name.CssFunction(_distance.CssText); /// /// Gets the distance from the origin. /// - public ICssValue Distance - { - get { return _distance; } - } + public ICssValue Distance => _distance; #endregion diff --git a/src/AngleSharp.Css/Values/Point.cs b/src/AngleSharp.Css/Values/Point.cs index f21a6264..118bab34 100644 --- a/src/AngleSharp.Css/Values/Point.cs +++ b/src/AngleSharp.Css/Values/Point.cs @@ -136,18 +136,12 @@ public String CssText /// /// Gets the value for the x-coordinate. /// - public ICssValue X - { - get { return _x; } - } + public ICssValue X => _x; /// /// Gets the value for the y-coordinate. /// - public ICssValue Y - { - get { return _y; } - } + public ICssValue Y => _y; #endregion diff --git a/src/AngleSharp.Css/Values/Point3.cs b/src/AngleSharp.Css/Values/Point3.cs index bf9f87b3..c78041c9 100644 --- a/src/AngleSharp.Css/Values/Point3.cs +++ b/src/AngleSharp.Css/Values/Point3.cs @@ -40,25 +40,16 @@ public String CssText /// /// Gets the x coordinate. /// - public ICssValue X - { - get { return _x; } - } + public ICssValue X => _x; /// /// Gets the y coordinate. /// - public ICssValue Y - { - get { return _y; } - } + public ICssValue Y => _y; /// /// Gets the z coordinate. /// - public ICssValue Z - { - get { return _z; } - } + public ICssValue Z => _z; } } diff --git a/src/AngleSharp.Css/Values/RadialGradient.cs b/src/AngleSharp.Css/Values/RadialGradient.cs index af4cc8dd..17650c84 100644 --- a/src/AngleSharp.Css/Values/RadialGradient.cs +++ b/src/AngleSharp.Css/Values/RadialGradient.cs @@ -55,10 +55,7 @@ public RadialGradient(Boolean circle, Point center, ICssValue width, ICssValue h /// /// Gets the name of the function. /// - public String Name - { - get { return _repeating ? FunctionNames.RepeatingRadialGradient : FunctionNames.RadialGradient; } - } + public String Name => _repeating ? FunctionNames.RepeatingRadialGradient : FunctionNames.RadialGradient; /// /// Gets the arguments. @@ -118,66 +115,42 @@ public ICssValue[] Arguments /// /// Gets the CSS text representation. /// - public String CssText - { - get { return Name.CssFunction(Arguments.Join(", ")); } - } + public String CssText => Name.CssFunction(Arguments.Join(", ")); /// /// Gets if the gradient should always be displayed as a circle. /// - public Boolean IsCircle - { - get { return _circle; } - } + public Boolean IsCircle => _circle; /// /// Gets the special size mode of the gradient. /// - public SizeMode Mode - { - get { return _sizeMode; } - } + public SizeMode Mode => _sizeMode; /// /// Gets the position of the radial gradient. /// - public Point Position - { - get { return _center; } - } + public Point Position => _center; /// /// Gets the horizontal radius. /// - public ICssValue MajorRadius - { - get { return _width ?? Length.Full; } - } + public ICssValue MajorRadius => _width ?? Length.Full; /// /// Gets the vertical radius. /// - public ICssValue MinorRadius - { - get { return _height ?? Length.Full; } - } + public ICssValue MinorRadius => _height ?? Length.Full; /// /// Gets all stops. /// - public GradientStop[] Stops - { - get { return _stops; } - } + public GradientStop[] Stops => _stops; /// /// Gets if the gradient is repeating. /// - public Boolean IsRepeating - { - get { return _repeating; } - } + public Boolean IsRepeating => _repeating; #endregion diff --git a/src/AngleSharp.Css/Values/Resolution.cs b/src/AngleSharp.Css/Values/Resolution.cs index ac30639f..2b906fbe 100644 --- a/src/AngleSharp.Css/Values/Resolution.cs +++ b/src/AngleSharp.Css/Values/Resolution.cs @@ -36,26 +36,17 @@ public Resolution(Double value, Unit unit) /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); } - } + public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); /// /// Gets the value of resolution. /// - public Double Value - { - get { return _value; } - } + public Double Value => _value; /// /// Gets the type of the length. /// - public Unit Type - { - get { return _unit; } - } + public Unit Type => _unit; /// /// Gets the representation of the unit as a string. diff --git a/src/AngleSharp.Css/Values/RotateTransform.cs b/src/AngleSharp.Css/Values/RotateTransform.cs index 93c0f061..ba4d6529 100644 --- a/src/AngleSharp.Css/Values/RotateTransform.cs +++ b/src/AngleSharp.Css/Values/RotateTransform.cs @@ -71,19 +71,13 @@ public String Name /// /// Gets the arguments. /// - public ICssValue[] Arguments - { - get - { - return new ICssValue[] + public ICssValue[] Arguments => new ICssValue[] { new Length(_x, Length.Unit.None), new Length(_y, Length.Unit.None), new Length(_z, Length.Unit.None), _angle, }; - } - } /// /// Gets the CSS text representation. @@ -107,34 +101,22 @@ public String CssText /// /// Gets the value of the x-component of the rotation vector. /// - public Double X - { - get { return _x; } - } + public Double X => _x; /// /// Gets the value of the y-component of the rotation vector. /// - public Double Y - { - get { return _y; } - } + public Double Y => _y; /// /// Gets the value of the z-component of the rotation vector. /// - public Double Z - { - get { return _z; } - } + public Double Z => _z; /// /// Gets the angle. /// - public ICssValue Angle - { - get { return _angle; } - } + public ICssValue Angle => _angle; #endregion diff --git a/src/AngleSharp.Css/Values/ScaleTransform.cs b/src/AngleSharp.Css/Values/ScaleTransform.cs index d044372a..31e7a0e3 100644 --- a/src/AngleSharp.Css/Values/ScaleTransform.cs +++ b/src/AngleSharp.Css/Values/ScaleTransform.cs @@ -68,18 +68,12 @@ public String Name /// /// Gets the arguments. /// - public ICssValue[] Arguments - { - get - { - return new ICssValue[] + public ICssValue[] Arguments => new ICssValue[] { new Length(_sx, Length.Unit.None), new Length(_sy, Length.Unit.None), new Length(_sz, Length.Unit.None), }; - } - } /// /// Gets the CSS text representation. @@ -122,26 +116,17 @@ public String CssText /// /// Gets the scaling in x-direction. /// - public Double ScaleX - { - get { return _sx; } - } + public Double ScaleX => _sx; /// /// Gets the scaling in y-direction. /// - public Double ScaleY - { - get { return _sy; } - } + public Double ScaleY => _sy; /// /// Gets the scaling in z-direction. /// - public Double ScaleZ - { - get { return _sz; } - } + public Double ScaleZ => _sz; #endregion diff --git a/src/AngleSharp.Css/Values/SkewTransform.cs b/src/AngleSharp.Css/Values/SkewTransform.cs index af01a2d4..a1d1efe8 100644 --- a/src/AngleSharp.Css/Values/SkewTransform.cs +++ b/src/AngleSharp.Css/Values/SkewTransform.cs @@ -59,10 +59,7 @@ public String Name /// /// Gets the arguments. /// - public ICssValue[] Arguments - { - get { return new ICssValue[] { }; } - } + public ICssValue[] Arguments => new ICssValue[] { }; /// /// Gets the CSS text representation. @@ -92,18 +89,12 @@ public String CssText /// /// Gets the value of the first angle. /// - public ICssValue Alpha - { - get { return _alpha; } - } + public ICssValue Alpha => _alpha; /// /// Gets the value of the second angle. /// - public ICssValue Beta - { - get { return _beta; } - } + public ICssValue Beta => _beta; #endregion diff --git a/src/AngleSharp.Css/Values/StepsTimingFunction.cs b/src/AngleSharp.Css/Values/StepsTimingFunction.cs index 76c559e8..574248be 100644 --- a/src/AngleSharp.Css/Values/StepsTimingFunction.cs +++ b/src/AngleSharp.Css/Values/StepsTimingFunction.cs @@ -41,10 +41,7 @@ public StepsTimingFunction(Int32 intervals, Boolean start = false) /// /// Gets the name of the function. /// - public String Name - { - get { return FunctionNames.Steps; } - } + public String Name => FunctionNames.Steps; /// /// Gets the arguments. @@ -91,18 +88,12 @@ public String CssText /// /// Gets the numbers of intervals. /// - public Int32 Intervals - { - get { return _intervals; } - } + public Int32 Intervals => _intervals; /// /// Gets if the steps should occur in the beginning. /// - public Boolean IsStart - { - get { return _start; } - } + public Boolean IsStart => _start; #endregion } diff --git a/src/AngleSharp.Css/Values/Time.cs b/src/AngleSharp.Css/Values/Time.cs index e0e96176..ca396c45 100644 --- a/src/AngleSharp.Css/Values/Time.cs +++ b/src/AngleSharp.Css/Values/Time.cs @@ -45,26 +45,17 @@ public Time(Double value, Unit unit) /// /// Gets the CSS text representation. /// - public String CssText - { - get { return String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); } - } + public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString); /// /// Gets the value of time. /// - public Double Value - { - get { return _value; } - } + public Double Value => _value; /// /// Gets the type of the length. /// - public Unit Type - { - get { return _unit; } - } + public Unit Type => _unit; /// /// Gets the representation of the unit as a string. diff --git a/src/AngleSharp.Css/Values/TransformMatrix.cs b/src/AngleSharp.Css/Values/TransformMatrix.cs index e6f1e092..30ef20c8 100644 --- a/src/AngleSharp.Css/Values/TransformMatrix.cs +++ b/src/AngleSharp.Css/Values/TransformMatrix.cs @@ -106,98 +106,62 @@ public TransformMatrix( /// /// Gets the element of the 1st row, 1st column. /// - public Double M11 - { - get { return _matrix[0, 0]; } - } + public Double M11 => _matrix[0, 0]; /// /// Gets the element of the 1st row, 2nd column. /// - public Double M12 - { - get { return _matrix[0, 1]; } - } + public Double M12 => _matrix[0, 1]; /// /// Gets the element of the 1st row, 3rd column. /// - public Double M13 - { - get { return _matrix[0, 2]; } - } + public Double M13 => _matrix[0, 2]; /// /// Gets the element of the 2nd row, 1st column. /// - public Double M21 - { - get { return _matrix[1, 0]; } - } + public Double M21 => _matrix[1, 0]; /// /// Gets the element of the 2nd row, 2nd column. /// - public Double M22 - { - get { return _matrix[1, 1]; } - } + public Double M22 => _matrix[1, 1]; /// /// Gets the element of the 2nd row, 3rd column. /// - public Double M23 - { - get { return _matrix[1, 2]; } - } + public Double M23 => _matrix[1, 2]; /// /// Gets the element of the 3rd row, 1st column. /// - public Double M31 - { - get { return _matrix[2, 0]; } - } + public Double M31 => _matrix[2, 0]; /// /// Gets the element of the 3rd row, 2nd column. /// - public Double M32 - { - get { return _matrix[2, 1]; } - } + public Double M32 => _matrix[2, 1]; /// /// Gets the element of the 3rd row, 3rd column. /// - public Double M33 - { - get { return _matrix[2, 2]; } - } + public Double M33 => _matrix[2, 2]; /// /// Gets the x-element of the translation vector. /// - public Double Tx - { - get { return _matrix[0, 3]; } - } + public Double Tx => _matrix[0, 3]; /// /// Gets the y-element of the translation vector. /// - public Double Ty - { - get { return _matrix[1, 3]; } - } + public Double Ty => _matrix[1, 3]; /// /// Gets the z-element of the translation vector. /// - public Double Tz - { - get { return _matrix[2, 3]; } - } + public Double Tz => _matrix[2, 3]; #endregion diff --git a/src/AngleSharp.Css/Values/TranslateTransform.cs b/src/AngleSharp.Css/Values/TranslateTransform.cs index 6c319f30..3b4d4c2e 100644 --- a/src/AngleSharp.Css/Values/TranslateTransform.cs +++ b/src/AngleSharp.Css/Values/TranslateTransform.cs @@ -68,50 +68,32 @@ public String Name /// /// Gets the arguments. /// - public ICssValue[] Arguments - { - get - { - return new[] + public ICssValue[] Arguments => new[] { _x, _y, _z }; - } - } /// /// Gets the CSS text representation. /// - public String CssText - { - get { return Name.CssFunction(Arguments.Join(", ")); } - } + public String CssText => Name.CssFunction(Arguments.Join(", ")); /// /// Gets the shift in x-direction. /// - public ICssValue ShiftX - { - get { return _x; } - } + public ICssValue ShiftX => _x; /// /// Gets the shift in y-direction. /// - public ICssValue ShiftY - { - get { return _y; } - } + public ICssValue ShiftY => _y; /// /// Gets the shift in z-direction. /// - public ICssValue ShiftZ - { - get { return _z; } - } + public ICssValue ShiftZ => _z; #endregion diff --git a/src/AngleSharp.Css/Values/VarReference.cs b/src/AngleSharp.Css/Values/VarReference.cs index 968225a4..831eba29 100644 --- a/src/AngleSharp.Css/Values/VarReference.cs +++ b/src/AngleSharp.Css/Values/VarReference.cs @@ -37,10 +37,7 @@ public VarReference(String variableName, String defaultValue = null) /// /// Gets the name of the function. /// - public String Name - { - get { return FunctionNames.Var; } - } + public String Name => FunctionNames.Var; /// /// Gets the arguments. @@ -64,18 +61,12 @@ public ICssValue[] Arguments /// /// Gets the referenced variable name. /// - public String VariableName - { - get { return _variableName; } - } + public String VariableName => _variableName; /// /// Gets the defined fallback value, if any. /// - public String DefaultValue - { - get { return _defaultValue; } - } + public String DefaultValue => _defaultValue; /// /// Gets the CSS text representation. diff --git a/src/AngleSharp.Css/Values/VarReferences.cs b/src/AngleSharp.Css/Values/VarReferences.cs index e0769162..5c5aeb07 100644 --- a/src/AngleSharp.Css/Values/VarReferences.cs +++ b/src/AngleSharp.Css/Values/VarReferences.cs @@ -29,33 +29,21 @@ public VarReferences(String value, IEnumerable> r /// /// Gets the literal value of the shorthand. /// - public String Value - { - get { return _value; } - } + public String Value => _value; /// /// Gets the positions of the variable references. /// - public TextRange[] Ranges - { - get { return _ranges; } - } + public TextRange[] Ranges => _ranges; /// /// Gets the referenced variables. /// - public VarReference[] References - { - get { return _references; } - } + public VarReference[] References => _references; /// /// Gets the CSS text representation. /// - public String CssText - { - get { return _value; } - } + public String CssText => _value; } } diff --git a/src/AngleSharp.Performance.Common/TestResult.cs b/src/AngleSharp.Performance.Common/TestResult.cs index 8f3b3b94..5bdf17ec 100644 --- a/src/AngleSharp.Performance.Common/TestResult.cs +++ b/src/AngleSharp.Performance.Common/TestResult.cs @@ -19,20 +19,11 @@ public List Durations private set; } - public TimeSpan Shortest - { - get { return Durations.Count > 0 ? Durations.Min() : TimeSpan.Zero; } - } + public TimeSpan Shortest => Durations.Count > 0 ? Durations.Min() : TimeSpan.Zero; - public TimeSpan Longest - { - get { return Durations.Count > 0 ? Durations.Max() : TimeSpan.Zero; } - } + public TimeSpan Longest => Durations.Count > 0 ? Durations.Max() : TimeSpan.Zero; - public TimeSpan Average - { - get { return TimeSpan.FromMilliseconds(Durations.Count > 0 ? Durations.Average(m => m.TotalMilliseconds) : 0.0); } - } + public TimeSpan Average => TimeSpan.FromMilliseconds(Durations.Count > 0 ? Durations.Average(m => m.TotalMilliseconds) : 0.0); public TimeSpan Deviation { diff --git a/src/AngleSharp.Performance.Common/TestSuite.cs b/src/AngleSharp.Performance.Common/TestSuite.cs index 62a314e1..5f600951 100644 --- a/src/AngleSharp.Performance.Common/TestSuite.cs +++ b/src/AngleSharp.Performance.Common/TestSuite.cs @@ -39,20 +39,11 @@ public Int32 NumberOfReRuns set { _reruns = value; } } - internal IEnumerable Tests - { - get { return _tests; } - } + internal IEnumerable Tests => _tests; - internal IEnumerable Parsers - { - get { return _parsers; } - } + internal IEnumerable Parsers => _parsers; - internal IOutput Console - { - get { return _output; } - } + internal IOutput Console => _output; void Warmup() { diff --git a/src/AngleSharp.Performance.Css/AngleSharpParser.cs b/src/AngleSharp.Performance.Css/AngleSharpParser.cs index 647b9c95..8cfdc9da 100644 --- a/src/AngleSharp.Performance.Css/AngleSharpParser.cs +++ b/src/AngleSharp.Performance.Css/AngleSharpParser.cs @@ -14,15 +14,9 @@ class AngleSharpParser : ITestee }; private static readonly CssParser parser = new CssParser(options); - public String Name - { - get { return "AngleSharp"; } - } + public String Name => "AngleSharp"; - public Type Library - { - get { return typeof(BrowsingContext); } - } + public Type Library => typeof(BrowsingContext); public void Run(String source) { diff --git a/src/AngleSharp.Performance.Css/CsCssParser.cs b/src/AngleSharp.Performance.Css/CsCssParser.cs index 157a2d81..915051e0 100644 --- a/src/AngleSharp.Performance.Css/CsCssParser.cs +++ b/src/AngleSharp.Performance.Css/CsCssParser.cs @@ -5,15 +5,9 @@ class CsCssParser : ITestee { - public String Name - { - get { return "CsCss"; } - } + public String Name => "CsCss"; - public Type Library - { - get { return typeof(CssLoader); } - } + public Type Library => typeof(CssLoader); public void Run(String source) { diff --git a/src/AngleSharp.Performance.Css/ExCssParser.cs b/src/AngleSharp.Performance.Css/ExCssParser.cs index c69743d4..e389aa8c 100644 --- a/src/AngleSharp.Performance.Css/ExCssParser.cs +++ b/src/AngleSharp.Performance.Css/ExCssParser.cs @@ -5,15 +5,9 @@ class ExCssParser : ITestee { - public String Name - { - get { return "ExCSS"; } - } + public String Name => "ExCSS"; - public Type Library - { - get { return typeof(Parser); } - } + public Type Library => typeof(Parser); public void Run(String source) { diff --git a/src/AngleSharp.Performance.Utilities/StandardTests.cs b/src/AngleSharp.Performance.Utilities/StandardTests.cs index 3f122971..f2a1c708 100644 --- a/src/AngleSharp.Performance.Utilities/StandardTests.cs +++ b/src/AngleSharp.Performance.Utilities/StandardTests.cs @@ -12,10 +12,7 @@ public StandardTests() _tests = new List(); } - public List Tests - { - get { return _tests; } - } + public List Tests => _tests; public StandardTests Include(params String[] values) { diff --git a/src/AngleSharp.Performance.Utilities/UrlTests.cs b/src/AngleSharp.Performance.Utilities/UrlTests.cs index fe84fc7e..be94ff4e 100644 --- a/src/AngleSharp.Performance.Utilities/UrlTests.cs +++ b/src/AngleSharp.Performance.Utilities/UrlTests.cs @@ -17,10 +17,7 @@ public UrlTests(String extension, Boolean withBuffer = true) _extension = extension; } - public List Tests - { - get { return _tests; } - } + public List Tests => _tests; public async Task Include(params String[] urls) { From d203d5975da161053bbb27d4f79ea5a4ae7b66a1 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 13:22:13 +0200 Subject: [PATCH 12/49] Added test for issue #27 --- src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs index 88613609..2dff206c 100644 --- a/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs +++ b/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs @@ -759,5 +759,14 @@ public void CssGridTemplateRowsAndColumnsWithFractionsLegal() Assert.IsTrue(property.HasValue); Assert.AreEqual("100px 1fr / 50px 1fr", property.Value); } + + [Test] + public void CssRuleWithOnlyGridTemplateAreasLegal_Issue27() + { + var snippet = @"div#A { grid-template-areas: ""a b b"" ""a c d"" }"; + var rule = ParseRule(snippet); + var text = rule.CssText; + Assert.AreEqual(snippet, text); + } } } From 877982215115e9971724692920b7f09ec0e23d23 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 13:37:52 +0200 Subject: [PATCH 13/49] Fixed GetStyle when CSS not configured --- CHANGELOG.md | 4 ++- src/AngleSharp.Css.Tests/Mocks/SiteMapping.cs | 9 ++---- .../Parsing/LargeValues.cs | 11 +++++++ .../Dom/ElementCssInlineStyleExtensions.cs | 30 +++++++++---------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1504124e..7423bb72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ # 0.12.0 -Released on Thursday, May 2 2019. +Released on Thursday, May 5 2019. - Reference latest AngleSharp +- Returns `null` in `GetStyle` if CSS not configured (#15) - Added extension helper `SetStyle` to modify all styles of many elements (#22) +- Fixed bug regarding CSS grid serialization (#27) # 0.10.1 diff --git a/src/AngleSharp.Css.Tests/Mocks/SiteMapping.cs b/src/AngleSharp.Css.Tests/Mocks/SiteMapping.cs index 1456d526..0f93ab26 100644 --- a/src/AngleSharp.Css.Tests/Mocks/SiteMapping.cs +++ b/src/AngleSharp.Css.Tests/Mocks/SiteMapping.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Tests.Mocks +namespace AngleSharp.Css.Tests.Mocks { using AngleSharp.Xml; using AngleSharp.Xml.Dom; @@ -24,14 +24,11 @@ public String this[String url] get { var element = _xml.QuerySelector("entry[url='" + url + "']"); - return element != null ? element.TextContent : null; + return element?.TextContent; } } - public Boolean Contains(String url) - { - return this[url] != null; - } + public Boolean Contains(String url) => this[url] != null; public void Add(String url, String fileName) { diff --git a/src/AngleSharp.Css.Tests/Parsing/LargeValues.cs b/src/AngleSharp.Css.Tests/Parsing/LargeValues.cs index 21ba2b48..36d6e9d0 100644 --- a/src/AngleSharp.Css.Tests/Parsing/LargeValues.cs +++ b/src/AngleSharp.Css.Tests/Parsing/LargeValues.cs @@ -1,6 +1,7 @@ namespace AngleSharp.Css.Tests.Parsing { using AngleSharp.Css.Dom; + using AngleSharp.Html.Parser; using NUnit.Framework; using static CssConstructionFunctions; @@ -30,5 +31,15 @@ public void LargeNegativeZIndexShouldNotErrorAndBeCapped() var style = sheet.Rules[0] as ICssStyleRule; Assert.AreEqual("-2147483648", style.Style.GetZIndex()); } + + [Test] + public void SilentlyIgnoresErrorsWhenInvokedWithoutCss_Issue15() + { + var p = new HtmlParser(); + var dom = p.ParseDocument(@"
Test
"); + var div = dom.QuerySelector("div"); + var style = div.GetStyle(); + Assert.IsNull(style); + } } } diff --git a/src/AngleSharp.Css/Dom/ElementCssInlineStyleExtensions.cs b/src/AngleSharp.Css/Dom/ElementCssInlineStyleExtensions.cs index 4ef9b11e..a6cab36f 100644 --- a/src/AngleSharp.Css/Dom/ElementCssInlineStyleExtensions.cs +++ b/src/AngleSharp.Css/Dom/ElementCssInlineStyleExtensions.cs @@ -1,6 +1,7 @@ namespace AngleSharp.Css.Dom { using AngleSharp.Attributes; + using AngleSharp.Css.Parser; using AngleSharp.Dom; using System; using System.Runtime.CompilerServices; @@ -29,18 +30,7 @@ public static class ElementCssInlineStyleExtensions [DomAccessor(Accessors.Setter)] public static void SetStyle(this IElement element, String value) => element.SetAttribute(AttributeNames.Style, value); - internal static void UpdateStyle(this IElement element, String value) - { - if (_styles.TryGetValue(element, out ICssStyleDeclaration style)) - { - style.Update(value); - } - else - { - style = CreateStyle(element); - _styles.Add(element, style); - } - } + internal static void UpdateStyle(this IElement element, String value) => element.GetStyle()?.Update(value); private static ICssStyleDeclaration CreateStyle(IElement element) => CreateStyle(element, null); @@ -48,10 +38,18 @@ private static ICssStyleDeclaration CreateStyle(IElement element, String source) { var document = element.Owner; var context = document.Context; - var style = new CssStyleDeclaration(context); - style.Update(source ?? element.GetAttribute(AttributeNames.Style)); - style.Changed += value => element.SetAttribute(AttributeNames.Style, value); - return style; + var parser = context?.GetService(); + + // Seems to be run from a context with CSS + if (parser != null) + { + var style = new CssStyleDeclaration(context); + style.Update(source ?? element.GetAttribute(AttributeNames.Style)); + style.Changed += value => element.SetAttribute(AttributeNames.Style, value); + return style; + } + + return null; } } } From 6eb73f83ffd144e1c22ff9c1af3dc5eefb78d331 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 14:54:50 +0200 Subject: [PATCH 14/49] Added src converter fixes #25 --- CHANGELOG.md | 1 + src/AngleSharp.Css/Constants/CssKeywords.cs | 5 ++ .../Declarations/SrcDeclaration.cs | 2 +- src/AngleSharp.Css/ValueConverters.cs | 82 ++++++++++++------- src/AngleSharp.Css/Values/FontFormat.cs | 23 ++++++ src/AngleSharp.Css/Values/LocalFont.cs | 23 ++++++ 6 files changed, 107 insertions(+), 29 deletions(-) create mode 100644 src/AngleSharp.Css/Values/FontFormat.cs create mode 100644 src/AngleSharp.Css/Values/LocalFont.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 7423bb72..1a464e8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Released on Thursday, May 5 2019. - Reference latest AngleSharp - Returns `null` in `GetStyle` if CSS not configured (#15) - Added extension helper `SetStyle` to modify all styles of many elements (#22) +- Introduced special converter for the `src` declaration (#25) - Fixed bug regarding CSS grid serialization (#27) # 0.10.1 diff --git a/src/AngleSharp.Css/Constants/CssKeywords.cs b/src/AngleSharp.Css/Constants/CssKeywords.cs index ab226f3a..e6a8734e 100644 --- a/src/AngleSharp.Css/Constants/CssKeywords.cs +++ b/src/AngleSharp.Css/Constants/CssKeywords.cs @@ -191,6 +191,11 @@ public static class CssKeywords ///
public static readonly String MaxContent = "max-content"; + /// + /// The format keyword. + /// + public static readonly String Format = "format"; + /// /// The from keyword. /// diff --git a/src/AngleSharp.Css/Declarations/SrcDeclaration.cs b/src/AngleSharp.Css/Declarations/SrcDeclaration.cs index 4b1d0db1..3a146a3b 100644 --- a/src/AngleSharp.Css/Declarations/SrcDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/SrcDeclaration.cs @@ -7,7 +7,7 @@ static class SrcDeclaration { public static String Name = PropertyNames.Src; - public static IValueConverter Converter = Any; + public static IValueConverter Converter = SrcListConverter; public static PropertyFlags Flags = PropertyFlags.None; } diff --git a/src/AngleSharp.Css/ValueConverters.cs b/src/AngleSharp.Css/ValueConverters.cs index fe64081b..0bd24e02 100644 --- a/src/AngleSharp.Css/ValueConverters.cs +++ b/src/AngleSharp.Css/ValueConverters.cs @@ -850,63 +850,89 @@ static class ValueConverters public static readonly IValueConverter GridAutoConverter = Or(TrackSizeConverter.Many(), AssignInitial()); public static readonly IValueConverter GridLineConverter = Or( - Assign(CssKeywords.Auto, "auto"), + Assign(CssKeywords.Auto, CssKeywords.Auto), WithAny(Assign(CssKeywords.Span, true), IntegerConverter, IdentifierConverter), AssignInitial()); + public static readonly IValueConverter SrcListConverter = + WithOrder( + Or(UrlConverter, FromParser(ParseLocal)), + Or(FromParser(ParseFormat), None)) + .FromList(); + #endregion #region Helpers private static IValueConverter FromParser(Func converter) - where T : class, ICssValue + where T : class, ICssValue => new ClassValueConverter(converter); + + private static Func FromString(Func converter) => source => { - return new ClassValueConverter(converter); - } + var result = converter.Invoke(source); - private static Func FromString(Func converter) + if (result != null) + { + return new StringValue(result); + } + + return null; + }; + + private static Func FromInteger(Func converter) => source => { - return source => + var result = converter.Invoke(source); + + if (result.HasValue) { - var result = converter.Invoke(source); + return new Length(result.Value, Length.Unit.None); + } - if (result != null) - { - return new StringValue(result); - } + return null; + }; - return null; - }; - } + private static Func FromNumber(Func converter) => source => + { + var result = converter.Invoke(source); + + if (result.HasValue) + { + return new Length(result.Value, Length.Unit.None); + } + + return null; + }; - private static Func FromInteger(Func converter) + private static ICssFunctionValue ParseLocal(this StringSource source) { - return source => + if (source.IsFunction(CssKeywords.Local)) { - var result = converter.Invoke(source); + var content = source.ParseString() ?? source.ParseIdent(); + var f = source.SkipGetSkip(); - if (result.HasValue) + if (content != null && f == Symbols.RoundBracketClose) { - return new Length(result.Value, Length.Unit.None); + return new LocalFont(content); } + } - return null; - }; + return null; } - private static Func FromNumber(Func converter) + private static ICssFunctionValue ParseFormat(this StringSource source) { - return source => + if (source.IsFunction(CssKeywords.Format)) { - var result = converter.Invoke(source); + var content = source.ParseString() ?? source.ParseIdent(); + var f = source.SkipGetSkip(); - if (result.HasValue) + if (content != null && f == Symbols.RoundBracketClose) { - return new Length(result.Value, Length.Unit.None); + return new FontFormat(content); } + } - return null; - }; + return null; } #endregion diff --git a/src/AngleSharp.Css/Values/FontFormat.cs b/src/AngleSharp.Css/Values/FontFormat.cs new file mode 100644 index 00000000..1e4b8372 --- /dev/null +++ b/src/AngleSharp.Css/Values/FontFormat.cs @@ -0,0 +1,23 @@ +namespace AngleSharp.Css.Values +{ + using AngleSharp.Css.Converters; + using AngleSharp.Css.Dom; + using AngleSharp.Text; + using System; + + sealed class FontFormat : ICssFunctionValue + { + private readonly String _fontFormat; + + public FontFormat(String fontFormat) + { + _fontFormat = fontFormat; + } + + public String Name => CssKeywords.Format; + + public ICssValue[] Arguments => new[] { new StringValue(_fontFormat) }; + + public String CssText => Name.CssFunction(Arguments.Join(", ")); + } +} diff --git a/src/AngleSharp.Css/Values/LocalFont.cs b/src/AngleSharp.Css/Values/LocalFont.cs new file mode 100644 index 00000000..fbf839ec --- /dev/null +++ b/src/AngleSharp.Css/Values/LocalFont.cs @@ -0,0 +1,23 @@ +namespace AngleSharp.Css.Values +{ + using AngleSharp.Css.Converters; + using AngleSharp.Css.Dom; + using AngleSharp.Text; + using System; + + sealed class LocalFont : ICssFunctionValue + { + private readonly String _fontName; + + public LocalFont(String fontName) + { + _fontName = fontName; + } + + public String Name => CssKeywords.Local; + + public ICssValue[] Arguments => new[] { new StringValue(_fontName) }; + + public String CssText => Name.CssFunction(Arguments.Join(", ")); + } +} From 406e3b49a8994b1b3bc3b37d91e5f4b1d9fab1c0 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 15:25:41 +0200 Subject: [PATCH 15/49] Provided pointer-events fixes #16 --- CHANGELOG.md | 1 + .../Styling/HtmlCssIntegration.cs | 13 +++++ src/AngleSharp.Css/Constants/CssKeywords.cs | 25 ++++++++++ .../Declarations/PointerEventsDeclaration.cs | 15 ++++++ .../DefaultDeclarationFactory.cs | 6 +++ src/AngleSharp.Css/Dom/PointerEvent.cs | 49 +++++++++++++++++++ src/AngleSharp.Css/Map.cs | 17 +++++++ src/AngleSharp.Css/ValueConverters.cs | 5 ++ 8 files changed, 131 insertions(+) create mode 100644 src/AngleSharp.Css/Declarations/PointerEventsDeclaration.cs create mode 100644 src/AngleSharp.Css/Dom/PointerEvent.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a464e8b..bf26134e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Released on Thursday, May 5 2019. - Reference latest AngleSharp - Returns `null` in `GetStyle` if CSS not configured (#15) +- Added `pointer-events` and fixed border recombination (#16) - Added extension helper `SetStyle` to modify all styles of many elements (#22) - Introduced special converter for the `src` declaration (#25) - Fixed bug regarding CSS grid serialization (#27) diff --git a/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs b/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs index f01fed2f..7cc75f59 100644 --- a/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs +++ b/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs @@ -416,5 +416,18 @@ public void RemovingPropertiesShouldNotYieldEmptyStyle_Issue14() Assert.AreEqual("background-color: rgba(0, 0, 0, 0); background-image: none; background-attachment: scroll; background-clip: border-box; background-origin: padding-box; background-repeat: repeat; background-size: auto auto", style.CssText); } + + [Test] + public void RecombinationWorksWithBorder_Issue16() + { + var expected = ""; + var document = ParseDocument(""); + var element = document.CreateElement("button"); + element.GetStyle().SetPointerEvents("auto"); + element.GetStyle().SetBorderWidth("1px"); + element.GetStyle().SetBorderStyle("solid"); + element.GetStyle().SetBorderColor("black"); + Assert.AreEqual(expected, element.ToHtml()); + } } } diff --git a/src/AngleSharp.Css/Constants/CssKeywords.cs b/src/AngleSharp.Css/Constants/CssKeywords.cs index e6a8734e..433e58d8 100644 --- a/src/AngleSharp.Css/Constants/CssKeywords.cs +++ b/src/AngleSharp.Css/Constants/CssKeywords.cs @@ -1500,5 +1500,30 @@ public static class CssKeywords /// The right bottom keyword. ///
public static readonly String RightBottom = "right bottom"; + + /// + /// The stroke keyword. + /// + public static readonly String Stroke = "stroke"; + + /// + /// The painted keyword. + /// + public static readonly String Painted = "painted"; + + /// + /// The visibleStroke keyword. + /// + public static readonly String VisibleStroke = "visibleStroke"; + + /// + /// The visibleFill keyword. + /// + public static readonly String VisibleFill = "visibleFill"; + + /// + /// The visiblePainted keyword. + /// + public static readonly String VisiblePainted = "visiblePainted"; } } diff --git a/src/AngleSharp.Css/Declarations/PointerEventsDeclaration.cs b/src/AngleSharp.Css/Declarations/PointerEventsDeclaration.cs new file mode 100644 index 00000000..84ad9744 --- /dev/null +++ b/src/AngleSharp.Css/Declarations/PointerEventsDeclaration.cs @@ -0,0 +1,15 @@ +namespace AngleSharp.Css.Declarations +{ + using AngleSharp.Css.Dom; + using System; + using static ValueConverters; + + static class PointerEventsDeclaration + { + public static String Name = PropertyNames.PointerEvents; + + public static IValueConverter Converter = Or(PointerEventConverter, AssignInitial(PointerEvent.Auto)); + + public static PropertyFlags Flags = PropertyFlags.Inherited; + } +} diff --git a/src/AngleSharp.Css/DefaultDeclarationFactory.cs b/src/AngleSharp.Css/DefaultDeclarationFactory.cs index 295aabc2..bdca5de4 100644 --- a/src/AngleSharp.Css/DefaultDeclarationFactory.cs +++ b/src/AngleSharp.Css/DefaultDeclarationFactory.cs @@ -1245,6 +1245,12 @@ public class DefaultDeclarationFactory : IDeclarationFactory converter: ScrollbarTrackColorDeclaration.Converter, flags: ScrollbarTrackColorDeclaration.Flags) }, + { + PointerEventsDeclaration.Name, new DeclarationInfo( + name: PointerEventsDeclaration.Name, + converter: PointerEventsDeclaration.Converter, + flags: PointerEventsDeclaration.Flags) + }, { OrderDeclaration.Name, new DeclarationInfo( name: OrderDeclaration.Name, diff --git a/src/AngleSharp.Css/Dom/PointerEvent.cs b/src/AngleSharp.Css/Dom/PointerEvent.cs new file mode 100644 index 00000000..b791ba33 --- /dev/null +++ b/src/AngleSharp.Css/Dom/PointerEvent.cs @@ -0,0 +1,49 @@ +namespace AngleSharp.Css.Dom +{ + /// + /// The values for pointer-event. + /// + public enum PointerEvent + { + /// + /// The element is never the target of pointer events; however, pointer events may target its descendant elements if those descendants have pointer-events set to some other value. In these circumstances, pointer events will trigger event listeners on this parent element as appropriate on their way to/from the descendant during the event capture/bubble phases. + /// + None, + /// + /// The element behaves as it would if the pointer-events property were not specified. In SVG content, this value and the value visiblePainted have the same effect. + /// + Auto, + /// + /// SVG only. The element can only be the target of a pointer event when the visibility property is set to visible and e.g. when a mouse cursor is over the interior (i.e., 'fill') of the element and the fill property is set to a value other than none, or when a mouse cursor is over the perimeter (i.e., 'stroke') of the element and the stroke property is set to a value other than none. + /// + VisiblePainted, + /// + /// SVG only. The element can only be the target of a pointer event when the visibility property is set to visible and when e.g. a mouse cursor is over the interior (i.e., fill) of the element. The value of the fill property does not affect event processing. + /// + VisibleFill, + /// + /// SVG only. The element can only be the target of a pointer event when the visibility property is set to visible and e.g. when the mouse cursor is over the perimeter (i.e., stroke) of the element. The value of the stroke property does not affect event processing. + /// + VisibleStroke, + /// + /// SVG only. The element can be the target of a pointer event when the visibility property is set to visible and e.g. the mouse cursor is over either the interior (i.e., fill) or the perimeter (i.e., stroke) of the element. The values of the fill and stroke do not affect event processing. + /// + Visible, + /// + /// SVG only. The element can only be the target of a pointer event when e.g. the mouse cursor is over the interior (i.e., 'fill') of the element and the fill property is set to a value other than none, or when the mouse cursor is over the perimeter (i.e., 'stroke') of the element and the stroke property is set to a value other than none. The value of the visibility property does not affect event processing. + /// + Painted, + /// + /// SVG only. The element can only be the target of a pointer event when the pointer is over the interior (i.e., fill) of the element. The values of the fill and visibility properties do not affect event processing. + /// + Fill, + /// + /// SVG only. The element can only be the target of a pointer event when the pointer is over the perimeter (i.e., stroke) of the element. The values of the stroke and visibility properties do not affect event processing. + /// + Stroke, + /// + /// SVG only. The element can only be the target of a pointer event when the pointer is over the interior (i.e., fill) or the perimeter (i.e., stroke) of the element. The values of the fill, stroke, and visibility properties do not affect event processing. + /// + All, + } +} diff --git a/src/AngleSharp.Css/Map.cs b/src/AngleSharp.Css/Map.cs index 55e488ce..6c8064e5 100644 --- a/src/AngleSharp.Css/Map.cs +++ b/src/AngleSharp.Css/Map.cs @@ -753,6 +753,23 @@ static class Map { CssKeywords.Start, RubyOverhangMode.Start }, }; + /// + /// Contains the string-PointerEvent mapping. + /// + public static readonly Dictionary PointerEvents = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + { CssKeywords.None, PointerEvent.None }, + { CssKeywords.Auto, PointerEvent.Auto }, + { CssKeywords.Visible, PointerEvent.Visible }, + { CssKeywords.VisibleFill, PointerEvent.VisibleFill }, + { CssKeywords.VisiblePainted, PointerEvent.VisiblePainted }, + { CssKeywords.VisibleStroke, PointerEvent.VisibleStroke }, + { CssKeywords.Painted, PointerEvent.Painted }, + { CssKeywords.Fill, PointerEvent.Fill }, + { CssKeywords.Stroke, PointerEvent.Stroke }, + { CssKeywords.All, PointerEvent.All }, + }; + /// /// Contains the string-FlexDirection mapping. /// diff --git a/src/AngleSharp.Css/ValueConverters.cs b/src/AngleSharp.Css/ValueConverters.cs index 0bd24e02..27361487 100644 --- a/src/AngleSharp.Css/ValueConverters.cs +++ b/src/AngleSharp.Css/ValueConverters.cs @@ -444,6 +444,11 @@ static class ValueConverters ///
public static readonly IValueConverter RubyPositionConverter = Map.RubyPositions.ToConverter(); + /// + /// Represents a converter for the PointerEvent enumeration. + /// + public static readonly IValueConverter PointerEventConverter = Map.PointerEvents.ToConverter(); + /// /// Represents a converter for the SystemFont enumeration. /// From a136533add5e2ed38160ecca344dbcff6b563374 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 19:59:13 +0200 Subject: [PATCH 16/49] Added default style sheet provider fixes #21 --- CHANGELOG.md | 1 + .../Extensions/InnerText.cs | 4 +- .../Mocks/DelayedStream.cs | 4 +- .../Styling/Configuration.cs | 7 +- .../Styling/HtmlCssIntegration.cs | 11 ++ .../CssConfigurationExtensions.cs | 13 +- .../CssDefaultStyleSheetProvider.cs | 125 ++++++++++++++++++ src/AngleSharp.Css/CssStylingService.cs | 125 +----------------- src/AngleSharp.Css/Dom/Internal/CssComment.cs | 7 +- .../Dom/Internal/CssMediaQueryList.cs | 9 +- src/AngleSharp.Css/Dom/Internal/CssMedium.cs | 16 +-- .../Dom/Internal/CssProperty.cs | 19 ++- src/AngleSharp.Css/Dom/Internal/CssRule.cs | 8 +- .../Dom/Internal/CssRuleList.cs | 27 +--- .../Dom/Internal/CssStyleDeclaration.cs | 12 +- .../Dom/Internal/CssStyleSheet.cs | 7 +- .../Dom/Internal/DocumentFunction.cs | 7 +- .../Dom/Internal/DocumentFunctions.cs | 37 ++---- src/AngleSharp.Css/Dom/Internal/MediaList.cs | 32 ++--- .../Dom/Internal/PseudoElement.cs | 16 +-- .../Dom/Internal/Rules/CssCharsetRule.cs | 4 +- .../Dom/Internal/Rules/CssDeclarationRule.cs | 5 +- .../Dom/Internal/Rules/CssDocumentRule.cs | 4 +- .../Dom/Internal/Rules/CssFontFaceRule.cs | 30 ++--- .../Dom/Internal/Rules/CssImportRule.cs | 6 +- .../Dom/Internal/Rules/CssKeyframeRule.cs | 4 +- .../Dom/Internal/Rules/CssKeyframesRule.cs | 4 +- .../Dom/Internal/Rules/CssMediaRule.cs | 4 +- .../Dom/Internal/Rules/CssNamespaceRule.cs | 4 +- .../Dom/Internal/Rules/CssPageRule.cs | 2 +- .../Dom/Internal/Rules/CssStyleRule.cs | 4 +- .../Dom/Internal/Rules/CssSupportsRule.cs | 4 +- .../Dom/Internal/StyleCollection.cs | 8 +- .../Dom/StyleCollectionExtensions.cs | 8 +- .../Extensions/CssApiExtensions.cs | 24 ++-- .../Extensions/MediaListExtensions.cs | 28 ++-- .../Extensions/ValidationExtensions.cs | 15 +-- .../ICssDefaultStyleSheetProvider.cs | 35 +++++ src/AngleSharp.Css/PrettyStyleFormatter.cs | 8 +- src/AngleSharp.Css/Values/MatrixTransform.cs | 5 +- .../TestSuite.cs | 8 +- 41 files changed, 322 insertions(+), 379 deletions(-) create mode 100644 src/AngleSharp.Css/CssDefaultStyleSheetProvider.cs create mode 100644 src/AngleSharp.Css/ICssDefaultStyleSheetProvider.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index bf26134e..c1de1592 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Released on Thursday, May 5 2019. - Reference latest AngleSharp - Returns `null` in `GetStyle` if CSS not configured (#15) - Added `pointer-events` and fixed border recombination (#16) +- Fixed missing `CssStylingService.Default` in cascade (#21) - Added extension helper `SetStyle` to modify all styles of many elements (#22) - Introduced special converter for the `src` declaration (#25) - Fixed bug regarding CSS grid serialization (#27) diff --git a/src/AngleSharp.Css.Tests/Extensions/InnerText.cs b/src/AngleSharp.Css.Tests/Extensions/InnerText.cs index 9a2dd373..c8fe56b4 100644 --- a/src/AngleSharp.Css.Tests/Extensions/InnerText.cs +++ b/src/AngleSharp.Css.Tests/Extensions/InnerText.cs @@ -73,7 +73,9 @@ public void SetInnerText(String fixture, String expectedInnerText, String expect [TestCase("", "")] public void GetInnerText(String fixture, String expected) { - var config = Configuration.Default.WithCss(); + var defaultSheet = new CssDefaultStyleSheetProvider(); + defaultSheet.SetDefault(""); + var config = Configuration.Default.With(defaultSheet).WithCss(); var doc = fixture.ToHtmlDocument(config); Assert.AreEqual(expected, doc.Body.GetInnerText()); diff --git a/src/AngleSharp.Css.Tests/Mocks/DelayedStream.cs b/src/AngleSharp.Css.Tests/Mocks/DelayedStream.cs index f0fd3f49..38dc13da 100644 --- a/src/AngleSharp.Css.Tests/Mocks/DelayedStream.cs +++ b/src/AngleSharp.Css.Tests/Mocks/DelayedStream.cs @@ -35,8 +35,8 @@ public override void Flush() public override Int64 Position { - get { return _stream.Position; } - set { _stream.Position = value; } + get => _stream.Position; + set => _stream.Position = value; } public override async Task CopyToAsync(Stream destination, Int32 bufferSize, CancellationToken cancellationToken) diff --git a/src/AngleSharp.Css.Tests/Styling/Configuration.cs b/src/AngleSharp.Css.Tests/Styling/Configuration.cs index dec765e3..4d3b2576 100644 --- a/src/AngleSharp.Css.Tests/Styling/Configuration.cs +++ b/src/AngleSharp.Css.Tests/Styling/Configuration.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Tests.Styling +namespace AngleSharp.Css.Tests.Styling { using AngleSharp.Css.Dom; using AngleSharp.Io; @@ -30,10 +30,9 @@ public void ConfigurationWithExtensionLeavesOriginallyUnmodified() [Test] public void ObtainDefaultSheet() { - var service = new CssStylingService(); + var service = new CssDefaultStyleSheetProvider(); Assert.IsNotNull(service.Default); - Assert.IsTrue((service as IStylingService).SupportsType(MimeTypeNames.Css)); - var sheet = service.Default as ICssStyleSheet; + var sheet = service.Default; Assert.IsNotNull(sheet); Assert.AreEqual(49, sheet.Rules.Length); } diff --git a/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs b/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs index 7cc75f59..1af4d481 100644 --- a/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs +++ b/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs @@ -5,6 +5,7 @@ namespace AngleSharp.Css.Tests.Styling using AngleSharp.Css.Tests.Mocks; using AngleSharp.Dom; using AngleSharp.Html.Dom; + using AngleSharp.Html.Parser; using AngleSharp.Io; using NUnit.Framework; using System; @@ -429,5 +430,15 @@ public void RecombinationWorksWithBorder_Issue16() element.GetStyle().SetBorderColor("black"); Assert.AreEqual(expected, element.ToHtml()); } + + [Test] + public static void DefaultStyleSheetTest_Issue21() + { + var browsingContext = BrowsingContext.New(Configuration.Default.WithCss()); + var htmlParser = browsingContext.GetService(); + var document = htmlParser.ParseDocument("Hello, World!"); + var boldStyle = document.Body.FirstElementChild.ComputeCurrentStyle(); + Assert.AreEqual("bolder", boldStyle.GetFontWeight()); + } } } diff --git a/src/AngleSharp.Css/CssConfigurationExtensions.cs b/src/AngleSharp.Css/CssConfigurationExtensions.cs index 2afeb17f..5f544ed0 100644 --- a/src/AngleSharp.Css/CssConfigurationExtensions.cs +++ b/src/AngleSharp.Css/CssConfigurationExtensions.cs @@ -15,15 +15,18 @@ public static class CssConfigurationExtensions ///
/// The configuration to extend. /// Optional options for the parser. - /// Optional setup for the style engine. /// The new instance with the service. - public static IConfiguration WithCss(this IConfiguration configuration, CssParserOptions options = default(CssParserOptions), Action setup = null) + public static IConfiguration WithCss(this IConfiguration configuration, CssParserOptions options = default(CssParserOptions)) { if (configuration == null) throw new ArgumentNullException(nameof(configuration)); var service = new CssStylingService(); - setup?.Invoke(service); + + if (!configuration.Has()) + { + configuration = configuration.With(new CssDefaultStyleSheetProvider()); + } if (!configuration.Has()) { @@ -50,7 +53,9 @@ public static class CssConfigurationExtensions configuration = configuration.With(context => new CssParser(options, context)); } - return configuration.WithOnly(Factory.Observer).With(service); + return configuration + .WithOnly(Factory.Observer) + .WithOnly(service); } } } diff --git a/src/AngleSharp.Css/CssDefaultStyleSheetProvider.cs b/src/AngleSharp.Css/CssDefaultStyleSheetProvider.cs new file mode 100644 index 00000000..1afae9b4 --- /dev/null +++ b/src/AngleSharp.Css/CssDefaultStyleSheetProvider.cs @@ -0,0 +1,125 @@ +namespace AngleSharp.Css +{ + using AngleSharp.Css.Dom; + using AngleSharp.Css.Parser; + using System; + + sealed class CssDefaultStyleSheetProvider : ICssDefaultStyleSheetProvider + { + #region Fields + + private ICssStyleSheet _default; + + #endregion + + #region Properties + + public ICssStyleSheet Default => _default ?? (_default = Parse(DefaultSource)); + + #endregion + + #region Methods + + public void SetDefault(ICssStyleSheet sheet) => _default = sheet; + + public void SetDefault(String source) => SetDefault(Parse(source)); + + public void AppendDefault(String source) => SetDefault(Parse($"{DefaultSource}\r\n{source}")); + + #endregion + + #region Default Stylesheet + + private static ICssStyleSheet Parse(String source) + { + var parser = new CssParser(); + return parser.ParseStyleSheet(source); + } + + /// + /// Gets the source code for the by default used base stylesheet. + /// Taken from https://www.w3.org/TR/CSS22/sample.html. + /// + public static readonly String DefaultSource = @" +html, address, +blockquote, +body, dd, div, +dl, dt, fieldset, form, +frame, frameset, +h1, h2, h3, h4, +h5, h6, noframes, +ol, p, ul, center, +dir, hr, menu, pre { display: block; unicode-bidi: embed } +li { display: list-item } +head { display: none } +table { display: table } +tr { display: table-row } +thead { display: table-header-group } +tbody { display: table-row-group } +tfoot { display: table-footer-group } +col { display: table-column } +colgroup { display: table-column-group } +td, th { display: table-cell } +caption { display: table-caption } +th { font-weight: bolder; text-align: center } +caption { text-align: center } +body { margin: 8px } +h1 { font-size: 2em; margin: .67em 0 } +h2 { font-size: 1.5em; margin: .75em 0 } +h3 { font-size: 1.17em; margin: .83em 0 } +h4, p, +blockquote, ul, +fieldset, form, +ol, dl, dir, +menu { margin: 1.12em 0 } +h5 { font-size: .83em; margin: 1.5em 0 } +h6 { font-size: .75em; margin: 1.67em 0 } +h1, h2, h3, h4, +h5, h6, b, +strong { font-weight: bolder } +blockquote { margin-left: 40px; margin-right: 40px } +i, cite, em, +var, address { font-style: italic } +pre, tt, code, +kbd, samp { font-family: monospace } +pre { white-space: pre } +button, textarea, +input, select { display: inline-block } +big { font-size: 1.17em } +small, sub, sup { font-size: .83em } +sub { vertical-align: sub } +sup { vertical-align: super } +table { border-spacing: 2px; } +thead, tbody, +tfoot { vertical-align: middle } +td, th, tr { vertical-align: inherit } +s, strike, del { text-decoration: line-through } +hr { border: 1px inset } +ol, ul, dir, +menu, dd { margin-left: 40px } +ol { list-style-type: decimal } +ol ul, ul ol, +ul ul, ol ol { margin-top: 0; margin-bottom: 0 } +u, ins { text-decoration: underline } +br:before { content: '\A'; white-space: pre-line } +center { text-align: center } +:link, :visited { text-decoration: underline } +:focus { outline: thin dotted invert } + +/* Begin bidirectionality settings (do not change) */ +BDO[DIR='ltr'] { direction: ltr; unicode-bidi: bidi-override } +BDO[DIR='rtl'] { direction: rtl; unicode-bidi: bidi-override } + +*[DIR='ltr'] { direction: ltr; unicode-bidi: embed } +*[DIR='rtl'] { direction: rtl; unicode-bidi: embed } + +@media print { + h1 { page-break-before: always } + h1, h2, h3, + h4, h5, h6 { page-break-after: avoid } + ul, ol, dl { page-break-before: avoid } +}"; + + #endregion + } +} diff --git a/src/AngleSharp.Css/CssStylingService.cs b/src/AngleSharp.Css/CssStylingService.cs index a334c16c..f685d223 100644 --- a/src/AngleSharp.Css/CssStylingService.cs +++ b/src/AngleSharp.Css/CssStylingService.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css +namespace AngleSharp.Css { using AngleSharp.Css.Dom; using AngleSharp.Css.Parser; @@ -14,37 +14,9 @@ ///
public class CssStylingService : IStylingService { - #region Fields - - private ICssStyleSheet _default; - - #endregion - - #region Properties - - /// - /// Gets the default stylesheet as specified by the W3C: - /// http://www.w3.org/TR/CSS21/sample.html - /// - public ICssStyleSheet Default => _default ?? (_default = ParseDefault()); - - #endregion - #region Methods - Boolean IStylingService.SupportsType(String mimeType) - { - return mimeType.Isi(MimeTypeNames.Css); - } - - /// - /// Sets a new default stylesheet to use. - /// - /// The default stylesheet to use. - public void SetDefault(ICssStyleSheet sheet) - { - _default = sheet; - } + Boolean IStylingService.SupportsType(String mimeType) => mimeType.Isi(MimeTypeNames.Css); /// /// Creates a style sheet for the given response asynchronously. @@ -74,98 +46,5 @@ public async Task ParseStylesheetAsync(IResponse response, StyleOpt } #endregion - - #region Default Stylesheet - - private ICssStyleSheet ParseDefault() - { - var parser = new CssParser(); - return parser.ParseStyleSheet(DefaultSource); - } - - /// - /// Gets the source code for the by default used base stylesheet. - /// - public static readonly String DefaultSource = @" -html, address, -blockquote, -body, dd, div, -dl, dt, fieldset, form, -frame, frameset, -h1, h2, h3, h4, -h5, h6, noframes, -ol, p, ul, center, -dir, hr, menu, pre { display: block; unicode-bidi: embed } -li { display: list-item } -head { display: none } -table { display: table } -tr { display: table-row } -thead { display: table-header-group } -tbody { display: table-row-group } -tfoot { display: table-footer-group } -col { display: table-column } -colgroup { display: table-column-group } -td, th { display: table-cell } -caption { display: table-caption } -th { font-weight: bolder; text-align: center } -caption { text-align: center } -body { margin: 8px } -h1 { font-size: 2em; margin: .67em 0 } -h2 { font-size: 1.5em; margin: .75em 0 } -h3 { font-size: 1.17em; margin: .83em 0 } -h4, p, -blockquote, ul, -fieldset, form, -ol, dl, dir, -menu { margin: 1.12em 0 } -h5 { font-size: .83em; margin: 1.5em 0 } -h6 { font-size: .75em; margin: 1.67em 0 } -h1, h2, h3, h4, -h5, h6, b, -strong { font-weight: bolder } -blockquote { margin-left: 40px; margin-right: 40px } -i, cite, em, -var, address { font-style: italic } -pre, tt, code, -kbd, samp { font-family: monospace } -pre { white-space: pre } -button, textarea, -input, select { display: inline-block } -big { font-size: 1.17em } -small, sub, sup { font-size: .83em } -sub { vertical-align: sub } -sup { vertical-align: super } -table { border-spacing: 2px; } -thead, tbody, -tfoot { vertical-align: middle } -td, th, tr { vertical-align: inherit } -s, strike, del { text-decoration: line-through } -hr { border: 1px inset } -ol, ul, dir, -menu, dd { margin-left: 40px } -ol { list-style-type: decimal } -ol ul, ul ol, -ul ul, ol ol { margin-top: 0; margin-bottom: 0 } -u, ins { text-decoration: underline } -br:before { content: '\A'; white-space: pre-line } -center { text-align: center } -:link, :visited { text-decoration: underline } -:focus { outline: thin dotted invert } - -/* Begin bidirectionality settings (do not change) */ -BDO[DIR='ltr'] { direction: ltr; unicode-bidi: bidi-override } -BDO[DIR='rtl'] { direction: rtl; unicode-bidi: bidi-override } - -*[DIR='ltr'] { direction: ltr; unicode-bidi: embed } -*[DIR='rtl'] { direction: rtl; unicode-bidi: embed } - -@media print { - h1 { page-break-before: always } - h1, h2, h3, - h4, h5, h6 { page-break-after: avoid } - ul, ol, dl { page-break-before: avoid } -}"; - - #endregion } } diff --git a/src/AngleSharp.Css/Dom/Internal/CssComment.cs b/src/AngleSharp.Css/Dom/Internal/CssComment.cs index 91cc0f34..fb7f8f56 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssComment.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssComment.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using System; using System.IO; @@ -31,10 +31,7 @@ public CssComment(String data) #region String Representation - public void ToCss(TextWriter writer, IStyleFormatter formatter) - { - writer.Write(formatter.Comment(_data)); - } + public void ToCss(TextWriter writer, IStyleFormatter formatter) => writer.Write(formatter.Comment(_data)); #endregion } diff --git a/src/AngleSharp.Css/Dom/Internal/CssMediaQueryList.cs b/src/AngleSharp.Css/Dom/Internal/CssMediaQueryList.cs index b7b104a9..b57932d7 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssMediaQueryList.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssMediaQueryList.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using AngleSharp.Css.Dom.Events; using AngleSharp.Dom; @@ -50,11 +50,8 @@ public CssMediaQueryList(IWindow window, IMediaList media) #region Helpers - private Boolean ComputeMatched(IWindow window) - { - //TODO use Validate with RenderDevice - return false; - } + //TODO use Validate with RenderDevice + private Boolean ComputeMatched(IWindow window) => false; private void Resized(Object sender, Event ev) { diff --git a/src/AngleSharp.Css/Dom/Internal/CssMedium.cs b/src/AngleSharp.Css/Dom/Internal/CssMedium.cs index 0c2e04ff..986c7e63 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssMedium.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssMedium.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using AngleSharp.Text; using System; @@ -48,14 +48,7 @@ public CssMedium(String type, Boolean inverse, Boolean exclusive, IEnumerable _inverse; - public String Constraints - { - get - { - var constraints = Features.Select(m => m.ToCss()); - return String.Join(" and ", constraints); - } - } + public String Constraints => String.Join(" and ", Features.Select(m => m.ToCss())); #endregion @@ -87,10 +80,7 @@ public override Boolean Equals(Object obj) return false; } - public override Int32 GetHashCode() - { - return base.GetHashCode(); - } + public override Int32 GetHashCode() => base.GetHashCode(); public void ToCss(TextWriter writer, IStyleFormatter formatter) { diff --git a/src/AngleSharp.Css/Dom/Internal/CssProperty.cs b/src/AngleSharp.Css/Dom/Internal/CssProperty.cs index 0dd1d7be..d4934bed 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssProperty.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssProperty.cs @@ -40,14 +40,14 @@ internal CssProperty(String name, IValueConverter converter, PropertyFlags flags public ICssValue RawValue { - get { return _value; } - set { _value = value; } + get => _value; + set => _value = value; } - + public String Value { - get { return _value?.CssText ?? CssKeywords.Initial; } - set { _value = _converter.Convert(value); } + get => _value?.CssText ?? CssKeywords.Initial; + set => _value = _converter.Convert(value); } public Boolean HasValue => _value != null; @@ -66,8 +66,8 @@ public String Value public Boolean IsImportant { - get { return _important; } - set { _important = value; } + get => _important; + set => _important = value; } public String CssText => this.ToCss(); @@ -86,10 +86,7 @@ public Boolean IsImportant #region String Representation - public void ToCss(TextWriter writer, IStyleFormatter formatter) - { - writer.Write(formatter.Declaration(Name, Value, IsImportant)); - } + public void ToCss(TextWriter writer, IStyleFormatter formatter) => writer.Write(formatter.Declaration(Name, Value, IsImportant)); #endregion } diff --git a/src/AngleSharp.Css/Dom/Internal/CssRule.cs b/src/AngleSharp.Css/Dom/Internal/CssRule.cs index 52c51e24..d1e5b93d 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssRule.cs @@ -33,7 +33,7 @@ internal CssRule(ICssStyleSheet owner, CssRuleType type) public String CssText { - get { return this.ToCss(); } + get => this.ToCss(); set { var rule = Parser.ParseRule(Owner, value); @@ -50,7 +50,7 @@ public String CssText public ICssRule Parent { - get { return _parent; } + get => _parent; set { _parent = value; @@ -64,8 +64,8 @@ public ICssRule Parent public ICssStyleSheet Owner { - get { return _owner; } - set { _owner = value; } + get => _owner; + set => _owner = value; } public CssRuleType Type => _type; diff --git a/src/AngleSharp.Css/Dom/Internal/CssRuleList.cs b/src/AngleSharp.Css/Dom/Internal/CssRuleList.cs index 1f0e4c32..fe5c7a37 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssRuleList.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssRuleList.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using AngleSharp.Dom; using System; @@ -28,10 +28,7 @@ internal CssRuleList() #region Index - public ICssRule this[Int32 index] - { - get { return _rules[index]; } - } + public ICssRule this[Int32 index] => _rules[index]; #endregion @@ -45,10 +42,7 @@ public ICssRule this[Int32 index] #region Methods - public void Clear() - { - _rules.Clear(); - } + public void Clear() => _rules.Clear(); public void RemoveAt(Int32 index) { @@ -103,24 +97,15 @@ public void Add(ICssRule rule) } } - public void AddRange(IEnumerable rules) - { - _rules.AddRange(rules); - } + public void AddRange(IEnumerable rules) => _rules.AddRange(rules); #endregion #region Implemented Interface - public IEnumerator GetEnumerator() - { - return _rules.GetEnumerator(); - } + public IEnumerator GetEnumerator() => _rules.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs b/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs index 16df1fef..1405be76 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs @@ -48,15 +48,9 @@ public CssStyleDeclaration(ICssRule parent) #region Index - public String this[Int32 index] - { - get { return _declarations[index]?.Name; } - } + public String this[Int32 index] => _declarations[index]?.Name; - public String this[String name] - { - get { return GetPropertyValue(name); } - } + public String this[String name] => GetPropertyValue(name); #endregion @@ -66,7 +60,7 @@ public String this[String name] public String CssText { - get { return this.ToCss(); } + get => this.ToCss(); set { Update(value); RaiseChanged(); } } diff --git a/src/AngleSharp.Css/Dom/Internal/CssStyleSheet.cs b/src/AngleSharp.Css/Dom/Internal/CssStyleSheet.cs index ea35e3b6..fc91f96d 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssStyleSheet.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssStyleSheet.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using AngleSharp.Css.Parser; using AngleSharp.Dom; @@ -73,10 +73,7 @@ public String Href #region Methods - public void ToCss(TextWriter writer, IStyleFormatter formatter) - { - writer.Write(formatter.Sheet(Rules)); - } + public void ToCss(TextWriter writer, IStyleFormatter formatter) => writer.Write(formatter.Sheet(Rules)); public void Add(ICssRule rule) { diff --git a/src/AngleSharp.Css/Dom/Internal/DocumentFunction.cs b/src/AngleSharp.Css/Dom/Internal/DocumentFunction.cs index d8312731..40d19114 100644 --- a/src/AngleSharp.Css/Dom/Internal/DocumentFunction.cs +++ b/src/AngleSharp.Css/Dom/Internal/DocumentFunction.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using AngleSharp.Text; using System; @@ -42,10 +42,7 @@ internal DocumentFunction(String name, String data) #region String Representation - public void ToCss(TextWriter writer, IStyleFormatter formatter) - { - writer.Write(_name.CssFunction(_data.CssString())); - } + public void ToCss(TextWriter writer, IStyleFormatter formatter) => writer.Write(_name.CssFunction(_data.CssString())); #endregion } diff --git a/src/AngleSharp.Css/Dom/Internal/DocumentFunctions.cs b/src/AngleSharp.Css/Dom/Internal/DocumentFunctions.cs index 2641c6e8..fe96d11f 100644 --- a/src/AngleSharp.Css/Dom/Internal/DocumentFunctions.cs +++ b/src/AngleSharp.Css/Dom/Internal/DocumentFunctions.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using System; using System.Collections; @@ -19,42 +19,21 @@ public DocumentFunctions(List functions) _functions = functions; } - public IDocumentFunction this[Int32 index] - { - get { return _functions[index]; } - } + public IDocumentFunction this[Int32 index] => _functions[index]; public Int32 Length => _functions.Count; - public IEnumerator GetEnumerator() - { - return _functions.GetEnumerator(); - } + public IEnumerator GetEnumerator() => _functions.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - public void Add(IDocumentFunction function) - { - _functions.Add(function); - } + public void Add(IDocumentFunction function) => _functions.Add(function); - public void Remove(IDocumentFunction function) - { - _functions.Remove(function); - } + public void Remove(IDocumentFunction function) => _functions.Remove(function); - public void Clear() - { - _functions.Clear(); - } + public void Clear() => _functions.Clear(); - public void AddRange(IEnumerable functions) - { - _functions.AddRange(functions); - } + public void AddRange(IEnumerable functions) => _functions.AddRange(functions); public void ToCss(TextWriter writer, IStyleFormatter formatter) { diff --git a/src/AngleSharp.Css/Dom/Internal/MediaList.cs b/src/AngleSharp.Css/Dom/Internal/MediaList.cs index d6a3d0b4..ca9e3354 100644 --- a/src/AngleSharp.Css/Dom/Internal/MediaList.cs +++ b/src/AngleSharp.Css/Dom/Internal/MediaList.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { using AngleSharp.Css.Parser; using AngleSharp.Dom; @@ -31,10 +31,7 @@ internal MediaList(IBrowsingContext context) #region Index - public String this[Int32 index] - { - get { return _media[index].ToCss(); } - } + public String this[Int32 index] => _media[index].ToCss(); #endregion @@ -46,8 +43,8 @@ public String this[Int32 index] public String MediaText { - get { return this.ToCss(); } - set { SetMediaText(value, throwOnError: true); } + get => this.ToCss(); + set => SetMediaText(value, throwOnError: true); } #endregion @@ -76,20 +73,13 @@ public void SetMediaText(String value, Boolean throwOnError) public void Add(String newMedium) { - var medium = MediumParser.Parse(newMedium); - - if (medium == null) - throw new DomException(DomError.Syntax); - + var medium = MediumParser.Parse(newMedium) ?? throw new DomException(DomError.Syntax); _media.Add(medium); } public void Remove(String oldMedium) { - var medium = MediumParser.Parse(oldMedium); - - if (medium == null) - throw new DomException(DomError.Syntax); + var medium = MediumParser.Parse(oldMedium) ?? throw new DomException(DomError.Syntax); for (var i = 0; i < _media.Count; i++) { @@ -127,15 +117,9 @@ public void ToCss(TextWriter writer, IStyleFormatter formatter) #region IEnumerable implementation - public IEnumerator GetEnumerator() - { - return _media.GetEnumerator(); - } + public IEnumerator GetEnumerator() => _media.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion } diff --git a/src/AngleSharp.Css/Dom/Internal/PseudoElement.cs b/src/AngleSharp.Css/Dom/Internal/PseudoElement.cs index a10df293..3a68f57a 100644 --- a/src/AngleSharp.Css/Dom/Internal/PseudoElement.cs +++ b/src/AngleSharp.Css/Dom/Internal/PseudoElement.cs @@ -33,7 +33,7 @@ public PseudoElement(IElement host, String name) public String Slot { - get { return _host.Slot; } + get => _host.Slot; set { } } @@ -55,25 +55,25 @@ public String Slot public String ClassName { - get { return _host.ClassName; } + get => _host.ClassName; set { } } public String Id { - get { return _host.Id; } + get => _host.Id; set { } } public String InnerHtml { - get { return String.Empty; } + get => String.Empty; set { } } public String OuterHtml { - get { return String.Empty; } + get => String.Empty; set { } } @@ -107,14 +107,14 @@ public String OuterHtml public String NodeValue { - get { return _host.NodeValue; } + get => _host.NodeValue; set { } } public String TextContent { - get { return String.Empty; } - set { } + get => String.Empty; + set { } } public Boolean HasChildNodes => _host.HasChildNodes; diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssCharsetRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssCharsetRule.cs index 824c1063..391b5d8b 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssCharsetRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssCharsetRule.cs @@ -29,8 +29,8 @@ internal CssCharsetRule(ICssStyleSheet sheet) public String CharacterSet { - get { return _charSet; } - set { _charSet = value ?? String.Empty; } + get => _charSet; + set => _charSet = value ?? String.Empty; } #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssDeclarationRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssDeclarationRule.cs index 0a4dec43..08ec3efe 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssDeclarationRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssDeclarationRule.cs @@ -34,10 +34,7 @@ internal CssDeclarationRule(ICssStyleSheet owner, CssRuleType type, String name, #region Properties - public String this[String propertyName] - { - get { return GetValue(propertyName); } - } + public String this[String propertyName] => GetValue(propertyName); public Int32 Length => _declarations.Count; diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssDocumentRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssDocumentRule.cs index 1a2f2562..2c47ead0 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssDocumentRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssDocumentRule.cs @@ -30,8 +30,8 @@ internal CssDocumentRule(ICssStyleSheet owner) public String ConditionText { - get { return _conditions.ToCss(); } - set { SetConditionText(value, throwOnError: true); } + get => _conditions.ToCss(); + set => SetConditionText(value, throwOnError: true); } public IDocumentFunctions Conditions => _conditions; diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssFontFaceRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssFontFaceRule.cs index e6f92c04..88280984 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssFontFaceRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssFontFaceRule.cs @@ -37,49 +37,49 @@ internal CssFontFaceRule(ICssStyleSheet owner) String ICssFontFaceRule.Family { - get { return GetValue(PropertyNames.FontFamily); } - set { SetValue(PropertyNames.FontFamily, value); } + get => GetValue(PropertyNames.FontFamily); + set => SetValue(PropertyNames.FontFamily, value); } String ICssFontFaceRule.Source { - get { return GetValue(PropertyNames.Src); } - set { SetValue(PropertyNames.Src, value); } + get => GetValue(PropertyNames.Src); + set => SetValue(PropertyNames.Src, value); } String ICssFontFaceRule.Style { - get { return GetValue(PropertyNames.FontStyle); } - set { SetValue(PropertyNames.FontStyle, value); } + get => GetValue(PropertyNames.FontStyle); + set => SetValue(PropertyNames.FontStyle, value); } String ICssFontFaceRule.Weight { - get { return GetValue(PropertyNames.FontWeight); } - set { SetValue(PropertyNames.FontWeight, value); } + get => GetValue(PropertyNames.FontWeight); + set => SetValue(PropertyNames.FontWeight, value); } String ICssFontFaceRule.Stretch { - get { return GetValue(PropertyNames.FontStretch); } - set { SetValue(PropertyNames.FontStretch, value); } + get => GetValue(PropertyNames.FontStretch); + set => SetValue(PropertyNames.FontStretch, value); } String ICssFontFaceRule.Range { - get { return GetValue(PropertyNames.UnicodeRange); } - set { SetValue(PropertyNames.UnicodeRange, value); } + get => GetValue(PropertyNames.UnicodeRange); + set => SetValue(PropertyNames.UnicodeRange, value); } String ICssFontFaceRule.Variant { - get { return GetValue(PropertyNames.FontVariant); } - set { SetValue(PropertyNames.FontVariant, value); } + get => GetValue(PropertyNames.FontVariant); + set => SetValue(PropertyNames.FontVariant, value); } String ICssFontFaceRule.Features { - get { return String.Empty; } + get => String.Empty; set { } } diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssImportRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssImportRule.cs index aeaac447..1aec5a80 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssImportRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssImportRule.cs @@ -31,8 +31,8 @@ internal CssImportRule(ICssStyleSheet owner) public String Href { - get { return _href; } - set { _href = value; } + get => _href; + set => _href = value; } IMediaList ICssImportRule.Media => _media; @@ -41,7 +41,7 @@ public String Href public ICssStyleSheet Sheet { - get { return _styleSheet; } + get => _styleSheet; set { _styleSheet = value; _styleSheet?.SetParent(Owner); } } diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframeRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframeRule.cs index 29878ade..49bacd6b 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframeRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframeRule.cs @@ -30,8 +30,8 @@ internal CssKeyframeRule(ICssStyleSheet owner) public String KeyText { - get { return _selector?.ToCss(); } - set { _selector = KeyframeParser.Parse(value); } + get => _selector?.ToCss(); + set => _selector = KeyframeParser.Parse(value); } public IKeyframeSelector Key => _selector; diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframesRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframesRule.cs index 7eab58a1..ba792adf 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframesRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssKeyframesRule.cs @@ -29,8 +29,8 @@ internal CssKeyframesRule(ICssStyleSheet owner) public String Name { - get { return _name; } - set { _name = value; } + get => _name; + set => _name = value; } #endregion diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssMediaRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssMediaRule.cs index 702574a4..e3333dd5 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssMediaRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssMediaRule.cs @@ -28,8 +28,8 @@ internal CssMediaRule(ICssStyleSheet owner) public String ConditionText { - get { return _media.MediaText; } - set { _media.MediaText = value; } + get => _media.MediaText; + set => _media.MediaText = value; } IMediaList ICssMediaRule.Media => _media; diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssNamespaceRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssNamespaceRule.cs index eca3811c..b0d6db4b 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssNamespaceRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssNamespaceRule.cs @@ -32,13 +32,13 @@ internal CssNamespaceRule(ICssStyleSheet owner) public String NamespaceUri { - get { return _namespaceUri; } + get => _namespaceUri; set { CheckValidity(); _namespaceUri = value ?? String.Empty; } } public String Prefix { - get { return _prefix; } + get => _prefix; set { CheckValidity(); _prefix = value ?? String.Empty; } } diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs index 09ae8ae4..bebb2bcf 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssPageRule.cs @@ -29,7 +29,7 @@ internal CssPageRule(ICssStyleSheet owner) public String SelectorText { - get { return _selector?.Text; } + get => _selector?.Text; set { _selector = ParseSelector(value); ; } } diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssStyleRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssStyleRule.cs index 0a7d3d5a..8d8f5b0c 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssStyleRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssStyleRule.cs @@ -31,8 +31,8 @@ internal CssStyleRule(ICssStyleSheet owner) public String SelectorText { - get { return _selector?.Text; } - set { _selector = ParseSelector(value); } + get => _selector?.Text; + set => _selector = ParseSelector(value); } ICssStyleDeclaration ICssStyleRule.Style => _style; diff --git a/src/AngleSharp.Css/Dom/Internal/Rules/CssSupportsRule.cs b/src/AngleSharp.Css/Dom/Internal/Rules/CssSupportsRule.cs index 2cf78883..64725eef 100644 --- a/src/AngleSharp.Css/Dom/Internal/Rules/CssSupportsRule.cs +++ b/src/AngleSharp.Css/Dom/Internal/Rules/CssSupportsRule.cs @@ -29,8 +29,8 @@ internal CssSupportsRule(ICssStyleSheet owner) public String ConditionText { - get { return _condition.ToCss(); } - set { SetConditionText(value, throwOnError: true); } + get => _condition.ToCss(); + set => SetConditionText(value, throwOnError: true); } public IConditionFunction Condition => _condition; diff --git a/src/AngleSharp.Css/Dom/Internal/StyleCollection.cs b/src/AngleSharp.Css/Dom/Internal/StyleCollection.cs index 3ea17208..7aeea81d 100644 --- a/src/AngleSharp.Css/Dom/Internal/StyleCollection.cs +++ b/src/AngleSharp.Css/Dom/Internal/StyleCollection.cs @@ -1,6 +1,5 @@ -namespace AngleSharp.Css.Dom +namespace AngleSharp.Css.Dom { - using AngleSharp.Css.Extensions; using System.Collections; using System.Collections.Generic; @@ -93,10 +92,7 @@ private IEnumerable GetRules(ICssRuleList rules) } } - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); #endregion } diff --git a/src/AngleSharp.Css/Dom/StyleCollectionExtensions.cs b/src/AngleSharp.Css/Dom/StyleCollectionExtensions.cs index 81f249a8..b4ec369d 100644 --- a/src/AngleSharp.Css/Dom/StyleCollectionExtensions.cs +++ b/src/AngleSharp.Css/Dom/StyleCollectionExtensions.cs @@ -23,8 +23,12 @@ static class StyleCollectionExtensions public static StyleCollection GetStyleCollection(this IWindow window) { var document = window.Document; - var device = document.Context.GetService(); - var stylesheets = document.GetStyleSheets().OfType(); + var ctx = document.Context; + var device = ctx.GetService(); + var defaultStyleSheetProvider = ctx.GetServices(); + var defaultSheets = defaultStyleSheetProvider.Select(m => m.Default).Where(m => m != null); + var currentSheets = document.GetStyleSheets().OfType(); + var stylesheets = defaultSheets.Concat(currentSheets); return new StyleCollection(stylesheets, device); } diff --git a/src/AngleSharp.Css/Extensions/CssApiExtensions.cs b/src/AngleSharp.Css/Extensions/CssApiExtensions.cs index 4aa2e12d..272520df 100644 --- a/src/AngleSharp.Css/Extensions/CssApiExtensions.cs +++ b/src/AngleSharp.Css/Extensions/CssApiExtensions.cs @@ -19,9 +19,7 @@ public static class CssApiExtensions /// The computed style declaration if available. public static ICssStyleDeclaration ComputeCurrentStyle(this IElement element) { - if (element == null) - throw new ArgumentNullException(nameof(element)); - + element = element ?? throw new ArgumentNullException(nameof(element)); var document = element.Owner; var window = document?.DefaultView; return window?.GetComputedStyle(element); @@ -39,13 +37,10 @@ public static ICssStyleDeclaration ComputeCurrentStyle(this IElement element) /// /// The collection itself. public static T Css(this T elements, String propertyName, String propertyValue) - where T : IEnumerable + where T : class, IEnumerable { - if (elements == null) - throw new ArgumentNullException(nameof(elements)); - - if (propertyName == null) - throw new ArgumentNullException(nameof(propertyName)); + elements = elements ?? throw new ArgumentNullException(nameof(elements)); + propertyName = propertyName ?? throw new ArgumentNullException(nameof(propertyName)); foreach (var element in elements.OfType()) { @@ -66,13 +61,10 @@ public static T Css(this T elements, String propertyName, String propertyValu /// /// The collection itself. public static T Css(this T elements, IEnumerable> properties) - where T : IEnumerable + where T : class, IEnumerable { - if (elements == null) - throw new ArgumentNullException(nameof(elements)); - - if (properties == null) - throw new ArgumentNullException(nameof(properties)); + elements = elements ?? throw new ArgumentNullException(nameof(elements)); + properties = properties ?? throw new ArgumentNullException(nameof(properties)); foreach (var element in elements.OfType()) { @@ -97,7 +89,7 @@ public static T Css(this T elements, IEnumerable /// /// The collection itself. public static T Css(this T elements, Object properties) - where T : IEnumerable + where T : class, IEnumerable { var realProperties = properties.ToDictionary(); return elements.Css(realProperties); diff --git a/src/AngleSharp.Css/Extensions/MediaListExtensions.cs b/src/AngleSharp.Css/Extensions/MediaListExtensions.cs index 37602619..9b58d9ef 100644 --- a/src/AngleSharp.Css/Extensions/MediaListExtensions.cs +++ b/src/AngleSharp.Css/Extensions/MediaListExtensions.cs @@ -7,7 +7,8 @@ namespace AngleSharp.Css.Dom static class MediaListExtensions { - private readonly static ConditionalWeakTable AssociatedValidators = new ConditionalWeakTable(); + private readonly static ConditionalWeakTable AssociatedValidators = + new ConditionalWeakTable(); private readonly static String[] KnownTypes = { @@ -21,10 +22,8 @@ static class MediaListExtensions CssKeywords.All }; - public static void AssociateValidator(this IMediaFeature feature, IFeatureValidator validator) - { + public static void AssociateValidator(this IMediaFeature feature, IFeatureValidator validator) => AssociatedValidators.Add(feature, validator); - } public static Boolean Validate(this IMediaFeature feature, IRenderDevice device) { @@ -33,10 +32,7 @@ public static Boolean Validate(this IMediaFeature feature, IRenderDevice device) return validator?.Validate(feature, device) ?? false; } - public static Boolean Validate(this IMediaList list, IRenderDevice device) - { - return !list.Any(m => !m.Validate(device)); - } + public static Boolean Validate(this IMediaList list, IRenderDevice device) => !list.Any(m => !m.Validate(device)); public static Boolean Validate(this ICssMedium medium, IRenderDevice device) { @@ -48,16 +44,12 @@ public static Boolean Validate(this ICssMedium medium, IRenderDevice device) return !medium.IsInvalid(device) && !medium.Features.Any(m => m.Validate(device) == medium.IsInverse); } - private static Boolean IsInvalid(this ICssMedium medium, IRenderDevice device) - { - return medium.IsInvalid(device, CssKeywords.Screen, DeviceCategory.Screen) || - medium.IsInvalid(device, CssKeywords.Speech, DeviceCategory.Speech) || - medium.IsInvalid(device, CssKeywords.Print, DeviceCategory.Printer); - } + private static Boolean IsInvalid(this ICssMedium medium, IRenderDevice device) => + medium.IsInvalid(device, CssKeywords.Screen, DeviceCategory.Screen) || + medium.IsInvalid(device, CssKeywords.Speech, DeviceCategory.Speech) || + medium.IsInvalid(device, CssKeywords.Print, DeviceCategory.Printer); - private static Boolean IsInvalid(this ICssMedium medium, IRenderDevice device, String keyword, DeviceCategory category) - { - return keyword.Is(medium.Type) && (device.Category == category) == medium.IsInverse; - } + private static Boolean IsInvalid(this ICssMedium medium, IRenderDevice device, String keyword, DeviceCategory category) => + device != null && keyword.Is(medium.Type) && device.Category == category == medium.IsInverse; } } diff --git a/src/AngleSharp.Css/Extensions/ValidationExtensions.cs b/src/AngleSharp.Css/Extensions/ValidationExtensions.cs index 02fc5ccf..937c4cb5 100644 --- a/src/AngleSharp.Css/Extensions/ValidationExtensions.cs +++ b/src/AngleSharp.Css/Extensions/ValidationExtensions.cs @@ -14,10 +14,7 @@ public static class ValidationExtensions /// The rule to extend. /// The device to check for support. /// True if support is given, otherwise false. - public static Boolean IsValid(this ICssSupportsRule rule, IRenderDevice device) - { - return rule.Condition.Check(device); - } + public static Boolean IsValid(this ICssSupportsRule rule, IRenderDevice device) => rule.Condition.Check(device); /// /// Determines if the rule is valid for a given device. @@ -25,10 +22,7 @@ public static Boolean IsValid(this ICssSupportsRule rule, IRenderDevice device) /// The rule to extend. /// The device to check for conformance. /// True if support is given, otherwise false. - public static Boolean IsValid(this ICssMediaRule rule, IRenderDevice device) - { - return rule.Media.Validate(device); - } + public static Boolean IsValid(this ICssMediaRule rule, IRenderDevice device) => rule.Media.Validate(device); /// /// Determines if the rule is valid for a given URL. @@ -36,9 +30,6 @@ public static Boolean IsValid(this ICssMediaRule rule, IRenderDevice device) /// The rule to extend. /// The URL to check for conformance. /// True if the URL is matching, otherwise false. - public static Boolean IsValid(this ICssDocumentRule rule, Url url) - { - return rule.Conditions.Any(m => m.Matches(url)); - } + public static Boolean IsValid(this ICssDocumentRule rule, Url url) => rule.Conditions.Any(m => m.Matches(url)); } } diff --git a/src/AngleSharp.Css/ICssDefaultStyleSheetProvider.cs b/src/AngleSharp.Css/ICssDefaultStyleSheetProvider.cs new file mode 100644 index 00000000..8515c9d6 --- /dev/null +++ b/src/AngleSharp.Css/ICssDefaultStyleSheetProvider.cs @@ -0,0 +1,35 @@ +namespace AngleSharp.Css +{ + using AngleSharp.Css.Dom; + using System; + + /// + /// Handles the presence of a default stylesheet, if any. + /// + public interface ICssDefaultStyleSheetProvider + { + /// + /// Gets the default stylesheet for some basic styling. + /// + ICssStyleSheet Default { get; } + + /// + /// Sets a new default stylesheet to use. + /// + /// The default stylesheet to use. + void SetDefault(ICssStyleSheet sheet); + + /// + /// Sets a new default stylesheet to use. + /// + /// The source of the default stylesheet. + void SetDefault(String source); + + /// + /// Sets the default stylesheet to the W3C stylesheet together with + /// some custom extensions in form of the given source. + /// + /// The source of the custom stylesheet part. + void AppendDefault(String source); + } +} diff --git a/src/AngleSharp.Css/PrettyStyleFormatter.cs b/src/AngleSharp.Css/PrettyStyleFormatter.cs index 9084e646..09f23cd3 100644 --- a/src/AngleSharp.Css/PrettyStyleFormatter.cs +++ b/src/AngleSharp.Css/PrettyStyleFormatter.cs @@ -39,8 +39,8 @@ public PrettyStyleFormatter() /// public String Indentation { - get { return _intendString; } - set { _intendString = value; } + get => _intendString; + set => _intendString = value; } /// @@ -48,8 +48,8 @@ public String Indentation /// public String NewLine { - get { return _newLineString; } - set { _newLineString = value; } + get => _newLineString; + set => _newLineString = value; } #endregion diff --git a/src/AngleSharp.Css/Values/MatrixTransform.cs b/src/AngleSharp.Css/Values/MatrixTransform.cs index 1c0cd7b4..cfe1fc19 100644 --- a/src/AngleSharp.Css/Values/MatrixTransform.cs +++ b/src/AngleSharp.Css/Values/MatrixTransform.cs @@ -60,10 +60,7 @@ public ICssValue[] Arguments /// /// The index to look for. /// The value. - public Double this[Int32 index] - { - get { return _values[index]; } - } + public Double this[Int32 index] => _values[index]; #endregion diff --git a/src/AngleSharp.Performance.Common/TestSuite.cs b/src/AngleSharp.Performance.Common/TestSuite.cs index 5f600951..ddd474f1 100644 --- a/src/AngleSharp.Performance.Common/TestSuite.cs +++ b/src/AngleSharp.Performance.Common/TestSuite.cs @@ -29,14 +29,14 @@ public TestSuite(IEnumerable parsers, IEnumerable tests, IOutput public Int32 NumberOfRepeats { - get { return _repeats; } - set { _repeats = value; } + get => _repeats; + set => _repeats = value; } public Int32 NumberOfReRuns { - get { return _reruns; } - set { _reruns = value; } + get => _reruns; + set => _reruns = value; } internal IEnumerable Tests => _tests; From 9cc365f6a2a3c8878fa56f39860b6cfa5b370ba5 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 20:05:08 +0200 Subject: [PATCH 17/49] Fixed the NRE for IRenderDevice in @media #20 --- CHANGELOG.md | 1 + .../Styling/HtmlCssIntegration.cs | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1de1592..d21c0e93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Released on Thursday, May 5 2019. - Reference latest AngleSharp - Returns `null` in `GetStyle` if CSS not configured (#15) - Added `pointer-events` and fixed border recombination (#16) +- Fixed exception when not providing an `IRenderDevice` (#20) - Fixed missing `CssStylingService.Default` in cascade (#21) - Added extension helper `SetStyle` to modify all styles of many elements (#22) - Introduced special converter for the `src` declaration (#25) diff --git a/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs b/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs index 1af4d481..16e80145 100644 --- a/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs +++ b/src/AngleSharp.Css.Tests/Styling/HtmlCssIntegration.cs @@ -432,7 +432,7 @@ public void RecombinationWorksWithBorder_Issue16() } [Test] - public static void DefaultStyleSheetTest_Issue21() + public void DefaultStyleSheetTest_Issue21() { var browsingContext = BrowsingContext.New(Configuration.Default.WithCss()); var htmlParser = browsingContext.GetService(); @@ -440,5 +440,15 @@ public static void DefaultStyleSheetTest_Issue21() var boldStyle = document.Body.FirstElementChild.ComputeCurrentStyle(); Assert.AreEqual("bolder", boldStyle.GetFontWeight()); } + + [Test] + public void MediaRuleCssCausesException_Issue20() + { + var browsingContext = BrowsingContext.New(Configuration.Default.WithCss()); + var htmlParser = browsingContext.GetService(); + var document = htmlParser.ParseDocument(""); + var style = document.Body.ComputeCurrentStyle(); + Assert.IsNotNull(style); + } } } From 847d59a3bd6e4f817ed02603e7b3dd4e23379513 Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 23:31:09 +0200 Subject: [PATCH 18/49] WIP CSSOM value model --- CHANGELOG.md | 2 + src/AngleSharp.Css/Constants/InitialValues.cs | 275 +++++++++--------- .../Converters/AnyValueConverter.cs | 2 +- .../Declarations/BackgroundDeclaration.cs | 8 +- src/AngleSharp.Css/Map.cs | 2 +- .../Parser/Micro/CompoundParser.cs | 2 +- .../Parser/Micro/GradientParser.cs | 18 +- src/AngleSharp.Css/Parser/Micro/GridParser.cs | 2 +- .../Parser/Micro/IdentParser.cs | 2 +- .../Parser/Micro/TimingFunctionParser.cs | 12 +- .../Parser/Micro/TransformParser.cs | 8 +- src/AngleSharp.Css/ValueConverters.cs | 4 +- src/AngleSharp.Css/Values/Colors.cs | 6 +- .../Values/{ => Composites}/Background.cs | 2 +- .../{ => Composites}/BackgroundLayer.cs | 2 +- .../Values/{ => Composites}/BorderImage.cs | 2 +- .../{ => Composites}/BorderImageSlice.cs | 3 +- .../Values/{ => Composites}/BorderRadius.cs | 2 +- .../{ => Composites}/CalcAddExpression.cs | 2 +- .../{ => Composites}/CalcDivExpression.cs | 2 +- .../{ => Composites}/CalcMulExpression.cs | 2 +- .../{ => Composites}/CalcSubExpression.cs | 2 +- .../Values/{ => Composites}/Cursor.cs | 2 +- .../{ => Composites}/CursorDefinition.cs | 5 +- .../Values/{ => Composites}/FontInfo.cs | 2 +- .../Values/{ => Composites}/GradientStop.cs | 2 +- .../Values/{ => Composites}/Grid.cs | 2 +- .../Values/{ => Composites}/GridTemplate.cs | 6 +- .../Values/{ => Composites}/ImageRepeats.cs | 2 +- .../Values/{ => Composites}/Point.cs | 17 +- .../Values/{ => Composites}/Point3.cs | 2 +- .../Values/{ => Composites}/Shadow.cs | 2 +- .../Values/{ => Functions}/Calc.cs | 0 .../CubicBezierTimingFunction.cs | 8 +- .../Values/{ => Functions}/FitContent.cs | 0 .../Values/{ => Functions}/FontFormat.cs | 2 +- .../Values/{ => Functions}/LinearGradient.cs | 2 +- .../Values/{ => Functions}/LocalFont.cs | 2 +- .../Values/{ => Functions}/MatrixTransform.cs | 2 +- .../Values/{ => Functions}/MinMax.cs | 0 .../{ => Functions}/PerspectiveTransform.cs | 2 +- .../Values/{ => Functions}/RadialGradient.cs | 4 +- .../Values/{ => Functions}/Repeat.cs | 0 .../Values/{ => Functions}/RotateTransform.cs | 2 +- .../Values/{ => Functions}/ScaleTransform.cs | 8 +- .../Values/{ => Functions}/Shape.cs | 0 .../Values/{ => Functions}/SkewTransform.cs | 2 +- .../{ => Functions}/StepsTimingFunction.cs | 8 +- .../{ => Functions}/TranslateTransform.cs | 12 +- .../Values/{ => Functions}/UrlReference.cs | 4 +- .../Values/{ => Functions}/VarReference.cs | 16 +- .../Values/ICssCompositeValue.cs | 11 + .../Values/ICssFunctionValue.cs | 2 +- ...adient.cs => ICssGradientFunctionValue.cs} | 2 +- .../{IImageSource.cs => ICssImageValue.cs} | 4 +- .../Values/ICssMultipleValue.cs | 11 + .../Values/ICssPrimitiveValue.cs | 11 + src/AngleSharp.Css/Values/ICssRawValue.cs | 2 +- ...Function.cs => ICssTimingFunctionValue.cs} | 2 +- ...sform.cs => ICssTransformFunctionValue.cs} | 4 +- .../Values/{ => Multiples}/Counters.cs | 2 +- .../Values/{ => Multiples}/CssListValue.cs | 13 +- .../Values/{ => Multiples}/CssTupleValue.cs | 13 +- .../Values/{ => Multiples}/Periodic.cs | 2 +- .../Values/{ => Primitives}/Angle.cs | 40 +-- .../Values/{ => Primitives}/BackgroundSize.cs | 8 +- .../Values/{ => Primitives}/Color.cs | 78 ++--- .../Values/{ => Primitives}/Constant.cs | 3 +- .../{ => Primitives}/CounterDefinition.cs | 3 +- .../Values/{ => Primitives}/CounterValue.cs | 3 +- .../Values/{ => Primitives}/Fraction.cs | 26 +- .../Values/{ => Primitives}/Frequency.cs | 46 +-- .../Values/{ => Primitives}/Identifier.cs | 3 +- .../{StringValue.cs => Primitives/Label.cs} | 11 +- .../Values/{ => Primitives}/Length.cs | 39 +-- .../Values/{ => Primitives}/LineNames.cs | 2 +- .../Values/{ => Primitives}/Quote.cs | 3 +- .../Values/{ => Primitives}/Resolution.cs | 21 +- .../Values/{ => Primitives}/Time.cs | 45 +-- .../{CssAnyValue.cs => Raws/AnyValue.cs} | 4 +- .../Values/{ => Raws}/Default.cs | 0 .../Values/{ => Raws}/Inherit.cs | 0 .../Values/{ => Raws}/Initial.cs | 0 src/AngleSharp.Css/Values/{ => Raws}/Unset.cs | 0 .../Values/{ => Raws}/VarReferences.cs | 0 src/AngleSharp.Css/Values/TransformMatrix.cs | 8 +- 86 files changed, 371 insertions(+), 529 deletions(-) rename src/AngleSharp.Css/Values/{ => Composites}/Background.cs (96%) rename src/AngleSharp.Css/Values/{ => Composites}/BackgroundLayer.cs (97%) rename src/AngleSharp.Css/Values/{ => Composites}/BorderImage.cs (98%) rename src/AngleSharp.Css/Values/{ => Composites}/BorderImageSlice.cs (97%) rename src/AngleSharp.Css/Values/{ => Composites}/BorderRadius.cs (97%) rename src/AngleSharp.Css/Values/{ => Composites}/CalcAddExpression.cs (95%) rename src/AngleSharp.Css/Values/{ => Composites}/CalcDivExpression.cs (95%) rename src/AngleSharp.Css/Values/{ => Composites}/CalcMulExpression.cs (95%) rename src/AngleSharp.Css/Values/{ => Composites}/CalcSubExpression.cs (95%) rename src/AngleSharp.Css/Values/{ => Composites}/Cursor.cs (97%) rename src/AngleSharp.Css/Values/{ => Composites}/CursorDefinition.cs (85%) rename src/AngleSharp.Css/Values/{ => Composites}/FontInfo.cs (99%) rename src/AngleSharp.Css/Values/{ => Composites}/GradientStop.cs (97%) rename src/AngleSharp.Css/Values/{ => Composites}/Grid.cs (98%) rename src/AngleSharp.Css/Values/{ => Composites}/GridTemplate.cs (97%) rename src/AngleSharp.Css/Values/{ => Composites}/ImageRepeats.cs (97%) rename src/AngleSharp.Css/Values/{ => Composites}/Point.cs (93%) rename src/AngleSharp.Css/Values/{ => Composites}/Point3.cs (97%) rename src/AngleSharp.Css/Values/{ => Composites}/Shadow.cs (98%) rename src/AngleSharp.Css/Values/{ => Functions}/Calc.cs (100%) rename src/AngleSharp.Css/Values/{ => Functions}/CubicBezierTimingFunction.cs (94%) rename src/AngleSharp.Css/Values/{ => Functions}/FitContent.cs (100%) rename src/AngleSharp.Css/Values/{ => Functions}/FontFormat.cs (85%) rename src/AngleSharp.Css/Values/{ => Functions}/LinearGradient.cs (98%) rename src/AngleSharp.Css/Values/{ => Functions}/LocalFont.cs (85%) rename src/AngleSharp.Css/Values/{ => Functions}/MatrixTransform.cs (97%) rename src/AngleSharp.Css/Values/{ => Functions}/MinMax.cs (100%) rename src/AngleSharp.Css/Values/{ => Functions}/PerspectiveTransform.cs (96%) rename src/AngleSharp.Css/Values/{ => Functions}/RadialGradient.cs (97%) rename src/AngleSharp.Css/Values/{ => Functions}/Repeat.cs (100%) rename src/AngleSharp.Css/Values/{ => Functions}/RotateTransform.cs (98%) rename src/AngleSharp.Css/Values/{ => Functions}/ScaleTransform.cs (94%) rename src/AngleSharp.Css/Values/{ => Functions}/Shape.cs (100%) rename src/AngleSharp.Css/Values/{ => Functions}/SkewTransform.cs (98%) rename src/AngleSharp.Css/Values/{ => Functions}/StepsTimingFunction.cs (92%) rename src/AngleSharp.Css/Values/{ => Functions}/TranslateTransform.cs (94%) rename src/AngleSharp.Css/Values/{ => Functions}/UrlReference.cs (90%) rename src/AngleSharp.Css/Values/{ => Functions}/VarReference.cs (85%) create mode 100644 src/AngleSharp.Css/Values/ICssCompositeValue.cs rename src/AngleSharp.Css/Values/{IGradient.cs => ICssGradientFunctionValue.cs} (87%) rename src/AngleSharp.Css/Values/{IImageSource.cs => ICssImageValue.cs} (73%) create mode 100644 src/AngleSharp.Css/Values/ICssMultipleValue.cs create mode 100644 src/AngleSharp.Css/Values/ICssPrimitiveValue.cs rename src/AngleSharp.Css/Values/{ITimingFunction.cs => ICssTimingFunctionValue.cs} (69%) rename src/AngleSharp.Css/Values/{ITransform.cs => ICssTransformFunctionValue.cs} (84%) rename src/AngleSharp.Css/Values/{ => Multiples}/Counters.cs (96%) rename src/AngleSharp.Css/Values/{ => Multiples}/CssListValue.cs (78%) rename src/AngleSharp.Css/Values/{ => Multiples}/CssTupleValue.cs (84%) rename src/AngleSharp.Css/Values/{ => Multiples}/Periodic.cs (98%) rename src/AngleSharp.Css/Values/{ => Primitives}/Angle.cs (89%) rename src/AngleSharp.Css/Values/{ => Primitives}/BackgroundSize.cs (92%) rename src/AngleSharp.Css/Values/{ => Primitives}/Color.cs (91%) rename src/AngleSharp.Css/Values/{ => Primitives}/Constant.cs (93%) rename src/AngleSharp.Css/Values/{ => Primitives}/CounterDefinition.cs (95%) rename src/AngleSharp.Css/Values/{ => Primitives}/CounterValue.cs (94%) rename src/AngleSharp.Css/Values/{ => Primitives}/Fraction.cs (88%) rename src/AngleSharp.Css/Values/{ => Primitives}/Frequency.cs (87%) rename src/AngleSharp.Css/Values/{ => Primitives}/Identifier.cs (91%) rename src/AngleSharp.Css/Values/{StringValue.cs => Primitives/Label.cs} (75%) rename src/AngleSharp.Css/Values/{ => Primitives}/Length.cs (94%) rename src/AngleSharp.Css/Values/{ => Primitives}/LineNames.cs (95%) rename src/AngleSharp.Css/Values/{ => Primitives}/Quote.cs (95%) rename src/AngleSharp.Css/Values/{ => Primitives}/Resolution.cs (91%) rename src/AngleSharp.Css/Values/{ => Primitives}/Time.cs (84%) rename src/AngleSharp.Css/Values/{CssAnyValue.cs => Raws/AnyValue.cs} (91%) rename src/AngleSharp.Css/Values/{ => Raws}/Default.cs (100%) rename src/AngleSharp.Css/Values/{ => Raws}/Inherit.cs (100%) rename src/AngleSharp.Css/Values/{ => Raws}/Initial.cs (100%) rename src/AngleSharp.Css/Values/{ => Raws}/Unset.cs (100%) rename src/AngleSharp.Css/Values/{ => Raws}/VarReferences.cs (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index d21c0e93..ba47e5de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,13 @@ Released on Thursday, May 5 2019. - Reference latest AngleSharp +- Fixed empty value when removing properties (#14) - Returns `null` in `GetStyle` if CSS not configured (#15) - Added `pointer-events` and fixed border recombination (#16) - Fixed exception when not providing an `IRenderDevice` (#20) - Fixed missing `CssStylingService.Default` in cascade (#21) - Added extension helper `SetStyle` to modify all styles of many elements (#22) +- Opened CSSOM, e.g., declared `ICssFunctionValue` `public` (#24) - Introduced special converter for the `src` declaration (#25) - Fixed bug regarding CSS grid serialization (#27) diff --git a/src/AngleSharp.Css/Constants/InitialValues.cs b/src/AngleSharp.Css/Constants/InitialValues.cs index 88665083..7ba0409b 100644 --- a/src/AngleSharp.Css/Constants/InitialValues.cs +++ b/src/AngleSharp.Css/Constants/InitialValues.cs @@ -5,143 +5,146 @@ namespace AngleSharp.Css.Constants using AngleSharp.Dom; using System; + /// + /// A collection of initial values for the respective CSS declarations. + /// static class InitialValues { - public static readonly ICssValue ColorDeclaration = Color.Black; - public static readonly ICssValue BackgroundColorDeclaration = Color.Transparent; - public static readonly ICssValue BackgroundImageDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue BackgroundRepeatDeclaration = new ImageRepeats(new Identifier(CssKeywords.Repeat), new Identifier(CssKeywords.Repeat)); - public static readonly ICssValue BackgroundPositionDeclaration = new CssTupleValue(new ICssValue[] { new Length(0, Length.Unit.Percent), new Length(0, Length.Unit.Percent) }); - public static readonly ICssValue BackgroundSizeDeclaration = new BackgroundSize(new Constant(CssKeywords.Auto, Length.Auto), new Constant(CssKeywords.Auto, Length.Auto)); - public static readonly ICssValue BackgroundOriginDeclaration = new Constant(CssKeywords.BorderBox, BoxModel.PaddingBox); - public static readonly ICssValue BackgroundClipDeclaration = new Constant(CssKeywords.BorderBox, BoxModel.BorderBox); - public static readonly ICssValue BackgroundAttachmentDeclaration = new Constant(CssKeywords.Scroll, BackgroundAttachment.Scroll); - public static readonly ICssValue FontStyleDeclaration = new Constant(CssKeywords.Normal, FontStyle.Normal); - public static readonly ICssValue FontVariantDeclaration = new Constant(CssKeywords.Normal, FontVariant.Normal); - public static readonly ICssValue FontWeightDeclaration = new Constant(CssKeywords.Normal, FontWeight.Normal); - public static readonly ICssValue FontStretchDeclaration = new Constant(CssKeywords.Normal, FontStretch.Normal); - public static readonly ICssValue FontSizeDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue FontFamilyDeclaration = new StringValue("Times New Roman"); - public static readonly ICssValue LineHeightDeclaration = new Constant(CssKeywords.Normal, Length.Normal); - public static readonly ICssValue BorderTopWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue BorderRightWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue BorderBottomWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue BorderLeftWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue BorderTopStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); - public static readonly ICssValue BorderRightStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); - public static readonly ICssValue BorderBottomStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); - public static readonly ICssValue BorderLeftStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); - public static readonly ICssValue BorderTopColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); - public static readonly ICssValue BorderRightColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); - public static readonly ICssValue BorderBottomColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); - public static readonly ICssValue BorderLeftColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); - public static readonly ICssValue ColumnWidthDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue ColumnCountDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue ColumnRuleWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue ColumnRuleStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); - public static readonly ICssValue ColumnRuleColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); - public static readonly ICssValue AnimationNameDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue AnimationDurationDeclaration = Time.Zero; - public static readonly ICssValue AnimationTimingFunctionDeclaration = CubicBezierTimingFunction.Ease; - public static readonly ICssValue AnimationDelayDeclaration = Time.Zero; - public static readonly ICssValue AnimationIterationCountDeclaration = new Length(1, Length.Unit.None); - public static readonly ICssValue AnimationDirectionDeclaration = new Constant(CssKeywords.Normal, AnimationDirection.Normal); - public static readonly ICssValue AnimationFillModeDeclaration = new Constant(CssKeywords.None, AnimationFillStyle.None); - public static readonly ICssValue AnimationPlayStateDeclaration = new Constant(CssKeywords.Running, PlayState.Running); - public static readonly ICssValue TransitionDelayDeclaration = Time.Zero; - public static readonly ICssValue TransitionDurationDeclaration = Time.Zero; - public static readonly ICssValue TransitionPropertyDeclaration = new Identifier(CssKeywords.All); - public static readonly ICssValue TransitionTimingFunctionDeclaration = CubicBezierTimingFunction.Ease; - public static readonly ICssValue DirectionDeclaration = new Constant(CssKeywords.Ltr, DirectionMode.Ltr); - public static readonly ICssValue EmptyCellsDeclaration = new Constant(CssKeywords.Show, true); - public static readonly ICssValue FlexGrowDeclaration = new Length(0, Length.Unit.None); - public static readonly ICssValue FlexShrinkDeclaration = new Length(1, Length.Unit.None); - public static readonly ICssValue FlexBasisDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue FloatDeclaration = new Constant(CssKeywords.None, Floating.None); - public static readonly ICssValue BorderSpacingDeclaration = Length.Zero; - public static readonly ICssValue BoxShadowDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue BoxSizingDeclaration = new Constant(CssKeywords.ContentBox, BoxModel.ContentBox); - public static readonly ICssValue BreakAfterDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); - public static readonly ICssValue BreakBeforeDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); - public static readonly ICssValue BreakInsideDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); - public static readonly ICssValue PageBreakInsideDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); - public static readonly ICssValue PageBreakBeforeDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); - public static readonly ICssValue PageBreakAfterDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); - public static readonly ICssValue BottomDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue TopDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue LeftDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue RightDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue MinHeightDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue MinWidthDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue MaxHeightDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue MaxWidthDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue MarginLeftDeclaration = Length.Zero; - public static readonly ICssValue MarginBottomDeclaration = Length.Zero; - public static readonly ICssValue MarginRightDeclaration = Length.Zero; - public static readonly ICssValue MarginTopDeclaration = Length.Zero; - public static readonly ICssValue PaddingLeftDeclaration = Length.Zero; - public static readonly ICssValue PaddingBottomDeclaration = Length.Zero; - public static readonly ICssValue PaddingRightDeclaration = Length.Zero; - public static readonly ICssValue PaddingTopDeclaration = Length.Zero; - public static readonly ICssValue CaptionSideDeclaration = new Constant(CssKeywords.Top, true); - public static readonly ICssValue CursorDeclaration = new Constant(CssKeywords.Auto, SystemCursor.Auto); - public static readonly ICssValue OverflowWrapDeclaration = new Constant(CssKeywords.Normal, OverflowWrap.Normal); - public static readonly ICssValue WordSpacingDeclaration = new Constant(CssKeywords.Normal, Length.Normal); - public static readonly ICssValue WordBreakDeclaration = new Constant(CssKeywords.Normal, WordBreak.Normal); - public static readonly ICssValue VisibilityDeclaration = new Constant(CssKeywords.Visible, Visibility.Visible); - public static readonly ICssValue VerticalAlignDeclaration = new Constant(CssKeywords.Baseline, VerticalAlignment.Baseline); - public static readonly ICssValue OpacityDeclaration = new Length(1.0, Length.Unit.None); - public static readonly ICssValue OverflowDeclaration = new Constant(CssKeywords.Visible, OverflowMode.Visible); - public static readonly ICssValue OutlineWidthDeclaration = new Constant(CssKeywords.Medium, Length.Medium); - public static readonly ICssValue OutlineStyleDeclaration = new Constant(CssKeywords.None, LineStyle.None); - public static readonly ICssValue OutlineColorDeclaration = new Constant(CssKeywords.Invert, Color.InvertedColor); - public static readonly ICssValue TextTransformDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue TextShadowDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue TextRenderingDeclaration = new Constant(CssKeywords.Auto, null); - public static readonly ICssValue TextOverflowDeclaration = new Constant(CssKeywords.Auto, OverflowMode.Clip); - public static readonly ICssValue TextOrientationDeclaration = new Constant(CssKeywords.Mixed, null); - public static readonly ICssValue TextJustifyDeclaration = new Constant(CssKeywords.Auto, TextJustify.Auto); - public static readonly ICssValue TextIndentDeclaration = Length.Zero; - public static readonly ICssValue TextAlignDeclaration = new Constant(CssKeywords.Left, HorizontalAlignment.Left); - public static readonly ICssValue TextAlignLastDeclaration = new Constant(CssKeywords.Auto, TextAlignLast.Auto); - public static readonly ICssValue TextDecorationLineDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue TextDecorationStyleDeclaration = new Constant(CssKeywords.Solid, LineStyle.Solid); - public static readonly ICssValue TextDecorationColorDeclaration = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); - public static readonly ICssValue ListStyleTypeDeclaration = new Constant(CssKeywords.Disc, ListStyle.Disc); - public static readonly ICssValue ListStylePositionDeclaration = new Constant(CssKeywords.Outside, ListPosition.Outside); - public static readonly ICssValue ListStyleImageDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue LineBreakDeclaration = new Constant(CssKeywords.Auto, BreakMode.Auto); - public static readonly ICssValue GridTemplateRowsDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue GridTemplateColumnsDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue GridTemplateAreasDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue GridAutoRowsDeclaration = new Constant(CssKeywords.Auto, null); - public static readonly ICssValue GridAutoColumnsDeclaration = new Constant(CssKeywords.Auto, null); - public static readonly ICssValue GridAutoFlowDeclaration = new Constant(CssKeywords.Row, false); - public static readonly ICssValue GridColumnGapDeclaration = Length.Zero; - public static readonly ICssValue GridRowGapDeclaration = Length.Zero; - public static readonly ICssValue ColumnGapDeclaration = new Constant(CssKeywords.Normal, Length.Normal); - public static readonly ICssValue RowGapDeclaration = new Constant(CssKeywords.Normal, Length.Normal); - public static readonly ICssValue PerspectiveDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue PositionDeclaration = new Constant(CssKeywords.Inline, PositionMode.Static); - public static readonly ICssValue TransformDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue ClearModeDeclaration = new Constant(CssKeywords.None, ClearMode.None); - public static readonly ICssValue ClipDeclaration = new Constant(CssKeywords.Auto, Length.Auto); - public static readonly ICssValue ContentDeclaration = new Constant(CssKeywords.Normal, null); - public static readonly ICssValue CounterIncrementDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue CounterResetDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue DisplayDeclaration = new Constant(CssKeywords.Inline, DisplayMode.Inline); - public static readonly ICssValue BackfaceVisibilityDeclaration = new Constant(CssKeywords.Visible, Visibility.Visible); - public static readonly ICssValue BorderImageSourceDeclaration = new Constant(CssKeywords.None, null); - public static readonly ICssValue BorderImageSliceDeclaration = Length.Full; - public static readonly ICssValue BorderImageWidthDeclaration = new Length(1, Length.Unit.None); - public static readonly ICssValue BorderImageOutsetDeclaration = Length.Zero; - public static readonly ICssValue BorderImageRepeatDeclaration = new Constant(CssKeywords.Stretch, BorderRepeat.Stretch); - public static readonly ICssValue AlignSelfDeclaration = new Constant(CssKeywords.Auto, FlexContentMode.Auto); - public static readonly ICssValue AlignItemsDeclaration = new Constant(CssKeywords.Normal, null); - public static readonly ICssValue AlignContentDeclaration = new Constant(CssKeywords.Normal, null); - public static readonly ICssValue JustifyContentDeclaration = new Constant(CssKeywords.Normal, null); - public static readonly ICssValue JustifyItemsDeclaration = new Constant(CssKeywords.Legacy, null); - public static readonly ICssValue JustifySelfDeclaration = new Constant(CssKeywords.Auto, FlexContentMode.Auto); - public static readonly ICssValue ZIndexDeclaration = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue ColorDecl = Color.Black; + public static readonly ICssValue BackgroundColorDecl = Color.Transparent; + public static readonly ICssValue BackgroundImageDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue BackgroundRepeatDecl = new ImageRepeats(new Identifier(CssKeywords.Repeat), new Identifier(CssKeywords.Repeat)); + public static readonly ICssValue BackgroundPositionDecl = new CssTupleValue(new ICssValue[] { new Length(0, Length.Unit.Percent), new Length(0, Length.Unit.Percent) }); + public static readonly ICssValue BackgroundSizeDecl = new BackgroundSize(new Constant(CssKeywords.Auto, Length.Auto), new Constant(CssKeywords.Auto, Length.Auto)); + public static readonly ICssValue BackgroundOriginDecl = new Constant(CssKeywords.BorderBox, BoxModel.PaddingBox); + public static readonly ICssValue BackgroundClipDecl = new Constant(CssKeywords.BorderBox, BoxModel.BorderBox); + public static readonly ICssValue BackgroundAttachmentDecl = new Constant(CssKeywords.Scroll, BackgroundAttachment.Scroll); + public static readonly ICssValue FontStyleDecl = new Constant(CssKeywords.Normal, FontStyle.Normal); + public static readonly ICssValue FontVariantDecl = new Constant(CssKeywords.Normal, FontVariant.Normal); + public static readonly ICssValue FontWeightDecl = new Constant(CssKeywords.Normal, FontWeight.Normal); + public static readonly ICssValue FontStretchDecl = new Constant(CssKeywords.Normal, FontStretch.Normal); + public static readonly ICssValue FontSizeDecl = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue FontFamilyDecl = new Label("Times New Roman"); + public static readonly ICssValue LineHeightDecl = new Constant(CssKeywords.Normal, Length.Normal); + public static readonly ICssValue BorderTopWidthDecl = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue BorderRightWidthDecl = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue BorderBottomWidthDecl = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue BorderLeftWidthDecl = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue BorderTopStyleDecl = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue BorderRightStyleDecl = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue BorderBottomStyleDecl = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue BorderLeftStyleDecl = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue BorderTopColorDecl = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue BorderRightColorDecl = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue BorderBottomColorDecl = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue BorderLeftColorDecl = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue ColumnWidthDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue ColumnCountDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue ColumnRuleWidthDecl = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue ColumnRuleStyleDecl = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue ColumnRuleColorDecl = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue AnimationNameDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue AnimationDurationDecl = Time.Zero; + public static readonly ICssValue AnimationTimingFunctionDecl = CubicBezierTimingFunction.Ease; + public static readonly ICssValue AnimationDelayDecl = Time.Zero; + public static readonly ICssValue AnimationIterationCountDecl = new Length(1, Length.Unit.None); + public static readonly ICssValue AnimationDirectionDecl = new Constant(CssKeywords.Normal, AnimationDirection.Normal); + public static readonly ICssValue AnimationFillModeDecl = new Constant(CssKeywords.None, AnimationFillStyle.None); + public static readonly ICssValue AnimationPlayStateDecl = new Constant(CssKeywords.Running, PlayState.Running); + public static readonly ICssValue TransitionDelayDecl = Time.Zero; + public static readonly ICssValue TransitionDurationDecl = Time.Zero; + public static readonly ICssValue TransitionPropertyDecl = new Identifier(CssKeywords.All); + public static readonly ICssValue TransitionTimingFunctionDecl = CubicBezierTimingFunction.Ease; + public static readonly ICssValue DirectionDecl = new Constant(CssKeywords.Ltr, DirectionMode.Ltr); + public static readonly ICssValue EmptyCellsDecl = new Constant(CssKeywords.Show, true); + public static readonly ICssValue FlexGrowDecl = new Length(0, Length.Unit.None); + public static readonly ICssValue FlexShrinkDecl = new Length(1, Length.Unit.None); + public static readonly ICssValue FlexBasisDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue FloatDecl = new Constant(CssKeywords.None, Floating.None); + public static readonly ICssValue BorderSpacingDecl = Length.Zero; + public static readonly ICssValue BoxShadowDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue BoxSizingDecl = new Constant(CssKeywords.ContentBox, BoxModel.ContentBox); + public static readonly ICssValue BreakAfterDecl = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue BreakBeforeDecl = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue BreakInsideDecl = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue PageBreakInsideDecl = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue PageBreakBeforeDecl = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue PageBreakAfterDecl = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue BottomDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue TopDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue LeftDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue RightDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue MinHeightDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue MinWidthDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue MaxHeightDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue MaxWidthDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue MarginLeftDecl = Length.Zero; + public static readonly ICssValue MarginBottomDecl = Length.Zero; + public static readonly ICssValue MarginRightDecl = Length.Zero; + public static readonly ICssValue MarginTopDecl = Length.Zero; + public static readonly ICssValue PaddingLeftDecl = Length.Zero; + public static readonly ICssValue PaddingBottomDecl = Length.Zero; + public static readonly ICssValue PaddingRightDecl = Length.Zero; + public static readonly ICssValue PaddingTopDecl = Length.Zero; + public static readonly ICssValue CaptionSideDecl = new Constant(CssKeywords.Top, true); + public static readonly ICssValue CursorDecl = new Constant(CssKeywords.Auto, SystemCursor.Auto); + public static readonly ICssValue OverflowWrapDecl = new Constant(CssKeywords.Normal, OverflowWrap.Normal); + public static readonly ICssValue WordSpacingDecl = new Constant(CssKeywords.Normal, Length.Normal); + public static readonly ICssValue WordBreakDecl = new Constant(CssKeywords.Normal, WordBreak.Normal); + public static readonly ICssValue VisibilityDecl = new Constant(CssKeywords.Visible, Visibility.Visible); + public static readonly ICssValue VerticalAlignDecl = new Constant(CssKeywords.Baseline, VerticalAlignment.Baseline); + public static readonly ICssValue OpacityDecl = new Length(1.0, Length.Unit.None); + public static readonly ICssValue OverflowDecl = new Constant(CssKeywords.Visible, OverflowMode.Visible); + public static readonly ICssValue OutlineWidthDecl = new Constant(CssKeywords.Medium, Length.Medium); + public static readonly ICssValue OutlineStyleDecl = new Constant(CssKeywords.None, LineStyle.None); + public static readonly ICssValue OutlineColorDecl = new Constant(CssKeywords.Invert, Color.InvertedColor); + public static readonly ICssValue TextTransformDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue TextShadowDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue TextRenderingDecl = new Constant(CssKeywords.Auto, null); + public static readonly ICssValue TextOverflowDecl = new Constant(CssKeywords.Auto, OverflowMode.Clip); + public static readonly ICssValue TextOrientationDecl = new Constant(CssKeywords.Mixed, null); + public static readonly ICssValue TextJustifyDecl = new Constant(CssKeywords.Auto, TextJustify.Auto); + public static readonly ICssValue TextIndentDecl = Length.Zero; + public static readonly ICssValue TextAlignDecl = new Constant(CssKeywords.Left, HorizontalAlignment.Left); + public static readonly ICssValue TextAlignLastDecl = new Constant(CssKeywords.Auto, TextAlignLast.Auto); + public static readonly ICssValue TextDecorationLineDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue TextDecorationStyleDecl = new Constant(CssKeywords.Solid, LineStyle.Solid); + public static readonly ICssValue TextDecorationColorDecl = new Constant(CssKeywords.CurrentColor, Color.CurrentColor); + public static readonly ICssValue ListStyleTypeDecl = new Constant(CssKeywords.Disc, ListStyle.Disc); + public static readonly ICssValue ListStylePositionDecl = new Constant(CssKeywords.Outside, ListPosition.Outside); + public static readonly ICssValue ListStyleImageDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue LineBreakDecl = new Constant(CssKeywords.Auto, BreakMode.Auto); + public static readonly ICssValue GridTemplateRowsDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue GridTemplateColumnsDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue GridTemplateAreasDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue GridAutoRowsDecl = new Constant(CssKeywords.Auto, null); + public static readonly ICssValue GridAutoColumnsDecl = new Constant(CssKeywords.Auto, null); + public static readonly ICssValue GridAutoFlowDecl = new Constant(CssKeywords.Row, false); + public static readonly ICssValue GridColumnGapDecl = Length.Zero; + public static readonly ICssValue GridRowGapDecl = Length.Zero; + public static readonly ICssValue ColumnGapDecl = new Constant(CssKeywords.Normal, Length.Normal); + public static readonly ICssValue RowGapDecl = new Constant(CssKeywords.Normal, Length.Normal); + public static readonly ICssValue PerspectiveDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue PositionDecl = new Constant(CssKeywords.Inline, PositionMode.Static); + public static readonly ICssValue TransformDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue ClearModeDecl = new Constant(CssKeywords.None, ClearMode.None); + public static readonly ICssValue ClipDecl = new Constant(CssKeywords.Auto, Length.Auto); + public static readonly ICssValue ContentDecl = new Constant(CssKeywords.Normal, null); + public static readonly ICssValue CounterIncrementDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue CounterResetDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue DisplayDecl = new Constant(CssKeywords.Inline, DisplayMode.Inline); + public static readonly ICssValue BackfaceVisibilityDecl = new Constant(CssKeywords.Visible, Visibility.Visible); + public static readonly ICssValue BorderImageSourceDecl = new Constant(CssKeywords.None, null); + public static readonly ICssValue BorderImageSliceDecl = Length.Full; + public static readonly ICssValue BorderImageWidthDecl = new Length(1, Length.Unit.None); + public static readonly ICssValue BorderImageOutsetDecl = Length.Zero; + public static readonly ICssValue BorderImageRepeatDecl = new Constant(CssKeywords.Stretch, BorderRepeat.Stretch); + public static readonly ICssValue AlignSelfDecl = new Constant(CssKeywords.Auto, FlexContentMode.Auto); + public static readonly ICssValue AlignItemsDecl = new Constant(CssKeywords.Normal, null); + public static readonly ICssValue AlignContentDecl = new Constant(CssKeywords.Normal, null); + public static readonly ICssValue JustifyContentDecl = new Constant(CssKeywords.Normal, null); + public static readonly ICssValue JustifyItemsDecl = new Constant(CssKeywords.Legacy, null); + public static readonly ICssValue JustifySelfDecl = new Constant(CssKeywords.Auto, FlexContentMode.Auto); + public static readonly ICssValue ZIndexDecl = new Constant(CssKeywords.Auto, Length.Auto); } } diff --git a/src/AngleSharp.Css/Converters/AnyValueConverter.cs b/src/AngleSharp.Css/Converters/AnyValueConverter.cs index c3682870..f3309323 100644 --- a/src/AngleSharp.Css/Converters/AnyValueConverter.cs +++ b/src/AngleSharp.Css/Converters/AnyValueConverter.cs @@ -10,7 +10,7 @@ public ICssValue Convert(StringSource source) { var value = source.Content; source.Next(value.Length); - return new CssAnyValue(value); + return new AnyValue(value); } } } diff --git a/src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs b/src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs index fc012bb6..692dd140 100644 --- a/src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/BackgroundDeclaration.cs @@ -151,9 +151,7 @@ public ICssValue Merge(ICssValue[] values) public ICssValue[] Split(ICssValue value) { - var background = value as Background; - - if (background != null) + if (value is Background background) { return new[] { @@ -215,9 +213,7 @@ private static ICssValue GetValue(CssListValue container, Int32 index) private static ICssValue CreateMultiple(Background background, Func getValue) { - var layers = background.Layers as CssListValue; - - if (layers != null) + if (background.Layers is CssListValue layers) { var values = layers.Items.OfType().Select(getValue); diff --git a/src/AngleSharp.Css/Map.cs b/src/AngleSharp.Css/Map.cs index 6c8064e5..7d9cb257 100644 --- a/src/AngleSharp.Css/Map.cs +++ b/src/AngleSharp.Css/Map.cs @@ -146,7 +146,7 @@ static class Map /// /// Contains the string-TimingFunction mapping. /// - public static readonly Dictionary TimingFunctions = new Dictionary(StringComparer.OrdinalIgnoreCase) + public static readonly Dictionary TimingFunctions = new Dictionary(StringComparer.OrdinalIgnoreCase) { { CssKeywords.Ease, new CubicBezierTimingFunction(0.25, 0.1, 0.25, 1.0) }, { CssKeywords.EaseIn, new CubicBezierTimingFunction(0.42, 0.0, 1.0, 1.0) }, diff --git a/src/AngleSharp.Css/Parser/Micro/CompoundParser.cs b/src/AngleSharp.Css/Parser/Micro/CompoundParser.cs index 2a60f483..f8fa1088 100644 --- a/src/AngleSharp.Css/Parser/Micro/CompoundParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/CompoundParser.cs @@ -106,7 +106,7 @@ public static CssTupleValue ParseQuotes(this StringSource source) return null; } - public static IImageSource ParseImageSource(this StringSource source) + public static ICssImageValue ParseImageSource(this StringSource source) { var url = source.ParseUri(); diff --git a/src/AngleSharp.Css/Parser/Micro/GradientParser.cs b/src/AngleSharp.Css/Parser/Micro/GradientParser.cs index fd5b5a9a..11a2e587 100644 --- a/src/AngleSharp.Css/Parser/Micro/GradientParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/GradientParser.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Parser static class GradientParser { - private static readonly Dictionary> GradientFunctions = new Dictionary> + private static readonly Dictionary> GradientFunctions = new Dictionary> { { FunctionNames.LinearGradient, ParseLinearGradient }, { FunctionNames.RepeatingLinearGradient, ParseRepeatingLinearGradient }, @@ -16,7 +16,7 @@ static class GradientParser { FunctionNames.RepeatingRadialGradient, ParseRepeatingRadialGradient }, }; - public static IGradient ParseGradient(this StringSource source) + public static ICssGradientFunctionValue ParseGradient(this StringSource source) { var pos = source.Index; var ident = source.ParseIdent(); @@ -25,7 +25,7 @@ public static IGradient ParseGradient(this StringSource source) { if (source.Current == Symbols.RoundBracketOpen) { - var function = default(Func); + var function = default(Func); if (GradientFunctions.TryGetValue(ident, out function)) { @@ -39,12 +39,12 @@ public static IGradient ParseGradient(this StringSource source) return null; } - private static IGradient ParseLinearGradient(StringSource source) + private static ICssGradientFunctionValue ParseLinearGradient(StringSource source) { return ParseLinearGradient(source, false); } - private static IGradient ParseRepeatingLinearGradient(StringSource source) + private static ICssGradientFunctionValue ParseRepeatingLinearGradient(StringSource source) { return ParseLinearGradient(source, true); } @@ -53,7 +53,7 @@ private static IGradient ParseRepeatingLinearGradient(StringSource source) /// Parses a linear gradient. /// https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient /// - private static IGradient ParseLinearGradient(StringSource source, Boolean repeating) + private static ICssGradientFunctionValue ParseLinearGradient(StringSource source, Boolean repeating) { var start = source.Index; var angle = ParseLinearAngle(source); @@ -85,12 +85,12 @@ private static IGradient ParseLinearGradient(StringSource source, Boolean repeat return null; } - private static IGradient ParseRadialGradient(StringSource source) + private static ICssGradientFunctionValue ParseRadialGradient(StringSource source) { return ParseRadialGradient(source, false); } - private static IGradient ParseRepeatingRadialGradient(StringSource source) + private static ICssGradientFunctionValue ParseRepeatingRadialGradient(StringSource source) { return ParseRadialGradient(source, true); } @@ -99,7 +99,7 @@ private static IGradient ParseRepeatingRadialGradient(StringSource source) /// Parses a radial gradient /// https://developer.mozilla.org/en-US/docs/Web/CSS/radial-gradient /// - private static IGradient ParseRadialGradient(StringSource source, Boolean repeating) + private static ICssGradientFunctionValue ParseRadialGradient(StringSource source, Boolean repeating) { var start = source.Index; var options = ParseRadialOptions(source); diff --git a/src/AngleSharp.Css/Parser/Micro/GridParser.cs b/src/AngleSharp.Css/Parser/Micro/GridParser.cs index f0f619f7..4f84970c 100644 --- a/src/AngleSharp.Css/Parser/Micro/GridParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/GridParser.cs @@ -54,7 +54,7 @@ public static ICssValue ParseGridTemplate(this StringSource source) hasValue = true; source.SkipSpacesAndComments(); rowValues.Add(new CssTupleValue(new[] { value.Item1, value.Item3, value.Item4 })); - areaValues.Add(new StringValue(value.Item2)); + areaValues.Add(new Label(value.Item2)); } if (hasValue) diff --git a/src/AngleSharp.Css/Parser/Micro/IdentParser.cs b/src/AngleSharp.Css/Parser/Micro/IdentParser.cs index abf8da3f..de73e411 100644 --- a/src/AngleSharp.Css/Parser/Micro/IdentParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/IdentParser.cs @@ -130,7 +130,7 @@ public static ICssValue ParseFontFamily(this StringSource source) return null; } - return new StringValue(str); + return new Label(str); } public static ICssValue[] ParseFontFamilies(this StringSource source) diff --git a/src/AngleSharp.Css/Parser/Micro/TimingFunctionParser.cs b/src/AngleSharp.Css/Parser/Micro/TimingFunctionParser.cs index e485e635..54a4ce45 100644 --- a/src/AngleSharp.Css/Parser/Micro/TimingFunctionParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/TimingFunctionParser.cs @@ -7,23 +7,23 @@ namespace AngleSharp.Css.Parser static class TimingFunctionParser { - private static readonly Dictionary> TimingFunctions = new Dictionary> + private static readonly Dictionary> TimingFunctions = new Dictionary> { { FunctionNames.Steps, ParseSteps }, { FunctionNames.CubicBezier, ParseCubicBezier }, }; - public static ITimingFunction ParseTimingFunction(this StringSource source) + public static ICssTimingFunctionValue ParseTimingFunction(this StringSource source) { var pos = source.Index; - var result = default(ITimingFunction); + var result = default(ICssTimingFunctionValue); var ident = source.ParseIdent(); if (ident != null) { if (source.Current == Symbols.RoundBracketOpen) { - var function = default(Func); + var function = default(Func); if (TimingFunctions.TryGetValue(ident, out function)) { @@ -45,7 +45,7 @@ public static ITimingFunction ParseTimingFunction(this StringSource source) return result; } - private static ITimingFunction ParseSteps(StringSource source) + private static ICssTimingFunctionValue ParseSteps(StringSource source) { var intervals = source.ParseInteger(); var c = source.SkipGetSkip(); @@ -71,7 +71,7 @@ private static ITimingFunction ParseSteps(StringSource source) return null; } - private static ITimingFunction ParseCubicBezier(StringSource source) + private static ICssTimingFunctionValue ParseCubicBezier(StringSource source) { var p1 = source.ParseNumber(); var c1 = source.SkipGetSkip(); diff --git a/src/AngleSharp.Css/Parser/Micro/TransformParser.cs b/src/AngleSharp.Css/Parser/Micro/TransformParser.cs index 8fabd529..f7d689f2 100644 --- a/src/AngleSharp.Css/Parser/Micro/TransformParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/TransformParser.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Parser static class TransformParser { - private static readonly Dictionary> TransformFunctions = new Dictionary> + private static readonly Dictionary> TransformFunctions = new Dictionary> { { FunctionNames.Skew, ParseSkew2d }, { FunctionNames.SkewX, ParseSkewX }, @@ -33,7 +33,7 @@ static class TransformParser { FunctionNames.Perspective, ParsePerspective }, }; - public static ITransform ParseTransform(this StringSource source) + public static ICssTransformFunctionValue ParseTransform(this StringSource source) { var pos = source.Index; var ident = source.ParseIdent(); @@ -42,7 +42,7 @@ public static ITransform ParseTransform(this StringSource source) { if (source.Current == Symbols.RoundBracketOpen) { - var function = default(Func); + var function = default(Func); if (TransformFunctions.TryGetValue(ident, out function)) { @@ -479,7 +479,7 @@ private static TranslateTransform ParseTranslateZ(StringSource source) /// A perspective for 3D transformations. /// http://www.w3.org/TR/css3-transforms/#funcdef-perspective /// - private static ITransform ParsePerspective(StringSource source) + private static ICssTransformFunctionValue ParsePerspective(StringSource source) { var l = source.ParseLengthOrCalc(); var f = source.SkipGetSkip(); diff --git a/src/AngleSharp.Css/ValueConverters.cs b/src/AngleSharp.Css/ValueConverters.cs index 27361487..af93aca4 100644 --- a/src/AngleSharp.Css/ValueConverters.cs +++ b/src/AngleSharp.Css/ValueConverters.cs @@ -872,13 +872,13 @@ static class ValueConverters private static IValueConverter FromParser(Func converter) where T : class, ICssValue => new ClassValueConverter(converter); - private static Func FromString(Func converter) => source => + private static Func FromString(Func converter) => source => { var result = converter.Invoke(source); if (result != null) { - return new StringValue(result); + return new Label(result); } return null; diff --git a/src/AngleSharp.Css/Values/Colors.cs b/src/AngleSharp.Css/Values/Colors.cs index a4a498e1..94eea847 100644 --- a/src/AngleSharp.Css/Values/Colors.cs +++ b/src/AngleSharp.Css/Values/Colors.cs @@ -192,7 +192,7 @@ static class Colors { "threedshadow", new Color(136, 136, 136) }, { "window", new Color(255, 255, 255) }, { "windowframe", new Color(204, 204, 204) }, - { "windowtext", new Color(0, 0, 0) } + { "windowtext", new Color(0, 0, 0) }, }; #endregion @@ -215,9 +215,7 @@ static class Colors /// The color with the given name or null. public static Color? GetColor(String name) { - var color = default(Color); - - if (TheColors.TryGetValue(name, out color)) + if (TheColors.TryGetValue(name, out Color color)) { return color; } diff --git a/src/AngleSharp.Css/Values/Background.cs b/src/AngleSharp.Css/Values/Composites/Background.cs similarity index 96% rename from src/AngleSharp.Css/Values/Background.cs rename to src/AngleSharp.Css/Values/Composites/Background.cs index 78817d96..ade014d8 100644 --- a/src/AngleSharp.Css/Values/Background.cs +++ b/src/AngleSharp.Css/Values/Composites/Background.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS background definition. /// - sealed class Background : ICssValue + sealed class Background : ICssCompositeValue { private readonly ICssValue _layers; private readonly ICssValue _color; diff --git a/src/AngleSharp.Css/Values/BackgroundLayer.cs b/src/AngleSharp.Css/Values/Composites/BackgroundLayer.cs similarity index 97% rename from src/AngleSharp.Css/Values/BackgroundLayer.cs rename to src/AngleSharp.Css/Values/Composites/BackgroundLayer.cs index e71194d0..340f4143 100644 --- a/src/AngleSharp.Css/Values/BackgroundLayer.cs +++ b/src/AngleSharp.Css/Values/Composites/BackgroundLayer.cs @@ -4,7 +4,7 @@ namespace AngleSharp.Css.Values using AngleSharp.Text; using System; - struct BackgroundLayer : ICssValue + struct BackgroundLayer : ICssCompositeValue { public ICssValue Image; public Point? Position; diff --git a/src/AngleSharp.Css/Values/BorderImage.cs b/src/AngleSharp.Css/Values/Composites/BorderImage.cs similarity index 98% rename from src/AngleSharp.Css/Values/BorderImage.cs rename to src/AngleSharp.Css/Values/Composites/BorderImage.cs index eefaa3bf..96de97b8 100644 --- a/src/AngleSharp.Css/Values/BorderImage.cs +++ b/src/AngleSharp.Css/Values/Composites/BorderImage.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS border image definition. /// - struct BorderImage : ICssValue + struct BorderImage : ICssCompositeValue { #region Fields diff --git a/src/AngleSharp.Css/Values/BorderImageSlice.cs b/src/AngleSharp.Css/Values/Composites/BorderImageSlice.cs similarity index 97% rename from src/AngleSharp.Css/Values/BorderImageSlice.cs rename to src/AngleSharp.Css/Values/Composites/BorderImageSlice.cs index d6a62586..37b2b179 100644 --- a/src/AngleSharp.Css/Values/BorderImageSlice.cs +++ b/src/AngleSharp.Css/Values/Composites/BorderImageSlice.cs @@ -1,13 +1,12 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using AngleSharp.Text; using System; /// /// Represents the CSS border image slice definition. /// - struct BorderImageSlice : ICssValue + struct BorderImageSlice : ICssCompositeValue { #region Fields diff --git a/src/AngleSharp.Css/Values/BorderRadius.cs b/src/AngleSharp.Css/Values/Composites/BorderRadius.cs similarity index 97% rename from src/AngleSharp.Css/Values/BorderRadius.cs rename to src/AngleSharp.Css/Values/Composites/BorderRadius.cs index 95db1e5c..22d12c3c 100644 --- a/src/AngleSharp.Css/Values/BorderRadius.cs +++ b/src/AngleSharp.Css/Values/Composites/BorderRadius.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a border radius value. /// - class BorderRadius : ICssValue + class BorderRadius : ICssCompositeValue { #region Fields diff --git a/src/AngleSharp.Css/Values/CalcAddExpression.cs b/src/AngleSharp.Css/Values/Composites/CalcAddExpression.cs similarity index 95% rename from src/AngleSharp.Css/Values/CalcAddExpression.cs rename to src/AngleSharp.Css/Values/Composites/CalcAddExpression.cs index a696b624..906546c4 100644 --- a/src/AngleSharp.Css/Values/CalcAddExpression.cs +++ b/src/AngleSharp.Css/Values/Composites/CalcAddExpression.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a calc add expression, i.e., a + b. /// - class CalcAddExpression : ICssValue + class CalcAddExpression : ICssCompositeValue { private readonly ICssValue _left; private readonly ICssValue _right; diff --git a/src/AngleSharp.Css/Values/CalcDivExpression.cs b/src/AngleSharp.Css/Values/Composites/CalcDivExpression.cs similarity index 95% rename from src/AngleSharp.Css/Values/CalcDivExpression.cs rename to src/AngleSharp.Css/Values/Composites/CalcDivExpression.cs index 9bff853a..6f07d0a7 100644 --- a/src/AngleSharp.Css/Values/CalcDivExpression.cs +++ b/src/AngleSharp.Css/Values/Composites/CalcDivExpression.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a calc division expression, i.e., a / b. /// - class CalcDivExpression : ICssValue + class CalcDivExpression : ICssCompositeValue { private readonly ICssValue _left; private readonly ICssValue _right; diff --git a/src/AngleSharp.Css/Values/CalcMulExpression.cs b/src/AngleSharp.Css/Values/Composites/CalcMulExpression.cs similarity index 95% rename from src/AngleSharp.Css/Values/CalcMulExpression.cs rename to src/AngleSharp.Css/Values/Composites/CalcMulExpression.cs index 442b437d..4689f1b7 100644 --- a/src/AngleSharp.Css/Values/CalcMulExpression.cs +++ b/src/AngleSharp.Css/Values/Composites/CalcMulExpression.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a calc multiplication expression, i.e., a * b. /// - class CalcMulExpression : ICssValue + class CalcMulExpression : ICssCompositeValue { private readonly ICssValue _left; private readonly ICssValue _right; diff --git a/src/AngleSharp.Css/Values/CalcSubExpression.cs b/src/AngleSharp.Css/Values/Composites/CalcSubExpression.cs similarity index 95% rename from src/AngleSharp.Css/Values/CalcSubExpression.cs rename to src/AngleSharp.Css/Values/Composites/CalcSubExpression.cs index 152d2f09..a180eb86 100644 --- a/src/AngleSharp.Css/Values/CalcSubExpression.cs +++ b/src/AngleSharp.Css/Values/Composites/CalcSubExpression.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a calc subtraction expression, i.e., a - b. /// - class CalcSubExpression : ICssValue + class CalcSubExpression : ICssCompositeValue { private readonly ICssValue _left; private readonly ICssValue _right; diff --git a/src/AngleSharp.Css/Values/Cursor.cs b/src/AngleSharp.Css/Values/Composites/Cursor.cs similarity index 97% rename from src/AngleSharp.Css/Values/Cursor.cs rename to src/AngleSharp.Css/Values/Composites/Cursor.cs index 92d06925..ffebebe0 100644 --- a/src/AngleSharp.Css/Values/Cursor.cs +++ b/src/AngleSharp.Css/Values/Composites/Cursor.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS cursor definition. /// - class Cursor : ICssValue + class Cursor : ICssCompositeValue { private readonly ICssValue[] _definitions; private readonly ICssValue _cursor; diff --git a/src/AngleSharp.Css/Values/CursorDefinition.cs b/src/AngleSharp.Css/Values/Composites/CursorDefinition.cs similarity index 85% rename from src/AngleSharp.Css/Values/CursorDefinition.cs rename to src/AngleSharp.Css/Values/Composites/CursorDefinition.cs index 0ab0aad0..f519e9db 100644 --- a/src/AngleSharp.Css/Values/CursorDefinition.cs +++ b/src/AngleSharp.Css/Values/Composites/CursorDefinition.cs @@ -1,12 +1,11 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using AngleSharp.Text; using System; - struct CursorDefinition : ICssValue + struct CursorDefinition : ICssCompositeValue { - public IImageSource Source; + public ICssImageValue Source; public Point? Position; /// diff --git a/src/AngleSharp.Css/Values/FontInfo.cs b/src/AngleSharp.Css/Values/Composites/FontInfo.cs similarity index 99% rename from src/AngleSharp.Css/Values/FontInfo.cs rename to src/AngleSharp.Css/Values/Composites/FontInfo.cs index 7c9f2c9b..329fbb24 100644 --- a/src/AngleSharp.Css/Values/FontInfo.cs +++ b/src/AngleSharp.Css/Values/Composites/FontInfo.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS font definition. /// - class FontInfo : ICssValue + class FontInfo : ICssCompositeValue { #region Fields diff --git a/src/AngleSharp.Css/Values/GradientStop.cs b/src/AngleSharp.Css/Values/Composites/GradientStop.cs similarity index 97% rename from src/AngleSharp.Css/Values/GradientStop.cs rename to src/AngleSharp.Css/Values/Composites/GradientStop.cs index 1c333265..067366b4 100644 --- a/src/AngleSharp.Css/Values/GradientStop.cs +++ b/src/AngleSharp.Css/Values/Composites/GradientStop.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// More information can be found at the W3C: /// http://dev.w3.org/csswg/css-images-3/#color-stop-syntax /// - struct GradientStop : ICssValue + struct GradientStop : ICssCompositeValue { #region Fields diff --git a/src/AngleSharp.Css/Values/Grid.cs b/src/AngleSharp.Css/Values/Composites/Grid.cs similarity index 98% rename from src/AngleSharp.Css/Values/Grid.cs rename to src/AngleSharp.Css/Values/Composites/Grid.cs index ada5eef1..30f5b345 100644 --- a/src/AngleSharp.Css/Values/Grid.cs +++ b/src/AngleSharp.Css/Values/Composites/Grid.cs @@ -9,7 +9,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS grid definition. /// - class Grid : ICssValue + class Grid : ICssCompositeValue { #region Fields diff --git a/src/AngleSharp.Css/Values/GridTemplate.cs b/src/AngleSharp.Css/Values/Composites/GridTemplate.cs similarity index 97% rename from src/AngleSharp.Css/Values/GridTemplate.cs rename to src/AngleSharp.Css/Values/Composites/GridTemplate.cs index c71fa623..ce4875dc 100644 --- a/src/AngleSharp.Css/Values/GridTemplate.cs +++ b/src/AngleSharp.Css/Values/Composites/GridTemplate.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS grid template definition. /// - class GridTemplate : ICssValue + class GridTemplate : ICssCompositeValue { #region Fields @@ -94,8 +94,8 @@ public String CssText return rows; } - - #endregion } + + #endregion } } diff --git a/src/AngleSharp.Css/Values/ImageRepeats.cs b/src/AngleSharp.Css/Values/Composites/ImageRepeats.cs similarity index 97% rename from src/AngleSharp.Css/Values/ImageRepeats.cs rename to src/AngleSharp.Css/Values/Composites/ImageRepeats.cs index 9649d9bb..50b7d216 100644 --- a/src/AngleSharp.Css/Values/ImageRepeats.cs +++ b/src/AngleSharp.Css/Values/Composites/ImageRepeats.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS image repeat definition. /// - struct ImageRepeats : ICssValue + struct ImageRepeats : ICssCompositeValue { private readonly ICssValue _horizontal; private readonly ICssValue _vertical; diff --git a/src/AngleSharp.Css/Values/Point.cs b/src/AngleSharp.Css/Values/Composites/Point.cs similarity index 93% rename from src/AngleSharp.Css/Values/Point.cs rename to src/AngleSharp.Css/Values/Composites/Point.cs index 118bab34..d6aec381 100644 --- a/src/AngleSharp.Css/Values/Point.cs +++ b/src/AngleSharp.Css/Values/Composites/Point.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a point value consisting of two distances. /// - struct Point : IEquatable, ICssValue + struct Point : IEquatable, ICssCompositeValue { #region Basic values @@ -153,10 +153,7 @@ public String CssText /// The left point. /// The right point. /// True if both points are equal, otherwise false. - public static Boolean operator ==(Point a, Point b) - { - return a.Equals(b); - } + public static Boolean operator ==(Point a, Point b) => a.Equals(b); /// /// Checks the inequality of the two given points. @@ -164,20 +161,14 @@ public String CssText /// The left point. /// The right point. /// True if both points are not equal, otherwise false. - public static Boolean operator !=(Point a, Point b) - { - return !a.Equals(b); - } + public static Boolean operator !=(Point a, Point b) => !a.Equals(b); /// /// Checks if both points are actually equal. /// /// The other point to compare to. /// True if both points are equal, otherwise false. - public Boolean Equals(Point other) - { - return _x.Equals(other._x) && _y.Equals(other._y); - } + public Boolean Equals(Point other) => _x.Equals(other._x) && _y.Equals(other._y); /// /// Tests if another object is equal to this object. diff --git a/src/AngleSharp.Css/Values/Point3.cs b/src/AngleSharp.Css/Values/Composites/Point3.cs similarity index 97% rename from src/AngleSharp.Css/Values/Point3.cs rename to src/AngleSharp.Css/Values/Composites/Point3.cs index c78041c9..55ea3cb7 100644 --- a/src/AngleSharp.Css/Values/Point3.cs +++ b/src/AngleSharp.Css/Values/Composites/Point3.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS origin definition. /// - class Point3 : ICssValue + class Point3 : ICssCompositeValue { private readonly ICssValue _x; private readonly ICssValue _y; diff --git a/src/AngleSharp.Css/Values/Shadow.cs b/src/AngleSharp.Css/Values/Composites/Shadow.cs similarity index 98% rename from src/AngleSharp.Css/Values/Shadow.cs rename to src/AngleSharp.Css/Values/Composites/Shadow.cs index f4f952ec..e6168c5f 100644 --- a/src/AngleSharp.Css/Values/Shadow.cs +++ b/src/AngleSharp.Css/Values/Composites/Shadow.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// The shadow class for holding information about a box or text-shadow. /// - class Shadow : ICssValue + class Shadow : ICssCompositeValue { #region Fields diff --git a/src/AngleSharp.Css/Values/Calc.cs b/src/AngleSharp.Css/Values/Functions/Calc.cs similarity index 100% rename from src/AngleSharp.Css/Values/Calc.cs rename to src/AngleSharp.Css/Values/Functions/Calc.cs diff --git a/src/AngleSharp.Css/Values/CubicBezierTimingFunction.cs b/src/AngleSharp.Css/Values/Functions/CubicBezierTimingFunction.cs similarity index 94% rename from src/AngleSharp.Css/Values/CubicBezierTimingFunction.cs rename to src/AngleSharp.Css/Values/Functions/CubicBezierTimingFunction.cs index 1b7d0a69..1a5dd137 100644 --- a/src/AngleSharp.Css/Values/CubicBezierTimingFunction.cs +++ b/src/AngleSharp.Css/Values/Functions/CubicBezierTimingFunction.cs @@ -9,7 +9,7 @@ namespace AngleSharp.Css.Values /// Represents a cubic-bezier timing-function object. /// https://developer.mozilla.org/en-US/docs/Web/CSS/timing-function /// - class CubicBezierTimingFunction : ITimingFunction, IEquatable + class CubicBezierTimingFunction : ICssTimingFunctionValue, IEquatable { #region Fields @@ -145,10 +145,8 @@ public String CssText /// /// The cubic bezier to compare to. /// True if both have the same parameters, otherwise false. - public Boolean Equals(CubicBezierTimingFunction other) - { - return _x1 == other._x1 && _x2 == other._x2 && _y1 == other._y1 && _y2 == other._y2; - } + public Boolean Equals(CubicBezierTimingFunction other) => + _x1 == other._x1 && _x2 == other._x2 && _y1 == other._y1 && _y2 == other._y2; #endregion } diff --git a/src/AngleSharp.Css/Values/FitContent.cs b/src/AngleSharp.Css/Values/Functions/FitContent.cs similarity index 100% rename from src/AngleSharp.Css/Values/FitContent.cs rename to src/AngleSharp.Css/Values/Functions/FitContent.cs diff --git a/src/AngleSharp.Css/Values/FontFormat.cs b/src/AngleSharp.Css/Values/Functions/FontFormat.cs similarity index 85% rename from src/AngleSharp.Css/Values/FontFormat.cs rename to src/AngleSharp.Css/Values/Functions/FontFormat.cs index 1e4b8372..9be05383 100644 --- a/src/AngleSharp.Css/Values/FontFormat.cs +++ b/src/AngleSharp.Css/Values/Functions/FontFormat.cs @@ -16,7 +16,7 @@ public FontFormat(String fontFormat) public String Name => CssKeywords.Format; - public ICssValue[] Arguments => new[] { new StringValue(_fontFormat) }; + public ICssValue[] Arguments => new[] { new Label(_fontFormat) }; public String CssText => Name.CssFunction(Arguments.Join(", ")); } diff --git a/src/AngleSharp.Css/Values/LinearGradient.cs b/src/AngleSharp.Css/Values/Functions/LinearGradient.cs similarity index 98% rename from src/AngleSharp.Css/Values/LinearGradient.cs rename to src/AngleSharp.Css/Values/Functions/LinearGradient.cs index 7d5e5504..64452932 100644 --- a/src/AngleSharp.Css/Values/LinearGradient.cs +++ b/src/AngleSharp.Css/Values/Functions/LinearGradient.cs @@ -9,7 +9,7 @@ namespace AngleSharp.Css.Values /// Represents a linear gradient: /// http://dev.w3.org/csswg/css-images-3/#linear-gradients /// - class LinearGradient : IGradient, ICssFunctionValue + class LinearGradient : ICssGradientFunctionValue { #region Fields diff --git a/src/AngleSharp.Css/Values/LocalFont.cs b/src/AngleSharp.Css/Values/Functions/LocalFont.cs similarity index 85% rename from src/AngleSharp.Css/Values/LocalFont.cs rename to src/AngleSharp.Css/Values/Functions/LocalFont.cs index fbf839ec..cab89564 100644 --- a/src/AngleSharp.Css/Values/LocalFont.cs +++ b/src/AngleSharp.Css/Values/Functions/LocalFont.cs @@ -16,7 +16,7 @@ public LocalFont(String fontName) public String Name => CssKeywords.Local; - public ICssValue[] Arguments => new[] { new StringValue(_fontName) }; + public ICssValue[] Arguments => new[] { new Label(_fontName) }; public String CssText => Name.CssFunction(Arguments.Join(", ")); } diff --git a/src/AngleSharp.Css/Values/MatrixTransform.cs b/src/AngleSharp.Css/Values/Functions/MatrixTransform.cs similarity index 97% rename from src/AngleSharp.Css/Values/MatrixTransform.cs rename to src/AngleSharp.Css/Values/Functions/MatrixTransform.cs index cfe1fc19..db773382 100644 --- a/src/AngleSharp.Css/Values/MatrixTransform.cs +++ b/src/AngleSharp.Css/Values/Functions/MatrixTransform.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values /// /// Represents the matrix3d transformation. /// - class MatrixTransform : ITransform, ICssFunctionValue + class MatrixTransform : ICssTransformFunctionValue { #region Fields diff --git a/src/AngleSharp.Css/Values/MinMax.cs b/src/AngleSharp.Css/Values/Functions/MinMax.cs similarity index 100% rename from src/AngleSharp.Css/Values/MinMax.cs rename to src/AngleSharp.Css/Values/Functions/MinMax.cs diff --git a/src/AngleSharp.Css/Values/PerspectiveTransform.cs b/src/AngleSharp.Css/Values/Functions/PerspectiveTransform.cs similarity index 96% rename from src/AngleSharp.Css/Values/PerspectiveTransform.cs rename to src/AngleSharp.Css/Values/Functions/PerspectiveTransform.cs index 65543201..02e40eb3 100644 --- a/src/AngleSharp.Css/Values/PerspectiveTransform.cs +++ b/src/AngleSharp.Css/Values/Functions/PerspectiveTransform.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents the distance transformation. /// - class PerspectiveTransform : ITransform, ICssFunctionValue + class PerspectiveTransform : ICssTransformFunctionValue { #region Fields diff --git a/src/AngleSharp.Css/Values/RadialGradient.cs b/src/AngleSharp.Css/Values/Functions/RadialGradient.cs similarity index 97% rename from src/AngleSharp.Css/Values/RadialGradient.cs rename to src/AngleSharp.Css/Values/Functions/RadialGradient.cs index 17650c84..697df6af 100644 --- a/src/AngleSharp.Css/Values/RadialGradient.cs +++ b/src/AngleSharp.Css/Values/Functions/RadialGradient.cs @@ -11,7 +11,7 @@ namespace AngleSharp.Css.Values /// Represents a radial gradient: /// http://dev.w3.org/csswg/css-images-3/#radial-gradients /// - class RadialGradient : IGradient, ICssFunctionValue + class RadialGradient : ICssGradientFunctionValue { #region Fields @@ -94,7 +94,7 @@ public ICssValue[] Arguments } } - args.Add(new CssAnyValue(String.Join(" ", new[] + args.Add(new AnyValue(String.Join(" ", new[] { _circle ? CssKeywords.Circle : CssKeywords.Ellipse, size, diff --git a/src/AngleSharp.Css/Values/Repeat.cs b/src/AngleSharp.Css/Values/Functions/Repeat.cs similarity index 100% rename from src/AngleSharp.Css/Values/Repeat.cs rename to src/AngleSharp.Css/Values/Functions/Repeat.cs diff --git a/src/AngleSharp.Css/Values/RotateTransform.cs b/src/AngleSharp.Css/Values/Functions/RotateTransform.cs similarity index 98% rename from src/AngleSharp.Css/Values/RotateTransform.cs rename to src/AngleSharp.Css/Values/Functions/RotateTransform.cs index ba4d6529..ee3802b2 100644 --- a/src/AngleSharp.Css/Values/RotateTransform.cs +++ b/src/AngleSharp.Css/Values/Functions/RotateTransform.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values /// /// Represents the rotate3d transformation. /// - class RotateTransform : ITransform, ICssFunctionValue + class RotateTransform : ICssTransformFunctionValue { #region Fields diff --git a/src/AngleSharp.Css/Values/ScaleTransform.cs b/src/AngleSharp.Css/Values/Functions/ScaleTransform.cs similarity index 94% rename from src/AngleSharp.Css/Values/ScaleTransform.cs rename to src/AngleSharp.Css/Values/Functions/ScaleTransform.cs index 31e7a0e3..e700fe37 100644 --- a/src/AngleSharp.Css/Values/ScaleTransform.cs +++ b/src/AngleSharp.Css/Values/Functions/ScaleTransform.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values /// /// Represents the scale3d transformation. /// - class ScaleTransform : ITransform, ICssFunctionValue + class ScaleTransform : ICssTransformFunctionValue { #region Fields @@ -136,10 +136,8 @@ public String CssText /// Computes the matrix for the given transformation. /// /// The transformation matrix representation. - public TransformMatrix ComputeMatrix() - { - return new TransformMatrix(_sx, 0f, 0f, 0f, _sy, 0f, 0f, 0f, _sz, 0f, 0f, 0f, 0f, 0f, 0f); - } + public TransformMatrix ComputeMatrix() => + new TransformMatrix(_sx, 0f, 0f, 0f, _sy, 0f, 0f, 0f, _sz, 0f, 0f, 0f, 0f, 0f, 0f); #endregion } diff --git a/src/AngleSharp.Css/Values/Shape.cs b/src/AngleSharp.Css/Values/Functions/Shape.cs similarity index 100% rename from src/AngleSharp.Css/Values/Shape.cs rename to src/AngleSharp.Css/Values/Functions/Shape.cs diff --git a/src/AngleSharp.Css/Values/SkewTransform.cs b/src/AngleSharp.Css/Values/Functions/SkewTransform.cs similarity index 98% rename from src/AngleSharp.Css/Values/SkewTransform.cs rename to src/AngleSharp.Css/Values/Functions/SkewTransform.cs index a1d1efe8..afea9d3f 100644 --- a/src/AngleSharp.Css/Values/SkewTransform.cs +++ b/src/AngleSharp.Css/Values/Functions/SkewTransform.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents the skew transformation. /// - class SkewTransform : ITransform, ICssFunctionValue + class SkewTransform : ICssTransformFunctionValue { #region Fields diff --git a/src/AngleSharp.Css/Values/StepsTimingFunction.cs b/src/AngleSharp.Css/Values/Functions/StepsTimingFunction.cs similarity index 92% rename from src/AngleSharp.Css/Values/StepsTimingFunction.cs rename to src/AngleSharp.Css/Values/Functions/StepsTimingFunction.cs index 574248be..d4f80861 100644 --- a/src/AngleSharp.Css/Values/StepsTimingFunction.cs +++ b/src/AngleSharp.Css/Values/Functions/StepsTimingFunction.cs @@ -10,7 +10,7 @@ namespace AngleSharp.Css.Values /// Represents a steps timing-function object. /// https://developer.mozilla.org/en-US/docs/Web/CSS/timing-function /// - class StepsTimingFunction : ITimingFunction + class StepsTimingFunction : ICssTimingFunctionValue { #region Fields @@ -50,8 +50,10 @@ public ICssValue[] Arguments { get { - var args = new List(); - args.Add(new Length(_intervals, Length.Unit.None)); + var args = new List + { + new Length(_intervals, Length.Unit.None), + }; if (_start) { diff --git a/src/AngleSharp.Css/Values/TranslateTransform.cs b/src/AngleSharp.Css/Values/Functions/TranslateTransform.cs similarity index 94% rename from src/AngleSharp.Css/Values/TranslateTransform.cs rename to src/AngleSharp.Css/Values/Functions/TranslateTransform.cs index 3b4d4c2e..b646a990 100644 --- a/src/AngleSharp.Css/Values/TranslateTransform.cs +++ b/src/AngleSharp.Css/Values/Functions/TranslateTransform.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values /// /// Represents the translate3d transformation. /// - class TranslateTransform : ITransform, ICssFunctionValue + class TranslateTransform : ICssTransformFunctionValue { #region Fields @@ -69,11 +69,11 @@ public String Name /// Gets the arguments. /// public ICssValue[] Arguments => new[] - { - _x, - _y, - _z - }; + { + _x, + _y, + _z + }; /// /// Gets the CSS text representation. diff --git a/src/AngleSharp.Css/Values/UrlReference.cs b/src/AngleSharp.Css/Values/Functions/UrlReference.cs similarity index 90% rename from src/AngleSharp.Css/Values/UrlReference.cs rename to src/AngleSharp.Css/Values/Functions/UrlReference.cs index c41c648c..b72ed563 100644 --- a/src/AngleSharp.Css/Values/UrlReference.cs +++ b/src/AngleSharp.Css/Values/Functions/UrlReference.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values /// Represents an URL object. /// https://developer.mozilla.org/en-US/docs/Web/CSS/uri /// - class UrlReference : IImageSource, ICssFunctionValue + class UrlReference : ICssImageValue, ICssFunctionValue { #region Fields @@ -39,7 +39,7 @@ public UrlReference(String path) /// /// Gets the arguments. /// - public ICssValue[] Arguments => new[] { new StringValue(_path) }; + public ICssValue[] Arguments => new[] { new Label(_path) }; /// /// Gets the CSS text representation. diff --git a/src/AngleSharp.Css/Values/VarReference.cs b/src/AngleSharp.Css/Values/Functions/VarReference.cs similarity index 85% rename from src/AngleSharp.Css/Values/VarReference.cs rename to src/AngleSharp.Css/Values/Functions/VarReference.cs index 831eba29..83a486e8 100644 --- a/src/AngleSharp.Css/Values/VarReference.cs +++ b/src/AngleSharp.Css/Values/Functions/VarReference.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS var replacement. /// - class VarReference : ICssValue, ICssFunctionValue + class VarReference : ICssFunctionValue { #region Fields @@ -46,12 +46,14 @@ public ICssValue[] Arguments { get { - var list = new List(); - list.Add(new Identifier(_variableName)); + var list = new List + { + new Identifier(_variableName), + }; if (_defaultValue != null) { - list.Add(new CssAnyValue(_defaultValue)); + list.Add(new AnyValue(_defaultValue)); } return list.ToArray(); @@ -76,8 +78,10 @@ public String CssText get { var fn = FunctionNames.Var; - var args = new List(); - args.Add(_variableName); + var args = new List + { + _variableName, + }; if (!String.IsNullOrEmpty(_defaultValue)) { diff --git a/src/AngleSharp.Css/Values/ICssCompositeValue.cs b/src/AngleSharp.Css/Values/ICssCompositeValue.cs new file mode 100644 index 00000000..f7149509 --- /dev/null +++ b/src/AngleSharp.Css/Values/ICssCompositeValue.cs @@ -0,0 +1,11 @@ +namespace AngleSharp.Css.Values +{ + using AngleSharp.Css.Dom; + + /// + /// Represents a composition of CSS values. + /// + public interface ICssCompositeValue : ICssValue + { + } +} diff --git a/src/AngleSharp.Css/Values/ICssFunctionValue.cs b/src/AngleSharp.Css/Values/ICssFunctionValue.cs index 203e069f..4f784b4d 100644 --- a/src/AngleSharp.Css/Values/ICssFunctionValue.cs +++ b/src/AngleSharp.Css/Values/ICssFunctionValue.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS value using a function call. /// - interface ICssFunctionValue : ICssValue + public interface ICssFunctionValue : ICssValue { /// /// Gets the name of the function. diff --git a/src/AngleSharp.Css/Values/IGradient.cs b/src/AngleSharp.Css/Values/ICssGradientFunctionValue.cs similarity index 87% rename from src/AngleSharp.Css/Values/IGradient.cs rename to src/AngleSharp.Css/Values/ICssGradientFunctionValue.cs index 39ba7750..fa4aa866 100644 --- a/src/AngleSharp.Css/Values/IGradient.cs +++ b/src/AngleSharp.Css/Values/ICssGradientFunctionValue.cs @@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values /// /// The common interface for all CSS gradients. /// - interface IGradient : IImageSource + interface ICssGradientFunctionValue : ICssImageValue { /// /// Gets an enumeration of all stops. diff --git a/src/AngleSharp.Css/Values/IImageSource.cs b/src/AngleSharp.Css/Values/ICssImageValue.cs similarity index 73% rename from src/AngleSharp.Css/Values/IImageSource.cs rename to src/AngleSharp.Css/Values/ICssImageValue.cs index e44f1b02..d89981bc 100644 --- a/src/AngleSharp.Css/Values/IImageSource.cs +++ b/src/AngleSharp.Css/Values/ICssImageValue.cs @@ -1,12 +1,10 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; - /// /// Basic interface for all image sources /// (linear-gradient, radial-gradient, URL, solid, ...). /// - interface IImageSource : ICssValue + interface ICssImageValue : ICssFunctionValue { } } diff --git a/src/AngleSharp.Css/Values/ICssMultipleValue.cs b/src/AngleSharp.Css/Values/ICssMultipleValue.cs new file mode 100644 index 00000000..ad95fc93 --- /dev/null +++ b/src/AngleSharp.Css/Values/ICssMultipleValue.cs @@ -0,0 +1,11 @@ +namespace AngleSharp.Css.Values +{ + using AngleSharp.Css.Dom; + + /// + /// Represents a multiple CSS value holder. + /// + public interface ICssMultipleValue : ICssValue + { + } +} diff --git a/src/AngleSharp.Css/Values/ICssPrimitiveValue.cs b/src/AngleSharp.Css/Values/ICssPrimitiveValue.cs new file mode 100644 index 00000000..b2d1cb21 --- /dev/null +++ b/src/AngleSharp.Css/Values/ICssPrimitiveValue.cs @@ -0,0 +1,11 @@ +namespace AngleSharp.Css.Values +{ + using AngleSharp.Css.Dom; + + /// + /// Represents a primitive CSS value. + /// + public interface ICssPrimitiveValue : ICssValue + { + } +} diff --git a/src/AngleSharp.Css/Values/ICssRawValue.cs b/src/AngleSharp.Css/Values/ICssRawValue.cs index e4420f7f..76cd883e 100644 --- a/src/AngleSharp.Css/Values/ICssRawValue.cs +++ b/src/AngleSharp.Css/Values/ICssRawValue.cs @@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values /// /// Represents a value that needs to be evaluated at runtime. /// - interface ICssRawValue : ICssValue + public interface ICssRawValue : ICssValue { } } diff --git a/src/AngleSharp.Css/Values/ITimingFunction.cs b/src/AngleSharp.Css/Values/ICssTimingFunctionValue.cs similarity index 69% rename from src/AngleSharp.Css/Values/ITimingFunction.cs rename to src/AngleSharp.Css/Values/ICssTimingFunctionValue.cs index c536dd1d..c2520460 100644 --- a/src/AngleSharp.Css/Values/ITimingFunction.cs +++ b/src/AngleSharp.Css/Values/ICssTimingFunctionValue.cs @@ -3,7 +3,7 @@ namespace AngleSharp.Css.Values /// /// Represents a general timing function. /// - interface ITimingFunction : ICssFunctionValue + interface ICssTimingFunctionValue : ICssFunctionValue { } } diff --git a/src/AngleSharp.Css/Values/ITransform.cs b/src/AngleSharp.Css/Values/ICssTransformFunctionValue.cs similarity index 84% rename from src/AngleSharp.Css/Values/ITransform.cs rename to src/AngleSharp.Css/Values/ICssTransformFunctionValue.cs index 6966b0d1..46469a26 100644 --- a/src/AngleSharp.Css/Values/ITransform.cs +++ b/src/AngleSharp.Css/Values/ICssTransformFunctionValue.cs @@ -1,11 +1,9 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; - /// /// Functionality for computing transformation. /// - interface ITransform : ICssValue + interface ICssTransformFunctionValue : ICssFunctionValue { /// /// Computes the matrix for the given transformation. diff --git a/src/AngleSharp.Css/Values/Counters.cs b/src/AngleSharp.Css/Values/Multiples/Counters.cs similarity index 96% rename from src/AngleSharp.Css/Values/Counters.cs rename to src/AngleSharp.Css/Values/Multiples/Counters.cs index 1d0feb01..80d190af 100644 --- a/src/AngleSharp.Css/Values/Counters.cs +++ b/src/AngleSharp.Css/Values/Multiples/Counters.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents the CSS counters definition. /// - class Counters : ICssValue + class Counters : ICssMultipleValue { private readonly ICssValue[] _counters; diff --git a/src/AngleSharp.Css/Values/CssListValue.cs b/src/AngleSharp.Css/Values/Multiples/CssListValue.cs similarity index 78% rename from src/AngleSharp.Css/Values/CssListValue.cs rename to src/AngleSharp.Css/Values/Multiples/CssListValue.cs index f156cf39..6b3aeb97 100644 --- a/src/AngleSharp.Css/Values/CssListValue.cs +++ b/src/AngleSharp.Css/Values/Multiples/CssListValue.cs @@ -10,7 +10,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS value list. /// - class CssListValue : ICssValue, IEnumerable + class CssListValue : ICssMultipleValue, IEnumerable { private readonly ICssValue[] _items; @@ -33,14 +33,9 @@ public CssListValue(ICssValue[] items) /// public String CssText => _items.Join(", "); - IEnumerator IEnumerable.GetEnumerator() - { - return _items.AsEnumerable().GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => + _items.AsEnumerable().GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return _items.GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => _items.GetEnumerator(); } } diff --git a/src/AngleSharp.Css/Values/CssTupleValue.cs b/src/AngleSharp.Css/Values/Multiples/CssTupleValue.cs similarity index 84% rename from src/AngleSharp.Css/Values/CssTupleValue.cs rename to src/AngleSharp.Css/Values/Multiples/CssTupleValue.cs index b514ef13..2691d155 100644 --- a/src/AngleSharp.Css/Values/CssTupleValue.cs +++ b/src/AngleSharp.Css/Values/Multiples/CssTupleValue.cs @@ -10,7 +10,7 @@ namespace AngleSharp.Css.Values /// /// Represents a tuple of CSS values. /// - class CssTupleValue : ICssValue, IEnumerable + class CssTupleValue : ICssMultipleValue, IEnumerable { #region Fields @@ -55,15 +55,10 @@ public CssTupleValue(ICssValue[] items, String separator = null) #region Methods - IEnumerator IEnumerable.GetEnumerator() - { - return _items.AsEnumerable().GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => + _items.AsEnumerable().GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() - { - return _items.GetEnumerator(); - } + IEnumerator IEnumerable.GetEnumerator() => _items.GetEnumerator(); #endregion } diff --git a/src/AngleSharp.Css/Values/Periodic.cs b/src/AngleSharp.Css/Values/Multiples/Periodic.cs similarity index 98% rename from src/AngleSharp.Css/Values/Periodic.cs rename to src/AngleSharp.Css/Values/Multiples/Periodic.cs index 9a580093..da331eb7 100644 --- a/src/AngleSharp.Css/Values/Periodic.cs +++ b/src/AngleSharp.Css/Values/Multiples/Periodic.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a periodic CSS value. /// - class Periodic : ICssValue + class Periodic : ICssMultipleValue where T : ICssValue { #region Fields diff --git a/src/AngleSharp.Css/Values/Angle.cs b/src/AngleSharp.Css/Values/Primitives/Angle.cs similarity index 89% rename from src/AngleSharp.Css/Values/Angle.cs rename to src/AngleSharp.Css/Values/Primitives/Angle.cs index d6c77f85..5c249e00 100644 --- a/src/AngleSharp.Css/Values/Angle.cs +++ b/src/AngleSharp.Css/Values/Primitives/Angle.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values /// Represents an angle object. /// https://developer.mozilla.org/en-US/docs/Web/CSS/angle /// - struct Angle : IEquatable, IComparable, ICssValue + struct Angle : IEquatable, IComparable, ICssPrimitiveValue { #region Basic angles @@ -121,10 +121,7 @@ public String UnitString /// /// Compares the magnitude of two angles. /// - public static Boolean operator >(Angle a, Angle b) - { - return a.CompareTo(b) == 1; - } + public static Boolean operator >(Angle a, Angle b) => a.CompareTo(b) == 1; /// /// Compares the magnitude of two angles. @@ -138,20 +135,14 @@ public String UnitString /// /// Compares the magnitude of two angles. /// - public static Boolean operator <(Angle a, Angle b) - { - return a.CompareTo(b) == -1; - } + public static Boolean operator <(Angle a, Angle b) => a.CompareTo(b) == -1; /// /// Compares the current angle against the given one. /// /// The angle to compare to. /// The result of the comparison. - public Int32 CompareTo(Angle other) - { - return ToRadian().CompareTo(other.ToRadian()); - } + public Int32 CompareTo(Angle other) => ToRadian().CompareTo(other.ToRadian()); #endregion @@ -165,8 +156,7 @@ public Int32 CompareTo(Angle other) /// True if successful, otherwise false. public static Boolean TryParse(String s, out Angle result) { - var value = default(Double); - var unit = GetUnit(s.CssUnit(out value)); + var unit = GetUnit(s.CssUnit(out double value)); if (unit != Unit.None) { @@ -244,10 +234,7 @@ public Double ToTurns() /// /// The angle to compare with. /// True if both represent the same angle in rad. - public Boolean Equals(Angle other) - { - return ToRadian() == other.ToRadian(); - } + public Boolean Equals(Angle other) => ToRadian() == other.ToRadian(); #endregion @@ -287,18 +274,12 @@ public enum Unit : byte /// /// Checks for equality of two angles. /// - public static Boolean operator ==(Angle a, Angle b) - { - return a.Equals(b); - } + public static Boolean operator ==(Angle a, Angle b) => a.Equals(b); /// /// Checks for inequality of two angles. /// - public static Boolean operator !=(Angle a, Angle b) - { - return !a.Equals(b); - } + public static Boolean operator !=(Angle a, Angle b) => !a.Equals(b); /// /// Tests if another object is equal to this object. @@ -321,10 +302,7 @@ public override Boolean Equals(Object obj) /// Returns a hash code that defines the current angle. /// /// The integer value of the hashcode. - public override Int32 GetHashCode() - { - return (Int32)_value; - } + public override Int32 GetHashCode() => (Int32)_value; #endregion } diff --git a/src/AngleSharp.Css/Values/BackgroundSize.cs b/src/AngleSharp.Css/Values/Primitives/BackgroundSize.cs similarity index 92% rename from src/AngleSharp.Css/Values/BackgroundSize.cs rename to src/AngleSharp.Css/Values/Primitives/BackgroundSize.cs index 8a1c54bb..6114ad96 100644 --- a/src/AngleSharp.Css/Values/BackgroundSize.cs +++ b/src/AngleSharp.Css/Values/Primitives/BackgroundSize.cs @@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS background size definition. /// - struct BackgroundSize : IEquatable, ICssValue + struct BackgroundSize : IEquatable, ICssPrimitiveValue { #region Fields @@ -94,10 +94,8 @@ public String CssText /// /// The other background size. /// True if both are equivalent, otherwise false. - public Boolean Equals(BackgroundSize other) - { - return _mode == other._mode && _height == other._height && _width == other._width; - } + public Boolean Equals(BackgroundSize other) => + _mode == other._mode && _height == other._height && _width == other._width; #endregion diff --git a/src/AngleSharp.Css/Values/Color.cs b/src/AngleSharp.Css/Values/Primitives/Color.cs similarity index 91% rename from src/AngleSharp.Css/Values/Color.cs rename to src/AngleSharp.Css/Values/Primitives/Color.cs index f6c3658d..ec34f7ec 100644 --- a/src/AngleSharp.Css/Values/Color.cs +++ b/src/AngleSharp.Css/Values/Primitives/Color.cs @@ -1,7 +1,6 @@ namespace AngleSharp.Css.Values { using AngleSharp.Css; - using AngleSharp.Css.Dom; using AngleSharp.Text; using System; using System.Globalization; @@ -11,7 +10,7 @@ namespace AngleSharp.Css.Values /// Represents a color value. /// [StructLayout(LayoutKind.Explicit, Pack = 1, CharSet = CharSet.Unicode)] - struct Color : IEquatable, IComparable, ICssValue + struct Color : IEquatable, IComparable, ICssPrimitiveValue { #region Basic colors @@ -127,10 +126,8 @@ public Color(Byte r, Byte g, Byte b, Byte a) /// The value for blue [0,255]. /// The value for alpha [0,1]. /// The CSS color value. - public static Color FromRgba(Byte r, Byte g, Byte b, Double a) - { - return new Color(r, g, b, Normalize(a)); - } + public static Color FromRgba(Byte r, Byte g, Byte b, Double a) => + new Color(r, g, b, Normalize(a)); /// /// Returns the color from the given primitives. @@ -140,10 +137,8 @@ public static Color FromRgba(Byte r, Byte g, Byte b, Double a) /// The value for blue [0,1]. /// The value for alpha [0,1]. /// The CSS color value. - public static Color FromRgba(Double r, Double g, Double b, Double a) - { - return new Color(Normalize(r), Normalize(g), Normalize(b), Normalize(a)); - } + public static Color FromRgba(Double r, Double g, Double b, Double a) => + new Color(Normalize(r), Normalize(g), Normalize(b), Normalize(a)); /// /// Returns the gray color from the given value. @@ -151,10 +146,8 @@ public static Color FromRgba(Double r, Double g, Double b, Double a) /// The value for each component [0,255]. /// The value for alpha [0,1]. /// The CSS color value. - public static Color FromGray(Byte number, Double alpha = 1.0) - { - return new Color(number, number, number, Normalize(alpha)); - } + public static Color FromGray(Byte number, Double alpha = 1.0) => + new Color(number, number, number, Normalize(alpha)); /// /// Returns the gray color from the given value. @@ -162,20 +155,15 @@ public static Color FromGray(Byte number, Double alpha = 1.0) /// The value for each component [0,1]. /// The value for alpha [0,1]. /// The CSS color value. - public static Color FromGray(Double value, Double alpha = 1.0) - { - return FromGray(Normalize(value), alpha); - } + public static Color FromGray(Double value, Double alpha = 1.0) => + FromGray(Normalize(value), alpha); /// /// Returns the color with the given name. /// /// The name of the color. /// The CSS color value. - public static Color? FromName(String name) - { - return Colors.GetColor(name); - } + public static Color? FromName(String name) => Colors.GetColor(name); /// /// Returns the color from the given primitives without any alpha. @@ -184,10 +172,7 @@ public static Color FromGray(Double value, Double alpha = 1.0) /// The value for green [0,255]. /// The value for blue [0,255]. /// The CSS color value. - public static Color FromRgb(Byte r, Byte g, Byte b) - { - return new Color(r, g, b); - } + public static Color FromRgb(Byte r, Byte g, Byte b) => new Color(r, g, b); /// /// Returns the color from the given hex string. @@ -303,10 +288,7 @@ public static Color FromFlexHex(String color) /// The saturation [0,1]. /// The light value [0,1]. /// The CSS color. - public static Color FromHsl(Double h, Double s, Double l) - { - return FromHsla(h, s, l, 1.0); - } + public static Color FromHsl(Double h, Double s, Double l) => FromHsla(h, s, l, 1.0); /// /// Returns the color that represents the given HSL values. @@ -461,10 +443,7 @@ public String CssText /// The first color to use. /// The second color to use. /// True if both colors are equal, otherwise false. - public static Boolean operator ==(Color a, Color b) - { - return a._hashcode == b._hashcode; - } + public static Boolean operator ==(Color a, Color b) => a._hashcode == b._hashcode; /// /// Compares two colors and returns a boolean indicating if the two do not match. @@ -472,20 +451,14 @@ public String CssText /// The first color to use. /// The second color to use. /// True if both colors are not equal, otherwise false. - public static Boolean operator !=(Color a, Color b) - { - return a._hashcode != b._hashcode; - } + public static Boolean operator !=(Color a, Color b) => a._hashcode != b._hashcode; /// /// Checks two colors for equality. /// /// The other color. /// True if both colors or equal, otherwise false. - public Boolean Equals(Color other) - { - return this._hashcode == other._hashcode; - } + public Boolean Equals(Color other) => _hashcode == other._hashcode; /// /// Tests if another object is equal to this object. @@ -504,19 +477,13 @@ public override Boolean Equals(Object obj) return false; } - Int32 IComparable.CompareTo(Color other) - { - return _hashcode - other._hashcode; - } + Int32 IComparable.CompareTo(Color other) => _hashcode - other._hashcode; /// /// Returns a hash code that defines the current color. /// /// The integer value of the hashcode. - public override Int32 GetHashCode() - { - return _hashcode; - } + public override Int32 GetHashCode() => _hashcode; #endregion @@ -529,10 +496,7 @@ public override Int32 GetHashCode() /// The first color (above) with transparency. /// The second color (below the first one) without transparency. /// The outcome in the crossing section. - public static Color Mix(Color above, Color below) - { - return Mix(above.Alpha, above, below); - } + public static Color Mix(Color above, Color below) => Mix(above.Alpha, above, below); /// /// Mixes two colors using alpha compositing as described here: @@ -555,10 +519,8 @@ public static Color Mix(Double alpha, Color above, Color below) #region Helpers - private static Byte Normalize(Double value) - { - return (Byte)Math.Max(Math.Min(Math.Truncate(256.0 * value), 255.0), 0.0); - } + private static Byte Normalize(Double value) => + (Byte)Math.Max(Math.Min(Math.Truncate(256.0 * value), 255.0), 0.0); private static Double HueToRgb(Double m1, Double m2, Double h) { diff --git a/src/AngleSharp.Css/Values/Constant.cs b/src/AngleSharp.Css/Values/Primitives/Constant.cs similarity index 93% rename from src/AngleSharp.Css/Values/Constant.cs rename to src/AngleSharp.Css/Values/Primitives/Constant.cs index 8da93d96..0139e489 100644 --- a/src/AngleSharp.Css/Values/Constant.cs +++ b/src/AngleSharp.Css/Values/Primitives/Constant.cs @@ -1,12 +1,11 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using System; /// /// Represents a selected CSS enum value. /// - class Constant : ICssValue + class Constant : ICssPrimitiveValue { #region Fields diff --git a/src/AngleSharp.Css/Values/CounterDefinition.cs b/src/AngleSharp.Css/Values/Primitives/CounterDefinition.cs similarity index 95% rename from src/AngleSharp.Css/Values/CounterDefinition.cs rename to src/AngleSharp.Css/Values/Primitives/CounterDefinition.cs index e1cd61e9..46eda791 100644 --- a/src/AngleSharp.Css/Values/CounterDefinition.cs +++ b/src/AngleSharp.Css/Values/Primitives/CounterDefinition.cs @@ -1,12 +1,11 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using System; /// /// Represents a CSS counter. /// - struct CounterDefinition : ICssValue + struct CounterDefinition : ICssPrimitiveValue { #region Fields diff --git a/src/AngleSharp.Css/Values/CounterValue.cs b/src/AngleSharp.Css/Values/Primitives/CounterValue.cs similarity index 94% rename from src/AngleSharp.Css/Values/CounterValue.cs rename to src/AngleSharp.Css/Values/Primitives/CounterValue.cs index fdebff3f..83a3964a 100644 --- a/src/AngleSharp.Css/Values/CounterValue.cs +++ b/src/AngleSharp.Css/Values/Primitives/CounterValue.cs @@ -1,12 +1,11 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using System; /// /// Sets a CSS counter. /// - struct CounterValue : ICssValue + struct CounterValue : ICssPrimitiveValue { #region Fields diff --git a/src/AngleSharp.Css/Values/Fraction.cs b/src/AngleSharp.Css/Values/Primitives/Fraction.cs similarity index 88% rename from src/AngleSharp.Css/Values/Fraction.cs rename to src/AngleSharp.Css/Values/Primitives/Fraction.cs index c52d0dd2..7ee67d30 100644 --- a/src/AngleSharp.Css/Values/Fraction.cs +++ b/src/AngleSharp.Css/Values/Primitives/Fraction.cs @@ -1,13 +1,12 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using System; using System.Globalization; /// /// Represents a fractional value. /// - struct Fraction : IEquatable, IComparable, ICssValue + struct Fraction : IEquatable, IComparable, ICssPrimitiveValue { #region Fields @@ -78,8 +77,7 @@ public String UnitString /// True if successful, otherwise false. public static Boolean TryParse(String s, out Fraction result) { - var value = default(Double); - var unit = GetUnit(s.CssUnit(out value)); + var unit = GetUnit(s.CssUnit(out double value)); if (unit != Unit.None) { @@ -110,20 +108,14 @@ public static Unit GetUnit(String s) /// /// The unit to convert to. /// The value in the given unit. - public Double To(Unit unit) - { - return _value; - } + public Double To(Unit unit) => _value; /// /// Checks if the current resolution equals the given one. /// /// The given resolution to check for equality. /// True if both are equal, otherwise false. - public Boolean Equals(Fraction other) - { - return _value == other._value && _unit == other._unit; - } + public Boolean Equals(Fraction other) => _value == other._value && _unit == other._unit; #endregion @@ -153,10 +145,7 @@ public enum Unit : byte /// /// The fraction to compare to. /// The result of the comparison. - public Int32 CompareTo(Fraction other) - { - return _value.CompareTo(other._value); - } + public Int32 CompareTo(Fraction other) => _value.CompareTo(other._value); /// /// Tests if another object is equal to this object. @@ -179,10 +168,7 @@ public override Boolean Equals(Object obj) /// Returns a hash code that defines the current fraction. /// /// The integer value of the hashcode. - public override Int32 GetHashCode() - { - return _value.GetHashCode(); - } + public override Int32 GetHashCode() => _value.GetHashCode(); #endregion } diff --git a/src/AngleSharp.Css/Values/Frequency.cs b/src/AngleSharp.Css/Values/Primitives/Frequency.cs similarity index 87% rename from src/AngleSharp.Css/Values/Frequency.cs rename to src/AngleSharp.Css/Values/Primitives/Frequency.cs index aacce6fc..e37c4cb2 100644 --- a/src/AngleSharp.Css/Values/Frequency.cs +++ b/src/AngleSharp.Css/Values/Primitives/Frequency.cs @@ -1,13 +1,12 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using System; using System.Globalization; /// /// Represents a time value. /// - struct Frequency : IEquatable, IComparable, ICssValue + struct Frequency : IEquatable, IComparable, ICssPrimitiveValue { #region Fields @@ -85,10 +84,7 @@ public String UnitString /// /// Compares the magnitude of two frequencies. /// - public static Boolean operator >(Frequency a, Frequency b) - { - return a.CompareTo(b) == 1; - } + public static Boolean operator >(Frequency a, Frequency b) => a.CompareTo(b) == 1; /// /// Compares the magnitude of two frequencies. @@ -102,20 +98,14 @@ public String UnitString /// /// Compares the magnitude of two frequencies. /// - public static Boolean operator <(Frequency a, Frequency b) - { - return a.CompareTo(b) == -1; - } + public static Boolean operator <(Frequency a, Frequency b) => a.CompareTo(b) == -1; /// /// Compares the current frequency against the given one. /// /// The frequency to compare to. /// The result of the comparison. - public Int32 CompareTo(Frequency other) - { - return ToHertz().CompareTo(other.ToHertz()); - } + public Int32 CompareTo(Frequency other) => ToHertz().CompareTo(other.ToHertz()); #endregion @@ -129,8 +119,7 @@ public Int32 CompareTo(Frequency other) /// True if successful, otherwise false. public static Boolean TryParse(String s, out Frequency result) { - var value = default(Double); - var unit = GetUnit(s.CssUnit(out value)); + var unit = GetUnit(s.CssUnit(out double value)); if (unit != Unit.None) { @@ -161,20 +150,14 @@ public static Unit GetUnit(String s) /// Converts the value to Hz. /// /// The value in Hz. - public Double ToHertz() - { - return _unit == Unit.Khz ? _value * 1000.0 : _value; - } + public Double ToHertz() => _unit == Unit.Khz ? _value * 1000.0 : _value; /// /// Checks for equality with the other frequency. /// /// The frequency to compare to. /// True if both frequencies are equal, otherwise false. - public Boolean Equals(Frequency other) - { - return _value == other._value && _unit == other._unit; - } + public Boolean Equals(Frequency other) => _value == other._value && _unit == other._unit; #endregion @@ -206,18 +189,12 @@ public enum Unit : byte /// /// Checks for equality of two frequencies. /// - public static Boolean operator ==(Frequency a, Frequency b) - { - return a.Equals(b); - } + public static Boolean operator ==(Frequency a, Frequency b) => a.Equals(b); /// /// Checks for inequality of two frequencies. /// - public static Boolean operator !=(Frequency a, Frequency b) - { - return !a.Equals(b); - } + public static Boolean operator !=(Frequency a, Frequency b) => !a.Equals(b); /// /// Tests if another object is equal to this object. @@ -240,10 +217,7 @@ public override Boolean Equals(Object obj) /// Returns a hash code that defines the current frequency. /// /// The integer value of the hashcode. - public override Int32 GetHashCode() - { - return _value.GetHashCode(); - } + public override Int32 GetHashCode() => _value.GetHashCode(); #endregion } diff --git a/src/AngleSharp.Css/Values/Identifier.cs b/src/AngleSharp.Css/Values/Primitives/Identifier.cs similarity index 91% rename from src/AngleSharp.Css/Values/Identifier.cs rename to src/AngleSharp.Css/Values/Primitives/Identifier.cs index 9e25bf84..db5aef6d 100644 --- a/src/AngleSharp.Css/Values/Identifier.cs +++ b/src/AngleSharp.Css/Values/Primitives/Identifier.cs @@ -1,12 +1,11 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using System; /// /// Represents a CSS identifier value. /// - struct Identifier : ICssValue + struct Identifier : ICssPrimitiveValue { #region Fields diff --git a/src/AngleSharp.Css/Values/StringValue.cs b/src/AngleSharp.Css/Values/Primitives/Label.cs similarity index 75% rename from src/AngleSharp.Css/Values/StringValue.cs rename to src/AngleSharp.Css/Values/Primitives/Label.cs index f82c2f7c..9d6f109f 100644 --- a/src/AngleSharp.Css/Values/StringValue.cs +++ b/src/AngleSharp.Css/Values/Primitives/Label.cs @@ -1,13 +1,12 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using AngleSharp.Text; using System; /// - /// Represents a CSS string value. + /// Represents a CSS label ("string") value. /// - class StringValue : ICssValue + class Label : ICssPrimitiveValue { #region Fields @@ -18,10 +17,10 @@ class StringValue : ICssValue #region ctor /// - /// Creates a new CSS string value. + /// Creates a new CSS label value. /// /// The string to represent. - public StringValue(String value) + public Label(String value) { _value = value; } @@ -31,7 +30,7 @@ public StringValue(String value) #region Properties /// - /// Gets the string value. + /// Gets the label value. /// public String Value => _value; diff --git a/src/AngleSharp.Css/Values/Length.cs b/src/AngleSharp.Css/Values/Primitives/Length.cs similarity index 94% rename from src/AngleSharp.Css/Values/Length.cs rename to src/AngleSharp.Css/Values/Primitives/Length.cs index 699f34b1..87a647b8 100644 --- a/src/AngleSharp.Css/Values/Length.cs +++ b/src/AngleSharp.Css/Values/Primitives/Length.cs @@ -1,13 +1,12 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using System; using System.Globalization; /// /// Represents an absolute length value. /// - struct Length : IEquatable, IComparable, ICssValue + struct Length : IEquatable, IComparable, ICssPrimitiveValue { #region Basic lengths @@ -173,10 +172,7 @@ public String UnitString /// /// Compares the magnitude of two lengths. /// - public static Boolean operator >(Length a, Length b) - { - return a.CompareTo(b) == 1; - } + public static Boolean operator >(Length a, Length b) => a.CompareTo(b) == 1; /// /// Compares the magnitude of two lengths. @@ -190,10 +186,7 @@ public String UnitString /// /// Compares the magnitude of two lengths. /// - public static Boolean operator <(Length a, Length b) - { - return a.CompareTo(b) == -1; - } + public static Boolean operator <(Length a, Length b) => a.CompareTo(b) == -1; /// /// Compares the current length against the given one. @@ -229,8 +222,7 @@ public Int32 CompareTo(Length other) /// True if successful, otherwise false. public static Boolean TryParse(String s, out Length result) { - var value = default(Double); - var unitString = s.CssUnit(out value); + var unitString = s.CssUnit(out double value); var unit = GetUnit(unitString); if (unit != Unit.None) @@ -421,10 +413,7 @@ public enum Unit : byte /// The left length. /// The right length. /// True if both lengths are equal, otherwise false. - public static Boolean operator ==(Length a, Length b) - { - return a.Equals(b); - } + public static Boolean operator ==(Length a, Length b) => a.Equals(b); /// /// Checks the inequality of the two given lengths. @@ -432,21 +421,16 @@ public enum Unit : byte /// The left length. /// The right length. /// True if both lengths are not equal, otherwise false. - public static Boolean operator !=(Length a, Length b) - { - return !a.Equals(b); - } + public static Boolean operator !=(Length a, Length b) => !a.Equals(b); /// /// Checks if both lengths are actually equal. /// /// The other length to compare to. /// True if both lengths are equal, otherwise false. - public Boolean Equals(Length other) - { - return (_value == other._value || (Double.IsNaN(_value) && Double.IsNaN(other._value))) && - (_value == 0.0 || _unit == other._unit); - } + public Boolean Equals(Length other) => + (_value == other._value || (Double.IsNaN(_value) && Double.IsNaN(other._value))) && + (_value == 0.0 || _unit == other._unit); /// /// Tests if another object is equal to this object. @@ -469,10 +453,7 @@ public override Boolean Equals(Object obj) /// Returns a hash code that defines the current length. /// /// The integer value of the hashcode. - public override Int32 GetHashCode() - { - return _value.GetHashCode(); - } + public override Int32 GetHashCode() => _value.GetHashCode(); #endregion } diff --git a/src/AngleSharp.Css/Values/LineNames.cs b/src/AngleSharp.Css/Values/Primitives/LineNames.cs similarity index 95% rename from src/AngleSharp.Css/Values/LineNames.cs rename to src/AngleSharp.Css/Values/Primitives/LineNames.cs index 51b58432..86956c80 100644 --- a/src/AngleSharp.Css/Values/LineNames.cs +++ b/src/AngleSharp.Css/Values/Primitives/LineNames.cs @@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values /// /// Represents a CSS line names definition. /// - class LineNames : ICssValue + class LineNames : ICssPrimitiveValue { private readonly String[] _names; diff --git a/src/AngleSharp.Css/Values/Quote.cs b/src/AngleSharp.Css/Values/Primitives/Quote.cs similarity index 95% rename from src/AngleSharp.Css/Values/Quote.cs rename to src/AngleSharp.Css/Values/Primitives/Quote.cs index b2c04e2a..f1ec4968 100644 --- a/src/AngleSharp.Css/Values/Quote.cs +++ b/src/AngleSharp.Css/Values/Primitives/Quote.cs @@ -1,13 +1,12 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using AngleSharp.Text; using System; /// /// Represents a CSS quote. /// - struct Quote : ICssValue + struct Quote : ICssPrimitiveValue { #region Fields diff --git a/src/AngleSharp.Css/Values/Resolution.cs b/src/AngleSharp.Css/Values/Primitives/Resolution.cs similarity index 91% rename from src/AngleSharp.Css/Values/Resolution.cs rename to src/AngleSharp.Css/Values/Primitives/Resolution.cs index 2b906fbe..d8093e52 100644 --- a/src/AngleSharp.Css/Values/Resolution.cs +++ b/src/AngleSharp.Css/Values/Primitives/Resolution.cs @@ -1,13 +1,12 @@ namespace AngleSharp.Css.Values { - using AngleSharp.Css.Dom; using System; using System.Globalization; /// /// Represents a resolution value. /// - struct Resolution : IEquatable, IComparable, ICssValue + struct Resolution : IEquatable, IComparable, ICssPrimitiveValue { #region Fields @@ -84,8 +83,7 @@ public String UnitString /// True if successful, otherwise false. public static Boolean TryParse(String s, out Resolution result) { - var value = default(Double); - var unit = GetUnit(s.CssUnit(out value)); + var unit = GetUnit(s.CssUnit(out double value)); if (unit != Unit.None) { @@ -157,10 +155,7 @@ public Double To(Unit unit) /// /// The given resolution to check for equality. /// True if both are equal, otherwise false. - public Boolean Equals(Resolution other) - { - return _value == other._value && _unit == other._unit; - } + public Boolean Equals(Resolution other) => _value == other._value && _unit == other._unit; #endregion @@ -198,10 +193,7 @@ public enum Unit : byte /// /// The resolution to compare to. /// The result of the comparison. - public Int32 CompareTo(Resolution other) - { - return ToDotsPerPixel().CompareTo(other.ToDotsPerPixel()); - } + public Int32 CompareTo(Resolution other) => ToDotsPerPixel().CompareTo(other.ToDotsPerPixel()); /// /// Tests if another object is equal to this object. @@ -224,10 +216,7 @@ public override Boolean Equals(Object obj) /// Returns a hash code that defines the current resolution. /// /// The integer value of the hashcode. - public override Int32 GetHashCode() - { - return _value.GetHashCode(); - } + public override Int32 GetHashCode() => _value.GetHashCode(); #endregion } diff --git a/src/AngleSharp.Css/Values/Time.cs b/src/AngleSharp.Css/Values/Primitives/Time.cs similarity index 84% rename from src/AngleSharp.Css/Values/Time.cs rename to src/AngleSharp.Css/Values/Primitives/Time.cs index ca396c45..4f13c5ac 100644 --- a/src/AngleSharp.Css/Values/Time.cs +++ b/src/AngleSharp.Css/Values/Primitives/Time.cs @@ -7,7 +7,7 @@ namespace AngleSharp.Css.Values /// /// Represents a time value. /// - struct Time : IEquatable /// The serialized value representation.. - public CssAnyValue(String text) + public AnyValue(String text) { _text = text; } diff --git a/src/AngleSharp.Css/Values/Default.cs b/src/AngleSharp.Css/Values/Raws/Default.cs similarity index 100% rename from src/AngleSharp.Css/Values/Default.cs rename to src/AngleSharp.Css/Values/Raws/Default.cs diff --git a/src/AngleSharp.Css/Values/Inherit.cs b/src/AngleSharp.Css/Values/Raws/Inherit.cs similarity index 100% rename from src/AngleSharp.Css/Values/Inherit.cs rename to src/AngleSharp.Css/Values/Raws/Inherit.cs diff --git a/src/AngleSharp.Css/Values/Initial.cs b/src/AngleSharp.Css/Values/Raws/Initial.cs similarity index 100% rename from src/AngleSharp.Css/Values/Initial.cs rename to src/AngleSharp.Css/Values/Raws/Initial.cs diff --git a/src/AngleSharp.Css/Values/Unset.cs b/src/AngleSharp.Css/Values/Raws/Unset.cs similarity index 100% rename from src/AngleSharp.Css/Values/Unset.cs rename to src/AngleSharp.Css/Values/Raws/Unset.cs diff --git a/src/AngleSharp.Css/Values/VarReferences.cs b/src/AngleSharp.Css/Values/Raws/VarReferences.cs similarity index 100% rename from src/AngleSharp.Css/Values/VarReferences.cs rename to src/AngleSharp.Css/Values/Raws/VarReferences.cs diff --git a/src/AngleSharp.Css/Values/TransformMatrix.cs b/src/AngleSharp.Css/Values/TransformMatrix.cs index 30ef20c8..de9e1b21 100644 --- a/src/AngleSharp.Css/Values/TransformMatrix.cs +++ b/src/AngleSharp.Css/Values/TransformMatrix.cs @@ -174,7 +174,7 @@ public TransformMatrix( /// True if all elements are equal, otherwise false. public Boolean Equals(TransformMatrix other) { - var A = this._matrix; + var A = _matrix; var B = other._matrix; for (var i = 0; i < 4; i++) @@ -200,11 +200,7 @@ public Boolean Equals(TransformMatrix other) /// /// The object to test with. /// True if the two objects are equal, otherwise false. - public override Boolean Equals(Object obj) - { - var other = obj as TransformMatrix; - return other != null ? Equals(other) : false; - } + public override Boolean Equals(Object obj) => obj is TransformMatrix other ? Equals(other) : false; /// /// Returns a hash code that defines the current length. From 54ac3a827668be5ec1edbccbff7df6b67b82d37d Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Sun, 5 May 2019 23:49:48 +0200 Subject: [PATCH 19/49] Fixed stroke-width without unit #18 --- CHANGELOG.md | 1 + .../Declarations/CssStrokeProperty.cs | 14 +++++++++++++- .../Declarations/StrokeWidthDeclaration.cs | 6 ++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba47e5de..feeb0cf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Released on Thursday, May 5 2019. - Fixed empty value when removing properties (#14) - Returns `null` in `GetStyle` if CSS not configured (#15) - Added `pointer-events` and fixed border recombination (#16) +- Fixed `stroke-width` value without unit (#18) - Fixed exception when not providing an `IRenderDevice` (#20) - Fixed missing `CssStylingService.Default` in cascade (#21) - Added extension helper `SetStyle` to modify all styles of many elements (#22) diff --git a/src/AngleSharp.Css.Tests/Declarations/CssStrokeProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssStrokeProperty.cs index 30b94588..2921d788 100644 --- a/src/AngleSharp.Css.Tests/Declarations/CssStrokeProperty.cs +++ b/src/AngleSharp.Css.Tests/Declarations/CssStrokeProperty.cs @@ -1,4 +1,4 @@ -namespace AngleSharp.Css.Tests.Declarations +namespace AngleSharp.Css.Tests.Declarations { using NUnit.Framework; using static CssConstructionFunctions; @@ -370,5 +370,17 @@ public void CssStrokeWidthNoneIllegal() Assert.IsFalse(property.IsInherited); Assert.IsFalse(property.HasValue); } + + [Test] + public void CssStrokeWithoutUnit_Issue18() + { + var snippet = "stroke-width: 3"; + var property = ParseDeclaration(snippet); + Assert.AreEqual("stroke-width", property.Name); + Assert.IsFalse(property.IsImportant); + Assert.IsFalse(property.IsInherited); + Assert.IsTrue(property.HasValue); + Assert.AreEqual("3", property.Value); + } } } diff --git a/src/AngleSharp.Css/Declarations/StrokeWidthDeclaration.cs b/src/AngleSharp.Css/Declarations/StrokeWidthDeclaration.cs index cfe20827..f34d48eb 100644 --- a/src/AngleSharp.Css/Declarations/StrokeWidthDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/StrokeWidthDeclaration.cs @@ -7,8 +7,10 @@ static class StrokeWidthDeclaration { public static String Name = PropertyNames.StrokeWidth; - public static IValueConverter Converter = LengthOrPercentConverter; + public static IValueConverter Converter = Or( + LengthOrPercentConverter, + NumberConverter); - public static PropertyFlags Flags = PropertyFlags.Animatable; + public static PropertyFlags Flags = PropertyFlags.Unitless | PropertyFlags.Animatable; } } From 85d51ae2f56837bbd0eef3f0a6ca1c8983ea762c Mon Sep 17 00:00:00 2001 From: Florian Rappl Date: Mon, 6 May 2019 00:30:24 +0200 Subject: [PATCH 20/49] Prepare value model with primitives as struct --- .../Converters/IdentifierValueConverter.cs | 7 ++- .../Declarations/BorderImageDeclaration.cs | 23 ++++---- .../Declarations/ContentDeclaration.cs | 4 +- .../Declarations/FontDeclaration.cs | 11 ++-- src/AngleSharp.Css/Parser/Micro/GridParser.cs | 4 +- .../Parser/Micro/IdentParser.cs | 14 +++-- src/AngleSharp.Css/ValueConverters.cs | 6 +-- .../Values/Functions/FontFormat.cs | 2 +- .../Values/Functions/LocalFont.cs | 2 +- .../Values/Functions/UrlReference.cs | 2 +- .../Values/ICssMultipleValue.cs | 15 +++++- .../Values/Multiples/Counters.cs | 45 ++++++++++------ .../Values/Multiples/CssListValue.cs | 34 +++++++----- .../Values/Multiples/CssTupleValue.cs | 22 +++----- .../Values/Multiples/Periodic.cs | 54 ++++++++++++------- .../Values/Primitives/Constant.cs | 2 +- .../Values/Primitives/Identifier.cs | 5 ++ src/AngleSharp.Css/Values/Primitives/Label.cs | 2 +- .../Values/Primitives/LineNames.cs | 3 +- 19 files changed, 153 insertions(+), 104 deletions(-) diff --git a/src/AngleSharp.Css/Converters/IdentifierValueConverter.cs b/src/AngleSharp.Css/Converters/IdentifierValueConverter.cs index b6b087a9..72b3f537 100644 --- a/src/AngleSharp.Css/Converters/IdentifierValueConverter.cs +++ b/src/AngleSharp.Css/Converters/IdentifierValueConverter.cs @@ -41,7 +41,12 @@ public IdentifierValueConverter(String identifier, T result) public ICssValue Convert(StringSource source) { - return source.IsIdentifier(_identifier) ? new Constant(_identifier, _result) : null; + if (source.IsIdentifier(_identifier)) + { + return new Constant(_identifier, _result); + } + + return null; } } } diff --git a/src/AngleSharp.Css/Declarations/BorderImageDeclaration.cs b/src/AngleSharp.Css/Declarations/BorderImageDeclaration.cs index fb2a1312..93c69b62 100644 --- a/src/AngleSharp.Css/Declarations/BorderImageDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/BorderImageDeclaration.cs @@ -137,7 +137,7 @@ public ICssValue[] Split(ICssValue value) if (img.HasValue) { - return new[] + return new ICssValue[] { img.Value.Outsets, img.Value.Repeat, @@ -146,21 +146,16 @@ public ICssValue[] Split(ICssValue value) img.Value.Widths, }; } - else + else if (value is Constant constant) { - var constant = value as Constant; - - if (constant != null) + return new ICssValue[] { - return new[] - { - null, - null, - null, - constant, - null, - }; - } + null, + null, + null, + constant, + null, + }; } return null; diff --git a/src/AngleSharp.Css/Declarations/ContentDeclaration.cs b/src/AngleSharp.Css/Declarations/ContentDeclaration.cs index e08ab7b3..62d32282 100644 --- a/src/AngleSharp.Css/Declarations/ContentDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/ContentDeclaration.cs @@ -84,9 +84,9 @@ public ICssValue Convert(StringSource source) var m = source.ParseStatic(ContentModes); - if (m != null) + if (m.HasValue) { - ms.Add(m); + ms.Add(m.Value); source.SkipSpacesAndComments(); continue; } diff --git a/src/AngleSharp.Css/Declarations/FontDeclaration.cs b/src/AngleSharp.Css/Declarations/FontDeclaration.cs index f1cef230..ac9dc761 100644 --- a/src/AngleSharp.Css/Declarations/FontDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/FontDeclaration.cs @@ -129,21 +129,18 @@ public ICssValue Merge(ICssValue[] values) public ICssValue[] Split(ICssValue value) { - var font = value as FontInfo; - - if (font == null) + if (!(value is FontInfo font)) { - var systemFont = value as Constant; - if (systemFont == null) + if (!(value is Constant systemFont)) { return null; } - return new[] { systemFont, null, null, null, null, null, null }; + return new ICssValue[] { systemFont, null, null, null, null, null, null }; } - return new[] { font.FontFamilies, font.Size, font.Variant, font.Weight, font.Stretch, font.Style, font.LineHeight }; + return new ICssValue[] { font.FontFamilies, font.Size, font.Variant, font.Weight, font.Stretch, font.Style, font.LineHeight }; } } } diff --git a/src/AngleSharp.Css/Parser/Micro/GridParser.cs b/src/AngleSharp.Css/Parser/Micro/GridParser.cs index 4f84970c..5d98bd43 100644 --- a/src/AngleSharp.Css/Parser/Micro/GridParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/GridParser.cs @@ -81,7 +81,7 @@ public static ICssValue ParseGridTemplate(this StringSource source) return null; } - private static Tuple ParseGridTemplateAlternative(this StringSource source) + private static Tuple ParseGridTemplateAlternative(this StringSource source) { var namesHead = source.ParseLineNames(); source.SkipSpacesAndComments(); @@ -100,7 +100,7 @@ private static Tuple ParseGridTemplateA return null; } - public static LineNames ParseLineNames(this StringSource source) + public static LineNames? ParseLineNames(this StringSource source) { var pos = source.Index; diff --git a/src/AngleSharp.Css/Parser/Micro/IdentParser.cs b/src/AngleSharp.Css/Parser/Micro/IdentParser.cs index de73e411..44a00f81 100644 --- a/src/AngleSharp.Css/Parser/Micro/IdentParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/IdentParser.cs @@ -41,9 +41,8 @@ public static ICssValue ParseConstant(this StringSource source, IDictionary(ident.ToLowerInvariant(), mode); } @@ -52,11 +51,16 @@ public static ICssValue ParseConstant(this StringSource source, IDictionary ParseStatic(this StringSource source, IDictionary values) + public static Constant? ParseStatic(this StringSource source, IDictionary values) { var ident = source.ParseIdent(); - var mode = default(T); - return ident != null && values.TryGetValue(ident, out mode) ? new Constant(ident.ToLowerInvariant(), mode) : null; + + if (ident != null && values.TryGetValue(ident, out T mode)) + { + return new Constant(ident.ToLowerInvariant(), mode); + } + + return null; } public static Boolean IsFunction(this StringSource source, String name) diff --git a/src/AngleSharp.Css/ValueConverters.cs b/src/AngleSharp.Css/ValueConverters.cs index af93aca4..fb111849 100644 --- a/src/AngleSharp.Css/ValueConverters.cs +++ b/src/AngleSharp.Css/ValueConverters.cs @@ -108,7 +108,7 @@ static class ValueConverters /// /// Represents a string object. /// - public static readonly IValueConverter StringConverter = FromParser(FromString(StringParser.ParseString)); + public static readonly IValueConverter StringConverter = new StructValueConverter