Fixing nsbeta2+ bug 39892. Adding support for getting the computed value of the 'behavior' property with getComputedStyle(). r=hyatt

This commit is contained in:
jst%netscape.com 2000-06-14 00:06:36 +00:00
Родитель 2f8a7501aa
Коммит eb6d78edaf
9 изменённых файлов: 408 добавлений и 27 удалений

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

@ -75,6 +75,7 @@ private:
nsresult GetDisplay(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBehavior(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIContent> mContent;
nsString mPseudo;
@ -217,8 +218,18 @@ NS_IMETHODIMP
nsComputedDOMStyle::GetPropertyValue(const nsString& aPropertyName,
nsString& aReturn)
{
// TBI
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
nsCOMPtr<nsIDOMCSSValue> val;
aReturn.Truncate();
nsresult rv = GetPropertyCSSValue(aPropertyName, getter_AddRefs(val));
NS_ENSURE_SUCCESS(rv, rv);
if (val) {
rv = val->GetCssText(aReturn);
}
return rv;
}
@ -238,6 +249,8 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsString& aPropertyName,
nsCSSProperty prop = nsCSSProps::LookupProperty(aPropertyName);
switch (prop) {
case eCSSProperty_behavior :
rv = GetBehavior(frame, *getter_AddRefs(val)); break;
case eCSSProperty_display :
rv = GetDisplay(frame, *getter_AddRefs(val)); break;
case eCSSProperty_width :
@ -257,10 +270,10 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsString& aPropertyName,
}
if (val) {
val->QueryInterface(NS_GET_IID(nsIDOMCSSValue), (void **)aReturn);
rv = val->QueryInterface(NS_GET_IID(nsIDOMCSSValue), (void **)aReturn);
}
return NS_OK;
return rv;
}
@ -344,12 +357,48 @@ nsComputedDOMStyle::GetBackgroundRepeat(nsString& aBackgroundRepeat)
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
nsComputedDOMStyle::GetBehavior(nsString& aBehavior)
#endif
nsresult
nsComputedDOMStyle::GetBehavior(nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue)
{
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
nsISupports *tmp = NS_STATIC_CAST(nsIComputedDOMStyle *, this);
nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue(tmp, mT2P);
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
nsStyleUserInterface uiStyle;
const nsStyleUserInterface* ui = nsnull;
if (aFrame) {
aFrame->GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)ui);
} else {
nsCOMPtr<nsIPresContext> presCtx;
mPresShell->GetPresContext(getter_AddRefs(presCtx));
NS_ENSURE_TRUE(presCtx, NS_ERROR_FAILURE);
nsCOMPtr<nsIStyleContext> styleCtx;
presCtx->ResolveStyleContextFor(mContent, nsnull, PR_FALSE,
getter_AddRefs(styleCtx));
NS_ENSURE_TRUE(styleCtx, NS_ERROR_FAILURE);
styleCtx->GetStyle(eStyleStruct_UserInterface, uiStyle);
ui = &uiStyle;
}
if (ui) {
val->SetString(ui->mBehavior);
} else {
val->SetString("");
}
return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),
(void **)&aValue);
}
#if 0
NS_IMETHODIMP
nsComputedDOMStyle::GetBorder(nsString& aBorder)
{

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

@ -24,10 +24,12 @@
#include "nsCOMPtr.h"
#include "nsDOMError.h"
#include "prprf.h"
nsROCSSPrimitiveValue::nsROCSSPrimitiveValue(nsISupports *aOwner, float aT2P)
: mType(0), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P), mScriptObject(nsnull)
: mType(CSS_PX), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
@ -86,7 +88,77 @@ NS_IMETHODIMP
nsROCSSPrimitiveValue::GetCssText(nsString& aCssText)
{
aCssText.Truncate();
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
switch (mType) {
case CSS_PX :
{
PRInt32 px = NSTwipsToIntPixels(mTwips, mT2P);
aCssText.AppendInt(px);
aCssText.AppendWithConversion("px");
break;
}
case CSS_CM :
{
float val = NS_TWIPS_TO_CENTIMETERS(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("cm");
break;
}
case CSS_MM :
{
float val = NS_TWIPS_TO_MILLIMETERS(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("mm");
break;
}
case CSS_IN :
{
float val = NS_TWIPS_TO_INCHES(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("in");
break;
}
case CSS_PT :
{
float val = NSTwipsToFloatPoints(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("pt");
break;
}
case CSS_STRING :
{
aCssText.Append(mString);
break;
}
case CSS_PC :
case CSS_UNKNOWN :
case CSS_NUMBER :
case CSS_PERCENTAGE :
case CSS_EMS :
case CSS_EXS :
case CSS_DEG :
case CSS_RAD :
case CSS_GRAD :
case CSS_MS :
case CSS_S :
case CSS_HZ :
case CSS_KHZ :
case CSS_DIMENSION :
case CSS_URI :
case CSS_IDENT :
case CSS_ATTR :
case CSS_COUNTER :
case CSS_RECT :
case CSS_RGBCOLOR :
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
return NS_OK;
}

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

@ -63,6 +63,12 @@ public:
mType = CSS_STRING;
}
void SetString(const nsString& aString)
{
mString.Assign(aString);
mType = CSS_STRING;
}
private:
PRUint16 mType;

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

@ -75,6 +75,7 @@ private:
nsresult GetDisplay(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBehavior(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIContent> mContent;
nsString mPseudo;
@ -217,8 +218,18 @@ NS_IMETHODIMP
nsComputedDOMStyle::GetPropertyValue(const nsString& aPropertyName,
nsString& aReturn)
{
// TBI
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
nsCOMPtr<nsIDOMCSSValue> val;
aReturn.Truncate();
nsresult rv = GetPropertyCSSValue(aPropertyName, getter_AddRefs(val));
NS_ENSURE_SUCCESS(rv, rv);
if (val) {
rv = val->GetCssText(aReturn);
}
return rv;
}
@ -238,6 +249,8 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsString& aPropertyName,
nsCSSProperty prop = nsCSSProps::LookupProperty(aPropertyName);
switch (prop) {
case eCSSProperty_behavior :
rv = GetBehavior(frame, *getter_AddRefs(val)); break;
case eCSSProperty_display :
rv = GetDisplay(frame, *getter_AddRefs(val)); break;
case eCSSProperty_width :
@ -257,10 +270,10 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsString& aPropertyName,
}
if (val) {
val->QueryInterface(NS_GET_IID(nsIDOMCSSValue), (void **)aReturn);
rv = val->QueryInterface(NS_GET_IID(nsIDOMCSSValue), (void **)aReturn);
}
return NS_OK;
return rv;
}
@ -344,12 +357,48 @@ nsComputedDOMStyle::GetBackgroundRepeat(nsString& aBackgroundRepeat)
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
nsComputedDOMStyle::GetBehavior(nsString& aBehavior)
#endif
nsresult
nsComputedDOMStyle::GetBehavior(nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue)
{
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
nsISupports *tmp = NS_STATIC_CAST(nsIComputedDOMStyle *, this);
nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue(tmp, mT2P);
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
nsStyleUserInterface uiStyle;
const nsStyleUserInterface* ui = nsnull;
if (aFrame) {
aFrame->GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)ui);
} else {
nsCOMPtr<nsIPresContext> presCtx;
mPresShell->GetPresContext(getter_AddRefs(presCtx));
NS_ENSURE_TRUE(presCtx, NS_ERROR_FAILURE);
nsCOMPtr<nsIStyleContext> styleCtx;
presCtx->ResolveStyleContextFor(mContent, nsnull, PR_FALSE,
getter_AddRefs(styleCtx));
NS_ENSURE_TRUE(styleCtx, NS_ERROR_FAILURE);
styleCtx->GetStyle(eStyleStruct_UserInterface, uiStyle);
ui = &uiStyle;
}
if (ui) {
val->SetString(ui->mBehavior);
} else {
val->SetString("");
}
return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),
(void **)&aValue);
}
#if 0
NS_IMETHODIMP
nsComputedDOMStyle::GetBorder(nsString& aBorder)
{

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

@ -24,10 +24,12 @@
#include "nsCOMPtr.h"
#include "nsDOMError.h"
#include "prprf.h"
nsROCSSPrimitiveValue::nsROCSSPrimitiveValue(nsISupports *aOwner, float aT2P)
: mType(0), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P), mScriptObject(nsnull)
: mType(CSS_PX), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
@ -86,7 +88,77 @@ NS_IMETHODIMP
nsROCSSPrimitiveValue::GetCssText(nsString& aCssText)
{
aCssText.Truncate();
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
switch (mType) {
case CSS_PX :
{
PRInt32 px = NSTwipsToIntPixels(mTwips, mT2P);
aCssText.AppendInt(px);
aCssText.AppendWithConversion("px");
break;
}
case CSS_CM :
{
float val = NS_TWIPS_TO_CENTIMETERS(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("cm");
break;
}
case CSS_MM :
{
float val = NS_TWIPS_TO_MILLIMETERS(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("mm");
break;
}
case CSS_IN :
{
float val = NS_TWIPS_TO_INCHES(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("in");
break;
}
case CSS_PT :
{
float val = NSTwipsToFloatPoints(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("pt");
break;
}
case CSS_STRING :
{
aCssText.Append(mString);
break;
}
case CSS_PC :
case CSS_UNKNOWN :
case CSS_NUMBER :
case CSS_PERCENTAGE :
case CSS_EMS :
case CSS_EXS :
case CSS_DEG :
case CSS_RAD :
case CSS_GRAD :
case CSS_MS :
case CSS_S :
case CSS_HZ :
case CSS_KHZ :
case CSS_DIMENSION :
case CSS_URI :
case CSS_IDENT :
case CSS_ATTR :
case CSS_COUNTER :
case CSS_RECT :
case CSS_RGBCOLOR :
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
return NS_OK;
}

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

@ -63,6 +63,12 @@ public:
mType = CSS_STRING;
}
void SetString(const nsString& aString)
{
mString.Assign(aString);
mType = CSS_STRING;
}
private:
PRUint16 mType;

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

@ -75,6 +75,7 @@ private:
nsresult GetDisplay(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsresult GetBehavior(nsIFrame *aFrame, nsIDOMCSSPrimitiveValue*& aValue);
nsCOMPtr<nsIPresShell> mPresShell;
nsCOMPtr<nsIContent> mContent;
nsString mPseudo;
@ -217,8 +218,18 @@ NS_IMETHODIMP
nsComputedDOMStyle::GetPropertyValue(const nsString& aPropertyName,
nsString& aReturn)
{
// TBI
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
nsCOMPtr<nsIDOMCSSValue> val;
aReturn.Truncate();
nsresult rv = GetPropertyCSSValue(aPropertyName, getter_AddRefs(val));
NS_ENSURE_SUCCESS(rv, rv);
if (val) {
rv = val->GetCssText(aReturn);
}
return rv;
}
@ -238,6 +249,8 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsString& aPropertyName,
nsCSSProperty prop = nsCSSProps::LookupProperty(aPropertyName);
switch (prop) {
case eCSSProperty_behavior :
rv = GetBehavior(frame, *getter_AddRefs(val)); break;
case eCSSProperty_display :
rv = GetDisplay(frame, *getter_AddRefs(val)); break;
case eCSSProperty_width :
@ -257,10 +270,10 @@ nsComputedDOMStyle::GetPropertyCSSValue(const nsString& aPropertyName,
}
if (val) {
val->QueryInterface(NS_GET_IID(nsIDOMCSSValue), (void **)aReturn);
rv = val->QueryInterface(NS_GET_IID(nsIDOMCSSValue), (void **)aReturn);
}
return NS_OK;
return rv;
}
@ -344,12 +357,48 @@ nsComputedDOMStyle::GetBackgroundRepeat(nsString& aBackgroundRepeat)
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
nsComputedDOMStyle::GetBehavior(nsString& aBehavior)
#endif
nsresult
nsComputedDOMStyle::GetBehavior(nsIFrame *aFrame,
nsIDOMCSSPrimitiveValue*& aValue)
{
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
nsISupports *tmp = NS_STATIC_CAST(nsIComputedDOMStyle *, this);
nsROCSSPrimitiveValue *val = new nsROCSSPrimitiveValue(tmp, mT2P);
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
nsStyleUserInterface uiStyle;
const nsStyleUserInterface* ui = nsnull;
if (aFrame) {
aFrame->GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)ui);
} else {
nsCOMPtr<nsIPresContext> presCtx;
mPresShell->GetPresContext(getter_AddRefs(presCtx));
NS_ENSURE_TRUE(presCtx, NS_ERROR_FAILURE);
nsCOMPtr<nsIStyleContext> styleCtx;
presCtx->ResolveStyleContextFor(mContent, nsnull, PR_FALSE,
getter_AddRefs(styleCtx));
NS_ENSURE_TRUE(styleCtx, NS_ERROR_FAILURE);
styleCtx->GetStyle(eStyleStruct_UserInterface, uiStyle);
ui = &uiStyle;
}
if (ui) {
val->SetString(ui->mBehavior);
} else {
val->SetString("");
}
return val->QueryInterface(NS_GET_IID(nsIDOMCSSPrimitiveValue),
(void **)&aValue);
}
#if 0
NS_IMETHODIMP
nsComputedDOMStyle::GetBorder(nsString& aBorder)
{

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

@ -24,10 +24,12 @@
#include "nsCOMPtr.h"
#include "nsDOMError.h"
#include "prprf.h"
nsROCSSPrimitiveValue::nsROCSSPrimitiveValue(nsISupports *aOwner, float aT2P)
: mType(0), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P), mScriptObject(nsnull)
: mType(CSS_PX), mTwips(0), mString(), mOwner(aOwner), mT2P(aT2P),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
@ -86,7 +88,77 @@ NS_IMETHODIMP
nsROCSSPrimitiveValue::GetCssText(nsString& aCssText)
{
aCssText.Truncate();
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
switch (mType) {
case CSS_PX :
{
PRInt32 px = NSTwipsToIntPixels(mTwips, mT2P);
aCssText.AppendInt(px);
aCssText.AppendWithConversion("px");
break;
}
case CSS_CM :
{
float val = NS_TWIPS_TO_CENTIMETERS(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("cm");
break;
}
case CSS_MM :
{
float val = NS_TWIPS_TO_MILLIMETERS(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("mm");
break;
}
case CSS_IN :
{
float val = NS_TWIPS_TO_INCHES(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("in");
break;
}
case CSS_PT :
{
float val = NSTwipsToFloatPoints(mTwips);
char buf[64];
PR_snprintf(buf, 63, "%.2fcm", val);
aCssText.AppendWithConversion("pt");
break;
}
case CSS_STRING :
{
aCssText.Append(mString);
break;
}
case CSS_PC :
case CSS_UNKNOWN :
case CSS_NUMBER :
case CSS_PERCENTAGE :
case CSS_EMS :
case CSS_EXS :
case CSS_DEG :
case CSS_RAD :
case CSS_GRAD :
case CSS_MS :
case CSS_S :
case CSS_HZ :
case CSS_KHZ :
case CSS_DIMENSION :
case CSS_URI :
case CSS_IDENT :
case CSS_ATTR :
case CSS_COUNTER :
case CSS_RECT :
case CSS_RGBCOLOR :
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
}
return NS_OK;
}

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

@ -63,6 +63,12 @@ public:
mType = CSS_STRING;
}
void SetString(const nsString& aString)
{
mString.Assign(aString);
mType = CSS_STRING;
}
private:
PRUint16 mType;