1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef nsHtml5Speculation_h
6 #define nsHtml5Speculation_h
7 
8 #include "nsHtml5OwningUTF16Buffer.h"
9 #include "nsAHtml5TreeBuilderState.h"
10 #include "nsHtml5TreeOperation.h"
11 #include "nsAHtml5TreeOpSink.h"
12 #include "nsTArray.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/UniquePtr.h"
15 
16 class nsHtml5Speculation final : public nsAHtml5TreeOpSink {
17  public:
18   nsHtml5Speculation(nsHtml5OwningUTF16Buffer* aBuffer, int32_t aStart,
19                      int32_t aStartLineNumber,
20                      nsAHtml5TreeBuilderState* aSnapshot);
21 
22   ~nsHtml5Speculation();
23 
GetBuffer()24   nsHtml5OwningUTF16Buffer* GetBuffer() { return mBuffer; }
25 
GetStart()26   int32_t GetStart() { return mStart; }
27 
GetStartLineNumber()28   int32_t GetStartLineNumber() { return mStartLineNumber; }
29 
GetSnapshot()30   nsAHtml5TreeBuilderState* GetSnapshot() { return mSnapshot.get(); }
31 
32   /**
33    * Flush the operations from the tree operations from the argument
34    * queue unconditionally.
35    */
36   virtual void MoveOpsFrom(nsTArray<nsHtml5TreeOperation>& aOpQueue) override;
37 
38   void FlushToSink(nsAHtml5TreeOpSink* aSink);
39 
40  private:
41   /**
42    * The first buffer in the pending UTF-16 buffer queue
43    */
44   RefPtr<nsHtml5OwningUTF16Buffer> mBuffer;
45 
46   /**
47    * The start index of this speculation in the first buffer
48    */
49   int32_t mStart;
50 
51   /**
52    * The current line number at the start of the speculation
53    */
54   int32_t mStartLineNumber;
55 
56   mozilla::UniquePtr<nsAHtml5TreeBuilderState> mSnapshot;
57 
58   nsTArray<nsHtml5TreeOperation> mOpQueue;
59 };
60 
61 #endif  // nsHtml5Speculation_h
62