Closed
Bug 107923
Opened 24 years ago
Closed 23 years ago
nsCSSDeclaration::GetCssText flubs !important rules
Categories
(Core :: DOM: CSS Object Model, defect)
Core
DOM: CSS Object Model
Tracking
()
RESOLVED
FIXED
mozilla1.1alpha
People
(Reporter: bzbarsky, Assigned: glazou)
References
Details
(Keywords: dom2)
Attachments
(1 file, 2 obsolete files)
1.19 KB,
text/html
|
Details |
All the shorthand property handling in nsCSSDeclaration::GetCssText has major
issues with handling of !important. Specifically, it does not distinguish
between the following sets of property/value pairs:
1) border: 1px solid red;
2) border: 1px solid red !important;
3) border: 1px red; border-style: solid !important;
The logic for deciding when to combine things and when not to really should take
this into account.
I have a simple change to AppendValueToString which could fix the fact that
!important properties are not displayed, but it just adds "!important" after the
property value, which is no good if multiple properties values get appended in a
row as the shorthand code does.
![]() |
Reporter | |
Comment 1•24 years ago
|
||
Assignee | ||
Comment 2•24 years ago
|
||
Very good catch, Boris. Accepting bug.
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9.7
Comment 5•23 years ago
|
||
Moving to Moz1.1. Engineers are overloaded with higher priority bugs.
Target Milestone: mozilla0.9.9 → mozilla1.1
![]() |
Reporter | |
Comment 6•23 years ago
|
||
I should note that this has an easy fix if it were not for the design of our
shorthand system. Could we please back that out, fix this bug, and then do the
shorthands when we can do them something resembling right? As it is, we're
violating the spec here for questionable benefit...
Keywords: dom2
Assignee | ||
Comment 7•23 years ago
|
||
NO !!! This change is not a questionable benefit for CSS in Composer but
an absolutely necessary change. DON'T DO THAT !
![]() |
Reporter | |
Comment 8•23 years ago
|
||
OK. So could we please not break CSS use by web authors for the benefit of CSS
in composer in the future? Unlike web authors composer _could_ be using
internal APIs for this if it needed to...
Comment 9•23 years ago
|
||
If this broke real webpages only in favor of making CSS in composer work
correctly, then I'm afraid I'll haveto go with bz here. Regressing stuff that
shows up on real web pages is not acceptable unless the gain in some other are
is *really* *really* high. Can we do something about this?
![]() |
Reporter | |
Comment 10•23 years ago
|
||
I should qualify my comments in glazou's favor. The shorthands did not break
anything that was not broken -- we have always flubbed the !important rules.
The shorthand stuff just makes fixing the !important issue much harder...
Assignee | ||
Comment 11•23 years ago
|
||
Fix almost in hand. Should be ok for 099.
Assignee | ||
Comment 12•23 years ago
|
||
with this patch, cssText now correctly output "! important" declarations and
I fixed some holes in my previous code (for instance border-style shorthand
not handled). Test case attached OK, and even with a better factorization
that the original css rules.
Reviews please ?
![]() |
Reporter | |
Comment 13•23 years ago
|
||
> (!isBgPositionXImportant == !isBgPositionYImportant))
You do this all over... Just use
(isBgPositionXImportant == isBgPositionYImportant) -- these are PRBools...
I think it would make sense to add nsCSSDeclaration::AllPropertiesSameImportance
and call that first thing from nsCSSDeclaration::AllPropertiesSameValue. That
would be much more reusable, in my opinion, for other shorthands too...
Change AppendImportanceToStringIfNeeded and AppendDeclarationSeparator to return
nsAString& instead of void. Then you can do things like:
aString.Append(ImportanceIfNeeded(GetValueIsImportant(aProperty)) +
DeclarationSeparator());
reducing string copies. You could even inline those functions. As far as that
goes, I'd make the declaration separator a define.... [#define
kDeclarationSeparator NS_LITERAL_STRING("; ") ]
Your new code could fail to create a background shorthand in the following
scenario:
background: url() center center no-repeat green;
background-attachment: center right !important;
Since in this case you will reset numberOfSameImportance to 1. You probably
only want to do that for cases when numberOfSameImportance has not gotten bigger
than 1 yet... (this last issue is pretty minor and I'd be happy to see that
spun off into a separate bug).
Assignee | ||
Comment 14•23 years ago
|
||
boris : no, you cannot use (a == b) if a and b are PRBools. We had a discussion
in #mozilla with brendan and shaver ; PRBool is an int ; it *should* be 0 or 1
but that's not for sure. Using (!a == !b) guarantees that you are comparing values
both equal to 0 or 1.
About shorthand factorization : I studied it a while and I think that factorization
in all cases is extremely difficult, or even impossible. Because border-*
shorthands can be grouped by size or by type, there are cases where you just cannot
decide the factorization user wants. Implementation has to make a choice.
Comment 15•23 years ago
|
||
!a == !b seems just wrong to me. Why not do the right thing and ensure that you
never assign a "true" value other than 1 into PRBool's every time you assign
into them? Then you could do the obvious and natural a == b check w/o confusing
the code with the negation operators all over.
Assignee | ||
Comment 16•23 years ago
|
||
Attachment #70292 -
Attachment is obsolete: true
![]() |
Reporter | |
Comment 17•23 years ago
|
||
1) I still think we could use nsCSSDeclaration::AllPropertiesSameImportance....
Could be used in at least two places in your code, and likely in future
shorthands. If you decide not to do that, I think it would be nice to change
the code in nsCSSDeclaration::AllPropertiesSameValue to be as lazy about
getting values as possible (getting values can be expensive).
So something like:
PRBool isSecondImportant =
GetValueIsImportant((nsCSSProperty)mOrder->ValueAt(aSecond));
if (isFirstImportant != isSecondImportant) {
return PR_FALSE;
}
GetValue((nsCSSProperty)mOrder->ValueAt(aFirst), firstValue);
GetValue((nsCSSProperty)mOrder->ValueAt(aSecond), otherValue);
if (firstValue != otherValue) {
return PR_FALSE;
}
2)
> +#define CSS_IMPORTANCE_STRING(importance) (importance ? ...
Please parenthesize "(importance)" in the macro body.
> +#define kDeclarationSeparation NS_LITERAL_STRING(" ; ")
Why the space before the ';'? Also, I'd call it "separator" not "separation".
Other than that, looks good... Thanks for doing this, glazou.
Assignee | ||
Comment 18•23 years ago
|
||
Comment on attachment 70514 [details] [diff] [review]
patch v2.0
I am merging the work done on this bug and the one done on bug 142019. Please
see bug 142019 for new patches.
Attachment #70514 -
Attachment is obsolete: true
Assignee | ||
Comment 19•23 years ago
|
||
Forgot to say a few things :
1. new patch follows Hixie's suggestions
2. I also fixed a bug in background shorthand output
No longer depends on: 142019
Assignee | ||
Comment 20•23 years ago
|
||
This bug is fixed by fix for 142019, checked in just a minute ago => closing
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•