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 background shorthand property #2992

Closed
aboalwi opened this issue Oct 31, 2016 · 16 comments · Fixed by #5053
Closed

CSS background shorthand property #2992

aboalwi opened this issue Oct 31, 2016 · 16 comments · Fixed by #5053

Comments

@aboalwi
Copy link

aboalwi commented Oct 31, 2016

I know i should be using background-color and it will work but you don't know how i'm used to it this way.. it's web developer friendly ... please :)

@tsonevn tsonevn self-assigned this Oct 31, 2016
@tsonevn
Copy link
Contributor

tsonevn commented Oct 31, 2016

Hi @aboalwi,
Thank you for interest in NativeScirpt.
Regaring to your issue, it would help if you could provide more info about your problem or sample project.
In NativeScript you could set background-color to Element using CSS file or just via adding the stile property in the open tag of the component in the XML. I am attaching examples.

XML

 <StackLayout backgroundColor="red">
</StackLayout>

CSS

StackLayout{
    background-color: green;
}

Hope this helps.

@aboalwi
Copy link
Author

aboalwi commented Oct 31, 2016

What i'm saying (in web) background: red; will work just fine.. that's how css works.. it's just a little thing not a big deal it would be nice for it to work in nativescript too.. since we are used to it... yea

@valentinstoychev
Copy link

This looks reasonable. The definition of how this property is used on web is here - http://www.w3schools.com/cssref/css3_pr_background.asp

@hshristov - is this something we can support, in order to have the same behavior with the web?

@hshristov
Copy link
Contributor

@valentinstoychev Yes we can support it.

@wnas
Copy link

wnas commented Oct 31, 2016

for proper documentation please do not refer to w3 fools. use MDN instead..

https://developer.mozilla.org/en-US/docs/Web/CSS/background-color

@tsonevn tsonevn removed their assignment Oct 31, 2016
@NordlingDev
Copy link

NordlingDev commented Oct 31, 2016

Same goes for the border property. We should be able to set the border with just one line:

border: 1 #000000;

Don't think border style is possible though, so having this wouldn't work (?):

border: 1 solid #000000;

Correct me if I'm wrong about above.

@hamorphis
Copy link
Contributor

@NordlingArt Currently, we only support solid borders, i.e. no dotted, dashes, etc.

@hamorphis
Copy link
Contributor

hamorphis commented Nov 1, 2016

By the way, in order to parse a shorthand value like this:

background: #00ff00 url("smiley.gif") no-repeat fixed center; 

I would need to rip of the source code of one of the web browser engines. The formal syntax of the background property is way messed up: https://developer.mozilla.org/en-US/docs/Web/CSS/background

The props can appear in any order they like and some of them may be omitted. Nice!

@hamorphis
Copy link
Contributor

@hamorphis
Copy link
Contributor

@hamorphis
Copy link
Contributor

hamorphis commented Nov 1, 2016

It is beautiful :)

https://github.com/WebKit/webkit/blob/f8d95c5a97274dbc4f6080d4059a232bf60db8a7/Source/WebCore/css/parser/CSSPropertyParser.cpp

