2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 07:56:25 +04:00
|
|
|
|
2016-07-07 11:20:22 +03:00
|
|
|
#include "StyleSheetTransactions.h"
|
1999-07-02 07:56:25 +04:00
|
|
|
|
2013-04-03 04:13:10 +04:00
|
|
|
#include <stddef.h> // for nullptr
|
1999-07-02 07:56:25 +04:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsAString.h"
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc.
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheet.h" // for mozilla::StyleSheet
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsDebug.h" // for NS_ENSURE_TRUE
|
2016-07-08 08:15:21 +03:00
|
|
|
#include "nsError.h" // for NS_OK, etc.
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIDOMDocument.h" // for nsIDOMDocument
|
|
|
|
#include "nsIDocument.h" // for nsIDocument
|
|
|
|
#include "nsIDocumentObserver.h" // for UPDATE_STYLE
|
|
|
|
#include "nsIEditor.h" // for nsIEditor
|
1999-07-02 07:56:25 +04:00
|
|
|
|
2016-07-07 11:20:22 +03:00
|
|
|
namespace mozilla {
|
2014-06-20 14:32:49 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
static void
|
2016-09-26 15:03:25 +03:00
|
|
|
AddStyleSheet(nsIEditor* aEditor, StyleSheet* aSheet)
|
2004-01-08 01:30:53 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
aEditor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
if (doc) {
|
|
|
|
doc->BeginUpdate(UPDATE_STYLE);
|
2004-07-28 11:08:41 +04:00
|
|
|
doc->AddStyleSheet(aSheet);
|
2004-01-08 01:30:53 +03:00
|
|
|
doc->EndUpdate(UPDATE_STYLE);
|
|
|
|
}
|
|
|
|
}
|
1999-07-02 07:56:25 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
static void
|
2016-09-26 15:03:25 +03:00
|
|
|
RemoveStyleSheet(nsIEditor* aEditor, StyleSheet* aSheet)
|
2004-01-08 01:30:53 +03:00
|
|
|
{
|
|
|
|
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 07:56:25 +04:00
|
|
|
|
2016-07-07 11:20:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* AddStyleSheetTransaction
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
AddStyleSheetTransaction::AddStyleSheetTransaction()
|
|
|
|
: mEditor(nullptr)
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(AddStyleSheetTransaction,
|
|
|
|
EditTransactionBase,
|
2014-04-25 20:49:00 +04:00
|
|
|
mSheet)
|
2009-05-09 08:59:25 +04:00
|
|
|
|
2016-07-07 11:20:22 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTransaction)
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
|
2009-05-09 08:59:25 +04:00
|
|
|
|
1999-07-02 07:56:25 +04:00
|
|
|
NS_IMETHODIMP
|
2016-07-07 11:20:22 +03:00
|
|
|
AddStyleSheetTransaction::Init(nsIEditor* aEditor,
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet* aSheet)
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
|
1999-07-02 07:56:25 +04:00
|
|
|
|
|
|
|
mEditor = aEditor;
|
2010-05-12 00:41:47 +04:00
|
|
|
mSheet = aSheet;
|
2013-05-22 03:23:53 +04:00
|
|
|
|
1999-07-02 07:56:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-07 11:20:22 +03:00
|
|
|
AddStyleSheetTransaction::DoTransaction()
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
|
2013-05-22 03:23:53 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
AddStyleSheet(mEditor, mSheet);
|
|
|
|
return NS_OK;
|
1999-07-02 07:56:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-07 11:20:22 +03:00
|
|
|
AddStyleSheetTransaction::UndoTransaction()
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
|
2013-05-22 03:23:53 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
RemoveStyleSheet(mEditor, mSheet);
|
|
|
|
return NS_OK;
|
1999-07-02 07:56:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-07 11:20:22 +03:00
|
|
|
AddStyleSheetTransaction::GetTxnDescription(nsAString& aString)
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
2016-07-07 11:20:22 +03:00
|
|
|
aString.AssignLiteral("AddStyleSheetTransaction");
|
1999-07-02 07:56:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-07 11:20:22 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* RemoveStyleSheetTransaction
|
|
|
|
******************************************************************************/
|
1999-07-02 07:56:25 +04:00
|
|
|
|
2016-07-07 11:20:22 +03:00
|
|
|
RemoveStyleSheetTransaction::RemoveStyleSheetTransaction()
|
|
|
|
: mEditor(nullptr)
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(RemoveStyleSheetTransaction,
|
|
|
|
EditTransactionBase,
|
2014-04-25 20:49:00 +04:00
|
|
|
mSheet)
|
2009-05-09 08:59:25 +04:00
|
|
|
|
2016-07-07 11:20:22 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTransaction)
|
2016-07-08 03:48:34 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
|
2009-05-09 08:59:25 +04:00
|
|
|
|
1999-07-02 07:56:25 +04:00
|
|
|
NS_IMETHODIMP
|
2016-07-07 11:20:22 +03:00
|
|
|
RemoveStyleSheetTransaction::Init(nsIEditor* aEditor,
|
2016-09-26 15:03:25 +03:00
|
|
|
StyleSheet* aSheet)
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
|
1999-07-02 07:56:25 +04:00
|
|
|
|
|
|
|
mEditor = aEditor;
|
2010-05-12 00:41:47 +04:00
|
|
|
mSheet = aSheet;
|
|
|
|
|
1999-07-02 07:56:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-07 11:20:22 +03:00
|
|
|
RemoveStyleSheetTransaction::DoTransaction()
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
|
1999-07-02 07:56:25 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
RemoveStyleSheet(mEditor, mSheet);
|
|
|
|
return NS_OK;
|
1999-07-02 07:56:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-07 11:20:22 +03:00
|
|
|
RemoveStyleSheetTransaction::UndoTransaction()
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
2010-06-18 00:40:48 +04:00
|
|
|
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
|
2003-06-30 23:10:53 +04:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
AddStyleSheet(mEditor, mSheet);
|
|
|
|
return NS_OK;
|
1999-07-02 07:56:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-07 11:20:22 +03:00
|
|
|
RemoveStyleSheetTransaction::GetTxnDescription(nsAString& aString)
|
1999-07-02 07:56:25 +04:00
|
|
|
{
|
2016-07-07 11:20:22 +03:00
|
|
|
aString.AssignLiteral("RemoveStyleSheetTransaction");
|
1999-07-02 07:56:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-07-07 11:20:22 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|