gecko-dev/editor/libeditor/TextEditor.cpp

2180 lines
64 KiB
C++
Raw Normal View History

/* -*- 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/. */
#include "mozilla/TextEditor.h"
#include "EditAggregateTransaction.h"
#include "HTMLEditRules.h"
#include "InternetCiter.h"
#include "TextEditUtils.h"
#include "gfxFontUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/EditAction.h"
#include "mozilla/EditorDOMPoint.h"
#include "mozilla/EditorUtils.h"
#include "mozilla/HTMLEditor.h"
#include "mozilla/IMEStateManager.h"
#include "mozilla/mozalloc.h"
#include "mozilla/Preferences.h"
#include "mozilla/TextEditRules.h"
#include "mozilla/TextComposition.h"
#include "mozilla/TextEvents.h"
#include "mozilla/TextServicesDocument.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/Element.h"
#include "nsAString.h"
#include "nsCRT.h"
#include "nsCaret.h"
#include "nsCharTraits.h"
#include "nsComponentManagerUtils.h"
#include "nsContentCID.h"
#include "nsContentList.h"
#include "nsCopySupport.h"
#include "nsDebug.h"
#include "nsDependentSubstring.h"
#include "nsError.h"
#include "nsGkAtoms.h"
#include "nsIAbsorbingTransaction.h"
#include "nsIClipboard.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsIDocumentEncoder.h"
#include "nsINode.h"
#include "nsIPresShell.h"
#include "nsISelectionController.h"
#include "nsISupportsPrimitives.h"
#include "nsITransferable.h"
#include "nsIWeakReferenceUtils.h"
#include "nsNameSpaceManager.h"
#include "nsLiteralString.h"
#include "nsReadableUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsString.h"
#include "nsStringFwd.h"
#include "nsTextNode.h"
#include "nsUnicharUtils.h"
#include "nsXPCOM.h"
class nsIOutputStream;
class nsISupports;
namespace mozilla {
using namespace dom;
template already_AddRefed<Element>
TextEditor::InsertBrElementWithTransaction(
Selection& aSelection,
const EditorDOMPoint& aPointToInsert,
EDirection aSelect);
template already_AddRefed<Element>
TextEditor::InsertBrElementWithTransaction(
Selection& aSelection,
const EditorRawDOMPoint& aPointToInsert,
EDirection aSelect);
TextEditor::TextEditor()
: mWrapColumn(0)
, mMaxTextLength(-1)
, mInitTriggerCounter(0)
, mNewlineHandling(nsIPlaintextEditor::eNewlinesPasteToFirst)
#ifdef XP_WIN
, mCaretStyle(1)
#else
, mCaretStyle(0)
#endif
{
// check the "single line editor newline handling"
// and "caret behaviour in selection" prefs
GetDefaultEditorPrefs(mNewlineHandling, mCaretStyle);
}
TextEditor::~TextEditor()
{
// Remove event listeners. Note that if we had an HTML editor,
// it installed its own instead of these
RemoveEventListeners();
if (mRules)
mRules->DetachEditor();
}
NS_IMPL_CYCLE_COLLECTION_CLASS(TextEditor)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TextEditor, EditorBase)
if (tmp->mRules)
tmp->mRules->DetachEditor();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRules)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedDocumentEncoder)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TextEditor, EditorBase)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRules)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCachedDocumentEncoder)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(TextEditor, EditorBase)
NS_IMPL_RELEASE_INHERITED(TextEditor, EditorBase)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextEditor)
NS_INTERFACE_MAP_ENTRY(nsIPlaintextEditor)
NS_INTERFACE_MAP_END_INHERITING(EditorBase)
nsresult
TextEditor::Init(nsIDocument& aDoc,
Element* aRoot,
nsISelectionController* aSelCon,
uint32_t aFlags,
const nsAString& aInitialValue)
{
if (mRules) {
mRules->DetachEditor();
}
nsresult rulesRv = NS_OK;
{
// block to scope AutoEditInitRulesTrigger
AutoEditInitRulesTrigger rulesTrigger(this, rulesRv);
// Init the base editor
nsresult rv = EditorBase::Init(aDoc, aRoot, aSelCon, aFlags, aInitialValue);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
NS_ENSURE_SUCCESS(rulesRv, rulesRv);
// mRules may not have been initialized yet, when this is called via
Bug 1260651 part.56 Rename nsHTMLEditor to mozilla::HTMLEditor and related stuff r=mccr8 This patch renames classes/structs as: nsHTMLEditor -> mozilla::HTMLEditor nsHTMLEditor::BlobReader -> mozilla::HTMLEditor::BlobReader SetSelectionAfterTableEdit -> mozilla::AutoSelectionSetterAfterTableEdit nsHTMLEditor.h -> HTMLEditor.h (exposed as mozilla/editor/HTMLEditor.h) nsHTMLAbsPosition.cpp -> HTMLAbsPositionEditor.cpp nsHTMLAnonymousUtils.cpp -> HTMLAnonymousNodeEditor.cpp nsHTMLDataTransfer.cpp -> HTMLEditorDataTransfer.cpp nsHTMLEditorStyle.cpp -> HTMLStyleEditor.cpp nsHTMLInlineTableEditor.cpp -> HTMLInlineTableEditor.cpp nsHTMLObjectResizer.cpp -> HTMLEditorObjectResizer.cpp nsTableEditor.cpp -> HTMLTableEditor.cpp These new file names are clearer names which related to HTMLEditor than old names. MozReview-Commit-ID: DTWaoFvy0DF --HG-- rename : editor/libeditor/nsHTMLAbsPosition.cpp => editor/libeditor/HTMLAbsPositionEditor.cpp rename : editor/libeditor/nsHTMLAnonymousUtils.cpp => editor/libeditor/HTMLAnonymousNodeEditor.cpp rename : editor/libeditor/nsHTMLEditor.cpp => editor/libeditor/HTMLEditor.cpp rename : editor/libeditor/nsHTMLEditor.h => editor/libeditor/HTMLEditor.h rename : editor/libeditor/nsHTMLDataTransfer.cpp => editor/libeditor/HTMLEditorDataTransfer.cpp rename : editor/libeditor/nsHTMLObjectResizer.cpp => editor/libeditor/HTMLEditorObjectResizer.cpp rename : editor/libeditor/nsHTMLInlineTableEditor.cpp => editor/libeditor/HTMLInlineTableEditor.cpp rename : editor/libeditor/nsHTMLEditorStyle.cpp => editor/libeditor/HTMLStyleEditor.cpp rename : editor/libeditor/nsTableEditor.cpp => editor/libeditor/HTMLTableEditor.cpp
2016-07-09 02:42:33 +00:00
// HTMLEditor::Init.
if (mRules) {
mRules->SetInitialValue(aInitialValue);
}
return NS_OK;
}
static int32_t sNewlineHandlingPref = -1,
sCaretStylePref = -1;
static void
EditorPrefsChangedCallback(const char* aPrefName, void *)
{
if (!nsCRT::strcmp(aPrefName, "editor.singleLine.pasteNewlines")) {
sNewlineHandlingPref =
Preferences::GetInt("editor.singleLine.pasteNewlines",
nsIPlaintextEditor::eNewlinesPasteToFirst);
} else if (!nsCRT::strcmp(aPrefName, "layout.selection.caret_style")) {
sCaretStylePref = Preferences::GetInt("layout.selection.caret_style",
#ifdef XP_WIN
1);
if (!sCaretStylePref) {
sCaretStylePref = 1;
}
#else
0);
#endif
}
}
// static
void
TextEditor::GetDefaultEditorPrefs(int32_t& aNewlineHandling,
int32_t& aCaretStyle)
{
if (sNewlineHandlingPref == -1) {
Preferences::RegisterCallbackAndCall(EditorPrefsChangedCallback,
"editor.singleLine.pasteNewlines");
Preferences::RegisterCallbackAndCall(EditorPrefsChangedCallback,
"layout.selection.caret_style");
}
aNewlineHandling = sNewlineHandlingPref;
aCaretStyle = sCaretStylePref;
}
void
TextEditor::BeginEditorInit()
{
mInitTriggerCounter++;
}
nsresult
TextEditor::EndEditorInit()
{
MOZ_ASSERT(mInitTriggerCounter > 0, "ended editor init before we began?");
mInitTriggerCounter--;
if (mInitTriggerCounter) {
return NS_OK;
}
nsresult rv = InitRules();
if (NS_FAILED(rv)) {
return rv;
}
// Throw away the old transaction manager if this is not the first time that
// we're initializing the editor.
ClearUndoRedo();
EnableUndoRedo();
return NS_OK;
}
NS_IMETHODIMP
TextEditor::SetDocumentCharacterSet(const nsACString& characterSet)
{
nsresult rv = EditorBase::SetDocumentCharacterSet(characterSet);
NS_ENSURE_SUCCESS(rv, rv);
// Update META charset element.
nsCOMPtr<nsIDocument> doc = GetDocument();
if (NS_WARN_IF(!doc)) {
return NS_ERROR_NOT_INITIALIZED;
}
if (UpdateMetaCharset(*doc, characterSet)) {
return NS_OK;
}
RefPtr<nsContentList> headList =
doc->GetElementsByTagName(NS_LITERAL_STRING("head"));
if (NS_WARN_IF(!headList)) {
return NS_OK;
}
nsCOMPtr<nsIContent> headNode = headList->Item(0);
if (NS_WARN_IF(!headNode)) {
return NS_OK;
}
// Create a new meta charset tag
EditorRawDOMPoint atStartOfHeadNode(headNode, 0);
RefPtr<Element> metaElement =
CreateNodeWithTransaction(*nsGkAtoms::meta, atStartOfHeadNode);
if (NS_WARN_IF(!metaElement)) {
return NS_OK;
}
// Set attributes to the created element
if (characterSet.IsEmpty()) {
return NS_OK;
}
// not undoable, undo should undo CreateNodeWithTransaction().
metaElement->SetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv,
NS_LITERAL_STRING("Content-Type"), true);
metaElement->SetAttr(kNameSpaceID_None, nsGkAtoms::content,
NS_LITERAL_STRING("text/html;charset=") +
NS_ConvertASCIItoUTF16(characterSet),
true);
return NS_OK;
}
bool
TextEditor::UpdateMetaCharset(nsIDocument& aDocument,
const nsACString& aCharacterSet)
{
// get a list of META tags
RefPtr<nsContentList> metaList =
aDocument.GetElementsByTagName(NS_LITERAL_STRING("meta"));
if (NS_WARN_IF(!metaList)) {
return false;
}
for (uint32_t i = 0; i < metaList->Length(true); ++i) {
nsCOMPtr<nsIContent> metaNode = metaList->Item(i);
MOZ_ASSERT(metaNode);
if (!metaNode->IsElement()) {
continue;
}
nsAutoString currentValue;
metaNode->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv,
currentValue);
if (!FindInReadable(NS_LITERAL_STRING("content-type"),
currentValue,
nsCaseInsensitiveStringComparator())) {
continue;
}
metaNode->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::content,
currentValue);
NS_NAMED_LITERAL_STRING(charsetEquals, "charset=");
nsAString::const_iterator originalStart, start, end;
originalStart = currentValue.BeginReading(start);
currentValue.EndReading(end);
if (!FindInReadable(charsetEquals, start, end,
nsCaseInsensitiveStringComparator())) {
continue;
}
// set attribute to <original prefix> charset=text/html
RefPtr<Element> metaElement = metaNode->AsElement();
MOZ_ASSERT(metaElement);
nsresult rv =
SetAttributeWithTransaction(*metaElement, *nsGkAtoms::content,
Substring(originalStart, start) +
charsetEquals +
NS_ConvertASCIItoUTF16(aCharacterSet));
return NS_SUCCEEDED(rv);
}
return false;
}
nsresult
TextEditor::InitRules()
{
if (!mRules) {
// instantiate the rules for this text editor
mRules = new TextEditRules();
}
return mRules->Init(this);
}
nsresult
TextEditor::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent)
{
// NOTE: When you change this method, you should also change:
Bug 1055286 - Flatten editor/libeditor/text to editor/libeditor; r=poiru --HG-- rename : editor/libeditor/text/crashtests/403965-1.xhtml => editor/libeditor/crashtests/403965-1.xhtml rename : editor/libeditor/text/crashtests/580151-1.xhtml => editor/libeditor/crashtests/580151-1.xhtml rename : editor/libeditor/text/nsInternetCiter.cpp => editor/libeditor/nsInternetCiter.cpp rename : editor/libeditor/text/nsInternetCiter.h => editor/libeditor/nsInternetCiter.h rename : editor/libeditor/text/nsPlaintextDataTransfer.cpp => editor/libeditor/nsPlaintextDataTransfer.cpp rename : editor/libeditor/text/nsPlaintextEditor.cpp => editor/libeditor/nsPlaintextEditor.cpp rename : editor/libeditor/text/nsPlaintextEditor.h => editor/libeditor/nsPlaintextEditor.h rename : editor/libeditor/text/nsTextEditRules.cpp => editor/libeditor/nsTextEditRules.cpp rename : editor/libeditor/text/nsTextEditRules.h => editor/libeditor/nsTextEditRules.h rename : editor/libeditor/text/nsTextEditRulesBidi.cpp => editor/libeditor/nsTextEditRulesBidi.cpp rename : editor/libeditor/text/nsTextEditUtils.cpp => editor/libeditor/nsTextEditUtils.cpp rename : editor/libeditor/text/nsTextEditUtils.h => editor/libeditor/nsTextEditUtils.h rename : editor/libeditor/text/tests/test_bug1026397.html => editor/libeditor/tests/test_bug1026397.html rename : editor/libeditor/text/tests/test_bug318065.html => editor/libeditor/tests/test_bug318065.html rename : editor/libeditor/text/tests/test_bug471319.html => editor/libeditor/tests/test_bug471319.html rename : editor/libeditor/text/tests/test_bug471722.html => editor/libeditor/tests/test_bug471722.html rename : editor/libeditor/text/tests/test_bug483651.html => editor/libeditor/tests/test_bug483651.html rename : editor/libeditor/text/tests/test_bug527935.html => editor/libeditor/tests/test_bug527935.html rename : editor/libeditor/text/tests/test_bug569988.html => editor/libeditor/tests/test_bug569988.html rename : editor/libeditor/text/tests/test_bug590554.html => editor/libeditor/tests/test_bug590554.html rename : editor/libeditor/text/tests/test_bug596001.html => editor/libeditor/tests/test_bug596001.html rename : editor/libeditor/text/tests/test_bug596333.html => editor/libeditor/tests/test_bug596333.html rename : editor/libeditor/text/tests/test_bug596506.html => editor/libeditor/tests/test_bug596506.html rename : editor/libeditor/text/tests/test_bug597331.html => editor/libeditor/tests/test_bug597331.html rename : editor/libeditor/text/tests/test_bug600570.html => editor/libeditor/tests/test_bug600570.html rename : editor/libeditor/text/tests/test_bug602130.html => editor/libeditor/tests/test_bug602130.html rename : editor/libeditor/text/tests/test_bug603556.html => editor/libeditor/tests/test_bug603556.html rename : editor/libeditor/text/tests/test_bug604532.html => editor/libeditor/tests/test_bug604532.html rename : editor/libeditor/text/tests/test_bug625452.html => editor/libeditor/tests/test_bug625452.html rename : editor/libeditor/text/tests/test_bug629172.html => editor/libeditor/tests/test_bug629172.html rename : editor/libeditor/text/tests/test_bug636465.xul => editor/libeditor/tests/test_bug636465.xul rename : editor/libeditor/text/tests/test_bug638596.html => editor/libeditor/tests/test_bug638596.html rename : editor/libeditor/text/tests/test_bug641466.html => editor/libeditor/tests/test_bug641466.html rename : editor/libeditor/text/tests/test_bug645914.html => editor/libeditor/tests/test_bug645914.html rename : editor/libeditor/text/tests/test_bug681229.html => editor/libeditor/tests/test_bug681229.html rename : editor/libeditor/text/tests/test_bug692520.html => editor/libeditor/tests/test_bug692520.html rename : editor/libeditor/text/tests/test_bug740784.html => editor/libeditor/tests/test_bug740784.html rename : editor/libeditor/text/tests/test_bug757771.html => editor/libeditor/tests/test_bug757771.html rename : editor/libeditor/text/tests/test_bug830600.html => editor/libeditor/tests/test_bug830600.html rename : editor/libeditor/text/tests/test_dom_input_event_on_texteditor.html => editor/libeditor/tests/test_dom_input_event_on_texteditor.html rename : editor/libeditor/text/tests/test_texteditor_keyevent_handling.html => editor/libeditor/tests/test_texteditor_keyevent_handling.html
2014-08-19 00:59:37 +00:00
// * editor/libeditor/tests/test_texteditor_keyevent_handling.html
Bug 1055105 - Flatten editor/libeditor/html to editor/libeditor; r=poiru --HG-- rename : editor/libeditor/html/TextEditorTest.cpp => editor/libeditor/TextEditorTest.cpp rename : editor/libeditor/html/TextEditorTest.h => editor/libeditor/TextEditorTest.h rename : editor/libeditor/html/TypeInState.cpp => editor/libeditor/TypeInState.cpp rename : editor/libeditor/html/TypeInState.h => editor/libeditor/TypeInState.h rename : editor/libeditor/html/crashtests/336081-1.xhtml => editor/libeditor/crashtests/336081-1.xhtml rename : editor/libeditor/html/crashtests/382778-1.html => editor/libeditor/crashtests/382778-1.html rename : editor/libeditor/html/crashtests/407074-1.html => editor/libeditor/crashtests/407074-1.html rename : editor/libeditor/html/crashtests/407277-1.html => editor/libeditor/crashtests/407277-1.html rename : editor/libeditor/html/crashtests/414178-1.html => editor/libeditor/crashtests/414178-1.html rename : editor/libeditor/html/crashtests/418923-1.html => editor/libeditor/crashtests/418923-1.html rename : editor/libeditor/html/crashtests/420439.html => editor/libeditor/crashtests/420439.html rename : editor/libeditor/html/crashtests/428489-1.html => editor/libeditor/crashtests/428489-1.html rename : editor/libeditor/html/crashtests/431086-1.xhtml => editor/libeditor/crashtests/431086-1.xhtml rename : editor/libeditor/html/crashtests/448329-1.html => editor/libeditor/crashtests/448329-1.html rename : editor/libeditor/html/crashtests/448329-2.html => editor/libeditor/crashtests/448329-2.html rename : editor/libeditor/html/crashtests/448329-3.html => editor/libeditor/crashtests/448329-3.html rename : editor/libeditor/html/crashtests/456727-1.html => editor/libeditor/crashtests/456727-1.html rename : editor/libeditor/html/crashtests/456727-2.html => editor/libeditor/crashtests/456727-2.html rename : editor/libeditor/html/crashtests/467647-1.html => editor/libeditor/crashtests/467647-1.html rename : editor/libeditor/html/crashtests/499844-1.html => editor/libeditor/crashtests/499844-1.html rename : editor/libeditor/html/crashtests/503709-1.xhtml => editor/libeditor/crashtests/503709-1.xhtml rename : editor/libeditor/html/crashtests/513375-1.xhtml => editor/libeditor/crashtests/513375-1.xhtml rename : editor/libeditor/html/crashtests/535632-1.xhtml => editor/libeditor/crashtests/535632-1.xhtml rename : editor/libeditor/html/crashtests/574558-1.xhtml => editor/libeditor/crashtests/574558-1.xhtml rename : editor/libeditor/html/crashtests/582138-1.xhtml => editor/libeditor/crashtests/582138-1.xhtml rename : editor/libeditor/html/crashtests/612565-1.html => editor/libeditor/crashtests/612565-1.html rename : editor/libeditor/html/crashtests/615015-1.html => editor/libeditor/crashtests/615015-1.html rename : editor/libeditor/html/crashtests/615450-1.html => editor/libeditor/crashtests/615450-1.html rename : editor/libeditor/html/crashtests/639736-1.xhtml => editor/libeditor/crashtests/639736-1.xhtml rename : editor/libeditor/html/crashtests/643786-1.html => editor/libeditor/crashtests/643786-1.html rename : editor/libeditor/html/crashtests/682650-1.html => editor/libeditor/crashtests/682650-1.html rename : editor/libeditor/html/crashtests/716456-1.html => editor/libeditor/crashtests/716456-1.html rename : editor/libeditor/html/crashtests/759748.html => editor/libeditor/crashtests/759748.html rename : editor/libeditor/html/crashtests/761861.html => editor/libeditor/crashtests/761861.html rename : editor/libeditor/html/crashtests/766305.html => editor/libeditor/crashtests/766305.html rename : editor/libeditor/html/crashtests/766387.html => editor/libeditor/crashtests/766387.html rename : editor/libeditor/html/crashtests/766795.html => editor/libeditor/crashtests/766795.html rename : editor/libeditor/html/crashtests/767169.html => editor/libeditor/crashtests/767169.html rename : editor/libeditor/html/crashtests/768748.html => editor/libeditor/crashtests/768748.html rename : editor/libeditor/html/crashtests/769008-1.html => editor/libeditor/crashtests/769008-1.html rename : editor/libeditor/html/crashtests/769967.xhtml => editor/libeditor/crashtests/769967.xhtml rename : editor/libeditor/html/crashtests/793866.html => editor/libeditor/crashtests/793866.html rename : editor/libeditor/html/nsEditProperty.cpp => editor/libeditor/nsEditProperty.cpp rename : editor/libeditor/html/nsHTMLAbsPosition.cpp => editor/libeditor/nsHTMLAbsPosition.cpp rename : editor/libeditor/html/nsHTMLAnonymousUtils.cpp => editor/libeditor/nsHTMLAnonymousUtils.cpp rename : editor/libeditor/html/nsHTMLCSSUtils.cpp => editor/libeditor/nsHTMLCSSUtils.cpp rename : editor/libeditor/html/nsHTMLCSSUtils.h => editor/libeditor/nsHTMLCSSUtils.h rename : editor/libeditor/html/nsHTMLDataTransfer.cpp => editor/libeditor/nsHTMLDataTransfer.cpp rename : editor/libeditor/html/nsHTMLEditRules.cpp => editor/libeditor/nsHTMLEditRules.cpp rename : editor/libeditor/html/nsHTMLEditRules.h => editor/libeditor/nsHTMLEditRules.h rename : editor/libeditor/html/nsHTMLEditUtils.cpp => editor/libeditor/nsHTMLEditUtils.cpp rename : editor/libeditor/html/nsHTMLEditUtils.h => editor/libeditor/nsHTMLEditUtils.h rename : editor/libeditor/html/nsHTMLEditor.cpp => editor/libeditor/nsHTMLEditor.cpp rename : editor/libeditor/html/nsHTMLEditor.h => editor/libeditor/nsHTMLEditor.h rename : editor/libeditor/html/nsHTMLEditorEventListener.cpp => editor/libeditor/nsHTMLEditorEventListener.cpp rename : editor/libeditor/html/nsHTMLEditorEventListener.h => editor/libeditor/nsHTMLEditorEventListener.h rename : editor/libeditor/html/nsHTMLEditorStyle.cpp => editor/libeditor/nsHTMLEditorStyle.cpp rename : editor/libeditor/html/nsHTMLInlineTableEditor.cpp => editor/libeditor/nsHTMLInlineTableEditor.cpp rename : editor/libeditor/html/nsHTMLObjectResizer.cpp => editor/libeditor/nsHTMLObjectResizer.cpp rename : editor/libeditor/html/nsHTMLObjectResizer.h => editor/libeditor/nsHTMLObjectResizer.h rename : editor/libeditor/html/nsHTMLURIRefObject.cpp => editor/libeditor/nsHTMLURIRefObject.cpp rename : editor/libeditor/html/nsHTMLURIRefObject.h => editor/libeditor/nsHTMLURIRefObject.h rename : editor/libeditor/html/nsTableEditor.cpp => editor/libeditor/nsTableEditor.cpp rename : editor/libeditor/html/nsWSRunObject.cpp => editor/libeditor/nsWSRunObject.cpp rename : editor/libeditor/html/nsWSRunObject.h => editor/libeditor/nsWSRunObject.h rename : editor/libeditor/html/tests/browserscope/lib/richtext/LICENSE => editor/libeditor/tests/browserscope/lib/richtext/LICENSE rename : editor/libeditor/html/tests/browserscope/lib/richtext/README => editor/libeditor/tests/browserscope/lib/richtext/README rename : editor/libeditor/html/tests/browserscope/lib/richtext/README.Mozilla => editor/libeditor/tests/browserscope/lib/richtext/README.Mozilla rename : editor/libeditor/html/tests/browserscope/lib/richtext/currentStatus.js => editor/libeditor/tests/browserscope/lib/richtext/currentStatus.js rename : editor/libeditor/html/tests/browserscope/lib/richtext/current_revision => editor/libeditor/tests/browserscope/lib/richtext/current_revision rename : editor/libeditor/html/tests/browserscope/lib/richtext/richtext/editable.html => editor/libeditor/tests/browserscope/lib/richtext/richtext/editable.html rename : editor/libeditor/html/tests/browserscope/lib/richtext/richtext/js/range.js => editor/libeditor/tests/browserscope/lib/richtext/richtext/js/range.js rename : editor/libeditor/html/tests/browserscope/lib/richtext/richtext/richtext.html => editor/libeditor/tests/browserscope/lib/richtext/richtext/richtext.html rename : editor/libeditor/html/tests/browserscope/lib/richtext/update_from_upstream => editor/libeditor/tests/browserscope/lib/richtext/update_from_upstream rename : editor/libeditor/html/tests/browserscope/lib/richtext2/LICENSE => editor/libeditor/tests/browserscope/lib/richtext2/LICENSE rename : editor/libeditor/html/tests/browserscope/lib/richtext2/README => editor/libeditor/tests/browserscope/lib/richtext2/README rename : editor/libeditor/html/tests/browserscope/lib/richtext2/README.Mozilla => editor/libeditor/tests/browserscope/lib/richtext2/README.Mozilla rename : editor/libeditor/html/tests/browserscope/lib/richtext2/currentStatus.js => editor/libeditor/tests/browserscope/lib/richtext2/currentStatus.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/current_revision => editor/libeditor/tests/browserscope/lib/richtext2/current_revision rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/__init__.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/__init__.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/common.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/common.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/handlers.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/handlers.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/common.css => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/common.css rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/editable-body.html => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/editable-body.html rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/editable-dM.html => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/editable-dM.html rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/editable-div.html => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/editable-div.html rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/editable.css => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/editable.css rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/canonicalize.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/canonicalize.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/compare.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/compare.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/output.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/output.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/pad.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/pad.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/range-bootstrap.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/range-bootstrap.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/range.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/range.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/run.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/run.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/units.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/units.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/static/js/variables.js => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/static/js/variables.js rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/templates/output.html => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/templates/output.html rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/templates/richtext2.html => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/templates/richtext2.html rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/__init__.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/__init__.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/apply.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/apply.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/applyCSS.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/applyCSS.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/change.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/change.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/changeCSS.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/changeCSS.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/delete.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/delete.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/forwarddelete.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/forwarddelete.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/insert.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/insert.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/queryEnabled.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/queryEnabled.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/queryIndeterm.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/queryIndeterm.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/queryState.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/queryState.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/querySupported.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/querySupported.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/queryValue.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/queryValue.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/selection.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/selection.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/unapply.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/unapply.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/tests/unapplyCSS.py => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/tests/unapplyCSS.py rename : editor/libeditor/html/tests/browserscope/lib/richtext2/richtext2/unittestexample.html => editor/libeditor/tests/browserscope/lib/richtext2/richtext2/unittestexample.html rename : editor/libeditor/html/tests/browserscope/lib/richtext2/update_from_upstream => editor/libeditor/tests/browserscope/lib/richtext2/update_from_upstream rename : editor/libeditor/html/tests/browserscope/mochitest.ini => editor/libeditor/tests/browserscope/mochitest.ini rename : editor/libeditor/html/tests/browserscope/test_richtext.html => editor/libeditor/tests/browserscope/test_richtext.html rename : editor/libeditor/html/tests/browserscope/test_richtext2.html => editor/libeditor/tests/browserscope/test_richtext2.html rename : editor/libeditor/html/tests/data/cfhtml-chromium.txt => editor/libeditor/tests/data/cfhtml-chromium.txt rename : editor/libeditor/html/tests/data/cfhtml-firefox.txt => editor/libeditor/tests/data/cfhtml-firefox.txt rename : editor/libeditor/html/tests/data/cfhtml-ie.txt => editor/libeditor/tests/data/cfhtml-ie.txt rename : editor/libeditor/html/tests/data/cfhtml-nocontext.txt => editor/libeditor/tests/data/cfhtml-nocontext.txt rename : editor/libeditor/html/tests/data/cfhtml-ooo.txt => editor/libeditor/tests/data/cfhtml-ooo.txt rename : editor/libeditor/html/tests/file_bug549262.html => editor/libeditor/tests/file_bug549262.html rename : editor/libeditor/html/tests/file_bug674770-1.html => editor/libeditor/tests/file_bug674770-1.html rename : editor/libeditor/html/tests/file_select_all_without_body.html => editor/libeditor/tests/file_select_all_without_body.html rename : editor/libeditor/html/tests/green.png => editor/libeditor/tests/green.png rename : editor/libeditor/html/tests/test_CF_HTML_clipboard.html => editor/libeditor/tests/test_CF_HTML_clipboard.html rename : editor/libeditor/html/tests/test_bug200416.html => editor/libeditor/tests/test_bug200416.html rename : editor/libeditor/html/tests/test_bug289384.html => editor/libeditor/tests/test_bug289384.html rename : editor/libeditor/html/tests/test_bug290026.html => editor/libeditor/tests/test_bug290026.html rename : editor/libeditor/html/tests/test_bug291780.html => editor/libeditor/tests/test_bug291780.html rename : editor/libeditor/html/tests/test_bug316447.html => editor/libeditor/tests/test_bug316447.html rename : editor/libeditor/html/tests/test_bug332636.html => editor/libeditor/tests/test_bug332636.html rename : editor/libeditor/html/tests/test_bug332636.html^headers^ => editor/libeditor/tests/test_bug332636.html^headers^ rename : editor/libeditor/html/tests/test_bug366682.html => editor/libeditor/tests/test_bug366682.html rename : editor/libeditor/html/tests/test_bug372345.html => editor/libeditor/tests/test_bug372345.html rename : editor/libeditor/html/tests/test_bug404320.html => editor/libeditor/tests/test_bug404320.html rename : editor/libeditor/html/tests/test_bug410986.html => editor/libeditor/tests/test_bug410986.html rename : editor/libeditor/html/tests/test_bug414526.html => editor/libeditor/tests/test_bug414526.html rename : editor/libeditor/html/tests/test_bug417418.html => editor/libeditor/tests/test_bug417418.html rename : editor/libeditor/html/tests/test_bug432225.html => editor/libeditor/tests/test_bug432225.html rename : editor/libeditor/html/tests/test_bug439808.html => editor/libeditor/tests/test_bug439808.html rename : editor/libeditor/html/tests/test_bug442186.html => editor/libeditor/tests/test_bug442186.html rename : editor/libeditor/html/tests/test_bug449243.html => editor/libeditor/tests/test_bug449243.html rename : editor/libeditor/html/tests/test_bug455992.html => editor/libeditor/tests/test_bug455992.html rename : editor/libeditor/html/tests/test_bug456244.html => editor/libeditor/tests/test_bug456244.html rename : editor/libeditor/html/tests/test_bug460740.html => editor/libeditor/tests/test_bug460740.html rename : editor/libeditor/html/tests/test_bug468353.html => editor/libeditor/tests/test_bug468353.html rename : editor/libeditor/html/tests/test_bug478725.html => editor/libeditor/tests/test_bug478725.html rename : editor/libeditor/html/tests/test_bug480647.html => editor/libeditor/tests/test_bug480647.html rename : editor/libeditor/html/tests/test_bug480972.html => editor/libeditor/tests/test_bug480972.html rename : editor/libeditor/html/tests/test_bug484181.html => editor/libeditor/tests/test_bug484181.html rename : editor/libeditor/html/tests/test_bug487524.html => editor/libeditor/tests/test_bug487524.html rename : editor/libeditor/html/tests/test_bug489202.xul => editor/libeditor/tests/test_bug489202.xul rename : editor/libeditor/html/tests/test_bug490879.xul => editor/libeditor/tests/test_bug490879.xul rename : editor/libeditor/html/tests/test_bug520189.html => editor/libeditor/tests/test_bug520189.html rename : editor/libeditor/html/tests/test_bug525389.html => editor/libeditor/tests/test_bug525389.html rename : editor/libeditor/html/tests/test_bug537046.html => editor/libeditor/tests/test_bug537046.html rename : editor/libeditor/html/tests/test_bug549262.html => editor/libeditor/tests/test_bug549262.html rename : editor/libeditor/html/tests/test_bug550434.html => editor/libeditor/tests/test_bug550434.html rename : editor/libeditor/html/tests/test_bug551704.html => editor/libeditor/tests/test_bug551704.html rename : editor/libeditor/html/tests/test_bug552782.html => editor/libeditor/tests/test_bug552782.html rename : editor/libeditor/html/tests/test_bug570144.html => editor/libeditor/tests/test_bug570144.html rename : editor/libeditor/html/tests/test_bug578771.html => editor/libeditor/tests/test_bug578771.html rename : editor/libeditor/html/tests/test_bug587461.html => editor/libeditor/tests/test_bug587461.html rename : editor/libeditor/html/tests/test_bug592592.html => editor/libeditor/tests/test_bug592592.html rename : editor/libeditor/html/tests/test_bug597784.html => editor/libeditor/tests/test_bug597784.html rename : editor/libeditor/html/tests/test_bug599322.html => editor/libeditor/tests/test_bug599322.html rename : editor/libeditor/html/tests/test_bug607584.html => editor/libeditor/tests/test_bug607584.html rename : editor/libeditor/html/tests/test_bug607584.xul => editor/libeditor/tests/test_bug607584.xul rename : editor/libeditor/html/tests/test_bug611182.html => editor/libeditor/tests/test_bug611182.html rename : editor/libeditor/html/tests/test_bug612128.html => editor/libeditor/tests/test_bug612128.html rename : editor/libeditor/html/tests/test_bug612447.html => editor/libeditor/tests/test_bug612447.html rename : editor/libeditor/html/tests/test_bug616590.xul => editor/libeditor/tests/test_bug616590.xul rename : editor/libeditor/html/tests/test_bug620906.html => editor/libeditor/tests/test_bug620906.html rename : editor/libeditor/html/tests/test_bug622371.html => editor/libeditor/tests/test_bug622371.html rename : editor/libeditor/html/tests/test_bug629845.html => editor/libeditor/tests/test_bug629845.html rename : editor/libeditor/html/tests/test_bug635636.html => editor/libeditor/tests/test_bug635636.html rename : editor/libeditor/html/tests/test_bug640321.html => editor/libeditor/tests/test_bug640321.html rename : editor/libeditor/html/tests/test_bug668599.html => editor/libeditor/tests/test_bug668599.html rename : editor/libeditor/html/tests/test_bug674770-1.html => editor/libeditor/tests/test_bug674770-1.html rename : editor/libeditor/html/tests/test_bug674770-2.html => editor/libeditor/tests/test_bug674770-2.html rename : editor/libeditor/html/tests/test_bug674861.html => editor/libeditor/tests/test_bug674861.html rename : editor/libeditor/html/tests/test_bug676401.html => editor/libeditor/tests/test_bug676401.html rename : editor/libeditor/html/tests/test_bug677752.html => editor/libeditor/tests/test_bug677752.html rename : editor/libeditor/html/tests/test_bug686203.html => editor/libeditor/tests/test_bug686203.html rename : editor/libeditor/html/tests/test_bug697842.html => editor/libeditor/tests/test_bug697842.html rename : editor/libeditor/html/tests/test_bug725069.html => editor/libeditor/tests/test_bug725069.html rename : editor/libeditor/html/tests/test_bug735059.html => editor/libeditor/tests/test_bug735059.html rename : editor/libeditor/html/tests/test_bug738366.html => editor/libeditor/tests/test_bug738366.html rename : editor/libeditor/html/tests/test_bug757371.html => editor/libeditor/tests/test_bug757371.html rename : editor/libeditor/html/tests/test_bug767684.html => editor/libeditor/tests/test_bug767684.html rename : editor/libeditor/html/tests/test_bug780035.html => editor/libeditor/tests/test_bug780035.html rename : editor/libeditor/html/tests/test_bug780908.xul => editor/libeditor/tests/test_bug780908.xul rename : editor/libeditor/html/tests/test_bug787432.html => editor/libeditor/tests/test_bug787432.html rename : editor/libeditor/html/tests/test_bug790475.html => editor/libeditor/tests/test_bug790475.html rename : editor/libeditor/html/tests/test_bug796839.html => editor/libeditor/tests/test_bug796839.html rename : editor/libeditor/html/tests/test_bug832025.html => editor/libeditor/tests/test_bug832025.html rename : editor/libeditor/html/tests/test_bug857487.html => editor/libeditor/tests/test_bug857487.html rename : editor/libeditor/html/tests/test_bug966155.html => editor/libeditor/tests/test_bug966155.html rename : editor/libeditor/html/tests/test_bug966552.html => editor/libeditor/tests/test_bug966552.html rename : editor/libeditor/html/tests/test_bug998188.html => editor/libeditor/tests/test_bug998188.html rename : editor/libeditor/html/tests/test_contenteditable_focus.html => editor/libeditor/tests/test_contenteditable_focus.html rename : editor/libeditor/html/tests/test_contenteditable_text_input_handling.html => editor/libeditor/tests/test_contenteditable_text_input_handling.html rename : editor/libeditor/html/tests/test_dom_input_event_on_htmleditor.html => editor/libeditor/tests/test_dom_input_event_on_htmleditor.html rename : editor/libeditor/html/tests/test_htmleditor_keyevent_handling.html => editor/libeditor/tests/test_htmleditor_keyevent_handling.html rename : editor/libeditor/html/tests/test_keypress_untrusted_event.html => editor/libeditor/tests/test_keypress_untrusted_event.html rename : editor/libeditor/html/tests/test_root_element_replacement.html => editor/libeditor/tests/test_root_element_replacement.html rename : editor/libeditor/html/tests/test_select_all_without_body.html => editor/libeditor/tests/test_select_all_without_body.html rename : editor/libeditor/html/tests/test_spellcheck_pref.html => editor/libeditor/tests/test_spellcheck_pref.html
2014-08-18 21:28:17 +00:00
// * editor/libeditor/tests/test_htmleditor_keyevent_handling.html
//
// And also when you add new key handling, you need to change the subclass's
// HandleKeyPressEvent()'s switch statement.
if (IsReadonly() || IsDisabled()) {
// When we're not editable, the events handled on EditorBase.
return EditorBase::HandleKeyPressEvent(aKeyboardEvent);
}
if (NS_WARN_IF(!aKeyboardEvent)) {
return NS_ERROR_UNEXPECTED;
}
MOZ_ASSERT(aKeyboardEvent->mMessage == eKeyPress,
"HandleKeyPressEvent gets non-keypress event");
switch (aKeyboardEvent->mKeyCode) {
case NS_VK_META:
case NS_VK_WIN:
case NS_VK_SHIFT:
case NS_VK_CONTROL:
case NS_VK_ALT:
// These keys are handled on EditorBase
return EditorBase::HandleKeyPressEvent(aKeyboardEvent);
case NS_VK_BACK:
if (aKeyboardEvent->IsControl() || aKeyboardEvent->IsAlt() ||
aKeyboardEvent->IsMeta() || aKeyboardEvent->IsOS()) {
return NS_OK;
}
DeleteSelectionAsAction(nsIEditor::ePrevious, nsIEditor::eStrip);
aKeyboardEvent->PreventDefault(); // consumed
return NS_OK;
case NS_VK_DELETE:
// on certain platforms (such as windows) the shift key
// modifies what delete does (cmd_cut in this case).
// bailing here to allow the keybindings to do the cut.
if (aKeyboardEvent->IsShift() || aKeyboardEvent->IsControl() ||
aKeyboardEvent->IsAlt() || aKeyboardEvent->IsMeta() ||
aKeyboardEvent->IsOS()) {
return NS_OK;
}
DeleteSelectionAsAction(nsIEditor::eNext, nsIEditor::eStrip);
aKeyboardEvent->PreventDefault(); // consumed
return NS_OK;
case NS_VK_TAB: {
if (IsTabbable()) {
return NS_OK; // let it be used for focus switching
}
if (aKeyboardEvent->IsShift() || aKeyboardEvent->IsControl() ||
aKeyboardEvent->IsAlt() || aKeyboardEvent->IsMeta() ||
aKeyboardEvent->IsOS()) {
return NS_OK;
}
// else we insert the tab straight through
aKeyboardEvent->PreventDefault();
return OnInputText(NS_LITERAL_STRING("\t"));
}
case NS_VK_RETURN:
if (IsSingleLineEditor() || !aKeyboardEvent->IsInputtingLineBreak()) {
return NS_OK;
}
aKeyboardEvent->PreventDefault();
return OnInputParagraphSeparator();
}
if (!aKeyboardEvent->IsInputtingText()) {
// we don't PreventDefault() here or keybindings like control-x won't work
return NS_OK;
}
aKeyboardEvent->PreventDefault();
nsAutoString str(aKeyboardEvent->mCharCode);
return OnInputText(str);
}
nsresult
TextEditor::OnInputText(const nsAString& aStringToInsert)
{
AutoPlaceholderBatch batch(this, nsGkAtoms::TypingTxnName);
nsresult rv = InsertTextAsSubAction(aStringToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
TextEditor::OnInputParagraphSeparator()
{
AutoPlaceholderBatch batch(this, nsGkAtoms::TypingTxnName);
nsresult rv = InsertParagraphSeparatorAsAction();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
template<typename PT, typename CT>
already_AddRefed<Element>
TextEditor::InsertBrElementWithTransaction(
Selection& aSelection,
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect /* = eNone */)
{
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return nullptr;
}
// We need to insert a <br> node.
RefPtr<Element> newBRElement;
if (aPointToInsert.IsInTextNode()) {
EditorDOMPoint pointInContainer;
if (aPointToInsert.IsStartOfContainer()) {
// Insert before the text node.
pointInContainer.Set(aPointToInsert.GetContainer());
if (NS_WARN_IF(!pointInContainer.IsSet())) {
return nullptr;
}
} else if (aPointToInsert.IsEndOfContainer()) {
// Insert after the text node.
pointInContainer.Set(aPointToInsert.GetContainer());
if (NS_WARN_IF(!pointInContainer.IsSet())) {
return nullptr;
}
DebugOnly<bool> advanced = pointInContainer.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after the text node");
} else {
MOZ_DIAGNOSTIC_ASSERT(aPointToInsert.IsSetAndValid());
// Unfortunately, we need to split the text node at the offset.
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode =
SplitNodeWithTransaction(aPointToInsert, error);
if (NS_WARN_IF(error.Failed())) {
error.SuppressException();
return nullptr;
}
Unused << newLeftNode;
// Insert new <br> before the right node.
pointInContainer.Set(aPointToInsert.GetContainer());
}
// Create a <br> node.
newBRElement = CreateNodeWithTransaction(*nsGkAtoms::br, pointInContainer);
if (NS_WARN_IF(!newBRElement)) {
return nullptr;
}
} else {
newBRElement = CreateNodeWithTransaction(*nsGkAtoms::br, aPointToInsert);
if (NS_WARN_IF(!newBRElement)) {
return nullptr;
}
}
switch (aSelect) {
case eNone:
break;
case eNext: {
aSelection.SetInterlinePosition(true, IgnoreErrors());
// Collapse selection after the <br> node.
EditorRawDOMPoint afterBRElement(newBRElement);
if (afterBRElement.IsSet()) {
DebugOnly<bool> advanced = afterBRElement.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the <br> element");
ErrorResult error;
aSelection.Collapse(afterBRElement, error);
NS_WARNING_ASSERTION(!error.Failed(),
"Failed to collapse selection after the <br> element");
} else {
NS_WARNING("The <br> node is not in the DOM tree?");
}
break;
}
case ePrevious: {
aSelection.SetInterlinePosition(true, IgnoreErrors());
// Collapse selection at the <br> node.
EditorRawDOMPoint atBRElement(newBRElement);
if (atBRElement.IsSet()) {
ErrorResult error;
aSelection.Collapse(atBRElement, error);
NS_WARNING_ASSERTION(!error.Failed(),
"Failed to collapse selection at the <br> element");
} else {
NS_WARNING("The <br> node is not in the DOM tree?");
}
break;
}
default:
NS_WARNING("aSelect has invalid value, the caller need to set selection "
"by itself");
break;
}
return newBRElement.forget();
}
nsresult
TextEditor::ExtendSelectionForDelete(Selection* aSelection,
nsIEditor::EDirection* aAction)
{
bool bCollapsed = aSelection->IsCollapsed();
if (*aAction == eNextWord ||
*aAction == ePreviousWord ||
(*aAction == eNext && bCollapsed) ||
(*aAction == ePrevious && bCollapsed) ||
*aAction == eToBeginningOfLine ||
*aAction == eToEndOfLine) {
nsCOMPtr<nsISelectionController> selCont;
GetSelectionController(getter_AddRefs(selCont));
NS_ENSURE_TRUE(selCont, NS_ERROR_NO_INTERFACE);
switch (*aAction) {
case eNextWord: {
nsresult rv = selCont->WordExtendForDelete(true);
// DeleteSelectionWithTransaction() doesn't handle these actions
// because it's inside batching, so don't confuse it:
*aAction = eNone;
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
case ePreviousWord: {
nsresult rv = selCont->WordExtendForDelete(false);
*aAction = eNone;
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
case eNext: {
nsresult rv = selCont->CharacterExtendForDelete();
// Don't set aAction to eNone (see Bug 502259)
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
case ePrevious: {
// Only extend the selection where the selection is after a UTF-16
// surrogate pair or a variation selector.
// For other cases we don't want to do that, in order
// to make sure that pressing backspace will only delete the last
// typed character.
EditorRawDOMPoint atStartOfSelection =
EditorBase::GetStartPoint(aSelection);
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
}
// node might be anonymous DIV, so we find better text node
EditorRawDOMPoint insertionPoint =
FindBetterInsertionPoint(atStartOfSelection);
if (insertionPoint.IsInTextNode()) {
const nsTextFragment* data =
insertionPoint.GetContainerAsText()->GetText();
uint32_t offset = insertionPoint.Offset();
if ((offset > 1 &&
NS_IS_LOW_SURROGATE(data->CharAt(offset - 1)) &&
NS_IS_HIGH_SURROGATE(data->CharAt(offset - 2))) ||
(offset > 0 &&
gfxFontUtils::IsVarSelector(data->CharAt(offset - 1)))) {
nsresult rv = selCont->CharacterExtendForBackspace();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
}
return NS_OK;
}
case eToBeginningOfLine: {
// Select to beginning
nsresult rv = selCont->IntraLineMove(false, true);
*aAction = eNone;
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
case eToEndOfLine: {
nsresult rv = selCont->IntraLineMove(true, true);
*aAction = eNext;
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
// For avoiding several compiler warnings
default:
return NS_OK;
}
}
return NS_OK;
}
NS_IMETHODIMP
TextEditor::DeleteSelection(EDirection aAction,
EStripWrappers aStripWrappers)
{
nsresult rv = DeleteSelectionAsAction(aAction, aStripWrappers);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
TextEditor::DeleteSelectionAsAction(EDirection aDirection,
EStripWrappers aStripWrappers)
{
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
// Showing this assertion is fine if this method is called by outside via
// mutation event listener or something. Otherwise, this is called by
// wrong method.
NS_ASSERTION(!mPlaceholderBatch,
"Should be called only when this is the only edit action of the operation "
"unless mutation event listener nests some operations");
// delete placeholder txns merge.
AutoPlaceholderBatch batch(this, nsGkAtoms::DeleteTxnName);
nsresult rv = DeleteSelectionAsSubAction(aDirection, aStripWrappers);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
TextEditor::DeleteSelectionAsSubAction(EDirection aDirection,
EStripWrappers aStripWrappers)
{
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
MOZ_ASSERT(mPlaceholderBatch);
if (!mRules) {
return NS_ERROR_NOT_INITIALIZED;
}
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
// pre-process
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
// If there is an existing selection when an extended delete is requested,
// platforms that use "caret-style" caret positioning collapse the
// selection to the start and then create a new selection.
// Platforms that use "selection-style" caret positioning just delete the
// existing selection without extending it.
if (!selection->IsCollapsed()) {
switch (aDirection) {
case eNextWord:
case ePreviousWord:
case eToBeginningOfLine:
case eToEndOfLine: {
if (mCaretStyle != 1) {
aDirection = eNone;
break;
}
ErrorResult error;
selection->CollapseToStart(error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
break;
}
default:
break;
}
}
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this,
EditSubAction::eDeleteSelectedContent,
aDirection);
EditSubActionInfo subActionInfo(EditSubAction::eDeleteSelectedContent);
subActionInfo.collapsedAction = aDirection;
subActionInfo.stripWrappers = aStripWrappers;
bool cancel, handled;
nsresult rv =
rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (!cancel && !handled) {
rv = DeleteSelectionWithTransaction(aDirection, aStripWrappers);
}
if (!cancel) {
// post-process
rv = rules->DidDoAction(selection, subActionInfo, rv);
}
return rv;
}
nsresult
TextEditor::DeleteSelectionWithTransaction(EDirection aDirection,
EStripWrappers aStripWrappers)
{
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_NOT_INITIALIZED;
}
RefPtr<EditAggregateTransaction> deleteSelectionTransaction;
nsCOMPtr<nsINode> deleteNode;
int32_t deleteCharOffset = 0, deleteCharLength = 0;
if (!selection->IsCollapsed() || aDirection != eNone) {
deleteSelectionTransaction =
CreateTxnForDeleteSelection(aDirection,
getter_AddRefs(deleteNode),
&deleteCharOffset,
&deleteCharLength);
if (NS_WARN_IF(!deleteSelectionTransaction)) {
return NS_ERROR_FAILURE;
}
}
RefPtr<CharacterData> deleteCharData =
CharacterData::FromNodeOrNull(deleteNode);
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this,
EditSubAction::eDeleteSelectedContent,
aDirection);
if (mRules && mRules->AsHTMLEditRules()) {
if (!deleteNode) {
RefPtr<HTMLEditRules> htmlEditRules = mRules->AsHTMLEditRules();
htmlEditRules->WillDeleteSelection(*selection);
} else if (!deleteCharData) {
RefPtr<HTMLEditRules> htmlEditRules = mRules->AsHTMLEditRules();
htmlEditRules->WillDeleteNode(*selection, *deleteNode);
}
}
// Notify nsIEditActionListener::WillDelete[Selection|Text]
if (!mActionListeners.IsEmpty()) {
if (!deleteNode) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillDeleteSelection(selection);
}
} else if (deleteCharData) {
AutoActionListenerArray listeners(mActionListeners);
for (auto& listener : listeners) {
listener->WillDeleteText(deleteCharData, deleteCharOffset, 1);
}
}
}
// Delete the specified amount
nsresult rv = DoTransaction(deleteSelectionTransaction);
if (mRules && mRules->AsHTMLEditRules() && deleteCharData) {
MOZ_ASSERT(deleteNode);
RefPtr<HTMLEditRules> htmlEditRules = mRules->AsHTMLEditRules();
htmlEditRules->DidDeleteText(*selection, *deleteNode, deleteCharOffset, 1);
}
if (mTextServicesDocument && NS_SUCCEEDED(rv) &&
deleteNode && !deleteCharData) {
RefPtr<TextServicesDocument> textServicesDocument = mTextServicesDocument;
textServicesDocument->DidDeleteNode(deleteNode);
}
// Notify nsIEditActionListener::DidDelete[Selection|Text|Node]
{
AutoActionListenerArray listeners(mActionListeners);
if (!deleteNode) {
for (auto& listener : mActionListeners) {
listener->DidDeleteSelection(selection);
}
} else if (deleteCharData) {
for (auto& listener : mActionListeners) {
listener->DidDeleteText(deleteCharData, deleteCharOffset, 1, rv);
}
} else {
for (auto& listener : mActionListeners) {
listener->DidDeleteNode(deleteNode, rv);
}
}
}
return rv;
}
already_AddRefed<Element>
TextEditor::DeleteSelectionAndCreateElement(nsAtom& aTag)
{
nsresult rv = DeleteSelectionAndPrepareToCreateNode();
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return nullptr;
}
EditorRawDOMPoint pointToInsert(selection->AnchorRef());
if (!pointToInsert.IsSet()) {
return nullptr;
}
RefPtr<Element> newElement = CreateNodeWithTransaction(aTag, pointToInsert);
// We want the selection to be just after the new node
EditorRawDOMPoint afterNewElement(newElement);
MOZ_ASSERT(afterNewElement.IsSetAndValid());
DebugOnly<bool> advanced = afterNewElement.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to move offset next to the new element");
ErrorResult error;
selection->Collapse(afterNewElement, error);
if (NS_WARN_IF(error.Failed())) {
// XXX Even if it succeeded to create new element, this returns error
// when Selection.Collapse() fails something. This could occur with
// mutation observer or mutation event listener.
error.SuppressException();
return nullptr;
}
return newElement.forget();
}
nsresult
TextEditor::DeleteSelectionAndPrepareToCreateNode()
{
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_NOT_INITIALIZED;
}
if (NS_WARN_IF(!selection->GetAnchorFocusRange())) {
return NS_OK;
}
if (!selection->GetAnchorFocusRange()->Collapsed()) {
nsresult rv = DeleteSelectionAsSubAction(eNone, eStrip);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
MOZ_ASSERT(selection->GetAnchorFocusRange() &&
selection->GetAnchorFocusRange()->Collapsed(),
"Selection not collapsed after delete");
}
// If the selection is a chardata node, split it if necessary and compute
// where to put the new node
EditorDOMPoint atAnchor(selection->AnchorRef());
if (NS_WARN_IF(!atAnchor.IsSet()) || !atAnchor.IsInDataNode()) {
return NS_OK;
}
if (NS_WARN_IF(!atAnchor.GetContainer()->GetParentNode())) {
return NS_ERROR_FAILURE;
}
if (atAnchor.IsStartOfContainer()) {
EditorRawDOMPoint atAnchorContainer(atAnchor.GetContainer());
if (NS_WARN_IF(!atAnchorContainer.IsSetAndValid())) {
return NS_ERROR_FAILURE;
}
ErrorResult error;
selection->Collapse(atAnchorContainer, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
if (atAnchor.IsEndOfContainer()) {
EditorRawDOMPoint afterAnchorContainer(atAnchor.GetContainer());
if (NS_WARN_IF(!afterAnchorContainer.AdvanceOffset())) {
return NS_ERROR_FAILURE;
}
ErrorResult error;
selection->Collapse(afterAnchorContainer, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
ErrorResult error;
nsCOMPtr<nsIContent> newLeftNode = SplitNodeWithTransaction(atAnchor, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
EditorRawDOMPoint atRightNode(atAnchor.GetContainer());
if (NS_WARN_IF(!atRightNode.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(atRightNode.IsSetAndValid());
selection->Collapse(atRightNode, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
return NS_OK;
}
NS_IMETHODIMP
TextEditor::InsertText(const nsAString& aStringToInsert)
{
nsresult rv = InsertTextAsAction(aStringToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
TextEditor::InsertTextAsAction(const nsAString& aStringToInsert)
{
// Showing this assertion is fine if this method is called by outside via
// mutation event listener or something. Otherwise, this is called by
// wrong method.
NS_ASSERTION(!mPlaceholderBatch,
"Should be called only when this is the only edit action of the operation "
"unless mutation event listener nests some operations");
AutoPlaceholderBatch batch(this, nullptr);
nsresult rv = InsertTextAsSubAction(aStringToInsert);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
TextEditor::InsertTextAsSubAction(const nsAString& aStringToInsert)
{
MOZ_ASSERT(mPlaceholderBatch);
if (!mRules) {
return NS_ERROR_NOT_INITIALIZED;
}
// Protect the edit rules object from dying.
RefPtr<TextEditRules> rules(mRules);
EditSubAction editSubAction =
ShouldHandleIMEComposition() ?
EditSubAction::eInsertTextComingFromIME : EditSubAction::eInsertText;
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this, editSubAction, nsIEditor::eNext);
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
nsAutoString resultString;
// XXX can we trust instring to outlive subActionInfo,
// XXX and subActionInfo not to refer to instring in its dtor?
//nsAutoString instring(aStringToInsert);
EditSubActionInfo subActionInfo(editSubAction);
subActionInfo.inString = &aStringToInsert;
subActionInfo.outString = &resultString;
subActionInfo.maxLength = mMaxTextLength;
bool cancel, handled;
nsresult rv =
rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (!cancel && !handled) {
// we rely on rules code for now - no default implementation
}
if (cancel) {
return NS_OK;
}
// post-process
rv = rules->DidDoAction(selection, subActionInfo, NS_OK);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
TextEditor::InsertLineBreak()
{
return InsertParagraphSeparatorAsAction();
}
nsresult
TextEditor::InsertParagraphSeparatorAsAction()
{
if (!mRules) {
return NS_ERROR_NOT_INITIALIZED;
}
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
AutoPlaceholderBatch beginBatching(this);
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this,
EditSubAction::eInsertParagraphSeparator,
nsIEditor::eNext);
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
EditSubActionInfo subActionInfo(EditSubAction::eInsertParagraphSeparator);
subActionInfo.maxLength = mMaxTextLength;
bool cancel, handled;
nsresult rv = rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
if (NS_WARN_IF(NS_FAILED(rv))) {
// XXX DidDoAction() won't be called when WillDoAction() returns error.
// Perhaps, we should move the code between WillDoAction() and
// DidDoAction() to a new method and guarantee that DidDoAction() is
// always called after WillDoAction().
return rv;
}
if (!cancel && !handled) {
// get the (collapsed) selection location
nsRange* firstRange = selection->GetRangeAt(0);
if (NS_WARN_IF(!firstRange)) {
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint pointToInsert(firstRange->StartRef());
if (NS_WARN_IF(!pointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
}
MOZ_ASSERT(pointToInsert.IsSetAndValid());
// don't put text in places that can't have it
if (!pointToInsert.IsInTextNode() &&
!CanContainTag(*pointToInsert.GetContainer(),
*nsGkAtoms::textTagName)) {
return NS_ERROR_FAILURE;
}
// we need to get the doc
nsCOMPtr<nsIDocument> doc = GetDocument();
if (NS_WARN_IF(!doc)) {
return NS_ERROR_NOT_INITIALIZED;
}
// don't change my selection in subtransactions
AutoTransactionsConserveSelection dontChangeMySelection(*this);
// insert a linefeed character
EditorRawDOMPoint pointAfterInsertedLineBreak;
rv = InsertTextWithTransaction(*doc, NS_LITERAL_STRING("\n"), pointToInsert,
&pointAfterInsertedLineBreak);
if (NS_WARN_IF(!pointAfterInsertedLineBreak.IsSet())) {
rv = NS_ERROR_NULL_POINTER; // don't return here, so DidDoAction is called
}
if (NS_SUCCEEDED(rv)) {
// set the selection to the correct location
MOZ_ASSERT(!pointAfterInsertedLineBreak.GetChild(),
"After inserting text into a text node, pointAfterInsertedLineBreak."
"GetChild() should be nullptr");
rv = selection->Collapse(pointAfterInsertedLineBreak);
if (NS_SUCCEEDED(rv)) {
// see if we're at the end of the editor range
EditorRawDOMPoint endPoint = GetEndPoint(selection);
if (endPoint == pointAfterInsertedLineBreak) {
// SetInterlinePosition(true) means we want the caret to stick to the
// content on the "right". We want the caret to stick to whatever is
// past the break. This is because the break is on the same line we
// were on, but the next content will be on the following line.
selection->SetInterlinePosition(true, IgnoreErrors());
}
}
}
}
if (!cancel) {
// post-process, always called if WillInsertBreak didn't return cancel==true
rv = rules->DidDoAction(selection, subActionInfo, rv);
}
return rv;
}
nsresult
TextEditor::SetText(const nsAString& aString)
{
MOZ_ASSERT(aString.FindChar(static_cast<char16_t>('\r')) == kNotFound);
Bug 1467796 - part 2: Make autocomplete use new method TextEditor::ReplaceTextAsAction() which replaces all text with specified text r=m_kato InputEvent.inputType needs to distinguish whether inserting text is caused by insertText command or replaced by autocomplete or spellchecker. Therefore, nsTextEditorState::SetValue() cannot use TextEditor::InsertTextAsAction() nor TextEditor::DeleteSelectionAsAction(). This patch reuses TextEditor::SetText()'s slow path for the new method. Note that the new method uses EditSubAction::eInsertText as top level edit sub- action because specifying this improves undo/redo behavior. And also this patch modifies test_bug1368544.html. Oddly, only on Android, we get different result. After removing all text with setUserInput(""), TextEditor::DeleteSelectionAsSubAction() removes both text node and non-bogus <br> element from the anonymous-div element. However, only on Android, new <br> element is recreated. I've not understood where this difference comes from yet. MozReview-Commit-ID: GKNksctGik --HG-- rename : toolkit/content/tests/chrome/file_autocomplete_with_composition.js => toolkit/content/tests/chrome/file_editor_with_autocomplete.js rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_input.html => toolkit/content/tests/chrome/test_editor_for_input_with_autocomplete.html rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_textbox.xul => toolkit/content/tests/chrome/test_editor_for_textbox_with_autocomplete.xul extra : rebase_source : b90419d9e5a01e86f6e6418f8df002c91416acae
2018-07-03 13:25:52 +00:00
AutoPlaceholderBatch batch(this, nullptr);
nsresult rv = SetTextAsSubAction(aString);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
TextEditor::ReplaceTextAsAction(const nsAString& aString,
nsRange* aReplaceRange /* = nullptr */)
Bug 1467796 - part 2: Make autocomplete use new method TextEditor::ReplaceTextAsAction() which replaces all text with specified text r=m_kato InputEvent.inputType needs to distinguish whether inserting text is caused by insertText command or replaced by autocomplete or spellchecker. Therefore, nsTextEditorState::SetValue() cannot use TextEditor::InsertTextAsAction() nor TextEditor::DeleteSelectionAsAction(). This patch reuses TextEditor::SetText()'s slow path for the new method. Note that the new method uses EditSubAction::eInsertText as top level edit sub- action because specifying this improves undo/redo behavior. And also this patch modifies test_bug1368544.html. Oddly, only on Android, we get different result. After removing all text with setUserInput(""), TextEditor::DeleteSelectionAsSubAction() removes both text node and non-bogus <br> element from the anonymous-div element. However, only on Android, new <br> element is recreated. I've not understood where this difference comes from yet. MozReview-Commit-ID: GKNksctGik --HG-- rename : toolkit/content/tests/chrome/file_autocomplete_with_composition.js => toolkit/content/tests/chrome/file_editor_with_autocomplete.js rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_input.html => toolkit/content/tests/chrome/test_editor_for_input_with_autocomplete.html rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_textbox.xul => toolkit/content/tests/chrome/test_editor_for_textbox_with_autocomplete.xul extra : rebase_source : b90419d9e5a01e86f6e6418f8df002c91416acae
2018-07-03 13:25:52 +00:00
{
AutoPlaceholderBatch batch(this, nullptr);
// This should emulates inserting text for better undo/redo behavior.
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this, EditSubAction::eInsertText,
nsIEditor::eNext);
if (!aReplaceRange) {
nsresult rv = SetTextAsSubAction(aString);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
if (NS_WARN_IF(aString.IsEmpty() && aReplaceRange->Collapsed())) {
return NS_OK;
}
// Note that do not notify selectionchange caused by selecting all text
// because it's preparation of our delete implementation so web apps
// shouldn't receive such selectionchange before the first mutation.
AutoUpdateViewBatch preventSelectionChangeEvent(this);
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
// Select the range but as far as possible, we should not create new range
// even if it's part of special Selection.
nsresult rv = selection->RemoveAllRangesTemporarily();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
ErrorResult error;
selection->AddRange(*aReplaceRange, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
rv = ReplaceSelectionAsSubAction(aString);
Bug 1467796 - part 2: Make autocomplete use new method TextEditor::ReplaceTextAsAction() which replaces all text with specified text r=m_kato InputEvent.inputType needs to distinguish whether inserting text is caused by insertText command or replaced by autocomplete or spellchecker. Therefore, nsTextEditorState::SetValue() cannot use TextEditor::InsertTextAsAction() nor TextEditor::DeleteSelectionAsAction(). This patch reuses TextEditor::SetText()'s slow path for the new method. Note that the new method uses EditSubAction::eInsertText as top level edit sub- action because specifying this improves undo/redo behavior. And also this patch modifies test_bug1368544.html. Oddly, only on Android, we get different result. After removing all text with setUserInput(""), TextEditor::DeleteSelectionAsSubAction() removes both text node and non-bogus <br> element from the anonymous-div element. However, only on Android, new <br> element is recreated. I've not understood where this difference comes from yet. MozReview-Commit-ID: GKNksctGik --HG-- rename : toolkit/content/tests/chrome/file_autocomplete_with_composition.js => toolkit/content/tests/chrome/file_editor_with_autocomplete.js rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_input.html => toolkit/content/tests/chrome/test_editor_for_input_with_autocomplete.html rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_textbox.xul => toolkit/content/tests/chrome/test_editor_for_textbox_with_autocomplete.xul extra : rebase_source : b90419d9e5a01e86f6e6418f8df002c91416acae
2018-07-03 13:25:52 +00:00
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
TextEditor::SetTextAsSubAction(const nsAString& aString)
{
MOZ_ASSERT(mPlaceholderBatch);
if (NS_WARN_IF(!mRules)) {
return NS_ERROR_NOT_INITIALIZED;
}
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this, EditSubAction::eSetText,
nsIEditor::eNext);
// pre-process
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_NULL_POINTER;
}
EditSubActionInfo subActionInfo(EditSubAction::eSetText);
subActionInfo.inString = &aString;
subActionInfo.maxLength = mMaxTextLength;
bool cancel;
bool handled;
nsresult rv =
rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (cancel) {
return NS_OK;
}
if (!handled) {
Bug 1467796 - part 2: Make autocomplete use new method TextEditor::ReplaceTextAsAction() which replaces all text with specified text r=m_kato InputEvent.inputType needs to distinguish whether inserting text is caused by insertText command or replaced by autocomplete or spellchecker. Therefore, nsTextEditorState::SetValue() cannot use TextEditor::InsertTextAsAction() nor TextEditor::DeleteSelectionAsAction(). This patch reuses TextEditor::SetText()'s slow path for the new method. Note that the new method uses EditSubAction::eInsertText as top level edit sub- action because specifying this improves undo/redo behavior. And also this patch modifies test_bug1368544.html. Oddly, only on Android, we get different result. After removing all text with setUserInput(""), TextEditor::DeleteSelectionAsSubAction() removes both text node and non-bogus <br> element from the anonymous-div element. However, only on Android, new <br> element is recreated. I've not understood where this difference comes from yet. MozReview-Commit-ID: GKNksctGik --HG-- rename : toolkit/content/tests/chrome/file_autocomplete_with_composition.js => toolkit/content/tests/chrome/file_editor_with_autocomplete.js rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_input.html => toolkit/content/tests/chrome/test_editor_for_input_with_autocomplete.html rename : toolkit/content/tests/chrome/test_autocomplete_with_composition_on_textbox.xul => toolkit/content/tests/chrome/test_editor_for_textbox_with_autocomplete.xul extra : rebase_source : b90419d9e5a01e86f6e6418f8df002c91416acae
2018-07-03 13:25:52 +00:00
// Note that do not notify selectionchange caused by selecting all text
// because it's preparation of our delete implementation so web apps
// shouldn't receive such selectionchange before the first mutation.
AutoUpdateViewBatch preventSelectionChangeEvent(this);
// We want to select trailing BR node to remove all nodes to replace all,
// but TextEditor::SelectEntireDocument doesn't select that BR node.
if (rules->DocumentIsEmpty()) {
// if it's empty, don't select entire doc - that would select
// the bogus node
Element* rootElement = GetRoot();
if (NS_WARN_IF(!rootElement)) {
return NS_ERROR_FAILURE;
}
rv = selection->Collapse(rootElement, 0);
} else {
rv = EditorBase::SelectEntireDocument(selection);
}
if (NS_SUCCEEDED(rv)) {
rv = ReplaceSelectionAsSubAction(aString);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"Failed to replace selection with new string");
}
}
// post-process
return rules->DidDoAction(selection, subActionInfo, rv);
}
nsresult
TextEditor::ReplaceSelectionAsSubAction(const nsAString& aString)
{
if (aString.IsEmpty()) {
nsresult rv = DeleteSelectionAsSubAction(eNone, eStrip);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult rv = InsertTextAsSubAction(aString);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
bool
TextEditor::EnsureComposition(WidgetCompositionEvent& aCompositionEvent)
{
if (mComposition) {
return true;
}
// The compositionstart event must cause creating new TextComposition
// instance at being dispatched by IMEStateManager.
mComposition = IMEStateManager::GetTextCompositionFor(&aCompositionEvent);
if (!mComposition) {
// However, TextComposition may be committed before the composition
// event comes here.
return false;
}
mComposition->StartHandlingComposition(this);
return true;
}
nsresult
TextEditor::OnCompositionStart(WidgetCompositionEvent& aCompositionStartEvent)
{
if (NS_WARN_IF(mComposition)) {
return NS_OK;
}
if (IsPasswordEditor()) {
if (NS_WARN_IF(!mRules)) {
return NS_ERROR_FAILURE;
}
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
rules->ResetIMETextPWBuf();
}
EnsureComposition(aCompositionStartEvent);
NS_WARNING_ASSERTION(mComposition, "Failed to get TextComposition instance?");
return NS_OK;
}
nsresult
TextEditor::OnCompositionChange(WidgetCompositionEvent& aCompsitionChangeEvent)
{
MOZ_ASSERT(aCompsitionChangeEvent.mMessage == eCompositionChange,
"The event should be eCompositionChange");
if (!EnsureComposition(aCompsitionChangeEvent)) {
return NS_OK;
}
nsIPresShell* presShell = GetPresShell();
if (NS_WARN_IF(!presShell)) {
return NS_ERROR_NOT_INITIALIZED;
}
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
// NOTE: TextComposition should receive selection change notification before
// CompositionChangeEventHandlingMarker notifies TextComposition of the
// end of handling compositionchange event because TextComposition may
// need to ignore selection changes caused by composition. Therefore,
// CompositionChangeEventHandlingMarker must be destroyed after a call
// of NotifiyEditorObservers(eNotifyEditorObserversOfEnd) or
// NotifiyEditorObservers(eNotifyEditorObserversOfCancel) which notifies
// TextComposition of a selection change.
MOZ_ASSERT(!mPlaceholderBatch,
"UpdateIMEComposition() must be called without place holder batch");
TextComposition::CompositionChangeEventHandlingMarker
compositionChangeEventHandlingMarker(mComposition, &aCompsitionChangeEvent);
RefPtr<nsCaret> caretP = presShell->GetCaret();
nsresult rv;
{
AutoPlaceholderBatch batch(this, nsGkAtoms::IMETxnName);
MOZ_ASSERT(mIsInEditSubAction,
"AutoPlaceholderBatch should've notified the observes of before-edit");
rv = InsertTextAsSubAction(aCompsitionChangeEvent.mData);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"Failed to insert new composition string");
if (caretP) {
caretP->SetSelection(selection);
}
}
// If still composing, we should fire input event via observer.
// Note that if the composition will be committed by the following
// compositionend event, we don't need to notify editor observes of this
// change.
// NOTE: We must notify after the auto batch will be gone.
if (!aCompsitionChangeEvent.IsFollowedByCompositionEnd()) {
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
}
return rv;
}
void
TextEditor::OnCompositionEnd(WidgetCompositionEvent& aCompositionEndEvent)
{
if (NS_WARN_IF(!mComposition)) {
return;
}
// commit the IME transaction..we can get at it via the transaction mgr.
// Note that this means IME won't work without an undo stack!
if (mTransactionManager) {
nsCOMPtr<nsITransaction> txn = mTransactionManager->PeekUndoStack();
nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryInterface(txn);
if (plcTxn) {
DebugOnly<nsresult> rv = plcTxn->Commit();
NS_ASSERTION(NS_SUCCEEDED(rv),
"nsIAbsorbingTransaction::Commit() failed");
}
}
// Composition string may have hidden the caret. Therefore, we need to
// cancel it here.
HideCaret(false);
// FYI: mComposition still keeps storing container text node of committed
// string, its offset and length. However, they will be invalidated
// soon since its Destroy() will be called by IMEStateManager.
mComposition->EndHandlingComposition(this);
mComposition = nullptr;
// notify editor observers of action
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
}
already_AddRefed<nsIContent>
TextEditor::GetInputEventTargetContent()
{
nsCOMPtr<nsIContent> target = do_QueryInterface(mEventTarget);
return target.forget();
}
nsresult
TextEditor::IsEmpty(bool* aIsEmpty) const
{
if (NS_WARN_IF(!mRules)) {
return NS_ERROR_NOT_INITIALIZED;
}
*aIsEmpty = true;
if (mRules->HasBogusNode()) {
return NS_OK;
}
// Even if there is no bogus node, we should be detected as empty editor
// if all the children are text nodes and these have no content.
Element* rootElement = GetRoot();
if (!rootElement) {
// XXX Why don't we return an error in such case??
return NS_OK;
}
for (nsIContent* child = rootElement->GetFirstChild();
child; child = child->GetNextSibling()) {
if (!EditorBase::IsTextNode(child) ||
static_cast<nsTextNode*>(child)->TextDataLength()) {
*aIsEmpty = false;
return NS_OK;
}
}
return NS_OK;
}
NS_IMETHODIMP
TextEditor::GetDocumentIsEmpty(bool* aDocumentIsEmpty)
{
nsresult rv = IsEmpty(aDocumentIsEmpty);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
TextEditor::GetTextLength(int32_t* aCount)
{
MOZ_ASSERT(aCount);
// initialize out params
*aCount = 0;
// special-case for empty document, to account for the bogus node
bool isEmpty = false;
nsresult rv = IsEmpty(&isEmpty);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (isEmpty) {
return NS_OK;
}
Element* rootElement = GetRoot();
if (NS_WARN_IF(!rootElement)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
uint32_t totalLength = 0;
iter->Init(rootElement);
for (; !iter->IsDone(); iter->Next()) {
nsCOMPtr<nsINode> currentNode = iter->GetCurrentNode();
if (IsTextNode(currentNode) && IsEditable(currentNode)) {
totalLength += currentNode->Length();
}
}
*aCount = totalLength;
return NS_OK;
}
NS_IMETHODIMP
TextEditor::GetWrapWidth(int32_t* aWrapColumn)
{
if (NS_WARN_IF(!aWrapColumn)) {
return NS_ERROR_INVALID_ARG;
}
*aWrapColumn = WrapWidth();
return NS_OK;
}
//
// See if the style value includes this attribute, and if it does,
// cut out everything from the attribute to the next semicolon.
//
static void CutStyle(const char* stylename, nsString& styleValue)
{
// Find the current wrapping type:
int32_t styleStart = styleValue.Find(stylename, true);
if (styleStart >= 0) {
int32_t styleEnd = styleValue.Find(";", false, styleStart);
if (styleEnd > styleStart) {
styleValue.Cut(styleStart, styleEnd - styleStart + 1);
} else {
styleValue.Cut(styleStart, styleValue.Length() - styleStart);
}
}
}
NS_IMETHODIMP
TextEditor::SetWrapWidth(int32_t aWrapColumn)
{
SetWrapColumn(aWrapColumn);
// Make sure we're a plaintext editor, otherwise we shouldn't
// do the rest of this.
if (!IsPlaintextEditor()) {
return NS_OK;
}
// Ought to set a style sheet here ...
// Probably should keep around an mPlaintextStyleSheet for this purpose.
dom::Element *rootElement = GetRoot();
NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER);
// Get the current style for this root element:
nsAutoString styleValue;
rootElement->GetAttr(kNameSpaceID_None, nsGkAtoms::style, styleValue);
// We'll replace styles for these values:
CutStyle("white-space", styleValue);
CutStyle("width", styleValue);
CutStyle("font-family", styleValue);
// If we have other style left, trim off any existing semicolons
// or whitespace, then add a known semicolon-space:
if (!styleValue.IsEmpty()) {
styleValue.Trim("; \t", false, true);
styleValue.AppendLiteral("; ");
}
// Make sure we have fixed-width font. This should be done for us,
// but it isn't, see bug 22502, so we have to add "font: -moz-fixed;".
// Only do this if we're wrapping.
if (IsWrapHackEnabled() && aWrapColumn >= 0) {
styleValue.AppendLiteral("font-family: -moz-fixed; ");
}
// and now we're ready to set the new whitespace/wrapping style.
if (aWrapColumn > 0) {
// Wrap to a fixed column.
styleValue.AppendLiteral("white-space: pre-wrap; width: ");
styleValue.AppendInt(aWrapColumn);
styleValue.AppendLiteral("ch;");
} else if (!aWrapColumn) {
styleValue.AppendLiteral("white-space: pre-wrap;");
} else {
styleValue.AppendLiteral("white-space: pre;");
}
return rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleValue, true);
}
NS_IMETHODIMP
TextEditor::SetWrapColumn(int32_t aWrapColumn)
{
mWrapColumn = aWrapColumn;
return NS_OK;
}
NS_IMETHODIMP
TextEditor::GetNewlineHandling(int32_t* aNewlineHandling)
{
NS_ENSURE_ARG_POINTER(aNewlineHandling);
*aNewlineHandling = mNewlineHandling;
return NS_OK;
}
NS_IMETHODIMP
TextEditor::SetNewlineHandling(int32_t aNewlineHandling)
{
mNewlineHandling = aNewlineHandling;
return NS_OK;
}
NS_IMETHODIMP
TextEditor::Undo(uint32_t aCount)
{
// If we don't have transaction in the undo stack, we shouldn't notify
// anybody of trying to undo since it's not useful notification but we
// need to pay some runtime cost.
if (!CanUndo()) {
return NS_OK;
}
// If there is composition, we shouldn't allow to undo with committing
// composition since Chrome doesn't allow it and it doesn't make sense
// because committing composition causes one transaction and Undo(1)
// undoes the committing composition.
if (GetComposition()) {
return NS_OK;
}
// Protect the edit rules object from dying.
RefPtr<TextEditRules> rules(mRules);
AutoUpdateViewBatch beginViewBatching(this);
NotifyEditorObservers(eNotifyEditorObserversOfBefore);
if (NS_WARN_IF(!CanUndo()) || NS_WARN_IF(Destroyed())) {
return NS_ERROR_FAILURE;
}
nsresult rv;
{
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this, EditSubAction::eUndo,
nsIEditor::eNone);
EditSubActionInfo subActionInfo(EditSubAction::eUndo);
RefPtr<Selection> selection = GetSelection();
bool cancel, handled;
rv = rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(rv)) {
RefPtr<TransactionManager> transactionManager(mTransactionManager);
for (uint32_t i = 0; i < aCount; ++i) {
rv = transactionManager->Undo();
if (NS_WARN_IF(NS_FAILED(rv))) {
break;
}
DoAfterUndoTransaction();
}
rv = rules->DidDoAction(selection, subActionInfo, rv);
}
}
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
return rv;
}
NS_IMETHODIMP
TextEditor::Redo(uint32_t aCount)
{
// If we don't have transaction in the redo stack, we shouldn't notify
// anybody of trying to redo since it's not useful notification but we
// need to pay some runtime cost.
if (!CanRedo()) {
return NS_OK;
}
// If there is composition, we shouldn't allow to redo with committing
// composition since Chrome doesn't allow it and it doesn't make sense
// because committing composition causes removing all transactions from
// the redo queue. So, it becomes impossible to redo anything.
if (GetComposition()) {
return NS_OK;
}
// Protect the edit rules object from dying.
RefPtr<TextEditRules> rules(mRules);
AutoUpdateViewBatch beginViewBatching(this);
NotifyEditorObservers(eNotifyEditorObserversOfBefore);
if (NS_WARN_IF(!CanRedo()) || NS_WARN_IF(Destroyed())) {
return NS_ERROR_FAILURE;
}
nsresult rv;
{
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this, EditSubAction::eRedo,
nsIEditor::eNone);
EditSubActionInfo subActionInfo(EditSubAction::eRedo);
RefPtr<Selection> selection = GetSelection();
bool cancel, handled;
rv = rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
if (!cancel && NS_SUCCEEDED(rv)) {
RefPtr<TransactionManager> transactionManager(mTransactionManager);
for (uint32_t i = 0; i < aCount; ++i) {
nsresult rv = transactionManager->Redo();
if (NS_WARN_IF(NS_FAILED(rv))) {
break;
}
DoAfterRedoTransaction();
}
rv = rules->DidDoAction(selection, subActionInfo, rv);
}
}
NotifyEditorObservers(eNotifyEditorObserversOfEnd);
return rv;
}
bool
TextEditor::CanCutOrCopy(PasswordFieldAllowed aPasswordFieldAllowed)
{
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
if (!selection) {
return false;
}
if (aPasswordFieldAllowed == ePasswordFieldNotAllowed &&
IsPasswordEditor()) {
return false;
}
return !selection->IsCollapsed();
}
bool
TextEditor::FireClipboardEvent(EventMessage aEventMessage,
int32_t aSelectionType,
bool* aActionTaken)
{
if (aEventMessage == ePaste) {
CommitComposition();
}
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
NS_ENSURE_TRUE(presShell, false);
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
if (!selection) {
return false;
}
if (!nsCopySupport::FireClipboardEvent(aEventMessage, aSelectionType,
presShell, selection, aActionTaken)) {
return false;
}
// If the event handler caused the editor to be destroyed, return false.
// Otherwise return true to indicate that the event was not cancelled.
return !mDidPreDestroy;
}
NS_IMETHODIMP
TextEditor::Cut()
{
bool actionTaken = false;
if (FireClipboardEvent(eCut, nsIClipboard::kGlobalClipboard, &actionTaken)) {
// XXX This transaction name is referred by PlaceholderTransaction::Merge()
// so that we need to keep using it here.
AutoPlaceholderBatch batch(this, nsGkAtoms::DeleteTxnName);
DeleteSelectionAsSubAction(eNone, eStrip);
}
return actionTaken ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
TextEditor::CanCut(bool* aCanCut)
{
NS_ENSURE_ARG_POINTER(aCanCut);
// Cut is always enabled in HTML documents
nsCOMPtr<nsIDocument> doc = GetDocument();
*aCanCut = (doc && doc->IsHTMLOrXHTML()) ||
(IsModifiable() && CanCutOrCopy(ePasswordFieldNotAllowed));
return NS_OK;
}
NS_IMETHODIMP
TextEditor::Copy()
{
bool actionTaken = false;
FireClipboardEvent(eCopy, nsIClipboard::kGlobalClipboard, &actionTaken);
return actionTaken ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
TextEditor::CanCopy(bool* aCanCopy)
{
NS_ENSURE_ARG_POINTER(aCanCopy);
// Copy is always enabled in HTML documents
nsCOMPtr<nsIDocument> doc = GetDocument();
*aCanCopy = (doc && doc->IsHTMLOrXHTML()) ||
CanCutOrCopy(ePasswordFieldNotAllowed);
return NS_OK;
}
NS_IMETHODIMP
TextEditor::CanDelete(bool* aCanDelete)
{
NS_ENSURE_ARG_POINTER(aCanDelete);
*aCanDelete = IsModifiable() && CanCutOrCopy(ePasswordFieldAllowed);
return NS_OK;
}
already_AddRefed<nsIDocumentEncoder>
TextEditor::GetAndInitDocEncoder(const nsAString& aFormatType,
uint32_t aDocumentEncoderFlags,
const nsACString& aCharset) const
{
nsCOMPtr<nsIDocumentEncoder> docEncoder;
if (!mCachedDocumentEncoder ||
!mCachedDocumentEncoderType.Equals(aFormatType)) {
nsAutoCString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
LossyAppendUTF16toASCII(aFormatType, formatType);
docEncoder = do_CreateInstance(formatType.get());
if (NS_WARN_IF(!docEncoder)) {
return nullptr;
}
mCachedDocumentEncoder = docEncoder;
mCachedDocumentEncoderType = aFormatType;
} else {
docEncoder = mCachedDocumentEncoder;
}
nsCOMPtr<nsIDocument> doc = GetDocument();
NS_ASSERTION(doc, "Need a document");
nsresult rv =
docEncoder->NativeInit(
doc, aFormatType,
aDocumentEncoderFlags |
nsIDocumentEncoder::RequiresReinitAfterOutput);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
if (!aCharset.IsEmpty() && !aCharset.EqualsLiteral("null")) {
docEncoder->SetCharset(aCharset);
}
int32_t wrapWidth = WrapWidth();
if (wrapWidth >= 0) {
Unused << docEncoder->SetWrapColumn(wrapWidth);
}
// Set the selection, if appropriate.
// We do this either if the OutputSelectionOnly flag is set,
// in which case we use our existing selection ...
if (aDocumentEncoderFlags & nsIDocumentEncoder::OutputSelectionOnly) {
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return nullptr;
}
rv = docEncoder->SetSelection(selection);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
}
// ... or if the root element is not a body,
// in which case we set the selection to encompass the root.
else {
dom::Element* rootElement = GetRoot();
if (NS_WARN_IF(!rootElement)) {
return nullptr;
}
if (!rootElement->IsHTMLElement(nsGkAtoms::body)) {
rv = docEncoder->SetContainerNode(rootElement);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
}
}
return docEncoder.forget();
}
NS_IMETHODIMP
TextEditor::OutputToString(const nsAString& aFormatType,
uint32_t aDocumentEncoderFlags,
nsAString& aOutputString)
{
return ComputeValueInternal(aFormatType, aDocumentEncoderFlags,
aOutputString);
}
nsresult
TextEditor::ComputeValueInternal(const nsAString& aFormatType,
uint32_t aDocumentEncoderFlags,
nsAString& aOutputString) const
{
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
EditSubActionInfo subActionInfo(EditSubAction::eComputeTextToOutput);
subActionInfo.outString = &aOutputString;
subActionInfo.flags = aDocumentEncoderFlags;
subActionInfo.outputFormat = &aFormatType;
Selection* selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
bool cancel, handled;
nsresult rv =
rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
if (cancel || NS_FAILED(rv)) {
return rv;
}
if (handled) {
// This case will get triggered by password fields or single text node only.
return rv;
}
nsAutoCString charset;
rv = GetDocumentCharsetInternal(charset);
if (NS_FAILED(rv) || charset.IsEmpty()) {
charset.AssignLiteral("windows-1252");
}
nsCOMPtr<nsIDocumentEncoder> encoder =
GetAndInitDocEncoder(aFormatType, aDocumentEncoderFlags, charset);
if (NS_WARN_IF(!encoder)) {
return NS_ERROR_FAILURE;
}
// XXX Why don't we call TextEditRules::DidDoAction() here?
return encoder->EncodeToString(aOutputString);
}
nsresult
TextEditor::PasteAsQuotationAsAction(int32_t aClipboardType,
bool aDispatchPasteEvent)
{
MOZ_ASSERT(aClipboardType == nsIClipboard::kGlobalClipboard ||
aClipboardType == nsIClipboard::kSelectionClipboard);
// Get Clipboard Service
nsresult rv;
nsCOMPtr<nsIClipboard> clipboard =
do_GetService("@mozilla.org/widget/clipboard;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// XXX Why don't we dispatch ePaste event here?
// Get the nsITransferable interface for getting the data from the clipboard
nsCOMPtr<nsITransferable> trans;
rv = PrepareTransferable(getter_AddRefs(trans));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (!trans) {
return NS_OK;
}
// 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;
}
nsresult
TextEditor::InsertWithQuotationsAsSubAction(const nsAString& aQuotedText)
{
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
// Let the citer quote it for us:
nsString quotedStuff;
nsresult rv = InternetCiter::GetCiteString(aQuotedText, quotedStuff);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// It's best to put a blank line after the quoted text so that mails
// written without thinking won't be so ugly.
if (!aQuotedText.IsEmpty() && (aQuotedText.Last() != char16_t('\n'))) {
quotedStuff.Append(char16_t('\n'));
}
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
return NS_ERROR_FAILURE;
}
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
*this, EditSubAction::eInsertText,
nsIEditor::eNext);
// XXX This WillDoAction() usage is hacky. If it returns as handled,
// this method cannot work as expected. So, this should have specific
// sub-action rather than using eInsertElement.
EditSubActionInfo subActionInfo(EditSubAction::eInsertElement);
bool cancel, handled;
rv = rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (cancel) {
return NS_OK; // Rules canceled the operation.
}
MOZ_ASSERT(!handled, "WillDoAction() shouldn't handle in this case");
if (!handled) {
rv = InsertTextAsSubAction(quotedStuff);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// XXX Why don't we call TextEditRules::DidDoAction()?
return NS_OK;
}
nsresult
TextEditor::SharedOutputString(uint32_t aFlags,
bool* aIsCollapsed,
nsAString& aResult)
{
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 05:24:48 +00:00
RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED);
*aIsCollapsed = selection->IsCollapsed();
if (!*aIsCollapsed) {
aFlags |= nsIDocumentEncoder::OutputSelectionOnly;
}
// If the selection isn't collapsed, we'll use the whole document.
return ComputeValueInternal(NS_LITERAL_STRING("text/plain"), aFlags, aResult);
}
void
TextEditor::OnStartToHandleTopLevelEditSubAction(
EditSubAction aEditSubAction,
nsIEditor::EDirection aDirection)
{
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
EditorBase::OnStartToHandleTopLevelEditSubAction(aEditSubAction, aDirection);
if (!rules) {
return;
}
MOZ_ASSERT(mTopLevelEditSubAction == aEditSubAction);
MOZ_ASSERT(mDirection == aDirection);
DebugOnly<nsresult> rv =
rules->BeforeEdit(mTopLevelEditSubAction, mDirection);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"TextEditRules::BeforeEdit() failed to handle something");
}
void
TextEditor::OnEndHandlingTopLevelEditSubAction()
{
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
// post processing
DebugOnly<nsresult> rv =
rules ? rules->AfterEdit(mTopLevelEditSubAction, mDirection) : NS_OK;
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"TextEditRules::AfterEdit() failed to handle something");
EditorBase::OnEndHandlingTopLevelEditSubAction();
MOZ_ASSERT(!mTopLevelEditSubAction);
MOZ_ASSERT(mDirection == eNone);
}
nsresult
TextEditor::SelectEntireDocument(Selection* aSelection)
{
if (!aSelection || !mRules) {
return NS_ERROR_NULL_POINTER;
}
// Protect the edit rules object from dying
RefPtr<TextEditRules> rules(mRules);
// is doc empty?
if (rules->DocumentIsEmpty()) {
// get root node
Element* rootElement = GetRoot();
if (NS_WARN_IF(!rootElement)) {
return NS_ERROR_FAILURE;
}
// if it's empty don't select entire doc - that would select the bogus node
return aSelection->Collapse(rootElement, 0);
}
SelectionBatcher selectionBatcher(aSelection);
nsresult rv = EditorBase::SelectEntireDocument(aSelection);
NS_ENSURE_SUCCESS(rv, rv);
// Don't select the trailing BR node if we have one
nsCOMPtr<nsIContent> childNode;
rv = GetEndChildNode(aSelection, getter_AddRefs(childNode));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (childNode) {
childNode = childNode->GetPreviousSibling();
}
if (childNode && TextEditUtils::IsMozBR(childNode)) {
int32_t parentOffset;
nsINode* parentNode = GetNodeLocation(childNode, &parentOffset);
return aSelection->Extend(parentNode, parentOffset);
}
return NS_OK;
}
EventTarget*
TextEditor::GetDOMEventTarget()
{
return mEventTarget;
}
nsresult
TextEditor::SetAttributeOrEquivalent(Element* aElement,
nsAtom* aAttribute,
const nsAString& aValue,
bool aSuppressTransaction)
{
if (NS_WARN_IF(!aElement) || NS_WARN_IF(!aAttribute)) {
return NS_ERROR_INVALID_ARG;
}
return SetAttributeWithTransaction(*aElement, *aAttribute, aValue);
}
nsresult
TextEditor::RemoveAttributeOrEquivalent(Element* aElement,
nsAtom* aAttribute,
bool aSuppressTransaction)
{
if (NS_WARN_IF(!aElement) || NS_WARN_IF(!aAttribute)) {
return NS_ERROR_INVALID_ARG;
}
return RemoveAttributeWithTransaction(*aElement, *aAttribute);
}
} // namespace mozilla