diff --git a/mozilla/allmakefiles.sh b/mozilla/allmakefiles.sh index e86953d4792..1504fdc5292 100755 --- a/mozilla/allmakefiles.sh +++ b/mozilla/allmakefiles.sh @@ -1217,6 +1217,19 @@ if [ "$MOZ_SVG" ]; then " fi +# xtf +if [ "$MOZ_XTF" ]; then + MAKEFILES_content="$MAKEFILES_content + content/xtf/Makefile + content/xtf/public/Makefile + content/xtf/src/Makefile +" + MAKEFILES_layout="$MAKEFILES_layout + layout/xtf/Makefile + layout/xtf/src/Makefile +" +fi + # directory/xpcom if [ "$MOZ_LDAP_XPCOM" ]; then MAKEFILES_ldap=" diff --git a/mozilla/config/autoconf.mk.in b/mozilla/config/autoconf.mk.in index b03c76cf25f..8bba0655bb7 100644 --- a/mozilla/config/autoconf.mk.in +++ b/mozilla/config/autoconf.mk.in @@ -163,6 +163,7 @@ MOZ_INTERNAL_LIBART_LGPL = @MOZ_INTERNAL_LIBART_LGPL@ MOZ_UPDATE_XTERM = @MOZ_UPDATE_XTERM@ MOZ_MATHML = @MOZ_MATHML@ +MOZ_XTF = @MOZ_XTF@ MOZ_SVG = @MOZ_SVG@ MOZ_SVG_RENDERER_GDIPLUS = @MOZ_SVG_RENDERER_GDIPLUS@ MOZ_SVG_RENDERER_LIBART = @MOZ_SVG_RENDERER_LIBART@ diff --git a/mozilla/configure.in b/mozilla/configure.in index 4e1a51f8a42..9509ca9c73a 100644 --- a/mozilla/configure.in +++ b/mozilla/configure.in @@ -4138,6 +4138,17 @@ if test "$MOZ_MATHML"; then AC_DEFINE(MOZ_MATHML) fi +dnl ======================================================== +dnl XTF +dnl ======================================================== +MOZ_ARG_ENABLE_BOOL(xtf, +[ --enable-xtf Enable XTF (pluggable xml tags) support], + MOZ_XTF=1, + MOZ_XTF= ) +if test -n "$MOZ_XTF"; then + AC_DEFINE(MOZ_XTF) +fi + dnl ======================================================== dnl SVG dnl ======================================================== @@ -5568,6 +5579,7 @@ AC_SUBST(MOZ_GFX_TOOLKIT_LDFLAGS) AC_SUBST(MOZ_UPDATE_XTERM) AC_SUBST(MINIMO) AC_SUBST(MOZ_MATHML) +AC_SUBST(MOZ_XTF) AC_SUBST(MOZ_SVG) AC_SUBST(MOZ_SVG_RENDERER_GDIPLUS) AC_SUBST(MOZ_SVG_RENDERER_LIBART) diff --git a/mozilla/content/Makefile.in b/mozilla/content/Makefile.in index 949b1b7aac2..146226a56c4 100644 --- a/mozilla/content/Makefile.in +++ b/mozilla/content/Makefile.in @@ -49,6 +49,10 @@ ifdef MOZ_SVG DIRS += svg endif +ifdef MOZ_XTF +DIRS += xtf +endif + DIRS += events shared include $(topsrcdir)/config/rules.mk diff --git a/mozilla/content/base/public/nsContentUtils.h b/mozilla/content/base/public/nsContentUtils.h index efa9652a6c8..c291d4f4f8c 100644 --- a/mozilla/content/base/public/nsContentUtils.h +++ b/mozilla/content/base/public/nsContentUtils.h @@ -75,6 +75,9 @@ class nsIDOMDocument; class nsIConsoleService; class nsIStringBundleService; class nsIStringBundle; +#ifdef MOZ_XTF +class nsIXTFService; +#endif class nsContentUtils { @@ -254,6 +257,10 @@ public: return sIOService; }; +#ifdef MOZ_XTF + static nsIXTFService* GetXTFServiceWeakRef(); +#endif + static nsIScriptSecurityManager* GetSecurityManager() { return sSecurityManager; @@ -490,6 +497,10 @@ private: static nsIIOService *sIOService; +#ifdef MOZ_XTF + static nsIXTFService *sXTFService; +#endif + static nsIPrefBranch *sPrefBranch; static nsIPref *sPref; diff --git a/mozilla/content/base/public/nsINameSpaceManager.h b/mozilla/content/base/public/nsINameSpaceManager.h index 29d7e32ac9a..d7c88355ee4 100644 --- a/mozilla/content/base/public/nsINameSpaceManager.h +++ b/mozilla/content/base/public/nsINameSpaceManager.h @@ -58,6 +58,7 @@ class nsINameSpace; #define kNameSpaceID_XUL 9 #define kNameSpaceID_SVG 10 #define kNameSpaceID_XMLEvents 11 +#define kNameSpaceID_LastBuiltin 11 // last 'built-in' namespace #define NS_NAMESPACEMANAGER_CONTRACTID "@mozilla.org/content/namespacemanager;1" diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index 5588c645716..53ee4c9aeba 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -104,6 +104,10 @@ #include "nsGenericElement.h" #include "nsNodeInfoManager.h" #include "nsCRT.h" +#ifdef MOZ_XTF +#include "nsIXTFService.h" +static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID); +#endif // for ReportToConsole #include "nsIStringBundle.h" @@ -120,6 +124,9 @@ nsIThreadJSContextStack *nsContentUtils::sThreadJSContextStack = nsnull; nsIParserService *nsContentUtils::sParserService = nsnull; nsINameSpaceManager *nsContentUtils::sNameSpaceManager = nsnull; nsIIOService *nsContentUtils::sIOService = nsnull; +#ifdef MOZ_XTF +nsIXTFService *nsContentUtils::sXTFService = nsnull; +#endif nsIPrefBranch *nsContentUtils::sPrefBranch = nsnull; nsIPref *nsContentUtils::sPref = nsnull; imgILoader *nsContentUtils::sImgLoader = nsnull; @@ -207,6 +214,19 @@ nsContentUtils::GetParserServiceWeakRef() return sParserService; } +nsIXTFService* +nsContentUtils::GetXTFServiceWeakRef() +{ + if (!sXTFService) { + nsresult rv = CallGetService(kXTFServiceCID, &sXTFService); + if (NS_FAILED(rv)) { + sXTFService = nsnull; + } + } + + return sXTFService; +} + template struct NormalizeNewlinesCharTraits { public: @@ -392,6 +412,9 @@ nsContentUtils::Shutdown() NS_IF_RELEASE(sNameSpaceManager); NS_IF_RELEASE(sParserService); NS_IF_RELEASE(sIOService); +#ifdef MOZ_XTF + NS_IF_RELEASE(sXTFService); +#endif NS_IF_RELEASE(sImgLoader); NS_IF_RELEASE(sPrefBranch); NS_IF_RELEASE(sPref); diff --git a/mozilla/content/base/src/nsNameSpaceManager.cpp b/mozilla/content/base/src/nsNameSpaceManager.cpp index 0395a3b005c..23981f2cc3c 100644 --- a/mozilla/content/base/src/nsNameSpaceManager.cpp +++ b/mozilla/content/base/src/nsNameSpaceManager.cpp @@ -44,6 +44,13 @@ #include "nsLayoutAtoms.h" #include "nsString.h" +#ifdef MOZ_XTF +#include "nsIServiceManager.h" +#include "nsIXTFService.h" +#include "nsContentUtils.h" +static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID); +#endif + #define kXMLNSNameSpaceURI "http://www.w3.org/2000/xmlns/" #define kXMLNameSpaceURI "http://www.w3.org/XML/1998/namespace" #define kXHTMLNameSpaceURI "http://www.w3.org/1999/xhtml" @@ -467,6 +474,15 @@ NS_NewElement(nsIContent** aResult, PRInt32 aElementType, if (aElementType == kNameSpaceID_XMLEvents) { return NS_NewXMLEventsElement(aResult, aNodeInfo); } +#ifdef MOZ_XTF + if (aElementType > kNameSpaceID_LastBuiltin) { + nsIXTFService* xtfService = nsContentUtils::GetXTFServiceWeakRef(); + NS_ASSERTION(xtfService, "could not get xtf service"); + if (xtfService && + NS_SUCCEEDED(xtfService->CreateElement(aResult, aNodeInfo))) + return NS_OK; + } +#endif return NS_NewXMLElement(aResult, aNodeInfo); } diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index 3ed86e41b12..0db84c4dba8 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -526,6 +526,11 @@ nsXMLContentSink::CloseElement(nsIContent* aContent, PRBool* aAppendContent) nsINodeInfo* nodeInfo = aContent->GetNodeInfo(); +#ifdef MOZ_XTF + if (nodeInfo->NamespaceID() > kNameSpaceID_LastBuiltin) + aContent->DoneAddingChildren(); +#endif + if (!nodeInfo->NamespaceEquals(kNameSpaceID_XHTML) && !nodeInfo->NamespaceEquals(kNameSpaceID_SVG)) { return NS_OK; diff --git a/mozilla/content/xtf/Makefile.in b/mozilla/content/xtf/Makefile.in new file mode 100644 index 00000000000..96f5d6194d6 --- /dev/null +++ b/mozilla/content/xtf/Makefile.in @@ -0,0 +1,47 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Mozilla XTF project. +# +# The Initial Developer of the Original Code is +# Alex Fritze. +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Alex Fritze (original author) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = public src + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/content/xtf/public/Makefile.in b/mozilla/content/xtf/public/Makefile.in new file mode 100644 index 00000000000..505990d9850 --- /dev/null +++ b/mozilla/content/xtf/public/Makefile.in @@ -0,0 +1,72 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Mozilla XTF project. +# +# The Initial Developer of the Original Code is +# Alex Fritze. +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Alex Fritze (original author) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = content +XPIDL_MODULE = content_xtf + +XPIDLSRCS = \ + nsIXMLContentBuilder.idl \ + nsIXTFAttributeHandler.idl \ + nsIXTFElement.idl \ + nsIXTFElementFactory.idl \ + nsIXTFElementWrapper.idl \ + nsIXTFGenericElement.idl \ + nsIXTFGenericElementWrapper.idl \ + nsIXTFPrivate.idl \ + nsIXTFVisual.idl \ + nsIXTFXMLVisual.idl \ + nsIXTFXMLVisualWrapper.idl \ + nsIXTFXULVisual.idl \ + nsIXTFXULVisualWrapper.idl \ + $(NULL) + +ifdef MOZ_SVG +XPIDLSRCS += \ + nsIXTFSVGVisual.idl \ + nsIXTFSVGVisualWrapper.idl \ + $(NULL) +endif + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/content/xtf/public/nsIXMLContentBuilder.idl b/mozilla/content/xtf/public/nsIXMLContentBuilder.idl new file mode 100644 index 00000000000..45e82f3b271 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXMLContentBuilder.idl @@ -0,0 +1,89 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsISupports.idl" + +interface nsIDOMElement; +interface nsIDOMDocument; + +[scriptable, uuid(e9c4cd4f-cd41-43d0-bf3b-48abb9cde90f)] +interface nsIXMLContentBuilder : nsISupports +{ + // (Re-)Initialize this builder. Set 'root' as the new root and + // current element. If 'root' is null, the first element built (with + // 'beginElement()') will become the new root. Also resets the + // element namespace. + void clear(in nsIDOMElement root); + + // Set the document which will be used by 'beginElement()' to create + // elements. If null, the builder will create a new XML document + // internally. + void setDocument(in nsIDOMDocument doc); + + // Set the namespace for all elements built subsequently + void setElementNamespace(in AString ns); + + // Create an element. The element will become the 'current' element, + // i.e. the target for attributes (via 'attrib()') or child content + // (via subsequent begin/endElement()-calls), until it is 'closed' + // with a call to 'endElement()'. + void beginElement(in AString tagname); + void endElement(); + + // Set an attribute on the current element + void attrib(in AString name, in AString value); + + // Create a textNode + void textNode(in AString text); + + readonly attribute nsIDOMElement root; + readonly attribute nsIDOMElement current; +}; + +%{C++ + +// {E09AF32D-2A54-4D76-9EF0-3070E83F8BE7} +#define NS_XMLCONTENTBUILDER_CID \ +{ 0xe09af32d, 0x2a54, 0x4d76, { 0x9e, 0xf0, 0x30, 0x70, 0xe8, 0x3f, 0x8b, 0xe7 } } + +#define NS_XMLCONTENTBUILDER_CONTRACTID "@mozilla.org/xtf/xml-contentbuilder;1" + +nsresult NS_NewXMLContentBuilder(nsIXMLContentBuilder** aResult); + +%} + diff --git a/mozilla/content/xtf/public/nsIXTFAttributeHandler.idl b/mozilla/content/xtf/public/nsIXTFAttributeHandler.idl new file mode 100644 index 00000000000..3fabd733fee --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFAttributeHandler.idl @@ -0,0 +1,69 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsISupports.idl" +interface nsIAtom; + +[scriptable, uuid(72152f7f-7e8d-43fd-8477-3f29ae8d240d)] +interface nsIXTFAttributeHandler : nsISupports +{ + // If 'false' the given attribute will be handled by the wrapper. + // Namespaced attributes will always be handled by the wrapper. The + // set of attributes handled by the attribute handler should remain + // constant for its complete lifetime. + boolean handlesAttribute(in nsIAtom name); + + void setAttribute(in nsIAtom name, in AString newValue); + + void removeAttribute(in nsIAtom name); + + // If the attribute 'name' is unknown the implementation should mark + // the returned string as being 'null' (i.e. return 'null' in JS; + // call SetIsVoid(PR_TRUE) in C++) rather than throw an exception. + // A 'void' result will be translated into NS_CONTENT_ATTR_NOT_THERE + // by the wrapper. An empty result will be translated into + // NS_CONTENT_ATTR_NO_VALUE. + AString getAttribute(in nsIAtom name); + + boolean hasAttribute(in nsIAtom name); + + unsigned long getAttributeCount(); + + // note that this method should return an *atom* not a string. + nsIAtom getAttributeNameAt(in unsigned long index); +}; diff --git a/mozilla/content/xtf/public/nsIXTFElement.idl b/mozilla/content/xtf/public/nsIXTFElement.idl new file mode 100644 index 00000000000..162348e8bb7 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFElement.idl @@ -0,0 +1,142 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsISupports.idl" +interface nsIAtom; +interface nsIDOMDocument; +interface nsIDOMElement; +interface nsIDOMNode; + +[scriptable, uuid(f0617ed1-db6a-4704-ac4b-67bf15a77788)] +interface nsIXTFElement : nsISupports +{ + // called when the wrapper object is being destroyed. + void onDestroyed(); + + // Constants for attribute elementType: + + // Elements of type GENERIC_ELEMENT are required to implement the + // nsIXTFGenericElement interface in addition to nsIXTFElement: + const unsigned long ELEMENT_TYPE_GENERIC_ELEMENT = 0; + + // Elements of type SVG_VISUAL are required to implement the + // nsIXTFSVGVisual interface in addition to nsIXTFElement: + const unsigned long ELEMENT_TYPE_SVG_VISUAL = 1; + + // Elements of type XML_VISUAL are required to implement the + // nsIXTFXMLVisual interface in addition to nsIXTFElement: + const unsigned long ELEMENT_TYPE_XML_VISUAL = 2; + + // Elements of type XUL_VISUAL are required to implement the + // nsIXTFXULVisual interface in addition to nsIXTFElement: + const unsigned long ELEMENT_TYPE_XUL_VISUAL = 3; + + // elementType identifies the type of wrapper that will be built for + // a given xtf element. It must remain constant for the entire + // lifetime of the xtf element (i.e. before any onCreated()-calls + // until after onDestroyed()-calls). + readonly attribute unsigned long elementType; + + // If isAttributeHandler is set to 'true', the xtf element indicates + // that it wants to manage its own attributes. In this case it needs + // to implement the nsIXTFAttributeHandler interface in addition to + // its other interfaces. 'isAttributeHandler' must remain constant + // for the entire lifetime of the xtf element (i.e. before any + // onCreated()-calls until after onDestroyed()-calls). + readonly attribute boolean isAttributeHandler; + + // getScriptingInterfaces: This array serves 2 purposes: a) All + // interfaces in this array will automatically be accessible when + // our wrapper element is used from JS (other interfaces need to be + // explicitly QI'ed for), and b) All these interfaces are callable + // from unpriviliged script. + void getScriptingInterfaces(out unsigned long count, + [array, size_is(count), retval] out nsIIDPtr array); + + // Notification mask constants: + // To receive a given event set the corresponding bit in + // nsIXTFElementWrapper::notificationMask. + const unsigned long NOTIFY_WILL_CHANGE_DOCUMENT = 0x00000001; + const unsigned long NOTIFY_DOCUMENT_CHANGED = 0x00000002; + + const unsigned long NOTIFY_WILL_CHANGE_PARENT = 0x00000004; + const unsigned long NOTIFY_PARENT_CHANGED = 0x00000008; + + const unsigned long NOTIFY_WILL_INSERT_CHILD = 0x00000010; + const unsigned long NOTIFY_CHILD_INSERTED = 0x00000020; + + const unsigned long NOTIFY_WILL_APPEND_CHILD = 0x00000040; + const unsigned long NOTIFY_CHILD_APPENDED = 0x00000080; + + const unsigned long NOTIFY_WILL_REMOVE_CHILD = 0x00000100; + const unsigned long NOTIFY_CHILD_REMOVED = 0x00000200; + + const unsigned long NOTIFY_WILL_SET_ATTRIBUTE = 0x00000400; + const unsigned long NOTIFY_ATTRIBUTE_SET = 0x00000800; + + const unsigned long NOTIFY_WILL_REMOVE_ATTRIBUTE = 0x00001000; + const unsigned long NOTIFY_ATTRIBUTE_REMOVED = 0x00002000; + + const unsigned long NOTIFY_DONE_ADDING_CHILDREN = 0x00004000; + + // Event notifications: + + void willChangeDocument(in nsIDOMDocument newDoc); + void documentChanged(in nsIDOMDocument newDoc); + + void willChangeParent(in nsIDOMElement newParent); + void parentChanged(in nsIDOMElement newParent); + + void willInsertChild(in nsIDOMNode child, in unsigned long index); + void childInserted(in nsIDOMNode child, in unsigned long index); + + void willAppendChild(in nsIDOMNode child); + void childAppended(in nsIDOMNode child); + + void willRemoveChild(in unsigned long index); + void childRemoved(in unsigned long index); + + void willSetAttribute(in nsIAtom name, in AString newValue); + void attributeSet(in nsIAtom name, in AString newValue); + + void willRemoveAttribute(in nsIAtom name); + void attributeRemoved(in nsIAtom name); + + void doneAddingChildren(); +}; + diff --git a/mozilla/content/xtf/public/nsIXTFElementFactory.idl b/mozilla/content/xtf/public/nsIXTFElementFactory.idl new file mode 100644 index 00000000000..a998850d154 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFElementFactory.idl @@ -0,0 +1,54 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsISupports.idl" + +interface nsIXTFElement; + +[scriptable, uuid(27c10dca-2efc-416b-ae36-9794380a661e)] +interface nsIXTFElementFactory : nsISupports +{ + nsIXTFElement createElement(in AString tagName); +}; + +%{C++ + +#define NS_XTF_ELEMENT_FACTORY_CONTRACTID "@mozilla.org/xtf/element-factory;1" +#define NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_XTF_ELEMENT_FACTORY_CONTRACTID "?namespace=" + +%} diff --git a/mozilla/content/xtf/public/nsIXTFElementWrapper.idl b/mozilla/content/xtf/public/nsIXTFElementWrapper.idl new file mode 100644 index 00000000000..e40c3f45ed2 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFElementWrapper.idl @@ -0,0 +1,54 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsISupports.idl" + +interface nsIDOMElement; +interface nsIDOMDocument; + +[scriptable, uuid(94c05b72-997a-4bb0-a23d-63e40c55b02c)] +interface nsIXTFElementWrapper : nsISupports +{ + readonly attribute nsIDOMElement elementNode; + readonly attribute nsIDOMElement documentFrameElement; + + // Events can be unmasked by setting the corresponding bit as given + // by the NOTIFY_* constants in nsIXTFElement and nsIXTFVisual: + attribute unsigned long notificationMask; +}; + diff --git a/mozilla/content/xtf/public/nsIXTFGenericElement.idl b/mozilla/content/xtf/public/nsIXTFGenericElement.idl new file mode 100644 index 00000000000..df6b1023114 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFGenericElement.idl @@ -0,0 +1,51 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFElement.idl" + +interface nsIXTFGenericElementWrapper; + +[scriptable, uuid(39e595c6-c566-40ad-bc4c-92fc4352cffd)] +interface nsIXTFGenericElement : nsIXTFElement +{ + // onCreated: Will be called before any notifications are sent to + // the xtf element. Parameter 'wrapper' is a weak proxy to the + // wrapping element (i.e. it can safely be addrefed by the xtf + // element without creating cyclic XPCOM referencing). + void onCreated(in nsIXTFGenericElementWrapper wrapper); +}; diff --git a/mozilla/content/xtf/public/nsIXTFGenericElementWrapper.idl b/mozilla/content/xtf/public/nsIXTFGenericElementWrapper.idl new file mode 100644 index 00000000000..ddf4b17ad0f --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFGenericElementWrapper.idl @@ -0,0 +1,45 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFElementWrapper.idl" + +[scriptable, uuid(5e0cf513-5b87-4da2-a5ce-d9ba3a30d540)] +interface nsIXTFGenericElementWrapper : nsIXTFElementWrapper +{ +}; + diff --git a/mozilla/content/xtf/public/nsIXTFPrivate.idl b/mozilla/content/xtf/public/nsIXTFPrivate.idl new file mode 100644 index 00000000000..047017be845 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFPrivate.idl @@ -0,0 +1,55 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsISupports.idl" + +/* + * This interface can be used to give access to a private 'inner' + * interface when an xtf element is accessed through its wrapper (or + * more precisely: accessed through one of the wrapper-generated + * nsXTFInterfaceAggregator proxies). For JS-implemented XTF elements + * the inner interface can be used to gain access to the underlying + * JSObject using xpconnect's "wrappedJSObject" mechanism (see + * nsIXPConnect.idl). + */ + +[scriptable, uuid(13ef3d54-1dd1-4a5c-a8d5-a04a327fb9b6)] +interface nsIXTFPrivate : nsISupports +{ + readonly attribute nsISupports inner; +}; diff --git a/mozilla/content/xtf/public/nsIXTFSVGVisual.idl b/mozilla/content/xtf/public/nsIXTFSVGVisual.idl new file mode 100644 index 00000000000..447eed22175 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFSVGVisual.idl @@ -0,0 +1,53 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFVisual.idl" + +interface nsIXTFSVGVisualWrapper; +interface nsIDOMElement; + +[scriptable, uuid(6e051a6a-9ac3-4f3a-b701-d794761c47d9)] +interface nsIXTFSVGVisual : nsIXTFVisual +{ + // onCreated: Will be called before any notifications are sent to + // the xtf element or before the element will be asked for its + // visualContent. Parameter 'wrapper' is a weak proxy to the + // wrapping element (i.e. it can safely be addrefed by the xtf + // element without creating cyclic XPCOM referencing). + void onCreated(in nsIXTFSVGVisualWrapper wrapper); +}; diff --git a/mozilla/content/xtf/public/nsIXTFSVGVisualWrapper.idl b/mozilla/content/xtf/public/nsIXTFSVGVisualWrapper.idl new file mode 100644 index 00000000000..b0d997eca3c --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFSVGVisualWrapper.idl @@ -0,0 +1,45 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFElementWrapper.idl" + +[scriptable, uuid(056d0708-6112-44ff-b3ca-ecf14936d599)] +interface nsIXTFSVGVisualWrapper : nsIXTFElementWrapper +{ +}; + diff --git a/mozilla/content/xtf/public/nsIXTFVisual.idl b/mozilla/content/xtf/public/nsIXTFVisual.idl new file mode 100644 index 00000000000..6166877388c --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFVisual.idl @@ -0,0 +1,75 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFElement.idl" + +interface nsIDOMElement; + +[scriptable, uuid(705e7fc8-6fbb-456e-8d18-fd2dae55d477)] +interface nsIXTFVisual : nsIXTFElement +{ + // The content tree rooted in 'visualContent' will be rendered where + // the xtf visual is placed into an appropriate context. A visual + // will be asked for its visual content once at most. The tree + // cannot be dynamically replaced during the lifetime of the + // element, it may however be dynamically manipulated (i.e. you can + // insert/remove content, set attributes, etc., but *not* exchange + // the root element for something else). + readonly attribute nsIDOMElement visualContent; + + // Children of the xtf visual which are themselves 'visuals' + // (i.e. built-ins elements, other xtf visuals or xbl elements with + // visual ) will be rendered as if they were children of + // 'insertionPoint'. 'insertionPoint' should either be null (in + // which case the children will not be automatically rendered) or + // point into the 'visualContent' tree. + readonly attribute nsIDOMElement insertionPoint; + + // If 'true', document style sheets will apply to the visual + // content. If 'false', only UA and user style sheets will be + // applied. + readonly attribute boolean applyDocumentStyleSheets; + + // Notification mask constants: + // To receive a given event set the corresponding bit in + // nsIXTFElementWrapper::notificationMask. + const unsigned long NOTIFY_DID_LAYOUT = 0x00010000; + + // Event notifications: + void didLayout(); +}; diff --git a/mozilla/content/xtf/public/nsIXTFXMLVisual.idl b/mozilla/content/xtf/public/nsIXTFXMLVisual.idl new file mode 100644 index 00000000000..08a309c0d71 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFXMLVisual.idl @@ -0,0 +1,53 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFVisual.idl" + +interface nsIXTFXMLVisualWrapper; +interface nsIDOMElement; + +[scriptable, uuid(f6e8a067-a3ec-450f-b1e1-3f14ac2b369e)] +interface nsIXTFXMLVisual : nsIXTFVisual +{ + // onCreated: Will be called before any notifications are sent to + // the xtf element or before the element will be asked for its + // visualContent. Parameter 'wrapper' is a weak proxy to the + // wrapping element (i.e. it can safely be addrefed by the xtf + // element without creating cyclic XPCOM referencing). + void onCreated(in nsIXTFXMLVisualWrapper wrapper); +}; diff --git a/mozilla/content/xtf/public/nsIXTFXMLVisualWrapper.idl b/mozilla/content/xtf/public/nsIXTFXMLVisualWrapper.idl new file mode 100644 index 00000000000..924c1f49f23 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFXMLVisualWrapper.idl @@ -0,0 +1,45 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFElementWrapper.idl" + +[scriptable, uuid(a260bc18-c639-41e5-b28a-a6b5c8e99993)] +interface nsIXTFXMLVisualWrapper : nsIXTFElementWrapper +{ +}; + diff --git a/mozilla/content/xtf/public/nsIXTFXULVisual.idl b/mozilla/content/xtf/public/nsIXTFXULVisual.idl new file mode 100644 index 00000000000..bad9338f0f0 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFXULVisual.idl @@ -0,0 +1,53 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFVisual.idl" + +interface nsIXTFXULVisualWrapper; +interface nsIDOMElement; + +[scriptable, uuid(d4ae63e2-bf46-4792-8ae4-5105aeab26a3)] +interface nsIXTFXULVisual : nsIXTFVisual +{ + // onCreated: Will be called before any notifications are sent to + // the xtf element or before the element will be asked for its + // visualContent. Parameter 'wrapper' is a weak proxy to the + // wrapping element (i.e. it can safely be addrefed by the xtf + // element without creating cyclic XPCOM referencing). + void onCreated(in nsIXTFXULVisualWrapper wrapper); +}; diff --git a/mozilla/content/xtf/public/nsIXTFXULVisualWrapper.idl b/mozilla/content/xtf/public/nsIXTFXULVisualWrapper.idl new file mode 100644 index 00000000000..2f3f477adb1 --- /dev/null +++ b/mozilla/content/xtf/public/nsIXTFXULVisualWrapper.idl @@ -0,0 +1,45 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsIXTFElementWrapper.idl" + +[scriptable, uuid(b8bb0585-5b59-4e6f-9e0e-13569da1ad33)] +interface nsIXTFXULVisualWrapper : nsIXTFElementWrapper +{ +}; + diff --git a/mozilla/content/xtf/readme.txt b/mozilla/content/xtf/readme.txt new file mode 100644 index 00000000000..f25783b3c52 --- /dev/null +++ b/mozilla/content/xtf/readme.txt @@ -0,0 +1,164 @@ +XTF: An eXtensible Tag Framework +================================ + +XTF allows you to extend Mozilla by implementing new XML elements in +XPCOM modules. It is not a C++-version of XBL: XTF elements can be +written in any XPCOM-compatible language. I myself tend to write most +elements in JavaScript. + +XTF support needs to be explicitly switched on for Mozilla builds by +specifying the configure option '--enable-xtf' (add "ac_add_options +--enabl-xtf" to your .mozconfig). + +To serve a particular namespace "urn:mycompany:mynamespace" with your +own XTF elements, create an XPCOM component that implements the +interface nsIXTFElementFactory, and register it with the component +manager under the contract id +"@mozilla.org/xtf/element-factory;1?namespace=urn:mycompany:mynamespace". +Whenever Mozilla encounters a tag in your namespace it will call your +factory's 'createElement()' function. This function should either +return a new xtf element (an object implementing 'nsIXTFElement' and +some other interfaces, depending on type and required features), or +'null'. In the later case, the implementation will build a generic XML +element. + +All interfaces relevant to XTF factory modules and XTF elements can be +found in mozilla/content/xtf/public/. The implementation code itself +is mainly spread over the directories mozilla/content/xtf/ and +mozilla/layout/xtf/. + +Binding outermost elements (document elements) +============================================== + +Binding of outermost elements is not (yet) supported. Depending on +what you use xtf elements for, this might or might not be a +problem. If you use xtf to implement a whole new language, rather than +just widgets that will get used in html, xul, or svg docs, then you'll +probably want to wrap up your documents in an xml element for which +you provide some style (e.g. via a ua style sheet), so that things get +displayed instead of pretty printed. This outermost element can be in +your xtf-served namespace, as long as your xtf factory returns a +failure for this element's tagname. The implementation will then +generate a generic XML element for this element. + +XTF and XUL +=========== + +When using XTF elements in XUL documents, note that the owner document +(both wrapper.ownerDocument & wrapper.elementNode.ownerDocument) will +be null at the time of the onCreated() call. (For XML and SVG +documents, at least wrapper.ownerDocument should be non-null.) This +is unfortunate, since it is often advantageous to build the visual +content tree at the time of the onCreated() call and not wait until +the visual content is explicitly requested, so that attributes set on +the xtf element can be mapped directly to elements in the visual +content tree. It is possible to build the content tree using a +different document than the ultimate target document, but this in turn +leads to some subtleties with XBL-bound content - see below. + + +XTF and XBL +=========== + +XTF elements generally behave well in conjunction with XBL. There are +a few issues when using XBL-bound elements in an XTFVisual's +visualContent that arise from the fact that XBL bindings are attached +to elements at layout-time rather than content-tree contruction time: +Accessing an XBL-bound element's interfaces or JS object before +layout-time usually doesn't yield the expected result. E.g. a listbox +won't have the members 'appendItem', 'clearSelection', etc. before +layout-time, even if QI'ed for nsIDOMXULMenuListElement. Worse, if the +visual content has been constructed in a different document (because +the target doc wasn't available at the time of content tree +construction time - see above), then the JS object obtained before +layout time will be different to the one that will ultimately receive +the bound implementation, i.e. even QI'ing at a later stage will +fail. To work around these issues, XBL-bound content should a) either +be build as late as possible (i.e. when requested by the wrapper with +a call to nsIXTFVisual::GetVisualContent()) or b) if this is not a +possibility (e.g. because you would like to map attributes directly +into the visual content tree), all JS object references to the element +should be re-resolved at the time of the first layout (listen in to +DidLayout() notifications). + + +Bugs +==== + +1. +For xtf elements written in JS (and possibly C++ as well), +constructing a visual's visualContent using the same document as the +visual's leads to some nasty reference cycle which prevents the +wrapper, inner xtf element, anonymous content and possibly the whole +document from ever getting destroyed. A workaround is to construct the +visualContent in a different document (e.g. setting the document in +nsXMLContentBuilder to null, or not setting the document at all, will +lead to new content being build in a new temporary document). + + +2. +XBL-bound elements behave strangely if *any* XUL content underneath +them is accessed from JS too early. +Example: + + + + + +If the JS-implemented xtf element 'foo' accesses any xul content +before it receives the 'didLayout' notification, the groupbox will not +be properly build (it will not contain the label text). 'Accessing xul +content' includes any operation that leads to a js wrapper being +constructed for a xul element. E.g. if the xtf element listens in to +parentChanged-notifications, a wrapper will be build for the +notification's 'parent' parameter and groupbox construction +mysteriously fails. + + +3. +Some XUL interfaces can't be used via XPCOM and thus might not work as +expected. E.g. menulist's +nsIDOMXULSelectControlElement::insertItemAt() is supposed to return an +element of type nsIDOMXULSelectControlItemElement. However, since +menulist's XBL implementation of insertItemAt creates a xul element +which will only be bound when the next asynchronous layout occurs, +QI'ing to nsIDOMXULSelectControlItemElement fails. The result is that +the method call always fails when invoked through XPCOM. A pragmatic +solution would be to change the XUL interface signatures to return +nsIDOMXULElement instead of nsIDOMXULSelectControlItemElement. + + +4. +QI'ing a JS-implemented xtf element's wrapper from JS as in + + element.QueryInterface(Components.interface.nsIXTFPrivate); + +occasionally hits the assertion + + ###!!! ASSERTION: tearoff not empty in dtor: + '!(GetInterface()||GetNative()||GetJSObject())', + file /home/alex/devel/mozilla/js/src/xpconnect/src/xpcinlines.h, line 627 + +with the result that the QI succeeds (i.e. doesn't throw an exception) +but the interface methods/properties aren't available on the element +after the QI, even though element implements the given interface. + +This seems to happen if GC kicks in *afer* the xtf element is being +queried for its interface ( resulting in the creation of an +nsXTFInterfaceAggregator) but *before* the nsXTFInterfaceAggregator +has been wrapped for JS use by XPCConvert::NativeData2JS(). + +The workaround is to a) either expose the interface via +getScriptingInterfaces (in which case it will be available to JS +callers automatically), or b) call QI until the interface is correctly +installed, e.g.: + + while (!element.inner) + element.QueryInterface(Components.interface.nsIXTFPrivate); + +With this code the QI should succeed in the first or second iteration. + + + +07. October 2004 Alex Fritze diff --git a/mozilla/content/xtf/src/Makefile.in b/mozilla/content/xtf/src/Makefile.in new file mode 100644 index 00000000000..1de4194ebc6 --- /dev/null +++ b/mozilla/content/xtf/src/Makefile.in @@ -0,0 +1,101 @@ +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Mozilla XTF project. +# +# The Initial Developer of the Original Code is +# Alex Fritze. +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Alex Fritze (original author) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = content +LIBRARY_NAME = gkcontentxtf_s +REQUIRES = xpcom \ + string \ + layout \ + content \ + widget \ + gfx \ + dom \ + js \ + locale \ + htmlparser \ + view \ + pref \ + necko \ + xpconnect \ + webshell + +CPPSRCS = \ + nsXMLContentBuilder.cpp \ + nsXTFElementWrapper.cpp \ + nsXTFGenericElementWrapper.cpp \ + nsXTFInterfaceAggregator.cpp \ + nsXTFService.cpp \ + nsXTFVisualWrapper.cpp \ + nsXTFWeakTearoff.cpp \ + nsXTFXMLVisualWrapper.cpp \ + nsXTFXULVisualWrapper.cpp \ + $(NULL) + +ifdef MOZ_SVG +CPPSRCS += \ + nsXTFSVGVisualWrapper.cpp \ + $(NULL) +endif + +include $(topsrcdir)/config/config.mk + +# we don't want the shared lib, but we want to force the creation of a static lib. +FORCE_STATIC_LIB = 1 + +EXPORTS = \ + nsIXTFService.h \ + nsIXTFElementWrapperPrivate.h \ + nsIXTFVisualWrapperPrivate.h \ + $(NULL) + + +include $(topsrcdir)/config/rules.mk + +INCLUDES += \ + -I$(srcdir)/../../shared/public \ + -I$(srcdir)/../../html/base/src \ + -I$(srcdir)/../../xml/content/src \ + -I$(srcdir)/../../../dom \ + -I$(srcdir)/../../base/src \ + -I$(srcdir)/../../../layout/html/base/src \ + $(NULL) diff --git a/mozilla/content/xtf/src/nsIXTFElementWrapperPrivate.h b/mozilla/content/xtf/src/nsIXTFElementWrapperPrivate.h new file mode 100644 index 00000000000..c309852210b --- /dev/null +++ b/mozilla/content/xtf/src/nsIXTFElementWrapperPrivate.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_IXTFELEMENTWRAPPERPRIVATE_H__ +#define __NS_IXTFELEMENTWRAPPERPRIVATE_H__ + +#include "nsISupports.h" + +// {599EB85F-ABC0-4B52-A1B0-EA103D48E3AE} +#define NS_IXTFELEMENTWRAPPERPRIVATE_IID \ +{ 0x599eb85f, 0xabc0, 0x4b52, { 0xa1, 0xb0, 0xea, 0x10, 0x3d, 0x48, 0xe3, 0xae } } + + +class nsIXTFElementWrapperPrivate : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXTFELEMENTWRAPPERPRIVATE_IID) + + // element type as given in nsIXTFElement: + virtual PRUint32 GetElementType() = 0; +}; + +#endif // __NS_IXTFELEMENTWRAPPERPRIVATE_H__ diff --git a/mozilla/content/xtf/src/nsIXTFService.h b/mozilla/content/xtf/src/nsIXTFService.h new file mode 100644 index 00000000000..6be3c0f2afb --- /dev/null +++ b/mozilla/content/xtf/src/nsIXTFService.h @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_IXTFSERVICE_H__ +#define __NS_IXTFSERVICE_H__ + +#include "nsISupports.h" + +class nsIContent; +class nsINodeInfo; + +// {02AD2ADD-C5EC-4362-BB5F-E2C69BA76151} +#define NS_IXTFSERVICE_IID \ + { 0x02ad2add, 0xc5ec, 0x4362, { 0xbb, 0x5f, 0xe2, 0xc6, 0x9b, 0xa7, 0x61, 0x51 } } + +class nsIXTFService : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXTFSERVICE_IID) + + // try to create an xtf element based on namespace + virtual nsresult CreateElement(nsIContent** aResult, + nsINodeInfo* aNodeInfo)=0; +}; + +//---------------------------------------------------------------------- +// The one class implementing this interface: + +// {4EC832DA-6AE7-4185-807B-DADDCB5DA37A} +#define NS_XTFSERVICE_CID \ + { 0x4ec832da, 0x6ae7, 0x4185, { 0x80, 0x7b, 0xda, 0xdd, 0xcb, 0x5d, 0xa3, 0x7a } } + +#define NS_XTFSERVICE_CONTRACTID "@mozilla.org/xtf/xtf-service;1" + +nsresult NS_NewXTFService(nsIXTFService** aResult); + +#endif // __NS_IXTFSERVICE_H__ + diff --git a/mozilla/content/xtf/src/nsIXTFVisualWrapperPrivate.h b/mozilla/content/xtf/src/nsIXTFVisualWrapperPrivate.h new file mode 100644 index 00000000000..fd734a2db02 --- /dev/null +++ b/mozilla/content/xtf/src/nsIXTFVisualWrapperPrivate.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_IXTFVISUALWRAPPERPRIVATE_H__ +#define __NS_IXTFVISUALWRAPPERPRIVATE_H__ + +#include "nsISupports.h" + +//////////////////////////////////////////////////////////////////////// +// nsIXTFVisualWrapperPrivate: private interface for visual frames + +// {B628361B-4466-407F-AD26-58F282DBB6DD} +#define NS_IXTFVISUALWRAPPERPRIVATE_IID \ +{ 0xb628361b, 0x4466, 0x407f, { 0xad, 0x26, 0x58, 0xf2, 0x82, 0xdb, 0xb6, 0xdd } } + +class nsIXTFVisualWrapperPrivate : public nsISupports +{ +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXTFVISUALWRAPPERPRIVATE_IID) + + NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems) = 0; + virtual void DidLayout() = 0; + virtual void GetInsertionPoint(nsIDOMElement** insertionPoint) = 0; + virtual PRBool ApplyDocumentStyleSheets() = 0; +}; + +#endif // __NS_IXTFVISUALWRAPPERPRIVATE_H__ diff --git a/mozilla/content/xtf/src/nsXMLContentBuilder.cpp b/mozilla/content/xtf/src/nsXMLContentBuilder.cpp new file mode 100644 index 00000000000..970a769c8eb --- /dev/null +++ b/mozilla/content/xtf/src/nsXMLContentBuilder.cpp @@ -0,0 +1,250 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsIXMLContentBuilder.h" +#include "nsISupportsArray.h" +#include "nsINameSpaceManager.h" +#include "nsINodeInfo.h" +#include "nsIContent.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsIAtom.h" +#include "nsContentCID.h" +#include "nsIDocument.h" +#include "nsIDOMElement.h" +#include "nsIDOMDocument.h" +#include "nsIDOMText.h" +#include "nsNodeInfoManager.h" +#include "nsContentCreatorFunctions.h" + +static NS_DEFINE_CID(kXMLDocumentCID, NS_XMLDOCUMENT_CID); + + +class nsXMLContentBuilder : public nsIXMLContentBuilder +{ +protected: + friend nsresult NS_NewXMLContentBuilder(nsIXMLContentBuilder** aResult); + + nsXMLContentBuilder(); + ~nsXMLContentBuilder(); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsIXMLContentBuilder interface + NS_DECL_NSIXMLCONTENTBUILDER + +private: + void EnsureDoc(); + + nsCOMPtr mTop; + nsCOMPtr mCurrent; + nsCOMPtr mDocument; + nsCOMPtr mNamespaceManager; + PRInt32 mNamespaceId; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXMLContentBuilder::nsXMLContentBuilder() + : mNamespaceId(kNameSpaceID_None) +{ +#ifdef DEBUG +// printf("nsXMLContentBuilder CTOR\n"); +#endif + + mNamespaceManager = do_GetService(NS_NAMESPACEMANAGER_CONTRACTID); +} + +nsXMLContentBuilder::~nsXMLContentBuilder() +{ +#ifdef DEBUG +// printf("~nsXMLContentBuilder\n"); +#endif +} + +nsresult +NS_NewXMLContentBuilder(nsIXMLContentBuilder** aResult) +{ + nsXMLContentBuilder* result = new nsXMLContentBuilder(); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports methods + +NS_IMPL_ISUPPORTS1(nsXMLContentBuilder, nsIXMLContentBuilder); + +//---------------------------------------------------------------------- +// nsIXMLContentBuilder implementation + +/* void clear (in nsIDOMElement root); */ +NS_IMETHODIMP nsXMLContentBuilder::Clear(nsIDOMElement *root) +{ + mCurrent = root; + mTop = root; + if (mNamespaceId != kNameSpaceID_None) { + mNamespaceId = kNameSpaceID_None; + } + return NS_OK; +} + +/* void setDocument (in nsIDOMDocument doc); */ +NS_IMETHODIMP nsXMLContentBuilder::SetDocument(nsIDOMDocument *doc) +{ + mDocument = do_QueryInterface(doc); +#ifdef DEBUG + if (!mDocument) + NS_WARNING("null document in nsXMLContentBuilder::SetDocument"); +#endif + return NS_OK; +} + +/* void setElementNamespace (in AString ns); */ +NS_IMETHODIMP nsXMLContentBuilder::SetElementNamespace(const nsAString & ns) +{ + mNamespaceManager->RegisterNameSpace(ns, mNamespaceId); + return NS_OK; +} + +/* void beginElement (in AString tagname); */ +NS_IMETHODIMP nsXMLContentBuilder::BeginElement(const nsAString & tagname) +{ + nsCOMPtr node; + { + EnsureDoc(); + nsCOMPtr nameAtom = do_GetAtom(tagname); + mDocument->CreateElem(nameAtom, nsnull, mNamespaceId, PR_FALSE, getter_AddRefs(node)); + } + if (!node) { + NS_ERROR("could not create node"); + return NS_ERROR_FAILURE; + } + + // ok, we created a content element. now either append it to our + // top-level array or to the current element. + if (!mCurrent) { + if (mTop) { + NS_ERROR("Building of multi-rooted trees not supported"); + return NS_ERROR_FAILURE; + } + mTop = node; + mCurrent = mTop; + } + else { + mCurrent->AppendChildTo(node, PR_TRUE, PR_TRUE); + mCurrent = node; + } + + return NS_OK; +} + +/* void endElement (); */ +NS_IMETHODIMP nsXMLContentBuilder::EndElement() +{ + NS_ASSERTION(mCurrent, "unbalanced begin/endelement"); + mCurrent = mCurrent->GetParent(); + return NS_OK; +} + +/* void attrib (in AString name, in AString value); */ +NS_IMETHODIMP nsXMLContentBuilder::Attrib(const nsAString & name, const nsAString & value) +{ + NS_ASSERTION(mCurrent, "can't set attrib w/o open element"); + nsCOMPtr nameAtom = do_GetAtom(name); + mCurrent->SetAttr(0, nameAtom, value, PR_TRUE); + return NS_OK; +} + +/* void textNode (in AString text); */ +NS_IMETHODIMP nsXMLContentBuilder::TextNode(const nsAString & text) +{ + EnsureDoc(); + NS_ASSERTION(mCurrent, "can't append textnode w/o open element"); + nsCOMPtr domDoc = do_QueryInterface(mDocument); + NS_ASSERTION(domDoc, "no dom document"); + + nsCOMPtr textNode; + domDoc->CreateTextNode(text, getter_AddRefs(textNode)); + NS_ASSERTION(textNode, "Failed to create text node"); + nsCOMPtr textContent = do_QueryInterface(textNode); + mCurrent->AppendChildTo(textContent, PR_TRUE, PR_TRUE); + return NS_OK; +} + +/* readonly attribute nsIDOMElement root; */ +NS_IMETHODIMP nsXMLContentBuilder::GetRoot(nsIDOMElement * *aRoot) +{ + if (!mTop) { + *aRoot = nsnull; + return NS_OK; + } + return mTop->QueryInterface(nsIDOMElement::GetIID(), (void**)aRoot); +} + +/* readonly attribute nsIDOMElement current; */ +NS_IMETHODIMP nsXMLContentBuilder::GetCurrent(nsIDOMElement * *aCurrent) +{ + if (!mCurrent) { + *aCurrent = nsnull; + return NS_OK; + } + return mCurrent->QueryInterface(nsIDOMElement::GetIID(), (void**)aCurrent); +} + +//---------------------------------------------------------------------- +// implementation helpers + +void nsXMLContentBuilder::EnsureDoc() +{ + if (!mDocument) { + mDocument = do_CreateInstance(kXMLDocumentCID); + // XXX should probably do some doc initialization here, such as + // setting the base url + } + NS_ASSERTION(mDocument, "null doc"); +} diff --git a/mozilla/content/xtf/src/nsXTFElementWrapper.cpp b/mozilla/content/xtf/src/nsXTFElementWrapper.cpp new file mode 100644 index 00000000000..331ab0c548d --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFElementWrapper.cpp @@ -0,0 +1,560 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsXTFElementWrapper.h" +#include "nsIXTFElement.h" +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsXTFInterfaceAggregator.h" +#include "nsIClassInfo.h" +#include "nsPIDOMWindow.h" +#include "nsIInterfaceRequestorUtils.h" +#include "nsIDocument.h" +#include "nsHTMLAtoms.h" // XXX only needed for nsHTMLAtoms::id + +nsXTFElementWrapper::nsXTFElementWrapper(nsINodeInfo* aNodeInfo) + : nsXTFElementWrapperBase(aNodeInfo), + mNotificationMask(0) +{ +} + +nsresult +nsXTFElementWrapper::Init() +{ + PRBool innerHandlesAttribs = PR_FALSE; + GetXTFElement()->GetIsAttributeHandler(&innerHandlesAttribs); + if (innerHandlesAttribs) + mAttributeHandler = do_QueryInterface(GetXTFElement()); + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports implementation + +NS_IMPL_ADDREF_INHERITED(nsXTFElementWrapper,nsXTFElementWrapperBase) +NS_IMPL_RELEASE_INHERITED(nsXTFElementWrapper,nsXTFElementWrapperBase) + +NS_IMETHODIMP +nsXTFElementWrapper::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + nsresult rv; + + if(aIID.Equals(NS_GET_IID(nsIClassInfo))) { + *aInstancePtr = NS_STATIC_CAST(nsIClassInfo*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + else if (aIID.Equals(NS_GET_IID(nsIXTFElementWrapperPrivate))) { + *aInstancePtr = NS_STATIC_CAST(nsIXTFElementWrapperPrivate*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + else if(aIID.Equals(NS_GET_IID(nsIXTFElementWrapper))) { + *aInstancePtr = NS_STATIC_CAST(nsIXTFElementWrapper*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + else if (NS_SUCCEEDED(rv = nsXTFElementWrapperBase::QueryInterface(aIID, aInstancePtr))) { + return rv; + } + else if (AggregatesInterface(aIID)) { +#ifdef DEBUG +// printf("nsXTFElementWrapper::QueryInterface(): creating aggregation tearoff\n"); +#endif + return NS_NewXTFInterfaceAggregator(aIID, GetXTFElement(), (nsIContent*)this, + (nsISupports**)aInstancePtr); + } + + return NS_ERROR_NO_INTERFACE; +} + +//---------------------------------------------------------------------- +// nsIContent methods: + +void +nsXTFElementWrapper::SetDocument(nsIDocument* aDocument, PRBool aDeep, + PRBool aCompileEventHandlers) +{ + // XXX For some reason we often get 2 SetDocument notifications with + // identical aDocument (one when expat encounters the element and + // another when the element is appended to its parent). We want to + // make sure that we only route notifications if the document has + // actually changed. + bool docReallyChanged = false; + if (aDocument!=GetCurrentDoc()) docReallyChanged = true; + + nsCOMPtr domDocument; + if (docReallyChanged && + mNotificationMask & (nsIXTFElement::NOTIFY_WILL_CHANGE_DOCUMENT | + nsIXTFElement::NOTIFY_DOCUMENT_CHANGED)) + domDocument = do_QueryInterface(aDocument); + + if (docReallyChanged && + (mNotificationMask & nsIXTFElement::NOTIFY_WILL_CHANGE_DOCUMENT)) + GetXTFElement()->WillChangeDocument(domDocument); + nsXTFElementWrapperBase::SetDocument(aDocument, aDeep, aCompileEventHandlers); + if (docReallyChanged && + (mNotificationMask & nsIXTFElement::NOTIFY_DOCUMENT_CHANGED)) + GetXTFElement()->DocumentChanged(domDocument); +} + +void +nsXTFElementWrapper::SetParent(nsIContent* aParent) +{ + nsCOMPtr domParent; + if (mNotificationMask & (nsIXTFElement::NOTIFY_WILL_CHANGE_PARENT | + nsIXTFElement::NOTIFY_PARENT_CHANGED)) + domParent = do_QueryInterface(aParent); + + if (mNotificationMask & nsIXTFElement::NOTIFY_WILL_CHANGE_PARENT) + GetXTFElement()->WillChangeParent(domParent); + nsXTFElementWrapperBase::SetParent(aParent); + if (mNotificationMask & nsIXTFElement::NOTIFY_PARENT_CHANGED) + GetXTFElement()->ParentChanged(domParent); +} + +nsresult +nsXTFElementWrapper::InsertChildAt(nsIContent* aKid, PRUint32 aIndex, + PRBool aNotify, PRBool aDeepSetDocument) +{ + nsresult rv; + + nsCOMPtr domKid; + if (mNotificationMask & (nsIXTFElement::NOTIFY_WILL_INSERT_CHILD | + nsIXTFElement::NOTIFY_CHILD_INSERTED)) + domKid = do_QueryInterface(aKid); + + if (mNotificationMask & nsIXTFElement::NOTIFY_WILL_INSERT_CHILD) + GetXTFElement()->WillInsertChild(domKid, aIndex); + rv = nsXTFElementWrapperBase::InsertChildAt(aKid, aIndex, aNotify, aDeepSetDocument); + if (mNotificationMask & nsIXTFElement::NOTIFY_CHILD_INSERTED) + GetXTFElement()->ChildInserted(domKid, aIndex); + + return rv; +} + +nsresult +nsXTFElementWrapper::AppendChildTo(nsIContent* aKid, PRBool aNotify, + PRBool aDeepSetDocument) +{ + nsresult rv; + + nsCOMPtr domKid; + if (mNotificationMask & (nsIXTFElement::NOTIFY_WILL_APPEND_CHILD | + nsIXTFElement::NOTIFY_CHILD_APPENDED)) + domKid = do_QueryInterface(aKid); + + if (mNotificationMask & nsIXTFElement::NOTIFY_WILL_APPEND_CHILD) + GetXTFElement()->WillAppendChild(domKid); + rv = nsXTFElementWrapperBase::AppendChildTo(aKid, aNotify, aDeepSetDocument); + if (mNotificationMask & nsIXTFElement::NOTIFY_CHILD_APPENDED) + GetXTFElement()->ChildAppended(domKid); + return rv; +} + +nsresult +nsXTFElementWrapper::RemoveChildAt(PRUint32 aIndex, PRBool aNotify) +{ + nsresult rv; + if (mNotificationMask & nsIXTFElement::NOTIFY_WILL_REMOVE_CHILD) + GetXTFElement()->WillRemoveChild(aIndex); + rv = nsXTFElementWrapperBase::RemoveChildAt(aIndex, aNotify); + if (mNotificationMask & nsIXTFElement::NOTIFY_CHILD_REMOVED) + GetXTFElement()->ChildRemoved(aIndex); + return rv; +} + +nsIAtom * +nsXTFElementWrapper::GetIDAttributeName() const +{ + // XXX: + return nsHTMLAtoms::id; +} + +nsresult +nsXTFElementWrapper::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + nsIAtom* aPrefix, const nsAString& aValue, + PRBool aNotify) +{ + nsresult rv; + + if (mNotificationMask & nsIXTFElement::NOTIFY_WILL_SET_ATTRIBUTE) + GetXTFElement()->WillSetAttribute(aName, aValue); + + if (aNameSpaceID==kNameSpaceID_None && HandledByInner(aName)) { + // XXX we don't do namespaced attributes yet + if (aNameSpaceID != kNameSpaceID_None) { + NS_WARNING("setattr: xtf elements don't do namespaced attribs yet!"); + return NS_ERROR_FAILURE; + } + rv = mAttributeHandler->SetAttribute(aName, aValue); + // XXX mutation events? + } + else { // let wrapper handle it + rv = nsXTFElementWrapperBase::SetAttr(aNameSpaceID, aName, aPrefix, aValue, aNotify); + } + + if (mNotificationMask & nsIXTFElement::NOTIFY_ATTRIBUTE_SET) + GetXTFElement()->AttributeSet(aName, aValue); + + return rv; +} + +nsresult +nsXTFElementWrapper::GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + nsAString& aResult) const +{ + if (aNameSpaceID==kNameSpaceID_None && HandledByInner(aName)) { + // XXX we don't do namespaced attributes yet + if (aNameSpaceID != kNameSpaceID_None) { + NS_WARNING("getattr: xtf elements don't do namespaced attribs yet!"); + return NS_CONTENT_ATTR_NOT_THERE; + } + nsresult rv = mAttributeHandler->GetAttribute(aName, aResult); + if (NS_FAILED(rv)) return rv; + if (aResult.IsVoid()) return NS_CONTENT_ATTR_NOT_THERE; + if (aResult.IsEmpty()) return NS_CONTENT_ATTR_NO_VALUE; + + return NS_CONTENT_ATTR_HAS_VALUE; + } + else { // try wrapper + return nsXTFElementWrapperBase::GetAttr(aNameSpaceID, aName, aResult); + } +} + +PRBool +nsXTFElementWrapper::HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const +{ + if (aNameSpaceID==kNameSpaceID_None && HandledByInner(aName)) { + PRBool rval = PR_FALSE; + mAttributeHandler->HasAttribute(aName, &rval); + return rval; + } + else { // try wrapper + return nsXTFElementWrapperBase::HasAttr(aNameSpaceID, aName); + } +} + + +nsresult +nsXTFElementWrapper::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr, + PRBool aNotify) +{ + nsresult rv; + + if (mNotificationMask & nsIXTFElement::NOTIFY_WILL_REMOVE_ATTRIBUTE) + GetXTFElement()->WillRemoveAttribute(aAttr); + + if (aNameSpaceID==kNameSpaceID_None && HandledByInner(aAttr)) { + // XXX we don't do namespaced attributes yet + if (aNameSpaceID != kNameSpaceID_None) { + NS_WARNING("setattr: xtf elements don't do namespaced attribs yet!"); + return NS_ERROR_FAILURE; + } + rv = mAttributeHandler->RemoveAttribute(aAttr); + // XXX mutation events? + } + else { // try wrapper + rv = nsXTFElementWrapperBase::UnsetAttr(aNameSpaceID, aAttr, aNotify); + } + + if (mNotificationMask & nsIXTFElement::NOTIFY_ATTRIBUTE_REMOVED) + GetXTFElement()->AttributeRemoved(aAttr); + + return rv; +} + +nsresult +nsXTFElementWrapper::GetAttrNameAt(PRUint32 aIndex, PRInt32* aNameSpaceID, + nsIAtom** aName, nsIAtom** aPrefix) const +{ + PRUint32 innerCount=0; + if (mAttributeHandler) { + mAttributeHandler->GetAttributeCount(&innerCount); + } + + if (aIndex < innerCount) { + *aNameSpaceID = kNameSpaceID_None; + *aPrefix = nsnull; + return mAttributeHandler->GetAttributeNameAt(aIndex, aName); + } + else { // wrapper handles attrib + return nsXTFElementWrapperBase::GetAttrNameAt(aIndex - innerCount, aNameSpaceID, + aName, aPrefix); + } +} + +PRUint32 +nsXTFElementWrapper::GetAttrCount() const +{ + PRUint32 innerCount = 0; + if (mAttributeHandler) { + mAttributeHandler->GetAttributeCount(&innerCount); + } + // add wrapper attribs + return innerCount + nsXTFElementWrapperBase::GetAttrCount(); +} + +void +nsXTFElementWrapper::DoneAddingChildren() +{ + if (mNotificationMask & nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN) + GetXTFElement()->DoneAddingChildren(); +} + +already_AddRefed +nsXTFElementWrapper::GetExistingAttrNameFromQName(const nsAString& aStr) const +{ + nsINodeInfo* nodeInfo = nsXTFElementWrapperBase::GetExistingAttrNameFromQName(aStr).get(); + + // Maybe this attribute is handled by our inner element: + if (!nodeInfo) { + nsCOMPtr nameAtom = do_GetAtom(aStr); + if (HandledByInner(nameAtom)) + mNodeInfo->NodeInfoManager()->GetNodeInfo(nameAtom, nsnull, kNameSpaceID_None, &nodeInfo); + } + + return nodeInfo; +} + +//---------------------------------------------------------------------- +// nsIDOMElement methods: + +NS_IMETHODIMP +nsXTFElementWrapper::GetAttribute(const nsAString& aName, nsAString& aReturn) +{ + const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName); + if (name) { + GetAttr(name->NamespaceID(), name->LocalName(), aReturn); + return NS_OK; + } + + // Maybe this attribute is handled by our inner element: + if (mAttributeHandler) { + nsresult rv = nsContentUtils::CheckQName(aName, PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr nameAtom = do_GetAtom(aName); + if (HandledByInner(nameAtom)) { + GetAttr(kNameSpaceID_None, nameAtom, aReturn); + return NS_OK; + } + } + + SetDOMStringToNull(aReturn); + return NS_OK; +} + +NS_IMETHODIMP +nsXTFElementWrapper::RemoveAttribute(const nsAString& aName) +{ + const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName); + + if (name) { + nsAttrName tmp(*name); + return UnsetAttr(name->NamespaceID(), name->LocalName(), PR_TRUE); + } + + // Maybe this attribute is handled by our inner element: + if (mAttributeHandler) { + nsCOMPtr nameAtom = do_GetAtom(aName); + return UnsetAttr(kNameSpaceID_None, nameAtom, PR_TRUE); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsXTFElementWrapper::HasAttribute(const nsAString& aName, PRBool* aReturn) +{ + const nsAttrName* name = InternalGetExistingAttrNameFromQName(aName); + if (name) { + *aReturn = PR_TRUE; + return NS_OK; + } + + // Maybe this attribute is handled by our inner element: + if (mAttributeHandler) { + nsCOMPtr nameAtom = do_GetAtom(aName); + *aReturn = HasAttr(kNameSpaceID_None, nameAtom); + return NS_OK; + } + + *aReturn = PR_FALSE; + return NS_OK; +} + + +//---------------------------------------------------------------------- +// nsIClassInfo implementation + +/* void getInterfaces (out PRUint32 count, [array, size_is (count), retval] out nsIIDPtr array); */ +NS_IMETHODIMP +nsXTFElementWrapper::GetInterfaces(PRUint32 *count, nsIID * **array) +{ + return GetXTFElement()->GetScriptingInterfaces(count, array); +} + +/* nsISupports getHelperForLanguage (in PRUint32 language); */ +NS_IMETHODIMP +nsXTFElementWrapper::GetHelperForLanguage(PRUint32 language, nsISupports **_retval) +{ + *_retval = nsnull; + return NS_OK; +} + +/* readonly attribute string contractID; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetContractID(char * *aContractID) +{ + *aContractID = nsnull; + return NS_OK; +} + +/* readonly attribute string classDescription; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetClassDescription(char * *aClassDescription) +{ + *aClassDescription = nsnull; + return NS_OK; +} + +/* readonly attribute nsCIDPtr classID; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetClassID(nsCID * *aClassID) +{ + *aClassID = nsnull; + return NS_OK; +} + +/* readonly attribute PRUint32 implementationLanguage; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetImplementationLanguage(PRUint32 *aImplementationLanguage) +{ + *aImplementationLanguage = nsIProgrammingLanguage::UNKNOWN; + return NS_OK; +} + +/* readonly attribute PRUint32 flags; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetFlags(PRUint32 *aFlags) +{ + *aFlags = nsIClassInfo::DOM_OBJECT; + return NS_OK; +} + +/* [notxpcom] readonly attribute nsCID classIDNoAlloc; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) +{ + return NS_ERROR_NOT_AVAILABLE; +} + +//---------------------------------------------------------------------- +// nsIXTFElementWrapper implementation: + +/* readonly attribute nsIDOMElement elementNode; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetElementNode(nsIDOMElement * *aElementNode) +{ + *aElementNode = (nsIDOMElement*)this; + NS_ADDREF(*aElementNode); + return NS_OK; +} + +/* readonly attribute nsIDOMElement documentFrameElement; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetDocumentFrameElement(nsIDOMElement * *aDocumentFrameElement) +{ + *aDocumentFrameElement = nsnull; + + nsIDocument *doc = GetCurrentDoc(); + if (!doc) { + NS_WARNING("no document"); + return NS_OK; + } + nsCOMPtr container = doc->GetContainer(); + if (!container) { + NS_ERROR("no docshell"); + return NS_ERROR_FAILURE; + } + nsCOMPtr pidomwin = do_GetInterface(container); + if (!pidomwin) { + NS_ERROR("no nsPIDOMWindow interface on docshell"); + return NS_ERROR_FAILURE; + } + *aDocumentFrameElement = pidomwin->GetFrameElementInternal(); + NS_IF_ADDREF(*aDocumentFrameElement); + return NS_OK; +} + +/* attribute unsigned long notificationMask; */ +NS_IMETHODIMP +nsXTFElementWrapper::GetNotificationMask(PRUint32 *aNotificationMask) +{ + *aNotificationMask = mNotificationMask; + return NS_OK; +} +NS_IMETHODIMP +nsXTFElementWrapper::SetNotificationMask(PRUint32 aNotificationMask) +{ + mNotificationMask = aNotificationMask; + return NS_OK; +} + +//---------------------------------------------------------------------- +// implementation helpers: +PRBool +nsXTFElementWrapper::AggregatesInterface(REFNSIID aIID) +{ + // We must ensure that the inner element has a distinct xpconnect + // identity, so we mustn't aggregate nsIXPConnectWrappedJS: + if (aIID.Equals(NS_GET_IID(nsIXPConnectWrappedJS))) return PR_FALSE; + + nsCOMPtr inst; + GetXTFElement()->QueryInterface(aIID, getter_AddRefs(inst)); + return (inst!=nsnull); +} + +PRBool +nsXTFElementWrapper::HandledByInner(nsIAtom *attr) const +{ + PRBool retval = PR_FALSE; + if (mAttributeHandler) + mAttributeHandler->HandlesAttribute(attr, &retval); + return retval; +} diff --git a/mozilla/content/xtf/src/nsXTFElementWrapper.h b/mozilla/content/xtf/src/nsXTFElementWrapper.h new file mode 100644 index 00000000000..fa40537778b --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFElementWrapper.h @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_XTFELEMENTWRAPPER_H__ +#define __NS_XTFELEMENTWRAPPER_H__ + +#include "nsIXTFElementWrapper.h" +#include "nsIXTFElementWrapperPrivate.h" +#include "nsXMLElement.h" +#include "nsIXTFAttributeHandler.h" + +class nsIXTFElement; + +typedef nsXMLElement nsXTFElementWrapperBase; + +// Pseudo IID for nsXTFElementWrapper +// {599EB85F-ABC0-4B52-A1B0-EA103D48E3AE} +#define NS_XTFELEMENTWRAPPER_IID \ +{ 0x599eb85f, 0xabc0, 0x4b52, { 0xa1, 0xb0, 0xea, 0x10, 0x3d, 0x48, 0xe3, 0xae } } + + +class nsXTFElementWrapper : public nsXTFElementWrapperBase, + public nsIXTFElementWrapper, + public nsIXTFElementWrapperPrivate, + public nsIClassInfo +{ +protected: + nsXTFElementWrapper(nsINodeInfo* aNodeInfo); + nsresult Init(); + +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_XTFELEMENTWRAPPER_IID) + + // nsISupports interface + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFElementWrapper + NS_DECL_NSIXTFELEMENTWRAPPER + + // nsIXTFElementWrapperPrivate + // to be implemented by subclass + // virtual PRUint32 GetElementType() = 0; + + // nsIContent specializations: + void SetDocument(nsIDocument* aDocument, PRBool aDeep, + PRBool aCompileEventHandlers); + void SetParent(nsIContent* aParent); + nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex, + PRBool aNotify, PRBool aDeepSetDocument); + nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify, + PRBool aDeepSetDocument); + nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify); + nsIAtom *GetIDAttributeName() const; + nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + nsIAtom* aPrefix, const nsAString& aValue, + PRBool aNotify); + nsresult GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + nsAString& aResult) const; + PRBool HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const; + nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr, + PRBool aNotify); + nsresult GetAttrNameAt(PRUint32 aIndex, PRInt32* aNameSpaceID, + nsIAtom** aName, nsIAtom** aPrefix) const; + PRUint32 GetAttrCount() const; + virtual already_AddRefed GetExistingAttrNameFromQName(const nsAString& aStr) const; + + virtual void DoneAddingChildren(); + + // nsIDOMElement specializations: + NS_IMETHOD GetAttribute(const nsAString& aName, + nsAString& aReturn); + NS_IMETHOD RemoveAttribute(const nsAString& aName); + NS_IMETHOD HasAttribute(const nsAString& aName, PRBool* aReturn); + + // nsIClassInfo interface + NS_DECL_NSICLASSINFO + +protected: + // to be implemented by subclasses: + virtual nsIXTFElement *GetXTFElement() const = 0; + + // implementation helpers: + PRBool AggregatesInterface(REFNSIID aIID); + + PRBool HandledByInner(nsIAtom* attr) const; + + PRUint32 mNotificationMask; + nsCOMPtr mAttributeHandler; +}; + +#endif // __NS_XTFELEMENTWRAPPER_H__ diff --git a/mozilla/content/xtf/src/nsXTFGenericElementWrapper.cpp b/mozilla/content/xtf/src/nsXTFGenericElementWrapper.cpp new file mode 100644 index 00000000000..096caa2af6d --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFGenericElementWrapper.cpp @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsXTFElementWrapper.h" +#include "nsIXTFGenericElement.h" +#include "nsXTFWeakTearoff.h" +#include "nsIXTFGenericElementWrapper.h" + +typedef nsXTFElementWrapper nsXTFGenericElementWrapperBase; + +//////////////////////////////////////////////////////////////////////// +// nsXTFGenericElementWrapper class +class nsXTFGenericElementWrapper : public nsXTFGenericElementWrapperBase, + public nsIXTFGenericElementWrapper +{ +protected: + friend nsresult + NS_NewXTFGenericElementWrapper(nsIXTFGenericElement* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + + nsXTFGenericElementWrapper(nsINodeInfo* aNodeInfo, nsIXTFGenericElement* xtfElement); + virtual ~nsXTFGenericElementWrapper(); + nsresult Init(); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFElementWrapperPrivate interface + virtual PRUint32 GetElementType() { return nsIXTFElement::ELEMENT_TYPE_GENERIC_ELEMENT; } + + // nsIXTFGenericElementWrapper interface + NS_DECL_NSIXTFGENERICELEMENTWRAPPER + + // nsIXTFElementWrapper interface + NS_FORWARD_NSIXTFELEMENTWRAPPER(nsXTFGenericElementWrapperBase::) + +private: + virtual nsIXTFElement *GetXTFElement() const { return mXTFElement; } + + nsCOMPtr mXTFElement; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXTFGenericElementWrapper::nsXTFGenericElementWrapper(nsINodeInfo* aNodeInfo, + nsIXTFGenericElement* xtfElement) + : nsXTFGenericElementWrapperBase(aNodeInfo), mXTFElement(xtfElement) +{ +#ifdef DEBUG +// printf("nsXTFGenericElementWrapper CTOR\n"); +#endif + NS_ASSERTION(mXTFElement, "xtfElement is null"); +} + +nsresult +nsXTFGenericElementWrapper::Init() +{ + nsXTFGenericElementWrapperBase::Init(); + + // pass a weak wrapper (non base object ref-counted), so that + // our mXTFElement can safely addref/release. + nsISupports *weakWrapper=nsnull; + NS_NewXTFWeakTearoff(NS_GET_IID(nsIXTFGenericElementWrapper), + (nsIXTFGenericElementWrapper*)this, + &weakWrapper); + if (!weakWrapper) { + NS_ERROR("could not construct weak wrapper"); + return NS_ERROR_FAILURE; + } + + mXTFElement->OnCreated((nsIXTFGenericElementWrapper*)weakWrapper); + weakWrapper->Release(); + + return NS_OK; +} + +nsXTFGenericElementWrapper::~nsXTFGenericElementWrapper() +{ + mXTFElement->OnDestroyed(); + mXTFElement = nsnull; + +#ifdef DEBUG +// printf("nsXTFGenericElementWrapper DTOR\n"); +#endif +} + +nsresult +NS_NewXTFGenericElementWrapper(nsIXTFGenericElement* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult) +{ + *aResult = nsnull; + + if (!xtfElement) { + NS_ERROR("can't construct an xtf wrapper without an xtf element"); + return NS_ERROR_FAILURE; + } + + nsXTFGenericElementWrapper* result = new nsXTFGenericElementWrapper(ni, xtfElement); + if (!result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + + nsresult rv = result->Init(); + + if (NS_FAILED(rv)) { + NS_RELEASE(result); + return rv; + } + + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports implementation + + +NS_IMPL_ADDREF_INHERITED(nsXTFGenericElementWrapper, nsXTFGenericElementWrapperBase) +NS_IMPL_RELEASE_INHERITED(nsXTFGenericElementWrapper, nsXTFGenericElementWrapperBase) + +NS_INTERFACE_MAP_BEGIN(nsXTFGenericElementWrapper) + NS_INTERFACE_MAP_ENTRY(nsIXTFGenericElementWrapper) +NS_INTERFACE_MAP_END_INHERITING(nsXTFGenericElementWrapperBase) + +//---------------------------------------------------------------------- +// nsIXTFGenericElementWrapper implementation: + +// XXX nothing yet + diff --git a/mozilla/content/xtf/src/nsXTFGenericElementWrapper.h b/mozilla/content/xtf/src/nsXTFGenericElementWrapper.h new file mode 100644 index 00000000000..b1dd5bac97a --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFGenericElementWrapper.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_XTFGENERICELEMENTWRAPPER_H__ +#define __NS_XTFGENERICELEMENTWRAPPER_H__ + +class nsIXTFGenericElement; +class nsIContent; +class nsINodeInfo; + +nsresult +NS_NewXTFGenericElementWrapper(nsIXTFGenericElement* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + +#endif // __NS_XTFGENERICELEMENTWRAPPER_H__ diff --git a/mozilla/content/xtf/src/nsXTFInterfaceAggregator.cpp b/mozilla/content/xtf/src/nsXTFInterfaceAggregator.cpp new file mode 100644 index 00000000000..8d1cd9b0a9d --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFInterfaceAggregator.cpp @@ -0,0 +1,179 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "xptcall.h" +#include "nsIInterfaceInfo.h" +#include "nsIInterfaceInfoManager.h" +#ifdef DEBUG +#include +#endif + +//////////////////////////////////////////////////////////////////////// +// nsXTFInterfaceAggregator class + +class nsXTFInterfaceAggregator : public nsXPTCStubBase +{ +protected: + friend nsresult + NS_NewXTFInterfaceAggregator(const nsIID& iid, + nsISupports* inner, + nsISupports* outer, + nsISupports** result); + + nsXTFInterfaceAggregator(const nsIID& iid, + nsISupports* inner, + nsISupports* outer); + ~nsXTFInterfaceAggregator(); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsXPTCStubBase + NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info); + + NS_IMETHOD CallMethod(PRUint16 methodIndex, + const nsXPTMethodInfo* info, + nsXPTCMiniVariant* params); + +private: + nsISupports *mInner; + nsISupports *mOuter; + nsIID mIID; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXTFInterfaceAggregator::nsXTFInterfaceAggregator(const nsIID& iid, + nsISupports* inner, + nsISupports* outer) + : mOuter(outer), mIID(iid) +{ +#ifdef DEBUG +// printf("nsXTFInterfaceAggregator CTOR\n"); +#endif + inner->QueryInterface(iid, (void**)&mInner); + mOuter->AddRef(); +} + +nsXTFInterfaceAggregator::~nsXTFInterfaceAggregator() +{ +#ifdef DEBUG +// printf("nsXTFInterfaceAggregator DTOR\n"); +#endif + mInner->Release(); + mOuter->Release(); +} + +nsresult +NS_NewXTFInterfaceAggregator(const nsIID& iid, + nsISupports* inner, + nsISupports* outer, + nsISupports** aResult){ + NS_PRECONDITION(aResult != nsnull, "null ptr"); + if (!aResult) + return NS_ERROR_NULL_POINTER; + + nsXTFInterfaceAggregator* result = new nsXTFInterfaceAggregator(iid,inner,outer); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports implementation + +NS_IMPL_ADDREF(nsXTFInterfaceAggregator) +NS_IMPL_RELEASE(nsXTFInterfaceAggregator) + +NS_IMETHODIMP +nsXTFInterfaceAggregator::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if(aIID.Equals(mIID)) { + *aInstancePtr = NS_STATIC_CAST(nsXPTCStubBase*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + else return mOuter->QueryInterface(aIID, aInstancePtr); +} + +//---------------------------------------------------------------------- +// nsXPTCStubBase implementation + +NS_IMETHODIMP +nsXTFInterfaceAggregator::GetInterfaceInfo(nsIInterfaceInfo** info) +{ + nsCOMPtr iim = XPTI_GetInterfaceInfoManager(); + NS_ASSERTION(iim, "could not get interface info manager"); + return iim->GetInfoForIID( &mIID, info); +} + +NS_IMETHODIMP +nsXTFInterfaceAggregator::CallMethod(PRUint16 methodIndex, + const nsXPTMethodInfo* info, + nsXPTCMiniVariant* params) +{ + if (methodIndex < 3) { + NS_ERROR("huh? indirect nsISupports method call unexpected on nsXTFInterfaceAggregator."); + return NS_ERROR_FAILURE; + } + + // prepare args: + int paramCount = info->GetParamCount(); + nsXPTCVariant* fullPars = paramCount ? new nsXPTCVariant[paramCount] : nsnull; + + for (int i=0; iGetParam(i); + PRUint8 flags = paramInfo.IsOut() ? nsXPTCVariant::PTR_IS_DATA : 0; + fullPars[i].Init(params[i], paramInfo.GetType(), flags); + } + + // make the call: + nsresult rv = XPTC_InvokeByIndex(mInner, + methodIndex, + paramCount, + fullPars); + if (fullPars) + delete []fullPars; + return rv; +} diff --git a/mozilla/content/xtf/src/nsXTFInterfaceAggregator.h b/mozilla/content/xtf/src/nsXTFInterfaceAggregator.h new file mode 100644 index 00000000000..624b5bfaafa --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFInterfaceAggregator.h @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_XTFINTERFACEAGGREGATOR_H__ +#define __NS_XTFINTERFACEAGGREGATOR_H__ + +nsresult +NS_NewXTFInterfaceAggregator(const nsIID& iid, + nsISupports* inner, + nsISupports* outer, + nsISupports** result); + + +#endif // __NS_XTFINTERFACEAGGREGATOR_H__ diff --git a/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.cpp b/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.cpp new file mode 100644 index 00000000000..f5c003539d0 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.cpp @@ -0,0 +1,172 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsXTFVisualWrapper.h" +#include "nsIXTFSVGVisual.h" +#include "nsXTFWeakTearoff.h" +#include "nsIXTFSVGVisualWrapper.h" + +typedef nsXTFVisualWrapper nsXTFSVGVisualWrapperBase; + +//////////////////////////////////////////////////////////////////////// +// nsXTFSVGVisualWrapper class +class nsXTFSVGVisualWrapper : public nsXTFSVGVisualWrapperBase, + public nsIXTFSVGVisualWrapper +{ +protected: + friend nsresult + NS_NewXTFSVGVisualWrapper(nsIXTFSVGVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + + nsXTFSVGVisualWrapper(nsINodeInfo* ni, nsIXTFSVGVisual* xtfElement); + virtual ~nsXTFSVGVisualWrapper(); + nsresult Init(); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFElementWrapperPrivate interface + virtual PRUint32 GetElementType() { return nsIXTFElement::ELEMENT_TYPE_SVG_VISUAL; } + + // nsIXTFSVGVisualWrapper interface + NS_DECL_NSIXTFSVGVISUALWRAPPER + + // nsIXTFElementWrapper interface + NS_FORWARD_NSIXTFELEMENTWRAPPER(nsXTFSVGVisualWrapperBase::) + +private: + virtual nsIXTFElement *GetXTFElement() const { return mXTFElement; } + virtual nsIXTFVisual *GetXTFVisual() const { return mXTFElement; } + + nsCOMPtr mXTFElement; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXTFSVGVisualWrapper::nsXTFSVGVisualWrapper(nsINodeInfo* aNodeInfo, + nsIXTFSVGVisual* xtfElement) + : nsXTFSVGVisualWrapperBase(aNodeInfo), mXTFElement(xtfElement) +{ +#ifdef DEBUG +// printf("nsXTFSVGVisualWrapper CTOR\n"); +#endif + NS_ASSERTION(mXTFElement, "xtfElement is null"); +} + +nsresult +nsXTFSVGVisualWrapper::Init() +{ + nsXTFSVGVisualWrapperBase::Init(); + + // pass a weak wrapper (non base object ref-counted), so that + // our mXTFElement can safely addref/release. + nsISupports *weakWrapper=nsnull; + NS_NewXTFWeakTearoff(NS_GET_IID(nsIXTFSVGVisualWrapper), + (nsIXTFSVGVisualWrapper*)this, + &weakWrapper); + if (!weakWrapper) { + NS_ERROR("could not construct weak wrapper"); + return NS_ERROR_FAILURE; + } + + mXTFElement->OnCreated((nsIXTFSVGVisualWrapper*)weakWrapper); + weakWrapper->Release(); + + return NS_OK; +} + +nsXTFSVGVisualWrapper::~nsXTFSVGVisualWrapper() +{ + mXTFElement->OnDestroyed(); + mXTFElement = nsnull; + +#ifdef DEBUG +// printf("nsXTFSVGVisualWrapper DTOR\n"); +#endif +} + +nsresult +NS_NewXTFSVGVisualWrapper(nsIXTFSVGVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult) +{ + *aResult = nsnull; + + if (!xtfElement) { + NS_ERROR("can't construct an xtf wrapper without an xtf element"); + return NS_ERROR_FAILURE; + } + + nsXTFSVGVisualWrapper* result = new nsXTFSVGVisualWrapper(ni, xtfElement); + if (!result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + + nsresult rv = result->Init(); + + if (NS_FAILED(rv)) { + NS_RELEASE(result); + return rv; + } + + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports implementation + + +NS_IMPL_ADDREF_INHERITED(nsXTFSVGVisualWrapper, nsXTFSVGVisualWrapperBase) +NS_IMPL_RELEASE_INHERITED(nsXTFSVGVisualWrapper, nsXTFSVGVisualWrapperBase) + +NS_INTERFACE_MAP_BEGIN(nsXTFSVGVisualWrapper) + NS_INTERFACE_MAP_ENTRY(nsIXTFSVGVisualWrapper) +NS_INTERFACE_MAP_END_INHERITING(nsXTFSVGVisualWrapperBase) + +//---------------------------------------------------------------------- +// nsIXTFSVGVisualWrapper implementation: + +// XXX nothing yet + + diff --git a/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.h b/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.h new file mode 100644 index 00000000000..867e0aca4c3 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFSVGVisualWrapper.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_XTFSVGVISUALWRAPPER_H__ +#define __NS_XTFSVGVISUALWRAPPER_H__ + +class nsIXTFSVGVisual; +class nsIContent; +class nsINodeInfo; + +nsresult +NS_NewXTFSVGVisualWrapper(nsIXTFSVGVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + +#endif // __NS_XTFSVGVISUALWRAPPER_H__ diff --git a/mozilla/content/xtf/src/nsXTFService.cpp b/mozilla/content/xtf/src/nsXTFService.cpp new file mode 100644 index 00000000000..e29697ea9e2 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFService.cpp @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsINodeInfo.h" +#include "nsIServiceManager.h" +#include "nsIXTFElement.h" +#include "nsIXTFElementFactory.h" +#include "nsIXTFGenericElement.h" +#include "nsIXTFService.h" +#include "nsIXTFXMLVisual.h" +#include "nsIXTFXULVisual.h" +#include "nsInterfaceHashtable.h" +#include "nsString.h" +#include "nsXTFGenericElementWrapper.h" +#include "nsXTFXMLVisualWrapper.h" +#include "nsXTFXULVisualWrapper.h" + +#ifdef MOZ_SVG +#include "nsXTFSVGVisualWrapper.h" +#include "nsIXTFSVGVisual.h" +#endif + +//////////////////////////////////////////////////////////////////////// +// nsXTFService class +class nsXTFService : public nsIXTFService +{ +protected: + friend nsresult NS_NewXTFService(nsIXTFService** aResult); + + nsXTFService(); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsIXTFService interface + nsresult CreateElement(nsIContent** aResult, nsINodeInfo* aNodeInfo); + +private: + nsInterfaceHashtable mFactoryHash; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXTFService::nsXTFService() +{ + mFactoryHash.Init(); // XXX this can fail. move to Init() +} + +nsresult +NS_NewXTFService(nsIXTFService** aResult) +{ + NS_PRECONDITION(aResult != nsnull, "null ptr"); + if (! aResult) + return NS_ERROR_NULL_POINTER; + + nsXTFService* result = new nsXTFService(); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports methods + +NS_IMPL_ISUPPORTS1(nsXTFService, nsIXTFService); + +//---------------------------------------------------------------------- +// nsIXTFService methods + +nsresult +nsXTFService::CreateElement(nsIContent** aResult, nsINodeInfo* aNodeInfo) +{ + nsCOMPtr factory; + + // Check if we have an xtf factory for the given namespaceid in our cache: + if (!mFactoryHash.Get(aNodeInfo->NamespaceID(), getter_AddRefs(factory))) { + // No. See if there is one registered with the component manager: + nsCAutoString xtf_contract_id(NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX); + nsAutoString uri; + aNodeInfo->GetNamespaceURI(uri); + AppendUTF16toUTF8(uri, xtf_contract_id); +#ifdef DEBUG + printf("Testing for XTF factory at %s\n", xtf_contract_id.get()); +#endif + factory = do_GetService(xtf_contract_id.get()); + if (factory) { +#ifdef DEBUG + printf("We've got an XTF factory.\n"); +#endif + // Put into hash: + mFactoryHash.Put(aNodeInfo->NamespaceID(), factory); + } + } + if (!factory) return NS_ERROR_FAILURE; + + // We have an xtf factory. Now try to create an element for the given tag name: + nsCOMPtr elem; + nsAutoString tagName; + aNodeInfo->GetName(tagName); + factory->CreateElement(tagName, getter_AddRefs(elem)); + if (!elem) return NS_ERROR_FAILURE; + + // We've got an xtf element. Create an appropriate wrapper for it: + PRUint32 elementType; + elem->GetElementType(&elementType); + switch (elementType) { + case nsIXTFElement::ELEMENT_TYPE_GENERIC_ELEMENT: + { + nsCOMPtr elem2 = do_QueryInterface(elem); + return NS_NewXTFGenericElementWrapper(elem2, aNodeInfo, aResult); + break; + } + case nsIXTFElement::ELEMENT_TYPE_SVG_VISUAL: + { +#ifdef MOZ_SVG + nsCOMPtr elem2 = do_QueryInterface(elem); + return NS_NewXTFSVGVisualWrapper(elem2, aNodeInfo, aResult); +#else + NS_ERROR("xtf svg visuals are only supported in mozilla builds with native svg support"); +#endif + break; + } + case nsIXTFElement::ELEMENT_TYPE_XML_VISUAL: + { + nsCOMPtr elem2 = do_QueryInterface(elem); + return NS_NewXTFXMLVisualWrapper(elem2, aNodeInfo, aResult); + break; + } + case nsIXTFElement::ELEMENT_TYPE_XUL_VISUAL: + { + nsCOMPtr elem2 = do_QueryInterface(elem); + return NS_NewXTFXULVisualWrapper(elem2, aNodeInfo, aResult); + break; + } + default: + NS_ERROR("unknown xtf element type"); + break; + } + return NS_ERROR_FAILURE; +} + diff --git a/mozilla/content/xtf/src/nsXTFVisualWrapper.cpp b/mozilla/content/xtf/src/nsXTFVisualWrapper.cpp new file mode 100644 index 00000000000..fe3f6f5c9f1 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFVisualWrapper.cpp @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsXTFVisualWrapper.h" +#include "nsISupportsArray.h" +#include "nsIPresShell.h" +#include "nsPresContext.h" +#include "nsIDocument.h" + +nsXTFVisualWrapper::nsXTFVisualWrapper(nsINodeInfo* aNodeInfo) + : nsXTFVisualWrapperBase(aNodeInfo) +{} + +//---------------------------------------------------------------------- +// nsISupports implementation + + +NS_IMPL_ADDREF_INHERITED(nsXTFVisualWrapper,nsXTFVisualWrapperBase) +NS_IMPL_RELEASE_INHERITED(nsXTFVisualWrapper,nsXTFVisualWrapperBase) + +NS_INTERFACE_MAP_BEGIN(nsXTFVisualWrapper) + NS_INTERFACE_MAP_ENTRY(nsIXTFVisualWrapperPrivate) +NS_INTERFACE_MAP_END_INHERITING(nsXTFVisualWrapperBase) + +//---------------------------------------------------------------------- +// nsIXTFVisualWrapperPrivate implementation: + +NS_IMETHODIMP +nsXTFVisualWrapper::CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems) +{ + nsIDocument *doc = GetCurrentDoc(); + NS_ASSERTION(doc, "no document; cannot create anonymous content"); + + if (!mVisualContent) { + GetXTFVisual()->GetVisualContent(getter_AddRefs(mVisualContent)); + } + if (!mVisualContent) return NS_OK; // nothing to append + + // Check if we are creating content for the primary presShell + bool isPrimaryShell = + (aPresContext->PresShell() == doc->GetShellAt(0)); + + nsCOMPtr contentToAppend; + if (!isPrimaryShell) { + // The presShell we are generating content for is not a primary + // shell. In practice that means it means we are constructing + // content for printing. Instead of asking the xtf element to + // construct new visual content, we just clone the exisiting + // content. In this way, the xtf element only ever has to provide + // one visual content tree which it can dynamically manipulate. + mVisualContent->CloneNode(PR_TRUE, getter_AddRefs(contentToAppend)); + } + else + contentToAppend = mVisualContent; + + if (contentToAppend) + aAnonymousItems.AppendElement(contentToAppend); + + return NS_OK; +} + +void +nsXTFVisualWrapper::DidLayout() +{ + if (mNotificationMask & nsIXTFVisual::NOTIFY_DID_LAYOUT) + GetXTFVisual()->DidLayout(); +} + +void +nsXTFVisualWrapper::GetInsertionPoint(nsIDOMElement** insertionPoint) +{ + GetXTFVisual()->GetInsertionPoint(insertionPoint); +} + +PRBool +nsXTFVisualWrapper::ApplyDocumentStyleSheets() +{ + PRBool retval = PR_FALSE; + GetXTFVisual()->GetApplyDocumentStyleSheets(&retval); + return retval; +} diff --git a/mozilla/content/xtf/src/nsXTFVisualWrapper.h b/mozilla/content/xtf/src/nsXTFVisualWrapper.h new file mode 100644 index 00000000000..61e8825b9bb --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFVisualWrapper.h @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_XTFVISUALWRAPPER_H__ +#define __NS_XTFVISUALWRAPPER_H__ + +#include "nsXTFElementWrapper.h" +#include "nsIDOMElement.h" +#include "nsIXTFVisualWrapperPrivate.h" +#include "nsIXTFVisual.h" + +typedef nsXTFElementWrapper nsXTFVisualWrapperBase; + +class nsXTFVisualWrapper : public nsXTFVisualWrapperBase, + public nsIXTFVisualWrapperPrivate +{ +protected: + nsXTFVisualWrapper(nsINodeInfo* aNodeInfo); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFVisualWrapperPrivate + NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems); + virtual void DidLayout(); + virtual void GetInsertionPoint(nsIDOMElement** insertionPoint); + virtual PRBool ApplyDocumentStyleSheets(); + +protected: + // to be implemented by subclasses: + virtual nsIXTFVisual *GetXTFVisual() const = 0; + + nsCOMPtr mVisualContent; +}; + +#endif // __NS_XTFVISUALWRAPPER_H__ diff --git a/mozilla/content/xtf/src/nsXTFWeakTearoff.cpp b/mozilla/content/xtf/src/nsXTFWeakTearoff.cpp new file mode 100644 index 00000000000..4dbba622f65 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFWeakTearoff.cpp @@ -0,0 +1,173 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "xptcall.h" +#include "nsIInterfaceInfo.h" +#include "nsIInterfaceInfoManager.h" +#ifdef DEBUG +#include +#endif + +//////////////////////////////////////////////////////////////////////// +// nsXTFWeakTearoff class + +class nsXTFWeakTearoff : public nsXPTCStubBase +{ +protected: + friend nsresult + NS_NewXTFWeakTearoff(const nsIID& iid, + nsISupports* obj, + nsISupports** result); + + nsXTFWeakTearoff(const nsIID& iid, + nsISupports* obj); + ~nsXTFWeakTearoff(); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsXPTCStubBase + NS_IMETHOD GetInterfaceInfo(nsIInterfaceInfo** info); + + NS_IMETHOD CallMethod(PRUint16 methodIndex, + const nsXPTMethodInfo* info, + nsXPTCMiniVariant* params); + +private: + nsISupports *mObj; + nsIID mIID; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXTFWeakTearoff::nsXTFWeakTearoff(const nsIID& iid, + nsISupports* obj) + : mObj(obj), mIID(iid) +{ +#ifdef DEBUG +// printf("nsXTFWeakTearoff CTOR\n"); +#endif +} + +nsXTFWeakTearoff::~nsXTFWeakTearoff() +{ +#ifdef DEBUG +// printf("nsXTFWeakTearoff DTOR\n"); +#endif +} + +nsresult +NS_NewXTFWeakTearoff(const nsIID& iid, + nsISupports* obj, + nsISupports** aResult){ + NS_PRECONDITION(aResult != nsnull, "null ptr"); + if (!aResult) + return NS_ERROR_NULL_POINTER; + + nsXTFWeakTearoff* result = new nsXTFWeakTearoff(iid,obj); + if (! result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports implementation + +NS_IMPL_ADDREF(nsXTFWeakTearoff) +NS_IMPL_RELEASE(nsXTFWeakTearoff) + +NS_IMETHODIMP +nsXTFWeakTearoff::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if(aIID.Equals(mIID) || aIID.Equals(NS_GET_IID(nsISupports))) { + *aInstancePtr = NS_STATIC_CAST(nsXPTCStubBase*, this); + NS_ADDREF_THIS(); + return NS_OK; + } + // we can't map QI onto the obj, because the xpcom wrapper otherwise + // QI-accumulates all interfaces defined on mObj +// else return mObj->QueryInterface(aIID, aInstancePtr); + else return NS_ERROR_NO_INTERFACE; +} + +//---------------------------------------------------------------------- +// nsXPTCStubBase implementation + +NS_IMETHODIMP +nsXTFWeakTearoff::GetInterfaceInfo(nsIInterfaceInfo** info) +{ + nsCOMPtr iim = XPTI_GetInterfaceInfoManager(); + NS_ASSERTION(iim, "could not get interface info manager"); + return iim->GetInfoForIID( &mIID, info); +} + +NS_IMETHODIMP +nsXTFWeakTearoff::CallMethod(PRUint16 methodIndex, + const nsXPTMethodInfo* info, + nsXPTCMiniVariant* params) +{ + if (methodIndex < 3) { + NS_ERROR("huh? indirect nsISupports method call unexpected on nsXTFWeakTearoff."); + return NS_ERROR_FAILURE; + } + + // prepare args: + int paramCount = info->GetParamCount(); + nsXPTCVariant* fullPars = paramCount ? new nsXPTCVariant[paramCount] : nsnull; + + for (int i=0; iGetParam(i); + uint8 flags = paramInfo.IsOut() ? nsXPTCVariant::PTR_IS_DATA : 0; + fullPars[i].Init(params[i], paramInfo.GetType(), flags); + } + + // make the call: + nsresult rv = XPTC_InvokeByIndex(mObj, + methodIndex, + paramCount, + fullPars); + if (fullPars) + delete []fullPars; + return rv; +} diff --git a/mozilla/content/xtf/src/nsXTFWeakTearoff.h b/mozilla/content/xtf/src/nsXTFWeakTearoff.h new file mode 100644 index 00000000000..64db4506ef9 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFWeakTearoff.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_XTFWEAKTEAROFF_H__ +#define __NS_XTFWEAKTEAROFF_H__ + +nsresult +NS_NewXTFWeakTearoff(const nsIID& iid, + nsISupports* obj, + nsISupports** result); + + +#endif // __NS_XTFWEAKTEAROFF_H__ diff --git a/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.cpp b/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.cpp new file mode 100644 index 00000000000..3a2aff449c8 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.cpp @@ -0,0 +1,175 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsXTFVisualWrapper.h" +#include "nsIXTFXMLVisual.h" +#include "nsXTFWeakTearoff.h" +#include "nsIXTFXMLVisualWrapper.h" + +typedef nsXTFVisualWrapper nsXTFXMLVisualWrapperBase; + +//////////////////////////////////////////////////////////////////////// +// nsXTFXMLVisualWrapper class +class nsXTFXMLVisualWrapper : public nsXTFXMLVisualWrapperBase, + public nsIXTFXMLVisualWrapper +{ +protected: + friend nsresult + NS_NewXTFXMLVisualWrapper(nsIXTFXMLVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + + nsXTFXMLVisualWrapper(nsINodeInfo* ni, nsIXTFXMLVisual* xtfElement); + virtual ~nsXTFXMLVisualWrapper(); + nsresult Init(); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFElementWrapperPrivate interface + virtual PRUint32 GetElementType() { return nsIXTFElement::ELEMENT_TYPE_XML_VISUAL; } + + // nsIXTFXMLVisualWrapper interface + NS_DECL_NSIXTFXMLVISUALWRAPPER + + // nsIXTFElementWrapper interface + NS_FORWARD_NSIXTFELEMENTWRAPPER(nsXTFXMLVisualWrapperBase::) + +private: + virtual nsIXTFElement *GetXTFElement() const { return mXTFElement; } + virtual nsIXTFVisual *GetXTFVisual() const { return mXTFElement; } + + nsCOMPtr mXTFElement; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXTFXMLVisualWrapper::nsXTFXMLVisualWrapper(nsINodeInfo* aNodeInfo, + nsIXTFXMLVisual* xtfElement) + : nsXTFXMLVisualWrapperBase(aNodeInfo), mXTFElement(xtfElement) +{ +#ifdef DEBUG +// printf("nsXTFXMLVisualWrapper CTOR\n"); +#endif + NS_ASSERTION(mXTFElement, "xtfElement is null"); +} + +nsresult +nsXTFXMLVisualWrapper::Init() +{ + nsXTFXMLVisualWrapperBase::Init(); + + // pass a weak wrapper (non base object ref-counted), so that + // our mXTFElement can safely addref/release. + nsISupports *weakWrapper=nsnull; + NS_NewXTFWeakTearoff(NS_GET_IID(nsIXTFXMLVisualWrapper), + (nsIXTFXMLVisualWrapper*)this, + &weakWrapper); + if (!weakWrapper) { + NS_ERROR("could not construct weak wrapper"); + return NS_ERROR_FAILURE; + } + + mXTFElement->OnCreated((nsIXTFXMLVisualWrapper*)weakWrapper); + weakWrapper->Release(); + + return NS_OK; +} + +nsXTFXMLVisualWrapper::~nsXTFXMLVisualWrapper() +{ + mXTFElement->OnDestroyed(); + mXTFElement = nsnull; + +#ifdef DEBUG +// printf("nsXTFXMLVisualWrapper DTOR\n"); +#endif +} + +nsresult +NS_NewXTFXMLVisualWrapper(nsIXTFXMLVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult) +{ + *aResult = nsnull; + + if (!xtfElement) { + NS_ERROR("can't construct an xtf wrapper without an xtf element"); + return NS_ERROR_FAILURE; + } + + nsXTFXMLVisualWrapper* result = new nsXTFXMLVisualWrapper(ni, xtfElement); + if (!result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + + nsresult rv = result->Init(); + + if (NS_FAILED(rv)) { + NS_RELEASE(result); + return rv; + } + + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports implementation + + +NS_IMPL_ADDREF_INHERITED(nsXTFXMLVisualWrapper,nsXTFXMLVisualWrapperBase) +NS_IMPL_RELEASE_INHERITED(nsXTFXMLVisualWrapper,nsXTFXMLVisualWrapperBase) + +NS_INTERFACE_MAP_BEGIN(nsXTFXMLVisualWrapper) + NS_INTERFACE_MAP_ENTRY(nsIXTFXMLVisualWrapper) +NS_INTERFACE_MAP_END_INHERITING(nsXTFXMLVisualWrapperBase) + +//---------------------------------------------------------------------- +// nsIXTFXMLVisualWrapper implementation: + +// XXX nothing yet + + + + + diff --git a/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.h b/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.h new file mode 100644 index 00000000000..0f0509b5198 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFXMLVisualWrapper.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_XTFXMLVISUALWRAPPER_H__ +#define __NS_XTFXMLVISUALWRAPPER_H__ + +class nsIXTFXMLVisual; +class nsIContent; +class nsINodeInfo; + +nsresult +NS_NewXTFXMLVisualWrapper(nsIXTFXMLVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + +#endif // __NS_XTFXMLVISUALWRAPPER_H__ diff --git a/mozilla/content/xtf/src/nsXTFXULVisualWrapper.cpp b/mozilla/content/xtf/src/nsXTFXULVisualWrapper.cpp new file mode 100644 index 00000000000..0d7e5d5b807 --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFXULVisualWrapper.cpp @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsXTFVisualWrapper.h" +#include "nsIXTFXULVisual.h" +#include "nsXTFWeakTearoff.h" +#include "nsIXTFXULVisualWrapper.h" + +typedef nsXTFVisualWrapper nsXTFXULVisualWrapperBase; + +//////////////////////////////////////////////////////////////////////// +// nsXTFXULVisualWrapper class +class nsXTFXULVisualWrapper : public nsXTFXULVisualWrapperBase, + public nsIXTFXULVisualWrapper +{ +protected: + friend nsresult + NS_NewXTFXULVisualWrapper(nsIXTFXULVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + + nsXTFXULVisualWrapper(nsINodeInfo* ni, nsIXTFXULVisual* xtfElement); + virtual ~nsXTFXULVisualWrapper(); + nsresult Init(); + +public: + // nsISupports interface + NS_DECL_ISUPPORTS_INHERITED + + // nsIXTFElementWrapperPrivate interface + virtual PRUint32 GetElementType() { return nsIXTFElement::ELEMENT_TYPE_XUL_VISUAL; } + + // nsIXTFXULVisualWrapper interface + NS_DECL_NSIXTFXULVISUALWRAPPER + + // nsIXTFElementWrapper interface + NS_FORWARD_NSIXTFELEMENTWRAPPER(nsXTFXULVisualWrapperBase::) + +private: + virtual nsIXTFElement *GetXTFElement() const { return mXTFElement; } + virtual nsIXTFVisual *GetXTFVisual() const { return mXTFElement; } + + nsCOMPtr mXTFElement; +}; + +//---------------------------------------------------------------------- +// implementation: + +nsXTFXULVisualWrapper::nsXTFXULVisualWrapper(nsINodeInfo* aNodeInfo, + nsIXTFXULVisual* xtfElement) + : nsXTFXULVisualWrapperBase(aNodeInfo), mXTFElement(xtfElement) +{ +#ifdef DEBUG +// printf("nsXTFXULVisualWrapper CTOR\n"); +#endif + NS_ASSERTION(mXTFElement, "xtfElement is null"); +} + +nsresult +nsXTFXULVisualWrapper::Init() +{ + nsXTFXULVisualWrapperBase::Init(); + + // pass a weak wrapper (non base object ref-counted), so that + // our mXTFElement can safely addref/release. + nsISupports *weakWrapper=nsnull; + NS_NewXTFWeakTearoff(NS_GET_IID(nsIXTFXULVisualWrapper), + (nsIXTFXULVisualWrapper*)this, + &weakWrapper); + if (!weakWrapper) { + NS_ERROR("could not construct weak wrapper"); + return NS_ERROR_FAILURE; + } + + mXTFElement->OnCreated((nsIXTFXULVisualWrapper*)weakWrapper); + weakWrapper->Release(); + + return NS_OK; +} + +nsXTFXULVisualWrapper::~nsXTFXULVisualWrapper() +{ + mXTFElement->OnDestroyed(); + mXTFElement = nsnull; + +#ifdef DEBUG +// printf("nsXTFXULVisualWrapper DTOR\n"); +#endif +} + +nsresult +NS_NewXTFXULVisualWrapper(nsIXTFXULVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult) +{ + *aResult = nsnull; + + if (!xtfElement) { + NS_ERROR("can't construct an xtf wrapper without an xtf element"); + return NS_ERROR_FAILURE; + } + + nsXTFXULVisualWrapper* result = new nsXTFXULVisualWrapper(ni, xtfElement); + if (!result) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(result); + + nsresult rv = result->Init(); + + if (NS_FAILED(rv)) { + NS_RELEASE(result); + return rv; + } + + *aResult = result; + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports implementation + + +NS_IMPL_ADDREF_INHERITED(nsXTFXULVisualWrapper,nsXTFXULVisualWrapperBase) +NS_IMPL_RELEASE_INHERITED(nsXTFXULVisualWrapper,nsXTFXULVisualWrapperBase) + +NS_INTERFACE_MAP_BEGIN(nsXTFXULVisualWrapper) + NS_INTERFACE_MAP_ENTRY(nsIXTFXULVisualWrapper) +NS_INTERFACE_MAP_END_INHERITING(nsXTFXULVisualWrapperBase) + +//---------------------------------------------------------------------- +// nsIXTFXULVisualWrapper implementation: + +// XXX nothing yet diff --git a/mozilla/content/xtf/src/nsXTFXULVisualWrapper.h b/mozilla/content/xtf/src/nsXTFXULVisualWrapper.h new file mode 100644 index 00000000000..3ba0afc264a --- /dev/null +++ b/mozilla/content/xtf/src/nsXTFXULVisualWrapper.h @@ -0,0 +1,51 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#ifndef __NS_XTFXULVISUALWRAPPER_H__ +#define __NS_XTFXULVISUALWRAPPER_H__ + +class nsIXTFXULVisual; +class nsIContent; +class nsINodeInfo; + +nsresult +NS_NewXTFXULVisualWrapper(nsIXTFXULVisual* xtfElement, + nsINodeInfo* ni, + nsIContent** aResult); + +#endif // __NS_XTFXULVISUALWRAPPER_H__ diff --git a/mozilla/layout/Makefile.in b/mozilla/layout/Makefile.in index 5644ad509e7..0552bf9c103 100644 --- a/mozilla/layout/Makefile.in +++ b/mozilla/layout/Makefile.in @@ -50,6 +50,10 @@ ifdef MOZ_MATHML DIRS += mathml endif +ifdef MOZ_XTF +DIRS += xtf +endif + ifdef MOZ_SVG DIRS += svg endif diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index abb76835b4f..b35e0778861 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -147,6 +147,20 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #include "nsMathMLParts.h" #endif +#ifdef MOZ_XTF +#include "nsIXTFElement.h" +#include "nsIXTFElementWrapperPrivate.h" +#include "nsIXTFVisualWrapperPrivate.h" +nsresult +NS_NewXTFXULDisplayFrame(nsIPresShell*, nsIFrame**); +nsresult +NS_NewXTFXMLDisplayFrame(nsIPresShell*, PRBool isBlock, nsIFrame**); +#ifdef MOZ_SVG +nsresult +NS_NewXTFSVGDisplayFrame(nsIPresShell*, nsIContent*, nsIFrame**); +#endif +#endif + #ifdef MOZ_SVG #include "nsSVGAtoms.h" #include "nsISVGTextContainerFrame.h" @@ -5127,9 +5141,22 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsIPresShell* aPresShell nsFrameItems& aChildItems) { nsCOMPtr creator(do_QueryInterface(aParentFrame)); + if (!creator) return NS_OK; +#ifdef MOZ_XTF + PRBool registerWithShell = PR_TRUE; + PRBool forceBindingParent = PR_FALSE; + nsCOMPtr xtfElem = do_QueryInterface(aParent); + if (xtfElem) { + // no need to track XTF anonymous content by the shell: + registerWithShell = PR_FALSE; + if (xtfElem->ApplyDocumentStyleSheets()) + forceBindingParent = PR_TRUE; + } +#endif + nsCOMPtr anonymousItems; NS_NewISupportsArray(getter_AddRefs(anonymousItems)); @@ -5162,6 +5189,9 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsIPresShell* aPresShell aPresShell->SetAnonymousContentFor(aParent, nsnull); } +#ifdef MOZ_XTF + if (registerWithShell) +#endif // Inform the pres shell about the anonymous content aPresShell->SetAnonymousContentFor(aParent, anonymousItems); @@ -5191,6 +5221,11 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsIPresShell* aPresShell rv = content->SetBindingParent(content); } else +#endif +#ifdef MOZ_XTF + if (forceBindingParent) + rv = content->SetBindingParent(aParent); + else #endif rv = content->SetBindingParent(content); @@ -6769,6 +6804,134 @@ nsCSSFrameConstructor::ConstructMathMLFrame(nsIPresShell* aPresShell, } #endif // MOZ_MATHML +// XTF +#ifdef MOZ_XTF +nsresult +nsCSSFrameConstructor::ConstructXTFFrame(nsIPresShell* aPresShell, + nsPresContext* aPresContext, + nsFrameConstructorState& aState, + nsIContent* aContent, + nsIFrame* aParentFrame, + nsIAtom* aTag, + PRInt32 aNameSpaceID, + nsStyleContext* aStyleContext, + nsFrameItems& aFrameItems) +{ +#ifdef DEBUG +// printf("nsCSSFrameConstructor::ConstructXTFFrame\n"); +#endif + nsresult rv = NS_OK; + PRBool isAbsolutelyPositioned = PR_FALSE; + PRBool isFixedPositioned = PR_FALSE; + PRBool forceView = PR_FALSE; + PRBool isBlock = PR_FALSE; + + //NS_ASSERTION(aTag != nsnull, "null XTF tag"); + //if (aTag == nsnull) + // return NS_OK; + + // Initialize the new frame + nsIFrame* newFrame = nsnull; + + // See if the element is absolute or fixed positioned + const nsStyleDisplay* disp = aStyleContext->GetStyleDisplay(); + if (NS_STYLE_POSITION_ABSOLUTE == disp->mPosition) { + isAbsolutelyPositioned = PR_TRUE; + } + else if (NS_STYLE_POSITION_FIXED == disp->mPosition) { + isFixedPositioned = PR_TRUE; + } + + nsCOMPtr xtfElem = do_QueryInterface(aContent); + NS_ASSERTION(xtfElem, "huh? no xtf element?"); + switch(xtfElem->GetElementType()) { + case nsIXTFElement::ELEMENT_TYPE_SVG_VISUAL: +#ifdef MOZ_SVG + rv = NS_NewXTFSVGDisplayFrame(aPresShell, aContent, &newFrame); +#else + NS_ERROR("xtf svg visuals are only supported in mozilla builds with native svg"); +#endif + break; + case nsIXTFElement::ELEMENT_TYPE_XML_VISUAL: + { + PRBool isBlock = (NS_STYLE_DISPLAY_BLOCK == disp->mDisplay); + rv = NS_NewXTFXMLDisplayFrame(aPresShell, isBlock, &newFrame); + } + break; + case nsIXTFElement::ELEMENT_TYPE_XUL_VISUAL: + rv = NS_NewXTFXULDisplayFrame(aPresShell, &newFrame); + break; + case nsIXTFElement::ELEMENT_TYPE_GENERIC_ELEMENT: + NS_ERROR("huh? ELEMENT_TYPE_GENERIC_ELEMENT should have been flagged by caller"); + break; + default: + NS_ERROR("unknown xtf frame!"); + return NS_OK; + } + + // If we succeeded in creating a frame then initialize it, process its + // children (if requested), and set the initial child list + if (NS_SUCCEEDED(rv) && newFrame != nsnull) { + + nsIFrame* geometricParent = isAbsolutelyPositioned + ? aState.mAbsoluteItems.containingBlock + : aParentFrame; + + InitAndRestoreFrame(aPresContext, aState, aContent, + geometricParent, aStyleContext, nsnull, newFrame); + + nsHTMLContainerFrame::CreateViewForFrame(newFrame, aParentFrame, forceView); + + // Create anonymous frames before processing children, so that + // explicit child content can be appended to the correct anonymous + // frame. Call version of CreateAnonymousFrames that doesn't check + // tag: + nsFrameItems childItems; + CreateAnonymousFrames(aPresShell, aPresContext, aState, aContent, mDocument, newFrame, + PR_FALSE, childItems); + + // Set the frame's initial child list + newFrame->SetInitialChildList(aPresContext, nsnull, childItems.childList); + + // Process the child content if requested + nsIFrame *insertionFrame = newFrame->GetContentInsertionFrame(); + if (insertionFrame) { + nsFrameItems insertionItems; + rv = ProcessChildren(aPresShell, aPresContext, aState, aContent, + insertionFrame, PR_TRUE, insertionItems, isBlock); + if (insertionItems.childList) { + AppendFrames(aPresContext, aPresShell,aState.mFrameManager, + aContent, insertionFrame, + insertionItems.childList); + } + } + + // If the frame is absolutely positioned then create a placeholder frame + if (isAbsolutelyPositioned || isFixedPositioned) { + nsIFrame* placeholderFrame; + + CreatePlaceholderFrameFor(aPresShell, aPresContext, aState.mFrameManager, aContent, newFrame, + aStyleContext, aParentFrame, &placeholderFrame); + + // Add the positioned frame to its containing block's list of child frames + if (isAbsolutelyPositioned) { + aState.mAbsoluteItems.AddChild(newFrame); + } else { + aState.mFixedItems.AddChild(newFrame); + } + + // Add the placeholder frame to the flow + aFrameItems.AddChild(placeholderFrame); + } else { + // Add the new frame to our list of frame items. + aFrameItems.AddChild(newFrame); + } + } + return rv; +} +#endif // MOZ_XTF + + // SVG #ifdef MOZ_SVG nsresult @@ -7259,7 +7422,7 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe return NS_OK; } - if (aTag == nsLayoutAtoms::textTagName) + if (aContent->IsContentOfType(nsIContent::eTEXT)) return ConstructTextFrame(aPresShell, aPresContext, aState, aContent, aParentFrame, styleContext, aFrameItems); @@ -7312,6 +7475,24 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe } #endif +// XTF +#ifdef MOZ_XTF + if (NS_SUCCEEDED(rv) && + ((nsnull == aFrameItems.childList) || + (lastChild == aFrameItems.lastChild))) { + nsCOMPtr xtfElem = do_QueryInterface(aContent); + if (xtfElem) { + if (xtfElem->GetElementType() == nsIXTFElement::ELEMENT_TYPE_GENERIC_ELEMENT) { + // we don't build frames for generic elements, only for visuals + aState.mFrameManager->SetUndisplayedContent(aContent, styleContext); + return NS_OK; + } else + rv = ConstructXTFFrame(aPresShell, aPresContext, aState, aContent, aParentFrame, + aTag, aNameSpaceID, styleContext, aFrameItems); + } + } +#endif + if (NS_SUCCEEDED(rv) && ((nsnull == aFrameItems.childList) || (lastChild == aFrameItems.lastChild))) { // When there is no explicit frame to create, assume it's a diff --git a/mozilla/layout/base/nsCSSFrameConstructor.h b/mozilla/layout/base/nsCSSFrameConstructor.h index c74e880b9d0..c5917eed7a1 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.h +++ b/mozilla/layout/base/nsCSSFrameConstructor.h @@ -616,6 +616,19 @@ private: PRBool& aHaltProcessing); +// XTF +#ifdef MOZ_XTF + nsresult ConstructXTFFrame(nsIPresShell* aPresShell, + nsPresContext* aPresContext, + nsFrameConstructorState& aState, + nsIContent* aContent, + nsIFrame* aParentFrame, + nsIAtom* aTag, + PRInt32 aNameSpaceID, + nsStyleContext* aStyleContext, + nsFrameItems& aFrameItems); +#endif + // SVG - rods #ifdef MOZ_SVG nsresult TestSVGConditions(nsIContent* aContent, diff --git a/mozilla/layout/build/Makefile.in b/mozilla/layout/build/Makefile.in index fe2d434c8a1..52fb47c3428 100644 --- a/mozilla/layout/build/Makefile.in +++ b/mozilla/layout/build/Makefile.in @@ -145,6 +145,18 @@ SHARED_LIBRARY_LIBS += \ $(NULL) endif +ifdef MOZ_XTF +SHARED_LIBRARY_LIBS += \ + $(DIST)/lib/$(LIB_PREFIX)gkcontentxtf_s.$(LIB_SUFFIX) \ + $(NULL) + +ifdef MOZ_SVG +SHARED_LIBRARY_LIBS += \ + $(DIST)/lib/$(LIB_PREFIX)gkxtfbase_s.$(LIB_SUFFIX) \ + $(NULL) +endif +endif + ifdef MOZ_SVG SHARED_LIBRARY_LIBS += \ $(DIST)/lib/$(LIB_PREFIX)gksvgbase_s.$(LIB_SUFFIX) \ diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index b0bbda0cbea..bf776459d23 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -199,6 +199,11 @@ static void Shutdown(); #include "nsMathMLOperators.h" #endif +#ifdef MOZ_XTF +#include "nsIXTFService.h" +#include "nsIXMLContentBuilder.h" +#endif + #ifdef MOZ_SVG #include "nsSVGAtoms.h" #include "nsSVGTypeCIDs.h" @@ -594,6 +599,10 @@ MAKE_CTOR(CreateXULPopupListener, nsIXULPopupListener, NS_NewXUL // NS_NewXULControllers // NS_NewXULPrototypeCache #endif +#ifdef MOZ_XTF +MAKE_CTOR(CreateXTFService, nsIXTFService, NS_NewXTFService) +MAKE_CTOR(CreateXMLContentBuilder, nsIXMLContentBuilder, NS_NewXMLContentBuilder) +#endif #ifdef MOZ_SVG MAKE_CTOR(CreateSVGRect, nsIDOMSVGRect, NS_NewSVGRect) #endif @@ -957,13 +966,13 @@ static const nsModuleComponentInfo gComponents[] = { { "XML document", NS_XMLDOCUMENT_CID, - nsnull, + "@mozilla.org/xml/xml-document;1", CreateXMLDocument }, #ifdef MOZ_SVG { "SVG document", NS_SVGDOCUMENT_CID, - nsnull, + "@mozilla.org/svg/svg-document;1", CreateSVGDocument }, #endif @@ -1223,6 +1232,18 @@ static const nsModuleComponentInfo gComponents[] = { NS_NewXULPrototypeDocument }, #endif +#ifdef MOZ_XTF + { "XTF Service", + NS_XTFSERVICE_CID, + NS_XTFSERVICE_CONTRACTID, + CreateXTFService }, + + { "XML Content Builder", + NS_XMLCONTENTBUILDER_CID, + NS_XMLCONTENTBUILDER_CONTRACTID, + CreateXMLContentBuilder }, +#endif + #ifdef MOZ_SVG { "SVG Rect", NS_SVGRECT_CID, diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index abb76835b4f..b35e0778861 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -147,6 +147,20 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); #include "nsMathMLParts.h" #endif +#ifdef MOZ_XTF +#include "nsIXTFElement.h" +#include "nsIXTFElementWrapperPrivate.h" +#include "nsIXTFVisualWrapperPrivate.h" +nsresult +NS_NewXTFXULDisplayFrame(nsIPresShell*, nsIFrame**); +nsresult +NS_NewXTFXMLDisplayFrame(nsIPresShell*, PRBool isBlock, nsIFrame**); +#ifdef MOZ_SVG +nsresult +NS_NewXTFSVGDisplayFrame(nsIPresShell*, nsIContent*, nsIFrame**); +#endif +#endif + #ifdef MOZ_SVG #include "nsSVGAtoms.h" #include "nsISVGTextContainerFrame.h" @@ -5127,9 +5141,22 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsIPresShell* aPresShell nsFrameItems& aChildItems) { nsCOMPtr creator(do_QueryInterface(aParentFrame)); + if (!creator) return NS_OK; +#ifdef MOZ_XTF + PRBool registerWithShell = PR_TRUE; + PRBool forceBindingParent = PR_FALSE; + nsCOMPtr xtfElem = do_QueryInterface(aParent); + if (xtfElem) { + // no need to track XTF anonymous content by the shell: + registerWithShell = PR_FALSE; + if (xtfElem->ApplyDocumentStyleSheets()) + forceBindingParent = PR_TRUE; + } +#endif + nsCOMPtr anonymousItems; NS_NewISupportsArray(getter_AddRefs(anonymousItems)); @@ -5162,6 +5189,9 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsIPresShell* aPresShell aPresShell->SetAnonymousContentFor(aParent, nsnull); } +#ifdef MOZ_XTF + if (registerWithShell) +#endif // Inform the pres shell about the anonymous content aPresShell->SetAnonymousContentFor(aParent, anonymousItems); @@ -5191,6 +5221,11 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsIPresShell* aPresShell rv = content->SetBindingParent(content); } else +#endif +#ifdef MOZ_XTF + if (forceBindingParent) + rv = content->SetBindingParent(aParent); + else #endif rv = content->SetBindingParent(content); @@ -6769,6 +6804,134 @@ nsCSSFrameConstructor::ConstructMathMLFrame(nsIPresShell* aPresShell, } #endif // MOZ_MATHML +// XTF +#ifdef MOZ_XTF +nsresult +nsCSSFrameConstructor::ConstructXTFFrame(nsIPresShell* aPresShell, + nsPresContext* aPresContext, + nsFrameConstructorState& aState, + nsIContent* aContent, + nsIFrame* aParentFrame, + nsIAtom* aTag, + PRInt32 aNameSpaceID, + nsStyleContext* aStyleContext, + nsFrameItems& aFrameItems) +{ +#ifdef DEBUG +// printf("nsCSSFrameConstructor::ConstructXTFFrame\n"); +#endif + nsresult rv = NS_OK; + PRBool isAbsolutelyPositioned = PR_FALSE; + PRBool isFixedPositioned = PR_FALSE; + PRBool forceView = PR_FALSE; + PRBool isBlock = PR_FALSE; + + //NS_ASSERTION(aTag != nsnull, "null XTF tag"); + //if (aTag == nsnull) + // return NS_OK; + + // Initialize the new frame + nsIFrame* newFrame = nsnull; + + // See if the element is absolute or fixed positioned + const nsStyleDisplay* disp = aStyleContext->GetStyleDisplay(); + if (NS_STYLE_POSITION_ABSOLUTE == disp->mPosition) { + isAbsolutelyPositioned = PR_TRUE; + } + else if (NS_STYLE_POSITION_FIXED == disp->mPosition) { + isFixedPositioned = PR_TRUE; + } + + nsCOMPtr xtfElem = do_QueryInterface(aContent); + NS_ASSERTION(xtfElem, "huh? no xtf element?"); + switch(xtfElem->GetElementType()) { + case nsIXTFElement::ELEMENT_TYPE_SVG_VISUAL: +#ifdef MOZ_SVG + rv = NS_NewXTFSVGDisplayFrame(aPresShell, aContent, &newFrame); +#else + NS_ERROR("xtf svg visuals are only supported in mozilla builds with native svg"); +#endif + break; + case nsIXTFElement::ELEMENT_TYPE_XML_VISUAL: + { + PRBool isBlock = (NS_STYLE_DISPLAY_BLOCK == disp->mDisplay); + rv = NS_NewXTFXMLDisplayFrame(aPresShell, isBlock, &newFrame); + } + break; + case nsIXTFElement::ELEMENT_TYPE_XUL_VISUAL: + rv = NS_NewXTFXULDisplayFrame(aPresShell, &newFrame); + break; + case nsIXTFElement::ELEMENT_TYPE_GENERIC_ELEMENT: + NS_ERROR("huh? ELEMENT_TYPE_GENERIC_ELEMENT should have been flagged by caller"); + break; + default: + NS_ERROR("unknown xtf frame!"); + return NS_OK; + } + + // If we succeeded in creating a frame then initialize it, process its + // children (if requested), and set the initial child list + if (NS_SUCCEEDED(rv) && newFrame != nsnull) { + + nsIFrame* geometricParent = isAbsolutelyPositioned + ? aState.mAbsoluteItems.containingBlock + : aParentFrame; + + InitAndRestoreFrame(aPresContext, aState, aContent, + geometricParent, aStyleContext, nsnull, newFrame); + + nsHTMLContainerFrame::CreateViewForFrame(newFrame, aParentFrame, forceView); + + // Create anonymous frames before processing children, so that + // explicit child content can be appended to the correct anonymous + // frame. Call version of CreateAnonymousFrames that doesn't check + // tag: + nsFrameItems childItems; + CreateAnonymousFrames(aPresShell, aPresContext, aState, aContent, mDocument, newFrame, + PR_FALSE, childItems); + + // Set the frame's initial child list + newFrame->SetInitialChildList(aPresContext, nsnull, childItems.childList); + + // Process the child content if requested + nsIFrame *insertionFrame = newFrame->GetContentInsertionFrame(); + if (insertionFrame) { + nsFrameItems insertionItems; + rv = ProcessChildren(aPresShell, aPresContext, aState, aContent, + insertionFrame, PR_TRUE, insertionItems, isBlock); + if (insertionItems.childList) { + AppendFrames(aPresContext, aPresShell,aState.mFrameManager, + aContent, insertionFrame, + insertionItems.childList); + } + } + + // If the frame is absolutely positioned then create a placeholder frame + if (isAbsolutelyPositioned || isFixedPositioned) { + nsIFrame* placeholderFrame; + + CreatePlaceholderFrameFor(aPresShell, aPresContext, aState.mFrameManager, aContent, newFrame, + aStyleContext, aParentFrame, &placeholderFrame); + + // Add the positioned frame to its containing block's list of child frames + if (isAbsolutelyPositioned) { + aState.mAbsoluteItems.AddChild(newFrame); + } else { + aState.mFixedItems.AddChild(newFrame); + } + + // Add the placeholder frame to the flow + aFrameItems.AddChild(placeholderFrame); + } else { + // Add the new frame to our list of frame items. + aFrameItems.AddChild(newFrame); + } + } + return rv; +} +#endif // MOZ_XTF + + // SVG #ifdef MOZ_SVG nsresult @@ -7259,7 +7422,7 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe return NS_OK; } - if (aTag == nsLayoutAtoms::textTagName) + if (aContent->IsContentOfType(nsIContent::eTEXT)) return ConstructTextFrame(aPresShell, aPresContext, aState, aContent, aParentFrame, styleContext, aFrameItems); @@ -7312,6 +7475,24 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe } #endif +// XTF +#ifdef MOZ_XTF + if (NS_SUCCEEDED(rv) && + ((nsnull == aFrameItems.childList) || + (lastChild == aFrameItems.lastChild))) { + nsCOMPtr xtfElem = do_QueryInterface(aContent); + if (xtfElem) { + if (xtfElem->GetElementType() == nsIXTFElement::ELEMENT_TYPE_GENERIC_ELEMENT) { + // we don't build frames for generic elements, only for visuals + aState.mFrameManager->SetUndisplayedContent(aContent, styleContext); + return NS_OK; + } else + rv = ConstructXTFFrame(aPresShell, aPresContext, aState, aContent, aParentFrame, + aTag, aNameSpaceID, styleContext, aFrameItems); + } + } +#endif + if (NS_SUCCEEDED(rv) && ((nsnull == aFrameItems.childList) || (lastChild == aFrameItems.lastChild))) { // When there is no explicit frame to create, assume it's a diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.h b/mozilla/layout/html/style/src/nsCSSFrameConstructor.h index c74e880b9d0..c5917eed7a1 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.h +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.h @@ -616,6 +616,19 @@ private: PRBool& aHaltProcessing); +// XTF +#ifdef MOZ_XTF + nsresult ConstructXTFFrame(nsIPresShell* aPresShell, + nsPresContext* aPresContext, + nsFrameConstructorState& aState, + nsIContent* aContent, + nsIFrame* aParentFrame, + nsIAtom* aTag, + PRInt32 aNameSpaceID, + nsStyleContext* aStyleContext, + nsFrameItems& aFrameItems); +#endif + // SVG - rods #ifdef MOZ_SVG nsresult TestSVGConditions(nsIContent* aContent, diff --git a/mozilla/layout/svg/base/src/nsSVGGenericContainerFrame.cpp b/mozilla/layout/svg/base/src/nsSVGGenericContainerFrame.cpp index 5f24abb46e0..1467b2e665d 100644 --- a/mozilla/layout/svg/base/src/nsSVGGenericContainerFrame.cpp +++ b/mozilla/layout/svg/base/src/nsSVGGenericContainerFrame.cpp @@ -36,86 +36,10 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsContainerFrame.h" -#include "nsIDOMSVGGElement.h" -#include "nsPresContext.h" -#include "nsISVGChildFrame.h" -#include "nsISVGContainerFrame.h" -#include "nsISVGRendererCanvas.h" -#include "nsISVGOuterSVGFrame.h" - -typedef nsContainerFrame nsSVGGenericContainerFrameBase; - -class nsSVGGenericContainerFrame : public nsSVGGenericContainerFrameBase, - public nsISVGChildFrame, - public nsISVGContainerFrame -{ - friend nsresult - NS_NewSVGGenericContainerFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame** aNewFrame); -protected: - nsSVGGenericContainerFrame(); - virtual ~nsSVGGenericContainerFrame(); - nsresult Init(); - - // nsISupports interface: - NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); -private: - NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } - NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } -public: - // nsIFrame: - - NS_IMETHOD AppendFrames(nsPresContext* aPresContext, - nsIPresShell& aPresShell, - nsIAtom* aListName, - nsIFrame* aFrameList); - NS_IMETHOD InsertFrames(nsPresContext* aPresContext, - nsIPresShell& aPresShell, - nsIAtom* aListName, - nsIFrame* aPrevFrame, - nsIFrame* aFrameList); - NS_IMETHOD RemoveFrame(nsPresContext* aPresContext, - nsIPresShell& aPresShell, - nsIAtom* aListName, - nsIFrame* aOldFrame); - NS_IMETHOD ReplaceFrame(nsPresContext* aPresContext, - nsIPresShell& aPresShell, - nsIAtom* aListName, - nsIFrame* aOldFrame, - nsIFrame* aNewFrame); - NS_IMETHOD Init(nsPresContext* aPresContext, - nsIContent* aContent, - nsIFrame* aParent, - nsStyleContext* aContext, - nsIFrame* aPrevInFlow); - - NS_IMETHOD AttributeChanged(nsPresContext* aPresContext, - nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aModType); - - - // nsISVGChildFrame interface: - NS_IMETHOD Paint(nsISVGRendererCanvas* canvas, const nsRect& dirtyRectTwips); - NS_IMETHOD GetFrameForPoint(float x, float y, nsIFrame** hit); - NS_IMETHOD_(already_AddRefed) GetCoveredRegion(); - NS_IMETHOD InitialUpdate(); - NS_IMETHOD NotifyCanvasTMChanged(); - NS_IMETHOD NotifyRedrawSuspended(); - NS_IMETHOD NotifyRedrawUnsuspended(); - NS_IMETHOD GetBBox(nsIDOMSVGRect **_retval); - - // nsISVGContainerFrame interface: - nsISVGOuterSVGFrame*GetOuterSVGFrame(); - already_AddRefed GetCanvasTM(); - already_AddRefed GetCoordContextProvider(); - -protected: -}; +#include "nsSVGGenericContainerFrame.h" //---------------------------------------------------------------------- -// Implementation +// nsSVGGenericContainerFrame Implementation nsresult NS_NewSVGGenericContainerFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame** aNewFrame) diff --git a/mozilla/layout/svg/base/src/nsSVGGenericContainerFrame.h b/mozilla/layout/svg/base/src/nsSVGGenericContainerFrame.h new file mode 100644 index 00000000000..868c4ddf9c9 --- /dev/null +++ b/mozilla/layout/svg/base/src/nsSVGGenericContainerFrame.h @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla SVG project. + * + * The Initial Developer of the Original Code is + * Crocodile Clips Ltd.. + * Portions created by the Initial Developer are Copyright (C) 2001 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef __NS_SVGGENERICCONTAINERFRAME_H__ +#define __NS_SVGGENERICCONTAINERFRAME_H__ + +#include "nsContainerFrame.h" +#include "nsIDOMSVGGElement.h" +#include "nsPresContext.h" +#include "nsISVGChildFrame.h" +#include "nsISVGContainerFrame.h" +#include "nsISVGRendererCanvas.h" +#include "nsISVGOuterSVGFrame.h" + +typedef nsContainerFrame nsSVGGenericContainerFrameBase; + +class nsSVGGenericContainerFrame : public nsSVGGenericContainerFrameBase, + public nsISVGChildFrame, + public nsISVGContainerFrame +{ + friend nsresult + NS_NewSVGGenericContainerFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame** aNewFrame); +protected: + nsSVGGenericContainerFrame(); + virtual ~nsSVGGenericContainerFrame(); + nsresult Init(); + + // nsISupports interface: + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); +private: + NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } + NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } +public: + // nsIFrame: + + NS_IMETHOD AppendFrames(nsPresContext* aPresContext, + nsIPresShell& aPresShell, + nsIAtom* aListName, + nsIFrame* aFrameList); + NS_IMETHOD InsertFrames(nsPresContext* aPresContext, + nsIPresShell& aPresShell, + nsIAtom* aListName, + nsIFrame* aPrevFrame, + nsIFrame* aFrameList); + NS_IMETHOD RemoveFrame(nsPresContext* aPresContext, + nsIPresShell& aPresShell, + nsIAtom* aListName, + nsIFrame* aOldFrame); + NS_IMETHOD ReplaceFrame(nsPresContext* aPresContext, + nsIPresShell& aPresShell, + nsIAtom* aListName, + nsIFrame* aOldFrame, + nsIFrame* aNewFrame); + NS_IMETHOD Init(nsPresContext* aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsStyleContext* aContext, + nsIFrame* aPrevInFlow); + + NS_IMETHOD AttributeChanged(nsPresContext* aPresContext, + nsIContent* aChild, + PRInt32 aNameSpaceID, + nsIAtom* aAttribute, + PRInt32 aModType); + + + // nsISVGChildFrame interface: + NS_IMETHOD Paint(nsISVGRendererCanvas* canvas, const nsRect& dirtyRectTwips); + NS_IMETHOD GetFrameForPoint(float x, float y, nsIFrame** hit); + NS_IMETHOD_(already_AddRefed) GetCoveredRegion(); + NS_IMETHOD InitialUpdate(); + NS_IMETHOD NotifyCanvasTMChanged(); + NS_IMETHOD NotifyRedrawSuspended(); + NS_IMETHOD NotifyRedrawUnsuspended(); + NS_IMETHOD GetBBox(nsIDOMSVGRect **_retval); + + // nsISVGContainerFrame interface: + nsISVGOuterSVGFrame*GetOuterSVGFrame(); + already_AddRefed GetCanvasTM(); + already_AddRefed GetCoordContextProvider(); +}; + +#endif // __NS_SVGGENERICCONTAINERFRAME_H__ diff --git a/mozilla/layout/xtf/Makefile.in b/mozilla/layout/xtf/Makefile.in new file mode 100644 index 00000000000..66e000bbf73 --- /dev/null +++ b/mozilla/layout/xtf/Makefile.in @@ -0,0 +1,50 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Mozilla XTF project. +# +# The Initial Developer of the Original Code is +# Alex Fritze. +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Alex Fritze (original author) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +ifdef MOZ_SVG +DIRS = src +endif + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/layout/xtf/src/Makefile.in b/mozilla/layout/xtf/src/Makefile.in new file mode 100644 index 00000000000..282768acab2 --- /dev/null +++ b/mozilla/layout/xtf/src/Makefile.in @@ -0,0 +1,89 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Mozilla XTF project. +# +# The Initial Developer of the Original Code is +# Alex Fritze. +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Alex Fritze (original author) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + + +MODULE = layout +LIBRARY_NAME = gkxtfbase_s +REQUIRES = xpcom \ + string \ + content \ + gfx \ + widget \ + dom \ + locale \ + view \ + pref \ + necko \ + unicharutil \ + webshell \ + $(NULL) + +CPPSRCS = \ + nsXTFSVGDisplayFrame.cpp \ + nsXTFXULDisplayFrame.cpp \ + nsXTFXMLDisplayFrame.cpp \ + $(NULL) + +include $(topsrcdir)/config/config.mk + +# we don't want the shared lib, but we want to force the creation of a static lib. +FORCE_STATIC_LIB = 1 + +include $(topsrcdir)/config/rules.mk + +LOCAL_INCLUDES = \ + -I$(srcdir)/../../base/src \ + -I$(srcdir)/../../html/table/src \ + -I$(srcdir)/../../html/style/src \ + -I$(srcdir)/../../html/base/src \ + -I$(srcdir)/../../html/forms/src \ + -I$(srcdir)/../../../content/svg/content/src \ + -I$(srcdir)/../../html/content/src \ + -I$(srcdir)/../../xml/content/src \ + -I$(srcdir)/../../base/public \ + -I$(srcdir)/../../svg/base/src \ + -I$(srcdir)/../../xul/base/src \ + $(NULL) + +DEFINES += -D_IMPL_NS_LAYOUT diff --git a/mozilla/layout/xtf/src/nsXTFSVGDisplayFrame.cpp b/mozilla/layout/xtf/src/nsXTFSVGDisplayFrame.cpp new file mode 100644 index 00000000000..56218cb6299 --- /dev/null +++ b/mozilla/layout/xtf/src/nsXTFSVGDisplayFrame.cpp @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsContainerFrame.h" +#include "nsPresContext.h" +#include "nsISupportsArray.h" +#include "nsSVGGenericContainerFrame.h" +#include "nsIXTFVisualWrapperPrivate.h" +#include "nsIAnonymousContentCreator.h" + +typedef nsSVGGenericContainerFrame nsXTFSVGDisplayFrameBase; + +class nsXTFSVGDisplayFrame : public nsXTFSVGDisplayFrameBase, + public nsIAnonymousContentCreator +{ +public: + friend nsresult + NS_NewXTFSVGDisplayFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame** aNewFrame); + // nsISupports interface: + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); +private: + NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } + NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } + +protected: + // nsIAnonymousContentCreator + NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems); + + // If the creator doesn't want to create special frame for frame hierarchy + // then it should null out the style content arg and return NS_ERROR_FAILURE + NS_IMETHOD CreateFrameFor(nsPresContext* aPresContext, + nsIContent * aContent, + nsIFrame** aFrame) { + if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; } +}; + +//---------------------------------------------------------------------- +// Implementation + +nsresult +NS_NewXTFSVGDisplayFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsIFrame** aNewFrame) +{ + nsXTFSVGDisplayFrame* it = new (aPresShell) nsXTFSVGDisplayFrame; + if (nsnull == it) + return NS_ERROR_OUT_OF_MEMORY; + + *aNewFrame = it; + + return NS_OK; +} + +//---------------------------------------------------------------------- +// nsISupports methods + +NS_INTERFACE_MAP_BEGIN(nsXTFSVGDisplayFrame) + NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator) +NS_INTERFACE_MAP_END_INHERITING(nsXTFSVGDisplayFrameBase) + + +//---------------------------------------------------------------------- +// nsIAnonymousContentCreator methods: + +NS_IMETHODIMP +nsXTFSVGDisplayFrame::CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems) +{ + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + return visual->CreateAnonymousContent(aPresContext, aAnonymousItems); +} diff --git a/mozilla/layout/xtf/src/nsXTFXMLDisplayFrame.cpp b/mozilla/layout/xtf/src/nsXTFXMLDisplayFrame.cpp new file mode 100644 index 00000000000..d9ef12fd8e1 --- /dev/null +++ b/mozilla/layout/xtf/src/nsXTFXMLDisplayFrame.cpp @@ -0,0 +1,272 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsCOMPtr.h" +#include "nsStyleSet.h" +#include "nsPresContext.h" +#include "nsIPresShell.h" +#include "nsBlockFrame.h" +#include "nsInlineFrame.h" +#include "nsIXTFXMLVisual.h" +#include "nsIDOMElement.h" +#include "nsIXTFVisualWrapperPrivate.h" +#include "nsIAnonymousContentCreator.h" + +//////////////////////////////////////////////////////////////////////// +// nsXTFXMLBlockDisplayFrame + +nsresult NS_NewXTFXMLDisplayFrame(nsIPresShell* aPresShell, + PRBool isBlock, nsIFrame** aNewFrame); + + +typedef nsBlockFrame nsXTFXMLBlockDisplayFrameBase; + +class nsXTFXMLBlockDisplayFrame : public nsXTFXMLBlockDisplayFrameBase, + public nsIAnonymousContentCreator +{ +public: + nsXTFXMLBlockDisplayFrame(); + + // nsISupports interface: + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); +private: + NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } + NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } + +public: + // nsIFrame + virtual nsIFrame* GetContentInsertionFrame(); + + NS_IMETHOD DidReflow(nsPresContext* aPresContext, + const nsHTMLReflowState* aReflowState, + nsDidReflowStatus aStatus); + + // nsIAnonymousContentCreator + NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems); + + // If the creator doesn't want to create special frame for frame hierarchy + // then it should null out the style content arg and return NS_ERROR_FAILURE + NS_IMETHOD CreateFrameFor(nsPresContext* aPresContext, + nsIContent * aContent, + nsIFrame** aFrame) { + if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; } +}; + +//---------------------------------------------------------------------- +// Implementation + +nsXTFXMLBlockDisplayFrame::nsXTFXMLBlockDisplayFrame() + : nsXTFXMLBlockDisplayFrameBase() +{} + +//---------------------------------------------------------------------- +// nsISupports methods + +NS_INTERFACE_MAP_BEGIN(nsXTFXMLBlockDisplayFrame) + NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator) +NS_INTERFACE_MAP_END_INHERITING(nsXTFXMLBlockDisplayFrameBase) + +//---------------------------------------------------------------------- +// nsIFrame methods + +nsIFrame* +nsXTFXMLBlockDisplayFrame::GetContentInsertionFrame() +{ + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + + nsCOMPtr childInsertionPoint; + visual->GetInsertionPoint(getter_AddRefs(childInsertionPoint)); + if (!childInsertionPoint) return nsnull; // we don't take visual child content + + nsCOMPtr content = do_QueryInterface(childInsertionPoint); + NS_ASSERTION(content, "element not implementing nsIContent!?"); + + nsIFrame* insertionFrame = nsnull; + GetPresContext()->PresShell()->GetPrimaryFrameFor(content, &insertionFrame); + return insertionFrame; +} + + + +NS_IMETHODIMP +nsXTFXMLBlockDisplayFrame::DidReflow(nsPresContext* aPresContext, + const nsHTMLReflowState* aReflowState, + nsDidReflowStatus aStatus) +{ + nsresult rv = nsXTFXMLBlockDisplayFrameBase::DidReflow(aPresContext, aReflowState, aStatus); + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + visual->DidLayout(); + + return rv; +} + +//---------------------------------------------------------------------- +// nsIAnonymousContentCreator methods: + +NS_IMETHODIMP +nsXTFXMLBlockDisplayFrame::CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems) +{ + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + return visual->CreateAnonymousContent(aPresContext, aAnonymousItems); +} + +//////////////////////////////////////////////////////////////////////// +// nsXTFXMLInlineDisplayFrame + +nsresult NS_NewXTFXMLDisplayFrame(nsIPresShell* aPresShell, + PRBool isInline, nsIFrame** aNewFrame); + + +typedef nsInlineFrame nsXTFXMLInlineDisplayFrameBase; + +class nsXTFXMLInlineDisplayFrame : public nsXTFXMLInlineDisplayFrameBase, + public nsIAnonymousContentCreator +{ +public: + nsXTFXMLInlineDisplayFrame(); + + // nsISupports interface: + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); +private: + NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } + NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } + +public: + // nsIFrame + virtual nsIFrame* GetContentInsertionFrame(); + + NS_IMETHOD DidReflow(nsPresContext* aPresContext, + const nsHTMLReflowState* aReflowState, + nsDidReflowStatus aStatus); + + // nsIAnonymousContentCreator + NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems); + + // If the creator doesn't want to create special frame for frame hierarchy + // then it should null out the style content arg and return NS_ERROR_FAILURE + NS_IMETHOD CreateFrameFor(nsPresContext* aPresContext, + nsIContent * aContent, + nsIFrame** aFrame) { + if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; } +}; + +//---------------------------------------------------------------------- +// Implementation + +nsXTFXMLInlineDisplayFrame::nsXTFXMLInlineDisplayFrame() + : nsXTFXMLInlineDisplayFrameBase() +{} + +//---------------------------------------------------------------------- +// nsISupports methods + +NS_INTERFACE_MAP_BEGIN(nsXTFXMLInlineDisplayFrame) + NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator) +NS_INTERFACE_MAP_END_INHERITING(nsXTFXMLInlineDisplayFrameBase) + +//---------------------------------------------------------------------- +// nsIFrame methods + +nsIFrame* +nsXTFXMLInlineDisplayFrame::GetContentInsertionFrame() +{ + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + + nsCOMPtr childInsertionPoint; + visual->GetInsertionPoint(getter_AddRefs(childInsertionPoint)); + if (!childInsertionPoint) return nsnull; // we don't take visual child content + + nsCOMPtr content = do_QueryInterface(childInsertionPoint); + NS_ASSERTION(content, "element not implementing nsIContent!?"); + + nsIFrame* insertionFrame = nsnull; + GetPresContext()->PresShell()->GetPrimaryFrameFor(content, &insertionFrame); + return insertionFrame; +} + + + +NS_IMETHODIMP +nsXTFXMLInlineDisplayFrame::DidReflow(nsPresContext* aPresContext, + const nsHTMLReflowState* aReflowState, + nsDidReflowStatus aStatus) +{ + nsresult rv = nsXTFXMLInlineDisplayFrameBase::DidReflow(aPresContext, aReflowState, aStatus); + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + visual->DidLayout(); + + return rv; +} + +//---------------------------------------------------------------------- +// nsIAnonymousContentCreator methods: + +NS_IMETHODIMP +nsXTFXMLInlineDisplayFrame::CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems) +{ + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + return visual->CreateAnonymousContent(aPresContext, aAnonymousItems); +} + + +//////////////////////////////////////////////////////////////////////// +// Construction API + +nsresult +NS_NewXTFXMLDisplayFrame(nsIPresShell* aPresShell, PRBool isBlock, nsIFrame** aNewFrame) +{ + if (isBlock) + *aNewFrame = new (aPresShell) nsXTFXMLBlockDisplayFrame(); + else + *aNewFrame = new (aPresShell) nsXTFXMLInlineDisplayFrame(); + + if (nsnull == *aNewFrame) + return NS_ERROR_OUT_OF_MEMORY; + + return NS_OK; +} diff --git a/mozilla/layout/xtf/src/nsXTFXULDisplayFrame.cpp b/mozilla/layout/xtf/src/nsXTFXULDisplayFrame.cpp new file mode 100644 index 00000000000..be60f34728c --- /dev/null +++ b/mozilla/layout/xtf/src/nsXTFXULDisplayFrame.cpp @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ----- BEGIN LICENSE BLOCK ----- + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla XTF project. + * + * The Initial Developer of the Original Code is + * Alex Fritze. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alex Fritze (original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ----- END LICENSE BLOCK ----- */ + +#include "nsBoxFrame.h" +#include "nsIDOMElement.h" +#include "nsIXTFVisualWrapperPrivate.h" +#include "nsIAnonymousContentCreator.h" + +typedef nsBoxFrame nsXTFXULDisplayFrameBase; + +class nsXTFXULDisplayFrame : public nsXTFXULDisplayFrameBase, + public nsIAnonymousContentCreator +{ +public: + friend nsresult + NS_NewXTFXULDisplayFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame); + + nsXTFXULDisplayFrame(nsIPresShell* aPresShell); + + // nsISupports interface: + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); +private: + NS_IMETHOD_(nsrefcnt) AddRef() { return NS_OK; } + NS_IMETHOD_(nsrefcnt) Release() { return NS_OK; } + +public: + // nsIFrame + virtual nsIFrame* GetContentInsertionFrame(); + + NS_IMETHOD EndLayout(nsBoxLayoutState& aState); + + // nsIAnonymousContentCreator + NS_IMETHOD CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems); + + // If the creator doesn't want to create special frame for frame hierarchy + // then it should null out the style content arg and return NS_ERROR_FAILURE + NS_IMETHOD CreateFrameFor(nsPresContext* aPresContext, + nsIContent * aContent, + nsIFrame** aFrame) { + if (aFrame) *aFrame = nsnull; return NS_ERROR_FAILURE; } +}; + +//---------------------------------------------------------------------- +// Implementation + +nsresult +NS_NewXTFXULDisplayFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame) +{ + nsXTFXULDisplayFrame* it = new (aPresShell) nsXTFXULDisplayFrame(aPresShell); + if (nsnull == it) + return NS_ERROR_OUT_OF_MEMORY; + + *aNewFrame = it; + + return NS_OK; +} + +nsXTFXULDisplayFrame::nsXTFXULDisplayFrame(nsIPresShell* aPresShell) + : nsXTFXULDisplayFrameBase(aPresShell, PR_FALSE, nsnull) +{} + +//---------------------------------------------------------------------- +// nsISupports methods + +NS_INTERFACE_MAP_BEGIN(nsXTFXULDisplayFrame) + NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator) +NS_INTERFACE_MAP_END_INHERITING(nsXTFXULDisplayFrameBase) + +//---------------------------------------------------------------------- +// nsIFrame mehthods + +nsIFrame* +nsXTFXULDisplayFrame::GetContentInsertionFrame() +{ + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + + nsCOMPtr childInsertionPoint; + visual->GetInsertionPoint(getter_AddRefs(childInsertionPoint)); + if (!childInsertionPoint) return nsnull; // we don't take visual child content + + nsCOMPtr content = do_QueryInterface(childInsertionPoint); + NS_ASSERTION(content, "element not implementing nsIContent!?"); + + nsIFrame* insertionFrame = nsnull; + GetPresContext()->GetPresShell()->GetPrimaryFrameFor(content, &insertionFrame); + return insertionFrame; +} + +NS_IMETHODIMP +nsXTFXULDisplayFrame::EndLayout(nsBoxLayoutState& aState) +{ + nsresult rv = nsXTFXULDisplayFrameBase::EndLayout(aState); + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + visual->DidLayout(); + + return rv; +} + +//---------------------------------------------------------------------- +// nsIAnonymousContentCreator methods: + +NS_IMETHODIMP +nsXTFXULDisplayFrame::CreateAnonymousContent(nsPresContext* aPresContext, + nsISupportsArray& aAnonymousItems) +{ + nsCOMPtr visual = do_QueryInterface(mContent); + NS_ASSERTION(visual, "huh? associated content not implementing nsIXTFVisualWrapperPrivate"); + return visual->CreateAnonymousContent(aPresContext, aAnonymousItems); +}