From 1609dc7d0a5665c73a2ba64461f87e02cc059bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sat, 12 Nov 2022 15:47:52 +0100 Subject: [PATCH 1/4] CSS hex color support with alpha Closes: #4304 --- .../editor/module/main/ColorsModuleTest.java | 6 ++++ .../css/lib/api/properties/TokenAcceptor.java | 33 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/ColorsModuleTest.java b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/ColorsModuleTest.java index 2d611e922b73..387d04238b15 100644 --- a/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/ColorsModuleTest.java +++ b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/ColorsModuleTest.java @@ -63,7 +63,13 @@ public void testHashValues() { PropertyDefinition p = Properties.getPropertyDefinition( "color"); assertTrue(new ResolvedProperty(p, "#ffaa00").isResolved()); assertTrue(new ResolvedProperty(p, "#fb0").isResolved()); + assertTrue(new ResolvedProperty(p, "#ffaa0077").isResolved()); + assertTrue(new ResolvedProperty(p, "#fa07").isResolved()); + assertFalse(new ResolvedProperty(p, "#fx0").isResolved()); assertFalse(new ResolvedProperty(p, "#fa001").isResolved()); + assertFalse(new ResolvedProperty(p, "#dummy1").isResolved()); + assertFalse(new ResolvedProperty(p, "#dummy123").isResolved()); + assertFalse(new ResolvedProperty(p, "#dffaa007712").isResolved()); } public void testRGBaValues() { diff --git a/ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/TokenAcceptor.java b/ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/TokenAcceptor.java index c04e8bc311b2..10efb0efa984 100644 --- a/ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/TokenAcceptor.java +++ b/ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/TokenAcceptor.java @@ -21,6 +21,7 @@ import java.text.DateFormat; import java.text.ParseException; import java.util.*; +import java.util.regex.Pattern; import org.netbeans.modules.css.lib.api.CssTokenId; import org.netbeans.modules.web.common.api.LexerUtils; import org.openide.util.Lookup; @@ -186,14 +187,42 @@ protected List postfixes() { public static class HashColor extends TokenAcceptor { + private static final Pattern COLOR_PATTERN = Pattern.compile("#[0-9a-fA-F]{3,8}"); + public HashColor(String id) { super(id); } @Override public boolean accepts(Token token) { - int len = token.image().length(); - return token.tokenId() == CssTokenId.HASH && (len == 4 || len == 7); //three of six hex digits after hash sign are allowed + if(token.tokenId() != CssTokenId.HASH) { + return false; + } + CharSequence cs = token.image(); + // Variants: + // #RGB + // #RRGGBB + // #RGBA + // #RRGGBBAA + int len = cs.length(); + if(len != 4 && len != 7 && len != 5 && len != 9) { + return false; + } + if (cs.charAt(0) != '#') { + return false; + } + for (int i = 1; i < len; i++) { + if (!hexChar(cs.charAt(i))) { + return false; + } + } + return true; + } + + private static boolean hexChar(int val) { + return (val >= '0' && val <= '9') + || ( val >= 'a' && val <= 'f') + || (val >= 'A' && val <= 'F'); } } From 483cd8c8ef637a3b4fdf1cf1fd4c0fb59751caec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sun, 13 Nov 2022 15:25:41 +0100 Subject: [PATCH 2/4] Implement CSS3 sizing module Closes: #4312 --- .../css/editor/module/main/Bundle.properties | 1 + .../module/main/DefaultCssEditorModule.java | 3 +- .../properties/basic_box_model.properties | 8 --- .../basic_user_interface.properties | 3 - .../module/main/properties/sizing.properties | 28 ++++++++ .../module/main/BasicBoxModelModuleTest.java | 4 -- .../editor/module/main/SizingModuleTest.java | 65 +++++++++++++++++++ .../lib/api/properties/PropertyCategory.java | 3 +- 8 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/sizing.properties create mode 100644 ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/SizingModuleTest.java diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/Bundle.properties b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/Bundle.properties index acef45abdcca..9eb4e37b764e 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/Bundle.properties +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/Bundle.properties @@ -54,6 +54,7 @@ css-module-displayname-paged_media=Paged Media css-module-displayname-alignment=Box Alignment css-module-displayname-fragmentation=Fragmentation css-module-displayname-positioning=Positioning +css-module-displayname-sizing=Sizing completion-help-no-documentation-found=No documentation found diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/DefaultCssEditorModule.java b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/DefaultCssEditorModule.java index 8b63bd8feeeb..2595d643bc90 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/DefaultCssEditorModule.java +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/DefaultCssEditorModule.java @@ -105,7 +105,8 @@ public class DefaultCssEditorModule extends CssEditorModule { module("generated_and_replaced_content", "http://www.w3.org/TR/css3-content"), //NOI18N module("alignment", "http://www.w3.org/TR/css-align-3"), //NOI18N module("fragmentation", "http://www.w3.org/TR/css-break-3"), //NOI18N - module("positioning", "http://www.w3.org/TR/css3-positioning") //NOI18N + module("positioning", "http://www.w3.org/TR/css-position-3"), //NOI18N + module("sizing", "http://www.w3.org/TR/css-sizing-3") //NOI18N }; private static Map propertyDescriptors; diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/basic_box_model.properties b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/basic_box_model.properties index 8a667dce711d..efc4d6c722c1 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/basic_box_model.properties +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/basic_box_model.properties @@ -68,10 +68,6 @@ marquee-loop=!non-negative-integer | infinite | #marquee-style=scroll | slide | alternate -max-width;max-height= | | available | min-content | max-content | fit-content | none | inherit - -min-width;min-height= | | available | min-content | max-content | fit-content | inherit - overflow=[ visible | hidden | scroll | auto | no-display | no-content | ]{1,2} overflow-style= || @@ -86,7 +82,3 @@ rotation= rotation-point= visibility=visible | hidden | collapse | - -width=[ | ] && [border-box | content-box]? | available | min-content | max-content | fit-content | auto | inherit | - -height=[ | ] && [border-box | content-box]? | available | min-content | max-content | fit-content | complex | auto | inherit | \ No newline at end of file diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/basic_user_interface.properties b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/basic_user_interface.properties index b6e17fa905a8..e6291fcbb36c 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/basic_user_interface.properties +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/basic_user_interface.properties @@ -27,9 +27,6 @@ appearance=normal | | none | list-menu | radio-group | checkbox-group | outline-tree | range \ | field | combo-box | signature | password | -box-sizing=content-box | border-box | - - #content= # #@basic_user_interface-content= diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/sizing.properties b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/sizing.properties new file mode 100644 index 000000000000..3736d9c9c9df --- /dev/null +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/sizing.properties @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +#Basic User Interface Module + +$category=sizing + +box-sizing=content-box | border-box | + +width;height= auto | | | min-content | max-content | [ fit-content [ ( [ | ] ) ]? ] | inherit | + +max-width;max-height= none | | | min-content | max-content | [ fit-content [ ( [ | ] ) ]? ] | inherit | + +min-width;min-height= auto | | | min-content | max-content | [ fit-content [ ( [ | ] ) ]? ] | inherit | \ No newline at end of file diff --git a/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/BasicBoxModelModuleTest.java b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/BasicBoxModelModuleTest.java index f90fe4a3d8f3..073aa8821909 100644 --- a/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/BasicBoxModelModuleTest.java +++ b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/BasicBoxModelModuleTest.java @@ -40,10 +40,6 @@ public void testProperties() { assertPropertyValues("padding", "1px"); } - public void testHeight() { - assertPropertyDeclaration("height: 20px"); - } - public void testMargin() { assertPropertyDeclaration("margin: 1px"); //tblr == 1 assertPropertyDeclaration("margin: 1px 2px"); //tb=1, lr=2 diff --git a/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/SizingModuleTest.java b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/SizingModuleTest.java new file mode 100644 index 000000000000..7a024280f0da --- /dev/null +++ b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/SizingModuleTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.css.editor.module.main; + +public class SizingModuleTest extends CssModuleTestBase { + + public SizingModuleTest(String testName) { + super(testName); + } + + public void testHeightWidth() { + assertPropertyDeclaration("width: auto"); + assertPropertyDeclaration("height: 20px"); + assertPropertyDeclaration("width: 20%"); + assertPropertyDeclaration("height: min-content"); + assertPropertyDeclaration("width: max-content"); + assertPropertyDeclaration("height: fit-content"); + assertPropertyDeclaration("width: fit-content(30%)"); + assertPropertyDeclaration("height: inherit"); + assertPropertyDeclaration("width: initial"); + assertPropertyDeclaration("height: var(--test)"); + } + + public void testMaxHeightWidth() { + assertPropertyDeclaration("max-width: none"); + assertPropertyDeclaration("max-height: 20px"); + assertPropertyDeclaration("max-width: 20%"); + assertPropertyDeclaration("max-height: min-content"); + assertPropertyDeclaration("max-width: max-content"); + assertPropertyDeclaration("max-height: fit-content"); + assertPropertyDeclaration("max-width: fit-content(30%)"); + assertPropertyDeclaration("max-height: inherit"); + assertPropertyDeclaration("max-width: initial"); + assertPropertyDeclaration("max-height: var(--test)"); + } + + public void testMinHeightWidth() { + assertPropertyDeclaration("min-width: auto"); + assertPropertyDeclaration("min-height: 20px"); + assertPropertyDeclaration("min-width: 20%"); + assertPropertyDeclaration("min-height: min-content"); + assertPropertyDeclaration("min-width: max-content"); + assertPropertyDeclaration("min-height: fit-content"); + assertPropertyDeclaration("min-width: fit-content(30%)"); + assertPropertyDeclaration("min-height: inherit"); + assertPropertyDeclaration("min-width: initial"); + assertPropertyDeclaration("min-height: var(--test)"); + } +} diff --git a/ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/PropertyCategory.java b/ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/PropertyCategory.java index 7ac45bb679af..4c75acbaff53 100644 --- a/ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/PropertyCategory.java +++ b/ide/css.lib/src/org/netbeans/modules/css/lib/api/properties/PropertyCategory.java @@ -54,7 +54,8 @@ public enum PropertyCategory { MARQUEE, MULTI_COLUMN_LAYOUT, PAGED_MEDIA, - POSITIONING, + POSITIONING, + SIZING, RUBY, SPEECH, TEXT, From 9c61cda11e897dfde2d9a6f385d42d82a60ef8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sun, 13 Nov 2022 21:24:07 +0100 Subject: [PATCH 3/4] Complete CSS3 positioning module Completion of work started in #4480 --- .../main/properties/default_module.properties | 8 --- .../main/properties/positioning.properties | 6 +++ .../module/main/PositioningModuleTest.java | 53 +++++++++++++++++++ 3 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/PositioningModuleTest.java diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/default_module.properties b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/default_module.properties index 3da6a2f30a56..34150437f140 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/default_module.properties +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/default_module.properties @@ -48,8 +48,6 @@ azimuth= | [[ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards -bottom= | | auto - border-collapse=collapse | separate | border-spacing=[ []?] | @@ -64,8 +62,6 @@ elevation= | below | level | above | higher | lower empty-cells=show | hide | -left= | | auto - pitch-range= pitch=!frequency | x-low | low | medium | high | x-high @@ -76,8 +72,6 @@ quotes=[ ]+ | none | richness= -right= | | auto - speak-header=once | always | speak-numeral=digits | continuous | @@ -90,8 +84,6 @@ stress= table-layout=auto | fixed | -top= | | auto - volume= | | silent | x-soft | soft | medium | loud | x-loud z-index=auto | diff --git a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/positioning.properties b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/positioning.properties index 9867713492a8..7295dc6fa505 100644 --- a/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/positioning.properties +++ b/ide/css.editor/src/org/netbeans/modules/css/editor/module/main/properties/positioning.properties @@ -19,4 +19,10 @@ $category=positioning +top;right;bottom;left;inset-block-start;inset-inline-start;inset-block-end;inset-inline-end = | | auto + +inset = [ | | auto ]{1,4} + +inset-block;inset-inline = [ | | auto ]{1,2} + position=static | relative | absolute | fixed | sticky | diff --git a/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/PositioningModuleTest.java b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/PositioningModuleTest.java new file mode 100644 index 000000000000..6714df1b5b41 --- /dev/null +++ b/ide/css.editor/test/unit/src/org/netbeans/modules/css/editor/module/main/PositioningModuleTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.css.editor.module.main; + +public class PositioningModuleTest extends CssModuleTestBase { + + public PositioningModuleTest(String testName) { + super(testName); + } + + public void testBaseDefinitions() { + for (String propertyName : new String[]{"top", "right", "left", "bottom", "inset-block-start", "inset-inline-start", "inset-block-end", "inset-inline-end"}) { + for (String value : new String[]{"auto", "15.2px", "10%", "inherit", "initial", "unset"}) { + assertPropertyDeclaration(propertyName + ": " + value); + } + } + } + + public void testInset() { + assertPropertyDeclaration("inset: auto"); + assertPropertyDeclaration("inset: initial"); + assertPropertyDeclaration("inset: inherit"); + assertPropertyDeclaration("inset: 12px"); + assertPropertyDeclaration("inset: 12px auto"); + assertPropertyDeclaration("inset: 12px auto 42em"); + assertPropertyDeclaration("inset: 12px auto 42em 10%"); + } + + public void testInsetBlockInline() { + assertPropertyDeclaration("inset-block: auto"); + assertPropertyDeclaration("inset-inline: initial"); + assertPropertyDeclaration("inset-block: inherit"); + assertPropertyDeclaration("inset-inline: 12px"); + assertPropertyDeclaration("inset-block: 12px auto"); + } + +} From cb00c5844d47bea4847400d956764bee77a8e54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=A4sing?= Date: Sun, 13 Nov 2022 21:24:25 +0100 Subject: [PATCH 4/4] Update documentation for CSS3 properties --- ide/css.editor/external/binaries-list | 2 +- ide/css.editor/external/css3-spec-howtocreate.txt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ide/css.editor/external/binaries-list b/ide/css.editor/external/binaries-list index b5f382fb57bc..0034d6854be2 100644 --- a/ide/css.editor/external/binaries-list +++ b/ide/css.editor/external/binaries-list @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. 901D8F815922C435D985DA3814D20E34CC7622CB css21-spec.zip -25FEEFC8F0192368A5E0A35F4A6013A71865AECC css3-spec.zip +B9A045802E3214909501B822177EE3AA2F4A469F css3-spec.zip diff --git a/ide/css.editor/external/css3-spec-howtocreate.txt b/ide/css.editor/external/css3-spec-howtocreate.txt index 0642897c9890..f5492787a269 100644 --- a/ide/css.editor/external/css3-spec-howtocreate.txt +++ b/ide/css.editor/external/css3-spec-howtocreate.txt @@ -51,7 +51,9 @@ http://www.w3.org/TR/css3-ui/ \ http://www.w3.org/TR/css3-values/ \ http://www.w3.org/TR/css3-writing-modes/ \ http://www.w3.org/TR/css-align-3/ \ -http://www.w3.org/TR/css-break-3/ +http://www.w3.org/TR/css-break-3/ \ +http://www.w3.org/TR/css-position-3/ \ +http://www.w3.org/TR/css-sizing-3/ 3. Check that the contents still looks sane and mirroring worked