From 8a1b7e11ba209fb213feed71554bf33c41d01fa0 Mon Sep 17 00:00:00 2001 From: "kostello%netscape.com" Date: Fri, 17 Jul 1998 23:00:54 +0000 Subject: [PATCH] 1) Move the CSS dependent methods out of nsDocument and placed them in a new class nsMarkupDocument. The point of nsMarkupDocument is to hold methods which are common to HTML and XML but not relevant to the base nsDocument class. 2) Added Selection support methods for Rod. 3) Added LookupProperty to nsCSSProperty: Given a property ID and Property Index returns back the string representation of the property. This was need to convert CSSValues back to strings for saving. TODO: Make sure that our URL Information stored in a CSSDeclaration contains enough information to return it to it's original form on output. git-svn-id: svn://10.0.0.236/trunk@5855 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIDocument.h | 16 +- mozilla/content/base/src/nsDocument.cpp | 306 ++++++------- mozilla/content/base/src/nsDocument.h | 32 +- .../html/document/src/nsHTMLDocument.cpp | 2 +- .../html/document/src/nsHTMLDocument.h | 3 +- .../html/document/src/nsMarkupDocument.cpp | 275 ++++++++++++ .../html/document/src/nsMarkupDocument.h | 65 +++ .../html/style/src/nsCSSDeclaration.cpp | 236 ++++++++-- .../content/html/style/src/nsCSSParser.cpp | 1 + mozilla/content/html/style/src/nsCSSProps.h | 6 + .../content/html/style/src/nsCSSStruct.cpp | 236 ++++++++-- mozilla/content/shared/public/nsCSSProps.h | 6 + mozilla/content/shared/src/nsCSSProps.cpp | 415 ++++++++++++++++++ mozilla/layout/base/public/nsIDocument.h | 16 +- mozilla/layout/base/src/nsDocument.cpp | 306 ++++++------- mozilla/layout/base/src/nsDocument.h | 32 +- mozilla/layout/base/src/nsFrame.cpp | 82 +++- .../layout/html/base/src/nsTextContent.cpp | 22 +- mozilla/layout/html/document/src/Makefile | 1 + mozilla/layout/html/document/src/makefile.win | 2 + .../html/document/src/nsHTMLDocument.cpp | 2 +- .../layout/html/document/src/nsHTMLDocument.h | 3 +- .../html/document/src/nsMarkupDocument.cpp | 275 ++++++++++++ .../html/document/src/nsMarkupDocument.h | 65 +++ .../html/style/src/nsCSSDeclaration.cpp | 236 ++++++++-- mozilla/layout/html/style/src/nsCSSParser.cpp | 1 + mozilla/layout/html/style/src/nsCSSProps.cpp | 415 ++++++++++++++++++ mozilla/layout/html/style/src/nsCSSProps.h | 6 + mozilla/layout/style/nsCSSDeclaration.cpp | 236 ++++++++-- mozilla/layout/style/nsCSSParser.cpp | 1 + mozilla/layout/style/nsCSSProps.cpp | 415 ++++++++++++++++++ mozilla/layout/style/nsCSSProps.h | 6 + mozilla/layout/style/nsCSSStruct.cpp | 236 ++++++++-- 33 files changed, 3397 insertions(+), 560 deletions(-) create mode 100644 mozilla/content/html/document/src/nsMarkupDocument.cpp create mode 100644 mozilla/content/html/document/src/nsMarkupDocument.h create mode 100644 mozilla/layout/html/document/src/nsMarkupDocument.cpp create mode 100644 mozilla/layout/html/document/src/nsMarkupDocument.h diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 9c0708aa20c..284def789da 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -42,6 +42,8 @@ class nsIViewerContainer; class nsIDOMEvent; class nsIDeviceContext; class nsIParser; +class nsIDOMNode; +class nsXIFConverter; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ @@ -209,14 +211,26 @@ public: * NOTE: we may way to place the result in a stream, * but we will use a string for now -- gpk */ - virtual void ToXIF(nsString & aBuffer, PRBool aUseSelection) = 0; + virtual void CreateXIF(nsString & aBuffer, PRBool aUseSelection) = 0; + virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0; + virtual void BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0; + virtual void ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0; + virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0; + /* Helper methods to help determine the logical positioning of content */ + virtual PRBool IsInRange(nsIContent *aStartContent, nsIContent* aEndContent, nsIContent* aContent) const = 0; + virtual PRBool IsBefore(nsIContent *aNewContent, nsIContent* aCurrentContent) const = 0; + virtual nsIContent* GetPrevContent(nsIContent *aContent) const = 0; + virtual nsIContent* GetNextContent(nsIContent *aContent) const = 0; NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) = 0; + + + }; diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index e3fab1b06cf..f4fc7a0548e 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -993,159 +993,12 @@ void nsDocument::GetSelectionText(nsString & aText) { } -void nsDocument::CSSSelectorToXIF(nsXIFConverter& aConverter, nsCSSSelector& aSelector) -{ - nsString s; - nsCSSSelector* next = aSelector.mNext; - - if (nsnull != next) - CSSSelectorToXIF(aConverter,*next); - - aConverter.BeginCSSSelector(); - - if (aSelector.mTag != nsnull) - { - aSelector.mTag->ToString(s); - aConverter.AddCSSTag(s); - } - - if (aSelector.mID != nsnull) - { - aSelector.mID->ToString(s); - aConverter.AddCSSID(s); - } - - if (aSelector.mClass != nsnull) - { - aSelector.mClass->ToString(s); - aConverter.AddCSSClass(s); - } - - if (aSelector.mPseudoClass != nsnull) - { - aSelector.mPseudoClass->ToString(s); - aConverter.AddCSSPsuedoClass(s); - } - aConverter.EndCSSSelector(); - -} - - -void nsDocument::CSSDeclarationToXIF(nsXIFConverter& aConverter, nsICSSDeclaration& aDeclaration) -{ - PRInt32 propId; - nsCSSValue value; - nsString name; - nsString str; - - - - aConverter.BeginCSSDeclarationList(); - for (propId = 0; propId < PROP_MAX; propId++) - { - switch(propId) - { - case PROP_BACKGROUND: - case PROP_BORDER: - case PROP_CLIP: - case PROP_FONT: - case PROP_LIST_STYLE: - case PROP_MARGIN: - case PROP_PADDING: - case PROP_BACKGROUND_POSITION: - case PROP_BORDER_TOP: - case PROP_BORDER_RIGHT: - case PROP_BORDER_BOTTOM: - case PROP_BORDER_LEFT: - case PROP_BORDER_COLOR: - case PROP_BORDER_STYLE: - case PROP_BORDER_WIDTH: - break; - - default: - aDeclaration.GetValue(propId,value); - if (value.GetUnit() != eHTMLUnit_Null) - { - aConverter.BeginCSSDeclaration(); - name = nsCSSProps::kNameTable[propId].name; - value.ToCSSString(str,propId); - aConverter.AddCSSDeclaration(name,str); - aConverter.EndCSSDeclaration(); - } - } - } - aConverter.EndCSSDeclarationList(); -} - - -void nsDocument::StyleSheetsToXIF(nsXIFConverter& aConverter) -{ - - PRInt32 count = GetNumberOfStyleSheets(); - nsIURL& docURL = *mDocumentURL; - - for (PRInt32 index = 0; index < count; index++) - { - nsIStyleSheet* sheet = GetStyleSheetAt(index); - nsICSSStyleSheet* cssSheet = nsnull; - - if (sheet != nsnull) - { - nsIURL& sheetURL = *sheet->GetURL(); - - if (!(sheetURL == docURL)) - break; - - nsresult isCss = sheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet); - if ((isCss == NS_OK) && (cssSheet != nsnull)) - { - PRInt32 ruleCount = cssSheet->StyleRuleCount(); - PRInt32 ruleIndex; - nsICSSStyleRule* rule = nsnull; - - aConverter.BeginCSSStyleSheet(); - for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++) - { - if (NS_OK == cssSheet->GetStyleRuleAt(ruleIndex, rule)) - { - aConverter.BeginCSSRule(); - - if (nsnull != rule) - { - nsCSSSelector* selector = rule->FirstSelector(); - - if (nsnull != selector) - CSSSelectorToXIF(aConverter,*selector); - - nsICSSDeclaration* declaration = rule->GetDeclaration(); - if (nsnull != declaration) - CSSDeclarationToXIF(aConverter,*declaration); - - NS_IF_RELEASE(declaration); - NS_IF_RELEASE(rule); - } // ruleAt - - aConverter.EndCSSRule(); - } // for loop - } - aConverter.EndCSSStyleSheet(); - NS_RELEASE(cssSheet); - } // css_sheet - NS_RELEASE(sheet); - } // sheet - } -} - - - -void nsDocument::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +void nsDocument::BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) { nsIContent* content = nsnull; - nsresult isContent = aNode->QueryInterface(kIContentIID, (void**)&content); - nsIDOMElement* element = nsnull; - nsresult isElement = aNode->QueryInterface(kIDOMElementIID, (void**)&element); - PRBool isSynthetic = PR_TRUE; + nsresult isContent = aNode->QueryInterface(kIContentIID, (void**)&content); + PRBool isSynthetic = PR_TRUE; // Begin Conversion if (NS_OK == isContent) @@ -1156,50 +1009,50 @@ void nsDocument::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) content->BeginConvertToXIF(aConverter); content->DoConvertToXIF(aConverter); } + NS_RELEASE(content); } - - +} + +void nsDocument::ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ // Iterate through the children, convertion child nodes nsresult result = NS_OK; - nsIDOMNode* node = nsnull; - result = aNode->GetFirstChild(&node); + nsIDOMNode* child = nsnull; + result = aNode->GetFirstChild(&child); - while ((result == NS_OK) && (node != nsnull)) + while ((result == NS_OK) && (child != nsnull)) { - nsIDOMNode* temp = node; - ToXIF(aConverter,node); - result = node->GetNextSibling(&node); + nsIDOMNode* temp = child; + ToXIF(aConverter,child); + result = child->GetNextSibling(&child); NS_RELEASE(temp); } +} - if (NS_OK == isContent && PR_FALSE == isSynthetic) - { - nsIAtom* tag = content->GetTag(); - if (tag != nsnull) - { - if (tag != nsnull) - { - nsString str; - tag->ToString(str); - if (str.EqualsIgnoreCase("Head")) - StyleSheetsToXIF(aConverter); - } - } - } +void nsDocument::FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ + nsIContent* content = nsnull; + nsresult isContent = aNode->QueryInterface(kIContentIID, (void**)&content); + PRBool isSynthetic = PR_TRUE; if (NS_OK == isContent) { + content->IsSynthetic(isSynthetic); if (PR_FALSE == isSynthetic) content->FinishConvertToXIF(aConverter); NS_RELEASE(content); } - if (NS_OK == isElement) - { - NS_RELEASE(element); - } } -void nsDocument::ToXIF(nsString & aBuffer, PRBool aUseSelection) + +void nsDocument::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ + BeginConvertToXIF(aConverter,aNode); + ConvertChildrenToXIF(aConverter,aNode); + FinishConvertToXIF(aConverter,aNode); +} + +void nsDocument::CreateXIF(nsString & aBuffer, PRBool aUseSelection) { nsXIFConverter converter(aBuffer); @@ -1225,3 +1078,102 @@ void nsDocument::ToXIF(nsString & aBuffer, PRBool aUseSelection) converter.Write(); } + + +nsIContent* nsDocument::FindContent( nsIContent* aStartNode, + nsIContent* aTest1, + nsIContent* aTest2) const +{ + PRInt32 count = aStartNode->ChildCount(); + PRInt32 index; + + for(index = 0; index < count;index++) + { + nsIContent* child = aStartNode->ChildAt(index); + nsIContent* content = FindContent(child,aTest1,aTest2); + if (content != nsnull) + return content; + if (child == aTest1 || child == aTest2) + return child; + } + return nsnull; +} + +PRBool nsDocument::IsInRange(nsIContent *aStartContent, nsIContent* aEndContent, nsIContent* aContent) const +{ + PRBool result; + + if (aStartContent == aEndContent) + { + return PRBool(aContent == aStartContent); + } + else if (aStartContent == aContent || aEndContent == aContent) + { + result = PR_TRUE; + } + else + { + result = IsBefore(aStartContent,aContent); + if (result == PR_TRUE) + result = IsBefore(aContent,aEndContent); + } + return result; + +} + + +PRBool nsDocument::IsBefore(nsIContent *aNewContent, nsIContent* aCurrentContent) const +{ + + PRBool result = PR_FALSE; + + if (nsnull != aNewContent && nsnull != aCurrentContent && aNewContent != aCurrentContent) + { + nsIContent* test = FindContent(mRootContent,aNewContent,aCurrentContent); + if (test == aNewContent) + result = PR_TRUE; + } + return result; +} + +nsIContent* nsDocument::GetPrevContent(nsIContent *aContent) const +{ + nsIContent* result = nsnull; + + // Look at previous sibling + + if (nsnull != aContent) + { + nsIContent* parent = aContent->GetParent(); + if (parent != nsnull && parent != mRootContent) + { + PRInt32 index = parent->IndexOf(aContent); + if (index > 0) + result = parent->ChildAt(index-1); + else + result = GetPrevContent(parent); + } + } + return result; +} + +nsIContent* nsDocument::GetNextContent(nsIContent *aContent) const +{ + nsIContent* result = nsnull; + + if (nsnull != aContent) + { + // Look at next sibling + nsIContent* parent = aContent->GetParent(); + if (parent != nsnull && parent != mRootContent) + { + PRInt32 index = parent->IndexOf(aContent); + PRInt32 count = parent->ChildCount(); + if (index+1 < count) + result = parent->ChildAt(index+1); + else + result = GetNextContent(parent); + } + } + return result; +} diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index e785d9527c6..851ed57528a 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -24,12 +24,10 @@ #include "nsIScriptObjectOwner.h" #include "nsIScriptContextOwner.h" #include "nsIDOMEventCapturer.h" +#include "nsXIFConverter.h" class nsISelection; -class nsXIFConverter; class nsIEventListenerManager; -struct nsCSSSelector; -class nsICSSDeclaration; class nsIParser; class nsPostData : public nsIPostData { @@ -191,15 +189,13 @@ public: * Converts the document or a selection of the * document to XIF (XML Interchange Format) * and places the result in aBuffer. - - * NOTE: we may way to place the result in a stream, - * but we will use a string for now -- gpk - */ - virtual void ToXIF(nsString & aBuffer, PRBool aUseSelection); - - virtual void CSSSelectorToXIF(nsXIFConverter& aConverter, nsCSSSelector& aSelector); - virtual void CSSDeclarationToXIF(nsXIFConverter& aConverter, nsICSSDeclaration& aDeclaration); - virtual void StyleSheetsToXIF(nsXIFConverter& aConverter); + */ + virtual void CreateXIF(nsString & aBuffer, PRBool aUseSelection); + virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + virtual void BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + virtual void ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + public: @@ -254,9 +250,19 @@ public: nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); + + virtual PRBool IsInRange(nsIContent *aStartContent, nsIContent* aEndContent, nsIContent* aContent) const; + virtual PRBool IsBefore(nsIContent *aNewContent, nsIContent* aCurrentContent) const; + virtual nsIContent* GetPrevContent(nsIContent *aContent) const; + virtual nsIContent* GetNextContent(nsIContent *aContent) const; + +protected: + nsIContent* FindContent( nsIContent* aStartNode, + nsIContent* aTest1, + nsIContent* aTest2) const; + protected: virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); // subclass hook - virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); nsDocument(); virtual ~nsDocument(); diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 87b8900c1ee..f769e622bde 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -57,7 +57,7 @@ NS_NewHTMLDocument(nsIDocument** aInstancePtrResult) } nsHTMLDocument::nsHTMLDocument() - : nsDocument(), + : nsMarkupDocument(), mAttrStyleSheet(nsnull) { nsHTMLAtoms::AddrefAtoms(); diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index c8ca6113133..28109b6f3f7 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -19,12 +19,13 @@ #define nsHTMLDocument_h___ #include "nsDocument.h" +#include "nsMarkupDocument.h" #include "nsIHTMLDocument.h" class nsIHTMLStyleSheet; class nsIViewerContainer; -class nsHTMLDocument : public nsDocument { +class nsHTMLDocument : public nsMarkupDocument { public: nsHTMLDocument(); virtual ~nsHTMLDocument(); diff --git a/mozilla/content/html/document/src/nsMarkupDocument.cpp b/mozilla/content/html/document/src/nsMarkupDocument.cpp new file mode 100644 index 00000000000..6549c53db88 --- /dev/null +++ b/mozilla/content/html/document/src/nsMarkupDocument.cpp @@ -0,0 +1,275 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + + + +#include "nsMarkupDocument.h" +#include "nsIContent.h" +#include "nsIURL.h" +#include "nsIDOMElement.h" + +#include "nsCSSPropIDs.h" +#include "nsCSSProps.h" +#include "nsICSSStyleSheet.h" +#include "nsICSSStyleRule.h" +#include "nsICSSDeclaration.h" +#include "nsIHTMLCSSStyleSheet.h" +#include "nsHTMLValue.h" +#include "nsXIFConverter.h" + +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); +static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID); + + + +nsMarkupDocument::nsMarkupDocument() : nsDocument() +{ +} + +nsMarkupDocument::~nsMarkupDocument() +{ +} + +/** + * Converts a CSS selector to XIF + * + * @update gpk 01/17/1998 + * @param aConverter -- the XIFConverter where all output is being written + * @param aSelector -- the Object to be converted to XIF + */ +void nsMarkupDocument::CSSSelectorToXIF(nsXIFConverter& aConverter, nsCSSSelector& aSelector) +{ + nsString s; + + nsCSSSelector* next = aSelector.mNext; + + if (nsnull != next) + CSSSelectorToXIF(aConverter,*next); + + aConverter.BeginCSSSelector(); + + if (aSelector.mTag != nsnull) + { + aSelector.mTag->ToString(s); + aConverter.AddCSSTag(s); + } + + if (aSelector.mID != nsnull) + { + aSelector.mID->ToString(s); + aConverter.AddCSSID(s); + } + + if (aSelector.mClass != nsnull) + { + aSelector.mClass->ToString(s); + aConverter.AddCSSClass(s); + } + + if (aSelector.mPseudoClass != nsnull) + { + aSelector.mPseudoClass->ToString(s); + aConverter.AddCSSPsuedoClass(s); + } + aConverter.EndCSSSelector(); + +} + + +/** + * Converts a CSS Declaration to XIF + * + * @update gpk 01/17/1998 + * @param aConverter -- the XIFConverter where all output is being written + * @param aDeclaration -- the Object to be converted to XIF + */ +void nsMarkupDocument::CSSDeclarationToXIF(nsXIFConverter& aConverter, nsICSSDeclaration& aDeclaration) +{ + PRInt32 propId; + nsCSSValue value; + nsString name; + nsString str; + + + + aConverter.BeginCSSDeclarationList(); + for (propId = 0; propId < PROP_MAX; propId++) + { + switch(propId) + { + case PROP_BACKGROUND: + case PROP_BORDER: + case PROP_CLIP: + case PROP_FONT: + case PROP_LIST_STYLE: + case PROP_MARGIN: + case PROP_PADDING: + case PROP_BACKGROUND_POSITION: + case PROP_BORDER_TOP: + case PROP_BORDER_RIGHT: + case PROP_BORDER_BOTTOM: + case PROP_BORDER_LEFT: + case PROP_BORDER_COLOR: + case PROP_BORDER_STYLE: + case PROP_BORDER_WIDTH: + break; + + default: + aDeclaration.GetValue(propId,value); + if (value.GetUnit() != eHTMLUnit_Null) + { + aConverter.BeginCSSDeclaration(); + name = nsCSSProps::kNameTable[propId].name; + value.ToCSSString(str,propId); + aConverter.AddCSSDeclaration(name,str); + aConverter.EndCSSDeclaration(); + } + } + } + aConverter.EndCSSDeclarationList(); +} + + +/** + * Converts the CSS Stylesheets in this document to XIF + * + * @update gpk 01/17/1998 + * @param aConverter -- the XIFConverter where all output is being written + * @param aDeclaration -- the Object to be converted to XIF + */ +void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter) +{ + + PRInt32 count = GetNumberOfStyleSheets(); + nsIURL& docURL = *mDocumentURL; + + for (PRInt32 index = 0; index < count; index++) + { + nsIStyleSheet* sheet = GetStyleSheetAt(index); + nsICSSStyleSheet* cssSheet = nsnull; + + if (sheet != nsnull) + { + nsIURL& sheetURL = *sheet->GetURL(); + + if (!(sheetURL == docURL)) + break; + + nsresult isCss = sheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet); + if ((isCss == NS_OK) && (cssSheet != nsnull)) + { + PRInt32 ruleCount = cssSheet->StyleRuleCount(); + PRInt32 ruleIndex; + nsICSSStyleRule* rule = nsnull; + + aConverter.BeginCSSStyleSheet(); + for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++) + { + if (NS_OK == cssSheet->GetStyleRuleAt(ruleIndex, rule)) + { + aConverter.BeginCSSRule(); + + if (nsnull != rule) + { + nsCSSSelector* selector = rule->FirstSelector(); + + if (nsnull != selector) + CSSSelectorToXIF(aConverter,*selector); + + nsICSSDeclaration* declaration = rule->GetDeclaration(); + if (nsnull != declaration) + CSSDeclarationToXIF(aConverter,*declaration); + + NS_IF_RELEASE(declaration); + NS_IF_RELEASE(rule); + } // ruleAt + + aConverter.EndCSSRule(); + } // for loop + } + aConverter.EndCSSStyleSheet(); + NS_RELEASE(cssSheet); + } // css_sheet + NS_RELEASE(sheet); + } // sheet + } +} + + +void nsMarkupDocument::FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ + nsIContent* content = nsnull; + nsresult isContent = aNode->QueryInterface(kIContentIID, (void**)&content); + PRBool isSynthetic = PR_TRUE; + + if (NS_OK == isContent) + { + content->IsSynthetic(isSynthetic); + if (PR_FALSE == isSynthetic) + { + nsIAtom* tag = content->GetTag(); + if (tag != nsnull) + { + if (tag != nsnull) + { + nsString str; + tag->ToString(str); + if (str.EqualsIgnoreCase("Head")) + StyleSheetsToXIF(aConverter); + } + } + } + } + nsDocument::FinishConvertToXIF(aConverter,aNode); +} + +void nsMarkupDocument::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ + BeginConvertToXIF(aConverter,aNode); + ConvertChildrenToXIF(aConverter,aNode); + FinishConvertToXIF(aConverter,aNode); +} + +void nsMarkupDocument::CreateXIF(nsString & aBuffer, PRBool aUseSelection) +{ + + nsXIFConverter converter(aBuffer); + // call the function + + converter.AddStartTag("section"); + + converter.AddStartTag("section_head"); + converter.AddEndTag("section_head"); + + converter.AddStartTag("section_body"); + + nsIDOMElement* root = nsnull; + if (NS_OK == GetDocumentElement(&root)) + { + ToXIF(converter,root); + NS_RELEASE(root); + } + converter.AddEndTag("section_body"); + + converter.AddEndTag("section"); + + converter.Write(); + +} diff --git a/mozilla/content/html/document/src/nsMarkupDocument.h b/mozilla/content/html/document/src/nsMarkupDocument.h new file mode 100644 index 00000000000..1ae5e7dff48 --- /dev/null +++ b/mozilla/content/html/document/src/nsMarkupDocument.h @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsMarkupDocument_h___ +#define nsMarkupDocument_h___ + +#include "nsDocument.h" +#include "nsIHTMLDocument.h" + +class nsICSSDeclaration; +struct nsCSSSelector; + +/** + * MODULE NOTES: + * @update gpk 7/17/98 + * + * This class is designed to sit between nsDocument and + * classes like nsHTMLDocument. It contains methods which + * are outside the scope of nsDocument but might be used + * by both HTML and XML documents. + * + */ + + +class nsMarkupDocument : public nsDocument { +public: + nsMarkupDocument(); + virtual ~nsMarkupDocument(); + + /** + * Converts the document or a selection of the + * document to XIF (XML Interchange Format) + * and places the result in aBuffer. + + * NOTE: we may way to place the result in a stream, + * but we will use a string for now -- gpk + */ + virtual void CreateXIF(nsString & aBuffer, PRBool aUseSelection); + virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + +protected: + virtual void CSSSelectorToXIF(nsXIFConverter& aConverter, nsCSSSelector& aSelector); + virtual void CSSDeclarationToXIF(nsXIFConverter& aConverter, nsICSSDeclaration& aDeclaration); + virtual void StyleSheetsToXIF(nsXIFConverter& aConverter); + + +private: +}; + +#endif /* nsMarkupDocument_h___ */ diff --git a/mozilla/content/html/style/src/nsCSSDeclaration.cpp b/mozilla/content/html/style/src/nsCSSDeclaration.cpp index 05691119e8c..38f4f48d504 100644 --- a/mozilla/content/html/style/src/nsCSSDeclaration.cpp +++ b/mozilla/content/html/style/src/nsCSSDeclaration.cpp @@ -27,6 +27,160 @@ //#define DEBUG_REFS + +struct CSSColorEntry{ + PRUint8 r; + PRUint8 g; + PRUint8 b; + char *name; +}; + +static CSSColorEntry css_rgb_table[] = +{ + { 0, 0, 0, "black" }, + { 0, 0, 128, "navy" }, + { 0, 0, 139, "darkblue" }, + { 0, 0, 205, "mediumblue" }, + { 0, 0, 255, "blue" }, + { 0, 100, 0, "darkgreen" }, + { 0, 128, 0, "green" }, + { 0, 128, 128, "teal" }, + { 0, 139, 139, "darkcyan" }, + { 0, 191, 255, "deepskyblue" }, + { 0, 206, 209, "darkturquoise" }, + { 0, 250, 154, "mediumspringgreen" }, + { 0, 255, 0, "lime" }, + { 0, 255, 127, "springgreen" }, + { 0, 255, 255, "aqua" }, + { 0, 255, 255, "cyan" }, + { 25, 25, 112, "midnightblue" }, + { 30, 144, 255, "dodgerblue" }, + { 32, 178, 170, "lightseagreen" }, + { 34, 139, 34, "forestgreen" }, + { 46, 139, 87, "seagreen" }, + { 47, 79, 79, "darkslategray" }, + { 50, 205, 50, "limegreen" }, + { 60, 179, 113, "mediumseagreen" }, + { 64, 224, 208, "turquoise" }, + { 65, 105, 225, "royalblue" }, + { 70, 130, 180, "steelblue" }, + { 72, 61, 139, "darkslateblue" }, + { 72, 209, 204, "mediumturquoise" }, + { 75, 0, 130, "indigo" }, + { 85, 107, 47, "darkolivegreen" }, + { 95, 158, 160, "cadetblue" }, + {100, 149, 237, "cornflowerblue" }, + {102, 205, 170, "mediumaquamarine" }, + {105, 105, 105, "dimgray" }, + {106, 90, 205, "slateblue" }, + {107, 142, 35, "olivedrab" }, + {112, 128, 144, "slategray" }, + {119, 136, 153, "lightslategray" }, + {123, 104, 238, "mediumslateblue" }, + {124, 252, 0, "lawngreen" }, + {127, 255, 0, "chartreuse" }, + {127, 255, 212, "aquamarine" }, + {128, 0, 0, "maroon" }, + {128, 0, 128, "purple" }, + {128, 128, 0, "olive" }, + {128, 128, 128, "gray" }, + {135, 206, 235, "skyblue" }, + {135, 206, 250, "lightskyblue" }, + {138, 43, 226, "blueviolet" }, + {139, 0, 0, "darkred" }, + {139, 0, 139, "darkmagenta" }, + {139, 69, 19, "saddlebrown" }, + {143, 188, 143, "darkseagreen" }, + {144, 238, 144, "lightgreen" }, + {147, 112, 219, "mediumpurple" }, + {148, 0, 211, "darkviolet" }, + {152, 251, 152, "palegreen" }, + {153, 50, 204, "darkorchid" }, + {154, 205, 50, "yellowgreen" }, + {160, 82, 45, "sienna" }, + {165, 42, 42, "brown" }, + {169, 169, 169, "darkgray" }, + {173, 216, 230, "lightblue" }, + {173, 255, 47, "greenyellow" }, + {175, 238, 238, "paleturquoise" }, + {176, 196, 222, "lightsteelblue" }, + {176, 224, 230, "powderblue" }, + {178, 34, 34, "firebrick" }, + {184, 134, 11, "darkgoldenrod" }, + {186, 85, 211, "mediumorchid" }, + {188, 143, 143, "rosybrown" }, + {189, 183, 107, "darkkhaki" }, + {192, 192, 192, "silver" }, + {199, 21, 133, "mediumvioletred" }, + {205, 92, 92, "indianred" }, + {205, 133, 63, "peru" }, + {210, 105, 30, "chocolate" }, + {210, 180, 140, "tan" }, + {211, 211, 211, "lightgrey" }, + {216, 191, 216, "thistle" }, + {218, 112, 214, "orchid" }, + {218, 165, 32, "goldenrod" }, + {219, 112, 147, "palevioletred" }, + {220, 20, 60, "crimson" }, + {220, 220, 220, "gainsboro" }, + {221, 160, 221, "plum" }, + {222, 184, 135, "burlywood" }, + {224, 255, 255, "lightcyan" }, + {230, 230, 250, "lavender" }, + {233, 150, 122, "darksalmon" }, + {238, 130, 238, "violet" }, + {238, 232, 170, "palegoldenrod" }, + {240, 128, 128, "lightcoral" }, + {240, 230, 140, "khaki" }, + {240, 248, 255, "aliceblue" }, + {240, 255, 240, "honeydew" }, + {240, 255, 255, "azure" }, + {244, 164, 96, "sandybrown" }, + {245, 222, 179, "wheat" }, + {245, 245, 220, "beige" }, + {245, 245, 245, "whitesmoke" }, + {245, 255, 250, "mintcream" }, + {248, 248, 255, "ghostwhite" }, + {250, 128, 114, "salmon" }, + {250, 235, 215, "antiquewhite" }, + {250, 240, 230, "linen" }, + {250, 250, 210, "lightgoldenrodyellow" }, + {253, 245, 230, "oldlace" }, + {255, 0, 0, "red" }, + {255, 0, 255, "fuchsia" }, + {255, 0, 255, "magenta" }, + {255, 20, 147, "deeppink" }, + {255, 69, 0, "orangered" }, + {255, 99, 71, "tomato" }, + {255, 105, 180, "hotpink" }, + {255, 127, 80, "coral" }, + {255, 140, 0, "darkorange" }, + {255, 160, 122, "lightsalmon" }, + {255, 165, 0, "orange" }, + {255, 182, 193, "lightpink" }, + {255, 192, 203, "pink" }, + {255, 215, 0, "gold" }, + {255, 218, 185, "peachpuff" }, + {255, 222, 173, "navajowhite" }, + {255, 228, 181, "moccasin" }, + {255, 228, 196, "bisque" }, + {255, 228, 225, "mistyrose" }, + {255, 235, 205, "blanchedalmond" }, + {255, 239, 213, "papayawhip" }, + {255, 240, 245, "lavenderblush" }, + {255, 245, 238, "seashell" }, + {255, 248, 220, "cornsilk" }, + {255, 250, 205, "lemonchiffon" }, + {255, 250, 240, "floralwhite" }, + {255, 250, 250, "snow" }, + {255, 255, 0, "yellow" }, + {255, 255, 224, "lightyellow" }, + {255, 255, 240, "ivory" }, + {255, 255, 255, "white" }, +}; + + + static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID); static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID); static NS_DEFINE_IID(kCSSDisplaySID, NS_CSS_DISPLAY_SID); @@ -2062,6 +2216,35 @@ NS_HTML nsresult +const char* RGBToCSSString(PRInt32 r, PRInt32 g, PRInt32 b) +{ + const char* result = nsnull; + + PRInt32 index = 0; + PRInt32 count = sizeof(css_rgb_table)/sizeof(CSSColorEntry); + CSSColorEntry* entry = nsnull; + + for (index = 0; index < count; index++) + { + entry = &css_rgb_table[index]; + if (entry->r == r) + { + if (entry->g == g && entry->b == b) + { + result = entry->name; + break; + } + } + else if (entry->r > r) + { + break; + } + } + return result; +} + + + void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const { if (eCSSUnit_Null == mUnit) { @@ -2070,51 +2253,46 @@ void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const if (eCSSUnit_String == mUnit) { if (nsnull != mValue.mString) { - aBuffer.Append('"'); aBuffer.Append(*(mValue.mString)); - aBuffer.Append('"'); } else { aBuffer.Append("null str"); } } else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) { - - if (aPropID == PROP_FONT_SIZE && mUnit == eCSSUnit_Enumerated) + if (mUnit == eCSSUnit_Enumerated) { - PRBool found = PR_TRUE; - switch (mValue.mInt) + const char* name = nsCSSProps::LookupProperty(aPropID,mValue.mInt); + if (name != nsnull) { - case NS_STYLE_FONT_SIZE_XXSMALL: aBuffer.Append("xx-small"); break; - case NS_STYLE_FONT_SIZE_XSMALL: aBuffer.Append("x-small"); break; - case NS_STYLE_FONT_SIZE_SMALL: aBuffer.Append("small"); break; - case NS_STYLE_FONT_SIZE_MEDIUM: aBuffer.Append("medium"); break; - case NS_STYLE_FONT_SIZE_LARGE: aBuffer.Append("large"); break; - case NS_STYLE_FONT_SIZE_XLARGE: aBuffer.Append("x-large"); break; - case NS_STYLE_FONT_SIZE_XXLARGE: aBuffer.Append("xx-large"); break; - case NS_STYLE_FONT_SIZE_LARGER: aBuffer.Append("larger"); break; - case NS_STYLE_FONT_SIZE_SMALLER: aBuffer.Append("smaller"); break; - - default: - found = PR_FALSE; - } - if (found) + aBuffer.Append(name); return; - - } + } + } aBuffer.Append(mValue.mInt, 10); aBuffer.Append("[0x"); aBuffer.Append(mValue.mInt, 16); aBuffer.Append(']'); } else if (eCSSUnit_Color == mUnit){ - aBuffer.Append("rgb("); - aBuffer.Append(NS_GET_R(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_G(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_B(mValue.mColor), 10); - aBuffer.Append(')'); + PRInt32 r = NS_GET_R(mValue.mColor); + PRInt32 g = NS_GET_G(mValue.mColor); + PRInt32 b = NS_GET_B(mValue.mColor); + + const char* name = RGBToCSSString(r,g,b); + + if (name != nsnull) + aBuffer.Append(name); + else + { + aBuffer.Append("rgb("); + aBuffer.Append(NS_GET_R(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_G(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_B(mValue.mColor), 10); + aBuffer.Append(')'); + } return; } else if (eCSSUnit_Percent == mUnit) { diff --git a/mozilla/content/html/style/src/nsCSSParser.cpp b/mozilla/content/html/style/src/nsCSSParser.cpp index 47b53598d20..4894d23207a 100644 --- a/mozilla/content/html/style/src/nsCSSParser.cpp +++ b/mozilla/content/html/style/src/nsCSSParser.cpp @@ -30,6 +30,7 @@ #include "nsIAtom.h" #include "nsVoidArray.h" #include "nsColor.h" +#include "nsStyleConsts.h" // XXX TODO: // - rework aErrorCode stuff: switch over to nsresult diff --git a/mozilla/content/html/style/src/nsCSSProps.h b/mozilla/content/html/style/src/nsCSSProps.h index 29bd8de6945..9fddff3b07c 100644 --- a/mozilla/content/html/style/src/nsCSSProps.h +++ b/mozilla/content/html/style/src/nsCSSProps.h @@ -28,6 +28,12 @@ public: // known. The lookup function uses a perfect hash. static PRInt32 LookupName(const char* str); + + // Given a CSS Property ID and an Property Value Index + // Return back a const char* representation of the + // value. Return back nsnull if no value is found + static const char* LookupProperty(PRInt32 aProp, PRInt32 aIndex); + struct NameTableEntry { const char* name; PRInt32 id; diff --git a/mozilla/content/html/style/src/nsCSSStruct.cpp b/mozilla/content/html/style/src/nsCSSStruct.cpp index 05691119e8c..38f4f48d504 100644 --- a/mozilla/content/html/style/src/nsCSSStruct.cpp +++ b/mozilla/content/html/style/src/nsCSSStruct.cpp @@ -27,6 +27,160 @@ //#define DEBUG_REFS + +struct CSSColorEntry{ + PRUint8 r; + PRUint8 g; + PRUint8 b; + char *name; +}; + +static CSSColorEntry css_rgb_table[] = +{ + { 0, 0, 0, "black" }, + { 0, 0, 128, "navy" }, + { 0, 0, 139, "darkblue" }, + { 0, 0, 205, "mediumblue" }, + { 0, 0, 255, "blue" }, + { 0, 100, 0, "darkgreen" }, + { 0, 128, 0, "green" }, + { 0, 128, 128, "teal" }, + { 0, 139, 139, "darkcyan" }, + { 0, 191, 255, "deepskyblue" }, + { 0, 206, 209, "darkturquoise" }, + { 0, 250, 154, "mediumspringgreen" }, + { 0, 255, 0, "lime" }, + { 0, 255, 127, "springgreen" }, + { 0, 255, 255, "aqua" }, + { 0, 255, 255, "cyan" }, + { 25, 25, 112, "midnightblue" }, + { 30, 144, 255, "dodgerblue" }, + { 32, 178, 170, "lightseagreen" }, + { 34, 139, 34, "forestgreen" }, + { 46, 139, 87, "seagreen" }, + { 47, 79, 79, "darkslategray" }, + { 50, 205, 50, "limegreen" }, + { 60, 179, 113, "mediumseagreen" }, + { 64, 224, 208, "turquoise" }, + { 65, 105, 225, "royalblue" }, + { 70, 130, 180, "steelblue" }, + { 72, 61, 139, "darkslateblue" }, + { 72, 209, 204, "mediumturquoise" }, + { 75, 0, 130, "indigo" }, + { 85, 107, 47, "darkolivegreen" }, + { 95, 158, 160, "cadetblue" }, + {100, 149, 237, "cornflowerblue" }, + {102, 205, 170, "mediumaquamarine" }, + {105, 105, 105, "dimgray" }, + {106, 90, 205, "slateblue" }, + {107, 142, 35, "olivedrab" }, + {112, 128, 144, "slategray" }, + {119, 136, 153, "lightslategray" }, + {123, 104, 238, "mediumslateblue" }, + {124, 252, 0, "lawngreen" }, + {127, 255, 0, "chartreuse" }, + {127, 255, 212, "aquamarine" }, + {128, 0, 0, "maroon" }, + {128, 0, 128, "purple" }, + {128, 128, 0, "olive" }, + {128, 128, 128, "gray" }, + {135, 206, 235, "skyblue" }, + {135, 206, 250, "lightskyblue" }, + {138, 43, 226, "blueviolet" }, + {139, 0, 0, "darkred" }, + {139, 0, 139, "darkmagenta" }, + {139, 69, 19, "saddlebrown" }, + {143, 188, 143, "darkseagreen" }, + {144, 238, 144, "lightgreen" }, + {147, 112, 219, "mediumpurple" }, + {148, 0, 211, "darkviolet" }, + {152, 251, 152, "palegreen" }, + {153, 50, 204, "darkorchid" }, + {154, 205, 50, "yellowgreen" }, + {160, 82, 45, "sienna" }, + {165, 42, 42, "brown" }, + {169, 169, 169, "darkgray" }, + {173, 216, 230, "lightblue" }, + {173, 255, 47, "greenyellow" }, + {175, 238, 238, "paleturquoise" }, + {176, 196, 222, "lightsteelblue" }, + {176, 224, 230, "powderblue" }, + {178, 34, 34, "firebrick" }, + {184, 134, 11, "darkgoldenrod" }, + {186, 85, 211, "mediumorchid" }, + {188, 143, 143, "rosybrown" }, + {189, 183, 107, "darkkhaki" }, + {192, 192, 192, "silver" }, + {199, 21, 133, "mediumvioletred" }, + {205, 92, 92, "indianred" }, + {205, 133, 63, "peru" }, + {210, 105, 30, "chocolate" }, + {210, 180, 140, "tan" }, + {211, 211, 211, "lightgrey" }, + {216, 191, 216, "thistle" }, + {218, 112, 214, "orchid" }, + {218, 165, 32, "goldenrod" }, + {219, 112, 147, "palevioletred" }, + {220, 20, 60, "crimson" }, + {220, 220, 220, "gainsboro" }, + {221, 160, 221, "plum" }, + {222, 184, 135, "burlywood" }, + {224, 255, 255, "lightcyan" }, + {230, 230, 250, "lavender" }, + {233, 150, 122, "darksalmon" }, + {238, 130, 238, "violet" }, + {238, 232, 170, "palegoldenrod" }, + {240, 128, 128, "lightcoral" }, + {240, 230, 140, "khaki" }, + {240, 248, 255, "aliceblue" }, + {240, 255, 240, "honeydew" }, + {240, 255, 255, "azure" }, + {244, 164, 96, "sandybrown" }, + {245, 222, 179, "wheat" }, + {245, 245, 220, "beige" }, + {245, 245, 245, "whitesmoke" }, + {245, 255, 250, "mintcream" }, + {248, 248, 255, "ghostwhite" }, + {250, 128, 114, "salmon" }, + {250, 235, 215, "antiquewhite" }, + {250, 240, 230, "linen" }, + {250, 250, 210, "lightgoldenrodyellow" }, + {253, 245, 230, "oldlace" }, + {255, 0, 0, "red" }, + {255, 0, 255, "fuchsia" }, + {255, 0, 255, "magenta" }, + {255, 20, 147, "deeppink" }, + {255, 69, 0, "orangered" }, + {255, 99, 71, "tomato" }, + {255, 105, 180, "hotpink" }, + {255, 127, 80, "coral" }, + {255, 140, 0, "darkorange" }, + {255, 160, 122, "lightsalmon" }, + {255, 165, 0, "orange" }, + {255, 182, 193, "lightpink" }, + {255, 192, 203, "pink" }, + {255, 215, 0, "gold" }, + {255, 218, 185, "peachpuff" }, + {255, 222, 173, "navajowhite" }, + {255, 228, 181, "moccasin" }, + {255, 228, 196, "bisque" }, + {255, 228, 225, "mistyrose" }, + {255, 235, 205, "blanchedalmond" }, + {255, 239, 213, "papayawhip" }, + {255, 240, 245, "lavenderblush" }, + {255, 245, 238, "seashell" }, + {255, 248, 220, "cornsilk" }, + {255, 250, 205, "lemonchiffon" }, + {255, 250, 240, "floralwhite" }, + {255, 250, 250, "snow" }, + {255, 255, 0, "yellow" }, + {255, 255, 224, "lightyellow" }, + {255, 255, 240, "ivory" }, + {255, 255, 255, "white" }, +}; + + + static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID); static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID); static NS_DEFINE_IID(kCSSDisplaySID, NS_CSS_DISPLAY_SID); @@ -2062,6 +2216,35 @@ NS_HTML nsresult +const char* RGBToCSSString(PRInt32 r, PRInt32 g, PRInt32 b) +{ + const char* result = nsnull; + + PRInt32 index = 0; + PRInt32 count = sizeof(css_rgb_table)/sizeof(CSSColorEntry); + CSSColorEntry* entry = nsnull; + + for (index = 0; index < count; index++) + { + entry = &css_rgb_table[index]; + if (entry->r == r) + { + if (entry->g == g && entry->b == b) + { + result = entry->name; + break; + } + } + else if (entry->r > r) + { + break; + } + } + return result; +} + + + void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const { if (eCSSUnit_Null == mUnit) { @@ -2070,51 +2253,46 @@ void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const if (eCSSUnit_String == mUnit) { if (nsnull != mValue.mString) { - aBuffer.Append('"'); aBuffer.Append(*(mValue.mString)); - aBuffer.Append('"'); } else { aBuffer.Append("null str"); } } else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) { - - if (aPropID == PROP_FONT_SIZE && mUnit == eCSSUnit_Enumerated) + if (mUnit == eCSSUnit_Enumerated) { - PRBool found = PR_TRUE; - switch (mValue.mInt) + const char* name = nsCSSProps::LookupProperty(aPropID,mValue.mInt); + if (name != nsnull) { - case NS_STYLE_FONT_SIZE_XXSMALL: aBuffer.Append("xx-small"); break; - case NS_STYLE_FONT_SIZE_XSMALL: aBuffer.Append("x-small"); break; - case NS_STYLE_FONT_SIZE_SMALL: aBuffer.Append("small"); break; - case NS_STYLE_FONT_SIZE_MEDIUM: aBuffer.Append("medium"); break; - case NS_STYLE_FONT_SIZE_LARGE: aBuffer.Append("large"); break; - case NS_STYLE_FONT_SIZE_XLARGE: aBuffer.Append("x-large"); break; - case NS_STYLE_FONT_SIZE_XXLARGE: aBuffer.Append("xx-large"); break; - case NS_STYLE_FONT_SIZE_LARGER: aBuffer.Append("larger"); break; - case NS_STYLE_FONT_SIZE_SMALLER: aBuffer.Append("smaller"); break; - - default: - found = PR_FALSE; - } - if (found) + aBuffer.Append(name); return; - - } + } + } aBuffer.Append(mValue.mInt, 10); aBuffer.Append("[0x"); aBuffer.Append(mValue.mInt, 16); aBuffer.Append(']'); } else if (eCSSUnit_Color == mUnit){ - aBuffer.Append("rgb("); - aBuffer.Append(NS_GET_R(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_G(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_B(mValue.mColor), 10); - aBuffer.Append(')'); + PRInt32 r = NS_GET_R(mValue.mColor); + PRInt32 g = NS_GET_G(mValue.mColor); + PRInt32 b = NS_GET_B(mValue.mColor); + + const char* name = RGBToCSSString(r,g,b); + + if (name != nsnull) + aBuffer.Append(name); + else + { + aBuffer.Append("rgb("); + aBuffer.Append(NS_GET_R(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_G(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_B(mValue.mColor), 10); + aBuffer.Append(')'); + } return; } else if (eCSSUnit_Percent == mUnit) { diff --git a/mozilla/content/shared/public/nsCSSProps.h b/mozilla/content/shared/public/nsCSSProps.h index 29bd8de6945..9fddff3b07c 100644 --- a/mozilla/content/shared/public/nsCSSProps.h +++ b/mozilla/content/shared/public/nsCSSProps.h @@ -28,6 +28,12 @@ public: // known. The lookup function uses a perfect hash. static PRInt32 LookupName(const char* str); + + // Given a CSS Property ID and an Property Value Index + // Return back a const char* representation of the + // value. Return back nsnull if no value is found + static const char* LookupProperty(PRInt32 aProp, PRInt32 aIndex); + struct NameTableEntry { const char* name; PRInt32 id; diff --git a/mozilla/content/shared/src/nsCSSProps.cpp b/mozilla/content/shared/src/nsCSSProps.cpp index b5431d82aa0..44479e77776 100644 --- a/mozilla/content/shared/src/nsCSSProps.cpp +++ b/mozilla/content/shared/src/nsCSSProps.cpp @@ -6,6 +6,10 @@ #include "plstr.h" #include "nsCSSProps.h" +#include "nsCSSKeywordIDs.h" +#include "nsStyleConsts.h" +#include "nsCSSKeywords.h" + #define TOTAL_KEYWORDS 80 #define MIN_WORD_LENGTH 3 #define MAX_WORD_LENGTH 21 @@ -363,3 +367,414 @@ const nsCSSProps::NameTableEntry nsCSSProps::kNameTable[] = { { "word-spacing", 78 }, { "z-index", 79 }, }; + + + + +// Keyword id tables for variant/enum parsing +static PRInt32 kBackgroundAttachmentKTable[] = { + KEYWORD_FIXED, NS_STYLE_BG_ATTACHMENT_FIXED, + KEYWORD_SCROLL, NS_STYLE_BG_ATTACHMENT_SCROLL, + -1,-1 +}; + +static PRInt32 kBackgroundColorKTable[] = { + KEYWORD_TRANSPARENT, NS_STYLE_BG_COLOR_TRANSPARENT, + -1,-1 +}; + +static PRInt32 kBackgroundRepeatKTable[] = { + KEYWORD_NO_REPEAT, NS_STYLE_BG_REPEAT_OFF, + KEYWORD_REPEAT, NS_STYLE_BG_REPEAT_XY, + KEYWORD_REPEAT_X, NS_STYLE_BG_REPEAT_X, + KEYWORD_REPEAT_Y, NS_STYLE_BG_REPEAT_Y, + -1,-1 +}; + +static PRInt32 kBorderStyleKTable[] = { + KEYWORD_NONE, NS_STYLE_BORDER_STYLE_NONE, + KEYWORD_DOTTED, NS_STYLE_BORDER_STYLE_DOTTED, + KEYWORD_DASHED, NS_STYLE_BORDER_STYLE_DASHED, + KEYWORD_SOLID, NS_STYLE_BORDER_STYLE_SOLID, + KEYWORD_DOUBLE, NS_STYLE_BORDER_STYLE_DOUBLE, + KEYWORD_GROOVE, NS_STYLE_BORDER_STYLE_GROOVE, + KEYWORD_RIDGE, NS_STYLE_BORDER_STYLE_RIDGE, + KEYWORD_INSET, NS_STYLE_BORDER_STYLE_INSET, + KEYWORD_OUTSET, NS_STYLE_BORDER_STYLE_OUTSET, + -1,-1 +}; + +static PRInt32 kBorderWidthKTable[] = { + KEYWORD_THIN, NS_STYLE_BORDER_WIDTH_THIN, + KEYWORD_MEDIUM, NS_STYLE_BORDER_WIDTH_MEDIUM, + KEYWORD_THICK, NS_STYLE_BORDER_WIDTH_THICK, + -1,-1 +}; + +static PRInt32 kClearKTable[] = { + KEYWORD_NONE, NS_STYLE_CLEAR_NONE, + KEYWORD_LEFT, NS_STYLE_CLEAR_LEFT, + KEYWORD_RIGHT, NS_STYLE_CLEAR_RIGHT, + KEYWORD_BOTH, NS_STYLE_CLEAR_LEFT_AND_RIGHT, + -1,-1 +}; + +static PRInt32 kCursorKTable[] = { + KEYWORD_IBEAM, NS_STYLE_CURSOR_IBEAM, + KEYWORD_ARROW, NS_STYLE_CURSOR_DEFAULT, + KEYWORD_HAND, NS_STYLE_CURSOR_HAND, + -1,-1 +}; + +static PRInt32 kDirectionKTable[] = { + KEYWORD_LTR, NS_STYLE_DIRECTION_LTR, + KEYWORD_RTL, NS_STYLE_DIRECTION_RTL, + KEYWORD_INHERIT, NS_STYLE_DIRECTION_INHERIT, + -1,-1 +}; + +static PRInt32 kDisplayKTable[] = { + KEYWORD_NONE, NS_STYLE_DISPLAY_NONE, + KEYWORD_BLOCK, NS_STYLE_DISPLAY_BLOCK, + KEYWORD_INLINE, NS_STYLE_DISPLAY_INLINE, + KEYWORD_LIST_ITEM, NS_STYLE_DISPLAY_LIST_ITEM, + KEYWORD_MARKER, NS_STYLE_DISPLAY_MARKER, + KEYWORD_RUN_IN, NS_STYLE_DISPLAY_RUN_IN, + KEYWORD_COMPACT, NS_STYLE_DISPLAY_COMPACT, + KEYWORD_TABLE, NS_STYLE_DISPLAY_TABLE, + KEYWORD_INLINE_TABLE, NS_STYLE_DISPLAY_INLINE_TABLE, + KEYWORD_TABLE_ROW_GROUP, NS_STYLE_DISPLAY_TABLE_ROW_GROUP, + KEYWORD_TABLE_COLUMN, NS_STYLE_DISPLAY_TABLE_COLUMN, + KEYWORD_TABLE_COLUMN_GROUP, NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP, + KEYWORD_TABLE_HEADER_GROUP, NS_STYLE_DISPLAY_TABLE_HEADER_GROUP, + KEYWORD_TABLE_FOOTER_GROUP, NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP, + KEYWORD_TABLE_ROW, NS_STYLE_DISPLAY_TABLE_ROW, + KEYWORD_TABLE_CELL, NS_STYLE_DISPLAY_TABLE_CELL, + KEYWORD_TABLE_CAPTION, NS_STYLE_DISPLAY_TABLE_CAPTION, + -1,-1 +}; + +static PRInt32 kFloatKTable[] = { + KEYWORD_NONE, NS_STYLE_FLOAT_NONE, + KEYWORD_LEFT, NS_STYLE_FLOAT_LEFT, + KEYWORD_RIGHT, NS_STYLE_FLOAT_RIGHT, + -1,-1 +}; + +static PRInt32 kFontSizeKTable[] = { + KEYWORD_XX_SMALL, NS_STYLE_FONT_SIZE_XXSMALL, + KEYWORD_X_SMALL, NS_STYLE_FONT_SIZE_XSMALL, + KEYWORD_SMALL, NS_STYLE_FONT_SIZE_SMALL, + KEYWORD_MEDIUM, NS_STYLE_FONT_SIZE_MEDIUM, + KEYWORD_LARGE, NS_STYLE_FONT_SIZE_LARGE, + KEYWORD_X_LARGE, NS_STYLE_FONT_SIZE_XLARGE, + KEYWORD_XX_LARGE, NS_STYLE_FONT_SIZE_XXLARGE, + KEYWORD_LARGER, NS_STYLE_FONT_SIZE_LARGER, + KEYWORD_SMALLER, NS_STYLE_FONT_SIZE_SMALLER, + -1,-1 +}; + +static PRInt32 kFontStyleKTable[] = { + KEYWORD_NORMAL, NS_STYLE_FONT_STYLE_NORMAL, + KEYWORD_ITALIC, NS_STYLE_FONT_STYLE_ITALIC, + KEYWORD_OBLIQUE, NS_STYLE_FONT_STYLE_OBLIQUE, + -1,-1 +}; + +static PRInt32 kFontVariantKTable[] = { + KEYWORD_NORMAL, NS_STYLE_FONT_VARIANT_NORMAL, + KEYWORD_SMALL_CAPS, NS_STYLE_FONT_VARIANT_SMALL_CAPS, + -1,-1 +}; + +static PRInt32 kListStyleImageKTable[] = { + KEYWORD_NONE, NS_STYLE_LIST_STYLE_IMAGE_NONE, + -1,-1 +}; + +static PRInt32 kListStylePositionKTable[] = { + KEYWORD_INSIDE, NS_STYLE_LIST_STYLE_POSITION_INSIDE, + KEYWORD_OUTSIDE, NS_STYLE_LIST_STYLE_POSITION_OUTSIDE, + -1,-1 +}; + +static PRInt32 kListStyleKTable[] = { + KEYWORD_NONE, NS_STYLE_LIST_STYLE_NONE, + KEYWORD_DISC, NS_STYLE_LIST_STYLE_DISC, + KEYWORD_CIRCLE, NS_STYLE_LIST_STYLE_CIRCLE, + KEYWORD_SQUARE, NS_STYLE_LIST_STYLE_SQUARE, + KEYWORD_DECIMAL, NS_STYLE_LIST_STYLE_DECIMAL, + KEYWORD_LOWER_ROMAN, NS_STYLE_LIST_STYLE_LOWER_ROMAN, + KEYWORD_UPPER_ROMAN, NS_STYLE_LIST_STYLE_UPPER_ROMAN, + KEYWORD_LOWER_ALPHA, NS_STYLE_LIST_STYLE_LOWER_ALPHA, + KEYWORD_UPPER_ALPHA, NS_STYLE_LIST_STYLE_UPPER_ALPHA, + -1,-1 +}; + +static PRInt32 kMarginSizeKTable[] = { + KEYWORD_AUTO, NS_STYLE_MARGIN_SIZE_AUTO, + -1,-1 +}; + +static PRInt32 kOverflowKTable[] = { + KEYWORD_VISIBLE, NS_STYLE_OVERFLOW_VISIBLE, + KEYWORD_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN, + KEYWORD_SCROLL, NS_STYLE_OVERFLOW_SCROLL, + KEYWORD_AUTO, NS_STYLE_OVERFLOW_AUTO, + -1,-1 +}; + +static PRInt32 kPositionKTable[] = { + KEYWORD_RELATIVE, NS_STYLE_POSITION_RELATIVE, + KEYWORD_ABSOLUTE, NS_STYLE_POSITION_ABSOLUTE, + KEYWORD_FIXED, NS_STYLE_POSITION_FIXED, + -1,-1 +}; + +static PRInt32 kTextAlignKTable[] = { + KEYWORD_LEFT, NS_STYLE_TEXT_ALIGN_LEFT, + KEYWORD_RIGHT, NS_STYLE_TEXT_ALIGN_RIGHT, + KEYWORD_CENTER, NS_STYLE_TEXT_ALIGN_CENTER, + KEYWORD_JUSTIFY, NS_STYLE_TEXT_ALIGN_JUSTIFY, + -1,-1 +}; + +static PRInt32 kTextTransformKTable[] = { + KEYWORD_NONE, NS_STYLE_TEXT_TRANSFORM_NONE, + KEYWORD_CAPITALIZE, NS_STYLE_TEXT_TRANSFORM_CAPITALIZE, + KEYWORD_LOWERCASE, NS_STYLE_TEXT_TRANSFORM_LOWERCASE, + KEYWORD_UPPERCASE, NS_STYLE_TEXT_TRANSFORM_UPPERCASE, + -1,-1 +}; + +static PRInt32 kVerticalAlignKTable[] = { + KEYWORD_BASELINE, NS_STYLE_VERTICAL_ALIGN_BASELINE, + KEYWORD_SUB, NS_STYLE_VERTICAL_ALIGN_SUB, + KEYWORD_SUPER, NS_STYLE_VERTICAL_ALIGN_SUPER, + KEYWORD_TOP, NS_STYLE_VERTICAL_ALIGN_TOP, + KEYWORD_TEXT_TOP, NS_STYLE_VERTICAL_ALIGN_TEXT_TOP, + KEYWORD_MIDDLE, NS_STYLE_VERTICAL_ALIGN_MIDDLE, + KEYWORD_BOTTOM, NS_STYLE_VERTICAL_ALIGN_BOTTOM, + KEYWORD_TEXT_BOTTOM, NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM, + -1,-1 +}; + +static PRInt32 kVisibilityKTable[] = { + KEYWORD_VISIBLE, NS_STYLE_VISIBILITY_VISIBLE, + KEYWORD_HIDDEN, NS_STYLE_VISIBILITY_HIDDEN, + -1,-1 +}; + +static PRInt32 kWhitespaceKTable[] = { + KEYWORD_NORMAL, NS_STYLE_WHITESPACE_NORMAL, + KEYWORD_PRE, NS_STYLE_WHITESPACE_PRE, + KEYWORD_NOWRAP, NS_STYLE_WHITESPACE_NOWRAP, + -1,-1 +}; + +static const char* kBorderTopNames[] = { + "border-top-width", + "border-top-style", + "border-top-color", +}; +static const char* kBorderRightNames[] = { + "border-right-width", + "border-right-style", + "border-right-color", +}; +static const char* kBorderBottomNames[] = { + "border-bottom-width", + "border-bottom-style", + "border-bottom-color", +}; +static const char* kBorderLeftNames[] = { + "border-left-width", + "border-left-style", + "border-left-color", +}; + +static const char* SearchKeywordTable(PRInt32 aID, PRInt32 aTable[]) +{ + PRInt32 i = 1; + if (aID >= 0) + { + for (;;) { + if (aTable[i] < 0) { + break; + } + if (aID == aTable[i]) { + return nsCSSKeywords::kNameTable[aTable[i-1]].name; + } + i += 2; + } + } + return nsnull; +} + + + +const char* nsCSSProps::LookupProperty(PRInt32 aProp, PRInt32 aIndex) +{ + switch (aProp) { + + case PROP_BACKGROUND: + break; + + case PROP_BACKGROUND_ATTACHMENT: + return SearchKeywordTable(aIndex,kBackgroundAttachmentKTable); + + case PROP_BACKGROUND_COLOR: + return SearchKeywordTable(aIndex,kBackgroundColorKTable); + + case PROP_BACKGROUND_FILTER: + break; + + case PROP_BACKGROUND_IMAGE: + break; + + case PROP_BACKGROUND_POSITION: + break; + + case PROP_BACKGROUND_REPEAT: + return SearchKeywordTable(aIndex,kBackgroundRepeatKTable); + + case PROP_BORDER: + case PROP_BORDER_COLOR: + case PROP_BORDER_STYLE: + case PROP_BORDER_BOTTOM: + case PROP_BORDER_LEFT: + case PROP_BORDER_RIGHT: + case PROP_BORDER_TOP: + case PROP_BORDER_BOTTOM_COLOR: + case PROP_BORDER_LEFT_COLOR: + case PROP_BORDER_RIGHT_COLOR: + case PROP_BORDER_TOP_COLOR: + break; + + case PROP_BORDER_BOTTOM_STYLE: + case PROP_BORDER_LEFT_STYLE: + case PROP_BORDER_RIGHT_STYLE: + case PROP_BORDER_TOP_STYLE: + return SearchKeywordTable(aIndex,kBorderStyleKTable); + break; + + case PROP_BORDER_BOTTOM_WIDTH: + case PROP_BORDER_LEFT_WIDTH: + case PROP_BORDER_RIGHT_WIDTH: + case PROP_BORDER_TOP_WIDTH: + return SearchKeywordTable(aIndex,kBorderWidthKTable); + break; + + case PROP_BORDER_WIDTH: + case PROP_CLEAR: + return SearchKeywordTable(aIndex,kClearKTable); + break; + + case PROP_CLIP: + case PROP_COLOR: + break; + + case PROP_CURSOR: + return SearchKeywordTable(aIndex,kCursorKTable); + break; + + case PROP_DIRECTION: + return SearchKeywordTable(aIndex,kDirectionKTable); + + case PROP_DISPLAY: + return SearchKeywordTable(aIndex,kDisplayKTable); + + case PROP_FILTER: + break; + + case PROP_FLOAT: + return SearchKeywordTable(aIndex,kFloatKTable); + + case PROP_FONT: + case PROP_FONT_FAMILY: + break; + + case PROP_FONT_SIZE: + return SearchKeywordTable(aIndex,kFontSizeKTable); + break; + + case PROP_FONT_STYLE: + return SearchKeywordTable(aIndex,kFontStyleKTable); + + case PROP_FONT_VARIANT: + return SearchKeywordTable(aIndex,kFontVariantKTable); + + + case PROP_FONT_WEIGHT: + case PROP_HEIGHT: + case PROP_LEFT: + case PROP_LINE_HEIGHT: + case PROP_LIST_STYLE: + break; + + case PROP_LIST_STYLE_IMAGE: + return SearchKeywordTable(aIndex, kListStyleImageKTable); + + case PROP_LIST_STYLE_POSITION: + return SearchKeywordTable(aIndex, kListStylePositionKTable); + + + case PROP_LIST_STYLE_TYPE: + return SearchKeywordTable(aIndex, kListStyleKTable); + + case PROP_MARGIN: + case PROP_MARGIN_BOTTOM: + case PROP_MARGIN_LEFT: + case PROP_MARGIN_RIGHT: + case PROP_MARGIN_TOP: + return SearchKeywordTable(aIndex, kMarginSizeKTable); + break; + + case PROP_PADDING: + case PROP_PADDING_BOTTOM: + case PROP_PADDING_LEFT: + case PROP_PADDING_RIGHT: + case PROP_PADDING_TOP: + break; + + case PROP_OPACITY: + break; + + case PROP_OVERFLOW: + return SearchKeywordTable(aIndex, kOverflowKTable); + + case PROP_POSITION: + return SearchKeywordTable(aIndex, kPositionKTable); + break; + + case PROP_TEXT_ALIGN: + return SearchKeywordTable(aIndex, kTextAlignKTable); + + case PROP_TEXT_DECORATION: + case PROP_TEXT_INDENT: + break; + + case PROP_TEXT_TRANSFORM: + return SearchKeywordTable(aIndex, kTextTransformKTable); + + case PROP_TOP: + break; + + case PROP_VERTICAL_ALIGN: + return SearchKeywordTable(aIndex, kVerticalAlignKTable); + break; + + case PROP_VISIBILITY: + return SearchKeywordTable(aIndex, kVisibilityKTable); + + case PROP_WHITE_SPACE: + return SearchKeywordTable(aIndex, kWhitespaceKTable); + + case PROP_WIDTH: + case PROP_LETTER_SPACING: + case PROP_WORD_SPACING: + case PROP_Z_INDEX: + break; + } + return nsnull; +} diff --git a/mozilla/layout/base/public/nsIDocument.h b/mozilla/layout/base/public/nsIDocument.h index 9c0708aa20c..284def789da 100644 --- a/mozilla/layout/base/public/nsIDocument.h +++ b/mozilla/layout/base/public/nsIDocument.h @@ -42,6 +42,8 @@ class nsIViewerContainer; class nsIDOMEvent; class nsIDeviceContext; class nsIParser; +class nsIDOMNode; +class nsXIFConverter; // IID for the nsIDocument interface #define NS_IDOCUMENT_IID \ @@ -209,14 +211,26 @@ public: * NOTE: we may way to place the result in a stream, * but we will use a string for now -- gpk */ - virtual void ToXIF(nsString & aBuffer, PRBool aUseSelection) = 0; + virtual void CreateXIF(nsString & aBuffer, PRBool aUseSelection) = 0; + virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0; + virtual void BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0; + virtual void ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0; + virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) = 0; + /* Helper methods to help determine the logical positioning of content */ + virtual PRBool IsInRange(nsIContent *aStartContent, nsIContent* aEndContent, nsIContent* aContent) const = 0; + virtual PRBool IsBefore(nsIContent *aNewContent, nsIContent* aCurrentContent) const = 0; + virtual nsIContent* GetPrevContent(nsIContent *aContent) const = 0; + virtual nsIContent* GetNextContent(nsIContent *aContent) const = 0; NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, nsGUIEvent* aEvent, nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus) = 0; + + + }; diff --git a/mozilla/layout/base/src/nsDocument.cpp b/mozilla/layout/base/src/nsDocument.cpp index e3fab1b06cf..f4fc7a0548e 100644 --- a/mozilla/layout/base/src/nsDocument.cpp +++ b/mozilla/layout/base/src/nsDocument.cpp @@ -993,159 +993,12 @@ void nsDocument::GetSelectionText(nsString & aText) { } -void nsDocument::CSSSelectorToXIF(nsXIFConverter& aConverter, nsCSSSelector& aSelector) -{ - nsString s; - nsCSSSelector* next = aSelector.mNext; - - if (nsnull != next) - CSSSelectorToXIF(aConverter,*next); - - aConverter.BeginCSSSelector(); - - if (aSelector.mTag != nsnull) - { - aSelector.mTag->ToString(s); - aConverter.AddCSSTag(s); - } - - if (aSelector.mID != nsnull) - { - aSelector.mID->ToString(s); - aConverter.AddCSSID(s); - } - - if (aSelector.mClass != nsnull) - { - aSelector.mClass->ToString(s); - aConverter.AddCSSClass(s); - } - - if (aSelector.mPseudoClass != nsnull) - { - aSelector.mPseudoClass->ToString(s); - aConverter.AddCSSPsuedoClass(s); - } - aConverter.EndCSSSelector(); - -} - - -void nsDocument::CSSDeclarationToXIF(nsXIFConverter& aConverter, nsICSSDeclaration& aDeclaration) -{ - PRInt32 propId; - nsCSSValue value; - nsString name; - nsString str; - - - - aConverter.BeginCSSDeclarationList(); - for (propId = 0; propId < PROP_MAX; propId++) - { - switch(propId) - { - case PROP_BACKGROUND: - case PROP_BORDER: - case PROP_CLIP: - case PROP_FONT: - case PROP_LIST_STYLE: - case PROP_MARGIN: - case PROP_PADDING: - case PROP_BACKGROUND_POSITION: - case PROP_BORDER_TOP: - case PROP_BORDER_RIGHT: - case PROP_BORDER_BOTTOM: - case PROP_BORDER_LEFT: - case PROP_BORDER_COLOR: - case PROP_BORDER_STYLE: - case PROP_BORDER_WIDTH: - break; - - default: - aDeclaration.GetValue(propId,value); - if (value.GetUnit() != eHTMLUnit_Null) - { - aConverter.BeginCSSDeclaration(); - name = nsCSSProps::kNameTable[propId].name; - value.ToCSSString(str,propId); - aConverter.AddCSSDeclaration(name,str); - aConverter.EndCSSDeclaration(); - } - } - } - aConverter.EndCSSDeclarationList(); -} - - -void nsDocument::StyleSheetsToXIF(nsXIFConverter& aConverter) -{ - - PRInt32 count = GetNumberOfStyleSheets(); - nsIURL& docURL = *mDocumentURL; - - for (PRInt32 index = 0; index < count; index++) - { - nsIStyleSheet* sheet = GetStyleSheetAt(index); - nsICSSStyleSheet* cssSheet = nsnull; - - if (sheet != nsnull) - { - nsIURL& sheetURL = *sheet->GetURL(); - - if (!(sheetURL == docURL)) - break; - - nsresult isCss = sheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet); - if ((isCss == NS_OK) && (cssSheet != nsnull)) - { - PRInt32 ruleCount = cssSheet->StyleRuleCount(); - PRInt32 ruleIndex; - nsICSSStyleRule* rule = nsnull; - - aConverter.BeginCSSStyleSheet(); - for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++) - { - if (NS_OK == cssSheet->GetStyleRuleAt(ruleIndex, rule)) - { - aConverter.BeginCSSRule(); - - if (nsnull != rule) - { - nsCSSSelector* selector = rule->FirstSelector(); - - if (nsnull != selector) - CSSSelectorToXIF(aConverter,*selector); - - nsICSSDeclaration* declaration = rule->GetDeclaration(); - if (nsnull != declaration) - CSSDeclarationToXIF(aConverter,*declaration); - - NS_IF_RELEASE(declaration); - NS_IF_RELEASE(rule); - } // ruleAt - - aConverter.EndCSSRule(); - } // for loop - } - aConverter.EndCSSStyleSheet(); - NS_RELEASE(cssSheet); - } // css_sheet - NS_RELEASE(sheet); - } // sheet - } -} - - - -void nsDocument::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +void nsDocument::BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) { nsIContent* content = nsnull; - nsresult isContent = aNode->QueryInterface(kIContentIID, (void**)&content); - nsIDOMElement* element = nsnull; - nsresult isElement = aNode->QueryInterface(kIDOMElementIID, (void**)&element); - PRBool isSynthetic = PR_TRUE; + nsresult isContent = aNode->QueryInterface(kIContentIID, (void**)&content); + PRBool isSynthetic = PR_TRUE; // Begin Conversion if (NS_OK == isContent) @@ -1156,50 +1009,50 @@ void nsDocument::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) content->BeginConvertToXIF(aConverter); content->DoConvertToXIF(aConverter); } + NS_RELEASE(content); } - - +} + +void nsDocument::ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ // Iterate through the children, convertion child nodes nsresult result = NS_OK; - nsIDOMNode* node = nsnull; - result = aNode->GetFirstChild(&node); + nsIDOMNode* child = nsnull; + result = aNode->GetFirstChild(&child); - while ((result == NS_OK) && (node != nsnull)) + while ((result == NS_OK) && (child != nsnull)) { - nsIDOMNode* temp = node; - ToXIF(aConverter,node); - result = node->GetNextSibling(&node); + nsIDOMNode* temp = child; + ToXIF(aConverter,child); + result = child->GetNextSibling(&child); NS_RELEASE(temp); } +} - if (NS_OK == isContent && PR_FALSE == isSynthetic) - { - nsIAtom* tag = content->GetTag(); - if (tag != nsnull) - { - if (tag != nsnull) - { - nsString str; - tag->ToString(str); - if (str.EqualsIgnoreCase("Head")) - StyleSheetsToXIF(aConverter); - } - } - } +void nsDocument::FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ + nsIContent* content = nsnull; + nsresult isContent = aNode->QueryInterface(kIContentIID, (void**)&content); + PRBool isSynthetic = PR_TRUE; if (NS_OK == isContent) { + content->IsSynthetic(isSynthetic); if (PR_FALSE == isSynthetic) content->FinishConvertToXIF(aConverter); NS_RELEASE(content); } - if (NS_OK == isElement) - { - NS_RELEASE(element); - } } -void nsDocument::ToXIF(nsString & aBuffer, PRBool aUseSelection) + +void nsDocument::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ + BeginConvertToXIF(aConverter,aNode); + ConvertChildrenToXIF(aConverter,aNode); + FinishConvertToXIF(aConverter,aNode); +} + +void nsDocument::CreateXIF(nsString & aBuffer, PRBool aUseSelection) { nsXIFConverter converter(aBuffer); @@ -1225,3 +1078,102 @@ void nsDocument::ToXIF(nsString & aBuffer, PRBool aUseSelection) converter.Write(); } + + +nsIContent* nsDocument::FindContent( nsIContent* aStartNode, + nsIContent* aTest1, + nsIContent* aTest2) const +{ + PRInt32 count = aStartNode->ChildCount(); + PRInt32 index; + + for(index = 0; index < count;index++) + { + nsIContent* child = aStartNode->ChildAt(index); + nsIContent* content = FindContent(child,aTest1,aTest2); + if (content != nsnull) + return content; + if (child == aTest1 || child == aTest2) + return child; + } + return nsnull; +} + +PRBool nsDocument::IsInRange(nsIContent *aStartContent, nsIContent* aEndContent, nsIContent* aContent) const +{ + PRBool result; + + if (aStartContent == aEndContent) + { + return PRBool(aContent == aStartContent); + } + else if (aStartContent == aContent || aEndContent == aContent) + { + result = PR_TRUE; + } + else + { + result = IsBefore(aStartContent,aContent); + if (result == PR_TRUE) + result = IsBefore(aContent,aEndContent); + } + return result; + +} + + +PRBool nsDocument::IsBefore(nsIContent *aNewContent, nsIContent* aCurrentContent) const +{ + + PRBool result = PR_FALSE; + + if (nsnull != aNewContent && nsnull != aCurrentContent && aNewContent != aCurrentContent) + { + nsIContent* test = FindContent(mRootContent,aNewContent,aCurrentContent); + if (test == aNewContent) + result = PR_TRUE; + } + return result; +} + +nsIContent* nsDocument::GetPrevContent(nsIContent *aContent) const +{ + nsIContent* result = nsnull; + + // Look at previous sibling + + if (nsnull != aContent) + { + nsIContent* parent = aContent->GetParent(); + if (parent != nsnull && parent != mRootContent) + { + PRInt32 index = parent->IndexOf(aContent); + if (index > 0) + result = parent->ChildAt(index-1); + else + result = GetPrevContent(parent); + } + } + return result; +} + +nsIContent* nsDocument::GetNextContent(nsIContent *aContent) const +{ + nsIContent* result = nsnull; + + if (nsnull != aContent) + { + // Look at next sibling + nsIContent* parent = aContent->GetParent(); + if (parent != nsnull && parent != mRootContent) + { + PRInt32 index = parent->IndexOf(aContent); + PRInt32 count = parent->ChildCount(); + if (index+1 < count) + result = parent->ChildAt(index+1); + else + result = GetNextContent(parent); + } + } + return result; +} diff --git a/mozilla/layout/base/src/nsDocument.h b/mozilla/layout/base/src/nsDocument.h index e785d9527c6..851ed57528a 100644 --- a/mozilla/layout/base/src/nsDocument.h +++ b/mozilla/layout/base/src/nsDocument.h @@ -24,12 +24,10 @@ #include "nsIScriptObjectOwner.h" #include "nsIScriptContextOwner.h" #include "nsIDOMEventCapturer.h" +#include "nsXIFConverter.h" class nsISelection; -class nsXIFConverter; class nsIEventListenerManager; -struct nsCSSSelector; -class nsICSSDeclaration; class nsIParser; class nsPostData : public nsIPostData { @@ -191,15 +189,13 @@ public: * Converts the document or a selection of the * document to XIF (XML Interchange Format) * and places the result in aBuffer. - - * NOTE: we may way to place the result in a stream, - * but we will use a string for now -- gpk - */ - virtual void ToXIF(nsString & aBuffer, PRBool aUseSelection); - - virtual void CSSSelectorToXIF(nsXIFConverter& aConverter, nsCSSSelector& aSelector); - virtual void CSSDeclarationToXIF(nsXIFConverter& aConverter, nsICSSDeclaration& aDeclaration); - virtual void StyleSheetsToXIF(nsXIFConverter& aConverter); + */ + virtual void CreateXIF(nsString & aBuffer, PRBool aUseSelection); + virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + virtual void BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + virtual void ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + public: @@ -254,9 +250,19 @@ public: nsIDOMEvent* aDOMEvent, nsEventStatus& aEventStatus); + + virtual PRBool IsInRange(nsIContent *aStartContent, nsIContent* aEndContent, nsIContent* aContent) const; + virtual PRBool IsBefore(nsIContent *aNewContent, nsIContent* aCurrentContent) const; + virtual nsIContent* GetPrevContent(nsIContent *aContent) const; + virtual nsIContent* GetNextContent(nsIContent *aContent) const; + +protected: + nsIContent* FindContent( nsIContent* aStartNode, + nsIContent* aTest1, + nsIContent* aTest2) const; + protected: virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); // subclass hook - virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); nsDocument(); virtual ~nsDocument(); diff --git a/mozilla/layout/base/src/nsFrame.cpp b/mozilla/layout/base/src/nsFrame.cpp index d49764c09b1..a7903fc5989 100644 --- a/mozilla/layout/base/src/nsFrame.cpp +++ b/mozilla/layout/base/src/nsFrame.cpp @@ -34,7 +34,7 @@ #include "nsISizeOfHandler.h" #include "nsIEventStateManager.h" -#define DO_SELECTION 0 +#define DO_SELECTION 1 #include "nsIDOMText.h" #include "nsSelectionRange.h" @@ -65,12 +65,17 @@ PRInt32 fTrackerAddListMax = 0; PRBool gTrackerDebug = PR_FALSE; PRBool gCalcDebug = PR_FALSE; +nsIDocument *gDoc = nsnull; + // [HACK] Foward Declarations void BuildContentList(nsIContent*aContent); +/* PRBool IsInRange(nsIContent * aStartContent, nsIContent * aEndContent, nsIContent * aContent); PRBool IsBefore(nsIContent * aNewContent, nsIContent * aCurrentContent); nsIContent * GetPrevContent(nsIContent * aContent); nsIContent * GetNextContent(nsIContent * aContent); +*/ + void RefreshContentFrames(nsIPresContext& aPresContext, nsIContent * aStartContent, nsIContent * aEndContent); void ForceDrawFrame(nsFrame * aFrame); void resetContentTrackers(); @@ -491,19 +496,26 @@ NS_METHOD nsFrame::Paint(nsIPresContext& aPresContext, return NS_OK; } + nsIPresShell * shell = aPresContext.GetShell(); + nsIDocument * doc = shell->GetDocument(); if (mSelectionRange == nsnull) { // Get Selection Object - nsIPresShell * shell = aPresContext.GetShell(); - nsIDocument * doc = shell->GetDocument(); nsISelection * selection = doc->GetSelection(); mSelectionRange = selection->GetRange(); clearAfterPaint = PR_TRUE; - NS_RELEASE(shell); NS_RELEASE(selection); } - if (IsInRange(mSelectionRange->GetStartContent(), mSelectionRange->GetEndContent(), content)) { + PRBool inRange = doc->IsInRange(mSelectionRange->GetStartContent(), mSelectionRange->GetEndContent(), content); + + if (PR_TRUE == inRange) + cout << "IN" << endl; + else + cout << "OUT" << endl; + + + if (inRange) { nsRect rect; GetRect(rect); rect.width--; @@ -518,7 +530,8 @@ NS_METHOD nsFrame::Paint(nsIPresContext& aPresContext, mSelectionRange = nsnull; } NS_RELEASE(content); - + NS_RELEASE(doc); + NS_RELEASE(shell); #endif return NS_OK; } @@ -593,15 +606,14 @@ NS_METHOD nsFrame::HandlePress(nsIPresContext& aPresContext, #if DO_SELECTION nsFrame * currentFrame = aFrame; nsIPresShell * shell = aPresContext.GetShell(); - nsIDocument * doc = shell->GetDocument(); - nsISelection * selection = doc->GetSelection(); + + gDoc = shell->GetDocument(); + nsISelection * selection = gDoc->GetSelection(); nsMouseEvent * mouseEvent = (nsMouseEvent *)aEvent; mSelectionRange = selection->GetRange(); - NS_RELEASE(shell); - NS_RELEASE(doc); - NS_RELEASE(selection); + PRInt32 offset = 0; @@ -637,13 +649,25 @@ NS_METHOD nsFrame::HandlePress(nsIPresContext& aPresContext, if (gSelectionDebug) printf("****** Shift[%s]\n", (mouseEvent->isShift?"Down":"Up")); - if (IsInRange(mSelectionRange->GetStartContent(), mSelectionRange->GetEndContent(), newContent)) { + PRBool inRange = gDoc->IsInRange(mSelectionRange->GetStartContent(), mSelectionRange->GetEndContent(), newContent); + PRBool isBefore = gDoc->IsBefore(newContent,startContent); + +#if 1 + if (PR_TRUE == inRange) + cout << "IN" << endl; + else if (PR_TRUE == isBefore) + cout << "BEFORE" << endl; + else + cout << "AFTER" << endl; +#endif + + if (inRange) { //resetContentTrackers(); if (gTrackerDebug) printf("Adding split range to removed selection. Shift[%s]\n", (mouseEvent->isShift?"Down":"Up")); if (mouseEvent->isShift) { - nsIContent * prevContent = GetPrevContent(newContent); - nsIContent * nextContent = GetNextContent(newContent); + nsIContent * prevContent = gDoc->GetPrevContent(newContent); + nsIContent * nextContent = gDoc->GetNextContent(newContent); addRangeToSelectionTrackers(mSelectionRange->GetStartContent(), prevContent, kInsertInRemoveList); addRangeToSelectionTrackers(nextContent, mSelectionRange->GetEndContent(), kInsertInRemoveList); @@ -658,15 +682,15 @@ NS_METHOD nsFrame::HandlePress(nsIPresContext& aPresContext, addRangeToSelectionTrackers(newContent, newContent, kInsertInAddList); // add to selection } - } else if (IsBefore(newContent, startContent)) { + } else if (isBefore) { if (mouseEvent->isShift) { if (mStartSelectionPoint->IsAnchor()) { if (gSelectionDebug) printf("New Content is before, Start will now be end\n"); addRangeToSelectionTrackers(mSelectionRange->GetStartContent(), mSelectionRange->GetEndContent(), kInsertInRemoveList); // removed from selection - nsIContent * prevContent = GetPrevContent(newContent); - nsIContent * nextContent = GetNextContent(newContent); + nsIContent * prevContent = gDoc->GetPrevContent(newContent); + nsIContent * nextContent = gDoc->GetNextContent(newContent); mEndSelectionPoint->SetPoint(mStartSelectionPoint->GetContent(), mStartSelectionPoint->GetOffset(), PR_TRUE); mStartSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); @@ -698,8 +722,8 @@ NS_METHOD nsFrame::HandlePress(nsIPresContext& aPresContext, addRangeToSelectionTrackers(mSelectionRange->GetStartContent(), mSelectionRange->GetEndContent(), kInsertInRemoveList); // removed from selection - nsIContent * prevContent = GetPrevContent(newContent); - nsIContent * nextContent = GetNextContent(newContent); + nsIContent * prevContent = gDoc->GetPrevContent(newContent); + nsIContent * nextContent = gDoc->GetNextContent(newContent); mStartSelectionPoint->SetPoint(mEndSelectionPoint->GetContent(), mEndSelectionPoint->GetOffset(), PR_TRUE); mEndSelectionPoint->SetPoint(newContent, mStartPos, PR_FALSE); @@ -759,6 +783,8 @@ NS_METHOD nsFrame::HandlePress(nsIPresContext& aPresContext, ForceDrawFrame(this); NS_RELEASE(newContent); + NS_RELEASE(shell); + NS_RELEASE(selection); #endif aEventStatus = nsEventStatus_eIgnore; @@ -803,7 +829,7 @@ NS_METHOD nsFrame::HandleDrag(nsIPresContext& aPresContext, AdjustPointsInNewContent(aPresContext, aEvent, aFrame); - } else if (IsBefore(newContent, currentContent)) { + } else if (gDoc->IsBefore(newContent, currentContent)) { if (gSelectionDebug) printf("HandleDrag::New Frame, is Before.\n"); resetContentTrackers(); @@ -881,6 +907,7 @@ NS_METHOD nsFrame::HandleRelease(nsIPresContext& aPresContext, mDoingSelection = PR_FALSE; #endif aEventStatus = nsEventStatus_eIgnore; + NS_IF_RELEASE(gDoc); return NS_OK; } @@ -1606,6 +1633,13 @@ void nsFrame::NewContentIsBefore(nsIPresContext& aPresContext, // and the mouse is "before" the anchor in the content // and each new piece of content is being added to the selection + nsIPresShell * shell = aPresContext.GetShell(); + nsIDocument * doc = shell->GetDocument(); + PRBool inRange = doc->IsInRange(mStartSelectionPoint->GetContent(), mEndSelectionPoint->GetContent(), aNewContent); + if (PR_TRUE == inRange) + cout << "IN" << endl; + else + cout << "OUT" << endl; // Check to see if the new content is in the selection if (IsInRange(mStartSelectionPoint->GetContent(), mEndSelectionPoint->GetContent(), aNewContent)) { @@ -1704,6 +1738,14 @@ void nsFrame::NewContentIsAfter(nsIPresContext& aPresContext, // // Check to see if the new content is in the selection + nsIPresShell * shell = aPresContext.GetShell(); + nsIDocument * doc = shell->GetDocument(); + PRBool inRange = doc->IsInRange(mStartSelectionPoint->GetContent(), mEndSelectionPoint->GetContent(), aNewContent); + if (PR_TRUE == inRange) + cout << "IN" << endl; + else + cout << "OUT" << endl; + if (IsInRange(mStartSelectionPoint->GetContent(), mEndSelectionPoint->GetContent(), aNewContent)) { // Case #3 - Remove Content (from Start) diff --git a/mozilla/layout/html/base/src/nsTextContent.cpp b/mozilla/layout/html/base/src/nsTextContent.cpp index 00b4d4819eb..fea8b6a38a2 100644 --- a/mozilla/layout/html/base/src/nsTextContent.cpp +++ b/mozilla/layout/html/base/src/nsTextContent.cpp @@ -47,7 +47,6 @@ #define gCalcDebug 0 -PRBool IsInRange(nsIContent * aStart, nsIContent * aEnd, nsIContent * aContent); #ifdef NS_DEBUG @@ -588,14 +587,13 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext, nsISelection * selection = doc->GetSelection(); nsSelectionRange * range = selection->GetRange(); - NS_RELEASE(shell); - NS_RELEASE(doc); - NS_RELEASE(selection); - if (IsInRange(range->GetStartContent(), range->GetEndContent(), mContent)) { + if (doc->IsInRange(range->GetStartContent(), range->GetEndContent(), mContent)) { nsRect rect; GetRect(rect); + rect.x = 0; // HACK!!!: Not sure why x and y value are sometime garbage -- gpk + rect.y = 0; rect.width--; rect.height--; @@ -616,6 +614,9 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext, aRenderingContext.SetColor(color->mColor); aRenderingContext.DrawString(s0, s - s0, dx, dy, mRect.width); } + NS_RELEASE(shell); + NS_RELEASE(doc); + NS_RELEASE(selection); if (s0 != buf) { delete[] s0; @@ -659,13 +660,12 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext, nsISelection * selection = doc->GetSelection(); nsSelectionRange * range = selection->GetRange(); - NS_RELEASE(shell); - NS_RELEASE(doc); - NS_RELEASE(selection); - if (IsInRange(range->GetStartContent(), range->GetEndContent(), mContent)) { + if (doc->IsInRange(range->GetStartContent(), range->GetEndContent(), mContent)) { nsRect rect; GetRect(rect); + rect.x = 0; // HACK!!!: Not sure why x and y value are sometime garbage -- gpk + rect.y = 0; rect.width--; rect.height--; @@ -687,6 +687,10 @@ TextFrame::PaintRegularText(nsIPresContext& aPresContext, aRenderingContext.DrawString(s0, s - s0, dx, dy, mRect.width); } + NS_RELEASE(shell); + NS_RELEASE(doc); + NS_RELEASE(selection); + if (s0 != buf) { delete[] s0; } diff --git a/mozilla/layout/html/document/src/Makefile b/mozilla/layout/html/document/src/Makefile index cfba14d4b86..dcc138d5762 100644 --- a/mozilla/layout/html/document/src/Makefile +++ b/mozilla/layout/html/document/src/Makefile @@ -33,6 +33,7 @@ INCLUDES += \ # Note the sophisticated alphabetical ordering :-| CPPSRCS = \ + nsMarkupDocument.cpp \ nsHTMLContentSink.cpp \ nsHTMLDocument.cpp \ nsHTMLFrame.cpp \ diff --git a/mozilla/layout/html/document/src/makefile.win b/mozilla/layout/html/document/src/makefile.win index 4cfb820f67a..c6226698100 100644 --- a/mozilla/layout/html/document/src/makefile.win +++ b/mozilla/layout/html/document/src/makefile.win @@ -24,6 +24,7 @@ REQUIRES=xpcom raptor DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN CPPSRCS= \ + nsMarkupDocument.cpp \ nsHTMLContentSink.cpp \ nsHTMLDocument.cpp \ nsHTMLFrame.cpp \ @@ -32,6 +33,7 @@ CPPSRCS= \ $(NULL) CPP_OBJS= \ + .\$(OBJDIR)\nsMarkupDocument.obj \ .\$(OBJDIR)\nsHTMLContentSink.obj \ .\$(OBJDIR)\nsHTMLDocument.obj \ .\$(OBJDIR)\nsHTMLFrame.obj \ diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index 87b8900c1ee..f769e622bde 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -57,7 +57,7 @@ NS_NewHTMLDocument(nsIDocument** aInstancePtrResult) } nsHTMLDocument::nsHTMLDocument() - : nsDocument(), + : nsMarkupDocument(), mAttrStyleSheet(nsnull) { nsHTMLAtoms::AddrefAtoms(); diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.h b/mozilla/layout/html/document/src/nsHTMLDocument.h index c8ca6113133..28109b6f3f7 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.h +++ b/mozilla/layout/html/document/src/nsHTMLDocument.h @@ -19,12 +19,13 @@ #define nsHTMLDocument_h___ #include "nsDocument.h" +#include "nsMarkupDocument.h" #include "nsIHTMLDocument.h" class nsIHTMLStyleSheet; class nsIViewerContainer; -class nsHTMLDocument : public nsDocument { +class nsHTMLDocument : public nsMarkupDocument { public: nsHTMLDocument(); virtual ~nsHTMLDocument(); diff --git a/mozilla/layout/html/document/src/nsMarkupDocument.cpp b/mozilla/layout/html/document/src/nsMarkupDocument.cpp new file mode 100644 index 00000000000..6549c53db88 --- /dev/null +++ b/mozilla/layout/html/document/src/nsMarkupDocument.cpp @@ -0,0 +1,275 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + + + +#include "nsMarkupDocument.h" +#include "nsIContent.h" +#include "nsIURL.h" +#include "nsIDOMElement.h" + +#include "nsCSSPropIDs.h" +#include "nsCSSProps.h" +#include "nsICSSStyleSheet.h" +#include "nsICSSStyleRule.h" +#include "nsICSSDeclaration.h" +#include "nsIHTMLCSSStyleSheet.h" +#include "nsHTMLValue.h" +#include "nsXIFConverter.h" + +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); +static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID); + + + +nsMarkupDocument::nsMarkupDocument() : nsDocument() +{ +} + +nsMarkupDocument::~nsMarkupDocument() +{ +} + +/** + * Converts a CSS selector to XIF + * + * @update gpk 01/17/1998 + * @param aConverter -- the XIFConverter where all output is being written + * @param aSelector -- the Object to be converted to XIF + */ +void nsMarkupDocument::CSSSelectorToXIF(nsXIFConverter& aConverter, nsCSSSelector& aSelector) +{ + nsString s; + + nsCSSSelector* next = aSelector.mNext; + + if (nsnull != next) + CSSSelectorToXIF(aConverter,*next); + + aConverter.BeginCSSSelector(); + + if (aSelector.mTag != nsnull) + { + aSelector.mTag->ToString(s); + aConverter.AddCSSTag(s); + } + + if (aSelector.mID != nsnull) + { + aSelector.mID->ToString(s); + aConverter.AddCSSID(s); + } + + if (aSelector.mClass != nsnull) + { + aSelector.mClass->ToString(s); + aConverter.AddCSSClass(s); + } + + if (aSelector.mPseudoClass != nsnull) + { + aSelector.mPseudoClass->ToString(s); + aConverter.AddCSSPsuedoClass(s); + } + aConverter.EndCSSSelector(); + +} + + +/** + * Converts a CSS Declaration to XIF + * + * @update gpk 01/17/1998 + * @param aConverter -- the XIFConverter where all output is being written + * @param aDeclaration -- the Object to be converted to XIF + */ +void nsMarkupDocument::CSSDeclarationToXIF(nsXIFConverter& aConverter, nsICSSDeclaration& aDeclaration) +{ + PRInt32 propId; + nsCSSValue value; + nsString name; + nsString str; + + + + aConverter.BeginCSSDeclarationList(); + for (propId = 0; propId < PROP_MAX; propId++) + { + switch(propId) + { + case PROP_BACKGROUND: + case PROP_BORDER: + case PROP_CLIP: + case PROP_FONT: + case PROP_LIST_STYLE: + case PROP_MARGIN: + case PROP_PADDING: + case PROP_BACKGROUND_POSITION: + case PROP_BORDER_TOP: + case PROP_BORDER_RIGHT: + case PROP_BORDER_BOTTOM: + case PROP_BORDER_LEFT: + case PROP_BORDER_COLOR: + case PROP_BORDER_STYLE: + case PROP_BORDER_WIDTH: + break; + + default: + aDeclaration.GetValue(propId,value); + if (value.GetUnit() != eHTMLUnit_Null) + { + aConverter.BeginCSSDeclaration(); + name = nsCSSProps::kNameTable[propId].name; + value.ToCSSString(str,propId); + aConverter.AddCSSDeclaration(name,str); + aConverter.EndCSSDeclaration(); + } + } + } + aConverter.EndCSSDeclarationList(); +} + + +/** + * Converts the CSS Stylesheets in this document to XIF + * + * @update gpk 01/17/1998 + * @param aConverter -- the XIFConverter where all output is being written + * @param aDeclaration -- the Object to be converted to XIF + */ +void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter) +{ + + PRInt32 count = GetNumberOfStyleSheets(); + nsIURL& docURL = *mDocumentURL; + + for (PRInt32 index = 0; index < count; index++) + { + nsIStyleSheet* sheet = GetStyleSheetAt(index); + nsICSSStyleSheet* cssSheet = nsnull; + + if (sheet != nsnull) + { + nsIURL& sheetURL = *sheet->GetURL(); + + if (!(sheetURL == docURL)) + break; + + nsresult isCss = sheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet); + if ((isCss == NS_OK) && (cssSheet != nsnull)) + { + PRInt32 ruleCount = cssSheet->StyleRuleCount(); + PRInt32 ruleIndex; + nsICSSStyleRule* rule = nsnull; + + aConverter.BeginCSSStyleSheet(); + for (ruleIndex = 0; ruleIndex < ruleCount; ruleIndex++) + { + if (NS_OK == cssSheet->GetStyleRuleAt(ruleIndex, rule)) + { + aConverter.BeginCSSRule(); + + if (nsnull != rule) + { + nsCSSSelector* selector = rule->FirstSelector(); + + if (nsnull != selector) + CSSSelectorToXIF(aConverter,*selector); + + nsICSSDeclaration* declaration = rule->GetDeclaration(); + if (nsnull != declaration) + CSSDeclarationToXIF(aConverter,*declaration); + + NS_IF_RELEASE(declaration); + NS_IF_RELEASE(rule); + } // ruleAt + + aConverter.EndCSSRule(); + } // for loop + } + aConverter.EndCSSStyleSheet(); + NS_RELEASE(cssSheet); + } // css_sheet + NS_RELEASE(sheet); + } // sheet + } +} + + +void nsMarkupDocument::FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ + nsIContent* content = nsnull; + nsresult isContent = aNode->QueryInterface(kIContentIID, (void**)&content); + PRBool isSynthetic = PR_TRUE; + + if (NS_OK == isContent) + { + content->IsSynthetic(isSynthetic); + if (PR_FALSE == isSynthetic) + { + nsIAtom* tag = content->GetTag(); + if (tag != nsnull) + { + if (tag != nsnull) + { + nsString str; + tag->ToString(str); + if (str.EqualsIgnoreCase("Head")) + StyleSheetsToXIF(aConverter); + } + } + } + } + nsDocument::FinishConvertToXIF(aConverter,aNode); +} + +void nsMarkupDocument::ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode) +{ + BeginConvertToXIF(aConverter,aNode); + ConvertChildrenToXIF(aConverter,aNode); + FinishConvertToXIF(aConverter,aNode); +} + +void nsMarkupDocument::CreateXIF(nsString & aBuffer, PRBool aUseSelection) +{ + + nsXIFConverter converter(aBuffer); + // call the function + + converter.AddStartTag("section"); + + converter.AddStartTag("section_head"); + converter.AddEndTag("section_head"); + + converter.AddStartTag("section_body"); + + nsIDOMElement* root = nsnull; + if (NS_OK == GetDocumentElement(&root)) + { + ToXIF(converter,root); + NS_RELEASE(root); + } + converter.AddEndTag("section_body"); + + converter.AddEndTag("section"); + + converter.Write(); + +} diff --git a/mozilla/layout/html/document/src/nsMarkupDocument.h b/mozilla/layout/html/document/src/nsMarkupDocument.h new file mode 100644 index 00000000000..1ae5e7dff48 --- /dev/null +++ b/mozilla/layout/html/document/src/nsMarkupDocument.h @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsMarkupDocument_h___ +#define nsMarkupDocument_h___ + +#include "nsDocument.h" +#include "nsIHTMLDocument.h" + +class nsICSSDeclaration; +struct nsCSSSelector; + +/** + * MODULE NOTES: + * @update gpk 7/17/98 + * + * This class is designed to sit between nsDocument and + * classes like nsHTMLDocument. It contains methods which + * are outside the scope of nsDocument but might be used + * by both HTML and XML documents. + * + */ + + +class nsMarkupDocument : public nsDocument { +public: + nsMarkupDocument(); + virtual ~nsMarkupDocument(); + + /** + * Converts the document or a selection of the + * document to XIF (XML Interchange Format) + * and places the result in aBuffer. + + * NOTE: we may way to place the result in a stream, + * but we will use a string for now -- gpk + */ + virtual void CreateXIF(nsString & aBuffer, PRBool aUseSelection); + virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode); + +protected: + virtual void CSSSelectorToXIF(nsXIFConverter& aConverter, nsCSSSelector& aSelector); + virtual void CSSDeclarationToXIF(nsXIFConverter& aConverter, nsICSSDeclaration& aDeclaration); + virtual void StyleSheetsToXIF(nsXIFConverter& aConverter); + + +private: +}; + +#endif /* nsMarkupDocument_h___ */ diff --git a/mozilla/layout/html/style/src/nsCSSDeclaration.cpp b/mozilla/layout/html/style/src/nsCSSDeclaration.cpp index 05691119e8c..38f4f48d504 100644 --- a/mozilla/layout/html/style/src/nsCSSDeclaration.cpp +++ b/mozilla/layout/html/style/src/nsCSSDeclaration.cpp @@ -27,6 +27,160 @@ //#define DEBUG_REFS + +struct CSSColorEntry{ + PRUint8 r; + PRUint8 g; + PRUint8 b; + char *name; +}; + +static CSSColorEntry css_rgb_table[] = +{ + { 0, 0, 0, "black" }, + { 0, 0, 128, "navy" }, + { 0, 0, 139, "darkblue" }, + { 0, 0, 205, "mediumblue" }, + { 0, 0, 255, "blue" }, + { 0, 100, 0, "darkgreen" }, + { 0, 128, 0, "green" }, + { 0, 128, 128, "teal" }, + { 0, 139, 139, "darkcyan" }, + { 0, 191, 255, "deepskyblue" }, + { 0, 206, 209, "darkturquoise" }, + { 0, 250, 154, "mediumspringgreen" }, + { 0, 255, 0, "lime" }, + { 0, 255, 127, "springgreen" }, + { 0, 255, 255, "aqua" }, + { 0, 255, 255, "cyan" }, + { 25, 25, 112, "midnightblue" }, + { 30, 144, 255, "dodgerblue" }, + { 32, 178, 170, "lightseagreen" }, + { 34, 139, 34, "forestgreen" }, + { 46, 139, 87, "seagreen" }, + { 47, 79, 79, "darkslategray" }, + { 50, 205, 50, "limegreen" }, + { 60, 179, 113, "mediumseagreen" }, + { 64, 224, 208, "turquoise" }, + { 65, 105, 225, "royalblue" }, + { 70, 130, 180, "steelblue" }, + { 72, 61, 139, "darkslateblue" }, + { 72, 209, 204, "mediumturquoise" }, + { 75, 0, 130, "indigo" }, + { 85, 107, 47, "darkolivegreen" }, + { 95, 158, 160, "cadetblue" }, + {100, 149, 237, "cornflowerblue" }, + {102, 205, 170, "mediumaquamarine" }, + {105, 105, 105, "dimgray" }, + {106, 90, 205, "slateblue" }, + {107, 142, 35, "olivedrab" }, + {112, 128, 144, "slategray" }, + {119, 136, 153, "lightslategray" }, + {123, 104, 238, "mediumslateblue" }, + {124, 252, 0, "lawngreen" }, + {127, 255, 0, "chartreuse" }, + {127, 255, 212, "aquamarine" }, + {128, 0, 0, "maroon" }, + {128, 0, 128, "purple" }, + {128, 128, 0, "olive" }, + {128, 128, 128, "gray" }, + {135, 206, 235, "skyblue" }, + {135, 206, 250, "lightskyblue" }, + {138, 43, 226, "blueviolet" }, + {139, 0, 0, "darkred" }, + {139, 0, 139, "darkmagenta" }, + {139, 69, 19, "saddlebrown" }, + {143, 188, 143, "darkseagreen" }, + {144, 238, 144, "lightgreen" }, + {147, 112, 219, "mediumpurple" }, + {148, 0, 211, "darkviolet" }, + {152, 251, 152, "palegreen" }, + {153, 50, 204, "darkorchid" }, + {154, 205, 50, "yellowgreen" }, + {160, 82, 45, "sienna" }, + {165, 42, 42, "brown" }, + {169, 169, 169, "darkgray" }, + {173, 216, 230, "lightblue" }, + {173, 255, 47, "greenyellow" }, + {175, 238, 238, "paleturquoise" }, + {176, 196, 222, "lightsteelblue" }, + {176, 224, 230, "powderblue" }, + {178, 34, 34, "firebrick" }, + {184, 134, 11, "darkgoldenrod" }, + {186, 85, 211, "mediumorchid" }, + {188, 143, 143, "rosybrown" }, + {189, 183, 107, "darkkhaki" }, + {192, 192, 192, "silver" }, + {199, 21, 133, "mediumvioletred" }, + {205, 92, 92, "indianred" }, + {205, 133, 63, "peru" }, + {210, 105, 30, "chocolate" }, + {210, 180, 140, "tan" }, + {211, 211, 211, "lightgrey" }, + {216, 191, 216, "thistle" }, + {218, 112, 214, "orchid" }, + {218, 165, 32, "goldenrod" }, + {219, 112, 147, "palevioletred" }, + {220, 20, 60, "crimson" }, + {220, 220, 220, "gainsboro" }, + {221, 160, 221, "plum" }, + {222, 184, 135, "burlywood" }, + {224, 255, 255, "lightcyan" }, + {230, 230, 250, "lavender" }, + {233, 150, 122, "darksalmon" }, + {238, 130, 238, "violet" }, + {238, 232, 170, "palegoldenrod" }, + {240, 128, 128, "lightcoral" }, + {240, 230, 140, "khaki" }, + {240, 248, 255, "aliceblue" }, + {240, 255, 240, "honeydew" }, + {240, 255, 255, "azure" }, + {244, 164, 96, "sandybrown" }, + {245, 222, 179, "wheat" }, + {245, 245, 220, "beige" }, + {245, 245, 245, "whitesmoke" }, + {245, 255, 250, "mintcream" }, + {248, 248, 255, "ghostwhite" }, + {250, 128, 114, "salmon" }, + {250, 235, 215, "antiquewhite" }, + {250, 240, 230, "linen" }, + {250, 250, 210, "lightgoldenrodyellow" }, + {253, 245, 230, "oldlace" }, + {255, 0, 0, "red" }, + {255, 0, 255, "fuchsia" }, + {255, 0, 255, "magenta" }, + {255, 20, 147, "deeppink" }, + {255, 69, 0, "orangered" }, + {255, 99, 71, "tomato" }, + {255, 105, 180, "hotpink" }, + {255, 127, 80, "coral" }, + {255, 140, 0, "darkorange" }, + {255, 160, 122, "lightsalmon" }, + {255, 165, 0, "orange" }, + {255, 182, 193, "lightpink" }, + {255, 192, 203, "pink" }, + {255, 215, 0, "gold" }, + {255, 218, 185, "peachpuff" }, + {255, 222, 173, "navajowhite" }, + {255, 228, 181, "moccasin" }, + {255, 228, 196, "bisque" }, + {255, 228, 225, "mistyrose" }, + {255, 235, 205, "blanchedalmond" }, + {255, 239, 213, "papayawhip" }, + {255, 240, 245, "lavenderblush" }, + {255, 245, 238, "seashell" }, + {255, 248, 220, "cornsilk" }, + {255, 250, 205, "lemonchiffon" }, + {255, 250, 240, "floralwhite" }, + {255, 250, 250, "snow" }, + {255, 255, 0, "yellow" }, + {255, 255, 224, "lightyellow" }, + {255, 255, 240, "ivory" }, + {255, 255, 255, "white" }, +}; + + + static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID); static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID); static NS_DEFINE_IID(kCSSDisplaySID, NS_CSS_DISPLAY_SID); @@ -2062,6 +2216,35 @@ NS_HTML nsresult +const char* RGBToCSSString(PRInt32 r, PRInt32 g, PRInt32 b) +{ + const char* result = nsnull; + + PRInt32 index = 0; + PRInt32 count = sizeof(css_rgb_table)/sizeof(CSSColorEntry); + CSSColorEntry* entry = nsnull; + + for (index = 0; index < count; index++) + { + entry = &css_rgb_table[index]; + if (entry->r == r) + { + if (entry->g == g && entry->b == b) + { + result = entry->name; + break; + } + } + else if (entry->r > r) + { + break; + } + } + return result; +} + + + void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const { if (eCSSUnit_Null == mUnit) { @@ -2070,51 +2253,46 @@ void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const if (eCSSUnit_String == mUnit) { if (nsnull != mValue.mString) { - aBuffer.Append('"'); aBuffer.Append(*(mValue.mString)); - aBuffer.Append('"'); } else { aBuffer.Append("null str"); } } else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) { - - if (aPropID == PROP_FONT_SIZE && mUnit == eCSSUnit_Enumerated) + if (mUnit == eCSSUnit_Enumerated) { - PRBool found = PR_TRUE; - switch (mValue.mInt) + const char* name = nsCSSProps::LookupProperty(aPropID,mValue.mInt); + if (name != nsnull) { - case NS_STYLE_FONT_SIZE_XXSMALL: aBuffer.Append("xx-small"); break; - case NS_STYLE_FONT_SIZE_XSMALL: aBuffer.Append("x-small"); break; - case NS_STYLE_FONT_SIZE_SMALL: aBuffer.Append("small"); break; - case NS_STYLE_FONT_SIZE_MEDIUM: aBuffer.Append("medium"); break; - case NS_STYLE_FONT_SIZE_LARGE: aBuffer.Append("large"); break; - case NS_STYLE_FONT_SIZE_XLARGE: aBuffer.Append("x-large"); break; - case NS_STYLE_FONT_SIZE_XXLARGE: aBuffer.Append("xx-large"); break; - case NS_STYLE_FONT_SIZE_LARGER: aBuffer.Append("larger"); break; - case NS_STYLE_FONT_SIZE_SMALLER: aBuffer.Append("smaller"); break; - - default: - found = PR_FALSE; - } - if (found) + aBuffer.Append(name); return; - - } + } + } aBuffer.Append(mValue.mInt, 10); aBuffer.Append("[0x"); aBuffer.Append(mValue.mInt, 16); aBuffer.Append(']'); } else if (eCSSUnit_Color == mUnit){ - aBuffer.Append("rgb("); - aBuffer.Append(NS_GET_R(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_G(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_B(mValue.mColor), 10); - aBuffer.Append(')'); + PRInt32 r = NS_GET_R(mValue.mColor); + PRInt32 g = NS_GET_G(mValue.mColor); + PRInt32 b = NS_GET_B(mValue.mColor); + + const char* name = RGBToCSSString(r,g,b); + + if (name != nsnull) + aBuffer.Append(name); + else + { + aBuffer.Append("rgb("); + aBuffer.Append(NS_GET_R(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_G(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_B(mValue.mColor), 10); + aBuffer.Append(')'); + } return; } else if (eCSSUnit_Percent == mUnit) { diff --git a/mozilla/layout/html/style/src/nsCSSParser.cpp b/mozilla/layout/html/style/src/nsCSSParser.cpp index 47b53598d20..4894d23207a 100644 --- a/mozilla/layout/html/style/src/nsCSSParser.cpp +++ b/mozilla/layout/html/style/src/nsCSSParser.cpp @@ -30,6 +30,7 @@ #include "nsIAtom.h" #include "nsVoidArray.h" #include "nsColor.h" +#include "nsStyleConsts.h" // XXX TODO: // - rework aErrorCode stuff: switch over to nsresult diff --git a/mozilla/layout/html/style/src/nsCSSProps.cpp b/mozilla/layout/html/style/src/nsCSSProps.cpp index b5431d82aa0..44479e77776 100644 --- a/mozilla/layout/html/style/src/nsCSSProps.cpp +++ b/mozilla/layout/html/style/src/nsCSSProps.cpp @@ -6,6 +6,10 @@ #include "plstr.h" #include "nsCSSProps.h" +#include "nsCSSKeywordIDs.h" +#include "nsStyleConsts.h" +#include "nsCSSKeywords.h" + #define TOTAL_KEYWORDS 80 #define MIN_WORD_LENGTH 3 #define MAX_WORD_LENGTH 21 @@ -363,3 +367,414 @@ const nsCSSProps::NameTableEntry nsCSSProps::kNameTable[] = { { "word-spacing", 78 }, { "z-index", 79 }, }; + + + + +// Keyword id tables for variant/enum parsing +static PRInt32 kBackgroundAttachmentKTable[] = { + KEYWORD_FIXED, NS_STYLE_BG_ATTACHMENT_FIXED, + KEYWORD_SCROLL, NS_STYLE_BG_ATTACHMENT_SCROLL, + -1,-1 +}; + +static PRInt32 kBackgroundColorKTable[] = { + KEYWORD_TRANSPARENT, NS_STYLE_BG_COLOR_TRANSPARENT, + -1,-1 +}; + +static PRInt32 kBackgroundRepeatKTable[] = { + KEYWORD_NO_REPEAT, NS_STYLE_BG_REPEAT_OFF, + KEYWORD_REPEAT, NS_STYLE_BG_REPEAT_XY, + KEYWORD_REPEAT_X, NS_STYLE_BG_REPEAT_X, + KEYWORD_REPEAT_Y, NS_STYLE_BG_REPEAT_Y, + -1,-1 +}; + +static PRInt32 kBorderStyleKTable[] = { + KEYWORD_NONE, NS_STYLE_BORDER_STYLE_NONE, + KEYWORD_DOTTED, NS_STYLE_BORDER_STYLE_DOTTED, + KEYWORD_DASHED, NS_STYLE_BORDER_STYLE_DASHED, + KEYWORD_SOLID, NS_STYLE_BORDER_STYLE_SOLID, + KEYWORD_DOUBLE, NS_STYLE_BORDER_STYLE_DOUBLE, + KEYWORD_GROOVE, NS_STYLE_BORDER_STYLE_GROOVE, + KEYWORD_RIDGE, NS_STYLE_BORDER_STYLE_RIDGE, + KEYWORD_INSET, NS_STYLE_BORDER_STYLE_INSET, + KEYWORD_OUTSET, NS_STYLE_BORDER_STYLE_OUTSET, + -1,-1 +}; + +static PRInt32 kBorderWidthKTable[] = { + KEYWORD_THIN, NS_STYLE_BORDER_WIDTH_THIN, + KEYWORD_MEDIUM, NS_STYLE_BORDER_WIDTH_MEDIUM, + KEYWORD_THICK, NS_STYLE_BORDER_WIDTH_THICK, + -1,-1 +}; + +static PRInt32 kClearKTable[] = { + KEYWORD_NONE, NS_STYLE_CLEAR_NONE, + KEYWORD_LEFT, NS_STYLE_CLEAR_LEFT, + KEYWORD_RIGHT, NS_STYLE_CLEAR_RIGHT, + KEYWORD_BOTH, NS_STYLE_CLEAR_LEFT_AND_RIGHT, + -1,-1 +}; + +static PRInt32 kCursorKTable[] = { + KEYWORD_IBEAM, NS_STYLE_CURSOR_IBEAM, + KEYWORD_ARROW, NS_STYLE_CURSOR_DEFAULT, + KEYWORD_HAND, NS_STYLE_CURSOR_HAND, + -1,-1 +}; + +static PRInt32 kDirectionKTable[] = { + KEYWORD_LTR, NS_STYLE_DIRECTION_LTR, + KEYWORD_RTL, NS_STYLE_DIRECTION_RTL, + KEYWORD_INHERIT, NS_STYLE_DIRECTION_INHERIT, + -1,-1 +}; + +static PRInt32 kDisplayKTable[] = { + KEYWORD_NONE, NS_STYLE_DISPLAY_NONE, + KEYWORD_BLOCK, NS_STYLE_DISPLAY_BLOCK, + KEYWORD_INLINE, NS_STYLE_DISPLAY_INLINE, + KEYWORD_LIST_ITEM, NS_STYLE_DISPLAY_LIST_ITEM, + KEYWORD_MARKER, NS_STYLE_DISPLAY_MARKER, + KEYWORD_RUN_IN, NS_STYLE_DISPLAY_RUN_IN, + KEYWORD_COMPACT, NS_STYLE_DISPLAY_COMPACT, + KEYWORD_TABLE, NS_STYLE_DISPLAY_TABLE, + KEYWORD_INLINE_TABLE, NS_STYLE_DISPLAY_INLINE_TABLE, + KEYWORD_TABLE_ROW_GROUP, NS_STYLE_DISPLAY_TABLE_ROW_GROUP, + KEYWORD_TABLE_COLUMN, NS_STYLE_DISPLAY_TABLE_COLUMN, + KEYWORD_TABLE_COLUMN_GROUP, NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP, + KEYWORD_TABLE_HEADER_GROUP, NS_STYLE_DISPLAY_TABLE_HEADER_GROUP, + KEYWORD_TABLE_FOOTER_GROUP, NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP, + KEYWORD_TABLE_ROW, NS_STYLE_DISPLAY_TABLE_ROW, + KEYWORD_TABLE_CELL, NS_STYLE_DISPLAY_TABLE_CELL, + KEYWORD_TABLE_CAPTION, NS_STYLE_DISPLAY_TABLE_CAPTION, + -1,-1 +}; + +static PRInt32 kFloatKTable[] = { + KEYWORD_NONE, NS_STYLE_FLOAT_NONE, + KEYWORD_LEFT, NS_STYLE_FLOAT_LEFT, + KEYWORD_RIGHT, NS_STYLE_FLOAT_RIGHT, + -1,-1 +}; + +static PRInt32 kFontSizeKTable[] = { + KEYWORD_XX_SMALL, NS_STYLE_FONT_SIZE_XXSMALL, + KEYWORD_X_SMALL, NS_STYLE_FONT_SIZE_XSMALL, + KEYWORD_SMALL, NS_STYLE_FONT_SIZE_SMALL, + KEYWORD_MEDIUM, NS_STYLE_FONT_SIZE_MEDIUM, + KEYWORD_LARGE, NS_STYLE_FONT_SIZE_LARGE, + KEYWORD_X_LARGE, NS_STYLE_FONT_SIZE_XLARGE, + KEYWORD_XX_LARGE, NS_STYLE_FONT_SIZE_XXLARGE, + KEYWORD_LARGER, NS_STYLE_FONT_SIZE_LARGER, + KEYWORD_SMALLER, NS_STYLE_FONT_SIZE_SMALLER, + -1,-1 +}; + +static PRInt32 kFontStyleKTable[] = { + KEYWORD_NORMAL, NS_STYLE_FONT_STYLE_NORMAL, + KEYWORD_ITALIC, NS_STYLE_FONT_STYLE_ITALIC, + KEYWORD_OBLIQUE, NS_STYLE_FONT_STYLE_OBLIQUE, + -1,-1 +}; + +static PRInt32 kFontVariantKTable[] = { + KEYWORD_NORMAL, NS_STYLE_FONT_VARIANT_NORMAL, + KEYWORD_SMALL_CAPS, NS_STYLE_FONT_VARIANT_SMALL_CAPS, + -1,-1 +}; + +static PRInt32 kListStyleImageKTable[] = { + KEYWORD_NONE, NS_STYLE_LIST_STYLE_IMAGE_NONE, + -1,-1 +}; + +static PRInt32 kListStylePositionKTable[] = { + KEYWORD_INSIDE, NS_STYLE_LIST_STYLE_POSITION_INSIDE, + KEYWORD_OUTSIDE, NS_STYLE_LIST_STYLE_POSITION_OUTSIDE, + -1,-1 +}; + +static PRInt32 kListStyleKTable[] = { + KEYWORD_NONE, NS_STYLE_LIST_STYLE_NONE, + KEYWORD_DISC, NS_STYLE_LIST_STYLE_DISC, + KEYWORD_CIRCLE, NS_STYLE_LIST_STYLE_CIRCLE, + KEYWORD_SQUARE, NS_STYLE_LIST_STYLE_SQUARE, + KEYWORD_DECIMAL, NS_STYLE_LIST_STYLE_DECIMAL, + KEYWORD_LOWER_ROMAN, NS_STYLE_LIST_STYLE_LOWER_ROMAN, + KEYWORD_UPPER_ROMAN, NS_STYLE_LIST_STYLE_UPPER_ROMAN, + KEYWORD_LOWER_ALPHA, NS_STYLE_LIST_STYLE_LOWER_ALPHA, + KEYWORD_UPPER_ALPHA, NS_STYLE_LIST_STYLE_UPPER_ALPHA, + -1,-1 +}; + +static PRInt32 kMarginSizeKTable[] = { + KEYWORD_AUTO, NS_STYLE_MARGIN_SIZE_AUTO, + -1,-1 +}; + +static PRInt32 kOverflowKTable[] = { + KEYWORD_VISIBLE, NS_STYLE_OVERFLOW_VISIBLE, + KEYWORD_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN, + KEYWORD_SCROLL, NS_STYLE_OVERFLOW_SCROLL, + KEYWORD_AUTO, NS_STYLE_OVERFLOW_AUTO, + -1,-1 +}; + +static PRInt32 kPositionKTable[] = { + KEYWORD_RELATIVE, NS_STYLE_POSITION_RELATIVE, + KEYWORD_ABSOLUTE, NS_STYLE_POSITION_ABSOLUTE, + KEYWORD_FIXED, NS_STYLE_POSITION_FIXED, + -1,-1 +}; + +static PRInt32 kTextAlignKTable[] = { + KEYWORD_LEFT, NS_STYLE_TEXT_ALIGN_LEFT, + KEYWORD_RIGHT, NS_STYLE_TEXT_ALIGN_RIGHT, + KEYWORD_CENTER, NS_STYLE_TEXT_ALIGN_CENTER, + KEYWORD_JUSTIFY, NS_STYLE_TEXT_ALIGN_JUSTIFY, + -1,-1 +}; + +static PRInt32 kTextTransformKTable[] = { + KEYWORD_NONE, NS_STYLE_TEXT_TRANSFORM_NONE, + KEYWORD_CAPITALIZE, NS_STYLE_TEXT_TRANSFORM_CAPITALIZE, + KEYWORD_LOWERCASE, NS_STYLE_TEXT_TRANSFORM_LOWERCASE, + KEYWORD_UPPERCASE, NS_STYLE_TEXT_TRANSFORM_UPPERCASE, + -1,-1 +}; + +static PRInt32 kVerticalAlignKTable[] = { + KEYWORD_BASELINE, NS_STYLE_VERTICAL_ALIGN_BASELINE, + KEYWORD_SUB, NS_STYLE_VERTICAL_ALIGN_SUB, + KEYWORD_SUPER, NS_STYLE_VERTICAL_ALIGN_SUPER, + KEYWORD_TOP, NS_STYLE_VERTICAL_ALIGN_TOP, + KEYWORD_TEXT_TOP, NS_STYLE_VERTICAL_ALIGN_TEXT_TOP, + KEYWORD_MIDDLE, NS_STYLE_VERTICAL_ALIGN_MIDDLE, + KEYWORD_BOTTOM, NS_STYLE_VERTICAL_ALIGN_BOTTOM, + KEYWORD_TEXT_BOTTOM, NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM, + -1,-1 +}; + +static PRInt32 kVisibilityKTable[] = { + KEYWORD_VISIBLE, NS_STYLE_VISIBILITY_VISIBLE, + KEYWORD_HIDDEN, NS_STYLE_VISIBILITY_HIDDEN, + -1,-1 +}; + +static PRInt32 kWhitespaceKTable[] = { + KEYWORD_NORMAL, NS_STYLE_WHITESPACE_NORMAL, + KEYWORD_PRE, NS_STYLE_WHITESPACE_PRE, + KEYWORD_NOWRAP, NS_STYLE_WHITESPACE_NOWRAP, + -1,-1 +}; + +static const char* kBorderTopNames[] = { + "border-top-width", + "border-top-style", + "border-top-color", +}; +static const char* kBorderRightNames[] = { + "border-right-width", + "border-right-style", + "border-right-color", +}; +static const char* kBorderBottomNames[] = { + "border-bottom-width", + "border-bottom-style", + "border-bottom-color", +}; +static const char* kBorderLeftNames[] = { + "border-left-width", + "border-left-style", + "border-left-color", +}; + +static const char* SearchKeywordTable(PRInt32 aID, PRInt32 aTable[]) +{ + PRInt32 i = 1; + if (aID >= 0) + { + for (;;) { + if (aTable[i] < 0) { + break; + } + if (aID == aTable[i]) { + return nsCSSKeywords::kNameTable[aTable[i-1]].name; + } + i += 2; + } + } + return nsnull; +} + + + +const char* nsCSSProps::LookupProperty(PRInt32 aProp, PRInt32 aIndex) +{ + switch (aProp) { + + case PROP_BACKGROUND: + break; + + case PROP_BACKGROUND_ATTACHMENT: + return SearchKeywordTable(aIndex,kBackgroundAttachmentKTable); + + case PROP_BACKGROUND_COLOR: + return SearchKeywordTable(aIndex,kBackgroundColorKTable); + + case PROP_BACKGROUND_FILTER: + break; + + case PROP_BACKGROUND_IMAGE: + break; + + case PROP_BACKGROUND_POSITION: + break; + + case PROP_BACKGROUND_REPEAT: + return SearchKeywordTable(aIndex,kBackgroundRepeatKTable); + + case PROP_BORDER: + case PROP_BORDER_COLOR: + case PROP_BORDER_STYLE: + case PROP_BORDER_BOTTOM: + case PROP_BORDER_LEFT: + case PROP_BORDER_RIGHT: + case PROP_BORDER_TOP: + case PROP_BORDER_BOTTOM_COLOR: + case PROP_BORDER_LEFT_COLOR: + case PROP_BORDER_RIGHT_COLOR: + case PROP_BORDER_TOP_COLOR: + break; + + case PROP_BORDER_BOTTOM_STYLE: + case PROP_BORDER_LEFT_STYLE: + case PROP_BORDER_RIGHT_STYLE: + case PROP_BORDER_TOP_STYLE: + return SearchKeywordTable(aIndex,kBorderStyleKTable); + break; + + case PROP_BORDER_BOTTOM_WIDTH: + case PROP_BORDER_LEFT_WIDTH: + case PROP_BORDER_RIGHT_WIDTH: + case PROP_BORDER_TOP_WIDTH: + return SearchKeywordTable(aIndex,kBorderWidthKTable); + break; + + case PROP_BORDER_WIDTH: + case PROP_CLEAR: + return SearchKeywordTable(aIndex,kClearKTable); + break; + + case PROP_CLIP: + case PROP_COLOR: + break; + + case PROP_CURSOR: + return SearchKeywordTable(aIndex,kCursorKTable); + break; + + case PROP_DIRECTION: + return SearchKeywordTable(aIndex,kDirectionKTable); + + case PROP_DISPLAY: + return SearchKeywordTable(aIndex,kDisplayKTable); + + case PROP_FILTER: + break; + + case PROP_FLOAT: + return SearchKeywordTable(aIndex,kFloatKTable); + + case PROP_FONT: + case PROP_FONT_FAMILY: + break; + + case PROP_FONT_SIZE: + return SearchKeywordTable(aIndex,kFontSizeKTable); + break; + + case PROP_FONT_STYLE: + return SearchKeywordTable(aIndex,kFontStyleKTable); + + case PROP_FONT_VARIANT: + return SearchKeywordTable(aIndex,kFontVariantKTable); + + + case PROP_FONT_WEIGHT: + case PROP_HEIGHT: + case PROP_LEFT: + case PROP_LINE_HEIGHT: + case PROP_LIST_STYLE: + break; + + case PROP_LIST_STYLE_IMAGE: + return SearchKeywordTable(aIndex, kListStyleImageKTable); + + case PROP_LIST_STYLE_POSITION: + return SearchKeywordTable(aIndex, kListStylePositionKTable); + + + case PROP_LIST_STYLE_TYPE: + return SearchKeywordTable(aIndex, kListStyleKTable); + + case PROP_MARGIN: + case PROP_MARGIN_BOTTOM: + case PROP_MARGIN_LEFT: + case PROP_MARGIN_RIGHT: + case PROP_MARGIN_TOP: + return SearchKeywordTable(aIndex, kMarginSizeKTable); + break; + + case PROP_PADDING: + case PROP_PADDING_BOTTOM: + case PROP_PADDING_LEFT: + case PROP_PADDING_RIGHT: + case PROP_PADDING_TOP: + break; + + case PROP_OPACITY: + break; + + case PROP_OVERFLOW: + return SearchKeywordTable(aIndex, kOverflowKTable); + + case PROP_POSITION: + return SearchKeywordTable(aIndex, kPositionKTable); + break; + + case PROP_TEXT_ALIGN: + return SearchKeywordTable(aIndex, kTextAlignKTable); + + case PROP_TEXT_DECORATION: + case PROP_TEXT_INDENT: + break; + + case PROP_TEXT_TRANSFORM: + return SearchKeywordTable(aIndex, kTextTransformKTable); + + case PROP_TOP: + break; + + case PROP_VERTICAL_ALIGN: + return SearchKeywordTable(aIndex, kVerticalAlignKTable); + break; + + case PROP_VISIBILITY: + return SearchKeywordTable(aIndex, kVisibilityKTable); + + case PROP_WHITE_SPACE: + return SearchKeywordTable(aIndex, kWhitespaceKTable); + + case PROP_WIDTH: + case PROP_LETTER_SPACING: + case PROP_WORD_SPACING: + case PROP_Z_INDEX: + break; + } + return nsnull; +} diff --git a/mozilla/layout/html/style/src/nsCSSProps.h b/mozilla/layout/html/style/src/nsCSSProps.h index 29bd8de6945..9fddff3b07c 100644 --- a/mozilla/layout/html/style/src/nsCSSProps.h +++ b/mozilla/layout/html/style/src/nsCSSProps.h @@ -28,6 +28,12 @@ public: // known. The lookup function uses a perfect hash. static PRInt32 LookupName(const char* str); + + // Given a CSS Property ID and an Property Value Index + // Return back a const char* representation of the + // value. Return back nsnull if no value is found + static const char* LookupProperty(PRInt32 aProp, PRInt32 aIndex); + struct NameTableEntry { const char* name; PRInt32 id; diff --git a/mozilla/layout/style/nsCSSDeclaration.cpp b/mozilla/layout/style/nsCSSDeclaration.cpp index 05691119e8c..38f4f48d504 100644 --- a/mozilla/layout/style/nsCSSDeclaration.cpp +++ b/mozilla/layout/style/nsCSSDeclaration.cpp @@ -27,6 +27,160 @@ //#define DEBUG_REFS + +struct CSSColorEntry{ + PRUint8 r; + PRUint8 g; + PRUint8 b; + char *name; +}; + +static CSSColorEntry css_rgb_table[] = +{ + { 0, 0, 0, "black" }, + { 0, 0, 128, "navy" }, + { 0, 0, 139, "darkblue" }, + { 0, 0, 205, "mediumblue" }, + { 0, 0, 255, "blue" }, + { 0, 100, 0, "darkgreen" }, + { 0, 128, 0, "green" }, + { 0, 128, 128, "teal" }, + { 0, 139, 139, "darkcyan" }, + { 0, 191, 255, "deepskyblue" }, + { 0, 206, 209, "darkturquoise" }, + { 0, 250, 154, "mediumspringgreen" }, + { 0, 255, 0, "lime" }, + { 0, 255, 127, "springgreen" }, + { 0, 255, 255, "aqua" }, + { 0, 255, 255, "cyan" }, + { 25, 25, 112, "midnightblue" }, + { 30, 144, 255, "dodgerblue" }, + { 32, 178, 170, "lightseagreen" }, + { 34, 139, 34, "forestgreen" }, + { 46, 139, 87, "seagreen" }, + { 47, 79, 79, "darkslategray" }, + { 50, 205, 50, "limegreen" }, + { 60, 179, 113, "mediumseagreen" }, + { 64, 224, 208, "turquoise" }, + { 65, 105, 225, "royalblue" }, + { 70, 130, 180, "steelblue" }, + { 72, 61, 139, "darkslateblue" }, + { 72, 209, 204, "mediumturquoise" }, + { 75, 0, 130, "indigo" }, + { 85, 107, 47, "darkolivegreen" }, + { 95, 158, 160, "cadetblue" }, + {100, 149, 237, "cornflowerblue" }, + {102, 205, 170, "mediumaquamarine" }, + {105, 105, 105, "dimgray" }, + {106, 90, 205, "slateblue" }, + {107, 142, 35, "olivedrab" }, + {112, 128, 144, "slategray" }, + {119, 136, 153, "lightslategray" }, + {123, 104, 238, "mediumslateblue" }, + {124, 252, 0, "lawngreen" }, + {127, 255, 0, "chartreuse" }, + {127, 255, 212, "aquamarine" }, + {128, 0, 0, "maroon" }, + {128, 0, 128, "purple" }, + {128, 128, 0, "olive" }, + {128, 128, 128, "gray" }, + {135, 206, 235, "skyblue" }, + {135, 206, 250, "lightskyblue" }, + {138, 43, 226, "blueviolet" }, + {139, 0, 0, "darkred" }, + {139, 0, 139, "darkmagenta" }, + {139, 69, 19, "saddlebrown" }, + {143, 188, 143, "darkseagreen" }, + {144, 238, 144, "lightgreen" }, + {147, 112, 219, "mediumpurple" }, + {148, 0, 211, "darkviolet" }, + {152, 251, 152, "palegreen" }, + {153, 50, 204, "darkorchid" }, + {154, 205, 50, "yellowgreen" }, + {160, 82, 45, "sienna" }, + {165, 42, 42, "brown" }, + {169, 169, 169, "darkgray" }, + {173, 216, 230, "lightblue" }, + {173, 255, 47, "greenyellow" }, + {175, 238, 238, "paleturquoise" }, + {176, 196, 222, "lightsteelblue" }, + {176, 224, 230, "powderblue" }, + {178, 34, 34, "firebrick" }, + {184, 134, 11, "darkgoldenrod" }, + {186, 85, 211, "mediumorchid" }, + {188, 143, 143, "rosybrown" }, + {189, 183, 107, "darkkhaki" }, + {192, 192, 192, "silver" }, + {199, 21, 133, "mediumvioletred" }, + {205, 92, 92, "indianred" }, + {205, 133, 63, "peru" }, + {210, 105, 30, "chocolate" }, + {210, 180, 140, "tan" }, + {211, 211, 211, "lightgrey" }, + {216, 191, 216, "thistle" }, + {218, 112, 214, "orchid" }, + {218, 165, 32, "goldenrod" }, + {219, 112, 147, "palevioletred" }, + {220, 20, 60, "crimson" }, + {220, 220, 220, "gainsboro" }, + {221, 160, 221, "plum" }, + {222, 184, 135, "burlywood" }, + {224, 255, 255, "lightcyan" }, + {230, 230, 250, "lavender" }, + {233, 150, 122, "darksalmon" }, + {238, 130, 238, "violet" }, + {238, 232, 170, "palegoldenrod" }, + {240, 128, 128, "lightcoral" }, + {240, 230, 140, "khaki" }, + {240, 248, 255, "aliceblue" }, + {240, 255, 240, "honeydew" }, + {240, 255, 255, "azure" }, + {244, 164, 96, "sandybrown" }, + {245, 222, 179, "wheat" }, + {245, 245, 220, "beige" }, + {245, 245, 245, "whitesmoke" }, + {245, 255, 250, "mintcream" }, + {248, 248, 255, "ghostwhite" }, + {250, 128, 114, "salmon" }, + {250, 235, 215, "antiquewhite" }, + {250, 240, 230, "linen" }, + {250, 250, 210, "lightgoldenrodyellow" }, + {253, 245, 230, "oldlace" }, + {255, 0, 0, "red" }, + {255, 0, 255, "fuchsia" }, + {255, 0, 255, "magenta" }, + {255, 20, 147, "deeppink" }, + {255, 69, 0, "orangered" }, + {255, 99, 71, "tomato" }, + {255, 105, 180, "hotpink" }, + {255, 127, 80, "coral" }, + {255, 140, 0, "darkorange" }, + {255, 160, 122, "lightsalmon" }, + {255, 165, 0, "orange" }, + {255, 182, 193, "lightpink" }, + {255, 192, 203, "pink" }, + {255, 215, 0, "gold" }, + {255, 218, 185, "peachpuff" }, + {255, 222, 173, "navajowhite" }, + {255, 228, 181, "moccasin" }, + {255, 228, 196, "bisque" }, + {255, 228, 225, "mistyrose" }, + {255, 235, 205, "blanchedalmond" }, + {255, 239, 213, "papayawhip" }, + {255, 240, 245, "lavenderblush" }, + {255, 245, 238, "seashell" }, + {255, 248, 220, "cornsilk" }, + {255, 250, 205, "lemonchiffon" }, + {255, 250, 240, "floralwhite" }, + {255, 250, 250, "snow" }, + {255, 255, 0, "yellow" }, + {255, 255, 224, "lightyellow" }, + {255, 255, 240, "ivory" }, + {255, 255, 255, "white" }, +}; + + + static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID); static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID); static NS_DEFINE_IID(kCSSDisplaySID, NS_CSS_DISPLAY_SID); @@ -2062,6 +2216,35 @@ NS_HTML nsresult +const char* RGBToCSSString(PRInt32 r, PRInt32 g, PRInt32 b) +{ + const char* result = nsnull; + + PRInt32 index = 0; + PRInt32 count = sizeof(css_rgb_table)/sizeof(CSSColorEntry); + CSSColorEntry* entry = nsnull; + + for (index = 0; index < count; index++) + { + entry = &css_rgb_table[index]; + if (entry->r == r) + { + if (entry->g == g && entry->b == b) + { + result = entry->name; + break; + } + } + else if (entry->r > r) + { + break; + } + } + return result; +} + + + void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const { if (eCSSUnit_Null == mUnit) { @@ -2070,51 +2253,46 @@ void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const if (eCSSUnit_String == mUnit) { if (nsnull != mValue.mString) { - aBuffer.Append('"'); aBuffer.Append(*(mValue.mString)); - aBuffer.Append('"'); } else { aBuffer.Append("null str"); } } else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) { - - if (aPropID == PROP_FONT_SIZE && mUnit == eCSSUnit_Enumerated) + if (mUnit == eCSSUnit_Enumerated) { - PRBool found = PR_TRUE; - switch (mValue.mInt) + const char* name = nsCSSProps::LookupProperty(aPropID,mValue.mInt); + if (name != nsnull) { - case NS_STYLE_FONT_SIZE_XXSMALL: aBuffer.Append("xx-small"); break; - case NS_STYLE_FONT_SIZE_XSMALL: aBuffer.Append("x-small"); break; - case NS_STYLE_FONT_SIZE_SMALL: aBuffer.Append("small"); break; - case NS_STYLE_FONT_SIZE_MEDIUM: aBuffer.Append("medium"); break; - case NS_STYLE_FONT_SIZE_LARGE: aBuffer.Append("large"); break; - case NS_STYLE_FONT_SIZE_XLARGE: aBuffer.Append("x-large"); break; - case NS_STYLE_FONT_SIZE_XXLARGE: aBuffer.Append("xx-large"); break; - case NS_STYLE_FONT_SIZE_LARGER: aBuffer.Append("larger"); break; - case NS_STYLE_FONT_SIZE_SMALLER: aBuffer.Append("smaller"); break; - - default: - found = PR_FALSE; - } - if (found) + aBuffer.Append(name); return; - - } + } + } aBuffer.Append(mValue.mInt, 10); aBuffer.Append("[0x"); aBuffer.Append(mValue.mInt, 16); aBuffer.Append(']'); } else if (eCSSUnit_Color == mUnit){ - aBuffer.Append("rgb("); - aBuffer.Append(NS_GET_R(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_G(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_B(mValue.mColor), 10); - aBuffer.Append(')'); + PRInt32 r = NS_GET_R(mValue.mColor); + PRInt32 g = NS_GET_G(mValue.mColor); + PRInt32 b = NS_GET_B(mValue.mColor); + + const char* name = RGBToCSSString(r,g,b); + + if (name != nsnull) + aBuffer.Append(name); + else + { + aBuffer.Append("rgb("); + aBuffer.Append(NS_GET_R(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_G(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_B(mValue.mColor), 10); + aBuffer.Append(')'); + } return; } else if (eCSSUnit_Percent == mUnit) { diff --git a/mozilla/layout/style/nsCSSParser.cpp b/mozilla/layout/style/nsCSSParser.cpp index 47b53598d20..4894d23207a 100644 --- a/mozilla/layout/style/nsCSSParser.cpp +++ b/mozilla/layout/style/nsCSSParser.cpp @@ -30,6 +30,7 @@ #include "nsIAtom.h" #include "nsVoidArray.h" #include "nsColor.h" +#include "nsStyleConsts.h" // XXX TODO: // - rework aErrorCode stuff: switch over to nsresult diff --git a/mozilla/layout/style/nsCSSProps.cpp b/mozilla/layout/style/nsCSSProps.cpp index b5431d82aa0..44479e77776 100644 --- a/mozilla/layout/style/nsCSSProps.cpp +++ b/mozilla/layout/style/nsCSSProps.cpp @@ -6,6 +6,10 @@ #include "plstr.h" #include "nsCSSProps.h" +#include "nsCSSKeywordIDs.h" +#include "nsStyleConsts.h" +#include "nsCSSKeywords.h" + #define TOTAL_KEYWORDS 80 #define MIN_WORD_LENGTH 3 #define MAX_WORD_LENGTH 21 @@ -363,3 +367,414 @@ const nsCSSProps::NameTableEntry nsCSSProps::kNameTable[] = { { "word-spacing", 78 }, { "z-index", 79 }, }; + + + + +// Keyword id tables for variant/enum parsing +static PRInt32 kBackgroundAttachmentKTable[] = { + KEYWORD_FIXED, NS_STYLE_BG_ATTACHMENT_FIXED, + KEYWORD_SCROLL, NS_STYLE_BG_ATTACHMENT_SCROLL, + -1,-1 +}; + +static PRInt32 kBackgroundColorKTable[] = { + KEYWORD_TRANSPARENT, NS_STYLE_BG_COLOR_TRANSPARENT, + -1,-1 +}; + +static PRInt32 kBackgroundRepeatKTable[] = { + KEYWORD_NO_REPEAT, NS_STYLE_BG_REPEAT_OFF, + KEYWORD_REPEAT, NS_STYLE_BG_REPEAT_XY, + KEYWORD_REPEAT_X, NS_STYLE_BG_REPEAT_X, + KEYWORD_REPEAT_Y, NS_STYLE_BG_REPEAT_Y, + -1,-1 +}; + +static PRInt32 kBorderStyleKTable[] = { + KEYWORD_NONE, NS_STYLE_BORDER_STYLE_NONE, + KEYWORD_DOTTED, NS_STYLE_BORDER_STYLE_DOTTED, + KEYWORD_DASHED, NS_STYLE_BORDER_STYLE_DASHED, + KEYWORD_SOLID, NS_STYLE_BORDER_STYLE_SOLID, + KEYWORD_DOUBLE, NS_STYLE_BORDER_STYLE_DOUBLE, + KEYWORD_GROOVE, NS_STYLE_BORDER_STYLE_GROOVE, + KEYWORD_RIDGE, NS_STYLE_BORDER_STYLE_RIDGE, + KEYWORD_INSET, NS_STYLE_BORDER_STYLE_INSET, + KEYWORD_OUTSET, NS_STYLE_BORDER_STYLE_OUTSET, + -1,-1 +}; + +static PRInt32 kBorderWidthKTable[] = { + KEYWORD_THIN, NS_STYLE_BORDER_WIDTH_THIN, + KEYWORD_MEDIUM, NS_STYLE_BORDER_WIDTH_MEDIUM, + KEYWORD_THICK, NS_STYLE_BORDER_WIDTH_THICK, + -1,-1 +}; + +static PRInt32 kClearKTable[] = { + KEYWORD_NONE, NS_STYLE_CLEAR_NONE, + KEYWORD_LEFT, NS_STYLE_CLEAR_LEFT, + KEYWORD_RIGHT, NS_STYLE_CLEAR_RIGHT, + KEYWORD_BOTH, NS_STYLE_CLEAR_LEFT_AND_RIGHT, + -1,-1 +}; + +static PRInt32 kCursorKTable[] = { + KEYWORD_IBEAM, NS_STYLE_CURSOR_IBEAM, + KEYWORD_ARROW, NS_STYLE_CURSOR_DEFAULT, + KEYWORD_HAND, NS_STYLE_CURSOR_HAND, + -1,-1 +}; + +static PRInt32 kDirectionKTable[] = { + KEYWORD_LTR, NS_STYLE_DIRECTION_LTR, + KEYWORD_RTL, NS_STYLE_DIRECTION_RTL, + KEYWORD_INHERIT, NS_STYLE_DIRECTION_INHERIT, + -1,-1 +}; + +static PRInt32 kDisplayKTable[] = { + KEYWORD_NONE, NS_STYLE_DISPLAY_NONE, + KEYWORD_BLOCK, NS_STYLE_DISPLAY_BLOCK, + KEYWORD_INLINE, NS_STYLE_DISPLAY_INLINE, + KEYWORD_LIST_ITEM, NS_STYLE_DISPLAY_LIST_ITEM, + KEYWORD_MARKER, NS_STYLE_DISPLAY_MARKER, + KEYWORD_RUN_IN, NS_STYLE_DISPLAY_RUN_IN, + KEYWORD_COMPACT, NS_STYLE_DISPLAY_COMPACT, + KEYWORD_TABLE, NS_STYLE_DISPLAY_TABLE, + KEYWORD_INLINE_TABLE, NS_STYLE_DISPLAY_INLINE_TABLE, + KEYWORD_TABLE_ROW_GROUP, NS_STYLE_DISPLAY_TABLE_ROW_GROUP, + KEYWORD_TABLE_COLUMN, NS_STYLE_DISPLAY_TABLE_COLUMN, + KEYWORD_TABLE_COLUMN_GROUP, NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP, + KEYWORD_TABLE_HEADER_GROUP, NS_STYLE_DISPLAY_TABLE_HEADER_GROUP, + KEYWORD_TABLE_FOOTER_GROUP, NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP, + KEYWORD_TABLE_ROW, NS_STYLE_DISPLAY_TABLE_ROW, + KEYWORD_TABLE_CELL, NS_STYLE_DISPLAY_TABLE_CELL, + KEYWORD_TABLE_CAPTION, NS_STYLE_DISPLAY_TABLE_CAPTION, + -1,-1 +}; + +static PRInt32 kFloatKTable[] = { + KEYWORD_NONE, NS_STYLE_FLOAT_NONE, + KEYWORD_LEFT, NS_STYLE_FLOAT_LEFT, + KEYWORD_RIGHT, NS_STYLE_FLOAT_RIGHT, + -1,-1 +}; + +static PRInt32 kFontSizeKTable[] = { + KEYWORD_XX_SMALL, NS_STYLE_FONT_SIZE_XXSMALL, + KEYWORD_X_SMALL, NS_STYLE_FONT_SIZE_XSMALL, + KEYWORD_SMALL, NS_STYLE_FONT_SIZE_SMALL, + KEYWORD_MEDIUM, NS_STYLE_FONT_SIZE_MEDIUM, + KEYWORD_LARGE, NS_STYLE_FONT_SIZE_LARGE, + KEYWORD_X_LARGE, NS_STYLE_FONT_SIZE_XLARGE, + KEYWORD_XX_LARGE, NS_STYLE_FONT_SIZE_XXLARGE, + KEYWORD_LARGER, NS_STYLE_FONT_SIZE_LARGER, + KEYWORD_SMALLER, NS_STYLE_FONT_SIZE_SMALLER, + -1,-1 +}; + +static PRInt32 kFontStyleKTable[] = { + KEYWORD_NORMAL, NS_STYLE_FONT_STYLE_NORMAL, + KEYWORD_ITALIC, NS_STYLE_FONT_STYLE_ITALIC, + KEYWORD_OBLIQUE, NS_STYLE_FONT_STYLE_OBLIQUE, + -1,-1 +}; + +static PRInt32 kFontVariantKTable[] = { + KEYWORD_NORMAL, NS_STYLE_FONT_VARIANT_NORMAL, + KEYWORD_SMALL_CAPS, NS_STYLE_FONT_VARIANT_SMALL_CAPS, + -1,-1 +}; + +static PRInt32 kListStyleImageKTable[] = { + KEYWORD_NONE, NS_STYLE_LIST_STYLE_IMAGE_NONE, + -1,-1 +}; + +static PRInt32 kListStylePositionKTable[] = { + KEYWORD_INSIDE, NS_STYLE_LIST_STYLE_POSITION_INSIDE, + KEYWORD_OUTSIDE, NS_STYLE_LIST_STYLE_POSITION_OUTSIDE, + -1,-1 +}; + +static PRInt32 kListStyleKTable[] = { + KEYWORD_NONE, NS_STYLE_LIST_STYLE_NONE, + KEYWORD_DISC, NS_STYLE_LIST_STYLE_DISC, + KEYWORD_CIRCLE, NS_STYLE_LIST_STYLE_CIRCLE, + KEYWORD_SQUARE, NS_STYLE_LIST_STYLE_SQUARE, + KEYWORD_DECIMAL, NS_STYLE_LIST_STYLE_DECIMAL, + KEYWORD_LOWER_ROMAN, NS_STYLE_LIST_STYLE_LOWER_ROMAN, + KEYWORD_UPPER_ROMAN, NS_STYLE_LIST_STYLE_UPPER_ROMAN, + KEYWORD_LOWER_ALPHA, NS_STYLE_LIST_STYLE_LOWER_ALPHA, + KEYWORD_UPPER_ALPHA, NS_STYLE_LIST_STYLE_UPPER_ALPHA, + -1,-1 +}; + +static PRInt32 kMarginSizeKTable[] = { + KEYWORD_AUTO, NS_STYLE_MARGIN_SIZE_AUTO, + -1,-1 +}; + +static PRInt32 kOverflowKTable[] = { + KEYWORD_VISIBLE, NS_STYLE_OVERFLOW_VISIBLE, + KEYWORD_HIDDEN, NS_STYLE_OVERFLOW_HIDDEN, + KEYWORD_SCROLL, NS_STYLE_OVERFLOW_SCROLL, + KEYWORD_AUTO, NS_STYLE_OVERFLOW_AUTO, + -1,-1 +}; + +static PRInt32 kPositionKTable[] = { + KEYWORD_RELATIVE, NS_STYLE_POSITION_RELATIVE, + KEYWORD_ABSOLUTE, NS_STYLE_POSITION_ABSOLUTE, + KEYWORD_FIXED, NS_STYLE_POSITION_FIXED, + -1,-1 +}; + +static PRInt32 kTextAlignKTable[] = { + KEYWORD_LEFT, NS_STYLE_TEXT_ALIGN_LEFT, + KEYWORD_RIGHT, NS_STYLE_TEXT_ALIGN_RIGHT, + KEYWORD_CENTER, NS_STYLE_TEXT_ALIGN_CENTER, + KEYWORD_JUSTIFY, NS_STYLE_TEXT_ALIGN_JUSTIFY, + -1,-1 +}; + +static PRInt32 kTextTransformKTable[] = { + KEYWORD_NONE, NS_STYLE_TEXT_TRANSFORM_NONE, + KEYWORD_CAPITALIZE, NS_STYLE_TEXT_TRANSFORM_CAPITALIZE, + KEYWORD_LOWERCASE, NS_STYLE_TEXT_TRANSFORM_LOWERCASE, + KEYWORD_UPPERCASE, NS_STYLE_TEXT_TRANSFORM_UPPERCASE, + -1,-1 +}; + +static PRInt32 kVerticalAlignKTable[] = { + KEYWORD_BASELINE, NS_STYLE_VERTICAL_ALIGN_BASELINE, + KEYWORD_SUB, NS_STYLE_VERTICAL_ALIGN_SUB, + KEYWORD_SUPER, NS_STYLE_VERTICAL_ALIGN_SUPER, + KEYWORD_TOP, NS_STYLE_VERTICAL_ALIGN_TOP, + KEYWORD_TEXT_TOP, NS_STYLE_VERTICAL_ALIGN_TEXT_TOP, + KEYWORD_MIDDLE, NS_STYLE_VERTICAL_ALIGN_MIDDLE, + KEYWORD_BOTTOM, NS_STYLE_VERTICAL_ALIGN_BOTTOM, + KEYWORD_TEXT_BOTTOM, NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM, + -1,-1 +}; + +static PRInt32 kVisibilityKTable[] = { + KEYWORD_VISIBLE, NS_STYLE_VISIBILITY_VISIBLE, + KEYWORD_HIDDEN, NS_STYLE_VISIBILITY_HIDDEN, + -1,-1 +}; + +static PRInt32 kWhitespaceKTable[] = { + KEYWORD_NORMAL, NS_STYLE_WHITESPACE_NORMAL, + KEYWORD_PRE, NS_STYLE_WHITESPACE_PRE, + KEYWORD_NOWRAP, NS_STYLE_WHITESPACE_NOWRAP, + -1,-1 +}; + +static const char* kBorderTopNames[] = { + "border-top-width", + "border-top-style", + "border-top-color", +}; +static const char* kBorderRightNames[] = { + "border-right-width", + "border-right-style", + "border-right-color", +}; +static const char* kBorderBottomNames[] = { + "border-bottom-width", + "border-bottom-style", + "border-bottom-color", +}; +static const char* kBorderLeftNames[] = { + "border-left-width", + "border-left-style", + "border-left-color", +}; + +static const char* SearchKeywordTable(PRInt32 aID, PRInt32 aTable[]) +{ + PRInt32 i = 1; + if (aID >= 0) + { + for (;;) { + if (aTable[i] < 0) { + break; + } + if (aID == aTable[i]) { + return nsCSSKeywords::kNameTable[aTable[i-1]].name; + } + i += 2; + } + } + return nsnull; +} + + + +const char* nsCSSProps::LookupProperty(PRInt32 aProp, PRInt32 aIndex) +{ + switch (aProp) { + + case PROP_BACKGROUND: + break; + + case PROP_BACKGROUND_ATTACHMENT: + return SearchKeywordTable(aIndex,kBackgroundAttachmentKTable); + + case PROP_BACKGROUND_COLOR: + return SearchKeywordTable(aIndex,kBackgroundColorKTable); + + case PROP_BACKGROUND_FILTER: + break; + + case PROP_BACKGROUND_IMAGE: + break; + + case PROP_BACKGROUND_POSITION: + break; + + case PROP_BACKGROUND_REPEAT: + return SearchKeywordTable(aIndex,kBackgroundRepeatKTable); + + case PROP_BORDER: + case PROP_BORDER_COLOR: + case PROP_BORDER_STYLE: + case PROP_BORDER_BOTTOM: + case PROP_BORDER_LEFT: + case PROP_BORDER_RIGHT: + case PROP_BORDER_TOP: + case PROP_BORDER_BOTTOM_COLOR: + case PROP_BORDER_LEFT_COLOR: + case PROP_BORDER_RIGHT_COLOR: + case PROP_BORDER_TOP_COLOR: + break; + + case PROP_BORDER_BOTTOM_STYLE: + case PROP_BORDER_LEFT_STYLE: + case PROP_BORDER_RIGHT_STYLE: + case PROP_BORDER_TOP_STYLE: + return SearchKeywordTable(aIndex,kBorderStyleKTable); + break; + + case PROP_BORDER_BOTTOM_WIDTH: + case PROP_BORDER_LEFT_WIDTH: + case PROP_BORDER_RIGHT_WIDTH: + case PROP_BORDER_TOP_WIDTH: + return SearchKeywordTable(aIndex,kBorderWidthKTable); + break; + + case PROP_BORDER_WIDTH: + case PROP_CLEAR: + return SearchKeywordTable(aIndex,kClearKTable); + break; + + case PROP_CLIP: + case PROP_COLOR: + break; + + case PROP_CURSOR: + return SearchKeywordTable(aIndex,kCursorKTable); + break; + + case PROP_DIRECTION: + return SearchKeywordTable(aIndex,kDirectionKTable); + + case PROP_DISPLAY: + return SearchKeywordTable(aIndex,kDisplayKTable); + + case PROP_FILTER: + break; + + case PROP_FLOAT: + return SearchKeywordTable(aIndex,kFloatKTable); + + case PROP_FONT: + case PROP_FONT_FAMILY: + break; + + case PROP_FONT_SIZE: + return SearchKeywordTable(aIndex,kFontSizeKTable); + break; + + case PROP_FONT_STYLE: + return SearchKeywordTable(aIndex,kFontStyleKTable); + + case PROP_FONT_VARIANT: + return SearchKeywordTable(aIndex,kFontVariantKTable); + + + case PROP_FONT_WEIGHT: + case PROP_HEIGHT: + case PROP_LEFT: + case PROP_LINE_HEIGHT: + case PROP_LIST_STYLE: + break; + + case PROP_LIST_STYLE_IMAGE: + return SearchKeywordTable(aIndex, kListStyleImageKTable); + + case PROP_LIST_STYLE_POSITION: + return SearchKeywordTable(aIndex, kListStylePositionKTable); + + + case PROP_LIST_STYLE_TYPE: + return SearchKeywordTable(aIndex, kListStyleKTable); + + case PROP_MARGIN: + case PROP_MARGIN_BOTTOM: + case PROP_MARGIN_LEFT: + case PROP_MARGIN_RIGHT: + case PROP_MARGIN_TOP: + return SearchKeywordTable(aIndex, kMarginSizeKTable); + break; + + case PROP_PADDING: + case PROP_PADDING_BOTTOM: + case PROP_PADDING_LEFT: + case PROP_PADDING_RIGHT: + case PROP_PADDING_TOP: + break; + + case PROP_OPACITY: + break; + + case PROP_OVERFLOW: + return SearchKeywordTable(aIndex, kOverflowKTable); + + case PROP_POSITION: + return SearchKeywordTable(aIndex, kPositionKTable); + break; + + case PROP_TEXT_ALIGN: + return SearchKeywordTable(aIndex, kTextAlignKTable); + + case PROP_TEXT_DECORATION: + case PROP_TEXT_INDENT: + break; + + case PROP_TEXT_TRANSFORM: + return SearchKeywordTable(aIndex, kTextTransformKTable); + + case PROP_TOP: + break; + + case PROP_VERTICAL_ALIGN: + return SearchKeywordTable(aIndex, kVerticalAlignKTable); + break; + + case PROP_VISIBILITY: + return SearchKeywordTable(aIndex, kVisibilityKTable); + + case PROP_WHITE_SPACE: + return SearchKeywordTable(aIndex, kWhitespaceKTable); + + case PROP_WIDTH: + case PROP_LETTER_SPACING: + case PROP_WORD_SPACING: + case PROP_Z_INDEX: + break; + } + return nsnull; +} diff --git a/mozilla/layout/style/nsCSSProps.h b/mozilla/layout/style/nsCSSProps.h index 29bd8de6945..9fddff3b07c 100644 --- a/mozilla/layout/style/nsCSSProps.h +++ b/mozilla/layout/style/nsCSSProps.h @@ -28,6 +28,12 @@ public: // known. The lookup function uses a perfect hash. static PRInt32 LookupName(const char* str); + + // Given a CSS Property ID and an Property Value Index + // Return back a const char* representation of the + // value. Return back nsnull if no value is found + static const char* LookupProperty(PRInt32 aProp, PRInt32 aIndex); + struct NameTableEntry { const char* name; PRInt32 id; diff --git a/mozilla/layout/style/nsCSSStruct.cpp b/mozilla/layout/style/nsCSSStruct.cpp index 05691119e8c..38f4f48d504 100644 --- a/mozilla/layout/style/nsCSSStruct.cpp +++ b/mozilla/layout/style/nsCSSStruct.cpp @@ -27,6 +27,160 @@ //#define DEBUG_REFS + +struct CSSColorEntry{ + PRUint8 r; + PRUint8 g; + PRUint8 b; + char *name; +}; + +static CSSColorEntry css_rgb_table[] = +{ + { 0, 0, 0, "black" }, + { 0, 0, 128, "navy" }, + { 0, 0, 139, "darkblue" }, + { 0, 0, 205, "mediumblue" }, + { 0, 0, 255, "blue" }, + { 0, 100, 0, "darkgreen" }, + { 0, 128, 0, "green" }, + { 0, 128, 128, "teal" }, + { 0, 139, 139, "darkcyan" }, + { 0, 191, 255, "deepskyblue" }, + { 0, 206, 209, "darkturquoise" }, + { 0, 250, 154, "mediumspringgreen" }, + { 0, 255, 0, "lime" }, + { 0, 255, 127, "springgreen" }, + { 0, 255, 255, "aqua" }, + { 0, 255, 255, "cyan" }, + { 25, 25, 112, "midnightblue" }, + { 30, 144, 255, "dodgerblue" }, + { 32, 178, 170, "lightseagreen" }, + { 34, 139, 34, "forestgreen" }, + { 46, 139, 87, "seagreen" }, + { 47, 79, 79, "darkslategray" }, + { 50, 205, 50, "limegreen" }, + { 60, 179, 113, "mediumseagreen" }, + { 64, 224, 208, "turquoise" }, + { 65, 105, 225, "royalblue" }, + { 70, 130, 180, "steelblue" }, + { 72, 61, 139, "darkslateblue" }, + { 72, 209, 204, "mediumturquoise" }, + { 75, 0, 130, "indigo" }, + { 85, 107, 47, "darkolivegreen" }, + { 95, 158, 160, "cadetblue" }, + {100, 149, 237, "cornflowerblue" }, + {102, 205, 170, "mediumaquamarine" }, + {105, 105, 105, "dimgray" }, + {106, 90, 205, "slateblue" }, + {107, 142, 35, "olivedrab" }, + {112, 128, 144, "slategray" }, + {119, 136, 153, "lightslategray" }, + {123, 104, 238, "mediumslateblue" }, + {124, 252, 0, "lawngreen" }, + {127, 255, 0, "chartreuse" }, + {127, 255, 212, "aquamarine" }, + {128, 0, 0, "maroon" }, + {128, 0, 128, "purple" }, + {128, 128, 0, "olive" }, + {128, 128, 128, "gray" }, + {135, 206, 235, "skyblue" }, + {135, 206, 250, "lightskyblue" }, + {138, 43, 226, "blueviolet" }, + {139, 0, 0, "darkred" }, + {139, 0, 139, "darkmagenta" }, + {139, 69, 19, "saddlebrown" }, + {143, 188, 143, "darkseagreen" }, + {144, 238, 144, "lightgreen" }, + {147, 112, 219, "mediumpurple" }, + {148, 0, 211, "darkviolet" }, + {152, 251, 152, "palegreen" }, + {153, 50, 204, "darkorchid" }, + {154, 205, 50, "yellowgreen" }, + {160, 82, 45, "sienna" }, + {165, 42, 42, "brown" }, + {169, 169, 169, "darkgray" }, + {173, 216, 230, "lightblue" }, + {173, 255, 47, "greenyellow" }, + {175, 238, 238, "paleturquoise" }, + {176, 196, 222, "lightsteelblue" }, + {176, 224, 230, "powderblue" }, + {178, 34, 34, "firebrick" }, + {184, 134, 11, "darkgoldenrod" }, + {186, 85, 211, "mediumorchid" }, + {188, 143, 143, "rosybrown" }, + {189, 183, 107, "darkkhaki" }, + {192, 192, 192, "silver" }, + {199, 21, 133, "mediumvioletred" }, + {205, 92, 92, "indianred" }, + {205, 133, 63, "peru" }, + {210, 105, 30, "chocolate" }, + {210, 180, 140, "tan" }, + {211, 211, 211, "lightgrey" }, + {216, 191, 216, "thistle" }, + {218, 112, 214, "orchid" }, + {218, 165, 32, "goldenrod" }, + {219, 112, 147, "palevioletred" }, + {220, 20, 60, "crimson" }, + {220, 220, 220, "gainsboro" }, + {221, 160, 221, "plum" }, + {222, 184, 135, "burlywood" }, + {224, 255, 255, "lightcyan" }, + {230, 230, 250, "lavender" }, + {233, 150, 122, "darksalmon" }, + {238, 130, 238, "violet" }, + {238, 232, 170, "palegoldenrod" }, + {240, 128, 128, "lightcoral" }, + {240, 230, 140, "khaki" }, + {240, 248, 255, "aliceblue" }, + {240, 255, 240, "honeydew" }, + {240, 255, 255, "azure" }, + {244, 164, 96, "sandybrown" }, + {245, 222, 179, "wheat" }, + {245, 245, 220, "beige" }, + {245, 245, 245, "whitesmoke" }, + {245, 255, 250, "mintcream" }, + {248, 248, 255, "ghostwhite" }, + {250, 128, 114, "salmon" }, + {250, 235, 215, "antiquewhite" }, + {250, 240, 230, "linen" }, + {250, 250, 210, "lightgoldenrodyellow" }, + {253, 245, 230, "oldlace" }, + {255, 0, 0, "red" }, + {255, 0, 255, "fuchsia" }, + {255, 0, 255, "magenta" }, + {255, 20, 147, "deeppink" }, + {255, 69, 0, "orangered" }, + {255, 99, 71, "tomato" }, + {255, 105, 180, "hotpink" }, + {255, 127, 80, "coral" }, + {255, 140, 0, "darkorange" }, + {255, 160, 122, "lightsalmon" }, + {255, 165, 0, "orange" }, + {255, 182, 193, "lightpink" }, + {255, 192, 203, "pink" }, + {255, 215, 0, "gold" }, + {255, 218, 185, "peachpuff" }, + {255, 222, 173, "navajowhite" }, + {255, 228, 181, "moccasin" }, + {255, 228, 196, "bisque" }, + {255, 228, 225, "mistyrose" }, + {255, 235, 205, "blanchedalmond" }, + {255, 239, 213, "papayawhip" }, + {255, 240, 245, "lavenderblush" }, + {255, 245, 238, "seashell" }, + {255, 248, 220, "cornsilk" }, + {255, 250, 205, "lemonchiffon" }, + {255, 250, 240, "floralwhite" }, + {255, 250, 250, "snow" }, + {255, 255, 0, "yellow" }, + {255, 255, 224, "lightyellow" }, + {255, 255, 240, "ivory" }, + {255, 255, 255, "white" }, +}; + + + static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID); static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID); static NS_DEFINE_IID(kCSSDisplaySID, NS_CSS_DISPLAY_SID); @@ -2062,6 +2216,35 @@ NS_HTML nsresult +const char* RGBToCSSString(PRInt32 r, PRInt32 g, PRInt32 b) +{ + const char* result = nsnull; + + PRInt32 index = 0; + PRInt32 count = sizeof(css_rgb_table)/sizeof(CSSColorEntry); + CSSColorEntry* entry = nsnull; + + for (index = 0; index < count; index++) + { + entry = &css_rgb_table[index]; + if (entry->r == r) + { + if (entry->g == g && entry->b == b) + { + result = entry->name; + break; + } + } + else if (entry->r > r) + { + break; + } + } + return result; +} + + + void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const { if (eCSSUnit_Null == mUnit) { @@ -2070,51 +2253,46 @@ void nsCSSValue::AppendToCSSString(nsString& aBuffer, PRInt32 aPropID) const if (eCSSUnit_String == mUnit) { if (nsnull != mValue.mString) { - aBuffer.Append('"'); aBuffer.Append(*(mValue.mString)); - aBuffer.Append('"'); } else { aBuffer.Append("null str"); } } else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) { - - if (aPropID == PROP_FONT_SIZE && mUnit == eCSSUnit_Enumerated) + if (mUnit == eCSSUnit_Enumerated) { - PRBool found = PR_TRUE; - switch (mValue.mInt) + const char* name = nsCSSProps::LookupProperty(aPropID,mValue.mInt); + if (name != nsnull) { - case NS_STYLE_FONT_SIZE_XXSMALL: aBuffer.Append("xx-small"); break; - case NS_STYLE_FONT_SIZE_XSMALL: aBuffer.Append("x-small"); break; - case NS_STYLE_FONT_SIZE_SMALL: aBuffer.Append("small"); break; - case NS_STYLE_FONT_SIZE_MEDIUM: aBuffer.Append("medium"); break; - case NS_STYLE_FONT_SIZE_LARGE: aBuffer.Append("large"); break; - case NS_STYLE_FONT_SIZE_XLARGE: aBuffer.Append("x-large"); break; - case NS_STYLE_FONT_SIZE_XXLARGE: aBuffer.Append("xx-large"); break; - case NS_STYLE_FONT_SIZE_LARGER: aBuffer.Append("larger"); break; - case NS_STYLE_FONT_SIZE_SMALLER: aBuffer.Append("smaller"); break; - - default: - found = PR_FALSE; - } - if (found) + aBuffer.Append(name); return; - - } + } + } aBuffer.Append(mValue.mInt, 10); aBuffer.Append("[0x"); aBuffer.Append(mValue.mInt, 16); aBuffer.Append(']'); } else if (eCSSUnit_Color == mUnit){ - aBuffer.Append("rgb("); - aBuffer.Append(NS_GET_R(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_G(mValue.mColor), 10); - aBuffer.Append(","); - aBuffer.Append(NS_GET_B(mValue.mColor), 10); - aBuffer.Append(')'); + PRInt32 r = NS_GET_R(mValue.mColor); + PRInt32 g = NS_GET_G(mValue.mColor); + PRInt32 b = NS_GET_B(mValue.mColor); + + const char* name = RGBToCSSString(r,g,b); + + if (name != nsnull) + aBuffer.Append(name); + else + { + aBuffer.Append("rgb("); + aBuffer.Append(NS_GET_R(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_G(mValue.mColor), 10); + aBuffer.Append(","); + aBuffer.Append(NS_GET_B(mValue.mColor), 10); + aBuffer.Append(')'); + } return; } else if (eCSSUnit_Percent == mUnit) {