2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-10-08 05:29:29 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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/
|
1998-10-08 05:29:29 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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.
|
1998-10-08 05:29:29 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-10-08 05:29:29 +04:00
|
|
|
#include "nsCSSValue.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCSSProps.h"
|
2000-08-23 21:27:06 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsContentUtils.h"
|
2006-02-20 12:38:54 +03:00
|
|
|
#include "nsPresContext.h"
|
2004-03-09 06:57:51 +03:00
|
|
|
|
|
|
|
// Paint forcing
|
|
|
|
#include "prenv.h"
|
1998-10-08 05:29:29 +04:00
|
|
|
|
|
|
|
//#include "nsStyleConsts.h"
|
|
|
|
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((eCSSUnit_Integer == aUnit) ||
|
|
|
|
(eCSSUnit_Enumerated == aUnit), "not an int value");
|
|
|
|
if ((eCSSUnit_Integer == aUnit) ||
|
|
|
|
(eCSSUnit_Enumerated == aUnit)) {
|
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(float aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Percent <= aUnit, "not a float value");
|
|
|
|
if (eCSSUnit_Percent <= aUnit) {
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
nsCSSValue::nsCSSValue(const nsAString& aValue, nsCSSUnit aUnit)
|
1998-10-27 02:19:59 +03:00
|
|
|
: mUnit(aUnit)
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
2005-04-02 03:07:00 +04:00
|
|
|
NS_ASSERTION((eCSSUnit_String <= aUnit) && (aUnit <= eCSSUnit_Attr), "not a string value");
|
|
|
|
if ((eCSSUnit_String <= aUnit) && (aUnit <= eCSSUnit_Attr)) {
|
2000-08-23 21:27:06 +04:00
|
|
|
mValue.mString = ToNewUnicode(aValue);
|
1998-10-27 02:19:59 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mUnit = eCSSUnit_Null;
|
|
|
|
mValue.mInt = 0;
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::nsCSSValue(nscolor aValue)
|
|
|
|
: mUnit(eCSSUnit_Color)
|
|
|
|
{
|
|
|
|
mValue.mColor = aValue;
|
|
|
|
}
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
|
|
|
|
: mUnit(aUnit)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Array <= aUnit && aUnit <= eCSSUnit_Counters,
|
|
|
|
"bad unit");
|
|
|
|
mValue.mArray = aValue;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
|
|
|
|
2003-10-30 04:45:37 +03:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValue::URL* aValue)
|
2003-10-02 02:53:56 +04:00
|
|
|
: mUnit(eCSSUnit_URL)
|
|
|
|
{
|
|
|
|
mValue.mURL = aValue;
|
2003-10-30 04:45:37 +03:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
nsCSSValue::nsCSSValue(nsCSSValue::Image* aValue)
|
|
|
|
: mUnit(eCSSUnit_Image)
|
|
|
|
{
|
|
|
|
mValue.mImage = aValue;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
nsCSSValue::nsCSSValue(const nsCSSValue& aCopy)
|
|
|
|
: mUnit(aCopy.mUnit)
|
|
|
|
{
|
2005-04-02 03:07:00 +04:00
|
|
|
if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Attr)) {
|
1998-10-08 05:29:29 +04:00
|
|
|
if (nsnull != aCopy.mValue.mString) {
|
2000-06-06 13:36:12 +04:00
|
|
|
mValue.mString = nsCRT::strdup(aCopy.mValue.mString);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mValue.mString = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) {
|
|
|
|
mValue.mInt = aCopy.mValue.mInt;
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Color == mUnit){
|
|
|
|
mValue.mColor = aCopy.mValue.mColor;
|
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
else if (eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Counters) {
|
|
|
|
mValue.mArray = aCopy.mValue.mArray;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
2003-10-02 02:53:56 +04:00
|
|
|
else if (eCSSUnit_URL == mUnit){
|
|
|
|
mValue.mURL = aCopy.mValue.mURL;
|
2003-10-30 04:45:37 +03:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
else if (eCSSUnit_Image == mUnit){
|
|
|
|
mValue.mImage = aCopy.mValue.mImage;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
else {
|
|
|
|
mValue.mFloat = aCopy.mValue.mFloat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
nsCSSValue::~nsCSSValue()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy)
|
|
|
|
{
|
2005-04-03 20:47:01 +04:00
|
|
|
if (this != &aCopy) {
|
|
|
|
Reset();
|
|
|
|
new (this) nsCSSValue(aCopy);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsCSSValue::operator==(const nsCSSValue& aOther) const
|
|
|
|
{
|
|
|
|
if (mUnit == aOther.mUnit) {
|
2005-04-02 03:07:00 +04:00
|
|
|
if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Attr)) {
|
1998-10-08 05:29:29 +04:00
|
|
|
if (nsnull == mValue.mString) {
|
|
|
|
if (nsnull == aOther.mValue.mString) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsnull != aOther.mValue.mString) {
|
2000-06-06 13:36:12 +04:00
|
|
|
return (nsCRT::strcmp(mValue.mString, aOther.mValue.mString) == 0);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) {
|
2003-10-02 02:53:56 +04:00
|
|
|
return mValue.mInt == aOther.mValue.mInt;
|
|
|
|
}
|
|
|
|
else if (eCSSUnit_Color == mUnit) {
|
|
|
|
return mValue.mColor == aOther.mValue.mColor;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
else if (eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Counters) {
|
|
|
|
return *mValue.mArray == *aOther.mValue.mArray;
|
|
|
|
}
|
2003-10-02 02:53:56 +04:00
|
|
|
else if (eCSSUnit_URL == mUnit) {
|
2003-10-30 04:45:37 +03:00
|
|
|
return *mValue.mURL == *aOther.mValue.mURL;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
else if (eCSSUnit_Image == mUnit) {
|
|
|
|
return *mValue.mImage == *aOther.mValue.mImage;
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
else {
|
2003-10-02 02:53:56 +04:00
|
|
|
return mValue.mFloat == aOther.mValue.mFloat;
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
imgIRequest* nsCSSValue::GetImageValue() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUnit == eCSSUnit_Image, "not an Image value");
|
|
|
|
return mValue.mImage->mRequest;
|
|
|
|
}
|
|
|
|
|
2006-02-20 12:38:54 +03:00
|
|
|
nscoord nsCSSValue::GetLengthTwips(nsPresContext* aPresContext) const
|
2003-12-29 22:07:53 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IsFixedLengthUnit(), "not a fixed length unit");
|
2006-02-20 12:38:54 +03:00
|
|
|
NS_ASSERTION(aPresContext, "aPresContext is null");
|
2003-12-29 22:07:53 +03:00
|
|
|
|
2006-02-20 12:38:54 +03:00
|
|
|
float scale =
|
|
|
|
aPresContext->ScaledPixelsToTwips() / aPresContext->PixelsToTwips();
|
2003-12-29 22:07:53 +03:00
|
|
|
if (IsFixedLengthUnit()) {
|
|
|
|
switch (mUnit) {
|
|
|
|
case eCSSUnit_Inch:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_INCHES_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Foot:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_FEET_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Mile:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_MILES_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
|
|
|
|
case eCSSUnit_Millimeter:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_MILLIMETERS_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Centimeter:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_CENTIMETERS_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Meter:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_METERS_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Kilometer:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_KILOMETERS_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
|
|
|
|
case eCSSUnit_Point:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NSFloatPointsToTwips(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Pica:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_PICAS_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Didot:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_DIDOTS_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
case eCSSUnit_Cicero:
|
2006-02-20 12:38:54 +03:00
|
|
|
return NS_CICEROS_TO_TWIPS(mValue.mFloat * scale);
|
2003-12-29 22:07:53 +03:00
|
|
|
default:
|
|
|
|
NS_ERROR("should never get here");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-10-08 05:29:29 +04:00
|
|
|
void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((eCSSUnit_Integer == aUnit) ||
|
|
|
|
(eCSSUnit_Enumerated == aUnit), "not an int value");
|
|
|
|
Reset();
|
|
|
|
if ((eCSSUnit_Integer == aUnit) ||
|
|
|
|
(eCSSUnit_Enumerated == aUnit)) {
|
|
|
|
mUnit = aUnit;
|
|
|
|
mValue.mInt = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetPercentValue(float aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Percent;
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetFloatValue(float aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Number <= aUnit, "not a float value");
|
|
|
|
Reset();
|
|
|
|
if (eCSSUnit_Number <= aUnit) {
|
|
|
|
mUnit = aUnit;
|
|
|
|
mValue.mFloat = aValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
void nsCSSValue::SetStringValue(const nsAString& aValue,
|
2000-08-23 21:27:06 +04:00
|
|
|
nsCSSUnit aUnit)
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
2005-04-02 03:07:00 +04:00
|
|
|
NS_ASSERTION((eCSSUnit_String <= aUnit) && (aUnit <= eCSSUnit_Attr), "not a string unit");
|
1998-10-08 05:29:29 +04:00
|
|
|
Reset();
|
2005-04-02 03:07:00 +04:00
|
|
|
if ((eCSSUnit_String <= aUnit) && (aUnit <= eCSSUnit_Attr)) {
|
1998-10-27 02:19:59 +03:00
|
|
|
mUnit = aUnit;
|
2000-08-23 21:27:06 +04:00
|
|
|
mValue.mString = ToNewUnicode(aValue);
|
1998-10-27 02:19:59 +03:00
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsCSSValue::SetColorValue(nscolor aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Color;
|
|
|
|
mValue.mColor = aValue;
|
|
|
|
}
|
|
|
|
|
2005-04-02 03:07:00 +04:00
|
|
|
void nsCSSValue::SetArrayValue(nsCSSValue::Array* aValue, nsCSSUnit aUnit)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(eCSSUnit_Array <= aUnit && aUnit <= eCSSUnit_Counters,
|
|
|
|
"bad unit");
|
|
|
|
Reset();
|
|
|
|
mUnit = aUnit;
|
|
|
|
mValue.mArray = aValue;
|
|
|
|
mValue.mArray->AddRef();
|
|
|
|
}
|
|
|
|
|
2003-10-30 04:45:37 +03:00
|
|
|
void nsCSSValue::SetURLValue(nsCSSValue::URL* aValue)
|
2003-10-02 02:53:56 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_URL;
|
|
|
|
mValue.mURL = aValue;
|
2003-10-30 04:45:37 +03:00
|
|
|
mValue.mURL->AddRef();
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
void nsCSSValue::SetImageValue(nsCSSValue::Image* aValue)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Image;
|
|
|
|
mValue.mImage = aValue;
|
|
|
|
mValue.mImage->AddRef();
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetAutoValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Auto;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetInheritValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Inherit;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetInitialValue()
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Initial;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetNoneValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_None;
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
void nsCSSValue::SetNormalValue()
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
mUnit = eCSSUnit_Normal;
|
|
|
|
}
|
|
|
|
|
2004-08-04 07:23:37 +04:00
|
|
|
void nsCSSValue::StartImageLoad(nsIDocument* aDocument, PRBool aIsBGImage) const
|
2004-03-09 06:57:51 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(eCSSUnit_URL == mUnit, "Not a URL value!");
|
|
|
|
nsCSSValue::Image* image =
|
|
|
|
new nsCSSValue::Image(mValue.mURL->mURI,
|
|
|
|
mValue.mURL->mString,
|
2004-07-15 01:56:23 +04:00
|
|
|
mValue.mURL->mReferrer,
|
2004-08-04 07:23:37 +04:00
|
|
|
aDocument, aIsBGImage);
|
2004-03-09 06:57:51 +03:00
|
|
|
if (image) {
|
|
|
|
if (image->mString) {
|
|
|
|
nsCSSValue* writable = NS_CONST_CAST(nsCSSValue*, this);
|
|
|
|
writable->SetImageValue(image);
|
|
|
|
} else {
|
|
|
|
delete image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::Image::Image(nsIURI* aURI, const PRUnichar* aString,
|
2004-08-04 07:23:37 +04:00
|
|
|
nsIURI* aReferrer, nsIDocument* aDocument,
|
|
|
|
PRBool aIsBGImage)
|
2004-07-15 01:56:23 +04:00
|
|
|
: URL(aURI, aString, aReferrer)
|
2004-03-09 06:57:51 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSValue::Image);
|
|
|
|
|
|
|
|
// Check for failed mString allocation first
|
|
|
|
if (!mString)
|
|
|
|
return;
|
|
|
|
|
2005-07-16 01:19:04 +04:00
|
|
|
// If the pref is enabled, force all background image loads to
|
2004-08-04 07:23:37 +04:00
|
|
|
// complete before firing onload for the document. Otherwise, background
|
|
|
|
// image loads are special and don't block onload.
|
2005-07-16 01:19:04 +04:00
|
|
|
PRInt32 loadFlag = (PRInt32)nsIRequest::LOAD_NORMAL;
|
|
|
|
if (aIsBGImage) {
|
|
|
|
static PRBool onloadAfterImageBackgroundLoads =
|
|
|
|
nsContentUtils::GetBoolPref
|
|
|
|
("layout.fire_onload_after_image_background_loads");
|
|
|
|
if (!onloadAfterImageBackgroundLoads) {
|
|
|
|
loadFlag = (PRInt32)nsIRequest::LOAD_BACKGROUND;
|
|
|
|
}
|
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
|
|
|
|
if (mURI &&
|
2004-05-19 08:22:05 +04:00
|
|
|
nsContentUtils::CanLoadImage(mURI, aDocument, aDocument)) {
|
2004-07-15 01:56:23 +04:00
|
|
|
nsContentUtils::LoadImage(mURI, aDocument, aReferrer, nsnull,
|
2004-03-09 06:57:51 +03:00
|
|
|
loadFlag,
|
|
|
|
getter_AddRefs(mRequest));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSValue::Image::~Image()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSValue::Image);
|
|
|
|
}
|
|
|
|
|
2003-12-29 22:07:53 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
void nsCSSValue::AppendToString(nsAString& aBuffer,
|
2000-08-23 21:27:06 +04:00
|
|
|
nsCSSProperty aPropID) const
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
if (eCSSUnit_Null == mUnit) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (-1 < aPropID) {
|
2003-11-01 13:57:41 +03:00
|
|
|
AppendASCIItoUTF16(nsCSSProps::GetStringValue(aPropID), aBuffer);
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral(": ");
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
2004-03-09 06:57:51 +03:00
|
|
|
switch (mUnit) {
|
|
|
|
case eCSSUnit_Image:
|
2004-06-17 04:13:25 +04:00
|
|
|
case eCSSUnit_URL: aBuffer.AppendLiteral("url("); break;
|
|
|
|
case eCSSUnit_Attr: aBuffer.AppendLiteral("attr("); break;
|
|
|
|
case eCSSUnit_Counter: aBuffer.AppendLiteral("counter("); break;
|
|
|
|
case eCSSUnit_Counters: aBuffer.AppendLiteral("counters("); break;
|
2004-03-09 06:57:51 +03:00
|
|
|
default: break;
|
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Attr)) {
|
1998-10-08 05:29:29 +04:00
|
|
|
if (nsnull != mValue.mString) {
|
2000-08-23 21:27:06 +04:00
|
|
|
aBuffer.Append(PRUnichar('"'));
|
2000-06-06 13:36:12 +04:00
|
|
|
aBuffer.Append(mValue.mString);
|
2000-08-23 21:27:06 +04:00
|
|
|
aBuffer.Append(PRUnichar('"'));
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
else {
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral("null str");
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) {
|
2000-08-23 21:27:06 +04:00
|
|
|
nsAutoString intStr;
|
|
|
|
intStr.AppendInt(mValue.mInt, 10);
|
|
|
|
aBuffer.Append(intStr);
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral("[0x");
|
2000-08-23 21:27:06 +04:00
|
|
|
|
|
|
|
intStr.Truncate();
|
|
|
|
intStr.AppendInt(mValue.mInt, 16);
|
|
|
|
aBuffer.Append(intStr);
|
|
|
|
|
|
|
|
aBuffer.Append(PRUnichar(']'));
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2003-10-02 02:53:56 +04:00
|
|
|
else if (eCSSUnit_Color == mUnit) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral("(0x");
|
2000-08-23 21:27:06 +04:00
|
|
|
|
|
|
|
nsAutoString intStr;
|
|
|
|
intStr.AppendInt(NS_GET_R(mValue.mColor), 16);
|
|
|
|
aBuffer.Append(intStr);
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral(" 0x");
|
2000-08-23 21:27:06 +04:00
|
|
|
|
|
|
|
intStr.Truncate();
|
|
|
|
intStr.AppendInt(NS_GET_G(mValue.mColor), 16);
|
|
|
|
aBuffer.Append(intStr);
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral(" 0x");
|
2000-08-23 21:27:06 +04:00
|
|
|
|
|
|
|
intStr.Truncate();
|
|
|
|
intStr.AppendInt(NS_GET_B(mValue.mColor), 16);
|
|
|
|
aBuffer.Append(intStr);
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
aBuffer.AppendLiteral(" 0x");
|
2000-08-23 21:27:06 +04:00
|
|
|
|
|
|
|
intStr.Truncate();
|
|
|
|
intStr.AppendInt(NS_GET_A(mValue.mColor), 16);
|
|
|
|
aBuffer.Append(intStr);
|
|
|
|
|
|
|
|
aBuffer.Append(PRUnichar(')'));
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
2005-04-02 03:07:00 +04:00
|
|
|
else if (eCSSUnit_Array <= mUnit && mUnit <= eCSSUnit_Counters) {
|
|
|
|
for (PRUint16 i = 0, i_end = mValue.mArray->Count(); i != i_end; ++i) {
|
|
|
|
(*mValue.mArray)[i].AppendToString(aBuffer, aPropID);
|
|
|
|
}
|
|
|
|
}
|
2003-10-02 02:53:56 +04:00
|
|
|
else if (eCSSUnit_URL == mUnit) {
|
2003-10-30 04:45:37 +03:00
|
|
|
aBuffer.Append(mValue.mURL->mString);
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
2004-03-09 06:57:51 +03:00
|
|
|
else if (eCSSUnit_Image == mUnit) {
|
|
|
|
aBuffer.Append(mValue.mImage->mString);
|
|
|
|
}
|
1998-10-08 05:29:29 +04:00
|
|
|
else if (eCSSUnit_Percent == mUnit) {
|
2000-08-23 21:27:06 +04:00
|
|
|
nsAutoString floatString;
|
|
|
|
floatString.AppendFloat(mValue.mFloat * 100.0f);
|
|
|
|
aBuffer.Append(floatString);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
else if (eCSSUnit_Percent < mUnit) {
|
2000-08-23 21:27:06 +04:00
|
|
|
nsAutoString floatString;
|
|
|
|
floatString.AppendFloat(mValue.mFloat);
|
|
|
|
aBuffer.Append(floatString);
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (mUnit) {
|
1998-10-27 02:19:59 +03:00
|
|
|
case eCSSUnit_Null: break;
|
2004-06-17 04:13:25 +04:00
|
|
|
case eCSSUnit_Auto: aBuffer.AppendLiteral("auto"); break;
|
|
|
|
case eCSSUnit_Inherit: aBuffer.AppendLiteral("inherit"); break;
|
2004-12-05 01:10:07 +03:00
|
|
|
case eCSSUnit_Initial: aBuffer.AppendLiteral("-moz-initial"); break;
|
2004-06-17 04:13:25 +04:00
|
|
|
case eCSSUnit_None: aBuffer.AppendLiteral("none"); break;
|
|
|
|
case eCSSUnit_Normal: aBuffer.AppendLiteral("normal"); break;
|
2005-04-02 03:07:00 +04:00
|
|
|
case eCSSUnit_Array:
|
1998-10-27 02:19:59 +03:00
|
|
|
case eCSSUnit_String: break;
|
|
|
|
case eCSSUnit_URL:
|
2004-03-09 06:57:51 +03:00
|
|
|
case eCSSUnit_Image:
|
1998-10-27 02:19:59 +03:00
|
|
|
case eCSSUnit_Attr:
|
|
|
|
case eCSSUnit_Counter:
|
2000-08-23 21:27:06 +04:00
|
|
|
case eCSSUnit_Counters: aBuffer.Append(NS_LITERAL_STRING(")")); break;
|
2004-06-17 04:13:25 +04:00
|
|
|
case eCSSUnit_Integer: aBuffer.AppendLiteral("int"); break;
|
|
|
|
case eCSSUnit_Enumerated: aBuffer.AppendLiteral("enum"); break;
|
|
|
|
case eCSSUnit_Color: aBuffer.AppendLiteral("rbga"); break;
|
|
|
|
case eCSSUnit_Percent: aBuffer.AppendLiteral("%"); break;
|
|
|
|
case eCSSUnit_Number: aBuffer.AppendLiteral("#"); break;
|
|
|
|
case eCSSUnit_Inch: aBuffer.AppendLiteral("in"); break;
|
|
|
|
case eCSSUnit_Foot: aBuffer.AppendLiteral("ft"); break;
|
|
|
|
case eCSSUnit_Mile: aBuffer.AppendLiteral("mi"); break;
|
|
|
|
case eCSSUnit_Millimeter: aBuffer.AppendLiteral("mm"); break;
|
|
|
|
case eCSSUnit_Centimeter: aBuffer.AppendLiteral("cm"); break;
|
|
|
|
case eCSSUnit_Meter: aBuffer.AppendLiteral("m"); break;
|
|
|
|
case eCSSUnit_Kilometer: aBuffer.AppendLiteral("km"); break;
|
|
|
|
case eCSSUnit_Point: aBuffer.AppendLiteral("pt"); break;
|
|
|
|
case eCSSUnit_Pica: aBuffer.AppendLiteral("pc"); break;
|
|
|
|
case eCSSUnit_Didot: aBuffer.AppendLiteral("dt"); break;
|
|
|
|
case eCSSUnit_Cicero: aBuffer.AppendLiteral("cc"); break;
|
|
|
|
case eCSSUnit_EM: aBuffer.AppendLiteral("em"); break;
|
|
|
|
case eCSSUnit_EN: aBuffer.AppendLiteral("en"); break;
|
|
|
|
case eCSSUnit_XHeight: aBuffer.AppendLiteral("ex"); break;
|
|
|
|
case eCSSUnit_CapHeight: aBuffer.AppendLiteral("cap"); break;
|
|
|
|
case eCSSUnit_Char: aBuffer.AppendLiteral("ch"); break;
|
|
|
|
case eCSSUnit_Pixel: aBuffer.AppendLiteral("px"); break;
|
|
|
|
case eCSSUnit_Proportional: aBuffer.AppendLiteral("*"); break;
|
|
|
|
case eCSSUnit_Degree: aBuffer.AppendLiteral("deg"); break;
|
|
|
|
case eCSSUnit_Grad: aBuffer.AppendLiteral("grad"); break;
|
|
|
|
case eCSSUnit_Radian: aBuffer.AppendLiteral("rad"); break;
|
|
|
|
case eCSSUnit_Hertz: aBuffer.AppendLiteral("Hz"); break;
|
|
|
|
case eCSSUnit_Kilohertz: aBuffer.AppendLiteral("kHz"); break;
|
|
|
|
case eCSSUnit_Seconds: aBuffer.AppendLiteral("s"); break;
|
|
|
|
case eCSSUnit_Milliseconds: aBuffer.AppendLiteral("ms"); break;
|
|
|
|
}
|
|
|
|
aBuffer.AppendLiteral(" ");
|
1998-10-08 05:29:29 +04:00
|
|
|
}
|
|
|
|
|
2002-03-24 01:56:05 +03:00
|
|
|
void nsCSSValue::ToString(nsAString& aBuffer,
|
2000-08-23 21:27:06 +04:00
|
|
|
nsCSSProperty aPropID) const
|
1998-10-08 05:29:29 +04:00
|
|
|
{
|
|
|
|
aBuffer.Truncate();
|
|
|
|
AppendToString(aBuffer, aPropID);
|
|
|
|
}
|
2003-12-29 22:07:53 +03:00
|
|
|
|
|
|
|
#endif /* defined(DEBUG) */
|