mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Removing files that were moved to mozilla/content/... part of the carpool.
This commit is contained in:
parent
17dddc0630
commit
effc510939
@ -1,143 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "GenericElementCollection.h"
|
|
||||||
#include "nsIDOMElement.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
|
|
||||||
GenericElementCollection::GenericElementCollection(nsIContent *aParent,
|
|
||||||
nsIAtom *aTag)
|
|
||||||
: nsGenericDOMHTMLCollection()
|
|
||||||
{
|
|
||||||
mParent = aParent;
|
|
||||||
mTag = aTag;
|
|
||||||
NS_IF_ADDREF(aTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
GenericElementCollection::~GenericElementCollection()
|
|
||||||
{
|
|
||||||
// we do NOT have a ref-counted reference to mParent, so do NOT
|
|
||||||
// release it! this is to avoid circular references. The
|
|
||||||
// instantiator who provided mParent is responsible for managing our
|
|
||||||
// reference for us.
|
|
||||||
|
|
||||||
// Release reference on the tag
|
|
||||||
NS_IF_RELEASE(mTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
// we re-count every call. A better implementation would be to set ourselves up as
|
|
||||||
// an observer of contentAppended, contentInserted, and contentDeleted
|
|
||||||
NS_IMETHODIMP
|
|
||||||
GenericElementCollection::GetLength(PRUint32* aLength)
|
|
||||||
{
|
|
||||||
if (nsnull==aLength)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
*aLength=0;
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
if (nsnull!=mParent)
|
|
||||||
{
|
|
||||||
nsIContent *child=nsnull;
|
|
||||||
PRUint32 childIndex=0;
|
|
||||||
mParent->ChildAt(childIndex, child);
|
|
||||||
while (nsnull!=child)
|
|
||||||
{
|
|
||||||
nsIAtom *childTag;
|
|
||||||
child->GetTag(childTag);
|
|
||||||
if (mTag==childTag)
|
|
||||||
{
|
|
||||||
(*aLength)++;
|
|
||||||
}
|
|
||||||
NS_RELEASE(childTag);
|
|
||||||
NS_RELEASE(child);
|
|
||||||
childIndex++;
|
|
||||||
mParent->ChildAt(childIndex, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
GenericElementCollection::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
*aReturn=nsnull;
|
|
||||||
PRUint32 theIndex = 0;
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
if (nsnull!=mParent)
|
|
||||||
{
|
|
||||||
nsIContent *child=nsnull;
|
|
||||||
PRUint32 childIndex=0;
|
|
||||||
mParent->ChildAt(childIndex, child);
|
|
||||||
while (nsnull!=child)
|
|
||||||
{
|
|
||||||
nsIAtom *childTag;
|
|
||||||
child->GetTag(childTag);
|
|
||||||
if (mTag==childTag)
|
|
||||||
{
|
|
||||||
if (aIndex==theIndex)
|
|
||||||
{
|
|
||||||
child->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aReturn); // out-param addref
|
|
||||||
NS_ASSERTION(nsnull!=aReturn, "content element must be an nsIDOMNode");
|
|
||||||
NS_RELEASE(childTag);
|
|
||||||
NS_RELEASE(child);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
theIndex++;
|
|
||||||
}
|
|
||||||
NS_RELEASE(childTag);
|
|
||||||
NS_RELEASE(child);
|
|
||||||
childIndex++;
|
|
||||||
mParent->ChildAt(childIndex, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
GenericElementCollection::NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
if (nsnull!=mParent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
GenericElementCollection::ParentDestroyed()
|
|
||||||
{
|
|
||||||
// see comment in destructor, do NOT release mParent!
|
|
||||||
mParent = nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
nsresult
|
|
||||||
GenericElementCollection::SizeOf(nsISizeOfHandler* aSizer,
|
|
||||||
PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
if (!aResult) return NS_ERROR_NULL_POINTER;
|
|
||||||
*aResult = sizeof(*this);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef GenericElementCollection_h__
|
|
||||||
#define GenericElementCollection_h__
|
|
||||||
|
|
||||||
#include "nsGenericDOMHTMLCollection.h"
|
|
||||||
|
|
||||||
class nsIContent;
|
|
||||||
class nsIAtom;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides a late-bound collection of elements that are
|
|
||||||
* direct decendents of an element.
|
|
||||||
* mParent is NOT ref-counted to avoid circular references
|
|
||||||
*/
|
|
||||||
class GenericElementCollection : public nsGenericDOMHTMLCollection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GenericElementCollection(nsIContent *aParent,
|
|
||||||
nsIAtom *aTag);
|
|
||||||
virtual ~GenericElementCollection();
|
|
||||||
|
|
||||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
|
||||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
|
|
||||||
NS_IMETHOD NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn);
|
|
||||||
|
|
||||||
NS_IMETHOD ParentDestroyed();
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
nsIContent * mParent;
|
|
||||||
nsIAtom * mTag;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,559 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
||||||
*/
|
|
||||||
#include "nsIAttributeContent.h"
|
|
||||||
#include "nsGenericElement.h"
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
#include "nsIEventListenerManager.h"
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
#include "nsIDOMRange.h"
|
|
||||||
#include "nsIDOMDocument.h"
|
|
||||||
#include "nsIDOMDocumentFragment.h"
|
|
||||||
#include "nsRange.h"
|
|
||||||
|
|
||||||
#include "nsISelection.h"
|
|
||||||
#include "nsIEnumerator.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include "nsCRT.h"
|
|
||||||
#include "nsIEventStateManager.h"
|
|
||||||
#include "nsIPrivateDOMEvent.h"
|
|
||||||
#include "nsISizeOfHandler.h"
|
|
||||||
#include "nsIDOMEvent.h"
|
|
||||||
#include "nsIDOMText.h"
|
|
||||||
#include "nsIDOMScriptObjectFactory.h"
|
|
||||||
#include "prprf.h"
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include "nsIContent.h"
|
|
||||||
#include "nsTextFragment.h"
|
|
||||||
#include "nsVoidArray.h"
|
|
||||||
#include "nsINameSpaceManager.h"
|
|
||||||
#include "nsITextContent.h"
|
|
||||||
|
|
||||||
class nsIDOMAttr;
|
|
||||||
class nsIDOMEventListener;
|
|
||||||
class nsIDOMNodeList;
|
|
||||||
class nsIEventListenerManager;
|
|
||||||
class nsIFrame;
|
|
||||||
class nsIStyleContext;
|
|
||||||
class nsIStyleRule;
|
|
||||||
class nsISupportsArray;
|
|
||||||
class nsIDOMText;
|
|
||||||
|
|
||||||
|
|
||||||
// XXX share all id's in this dir
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class nsAttributeContent : public nsITextContent, public nsIAttributeContent {
|
|
||||||
public:
|
|
||||||
friend nsresult NS_NewAttributeContent(nsAttributeContent** aNewFrame);
|
|
||||||
|
|
||||||
nsAttributeContent();
|
|
||||||
virtual ~nsAttributeContent();
|
|
||||||
|
|
||||||
NS_IMETHOD Init(nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttrName);
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
|
|
||||||
// Implementation for nsIContent
|
|
||||||
NS_IMETHOD GetDocument(nsIDocument*& aResult) const;
|
|
||||||
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers);
|
|
||||||
NS_IMETHOD GetParent(nsIContent*& aResult) const;
|
|
||||||
NS_IMETHOD SetParent(nsIContent* aParent);
|
|
||||||
|
|
||||||
NS_IMETHOD GetNameSpaceID(PRInt32& aID) const {
|
|
||||||
aID = kNameSpaceID_None;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHOD GetTag(nsIAtom*& aResult) const {
|
|
||||||
aResult = nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHOD GetNodeInfo(nsINodeInfo*& aResult) const {
|
|
||||||
aResult = nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHOD NormalizeAttributeString(const nsAReadableString& aStr,
|
|
||||||
nsINodeInfo*& aNodeInfo) {
|
|
||||||
aNodeInfo = nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { return NS_OK; }
|
|
||||||
NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { return NS_OK; }
|
|
||||||
|
|
||||||
NS_IMETHOD GetBindingParent(nsIContent** aContent) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHOD SetBindingParent(nsIContent* aParent) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, const nsAReadableString& aValue,
|
|
||||||
PRBool aNotify) { return NS_OK; }
|
|
||||||
NS_IMETHOD SetAttribute(nsINodeInfo *aNodeInfo, const nsAReadableString& aValue,
|
|
||||||
PRBool aNotify) { return NS_OK; }
|
|
||||||
NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBool aNotify) { return NS_OK; }
|
|
||||||
NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, nsAWritableString& aResult) const {return NS_CONTENT_ATTR_NOT_THERE; }
|
|
||||||
NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, nsIAtom*& aPrefix, nsAWritableString& aResult) const {return NS_CONTENT_ATTR_NOT_THERE; }
|
|
||||||
NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, PRInt32& aNameSpaceID, nsIAtom*& aName, nsIAtom*& aPrefix) const {
|
|
||||||
aName = nsnull;
|
|
||||||
aPrefix = nsnull;
|
|
||||||
return NS_ERROR_ILLEGAL_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { aResult = 0; return NS_OK; }
|
|
||||||
|
|
||||||
NS_IMETHOD List(FILE* out, PRInt32 aIndent) const { return NS_OK; }
|
|
||||||
NS_IMETHOD DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const { return NS_OK; }
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext,
|
|
||||||
nsEvent* aEvent,
|
|
||||||
nsIDOMEvent** aDOMEvent,
|
|
||||||
PRUint32 aFlags,
|
|
||||||
nsEventStatus* aEventStatus);
|
|
||||||
|
|
||||||
NS_IMETHOD GetContentID(PRUint32* aID) {
|
|
||||||
*aID = 0;
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHOD SetContentID(PRUint32 aID) {
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHOD RangeAdd(nsIDOMRange& aRange);
|
|
||||||
NS_IMETHOD RangeRemove(nsIDOMRange& aRange);
|
|
||||||
NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const;
|
|
||||||
|
|
||||||
// Implementation for nsIContent
|
|
||||||
NS_IMETHOD CanContainChildren(PRBool& aResult) const { aResult = PR_FALSE; return NS_OK; }
|
|
||||||
|
|
||||||
NS_IMETHOD ChildCount(PRInt32& aResult) const { aResult = 0; return NS_OK; }
|
|
||||||
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { aResult = nsnull; return NS_OK; }
|
|
||||||
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { aResult = -1; return NS_OK; }
|
|
||||||
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) { return NS_OK; }
|
|
||||||
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) { return NS_OK; }
|
|
||||||
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { return NS_OK; }
|
|
||||||
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { return NS_OK; }
|
|
||||||
NS_IMETHOD SplitText(PRUint32 aOffset, nsIDOMText** aReturn){ return NS_OK; }
|
|
||||||
|
|
||||||
///////////////////
|
|
||||||
// Implementation for nsITextContent
|
|
||||||
NS_IMETHOD GetText(const nsTextFragment** aFragmentsResult);
|
|
||||||
NS_IMETHOD GetTextLength(PRInt32* aLengthResult);
|
|
||||||
NS_IMETHOD CopyText(nsAWritableString& aResult);
|
|
||||||
NS_IMETHOD SetText(const PRUnichar* aBuffer,
|
|
||||||
PRInt32 aLength,
|
|
||||||
PRBool aNotify);
|
|
||||||
NS_IMETHOD SetText(const nsAReadableString& aStr,
|
|
||||||
PRBool aNotify);
|
|
||||||
NS_IMETHOD SetText(const char* aBuffer,
|
|
||||||
PRInt32 aLength,
|
|
||||||
PRBool aNotify);
|
|
||||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult);
|
|
||||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone);
|
|
||||||
|
|
||||||
//----------------------------------------
|
|
||||||
|
|
||||||
void ValidateTextFragment();
|
|
||||||
|
|
||||||
void ToCString(nsAWritableString& aBuf, PRInt32 aOffset, PRInt32 aLen) const;
|
|
||||||
|
|
||||||
// Up pointer to the real content object that we are
|
|
||||||
// supporting. Sometimes there is work that we just can't do
|
|
||||||
// ourselves, so this is needed to ask the real object to do the
|
|
||||||
// work.
|
|
||||||
nsIContent* mContent;
|
|
||||||
nsIDocument* mDocument;
|
|
||||||
nsIContent* mParent;
|
|
||||||
|
|
||||||
nsTextFragment mText;
|
|
||||||
PRInt32 mNameSpaceID;
|
|
||||||
nsIAtom* mAttrName;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsAttributeContent)
|
|
||||||
|
|
||||||
NS_IMPL_RELEASE(nsAttributeContent)
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewAttributeContent(nsIContent** aContent)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION(aContent, "null OUT ptr");
|
|
||||||
if (nsnull == aContent) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
nsAttributeContent* it = new nsAttributeContent;
|
|
||||||
if (nsnull == it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
return NS_SUCCEEDED(it->QueryInterface(NS_GET_IID(nsIContent), (void **)aContent)) ?
|
|
||||||
NS_OK : NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
|
|
||||||
nsAttributeContent::nsAttributeContent()
|
|
||||||
: mText()
|
|
||||||
{
|
|
||||||
NS_INIT_REFCNT();
|
|
||||||
mDocument = nsnull;
|
|
||||||
mParent = nsnull;
|
|
||||||
mContent = nsnull;
|
|
||||||
mAttrName = nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
nsAttributeContent::~nsAttributeContent()
|
|
||||||
{
|
|
||||||
NS_IF_RELEASE(mAttrName);
|
|
||||||
//NS_IF_RELEASE(mDocument);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAttributeContent::Init(nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttrName)
|
|
||||||
{
|
|
||||||
NS_ASSERTION((nsnull == mContent) && (nsnull != aContent), "null ptr");
|
|
||||||
mContent = aContent;
|
|
||||||
|
|
||||||
NS_IF_RELEASE(mAttrName);
|
|
||||||
mNameSpaceID = aNameSpaceID;
|
|
||||||
mAttrName = aAttrName;
|
|
||||||
NS_ADDREF(mAttrName);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param aIID The name of the class implementing the method
|
|
||||||
* @param _classiiddef The name of the #define symbol that defines the IID
|
|
||||||
* for the class (e.g. NS_ISUPPORTS_IID)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
nsresult nsAttributeContent::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (NULL == aInstancePtr) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aIID.Equals(NS_GET_IID(nsIContent))) {
|
|
||||||
*aInstancePtr = (void*) ((nsIContent*)this);
|
|
||||||
NS_ADDREF_THIS();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aIID.Equals(NS_GET_IID(nsITextContent))) {
|
|
||||||
*aInstancePtr = (void*) ((nsITextContent*)this);
|
|
||||||
NS_ADDREF_THIS();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aIID.Equals(NS_GET_IID(nsIAttributeContent))) {
|
|
||||||
*aInstancePtr = (void*) ((nsIAttributeContent*)this);
|
|
||||||
NS_ADDREF_THIS();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
|
||||||
*aInstancePtr = (void*) ((nsISupports*)(nsIContent*)this);
|
|
||||||
NS_ADDREF_THIS();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_NOINTERFACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Implementation of nsIContent
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
nsAttributeContent::ToCString(nsAWritableString& aBuf, PRInt32 aOffset,
|
|
||||||
PRInt32 aLen) const
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::GetDocument(nsIDocument*& aResult) const
|
|
||||||
{
|
|
||||||
aResult = mDocument;
|
|
||||||
NS_IF_ADDREF(mDocument);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers)
|
|
||||||
{
|
|
||||||
mDocument = aDocument;
|
|
||||||
//NS_IF_ADDREF(mDocument);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::GetParent(nsIContent*& aResult) const
|
|
||||||
{
|
|
||||||
NS_IF_ADDREF(mParent);
|
|
||||||
aResult = mParent;
|
|
||||||
return NS_OK;;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::SetParent(nsIContent* aParent)
|
|
||||||
{
|
|
||||||
mParent = aParent;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::HandleDOMEvent(nsIPresContext* aPresContext,
|
|
||||||
nsEvent* aEvent,
|
|
||||||
nsIDOMEvent** aDOMEvent,
|
|
||||||
PRUint32 aFlags,
|
|
||||||
nsEventStatus* aEventStatus)
|
|
||||||
{
|
|
||||||
nsresult ret = NS_OK;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::RangeAdd(nsIDOMRange& aRange)
|
|
||||||
{
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::RangeRemove(nsIDOMRange& aRange)
|
|
||||||
{
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::GetRangeList(nsVoidArray*& aResult) const
|
|
||||||
{
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Implementation of the nsITextContent interface
|
|
||||||
|
|
||||||
void
|
|
||||||
nsAttributeContent::ValidateTextFragment()
|
|
||||||
{
|
|
||||||
if (nsnull != mContent) {
|
|
||||||
nsAutoString result;
|
|
||||||
mContent->GetAttribute(mNameSpaceID, mAttrName, result);
|
|
||||||
|
|
||||||
PRUnichar * text = result.ToNewUnicode();
|
|
||||||
mText.SetTo(text, result.Length());
|
|
||||||
nsCRT::free(text);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mText.SetTo("", 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::GetText(const nsTextFragment** aFragmentsResult)
|
|
||||||
{
|
|
||||||
ValidateTextFragment();
|
|
||||||
if (nsnull != mContent) {
|
|
||||||
*aFragmentsResult = &mText;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
// XXX is this a good idea, or should we just return an empty
|
|
||||||
// fragment with no data in it?
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::GetTextLength(PRInt32* aLengthResult)
|
|
||||||
{
|
|
||||||
if (!aLengthResult) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
ValidateTextFragment();
|
|
||||||
*aLengthResult = mText.GetLength();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::CopyText(nsAWritableString& aResult)
|
|
||||||
{
|
|
||||||
ValidateTextFragment();
|
|
||||||
if (mText.Is2b()) {
|
|
||||||
aResult.Assign(mText.Get2b(), mText.GetLength());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
aResult.Assign(NS_ConvertASCIItoUCS2(mText.Get1b(), mText.GetLength()).get(), mText.GetLength());
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX shouldn't these update mContent's attribute?
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::SetText(const PRUnichar* aBuffer, PRInt32 aLength,
|
|
||||||
PRBool aNotify)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION((aLength >= 0) && (nsnull != aBuffer), "bad args");
|
|
||||||
if (aLength < 0) {
|
|
||||||
return NS_ERROR_ILLEGAL_VALUE;
|
|
||||||
}
|
|
||||||
if (nsnull == aBuffer) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
mText.SetTo(aBuffer, aLength);
|
|
||||||
|
|
||||||
// Trigger a reflow
|
|
||||||
if (aNotify && (nsnull != mDocument)) {
|
|
||||||
mDocument->ContentChanged(mContent, nsnull);
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAttributeContent::SetText(const nsAReadableString& aStr,
|
|
||||||
PRBool aNotify)
|
|
||||||
{
|
|
||||||
mText = aStr;
|
|
||||||
|
|
||||||
// Trigger a reflow
|
|
||||||
if (aNotify && (nsnull != mDocument)) {
|
|
||||||
mDocument->ContentChanged(mContent, nsnull);
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX shouldn't these update mContent's attribute?
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::SetText(const char* aBuffer,
|
|
||||||
PRInt32 aLength,
|
|
||||||
PRBool aNotify)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION((aLength >= 0) && (nsnull != aBuffer), "bad args");
|
|
||||||
if (aLength < 0) {
|
|
||||||
return NS_ERROR_ILLEGAL_VALUE;
|
|
||||||
}
|
|
||||||
if (nsnull == aBuffer) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
mText.SetTo(aBuffer, aLength);
|
|
||||||
|
|
||||||
// Trigger a reflow
|
|
||||||
if (aNotify && (nsnull != mDocument)) {
|
|
||||||
mDocument->ContentChanged(mContent, nsnull);
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsAttributeContent::IsOnlyWhitespace(PRBool* aResult)
|
|
||||||
{
|
|
||||||
ValidateTextFragment();
|
|
||||||
|
|
||||||
nsTextFragment& frag = mText;
|
|
||||||
if (frag.Is2b()) {
|
|
||||||
const PRUnichar* cp = frag.Get2b();
|
|
||||||
const PRUnichar* end = cp + frag.GetLength();
|
|
||||||
while (cp < end) {
|
|
||||||
PRUnichar ch = *cp++;
|
|
||||||
if (!XP_IS_SPACE(ch)) {
|
|
||||||
*aResult = PR_FALSE;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const char* cp = frag.Get1b();
|
|
||||||
const char* end = cp + frag.GetLength();
|
|
||||||
while (cp < end) {
|
|
||||||
PRUnichar ch = PRUnichar(*(unsigned char*)cp);
|
|
||||||
cp++;
|
|
||||||
if (!XP_IS_SPACE(ch)) {
|
|
||||||
*aResult = PR_FALSE;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*aResult = PR_TRUE;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAttributeContent::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
|
||||||
{
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
nsAttributeContent* it;
|
|
||||||
NS_NEWXPCOM(it, nsAttributeContent);
|
|
||||||
if (nsnull == it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
result = it->QueryInterface(NS_GET_IID(nsITextContent), (void**) aReturn);
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
result = it->Init(mContent, mNameSpaceID, mAttrName);
|
|
||||||
if (NS_FAILED(result) || !aCloneText) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
it->mText = mText;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsAttributeContent::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
if (!aResult) return NS_ERROR_NULL_POINTER;
|
|
||||||
*aResult = sizeof(*this);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nslayout.h"
|
|
||||||
#include "nsGenericDOMHTMLCollection.h"
|
|
||||||
|
|
||||||
|
|
||||||
nsGenericDOMHTMLCollection::nsGenericDOMHTMLCollection()
|
|
||||||
{
|
|
||||||
NS_INIT_REFCNT();
|
|
||||||
mScriptObject = nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsGenericDOMHTMLCollection::~nsGenericDOMHTMLCollection()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsGenericDOMHTMLCollection::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
||||||
{
|
|
||||||
if (NULL == aInstancePtr) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
if (aIID.Equals(NS_GET_IID(nsIDOMHTMLCollection))) {
|
|
||||||
*aInstancePtr = (void*)(nsIDOMHTMLCollection*)this;
|
|
||||||
AddRef();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) {
|
|
||||||
*aInstancePtr = (void*)(nsIScriptObjectOwner*)this;
|
|
||||||
AddRef();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
|
||||||
*aInstancePtr = (void*)(nsISupports*)(nsIDOMHTMLCollection*)this;
|
|
||||||
AddRef();
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
return NS_NOINTERFACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsGenericDOMHTMLCollection)
|
|
||||||
NS_IMPL_RELEASE(nsGenericDOMHTMLCollection)
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsGenericDOMHTMLCollection::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
|
||||||
{
|
|
||||||
nsresult res = NS_OK;
|
|
||||||
if (nsnull == mScriptObject) {
|
|
||||||
res = NS_NewScriptHTMLCollection(aContext, (nsISupports *)(nsIDOMHTMLCollection *)this, nsnull, (void**)&mScriptObject);
|
|
||||||
}
|
|
||||||
*aScriptObject = mScriptObject;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsGenericDOMHTMLCollection::SetScriptObject(void *aScriptObject)
|
|
||||||
{
|
|
||||||
mScriptObject = aScriptObject;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef nsGenericDOMHTMLCollection_h__
|
|
||||||
#define nsGenericDOMHTMLCollection_h__
|
|
||||||
|
|
||||||
#include "nsISupports.h"
|
|
||||||
#include "nsIDOMHTMLCollection.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a base class for a generic HTML collection. The base class
|
|
||||||
* provides implementations for nsISupports and nsIScriptObjectOwner,
|
|
||||||
* but it is up to the subclass to implement the core HTML collection
|
|
||||||
* methods:
|
|
||||||
* GetLength
|
|
||||||
* Item
|
|
||||||
* NamedItem
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class nsGenericDOMHTMLCollection : public nsIDOMHTMLCollection,
|
|
||||||
public nsIScriptObjectOwner
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsGenericDOMHTMLCollection();
|
|
||||||
virtual ~nsGenericDOMHTMLCollection();
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
|
|
||||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
|
||||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
|
||||||
|
|
||||||
// The following need to be defined in the subclass
|
|
||||||
// nsIDOMHTMLCollection interface
|
|
||||||
NS_IMETHOD GetLength(PRUint32* aLength)=0;
|
|
||||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0;
|
|
||||||
NS_IMETHOD NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn)=0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void* mScriptObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // nsGenericDOMHTMLCollection_h__
|
|
@ -1,703 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsHTMLUtils.h"
|
|
||||||
#include "nsIDOMHTMLAnchorElement.h"
|
|
||||||
#include "nsIDOMNSHTMLAnchorElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsILink.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsIEventStateManager.h"
|
|
||||||
#include "nsIURL.h"
|
|
||||||
|
|
||||||
#include "nsIEventStateManager.h"
|
|
||||||
#include "nsIDOMEvent.h"
|
|
||||||
#include "nsNetUtil.h"
|
|
||||||
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsIFrameManager.h"
|
|
||||||
#include "nsIPresShell.h"
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
#include "prprf.h"
|
|
||||||
|
|
||||||
// XXX suppress
|
|
||||||
|
|
||||||
// XXX either suppress is handled in the event code below OR we need a
|
|
||||||
// custom frame
|
|
||||||
|
|
||||||
class nsHTMLAnchorElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLAnchorElement,
|
|
||||||
public nsIDOMNSHTMLAnchorElement,
|
|
||||||
public nsILink
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLAnchorElement();
|
|
||||||
virtual ~nsHTMLAnchorElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLAnchorElement
|
|
||||||
NS_DECL_IDOMHTMLANCHORELEMENT
|
|
||||||
|
|
||||||
// nsIDOMNSHTMLAnchorElement
|
|
||||||
NS_DECL_IDOMNSHTMLANCHORELEMENT
|
|
||||||
|
|
||||||
// nsILink
|
|
||||||
NS_IMETHOD GetLinkState(nsLinkState &aState);
|
|
||||||
NS_IMETHOD SetLinkState(nsLinkState aState);
|
|
||||||
NS_IMETHOD GetHrefCString(char* &aBuf);
|
|
||||||
|
|
||||||
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep,
|
|
||||||
PRBool aCompileEventHandlers);
|
|
||||||
NS_IMETHOD SetFocus(nsIPresContext* aPresContext);
|
|
||||||
NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext);
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent,
|
|
||||||
nsIDOMEvent** aDOMEvent, PRUint32 aFlags,
|
|
||||||
nsEventStatus* aEventStatus);
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
nsresult RegUnRegAccessKey(PRBool aDoReg);
|
|
||||||
|
|
||||||
// The cached visited state
|
|
||||||
nsLinkState mLinkState;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLAnchorElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLAnchorElement* it = new nsHTMLAnchorElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLAnchorElement::nsHTMLAnchorElement() : mLinkState(eLinkState_Unknown)
|
|
||||||
{
|
|
||||||
nsHTMLUtils::AddRef(); // for GetHrefCString
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLAnchorElement::~nsHTMLAnchorElement()
|
|
||||||
{
|
|
||||||
nsHTMLUtils::Release(); // for GetHrefCString
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLAnchorElement, nsGenericElement)
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLAnchorElement, nsGenericElement)
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI3(nsHTMLAnchorElement, nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLAnchorElement, nsIDOMNSHTMLAnchorElement,
|
|
||||||
nsILink)
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLAnchorElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLAnchorElement* it = new nsHTMLAnchorElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, AccessKey, accesskey)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Charset, charset)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Coords, coords)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Hreflang, hreflang)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Name, name)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Rel, rel)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Rev, rev)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Shape, shape)
|
|
||||||
NS_IMPL_INT_ATTR(nsHTMLAnchorElement, TabIndex, tabindex)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Target, target)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Type, type)
|
|
||||||
|
|
||||||
|
|
||||||
// This goes and gets the proper PresContext in order
|
|
||||||
// for it to get the EventStateManager so it can register
|
|
||||||
// the access key
|
|
||||||
nsresult nsHTMLAnchorElement::RegUnRegAccessKey(PRBool aDoReg)
|
|
||||||
{
|
|
||||||
// first check to see if it even has an acess key
|
|
||||||
nsAutoString accessKey;
|
|
||||||
PRInt32 nameSpaceID;
|
|
||||||
GetNameSpaceID(nameSpaceID);
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
rv = NS_STATIC_CAST(nsIContent *, this)->GetAttribute(nameSpaceID,
|
|
||||||
nsHTMLAtoms::accesskey,
|
|
||||||
accessKey);
|
|
||||||
|
|
||||||
if (NS_CONTENT_ATTR_NOT_THERE != rv) {
|
|
||||||
nsCOMPtr<nsIPresContext> presContext;
|
|
||||||
GetPresContext(this, getter_AddRefs(presContext));
|
|
||||||
|
|
||||||
// With a valid PresContext we can get the EVM
|
|
||||||
// and register the access key
|
|
||||||
if (presContext) {
|
|
||||||
nsCOMPtr<nsIEventStateManager> stateManager;
|
|
||||||
presContext->GetEventStateManager(getter_AddRefs(stateManager));
|
|
||||||
|
|
||||||
if (stateManager) {
|
|
||||||
if (aDoReg) {
|
|
||||||
return stateManager->RegisterAccessKey(nsnull, this,
|
|
||||||
(PRUint32)accessKey.First());
|
|
||||||
} else {
|
|
||||||
return stateManager->UnregisterAccessKey(nsnull, this,
|
|
||||||
(PRUint32)accessKey.First());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::SetDocument(nsIDocument* aDocument, PRBool aDeep,
|
|
||||||
PRBool aCompileEventHandlers)
|
|
||||||
{
|
|
||||||
// The document gets set to null before it is destroyed,
|
|
||||||
// so we unregister the the access key here (if it has one)
|
|
||||||
// before setting it to null
|
|
||||||
if (aDocument == nsnull) {
|
|
||||||
RegUnRegAccessKey(PR_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv;
|
|
||||||
rv = nsGenericHTMLContainerElement::SetDocument(aDocument,
|
|
||||||
aDeep,
|
|
||||||
aCompileEventHandlers);
|
|
||||||
|
|
||||||
// Register the access key here (if it has one)
|
|
||||||
// if the document isn't null
|
|
||||||
if (aDocument != nsnull) {
|
|
||||||
RegUnRegAccessKey(PR_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::Blur()
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIPresContext> presContext;
|
|
||||||
GetPresContext(this, getter_AddRefs(presContext));
|
|
||||||
return RemoveFocus(presContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::Focus()
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDocument> doc; // Strong
|
|
||||||
nsresult rv = GetDocument(*getter_AddRefs(doc));
|
|
||||||
if (NS_FAILED(rv)) { return rv; }
|
|
||||||
if (!doc) { return NS_ERROR_NULL_POINTER; }
|
|
||||||
|
|
||||||
PRInt32 numShells = doc->GetNumberOfShells();
|
|
||||||
nsCOMPtr<nsIPresContext> context;
|
|
||||||
|
|
||||||
for (PRInt32 i=0; i<numShells; i++) {
|
|
||||||
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(i));
|
|
||||||
if (!shell) { return NS_ERROR_NULL_POINTER; }
|
|
||||||
|
|
||||||
rv = shell->GetPresContext(getter_AddRefs(context));
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!context) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = SetFocus(context);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::SetFocus(nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
// don't make the link grab the focus if there is no link handler
|
|
||||||
nsCOMPtr<nsILinkHandler> handler;
|
|
||||||
nsresult rv = aPresContext->GetLinkHandler(getter_AddRefs(handler));
|
|
||||||
if (NS_SUCCEEDED(rv) && (nsnull != handler)) {
|
|
||||||
nsCOMPtr<nsIEventStateManager> stateManager;
|
|
||||||
|
|
||||||
aPresContext->GetEventStateManager(getter_AddRefs(stateManager));
|
|
||||||
|
|
||||||
if (stateManager) {
|
|
||||||
stateManager->SetContentState(this, NS_EVENT_STATE_FOCUS);
|
|
||||||
|
|
||||||
// Make sure the presentation is up-to-date
|
|
||||||
if (mDocument) {
|
|
||||||
mDocument->FlushPendingNotifications();
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPresShell> presShell;
|
|
||||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
||||||
|
|
||||||
if (presShell) {
|
|
||||||
nsIFrame* frame = nsnull;
|
|
||||||
presShell->GetPrimaryFrameFor(this, &frame);
|
|
||||||
if (frame) {
|
|
||||||
presShell->ScrollFrameIntoView(frame, NS_PRESSHELL_SCROLL_ANYWHERE,
|
|
||||||
NS_PRESSHELL_SCROLL_ANYWHERE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::RemoveFocus(nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
// If we are disabled, we probably shouldn't have focus in the
|
|
||||||
// first place, so allow it to be removed.
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEventStateManager> esm;
|
|
||||||
aPresContext->GetEventStateManager(getter_AddRefs(esm));
|
|
||||||
|
|
||||||
if (esm) {
|
|
||||||
nsCOMPtr<nsIDocument> doc;
|
|
||||||
GetDocument(*getter_AddRefs(doc));
|
|
||||||
if (!doc)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> rootContent;
|
|
||||||
rootContent = getter_AddRefs(doc->GetRootContent());
|
|
||||||
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
|
||||||
if (ParseValue(aValue, 0, 32767, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::suppress) {
|
|
||||||
if (nsCRT::strcasecmp(nsPromiseFlatString(aValue).get(),
|
|
||||||
NS_LITERAL_STRING("true").get())) {
|
|
||||||
aResult.SetEmptyValue(); // XXX? shouldn't just leave "true"
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX support suppress in here
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::HandleDOMEvent(nsIPresContext* aPresContext,
|
|
||||||
nsEvent* aEvent,
|
|
||||||
nsIDOMEvent** aDOMEvent,
|
|
||||||
PRUint32 aFlags,
|
|
||||||
nsEventStatus* aEventStatus)
|
|
||||||
{
|
|
||||||
return HandleDOMEventForAnchors(this, aPresContext, aEvent, aDOMEvent,
|
|
||||||
aFlags, aEventStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetHref(nsAWritableString& aValue)
|
|
||||||
{
|
|
||||||
char *buf;
|
|
||||||
nsresult rv = GetHrefCString(buf);
|
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
if (buf) {
|
|
||||||
aValue.Assign(NS_ConvertASCIItoUCS2(buf));
|
|
||||||
nsCRT::free(buf);
|
|
||||||
}
|
|
||||||
// NS_IMPL_STRING_ATTR does nothing where we have (buf == null)
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::SetHref(const nsAReadableString& aValue)
|
|
||||||
{
|
|
||||||
// Clobber our "cache", so we'll recompute it the next time
|
|
||||||
// somebody asks for it.
|
|
||||||
mLinkState = eLinkState_Unknown;
|
|
||||||
|
|
||||||
return NS_STATIC_CAST(nsIContent *, this)->SetAttribute(kNameSpaceID_HTML,
|
|
||||||
nsHTMLAtoms::href,
|
|
||||||
aValue, PR_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetProtocol(nsAWritableString& aProtocol)
|
|
||||||
{
|
|
||||||
nsAutoString href;
|
|
||||||
nsCOMPtr<nsIURI> url;
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
result = GetHref(href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
result = NS_NewURI(getter_AddRefs(url), href);
|
|
||||||
if (NS_FAILED(result))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
char* protocol;
|
|
||||||
result = url->GetScheme(&protocol);
|
|
||||||
if (NS_FAILED(result))
|
|
||||||
return result;
|
|
||||||
|
|
||||||
aProtocol.Assign(NS_ConvertASCIItoUCS2(protocol));
|
|
||||||
aProtocol.Append(PRUnichar(':'));
|
|
||||||
|
|
||||||
nsCRT::free(protocol);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetHost(nsAWritableString& aHost)
|
|
||||||
{
|
|
||||||
nsAutoString href;
|
|
||||||
nsCOMPtr<nsIURI> url;
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
result = GetHref(href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
result = NS_NewURI(getter_AddRefs(url), href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
char* host;
|
|
||||||
result = url->GetHost(&host);
|
|
||||||
if (result == NS_OK) {
|
|
||||||
aHost.Assign(NS_ConvertASCIItoUCS2(host));
|
|
||||||
nsCRT::free(host);
|
|
||||||
PRInt32 port;
|
|
||||||
(void)url->GetPort(&port);
|
|
||||||
if (-1 != port) {
|
|
||||||
aHost.Append(NS_LITERAL_STRING(":"));
|
|
||||||
nsAutoString portStr;
|
|
||||||
portStr.AppendInt(port);
|
|
||||||
aHost.Append(portStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetHostname(nsAWritableString& aHostname)
|
|
||||||
{
|
|
||||||
nsAutoString href;
|
|
||||||
nsIURI *url;
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
result = GetHref(href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
result = NS_NewURI(&url, href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
char* host;
|
|
||||||
result = url->GetHost(&host);
|
|
||||||
if (result == NS_OK) {
|
|
||||||
aHostname.Assign(NS_ConvertASCIItoUCS2(host));
|
|
||||||
nsCRT::free(host);
|
|
||||||
}
|
|
||||||
NS_RELEASE(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetPathname(nsAWritableString& aPathname)
|
|
||||||
{
|
|
||||||
nsAutoString href;
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
aPathname.Truncate();
|
|
||||||
|
|
||||||
result = GetHref(href);
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
||||||
|
|
||||||
if (!url) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* file;
|
|
||||||
result = url->GetFilePath(&file);
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
aPathname.Assign(NS_ConvertASCIItoUCS2(file));
|
|
||||||
nsCRT::free(file);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetSearch(nsAWritableString& aSearch)
|
|
||||||
{
|
|
||||||
nsAutoString href;
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
result = GetHref(href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
char *search;
|
|
||||||
nsIURL* url;
|
|
||||||
result = uri->QueryInterface(NS_GET_IID(nsIURL), (void**)&url);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result)) {
|
|
||||||
result = url->GetEscapedQuery(&search);
|
|
||||||
NS_RELEASE(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && search && (*search)) {
|
|
||||||
aSearch.Assign(PRUnichar('?'));
|
|
||||||
aSearch.Append(NS_ConvertASCIItoUCS2(search));
|
|
||||||
nsCRT::free(search);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
aSearch.SetLength(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetPort(nsAWritableString& aPort)
|
|
||||||
{
|
|
||||||
nsAutoString href;
|
|
||||||
nsCOMPtr<nsIURI> url;
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
result = GetHref(href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
result = NS_NewURI(getter_AddRefs(url), href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
aPort.Truncate(0);
|
|
||||||
PRInt32 port;
|
|
||||||
(void)url->GetPort(&port);
|
|
||||||
if (-1 != port) {
|
|
||||||
nsAutoString portStr;
|
|
||||||
portStr.AppendInt(port);
|
|
||||||
aPort.Append(portStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetHash(nsAWritableString& aHash)
|
|
||||||
{
|
|
||||||
nsAutoString href;
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
result = GetHref(href);
|
|
||||||
if (NS_OK == result) {
|
|
||||||
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
||||||
|
|
||||||
if (NS_OK == result) {
|
|
||||||
char *ref;
|
|
||||||
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
||||||
if (url) {
|
|
||||||
result = url->GetRef(&ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == NS_OK && (nsnull != ref) && ('\0' != *ref)) {
|
|
||||||
aHash.Assign(PRUnichar('#'));
|
|
||||||
aHash.Append(NS_ConvertASCIItoUCS2(ref));
|
|
||||||
nsCRT::free(ref);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
aHash.SetLength(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetText(nsAWritableString& aText)
|
|
||||||
{
|
|
||||||
aText.Truncate();
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> child;
|
|
||||||
|
|
||||||
GetFirstChild(getter_AddRefs(child));
|
|
||||||
|
|
||||||
if (child) {
|
|
||||||
child->GetNodeValue(aText);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetLinkState(nsLinkState &aState)
|
|
||||||
{
|
|
||||||
aState = mLinkState;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::SetLinkState(nsLinkState aState)
|
|
||||||
{
|
|
||||||
mLinkState = aState;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLAnchorElement::GetHrefCString(char* &aBuf)
|
|
||||||
{
|
|
||||||
// Get href= attribute (relative URL).
|
|
||||||
nsAutoString relURLSpec;
|
|
||||||
|
|
||||||
if (NS_CONTENT_ATTR_HAS_VALUE ==
|
|
||||||
NS_STATIC_CAST(nsIContent *, this)->GetAttribute(kNameSpaceID_HTML,
|
|
||||||
nsHTMLAtoms::href,
|
|
||||||
relURLSpec)) {
|
|
||||||
// Clean up any leading or trailing whitespace
|
|
||||||
relURLSpec.Trim(" \t\n\r");
|
|
||||||
|
|
||||||
// Get base URL.
|
|
||||||
nsCOMPtr<nsIURI> baseURL;
|
|
||||||
GetBaseURL(*getter_AddRefs(baseURL));
|
|
||||||
|
|
||||||
if (baseURL) {
|
|
||||||
// Get absolute URL.
|
|
||||||
NS_MakeAbsoluteURIWithCharset(&aBuf, relURLSpec, mDocument, baseURL,
|
|
||||||
nsHTMLUtils::IOService,
|
|
||||||
nsHTMLUtils::CharsetMgr);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Absolute URL is same as relative URL.
|
|
||||||
aBuf = relURLSpec.ToNewUTF8String();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Absolute URL is null to say we have no HREF.
|
|
||||||
aBuf = nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,161 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLBaseFontElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLBaseFontElement : public nsGenericHTMLLeafElement,
|
|
||||||
public nsIDOMHTMLBaseFontElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLBaseFontElement();
|
|
||||||
virtual ~nsHTMLBaseFontElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLLeafElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLLeafElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLLeafElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLBaseElement
|
|
||||||
NS_DECL_IDOMHTMLBASEFONTELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLBaseFontElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLBaseFontElement* it = new nsHTMLBaseFontElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLBaseFontElement::nsHTMLBaseFontElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLBaseFontElement::~nsHTMLBaseFontElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsHTMLBaseFontElement)
|
|
||||||
NS_IMPL_RELEASE(nsHTMLBaseFontElement)
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLBaseFontElement, nsGenericHTMLLeafElement,
|
|
||||||
nsIDOMHTMLBaseFontElement)
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLBaseFontElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLBaseFontElement* it = new nsHTMLBaseFontElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLBaseFontElement, Color, color)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLBaseFontElement, Face, face)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLBaseFontElement, Size, size)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLBaseFontElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if ((nsHTMLAtoms::color == aAttribute) ||
|
|
||||||
(nsHTMLAtoms::face == aAttribute) ||
|
|
||||||
(nsHTMLAtoms::size == aAttribute)) {
|
|
||||||
aHint = NS_STYLE_HINT_RECONSTRUCT_ALL; // XXX this seems a bit harsh, perhaps we need a reflow_all?
|
|
||||||
}
|
|
||||||
else if (! nsGenericHTMLElement::GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLBaseFontElement::SizeOf(nsISizeOfHandler* aSizer,
|
|
||||||
PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,497 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLButtonElement.h"
|
|
||||||
#include "nsIDOMNSHTMLButtonElement.h"
|
|
||||||
#include "nsIDOMHTMLFormElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsIFormControl.h"
|
|
||||||
#include "nsIForm.h"
|
|
||||||
#include "nsIURL.h"
|
|
||||||
|
|
||||||
#include "nsIFormControlFrame.h"
|
|
||||||
#include "nsIEventStateManager.h"
|
|
||||||
#include "nsIDOMEvent.h"
|
|
||||||
#include "nsISizeOfHandler.h"
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLButtonElement : public nsGenericHTMLContainerFormElement,
|
|
||||||
public nsIDOMHTMLButtonElement,
|
|
||||||
public nsIDOMNSHTMLButtonElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLButtonElement();
|
|
||||||
virtual ~nsHTMLButtonElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerFormElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerFormElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLButtonElement
|
|
||||||
NS_DECL_IDOMHTMLBUTTONELEMENT
|
|
||||||
|
|
||||||
// nsIDOMNSHTMLButtonElement
|
|
||||||
NS_DECL_IDOMNSHTMLBUTTONELEMENT
|
|
||||||
|
|
||||||
// overrided nsIFormControl method
|
|
||||||
NS_IMETHOD GetType(PRInt32* aType);
|
|
||||||
|
|
||||||
// nsIContent overrides...
|
|
||||||
NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
|
||||||
const nsAReadableString& aValue, PRBool aNotify);
|
|
||||||
NS_IMETHOD SetFocus(nsIPresContext* aPresContext);
|
|
||||||
NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext);
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext,
|
|
||||||
nsEvent* aEvent,
|
|
||||||
nsIDOMEvent** aDOMEvent,
|
|
||||||
PRUint32 aFlags,
|
|
||||||
nsEventStatus* aEventStatus);
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
PRInt8 mType;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Construction, destruction
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLButtonElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLButtonElement* it = new nsHTMLButtonElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = NS_STATIC_CAST(nsGenericElement *, it)->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLButtonElement::nsHTMLButtonElement()
|
|
||||||
{
|
|
||||||
mType = NS_FORM_BUTTON_BUTTON; // default
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLButtonElement::~nsHTMLButtonElement()
|
|
||||||
{
|
|
||||||
// Null out form's pointer to us - no ref counting here!
|
|
||||||
SetForm(nsnull);
|
|
||||||
}
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLButtonElement, nsGenericElement);
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLButtonElement, nsGenericElement);
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI2(nsHTMLButtonElement, nsGenericHTMLContainerFormElement,
|
|
||||||
nsIDOMHTMLButtonElement, nsIDOMNSHTMLButtonElement);
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
if (aName == nsHTMLAtoms::disabled) {
|
|
||||||
nsresult rv = nsGenericHTMLContainerFormElement::GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, aResult);
|
|
||||||
if (rv == NS_CONTENT_ATTR_NOT_THERE) {
|
|
||||||
aResult.Assign(NS_LITERAL_STRING("false"));
|
|
||||||
} else {
|
|
||||||
aResult.Assign(NS_LITERAL_STRING("true"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerFormElement::GetAttribute(aNameSpaceID, aName,
|
|
||||||
aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
PRBool aNotify)
|
|
||||||
{
|
|
||||||
nsAutoString value(aValue);
|
|
||||||
|
|
||||||
if (aName == nsHTMLAtoms::disabled &&
|
|
||||||
value.EqualsWithConversion("false", PR_TRUE)) {
|
|
||||||
return UnsetAttribute(aNameSpaceID, aName, aNotify);
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerFormElement::SetAttribute(aNameSpaceID, aName,
|
|
||||||
aValue, aNotify);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// nsIDOMHTMLButtonElement
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLButtonElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLButtonElement* it = new nsHTMLButtonElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = NS_STATIC_CAST(nsGenericElement *, it)->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// nsIContent
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
|
||||||
{
|
|
||||||
return nsGenericHTMLContainerFormElement::GetForm(aForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::GetType(nsAWritableString& aType)
|
|
||||||
{
|
|
||||||
return AttributeToString(nsHTMLAtoms::type,
|
|
||||||
nsHTMLValue(mType, eHTMLUnit_Enumerated),
|
|
||||||
aType);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLButtonElement, AccessKey, accesskey)
|
|
||||||
NS_IMPL_BOOL_ATTR(nsHTMLButtonElement, Disabled, disabled)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLButtonElement, Name, name)
|
|
||||||
NS_IMPL_INT_ATTR(nsHTMLButtonElement, TabIndex, tabindex)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLButtonElement, Value, value)
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::Blur()
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIPresContext> presContext;
|
|
||||||
GetPresContext(this, getter_AddRefs(presContext));
|
|
||||||
return RemoveFocus(presContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::Focus()
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIPresContext> presContext;
|
|
||||||
GetPresContext(this, getter_AddRefs(presContext));
|
|
||||||
return SetFocus(presContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::SetFocus(nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
// first see if we are disabled or not. If disabled then do nothing.
|
|
||||||
nsAutoString disabled;
|
|
||||||
if (NS_CONTENT_ATTR_HAS_VALUE == GetAttribute(kNameSpaceID_HTML,
|
|
||||||
nsHTMLAtoms::disabled,
|
|
||||||
disabled)) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEventStateManager> esm;
|
|
||||||
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
|
|
||||||
esm->SetContentState(this, NS_EVENT_STATE_FOCUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsIFormControlFrame* formControlFrame = nsnull;
|
|
||||||
nsresult rv = GetPrimaryFrame(this, formControlFrame);
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
formControlFrame->SetFocus(PR_TRUE, PR_TRUE);
|
|
||||||
formControlFrame->ScrollIntoView(aPresContext);
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::RemoveFocus(nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
// If we are disabled, we probably shouldn't have focus in the
|
|
||||||
// first place, so allow it to be removed.
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
|
|
||||||
nsIFormControlFrame* formControlFrame = nsnull;
|
|
||||||
rv = GetPrimaryFrame(this, formControlFrame);
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
formControlFrame->SetFocus(PR_FALSE, PR_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIEventStateManager> esm;
|
|
||||||
if (NS_OK == aPresContext->GetEventStateManager(getter_AddRefs(esm))) {
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> doc;
|
|
||||||
GetDocument(*getter_AddRefs(doc));
|
|
||||||
if (!doc)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContent> rootContent;
|
|
||||||
rootContent = getter_AddRefs(doc->GetRootContent());
|
|
||||||
rv = esm->SetContentState(rootContent, NS_EVENT_STATE_FOCUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsGenericHTMLElement::EnumTable kButtonTypeTable[] = {
|
|
||||||
{ "button", NS_FORM_BUTTON_BUTTON },
|
|
||||||
{ "reset", NS_FORM_BUTTON_RESET },
|
|
||||||
{ "submit", NS_FORM_BUTTON_SUBMIT },
|
|
||||||
{ 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::tabindex) {
|
|
||||||
if (ParseValue(aValue, 0, 32767, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::type) {
|
|
||||||
nsGenericHTMLElement::EnumTable *table = kButtonTypeTable;
|
|
||||||
nsAutoString val(aValue);
|
|
||||||
while (nsnull != table->tag) {
|
|
||||||
if (val.EqualsIgnoreCase(table->tag)) {
|
|
||||||
aResult.SetIntValue(table->value, eHTMLUnit_Enumerated);
|
|
||||||
mType = table->value;
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
table++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::disabled) {
|
|
||||||
aResult.SetEmptyValue();
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::type) {
|
|
||||||
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
|
|
||||||
EnumValueToString(aValue, kButtonTypeTable, aResult, PR_FALSE);
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerFormElement::AttributeToString(aAttribute,
|
|
||||||
aValue, aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::HandleDOMEvent(nsIPresContext* aPresContext,
|
|
||||||
nsEvent* aEvent,
|
|
||||||
nsIDOMEvent** aDOMEvent,
|
|
||||||
PRUint32 aFlags,
|
|
||||||
nsEventStatus* aEventStatus)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG(aPresContext);
|
|
||||||
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
||||||
|
|
||||||
// Do not process any DOM events if the element is disabled
|
|
||||||
PRBool bDisabled;
|
|
||||||
nsresult rv = GetDisabled(&bDisabled);
|
|
||||||
if (NS_FAILED(rv) || bDisabled) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try script event handlers first
|
|
||||||
nsresult ret;
|
|
||||||
ret = nsGenericHTMLContainerFormElement::HandleDOMEvent(aPresContext,
|
|
||||||
aEvent, aDOMEvent,
|
|
||||||
aFlags,
|
|
||||||
aEventStatus);
|
|
||||||
|
|
||||||
if ((NS_OK == ret) && (nsEventStatus_eIgnore == *aEventStatus) &&
|
|
||||||
!(aFlags & NS_EVENT_FLAG_CAPTURE)) {
|
|
||||||
switch (aEvent->message) {
|
|
||||||
|
|
||||||
case NS_KEY_PRESS:
|
|
||||||
case NS_KEY_UP:
|
|
||||||
{
|
|
||||||
// For backwards compat, trigger buttons with space or enter
|
|
||||||
// (bug 25300)
|
|
||||||
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
||||||
if ((keyEvent->keyCode == NS_VK_RETURN && NS_KEY_PRESS == aEvent->message) ||
|
|
||||||
keyEvent->keyCode == NS_VK_SPACE && NS_KEY_UP == aEvent->message) {
|
|
||||||
nsEventStatus status = nsEventStatus_eIgnore;
|
|
||||||
nsMouseEvent event;
|
|
||||||
event.eventStructType = NS_MOUSE_EVENT;
|
|
||||||
event.message = NS_MOUSE_LEFT_CLICK;
|
|
||||||
event.isShift = PR_FALSE;
|
|
||||||
event.isControl = PR_FALSE;
|
|
||||||
event.isAlt = PR_FALSE;
|
|
||||||
event.isMeta = PR_FALSE;
|
|
||||||
event.clickCount = 0;
|
|
||||||
event.widget = nsnull;
|
|
||||||
rv = HandleDOMEvent(aPresContext, &event, nsnull,
|
|
||||||
NS_EVENT_FLAG_INIT, &status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;// NS_KEY_PRESS
|
|
||||||
|
|
||||||
case NS_MOUSE_LEFT_CLICK:
|
|
||||||
{
|
|
||||||
// Tell the frame about the click
|
|
||||||
nsIFormControlFrame* formControlFrame = nsnull;
|
|
||||||
rv = GetPrimaryFrame(this, formControlFrame);
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
formControlFrame->MouseClicked(aPresContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;// NS_MOUSE_LEFT_CLICK
|
|
||||||
|
|
||||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
|
||||||
{
|
|
||||||
nsIEventStateManager *stateManager;
|
|
||||||
if (NS_OK == aPresContext->GetEventStateManager(&stateManager)) {
|
|
||||||
stateManager->SetContentState(this, NS_EVENT_STATE_ACTIVE |
|
|
||||||
NS_EVENT_STATE_FOCUS);
|
|
||||||
NS_RELEASE(stateManager);
|
|
||||||
}
|
|
||||||
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// cancel all of these events for buttons
|
|
||||||
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
|
||||||
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
|
||||||
case NS_MOUSE_MIDDLE_DOUBLECLICK:
|
|
||||||
case NS_MOUSE_RIGHT_DOUBLECLICK:
|
|
||||||
case NS_MOUSE_RIGHT_BUTTON_DOWN:
|
|
||||||
case NS_MOUSE_RIGHT_BUTTON_UP:
|
|
||||||
if (aDOMEvent != nsnull && *aDOMEvent != nsnull) {
|
|
||||||
(*aDOMEvent)->PreventBubble();
|
|
||||||
} else {
|
|
||||||
ret = NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NS_MOUSE_ENTER_SYNTH:
|
|
||||||
{
|
|
||||||
nsIEventStateManager *stateManager;
|
|
||||||
if (NS_OK == aPresContext->GetEventStateManager(&stateManager)) {
|
|
||||||
stateManager->SetContentState(this, NS_EVENT_STATE_HOVER);
|
|
||||||
NS_RELEASE(stateManager);
|
|
||||||
}
|
|
||||||
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// XXX this doesn't seem to do anything yet
|
|
||||||
case NS_MOUSE_EXIT_SYNTH:
|
|
||||||
{
|
|
||||||
nsIEventStateManager *stateManager;
|
|
||||||
if (NS_OK == aPresContext->GetEventStateManager(&stateManager)) {
|
|
||||||
stateManager->SetContentState(nsnull, NS_EVENT_STATE_HOVER);
|
|
||||||
NS_RELEASE(stateManager);
|
|
||||||
}
|
|
||||||
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::GetType(PRInt32* aType)
|
|
||||||
{
|
|
||||||
if (aType) {
|
|
||||||
*aType = mType;
|
|
||||||
return NS_OK;
|
|
||||||
} else {
|
|
||||||
return NS_FORM_NOTOK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLButtonElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,244 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLDirectoryElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
|
|
||||||
// XXX nav4 has type= start= (same as OL/UL)
|
|
||||||
|
|
||||||
extern nsGenericHTMLElement::EnumTable kListTypeTable[];
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLDirectoryElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLDirectoryElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLDirectoryElement();
|
|
||||||
virtual ~nsHTMLDirectoryElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLDirectoryElement
|
|
||||||
NS_DECL_IDOMHTMLDIRECTORYELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const;
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLDirectoryElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLDirectoryElement* it = new nsHTMLDirectoryElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLDirectoryElement::nsHTMLDirectoryElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLDirectoryElement::~nsHTMLDirectoryElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLDirectoryElement, nsGenericElement);
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLDirectoryElement, nsGenericElement);
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLDirectoryElement, nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLDirectoryElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLDirectoryElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLDirectoryElement* it = new nsHTMLDirectoryElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_BOOL_ATTR(nsHTMLDirectoryElement, Compact, compact)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLDirectoryElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::type) {
|
|
||||||
if (ParseEnumValue(aValue, kListTypeTable, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::start) {
|
|
||||||
if (ParseValue(aValue, 1, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::compact) {
|
|
||||||
aResult.SetEmptyValue();
|
|
||||||
return NS_CONTENT_ATTR_NO_VALUE;
|
|
||||||
}
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLDirectoryElement::AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::type) {
|
|
||||||
EnumValueToString(aValue, kListTypeTable, aResult);
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
return nsGenericHTMLContainerElement::AttributeToString(aAttribute, aValue,
|
|
||||||
aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
|
||||||
nsIMutableStyleContext* aContext,
|
|
||||||
nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
if (nsnull != aAttributes) {
|
|
||||||
nsHTMLValue value;
|
|
||||||
nsStyleList* list = (nsStyleList*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_List);
|
|
||||||
|
|
||||||
// type: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::type, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
list->mListStyleType = value.GetIntValue();
|
|
||||||
}
|
|
||||||
else if (value.GetUnit() != eHTMLUnit_Null) {
|
|
||||||
list->mListStyleType = NS_STYLE_LIST_STYLE_BASIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
// compact: empty
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::compact, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Empty) {
|
|
||||||
// XXX set
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext, aPresContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLDirectoryElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::type) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::compact) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT; // XXX
|
|
||||||
}
|
|
||||||
else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLDirectoryElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const
|
|
||||||
{
|
|
||||||
aFontMapFunc = nsnull;
|
|
||||||
aMapFunc = &MapAttributesInto;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLDirectoryElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,455 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsIDOMHTMLFontElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIDeviceContext.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsStyleUtil.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
|
|
||||||
// MJA: bug 31816
|
|
||||||
#include "nsIPresShell.h"
|
|
||||||
#include "nsIDocShellTreeItem.h"
|
|
||||||
// - END MJA
|
|
||||||
|
|
||||||
class nsHTMLFontElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLFontElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLFontElement();
|
|
||||||
virtual ~nsHTMLFontElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLFontElement
|
|
||||||
NS_DECL_IDOMHTMLFONTELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const;
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLFontElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLFontElement* it = new nsHTMLFontElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLFontElement::nsHTMLFontElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLFontElement::~nsHTMLFontElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLFontElement, nsGenericElement);
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLFontElement, nsGenericElement);
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLFontElement, nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLFontElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLFontElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLFontElement* it = new nsHTMLFontElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLFontElement, Color, color)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLFontElement, Face, face)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLFontElement, Size, size)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLFontElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
if ((aAttribute == nsHTMLAtoms::size) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::pointSize) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::fontWeight)) {
|
|
||||||
nsAutoString tmp(aValue);
|
|
||||||
//rickg: fixed flaw where ToInteger error code was not being checked.
|
|
||||||
// This caused wrong default value for font size.
|
|
||||||
PRInt32 ec, v = tmp.ToInteger(&ec);
|
|
||||||
if(NS_SUCCEEDED(ec)){
|
|
||||||
tmp.CompressWhitespace(PR_TRUE, PR_FALSE);
|
|
||||||
PRUnichar ch = tmp.IsEmpty() ? 0 : tmp.First();
|
|
||||||
aResult.SetIntValue(v, ((ch == '+') || (ch == '-')) ?
|
|
||||||
eHTMLUnit_Integer : eHTMLUnit_Enumerated);
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::color) {
|
|
||||||
if (ParseColor(aValue, mDocument, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLFontElement::AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
if ((aAttribute == nsHTMLAtoms::size) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::pointSize) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::fontWeight)) {
|
|
||||||
aResult.Truncate();
|
|
||||||
nsAutoString intVal;
|
|
||||||
if (aValue.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
intVal.AppendInt(aValue.GetIntValue(), 10);
|
|
||||||
aResult.Append(intVal);
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
else if (aValue.GetUnit() == eHTMLUnit_Integer) {
|
|
||||||
PRInt32 value = aValue.GetIntValue();
|
|
||||||
if (value >= 0) {
|
|
||||||
aResult.Append(NS_LITERAL_STRING("+"));
|
|
||||||
}
|
|
||||||
intVal.AppendInt(value, 10);
|
|
||||||
aResult.Append(intVal);
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerElement::AttributeToString(aAttribute, aValue,
|
|
||||||
aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
MapFontAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
|
||||||
nsIMutableStyleContext* aContext,
|
|
||||||
nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
if (nsnull != aAttributes) {
|
|
||||||
nsHTMLValue value;
|
|
||||||
nsStyleFont* font = (nsStyleFont*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Font);
|
|
||||||
const nsStyleFont* parentFont = font;
|
|
||||||
nsIStyleContext* parentContext = aContext->GetParent();
|
|
||||||
if (nsnull != parentContext) {
|
|
||||||
parentFont = (const nsStyleFont*)
|
|
||||||
parentContext->GetStyleData(eStyleStruct_Font);
|
|
||||||
}
|
|
||||||
const nsFont& defaultFont = aPresContext->GetDefaultFontDeprecated();
|
|
||||||
const nsFont& defaultFixedFont = aPresContext->GetDefaultFixedFontDeprecated();
|
|
||||||
|
|
||||||
// face: string list
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::face, value);
|
|
||||||
|
|
||||||
if (value.GetUnit() == eHTMLUnit_String) {
|
|
||||||
nsCOMPtr<nsIDeviceContext> dc;
|
|
||||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
|
||||||
if (dc) {
|
|
||||||
nsAutoString familyList;
|
|
||||||
|
|
||||||
value.GetStringValue(familyList);
|
|
||||||
|
|
||||||
font->mFont.name = familyList;
|
|
||||||
nsAutoString face;
|
|
||||||
|
|
||||||
// MJA: bug 31816 if we are not using document fonts, but this
|
|
||||||
// is a xul document, then we set the chromeOverride bit so we
|
|
||||||
// use the document fonts anyway
|
|
||||||
PRBool chromeOverride = PR_FALSE;
|
|
||||||
PRBool useDocumentFonts = PR_TRUE;
|
|
||||||
aPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts,
|
|
||||||
useDocumentFonts);
|
|
||||||
if (!useDocumentFonts) {
|
|
||||||
// check if the prefs have been disabled for this shell
|
|
||||||
// - if prefs are disabled then we use the document fonts
|
|
||||||
// anyway (yet another override)
|
|
||||||
PRBool prefsEnabled = PR_TRUE;
|
|
||||||
nsCOMPtr<nsIPresShell> shell;
|
|
||||||
aPresContext->GetShell(getter_AddRefs(shell));
|
|
||||||
if (shell) {
|
|
||||||
shell->ArePrefStyleRulesEnabled(prefsEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!prefsEnabled) {
|
|
||||||
useDocumentFonts = PR_TRUE;
|
|
||||||
} else {
|
|
||||||
// see if we are in the chrome, if so, use the document fonts (override the useDocFonts setting)
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
nsCOMPtr<nsISupports> container;
|
|
||||||
result = aPresContext->GetContainer(getter_AddRefs(container));
|
|
||||||
if (NS_SUCCEEDED(result) && container) {
|
|
||||||
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(container, &result));
|
|
||||||
if (NS_SUCCEEDED(result) && docShell){
|
|
||||||
PRInt32 docShellType;
|
|
||||||
result = docShell->GetItemType(&docShellType);
|
|
||||||
if (NS_SUCCEEDED(result)){
|
|
||||||
if (nsIDocShellTreeItem::typeChrome == docShellType){
|
|
||||||
chromeOverride = PR_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// find the correct font if we are usingDocumentFonts OR we
|
|
||||||
// are overriding for XUL
|
|
||||||
// MJA: bug 31816
|
|
||||||
PRBool fontFaceOK = PR_TRUE;
|
|
||||||
PRBool isMozFixed = font->mFont.name.EqualsIgnoreCase("-moz-fixed");
|
|
||||||
if ((chromeOverride || useDocumentFonts)) {
|
|
||||||
fontFaceOK = (NS_OK == dc->FirstExistingFont(font->mFont, face));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fontFaceOK || !(chromeOverride || useDocumentFonts)) {
|
|
||||||
// now set to defaults
|
|
||||||
font->mFont.name = defaultFont.name;
|
|
||||||
font->mFixedFont.name= defaultFixedFont.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set to monospace if using moz-fixed
|
|
||||||
if (isMozFixed) {
|
|
||||||
font->mFlags |= NS_STYLE_FONT_USE_FIXED;
|
|
||||||
} else {
|
|
||||||
font->mFlags &= ~NS_STYLE_FONT_USE_FIXED;
|
|
||||||
}
|
|
||||||
|
|
||||||
font->mFlags |= NS_STYLE_FONT_FACE_EXPLICIT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pointSize: int, enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::pointSize, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Integer) {
|
|
||||||
// XXX should probably sanitize value
|
|
||||||
font->mFont.size = parentFont->mFont.size +
|
|
||||||
NSIntPointsToTwips(value.GetIntValue());
|
|
||||||
font->mFixedFont.size = parentFont->mFixedFont.size +
|
|
||||||
NSIntPointsToTwips(value.GetIntValue());
|
|
||||||
font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT;
|
|
||||||
}
|
|
||||||
else if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
font->mFont.size = NSIntPointsToTwips(value.GetIntValue());
|
|
||||||
font->mFixedFont.size = NSIntPointsToTwips(value.GetIntValue());
|
|
||||||
font->mFlags |= NS_STYLE_FONT_SIZE_EXPLICIT;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// size: int, enum , NOTE: this does not count as an explicit size
|
|
||||||
// also this has no effect if font is already explicit (quirk mode)
|
|
||||||
//
|
|
||||||
// NOTE: we now do not emulate this quirk - it is too stupid, IE does it right, and it
|
|
||||||
// messes up other blocks (ie. Headings) when implemented... see bug 25810
|
|
||||||
|
|
||||||
#if 0 // removing the quirk...
|
|
||||||
nsCompatibility mode;
|
|
||||||
aPresContext->GetCompatibilityMode(&mode);
|
|
||||||
if ((eCompatibility_Standard == mode) ||
|
|
||||||
(0 == (font->mFlags & NS_STYLE_FONT_SIZE_EXPLICIT))) {
|
|
||||||
#else
|
|
||||||
if (1) {
|
|
||||||
#endif
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::size, value);
|
|
||||||
|
|
||||||
if ((value.GetUnit() == eHTMLUnit_Integer) ||
|
|
||||||
(value.GetUnit() == eHTMLUnit_Enumerated)) {
|
|
||||||
PRInt32 size = value.GetIntValue();
|
|
||||||
|
|
||||||
if (size != 0) { // bug 32063: ignore <font size="">
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Integer) { // int (+/-)
|
|
||||||
size = 3 + size; // XXX should be BASEFONT, not three
|
|
||||||
}
|
|
||||||
size = ((0 < size) ? ((size < 8) ? size : 7) : 1);
|
|
||||||
PRInt32 scaler;
|
|
||||||
aPresContext->GetFontScaler(&scaler);
|
|
||||||
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
|
|
||||||
font->mFont.size =
|
|
||||||
nsStyleUtil::CalcFontPointSize(size, (PRInt32)defaultFont.size,
|
|
||||||
scaleFactor, aPresContext);
|
|
||||||
font->mFixedFont.size =
|
|
||||||
nsStyleUtil::CalcFontPointSize(size,
|
|
||||||
(PRInt32)defaultFixedFont.size,
|
|
||||||
scaleFactor, aPresContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fontWeight: int, enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::fontWeight, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Integer) { // +/-
|
|
||||||
PRInt32 intValue = (value.GetIntValue() / 100);
|
|
||||||
PRInt32 weight = nsStyleUtil::ConstrainFontWeight(parentFont->mFont.weight +
|
|
||||||
(intValue * NS_STYLE_FONT_WEIGHT_BOLDER));
|
|
||||||
font->mFont.weight = weight;
|
|
||||||
font->mFixedFont.weight = weight;
|
|
||||||
}
|
|
||||||
else if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
PRInt32 weight = value.GetIntValue();
|
|
||||||
weight = nsStyleUtil::ConstrainFontWeight((weight / 100) * 100);
|
|
||||||
font->mFont.weight = weight;
|
|
||||||
font->mFixedFont.weight = weight;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IF_RELEASE(parentContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
|
||||||
nsIMutableStyleContext* aContext,
|
|
||||||
nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
if (nsnull != aAttributes) {
|
|
||||||
nsHTMLValue value;
|
|
||||||
|
|
||||||
// color: color
|
|
||||||
if (NS_CONTENT_ATTR_NOT_THERE !=
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::color, value)) {
|
|
||||||
const nsStyleFont* font = (const nsStyleFont*)
|
|
||||||
aContext->GetStyleData(eStyleStruct_Font);
|
|
||||||
nsStyleColor* color = (nsStyleColor*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Color);
|
|
||||||
nsStyleText* text = (nsStyleText*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
if (((eHTMLUnit_Color == value.GetUnit())) ||
|
|
||||||
(eHTMLUnit_ColorName == value.GetUnit())) {
|
|
||||||
color->mColor = value.GetColorValue();
|
|
||||||
|
|
||||||
// re-apply inherited text decoration, so colors sync
|
|
||||||
text->mTextDecoration = font->mFont.decorations;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext,
|
|
||||||
aPresContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLFontElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::color) {
|
|
||||||
aHint = NS_STYLE_HINT_VISUAL;
|
|
||||||
}
|
|
||||||
else if ((aAttribute == nsHTMLAtoms::face) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::pointSize) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::size) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::fontWeight)) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
}
|
|
||||||
else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLFontElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const
|
|
||||||
{
|
|
||||||
aFontMapFunc = &MapFontAttributesInto;
|
|
||||||
aMapFunc = &MapAttributesInto;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLFontElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
@ -1,142 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLModElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLModElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLModElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLModElement();
|
|
||||||
virtual ~nsHTMLModElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLModElement
|
|
||||||
NS_DECL_IDOMHTMLMODELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLModElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLModElement* it = new nsHTMLModElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLModElement::nsHTMLModElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLModElement::~nsHTMLModElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLModElement, nsGenericElement);
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLModElement, nsGenericElement);
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLModElement, nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLModElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLModElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLModElement* it = new nsHTMLModElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLModElement, Cite, cite)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLModElement, DateTime, datetime)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLModElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,187 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLOptGroupElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsIFrame.h"
|
|
||||||
#include "nsIFormControlFrame.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLOptGroupElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLOptGroupElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLOptGroupElement();
|
|
||||||
virtual ~nsHTMLOptGroupElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLOptGroupElement
|
|
||||||
NS_DECL_IDOMHTMLOPTGROUPELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent,
|
|
||||||
nsIDOMEvent** aDOMEvent, PRUint32 aFlags,
|
|
||||||
nsEventStatus* aEventStatus);
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLOptGroupElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLOptGroupElement* it = new nsHTMLOptGroupElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLOptGroupElement::nsHTMLOptGroupElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLOptGroupElement::~nsHTMLOptGroupElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLOptGroupElement, nsGenericElement);
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLOptGroupElement, nsGenericElement);
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLOptGroupElement, nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLOptGroupElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLOptGroupElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLOptGroupElement* it = new nsHTMLOptGroupElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_BOOL_ATTR(nsHTMLOptGroupElement, Disabled, disabled)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLOptGroupElement, Label, label)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptGroupElement::HandleDOMEvent(nsIPresContext* aPresContext,
|
|
||||||
nsEvent* aEvent,
|
|
||||||
nsIDOMEvent** aDOMEvent,
|
|
||||||
PRUint32 aFlags,
|
|
||||||
nsEventStatus* aEventStatus)
|
|
||||||
{
|
|
||||||
// Do not process any DOM events if the element is disabled
|
|
||||||
PRBool disabled;
|
|
||||||
nsresult rv = GetDisabled(&disabled);
|
|
||||||
if (NS_FAILED(rv) || disabled) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsIFormControlFrame* formControlFrame = nsnull;
|
|
||||||
rv = GetPrimaryFrame(this, formControlFrame);
|
|
||||||
nsIFrame* formFrame = nsnull;
|
|
||||||
|
|
||||||
if (formControlFrame &&
|
|
||||||
NS_SUCCEEDED(formControlFrame->QueryInterface(NS_GET_IID(nsIFrame),
|
|
||||||
(void **)&formFrame)) &&
|
|
||||||
formFrame)
|
|
||||||
{
|
|
||||||
const nsStyleUserInterface* uiStyle;
|
|
||||||
formFrame->GetStyleData(eStyleStruct_UserInterface,
|
|
||||||
(const nsStyleStruct *&)uiStyle);
|
|
||||||
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
|
||||||
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
||||||
{
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerElement::HandleDOMEvent(aPresContext, aEvent,
|
|
||||||
aDOMEvent, aFlags,
|
|
||||||
aEventStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptGroupElement::SizeOf(nsISizeOfHandler* aSizer,
|
|
||||||
PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,753 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLOptionElement.h"
|
|
||||||
#include "nsIDOMHTMLOptGroupElement.h"
|
|
||||||
#include "nsIDOMNSHTMLOptionCollection.h"
|
|
||||||
#include "nsIDOMHTMLFormElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsIFormControl.h"
|
|
||||||
#include "nsIForm.h"
|
|
||||||
#include "nsIDOMText.h"
|
|
||||||
#include "nsITextContent.h"
|
|
||||||
#include "nsIDOMNode.h"
|
|
||||||
#include "nsGenericElement.h"
|
|
||||||
#include "nsIDOMHTMLCollection.h"
|
|
||||||
#include "nsIJSNativeInitializer.h"
|
|
||||||
#include "nsISelectElement.h"
|
|
||||||
#include "nsISelectControlFrame.h"
|
|
||||||
#include "nsIComboboxControlFrame.h"
|
|
||||||
|
|
||||||
// Notify/query select frame for selected state
|
|
||||||
#include "nsIFormControlFrame.h"
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
#include "nsIPresShell.h"
|
|
||||||
#include "nsIFrame.h"
|
|
||||||
#include "nsIDOMHTMLSelectElement.h"
|
|
||||||
#include "nsNodeInfoManager.h"
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLOptionElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLOptionElement,
|
|
||||||
public nsIJSNativeInitializer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLOptionElement();
|
|
||||||
virtual ~nsHTMLOptionElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLOptionElement
|
|
||||||
NS_DECL_IDOMHTMLOPTIONELEMENT
|
|
||||||
|
|
||||||
// nsIJSNativeInitializer
|
|
||||||
NS_IMETHOD Initialize(JSContext* aContext, JSObject *aObj,
|
|
||||||
PRUint32 argc, jsval *argv);
|
|
||||||
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// Get the primary frame associated with this content
|
|
||||||
nsresult GetPrimaryFrame(nsIFormControlFrame *&aFormControlFrame,
|
|
||||||
PRBool aFlushNotifications = PR_TRUE);
|
|
||||||
|
|
||||||
// Get the select content element that contains this option, this
|
|
||||||
// intentionally does not return nsresult, all we care about is if
|
|
||||||
// there's a select associated with this option or not.
|
|
||||||
void GetSelect(nsIDOMHTMLSelectElement *&aSelectElement);
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLOptionElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* nsHTMLOptionElement's will be created without a nsINodeInfo passed in
|
|
||||||
* if someone creates new option elements in JavaScript, in a case like
|
|
||||||
* that we request the nsINodeInfo from the anonymous nodeinfo list.
|
|
||||||
*/
|
|
||||||
nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo);
|
|
||||||
if (!nodeInfo) {
|
|
||||||
nsCOMPtr<nsINodeInfoManager> nodeInfoManager;
|
|
||||||
nsresult rv;
|
|
||||||
rv = nsNodeInfoManager::GetAnonymousManager(*getter_AddRefs(nodeInfoManager));
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
rv = nodeInfoManager->GetNodeInfo(nsHTMLAtoms::option, nsnull,
|
|
||||||
kNameSpaceID_None,
|
|
||||||
*getter_AddRefs(nodeInfo));
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsIHTMLContent* it = new nsHTMLOptionElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = NS_STATIC_CAST(nsGenericElement *, it)->Init(nodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLOptionElement::nsHTMLOptionElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLOptionElement::~nsHTMLOptionElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// ISupports
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLOptionElement, nsGenericElement);
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLOptionElement, nsGenericElement);
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI2(nsHTMLOptionElement, nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLOptionElement, nsIJSNativeInitializer);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLOptionElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLOptionElement* it = new nsHTMLOptionElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = NS_STATIC_CAST(nsGenericElement *, it)->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aForm);
|
|
||||||
*aForm = nsnull;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement;
|
|
||||||
GetSelect(*getter_AddRefs(selectElement));
|
|
||||||
|
|
||||||
nsCOMPtr<nsIFormControl> selectControl(do_QueryInterface(selectElement));
|
|
||||||
|
|
||||||
if (selectControl) {
|
|
||||||
selectControl->GetForm(aForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::GetSelected(PRBool* aValue)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aValue);
|
|
||||||
*aValue = PR_FALSE;
|
|
||||||
|
|
||||||
nsIFormControlFrame* formControlFrame = nsnull;
|
|
||||||
GetPrimaryFrame(formControlFrame);
|
|
||||||
|
|
||||||
if (formControlFrame) {
|
|
||||||
PRInt32 indx;
|
|
||||||
|
|
||||||
GetIndex(&indx);
|
|
||||||
|
|
||||||
if (indx >= 0) {
|
|
||||||
nsAutoString value;
|
|
||||||
|
|
||||||
value.AppendInt(indx, 10); // Save the index in base 10
|
|
||||||
|
|
||||||
formControlFrame->GetProperty(nsHTMLAtoms::selected, value);
|
|
||||||
|
|
||||||
*aValue = value.EqualsWithConversion("1");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Note: The select content obj maintains all the PresState
|
|
||||||
// so defer to it to get the answer
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> parentNode;
|
|
||||||
GetParentNode(getter_AddRefs(parentNode));
|
|
||||||
|
|
||||||
nsCOMPtr<nsISelectElement> selectElement(do_QueryInterface(parentNode));
|
|
||||||
|
|
||||||
if (selectElement) {
|
|
||||||
return selectElement->IsOptionSelected(this, aValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::SetSelected(PRBool aValue)
|
|
||||||
{
|
|
||||||
nsIFormControlFrame* fcFrame = nsnull;
|
|
||||||
|
|
||||||
nsresult result = GetPrimaryFrame(fcFrame, PR_FALSE);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && fcFrame) {
|
|
||||||
nsISelectControlFrame* selectFrame = nsnull;
|
|
||||||
result = fcFrame->QueryInterface(NS_GET_IID(nsISelectControlFrame),
|
|
||||||
(void **) &selectFrame);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && (selectFrame)) {
|
|
||||||
PRInt32 indx;
|
|
||||||
|
|
||||||
GetIndex(&indx);
|
|
||||||
|
|
||||||
if (indx >= 0) {
|
|
||||||
return selectFrame->SetOptionSelected(indx, aValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Note: The select content obj maintains all the PresState
|
|
||||||
// so defer to it to get the answer
|
|
||||||
nsCOMPtr<nsIDOMNode> parentNode;
|
|
||||||
result = NS_OK;
|
|
||||||
|
|
||||||
GetParentNode(getter_AddRefs(parentNode));
|
|
||||||
|
|
||||||
nsCOMPtr<nsISelectElement> selectElement(do_QueryInterface(parentNode));
|
|
||||||
|
|
||||||
if (selectElement) {
|
|
||||||
return selectElement->SetOptionSelected(this, aValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//NS_IMPL_BOOL_ATTR(nsHTMLOptionElement, DefaultSelected, defaultselected)
|
|
||||||
//NS_IMPL_INT_ATTR(nsHTMLOptionElement, Index, index)
|
|
||||||
//NS_IMPL_STRING_ATTR(nsHTMLOptionElement, Label, label)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLOptionElement, Value, value)
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::GetDisabled(PRBool* aDisabled)
|
|
||||||
{
|
|
||||||
nsHTMLValue val;
|
|
||||||
nsresult rv = GetHTMLAttribute(nsHTMLAtoms::disabled, val);
|
|
||||||
*aDisabled = (NS_CONTENT_ATTR_NOT_THERE != rv);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::SetDisabled(PRBool aDisabled)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
nsHTMLValue empty(eHTMLUnit_Empty);
|
|
||||||
|
|
||||||
if (aDisabled) {
|
|
||||||
rv = SetHTMLAttribute(nsHTMLAtoms::disabled, empty, PR_TRUE);
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
nsIFormControlFrame* fcFrame = nsnull;
|
|
||||||
nsresult result = GetPrimaryFrame(fcFrame);
|
|
||||||
if (NS_SUCCEEDED(result) && (nsnull != fcFrame)) {
|
|
||||||
nsISelectControlFrame* selectFrame = nsnull;
|
|
||||||
|
|
||||||
result = fcFrame->QueryInterface(NS_GET_IID(nsISelectControlFrame),
|
|
||||||
(void **)&selectFrame);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && (nsnull != selectFrame)) {
|
|
||||||
selectFrame->OptionDisabled(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
rv = UnsetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::selected, PR_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::GetLabel(nsAWritableString& aValue)
|
|
||||||
{
|
|
||||||
nsGenericHTMLContainerElement::GetAttribute(kNameSpaceID_HTML,
|
|
||||||
nsHTMLAtoms::label, aValue);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::SetLabel(const nsAReadableString& aValue)
|
|
||||||
{
|
|
||||||
nsresult result;
|
|
||||||
|
|
||||||
result = nsGenericHTMLContainerElement::SetAttribute(kNameSpaceID_HTML,
|
|
||||||
nsHTMLAtoms::label,
|
|
||||||
aValue, PR_TRUE);
|
|
||||||
if (NS_SUCCEEDED(result)) {
|
|
||||||
nsIFormControlFrame* fcFrame = nsnull;
|
|
||||||
|
|
||||||
result = GetPrimaryFrame(fcFrame);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && (nsnull != fcFrame)) {
|
|
||||||
nsIComboboxControlFrame* selectFrame = nsnull;
|
|
||||||
|
|
||||||
result = fcFrame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame),
|
|
||||||
(void **) &selectFrame);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && selectFrame) {
|
|
||||||
selectFrame->UpdateSelection(PR_FALSE, PR_TRUE, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::GetDefaultSelected(PRBool* aDefaultSelected)
|
|
||||||
{
|
|
||||||
nsHTMLValue val;
|
|
||||||
|
|
||||||
nsresult rv = GetHTMLAttribute(nsHTMLAtoms::selected, val);
|
|
||||||
*aDefaultSelected = (NS_CONTENT_ATTR_NOT_THERE != rv);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::SetDefaultSelected(PRBool aDefaultSelected)
|
|
||||||
{
|
|
||||||
nsHTMLValue empty(eHTMLUnit_Empty);
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
|
|
||||||
if (aDefaultSelected) {
|
|
||||||
rv = SetHTMLAttribute(nsHTMLAtoms::selected, empty, PR_TRUE);
|
|
||||||
} else {
|
|
||||||
rv = UnsetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::selected, PR_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
// When setting DefaultSelected, we must also reset Selected (DOM Errata)
|
|
||||||
rv = SetSelected(aDefaultSelected);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::GetIndex(PRInt32* aIndex)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aIndex);
|
|
||||||
|
|
||||||
*aIndex = -1; // -1 indicates the index was not found
|
|
||||||
|
|
||||||
// Get our containing select content object.
|
|
||||||
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement;
|
|
||||||
|
|
||||||
GetSelect(*getter_AddRefs(selectElement));
|
|
||||||
|
|
||||||
if (selectElement) {
|
|
||||||
// Get the options from the select object.
|
|
||||||
nsCOMPtr<nsIDOMNSHTMLOptionCollection> options;
|
|
||||||
|
|
||||||
selectElement->GetOptions(getter_AddRefs(options));
|
|
||||||
|
|
||||||
if (options) {
|
|
||||||
// Walk the options to find out where we are in the list (ick, O(n))
|
|
||||||
PRUint32 length = 0;
|
|
||||||
|
|
||||||
options->GetLength(&length);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> thisOption;
|
|
||||||
|
|
||||||
for (PRUint32 i = 0; i < length; i++) {
|
|
||||||
options->Item(i, getter_AddRefs(thisOption));
|
|
||||||
|
|
||||||
if (thisOption.get() == NS_STATIC_CAST(nsIDOMNode *, this)) {
|
|
||||||
*aIndex = i;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::selected) {
|
|
||||||
aResult.SetEmptyValue();
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::disabled) {
|
|
||||||
aResult.SetEmptyValue();
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::label) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
} else if (aAttribute == nsHTMLAtoms::text) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
} else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::GetText(nsAWritableString& aText)
|
|
||||||
{
|
|
||||||
PRInt32 numNodes, i;
|
|
||||||
|
|
||||||
aText.SetLength(0);
|
|
||||||
|
|
||||||
nsresult rv = ChildCount(numNodes);
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < numNodes; i++) {
|
|
||||||
nsCOMPtr<nsIContent> node;
|
|
||||||
|
|
||||||
ChildAt(i, *getter_AddRefs(node));
|
|
||||||
|
|
||||||
if (node) {
|
|
||||||
nsCOMPtr<nsIDOMText> domText(do_QueryInterface(node));
|
|
||||||
|
|
||||||
if (domText) {
|
|
||||||
rv = domText->GetData(aText);
|
|
||||||
|
|
||||||
nsAutoString text(aText);
|
|
||||||
|
|
||||||
// the option could be all spaces, so compress the white space
|
|
||||||
// then make sure it's not empty, if the option is all
|
|
||||||
// whitespace then we return the whitespace
|
|
||||||
|
|
||||||
text.CompressWhitespace(PR_TRUE, PR_TRUE);
|
|
||||||
|
|
||||||
if (!text.IsEmpty()) {
|
|
||||||
aText.Assign(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::SetText(const nsAReadableString& aText)
|
|
||||||
{
|
|
||||||
PRInt32 numNodes, i;
|
|
||||||
PRBool usedExistingTextNode = PR_FALSE; // Do we need to create a text node?
|
|
||||||
|
|
||||||
nsresult result = ChildCount(numNodes);
|
|
||||||
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < numNodes; i++) {
|
|
||||||
nsCOMPtr<nsIContent> node;
|
|
||||||
|
|
||||||
ChildAt(i, *getter_AddRefs(node));
|
|
||||||
|
|
||||||
if (node) {
|
|
||||||
nsCOMPtr<nsIDOMText> domText(do_QueryInterface(node));
|
|
||||||
|
|
||||||
if (domText) {
|
|
||||||
result = domText->SetData(aText);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result)) {
|
|
||||||
usedExistingTextNode = PR_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!usedExistingTextNode) {
|
|
||||||
nsCOMPtr<nsIContent> text;
|
|
||||||
result = NS_NewTextNode(getter_AddRefs(text));
|
|
||||||
if (NS_OK == result) {
|
|
||||||
nsCOMPtr<nsIDOMText> domtext(do_QueryInterface(text));
|
|
||||||
|
|
||||||
if (domtext) {
|
|
||||||
result = domtext->SetData(aText);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result)) {
|
|
||||||
result = AppendChildTo(text, PR_TRUE);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result)) {
|
|
||||||
nsCOMPtr<nsIDocument> doc;
|
|
||||||
|
|
||||||
result = GetDocument(*getter_AddRefs(doc));
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result)) {
|
|
||||||
text->SetDocument(doc, PR_FALSE, PR_TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result)) {
|
|
||||||
nsIFormControlFrame* fcFrame = nsnull;
|
|
||||||
result = GetPrimaryFrame(fcFrame);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && fcFrame) {
|
|
||||||
nsIComboboxControlFrame* selectFrame = nsnull;
|
|
||||||
|
|
||||||
result = fcFrame->QueryInterface(NS_GET_IID(nsIComboboxControlFrame),
|
|
||||||
(void **)&selectFrame);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && selectFrame) {
|
|
||||||
selectFrame->UpdateSelection(PR_FALSE, PR_TRUE, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Options don't have frames - get the select content node
|
|
||||||
// then call nsGenericHTMLElement::GetPrimaryFrame()
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLOptionElement::GetPrimaryFrame(nsIFormControlFrame *&aIFormControlFrame,
|
|
||||||
PRBool aFlushNotifications)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMHTMLSelectElement> selectElement;
|
|
||||||
|
|
||||||
nsresult res = NS_ERROR_FAILURE; // This should be NS_OK;
|
|
||||||
|
|
||||||
GetSelect(*getter_AddRefs(selectElement));
|
|
||||||
|
|
||||||
if (selectElement) {
|
|
||||||
nsCOMPtr<nsIHTMLContent> selectContent(do_QueryInterface(selectElement));
|
|
||||||
|
|
||||||
if (selectContent) {
|
|
||||||
res = nsGenericHTMLElement::GetPrimaryFrame(selectContent,
|
|
||||||
aIFormControlFrame,
|
|
||||||
aFlushNotifications);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the select content element that contains this option
|
|
||||||
void
|
|
||||||
nsHTMLOptionElement::GetSelect(nsIDOMHTMLSelectElement *&aSelectElement)
|
|
||||||
{
|
|
||||||
aSelectElement = nsnull;
|
|
||||||
|
|
||||||
// Get the containing element (Either a select or an optGroup)
|
|
||||||
nsCOMPtr<nsIDOMNode> parentNode;
|
|
||||||
|
|
||||||
GetParentNode(getter_AddRefs(parentNode));
|
|
||||||
|
|
||||||
if (parentNode) {
|
|
||||||
nsresult res;
|
|
||||||
res = parentNode->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement),
|
|
||||||
(void**)&aSelectElement);
|
|
||||||
|
|
||||||
// If we are in an OptGroup we need to GetParentNode again (at least once)
|
|
||||||
if (NS_FAILED(res)) {
|
|
||||||
nsCOMPtr<nsIDOMHTMLOptGroupElement> optgroupElement;
|
|
||||||
|
|
||||||
while (parentNode) { // Be ready for nested OptGroups
|
|
||||||
// Don't need the optgroupElement, just seeing if it IS one.
|
|
||||||
optgroupElement = do_QueryInterface(parentNode);
|
|
||||||
|
|
||||||
if (optgroupElement) {
|
|
||||||
nsIDOMNode* tmpNode = parentNode.get();
|
|
||||||
|
|
||||||
tmpNode->GetParentNode(getter_AddRefs(parentNode));
|
|
||||||
} else {
|
|
||||||
break; // Break out if not a OptGroup (hopefully we have a select)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentNode) {
|
|
||||||
parentNode->QueryInterface(NS_GET_IID(nsIDOMHTMLSelectElement),
|
|
||||||
(void**)&aSelectElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::Initialize(JSContext* aContext,
|
|
||||||
JSObject *aObj,
|
|
||||||
PRUint32 argc,
|
|
||||||
jsval *argv)
|
|
||||||
{
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
if (argc > 0) {
|
|
||||||
// The first (optional) parameter is the text of the option
|
|
||||||
JSString* jsstr = JS_ValueToString(aContext, argv[0]);
|
|
||||||
if (jsstr) {
|
|
||||||
// Create a new text node and append it to the option
|
|
||||||
nsCOMPtr<nsIContent> content;
|
|
||||||
|
|
||||||
result = NS_NewTextNode(getter_AddRefs(content));
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsITextContent> textContent(do_QueryInterface(content));
|
|
||||||
|
|
||||||
if (!textContent) {
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = textContent->SetText(NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars(jsstr)),
|
|
||||||
JS_GetStringLength(jsstr),
|
|
||||||
PR_FALSE);
|
|
||||||
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this addrefs textNode:
|
|
||||||
result = AppendChildTo(content, PR_FALSE);
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 1) {
|
|
||||||
// The second (optional) parameter is the value of the option
|
|
||||||
jsstr = JS_ValueToString(aContext, argv[1]);
|
|
||||||
if (nsnull != jsstr) {
|
|
||||||
// Set the value attribute for this element
|
|
||||||
nsAutoString value(NS_REINTERPRET_CAST(const PRUnichar*,
|
|
||||||
JS_GetStringChars(jsstr)));
|
|
||||||
|
|
||||||
result = nsGenericHTMLContainerElement::SetAttribute(kNameSpaceID_HTML,
|
|
||||||
nsHTMLAtoms::value,
|
|
||||||
value, PR_FALSE);
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 2) {
|
|
||||||
// The third (optional) parameter is the defaultSelected value
|
|
||||||
JSBool defaultSelected;
|
|
||||||
if ((JS_TRUE == JS_ValueToBoolean(aContext,
|
|
||||||
argv[2],
|
|
||||||
&defaultSelected)) &&
|
|
||||||
(JS_TRUE == defaultSelected)) {
|
|
||||||
nsHTMLValue empty(eHTMLUnit_Empty);
|
|
||||||
|
|
||||||
result = SetHTMLAttribute(nsHTMLAtoms::selected, empty, PR_FALSE);
|
|
||||||
|
|
||||||
if (NS_FAILED(result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX Since we don't store the selected state, we can't deal
|
|
||||||
// with the fourth (optional) parameter that is meant to specify
|
|
||||||
// whether the option element should be currently selected or
|
|
||||||
// not. Does anyone depend on this behavior?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLOptionElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,140 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLQuoteElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLQuoteElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLQuoteElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLQuoteElement();
|
|
||||||
virtual ~nsHTMLQuoteElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLQuoteElement
|
|
||||||
NS_DECL_IDOMHTMLQUOTEELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLQuoteElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLQuoteElement* it = new nsHTMLQuoteElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLQuoteElement::nsHTMLQuoteElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLQuoteElement::~nsHTMLQuoteElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLQuoteElement, nsGenericElement)
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLQuoteElement, nsGenericElement)
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLQuoteElement, nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLQuoteElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLQuoteElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLQuoteElement* it = new nsHTMLQuoteElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLQuoteElement, Cite, cite)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLQuoteElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,238 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLTableCaptionElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLTableCaptionElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLTableCaptionElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLTableCaptionElement();
|
|
||||||
virtual ~nsHTMLTableCaptionElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLTableCaptionElement
|
|
||||||
NS_DECL_IDOMHTMLTABLECAPTIONELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const;
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLTableCaptionElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLTableCaptionElement* it = new nsHTMLTableCaptionElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLTableCaptionElement::nsHTMLTableCaptionElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLTableCaptionElement::~nsHTMLTableCaptionElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLTableCaptionElement, nsGenericElement);
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLTableCaptionElement, nsGenericElement);
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLTableCaptionElement,
|
|
||||||
nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLTableCaptionElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLTableCaptionElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLTableCaptionElement* it = new nsHTMLTableCaptionElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableCaptionElement, Align, align)
|
|
||||||
|
|
||||||
|
|
||||||
static nsGenericHTMLElement::EnumTable kCaptionAlignTable[] = {
|
|
||||||
{ "left", NS_SIDE_LEFT },
|
|
||||||
{ "right", NS_SIDE_RIGHT },
|
|
||||||
{ "top", NS_SIDE_TOP},
|
|
||||||
{ "bottom",NS_SIDE_BOTTOM},
|
|
||||||
{ 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableCaptionElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
if (ParseEnumValue(aValue, kCaptionAlignTable, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableCaptionElement::AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
if (eHTMLUnit_Enumerated == aValue.GetUnit()) {
|
|
||||||
EnumValueToString(aValue, kCaptionAlignTable, aResult);
|
|
||||||
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLElement::AttributeToString(aAttribute, aValue, aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
|
||||||
nsIMutableStyleContext* aContext,
|
|
||||||
nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
if (nsnull != aAttributes) {
|
|
||||||
nsHTMLValue value;
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::align, value);
|
|
||||||
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
PRUint8 align = value.GetIntValue();
|
|
||||||
nsStyleTable* tableStyle = (nsStyleTable*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Table);
|
|
||||||
|
|
||||||
tableStyle->mCaptionSide = align;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext,
|
|
||||||
aPresContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableCaptionElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
}
|
|
||||||
else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableCaptionElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const
|
|
||||||
{
|
|
||||||
aFontMapFunc = nsnull;
|
|
||||||
aMapFunc = &MapAttributesInto;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableCaptionElement::SizeOf(nsISizeOfHandler* aSizer,
|
|
||||||
PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,345 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLTableColElement.h"
|
|
||||||
#include "nsIHTMLTableColElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLTableColElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLTableColElement,
|
|
||||||
public nsIHTMLTableColElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLTableColElement();
|
|
||||||
virtual ~nsHTMLTableColElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLTableColElement
|
|
||||||
NS_DECL_IDOMHTMLTABLECOLELEMENT
|
|
||||||
|
|
||||||
// nsIHTMLTableColElement
|
|
||||||
NS_IMETHOD GetSpanValue(PRInt32* aSpan);
|
|
||||||
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const;
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLTableColElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLTableColElement* it = new nsHTMLTableColElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLTableColElement::nsHTMLTableColElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLTableColElement::~nsHTMLTableColElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLTableColElement, nsGenericElement)
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLTableColElement, nsGenericElement)
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI2(nsHTMLTableColElement,
|
|
||||||
nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLTableColElement,
|
|
||||||
nsIHTMLTableColElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLTableColElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLTableColElement* it = new nsHTMLTableColElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColElement, Align, align)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColElement, Ch, _char)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColElement, ChOff, charoff)
|
|
||||||
NS_IMPL_INT_ATTR(nsHTMLTableColElement, Span, span)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColElement, VAlign, valign)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColElement, Width, width)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
/* ignore these attributes, stored simply as strings ch */
|
|
||||||
/* attributes that resolve to integers */
|
|
||||||
if (aAttribute == nsHTMLAtoms::choff) {
|
|
||||||
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::span) {
|
|
||||||
if (ParseValue(aValue, 1, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::width) {
|
|
||||||
/* attributes that resolve to integers or percents or proportions */
|
|
||||||
|
|
||||||
if (ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
/* other attributes */
|
|
||||||
|
|
||||||
if (ParseTableCellHAlignValue(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
|
||||||
if (ParseTableVAlignValue(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColElement::AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
/* ignore these attributes, stored already as strings
|
|
||||||
ch
|
|
||||||
*/
|
|
||||||
/* ignore attributes that are of standard types
|
|
||||||
choff, span
|
|
||||||
*/
|
|
||||||
if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
if (TableCellHAlignValueToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
|
||||||
if (TableVAlignValueToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::width) {
|
|
||||||
if (ValueOrPercentOrProportionalToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerElement::AttributeToString(aAttribute, aValue,
|
|
||||||
aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
|
||||||
nsIMutableStyleContext* aContext,
|
|
||||||
nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION(nsnull!=aContext, "bad style context arg");
|
|
||||||
NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg");
|
|
||||||
|
|
||||||
if (aAttributes) {
|
|
||||||
nsHTMLValue value;
|
|
||||||
nsStyleText* textStyle = nsnull;
|
|
||||||
|
|
||||||
// width
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::width, value);
|
|
||||||
|
|
||||||
if (value.GetUnit() != eHTMLUnit_Null) {
|
|
||||||
nsStylePosition* position = (nsStylePosition*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Position);
|
|
||||||
|
|
||||||
switch (value.GetUnit()) {
|
|
||||||
case eHTMLUnit_Percent:
|
|
||||||
position->mWidth.SetPercentValue(value.GetPercentValue());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eHTMLUnit_Pixel:
|
|
||||||
float p2t;
|
|
||||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
||||||
position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eHTMLUnit_Proportional:
|
|
||||||
position->mWidth.SetIntValue(value.GetIntValue(), eStyleUnit_Proportional);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// align: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::align, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
textStyle->mTextAlign = value.GetIntValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
// valign: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::valign, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
if (nsnull==textStyle)
|
|
||||||
textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
textStyle->mVerticalAlign.SetIntValue(value.GetIntValue(),
|
|
||||||
eStyleUnit_Enumerated);
|
|
||||||
}
|
|
||||||
|
|
||||||
// span: int
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::span, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Integer) {
|
|
||||||
nsStyleTable *tableStyle = (nsStyleTable*)aContext->GetMutableStyleData(eStyleStruct_Table);
|
|
||||||
tableStyle->mSpan = value.GetIntValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext,
|
|
||||||
aPresContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if ((aAttribute == nsHTMLAtoms::width) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::align) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::valign) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::span)) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
}
|
|
||||||
else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const
|
|
||||||
{
|
|
||||||
aFontMapFunc = nsnull;
|
|
||||||
aMapFunc = &MapAttributesInto;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_METHOD nsHTMLTableColElement::GetSpanValue(PRInt32* aSpan)
|
|
||||||
{
|
|
||||||
if (nsnull!=aSpan) {
|
|
||||||
PRInt32 span=-1;
|
|
||||||
GetSpan(&span);
|
|
||||||
|
|
||||||
if (-1==span)
|
|
||||||
span=1; // the default;
|
|
||||||
|
|
||||||
*aSpan = span;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColElement::SizeOf(nsISizeOfHandler* aSizer,
|
|
||||||
PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,320 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLTableColElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLTableColGroupElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLTableColElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLTableColGroupElement();
|
|
||||||
virtual ~nsHTMLTableColGroupElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLTableColElement
|
|
||||||
NS_DECL_IDOMHTMLTABLECOLELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const;
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLTableColGroupElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLTableColGroupElement* it = new nsHTMLTableColGroupElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLTableColGroupElement::nsHTMLTableColGroupElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLTableColGroupElement::~nsHTMLTableColGroupElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLTableColGroupElement, nsGenericElement)
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLTableColGroupElement, nsGenericElement)
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLTableColGroupElement,
|
|
||||||
nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLTableColElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLTableColGroupElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLTableColGroupElement* it = new nsHTMLTableColGroupElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColGroupElement, Align, align)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColGroupElement, Ch, ch)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColGroupElement, ChOff, choff)
|
|
||||||
NS_IMPL_INT_ATTR(nsHTMLTableColGroupElement, Span, span)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColGroupElement, VAlign, valign)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableColGroupElement, Width, width)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColGroupElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
/* ignore these attributes, stored simply as strings
|
|
||||||
ch
|
|
||||||
*/
|
|
||||||
/* attributes that resolve to integers */
|
|
||||||
if (aAttribute == nsHTMLAtoms::choff) {
|
|
||||||
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::span) {
|
|
||||||
if (ParseValue(aValue, 1, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::width) {
|
|
||||||
/* attributes that resolve to integers or percents or proportions */
|
|
||||||
|
|
||||||
if (ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
/* other attributes */
|
|
||||||
|
|
||||||
if (ParseTableCellHAlignValue(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
|
||||||
if (ParseTableVAlignValue(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColGroupElement::AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
/* ignore these attributes, stored already as strings
|
|
||||||
ch
|
|
||||||
*/
|
|
||||||
/* ignore attributes that are of standard types
|
|
||||||
choff, repeat
|
|
||||||
*/
|
|
||||||
if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
if (TableCellHAlignValueToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
|
||||||
if (TableVAlignValueToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::width) {
|
|
||||||
if (ValueOrPercentOrProportionalToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerElement::AttributeToString(aAttribute, aValue,
|
|
||||||
aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
|
||||||
nsIMutableStyleContext* aContext,
|
|
||||||
nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION(nsnull!=aContext, "bad style context arg");
|
|
||||||
NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg");
|
|
||||||
|
|
||||||
if (nsnull != aAttributes) {
|
|
||||||
nsHTMLValue value;
|
|
||||||
nsStyleText* textStyle = nsnull;
|
|
||||||
|
|
||||||
// width
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::width, value);
|
|
||||||
|
|
||||||
if (value.GetUnit() != eHTMLUnit_Null) {
|
|
||||||
nsStylePosition* position = (nsStylePosition*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Position);
|
|
||||||
switch (value.GetUnit()) {
|
|
||||||
case eHTMLUnit_Percent:
|
|
||||||
position->mWidth.SetPercentValue(value.GetPercentValue());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eHTMLUnit_Pixel:
|
|
||||||
float p2t;
|
|
||||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
||||||
position->mWidth.SetCoordValue(NSIntPixelsToTwips(value.GetPixelValue(), p2t));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case eHTMLUnit_Proportional:
|
|
||||||
position->mWidth.SetIntValue(value.GetIntValue(),
|
|
||||||
eStyleUnit_Proportional);
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// align: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::align, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated)
|
|
||||||
{
|
|
||||||
textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
textStyle->mTextAlign = value.GetIntValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
// valign: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::valign, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
if (nsnull==textStyle)
|
|
||||||
textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
textStyle->mVerticalAlign.SetIntValue(value.GetIntValue(),
|
|
||||||
eStyleUnit_Enumerated);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext,
|
|
||||||
aPresContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColGroupElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if ((aAttribute == nsHTMLAtoms::width) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::align) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::valign)) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
}
|
|
||||||
else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColGroupElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const
|
|
||||||
{
|
|
||||||
aFontMapFunc = nsnull;
|
|
||||||
aMapFunc = &MapAttributesInto;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableColGroupElement::SizeOf(nsISizeOfHandler* aSizer,
|
|
||||||
PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,809 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLTableRowElement.h"
|
|
||||||
#include "nsIDOMHTMLTableElement.h"
|
|
||||||
#include "nsIDOMHTMLTableSectionElement.h"
|
|
||||||
#include "nsIDOMHTMLTableCellElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "GenericElementCollection.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsHTMLParts.h"
|
|
||||||
|
|
||||||
// temporary
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
#include "nsIPresShell.h"
|
|
||||||
#include "nsIFrame.h"
|
|
||||||
|
|
||||||
// nsTableCellCollection is needed because GenericElementCollection
|
|
||||||
// only supports element of a single tag. This collection supports
|
|
||||||
// elements <td> or <th> elements.
|
|
||||||
|
|
||||||
class nsTableCellCollection : public GenericElementCollection
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsTableCellCollection(nsIContent* aParent,
|
|
||||||
nsIAtom* aTag);
|
|
||||||
~nsTableCellCollection();
|
|
||||||
|
|
||||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
|
||||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
nsTableCellCollection::nsTableCellCollection(nsIContent* aParent,
|
|
||||||
nsIAtom* aTag)
|
|
||||||
: GenericElementCollection(aParent, aTag)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsTableCellCollection::~nsTableCellCollection()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsTableCellCollection::GetLength(PRUint32* aLength)
|
|
||||||
{
|
|
||||||
if (!aLength) {
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aLength = 0;
|
|
||||||
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
if (mParent) {
|
|
||||||
nsCOMPtr<nsIContent> child;
|
|
||||||
PRUint32 childIndex = 0;
|
|
||||||
|
|
||||||
mParent->ChildAt(childIndex, *getter_AddRefs(child));
|
|
||||||
|
|
||||||
while (child) {
|
|
||||||
nsCOMPtr<nsIAtom> childTag;
|
|
||||||
child->GetTag(*getter_AddRefs(childTag));
|
|
||||||
|
|
||||||
if ((nsHTMLAtoms::td == childTag.get()) ||
|
|
||||||
(nsHTMLAtoms::th == childTag.get())) {
|
|
||||||
(*aLength)++;
|
|
||||||
}
|
|
||||||
|
|
||||||
childIndex++;
|
|
||||||
mParent->ChildAt(childIndex, *getter_AddRefs(child));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsTableCellCollection::Item(PRUint32 aIndex,
|
|
||||||
nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
*aReturn = nsnull;
|
|
||||||
PRUint32 theIndex = 0;
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
|
|
||||||
if (mParent) {
|
|
||||||
nsCOMPtr<nsIContent> child;
|
|
||||||
PRUint32 childIndex = 0;
|
|
||||||
|
|
||||||
mParent->ChildAt(childIndex, *getter_AddRefs(child));
|
|
||||||
|
|
||||||
while (child) {
|
|
||||||
nsCOMPtr<nsIAtom> childTag;
|
|
||||||
|
|
||||||
child->GetTag(*getter_AddRefs(childTag));
|
|
||||||
|
|
||||||
if ((nsHTMLAtoms::td == childTag.get()) ||
|
|
||||||
(nsHTMLAtoms::th == childTag.get())) {
|
|
||||||
if (aIndex == theIndex) {
|
|
||||||
child->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aReturn);
|
|
||||||
|
|
||||||
NS_ASSERTION(aReturn, "content element must be an nsIDOMNode");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
theIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
childIndex++;
|
|
||||||
mParent->ChildAt(childIndex, *getter_AddRefs(child));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
|
|
||||||
class nsHTMLTableRowElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLTableRowElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLTableRowElement();
|
|
||||||
virtual ~nsHTMLTableRowElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLTableRowElement
|
|
||||||
NS_DECL_IDOMHTMLTABLEROWELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const;
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
nsresult GetSection(nsIDOMHTMLTableSectionElement** aSection);
|
|
||||||
nsresult GetTable(nsIDOMHTMLTableElement** aTable);
|
|
||||||
nsTableCellCollection* mCells;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef XXX_debugging
|
|
||||||
static
|
|
||||||
void DebugList(nsIDOMHTMLTableElement* aTable) {
|
|
||||||
nsIHTMLContent* content = nsnull;
|
|
||||||
nsresult result = aTable->QueryInterface(NS_GET_IID(nsIHTMLContent), (void**)&content);
|
|
||||||
if (NS_SUCCEEDED(result) && (nsnull != content)) {
|
|
||||||
nsIDocument* doc = nsnull;
|
|
||||||
result = content->GetDocument(doc);
|
|
||||||
if (NS_SUCCEEDED(result) && (nsnull != doc)) {
|
|
||||||
nsIContent* root = doc->GetRootContent();
|
|
||||||
if (root) {
|
|
||||||
root->List();
|
|
||||||
}
|
|
||||||
nsIPresShell* shell = doc->GetShellAt(0);
|
|
||||||
if (nsnull != shell) {
|
|
||||||
nsIFrame* rootFrame;
|
|
||||||
shell->GetRootFrame(rootFrame);
|
|
||||||
if (nsnull != rootFrame) {
|
|
||||||
rootFrame->List(stdout, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NS_RELEASE(shell);
|
|
||||||
NS_RELEASE(doc);
|
|
||||||
}
|
|
||||||
NS_RELEASE(content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLTableRowElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLTableRowElement* it = new nsHTMLTableRowElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLTableRowElement::nsHTMLTableRowElement()
|
|
||||||
{
|
|
||||||
mCells = nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLTableRowElement::~nsHTMLTableRowElement()
|
|
||||||
{
|
|
||||||
if (nsnull != mCells) {
|
|
||||||
mCells->ParentDestroyed();
|
|
||||||
NS_RELEASE(mCells);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLTableRowElement, nsGenericElement)
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLTableRowElement, nsGenericElement)
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLTableRowElement,
|
|
||||||
nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLTableRowElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLTableRowElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLTableRowElement* it = new nsHTMLTableRowElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// protected method
|
|
||||||
nsresult
|
|
||||||
nsHTMLTableRowElement::GetSection(nsIDOMHTMLTableSectionElement** aSection)
|
|
||||||
{
|
|
||||||
*aSection = nsnull;
|
|
||||||
if (nsnull == aSection) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
nsIDOMNode *sectionNode = nsnull;
|
|
||||||
nsresult result = GetParentNode(§ionNode);
|
|
||||||
if (NS_SUCCEEDED(result) && (nsnull != sectionNode)) {
|
|
||||||
result = sectionNode->QueryInterface(NS_GET_IID(nsIDOMHTMLTableSectionElement), (void**)aSection);
|
|
||||||
NS_RELEASE(sectionNode);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// protected method
|
|
||||||
nsresult
|
|
||||||
nsHTMLTableRowElement::GetTable(nsIDOMHTMLTableElement** aTable)
|
|
||||||
{
|
|
||||||
*aTable = nsnull;
|
|
||||||
|
|
||||||
if (!aTable) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> sectionNode;
|
|
||||||
|
|
||||||
nsresult result = GetParentNode(getter_AddRefs(sectionNode));
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && sectionNode) {
|
|
||||||
nsCOMPtr<nsIDOMNode> tableNode;
|
|
||||||
|
|
||||||
result = sectionNode->GetParentNode(getter_AddRefs(tableNode));
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && tableNode) {
|
|
||||||
result = tableNode->QueryInterface(NS_GET_IID(nsIDOMHTMLTableElement),
|
|
||||||
(void**)aTable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::GetRowIndex(PRInt32* aValue)
|
|
||||||
{
|
|
||||||
*aValue = -1;
|
|
||||||
nsCOMPtr<nsIDOMHTMLTableElement> table;
|
|
||||||
|
|
||||||
nsresult result = GetTable(getter_AddRefs(table));
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && table) {
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
||||||
|
|
||||||
table->GetRows(getter_AddRefs(rows));
|
|
||||||
|
|
||||||
PRUint32 numRows;
|
|
||||||
rows->GetLength(&numRows);
|
|
||||||
|
|
||||||
PRBool found = PR_FALSE;
|
|
||||||
|
|
||||||
for (PRUint32 i = 0; (i < numRows) && !found; i++) {
|
|
||||||
nsCOMPtr<nsIDOMNode> node;
|
|
||||||
|
|
||||||
rows->Item(i, getter_AddRefs(node));
|
|
||||||
|
|
||||||
if (node.get() == NS_STATIC_CAST(nsIDOMNode *, this)) {
|
|
||||||
*aValue = i;
|
|
||||||
found = PR_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this tells the table to delete a row and then insert it in a
|
|
||||||
// different place. This will generate 2 reflows until things get
|
|
||||||
// fixed at a higher level (e.g. DOM batching).
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::SetRowIndex(PRInt32 aValue)
|
|
||||||
{
|
|
||||||
PRInt32 oldIndex;
|
|
||||||
nsresult result = GetRowIndex(&oldIndex);
|
|
||||||
|
|
||||||
if ((-1 == oldIndex) || (oldIndex == aValue) || (NS_OK != result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMHTMLTableElement> table;
|
|
||||||
|
|
||||||
result = GetTable(getter_AddRefs(table));
|
|
||||||
|
|
||||||
if (NS_FAILED(result) || !table) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
||||||
|
|
||||||
table->GetRows(getter_AddRefs(rows));
|
|
||||||
|
|
||||||
PRUint32 numRowsU;
|
|
||||||
rows->GetLength(&numRowsU);
|
|
||||||
PRInt32 numRows = numRowsU; // numRows will be > 0 since this must be a row
|
|
||||||
|
|
||||||
// check if it really moves
|
|
||||||
if (!(((0 == oldIndex) && (aValue <= 0)) ||
|
|
||||||
((numRows-1 == oldIndex) && (aValue >= numRows-1)))) {
|
|
||||||
nsCOMPtr<nsIDOMNode> section;
|
|
||||||
nsCOMPtr<nsIDOMNode> refRow;
|
|
||||||
|
|
||||||
PRInt32 refIndex = aValue;
|
|
||||||
|
|
||||||
if (aValue < numRows) {
|
|
||||||
refIndex = 0;
|
|
||||||
} else {
|
|
||||||
refIndex = numRows-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rows->Item(refIndex, getter_AddRefs(refRow));
|
|
||||||
|
|
||||||
refRow->GetParentNode(getter_AddRefs(section));
|
|
||||||
|
|
||||||
nsCOMPtr<nsISupports> kungFuDeathGrip(NS_STATIC_CAST(nsIContent *, this));
|
|
||||||
|
|
||||||
table->DeleteRow(oldIndex); // delete this from the table
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> returnNode;
|
|
||||||
|
|
||||||
if (aValue >= numRows) {
|
|
||||||
// add this back into the table
|
|
||||||
section->AppendChild(this, getter_AddRefs(returnNode));
|
|
||||||
} else {
|
|
||||||
// add this back into the table
|
|
||||||
section->InsertBefore(this, refRow, getter_AddRefs(returnNode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::GetSectionRowIndex(PRInt32* aValue)
|
|
||||||
{
|
|
||||||
*aValue = -1;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMHTMLTableSectionElement> section;
|
|
||||||
|
|
||||||
nsresult result = GetSection(getter_AddRefs(section));
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(result) && section) {
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
||||||
|
|
||||||
section->GetRows(getter_AddRefs(rows));
|
|
||||||
|
|
||||||
PRBool found = PR_FALSE;
|
|
||||||
PRUint32 numRows;
|
|
||||||
|
|
||||||
rows->GetLength(&numRows);
|
|
||||||
|
|
||||||
for (PRUint32 i = 0; (i < numRows) && !found; i++) {
|
|
||||||
nsCOMPtr<nsIDOMNode> node;
|
|
||||||
rows->Item(i, getter_AddRefs(node));
|
|
||||||
|
|
||||||
if (node.get() == NS_STATIC_CAST(nsIDOMNode *, this)) {
|
|
||||||
*aValue = i;
|
|
||||||
found = PR_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this generates 2 reflows like SetRowIndex
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::SetSectionRowIndex(PRInt32 aValue)
|
|
||||||
{
|
|
||||||
PRInt32 oldIndex;
|
|
||||||
nsresult result = GetRowIndex(&oldIndex);
|
|
||||||
|
|
||||||
if ((-1 == oldIndex) || (oldIndex == aValue) || (NS_OK != result)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMHTMLTableSectionElement> section;
|
|
||||||
|
|
||||||
result = GetSection(getter_AddRefs(section));
|
|
||||||
|
|
||||||
if (NS_FAILED(result) || (nsnull == section)) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
||||||
section->GetRows(getter_AddRefs(rows));
|
|
||||||
|
|
||||||
PRUint32 numRowsU;
|
|
||||||
rows->GetLength(&numRowsU);
|
|
||||||
PRInt32 numRows = numRowsU;
|
|
||||||
|
|
||||||
// check if it really moves
|
|
||||||
if (!(((0 == oldIndex) && (aValue <= 0)) ||
|
|
||||||
((numRows-1 == oldIndex) && (aValue >= numRows-1)))) {
|
|
||||||
nsCOMPtr<nsISupports> kungFuDeathGrip(NS_STATIC_CAST(nsIContent *, this));
|
|
||||||
|
|
||||||
section->DeleteRow(oldIndex); // delete this from the section
|
|
||||||
numRows--;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> returnNode;
|
|
||||||
if ((numRows <= 0) || (aValue >= numRows)) {
|
|
||||||
// add this back into the section
|
|
||||||
section->AppendChild(this, getter_AddRefs(returnNode));
|
|
||||||
} else {
|
|
||||||
PRInt32 newIndex = aValue;
|
|
||||||
|
|
||||||
if (aValue <= 0) {
|
|
||||||
newIndex = 0;
|
|
||||||
} else if (aValue > oldIndex) {
|
|
||||||
// since this got removed before GetLength was called
|
|
||||||
newIndex--;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> refNode;
|
|
||||||
rows->Item(newIndex, getter_AddRefs(refNode));
|
|
||||||
|
|
||||||
// add this back into the section
|
|
||||||
section->InsertBefore(this, refNode, getter_AddRefs(returnNode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::GetCells(nsIDOMHTMLCollection** aValue)
|
|
||||||
{
|
|
||||||
if (!mCells) {
|
|
||||||
mCells = new nsTableCellCollection(this, nsHTMLAtoms::td);
|
|
||||||
|
|
||||||
NS_ENSURE_TRUE(mCells, NS_ERROR_OUT_OF_MEMORY);
|
|
||||||
|
|
||||||
NS_ADDREF(mCells); // this table's reference, released in the destructor
|
|
||||||
}
|
|
||||||
|
|
||||||
mCells->QueryInterface(NS_GET_IID(nsIDOMHTMLCollection), (void **)aValue);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::SetCells(nsIDOMHTMLCollection* aValue)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> cells;
|
|
||||||
GetCells(getter_AddRefs(cells));
|
|
||||||
|
|
||||||
PRUint32 numCells;
|
|
||||||
cells->GetLength(&numCells);
|
|
||||||
|
|
||||||
PRUint32 i;
|
|
||||||
|
|
||||||
for (i = 0; i < numCells; i++) {
|
|
||||||
DeleteCell(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
aValue->GetLength(&numCells);
|
|
||||||
|
|
||||||
for (i = 0; i < numCells; i++) {
|
|
||||||
nsCOMPtr<nsIDOMNode> node;
|
|
||||||
cells->Item(i, getter_AddRefs(node));
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> retChild;
|
|
||||||
AppendChild(node, getter_AddRefs(retChild));
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::InsertCell(PRInt32 aIndex, nsIDOMHTMLElement** aValue)
|
|
||||||
{
|
|
||||||
*aValue = nsnull;
|
|
||||||
|
|
||||||
PRInt32 refIndex = (0 <= aIndex) ? aIndex : 0;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> cells;
|
|
||||||
|
|
||||||
GetCells(getter_AddRefs(cells));
|
|
||||||
|
|
||||||
PRUint32 cellCount;
|
|
||||||
cells->GetLength(&cellCount);
|
|
||||||
|
|
||||||
PRBool doInsert = (aIndex < PRInt32(cellCount));
|
|
||||||
|
|
||||||
// create the cell
|
|
||||||
nsCOMPtr<nsIHTMLContent> cellContent;
|
|
||||||
|
|
||||||
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
||||||
mNodeInfo->NameChanged(nsHTMLAtoms::td, *getter_AddRefs(nodeInfo));
|
|
||||||
|
|
||||||
nsresult rv = NS_NewHTMLTableCellElement(getter_AddRefs(cellContent),
|
|
||||||
nodeInfo);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && cellContent) {
|
|
||||||
nsCOMPtr<nsIDOMNode> cellNode(do_QueryInterface(cellContent));
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && cellNode) {
|
|
||||||
nsCOMPtr<nsIDOMNode> retChild;
|
|
||||||
|
|
||||||
if (doInsert) {
|
|
||||||
PRInt32 refIndex = PR_MAX(aIndex, 0);
|
|
||||||
nsCOMPtr<nsIDOMNode> refCell;
|
|
||||||
|
|
||||||
cells->Item(refIndex, getter_AddRefs(refCell));
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> retChild;
|
|
||||||
|
|
||||||
rv = InsertBefore(cellNode, refCell, getter_AddRefs(retChild));
|
|
||||||
} else {
|
|
||||||
rv = AppendChild(cellNode, getter_AddRefs(retChild));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retChild) {
|
|
||||||
retChild->QueryInterface(NS_GET_IID(nsIDOMHTMLElement),
|
|
||||||
(void **)aValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::DeleteCell(PRInt32 aValue)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> cells;
|
|
||||||
|
|
||||||
GetCells(getter_AddRefs(cells));
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> cell;
|
|
||||||
|
|
||||||
cells->Item(aValue, getter_AddRefs(cell));
|
|
||||||
|
|
||||||
if (cell) {
|
|
||||||
nsCOMPtr<nsIDOMNode> retChild;
|
|
||||||
|
|
||||||
RemoveChild(cell, getter_AddRefs(retChild));
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, Align, align)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, BgColor, bgcolor)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, Ch, ch)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, ChOff, choff)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableRowElement, VAlign, valign)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
/* ignore these attributes, stored simply as strings
|
|
||||||
ch
|
|
||||||
*/
|
|
||||||
/* attributes that resolve to integers with default=0*/
|
|
||||||
if (aAttribute == nsHTMLAtoms::choff) {
|
|
||||||
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::height) {
|
|
||||||
/* attributes that resolve to integers or percents */
|
|
||||||
|
|
||||||
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::width) {
|
|
||||||
/* attributes that resolve to integers or percents or proportions */
|
|
||||||
|
|
||||||
if (ParseValueOrPercentOrProportional(aValue, aResult, eHTMLUnit_Pixel)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
/* other attributes */
|
|
||||||
|
|
||||||
if (ParseTableCellHAlignValue(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::bgcolor) {
|
|
||||||
if (ParseColor(aValue, mDocument, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
|
||||||
if (ParseTableVAlignValue(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
/* ignore these attributes, stored already as strings
|
|
||||||
ch
|
|
||||||
*/
|
|
||||||
/* ignore attributes that are of standard types
|
|
||||||
choff, height, width, background, bgcolor
|
|
||||||
*/
|
|
||||||
if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
if (TableCellHAlignValueToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
|
||||||
if (TableVAlignValueToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerElement::AttributeToString(aAttribute, aValue,
|
|
||||||
aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
|
||||||
nsIMutableStyleContext* aContext,
|
|
||||||
nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION(nsnull!=aContext, "bad style context arg");
|
|
||||||
NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg");
|
|
||||||
|
|
||||||
if (aAttributes) {
|
|
||||||
nsHTMLValue value;
|
|
||||||
nsHTMLValue widthValue;
|
|
||||||
nsStyleText* textStyle = nsnull;
|
|
||||||
|
|
||||||
// align: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::align, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
textStyle->mTextAlign = value.GetIntValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
// valign: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::valign, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
if (nsnull==textStyle)
|
|
||||||
textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
textStyle->mVerticalAlign.SetIntValue(value.GetIntValue(), eStyleUnit_Enumerated);
|
|
||||||
}
|
|
||||||
|
|
||||||
// height: pixel
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::height, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Pixel) {
|
|
||||||
float p2t;
|
|
||||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
||||||
nsStylePosition* pos = (nsStylePosition*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Position);
|
|
||||||
nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t);
|
|
||||||
pos->mHeight.SetCoordValue(twips);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext,
|
|
||||||
aPresContext);
|
|
||||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext,
|
|
||||||
aPresContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if ((aAttribute == nsHTMLAtoms::align) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::valign) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::height)) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
}
|
|
||||||
else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
if (!GetBackgroundAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const
|
|
||||||
{
|
|
||||||
aFontMapFunc = nsnull;
|
|
||||||
aMapFunc = &MapAttributesInto;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableRowElement::SizeOf(nsISizeOfHandler* aSizer,
|
|
||||||
PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,400 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIDOMHTMLTableSectionElement.h"
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsHTMLParts.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "GenericElementCollection.h"
|
|
||||||
|
|
||||||
// you will see the phrases "rowgroup" and "section" used interchangably
|
|
||||||
|
|
||||||
class nsHTMLTableSectionElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLTableSectionElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLTableSectionElement();
|
|
||||||
virtual ~nsHTMLTableSectionElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLTableSectionElement
|
|
||||||
NS_DECL_IDOMHTMLTABLESECTIONELEMENT
|
|
||||||
|
|
||||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult);
|
|
||||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const;
|
|
||||||
NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const;
|
|
||||||
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const;
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
GenericElementCollection *mRows;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLTableSectionElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLTableSectionElement* it = new nsHTMLTableSectionElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLTableSectionElement::nsHTMLTableSectionElement()
|
|
||||||
{
|
|
||||||
mRows = nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLTableSectionElement::~nsHTMLTableSectionElement()
|
|
||||||
{
|
|
||||||
if (nsnull!=mRows) {
|
|
||||||
mRows->ParentDestroyed();
|
|
||||||
NS_RELEASE(mRows);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLTableSectionElement, nsGenericElement)
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLTableSectionElement, nsGenericElement)
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI(nsHTMLTableSectionElement,
|
|
||||||
nsGenericHTMLContainerElement,
|
|
||||||
nsIDOMHTMLTableSectionElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLTableSectionElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLTableSectionElement* it = new nsHTMLTableSectionElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableSectionElement, Align, align)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableSectionElement, VAlign, valign)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableSectionElement, Ch, ch)
|
|
||||||
NS_IMPL_STRING_ATTR(nsHTMLTableSectionElement, ChOff, choff)
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableSectionElement::GetRows(nsIDOMHTMLCollection** aValue)
|
|
||||||
{
|
|
||||||
*aValue = nsnull;
|
|
||||||
|
|
||||||
if (!mRows) {
|
|
||||||
//XXX why was this here NS_ADDREF(nsHTMLAtoms::tr);
|
|
||||||
mRows = new GenericElementCollection(this, nsHTMLAtoms::tr);
|
|
||||||
|
|
||||||
NS_ENSURE_TRUE(mRows, NS_ERROR_OUT_OF_MEMORY);
|
|
||||||
|
|
||||||
NS_ADDREF(mRows); // this table's reference, released in the destructor
|
|
||||||
}
|
|
||||||
|
|
||||||
mRows->QueryInterface(NS_GET_IID(nsIDOMHTMLCollection), (void **)aValue);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableSectionElement::InsertRow(PRInt32 aIndex,
|
|
||||||
nsIDOMHTMLElement** aValue)
|
|
||||||
{
|
|
||||||
*aValue = nsnull;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
||||||
GetRows(getter_AddRefs(rows));
|
|
||||||
|
|
||||||
PRUint32 rowCount;
|
|
||||||
rows->GetLength(&rowCount);
|
|
||||||
|
|
||||||
PRBool doInsert = (aIndex < PRInt32(rowCount));
|
|
||||||
|
|
||||||
// create the row
|
|
||||||
nsCOMPtr<nsIHTMLContent> rowContent;
|
|
||||||
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
||||||
|
|
||||||
mNodeInfo->NameChanged(nsHTMLAtoms::tr, *getter_AddRefs(nodeInfo));
|
|
||||||
|
|
||||||
nsresult rv = NS_NewHTMLTableRowElement(getter_AddRefs(rowContent),
|
|
||||||
nodeInfo);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && rowContent) {
|
|
||||||
nsCOMPtr<nsIDOMNode> rowNode(do_QueryInterface(rowContent));
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && rowNode) {
|
|
||||||
nsCOMPtr<nsIDOMNode> retChild;
|
|
||||||
|
|
||||||
if (doInsert) {
|
|
||||||
PRInt32 refIndex = PR_MAX(aIndex, 0);
|
|
||||||
nsCOMPtr<nsIDOMNode> refRow;
|
|
||||||
rows->Item(refIndex, getter_AddRefs(refRow));
|
|
||||||
rv = InsertBefore(rowNode, refRow, getter_AddRefs(retChild));
|
|
||||||
} else {
|
|
||||||
rv = AppendChild(rowNode, getter_AddRefs(retChild));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retChild) {
|
|
||||||
retChild->QueryInterface(NS_GET_IID(nsIDOMHTMLElement),
|
|
||||||
(void **)aValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableSectionElement::DeleteRow(PRInt32 aValue)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMHTMLCollection> rows;
|
|
||||||
|
|
||||||
GetRows(getter_AddRefs(rows));
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> row;
|
|
||||||
|
|
||||||
rows->Item(aValue, getter_AddRefs(row));
|
|
||||||
|
|
||||||
if (row) {
|
|
||||||
nsCOMPtr<nsIDOMNode> retChild;
|
|
||||||
|
|
||||||
RemoveChild(row, getter_AddRefs(retChild));
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableSectionElement::StringToAttribute(nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
nsHTMLValue& aResult)
|
|
||||||
{
|
|
||||||
/* ignore these attributes, stored simply as strings
|
|
||||||
ch
|
|
||||||
*/
|
|
||||||
/* attributes that resolve to integers */
|
|
||||||
if (aAttribute == nsHTMLAtoms::choff) {
|
|
||||||
if (ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::height) {
|
|
||||||
/* attributes that resolve to integers or percents */
|
|
||||||
|
|
||||||
if (ParseValueOrPercent(aValue, aResult, eHTMLUnit_Pixel)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
/* other attributes */
|
|
||||||
|
|
||||||
if (ParseTableCellHAlignValue(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::bgcolor) {
|
|
||||||
if (ParseColor(aValue, mDocument, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
|
||||||
if (ParseTableVAlignValue(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_CONTENT_ATTR_NOT_THERE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableSectionElement::AttributeToString(nsIAtom* aAttribute,
|
|
||||||
const nsHTMLValue& aValue,
|
|
||||||
nsAWritableString& aResult) const
|
|
||||||
{
|
|
||||||
/* ignore these attributes, stored already as strings
|
|
||||||
ch
|
|
||||||
*/
|
|
||||||
/* ignore attributes that are of standard types
|
|
||||||
choff, height, width, background, bgcolor
|
|
||||||
*/
|
|
||||||
if (aAttribute == nsHTMLAtoms::align) {
|
|
||||||
if (TableCellHAlignValueToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (aAttribute == nsHTMLAtoms::valign) {
|
|
||||||
if (TableVAlignValueToString(aValue, aResult)) {
|
|
||||||
return NS_CONTENT_ATTR_HAS_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsGenericHTMLContainerElement::AttributeToString(aAttribute, aValue,
|
|
||||||
aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
MapAttributesInto(const nsIHTMLMappedAttributes* aAttributes,
|
|
||||||
nsIMutableStyleContext* aContext,
|
|
||||||
nsIPresContext* aPresContext)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION(nsnull!=aContext, "bad style context arg");
|
|
||||||
NS_PRECONDITION(nsnull!=aPresContext, "bad presentation context arg");
|
|
||||||
|
|
||||||
if (aAttributes) {
|
|
||||||
nsHTMLValue value;
|
|
||||||
nsHTMLValue widthValue;
|
|
||||||
nsStyleText* textStyle = nsnull;
|
|
||||||
|
|
||||||
// align: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::align, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
textStyle->mTextAlign = value.GetIntValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
// valign: enum
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::valign, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Enumerated) {
|
|
||||||
if (nsnull==textStyle)
|
|
||||||
textStyle = (nsStyleText*)aContext->GetMutableStyleData(eStyleStruct_Text);
|
|
||||||
textStyle->mVerticalAlign.SetIntValue(value.GetIntValue(),
|
|
||||||
eStyleUnit_Enumerated);
|
|
||||||
}
|
|
||||||
|
|
||||||
// height: pixel
|
|
||||||
aAttributes->GetAttribute(nsHTMLAtoms::height, value);
|
|
||||||
if (value.GetUnit() == eHTMLUnit_Pixel) {
|
|
||||||
float p2t;
|
|
||||||
aPresContext->GetScaledPixelsToTwips(&p2t);
|
|
||||||
nsStylePosition* pos = (nsStylePosition*)
|
|
||||||
aContext->GetMutableStyleData(eStyleStruct_Position);
|
|
||||||
nscoord twips = NSIntPixelsToTwips(value.GetPixelValue(), p2t);
|
|
||||||
pos->mHeight.SetCoordValue(twips);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aContext,
|
|
||||||
aPresContext);
|
|
||||||
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aContext,
|
|
||||||
aPresContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableSectionElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
|
|
||||||
PRInt32& aHint) const
|
|
||||||
{
|
|
||||||
if ((aAttribute == nsHTMLAtoms::align) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::valign) ||
|
|
||||||
(aAttribute == nsHTMLAtoms::height)) {
|
|
||||||
aHint = NS_STYLE_HINT_REFLOW;
|
|
||||||
}
|
|
||||||
else if (!GetCommonMappedAttributesImpact(aAttribute, aHint)) {
|
|
||||||
if (!GetBackgroundAttributesImpact(aAttribute, aHint)) {
|
|
||||||
aHint = NS_STYLE_HINT_CONTENT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableSectionElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc,
|
|
||||||
nsMapAttributesFunc& aMapFunc) const
|
|
||||||
{
|
|
||||||
aFontMapFunc = nsnull;
|
|
||||||
aMapFunc = &MapAttributesInto;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLTableSectionElement::SizeOf(nsISizeOfHandler* aSizer,
|
|
||||||
PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,295 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#include "nsIScriptObjectOwner.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsIHTMLContent.h"
|
|
||||||
#include "nsGenericHTMLElement.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsHTMLIIDs.h"
|
|
||||||
#include "nsIStyleContext.h"
|
|
||||||
#include "nsIMutableStyleContext.h"
|
|
||||||
#include "nsStyleConsts.h"
|
|
||||||
#include "nsIPresContext.h"
|
|
||||||
#include "nsLayoutAtoms.h"
|
|
||||||
#include "nsHTMLAtoms.h"
|
|
||||||
#include "nsIEventListenerManager.h"
|
|
||||||
#include "nsIDOMEventReceiver.h"
|
|
||||||
#include "nsDOMEventsIIDs.h"
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
#include "nsIHTMLStyleSheet.h"
|
|
||||||
#include "nsIHTMLContentContainer.h"
|
|
||||||
#include "nsIHTMLAttributes.h"
|
|
||||||
|
|
||||||
|
|
||||||
class nsHTMLUnknownElement : public nsGenericHTMLContainerElement,
|
|
||||||
public nsIDOMHTMLElement
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
nsHTMLUnknownElement();
|
|
||||||
virtual ~nsHTMLUnknownElement();
|
|
||||||
|
|
||||||
// nsISupports
|
|
||||||
NS_DECL_ISUPPORTS_INHERITED
|
|
||||||
|
|
||||||
// nsIDOMNode
|
|
||||||
NS_FORWARD_IDOMNODE_NO_CLONENODE(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMElement
|
|
||||||
NS_FORWARD_IDOMELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
// nsIDOMHTMLElement
|
|
||||||
NS_FORWARD_IDOMHTMLELEMENT(nsGenericHTMLContainerElement::)
|
|
||||||
|
|
||||||
NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
|
|
||||||
const nsAReadableString& aValue, PRBool aNotify);
|
|
||||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
NS_NewHTMLUnknownElement(nsIHTMLContent** aInstancePtrResult,
|
|
||||||
nsINodeInfo *aNodeInfo)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
|
||||||
|
|
||||||
nsHTMLUnknownElement* it = new nsHTMLUnknownElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult rv = it->Init(aNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
delete it;
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aInstancePtrResult = NS_STATIC_CAST(nsIHTMLContent *, it);
|
|
||||||
NS_ADDREF(*aInstancePtrResult);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsHTMLUnknownElement::nsHTMLUnknownElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLUnknownElement::~nsHTMLUnknownElement()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMPL_ADDREF_INHERITED(nsHTMLUnknownElement, nsGenericElement)
|
|
||||||
NS_IMPL_RELEASE_INHERITED(nsHTMLUnknownElement, nsGenericElement)
|
|
||||||
|
|
||||||
NS_IMPL_HTMLCONTENT_QI0(nsHTMLUnknownElement,
|
|
||||||
nsGenericHTMLContainerElement);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsHTMLUnknownElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(aReturn);
|
|
||||||
*aReturn = nsnull;
|
|
||||||
|
|
||||||
nsHTMLUnknownElement* it = new nsHTMLUnknownElement();
|
|
||||||
|
|
||||||
if (!it) {
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMNode> kungFuDeathGrip(it);
|
|
||||||
|
|
||||||
nsresult rv = it->Init(mNodeInfo);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
CopyInnerTo(this, it, aDeep);
|
|
||||||
|
|
||||||
*aReturn = NS_STATIC_CAST(nsIDOMNode *, it);
|
|
||||||
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument)
|
|
||||||
{
|
|
||||||
nsIHTMLStyleSheet *sheet;
|
|
||||||
|
|
||||||
if (aDocument) {
|
|
||||||
nsCOMPtr<nsIHTMLContentContainer> container(do_QueryInterface(aDocument));
|
|
||||||
|
|
||||||
container->GetAttributeStyleSheet(&sheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_ASSERTION(nsnull != sheet, "can't get attribute style sheet");
|
|
||||||
|
|
||||||
return sheet;
|
|
||||||
}
|
|
||||||
|
|
||||||
static nsresult
|
|
||||||
EnsureWritableAttributes(nsIHTMLContent* aContent,
|
|
||||||
nsIHTMLAttributes*& aAttributes, PRBool aCreate)
|
|
||||||
{
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
|
|
||||||
if (!aAttributes) {
|
|
||||||
if (PR_TRUE == aCreate) {
|
|
||||||
result = NS_NewHTMLAttributes(&aAttributes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ReleaseAttributes(nsIHTMLAttributes*& aAttributes)
|
|
||||||
{
|
|
||||||
// aAttributes->ReleaseContentRef();
|
|
||||||
NS_RELEASE(aAttributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLUnknownElement::SetAttribute(PRInt32 aNameSpaceID,
|
|
||||||
nsIAtom* aAttribute,
|
|
||||||
const nsAReadableString& aValue,
|
|
||||||
PRBool aNotify)
|
|
||||||
{
|
|
||||||
nsresult result = NS_OK;
|
|
||||||
NS_ASSERTION((kNameSpaceID_HTML == aNameSpaceID) ||
|
|
||||||
(kNameSpaceID_None == aNameSpaceID) ||
|
|
||||||
(kNameSpaceID_Unknown == aNameSpaceID),
|
|
||||||
"html content only holds HTML attributes");
|
|
||||||
|
|
||||||
if ((kNameSpaceID_HTML != aNameSpaceID) &&
|
|
||||||
(kNameSpaceID_None != aNameSpaceID) &&
|
|
||||||
(kNameSpaceID_Unknown != aNameSpaceID)) {
|
|
||||||
return NS_ERROR_ILLEGAL_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for event handlers
|
|
||||||
if ((nsLayoutAtoms::onclick == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::ondblclick == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onmousedown == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onmouseup == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onmouseover == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onmouseout == aAttribute)) {
|
|
||||||
AddScriptEventListener(aAttribute, aValue, kIDOMMouseListenerIID);
|
|
||||||
} else if ((nsLayoutAtoms::onkeydown == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onkeyup == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onkeypress == aAttribute)) {
|
|
||||||
AddScriptEventListener(aAttribute, aValue, kIDOMKeyListenerIID);
|
|
||||||
} else if (nsLayoutAtoms::onmousemove == aAttribute) {
|
|
||||||
AddScriptEventListener(aAttribute, aValue, kIDOMMouseMotionListenerIID);
|
|
||||||
} else if (nsLayoutAtoms::onload == aAttribute) {
|
|
||||||
AddScriptEventListener(nsLayoutAtoms::onload, aValue,
|
|
||||||
kIDOMLoadListenerIID);
|
|
||||||
} else if ((nsLayoutAtoms::onunload == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onabort == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onerror == aAttribute)) {
|
|
||||||
AddScriptEventListener(aAttribute, aValue, kIDOMLoadListenerIID);
|
|
||||||
} else if ((nsLayoutAtoms::onfocus == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onblur == aAttribute)) {
|
|
||||||
AddScriptEventListener(aAttribute, aValue, kIDOMFocusListenerIID);
|
|
||||||
} else if ((nsLayoutAtoms::onsubmit == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onreset == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onchange == aAttribute) ||
|
|
||||||
(nsLayoutAtoms::onselect == aAttribute)) {
|
|
||||||
AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID);
|
|
||||||
} else if (nsLayoutAtoms::onpaint == aAttribute) {
|
|
||||||
AddScriptEventListener(aAttribute, aValue, kIDOMPaintListenerIID);
|
|
||||||
} else if (nsLayoutAtoms::oninput == aAttribute) {
|
|
||||||
AddScriptEventListener(aAttribute, aValue, kIDOMFormListenerIID);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsHTMLValue val;
|
|
||||||
|
|
||||||
if (NS_CONTENT_ATTR_NOT_THERE !=
|
|
||||||
StringToAttribute(aAttribute, aValue, val)) {
|
|
||||||
// string value was mapped to nsHTMLValue, set it that way
|
|
||||||
result = SetHTMLAttribute(aAttribute, val, aNotify);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
if (ParseCommonAttribute(aAttribute, aValue, val)) {
|
|
||||||
// string value was mapped to nsHTMLValue, set it that way
|
|
||||||
result = SetHTMLAttribute(aAttribute, val, aNotify);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aValue.IsEmpty()) { // if empty string
|
|
||||||
val.SetEmptyValue();
|
|
||||||
result = SetHTMLAttribute(aAttribute, val, aNotify);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aNotify && (mDocument)) {
|
|
||||||
mDocument->BeginUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// set as string value to avoid another string copy
|
|
||||||
PRBool impact = NS_STYLE_HINT_NONE;
|
|
||||||
GetMappedAttributeImpact(aAttribute, impact);
|
|
||||||
|
|
||||||
if (mDocument) { // set attr via style sheet
|
|
||||||
nsCOMPtr<nsIHTMLStyleSheet> sheet(dont_AddRef(GetAttrStyleSheet(mDocument)));
|
|
||||||
|
|
||||||
if (sheet) {
|
|
||||||
result = sheet->SetAttributeFor(aAttribute, aValue,
|
|
||||||
(NS_STYLE_HINT_CONTENT < impact),
|
|
||||||
this, mAttributes);
|
|
||||||
}
|
|
||||||
} else { // manage this ourselves and re-sync when we connect to doc
|
|
||||||
result = EnsureWritableAttributes(this, mAttributes, PR_TRUE);
|
|
||||||
|
|
||||||
if (mAttributes) {
|
|
||||||
PRInt32 count;
|
|
||||||
result = mAttributes->SetAttributeFor(aAttribute, aValue,
|
|
||||||
(NS_STYLE_HINT_CONTENT < impact),
|
|
||||||
this, nsnull, count);
|
|
||||||
if (0 == count) {
|
|
||||||
ReleaseAttributes(mAttributes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aNotify && (mDocument)) {
|
|
||||||
result = mDocument->AttributeChanged(this, aNameSpaceID, aAttribute,
|
|
||||||
NS_STYLE_HINT_UNKNOWN);
|
|
||||||
mDocument->EndUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLUnknownElement::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
|
||||||
{
|
|
||||||
*aResult = sizeof(*this) + BaseSizeOf(aSizer);
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
#ifndef nsIAttributeContent_h___
|
|
||||||
#define nsIAttributeContent_h___
|
|
||||||
|
|
||||||
#include "nsISupports.h"
|
|
||||||
|
|
||||||
class nsIContent;
|
|
||||||
class nsIAtom;
|
|
||||||
|
|
||||||
// IID for the nsIAttributeContent class
|
|
||||||
#define NS_IATTRIBUTECONTENT_IID \
|
|
||||||
{ 0xbed47b65, 0x54f9, 0x11d3, \
|
|
||||||
{ 0x96, 0xe9, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
|
|
||||||
|
|
||||||
class nsIAttributeContent : public nsISupports {
|
|
||||||
public:
|
|
||||||
//friend nsresult NS_NewAttributeContent(nsIAttributeContent** aNewFrame);
|
|
||||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IATTRIBUTECONTENT_IID)
|
|
||||||
|
|
||||||
NS_IMETHOD Init(nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttrName) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* nsIAttributeContent_h___ */
|
|
@ -1,45 +0,0 @@
|
|||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Netscape Public
|
|
||||||
* License Version 1.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/NPL/
|
|
||||||
*
|
|
||||||
* 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 Mozilla Communicator client code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape Communications
|
|
||||||
* Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _nsIHTMLTableColElement__h_
|
|
||||||
#define _nsIHTMLTableColElement__h_
|
|
||||||
|
|
||||||
|
|
||||||
#include "nsISupports.h"
|
|
||||||
|
|
||||||
// XXX ask Peter if this can go away
|
|
||||||
#define NS_IHTMLTABLECOLELEMENT_IID \
|
|
||||||
{ 0xcc60f140, 0x4bf4, 0x11d2, \
|
|
||||||
{ 0x8F, 0x40, 0x00, 0x60, 0x08, 0x15, 0x9B, 0x0C } }
|
|
||||||
|
|
||||||
class nsIHTMLTableColElement : public nsISupports
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTMLTABLECOLELEMENT_IID)
|
|
||||||
|
|
||||||
/** @return the number of columns this column object represents. Always >= 1 */
|
|
||||||
NS_IMETHOD GetSpanValue (PRInt32* aSpan) = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
x
Reference in New Issue
Block a user