/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* vim: set ts=2 sw=2 et tw=78: *//* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */#ifndef nsHtml5DocumentBuilder_h#define nsHtml5DocumentBuilder_h#include"nsContentSink.h"#include"nsHtml5DocumentMode.h"#include"nsIDocument.h"#include"nsIContent.h"typedefnsIContent*nsIContentPtr;enumeHtml5FlushState{eNotFlushing=0,// not flushingeInFlush=1,// the Flush() method is on the call stackeInDocUpdate=2,// inside an update batch on the documenteNotifying=3// flushing pending append notifications};classnsHtml5DocumentBuilder:publicnsContentSink{public:NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHtml5DocumentBuilder,nsContentSink)NS_DECL_ISUPPORTS_INHERITEDinlinevoidHoldElement(already_AddRefed<nsIContent>aContent){*(mOwnedElements.AppendElement())=aContent;}nsresultInit(nsIDocument*aDoc,nsIURI*aURI,nsISupports*aContainer,nsIChannel*aChannel);// Getters and setters for fields from nsContentSinknsIDocument*GetDocument(){returnmDocument;}nsNodeInfoManager*GetNodeInfoManager(){returnmNodeInfoManager;}/** * Marks this parser as broken and tells the stream parser (if any) to * terminate. * * @return aReason for convenience */virtualnsresultMarkAsBroken(nsresultaReason);/** * Checks if this parser is broken. Returns a non-NS_OK (i.e. non-0) * value if broken. */inlinensresultIsBroken(){returnmBroken;}inlinevoidBeginDocUpdate(){NS_PRECONDITION(mFlushState==eInFlush,"Tried to double-open update.");NS_PRECONDITION(mParser,"Started update without parser.");mFlushState=eInDocUpdate;mDocument->BeginUpdate(UPDATE_CONTENT_MODEL);}inlinevoidEndDocUpdate(){NS_PRECONDITION(mFlushState!=eNotifying,"mFlushState out of sync");if(mFlushState==eInDocUpdate){mFlushState=eInFlush;mDocument->EndUpdate(UPDATE_CONTENT_MODEL);}}boolIsInDocUpdate(){returnmFlushState==eInDocUpdate;}voidSetDocumentCharsetAndSource(nsACString&aCharset,int32_taCharsetSource);/** * Sets up style sheet load / parse */voidUpdateStyleSheet(nsIContent*aElement);voidSetDocumentMode(nsHtml5DocumentModem);voidSetNodeInfoManager(nsNodeInfoManager*aManager){mNodeInfoManager=aManager;}// nsContentSink methodsvirtualvoidUpdateChildCounts()override;virtualnsresultFlushTags()override;protected:explicitnsHtml5DocumentBuilder(boolaRunsToCompletion);virtual~nsHtml5DocumentBuilder();protected:AutoTArray<nsCOMPtr<nsIContent>,32>mOwnedElements;/** * Non-NS_OK if this parser should refuse to process any more input. * For example, the parser needs to be marked as broken if it drops some * input due to a memory allocation failure. In such a case, the whole * parser needs to be marked as broken, because some input has been lost * and parsing more input could lead to a DOM where pieces of HTML source * that weren't supposed to become scripts become scripts. */nsresultmBroken;eHtml5FlushStatemFlushState;};#endif // nsHtml5DocumentBuilder_h