gecko-dev/editor/libeditor/StyleSheetTransactions.cpp

158 строки
4.2 KiB
C++
Исходник Обычный вид История

/* -*- 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
#include "StyleSheetTransactions.h"
1999-07-02 07:56:25 +04:00
#include <stddef.h> // for nullptr
1999-07-02 07:56:25 +04:00
#include "nsAString.h"
#include "nsCOMPtr.h" // for nsCOMPtr, do_QueryInterface, etc.
#include "mozilla/StyleSheet.h" // for mozilla::StyleSheet
#include "mozilla/StyleSheetInlines.h"
#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 07:56:25 +04:00
namespace mozilla {
static void
AddStyleSheet(nsIEditor* aEditor, StyleSheet* aSheet)
{
nsCOMPtr<nsIDOMDocument> domDoc;
aEditor->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
if (doc) {
doc->BeginUpdate(UPDATE_STYLE);
doc->AddStyleSheet(aSheet);
doc->EndUpdate(UPDATE_STYLE);
}
}
1999-07-02 07:56:25 +04:00
static void
RemoveStyleSheet(nsIEditor* aEditor, StyleSheet* 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 07:56:25 +04:00
/******************************************************************************
* AddStyleSheetTransaction
******************************************************************************/
AddStyleSheetTransaction::AddStyleSheetTransaction()
: mEditor(nullptr)
1999-07-02 07:56:25 +04:00
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(AddStyleSheetTransaction,
EditTransactionBase,
mSheet)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AddStyleSheetTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
1999-07-02 07:56:25 +04:00
NS_IMETHODIMP
AddStyleSheetTransaction::Init(nsIEditor* aEditor,
StyleSheet* aSheet)
1999-07-02 07:56:25 +04:00
{
NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
1999-07-02 07:56:25 +04:00
mEditor = aEditor;
mSheet = aSheet;
1999-07-02 07:56:25 +04:00
return NS_OK;
}
NS_IMETHODIMP
AddStyleSheetTransaction::DoTransaction()
1999-07-02 07:56:25 +04:00
{
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
AddStyleSheet(mEditor, mSheet);
return NS_OK;
1999-07-02 07:56:25 +04:00
}
NS_IMETHODIMP
AddStyleSheetTransaction::UndoTransaction()
1999-07-02 07:56:25 +04:00
{
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
RemoveStyleSheet(mEditor, mSheet);
return NS_OK;
1999-07-02 07:56:25 +04:00
}
NS_IMETHODIMP
AddStyleSheetTransaction::GetTxnDescription(nsAString& aString)
1999-07-02 07:56:25 +04:00
{
aString.AssignLiteral("AddStyleSheetTransaction");
1999-07-02 07:56:25 +04:00
return NS_OK;
}
/******************************************************************************
* RemoveStyleSheetTransaction
******************************************************************************/
1999-07-02 07:56:25 +04:00
RemoveStyleSheetTransaction::RemoveStyleSheetTransaction()
: mEditor(nullptr)
1999-07-02 07:56:25 +04:00
{
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(RemoveStyleSheetTransaction,
EditTransactionBase,
mSheet)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RemoveStyleSheetTransaction)
NS_INTERFACE_MAP_END_INHERITING(EditTransactionBase)
1999-07-02 07:56:25 +04:00
NS_IMETHODIMP
RemoveStyleSheetTransaction::Init(nsIEditor* aEditor,
StyleSheet* aSheet)
1999-07-02 07:56:25 +04:00
{
NS_ENSURE_TRUE(aEditor && aSheet, NS_ERROR_INVALID_ARG);
1999-07-02 07:56:25 +04:00
mEditor = aEditor;
mSheet = aSheet;
1999-07-02 07:56:25 +04:00
return NS_OK;
}
NS_IMETHODIMP
RemoveStyleSheetTransaction::DoTransaction()
1999-07-02 07:56:25 +04:00
{
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
1999-07-02 07:56:25 +04:00
RemoveStyleSheet(mEditor, mSheet);
return NS_OK;
1999-07-02 07:56:25 +04:00
}
NS_IMETHODIMP
RemoveStyleSheetTransaction::UndoTransaction()
1999-07-02 07:56:25 +04:00
{
NS_ENSURE_TRUE(mEditor && mSheet, NS_ERROR_NOT_INITIALIZED);
AddStyleSheet(mEditor, mSheet);
return NS_OK;
1999-07-02 07:56:25 +04:00
}
NS_IMETHODIMP
RemoveStyleSheetTransaction::GetTxnDescription(nsAString& aString)
1999-07-02 07:56:25 +04:00
{
aString.AssignLiteral("RemoveStyleSheetTransaction");
1999-07-02 07:56:25 +04:00
return NS_OK;
}
} // namespace mozilla