Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLCSSUtils.h
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  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Original Author: Daniel Glazman <glazman@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or 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 #ifndef nsHTMLCSSUtils_h__
00040 #define nsHTMLCSSUtils_h__
00041 
00042 #include "nsCOMPtr.h"
00043 #include "nsString.h"
00044 #include "nsIDOMViewCSS.h"
00045 #include "nsIDOMNode.h"
00046 #include "nsIDOMElement.h"
00047 #include "nsIHTMLEditor.h"
00048 #include "ChangeCSSInlineStyleTxn.h"
00049 #include "nsEditProperty.h"
00050 #include "nsIDOMCSSStyleDeclaration.h"
00051 
00052 #define SPECIFIED_STYLE_TYPE    1
00053 #define COMPUTED_STYLE_TYPE     2
00054 
00055 class nsHTMLEditor;
00056 
00057 typedef void (*nsProcessValueFunc)(const nsAString * aInputString, nsAString & aOutputString,
00058                                    const char * aDefaultValueString,
00059                                    const char * aPrependString, const char* aAppendString);
00060 
00061 class nsHTMLCSSUtils
00062 {
00063 public:
00064   nsHTMLCSSUtils();
00065   ~nsHTMLCSSUtils();
00066 
00067   enum nsCSSEditableProperty {
00068     eCSSEditableProperty_NONE=0,
00069     eCSSEditableProperty_background_color,
00070     eCSSEditableProperty_background_image,
00071     eCSSEditableProperty_border,
00072     eCSSEditableProperty_caption_side,
00073     eCSSEditableProperty_color,
00074     eCSSEditableProperty_float,
00075     eCSSEditableProperty_font_family,
00076     eCSSEditableProperty_font_size,
00077     eCSSEditableProperty_font_style,
00078     eCSSEditableProperty_font_weight,
00079     eCSSEditableProperty_height,
00080     eCSSEditableProperty_list_style_type,
00081     eCSSEditableProperty_margin_left,
00082     eCSSEditableProperty_margin_right,
00083     eCSSEditableProperty_text_align,
00084     eCSSEditableProperty_text_decoration,
00085     eCSSEditableProperty_vertical_align,
00086     eCSSEditableProperty_whitespace,
00087     eCSSEditableProperty_width
00088   };
00089 
00090 
00091   struct CSSEquivTable {
00092     nsCSSEditableProperty cssProperty;
00093     nsProcessValueFunc processValueFunctor;
00094     const char * defaultValue;
00095     const char * prependValue;
00096     const char * appendValue;
00097     PRBool gettable;
00098     PRBool caseSensitiveValue;
00099   };
00100 
00101 public:
00102   nsresult    Init(nsHTMLEditor * aEditor);
00103 
00112   PRBool      IsCSSEditableProperty(nsIDOMNode * aNode, nsIAtom * aProperty, const nsAString * aAttribute);
00113 
00122   nsresult    SetCSSProperty(nsIDOMElement * aElement, nsIAtom * aProperty,
00123                              const nsAString & aValue,
00124                              PRBool aSuppressTransaction);
00125   nsresult    SetCSSPropertyPixels(nsIDOMElement *aElement, nsIAtom *aProperty,
00126                                    PRInt32 aIntValue, PRBool aSuppressTxn);
00127   nsresult    RemoveCSSProperty(nsIDOMElement * aElement, nsIAtom * aProperty,
00128                                 const nsAString & aPropertyValue, PRBool aSuppressTransaction);
00129 
00137   nsresult    SetCSSProperty(nsIDOMElement * aElement,
00138                              const nsAString & aProperty,
00139                              const nsAString & aValue);
00140   nsresult    SetCSSPropertyPixels(nsIDOMElement * aElement,
00141                                    const nsAString & aProperty,
00142                                    PRInt32 aIntValue);
00143   nsresult    RemoveCSSProperty(nsIDOMElement * aElement,
00144                                 const nsAString & aProperty);
00145 
00153   nsresult    GetSpecifiedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
00154                                    nsAString & aValue);
00155   nsresult    GetComputedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
00156                                   nsAString & aValue);
00157 
00166   nsresult    RemoveCSSInlineStyle(nsIDOMNode * aNode, nsIAtom * aProperty, const nsAString & aPropertyValue);
00167 
00175   PRBool      IsCSSInvertable(nsIAtom * aProperty, const nsAString * aAttribute);
00176 
00181   nsresult    GetDefaultBackgroundColor(nsAString & aColor);
00182 
00187   nsresult    GetDefaultLengthUnit(nsAString & aLengthUnit);
00188 
00194   nsresult    HasClassOrID(nsIDOMElement * aElement, PRBool & aReturn);
00195 
00206   nsresult    GetCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
00207                                                    nsIAtom * aHTMLProperty,
00208                                                    const nsAString * aAttribute,
00209                                                    nsAString & aValueString,
00210                                                    PRUint8 aStyleType);
00211 
00223   nsresult    IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
00224                                                   nsIAtom * aHTMLProperty,
00225                                                   const nsAString * aAttribute,
00226                                                   PRBool & aIsSet,
00227                                                   nsAString & aValueString,
00228                                                   PRUint8 aStyleType);
00229 
00241   nsresult    SetCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
00242                                           nsIAtom * aHTMLProperty,
00243                                           const nsAString * aAttribute,
00244                                           const nsAString * aValue,
00245                                           PRInt32 * aCount,
00246                                           PRBool aSuppressTransaction);
00247 
00257   nsresult    RemoveCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
00258                                              nsIAtom *aHTMLProperty,
00259                                              const nsAString *aAttribute,
00260                                              const nsAString *aValue,
00261                                              PRBool aSuppressTransaction);
00262 
00271   void        ParseLength(const nsAString & aString, float * aValue, nsIAtom ** aUnit);
00272 
00278   nsresult    SetCSSEnabled(PRBool aIsCSSPrefChecked);
00279 
00285   PRBool      IsCSSPrefChecked();
00286 
00295   PRBool ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode);
00296 
00303   nsresult GetInlineStyles(nsIDOMElement * aElement, nsIDOMCSSStyleDeclaration ** aCssDecl,
00304                            PRUint32 * aLength);
00305 
00312   nsresult GetElementContainerOrSelf(nsIDOMNode * aNode, nsIDOMElement ** aElement);
00313 
00319   nsresult        GetDefaultViewCSS(nsIDOMNode * aNode, nsIDOMViewCSS ** aViewCSS);
00320 
00321 
00322 private:
00323 
00329   void  GetCSSPropertyAtom(nsCSSEditableProperty aProperty, nsIAtom ** aAtom);
00330 
00343   void      BuildCSSDeclarations(nsVoidArray & aPropertyArray,
00344                                  nsStringArray & cssValueArray,
00345                                  const CSSEquivTable * aEquivTable,
00346                                  const nsAString * aValue,
00347                                  PRBool aGetOrRemoveRequest);
00348 
00362   void      GenerateCSSDeclarationsFromHTMLStyle(nsIDOMNode * aNode,
00363                                                  nsIAtom * aHTMLProperty,
00364                                                  const nsAString *aAttribute,
00365                                                  const nsAString *aValue,
00366                                                  nsVoidArray & aPropertyArray,
00367                                                  nsStringArray & aValueArray,
00368                                                  PRBool aGetOrRemoveRequest);
00369 
00378   nsresult    CreateCSSPropertyTxn(nsIDOMElement * aElement, 
00379                                    nsIAtom * aProperty,
00380                                    const nsAString & aValue,
00381                                    ChangeCSSInlineStyleTxn ** aTxn,
00382                                    PRBool aRemoveProperty);
00383 
00393   nsresult    GetCSSInlinePropertyBase(nsIDOMNode * aNode, nsIAtom * aProperty,
00394                                        nsAString & aValue,
00395                                        nsIDOMViewCSS * aViewCSS,
00396                                        PRUint8 aStyleType);
00397 
00398 
00399 private:
00400   nsHTMLEditor            *mHTMLEditor;
00401   PRBool                  mIsCSSPrefChecked; 
00402 
00403 };
00404 
00405 nsresult NS_NewHTMLCSSUtils(nsHTMLCSSUtils** aInstancePtrResult);
00406 
00407 #define NS_EDITOR_INDENT_INCREMENT_IN        0.4134f
00408 #define NS_EDITOR_INDENT_INCREMENT_CM        1.05f
00409 #define NS_EDITOR_INDENT_INCREMENT_MM        10.5f
00410 #define NS_EDITOR_INDENT_INCREMENT_PT        29.76f
00411 #define NS_EDITOR_INDENT_INCREMENT_PC        2.48f
00412 #define NS_EDITOR_INDENT_INCREMENT_EM        3
00413 #define NS_EDITOR_INDENT_INCREMENT_EX        6
00414 #define NS_EDITOR_INDENT_INCREMENT_PX        40
00415 #define NS_EDITOR_INDENT_INCREMENT_PERCENT   4 
00416 
00417 #endif /* nsHTMLCSSUtils_h__ */