2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
1999-07-02 03:56:25 +00:00
|
|
|
|
|
|
|
|
2013-04-03 00:13:10 +00:00
|
|
|
#include <stddef.h> // for nullptr
|
1999-07-02 03:56:25 +00:00
|
|
|
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc
|
|
|
|
#include "nsCSSStyleSheet.h" // for nsCSSStyleSheet
|
|
|
|
#include "nsDebug.h" // for NS_ENSURE_TRUE
|
|
|
|
#include "nsError.h" // for NS_OK, etc
|
|
|
|
#include "nsIDOMDocument.h" // for nsIDOMDocument
|
|
|
|
#include "nsIDocument.h" // for nsIDocument
|
|
|
|
#include "nsIDocumentObserver.h" // for UPDATE_STYLE
|
|
|
|
#include "nsIEditor.h" // for nsIEditor
|
1999-07-02 03:56:25 +00:00
|
|
|
#include "nsStyleSheetTxns.h"
|
|
|
|
|
2012-07-13 06:33:42 +00:00
|
|
|
class nsIStyleSheet;
|
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
static void
|
|
|
|
AddStyleSheet(nsIEditor* aEditor, nsIStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
aEditor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
if (doc) {
|
|
|
|
doc->BeginUpdate(UPDATE_STYLE);
|
2004-07-28 07:08:41 +00:00
|
|
|
doc->AddStyleSheet(aSheet);
|
2004-01-07 22:30:53 +00:00
|
|
|
doc->EndUpdate(UPDATE_STYLE);
|
|
|
|
}
|
|
|
|
}
|
1999-07-02 03:56:25 +00:00
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
static void
|
|
|
|
RemoveStyleSheet(nsIEditor *aEditor, nsIStyleSheet *aSheet)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
aEditor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
if (doc) {
|
|
|
|
doc->BeginUpdate(UPDATE_STYLE);
|
|
|
|
doc->RemoveStyleSheet(aSheet);
|
|
|
|
doc->EndUpdate(UPDATE_STYLE);
|
|
|
|
}
|
|
|
|
}
|
1999-07-02 03:56:25 +00:00
|
|
|
|
|
|
|
AddStyleSheetTxn::AddStyleSheetTxn()
|
1999-09-21 22:31:27 +00:00
|
|
|
: EditTxn()
|
2013-04-03 00:13:10 +00:00
|
|
|
, mEditor(nullptr)
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-21 23:23:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED_1(AddStyleSheetTxn, EditTxn,
|
|
|
|
mSheet)
|
2009-05-09 04:59:25 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTxn)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
|
|
|
|
|
1999-07-02 03:56:25 +00:00
|
|
|
NS_IMETHODIMP
|
2010-05-11 20:41:47 +00:00
|
|
|
AddStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
|
1999-07-02 03:56:25 +00:00
|
|
|
|
|
|
|
mEditor = aEditor;
|
2010-05-11 20:41:47 +00:00
|
|
|
mSheet = aSheet;
|
2013-05-21 23:23:53 +00:00
|
|
|
|
1999-07-02 03:56:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-09 14:23:59 +00:00
|
|
|
AddStyleSheetTxn::DoTransaction()
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
|
2013-05-21 23:23:53 +00:00
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
AddStyleSheet(mEditor, mSheet);
|
|
|
|
return NS_OK;
|
1999-07-02 03:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-09 14:23:59 +00:00
|
|
|
AddStyleSheetTxn::UndoTransaction()
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
|
2013-05-21 23:23:53 +00:00
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
RemoveStyleSheet(mEditor, mSheet);
|
|
|
|
return NS_OK;
|
1999-07-02 03:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:16:54 +00:00
|
|
|
AddStyleSheetTxn::GetTxnDescription(nsAString& aString)
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
2004-06-17 00:13:25 +00:00
|
|
|
aString.AssignLiteral("AddStyleSheetTxn");
|
1999-07-02 03:56:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RemoveStyleSheetTxn::RemoveStyleSheetTxn()
|
1999-09-21 22:31:27 +00:00
|
|
|
: EditTxn()
|
2013-04-03 00:13:10 +00:00
|
|
|
, mEditor(nullptr)
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-21 23:23:53 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED_1(RemoveStyleSheetTxn, EditTxn,
|
|
|
|
mSheet)
|
2009-05-09 04:59:25 +00:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTxn)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(EditTxn)
|
|
|
|
|
1999-07-02 03:56:25 +00:00
|
|
|
NS_IMETHODIMP
|
2010-05-11 20:41:47 +00:00
|
|
|
RemoveStyleSheetTxn::Init(nsIEditor *aEditor, nsCSSStyleSheet *aSheet)
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
|
1999-07-02 03:56:25 +00:00
|
|
|
|
|
|
|
mEditor = aEditor;
|
2010-05-11 20:41:47 +00:00
|
|
|
mSheet = aSheet;
|
|
|
|
|
1999-07-02 03:56:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-09 14:23:59 +00:00
|
|
|
RemoveStyleSheetTxn::DoTransaction()
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
|
1999-07-02 03:56:25 +00:00
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
RemoveStyleSheet(mEditor, mSheet);
|
|
|
|
return NS_OK;
|
1999-07-02 03:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-03-09 14:23:59 +00:00
|
|
|
RemoveStyleSheetTxn::UndoTransaction()
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
2010-06-17 20:40:48 +00:00
|
|
|
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
|
2003-06-30 19:10:53 +00:00
|
|
|
|
2004-01-07 22:30:53 +00:00
|
|
|
AddStyleSheet(mEditor, mSheet);
|
|
|
|
return NS_OK;
|
1999-07-02 03:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:16:54 +00:00
|
|
|
RemoveStyleSheetTxn::GetTxnDescription(nsAString& aString)
|
1999-07-02 03:56:25 +00:00
|
|
|
{
|
2004-06-17 00:13:25 +00:00
|
|
|
aString.AssignLiteral("RemoveStyleSheetTxn");
|
1999-07-02 03:56:25 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|