Back to index

lightning-sunbird  0.9+nobinonly
nsSVGStylableElement.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * IBM Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * IBM Corporation. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   IBM Corporation
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsSVGStylableElement.h"
00040 #include "nsICSSOMFactory.h"
00041 #include "nsSVGAnimatedString.h"
00042 #include "nsSVGAtoms.h"
00043 #include "nsDOMCSSDeclaration.h"
00044 
00045 static NS_DEFINE_CID(kCSSOMFactoryCID, NS_CSSOMFACTORY_CID);
00046 
00047 //----------------------------------------------------------------------
00048 // nsISupports methods
00049 
00050 NS_IMPL_ADDREF_INHERITED(nsSVGStylableElement, nsSVGStylableElementBase)
00051 NS_IMPL_RELEASE_INHERITED(nsSVGStylableElement, nsSVGStylableElementBase)
00052 
00053 NS_INTERFACE_MAP_BEGIN(nsSVGStylableElement)
00054   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGStylable)
00055 NS_INTERFACE_MAP_END_INHERITING(nsSVGStylableElementBase)
00056 
00057 //----------------------------------------------------------------------
00058 // Implementation
00059 
00060 nsSVGStylableElement::nsSVGStylableElement(nsINodeInfo *aNodeInfo)
00061   : nsSVGStylableElementBase(aNodeInfo)
00062 {
00063 
00064 }
00065 
00066 nsresult
00067 nsSVGStylableElement::Init()
00068 {
00069   nsresult rv;
00070 
00071   // Create mapped properties:
00072 
00073   // DOM property: className, #IMPLIED attrib: class
00074   {
00075     mClassName = new nsSVGClassValue;
00076     NS_ENSURE_TRUE(mClassName, NS_ERROR_OUT_OF_MEMORY);
00077     rv = AddMappedSVGValue(nsSVGAtoms::_class,
00078                         NS_STATIC_CAST(nsIDOMSVGAnimatedString*, mClassName),
00079                         kNameSpaceID_None);
00080     NS_ENSURE_SUCCESS(rv, rv);
00081   }
00082 
00083   return rv;
00084 }
00085 
00086 //----------------------------------------------------------------------
00087 // nsIStyledContent methods
00088 
00089 const nsAttrValue*
00090 nsSVGStylableElement::GetClasses() const
00091 {
00092   return mClassName->GetAttrValue();
00093 }
00094 
00095 NS_IMETHODIMP_(PRBool)
00096 nsSVGStylableElement::HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const
00097 {
00098   NS_ASSERTION(aCaseSensitive, "svg should always be casesensitive");
00099 
00100   const nsAttrValue* val = mClassName->GetAttrValue();
00101   if (val->Type() == nsAttrValue::eAtom) {
00102     return aClass == val->GetAtomValue();
00103   }
00104   if (val->Type() == nsAttrValue::eAtomArray) {
00105     return val->GetAtomArrayValue()->IndexOf(aClass) >= 0;
00106   }
00107 
00108   return PR_FALSE;
00109 }
00110 
00111 //----------------------------------------------------------------------
00112 // nsIDOMSVGStylable methods
00113 
00114 /* readonly attribute nsIDOMSVGAnimatedString className; */
00115 NS_IMETHODIMP
00116 nsSVGStylableElement::GetClassName(nsIDOMSVGAnimatedString** aClassName)
00117 {
00118   NS_ADDREF(*aClassName = mClassName);
00119 
00120   return NS_OK;
00121 }
00122 
00123 /* readonly attribute nsIDOMCSSStyleDeclaration style; */
00124 NS_IMETHODIMP
00125 nsSVGStylableElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
00126 {
00127   nsDOMSlots *slots = GetDOMSlots();
00128 
00129   if (!slots->mStyle) {
00130     nsICSSOMFactory* cssOMFactory = nsnull;
00131     // We could cache the factory here, but lets wait with that until
00132     // we share code with html here.
00133     nsresult rv = CallGetService(kCSSOMFactoryCID, &cssOMFactory);
00134     NS_ENSURE_SUCCESS(rv, rv);
00135 
00136     rv = cssOMFactory->
00137       CreateDOMCSSAttributeDeclaration(this, getter_AddRefs(slots->mStyle));
00138     NS_ENSURE_SUCCESS(rv, rv);
00139   }
00140 
00141   NS_ADDREF(*aStyle = slots->mStyle);
00142 
00143   return NS_OK;
00144 }
00145 
00146 /* nsIDOMCSSValue getPresentationAttribute (in DOMString name); */
00147 NS_IMETHODIMP
00148 nsSVGStylableElement::GetPresentationAttribute(const nsAString& aName,
00149                                           nsIDOMCSSValue** aReturn)
00150 {
00151   // Let's not implement this just yet. The CSSValue interface has been
00152   // deprecated by the CSS WG.
00153   // http://lists.w3.org/Archives/Public/www-style/2003Oct/0347.html
00154 
00155   return NS_ERROR_NOT_IMPLEMENTED;
00156 }