2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (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.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2009-08-20 14:52:47 -07:00
|
|
|
* Jonathon Jongsma <jonathon.jongsma@collabora.co.uk>, Collabora Ltd.
|
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* representation of a declaration block (or style attribute) in a CSS
|
|
|
|
* stylesheet
|
|
|
|
*/
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2010-08-19 12:33:44 -07:00
|
|
|
#include "nsPrintfCString.h"
|
2010-07-02 21:18:55 -07:00
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 11:00:52 -07:00
|
|
|
// check that we can fit all the CSS properties into a PRUint8
|
|
|
|
// for the mOrder array - if not, might need to use PRUint16!
|
|
|
|
PR_STATIC_ASSERT(eCSSProperty_COUNT_no_shorthands - 1 <= PR_UINT8_MAX);
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::Declaration()
|
2010-07-23 11:00:52 -07:00
|
|
|
: mImmutable(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-28 15:49:35 -07:00
|
|
|
MOZ_COUNT_CTOR(mozilla::css::Declaration);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::Declaration(const Declaration& aCopy)
|
2008-01-10 12:13:24 -08:00
|
|
|
: mOrder(aCopy.mOrder),
|
2010-07-23 11:00:52 -07:00
|
|
|
mData(aCopy.mData ? aCopy.mData->Clone() : nsnull),
|
2009-12-11 08:13:19 -08:00
|
|
|
mImportantData(aCopy.mImportantData
|
2010-07-23 11:00:52 -07:00
|
|
|
? aCopy.mImportantData->Clone() : nsnull),
|
|
|
|
mImmutable(PR_FALSE)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-28 15:49:35 -07:00
|
|
|
MOZ_COUNT_CTOR(mozilla::css::Declaration);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::~Declaration()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-28 15:49:35 -07:00
|
|
|
MOZ_COUNT_DTOR(mozilla::css::Declaration);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::ValueAppended(nsCSSProperty aProperty)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-23 11:00:49 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData,
|
|
|
|
"should only be called while expanded");
|
2009-03-05 20:05:01 -08:00
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"shorthands forbidden");
|
2007-03-22 10:30:00 -07:00
|
|
|
// order IS important for CSS, so remove and add to the end
|
2009-03-05 20:05:01 -08:00
|
|
|
mOrder.RemoveElement(aProperty);
|
|
|
|
mOrder.AppendElement(aProperty);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::RemoveProperty(nsCSSProperty aProperty)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSExpandedDataBlock data;
|
2009-12-11 08:13:19 -08:00
|
|
|
ExpandTo(&data);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData, "Expand didn't null things out");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (nsCSSProps::IsShorthand(aProperty)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
2010-07-23 11:00:42 -07:00
|
|
|
data.ClearLonghandProperty(*p);
|
2008-01-10 12:13:24 -08:00
|
|
|
mOrder.RemoveElement(*p);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2010-07-23 11:00:42 -07:00
|
|
|
data.ClearLonghandProperty(aProperty);
|
2008-01-10 12:13:24 -08:00
|
|
|
mOrder.RemoveElement(aProperty);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-11 08:13:19 -08:00
|
|
|
CompressFrom(&data);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 10:31:52 -08:00
|
|
|
PRBool
|
|
|
|
Declaration::HasProperty(nsCSSProperty aProperty) const
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
|
|
|
aProperty < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"property ID out of range");
|
|
|
|
|
|
|
|
nsCSSCompressedDataBlock *data = GetValueIsImportant(aProperty)
|
|
|
|
? mImportantData : mData;
|
|
|
|
const nsCSSValue *val = data->ValueFor(aProperty);
|
|
|
|
return !!val;
|
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool
|
|
|
|
Declaration::AppendValueToString(nsCSSProperty aProperty,
|
|
|
|
nsAString& aResult) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-23 11:00:29 -07:00
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty &&
|
|
|
|
aProperty < eCSSProperty_COUNT_no_shorthands,
|
|
|
|
"property ID out of range");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSCompressedDataBlock *data = GetValueIsImportant(aProperty)
|
|
|
|
? mImportantData : mData;
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *val = data->ValueFor(aProperty);
|
|
|
|
if (!val) {
|
2010-07-23 11:00:29 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
val->AppendToString(aProperty, aResult);
|
2010-07-23 11:00:29 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aValue.Truncate(0);
|
|
|
|
|
|
|
|
// simple properties are easy.
|
|
|
|
if (!nsCSSProps::IsShorthand(aProperty)) {
|
|
|
|
AppendValueToString(aProperty, aValue);
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-07 15:10:20 -07:00
|
|
|
// DOM Level 2 Style says (when describing CSS2Properties, although
|
|
|
|
// not CSSStyleDeclaration.getPropertyValue):
|
|
|
|
// However, if there is no shorthand declaration that could be added
|
|
|
|
// to the ruleset without changing in any way the rules already
|
|
|
|
// declared in the ruleset (i.e., by adding longhand rules that were
|
|
|
|
// previously not declared in the ruleset), then the empty string
|
|
|
|
// should be returned for the shorthand property.
|
|
|
|
// This means we need to check a number of cases:
|
|
|
|
// (1) Since a shorthand sets all sub-properties, if some of its
|
|
|
|
// subproperties were not specified, we must return the empty
|
|
|
|
// string.
|
|
|
|
// (2) Since 'inherit' and 'initial' can only be specified as the
|
|
|
|
// values for entire properties, we need to return the empty
|
|
|
|
// string if some but not all of the subproperties have one of
|
|
|
|
// those values.
|
|
|
|
// (3) Since a single value only makes sense with or without
|
|
|
|
// !important, we return the empty string if some values are
|
|
|
|
// !important and some are not.
|
|
|
|
// Since we're doing this check for 'inherit' and 'initial' up front,
|
|
|
|
// we can also simplify the property serialization code by serializing
|
|
|
|
// those values up front as well.
|
|
|
|
PRUint32 totalCount = 0, importantCount = 0,
|
|
|
|
initialCount = 0, inheritCount = 0;
|
2007-06-12 11:28:56 -07:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
2008-10-07 15:10:20 -07:00
|
|
|
if (*p == eCSSProperty__x_system_font ||
|
2008-10-27 10:55:51 -07:00
|
|
|
nsCSSProps::PropHasFlags(*p, CSS_PROPERTY_DIRECTIONAL_SOURCE)) {
|
2008-10-07 15:10:20 -07:00
|
|
|
// The system-font subproperty and the *-source properties don't count.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++totalCount;
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *val = mData->ValueFor(*p);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!val || !mImportantData || !mImportantData->ValueFor(*p),
|
|
|
|
"can't be in both blocks");
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!val && mImportantData) {
|
2008-10-07 15:10:20 -07:00
|
|
|
++importantCount;
|
2010-08-19 12:33:44 -07:00
|
|
|
val = mImportantData->ValueFor(*p);
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!val) {
|
2008-10-07 15:10:20 -07:00
|
|
|
// Case (1) above: some subproperties not specified.
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
if (val->GetUnit() == eCSSUnit_Inherit) {
|
2008-10-07 15:10:20 -07:00
|
|
|
++inheritCount;
|
2010-08-19 12:33:44 -07:00
|
|
|
} else if (val->GetUnit() == eCSSUnit_Initial) {
|
2008-10-07 15:10:20 -07:00
|
|
|
++initialCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (importantCount != 0 && importantCount != totalCount) {
|
|
|
|
// Case (3), no consistent importance.
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
|
|
|
if (initialCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing initial up-front.
|
2010-07-23 11:00:27 -07:00
|
|
|
nsCSSValue(eCSSUnit_Initial).AppendToString(eCSSProperty_UNKNOWN, aValue);
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
|
|
|
if (inheritCount == totalCount) {
|
|
|
|
// Simplify serialization below by serializing inherit up-front.
|
2010-07-23 11:00:27 -07:00
|
|
|
nsCSSValue(eCSSUnit_Inherit).AppendToString(eCSSProperty_UNKNOWN, aValue);
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
|
|
|
if (initialCount != 0 || inheritCount != 0) {
|
|
|
|
// Case (2): partially initial or inherit.
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2007-06-12 11:28:56 -07:00
|
|
|
}
|
|
|
|
|
2008-12-23 06:06:57 -08:00
|
|
|
nsCSSCompressedDataBlock *data = importantCount ? mImportantData : mData;
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSProperty_margin:
|
|
|
|
case eCSSProperty_padding:
|
|
|
|
case eCSSProperty_border_color:
|
|
|
|
case eCSSProperty_border_style:
|
|
|
|
case eCSSProperty_border_width: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[0]).Find("-top") !=
|
|
|
|
kNotFound, "first subprop must be top");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[1]).Find("-right") !=
|
|
|
|
kNotFound, "second subprop must be right");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[2]).Find("-bottom") !=
|
|
|
|
kNotFound, "third subprop must be bottom");
|
|
|
|
NS_ABORT_IF_FALSE(nsCSSProps::GetStringValue(subprops[3]).Find("-left") !=
|
|
|
|
kNotFound, "fourth subprop must be left");
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue &topValue = *data->ValueFor(subprops[0]);
|
|
|
|
const nsCSSValue &rightValue = *data->ValueFor(subprops[1]);
|
|
|
|
const nsCSSValue &bottomValue = *data->ValueFor(subprops[2]);
|
|
|
|
const nsCSSValue &leftValue = *data->ValueFor(subprops[3]);
|
2010-07-23 11:00:27 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(topValue.GetUnit() != eCSSUnit_Null, "null top");
|
2010-07-23 11:00:27 -07:00
|
|
|
topValue.AppendToString(subprops[0], aValue);
|
2008-12-23 06:06:57 -08:00
|
|
|
if (topValue != rightValue || topValue != leftValue ||
|
|
|
|
topValue != bottomValue) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(rightValue.GetUnit() != eCSSUnit_Null, "null right");
|
2010-07-23 11:00:27 -07:00
|
|
|
rightValue.AppendToString(subprops[1], aValue);
|
2008-12-23 06:06:57 -08:00
|
|
|
if (topValue != bottomValue || rightValue != leftValue) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(bottomValue.GetUnit() != eCSSUnit_Null, "null bottom");
|
2010-07-23 11:00:27 -07:00
|
|
|
bottomValue.AppendToString(subprops[2], aValue);
|
2008-12-23 06:06:57 -08:00
|
|
|
if (rightValue != leftValue) {
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(leftValue.GetUnit() != eCSSUnit_Null, "null left");
|
2010-07-23 11:00:27 -07:00
|
|
|
leftValue.AppendToString(subprops[3], aValue);
|
2008-12-23 06:06:57 -08:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-09-09 08:21:47 -07:00
|
|
|
case eCSSProperty_border_radius:
|
2008-09-30 22:50:52 -07:00
|
|
|
case eCSSProperty__moz_outline_radius: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue* vals[4] = {
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(subprops[0]),
|
|
|
|
data->ValueFor(subprops[1]),
|
|
|
|
data->ValueFor(subprops[2]),
|
|
|
|
data->ValueFor(subprops[3])
|
2008-09-30 22:50:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// For compatibility, only write a slash and the y-values
|
|
|
|
// if they're not identical to the x-values.
|
2010-08-19 12:33:44 -07:00
|
|
|
PRBool needY = PR_FALSE;
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (vals[i]->GetUnit() == eCSSUnit_Pair) {
|
|
|
|
needY = PR_TRUE;
|
|
|
|
vals[i]->GetPairValue().mXValue.AppendToString(subprops[i], aValue);
|
|
|
|
} else {
|
|
|
|
vals[i]->AppendToString(subprops[i], aValue);
|
|
|
|
}
|
|
|
|
if (i < 3)
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needY) {
|
2008-09-30 22:50:52 -07:00
|
|
|
aValue.AppendLiteral(" / ");
|
2010-08-19 12:33:44 -07:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (vals[i]->GetUnit() == eCSSUnit_Pair) {
|
|
|
|
vals[i]->GetPairValue().mYValue.AppendToString(subprops[i], aValue);
|
|
|
|
} else {
|
|
|
|
vals[i]->AppendToString(subprops[i], aValue);
|
|
|
|
}
|
|
|
|
if (i < 3)
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2008-09-30 22:50:52 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-12-23 06:06:57 -08:00
|
|
|
case eCSSProperty_border: {
|
|
|
|
const nsCSSProperty* subproptables[3] = {
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color),
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_style),
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_width)
|
|
|
|
};
|
|
|
|
PRBool match = PR_TRUE;
|
|
|
|
for (const nsCSSProperty** subprops = subproptables,
|
|
|
|
**subprops_end = subproptables + NS_ARRAY_LENGTH(subproptables);
|
|
|
|
subprops < subprops_end; ++subprops) {
|
|
|
|
// Check only the first four subprops in each table, since the
|
|
|
|
// others are extras for dimensional box properties.
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *firstSide = data->ValueFor((*subprops)[0]);
|
2008-12-23 06:06:57 -08:00
|
|
|
for (PRInt32 side = 1; side < 4; ++side) {
|
|
|
|
const nsCSSValue *otherSide =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor((*subprops)[side]);
|
2008-12-23 06:06:57 -08:00
|
|
|
if (*firstSide != *otherSide)
|
|
|
|
match = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!match) {
|
|
|
|
// We can't express what we have in the border shorthand
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// tweak aProperty and fall through
|
2007-03-22 10:30:00 -07:00
|
|
|
aProperty = eCSSProperty_border_top;
|
2008-12-23 06:06:57 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_border_top:
|
|
|
|
case eCSSProperty_border_right:
|
|
|
|
case eCSSProperty_border_bottom:
|
|
|
|
case eCSSProperty_border_left:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_border_start:
|
|
|
|
case eCSSProperty_border_end:
|
2008-07-19 03:38:25 -07:00
|
|
|
case eCSSProperty__moz_column_rule:
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_outline: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(StringEndsWith(nsCSSProps::GetStringValue(subprops[2]),
|
|
|
|
NS_LITERAL_CSTRING("-color")) ||
|
|
|
|
StringEndsWith(nsCSSProps::GetStringValue(subprops[2]),
|
|
|
|
NS_LITERAL_CSTRING("-color-value")),
|
|
|
|
"third subprop must be the color property");
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *colorValue = data->ValueFor(subprops[2]);
|
2008-12-23 06:06:57 -08:00
|
|
|
PRBool isMozUseTextColor =
|
|
|
|
colorValue->GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
colorValue->GetIntValue() == NS_STYLE_COLOR_MOZ_USE_TEXT_COLOR;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!AppendValueToString(subprops[0], aValue) ||
|
|
|
|
!(aValue.Append(PRUnichar(' ')),
|
|
|
|
AppendValueToString(subprops[1], aValue)) ||
|
2008-12-23 06:06:57 -08:00
|
|
|
// Don't output a third value when it's -moz-use-text-color.
|
|
|
|
!(isMozUseTextColor ||
|
|
|
|
(aValue.Append(PRUnichar(' ')),
|
|
|
|
AppendValueToString(subprops[2], aValue)))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue.Truncate();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_margin_left:
|
|
|
|
case eCSSProperty_margin_right:
|
|
|
|
case eCSSProperty_margin_start:
|
|
|
|
case eCSSProperty_margin_end:
|
|
|
|
case eCSSProperty_padding_left:
|
|
|
|
case eCSSProperty_padding_right:
|
|
|
|
case eCSSProperty_padding_start:
|
2007-07-04 11:51:16 -07:00
|
|
|
case eCSSProperty_padding_end:
|
|
|
|
case eCSSProperty_border_left_color:
|
|
|
|
case eCSSProperty_border_left_style:
|
|
|
|
case eCSSProperty_border_left_width:
|
|
|
|
case eCSSProperty_border_right_color:
|
|
|
|
case eCSSProperty_border_right_style:
|
|
|
|
case eCSSProperty_border_right_width:
|
|
|
|
case eCSSProperty_border_start_color:
|
|
|
|
case eCSSProperty_border_start_style:
|
|
|
|
case eCSSProperty_border_start_width:
|
|
|
|
case eCSSProperty_border_end_color:
|
|
|
|
case eCSSProperty_border_end_style:
|
|
|
|
case eCSSProperty_border_end_width: {
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(aProperty);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(subprops[3] == eCSSProperty_UNKNOWN,
|
|
|
|
"not box property with physical vs. logical cascading");
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendValueToString(subprops[0], aValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_background: {
|
2009-02-19 21:29:21 -08:00
|
|
|
// We know from above that all subproperties were specified.
|
|
|
|
// However, we still can't represent that in the shorthand unless
|
|
|
|
// they're all lists of the same length. So if they're different
|
|
|
|
// lengths, we need to bail out.
|
|
|
|
// We also need to bail out if an item has background-clip and
|
|
|
|
// background-origin that are different and not the default
|
|
|
|
// values. (We omit them if they're both default.)
|
|
|
|
const nsCSSValueList *image =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_image)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
const nsCSSValueList *repeat =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_repeat)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
const nsCSSValueList *attachment =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_attachment)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
const nsCSSValuePairList *position =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_position)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetPairListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
const nsCSSValueList *clip =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_clip)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
const nsCSSValueList *origin =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_origin)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetListValue();
|
2009-05-28 11:09:05 -07:00
|
|
|
const nsCSSValuePairList *size =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty_background_size)->
|
2010-08-19 12:33:44 -07:00
|
|
|
GetPairListValue();
|
2009-02-19 21:29:21 -08:00
|
|
|
for (;;) {
|
2009-12-15 13:40:38 -08:00
|
|
|
if (size->mXValue.GetUnit() != eCSSUnit_Auto ||
|
|
|
|
size->mYValue.GetUnit() != eCSSUnit_Auto) {
|
|
|
|
// Non-default background-size, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2009-12-15 13:40:38 -08:00
|
|
|
}
|
2010-07-23 11:00:27 -07:00
|
|
|
image->mValue.AppendToString(eCSSProperty_background_image, aValue);
|
2009-02-18 17:13:25 -08:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 11:00:27 -07:00
|
|
|
repeat->mValue.AppendToString(eCSSProperty_background_repeat, aValue);
|
2009-02-19 07:29:28 -08:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 11:00:27 -07:00
|
|
|
attachment->mValue.AppendToString(eCSSProperty_background_attachment,
|
|
|
|
aValue);
|
2009-02-19 12:33:09 -08:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 11:00:27 -07:00
|
|
|
position->mXValue.AppendToString(eCSSProperty_background_position,
|
|
|
|
aValue);
|
2009-02-19 21:29:21 -08:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 11:00:27 -07:00
|
|
|
position->mYValue.AppendToString(eCSSProperty_background_position,
|
|
|
|
aValue);
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(clip->mValue.GetUnit() == eCSSUnit_Enumerated &&
|
|
|
|
origin->mValue.GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"should not be inherit/initial within list and "
|
|
|
|
"should have returned early for real inherit/initial");
|
2009-02-19 21:29:21 -08:00
|
|
|
if (clip->mValue.GetIntValue() != NS_STYLE_BG_CLIP_BORDER ||
|
|
|
|
origin->mValue.GetIntValue() != NS_STYLE_BG_ORIGIN_PADDING) {
|
|
|
|
PR_STATIC_ASSERT(NS_STYLE_BG_CLIP_BORDER ==
|
|
|
|
NS_STYLE_BG_ORIGIN_BORDER);
|
2009-05-28 11:09:05 -07:00
|
|
|
PR_STATIC_ASSERT(NS_STYLE_BG_CLIP_PADDING ==
|
2009-02-19 21:29:21 -08:00
|
|
|
NS_STYLE_BG_ORIGIN_PADDING);
|
2010-06-08 18:44:32 -07:00
|
|
|
PR_STATIC_ASSERT(NS_STYLE_BG_CLIP_CONTENT ==
|
|
|
|
NS_STYLE_BG_ORIGIN_CONTENT);
|
2010-06-08 18:44:33 -07:00
|
|
|
// The shorthand only has a single clip/origin value which
|
|
|
|
// sets both properties. So if they're different (and
|
|
|
|
// non-default), we can't represent the state using the
|
|
|
|
// shorthand.
|
2009-02-19 21:29:21 -08:00
|
|
|
if (clip->mValue != origin->mValue) {
|
|
|
|
aValue.Truncate();
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 11:00:27 -07:00
|
|
|
clip->mValue.AppendToString(eCSSProperty_background_clip, aValue);
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
image = image->mNext;
|
|
|
|
repeat = repeat->mNext;
|
|
|
|
attachment = attachment->mNext;
|
|
|
|
position = position->mNext;
|
|
|
|
clip = clip->mNext;
|
|
|
|
origin = origin->mNext;
|
2009-05-28 11:09:05 -07:00
|
|
|
size = size->mNext;
|
2009-02-19 21:29:21 -08:00
|
|
|
|
|
|
|
if (!image) {
|
2009-05-28 11:09:05 -07:00
|
|
|
if (repeat || attachment || position || clip || origin || size) {
|
2009-02-19 21:29:21 -08:00
|
|
|
// Uneven length lists, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-05-28 11:09:05 -07:00
|
|
|
if (!repeat || !attachment || !position || !clip || !origin || !size) {
|
2009-02-19 21:29:21 -08:00
|
|
|
// Uneven length lists, so can't be serialized as shorthand.
|
|
|
|
aValue.Truncate();
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2009-02-19 21:29:21 -08:00
|
|
|
}
|
|
|
|
aValue.Append(PRUnichar(','));
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2009-02-19 21:29:21 -08:00
|
|
|
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(eCSSProperty_background_color, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_font: {
|
2009-02-06 08:52:12 -08:00
|
|
|
// systemFont might not be present; the others are guaranteed to be
|
|
|
|
// based on the shorthand check at the beginning of the function
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue *systemFont =
|
2010-08-19 12:33:44 -07:00
|
|
|
data->ValueFor(eCSSProperty__x_system_font);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &style =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_style);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &variant =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_variant);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &weight =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_weight);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &size =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_size);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &lh =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_line_height);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &family =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_family);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &stretch =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_stretch);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &sizeAdjust =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_size_adjust);
|
2010-07-13 13:30:42 -07:00
|
|
|
const nsCSSValue &featureSettings =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_feature_settings);
|
2010-07-13 13:30:42 -07:00
|
|
|
const nsCSSValue &languageOverride =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_font_language_override);
|
2007-06-12 11:28:56 -07:00
|
|
|
|
2009-02-06 08:52:12 -08:00
|
|
|
if (systemFont &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_None &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_Null) {
|
|
|
|
if (style.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
variant.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
weight.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
size.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
lh.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
family.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
stretch.GetUnit() != eCSSUnit_System_Font ||
|
2010-07-13 13:30:42 -07:00
|
|
|
sizeAdjust.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
featureSettings.GetUnit() != eCSSUnit_System_Font ||
|
|
|
|
languageOverride.GetUnit() != eCSSUnit_System_Font) {
|
2009-02-06 08:52:12 -08:00
|
|
|
// This can't be represented as a shorthand.
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2009-02-06 08:52:12 -08:00
|
|
|
}
|
2010-07-23 11:00:27 -07:00
|
|
|
systemFont->AppendToString(eCSSProperty__x_system_font, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2010-07-13 13:30:42 -07:00
|
|
|
// The font-stretch, font-size-adjust,
|
|
|
|
// -moz-font-feature-settings, and -moz-font-language-override
|
2008-12-23 06:06:57 -08:00
|
|
|
// properties are reset by this shorthand property to their
|
|
|
|
// initial values, but can't be represented in its syntax.
|
2009-11-14 19:16:59 -08:00
|
|
|
if (stretch.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
stretch.GetIntValue() != NS_STYLE_FONT_STRETCH_NORMAL ||
|
2010-07-13 13:30:42 -07:00
|
|
|
sizeAdjust.GetUnit() != eCSSUnit_None ||
|
|
|
|
featureSettings.GetUnit() != eCSSUnit_Normal ||
|
|
|
|
languageOverride.GetUnit() != eCSSUnit_Normal) {
|
2010-07-23 11:00:34 -07:00
|
|
|
return;
|
2008-12-23 06:06:57 -08:00
|
|
|
}
|
|
|
|
|
2009-10-21 17:25:30 -07:00
|
|
|
if (style.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
style.GetIntValue() != NS_FONT_STYLE_NORMAL) {
|
2010-07-23 11:00:27 -07:00
|
|
|
style.AppendToString(eCSSProperty_font_style, aValue);
|
2007-06-12 11:28:56 -07:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2009-10-21 17:25:30 -07:00
|
|
|
if (variant.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
variant.GetIntValue() != NS_FONT_VARIANT_NORMAL) {
|
2010-07-23 11:00:27 -07:00
|
|
|
variant.AppendToString(eCSSProperty_font_variant, aValue);
|
2007-06-12 11:28:56 -07:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2009-11-14 19:16:59 -08:00
|
|
|
if (weight.GetUnit() != eCSSUnit_Enumerated ||
|
|
|
|
weight.GetIntValue() != NS_FONT_WEIGHT_NORMAL) {
|
2010-07-23 11:00:27 -07:00
|
|
|
weight.AppendToString(eCSSProperty_font_weight, aValue);
|
2007-06-12 11:28:56 -07:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
2010-07-23 11:00:27 -07:00
|
|
|
size.AppendToString(eCSSProperty_font_size, aValue);
|
2007-06-12 11:28:56 -07:00
|
|
|
if (lh.GetUnit() != eCSSUnit_Normal) {
|
|
|
|
aValue.Append(PRUnichar('/'));
|
2010-07-23 11:00:27 -07:00
|
|
|
lh.AppendToString(eCSSProperty_line_height, aValue);
|
2007-06-12 11:28:56 -07:00
|
|
|
}
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-07-23 11:00:27 -07:00
|
|
|
family.AppendToString(eCSSProperty_font_family, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSProperty_list_style:
|
|
|
|
if (AppendValueToString(eCSSProperty_list_style_type, aValue))
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
if (AppendValueToString(eCSSProperty_list_style_position, aValue))
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
AppendValueToString(eCSSProperty_list_style_image, aValue);
|
|
|
|
break;
|
|
|
|
case eCSSProperty_overflow: {
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &xValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_overflow_x);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &yValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_overflow_y);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (xValue == yValue)
|
2010-07-23 11:00:27 -07:00
|
|
|
xValue.AppendToString(eCSSProperty_overflow_x, aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-08-20 14:52:47 -07:00
|
|
|
case eCSSProperty_transition: {
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue &transProp =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_transition_property);
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue &transDuration =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_transition_duration);
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue &transTiming =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_transition_timing_function);
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue &transDelay =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_transition_delay);
|
2010-08-19 12:33:44 -07:00
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(transDuration.GetUnit() == eCSSUnit_List ||
|
|
|
|
transDuration.GetUnit() == eCSSUnit_ListDep,
|
|
|
|
nsPrintfCString(32, "bad t-duration unit %d",
|
|
|
|
transDuration.GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(transTiming.GetUnit() == eCSSUnit_List ||
|
|
|
|
transTiming.GetUnit() == eCSSUnit_ListDep,
|
|
|
|
nsPrintfCString(32, "bad t-timing unit %d",
|
|
|
|
transTiming.GetUnit()).get());
|
|
|
|
NS_ABORT_IF_FALSE(transDelay.GetUnit() == eCSSUnit_List ||
|
|
|
|
transDelay.GetUnit() == eCSSUnit_ListDep,
|
|
|
|
nsPrintfCString(32, "bad t-delay unit %d",
|
|
|
|
transDelay.GetUnit()).get());
|
|
|
|
|
|
|
|
const nsCSSValueList* dur = transDuration.GetListValue();
|
|
|
|
const nsCSSValueList* tim = transTiming.GetListValue();
|
|
|
|
const nsCSSValueList* del = transDelay.GetListValue();
|
|
|
|
|
|
|
|
if (transProp.GetUnit() == eCSSUnit_None ||
|
|
|
|
transProp.GetUnit() == eCSSUnit_All) {
|
|
|
|
// If any of the other three lists has more than one element,
|
|
|
|
// we can't use the shorthand.
|
|
|
|
if (!dur->mNext && !tim->mNext && !del->mNext) {
|
|
|
|
transProp.AppendToString(eCSSProperty_transition_property, aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
dur->mValue.AppendToString(eCSSProperty_transition_duration,aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
|
|
|
|
aValue);
|
2010-08-19 12:33:44 -07:00
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
del->mValue.AppendToString(eCSSProperty_transition_delay, aValue);
|
2009-08-20 14:52:47 -07:00
|
|
|
aValue.Append(PRUnichar(' '));
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
aValue.Truncate();
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(transProp.GetUnit() == eCSSUnit_List ||
|
|
|
|
transProp.GetUnit() == eCSSUnit_ListDep,
|
|
|
|
nsPrintfCString(32, "bad t-prop unit %d",
|
|
|
|
transProp.GetUnit()).get());
|
|
|
|
const nsCSSValueList* pro = transProp.GetListValue();
|
|
|
|
for (;;) {
|
|
|
|
pro->mValue.AppendToString(eCSSProperty_transition_property,
|
|
|
|
aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
dur->mValue.AppendToString(eCSSProperty_transition_duration,
|
|
|
|
aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
tim->mValue.AppendToString(eCSSProperty_transition_timing_function,
|
|
|
|
aValue);
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
del->mValue.AppendToString(eCSSProperty_transition_delay,
|
|
|
|
aValue);
|
|
|
|
pro = pro->mNext;
|
|
|
|
dur = dur->mNext;
|
|
|
|
tim = tim->mNext;
|
|
|
|
del = del->mNext;
|
|
|
|
if (!pro || !dur || !tim || !del) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aValue.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
if (pro || dur || tim || del) {
|
|
|
|
// Lists not all the same length, can't use shorthand.
|
|
|
|
aValue.Truncate();
|
2009-08-20 14:52:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-04-11 23:18:44 -07:00
|
|
|
#ifdef MOZ_CSS_ANIMATIONS
|
2011-04-11 23:18:42 -07:00
|
|
|
case eCSSProperty_animation: {
|
|
|
|
const nsCSSProperty* subprops =
|
|
|
|
nsCSSProps::SubpropertyEntryFor(eCSSProperty_animation);
|
|
|
|
static const size_t numProps = 8;
|
|
|
|
NS_ABORT_IF_FALSE(subprops[numProps] == eCSSProperty_UNKNOWN,
|
|
|
|
"unexpected number of subproperties");
|
|
|
|
const nsCSSValue* values[numProps];
|
|
|
|
const nsCSSValueList* lists[numProps];
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < numProps; ++i) {
|
|
|
|
values[i] = data->ValueFor(subprops[i]);
|
|
|
|
NS_ABORT_IF_FALSE(values[i]->GetUnit() == eCSSUnit_List ||
|
|
|
|
values[i]->GetUnit() == eCSSUnit_ListDep,
|
|
|
|
nsPrintfCString(32, "bad a-duration unit %d",
|
|
|
|
values[i]->GetUnit()).get());
|
|
|
|
lists[i] = values[i]->GetListValue();
|
|
|
|
}
|
2009-08-20 14:52:47 -07:00
|
|
|
|
2011-04-11 23:18:42 -07:00
|
|
|
for (;;) {
|
|
|
|
// We must serialize 'animation-name' last in case it has
|
|
|
|
// a value that conflicts with one of the other keyword properties.
|
|
|
|
NS_ABORT_IF_FALSE(subprops[numProps - 1] ==
|
|
|
|
eCSSProperty_animation_name,
|
|
|
|
"animation-name must be last");
|
|
|
|
bool done = false;
|
|
|
|
for (PRUint32 i = 0;;) {
|
|
|
|
lists[i]->mValue.AppendToString(subprops[i], aValue);
|
|
|
|
lists[i] = lists[i]->mNext;
|
|
|
|
if (!lists[i]) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
if (++i == numProps) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aValue.Append(PRUnichar(' '));
|
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aValue.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
for (PRUint32 i = 0; i < numProps; ++i) {
|
|
|
|
if (lists[i]) {
|
|
|
|
// Lists not all the same length, can't use shorthand.
|
|
|
|
aValue.Truncate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-04-11 23:18:44 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCSSProperty_marker: {
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &endValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_marker_end);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &midValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_marker_mid);
|
2009-02-06 08:52:13 -08:00
|
|
|
const nsCSSValue &startValue =
|
2010-08-19 12:33:44 -07:00
|
|
|
*data->ValueFor(eCSSProperty_marker_start);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (endValue == midValue && midValue == startValue)
|
|
|
|
AppendValueToString(eCSSProperty_marker_end, aValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(false, "no other shorthands");
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::GetValueIsImportant(const nsAString& aProperty) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCSSProperty propID = nsCSSProps::LookupProperty(aProperty);
|
2010-10-17 19:36:26 -07:00
|
|
|
if (propID == eCSSProperty_UNKNOWN) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return GetValueIsImportant(propID);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::GetValueIsImportant(nsCSSProperty aProperty) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mImportantData)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
// Calling ValueFor is inefficient, but we can assume '!important' is rare.
|
2008-10-07 15:10:20 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
if (!nsCSSProps::IsShorthand(aProperty)) {
|
|
|
|
return mImportantData->ValueFor(aProperty) != nsnull;
|
2008-10-07 15:10:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
|
|
|
|
if (*p == eCSSProperty__x_system_font) {
|
|
|
|
// The system_font subproperty doesn't count.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!mImportantData->ValueFor(*p)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-19 12:33:44 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::AppendPropertyAndValueToString(nsCSSProperty aProperty,
|
|
|
|
nsAutoString& aValue,
|
|
|
|
nsAString& aResult) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(0 <= aProperty && aProperty < eCSSProperty_COUNT,
|
|
|
|
"property enum out of range");
|
|
|
|
NS_ABORT_IF_FALSE((aProperty < eCSSProperty_COUNT_no_shorthands) ==
|
|
|
|
aValue.IsEmpty(),
|
|
|
|
"aValue should be given for shorthands but not longhands");
|
2008-12-23 06:06:57 -08:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(aProperty), aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.AppendLiteral(": ");
|
2008-12-23 06:06:57 -08:00
|
|
|
if (aValue.IsEmpty())
|
|
|
|
AppendValueToString(aProperty, aResult);
|
|
|
|
else
|
|
|
|
aResult.Append(aValue);
|
2010-08-19 12:33:44 -07:00
|
|
|
if (GetValueIsImportant(aProperty)) {
|
|
|
|
aResult.AppendLiteral(" ! important");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
aResult.AppendLiteral("; ");
|
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::ToString(nsAString& aString) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-02 15:40:35 -07:00
|
|
|
// Someone cares about this declaration's contents, so don't let it
|
|
|
|
// change from under them. See e.g. bug 338679.
|
|
|
|
SetImmutable();
|
|
|
|
|
2009-02-06 08:52:12 -08:00
|
|
|
nsCSSCompressedDataBlock *systemFontData =
|
|
|
|
GetValueIsImportant(eCSSProperty__x_system_font) ? mImportantData : mData;
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *systemFont =
|
|
|
|
systemFontData->ValueFor(eCSSProperty__x_system_font);
|
2009-02-06 08:52:12 -08:00
|
|
|
const PRBool haveSystemFont = systemFont &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_None &&
|
|
|
|
systemFont->GetUnit() != eCSSUnit_Null;
|
|
|
|
PRBool didSystemFont = PR_FALSE;
|
|
|
|
|
2008-01-10 12:13:24 -08:00
|
|
|
PRInt32 count = mOrder.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 index;
|
2008-12-23 06:06:57 -08:00
|
|
|
nsAutoTArray<nsCSSProperty, 16> shorthandsUsed;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
nsCSSProperty property = OrderValueAt(index);
|
2008-12-23 06:06:57 -08:00
|
|
|
PRBool doneProperty = PR_FALSE;
|
|
|
|
|
|
|
|
// If we already used this property in a shorthand, skip it.
|
|
|
|
if (shorthandsUsed.Length() > 0) {
|
|
|
|
for (const nsCSSProperty *shorthands =
|
|
|
|
nsCSSProps::ShorthandsContaining(property);
|
|
|
|
*shorthands != eCSSProperty_UNKNOWN; ++shorthands) {
|
|
|
|
if (shorthandsUsed.Contains(*shorthands)) {
|
|
|
|
doneProperty = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-23 06:06:57 -08:00
|
|
|
if (doneProperty)
|
|
|
|
continue;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-12-23 06:06:57 -08:00
|
|
|
// Try to use this property in a shorthand.
|
|
|
|
nsAutoString value;
|
|
|
|
for (const nsCSSProperty *shorthands =
|
|
|
|
nsCSSProps::ShorthandsContaining(property);
|
|
|
|
*shorthands != eCSSProperty_UNKNOWN; ++shorthands) {
|
|
|
|
// ShorthandsContaining returns the shorthands in order from those
|
|
|
|
// that contain the most subproperties to those that contain the
|
|
|
|
// least, which is exactly the order we want to test them.
|
|
|
|
nsCSSProperty shorthand = *shorthands;
|
|
|
|
|
|
|
|
// If GetValue gives us a non-empty string back, we can use that
|
|
|
|
// value; otherwise it's not possible to use this shorthand.
|
|
|
|
GetValue(shorthand, value);
|
|
|
|
if (!value.IsEmpty()) {
|
|
|
|
AppendPropertyAndValueToString(shorthand, value, aString);
|
|
|
|
shorthandsUsed.AppendElement(shorthand);
|
|
|
|
doneProperty = PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
2008-12-23 06:06:57 -08:00
|
|
|
}
|
2009-02-06 08:52:12 -08:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(shorthand != eCSSProperty_font ||
|
|
|
|
*(shorthands + 1) == eCSSProperty_UNKNOWN,
|
|
|
|
"font should always be the only containing shorthand");
|
2009-02-19 13:55:48 -08:00
|
|
|
if (shorthand == eCSSProperty_font) {
|
|
|
|
if (haveSystemFont && !didSystemFont) {
|
2009-02-06 08:52:12 -08:00
|
|
|
// Output the shorthand font declaration that we will
|
|
|
|
// partially override later. But don't add it to
|
|
|
|
// |shorthandsUsed|, since we will have to override it.
|
2010-07-23 11:00:27 -07:00
|
|
|
systemFont->AppendToString(eCSSProperty__x_system_font, value);
|
2009-02-06 08:52:12 -08:00
|
|
|
AppendPropertyAndValueToString(eCSSProperty_font, value, aString);
|
|
|
|
value.Truncate();
|
|
|
|
didSystemFont = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// That we output the system font is enough for this property if:
|
2009-02-19 13:55:48 -08:00
|
|
|
// (1) it's the hidden system font subproperty (which either
|
|
|
|
// means we output it or we don't have it), or
|
2009-02-06 08:52:12 -08:00
|
|
|
// (2) its value is the hidden system font value and it matches
|
2009-02-19 13:55:48 -08:00
|
|
|
// the hidden system font subproperty in importance, and
|
|
|
|
// we output the system font subproperty.
|
2010-08-19 12:33:44 -07:00
|
|
|
const nsCSSValue *val = systemFontData->ValueFor(property);
|
2009-02-06 08:52:12 -08:00
|
|
|
if (property == eCSSProperty__x_system_font ||
|
2009-02-19 13:55:48 -08:00
|
|
|
(haveSystemFont && val && val->GetUnit() == eCSSUnit_System_Font)) {
|
2009-02-06 08:52:12 -08:00
|
|
|
doneProperty = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-12-23 06:06:57 -08:00
|
|
|
if (doneProperty)
|
|
|
|
continue;
|
2010-08-19 12:33:44 -07:00
|
|
|
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(value.IsEmpty(), "value should be empty now");
|
2008-12-23 06:06:57 -08:00
|
|
|
AppendPropertyAndValueToString(property, value, aString);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (! aString.IsEmpty()) {
|
2010-08-19 12:33:44 -07:00
|
|
|
// if the string is not empty, we have trailing whitespace we
|
|
|
|
// should remove
|
2007-03-22 10:30:00 -07:00
|
|
|
aString.Truncate(aString.Length() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-08-19 12:33:44 -07:00
|
|
|
void
|
|
|
|
Declaration::List(FILE* out, PRInt32 aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("{ ", out);
|
2007-05-16 14:17:45 -07:00
|
|
|
nsAutoString s;
|
|
|
|
ToString(s);
|
|
|
|
fputs(NS_ConvertUTF16toUTF8(s).get(), out);
|
2007-03-22 10:30:00 -07:00
|
|
|
fputs("}", out);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aReturn.Truncate();
|
2008-01-10 12:13:24 -08:00
|
|
|
if (aIndex < mOrder.Length()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSProperty property = OrderValueAt(aIndex);
|
|
|
|
if (0 <= property) {
|
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(property), aReturn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-23 11:00:34 -07:00
|
|
|
void
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::InitializeEmpty()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mData && !mImportantData, "already initialized");
|
2007-03-22 10:30:00 -07:00
|
|
|
mData = nsCSSCompressedDataBlock::CreateEmptyBlock();
|
|
|
|
}
|
2009-12-11 08:13:19 -08:00
|
|
|
|
2010-07-23 11:00:49 -07:00
|
|
|
Declaration*
|
2010-06-28 15:49:35 -07:00
|
|
|
Declaration::EnsureMutable()
|
2009-12-11 08:13:19 -08:00
|
|
|
{
|
2010-08-19 12:33:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(mData, "should only be called when not expanded");
|
2010-07-23 11:00:49 -07:00
|
|
|
if (!IsMutable()) {
|
2010-07-23 11:00:52 -07:00
|
|
|
return new Declaration(*this);
|
2010-07-23 11:00:49 -07:00
|
|
|
} else {
|
|
|
|
return this;
|
2009-12-11 08:13:19 -08:00
|
|
|
}
|
|
|
|
}
|
2010-06-28 15:49:35 -07:00
|
|
|
|
|
|
|
} // namespace mozilla::css
|
|
|
|
} // namespace mozilla
|