From 80b36e289167433e9c896a21bbb76ff41fa8a6d0 Mon Sep 17 00:00:00 2001 From: "heikki%netscape.com" Date: Mon, 19 Feb 2001 12:55:42 +0000 Subject: [PATCH] Checking in changes needed for splitting layout into two separate libraries. r=jst@netscape.com, sr=waterson@netscape.com. Not part of the default build yet. git-svn-id: svn://10.0.0.236/trunk@87357 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/Makefile.in | 4 - .../content/base/public/nsIAnonymousContent.h | 4 + mozilla/content/base/public/nsTextFragment.h | 87 ++- mozilla/content/base/src/nsCommentNode.cpp | 15 - .../content/base/src/nsContentIterator.cpp | 1 + mozilla/content/base/src/nsDocument.cpp | 14 +- mozilla/content/base/src/nsDocumentViewer.cpp | 22 +- .../content/base/src/nsGeneratedIterator.cpp | 2 +- mozilla/content/base/src/nsGenericElement.cpp | 20 +- mozilla/content/base/src/nsHTMLValue.cpp | 46 -- mozilla/content/base/src/nsHTMLValue.h | 46 +- .../base/src/nsPlainTextSerializer.cpp | 4 +- mozilla/content/base/src/nsSelection.cpp | 2 +- mozilla/content/base/src/nsStyleContext.cpp | 537 ++---------------- mozilla/content/base/src/nsTextFragment.cpp | 95 ---- mozilla/content/base/src/nsTextFragment.h | 87 ++- mozilla/content/events/src/Makefile.in | 2 +- mozilla/content/events/src/makefile.win | 2 +- .../events/src/nsEventStateManager.cpp | 25 +- mozilla/content/html/content/src/Makefile.in | 8 +- mozilla/content/html/content/src/makefile.win | 8 +- .../html/content/src/nsGenericHTMLElement.cpp | 26 +- .../html/content/src/nsHTMLAppletElement.cpp | 8 +- .../html/content/src/nsHTMLFormElement.cpp | 6 +- .../html/content/src/nsHTMLImageElement.cpp | 79 +-- .../html/content/src/nsHTMLSpacerElement.cpp | 2 +- .../html/document/src/nsHTMLContentSink.cpp | 8 +- .../html/document/src/nsHTMLDocument.cpp | 28 +- .../src/nsHTMLFragmentContentSink.cpp | 10 +- .../html/document/src/nsMarkupDocument.cpp | 15 +- mozilla/content/html/style/src/nsCSSValue.cpp | 81 --- mozilla/content/html/style/src/nsCSSValue.h | 89 ++- .../html/style/src/nsHTMLStyleSheet.cpp | 31 +- .../content/html/style/src/nsHTMLValue.cpp | 46 -- mozilla/content/html/style/src/nsHTMLValue.h | 46 +- mozilla/content/makefile.win | 3 - mozilla/content/shared/public/nsHTMLValue.h | 46 +- .../content/shared/public/nsTextFragment.h | 87 ++- mozilla/content/shared/src/nsHTMLValue.cpp | 46 -- mozilla/content/shared/src/nsTextFragment.cpp | 95 ---- mozilla/content/xbl/src/Makefile.in | 2 +- mozilla/content/xbl/src/makefile.win | 2 +- mozilla/content/xbl/src/nsBindingManager.cpp | 2 +- mozilla/content/xbl/src/nsXBLBinding.cpp | 2 +- .../content/xbl/src/nsXBLPrototypeBinding.cpp | 2 +- mozilla/content/xbl/src/nsXBLService.cpp | 2 +- mozilla/content/xml/content/src/Makefile.in | 2 +- mozilla/content/xml/content/src/makefile.win | 2 +- mozilla/content/xml/document/src/Makefile.in | 2 +- mozilla/content/xml/document/src/makefile.win | 2 +- .../xml/document/src/nsXMLContentSink.cpp | 29 +- .../xml/document/src/nsXMLDocument.cpp | 23 +- mozilla/content/xsl/document/src/Makefile.in | 2 +- mozilla/content/xsl/document/src/makefile.win | 2 +- mozilla/layout/base/nsDocumentViewer.cpp | 22 +- mozilla/layout/generic/nsSelection.cpp | 2 +- mozilla/layout/style/nsCSSValue.cpp | 81 --- mozilla/layout/style/nsCSSValue.h | 89 ++- mozilla/layout/style/nsHTMLStyleSheet.cpp | 31 +- mozilla/layout/style/nsStyleContext.cpp | 537 ++---------------- 60 files changed, 863 insertions(+), 1758 deletions(-) diff --git a/mozilla/content/Makefile.in b/mozilla/content/Makefile.in index 80c7a34c32d..c72618833d7 100644 --- a/mozilla/content/Makefile.in +++ b/mozilla/content/Makefile.in @@ -30,9 +30,5 @@ DIRS = base html xml xul xbl xsl DIRS += events build -ifdef ENABLE_TESTS -DIRS += html/tests -endif - include $(topsrcdir)/config/rules.mk diff --git a/mozilla/content/base/public/nsIAnonymousContent.h b/mozilla/content/base/public/nsIAnonymousContent.h index 91e1b93fae4..54dced7dbb2 100644 --- a/mozilla/content/base/public/nsIAnonymousContent.h +++ b/mozilla/content/base/public/nsIAnonymousContent.h @@ -30,6 +30,7 @@ class nsISupportsArray; class nsIAtom; +class nsINodeInfo; #define NS_IANONYMOUS_CONTENT_IID { 0x41a69e00, 0x2d6d, 0x12d3, { 0xb0, 0x33, 0xa1, 0x38, 0x71, 0x39, 0x78, 0x7c } } @@ -40,7 +41,10 @@ class nsIAtom; class nsIAnonymousContent : public nsISupports { public: static const nsIID& GetIID() { static nsIID iid = NS_IANONYMOUS_CONTENT_IID; return iid; } + + NS_IMETHOD Init(nsINodeInfo *aInfo) = 0; }; +nsresult NS_NewAnonymousContent2(nsIContent **aNewNode); #endif diff --git a/mozilla/content/base/public/nsTextFragment.h b/mozilla/content/base/public/nsTextFragment.h index 52ccecd4763..5c3e7bea3a0 100644 --- a/mozilla/content/base/public/nsTextFragment.h +++ b/mozilla/content/base/public/nsTextFragment.h @@ -24,7 +24,9 @@ #include "nslayout.h" #include "nsAWritableString.h" -class nsString; +#include "nsCRT.h" +#include "nsString.h" +#include "nsMemory.h" // XXX should this normalize the code to keep a \u0000 at the end? @@ -65,7 +67,9 @@ public: mAllBits = 0; } - ~nsTextFragment(); + ~nsTextFragment() { + ReleaseText(); + } /** * Initialize the contents of this fragment to be a copy of @@ -83,7 +87,10 @@ public: * Initialize the contents of this fragment to be a copy of * the argument ucs2 string. */ - nsTextFragment(const PRUnichar* aString); + nsTextFragment(const PRUnichar* aString) : m1b(nsnull), mAllBits(0) { + SetTo(aString, nsCRT::strlen(aString)); + } + /** * Initialize the contents of this fragment to be a copy of @@ -177,7 +184,55 @@ public: * buffer. Like operator= except a length is specified instead of * assuming 0 termination. */ - void SetTo(const PRUnichar* aBuffer, PRInt32 aLength); + void SetTo(const PRUnichar* aBuffer, PRInt32 aLength) { + ReleaseText(); + if (0 != aLength) { + // See if we need to store the data in ucs2 or not + PRBool need2 = PR_FALSE; + const PRUnichar* ucp = aBuffer; + const PRUnichar* uend = aBuffer + aLength; + while (ucp < uend) { + PRUnichar ch = *ucp++; + if (ch >> 8) { + need2 = PR_TRUE; + break; + } + } + + if (need2) { + // Use ucs2 storage because we have to + PRUnichar* nt = (PRUnichar*)nsMemory::Alloc(aLength*sizeof(PRUnichar)); + if (nsnull != nt) { + // Copy data + nsCRT::memcpy(nt, aBuffer, sizeof(PRUnichar) * aLength); + + // Setup our fields + m2b = nt; + mState.mIs2b = 1; + mState.mInHeap = 1; + mState.mLength = aLength; + } + } + else { + // Use 1 byte storage because we can + unsigned char* nt = (unsigned char*)nsMemory::Alloc(aLength*sizeof(unsigned char)); + if (nsnull != nt) { + // Copy data + unsigned char* cp = nt; + unsigned char* end = nt + aLength; + while (cp < end) { + *cp++ = (unsigned char) *aBuffer++; + } + + // Setup our fields + m1b = nt; + mState.mIs2b = 0; + mState.mInHeap = 1; + mState.mLength = aLength; + } + } + } + } /** * Change the contents of this fragment to be a copy of the given @@ -189,7 +244,14 @@ public: /** * Append the contents of this string fragment to aString */ - void AppendTo(nsString& aString) const; + void AppendTo(nsString& aString) const { + if (mState.mIs2b) { + aString.Append(m2b, mState.mLength); + } + else { + aString.AppendWithConversion((char*)m1b, mState.mLength); + } + } /** * Make a copy of the fragments contents starting at offset for @@ -235,7 +297,20 @@ protected: FragmentBits mState; }; - void ReleaseText(); + void ReleaseText() { + if (mState.mLength && m1b && mState.mInHeap) { + if (mState.mIs2b) { + nsMemory::Free(m2b); + } + else { + nsMemory::Free(m1b); + } + } + m1b = nsnull; + mState.mIs2b = 0; + mState.mInHeap = 0; + mState.mLength = 0; + } }; #endif /* nsTextFragment_h___ */ diff --git a/mozilla/content/base/src/nsCommentNode.cpp b/mozilla/content/base/src/nsCommentNode.cpp index 60d92230fb2..379e9b4a679 100644 --- a/mozilla/content/base/src/nsCommentNode.cpp +++ b/mozilla/content/base/src/nsCommentNode.cpp @@ -24,7 +24,6 @@ #include "nsIScriptObjectOwner.h" #include "nsIDOMEventReceiver.h" #include "nsIContent.h" -#include "nsFrame.h" #include "nsLayoutAtoms.h" #include "nsISelection.h" #include "nsISelectionPrivate.h" @@ -371,20 +370,6 @@ nsCommentNode::HandleDOMEvent(nsIPresContext* aPresContext, aFlags, aEventStatus); } -nsresult NS_NewCommentFrame(nsIPresShell* aPresShell, nsIFrame*& aResult); -nsresult -NS_NewCommentFrame(nsIPresShell* aPresShell, nsIFrame*& aResult) -{ - nsIFrame* frame; - NS_NewEmptyFrame(aPresShell, &frame); - if (nsnull == frame) { - return NS_ERROR_OUT_OF_MEMORY; - } - aResult = frame; - return NS_OK; -} - - // This would ideally be done by the parser, but for the sake // of "genericity" it's being done in the comment content code static void diff --git a/mozilla/content/base/src/nsContentIterator.cpp b/mozilla/content/base/src/nsContentIterator.cpp index 700f46f764b..eac253e49d0 100644 --- a/mozilla/content/base/src/nsContentIterator.cpp +++ b/mozilla/content/base/src/nsContentIterator.cpp @@ -37,6 +37,7 @@ #include "nsCOMPtr.h" #include "nsIPresContext.h" #include "nsIComponentManager.h" +#include "nsContentCID.h" #include "nsLayoutCID.h" #include "nsVoidArray.h" diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 49e697362bc..b5b2412bac3 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -86,13 +86,14 @@ #include "nsIServiceManager.h" #include "nsLayoutAtoms.h" +#include "nsContentCID.h" #include "nsLayoutCID.h" #include "nsIDOMRange.h" #include "nsIEnumerator.h" #include "nsDOMError.h" #include "nsIScrollableView.h" #include "nsIFrame.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" #include "nsNodeInfoManager.h" #include "nsIXBLService.h" @@ -112,7 +113,7 @@ #include "nsXULAtoms.h" static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); - +static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); #include "nsILineBreakerFactory.h" @@ -611,7 +612,6 @@ nsDocument::~nsDocument() NS_RELEASE(subdoc); } - mRootContent = nsnull; mChildren->Clear(); @@ -1041,9 +1041,9 @@ nsDocument::CreateShell(nsIPresContext* aContext, return NS_ERROR_NULL_POINTER; } - nsIPresShell* shell; - nsresult rv = NS_NewPresShell(&shell); - if (NS_OK != rv) { + nsresult rv; + nsIPresShell* shell = do_CreateInstance(kPresShellCID,&rv); + if (NS_FAILED(rv)) { return rv; } @@ -2965,7 +2965,7 @@ PRBool nsDocument::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID if (manager) { nsCOMPtr scriptContext; - nsresult rv = nsLayoutUtils::GetStaticScriptContext(aContext, NS_REINTERPRET_CAST(JSObject*, mScriptObject), + nsresult rv = nsContentUtils::GetStaticScriptContext(aContext, NS_REINTERPRET_CAST(JSObject*, mScriptObject), getter_AddRefs(scriptContext)); if (NS_SUCCEEDED(rv) && scriptContext) { rv = manager->RegisterScriptEventListener(scriptContext, this, atom, theIID); diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 5c87e374af4..5ff9f354488 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -50,6 +50,7 @@ #include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLElement.h" #include "nsIDOMRange.h" +#include "nsContentCID.h" #include "nsLayoutCID.h" #include "nsHTMLParts.h" @@ -114,6 +115,10 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); #include "nsITransformMediator.h" static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); +static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); +static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); +static NS_DEFINE_CID(kPrintContextCID, NS_PRINTCONTEXT_CID); +static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); #ifdef NS_DEBUG #undef NOISY_VIEWER @@ -541,7 +546,7 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, if (!mPresContext) { // Create presentation context #if 1 - rv = NS_NewGalleyContext(getter_AddRefs(mPresContext)); + mPresContext = do_CreateInstance(kGalleyContextCID,&rv); #else // turn on print preview for debugging until print preview is fixed rv = NS_NewPrintPreviewContext(getter_AddRefs(mPresContext)); #endif @@ -1397,8 +1402,6 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, PRBool doesContainFrameSet; PRBool isIFrameSelection = IsThereAnIFrameSelected(aParent, domWinIntl, doesContainFrameSet); - PRBool isSelection = IsThereASelection(domWinIntl); - // the root webshell is responsible for // starting and ending the printing #if SPOOL_TO_ONE_DOC // this will fix all frames being painted to the same spooling document @@ -1529,8 +1532,7 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, } nsCOMPtr cx; - nsCOMPtr printcon; - rv = NS_NewPrintContext(getter_AddRefs(printcon)); + nsCOMPtr printcon(do_CreateInstance(kPrintContextCID,&rv)); if (NS_FAILED(rv)) { return rv; } else { @@ -1544,8 +1546,7 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, CreateStyleSet(mDocument, getter_AddRefs(ss)); - nsCOMPtr ps; - rv = NS_NewPresShell(getter_AddRefs(ps)); + nsCOMPtr ps(do_CreateInstance(kPresShellCID,&rv)); if (NS_FAILED(rv)) { return rv; } @@ -1856,7 +1857,7 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, NS_WARNING("unable to load UA style sheet"); } - rv = NS_NewStyleSet(aStyleSet); + rv = nsComponentManager::CreateInstance(kStyleSetCID,nsnull,NS_GET_IID(nsIStyleSet),(void**)aStyleSet); if (NS_OK == rv) { PRInt32 index = aDocument->GetNumberOfStyleSheets(); @@ -2436,8 +2437,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi if(webContainer) { // load the document and do the initial reflow on the entire document - nsCOMPtr printcon; - rv = NS_NewPrintContext(getter_AddRefs(printcon)); + nsCOMPtr printcon(do_CreateInstance(kPrintContextCID,&rv)); if (NS_FAILED(rv)) { return rv; } else { @@ -2462,7 +2462,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi mPrintPC->SetContainer(webContainer); CreateStyleSet(mDocument,&mPrintSS); - rv = NS_NewPresShell(&mPrintPS); + rv = nsComponentManager::CreateInstance(kPresShellCID, nsnull, NS_GET_IID(nsIPresShell),(void**)&mPrintPS); if(NS_FAILED(rv)){ return rv; } diff --git a/mozilla/content/base/src/nsGeneratedIterator.cpp b/mozilla/content/base/src/nsGeneratedIterator.cpp index 30a462b36a2..8706108609a 100644 --- a/mozilla/content/base/src/nsGeneratedIterator.cpp +++ b/mozilla/content/base/src/nsGeneratedIterator.cpp @@ -36,7 +36,7 @@ #include "nsCOMPtr.h" #include "nsIPresContext.h" #include "nsIComponentManager.h" -#include "nsLayoutCID.h" +#include "nsContentCID.h" #include "nsIPresShell.h" #define DO_AFTER 1 diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 06f874ec09c..101efa81814 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -73,7 +73,7 @@ #include "nsLayoutAtoms.h" #include "nsHTMLAtoms.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" #include "nsIJSContextStack.h" #include "nsIServiceManager.h" @@ -1949,7 +1949,7 @@ nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, atom.get() == nsLayoutAtoms::onmouseover || atom.get() == nsLayoutAtoms::onmouseout) { if (NS_OK == GetListenerManager(&manager)) { nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || + if (NS_FAILED(nsContentUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMMouseListenerIID)) { NS_RELEASE(manager); return PR_FALSE; @@ -1959,7 +1959,7 @@ nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, else if (atom.get() == nsLayoutAtoms::onkeydown || atom.get() == nsLayoutAtoms::onkeyup || atom.get() == nsLayoutAtoms::onkeypress) { if (NS_OK == GetListenerManager(&manager)) { nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || + if (NS_FAILED(nsContentUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMKeyListenerIID)) { NS_RELEASE(manager); return PR_FALSE; @@ -1969,7 +1969,7 @@ nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, else if (atom.get() == nsLayoutAtoms::onmousemove) { if (NS_OK == GetListenerManager(&manager)) { nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || + if (NS_FAILED(nsContentUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMMouseMotionListenerIID)) { NS_RELEASE(manager); return PR_FALSE; @@ -1979,7 +1979,7 @@ nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, else if (atom.get() == nsLayoutAtoms::onfocus || atom.get() == nsLayoutAtoms::onblur) { if (NS_OK == GetListenerManager(&manager)) { nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || + if (NS_FAILED(nsContentUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMFocusListenerIID)) { NS_RELEASE(manager); return PR_FALSE; @@ -1990,7 +1990,7 @@ nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, atom.get() == nsLayoutAtoms::onselect) { if (NS_OK == GetListenerManager(&manager)) { nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || + if (NS_FAILED(nsContentUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMFormListenerIID)) { NS_RELEASE(manager); return PR_FALSE; @@ -2001,7 +2001,7 @@ nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, atom.get() == nsLayoutAtoms::onerror) { if (NS_OK == GetListenerManager(&manager)) { nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || + if (NS_FAILED(nsContentUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMLoadListenerIID)) { NS_RELEASE(manager); return PR_FALSE; @@ -2012,7 +2012,7 @@ nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, atom.get() == nsLayoutAtoms::onscroll) { if (NS_OK == GetListenerManager(&manager)) { nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || + if (NS_FAILED(nsContentUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMPaintListenerIID)) { NS_RELEASE(manager); @@ -2634,7 +2634,7 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); } - nsLayoutUtils::GetDynamicScriptContext(cx, getter_AddRefs(context)); + nsContentUtils::GetDynamicScriptContext(cx, getter_AddRefs(context)); NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); } @@ -2642,7 +2642,7 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, if (mNodeInfo->Equals(nsHTMLAtoms::body) || mNodeInfo->Equals(nsHTMLAtoms::frameset)) { if (!global && cx) { - nsLayoutUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); + nsContentUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); } diff --git a/mozilla/content/base/src/nsHTMLValue.cpp b/mozilla/content/base/src/nsHTMLValue.cpp index 6e7c540d03c..ec0cdc4749d 100644 --- a/mozilla/content/base/src/nsHTMLValue.cpp +++ b/mozilla/content/base/src/nsHTMLValue.cpp @@ -22,20 +22,9 @@ #include "nsHTMLValue.h" #include "nsString.h" -#include "nsReadableUtils.h" #include "nsCRT.h" #include "nsISizeOfHandler.h" -nsHTMLValue::nsHTMLValue(nsHTMLUnit aUnit) - : mUnit(aUnit) -{ - NS_ASSERTION((aUnit <= eHTMLUnit_Empty), "not a valueless unit"); - if (aUnit > eHTMLUnit_Empty) { - mUnit = eHTMLUnit_Null; - } - mValue.mString = nsnull; -} - nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit) : mUnit(aUnit) { @@ -61,21 +50,6 @@ nsHTMLValue::nsHTMLValue(float aValue) mValue.mFloat = aValue; } -nsHTMLValue::nsHTMLValue(const nsAReadableString& aValue, nsHTMLUnit aUnit) - : mUnit(aUnit) -{ - NS_ASSERTION((eHTMLUnit_String == aUnit) || - (eHTMLUnit_ColorName == aUnit), "not a string value"); - if ((eHTMLUnit_String == aUnit) || - (eHTMLUnit_ColorName == aUnit)) { - mValue.mString = ToNewUnicode(aValue); - } - else { - mUnit = eHTMLUnit_Null; - mValue.mInt = 0; - } -} - nsHTMLValue::nsHTMLValue(nsISupports* aValue) : mUnit(eHTMLUnit_ISupports) { @@ -115,11 +89,6 @@ nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy) } } -nsHTMLValue::~nsHTMLValue(void) -{ - Reset(); -} - nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy) { Reset(); @@ -184,21 +153,6 @@ PRUint32 nsHTMLValue::HashValue(void) const } -void nsHTMLValue::Reset(void) -{ - if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) { - if (nsnull != mValue.mString) { - nsCRT::free(mValue.mString); - } - } - else if (eHTMLUnit_ISupports == mUnit) { - NS_IF_RELEASE(mValue.mISupports); - } - mUnit = eHTMLUnit_Null; - mValue.mString = nsnull; -} - - void nsHTMLValue::SetIntValue(PRInt32 aValue, nsHTMLUnit aUnit) { Reset(); diff --git a/mozilla/content/base/src/nsHTMLValue.h b/mozilla/content/base/src/nsHTMLValue.h index 1c7ed08306f..95a6eb21a28 100644 --- a/mozilla/content/base/src/nsHTMLValue.h +++ b/mozilla/content/base/src/nsHTMLValue.h @@ -26,6 +26,7 @@ #include "nsColor.h" #include "nsString.h" #include "nsISupports.h" +#include "nsReadableUtils.h" enum nsHTMLUnit { eHTMLUnit_Null = 0, // (n/a) null unit, value is not specified @@ -45,14 +46,39 @@ enum nsHTMLUnit { class nsHTMLValue { public: - nsHTMLValue(nsHTMLUnit aUnit = eHTMLUnit_Null); + nsHTMLValue(nsHTMLUnit aUnit = eHTMLUnit_Null) : mUnit(aUnit) + { + NS_ASSERTION((aUnit <= eHTMLUnit_Empty), "not a valueless unit"); + if (aUnit > eHTMLUnit_Empty) { + mUnit = eHTMLUnit_Null; + } + mValue.mString = nsnull; + } + nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit); nsHTMLValue(float aValue); - nsHTMLValue(const nsAReadableString& aValue, nsHTMLUnit aUnit = eHTMLUnit_String); + nsHTMLValue(const nsAReadableString& aValue, + nsHTMLUnit aUnit = eHTMLUnit_String) : mUnit(aUnit) + { + NS_ASSERTION((eHTMLUnit_String == aUnit) || + (eHTMLUnit_ColorName == aUnit), "not a string value"); + if ((eHTMLUnit_String == aUnit) || + (eHTMLUnit_ColorName == aUnit)) { + mValue.mString = ToNewUnicode(aValue); + } + else { + mUnit = eHTMLUnit_Null; + mValue.mInt = 0; + } + } + nsHTMLValue(nsISupports* aValue); nsHTMLValue(nscolor aValue); nsHTMLValue(const nsHTMLValue& aCopy); - ~nsHTMLValue(void); + ~nsHTMLValue(void) + { + Reset(); + } nsHTMLValue& operator=(const nsHTMLValue& aCopy); PRBool operator==(const nsHTMLValue& aOther) const; @@ -67,7 +93,19 @@ public: nsISupports* GetISupportsValue(void) const; nscolor GetColorValue(void) const; - void Reset(void); + void Reset(void) { + if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) { + if (nsnull != mValue.mString) { + nsCRT::free(mValue.mString); + } + } + else if (eHTMLUnit_ISupports == mUnit) { + NS_IF_RELEASE(mValue.mISupports); + } + mUnit = eHTMLUnit_Null; + mValue.mString = nsnull; + } + void SetIntValue(PRInt32 aValue, nsHTMLUnit aUnit); void SetPixelValue(PRInt32 aValue); void SetPercentValue(float aValue); diff --git a/mozilla/content/base/src/nsPlainTextSerializer.cpp b/mozilla/content/base/src/nsPlainTextSerializer.cpp index bf349798f82..d791b2d3d18 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.cpp +++ b/mozilla/content/base/src/nsPlainTextSerializer.cpp @@ -35,7 +35,7 @@ #include "nsITextContent.h" #include "nsTextFragment.h" #include "nsParserCIID.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" static NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID); static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); @@ -377,7 +377,7 @@ nsPlainTextSerializer::AddLeaf(const nsIParserNode& aNode) PRUint32 length; str.SetCapacity(text.Length()); nsReadingIterator srcStart, srcEnd; - length = nsLayoutUtils::CopyNewlineNormalizedUnicodeTo(text.BeginReading(srcStart), text.EndReading(srcEnd), str); + length = nsContentUtils::CopyNewlineNormalizedUnicodeTo(text.BeginReading(srcStart), text.EndReading(srcEnd), str); str.SetLength(length); return DoAddLeaf(type, str); } diff --git a/mozilla/content/base/src/nsSelection.cpp b/mozilla/content/base/src/nsSelection.cpp index 97e88f6b54e..7e134bfaf3a 100644 --- a/mozilla/content/base/src/nsSelection.cpp +++ b/mozilla/content/base/src/nsSelection.cpp @@ -34,7 +34,7 @@ #include "nsISelectionListener.h" #include "nsIFocusTracker.h" #include "nsIComponentManager.h" -#include "nsLayoutCID.h" +#include "nsContentCID.h" #include "nsIContent.h" #include "nsIDOMElement.h" #include "nsIDOMNode.h" diff --git a/mozilla/content/base/src/nsStyleContext.cpp b/mozilla/content/base/src/nsStyleContext.cpp index 573da0dfd00..cc960666fa2 100644 --- a/mozilla/content/base/src/nsStyleContext.cpp +++ b/mozilla/content/base/src/nsStyleContext.cpp @@ -44,8 +44,6 @@ #include "nsISupportsArray.h" #include "nsCRT.h" -#include "nsIFrame.h" - #include "nsCOMPtr.h" #include "nsIStyleSet.h" #include "nsISizeOfHandler.h" @@ -54,8 +52,6 @@ #include "prenv.h" -#define DELETE_ARRAY_IF(array) if (array) { delete[] array; array = nsnull; } - #ifdef DEBUG // #define NOISY_DEBUG #endif @@ -104,26 +100,6 @@ static nscoord CalcCoord(const nsStyleCoord& aCoord, const nscoord* aEnumTable, PRInt32 aNumEnums); -// XXX this is here to support deprecated calc spacing methods only -static nscoord kBorderWidths[3]; // contain the twips values for thin, medium and thick -static void InitBorderWidths(nsIPresContext* aPresContext) -{ - // XXX support kBorderWidhts until deprecated methods are removed - static PRBool kWidthsInitialized = PR_FALSE; - if (! kWidthsInitialized) { - kWidthsInitialized = PR_TRUE; - - float pixelsToTwips = 20.0f; - if (aPresContext) { - aPresContext->GetPixelsToTwips(&pixelsToTwips); - } - kBorderWidths[NS_STYLE_BORDER_WIDTH_THIN] = NSIntPixelsToTwips(1, pixelsToTwips); - kBorderWidths[NS_STYLE_BORDER_WIDTH_MEDIUM] = NSIntPixelsToTwips(3, pixelsToTwips); - kBorderWidths[NS_STYLE_BORDER_WIDTH_THICK] = NSIntPixelsToTwips(5, pixelsToTwips); - } -} - - // EnsureBlockDisplay: // - if the display value (argument) is not a block-type // then we set it to a valid block display value @@ -133,19 +109,11 @@ static void EnsureBlockDisplay(/*in out*/PRUint8 &display); // -------------------- // nsStyleFont // -nsStyleFont::nsStyleFont(void) - : mFont(nsnull, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE, 0), - mFixedFont(nsnull, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE, 0) -{} - nsStyleFont::nsStyleFont(const nsFont& aVariableFont, const nsFont& aFixedFont) : mFont(aVariableFont), mFixedFont(aFixedFont) { } -nsStyleFont::~nsStyleFont(void) { } - - struct StyleFontImpl : public nsStyleFont { StyleFontImpl(const nsFont& aVariableFont, const nsFont& aFixedFont) : nsStyleFont(aVariableFont, aFixedFont) @@ -248,8 +216,6 @@ PRUint32 StyleFontImpl::ComputeCRC32(PRUint32 aCrc) const // -------------------- // nsStyleColor // -nsStyleColor::nsStyleColor(void) { } -nsStyleColor::~nsStyleColor(void) { } struct StyleColorImpl: public nsStyleColor { StyleColorImpl(void) { } @@ -377,127 +343,6 @@ PRUint32 StyleColorImpl::ComputeCRC32(PRUint32 aCrc) const #pragma mark - #endif -#define BORDER_COLOR_DEFINED 0x80 -#define BORDER_COLOR_SPECIAL 0x40 -#define BORDER_STYLE_MASK 0x3F - -#define NS_SPACING_MARGIN 0 -#define NS_SPACING_PADDING 1 -#define NS_SPACING_BORDER 2 - -static nscoord CalcSideFor(const nsIFrame* aFrame, const nsStyleCoord& aCoord, - PRUint8 aSpacing, PRUint8 aSide, - const nscoord* aEnumTable, PRInt32 aNumEnums) -{ - nscoord result = 0; - - switch (aCoord.GetUnit()) { - case eStyleUnit_Auto: - // Auto margins are handled by layout - break; - - case eStyleUnit_Inherit: - nsIFrame* parentFrame; - aFrame->GetParent(&parentFrame); // XXX may not be direct parent... - if (nsnull != parentFrame) { - nsIStyleContext* parentContext; - parentFrame->GetStyleContext(&parentContext); - if (nsnull != parentContext) { - nsMargin parentSide; - switch (aSpacing) { - case NS_SPACING_MARGIN: { - const nsStyleMargin* parentMargin = (const nsStyleMargin*)parentContext->GetStyleData(eStyleStruct_Margin); - parentMargin->CalcMarginFor(parentFrame, parentSide); - break; - } - case NS_SPACING_PADDING: { - const nsStylePadding* parentPadding = (const nsStylePadding*)parentContext->GetStyleData(eStyleStruct_Padding); - parentPadding->CalcPaddingFor(parentFrame, parentSide); - break; - } - case NS_SPACING_BORDER: { - const nsStyleBorder* parentBorder = (const nsStyleBorder*)parentContext->GetStyleData(eStyleStruct_Border); - parentBorder->CalcBorderFor(parentFrame, parentSide); - break; - } - } - switch (aSide) { - case NS_SIDE_LEFT: result = parentSide.left; break; - case NS_SIDE_TOP: result = parentSide.top; break; - case NS_SIDE_RIGHT: result = parentSide.right; break; - case NS_SIDE_BOTTOM: result = parentSide.bottom; break; - } - NS_RELEASE(parentContext); - } - } - break; - - case eStyleUnit_Percent: - { - nscoord baseWidth = 0; - PRBool isBase = PR_FALSE; - nsIFrame* frame; - aFrame->GetParent(&frame); - while (nsnull != frame) { - frame->IsPercentageBase(isBase); - if (isBase) { - nsSize size; - frame->GetSize(size); - baseWidth = size.width; // not really width, need to subtract out padding... - break; - } - frame->GetParent(&frame); - } - result = (nscoord)((float)baseWidth * aCoord.GetPercentValue()); - } - break; - - case eStyleUnit_Coord: - result = aCoord.GetCoordValue(); - break; - - case eStyleUnit_Enumerated: - if (nsnull != aEnumTable) { - PRInt32 value = aCoord.GetIntValue(); - if ((0 <= value) && (value < aNumEnums)) { - return aEnumTable[aCoord.GetIntValue()]; - } - } - break; - - case eStyleUnit_Null: - case eStyleUnit_Normal: - case eStyleUnit_Integer: - case eStyleUnit_Proportional: - default: - result = 0; - break; - } - if ((NS_SPACING_PADDING == aSpacing) || (NS_SPACING_BORDER == aSpacing)) { - if (result < 0) { - result = 0; - } - } - return result; -} - -static void CalcSidesFor(const nsIFrame* aFrame, const nsStyleSides& aSides, - PRUint8 aSpacing, - const nscoord* aEnumTable, PRInt32 aNumEnums, - nsMargin& aResult) -{ - nsStyleCoord coord; - - aResult.left = CalcSideFor(aFrame, aSides.GetLeft(coord), aSpacing, NS_SIDE_LEFT, - aEnumTable, aNumEnums); - aResult.top = CalcSideFor(aFrame, aSides.GetTop(coord), aSpacing, NS_SIDE_TOP, - aEnumTable, aNumEnums); - aResult.right = CalcSideFor(aFrame, aSides.GetRight(coord), aSpacing, NS_SIDE_RIGHT, - aEnumTable, aNumEnums); - aResult.bottom = CalcSideFor(aFrame, aSides.GetBottom(coord), aSpacing, NS_SIDE_BOTTOM, - aEnumTable, aNumEnums); -} - static PRBool IsFixedData(const nsStyleSides& aSides, PRBool aEnumOK) { return PRBool(IsFixedUnit(aSides.GetLeftUnit(), aEnumOK) && @@ -535,27 +380,6 @@ static nscoord CalcCoord(const nsStyleCoord& aCoord, #pragma mark - #endif -nsStyleMargin::nsStyleMargin(void) { } -nsStyleMargin::~nsStyleMargin(void) { } - -PRBool nsStyleMargin::GetMargin(nsMargin& aMargin) const -{ - if (mHasCachedMargin) { - aMargin = mCachedMargin; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStyleMargin::CalcMarginFor(const nsIFrame* aFrame, nsMargin& aMargin) const -{ - if (mHasCachedMargin) { - aMargin = mCachedMargin; - } else { - CalcSidesFor(aFrame, mMargin, NS_SPACING_MARGIN, nsnull, 0, aMargin); - } -} - struct StyleMarginImpl: public nsStyleMargin { StyleMarginImpl(void) : nsStyleMargin() @@ -631,27 +455,6 @@ PRUint32 StyleMarginImpl::ComputeCRC32(PRUint32 aCrc) const #pragma mark - #endif -nsStylePadding::nsStylePadding(void) { } -nsStylePadding::~nsStylePadding(void) { } - -PRBool nsStylePadding::GetPadding(nsMargin& aPadding) const -{ - if (mHasCachedPadding) { - aPadding = mCachedPadding; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStylePadding::CalcPaddingFor(const nsIFrame* aFrame, nsMargin& aPadding) const -{ - if (mHasCachedPadding) { - aPadding = mCachedPadding; - } else { - CalcSidesFor(aFrame, mPadding, NS_SPACING_PADDING, nsnull, 0, aPadding); - } -} - struct StylePaddingImpl: public nsStylePadding { StylePaddingImpl(void) : nsStylePadding() @@ -727,94 +530,9 @@ PRUint32 StylePaddingImpl::ComputeCRC32(PRUint32 aCrc) const #pragma mark - #endif -nsStyleBorderPadding::nsStyleBorderPadding(void) { mHasCachedBorderPadding = PR_FALSE; } -nsStyleBorderPadding::~nsStyleBorderPadding(void) { } - -PRBool nsStyleBorderPadding::GetBorderPadding(nsMargin& aBorderPadding) const { - if (mHasCachedBorderPadding) { - aBorderPadding = mCachedBorderPadding; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStyleBorderPadding::SetBorderPadding(nsMargin aBorderPadding) { - mCachedBorderPadding = aBorderPadding; - mHasCachedBorderPadding = PR_TRUE; -} - -#ifdef XP_MAC -#pragma mark - -#endif - -nsStyleBorder::nsStyleBorder(void) { } -nsStyleBorder::~nsStyleBorder(void) { } - -PRBool nsStyleBorder::GetBorder(nsMargin& aBorder) const -{ - if (mHasCachedBorder) { - aBorder = mCachedBorder; - return PR_TRUE; - } - return PR_FALSE; -} - -PRUint8 nsStyleBorder::GetBorderStyle(PRUint8 aSide) const -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - return (mBorderStyle[aSide] & BORDER_STYLE_MASK); -} - -void nsStyleBorder::SetBorderStyle(PRUint8 aSide, PRUint8 aStyle) -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - mBorderStyle[aSide] &= ~BORDER_STYLE_MASK; - mBorderStyle[aSide] |= (aStyle & BORDER_STYLE_MASK); - -} - -PRBool nsStyleBorder::GetBorderColor(PRUint8 aSide, nscolor& aColor) const -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - if ((mBorderStyle[aSide] & BORDER_COLOR_SPECIAL) == 0) { - aColor = mBorderColor[aSide]; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStyleBorder::SetBorderColor(PRUint8 aSide, nscolor aColor) -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - mBorderColor[aSide] = aColor; - mBorderStyle[aSide] &= ~BORDER_COLOR_SPECIAL; - mBorderStyle[aSide] |= BORDER_COLOR_DEFINED; -} - -void nsStyleBorder::SetBorderTransparent(PRUint8 aSide) -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - mBorderStyle[aSide] |= (BORDER_COLOR_DEFINED | BORDER_COLOR_SPECIAL); -} - -void nsStyleBorder::UnsetBorderColor(PRUint8 aSide) -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - mBorderStyle[aSide] &= BORDER_STYLE_MASK; -} - -void nsStyleBorder::CalcBorderFor(const nsIFrame* aFrame, nsMargin& aBorder) const -{ - if (mHasCachedBorder) { - aBorder = mCachedBorder; - } else { - CalcSidesFor(aFrame, mBorder, NS_SPACING_BORDER, kBorderWidths, 3, aBorder); - } -} - struct StyleBorderImpl: public nsStyleBorder { StyleBorderImpl(void) - : nsStyleBorder() + : nsStyleBorder(), mWidthsInitialized(PR_FALSE) {} void ResetFrom(const nsStyleBorder* aParent, nsIPresContext* aPresContext); @@ -828,10 +546,25 @@ struct StyleBorderImpl: public nsStyleBorder { private: // These are not allowed StyleBorderImpl(const StyleBorderImpl& aOther); StyleBorderImpl& operator=(const StyleBorderImpl& aOther); + + // XXX remove with deprecated methods + PRBool mWidthsInitialized; }; void StyleBorderImpl::ResetFrom(const nsStyleBorder* aParent, nsIPresContext* aPresContext) { + // XXX support mBorderWidhts until deprecated methods are removed + if (! mWidthsInitialized) { + float pixelsToTwips = 20.0f; + if (aPresContext) { + aPresContext->GetPixelsToTwips(&pixelsToTwips); + } + mBorderWidths[NS_STYLE_BORDER_WIDTH_THIN] = NSIntPixelsToTwips(1, pixelsToTwips); + mBorderWidths[NS_STYLE_BORDER_WIDTH_MEDIUM] = NSIntPixelsToTwips(3, pixelsToTwips); + mBorderWidths[NS_STYLE_BORDER_WIDTH_THICK] = NSIntPixelsToTwips(5, pixelsToTwips); + mWidthsInitialized = PR_TRUE; + } + // spacing values not inherited nsStyleCoord medium(NS_STYLE_BORDER_WIDTH_MEDIUM, eStyleUnit_Enumerated); mBorder.SetLeft(medium); @@ -889,25 +622,25 @@ void StyleBorderImpl::RecalcData(nscolor aColor) mCachedBorder.left = 0; } else { - mCachedBorder.left = CalcCoord(mBorder.GetLeft(coord), kBorderWidths, 3); + mCachedBorder.left = CalcCoord(mBorder.GetLeft(coord), mBorderWidths, 3); } if (!IsBorderSideVisible(NS_SIDE_TOP)) { mCachedBorder.top = 0; } else { - mCachedBorder.top = CalcCoord(mBorder.GetTop(coord), kBorderWidths, 3); + mCachedBorder.top = CalcCoord(mBorder.GetTop(coord), mBorderWidths, 3); } if (!IsBorderSideVisible(NS_SIDE_RIGHT)) { mCachedBorder.right = 0; } else { - mCachedBorder.right = CalcCoord(mBorder.GetRight(coord), kBorderWidths, 3); + mCachedBorder.right = CalcCoord(mBorder.GetRight(coord), mBorderWidths, 3); } if (!IsBorderSideVisible(NS_SIDE_BOTTOM)) { mCachedBorder.bottom = 0; } else { - mCachedBorder.bottom = CalcCoord(mBorder.GetBottom(coord), kBorderWidths, 3); + mCachedBorder.bottom = CalcCoord(mBorder.GetBottom(coord), mBorderWidths, 3); } mHasCachedBorder = PR_TRUE; } @@ -976,53 +709,9 @@ PRUint32 StyleBorderImpl::ComputeCRC32(PRUint32 aCrc) const #pragma mark - #endif -nsStyleOutline::nsStyleOutline(void) { } -nsStyleOutline::~nsStyleOutline(void) { } - -PRBool nsStyleOutline::GetOutlineWidth(nscoord& aWidth) const -{ - if (mHasCachedOutline) { - aWidth = mCachedOutlineWidth; - return PR_TRUE; - } - return PR_FALSE; -} - -PRUint8 nsStyleOutline::GetOutlineStyle(void) const -{ - return (mOutlineStyle & BORDER_STYLE_MASK); -} - -void nsStyleOutline::SetOutlineStyle(PRUint8 aStyle) -{ - mOutlineStyle &= ~BORDER_STYLE_MASK; - mOutlineStyle |= (aStyle & BORDER_STYLE_MASK); -} - -PRBool nsStyleOutline::GetOutlineColor(nscolor& aColor) const -{ - if ((mOutlineStyle & BORDER_COLOR_SPECIAL) == 0) { - aColor = mOutlineColor; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStyleOutline::SetOutlineColor(nscolor aColor) -{ - mOutlineColor = aColor; - mOutlineStyle &= ~BORDER_COLOR_SPECIAL; - mOutlineStyle |= BORDER_COLOR_DEFINED; -} - -void nsStyleOutline::SetOutlineInvert(void) -{ - mOutlineStyle |= (BORDER_COLOR_DEFINED | BORDER_COLOR_SPECIAL); -} - struct StyleOutlineImpl: public nsStyleOutline { StyleOutlineImpl(void) - : nsStyleOutline() + : nsStyleOutline(), mWidthsInitialized(PR_FALSE) {} void ResetFrom(const nsStyleOutline* aParent, nsIPresContext* aPresContext); @@ -1035,10 +724,25 @@ struct StyleOutlineImpl: public nsStyleOutline { private: // These are not allowed StyleOutlineImpl(const StyleOutlineImpl& aOther); StyleOutlineImpl& operator=(const StyleOutlineImpl& aOther); + + // XXX remove with deprecated methods + PRBool mWidthsInitialized; }; void StyleOutlineImpl::ResetFrom(const nsStyleOutline* aParent, nsIPresContext* aPresContext) { + // XXX support mBorderWidhts until deprecated methods are removed + if (! mWidthsInitialized) { + float pixelsToTwips = 20.0f; + if (aPresContext) { + aPresContext->GetPixelsToTwips(&pixelsToTwips); + } + mBorderWidths[NS_STYLE_BORDER_WIDTH_THIN] = NSIntPixelsToTwips(1, pixelsToTwips); + mBorderWidths[NS_STYLE_BORDER_WIDTH_MEDIUM] = NSIntPixelsToTwips(3, pixelsToTwips); + mBorderWidths[NS_STYLE_BORDER_WIDTH_THICK] = NSIntPixelsToTwips(5, pixelsToTwips); + mWidthsInitialized = PR_TRUE; + } + // spacing values not inherited mOutlineRadius.Reset(); @@ -1068,7 +772,7 @@ void StyleOutlineImpl::RecalcData(void) mCachedOutlineWidth = 0; } else { - mCachedOutlineWidth = CalcCoord(mOutlineWidth, kBorderWidths, 3); + mCachedOutlineWidth = CalcCoord(mOutlineWidth, mBorderWidths, 3); } mHasCachedOutline = PR_TRUE; } @@ -1385,9 +1089,6 @@ PRUint32 StyleTextImpl::ComputeCRC32(PRUint32 aCrc) const // nsStyleDisplay // -nsStyleDisplay::nsStyleDisplay(void) { } -nsStyleDisplay::~nsStyleDisplay(void) { } - struct StyleDisplayImpl: public nsStyleDisplay { StyleDisplayImpl(void) { } @@ -1645,168 +1346,6 @@ nsStyleContent::~nsStyleContent(void) DELETE_ARRAY_IF(mQuotes); } -nsresult -nsStyleContent::GetContentAt(PRUint32 aIndex, nsStyleContentType& aType, nsString& aContent) const -{ - if (aIndex < mContentCount) { - aType = mContents[aIndex].mType; - aContent = mContents[aIndex].mContent; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::AllocateContents(PRUint32 aCount) -{ - if (aCount != mContentCount) { - DELETE_ARRAY_IF(mContents); - if (aCount) { - mContents = new nsStyleContentData[aCount]; - if (! mContents) { - mContentCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } - } - mContentCount = aCount; - } - return NS_OK; -} - -nsresult -nsStyleContent::SetContentAt(PRUint32 aIndex, nsStyleContentType aType, const nsString& aContent) -{ - if (aIndex < mContentCount) { - mContents[aIndex].mType = aType; - if (aType < eStyleContentType_OpenQuote) { - mContents[aIndex].mContent = aContent; - } - else { - mContents[aIndex].mContent.Truncate(); - } - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::GetCounterIncrementAt(PRUint32 aIndex, nsString& aCounter, PRInt32& aIncrement) const -{ - if (aIndex < mIncrementCount) { - aCounter = mIncrements[aIndex].mCounter; - aIncrement = mIncrements[aIndex].mValue; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::AllocateCounterIncrements(PRUint32 aCount) -{ - if (aCount != mIncrementCount) { - DELETE_ARRAY_IF(mIncrements); - if (aCount) { - mIncrements = new nsStyleCounterData[aCount]; - if (! mIncrements) { - mIncrementCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } - } - mIncrementCount = aCount; - } - return NS_OK; -} - -nsresult -nsStyleContent::SetCounterIncrementAt(PRUint32 aIndex, const nsString& aCounter, PRInt32 aIncrement) -{ - if (aIndex < mIncrementCount) { - mIncrements[aIndex].mCounter = aCounter; - mIncrements[aIndex].mValue = aIncrement; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::GetCounterResetAt(PRUint32 aIndex, nsString& aCounter, PRInt32& aValue) const -{ - if (aIndex < mResetCount) { - aCounter = mResets[aIndex].mCounter; - aValue = mResets[aIndex].mValue; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::AllocateCounterResets(PRUint32 aCount) -{ - if (aCount != mResetCount) { - DELETE_ARRAY_IF(mResets); - if (aCount) { - mResets = new nsStyleCounterData[aCount]; - if (! mResets) { - mResetCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } - } - mResetCount = aCount; - } - return NS_OK; -} - -nsresult -nsStyleContent::SetCounterResetAt(PRUint32 aIndex, const nsString& aCounter, PRInt32 aValue) -{ - if (aIndex < mResetCount) { - mResets[aIndex].mCounter = aCounter; - mResets[aIndex].mValue = aValue; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::GetQuotesAt(PRUint32 aIndex, nsString& aOpen, nsString& aClose) const -{ - if (aIndex < mQuotesCount) { - aIndex *= 2; - aOpen = mQuotes[aIndex]; - aClose = mQuotes[++aIndex]; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::AllocateQuotes(PRUint32 aCount) -{ - if (aCount != mQuotesCount) { - DELETE_ARRAY_IF(mQuotes); - if (aCount) { - mQuotes = new nsString[aCount * 2]; - if (! mQuotes) { - mQuotesCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } - } - mQuotesCount = aCount; - } - return NS_OK; -} - -nsresult -nsStyleContent::SetQuotesAt(PRUint32 aIndex, const nsString& aOpen, const nsString& aClose) -{ - if (aIndex < mQuotesCount) { - aIndex *= 2; - mQuotes[aIndex] = aOpen; - mQuotes[++aIndex] = aClose; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} struct StyleContentImpl: public nsStyleContent { StyleContentImpl(void) : nsStyleContent() { }; @@ -2980,8 +2519,6 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent, NS_IF_ADDREF(mPseudoTag); NS_IF_ADDREF(mRules); - InitBorderWidths(aPresContext); - mNextSibling = this; mPrevSibling = this; if (nsnull != mParent) { diff --git a/mozilla/content/base/src/nsTextFragment.cpp b/mozilla/content/base/src/nsTextFragment.cpp index fad38cd3065..6400a43e619 100644 --- a/mozilla/content/base/src/nsTextFragment.cpp +++ b/mozilla/content/base/src/nsTextFragment.cpp @@ -20,32 +20,7 @@ * Contributor(s): */ #include "nsTextFragment.h" -#include "nsString.h" -#include "nsCRT.h" #include "nsReadableUtils.h" -#include "nsMemory.h" - -nsTextFragment::~nsTextFragment() -{ - ReleaseText(); -} - -void -nsTextFragment::ReleaseText() -{ - if (mState.mLength && m1b && mState.mInHeap) { - if (mState.mIs2b) { - nsMemory::Free(m2b); - } - else { - nsMemory::Free(m1b); - } - } - m1b = nsnull; - mState.mIs2b = 0; - mState.mInHeap = 0; - mState.mLength = 0; -} nsTextFragment::nsTextFragment(const nsTextFragment& aOther) : m1b(nsnull), @@ -66,13 +41,6 @@ nsTextFragment::nsTextFragment(const char* aString) SetTo(aString, strlen(aString)); } -nsTextFragment::nsTextFragment(const PRUnichar* aString) - : m1b(nsnull), - mAllBits(0) -{ - SetTo(aString, nsCRT::strlen(aString)); -} - nsTextFragment::nsTextFragment(const nsString& aString) : m1b(nsnull), mAllBits(0) @@ -139,58 +107,6 @@ nsTextFragment::SetTo(PRUnichar* aBuffer, PRInt32 aLength, PRBool aRelease) mState.mLength = aLength; } -void -nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength) -{ - ReleaseText(); - if (0 != aLength) { - // See if we need to store the data in ucs2 or not - PRBool need2 = PR_FALSE; - const PRUnichar* ucp = aBuffer; - const PRUnichar* uend = aBuffer + aLength; - while (ucp < uend) { - PRUnichar ch = *ucp++; - if (ch >> 8) { - need2 = PR_TRUE; - break; - } - } - - if (need2) { - // Use ucs2 storage because we have to - PRUnichar* nt = (PRUnichar*)nsMemory::Alloc(aLength*sizeof(PRUnichar)); - if (nsnull != nt) { - // Copy data - nsCRT::memcpy(nt, aBuffer, sizeof(PRUnichar) * aLength); - - // Setup our fields - m2b = nt; - mState.mIs2b = 1; - mState.mInHeap = 1; - mState.mLength = aLength; - } - } - else { - // Use 1 byte storage because we can - unsigned char* nt = (unsigned char*)nsMemory::Alloc(aLength*sizeof(unsigned char)); - if (nsnull != nt) { - // Copy data - unsigned char* cp = nt; - unsigned char* end = nt + aLength; - while (cp < end) { - *cp++ = (unsigned char) *aBuffer++; - } - - // Setup our fields - m1b = nt; - mState.mIs2b = 0; - mState.mInHeap = 1; - mState.mLength = aLength; - } - } - } -} - void nsTextFragment::SetTo(const char* aBuffer, PRInt32 aLength) { @@ -208,17 +124,6 @@ nsTextFragment::SetTo(const char* aBuffer, PRInt32 aLength) } } -void -nsTextFragment::AppendTo(nsString& aString) const -{ - if (mState.mIs2b) { - aString.Append(m2b, mState.mLength); - } - else { - aString.AppendWithConversion((char*)m1b, mState.mLength); - } -} - void nsTextFragment::CopyTo(PRUnichar* aDest, PRInt32 aOffset, PRInt32 aCount) { diff --git a/mozilla/content/base/src/nsTextFragment.h b/mozilla/content/base/src/nsTextFragment.h index 52ccecd4763..5c3e7bea3a0 100644 --- a/mozilla/content/base/src/nsTextFragment.h +++ b/mozilla/content/base/src/nsTextFragment.h @@ -24,7 +24,9 @@ #include "nslayout.h" #include "nsAWritableString.h" -class nsString; +#include "nsCRT.h" +#include "nsString.h" +#include "nsMemory.h" // XXX should this normalize the code to keep a \u0000 at the end? @@ -65,7 +67,9 @@ public: mAllBits = 0; } - ~nsTextFragment(); + ~nsTextFragment() { + ReleaseText(); + } /** * Initialize the contents of this fragment to be a copy of @@ -83,7 +87,10 @@ public: * Initialize the contents of this fragment to be a copy of * the argument ucs2 string. */ - nsTextFragment(const PRUnichar* aString); + nsTextFragment(const PRUnichar* aString) : m1b(nsnull), mAllBits(0) { + SetTo(aString, nsCRT::strlen(aString)); + } + /** * Initialize the contents of this fragment to be a copy of @@ -177,7 +184,55 @@ public: * buffer. Like operator= except a length is specified instead of * assuming 0 termination. */ - void SetTo(const PRUnichar* aBuffer, PRInt32 aLength); + void SetTo(const PRUnichar* aBuffer, PRInt32 aLength) { + ReleaseText(); + if (0 != aLength) { + // See if we need to store the data in ucs2 or not + PRBool need2 = PR_FALSE; + const PRUnichar* ucp = aBuffer; + const PRUnichar* uend = aBuffer + aLength; + while (ucp < uend) { + PRUnichar ch = *ucp++; + if (ch >> 8) { + need2 = PR_TRUE; + break; + } + } + + if (need2) { + // Use ucs2 storage because we have to + PRUnichar* nt = (PRUnichar*)nsMemory::Alloc(aLength*sizeof(PRUnichar)); + if (nsnull != nt) { + // Copy data + nsCRT::memcpy(nt, aBuffer, sizeof(PRUnichar) * aLength); + + // Setup our fields + m2b = nt; + mState.mIs2b = 1; + mState.mInHeap = 1; + mState.mLength = aLength; + } + } + else { + // Use 1 byte storage because we can + unsigned char* nt = (unsigned char*)nsMemory::Alloc(aLength*sizeof(unsigned char)); + if (nsnull != nt) { + // Copy data + unsigned char* cp = nt; + unsigned char* end = nt + aLength; + while (cp < end) { + *cp++ = (unsigned char) *aBuffer++; + } + + // Setup our fields + m1b = nt; + mState.mIs2b = 0; + mState.mInHeap = 1; + mState.mLength = aLength; + } + } + } + } /** * Change the contents of this fragment to be a copy of the given @@ -189,7 +244,14 @@ public: /** * Append the contents of this string fragment to aString */ - void AppendTo(nsString& aString) const; + void AppendTo(nsString& aString) const { + if (mState.mIs2b) { + aString.Append(m2b, mState.mLength); + } + else { + aString.AppendWithConversion((char*)m1b, mState.mLength); + } + } /** * Make a copy of the fragments contents starting at offset for @@ -235,7 +297,20 @@ protected: FragmentBits mState; }; - void ReleaseText(); + void ReleaseText() { + if (mState.mLength && m1b && mState.mInHeap) { + if (mState.mIs2b) { + nsMemory::Free(m2b); + } + else { + nsMemory::Free(m1b); + } + } + m1b = nsnull; + mState.mIs2b = 0; + mState.mInHeap = 0; + mState.mLength = 0; + } }; #endif /* nsTextFragment_h___ */ diff --git a/mozilla/content/events/src/Makefile.in b/mozilla/content/events/src/Makefile.in index d7b1af73655..47b6157858b 100644 --- a/mozilla/content/events/src/Makefile.in +++ b/mozilla/content/events/src/Makefile.in @@ -27,7 +27,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = layout -LIBRARY_NAME = gkevents_s +LIBRARY_NAME = gkconevents_s REQUIRES = xpcom dom js locale widget caps xpconnect docshell webshell pref necko rdf uriloader htmlparser view CPPSRCS = \ diff --git a/mozilla/content/events/src/makefile.win b/mozilla/content/events/src/makefile.win index 1008f07334f..e81301961de 100644 --- a/mozilla/content/events/src/makefile.win +++ b/mozilla/content/events/src/makefile.win @@ -24,7 +24,7 @@ DEPTH=..\..\.. include <$(DEPTH)\config\config.mak> -LIBRARY_NAME=raptorevents_s +LIBRARY_NAME=contentevents_s MODULE=raptor DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 4ae554ecfd1..5aef502dd6c 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -80,6 +80,10 @@ #include "nsWidgetsCID.h" #include "nsIFormControl.h" +#include "nsIFrameTraversal.h" +#include "nsLayoutCID.h" +static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID); + //we will use key binding by default now. this wil lbreak viewer for now #define NON_KEYBINDING 0 @@ -865,7 +869,8 @@ nsEventStateManager::DoTreeScroll(nsIPresContext* inPresContext, PRInt32 inNumLi // w/out going back to the main event loop we can easily scroll the wrong // bits and it looks like garbage (bug 63465). nsIFrame* frame = nsnull; - if ( NS_SUCCEEDED(inTreeFrame->QueryInterface(NS_GET_IID(nsIFrame), (void**)&frame)) ) { + if ( NS_SUCCEEDED(inTreeFrame->QueryInterface(NS_GET_IID(nsIFrame), + (void **)&frame)) ) { nsIView* treeView = nsnull; frame->GetView(inPresContext, &treeView); if (!treeView) { @@ -1209,10 +1214,8 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, case MOUSE_SCROLL_N_LINES: case MOUSE_SCROLL_PAGE: { - nsresult rv = DoWheelScroll(aPresContext, aTargetFrame, msEvent, - numLines, - (action == MOUSE_SCROLL_PAGE), - PR_FALSE); + DoWheelScroll(aPresContext, aTargetFrame, msEvent, numLines, + (action == MOUSE_SCROLL_PAGE), PR_FALSE); } @@ -2204,9 +2207,13 @@ nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* } } - nsresult result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal), EXTENSIVE, - mPresContext, aFrame); + nsresult result; + nsCOMPtr trav(do_CreateInstance(kFrameTraversalCID,&result)); + if (NS_FAILED(result)) + return result; + result = trav->NewFrameTraversal(getter_AddRefs(frameTraversal), EXTENSIVE, + mPresContext, aFrame); if (NS_FAILED(result)) return NS_OK; @@ -3169,8 +3176,8 @@ void nsEventStateManager::FlushPendingEvents(nsIPresContext* aPresContext) { if (nsnull != shell) { shell->FlushPendingNotifications(); nsCOMPtr viewManager; - nsresult result = shell->GetViewManager(getter_AddRefs(viewManager)); - if (nsnull != viewManager) { + shell->GetViewManager(getter_AddRefs(viewManager)); + if (viewManager) { viewManager->FlushPendingInvalidates(); } } diff --git a/mozilla/content/html/content/src/Makefile.in b/mozilla/content/html/content/src/Makefile.in index 4a2b7f6ab12..deae827c9a5 100644 --- a/mozilla/content/html/content/src/Makefile.in +++ b/mozilla/content/html/content/src/Makefile.in @@ -27,7 +27,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = layout -LIBRARY_NAME = gkhtmlcon_s +LIBRARY_NAME = gkconhtmlcon_s REQUIRES = xpcom widget dom js locale webshell htmlparser necko unicharutil view pref oji java plugin docshell uriloader xpconnect rdf caps editor intl uconv CPPSRCS = \ @@ -98,6 +98,12 @@ CPPSRCS = \ nsHTMLWBRElement.cpp \ $(NULL) +EXPORTS = \ +nsIAttributeContent.h \ +nsIHTMLTableCellElement.h \ +nsIHTMLTableColElement.h \ +$(NULL) + # we don't want the shared lib, but we want to force the creation of a static lib. override NO_SHARED_LIB=1 override NO_STATIC_LIB= diff --git a/mozilla/content/html/content/src/makefile.win b/mozilla/content/html/content/src/makefile.win index cdcae7a0fb4..1bc5ad7d75b 100644 --- a/mozilla/content/html/content/src/makefile.win +++ b/mozilla/content/html/content/src/makefile.win @@ -21,13 +21,19 @@ DEPTH=..\..\..\.. -LIBRARY_NAME = nglhtmlcon_s +LIBRARY_NAME = contenthtmlcontent_s MODULE=raptor DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN !if defined(XP_NEW_SELECTION) DEFINES = $(DEFINES) -DXP_NEW_SELECTION !endif +EXPORTS= \ + nsIAttributeContent.h \ + nsIHTMLTableCellElement.h \ + nsIHTMLTableColElement.h \ + $(NULL) + CPPSRCS= \ nsAttributeContent.cpp \ nsGenericHTMLElement.cpp \ diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index bb1d19edd93..5c0f42aa783 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -94,7 +94,7 @@ #include "nsIBindingManager.h" #include "nsIXBLBinding.h" -#include "nsObjectFrame.h" +#include "nsIObjectFrame.h" #include "nsLayoutAtoms.h" #include "xptinfo.h" #include "nsIInterfaceInfoManager.h" @@ -107,6 +107,8 @@ #include "nsParserCIID.h" #include "nsIHTMLContentSink.h" #include "nsLayoutCID.h" +#include "nsContentCID.h" +static NS_DEFINE_CID(kPresStateCID, NS_PRESSTATE_CID); // XXX todo: add in missing out-of-memory checks #include "nsIPref.h" // Used by the temp pref, should be removed! @@ -2430,7 +2432,9 @@ nsGenericHTMLElement::GetPrimaryPresState(nsIHTMLContent* aContent, aContent->GetContentID(&ID); result = history->GetState(ID, aPresState, aStateType); if (!*aPresState) { - result = NS_NewPresState(aPresState); + result = nsComponentManager::CreateInstance(kPresStateCID, nsnull, + NS_GET_IID(nsIPresState), + (void**)aPresState); if (NS_SUCCEEDED(result)) { result = history->AddState(ID, *aPresState, aStateType); } @@ -3970,19 +3974,13 @@ nsGenericHTMLElement::GetPluginInstance(nsIPluginInstance** aPluginInstance) if (!frame) { return NS_OK; } - - nsCOMPtr type; - frame->GetFrameType(getter_AddRefs(type)); - - if (type.get() == nsLayoutAtoms::objectFrame) { - // XXX We could have created an interface for this, but Troy - // preferred the ugliness of a static cast to the weight of - // a new interface. - - nsObjectFrame* objectFrame = NS_STATIC_CAST(nsObjectFrame*, frame); - - return objectFrame->GetPluginInstance(*aPluginInstance); + nsIObjectFrame* objectFrame = nsnull; + frame->QueryInterface(NS_GET_IID(nsIObjectFrame),(void**)&objectFrame); + if (objectFrame) { + objectFrame->GetPluginInstance(*aPluginInstance); + } else { + NS_WARNING("frame should have been an object frame"); } return NS_OK; diff --git a/mozilla/content/html/content/src/nsHTMLAppletElement.cpp b/mozilla/content/html/content/src/nsHTMLAppletElement.cpp index e6be01e3993..58e2632901a 100644 --- a/mozilla/content/html/content/src/nsHTMLAppletElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLAppletElement.cpp @@ -34,7 +34,7 @@ #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsIFrame.h" - +#include "nsIObjectFrame.h" #include "nsIServiceManager.h" #include "nsIJVMManager.h" #include "nsILiveConnectManager.h" @@ -252,10 +252,6 @@ nsHTMLAppletElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapF -extern nsresult -NS_GetObjectFramePluginInstance(nsIFrame* aFrame, - nsIPluginInstance*& aPluginInstance); - /** * For backwards compatibility an applet element's JavaScript object * should expose both the public fields of the applet, and the @@ -314,7 +310,7 @@ nsHTMLAppletElement::GetScriptObject(nsIScriptContext* aContext, JSObject* wrappedAppletObject = nsnull; nsCOMPtr pluginInstance; - NS_GetObjectFramePluginInstance(frame, *getter_AddRefs(pluginInstance)); + GetPluginInstance(getter_AddRefs(pluginInstance)); if (pluginInstance) { nsCOMPtr javaPluginInstance; diff --git a/mozilla/content/html/content/src/nsHTMLFormElement.cpp b/mozilla/content/html/content/src/nsHTMLFormElement.cpp index 15cbd84bb21..5a766d05f51 100644 --- a/mozilla/content/html/content/src/nsHTMLFormElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLFormElement.cpp @@ -43,7 +43,7 @@ #include "nsISizeOfHandler.h" #include "nsIScriptGlobalObject.h" #include "nsDOMError.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" #include "nsHashtable.h" #include "nsContentList.h" @@ -595,8 +595,8 @@ nsHTMLFormElement::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, nsCOMPtr scriptContext; nsresult rv = NS_OK; - rv = nsLayoutUtils::GetStaticScriptContext(aContext, aObj, - getter_AddRefs(scriptContext)); + rv = nsContentUtils::GetStaticScriptContext(aContext, aObj, + getter_AddRefs(scriptContext)); // If we can't get a script context, there's nothing we can do if (!scriptContext || NS_FAILED(rv)) { diff --git a/mozilla/content/html/content/src/nsHTMLImageElement.cpp b/mozilla/content/html/content/src/nsHTMLImageElement.cpp index ab24250611e..c47b2897668 100644 --- a/mozilla/content/html/content/src/nsHTMLImageElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLImageElement.cpp @@ -46,11 +46,10 @@ #include "nsIURL.h" #include "nsIServiceManager.h" #include "nsNetUtil.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" #include "nsIWebShell.h" #include "nsIFrame.h" -#include "nsImageFrame.h" -#include "nsFrameImageLoader.h" +#include "nsIImageFrame.h" #include "nsLayoutAtoms.h" #include "nsNodeInfoManager.h" #include "nsIFrameImageLoader.h" @@ -118,7 +117,7 @@ protected: nsresult SetSrcInner(nsIURI* aBaseURL, const nsAReadableString& aSrc); static nsresult GetCallerSourceURL(JSContext* cx, nsIURI** sourceURL); - nsresult GetImageFrame(nsImageFrame** aImageFrame); + nsresult GetImageFrame(nsIImageFrame** aImageFrame); // Only used if this is a script constructed image nsIDocument* mOwnerDocument; @@ -244,12 +243,12 @@ NS_IMPL_STRING_ATTR(nsHTMLImageElement, Vspace, vspace) NS_IMPL_INT_ATTR(nsHTMLImageElement, Vspace, vspace) nsresult -nsHTMLImageElement::GetImageFrame(nsImageFrame** aImageFrame) +nsHTMLImageElement::GetImageFrame(nsIImageFrame** aImageFrame) { nsresult result; nsCOMPtr context; nsCOMPtr shell; - + if (mDocument) { // Make sure the presentation is up-to-date result = mDocument->FlushPendingNotifications(); @@ -257,40 +256,44 @@ nsHTMLImageElement::GetImageFrame(nsImageFrame** aImageFrame) return result; } } - + result = GetPresContext(this, getter_AddRefs(context)); if (NS_FAILED(result)) { return result; } - + result = context->GetShell(getter_AddRefs(shell)); if (NS_FAILED(result)) { return result; } - + nsIFrame* frame; result = shell->GetPrimaryFrameFor(this, &frame); if (NS_FAILED(result)) { return result; } - + if (frame) { nsCOMPtr type; - + frame->GetFrameType(getter_AddRefs(type)); - + if (type.get() == nsLayoutAtoms::imageFrame) { - // XXX We could have created an interface for this, but Troy - // preferred the ugliness of a static cast to the weight of - // a new interface. - nsImageFrame* imageFrame = NS_STATIC_CAST(nsImageFrame*, frame); + nsIImageFrame* imageFrame; + result = frame->QueryInterface(NS_GET_IID(nsIImageFrame), + (void**)&imageFrame); + if (NS_FAILED(result)) { + NS_WARNING("Should not happen - frame is not image frame even though " + "type is nsLayoutAtoms::imageFrame"); + return result; + } *aImageFrame = imageFrame; - + return NS_OK; } } - return NS_ERROR_FAILURE; + return NS_OK; } NS_IMETHODIMP @@ -300,10 +303,10 @@ nsHTMLImageElement::GetComplete(PRBool* aComplete) *aComplete = PR_FALSE; nsresult result; - nsImageFrame* imageFrame; + nsIImageFrame* imageFrame; - result = GetImageFrame(&imageFrame); - if (NS_SUCCEEDED(result) && imageFrame) { + GetImageFrame(&imageFrame); + if (imageFrame) { result = imageFrame->IsImageComplete(aComplete); } else { result = NS_OK; @@ -352,13 +355,19 @@ nsHTMLImageElement::GetHeight(PRInt32* aHeight) NS_ENSURE_ARG_POINTER(aHeight); *aHeight = 0; - nsImageFrame* imageFrame; + nsIImageFrame* imageFrame = nsnull; nsresult rv = GetImageFrame(&imageFrame); - if (NS_SUCCEEDED(rv) && imageFrame) { + nsIFrame* frame = nsnull; + if (imageFrame) { + imageFrame->QueryInterface(NS_GET_IID(nsIFrame), (void**)&frame); + NS_WARN_IF_FALSE(frame,"Should not happen - image frame is not frame"); + } + + if (frame) { nsSize size; - imageFrame->GetSize(size); + frame->GetSize(size); nsCOMPtr context; rv = GetPresContext(this, getter_AddRefs(context)); @@ -431,13 +440,19 @@ nsHTMLImageElement::GetWidth(PRInt32* aWidth) NS_ENSURE_ARG_POINTER(aWidth); *aWidth = 0; - nsImageFrame* imageFrame; + nsIImageFrame* imageFrame; nsresult rv = GetImageFrame(&imageFrame); - if (NS_SUCCEEDED(rv) && imageFrame) { + nsIFrame* frame = nsnull; + if (imageFrame) { + imageFrame->QueryInterface(NS_GET_IID(nsIFrame), (void**)&frame); + NS_WARN_IF_FALSE(frame,"Should not happen - image frame is not frame"); + } + + if (NS_SUCCEEDED(rv) && frame) { nsSize size; - imageFrame->GetSize(size); + frame->GetSize(size); nsCOMPtr context; rv = GetPresContext(this, getter_AddRefs(context)); @@ -649,7 +664,7 @@ nsHTMLImageElement::GetCallerSourceURL(JSContext* cx, // XXX This will fail on non-DOM contexts :( nsCOMPtr global; - nsLayoutUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); + nsContentUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); if (global) { nsCOMPtr window(do_QueryInterface(global)); @@ -774,8 +789,8 @@ nsHTMLImageElement::Initialize(JSContext* aContext, // from the static scope chain rather than through the JSCOntext. nsCOMPtr globalObject; - nsLayoutUtils::GetStaticScriptGlobal(aContext, aObj, - getter_AddRefs(globalObject));; + nsContentUtils::GetStaticScriptGlobal(aContext, aObj, + getter_AddRefs(globalObject));; if (globalObject) { nsCOMPtr domWindow(do_QueryInterface(globalObject)); @@ -1034,7 +1049,7 @@ nsHTMLImageElement::GetNaturalHeight(PRInt32* aNaturalHeight) *aNaturalHeight = 0; - nsImageFrame* imageFrame; + nsIImageFrame* imageFrame = nsnull; nsresult rv = GetImageFrame(&imageFrame); if (NS_FAILED(rv) || !imageFrame) @@ -1059,7 +1074,7 @@ nsHTMLImageElement::GetNaturalWidth(PRInt32* aNaturalWidth) *aNaturalWidth = 0; - nsImageFrame* imageFrame; + nsIImageFrame* imageFrame; nsresult rv = GetImageFrame(&imageFrame); if (NS_FAILED(rv) || !imageFrame) diff --git a/mozilla/content/html/content/src/nsHTMLSpacerElement.cpp b/mozilla/content/html/content/src/nsHTMLSpacerElement.cpp index 2dcb2c3c16a..8d1a01ed1ed 100644 --- a/mozilla/content/html/content/src/nsHTMLSpacerElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSpacerElement.cpp @@ -44,7 +44,7 @@ #include "nsIURL.h" #include "nsIServiceManager.h" #include "nsNetUtil.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" #include "nsIWebShell.h" #include "nsIFrame.h" #include "nsLayoutAtoms.h" diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index be4f97a90e4..6612eb566e4 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -67,7 +67,7 @@ #include "nsIScrollableView.h" #include "nsHTMLAtoms.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" #include "nsIFrame.h" #include "nsICharsetConverterManager.h" #include "nsICharsetConverterManager2.h" @@ -1006,7 +1006,7 @@ MakeContentObject(nsHTMLTag aNodeType, case eHTMLTag_form: // the form was already created if (aForm) { - rv = aForm->QueryInterface(kIHTMLContentIID, (void**)aResult); + rv = aForm->QueryInterface(NS_GET_IID(nsIHTMLContent), (void**)aResult); } else { rv = NS_NewHTMLFormElement(aResult, aNodeInfo); @@ -1952,7 +1952,7 @@ SinkContext::AddText(const nsAReadableString& aText) return rv; } } - mTextLength += nsLayoutUtils::CopyNewlineNormalizedUnicodeTo(aText, + mTextLength += nsContentUtils::CopyNewlineNormalizedUnicodeTo(aText, offset, &mText[mTextLength], amount); @@ -2113,7 +2113,7 @@ SinkContext::FlushText(PRBool* aDidFlush, PRBool aReleaseLast) // Set the text in the text node nsITextContent* text = nsnull; - content->QueryInterface(kITextContentIID, (void**) &text); + content->QueryInterface(NS_GET_IID(nsITextContent), (void**) &text); text->SetText(mText, mTextLength, PR_FALSE); NS_RELEASE(text); diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index fd9adb6e18d..aa0468a13d1 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -100,7 +100,7 @@ #include "nsCharsetDetectionAdaptorCID.h" #include "nsICharsetAlias.h" #include "nsIPref.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" #include "nsIDocumentCharsetInfo.h" #include "nsIDocumentEncoder.h" //for outputting selection #include "nsIBookmarksService.h" @@ -108,7 +108,9 @@ #include "nsICachedNetData.h" #include "nsIXMLContent.h" //for createelementNS #include "nsHTMLParts.h" //for createelementNS - +#include "nsLayoutCID.h" +#include "nsContentCID.h" +static NS_DEFINE_CID(kHTMLStyleSheetCID,NS_HTMLSTYLESHEET_CID); #define DETECTOR_CONTRACTID_MAX 127 static char g_detector_contractid[DETECTOR_CONTRACTID_MAX + 1]; @@ -396,7 +398,16 @@ nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) NS_IF_RELEASE(mForms); if (nsnull == mAttrStyleSheet) { - result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this); + //result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this); + result = nsComponentManager::CreateInstance(kHTMLStyleSheetCID, nsnull, + NS_GET_IID(nsIHTMLStyleSheet), + (void**)&mAttrStyleSheet); + if (NS_SUCCEEDED(result)) { + result = mAttrStyleSheet->Init(aURL,this); + if (NS_FAILED(result)) { + NS_RELEASE(mAttrStyleSheet); + } + } } else { result = mAttrStyleSheet->Reset(aURL); @@ -617,8 +628,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); if (needsParser) { - rv = nsComponentManager::CreateInstance(kCParserCID, - nsnull, + rv = nsComponentManager::CreateInstance(kCParserCID, nsnull, NS_GET_IID(nsIParser), (void **)&mParser); if (NS_FAILED(rv)) { return rv; } @@ -2033,7 +2043,7 @@ nsHTMLDocument::GetSourceDocumentURL(JSContext* cx, // XXX This will fail on non-DOM contexts :( nsCOMPtr global; - nsLayoutUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); + nsContentUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); if (global) { nsCOMPtr window(do_QueryInterface(global, &result)); @@ -2095,8 +2105,7 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURL) if (NS_OK == result) { static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); - result = nsComponentManager::CreateInstance(kCParserCID, - nsnull, + result = nsComponentManager::CreateInstance(kCParserCID, nsnull, NS_GET_IID(nsIParser), (void **)&mParser); mIsWriting = 1; @@ -2121,9 +2130,8 @@ nsHTMLDocument::OpenCommon(nsIURI* aSourceURL) result = NS_NewHTMLContentSink(getter_AddRefs(sink), this, aSourceURL, webShell); if (NS_OK == result) { - nsCOMPtr theDTD; static NS_DEFINE_CID(kNavDTDCID, NS_CNAVDTD_CID); - result=nsComponentManager::CreateInstance(kNavDTDCID,nsnull,NS_GET_IID(nsIDTD),getter_AddRefs(theDTD)); + nsCOMPtr theDTD(do_CreateInstance(kNavDTDCID, &result)); if(NS_SUCCEEDED(result)) { mParser->RegisterDTD(theDTD); } diff --git a/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp b/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp index 3fb33e52311..2f8e17eeab7 100644 --- a/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -43,7 +43,7 @@ #include "nsINodeInfo.h" #include "prmem.h" #include "nsReadableUtils.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" // // XXX THIS IS TEMPORARY CODE @@ -767,10 +767,10 @@ nsHTMLFragmentContentSink::AddText(const nsAReadableString& aString) return rv; } } - mTextLength += nsLayoutUtils::CopyNewlineNormalizedUnicodeTo(aString, - offset, - &mText[mTextLength], - amount); + mTextLength += + nsContentUtils::CopyNewlineNormalizedUnicodeTo(aString, offset, + &mText[mTextLength], + amount); offset += amount; addLen -= amount; } diff --git a/mozilla/content/html/document/src/nsMarkupDocument.cpp b/mozilla/content/html/document/src/nsMarkupDocument.cpp index b8db4f96425..6f78159aed4 100644 --- a/mozilla/content/html/document/src/nsMarkupDocument.cpp +++ b/mozilla/content/html/document/src/nsMarkupDocument.cpp @@ -25,8 +25,9 @@ #include "nsMarkupDocument.h" #include "nsIURL.h" - +#include "nsLayoutCID.h" #include "nsIPresShell.h" +static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); nsMarkupDocument::nsMarkupDocument() : nsDocument() @@ -38,8 +39,6 @@ nsMarkupDocument::~nsMarkupDocument() } // XXX Temp hack: moved from nsDocument to fix circular linkage problem... -extern NS_LAYOUT nsresult - NS_NewPresShell(nsIPresShell** aInstancePtrResult); NS_IMETHODIMP nsMarkupDocument::CreateShell(nsIPresContext* aContext, @@ -52,20 +51,20 @@ nsMarkupDocument::CreateShell(nsIPresContext* aContext, return NS_ERROR_NULL_POINTER; } - nsIPresShell* shell; - nsresult rv = NS_NewPresShell(&shell); - if (NS_OK != rv) { + nsresult rv; + nsCOMPtr shell(do_CreateInstance(kPresShellCID,&rv)); + if (NS_FAILED(rv)) { return rv; } if (NS_OK != (rv = shell->Init(this, aContext, aViewManager, aStyleSet))) { - NS_RELEASE(shell); return rv; } // Note: we don't hold a ref to the shell (it holds a ref to us) mPresShells.AppendElement(shell); - *aInstancePtrResult = shell; + *aInstancePtrResult = shell.get(); + NS_ADDREF(*aInstancePtrResult); return NS_OK; } diff --git a/mozilla/content/html/style/src/nsCSSValue.cpp b/mozilla/content/html/style/src/nsCSSValue.cpp index 0ddd9b70e29..be3eb569d20 100644 --- a/mozilla/content/html/style/src/nsCSSValue.cpp +++ b/mozilla/content/html/style/src/nsCSSValue.cpp @@ -22,22 +22,11 @@ #include "nsCSSValue.h" #include "nsString.h" #include "nsCSSProps.h" -#include "nsUnitConversion.h" #include "nsReadableUtils.h" //#include "nsStyleConsts.h" -nsCSSValue::nsCSSValue(nsCSSUnit aUnit) - : mUnit(aUnit) -{ - NS_ASSERTION(aUnit <= eCSSUnit_Normal, "not a valueless unit"); - if (aUnit > eCSSUnit_Normal) { - mUnit = eCSSUnit_Null; - } - mValue.mInt = 0; -} - nsCSSValue::nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit) : mUnit(aUnit) { @@ -107,11 +96,6 @@ nsCSSValue::nsCSSValue(const nsCSSValue& aCopy) } } -nsCSSValue::~nsCSSValue(void) -{ - Reset(); -} - nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy) { Reset(); @@ -159,54 +143,6 @@ PRBool nsCSSValue::operator==(const nsCSSValue& aOther) const return PR_FALSE; } -nscoord nsCSSValue::GetLengthTwips(void) const -{ - NS_ASSERTION(IsFixedLengthUnit(), "not a fixed length unit"); - - if (IsFixedLengthUnit()) { - switch (mUnit) { - case eCSSUnit_Inch: - return NS_INCHES_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Foot: - return NS_FEET_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Mile: - return NS_MILES_TO_TWIPS(mValue.mFloat); - - case eCSSUnit_Millimeter: - return NS_MILLIMETERS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Centimeter: - return NS_CENTIMETERS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Meter: - return NS_METERS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Kilometer: - return NS_KILOMETERS_TO_TWIPS(mValue.mFloat); - - case eCSSUnit_Point: - return NSFloatPointsToTwips(mValue.mFloat); - case eCSSUnit_Pica: - return NS_PICAS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Didot: - return NS_DIDOTS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Cicero: - return NS_CICEROS_TO_TWIPS(mValue.mFloat); - default: - NS_ERROR("should never get here"); - break; - } - } - return 0; -} - -void nsCSSValue::Reset(void) -{ - if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) && - (nsnull != mValue.mString)) { - nsCRT::free(mValue.mString); - } - mUnit = eCSSUnit_Null; - mValue.mInt = 0; -}; - void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit) { NS_ASSERTION((eCSSUnit_Integer == aUnit) || @@ -219,23 +155,6 @@ void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit) } } -void nsCSSValue::SetPercentValue(float aValue) -{ - Reset(); - mUnit = eCSSUnit_Percent; - mValue.mFloat = aValue; -} - -void nsCSSValue::SetFloatValue(float aValue, nsCSSUnit aUnit) -{ - NS_ASSERTION(eCSSUnit_Number <= aUnit, "not a float value"); - Reset(); - if (eCSSUnit_Number <= aUnit) { - mUnit = aUnit; - mValue.mFloat = aValue; - } -} - void nsCSSValue::SetStringValue(const nsAReadableString& aValue, nsCSSUnit aUnit) { diff --git a/mozilla/content/html/style/src/nsCSSValue.h b/mozilla/content/html/style/src/nsCSSValue.h index 0079fc41bcf..6058258dcda 100644 --- a/mozilla/content/html/style/src/nsCSSValue.h +++ b/mozilla/content/html/style/src/nsCSSValue.h @@ -27,6 +27,7 @@ #include "nsString.h" #include "nsCoord.h" #include "nsCSSProps.h" +#include "nsUnitConversion.h" enum nsCSSUnit { @@ -93,20 +94,34 @@ enum nsCSSUnit { class nsCSSValue { public: - nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null); // for valueless units only (null, auto, inherit, none, normal) + // for valueless units only (null, auto, inherit, none, normal) + nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null) + : mUnit(aUnit) + { + NS_ASSERTION(aUnit <= eCSSUnit_Normal, "not a valueless unit"); + if (aUnit > eCSSUnit_Normal) { + mUnit = eCSSUnit_Null; + } + mValue.mInt = 0; + } + nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit); nsCSSValue(float aValue, nsCSSUnit aUnit); nsCSSValue(const nsAReadableString& aValue, nsCSSUnit aUnit); nsCSSValue(nscolor aValue); nsCSSValue(const nsCSSValue& aCopy); - ~nsCSSValue(void); + ~nsCSSValue(void) + { + Reset(); + } + nsCSSValue& operator=(const nsCSSValue& aCopy); PRBool operator==(const nsCSSValue& aOther) const; PRBool operator!=(const nsCSSValue& aOther) const; nsCSSUnit GetUnit(void) const { return mUnit; }; - PRBool IsLengthUnit(void) const + PRBool IsLengthUnit(void) const { return PRBool((eCSSUnit_Inch <= mUnit) && (mUnit <= eCSSUnit_Pixel)); } PRBool IsFixedLengthUnit(void) const { return PRBool((eCSSUnit_Inch <= mUnit) && (mUnit <= eCSSUnit_Cicero)); } @@ -124,12 +139,72 @@ public: float GetFloatValue(void) const; nsAWritableString& GetStringValue(nsAWritableString& aBuffer) const; nscolor GetColorValue(void) const; - nscoord GetLengthTwips(void) const; + nscoord GetLengthTwips(void) const + { + NS_ASSERTION(IsFixedLengthUnit(), "not a fixed length unit"); + + if (IsFixedLengthUnit()) { + switch (mUnit) { + case eCSSUnit_Inch: + return NS_INCHES_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Foot: + return NS_FEET_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Mile: + return NS_MILES_TO_TWIPS(mValue.mFloat); + + case eCSSUnit_Millimeter: + return NS_MILLIMETERS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Centimeter: + return NS_CENTIMETERS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Meter: + return NS_METERS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Kilometer: + return NS_KILOMETERS_TO_TWIPS(mValue.mFloat); + + case eCSSUnit_Point: + return NSFloatPointsToTwips(mValue.mFloat); + case eCSSUnit_Pica: + return NS_PICAS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Didot: + return NS_DIDOTS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Cicero: + return NS_CICEROS_TO_TWIPS(mValue.mFloat); + default: + NS_ERROR("should never get here"); + break; + } + } + return 0; + } + + void Reset(void) // sets to null + { + if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) && + (nsnull != mValue.mString)) { + nsCRT::free(mValue.mString); + } + mUnit = eCSSUnit_Null; + mValue.mInt = 0; + } - void Reset(void); // sets to null void SetIntValue(PRInt32 aValue, nsCSSUnit aUnit); - void SetPercentValue(float aValue); - void SetFloatValue(float aValue, nsCSSUnit aUnit); + void SetPercentValue(float aValue) + { + Reset(); + mUnit = eCSSUnit_Percent; + mValue.mFloat = aValue; + } + + void SetFloatValue(float aValue, nsCSSUnit aUnit) + { + NS_ASSERTION(eCSSUnit_Number <= aUnit, "not a float value"); + Reset(); + if (eCSSUnit_Number <= aUnit) { + mUnit = aUnit; + mValue.mFloat = aValue; + } + } + void SetStringValue(const nsAReadableString& aValue, nsCSSUnit aUnit); void SetColorValue(nscolor aValue); void SetAutoValue(void); diff --git a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp index 1091584bebe..e5a7c9f8cc1 100644 --- a/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsHTMLStyleSheet.cpp @@ -50,18 +50,22 @@ #include "nsIEventStateManager.h" #include "nsIDocument.h" #include "nsHTMLIIDs.h" -#include "nsCSSFrameConstructor.h" +#include "nsICSSFrameConstructor.h" +#include "nsIStyleFrameConstruction.h" #include "nsHTMLParts.h" #include "nsIPresShell.h" #include "nsStyleConsts.h" -#include "nsHTMLContainerFrame.h" #include "nsINameSpaceManager.h" #include "nsLayoutAtoms.h" +#include "nsContentCID.h" +#include "nsLayoutCID.h" #include "nsIStyleSet.h" #include "nsISizeOfHandler.h" static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID); +static NS_DEFINE_CID(kHTMLAttributesCID, NS_HTMLATTRIBUTES_CID); +static NS_DEFINE_CID(kCSSFrameConstructorCID, NS_CSSFRAMECONSTRUCTOR_CID); class HTMLColorRule : public nsIStyleRule { public: @@ -798,16 +802,15 @@ nsresult HTMLStyleSheetImpl::QueryInterface(const nsIID& aIID, if (aIID.Equals(kIStyleFrameConstructionIID)) { // XXX this breaks XPCOM rules since it isn't a proper delegate // This is a temporary method of connecting the constructor for now - nsCSSFrameConstructor* constructor = new nsCSSFrameConstructor(); - if (nsnull != constructor) { - constructor->Init(mDocument); - nsresult result = constructor->QueryInterface(aIID, aInstancePtrResult); - if (NS_FAILED(result)) { - delete constructor; + nsresult result; + nsCOMPtr constructor(do_CreateInstance(kCSSFrameConstructorCID,&result)); + if (NS_SUCCEEDED(result)) { + result = constructor->Init(mDocument); + if (NS_SUCCEEDED(result)) { + result = constructor->QueryInterface(aIID, aInstancePtrResult); } - return result; } - return NS_ERROR_OUT_OF_MEMORY; + return result; } if (aIID.Equals(kISupportsIID)) { *aInstancePtrResult = (void*) this; @@ -1240,7 +1243,9 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute, nsresult result = NS_OK; if (! aAttributes) { - result = NS_NewHTMLAttributes(&aAttributes); + result = nsComponentManager::CreateInstance(kHTMLAttributesCID, nsnull, + NS_GET_IID(nsIHTMLAttributes), + (void**)&aAttributes); } if (aAttributes) { result = aAttributes->SetAttributeFor(aAttribute, aValue, aMappedToStyle, @@ -1259,7 +1264,9 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute, nsresult result = NS_OK; if ((! aAttributes) && (eHTMLUnit_Null != aValue.GetUnit())) { - result = NS_NewHTMLAttributes(&aAttributes); + result = nsComponentManager::CreateInstance(kHTMLAttributesCID, nsnull, + NS_GET_IID(nsIHTMLAttributes), + (void**)&aAttributes); } if (aAttributes) { PRInt32 count; diff --git a/mozilla/content/html/style/src/nsHTMLValue.cpp b/mozilla/content/html/style/src/nsHTMLValue.cpp index 6e7c540d03c..ec0cdc4749d 100644 --- a/mozilla/content/html/style/src/nsHTMLValue.cpp +++ b/mozilla/content/html/style/src/nsHTMLValue.cpp @@ -22,20 +22,9 @@ #include "nsHTMLValue.h" #include "nsString.h" -#include "nsReadableUtils.h" #include "nsCRT.h" #include "nsISizeOfHandler.h" -nsHTMLValue::nsHTMLValue(nsHTMLUnit aUnit) - : mUnit(aUnit) -{ - NS_ASSERTION((aUnit <= eHTMLUnit_Empty), "not a valueless unit"); - if (aUnit > eHTMLUnit_Empty) { - mUnit = eHTMLUnit_Null; - } - mValue.mString = nsnull; -} - nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit) : mUnit(aUnit) { @@ -61,21 +50,6 @@ nsHTMLValue::nsHTMLValue(float aValue) mValue.mFloat = aValue; } -nsHTMLValue::nsHTMLValue(const nsAReadableString& aValue, nsHTMLUnit aUnit) - : mUnit(aUnit) -{ - NS_ASSERTION((eHTMLUnit_String == aUnit) || - (eHTMLUnit_ColorName == aUnit), "not a string value"); - if ((eHTMLUnit_String == aUnit) || - (eHTMLUnit_ColorName == aUnit)) { - mValue.mString = ToNewUnicode(aValue); - } - else { - mUnit = eHTMLUnit_Null; - mValue.mInt = 0; - } -} - nsHTMLValue::nsHTMLValue(nsISupports* aValue) : mUnit(eHTMLUnit_ISupports) { @@ -115,11 +89,6 @@ nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy) } } -nsHTMLValue::~nsHTMLValue(void) -{ - Reset(); -} - nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy) { Reset(); @@ -184,21 +153,6 @@ PRUint32 nsHTMLValue::HashValue(void) const } -void nsHTMLValue::Reset(void) -{ - if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) { - if (nsnull != mValue.mString) { - nsCRT::free(mValue.mString); - } - } - else if (eHTMLUnit_ISupports == mUnit) { - NS_IF_RELEASE(mValue.mISupports); - } - mUnit = eHTMLUnit_Null; - mValue.mString = nsnull; -} - - void nsHTMLValue::SetIntValue(PRInt32 aValue, nsHTMLUnit aUnit) { Reset(); diff --git a/mozilla/content/html/style/src/nsHTMLValue.h b/mozilla/content/html/style/src/nsHTMLValue.h index 1c7ed08306f..95a6eb21a28 100644 --- a/mozilla/content/html/style/src/nsHTMLValue.h +++ b/mozilla/content/html/style/src/nsHTMLValue.h @@ -26,6 +26,7 @@ #include "nsColor.h" #include "nsString.h" #include "nsISupports.h" +#include "nsReadableUtils.h" enum nsHTMLUnit { eHTMLUnit_Null = 0, // (n/a) null unit, value is not specified @@ -45,14 +46,39 @@ enum nsHTMLUnit { class nsHTMLValue { public: - nsHTMLValue(nsHTMLUnit aUnit = eHTMLUnit_Null); + nsHTMLValue(nsHTMLUnit aUnit = eHTMLUnit_Null) : mUnit(aUnit) + { + NS_ASSERTION((aUnit <= eHTMLUnit_Empty), "not a valueless unit"); + if (aUnit > eHTMLUnit_Empty) { + mUnit = eHTMLUnit_Null; + } + mValue.mString = nsnull; + } + nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit); nsHTMLValue(float aValue); - nsHTMLValue(const nsAReadableString& aValue, nsHTMLUnit aUnit = eHTMLUnit_String); + nsHTMLValue(const nsAReadableString& aValue, + nsHTMLUnit aUnit = eHTMLUnit_String) : mUnit(aUnit) + { + NS_ASSERTION((eHTMLUnit_String == aUnit) || + (eHTMLUnit_ColorName == aUnit), "not a string value"); + if ((eHTMLUnit_String == aUnit) || + (eHTMLUnit_ColorName == aUnit)) { + mValue.mString = ToNewUnicode(aValue); + } + else { + mUnit = eHTMLUnit_Null; + mValue.mInt = 0; + } + } + nsHTMLValue(nsISupports* aValue); nsHTMLValue(nscolor aValue); nsHTMLValue(const nsHTMLValue& aCopy); - ~nsHTMLValue(void); + ~nsHTMLValue(void) + { + Reset(); + } nsHTMLValue& operator=(const nsHTMLValue& aCopy); PRBool operator==(const nsHTMLValue& aOther) const; @@ -67,7 +93,19 @@ public: nsISupports* GetISupportsValue(void) const; nscolor GetColorValue(void) const; - void Reset(void); + void Reset(void) { + if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) { + if (nsnull != mValue.mString) { + nsCRT::free(mValue.mString); + } + } + else if (eHTMLUnit_ISupports == mUnit) { + NS_IF_RELEASE(mValue.mISupports); + } + mUnit = eHTMLUnit_Null; + mValue.mString = nsnull; + } + void SetIntValue(PRInt32 aValue, nsHTMLUnit aUnit); void SetPixelValue(PRInt32 aValue); void SetPercentValue(float aValue); diff --git a/mozilla/content/makefile.win b/mozilla/content/makefile.win index 1c8c09dac62..d8bce23fe05 100644 --- a/mozilla/content/makefile.win +++ b/mozilla/content/makefile.win @@ -30,9 +30,6 @@ DIRS= \ events \ xul \ build \ -!if !defined(DISABLE_TESTS) - html\tests \ -!endif $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/content/shared/public/nsHTMLValue.h b/mozilla/content/shared/public/nsHTMLValue.h index 1c7ed08306f..95a6eb21a28 100644 --- a/mozilla/content/shared/public/nsHTMLValue.h +++ b/mozilla/content/shared/public/nsHTMLValue.h @@ -26,6 +26,7 @@ #include "nsColor.h" #include "nsString.h" #include "nsISupports.h" +#include "nsReadableUtils.h" enum nsHTMLUnit { eHTMLUnit_Null = 0, // (n/a) null unit, value is not specified @@ -45,14 +46,39 @@ enum nsHTMLUnit { class nsHTMLValue { public: - nsHTMLValue(nsHTMLUnit aUnit = eHTMLUnit_Null); + nsHTMLValue(nsHTMLUnit aUnit = eHTMLUnit_Null) : mUnit(aUnit) + { + NS_ASSERTION((aUnit <= eHTMLUnit_Empty), "not a valueless unit"); + if (aUnit > eHTMLUnit_Empty) { + mUnit = eHTMLUnit_Null; + } + mValue.mString = nsnull; + } + nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit); nsHTMLValue(float aValue); - nsHTMLValue(const nsAReadableString& aValue, nsHTMLUnit aUnit = eHTMLUnit_String); + nsHTMLValue(const nsAReadableString& aValue, + nsHTMLUnit aUnit = eHTMLUnit_String) : mUnit(aUnit) + { + NS_ASSERTION((eHTMLUnit_String == aUnit) || + (eHTMLUnit_ColorName == aUnit), "not a string value"); + if ((eHTMLUnit_String == aUnit) || + (eHTMLUnit_ColorName == aUnit)) { + mValue.mString = ToNewUnicode(aValue); + } + else { + mUnit = eHTMLUnit_Null; + mValue.mInt = 0; + } + } + nsHTMLValue(nsISupports* aValue); nsHTMLValue(nscolor aValue); nsHTMLValue(const nsHTMLValue& aCopy); - ~nsHTMLValue(void); + ~nsHTMLValue(void) + { + Reset(); + } nsHTMLValue& operator=(const nsHTMLValue& aCopy); PRBool operator==(const nsHTMLValue& aOther) const; @@ -67,7 +93,19 @@ public: nsISupports* GetISupportsValue(void) const; nscolor GetColorValue(void) const; - void Reset(void); + void Reset(void) { + if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) { + if (nsnull != mValue.mString) { + nsCRT::free(mValue.mString); + } + } + else if (eHTMLUnit_ISupports == mUnit) { + NS_IF_RELEASE(mValue.mISupports); + } + mUnit = eHTMLUnit_Null; + mValue.mString = nsnull; + } + void SetIntValue(PRInt32 aValue, nsHTMLUnit aUnit); void SetPixelValue(PRInt32 aValue); void SetPercentValue(float aValue); diff --git a/mozilla/content/shared/public/nsTextFragment.h b/mozilla/content/shared/public/nsTextFragment.h index 52ccecd4763..5c3e7bea3a0 100644 --- a/mozilla/content/shared/public/nsTextFragment.h +++ b/mozilla/content/shared/public/nsTextFragment.h @@ -24,7 +24,9 @@ #include "nslayout.h" #include "nsAWritableString.h" -class nsString; +#include "nsCRT.h" +#include "nsString.h" +#include "nsMemory.h" // XXX should this normalize the code to keep a \u0000 at the end? @@ -65,7 +67,9 @@ public: mAllBits = 0; } - ~nsTextFragment(); + ~nsTextFragment() { + ReleaseText(); + } /** * Initialize the contents of this fragment to be a copy of @@ -83,7 +87,10 @@ public: * Initialize the contents of this fragment to be a copy of * the argument ucs2 string. */ - nsTextFragment(const PRUnichar* aString); + nsTextFragment(const PRUnichar* aString) : m1b(nsnull), mAllBits(0) { + SetTo(aString, nsCRT::strlen(aString)); + } + /** * Initialize the contents of this fragment to be a copy of @@ -177,7 +184,55 @@ public: * buffer. Like operator= except a length is specified instead of * assuming 0 termination. */ - void SetTo(const PRUnichar* aBuffer, PRInt32 aLength); + void SetTo(const PRUnichar* aBuffer, PRInt32 aLength) { + ReleaseText(); + if (0 != aLength) { + // See if we need to store the data in ucs2 or not + PRBool need2 = PR_FALSE; + const PRUnichar* ucp = aBuffer; + const PRUnichar* uend = aBuffer + aLength; + while (ucp < uend) { + PRUnichar ch = *ucp++; + if (ch >> 8) { + need2 = PR_TRUE; + break; + } + } + + if (need2) { + // Use ucs2 storage because we have to + PRUnichar* nt = (PRUnichar*)nsMemory::Alloc(aLength*sizeof(PRUnichar)); + if (nsnull != nt) { + // Copy data + nsCRT::memcpy(nt, aBuffer, sizeof(PRUnichar) * aLength); + + // Setup our fields + m2b = nt; + mState.mIs2b = 1; + mState.mInHeap = 1; + mState.mLength = aLength; + } + } + else { + // Use 1 byte storage because we can + unsigned char* nt = (unsigned char*)nsMemory::Alloc(aLength*sizeof(unsigned char)); + if (nsnull != nt) { + // Copy data + unsigned char* cp = nt; + unsigned char* end = nt + aLength; + while (cp < end) { + *cp++ = (unsigned char) *aBuffer++; + } + + // Setup our fields + m1b = nt; + mState.mIs2b = 0; + mState.mInHeap = 1; + mState.mLength = aLength; + } + } + } + } /** * Change the contents of this fragment to be a copy of the given @@ -189,7 +244,14 @@ public: /** * Append the contents of this string fragment to aString */ - void AppendTo(nsString& aString) const; + void AppendTo(nsString& aString) const { + if (mState.mIs2b) { + aString.Append(m2b, mState.mLength); + } + else { + aString.AppendWithConversion((char*)m1b, mState.mLength); + } + } /** * Make a copy of the fragments contents starting at offset for @@ -235,7 +297,20 @@ protected: FragmentBits mState; }; - void ReleaseText(); + void ReleaseText() { + if (mState.mLength && m1b && mState.mInHeap) { + if (mState.mIs2b) { + nsMemory::Free(m2b); + } + else { + nsMemory::Free(m1b); + } + } + m1b = nsnull; + mState.mIs2b = 0; + mState.mInHeap = 0; + mState.mLength = 0; + } }; #endif /* nsTextFragment_h___ */ diff --git a/mozilla/content/shared/src/nsHTMLValue.cpp b/mozilla/content/shared/src/nsHTMLValue.cpp index 6e7c540d03c..ec0cdc4749d 100644 --- a/mozilla/content/shared/src/nsHTMLValue.cpp +++ b/mozilla/content/shared/src/nsHTMLValue.cpp @@ -22,20 +22,9 @@ #include "nsHTMLValue.h" #include "nsString.h" -#include "nsReadableUtils.h" #include "nsCRT.h" #include "nsISizeOfHandler.h" -nsHTMLValue::nsHTMLValue(nsHTMLUnit aUnit) - : mUnit(aUnit) -{ - NS_ASSERTION((aUnit <= eHTMLUnit_Empty), "not a valueless unit"); - if (aUnit > eHTMLUnit_Empty) { - mUnit = eHTMLUnit_Null; - } - mValue.mString = nsnull; -} - nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit) : mUnit(aUnit) { @@ -61,21 +50,6 @@ nsHTMLValue::nsHTMLValue(float aValue) mValue.mFloat = aValue; } -nsHTMLValue::nsHTMLValue(const nsAReadableString& aValue, nsHTMLUnit aUnit) - : mUnit(aUnit) -{ - NS_ASSERTION((eHTMLUnit_String == aUnit) || - (eHTMLUnit_ColorName == aUnit), "not a string value"); - if ((eHTMLUnit_String == aUnit) || - (eHTMLUnit_ColorName == aUnit)) { - mValue.mString = ToNewUnicode(aValue); - } - else { - mUnit = eHTMLUnit_Null; - mValue.mInt = 0; - } -} - nsHTMLValue::nsHTMLValue(nsISupports* aValue) : mUnit(eHTMLUnit_ISupports) { @@ -115,11 +89,6 @@ nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy) } } -nsHTMLValue::~nsHTMLValue(void) -{ - Reset(); -} - nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy) { Reset(); @@ -184,21 +153,6 @@ PRUint32 nsHTMLValue::HashValue(void) const } -void nsHTMLValue::Reset(void) -{ - if ((eHTMLUnit_String == mUnit) || (eHTMLUnit_ColorName == mUnit)) { - if (nsnull != mValue.mString) { - nsCRT::free(mValue.mString); - } - } - else if (eHTMLUnit_ISupports == mUnit) { - NS_IF_RELEASE(mValue.mISupports); - } - mUnit = eHTMLUnit_Null; - mValue.mString = nsnull; -} - - void nsHTMLValue::SetIntValue(PRInt32 aValue, nsHTMLUnit aUnit) { Reset(); diff --git a/mozilla/content/shared/src/nsTextFragment.cpp b/mozilla/content/shared/src/nsTextFragment.cpp index fad38cd3065..6400a43e619 100644 --- a/mozilla/content/shared/src/nsTextFragment.cpp +++ b/mozilla/content/shared/src/nsTextFragment.cpp @@ -20,32 +20,7 @@ * Contributor(s): */ #include "nsTextFragment.h" -#include "nsString.h" -#include "nsCRT.h" #include "nsReadableUtils.h" -#include "nsMemory.h" - -nsTextFragment::~nsTextFragment() -{ - ReleaseText(); -} - -void -nsTextFragment::ReleaseText() -{ - if (mState.mLength && m1b && mState.mInHeap) { - if (mState.mIs2b) { - nsMemory::Free(m2b); - } - else { - nsMemory::Free(m1b); - } - } - m1b = nsnull; - mState.mIs2b = 0; - mState.mInHeap = 0; - mState.mLength = 0; -} nsTextFragment::nsTextFragment(const nsTextFragment& aOther) : m1b(nsnull), @@ -66,13 +41,6 @@ nsTextFragment::nsTextFragment(const char* aString) SetTo(aString, strlen(aString)); } -nsTextFragment::nsTextFragment(const PRUnichar* aString) - : m1b(nsnull), - mAllBits(0) -{ - SetTo(aString, nsCRT::strlen(aString)); -} - nsTextFragment::nsTextFragment(const nsString& aString) : m1b(nsnull), mAllBits(0) @@ -139,58 +107,6 @@ nsTextFragment::SetTo(PRUnichar* aBuffer, PRInt32 aLength, PRBool aRelease) mState.mLength = aLength; } -void -nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength) -{ - ReleaseText(); - if (0 != aLength) { - // See if we need to store the data in ucs2 or not - PRBool need2 = PR_FALSE; - const PRUnichar* ucp = aBuffer; - const PRUnichar* uend = aBuffer + aLength; - while (ucp < uend) { - PRUnichar ch = *ucp++; - if (ch >> 8) { - need2 = PR_TRUE; - break; - } - } - - if (need2) { - // Use ucs2 storage because we have to - PRUnichar* nt = (PRUnichar*)nsMemory::Alloc(aLength*sizeof(PRUnichar)); - if (nsnull != nt) { - // Copy data - nsCRT::memcpy(nt, aBuffer, sizeof(PRUnichar) * aLength); - - // Setup our fields - m2b = nt; - mState.mIs2b = 1; - mState.mInHeap = 1; - mState.mLength = aLength; - } - } - else { - // Use 1 byte storage because we can - unsigned char* nt = (unsigned char*)nsMemory::Alloc(aLength*sizeof(unsigned char)); - if (nsnull != nt) { - // Copy data - unsigned char* cp = nt; - unsigned char* end = nt + aLength; - while (cp < end) { - *cp++ = (unsigned char) *aBuffer++; - } - - // Setup our fields - m1b = nt; - mState.mIs2b = 0; - mState.mInHeap = 1; - mState.mLength = aLength; - } - } - } -} - void nsTextFragment::SetTo(const char* aBuffer, PRInt32 aLength) { @@ -208,17 +124,6 @@ nsTextFragment::SetTo(const char* aBuffer, PRInt32 aLength) } } -void -nsTextFragment::AppendTo(nsString& aString) const -{ - if (mState.mIs2b) { - aString.Append(m2b, mState.mLength); - } - else { - aString.AppendWithConversion((char*)m1b, mState.mLength); - } -} - void nsTextFragment::CopyTo(PRUnichar* aDest, PRInt32 aOffset, PRInt32 aCount) { diff --git a/mozilla/content/xbl/src/Makefile.in b/mozilla/content/xbl/src/Makefile.in index cd2be319194..a740797d91f 100644 --- a/mozilla/content/xbl/src/Makefile.in +++ b/mozilla/content/xbl/src/Makefile.in @@ -27,7 +27,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = layout -LIBRARY_NAME = gkxbl_s +LIBRARY_NAME = gkconxbl_s REQUIRES = xpcom js dom widget caps locale htmlparser necko rdf xpconnect pref docshell uriloader chrome lwbrk CPPSRCS = \ diff --git a/mozilla/content/xbl/src/makefile.win b/mozilla/content/xbl/src/makefile.win index 60b6936a33c..0d002c7e42c 100644 --- a/mozilla/content/xbl/src/makefile.win +++ b/mozilla/content/xbl/src/makefile.win @@ -21,7 +21,7 @@ DEPTH=..\..\.. -LIBRARY_NAME=raptorxbl_s +LIBRARY_NAME=contentxbl_s MODULE=raptor DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN diff --git a/mozilla/content/xbl/src/nsBindingManager.cpp b/mozilla/content/xbl/src/nsBindingManager.cpp index c55a47e3f0b..43ae1d4817b 100644 --- a/mozilla/content/xbl/src/nsBindingManager.cpp +++ b/mozilla/content/xbl/src/nsBindingManager.cpp @@ -40,7 +40,7 @@ #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsIXMLContentSink.h" -#include "nsLayoutCID.h" +#include "nsContentCID.h" #include "nsXMLDocument.h" #include "nsHTMLAtoms.h" #include "nsSupportsArray.h" diff --git a/mozilla/content/xbl/src/nsXBLBinding.cpp b/mozilla/content/xbl/src/nsXBLBinding.cpp index 1b5dd2a8886..32e41fd38ef 100644 --- a/mozilla/content/xbl/src/nsXBLBinding.cpp +++ b/mozilla/content/xbl/src/nsXBLBinding.cpp @@ -42,7 +42,7 @@ #include "nsIXMLContent.h" #include "nsIXULContent.h" #include "nsIXMLContentSink.h" -#include "nsLayoutCID.h" +#include "nsContentCID.h" #include "nsXMLDocument.h" #include "nsIDOMElement.h" #include "nsIDOMText.h" diff --git a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp index a886ddf7714..4aaff0084ea 100644 --- a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -40,7 +40,7 @@ #include "nsIXMLContent.h" #include "nsIXULContent.h" #include "nsIXMLContentSink.h" -#include "nsLayoutCID.h" +#include "nsContentCID.h" #include "nsXMLDocument.h" #include "nsIDOMElement.h" #include "nsIDOMText.h" diff --git a/mozilla/content/xbl/src/nsXBLService.cpp b/mozilla/content/xbl/src/nsXBLService.cpp index 2119b7ef260..ace03aa71b3 100644 --- a/mozilla/content/xbl/src/nsXBLService.cpp +++ b/mozilla/content/xbl/src/nsXBLService.cpp @@ -48,7 +48,7 @@ #include "nsIDOMElement.h" #include "nsIDocument.h" #include "nsIXMLContentSink.h" -#include "nsLayoutCID.h" +#include "nsContentCID.h" #include "nsXMLDocument.h" #include "nsHTMLAtoms.h" #include "nsSupportsArray.h" diff --git a/mozilla/content/xml/content/src/Makefile.in b/mozilla/content/xml/content/src/Makefile.in index 7c9894e2fae..123a017ad9a 100644 --- a/mozilla/content/xml/content/src/Makefile.in +++ b/mozilla/content/xml/content/src/Makefile.in @@ -27,7 +27,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = layout -LIBRARY_NAME = gkxmlcon_s +LIBRARY_NAME = gkconxmlcon_s REQUIRES = xpcom js dom widget locale necko caps webshell docshell htmlparser view uriloader CPPSRCS = \ diff --git a/mozilla/content/xml/content/src/makefile.win b/mozilla/content/xml/content/src/makefile.win index 605bae1c664..ed4674d7277 100644 --- a/mozilla/content/xml/content/src/makefile.win +++ b/mozilla/content/xml/content/src/makefile.win @@ -21,7 +21,7 @@ DEPTH=..\..\..\.. -LIBRARY_NAME=raptorxmlcontent_s +LIBRARY_NAME=contentxmlcontent_s MODULE=raptor DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN diff --git a/mozilla/content/xml/document/src/Makefile.in b/mozilla/content/xml/document/src/Makefile.in index 1254cc04393..bb02ee1d668 100644 --- a/mozilla/content/xml/document/src/Makefile.in +++ b/mozilla/content/xml/document/src/Makefile.in @@ -27,7 +27,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = layout -LIBRARY_NAME = gkxmldoc_s +LIBRARY_NAME = gkconxmldoc_s REQUIRES = xpcom js dom locale widget caps htmlparser necko view docshell webshell uriloader pref xpconnect uconv chardet expat lwbrk CPPSRCS = \ diff --git a/mozilla/content/xml/document/src/makefile.win b/mozilla/content/xml/document/src/makefile.win index 3640928306c..ab07635e252 100644 --- a/mozilla/content/xml/document/src/makefile.win +++ b/mozilla/content/xml/document/src/makefile.win @@ -21,7 +21,7 @@ DEPTH=..\..\..\.. -LIBRARY_NAME=raptorxmldoc_s +LIBRARY_NAME=contentxmldoc_s MODULE=raptor DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index 3babaa8bd8d..ccf919ab43b 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -56,9 +56,9 @@ #include "nsICSSStyleSheet.h" #include "nsIHTMLContentContainer.h" #include "nsHTMLAtoms.h" -#include "nsLayoutUtils.h" +#include "nsContentUtils.h" #include "nsLayoutAtoms.h" -#include "nsLayoutCID.h" +#include "nsContentCID.h" #include "nsIScriptContext.h" #include "nsINameSpace.h" #include "nsINameSpaceManager.h" @@ -994,17 +994,6 @@ nsresult nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl, const nsString& aType) { nsresult rv = NS_OK; - nsCOMPtr parser; - - static NS_DEFINE_CID(kCParserCID, NS_PARSER_IID); - - // Create the XML parser - rv = nsComponentManager::CreateInstance(kCParserCID, - nsnull, - NS_GET_IID(nsIParser), - getter_AddRefs(parser)); - - if (NS_FAILED(rv)) return rv; // Create a transform mediator rv = NS_NewTransformMediator(getter_AddRefs(mXSLTransformMediator), aType); @@ -1013,6 +1002,12 @@ nsXMLContentSink::LoadXSLStyleSheet(nsIURI* aUrl, const nsString& aType) return NS_OK; } + static NS_DEFINE_CID(kCParserCID, NS_PARSER_IID); + + // Create the XML parser + nsCOMPtr parser(do_CreateInstance(kCParserCID, &rv)); + if (NS_FAILED(rv)) return rv; + // Enable the transform mediator. It will start the transform // as soon as it has enough state to do so. The state needed is // the source content model, the style content model, the current @@ -1366,10 +1361,10 @@ nsXMLContentSink::AddText(const nsAReadableString& aString) } } } - mTextLength += nsLayoutUtils::CopyNewlineNormalizedUnicodeTo(aString, - offset, - &mText[mTextLength], - amount); + mTextLength += + nsContentUtils::CopyNewlineNormalizedUnicodeTo(aString, offset, + &mText[mTextLength], + amount); offset += amount; addLen -= amount; } diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index b3533b20968..c6f85d09db3 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -73,13 +73,12 @@ #include "nsScriptSecurityManager.h" #include "nsIPrincipal.h" #include "nsIAggregatePrincipal.h" - +#include "nsLayoutCID.h" +#include "nsContentCID.h" +static NS_DEFINE_CID(kHTMLStyleSheetCID,NS_HTMLSTYLESHEET_CID); // XXX The XML world depends on the html atoms #include "nsHTMLAtoms.h" -#ifdef INCLUDE_XUL -#include "nsXULAtoms.h" -#endif #define DETECTOR_CONTRACTID_MAX 127 static char g_detector_contractid[DETECTOR_CONTRACTID_MAX + 1]; @@ -441,10 +440,9 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand, static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); - rv = nsComponentManager::CreateInstance(kCParserCID, - nsnull, - NS_GET_IID(nsIParser), - (void **)&mParser); + rv = nsComponentManager::CreateInstance(kCParserCID, nsnull, + NS_GET_IID(nsIParser), + (void **)&mParser); if (NS_OK == rv) { nsIXMLContentSink* sink; @@ -1025,7 +1023,14 @@ nsXMLDocument::SetDefaultStylesheets(nsIURI* aUrl) { nsresult result = NS_OK; if (aUrl) { - result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this); + //result = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this); + result = nsComponentManager::CreateInstance(kHTMLStyleSheetCID,nsnull,NS_GET_IID(nsIHTMLStyleSheet),(void**)&mAttrStyleSheet); + if (NS_SUCCEEDED(result)) { + result = mAttrStyleSheet->Init(aUrl,this); + if (NS_FAILED(result)) { + NS_RELEASE(mAttrStyleSheet); + } + } if (NS_OK == result) { AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet diff --git a/mozilla/content/xsl/document/src/Makefile.in b/mozilla/content/xsl/document/src/Makefile.in index b3349827ed8..14d75b2bb22 100755 --- a/mozilla/content/xsl/document/src/Makefile.in +++ b/mozilla/content/xsl/document/src/Makefile.in @@ -23,7 +23,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = layout -LIBRARY_NAME = gkxsldoc_s +LIBRARY_NAME = gkconxsldoc_s REQUIRES = xpcom htmlparser view widget dom locale necko include $(topsrcdir)/config/config.mk diff --git a/mozilla/content/xsl/document/src/makefile.win b/mozilla/content/xsl/document/src/makefile.win index 751c190e62e..5dac028736d 100644 --- a/mozilla/content/xsl/document/src/makefile.win +++ b/mozilla/content/xsl/document/src/makefile.win @@ -21,7 +21,7 @@ DEPTH=..\..\..\.. -LIBRARY_NAME=raptorxsldoc_s +LIBRARY_NAME=contentxsldoc_s MODULE=raptor DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 5c87e374af4..5ff9f354488 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -50,6 +50,7 @@ #include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLElement.h" #include "nsIDOMRange.h" +#include "nsContentCID.h" #include "nsLayoutCID.h" #include "nsHTMLParts.h" @@ -114,6 +115,10 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); #include "nsITransformMediator.h" static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); +static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); +static NS_DEFINE_CID(kGalleyContextCID, NS_GALLEYCONTEXT_CID); +static NS_DEFINE_CID(kPrintContextCID, NS_PRINTCONTEXT_CID); +static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID); #ifdef NS_DEBUG #undef NOISY_VIEWER @@ -541,7 +546,7 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, if (!mPresContext) { // Create presentation context #if 1 - rv = NS_NewGalleyContext(getter_AddRefs(mPresContext)); + mPresContext = do_CreateInstance(kGalleyContextCID,&rv); #else // turn on print preview for debugging until print preview is fixed rv = NS_NewPrintPreviewContext(getter_AddRefs(mPresContext)); #endif @@ -1397,8 +1402,6 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, PRBool doesContainFrameSet; PRBool isIFrameSelection = IsThereAnIFrameSelected(aParent, domWinIntl, doesContainFrameSet); - PRBool isSelection = IsThereASelection(domWinIntl); - // the root webshell is responsible for // starting and ending the printing #if SPOOL_TO_ONE_DOC // this will fix all frames being painted to the same spooling document @@ -1529,8 +1532,7 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, } nsCOMPtr cx; - nsCOMPtr printcon; - rv = NS_NewPrintContext(getter_AddRefs(printcon)); + nsCOMPtr printcon(do_CreateInstance(kPrintContextCID,&rv)); if (NS_FAILED(rv)) { return rv; } else { @@ -1544,8 +1546,7 @@ DocumentViewerImpl::PrintContent(nsIWebShell * aParent, CreateStyleSet(mDocument, getter_AddRefs(ss)); - nsCOMPtr ps; - rv = NS_NewPresShell(getter_AddRefs(ps)); + nsCOMPtr ps(do_CreateInstance(kPresShellCID,&rv)); if (NS_FAILED(rv)) { return rv; } @@ -1856,7 +1857,7 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, NS_WARNING("unable to load UA style sheet"); } - rv = NS_NewStyleSet(aStyleSet); + rv = nsComponentManager::CreateInstance(kStyleSetCID,nsnull,NS_GET_IID(nsIStyleSet),(void**)aStyleSet); if (NS_OK == rv) { PRInt32 index = aDocument->GetNumberOfStyleSheets(); @@ -2436,8 +2437,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi if(webContainer) { // load the document and do the initial reflow on the entire document - nsCOMPtr printcon; - rv = NS_NewPrintContext(getter_AddRefs(printcon)); + nsCOMPtr printcon(do_CreateInstance(kPrintContextCID,&rv)); if (NS_FAILED(rv)) { return rv; } else { @@ -2462,7 +2462,7 @@ DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintLi mPrintPC->SetContainer(webContainer); CreateStyleSet(mDocument,&mPrintSS); - rv = NS_NewPresShell(&mPrintPS); + rv = nsComponentManager::CreateInstance(kPresShellCID, nsnull, NS_GET_IID(nsIPresShell),(void**)&mPrintPS); if(NS_FAILED(rv)){ return rv; } diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index 97e88f6b54e..7e134bfaf3a 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -34,7 +34,7 @@ #include "nsISelectionListener.h" #include "nsIFocusTracker.h" #include "nsIComponentManager.h" -#include "nsLayoutCID.h" +#include "nsContentCID.h" #include "nsIContent.h" #include "nsIDOMElement.h" #include "nsIDOMNode.h" diff --git a/mozilla/layout/style/nsCSSValue.cpp b/mozilla/layout/style/nsCSSValue.cpp index 0ddd9b70e29..be3eb569d20 100644 --- a/mozilla/layout/style/nsCSSValue.cpp +++ b/mozilla/layout/style/nsCSSValue.cpp @@ -22,22 +22,11 @@ #include "nsCSSValue.h" #include "nsString.h" #include "nsCSSProps.h" -#include "nsUnitConversion.h" #include "nsReadableUtils.h" //#include "nsStyleConsts.h" -nsCSSValue::nsCSSValue(nsCSSUnit aUnit) - : mUnit(aUnit) -{ - NS_ASSERTION(aUnit <= eCSSUnit_Normal, "not a valueless unit"); - if (aUnit > eCSSUnit_Normal) { - mUnit = eCSSUnit_Null; - } - mValue.mInt = 0; -} - nsCSSValue::nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit) : mUnit(aUnit) { @@ -107,11 +96,6 @@ nsCSSValue::nsCSSValue(const nsCSSValue& aCopy) } } -nsCSSValue::~nsCSSValue(void) -{ - Reset(); -} - nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy) { Reset(); @@ -159,54 +143,6 @@ PRBool nsCSSValue::operator==(const nsCSSValue& aOther) const return PR_FALSE; } -nscoord nsCSSValue::GetLengthTwips(void) const -{ - NS_ASSERTION(IsFixedLengthUnit(), "not a fixed length unit"); - - if (IsFixedLengthUnit()) { - switch (mUnit) { - case eCSSUnit_Inch: - return NS_INCHES_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Foot: - return NS_FEET_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Mile: - return NS_MILES_TO_TWIPS(mValue.mFloat); - - case eCSSUnit_Millimeter: - return NS_MILLIMETERS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Centimeter: - return NS_CENTIMETERS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Meter: - return NS_METERS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Kilometer: - return NS_KILOMETERS_TO_TWIPS(mValue.mFloat); - - case eCSSUnit_Point: - return NSFloatPointsToTwips(mValue.mFloat); - case eCSSUnit_Pica: - return NS_PICAS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Didot: - return NS_DIDOTS_TO_TWIPS(mValue.mFloat); - case eCSSUnit_Cicero: - return NS_CICEROS_TO_TWIPS(mValue.mFloat); - default: - NS_ERROR("should never get here"); - break; - } - } - return 0; -} - -void nsCSSValue::Reset(void) -{ - if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) && - (nsnull != mValue.mString)) { - nsCRT::free(mValue.mString); - } - mUnit = eCSSUnit_Null; - mValue.mInt = 0; -}; - void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit) { NS_ASSERTION((eCSSUnit_Integer == aUnit) || @@ -219,23 +155,6 @@ void nsCSSValue::SetIntValue(PRInt32 aValue, nsCSSUnit aUnit) } } -void nsCSSValue::SetPercentValue(float aValue) -{ - Reset(); - mUnit = eCSSUnit_Percent; - mValue.mFloat = aValue; -} - -void nsCSSValue::SetFloatValue(float aValue, nsCSSUnit aUnit) -{ - NS_ASSERTION(eCSSUnit_Number <= aUnit, "not a float value"); - Reset(); - if (eCSSUnit_Number <= aUnit) { - mUnit = aUnit; - mValue.mFloat = aValue; - } -} - void nsCSSValue::SetStringValue(const nsAReadableString& aValue, nsCSSUnit aUnit) { diff --git a/mozilla/layout/style/nsCSSValue.h b/mozilla/layout/style/nsCSSValue.h index 0079fc41bcf..6058258dcda 100644 --- a/mozilla/layout/style/nsCSSValue.h +++ b/mozilla/layout/style/nsCSSValue.h @@ -27,6 +27,7 @@ #include "nsString.h" #include "nsCoord.h" #include "nsCSSProps.h" +#include "nsUnitConversion.h" enum nsCSSUnit { @@ -93,20 +94,34 @@ enum nsCSSUnit { class nsCSSValue { public: - nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null); // for valueless units only (null, auto, inherit, none, normal) + // for valueless units only (null, auto, inherit, none, normal) + nsCSSValue(nsCSSUnit aUnit = eCSSUnit_Null) + : mUnit(aUnit) + { + NS_ASSERTION(aUnit <= eCSSUnit_Normal, "not a valueless unit"); + if (aUnit > eCSSUnit_Normal) { + mUnit = eCSSUnit_Null; + } + mValue.mInt = 0; + } + nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit); nsCSSValue(float aValue, nsCSSUnit aUnit); nsCSSValue(const nsAReadableString& aValue, nsCSSUnit aUnit); nsCSSValue(nscolor aValue); nsCSSValue(const nsCSSValue& aCopy); - ~nsCSSValue(void); + ~nsCSSValue(void) + { + Reset(); + } + nsCSSValue& operator=(const nsCSSValue& aCopy); PRBool operator==(const nsCSSValue& aOther) const; PRBool operator!=(const nsCSSValue& aOther) const; nsCSSUnit GetUnit(void) const { return mUnit; }; - PRBool IsLengthUnit(void) const + PRBool IsLengthUnit(void) const { return PRBool((eCSSUnit_Inch <= mUnit) && (mUnit <= eCSSUnit_Pixel)); } PRBool IsFixedLengthUnit(void) const { return PRBool((eCSSUnit_Inch <= mUnit) && (mUnit <= eCSSUnit_Cicero)); } @@ -124,12 +139,72 @@ public: float GetFloatValue(void) const; nsAWritableString& GetStringValue(nsAWritableString& aBuffer) const; nscolor GetColorValue(void) const; - nscoord GetLengthTwips(void) const; + nscoord GetLengthTwips(void) const + { + NS_ASSERTION(IsFixedLengthUnit(), "not a fixed length unit"); + + if (IsFixedLengthUnit()) { + switch (mUnit) { + case eCSSUnit_Inch: + return NS_INCHES_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Foot: + return NS_FEET_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Mile: + return NS_MILES_TO_TWIPS(mValue.mFloat); + + case eCSSUnit_Millimeter: + return NS_MILLIMETERS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Centimeter: + return NS_CENTIMETERS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Meter: + return NS_METERS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Kilometer: + return NS_KILOMETERS_TO_TWIPS(mValue.mFloat); + + case eCSSUnit_Point: + return NSFloatPointsToTwips(mValue.mFloat); + case eCSSUnit_Pica: + return NS_PICAS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Didot: + return NS_DIDOTS_TO_TWIPS(mValue.mFloat); + case eCSSUnit_Cicero: + return NS_CICEROS_TO_TWIPS(mValue.mFloat); + default: + NS_ERROR("should never get here"); + break; + } + } + return 0; + } + + void Reset(void) // sets to null + { + if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) && + (nsnull != mValue.mString)) { + nsCRT::free(mValue.mString); + } + mUnit = eCSSUnit_Null; + mValue.mInt = 0; + } - void Reset(void); // sets to null void SetIntValue(PRInt32 aValue, nsCSSUnit aUnit); - void SetPercentValue(float aValue); - void SetFloatValue(float aValue, nsCSSUnit aUnit); + void SetPercentValue(float aValue) + { + Reset(); + mUnit = eCSSUnit_Percent; + mValue.mFloat = aValue; + } + + void SetFloatValue(float aValue, nsCSSUnit aUnit) + { + NS_ASSERTION(eCSSUnit_Number <= aUnit, "not a float value"); + Reset(); + if (eCSSUnit_Number <= aUnit) { + mUnit = aUnit; + mValue.mFloat = aValue; + } + } + void SetStringValue(const nsAReadableString& aValue, nsCSSUnit aUnit); void SetColorValue(nscolor aValue); void SetAutoValue(void); diff --git a/mozilla/layout/style/nsHTMLStyleSheet.cpp b/mozilla/layout/style/nsHTMLStyleSheet.cpp index 1091584bebe..e5a7c9f8cc1 100644 --- a/mozilla/layout/style/nsHTMLStyleSheet.cpp +++ b/mozilla/layout/style/nsHTMLStyleSheet.cpp @@ -50,18 +50,22 @@ #include "nsIEventStateManager.h" #include "nsIDocument.h" #include "nsHTMLIIDs.h" -#include "nsCSSFrameConstructor.h" +#include "nsICSSFrameConstructor.h" +#include "nsIStyleFrameConstruction.h" #include "nsHTMLParts.h" #include "nsIPresShell.h" #include "nsStyleConsts.h" -#include "nsHTMLContainerFrame.h" #include "nsINameSpaceManager.h" #include "nsLayoutAtoms.h" +#include "nsContentCID.h" +#include "nsLayoutCID.h" #include "nsIStyleSet.h" #include "nsISizeOfHandler.h" static NS_DEFINE_IID(kIStyleFrameConstructionIID, NS_ISTYLE_FRAME_CONSTRUCTION_IID); +static NS_DEFINE_CID(kHTMLAttributesCID, NS_HTMLATTRIBUTES_CID); +static NS_DEFINE_CID(kCSSFrameConstructorCID, NS_CSSFRAMECONSTRUCTOR_CID); class HTMLColorRule : public nsIStyleRule { public: @@ -798,16 +802,15 @@ nsresult HTMLStyleSheetImpl::QueryInterface(const nsIID& aIID, if (aIID.Equals(kIStyleFrameConstructionIID)) { // XXX this breaks XPCOM rules since it isn't a proper delegate // This is a temporary method of connecting the constructor for now - nsCSSFrameConstructor* constructor = new nsCSSFrameConstructor(); - if (nsnull != constructor) { - constructor->Init(mDocument); - nsresult result = constructor->QueryInterface(aIID, aInstancePtrResult); - if (NS_FAILED(result)) { - delete constructor; + nsresult result; + nsCOMPtr constructor(do_CreateInstance(kCSSFrameConstructorCID,&result)); + if (NS_SUCCEEDED(result)) { + result = constructor->Init(mDocument); + if (NS_SUCCEEDED(result)) { + result = constructor->QueryInterface(aIID, aInstancePtrResult); } - return result; } - return NS_ERROR_OUT_OF_MEMORY; + return result; } if (aIID.Equals(kISupportsIID)) { *aInstancePtrResult = (void*) this; @@ -1240,7 +1243,9 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute, nsresult result = NS_OK; if (! aAttributes) { - result = NS_NewHTMLAttributes(&aAttributes); + result = nsComponentManager::CreateInstance(kHTMLAttributesCID, nsnull, + NS_GET_IID(nsIHTMLAttributes), + (void**)&aAttributes); } if (aAttributes) { result = aAttributes->SetAttributeFor(aAttribute, aValue, aMappedToStyle, @@ -1259,7 +1264,9 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute, nsresult result = NS_OK; if ((! aAttributes) && (eHTMLUnit_Null != aValue.GetUnit())) { - result = NS_NewHTMLAttributes(&aAttributes); + result = nsComponentManager::CreateInstance(kHTMLAttributesCID, nsnull, + NS_GET_IID(nsIHTMLAttributes), + (void**)&aAttributes); } if (aAttributes) { PRInt32 count; diff --git a/mozilla/layout/style/nsStyleContext.cpp b/mozilla/layout/style/nsStyleContext.cpp index 573da0dfd00..cc960666fa2 100644 --- a/mozilla/layout/style/nsStyleContext.cpp +++ b/mozilla/layout/style/nsStyleContext.cpp @@ -44,8 +44,6 @@ #include "nsISupportsArray.h" #include "nsCRT.h" -#include "nsIFrame.h" - #include "nsCOMPtr.h" #include "nsIStyleSet.h" #include "nsISizeOfHandler.h" @@ -54,8 +52,6 @@ #include "prenv.h" -#define DELETE_ARRAY_IF(array) if (array) { delete[] array; array = nsnull; } - #ifdef DEBUG // #define NOISY_DEBUG #endif @@ -104,26 +100,6 @@ static nscoord CalcCoord(const nsStyleCoord& aCoord, const nscoord* aEnumTable, PRInt32 aNumEnums); -// XXX this is here to support deprecated calc spacing methods only -static nscoord kBorderWidths[3]; // contain the twips values for thin, medium and thick -static void InitBorderWidths(nsIPresContext* aPresContext) -{ - // XXX support kBorderWidhts until deprecated methods are removed - static PRBool kWidthsInitialized = PR_FALSE; - if (! kWidthsInitialized) { - kWidthsInitialized = PR_TRUE; - - float pixelsToTwips = 20.0f; - if (aPresContext) { - aPresContext->GetPixelsToTwips(&pixelsToTwips); - } - kBorderWidths[NS_STYLE_BORDER_WIDTH_THIN] = NSIntPixelsToTwips(1, pixelsToTwips); - kBorderWidths[NS_STYLE_BORDER_WIDTH_MEDIUM] = NSIntPixelsToTwips(3, pixelsToTwips); - kBorderWidths[NS_STYLE_BORDER_WIDTH_THICK] = NSIntPixelsToTwips(5, pixelsToTwips); - } -} - - // EnsureBlockDisplay: // - if the display value (argument) is not a block-type // then we set it to a valid block display value @@ -133,19 +109,11 @@ static void EnsureBlockDisplay(/*in out*/PRUint8 &display); // -------------------- // nsStyleFont // -nsStyleFont::nsStyleFont(void) - : mFont(nsnull, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE, 0), - mFixedFont(nsnull, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, NS_FONT_DECORATION_NONE, 0) -{} - nsStyleFont::nsStyleFont(const nsFont& aVariableFont, const nsFont& aFixedFont) : mFont(aVariableFont), mFixedFont(aFixedFont) { } -nsStyleFont::~nsStyleFont(void) { } - - struct StyleFontImpl : public nsStyleFont { StyleFontImpl(const nsFont& aVariableFont, const nsFont& aFixedFont) : nsStyleFont(aVariableFont, aFixedFont) @@ -248,8 +216,6 @@ PRUint32 StyleFontImpl::ComputeCRC32(PRUint32 aCrc) const // -------------------- // nsStyleColor // -nsStyleColor::nsStyleColor(void) { } -nsStyleColor::~nsStyleColor(void) { } struct StyleColorImpl: public nsStyleColor { StyleColorImpl(void) { } @@ -377,127 +343,6 @@ PRUint32 StyleColorImpl::ComputeCRC32(PRUint32 aCrc) const #pragma mark - #endif -#define BORDER_COLOR_DEFINED 0x80 -#define BORDER_COLOR_SPECIAL 0x40 -#define BORDER_STYLE_MASK 0x3F - -#define NS_SPACING_MARGIN 0 -#define NS_SPACING_PADDING 1 -#define NS_SPACING_BORDER 2 - -static nscoord CalcSideFor(const nsIFrame* aFrame, const nsStyleCoord& aCoord, - PRUint8 aSpacing, PRUint8 aSide, - const nscoord* aEnumTable, PRInt32 aNumEnums) -{ - nscoord result = 0; - - switch (aCoord.GetUnit()) { - case eStyleUnit_Auto: - // Auto margins are handled by layout - break; - - case eStyleUnit_Inherit: - nsIFrame* parentFrame; - aFrame->GetParent(&parentFrame); // XXX may not be direct parent... - if (nsnull != parentFrame) { - nsIStyleContext* parentContext; - parentFrame->GetStyleContext(&parentContext); - if (nsnull != parentContext) { - nsMargin parentSide; - switch (aSpacing) { - case NS_SPACING_MARGIN: { - const nsStyleMargin* parentMargin = (const nsStyleMargin*)parentContext->GetStyleData(eStyleStruct_Margin); - parentMargin->CalcMarginFor(parentFrame, parentSide); - break; - } - case NS_SPACING_PADDING: { - const nsStylePadding* parentPadding = (const nsStylePadding*)parentContext->GetStyleData(eStyleStruct_Padding); - parentPadding->CalcPaddingFor(parentFrame, parentSide); - break; - } - case NS_SPACING_BORDER: { - const nsStyleBorder* parentBorder = (const nsStyleBorder*)parentContext->GetStyleData(eStyleStruct_Border); - parentBorder->CalcBorderFor(parentFrame, parentSide); - break; - } - } - switch (aSide) { - case NS_SIDE_LEFT: result = parentSide.left; break; - case NS_SIDE_TOP: result = parentSide.top; break; - case NS_SIDE_RIGHT: result = parentSide.right; break; - case NS_SIDE_BOTTOM: result = parentSide.bottom; break; - } - NS_RELEASE(parentContext); - } - } - break; - - case eStyleUnit_Percent: - { - nscoord baseWidth = 0; - PRBool isBase = PR_FALSE; - nsIFrame* frame; - aFrame->GetParent(&frame); - while (nsnull != frame) { - frame->IsPercentageBase(isBase); - if (isBase) { - nsSize size; - frame->GetSize(size); - baseWidth = size.width; // not really width, need to subtract out padding... - break; - } - frame->GetParent(&frame); - } - result = (nscoord)((float)baseWidth * aCoord.GetPercentValue()); - } - break; - - case eStyleUnit_Coord: - result = aCoord.GetCoordValue(); - break; - - case eStyleUnit_Enumerated: - if (nsnull != aEnumTable) { - PRInt32 value = aCoord.GetIntValue(); - if ((0 <= value) && (value < aNumEnums)) { - return aEnumTable[aCoord.GetIntValue()]; - } - } - break; - - case eStyleUnit_Null: - case eStyleUnit_Normal: - case eStyleUnit_Integer: - case eStyleUnit_Proportional: - default: - result = 0; - break; - } - if ((NS_SPACING_PADDING == aSpacing) || (NS_SPACING_BORDER == aSpacing)) { - if (result < 0) { - result = 0; - } - } - return result; -} - -static void CalcSidesFor(const nsIFrame* aFrame, const nsStyleSides& aSides, - PRUint8 aSpacing, - const nscoord* aEnumTable, PRInt32 aNumEnums, - nsMargin& aResult) -{ - nsStyleCoord coord; - - aResult.left = CalcSideFor(aFrame, aSides.GetLeft(coord), aSpacing, NS_SIDE_LEFT, - aEnumTable, aNumEnums); - aResult.top = CalcSideFor(aFrame, aSides.GetTop(coord), aSpacing, NS_SIDE_TOP, - aEnumTable, aNumEnums); - aResult.right = CalcSideFor(aFrame, aSides.GetRight(coord), aSpacing, NS_SIDE_RIGHT, - aEnumTable, aNumEnums); - aResult.bottom = CalcSideFor(aFrame, aSides.GetBottom(coord), aSpacing, NS_SIDE_BOTTOM, - aEnumTable, aNumEnums); -} - static PRBool IsFixedData(const nsStyleSides& aSides, PRBool aEnumOK) { return PRBool(IsFixedUnit(aSides.GetLeftUnit(), aEnumOK) && @@ -535,27 +380,6 @@ static nscoord CalcCoord(const nsStyleCoord& aCoord, #pragma mark - #endif -nsStyleMargin::nsStyleMargin(void) { } -nsStyleMargin::~nsStyleMargin(void) { } - -PRBool nsStyleMargin::GetMargin(nsMargin& aMargin) const -{ - if (mHasCachedMargin) { - aMargin = mCachedMargin; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStyleMargin::CalcMarginFor(const nsIFrame* aFrame, nsMargin& aMargin) const -{ - if (mHasCachedMargin) { - aMargin = mCachedMargin; - } else { - CalcSidesFor(aFrame, mMargin, NS_SPACING_MARGIN, nsnull, 0, aMargin); - } -} - struct StyleMarginImpl: public nsStyleMargin { StyleMarginImpl(void) : nsStyleMargin() @@ -631,27 +455,6 @@ PRUint32 StyleMarginImpl::ComputeCRC32(PRUint32 aCrc) const #pragma mark - #endif -nsStylePadding::nsStylePadding(void) { } -nsStylePadding::~nsStylePadding(void) { } - -PRBool nsStylePadding::GetPadding(nsMargin& aPadding) const -{ - if (mHasCachedPadding) { - aPadding = mCachedPadding; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStylePadding::CalcPaddingFor(const nsIFrame* aFrame, nsMargin& aPadding) const -{ - if (mHasCachedPadding) { - aPadding = mCachedPadding; - } else { - CalcSidesFor(aFrame, mPadding, NS_SPACING_PADDING, nsnull, 0, aPadding); - } -} - struct StylePaddingImpl: public nsStylePadding { StylePaddingImpl(void) : nsStylePadding() @@ -727,94 +530,9 @@ PRUint32 StylePaddingImpl::ComputeCRC32(PRUint32 aCrc) const #pragma mark - #endif -nsStyleBorderPadding::nsStyleBorderPadding(void) { mHasCachedBorderPadding = PR_FALSE; } -nsStyleBorderPadding::~nsStyleBorderPadding(void) { } - -PRBool nsStyleBorderPadding::GetBorderPadding(nsMargin& aBorderPadding) const { - if (mHasCachedBorderPadding) { - aBorderPadding = mCachedBorderPadding; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStyleBorderPadding::SetBorderPadding(nsMargin aBorderPadding) { - mCachedBorderPadding = aBorderPadding; - mHasCachedBorderPadding = PR_TRUE; -} - -#ifdef XP_MAC -#pragma mark - -#endif - -nsStyleBorder::nsStyleBorder(void) { } -nsStyleBorder::~nsStyleBorder(void) { } - -PRBool nsStyleBorder::GetBorder(nsMargin& aBorder) const -{ - if (mHasCachedBorder) { - aBorder = mCachedBorder; - return PR_TRUE; - } - return PR_FALSE; -} - -PRUint8 nsStyleBorder::GetBorderStyle(PRUint8 aSide) const -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - return (mBorderStyle[aSide] & BORDER_STYLE_MASK); -} - -void nsStyleBorder::SetBorderStyle(PRUint8 aSide, PRUint8 aStyle) -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - mBorderStyle[aSide] &= ~BORDER_STYLE_MASK; - mBorderStyle[aSide] |= (aStyle & BORDER_STYLE_MASK); - -} - -PRBool nsStyleBorder::GetBorderColor(PRUint8 aSide, nscolor& aColor) const -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - if ((mBorderStyle[aSide] & BORDER_COLOR_SPECIAL) == 0) { - aColor = mBorderColor[aSide]; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStyleBorder::SetBorderColor(PRUint8 aSide, nscolor aColor) -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - mBorderColor[aSide] = aColor; - mBorderStyle[aSide] &= ~BORDER_COLOR_SPECIAL; - mBorderStyle[aSide] |= BORDER_COLOR_DEFINED; -} - -void nsStyleBorder::SetBorderTransparent(PRUint8 aSide) -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - mBorderStyle[aSide] |= (BORDER_COLOR_DEFINED | BORDER_COLOR_SPECIAL); -} - -void nsStyleBorder::UnsetBorderColor(PRUint8 aSide) -{ - NS_ASSERTION(aSide <= NS_SIDE_LEFT, "bad side"); - mBorderStyle[aSide] &= BORDER_STYLE_MASK; -} - -void nsStyleBorder::CalcBorderFor(const nsIFrame* aFrame, nsMargin& aBorder) const -{ - if (mHasCachedBorder) { - aBorder = mCachedBorder; - } else { - CalcSidesFor(aFrame, mBorder, NS_SPACING_BORDER, kBorderWidths, 3, aBorder); - } -} - struct StyleBorderImpl: public nsStyleBorder { StyleBorderImpl(void) - : nsStyleBorder() + : nsStyleBorder(), mWidthsInitialized(PR_FALSE) {} void ResetFrom(const nsStyleBorder* aParent, nsIPresContext* aPresContext); @@ -828,10 +546,25 @@ struct StyleBorderImpl: public nsStyleBorder { private: // These are not allowed StyleBorderImpl(const StyleBorderImpl& aOther); StyleBorderImpl& operator=(const StyleBorderImpl& aOther); + + // XXX remove with deprecated methods + PRBool mWidthsInitialized; }; void StyleBorderImpl::ResetFrom(const nsStyleBorder* aParent, nsIPresContext* aPresContext) { + // XXX support mBorderWidhts until deprecated methods are removed + if (! mWidthsInitialized) { + float pixelsToTwips = 20.0f; + if (aPresContext) { + aPresContext->GetPixelsToTwips(&pixelsToTwips); + } + mBorderWidths[NS_STYLE_BORDER_WIDTH_THIN] = NSIntPixelsToTwips(1, pixelsToTwips); + mBorderWidths[NS_STYLE_BORDER_WIDTH_MEDIUM] = NSIntPixelsToTwips(3, pixelsToTwips); + mBorderWidths[NS_STYLE_BORDER_WIDTH_THICK] = NSIntPixelsToTwips(5, pixelsToTwips); + mWidthsInitialized = PR_TRUE; + } + // spacing values not inherited nsStyleCoord medium(NS_STYLE_BORDER_WIDTH_MEDIUM, eStyleUnit_Enumerated); mBorder.SetLeft(medium); @@ -889,25 +622,25 @@ void StyleBorderImpl::RecalcData(nscolor aColor) mCachedBorder.left = 0; } else { - mCachedBorder.left = CalcCoord(mBorder.GetLeft(coord), kBorderWidths, 3); + mCachedBorder.left = CalcCoord(mBorder.GetLeft(coord), mBorderWidths, 3); } if (!IsBorderSideVisible(NS_SIDE_TOP)) { mCachedBorder.top = 0; } else { - mCachedBorder.top = CalcCoord(mBorder.GetTop(coord), kBorderWidths, 3); + mCachedBorder.top = CalcCoord(mBorder.GetTop(coord), mBorderWidths, 3); } if (!IsBorderSideVisible(NS_SIDE_RIGHT)) { mCachedBorder.right = 0; } else { - mCachedBorder.right = CalcCoord(mBorder.GetRight(coord), kBorderWidths, 3); + mCachedBorder.right = CalcCoord(mBorder.GetRight(coord), mBorderWidths, 3); } if (!IsBorderSideVisible(NS_SIDE_BOTTOM)) { mCachedBorder.bottom = 0; } else { - mCachedBorder.bottom = CalcCoord(mBorder.GetBottom(coord), kBorderWidths, 3); + mCachedBorder.bottom = CalcCoord(mBorder.GetBottom(coord), mBorderWidths, 3); } mHasCachedBorder = PR_TRUE; } @@ -976,53 +709,9 @@ PRUint32 StyleBorderImpl::ComputeCRC32(PRUint32 aCrc) const #pragma mark - #endif -nsStyleOutline::nsStyleOutline(void) { } -nsStyleOutline::~nsStyleOutline(void) { } - -PRBool nsStyleOutline::GetOutlineWidth(nscoord& aWidth) const -{ - if (mHasCachedOutline) { - aWidth = mCachedOutlineWidth; - return PR_TRUE; - } - return PR_FALSE; -} - -PRUint8 nsStyleOutline::GetOutlineStyle(void) const -{ - return (mOutlineStyle & BORDER_STYLE_MASK); -} - -void nsStyleOutline::SetOutlineStyle(PRUint8 aStyle) -{ - mOutlineStyle &= ~BORDER_STYLE_MASK; - mOutlineStyle |= (aStyle & BORDER_STYLE_MASK); -} - -PRBool nsStyleOutline::GetOutlineColor(nscolor& aColor) const -{ - if ((mOutlineStyle & BORDER_COLOR_SPECIAL) == 0) { - aColor = mOutlineColor; - return PR_TRUE; - } - return PR_FALSE; -} - -void nsStyleOutline::SetOutlineColor(nscolor aColor) -{ - mOutlineColor = aColor; - mOutlineStyle &= ~BORDER_COLOR_SPECIAL; - mOutlineStyle |= BORDER_COLOR_DEFINED; -} - -void nsStyleOutline::SetOutlineInvert(void) -{ - mOutlineStyle |= (BORDER_COLOR_DEFINED | BORDER_COLOR_SPECIAL); -} - struct StyleOutlineImpl: public nsStyleOutline { StyleOutlineImpl(void) - : nsStyleOutline() + : nsStyleOutline(), mWidthsInitialized(PR_FALSE) {} void ResetFrom(const nsStyleOutline* aParent, nsIPresContext* aPresContext); @@ -1035,10 +724,25 @@ struct StyleOutlineImpl: public nsStyleOutline { private: // These are not allowed StyleOutlineImpl(const StyleOutlineImpl& aOther); StyleOutlineImpl& operator=(const StyleOutlineImpl& aOther); + + // XXX remove with deprecated methods + PRBool mWidthsInitialized; }; void StyleOutlineImpl::ResetFrom(const nsStyleOutline* aParent, nsIPresContext* aPresContext) { + // XXX support mBorderWidhts until deprecated methods are removed + if (! mWidthsInitialized) { + float pixelsToTwips = 20.0f; + if (aPresContext) { + aPresContext->GetPixelsToTwips(&pixelsToTwips); + } + mBorderWidths[NS_STYLE_BORDER_WIDTH_THIN] = NSIntPixelsToTwips(1, pixelsToTwips); + mBorderWidths[NS_STYLE_BORDER_WIDTH_MEDIUM] = NSIntPixelsToTwips(3, pixelsToTwips); + mBorderWidths[NS_STYLE_BORDER_WIDTH_THICK] = NSIntPixelsToTwips(5, pixelsToTwips); + mWidthsInitialized = PR_TRUE; + } + // spacing values not inherited mOutlineRadius.Reset(); @@ -1068,7 +772,7 @@ void StyleOutlineImpl::RecalcData(void) mCachedOutlineWidth = 0; } else { - mCachedOutlineWidth = CalcCoord(mOutlineWidth, kBorderWidths, 3); + mCachedOutlineWidth = CalcCoord(mOutlineWidth, mBorderWidths, 3); } mHasCachedOutline = PR_TRUE; } @@ -1385,9 +1089,6 @@ PRUint32 StyleTextImpl::ComputeCRC32(PRUint32 aCrc) const // nsStyleDisplay // -nsStyleDisplay::nsStyleDisplay(void) { } -nsStyleDisplay::~nsStyleDisplay(void) { } - struct StyleDisplayImpl: public nsStyleDisplay { StyleDisplayImpl(void) { } @@ -1645,168 +1346,6 @@ nsStyleContent::~nsStyleContent(void) DELETE_ARRAY_IF(mQuotes); } -nsresult -nsStyleContent::GetContentAt(PRUint32 aIndex, nsStyleContentType& aType, nsString& aContent) const -{ - if (aIndex < mContentCount) { - aType = mContents[aIndex].mType; - aContent = mContents[aIndex].mContent; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::AllocateContents(PRUint32 aCount) -{ - if (aCount != mContentCount) { - DELETE_ARRAY_IF(mContents); - if (aCount) { - mContents = new nsStyleContentData[aCount]; - if (! mContents) { - mContentCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } - } - mContentCount = aCount; - } - return NS_OK; -} - -nsresult -nsStyleContent::SetContentAt(PRUint32 aIndex, nsStyleContentType aType, const nsString& aContent) -{ - if (aIndex < mContentCount) { - mContents[aIndex].mType = aType; - if (aType < eStyleContentType_OpenQuote) { - mContents[aIndex].mContent = aContent; - } - else { - mContents[aIndex].mContent.Truncate(); - } - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::GetCounterIncrementAt(PRUint32 aIndex, nsString& aCounter, PRInt32& aIncrement) const -{ - if (aIndex < mIncrementCount) { - aCounter = mIncrements[aIndex].mCounter; - aIncrement = mIncrements[aIndex].mValue; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::AllocateCounterIncrements(PRUint32 aCount) -{ - if (aCount != mIncrementCount) { - DELETE_ARRAY_IF(mIncrements); - if (aCount) { - mIncrements = new nsStyleCounterData[aCount]; - if (! mIncrements) { - mIncrementCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } - } - mIncrementCount = aCount; - } - return NS_OK; -} - -nsresult -nsStyleContent::SetCounterIncrementAt(PRUint32 aIndex, const nsString& aCounter, PRInt32 aIncrement) -{ - if (aIndex < mIncrementCount) { - mIncrements[aIndex].mCounter = aCounter; - mIncrements[aIndex].mValue = aIncrement; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::GetCounterResetAt(PRUint32 aIndex, nsString& aCounter, PRInt32& aValue) const -{ - if (aIndex < mResetCount) { - aCounter = mResets[aIndex].mCounter; - aValue = mResets[aIndex].mValue; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::AllocateCounterResets(PRUint32 aCount) -{ - if (aCount != mResetCount) { - DELETE_ARRAY_IF(mResets); - if (aCount) { - mResets = new nsStyleCounterData[aCount]; - if (! mResets) { - mResetCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } - } - mResetCount = aCount; - } - return NS_OK; -} - -nsresult -nsStyleContent::SetCounterResetAt(PRUint32 aIndex, const nsString& aCounter, PRInt32 aValue) -{ - if (aIndex < mResetCount) { - mResets[aIndex].mCounter = aCounter; - mResets[aIndex].mValue = aValue; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::GetQuotesAt(PRUint32 aIndex, nsString& aOpen, nsString& aClose) const -{ - if (aIndex < mQuotesCount) { - aIndex *= 2; - aOpen = mQuotes[aIndex]; - aClose = mQuotes[++aIndex]; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsStyleContent::AllocateQuotes(PRUint32 aCount) -{ - if (aCount != mQuotesCount) { - DELETE_ARRAY_IF(mQuotes); - if (aCount) { - mQuotes = new nsString[aCount * 2]; - if (! mQuotes) { - mQuotesCount = 0; - return NS_ERROR_OUT_OF_MEMORY; - } - } - mQuotesCount = aCount; - } - return NS_OK; -} - -nsresult -nsStyleContent::SetQuotesAt(PRUint32 aIndex, const nsString& aOpen, const nsString& aClose) -{ - if (aIndex < mQuotesCount) { - aIndex *= 2; - mQuotes[aIndex] = aOpen; - mQuotes[++aIndex] = aClose; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; -} struct StyleContentImpl: public nsStyleContent { StyleContentImpl(void) : nsStyleContent() { }; @@ -2980,8 +2519,6 @@ StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent, NS_IF_ADDREF(mPseudoTag); NS_IF_ADDREF(mRules); - InitBorderWidths(aPresContext); - mNextSibling = this; mPrevSibling = this; if (nsnull != mParent) {