Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Css improvements #4964

Merged
merged 4 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ide/css.editor/external/binaries-list
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion ide/css.editor/external/css3-spec-howtocreate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, PropertyDefinition> propertyDescriptors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ marquee-loop=!non-negative-integer | infinite | <var-fn>

#marquee-style=scroll | slide | alternate

max-width;max-height= <length> | <percentage> | available | min-content | max-content | fit-content | none | inherit

min-width;min-height= <length> | <percentage> | available | min-content | max-content | fit-content | inherit

overflow=[ visible | hidden | scroll | auto | no-display | no-content | <var-fn> ]{1,2}

overflow-style=<basic_box_model-overflow-style> || <marquee_model-overflow-style>
Expand All @@ -86,7 +82,3 @@ rotation=<angle>
rotation-point=<bg-pos>

visibility=visible | hidden | collapse | <var-fn>

width=[ <length> | <percentage> ] && [border-box | content-box]? | available | min-content | max-content | fit-content | auto | inherit | <var-fn>

height=[ <length> | <percentage> ] && [border-box | content-box]? | available | min-content | max-content | fit-content | complex | auto | inherit | <var-fn>
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ appearance=normal | <appearance> | none
| list-menu | radio-group | checkbox-group | outline-tree | range \
| field | combo-box | signature | password | <var-fn>

box-sizing=content-box | border-box | <var-fn>


#content=<basic_user_interface-content>
#
#@basic_user_interface-content=<icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

azimuth=<angle> | [[ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards

bottom=<length> | <percentage> | auto

border-collapse=collapse | separate | <var-fn>

border-spacing=[<length> [<length>]?] | <var-fn>
Expand All @@ -64,8 +62,6 @@ elevation=<angle> | below | level | above | higher | lower

empty-cells=show | hide | <var-fn>

left=<length> | <percentage> | auto

pitch-range=<number>

pitch=!frequency | x-low | low | medium | high | x-high
Expand All @@ -76,8 +72,6 @@ quotes=[<string> <string>]+ | none | <var-fn>

richness=<number>

right=<length> | <percentage> | auto

speak-header=once | always | <var-fn>

speak-numeral=digits | continuous | <var-fn>
Expand All @@ -90,8 +84,6 @@ stress=<number>

table-layout=auto | fixed | <var-fn>

top=<length> | <percentage> | auto

volume=<number> | <percentage> | silent | x-soft | soft | medium | loud | x-loud

z-index=auto | <integer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@

$category=positioning

top;right;bottom;left;inset-block-start;inset-inline-start;inset-block-end;inset-inline-end = <length> | <percentage> | auto

inset = [ <length> | <percentage> | auto ]{1,4}

inset-block;inset-inline = [ <length> | <percentage> | auto ]{1,2}

position=static | relative | absolute | fixed | sticky | <var-fn>
Original file line number Diff line number Diff line change
@@ -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 | <var-fn>

width;height= auto | <length> | <percentage> | min-content | max-content | [ fit-content [ ( [ <length> | <percentage> ] ) ]? ] | inherit | <var-fn>

max-width;max-height= none | <length> | <percentage> | min-content | max-content | [ fit-content [ ( [ <length> | <percentage> ] ) ]? ] | inherit | <var-fn>

min-width;min-height= auto | <length> | <percentage> | min-content | max-content | [ fit-content [ ( [ <length> | <percentage> ] ) ]? ] | inherit | <var-fn>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}

}
Original file line number Diff line number Diff line change
@@ -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)");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public enum PropertyCategory {
MARQUEE,
MULTI_COLUMN_LAYOUT,
PAGED_MEDIA,
POSITIONING,
POSITIONING,
SIZING,
RUBY,
SPEECH,
TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,14 +187,42 @@ protected List<String> 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');
}
}

Expand Down