1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef SetDocumentTitleTransaction_h
7 #define SetDocumentTitleTransaction_h
8 
9 #include "mozilla/EditTransactionBase.h" // for EditTransactionBase, etc.
10 #include "nsString.h"                   // for nsString
11 #include "nscore.h"                     // for NS_IMETHOD, nsAString, etc.
12 
13 class nsIHTMLEditor;
14 
15 namespace mozilla {
16 
17 /**
18  * A transaction that changes the document's title,
19  *  which is a text node under the <title> tag in a page's <head> section
20  * provides default concrete behavior for all nsITransaction methods.
21  */
22 class SetDocumentTitleTransaction final : public EditTransactionBase
23 {
24 public:
25   /**
26    * Initialize the transaction.
27    * @param aEditor     The object providing core editing operations.
28    * @param aValue      The new value for document title.
29    */
30   NS_IMETHOD Init(nsIHTMLEditor* aEditor,
31                   const nsAString* aValue);
32   SetDocumentTitleTransaction();
33 
34 private:
35   nsresult SetDomTitle(const nsAString& aTitle);
36 
37 public:
38   NS_DECL_EDITTRANSACTIONBASE
39 
40   NS_IMETHOD RedoTransaction() override;
41   NS_IMETHOD GetIsTransient(bool *aIsTransient) override;
42 
43 protected:
44 
45   // The editor that created this transaction.
46   nsIHTMLEditor* mEditor;
47 
48   // The new title string.
49   nsString mValue;
50 
51   // The previous title string to use for undo.
52   nsString mUndoValue;
53 
54   // Set true if we dont' really change the title during Do().
55   bool mIsTransient;
56 };
57 
58 } // namespace mozilla
59 
60 #endif // #ifndef SetDocumentTitleTransaction_h
61