diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index f063a5708fd..f76c8c7097f 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -259,18 +259,6 @@ nsHTMLDocument::nsHTMLDocument() mDTDMode = eDTDMode_quirks; mCSSLoader = nsnull; - // Find/Search Init - mSearchStr = nsnull; - mLastBlockSearchOffset = 0; - mAdjustToEnd = PR_FALSE; - mShouldMatchCase = PR_FALSE; - - mHoldBlockContent = nsnull; - - // These will be converted to a nsDeque - mStackInx = 0; - mParentStack = (nsIDOMNode**) new PRUint32[32]; - mChildStack = (nsIDOMNode**) new PRUint32[32]; mBodyContent = nsnull; mForms = nsnull; mIsWriting = 0; @@ -332,11 +320,6 @@ nsHTMLDocument::~nsHTMLDocument() NS_RELEASE(mCSSLoader); } - // These will be converted to a nsDeque - delete[] mParentStack; - delete[] mChildStack; - - delete mSearchStr; NS_IF_RELEASE(mBodyContent); if (--gRefCntRDFService == 0) @@ -2827,6 +2810,7 @@ nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds) return NS_OK; } +#ifdef NS_IMPLEMENT_DOCUMENT_LAYERS PRBool nsHTMLDocument::MatchLayers(nsIContent *aContent, nsString* aData) { @@ -2844,7 +2828,6 @@ nsHTMLDocument::MatchLayers(nsIContent *aContent, nsString* aData) return result; } -#ifdef NS_IMPLEMENT_DOCUMENT_LAYERS NS_IMETHODIMP nsHTMLDocument::GetLayers(nsIDOMHTMLCollection** aLayers) { @@ -3213,886 +3196,6 @@ nsHTMLDocument::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, } //---------------------------- -class SubText { -public: - nsIDOMNode * mContentNode; - PRInt32 mOffset; - PRInt32 mLength; -}; - -//---------------------------- -class BlockText { - nsString mText; - SubText * mSubTexts[512]; - PRInt32 mNumSubTexts; -public: - BlockText() : mNumSubTexts(0) { PRInt32 i; for (i=0;i<512;i++) mSubTexts[i] = 0; } // debug only - virtual ~BlockText(); - - char * GetText() { return mText.ToNewCString(); } - const nsString & GetNSString() { return mText; } - - void ClearBlock(); - PRInt32 GetNumItems() { return mNumSubTexts; } - - void AddSubText(nsIDOMNode * aNode, nsString & aStr, PRInt32 aDirection, PRInt32 & aOffset); - PRInt32 GetStartEnd(PRInt32 anIndex, PRInt32 aLength, - nsIDOMNode ** aStartNode, PRInt32 & aStartOffset, - nsIDOMNode ** aEndNode, PRInt32 & aEndOffset, - PRInt32 aDirection); -}; - -//---------------------------- -BlockText::~BlockText() -{ - ClearBlock(); -} - -//---------------------------- -void BlockText::ClearBlock() -{ - PRInt32 i; - for (i=0;imContentNode = aNode; - subTxt->mLength = aStr.Length(); - if (aDirection == kForward) { - subTxt->mOffset = mText.Length(); - mText.Append(aStr); - mSubTexts[mNumSubTexts++] = subTxt; - } - else { - subTxt->mOffset = 0; - // Shift them all down one slot - PRInt32 i; - for (i=mNumSubTexts;i>0;i--) { - mSubTexts[i] = mSubTexts[i-1]; - mSubTexts[i]->mOffset += aStr.Length(); - } - mNumSubTexts++; - mText.Insert(aStr, 0); - mSubTexts[0] = subTxt; - } - } -} - -//----------------------------------------------- -PRInt32 BlockText::GetStartEnd(PRInt32 anIndex, PRInt32 aLength, - nsIDOMNode ** aStartNode, PRInt32 & aStartOffset, - nsIDOMNode ** aEndNode, PRInt32 & aEndOffset, - PRInt32 aDirection) -{ - - PRInt32 i = 0; - PRInt32 endPos = anIndex + aLength; - while (anIndex > mSubTexts[i]->mOffset+mSubTexts[i]->mLength) { - i++; - } - aStartOffset = anIndex - mSubTexts[i]->mOffset; - *aStartNode = mSubTexts[i]->mContentNode; - if (endPos <= mSubTexts[i]->mOffset+mSubTexts[i]->mLength) { - aEndOffset = aStartOffset + aLength; - *aEndNode = *aStartNode; - } else { - - while (endPos > mSubTexts[i]->mOffset+mSubTexts[i]->mLength) { - i++; - } - aEndOffset = endPos - mSubTexts[i]->mOffset; - *aEndNode = mSubTexts[i]->mContentNode; - } - - if (aDirection == kBackward) { - endPos -= aLength; - } - return endPos; - -} - -//----------------------------------------------- -PRBool nsHTMLDocument::SearchBlock(BlockText & aBlockText, - nsString & aStr, - nsIDOMNode * aCurrentBlock) -{ - PRBool found = PR_FALSE; - - PRInt32 lastBlockSearchOffset; - PRBool adjustToEnd; - - if (aCurrentBlock == mHoldBlockContent || mHoldBlockContent == nsnull) { - lastBlockSearchOffset = mLastBlockSearchOffset; - adjustToEnd = mAdjustToEnd; - } else { - lastBlockSearchOffset = 0; - adjustToEnd = PR_TRUE; - } - - char * searchStr; - char * contentStr; - - if (!mShouldMatchCase) { - nsString searchTxt(aStr); - nsString blockTxt(aBlockText.GetNSString()); - - searchTxt.ToLowerCase(); - blockTxt.ToLowerCase(); - searchStr = searchTxt.ToNewCString(); - contentStr = blockTxt.ToNewCString(); - } else { - searchStr = aStr.ToNewCString(); - contentStr = aBlockText.GetText(); - } - - char * adjustedContent; - char * str = nsnull; - - if (mSearchDirection == kForward) { - adjustedContent = contentStr + lastBlockSearchOffset; - str = strstr(adjustedContent, searchStr); - } else { - adjustedContent = contentStr; - size_t adjLen; - size_t srchLen = strlen(searchStr); - if (adjustToEnd) { - adjLen = strlen(adjustedContent); - if (srchLen > adjLen) { - str = nsnull; - } else if (adjLen == srchLen && !strncmp(adjustedContent, searchStr, srchLen)) { - str = adjustedContent; - } else { - str = adjustedContent + adjLen - srchLen; - while (strncmp(str, searchStr, srchLen)) { - str--; - if (str < adjustedContent) { - str = nsnull; - break; - } - } - } - } else { - adjLen = lastBlockSearchOffset; - if (lastBlockSearchOffset > 0) { - str = adjustedContent + adjLen - 1; - while (strncmp(str, searchStr, srchLen)) { - str--; - if (str < adjustedContent) { - str = nsnull; - break; - } - } - } - } - } - -#if 0 - if (str) { - PRInt32 inx = str - contentStr; - - nsIDOMNode * startNode; - PRInt32 startOffset; - nsIDOMNode * endNode; - PRInt32 endOffset; - - mLastBlockSearchOffset = aBlockText.GetStartEnd(inx, aStr.Length(), &startNode, startOffset, &endNode, endOffset, mSearchDirection); - mHoldBlockContent = aCurrentBlock; - nsSelectionRange * range = mSelection->GetRange(); - nsSelectionPoint * startPnt = range->GetStartPoint(); - nsSelectionPoint * endPnt = range->GetEndPoint(); - - nsIContent* content; - nsresult rv = startNode->QueryInterface(NS_GET_IID(nsIContent),(void **)&content); - if (NS_OK == rv) { - startPnt->SetPoint(content, startOffset, PR_TRUE); - NS_RELEASE(content); - } - rv = endNode->QueryInterface(NS_GET_IID(nsIContent),(void **)&content); - if (NS_OK == rv) { - endPnt->SetPoint(content, endOffset, PR_FALSE); - NS_RELEASE(content); - } - - found = PR_TRUE; - } -#endif //0 - delete[] searchStr; - delete[] contentStr; - - return found; -} - -//////////////////////////////////////////////////////////////// -// Methods to see if a Content node is a block or an inline tag. -//////////////////////////////////////////////////////////////// -PRInt32 nsHTMLDocument::GetTagID(nsString& aName) const -{ - if (!mParserService) - { - nsIParserService* parserService; - if (NS_FAILED(nsServiceManager::GetService(kParserServiceCID, - NS_GET_IID(nsIParserService), - (nsISupports**)&parserService)) - || !parserService) - return PR_FALSE; - - // Wish mParserService could be mutable: - NS_CONST_CAST(nsHTMLDocument* , this)->mParserService = dont_AddRef(parserService); - } - - PRInt32 id; - mParserService->HTMLStringTagToId(aName, &id); - return id; -} - -PRBool nsHTMLDocument::NodeIsBlock(nsIDOMNode* aNode) const -{ - if (!aNode) - return NS_ERROR_INVALID_ARG; - - // Get the id of the tag itself: - nsAutoString tagName; - aNode->GetNodeName(tagName); - PRInt32 ID = GetTagID(tagName); - - // Get the parent - nsCOMPtr parentNode; - nsresult rv = aNode->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(rv)) return rv; - - // and the parent's id - parentNode->GetNodeName(tagName); - PRInt32 parentID = GetTagID(tagName); - - // Now we can get the inline status from the DTD: - nsCOMPtr dtd; - rv = GetDTD(getter_AddRefs(dtd)); - if (NS_FAILED(rv) || !dtd) - return PR_FALSE; - return dtd->IsBlockElement(ID, parentID); -} - -///////////////////////////////////////////// -// This function moves up the parent hierarchy -// looking for a parent that is a "block" -///////////////////////////////////////////// -nsIDOMNode * nsHTMLDocument::FindBlockParent(nsIDOMNode * aNode, - PRBool aSkipThisContent) -{ - // Clear up stack and release content nodes on it - PRInt32 i; - for (i=0;iGetParentNode(&parent); - nsIDOMNode * child; - - if (parent == nsnull) { - return nsnull; - } - NS_ADDREF(aNode); - - // This method enables the param "aNode" be part of the "path" - // on the stack as the it look for the block parent. - // - // There are times when we don't want to include the aNode - // as part of the path so we skip to its prev/next sibling. If it was - // the first/last sibling then we jump up to it's parent. - if (aSkipThisContent) { - child = aNode; - nsIDOMNode * nextChild; - - PRBool done = PR_FALSE; - while (!done) { - - if (mSearchDirection == kForward) { - child->GetNextSibling(&nextChild); - } else { - child->GetPreviousSibling(&nextChild); - } - - if (nextChild == nsnull) { - NS_RELEASE(child); - child = parent; - child->GetParentNode(&parent); - if (parent == nsnull) { - NS_RELEASE(child); - return nsnull; - } - } else { - NS_RELEASE(child); - child = nextChild; - done = PR_TRUE; - } - } // while - - } else { - child = aNode; - } - - // This travels up through the parents looking for the parent who - // is a block tag. We place the child/parent pairs onto a stack - // so we know what nodes to skip as we work our way back down into - // the block - do { - - NS_ADDREF(parent); - NS_ADDREF(child); - mParentStack[mStackInx] = parent; - mChildStack[mStackInx++] = child; - - if (parent == mBodyContent) { - break; - } - - nsIDOMNode * oldChild = child; - child = parent; - child->GetParentNode(&parent); - NS_RELEASE(oldChild); - } while (parent != nsnull); - - - NS_RELEASE(child); - return parent; -} - -//----------------------------------------------- -PRBool nsHTMLDocument::BuildBlockFromContent(nsIDOMNode * aNode, - BlockText & aBlockText, - nsIDOMNode * aCurrentBlock) -{ - // First check to see if it is a new Block node - // If it is then we need to check the current block text (aBlockText) - // to see if it holds the search string - if (NodeIsBlock(aNode)) { - - // Search current block of text - if (SearchBlock(aBlockText, *mSearchStr, aCurrentBlock)) { - return PR_TRUE; - } - - // Clear the text we have already searched - aBlockText.ClearBlock(); - - // Start new search here on down with a new block - BlockText blockText; - if (!BuildBlockTraversing(aNode, blockText, aNode)) { - // down inside the search string wasn't found check the full block text - // for the search text - if (SearchBlock(blockText, *mSearchStr, aNode)) { - return PR_TRUE; - } - } else { - // search text was found down inside, so leave - return PR_TRUE; - } - - } else { - if (BuildBlockTraversing(aNode, aBlockText, aCurrentBlock)) { - return PR_TRUE; - } - } - - return PR_FALSE; -} - -//---------------------------------- -// This function moves down through -// the hiearchy and build the block of text -//----------------------------------------- -PRBool nsHTMLDocument::BuildBlockTraversing(nsIDOMNode * aParent, - BlockText & aBlockText, - nsIDOMNode * aCurrentBlock) -{ - nsIDOMText* textContent; - nsresult rv = aParent->QueryInterface(NS_GET_IID(nsIDOMText),(void **)&textContent); - if (NS_OK == rv) { - nsString stringBuf; - textContent->GetData(stringBuf); - - if (aCurrentBlock == mHoldBlockContent || mHoldBlockContent == nsnull) { - if (mSearchDirection == kBackward && aBlockText.GetNumItems() > 0) { - mLastBlockSearchOffset += stringBuf.Length(); - } - } - - aBlockText.AddSubText(aParent, stringBuf, mSearchDirection, mLastBlockSearchOffset); - NS_RELEASE(textContent); - } else { - PRBool hasChildNode; - aParent->HasChildNodes(&hasChildNode); - if (hasChildNode) { - nsIDOMNode * child; - if (mSearchDirection == kForward) { - aParent->GetFirstChild(&child); - } else { - aParent->GetLastChild(&child); - } - while (nsnull != child) { - PRBool found = BuildBlockFromContent(child, aBlockText, aCurrentBlock); - nsIDOMNode * sibling = child; - NS_IF_RELEASE(child); - if (found) { - return PR_TRUE; - } - if (mSearchDirection == kForward) { - sibling->GetNextSibling(&child); - } else { - sibling->GetPreviousSibling(&child); - } - } - } - } - - return PR_FALSE; -} - -//---------------------------------- -// This function moves down through -// the hiearchy and build the block of text -//----------------------------------------- -PRBool nsHTMLDocument::BuildBlockFromStack(nsIDOMNode * aParent, - BlockText & aBlockText, - PRInt32 aStackInx, - nsIDOMNode * aCurrentBlock) -{ - nsIDOMNode * stackChild = mChildStack[aStackInx]; - - PRBool hasChildNode; - aParent->HasChildNodes(&hasChildNode); - if (hasChildNode) { - nsIDOMNode * child = stackChild; - NS_ADDREF(child); - - while (nsnull != child) { - - if (child == stackChild && aStackInx > 0) { - if (NodeIsBlock(child)) { - if (SearchBlock(aBlockText, *mSearchStr, aCurrentBlock)) { - NS_IF_RELEASE(child); - return PR_TRUE; - } else { - aBlockText.ClearBlock(); - } - BlockText blockText; - if (BuildBlockFromStack(child, blockText, aStackInx-1, child)) { - NS_IF_RELEASE(child); - return PR_TRUE; - } - if (SearchBlock(blockText, *mSearchStr, child)) { - return PR_TRUE; - } - } else { - if (BuildBlockFromStack(child, aBlockText, aStackInx-1, aCurrentBlock)) { - NS_IF_RELEASE(child); - return PR_TRUE; - } - } - } else { - if (BuildBlockFromContent(child, aBlockText, aCurrentBlock)) { - NS_IF_RELEASE(child); - return PR_TRUE; - } - } - - nsIDOMNode * sibling = child; - NS_RELEASE(child); - if (mSearchDirection == kForward) { - sibling->GetNextSibling(&child); - } else { - sibling->GetPreviousSibling(&child); - } - } - } - - return PR_FALSE; - -} - - -#if 0 // debug -void printDOMRefs(nsIDOMNode * aNode, PRInt32 aLevel) -{ - char * cStr = nsnull; - - PRInt32 i; - for (i=0;iQueryInterface(NS_GET_IID(nsIDOMElement),(void **)&domElement); - if (NS_OK == rv) { - nsString tagName; - domElement->GetTagName(tagName); - cStr = tagName.ToNewCString(); - NS_RELEASE(domElement); - } - - nsIDOMText* textContent; - rv = aNode->QueryInterface(NS_GET_IID(nsIDOMText),(void **)&textContent); - if (NS_OK == rv) { - nsString stringBuf; - textContent->GetData(stringBuf); - cStr = stringBuf.ToNewCString(); - NS_RELEASE(textContent); - } - - if (cStr) { - for (i=0;i"), aNode); - delete[] cStr; - - PRBool hasChildren; - aNode->HasChildNodes(&hasChildren); - if (hasChildren) { - nsIDOMNode * childNode; - aNode->GetFirstChild(&childNode); - while (childNode != nsnull) { - printDOMRefs(childNode, aLevel+2); - nsIDOMNode * oldChild = childNode; - oldChild->GetNextSibling(&childNode); - NS_RELEASE(oldChild); - } - } -} -#endif - - - -static nsIDOMNode * FindDOMNode(nsIDOMNode * aNode, nsIContent * aContent) -{ - nsIContent* content; - nsresult rv = aNode->QueryInterface(NS_GET_IID(nsIContent),(void **)&content); - if (NS_OK == rv) { - if (content == aContent) { - return aNode; - } - } - - PRBool hasChildren; - aNode->HasChildNodes(&hasChildren); - if (hasChildren) { - nsIDOMNode * childNode; - aNode->GetFirstChild(&childNode); - while (childNode != nsnull) { - nsIDOMNode * node = FindDOMNode(childNode, aContent); - if (node != nsnull) { - return node; - } - nsIDOMNode * oldChild = childNode; - oldChild->GetNextSibling(&childNode); - NS_RELEASE(oldChild); - } - } - return nsnull; -} - -/** - * Finds text in content - */ -NS_IMETHODIMP nsHTMLDocument::FindNext(const nsAReadableString &aSearchStr, - PRBool aMatchCase, PRBool aSearchDown, - PRBool &aIsFound) -{ -#if 0 - aIsFound = PR_FALSE; - mShouldMatchCase = aMatchCase; - - if (mSearchStr == nsnull) { - mSearchStr = new nsString(aSearchStr); - } else { - mSearchStr->SetLength(0); - mSearchStr->Append(aSearchStr); - } - - // Temporary - PRBool doReplace = PR_FALSE; - nsString replacementStr("xxxx"); - PRInt32 inx = mSearchStr->FindChar('/'); - if (inx > -1) { - if (inx == mSearchStr->Length()-1) { - replacementStr.SetLength(0); - } else { - replacementStr = *mSearchStr; - replacementStr.Cut(0, inx+1); - } - mSearchStr->Truncate(inx); - - doReplace = PR_TRUE; - } - - nsIDOMElement * root = nsnull; - if (NS_OK != GetDocumentElement(&root)) { - return PR_FALSE; - } - - // DEBUG printDOMRefs(root, 0); - - nsIDOMNode * start = nsnull; - nsIDOMNode * end = nsnull; - nsIDOMNode * child; - - if (mBodyContent == nsnull && PR_FALSE == GetBodyContent()) { - return NS_OK; - } - - //printRefs(mBodyContent, 0); - - start = mBodyContent; - NS_ADDREF(start); - - // Find very first Piece of Content - while (1) { - start->GetFirstChild(&child); - if (child == nsnull) { - break; - } - NS_RELEASE(start); - start = child; - } - - end = mBodyContent; - NS_ADDREF(end); - - // Find very last piece of Content - while (1) { - end->GetLastChild(&child); - if (child == nsnull) { - break; - } - NS_RELEASE(end); - end = child; - } - - nsSelectionRange * range = mSelection->GetRange(); - nsSelectionPoint * startPnt = range->GetStartPoint(); - nsSelectionPoint * endPnt = range->GetEndPoint(); - nsIContent * endContent = range->GetEndContent(); - nsIContent * startContent; - - mSearchDirection = aSearchDown? kForward:kBackward; - nsIDOMNode * searchNode = nsnull; - - // This is a short circut for starting to search - // at the beginning of the doocument forward - if (endContent == nsnull && mSearchDirection == kForward) { - searchNode = mBodyContent; - BlockText blockText; - if (!BuildBlockTraversing(searchNode, blockText, mBodyContent)) { - if (SearchBlock(blockText, *mSearchStr, mBodyContent)) { - aIsFound = PR_TRUE; - } - } else { - aIsFound = PR_TRUE; - } - } else { - - mAdjustToEnd = PR_FALSE; - - // Convert the nsICOntent Node in the Selection Points - // to their DOM Node counter part - if (mSearchDirection == kForward) { - nsIDOMNode * endNode; - nsresult rv = endContent->QueryInterface(NS_GET_IID(nsIDOMNode),(void **)&endNode); - if (NS_OK == rv) { - searchNode = endNode; - } - mLastBlockSearchOffset = endPnt->GetOffset(); - } else { - nsIContent * startContent = range->GetStartContent(); - if (startContent == nsnull) { - searchNode = end; - mAdjustToEnd = PR_TRUE; - } else { - nsIDOMNode * startNode; - nsresult rv = startContent->QueryInterface(NS_GET_IID(nsIDOMNode),(void **)&startNode); - if (NS_OK == rv) { - searchNode = startNode; - } - mLastBlockSearchOffset = startPnt->GetOffset(); - NS_IF_RELEASE(startContent); - } - } - - nsIDOMNode * blockContent = FindBlockParent(searchNode); // this ref counts blockContent - while (blockContent != nsnull) { - - BlockText blockText; - if (BuildBlockFromStack(blockContent, blockText, mStackInx-1, blockContent)) { - aIsFound = PR_TRUE; - break; - } - if (SearchBlock(blockText, *mSearchStr, blockContent)) { - return PR_TRUE; - } - - mLastBlockSearchOffset = 0; - mAdjustToEnd = PR_TRUE; - - nsIDOMNode * blockChild = blockContent; - blockContent = FindBlockParent(blockChild, PR_TRUE); - NS_RELEASE(blockChild); - } - - // Clear up stack and release content nodes on it - PRInt32 i; - for (i=0;iGetRange(); - startContent = range->GetStartContent(); - endContent = range->GetEndContent(); - startPnt = range->GetStartPoint(); - endPnt = range->GetEndPoint(); - - nsIDOMElement * root = nsnull; - if (NS_OK == GetDocumentElement(&root)) { - nsIDOMNode * node = FindDOMNode(root, startContent); - - nsString contentStr; - nsIDOMText* textContent; - nsresult rv = node->QueryInterface(NS_GET_IID(nsIDOMText),(void **)&textContent); - if (NS_OK == rv) { - textContent->GetData(contentStr); - NS_RELEASE(textContent); - } - - //PRInt32 offset = contentStr.Find(*mSearchStr, !mShouldMatchCase); - PRInt32 offset; - // temporary - if (mShouldMatchCase) { - offset = contentStr.Find(*mSearchStr); - if (offset == -1) { - offset = contentStr.RFind(*mSearchStr); - } - } else { - nsString cs(contentStr); - nsString ss(*mSearchStr); - cs.ToLowerCase(); - ss.ToLowerCase(); - offset = cs.Find(ss); - if (offset == -1) { - offset = cs.RFind(ss); - } - } - // end temporary - - if (offset > -1) { - contentStr.Cut(offset, mSearchStr->Length()); - contentStr.Insert(replacementStr, offset, replacementStr.Length()); - - nsIDOMNode * parent; - node->GetParentNode(&parent); - - //nsIDOMNode * delNode; - //parent->ReplaceChild(newNode, node, &delNode); - - PRBool nodeWasAdded = PR_FALSE; - nsIDOMNode * nextNode; - nsIDOMNode * prevNode; - nsIDOMNode * delNode; - - node->GetPreviousSibling(&prevNode); - node->GetNextSibling(&nextNode); - - parent->RemoveChild(node, &delNode); - NS_IF_RELEASE(delNode); - - nsIDOMNode * contentNode = nsnull; - PRInt32 newOffset; - - if (contentStr.Length() > 0) { - nsIDOMNode * retNode; - nsIDOMText * newNode; - CreateTextNode(contentStr, &newNode); - if (nsnull != nextNode) { - parent->InsertBefore(newNode, nextNode, &retNode); - } else { - parent->AppendChild(newNode, &retNode); - } - - newOffset = offset + replacementStr.Length(); - contentNode = newNode; - nodeWasAdded = PR_TRUE; - - NS_IF_RELEASE(newNode); - NS_IF_RELEASE(retNode); - } else { - newOffset = 0; - contentNode = (nextNode == nsnull ? prevNode : nextNode); - // XXX Bummer if previous is also null then this was the only child - // now we have to go find a different node to set the content to for selection - // So we will use the parent node for now, but this needs to be changed - if (contentNode == nsnull) { - contentNode = parent; - } - } - - NS_ADDREF(contentNode); - - NS_IF_RELEASE(nextNode); - NS_IF_RELEASE(prevNode); - - if (contentNode != nsnull) { - nsIContent* content; - rv = contentNode->QueryInterface(NS_GET_IID(nsIContent),(void **)&content); - if (NS_OK == rv) { - //range = mSelection->GetRange(); - //startPnt = range->GetStartPoint(); - //endPnt = range->GetEndPoint(); - - startPnt->SetContent(content); - startPnt->SetOffset(newOffset); - endPnt->SetContent(content); - endPnt->SetOffset(newOffset); - range->SetStartPoint(startPnt); - range->SetEndPoint(endPnt); - NS_RELEASE(content); - } - } - NS_IF_RELEASE(contentNode); - NS_IF_RELEASE(parent); - NS_IF_RELEASE(node); - NS_IF_RELEASE(root); - } - } - NS_RELEASE(startContent); - NS_RELEASE(endContent); - } -#endif //0 - return NS_OK; -} PRBool nsHTMLDocument::GetBodyContent() @@ -4188,47 +3291,3 @@ nsHTMLDocument::GetForms(nsIDOMHTMLCollection** aForms) return NS_OK; } -PRBool -nsHTMLDocument::IsInSelection(nsISelection* aSelection, - const nsIContent* aContent) const -{ - nsIAtom* tag; - nsresult rv = aContent->GetTag(tag); - PRBool retval; - -#if 0 - // HTML document has to include body in the selection, - // so that output can see style nodes on the body - // in case the caller doesn't know to specify wrap column - // or preformatted or similar styles. - retval = (NS_SUCCEEDED(rv) && tag == nsHTMLAtoms::body); - if (retval) - { - NS_IF_RELEASE(tag); - return PR_TRUE; - } -#endif - - // If it's a block node, return true if the node itself - // is in the selection. If it's inline, return true if - // the node or any of its children is in the selection. - nsCOMPtr node (do_QueryInterface((nsIContent*)aContent)); - PRBool nodeIsBlock = (NS_SUCCEEDED(rv) - && tag != nsHTMLAtoms::pre - && tag != nsHTMLAtoms::h1 - && tag != nsHTMLAtoms::h2 - && tag != nsHTMLAtoms::h3 - && tag != nsHTMLAtoms::h4 - && tag != nsHTMLAtoms::h5 - && tag != nsHTMLAtoms::h6 - && NodeIsBlock(node)); - - aSelection->ContainsNode(node, !nodeIsBlock, &retval); - NS_IF_RELEASE(tag); - return retval; -} - - - - - diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index cb95ebf002b..64997c8c972 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -137,73 +137,18 @@ public: virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, PRBool *aDidDefineProperty); - /** - * Finds text in content - */ - NS_IMETHOD FindNext(const nsAReadableString &aSearchStr, PRBool aMatchCase, - PRBool aSearchDown, PRBool &aIsFound); - - /* - * Like nsDocument::IsInSelection except it always includes the body node - */ - virtual PRBool IsInSelection(nsISelection* aSelection, const nsIContent *aContent) const; - virtual nsresult Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup); /* * Returns true if document.domain was set for this document */ NS_IMETHOD WasDomainSet(PRBool* aDomainWasSet); + protected: nsresult GetPixelDimensions(nsIPresShell* aShell, PRInt32* aWidth, PRInt32* aHeight); - // Find/Search Method/Data member - PRBool SearchBlock(BlockText & aBlockText, - nsString & aStr, - nsIDOMNode * aCurrentBlock); - - PRInt32 GetTagID(nsString& aName) const; - PRBool NodeIsBlock(nsIDOMNode * aNode) const; - nsIDOMNode * FindBlockParent(nsIDOMNode * aNode, - PRBool aSkipThisContent = PR_FALSE); - - PRBool BuildBlockTraversing(nsIDOMNode * aParent, - BlockText & aBlockText, - nsIDOMNode * aCurrentBlock); - - PRBool BuildBlockFromContent(nsIDOMNode * aNode, - BlockText & aBlockText, - nsIDOMNode * aCurrentBlock); - - PRBool BuildBlockFromStack(nsIDOMNode * aParent, - BlockText & aBlockText, - PRInt32 aStackInx, - nsIDOMNode * aCurrentBlock); - - // Search/Find Data Member - nsIDOMNode ** mParentStack; - nsIDOMNode ** mChildStack; - PRInt32 mStackInx; - - nsString * mSearchStr; - PRInt32 mSearchDirection; - - PRInt32 mLastBlockSearchOffset; - PRBool mAdjustToEnd; - - nsIDOMNode * mHoldBlockContent; - nsIDOMNode * mBodyContent; - - PRBool mShouldMatchCase; - - /* - * Bug 13871: Frameset spoofing - find out if document.domain was set - */ - PRBool mDomainWasSet; - -protected: void RegisterNamedItems(nsIContent *aContent, PRBool aInForm); void UnregisterNamedItems(nsIContent *aContent, PRBool aInForm); nsIContent* FindNamedItem(nsIContent *aContent, const nsString& aName, @@ -213,7 +158,8 @@ protected: nsIContent *MatchId(nsIContent *aContent, const nsAReadableString& aId); virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet); - virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); + virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, + PRInt32 aIndex); static PRBool MatchLinks(nsIContent *aContent, nsString* aData); static PRBool MatchAnchors(nsIContent *aContent, nsString* aData); static PRBool MatchLayers(nsIContent *aContent, nsString* aData); @@ -259,11 +205,16 @@ protected: static nsrefcnt gRefCntRDFService; static nsIRDFService* gRDF; - // The parser service -- used for NodeIsBlock: - nsCOMPtr mParserService; - PRUint32 mIsWriting : 1; PRUint32 mWriteLevel : 31; + + nsIDOMNode * mBodyContent; + + /* + * Bug 13871: Frameset spoofing - find out if document.domain was set + */ + PRBool mDomainWasSet; + }; #endif /* nsHTMLDocument_h___ */ diff --git a/mozilla/content/html/document/src/nsIHTMLDocument.h b/mozilla/content/html/document/src/nsIHTMLDocument.h index 998d1c26630..87000c467a1 100644 --- a/mozilla/content/html/document/src/nsIHTMLDocument.h +++ b/mozilla/content/html/document/src/nsIHTMLDocument.h @@ -44,7 +44,7 @@ class nsICSSLoader; */ class nsIHTMLDocument : public nsISupports { public: - static const nsIID& GetIID() { static nsIID iid = NS_IHTMLDOCUMENT_IID; return iid; } + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTMLDOCUMENT_IID) NS_IMETHOD AddImageMap(nsIDOMHTMLMapElement* aMap) = 0; diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index f063a5708fd..f76c8c7097f 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -259,18 +259,6 @@ nsHTMLDocument::nsHTMLDocument() mDTDMode = eDTDMode_quirks; mCSSLoader = nsnull; - // Find/Search Init - mSearchStr = nsnull; - mLastBlockSearchOffset = 0; - mAdjustToEnd = PR_FALSE; - mShouldMatchCase = PR_FALSE; - - mHoldBlockContent = nsnull; - - // These will be converted to a nsDeque - mStackInx = 0; - mParentStack = (nsIDOMNode**) new PRUint32[32]; - mChildStack = (nsIDOMNode**) new PRUint32[32]; mBodyContent = nsnull; mForms = nsnull; mIsWriting = 0; @@ -332,11 +320,6 @@ nsHTMLDocument::~nsHTMLDocument() NS_RELEASE(mCSSLoader); } - // These will be converted to a nsDeque - delete[] mParentStack; - delete[] mChildStack; - - delete mSearchStr; NS_IF_RELEASE(mBodyContent); if (--gRefCntRDFService == 0) @@ -2827,6 +2810,7 @@ nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds) return NS_OK; } +#ifdef NS_IMPLEMENT_DOCUMENT_LAYERS PRBool nsHTMLDocument::MatchLayers(nsIContent *aContent, nsString* aData) { @@ -2844,7 +2828,6 @@ nsHTMLDocument::MatchLayers(nsIContent *aContent, nsString* aData) return result; } -#ifdef NS_IMPLEMENT_DOCUMENT_LAYERS NS_IMETHODIMP nsHTMLDocument::GetLayers(nsIDOMHTMLCollection** aLayers) { @@ -3213,886 +3196,6 @@ nsHTMLDocument::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, } //---------------------------- -class SubText { -public: - nsIDOMNode * mContentNode; - PRInt32 mOffset; - PRInt32 mLength; -}; - -//---------------------------- -class BlockText { - nsString mText; - SubText * mSubTexts[512]; - PRInt32 mNumSubTexts; -public: - BlockText() : mNumSubTexts(0) { PRInt32 i; for (i=0;i<512;i++) mSubTexts[i] = 0; } // debug only - virtual ~BlockText(); - - char * GetText() { return mText.ToNewCString(); } - const nsString & GetNSString() { return mText; } - - void ClearBlock(); - PRInt32 GetNumItems() { return mNumSubTexts; } - - void AddSubText(nsIDOMNode * aNode, nsString & aStr, PRInt32 aDirection, PRInt32 & aOffset); - PRInt32 GetStartEnd(PRInt32 anIndex, PRInt32 aLength, - nsIDOMNode ** aStartNode, PRInt32 & aStartOffset, - nsIDOMNode ** aEndNode, PRInt32 & aEndOffset, - PRInt32 aDirection); -}; - -//---------------------------- -BlockText::~BlockText() -{ - ClearBlock(); -} - -//---------------------------- -void BlockText::ClearBlock() -{ - PRInt32 i; - for (i=0;imContentNode = aNode; - subTxt->mLength = aStr.Length(); - if (aDirection == kForward) { - subTxt->mOffset = mText.Length(); - mText.Append(aStr); - mSubTexts[mNumSubTexts++] = subTxt; - } - else { - subTxt->mOffset = 0; - // Shift them all down one slot - PRInt32 i; - for (i=mNumSubTexts;i>0;i--) { - mSubTexts[i] = mSubTexts[i-1]; - mSubTexts[i]->mOffset += aStr.Length(); - } - mNumSubTexts++; - mText.Insert(aStr, 0); - mSubTexts[0] = subTxt; - } - } -} - -//----------------------------------------------- -PRInt32 BlockText::GetStartEnd(PRInt32 anIndex, PRInt32 aLength, - nsIDOMNode ** aStartNode, PRInt32 & aStartOffset, - nsIDOMNode ** aEndNode, PRInt32 & aEndOffset, - PRInt32 aDirection) -{ - - PRInt32 i = 0; - PRInt32 endPos = anIndex + aLength; - while (anIndex > mSubTexts[i]->mOffset+mSubTexts[i]->mLength) { - i++; - } - aStartOffset = anIndex - mSubTexts[i]->mOffset; - *aStartNode = mSubTexts[i]->mContentNode; - if (endPos <= mSubTexts[i]->mOffset+mSubTexts[i]->mLength) { - aEndOffset = aStartOffset + aLength; - *aEndNode = *aStartNode; - } else { - - while (endPos > mSubTexts[i]->mOffset+mSubTexts[i]->mLength) { - i++; - } - aEndOffset = endPos - mSubTexts[i]->mOffset; - *aEndNode = mSubTexts[i]->mContentNode; - } - - if (aDirection == kBackward) { - endPos -= aLength; - } - return endPos; - -} - -//----------------------------------------------- -PRBool nsHTMLDocument::SearchBlock(BlockText & aBlockText, - nsString & aStr, - nsIDOMNode * aCurrentBlock) -{ - PRBool found = PR_FALSE; - - PRInt32 lastBlockSearchOffset; - PRBool adjustToEnd; - - if (aCurrentBlock == mHoldBlockContent || mHoldBlockContent == nsnull) { - lastBlockSearchOffset = mLastBlockSearchOffset; - adjustToEnd = mAdjustToEnd; - } else { - lastBlockSearchOffset = 0; - adjustToEnd = PR_TRUE; - } - - char * searchStr; - char * contentStr; - - if (!mShouldMatchCase) { - nsString searchTxt(aStr); - nsString blockTxt(aBlockText.GetNSString()); - - searchTxt.ToLowerCase(); - blockTxt.ToLowerCase(); - searchStr = searchTxt.ToNewCString(); - contentStr = blockTxt.ToNewCString(); - } else { - searchStr = aStr.ToNewCString(); - contentStr = aBlockText.GetText(); - } - - char * adjustedContent; - char * str = nsnull; - - if (mSearchDirection == kForward) { - adjustedContent = contentStr + lastBlockSearchOffset; - str = strstr(adjustedContent, searchStr); - } else { - adjustedContent = contentStr; - size_t adjLen; - size_t srchLen = strlen(searchStr); - if (adjustToEnd) { - adjLen = strlen(adjustedContent); - if (srchLen > adjLen) { - str = nsnull; - } else if (adjLen == srchLen && !strncmp(adjustedContent, searchStr, srchLen)) { - str = adjustedContent; - } else { - str = adjustedContent + adjLen - srchLen; - while (strncmp(str, searchStr, srchLen)) { - str--; - if (str < adjustedContent) { - str = nsnull; - break; - } - } - } - } else { - adjLen = lastBlockSearchOffset; - if (lastBlockSearchOffset > 0) { - str = adjustedContent + adjLen - 1; - while (strncmp(str, searchStr, srchLen)) { - str--; - if (str < adjustedContent) { - str = nsnull; - break; - } - } - } - } - } - -#if 0 - if (str) { - PRInt32 inx = str - contentStr; - - nsIDOMNode * startNode; - PRInt32 startOffset; - nsIDOMNode * endNode; - PRInt32 endOffset; - - mLastBlockSearchOffset = aBlockText.GetStartEnd(inx, aStr.Length(), &startNode, startOffset, &endNode, endOffset, mSearchDirection); - mHoldBlockContent = aCurrentBlock; - nsSelectionRange * range = mSelection->GetRange(); - nsSelectionPoint * startPnt = range->GetStartPoint(); - nsSelectionPoint * endPnt = range->GetEndPoint(); - - nsIContent* content; - nsresult rv = startNode->QueryInterface(NS_GET_IID(nsIContent),(void **)&content); - if (NS_OK == rv) { - startPnt->SetPoint(content, startOffset, PR_TRUE); - NS_RELEASE(content); - } - rv = endNode->QueryInterface(NS_GET_IID(nsIContent),(void **)&content); - if (NS_OK == rv) { - endPnt->SetPoint(content, endOffset, PR_FALSE); - NS_RELEASE(content); - } - - found = PR_TRUE; - } -#endif //0 - delete[] searchStr; - delete[] contentStr; - - return found; -} - -//////////////////////////////////////////////////////////////// -// Methods to see if a Content node is a block or an inline tag. -//////////////////////////////////////////////////////////////// -PRInt32 nsHTMLDocument::GetTagID(nsString& aName) const -{ - if (!mParserService) - { - nsIParserService* parserService; - if (NS_FAILED(nsServiceManager::GetService(kParserServiceCID, - NS_GET_IID(nsIParserService), - (nsISupports**)&parserService)) - || !parserService) - return PR_FALSE; - - // Wish mParserService could be mutable: - NS_CONST_CAST(nsHTMLDocument* , this)->mParserService = dont_AddRef(parserService); - } - - PRInt32 id; - mParserService->HTMLStringTagToId(aName, &id); - return id; -} - -PRBool nsHTMLDocument::NodeIsBlock(nsIDOMNode* aNode) const -{ - if (!aNode) - return NS_ERROR_INVALID_ARG; - - // Get the id of the tag itself: - nsAutoString tagName; - aNode->GetNodeName(tagName); - PRInt32 ID = GetTagID(tagName); - - // Get the parent - nsCOMPtr parentNode; - nsresult rv = aNode->GetParentNode(getter_AddRefs(parentNode)); - if (NS_FAILED(rv)) return rv; - - // and the parent's id - parentNode->GetNodeName(tagName); - PRInt32 parentID = GetTagID(tagName); - - // Now we can get the inline status from the DTD: - nsCOMPtr dtd; - rv = GetDTD(getter_AddRefs(dtd)); - if (NS_FAILED(rv) || !dtd) - return PR_FALSE; - return dtd->IsBlockElement(ID, parentID); -} - -///////////////////////////////////////////// -// This function moves up the parent hierarchy -// looking for a parent that is a "block" -///////////////////////////////////////////// -nsIDOMNode * nsHTMLDocument::FindBlockParent(nsIDOMNode * aNode, - PRBool aSkipThisContent) -{ - // Clear up stack and release content nodes on it - PRInt32 i; - for (i=0;iGetParentNode(&parent); - nsIDOMNode * child; - - if (parent == nsnull) { - return nsnull; - } - NS_ADDREF(aNode); - - // This method enables the param "aNode" be part of the "path" - // on the stack as the it look for the block parent. - // - // There are times when we don't want to include the aNode - // as part of the path so we skip to its prev/next sibling. If it was - // the first/last sibling then we jump up to it's parent. - if (aSkipThisContent) { - child = aNode; - nsIDOMNode * nextChild; - - PRBool done = PR_FALSE; - while (!done) { - - if (mSearchDirection == kForward) { - child->GetNextSibling(&nextChild); - } else { - child->GetPreviousSibling(&nextChild); - } - - if (nextChild == nsnull) { - NS_RELEASE(child); - child = parent; - child->GetParentNode(&parent); - if (parent == nsnull) { - NS_RELEASE(child); - return nsnull; - } - } else { - NS_RELEASE(child); - child = nextChild; - done = PR_TRUE; - } - } // while - - } else { - child = aNode; - } - - // This travels up through the parents looking for the parent who - // is a block tag. We place the child/parent pairs onto a stack - // so we know what nodes to skip as we work our way back down into - // the block - do { - - NS_ADDREF(parent); - NS_ADDREF(child); - mParentStack[mStackInx] = parent; - mChildStack[mStackInx++] = child; - - if (parent == mBodyContent) { - break; - } - - nsIDOMNode * oldChild = child; - child = parent; - child->GetParentNode(&parent); - NS_RELEASE(oldChild); - } while (parent != nsnull); - - - NS_RELEASE(child); - return parent; -} - -//----------------------------------------------- -PRBool nsHTMLDocument::BuildBlockFromContent(nsIDOMNode * aNode, - BlockText & aBlockText, - nsIDOMNode * aCurrentBlock) -{ - // First check to see if it is a new Block node - // If it is then we need to check the current block text (aBlockText) - // to see if it holds the search string - if (NodeIsBlock(aNode)) { - - // Search current block of text - if (SearchBlock(aBlockText, *mSearchStr, aCurrentBlock)) { - return PR_TRUE; - } - - // Clear the text we have already searched - aBlockText.ClearBlock(); - - // Start new search here on down with a new block - BlockText blockText; - if (!BuildBlockTraversing(aNode, blockText, aNode)) { - // down inside the search string wasn't found check the full block text - // for the search text - if (SearchBlock(blockText, *mSearchStr, aNode)) { - return PR_TRUE; - } - } else { - // search text was found down inside, so leave - return PR_TRUE; - } - - } else { - if (BuildBlockTraversing(aNode, aBlockText, aCurrentBlock)) { - return PR_TRUE; - } - } - - return PR_FALSE; -} - -//---------------------------------- -// This function moves down through -// the hiearchy and build the block of text -//----------------------------------------- -PRBool nsHTMLDocument::BuildBlockTraversing(nsIDOMNode * aParent, - BlockText & aBlockText, - nsIDOMNode * aCurrentBlock) -{ - nsIDOMText* textContent; - nsresult rv = aParent->QueryInterface(NS_GET_IID(nsIDOMText),(void **)&textContent); - if (NS_OK == rv) { - nsString stringBuf; - textContent->GetData(stringBuf); - - if (aCurrentBlock == mHoldBlockContent || mHoldBlockContent == nsnull) { - if (mSearchDirection == kBackward && aBlockText.GetNumItems() > 0) { - mLastBlockSearchOffset += stringBuf.Length(); - } - } - - aBlockText.AddSubText(aParent, stringBuf, mSearchDirection, mLastBlockSearchOffset); - NS_RELEASE(textContent); - } else { - PRBool hasChildNode; - aParent->HasChildNodes(&hasChildNode); - if (hasChildNode) { - nsIDOMNode * child; - if (mSearchDirection == kForward) { - aParent->GetFirstChild(&child); - } else { - aParent->GetLastChild(&child); - } - while (nsnull != child) { - PRBool found = BuildBlockFromContent(child, aBlockText, aCurrentBlock); - nsIDOMNode * sibling = child; - NS_IF_RELEASE(child); - if (found) { - return PR_TRUE; - } - if (mSearchDirection == kForward) { - sibling->GetNextSibling(&child); - } else { - sibling->GetPreviousSibling(&child); - } - } - } - } - - return PR_FALSE; -} - -//---------------------------------- -// This function moves down through -// the hiearchy and build the block of text -//----------------------------------------- -PRBool nsHTMLDocument::BuildBlockFromStack(nsIDOMNode * aParent, - BlockText & aBlockText, - PRInt32 aStackInx, - nsIDOMNode * aCurrentBlock) -{ - nsIDOMNode * stackChild = mChildStack[aStackInx]; - - PRBool hasChildNode; - aParent->HasChildNodes(&hasChildNode); - if (hasChildNode) { - nsIDOMNode * child = stackChild; - NS_ADDREF(child); - - while (nsnull != child) { - - if (child == stackChild && aStackInx > 0) { - if (NodeIsBlock(child)) { - if (SearchBlock(aBlockText, *mSearchStr, aCurrentBlock)) { - NS_IF_RELEASE(child); - return PR_TRUE; - } else { - aBlockText.ClearBlock(); - } - BlockText blockText; - if (BuildBlockFromStack(child, blockText, aStackInx-1, child)) { - NS_IF_RELEASE(child); - return PR_TRUE; - } - if (SearchBlock(blockText, *mSearchStr, child)) { - return PR_TRUE; - } - } else { - if (BuildBlockFromStack(child, aBlockText, aStackInx-1, aCurrentBlock)) { - NS_IF_RELEASE(child); - return PR_TRUE; - } - } - } else { - if (BuildBlockFromContent(child, aBlockText, aCurrentBlock)) { - NS_IF_RELEASE(child); - return PR_TRUE; - } - } - - nsIDOMNode * sibling = child; - NS_RELEASE(child); - if (mSearchDirection == kForward) { - sibling->GetNextSibling(&child); - } else { - sibling->GetPreviousSibling(&child); - } - } - } - - return PR_FALSE; - -} - - -#if 0 // debug -void printDOMRefs(nsIDOMNode * aNode, PRInt32 aLevel) -{ - char * cStr = nsnull; - - PRInt32 i; - for (i=0;iQueryInterface(NS_GET_IID(nsIDOMElement),(void **)&domElement); - if (NS_OK == rv) { - nsString tagName; - domElement->GetTagName(tagName); - cStr = tagName.ToNewCString(); - NS_RELEASE(domElement); - } - - nsIDOMText* textContent; - rv = aNode->QueryInterface(NS_GET_IID(nsIDOMText),(void **)&textContent); - if (NS_OK == rv) { - nsString stringBuf; - textContent->GetData(stringBuf); - cStr = stringBuf.ToNewCString(); - NS_RELEASE(textContent); - } - - if (cStr) { - for (i=0;i"), aNode); - delete[] cStr; - - PRBool hasChildren; - aNode->HasChildNodes(&hasChildren); - if (hasChildren) { - nsIDOMNode * childNode; - aNode->GetFirstChild(&childNode); - while (childNode != nsnull) { - printDOMRefs(childNode, aLevel+2); - nsIDOMNode * oldChild = childNode; - oldChild->GetNextSibling(&childNode); - NS_RELEASE(oldChild); - } - } -} -#endif - - - -static nsIDOMNode * FindDOMNode(nsIDOMNode * aNode, nsIContent * aContent) -{ - nsIContent* content; - nsresult rv = aNode->QueryInterface(NS_GET_IID(nsIContent),(void **)&content); - if (NS_OK == rv) { - if (content == aContent) { - return aNode; - } - } - - PRBool hasChildren; - aNode->HasChildNodes(&hasChildren); - if (hasChildren) { - nsIDOMNode * childNode; - aNode->GetFirstChild(&childNode); - while (childNode != nsnull) { - nsIDOMNode * node = FindDOMNode(childNode, aContent); - if (node != nsnull) { - return node; - } - nsIDOMNode * oldChild = childNode; - oldChild->GetNextSibling(&childNode); - NS_RELEASE(oldChild); - } - } - return nsnull; -} - -/** - * Finds text in content - */ -NS_IMETHODIMP nsHTMLDocument::FindNext(const nsAReadableString &aSearchStr, - PRBool aMatchCase, PRBool aSearchDown, - PRBool &aIsFound) -{ -#if 0 - aIsFound = PR_FALSE; - mShouldMatchCase = aMatchCase; - - if (mSearchStr == nsnull) { - mSearchStr = new nsString(aSearchStr); - } else { - mSearchStr->SetLength(0); - mSearchStr->Append(aSearchStr); - } - - // Temporary - PRBool doReplace = PR_FALSE; - nsString replacementStr("xxxx"); - PRInt32 inx = mSearchStr->FindChar('/'); - if (inx > -1) { - if (inx == mSearchStr->Length()-1) { - replacementStr.SetLength(0); - } else { - replacementStr = *mSearchStr; - replacementStr.Cut(0, inx+1); - } - mSearchStr->Truncate(inx); - - doReplace = PR_TRUE; - } - - nsIDOMElement * root = nsnull; - if (NS_OK != GetDocumentElement(&root)) { - return PR_FALSE; - } - - // DEBUG printDOMRefs(root, 0); - - nsIDOMNode * start = nsnull; - nsIDOMNode * end = nsnull; - nsIDOMNode * child; - - if (mBodyContent == nsnull && PR_FALSE == GetBodyContent()) { - return NS_OK; - } - - //printRefs(mBodyContent, 0); - - start = mBodyContent; - NS_ADDREF(start); - - // Find very first Piece of Content - while (1) { - start->GetFirstChild(&child); - if (child == nsnull) { - break; - } - NS_RELEASE(start); - start = child; - } - - end = mBodyContent; - NS_ADDREF(end); - - // Find very last piece of Content - while (1) { - end->GetLastChild(&child); - if (child == nsnull) { - break; - } - NS_RELEASE(end); - end = child; - } - - nsSelectionRange * range = mSelection->GetRange(); - nsSelectionPoint * startPnt = range->GetStartPoint(); - nsSelectionPoint * endPnt = range->GetEndPoint(); - nsIContent * endContent = range->GetEndContent(); - nsIContent * startContent; - - mSearchDirection = aSearchDown? kForward:kBackward; - nsIDOMNode * searchNode = nsnull; - - // This is a short circut for starting to search - // at the beginning of the doocument forward - if (endContent == nsnull && mSearchDirection == kForward) { - searchNode = mBodyContent; - BlockText blockText; - if (!BuildBlockTraversing(searchNode, blockText, mBodyContent)) { - if (SearchBlock(blockText, *mSearchStr, mBodyContent)) { - aIsFound = PR_TRUE; - } - } else { - aIsFound = PR_TRUE; - } - } else { - - mAdjustToEnd = PR_FALSE; - - // Convert the nsICOntent Node in the Selection Points - // to their DOM Node counter part - if (mSearchDirection == kForward) { - nsIDOMNode * endNode; - nsresult rv = endContent->QueryInterface(NS_GET_IID(nsIDOMNode),(void **)&endNode); - if (NS_OK == rv) { - searchNode = endNode; - } - mLastBlockSearchOffset = endPnt->GetOffset(); - } else { - nsIContent * startContent = range->GetStartContent(); - if (startContent == nsnull) { - searchNode = end; - mAdjustToEnd = PR_TRUE; - } else { - nsIDOMNode * startNode; - nsresult rv = startContent->QueryInterface(NS_GET_IID(nsIDOMNode),(void **)&startNode); - if (NS_OK == rv) { - searchNode = startNode; - } - mLastBlockSearchOffset = startPnt->GetOffset(); - NS_IF_RELEASE(startContent); - } - } - - nsIDOMNode * blockContent = FindBlockParent(searchNode); // this ref counts blockContent - while (blockContent != nsnull) { - - BlockText blockText; - if (BuildBlockFromStack(blockContent, blockText, mStackInx-1, blockContent)) { - aIsFound = PR_TRUE; - break; - } - if (SearchBlock(blockText, *mSearchStr, blockContent)) { - return PR_TRUE; - } - - mLastBlockSearchOffset = 0; - mAdjustToEnd = PR_TRUE; - - nsIDOMNode * blockChild = blockContent; - blockContent = FindBlockParent(blockChild, PR_TRUE); - NS_RELEASE(blockChild); - } - - // Clear up stack and release content nodes on it - PRInt32 i; - for (i=0;iGetRange(); - startContent = range->GetStartContent(); - endContent = range->GetEndContent(); - startPnt = range->GetStartPoint(); - endPnt = range->GetEndPoint(); - - nsIDOMElement * root = nsnull; - if (NS_OK == GetDocumentElement(&root)) { - nsIDOMNode * node = FindDOMNode(root, startContent); - - nsString contentStr; - nsIDOMText* textContent; - nsresult rv = node->QueryInterface(NS_GET_IID(nsIDOMText),(void **)&textContent); - if (NS_OK == rv) { - textContent->GetData(contentStr); - NS_RELEASE(textContent); - } - - //PRInt32 offset = contentStr.Find(*mSearchStr, !mShouldMatchCase); - PRInt32 offset; - // temporary - if (mShouldMatchCase) { - offset = contentStr.Find(*mSearchStr); - if (offset == -1) { - offset = contentStr.RFind(*mSearchStr); - } - } else { - nsString cs(contentStr); - nsString ss(*mSearchStr); - cs.ToLowerCase(); - ss.ToLowerCase(); - offset = cs.Find(ss); - if (offset == -1) { - offset = cs.RFind(ss); - } - } - // end temporary - - if (offset > -1) { - contentStr.Cut(offset, mSearchStr->Length()); - contentStr.Insert(replacementStr, offset, replacementStr.Length()); - - nsIDOMNode * parent; - node->GetParentNode(&parent); - - //nsIDOMNode * delNode; - //parent->ReplaceChild(newNode, node, &delNode); - - PRBool nodeWasAdded = PR_FALSE; - nsIDOMNode * nextNode; - nsIDOMNode * prevNode; - nsIDOMNode * delNode; - - node->GetPreviousSibling(&prevNode); - node->GetNextSibling(&nextNode); - - parent->RemoveChild(node, &delNode); - NS_IF_RELEASE(delNode); - - nsIDOMNode * contentNode = nsnull; - PRInt32 newOffset; - - if (contentStr.Length() > 0) { - nsIDOMNode * retNode; - nsIDOMText * newNode; - CreateTextNode(contentStr, &newNode); - if (nsnull != nextNode) { - parent->InsertBefore(newNode, nextNode, &retNode); - } else { - parent->AppendChild(newNode, &retNode); - } - - newOffset = offset + replacementStr.Length(); - contentNode = newNode; - nodeWasAdded = PR_TRUE; - - NS_IF_RELEASE(newNode); - NS_IF_RELEASE(retNode); - } else { - newOffset = 0; - contentNode = (nextNode == nsnull ? prevNode : nextNode); - // XXX Bummer if previous is also null then this was the only child - // now we have to go find a different node to set the content to for selection - // So we will use the parent node for now, but this needs to be changed - if (contentNode == nsnull) { - contentNode = parent; - } - } - - NS_ADDREF(contentNode); - - NS_IF_RELEASE(nextNode); - NS_IF_RELEASE(prevNode); - - if (contentNode != nsnull) { - nsIContent* content; - rv = contentNode->QueryInterface(NS_GET_IID(nsIContent),(void **)&content); - if (NS_OK == rv) { - //range = mSelection->GetRange(); - //startPnt = range->GetStartPoint(); - //endPnt = range->GetEndPoint(); - - startPnt->SetContent(content); - startPnt->SetOffset(newOffset); - endPnt->SetContent(content); - endPnt->SetOffset(newOffset); - range->SetStartPoint(startPnt); - range->SetEndPoint(endPnt); - NS_RELEASE(content); - } - } - NS_IF_RELEASE(contentNode); - NS_IF_RELEASE(parent); - NS_IF_RELEASE(node); - NS_IF_RELEASE(root); - } - } - NS_RELEASE(startContent); - NS_RELEASE(endContent); - } -#endif //0 - return NS_OK; -} PRBool nsHTMLDocument::GetBodyContent() @@ -4188,47 +3291,3 @@ nsHTMLDocument::GetForms(nsIDOMHTMLCollection** aForms) return NS_OK; } -PRBool -nsHTMLDocument::IsInSelection(nsISelection* aSelection, - const nsIContent* aContent) const -{ - nsIAtom* tag; - nsresult rv = aContent->GetTag(tag); - PRBool retval; - -#if 0 - // HTML document has to include body in the selection, - // so that output can see style nodes on the body - // in case the caller doesn't know to specify wrap column - // or preformatted or similar styles. - retval = (NS_SUCCEEDED(rv) && tag == nsHTMLAtoms::body); - if (retval) - { - NS_IF_RELEASE(tag); - return PR_TRUE; - } -#endif - - // If it's a block node, return true if the node itself - // is in the selection. If it's inline, return true if - // the node or any of its children is in the selection. - nsCOMPtr node (do_QueryInterface((nsIContent*)aContent)); - PRBool nodeIsBlock = (NS_SUCCEEDED(rv) - && tag != nsHTMLAtoms::pre - && tag != nsHTMLAtoms::h1 - && tag != nsHTMLAtoms::h2 - && tag != nsHTMLAtoms::h3 - && tag != nsHTMLAtoms::h4 - && tag != nsHTMLAtoms::h5 - && tag != nsHTMLAtoms::h6 - && NodeIsBlock(node)); - - aSelection->ContainsNode(node, !nodeIsBlock, &retval); - NS_IF_RELEASE(tag); - return retval; -} - - - - - diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.h b/mozilla/layout/html/document/src/nsHTMLDocument.h index cb95ebf002b..64997c8c972 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.h +++ b/mozilla/layout/html/document/src/nsHTMLDocument.h @@ -137,73 +137,18 @@ public: virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, PRBool *aDidDefineProperty); - /** - * Finds text in content - */ - NS_IMETHOD FindNext(const nsAReadableString &aSearchStr, PRBool aMatchCase, - PRBool aSearchDown, PRBool &aIsFound); - - /* - * Like nsDocument::IsInSelection except it always includes the body node - */ - virtual PRBool IsInSelection(nsISelection* aSelection, const nsIContent *aContent) const; - virtual nsresult Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup); /* * Returns true if document.domain was set for this document */ NS_IMETHOD WasDomainSet(PRBool* aDomainWasSet); + protected: nsresult GetPixelDimensions(nsIPresShell* aShell, PRInt32* aWidth, PRInt32* aHeight); - // Find/Search Method/Data member - PRBool SearchBlock(BlockText & aBlockText, - nsString & aStr, - nsIDOMNode * aCurrentBlock); - - PRInt32 GetTagID(nsString& aName) const; - PRBool NodeIsBlock(nsIDOMNode * aNode) const; - nsIDOMNode * FindBlockParent(nsIDOMNode * aNode, - PRBool aSkipThisContent = PR_FALSE); - - PRBool BuildBlockTraversing(nsIDOMNode * aParent, - BlockText & aBlockText, - nsIDOMNode * aCurrentBlock); - - PRBool BuildBlockFromContent(nsIDOMNode * aNode, - BlockText & aBlockText, - nsIDOMNode * aCurrentBlock); - - PRBool BuildBlockFromStack(nsIDOMNode * aParent, - BlockText & aBlockText, - PRInt32 aStackInx, - nsIDOMNode * aCurrentBlock); - - // Search/Find Data Member - nsIDOMNode ** mParentStack; - nsIDOMNode ** mChildStack; - PRInt32 mStackInx; - - nsString * mSearchStr; - PRInt32 mSearchDirection; - - PRInt32 mLastBlockSearchOffset; - PRBool mAdjustToEnd; - - nsIDOMNode * mHoldBlockContent; - nsIDOMNode * mBodyContent; - - PRBool mShouldMatchCase; - - /* - * Bug 13871: Frameset spoofing - find out if document.domain was set - */ - PRBool mDomainWasSet; - -protected: void RegisterNamedItems(nsIContent *aContent, PRBool aInForm); void UnregisterNamedItems(nsIContent *aContent, PRBool aInForm); nsIContent* FindNamedItem(nsIContent *aContent, const nsString& aName, @@ -213,7 +158,8 @@ protected: nsIContent *MatchId(nsIContent *aContent, const nsAReadableString& aId); virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet); - virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); + virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, + PRInt32 aIndex); static PRBool MatchLinks(nsIContent *aContent, nsString* aData); static PRBool MatchAnchors(nsIContent *aContent, nsString* aData); static PRBool MatchLayers(nsIContent *aContent, nsString* aData); @@ -259,11 +205,16 @@ protected: static nsrefcnt gRefCntRDFService; static nsIRDFService* gRDF; - // The parser service -- used for NodeIsBlock: - nsCOMPtr mParserService; - PRUint32 mIsWriting : 1; PRUint32 mWriteLevel : 31; + + nsIDOMNode * mBodyContent; + + /* + * Bug 13871: Frameset spoofing - find out if document.domain was set + */ + PRBool mDomainWasSet; + }; #endif /* nsHTMLDocument_h___ */ diff --git a/mozilla/layout/html/document/src/nsIHTMLDocument.h b/mozilla/layout/html/document/src/nsIHTMLDocument.h index 998d1c26630..87000c467a1 100644 --- a/mozilla/layout/html/document/src/nsIHTMLDocument.h +++ b/mozilla/layout/html/document/src/nsIHTMLDocument.h @@ -44,7 +44,7 @@ class nsICSSLoader; */ class nsIHTMLDocument : public nsISupports { public: - static const nsIID& GetIID() { static nsIID iid = NS_IHTMLDOCUMENT_IID; return iid; } + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTMLDOCUMENT_IID) NS_IMETHOD AddImageMap(nsIDOMHTMLMapElement* aMap) = 0;