mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-05 15:59:45 +00:00
Bug 1476897 - part 6: Move implementation of both TextEditor::PasteAsQuotation() and HTMLEditor::PasteAsQuotation() to new virtual methods r=m_kato
Neither TextEditor::PasteAsQuotation() nor HTMLEditor::PasteAsQuotation() is used via nsIEditorMailSupport. So, perhaps, we can remove this method from the interface. But for now, we should move each implementation to new virtual methods and make only HTMLEditor::PasteAsQuotation() calls new method since nobody uses nsIEditorMailSupport with TextEditor instances. MozReview-Commit-ID: Eilxk74VHwT --HG-- extra : rebase_source : 15abe305d9f332ecd521d9115a71443665a8c9fe
This commit is contained in:
parent
a2ecad4a67
commit
5e98e38c30
@ -19,8 +19,6 @@
|
||||
#include "nsID.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIEditorMailSupport.h"
|
||||
#include "nsIPlaintextEditor.h"
|
||||
#include "nsISelectionController.h"
|
||||
#include "nsITransferable.h"
|
||||
#include "nsString.h"
|
||||
@ -1310,7 +1308,7 @@ PasteQuotationCommand::DoCommand(const char* aCommandName,
|
||||
}
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
return textEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
|
||||
return textEditor->PasteAsQuotationAsAction(nsIClipboard::kGlobalClipboard);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -1324,7 +1322,7 @@ PasteQuotationCommand::DoCommandParams(const char* aCommandName,
|
||||
}
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
return textEditor->PasteAsQuotation(nsIClipboard::kGlobalClipboard);
|
||||
return textEditor->PasteAsQuotationAsAction(nsIClipboard::kGlobalClipboard);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -717,7 +717,7 @@ EditorEventListener::HandleMiddleClickPaste(MouseEvent* aMouseEvent)
|
||||
// If the ctrl key is pressed, we'll do paste as quotation.
|
||||
// Would've used the alt key, but the kde wmgr treats alt-middle specially.
|
||||
if (clickEvent->IsControl()) {
|
||||
textEditor->PasteAsQuotation(clipboard);
|
||||
textEditor->PasteAsQuotationAsAction(clipboard);
|
||||
} else {
|
||||
textEditor->Paste(clipboard);
|
||||
}
|
||||
|
@ -156,6 +156,16 @@ public:
|
||||
virtual bool IsAcceptableInputEvent(WidgetGUIEvent* aGUIEvent) override;
|
||||
virtual nsresult GetPreferredIMEState(widget::IMEState* aState) override;
|
||||
|
||||
/**
|
||||
* PasteAsQuotationAsAction() pastes content in clipboard with newly created
|
||||
* blockquote element. If the editor is in plaintext mode, will paste the
|
||||
* content with appending ">" to start of each line.
|
||||
*
|
||||
* @param aClipboardType nsIClipboard::kGlobalClipboard or
|
||||
* nsIClipboard::kSelectionClipboard.
|
||||
*/
|
||||
virtual nsresult PasteAsQuotationAsAction(int32_t aClipboardType) override;
|
||||
|
||||
/**
|
||||
* Can we paste |aTransferable| or, if |aTransferable| is null, will a call
|
||||
* to pasteTransferable later possibly succeed if given an instance of
|
||||
|
@ -1556,10 +1556,23 @@ HTMLEditor::CanPasteTransferable(nsITransferable* aTransferable)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLEditor::PasteAsQuotation(int32_t aSelectionType)
|
||||
HTMLEditor::PasteAsQuotation(int32_t aClipboardType)
|
||||
{
|
||||
if (NS_WARN_IF(aClipboardType != nsIClipboard::kGlobalClipboard &&
|
||||
aClipboardType != nsIClipboard::kSelectionClipboard)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
return HTMLEditor::PasteAsQuotationAsAction(aClipboardType);
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLEditor::PasteAsQuotationAsAction(int32_t aClipboardType)
|
||||
{
|
||||
MOZ_ASSERT(aClipboardType == nsIClipboard::kGlobalClipboard ||
|
||||
aClipboardType == nsIClipboard::kSelectionClipboard);
|
||||
|
||||
if (IsPlaintextEditor()) {
|
||||
return PasteAsPlaintextQuotation(aSelectionType);
|
||||
return PasteAsPlaintextQuotation(aClipboardType);
|
||||
}
|
||||
|
||||
// If it's not in plain text edit mode, paste text into new
|
||||
@ -1606,7 +1619,7 @@ HTMLEditor::PasteAsQuotation(int32_t aSelectionType)
|
||||
}
|
||||
|
||||
// XXX Why don't we call HTMLEditRules::DidDoAction() after Paste()?
|
||||
rv = Paste(aSelectionType);
|
||||
rv = Paste(aClipboardType);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -1845,45 +1845,64 @@ TextEditor::InsertTextWithQuotations(const nsAString& aStringToInsert)
|
||||
NS_IMETHODIMP
|
||||
TextEditor::PasteAsQuotation(int32_t aSelectionType)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TextEditor::PasteAsQuotationAsAction(int32_t aClipboardType)
|
||||
{
|
||||
MOZ_ASSERT(aClipboardType == nsIClipboard::kGlobalClipboard ||
|
||||
aClipboardType == nsIClipboard::kSelectionClipboard);
|
||||
|
||||
// Get Clipboard Service
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIClipboard> clipboard =
|
||||
do_GetService("@mozilla.org/widget/clipboard;1", &rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Get the nsITransferable interface for getting the data from the clipboard
|
||||
nsCOMPtr<nsITransferable> trans;
|
||||
rv = PrepareTransferable(getter_AddRefs(trans));
|
||||
if (NS_SUCCEEDED(rv) && trans) {
|
||||
// Get the Data from the clipboard
|
||||
clipboard->GetData(trans, aSelectionType);
|
||||
|
||||
// Now we ask the transferable for the data
|
||||
// it still owns the data, we just have a pointer to it.
|
||||
// If it can't support a "text" output of the data the call will fail
|
||||
nsCOMPtr<nsISupports> genericDataObj;
|
||||
uint32_t len;
|
||||
nsAutoCString flav;
|
||||
rv = trans->GetAnyTransferData(flav, getter_AddRefs(genericDataObj),
|
||||
&len);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (flav.EqualsLiteral(kUnicodeMime) ||
|
||||
flav.EqualsLiteral(kMozTextInternal)) {
|
||||
nsCOMPtr<nsISupportsString> textDataObj ( do_QueryInterface(genericDataObj) );
|
||||
if (textDataObj && len > 0) {
|
||||
nsAutoString stuffToPaste;
|
||||
textDataObj->GetData ( stuffToPaste );
|
||||
AutoPlaceholderBatch beginBatching(this);
|
||||
rv = InsertWithQuotationsAsSubAction(stuffToPaste);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Failed to insert the text with quotations");
|
||||
}
|
||||
}
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
if (!trans) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return rv;
|
||||
// Get the Data from the clipboard
|
||||
clipboard->GetData(trans, aClipboardType);
|
||||
|
||||
// Now we ask the transferable for the data
|
||||
// it still owns the data, we just have a pointer to it.
|
||||
// If it can't support a "text" output of the data the call will fail
|
||||
nsCOMPtr<nsISupports> genericDataObj;
|
||||
uint32_t len;
|
||||
nsAutoCString flav;
|
||||
rv = trans->GetAnyTransferData(flav, getter_AddRefs(genericDataObj),
|
||||
&len);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!flav.EqualsLiteral(kUnicodeMime) &&
|
||||
!flav.EqualsLiteral(kMozTextInternal)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupportsString> textDataObj = do_QueryInterface(genericDataObj);
|
||||
if (textDataObj && len > 0) {
|
||||
nsAutoString stuffToPaste;
|
||||
textDataObj->GetData ( stuffToPaste );
|
||||
AutoPlaceholderBatch beginBatching(this);
|
||||
rv = InsertWithQuotationsAsSubAction(stuffToPaste);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -127,6 +127,16 @@ public:
|
||||
*/
|
||||
nsresult InsertTextAsAction(const nsAString& aStringToInsert);
|
||||
|
||||
/**
|
||||
* PasteAsQuotationAsAction() pastes content in clipboard as quotation.
|
||||
* If the editor is TextEditor or in plaintext mode, will paste the content
|
||||
* with appending ">" to start of each line.
|
||||
*
|
||||
* @param aClipboardType nsIClipboard::kGlobalClipboard or
|
||||
* nsIClipboard::kSelectionClipboard.
|
||||
*/
|
||||
virtual nsresult PasteAsQuotationAsAction(int32_t aClipboardType);
|
||||
|
||||
/**
|
||||
* DeleteSelectionAsAction() removes selection content or content around
|
||||
* caret with transactions. This should be used for handling it as an
|
||||
|
Loading…
Reference in New Issue
Block a user