Bug 119807, Computed color values should support getRGBColorValue(). r=bzbarsky, sr=jst, a=asa

This commit is contained in:
caillon%returnzero.com 2002-03-22 20:18:42 +00:00
Родитель 35ce4f899c
Коммит 6ced451a8d
17 изменённых файлов: 1397 добавлений и 747 удалений

Просмотреть файл

@ -68,6 +68,7 @@ CPPSRCS = \
nsInspectorCSSUtils.cpp \
nsROCSSPrimitiveValue.cpp \
nsDOMCSSRect.cpp \
nsDOMCSSRGBColor.cpp \
$(NULL)
EXPORTS = \

Просмотреть файл

@ -82,6 +82,7 @@ CPP_OBJS = \
.\$(OBJDIR)\nsInspectorCSSUtils.obj \
.\$(OBJDIR)\nsROCSSPrimitiveValue.obj \
.\$(OBJDIR)\nsDOMCSSRect.obj \
.\$(OBJDIR)\nsDOMCSSRGBColor.obj \
$(NULL)
LINCS= -I..\..\..\base\src \

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,253 @@
/* -*- 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:
* Christopher A. Aillon <christopher@aillon.com>
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher A. Aillon <christopher@aillon.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef nsComputedDOMStyle_h__
#define nsComputedDOMStyle_h__
#include "nsIComputedDOMStyle.h"
#include "nsROCSSPrimitiveValue.h"
#include "nsDOMCSSRGBColor.h"
#include "nsIPresShell.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsCOMPtr.h"
#include "nsWeakReference.h"
class nsComputedDOMStyle : public nsIComputedDOMStyle
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsIDOMElement *aElement,
const nsAReadableString& aPseudoElt,
nsIPresShell *aPresShell);
NS_DECL_NSIDOMCSSSTYLEDECLARATION
nsComputedDOMStyle();
virtual ~nsComputedDOMStyle();
private:
nsIFrame* GetContainingBlock(nsIFrame *aFrame);
nsresult GetStyleData(nsStyleStructID aID,
const nsStyleStruct*& aStyleStruct,
nsIFrame* aFrame=0);
nsresult GetOffsetWidthFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetAbsoluteOffset(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetRelativeOffset(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetStaticOffset(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingWidthFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nscoord GetPaddingWidthCoordFor(PRUint8 aSide,
nsIFrame *aFrame);
nsresult GetBorderStyleFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderWidthFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nscoord GetBorderWidthCoordFor(PRUint8 aSide,
nsIFrame *aFrame);
nsresult GetBorderColorFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginWidthFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nscoord GetMarginWidthCoordFor(PRUint8 aSide,
nsIFrame *aFrame);
nsresult GetLineHeightCoord(nsIFrame *aFrame,
const nsStyleText *aText,
nscoord& aCoord);
/* Properties Queryable as CSSValues */
nsresult GetWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetHeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMaxHeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMaxWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMinHeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMinWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetLeft(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTop(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetRight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBottom(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Font properties */
nsresult GetColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontFamily(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontSize(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontSizeAdjust(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontWeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontVariant(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Background properties */
nsresult GetBackgroundAttachment(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBackgroundColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBackgroundImage(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBackgroundRepeat(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Padding properties */
nsresult GetPadding(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingTop(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingBottom(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingLeft(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingRight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Table Properties */
nsresult GetBorderCollapse(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetCaptionSide(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetEmptyCells(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTableLayout(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetVerticalAlign(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Border Properties */
nsresult GetBorderStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderTopStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderBottomStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderLeftStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderRightStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderTopColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderBottomColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderLeftColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderRightColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Margin Properties */
nsresult GetMarginWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Outline Properties */
nsresult GetOutline(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetOutlineWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetOutlineStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetOutlineColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/*Marker Properties */
nsresult GetMarkerOffset(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* z-index */
nsresult GetZIndex(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* List properties */
nsresult GetListStyleImage(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetListStylePosition(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetListStyleType(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Text Properties */
nsresult GetLineHeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTextAlign(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTextDecoration(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTextIndent(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTextTransform(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetLetterSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetWordSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetWhiteSpace(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Visibility properties */
nsresult GetOpacity(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetVisibility(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Direction properties */
nsresult GetDirection(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetUnicodeBidi(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Display properties */
nsresult GetBinding(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetClear(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetCssFloat(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetDisplay(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPosition(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetClip(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetOverflow(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* User interface properties */
nsresult GetCursor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsROCSSPrimitiveValue* GetROCSSPrimitiveValue();
nsDOMCSSRGBColor* GetDOMCSSRGBColor(nscolor aColor);
nsWeakPtr mPresShellWeak;
nsCOMPtr<nsIContent> mContent;
/*
* When a frame is unavailable, strong reference to the
* style context while we're accessing the data from in.
*/
nsCOMPtr<nsIStyleContext> mStyleContextHolder;
nsCOMPtr<nsIAtom> mPseudo;
float mT2P; /* For unit conversions */
};
#endif /* nsComputedDOMStyle_h__ */

Просмотреть файл

@ -0,0 +1,93 @@
/* -*- 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:
* Christopher A. Aillon <christopher@aillon.com>
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher A. Aillon <christopher@aillon.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include "nsISupports.h"
#include "nsCOMPtr.h"
#include "nsIDOMCSSPrimitiveValue.h"
#include "nsDOMCSSRGBColor.h"
#include "nsContentUtils.h"
nsDOMCSSRGBColor::nsDOMCSSRGBColor(nsIDOMCSSPrimitiveValue* aRed,
nsIDOMCSSPrimitiveValue* aGreen,
nsIDOMCSSPrimitiveValue* aBlue)
: mRed(aRed), mGreen(aGreen), mBlue(aBlue)
{
NS_INIT_REFCNT();
}
nsDOMCSSRGBColor::~nsDOMCSSRGBColor(void)
{
}
NS_INTERFACE_MAP_BEGIN(nsDOMCSSRGBColor)
NS_INTERFACE_MAP_ENTRY(nsIDOMRGBColor)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSRGBColor)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMCSSRGBColor)
NS_IMPL_RELEASE(nsDOMCSSRGBColor)
NS_IMETHODIMP
nsDOMCSSRGBColor::GetRed(nsIDOMCSSPrimitiveValue** aRed)
{
NS_ENSURE_TRUE(mRed, NS_ERROR_NOT_INITIALIZED);
*aRed = mRed;
NS_ADDREF(*aRed);
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSRGBColor::GetGreen(nsIDOMCSSPrimitiveValue** aGreen)
{
NS_ENSURE_TRUE(mGreen, NS_ERROR_NOT_INITIALIZED);
*aGreen = mGreen;
NS_ADDREF(*aGreen);
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSRGBColor::GetBlue(nsIDOMCSSPrimitiveValue** aBlue)
{
NS_ENSURE_TRUE(mBlue, NS_ERROR_NOT_INITIALIZED);
*aBlue = mBlue;
NS_ADDREF(*aBlue);
return NS_OK;
}

Просмотреть файл

Просмотреть файл

@ -116,6 +116,7 @@ nsROCSSPrimitiveValue::GetCssText(nsAWritableString& aCssText)
tmpStr.Append(NS_LITERAL_STRING("pt"));
break;
}
case CSS_IDENT :
case CSS_STRING :
{
tmpStr.Append(mValue.mString);
@ -178,6 +179,43 @@ nsROCSSPrimitiveValue::GetCssText(nsAWritableString& aCssText)
if (NS_FAILED(result))
break;
tmpStr.Append(sideValue + NS_LITERAL_STRING(")"));
break;
}
case CSS_RGBCOLOR :
{
NS_ASSERTION(mValue.mColor, "mValue.mColor should never be null");
NS_NAMED_LITERAL_STRING(comma, ", ");
nsCOMPtr<nsIDOMCSSPrimitiveValue> colorCSSValue;
nsAutoString colorValue;
tmpStr = NS_LITERAL_STRING("rgb(");
// get the red component
result = mValue.mColor->GetRed(getter_AddRefs(colorCSSValue));
if (NS_FAILED(result))
break;
result = colorCSSValue->GetCssText(colorValue);
if (NS_FAILED(result))
break;
tmpStr.Append(colorValue + comma);
// get the green component
result = mValue.mColor->GetGreen(getter_AddRefs(colorCSSValue));
if (NS_FAILED(result))
break;
result = colorCSSValue->GetCssText(colorValue);
if (NS_FAILED(result))
break;
tmpStr.Append(colorValue + comma);
// get the blue component
result = mValue.mColor->GetBlue(getter_AddRefs(colorCSSValue));
if (NS_FAILED(result))
break;
result = colorCSSValue->GetCssText(colorValue);
if (NS_FAILED(result))
break;
tmpStr.Append(colorValue + NS_LITERAL_STRING(")"));
break;
}
case CSS_PC :
@ -192,10 +230,8 @@ nsROCSSPrimitiveValue::GetCssText(nsAWritableString& aCssText)
case CSS_HZ :
case CSS_KHZ :
case CSS_DIMENSION :
case CSS_IDENT :
case CSS_ATTR :
case CSS_COUNTER :
case CSS_RGBCOLOR :
NS_ERROR("We have a bogus value set. This should not happen");
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
@ -275,6 +311,11 @@ nsROCSSPrimitiveValue::GetFloatValue(PRUint16 aUnitType, float* aReturn)
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
*aReturn = NSTwipsToFloatPoints(mValue.mTwips);
break;
case CSS_PC :
if (mType != CSS_PX)
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
*aReturn = NS_TWIPS_TO_PICAS(mValue.mTwips);
break;
case CSS_PERCENTAGE :
if (mType != CSS_PERCENTAGE)
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
@ -285,7 +326,6 @@ nsROCSSPrimitiveValue::GetFloatValue(PRUint16 aUnitType, float* aReturn)
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
*aReturn = mValue.mFloat;
break;
case CSS_PC :
case CSS_UNKNOWN :
case CSS_EMS :
case CSS_EXS :
@ -323,6 +363,7 @@ NS_IMETHODIMP
nsROCSSPrimitiveValue::GetStringValue(nsAWritableString& aReturn)
{
switch (mType) {
case CSS_IDENT:
case CSS_STRING:
aReturn.Assign(mValue.mString);
break;
@ -331,7 +372,6 @@ nsROCSSPrimitiveValue::GetStringValue(nsAWritableString& aReturn)
nsDependentString(mValue.mString) +
NS_LITERAL_STRING(")"));
break;
case CSS_IDENT:
case CSS_ATTR:
default:
aReturn.Truncate();
@ -364,6 +404,11 @@ nsROCSSPrimitiveValue::GetRectValue(nsIDOMRect** aReturn)
NS_IMETHODIMP
nsROCSSPrimitiveValue::GetRGBColorValue(nsIDOMRGBColor** aReturn)
{
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
if (mType != CSS_RGBCOLOR) {
*aReturn = nsnull;
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
NS_ASSERTION(mValue.mColor, "mValue.mColor should never be null");
return CallQueryInterface(mValue.mColor, aReturn);
}

Просмотреть файл

@ -48,6 +48,7 @@
#include "nsCOMPtr.h"
#include "nsDOMError.h"
#include "nsDOMCSSRect.h"
#include "nsDOMCSSRGBColor.h"
class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue
{
@ -85,32 +86,60 @@ public:
mType = CSS_PX;
}
void SetIdent(const nsACString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = (mValue.mString != nsnull) ? CSS_IDENT : CSS_UNKNOWN;
}
void SetIdent(const nsAString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = (mValue.mString != nsnull) ? CSS_IDENT : CSS_UNKNOWN;
}
void SetString(const nsACString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = CSS_STRING;
mType = (mValue.mString != nsnull) ? CSS_STRING : CSS_UNKNOWN;
}
void SetString(const nsAString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = CSS_STRING;
mType = (mValue.mString != nsnull) ? CSS_STRING : CSS_UNKNOWN;
}
void SetURI(const nsACString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = CSS_URI;
mType = (mValue.mString != nsnull) ? CSS_URI : CSS_UNKNOWN;
}
void SetURI(const nsAString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = CSS_URI;
mType = (mValue.mString != nsnull) ? CSS_URI : CSS_UNKNOWN;
}
void SetColor(nsIDOMRGBColor* aColor)
{
NS_PRECONDITION(aColor, "Null RGBColor being set!");
Reset();
mValue.mColor = aColor;
if (mValue.mColor) {
NS_ADDREF(mValue.mColor);
mType = CSS_RGBCOLOR;
}
else {
mType = CSS_UNKNOWN;
}
}
void SetRect(nsIDOMRect* aRect)
@ -118,21 +147,35 @@ public:
NS_PRECONDITION(aRect, "Null rect being set!");
Reset();
mValue.mRect = aRect;
NS_ADDREF(mValue.mRect);
mType = CSS_RECT;
if (mValue.mRect) {
NS_ADDREF(mValue.mRect);
mType = CSS_RECT;
}
else {
mType = CSS_UNKNOWN;
}
}
void Reset(void)
{
if (mType == CSS_STRING || mType == CSS_URI) {
NS_ASSERTION(mValue.mString, "Null string should never happen");
nsMemory::Free(mValue.mString);
mValue.mString = nsnull;
}
else if (mType == CSS_RECT) {
NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
NS_RELEASE(mValue.mRect);
mValue.mRect = nsnull;
switch (mType) {
case CSS_IDENT:
case CSS_STRING:
case CSS_URI:
NS_ASSERTION(mValue.mString, "Null string should never happen");
nsMemory::Free(mValue.mString);
mValue.mString = nsnull;
break;
case CSS_RECT:
NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
NS_RELEASE(mValue.mRect);
mValue.mRect = nsnull;
break;
case CSS_RGBCOLOR:
NS_ASSERTION(mValue.mColor, "Null RGBColor should never happen");
NS_RELEASE(mValue.mColor);
mValue.mColor = nsnull;
break;
}
}
@ -140,10 +183,11 @@ private:
PRUint16 mType;
union {
nscoord mTwips;
float mFloat;
nsIDOMRect* mRect;
PRUnichar* mString;
nscoord mTwips;
float mFloat;
nsIDOMRGBColor* mColor;
nsIDOMRect* mRect;
PRUnichar* mString;
} mValue;
nsISupports *mOwner;

Просмотреть файл

@ -2429,6 +2429,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsDOMCSSRGBColor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@ -3516,6 +3523,11 @@
<PATH>nsWyciwygProtocolHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsDOMCSSRGBColor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
<TARGET>
@ -5894,6 +5906,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsDOMCSSRGBColor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
</FILELIST>
<LINKORDER>
<FILEREF>
@ -6981,6 +7000,11 @@
<PATH>nsWyciwygProtocolHandler.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsDOMCSSRGBColor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</LINKORDER>
</TARGET>
</TARGETLIST>
@ -7776,6 +7800,12 @@
<PATH>nsROCSSPrimitiveValue.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>content.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsDOMCSSRGBColor.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>xbl</NAME>
<FILEREF>

Просмотреть файл

@ -242,11 +242,16 @@ enum nsDOMClassInfoID {
// We are now trying to preserve binary compat in classinfo. No
// more putting things in those categories up there. New entries
// are to be added right before eDOMClassInfoIDCount
// Rect object used by getComputedStyle
eDOMClassInfo_CSSRect_id,
// DOM Chrome Window class, almost identical to Window
eDOMClassInfo_ChromeWindow_id,
// RGBColor object used by getComputedStyle
eDOMClassInfo_CSSRGBColor_id,
// This one better be the last one in this list
eDOMClassInfoIDCount
};

Просмотреть файл

@ -143,6 +143,7 @@
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSRuleList.h"
#include "nsIDOMRect.h"
#include "nsIDOMRGBColor.h"
// XBL related includes.
#include "nsIXBLService.h"
@ -767,6 +768,10 @@ static nsDOMClassInfoData sClassInfoData[] = {
nsIXPCScriptable::WANT_DELPROPERTY |
nsIXPCScriptable::WANT_ENUMERATE |
nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE)
NS_DEFINE_CLASSINFO_DATA(CSSRGBColor, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
};
nsIXPConnect *nsDOMClassInfo::sXPConnect = nsnull;
@ -1726,6 +1731,10 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMRect)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(CSSRGBColor, nsIDOMRGBColor)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMRGBColor)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Range, nsIDOMRange)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMRange)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSRange)

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,253 @@
/* -*- 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:
* Christopher A. Aillon <christopher@aillon.com>
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher A. Aillon <christopher@aillon.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef nsComputedDOMStyle_h__
#define nsComputedDOMStyle_h__
#include "nsIComputedDOMStyle.h"
#include "nsROCSSPrimitiveValue.h"
#include "nsDOMCSSRGBColor.h"
#include "nsIPresShell.h"
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsCOMPtr.h"
#include "nsWeakReference.h"
class nsComputedDOMStyle : public nsIComputedDOMStyle
{
public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init(nsIDOMElement *aElement,
const nsAReadableString& aPseudoElt,
nsIPresShell *aPresShell);
NS_DECL_NSIDOMCSSSTYLEDECLARATION
nsComputedDOMStyle();
virtual ~nsComputedDOMStyle();
private:
nsIFrame* GetContainingBlock(nsIFrame *aFrame);
nsresult GetStyleData(nsStyleStructID aID,
const nsStyleStruct*& aStyleStruct,
nsIFrame* aFrame=0);
nsresult GetOffsetWidthFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetAbsoluteOffset(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetRelativeOffset(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetStaticOffset(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingWidthFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nscoord GetPaddingWidthCoordFor(PRUint8 aSide,
nsIFrame *aFrame);
nsresult GetBorderStyleFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderWidthFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nscoord GetBorderWidthCoordFor(PRUint8 aSide,
nsIFrame *aFrame);
nsresult GetBorderColorFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginWidthFor(PRUint8 aSide,
nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue);
nscoord GetMarginWidthCoordFor(PRUint8 aSide,
nsIFrame *aFrame);
nsresult GetLineHeightCoord(nsIFrame *aFrame,
const nsStyleText *aText,
nscoord& aCoord);
/* Properties Queryable as CSSValues */
nsresult GetWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetHeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMaxHeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMaxWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMinHeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMinWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetLeft(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTop(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetRight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBottom(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Font properties */
nsresult GetColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontFamily(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontSize(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontSizeAdjust(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontWeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetFontVariant(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Background properties */
nsresult GetBackgroundAttachment(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBackgroundColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBackgroundImage(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBackgroundRepeat(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Padding properties */
nsresult GetPadding(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingTop(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingBottom(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingLeft(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPaddingRight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Table Properties */
nsresult GetBorderCollapse(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetCaptionSide(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetEmptyCells(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTableLayout(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetVerticalAlign(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Border Properties */
nsresult GetBorderStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderTopStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderBottomStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderLeftStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderRightStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderTopColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderBottomColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderLeftColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBorderRightColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Margin Properties */
nsresult GetMarginWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginTopWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginBottomWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginLeftWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetMarginRightWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Outline Properties */
nsresult GetOutline(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetOutlineWidth(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetOutlineStyle(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetOutlineColor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/*Marker Properties */
nsresult GetMarkerOffset(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* z-index */
nsresult GetZIndex(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* List properties */
nsresult GetListStyleImage(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetListStylePosition(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetListStyleType(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Text Properties */
nsresult GetLineHeight(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTextAlign(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTextDecoration(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTextIndent(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetTextTransform(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetLetterSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetWordSpacing(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetWhiteSpace(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Visibility properties */
nsresult GetOpacity(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetVisibility(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Direction properties */
nsresult GetDirection(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetUnicodeBidi(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* Display properties */
nsresult GetBinding(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetClear(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetCssFloat(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetDisplay(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetPosition(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetClip(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetOverflow(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
/* User interface properties */
nsresult GetCursor(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsROCSSPrimitiveValue* GetROCSSPrimitiveValue();
nsDOMCSSRGBColor* GetDOMCSSRGBColor(nscolor aColor);
nsWeakPtr mPresShellWeak;
nsCOMPtr<nsIContent> mContent;
/*
* When a frame is unavailable, strong reference to the
* style context while we're accessing the data from in.
*/
nsCOMPtr<nsIStyleContext> mStyleContextHolder;
nsCOMPtr<nsIAtom> mPseudo;
float mT2P; /* For unit conversions */
};
#endif /* nsComputedDOMStyle_h__ */

Просмотреть файл

@ -0,0 +1,93 @@
/* -*- 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:
* Christopher A. Aillon <christopher@aillon.com>
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher A. Aillon <christopher@aillon.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#include "nsISupports.h"
#include "nsCOMPtr.h"
#include "nsIDOMCSSPrimitiveValue.h"
#include "nsDOMCSSRGBColor.h"
#include "nsContentUtils.h"
nsDOMCSSRGBColor::nsDOMCSSRGBColor(nsIDOMCSSPrimitiveValue* aRed,
nsIDOMCSSPrimitiveValue* aGreen,
nsIDOMCSSPrimitiveValue* aBlue)
: mRed(aRed), mGreen(aGreen), mBlue(aBlue)
{
NS_INIT_REFCNT();
}
nsDOMCSSRGBColor::~nsDOMCSSRGBColor(void)
{
}
NS_INTERFACE_MAP_BEGIN(nsDOMCSSRGBColor)
NS_INTERFACE_MAP_ENTRY(nsIDOMRGBColor)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSRGBColor)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMCSSRGBColor)
NS_IMPL_RELEASE(nsDOMCSSRGBColor)
NS_IMETHODIMP
nsDOMCSSRGBColor::GetRed(nsIDOMCSSPrimitiveValue** aRed)
{
NS_ENSURE_TRUE(mRed, NS_ERROR_NOT_INITIALIZED);
*aRed = mRed;
NS_ADDREF(*aRed);
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSRGBColor::GetGreen(nsIDOMCSSPrimitiveValue** aGreen)
{
NS_ENSURE_TRUE(mGreen, NS_ERROR_NOT_INITIALIZED);
*aGreen = mGreen;
NS_ADDREF(*aGreen);
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSRGBColor::GetBlue(nsIDOMCSSPrimitiveValue** aBlue)
{
NS_ENSURE_TRUE(mBlue, NS_ERROR_NOT_INITIALIZED);
*aBlue = mBlue;
NS_ADDREF(*aBlue);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,66 @@
/* -*- 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:
* Christopher A. Aillon <christopher@aillon.com>
*
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Christopher A. Aillon <christopher@aillon.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef nsDOMCSSRGBColor_h__
#define nsDOMCSSRGBColor_h__
#include "nsISupports.h"
#include "nsIDOMRGBColor.h"
#include "nsCOMPtr.h"
class nsIDOMCSSPrimitiveValue;
class nsDOMCSSRGBColor : public nsIDOMRGBColor {
public:
nsDOMCSSRGBColor(nsIDOMCSSPrimitiveValue* aRed,
nsIDOMCSSPrimitiveValue* aGreen,
nsIDOMCSSPrimitiveValue* aBlue);
virtual ~nsDOMCSSRGBColor(void);
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMRGBCOLOR
private:
nsCOMPtr<nsIDOMCSSPrimitiveValue> mRed;
nsCOMPtr<nsIDOMCSSPrimitiveValue> mGreen;
nsCOMPtr<nsIDOMCSSPrimitiveValue> mBlue;
};
#endif // nsDOMCSSRGBColor_h__

Просмотреть файл

@ -116,6 +116,7 @@ nsROCSSPrimitiveValue::GetCssText(nsAWritableString& aCssText)
tmpStr.Append(NS_LITERAL_STRING("pt"));
break;
}
case CSS_IDENT :
case CSS_STRING :
{
tmpStr.Append(mValue.mString);
@ -178,6 +179,43 @@ nsROCSSPrimitiveValue::GetCssText(nsAWritableString& aCssText)
if (NS_FAILED(result))
break;
tmpStr.Append(sideValue + NS_LITERAL_STRING(")"));
break;
}
case CSS_RGBCOLOR :
{
NS_ASSERTION(mValue.mColor, "mValue.mColor should never be null");
NS_NAMED_LITERAL_STRING(comma, ", ");
nsCOMPtr<nsIDOMCSSPrimitiveValue> colorCSSValue;
nsAutoString colorValue;
tmpStr = NS_LITERAL_STRING("rgb(");
// get the red component
result = mValue.mColor->GetRed(getter_AddRefs(colorCSSValue));
if (NS_FAILED(result))
break;
result = colorCSSValue->GetCssText(colorValue);
if (NS_FAILED(result))
break;
tmpStr.Append(colorValue + comma);
// get the green component
result = mValue.mColor->GetGreen(getter_AddRefs(colorCSSValue));
if (NS_FAILED(result))
break;
result = colorCSSValue->GetCssText(colorValue);
if (NS_FAILED(result))
break;
tmpStr.Append(colorValue + comma);
// get the blue component
result = mValue.mColor->GetBlue(getter_AddRefs(colorCSSValue));
if (NS_FAILED(result))
break;
result = colorCSSValue->GetCssText(colorValue);
if (NS_FAILED(result))
break;
tmpStr.Append(colorValue + NS_LITERAL_STRING(")"));
break;
}
case CSS_PC :
@ -192,10 +230,8 @@ nsROCSSPrimitiveValue::GetCssText(nsAWritableString& aCssText)
case CSS_HZ :
case CSS_KHZ :
case CSS_DIMENSION :
case CSS_IDENT :
case CSS_ATTR :
case CSS_COUNTER :
case CSS_RGBCOLOR :
NS_ERROR("We have a bogus value set. This should not happen");
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
@ -275,6 +311,11 @@ nsROCSSPrimitiveValue::GetFloatValue(PRUint16 aUnitType, float* aReturn)
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
*aReturn = NSTwipsToFloatPoints(mValue.mTwips);
break;
case CSS_PC :
if (mType != CSS_PX)
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
*aReturn = NS_TWIPS_TO_PICAS(mValue.mTwips);
break;
case CSS_PERCENTAGE :
if (mType != CSS_PERCENTAGE)
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
@ -285,7 +326,6 @@ nsROCSSPrimitiveValue::GetFloatValue(PRUint16 aUnitType, float* aReturn)
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
*aReturn = mValue.mFloat;
break;
case CSS_PC :
case CSS_UNKNOWN :
case CSS_EMS :
case CSS_EXS :
@ -323,6 +363,7 @@ NS_IMETHODIMP
nsROCSSPrimitiveValue::GetStringValue(nsAWritableString& aReturn)
{
switch (mType) {
case CSS_IDENT:
case CSS_STRING:
aReturn.Assign(mValue.mString);
break;
@ -331,7 +372,6 @@ nsROCSSPrimitiveValue::GetStringValue(nsAWritableString& aReturn)
nsDependentString(mValue.mString) +
NS_LITERAL_STRING(")"));
break;
case CSS_IDENT:
case CSS_ATTR:
default:
aReturn.Truncate();
@ -364,6 +404,11 @@ nsROCSSPrimitiveValue::GetRectValue(nsIDOMRect** aReturn)
NS_IMETHODIMP
nsROCSSPrimitiveValue::GetRGBColorValue(nsIDOMRGBColor** aReturn)
{
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
if (mType != CSS_RGBCOLOR) {
*aReturn = nsnull;
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
NS_ASSERTION(mValue.mColor, "mValue.mColor should never be null");
return CallQueryInterface(mValue.mColor, aReturn);
}

Просмотреть файл

@ -48,6 +48,7 @@
#include "nsCOMPtr.h"
#include "nsDOMError.h"
#include "nsDOMCSSRect.h"
#include "nsDOMCSSRGBColor.h"
class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue
{
@ -85,32 +86,60 @@ public:
mType = CSS_PX;
}
void SetIdent(const nsACString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = (mValue.mString != nsnull) ? CSS_IDENT : CSS_UNKNOWN;
}
void SetIdent(const nsAString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = (mValue.mString != nsnull) ? CSS_IDENT : CSS_UNKNOWN;
}
void SetString(const nsACString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = CSS_STRING;
mType = (mValue.mString != nsnull) ? CSS_STRING : CSS_UNKNOWN;
}
void SetString(const nsAString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = CSS_STRING;
mType = (mValue.mString != nsnull) ? CSS_STRING : CSS_UNKNOWN;
}
void SetURI(const nsACString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = CSS_URI;
mType = (mValue.mString != nsnull) ? CSS_URI : CSS_UNKNOWN;
}
void SetURI(const nsAString& aString)
{
Reset();
mValue.mString = ToNewUnicode(aString);
mType = CSS_URI;
mType = (mValue.mString != nsnull) ? CSS_URI : CSS_UNKNOWN;
}
void SetColor(nsIDOMRGBColor* aColor)
{
NS_PRECONDITION(aColor, "Null RGBColor being set!");
Reset();
mValue.mColor = aColor;
if (mValue.mColor) {
NS_ADDREF(mValue.mColor);
mType = CSS_RGBCOLOR;
}
else {
mType = CSS_UNKNOWN;
}
}
void SetRect(nsIDOMRect* aRect)
@ -118,21 +147,35 @@ public:
NS_PRECONDITION(aRect, "Null rect being set!");
Reset();
mValue.mRect = aRect;
NS_ADDREF(mValue.mRect);
mType = CSS_RECT;
if (mValue.mRect) {
NS_ADDREF(mValue.mRect);
mType = CSS_RECT;
}
else {
mType = CSS_UNKNOWN;
}
}
void Reset(void)
{
if (mType == CSS_STRING || mType == CSS_URI) {
NS_ASSERTION(mValue.mString, "Null string should never happen");
nsMemory::Free(mValue.mString);
mValue.mString = nsnull;
}
else if (mType == CSS_RECT) {
NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
NS_RELEASE(mValue.mRect);
mValue.mRect = nsnull;
switch (mType) {
case CSS_IDENT:
case CSS_STRING:
case CSS_URI:
NS_ASSERTION(mValue.mString, "Null string should never happen");
nsMemory::Free(mValue.mString);
mValue.mString = nsnull;
break;
case CSS_RECT:
NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
NS_RELEASE(mValue.mRect);
mValue.mRect = nsnull;
break;
case CSS_RGBCOLOR:
NS_ASSERTION(mValue.mColor, "Null RGBColor should never happen");
NS_RELEASE(mValue.mColor);
mValue.mColor = nsnull;
break;
}
}
@ -140,10 +183,11 @@ private:
PRUint16 mType;
union {
nscoord mTwips;
float mFloat;
nsIDOMRect* mRect;
PRUnichar* mString;
nscoord mTwips;
float mFloat;
nsIDOMRGBColor* mColor;
nsIDOMRect* mRect;
PRUnichar* mString;
} mValue;
nsISupports *mOwner;