Bug 49058 - CSSStyleDeclaration.getPropertyPriority() fails for CSS shorthand properties with 'important' priority
Summary: CSSStyleDeclaration.getPropertyPriority() fails for CSS shorthand properties ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: All OS X 10.5
: P2 Normal
Assignee: Alexis Menard (darktears)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-05 00:45 PDT by Xianzhu Wang
Modified: 2012-02-01 13:48 PST (History)
9 users (show)

See Also:


Attachments
Test case (664 bytes, text/html)
2010-11-05 00:45 PDT, Xianzhu Wang
no flags Details
Patch (6.81 KB, patch)
2012-02-01 05:52 PST, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch (6.81 KB, patch)
2012-02-01 06:09 PST, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch (16.71 KB, patch)
2012-02-01 07:07 PST, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch (15.44 KB, patch)
2012-02-01 11:20 PST, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch for landing (14.51 KB, patch)
2012-02-01 11:52 PST, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch for landing (14.59 KB, patch)
2012-02-01 12:02 PST, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff
Patch for landing (14.40 KB, patch)
2012-02-01 12:08 PST, Alexis Menard (darktears)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Xianzhu Wang 2010-11-05 00:45:33 PDT
Created attachment 73040 [details]
Test case

For a style rule containing a declaration of a shorthand property (e.g. 'background'):
  background: yellow !important;
rule.getPropertyPriority('background') returns ''.
Firefox returns 'important'.
Comment 1 Yi Shen 2010-11-11 17:37:42 PST
(In reply to comment #0)
> Created an attachment (id=73040) [details]
> Test case
> 
> For a style rule containing a declaration of a shorthand property (e.g. 'background'):
>   background: yellow !important;
> rule.getPropertyPriority('background') returns ''.
> Firefox returns 'important'.

Is there any specification for this? If yes, I can try work on it.
Comment 2 Alexis Menard (darktears) 2012-02-01 05:52:47 PST
Created attachment 124937 [details]
Patch
Comment 3 Alexis Menard (darktears) 2012-02-01 06:09:05 PST
Created attachment 124940 [details]
Patch
Comment 4 Antti Koivisto 2012-02-01 06:21:33 PST
Comment on attachment 124940 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=124940&action=review

> Source/WebCore/css/CSSMutableStyleDeclaration.h:147
> +    bool getCommonPriority(const int* properties, size_t) const;

Please don't use get* naming. Follow the normal WebKit style instead (I know this class has existing cases).

The internal priority functions should either return enum or be named differently (bool hasImportantCommonPriority() or similar)
Comment 5 Antti Koivisto 2012-02-01 06:22:00 PST
It would be good to understand what other engines do in these cases.
Comment 6 Alexis Menard (darktears) 2012-02-01 07:07:05 PST
Created attachment 124948 [details]
Patch
Comment 7 Andreas Kling 2012-02-01 09:50:21 PST
Comment on attachment 124948 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=124948&action=review

> Source/WebCore/ChangeLog:31
> +2012-02-01  Alexis Menard  <alexis.menard@openbossa.org>

Double ChangeLog.

> Source/WebCore/css/CSSMutableStyleDeclaration.cpp:661
> +bool CSSMutableStyleDeclaration::hasPropertyImportantPriority(int propertyID) const

I like propertyIsImportant(int propertyID) better.

> Source/WebCore/css/CSSMutableStyleDeclaration.cpp:689
> +// Only returns true if all properties have the same priority false otherwise.
> +bool CSSMutableStyleDeclaration::hasImportantCommonPriority(const int* properties, size_t size) const
> +{
> +    bool res = hasPropertyImportantPriority(properties[0]);
> +    // The first longhand doesn't have priority, we can assume the others have equal priority.
> +    // If not it doesn't matter as we can't anyway resolve the priority of the shorthand.
> +    if (!res)
> +        return false;
> +
> +    for (size_t i = 1; i < size; ++i) {
> +        bool priority = hasPropertyImportantPriority(properties[i]);
> +        if (res != priority)
> +            return false;
> +    }
> +    return res;
>  }

This function doesn't do what its name implies. It only checks that all properties return true for hasPropertyImportantPriority() (since you return early if !res)

> Source/WebCore/css/CSSMutableStyleDeclaration.h:147
> +    bool hasImportantCommonPriority(const int* properties, size_t) const;

Should be static as it doesn't require an object.
Comment 8 Alexis Menard (darktears) 2012-02-01 11:20:01 PST
Created attachment 124978 [details]
Patch
Comment 9 Andreas Kling 2012-02-01 11:41:19 PST
Comment on attachment 124978 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=124978&action=review

> Source/WebKit/qt/ChangeLog:8
> +        Update the code as getPropertyPriority has been renamed to hasPropertyImportantPriority.

hasPropertyImportantPriority -> propertyIsImportant

> Source/WebCore/css/CSSMutableStyleDeclaration.cpp:663
> +    for (size_t i = 0; i < longhands.length(); ++i) {

longhands.length() returns unsigned so 'i' should be unsigned as well.

> Source/WebCore/css/CSSMutableStyleDeclaration.cpp:680
> +    return containsOnlyImportantProperties(longhands);

I think we can fold containsOnlyImportantProperties() into the propertyIsImportant() here, no need for it to be a separate function.

> LayoutTests/fast/css/shorthand-priority.html:10
> +description("Tests that query the priority for a shorthand works.");

query -> querying
Comment 10 Alexis Menard (darktears) 2012-02-01 11:52:04 PST
Created attachment 124980 [details]
Patch for landing
Comment 11 WebKit Review Bot 2012-02-01 11:56:01 PST
Attachment 124980 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'LayoutTests/ChangeLog', u'LayoutTests/fast..." exit_code: 1

Source/WebCore/ChangeLog:1:  ChangeLog entry has no bug number  [changelog/bugnumber] [5]
Total errors found: 1 in 10 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 12 Alexis Menard (darktears) 2012-02-01 12:02:30 PST
Created attachment 124982 [details]
Patch for landing
Comment 13 Alexis Menard (darktears) 2012-02-01 12:08:56 PST
Created attachment 124983 [details]
Patch for landing
Comment 14 WebKit Review Bot 2012-02-01 13:48:41 PST
Comment on attachment 124983 [details]
Patch for landing

Clearing flags on attachment: 124983

Committed r106490: <http://trac.webkit.org/changeset/106490>
Comment 15 WebKit Review Bot 2012-02-01 13:48:48 PST
All reviewed patches have been landed.  Closing bug.