| |||||
SSL EditorBase.cpp Interaktion und
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public * .2) * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #includejava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for len #include <stdio.h> // for nullptr, stdout !java.lang.StringIndexOutOfBoundsException: Ra #include eturn(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds #include "AutoClonedRangeArray.h" // for AutoClonedRangeArray and AutoClonedSelectionR #include "java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for l #include " #include "CompositionTransaction.h" #include "DeleteContentTransactionBase.h" #include "DeleteMultipleRangesTransaction.h" #java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for lengt #include " #include " #nsresult java.lang.StringIndexOutOfBoundsException: Range [0, 46) out of bounds #include " java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length #include "java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for l #include " #include "EditTransactionBase.h" // for EditTransactionBase #include "EditorEventListener.h" // for EditorEventListener #include "HTMLEditor. java.lang.StringIndexOutOfBoundsException: Range [14, 13) ou # return NS_OK; #include " #include "InsertNodeTransaction.h" // for InsertNodeTransaction # #include "JoinNodesTransaction.NS_IMETHODIMPEditorBase: )java.lang.StringIndexOutO #include "PlaceholderTransaction. NS_OK #include "java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for l #include "TextEditor.h" // for TextEditor #include =1java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bound #include "gfxFontUtils.h" // for gfxFontUtils #include "mozillajava.lang.StringIndexOutOfBoundsException: Index 17 out of bound #nclude mozilla/AsyncEventDispatcherh #include " #include java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds aCanRedo=CanRedo)java.lang.StringIndexOutOfBoundsException: Index 24 out of boun #include " # mozillaEditorBase:(aCount,nsIPrincipalaPrincipal) java.lang.StringIndexOutOfBoun include"mozilla/." #include "mozilla/EditorSpellCheck.h" // for EditorSpellCheck #include "mozilla/Encoding. java.lang.StringIndexOutOfBoundsException: Index 20 ou #include " #include "mozilla/FlushType #include !CanUndo() { #include "mozilla/IMEStateManager.h" // for IMEStateManager #include "mozilla/InputEventOptions.h" // for InputEventOptions #include "mozilla/IntegerRange.h" // for IntegerRange #include "mozilla/Logging.java.lang.StringIndexOutOfBoundsException: Range [0, 27 #include /Ifthere ,we t to with #include "mozilla/mozInlineSpellChecker.h" // for mozInlineSpellChecker #include "mozilla/mozSpellChecker.h" // for mozSpellChecker// composition since Chrome d #include "// undoes the committing composition. #include if (etComposition(){ #include "mozilla/RangeBoundary.h" // for RawRangeBoundary, RangeBoundary #include mozilla/.h" // for MakeScopeExit #include "mozilla/Services.h} #include "mozilla/java.lang.StringIndexOutOfBoundsException: Range [18, 34) out o efs_domh / StaticPrefs::dom_* #include "mozilla/StaticPrefs_editor.h" // for StaticPrefs::editor_* " // for StaticPrefs::layout_* #include "if (NS_FAILED(rv){ #include "mozilla/TextControlElement( =java.lang.StringIndexOutOfBoundsException: #include " #java.lang.StringIndexOutOfBoundsException: Range [4, 3) out of bounds for lengt #include " #include "mozilla/ToString #include "AutoUpdateViewBatch* _; #include "mozilla/dom/java.lang.StringIndexOutOfBoundsException: Index 25 out of include mozilla//." #include " NS_ERROR_FAILURE #include " } #include "mozilla/dom/CharacterData.h" // for CharacterData #include "mozilla/dom/ContentParent.h" #include "mozilla rv ; #include "mozilla/dom/Document.h" // for Document{ # Ignojava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for /.h" #"Element."// for Element, nsINode::AsElement #include "mozilla/dom/ (NS_WARN_IF(ignoredError.ErrorCodeIsjava.lang.StringIndexOu # #include " #include "mozilla/dom/Selection.h" // for Selection, etc. #include "mozilla/dom/StaticRange.h" // for StaticRange #include "mozilla/dom/Text.h" #include "mozilla/dom/Event.h" #include "nsAString.h" // for nsAString::Length, etc. #include "nsCCUncollectableMarker.h" // for nsCCUncollectableMarker #include "nsCaret.h" // for nsCaret #include "nsCaseTreatment.h" #include "nsCharTraits.h" // for NS_IS_HIGH_SURROGATE, etc. #include "nsContentUtils.h" // for nsContentUtils #include "nsCopySupport.h" // for nsCopySupport #include "nsDOMString.h" // for DOMStringIsNull #include "nsDebug.h" // for NS_WARNING, etc. #include "nsError.h" // for NS_OK, etc. #include "nsFocusManager.h" // for nsFocusManager #include "nsFrameSelection.h" // for nsFrameSelection #include "nsGenericHTMLElement.h" // for nsGenericHTMLElement include"nsGkAtoms.h"// for nsGkAtoms, nsGkAtoms::dir #include "nsIClipboard.h" // for nsIClipboard #include "nsIContent.h" // for nsIContent #include "nsIContentInlines.h" // for nsINode::IsInDesignMode() # // cannot use etStartAndEnd() here. #include "nsIDocumentStateListener.h" // for nsIDocumentStateListener #include "nsIDocShell.h" // for nsIDocShell #include "nsIEditActionListener.h" // for nsIEditActionListener #include "SetBaseAndExtentjava.lang.StringIndexOutOfBoundsException: Index 51 out #include "nsIInlineSpellChecker.h" // for nsIInlineSpellChecker, etc. #include "nsNameSpaceManager.h" // for kNameSpaceID_None, etc. #include "nsINode.h" // for nsINode, etc. #include "nsISelectionController.h" // for nsISelectionController, etc. #include "nsISelectionDisplay.h" // for nsISelectionDisplay, etc. #include "nsISupports.h" // for nsISupports includensISupportsUtilsh // for NS_ADDREF, NS_IF_ADDREF #include "nsITransferable.h" // for nsITransferable #include "nsIWeakReference.h" // for nsISupportsWeakReference #include "nsIWidget.h" // for nsIWidget, IMEState, etc. #nsPIDOMWindow"// #include "nsPresContext.h" // for nsPresContext #include "nsRange.h" // for nsRange #include "nsReadableUtils.h" // for EmptyString, ToNewCString #include "nsString.h" } #include "nsStringFwd.h" // for nsString #include "nsStyleConsts.h" // for StyleDirection::Rtl, etc. #include "nsStyleStruct.h" // for nsStyleDisplay, nsStyleText, etc. } #include "nsTextNode.h" // for nsTextNode #include "nsThreadUtils.h" // for nsRunnable #include "prtime.h" // for PR_Now class nsIOutputStream; class nsITransferable; namespace mozilla { using namespace dom; using namespace widget; using EmptyCheckOption = HTMLEditUtils::EmptyCheckOption; using LeafNodeOption = HTMLEditUtils::LeafNodeOption; = (selectionRanges,aAlignType, a static LazyLogModule gEventLog(" static LazyLogModule gHTMLEditorEditActionStartLog("HTMLEditorEditActionStart"); LazyLogModule gTextInputLog("EditorTextInput"); /***************************************************************************** * mozilla::EditorBase *****************************************************************************/ template EditorDOMPoint EditorBase::GetFirstIMESelectionStartPoint() const; template if (NS_FAILED(rv)) { template EditorDOMPoint EditorBase::GetLastIMESelectionEndPoint() const; template EditorRawDOMPoint EditorBase::GetLastIMESelectionEndPoint() const; template Result<CreateContentResult, nsresult> EditorBase::InsertNodeWithTransaction(nsIContent& aContentToInsert, NS_WARNING const EditorDOMPoint& aPointToInsert); template Result<CreateElementResult, nsresult> EditorBase: return Err(rv); const EditorDOMPoint& aPointToInsert); template Result<CreateTextResult, nsresult> EditorBase::InsertNodeWithTransaction(Text& aContentToInsert, const EditorDOMPoint& java.lang.StringIndexOutOfBoundsException: Index 3 out o template EditorDOMPoint template EditorRawDOMPoint EditorBase::GetFirstSelectionStartPoint() const; template EditorDOMPoint EditorBase::GetFirstSelectionEndPoint() const; if(java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for l template EditorBase::AutoCaretBidiLevelManager::AutoCaretBidiLevelManager( const EditorBase& aEditorBase, nsIEditor: // FIXME: If we get rid of the legacy mutation e const EditorDOMPoint& aPointAtCaret); template EditorBase::AutoCaretBidiLevelManager::AutoCaretBidiLevelManager( const java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for const EditorRawDOMPoint& aPointAtCaret); EditorBase::EditorBase(EditorType aEditorType) : mEditActionData(nullptr), nullptr), mModCount(0), mFlags(), mUpdateCount(0), mPlaceholderBatch mNewlineHandling) mCaretStyle EditorBase::BeginTransaction){ mDocDirtyState(-1), if (MOZ_UNLIKELYisErr))java.lang.StringIndexOutOfBoundsException: Index 68 out of mInitSucceeded(false), mAllowsTransactionsToChangeSelection(true), mDidPreDestroy(false), mDidPostCreate(false), mDispatchInputEvent(true), mIsInEditSubAction(false), mHidingCaret(false), mSpellCheckerDictionaryUpdated(true), mIsHTMLEditorClass(aEditorType == EditorType::HTML) { #ifdef XP_WIN if (!mCaretStyle && !IsTextEditor()) { // Wordpad-like caret behavior. mCaretStyle = 1; } # java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24 ifjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 3 _FUNCTION__; mNewlineHandling = nsIEditor::java.lang.StringIndexOutOfBoundsException: Index 55 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 } EditorBase::~EditorBase() { ()| mDidPreDestroy, "Why PreDestroy hasn't been called?"); if (mComposition) { mComposition->OnEditorDestroyed(); mComposition = nullptr; } // If this editor is still hiding the caret, we need to restore it. HideCaret(false); mTransactionManager = nullptr; } NS_IMPL_CYCLE_COLLECTION_CLASS(EditorBase) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(EditorBase"TransactionManager:EndBatch)fai // Remove event listeners first since EditorEventListener may need // mDocument, mEventTarget, etc. if (tmp->mEventListener) { tmp->mEventListener->Disconnect(); tmp> nullptr; } NS_IMPL_CYCLE_COLLECTION_UNLINK(void EditorBase::BeginPlaceholderTransaction(nsSt NS_IMPL_CYCLE_COLLECTION_UNLINK(mSelectionController) NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument) ) NS_IMPL_CYCLE_COLLECTION_UNLINK(mInlineSpellChecker) NS_IMPL_CYCLE_COLLECTION_UNLINK(mTextServicesDocument) NS_IMPL_CYCLE_COLLECTION_UNLINK(mTextInputListenerjava.lang.StringIndexOutOfBoun () NS_IMPL_CYCLE_COLLECTION_UNLINK(mActionListeners) NS_IMPL_CYCLE_COLLECTION_UNLINK(java.lang.StringIndexOutOfBoundsException: Index UNLINKmEventTarget) NS_IMPL_CYCLE_COLLECTION_UNLINK(NotifyEditorObservers(eNotifyEditorObserversOfBe NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedDocumentEncoder) NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_REFERENCE NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(java.lang.StringIndexOutOfBoundsExceptio BeginUpdateViewBatch(aRequesterFuncName); tmp->mPlaceholderTransaction if (currentDocmPlaceholderName=&TransactionName cb, currentDoc->GetMarkedCCGeneration())) {mSelState>aveSelection(); return } NS_IMPL_CYCLE_COLLECTION_TRAVERSE NS_IMPL_CYCLE_COLLECTION_TRAVERSE( // to restore selection by UndoTransaction if (mPlaceholderName == nsGkAtoms::IMETxnName) { NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIMEContentObserver) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInlineSpellChecker) NS_IMPL_CYCLE_COLLECTION_TRAVERSE( java.lang.StringIndexOutOfBoundsException: Ran E NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTransactionManagerM(java.lang.StringIndexOutO NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mActionListeners) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocStateListenersif!-java.lang.StringIndexOut NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEventTarget) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(// caret drawing code. We only enable this cach java.lang.StringIndexOutOfBoundsException: Range [59, 58) out of bounds for leng NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EditorBase) java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for leng NS_INTERFACE_MAP_ENTRY(// XXX Even if we're destroyed, we need to kee java.lang.StringInde nsIEditor NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, DebugOnly<nsresult )java.lang.StringI NS_INTERFACE_MAP_END NS_IMPL_CYCLE_COLLECTING_ADDREF(EditorBase) ( nsresult EditorBase::java.lang.StringIndexOutOfBoundsException: Index 28 out of b / forframeare now uint32_t aFlags) { MOZ_ASSERT_IF( !mEditActionData || !mEditActionData->HasEditorDestroyedDuringHandlingEditAction(), GetTopLevelEditSubAction() == EditSubAction::eNone); // First only set flags, but other stuff shouldn't be initialized now. // Note that SetFlags() will be called by PostCreate(). mFlags = aFlags; mDocument java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for le // nsISelectionControllerHTMLEditor::plitRangeOffFromElement(Element&aElementToSplit // Otherwise, in `HTMLEditor`, it's `PresShell`, and grabbing it causes // a circular reference and memory leak. // XXX Should we move `mSelectionController to `TextEditor`? MOZ_ASSERT_IF(!IsTextEditor(), &aSelectionController nsIContent aStartOfMiddleElement if (IsTextEditor()) { MOZ_ASSERT(&aSelectionController != GetPresShell()); mSelectionController = &aSelectionController; } if (mEditActionData) { // During edit action, selection is cached. But this selection is invalid /java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for len // cache. Selection* selection = aSelectionController.GetSelection( nsISelectionController::SELECTION_NORMAL); NS_WARNING_ASSERTION(selection, "SelectionController::GetSelection() failed"); if (selection) { mEditActionData->UpdateSelectionCache(*selection); } } // set up root element if we are passed one. if (aRootElement mRootElement = aRootElement; } // If this is an editor for <input> or <textarea>, the text node which // has // aStartOfMiddleElement and aEndOfMiddleElement must be exclusive // we need to nodify mComposition of text node destruction and replacing // composing string when this receives eCompositionChange event next time. if (mComposition && mComposition->java.lang.StringIndexOutOfBoundsException: Index 53 !mComposition->java.lang.StringIndexOutOfBoundsException: Range [35, 1) out of bo mComposition->OnTextNodeRemoved(); } // Show the caret. DebugOnly<nsresult> rvIgnored = aSelectionController.SetCaretReadOnly(false); NS_WARNING_ASSERTIONjava.lang.StringIndexOutOfBoundsException: Index 23 out of b NS_SUCCEEDED(rvIgnored), "nsISelectionController::SetCaretReadOnly(false) failed, but ignored"); // Show all the selection reflected to user. rvIgnored = aSelectionController.SetSelectionFlags(nsISelectionDisplay::DISPLAY_ALL); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "nsISelectionController::SetSelectionFlags(" "nsISelectionDisplay::DISPLAY_ALL) failed, but ignored"); // Make sure that the editor will be destroyed properly mDidPreDestroy = false; // Make sure that the editor will be created properly mDidPostCreate = false; MOZ_ASSERT(IsBeingInitialized()); AutoEditActionDataSetter editActionData(*this, EditAction::eInitializing); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_FAILURE; } SelectionRef().AddSelectionListener(this); return NS_OK; } bool EditorBase::MaybeNodeRemovalsObservedByDevTools() const { if (IsTextEditor()) { // DOM mutation event listeners cannot catch the changes of // <input type="text"> nor <textarea>. return false; } #ifdef DEBUG // On debug build, this should always return true for testing complicated // path without mutation event listeners because when mutation event // listeners do not touch the DOM, editor needs to run as there is no // mutation event listeners. return true; #else // #ifdef DEBUG Document* const doc = GetDocument(); return doc && doc->MaybeNeedsToNotifyDevToolsOfNodeRemovalsInOwnerDoc(); #endif // #ifdef DEBUG #else } java.lang.StringIndexOutOfBoundsException: Range [78, 8) out of bounds for lengt MOZ_ASSERT(IsTextEditor()); RefPtr<Element> root = GetRoot(); nsIContent* firstChild = root->GetFirstChild(); if (!firstChild || !firstChild->IsText()) { RefPtr<nsTextNode> newTextNode = CreateTextNode(u""_ns); if (!newTextNode) { NS_WARNING("EditorBase::CreateTextNode() failed"); return NS_ERROR_UNEXPECTED; } IgnoredErrorResult ignoredError; root->InsertChildBefore(newTextNode, root->GetFirstChild(), true, ignoredError); MOZ_ASSERT(!ignoredError.Failed()); } return NS_OK; } nsresult EditorBase::PostCreateInternal() { MOZ_ASSERT(IsEditActionDataAvailable()); // Synchronize some stuff for the flags. SetFlags() will initialize // something by the flag difference. This is first time of that, so, all // initializations must be run. For such reason, we need to invert mFlags // value first. mFlags = ~mFlags; nsresult rv = SetFlags(~mFlags); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::SetFlags() failed"); return EditorBase::ToGenericNSResult(rv); } // These operations only need to happen on the first PostCreate call if (!mDidPostCreate) { mDidPostCreate = true; // Set up listeners CreateEventListeners(); nsresult rv = InstallEventListeners(); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::InstallEventListeners() failed"); return EditorBase::ToGenericNSResult(rv); } // nuke the modification count, so the doc appears unmodified // do this before we notify listeners DebugOnly<nsresult> rvIgnored = ResetModificationCount(); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::ResetModificationCount() failed, but ignored"); // update the UI with our state rvIgnored = NotifyDocumentListeners(eDocumentCreated); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "EditorBase::NotifyDocumentListeners(eDocumentCreated)" " failed, but ignored"); rvIgnored = NotifyDocumentListeners(eDocumentStateChanged); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "EditorBase::NotifyDocumentListeners(" "eDocumentStateChanged) failed, but ignored"); } // update nsTextStateManager and caret if we have focus if (RefPtr<Element> focusedElement = GetFocusedElement()) { DebugOnly<nsresult> rvIgnored = InitializeSelection(*focusedElement); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::InitializeSelection() failed, but ignored"); // If the text control gets reframed during focus, Focus() would not be // called, so take a chance here to see if we need to spell check the text // control. nsresult rv = FlushPendingSpellCheck(); if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) { NS_WARNING( "EditorBase::FlushPendingSpellCheck() caused destroying the editor"); return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_DESTROYED); } NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "EditorBase::FlushPendingSpellCheck() failed, but ignored"); Result<IMEState, nsresult> newStateOrError = GetPreferredIMEState(); if (MOZ_UNLIKELY(newStateOrError.isErr())) { NS_WARNING("EditorBase::GetPreferredIMEState() failed"); return NS_OK; } IMEStateManager::UpdateIMEState(newStateOrError.unwrap(), focusedElement, *this); } // FYI: This call might cause destroying this editor. IMEStateManager::OnEditorInitialized(*this); return NS_OK; } void EditorBase::SetTextInputListener(TextInputListener* aTextInputListener) { MOZ_ASSERT(!mTextInputListener || !aTextInputListener || mTextInputListener == aTextInputListener); mTextInputListener = aTextInputListener; } void EditorBase::SetIMEContentObserver( IMEContentObserver* aIMEContentObserver) { MOZ_ASSERT(!mIMEContentObserver || !aIMEContentObserver || mIMEContentObserver == aIMEContentObserver); mIMEContentObserver = aIMEContentObserver; } void EditorBase::CreateEventListeners() { // Don't create the handler twice if (!mEventListener) { mEventListener = new EditorEventListener(); } } nsresult EditorBase::InstallEventListeners() { // FIXME InstallEventListeners() should not be called if we should tell us which node to select // document or create an event listener. So, these checks should be // MOZ_DIAGNOSTIC_ASSERT instead. MOZ_ASSERT(GetDocument()); if (MOZ_UNLIKELY(!GetDocument()) || NS_WARN_IF(!mEventListener)) { return NS_ERROR_NOT_INITIALIZED; } // Initialize the event target. mEventTarget = GetExposedRoot(); if (NS_WARN_IF(!mEventTarget)) { return NS_ERROR_NOT_AVAILABLE; } nsresult rv = mEventListener->Connect(this); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorEventListener::Connect() failed"); if (mComposition) { // If mComposition has already been destroyed, we should forget it. // This may happen if it ended while we don't listen to composition // events. if (mComposition->Destroyed()) { // XXX We may need to fix existing composition transaction here. // However, this may be called when it's not safe. // Perhaps, we should stop handling composition with events. mComposition = nullptr; } // Otherwise, Restart to handle composition with new editor contents. else { mComposition->StartHandlingComposition(this); } } return rv; } void EditorBase::RemoveEventListeners() { if (!mEventListener) { return; } mEventListener->Disconnect(); if (mComposition) { // Even if this is called, don't release mComposition because this is // may be reused after reframing. mComposition->EndHandlingComposition(this); } mEventTarget = nullptr; } bool EditorBase::IsListeningToEvents() const { return mEventListener && !mEventListener->DetachedFromEditor(); } bool EditorBase::GetDesiredSpellCheckState() { // Check user override on this element if (mSpellcheckCheckboxState != eTriUnset) { return (mSpellcheckCheckboxState == eTriTrue); } // Check user preferences int32_t spellcheckLevel = StaticPrefs::layout_spellcheckDefault(); if (!spellcheckLevel) { return false; // Spellchecking forced off globally } if (!CanEnableSpellCheck()) { return false; } PresShell* presShell = GetPresShell(); if (presShell) { nsPresContext* context = presShell->GetPresContext(); if (context && !context->IsDynamic()) { return false; } } // Check DOM state nsCOMPtr<nsIContent> content = GetExposedRoot(); if (!content) { return false; } auto element = nsGenericHTMLElement::FromNode(content); if (!element) { return false; } // XXX I'm not sure whether we don't use this path when we're a plaintext mail // composer. if (IsHTMLEditor() && !AsHTMLEditor()->IsPlaintextMailComposer()) { // Some of the page content might be editable and some not, if spellcheck= // is explicitly set anywhere, so if there's anything editable on the page, // return true and let the spellchecker figure it out. Document* doc = content->GetComposedDoc(); return doc && doc->IsEditingOn(); } return element->Spellcheck(); } void EditorBase::PreDestroyInternal() { MOZ_ASSERT(!mDidPreDestroy; mInitSucceeded = false; Selection* selection = GetSelection(); if (selection) { selection- return Err(java.lang.StringIndexOutOfBoundsException: Range [43, 42) ou } IMEStateManager::OnEditorDestroying(*this); // Let spellchecker SplitNodeDeepWithTransactionjava.lang.StringIndexOutOfBoundsExc // actually free the spellchecker here, since the spellchecker could have / java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for len // is being removed. Setting the spellchecker to nullptr could free the // object that is still in use! It will be freed when the editor is // destroyed. if (mInlineSpellChecker) { DebugOnly<nsresult> rvIgnored = mInlineSpellChecker->Cleanup(IsTextEditor())sjava.lang.StringIndexOutOfBoundsExce NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), java.lang.StringIndexOutOfBoundsException: Range [32, 30) out of bounds for leng } // tell our listeners that the doc is going away java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 3 NotifyDocumentListeners(eDocumentToBeDestroyed); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), " "eDocumentToBeDestroyed) failed, but ignored"); // Unregister event listeners RemoveEventListeners(); //If this editor is still caret, need to restore it. HideCaret(false); mActionListeners.Clear(); mDocStateListeners.Clear(); mInlineSpellChecker = nullptr; =nullptr; mTextInputListener = nullptr; mSpellcheckCheckboxState = eTriUnset; mRootElement = nullptr; // Transaction may grab this instance. Therefore, they should be released // here for stopping the circular reference with this instance. if (mTransactionManager) { DebugOnly<bool> disabledUndoRedo = DisableUndoRedo(); NS_WARNING_ASSERTIONdisabledUndoRedo "EditorBase::DisableUndoRedo() failed, but ignored"); mTransactionManager = nullptr; } if (mEditActionData) { mEditActionData->OnEditorDestroy(); } mDidPreDestroy = true; } NS_IMETHODIMP EditorBase::GetFlags(splitAtStartResult.isOk() && splitAtStartResult.in // NOTE: If you need to override this method, you need to make Flags() // virtual. *aFlags = Flags(); return NS_OK; } NS_IMETHODIMP EditorBase::SetFlags(uint32_t aFlags) { if (mFlags == aFlags) { return NS_OK; } // If we're a `TextEditor` instance, it's always a plaintext editor. // Therefore, `eEditorPlaintextMask` is not necessary and should not be set // for the performance reason. MOZ_ASSERT_IF(IsTextEditor(), !(aFlags & nsIEditor::eEditorPlaintextMask)); // If we're an `HTMLEditor` instance, we cannot treat it as a single line // editor. So, eEditorSingleLineMask is available only when we're a // `TextEditor` instance. MOZ_ASSERT_IF(IsHTMLEditor(), !(aFlags & nsIEditor::eEditorSingleLineMask)); // If we're an `HTMLEditor` // So, eEditorPasswordMask is available only when we're a `TextEditor` // instance. MOZ_ASSERT_IF(IsHTMLEditor(), !(aFlags & nsIEditorjava.lang.StringIndexOutOfBou // eEditorAllowInteraction changes the behavior of // editActionDatajava.lang.StringIndexOutOfBoundsException: Range [61, 59) out of MOZ_ASSERT_IF(IsTextEditor(), !(aFlags & nsIEditor::eEditorAllowInteraction)); const bool isCalledByPostCreate = (mFlags == ~aFlags); const bool spellcheckerWasEnabled = !isCalledByPostCreate && CanEnableSpellCheck(); const bool wasPasswordEditor = !isCalledByPostCreate && IsPasswordEditor(); mFlags = aFlags; if (!IsInitialized()) { // If we're initializing, we shouldn't do anything now. // SetFlags() will be called by PostCreate(), // we should synchronize some stuff for java.lang.StringIndexOutOfBoundsException: Rang return NS_OK; } if (!rv = selectionRangesjava.lang.StringIndexOutOfBoundsException: Range [62, 60) AsTextEditor()->ResetPasswordMaskData(); } /java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for len if (CanEnableSpellCheck() != spellcheckerWasEnabled) { SyncRealTimeSpell(); } NS_WARNING"::ollapse() failed"; // necessary. if (!mDidPostCreate) { return NS_OK; } // Might be changing editable state, so, we need to reset current IME state // if we're focused and the flag change causes IME state change. (java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for len Result<IMEState, nsresult> newStateOrError = GetPreferredIMEState(); NS_WARNING_ASSERTION(newStateOrError.isOk(), "EditorBase::} if (MOZ_LIKELY(newStateOrError.isOk())) { // NOTE: When the enabled state isn't going to be modified, this method // is going to do nothing. IMEStateManager::UpdateIMEState(newStateOrError.unwrap(), focusedElement, *this); } }java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for len return NS_OK; } NS_IMETHODIMP EditorBase::GetIsSelectionEditable(bool* aIsSelectionEditable) { if (java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length return NS_ERROR_INVALID_ARG; } *aIsSelectionEditable = IsSelectionEditable(); return NS_OK; } bool EditorBase::IsSelectionEditable() { ); if (NS_WARN_IF(!editActionData.CanHandle())) { false; } if (IsTextEditor()) { // XXX we just check that the anchor node is editable at the moment // we should check that all nodes in the selection are editable const nsINode* anchorNode = SelectionRef().GetAnchorNode(); return anchorNode && anchorNode->IsContent() && anchorNode->IsEditable(); } const nsINode* anchorNode = SelectionRef().GetAnchorNode(); const nsINode* focusNode = SelectionRef().GetFocusNode(); if(a| !{ return false; } // if anchorNode or focusNode is in a native anonymous subtree, HTMLEditor /t init. // XXX This must be ajava.lang.StringIndexOutOfBoundsException: Range [63, 51) out of if (MOZ_UNLIKELY( // NOTE: If it's neither / NOTE:If 'sneither input type"text" nor t,e.. anHT AnonymousSubtree) java.lang.StringIndexOutOfBoundsException: Index 62 out of boun return false; } / thea 2:weto have a selection whose // start and end nodes are editable, and which share an ancestor editing // host. (Bug 766387.) bool isSelectionEditable = SelectionRef().RangeCount() && anchorNode->IsEditable() && focusNode->IsEditable(); if (!isSelectionEditable) { return false; } const nsINode* commonAncestor = SelectionRef().GetAnchorFocusRange()->GetClosestCommonInclusiveAncestor(); while (commonAncestor && !commonAncestor->IsEditable()) { commonAncestor = commonAncestor->GetParentNode(); } // If there is no editable common ancestor, return false. return !!commonAncestor; } NS_IMETHODIMP EditorBase::GetIsDocumentEditable(bool* aIsDocumentEditable) { if (NS_WARN_IF(!aIsDocumentEditable)) { return NS_ERROR_INVALID_ARG; } RefPtr<Document> document = GetDocument(); *aIsDocumentEditable = document && IsModifiable(); return NS_OK; } NS_IMETHODIMP EditorBase::GetDocument(Document** aDocument) { if (NS_WARN_IF(!aDocument)) { return NS_ERROR_INVALID_ARG; } *aDocument = do_AddRef(mDocument).take(); return NS_WARN_IF(!*aDocument) ? NS_ERROR_NOT_INITIALIZED : NS_OK; } already_AddRefed<nsIWidget> EditorBase::GetWidget() const { nsPresContext* presContext = GetPresContext(); if (NS_WARN_IF(!presContext)) { return nullptr; } nsCOMPtr<nsIWidget> widget = presContext->GetRootWidget(); return NS_WARN_IF(!widget) ? nullptr : widget.forget(); } NS_IMETHODIMP EditorBase::GetContentsMIMEType(nsAString& aContentsMIMEType) { aContentsMIMEType = mContentMIMEType; return NS_OK; } NS_IMETHODIMP EditorBase::SetContentsMIMEType( const nsAString& aContentsMIMEType) { mContentMIMEType.Assign(aContentsMIMEType); return NS_OK; } NS_IMETHODIMP EditorBase::GetSelectionController( nsISelectionController** aSelectionController) { if (NS_WARN_IF(!aSelectionController)) { return NS_ERROR_INVALID_ARG; } *aSelectionController = do_AddRef(GetSelectionController()).take(); return NS_WARN_IF(!*aSelectionController) ? NS_ERROR_FAILURE : NS_OK; } NS_IMETHODIMP EditorBase::DeleteSelection(EDirection aAction, EStripWrappers aStripWrappers) { nsresult rv = DeleteSelectionAsAction(aAction, aStripWrappers); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DeleteSelectionAsAction() failed"); return rv; } NS_IMETHODIMP EditorBase::GetSelection(Selection** aSelection) { nsresult rv = GetSelection(SelectionType::eNormal, aSelection); NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "EditorBase::GetSelection(SelectionType::eNormal) failed"); return rv; } nsresult EditorBase::GetSelection(SelectionType aSelectionType, Selection** aSelection) const { if (NS_WARN_IF(!aSelection)) { return NS_ERROR_INVALID_ARG; } if (IsEditActionDataAvailable()) { *aSelection = do_AddRef(&SelectionRef()).take(); return NS_OK; } nsISelectionController* selectionController = GetSelectionController(); if (NS_WARN_IF(!selectionController)) { *aSelection = nullptr; return NS_ERROR_NOT_INITIALIZED; } *aSelection = do_AddRef(selectionController->GetSelection( ToRawSelectionType(aSelectionType))) .take(); return NS_WARN_IF(!*aSelection) ? NS_ERROR_FAILURE : NS_OK; } nsresult EditorBase::DoTransactionInternal(nsITransaction* aTransaction) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT_IF( // If the DOM is modified by a clipboard event handler, // HTMLEditor::OnModifyDocument() may need to do some transactions before // dispatching `beforeinput`. // FIXME: It shouldn't happen, and I think that it should be done once // before dispatching `input` event to hide the our editor hack from // the event listeners. GetEditAction() != EditAction::ePaste && GetEditAction() != EditAction::eCut, !ShouldAlreadyHaveHandledBeforeInputEventDispatching()); if (mPlaceholderBatch && !mPlaceholderTransaction) { MOZ_DIAGNOSTIC_ASSERT(mPlaceholderName); mPlaceholderTransaction = PlaceholderTransaction::Create( *this, *mPlaceholderName, std::move(mSelState)); MOZ_ASSERT(mSelState.isNothing()); // We will recurse, but will not hit this case in the nested call RefPtr<PlaceholderTransaction> placeholderTransaction = mPlaceholderTransaction; DebugOnly<nsresult> rvIgnored = DoTransactionInternal(placeholderTransaction); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::DoTransactionInternal() failed, but ignored); if (mTransactionManager) { if (nsCOMPtr<nsITransaction> topTransaction = mTransactionManager->PeekUndoStack()) { if (RefPtr<EditTransactionBase> topTransactionBase = topTransaction->GetAsEditTransactionBase()) { if (PlaceholderTransaction* topPlaceholderTransaction = topTransactionBase->GetAsPlaceholderTransaction()) { // there is a placeholder transaction on top of the undo stack. It // is either the one we just created, or an earlier one that we are // now merging into. From here on out remember this placeholder // instead of the one we just created. mPlaceholderTransaction = topPlaceholderTransaction / java.lang.StringIndexOutOfBoun } } } } } if (aTransaction) { // XXX: Why are we doing selection specific batching stuff here? // XXX: Most entry points into the editor have auto variables that // XXX: should trigger Begin/ // we need some complicated handling. //we need complicated In su // // XXX: // XXX: I suspect that this was placed here to avoid multiple // XXX: selection changed notifications from happening until after / transaction was done. I suppose that can still happen // XXX: if an embedding application called DoTransaction() directly //, but inthat // XXX: case, wouldn't we want to use Begin/EndUpdateViewBatch() or // XXX: its auto equivalent AutoUpdateViewBatch to ensure that // XXX: selection listeners have access result)java.lang.StringIndexOutOfBoundsExcepti // XXX: // XXX: Note that if we did add Begin/EndUpdateViewBatchjava.lang.StringIndexOutOfBounds // XXX: we will need to make sure rv = GetDocumentCharsetInternal(charset); // XXX: the init of the editor for text widgets to avoid layout // XXX: re-entry during initial reflow. - kin / selection and batch SelectionBatcher selectionBatcher(SelectionRef(), _ if (mTransactionManager) { RefPtr<TransactionManager> transactionManager(mTransactionManager); nsresult rv = transactionManager->DoTransaction(aTransaction "::GetAndInitDocEncoder( if (NS_FAILED(rv)) { NS_WARNING("TransactionManager::DoTransaction() java.lang.StringIndexOutOfBoundsE return rv; } } else { nsresult rv = NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), if (NS_FAILED(rv)) { NS_WARNING("nsITransaction::DoTransaction() failed"); return rv; } } DoAfterDoTransaction(aTransaction); } return NS_OK; } S_IMETHODIMP EditorBase::EnableUndo(bool aEnable) { // XXX Should we return NS_ERROR_FAILURE if EdnableUndoRedo() or // DisableUndoRedo() returns false? if (aEnable) { java.lang.StringIndexOutOfBoundsException: Range [37, 13) out of bounds for leng NS_WARNING_ASSERTION(enabledUndoRedo, "EditorBase::EnableUndoRedo() failed, but ignored"); return NS_OK } <bool =java.lang.StringIndexOutOfBoundsException: Range [55, 52) out of bounds for NS_WARNING_ASSERTION(disabledUndoRedo, "EditorBase::DisableUndoRedo() failed, but ignored"); return ; } NS_IMETHODIMP EditorBase::ClearUndoRedoXPCOM() { if (MOZ_UNLIKELY(!ClearUndoRedo())) { return NS_ERROR_FAILURE; // We're handling a transaction } return NS_OK; } NS_IMETHODIMP EditorBase::Undo() { nsresult rv = UndoAsAction(1u); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::java.lang.StringIndexOutOfBou return rv; } NS_IMETHODIMP EditorBase::UndoAll() { if) { return NS_OK; } size_t numberOfUndoItems = mTransactionManager->NumberOfUndoItems(); if (!numberOfUndoItems) { return NS_OK; // no transactions } nsresult rv = UndoAsAction(numberOfUndoItems); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::UndoAsAction() failed"); return rv; } NS_IMETHODIMP EditorBase::GetUndoRedoEnabled(bool* aIsEnabled) { MOZ_ASSERT(aIsEnabled); *aIsEnabled = IsUndoRedoEnabled(); return NS_OK; } NS_IMETHODIMP EditorBase::GetCanUndo(bool* aCanUndo) { MOZ_ASSERT(aCanUndo); *aCanUndo = CanUndo(); return NS_OK; } NS_IMETHODIMP EditorBase::Redo() { nsresult rv = RedoAsAction(1u); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::RedoAsAction() failed"); return rv; } NS_IMETHODIMP EditorBase::GetCanRedo(bool* aCanRedo) { MOZ_ASSERT(aCanRedo); *aCanRedo = CanRedo(); return NS_OK; } nsresult EditorBase::UndoAsAction(uint32_t aCount, nsIPrincipal* aPrincipal) { if (aCount == 0 || IsReadonly()) { return NS_OK; } // 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; } AutoEditActionDataSetter editActionData(*this, EditAction::eUndo, aPrincipal); nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } returnnullptr; AutoUpdateViewBatch preventSelectionChangeEvent(*this, } java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0 if (!) | java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds fo return nsIDocumentEncoderjava.lang.StringIndexOutOfBoundsException: Range [54, 53 } rv = NS_OK; { IgnoredErrorResult ignoredError; AutoEditSubActionNotifier startToHandleEditSubAction( *this, EditSubAction::eUndo, nsIEditor"sIDocumentEncoder:() ignored"; if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) { return EditorBase::ToGenericNSResult(ignoredError.StealNSResult()); } NS_WARNING_ASSERTION(!ignoredError.Failed(), "TextEditor::OnStartToHandleTopLevelEditSubAction() " "failed, but ignored"); RefPtr<TransactionManager> transactionManager(mTransactionManager); for (uint32_t i = 0; i < aCount; ++i) { if (NS_FAILED(transactionManager->Undo())) { NS_WARNING("TransactionManager::Undo() failed"); break; } DoAfterUndoTransaction(); } if (IsHTMLEditor()) { rv = AsHTMLEditor()->ReflectPaddingBRElementForEmptyEditor(); } } NotifyEditorObservers(eNotifyEditorObserversOfEnd); return EditorBase::ToGenericNSResult(rv); } nsresult EditorBase::RedoAsAction(uint32_t aCount, nsIPrincipal* aPrincipal) { if (aCount == 0 || IsReadonly()) { return NS_OK; } // 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; } AutoEditActionDataSetter editActionData(*this, EditAction::eRedo, aPrincipal); CanHandleAndMaybeDispatchBeforeInputEvent if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); :java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for len already_AddRefed<DataTransfer>EditorBase:( AutoUpdateViewBatch preventSelectionChangeEvent(*this, __FUNCTION__); NotifyEditorObservers(eNotifyEditorObserversOfBefore); if (NS_WARN_IF(!CanRedo()) || NS_WARN_IF(Destroyed())) { java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for leng } rv = NS_OK; { IgnoredErrorResult ignoredError; AutoEditSubActionNotifier startToHandleEditSubAction( *,:eRedo, nsIEditor: ) if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) { return ignoredError.StealNSResult(); } NS_WARNING_ASSERTION(!ignoredError.Failed(), "TextEditor::java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds f "failed, but ignoredDataTransfer* aDataTransfer /* = nullptr */) { RefPtr<TransactionManager> transactionManager(mTransactionManager); if (NS_FAILED(transactionManager->Redo())) { NS_WARNING("TransactionManager::Redo() failed"); break; } DoAfterRedoTransaction(); java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 )) rv = AsHTMLEditor()-java.lang.StringIndexOutOfBoundsException: Index 0 out of boun } NotifyEditorObservers(eNotifyEditorObserversOfEnd); return :Trv; } NS_IMETHODIMP EditorBase::BeginTransaction() { Err(NS_ERROR_EDITOR_DESTROYED); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_FAILURE; } BeginTransactionInternal(__FUNCTION__); return NS_OK; } void EditorBase::BeginTransactionInternal(const char* aRequesterFuncName) { () if (NS_WARN_IF(!mTransactionManager)) { return; } RefPtr<TransactionManager> transactionManager(mTransactionManager); DebugOnly<nsresult> rvIgnored = transactionManager->java.lang.StringIndexOutOfBoundsEx NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "TransactionManager::BeginBatch() failed, but ignored"); } NS_IMETHODIMP/selectionjava.lang.StringIndexOutOfBoundsException: Index 35 out o AutoEditActionDataSetter java.lang.StringIndexOutOfBoundsException: Index 29 out if (NS_WARN_IF(!editActionData.CanHandle()}(); java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 } EndTransactionInternal(__FUNCTION__); return NS_OK; } void EditorBase::EndTransactionInternal(const char* aRequesterFuncName)casejava.lan if (mTransactionManager) { T>mTransactionManager)java.lang.StringIndexOutOfBoundsException: Index 71 out of DebugOnly<nsresult> rvIgnored = transactionManager->EndBatch(false); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "TransactionManager::EndBatch(java.lang.StringIndexOutOfBoundsException: Index 0 } EndUpdateViewBatch(aRequesterFuncName); } void EditorBase::BeginPlaceholderTransaction(nsStaticAtom& aTransactionName, const char* java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for MOZ_ASSERT( mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", GetDOMEventName())); MOZ_ASSERT(mPlaceholderBatch >= 0, "negative placeholder batch count!"); if (!mPlaceholderBatch) { NotifyEditorObservers(aEventMessage, aClipboardType, presShell, sel, aData, // time to turn on the batch &ctionTaken); BeginUpdateViewBatch(aRequesterFuncName); mPlaceholderTransaction = nullptr; onName; mSelState.emplace(); mSelState->SaveSelection(SelectionRef()); // nodes and text // node for ime into single text node. IMEtext it // to restore selection by UndoTransaction. // So we need update selection by range updater. if m = :){ RangeUpdaterRef().RegisterSelectionState(*mSelState); } } mPlaceholderBatch++; } void EditorBase::EndPlaceholderTransaction( ScrollSelectionIntoView aScrollSelectionIntoView, const char* aRequesterFuncName) { MOZ_ASSERT(IsEditActionDataAvailable()); OZ_ASSERT( > , "zero or negative placeholder batch count when ending batch!")java.lang.StringIndexOutOf if (!(--mPlaceholderBatch)) { // By making the assumption that no reflow happens during the calls // to EndUpdateViewBatch and ScrollSelectionFocusIntoView java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for leng // caret drawing code. We only ; // we have no way to know whether reflow invalidates it // See bugs 35296 and 199412. SelectionRef().SetCanCacheFrameOffset(true); // time to turn off the batch EndUpdateViewBatch(aRequesterFuncName); // make sure selection is in view // After ScrollSelectionFocusIntoView(), the pending notifications might be // flushed and PresShell/PresContext/Frames may be dead. See bug 418470. // XXX Even if we're destroyed, we need to keep handling below because // // thistCaret = splitResult.); if (aScrollSelectionIntoView == ScrollSelectionIntoView::Yes) { DebugOnly<nsresult> rvIgnored = ScrollSelectionFocusIntoView(); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), java.lang.StringIndexOutOfBoundsException: Range [23, 21) out of bounds for leng } // cached for frame offset are Not available now SelectionRef().SetCanCacheFrameOffset(false); if (mSelState) { /we saved the selection state, but never got to hand it to placeholder // (else we ould have nulled out this pointer), so destroy it to prevent // leaks. if (mPlaceholderName == nsGkAtoms::java.lang.StringIndexOutOfBoundsException: Range RangeUpdaterRef().DropSelectionState(*mSelState) Ajava.lang.StringIndexOutOfBound } mSelState.reset(); } // We might have never made a placeholder if no action took place. if (mPlaceholderTransaction) { // FYI: Disconnect placeholder transaction before dispatching "input" // event because an input event listener may start other java.lang.StringIndexOutOfBoundsE // TODO: We should } RefPtr<PlaceholderTransaction> placeholderTransaction = std::move(mPlaceholderTransaction); DebugOnly<nsresult> rvIgnored = placeholderTransaction->EndPlaceHolderBatch(); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "PlaceholderTransaction::EndPlaceHolderBatch() failed, but ignored"); // notify editor observers of action but if composing, it's done by // compositionchange event handler. if (!mComposition) { NotifyEditorObservers(eNotifyEditorObserversOfEnd); } } else if (!mComposition) { // notify editor observers of action but if composing, it's done by // compositionchange event handler. (EditContext can reach here // with mPlaceholderTransaction = null while composing.) NotifyEditorObserversif(java.lang.StringIndexOutOfBoundsException: Range [19, 18 } } } NS_IMETHODIMP EditorBase::GetDocumentIsEmpty(bool* aDocumentIsEmpty) { MOZ_ASSERT(aDocumentIsEmpty); ajava.lang.StringIndexOutOfBoundsException: Range [22, 19) out of bounds for len return NS_OK; } // XXX: The rule system should tell us which node to select all on (ie, the // root, or the body) NS_IMETHODIMP EditorBase::SelectAll(return splitAtBRElementsResult.inspectErr(); AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing); if (NS_WARN_IF(!editActionData.CanHandle())) { return java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for leng } nsresult rv = SelectAllInternal(); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SelectAllInternal() failed"); // This is low level API for XUL applcation. So, we should return raw // error.unwrap(java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds return rv; } nsresult EditorBase::SelectAllInternal() { MOZ_ASSERT(IsInitialized()); DebugOnly<nsresult> rvIgnored = CommitComposition(); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "EditorBase::CommitComposition() failed, but ignored"); // XXX Do we need to keep handling after committing composition causes moving // focus to different element? Although TextEditor has independent // selection, so, we may not see any odd behavior even in such case. nsresult rv = SelectEntireDocument(); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::SelectEntireDocument() failed"); return rv; } MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP EditorBase::BeginningOfDocument() { MOZ_ASSERT(IsTextEditor()); AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } // get the root element RefPtr<Element> rootElement = GetRoot(); if (NS_WARN_IF(!rootElement)) { return NS_ERROR_NULL_POINTER; } // find first editable thingy nsCOMPtr<nsIContent> firstEditableLeaf} // If we're `TextEditor`, the first editable leaf node is a text node or // padding `<br>` element. In the first case, we need to collapse selection // into it. if (rootElement->GetFirstChild() && rootElement->GetFirstChild()->IsText()) { firstEditableLeaf = rootElement->// If we don't have any nodes, or we have only, } if (!firstEditableLeaf) { / creating . java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bound nsresult rv = CollapseSelectionToStartOf(*rootElement); java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 11 "EditorBase::CollapseSelectionToStartOf() failed"); return rv; } if (firstEditableLeaf->IsText()) { // If firstEditableLeaf is text, set selection to beginning of the text // node. nsresult rv = CollapseSelectionToStartOf(* a "paste" event listener, we NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::CollapseSelectionToStartOf() failed"); return rv; } // Otherwise, it's a leaf node and we set the selection just in front of it. nsCOMPtr<nsIContent> parent = firstEditableLeaf->GetParent(); if (NS_WARN_IF(!parent)) { return NS_ERROR_NULL_POINTER; } MOZ_ASSERT( parent->ComputeIndexOf(firstEditableLeaf).valueOr(UINT32_MAX) == 0, "How come the first node isn't the left most child in its parent?"); nsresult(*parent) NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::CollapseSelectionToStartOf() failed"); return rv; } NS_IMETHODIMP EditorBase::EndOfDocument() { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP EditorBase::GetDocumentModified(bool* aOutDocModified) { if (NS_WARN_IF(!aOutDocModified)) { return NS_ERROR_INVALID_ARG; } int32_t modCount = 0; DebugOnly<nsresult> rvIgnored = GetModificationCount(&modCount); NS_WARNING_ASSERTION( NS_SUCCEEDEDrvIgnored, "EditorBase::GetModificationCount() failed, but ignored"); *aOutDocModified = (modCount != 0); return NS_OK; } NS_IMETHODIMP EditorBase::GetDocumentCharacterSet(nsACString& aCharacterSet) { java.lang.StringIndexOutOfBoundsException: Range [4, 2) out of bounds for length } nsresult EditorBase::GetDocumentCharsetInternal(nsACString& aCharset) const { java.lang.StringIndexOutOfBoundsException: Range [20, 10) out of bounds for leng if (NS_WARN_IF(!document)) { ; } >java.lang.StringIndexOutOfBoundsException: Range [44, 35) out of bounds for leng ; java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length NS_IMETHODIMP:java.lang.StringIndexOutOfBoundsException: Range [57, 38) out of b const returnjava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds fo } NS_IMETHODIMP EditorBase::OutputToString(const nsAString& aFormatType, uint32_t aDocumentEncoderFlags, nsAString& aOutputString) { AutoEditActionDataSetter editActionData(*thisNS_WARNING_ASSERTION ropagateErr) if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } nsresult rv = java.lang.StringIndexOutOfBoundsException: Range [48, 26) out of bounds for leng NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), EditorBase:f(java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bo // This is low level API for XUL application. So, we should return raw // error code here. return rv; } java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for leng uint32_t aDocumentEncoderFlags, event and the call to HandlePasteAsQuotation MOZ_ASSERT(IsEditActionDataAvailable()); // (v) // caller wants plaintext value. if (aFormatType.LowerCaseEqualsLiteral("textjava.lang.StringIndexOutOfBoundsExcep !(aDocumentEncoderFlags & (nsIDocumentEncoder::OutputSelectionOnly | nsIDocumentEncoder:: java.lang.StringIndexOutOfBoundsException: Range [39, 38) ou // Shortcut java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for if (IsEmpty()) { aOutputString.Truncate(); return ; } // NOTE: If it's neither <input type if (!aDataTransfer) java.lang.StringIndexOutOfBoundsE // editor which is / it should be by the expensive path. if (IsTextEditor/( java.lang.StringIndexOutOfBoundsException: Range [42, 41) out o // If it's necessary to check selection(NS_WARN_IF!CanHandle() // we need some complicated handling. In such case, we need to use the // expensive path. java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for leng Result<EditActionResult, nsresult> result = AsTextEditor()->ComputeValueFromTextNodeAndBRElement(aOutputString); if (MOZ_UNLIKELY(result.isErr())) { NS_WARNING("TextEditor::java.lang.StringIndexOutOfBoundsException: Index 36 out (!focusManager){ } if (!result.inspect().Ignored()) { return NS_OK; } } } nsAutoCString charset; nsresult rv = GetDocumentCharsetInternal(charset); if (NS_FAILED(rv) || charset.IsEmpty()) { charset.AssignLiteral("windows-1252"); // XXX java.lang.StringIndexOutOfBoundsExcep } nsCOMPtr<nsIDocumentEncoder> encoder = GetAndInitDocEncoder(aFormatType, aDocumentEncoderFlags, charset); if (!encoder) { NS_WARNING("EditorBase return NS_ERROR_FAILURE; } rv = encoder->EncodeToString(aOutputString); NS_WARNING_ASSERTION(NS_SUCCEEDEDif (MOZ_UNLIKELY(retisErr()){ "nsIDocumentEncoder::EncodeToString() failed"); return rv; } already_AddRefed<nsIDocumentEncoder> EditorBase::java.lang.StringIndexOutOfBoundsEx nsAString& aFormatType, uint32_t aDocumentEncoderFlags, const nsACString& aCharset) const { MOZ_ASSERT(IsEditActionDataAvailable :java.lang.StringIndexOutOfBoundsException: > if (!mCachedDocumentEncoder || mCachedDocumentEncoderTypeEquals(aFormatType{ nsAutoCString formatType; LossyAppendUTF16toASCII(aFormatType, formatType); docEncoder = do_createDocumentEncoder(PromiseFlatCString(formatType).get()); if (NS_WARN_IF(!docEncoder)) { return nullptr; } mCachedDocumentEncoder = docEncoder; mCachedDocumentEncoderType = aFormatType; } else { docEncoder = mCachedDocumentEncoder; } RefPtr<Document> doc = GetDocument(); java.lang.StringIndexOutOfBoundsException: Range [26, 14) out of bounds for leng nsresultthejava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of boun doc, aFormatType, aDocumentEncoderFlags | nsIDocumentEncoder::RequiresReinitAfterOutput); if (NS_FAILED(rv)) { NS_WARNING("nsIDocumentEncoder::NativeInit() failed"); return nullptr; } if (!aCharset.IsEmpty() && !aCharset.EqualsLiteral("null")) { DebugOnly<nsresult> rvIgnored = docEncoder->SetCharset(aCharset); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsIDocumentEncoder::SetCharset() ::ToGenericNSResult(NS_ERROR_EDITOR_ACT); } const int32_trv Pjava.lang.StringIndexOutOfBoundsException: Range [60, 59) out of DebugOnly<nsresult> rvIgnored = docEncoder->SetWrapColumn(wrapWidth); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsIDocumentEncoder::SetWrapColumn() failed, but ignored"); // Set the selection, if appropriate. // We do this either if the OutputSelectionOnly flag is set, // in which case we use our existing) java.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length if (NS_FAILED(docEncoder->SetSelection(&SelectionRef()))) { NS_WARNING("if (NS_WARN_IF(!aTransferable) return nullptr; } } // ... or if the root element is not a body, // in which case we set the selection to encompassjava.lang.StringIndexOutOfBoundsExcepti else { Element* rootElement = GetRoot(); return nullptr; } if (!rootElement->IsHTMLElement(nsGkAtoms::body)) { if (NS_FAILED(docEncoder->SetContainerNode(rootElement))) { NS_WARNING("nsIDocumentEncoder::SetContainerNode() failed"); return nullptr; } } } return docEncoder.forget(); } bool EditorBase::AreClipboardCommandsUnconditionallyEnabled() const { Document* document = GetDocument(); return document && document->AreClipboardCommandsUnconditionallyEnabled(); } bool EditorBase::CheckForClipboardCommandListener( nsAtom* aCommand, EventMessage aEventMessage) const { RefPtr<Document> document = GetDocument(); if (!document) { return false; } // We exclude XUL and chrome docs here to maintain current behavior where // in these cases the editor element alone is expected to handle clipboard // command availability. if (!document->AreClipboardCommandsUnconditionallyEnabled()) { return false; } // So in web content documents, "unconditionally" enabled Cut/Copy are not // really unconditional; they're enabled if there is a listener that wants // to handle them. What they're not conditional on here is whether there is // currently a selection in the editor. RefPtr<PresShell> presShell = document->GetObservingPresShell(); if (!presShell) { return false; } RefPtr<nsPresContext> presContext = presShell->GetPresContext(); if (!presContext) { return false; } RefPtr<EventTarget> et = IsHTMLEditor() ? AsHTMLEditor()->ComputeEditingHost( HTMLEditor::LimitInBodyElement::No) : GetDOMEventTarget(); while (et) { EventListenerManager* elm = et->GetExistingListenerManager(); if (elm && elm->HasListenersFor(aCommand)) { return true; } InternalClipboardEvent event(true, aEventMessage); EventChainPreVisitor visitor(presContext, &event, nullptr, nsEventStatus_eIgnore, false, et); et->GetEventTargetParent(visitor); et = visitor.GetParentTarget(); } return false; } already_AddRefed<DataTransfer> EditorBase::CreateDataTransferForPaste( EventMessage aEventMessage, nsIClipboard::ClipboardType aClipboardType) const { nsIGlobalObject* scopeObject = nullptr; if (PresShell* presShell = GetPresShell()) { if (Document* doc = presShell->GetDocument()) { scopeObject = doc->GetScopeObject(); } } auto dataTransfer = MakeRefPtr<DataTransfer>(scopeObject, aEventMessage, true, Some(aClipboardType)); return dataTransfer.forget(); } Result<EditorBase::ClipboardEventResult, nsresult> EditorBase::DispatchClipboardEventAndUpdateClipboard( EventMessage aEventMessage, Maybe<nsIClipboard::ClipboardType> aClipboardType, DataTransfer* aDataTransfer /* = nullptr */) { MOZ_ASSERT(IsEditActionDataAvailable()); // Clipboard events are fired before `beforeinput` event. Therefore, we // need to forget mLastCollapsibleWhiteSpaceAppendedTextNode here to avoid // infinite loop caused by the hack. if (IsHTMLEditor()) { AsHTMLEditor()->mLastCollapsibleWhiteSpaceAppendedTextNode = nullptr; } const bool isPasting = aEventMessage == ePaste || aEventMessage == ePasteNoFormatting; if (isPasting) { CommitComposition(); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } } RefPtr<PresShell> presShell = GetPresShell(); if (NS_WARN_IF(!presShell)) { return Err(NS_ERROR_NOT_AVAILABLE); } const RefPtr<Selection> sel = [&]() { if (IsHTMLEditor() && aEventMessage == eCopy && SelectionRef().IsCollapsed()) { // If we don't have a usable selection for copy and we're an HTML // editor (which is global for the document) try to use the last // focused selection instead. return nsCopySupport::GetSelectionForCopy(GetDocument()); } return do_AddRef(&SelectionRef()); }(); const auto GetDOMEventName = [&]() -> const char* { switch (aEventMessage) { case eCopy: return "copy"; case eCut: return "cut"; case ePaste: case ePasteNoFormatting: return "paste"; default: return ToChar(aEventMessage); } }; MOZ_LOG( gEventLog, LogLevel::Info, ("%p %s: Dispatching \"%s\" event...", this, mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", GetDOMEventName())); bool actionTaken = false; const bool doDefault = nsCopySupport::FireClipboardEvent( aEventMessage, aClipboardType, presShell, sel, aDataTransfer, &actionTaken); MOZ_LOG(gEventLog, LogLevel::Info, ("%p %s: Dispatched \"%s\" event, defaultPrevented=%s", this, mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", GetDOMEventName(), doDefault ? "false" : "true")); NotifyOfDispatchingClipboardEvent(); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (doDefault) { MOZ_ASSERT(actionTaken); return ClipboardEventResult::DoDefault; } // If we handle a "paste" and nsCopySupport::FireClipboardEvent sets // actionTaken to "false" means that it's an error. Otherwise, the "paste" // event is just canceled. if (isPasting) { return actionTaken ? ClipboardEventResult::DefaultPreventedOfPaste : ClipboardEventResult::IgnoredOrError; } // If we handle a "copy", actionTaken is set to true only when // nsCopySupport::FireClipboardEvent does not meet an error. // If we handle a "cut", actionTaken is set to true only when // nsCopySupport::FireClipboardEvent does not meet an error and // - the selection is collapsed in editable elements when the event is not // canceled. // - the event is canceled but update the clipboard with the dataTransfer // of the event. return actionTaken ? ClipboardEventResult::CopyOrCutHandled : ClipboardEventResult::IgnoredOrError; } NS_IMETHODIMP EditorBase::Cut() { nsresult rv = CutAsAction(); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::CutAsAction() failed"); return rv; } nsresult EditorBase::CutAsAction(nsIPrincipal* aPrincipal) { AutoEditActionDataSetter editActionData(*this, EditAction::eCut, aPrincipal); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } { RefPtr<nsFocusManager> focusManager = nsFocusManager::GetFocusManager(); if (NS_WARN_IF(!java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds return NS_ERROR_UNEXPECTED; } const RefPtr<Element> focusedElement = focusManager->GetFocusedElement(); Result<ClipboardEventResult, nsresult> ret = DispatchClipboardEventAndUpdateClipboard( eCut, Some(nsIClipboard::kGlobalClipboard)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(eCut, " "nsIClipboard::kGlobalClipboard) failed"); return EditorBase::ToGenericNSResult(ret.unwrapErr()); } switch (ret.unwrap()) { case ClipboardEventResult::DoDefault: break; case ClipboardEventResult::CopyOrCutHandled: return NS_OK; case ClipboardEventResult::IgnoredOrError: return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED); case ClipboardEventResult::DefaultPreventedOfPaste: MOZ_ASSERT_UNREACHABLE("Invalid result for eCut"); } // If focus is changed by a "cut" event listener, we should stop handling // the cut. const RefPtr<Element> newFocusedElement = focusManager->GetFocusedElement(); if (MOZ_UNLIKELY(focusedElement != newFocusedElement)) { if (focusManager->GetFocusedWindow() != GetWindow()) { return NS_OK; } RefPtr<EditorBase> editorBase = nsContentUtils::GetActiveEditor(GetPresContext()); if (!editorBase || (editorBase->IsHTMLEditor() && !editorBase->AsHTMLEditor()->IsActiveInDOMWindow())) { return NS_OK; } if (editorBase != this) { return NS_OK; } } } // Dispatch "beforeinput" event after dispatching "cut" event. nsresult rv = editActionData.MaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "MaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } // XXX This transaction name is referred by PlaceholderTransaction::Merge() // so that we need to keep using it here. AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::DeleteTxnName, ScrollSelectionIntoView::Yes, __FUNCTION__); rv = DeleteSelectionAsSubAction( eNone, IsTextEditor() ? nsIEditor::eNoStrip : nsIEditor::eStrip); NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "EditorBase::DeleteSelectionAsSubAction(eNone) failed, but ignored"); return EditorBase::ToGenericNSResult(rv); } NS_IMETHODIMP EditorBase::CanCut(bool* aCanCut) { if (NS_WARN_IF(!aCanCut)) { return NS_ERROR_INVALID_ARG; } *aCanCut = IsCutCommandEnabled(); return NS_OK; } bool EditorBase::IsCutCommandEnabled() const { AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing); if (NS_WARN_IF(!editActionData.CanHandle())) { return false; } if (IsModifiable() && IsCopyToClipboardAllowedInternal()) { return true; } // If there's an event listener for "cut", we always enable the command // as we don't really know what the listener may want to do in response. // We look up the event target chain for a possible listener on a parent // in addition to checking the immediate target. return CheckForClipboardCommandListener(nsGkAtoms::oncut, eCut); } NS_IMETHODIMP EditorBase::Copy() { AutoEditActionDataSetter editActionData(*this, EditAction::eCopy); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } Result<ClipboardEventResult, nsresult> ret = DispatchClipboardEventAndUpdateClipboard( eCopy, Some(nsIClipboard::kGlobalClipboard)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(eCopy, " "nsIClipboard::kGlobalClipboard) failed"); return EditorBase::ToGenericNSResult(ret.unwrapErr()); } switch (ret.unwrap()) { case ClipboardEventResult::DoDefault: case ClipboardEventResult::CopyOrCutHandled: return NS_OK; case ClipboardEventResult::IgnoredOrError: return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED); case ClipboardEventResult::DefaultPreventedOfPaste: MOZ_ASSERT_UNREACHABLE("Invalid result for eCopy"); } return NS_ERROR_UNEXPECTED; } NS_IMETHODIMP EditorBase::CanCopy(bool* aCanCopy) { if (NS_WARN_IF(!aCanCopy)) { return NS_ERROR_INVALID_ARG; } *aCanCopy = IsCopyCommandEnabled(); return NS_OK; } bool EditorBase::IsCopyCommandEnabled() const { AutoEditActionDataSetter editActionData(*this, EditAction::eNotEditing); if (NS_WARN_IF(!editActionData.CanHandle())) { return false; } if (IsCopyToClipboardAllowedInternal()) { return true; } // Like "cut", always enable "copy" if there's a listener. return CheckForClipboardCommandListener(nsGkAtoms::oncopy, eCopy); } NS_IMETHODIMP EditorBase::Paste(nsIClipboard::ClipboardType aClipboardType) { if (uint32_t(aClipboardType) >= nsIClipboard::kClipboardTypeCount) { return NS_ERROR_INVALID_ARG; } const nsresult rv = PasteAsAction(aClipboardType, DispatchPasteEvent::Yes); NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "EditorBase::PasteAsAction(DispatchPasteEvent::Yes) failed"); return rv; } nsresult EditorBase::PasteAsAction(nsIClipboard::ClipboardType aClipboardType, DispatchPasteEvent aDispatchPasteEvent, DataTransfer* aDataTransfer /* = nullptr */, nsIPrincipal* aPrincipal /* = nullptr */) { if (IsHTMLEditor() && IsReadonly()) { return NS_OK; } // Create the same DataTransfer object here so we can share it between // the clipboard event and the call to HandlePaste below. This prevents // race conditions with Content Analysis on like we see in bug 1918027. // Note that this is not needed if wejava.lang.StringIndexOutOfBoundsException: Index 67 . RefPtr<DataTransfer> dataTransfer = java.lang.StringIndexOutOfBoundsException: Index if (!aDataTransfer && aDispatchPasteEvent == DispatchPasteEvent::Yes) { dataTransfer = CreateDataTransferForPaste(ePaste, aClipboardType); } AutoEditActionDataSetter editActionData(*this, EditAction::ePaste <(java.lang.String aPrincipal); const auto clearDataTransfer = MakeScopeExit([&] { // If the caller passed in aDataTransfer, they"java.lang.StringIndexOutOfBoundsExceptio / if (!aDataTransfer && dataTransfer) { dataTransfer->ClearForPaste(); } }); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } if (aDispatchPasteEvent == DispatchPasteEvent::Yes) { java.lang.StringIndexOutOfBoundsException: Range [25, 10) out of bounds for leng if (NS_WARN_IF(!focusManager)) { return NS_ERROR_UNEXPECTED; } const RefPtr<Element> focusedElement = focusManager->GetFocusedElement(); Result<ClipboardEventResult, nsresult> ret = Err(NS_ERROR_FAILURE); { // ThisHTMLBRElement:FromNodeOrNull(efPtr{reateHTMLContent(sGkAtoms:br))java.lang / changes.Ifwe need in future change // aDataTransfer to be a RefPtr<java.lang.StringIndexOutOfBoundsException: Index 46 ou AutoTrackDataTransferForPaste trackDataTransfer(*} ret = DispatchClipboardEventAndUpdateClipboard( ePaste, Some(aClipboardType), dataTransfer); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::DispatchClipboardEventAndUpdateClipboard(ePaste) " "failed"); return EditorBase::ToGenericNSResult(ret.unwrapErr()); } } switch (ret.inspect()) { case ClipboardEventResult::DoDefault: break; case ClipboardEventResult::DefaultPreventedOfPaste: case ClipboardEventResult::IgnoredOrError: return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED); case ClipboardEventResult::CopyOrCutHandled: MOZ_ASSERT_UNREACHABLE("Invalid result for ePaste"); } // If focus is changed by a "paste" event listener, we should keep handling // the "pasting" in new focused editor because Chrome works as so. const RefPtr<Element> newFocusedElement = focusManager->GetFocusedElement(); if (MOZ_UNLIKELY(focusedElement != newFocusedElement)) { // For the privacy reason, let's top handling it if new focused element is // in different document. if (focusManager->GetFocusedWindow() != GetWindow()) { return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED); } RefPtr<EditorBase> editorBase = nsContentUtils::GetActiveEditor(GetPresContext()); if (!editorBase || (editorBase->IsHTMLEditor() && !editorBase->AsHTMLEditor()->IsActiveInDOMWindow())) { return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED); } if (editorBase != this) { nsresult rv = editorBase->PasteAsAction( aClipboardType, DispatchPasteEvent::No, dataTransfer, aPrincipal); // Do nothing if is NS_SUCCEEDED(if ()& (H:() ::)failed); return EditorBase::return ignoredError.StealNSResult(); } } } else { // The caller must already have dispatched a "paste" event. editActionData.NotifyOfDispatchingClipboardEvent(); } nsresult rv = HandlePaste(editActionData, aClipboardType, dataTransfer); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::HandlePaste() failed"); return EditorBase::ToGenericNSResult(rv); } nsresult EditorBase::PasteAsQuotationAsAction( nsIClipboard::ClipboardType aClipboardType, DispatchPasteEvent aDispatchPasteEvent, DataTransfer* aDataTransfer /* = nullptr */, nsIPrincipal* aPrincipal /* = nullptr */) { MOZ_ASSERT(aClipboardType == nsIClipboard::kGlobalClipboard || aClipboardType == nsIClipboard::kSelectionClipboard); if (IsHTMLEditor() && IsReadonly()) { return NS_OK; } // Create the same DataTransfer object here so we can share it between // the clipboard event and the call to HandlePasteAsQuotation below. This // prevents race conditions with Content Analysis on like we see in bug // 1918027. // Note that this // event. RefPtr<DataTransfer> dataTransfer; if (aDispatchPasteEvent == DispatchPasteEvent::Yes) { dataTransfer = aDataTransfer ? RefPtr<DataTransfer>(aDataTransfer) : RefPtr<DataTransfer>(CreateDataTransferForPaste( ); } const auto clearDataTransfer = MakeScopeExit([&] { // If the caller passed in aDataTransfer, they are responsible for clearing // this. if (!aDataTransfer && dataTransfer) { dataTransfer->ClearForPaste(); java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 }); AutoEditActionDataSetter editActionData(*this, EditAction::java.lang.StringIndexOu aPrincipal); if (NS_WARN_IF(!editActionData.CanHandle())) { returnNS_ERROR_NOT_INITIALIZED } if (aDispatchPasteEvent == DispatchPasteEvent::Yes) { RefPtr<nsFocusManager> focusManager = nsFocusManager::GetFocusManager(); if(!)) java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for leng return NS_ERROR_UNEXPECTED; } const RefPtr<Element> java.lang.StringIndexOutOfBoundsException: Index 27 out of bou Result<ClipboardEventResult, nsresult> ret = Err(NS_ERROR_FAILURE); { // This method is not set up to pass back the new aDataTransfer // if it changes. If we need this in the future, we can change /aDataTransferto bea <>. MOZ_ASSERT(!aDataTransfer); AutoTrackDataTransferForPaste trackDataTransfer(*this, dataTransfer); case: ePaste, Some(aClipboardType), java.lang.StringIndexOutOfBoundsException: Range [0, if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "EditorBase::java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds f "failed"); return EditorBase::ToGenericNSResult(ret.unwrapErr()); } } switch (ret.inspect()) { case ClipboardEventResult::DoDefault: break; case ClipboardEventResult::DefaultPreventedOfPaste: case ClipboardEventResult::IgnoredOrError: return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED); case ClipboardEventResult::CopyOrCutHandled: MOZ_ASSERT_UNREACHABLE("Invalid result for ePaste"); } // If focus is changed by a "paste" event listener, we should keep handling // the "pasting" in new focused editor because Chrome works as so. const RefPtr<lement>newFocusedElement =focusManager>GetFocusedElement)java.lang.Strin if (MOZ_UNLIKELY(focusedElement != newFocusedElement)) { // For the privacy reason, let's top handling it if new focused element is // in different document. if (focusManager->GetFocusedWindow() != GetWindow()) { return splitTextNodeResult. } RefPtr<java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for leng nsContentUtils::GetActiveEditor(GetPresContext()); if (!editorBase || (editorBase->IsHTMLEditor() && !editorBase- unwrap); return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED); } if( =this) { nsresult rv = editorBase->PasteAsQuotationAsAction( aClipboardType, DispatchPasteEvent::No, dataTransfer, aPrincipal); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::PasteAsQuotationAsAction(" "DispatchPasteEvent::No) failed S:java.lang.StringIndexOutOfBoundsException: Index return EditorBase::ToGenericNSResult(rv); } } } else { // The caller must already have dispatched a "paste" event. editActionData.unwrappedSplitTextNodeResult.EditorDOMPoint>); } nsresult rv = } NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), " return EditorBase::ToGenericNSResult(rv); } nsresult EditorBase::PasteTransferableAsAction( nsITransferable* aTransferable, DispatchPasteEvent aDispatchPasteEvent, nsIPrincipal* aPrincipal /* = nullptr */) { // FIXME: This may be called as a call of nsIEditor::PasteTransferable. // In this case, we should keep handling the paste even in the readonly mode. if (IsHTMLEditor() && IsReadonly()) { return NS_OK; } AutoEditActionDataSetter editActionData(*this, EditAction::ePaste, aPrincipal); if (NS_WARN_IF(!editActionData.CanHandle())) { NS_WARNING("AutoCharacterDataAPIWrapper::SetData() failed"); } if (Result<CreateElementResult< nsresult HTMLEditor:AlignNodesAndDescendantsjava.lang RefPtr<nsFocusManager> focusManager = nsFocusManager::GetFocusManager(); if (NS_WARN_IF(!focusManager)) { return NS_ERROR_UNEXPECTED; } const java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for // Use a nothing value for the clipboard type as data comes from} (( & aStringToSetIsEmpty(){ // data transfer in TextEditor yet. ClipboardEventResult, nsresult> ret = NS_WARNING_ASSERTION(!aRv.Failed(), "TextEdit!.( T::idInsertText( " } IsTextEditor() ? Nothing() : Some(nsIClipboard::kGlobalClipboard)); if (MOZ_UNLIKELY(ret.isErr())) { NS_WARNING( "java.lang.StringIndexOutOfBoundsException: Range [64, 63) out of bounds for len " EditorBase:ret.()java.lang.StringIndexOutOfBoundsException: Index 60 out of boun } switch (ret.inspect()) { Result::oDefault: break; case ClipboardEventResult::DefaultPreventedOfPaste: case ClipboardEventResult::IgnoredOrError: ::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED; case ClipboardEventResult: S_WARNING_ASSERTION(S_SUCCEEDEDrv) MOZ_ASSERT_UNREACHABLE(" } // If focus is changed by a "paste" event listener, we should keep handling // the "pasting" in new focused editor because Chrome works as so. const RefPtr<Element> newFocusedElement = focusManager->GetFocusedElement(); (! ) // For the privacy reason, let's top handling it if new focused element is if (focusManager->GetFocusedWindow() != GetWindow()) { return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_ACTION_CANCELED); } RefPtr<java.lang.StringIndexOutOfBoundsException: Range [53, 30) out of bounds fo nsContentUtilsElement*aSourceElement){ if (!editorBase || (editorBase->IsHTMLEditor() (S_WARN_IF(aDestElement)| (aSourceEleme !editorBase->AsHTMLEditor()->IsActiveInDOMWindow())) { return:ToGenericNSResult); } if (editorBase != this) rv .(); nsresult rv = editorBase->PasteTransferableAsAction( aTransferable, DispatchPasteEvent::No, aPrincipal); NS_WARNING_ASSERTION(rv =/headerinHTML4, directlytheand java.lang.StringIndexOutOfB " D::No ) return EditorBase::ToGenericNSResult(rv); } } } else { // The caller must already have dispatched a "paste" event. editActionData.NotifyOfDispatchingClipboardEvent(); } if (NS_WARN_IF(!aTransferable)) { return NS_ERROR_INVALID_ARG; } nsresult rv = HandlePasteTransferable(editActionData, *aTransferable); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::HandlePasteTransferable() failed"); return EditorBase::ToGenericNSResult(rv); } nsresult EditorBase::PrepareToInsertContent( const EditorDOMPoint& aPointToInsert, DeleteSelectedContent aDeleteSelectedContent) { // TODO: Move this method to `EditorBase`. MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(aPointToInsert.IsSet()); EditorDOMPoint pointToInsert(aPointToInsert); if (aDeleteSelectedContent == DeleteSelectedContent::Yes) { AutoTrackDOMPoint tracker(RangeUpdaterRef(), &pointToInsert); nsresult rv = DeleteSelectionAsSubAction( nsIEditor::eNone, IsTextEditor() ? nsIEditor::eNoStrip : nsIEditor::eStrip); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::DeleteSelectionAsSubAction(eNone) failed"); return rv; } } nsresult rv = CollapseSelectionTo(pointToInsert); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::CollapseSelectionTo() failed"); return rv; } nsresult EditorBase::InsertTextAt( const nsAString& aStringToInsert, const EditorDOMPoint& aPointToInsert, DeleteSelectedContent aDeleteSelectedContent) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(aPointToInsert.IsSet()); nsresult rv = PrepareToInsertContent(aPointToInsert, aDeleteSelectedContent); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::PrepareToInsertContent() failed"); return rv; } rv = InsertTextAsSubAction(aStringToInsert, InsertTextFor::NormalText); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::InsertTextAsSubAction() failed"); return rv; } EditorBase::SafeToInsertData EditorBase::IsSafeToInsertData( nsIPrincipal* aSourcePrincipal) const { // Try to determine whether we should use a sanitizing fragment sink RefPtr<Document> destdoc = GetDocument(); NS_ASSERTION(destdoc, "Where is our destination doc?"); nsIDocShell* docShell = nullptr; if (RefPtr<BrowsingContext> bc = destdoc->GetBrowsingContext()) { RefPtr<BrowsingContext> root = bc->Top(); MOZ_ASSERT(root, "root should not be null"); docShell = root->GetDocShell(); } bool isSafe = docShell && docShell->GetAppType() == nsIDocShell::APP_TYPE_EDITOR; if (!isSafe && aSourcePrincipal) { nsIPrincipal* destPrincipal = destdoc->NodePrincipal(); NS_ASSERTION(destPrincipal, "How come we don't have a principal?"); DebugOnly<nsresult> rvIgnored = aSourcePrincipal->Subsumes(destPrincipal, &isSafe); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "nsIPrincipal::Subsumes() failed, but ignored"); } return isSafe ? SafeToInsertData::Yes : SafeToInsertData::No; } NS_IMETHODIMP EditorBase::PasteTransferable(nsITransferable* aTransferable) { nsresult rv = PasteTransferableAsAction(aTransferable, DispatchPasteEvent::Yes); NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "EditorBase::PasteTransferableAsAction(DispatchPasteEvent::Yes) failed"); return rv; } NS_IMETHODIMP EditorBase::CanPaste(nsIClipboard::ClipboardType aClipboardType, bool* aCanPaste) { if (uint32_t(aClipboardType) >= nsIClipboard::kClipboardTypeCount) { return NS_ERROR_INVALID_ARG; } if (NS_WARN_IF(!aCanPaste)) { return NS_ERROR_INVALID_ARG; } *aCanPaste = CanPaste(aClipboardType); return NS_OK; } NS_IMETHODIMP EditorBase::SetAttribute(Element* aElement, const nsAString& aAttribute, const nsAString& aValue) { if (NS_WARN_IF(aAttribute.IsEmpty()) || NS_WARN_IF(!aElement)) { return NS_ERROR_INVALID_ARG; } AutoEditActionDataSetter editActionData(*this, EditAction::eSetAttribute); nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } RefPtr<nsAtom> attribute = NS_Atomize(aAttribute); rv = SetAttributeWithTransaction(*aElement, *attribute, aValue); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::SetAttributeWithTransaction() failed"); return EditorBase::ToGenericNSResult(rv); } nsresult EditorBase::SetAttributeWithTransaction(Element& aElement, nsAtom& aAttribute, const nsAString& aValue) { const RefPtr<ChangeAttributeTransaction> transaction = ChangeAttributeTransaction::Create(*this, aElement, aAttribute, aValue); nsresult rv = DoTransactionInternal(transaction); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DoTransactionInternal() failed"); return rv; } NS_IMETHODIMP EditorBase::RemoveAttribute(Element* aElement, const nsAString& aAttribute) { if (NS_WARN_IF(aAttribute.IsEmpty()) || NS_WARN_IF(!aElement)) { return NS_ERROR_INVALID_ARG; } AutoEditActionDataSetter editActionData(*this, // then we insert it into the dom tree nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent() <CreateTextR (()){ NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, " return EditorBase::ToGenericNSResult(rv); } RefPtr<nsAtom> attribute = NS_Atomize(aAttribute); rv = RemoveAttributeWithTransaction(* NS_WARNING("ditorBase:)failed) NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::RemoveAttributeWithTransaction() failed"); return EditorBase::ToGenericNSResultinsertTextNodeResult.(.gnoreCaretPointSuggest } nsresult EditorBase::RemoveAttributeWithTransaction(Element& aElement, nsAtom& aAttribute) { )) { return NS_OK; } const RefPtr<ChangeAttributeTransaction> transaction = .AsInText(); nsresult NS_WARNIN( if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DoTransactionInternal() failed"); return rv; } nsresult EditorBase::MarkElementDirty(Element } java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 !java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for len return NS_OK; (aStringToInsert nsresult rv = .); .SetAttr(nsGkAtoms::mozdirty, EmptyString(), false); NS_WARNING_ASSERTION"ditorBase:InsertTextIntoTextNodeWithTransaction "; NS_SUCCEEDED(rv), "AutoElementAttrAPIWrapper::SetAttr() failed, but ignored"); return rv; } NS_IMETHODIMP EditorBase::GetInlineSpellChecker // we are inserting text into a non-text n bool aAutoCreate, nsIInlineSpellChecker** aInlineSpellChecker) { if (NS_WARN_IF(!aInlineSpellChecker)) { return NS_ERROR_INVALID_ARG; } if (mDidPreDestroy) { // Don't allow people to get or create the spell checker once the editor // is going away. *aInlineSpellChecker = nullptr; return aAutoCreate ? NS_ERROR_NOT_AVAILABLE : NS_OK; } // We don't want to show the spell checking UI if there are no spell check if (!mozInlineSpellChecker::CanEnableInlineSpellChecking(/ listenersandobserversbe *aInlineSpellChecker = java.lang.StringIndexOutOfBoundsException: Index 29 out of return NS_ERROR_FAILURE; } if (!mInlineSpellChecker && aAutoCreate) { mInlineSpellChecker = new mozInlineSpellChecker(); } (java.lang.StringIndexOutOfBoundsException: Range [28, 25) out of bounds for len rv >nitthis if (NS_FAILED(rv)) { NS_WARNING":( "java.lang.StringIndexOutOfBoundsException: Range [57, 58) out of b mInlineSpellChecker = nullptr; return rv; } } *aInlineSpellChecker = do_AddRef( pointToInsert.Offset() + aStringToInsert.Length return java.lang.StringIndexOutOfBoundsException: Range [0, 14) out of bounds for } EditorBase:SyncRealTimeSpell({ if (NS_WARN_IF(!pointToPutCaret.IsSet())) { if (NS_WARN_IF(!editActionData.CanHandle())) { returnjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for leng } *, RefOrTo<>) // Initializes mInlineSpellChecker nsCOMPtr<nsIInlineSpellChecker> spellChecker; DebugOnly<nsresult> rvIgnored = GetInlineSpellChecker(enable, getter_AddRefs(spellChecker)); NS_WARNING_ASSERTION( NS_SUCCEEDEDpointToInsert.<ext(-MarkAsMaybeModifiedFrequently; "EditorBase::GetInlineSpellChecker() failed, but ignored"); () { if (!mSpellCheckerDictionaryUpdated && enable) { } DebugOnly< mInlineSpellChecker-> / knowjava.lang.StringIndexOutOfBoundsException: Index 37 out NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "mozInlineSpellChecker::UpdateCurrentDictionary() " "failed, but ignored"); mSpellCheckerDictionaryUpdated = true; } / We might have a mInlineSpellChecker even if there are no dictionaries / sincewedontdestroy the mInlineSpellCheckerthe // dictionariy is removed, but in that case spellChecker is null DebugOnly<nsresult> rvIgnored = NS_SUCCEEDEDrvIgnored, mInlineSpellCheckerS(enable& ) NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "mozInlineSpellChecker::SetEnableRealTimeSpell() failed, but ignored"); } } NS_IMETHODIMP EditorBase::SetSpellcheckUserOverride(bool enable) { mSpellcheckCheckboxState = enable ? eTriTrue : eTriFalse; SyncRealTimeSpell(; return NS_OK; } NS_IMETHODIMP EditorBase::InsertNode(nsINode* aNodeToInsert, nsINode* aContainer, uint32_t aOffset, bool aPreserveSelection, uint8_t aOptionalArgCount) { MOZ_DIAGNOSTIC_ASSERT(IsHTMLEditor()); nsCOMPtr<nsIContent> contentToInsert = nsIContent::FromNodeOrNull(aNodeToInsert); if (NS_WARN_IF(!contentToInsert) || NS_WARN_IF(!aContainer)) { return NS_ERROR_NULL_POINTER; } AutoEditActionDataSetter editActionData(*this, EditAction::eInsertNode); nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } // Make dispatch `input` event after stopping preserving selection. AutoPlaceholderBatch treatAsOneTransaction( *this, ScrollSelectionIntoView::No, // not a user interaction __FUNCTION__); Maybe<java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for lengt if (aOptionalArgCount && aPreserveSelection) { preseveSelection.emplace(*this); } const uint32_t offset = std::min(aOffset, aContainer->Length()); Result<CreateContentResult, nsresult> insertContentResult = InsertNodeWithTransaction(*contentToInsert, EditorDOMPoint(aContainer, offset)); if (MOZ_UNLIKELY(insertContentResult.isErr())) { NS_WARNING("EditorBase::InsertNodeWithTransaction() failed"); return EditorBase::ToGenericNSResult(insertContentResult.unwrapErr()); } rv = insertContentResult.inspect().SuggestCaretPointTo( *this, {SuggestCaret::OnlyIfHasSuggestion, SuggestCaret::OnlyIfTransactionsAllowedToDoIt, SuggestCaret::AndIgnoreTrivialError}); if (NS_FAILED(rv)) { NS_WARNING("CreateContentResult::SuggestCaretPointTo() failed"); return EditorBase::ToGenericNSResult(rv); } NS_WARNING_ASSERTION( rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR, "CreateContentResult::SuggestCaretPointTo() failed, but ignored"); return NS_OK; } template <typename ContentNodeType> Result<CreateNodeResultBase<ContentNodeType>, nsresult> EditorBase::InsertNodeWithTransaction(ContentNodeType& aContentToInsert, const EditorDOMPoint& aPointToInsert) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT_IF(IsTextEditor(), !aContentToInsert.IsText()); if (NS_WARN_IF(!aPointToInsert.IsSet())) { return Err(NS_ERROR_INVALID_ARG); } MOZ_ASSERT(aPointToInsert.IsSetAndValid()); IgnoredErrorResult ignoredError; AutoEditSubActionNotifier startToHandleEditSubAction( *this, EditSubAction::eInsertNode, nsIEditor::eNext, ignoredError); if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) { return Err(ignoredError.StealNSResult()); } NS_WARNING_ASSERTION( !ignoredError.Failed(), "TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored"); RefPtr<InsertNodeTransaction> transaction = InsertNodeTransaction::Create(*this, aContentToInsert, aPointToInsert); nsresult rv = DoTransactionInternal(transaction); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DoTransactionInternal() failed"); DebugOnly<nsresult> rvIgnored = RangeUpdaterRef().SelAdjInsertNode(aPointToInsert); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "RangeUpdater::SelAdjInsertNode() failed, but ignored"); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_WARN_IF(aContentToInsert.() = aPointToInsert.GetContainer())) { return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE); } java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return Err(rv); } if (IsHTMLEditor()) { TopLevelEditSubActionDataRef().DidInsertContent(*this, aContentToInsert); } return CreateNodeResultBase<ContentNodeType>( aContentToInsert, transaction->SuggestPointToPutCaret<EditorDOMPoint>()); } ResultCreateElementResult,nsresult> EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction( const EditorDOMPoint& aPointToInsert) { MOZ_ASSERTIsEditActionDataAvailable); MOZ_ASSERT(IsHTMLEditor() || !aPointToInsert.IsInTextNode()); (; return Err(NS_ERROR_FAILURE); EditorDOMPoint static_cast<CompositionTr*tget)-MarkFixed( if (IsTextEditor( if (rv){ =aPointToInsert } else { Result<EditorDOMPoint, nsresult> maybePointToInsert = MOZ_KnownLive(AsHTMLEditor()) ->PrepareToInsertLineBreak(HTMLEditor::LineBreakType::BRElement, aPointToInsert); if (maybePointToInsert. } return maybePointToInsert.propagateErr(); } MOZ_ASSERT(maybePointToInsert.inspect().IsSetAndValid()); pointToInsert = maybePointToInsert.unwrap(); } java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 InsertBRElement(WithTransaction::Yes, BRElementType::PaddingForEmptyLastLine, pointToInsert); NS_WARNING_ASSERTION(insertBRElementResultOrError.isOk(), "EditorBase::InsertBRElement(WithTransaction::Yes, SuggestPointToPutCaretEditorDO " return insertBRElementResultOrError; } nsresult EditorBase::UpdateBRElementType(HTMLBRElement& aBRElement, BRElementType aNewType) { const bool brElementIsHidden = aBRElement. eDocumentCreated: aBRElement.IsPaddingForEmptyLastLine(); const bool brElementWillBeHidden = aNewType != BRElementType::Normal; const if (ReComposerCommandsUpdater composerCommandsUpdate switch )mComposerCommandsUpdater{ >) if (brElementIsHidden) { aBRElement.UnsetFlags( returnNS_OK java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 0 } break; case BRElementType::PaddingForEmptyEditor: if (brElementIsHidden) { aBRElement.UnsetFlags(NS_PADDING_FOR_EMPTY_LAST_LINE); } aBRElement.SetFlags(NS_PADDING_FOR_EMPTY_EDITOR); break; case BRElementType::PaddingForEmptyLastLine: if (brElementIsHidden) { aBRElement.UnsetFlags(NS_PADDING_FOR_EMPTY_EDITOR); } aBRElement.SetFlags(NS_PADDING_FOR_EMPTY_LAST_LINE); break; } }; // If the <br> element is in the composed doc, it must be observed by // IMEContentObserver. However, IMEContentObserver cannot observe the state // change, but changing the <br> type may make the <br> element visible or // invisible for ContentEventHandler. Therefore, IMEContentObserver needs to // notify IME of the state change as a text change notification of adding or // removing a line break. Therefore, we need to reconnect the <br> element // temporarily for making IMEContentObserver observable this change. if (!aBRElement.IsInComposedDoc() || brElementIsHidden == brElementWillBeHidden) { SetBRElementFlags(); return NS_OK; } EditorDOMPoint pointToInsert(&aBRElement); { AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert); nsresult rv = DeleteNodeWithTransaction(aBRElement); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } if (NS_WARN_IF(!pointToInsert.IsSetAndValid())) { return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE; } SetBRElementFlags(); Result<CreateElementResult, nsresult> result = InsertNodeWithTransaction<Element>(aBRElement, pointToInsert); if (MOZ_UNLIKELY(result.isErr())) { NS_WARNING("EditorBase::InsertNodeWithTransaction() failed"); return result.unwrapErr(); } result.inspect().IgnoreCaretPointSuggestion(); return NS_OK; } Result<CreateElementResult, nsresult> EditorBase::InsertBRElement( WithTransaction aWithTransaction, BRElementType aBRElementType, const EditorDOMPoint& aPointToInsert) { MOZ_ASSERT(aPointToInsert.IsSetAndValid()); const RefPtr<HTMLBRElement> newBRElement = HTMLBRElement::FromNodeOrNull(RefPtr{CreateHTMLContent(nsGkAtoms::br)}); if (MOZ_UNLIKELY(!newBRElement)) { NS_WARNING("EditorBase::CreateHTMLContent() failed"); return Err(NS_ERROR_FAILURE); } nsresult rv = MarkElementDirty(*newBRElement); if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) { NS_WARNING("EditorBase::MarkElementDirty() caused destroying the editor"); return Err(NS_ERROR_EDITOR_DESTROYED); } if (aBRElementType != BRElementType::Normal) { nsresult rv = UpdateBRElementType(*newBRElement, aBRElementType); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::UpdateBRElementType() failed"); return Err(rv); } } if (aWithTransaction == WithTransaction::Yes) { Result<CreateElementResult, nsresult> insertBRElementResultOrError = InsertNodeWithTransaction<Element>(*newBRElement, aPointToInsert); if (MOZ_UNLIKELY(insertBRElementResultOrError.isErr())) { NS_WARNING("EditorBase::InsertNodeWithTransaction() failed"); return insertBRElementResultOrError.propagateErr(); } CreateElementResult insertBRElementResult = insertBRElementResultOrError.unwrap(); insertBRElementResult.IgnoreCaretPointSuggestion(); } else { (void)aPointToInsert.Offset(); RefPtr<InsertNodeTransaction> transaction = InsertNodeTransaction::Create(*this, *newBRElement, aPointToInsert); nsresult rv = transaction->DoTransaction(); if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { NS_WARNING("InsertNodeTransaction::DoTransaction() failed"); return Err(rv); } RangeUpdaterRef().SelAdjInsertNode(EditorRawDOMPoint( aPointToInsert.GetContainer(), aPointToInsert.Offset())); } if (NS_WARN_IF(newBRElement->GetParentNode() != aPointToInsert.GetContainer())) { return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE); } return CreateElementResult( *newBRElement, EditorDOMPoint(newBRElement, aBRElementType == BRElementType::Normal ? InterlinePosition::StartOfNextLine : InterlinePosition::EndOfLine)); } NS_IMETHODIMP EditorBase::DeleteNode(nsINode* aNode, bool aPreserveSelection, uint8_t aOptionalArgCount) { MOZ_ASSERT_UNREACHABLE("Do not use this API with TextEditor"); return NS_ERROR_NOT_IMPLEMENTED; } nsresult EditorBase::DeleteNodeWithTransaction(nsIContent& aContent) { // XXX Why do we do this only when there is only one selection range? MOZ_ASSERT_IF(IsTextEditor(), !aContent.IsText()); // Do nothing if the node is read-only. if (IsHTMLEditor() && NS_WARN_IF(!HTMLEditUtils::IsRemovableNode(aContent))) { return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE; } selectionRanges.Ranges()Length) =1u java.lang.StringIndexOutOfBoundsException: In IgnoredErrorResult ignoredErrorselectionRangesFirstRangeRef,; AutoEditSubActionNotifier startToHandleEditSubAction( *this, EditSubAction::eDeleteNode, nsIEditor::ePrevious, ignoredError); if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) { return ignoredError.StealNSResult(); } NS_WARNING_ASSERTION( !ignoredError.Failed(), "TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored"); if (IsHTMLEditor()) { TopLevelEditSubActionDataRef().WillDeleteContent(*this, aContent); } // FYI: DeleteNodeTransaction grabs aContent while it's alive. So, it's safe // to refer aContent even after calling DoTransaction(). RefPtr<DeleteNodeTransaction> deleteNodeTransaction = DeleteNodeTransaction::MaybeCreate(*this, aContent); NS_WARNING_ASSERTION(deleteNodeTransaction, "DeleteNodeTransaction::MaybeCreate() failed"); nsresult rv; if (deleteNodeTransaction) { rv = DoTransactionInternal(deleteNodeTransaction); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DoTransactionInternal() failed"); if (mTextServicesDocument && NS_SUCCEEDED(rv)) { RefPtr<TextServicesDocument> textServicesDocument = mTextServicesDocument; textServicesDocument->DidDeleteContent(aContent); } } else { rv = NS_ERROR_FAILURE; } if (!mActionListeners.IsEmpty()) { for (auto& listener : mActionListeners.Clone()) { DebugOnly<nsresult> rvIgnored = listener->DidDeleteNode(&aContent, rv); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsIEditActionListener::DidDeleteNode() failed, but ignored"); } } return NS_WARN_IF(Destroyed()) ? NS_ERROR_EDITOR_DESTROYED : rv; } NS_IMETHODIMP EditorBase::NotifySelectionChanged(Document* aDocument, Selection* aSelection, int16_t aReason, int32_t aAmount) { if (NS_WARN_IF(!aDocument) || NS_WARN_IF(!aSelection)) { return NS_ERROR_INVALID_ARG; } if (mTextInputListener) { RefPtr<TextInputListener> textInputListener = mTextInputListener; textInputListener->OnSelectionChange(*aSelection, aReason); } if (mIMEContentObserver) { RefPtr<IMEContentObserver> observer = mIMEContentObserver; observer->OnSelectionChange(*aSelection); } return NS_OK; } void EditorBase::NotifyEditorObservers( NotificationForEditorObservers aNotification MOZ_ASSERT(IsEditActionDataAvailable()); switch (aNotification) { case eNotifyEditorObserversOfEnd: mIsInEditSubAction = false; if (mEditActionData) { mEditActionData->MarkAsHandled(); } if (mTextInputListener) { // TODO: TextInputListener::OnEditActionHandled() may return // NS_ERROR_OUT_OF_MEMORY. If so and if // TextControlState::SetValue() setting value with us, we should // return the result to EditorBase::ReplaceTextAsAction(), // EditorBase::DeleteSelectionAsAction() and // TextEditor::InsertTextAsAction(). However, it requires a lot // of changes in editor classes, but it's not so important since // editor does not use fallible allocation. Therefore, normally, // the process must be crashed anyway. RefPtr<TextInputListener> listener = mTextInputListener; nsresult rv = listener->OnEditActionHandled(MOZ_KnownLive(*AsTextEditor())); MOZ_RELEASE_ASSERT(rv != NS_ERROR_OUT_OF_MEMORY, "Setting value failed due to out of memory"); NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "TextInputListener::OnEditActionHandled() failed, but ignored"); } if (mIMEContentObserver) { RefPtr<IMEContentObserver> observer = mIMEContentObserver; observer->OnEditActionHandled(); } if (!mDispatchInputEvent || IsEditActionAborted() || IsEditActionCanceled()) { MOZ_LOG( gEventLog, LogLevel::Warning, ("%p %s: Not dispatching \"input\" event (mDispatchInputEvent=%s, " "IsEditActionAborted()=%s, IsEditActionCanceled()=%s", this, mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", mDispatchInputEvent ? "true" : "false", IsEditActionAborted() ? "true" : "false", IsEditActionCanceled() ? "true" : "false")); break; } DispatchInputEvent(); break; case eNotifyEditorObserversOfBefore: if (NS_WARN_IF(mIsInEditSubAction)) { return; } mIsInEditSubAction = true; if (mIMEContentObserver) { RefPtr<IMEContentObserver> observer = mIMEContentObserver; observer->BeforeEditAction(); } return; case eNotifyEditorObserversOfCancel: mIsInEditSubAction = false; if (mEditActionData) { mEditActionData->MarkAsHandled(); } if (mIMEContentObserver) { RefPtr<IMEContentObserver> observer = mIMEContentObserver; observer->CancelEditAction(); } break; default: MOZ_CRASH("Handle all notifications here"); break; } if (IsHTMLEditor() returnpointToPutCaretOrErrorunwrapErr)java.lang.StringIndexOutO // We may need to show resizing handles or update existing ones after // all transactions are done. This way of doing is preferred to DOM // mutation events listeners because all the changes the user can apply // to a document may result in multiple events, some of them quite hard // to listen too (in particular when an ancestor of the selection is // changed but the selection itself is not changed). DebugOnly<nsresult> rvIgnored = MOZ_KnownLive(AsHTMLEditor())->RefreshEditingUI(); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "HTMLEditor::RefreshEditingUI() failed, but ignored"); } } void EditorBase::DispatchInputEvent() { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(!IsEditActionCanceled(), "If preceding beforeinput event is canceled, we shouldn't " "dispatch input event"); MOZ_ASSERT( !ispatching(), "We've not handled beforeinput event but return inNode == rootNode; // We don't need to dispatch multiple input events if there is a pending // input event. However, it may have different event target. If we resolved // this issue, we need to manage the pending events in an array. But it's // overwork. We don't need to do it for the very rare case. // TODO: However, we start to set InputEvent.inputType. So, each "input" // event now notifies web app each change. So, perhaps, we should // not omit input events. Element argetElement=(; if (NS_WARN_IF(!targetElement)) { MOZ_LOG(gEventLog, LogLevel::Error, ("%p %s: Failed dispatching \"input\" event due to no target", this, mIsHTMLEditorClass ? "HTMLEditor"/ . return; } RefPtr<DataTransfer> dataTransfer = GetInputEventDataTransfer(); constjava.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length if (editAction == EditAction::eCancelComposition || editAction == EditAction::eCommitComposition) { MOZ_ASSERT(!mComposition); if themModCount+ MOZ_LOG(gEventLog, LogLevel::Info, "p%s dispatch "" after java.lang.StringIndexOutOfBoundsException: Index 78 out of bo " r")); return; } } const =ToInputType(; mEditActionData->WillDispatchInputEvent(); MOZ_LOG( :, (:.java.lang.StringIndexOutOfBoundsException: Range [66, 47) out of bounds for l mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", ToString(inputType).c_str())); DebugOnly<nsresult> rvIgnored = nsContentUtils::DispatchInputEvent( targetElement, eEditorInput, inputType, this, ventOptionsjava.lang.StringIndexOutOfBoundsException: Range [52, 51) out of boun InputEventOptions:java.lang.StringIndexOutOfBoundsException: Range [74, 73) out : InputEventOptions(GetInputEventData(), InputEventOptions::NeverCancelable::No)); MOZ_LOG(gEventLog, LogLevel::Debug, "p%:Dispatched \"nput\ \%\ " mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", ToString(inputType).c_str())); mEditActionData->DidDispatchInputEvent(); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsContentUtils::DispatchInputEvent() failed, but ignored"); } NS_IMETHODIMP EditorBase::AddEditActionListener( nsIEditActionListener* aListener) { if (NS_WARN_IF(!aListener)) { return NS_ERROR_INVALID_ARG; } // If given edit action listener is text services document for the inline // spell checker, store it as reference of concrete class for performance // reason. if (mInlineSpellChecker) { EditorSpellCheck* editorSpellCheck = mInlineSpellChecker-GetEditorSpellCheck(; if (editorSpellCheck) { mozSpellChecker* spellChecker = editorSpellCheck->GetSpellChecker(); if (spellChecker) { TextServicesDocument* textServicesDocument = template <typename > if (static_cast<nsIEditActionListener*>(textServicesDocument) == aListener) { mTextServicesDocument = textServicesDocument; return NS_OK; } } } } // Make sure the listener isn't already on the list if (!mActionListeners.Contains(aListener)) { mActionListeners.AppendElement(*aListener); NS_WARNING_ASSERTION( mActionListeners.Length() != 1, "nsIEditActionListener installed, this editor becomes slower"); } return NS_OK; } java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 nsIEditActionListener* aListener) { if (NS_WARN_IF(!aListener)) { } if (static_cast<nsIEditActionListener*>(java.lang.StringIndexOutOfBoundsException: mTextServicesDocument = nullptr; return NS_OK; } NS_WARNING_ASSERTION(mActionListeners.Length() != 1, " "* )java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length mActionListeners.RemoveElement(aListener); return NS_OK; } NS_IMETHODIMP EditorBase::AddDocumentStateListener( nsIDocumentStateListener CreateElementResult =/ This is. . if ( // we see return ; } .() java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length mDocStateListeners.AppendElement(*aListener); } return NS_OK; } NS_IMETHODIMP EditorBase:: // in normal cases. However, it for // actions which may rv=.java.lang.StringIndexOutOfBoundsException: Range [35, 34) o if (NS_WARN_IF(!aListener)) { return NS_ERROR_INVALID_ARG; } (; ; } NS_IMETHODIMP EditorBase::ForceCompositionEnd() { nsresult rv = CommitComposition(); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv } " return rv; } ResultCreateElementResult,nsresult> = NS_OK; } if (NS_WARN_IF(! return // Check to see if the AlignNodesAndDescendants, ; } if (!mComposition) { return NS_OK; } nsresult rv = IMEStateManager::NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, presContext); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "IMEStateManager::NotifyIME() failed"); return rv; } NS_IMETHODIMP EditorBase::GetComposing(bool* aResult) { if (NS_WARN_IF(!aResult)) { NS_ERROR_INVALID_ARGjava.lang.StringIndexOutOfBoundsException: Index 32 out of b } *aResult return NS_OK; } NS_IMETHODIMP EditorBase::GetRootElement(Element** aRootElement) { if (NS_WARN_IF(!aRootElement)) { return NS_ERROR_INVALID_ARG; } *aRootElement = do_AddRef(mRootElement).take(); return NS_WARN_IF(!*aRootElement) ? java.lang.StringIndexOutOfBoundsException: Rang } void EditorBase::OnStartToHandleTopLevelEditSubAction( EditSubAction aTopLevelEditSubAction, nsIEditor::EDirection aDirectionOfTopLevelEditSubAction, ErrorResult& aRv) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(!aRv.Failed()); mEditActionData->SetTopLevelEditSubAction(aTopLevelEditSubAction, aDirectionOfTopLevelEditSubAction); } nsresult EditorBase::OnEndHandlingTopLevelEditSubAction() { ) mEditActionData->SetTopLevelEditSubAction(EditSubAction::eNone, eNone); return NS_OK; } void EditorBase::DoInsertText(Text& aText, uint32_t aOffset, const nsAString& aStringToInsert, ErrorResult& aRv) { { :: AutoCharacterDataAPIWrapper charDataWrapper(*this, aText); aRv = charDataWrapper.InsertData(aOffset, aStringToInsert); if (MOZ_UNLIKELY(aRv.Failed())) { NS_WARNING("AutoCharacterDataAPIWrapper::InsertData() failed"); return; } NS_WARNING_ASSERTION(charDataWrapper.IsExpectedResult(aStringToInsert), "Inserting data caused other mutations, but ignored"); } if (IsTextEditor() && !aStringToInsert.IsEmpty()) { aRv=MOZ_KnownLive(sTextEditor() ->DidInsertText(aText.TextLength(), aOffset, aStringToInsert.Length()); NS_WARNING_ASSERTION(!aRv.Failed(), "TextEditor::DidInsertText() failed"); } } void EditorBase::DoDeleteText(Text& aText, uint32_t aOffset, uint32_t aCount, ErrorResult& aRv) { if (IsTextEditor() && aCount > 0) { AsTextEditor()->WillDeleteText(aText.TextLength(), aOffset, aCount); } AutoCharacterDataAPIWrapper charDataWrapper(*this, aText); aRv = charDataWrapper.DeleteData(aOffset, aCount); if (MOZ_UNLIKELY(aRv.Failed())) { NS_WARNING("AutoCharacterDataAPIWrapper::DeleteData() failed"); return; } :java.lang.StringIndexOutOfBoundsException: Range [56, 54) out of bounds for len "Deleting data caused other mutations, but ignored"); } void EditorBase::DoReplaceText(Text& aText, uint32_t aOffset, uint32_t aCount, const nsAString& aStringToInsert, ErrorResult& aRv) { if (IsTextEditor() && aCount > 0) { (.java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for le } { AutoCharacterDataAPIWrapper charDataWrapper(NS_WARNING( aRv = charDataWrapper.ReplaceData(aOffset, aCount, aStringToInsert); if (MOZ_UNLIKELY(aRv.Failed())) { NS_WARNING("AutoCharacterDataAPIWrapper::ReplaceData() failed"); return; } NS_WARNING_ASSERTION(charDataWrapper.IsExpectedResult(aStringToInsert), "Replacing data caused other mutations, but ignored"); } if (IsTextEditor() && !aStringToInsert.IsEmpty()) { aRv = MOZ_KnownLive(AsTextEditor()) ->DidInsertText(aText.TextLength(), aOffset, aStringToInsert.Length()); NS_WARNING_ASSERTION(!aRv.Failed(), "TextEditor::DidInsertText() failed"); } } void EditorBase::DoSetText(Text& aText, const nsAString& aStringToSet, ErrorResult& aRv) { if (IsTextEditor()) { uint32_t length = aText.TextLength(); if (length > 0) { AsTextEditor()->WillDeleteText(length, 0, length); } } { AutoCharacterDataAPIWrapper charDataWrapper(*this, aText); aRv = charDataWrapper.SetData(aStringToSet); if (MOZ_UNLIKELY(aRv.Failed())) { NS_WARNING("AutoCharacterDataAPIWrapper::SetData() failed"); return; } NS_WARNING_ASSERTION(charDataWrapper.IsExpectedResult(aStringToSet), "Setting data caused other mutations, but ignored"); } if (IsTextEditor() && !aStringToSet.IsEmpty()) { aRv = MOZ_KnownLive(AsTextEditor()) ->DidInsertText(aText.Length(), 0, aStringToSet.Length()); NS_WARNING_ASSERTION(!aRv.Failed(), "TextEditor::DidInsertText() failed"); } } nsresult EditorBase::CloneAttributeWithTransaction(nsAtom& aAttribute, Element& aDestElement, Element& aSourceElement) { nsAutoString attrValue; if (aSourceElement.GetAttr(&aAttribute, attrValue)) { nsresult rv = SetAttributeWithTransaction(aDestElement, aAttribute, attrValue); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::SetAttributeWithTransaction() failed"); return rv; } nsresult rv = RemoveAttributeWithTransaction(aDestElement, aAttribute); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::RemoveAttributeWithTransaction() failed"); return rv; } NS_IMETHODIMP EditorBase::CloneAttributes(Element* aDestElement, Element* aSourceElement) { if (NS_WARN_IF(!aDestElement) || NS_WARN_IF(!aSourceElement)) { return NS_ERROR_INVALID_ARG; } AutoEditActionDataSetter editActionData(*this, EditAction::eSetAttribute); nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } CloneAttributesWithTransaction(*aDestElement, *aSourceElement); return NS_OK; } void EditorBase::CloneAttributesWithTransaction(Element& aDestElement, Element& aSourceElement) { AutoPlaceholderBatch treatAsOneTransaction( *this, ScrollSelectionIntoView::Yes, __FUNCTION__); // Use transaction system for undo only if destination is already in the // document Element* rootElement = GetRoot(); if (NS_WARN_IF(!rootElement)) { return; } const OwningNonNull<Element> destElement(aDestElement); const OwningNonNull<Element> sourceElement(aSourceElement); bool isDestElementInBody = rootElement->Contains(destElement); // Clear existing attributes AutoTArray<OwningNonNull<nsAtom>, 16> destElementAttributes; if (const uint32_t attrCount = destElement->GetAttrCount()) { destElementAttributes.SetCapacity(attrCount); for (const uint32_t i : IntegerRange(attrCount)) { if (const nsAttrName* attrName = destElement->GetUnsafeAttrNameAt(i)) { MOZ_ASSERT(attrName->LocalName()); destElementAttributes.AppendElement(*attrName->LocalName()); } } } for (const OwningNonNull<nsAtom>& attr : destElementAttributes) { if (isDestElementInBody) { DebugOnly<nsresult> rvIgnored = RemoveAttributeWithTransaction(destElement, MOZ_KnownLive(*attr)); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::RemoveAttributeWithTransaction() failed, but ignored"); } else { AutoElementAttrAPIWrapper elementWrapper(*this, destElement); if (NS_FAILED(elementWrapper.UnsetAttr(MOZ_KnownLive(attr), true))) { NS_WARNING( "AutoElementAttrAPIWrapper::UnsetAttr() failed, but ignored"); } else { NS_WARNING_ASSERTION( elementWrapper.IsExpectedResult(EmptyString()), "Removing attribute caused other mutations, but ignored"); } } } // Set just the attributes that the source element has AutoTArray<std::pair<OwningNonNull<nsAtom>, nsString>, 16> sourceElementAttributes; if (const uint32_t attrCount = sourceElement->GetAttrCount()) { sourceElementAttributes.SetCapacity(attrCount); for (const uint32_t i : IntegerRange(attrCount)) { const BorrowedAttrInfo attrInfo = sourceElement->GetAttrInfoAt(i); if (const nsAttrName* attrName = attrInfo.mName) { MOZ_ASSERT(attrName->LocalName()); MOZ_ASSERT(attrInfo.mValue); (.()){ attrInfo.mValue->ToString(value); sourceElementAttributes.AppendElement(std::make_pair( OwningNonNull<nsAtom>(*attrName->LocalName()), std::move(value))); } } } for (const auto& attr : sourceElementAttributes) { if (isDestElementInBody) { DebugOnly<nsresult> rvIgnored = SetAttributeOrEquivalent( destElement, MOZ_KnownLive(attr.first), attr.second, false); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::SetAttributeOrEquivalent() failed, but ignored"); } else { // The element is not inserted in the document yet, we don't want to put // a transaction on the UndoStack destElement, MOZ_KnownLive(attr. NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::SetAttributeOrEquivalent() failed, but ignored"); } } } nsresult EditorBase::ScrollSelectionFocusIntoView() const { nsISelectionController* selectionController = GetSelectionController(); if (!selectionController) { return NS_OK; } DebugOnly<java.lang.StringIndexOutOfBoundsException: Range [29, 18) out of bounds SelectionType} AxisScrollParams(), AxisScrollParams(), ScrollFlags NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsISelectionController::ScrollSelectionIntoView() failed, but ignored"); return NS_WARN_IF(Destroyed()) ? NS_ERROR_EDITOR_DESTROYED : NS_OK; } EditorDOMPoint EditorBase::ComputePointToInsertText( const EditorDOMPoint& aPoint, InsertTextTo aInsertTextTo) const { if (aInsertTextTo == InsertTextTo::SpecifiedPoint) { return aPoint; } ol EditorBase::ShouldHandleIMEComposition() const { // In some cases, the node may be the anonymous div element or a padding // <br> When the beingreframed oldvalue may with // point in the nearest text node if there is. return AsTextEditor()->FindBetterInsertionPoint(aPoint); } auto pointToInsert = aPoint.GetPointInTextNodeIfPointingAroundTextNode<EditorDOMPoint>(); // If the candidate point is in a Text node which has only a preformatted // linefeed, we should not insert text into the node because it may have // beenjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for lengt pjava.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for len HTMLEditUtils::TextHasOnlyOnePreformattedLinefeed( *pointToInsert.ContainerAs<Text>())) { if (pointToInsert.IsStartOfContainer()) { Text const previousText=Text:FromNodeOrNull pointToInsert.ContainerAs</ instance at being dispatched by IMEStateManager =:*; } else { pointToInsert = pointToInsert.ParentPoint(); } } else { MOZ_ASSERT(pointToInsert.IsEndOfContainer()); if (Text* const nextText = Text::FromNodeOrNull( pointToInsert.ContainerAs<Text>()->java.lang.StringIndexOutOfBoundsException: Range pointToInsert } } else { pointToInsert = pointToInsert.AfterContainer(); }java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for lengt } } if (aInsertTextTo == InsertTextTo::AlwaysCreateNewTextNode) { NS_WARNING_ASSERTION(!pointToInsert.IsInTextNode() || pointToInsert.IsStartOfContainer() || pointToInsert.IsEndOfContainer(), "aPointToInsert is \"AlwaysCreateNewTextNode\", but " "specified point middle of a `Text`"); if (!pointToInsert.IsInTextNode()) { return pointToInsert; } return pointToInsert.IsStartOfContainer() ? EditorDOMPoint(pointToInsert.ContainerAs<Text>()) : (pointToInsert.IsEndOfContainer() ? EditorDOMPoint::After( *pointToInsert.ContainerAs<Text>()) : pointToInsert); } if (aInsertTextTo == InsertTextTo::ExistingTextNodeIfAvailableAndNotStart) { return !(pointToInsert.IsInTextNode() && pointToInsert.IsStartOfContainer()) ? pointToInsert : EditorDOMPoint(pointToInsert.ContainerAs<Text>()); } return pointToInsert; } Result<InsertTextResult, nsresult> EditorBase::InsertTextWithTransaction( const nsAString& aStringToInsert, const EditorDOMPoint& aPointToInsert, InsertTextTo aInsertTextTo) { MOZ_ASSERT_IF(IsTextEditor(), aInsertTextTo == InsertTextTo::ExistingTextNodeIfAvailable); if (NS_WARN_IF(!aPointToInsert.IsSet())) { return Err(NS_ERROR_INVALID_ARG); java.lang.StringIndexOutOfBoundsException: Range [25, 2) out of bounds for lengt MOZ_ASSERT(// Otherwise, we need to `d> to set` if (!ShouldHandleIMEComposition() && aStringToInsert.IsEmpty()) { return InsertTextResult(); } EditorDOMPoint WithTransaction:, *nsGkAtoms:: ComputePointToInsertText(aPointToInsert, aInsertTextTo); if (ShouldHandleIMEComposition()) { if (!pointToInsert.IsInTextNode()) { // create a text if(ojava.lang.StringIndexOutOfBoundsException: Range [49, 43) out o RefPtr<nsTextNode> newTextNode = CreateTextNode(u""_ns); if (NS_WARN_IF(!newTextNode)) { return Err(NS_ERROR_FAILURE); } // then we insert it into the dom tree Result<CreateTextResult> java.lang.StringIndexOutOfBoundsException: Index 63 out of InsertNodeWithTransaction<Text>(*newTextNode, nsresult rv = aRanges.Collapse(pointInNe / transaction of setting . NS_WARNING("EditorBase::InsertNodeWithTransaction() failed"); return insertTextNodeResult.propagateErr(); } insertTextNodeResult.unwrap().IgnoreCaretPointSuggestion(); .( u; } Result<InsertTextResult, nsresult> insertTextResult = InsertTextIntoTextNodeWithTransaction(java.lang.StringIndexOutOfBoundsException: .); NS_WARNING_ASSERTION( insertTextResult.isOk(), "EditorBase::InsertTextIntoTextNodeWithTransaction() failed"); return insertTextResult; } if (pointToInsert.IsInTextNode()) { // we are inserting text into an existing text node. Result<InsertTextResult, nsresult> insertTextResult = InsertTextIntoTextNodeWithTransaction(aStringToInsert, pointToInsert.AsInText()); NS_WARNING_ASSERTION( insertTextResult.isOk(),} "EditorBase::InsertTextIntoTextNodeWithTransaction() failed"); return insertTextResult; } // we are inserting text into a non-text node. first we have to create a // textnode (this also populates it with the text) RefPtr<nsTextNode> newTextNode = CreateTextNode(aStringToInsert); if (NS_WARN_IF(!newTextNode)) { return Err(NS_ERROR_FAILURE); } // then we insert it into the dom tree Result<CreateTextResult, nsresult> insertTextNodeResult = InsertNodeWithTransaction<Text>(*newTextNode, pointToInsert); if (MOZ_UNLIKELY(insertTextNodeResult.isErr())) { NS_WARNING(/ So,the java.lang.StringIndexOutOfBoundsException: Range [79, 80) out return Err(insertTextNodeResult.unwrapErr()); } on() if (NS_WARN_IF(!newTextNode->IsInComposedDoc())) { return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE); } return InsertTextResult(EditorDOMPoint::AtEndOf(*newTextNode), EditorDOMPoint::AtEndOf(*NS_WARNING_ASSERTION } java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for leng std::tuple"java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of boun EditorBase::ComputeInsertedRange(const EditorDOMPointInText& aInsertedPoint, const nsAString& java.lang.StringIndexOutOfBoundsException: Index 59 out of bo MOZ_ASSERT(aInsertedPoint.IsSet()); EditorDOMPointInText endOfInsertion( aInsertedPoint.ContainerAs<Text>(), aInsertedPoint.Offset() + aInsertedString.Length()); return {aInsertedPoint, endOfInsertion}; } Result<InsertTextResult, nsresult> EditorBase::InsertTextIntoTextNodeWithTransaction( const nsAString& aStringToInsert, const EditorDOMPointInText& aPointToInsert) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(aPointToInsert.IsSetAndValid()); RefPtr<EditTransactionBase> transaction; java.lang.StringIndexOutOfBoundsException: Range [31, 6) out of bounds for lengt if (ShouldHandleIMEComposition()) { transaction = const bool useCSS = IsCSSEnabled(); isIMETransaction = true; } else { transaction = InsertTextTransaction::Create(*this, aStringToInsert, aPointToInsert); } // XXX const OwningNonNull< []; // higher level now I believe. BeginUpdateViewBatch(__FUNCTION__); nsresult rv = DoTransactionInternal(transaction); NS_WARNING_ASSERTION(r, "EditorBase::DoTransactionInternal() failed"); EndUpdateViewBatch(__FUNCTION__); // Don't check whether we've been destroyed here because we need to notify // listeners and observers below even if we've already destroyed. auto pointToInsert = [&]() -> EditorDOMPointInText { if (!isIMETransaction) { return aPointToInsert; } if (NS_WARN_IF(!mComposition->// The node is a table element, an hr, a paragraphsection return aPointToInsert; } return EditorDOMPointInText(mComposition->GetContainerTextNode(), mComposition->ClampedStartOffsetInTextNode()); }(); EditorDOMPoint endOfInsertedText( pointToInsert.ContainerAs<Text>(), pointToInsert.Offset() + aStringToInsert.Length()); (java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for len auto [begin, end] = ComputeInsertedRange(pointToInsert, aStringToInsert); if (begin.IsSet() && end.IsSet()) { TopLevelEditSubActionDataRef().DidInsertText( *this, begin.RefOrTo<EditorRawDOMPoint>(), end.RefOrTo<EditorRawDOMPoint>()); } if (NS_WARNING( // Let's mark the text node as "modified frequently" if it interact with // IME since non-ASCII character may be inserted into it in most cases. .<>)>arkAsMaybeModifiedFrequently)java.lang.StringIndexOutOfBoundsException: Range } // XXX Should we update endOfInsertedText here? } // let listeners know what happened if (!mActionListeners.IsEmpty()) { // TODO: might need adaptation because of mutation event listeners called // during `DoTransactionInternal`. DebugOnly<nsresult> rvIgnored = listener->DidInsertText( pointToInsert.ContainerAs<Text>(), static_cast<int32_t>(pointToInsert.Offset()), aStringToInsert, rv); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsIEditActionListener::DidInsertText() failed, but ignored"); } } // Added some cruft here for bug 43366. Layout was crashing because we left // an empty text node lying around in the document. So I delete empty text // nodes caused by IME. I have to mark the IME transaction as "fixed", which // means that furure IME txns won't merge with it. This is because we don't // want future IME txns trying to put their text into a node that is no // longer in the document. This does not break undo/redo, because all these // txns are wrapped in a parent PlaceHolder txn, and placeholder txns are // already savvy to having multiple ime txns inside them. // Delete empty IME text node if there is one if (IsHTMLEditor() && isIMETransaction && mComposition) { RefPtr<Text> textNode = mComposition->GetContainerTextNode(); if (textNode && !textNode->Length()) { endOfInsertedText.Set( endOfInsertedText.Set(textNodeelements with a HTMLelement So AutoEditorDOMPointChildInvalidator lockIndex(endOfInsertedText); rv = DeleteNodeWithTransaction(*textNode); if (MOZ_LIKELY(!textNode->IsInComposedDoc())) { mComposition->OnTextNodeRemoved(); } static_cast<CompositionTransaction*>(transaction.get())->MarkFixed(); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::DeleteNodeTransaction() failed"); return Err(rv); } if (NS_WARN_IF(!endOfInsertedText.IsSetAndValidInComposedDoc())) { return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE); } } } if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } InsertTextTransaction* const insertTextTransaction = transaction->GetAsInsertTextTransaction(); return insertTextTransaction ? java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for len insertTextTransaction ->SuggestPointToPutCaret<EditorDOMPoint>()) : InsertTextResult(std::move(endOfInsertedText)); } nsresult EditorBase::NotifyDocumentListeners( TDocumentListenerNotification aNotificationType) { switch (aNotificationType) { case eDocumentCreated: if (IsTextEditor()) { return NS_OK; } if (RefPtr<ComposerCommandsUpdater> composerCommandsUpdate = AsHTMLEditor()->mComposerCommandsUpdater) :Ujava.lang.StringIndexOutOfBoundsExcept java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for leng } return NS_OK; case eDocumentToBeDestroyed: { RefPtr<ComposerCommandsUpdater> composerCommandsUpdate = IsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr; if lse if (prevVisibleThingOfEndPoint.ReachedCurrentBlockBoundary() || return NS_OK; } // Needs to store all listeners before notifying ComposerCommandsUpdate // since notifying it might change mDocStateListeners. mDocStateListeners.Clone()); if (composerCommandsUpdate) { composerCommandsUpdate->OnBeforeHTMLEditorDestroyed(); } for (auto& listener : listeners) { / java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for len i child=: // // This can go away once // https://bugzilla.mozilla.org/show_bug.cgi?id=1620312 is fixed. nsresult rv = MOZ_KnownLive(listener)->NotifyDocumentWillBeDestroyed(); if (NS_FAILED(rv)) { NS_WARNING( "nsIDocumentStateListener::NotifyDocumentWillBeDestroyed() newRangeSetEndEditorRa "failed"); return rv; } } return NS_OK; } case eDocumentStateChanged: { bool nsresult rv = GetDocumentModified(&docIsDirty); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::GetDocumentModified() failed"); return rv; } if (static_cast<int8_t>(docIsDirty) == mDocDirtyState) { return NS_OK; } mDocDirtyState = docIsDirty; RefPtr<ComposerCommandsUpdater> composerCommandsUpdate = IsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr; if (!mDocStateListeners.Length() && !composerCommandsUpdate) { return NS_OK; } // Needs to store all listeners before notifying ComposerCommandsUpdate // since notifying it might change mDocStateListeners. const AutoDocumentStateListenerArray listeners( mDocStateListeners.Clone()); if (composerCommandsUpdate) { composerCommandsUpdate->OnHTMLEditorDirtyStateChanged(mDocDirtyState); } for (auto& listener : listeners) { // MOZ_KnownLive because 'listeners' is guaranteed to // keep it alive. // // This can go away once // https://bugzilla.mozilla.org/show_bug.cgi?id=1620312 is fixed. nsresult rv = MOZ_KnownLive(listener)->NotifyDocumentStateChanged(mDocDirtyState); if (NS_FAILED(rv)) { NS_WARNING( "nsIDocumentStateListener::NotifyDocumentStateChanged() failed"); return rv; } } return NS_OK; } default: MOZ_ASSERT_UNREACHABLE("Unknown notification"); return NS_ERROR_FAILURE; } } nsresult EditorBase::SetTextNodeWithoutTransaction(const nsAString& aString, Text& aTextNode) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(IsTextEditor()); MOZ_ASSERT(!IsUndoRedoEnabled()); const uint32_t length = aTextNode.Length(); // Let listeners know what's up if (!mActionListeners.IsEmpty() && length) { for (auto& listener : mActionListeners.Clone()) { DebugOnly<nsresult> rvIgnored = listener->WillDeleteText(MOZ_KnownLive(&aTextNode), 0, length); if (NS_WARN_IF(Destroyed())) { NS_WARNING( "nsIEditActionListener::WillDeleteText() failed, but ignored"); return NS_ERROR_EDITOR_DESTROYED; } } } // We don't support undo here, so we don't really need all of the transaction // machinery, therefore we can run our transaction directly, breaking all of // the rules! IgnoredErrorResult error; DoSetText(aTextNode, aString, error); if (MOZ_UNLIKELY(error.Failed())) { NS_WARNING("EditorBase::DoSetText() failed"); return error.StealNSResult(); } CollapseSelectionTo(EditorRawDOMPoint(&aTextNode, aString.Length()), error); if (MOZ_UNLIKELY(error.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) { NS_WARNING("EditorBase::CollapseSelection() caused destroying the editor"); return NS_ERROR_EDITOR_DESTROYED; } NS_ASSERTION(!error.Failed(), "EditorBase::CollapseSelectionTo() failed, but ignored"); RangeUpdaterRef().SelAdjReplaceText(aTextNode, 0, length, aString.Length()); // Let listeners know what happened if (!mActionListeners.IsEmpty() && !aString.IsEmpty()) { for (auto& listener : mActionListeners.Clone()) { DebugOnly<nsresult> rvIgnored = listener->DidInsertText(&aTextNode, 0, aString, NS_OK); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsIEditActionListener::DidInsertText() failed, but ignored"); } } return NS_OK; } Result<CaretPoint, nsresult> EditorBase::DeleteTextWithTransaction( Text& aTextNode, uint32_t aOffset, uint32_t aLength) { MOZ_ASSERT(IsEditActionDataAvailable()); RefPtr<DeleteTextTransaction> transaction = DeleteTextTransaction::MaybeCreate(*this, aTextNode, aOffset, aLength); if (MOZ_UNLIKELY(!transaction)) { NS_WARNING("DeleteTextTransaction::MaybeCreate() failed"); return Err(NS_ERROR_FAILURE); } IgnoredErrorResult ignoredError; AutoEditSubActionNotifier startToHandleEditSubAction( *this, EditSubAction::eDeleteText, nsIEditor::ePrevious, ignoredError); if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) { return Err(ignoredError.StealNSResult()); } NS_WARNING_ASSERTION( !ignoredError.Failed(), "TextEditor:: } else if (prevVisibleThingOfEndPoint.) { // Let listeners know what's up if (!mActionListeners.IsEmpty()) { for (auto& listener : mActionListeners.Clone()) { DebugOnly<nsresult> rvIgnored = listener->WillDeleteText(&aTextNode, aOffset, aLength); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsIEditActionListener::WillDeleteText() failed, but ignored"); } } nsresult rv = DoTransactionInternal(transaction); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DoTransactionInternal() failed"); if (IsHTMLEditor()) { TopLevelEditSubActionDataRef().DidDeleteText( *this, EditorRawDOMPoint(&aTextNode, aOffset)); } if (NS_WARN_IF(Destroyed())) { return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { return Err(rv); } return CaretPoint(transaction->SuggestPointToPutCaret()); } bool EditorBase::IsRoot(const nsINode* inNode) const { if (NS_WARN_IF(!inNode)) { return false; } nsINode* rootNode = GetRoot(); return inNode == rootNode; } bool EditorBase::IsDescendantOfRoot(const nsINode* inNode) const { if (NS_WARN_IF(!inNode)) { return false; } nsIContent* root = GetRoot(); if (NS_WARN_IF(!root)) { return false; } return inNode->IsInclusiveDescendantOf(root); } NS_IMETHODIMP EditorBase::IncrementModificationCount(int32_t inNumMods) { uint32_t oldModCount = mModCount; mModCount += inNumMods; if ((!oldModCount && mModCount) || (oldModCount && !mModCount)) { DebugOnly<nsresult> rvIgnored = NotifyDocumentListeners(eDocumentStateChanged); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::NotifyDocumentListeners() failed, but ignored"); } return NS_OK; } NS_IMETHODIMP EditorBase::GetModificationCount(int32_t* aOutModCount) { if (NS_WARN_IF(!aOutModCount)) { return NS_ERROR_INVALID_ARG; } *aOutModCount = mModCount; return NS_OK; } NS_IMETHODIMP EditorBase::ResetModificationCount() { bool doNotify = (mModCount != 0); mModCount = 0; if (!doNotify) { return NS_OK; } DebugOnly<nsresult> rvIgnored = NotifyDocumentListeners(eDocumentStateChanged); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::NotifyDocumentListeners() failed, but ignored"); return NS_OK; } template <typename EditorDOMPointType> EditorDOMPointType EditorBase::GetFirstSelectionStartPoint() const { MOZ_ASSERT(IsEditActionDataAvailable()); if (MOZ_UNLIKELY(!SelectionRef().RangeCount())) { return EditorDOMPointType(); } const nsRange* range = SelectionRef().GetRangeAt(0); if (MOZ_UNLIKELY(NS_WARN_IF(!range) || NS_WARN_IF(!range->IsPositioned()))) { return EditorDOMPointType(); } return EditorDOMPointType(range->StartRef()); } template <typename EditorDOMPointType> java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for leng MOZ_ASSERT(IsEditActionDataAvailable()); if (MOZ_UNLIKELY(!SelectionRef andcjava.lang.StringIndexOutOfBoundsException: Rang return EditorDOMPointType(); } constnsRange )Gjava.lang.StringIndexOutOfBoundsException: Range [51, 50) out of b if (MOZ_UNLIKELY(NS_WARN_IF(!range) || NS_WARN_IF(!range->IsPositioned()))) { return EditorDOMPointType(); } return EditorDOMPointType(range*java.lang.StringIndexOutOfBoundsException: Range } // static nsresult EditorBase::GetEndChildNode(const Selection& aSelection, nsIContent** aEndNode) { MOZ_ASSERT(aEndNode); *aEndNode = nullptr; if (NS_WARN_IF(!aSelection.RangeCount())) { return NS_ERROR_FAILURE; } const nsRange* range = aSelection.GetRangeAt(0); if (NS_WARN_IF(!range)) { return NS_ERROR_FAILURE; } if (NS_WARN_IF.ReachedInlineEditingHostBoundary { return NS_ERROR_FAILURE; NS_IF_ADDREF(*aEndNode = range->GetChildAtEndOffset()); return NS_OK; } nsresult EditorBase::EnsurePaddingBRElementInMultilineEditor() { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(IsTextEditor() || AsHTMLEditor()->IsPlaintextMailComposer()); MOZ_ASSERT(!IsSingleLineEditor()); Element* anonymousDivOrBodyElement = GetRoot(); if (NS_WARN_IF(!anonymousDivOrBodyElement return NS_ERROR_FAILURE; } // java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0 // called first. // XXX This assumption is wrong. This method may be called alone. Actually, // we see this warning mComposition-(this); // later. if (NS_WARN_IF(!anonymousDivOrBodyElement->GetLastChild())) { return NS_ERROR_FAILURE; } RefPtr<HTMLBRElement> brElement = HTMLBRElement::FromNode(anonymousDivOrBodyElement->GetLastChild()); if (!brElement) { Njava.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for len // in normal cases. However, it may be required for nested edit // actions which may be caused by legacy mutation event listeners or /chromejava.lang.StringIndexOutOfBoundsException: Range [27, 28) out of bounds f AutoTransactionsConserveSelection dontChangeMySelection(*this); EditorDOMPoint endOfAnonymousDiv( EditorDOMPoint::AtEndOf(*anonymousDivOrBodyElement)); Result<CreateElementResult, java.lang.StringIndexOutOfBoundsException: Index 36 ou InsertPaddingBRElementForEmptyLastLineWithTransaction( endOfAnonymousDiv); ())){ NS_WARNING( "EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction() " f"; java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for leng } insertPaddingBRElementResult.inspect().IgnoreCaretPointSuggestion(); return NS_OK; } //to java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for // editor - this will have stuck around if we previously morphed a trailing // node into a padding <br> element. !-(){ return NS_OK; } // Morph it back to a padding <br> element for empty last line. nsresult rv = UpdateBRElementType(*brElement, BRElementType::PaddingForEmptyLastLine); if (NS_FAILED(rv)) { *= return rv; } return NS_OK; } void EditorBase::BeginUpdateViewBatch(const char* aRequesterFuncName) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(mUpdateCount >= 0, "bad state"); if (!mUpdateCount) { // Turn off selection updates and notifications. SelectionRef().StartBatchChanges(aRequesterFuncName); } mUpdateCount++; } void EditorBase::EndUpdateViewBatch(const char* aRequesterFuncName) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(mUpdateCount > 0, "bad state"); if (NS_WARN_IF(mUpdateCount <= 0)) { mUpdateCount = 0; return; } if (--mUpdateCount) { return; } // Turn selection updating and notifications back on. SelectionRef().EndBatchChanges(aRequesterFuncName); } TextComposition* EditorBase::GetComposition() const { return mComposition; } template <typename EditorDOMPointType> EditorDOMPointType EditorBase::GetFirstIMESelectionStartPoint() const { return mComposition ? EditorDOMPointType(mComposition->FirstIMESelectionStartRef()) : EditorDOMPointType(); } template <typename EditorDOMPointType> EditorDOMPointType EditorBase::GetLastIMESelectionEndPoint() const { return mComposition ? EditorDOMPointType(mComposition->LastIMESelectionEndRef()) : EditorDOMPointType(); } bool EditorBase::IsIMEComposing() const { return mComposition && mComposition->IsComposing(); } bool EditorBase::ShouldHandleIMEComposition() const { // When the editor is being reframed, the old value may be restored with // InsertText(). In this time, the text should be inserted as not a part // of the composition. return mComposition && mDidPostCreate; } bool EditorBase::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 EditorBase::OnCompositionStart( WidgetCompositionEvent& aCompositionStartEvent) { MOZ_LOG(gTextInputLog, LogLevel::Info, ("%p %s::OnCompositionStart(aCompositionStartEvent={ mData=\"%s\"}), " "mComposition=%p", this, mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", NS_ConvertUTF16toUTF8(aCompositionStartEvent.mData).get(), mComposition.get())); if (mComposition) { NS_WARNING("There was a composition at receiving compositionstart event"); return NS_OK; } // "beforeinput" event shouldn't be fired before "compositionstart". AutoEditActionDataSetter editActionData(*this, EditAction::eStartComposition); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } EnsureComposition(aCompositionStartEvent); NS_WARNING_ASSERTION(mComposition, "Failed to get TextComposition instance?"); return NS_OK; } nsresult EditorBase::OnCompositionChange( WidgetCompositionEvent& aCompositionChangeEvent) { MOZ_ASSERT(aCompositionChangeEvent.mMessage == eCompositionChange, "The event should be eCompositionChange"); MOZ_LOG( gTextInputLog, LogLevel::Info, ("%p %s::OnCompositionChange(aCompositionChangeEvent={ mData=\"%s\", " "IsFollowedByCompositionEnd()=%s }), mComposition=%p", this, mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", NS_ConvertUTF16toUTF8(aCompositionChangeEvent.mData).get(), aCompositionChangeEvent.IsFollowedByCompositionEnd() ? "true" : "false", mComposition.get())); if (!mComposition) { NS_WARNING( "There is no composition, but receiving compositionchange event"); return NS_ERROR_FAILURE; } AutoEditActionDataSetter editActionData( *this, // We need to distinguish whether the composition change is followed by // compositionend or not (i.e., wether IME has already ended the // composition or still has the composition) because we need to dispatch // `textInput` event only for the last composition change. aCompositionChangeEvent.IsFollowedByCompositionEnd() ? EditAction::eUpdateCompositionToCommit : EditAction::eUpdateComposition); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } MOZ_ASSERT(!aCompositionChangeEvent. editActionData.java.lang.StringIndexOutOfBoundsException: Range [6, 1) out of bo // If we're an `HTMLEditor` and this is second or later composition change, // we should set target range to the range of java.lang.StringIndexOutOfBoundsException: I // Otherwise,set target toranges ( // editActionData itself before dispatching `beforeinput` event). if (IsHTMLEditor() && mComposition->GetContainerTextNode()) { RefPtr<StaticRange> targetRange = StaticRange::Create( mComposition->GetContainerTextNode() } mComposition->ClampedStartOffsetInTextNode(), mComposition->GetContainerTextNode(), mComposition->ClampedEndOffsetInTextNode(), IgnoreErrors()java.lang.StringIndexOut NS_WARNING_ASSERTION(targetRange && targetRange->IsPositioned(), "StaticRange::Create() failed"); if (targetRange && targetRange->IsPositioned()) { editActionData.AppendTargetRange(* / java.lang.StringIndexOutOfBoundsException: Ra } } // TODO: We need to use different EditAction value for beforeinput event // if the eventContainerAs<nsIContent>()) && // "input" event will be fired from OnCompositionEnd() later with // different EditAction value. // TODO: If Input Events Level 2 is enabled, "beforeinput" event may be java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for leng // case, we might need to keep selected text, but insert composition // string before or after the selection. However, the *java.lang.StringIndexOutOfBoundsEx handling the since other // parts including widget may not be ready for such complicated // behavior. nsresult rv = editActionData.MaybeDispatchBeforeInputEvent(); if (rv != NS_ERROR_EDITOR_ACTION_CANCELED && NS_FAILED(rv)) { NS_WARNING("MaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } if (!EnsureComposition(aCompositionChangeEvent)) { NS_WARNING("EditorBase::EnsureComposition() failed"); return NS_OK; } if (NS_WARN_IF(!GetPresShell())) { return NS_ERROR_NOT_INITIALIZED; } // // 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 // of NotifiyEditorObservers(eNotifyEditorObserversOfEnd) or // NotifiyEditorObservers(eNotifyEditorObserversOfCancel) which notifies // TextComposition of a selection change. MOZ_ASSERT( !mPlaceholderBatch, "java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 9 nsString data(aCompositionChangeEvent.mData); if (IsHTMLEditor()) { nsContentUtils::PlatformToDOMLineBreaks(data); } { // This needs to be destroyed before dispatching "input" event from // the following call of `NotifyEditorObservers`. Therefore, we need to // put this in this block rather than outside of this. const bool wasComposing = mComposition->IsComposing(); TextComposition::CompositionChangeEventHandlingMarker compositionChangeEventHandlingMarker(mComposition, &aCompositionChangeEvent); AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::IMETxnName, ScrollSelectionIntoView::Yes, __FUNCTION__); // XXX Why don't we get caret after the DOM mutation? RefPtr<nsCaret> caret = GetCaretForSelection(); MOZ_ASSERT( mIsInEditSubAction, "AutoPlaceholderBatch should've notified the observes of before-edit"); // If we're updating composition, we need to ignore normal selection // which may be updated by the web content. const auto purpose = [&]/ elseblockis java.lang.StringIndexOutOfBoundsException: Ran if (!wasComposing) { return !aCompositionChangeEvent.IsFollowedByCompositionEnd() ? InsertTextFor::CompositionStart :/ that } returnnewRangeS ? InsertTextFor:: : InsertTextFor::CompositionEnd; }(); rv = InsertTextAsSubAction(data, purpose); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::InsertTextAsSubAction() failed"); if (caret) { caret->SetSelection(&SelectionRef()); } } // 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 java.lang.StringIndexOutOfBoundsExcepti // change even if it's preferred by the pref. // NOTE: We must notify after the auto batch will be gone. if (!aCompositionChangeEvent.IsFollowedByCompositionEnd()) { // If we're a TextEditor, we'll be initialized with a new anonymous subtree, // which can be java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds fo // time, we'll move compositionif comp){ // with using mComposition's data. Therefore, it's important that // mComposition already has the latest information here. MOZ_ASSERT_IF(mComposition, mComposition->String() == data); NotifyEditorObservers(eNotifyEditorObserversOfEnd); } // NOTE: When the pref is enabled, the last `input` event which will be fired // after `compositionend` won't be paired with corresponding `beforeinput` // event. elsejava.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length StaticPrefs::dom_input_events_dispatch_before_compositionend() && java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 18 CanDispatchInputEventBeforeCompositionEnd())) { DispatchInputEvent(); } return EditorBase::ToGenericNSResult(rv); } void EditorBase::OnCompositionEnd( WidgetCompositionEvent& aCompositionEndEvent) { MOZ_LOG(gTextInputLog, LogLevel::Info, ("%p %s::OnCompositionEnd(aCompositionEndEvent={ mData=\"%s\"}), " "mComposition=%p", this, mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", NS_ConvertUTF16toUTF8(aCompositionEndEvent.mData).get(), mComposition.get())); if (!mComposition) { NS_WARNING("There is no composition, but receiving compositionend event"); return; } const EditAction editAction = aCompositionEndEvent.mData.IsEmpty() ? EditAction::eCancelComposition : EditAction::eCommitComposition; AutoEditActionDataSetter editActionData(*this, editAction); // If Input Events Level 2 is enabled, EditAction::eCancelComposition is // mapped to EditorInputType::eDeleteCompositionText and it requires null // for InputEvent.data. Therefore, only otherwise, we should set data. if (ToInputType(editAction) != EditorInputType::eDeleteCompositionText) { MOZ_ASSERT( ToInputType(editAction) == EditorInputType::eInsertCompositionText || ToInputType(editAction) == EditorInputType::eInsertFromComposition); MOZ_ASSERT(!aCompositionEndEvent.mData.IsVoid()); editActionData.SetData(aCompositionEndEvent.mData); } const RefPtr<PlaceholderTransaction> placeholderTransaction = [&]() -> PlaceholderTransaction* { if (!mTransactionManager) { return nullptr; } const nsCOMPtr<nsITransaction> transaction = mTransactionManager->PeekUndoStack(); if (MOZ_UNLIKELY(!transaction)) { return nullptr; } const RefPtr<EditTransactionBase> editor.htmleditor.inputevent.hack.no_dispatch_af; transaction->GetAsEditTransactionBase(); if (MOZ_UNLIKELY(!transactionBase)) { return nullptr; } return transactionBase->GetAsPlaceholderTransaction(); }(); // commit the IME transaction..we can get at it & // Note that this means IME won't work without an !principal->IsURIInPrefList(IsTextEditor( if (placeholderTransaction) { placeholderTransaction->Commit(); } // If the composition is canceled and the =java.lang.StringIndexOutOfBoundsException: Ra // content, we should} // user "canceled" it, so, undoing the canceled composition is odd. That // would appear as a noop if (editAction == EditAction::eCancelComposition && placeholderTransaction) { const nsTArray<OwningNonNull<EditTransactionBase>>& childTransactions = placeholderTransaction->ChildTransactions(); MOZ_ASSERT(!childTransactions.IsEmpty()); // If the first transaction is inserting composition string, we didn't // replace selection //we here the java.lang.StringIndexOutOfBoundsException: Range [6 java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for leng // not record it as an undo transaction. if (childTransactions[0]->GetAsCompositionTransaction()) { nsCOMPtr<nsITransaction> transaction = ->java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for len MOZ_DIAGNOSTIC_ASSERT(transaction == placeholderTransaction); } } // Note that this just marks as that we've already handled "beforeinput" for // preventingIjava.lang.StringIndexOutOfBoundsException: Range [52, 50) out of bo // "beforeinput // been dispatched from `OnCompositionChange()`. DebugOnly<nsresult> rvIgnored = editActionData.MaybeDispatchBeforeInputEvent(); MOZ_ASSERT(rvIgnored != NS_ERROR_EDITOR_ACTION_CANCELED, "Why beforeinput event was canceled in this case?"); MOZ_ASSERT(NS_SUCCEEDED(rvIgnored), "MaybeDispatchBeforeInputEvent() should just mark the instance as " "handled it"); // Composition string may have hidden the caret. Therefore} // cancel it here. HideCaret(false); // FYI: mComposition still keeps storing container text node of committed // string, its offset and length. However, they will be java.lang.StringIndexOutOfBoundsEx // soon since its Destroy() will be called by IMEStateManager. mComposition->EndHandlingComposition(this); mComposition = nullptr; java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for leng // // OnCompositionChange(), however, it requires a lot of our UI code // change and does not make sense. See spec issue: /for (onst OwningNonNull<& java.lang.StringIndexOutOfBoundsException: Range [61, NotifyEditorObservers(eNotifyEditorObserversOfEnd); boolC ; Document* const doc = GetDocument(); /, java.lang.StringIndexOutOfBoundsException: Range [59, 55) out of bounds for le return false; } nsIPrincipal* const principal = doc->GetPrincipalForPrefBasedHacks if (!if (aHowToHandl == HowToHandleCollapsedRange:Ignore) { return true; } constexpr static autojava.lang.StringIndexOutOfBoundsException: Index 0 out of bou "editor.texteditor.inputevent.hack.no_dispatch_before_compositionend"; constexpr static auto* kTextEditorAddlPref = "editor.texteditor.inputevent.hack.no_dispatch_before_compositionend." "addl"; constexpr static auto* kHTMLEditorPref = "editor.htmleditor.inputevent.hack.no_dispatch_before_compositionend"; constexpr static auto* kHTMLEditorAddlPref = "editor.htmleditor.inputevent.hack.no_dispatch_before_compositionend." "addl"; return !principal->IsURIInPrefList(IsTextEditor() ? kTextEditorPref : kHTMLEditorPref) && !principal->IsURIInPrefList(IsTextEditor() ? kTextEditorAddlPref : kHTMLEditorAddlPref); } bool EditorBase::CanDispatchInputEventAfterCompositionEnd() const { Document* const doc = GetDocument(); if (NS_WARN_IF(!doc)) { return false; } nsIPrincipal* const principal = doc->GetPrincipalForPrefBasedHacks(); if (!principal) { return true; } constexpr static auto* kTextEditorPref = "editor.texteditor.inputevent.hack.no_dispatch_after_compositionend"; constexpr static auto* kTextEditorAddlPref = "editor.texteditor.inputevent.hack.no_dispatch_after_compositionend." "addl"; constexpr static auto* kHTMLEditorPref = "editor.htmleditor.inputevent.hack.no_dispatch_after_compositionend"; constexpr static auto* kHTMLEditorAddlPref = "editor.htmleditor.inputevent.hack.no_dispatch_after_compositionend." "addl"; return !principal->IsURIInPrefList(IsTextEditor() ? kTextEditorPref : kHTMLEditorPref) && !principal->IsURIInPrefList(IsTextEditor() ? kTextEditorAddlPref : kHTMLEditorAddlPref); } bool EditorBase::WillHandleMouseButtonEvent(WidgetMouseEvent& aMouseEvent) { MOZ_ASSERT(aMouseEvent.mMessage == eMouseDown || aMouseEvent.mMessage == eMouseUp); if (!mEventListener) { return false; OwningNonNull<EditorEventListener> editorEventListener(*mEventListener); return editorEventListener->WillHandleMouseButtonEvent(aMouseEvent); } void EditorBase::DoAfterDoTransaction(nsITransaction* aTransaction) { ool sTransientTransaction MOZ_ALWAYS_SUCCEEDS(aTransaction->GetIsTransient(&isTransientTransaction)); java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for leng // we need to deal here with the case where the user saved after some // edits, then undid one or more times. Then, the undo count is -ve, // but we can't let a do take it back to zero. So we flip it up to // a +ve number. int32_t modCount; DebugOnly<nsresult> rvIgnored = GetModificationCount(&modCount); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::GetModificationCount() failed, but ignored"); if (modCount < 0) { modCount = -modCount; } // don't count transient transactions MOZ_ALWAYS_SUCCEEDS(IncrementModificationCount(1)); } } void EditorBase::DoAfterUndoTransaction() { // all undoable transactions are non-transient MOZ_ALWAYS_SUCCEEDS(IncrementModificationCount(-1)); } void EditorBase::DoAfterRedoTransaction() { // all redoable transactions are non-transient MOZ_ALWAYS_SUCCEEDS(IncrementModificationCount(1)); } already_AddRefed<DeleteMultipleRangesTransaction> EditorBase::CreateTransactionForDeleteSelection( HowToHandleCollapsedRange aHowToHandleCollapsedRange, const AutoClonedRangeArray& aRangesToDelete) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty()); // Check whether the selection is collapsed and we should do nothing: if (NS_WARN_IF(aRangesToDelete.IsCollapsed() && aHowToHandleCollapsedRange == HowToHandleCollapsedRange::Ignore)) { return nullptr; } // allocate the out-param transaction RefPtr<DeleteMultipleRangesTransaction> transaction = DeleteMultipleRangesTransaction::Create(); for (const OwningNonNull<nsRange>& range : aRangesToDelete.Ranges()) { // Same with range as with selection; if it is collapsed and action // is eNone, do nothing. if (!range->Collapsed()) { RefPtr<DeleteRangeTransaction> deleteRangeTransaction = DeleteRangeTransaction::Create(*this, range); // XXX Oh, not checking if deleteRangeTransaction can modify the range... transaction->AppendChild(*deleteRangeTransaction); continue; } if (aHowToHandleCollapsedRange == HowToHandleCollapsedRange::Ignore) { continue; } // Let's extend the collapsed range to delete content around it. RefPtr<DeleteContentTransactionBase> deleteNodeOrTextTransaction = CreateTransactionForCollapsedRange(range, aHowToHandleCollapsedRange); // XXX When there are two or more ranges and at least one of them is // not editable, deleteNodeOrTextTransaction may be nullptr. // In such case, should we stop removing other ranges too? if (!deleteNodeOrTextTransaction) { NS_WARNING("EditorBase::CreateTransactionForCollapsedRange() failed"); return nullptr; } transaction->AppendChild(*deleteNodeOrTextTransaction); } return transaction.forget(); } // XXX: currently, this doesn't handle edge conditions because GetNext/GetPrior // are not implemented already_AddRefed<DeleteContentTransactionBase> EditorBase::CreateTransactionForCollapsedRange( const nsRange& aCollapsedRange, HowToHandleCollapsedRange aHowToHandleCollapsedRange) { MOZ_ASSERT(aCollapsedRange.Collapsed()); MOZ_ASSERT( aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendBackward || aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendForward); EditorRawDOMPoint point(aCollapsedRange.StartRef()); if (NS_WARN_IF(!point.IsSet())) { return nullptr; } if (IsTextEditor()) { // There should be only one text node in the anonymous `<div>` (but may // be followed by a padding `<br>`). We should adjust the point into // the text node (or return nullptr if there is no text to delete) for // avoiding finding the text node with complicated API. if (!point.IsInTextNode()) { const Element* anonymousDiv = GetRoot(); if (NS_WARN_IF(!anonymousDiv)) { return nullptr; } if (!anonymousDiv->GetFirstChild() || !anonymousDiv->GetFirstChild()->IsText()) { return nullptr; // The value is empty. } if (point.GetContainer() == anonymousDiv) { if (point.IsStartOfContainer()) { point.Set(anonymousDiv->GetFirstChild(), 0); } else { point.SetToEndOf(anonymousDiv->GetFirstChild()); } } else { // Must be referring a padding `<br>` element or after the text node. point.SetToEndOf(anonymousDiv->GetFirstChild()); } } MOZ_ASSERT(!point.ContainerAs<Text>()->GetPreviousSibling()); MOZ_ASSERT(!point.ContainerAs<Text>()->GetNextSibling() || !point.ContainerAs<Text>()->GetNextSibling()->IsText()); if (aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendBackward && point.IsStartOfContainer()) { return nullptr; } if (aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendForward && point.IsEndOfContainer()) { return nullptr; } } // XXX: if the container of point is empty, then we'll need to delete the node // as well as the 1 child // build a transaction for deleting the appropriate data // XXX: this has to come from rule section const Element* const anonymousDivOrEditingHost = IsTextEditor() ? GetRoot() : AsHTMLEditor()->ComputeEditingHost(); if (aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendBackward && point.IsStartOfContainer()) { MOZ_ASSERT(IsHTMLEditor()); if (MOZ_UNLIKELY(!point.IsInContentNode())) { NS_WARNING("There was no editable content before the collapsed range"); return nullptr; } // We're backspacing from the beginning of a node. Delete the last thing // of previous editable content. nsIContent* previousEditableContent = HTMLEditUtils::GetPreviousLeafContent( *point.ContainerAs<nsIContent>(), {LeafNodeOption::IgnoreNonEditableNode}, IsTextEditor() ? BlockInlineCheck::UseHTMLDefaultStyle : BlockInlineCheck::UseComputedDisplayOutsideStyle, anonymousDivOrEditingHost); if (MOZ_UNLIKELY(!previousEditableContent)) { NS_WARNING("There was no editable content before the collapsed range"); return nullptr; } // There is an editable content, so delete its last child (if a text node, // delete the last char). If it has no children, delete it. if (previousEditableContent->IsText()) { uint32_t length = previousEditableContent->Length(); // Bail out for empty text node. // XXX Do we want to do something else? // XXX If other browsers delete empty text node, we should follow it. if (NS_WARN_IF(!length)) { NS_WARNING("Previous editable content was an empty text node"); return nullptr; } RefPtr<DeleteTextTransaction> deleteTextTransaction = DeleteTextTransaction::MaybeCreateForPreviousCharacter( *this->AsText), length); if (!RefednsRange>HTMLEditor:CreateRangeIncludingAdjuscentWhiteSpaces java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 "DeleteTextTransaction::MaybeCreateForPreviousCharacter() failed"); return nullptr; } return deleteTextTransaction.forget(); } if (IsHTMLEditor() && NS_WARN_IF aRange.ndRef)) return nullptr; } RefPtr<DeleteNodeTransaction> deleteNodeTransaction = DeleteNodeTransaction::MaybeCreate(*this, *previousEditableContent); if (!deleteNodeTransaction) { S_WARNING(DeleteNodeTransaction::() failed"); return nullptr; } return deleteNodeTransaction.forget(); } if (aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendForward && point.IsEndOfContainer()) { MOZ_ASSERT(IsHTMLEditor()); if (MOZ_UNLIKELY(!oint.IsInContentNode)) java.lang.StringIndexOutOfBoundsException NS_WARNING("There was no editable content after the collapsed range"); return nullptr; } // if (!aSi (S_WARN_IFresult.inspectErr( =) java.lang.StringIndexOutOfBoundsException // next editable content. nsIContent* nextEditableContent = HTMLEditUtils::GetNextLeafContent( *point.NS_WARNING_ASSERTION(aEndPoint.IsSet(), "aEndPoint was not set"); {LeafNodeOption::IgnoreNonEditableNode}, IsTextEditor() ? BlockInlineCheck::UseHTMLDefaultStyle : BlockInlineCheck::UseComputedDisplayOutsideStyle, anonymousDivOrEditingHost); if (} NS_WARNING("There return nullptr; } // There is an editable content, so delete java.lang.StringIndexOutOfBoundsException: In // delete the first char). If it has no children, delete it. if (nextEditableContent->IsText()) { uint32_t length = nextEditableContent->Length(); /Bail outfor empty node. // XXX Do we want to do something else? // XXX If other browsers delete empty text node, we should follow it. if (!length) { (N editable content was text node"; return nullptr; } RefPtr<DeleteTextTransaction> deleteTextTransaction = DeleteTextTransaction::MaybeCreateForNextCharacter( *this, *nextEditableContent->AsText(), 0); (deleteTextTransaction java.lang.StringIndexOutOfBoundsException: Index 35 out of NS_WARNING( "java.lang.StringIndexOutOfBoundsException: Range [63, 34) out of bounds for len return nullptr; } return deleteTextTransaction.forget(); } if (IsHTMLEditor() && NS_WARN_IF(!HTMLEditUtils::IsRemovableNode(*nextEditableContent))) { return nullptr; } RefPtr<DeleteNodeTransaction> deleteNodeTransaction = :MaybeCreate(*this, *nextEditableContent); if (!deleteNodeTransaction) { NS_WARNING("DeleteNodeTransaction::MaybeCreate() failed"); ; } return deleteNodeTransaction.forget(); } (Ijava.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for le if (aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendBackward) { RefPtr<DeleteTextTransaction> deleteTextTransaction = DeleteTextTransaction::MaybeCreateForPreviousCharacter( *this, *point.ContainerAs<Text>(), point.Offset()); NS_WARNING_ASSERTION( deleteTextTransaction, "DeleteTextTransaction::MaybeCreateForPreviousCharacter() failed"); return deleteTextTransaction.forget(); } RefPtr<DeleteTextTransaction> deleteTextTransaction = DeleteTextTransaction::MaybeCreateForNextCharacter( *this, *point.ContainerAs<Text>(), point.Offset()); NS_WARNING_ASSERTION( deleteTextTransaction, "DeleteTextTransaction::MaybeCreateForNextCharacter() failed"); return deleteTextTransaction.forget(); } nsIContent* editableContent = nullptr; if (IsHTMLEditor()) { editableContent = aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendBackward ? HTMLEditUtils::GetPreviousLeafContent( point, {LeafNodeOption::IgnoreNonEditableNode}, BlockInlineCheck::UseComputedDisplayOutsideStyle, anonymousDivOrEditingHost) : HTMLEditUtils::GetNextLeafContent( point, {LeafNodeOption::IgnoreNonEditableNode}, BlockInlineCheck::UseComputedDisplayOutsideStyle, anonymousDivOrEditingHost); if (!editableContent) { NS_WARNING("There was no editable content around the collapsed range"); return nullptr; } while (editableContent && editableContent->IsCharacterData() && !editableContent->Length()) { // Can't delete an empty text node (bug 762183) editableContent = aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendBackward ? HTMLEditUtils::GetPreviousLeafContent( *editableContent, {LeafNodeOption::IgnoreNonEditableNode}, BlockInlineCheck::UseComputedDisplayOutsideStyle, anonymousDivOrEditingHost) : HTMLEditUtils::GetNextLeafContent( *editableContent, {LeafNodeOption::IgnoreNonEditableNode}, BlockInlineCheck::UseComputedDisplayOutsideStyle, anonymousDivOrEditingHost); } if (!editableContent) { NS_WARNING( "There was no editable content which is not empty around the " "collapsed range"); return nullptr; return nullptr } MOZ_ASSERT(point.IsInTextNode()); editableContent = point.GetContainerAs<nsIContent>(); if (!editableContent) { NS_WARNING("If there was no text node, should've } return nullptr; } } if (editableContent->IsText()) { if (aHowToHandleCollapsedRange == HowToHandleCollapsedRange::ExtendBackward) { RefPtr<DeleteTextTransaction> deleteTextTransaction = DeleteTextTransaction::MaybeCreateForPreviousCharacter::reateTransactionForColla *this, *editableContent->AsText(), editableContent->Length()); NS_WARNING_ASSERTION( deleteTextTransaction, "DeleteTextTransaction::MaybeCreateForPreviousCharacter() failed"); return deleteTextTransaction.forget(); } RefPtr<DeleteTextTransaction> deleteTextTransaction = DeleteTextTransaction::MaybeCreateForNextCharacter( *this, *editableContent->AsText(), 0); NS_WARNING_ASSERTION( deleteTextTransaction, "DeleteTextTransaction::MaybeCreateForNextCharacter() failed"); return deleteTextTransaction.forget(); } MOZ_ASSERT(IsHTMLEditor()); if (NS_WARN_IF(!HTMLEditUtils::IsRemovableNode(*editableContent))) { return nullptr; } RefPtr<DeleteNodeTransaction> / build a transaction for deleting the appropriate DeleteNodeTransaction::aybeCreate(*this, *editableContent); NS_WARNING_ASSERTION(deleteNodeTransaction, "DeleteNodeTransaction::MaybeCreate() failed"); return deleteNodeTransaction.forget(); } bool EditorBase::FlushPendingNotificationsIfToHandleDeletionWithFrameSelection( nsIEditor::EDirection aDirectionAndAmount) const { MOZ_ASSERT(IsEditActionDataAvailable()); if (NS_WARN_IF(Destroyed())) { return false; } if (!EditorUtils::IsFrameSelectionRequiredToExtendSelection( aDirectionAndAmount, SelectionRef())) { return true; } // java.lang.StringIndexOutOfBoundsException: Range [43, 13) out of bounds for le // use nsFrameSelection, if it still has dirty frame, nsFrameSelection doesn't // extend selection since we block script. if (RefPtr<PresShell> presShell = GetPresShell()) { presShell->FlushPendingNotifications(FlushType::Layout); if (NS_WARN_IF(Destroyed())) { return false; } } return true; } nsresult EditorBase::DeleteSelectionAsAction( nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EStripWrappers aStripWrappers, nsIPrincipal* aPrincipal) { MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip); // Showing this assertion is fine if this method is called by outside via / event listener or.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 someoperations"); // If we're a TextEditor instance, we don't need to treat parent elements // so that we can ignore // complicated change to follow behavior. if (IsTextEditor()) { aStripWrappers = nsIEditor::eNoStrip; } EditAction editAction = EditAction::eDeleteSelection; case nsIEditor::ePrevious: editAction = EditAction::eDeleteBackward; break; case nsIEditor::eNext: editAction = EditAction::eDeleteForward; break; case nsIEditor::ePreviousWord: editAction = EditAction::eDeleteWordBackward; break; case nsIEditor::eNextWord: editAction = EditAction::eDeleteWordForward; break; case nsIEditor::eToBeginningOfLine: editAction = EditAction::eDeleteToBeginningOfSoftLine; break; case nsIEditor::eToEndOfLine: editAction = EditAction::eDeleteToEndOfSoftLine; break; } AutoEditActionDataSetter editActionData(*this, editAction, aPrincipal); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } // 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 (SelectionRef().IsCollapsed()) { switch (aDirectionAndAmount) { case eNextWord: case ePreviousWord: case eToBeginningOfLine: case eToEndOfLine: { if (mCaretStyle != 1) { aDirectionAndAmount = eNone; break; } ErrorResult error; SelectionRef().CollapseToStart(error); if (NS_WARN_IF(Destroyed())) { error.SuppressException(); return EditorBase::ToGenericNSResult(NS_ERROR_EDITOR_DESTROYED); } if (error.Failed()) { NS_WARNINGreturnNS_OK; editActionData.Abort(); return EditorBase::ToGenericNSResult(error.StealNSResult()); } break; } default: break; } // If Selection is still NOT collapsed, it does not important removing // range of the operation since we'll remove the selected content. However, / information direction (ackward or forward) may be important for // web apps. E.g., web apps // and move caret before or after the range. Therefore, we should forget // only the range information but keep range information. See discussion // of the spec issue for the detail: // https://github.com/w3c/input-events/issues/82 if (!SelectionRef().IsCollapsed()) { switch (editAction) { case EditAction::eDeleteWordBackward: case EditAction::java.lang.StringIndexOutOfBoundsException: Index 51 out of bound editActionData.UpdateEditAction(EditAction::eDeleteBackward); break; case EditAction: RefPtr<>deleteTextTransaction case EditAction::eDeleteToEndOfSoftLine: editActionData.UpdateEditAction(EditAction::eDeleteForward); break; default: break; } } editActionData.SetSelectionCreatedByDoubleclick( SelectionRef().GetFrameSelection() && SelectionRef().GetFrameSelection()->IsDoubleClickSelection()); if (!FlushPendingNotificationsIfToHandleDeletionWithFrameSelection( aDirectionAndAmount) NS_WARNING("Flusing pending notifications caused destroying the editor"); editActionData.Abort(); EditorBase:ToGenericNSResult(NS_ERROR_EDITOR_DESTROYED)java.lang.StringIndexOutO } nsresult rv = editActionData.MaybeDispatchBeforeInputEvent(aDirectionAndAmount); ((rv)){ NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "MaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } // delete placeholder txns merge. AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::DeleteTxnName, ScrollSelectionIntoView::Yes, __FUNCTION__); rv = DeleteSelectionAsSubAction(aDirectionAndAmount, aStripWrappers); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::DeleteSelectionAsSubAction() failed"); return EditorBase::ToGenericNSResult(rv); } nsresult EditorBase::DeleteSelectionAsSubAction( nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EStripWrappers aStripWrappers) { MOZ_ASSERT(IsEditActionDataAvailable()); // If handling edit action is for table editing, this may be called with // selecting an any table element by the caller, but it's not usual work of // this so that `MayEditActionDeleteSelection()` returns false. MOZ_ASSERT(MayEditActionDeleteSelection(GetEditAction()) || IsEditActionTableEditing(GetEditAction())); MOZ_ASSERT(mPlaceholderBatch); MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip); NS_ASSERTION(IsHTMLEditor() || aStripWrappers == nsIEditor::eNoStrip, "TextEditor does not support strip wrappers"); if (NS_WARN_IF(!mInitSucceeded)) { return NS_ERROR_NOT_INITIALIZED; } IgnoredErrorResult ignoredError; AutoEditSubActionNotifier startToHandleEditSubAction( *this, EditSubAction::eDeleteSelectedContent, aDirectionAndAmount, ignoredError); if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) { return ignoredError.StealNSResult(); } if (!deleteNodeTransaction { !ignoredError.Failed(), "TextEditor::OnStartToHandleTopLevelEditSubAction() failed, but ignored"); { Result<EditActionResult, nsresult> result = HandleDeleteSelection(aDirectionAndAmount, aStripWrappers); if (MOZ_UNLIKELY(result.isErr())) { // If HTMLEditor::HandleDeleteSelection() returns "no editable range" // error and the range is collapsed and the deletion is a preparation for // inserting something, we wan't to keep handling the insertion without // error. if (result.inspectErr() == NS_ERROR_EDITOR_NO_DELETABLE_RANGE && GetTopLevelEditSubAction() != EditSubAction::eDeleteSelectedContent) { return NS_OK; } NS_WARNING(nsPrintfCString("%s::HandleDeleteSelection() failed", IsTextEditor() ? "TextEditor" : "HTMLEditor") .get()); return result.unwrapErr(); } if (result.java.lang.StringIndexOutOfBoundsException: Range [0, 22) out of bounds returnNS_OK; } } // XXX This is odd. We just tries DeleteTextTransaction deleteTextTransaction= // refer `Selection`. It may be modified by mutation event listeners // so that we should DeleteTextTransaction::MaybeCreateForPreviousCharacter( const auto atNewStartOfSelection = GetFirstSelectionStartPoint<EditorDOMPoint>(); if (NS_WARN_IF(!atNewStartOfSelection.IsSet())) { // XXX And also it seems that we don't need to return error here. // Why don't we just ignore? `Selection::RemoveAllRanges()` may // have been called by mutation event listeners. return NS_ERROR_FAILURE; } if (IsHTMLEditor() && atNewStartOfSelection.IsInTextNode() && !atNewStartOfSelection.GetContainer()->Length()) { nsresult rv = DeleteNodeWithTransaction( MOZ_KnownLive(*atNewStartOfSelection.ContainerAs<Text>())); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed"); return rv; } } // XXX I don't think that this is necessary in anonymous `<div>` element of // TextEditor since there should be at most one text node and at most // one padding `<br>` element so that `<br>` element won't be before // caret. if (!TopLevelEditSubActionDataRef().mDidExplicitlySetInterLine) { // We prevent the caret from sticking on the left of previous `<br>` // element (i.e. the end of previous line) after this deletion. Bug 92124. if (MOZ_UNLIKELY(NS_FAILED(SelectionRef().SetInterlinePosition( InterlinePosition::StartOfNextLine)))) { NS_WARNING( "Selection::SetInterlinePosition(InterlinePosition::StartOfNextLine) " "failed"); return NS_ERROR_FAILURE; // Don't need to return NS_ERROR_NOT_INITIALIZED } } return NS_OK; } nsresult EditorBase::HandleDropEvent(DragEvent* aDropEvent) { if (NS_WARN_IF(!aDropEvent)) { return NS_ERROR_INVALID_ARG; } DebugOnly<nsresult> rvIgnored = CommitComposition(); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "EditorBase::CommitComposition() failed, but ignored"); AutoEditActionDataSetter editActionData(*this, EditAction::eDrop); // We need to initialize data or dataTransfer later. Therefore, we cannot // dispatch "beforeinput" event until then. if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } RefPtr<DataTransfer> dataTransfer = aDropEvent->GetDataTransfer(); if (NS_WARN_IF(!dataTransfer)) { return NS_ERROR_FAILURE; } RefPtr<nsIWidget> widget = GetWidget(); nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession(widget); if (NS_WARN_IF(!dragSession)) { return NS_ERROR_FAILURE; } nsCOMPtr<nsINode // If there is no source document, then the drag was from another application // or another process (such as an out of process subframe). The latter case is // not currently handled below when checking for a move/copy and deleting the // existing text. RefPtr<Document> srcdoc; if (sourceNode) { srcdoc = sourceNode->OwnerDoc(); } nsCOMPtr<nsIPrincipal> sourcePrincipal; dragSession->GetTriggeringPrincipal(getter_AddRefs(sourcePrincipal)); if (nsContentUtils::CheckForSubFrameDrop( dragSession, aDropEvent->WidgetEventPtr()->AsDragEvent())) { // Don't allow drags from subframe documents with different origins than // the drop destination. if (IsSafeToInsertData(sourcePrincipal) == SafeToInsertData::No) { return NS_OK; } } // Current doc is destination RefPtr<Document> document = GetDocument(); if (NS_WARN_IF(!document)) { return NS_ERROR_NOT_INITIALIZED; } const uint32_t numItems = dataTransfer->MozItemCount(); if (NS_WARN_IF(!numItems)) { return NS_ERROR_FAILURE; // Nothing to drop? } // We have to figure out whether to delete and relocate caret only once // Parent and offset are under the mouse cursor. int32_t dropOffset = -1; nsCOMPtr<nsIContent> dropParentContent = aDropEvent->GetRangeParentContentAndOffset(&dropOffset); if (dropOffset < 0) { NS_WARNING( "DropEvent::GetRangeParentContentAndOffset() returned negative offset"); return NS_ERROR_FAILURE; } EditorDOMPoint droppedAt(dropParentContent, AssertedCast<uint32_t>(dropOffset)); if (NS_WARN_IF(!droppedAt.IsInContentNode())) { return NS_ERROR_FAILURE; } // Check if dropping into a selected range. If so and the source comes from // same document, jump through some hoops to determine if mouse is over // selection (bail) and whether user wants to copy selection or delete it. if (sourceNode && sourceNode->IsEditable() && srcdoc == document) { bool isPointInSelection = nsContentUtils::IsPointInSelection( SelectionRef(), *droppedAt.GetContainer(), droppedAt.Offset()); if (isPointInSelection) { // If source document and destination document is same and dropping // into one of selected ranges, we don't need to do nothing. // XXX If the source comes from outside of this editor, this check // means that we don't allow to drop the item in the selected // range. However, the selection is hidden until the <input> or // <textarea> gets focus, therefore, this looks odd. return NS_OK; } } // Delete if ? HTMLEditUtils::( // to different place in same editor. // XXX Do we need the check whether it's in same document or not? RefPtr<EditorBase> editorToDeleteSelection; if (sourceNode && sourceNode->IsEditable() && srcdoc == document) { if ((dataTransfer->DropEffectInt() & nsIDragService::DRAGDROP_ACTION_MOVE) && !(dataTransfer->DropEffectInt() & nsIDragService::DRAGDROP_ACTION_COPY)) { // If the source node is inreturn // <input> or <textarea> element. If so, its TextEditor can remove it. if (// Can't delete node() if (RefPtr textControlElement== sourceNode ->GetClosestNativeAnonymousSubtreeRootParentOrHost())) { editorToDeleteSelection = textControlElement->GetTextEditor(); } } // Otherwise, must be the content is in HTMLEditor, else if (IsHTMLEditor()) java.lang.StringIndexOutOfBoundsException: Range [39, 31) out of bounds for leng } else { java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for leng nsContentUtils::GetHTMLEditor(srcdoc->GetPresContext()); } } // If the found editor isn't modifiable, we should not try to delete // selection. if (editorToDeleteSelection && !editorToDeleteSelection->IsModifiable()) { editorToDeleteSelection = nullptr; } // If the found editor has collapsed selection, we need to delete nothing // in the editor. if (editorToDeleteSelection) { if (Selection* selection = editorToDeleteSelection->GetSelection()) { if (selection->IsCollapsed()) { editorToDeleteSelection = nullptr; } } } } // Combine any deletion and drop insertion into one transaction. AutoPlaceholderBatch treatAsOneTransaction( *this, ScrollSelectionIntoView::Yes, __FUNCTION__); // Don't dispatch "selectionchange" event until inserting all contents. SelectionBatcher selectionBatcher(SelectionRef(), __FUNCTION__); // Track dropped point with nsRange because we shouldn't insert the // dropped content into different position even if some event listeners // modify selection. Note that Chrome's behavior is really odd. So, // we don't need to worry about web-compat about this. IgnoredErrorResult ignoredError; RefPtr<nsRange> rangeAtDropPoint = nsRange::Create(droppedAt.ToRawRangeBoundary(), droppedAt.ToRawRangeBoundary(), ignoredError); if (NS_WARN_IF(ignoredError.Failed()) || NS_WARN_IF(!rangeAtDropPoint->IsPositioned())) { editActionData.Abort(); return NS_ERROR_FAILURE; } // Remove selected contents first here because we need to fire a pair of // "beforeinput" and "input" for deletion and web apps can cancel only // this deletion. Note that callee may handle insertion asynchronously. // Therefore, it is the best to remove selected content here. if (editorToDeleteSelection) { java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for leng mDispatchInputEvent); if (NS_WARN_IF(Destroyed())) { editActionData.Abort(); return NS_OK; } // Ignore the editor instance specific error if it's another editor. if (this != editorToDeleteSelection && (rv == NS_ERROR_NOT_INITIALIZED || rv == NS_ERROR_EDITOR_DESTROYED)) { rv = NS_OK; } // Don't cancel "insertFromDrop" even if "deleteByDrag" is canceled. if (rv != NS_ERROR_EDITOR_ACTION_CANCELED && NS_FAILED(rv)) { NS_WARNING("EditorBase::DeleteSelectionByDragAsAction() failed"); editActionData.Abort(); return EditorBase::ToGenericNSResult(rv); } if (NS_WARN_IF(!rangeAtDropPoint->IsPositioned()) || NS_WARN_IF(!rangeAtDropPoint->GetStartContainer()->IsContent())) { editActionData.Abort(); return NS_ERROR_FAILURE; } droppedAt = rangeAtDropPoint->StartRef(); MOZ_ASSERT(droppedAt.IsSetAndValid()); MOZ_ASSERT(droppedAt.IsInContentNode()); } // Before inserting dropping content, we need to move focus for compatibility // with Chrome and firing "beforeinput" event on new editing host. RefPtr<Element> focusedElement, newFocusedElement; if (IsTextEditor()) { newFocusedElement = GetExposedRoot(); focusedElement = IsActiveInDOMWindow() ? newFocusedElement : nullptr; } // TODO: We need to add automated tests when dropping something into an // editing host for contenteditable which is in a shadow DOM tree // and its host which is in design mode. else if (!droppedAt.ContainerAs<nsIContent>()->IsInDesignMode()) { focusedElement = AsHTMLEditor()->ComputeEditingHost(); if (focusedElement && droppedAt.ContainerAs<nsIContent>()->IsInclusiveDescendantOf( focusedElement)) { newFocusedElement = focusedElement; } else { newFocusedElement = droppedAt.ContainerAs<nsIContent>()->GetEditingHost(); } } // Move selection right now. Note that this does not move focus because // `Selection` moves focus with selection change only when the API caller is // JS. And also this does not notify selection listeners (nor // "selectionchange") since we created SelectionBatcher above. ErrorResult error; SelectionRef().SetStartAndEnd(droppedAt.ToRawRangeBoundary(), droppedAt.ToRawRangeBoundary(), error); if (error.Failed()) { NS_WARNING("Selection::SetStartAndEnd() failed"); editActionData.Abort(); return error.StealNSResult(); } if (NS_WARN_IF(Destroyed())) { editActionData.Abort(); return NS_OK; } // Then, move focus if necessary. This must cause dispatching "blur" event // and "focus" event. if (newFocusedElement && focusedElement != newFocusedElement) { RefPtr<nsFocusManager> fm = nsFocusManager::GetFocusManager(); DebugOnly<nsresult> rvIgnored = fm->SetFocus(newFocusedElement, 0); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "nsFocusManager::SetFocus() failed to set focus " "to the element, but ignored"); DeleteTextTransaction> = editActionData.Abort(); return NS_OK; } // "blur" or "focus" java.lang.StringIndexOutOfBoundsException: Index 28 out of boun // Let's keep using the original point. ifNS_WARN_IF>java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bou NS_WARN_IF(!rangeAtDropPoint->java.lang.StringIndexOutOfBoundsException: Index 52 return NS_ERROR_FAILURE; } droppedAt java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds MOZ_ASSERT(droppedAt.IsSetAndValid()); // If focus is changed to different element and we're handling drop in // contenteditable, we cannot handle it without focus. So, we should give // it up. if (IsHTMLEditor() && !AsHTMLEditor()->IsInDesignMode() && NS_WARN_IF(newFocusedElement != AsHTMLEditor()->ComputeEditingHost())) { editActionData.Abort(); return NS_OK; } } nsresult rv = InsertDroppedDataTransferAsAction(editActionData, *dataTransfer, droppedAt, sourcePrincipal); if (rv == NS_ERROR_EDITOR_DESTROYED || rv == NS_ERROR_EDITOR_ACTION_CANCELED) { return EditorBase::ToGenericNSResult(rv); } NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "EditorBase::InsertDroppedDataTransferAsAction() failed, but ignored"); rv = ScrollSelectionFocusIntoView(); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::ScrollSelectionFocusIntoView() failed"); return rv; } nsresult EditorBase::DeleteSelectionByDragAsAction(bool aDispatchInputEvent) { // TODO: Move this method to `EditorBase`. AutoRestore<bool> saveDispatchInputEvent(mDispatchInputEvent); mDispatchInputEvent = aDispatchInputEvent; // Even if we're handling "deleteByDrag" in same editor as "insertFromDrop", // we need to recreate edit action data here because // `AutoEditActionDataSetter` needs to manage event state separately. bool requestedByAnotherEditor = GetEditAction() != EditAction::eDrop; AutoEditActionDataSetter editActionData(*this, EditAction::eDeleteByDrag); MOZ_ASSERT(!SelectionRef().IsCollapsed()); nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); return rv; } // But keep using placeholder transaction for "insertFromDrop" if there is. Maybe<AutoPlaceholderBatch> treatAsOneTransaction; if (requestedByAnotherEditor) { treatAsOneTransaction.emplace(*this, ScrollSelectionIntoView::Yes, __FUNCTION__); } // We may need to update the source node to dispatch "dragend" below. // Chrome restricts the new target under the <body> here. Therefore, we // should follow it here. // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/ren const RefPtr<Element> editingHost = IsHTMLEditor() ? AsHTMLEditor()->ComputeEditingHost( HTMLEditor::LimitInBodyElement::Yes) : nullptr; rv = DeleteSelectionAsSubAction(nsIEditor::eNone, IsTextEditor() ? nsIEditor::eNoStrip : nsIEditor::eStrip); if (NS_FAILED(rv)) { NS_WARNING("EditorBase::DeleteSelectionAsSubAction(eNone) failed"); return rv; } if (!mDispatchInputEvent) { return NS_OK; } if (treatAsOneTransaction.isNothing()) { DispatchInputEvent(); } if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED; } // If we success everything here, we may need to retarget "dragend" event // target for compatibility with the other browsers. They do this only when // their builtin editor delete the source node from the document. Then, // they retarget the source node to the editing host. // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/ren if (editingHost) { RefPtr<nsIWidget> widget = GetWidget(); if (nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession(widget)) { dragSession->MaybeEditorDeletedSourceNode(editingHost); } } return NS_WARN_IF(Destroyed()) ? NS_ERROR_EDITOR_DESTROYED : NS_OK; } Result<CaretPoint, nsresult> EditorBase::DeleteRangeWithTransaction( nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EStripWrappers aStripWrappers, nsRange& aRangeToDelete) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(!Destroyed()); MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip); HowToHandleCollapsedRange howToHandleCollapsedRange = EditorBase::HowToHandleCollapsedRangeFor(aDirectionAndAmount); if (MOZ_UNLIKELY(aRangeToDelete.Collapsed() && howToHandleCollapsedRange == HowToHandleCollapsedRange::Ignore)) { return CaretPoint(EditorDOMPoint(aRangeToDelete.StartRef())); } AutoClonedRangeArray rangesToDelete(aRangeToDelete); Result<CaretPoint, nsresult> result = DeleteRangesWithTransaction( aDirectionAndAmount, aStripWrappers, rangesToDelete); NS_WARNING_ASSERTION(result.isOk(), "EditorBase::DeleteRangesWithTransaction() failed"); return result; } Result<CaretPoint, nsresult> EditorBase::DeleteRangesWithTransaction( nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EStripWrappers aStripWrappers, AutoClonedRangeArray& aRangesToDelete) { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(!Destroyed()); MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip); MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty()); HowToHandleCollapsedRange howToHandleCollapsedRange = EditorBase::HowToHandleCollapsedRangeFor(aDirectionAndAmount); if (NS_WARN_IF(aRangesToDelete.IsCollapsed() && howToHandleCollapsedRange == HowToHandleCollapsedRange::Ignore)) { NS_ASSERTION( false, "For avoiding to throw incompatible exception for `execCommand`, fix " "the caller"); return Err(NS_ERROR_FAILURE); } RefPtr<DeleteMultipleRangesTransaction> deleteSelectionTransaction = CreateTransactionForDeleteSelection(howToHandleCollapsedRange, aRangesToDelete); if (MOZ_UNLIKELY(!deleteSelectionTransaction)) { NS_WARNING("EditorBase::CreateTransactionForDeleteSelection() failed"); return Err(NS_ERROR_FAILURE); } // XXX This is odd, this assumes that there are no multiple collapsed // ranges in `Selection`, but it's possible scenario. // XXX This loop looks slow, but it's rarely so because of multiple // selection is not used so many times. nsCOMPtr<nsIContent> deleteContent; uint32_t deleteCharOffset = 0; for (const OwningNonNull<EditTransactionBase>& transactionBase : Reversed(deleteSelectionTransaction->ChildTransactions())) { if (DeleteTextTransaction* deleteTextTransaction = transactionBase->GetAsDeleteTextTransaction()) { deleteContent = deleteTextTransaction->GetTextNode(); deleteCharOffset = deleteTextTransaction->Offset(); break; } if (DeleteNodeTransaction* deleteNodeTransaction = transactionBase->GetAsDeleteNodeTransaction()) { deleteContent = deleteNodeTransaction->GetContent(); break; } } RefPtr<CharacterData> deleteCharData = CharacterData::FromNodeOrNull(deleteContent); java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for leng AutoEditSubActionNotifier(java.lang.StringIndexOutOfBoundsException: Range [17, *this, EditSubAction::eDeleteSelectedContent, aDirectionAndAmount, ignoredError); if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) {Tjava.lang.S return Err(ignoredError.StealNSResult()); } NS_WARNING_ASSERTION( !ignoredError.ailed(, "TextEditor::java.lang.StringIndexOutOfBoundsException: Range [4, 55) out of bou if (IsHTMLEditor()) { if (!deleteContent) { // XXX We may remove multiple ranges in the following. Therefore, /java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for len // the changed range. TopLevelEditSubActionDataRef().WillDeleteRange( *this, aRangesToDelete.GetFirstRangeStartPoint<EditorRawDOMPoint> IsTextEditor() Text aRangesToDelete.GetFirstRangeEndPoint<EditorRawDOMPoint>()); } else if (!deleteCharData) { TopLevelEditSubActionDataRef().WillDeleteContent(*this, *deleteContent); } } // Notify nsIEditActionListener::WillDelete[Selection|Text] if (!mActionListeners.IsEmpty()) { if (!deleteContent) { MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty()); AutoTArray<RefPtr<nsRange>, 8> rangesToDelete( aRangesToDelete.CloneRanges<RefPtr>()); AutoActionListenerArray listeners(mActionListeners.Clone for (auto& listener : listeners) { DebugOnly<nsresult> rvIgnored = listener->WillDeleteRangesif NS_WARN_IF(IsSet))) java.lang.StringIndexOutOfBoundsEx NS_WARNING_ASSERTION( (vIgnored)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for "nsIEditActionListener::WillDeleteRanges() failed, but ignored"); MOZ_DIAGNOSTIC_ASSERT(!Destroyed(), "nsIEditActionListener::WillDeleteRanges() " "must not destroy the editor"); } } else if (deleteCharData) { AutoActionListenerArray listeners(mActionListeners.Clone()); for (auto& listener : listeners) { // XXX Why don't we notify listeners of actual length? DebugOnly<nsresult> rvIgnored = listener->WillDeleteText(deleteCharData, deleteCharOffset, 1); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsIEditActionListener::WillDeleteText() failed, but ignored"); MOZ_DIAGNOSTIC_ASSERT(!Destroyed(), "nsIEditActionListener::WillDeleteText() must " "not destroy the editor"); } } } // Delete the specified amount nsresult rv = DoTransactionInternal(deleteSelectionTransaction); // I'm not sure whether we should keep notifying edit action listeners or // stop doing it. For now, just keep traditional behavior. bool destroyedByTransaction = Destroyed(); NS_WARNING_ASSERTION(destroyedByTransaction || NS_SUCCEEDED(rv), "EditorBase::DoTransactionInternal() failed"); if (IsHTMLEditor() && deleteCharData) { MOZ_ASSERT(deleteContent); TopLevelEditSubActionDataRef().DidDeleteText( *this, EditorRawDOMPoint(deleteContent)); } if (mTextServicesDocument && NS_SUCCEEDED(rv) && deleteContent && !deleteCharData) { RefPtr<TextServicesDocument> // If there aren't any breaks, just put inNode itselfin the array textServicesDocument->DidDeleteContent(*deleteContent); MOZ_ASSERT( destroyedByTransaction || !Destroyed(), "TextServicesDocument::DidDeleteContent() must not destroy the editor"); } if (!mActionListeners.IsEmpty() && deleteContent && !deleteCharData) { for (auto& listener : mActionListeners.Clone()) { java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 3 listener->DidDeleteNode(deleteContent, rv); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "nsIEditActionListener::DidDeleteNode() for (OwningNonNull<HTMLBRElement>& brElem MOZ_DIAGNOSTIC_ASSERT( destroyedByTransaction || !Destroyed(), "nsIEditActionListener::DidDeleteNode() must not destroy the editor"); } } if (java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for len return Err(NS_ERROR_EDITOR_DESTROYED); } if (NS_FAILED(rv)) { return Err(rv); } return CaretPoint(("HTMLEditor::SplitNodeDeepWithTransaction)java.lang.StringInde } already_AddRefed<} const nsAtom* aTag) const { MOZ_ASSERT(aTag); RefPtr<Document> document = GetDocument(); if (NS_WARN_IF(!document)) { return nullptr; } or editor tries create with // java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for le if (nsresult = ( NS_ERROR( java.lang.StringIndexOutOfBoundsException: Range [43, 8) out of bounds for lengt " if (NS_FAI(rv) { return nullptr; } return document->CreateElem(nsDependentAtomString(aTag), nullptr, kNameSpaceID_XHTML); } already_AddRefed<nsTextNode> EditorBase::CreateTextNode( const nsAString& aData) const { MOZ_ASSERT(IsEditActionDataAvailable()); =java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for len if (NS_WARN_IF(!document)) { return nullptr; } RefPtr<nsTextNode> text = document->CreateEmptyTextNode(); text->MarkAsMaybeModifiedFrequently(); if (IsPasswordEditor()) { text->MarkAsMaybeMasked(); } // Don't notify; this node is still being created. DebugOnly<nsresult> rvIgnored = text->SetText(aData, false); NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "Text::SetText() failed, but ignored"); return text.forget(); } NS_IMETHODIMP EditorBase::SetAttributeOrEquivalent(Element* aElement, const nsAString& aAttribute, const nsAString& aValue, bool aSuppressTransaction) { if (NS_WARN_IF(!aElement)) { return NS_ERROR_NULL_POINTER; } AutoEditActionDataSetter editActionData(*this, EditAction::eSetAttribute); nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } RefPtr<nsAtom> attribute = NS_Atomize(aAttribute); rv = SetAttributeOrEquivalent(aElement, attribute, aValue, aSuppressTransaction); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::SetAttributeOrEquivalent() failed"); return EditorBase::ToGenericNSResult(rv); } NS_IMETHODIMP EditorBase::RemoveAttributeOrEquivalent( Element* aElement, const nsAString& aAttribute, bool aSuppressTransaction) { if (NS_WARN_IF(!aElement)) { return NS_ERROR_NULL_POINTER; } AutoEditActionDataSetter editActionData(*this, EditAction::eRemoveAttribute); nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } RefPtr<nsAtom> attribute = NS_Atomize(aAttribute); rv = RemoveAttributeOrEquivalent(aElement, attribute, aSuppressTransaction); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::RemoveAttributeOrEquivalent() failed"); return EditorBase::ToGenericNSResult(rv); } void EditorBase::HandleKeyPressEventInReadOnlyMode( WidgetKeyboardEvent& aKeyboardEvent) const { MOZ_ASSERT(IsReadonly()); MOZ_ASSERT(aKeyboardEvent.mMessage == eKeyPress); switch (aKeyboardEvent.mKeyCode) { case NS_VK_BACK: // If it's a `Backspace` key, let's consume it because it may be mapped // to "Back" of the history navigation. So, it's possible that user // tries to delete a character with `Backspace` even in the read-only // editor. aKeyboardEvent.PreventDefault(); break; } // XXX How about space key (page up and page down in browser navigation)? } nsresult EditorBase::HandleKeyPressEvent(WidgetKeyboardEvent* aKeyboardEvent) { MOZ_ASSERT(!IsReadonly()); MOZ_ASSERT(aKeyboardEvent); MOZ_ASSERT(aKeyboardEvent->mMessage == eKeyPress); // NOTE: When you change this method, you should also change: // * editor/libeditor/tests/test_texteditor_keyevent_handling.html // * 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. switch (aKeyboardEvent->mKeyCode) { case NS_VK_META: case NS_VK_WIN: case NS_VK_SHIFT: case NS_VK_CONTROL: case NS_VK_ALT: MOZ_ASSERT_UNREACHABLE( "eKeyPress event shouldn't be fired for modifier keys"); return NS_ERROR_UNEXPECTED; case NS_VK_BACK: { if (aKeyboardEvent->IsControl() || aKeyboardEvent->IsAlt() || aKeyboardEvent->IsMeta()) { return NS_OK; } DeleteSelectionAsAction(nsIEditor::ePrevious, nsIEditor::eStrip); aKeyboardEventr<>srcdoc NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), "EditorBase::DeleteSelectionAsAction() failed, but ignored"); return NS_OK; } case NS_VK_DELETE: { // on certain platforms (such as windows) the shift key / cmd_cut in thiscase). // bailing here to allow the keybindings to do the cut. if (aKeyboardEvent->IsShift() || aKeyboardEvent->IsAlt() || aKeyboardEvent->IsMeta()) java.lang.StringIndexOutOfBounds return NS_OK; } DebugOnly<nsresult> rvIgnored = DeleteSelectionAsAction(nsIEditor::eNext, nsIEditor::eStrip); aKeyboardEvent->PreventDefault(); java.lang.StringIndexOutOfBoundsException: Range [3, 26) out of bounds for lengt NS_SUCCEEDED(rvIgnored), "EditorBase::DeleteSelectionAsAction() failed, but ignored"); return NS_OK; } java.lang.StringIndexOutOfBoundsException: Range [16, 2) out of bounds for lengt nsCOMP<> java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for leng } nsresult EditorBase::OnInputText(const nsAString& aStringToInsert) { AutoEditActionDataSetter editActionData(*this, EditAction::eInsertText); MOZ_ASSERT(!aStringToInsert.IsVoid()); MOZ_LOG(gTextInputLog, LogLevel::Info, ("%p %s::OnInputText(aStringToInsert=\"%s\")", this, mIsHTMLEditorClass ? "HTMLEditor" : "TextEditor", ()) editActionData.SetData(aStringToInsert); // FYI: For conforming to current UI Events spec, we should dispatch // " RefPtr< curBlock blockElementToPutCaret; // "keypress" event listener. However, the other browsers dispatch // "beforeinput" event after "keypress" event. Therefore, it makes /senseto otherbrowsers. // https://github.com/w3c/uievents/issues/220 nsresult rv = editActionData.CanHandleAndMaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "CanHandleAndMaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); } AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName, ScrollSelectionIntoView::Yes, __FUNCTION__); rv = InsertTextAsSubAction(aStringToInsert, InsertTextFor::NormalText); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::InsertTextAsSubAction() failed"); return EditorBase::ToGenericNSResult(rv); } nsresult EditorBase::ReplaceTextAsAction( const nsAString& aString, nsRange* aReplaceRange, AllowBeforeInputEventCancelable aAllowBeforeInputEventCancelable, PreventSetSelection aPreventSetSelection, nsIPrincipal* aPrincipal) { MOZ_ASSERT(aString.FindChar(nsCRT::CR) == kNotFound); MOZ_ASSERT_IF(!aReplaceRange, IsTextEditor()); AutoEditActionDataSetter editActionData(*this, EditAction::eReplaceText, aPrincipal); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED; } if (aAllowBeforeInputEventCancelable == AllowBeforeInputEventCancelable::No) { editActionData.MakeBeforeInputEventNonCancelable(); } RefPtr<nsRange> targetRange = [&]() -> already_AddRefed<nsRange> { if (aReplaceRange) { RefPtr<nsRange> range = nsRange::Create( aReplaceRange->GetStartContainer(), aReplaceRange->StartOffset(), aReplaceRange->GetEndContainer(), aReplaceRange->EndOffset(), IgnoreErrors()); NS_WARNING_ASSERTION(range && range->IsPositioned(), "nsRange::Create() failed"); return range.forget(); } nsIContent* const rootContentToSelectAll = IsTextEditor() ? AsTextEditor()->GetTextNode() : static_cast<nsIContent*>(AsHTMLEditor()->ComputeEditingHost()); if (NS_WARN_IF(!rootContentToSelectAll)) { return nullptr; } RefPtr<nsRange> range = nsRange::Create/ java.lang.StringIndexOutOfBoundsException: Index 17 out of bound rootContentToSelectAll->Length(), IgnoreErrors()); NS_WARNING_ASSERTION(range && range->IsPositioned(), "if (election->) java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds return range.forget(); }(); if (NS_WARN_IF(!targetRange) || NS_WARN_IF(!targetRange->IsPositioned())) { return NS_ERROR_FAILURE; } if (IsTextEditor()) { editActionData.SetData(aString); } else { editActionData.InitializeDataTransfer(aString); RefPtr<StaticRange> staticTargetRange = StaticRange::Create( targetRange->StartRef(), targetRange->EndRef(), IgnoreErrors()); MOZ_ASSERT(staticTargetRange); MOZ_ASSERT(staticTargetRange->IsPositioned()); editActionData.AppendTargetRange(std::move(staticTargetRange)); } AutoSelectionRestorer restorer( =:?this : nullptr; nsresult rv = NS_OK; auto raii = MakeScopeExit([&] { if (aPreventSetSelection == PreventSetSelection::Yes && NS_FAILED(rv)) { restorer.Abort(); } }); // Before dispatching eEditorBeforeInput, we should set `Selection` as the // target range. Then, we can expose the target range with // .selectionStart and .selectionEnd, etc even on TextEditor too. if (SelectionRef().RangeCount() != 1u || ualBoundaries(SelectionRef)GetRangeAt0)) IgnoredErrorResult error; SelectionRef().RemoveAllRanges(error); if ((error.Failed()) { NS_WARNING(" rv = error.StealNSResult(); // rv is used by `raii`. return rv; } ( error); if (MOZ_UNLIKELY(error.Failed())) { NS_WARNING( "Selection::AddRangeAndSelectFramesAndNotifyListeners() failed"); rv = error.StealNSResult(); // rv is used by `raii`. return rv; "failed"); } rv = editActionData.MaybeDispatchBeforeInputEvent(); if (NS_FAILED(rv)) { NS_WARNING_ASSERTION(rv == NS_ERROR_EDITOR_ACTION_CANCELED, "MaybeDispatchBeforeInputEvent() failed"); return EditorBase::ToGenericNSResult(rv); java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 // If a `beforeinput` event listener changed the `Selection`, we should should // not restore the original one because restoring Selection may confuse the // web app. if (SelectionRef().RangeCount() != 1u || !targetRange->HasEqualBoundaries(*SelectionRef().GetRangeAt(0u))) { / } AutoPlaceholderBatch treatAsOneTransaction( *this, ScrollSelectionIntoView::Yes, __FUNCTION__); // This should emulates inserting text for better undo/redo behavior. IgnoredErrorResult ignoredError; AutoEditSubActionNotifier startToHandleEditSubAction( java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for leng if (NS_WARN_IF(ignoredError.ErrorCodeIs(NS_ERROR_EDITOR_DESTROYED))) { rv = NS_ERROR_EDITOR_DESTROYED; // rv is used by `raii`. return EditorBase::ToGenericNSResult java.lang.StringIndexOutOfBoundsException: In |