mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-16 15:17:14 +00:00
new
This commit is contained in:
parent
77c0d137b9
commit
b4eebb5585
674
layout/html/content/src/nsGenericDOMDataNode.cpp
Normal file
674
layout/html/content/src/nsGenericDOMDataNode.cpp
Normal file
@ -0,0 +1,674 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "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.
|
||||
*/
|
||||
#include "nsGenericDomDataNode.h"
|
||||
#include "nsIEventListenerManager.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsXIFConverter.h"
|
||||
#include "nsSelectionRange.h"
|
||||
#include "nsISelection.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIEventStateManager.h"
|
||||
#include "nsIPrivateDOMEvent.h"
|
||||
#include "nsISizeOfHandler.h"
|
||||
#include "nsDOMEvent.h"
|
||||
|
||||
// XXX share all id's in this dir
|
||||
|
||||
NS_DEFINE_IID(kIDOMDataIID, NS_IDOMDATA_IID);
|
||||
extern void NS_QuoteForHTML(const nsString& aValue, nsString& aResult);
|
||||
|
||||
static NS_DEFINE_IID(kIPrivateDOMEventIID, NS_IPRIVATEDOMEVENT_IID);
|
||||
|
||||
// XXX temporary code until troy gets done whacking things
|
||||
|
||||
#include "nsIContentDelegate.h"
|
||||
#include "nsFrame.h"
|
||||
#include "nsHTMLParts.h"
|
||||
static nsIContentDelegate* gContentDelegate;
|
||||
static NS_DEFINE_IID(kIContentDelegateIID, NS_ICONTENTDELEGATE_IID);
|
||||
|
||||
/**
|
||||
* THE html content delegate. There is exactly one instance of this
|
||||
* class and it's used for all html content. It just turns around
|
||||
* and asks the content object to create the frame.
|
||||
*/
|
||||
class ZZContentDelegate : public nsIContentDelegate {
|
||||
public:
|
||||
ZZContentDelegate();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_IMETHOD CreateFrame(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsIStyleContext* aStyleContext,
|
||||
nsIFrame*& aResult);
|
||||
protected:
|
||||
~ZZContentDelegate();
|
||||
};
|
||||
|
||||
ZZContentDelegate::ZZContentDelegate()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ZZContentDelegate, kIContentDelegateIID);
|
||||
|
||||
ZZContentDelegate::~ZZContentDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
ZZContentDelegate::CreateFrame(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsIStyleContext* aStyleContext,
|
||||
nsIFrame*& aResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aContent, "null ptr");
|
||||
|
||||
// Make sure the content is html content
|
||||
nsIDOMNode* dn;
|
||||
nsIFrame* frame = nsnull;
|
||||
nsresult rv = aContent->QueryInterface(kIDOMNodeIID, (void**) &dn);
|
||||
if (NS_OK != rv) {
|
||||
// This means that *somehow* somebody which is not an dom
|
||||
// node object got ahold of this delegate and tried to
|
||||
// create a frame with it. Give them back an nsFrame.
|
||||
rv = nsFrame::NewFrame(&frame, aContent, aParentFrame);
|
||||
}
|
||||
else {
|
||||
PRInt32 nodeType;
|
||||
dn->GetNodeType(&nodeType);
|
||||
switch (nodeType) {
|
||||
case nsIDOMNode::TEXT:
|
||||
rv = NS_NewTextFrame(aContent, aParentFrame, frame);
|
||||
break;
|
||||
|
||||
case nsIDOMNode::COMMENT:
|
||||
rv = NS_NewCommentFrame(aContent, aParentFrame, frame);
|
||||
break;
|
||||
}
|
||||
NS_RELEASE(dn);
|
||||
}
|
||||
if (nsnull != frame) {
|
||||
frame->SetStyleContext(aPresContext, aStyleContext);
|
||||
}
|
||||
aResult = frame;
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsGenericDomDataNode::nsGenericDomDataNode()
|
||||
{
|
||||
mDocument = nsnull;
|
||||
mParent = nsnull;
|
||||
mContent = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
mListenerManager = nsnull;
|
||||
mText = nsnull;
|
||||
mTextLength = 0;
|
||||
|
||||
// Create shared content delegate if this is the first html content
|
||||
// object being created.
|
||||
if (nsnull == gContentDelegate) {
|
||||
gContentDelegate = new ZZContentDelegate();
|
||||
}
|
||||
|
||||
// Add a reference to the shared content delegate object
|
||||
NS_ADDREF(gContentDelegate);
|
||||
}
|
||||
|
||||
nsGenericDomDataNode::~nsGenericDomDataNode()
|
||||
{
|
||||
if (nsnull != mText) {
|
||||
delete [] mText;
|
||||
}
|
||||
NS_IF_RELEASE(mListenerManager);
|
||||
// XXX what about mScriptObject? its now safe to GC it...
|
||||
|
||||
NS_PRECONDITION(nsnull != gContentDelegate, "null content delegate");
|
||||
if (nsnull != gContentDelegate) {
|
||||
// Remove our reference to the shared content delegate object. If
|
||||
// the last reference just went away, null out gContentDelegate.
|
||||
nsrefcnt rc = gContentDelegate->Release();
|
||||
if (0 == rc) {
|
||||
gContentDelegate = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsGenericDomDataNode::Init(nsIHTMLContent* aOuterContentObject)
|
||||
{
|
||||
NS_ASSERTION((nsnull == mContent) && (nsnull != aOuterContentObject),
|
||||
"null ptr");
|
||||
mContent = aOuterContentObject;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetNodeValue(nsString& aNodeValue)
|
||||
{
|
||||
aNodeValue.Truncate();
|
||||
aNodeValue.Append(mText, mTextLength);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::SetNodeValue(const nsString& aNodeValue)
|
||||
{
|
||||
PRUnichar* nt = aNodeValue.ToNewUnicode();
|
||||
if (nsnull == nt) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
if (nsnull != mText) {
|
||||
delete [] mText;
|
||||
}
|
||||
mTextLength = aNodeValue.Length();
|
||||
mText = nt;
|
||||
|
||||
// Trigger a reflow
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->ContentChanged(mContent, nsnull);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetParentNode(nsIDOMNode** aParentNode)
|
||||
{
|
||||
if (nsnull != mParent) {
|
||||
nsresult res = mParent->QueryInterface(kIDOMNodeIID, (void**)aParentNode);
|
||||
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
*aParentNode = nsnull;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetPreviousSibling(nsIDOMNode** aNode)
|
||||
{
|
||||
if (nsnull != mParent) {
|
||||
PRInt32 pos;
|
||||
mParent->IndexOf(mContent, pos);
|
||||
if (pos > -1) {
|
||||
nsIContent* prev;
|
||||
mParent->ChildAt(--pos, prev);
|
||||
if (nsnull != prev) {
|
||||
nsresult res = prev->QueryInterface(kIDOMNodeIID, (void**)aNode);
|
||||
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
|
||||
NS_RELEASE(prev); // balance the AddRef in ChildAt()
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
*aNode = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetNextSibling(nsIDOMNode** aNextSibling)
|
||||
{
|
||||
if (nsnull != mParent) {
|
||||
PRInt32 pos;
|
||||
mParent->IndexOf(mContent, pos);
|
||||
if (pos > -1 ) {
|
||||
nsIContent* prev;
|
||||
mParent->ChildAt(++pos, prev);
|
||||
if (nsnull != prev) {
|
||||
nsresult res = prev->QueryInterface(kIDOMNodeIID,(void**)aNextSibling);
|
||||
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
|
||||
NS_RELEASE(prev); // balance the AddRef in ChildAt()
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
*aNextSibling = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult
|
||||
nsGenericDomDataNode::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn)
|
||||
{
|
||||
*aReturn = PR_FALSE;
|
||||
PRInt32 nt1, nt2;
|
||||
GetNodeType(&nt1);
|
||||
aNode->GetNodeType(&nt2);
|
||||
if (nt1 != nt2) {
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Implementation of nsIDOMData
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetData(nsString& aData)
|
||||
{
|
||||
if (nsnull != mText) {
|
||||
aData.SetString(mText, mTextLength);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::SetData(const nsString& aData)
|
||||
{
|
||||
if (mText) {
|
||||
delete[] mText;
|
||||
mText = nsnull;
|
||||
}
|
||||
|
||||
mTextLength = aData.Length();
|
||||
mText = aData.ToNewUnicode();
|
||||
|
||||
// Notify the document that the text changed
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->ContentChanged(mContent, nsnull);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetSize(PRUint32* aSize)
|
||||
{
|
||||
*aSize = mTextLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX temporary
|
||||
#define NS_DOM_INDEX_SIZE_ERR NS_ERROR_FAILURE
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::Substring(PRUint32 aStart,
|
||||
PRUint32 aCount,
|
||||
nsString& aReturn)
|
||||
{
|
||||
aReturn.Truncate();
|
||||
if (nsnull != mText) {
|
||||
// XXX add <0 checks if types change
|
||||
if (aStart >= PRUint32(mTextLength)) {
|
||||
return NS_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
PRUint32 amount = aCount;
|
||||
if (aStart + amount > PRUint32(mTextLength)) {
|
||||
amount = mTextLength - aStart;
|
||||
}
|
||||
aReturn.SetString(mText + aStart, amount);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::Append(const nsString& aData)
|
||||
{
|
||||
return Replace(mTextLength, 0, aData);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::Insert(PRUint32 aOffset, const nsString& aData)
|
||||
{
|
||||
return Replace(aOffset, 0, aData);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::Remove(PRUint32 aOffset, PRUint32 aCount)
|
||||
{
|
||||
nsAutoString empty;
|
||||
return Replace(aOffset, aCount, empty);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::Replace(PRUint32 aOffset, PRUint32 aCount,
|
||||
const nsString& aData)
|
||||
{
|
||||
// sanitize arguments
|
||||
if (aOffset > (PRUint32)mTextLength) {
|
||||
aOffset = mTextLength;
|
||||
}
|
||||
|
||||
// Allocate new buffer
|
||||
PRInt32 endOffset = aOffset + aCount;
|
||||
if (endOffset > mTextLength) {
|
||||
aCount = mTextLength - aOffset;
|
||||
endOffset = mTextLength;
|
||||
}
|
||||
PRInt32 dataLength = aData.Length();
|
||||
PRInt32 newLength = mTextLength - aCount + dataLength;
|
||||
PRUnichar* to = new PRUnichar[newLength ? newLength : 1];
|
||||
if (nsnull == to) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// Copy over appropriate data
|
||||
if (0 != aOffset) {
|
||||
nsCRT::memcpy(to, mText, sizeof(PRUnichar) * aOffset);
|
||||
}
|
||||
if (0 != dataLength) {
|
||||
nsCRT::memcpy(to + aOffset, aData.GetUnicode(),
|
||||
sizeof(PRUnichar) * dataLength);
|
||||
}
|
||||
if (endOffset != mTextLength) {
|
||||
nsCRT::memcpy(to + aOffset + dataLength, mText + endOffset,
|
||||
sizeof(PRUnichar) * (mTextLength - endOffset));
|
||||
}
|
||||
|
||||
// Switch to new buffer
|
||||
if (nsnull != mText) {
|
||||
delete [] mText;
|
||||
}
|
||||
mText = to;
|
||||
mTextLength = newLength;
|
||||
|
||||
// Notify the document that the text changed
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->ContentChanged(mContent, nsnull);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// nsIScriptObjectOwner implementation
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetScriptObject(nsIScriptContext* aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
#if XXX
|
||||
if (nsnull == mScriptObject) {
|
||||
nsIDOMElement* ele = nsnull;
|
||||
mContent->QueryInterface(kIDOMElementIID, (void**) &ele);
|
||||
res = NS_NewScriptElement(aContext, ele, mParent, (void**)&mScriptObject);
|
||||
NS_RELEASE(ele);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::ResetScriptObject()
|
||||
{
|
||||
mScriptObject = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// nsIDOMEventReceiver implementation
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetListenerManager(nsIEventListenerManager** aResult)
|
||||
{
|
||||
if (nsnull != mListenerManager) {
|
||||
NS_ADDREF(mListenerManager);
|
||||
*aResult = mListenerManager;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult rv = NS_NewEventListenerManager(aResult);
|
||||
if (NS_OK == rv) {
|
||||
mListenerManager = *aResult;
|
||||
NS_ADDREF(mListenerManager);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetNewListenerManager(nsIEventListenerManager** aResult)
|
||||
{
|
||||
return NS_NewEventListenerManager(aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::AddEventListener(nsIDOMEventListener* aListener,
|
||||
const nsIID& aIID)
|
||||
{
|
||||
nsIEventListenerManager *manager;
|
||||
|
||||
if (NS_OK == GetListenerManager(&manager)) {
|
||||
manager->AddEventListener(aListener, aIID);
|
||||
NS_RELEASE(manager);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::RemoveEventListener(nsIDOMEventListener* aListener,
|
||||
const nsIID& aIID)
|
||||
{
|
||||
if (nsnull != mListenerManager) {
|
||||
mListenerManager->RemoveEventListener(aListener, aIID);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Implementation of nsIContent
|
||||
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::BeginConvertToXIF(nsXIFConverter& aConverter) const
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::FinishConvertToXIF(nsXIFConverter& aConverter) const
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the content object into the (XIF) XML Interchange Format
|
||||
* XIF is an intermediate form of the content model, the buffer
|
||||
* will then be parsed into any number of formats including HTML, TXT, etc.
|
||||
*/
|
||||
nsresult
|
||||
nsGenericDomDataNode::ConvertContentToXIF(nsXIFConverter& aConverter) const
|
||||
{
|
||||
const nsIContent* content = mContent;
|
||||
|
||||
if (aConverter.GetUseSelection() == PR_TRUE && mDocument->IsInSelection(content))
|
||||
{
|
||||
nsISelection* sel = mDocument->GetSelection();
|
||||
if (sel != nsnull)
|
||||
{
|
||||
nsSelectionRange* range = sel->GetRange();
|
||||
if (range != nsnull)
|
||||
{
|
||||
nsSelectionPoint* startPoint = range->GetStartPoint();
|
||||
nsSelectionPoint* endPoint = range->GetEndPoint();
|
||||
|
||||
nsIContent* startContent = startPoint->GetContent();
|
||||
nsIContent* endContent = endPoint->GetContent();
|
||||
|
||||
PRInt32 startOffset = startPoint->GetOffset();
|
||||
PRInt32 endOffset = endPoint->GetOffset();
|
||||
|
||||
nsString buffer;
|
||||
buffer.Append(mText, mTextLength);
|
||||
if (startContent == content || endContent == content)
|
||||
{
|
||||
// NOTE: ORDER MATTERS!
|
||||
// This must go before the Cut
|
||||
if (endContent == content)
|
||||
buffer.Truncate(endOffset);
|
||||
|
||||
// This must go after the Trunctate
|
||||
if (startContent == content)
|
||||
buffer.Cut(0,startOffset);
|
||||
}
|
||||
aConverter.AddContent(buffer);
|
||||
NS_IF_RELEASE(startContent);
|
||||
NS_IF_RELEASE(endContent);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(sel);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsString buffer;
|
||||
buffer.Append(mText, mTextLength);
|
||||
aConverter.AddContent(buffer);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsGenericDomDataNode::ToCString(nsString& aBuf, PRInt32 aOffset,
|
||||
PRInt32 aLen) const
|
||||
{
|
||||
PRUnichar* cp = mText + aOffset;
|
||||
PRUnichar* end = cp + aLen;
|
||||
while (cp < end) {
|
||||
PRUnichar ch = *cp++;
|
||||
if (ch == '\r') {
|
||||
aBuf.Append("\\r");
|
||||
} else if (ch == '\n') {
|
||||
aBuf.Append("\\n");
|
||||
} else if (ch == '\t') {
|
||||
aBuf.Append("\\t");
|
||||
} else if ((ch < ' ') || (ch >= 127)) {
|
||||
aBuf.Append("\\0");
|
||||
aBuf.Append((PRInt32)ch, 8);
|
||||
} else {
|
||||
aBuf.Append(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetDocument(nsIDocument*& aResult) const
|
||||
{
|
||||
aResult = mDocument;
|
||||
NS_IF_ADDREF(mDocument);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::SetDocument(nsIDocument* aDocument)
|
||||
{
|
||||
mDocument = aDocument;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::GetParent(nsIContent*& aResult) const
|
||||
{
|
||||
NS_IF_ADDREF(mParent);
|
||||
aResult = mParent;
|
||||
return NS_OK;;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::SetParent(nsIContent* aParent)
|
||||
{
|
||||
mParent = aParent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
nsresult ret = NS_OK;
|
||||
|
||||
nsIDOMEvent* domEvent = nsnull;
|
||||
if (DOM_EVENT_INIT == aFlags) {
|
||||
nsIEventStateManager *manager;
|
||||
if (NS_OK == aPresContext.GetEventStateManager(&manager)) {
|
||||
manager->SetEventTarget(mContent);
|
||||
NS_RELEASE(manager);
|
||||
}
|
||||
aDOMEvent = &domEvent;
|
||||
}
|
||||
|
||||
//Capturing stage
|
||||
|
||||
//Local handling stage
|
||||
if (nsnull != mListenerManager) {
|
||||
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aEventStatus);
|
||||
}
|
||||
|
||||
//Bubbling stage
|
||||
if (DOM_EVENT_CAPTURE != aFlags && mParent != nsnull) {
|
||||
ret = mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
||||
DOM_EVENT_BUBBLE, aEventStatus);
|
||||
}
|
||||
|
||||
if (DOM_EVENT_INIT == aFlags) {
|
||||
// We're leaving the DOM event loop so if we created a DOM event,
|
||||
// release here.
|
||||
if (nsnull != *aDOMEvent) {
|
||||
if (0 != (*aDOMEvent)->Release()) {
|
||||
// Okay, so someone in the DOM loop (a listener, JS object)
|
||||
// still has a ref to the DOM Event but the internal data
|
||||
// hasn't been malloc'd. Force a copy of the data here so the
|
||||
// DOM Event is still valid.
|
||||
nsIPrivateDOMEvent *privateEvent;
|
||||
if (NS_OK == (*aDOMEvent)->QueryInterface(kIPrivateDOMEventIID, (void**)&privateEvent)) {
|
||||
privateEvent->DuplicatePrivateData();
|
||||
NS_RELEASE(privateEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
aDOMEvent = nsnull;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Implementation of nsIHTMLContent
|
||||
|
||||
nsresult
|
||||
nsGenericDomDataNode::Compact()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX not really implemented (yet)
|
||||
nsresult
|
||||
nsGenericDomDataNode::SizeOf(nsISizeOfHandler* aHandler) const
|
||||
{
|
||||
aHandler->Add(sizeof(*this));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIContentDelegate*
|
||||
nsGenericDomDataNode::GetDelegate(nsIPresContext* aCX)
|
||||
{
|
||||
gContentDelegate->AddRef();
|
||||
return gContentDelegate;
|
||||
}
|
574
layout/html/content/src/nsGenericDOMDataNode.h
Normal file
574
layout/html/content/src/nsGenericDOMDataNode.h
Normal file
@ -0,0 +1,574 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "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.
|
||||
*/
|
||||
#ifndef nsGenericDomDataNode_h___
|
||||
#define nsGenericDomDataNode_h___
|
||||
|
||||
#include "nsIDOMData.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
extern const nsIID kIDOMDataIID;
|
||||
extern const nsIID kIDOMNodeIID;
|
||||
extern const nsIID kIDOMEventReceiverIID;
|
||||
extern const nsIID kIScriptObjectOwnerIID;
|
||||
extern const nsIID kISupportsIID;
|
||||
extern const nsIID kIContentIID;
|
||||
extern const nsIID kIHTMLContentIID;
|
||||
|
||||
class nsIDOMAttribute;
|
||||
class nsIDOMEventListener;
|
||||
class nsIDOMNodeList;
|
||||
class nsIEventListenerManager;
|
||||
class nsIFrame;
|
||||
class nsIHTMLAttributes;
|
||||
class nsIHTMLContent;
|
||||
class nsIStyleContext;
|
||||
class nsIStyleRule;
|
||||
class nsISupportsArray;
|
||||
|
||||
struct nsGenericDomDataNode {
|
||||
nsGenericDomDataNode();
|
||||
~nsGenericDomDataNode();
|
||||
|
||||
void Init(nsIHTMLContent* aOuterContentObject);
|
||||
|
||||
// Implementation for nsIDOMNode
|
||||
nsresult GetNodeName(nsString& aNodeName) {
|
||||
aNodeName.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetNodeValue(nsString& aNodeValue);
|
||||
nsresult SetNodeValue(const nsString& aNodeValue);
|
||||
nsresult GetParentNode(nsIDOMNode** aParentNode);
|
||||
nsresult GetAttributes(nsIDOMNamedNodeMap** aAttributes) {
|
||||
*aAttributes = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetPreviousSibling(nsIDOMNode** aPreviousSibling);
|
||||
nsresult GetNextSibling(nsIDOMNode** aNextSibling);
|
||||
nsresult GetChildNodes(nsIDOMNodeList** aChildNodes) {
|
||||
*aChildNodes = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetHasChildNodes(PRBool* aHasChildNodes) {
|
||||
*aHasChildNodes = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetFirstChild(nsIDOMNode** aFirstChild) {
|
||||
*aFirstChild = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetLastChild(nsIDOMNode** aLastChild) {
|
||||
*aLastChild = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
|
||||
nsIDOMNode** aReturn) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsresult ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
|
||||
nsIDOMNode** aReturn) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsresult RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsresult AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Implementation for nsIDOMData
|
||||
nsresult GetData(nsString& aData);
|
||||
nsresult SetData(const nsString& aData);
|
||||
nsresult GetSize(PRUint32* aSize);
|
||||
nsresult Substring(PRUint32 aStart, PRUint32 aEnd, nsString& aReturn);
|
||||
nsresult Append(const nsString& aData);
|
||||
nsresult Insert(PRUint32 aOffset, const nsString& aData);
|
||||
nsresult Remove(PRUint32 aOffset, PRUint32 aCount);
|
||||
nsresult Replace(PRUint32 aOffset, PRUint32 aCount, const nsString& aData);
|
||||
|
||||
// nsIDOMEventReceiver interface
|
||||
nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
nsresult RemoveEventListener(nsIDOMEventListener* aListener,
|
||||
const nsIID& aIID);
|
||||
nsresult GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
nsresult GetNewListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
nsresult GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
|
||||
nsresult ResetScriptObject();
|
||||
|
||||
// Implementation for nsIContent
|
||||
nsresult GetDocument(nsIDocument*& aResult) const;
|
||||
nsresult SetDocument(nsIDocument* aDocument);
|
||||
nsresult GetParent(nsIContent*& aResult) const;
|
||||
nsresult SetParent(nsIContent* aParent);
|
||||
nsresult IsSynthetic(PRBool& aResult) {
|
||||
aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetTag(nsIAtom*& aResult) const {
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult SetAttribute(const nsString& aName, const nsString& aValue,
|
||||
PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetAttribute(const nsString& aName, nsString& aResult) const {
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
nsIContentDelegate* GetDelegate(nsIPresContext* aCX);
|
||||
nsresult List(FILE* out, PRInt32 aIndent) const;
|
||||
nsresult HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
// Implementation for nsIHTMLContent
|
||||
nsresult Compact();
|
||||
nsresult SetAttribute(nsIAtom* aAttribute, const nsString& aValue,
|
||||
PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult SetAttribute(nsIAtom* aAttribute, const nsHTMLValue& aValue,
|
||||
PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult UnsetAttribute(nsIAtom* aAttribute) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetAttribute(nsIAtom *aAttribute, nsString &aResult) const {
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
nsresult GetAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const {
|
||||
return NS_CONTENT_ATTR_NOT_THERE;
|
||||
}
|
||||
nsresult GetAllAttributeNames(nsISupportsArray* aArray,
|
||||
PRInt32& aCount) const {
|
||||
aCount = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetAttributeCount(PRInt32& aResult) const {
|
||||
aResult = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult SetID(nsIAtom* aID) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetID(nsIAtom*& aResult) const {
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult SetClass(nsIAtom* aClass) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetClass(nsIAtom*& aResult) const {
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetStyleRule(nsIStyleRule*& aResult) {
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult MapAttributesInto(nsIStyleContext* aStyleContext,
|
||||
nsIPresContext* aPresContext) {
|
||||
return NS_OK;
|
||||
}
|
||||
static void MapNoAttributes(nsIHTMLAttributes* aAttributes,
|
||||
nsIStyleContext* aContext,
|
||||
nsIPresContext* aPresContext) {
|
||||
}
|
||||
nsresult SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
nsresult BeginConvertToXIF(nsXIFConverter& aConverter) const;
|
||||
nsresult ConvertContentToXIF(nsXIFConverter& aConverter) const;
|
||||
nsresult FinishConvertToXIF(nsXIFConverter& aConverter) const;
|
||||
nsresult CanContainChildren(PRBool& aResult) const {
|
||||
aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult ChildCount(PRInt32& aResult) const {
|
||||
aResult = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult ChildAt(PRInt32 aIndex, nsIContent*& aResult) const {
|
||||
aResult = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const {
|
||||
aResult = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult RemoveChildAt(PRInt32 aIndex, PRBool aNotify) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
void ToCString(nsString& 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.
|
||||
nsIHTMLContent* mContent;
|
||||
|
||||
nsIDocument* mDocument;
|
||||
nsIContent* mParent;
|
||||
void* mScriptObject;
|
||||
nsIEventListenerManager* mListenerManager;
|
||||
|
||||
PRUnichar* mText;
|
||||
PRInt32 mTextLength;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Mostly implement the nsIDOMNode API by forwarding the methods to a
|
||||
* generic content object (either nsGenericHTMLLeafElement or
|
||||
* nsGenericHTMLContainerContent)
|
||||
*
|
||||
* Note that classes using this macro will need to implement:
|
||||
* NS_IMETHOD GetNodeType(PRInt32* aNodeType);
|
||||
* NS_IMETHOD CloneNode(nsIDOMNode** aReturn);
|
||||
*/
|
||||
#define NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(_g) \
|
||||
NS_IMETHOD GetNodeName(nsString& aNodeName) { \
|
||||
return _g.GetNodeName(aNodeName); \
|
||||
} \
|
||||
NS_IMETHOD GetNodeValue(nsString& aNodeValue) { \
|
||||
return _g.GetNodeValue(aNodeValue); \
|
||||
} \
|
||||
NS_IMETHOD SetNodeValue(const nsString& aNodeValue) { \
|
||||
return _g.SetNodeValue(aNodeValue); \
|
||||
} \
|
||||
NS_IMETHOD GetNodeType(PRInt32* aNodeType); \
|
||||
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) { \
|
||||
return _g.GetParentNode(aParentNode); \
|
||||
} \
|
||||
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) { \
|
||||
return _g.GetChildNodes(aChildNodes); \
|
||||
} \
|
||||
NS_IMETHOD GetHasChildNodes(PRBool* aHasChildNodes) { \
|
||||
return _g.GetHasChildNodes(aHasChildNodes); \
|
||||
} \
|
||||
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild) { \
|
||||
return _g.GetFirstChild(aFirstChild); \
|
||||
} \
|
||||
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild) { \
|
||||
return _g.GetLastChild(aLastChild); \
|
||||
} \
|
||||
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling) { \
|
||||
return _g.GetPreviousSibling(aPreviousSibling); \
|
||||
} \
|
||||
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling) { \
|
||||
return _g.GetNextSibling(aNextSibling); \
|
||||
} \
|
||||
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes) { \
|
||||
return _g.GetAttributes(aAttributes); \
|
||||
} \
|
||||
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, \
|
||||
nsIDOMNode** aReturn) { \
|
||||
return _g.InsertBefore(aNewChild, aRefChild, aReturn); \
|
||||
} \
|
||||
NS_IMETHOD AppendChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { \
|
||||
return _g.AppendChild(aOldChild, aReturn); \
|
||||
} \
|
||||
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, \
|
||||
nsIDOMNode** aReturn) { \
|
||||
return _g.ReplaceChild(aNewChild, aOldChild, aReturn); \
|
||||
} \
|
||||
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { \
|
||||
return _g.RemoveChild(aOldChild, aReturn); \
|
||||
} \
|
||||
NS_IMETHOD Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn); \
|
||||
NS_IMETHOD CloneNode(nsIDOMNode** aReturn);
|
||||
|
||||
#define NS_IMPL_IDOMDATA_USING_GENERIC_DOM_DATA(_g) \
|
||||
NS_IMETHOD GetData(nsString& aData) { \
|
||||
return _g.GetData(aData); \
|
||||
} \
|
||||
NS_IMETHOD SetData(const nsString& aData) { \
|
||||
return _g.SetData(aData); \
|
||||
} \
|
||||
NS_IMETHOD GetSize(PRUint32* aSize) { \
|
||||
return _g.GetSize(aSize); \
|
||||
} \
|
||||
NS_IMETHOD Substring(PRUint32 aStart, PRUint32 aEnd, nsString& aReturn) { \
|
||||
return _g.Substring(aStart, aEnd, aReturn); \
|
||||
} \
|
||||
NS_IMETHOD Append(const nsString& aData) { \
|
||||
return _g.Append(aData); \
|
||||
} \
|
||||
NS_IMETHOD Insert(PRUint32 aOffset, const nsString& aData) { \
|
||||
return _g.Insert(aOffset, aData); \
|
||||
} \
|
||||
NS_IMETHOD Remove(PRUint32 aOffset, PRUint32 aCount) { \
|
||||
return _g.Remove(aOffset, aCount); \
|
||||
} \
|
||||
NS_IMETHOD Replace(PRUint32 aOffset, PRUint32 aCount, \
|
||||
const nsString& aData) { \
|
||||
return _g.Replace(aOffset, aCount, aData); \
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implement the nsIDOMEventReceiver API by forwarding the methods to a
|
||||
* generic content object (either nsGenericHTMLLeafElement or
|
||||
* nsGenericHTMLContainerContent)
|
||||
*/
|
||||
#define NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(_g) \
|
||||
NS_IMETHOD AddEventListener(nsIDOMEventListener *aListener, \
|
||||
const nsIID& aIID) { \
|
||||
return _g.AddEventListener(aListener, aIID); \
|
||||
} \
|
||||
NS_IMETHOD RemoveEventListener(nsIDOMEventListener *aListener, \
|
||||
const nsIID& aIID) { \
|
||||
return _g.RemoveEventListener(aListener, aIID); \
|
||||
} \
|
||||
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aResult) { \
|
||||
return _g.GetListenerManager(aResult); \
|
||||
} \
|
||||
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager** aResult) { \
|
||||
return _g.GetNewListenerManager(aResult); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the nsIScriptObjectOwner API by forwarding the methods to a
|
||||
* generic content object (either nsGenericHTMLLeafElement or
|
||||
* nsGenericHTMLContainerContent)
|
||||
*/
|
||||
#define NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(_g) \
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, \
|
||||
void** aScriptObject) { \
|
||||
return _g.GetScriptObject(aContext, aScriptObject); \
|
||||
} \
|
||||
NS_IMETHOD ResetScriptObject() { \
|
||||
return _g.ResetScriptObject(); \
|
||||
}
|
||||
|
||||
#define NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(_g) \
|
||||
NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \
|
||||
return _g.GetDocument(aResult); \
|
||||
} \
|
||||
NS_IMETHOD SetDocument(nsIDocument* aDocument) { \
|
||||
return _g.SetDocument(aDocument); \
|
||||
} \
|
||||
NS_IMETHOD GetParent(nsIContent*& aResult) const { \
|
||||
return _g.GetParent(aResult); \
|
||||
} \
|
||||
NS_IMETHOD SetParent(nsIContent* aParent) { \
|
||||
return _g.SetParent(aParent); \
|
||||
} \
|
||||
NS_IMETHOD CanContainChildren(PRBool& aResult) const { \
|
||||
return _g.CanContainChildren(aResult); \
|
||||
} \
|
||||
NS_IMETHOD ChildCount(PRInt32& aResult) const { \
|
||||
return _g.ChildCount(aResult); \
|
||||
} \
|
||||
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { \
|
||||
return _g.ChildAt(aIndex, aResult); \
|
||||
} \
|
||||
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { \
|
||||
return _g.IndexOf(aPossibleChild, aResult); \
|
||||
} \
|
||||
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, \
|
||||
PRBool aNotify) { \
|
||||
return _g.InsertChildAt(aKid, aIndex, aNotify); \
|
||||
} \
|
||||
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, \
|
||||
PRBool aNotify) { \
|
||||
return _g.ReplaceChildAt(aKid, aIndex, aNotify); \
|
||||
} \
|
||||
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { \
|
||||
return _g.AppendChildTo(aKid, aNotify); \
|
||||
} \
|
||||
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { \
|
||||
return _g.RemoveChildAt(aIndex, aNotify); \
|
||||
} \
|
||||
NS_IMETHOD IsSynthetic(PRBool& aResult) { \
|
||||
return _g.IsSynthetic(aResult); \
|
||||
} \
|
||||
NS_IMETHOD GetTag(nsIAtom*& aResult) const { \
|
||||
return _g.GetTag(aResult); \
|
||||
} \
|
||||
NS_IMETHOD SetAttribute(const nsString& aName, const nsString& aValue, \
|
||||
PRBool aNotify) { \
|
||||
return _g.SetAttribute(aName, aValue, aNotify); \
|
||||
} \
|
||||
NS_IMETHOD GetAttribute(const nsString& aName, \
|
||||
nsString& aResult) const { \
|
||||
return _g.GetAttribute(aName, aResult); \
|
||||
} \
|
||||
virtual nsIContentDelegate* GetDelegate(nsIPresContext* aCX) { \
|
||||
return _g.GetDelegate(aCX); \
|
||||
} \
|
||||
NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; \
|
||||
NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const { \
|
||||
return _g.BeginConvertToXIF(aConverter); \
|
||||
} \
|
||||
NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const { \
|
||||
return _g.ConvertContentToXIF(aConverter); \
|
||||
} \
|
||||
NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const { \
|
||||
return _g.FinishConvertToXIF(aConverter); \
|
||||
} \
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const { \
|
||||
return _g.SizeOf(aHandler); \
|
||||
} \
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext, \
|
||||
nsEvent* aEvent, \
|
||||
nsIDOMEvent** aDOMEvent, \
|
||||
PRUint32 aFlags, \
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
#define NS_IMPL_IHTMLCONTENT_USING_GENERIC_DOM_DATA(_g) \
|
||||
NS_IMETHOD Compact() { \
|
||||
return _g.Compact(); \
|
||||
} \
|
||||
NS_IMETHOD SetAttribute(nsIAtom* aAttribute, const nsString& aValue, \
|
||||
PRBool aNotify) { \
|
||||
return _g.SetAttribute(aAttribute, aValue, aNotify); \
|
||||
} \
|
||||
NS_IMETHOD SetAttribute(nsIAtom* aAttribute, \
|
||||
const nsHTMLValue& aValue, PRBool aNotify) { \
|
||||
return _g.SetAttribute(aAttribute, aValue, aNotify); \
|
||||
} \
|
||||
NS_IMETHOD UnsetAttribute(nsIAtom* aAttribute) { \
|
||||
return _g.UnsetAttribute(aAttribute); \
|
||||
} \
|
||||
NS_IMETHOD GetAttribute(nsIAtom *aAttribute, \
|
||||
nsString &aResult) const { \
|
||||
return _g.GetAttribute(aAttribute, aResult); \
|
||||
} \
|
||||
NS_IMETHOD GetAttribute(nsIAtom* aAttribute, \
|
||||
nsHTMLValue& aValue) const { \
|
||||
return _g.GetAttribute(aAttribute, aValue); \
|
||||
} \
|
||||
NS_IMETHOD GetAllAttributeNames(nsISupportsArray* aArray, \
|
||||
PRInt32& aResult) const { \
|
||||
return _g.GetAllAttributeNames(aArray, aResult); \
|
||||
} \
|
||||
NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { \
|
||||
return _g.GetAttributeCount(aResult); \
|
||||
} \
|
||||
NS_IMETHOD SetID(nsIAtom* aID) { \
|
||||
return _g.SetID(aID); \
|
||||
} \
|
||||
NS_IMETHOD GetID(nsIAtom*& aResult) const { \
|
||||
return _g.GetID(aResult); \
|
||||
} \
|
||||
NS_IMETHOD SetClass(nsIAtom* aClass) { \
|
||||
return _g.SetClass(aClass); \
|
||||
} \
|
||||
NS_IMETHOD GetClass(nsIAtom*& aResult) const { \
|
||||
return _g.GetClass(aResult); \
|
||||
} \
|
||||
NS_IMETHOD GetStyleRule(nsIStyleRule*& aResult) { \
|
||||
return _g.GetStyleRule(aResult); \
|
||||
} \
|
||||
NS_IMETHOD ToHTMLString(nsString& aResult) const; \
|
||||
NS_IMETHOD ToHTML(FILE* out) const; \
|
||||
NS_IMETHOD CreateFrame(nsIPresContext* aPresContext, \
|
||||
nsIFrame* aParentFrame, \
|
||||
nsIStyleContext* aStyleContext, \
|
||||
nsIFrame*& aResult) { \
|
||||
NS_NOTREACHED("whoops"); \
|
||||
return NS_ERROR_FAILURE; \
|
||||
} \
|
||||
NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, \
|
||||
const nsString& aValue, \
|
||||
nsHTMLValue& aResult) { \
|
||||
return NS_CONTENT_ATTR_NOT_THERE; \
|
||||
} \
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute, \
|
||||
nsHTMLValue& aValue, \
|
||||
nsString& aResult) const { \
|
||||
return NS_CONTENT_ATTR_NOT_THERE; \
|
||||
} \
|
||||
NS_IMETHOD \
|
||||
GetAttributeMappingFunction(nsMapAttributesFunc& aMapFunc) const { \
|
||||
aMapFunc = nsGenericDomDataNode::MapNoAttributes; \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
/**
|
||||
* This macro implements the portion of query interface that is
|
||||
* generic to all html content objects.
|
||||
*/
|
||||
#define NS_IMPL_DOM_DATA_QUERY_INTERFACE(_id, _iptr, _this) \
|
||||
if (_id.Equals(kISupportsIID)) { \
|
||||
nsIHTMLContent* tmp = _this; \
|
||||
nsISupports* tmp2 = tmp; \
|
||||
*_iptr = (void*) tmp2; \
|
||||
AddRef(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (_id.Equals(kIDOMNodeIID)) { \
|
||||
nsIDOMNode* tmp = _this; \
|
||||
*_iptr = (void*) tmp; \
|
||||
AddRef(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (_id.Equals(kIDOMDataIID)) { \
|
||||
nsIDOMData* tmp = _this; \
|
||||
*_iptr = (void*) tmp; \
|
||||
AddRef(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (_id.Equals(kIDOMEventReceiverIID)) { \
|
||||
nsIDOMEventReceiver* tmp = _this; \
|
||||
*_iptr = (void*) tmp; \
|
||||
AddRef(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (_id.Equals(kIScriptObjectOwnerIID)) { \
|
||||
nsIScriptObjectOwner* tmp = _this; \
|
||||
*_iptr = (void*) tmp; \
|
||||
AddRef(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (_id.Equals(kIContentIID)) { \
|
||||
nsIContent* tmp = _this; \
|
||||
*_iptr = (void*) tmp; \
|
||||
AddRef(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (_id.Equals(kIHTMLContentIID)) { \
|
||||
nsIHTMLContent* tmp = _this; \
|
||||
*_iptr = (void*) tmp; \
|
||||
AddRef(); \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
#endif /* nsGenericDomDataNode_h___ */
|
256
layout/html/content/src/nsTextNode.cpp
Normal file
256
layout/html/content/src/nsTextNode.cpp
Normal file
@ -0,0 +1,256 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "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.
|
||||
*/
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsGenericDomDataNode.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsITextContent.h"
|
||||
#include "nsFrame.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
||||
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);
|
||||
|
||||
/* XXX should not be html content; should be nsITextContent */
|
||||
|
||||
class nsTextNode : public nsIDOMText,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsIDOMEventReceiver,
|
||||
public nsIHTMLContent,
|
||||
public nsITextContent
|
||||
{
|
||||
public:
|
||||
nsTextNode();
|
||||
~nsTextNode();
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMNode
|
||||
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
|
||||
|
||||
// nsIDOMData
|
||||
NS_IMPL_IDOMDATA_USING_GENERIC_DOM_DATA(mInner)
|
||||
|
||||
// nsIDOMText
|
||||
NS_IMETHOD SplitText(PRUint32 aOffset, nsIDOMText** aReturn);
|
||||
NS_IMETHOD JoinText(nsIDOMText* aNode1, nsIDOMText* aNode2,
|
||||
nsIDOMText** aReturn);
|
||||
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(mInner)
|
||||
|
||||
// nsIDOMEventReceiver
|
||||
NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(mInner)
|
||||
|
||||
// nsIContent
|
||||
NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner)
|
||||
|
||||
// nsIHTMLContent
|
||||
NS_IMPL_IHTMLCONTENT_USING_GENERIC_DOM_DATA(mInner)
|
||||
|
||||
// nsITextContent
|
||||
NS_IMETHOD GetText(const PRUnichar*& aBaseResult, PRInt32& aLengthResult);
|
||||
NS_IMETHOD SetText(const PRUnichar* aBuffer, PRInt32 aLength,
|
||||
PRBool aNotify);
|
||||
|
||||
protected:
|
||||
nsGenericDomDataNode mInner;
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewTextNode(nsIHTMLContent** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
nsTextNode* it = new nsTextNode();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIHTMLContentIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsTextNode::nsTextNode()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mInner.Init(this);
|
||||
}
|
||||
|
||||
nsTextNode::~nsTextNode()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsTextNode)
|
||||
|
||||
NS_IMPL_RELEASE(nsTextNode)
|
||||
|
||||
nsresult
|
||||
nsTextNode::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
NS_IMPL_DOM_DATA_QUERY_INTERFACE(aIID, aInstancePtr, this)
|
||||
if (aIID.Equals(kIDOMTextIID)) {
|
||||
nsIDOMText* tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kITextContentIID)) {
|
||||
nsITextContent* tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::GetNodeType(PRInt32* aNodeType)
|
||||
{
|
||||
*aNodeType = (PRInt32)nsIDOMNode::TEXT;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextNode::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn)
|
||||
{
|
||||
// XXX not yet implemented
|
||||
*aReturn = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextNode::CloneNode(nsIDOMNode** aReturn)
|
||||
{
|
||||
nsTextNode* it = new nsTextNode();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
//XXX mInner.CopyInnerTo(this, &it->mInner);
|
||||
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
|
||||
|
||||
PRInt32 index;
|
||||
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||
|
||||
fprintf(out, "Text refcount=%d<", mRefCnt);
|
||||
|
||||
nsAutoString tmp;
|
||||
mInner.ToCString(tmp, 0, mInner.mTextLength);
|
||||
fputs(tmp, out);
|
||||
|
||||
fputs(">\n", out);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextNode::ToHTML(FILE* out) const
|
||||
{
|
||||
nsAutoString tmp;
|
||||
tmp.Append(mInner.mText, mInner.mTextLength);
|
||||
fputs(tmp, out);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTextNode::ToHTMLString(nsString& aBuf) const
|
||||
{
|
||||
aBuf.Truncate(0);
|
||||
aBuf.Append(mInner.mText, mInner.mTextLength);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
|
||||
aFlags, aEventStatus);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Implementation of the nsIDOMText interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::SplitText(PRUint32 aOffset, nsIDOMText** aReturn)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::JoinText(nsIDOMText* aNode1, nsIDOMText* aNode2,
|
||||
nsIDOMText** aReturn)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Implementation of the nsITextContent interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::GetText(const PRUnichar*& aBaseResult, PRInt32& aLengthResult)
|
||||
{
|
||||
aBaseResult = mInner.mText;
|
||||
aLengthResult = mInner.mTextLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XXX probably should normalize the code to keep a \u0000 at the end
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::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;
|
||||
}
|
||||
|
||||
PRUnichar* nt = new PRUnichar[aLength+1];
|
||||
if (nsnull == nt) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
if (nsnull != mInner.mText) {
|
||||
delete [] mInner.mText;
|
||||
}
|
||||
nsCRT::memcpy(nt, aBuffer, sizeof(PRUnichar) * aLength);
|
||||
nt[aLength] = 0;
|
||||
mInner.mTextLength = aLength;
|
||||
mInner.mText = nt;
|
||||
|
||||
// Trigger a reflow
|
||||
if (aNotify && (nsnull != mInner.mDocument)) {
|
||||
mInner.mDocument->ContentChanged(this, nsnull);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user