Bug 454376 add -lCrun -lCstd for Solaris OS_LIBS, r=bsmedberg
[wine-gecko.git] / layout / style / nsComputedDOMStyle.cpp
blob1d307ed75064ee9330536c85cb9df2bb52fa906a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Daniel Glazman <glazman@netscape.com>
24 * Boris Zbarsky <bzbarsky@mit.edu>
25 * Christopher A. Aillon <christopher@aillon.com>
26 * Mats Palmgren <mats.palmgren@bredband.net>
27 * Christian Biesinger <cbiesinger@web.de>
28 * Michael Ventnor <m.ventnor@gmail.com>
30 * Alternatively, the contents of this file may be used under the terms of
31 * either of the GNU General Public License Version 2 or later (the "GPL"),
32 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
33 * in which case the provisions of the GPL or the LGPL are applicable instead
34 * of those above. If you wish to allow use of your version of this file only
35 * under the terms of either the GPL or the LGPL, and not to allow others to
36 * use your version of this file under the terms of the MPL, indicate your
37 * decision by deleting the provisions above and replace them with the notice
38 * and other provisions required by the GPL or the LGPL. If you do not delete
39 * the provisions above, a recipient may use your version of this file under
40 * the terms of any one of the MPL, the GPL or the LGPL.
42 * ***** END LICENSE BLOCK ***** */
44 /* DOM object returned from element.getComputedStyle() */
46 #include "nsComputedDOMStyle.h"
48 #include "nsDOMError.h"
49 #include "nsDOMString.h"
50 #include "nsIDOMCSS2Properties.h"
51 #include "nsIDOMElement.h"
52 #include "nsIDOMCSSPrimitiveValue.h"
53 #include "nsStyleContext.h"
54 #include "nsIScrollableFrame.h"
55 #include "nsContentUtils.h"
56 #include "prprf.h"
58 #include "nsCSSProps.h"
59 #include "nsCSSKeywords.h"
60 #include "nsDOMCSSRect.h"
61 #include "nsGkAtoms.h"
62 #include "nsHTMLReflowState.h"
63 #include "nsThemeConstants.h"
64 #include "nsStyleUtil.h"
65 #include "nsStyleStructInlines.h"
67 #include "nsPresContext.h"
68 #include "nsIDocument.h"
70 #include "nsCSSPseudoElements.h"
71 #include "nsStyleSet.h"
72 #include "imgIRequest.h"
73 #include "nsInspectorCSSUtils.h"
74 #include "nsLayoutUtils.h"
75 #include "nsFrameManager.h"
76 #include "nsCSSKeywords.h"
77 #include "nsStyleCoord.h"
78 #include "nsDisplayList.h"
80 #if defined(DEBUG_bzbarsky) || defined(DEBUG_caillon)
81 #define DEBUG_ComputedDOMStyle
82 #endif
85 * This is the implementation of the readonly CSSStyleDeclaration that is
86 * returned by the getComputedStyle() function.
89 static nsComputedDOMStyle *sCachedComputedDOMStyle;
91 nsresult
92 NS_NewComputedDOMStyle(nsIComputedDOMStyle** aComputedStyle)
94 NS_ENSURE_ARG_POINTER(aComputedStyle);
96 if (sCachedComputedDOMStyle) {
97 // There's an unused nsComputedDOMStyle cached, use it.
98 // But before we use it, re-initialize the object.
100 // Oh yeah baby, placement new!
101 *aComputedStyle = new (sCachedComputedDOMStyle) nsComputedDOMStyle();
103 sCachedComputedDOMStyle = nsnull;
104 } else {
105 // No nsComputedDOMStyle cached, create a new one.
107 *aComputedStyle = new nsComputedDOMStyle();
108 NS_ENSURE_TRUE(*aComputedStyle, NS_ERROR_OUT_OF_MEMORY);
111 NS_ADDREF(*aComputedStyle);
113 return NS_OK;
116 static nsIFrame*
117 GetContainingBlockFor(nsIFrame* aFrame) {
118 if (!aFrame) {
119 return nsnull;
121 return nsHTMLReflowState::GetContainingBlockFor(aFrame);
124 nsComputedDOMStyle::nsComputedDOMStyle()
125 : mInner(this), mDocumentWeak(nsnull), mOuterFrame(nsnull),
126 mInnerFrame(nsnull), mPresShell(nsnull), mAppUnitsPerInch(0)
131 nsComputedDOMStyle::~nsComputedDOMStyle()
135 void
136 nsComputedDOMStyle::Shutdown()
138 // We want to de-allocate without calling the dtor since we
139 // already did that manually in doDestroyComputedDOMStyle(),
140 // so cast our cached object to something that doesn't know
141 // about our dtor.
142 delete reinterpret_cast<char*>(sCachedComputedDOMStyle);
143 sCachedComputedDOMStyle = nsnull;
147 // QueryInterface implementation for nsComputedDOMStyle
148 NS_INTERFACE_MAP_BEGIN(nsComputedDOMStyle)
149 NS_INTERFACE_MAP_ENTRY(nsIComputedDOMStyle)
150 NS_INTERFACE_MAP_ENTRY(nsICSSDeclaration)
151 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration)
152 NS_INTERFACE_MAP_ENTRY_AGGREGATED(nsIDOMCSS2Properties, &mInner)
153 NS_INTERFACE_MAP_ENTRY_AGGREGATED(nsIDOMNSCSS2Properties, &mInner)
154 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIComputedDOMStyle)
155 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(ComputedCSSStyleDeclaration)
156 NS_INTERFACE_MAP_END
159 static void doDestroyComputedDOMStyle(nsComputedDOMStyle *aComputedStyle)
161 if (!sCachedComputedDOMStyle) {
162 // The cache is empty, store aComputedStyle in the cache.
164 sCachedComputedDOMStyle = aComputedStyle;
165 sCachedComputedDOMStyle->~nsComputedDOMStyle();
166 } else {
167 // The cache is full, delete aComputedStyle
169 delete aComputedStyle;
173 NS_IMPL_ADDREF(nsComputedDOMStyle)
174 NS_IMPL_RELEASE_WITH_DESTROY(nsComputedDOMStyle,
175 doDestroyComputedDOMStyle(this))
178 NS_IMETHODIMP
179 nsComputedDOMStyle::Init(nsIDOMElement *aElement,
180 const nsAString& aPseudoElt,
181 nsIPresShell *aPresShell)
183 NS_ENSURE_ARG_POINTER(aElement);
184 NS_ENSURE_ARG_POINTER(aPresShell);
186 mDocumentWeak = do_GetWeakReference(aPresShell->GetDocument());
188 mContent = do_QueryInterface(aElement);
189 if (!mContent) {
190 // This should not happen, all our elements support nsIContent!
192 return NS_ERROR_FAILURE;
195 if (!DOMStringIsNull(aPseudoElt) && !aPseudoElt.IsEmpty() &&
196 aPseudoElt.First() == PRUnichar(':')) {
197 // deal with two-colon forms of aPseudoElt
198 nsAString::const_iterator start, end;
199 aPseudoElt.BeginReading(start);
200 aPseudoElt.EndReading(end);
201 NS_ASSERTION(start != end, "aPseudoElt is not empty!");
202 ++start;
203 PRBool haveTwoColons = PR_TRUE;
204 if (start == end || *start != PRUnichar(':')) {
205 --start;
206 haveTwoColons = PR_FALSE;
208 mPseudo = do_GetAtom(Substring(start, end));
209 NS_ENSURE_TRUE(mPseudo, NS_ERROR_OUT_OF_MEMORY);
211 // There aren't any non-CSS2 pseudo-elements with a single ':'
212 if (!haveTwoColons &&
213 !nsCSSPseudoElements::IsCSS2PseudoElement(mPseudo)) {
214 // XXXbz I'd really rather we threw an exception or something, but
215 // the DOM spec sucks.
216 mPseudo = nsnull;
220 nsPresContext *presCtx = aPresShell->GetPresContext();
221 NS_ENSURE_TRUE(presCtx, NS_ERROR_FAILURE);
223 mAppUnitsPerInch = presCtx->AppUnitsPerInch();
225 return NS_OK;
228 NS_IMETHODIMP
229 nsComputedDOMStyle::GetPropertyValue(const nsCSSProperty aPropID,
230 nsAString& aValue)
232 // This is mostly to avoid code duplication with GetPropertyCSSValue(); if
233 // perf ever becomes an issue here (doubtful), we can look into changing
234 // this.
235 return GetPropertyValue(
236 NS_ConvertASCIItoUTF16(nsCSSProps::GetStringValue(aPropID)),
237 aValue);
240 NS_IMETHODIMP
241 nsComputedDOMStyle::SetPropertyValue(const nsCSSProperty aPropID,
242 const nsAString& aValue)
244 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
248 NS_IMETHODIMP
249 nsComputedDOMStyle::GetCssText(nsAString& aCssText)
251 aCssText.Truncate();
253 return NS_OK;
257 NS_IMETHODIMP
258 nsComputedDOMStyle::SetCssText(const nsAString& aCssText)
260 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
264 NS_IMETHODIMP
265 nsComputedDOMStyle::GetLength(PRUint32* aLength)
267 NS_PRECONDITION(aLength, "Null aLength! Prepare to die!");
269 (void)GetQueryablePropertyMap(aLength);
271 return NS_OK;
275 NS_IMETHODIMP
276 nsComputedDOMStyle::GetParentRule(nsIDOMCSSRule** aParentRule)
278 NS_ENSURE_ARG_POINTER(aParentRule);
279 *aParentRule = nsnull;
281 return NS_OK;
285 NS_IMETHODIMP
286 nsComputedDOMStyle::GetPropertyValue(const nsAString& aPropertyName,
287 nsAString& aReturn)
289 nsCOMPtr<nsIDOMCSSValue> val;
291 aReturn.Truncate();
293 nsresult rv = GetPropertyCSSValue(aPropertyName, getter_AddRefs(val));
294 NS_ENSURE_SUCCESS(rv, rv);
296 if (val) {
297 rv = val->GetCssText(aReturn);
300 return rv;
304 NS_IMETHODIMP
305 nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName,
306 nsIDOMCSSValue** aReturn)
308 NS_ENSURE_ARG_POINTER(aReturn);
309 *aReturn = nsnull;
311 nsCOMPtr<nsIDocument> document = do_QueryReferent(mDocumentWeak);
312 NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE);
314 // Flush _before_ getting the presshell, since that could create a new
315 // presshell. Also note that we want to flush the style on the document
316 // we're computing style in, not on the document mContent is in -- the two
317 // may be different.
318 document->FlushPendingNotifications(Flush_Style);
320 mPresShell = document->GetPrimaryShell();
321 NS_ENSURE_TRUE(mPresShell && mPresShell->GetPresContext(),
322 NS_ERROR_NOT_AVAILABLE);
324 mOuterFrame = mPresShell->GetPrimaryFrameFor(mContent);
325 mInnerFrame = mOuterFrame;
326 if (!mOuterFrame || mPseudo) {
327 // Need to resolve a style context
328 mStyleContextHolder =
329 nsInspectorCSSUtils::GetStyleContextForContent(mContent,
330 mPseudo,
331 mPresShell);
332 NS_ENSURE_TRUE(mStyleContextHolder, NS_ERROR_OUT_OF_MEMORY);
333 } else {
334 nsIAtom* type = mOuterFrame->GetType();
335 if (type == nsGkAtoms::tableOuterFrame) {
336 // If the frame is an outer table frame then we should get the style
337 // from the inner table frame.
338 mInnerFrame = mOuterFrame->GetFirstChild(nsnull);
339 NS_ASSERTION(mInnerFrame, "Outer table must have an inner");
340 NS_ASSERTION(!mInnerFrame->GetNextSibling(),
341 "Outer table frames should have just one child, the inner "
342 "table");
345 mStyleContextHolder = mInnerFrame->GetStyleContext();
346 NS_ASSERTION(mStyleContextHolder, "Frame without style context?");
349 nsresult rv = NS_OK;
351 nsCSSProperty prop = nsCSSProps::LookupProperty(aPropertyName);
353 PRUint32 i = 0;
354 PRUint32 length = 0;
355 const ComputedStyleMapEntry* propMap = GetQueryablePropertyMap(&length);
356 for (; i < length; ++i) {
357 if (prop == propMap[i].mProperty) {
358 // Call our pointer-to-member-function.
359 rv = (this->*(propMap[i].mGetter))(aReturn);
360 break;
364 #ifdef DEBUG_ComputedDOMStyle
365 if (i == length) {
366 NS_WARNING(PromiseFlatCString(NS_ConvertUTF16toUTF8(aPropertyName) +
367 NS_LITERAL_CSTRING(" is not queryable!")).get());
369 #endif
371 if (NS_FAILED(rv)) {
372 *aReturn = nsnull;
375 mOuterFrame = nsnull;
376 mInnerFrame = nsnull;
377 mPresShell = nsnull;
379 // Release the current style context for it should be re-resolved
380 // whenever a frame is not available.
381 mStyleContextHolder = nsnull;
383 return rv;
387 NS_IMETHODIMP
388 nsComputedDOMStyle::RemoveProperty(const nsAString& aPropertyName,
389 nsAString& aReturn)
391 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
395 NS_IMETHODIMP
396 nsComputedDOMStyle::GetPropertyPriority(const nsAString& aPropertyName,
397 nsAString& aReturn)
399 aReturn.Truncate();
401 return NS_OK;
405 NS_IMETHODIMP
406 nsComputedDOMStyle::SetProperty(const nsAString& aPropertyName,
407 const nsAString& aValue,
408 const nsAString& aPriority)
410 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
414 NS_IMETHODIMP
415 nsComputedDOMStyle::Item(PRUint32 aIndex, nsAString& aReturn)
417 aReturn.Truncate();
419 PRUint32 length = 0;
420 const ComputedStyleMapEntry* propMap = GetQueryablePropertyMap(&length);
421 if (aIndex < length) {
422 CopyASCIItoUTF16(nsCSSProps::GetStringValue(propMap[aIndex].mProperty),
423 aReturn);
426 return NS_OK;
430 // Property getters...
432 nsresult
433 nsComputedDOMStyle::GetBinding(nsIDOMCSSValue** aValue)
435 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
436 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
438 const nsStyleDisplay* display = GetStyleDisplay();
440 if (display->mBinding) {
441 val->SetURI(display->mBinding->mURI);
442 } else {
443 val->SetIdent(nsGkAtoms::none);
446 return CallQueryInterface(val, aValue);
449 nsresult
450 nsComputedDOMStyle::GetClear(nsIDOMCSSValue** aValue)
452 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
453 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
455 const nsStyleDisplay *display = GetStyleDisplay();
457 if (display->mBreakType != NS_STYLE_CLEAR_NONE) {
458 const nsAFlatCString& clear =
459 nsCSSProps::ValueToKeyword(display->mBreakType,
460 nsCSSProps::kClearKTable);
461 val->SetIdent(clear);
462 } else {
463 val->SetIdent(nsGkAtoms::none);
466 return CallQueryInterface(val, aValue);
469 nsresult
470 nsComputedDOMStyle::GetCssFloat(nsIDOMCSSValue** aValue)
472 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
473 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
475 const nsStyleDisplay* display = GetStyleDisplay();
477 if (display->mFloats != NS_STYLE_FLOAT_NONE) {
478 const nsAFlatCString& cssFloat =
479 nsCSSProps::ValueToKeyword(display->mFloats,
480 nsCSSProps::kFloatKTable);
481 val->SetIdent(cssFloat);
482 } else {
483 val->SetIdent(nsGkAtoms::none);
486 return CallQueryInterface(val, aValue);
489 nsresult
490 nsComputedDOMStyle::GetBottom(nsIDOMCSSValue** aValue)
492 return GetOffsetWidthFor(NS_SIDE_BOTTOM, aValue);
495 nsresult
496 nsComputedDOMStyle::GetStackSizing(nsIDOMCSSValue** aValue)
498 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
499 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
501 val->SetIdent(GetStyleXUL()->mStretchStack ? nsGkAtoms::stretch_to_fit :
502 nsGkAtoms::ignore);
504 return CallQueryInterface(val, aValue);
507 nsresult
508 nsComputedDOMStyle::SetToRGBAColor(nsROCSSPrimitiveValue* aValue,
509 nscolor aColor)
511 if (NS_GET_A(aColor) == 0) {
512 aValue->SetIdent(nsGkAtoms::transparent);
513 return NS_OK;
516 nsROCSSPrimitiveValue *red = GetROCSSPrimitiveValue();
517 nsROCSSPrimitiveValue *green = GetROCSSPrimitiveValue();
518 nsROCSSPrimitiveValue *blue = GetROCSSPrimitiveValue();
519 nsROCSSPrimitiveValue *alpha = GetROCSSPrimitiveValue();
521 if (red && green && blue && alpha) {
522 PRUint8 a = NS_GET_A(aColor);
523 nsDOMCSSRGBColor *rgbColor =
524 new nsDOMCSSRGBColor(red, green, blue, alpha, a < 255);
526 if (rgbColor) {
527 red->SetNumber(NS_GET_R(aColor));
528 green->SetNumber(NS_GET_G(aColor));
529 blue->SetNumber(NS_GET_B(aColor));
530 alpha->SetNumber(nsStyleUtil::ColorComponentToFloat(a));
532 aValue->SetColor(rgbColor);
533 return NS_OK;
537 delete red;
538 delete green;
539 delete blue;
540 delete alpha;
542 return NS_ERROR_OUT_OF_MEMORY;
545 nsresult
546 nsComputedDOMStyle::GetColor(nsIDOMCSSValue** aValue)
548 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
549 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
551 const nsStyleColor* color = GetStyleColor();
553 nsresult rv = SetToRGBAColor(val, color->mColor);
554 if (NS_FAILED(rv)) {
555 delete val;
556 return rv;
559 return CallQueryInterface(val, aValue);
562 nsresult
563 nsComputedDOMStyle::GetOpacity(nsIDOMCSSValue** aValue)
565 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
566 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
568 val->SetNumber(GetStyleDisplay()->mOpacity);
570 return CallQueryInterface(val, aValue);
573 nsresult
574 nsComputedDOMStyle::GetColumnCount(nsIDOMCSSValue** aValue)
576 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
577 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
579 const nsStyleColumn* column = GetStyleColumn();
581 if (column->mColumnCount == NS_STYLE_COLUMN_COUNT_AUTO) {
582 val->SetIdent(nsGkAtoms::_auto);
583 } else {
584 val->SetNumber(column->mColumnCount);
587 return CallQueryInterface(val, aValue);
590 nsresult
591 nsComputedDOMStyle::GetColumnWidth(nsIDOMCSSValue** aValue)
593 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
594 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
596 // XXX fix the auto case. When we actually have a column frame, I think
597 // we should return the computed column width.
598 SetValueToCoord(val, GetStyleColumn()->mColumnWidth);
600 return CallQueryInterface(val, aValue);
603 nsresult
604 nsComputedDOMStyle::GetColumnGap(nsIDOMCSSValue** aValue)
606 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
607 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
609 const nsStyleColumn* column = GetStyleColumn();
610 if (column->mColumnGap.GetUnit() == eStyleUnit_Normal) {
611 val->SetAppUnits(GetStyleFont()->mFont.size);
612 } else {
613 SetValueToCoord(val, GetStyleColumn()->mColumnGap);
616 return CallQueryInterface(val, aValue);
619 nsresult
620 nsComputedDOMStyle::GetColumnRuleWidth(nsIDOMCSSValue** aValue)
622 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
623 if (!val)
624 return NS_ERROR_OUT_OF_MEMORY;
626 SetValueToCoord(val, GetStyleColumn()->GetComputedColumnRuleWidth());
627 return CallQueryInterface(val, aValue);
630 nsresult
631 nsComputedDOMStyle::GetColumnRuleStyle(nsIDOMCSSValue** aValue)
633 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
634 if (!val)
635 return NS_ERROR_OUT_OF_MEMORY;
637 const nsStyleColumn* column = GetStyleColumn();
638 if (column->mColumnRuleStyle == NS_STYLE_BORDER_STYLE_NONE) {
639 val->SetIdent(nsGkAtoms::none);
640 } else {
641 const nsAFlatCString& style =
642 nsCSSProps::ValueToKeyword(column->mColumnRuleStyle,
643 nsCSSProps::kBorderStyleKTable);
644 val->SetIdent(style);
646 return CallQueryInterface(val, aValue);
649 nsresult
650 nsComputedDOMStyle::GetColumnRuleColor(nsIDOMCSSValue** aValue)
652 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
653 if (!val)
654 return NS_ERROR_OUT_OF_MEMORY;
656 const nsStyleColumn* column = GetStyleColumn();
657 nscolor ruleColor;
658 if (column->mColumnRuleColorIsForeground) {
659 ruleColor = GetStyleColor()->mColor;
660 } else {
661 ruleColor = column->mColumnRuleColor;
664 SetToRGBAColor(val, ruleColor);
665 return CallQueryInterface(val, aValue);
668 nsresult
669 nsComputedDOMStyle::GetContent(nsIDOMCSSValue** aValue)
671 const nsStyleContent *content = GetStyleContent();
673 if (content->ContentCount() == 0) {
674 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
675 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
676 val->SetIdent(nsGkAtoms::none);
677 return CallQueryInterface(val, aValue);
680 if (content->ContentCount() == 1 &&
681 content->ContentAt(0).mType == eStyleContentType_AltContent) {
682 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
683 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
684 val->SetIdent(eCSSKeyword__moz_alt_content);
685 return CallQueryInterface(val, aValue);
688 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
689 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
691 for (PRUint32 i = 0, i_end = content->ContentCount(); i < i_end; ++i) {
692 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
693 if (!val || !valueList->AppendCSSValue(val)) {
694 delete valueList;
695 delete val;
696 return NS_ERROR_OUT_OF_MEMORY;
699 const nsStyleContentData &data = content->ContentAt(i);
700 switch (data.mType) {
701 case eStyleContentType_String:
703 nsString str;
704 nsStyleUtil::EscapeCSSString(nsDependentString(data.mContent.mString),
705 str);
706 str.Insert(PRUnichar('"'), 0);
707 str.Append(PRUnichar('"'));
708 val->SetString(str);
710 break;
711 case eStyleContentType_Image:
713 nsCOMPtr<nsIURI> uri;
714 if (data.mContent.mImage) {
715 data.mContent.mImage->GetURI(getter_AddRefs(uri));
717 val->SetURI(uri);
719 break;
720 case eStyleContentType_Attr:
721 val->SetString(nsDependentString(data.mContent.mString),
722 nsIDOMCSSPrimitiveValue::CSS_ATTR);
723 break;
724 case eStyleContentType_Counter:
725 case eStyleContentType_Counters:
727 /* FIXME: counters should really use an object */
728 nsAutoString str;
729 if (data.mType == eStyleContentType_Counter) {
730 str.AppendLiteral("counter(");
732 else {
733 str.AppendLiteral("counters(");
735 // WRITE ME
736 nsCSSValue::Array *a = data.mContent.mCounters;
738 str.Append(a->Item(0).GetStringBufferValue());
739 PRInt32 typeItem = 1;
740 if (data.mType == eStyleContentType_Counters) {
741 typeItem = 2;
742 str.AppendLiteral(", \"");
743 nsString itemstr;
744 nsStyleUtil::EscapeCSSString(
745 nsDependentString(a->Item(1).GetStringBufferValue()), itemstr);
746 str.Append(itemstr);
747 str.Append(PRUnichar('"'));
749 PRInt32 type = a->Item(typeItem).GetIntValue();
750 if (type != NS_STYLE_LIST_STYLE_DECIMAL) {
751 str.AppendLiteral(", ");
752 str.AppendInt(type);
755 str.Append(PRUnichar(')'));
756 val->SetString(str, nsIDOMCSSPrimitiveValue::CSS_COUNTER);
758 break;
759 case eStyleContentType_OpenQuote:
760 val->SetIdent(eCSSKeyword_open_quote);
761 break;
762 case eStyleContentType_CloseQuote:
763 val->SetIdent(eCSSKeyword_close_quote);
764 break;
765 case eStyleContentType_NoOpenQuote:
766 val->SetIdent(eCSSKeyword_no_open_quote);
767 break;
768 case eStyleContentType_NoCloseQuote:
769 val->SetIdent(eCSSKeyword_no_close_quote);
770 break;
771 case eStyleContentType_AltContent:
772 default:
773 NS_NOTREACHED("unexpected type");
774 break;
778 return CallQueryInterface(valueList, aValue);
781 nsresult
782 nsComputedDOMStyle::GetCounterIncrement(nsIDOMCSSValue** aValue)
784 const nsStyleContent *content = GetStyleContent();
786 if (content->CounterIncrementCount() == 0) {
787 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
788 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
789 val->SetIdent(nsGkAtoms::none);
790 return CallQueryInterface(val, aValue);
793 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
794 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
796 for (PRUint32 i = 0, i_end = content->CounterIncrementCount(); i < i_end; ++i) {
797 nsROCSSPrimitiveValue* name = GetROCSSPrimitiveValue();
798 if (!name || !valueList->AppendCSSValue(name)) {
799 delete valueList;
800 delete name;
801 return NS_ERROR_OUT_OF_MEMORY;
804 nsROCSSPrimitiveValue* value = GetROCSSPrimitiveValue();
805 if (!value || !valueList->AppendCSSValue(value)) {
806 delete valueList;
807 delete value;
808 return NS_ERROR_OUT_OF_MEMORY;
811 const nsStyleCounterData *data = content->GetCounterIncrementAt(i);
812 name->SetString(data->mCounter);
813 value->SetNumber(data->mValue); // XXX This should really be integer
816 return CallQueryInterface(valueList, aValue);
819 /* Convert the stored representation into a list of two values and then hand
820 * it back.
822 nsresult nsComputedDOMStyle::GetMozTransformOrigin(nsIDOMCSSValue **aValue)
824 /* We need to build up a list of two values. We'll call them
825 * width and height.
827 nsAutoPtr<nsROCSSPrimitiveValue> width(GetROCSSPrimitiveValue());
828 nsAutoPtr<nsROCSSPrimitiveValue> height(GetROCSSPrimitiveValue());
829 if (!width || !height)
830 return NS_ERROR_OUT_OF_MEMORY;
832 /* Now, get the values. */
833 const nsStyleDisplay* display = GetStyleDisplay();
834 SetValueToCoord(width, display->mTransformOrigin[0],
835 &nsComputedDOMStyle::GetFrameBoundsWidthForTransform);
836 SetValueToCoord(height, display->mTransformOrigin[1],
837 &nsComputedDOMStyle::GetFrameBoundsHeightForTransform);
839 /* Store things as a value list, fail if we can't get one. */
840 nsAutoPtr<nsDOMCSSValueList> valueList(GetROCSSValueList(PR_FALSE));
841 if (!valueList)
842 return NS_ERROR_OUT_OF_MEMORY;
844 /* Chain on width and height, fail if we can't. */
845 if (!valueList->AppendCSSValue(width))
846 return NS_ERROR_OUT_OF_MEMORY;
847 width.forget();
848 if (!valueList->AppendCSSValue(height))
849 return NS_ERROR_OUT_OF_MEMORY;
850 height.forget();
852 /* Release the pointer and call query interface! We're done. */
853 return CallQueryInterface(valueList.forget(), aValue);
856 /* If the property is "none", hand back "none" wrapped in a value.
857 * Otherwise, compute the aggregate transform matrix and hands it back in a
858 * "matrix" wrapper.
860 nsresult nsComputedDOMStyle::GetMozTransform(nsIDOMCSSValue **aValue)
862 static const PRInt32 NUM_FLOATS = 4;
864 /* First, get the display data. We'll need it. */
865 const nsStyleDisplay* display = GetStyleDisplay();
867 /* If the "no transforms" flag is set, then we should construct a
868 * single-element entry and hand it back.
870 if (!display->mTransformPresent) {
871 nsROCSSPrimitiveValue *val(GetROCSSPrimitiveValue());
872 if (!val)
873 return NS_ERROR_OUT_OF_MEMORY;
875 /* Set it to "none." */
876 val->SetIdent(eCSSKeyword_none);
877 return CallQueryInterface(val, aValue);
880 /* Otherwise, we need to compute the current value of the transform matrix,
881 * store it in a string, and hand it back to the caller.
883 nsAutoString resultString(NS_LITERAL_STRING("matrix("));
885 /* Now, we need to convert the matrix into a string. We'll start by taking
886 * the first four entries and converting them directly to floating-point
887 * values.
889 for (PRInt32 index = 0; index < NUM_FLOATS; ++index) {
890 resultString.AppendFloat(display->mTransform.GetMainMatrixEntry(index));
891 resultString.Append(NS_LITERAL_STRING(", "));
894 /* Use the inner frame for width and height. If we fail, assume zero.
895 * TODO: There is no good way for us to represent the case where there's no
896 * frame, which is problematic. The reason is that when we have percentage
897 * transforms, there are a total of four stored matrix entries that influence
898 * the transform based on the size of the element. However, this poses a
899 * problem, because only two of these values can be explicitly referenced
900 * using the named transforms. Until a real solution is found, we'll just
901 * use this approach.
903 nsRect bounds =
904 (mInnerFrame ? nsDisplayTransform::GetFrameBoundsForTransform(mInnerFrame) :
905 nsRect(0, 0, 0, 0));
907 /* Now, compute the dX and dY components by adding the stored coord value
908 * (in CSS pixels) to the translate values.
911 float deltaX = nsPresContext::AppUnitsToFloatCSSPixels
912 (display->mTransform.GetXTranslation(bounds));
913 float deltaY = nsPresContext::AppUnitsToFloatCSSPixels
914 (display->mTransform.GetYTranslation(bounds));
917 /* Append these values! */
918 resultString.AppendFloat(deltaX);
919 resultString.Append(NS_LITERAL_STRING("px, "));
920 resultString.AppendFloat(deltaY);
921 resultString.Append(NS_LITERAL_STRING("px)"));
923 /* Create a value to hold our result. */
924 nsROCSSPrimitiveValue* rv(GetROCSSPrimitiveValue());
926 if (!rv)
927 return NS_ERROR_OUT_OF_MEMORY;
929 rv->SetString(resultString);
930 return CallQueryInterface(rv, aValue);
933 nsresult
934 nsComputedDOMStyle::GetCounterReset(nsIDOMCSSValue** aValue)
936 const nsStyleContent *content = GetStyleContent();
938 if (content->CounterResetCount() == 0) {
939 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
940 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
941 val->SetIdent(nsGkAtoms::none);
942 return CallQueryInterface(val, aValue);
945 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
946 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
948 for (PRUint32 i = 0, i_end = content->CounterResetCount(); i < i_end; ++i) {
949 nsROCSSPrimitiveValue* name = GetROCSSPrimitiveValue();
950 if (!name || !valueList->AppendCSSValue(name)) {
951 delete valueList;
952 delete name;
953 return NS_ERROR_OUT_OF_MEMORY;
956 nsROCSSPrimitiveValue* value = GetROCSSPrimitiveValue();
957 if (!value || !valueList->AppendCSSValue(value)) {
958 delete valueList;
959 delete value;
960 return NS_ERROR_OUT_OF_MEMORY;
963 const nsStyleCounterData *data = content->GetCounterResetAt(i);
964 name->SetString(data->mCounter);
965 value->SetNumber(data->mValue); // XXX This should really be integer
968 return CallQueryInterface(valueList, aValue);
971 nsresult
972 nsComputedDOMStyle::GetQuotes(nsIDOMCSSValue** aValue)
974 const nsStyleQuotes *quotes = GetStyleQuotes();
976 if (quotes->QuotesCount() == 0) {
977 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
978 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
979 val->SetIdent(nsGkAtoms::none);
980 return CallQueryInterface(val, aValue);
983 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
984 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
986 for (PRUint32 i = 0, i_end = quotes->QuotesCount(); i < i_end; ++i) {
987 nsROCSSPrimitiveValue* openVal = GetROCSSPrimitiveValue();
988 if (!openVal || !valueList->AppendCSSValue(openVal)) {
989 delete valueList;
990 delete openVal;
991 return NS_ERROR_OUT_OF_MEMORY;
994 nsROCSSPrimitiveValue* closeVal = GetROCSSPrimitiveValue();
995 if (!closeVal || !valueList->AppendCSSValue(closeVal)) {
996 delete valueList;
997 delete closeVal;
998 return NS_ERROR_OUT_OF_MEMORY;
1001 nsString s;
1002 nsStyleUtil::EscapeCSSString(*quotes->OpenQuoteAt(i), s);
1003 s.Insert(PRUnichar('"'), 0);
1004 s.Append(PRUnichar('"'));
1005 openVal->SetString(s);
1006 nsStyleUtil::EscapeCSSString(*quotes->CloseQuoteAt(i), s);
1007 s.Insert(PRUnichar('"'), 0);
1008 s.Append(PRUnichar('"'));
1009 closeVal->SetString(s);
1012 return CallQueryInterface(valueList, aValue);
1015 nsresult
1016 nsComputedDOMStyle::GetFontFamily(nsIDOMCSSValue** aValue)
1018 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1019 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1021 const nsStyleFont* font = GetStyleFont();
1023 nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocumentWeak);
1024 NS_ASSERTION(doc, "document is required");
1025 nsIPresShell* presShell = doc->GetPrimaryShell();
1026 NS_ASSERTION(presShell, "pres shell is required");
1027 nsPresContext *presContext = presShell->GetPresContext();
1028 NS_ASSERTION(presContext, "pres context is required");
1030 const nsString& fontName = font->mFont.name;
1031 PRUint8 generic = font->mFlags & NS_STYLE_FONT_FACE_MASK;
1032 if (generic == kGenericFont_NONE && !font->mFont.systemFont) {
1033 const nsFont* defaultFont =
1034 presContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID);
1036 PRInt32 lendiff = fontName.Length() - defaultFont->name.Length();
1037 if (lendiff > 0) {
1038 val->SetString(Substring(fontName, 0, lendiff-1)); // -1 removes comma
1039 } else {
1040 val->SetString(fontName);
1042 } else {
1043 val->SetString(fontName);
1046 return CallQueryInterface(val, aValue);
1049 nsresult
1050 nsComputedDOMStyle::GetFontSize(nsIDOMCSSValue** aValue)
1052 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1053 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1055 // Note: GetStyleFont()->mSize is the 'computed size';
1056 // GetStyleFont()->mFont.size is the 'actual size'
1057 val->SetAppUnits(GetStyleFont()->mSize);
1059 return CallQueryInterface(val, aValue);
1062 nsresult
1063 nsComputedDOMStyle::GetFontSizeAdjust(nsIDOMCSSValue** aValue)
1065 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1066 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1068 const nsStyleFont *font = GetStyleFont();
1070 if (font->mFont.sizeAdjust) {
1071 val->SetNumber(font->mFont.sizeAdjust);
1072 } else {
1073 val->SetIdent(nsGkAtoms::none);
1076 return CallQueryInterface(val, aValue);
1079 nsresult
1080 nsComputedDOMStyle::GetFontStyle(nsIDOMCSSValue** aValue)
1082 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1083 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1085 const nsStyleFont* font = GetStyleFont();
1087 if (font->mFont.style != NS_STYLE_FONT_STYLE_NORMAL) {
1088 const nsAFlatCString& style=
1089 nsCSSProps::ValueToKeyword(font->mFont.style,
1090 nsCSSProps::kFontStyleKTable);
1091 val->SetIdent(style);
1092 } else {
1093 val->SetIdent(nsGkAtoms::normal);
1096 return CallQueryInterface(val, aValue);
1099 nsresult
1100 nsComputedDOMStyle::GetFontWeight(nsIDOMCSSValue** aValue)
1102 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1103 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1105 const nsStyleFont* font = GetStyleFont();
1107 const nsAFlatCString& str_weight=
1108 nsCSSProps::ValueToKeyword(font->mFont.weight,
1109 nsCSSProps::kFontWeightKTable);
1110 if (!str_weight.IsEmpty()) {
1111 val->SetIdent(str_weight);
1112 } else {
1113 val->SetNumber(font->mFont.weight);
1116 return CallQueryInterface(val, aValue);
1119 nsresult
1120 nsComputedDOMStyle::GetFontVariant(nsIDOMCSSValue** aValue)
1122 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1123 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1125 const nsStyleFont* font = GetStyleFont();
1127 if (font->mFont.variant != NS_STYLE_FONT_VARIANT_NORMAL) {
1128 const nsAFlatCString& variant=
1129 nsCSSProps::ValueToKeyword(font->mFont.variant,
1130 nsCSSProps::kFontVariantKTable);
1131 val->SetIdent(variant);
1132 } else {
1133 val->SetIdent(nsGkAtoms::normal);
1136 return CallQueryInterface(val, aValue);
1139 nsresult
1140 nsComputedDOMStyle::GetBackgroundAttachment(nsIDOMCSSValue** aValue)
1142 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1143 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1145 const nsStyleBackground *background = GetStyleBackground();
1147 const nsAFlatCString& backgroundAttachment =
1148 nsCSSProps::ValueToKeyword(background->mBackgroundAttachment,
1149 nsCSSProps::kBackgroundAttachmentKTable);
1150 val->SetIdent(backgroundAttachment);
1152 return CallQueryInterface(val, aValue);
1155 nsresult
1156 nsComputedDOMStyle::GetBackgroundClip(nsIDOMCSSValue** aValue)
1158 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1159 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1161 const nsAFlatCString& backgroundClip =
1162 nsCSSProps::ValueToKeyword(GetStyleBackground()->mBackgroundClip,
1163 nsCSSProps::kBackgroundClipKTable);
1165 val->SetIdent(backgroundClip);
1167 return CallQueryInterface(val, aValue);
1170 nsresult
1171 nsComputedDOMStyle::GetBackgroundColor(nsIDOMCSSValue** aValue)
1173 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1174 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1176 const nsStyleBackground* color = GetStyleBackground();
1177 nsresult rv = SetToRGBAColor(val, color->mBackgroundColor);
1178 if (NS_FAILED(rv)) {
1179 delete val;
1180 return rv;
1183 return CallQueryInterface(val, aValue);
1186 nsresult
1187 nsComputedDOMStyle::GetBackgroundImage(nsIDOMCSSValue** aValue)
1189 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1190 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1192 const nsStyleBackground* color = GetStyleBackground();
1194 if (color->mBackgroundFlags & NS_STYLE_BG_IMAGE_NONE) {
1195 val->SetIdent(nsGkAtoms::none);
1196 } else {
1197 nsCOMPtr<nsIURI> uri;
1198 if (color->mBackgroundImage) {
1199 color->mBackgroundImage->GetURI(getter_AddRefs(uri));
1201 val->SetURI(uri);
1204 return CallQueryInterface(val, aValue);
1207 nsresult
1208 nsComputedDOMStyle::GetBackgroundInlinePolicy(nsIDOMCSSValue** aValue)
1210 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1211 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1213 const nsAFlatCString& backgroundPolicy =
1214 nsCSSProps::ValueToKeyword(GetStyleBackground()->mBackgroundInlinePolicy,
1215 nsCSSProps::kBackgroundInlinePolicyKTable);
1217 val->SetIdent(backgroundPolicy);
1219 return CallQueryInterface(val, aValue);
1222 nsresult
1223 nsComputedDOMStyle::GetBackgroundOrigin(nsIDOMCSSValue** aValue)
1225 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1226 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1228 const nsAFlatCString& backgroundOrigin =
1229 nsCSSProps::ValueToKeyword(GetStyleBackground()->mBackgroundOrigin,
1230 nsCSSProps::kBackgroundOriginKTable);
1232 val->SetIdent(backgroundOrigin);
1234 return CallQueryInterface(val, aValue);
1237 nsresult
1238 nsComputedDOMStyle::GetBackgroundPosition(nsIDOMCSSValue** aValue)
1240 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
1241 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
1243 nsROCSSPrimitiveValue *valX = GetROCSSPrimitiveValue();
1244 if (!valX || !valueList->AppendCSSValue(valX)) {
1245 delete valueList;
1246 delete valX;
1247 return NS_ERROR_OUT_OF_MEMORY;
1250 nsROCSSPrimitiveValue *valY = GetROCSSPrimitiveValue();
1251 if (!valY || !valueList->AppendCSSValue(valY)) {
1252 delete valueList;
1253 delete valY;
1254 return NS_ERROR_OUT_OF_MEMORY;
1257 const nsStyleBackground *bg = GetStyleBackground();
1259 if (NS_STYLE_BG_X_POSITION_LENGTH & bg->mBackgroundFlags) {
1260 valX->SetAppUnits(bg->mBackgroundXPosition.mCoord);
1262 else if (NS_STYLE_BG_X_POSITION_PERCENT & bg->mBackgroundFlags) {
1263 valX->SetPercent(bg->mBackgroundXPosition.mFloat);
1265 else {
1266 valX->SetPercent(0.0f);
1269 if (NS_STYLE_BG_Y_POSITION_LENGTH & bg->mBackgroundFlags) {
1270 valY->SetAppUnits(bg->mBackgroundYPosition.mCoord);
1272 else if (NS_STYLE_BG_Y_POSITION_PERCENT & bg->mBackgroundFlags) {
1273 valY->SetPercent(bg->mBackgroundYPosition.mFloat);
1275 else {
1276 valY->SetPercent(0.0f);
1279 return CallQueryInterface(valueList, aValue);
1282 nsresult
1283 nsComputedDOMStyle::GetBackgroundRepeat(nsIDOMCSSValue** aValue)
1285 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1286 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1288 const nsAFlatCString& backgroundRepeat =
1289 nsCSSProps::ValueToKeyword(GetStyleBackground()->mBackgroundRepeat,
1290 nsCSSProps::kBackgroundRepeatKTable);
1291 val->SetIdent(backgroundRepeat);
1293 return CallQueryInterface(val, aValue);
1296 nsresult
1297 nsComputedDOMStyle::GetPadding(nsIDOMCSSValue** aValue)
1299 // return null per spec.
1300 aValue = nsnull;
1302 return NS_OK;
1305 nsresult
1306 nsComputedDOMStyle::GetPaddingTop(nsIDOMCSSValue** aValue)
1308 return GetPaddingWidthFor(NS_SIDE_TOP, aValue);
1311 nsresult
1312 nsComputedDOMStyle::GetPaddingBottom(nsIDOMCSSValue** aValue)
1314 return GetPaddingWidthFor(NS_SIDE_BOTTOM, aValue);
1317 nsresult
1318 nsComputedDOMStyle::GetPaddingLeft(nsIDOMCSSValue** aValue)
1320 return GetPaddingWidthFor(NS_SIDE_LEFT, aValue);
1323 nsresult
1324 nsComputedDOMStyle::GetPaddingRight(nsIDOMCSSValue** aValue)
1326 return GetPaddingWidthFor(NS_SIDE_RIGHT, aValue);
1329 nsresult
1330 nsComputedDOMStyle::GetBorderCollapse(nsIDOMCSSValue** aValue)
1332 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1333 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1335 const nsAFlatCString& ident=
1336 nsCSSProps::ValueToKeyword(GetStyleTableBorder()->mBorderCollapse,
1337 nsCSSProps::kBorderCollapseKTable);
1338 val->SetIdent(ident);
1340 return CallQueryInterface(val, aValue);
1343 nsresult
1344 nsComputedDOMStyle::GetBorderSpacing(nsIDOMCSSValue** aValue)
1346 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
1347 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
1349 nsROCSSPrimitiveValue* xSpacing = GetROCSSPrimitiveValue();
1350 if (!xSpacing) {
1351 delete valueList;
1352 return NS_ERROR_OUT_OF_MEMORY;
1354 if (!valueList->AppendCSSValue(xSpacing)) {
1355 delete valueList;
1356 delete xSpacing;
1357 return NS_ERROR_OUT_OF_MEMORY;
1360 nsROCSSPrimitiveValue* ySpacing = GetROCSSPrimitiveValue();
1361 if (!ySpacing) {
1362 delete valueList;
1363 return NS_ERROR_OUT_OF_MEMORY;
1365 if (!valueList->AppendCSSValue(ySpacing)) {
1366 delete valueList;
1367 delete ySpacing;
1368 return NS_ERROR_OUT_OF_MEMORY;
1371 const nsStyleTableBorder *border = GetStyleTableBorder();
1372 xSpacing->SetAppUnits(border->mBorderSpacingX);
1373 ySpacing->SetAppUnits(border->mBorderSpacingY);
1375 return CallQueryInterface(valueList, aValue);
1378 nsresult
1379 nsComputedDOMStyle::GetCaptionSide(nsIDOMCSSValue** aValue)
1381 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1382 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1384 const nsAFlatCString& side =
1385 nsCSSProps::ValueToKeyword(GetStyleTableBorder()->mCaptionSide,
1386 nsCSSProps::kCaptionSideKTable);
1387 val->SetIdent(side);
1389 return CallQueryInterface(val, aValue);
1392 nsresult
1393 nsComputedDOMStyle::GetEmptyCells(nsIDOMCSSValue** aValue)
1395 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1396 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1398 const nsAFlatCString& emptyCells =
1399 nsCSSProps::ValueToKeyword(GetStyleTableBorder()->mEmptyCells,
1400 nsCSSProps::kEmptyCellsKTable);
1401 val->SetIdent(emptyCells);
1403 return CallQueryInterface(val, aValue);
1406 nsresult
1407 nsComputedDOMStyle::GetTableLayout(nsIDOMCSSValue** aValue)
1409 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1410 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1412 const nsStyleTable *table = GetStyleTable();
1414 if (table->mLayoutStrategy != NS_STYLE_TABLE_LAYOUT_AUTO) {
1415 const nsAFlatCString& tableLayout =
1416 nsCSSProps::ValueToKeyword(table->mLayoutStrategy,
1417 nsCSSProps::kTableLayoutKTable);
1418 val->SetIdent(tableLayout);
1419 } else {
1420 val->SetIdent(nsGkAtoms::_auto);
1423 return CallQueryInterface(val, aValue);
1426 nsresult
1427 nsComputedDOMStyle::GetBorderStyle(nsIDOMCSSValue** aValue)
1429 // return null per spec.
1430 aValue = nsnull;
1432 return NS_OK;
1435 nsresult
1436 nsComputedDOMStyle::GetBorderTopStyle(nsIDOMCSSValue** aValue)
1438 return GetBorderStyleFor(NS_SIDE_TOP, aValue);
1441 nsresult
1442 nsComputedDOMStyle::GetBorderBottomStyle(nsIDOMCSSValue** aValue)
1444 return GetBorderStyleFor(NS_SIDE_BOTTOM, aValue);
1446 nsresult
1447 nsComputedDOMStyle::GetBorderLeftStyle(nsIDOMCSSValue** aValue)
1449 return GetBorderStyleFor(NS_SIDE_LEFT, aValue);
1452 nsresult
1453 nsComputedDOMStyle::GetBorderRightStyle(nsIDOMCSSValue** aValue)
1455 return GetBorderStyleFor(NS_SIDE_RIGHT, aValue);
1458 nsresult
1459 nsComputedDOMStyle::GetBorderBottomColors(nsIDOMCSSValue** aValue)
1461 return GetBorderColorsFor(NS_SIDE_BOTTOM, aValue);
1464 nsresult
1465 nsComputedDOMStyle::GetBorderLeftColors(nsIDOMCSSValue** aValue)
1467 return GetBorderColorsFor(NS_SIDE_LEFT, aValue);
1470 nsresult
1471 nsComputedDOMStyle::GetBorderRightColors(nsIDOMCSSValue** aValue)
1473 return GetBorderColorsFor(NS_SIDE_RIGHT, aValue);
1477 nsresult
1478 nsComputedDOMStyle::GetBorderTopColors(nsIDOMCSSValue** aValue)
1480 return GetBorderColorsFor(NS_SIDE_TOP, aValue);
1484 nsresult
1485 nsComputedDOMStyle::GetBorderRadiusBottomLeft(nsIDOMCSSValue** aValue)
1487 return GetBorderRadiusFor(NS_SIDE_LEFT, aValue);
1490 nsresult
1491 nsComputedDOMStyle::GetBorderRadiusBottomRight(nsIDOMCSSValue** aValue)
1493 return GetBorderRadiusFor(NS_SIDE_BOTTOM, aValue);
1496 nsresult
1497 nsComputedDOMStyle::GetBorderRadiusTopLeft(nsIDOMCSSValue** aValue)
1499 return GetBorderRadiusFor(NS_SIDE_TOP, aValue);
1502 nsresult
1503 nsComputedDOMStyle::GetBorderRadiusTopRight(nsIDOMCSSValue** aValue)
1505 return GetBorderRadiusFor(NS_SIDE_RIGHT, aValue);
1508 nsresult
1509 nsComputedDOMStyle::GetBorderWidth(nsIDOMCSSValue** aValue)
1511 // return null per spec.
1512 aValue = nsnull;
1514 return NS_OK;
1517 nsresult
1518 nsComputedDOMStyle::GetBorderTopWidth(nsIDOMCSSValue** aValue)
1520 return GetBorderWidthFor(NS_SIDE_TOP, aValue);
1523 nsresult
1524 nsComputedDOMStyle::GetBorderBottomWidth(nsIDOMCSSValue** aValue)
1526 return GetBorderWidthFor(NS_SIDE_BOTTOM, aValue);
1529 nsresult
1530 nsComputedDOMStyle::GetBorderLeftWidth(nsIDOMCSSValue** aValue)
1532 return GetBorderWidthFor(NS_SIDE_LEFT, aValue);
1535 nsresult
1536 nsComputedDOMStyle::GetBorderRightWidth(nsIDOMCSSValue** aValue)
1538 return GetBorderWidthFor(NS_SIDE_RIGHT, aValue);
1541 nsresult
1542 nsComputedDOMStyle::GetBorderTopColor(nsIDOMCSSValue** aValue)
1544 return GetBorderColorFor(NS_SIDE_TOP, aValue);
1547 nsresult
1548 nsComputedDOMStyle::GetBorderBottomColor(nsIDOMCSSValue** aValue)
1550 return GetBorderColorFor(NS_SIDE_BOTTOM, aValue);
1553 nsresult
1554 nsComputedDOMStyle::GetBorderLeftColor(nsIDOMCSSValue** aValue)
1556 return GetBorderColorFor(NS_SIDE_LEFT, aValue);
1559 nsresult
1560 nsComputedDOMStyle::GetBorderRightColor(nsIDOMCSSValue** aValue)
1562 return GetBorderColorFor(NS_SIDE_RIGHT, aValue);
1565 nsresult
1566 nsComputedDOMStyle::GetMarginWidth(nsIDOMCSSValue** aValue)
1568 // return null per spec.
1569 aValue = nsnull;
1571 return NS_OK;
1574 nsresult
1575 nsComputedDOMStyle::GetMarginTopWidth(nsIDOMCSSValue** aValue)
1577 return GetMarginWidthFor(NS_SIDE_TOP, aValue);
1580 nsresult
1581 nsComputedDOMStyle::GetMarginBottomWidth(nsIDOMCSSValue** aValue)
1583 return GetMarginWidthFor(NS_SIDE_BOTTOM, aValue);
1586 nsresult
1587 nsComputedDOMStyle::GetMarginLeftWidth(nsIDOMCSSValue** aValue)
1589 return GetMarginWidthFor(NS_SIDE_LEFT, aValue);
1592 nsresult
1593 nsComputedDOMStyle::GetMarginRightWidth(nsIDOMCSSValue** aValue)
1595 return GetMarginWidthFor(NS_SIDE_RIGHT, aValue);
1598 nsresult
1599 nsComputedDOMStyle::GetMarkerOffset(nsIDOMCSSValue** aValue)
1601 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1602 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1604 SetValueToCoord(val, GetStyleContent()->mMarkerOffset);
1606 return CallQueryInterface(val, aValue);
1609 nsresult
1610 nsComputedDOMStyle::GetOutline(nsIDOMCSSValue** aValue)
1612 // return null per spec.
1613 aValue = nsnull;
1615 return NS_OK;
1618 nsresult
1619 nsComputedDOMStyle::GetOutlineWidth(nsIDOMCSSValue** aValue)
1621 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1622 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1624 const nsStyleOutline* outline = GetStyleOutline();
1626 nsStyleCoord coord;
1627 PRUint8 outlineStyle = outline->GetOutlineStyle();
1628 if (outlineStyle == NS_STYLE_BORDER_STYLE_NONE) {
1629 coord.SetCoordValue(0);
1630 } else {
1631 coord = outline->mOutlineWidth;
1633 SetValueToCoord(val, coord, nsnull, nsCSSProps::kBorderWidthKTable);
1635 return CallQueryInterface(val, aValue);
1638 nsresult
1639 nsComputedDOMStyle::GetOutlineStyle(nsIDOMCSSValue** aValue)
1641 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1642 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1644 PRUint8 outlineStyle = GetStyleOutline()->GetOutlineStyle();
1645 switch (outlineStyle) {
1646 case NS_STYLE_BORDER_STYLE_NONE:
1647 val->SetIdent(nsGkAtoms::none);
1648 break;
1649 case NS_STYLE_BORDER_STYLE_AUTO:
1650 val->SetIdent(nsGkAtoms::_auto);
1651 break;
1652 default:
1653 const nsAFlatCString& style =
1654 nsCSSProps::ValueToKeyword(outlineStyle,
1655 nsCSSProps::kOutlineStyleKTable);
1656 val->SetIdent(style);
1659 return CallQueryInterface(val, aValue);
1662 nsresult
1663 nsComputedDOMStyle::GetOutlineOffset(nsIDOMCSSValue** aValue)
1665 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1666 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1668 val->SetAppUnits(GetStyleOutline()->mOutlineOffset);
1670 return CallQueryInterface(val, aValue);
1673 nsresult
1674 nsComputedDOMStyle::GetOutlineRadiusBottomLeft(nsIDOMCSSValue** aValue)
1676 return GetOutlineRadiusFor(NS_SIDE_LEFT, aValue);
1679 nsresult
1680 nsComputedDOMStyle::GetOutlineRadiusBottomRight(nsIDOMCSSValue** aValue)
1682 return GetOutlineRadiusFor(NS_SIDE_BOTTOM, aValue);
1685 nsresult
1686 nsComputedDOMStyle::GetOutlineRadiusTopLeft(nsIDOMCSSValue** aValue)
1688 return GetOutlineRadiusFor(NS_SIDE_TOP, aValue);
1691 nsresult
1692 nsComputedDOMStyle::GetOutlineRadiusTopRight(nsIDOMCSSValue** aValue)
1694 return GetOutlineRadiusFor(NS_SIDE_RIGHT, aValue);
1697 nsresult
1698 nsComputedDOMStyle::GetOutlineColor(nsIDOMCSSValue** aValue)
1700 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1701 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1703 nscolor color;
1704 #ifdef GFX_HAS_INVERT
1705 GetStyleOutline()->GetOutlineColor(color);
1706 #else
1707 if (!GetStyleOutline()->GetOutlineColor(color))
1708 color = GetStyleColor()->mColor;
1709 #endif
1711 nsresult rv = SetToRGBAColor(val, color);
1712 if (NS_FAILED(rv)) {
1713 delete val;
1714 return rv;
1717 return CallQueryInterface(val, aValue);
1720 nsresult
1721 nsComputedDOMStyle::GetOutlineRadiusFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
1723 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1724 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1726 SetValueToCoord(val, GetStyleOutline()->mOutlineRadius.Get(aSide),
1727 &nsComputedDOMStyle::GetFrameBorderRectWidth);
1729 return CallQueryInterface(val, aValue);
1732 nsresult
1733 nsComputedDOMStyle::GetCSSShadowArray(nsCSSShadowArray* aArray,
1734 const nscolor& aDefaultColor,
1735 PRBool aUsesSpread,
1736 nsIDOMCSSValue** aValue)
1738 if (!aArray) {
1739 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1740 val->SetIdent(nsGkAtoms::none);
1741 return CallQueryInterface(val, aValue);
1744 static nscoord nsCSSShadowItem::* const shadowValuesNoSpread[] = {
1745 &nsCSSShadowItem::mXOffset,
1746 &nsCSSShadowItem::mYOffset,
1747 &nsCSSShadowItem::mRadius
1750 static nscoord nsCSSShadowItem::* const shadowValuesWithSpread[] = {
1751 &nsCSSShadowItem::mXOffset,
1752 &nsCSSShadowItem::mYOffset,
1753 &nsCSSShadowItem::mRadius,
1754 &nsCSSShadowItem::mSpread
1757 nscoord nsCSSShadowItem::* const * shadowValues;
1758 PRUint32 shadowValuesLength;
1759 if (aUsesSpread) {
1760 shadowValues = shadowValuesWithSpread;
1761 shadowValuesLength = NS_ARRAY_LENGTH(shadowValuesWithSpread);
1762 } else {
1763 shadowValues = shadowValuesNoSpread;
1764 shadowValuesLength = NS_ARRAY_LENGTH(shadowValuesNoSpread);
1767 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_TRUE);
1768 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
1770 for (nsCSSShadowItem *item = aArray->ShadowAt(0),
1771 *item_end = item + aArray->Length();
1772 item < item_end; ++item) {
1773 nsDOMCSSValueList *itemList = GetROCSSValueList(PR_FALSE);
1774 if (!itemList || !valueList->AppendCSSValue(itemList)) {
1775 delete itemList;
1776 delete valueList;
1777 return NS_ERROR_OUT_OF_MEMORY;
1780 // Color is either the specified shadow color or the foreground color
1781 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1782 if (!val || !itemList->AppendCSSValue(val)) {
1783 delete val;
1784 delete valueList;
1785 return NS_ERROR_OUT_OF_MEMORY;
1787 nscolor shadowColor;
1788 if (item->mHasColor) {
1789 shadowColor = item->mColor;
1790 } else {
1791 shadowColor = aDefaultColor;
1793 SetToRGBAColor(val, shadowColor);
1795 // Set the offsets, blur radius, and spread if available
1796 for (PRUint32 i = 0; i < shadowValuesLength; ++i) {
1797 val = GetROCSSPrimitiveValue();
1798 if (!val || !itemList->AppendCSSValue(val)) {
1799 delete val;
1800 delete valueList;
1801 return NS_ERROR_OUT_OF_MEMORY;
1803 val->SetAppUnits(item->*(shadowValues[i]));
1807 return CallQueryInterface(valueList, aValue);
1810 nsresult
1811 nsComputedDOMStyle::GetBoxShadow(nsIDOMCSSValue** aValue)
1813 return GetCSSShadowArray(GetStyleBorder()->mBoxShadow,
1814 GetStyleColor()->mColor,
1815 PR_TRUE, aValue);
1818 nsresult
1819 nsComputedDOMStyle::GetZIndex(nsIDOMCSSValue** aValue)
1821 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1822 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1824 SetValueToCoord(val, GetStylePosition()->mZIndex);
1826 return CallQueryInterface(val, aValue);
1829 nsresult
1830 nsComputedDOMStyle::GetListStyleImage(nsIDOMCSSValue** aValue)
1832 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1833 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1835 const nsStyleList* list = GetStyleList();
1837 if (!list->mListStyleImage) {
1838 val->SetIdent(nsGkAtoms::none);
1839 } else {
1840 nsCOMPtr<nsIURI> uri;
1841 if (list->mListStyleImage) {
1842 list->mListStyleImage->GetURI(getter_AddRefs(uri));
1844 val->SetURI(uri);
1847 return CallQueryInterface(val, aValue);
1850 nsresult
1851 nsComputedDOMStyle::GetListStylePosition(nsIDOMCSSValue** aValue)
1853 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1854 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1856 const nsAFlatCString& style =
1857 nsCSSProps::ValueToKeyword(GetStyleList()->mListStylePosition,
1858 nsCSSProps::kListStylePositionKTable);
1859 val->SetIdent(style);
1861 return CallQueryInterface(val, aValue);
1864 nsresult
1865 nsComputedDOMStyle::GetListStyleType(nsIDOMCSSValue** aValue)
1867 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1868 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1870 const nsStyleList *list = GetStyleList();
1872 if (list->mListStyleType == NS_STYLE_LIST_STYLE_NONE) {
1873 val->SetIdent(nsGkAtoms::none);
1874 } else {
1875 const nsAFlatCString& style =
1876 nsCSSProps::ValueToKeyword(list->mListStyleType,
1877 nsCSSProps::kListStyleKTable);
1878 val->SetIdent(style);
1881 return CallQueryInterface(val, aValue);
1884 nsresult
1885 nsComputedDOMStyle::GetImageRegion(nsIDOMCSSValue** aValue)
1887 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1888 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1890 const nsStyleList* list = GetStyleList();
1892 nsresult rv = NS_OK;
1893 nsROCSSPrimitiveValue *topVal = nsnull;
1894 nsROCSSPrimitiveValue *rightVal = nsnull;
1895 nsROCSSPrimitiveValue *bottomVal = nsnull;
1896 nsROCSSPrimitiveValue *leftVal = nsnull;
1897 if (list->mImageRegion.width <= 0 || list->mImageRegion.height <= 0) {
1898 val->SetIdent(nsGkAtoms::_auto);
1899 } else {
1900 // create the cssvalues for the sides, stick them in the rect object
1901 topVal = GetROCSSPrimitiveValue();
1902 rightVal = GetROCSSPrimitiveValue();
1903 bottomVal = GetROCSSPrimitiveValue();
1904 leftVal = GetROCSSPrimitiveValue();
1905 if (topVal && rightVal && bottomVal && leftVal) {
1906 nsDOMCSSRect * domRect = new nsDOMCSSRect(topVal, rightVal,
1907 bottomVal, leftVal);
1908 if (domRect) {
1909 topVal->SetAppUnits(list->mImageRegion.y);
1910 rightVal->SetAppUnits(list->mImageRegion.width + list->mImageRegion.x);
1911 bottomVal->SetAppUnits(list->mImageRegion.height + list->mImageRegion.y);
1912 leftVal->SetAppUnits(list->mImageRegion.x);
1913 val->SetRect(domRect);
1914 } else {
1915 rv = NS_ERROR_OUT_OF_MEMORY;
1917 } else {
1918 rv = NS_ERROR_OUT_OF_MEMORY;
1922 if (NS_FAILED(rv)) {
1923 delete topVal;
1924 delete rightVal;
1925 delete bottomVal;
1926 delete leftVal;
1927 delete val;
1929 return rv;
1932 return CallQueryInterface(val, aValue);
1935 nsresult
1936 nsComputedDOMStyle::GetLineHeight(nsIDOMCSSValue** aValue)
1938 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1939 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1941 nscoord lineHeight;
1942 GetLineHeightCoord(lineHeight);
1943 val->SetAppUnits(lineHeight);
1945 return CallQueryInterface(val, aValue);
1948 nsresult
1949 nsComputedDOMStyle::GetVerticalAlign(nsIDOMCSSValue** aValue)
1951 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
1952 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1954 SetValueToCoord(val, GetStyleTextReset()->mVerticalAlign,
1955 &nsComputedDOMStyle::GetLineHeightCoord,
1956 nsCSSProps::kVerticalAlignKTable);
1958 return CallQueryInterface(val, aValue);
1961 nsresult
1962 nsComputedDOMStyle::GetTextAlign(nsIDOMCSSValue** aValue)
1964 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1965 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1967 const nsAFlatCString& align=
1968 nsCSSProps::ValueToKeyword(GetStyleText()->mTextAlign,
1969 nsCSSProps::kTextAlignKTable);
1970 val->SetIdent(align);
1972 return CallQueryInterface(val, aValue);
1975 nsresult
1976 nsComputedDOMStyle::GetTextDecoration(nsIDOMCSSValue** aValue)
1978 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
1979 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
1981 const nsStyleTextReset* text = GetStyleTextReset();
1983 if (NS_STYLE_TEXT_DECORATION_NONE == text->mTextDecoration) {
1984 const nsAFlatCString& decoration=
1985 nsCSSKeywords::GetStringValue(eCSSKeyword_none);
1986 val->SetIdent(decoration);
1987 } else {
1988 nsAutoString decorationString;
1989 if (text->mTextDecoration & NS_STYLE_TEXT_DECORATION_UNDERLINE) {
1990 const nsAFlatCString& decoration=
1991 nsCSSProps::ValueToKeyword(NS_STYLE_TEXT_DECORATION_UNDERLINE,
1992 nsCSSProps::kTextDecorationKTable);
1993 decorationString.AppendWithConversion(decoration.get());
1995 if (text->mTextDecoration & NS_STYLE_TEXT_DECORATION_OVERLINE) {
1996 if (!decorationString.IsEmpty()) {
1997 decorationString.Append(PRUnichar(' '));
1999 const nsAFlatCString& decoration=
2000 nsCSSProps::ValueToKeyword(NS_STYLE_TEXT_DECORATION_OVERLINE,
2001 nsCSSProps::kTextDecorationKTable);
2002 decorationString.AppendWithConversion(decoration.get());
2004 if (text->mTextDecoration & NS_STYLE_TEXT_DECORATION_LINE_THROUGH) {
2005 if (!decorationString.IsEmpty()) {
2006 decorationString.Append(PRUnichar(' '));
2008 const nsAFlatCString& decoration=
2009 nsCSSProps::ValueToKeyword(NS_STYLE_TEXT_DECORATION_LINE_THROUGH,
2010 nsCSSProps::kTextDecorationKTable);
2011 decorationString.AppendWithConversion(decoration.get());
2013 if (text->mTextDecoration & NS_STYLE_TEXT_DECORATION_BLINK) {
2014 if (!decorationString.IsEmpty()) {
2015 decorationString.Append(PRUnichar(' '));
2017 const nsAFlatCString& decoration=
2018 nsCSSProps::ValueToKeyword(NS_STYLE_TEXT_DECORATION_BLINK,
2019 nsCSSProps::kTextDecorationKTable);
2020 decorationString.AppendWithConversion(decoration.get());
2022 val->SetString(decorationString);
2025 return CallQueryInterface(val, aValue);
2028 nsresult
2029 nsComputedDOMStyle::GetTextIndent(nsIDOMCSSValue** aValue)
2031 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2032 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2034 SetValueToCoord(val, GetStyleText()->mTextIndent,
2035 &nsComputedDOMStyle::GetCBContentWidth);
2037 return CallQueryInterface(val, aValue);
2040 nsresult
2041 nsComputedDOMStyle::GetTextShadow(nsIDOMCSSValue** aValue)
2043 return GetCSSShadowArray(GetStyleText()->mTextShadow,
2044 GetStyleColor()->mColor,
2045 PR_FALSE, aValue);
2048 nsresult
2049 nsComputedDOMStyle::GetTextTransform(nsIDOMCSSValue** aValue)
2051 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2052 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2054 const nsStyleText *text = GetStyleText();
2056 if (text->mTextTransform != NS_STYLE_TEXT_TRANSFORM_NONE) {
2057 const nsAFlatCString& textTransform =
2058 nsCSSProps::ValueToKeyword(text->mTextTransform,
2059 nsCSSProps::kTextTransformKTable);
2060 val->SetIdent(textTransform);
2061 } else {
2062 val->SetIdent(nsGkAtoms::none);
2065 return CallQueryInterface(val, aValue);
2068 nsresult
2069 nsComputedDOMStyle::GetLetterSpacing(nsIDOMCSSValue** aValue)
2071 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2072 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2074 SetValueToCoord(val, GetStyleText()->mLetterSpacing);
2076 return CallQueryInterface(val, aValue);
2079 nsresult
2080 nsComputedDOMStyle::GetWordSpacing(nsIDOMCSSValue** aValue)
2082 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2083 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2085 SetValueToCoord(val, GetStyleText()->mWordSpacing);
2087 return CallQueryInterface(val, aValue);
2090 nsresult
2091 nsComputedDOMStyle::GetWhiteSpace(nsIDOMCSSValue** aValue)
2093 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2094 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2096 const nsStyleText *text = GetStyleText();
2098 if (text->mWhiteSpace != NS_STYLE_WHITESPACE_NORMAL) {
2099 const nsAFlatCString& whiteSpace =
2100 nsCSSProps::ValueToKeyword(text->mWhiteSpace,
2101 nsCSSProps::kWhitespaceKTable);
2102 val->SetIdent(whiteSpace);
2103 } else {
2104 val->SetIdent(nsGkAtoms::normal);
2107 return CallQueryInterface(val, aValue);
2110 nsresult
2111 nsComputedDOMStyle::GetWordWrap(nsIDOMCSSValue** aValue)
2113 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2114 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2116 const nsStyleText *text = GetStyleText();
2118 if (text->mWordWrap != NS_STYLE_WORDWRAP_NORMAL) {
2119 const nsAFlatCString& wordWrap =
2120 nsCSSProps::ValueToKeyword(text->mWordWrap,
2121 nsCSSProps::kWordwrapKTable);
2122 val->SetIdent(wordWrap);
2123 } else {
2124 val->SetIdent(nsGkAtoms::normal);
2127 return CallQueryInterface(val, aValue);
2130 nsresult
2131 nsComputedDOMStyle::GetVisibility(nsIDOMCSSValue** aValue)
2133 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
2134 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2136 const nsAFlatCString& value=
2137 nsCSSProps::ValueToKeyword(GetStyleVisibility()->mVisible,
2138 nsCSSProps::kVisibilityKTable);
2139 val->SetIdent(value);
2141 return CallQueryInterface(val, aValue);
2144 nsresult
2145 nsComputedDOMStyle::GetDirection(nsIDOMCSSValue** aValue)
2147 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2148 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2150 const nsAFlatCString & direction =
2151 nsCSSProps::ValueToKeyword(GetStyleVisibility()->mDirection,
2152 nsCSSProps::kDirectionKTable);
2153 val->SetIdent(direction);
2155 return CallQueryInterface(val, aValue);
2158 nsresult
2159 nsComputedDOMStyle::GetUnicodeBidi(nsIDOMCSSValue** aValue)
2161 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2162 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2164 const nsStyleTextReset *text = GetStyleTextReset();
2166 if (text->mUnicodeBidi != NS_STYLE_UNICODE_BIDI_NORMAL) {
2167 const nsAFlatCString& bidi =
2168 nsCSSProps::ValueToKeyword(text->mUnicodeBidi,
2169 nsCSSProps::kUnicodeBidiKTable);
2170 val->SetIdent(bidi);
2171 } else {
2172 val->SetIdent(nsGkAtoms::normal);
2175 return CallQueryInterface(val, aValue);
2178 nsresult
2179 nsComputedDOMStyle::GetCursor(nsIDOMCSSValue** aValue)
2181 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_TRUE);
2182 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
2184 const nsStyleUserInterface *ui = GetStyleUserInterface();
2186 for (nsCursorImage *item = ui->mCursorArray,
2187 *item_end = ui->mCursorArray + ui->mCursorArrayLength;
2188 item < item_end; ++item) {
2189 nsDOMCSSValueList *itemList = GetROCSSValueList(PR_FALSE);
2190 if (!itemList || !valueList->AppendCSSValue(itemList)) {
2191 delete itemList;
2192 delete valueList;
2193 return NS_ERROR_OUT_OF_MEMORY;
2196 nsCOMPtr<nsIURI> uri;
2197 item->mImage->GetURI(getter_AddRefs(uri));
2199 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2200 if (!val || !itemList->AppendCSSValue(val)) {
2201 delete val;
2202 delete valueList;
2203 return NS_ERROR_OUT_OF_MEMORY;
2205 val->SetURI(uri);
2207 if (item->mHaveHotspot) {
2208 nsROCSSPrimitiveValue *valX = GetROCSSPrimitiveValue();
2209 if (!valX || !itemList->AppendCSSValue(valX)) {
2210 delete valX;
2211 delete valueList;
2212 return NS_ERROR_OUT_OF_MEMORY;
2214 nsROCSSPrimitiveValue *valY = GetROCSSPrimitiveValue();
2215 if (!valY || !itemList->AppendCSSValue(valY)) {
2216 delete valY;
2217 delete valueList;
2218 return NS_ERROR_OUT_OF_MEMORY;
2221 valX->SetNumber(item->mHotspotX);
2222 valY->SetNumber(item->mHotspotY);
2226 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2227 if (!val) {
2228 delete valueList;
2229 return NS_ERROR_OUT_OF_MEMORY;
2232 if (ui->mCursor == NS_STYLE_CURSOR_AUTO) {
2233 val->SetIdent(nsGkAtoms::_auto);
2234 } else {
2235 const nsAFlatCString& cursor =
2236 nsCSSProps::ValueToKeyword(ui->mCursor,
2237 nsCSSProps::kCursorKTable);
2238 val->SetIdent(cursor);
2240 if (!valueList->AppendCSSValue(val)) {
2241 delete valueList;
2242 delete val;
2243 return NS_ERROR_OUT_OF_MEMORY;
2246 return CallQueryInterface(valueList, aValue);
2249 nsresult
2250 nsComputedDOMStyle::GetAppearance(nsIDOMCSSValue** aValue)
2252 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2253 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2255 const nsAFlatCString& appearanceIdent =
2256 nsCSSProps::ValueToKeyword(GetStyleDisplay()->mAppearance,
2257 nsCSSProps::kAppearanceKTable);
2258 val->SetIdent(appearanceIdent);
2260 return CallQueryInterface(val, aValue);
2264 nsresult
2265 nsComputedDOMStyle::GetBoxAlign(nsIDOMCSSValue** aValue)
2267 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2268 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2270 const nsAFlatCString& boxAlignIdent =
2271 nsCSSProps::ValueToKeyword(GetStyleXUL()->mBoxAlign,
2272 nsCSSProps::kBoxAlignKTable);
2273 val->SetIdent(boxAlignIdent);
2275 return CallQueryInterface(val, aValue);
2278 nsresult
2279 nsComputedDOMStyle::GetBoxDirection(nsIDOMCSSValue** aValue)
2281 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2282 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2284 const nsAFlatCString& boxDirectionIdent =
2285 nsCSSProps::ValueToKeyword(GetStyleXUL()->mBoxDirection,
2286 nsCSSProps::kBoxDirectionKTable);
2287 val->SetIdent(boxDirectionIdent);
2289 return CallQueryInterface(val, aValue);
2292 nsresult
2293 nsComputedDOMStyle::GetBoxFlex(nsIDOMCSSValue** aValue)
2295 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2296 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2298 val->SetNumber(GetStyleXUL()->mBoxFlex);
2300 return CallQueryInterface(val, aValue);
2303 nsresult
2304 nsComputedDOMStyle::GetBoxOrdinalGroup(nsIDOMCSSValue** aValue)
2306 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2307 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2309 val->SetNumber(GetStyleXUL()->mBoxOrdinal);
2311 return CallQueryInterface(val, aValue);
2314 nsresult
2315 nsComputedDOMStyle::GetBoxOrient(nsIDOMCSSValue** aValue)
2317 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2318 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2320 const nsAFlatCString& boxOrientIdent =
2321 nsCSSProps::ValueToKeyword(GetStyleXUL()->mBoxOrient,
2322 nsCSSProps::kBoxOrientKTable);
2323 val->SetIdent(boxOrientIdent);
2325 return CallQueryInterface(val, aValue);
2328 nsresult
2329 nsComputedDOMStyle::GetBoxPack(nsIDOMCSSValue** aValue)
2331 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2332 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2334 const nsAFlatCString& boxPackIdent =
2335 nsCSSProps::ValueToKeyword(GetStyleXUL()->mBoxPack,
2336 nsCSSProps::kBoxPackKTable);
2337 val->SetIdent(boxPackIdent);
2339 return CallQueryInterface(val, aValue);
2342 nsresult
2343 nsComputedDOMStyle::GetBoxSizing(nsIDOMCSSValue** aValue)
2345 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2346 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2348 const nsAFlatCString& boxSizingIdent =
2349 nsCSSProps::ValueToKeyword(GetStylePosition()->mBoxSizing,
2350 nsCSSProps::kBoxSizingKTable);
2351 val->SetIdent(boxSizingIdent);
2353 return CallQueryInterface(val, aValue);
2356 nsresult
2357 nsComputedDOMStyle::GetBorderImage(nsIDOMCSSValue** aValue)
2359 const nsStyleBorder* border = GetStyleBorder();
2361 // none
2362 if (!border->GetBorderImage()) {
2363 nsROCSSPrimitiveValue *valNone = GetROCSSPrimitiveValue();
2364 NS_ENSURE_TRUE(valNone, NS_ERROR_OUT_OF_MEMORY);
2365 valNone->SetIdent(nsGkAtoms::none);
2366 return CallQueryInterface(valNone, aValue);
2369 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
2370 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
2372 // uri
2373 nsROCSSPrimitiveValue *valURI = GetROCSSPrimitiveValue();
2374 if (!valURI || !valueList->AppendCSSValue(valURI)) {
2375 delete valURI;
2376 delete valueList;
2377 return NS_ERROR_OUT_OF_MEMORY;
2379 nsCOMPtr<nsIURI> uri;
2380 border->GetBorderImage()->GetURI(getter_AddRefs(uri));
2381 valURI->SetURI(uri);
2383 // four split numbers
2384 NS_FOR_CSS_SIDES(side) {
2385 nsROCSSPrimitiveValue *valSplit = GetROCSSPrimitiveValue();
2386 if (!valSplit || !valueList->AppendCSSValue(valSplit)) {
2387 delete valSplit;
2388 delete valueList;
2389 return NS_ERROR_OUT_OF_MEMORY;
2391 SetValueToCoord(valSplit, border->mBorderImageSplit.Get(side), nsnull,
2392 nsnull);
2395 // copy of border-width
2396 if (border->mHaveBorderImageWidth) {
2397 nsROCSSPrimitiveValue *slash = GetROCSSPrimitiveValue();
2398 if (!slash || !valueList->AppendCSSValue(slash)) {
2399 delete slash;
2400 delete valueList;
2401 return NS_ERROR_OUT_OF_MEMORY;
2403 slash->SetString(NS_LITERAL_STRING("/"));
2404 NS_FOR_CSS_SIDES(side) {
2405 nsROCSSPrimitiveValue *borderWidth = GetROCSSPrimitiveValue();
2406 if (!borderWidth || !valueList->AppendCSSValue(borderWidth)) {
2407 delete borderWidth;
2408 delete valueList;
2409 return NS_ERROR_OUT_OF_MEMORY;
2411 nscoord width = GetStyleBorder()->mBorderImageWidth.side(side);
2412 borderWidth->SetAppUnits(width);
2416 // first keyword
2417 nsROCSSPrimitiveValue *keyword = GetROCSSPrimitiveValue();
2418 if (!keyword || !valueList->AppendCSSValue(keyword)) {
2419 delete keyword;
2420 delete valueList;
2421 return NS_ERROR_OUT_OF_MEMORY;
2423 const nsAFlatCString& borderImageIdent =
2424 nsCSSProps::ValueToKeyword(GetStyleBorder()->mBorderImageHFill,
2425 nsCSSProps::kBorderImageKTable);
2426 keyword->SetIdent(borderImageIdent);
2428 // second keyword
2429 nsROCSSPrimitiveValue *keyword2 = GetROCSSPrimitiveValue();
2430 if (!keyword2 || !valueList->AppendCSSValue(keyword2)) {
2431 delete keyword2;
2432 delete valueList;
2433 return NS_ERROR_OUT_OF_MEMORY;
2435 const nsAFlatCString& borderImageIdent2 =
2436 nsCSSProps::ValueToKeyword(GetStyleBorder()->mBorderImageVFill,
2437 nsCSSProps::kBorderImageKTable);
2438 keyword2->SetIdent(borderImageIdent2);
2440 return CallQueryInterface(valueList, aValue);
2443 nsresult
2444 nsComputedDOMStyle::GetFloatEdge(nsIDOMCSSValue** aValue)
2446 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2447 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2449 const nsAFlatCString& floatEdgeIdent =
2450 nsCSSProps::ValueToKeyword(GetStyleBorder()->mFloatEdge,
2451 nsCSSProps::kFloatEdgeKTable);
2452 val->SetIdent(floatEdgeIdent);
2454 return CallQueryInterface(val, aValue);
2457 nsresult
2458 nsComputedDOMStyle::GetForceBrokenImageIcon(nsIDOMCSSValue** aValue)
2460 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2461 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2463 val->SetNumber(GetStyleUIReset()->mForceBrokenImageIcon);
2465 return CallQueryInterface(val, aValue);
2468 nsresult
2469 nsComputedDOMStyle::GetIMEMode(nsIDOMCSSValue** aValue)
2471 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2472 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2474 const nsStyleUIReset *uiData = GetStyleUIReset();
2476 nsCSSKeyword keyword;
2477 if (uiData->mIMEMode == NS_STYLE_IME_MODE_AUTO) {
2478 keyword = eCSSKeyword_auto;
2479 } else if (uiData->mIMEMode == NS_STYLE_IME_MODE_NORMAL) {
2480 keyword = eCSSKeyword_normal;
2481 } else {
2482 keyword = nsCSSProps::ValueToKeywordEnum(uiData->mIMEMode,
2483 nsCSSProps::kIMEModeKTable);
2485 val->SetIdent(nsCSSKeywords::GetStringValue(keyword));
2487 return CallQueryInterface(val, aValue);
2490 nsresult
2491 nsComputedDOMStyle::GetUserFocus(nsIDOMCSSValue** aValue)
2493 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2494 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2496 const nsStyleUserInterface *uiData = GetStyleUserInterface();
2498 if (uiData->mUserFocus != NS_STYLE_USER_FOCUS_NONE) {
2499 if (uiData->mUserFocus == NS_STYLE_USER_FOCUS_NORMAL) {
2500 const nsAFlatCString& userFocusIdent =
2501 nsCSSKeywords::GetStringValue(eCSSKeyword_normal);
2502 val->SetIdent(userFocusIdent);
2503 } else {
2504 const nsAFlatCString& userFocusIdent =
2505 nsCSSProps::ValueToKeyword(uiData->mUserFocus,
2506 nsCSSProps::kUserFocusKTable);
2507 val->SetIdent(userFocusIdent);
2509 } else {
2510 const nsAFlatCString& userFocusIdent =
2511 nsCSSKeywords::GetStringValue(eCSSKeyword_none);
2512 val->SetIdent(userFocusIdent);
2515 return CallQueryInterface(val, aValue);
2518 nsresult
2519 nsComputedDOMStyle::GetUserInput(nsIDOMCSSValue** aValue)
2521 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2522 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2524 const nsStyleUserInterface *uiData = GetStyleUserInterface();
2526 if (uiData->mUserInput != NS_STYLE_USER_INPUT_AUTO) {
2527 if (uiData->mUserInput == NS_STYLE_USER_INPUT_NONE) {
2528 const nsAFlatCString& userInputIdent =
2529 nsCSSKeywords::GetStringValue(eCSSKeyword_none);
2530 val->SetIdent(userInputIdent);
2531 } else {
2532 const nsAFlatCString& userInputIdent =
2533 nsCSSProps::ValueToKeyword(uiData->mUserInput,
2534 nsCSSProps::kUserInputKTable);
2535 val->SetIdent(userInputIdent);
2537 } else {
2538 const nsAFlatCString& userInputIdent =
2539 nsCSSKeywords::GetStringValue(eCSSKeyword_auto);
2540 val->SetIdent(userInputIdent);
2543 return CallQueryInterface(val, aValue);
2546 nsresult
2547 nsComputedDOMStyle::GetUserModify(nsIDOMCSSValue** aValue)
2549 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2550 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2552 const nsAFlatCString& userModifyIdent =
2553 nsCSSProps::ValueToKeyword(GetStyleUserInterface()->mUserModify,
2554 nsCSSProps::kUserModifyKTable);
2555 val->SetIdent(userModifyIdent);
2557 return CallQueryInterface(val, aValue);
2560 nsresult
2561 nsComputedDOMStyle::GetUserSelect(nsIDOMCSSValue** aValue)
2563 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2564 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2566 const nsStyleUIReset *uiData = GetStyleUIReset();
2568 if (uiData->mUserSelect != NS_STYLE_USER_SELECT_AUTO) {
2569 if (uiData->mUserSelect == NS_STYLE_USER_SELECT_NONE) {
2570 const nsAFlatCString& userSelectIdent =
2571 nsCSSKeywords::GetStringValue(eCSSKeyword_none);
2572 val->SetIdent(userSelectIdent);
2573 } else {
2574 const nsAFlatCString& userSelectIdent =
2575 nsCSSProps::ValueToKeyword(uiData->mUserSelect,
2576 nsCSSProps::kUserSelectKTable);
2577 val->SetIdent(userSelectIdent);
2579 } else {
2580 const nsAFlatCString& userSelectIdent =
2581 nsCSSKeywords::GetStringValue(eCSSKeyword_auto);
2582 val->SetIdent(userSelectIdent);
2585 return CallQueryInterface(val, aValue);
2588 nsresult
2589 nsComputedDOMStyle::GetDisplay(nsIDOMCSSValue** aValue)
2591 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2592 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2594 const nsStyleDisplay *displayData = GetStyleDisplay();
2596 if (displayData->mDisplay == NS_STYLE_DISPLAY_NONE) {
2597 val->SetIdent(nsGkAtoms::none);
2598 } else {
2599 const nsAFlatCString& display =
2600 nsCSSProps::ValueToKeyword(displayData->mDisplay,
2601 nsCSSProps::kDisplayKTable);
2602 val->SetIdent(display);
2605 return CallQueryInterface(val, aValue);
2608 nsresult
2609 nsComputedDOMStyle::GetPosition(nsIDOMCSSValue** aValue)
2611 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2612 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2614 const nsAFlatCString& position =
2615 nsCSSProps::ValueToKeyword(GetStyleDisplay()->mPosition,
2616 nsCSSProps::kPositionKTable);
2617 val->SetIdent(position);
2619 return CallQueryInterface(val, aValue);
2622 nsresult
2623 nsComputedDOMStyle::GetClip(nsIDOMCSSValue** aValue)
2625 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2626 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2628 const nsStyleDisplay* display = GetStyleDisplay();
2630 nsresult rv = NS_OK;
2631 nsROCSSPrimitiveValue *topVal = nsnull;
2632 nsROCSSPrimitiveValue *rightVal = nsnull;
2633 nsROCSSPrimitiveValue *bottomVal = nsnull;
2634 nsROCSSPrimitiveValue *leftVal = nsnull;
2635 if (display->mClipFlags == NS_STYLE_CLIP_AUTO ||
2636 display->mClipFlags == (NS_STYLE_CLIP_TOP_AUTO |
2637 NS_STYLE_CLIP_RIGHT_AUTO |
2638 NS_STYLE_CLIP_BOTTOM_AUTO |
2639 NS_STYLE_CLIP_LEFT_AUTO)) {
2640 val->SetIdent(nsGkAtoms::_auto);
2641 } else {
2642 // create the cssvalues for the sides, stick them in the rect object
2643 topVal = GetROCSSPrimitiveValue();
2644 rightVal = GetROCSSPrimitiveValue();
2645 bottomVal = GetROCSSPrimitiveValue();
2646 leftVal = GetROCSSPrimitiveValue();
2647 if (topVal && rightVal && bottomVal && leftVal) {
2648 nsDOMCSSRect * domRect = new nsDOMCSSRect(topVal, rightVal,
2649 bottomVal, leftVal);
2650 if (domRect) {
2651 if (display->mClipFlags & NS_STYLE_CLIP_TOP_AUTO) {
2652 topVal->SetIdent(nsGkAtoms::_auto);
2653 } else {
2654 topVal->SetAppUnits(display->mClip.y);
2657 if (display->mClipFlags & NS_STYLE_CLIP_RIGHT_AUTO) {
2658 rightVal->SetIdent(nsGkAtoms::_auto);
2659 } else {
2660 rightVal->SetAppUnits(display->mClip.width + display->mClip.x);
2663 if (display->mClipFlags & NS_STYLE_CLIP_BOTTOM_AUTO) {
2664 bottomVal->SetIdent(nsGkAtoms::_auto);
2665 } else {
2666 bottomVal->SetAppUnits(display->mClip.height + display->mClip.y);
2669 if (display->mClipFlags & NS_STYLE_CLIP_LEFT_AUTO) {
2670 leftVal->SetIdent(nsGkAtoms::_auto);
2671 } else {
2672 leftVal->SetAppUnits(display->mClip.x);
2675 val->SetRect(domRect);
2676 } else {
2677 rv = NS_ERROR_OUT_OF_MEMORY;
2679 } else {
2680 rv = NS_ERROR_OUT_OF_MEMORY;
2684 if (NS_FAILED(rv)) {
2685 delete topVal;
2686 delete rightVal;
2687 delete bottomVal;
2688 delete leftVal;
2689 delete val;
2691 return rv;
2694 return CallQueryInterface(val, aValue);
2697 nsresult
2698 nsComputedDOMStyle::GetOverflow(nsIDOMCSSValue** aValue)
2700 const nsStyleDisplay* display = GetStyleDisplay();
2702 if (display->mOverflowX != display->mOverflowY) {
2703 // No value to return. We can't express this combination of
2704 // values as a shorthand.
2705 *aValue = nsnull;
2706 return NS_OK;
2709 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
2710 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2712 if (display->mOverflowX != NS_STYLE_OVERFLOW_AUTO) {
2713 const nsAFlatCString& overflow =
2714 nsCSSProps::ValueToKeyword(display->mOverflowX,
2715 nsCSSProps::kOverflowKTable);
2716 val->SetIdent(overflow);
2717 } else {
2718 val->SetIdent(nsGkAtoms::_auto);
2721 return CallQueryInterface(val, aValue);
2724 nsresult
2725 nsComputedDOMStyle::GetOverflowX(nsIDOMCSSValue** aValue)
2727 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
2728 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2730 const nsStyleDisplay* display = GetStyleDisplay();
2732 if (display->mOverflowX != NS_STYLE_OVERFLOW_AUTO) {
2733 const nsAFlatCString& overflow =
2734 nsCSSProps::ValueToKeyword(display->mOverflowX,
2735 nsCSSProps::kOverflowSubKTable);
2736 val->SetIdent(overflow);
2737 } else {
2738 val->SetIdent(nsGkAtoms::_auto);
2741 return CallQueryInterface(val, aValue);
2744 nsresult
2745 nsComputedDOMStyle::GetOverflowY(nsIDOMCSSValue** aValue)
2747 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
2748 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2750 const nsStyleDisplay* display = GetStyleDisplay();
2752 if (display->mOverflowY != NS_STYLE_OVERFLOW_AUTO) {
2753 const nsAFlatCString& overflow =
2754 nsCSSProps::ValueToKeyword(display->mOverflowY,
2755 nsCSSProps::kOverflowSubKTable);
2756 val->SetIdent(overflow);
2757 } else {
2758 val->SetIdent(nsGkAtoms::_auto);
2761 return CallQueryInterface(val, aValue);
2764 nsresult
2765 nsComputedDOMStyle::GetPageBreakAfter(nsIDOMCSSValue** aValue)
2767 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2768 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2770 const nsStyleDisplay *display = GetStyleDisplay();
2772 if (display->mBreakAfter) {
2773 val->SetIdent(nsGkAtoms::always);
2774 } else {
2775 val->SetIdent(nsGkAtoms::_auto);
2778 return CallQueryInterface(val, aValue);
2781 nsresult
2782 nsComputedDOMStyle::GetPageBreakBefore(nsIDOMCSSValue** aValue)
2784 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2785 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2787 const nsStyleDisplay *display = GetStyleDisplay();
2789 if (display->mBreakBefore) {
2790 val->SetIdent(nsGkAtoms::always);
2791 } else {
2792 val->SetIdent(nsGkAtoms::_auto);
2795 return CallQueryInterface(val, aValue);
2798 nsresult
2799 nsComputedDOMStyle::GetHeight(nsIDOMCSSValue** aValue)
2801 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2802 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2804 PRBool calcHeight = PR_FALSE;
2806 if (mInnerFrame) {
2807 calcHeight = PR_TRUE;
2809 const nsStyleDisplay* displayData = GetStyleDisplay();
2810 if (displayData->mDisplay == NS_STYLE_DISPLAY_INLINE &&
2811 !(mInnerFrame->IsFrameOfType(nsIFrame::eReplaced))) {
2812 calcHeight = PR_FALSE;
2816 if (calcHeight) {
2817 FlushPendingReflows();
2819 val->SetAppUnits(mInnerFrame->GetContentRect().height);
2820 } else {
2821 const nsStylePosition *positionData = GetStylePosition();
2823 nscoord minHeight =
2824 StyleCoordToNSCoord(positionData->mMinHeight,
2825 &nsComputedDOMStyle::GetCBContentHeight, 0);
2827 nscoord maxHeight =
2828 StyleCoordToNSCoord(positionData->mMaxHeight,
2829 &nsComputedDOMStyle::GetCBContentHeight,
2830 nscoord_MAX);
2832 SetValueToCoord(val, positionData->mHeight, nsnull, nsnull,
2833 minHeight, maxHeight);
2836 return CallQueryInterface(val, aValue);
2839 nsresult
2840 nsComputedDOMStyle::GetWidth(nsIDOMCSSValue** aValue)
2842 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2843 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2845 PRBool calcWidth = PR_FALSE;
2847 if (mInnerFrame) {
2848 calcWidth = PR_TRUE;
2850 const nsStyleDisplay *displayData = GetStyleDisplay();
2851 if (displayData->mDisplay == NS_STYLE_DISPLAY_INLINE &&
2852 !(mInnerFrame->IsFrameOfType(nsIFrame::eReplaced))) {
2853 calcWidth = PR_FALSE;
2857 if (calcWidth) {
2858 FlushPendingReflows();
2860 val->SetAppUnits(mInnerFrame->GetContentRect().width);
2861 } else {
2862 const nsStylePosition *positionData = GetStylePosition();
2864 nscoord minWidth =
2865 StyleCoordToNSCoord(positionData->mMinWidth,
2866 &nsComputedDOMStyle::GetCBContentWidth, 0);
2868 nscoord maxWidth =
2869 StyleCoordToNSCoord(positionData->mMaxWidth,
2870 &nsComputedDOMStyle::GetCBContentWidth,
2871 nscoord_MAX);
2873 SetValueToCoord(val, positionData->mWidth, nsnull,
2874 nsCSSProps::kWidthKTable, minWidth, maxWidth);
2877 return CallQueryInterface(val, aValue);
2880 nsresult
2881 nsComputedDOMStyle::GetMaxHeight(nsIDOMCSSValue** aValue)
2883 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2884 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2886 SetValueToCoord(val, GetStylePosition()->mMaxHeight,
2887 &nsComputedDOMStyle::GetCBContentHeight);
2889 return CallQueryInterface(val, aValue);
2892 nsresult
2893 nsComputedDOMStyle::GetMaxWidth(nsIDOMCSSValue** aValue)
2895 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2896 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2898 SetValueToCoord(val, GetStylePosition()->mMaxWidth,
2899 &nsComputedDOMStyle::GetCBContentWidth,
2900 nsCSSProps::kWidthKTable);
2902 return CallQueryInterface(val, aValue);
2905 nsresult
2906 nsComputedDOMStyle::GetMinHeight(nsIDOMCSSValue** aValue)
2908 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2909 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2911 SetValueToCoord(val, GetStylePosition()->mMinHeight,
2912 &nsComputedDOMStyle::GetCBContentHeight);
2914 return CallQueryInterface(val, aValue);
2917 nsresult
2918 nsComputedDOMStyle::GetMinWidth(nsIDOMCSSValue** aValue)
2920 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2921 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
2923 SetValueToCoord(val, GetStylePosition()->mMinWidth,
2924 &nsComputedDOMStyle::GetCBContentWidth,
2925 nsCSSProps::kWidthKTable);
2927 return CallQueryInterface(val, aValue);
2930 nsresult
2931 nsComputedDOMStyle::GetLeft(nsIDOMCSSValue** aValue)
2933 return GetOffsetWidthFor(NS_SIDE_LEFT, aValue);
2936 nsresult
2937 nsComputedDOMStyle::GetRight(nsIDOMCSSValue** aValue)
2939 return GetOffsetWidthFor(NS_SIDE_RIGHT, aValue);
2942 nsresult
2943 nsComputedDOMStyle::GetTop(nsIDOMCSSValue** aValue)
2945 return GetOffsetWidthFor(NS_SIDE_TOP, aValue);
2948 nsROCSSPrimitiveValue*
2949 nsComputedDOMStyle::GetROCSSPrimitiveValue()
2951 nsROCSSPrimitiveValue *primitiveValue = new nsROCSSPrimitiveValue(mAppUnitsPerInch);
2953 NS_ASSERTION(primitiveValue != 0, "ran out of memory");
2955 return primitiveValue;
2958 nsDOMCSSValueList*
2959 nsComputedDOMStyle::GetROCSSValueList(PRBool aCommaDelimited)
2961 nsDOMCSSValueList *valueList = new nsDOMCSSValueList(aCommaDelimited,
2962 PR_TRUE);
2963 NS_ASSERTION(valueList != 0, "ran out of memory");
2965 return valueList;
2968 nsresult
2969 nsComputedDOMStyle::GetOffsetWidthFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
2971 const nsStyleDisplay* display = GetStyleDisplay();
2973 FlushPendingReflows();
2975 nsresult rv = NS_OK;
2976 switch (display->mPosition) {
2977 case NS_STYLE_POSITION_STATIC:
2978 rv = GetStaticOffset(aSide, aValue);
2979 break;
2980 case NS_STYLE_POSITION_RELATIVE:
2981 rv = GetRelativeOffset(aSide, aValue);
2982 break;
2983 case NS_STYLE_POSITION_ABSOLUTE:
2984 case NS_STYLE_POSITION_FIXED:
2985 rv = GetAbsoluteOffset(aSide, aValue);
2986 break;
2987 default:
2988 NS_ERROR("Invalid position");
2989 break;
2992 return rv;
2995 nsresult
2996 nsComputedDOMStyle::GetAbsoluteOffset(PRUint8 aSide, nsIDOMCSSValue** aValue)
2998 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
2999 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3001 nsIFrame* container = GetContainingBlockFor(mOuterFrame);
3002 if (container) {
3003 nsMargin margin = mOuterFrame->GetUsedMargin();
3004 nsMargin border = container->GetUsedBorder();
3005 nsMargin scrollbarSizes(0, 0, 0, 0);
3006 nsRect rect = mOuterFrame->GetRect();
3007 nsRect containerRect = container->GetRect();
3009 if (container->GetType() == nsGkAtoms::viewportFrame) {
3010 // For absolutely positioned frames scrollbars are taken into
3011 // account by virtue of getting a containing block that does
3012 // _not_ include the scrollbars. For fixed positioned frames,
3013 // the containing block is the viewport, which _does_ include
3014 // scrollbars. We have to do some extra work.
3015 // the first child in the default frame list is what we want
3016 nsIFrame* scrollingChild = container->GetFirstChild(nsnull);
3017 nsCOMPtr<nsIScrollableFrame> scrollFrame =
3018 do_QueryInterface(scrollingChild);
3019 if (scrollFrame) {
3020 scrollbarSizes = scrollFrame->GetActualScrollbarSizes();
3024 nscoord offset = 0;
3025 switch (aSide) {
3026 case NS_SIDE_TOP:
3027 offset = rect.y - margin.top - border.top - scrollbarSizes.top;
3029 break;
3030 case NS_SIDE_RIGHT:
3031 offset = containerRect.width - rect.width -
3032 rect.x - margin.right - border.right - scrollbarSizes.right;
3034 break;
3035 case NS_SIDE_BOTTOM:
3036 offset = containerRect.height - rect.height -
3037 rect.y - margin.bottom - border.bottom - scrollbarSizes.bottom;
3039 break;
3040 case NS_SIDE_LEFT:
3041 offset = rect.x - margin.left - border.left - scrollbarSizes.left;
3043 break;
3044 default:
3045 NS_ERROR("Invalid side");
3046 break;
3048 val->SetAppUnits(offset);
3049 } else {
3050 // XXX no frame. This property makes no sense
3051 val->SetAppUnits(0);
3054 return CallQueryInterface(val, aValue);
3058 #if (NS_SIDE_TOP == 0) && (NS_SIDE_RIGHT == 1) && (NS_SIDE_BOTTOM == 2) && (NS_SIDE_LEFT == 3)
3059 #define NS_OPPOSITE_SIDE(s_) (((s_) + 2) & 3)
3060 #else
3061 #error "Somebody changed the side constants."
3062 #endif
3064 nsresult
3065 nsComputedDOMStyle::GetRelativeOffset(PRUint8 aSide, nsIDOMCSSValue** aValue)
3067 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3068 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3070 const nsStylePosition* positionData = GetStylePosition();
3071 PRInt32 sign = 1;
3072 nsStyleCoord coord = positionData->mOffset.Get(aSide);
3074 NS_ASSERTION(coord.GetUnit() == eStyleUnit_Coord ||
3075 coord.GetUnit() == eStyleUnit_Percent ||
3076 coord.GetUnit() == eStyleUnit_Auto,
3077 "Unexpected unit");
3079 if (coord.GetUnit() == eStyleUnit_Auto) {
3080 coord = positionData->mOffset.Get(NS_OPPOSITE_SIDE(aSide));
3081 sign = -1;
3083 PercentageBaseGetter baseGetter;
3084 if (aSide == NS_SIDE_LEFT || aSide == NS_SIDE_RIGHT) {
3085 baseGetter = &nsComputedDOMStyle::GetCBContentWidth;
3086 } else {
3087 baseGetter = &nsComputedDOMStyle::GetCBContentHeight;
3090 val->SetAppUnits(sign * StyleCoordToNSCoord(coord, baseGetter, 0));
3092 return CallQueryInterface(val, aValue);
3095 nsresult
3096 nsComputedDOMStyle::GetStaticOffset(PRUint8 aSide, nsIDOMCSSValue** aValue)
3099 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3100 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3102 SetValueToCoord(val, GetStylePosition()->mOffset.Get(aSide));
3104 return CallQueryInterface(val, aValue);
3107 void
3108 nsComputedDOMStyle::FlushPendingReflows()
3110 // Flush all pending notifications so that our frames are up to date
3111 nsCOMPtr<nsIDocument> document = mContent->GetDocument();
3112 if (document) {
3113 document->FlushPendingNotifications(Flush_Layout);
3117 nsresult
3118 nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
3120 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3121 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3123 if (!mInnerFrame) {
3124 SetValueToCoord(val, GetStylePadding()->mPadding.Get(aSide));
3125 } else {
3126 FlushPendingReflows();
3128 val->SetAppUnits(mInnerFrame->GetUsedPadding().side(aSide));
3131 return CallQueryInterface(val, aValue);
3134 PRBool
3135 nsComputedDOMStyle::GetLineHeightCoord(nscoord& aCoord)
3137 aCoord = nsHTMLReflowState::CalcLineHeight(mStyleContextHolder);
3139 // CalcLineHeight uses font->mFont.size, but we want to use
3140 // font->mSize as the font size. Adjust for that. Also adjust for
3141 // the text zoom, if any.
3142 const nsStyleFont* font = GetStyleFont();
3143 aCoord = NSToCoordRound((float(aCoord) *
3144 (float(font->mSize) / float(font->mFont.size))) /
3145 mPresShell->GetPresContext()->TextZoom());
3147 return PR_TRUE;
3150 nsresult
3151 nsComputedDOMStyle::GetBorderColorsFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
3153 const nsStyleBorder *border = GetStyleBorder();
3155 if (border->mBorderColors) {
3156 nsBorderColors* borderColors = border->mBorderColors[aSide];
3157 if (borderColors) {
3158 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
3159 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
3161 do {
3162 nsROCSSPrimitiveValue *primitive = GetROCSSPrimitiveValue();
3163 if (!primitive) {
3164 delete valueList;
3166 return NS_ERROR_OUT_OF_MEMORY;
3168 nsresult rv = SetToRGBAColor(primitive, borderColors->mColor);
3169 if (NS_FAILED(rv)) {
3170 delete valueList;
3171 delete primitive;
3172 return rv;
3175 PRBool success = valueList->AppendCSSValue(primitive);
3176 if (!success) {
3177 delete valueList;
3178 delete primitive;
3180 return NS_ERROR_OUT_OF_MEMORY;
3182 borderColors = borderColors->mNext;
3183 } while (borderColors);
3185 return CallQueryInterface(valueList, aValue);
3189 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3190 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3192 val->SetIdent(nsGkAtoms::none);
3194 return CallQueryInterface(val, aValue);
3197 nsresult
3198 nsComputedDOMStyle::GetBorderRadiusFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
3200 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3201 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3203 SetValueToCoord(val, GetStyleBorder()->mBorderRadius.Get(aSide),
3204 &nsComputedDOMStyle::GetFrameBorderRectWidth);
3206 return CallQueryInterface(val, aValue);
3209 nsresult
3210 nsComputedDOMStyle::GetBorderWidthFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
3212 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3213 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3215 nscoord width;
3216 if (mInnerFrame) {
3217 FlushPendingReflows();
3218 width = mInnerFrame->GetUsedBorder().side(aSide);
3219 } else {
3220 width = GetStyleBorder()->GetActualBorderWidth(aSide);
3222 val->SetAppUnits(width);
3224 return CallQueryInterface(val, aValue);
3227 nsresult
3228 nsComputedDOMStyle::GetBorderColorFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
3230 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3231 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3233 nscolor color;
3234 PRBool foreground;
3235 GetStyleBorder()->GetBorderColor(aSide, color, foreground);
3236 if (foreground) {
3237 color = GetStyleColor()->mColor;
3240 nsresult rv = SetToRGBAColor(val, color);
3241 if (NS_FAILED(rv)) {
3242 delete val;
3243 return rv;
3246 return CallQueryInterface(val, aValue);
3249 nsresult
3250 nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
3252 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3253 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3255 if (!mInnerFrame) {
3256 SetValueToCoord(val, GetStyleMargin()->mMargin.Get(aSide));
3257 } else {
3258 FlushPendingReflows();
3260 val->SetAppUnits(mInnerFrame->GetUsedMargin().side(aSide));
3263 return CallQueryInterface(val, aValue);
3266 nsresult
3267 nsComputedDOMStyle::GetBorderStyleFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
3269 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3270 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3272 PRUint8 borderStyle = GetStyleBorder()->GetBorderStyle(aSide);
3274 if (borderStyle != NS_STYLE_BORDER_STYLE_NONE) {
3275 const nsAFlatCString& style=
3276 nsCSSProps::ValueToKeyword(borderStyle,
3277 nsCSSProps::kBorderStyleKTable);
3278 val->SetIdent(style);
3279 } else {
3280 val->SetIdent(nsGkAtoms::none);
3283 return CallQueryInterface(val, aValue);
3286 void
3287 nsComputedDOMStyle::SetValueToCoord(nsROCSSPrimitiveValue* aValue,
3288 const nsStyleCoord& aCoord,
3289 PercentageBaseGetter aPercentageBaseGetter,
3290 const PRInt32 aTable[],
3291 nscoord aMinAppUnits,
3292 nscoord aMaxAppUnits)
3294 NS_PRECONDITION(aValue, "Must have a value to work with");
3296 switch (aCoord.GetUnit()) {
3297 case eStyleUnit_Normal:
3298 aValue->SetIdent(nsGkAtoms::normal);
3299 break;
3301 case eStyleUnit_Auto:
3302 aValue->SetIdent(nsGkAtoms::_auto);
3303 break;
3305 case eStyleUnit_Percent:
3307 nscoord percentageBase;
3308 if (aPercentageBaseGetter &&
3309 (this->*aPercentageBaseGetter)(percentageBase)) {
3310 nscoord val = nscoord(aCoord.GetPercentValue() * percentageBase);
3311 aValue->SetAppUnits(PR_MAX(aMinAppUnits, PR_MIN(val, aMaxAppUnits)));
3312 } else {
3313 aValue->SetPercent(aCoord.GetPercentValue());
3316 break;
3318 case eStyleUnit_Factor:
3319 aValue->SetNumber(aCoord.GetFactorValue());
3320 break;
3322 case eStyleUnit_Coord:
3324 nscoord val = aCoord.GetCoordValue();
3325 aValue->SetAppUnits(PR_MAX(aMinAppUnits, PR_MIN(val, aMaxAppUnits)));
3327 break;
3329 case eStyleUnit_Integer:
3330 aValue->SetNumber(aCoord.GetIntValue());
3331 break;
3333 case eStyleUnit_Enumerated:
3334 NS_ASSERTION(aTable, "Must have table to handle this case");
3335 aValue->SetIdent(nsCSSProps::ValueToKeyword(aCoord.GetIntValue(),
3336 aTable));
3337 break;
3339 case eStyleUnit_None:
3340 aValue->SetIdent(nsGkAtoms::none);
3341 break;
3343 default:
3344 NS_ERROR("Can't handle this unit");
3345 break;
3349 nscoord
3350 nsComputedDOMStyle::StyleCoordToNSCoord(const nsStyleCoord& aCoord,
3351 PercentageBaseGetter aPercentageBaseGetter,
3352 nscoord aDefaultValue)
3354 NS_PRECONDITION(aPercentageBaseGetter, "Must have a percentage base getter");
3355 switch (aCoord.GetUnit()) {
3356 case eStyleUnit_Coord:
3357 return aCoord.GetCoordValue();
3358 case eStyleUnit_Percent:
3360 nscoord percentageBase;
3361 if ((this->*aPercentageBaseGetter)(percentageBase)) {
3362 return nscoord(aCoord.GetPercentValue() * percentageBase);
3365 // Fall through to returning aDefaultValue if we have no percentage base.
3366 default:
3367 break;
3370 return aDefaultValue;
3373 PRBool
3374 nsComputedDOMStyle::GetCBContentWidth(nscoord& aWidth)
3376 if (!mOuterFrame) {
3377 return PR_FALSE;
3380 nsIFrame* container = GetContainingBlockFor(mOuterFrame);
3381 if (!container) {
3382 return PR_FALSE;
3385 FlushPendingReflows();
3387 aWidth = container->GetContentRect().width;
3388 return PR_TRUE;
3391 PRBool
3392 nsComputedDOMStyle::GetCBContentHeight(nscoord& aHeight)
3394 if (!mOuterFrame) {
3395 return PR_FALSE;
3398 nsIFrame* container = GetContainingBlockFor(mOuterFrame);
3399 if (!container) {
3400 return PR_FALSE;
3403 FlushPendingReflows();
3405 aHeight = container->GetContentRect().height;
3406 return PR_TRUE;
3409 PRBool
3410 nsComputedDOMStyle::GetFrameBorderRectWidth(nscoord& aWidth)
3412 if (!mInnerFrame) {
3413 return PR_FALSE;
3416 FlushPendingReflows();
3418 aWidth = mInnerFrame->GetSize().width;
3419 return PR_TRUE;
3422 PRBool
3423 nsComputedDOMStyle::GetFrameBoundsWidthForTransform(nscoord& aWidth)
3425 // We need a frame to work with.
3426 if (!mInnerFrame) {
3427 return PR_FALSE;
3430 FlushPendingReflows();
3432 // Check to see that we're transformed.
3433 if (!mInnerFrame->GetStyleDisplay()->HasTransform())
3434 return PR_FALSE;
3436 aWidth = nsDisplayTransform::GetFrameBoundsForTransform(mInnerFrame).width;
3437 return PR_TRUE;
3440 PRBool
3441 nsComputedDOMStyle::GetFrameBoundsHeightForTransform(nscoord& aHeight)
3443 // We need a frame to work with.
3444 if (!mInnerFrame) {
3445 return PR_FALSE;
3448 FlushPendingReflows();
3450 // Check to see that we're transformed.
3451 if (!mInnerFrame->GetStyleDisplay()->HasTransform())
3452 return PR_FALSE;
3454 aHeight = nsDisplayTransform::GetFrameBoundsForTransform(mInnerFrame).height;
3455 return PR_TRUE;
3458 #ifdef MOZ_SVG
3460 nsresult
3461 nsComputedDOMStyle::GetSVGPaintFor(PRBool aFill,
3462 nsIDOMCSSValue** aValue)
3464 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3465 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3467 const nsStyleSVG* svg = GetStyleSVG();
3468 const nsStyleSVGPaint* paint = nsnull;
3470 if (aFill)
3471 paint = &svg->mFill;
3472 else
3473 paint = &svg->mStroke;
3475 nsAutoString paintString;
3477 switch (paint->mType) {
3478 case eStyleSVGPaintType_None:
3480 val->SetIdent(nsGkAtoms::none);
3481 break;
3483 case eStyleSVGPaintType_Color:
3485 nsresult rv = SetToRGBAColor(val, paint->mPaint.mColor);
3486 if (NS_FAILED(rv)) {
3487 delete val;
3488 return rv;
3490 break;
3492 case eStyleSVGPaintType_Server:
3494 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_FALSE);
3495 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
3497 if (!valueList->AppendCSSValue(val)) {
3498 delete valueList;
3499 delete val;
3500 return NS_ERROR_OUT_OF_MEMORY;
3503 nsROCSSPrimitiveValue* fallback = GetROCSSPrimitiveValue();
3504 if (!fallback || !valueList->AppendCSSValue(fallback)) {
3505 delete valueList;
3506 delete fallback;
3507 return NS_ERROR_OUT_OF_MEMORY;
3510 val->SetURI(paint->mPaint.mPaintServer);
3511 nsresult rv = SetToRGBAColor(fallback, paint->mFallbackColor);
3512 if (NS_FAILED(rv)) {
3513 delete valueList;
3514 return rv;
3517 return CallQueryInterface(valueList, aValue);
3521 return CallQueryInterface(val, aValue);
3524 nsresult
3525 nsComputedDOMStyle::GetFill(nsIDOMCSSValue** aValue)
3527 return GetSVGPaintFor(PR_TRUE, aValue);
3530 nsresult
3531 nsComputedDOMStyle::GetStroke(nsIDOMCSSValue** aValue)
3533 return GetSVGPaintFor(PR_FALSE, aValue);
3536 nsresult
3537 nsComputedDOMStyle::GetMarkerEnd(nsIDOMCSSValue** aValue)
3539 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3540 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3542 const nsStyleSVG* svg = GetStyleSVG();
3544 if (svg->mMarkerEnd)
3545 val->SetURI(svg->mMarkerEnd);
3546 else
3547 val->SetIdent(nsGkAtoms::none);
3549 return CallQueryInterface(val, aValue);
3552 nsresult
3553 nsComputedDOMStyle::GetMarkerMid(nsIDOMCSSValue** aValue)
3555 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3556 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3558 const nsStyleSVG* svg = GetStyleSVG();
3560 if (svg->mMarkerMid)
3561 val->SetURI(svg->mMarkerMid);
3562 else
3563 val->SetIdent(nsGkAtoms::none);
3565 return CallQueryInterface(val, aValue);
3568 nsresult
3569 nsComputedDOMStyle::GetMarkerStart(nsIDOMCSSValue** aValue)
3571 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3572 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3574 const nsStyleSVG* svg = GetStyleSVG();
3576 if (svg->mMarkerStart)
3577 val->SetURI(svg->mMarkerStart);
3578 else
3579 val->SetIdent(nsGkAtoms::none);
3581 return CallQueryInterface(val, aValue);
3584 nsresult
3585 nsComputedDOMStyle::GetStrokeDasharray(nsIDOMCSSValue** aValue)
3587 const nsStyleSVG* svg = GetStyleSVG();
3589 if (!svg->mStrokeDasharrayLength || !svg->mStrokeDasharray) {
3590 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3591 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3592 val->SetIdent(nsGkAtoms::none);
3593 return CallQueryInterface(val, aValue);
3596 nsDOMCSSValueList *valueList = GetROCSSValueList(PR_TRUE);
3597 NS_ENSURE_TRUE(valueList, NS_ERROR_OUT_OF_MEMORY);
3599 for (PRUint32 i = 0; i < svg->mStrokeDasharrayLength; i++) {
3600 nsROCSSPrimitiveValue* dash = GetROCSSPrimitiveValue();
3601 if (!dash || !valueList->AppendCSSValue(dash)) {
3602 delete valueList;
3603 delete dash;
3604 return NS_ERROR_OUT_OF_MEMORY;
3607 SetValueToCoord(dash, svg->mStrokeDasharray[i]);
3610 return CallQueryInterface(valueList, aValue);
3613 nsresult
3614 nsComputedDOMStyle::GetStrokeDashoffset(nsIDOMCSSValue** aValue)
3616 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3617 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3619 SetValueToCoord(val, GetStyleSVG()->mStrokeDashoffset);
3621 return CallQueryInterface(val, aValue);
3624 nsresult
3625 nsComputedDOMStyle::GetStrokeWidth(nsIDOMCSSValue** aValue)
3627 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3628 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3630 SetValueToCoord(val, GetStyleSVG()->mStrokeWidth);
3632 return CallQueryInterface(val, aValue);
3635 nsresult
3636 nsComputedDOMStyle::GetFillOpacity(nsIDOMCSSValue** aValue)
3638 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3639 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3641 val->SetNumber(GetStyleSVG()->mFillOpacity);
3643 return CallQueryInterface(val, aValue);
3646 nsresult
3647 nsComputedDOMStyle::GetFloodOpacity(nsIDOMCSSValue** aValue)
3649 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3650 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3652 val->SetNumber(GetStyleSVGReset()->mFloodOpacity);
3654 return CallQueryInterface(val, aValue);
3657 nsresult
3658 nsComputedDOMStyle::GetStopOpacity(nsIDOMCSSValue** aValue)
3660 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3661 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3663 val->SetNumber(GetStyleSVGReset()->mStopOpacity);
3665 return CallQueryInterface(val, aValue);
3668 nsresult
3669 nsComputedDOMStyle::GetStrokeMiterlimit(nsIDOMCSSValue** aValue)
3671 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3672 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3674 val->SetNumber(GetStyleSVG()->mStrokeMiterlimit);
3676 return CallQueryInterface(val, aValue);
3679 nsresult
3680 nsComputedDOMStyle::GetStrokeOpacity(nsIDOMCSSValue** aValue)
3682 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3683 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3685 val->SetNumber(GetStyleSVG()->mStrokeOpacity);
3687 return CallQueryInterface(val, aValue);
3690 nsresult
3691 nsComputedDOMStyle::GetClipRule(nsIDOMCSSValue** aValue)
3693 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3694 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3696 const nsAFlatCString& keyword =
3697 nsCSSProps::ValueToKeyword(GetStyleSVG()->mClipRule,
3698 nsCSSProps::kFillRuleKTable);
3699 val->SetIdent(keyword);
3701 return CallQueryInterface(val, aValue);
3704 nsresult
3705 nsComputedDOMStyle::GetFillRule(nsIDOMCSSValue** aValue)
3707 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3708 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3710 const nsAFlatCString& keyword =
3711 nsCSSProps::ValueToKeyword(GetStyleSVG()->mFillRule,
3712 nsCSSProps::kFillRuleKTable);
3713 val->SetIdent(keyword);
3715 return CallQueryInterface(val, aValue);
3718 nsresult
3719 nsComputedDOMStyle::GetStrokeLinecap(nsIDOMCSSValue** aValue)
3721 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3722 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3724 const nsAFlatCString& keyword =
3725 nsCSSProps::ValueToKeyword(GetStyleSVG()->mStrokeLinecap,
3726 nsCSSProps::kStrokeLinecapKTable);
3727 val->SetIdent(keyword);
3729 return CallQueryInterface(val, aValue);
3732 nsresult
3733 nsComputedDOMStyle::GetStrokeLinejoin(nsIDOMCSSValue** aValue)
3735 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3736 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3738 const nsAFlatCString& keyword =
3739 nsCSSProps::ValueToKeyword(GetStyleSVG()->mStrokeLinejoin,
3740 nsCSSProps::kStrokeLinejoinKTable);
3741 val->SetIdent(keyword);
3743 return CallQueryInterface(val, aValue);
3746 nsresult
3747 nsComputedDOMStyle::GetTextAnchor(nsIDOMCSSValue** aValue)
3749 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3750 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3752 const nsAFlatCString& keyword =
3753 nsCSSProps::ValueToKeyword(GetStyleSVG()->mTextAnchor,
3754 nsCSSProps::kTextAnchorKTable);
3755 val->SetIdent(keyword);
3757 return CallQueryInterface(val, aValue);
3760 nsresult
3761 nsComputedDOMStyle::GetColorInterpolation(nsIDOMCSSValue** aValue)
3763 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3764 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3766 const nsStyleSVG* svg = GetStyleSVG();
3768 if (svg->mColorInterpolation != NS_STYLE_COLOR_INTERPOLATION_AUTO) {
3769 const nsAFlatCString& keyword =
3770 nsCSSProps::ValueToKeyword(svg->mColorInterpolation,
3771 nsCSSProps::kColorInterpolationKTable);
3772 val->SetIdent(keyword);
3773 } else {
3774 val->SetIdent(nsGkAtoms::_auto);
3777 return CallQueryInterface(val, aValue);
3780 nsresult
3781 nsComputedDOMStyle::GetColorInterpolationFilters(nsIDOMCSSValue** aValue)
3783 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3784 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3786 const nsStyleSVG* svg = GetStyleSVG();
3788 if (svg->mColorInterpolationFilters != NS_STYLE_COLOR_INTERPOLATION_AUTO) {
3789 const nsAFlatCString& keyword =
3790 nsCSSProps::ValueToKeyword(svg->mColorInterpolationFilters,
3791 nsCSSProps::kColorInterpolationKTable);
3792 val->SetIdent(keyword);
3793 } else {
3794 val->SetIdent(nsGkAtoms::_auto);
3797 return CallQueryInterface(val, aValue);
3800 nsresult
3801 nsComputedDOMStyle::GetDominantBaseline(nsIDOMCSSValue** aValue)
3803 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3804 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3806 const nsStyleSVGReset* svg = GetStyleSVGReset();
3808 if (svg->mDominantBaseline != NS_STYLE_DOMINANT_BASELINE_AUTO) {
3809 const nsAFlatCString& keyword =
3810 nsCSSProps::ValueToKeyword(svg->mDominantBaseline,
3811 nsCSSProps::kDominantBaselineKTable);
3812 val->SetIdent(keyword);
3813 } else {
3814 val->SetIdent(nsGkAtoms::_auto);
3817 return CallQueryInterface(val, aValue);
3820 nsresult
3821 nsComputedDOMStyle::GetPointerEvents(nsIDOMCSSValue** aValue)
3823 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3824 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3826 const nsStyleSVG* svg = GetStyleSVG();
3828 if (svg->mPointerEvents != NS_STYLE_POINTER_EVENTS_NONE) {
3829 const nsAFlatCString& keyword =
3830 nsCSSProps::ValueToKeyword(svg->mPointerEvents,
3831 nsCSSProps::kPointerEventsKTable);
3832 val->SetIdent(keyword);
3833 } else {
3834 val->SetIdent(nsGkAtoms::none);
3837 return CallQueryInterface(val, aValue);
3840 nsresult
3841 nsComputedDOMStyle::GetShapeRendering(nsIDOMCSSValue** aValue)
3843 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3844 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3846 const nsStyleSVG* svg = GetStyleSVG();
3848 if (svg->mShapeRendering != NS_STYLE_SHAPE_RENDERING_AUTO) {
3849 const nsAFlatCString& keyword =
3850 nsCSSProps::ValueToKeyword(svg->mShapeRendering,
3851 nsCSSProps::kShapeRenderingKTable);
3852 val->SetIdent(keyword);
3853 } else {
3854 val->SetIdent(nsGkAtoms::_auto);
3857 return CallQueryInterface(val, aValue);
3860 nsresult
3861 nsComputedDOMStyle::GetTextRendering(nsIDOMCSSValue** aValue)
3863 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3864 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3866 const nsStyleSVG* svg = GetStyleSVG();
3868 if (svg->mTextRendering != NS_STYLE_TEXT_RENDERING_AUTO) {
3869 const nsAFlatCString& keyword =
3870 nsCSSProps::ValueToKeyword(svg->mTextRendering,
3871 nsCSSProps::kTextRenderingKTable);
3872 val->SetIdent(keyword);
3873 } else {
3874 val->SetIdent(nsGkAtoms::_auto);
3877 return CallQueryInterface(val, aValue);
3880 nsresult
3881 nsComputedDOMStyle::GetFloodColor(nsIDOMCSSValue** aValue)
3883 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3884 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3886 nsresult rv = SetToRGBAColor(val, GetStyleSVGReset()->mFloodColor);
3887 if (NS_FAILED(rv)) {
3888 delete val;
3889 return rv;
3892 return CallQueryInterface(val, aValue);
3895 nsresult
3896 nsComputedDOMStyle::GetLightingColor(nsIDOMCSSValue** aValue)
3898 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3899 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3901 nsresult rv = SetToRGBAColor(val, GetStyleSVGReset()->mLightingColor);
3902 if (NS_FAILED(rv)) {
3903 delete val;
3904 return rv;
3907 return CallQueryInterface(val, aValue);
3910 nsresult
3911 nsComputedDOMStyle::GetStopColor(nsIDOMCSSValue** aValue)
3913 nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
3914 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3916 nsresult rv = SetToRGBAColor(val, GetStyleSVGReset()->mStopColor);
3917 if (NS_FAILED(rv)) {
3918 delete val;
3919 return rv;
3922 return CallQueryInterface(val, aValue);
3925 nsresult
3926 nsComputedDOMStyle::GetClipPath(nsIDOMCSSValue** aValue)
3928 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3929 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3931 const nsStyleSVGReset* svg = GetStyleSVGReset();
3933 if (svg->mClipPath)
3934 val->SetURI(svg->mClipPath);
3935 else
3936 val->SetIdent(nsGkAtoms::none);
3938 return CallQueryInterface(val, aValue);
3941 nsresult
3942 nsComputedDOMStyle::GetFilter(nsIDOMCSSValue** aValue)
3944 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3945 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3947 const nsStyleSVGReset* svg = GetStyleSVGReset();
3949 if (svg->mFilter)
3950 val->SetURI(svg->mFilter);
3951 else
3952 val->SetIdent(nsGkAtoms::none);
3954 return CallQueryInterface(val, aValue);
3957 nsresult
3958 nsComputedDOMStyle::GetMask(nsIDOMCSSValue** aValue)
3960 nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
3961 NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
3963 const nsStyleSVGReset* svg = GetStyleSVGReset();
3965 if (svg->mMask)
3966 val->SetURI(svg->mMask);
3967 else
3968 val->SetIdent(nsGkAtoms::none);
3970 return CallQueryInterface(val, aValue);
3973 #endif // MOZ_SVG
3976 #define COMPUTED_STYLE_MAP_ENTRY(_prop, _method) \
3977 { eCSSProperty_##_prop, &nsComputedDOMStyle::Get##_method }
3979 const nsComputedDOMStyle::ComputedStyleMapEntry*
3980 nsComputedDOMStyle::GetQueryablePropertyMap(PRUint32* aLength)
3982 /* ******************************************************************* *\
3983 * Properties below are listed in alphabetical order. *
3984 * Please keep them that way. *
3986 * Properties commented out with // are not yet implemented *
3987 * Properties commented out with //// are shorthands and not queryable *
3988 \* ******************************************************************* */
3989 static
3990 #ifndef XP_MACOSX
3991 // XXX If this actually fixes the bustage, replace this with an
3992 // autoconf test.
3993 const
3994 #endif
3995 ComputedStyleMapEntry map[] = {
3996 /* ****************************** *\
3997 * Implementations of CSS2 styles *
3998 \* ****************************** */
4000 // COMPUTED_STYLE_MAP_ENTRY(azimuth, Azimuth),
4001 //// COMPUTED_STYLE_MAP_ENTRY(background, Background),
4002 COMPUTED_STYLE_MAP_ENTRY(background_attachment, BackgroundAttachment),
4003 COMPUTED_STYLE_MAP_ENTRY(background_color, BackgroundColor),
4004 COMPUTED_STYLE_MAP_ENTRY(background_image, BackgroundImage),
4005 COMPUTED_STYLE_MAP_ENTRY(background_position, BackgroundPosition),
4006 COMPUTED_STYLE_MAP_ENTRY(background_repeat, BackgroundRepeat),
4007 //// COMPUTED_STYLE_MAP_ENTRY(border, Border),
4008 //// COMPUTED_STYLE_MAP_ENTRY(border_bottom, BorderBottom),
4009 COMPUTED_STYLE_MAP_ENTRY(border_bottom_color, BorderBottomColor),
4010 COMPUTED_STYLE_MAP_ENTRY(border_bottom_style, BorderBottomStyle),
4011 COMPUTED_STYLE_MAP_ENTRY(border_bottom_width, BorderBottomWidth),
4012 COMPUTED_STYLE_MAP_ENTRY(border_collapse, BorderCollapse),
4013 //// COMPUTED_STYLE_MAP_ENTRY(border_color, BorderColor),
4014 //// COMPUTED_STYLE_MAP_ENTRY(border_left, BorderLeft),
4015 COMPUTED_STYLE_MAP_ENTRY(border_left_color, BorderLeftColor),
4016 COMPUTED_STYLE_MAP_ENTRY(border_left_style, BorderLeftStyle),
4017 COMPUTED_STYLE_MAP_ENTRY(border_left_width, BorderLeftWidth),
4018 //// COMPUTED_STYLE_MAP_ENTRY(border_right, BorderRight),
4019 COMPUTED_STYLE_MAP_ENTRY(border_right_color, BorderRightColor),
4020 COMPUTED_STYLE_MAP_ENTRY(border_right_style, BorderRightStyle),
4021 COMPUTED_STYLE_MAP_ENTRY(border_right_width, BorderRightWidth),
4022 COMPUTED_STYLE_MAP_ENTRY(border_spacing, BorderSpacing),
4023 //// COMPUTED_STYLE_MAP_ENTRY(border_style, BorderStyle),
4024 //// COMPUTED_STYLE_MAP_ENTRY(border_top, BorderTop),
4025 COMPUTED_STYLE_MAP_ENTRY(border_top_color, BorderTopColor),
4026 COMPUTED_STYLE_MAP_ENTRY(border_top_style, BorderTopStyle),
4027 COMPUTED_STYLE_MAP_ENTRY(border_top_width, BorderTopWidth),
4028 //// COMPUTED_STYLE_MAP_ENTRY(border_width, BorderWidth),
4029 COMPUTED_STYLE_MAP_ENTRY(bottom, Bottom),
4030 COMPUTED_STYLE_MAP_ENTRY(caption_side, CaptionSide),
4031 COMPUTED_STYLE_MAP_ENTRY(clear, Clear),
4032 COMPUTED_STYLE_MAP_ENTRY(clip, Clip),
4033 COMPUTED_STYLE_MAP_ENTRY(color, Color),
4034 COMPUTED_STYLE_MAP_ENTRY(content, Content),
4035 COMPUTED_STYLE_MAP_ENTRY(counter_increment, CounterIncrement),
4036 COMPUTED_STYLE_MAP_ENTRY(counter_reset, CounterReset),
4037 //// COMPUTED_STYLE_MAP_ENTRY(cue, Cue),
4038 // COMPUTED_STYLE_MAP_ENTRY(cue_after, CueAfter),
4039 // COMPUTED_STYLE_MAP_ENTRY(cue_before, CueBefore),
4040 COMPUTED_STYLE_MAP_ENTRY(cursor, Cursor),
4041 COMPUTED_STYLE_MAP_ENTRY(direction, Direction),
4042 COMPUTED_STYLE_MAP_ENTRY(display, Display),
4043 // COMPUTED_STYLE_MAP_ENTRY(elevation, Elevation),
4044 COMPUTED_STYLE_MAP_ENTRY(empty_cells, EmptyCells),
4045 COMPUTED_STYLE_MAP_ENTRY(float, CssFloat),
4046 //// COMPUTED_STYLE_MAP_ENTRY(font, Font),
4047 COMPUTED_STYLE_MAP_ENTRY(font_family, FontFamily),
4048 COMPUTED_STYLE_MAP_ENTRY(font_size, FontSize),
4049 COMPUTED_STYLE_MAP_ENTRY(font_size_adjust, FontSizeAdjust),
4050 // COMPUTED_STYLE_MAP_ENTRY(font_stretch, FontStretch),
4051 COMPUTED_STYLE_MAP_ENTRY(font_style, FontStyle),
4052 COMPUTED_STYLE_MAP_ENTRY(font_variant, FontVariant),
4053 COMPUTED_STYLE_MAP_ENTRY(font_weight, FontWeight),
4054 COMPUTED_STYLE_MAP_ENTRY(height, Height),
4055 COMPUTED_STYLE_MAP_ENTRY(left, Left),
4056 COMPUTED_STYLE_MAP_ENTRY(letter_spacing, LetterSpacing),
4057 COMPUTED_STYLE_MAP_ENTRY(line_height, LineHeight),
4058 //// COMPUTED_STYLE_MAP_ENTRY(list_style, ListStyle),
4059 COMPUTED_STYLE_MAP_ENTRY(list_style_image, ListStyleImage),
4060 COMPUTED_STYLE_MAP_ENTRY(list_style_position, ListStylePosition),
4061 COMPUTED_STYLE_MAP_ENTRY(list_style_type, ListStyleType),
4062 //// COMPUTED_STYLE_MAP_ENTRY(margin, Margin),
4063 COMPUTED_STYLE_MAP_ENTRY(margin_bottom, MarginBottomWidth),
4064 COMPUTED_STYLE_MAP_ENTRY(margin_left, MarginLeftWidth),
4065 COMPUTED_STYLE_MAP_ENTRY(margin_right, MarginRightWidth),
4066 COMPUTED_STYLE_MAP_ENTRY(margin_top, MarginTopWidth),
4067 COMPUTED_STYLE_MAP_ENTRY(marker_offset, MarkerOffset),
4068 // COMPUTED_STYLE_MAP_ENTRY(marks, Marks),
4069 COMPUTED_STYLE_MAP_ENTRY(max_height, MaxHeight),
4070 COMPUTED_STYLE_MAP_ENTRY(max_width, MaxWidth),
4071 COMPUTED_STYLE_MAP_ENTRY(min_height, MinHeight),
4072 COMPUTED_STYLE_MAP_ENTRY(min_width, MinWidth),
4073 COMPUTED_STYLE_MAP_ENTRY(ime_mode, IMEMode),
4074 COMPUTED_STYLE_MAP_ENTRY(opacity, Opacity),
4075 // COMPUTED_STYLE_MAP_ENTRY(orphans, Orphans),
4076 //// COMPUTED_STYLE_MAP_ENTRY(outline, Outline),
4077 COMPUTED_STYLE_MAP_ENTRY(outline_color, OutlineColor),
4078 COMPUTED_STYLE_MAP_ENTRY(outline_style, OutlineStyle),
4079 COMPUTED_STYLE_MAP_ENTRY(outline_width, OutlineWidth),
4080 COMPUTED_STYLE_MAP_ENTRY(outline_offset, OutlineOffset),
4081 COMPUTED_STYLE_MAP_ENTRY(overflow, Overflow),
4082 COMPUTED_STYLE_MAP_ENTRY(overflow_x, OverflowX),
4083 COMPUTED_STYLE_MAP_ENTRY(overflow_y, OverflowY),
4084 //// COMPUTED_STYLE_MAP_ENTRY(padding, Padding),
4085 COMPUTED_STYLE_MAP_ENTRY(padding_bottom, PaddingBottom),
4086 COMPUTED_STYLE_MAP_ENTRY(padding_left, PaddingLeft),
4087 COMPUTED_STYLE_MAP_ENTRY(padding_right, PaddingRight),
4088 COMPUTED_STYLE_MAP_ENTRY(padding_top, PaddingTop),
4089 // COMPUTED_STYLE_MAP_ENTRY(page, Page),
4090 COMPUTED_STYLE_MAP_ENTRY(page_break_after, PageBreakAfter),
4091 COMPUTED_STYLE_MAP_ENTRY(page_break_before, PageBreakBefore),
4092 // COMPUTED_STYLE_MAP_ENTRY(page_break_inside, PageBreakInside),
4093 //// COMPUTED_STYLE_MAP_ENTRY(pause, Pause),
4094 // COMPUTED_STYLE_MAP_ENTRY(pause_after, PauseAfter),
4095 // COMPUTED_STYLE_MAP_ENTRY(pause_before, PauseBefore),
4096 // COMPUTED_STYLE_MAP_ENTRY(pitch, Pitch),
4097 // COMPUTED_STYLE_MAP_ENTRY(pitch_range, PitchRange),
4098 COMPUTED_STYLE_MAP_ENTRY(position, Position),
4099 COMPUTED_STYLE_MAP_ENTRY(quotes, Quotes),
4100 // COMPUTED_STYLE_MAP_ENTRY(richness, Richness),
4101 COMPUTED_STYLE_MAP_ENTRY(right, Right),
4102 //// COMPUTED_STYLE_MAP_ENTRY(size, Size),
4103 // COMPUTED_STYLE_MAP_ENTRY(speak, Speak),
4104 // COMPUTED_STYLE_MAP_ENTRY(speak_header, SpeakHeader),
4105 // COMPUTED_STYLE_MAP_ENTRY(speak_numeral, SpeakNumeral),
4106 // COMPUTED_STYLE_MAP_ENTRY(speak_punctuation, SpeakPunctuation),
4107 // COMPUTED_STYLE_MAP_ENTRY(speech_rate, SpeechRate),
4108 // COMPUTED_STYLE_MAP_ENTRY(stress, Stress),
4109 COMPUTED_STYLE_MAP_ENTRY(table_layout, TableLayout),
4110 COMPUTED_STYLE_MAP_ENTRY(text_align, TextAlign),
4111 COMPUTED_STYLE_MAP_ENTRY(text_decoration, TextDecoration),
4112 COMPUTED_STYLE_MAP_ENTRY(text_indent, TextIndent),
4113 COMPUTED_STYLE_MAP_ENTRY(text_shadow, TextShadow),
4114 COMPUTED_STYLE_MAP_ENTRY(text_transform, TextTransform),
4115 COMPUTED_STYLE_MAP_ENTRY(top, Top),
4116 COMPUTED_STYLE_MAP_ENTRY(unicode_bidi, UnicodeBidi),
4117 COMPUTED_STYLE_MAP_ENTRY(vertical_align, VerticalAlign),
4118 COMPUTED_STYLE_MAP_ENTRY(visibility, Visibility),
4119 // COMPUTED_STYLE_MAP_ENTRY(voice_family, VoiceFamily),
4120 // COMPUTED_STYLE_MAP_ENTRY(volume, Volume),
4121 COMPUTED_STYLE_MAP_ENTRY(white_space, WhiteSpace),
4122 // COMPUTED_STYLE_MAP_ENTRY(widows, Widows),
4123 COMPUTED_STYLE_MAP_ENTRY(width, Width),
4124 COMPUTED_STYLE_MAP_ENTRY(word_spacing, WordSpacing),
4125 COMPUTED_STYLE_MAP_ENTRY(z_index, ZIndex),
4127 /* ******************************* *\
4128 * Implementations of -moz- styles *
4129 \* ******************************* */
4131 COMPUTED_STYLE_MAP_ENTRY(appearance, Appearance),
4132 COMPUTED_STYLE_MAP_ENTRY(_moz_background_clip, BackgroundClip),
4133 COMPUTED_STYLE_MAP_ENTRY(_moz_background_inline_policy, BackgroundInlinePolicy),
4134 COMPUTED_STYLE_MAP_ENTRY(_moz_background_origin, BackgroundOrigin),
4135 COMPUTED_STYLE_MAP_ENTRY(binding, Binding),
4136 COMPUTED_STYLE_MAP_ENTRY(border_bottom_colors, BorderBottomColors),
4137 COMPUTED_STYLE_MAP_ENTRY(border_image, BorderImage),
4138 COMPUTED_STYLE_MAP_ENTRY(border_left_colors, BorderLeftColors),
4139 COMPUTED_STYLE_MAP_ENTRY(border_right_colors, BorderRightColors),
4140 COMPUTED_STYLE_MAP_ENTRY(border_top_colors, BorderTopColors),
4141 COMPUTED_STYLE_MAP_ENTRY(_moz_border_radius_bottomLeft, BorderRadiusBottomLeft),
4142 COMPUTED_STYLE_MAP_ENTRY(_moz_border_radius_bottomRight,BorderRadiusBottomRight),
4143 COMPUTED_STYLE_MAP_ENTRY(_moz_border_radius_topLeft, BorderRadiusTopLeft),
4144 COMPUTED_STYLE_MAP_ENTRY(_moz_border_radius_topRight, BorderRadiusTopRight),
4145 COMPUTED_STYLE_MAP_ENTRY(box_align, BoxAlign),
4146 COMPUTED_STYLE_MAP_ENTRY(box_direction, BoxDirection),
4147 COMPUTED_STYLE_MAP_ENTRY(box_flex, BoxFlex),
4148 COMPUTED_STYLE_MAP_ENTRY(box_ordinal_group, BoxOrdinalGroup),
4149 COMPUTED_STYLE_MAP_ENTRY(box_orient, BoxOrient),
4150 COMPUTED_STYLE_MAP_ENTRY(box_pack, BoxPack),
4151 COMPUTED_STYLE_MAP_ENTRY(box_shadow, BoxShadow),
4152 COMPUTED_STYLE_MAP_ENTRY(box_sizing, BoxSizing),
4153 COMPUTED_STYLE_MAP_ENTRY(_moz_column_count, ColumnCount),
4154 COMPUTED_STYLE_MAP_ENTRY(_moz_column_width, ColumnWidth),
4155 COMPUTED_STYLE_MAP_ENTRY(_moz_column_gap, ColumnGap),
4156 //// COMPUTED_STYLE_MAP_ENTRY(_moz_column_rule, ColumnRule),
4157 COMPUTED_STYLE_MAP_ENTRY(_moz_column_rule_color, ColumnRuleColor),
4158 COMPUTED_STYLE_MAP_ENTRY(_moz_column_rule_width, ColumnRuleWidth),
4159 COMPUTED_STYLE_MAP_ENTRY(_moz_column_rule_style, ColumnRuleStyle),
4160 COMPUTED_STYLE_MAP_ENTRY(float_edge, FloatEdge),
4161 COMPUTED_STYLE_MAP_ENTRY(force_broken_image_icon, ForceBrokenImageIcon),
4162 COMPUTED_STYLE_MAP_ENTRY(image_region, ImageRegion),
4163 COMPUTED_STYLE_MAP_ENTRY(_moz_outline_radius_bottomLeft, OutlineRadiusBottomLeft),
4164 COMPUTED_STYLE_MAP_ENTRY(_moz_outline_radius_bottomRight,OutlineRadiusBottomRight),
4165 COMPUTED_STYLE_MAP_ENTRY(_moz_outline_radius_topLeft, OutlineRadiusTopLeft),
4166 COMPUTED_STYLE_MAP_ENTRY(_moz_outline_radius_topRight, OutlineRadiusTopRight),
4167 COMPUTED_STYLE_MAP_ENTRY(stack_sizing, StackSizing),
4168 COMPUTED_STYLE_MAP_ENTRY(_moz_transform, MozTransform),
4169 COMPUTED_STYLE_MAP_ENTRY(_moz_transform_origin, MozTransformOrigin),
4170 COMPUTED_STYLE_MAP_ENTRY(user_focus, UserFocus),
4171 COMPUTED_STYLE_MAP_ENTRY(user_input, UserInput),
4172 COMPUTED_STYLE_MAP_ENTRY(user_modify, UserModify),
4173 COMPUTED_STYLE_MAP_ENTRY(user_select, UserSelect),
4174 COMPUTED_STYLE_MAP_ENTRY(word_wrap, WordWrap)
4176 #ifdef MOZ_SVG
4178 COMPUTED_STYLE_MAP_ENTRY(clip_path, ClipPath),
4179 COMPUTED_STYLE_MAP_ENTRY(clip_rule, ClipRule),
4180 COMPUTED_STYLE_MAP_ENTRY(color_interpolation, ColorInterpolation),
4181 COMPUTED_STYLE_MAP_ENTRY(color_interpolation_filters, ColorInterpolationFilters),
4182 COMPUTED_STYLE_MAP_ENTRY(dominant_baseline, DominantBaseline),
4183 COMPUTED_STYLE_MAP_ENTRY(fill, Fill),
4184 COMPUTED_STYLE_MAP_ENTRY(fill_opacity, FillOpacity),
4185 COMPUTED_STYLE_MAP_ENTRY(fill_rule, FillRule),
4186 COMPUTED_STYLE_MAP_ENTRY(filter, Filter),
4187 COMPUTED_STYLE_MAP_ENTRY(flood_color, FloodColor),
4188 COMPUTED_STYLE_MAP_ENTRY(flood_opacity, FloodOpacity),
4189 COMPUTED_STYLE_MAP_ENTRY(lighting_color, LightingColor),
4190 COMPUTED_STYLE_MAP_ENTRY(mask, Mask),
4191 COMPUTED_STYLE_MAP_ENTRY(marker_end, MarkerEnd),
4192 COMPUTED_STYLE_MAP_ENTRY(marker_mid, MarkerMid),
4193 COMPUTED_STYLE_MAP_ENTRY(marker_start, MarkerStart),
4194 COMPUTED_STYLE_MAP_ENTRY(pointer_events, PointerEvents),
4195 COMPUTED_STYLE_MAP_ENTRY(shape_rendering, ShapeRendering),
4196 COMPUTED_STYLE_MAP_ENTRY(stop_color, StopColor),
4197 COMPUTED_STYLE_MAP_ENTRY(stop_opacity, StopOpacity),
4198 COMPUTED_STYLE_MAP_ENTRY(stroke, Stroke),
4199 COMPUTED_STYLE_MAP_ENTRY(stroke_dasharray, StrokeDasharray),
4200 COMPUTED_STYLE_MAP_ENTRY(stroke_dashoffset, StrokeDashoffset),
4201 COMPUTED_STYLE_MAP_ENTRY(stroke_linecap, StrokeLinecap),
4202 COMPUTED_STYLE_MAP_ENTRY(stroke_linejoin, StrokeLinejoin),
4203 COMPUTED_STYLE_MAP_ENTRY(stroke_miterlimit, StrokeMiterlimit),
4204 COMPUTED_STYLE_MAP_ENTRY(stroke_opacity, StrokeOpacity),
4205 COMPUTED_STYLE_MAP_ENTRY(stroke_width, StrokeWidth),
4206 COMPUTED_STYLE_MAP_ENTRY(text_anchor, TextAnchor),
4207 COMPUTED_STYLE_MAP_ENTRY(text_rendering, TextRendering)
4208 #endif
4212 *aLength = NS_ARRAY_LENGTH(map);
4214 return map;