bool CSSPropertyParser::consumeBackgroundShorthand(const StylePropertyShorthand& shorthand, bool important)
{
    const unsigned longhandCount = shorthand.length();
    RefPtr<CSSValue> longhands[10];
    ASSERT(longhandCount <= 10);

    bool implicit = false;
    do {
        bool parsedLonghand[10] = { false };
        RefPtr<CSSValue> originValue;
        do {
            bool foundProperty = false;
            for (size_t i = 0; i < longhandCount; ++i) {
                if (parsedLonghand[i])
                    continue;

                RefPtr<CSSValue> value;
                RefPtr<CSSValue> valueY;
                CSSPropertyID property = shorthand.properties()[i];
                if (property == CSSPropertyBackgroundRepeatX || property == CSSPropertyWebkitMaskRepeatX) {
                    RefPtr<CSSPrimitiveValue> primitiveValue;
                    RefPtr<CSSPrimitiveValue> primitiveValueY;
                    consumeRepeatStyleComponent(m_range, primitiveValue, primitiveValueY, implicit);
                    value = primitiveValue;
                    valueY = primitiveValueY;
                } else if (property == CSSPropertyBackgroundPositionX || property == CSSPropertyWebkitMaskPositionX) {
                    CSSParserTokenRange rangeCopy = m_range;
                    RefPtr<CSSPrimitiveValue> primitiveValue;
                    RefPtr<CSSPrimitiveValue> primitiveValueY;
                    if (!consumePosition(rangeCopy, m_context.mode, UnitlessQuirk::Forbid, primitiveValue, primitiveValueY))
                        continue;
                    value = primitiveValue;
                    valueY = primitiveValueY;
                    m_range = rangeCopy;
                } else if (property == CSSPropertyBackgroundSize || property == CSSPropertyWebkitMaskSize) {
                    if (!consumeSlashIncludingWhitespace(m_range))
                        continue;
                    value = consumeBackgroundSize(property, m_range, m_context.mode);
                    if (!value || !parsedLonghand[i - 1]) // Position must have been parsed in the current layer.
                        return false;
                } else if (property == CSSPropertyBackgroundPositionY || property == CSSPropertyBackgroundRepeatY
                    || property == CSSPropertyWebkitMaskPositionY || property == CSSPropertyWebkitMaskRepeatY) {
                    continue;
                } else {
                    value = consumeBackgroundComponent(property, m_range, m_context);
                }
                if (value) {
                    if (property == CSSPropertyBackgroundOrigin || property == CSSPropertyWebkitMaskOrigin)
                        originValue = value;
                    parsedLonghand[i] = true;
                    foundProperty = true;
                    addBackgroundValue(longhands[i], value.releaseNonNull());
                    if (valueY) {
                        parsedLonghand[i + 1] = true;
                        addBackgroundValue(longhands[i + 1], valueY.releaseNonNull());
                    }
                }
            }
            if (!foundProperty)
                return false;
        } while (!m_range.atEnd() && m_range.peek().type() != CommaToken);

        // FIXME: This will make invalid longhands, see crbug.com/386459
        for (size_t i = 0; i < longhandCount; ++i) {
            CSSPropertyID property = shorthand.properties()[i];
            if (property == CSSPropertyBackgroundColor && !m_range.atEnd()) {
                if (parsedLonghand[i])
                    return false; // Colors are only allowed in the last layer.
                continue;
            }
            if ((property == CSSPropertyBackgroundClip || property == CSSPropertyWebkitMaskClip) && !parsedLonghand[i] && originValue) {
                addBackgroundValue(longhands[i], originValue.releaseNonNull());
                continue;
            }
            if (!parsedLonghand[i])
                addBackgroundValue(longhands[i], CSSValuePool::singleton().createImplicitInitialValue());
        }
    } while (consumeCommaIncludingWhitespace(m_range));
    if (!m_range.atEnd())
        return false;

    for (size_t i = 0; i < longhandCount; ++i) {
        CSSPropertyID property = shorthand.properties()[i];
        if (property == CSSPropertyBackgroundSize && longhands[i] && m_context.useLegacyBackgroundSizeShorthandBehavior)
            continue;
        addProperty(property, shorthand.id(), *longhands[i], important, implicit);
    }
    return true;
}

@hamorphis
Copy link
Contributor

That is a great task for the community. Write a function that accepts a shorthand background string and returns a JSON object containing background-color, -image, -position, -size, and -repeat.

@vjoao
Copy link
Contributor

vjoao commented Nov 16, 2016

This might give you a hint.
https://github.com/gilmoreorless/css-background-parser

@hamorphis
Copy link
Contributor

@vjoao Thanks, I will check it out.

@hamorphis hamorphis self-assigned this Nov 22, 2016
@hamorphis hamorphis changed the title background: color; does nothing CSS background shorthand property Nov 28, 2016
@ghost ghost assigned ADjenkov Nov 9, 2017
@ghost ghost added the in progress label Nov 9, 2017
@hgc2002
Copy link

hgc2002 commented Apr 21, 2019

Animated GIF for background do not work, shorthanded or not.

.page {
   background: url("~/assets/images/animated.gif");
}

The GIF is shown, but statically, not the animation it contains.

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot unassigned ADjenkov Apr 25, 2020
@lock lock bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.