NS_IMETHODIMP inDeepTreeWalker::PreviousNode(nsIDOMNode **_retval) { if (!mCurrentNode || mStack.Length() == 1) { // Nowhere to go from here *_retval = nullptr; return NS_OK; } nsCOMPtr<nsIDOMNode> node; PreviousSibling(getter_AddRefs(node)); if (!node) { return ParentNode(_retval); } // Now we're positioned at our previous sibling. But since the DOM tree // traversal is depth-first, the previous node is its most deeply nested last // child. Just loop until LastChild() returns null; since the LastChild() // call that returns null won't affect our position, we will then be // positioned at the correct node. while (node) { LastChild(getter_AddRefs(node)); } NS_ADDREF(*_retval = mCurrentNode); return NS_OK; }
BOOL CookiePath::CleanSmartCardAuthenticatedCookies() { Cookie *next_ck = (Cookie *) cookie_list.First(); while(next_ck ) { Cookie *ck = next_ck; next_ck = next_ck->Suc(); if(ck->GetHaveSmartCardAuthentication()) { OP_DELETE(ck); } } CookiePath *next_cp = LastChild(); while(next_cp) { CookiePath *cp = next_cp; next_cp = next_cp->Pred(); if(cp->CleanSmartCardAuthenticatedCookies()) { cp->Out(); OP_DELETE(cp); } } return cookie_list.Empty() && Empty(); }
const TiXmlElement* TiXmlNode::LastChildElement( const char * _value ) const { const TiXmlNode* node; for ( node = LastChild( _value ); node; node = node->PreviousSibling( _value ) ) { if ( node->ToElement() ) return node->ToElement(); } return 0; }
void XMLParagraph::DeleteLeaf(size_t nLeaf) { auto pNode = LeafRef(nLeaf).Node(); auto pParent = pNode->Parent(); while(pParent && (pParent->FirstChild() == pParent->LastChild())){ pNode = pParent; pParent = pParent->Parent(); } if(pParent){ pParent->DeleteChild(pNode); } }
Node * Node::FindEditChildByAttrib ( std::string const & childName, std::string const & attrName, std::string const & attrValue) { XML::Node::ChildIter it = FirstChild (); XML::Node::ChildIter last = LastChild (); while (it != last) { XML::Node * child = *it; if (child->GetName () == childName && child->FindAttribValue (attrName) == attrValue) return child; ++it; } return 0; }
NS_IMETHODIMP inDeepTreeWalker::NextNode(nsIDOMNode **_retval) { // First try our kids FirstChild(_retval); if (*_retval) { return NS_OK; } // Now keep trying next siblings up the parent chain, but if we // discover there's nothing else restore our state. #ifdef DEBUG nsIDOMNode* origCurrentNode = mCurrentNode; #endif uint32_t lastChildCallsToMake = 0; while (1) { NextSibling(_retval); if (*_retval) { return NS_OK; } nsCOMPtr<nsIDOMNode> parent; ParentNode(getter_AddRefs(parent)); if (!parent) { // Nowhere else to go; we're done. Restore our state. while (lastChildCallsToMake--) { nsCOMPtr<nsIDOMNode> dummy; LastChild(getter_AddRefs(dummy)); } NS_ASSERTION(mCurrentNode == origCurrentNode, "Didn't go back to the right node?"); *_retval = nullptr; return NS_OK; } ++lastChildCallsToMake; } NS_NOTREACHED("how did we get here?"); return NS_OK; }
void Node::Write (std::ostream & out, unsigned indent) const { WriteOpeningTag (out, indent); if (!_closed) { for (ConstChildIter it = FirstChild (); it != LastChild (); ++it) { XML::Node * child = *it; if (child->GetName ().empty ()) // text { out << Indentation (indent) << child->GetAttribValue ("Text") << std::endl; } else { child->Write (out, indent + 2); } } } WriteClosingTag (out, indent); }
// pth must not start with '/' CookiePath* CookiePath::GetCookiePathL(const char* pth, BOOL create, BOOL &is_full_path) { if (pth && *pth) { is_full_path = FALSE; char* tmp = (char*) (*pth != '?' ? op_strpbrk(pth, "/?") : NULL); char save_c = 0; if (tmp) { save_c = *tmp; *tmp = '\0'; } int test = 1; BOOL is_prefix = FALSE; CookiePath* cp = LastChild(); if(create) { while (cp && test>0) { test = UriUnescape::strcmp(cp->PathPart().CStr(), pth, UriUnescape::Safe); if (test > 0) cp = cp->Pred(); } } else { int len1 = op_strlen(pth); int clen; while(cp && test>0) { clen = cp->PathPart().Length(); if(clen < len1 && UriUnescape::isstrprefix(cp->PathPart().CStr(), pth, UriUnescape::All)) { is_prefix = TRUE; test = 0; } else test = UriUnescape::strcmp(cp->PathPart().CStr(), pth, UriUnescape::Safe); if (test > 0) cp = cp->Pred(); } } CookiePath* next_cp = cp; if (test != 0 || !cp) { if (!create) { if (tmp) *tmp = save_c; return this; } next_cp = CookiePath::CreateL(pth); if (cp) next_cp->Follow(cp); else if (FirstChild()) next_cp->Precede(FirstChild()); else next_cp->Under(this); } BOOL local_is_full_path = FALSE; if (tmp) { *tmp = save_c; if(save_c == '/') local_is_full_path = TRUE; } const char* next_path = (tmp && !is_prefix) ? (save_c == '?' ? tmp : tmp+1) : 0; CookiePath* return_cp = next_cp->GetCookiePathL(next_path, create, is_full_path); if(return_cp == next_cp && tmp && local_is_full_path && !is_prefix) is_full_path = TRUE; return return_cp; } else { return this; } }
nsIFrame* nsFrameList::GetNextVisualFor(nsIFrame* aFrame) const { if (!mFirstChild) return nullptr; nsIFrame* parent = mFirstChild->GetParent(); if (!parent) return aFrame ? aFrame->GetPrevSibling() : mFirstChild; nsBidiLevel baseLevel = nsBidiPresUtils::GetFrameBaseLevel(mFirstChild); nsAutoLineIterator iter = parent->GetLineIterator(); if (!iter) { // Parent is not a block Frame if (parent->GetType() == nsGkAtoms::lineFrame) { // Line frames are not bidi-splittable, so need to consider bidi reordering if (baseLevel == NSBIDI_LTR) { return nsBidiPresUtils::GetFrameToRightOf(aFrame, mFirstChild, -1); } else { // RTL return nsBidiPresUtils::GetFrameToLeftOf(aFrame, mFirstChild, -1); } } else { // Just get the next or prev sibling, depending on block and frame direction. nsBidiLevel frameEmbeddingLevel = nsBidiPresUtils::GetFrameEmbeddingLevel(mFirstChild); if ((frameEmbeddingLevel & 1) == (baseLevel & 1)) { return aFrame ? aFrame->GetNextSibling() : mFirstChild; } else { return aFrame ? aFrame->GetPrevSibling() : LastChild(); } } } // Parent is a block frame, so use the LineIterator to find the next visual // sibling on this line, or the first one on the next line. int32_t thisLine; if (aFrame) { thisLine = iter->FindLineContaining(aFrame); if (thisLine < 0) return nullptr; } else { thisLine = -1; } nsIFrame* frame = nullptr; nsIFrame* firstFrameOnLine; int32_t numFramesOnLine; nsRect lineBounds; uint32_t lineFlags; if (aFrame) { iter->GetLine(thisLine, &firstFrameOnLine, &numFramesOnLine, lineBounds, &lineFlags); if (baseLevel == NSBIDI_LTR) { frame = nsBidiPresUtils::GetFrameToRightOf(aFrame, firstFrameOnLine, numFramesOnLine); } else { // RTL frame = nsBidiPresUtils::GetFrameToLeftOf(aFrame, firstFrameOnLine, numFramesOnLine); } } int32_t numLines = iter->GetNumLines(); if (!frame && thisLine < numLines - 1) { // Get the first frame of the next line iter->GetLine(thisLine + 1, &firstFrameOnLine, &numFramesOnLine, lineBounds, &lineFlags); if (baseLevel == NSBIDI_LTR) { frame = nsBidiPresUtils::GetFrameToRightOf(nullptr, firstFrameOnLine, numFramesOnLine); } else { // RTL frame = nsBidiPresUtils::GetFrameToLeftOf(nullptr, firstFrameOnLine, numFramesOnLine); } } return frame; }
PRBool nsLineBox::IsLastChild(nsIFrame* aFrame) const { nsIFrame* lastFrame = LastChild(); return aFrame == lastFrame; }
void DataInnerNode::addChild(const DataNode &child) { ASSERT(numChildren() < maxStoreableChildren(), "Adding more children than we can store"); ASSERT(child.depth() == depth()-1, "The child that should be added has wrong depth"); node().setSize(node().Size()+1); LastChild()->setKey(child.key()); }