author | Masayuki Nakano <masayuki@d-toybox.com> |
Fri, 29 May 2015 00:58:42 +0900 | |
changeset 246166 | f2a922fd623e11743f1f2d5379799dab857e4893 |
parent 246165 | 703ace2e04148859467b4d2276d0ffbdbe86e7e0 |
child 246167 | c64cfd067b1ef76e539c9b47d1a67af422c3a91c |
push id | 28823 |
push user | ryanvm@gmail.com |
push date | Fri, 29 May 2015 13:33:16 +0000 |
treeherder | mozilla-central@9738f055d98c [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ehsan |
bugs | 1169139 |
milestone | 41.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/editor/composer/nsComposeTxtSrvFilter.h +++ b/editor/composer/nsComposeTxtSrvFilter.h @@ -19,37 +19,37 @@ class nsComposeTxtSrvFilter final : public nsITextServicesFilter { public: nsComposeTxtSrvFilter(); // nsISupports interface... NS_DECL_ISUPPORTS - // nsITextServicesFilter + // nsITextServicesFilter NS_DECL_NSITEXTSERVICESFILTER // Helper - Intializer void Init(bool aIsForMail) { mIsForMail = aIsForMail; } private: ~nsComposeTxtSrvFilter() {} bool mIsForMail; }; #define NS_COMPOSERTXTSRVFILTER_CID \ {/* {171E72DB-0F8A-412a-8461-E4C927A3A2AC}*/ \ 0x171e72db, 0xf8a, 0x412a, \ -{ 0x84, 0x61, 0xe4, 0xc9, 0x27, 0xa3, 0xa2, 0xac} } +{ 0x84, 0x61, 0xe4, 0xc9, 0x27, 0xa3, 0xa2, 0xac} } #define NS_COMPOSERTXTSRVFILTERMAIL_CID \ {/* {7FBD2146-5FF4-4674-B069-A7BBCE66E773}*/ \ 0x7fbd2146, 0x5ff4, 0x4674, \ -{ 0xb0, 0x69, 0xa7, 0xbb, 0xce, 0x66, 0xe7, 0x73} } +{ 0xb0, 0x69, 0xa7, 0xbb, 0xce, 0x66, 0xe7, 0x73} } // Generic for the editor #define COMPOSER_TXTSRVFILTER_CONTRACTID "@mozilla.org/editor/txtsrvfilter;1" // This is the same but includes "cite" typed blocked quotes #define COMPOSER_TXTSRVFILTERMAIL_CONTRACTID "@mozilla.org/editor/txtsrvfiltermail;1" #endif
--- a/editor/composer/nsComposerCommands.cpp +++ b/editor/composer/nsComposerCommands.cpp @@ -96,37 +96,37 @@ NS_IMETHODIMP nsBaseStateUpdatingCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { return DoCommand(aCommandName, refCon); } NS_IMETHODIMP -nsBaseStateUpdatingCommand::GetCommandStateParams(const char *aCommandName, +nsBaseStateUpdatingCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); if (editor) return GetCurrentState(editor, aParams); return NS_OK; } NS_IMETHODIMP -nsPasteNoFormattingCommand::IsCommandEnabled(const char * aCommandName, - nsISupports *refCon, +nsPasteNoFormattingCommand::IsCommandEnabled(const char * aCommandName, + nsISupports *refCon, bool *outCmdEnabled) { NS_ENSURE_ARG_POINTER(outCmdEnabled); *outCmdEnabled = false; // This command is only implemented by nsIHTMLEditor, since - // pasting in a plaintext editor automatically only supplies + // pasting in a plaintext editor automatically only supplies // "unformatted" text nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED); nsCOMPtr<nsIEditor> editor = do_QueryInterface(htmlEditor); NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); return editor->CanPaste(nsIClipboard::kGlobalClipboard, outCmdEnabled); @@ -140,17 +140,17 @@ nsPasteNoFormattingCommand::DoCommand(co nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED); return htmlEditor->PasteNoFormatting(nsIClipboard::kGlobalClipboard); } NS_IMETHODIMP nsPasteNoFormattingCommand::DoCommandParams(const char *aCommandName, - nsICommandParams *aParams, + nsICommandParams *aParams, nsISupports *refCon) { return DoCommand(aCommandName, refCon); } NS_IMETHODIMP nsPasteNoFormattingCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, @@ -166,23 +166,23 @@ nsPasteNoFormattingCommand::GetCommandSt } nsStyleUpdatingCommand::nsStyleUpdatingCommand(nsIAtom* aTagName) : nsBaseStateUpdatingCommand(aTagName) { } nsresult -nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, +nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need editor here"); nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_INITIALIZED); - + bool firstOfSelectionHasProp = false; bool anyOfSelectionHasProp = false; bool allOfSelectionHasProp = false; nsresult rv = htmlEditor->GetInlineProperty(mTagName, EmptyString(), EmptyString(), &firstOfSelectionHasProp, &anyOfSelectionHasProp, @@ -206,17 +206,17 @@ nsStyleUpdatingCommand::ToggleState(nsIE //create some params now... nsresult rv; nsCOMPtr<nsICommandParams> params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); if (NS_FAILED(rv) || !params) return rv; - // tags "href" and "name" are special cases in the core editor + // tags "href" and "name" are special cases in the core editor // they are used to remove named anchor/link and shouldn't be used for insertion bool doTagRemoval; if (mTagName == nsGkAtoms::href || mTagName == nsGkAtoms::name) { doTagRemoval = true; } else { // check current selection; set doTagRemoval if formatting should be removed rv = GetCurrentState(aEditor, params); NS_ENSURE_SUCCESS(rv, rv); @@ -295,21 +295,21 @@ nsListCommand::ToggleState(nsIEditor *aE NS_ENSURE_SUCCESS(rv, rv); bool inList; rv = params->GetBooleanValue(STATE_ALL,&inList); NS_ENSURE_SUCCESS(rv, rv); nsDependentAtomString listType(mTagName); if (inList) { - rv = editor->RemoveList(listType); + rv = editor->RemoveList(listType); } else { rv = editor->MakeOrChangeList(listType, false, EmptyString()); } - + return rv; } nsListItemCommand::nsListItemCommand(nsIAtom* aTagName) : nsBaseStateUpdatingCommand(aTagName) { } @@ -357,23 +357,23 @@ nsListItemCommand::ToggleState(nsIEditor nsCOMPtr<nsICommandParams> params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); if (NS_FAILED(rv) || !params) return rv; rv = GetCurrentState(aEditor, params); rv = params->GetBooleanValue(STATE_ALL,&inList); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv); - + if (inList) { // To remove a list, first get what kind of list we're in bool bMixed; nsAutoString localName; rv = GetListState(htmlEditor, &bMixed, localName); - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_SUCCESS(rv, rv); if (localName.IsEmpty() || bMixed) { return rv; } return htmlEditor->RemoveList(localName); } // Set to the requested paragraph type //XXX Note: This actually doesn't work for "LI", @@ -419,30 +419,30 @@ nsRemoveListCommand::DoCommand(const cha nsresult rv = NS_OK; if (editor) { // This removes any list type rv = editor->RemoveList(EmptyString()); } - return rv; + return rv; } NS_IMETHODIMP -nsRemoveListCommand::DoCommandParams(const char *aCommandName, +nsRemoveListCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { return DoCommand(aCommandName, refCon); } NS_IMETHODIMP nsRemoveListCommand::GetCommandStateParams(const char *aCommandName, - nsICommandParams *aParams, + nsICommandParams *aParams, nsISupports *refCon) { bool outCmdEnabled = false; IsCommandEnabled(aCommandName, refCon, &outCmdEnabled); return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled); } NS_IMETHODIMP @@ -463,26 +463,26 @@ nsIndentCommand::DoCommand(const char *a { nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon); nsresult rv = NS_OK; if (editor) { rv = editor->Indent(NS_LITERAL_STRING("indent")); } - - return rv; + + return rv; } NS_IMETHODIMP nsIndentCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { - return DoCommand(aCommandName, refCon); + return DoCommand(aCommandName, refCon); } NS_IMETHODIMP nsIndentCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { bool outCmdEnabled = false; @@ -511,26 +511,26 @@ nsOutdentCommand::IsCommandEnabled(const NS_IMETHODIMP nsOutdentCommand::DoCommand(const char *aCommandName, nsISupports *refCon) { nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(refCon); if (htmlEditor) return htmlEditor->Indent(NS_LITERAL_STRING("outdent")); - - return NS_OK; + + return NS_OK; } NS_IMETHODIMP nsOutdentCommand::DoCommandParams(const char *aCommandName, - nsICommandParams *aParams, + nsICommandParams *aParams, nsISupports *refCon) { - return DoCommand(aCommandName, refCon); + return DoCommand(aCommandName, refCon); } NS_IMETHODIMP nsOutdentCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { bool outCmdEnabled = false; @@ -555,29 +555,29 @@ nsMultiStateCommand::IsCommandEnabled(co bool *outCmdEnabled) { nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); // should be disabled sometimes, like if the current selection is an image if (editor) return editor->GetIsSelectionEditable(outCmdEnabled); *outCmdEnabled = false; - return NS_OK; + return NS_OK; } NS_IMETHODIMP nsMultiStateCommand::DoCommand(const char *aCommandName, nsISupports *refCon) { #ifdef DEBUG printf("who is calling nsMultiStateCommand::DoCommand \ (no implementation)? %s\n", aCommandName); #endif - - return NS_OK; + + return NS_OK; } NS_IMETHODIMP nsMultiStateCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); @@ -593,18 +593,18 @@ nsMultiStateCommand::DoCommandParams(con if (NS_SUCCEEDED(rv)) tString.AssignWithConversion(s); else rv = aParams->GetStringValue(STATE_ATTRIBUTE, tString); } rv = SetState(editor, tString); } - - return rv; + + return rv; } NS_IMETHODIMP nsMultiStateCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); @@ -621,17 +621,17 @@ nsParagraphStateCommand::nsParagraphStat { } nsresult nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); - + nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); bool outMixed; nsAutoString outStateString; nsresult rv = htmlEditor->GetParagraphState(&outMixed, outStateString); if (NS_SUCCEEDED(rv)) { @@ -680,17 +680,17 @@ nsFontFaceStateCommand::GetCurrentState( nsresult nsFontFaceStateCommand::SetState(nsIEditor *aEditor, nsString& newState) { NS_ASSERTION(aEditor, "Need an editor here"); nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); - + if (newState.EqualsLiteral("tt")) { // The old "teletype" attribute nsresult rv = htmlEditor->SetInlineProperty(nsGkAtoms::tt, EmptyString(), EmptyString()); NS_ENSURE_SUCCESS(rv, rv); // Clear existing font face return htmlEditor->RemoveInlineProperty(nsGkAtoms::font, NS_LITERAL_STRING("face")); @@ -783,17 +783,17 @@ nsFontColorStateCommand::nsFontColorStat { } nsresult nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); - + nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); bool outMixed; nsAutoString outStateString; nsresult rv = htmlEditor->GetFontColorState(&outMixed, outStateString); NS_ENSURE_SUCCESS(rv, rv); @@ -805,22 +805,22 @@ nsFontColorStateCommand::GetCurrentState } nsresult nsFontColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState) { NS_ASSERTION(aEditor, "Need an editor here"); nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); - + if (newState.IsEmpty() || newState.EqualsLiteral("normal")) { return htmlEditor->RemoveInlineProperty(nsGkAtoms::font, NS_LITERAL_STRING("color")); } - + return htmlEditor->SetInlineProperty(nsGkAtoms::font, NS_LITERAL_STRING("color"), newState); } nsHighlightColorStateCommand::nsHighlightColorStateCommand() : nsMultiStateCommand() { } @@ -881,17 +881,17 @@ nsBackgroundColorStateCommand::nsBackgro { } nsresult nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); - + nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); bool outMixed; nsAutoString outStateString; nsresult rv = htmlEditor->GetBackgroundColorState(&outMixed, outStateString); NS_ENSURE_SUCCESS(rv, rv); @@ -901,54 +901,54 @@ nsBackgroundColorStateCommand::GetCurren aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get()); return NS_OK; } nsresult nsBackgroundColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState) { NS_ASSERTION(aEditor, "Need an editor here"); - + nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); return htmlEditor->SetBackgroundColor(newState); } nsAlignCommand::nsAlignCommand() : nsMultiStateCommand() { } nsresult nsAlignCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); - + nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); - + nsIHTMLEditor::EAlignment firstAlign; bool outMixed; nsresult rv = htmlEditor->GetAlignment(&outMixed, &firstAlign); - + NS_ENSURE_SUCCESS(rv, rv); - + nsAutoString outStateString; switch (firstAlign) { default: case nsIHTMLEditor::eLeft: outStateString.AssignLiteral("left"); break; - + case nsIHTMLEditor::eCenter: outStateString.AssignLiteral("center"); break; - + case nsIHTMLEditor::eRight: outStateString.AssignLiteral("right"); break; case nsIHTMLEditor::eJustify: outStateString.AssignLiteral("justify"); break; } @@ -958,17 +958,17 @@ nsAlignCommand::GetCurrentState(nsIEdito aParams->SetCStringValue(STATE_ATTRIBUTE, tOutStateString.get()); return NS_OK; } nsresult nsAlignCommand::SetState(nsIEditor *aEditor, nsString& newState) { NS_ASSERTION(aEditor, "Need an editor here"); - + nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); return htmlEditor->Align(newState); } nsAbsolutePositioningCommand::nsAbsolutePositioningCommand() : nsBaseStateUpdatingCommand(nsGkAtoms::_empty) @@ -994,17 +994,17 @@ nsAbsolutePositioningCommand::IsCommandE *outCmdEnabled = false; return NS_OK; } nsresult nsAbsolutePositioningCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) { NS_ASSERTION(aEditor, "Need an editor here"); - + nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); bool isEnabled; htmlEditor->GetAbsolutePositioningEnabled(&isEnabled); if (!isEnabled) { aParams->SetBooleanValue(STATE_MIXED,false); aParams->SetCStringValue(STATE_ATTRIBUTE, ""); @@ -1023,17 +1023,17 @@ nsAbsolutePositioningCommand::GetCurrent aParams->SetCStringValue(STATE_ATTRIBUTE, NS_ConvertUTF16toUTF8(outStateString).get()); return NS_OK; } nsresult nsAbsolutePositioningCommand::ToggleState(nsIEditor *aEditor) { NS_ASSERTION(aEditor, "Need an editor here"); - + nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(aEditor); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_FAILURE); nsCOMPtr<nsIDOMElement> elt; nsresult rv = htmlEditor->GetAbsolutelyPositionedSelectionContainer(getter_AddRefs(elt)); NS_ENSURE_SUCCESS(rv, rv); return htmlEditor->AbsolutePositionSelection(!elt); @@ -1072,17 +1072,17 @@ nsDecreaseZIndexCommand::DoCommand(const nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED); return htmlEditor->RelativeChangeZIndex(-1); } NS_IMETHODIMP nsDecreaseZIndexCommand::DoCommandParams(const char *aCommandName, - nsICommandParams *aParams, + nsICommandParams *aParams, nsISupports *refCon) { return DoCommand(aCommandName, refCon); } NS_IMETHODIMP nsDecreaseZIndexCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, @@ -1122,17 +1122,17 @@ nsIncreaseZIndexCommand::DoCommand(const nsCOMPtr<nsIHTMLAbsPosEditor> htmlEditor = do_QueryInterface(refCon); NS_ENSURE_TRUE(htmlEditor, NS_ERROR_NOT_IMPLEMENTED); return htmlEditor->RelativeChangeZIndex(1); } NS_IMETHODIMP nsIncreaseZIndexCommand::DoCommandParams(const char *aCommandName, - nsICommandParams *aParams, + nsICommandParams *aParams, nsISupports *refCon) { return DoCommand(aCommandName, refCon); } NS_IMETHODIMP nsIncreaseZIndexCommand::GetCommandStateParams(const char *aCommandName, nsICommandParams *aParams, @@ -1170,18 +1170,18 @@ nsRemoveStylesCommand::DoCommand(const c { nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon); nsresult rv = NS_OK; if (editor) { rv = editor->RemoveAllInlineProperties(); } - - return rv; + + return rv; } NS_IMETHODIMP nsRemoveStylesCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { return DoCommand(aCommandName, refCon); @@ -1218,18 +1218,18 @@ nsIncreaseFontSizeCommand::DoCommand(con { nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon); nsresult rv = NS_OK; if (editor) { rv = editor->IncreaseFontSize(); } - - return rv; + + return rv; } NS_IMETHODIMP nsIncreaseFontSizeCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { return DoCommand(aCommandName, refCon); @@ -1266,18 +1266,18 @@ nsDecreaseFontSizeCommand::DoCommand(con { nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon); nsresult rv = NS_OK; if (editor) { rv = editor->DecreaseFontSize(); } - - return rv; + + return rv; } NS_IMETHODIMP nsDecreaseFontSizeCommand::DoCommandParams(const char *aCommandName, nsICommandParams *aParams, nsISupports *refCon) { return DoCommand(aCommandName, refCon); @@ -1377,17 +1377,17 @@ nsInsertTagCommand::IsCommandEnabled(con if (editor) return editor->GetIsSelectionEditable(outCmdEnabled); *outCmdEnabled = false; return NS_OK; } -// corresponding STATE_ATTRIBUTE is: src (img) and href (a) +// corresponding STATE_ATTRIBUTE is: src (img) and href (a) NS_IMETHODIMP nsInsertTagCommand::DoCommand(const char *aCmdName, nsISupports *refCon) { NS_ENSURE_TRUE(mTagName == nsGkAtoms::hr, NS_ERROR_NOT_IMPLEMENTED); nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(refCon); NS_ENSURE_TRUE(editor, NS_ERROR_NOT_IMPLEMENTED); @@ -1513,17 +1513,17 @@ RemoveOneProperty(nsIHTMLEditor* aEditor nsresult RemoveTextProperty(nsIHTMLEditor* aEditor, const nsAString& aProp) { MOZ_ASSERT(aEditor); if (aProp.LowerCaseEqualsLiteral("all")) { return aEditor->RemoveAllInlineProperties(); } - + return RemoveOneProperty(aEditor, aProp); } // the name of the attribute here should be the contents of the appropriate // tag, e.g. 'b' for bold, 'i' for italics. nsresult SetTextProperty(nsIHTMLEditor* aEditor, const nsAString& aProp) {
--- a/editor/composer/nsComposerCommands.h +++ b/editor/composer/nsComposerCommands.h @@ -61,47 +61,47 @@ public: NS_DECL_NSICONTROLLERCOMMAND protected: virtual ~nsBaseStateUpdatingCommand(); // get the current state (on or off) for this style or block format virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams) = 0; - + // add/remove the style virtual nsresult ToggleState(nsIEditor* aEditor) = 0; protected: nsIAtom* mTagName; }; // Shared class for the various style updating commands like bold, italics etc. // Suitable for commands whose state is either 'on' or 'off'. class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand { public: explicit nsStyleUpdatingCommand(nsIAtom* aTagName); - + protected: // get the current state (on or off) for this style or block format virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); - + // add/remove the style virtual nsresult ToggleState(nsIEditor* aEditor); }; class nsInsertTagCommand : public nsBaseComposerCommand { public: explicit nsInsertTagCommand(nsIAtom* aTagName); - + NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSICONTROLLERCOMMAND protected: virtual ~nsInsertTagCommand(); nsIAtom* mTagName; @@ -112,51 +112,51 @@ class nsListCommand : public nsBaseState { public: explicit nsListCommand(nsIAtom* aTagName); protected: // get the current state (on or off) for this style or block format virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); - + // add/remove the style virtual nsresult ToggleState(nsIEditor* aEditor); }; class nsListItemCommand : public nsBaseStateUpdatingCommand { public: explicit nsListItemCommand(nsIAtom* aTagName); protected: // get the current state (on or off) for this style or block format virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); - + // add/remove the style virtual nsresult ToggleState(nsIEditor* aEditor); }; // Base class for commands whose state consists of a string (e.g. para format) class nsMultiStateCommand : public nsBaseComposerCommand { public: - + nsMultiStateCommand(); - + NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSICONTROLLERCOMMAND protected: virtual ~nsMultiStateCommand(); virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0; virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0; - + }; class nsParagraphStateCommand : public nsMultiStateCommand { public: nsParagraphStateCommand();
--- a/editor/composer/nsComposerCommandsUpdater.cpp +++ b/editor/composer/nsComposerCommandsUpdater.cpp @@ -59,17 +59,17 @@ NS_IMETHODIMP nsComposerCommandsUpdater::NotifyDocumentWillBeDestroyed() { // cancel any outstanding update timer if (mUpdateTimer) { mUpdateTimer->Cancel(); mUpdateTimer = nullptr; } - + // We can't call this right now; it is too late in some cases and the window // is already partially destructed (e.g. JS objects may be gone). #if 0 // Trigger an nsIObserve notification that the document will be destroyed UpdateOneCommand("obs_documentWillBeDestroyed"); #endif return NS_OK; } @@ -109,21 +109,21 @@ nsComposerCommandsUpdater::DidDo(nsITran int32_t undoCount; aManager->GetNumberOfUndoItems(&undoCount); if (undoCount == 1) { if (mFirstDoOfFirstUndo) UpdateCommandGroup(NS_LITERAL_STRING("undo")); mFirstDoOfFirstUndo = false; } - + return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsComposerCommandsUpdater::WillUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, bool *aInterrupt) { *aInterrupt = false; return NS_OK; } @@ -146,17 +146,17 @@ nsComposerCommandsUpdater::WillRedo(nsIT nsITransaction *aTransaction, bool *aInterrupt) { *aInterrupt = false; return NS_OK; } NS_IMETHODIMP -nsComposerCommandsUpdater::DidRedo(nsITransactionManager *aManager, +nsComposerCommandsUpdater::DidRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aRedoResult) { UpdateCommandGroup(NS_LITERAL_STRING("undo")); return NS_OK; } NS_IMETHODIMP @@ -178,17 +178,17 @@ NS_IMETHODIMP nsComposerCommandsUpdater::WillEndBatch(nsITransactionManager *aManager, bool *aInterrupt) { *aInterrupt = false; return NS_OK; } NS_IMETHODIMP -nsComposerCommandsUpdater::DidEndBatch(nsITransactionManager *aManager, +nsComposerCommandsUpdater::DidEndBatch(nsITransactionManager *aManager, nsresult aResult) { return NS_OK; } NS_IMETHODIMP nsComposerCommandsUpdater::WillMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction, @@ -272,17 +272,17 @@ nsComposerCommandsUpdater::UpdateDirtySt } nsresult nsComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup) { nsCOMPtr<nsPICommandUpdater> commandUpdater = GetCommandUpdater(); NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE); - + // This hardcoded list of commands is temporary. // This code should use nsIControllerCommandGroup. if (aCommandGroup.EqualsLiteral("undo")) { commandUpdater->CommandStatusChanged("cmd_undo"); commandUpdater->CommandStatusChanged("cmd_redo"); } else if (aCommandGroup.EqualsLiteral("select") || @@ -301,44 +301,44 @@ nsComposerCommandsUpdater::UpdateCommand commandUpdater->CommandStatusChanged("cmd_em"); commandUpdater->CommandStatusChanged("cmd_strong"); commandUpdater->CommandStatusChanged("cmd_cite"); commandUpdater->CommandStatusChanged("cmd_abbr"); commandUpdater->CommandStatusChanged("cmd_acronym"); commandUpdater->CommandStatusChanged("cmd_code"); commandUpdater->CommandStatusChanged("cmd_samp"); commandUpdater->CommandStatusChanged("cmd_var"); - + commandUpdater->CommandStatusChanged("cmd_increaseFont"); commandUpdater->CommandStatusChanged("cmd_decreaseFont"); commandUpdater->CommandStatusChanged("cmd_paragraphState"); commandUpdater->CommandStatusChanged("cmd_fontFace"); commandUpdater->CommandStatusChanged("cmd_fontColor"); commandUpdater->CommandStatusChanged("cmd_backgroundColor"); commandUpdater->CommandStatusChanged("cmd_highlight"); - } + } else if (aCommandGroup.EqualsLiteral("save")) { // save commands (most are not in C++) commandUpdater->CommandStatusChanged("cmd_setDocumentModified"); commandUpdater->CommandStatusChanged("cmd_save"); } - return NS_OK; + return NS_OK; } nsresult nsComposerCommandsUpdater::UpdateOneCommand(const char *aCommand) { nsCOMPtr<nsPICommandUpdater> commandUpdater = GetCommandUpdater(); NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE); commandUpdater->CommandStatusChanged(aCommand); - return NS_OK; + return NS_OK; } bool nsComposerCommandsUpdater::SelectionIsCollapsed() { nsCOMPtr<nsIDOMWindow> domWindow = do_QueryReferent(mDOMWindow); NS_ENSURE_TRUE(domWindow, true);
--- a/editor/composer/nsComposerCommandsUpdater.h +++ b/editor/composer/nsComposerCommandsUpdater.h @@ -30,28 +30,28 @@ class nsComposerCommandsUpdater : public public nsITimerCallback { public: nsComposerCommandsUpdater(); // nsISupports NS_DECL_ISUPPORTS - + // nsISelectionListener NS_DECL_NSISELECTIONLISTENER - + // nsIDocumentStateListener NS_DECL_NSIDOCUMENTSTATELISTENER // nsITimerCallback interfaces NS_DECL_NSITIMERCALLBACK /** nsITransactionListener interfaces - */ + */ NS_IMETHOD WillDo(nsITransactionManager *aManager, nsITransaction *aTransaction, bool *aInterrupt) override; NS_IMETHOD DidDo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aDoResult) override; NS_IMETHOD WillUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, bool *aInterrupt) override; NS_IMETHOD DidUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aUndoResult) override; NS_IMETHOD WillRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, bool *aInterrupt) override; NS_IMETHOD DidRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aRedoResult) override; NS_IMETHOD WillBeginBatch(nsITransactionManager *aManager, bool *aInterrupt) override; NS_IMETHOD DidBeginBatch(nsITransactionManager *aManager, nsresult aResult) override; @@ -70,33 +70,33 @@ protected: virtual ~nsComposerCommandsUpdater(); enum { eStateUninitialized = -1, eStateOff = false, eStateOn = true }; - + bool SelectionIsCollapsed(); - nsresult UpdateDirtyState(bool aNowDirty); + nsresult UpdateDirtyState(bool aNowDirty); nsresult UpdateOneCommand(const char* aCommand); nsresult UpdateCommandGroup(const nsAString& aCommandGroup); already_AddRefed<nsPICommandUpdater> GetCommandUpdater(); - + nsresult PrimeUpdateTimer(); void TimerCallback(); nsCOMPtr<nsITimer> mUpdateTimer; nsWeakPtr mDOMWindow; nsWeakPtr mDocShell; - int8_t mDirtyState; - int8_t mSelectionCollapsed; + int8_t mDirtyState; + int8_t mSelectionCollapsed; bool mFirstDoOfFirstUndo; - + }; extern "C" nsresult NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult); #endif // nsComposerCommandsUpdater_h__
--- a/editor/composer/nsComposerController.cpp +++ b/editor/composer/nsComposerController.cpp @@ -35,24 +35,24 @@ class nsIControllerCommand; } #define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag) \ { \ _cmdClass* theCmd = new _cmdClass(_styleTag); \ inCommandTable->RegisterCommand(_cmdName, \ static_cast<nsIControllerCommand *>(theCmd)); \ } - + #define NS_REGISTER_TAG_COMMAND(_cmdClass, _cmdName, _tagName) \ { \ _cmdClass* theCmd = new _cmdClass(_tagName); \ inCommandTable->RegisterCommand(_cmdName, \ static_cast<nsIControllerCommand *>(theCmd)); \ } - + // static nsresult nsComposerController::RegisterEditorDocStateCommands( nsIControllerCommandTable *inCommandTable) { // observer commands for document state NS_REGISTER_FIRST_COMMAND(nsDocumentStateCommand, "obs_documentCreated")
--- a/editor/composer/nsComposerController.h +++ b/editor/composer/nsComposerController.h @@ -9,17 +9,17 @@ #include "nscore.h" // for nsresult class nsIControllerCommandTable; // The plaintext editor controller is used for basic text editing and html editing // commands in composer -// The refCon that gets passed to its commands is initially nsIEditingSession, +// The refCon that gets passed to its commands is initially nsIEditingSession, // and after successfule editor creation it is changed to nsIEditor. #define NS_EDITORDOCSTATECONTROLLER_CID \ { 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } } // The HTMLEditor controller is used only for HTML editors and takes nsIEditor as refCon #define NS_HTMLEDITORCONTROLLER_CID \ { 0x62db0002, 0xdbb6, 0x43f4, { 0x8f, 0xb7, 0x9d, 0x25, 0x38, 0xbc, 0x57, 0x47 } }
--- a/editor/composer/nsComposerDocumentCommands.cpp +++ b/editor/composer/nsComposerDocumentCommands.cpp @@ -87,26 +87,26 @@ nsSetDocumentOptionsCommand::DoCommandPa nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); nsRefPtr<nsPresContext> presContext; nsresult rv = GetPresContextFromEditor(editor, getter_AddRefs(presContext)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); - int32_t animationMode; + int32_t animationMode; rv = aParams->GetLongValue("imageAnimation", &animationMode); if (NS_SUCCEEDED(rv)) { // for possible values of animation mode, see: // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl presContext->SetImageAnimationMode(animationMode); } - bool allowPlugins; + bool allowPlugins; rv = aParams->GetBooleanValue("plugins", &allowPlugins); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIDocShell> docShell(presContext->GetDocShell()); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); rv = docShell->SetAllowPlugins(allowPlugins); NS_ENSURE_SUCCESS(rv, rv); @@ -145,17 +145,17 @@ nsSetDocumentOptionsCommand::GetCommandS { // for possible values of animation mode, see // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl rv = aParams->SetLongValue("imageAnimation", presContext->ImageAnimationMode()); NS_ENSURE_SUCCESS(rv, rv); } - bool allowPlugins = false; + bool allowPlugins = false; rv = aParams->GetBooleanValue("plugins", &allowPlugins); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIDocShell> docShell(presContext->GetDocShell()); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); allowPlugins = docShell->PluginsAllowedInCurrentDoc(); @@ -200,33 +200,33 @@ nsSetDocumentStateCommand::DoCommandPara { nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); NS_ENSURE_TRUE(editor, NS_ERROR_INVALID_ARG); if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentModified")) { NS_ENSURE_ARG_POINTER(aParams); - bool modified; + bool modified; nsresult rv = aParams->GetBooleanValue(STATE_ATTRIBUTE, &modified); // Should we fail if this param wasn't set? // I'm not sure we should be that strict NS_ENSURE_SUCCESS(rv, rv); if (modified) return editor->IncrementModificationCount(1); return editor->ResetModificationCount(); } if (!nsCRT::strcmp(aCommandName, "cmd_setDocumentReadOnly")) { NS_ENSURE_ARG_POINTER(aParams); - bool isReadOnly; + bool isReadOnly; nsresult rvRO = aParams->GetBooleanValue(STATE_ATTRIBUTE, &isReadOnly); NS_ENSURE_SUCCESS(rvRO, rvRO); uint32_t flags; editor->GetFlags(&flags); if (isReadOnly) flags |= nsIPlaintextEditor::eEditorReadonlyMask; else @@ -371,48 +371,48 @@ nsSetDocumentStateCommand::GetCommandSta editor->GetInlineTableEditingEnabled(&enabled); return aParams->SetBooleanValue(STATE_ATTRIBUTE, enabled); } return NS_ERROR_NOT_IMPLEMENTED; } /** - * Commands just for state notification + * Commands just for state notification * As of 11/21/02, possible commands are: * "obs_documentCreated" * "obs_documentWillBeDestroyed" * "obs_documentLocationChanged" * Note that you can use the same command class, nsDocumentStateCommand * for these or future observer commands. * We check the input command param for different behavior * * How to use: * 1. Get the nsICommandManager for the current editor * 2. Implement an nsIObserve object, e.g: * - * void Observe( + * void Observe( * in nsISupports aSubject, // The nsICommandManager calling this Observer * in string aTopic, // command name, e.g.:"obs_documentCreated" * // or "obs_documentWillBeDestroyed" in wstring aData ); // ignored (set to "command_status_changed") * * 3. Add the observer by: * commandManager.addObserver(observeobject, obs_documentCreated); - * 4. In the appropriate location in editorSession, editor, or commands code, + * 4. In the appropriate location in editorSession, editor, or commands code, * trigger the notification of this observer by something like: * * nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(mDocShell); * nsCOMPtr<nsPICommandUpdater> commandUpdater = do_QueryInterface(commandManager); * NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE); * commandUpdater->CommandStatusChanged(obs_documentCreated); * * 5. Use GetCommandStateParams() to obtain state information - * e.g., any creation state codes when creating an editor are - * supplied for "obs_documentCreated" command in the + * e.g., any creation state codes when creating an editor are + * supplied for "obs_documentCreated" command in the * "state_data" param's value * */ NS_IMETHODIMP nsDocumentStateCommand::IsCommandEnabled(const char* aCommandName, nsISupports *refCon, bool *outCmdEnabled) @@ -452,46 +452,46 @@ nsDocumentStateCommand::GetCommandStateP uint32_t editorStatus = nsIEditingSession::eEditorErrorUnknown; nsCOMPtr<nsIEditingSession> editingSession = do_QueryInterface(refCon); if (editingSession) { // refCon is initially set to nsIEditingSession until editor // is successfully created and source doc is loaded // Embedder gets error status if this fails - // If called before startup is finished, + // If called before startup is finished, // status = eEditorCreationInProgress rv = editingSession->GetEditorStatus(&editorStatus); NS_ENSURE_SUCCESS(rv, rv); } else { // If refCon is an editor, then everything started up OK! nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); if (editor) editorStatus = nsIEditingSession::eEditorOK; } // Note that if refCon is not-null, but is neither // an nsIEditingSession or nsIEditor, we return "eEditorErrorUnknown" aParams->SetLongValue(STATE_DATA, editorStatus); return NS_OK; - } + } else if (!nsCRT::strcmp(aCommandName, "obs_documentLocationChanged")) { nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon); if (editor) { nsCOMPtr<nsIDOMDocument> domDoc; editor->GetDocument(getter_AddRefs(domDoc)); nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); nsIURI *uri = doc->GetDocumentURI(); NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); return aParams->SetISupportsValue(STATE_DATA, (nsISupports*)uri); } return NS_OK; - } + } return NS_ERROR_NOT_IMPLEMENTED; }
--- a/editor/composer/nsComposerRegistration.cpp +++ b/editor/composer/nsComposerRegistration.cpp @@ -42,96 +42,96 @@ static NS_DEFINE_CID(kHTMLEditorDocState // Define the contructor function for the objects // // NOTE: This creates an instance of objects by using the default constructor // NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorSpellCheck) -// There are no macros that enable us to have 2 constructors +// There are no macros that enable us to have 2 constructors // for the same object // // Here we are creating the same object with two different contract IDs // and then initializing it different. // Basically, we need to tell the filter whether it is doing mail or not static nsresult nsComposeTxtSrvFilterConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult, bool aIsForMail) { *aResult = nullptr; - if (nullptr != aOuter) + if (nullptr != aOuter) { return NS_ERROR_NO_AGGREGATION; } nsComposeTxtSrvFilter * inst = new nsComposeTxtSrvFilter(); - if (nullptr == inst) + if (nullptr == inst) { return NS_ERROR_OUT_OF_MEMORY; } NS_ADDREF(inst); inst->Init(aIsForMail); nsresult rv = inst->QueryInterface(aIID, aResult); NS_RELEASE(inst); return rv; } static nsresult -nsComposeTxtSrvFilterConstructorForComposer(nsISupports *aOuter, +nsComposeTxtSrvFilterConstructorForComposer(nsISupports *aOuter, REFNSIID aIID, void **aResult) { return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, false); } static nsresult -nsComposeTxtSrvFilterConstructorForMail(nsISupports *aOuter, +nsComposeTxtSrvFilterConstructorForMail(nsISupports *aOuter, REFNSIID aIID, void **aResult) { return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, true); } // Constructor for a controller set up with a command table specified // by the CID passed in. This function uses do_GetService to get the // command table, so that every controller shares a single command // table, for space-efficiency. -// +// // The only reason to go via the service manager for the command table // is that it holds onto the singleton for us, avoiding static variables here. static nsresult CreateControllerWithSingletonCommandTable(const nsCID& inCommandTableCID, nsIController **aResult) { nsresult rv; nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIControllerCommandTable> composerCommandTable = do_GetService(inCommandTableCID, &rv); NS_ENSURE_SUCCESS(rv, rv); - + // this guy is a singleton, so make it immutable composerCommandTable->MakeImmutable(); - + nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv); NS_ENSURE_SUCCESS(rv, rv); - + rv = controllerContext->Init(composerCommandTable); NS_ENSURE_SUCCESS(rv, rv); - + *aResult = controller; NS_ADDREF(*aResult); return NS_OK; } // Here we make an instance of the controller that holds doc state commands. // We set it up with a singleton command table. static nsresult -nsHTMLEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID, +nsHTMLEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) { nsCOMPtr<nsIController> controller; nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorDocStateCommandTableCID, getter_AddRefs(controller)); NS_ENSURE_SUCCESS(rv, rv); return controller->QueryInterface(aIID, aResult); } @@ -145,50 +145,50 @@ nsHTMLEditorControllerConstructor(nsISup nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorCommandTableCID, getter_AddRefs(controller)); NS_ENSURE_SUCCESS(rv, rv); return controller->QueryInterface(aIID, aResult); } // Constructor for a command table that is pref-filled with HTML editor commands static nsresult -nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, +nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) { nsresult rv; nsCOMPtr<nsIControllerCommandTable> commandTable = do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - + rv = nsComposerController::RegisterHTMLEditorCommands(commandTable); NS_ENSURE_SUCCESS(rv, rv); - + // we don't know here whether we're being created as an instance, // or a service, so we can't become immutable - + return commandTable->QueryInterface(aIID, aResult); } // Constructor for a command table that is pref-filled with HTML editor doc state commands static nsresult -nsHTMLEditorDocStateCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, +nsHTMLEditorDocStateCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) { nsresult rv; nsCOMPtr<nsIControllerCommandTable> commandTable = do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - + rv = nsComposerController::RegisterEditorDocStateCommands(commandTable); NS_ENSURE_SUCCESS(rv, rv); - + // we don't know here whether we're being created as an instance, // or a service, so we can't become immutable - + return commandTable->QueryInterface(aIID, aResult); } NS_DEFINE_NAMED_CID(NS_HTMLEDITORCONTROLLER_CID); NS_DEFINE_NAMED_CID(NS_EDITORDOCSTATECONTROLLER_CID); NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_COMMANDTABLE_CID); NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID); NS_DEFINE_NAMED_CID(NS_EDITINGSESSION_CID);
--- a/editor/composer/nsEditingSession.cpp +++ b/editor/composer/nsEditingSession.cpp @@ -82,34 +82,34 @@ nsEditingSession::nsEditingSession() ----------------------------------------------------------------------------*/ nsEditingSession::~nsEditingSession() { // Must cancel previous timer? if (mLoadBlankDocTimer) mLoadBlankDocTimer->Cancel(); } -NS_IMPL_ISUPPORTS(nsEditingSession, nsIEditingSession, nsIWebProgressListener, +NS_IMPL_ISUPPORTS(nsEditingSession, nsIEditingSession, nsIWebProgressListener, nsISupportsWeakReference) /*--------------------------------------------------------------------------- MakeWindowEditable aEditorType string, "html" "htmlsimple" "text" "textsimple" - void makeWindowEditable(in nsIDOMWindow aWindow, in string aEditorType, + void makeWindowEditable(in nsIDOMWindow aWindow, in string aEditorType, in boolean aDoAfterUriLoad, in boolean aMakeWholeDocumentEditable, in boolean aInteractive); ----------------------------------------------------------------------------*/ #define DEFAULT_EDITOR_TYPE "html" NS_IMETHODIMP nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, - const char *aEditorType, + const char *aEditorType, bool aDoAfterUriLoad, bool aMakeWholeDocumentEditable, bool aInteractive) { mEditorType.Truncate(); mEditorFlags = 0; // disable plugins @@ -123,33 +123,33 @@ nsEditingSession::MakeWindowEditable(nsI nsresult rv; if (!mInteractive) { rv = DisableJSAndPlugins(aWindow); NS_ENSURE_SUCCESS(rv, rv); } // Always remove existing editor TearDownEditorOnWindow(aWindow); - + // Tells embedder that startup is in progress mEditorStatus = eEditorCreationInProgress; //temporary to set editor type here. we will need different classes soon. if (!aEditorType) aEditorType = DEFAULT_EDITOR_TYPE; mEditorType = aEditorType; - // if all this does is setup listeners and I don't need listeners, + // if all this does is setup listeners and I don't need listeners, // can't this step be ignored?? (based on aDoAfterURILoad) rv = PrepareForEditing(aWindow); - NS_ENSURE_SUCCESS(rv, rv); - + NS_ENSURE_SUCCESS(rv, rv); + // set the flag on the docShell to say that it's editable rv = docShell->MakeEditable(aDoAfterUriLoad); - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_SUCCESS(rv, rv); // Setup commands common to plaintext and html editors, // including the document creation observers // the first is an editing controller rv = SetupEditorCommandController("@mozilla.org/editor/editingcontroller;1", aWindow, static_cast<nsIEditingSession*>(this), &mBaseCommandControllerId); @@ -242,17 +242,17 @@ nsEditingSession::WindowIsEditable(nsIDO return docShell->GetEditable(outIsEditable); } // These are MIME types that are automatically parsed as "text/plain" // and thus we can edit them as plaintext // Note: in older versions, we attempted to convert the mimetype of -// the network channel for these and "text/xml" to "text/plain", +// the network channel for these and "text/xml" to "text/plain", // but further investigation reveals that strategy doesn't work const char* const gSupportedTextTypes[] = { "text/plain", "text/css", "text/rdf", "text/xsl", "text/javascript", // obsolete type "text/ecmascript", // obsolete type @@ -274,17 +274,17 @@ IsSupportedTextType(const char* aMIMETyp { if (strcmp(gSupportedTextTypes[i], aMIMEType) == 0) { return true; } i ++; } - + return false; } /*--------------------------------------------------------------------------- SetupEditorOnWindow nsIEditor setupEditorOnWindow (in nsIDOMWindow aWindow); @@ -341,34 +341,34 @@ nsEditingSession::SetupEditorOnWindow(ns } } } bool needHTMLController = false; const char *classString = "@mozilla.org/editor/htmleditor;1"; if (mEditorType.EqualsLiteral("textmail")) { - mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | - nsIPlaintextEditor::eEditorEnableWrapHackMask | + mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | + nsIPlaintextEditor::eEditorEnableWrapHackMask | nsIPlaintextEditor::eEditorMailMask; } else if (mEditorType.EqualsLiteral("text")) { - mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | + mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | nsIPlaintextEditor::eEditorEnableWrapHackMask; } else if (mEditorType.EqualsLiteral("htmlmail")) { if (mimeCType.EqualsLiteral("text/html")) { needHTMLController = true; mEditorFlags = nsIPlaintextEditor::eEditorMailMask; } else //set the flags back to textplain. - mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | + mEditorFlags = nsIPlaintextEditor::eEditorPlaintextMask | nsIPlaintextEditor::eEditorEnableWrapHackMask; } else // Defaulted to html { needHTMLController = true; } if (mInteractive) { @@ -385,20 +385,20 @@ nsEditingSession::SetupEditorOnWindow(ns NS_ENSURE_SUCCESS(rv, rv); if (mEditorStatus != eEditorCreationInProgress) { mStateMaintainer->NotifyDocumentCreated(); return NS_ERROR_FAILURE; } - // Create editor and do other things + // Create editor and do other things // only if we haven't found some error above, nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow); - NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); if (!mInteractive) { // Disable animation of images in this document: nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell(); NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); nsPresContext* presContext = presShell->GetPresContext(); NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); @@ -434,17 +434,17 @@ nsEditingSession::SetupEditorOnWindow(ns rv = editor->SetContentsMIMEType(mimeCType.get()); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIContentViewer> contentViewer; rv = docShell->GetContentViewer(getter_AddRefs(contentViewer)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(contentViewer, NS_ERROR_FAILURE); - nsCOMPtr<nsIDOMDocument> domDoc; + nsCOMPtr<nsIDOMDocument> domDoc; rv = contentViewer->GetDOMDocument(getter_AddRefs(domDoc)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(domDoc, NS_ERROR_FAILURE); // Set up as a doc state listener // Important! We must have this to broadcast the "obs_documentCreated" message rv = editor->AddDocumentStateListener(mStateMaintainer); NS_ENSURE_SUCCESS(rv, rv); @@ -516,17 +516,17 @@ nsEditingSession::TearDownEditorOnWindow { if (!mDoneSetup) { return NS_OK; } NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER); nsresult rv; - + // Kill any existing reload timer if (mLoadBlankDocTimer) { mLoadBlankDocTimer->Cancel(); mLoadBlankDocTimer = nullptr; } mDoneSetup = false; @@ -536,27 +536,27 @@ nsEditingSession::TearDownEditorOnWindow aWindow->GetDocument(getter_AddRefs(domDoc)); nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(domDoc); bool stopEditing = htmlDoc && htmlDoc->IsEditingOn(); if (stopEditing) RemoveWebProgressListener(aWindow); nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow); NS_ENSURE_STATE(docShell); - + nsCOMPtr<nsIEditor> editor; rv = docShell->GetEditor(getter_AddRefs(editor)); NS_ENSURE_SUCCESS(rv, rv); if (stopEditing) htmlDoc->TearingDownEditor(editor); if (mStateMaintainer && editor) { - // Null out the editor on the controllers first to prevent their weak + // Null out the editor on the controllers first to prevent their weak // references from pointing to a destroyed editor. SetEditorOnControllers(aWindow, nullptr); } // Null out the editor on the docShell to trigger PreDestroy which // needs to happen before document state listeners are removed below. docShell->SetEditor(nullptr); @@ -585,23 +585,23 @@ nsEditingSession::TearDownEditorOnWindow } /*--------------------------------------------------------------------------- GetEditorForFrame nsIEditor getEditorForFrame (in nsIDOMWindow aWindow); ----------------------------------------------------------------------------*/ -NS_IMETHODIMP +NS_IMETHODIMP nsEditingSession::GetEditorForWindow(nsIDOMWindow *aWindow, nsIEditor **outEditor) { nsCOMPtr<nsIDocShell> docShell = GetDocShellFromWindow(aWindow); NS_ENSURE_STATE(aWindow); - + return docShell->GetEditor(outEditor); } /*--------------------------------------------------------------------------- OnStateChange ----------------------------------------------------------------------------*/ @@ -785,17 +785,17 @@ nsEditingSession::OnProgressChange(nsIWe } /*--------------------------------------------------------------------------- OnLocationChange ----------------------------------------------------------------------------*/ NS_IMETHODIMP -nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, +nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *aURI, uint32_t aFlags) { nsCOMPtr<nsIDOMWindow> domWindow; nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIDOMDocument> domDoc; @@ -863,18 +863,18 @@ nsEditingSession::IsProgressForTargetDoc return editedWebProgress == aWebProgress; } /*--------------------------------------------------------------------------- GetEditorStatus - Called during GetCommandStateParams("obs_documentCreated"...) - to determine if editor was created and document + Called during GetCommandStateParams("obs_documentCreated"...) + to determine if editor was created and document was loaded successfully ----------------------------------------------------------------------------*/ NS_IMETHODIMP nsEditingSession::GetEditorStatus(uint32_t *aStatus) { NS_ENSURE_ARG_POINTER(aStatus); *aStatus = mEditorStatus; return NS_OK; @@ -882,36 +882,36 @@ nsEditingSession::GetEditorStatus(uint32 /*--------------------------------------------------------------------------- StartDocumentLoad Called on start of load in a single frame ----------------------------------------------------------------------------*/ nsresult -nsEditingSession::StartDocumentLoad(nsIWebProgress *aWebProgress, +nsEditingSession::StartDocumentLoad(nsIWebProgress *aWebProgress, bool aIsToBeMadeEditable) { #ifdef NOISY_DOC_LOADING printf("======= StartDocumentLoad ========\n"); #endif NS_ENSURE_ARG_POINTER(aWebProgress); - + // If we have an editor here, then we got a reload after making the editor. // We need to blow it away and make a new one at the end of the load. nsCOMPtr<nsIDOMWindow> domWindow; aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); if (domWindow) { nsIDocShell *docShell = GetDocShellFromWindow(domWindow); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); docShell->DetachEditorFromWindow(); } - + if (aIsToBeMadeEditable) mEditorStatus = eEditorCreationInProgress; return NS_OK; } /*--------------------------------------------------------------------------- @@ -920,37 +920,37 @@ nsEditingSession::StartDocumentLoad(nsIW Called on end of load in a single frame ----------------------------------------------------------------------------*/ nsresult nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus, bool aIsToBeMadeEditable) { NS_ENSURE_ARG_POINTER(aWebProgress); - + #ifdef NOISY_DOC_LOADING printf("======= EndDocumentLoad ========\n"); printf("with status %d, ", aStatus); nsCOMPtr<nsIURI> uri; nsXPIDLCString spec; if (NS_SUCCEEDED(aChannel->GetURI(getter_AddRefs(uri)))) { uri->GetSpec(spec); printf(" uri %s\n", spec.get()); } #endif // We want to call the base class EndDocumentLoad, // but avoid some of the stuff // that nsDocShell does (need to refactor). - + // OK, time to make an editor on this document nsCOMPtr<nsIDOMWindow> domWindow; aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); - - // Set the error state -- we will create an editor + + // Set the error state -- we will create an editor // anyway and load empty doc later if (aIsToBeMadeEditable) { if (aStatus == NS_ERROR_FILE_NOT_FOUND) mEditorStatus = eEditorErrorFileNotFound; } nsIDocShell *docShell = GetDocShellFromWindow(domWindow); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); // better error handling? @@ -964,17 +964,17 @@ nsEditingSession::EndDocumentLoad(nsIWeb nsresult rv = NS_OK; // did someone set the flag to make this shell editable? if (aIsToBeMadeEditable && mCanCreateEditor) { bool makeEditable; docShell->GetEditable(&makeEditable); - + if (makeEditable) { // To keep pre Gecko 1.9 behavior, setup editor always when // mMakeWholeDocumentEditable. bool needsSetup = false; if (mMakeWholeDocumentEditable) { needsSetup = true; } else { @@ -994,17 +994,17 @@ nsEditingSession::EndDocumentLoad(nsIWeb { // If we had an error, setup timer to load a blank page later if (mLoadBlankDocTimer) { // Must cancel previous timer? mLoadBlankDocTimer->Cancel(); mLoadBlankDocTimer = nullptr; } - + mLoadBlankDocTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); NS_ENSURE_SUCCESS(rv, rv); mEditorStatus = eEditorCreationInProgress; mLoadBlankDocTimer->InitWithFuncCallback( nsEditingSession::TimerCallback, static_cast<void*> (mDocShell.get()), 10, nsITimer::TYPE_ONE_SHOT); @@ -1058,25 +1058,25 @@ nsEditingSession::EndPageLoad(nsIWebProg printf("======= EndPageLoad ========\n"); printf(" with status %d, ", aStatus); nsCOMPtr<nsIURI> uri; nsXPIDLCString spec; if (NS_SUCCEEDED(aChannel->GetURI(getter_AddRefs(uri)))) { uri->GetSpec(spec); printf("uri %s\n", spec.get()); } - + nsAutoCString contentType; aChannel->GetContentType(contentType); if (!contentType.IsEmpty()) - printf(" flags = %d, status = %d, MIMETYPE = %s\n", + printf(" flags = %d, status = %d, MIMETYPE = %s\n", mEditorFlags, mEditorStatus, contentType.get()); #endif - // Set the error state -- we will create an editor anyway + // Set the error state -- we will create an editor anyway // and load empty doc later if (aStatus == NS_ERROR_FILE_NOT_FOUND) mEditorStatus = eEditorErrorFileNotFound; nsCOMPtr<nsIDOMWindow> domWindow; aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); nsIDocShell *docShell = GetDocShellFromWindow(domWindow); @@ -1118,26 +1118,26 @@ nsEditingSession::GetDocShellFromWindow( Set up this editing session for one or more editors ----------------------------------------------------------------------------*/ nsresult nsEditingSession::PrepareForEditing(nsIDOMWindow *aWindow) { if (mProgressListenerRegistered) return NS_OK; - + nsIDocShell *docShell = GetDocShellFromWindow(aWindow); - + // register callback nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell); NS_ENSURE_TRUE(webProgress, NS_ERROR_FAILURE); nsresult rv = webProgress->AddProgressListener(this, - (nsIWebProgress::NOTIFY_STATE_NETWORK | + (nsIWebProgress::NOTIFY_STATE_NETWORK | nsIWebProgress::NOTIFY_STATE_DOCUMENT | nsIWebProgress::NOTIFY_LOCATION)); mProgressListenerRegistered = NS_SUCCEEDED(rv); return rv; } @@ -1154,57 +1154,57 @@ nsEditingSession::SetupEditorCommandCont nsIDOMWindow *aWindow, nsISupports *aContext, uint32_t *aControllerId) { NS_ENSURE_ARG_POINTER(aControllerClassName); NS_ENSURE_ARG_POINTER(aWindow); NS_ENSURE_ARG_POINTER(aContext); NS_ENSURE_ARG_POINTER(aControllerId); - - nsCOMPtr<nsIControllers> controllers; + + nsCOMPtr<nsIControllers> controllers; nsresult rv = aWindow->GetControllers(getter_AddRefs(controllers)); NS_ENSURE_SUCCESS(rv, rv); // We only have to create each singleton controller once // We know this has happened once we have a controllerId value if (!*aControllerId) { nsCOMPtr<nsIController> controller; controller = do_CreateInstance(aControllerClassName, &rv); - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_SUCCESS(rv, rv); // We must insert at head of the list to be sure our // controller is found before other implementations // (e.g., not-implemented versions by browser) rv = controllers->InsertControllerAt(0, controller); - NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_SUCCESS(rv, rv); // Remember the ID for the controller rv = controllers->GetControllerId(controller, aControllerId); - NS_ENSURE_SUCCESS(rv, rv); - } + NS_ENSURE_SUCCESS(rv, rv); + } // Set the context return SetContextOnControllerById(controllers, aContext, *aControllerId); } /*--------------------------------------------------------------------------- SetEditorOnControllers Set the editor on the controller(s) for this window ----------------------------------------------------------------------------*/ NS_IMETHODIMP nsEditingSession::SetEditorOnControllers(nsIDOMWindow *aWindow, nsIEditor* aEditor) { NS_ENSURE_TRUE(aWindow, NS_ERROR_NULL_POINTER); - - nsCOMPtr<nsIControllers> controllers; + + nsCOMPtr<nsIControllers> controllers; nsresult rv = aWindow->GetControllers(getter_AddRefs(controllers)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupports> editorAsISupports = do_QueryInterface(aEditor); if (mBaseCommandControllerId) { rv = SetContextOnControllerById(controllers, editorAsISupports, mBaseCommandControllerId); @@ -1228,31 +1228,31 @@ nsEditingSession::SetEditorOnControllers nsresult nsEditingSession::SetContextOnControllerById(nsIControllers* aControllers, nsISupports* aContext, uint32_t aID) { NS_ENSURE_ARG_POINTER(aControllers); // aContext can be null (when destroying editor) - nsCOMPtr<nsIController> controller; + nsCOMPtr<nsIController> controller; aControllers->GetControllerById(aID, getter_AddRefs(controller)); - + // ok with nil controller nsCOMPtr<nsIControllerContext> editorController = do_QueryInterface(controller); NS_ENSURE_TRUE(editorController, NS_ERROR_FAILURE); return editorController->SetCommandContext(aContext); } void nsEditingSession::RemoveEditorControllers(nsIDOMWindow *aWindow) { - // Remove editor controllers from the aWindow, call when we're + // Remove editor controllers from the aWindow, call when we're // tearing down/detaching editor. nsCOMPtr<nsIControllers> controllers; if (aWindow) aWindow->GetControllers(getter_AddRefs(controllers)); if (controllers) {
--- a/editor/composer/nsEditingSession.h +++ b/editor/composer/nsEditingSession.h @@ -51,66 +51,66 @@ public: nsEditingSession(); // nsISupports NS_DECL_ISUPPORTS // nsIWebProgressListener NS_DECL_NSIWEBPROGRESSLISTENER - + // nsIEditingSession NS_DECL_NSIEDITINGSESSION protected: virtual ~nsEditingSession(); nsIDocShell * GetDocShellFromWindow(nsIDOMWindow *aWindow); - + nsresult SetupEditorCommandController(const char *aControllerClassName, nsIDOMWindow *aWindow, nsISupports *aContext, uint32_t *aControllerId); - nsresult SetContextOnControllerById(nsIControllers* aControllers, + nsresult SetContextOnControllerById(nsIControllers* aControllers, nsISupports* aContext, uint32_t aID); nsresult PrepareForEditing(nsIDOMWindow *aWindow); static void TimerCallback(nsITimer *aTimer, void *aClosure); nsCOMPtr<nsITimer> mLoadBlankDocTimer; - + // progress load stuff nsresult StartDocumentLoad(nsIWebProgress *aWebProgress, bool isToBeMadeEditable); - nsresult EndDocumentLoad(nsIWebProgress *aWebProgress, + nsresult EndDocumentLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus, bool isToBeMadeEditable); nsresult StartPageLoad(nsIChannel *aChannel); - nsresult EndPageLoad(nsIWebProgress *aWebProgress, + nsresult EndPageLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus); - + bool IsProgressForTargetDocument(nsIWebProgress *aWebProgress); void RemoveEditorControllers(nsIDOMWindow *aWindow); void RemoveWebProgressListener(nsIDOMWindow *aWindow); void RestoreAnimationMode(nsIDOMWindow *aWindow); void RemoveListenersAndControllers(nsIDOMWindow *aWindow, nsIEditor *aEditor); protected: bool mDoneSetup; // have we prepared for editing yet? // Used to prevent double creation of editor because nsIWebProgressListener - // receives a STATE_STOP notification before the STATE_START - // for our document, so we wait for the STATE_START, then STATE_STOP + // receives a STATE_STOP notification before the STATE_START + // for our document, so we wait for the STATE_START, then STATE_STOP // before creating an editor - bool mCanCreateEditor; + bool mCanCreateEditor; bool mInteractive; bool mMakeWholeDocumentEditable; bool mDisabledJSAndPlugins; // True if scripts were enabled before the editor turned scripts // off, otherwise false. @@ -123,19 +123,19 @@ protected: bool mProgressListenerRegistered; // The image animation mode before it was turned off. uint16_t mImageAnimationMode; // THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT // MORE THAN ONE EDITOR PER EDITING SESSION nsRefPtr<nsComposerCommandsUpdater> mStateMaintainer; - + // Save the editor type so we can create the editor after loading uri - nsCString mEditorType; + nsCString mEditorType; uint32_t mEditorFlags; uint32_t mEditorStatus; uint32_t mBaseCommandControllerId; uint32_t mDocStateControllerId; uint32_t mHTMLCommandControllerId; // Make sure the docshell we use is safe nsWeakPtr mDocShell;
--- a/editor/composer/nsEditorSpellCheck.cpp +++ b/editor/composer/nsEditorSpellCheck.cpp @@ -316,17 +316,17 @@ public: } return NS_OK; } private: nsCOMPtr<nsIEditorSpellCheckCallback> mCallback; }; -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::InitSpellChecker(nsIEditor* aEditor, bool aEnableSelectionChecking, nsIEditorSpellCheckCallback* aCallback) { NS_ENSURE_TRUE(aEditor, NS_ERROR_NULL_POINTER); mEditor = aEditor; nsresult rv; // We can spell check with any editor type @@ -403,131 +403,131 @@ nsEditorSpellCheck::InitSpellChecker(nsI NS_ENSURE_STATE(caller); rv = NS_DispatchToMainThread(caller); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::GetNextMisspelledWord(char16_t **aNextMisspelledWord) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); nsAutoString nextMisspelledWord; - + DeleteSuggestedWordList(); // Beware! This may flush notifications via synchronous // ScrollSelectionIntoView. nsresult rv = mSpellChecker->NextMisspelledWord(nextMisspelledWord, &mSuggestedWordList); *aNextMisspelledWord = ToNewUnicode(nextMisspelledWord); return rv; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::GetSuggestedWord(char16_t **aSuggestedWord) { nsAutoString word; if ( mSuggestedWordIndex < int32_t(mSuggestedWordList.Length())) { *aSuggestedWord = ToNewUnicode(mSuggestedWordList[mSuggestedWordIndex]); mSuggestedWordIndex++; } else { // A blank string signals that there are no more strings *aSuggestedWord = ToNewUnicode(EmptyString()); } return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::CheckCurrentWord(const char16_t *aSuggestedWord, bool *aIsMisspelled) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); DeleteSuggestedWordList(); return mSpellChecker->CheckWord(nsDependentString(aSuggestedWord), aIsMisspelled, &mSuggestedWordList); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::CheckCurrentWordNoSuggest(const char16_t *aSuggestedWord, bool *aIsMisspelled) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); return mSpellChecker->CheckWord(nsDependentString(aSuggestedWord), aIsMisspelled, nullptr); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::ReplaceWord(const char16_t *aMisspelledWord, const char16_t *aReplaceWord, bool allOccurrences) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); return mSpellChecker->Replace(nsDependentString(aMisspelledWord), nsDependentString(aReplaceWord), allOccurrences); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::IgnoreWordAllOccurrences(const char16_t *aWord) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); return mSpellChecker->IgnoreAll(nsDependentString(aWord)); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::GetPersonalDictionary() { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); // We can spell check with any editor type mDictionaryList.Clear(); mDictionaryIndex = 0; return mSpellChecker->GetPersonalDictionary(&mDictionaryList); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::GetPersonalDictionaryWord(char16_t **aDictionaryWord) { if ( mDictionaryIndex < int32_t( mDictionaryList.Length())) { *aDictionaryWord = ToNewUnicode(mDictionaryList[mDictionaryIndex]); mDictionaryIndex++; } else { // A blank string signals that there are no more strings *aDictionaryWord = ToNewUnicode(EmptyString()); } return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::AddWordToDictionary(const char16_t *aWord) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); return mSpellChecker->AddWordToPersonalDictionary(nsDependentString(aWord)); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::RemoveWordFromDictionary(const char16_t *aWord) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); return mSpellChecker->RemoveWordFromPersonalDictionary(nsDependentString(aWord)); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::GetDictionaryList(char16_t ***aDictionaryList, uint32_t *aCount) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(aDictionaryList && aCount, NS_ERROR_NULL_POINTER); *aDictionaryList = 0; *aCount = 0; @@ -568,25 +568,25 @@ nsEditorSpellCheck::GetDictionaryList(ch for (i = 0; i < *aCount; i++) { tmpPtr[i] = ToNewUnicode(dictList[i]); } return rv; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::GetCurrentDictionary(nsAString& aDictionary) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); return mSpellChecker->GetCurrentDictionary(aDictionary); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::SetCurrentDictionary(const nsAString& aDictionary) { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); nsRefPtr<nsEditorSpellCheck> kungFuDeathGrip = this; // The purpose of mUpdateDictionaryRunning is to avoid doing all of this if // UpdateCurrentDictionary's helper method DictionaryFetched, which calls us, @@ -647,39 +647,39 @@ nsEditorSpellCheck::CheckCurrentDictiona if (dictList.Length() > 0) { rv = SetCurrentDictionary(dictList[0]); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::UninitSpellChecker() { NS_ENSURE_TRUE(mSpellChecker, NS_ERROR_NOT_INITIALIZED); // Cleanup - kill the spell checker DeleteSuggestedWordList(); mDictionaryList.Clear(); mDictionaryIndex = 0; mSpellChecker = 0; return NS_OK; } /* void setFilter (in nsITextServicesFilter filter); */ -NS_IMETHODIMP +NS_IMETHODIMP nsEditorSpellCheck::SetFilter(nsITextServicesFilter *filter) { mTxtSrvFilter = filter; return NS_OK; } -nsresult +nsresult nsEditorSpellCheck::DeleteSuggestedWordList() { mSuggestedWordList.Clear(); mSuggestedWordIndex = 0; return NS_OK; } NS_IMETHODIMP @@ -793,17 +793,17 @@ nsEditorSpellCheck::DictionaryFetched(Di AppendUTF8toUTF16(utf8DictName, dictName); } } if (NS_SUCCEEDED(rv) && !dictName.IsEmpty()) { rv = SetCurrentDictionary(dictName); if (NS_FAILED(rv)) { // required dictionary was not available. Try to get a dictionary - // matching at least language part of dictName: + // matching at least language part of dictName: nsAutoString langCode; int32_t dashIdx = dictName.FindChar('-'); if (dashIdx != -1) { langCode.Assign(Substring(dictName, 0, dashIdx)); } else { langCode.Assign(dictName); }
--- a/editor/composer/nsIEditingSession.idl +++ b/editor/composer/nsIEditingSession.idl @@ -38,37 +38,37 @@ interface nsIEditingSession : nsISupport * embedder who should make the document * (or part of it) editable. * @param aInteractive if PR_FALSE turn off scripting and plugins */ void makeWindowEditable(in nsIDOMWindow window, in string aEditorType, in boolean doAfterUriLoad, in boolean aMakeWholeDocumentEditable, in boolean aInteractive); - + /** * Test whether a specific window has had its editable flag set; it may have an editor * now, or will get one after the uri load. - * + * * Use this, passing the content root window, to test if we've set up editing * for this content. */ boolean windowIsEditable(in nsIDOMWindow window); - + /** * Get the editor for this window. May return null */ - nsIEditor getEditorForWindow(in nsIDOMWindow window); + nsIEditor getEditorForWindow(in nsIDOMWindow window); - /** + /** * Setup editor and related support objects */ void setupEditorOnWindow(in nsIDOMWindow window); - /** + /** * Destroy editor and related support objects */ void tearDownEditorOnWindow(in nsIDOMWindow window); void setEditorOnControllers(in nsIDOMWindow aWindow, in nsIEditor aEditor); /**
--- a/editor/libeditor/InsertTextTxn.h +++ b/editor/libeditor/InsertTextTxn.h @@ -39,17 +39,17 @@ public: * @param aString the new text to insert * @param aPresShell used to get and set the selection */ InsertTextTxn(Text& aTextNode, uint32_t aOffset, const nsAString& aString, nsEditor& aEditor); NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InsertTextTxn, EditTxn) - + NS_DECL_EDITTXN NS_IMETHOD Merge(nsITransaction* aTransaction, bool* aDidMerge) override; /** Return the string data associated with this transaction */ void GetData(nsString& aResult); private:
--- a/editor/libeditor/PlaceholderTxn.cpp +++ b/editor/libeditor/PlaceholderTxn.cpp @@ -8,18 +8,18 @@ #include "IMETextTxn.h" #include "nsGkAtoms.h" #include "mozilla/dom/Selection.h" #include "nsQueryObject.h" using namespace mozilla; using namespace mozilla::dom; -PlaceholderTxn::PlaceholderTxn() : EditAggregateTxn(), - mAbsorb(true), +PlaceholderTxn::PlaceholderTxn() : EditAggregateTxn(), + mAbsorb(true), mForwarding(nullptr), mIMETextTxn(nullptr), mCommitted(false), mStartSel(nullptr), mEndSel(), mEditor(nullptr) { } @@ -67,47 +67,47 @@ NS_IMETHODIMP PlaceholderTxn::DoTransact return NS_OK; } NS_IMETHODIMP PlaceholderTxn::UndoTransaction(void) { // undo txns nsresult res = EditAggregateTxn::UndoTransaction(); NS_ENSURE_SUCCESS(res, res); - + NS_ENSURE_TRUE(mStartSel, NS_ERROR_NULL_POINTER); // now restore selection nsRefPtr<Selection> selection = mEditor->GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); return mStartSel->RestoreSelection(selection); } NS_IMETHODIMP PlaceholderTxn::RedoTransaction(void) { // redo txns nsresult res = EditAggregateTxn::RedoTransaction(); NS_ENSURE_SUCCESS(res, res); - + // now restore selection nsRefPtr<Selection> selection = mEditor->GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); return mEndSel.RestoreSelection(selection); } NS_IMETHODIMP PlaceholderTxn::Merge(nsITransaction *aTransaction, bool *aDidMerge) { NS_ENSURE_TRUE(aDidMerge && aTransaction, NS_ERROR_NULL_POINTER); // set out param default value *aDidMerge=false; - - if (mForwarding) + + if (mForwarding) { NS_NOTREACHED("tried to merge into a placeholder that was in forwarding mode!"); return NS_ERROR_FAILURE; } // check to see if aTransaction is one of the editor's // private transactions. If not, we want to avoid merging // the foreign transaction into our placeholder since we @@ -117,28 +117,28 @@ NS_IMETHODIMP PlaceholderTxn::Merge(nsIT NS_ENSURE_TRUE(pTxn, NS_OK); // it's foreign so just bail! EditTxn *editTxn = (EditTxn*)aTransaction; //XXX: hack, not safe! need nsIEditTransaction! // determine if this incoming txn is a placeholder txn nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryObject(editTxn); // we are absorbing all txn's if mAbsorb is lit. if (mAbsorb) - { + { nsRefPtr<IMETextTxn> otherTxn = do_QueryObject(aTransaction); if (otherTxn) { // special handling for IMETextTxn's: they need to merge with any previous // IMETextTxn in this placeholder, if possible. - if (!mIMETextTxn) + if (!mIMETextTxn) { // this is the first IME txn in the placeholder mIMETextTxn =otherTxn; AppendChild(editTxn); } - else + else { bool didMerge; mIMETextTxn->Merge(otherTxn, &didMerge); if (!didMerge) { // it wouldn't merge. Earlier IME txn is already committed and will // not absorb further IME txns. So just stack this one after it // and remember it as a candidate for further merges. @@ -148,26 +148,26 @@ NS_IMETHODIMP PlaceholderTxn::Merge(nsIT } } else if (!plcTxn) // see bug 171243: just drop incoming placeholders on the floor. { // their children will be swallowed by this preexisting one. AppendChild(editTxn); } *aDidMerge = true; // RememberEndingSelection(); -// efficiency hack: no need to remember selection here, as we haven't yet +// efficiency hack: no need to remember selection here, as we haven't yet // finished the initial batch and we know we will be told when the batch ends. // we can remeber the selection then. } else { // merge typing or IME or deletion transactions if the selection matches if (((mName.get() == nsGkAtoms::TypingTxnName) || (mName.get() == nsGkAtoms::IMETxnName) || - (mName.get() == nsGkAtoms::DeleteTxnName)) - && !mCommitted ) + (mName.get() == nsGkAtoms::DeleteTxnName)) + && !mCommitted ) { nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryObject(editTxn); if (plcTxn) { nsCOMPtr<nsIAtom> atom; plcTxn->GetTxnName(getter_AddRefs(atom)); if (atom && (atom == mName)) { // check if start selection of next placeholder matches @@ -224,29 +224,29 @@ NS_IMETHODIMP PlaceholderTxn::StartSelec } *aResult = mStartSel->IsEqual(aSelState); return NS_OK; } NS_IMETHODIMP PlaceholderTxn::EndPlaceHolderBatch() { mAbsorb = false; - - if (mForwarding) + + if (mForwarding) { nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryReferent(mForwarding); if (plcTxn) plcTxn->EndPlaceHolderBatch(); } - + // remember our selection state. return RememberEndingSelection(); } NS_IMETHODIMP PlaceholderTxn::ForwardEndBatchTo(nsIAbsorbingTransaction *aForwardingAddress) -{ +{ mForwarding = do_GetWeakReference(aForwardingAddress); return NS_OK; } NS_IMETHODIMP PlaceholderTxn::Commit() { mCommitted = true; return NS_OK;
--- a/editor/libeditor/PlaceholderTxn.h +++ b/editor/libeditor/PlaceholderTxn.h @@ -22,41 +22,41 @@ class IMETextTxn; } /** * An aggregate transaction that knows how to absorb all subsequent * transactions with the same name. This transaction does not "Do" anything. * But it absorbs other transactions via merge, and can undo/redo the * transactions it has absorbed. */ - -class PlaceholderTxn : public EditAggregateTxn, - public nsIAbsorbingTransaction, + +class PlaceholderTxn : public EditAggregateTxn, + public nsIAbsorbingTransaction, public nsSupportsWeakReference { public: - NS_DECL_ISUPPORTS_INHERITED - + NS_DECL_ISUPPORTS_INHERITED + PlaceholderTxn(); NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PlaceholderTxn, EditAggregateTxn) // ------------ EditAggregateTxn ----------------------- NS_DECL_EDITTXN NS_IMETHOD RedoTransaction() override; NS_IMETHOD Merge(nsITransaction *aTransaction, bool *aDidMerge) override; // ------------ nsIAbsorbingTransaction ----------------------- NS_IMETHOD Init(nsIAtom* aName, nsSelectionState* aSelState, nsEditor* aEditor) override; - + NS_IMETHOD GetTxnName(nsIAtom **aName) override; - + NS_IMETHOD StartSelectionEquals(nsSelectionState *aSelState, bool *aResult) override; NS_IMETHOD EndPlaceHolderBatch() override; NS_IMETHOD ForwardEndBatchTo(nsIAbsorbingTransaction *aForwardingAddress) override; NS_IMETHOD Commit() override; @@ -66,17 +66,17 @@ protected: virtual ~PlaceholderTxn(); /** the presentation shell, which we'll need to get the selection */ bool mAbsorb; // do we auto absorb any and all transaction? nsWeakPtr mForwarding; mozilla::dom::IMETextTxn *mIMETextTxn; // first IME txn in this placeholder - used for IME merging // non-owning for now - can't nsCOMPtr it due to broken transaction interfaces bool mCommitted; // do we stop auto absorbing any matching placeholder txns? - // these next two members store the state of the selection in a safe way. + // these next two members store the state of the selection in a safe way. // selection at the start of the txn is stored, as is the selection at the end. // This is so that UndoTransaction() and RedoTransaction() can restore the // selection properly. nsAutoPtr<nsSelectionState> mStartSel; // use a pointer because this is constructed before we exist nsSelectionState mEndSel; nsEditor* mEditor; /** the editor for this transaction */ };
--- a/editor/libeditor/SetDocTitleTxn.cpp +++ b/editor/libeditor/SetDocTitleTxn.cpp @@ -144,18 +144,18 @@ nsresult SetDocTitleTxn::SetDomTitle(con nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(textNode); NS_ENSURE_TRUE(newNode, NS_ERROR_FAILURE); if (newTitleNode) { // Not undoable: We will insert newTitleNode below nsCOMPtr<nsIDOMNode> resultNode; res = titleNode->AppendChild(newNode, getter_AddRefs(resultNode)); - } - else + } + else { // This is an undoable transaction res = editor->InsertNode(newNode, titleNode, 0); } NS_ENSURE_SUCCESS(res, res); } if (newTitleNode) @@ -170,13 +170,13 @@ NS_IMETHODIMP SetDocTitleTxn::GetTxnDesc { aString.AssignLiteral("SetDocTitleTxn: "); aString += mValue; return NS_OK; } NS_IMETHODIMP SetDocTitleTxn::GetIsTransient(bool *aIsTransient) { - NS_ENSURE_TRUE(aIsTransient, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(aIsTransient, NS_ERROR_NULL_POINTER); *aIsTransient = mIsTransient; return NS_OK; }
--- a/editor/libeditor/SetDocTitleTxn.h +++ b/editor/libeditor/SetDocTitleTxn.h @@ -35,17 +35,17 @@ public: NS_IMETHOD RedoTransaction() override; NS_IMETHOD GetIsTransient(bool *aIsTransient) override; protected: /** the editor that created this transaction */ nsIHTMLEditor* mEditor; - + /** The new title string */ nsString mValue; /** The previous title string to use for undo */ nsString mUndoValue; /** Set true if we dont' really change the title during Do() */ bool mIsTransient;
--- a/editor/libeditor/TextEditorTest.cpp +++ b/editor/libeditor/TextEditorTest.cpp @@ -44,33 +44,33 @@ void TextEditorTest::Run(nsIEditor *aEdi mTextEditor = do_QueryInterface(aEditor); mEditor = do_QueryInterface(aEditor); RunUnitTest(outNumTests, outNumTestsFailed); } nsresult TextEditorTest::RunUnitTest(int32_t *outNumTests, int32_t *outNumTestsFailed) { nsresult result; - + NS_ENSURE_TRUE(outNumTests && outNumTestsFailed, NS_ERROR_NULL_POINTER); - + *outNumTests = 0; *outNumTestsFailed = 0; - + result = InitDoc(); TEST_RESULT(result); // shouldn't we just bail on error here? - + // insert some simple text result = mTextEditor->InsertText(NS_LITERAL_STRING("1234567890abcdefghij1234567890")); TEST_RESULT(result); (*outNumTests)++; if (NS_FAILED(result)) ++(*outNumTestsFailed); - + // insert some more text result = mTextEditor->InsertText(NS_LITERAL_STRING("Moreover, I am cognizant of the interrelatedness of all communities and states. I cannot sit idly by in Atlanta and not be concerned about what happens in Birmingham. Injustice anywhere is a threat to justice everywhere")); TEST_RESULT(result); (*outNumTests)++; if (NS_FAILED(result)) ++(*outNumTestsFailed); result = TestInsertBreak(); @@ -118,17 +118,17 @@ nsresult TextEditorTest::TestInsertBreak TEST_RESULT(result); mEditor->DebugDumpContent(); // insert a second break adjacent to the first printf("inserting a second break\n"); result = mTextEditor->InsertLineBreak(); TEST_RESULT(result); mEditor->DebugDumpContent(); - + return result; } nsresult TextEditorTest::TestTextProperties() { nsCOMPtr<nsIDOMDocument>doc; nsresult result = mEditor->GetDocument(getter_AddRefs(doc)); TEST_RESULT(result);
--- a/editor/libeditor/TypeInState.cpp +++ b/editor/libeditor/TypeInState.cpp @@ -22,31 +22,31 @@ class nsIAtom; class nsIDOMDocument; using namespace mozilla; using namespace mozilla::dom; /******************************************************************** - * XPCOM cruft + * XPCOM cruft *******************************************************************/ NS_IMPL_CYCLE_COLLECTION(TypeInState, mLastSelectionContainer) NS_IMPL_CYCLE_COLLECTING_ADDREF(TypeInState) NS_IMPL_CYCLE_COLLECTING_RELEASE(TypeInState) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TypeInState) NS_INTERFACE_MAP_ENTRY(nsISelectionListener) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END /******************************************************************** * public methods *******************************************************************/ - + TypeInState::TypeInState() : mSetArray() ,mClearedArray() ,mRelativeFontSize(0) ,mLastSelectionOffset(0) { Reset(); } @@ -58,17 +58,17 @@ TypeInState::~TypeInState() Reset(); } nsresult TypeInState::UpdateSelState(Selection* aSelection) { NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER); - + if (!aSelection->Collapsed()) { return NS_OK; } return nsEditor::GetStartNodeAndOffset(aSelection, getter_AddRefs(mLastSelectionContainer), &mLastSelectionOffset); } @@ -109,17 +109,17 @@ NS_IMETHODIMP TypeInState::NotifySelecti } else { mLastSelectionContainer = nullptr; mLastSelectionOffset = 0; } } - Reset(); + Reset(); return NS_OK; } void TypeInState::Reset() { for(uint32_t i = 0, n = mClearedArray.Length(); i < n; i++) { delete mClearedArray[i]; } @@ -184,17 +184,17 @@ TypeInState::ClearProp(nsIAtom* aProp, c // add it to the list of cleared properties mClearedArray.AppendElement(item); } /*************************************************************************** * TakeClearProperty: hands back next property item on the clear list. * caller assumes ownership of PropItem and must delete it. - */ + */ PropItem* TypeInState::TakeClearProperty() { uint32_t count = mClearedArray.Length(); if (!count) { return nullptr; } @@ -202,17 +202,17 @@ TypeInState::TakeClearProperty() PropItem* propItem = mClearedArray[count]; mClearedArray.RemoveElementAt(count); return propItem; } /*************************************************************************** * TakeSetProperty: hands back next poroperty item on the set list. * caller assumes ownership of PropItem and must delete it. - */ + */ PropItem* TypeInState::TakeSetProperty() { uint32_t count = mSetArray.Length(); if (!count) { return nullptr; } count--; // indices are zero based @@ -261,17 +261,17 @@ TypeInState::GetTypingState(bool &isSet, } } /******************************************************************** * protected methods *******************************************************************/ - + void TypeInState::RemovePropFromSetList(nsIAtom* aProp, const nsAString& aAttr) { int32_t index; if (!aProp) { // clear _all_ props for(uint32_t i = 0, n = mSetArray.Length(); i < n; i++) { @@ -349,45 +349,45 @@ bool TypeInState::IsPropCleared(nsIAtom* { // special case for all props cleared outIndex = -1; return true; } return false; } -bool TypeInState::FindPropInList(nsIAtom *aProp, +bool TypeInState::FindPropInList(nsIAtom *aProp, const nsAString &aAttr, nsAString *outValue, nsTArray<PropItem*> &aList, int32_t &outIndex) { // linear search. list should be short. uint32_t i, count = aList.Length(); for (i=0; i<count; i++) { PropItem *item = aList[i]; if ( (item->tag == aProp) && - (item->attr == aAttr) ) + (item->attr == aAttr) ) { if (outValue) *outValue = item->value; outIndex = i; return true; } } return false; } /******************************************************************** * PropItem: helper struct for TypeInState *******************************************************************/ -PropItem::PropItem() : +PropItem::PropItem() : tag(nullptr) ,attr() ,value() { MOZ_COUNT_CTOR(PropItem); } PropItem::PropItem(nsIAtom *aTag, const nsAString &aAttr, const nsAString &aValue) :
--- a/editor/libeditor/TypeInState.h +++ b/editor/libeditor/TypeInState.h @@ -22,17 +22,17 @@ class Selection; } } struct PropItem { nsIAtom *tag; nsString attr; nsString value; - + PropItem(); PropItem(nsIAtom *aTag, const nsAString &aAttr, const nsAString &aValue); ~PropItem(); }; class TypeInState : public nsISelectionListener { public: @@ -47,17 +47,17 @@ public: // nsISelectionListener NS_DECL_NSISELECTIONLISTENER void SetProp(nsIAtom* aProp, const nsAString& aAttr, const nsAString& aValue); void ClearAllProps(); void ClearProp(nsIAtom* aProp, const nsAString& aAttr); - + //************************************************************************** // TakeClearProperty: hands back next property item on the clear list. // caller assumes ownership of PropItem and must delete it. PropItem* TakeClearProperty(); //************************************************************************** // TakeSetProperty: hands back next property item on the set list. // caller assumes ownership of PropItem and must delete it. @@ -84,16 +84,16 @@ protected: bool IsPropCleared(nsIAtom* aProp, const nsAString& aAttr); bool IsPropCleared(nsIAtom* aProp, const nsAString& aAttr, int32_t& outIndex); nsTArray<PropItem*> mSetArray; nsTArray<PropItem*> mClearedArray; int32_t mRelativeFontSize; nsCOMPtr<nsIDOMNode> mLastSelectionContainer; int32_t mLastSelectionOffset; - + friend class nsHTMLEditRules; }; #endif // TypeInState_h__
--- a/editor/libeditor/nsEditRules.h +++ b/editor/libeditor/nsEditRules.h @@ -21,32 +21,32 @@ class Selection; /*************************************************************************** * base for an object to encapsulate any additional info needed to be passed * to rules system by the editor */ class nsRulesInfo { public: - + explicit nsRulesInfo(EditAction aAction) : action(aAction) {} virtual ~nsRulesInfo() {} - + EditAction action; }; /*************************************************************************** * Interface of editing rules. - * + * */ class nsIEditRules : public nsISupports { public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IEDITRULES_IID) - + //Interfaces for addref and release and queryinterface //NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsIEditRules NS_IMETHOD Init(nsPlaintextEditor *aEditor)=0; NS_IMETHOD SetInitialValue(const nsAString& aValue) = 0; NS_IMETHOD DetachEditor()=0; NS_IMETHOD BeforeEdit(EditAction action, nsIEditor::EDirection aDirection) = 0;
--- a/editor/libeditor/nsEditor.cpp +++ b/editor/libeditor/nsEditor.cpp @@ -230,17 +230,17 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsI mSelConWeak = do_GetWeakReference(aSelCon); // weak reference to selectioncontroller selCon = aSelCon; } else { nsCOMPtr<nsIPresShell> presShell = GetPresShell(); selCon = do_QueryInterface(presShell); } NS_ASSERTION(selCon, "Selection controller should be available at this point"); - //set up root element if we are passed one. + //set up root element if we are passed one. if (aRoot) mRootElement = do_QueryInterface(aRoot); mUpdateCount=0; /* initialize IME stuff */ mIMETextNode = nullptr; mIMETextOffset = 0; @@ -542,17 +542,17 @@ nsEditor::GetDocument() already_AddRefed<nsIDOMDocument> nsEditor::GetDOMDocument() { NS_PRECONDITION(mDocWeak, "bad state, mDocWeak weak pointer not initialized"); nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak); return doc.forget(); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::GetDocument(nsIDOMDocument **aDoc) { *aDoc = GetDOMDocument().take(); return *aDoc ? NS_OK : NS_ERROR_NOT_INITIALIZED; } already_AddRefed<nsIPresShell> nsEditor::GetPresShell() @@ -753,17 +753,17 @@ nsEditor::GetNumberOfRedoItems(int32_t* *aNumItems = 0; return mTxnMgr ? mTxnMgr->GetNumberOfRedoItems(aNumItems) : NS_OK; } NS_IMETHODIMP nsEditor::GetTransactionManager(nsITransactionManager* *aTxnManager) { NS_ENSURE_ARG_POINTER(aTxnManager); - + *aTxnManager = nullptr; NS_ENSURE_TRUE(mTxnMgr, NS_ERROR_FAILURE); NS_ADDREF(*aTxnManager = mTxnMgr); return NS_OK; } NS_IMETHODIMP @@ -771,17 +771,17 @@ nsEditor::SetTransactionManager(nsITrans { NS_ENSURE_TRUE(aTxnManager, NS_ERROR_FAILURE); // nsITransactionManager is builtinclass, so this is safe mTxnMgr = static_cast<nsTransactionManager*>(aTxnManager); return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::Undo(uint32_t aCount) { ForceCompositionEnd(); bool hasTxnMgr, hasTransaction = false; CanUndo(&hasTxnMgr, &hasTransaction); NS_ENSURE_TRUE(hasTransaction, NS_OK); @@ -812,17 +812,17 @@ NS_IMETHODIMP nsEditor::CanUndo(bool *aI *aCanUndo = !!numTxns; } else { *aCanUndo = false; } return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::Redo(uint32_t aCount) { bool hasTxnMgr, hasTransaction = false; CanRedo(&hasTxnMgr, &hasTransaction); NS_ENSURE_TRUE(hasTransaction, NS_OK); nsAutoRules beginRulesSniffing(this, EditAction::redo, nsIEditor::eNone); @@ -852,29 +852,29 @@ NS_IMETHODIMP nsEditor::CanRedo(bool *aI *aCanRedo = !!numTxns; } else { *aCanRedo = false; } return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::BeginTransaction() { BeginUpdateViewBatch(); if (mTxnMgr) { mTxnMgr->BeginBatch(nullptr); } return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::EndTransaction() { if (mTxnMgr) { mTxnMgr->EndBatch(false); } EndUpdateViewBatch(); @@ -884,17 +884,17 @@ nsEditor::EndTransaction() // These two routines are similar to the above, but do not use // the transaction managers batching feature. Instead we use // a placeholder transaction to wrap up any further transaction // while the batch is open. The advantage of this is that // placeholder transactions can later merge, if needed. Merging // is unavailable between transaction manager batches. -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::BeginPlaceHolderTransaction(nsIAtom *aName) { NS_PRECONDITION(mPlaceHolderBatch >= 0, "negative placeholder batch count!"); if (!mPlaceHolderBatch) { NotifyEditorObservers(eNotifyEditorObserversOfBefore); // time to turn on the batch BeginUpdateViewBatch(); @@ -906,17 +906,17 @@ nsEditor::BeginPlaceHolderTransaction(ns mSelState->SaveSelection(selection); } } mPlaceHolderBatch++; return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::EndPlaceHolderTransaction() { NS_PRECONDITION(mPlaceHolderBatch > 0, "zero or negative placeholder batch count when ending batch!"); if (mPlaceHolderBatch == 1) { nsRefPtr<Selection> selection = GetSelection(); // By making the assumption that no reflow happens during the calls @@ -949,70 +949,70 @@ nsEditor::EndPlaceHolderTransaction() // cached for frame offset are Not available now if (selection) { selection->SetCanCacheFrameOffset(false); } if (mSelState) { - // we saved the selection state, but never got to hand it to placeholder + // 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. delete mSelState; mSelState = nullptr; } if (mPlaceHolderTxn) // we might have never made a placeholder if no action took place { nsCOMPtr<nsIAbsorbingTransaction> plcTxn = do_QueryReferent(mPlaceHolderTxn); - if (plcTxn) + if (plcTxn) { plcTxn->EndPlaceHolderBatch(); } - else + else { // in the future we will check to make sure undo is off here, // since that is the only known case where the placeholdertxn would disappear on us. // For now just removing the assert. } // notify editor observers of action but if composing, it's done by // compositionchange event handler. if (!mComposition) { NotifyEditorObservers(eNotifyEditorObserversOfEnd); } } else { NotifyEditorObservers(eNotifyEditorObserversOfCancel); } } mPlaceHolderBatch--; - + return NS_OK; } NS_IMETHODIMP nsEditor::ShouldTxnSetSelection(bool *aResult) { NS_ENSURE_TRUE(aResult, NS_ERROR_NULL_POINTER); *aResult = mShouldTxnSetSelection; return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::SetShouldTxnSetSelection(bool aShould) { mShouldTxnSetSelection = aShould; return NS_OK; } NS_IMETHODIMP nsEditor::GetDocumentIsEmpty(bool *aDocumentIsEmpty) { *aDocumentIsEmpty = true; dom::Element* root = GetRoot(); - NS_ENSURE_TRUE(root, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(root, NS_ERROR_NULL_POINTER); *aDocumentIsEmpty = !root->HasChildren(); return NS_OK; } // XXX: the rule system should tell us which node to select all on (ie, the root, or the body) NS_IMETHODIMP nsEditor::SelectAll() @@ -1027,21 +1027,21 @@ NS_IMETHODIMP nsEditor::SelectAll() NS_IMETHODIMP nsEditor::BeginningOfDocument() { if (!mDocWeak) { return NS_ERROR_NOT_INITIALIZED; } // get the selection nsRefPtr<Selection> selection = GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NOT_INITIALIZED); - - // get the root element + + // get the root element dom::Element* rootElement = GetRoot(); - NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER); - + NS_ENSURE_TRUE(rootElement, NS_ERROR_NULL_POINTER); + // find first editable thingy nsCOMPtr<nsINode> firstNode = GetFirstEditableNode(rootElement); if (!firstNode) { // just the root node, set selection to inside the root return selection->CollapseNative(rootElement, 0); } if (firstNode->NodeType() == nsIDOMNode::TEXT_NODE) { @@ -1056,37 +1056,37 @@ NS_IMETHODIMP nsEditor::BeginningOfDocum } int32_t offsetInParent = parent->IndexOf(firstNode); return selection->CollapseNative(parent, offsetInParent); } NS_IMETHODIMP nsEditor::EndOfDocument() -{ +{ NS_ENSURE_TRUE(mDocWeak, NS_ERROR_NOT_INITIALIZED); - // get selection - nsRefPtr<Selection> selection = GetSelection(); - NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); - - // get the root element + // get selection + nsRefPtr<Selection> selection = GetSelection(); + NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); + + // get the root element nsINode* node = GetRoot(); - NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER); nsINode* child = node->GetLastChild(); while (child && IsContainer(child->AsDOMNode())) { node = child; child = node->GetLastChild(); } uint32_t length = node->Length(); return selection->CollapseNative(node, int32_t(length)); -} - +} + NS_IMETHODIMP nsEditor::GetDocumentModified(bool *outDocModified) { NS_ENSURE_TRUE(outDocModified, NS_ERROR_NULL_POINTER); int32_t modCount = 0; GetModificationCount(&modCount); @@ -1112,84 +1112,84 @@ nsEditor::SetDocumentCharacterSet(const doc->SetDocumentCharacterSet(characterSet); return NS_OK; } NS_IMETHODIMP nsEditor::Cut() { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::CanCut(bool *aCanCut) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::Copy() { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::CanCopy(bool *aCanCut) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::CanDelete(bool *aCanDelete) { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::Paste(int32_t aSelectionType) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::PasteTransferable(nsITransferable *aTransferable) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::CanPaste(int32_t aSelectionType, bool *aCanPaste) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::CanPasteTransferable(nsITransferable *aTransferable, bool *aCanPaste) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsEditor::SetAttribute(nsIDOMElement* aElement, const nsAString& aAttribute, const nsAString& aValue) { nsCOMPtr<Element> element = do_QueryInterface(aElement); NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER); nsCOMPtr<nsIAtom> attribute = do_GetAtom(aAttribute); nsRefPtr<ChangeAttributeTxn> txn = CreateTxnForSetAttribute(*element, *attribute, aValue); return DoTransaction(txn); } -NS_IMETHODIMP -nsEditor::GetAttributeValue(nsIDOMElement *aElement, - const nsAString & aAttribute, - nsAString & aResultValue, +NS_IMETHODIMP +nsEditor::GetAttributeValue(nsIDOMElement *aElement, + const nsAString & aAttribute, + nsAString & aResultValue, bool *aResultIsSet) { NS_ENSURE_TRUE(aResultIsSet, NS_ERROR_NULL_POINTER); *aResultIsSet = false; if (!aElement) { return NS_OK; } nsAutoString value; @@ -1222,17 +1222,17 @@ nsEditor::OutputsMozDirty() // (eEditorMailMask), but false for webpages. return !(mFlags & nsIPlaintextEditor::eEditorAllowInteraction) || (mFlags & nsIPlaintextEditor::eEditorMailMask); } NS_IMETHODIMP nsEditor::MarkNodeDirty(nsIDOMNode* aNode) -{ +{ // Mark the node dirty, but not for webpages (bug 599983) if (!OutputsMozDirty()) { return NS_OK; } nsCOMPtr<dom::Element> element = do_QueryInterface(aNode); if (element) { element->SetAttr(kNameSpaceID_None, nsGkAtoms::mozdirty, EmptyString(), false); @@ -1535,19 +1535,19 @@ nsEditor::DeleteNode(nsINode* aNode) listener->DidDeleteNode(aNode->AsDOMNode(), res); } NS_ENSURE_SUCCESS(res, res); return NS_OK; } /////////////////////////////////////////////////////////////////////////// -// ReplaceContainer: replace inNode with a new node (outNode) which is contructed +// ReplaceContainer: replace inNode with a new node (outNode) which is contructed // to be of type aNodeType. Put inNodes children into outNode. -// Callers responsibility to make sure inNode's children can +// Callers responsibility to make sure inNode's children can // go in outNode. already_AddRefed<Element> nsEditor::ReplaceContainer(Element* aOldContainer, nsIAtom* aNodeType, nsIAtom* aAttribute, const nsAString* aValue, ECloneAttributes aCloneAttributes) { @@ -1566,17 +1566,17 @@ nsEditor::ReplaceContainer(Element* aOld nsresult res; if (aAttribute && aValue && aAttribute != nsGkAtoms::_empty) { res = ret->SetAttr(kNameSpaceID_None, aAttribute, *aValue, true); NS_ENSURE_SUCCESS(res, nullptr); } if (aCloneAttributes == eCloneAttributes) { CloneAttributes(ret, aOldContainer); } - + // notify our internal selection state listener // (Note: A nsAutoSelectionReset object must be created // before calling this to initialize mRangeUpdater) AutoReplaceContainerSelNotify selStateNotify(mRangeUpdater, aOldContainer, ret); { nsAutoTxnsConserveSelection conserveSelection(this); while (aOldContainer->HasChildren()) { @@ -1588,17 +1588,17 @@ nsEditor::ReplaceContainer(Element* aOld res = InsertNode(*child, *ret, -1); NS_ENSURE_SUCCESS(res, nullptr); } } // insert new container into tree res = InsertNode(*ret, *parent, offset); NS_ENSURE_SUCCESS(res, nullptr); - + // delete old container res = DeleteNode(aOldContainer); NS_ENSURE_SUCCESS(res, nullptr); return ret.forget(); } /////////////////////////////////////////////////////////////////////////////// @@ -1728,17 +1728,17 @@ nsEditor::MoveNode(nsIContent* aNode, ns } NS_IMETHODIMP nsEditor::AddEditorObserver(nsIEditorObserver *aObserver) { // we don't keep ownership of the observers. They must // remove themselves as observers before they are destroyed. - + NS_ENSURE_TRUE(aObserver, NS_ERROR_NULL_POINTER); // Make sure the listener isn't already on the list if (!mEditorObservers.Contains(aObserver)) { mEditorObservers.AppendElement(*aObserver); } return NS_OK; @@ -1959,39 +1959,39 @@ nsEditor::DebugUnitTests(int32_t *outNum { #ifdef DEBUG NS_NOTREACHED("This should never get called. Overridden by subclasses"); #endif return NS_OK; } -bool +bool nsEditor::ArePreservingSelection() { return !(mSavedSel.IsEmpty()); } void nsEditor::PreserveSelectionAcrossActions(Selection* aSel) { mSavedSel.SaveSelection(aSel); mRangeUpdater.RegisterSelectionState(mSavedSel); } -nsresult +nsresult nsEditor::RestorePreservedSelection(Selection* aSel) { if (mSavedSel.IsEmpty()) return NS_ERROR_FAILURE; mSavedSel.RestoreSelection(aSel); StopPreservingSelection(); return NS_OK; } -void +void nsEditor::StopPreservingSelection() { mRangeUpdater.DropSelectionState(mSavedSel); mSavedSel.MakeEmpty(); } void nsEditor::EnsureComposition(mozilla::WidgetGUIEvent* aEvent) @@ -2456,31 +2456,31 @@ nsEditor::GetFirstEditableNode(nsINode* NS_IMETHODIMP nsEditor::NotifyDocumentListeners(TDocumentListenerNotification aNotificationType) { if (!mDocStateListeners.Length()) { // Maybe there just aren't any. return NS_OK; } - + nsTArray<OwningNonNull<nsIDocumentStateListener>> listeners(mDocStateListeners); nsresult rv = NS_OK; switch (aNotificationType) { case eDocumentCreated: for (auto& listener : listeners) { rv = listener->NotifyDocumentCreated(); if (NS_FAILED(rv)) break; } break; - + case eDocumentToBeDestroyed: for (auto& listener : listeners) { rv = listener->NotifyDocumentWillBeDestroyed(); if (NS_FAILED(rv)) break; } break; @@ -2497,17 +2497,17 @@ nsEditor::NotifyDocumentListeners(TDocum for (auto& listener : listeners) { rv = listener->NotifyDocumentStateChanged(mDocDirtyState); if (NS_FAILED(rv)) break; } } break; - + default: NS_NOTREACHED("Unknown notification"); } return rv; } @@ -2927,20 +2927,20 @@ nsEditor::GetNodeLocation(nsINode* aChil *aOffset = parent->IndexOf(aChild); MOZ_ASSERT(*aOffset != -1); } else { *aOffset = -1; } return parent; } -// returns the number of things inside aNode. +// returns the number of things inside aNode. // If aNode is text, returns number of characters. If not, returns number of children nodes. nsresult -nsEditor::GetLengthOfDOMNode(nsIDOMNode *aNode, uint32_t &aCount) +nsEditor::GetLengthOfDOMNode(nsIDOMNode *aNode, uint32_t &aCount) { aCount = 0; nsCOMPtr<nsINode> node = do_QueryInterface(aNode); NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER); aCount = node->Length(); return NS_OK; } @@ -3014,17 +3014,17 @@ nsEditor::GetNextNode(nsINode* aParentNo if (!aEditableNode || IsEditable(resultNode)) { return resultNode; } // restart the search from the non-editable node we just found return GetNextNode(resultNode, aEditableNode, aNoBlockCrossing); } - + // unless there isn't one, in which case we are at the end of the node // and want the next one. if (aNoBlockCrossing && IsBlockNode(aParentNode)) { // don't cross out of parent block return nullptr; } return GetNextNode(aParentNode, aEditableNode, aNoBlockCrossing); @@ -3040,17 +3040,17 @@ nsEditor::GetPriorNode(nsINode* aCurrent if (!IsDescendantOfEditorRoot(aCurrentNode)) { return nullptr; } return FindNode(aCurrentNode, false, aEditableNode, aNoBlockCrossing); } nsIContent* -nsEditor::FindNextLeafNode(nsINode *aCurrentNode, +nsEditor::FindNextLeafNode(nsINode *aCurrentNode, bool aGoForward, bool bNoBlockCrossing) { // called only by GetPriorNode so we don't need to check params. NS_PRECONDITION(IsDescendantOfEditorRoot(aCurrentNode) && !IsEditorRoot(aCurrentNode), "Bogus arguments"); @@ -3063,17 +3063,17 @@ nsEditor::FindNextLeafNode(nsINode *aCu if (sibling) { if (bNoBlockCrossing && IsBlockNode(sibling)) { // don't look inside prevsib, since it is a block return sibling; } nsIContent *leaf = aGoForward ? GetLeftmostChild(sibling, bNoBlockCrossing) : GetRightmostChild(sibling, bNoBlockCrossing); - if (!leaf) { + if (!leaf) { return sibling; } return leaf; } nsINode *parent = cur->GetParentNode(); if (!parent) { @@ -3121,17 +3121,17 @@ nsEditor::FindNode(nsINode *aCurrentNode // prevent us from accidentally editing browser content // when the editor is in a text widget. return nullptr; } nsCOMPtr<nsIContent> candidate = FindNextLeafNode(aCurrentNode, aGoForward, bNoBlockCrossing); - + if (!candidate) { return nullptr; } if (!aEditableNode || IsEditable(candidate)) { return candidate; } @@ -3220,45 +3220,45 @@ nsEditor::CanContainTag(nsINode& aParent switch (aParent.NodeType()) { case nsIDOMNode::ELEMENT_NODE: case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: return TagCanContainTag(*aParent.NodeInfo()->NameAtom(), aChildTag); } return false; } -bool +bool nsEditor::TagCanContain(nsIAtom& aParentTag, nsIContent& aChild) { switch (aChild.NodeType()) { case nsIDOMNode::TEXT_NODE: case nsIDOMNode::ELEMENT_NODE: case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: return TagCanContainTag(aParentTag, *aChild.NodeInfo()->NameAtom()); } return false; } -bool +bool nsEditor::TagCanContainTag(nsIAtom& aParentTag, nsIAtom& aChildTag) { return true; } bool nsEditor::IsRoot(nsIDOMNode* inNode) { NS_ENSURE_TRUE(inNode, false); nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(GetRoot()); return inNode == rootNode; } -bool +bool nsEditor::IsRoot(nsINode* inNode) { NS_ENSURE_TRUE(inNode, false); nsCOMPtr<nsINode> rootNode = GetRoot(); return inNode == rootNode; } @@ -3266,17 +3266,17 @@ nsEditor::IsRoot(nsINode* inNode) bool nsEditor::IsEditorRoot(nsINode* aNode) { NS_ENSURE_TRUE(aNode, false); nsCOMPtr<nsINode> rootNode = GetEditorRoot(); return aNode == rootNode; } -bool +bool nsEditor::IsDescendantOfRoot(nsIDOMNode* inNode) { nsCOMPtr<nsINode> node = do_QueryInterface(inNode); return IsDescendantOfRoot(node); } bool nsEditor::IsDescendantOfRoot(nsINode* inNode) @@ -3370,17 +3370,17 @@ IsElementVisible(dom::Element* aElement) nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement, nullptr, nullptr); if (styleContext) { return styleContext->StyleDisplay()->mDisplay != NS_STYLE_DISPLAY_NONE; } return false; } -bool +bool nsEditor::IsEditable(nsIDOMNode *aNode) { nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); return IsEditable(content); } bool nsEditor::IsEditable(nsINode* aNode) @@ -3475,54 +3475,54 @@ NS_IMETHODIMP nsEditor::ResetModificatio /////////////////////////////////////////////////////////////////////////// // GetTag: digs out the atom for the tag of this node // nsIAtom * nsEditor::GetTag(nsIDOMNode *aNode) { nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); - if (!content) + if (!content) { NS_ASSERTION(aNode, "null node passed to nsEditor::GetTag()"); return nullptr; } - + return content->NodeInfo()->NameAtom(); } /////////////////////////////////////////////////////////////////////////// // GetTagString: digs out string for the tag of this node -// -nsresult +// +nsresult nsEditor::GetTagString(nsIDOMNode *aNode, nsAString& outString) { - if (!aNode) + if (!aNode) { NS_NOTREACHED("null node passed to nsEditor::GetTagString()"); return NS_ERROR_NULL_POINTER; } - + nsIAtom *atom = GetTag(aNode); if (!atom) { return NS_ERROR_FAILURE; } atom->ToString(outString); return NS_OK; } /////////////////////////////////////////////////////////////////////////// // NodesSameType: do these nodes have the same tag? -// -bool +// +bool nsEditor::NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2) { if (!aNode1 || !aNode2) { NS_NOTREACHED("null node passed to nsEditor::NodesSameType()"); return false; } nsCOMPtr<nsIContent> content1 = do_QueryInterface(aNode1); @@ -3541,45 +3541,45 @@ nsEditor::AreNodesSameType(nsIContent* a MOZ_ASSERT(aNode1); MOZ_ASSERT(aNode2); return aNode1->NodeInfo()->NameAtom() == aNode2->NodeInfo()->NameAtom(); } /////////////////////////////////////////////////////////////////////////// // IsTextNode: true if node of dom type text -// +// bool nsEditor::IsTextNode(nsIDOMNode *aNode) { if (!aNode) { NS_NOTREACHED("null node passed to IsTextNode()"); return false; } - + uint16_t nodeType; aNode->GetNodeType(&nodeType); return (nodeType == nsIDOMNode::TEXT_NODE); } bool nsEditor::IsTextNode(nsINode *aNode) { return aNode->NodeType() == nsIDOMNode::TEXT_NODE; } /////////////////////////////////////////////////////////////////////////// // GetChildAt: returns the node at this position index in the parent // -nsCOMPtr<nsIDOMNode> +nsCOMPtr<nsIDOMNode> nsEditor::GetChildAt(nsIDOMNode *aParent, int32_t aOffset) { nsCOMPtr<nsIDOMNode> resultNode; - + nsCOMPtr<nsIContent> parent = do_QueryInterface(aParent); NS_ENSURE_TRUE(parent, resultNode); resultNode = do_QueryInterface(parent->GetChildAt(aOffset)); return resultNode; } @@ -3595,19 +3595,19 @@ nsEditor::GetNodeAtRangeOffsetPoint(nsID if (IsTextNode(aParentOrNode)) { return aParentOrNode; } return GetChildAt(aParentOrNode, aOffset); } /////////////////////////////////////////////////////////////////////////// -// GetStartNodeAndOffset: returns whatever the start parent & offset is of +// GetStartNodeAndOffset: returns whatever the start parent & offset is of // the first range in the selection. -nsresult +nsresult nsEditor::GetStartNodeAndOffset(Selection* aSelection, nsIDOMNode **outStartNode, int32_t *outStartOffset) { NS_ENSURE_TRUE(outStartNode && outStartOffset && aSelection, NS_ERROR_NULL_POINTER); nsCOMPtr<nsINode> startNode; nsresult rv = GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), @@ -3642,19 +3642,19 @@ nsEditor::GetStartNodeAndOffset(Selectio NS_IF_ADDREF(*aStartNode = range->GetStartParent()); *aStartOffset = range->StartOffset(); return NS_OK; } /////////////////////////////////////////////////////////////////////////// -// GetEndNodeAndOffset: returns whatever the end parent & offset is of +// GetEndNodeAndOffset: returns whatever the end parent & offset is of // the first range in the selection. -nsresult +nsresult nsEditor::GetEndNodeAndOffset(Selection* aSelection, nsIDOMNode **outEndNode, int32_t *outEndOffset) { NS_ENSURE_TRUE(outEndNode && outEndOffset && aSelection, NS_ERROR_NULL_POINTER); nsCOMPtr<nsINode> endNode; nsresult rv = GetEndNodeAndOffset(aSelection, getter_AddRefs(endNode), @@ -3691,23 +3691,23 @@ nsEditor::GetEndNodeAndOffset(Selection* *aEndOffset = range->EndOffset(); return NS_OK; } /////////////////////////////////////////////////////////////////////////// // IsPreformatted: checks the style info for the node for the preformatted // text style. -nsresult +nsresult nsEditor::IsPreformatted(nsIDOMNode *aNode, bool *aResult) { nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); - + NS_ENSURE_TRUE(aResult && content, NS_ERROR_NULL_POINTER); - + nsCOMPtr<nsIPresShell> ps = GetPresShell(); NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED); // Look at the node (and its parent if it's not an element), and grab its style context nsRefPtr<nsStyleContext> elementStyle; if (!content->IsElement()) { content = content->GetParent(); } @@ -3729,28 +3729,28 @@ nsEditor::IsPreformatted(nsIDOMNode *aNo const nsStyleText* styleText = elementStyle->StyleText(); *aResult = styleText->WhiteSpaceIsSignificant(); return NS_OK; } /////////////////////////////////////////////////////////////////////////// -// SplitNodeDeep: this splits a node "deeply", splitting children as +// SplitNodeDeep: this splits a node "deeply", splitting children as // appropriate. The place to split is represented by // a dom point at {splitPointParent, splitPointOffset}. -// That dom point must be inside aNode, which is the node to +// That dom point must be inside aNode, which is the node to // split. outOffset is set to the offset in the parent of aNode where -// the split terminates - where you would want to insert -// a new element, for instance, if that's why you were splitting +// the split terminates - where you would want to insert +// a new element, for instance, if that's why you were splitting // the node. // nsresult -nsEditor::SplitNodeDeep(nsIDOMNode *aNode, - nsIDOMNode *aSplitPointParent, +nsEditor::SplitNodeDeep(nsIDOMNode *aNode, + nsIDOMNode *aSplitPointParent, int32_t aSplitPointOffset, int32_t *outOffset, bool aNoEmptyContainers, nsCOMPtr<nsIDOMNode> *outLeftNode, nsCOMPtr<nsIDOMNode> *outRightNode) { nsCOMPtr<nsINode> node = do_QueryInterface(aNode); NS_ENSURE_TRUE(node && aSplitPointParent && outOffset, NS_ERROR_NULL_POINTER); @@ -3761,21 +3761,21 @@ nsEditor::SplitNodeDeep(nsIDOMNode *aNod nsCOMPtr<nsINode> nodeToSplit = do_QueryInterface(aSplitPointParent); while (nodeToSplit) { // need to insert rules code call here to do things like // not split a list if you are after the last <li> or before the first, etc. // for now we just have some smarts about unneccessarily splitting // textnodes, which should be universal enough to put straight in // this nsEditor routine. - + nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(nodeToSplit); uint32_t len = nodeToSplit->Length(); bool bDoSplit = false; - + if (!(aNoEmptyContainers || nodeAsText) || (offset && (offset != (int32_t)len))) { bDoSplit = true; nsCOMPtr<nsIDOMNode> tempNode; nsresult rv = SplitNode(nodeToSplit->AsDOMNode(), offset, getter_AddRefs(tempNode)); NS_ENSURE_SUCCESS(rv, rv); @@ -3896,17 +3896,17 @@ nsEditor::BeginUpdateViewBatch() mUpdateCount++; } nsresult nsEditor::EndUpdateViewBatch() { NS_PRECONDITION(mUpdateCount > 0, "bad state"); - + if (mUpdateCount <= 0) { mUpdateCount = 0; return NS_ERROR_FAILURE; } mUpdateCount--; @@ -3918,41 +3918,41 @@ nsresult nsEditor::EndUpdateViewBatch() if (selection) { selection->EndBatchChanges(); } } return NS_OK; } -bool +bool nsEditor::GetShouldTxnSetSelection() { return mShouldTxnSetSelection; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::DeleteSelectionImpl(EDirection aAction, EStripWrappers aStripWrappers) { MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip); nsRefPtr<Selection> selection = GetSelection(); NS_ENSURE_STATE(selection); nsRefPtr<EditAggregateTxn> txn; nsCOMPtr<nsINode> deleteNode; int32_t deleteCharOffset = 0, deleteCharLength = 0; nsresult res = CreateTxnForDeleteSelection(aAction, getter_AddRefs(txn), getter_AddRefs(deleteNode), &deleteCharOffset, &deleteCharLength); nsCOMPtr<nsIDOMCharacterData> deleteCharData(do_QueryInterface(deleteNode)); - if (NS_SUCCEEDED(res)) + if (NS_SUCCEEDED(res)) { nsAutoRules beginRulesSniffing(this, EditAction::deleteSelection, aAction); // Notify nsIEditActionListener::WillDelete[Selection|Text|Node] if (!deleteNode) { for (auto& listener : mActionListeners) { listener->WillDeleteSelection(selection); } } else if (deleteCharData) { @@ -3961,17 +3961,17 @@ nsEditor::DeleteSelectionImpl(EDirection } } else { for (auto& listener : mActionListeners) { listener->WillDeleteNode(deleteNode->AsDOMNode()); } } // Delete the specified amount - res = DoTransaction(txn); + res = DoTransaction(txn); // Notify nsIEditActionListener::DidDelete[Selection|Text|Node] if (!deleteNode) { for (auto& listener : mActionListeners) { listener->DidDeleteSelection(selection); } } else if (deleteCharData) { for (auto& listener : mActionListeners) { @@ -4079,28 +4079,28 @@ nsEditor::DeleteSelectionAndPrepareToCre void nsEditor::DoAfterDoTransaction(nsITransaction *aTxn) { bool isTransientTransaction; MOZ_ALWAYS_TRUE(NS_SUCCEEDED( aTxn->GetIsTransient(&isTransientTransaction))); - + if (!isTransientTransaction) { // 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; GetModificationCount(&modCount); if (modCount < 0) modCount = -modCount; - + // don't count transient transactions MOZ_ALWAYS_TRUE(NS_SUCCEEDED( IncrementModificationCount(1))); } } void @@ -4184,33 +4184,33 @@ nsEditor::CreateTxnForIMEText(const nsAS nsRefPtr<IMETextTxn> txn = new IMETextTxn(*mIMETextNode, mIMETextOffset, mComposition->String().Length(), mComposition->GetRanges(), aStringToInsert, *this); return txn.forget(); } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::CreateTxnForAddStyleSheet(CSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn) { nsRefPtr<AddStyleSheetTxn> txn = new AddStyleSheetTxn(); nsresult rv = txn->Init(this, aSheet); if (NS_SUCCEEDED(rv)) { txn.forget(aTxn); } return rv; } -NS_IMETHODIMP +NS_IMETHODIMP nsEditor::CreateTxnForRemoveStyleSheet(CSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn) { nsRefPtr<RemoveStyleSheetTxn> txn = new RemoveStyleSheetTxn(); nsresult rv = txn->Init(this, aSheet); if (NS_SUCCEEDED(rv)) { txn.forget(aTxn); @@ -4460,52 +4460,52 @@ nsEditor::CreateTxnForDeleteInsertionPoi } NS_ADDREF(*aNode = selectedNode); } return NS_OK; } -nsresult +nsresult nsEditor::CreateRange(nsIDOMNode *aStartParent, int32_t aStartOffset, nsIDOMNode *aEndParent, int32_t aEndOffset, nsRange** aRange) { return nsRange::CreateRange(aStartParent, aStartOffset, aEndParent, aEndOffset, aRange); } -nsresult +nsresult nsEditor::AppendNodeToSelectionAsRange(nsIDOMNode *aNode) { NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); nsRefPtr<Selection> selection = GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE); nsCOMPtr<nsIDOMNode> parentNode; nsresult res = aNode->GetParentNode(getter_AddRefs(parentNode)); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_TRUE(parentNode, NS_ERROR_NULL_POINTER); - + int32_t offset = GetChildOffset(aNode, parentNode); - + nsRefPtr<nsRange> range; res = CreateRange(parentNode, offset, parentNode, offset+1, getter_AddRefs(range)); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER); return selection->AddRange(range); } nsresult nsEditor::ClearSelection() { nsRefPtr<Selection> selection = GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE); - return selection->RemoveAllRanges(); + return selection->RemoveAllRanges(); } already_AddRefed<Element> nsEditor::CreateHTMLContent(nsIAtom* aTag) { MOZ_ASSERT(aTag); nsCOMPtr<nsIDocument> doc = GetDocument(); @@ -4593,17 +4593,17 @@ nsEditor::HandleKeyPressEvent(nsIDOMKeyE // bailing here to allow the keybindings to do the cut. if (nativeKeyEvent->IsShift() || nativeKeyEvent->IsControl() || nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() || nativeKeyEvent->IsOS()) { return NS_OK; } DeleteSelection(nsIEditor::eNext, nsIEditor::eStrip); aKeyEvent->PreventDefault(); // consumed - return NS_OK; + return NS_OK; } return NS_OK; } nsresult nsEditor::HandleInlineSpellCheck(EditAction action, Selection* aSelection, nsIDOMNode *previousSelectedNode, @@ -4864,22 +4864,22 @@ nsEditor::SwitchTextDirectionTo(uint32_t #if DEBUG_JOE void nsEditor::DumpNode(nsIDOMNode *aNode, int32_t indent) { int32_t i; for (i=0; i<indent; i++) printf(" "); - + nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode); nsCOMPtr<nsIDOMDocumentFragment> docfrag = do_QueryInterface(aNode); - + if (element || docfrag) - { + { if (element) { nsAutoString tag; element->GetTagName(tag); printf("<%s>\n", NS_LossyConvertUTF16toASCII(tag).get()); } else {
--- a/editor/libeditor/nsEditor.h +++ b/editor/libeditor/nsEditor.h @@ -127,19 +127,19 @@ enum class EditAction : int32_t { increaseZIndex = 3018 }; inline bool operator!(const EditAction& aOp) { return aOp == EditAction::none; } -/** implementation of an editor object. it will be the controller/focal point - * for the main editor services. i.e. the GUIManager, publishing, transaction - * manager, event interfaces. the idea for the event interfaces is to have them +/** implementation of an editor object. it will be the controller/focal point + * for the main editor services. i.e. the GUIManager, publishing, transaction + * manager, event interfaces. the idea for the event interfaces is to have them * delegate the actual commands to the editor independent of the XPFE implementation. */ class nsEditor : public nsIEditor, public nsIEditorIMESupport, public nsSupportsWeakReference, public nsIObserver, public nsIPhonetic { @@ -152,17 +152,17 @@ public: }; /** The default constructor. This should suffice. the setting of the interfaces is done * after the construction of the editor class. */ nsEditor(); protected: - /** The default destructor. This should suffice. Should this be pure virtual + /** The default destructor. This should suffice. Should this be pure virtual * for someone to derive from the nsEditor later? I don't believe so. */ virtual ~nsEditor(); public: //Interfaces for addref and release and queryinterface //NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsEditor NS_DECL_CYCLE_COLLECTING_ISUPPORTS @@ -231,17 +231,17 @@ public: nsIAtom* aNodeType, nsIAtom* aAttribute = nullptr, const nsAString* aValue = nullptr); nsIContent* SplitNode(nsIContent& aNode, int32_t aOffset, mozilla::ErrorResult& aResult); nsresult JoinNodes(nsINode& aLeftNode, nsINode& aRightNode); nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset); - /* Method to replace certain CreateElementNS() calls. + /* Method to replace certain CreateElementNS() calls. Arguments: nsIAtom* aTag - tag you want */ already_AddRefed<mozilla::dom::Element> CreateHTMLContent(nsIAtom* aTag); // IME event handlers virtual nsresult BeginIMEComposition(mozilla::WidgetCompositionEvent* aEvent); virtual nsresult UpdateIMEComposition(nsIDOMEvent* aDOMTextEvent) = 0; @@ -289,18 +289,18 @@ protected: nsresult CreateTxnForDeleteSelection(EDirection aAction, EditAggregateTxn** aTxn, nsINode** aNode, int32_t* aOffset, int32_t* aLength); - nsresult CreateTxnForDeleteInsertionPoint(nsRange* aRange, - EDirection aAction, + nsresult CreateTxnForDeleteInsertionPoint(nsRange* aRange, + EDirection aAction, EditAggregateTxn* aTxn, nsINode** aNode, int32_t* aOffset, int32_t* aLength); /** Create a transaction for inserting aStringToInsert into aTextNode. Never * returns null. @@ -317,30 +317,30 @@ protected: */ NS_IMETHOD CreateTxnForAddStyleSheet(mozilla::CSSStyleSheet* aSheet, AddStyleSheetTxn* *aTxn); /** create a transaction for removing a style sheet */ NS_IMETHOD CreateTxnForRemoveStyleSheet(mozilla::CSSStyleSheet* aSheet, RemoveStyleSheetTxn* *aTxn); - + nsresult DeleteText(nsGenericDOMDataNode& aElement, uint32_t aOffset, uint32_t aLength); // NS_IMETHOD DeleteRange(nsIDOMRange *aRange); already_AddRefed<mozilla::dom::DeleteTextTxn> CreateTxnForDeleteText(nsGenericDOMDataNode& aElement, uint32_t aOffset, uint32_t aLength); already_AddRefed<mozilla::dom::DeleteTextTxn> CreateTxnForDeleteCharacter(nsGenericDOMDataNode& aData, uint32_t aOffset, EDirection aDirection); - + already_AddRefed<mozilla::dom::SplitNodeTxn> CreateTxnForSplitNode(nsIContent& aNode, uint32_t aOffset); already_AddRefed<mozilla::dom::JoinNodeTxn> CreateTxnForJoinNode(nsINode& aLeftNode, nsINode& aRightNode); /** * This method first deletes the selection, if it's not collapsed. Then if @@ -359,20 +359,20 @@ protected: // called after a transaction is redone successfully void DoAfterRedoTransaction(); typedef enum { eDocumentCreated, eDocumentToBeDestroyed, eDocumentStateChanged } TDocumentListenerNotification; - + // tell the doc state listeners that the doc state has changed NS_IMETHOD NotifyDocumentListeners(TDocumentListenerNotification aNotificationType); - + /** make the given selection span the entire document */ virtual nsresult SelectEntireDocument(mozilla::dom::Selection* aSelection); /** helper method for scrolling the selection into view after * an edit operation. aScrollToAnchor should be true if you * want to scroll to the point where the selection was started. * If false, it attempts to scroll the end of the selection into view. * @@ -380,25 +380,25 @@ protected: * in the various selection interfaces, since this version makes sure * that the editor's sync/async settings for reflowing, painting, and * scrolling match. */ NS_IMETHOD ScrollSelectionIntoView(bool aScrollToAnchor); // Convenience method; forwards to IsBlockNode(nsINode*). bool IsBlockNode(nsIDOMNode* aNode); - // stub. see comment in source. + // stub. see comment in source. virtual bool IsBlockNode(nsINode* aNode); - + // helper for GetPriorNode and GetNextNode nsIContent* FindNextLeafNode(nsINode *aCurrentNode, bool aGoForward, bool bNoBlockCrossing); - // install the event listeners for the editor + // install the event listeners for the editor virtual nsresult InstallEventListeners(); virtual void CreateEventListeners(); // unregister and release our event listeners virtual void RemoveEventListeners(); /** @@ -427,38 +427,38 @@ public: * with a call to StartOperation, naming the action and direction */ NS_IMETHOD StartOperation(EditAction opID, nsIEditor::EDirection aDirection); /** All editor operations which alter the doc should be followed * with a call to EndOperation */ NS_IMETHOD EndOperation(); - /** routines for managing the preservation of selection across + /** routines for managing the preservation of selection across * various editor actions */ bool ArePreservingSelection(); void PreserveSelectionAcrossActions(mozilla::dom::Selection* aSel); nsresult RestorePreservedSelection(mozilla::dom::Selection* aSel); void StopPreservingSelection(); - /** + /** * SplitNode() creates a new node identical to an existing node, and split * the contents between the two nodes * @param aExistingRightNode The node to split. It will become the new * node's next sibling. * @param aOffset The offset of aExistingRightNode's * content|children to do the split at * @param aNewLeftNode The new node resulting from the split, becomes * aExistingRightNode's previous sibling. */ nsresult SplitNodeImpl(nsIContent& aExistingRightNode, int32_t aOffset, nsIContent& aNewLeftNode); - /** + /** * JoinNodes() takes 2 nodes and merge their content|children. * @param aNodeToKeep The node that will remain after the join. * @param aNodeToJoin The node that will be joined with aNodeToKeep. * There is no requirement that the two nodes be of the same type. * @param aParent The parent of aNodeToKeep */ nsresult JoinNodesImpl(nsINode* aNodeToKeep, nsINode* aNodeToJoin, @@ -474,19 +474,19 @@ public: /** * Set outOffset to the offset of aChild in the parent. * Returns the parent of aChild. */ static already_AddRefed<nsIDOMNode> GetNodeLocation(nsIDOMNode* aChild, int32_t* outOffset); static nsINode* GetNodeLocation(nsINode* aChild, int32_t* aOffset); - /** returns the number of things inside aNode in the out-param aCount. - * @param aNode is the node to get the length of. - * If aNode is text, returns number of characters. + /** returns the number of things inside aNode in the out-param aCount. + * @param aNode is the node to get the length of. + * If aNode is text, returns number of characters. * If not, returns number of children nodes. * @param aCount [OUT] the result of the above calculation. */ static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, uint32_t &aCount); /** get the node immediately prior to aCurrentNode * @param aCurrentNode the node from which we start the search * @param aEditableNode if true, only return an editable node @@ -572,17 +572,17 @@ public: bool IsEditable(nsIDOMNode *aNode); virtual bool IsEditable(nsINode* aNode); /** returns true if aNode is a MozEditorBogus node */ bool IsMozEditorBogusNode(nsINode* aNode); /** counts number of editable child nodes */ uint32_t CountEditableChildren(nsINode* aNode); - + /** Find the deep first and last children. */ nsINode* GetFirstEditableNode(nsINode* aRoot); /** * Returns current composition. */ mozilla::TextComposition* GetComposition() const; /** @@ -594,17 +594,17 @@ public: static nsresult GetTagString(nsIDOMNode *aNode, nsAString& outString); static nsIAtom *GetTag(nsIDOMNode *aNode); bool NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2); virtual bool AreNodesSameType(nsIContent* aNode1, nsIContent* aNode2); static bool IsTextNode(nsIDOMNode *aNode); static bool IsTextNode(nsINode *aNode); - + static nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, int32_t aOffset); static nsCOMPtr<nsIDOMNode> GetNodeAtRangeOffsetPoint(nsIDOMNode* aParentOrNode, int32_t aOffset); static nsresult GetStartNodeAndOffset(mozilla::dom::Selection* aSelection, nsIDOMNode** outStartNode, int32_t* outStartOffset); static nsresult GetStartNodeAndOffset(mozilla::dom::Selection* aSelection, nsINode** aStartNode, @@ -616,31 +616,31 @@ public: nsINode** aEndNode, int32_t* aEndOffset); #if DEBUG_JOE static void DumpNode(nsIDOMNode *aNode, int32_t indent=0); #endif mozilla::dom::Selection* GetSelection(int16_t aSelectionType = nsISelectionController::SELECTION_NORMAL); - // Helpers to add a node to the selection. + // Helpers to add a node to the selection. // Used by table cell selection methods nsresult CreateRange(nsIDOMNode *aStartParent, int32_t aStartOffset, nsIDOMNode *aEndParent, int32_t aEndOffset, nsRange** aRange); // Creates a range with just the supplied node and appends that to the selection nsresult AppendNodeToSelectionAsRange(nsIDOMNode *aNode); // When you are using AppendNodeToSelectionAsRange, call this first to start a new selection nsresult ClearSelection(); nsresult IsPreformatted(nsIDOMNode *aNode, bool *aResult); - nsresult SplitNodeDeep(nsIDOMNode *aNode, - nsIDOMNode *aSplitPointParent, + nsresult SplitNodeDeep(nsIDOMNode *aNode, + nsIDOMNode *aSplitPointParent, int32_t aSplitPointOffset, int32_t *outOffset, bool aNoEmptyContainers = false, nsCOMPtr<nsIDOMNode> *outLeftNode = 0, nsCOMPtr<nsIDOMNode> *outRightNode = 0); ::DOMPoint JoinNodeDeep(nsIContent& aLeftNode, nsIContent& aRightNode); nsresult GetString(const nsAString& name, nsAString& value); @@ -729,17 +729,17 @@ public: { return (mFlags & nsIPlaintextEditor::eEditorAllowInteraction) != 0; } bool DontEchoPassword() const { return (mFlags & nsIPlaintextEditor::eEditorDontEchoPassword) != 0; } - + bool ShouldSkipSpellCheck() const { return (mFlags & nsIPlaintextEditor::eEditorSkipSpellCheck) != 0; } bool IsTabbable() const { return IsSingleLineEditor() || IsPasswordEditor() || IsFormWidget() ||
--- a/editor/libeditor/nsEditorCommands.h +++ b/editor/libeditor/nsEditorCommands.h @@ -15,19 +15,19 @@ class nsISupports; // This is a virtual base class for commands registered with the editor controller. // Note that such commands can be shared by more than on editor instance, so // MUST be stateless. Any state must be stored via the refCon (an nsIEditor). class nsBaseEditorCommand : public nsIControllerCommand { public: nsBaseEditorCommand(); - + NS_DECL_ISUPPORTS - + NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, bool *_retval) override = 0; NS_IMETHOD DoCommand(const char *aCommandName, nsISupports *aCommandRefCon) override = 0; protected: virtual ~nsBaseEditorCommand() {} };
--- a/editor/libeditor/nsEditorController.h +++ b/editor/libeditor/nsEditorController.h @@ -15,17 +15,17 @@ { 0x2c5a5cdd, 0xe742, 0x4dfe, { 0x86, 0xb8, 0x06, 0x93, 0x09, 0xbf, 0x6c, 0x91 } } class nsIControllerCommandTable; // the editor controller is used for both text widgets, and basic text editing // commands in composer. The refCon that gets passed to its commands is an nsIEditor. -class nsEditorController +class nsEditorController { public: static nsresult RegisterEditorCommands(nsIControllerCommandTable* inCommandTable); static nsresult RegisterEditingCommands(nsIControllerCommandTable* inCommandTable); }; #endif /* nsEditorController_h__ */
--- a/editor/libeditor/nsEditorEventListener.cpp +++ b/editor/libeditor/nsEditorEventListener.cpp @@ -101,17 +101,17 @@ nsEditorEventListener::nsEditorEventList #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH , mHaveBidiKeyboards(false) , mShouldSwitchTextDirection(false) , mSwitchToRTL(false) #endif { } -nsEditorEventListener::~nsEditorEventListener() +nsEditorEventListener::~nsEditorEventListener() { if (mEditor) { NS_WARNING("We're not uninstalled"); Disconnect(); } } nsresult @@ -680,17 +680,17 @@ nsEditorEventListener::MouseClick(nsIDOM bool preventDefault; nsresult rv = aMouseEvent->GetDefaultPrevented(&preventDefault); if (NS_FAILED(rv) || preventDefault) { // We're done if 'preventdefault' is true (see for example bug 70698). return rv; } - // If we got a mouse down inside the editing area, we should force the + // If we got a mouse down inside the editing area, we should force the // IME to commit before we change the cursor position mEditor->ForceCompositionEnd(); int16_t button = -1; aMouseEvent->GetButton(&button); if (button == 1) { return HandleMiddleClickPaste(aMouseEvent); } @@ -716,17 +716,17 @@ nsEditorEventListener::HandleMiddleClick } nsRefPtr<Selection> selection = mEditor->GetSelection(); if (selection) { selection->Collapse(parent, offset); } // If the ctrl key is pressed, we'll do paste as quotation. - // Would've used the alt key, but the kde wmgr treats alt-middle specially. + // Would've used the alt key, but the kde wmgr treats alt-middle specially. bool ctrlKey = false; aMouseEvent->GetCtrlKey(&ctrlKey); nsCOMPtr<nsIEditorMailSupport> mailEditor; if (ctrlKey) { mailEditor = do_QueryObject(mEditor); } @@ -918,18 +918,18 @@ nsEditorEventListener::Drop(nsIDOMDragEv nsCOMPtr<nsIContent> dropParent = do_QueryInterface(parent); NS_ENSURE_TRUE(dropParent, NS_ERROR_FAILURE); if (!dropParent->IsEditable() || !CanDrop(aDragEvent)) { // was it because we're read-only? if ((mEditor->IsReadonly() || mEditor->IsDisabled()) && !IsFileControlTextBox()) { // it was decided to "eat" the event as this is the "least surprise" - // since someone else handling it might be unintentional and the - // user could probably re-drag to be not over the disabled/readonly + // since someone else handling it might be unintentional and the + // user could probably re-drag to be not over the disabled/readonly // editfields if that is what is desired. return aDragEvent->StopPropagation(); } return NS_OK; } aDragEvent->StopPropagation(); aDragEvent->PreventDefault();
--- a/editor/libeditor/nsEditorUtils.cpp +++ b/editor/libeditor/nsEditorUtils.cpp @@ -28,17 +28,17 @@ using namespace mozilla; using namespace mozilla::dom; /****************************************************************************** * nsAutoSelectionReset *****************************************************************************/ nsAutoSelectionReset::nsAutoSelectionReset(Selection* aSel, nsEditor* aEd) : mSel(nullptr), mEd(nullptr) -{ +{ if (!aSel || !aEd) return; // not much we can do, bail. if (aEd->ArePreservingSelection()) return; // we already have initted mSavedSel, so this must be nested call. mSel = aSel; mEd = aEd; if (mSel) { mEd->PreserveSelectionAcrossActions(mSel); } @@ -173,17 +173,17 @@ nsEditorHookUtils::GetHookEnumeratorFrom nsCOMPtr<nsIDocShell> docShell = doc->GetDocShell(); nsCOMPtr<nsIClipboardDragDropHookList> hookObj = do_GetInterface(docShell); NS_ENSURE_TRUE(hookObj, NS_ERROR_FAILURE); return hookObj->GetHookEnumerator(aResult); } bool -nsEditorHookUtils::DoInsertionHook(nsIDOMDocument *aDoc, nsIDOMEvent *aDropEvent, +nsEditorHookUtils::DoInsertionHook(nsIDOMDocument *aDoc, nsIDOMEvent *aDropEvent, nsITransferable *aTrans) { nsCOMPtr<nsISimpleEnumerator> enumerator; GetHookEnumeratorFromDocument(aDoc, getter_AddRefs(enumerator)); NS_ENSURE_TRUE(enumerator, true); bool hasMoreHooks = false; while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMoreHooks)) && hasMoreHooks)
--- a/editor/libeditor/nsEditorUtils.h +++ b/editor/libeditor/nsEditorUtils.h @@ -22,31 +22,31 @@ class nsRange; namespace mozilla { namespace dom { template <class T> class OwningNonNull; class Selection; } } /*************************************************************************** - * stack based helper class for batching a collection of txns inside a + * stack based helper class for batching a collection of txns inside a * placeholder txn. */ class MOZ_STACK_CLASS nsAutoPlaceHolderBatch { private: nsCOMPtr<nsIEditor> mEd; public: - nsAutoPlaceHolderBatch( nsIEditor *aEd, nsIAtom *atom) : mEd(do_QueryInterface(aEd)) + nsAutoPlaceHolderBatch( nsIEditor *aEd, nsIAtom *atom) : mEd(do_QueryInterface(aEd)) { if (mEd) mEd->BeginPlaceHolderTransaction(atom); } ~nsAutoPlaceHolderBatch() { if (mEd) mEd->EndPlaceHolderTransaction(); } }; /*************************************************************************** - * stack based helper class for batching a collection of txns. + * stack based helper class for batching a collection of txns. * Note: I changed this to use placeholder batching so that we get * proper selection save/restore across undo/redo. */ class MOZ_STACK_CLASS nsAutoEditBatch : public nsAutoPlaceHolderBatch { public: explicit nsAutoEditBatch( nsIEditor *aEd) : nsAutoPlaceHolderBatch(aEd,nullptr) {} ~nsAutoEditBatch() {} @@ -61,115 +61,115 @@ class MOZ_STACK_CLASS nsAutoSelectionRes private: /** ref-counted reference to the selection that we are supposed to restore */ nsRefPtr<mozilla::dom::Selection> mSel; nsEditor *mEd; // non-owning ref to nsEditor public: /** constructor responsible for remembering all state needed to restore aSel */ nsAutoSelectionReset(mozilla::dom::Selection* aSel, nsEditor* aEd); - + /** destructor restores mSel to its former state */ ~nsAutoSelectionReset(); /** Abort: cancel selection saver */ void Abort(); }; /*************************************************************************** * stack based helper class for StartOperation()/EndOperation() sandwich */ class MOZ_STACK_CLASS nsAutoRules { public: - + nsAutoRules(nsEditor *ed, EditAction action, nsIEditor::EDirection aDirection) : mEd(ed), mDoNothing(false) - { + { if (mEd && !mEd->mAction) // mAction will already be set if this is nested call { mEd->StartOperation(action, aDirection); } else mDoNothing = true; // nested calls will end up here } - ~nsAutoRules() + ~nsAutoRules() { - if (mEd && !mDoNothing) + if (mEd && !mDoNothing) { mEd->EndOperation(); } } - + protected: nsEditor *mEd; bool mDoNothing; }; /*************************************************************************** * stack based helper class for turning off active selection adjustment * by low level transactions */ class MOZ_STACK_CLASS nsAutoTxnsConserveSelection { public: - + explicit nsAutoTxnsConserveSelection(nsEditor *ed) : mEd(ed), mOldState(true) { - if (mEd) + if (mEd) { mOldState = mEd->GetShouldTxnSetSelection(); mEd->SetShouldTxnSetSelection(false); } } - - ~nsAutoTxnsConserveSelection() + + ~nsAutoTxnsConserveSelection() { - if (mEd) + if (mEd) { mEd->SetShouldTxnSetSelection(mOldState); } } - + protected: nsEditor *mEd; bool mOldState; }; /*************************************************************************** * stack based helper class for batching reflow and paint requests. */ class MOZ_STACK_CLASS nsAutoUpdateViewBatch { public: - + explicit nsAutoUpdateViewBatch(nsEditor *ed) : mEd(ed) { NS_ASSERTION(mEd, "null mEd pointer!"); - if (mEd) + if (mEd) mEd->BeginUpdateViewBatch(); } - - ~nsAutoUpdateViewBatch() + + ~nsAutoUpdateViewBatch() { - if (mEd) + if (mEd) mEd->EndUpdateViewBatch(); } - + protected: nsEditor *mEd; }; /****************************************************************************** * some helper classes for iterating the dom tree *****************************************************************************/ -class nsBoolDomIterFunctor +class nsBoolDomIterFunctor { public: virtual bool operator()(nsINode* aNode) const = 0; }; class MOZ_STACK_CLASS nsDOMIterator { public:
--- a/editor/libeditor/nsHTMLAbsPosition.cpp +++ b/editor/libeditor/nsHTMLAbsPosition.cpp @@ -57,31 +57,31 @@ using namespace mozilla::dom; NS_IMETHODIMP nsHTMLEditor::AbsolutePositionSelection(bool aEnabled) { nsAutoEditBatch beginBatching(this); nsAutoRules beginRulesSniffing(this, aEnabled ? EditAction::setAbsolutePosition : EditAction::removeAbsolutePosition, nsIEditor::eNext); - + // the line below does not match the code; should it be removed? // Find out if the selection is collapsed: nsRefPtr<Selection> selection = GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); nsTextRulesInfo ruleInfo(aEnabled ? EditAction::setAbsolutePosition : EditAction::removeAbsolutePosition); bool cancel, handled; // Protect the edit rules object from dying nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules); nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); if (NS_FAILED(res) || cancel) return res; - + return mRules->DidDoAction(selection, &ruleInfo, res); } NS_IMETHODIMP nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval) { nsCOMPtr<nsIDOMElement> element; nsresult res = GetSelectionContainer(getter_AddRefs(element)); @@ -97,17 +97,17 @@ nsHTMLEditor::GetAbsolutelyPositionedSel NS_ENSURE_SUCCESS(res, res); if (positionStr.EqualsLiteral("absolute")) resultNode = GetAsDOMNode(node); else { node = node->GetParentNode(); } } - element = do_QueryInterface(resultNode ); + element = do_QueryInterface(resultNode ); *_retval = element; NS_IF_ADDREF(*_retval); return NS_OK; } NS_IMETHODIMP nsHTMLEditor::GetSelectionContainerAbsolutelyPositioned(bool *aIsSelectionContainerAbsolutelyPositioned) { @@ -166,30 +166,30 @@ nsHTMLEditor::SetElementZIndex(nsIDOMEle NS_IMETHODIMP nsHTMLEditor::RelativeChangeZIndex(int32_t aChange) { nsAutoEditBatch beginBatching(this); nsAutoRules beginRulesSniffing(this, (aChange < 0) ? EditAction::decreaseZIndex : EditAction::increaseZIndex, nsIEditor::eNext); - + // brade: can we get rid of this comment? // Find out if the selection is collapsed: nsRefPtr<Selection> selection = GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); nsTextRulesInfo ruleInfo(aChange < 0 ? EditAction::decreaseZIndex : EditAction::increaseZIndex); bool cancel, handled; // Protect the edit rules object from dying nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules); nsresult res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled); if (cancel || NS_FAILED(res)) return res; - + return mRules->DidDoAction(selection, &ruleInfo, res); } NS_IMETHODIMP nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement, int32_t * aZindex) { nsCOMPtr<Element> element = do_QueryInterface(aElement); @@ -615,17 +615,17 @@ nsHTMLEditor::CheckPositionedElementBGan // each above #d0, use a black background // If the background color is 'auto' and at least one of R G B values of // the foreground is below #d0, use a white background // Otherwise don't change background/foreground nsCOMPtr<Element> element = do_QueryInterface(aElement); NS_ENSURE_STATE(element || !aElement); aReturn.Truncate(); - + nsAutoString bgImageStr; nsresult res = mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::background_image, bgImageStr); NS_ENSURE_SUCCESS(res, res); if (bgImageStr.EqualsLiteral("none")) { nsAutoString bgColorStr; res =
--- a/editor/libeditor/nsHTMLCSSUtils.cpp +++ b/editor/libeditor/nsHTMLCSSUtils.cpp @@ -145,45 +145,45 @@ static void ProcessMarginLeftValue(const nsAString * aInputString, nsAString & aOutputString, const char * aDefaultValueString, const char * aPrependString, const char* aAppendString) { aOutputString.Truncate(); if (aInputString) { if (aInputString->EqualsLiteral("center") || aInputString->EqualsLiteral("-moz-center")) { - aOutputString.AppendLiteral("auto"); + aOutputString.AppendLiteral("auto"); } else if (aInputString->EqualsLiteral("right") || aInputString->EqualsLiteral("-moz-right")) { - aOutputString.AppendLiteral("auto"); + aOutputString.AppendLiteral("auto"); } else { - aOutputString.AppendLiteral("0px"); + aOutputString.AppendLiteral("0px"); } } } static void ProcessMarginRightValue(const nsAString * aInputString, nsAString & aOutputString, const char * aDefaultValueString, const char * aPrependString, const char* aAppendString) { aOutputString.Truncate(); if (aInputString) { if (aInputString->EqualsLiteral("center") || aInputString->EqualsLiteral("-moz-center")) { - aOutputString.AppendLiteral("auto"); + aOutputString.AppendLiteral("auto"); } else if (aInputString->EqualsLiteral("left") || aInputString->EqualsLiteral("-moz-left")) { - aOutputString.AppendLiteral("auto"); + aOutputString.AppendLiteral("auto"); } else { - aOutputString.AppendLiteral("0px"); + aOutputString.AppendLiteral("0px"); } } } const nsHTMLCSSUtils::CSSEquivTable boldEquivTable[] = { { nsHTMLCSSUtils::eCSSEditableProperty_font_weight, ProcessBValue, nullptr, nullptr, nullptr, true, false }, { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 } }; @@ -1185,17 +1185,17 @@ nsHTMLCSSUtils::SetCSSEnabled(bool aIsCS bool nsHTMLCSSUtils::IsCSSPrefChecked() { return mIsCSSPrefChecked ; } // ElementsSameStyle compares two elements and checks if they have the same -// specified CSS declarations in the STYLE attribute +// specified CSS declarations in the STYLE attribute // The answer is always negative if at least one of them carries an ID or a class bool nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode) { nsCOMPtr<dom::Element> firstElement = do_QueryInterface(aFirstNode); nsCOMPtr<dom::Element> secondElement = do_QueryInterface(aSecondNode); NS_ASSERTION((firstElement && secondElement), "Non element nodes passed to ElementsSameStyle.");
--- a/editor/libeditor/nsHTMLCSSUtils.h +++ b/editor/libeditor/nsHTMLCSSUtils.h @@ -280,17 +280,17 @@ public: /** retrieves the mIsCSSPrefChecked private member, true if the css pref is checked, * false if it is not * * @return the boolean value of the css pref */ bool IsCSSPrefChecked(); /** ElementsSameStyle compares two elements and checks if they have the same - * specified CSS declarations in the STYLE attribute + * specified CSS declarations in the STYLE attribute * The answer is always false if at least one of them carries an ID or a class * * @return true if the two elements are considered to have same styles * @param aFirstNode [IN] a DOM node * @param aSecondNode [IN] a DOM node */ bool ElementsSameStyle(mozilla::dom::Element* aFirstNode, mozilla::dom::Element* aSecondNode); @@ -399,22 +399,22 @@ private: * @param aStyleType [IN] eSpecified or eComputed */ nsresult GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty, nsAString& aValue, StyleType aStyleType); private: nsHTMLEditor *mHTMLEditor; - bool mIsCSSPrefChecked; + bool mIsCSSPrefChecked; }; #define NS_EDITOR_INDENT_INCREMENT_IN 0.4134f #define NS_EDITOR_INDENT_INCREMENT_CM 1.05f #define NS_EDITOR_INDENT_INCREMENT_MM 10.5f #define NS_EDITOR_INDENT_INCREMENT_PT 29.76f #define NS_EDITOR_INDENT_INCREMENT_PC 2.48f #define NS_EDITOR_INDENT_INCREMENT_EM 3 #define NS_EDITOR_INDENT_INCREMENT_EX 6 #define NS_EDITOR_INDENT_INCREMENT_PX 40 -#define NS_EDITOR_INDENT_INCREMENT_PERCENT 4 +#define NS_EDITOR_INDENT_INCREMENT_PERCENT 4 #endif /* nsHTMLCSSUtils_h__ */
--- a/editor/libeditor/nsHTMLDataTransfer.cpp +++ b/editor/libeditor/nsHTMLDataTransfer.cpp @@ -91,17 +91,17 @@ class nsILoadContext; class nsISupports; using namespace mozilla; using namespace mozilla::dom; #define kInsertCookie "_moz_Insert Here_moz_" // some little helpers -static bool FindIntegerAfterString(const char *aLeadingString, +static bool FindIntegerAfterString(const char *aLeadingString, nsCString &aCStr, int32_t &foundNumber); static nsresult RemoveFragComments(nsCString &theStr); static void RemoveBodyAndHead(nsINode& aNode); static nsresult FindTargetNode(nsIDOMNode *aStart, nsCOMPtr<nsIDOMNode> &aResult); nsresult nsHTMLEditor::LoadHTML(const nsAString & aInputString) { @@ -325,17 +325,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co cellSelectionMode = true; } if (cellSelectionMode) { // do we have table content to paste? If so, we want to delete // the selected table cells and replace with new table elements; // but if not we want to delete _contents_ of cells and replace - // with non-table elements. Use cellSelectionMode bool to + // with non-table elements. Use cellSelectionMode bool to // indicate results. if (!nsHTMLEditUtils::IsTableElement(nodeList[0])) { cellSelectionMode = false; } } if (!cellSelectionMode) { @@ -418,18 +418,18 @@ nsHTMLEditor::DoInsertHTMLWithContext(co // remember number of lists and tables above us int32_t highWaterMark = -1; if (startListAndTableArray.Length() > 0) { highWaterMark = DiscoverPartialListsAndTables(nodeList, startListAndTableArray); } - // if we have pieces of tables or lists to be inserted, let's force the paste - // to deal with table elements right away, so that it doesn't orphan some + // if we have pieces of tables or lists to be inserted, let's force the paste + // to deal with table elements right away, so that it doesn't orphan some // table or list contents outside the table or list. if (highWaterMark >= 0) { ReplaceOrphanedStructure(StartOrEnd::start, nodeList, startListAndTableArray, highWaterMark); } // Now go through the same process again for the end of the paste node list. @@ -465,17 +465,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co nsCOMPtr<nsIDOMNode> curNode = nodeList[j]->AsDOMNode(); NS_ENSURE_TRUE(curNode, NS_ERROR_FAILURE); NS_ENSURE_TRUE(curNode != fragmentAsNode, NS_ERROR_FAILURE); NS_ENSURE_TRUE(!nsTextEditUtils::IsBody(curNode), NS_ERROR_FAILURE); if (insertedContextParent) { - // if we had to insert something higher up in the paste hierarchy, we want to + // if we had to insert something higher up in the paste hierarchy, we want to // skip any further paste nodes that descend from that. Else we will paste twice. if (nsEditorUtils::IsDescendantOf(curNode, insertedContextParent)) continue; } // give the user a hand on table element insertion. if they have // a table or table row on the clipboard, and are trying to insert // into a table or table row, insert the appropriate children instead. @@ -496,17 +496,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co curNode->GetFirstChild(getter_AddRefs(child)); } } // give the user a hand on list insertion. if they have // a list on the clipboard, and are trying to insert // into a list or list item, insert the appropriate children instead, // ie, merge the lists instead of pasting in a sublist. - else if (nsHTMLEditUtils::IsList(curNode) && + else if (nsHTMLEditUtils::IsList(curNode) && (nsHTMLEditUtils::IsList(parentNode) || nsHTMLEditUtils::IsListItem(parentNode)) ) { nsCOMPtr<nsIDOMNode> child, tmp; curNode->GetFirstChild(getter_AddRefs(child)); while (child) { if (nsHTMLEditUtils::IsListItem(child) || nsHTMLEditUtils::IsList(child)) { @@ -594,17 +594,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co if (lastInsertNode) { parentNode = GetNodeLocation(lastInsertNode, &offsetOfNewNode); offsetOfNewNode++; } } // Now collapse the selection to the end of what we just inserted: - if (lastInsertNode) + if (lastInsertNode) { // set selection to the end of what we just pasted. nsCOMPtr<nsIDOMNode> selNode, tmp, highTable; int32_t selOffset; // but don't cross tables if (!nsHTMLEditUtils::IsTable(lastInsertNode)) { @@ -644,17 +644,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co nsWSRunObject wsRunObj(this, selNode, selOffset); nsCOMPtr<nsINode> visNode; int32_t outVisOffset=0; WSType visType; nsCOMPtr<nsINode> selNode_(do_QueryInterface(selNode)); wsRunObj.PriorVisibleNode(selNode_, selOffset, address_of(visNode), &outVisOffset, &visType); if (visType == WSType::br) { - // we are after a break. Is it visible? Despite the name, + // we are after a break. Is it visible? Despite the name, // PriorVisibleNode does not make that determination for breaks. // It also may not return the break in visNode. We have to pull it // out of the nsWSRunObject's state. if (!IsVisBreak(wsRunObj.mStartReasonNode)) { // don't leave selection past an invisible break; // reset {selNode,selOffset} to point before break selNode = GetNodeLocation(GetAsDOMNode(wsRunObj.mStartReasonNode), &selOffset); @@ -662,17 +662,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co nsWSRunObject wsRunObj(this, selNode, selOffset); selNode_ = do_QueryInterface(selNode); wsRunObj.PriorVisibleNode(selNode_, selOffset, address_of(visNode), &outVisOffset, &visType); if (visType == WSType::text || visType == WSType::normalWS) { selNode = GetAsDOMNode(visNode); selOffset = outVisOffset; // PriorVisibleNode already set offset to _after_ the text or ws } else if (visType == WSType::special) { - // prior visible thing is an image or some other non-text thingy. + // prior visible thing is an image or some other non-text thingy. // We want to be right after it. selNode = GetNodeLocation(GetAsDOMNode(wsRunObj.mStartReasonNode), &selOffset); ++selOffset; } } } selection->Collapse(selNode, selOffset); @@ -716,25 +716,25 @@ NS_IMETHODIMP nsHTMLEditor::RemoveInsertionListener(nsIContentFilter *aListener) { NS_ENSURE_TRUE(aListener, NS_ERROR_FAILURE); mContentFilters.RemoveElement(aListener); return NS_OK; } - + nsresult -nsHTMLEditor::DoContentFilterCallback(const nsAString &aFlavor, +nsHTMLEditor::DoContentFilterCallback(const nsAString &aFlavor, nsIDOMDocument *sourceDoc, bool aWillDeleteSelection, - nsIDOMNode **aFragmentAsNode, - nsIDOMNode **aFragStartNode, + nsIDOMNode **aFragmentAsNode, + nsIDOMNode **aFragStartNode, int32_t *aFragStartOffset, - nsIDOMNode **aFragEndNode, + nsIDOMNode **aFragEndNode, int32_t *aFragEndOffset, nsIDOMNode **aTargetNode, int32_t *aTargetOffset, bool *aDoContinue) { *aDoContinue = true; for (auto& listener : mContentFilters) { @@ -755,17 +755,17 @@ bool nsHTMLEditor::IsInLink(nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *outLink) { NS_ENSURE_TRUE(aNode, false); if (outLink) *outLink = nullptr; nsCOMPtr<nsIDOMNode> tmp, node = aNode; while (node) { - if (nsHTMLEditUtils::IsLink(node)) + if (nsHTMLEditUtils::IsLink(node)) { if (outLink) *outLink = node; return true; } tmp = node; tmp->GetParentNode(getter_AddRefs(node)); } @@ -820,17 +820,17 @@ nsHTMLEditor::PrepareHTMLTransferable(ns nsILoadContext* loadContext = destdoc ? destdoc->GetLoadContext() : nullptr; (*aTransferable)->Init(loadContext); // Create the desired DataFlavor for the type of data // we want to get out of the transferable // This should only happen in html editors, not plaintext if (!IsPlaintextEditor()) { - if (!aHavePrivFlavor) + if (!aHavePrivFlavor) { (*aTransferable)->AddDataFlavor(kNativeHTMLMime); } (*aTransferable)->AddDataFlavor(kHTMLMime); (*aTransferable)->AddDataFlavor(kFileMime); switch (Preferences::GetInt("clipboard.paste_image_type", 1)) { @@ -853,22 +853,22 @@ nsHTMLEditor::PrepareHTMLTransferable(ns (*aTransferable)->AddDataFlavor(kJPGImageMime); (*aTransferable)->AddDataFlavor(kPNGImageMime); break; } } (*aTransferable)->AddDataFlavor(kUnicodeMime); (*aTransferable)->AddDataFlavor(kMozTextInternal); } - + return NS_OK; } bool -FindIntegerAfterString(const char *aLeadingString, +FindIntegerAfterString(const char *aLeadingString, nsCString &aCStr, int32_t &foundNumber) { // first obtain offsets from cfhtml str int32_t numFront = aCStr.Find(aLeadingString); if (numFront == -1) return false; numFront += strlen(aLeadingString); @@ -903,26 +903,26 @@ RemoveFragComments(nsCString & aStr) return NS_OK; } nsresult nsHTMLEditor::ParseCFHTML(nsCString & aCfhtml, char16_t **aStuffToPaste, char16_t **aCfcontext) { // First obtain offsets from cfhtml str. int32_t startHTML, endHTML, startFragment, endFragment; - if (!FindIntegerAfterString("StartHTML:", aCfhtml, startHTML) || + if (!FindIntegerAfterString("StartHTML:", aCfhtml, startHTML) || startHTML < -1) return NS_ERROR_FAILURE; - if (!FindIntegerAfterString("EndHTML:", aCfhtml, endHTML) || + if (!FindIntegerAfterString("EndHTML:", aCfhtml, endHTML) || endHTML < -1) return NS_ERROR_FAILURE; - if (!FindIntegerAfterString("StartFragment:", aCfhtml, startFragment) || + if (!FindIntegerAfterString("StartFragment:", aCfhtml, startFragment) || startFragment < 0) return NS_ERROR_FAILURE; - if (!FindIntegerAfterString("EndFragment:", aCfhtml, endFragment) || + if (!FindIntegerAfterString("EndFragment:", aCfhtml, endFragment) || startFragment < 0) return NS_ERROR_FAILURE; // The StartHTML and EndHTML markers are allowed to be -1 to include everything. // See Reference: MSDN doc entitled "HTML Clipboard Format" // http://msdn.microsoft.com/en-us/library/aa767917(VS.85).aspx#unknown_854 if (startHTML == -1) { startHTML = aCfhtml.Find("<!--StartFragment-->"); @@ -949,29 +949,29 @@ nsHTMLEditor::ParseCFHTML(nsCString & aC while (curPos > startHTML) { if (aCfhtml[curPos] == '>') { // working backwards, the first thing we see is the end of a tag // so StartFragment is good, so do nothing. break; } - else if (aCfhtml[curPos] == '<') + else if (aCfhtml[curPos] == '<') { // if we are at the start, then we want to see the '<' - if (curPos != startFragment) + if (curPos != startFragment) { // working backwards, the first thing we see is the start of a tag // so StartFragment is bad, so we need to update it. NS_ERROR("StartFragment byte count in the clipboard looks bad, see bug #228879"); startFragment = curPos - 1; } break; } - else + else { curPos--; } } // create fragment string nsAutoCString fragmentUTF8(Substring(aCfhtml, startFragment, endFragment-startFragment)); @@ -984,27 +984,27 @@ nsHTMLEditor::ParseCFHTML(nsCString & aC // convert both strings to usc2 const nsAFlatString& fragUcs2Str = NS_ConvertUTF8toUTF16(fragmentUTF8); const nsAFlatString& cntxtUcs2Str = NS_ConvertUTF8toUTF16(contextUTF8); // translate platform linebreaks for fragment int32_t oldLengthInChars = fragUcs2Str.Length() + 1; // +1 to include null terminator int32_t newLengthInChars = 0; *aStuffToPaste = nsLinebreakConverter::ConvertUnicharLineBreaks(fragUcs2Str.get(), - nsLinebreakConverter::eLinebreakAny, - nsLinebreakConverter::eLinebreakContent, + nsLinebreakConverter::eLinebreakAny, + nsLinebreakConverter::eLinebreakContent, oldLengthInChars, &newLengthInChars); NS_ENSURE_TRUE(*aStuffToPaste, NS_ERROR_FAILURE); // translate platform linebreaks for context oldLengthInChars = cntxtUcs2Str.Length() + 1; // +1 to include null terminator newLengthInChars = 0; *aCfcontext = nsLinebreakConverter::ConvertUnicharLineBreaks(cntxtUcs2Str.get(), - nsLinebreakConverter::eLinebreakAny, - nsLinebreakConverter::eLinebreakContent, + nsLinebreakConverter::eLinebreakAny, + nsLinebreakConverter::eLinebreakContent, oldLengthInChars, &newLengthInChars); // it's ok for context to be empty. frag might be whole doc and contain all its context. // we're done! return NS_OK; } nsresult nsHTMLEditor::InsertObject(const char* aType, nsISupports* aObject, bool aIsSafe, @@ -1079,17 +1079,17 @@ nsresult nsHTMLEditor::InsertObject(cons nsAutoString stuffToPaste; stuffToPaste.AssignLiteral("<IMG src=\"data:"); AppendUTF8toUTF16(type, stuffToPaste); stuffToPaste.AppendLiteral(";base64,"); AppendUTF8toUTF16(data64, stuffToPaste); stuffToPaste.AppendLiteral("\" alt=\"\" >"); nsAutoEditBatch beginBatching(this); - rv = DoInsertHTMLWithContext(stuffToPaste, EmptyString(), EmptyString(), + rv = DoInsertHTMLWithContext(stuffToPaste, EmptyString(), EmptyString(), NS_LITERAL_STRING(kFileMime), aSourceDoc, aDestinationNode, aDestOffset, aDoDeleteSelection, aIsSafe, false); } return NS_OK; @@ -1408,17 +1408,17 @@ NS_IMETHODIMP nsHTMLEditor::PasteTransfe if (!nsEditorHookUtils::DoInsertionHook(domdoc, nullptr, aTransferable)) return NS_OK; nsAutoString contextStr, infoStr; return InsertFromTransferable(aTransferable, nullptr, contextStr, infoStr, nullptr, 0, true); } -// +// // HTML PasteNoFormatting. Ignore any HTML styles and formating in paste source // NS_IMETHODIMP nsHTMLEditor::PasteNoFormatting(int32_t aSelectionType) { if (!FireClipboardEvent(NS_PASTE, aSelectionType)) return NS_OK; ForceCompositionEnd(); @@ -1429,17 +1429,17 @@ NS_IMETHODIMP nsHTMLEditor::PasteNoForma NS_ENSURE_SUCCESS(rv, rv); // Get the nsITransferable interface for getting the data from the clipboard. // use nsPlaintextEditor::PrepareTransferable() to force unicode plaintext data. nsCOMPtr<nsITransferable> trans; rv = nsPlaintextEditor::PrepareTransferable(getter_AddRefs(trans)); if (NS_SUCCEEDED(rv) && trans) { - // Get the Data from the clipboard + // Get the Data from the clipboard if (NS_SUCCEEDED(clipboard->GetData(trans, aSelectionType)) && IsModifiable()) { const nsAFlatString& empty = EmptyString(); rv = InsertFromTransferable(trans, nullptr, empty, empty, nullptr, 0, true); } } @@ -2177,17 +2177,17 @@ nsHTMLEditor::GetListAndTableParents(Sta } int32_t nsHTMLEditor::DiscoverPartialListsAndTables(nsTArray<OwningNonNull<nsINode>>& aPasteNodes, nsTArray<OwningNonNull<Element>>& aListsAndTables) { int32_t ret = -1; int32_t listAndTableParents = aListsAndTables.Length(); - + // Scan insertion list for table elements (other than table). for (auto& curNode : aPasteNodes) { if (nsHTMLEditUtils::IsTableElement(curNode) && !curNode->IsHTMLElement(nsGkAtoms::table)) { nsCOMPtr<Element> table = curNode->GetParentElement(); while (table && !table->IsHTMLElement(nsGkAtoms::table)) { table = table->GetParentElement(); } @@ -2225,17 +2225,17 @@ nsHTMLEditor::DiscoverPartialListsAndTab nsINode* nsHTMLEditor::ScanForListAndTableStructure(StartOrEnd aStartOrEnd, nsTArray<OwningNonNull<nsINode>>& aNodes, Element& aListOrTable) { // Look upward from first/last paste node for a piece of this list/table int32_t idx = aStartOrEnd == StartOrEnd::end ? aNodes.Length() - 1 : 0; bool isList = nsHTMLEditUtils::IsList(&aListOrTable); - + for (nsCOMPtr<nsINode> node = aNodes[idx]; node; node = node->GetParentNode()) { if ((isList && nsHTMLEditUtils::IsListItem(node)) || (!isList && nsHTMLEditUtils::IsTableElement(node) && !node->IsHTMLElement(nsGkAtoms::table))) { nsCOMPtr<Element> structureNode = node->GetParentElement(); if (isList) { while (structureNode && !nsHTMLEditUtils::IsList(structureNode)) {
--- a/editor/libeditor/nsHTMLEditRules.cpp +++ b/editor/libeditor/nsHTMLEditRules.cpp @@ -97,17 +97,17 @@ IsStyleCachePreservingAction(EditAction action == EditAction::outdent || action == EditAction::align || action == EditAction::makeBasicBlock || action == EditAction::removeList || action == EditAction::makeDefListItem || action == EditAction::insertElement || action == EditAction::insertQuotation; } - + class nsTableCellAndListItemFunctor : public nsBoolDomIterFunctor { public: // Used to build list of all li's, td's & th's iterator covers virtual bool operator()(nsINode* aNode) const { if (nsHTMLEditUtils::IsTableCell(aNode)) return true; if (nsHTMLEditUtils::IsListItem(aNode)) return true; @@ -149,29 +149,29 @@ class nsEmptyEditableFunctor : public ns }; class nsEditableTextFunctor : public nsBoolDomIterFunctor { public: explicit nsEditableTextFunctor(nsHTMLEditor* editor) : mHTMLEditor(editor) {} virtual bool operator()(nsINode* aNode) const { - if (nsEditor::IsTextNode(aNode) && mHTMLEditor->IsEditable(aNode)) + if (nsEditor::IsTextNode(aNode) && mHTMLEditor->IsEditable(aNode)) { return true; } return false; } protected: nsHTMLEditor* mHTMLEditor; }; /******************************************************** - * Constructor/Destructor + * Constructor/Destructor ********************************************************/ nsHTMLEditRules::nsHTMLEditRules() { InitFields(); } void @@ -208,17 +208,17 @@ nsHTMLEditRules::InitFields() mCachedStyles[16] = StyleCache(nsGkAtoms::backgroundColor, EmptyString(), EmptyString()); mCachedStyles[17] = StyleCache(nsGkAtoms::sub, EmptyString(), EmptyString()); mCachedStyles[18] = StyleCache(nsGkAtoms::sup, EmptyString(), EmptyString()); } nsHTMLEditRules::~nsHTMLEditRules() { // remove ourselves as a listener to edit actions - // In some cases, we have already been removed by + // In some cases, we have already been removed by // ~nsHTMLEditor, in which case we will get a null pointer here // which we ignore. But this allows us to add the ability to // switch rule sets on the fly if we want. if (mHTMLEditor) mHTMLEditor->RemoveEditActionListener(this); } /******************************************************** @@ -226,28 +226,28 @@ nsHTMLEditRules::~nsHTMLEditRules() ********************************************************/ NS_IMPL_ADDREF_INHERITED(nsHTMLEditRules, nsTextEditRules) NS_IMPL_RELEASE_INHERITED(nsHTMLEditRules, nsTextEditRules) NS_IMPL_QUERY_INTERFACE_INHERITED(nsHTMLEditRules, nsTextEditRules, nsIEditActionListener) /******************************************************** - * Public methods + * Public methods ********************************************************/ NS_IMETHODIMP nsHTMLEditRules::Init(nsPlaintextEditor *aEditor) { InitFields(); mHTMLEditor = static_cast<nsHTMLEditor*>(aEditor); nsresult res; - // call through to base class Init + // call through to base class Init res = nsTextEditRules::Init(aEditor); NS_ENSURE_SUCCESS(res, res); // cache any prefs we care about static const char kPrefName[] = "editor.html.typing.returnInEmptyListItemClosesList"; nsAdoptingCString returnInEmptyLIKillsList = Preferences::GetCString(kPrefName); @@ -260,17 +260,17 @@ nsHTMLEditRules::Init(nsPlaintextEditor nsCOMPtr<nsINode> node = mHTMLEditor->GetRoot(); if (!node) { node = mHTMLEditor->GetDocument(); } NS_ENSURE_STATE(node); mUtilRange = new nsRange(node); - + // set up mDocChangeRange to be whole doc // temporarily turn off rules sniffing nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this); if (!mDocChangeRange) { mDocChangeRange = new nsRange(node); } if (node->IsElement()) { @@ -304,19 +304,19 @@ nsHTMLEditRules::BeforeEdit(EditAction a nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this); mDidExplicitlySetInterline = false; if (!mActionNesting++) { // clear our flag about if just deleted a range mDidRangedDelete = false; - + // remember where our selection was before edit action took place: - + // get selection NS_ENSURE_STATE(mHTMLEditor); nsRefPtr<Selection> selection = mHTMLEditor->GetSelection(); // get the selection location NS_ENSURE_STATE(selection->RangeCount()); mRangeItem->startNode = selection->GetRangeAt(0)->GetStartParent(); mRangeItem->startOffset = selection->GetRangeAt(0)->StartOffset(); @@ -326,27 +326,27 @@ nsHTMLEditRules::BeforeEdit(EditAction a nsCOMPtr<nsIDOMNode> selEndNode = GetAsDOMNode(mRangeItem->endNode); // register this range with range updater to track this as we perturb the doc NS_ENSURE_STATE(mHTMLEditor); (mHTMLEditor->mRangeUpdater).RegisterRangeItem(mRangeItem); // clear deletion state bool mDidDeleteSelection = false; - + // clear out mDocChangeRange and mUtilRange if(mDocChangeRange) { // clear out our accounting of what changed - mDocChangeRange->Reset(); + mDocChangeRange->Reset(); } if(mUtilRange) { // ditto for mUtilRange. - mUtilRange->Reset(); + mUtilRange->Reset(); } // remember current inline styles for deletion and normal insertion operations if (action == EditAction::insertText || action == EditAction::insertIMEText || action == EditAction::deleteSelection || IsStyleCachePreservingAction(action)) { nsCOMPtr<nsIDOMNode> selNode = selStartNode; @@ -414,111 +414,111 @@ nsHTMLEditRules::AfterEdit(EditAction ac nsresult nsHTMLEditRules::AfterEditInner(EditAction action, nsIEditor::EDirection aDirection) { ConfirmSelectionInBody(); if (action == EditAction::ignore) return NS_OK; - + NS_ENSURE_STATE(mHTMLEditor); nsRefPtr<Selection> selection = mHTMLEditor->GetSelection(); NS_ENSURE_STATE(selection); - + nsCOMPtr<nsIDOMNode> rangeStartParent, rangeEndParent; int32_t rangeStartOffset = 0, rangeEndOffset = 0; // do we have a real range to act on? - bool bDamagedRange = false; + bool bDamagedRange = false; if (mDocChangeRange) - { + { mDocChangeRange->GetStartContainer(getter_AddRefs(rangeStartParent)); mDocChangeRange->GetEndContainer(getter_AddRefs(rangeEndParent)); mDocChangeRange->GetStartOffset(&rangeStartOffset); mDocChangeRange->GetEndOffset(&rangeEndOffset); - if (rangeStartParent && rangeEndParent) - bDamagedRange = true; - } - + if (rangeStartParent && rangeEndParent) + bDamagedRange = true; + } + nsresult res; if (bDamagedRange && !((action == EditAction::undo) || (action == EditAction::redo))) { // don't let any txns in here move the selection around behind our back. // Note that this won't prevent explicit selection setting from working. NS_ENSURE_STATE(mHTMLEditor); nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); - + // expand the "changed doc range" as needed PromoteRange(*mDocChangeRange, action); // if we did a ranged deletion or handling backspace key, make sure we have // a place to put caret. // Note we only want to do this if the overall operation was deletion, // not if deletion was done along the way for EditAction::loadHTML, EditAction::insertText, etc. // That's why this is here rather than DidDeleteSelection(). if ((action == EditAction::deleteSelection) && mDidRangedDelete) { res = InsertBRIfNeeded(selection); NS_ENSURE_SUCCESS(res, res); - } - + } + // add in any needed <br>s, and remove any unneeded ones. AdjustSpecialBreaks(); - + // merge any adjacent text nodes if ( (action != EditAction::insertText && action != EditAction::insertIMEText) ) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->CollapseAdjacentTextNodes(mDocChangeRange); NS_ENSURE_SUCCESS(res, res); } // clean up any empty nodes in the selection res = RemoveEmptyNodes(); NS_ENSURE_SUCCESS(res, res); // attempt to transform any unneeded nbsp's into spaces after doing various operations - if ((action == EditAction::insertText) || + if ((action == EditAction::insertText) || (action == EditAction::insertIMEText) || (action == EditAction::deleteSelection) || - (action == EditAction::insertBreak) || + (action == EditAction::insertBreak) || (action == EditAction::htmlPaste || (action == EditAction::loadHTML))) { res = AdjustWhitespace(selection); NS_ENSURE_SUCCESS(res, res); - - // also do this for original selection endpoints. + + // also do this for original selection endpoints. NS_ENSURE_STATE(mHTMLEditor); NS_ENSURE_STATE(mRangeItem->startNode); NS_ENSURE_STATE(mRangeItem->endNode); nsWSRunObject(mHTMLEditor, mRangeItem->startNode, mRangeItem->startOffset).AdjustWhitespace(); // we only need to handle old selection endpoint if it was different from start if (mRangeItem->startNode != mRangeItem->endNode || mRangeItem->startOffset != mRangeItem->endOffset) { NS_ENSURE_STATE(mHTMLEditor); nsWSRunObject(mHTMLEditor, mRangeItem->endNode, mRangeItem->endOffset).AdjustWhitespace(); } } - + // if we created a new block, make sure selection lands in it if (mNewBlock) { res = PinSelectionToNewBlock(selection); mNewBlock = 0; } // adjust selection for insert text, html paste, and delete actions - if ((action == EditAction::insertText) || + if ((action == EditAction::insertText) || (action == EditAction::insertIMEText) || (action == EditAction::deleteSelection) || - (action == EditAction::insertBreak) || + (action == EditAction::insertBreak) || (action == EditAction::htmlPaste || (action == EditAction::loadHTML))) { res = AdjustSelection(selection, aDirection); NS_ENSURE_SUCCESS(res, res); } // check for any styles which were removed inappropriately @@ -526,39 +526,39 @@ nsHTMLEditRules::AfterEditInner(EditActi action == EditAction::insertIMEText || action == EditAction::deleteSelection || IsStyleCachePreservingAction(action)) { NS_ENSURE_STATE(mHTMLEditor); mHTMLEditor->mTypeInState->UpdateSelState(selection); res = ReapplyCachedStyles(); NS_ENSURE_SUCCESS(res, res); ClearCachedStyles(); - } + } } NS_ENSURE_STATE(mHTMLEditor); - - res = mHTMLEditor->HandleInlineSpellCheck(action, selection, + + res = mHTMLEditor->HandleInlineSpellCheck(action, selection, GetAsDOMNode(mRangeItem->startNode), mRangeItem->startOffset, rangeStartParent, rangeStartOffset, rangeEndParent, rangeEndOffset); NS_ENSURE_SUCCESS(res, res); // detect empty doc res = CreateBogusNodeIfNeeded(selection); - + // adjust selection HINT if needed NS_ENSURE_SUCCESS(res, res); - + if (!mDidExplicitlySetInterline) { res = CheckInterlinePosition(selection); } - + return res; } NS_IMETHODIMP nsHTMLEditRules::WillDoAction(Selection* aSelection, nsRulesInfo* aInfo, bool* aCancel, @@ -677,27 +677,27 @@ nsHTMLEditRules::DidDoAction(Selection* NS_ENSURE_SUCCESS(rv, rv); return DidAbsolutePosition(); } default: // pass thru to nsTextEditRules return nsTextEditRules::DidDoAction(aSelection, aInfo, aResult); } } - + nsresult nsHTMLEditRules::GetListState(bool *aMixed, bool *aOL, bool *aUL, bool *aDL) { NS_ENSURE_TRUE(aMixed && aOL && aUL && aDL, NS_ERROR_NULL_POINTER); *aMixed = false; *aOL = false; *aUL = false; *aDL = false; bool bNonList = false; - + nsTArray<OwningNonNull<nsINode>> arrayOfNodes; nsresult res = GetListActionNodes(arrayOfNodes, EntireList::no, TouchContent::no); NS_ENSURE_SUCCESS(res, res); // Examine list type for nodes in selection. for (const auto& curNode : arrayOfNodes) { if (!curNode->IsElement()) { @@ -716,36 +716,36 @@ nsHTMLEditRules::GetListState(bool *aMix } } else if (curNode->IsAnyOfHTMLElements(nsGkAtoms::dl, nsGkAtoms::dt, nsGkAtoms::dd)) { *aDL = true; } else { bNonList = true; } - } - + } + // hokey arithmetic with booleans if ((*aUL + *aOL + *aDL + bNonList) > 1) { *aMixed = true; } return NS_OK; } -nsresult +nsresult nsHTMLEditRules::GetListItemState(bool *aMixed, bool *aLI, bool *aDT, bool *aDD) { NS_ENSURE_TRUE(aMixed && aLI && aDT && aDD, NS_ERROR_NULL_POINTER); *aMixed = false; *aLI = false; *aDT = false; *aDD = false; bool bNonList = false; - + nsTArray<OwningNonNull<nsINode>> arrayOfNodes; nsresult res = GetListActionNodes(arrayOfNodes, EntireList::no, TouchContent::no); NS_ENSURE_SUCCESS(res, res); // examine list type for nodes in selection for (const auto& node : arrayOfNodes) { if (!node->IsElement()) { @@ -762,47 +762,47 @@ nsHTMLEditRules::GetListItemState(bool * // need to look inside dl and see which types of items it has bool bDT, bDD; GetDefinitionListItemTypes(node->AsElement(), &bDT, &bDD); *aDT |= bDT; *aDD |= bDD; } else { bNonList = true; } - } - + } + // hokey arithmetic with booleans if ( (*aDT + *aDD + bNonList) > 1) *aMixed = true; - + return NS_OK; } -nsresult +nsresult nsHTMLEditRules::GetAlignment(bool *aMixed, nsIHTMLEditor::EAlignment *aAlign) { // for now, just return first alignment. we'll lie about // if it's mixed. This is for efficiency // given that our current ui doesn't care if it's mixed. // cmanske: NOT TRUE! We would like to pay attention to mixed state // in Format | Align submenu! // this routine assumes that alignment is done ONLY via divs // default alignment is left NS_ENSURE_TRUE(aMixed && aAlign, NS_ERROR_NULL_POINTER); *aMixed = false; *aAlign = nsIHTMLEditor::eLeft; // get selection - NS_ENSURE_STATE(mHTMLEditor); + NS_ENSURE_STATE(mHTMLEditor); nsRefPtr<Selection> selection = mHTMLEditor->GetSelection(); NS_ENSURE_STATE(selection); // get selection location - NS_ENSURE_STATE(mHTMLEditor); + NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<Element> rootElem = mHTMLEditor->GetRoot(); NS_ENSURE_TRUE(rootElem, NS_ERROR_FAILURE); int32_t offset, rootOffset; nsCOMPtr<nsINode> parent = nsEditor::GetNodeLocation(rootElem, &rootOffset); NS_ENSURE_STATE(mHTMLEditor); nsresult res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), @@ -814,17 +814,17 @@ nsHTMLEditRules::GetAlignment(bool *aMix if (selection->Collapsed()) { // if it is, we want to look at 'parent' and its ancestors // for divs with alignment on them nodeToExamine = parent; } else if (!mHTMLEditor) { return NS_ERROR_UNEXPECTED; } - else if (mHTMLEditor->IsTextNode(parent)) + else if (mHTMLEditor->IsTextNode(parent)) { // if we are in a text node, then that is the node of interest nodeToExamine = parent; } else if (parent->IsHTMLElement(nsGkAtoms::html) && offset == rootOffset) { // if we have selected the body, let's look at the first editable node NS_ENSURE_STATE(mHTMLEditor); nodeToExamine = mHTMLEditor->GetNextNode(parent, offset, true); } @@ -832,17 +832,17 @@ nsHTMLEditRules::GetAlignment(bool *aMix { nsTArray<nsRefPtr<nsRange>> arrayOfRanges; GetPromotedRanges(*selection, arrayOfRanges, EditAction::align); // use these ranges to construct a list of nodes to act on. nsTArray<OwningNonNull<nsINode>> arrayOfNodes; res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, EditAction::align, TouchContent::no); - NS_ENSURE_SUCCESS(res, res); + NS_ENSURE_SUCCESS(res, res); nodeToExamine = arrayOfNodes.SafeElementAt(0); } NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER); NS_NAMED_LITERAL_STRING(typeAttrName, "align"); nsIAtom *dummyProperty = nullptr; nsCOMPtr<Element> blockParent; @@ -923,36 +923,36 @@ nsHTMLEditRules::GetAlignment(bool *aMix *aAlign = nsIHTMLEditor::eJustify; else *aAlign = nsIHTMLEditor::eLeft; return res; } } } isFirstNodeToExamine = false; - nodeToExamine = nodeToExamine->GetParentNode(); + nodeToExamine = nodeToExamine->GetParentNode(); } return NS_OK; } static nsIAtom* MarginPropertyAtomForIndent(nsHTMLCSSUtils* aHTMLCSSUtils, nsIDOMNode* aNode) { nsCOMPtr<nsINode> node = do_QueryInterface(aNode); NS_ENSURE_TRUE(node || !aNode, nsGkAtoms::marginLeft); nsAutoString direction; aHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::direction, direction); return direction.EqualsLiteral("rtl") ? nsGkAtoms::marginRight : nsGkAtoms::marginLeft; } -nsresult +nsresult nsHTMLEditRules::GetIndentState(bool *aCanIndent, bool *aCanOutdent) { NS_ENSURE_TRUE(aCanIndent && aCanOutdent, NS_ERROR_FAILURE); - *aCanIndent = true; + *aCanIndent = true; *aCanOutdent = false; // get selection NS_ENSURE_STATE(mHTMLEditor && mHTMLEditor->GetSelection()); OwningNonNull<Selection> selection = *mHTMLEditor->GetSelection(); // contruct a list of nodes to act on. nsTArray<OwningNonNull<nsINode>> arrayOfNodes; @@ -987,33 +987,33 @@ nsHTMLEditRules::GetIndentState(bool *aC NS_ENSURE_STATE(mHTMLEditor); mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit)); // if the number part is strictly positive, outdent is possible if (0 < f) { *aCanOutdent = true; break; } } - } - + } + if (!*aCanOutdent) { // if we haven't found something to outdent yet, also check the parents - // of selection endpoints. We might have a blockquote or list item + // of selection endpoints. We might have a blockquote or list item // in the parent hierarchy. - + // gather up info we need for test NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<nsIDOMNode> parent, tmp, root = do_QueryInterface(mHTMLEditor->GetRoot()); NS_ENSURE_TRUE(root, NS_ERROR_NULL_POINTER); int32_t selOffset; NS_ENSURE_STATE(mHTMLEditor); nsRefPtr<Selection> selection = mHTMLEditor->GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); - + // test start parent hierarchy NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), &selOffset); NS_ENSURE_SUCCESS(res, res); while (parent && (parent!=root)) { if (nsHTMLEditUtils::IsNodeThatCanOutdent(parent)) { @@ -1038,29 +1038,29 @@ nsHTMLEditRules::GetIndentState(bool *aC tmp=parent; tmp->GetParentNode(getter_AddRefs(parent)); } } return res; } -nsresult +nsresult nsHTMLEditRules::GetParagraphState(bool *aMixed, nsAString &outFormat) { // This routine is *heavily* tied to our ui choices in the paragraph // style popup. I can't see a way around that. NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER); *aMixed = true; outFormat.Truncate(0); - + bool bMixed = false; // using "x" as an uninitialized value, since "" is meaningful - nsAutoString formatStr(NS_LITERAL_STRING("x")); - + nsAutoString formatStr(NS_LITERAL_STRING("x")); + nsTArray<OwningNonNull<nsINode>> arrayOfNodes; nsresult res = GetParagraphFormatNodes(arrayOfNodes, TouchContent::no); NS_ENSURE_SUCCESS(res, res); // post process list. We need to replace any block nodes that are not format // nodes with their content. This is so we only have to look "up" the hierarchy // to find format nodes, instead of both up and down. for (int32_t i = arrayOfNodes.Length() - 1; i >= 0; i--) { @@ -1069,17 +1069,17 @@ nsHTMLEditRules::GetParagraphState(bool // if it is a known format node we have it easy if (IsBlockNode(GetAsDOMNode(curNode)) && !nsHTMLEditUtils::IsFormatNode(curNode)) { // arrayOfNodes.RemoveObject(curNode); res = AppendInnerFormatNodes(arrayOfNodes, curNode); NS_ENSURE_SUCCESS(res, res); } } - + // we might have an empty node list. if so, find selection parent // and put that on the list if (!arrayOfNodes.Length()) { nsCOMPtr<nsINode> selNode; int32_t selOffset; NS_ENSURE_STATE(mHTMLEditor); nsRefPtr<Selection> selection = mHTMLEditor->GetSelection(); NS_ENSURE_STATE(selection); @@ -1124,89 +1124,89 @@ nsHTMLEditRules::GetParagraphState(bool GetFormatString(node, format); break; } // else keep looking up tmp = node; tmp->GetParentNode(getter_AddRefs(node)); } } - + // if this is the first node, we've found, remember it as the format if (formatStr.EqualsLiteral("x")) formatStr = format; // else make sure it matches previously found format - else if (format != formatStr) + else if (format != formatStr) { bMixed = true; - break; - } - } - + break; + } + } + *aMixed = bMixed; outFormat = formatStr; return res; } nsresult nsHTMLEditRules::AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray, nsINode* aNode) { MOZ_ASSERT(aNode); - // we only need to place any one inline inside this node onto + // we only need to place any one inline inside this node onto // the list. They are all the same for purposes of determining - // paragraph style. We use foundInline to track this as we are + // paragraph style. We use foundInline to track this as we are // going through the children in the loop below. bool foundInline = false; for (nsIContent* child = aNode->GetFirstChild(); child; child = child->GetNextSibling()) { bool isBlock = IsBlockNode(child->AsDOMNode()); bool isFormat = nsHTMLEditUtils::IsFormatNode(child); if (isBlock && !isFormat) { // if it's a div, etc, recurse AppendInnerFormatNodes(aArray, child); } else if (isFormat) { aArray.AppendElement(*child); } else if (!foundInline) { // if this is the first inline we've found, use it - foundInline = true; + foundInline = true; aArray.AppendElement(*child); } } return NS_OK; } -nsresult +nsresult nsHTMLEditRules::GetFormatString(nsIDOMNode *aNode, nsAString &outFormat) { NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); if (nsHTMLEditUtils::IsFormatNode(aNode)) { nsCOMPtr<nsIAtom> atom = nsEditor::GetTag(aNode); atom->ToString(outFormat); } else outFormat.Truncate(); return NS_OK; -} +} /******************************************************** - * Protected rules methods + * Protected rules methods ********************************************************/ nsresult nsHTMLEditRules::WillInsert(Selection* aSelection, bool* aCancel) { nsresult res = nsTextEditRules::WillInsert(aSelection, aCancel); - NS_ENSURE_SUCCESS(res, res); - + NS_ENSURE_SUCCESS(res, res); + // Adjust selection to prevent insertion after a moz-BR. // this next only works for collapsed selections right now, // because selection is a pain to work with when not collapsed. // (no good way to extend start or end of selection), so we ignore // those types of selections. if (!aSelection->Collapsed()) { return NS_OK; } @@ -1231,17 +1231,17 @@ nsHTMLEditRules::WillInsert(Selection* a block1 = selNode; } else { NS_ENSURE_STATE(mHTMLEditor); block1 = mHTMLEditor->GetBlockNodeParent(selNode); } NS_ENSURE_STATE(mHTMLEditor); block2 = mHTMLEditor->GetBlockNodeParent(priorNode); - + if (block1 && block1 == block2) { // if we are here then the selection is right after a mozBR // that is in the same block as the selection. We need to move // the selection start to be before the mozBR. selNode = nsEditor::GetNodeLocation(priorNode, &selOffset); res = aSelection->Collapse(selNode,selOffset); NS_ENSURE_SUCCESS(res, res); } @@ -1256,40 +1256,40 @@ nsHTMLEditRules::WillInsert(Selection* a } // For most actions we want to clear the cached styles, but there are // exceptions if (!IsStyleCachePreservingAction(mTheAction)) { ClearCachedStyles(); } return NS_OK; -} +} nsresult nsHTMLEditRules::WillInsertText(EditAction aAction, Selection* aSelection, bool *aCancel, bool *aHandled, const nsAString *inString, nsAString *outString, int32_t aMaxLength) -{ +{ if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } if (inString->IsEmpty() && aAction != EditAction::insertIMEText) { // HACK: this is a fix for bug 19395 // I can't outlaw all empty insertions // because IME transaction depend on them - // There is more work to do to make the + // There is more work to do to make the // world safe for IME. *aCancel = true; *aHandled = false; return NS_OK; } - + // initialize out param *aCancel = false; *aHandled = true; nsresult res; // If the selection isn't collapsed, delete it. Don't delete existing inline // tags, because we're hopefully going to insert text (bug 787432). if (!aSelection->Collapsed()) { NS_ENSURE_STATE(mHTMLEditor); @@ -1307,34 +1307,34 @@ nsHTMLEditRules::WillInsertText(EditActi NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<nsIDocument> doc = mHTMLEditor->GetDocument(); nsCOMPtr<nsIDOMDocument> domDoc = mHTMLEditor->GetDOMDocument(); NS_ENSURE_TRUE(doc && domDoc, NS_ERROR_NOT_INITIALIZED); // for every property that is set, insert a new inline style node res = CreateStyleForInsertText(aSelection, domDoc); NS_ENSURE_SUCCESS(res, res); - + // get the (collapsed) selection location NS_ENSURE_STATE(mHTMLEditor); NS_ENSURE_STATE(aSelection->GetRangeAt(0)); nsCOMPtr<nsINode> selNode = aSelection->GetRangeAt(0)->GetStartParent(); int32_t selOffset = aSelection->GetRangeAt(0)->StartOffset(); NS_ENSURE_STATE(selNode); // dont put text in places that can't have it NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsTextNode(selNode) && (!mHTMLEditor || !mHTMLEditor->CanContainTag(*selNode, *nsGkAtoms::textTagName))) { return NS_ERROR_FAILURE; } - + if (aAction == EditAction::insertIMEText) { - // Right now the nsWSRunObject code bails on empty strings, but IME needs + // Right now the nsWSRunObject code bails on empty strings, but IME needs // the InsertTextImpl() call to still happen since empty strings are meaningful there. if (inString->IsEmpty()) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->InsertTextImpl(*inString, address_of(selNode), &selOffset, doc); } else @@ -1345,64 +1345,64 @@ nsHTMLEditRules::WillInsertText(EditActi } NS_ENSURE_SUCCESS(res, res); } else // aAction == kInsertText { // find where we are nsCOMPtr<nsINode> curNode = selNode; int32_t curOffset = selOffset; - - // is our text going to be PREformatted? + + // is our text going to be PREformatted? // We remember this so that we know how to handle tabs. bool isPRE; NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->IsPreformatted(GetAsDOMNode(selNode), &isPRE); - NS_ENSURE_SUCCESS(res, res); - + NS_ENSURE_SUCCESS(res, res); + // turn off the edit listener: we know how to // build the "doc changed range" ourselves, and it's // must faster to do it once here than to track all // the changes one at a time. - nsAutoLockListener lockit(&mListenerEnabled); - + nsAutoLockListener lockit(&mListenerEnabled); + // don't spaz my selection in subtransactions NS_ENSURE_STATE(mHTMLEditor); nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); nsAutoString tString(*inString); const char16_t *unicodeBuf = tString.get(); int32_t pos = 0; NS_NAMED_LITERAL_STRING(newlineStr, LFSTR); - + // for efficiency, break out the pre case separately. This is because // its a lot cheaper to search the input string for only newlines than // it is to search for both tabs and newlines. if (isPRE || IsPlaintextEditor()) { while (unicodeBuf && (pos != -1) && (pos < (int32_t)(*inString).Length())) { int32_t oldPos = pos; int32_t subStrLen; pos = tString.FindChar(nsCRT::LF, oldPos); - if (pos != -1) + if (pos != -1) { subStrLen = pos - oldPos; // if first char is newline, then use just it if (subStrLen == 0) subStrLen = 1; } else { subStrLen = tString.Length() - oldPos; pos = tString.Length(); } nsDependentSubstring subStr(tString, oldPos, subStrLen); - + // is it a return? if (subStr.Equals(newlineStr)) { NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<Element> br = mHTMLEditor->CreateBRImpl(address_of(curNode), &curOffset, nsIEditor::eNone); NS_ENSURE_STATE(br); @@ -1422,18 +1422,18 @@ nsHTMLEditRules::WillInsertText(EditActi NS_NAMED_LITERAL_STRING(tabStr, "\t"); NS_NAMED_LITERAL_STRING(spacesStr, " "); char specialChars[] = {TAB, nsCRT::LF, 0}; while (unicodeBuf && (pos != -1) && (pos < (int32_t)inString->Length())) { int32_t oldPos = pos; int32_t subStrLen; pos = tString.FindCharInSet(specialChars, oldPos); - - if (pos != -1) + + if (pos != -1) { subStrLen = pos - oldPos; // if first char is newline, then use just it if (subStrLen == 0) subStrLen = 1; } else { @@ -1751,17 +1751,17 @@ nsHTMLEditRules::SplitMailCites(Selectio NS_ENSURE_SUCCESS(res, res); if (citeNode) { // If our selection is just before a break, nudge it to be // just after it. This does two things for us. It saves us the trouble of having to add // a break here ourselves to preserve the "blockness" of the inline span mailquote // (in the inline case), and : // it means the break won't end up making an empty line that happens to be inside a - // mailquote (in either inline or block case). + // mailquote (in either inline or block case). // The latter can confuse a user if they click there and start typing, // because being in the mailquote may affect wrapping behavior, or font color, etc. NS_ENSURE_STATE(mHTMLEditor); nsWSRunObject wsObj(mHTMLEditor, selNode, selOffset); nsCOMPtr<nsINode> visNode; int32_t visOffset=0; WSType wsType; wsObj.NextVisibleNode(selNode, selOffset, address_of(visNode), @@ -1770,17 +1770,17 @@ nsHTMLEditRules::SplitMailCites(Selectio // ok, we are just before a break. is it inside the mailquote? if (visNode != citeNode && citeNode->Contains(visNode)) { // it is. so lets reset our selection to be just after it. NS_ENSURE_STATE(mHTMLEditor); selNode = mHTMLEditor->GetNodeLocation(visNode, &selOffset); ++selOffset; } } - + NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->SplitNodeDeep(GetAsDOMNode(citeNode), GetAsDOMNode(selNode), selOffset, &newOffset, true, address_of(leftCite), address_of(rightCite)); NS_ENSURE_SUCCESS(res, res); selNode = citeNode->GetParentNode(); NS_ENSURE_STATE(mHTMLEditor); @@ -1968,17 +1968,17 @@ nsHTMLEditRules::WillDeleteSelection(Sel } else { res = wsObj.DeleteWSBackward(); } *aHandled = true; NS_ENSURE_SUCCESS(res, res); res = InsertBRIfNeeded(aSelection); return res; } - + if (wsType == WSType::text) { // Found normal text to delete. OwningNonNull<Text> nodeAsText = *visNode->GetAsText(); int32_t so = visOffset; int32_t eo = visOffset + 1; if (aAction == nsIEditor::ePrevious) { if (so == 0) { return NS_ERROR_UNEXPECTED; @@ -2018,17 +2018,17 @@ nsHTMLEditRules::WillDeleteSelection(Sel NS_ENSURE_SUCCESS(res, res); // Remember that we did a ranged delete for the benefit of // AfterEditInner(). mDidRangedDelete = true; return NS_OK; } - + if (wsType == WSType::special || wsType == WSType::br || visNode->IsHTMLElement(nsGkAtoms::hr)) { // Short circuit for invisible breaks. delete them and recurse. if (visNode->IsHTMLElement(nsGkAtoms::br) && (!mHTMLEditor || !mHTMLEditor->IsVisBreak(visNode))) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->DeleteNode(visNode); NS_ENSURE_SUCCESS(res, res); @@ -2135,17 +2135,17 @@ nsHTMLEditRules::WillDeleteSelection(Sel // Fix up selection res = aSelection->Collapse(pt.node, pt.offset); NS_ENSURE_SUCCESS(res, res); } res = InsertBRIfNeeded(aSelection); NS_ENSURE_SUCCESS(res, res); return NS_OK; } - + if (wsType == WSType::otherBlock) { // Make sure it's not a table element. If so, cancel the operation // (translation: users cannot backspace or delete across table cells) if (nsHTMLEditUtils::IsTableElement(visNode)) { *aCancel = true; return NS_OK; } @@ -2215,17 +2215,17 @@ nsHTMLEditRules::WillDeleteSelection(Sel res = JoinBlocks(GetAsDOMNode(leftNode), GetAsDOMNode(rightNode), aCancel); *aHandled = true; NS_ENSURE_SUCCESS(res, res); } aSelection->Collapse(selPointNode, selPointOffset); return NS_OK; } - + if (wsType == WSType::thisBlock) { // At edge of our block. Look beside it and see if we can join to an // adjacent block // Make sure it's not a table element. If so, cancel the operation // (translation: users cannot backspace or delete across table cells) if (nsHTMLEditUtils::IsTableElement(visNode)) { *aCancel = true; @@ -2483,24 +2483,24 @@ nsHTMLEditRules::WillDeleteSelection(Sel NS_ENSURE_SUCCESS(res, res); return NS_OK; } /***************************************************************************************************** * InsertBRIfNeeded: determines if a br is needed for current selection to not be spastic. * If so, it inserts one. Callers responsibility to only call with collapsed selection. -* Selection* aSelection the collapsed selection +* Selection* aSelection the collapsed selection */ nsresult nsHTMLEditRules::InsertBRIfNeeded(Selection* aSelection) { NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER); - - // get selection + + // get selection nsCOMPtr<nsINode> node; int32_t offset; nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_TRUE(node, NS_ERROR_FAILURE); // inline elements don't need any br if (!IsBlockNode(GetAsDOMNode(node))) { @@ -2553,17 +2553,17 @@ nsHTMLEditRules::GetGoodSelPointForNode( ret.offset++; } return ret; } /***************************************************************************************************** * JoinBlocks: this method is used to join two block elements. The right element is always joined -* to the left element. If the elements are the same type and not nested within each other, +* to the left element. If the elements are the same type and not nested within each other, * JoinNodesSmart is called (example, joining two list items together into one). If the elements * are not the same type, or one is a descendant of the other, we instead destroy the right block * placing its children into leftblock. DTD containment rules are followed throughout. * nsCOMPtr<nsIDOMNode> *aLeftBlock pointer to the left block * nsCOMPtr<nsIDOMNode> *aRightBlock pointer to the right block; will have contents moved to left block * bool *aCanceled return TRUE if we had to cancel operation */ nsresult @@ -2613,17 +2613,17 @@ nsHTMLEditRules::JoinBlocks(nsIDOMNode * } NS_ENSURE_STATE(aLeftBlock && aRightBlock); // bail if both blocks the same if (aLeftBlock == aRightBlock) { *aCanceled = true; return NS_OK; } - + // Joining a list item to its parent is a NOP. if (nsHTMLEditUtils::IsList(aLeftBlock) && nsHTMLEditUtils::IsListItem(aRightBlock)) { nsCOMPtr<nsIDOMNode> rightParent; aRightBlock->GetParentNode(getter_AddRefs(rightParent)); if (rightParent == aLeftBlock) { return NS_OK; } @@ -2651,20 +2651,20 @@ nsHTMLEditRules::JoinBlocks(nsIDOMNode * aLeftBlock = leftList; aRightBlock = rightList; bMergeLists = true; NS_ENSURE_STATE(mHTMLEditor); existingList = mHTMLEditor->GetTag(leftList); } } } - + NS_ENSURE_STATE(mHTMLEditor); nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); - + nsresult res = NS_OK; int32_t rightOffset = 0; int32_t leftOffset = -1; // theOffset below is where you find yourself in aRightBlock when you traverse upwards // from aLeftBlock if (nsEditorUtils::IsDescendantOf(aLeftBlock, aRightBlock, &rightOffset)) { // tricky case. left block is inside right block. @@ -2806,17 +2806,17 @@ nsHTMLEditRules::JoinBlocks(nsIDOMNode * if (brNode) mHTMLEditor->DeleteNode(brNode); } else { // normal case. blocks are siblings, or at least close enough to siblings. An example // of the latter is a <p>paragraph</p><ul><li>one<li>two<li>three</ul>. The first // li and the p are not true siblings, but we still want to join them if you backspace // from li into p. - + // adjust whitespace at block boundaries NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<Element> leftBlock(do_QueryInterface(aLeftBlock)); nsCOMPtr<Element> rightBlock(do_QueryInterface(aRightBlock)); res = nsWSRunObject::PrepareToJoinBlocks(mHTMLEditor, leftBlock, rightBlock); NS_ENSURE_SUCCESS(res, res); // Do br adjustment. nsCOMPtr<nsIDOMNode> brNode; @@ -2829,17 +2829,17 @@ nsHTMLEditRules::JoinBlocks(nsIDOMNode * if (pt.node && bMergeLists) { nsCOMPtr<nsIDOMNode> newBlock; res = ConvertListType(aRightBlock, address_of(newBlock), existingList, nsGkAtoms::li); } } else { - // nodes are disimilar types. + // nodes are disimilar types. res = MoveBlock(aLeftBlock, aRightBlock, leftOffset, rightOffset); } if (NS_SUCCEEDED(res) && brNode) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->DeleteNode(brNode); } } @@ -2864,17 +2864,17 @@ nsHTMLEditRules::MoveBlock(nsIDOMNode *a nsresult res = GetNodesFromPoint(::DOMPoint(aRightBlock,aRightOffset), EditAction::makeList, arrayOfNodes, TouchContent::no); NS_ENSURE_SUCCESS(res, res); for (auto& curNode : arrayOfNodes) { // get the node to act on if (IsBlockNode(GetAsDOMNode(curNode))) { // For block nodes, move their contents only, then delete block. - res = MoveContents(GetAsDOMNode(curNode), aLeftBlock, &aLeftOffset); + res = MoveContents(GetAsDOMNode(curNode), aLeftBlock, &aLeftOffset); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->DeleteNode(curNode); } else { // otherwise move the content as is, checking against the dtd. res = MoveNodeSmart(GetAsDOMNode(curNode), aLeftBlock, &aLeftOffset); @@ -2882,17 +2882,17 @@ nsHTMLEditRules::MoveBlock(nsIDOMNode *a } return res; } /***************************************************************************************************** * MoveNodeSmart: this method is used to move node aSource to (aDest,aOffset). * DTD containment rules are followed throughout. aOffset is updated to point _after_ * inserted content. -* nsIDOMNode *aSource the selection. +* nsIDOMNode *aSource the selection. * nsIDOMNode *aDest parent to receive moved content * int32_t *aOffset offset in aDest to move content to */ nsresult nsHTMLEditRules::MoveNodeSmart(nsIDOMNode *aSource, nsIDOMNode *aDest, int32_t *aOffset) { nsCOMPtr<nsIContent> source = do_QueryInterface(aSource); nsCOMPtr<nsINode> dest = do_QueryInterface(aDest); @@ -2919,28 +2919,28 @@ nsHTMLEditRules::MoveNodeSmart(nsIDOMNod } return NS_OK; } /***************************************************************************************************** * MoveContents: this method is used to move node the _contents_ of aSource to (aDest,aOffset). * DTD containment rules are followed throughout. aOffset is updated to point _after_ * inserted content. aSource is deleted. -* nsIDOMNode *aSource the selection. +* nsIDOMNode *aSource the selection. * nsIDOMNode *aDest parent to receive moved content * int32_t *aOffset offset in aDest to move content to */ nsresult nsHTMLEditRules::MoveContents(nsIDOMNode *aSource, nsIDOMNode *aDest, int32_t *aOffset) { NS_ENSURE_TRUE(aSource && aDest && aOffset, NS_ERROR_NULL_POINTER); if (aSource == aDest) return NS_ERROR_ILLEGAL_VALUE; NS_ENSURE_STATE(mHTMLEditor); NS_ASSERTION(!mHTMLEditor->IsTextNode(aSource), "#text does not have contents"); - + nsCOMPtr<nsIDOMNode> child; nsAutoString tag; nsresult res; aSource->GetFirstChild(getter_AddRefs(child)); while (child) { res = MoveNodeSmart(child, aDest, aOffset); NS_ENSURE_SUCCESS(res, res); @@ -2962,29 +2962,29 @@ nsHTMLEditRules::DeleteNonTableElements( for (int32_t i = aNode->GetChildCount() - 1; i >= 0; --i) { nsresult rv = DeleteNonTableElements(aNode->GetChildAt(i)); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; } nsresult -nsHTMLEditRules::DidDeleteSelection(Selection* aSelection, - nsIEditor::EDirection aDir, +nsHTMLEditRules::DidDeleteSelection(Selection* aSelection, + nsIEditor::EDirection aDir, nsresult aResult) { if (!aSelection) { return NS_ERROR_NULL_POINTER; } - + // find where we are nsCOMPtr<nsINode> startNode; int32_t startOffset; nsresult res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(startNode), &startOffset); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE); - + // find any enclosing mailcite nsCOMPtr<Element> citeNode = GetTopEnclosingMailCite(*startNode); if (citeNode) { bool isEmpty = true, seenBR = false; NS_ENSURE_STATE(mHTMLEditor); mHTMLEditor->IsEmptyNodeImpl(citeNode, &isEmpty, true, true, false, &seenBR); if (isEmpty) @@ -2998,17 +2998,17 @@ nsHTMLEditRules::DidDeleteSelection(Sele { NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<Element> brNode = mHTMLEditor->CreateBR(parent, offset); NS_ENSURE_STATE(brNode); aSelection->Collapse(parent, offset); } } } - + // call through to base class return nsTextEditRules::DidDeleteSelection(aSelection, aDir, aResult); } nsresult nsHTMLEditRules::WillMakeList(Selection* aSelection, const nsAString* aListType, bool aEntireList, @@ -3027,17 +3027,17 @@ nsHTMLEditRules::WillMakeList(Selection* // initialize out param // we want to ignore result of WillInsert() *aCancel = false; *aHandled = false; // deduce what tag to use for list items nsCOMPtr<nsIAtom> itemType; - if (aItemType) { + if (aItemType) { itemType = do_GetAtom(*aItemType); NS_ENSURE_TRUE(itemType, NS_ERROR_OUT_OF_MEMORY); } else if (listType == nsGkAtoms::dl) { itemType = nsGkAtoms::dd; } else { itemType = nsGkAtoms::li; } @@ -3313,54 +3313,54 @@ nsHTMLEditRules::WillMakeList(Selection* } return res; } nsresult nsHTMLEditRules::WillRemoveList(Selection* aSelection, - bool aOrdered, + bool aOrdered, bool *aCancel, bool *aHandled) { if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } // initialize out param *aCancel = false; *aHandled = true; - + nsresult res = NormalizeSelection(aSelection); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); - + nsTArray<nsRefPtr<nsRange>> arrayOfRanges; GetPromotedRanges(*aSelection, arrayOfRanges, EditAction::makeList); - + // use these ranges to contruct a list of nodes to act on. nsTArray<OwningNonNull<nsINode>> arrayOfNodes; res = GetListActionNodes(arrayOfNodes, EntireList::no); - NS_ENSURE_SUCCESS(res, res); - + NS_ENSURE_SUCCESS(res, res); + // Remove all non-editable nodes. Leave them be. int32_t listCount = arrayOfNodes.Length(); int32_t i; for (i=listCount-1; i>=0; i--) { OwningNonNull<nsINode> testNode = arrayOfNodes[i]; NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsEditable(testNode)) { arrayOfNodes.RemoveElementAt(i); } } - + // reset list count listCount = arrayOfNodes.Length(); - + // Only act on lists or list items in the array for (auto& curNode : arrayOfNodes) { // here's where we actually figure out what to do if (nsHTMLEditUtils::IsListItem(curNode)) // unlist this listitem { bool bOutOfList; do { @@ -3375,38 +3375,38 @@ nsHTMLEditRules::WillRemoveList(Selectio } } return res; } nsresult nsHTMLEditRules::WillMakeDefListItem(Selection* aSelection, - const nsAString *aItemType, - bool aEntireList, + const nsAString *aItemType, + bool aEntireList, bool *aCancel, bool *aHandled) { // for now we let WillMakeList handle this NS_NAMED_LITERAL_STRING(listType, "dl"); return WillMakeList(aSelection, &listType, aEntireList, nullptr, aCancel, aHandled, aItemType); } nsresult nsHTMLEditRules::WillMakeBasicBlock(Selection* aSelection, - const nsAString *aBlockType, + const nsAString *aBlockType, bool *aCancel, bool *aHandled) { OwningNonNull<nsIAtom> blockType = do_GetAtom(*aBlockType); if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } // initialize out param *aCancel = false; *aHandled = false; - + nsresult res = WillInsert(aSelection, aCancel); NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() *aCancel = false; res = NormalizeSelection(aSelection); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); @@ -3430,22 +3430,22 @@ nsHTMLEditRules::WillMakeBasicBlock(Sele NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsEditable(arrayOfNodes[i])) { arrayOfNodes.RemoveElementAt(i); } } // reset list count listCount = arrayOfNodes.Length(); - + // if nothing visible in list, make an empty block if (ListIsEmptyLine(arrayOfNodes)) { nsCOMPtr<nsIDOMNode> theBlock; - + // get selection location NS_ENSURE_STATE(aSelection->RangeCount()); nsCOMPtr<nsINode> parent = aSelection->GetRangeAt(0)->GetStartParent(); int32_t offset = aSelection->GetRangeAt(0)->StartOffset(); NS_ENSURE_STATE(parent); if (tString.EqualsLiteral("normal") || tString.IsEmpty() ) // we are removing blocks (going to "body text") { @@ -3461,22 +3461,22 @@ nsHTMLEditRules::WillMakeBasicBlock(Sele if (nsHTMLEditUtils::IsFormatNode(curBlock)) { // if the first editable node after selection is a br, consume it. Otherwise // it gets pushed into a following block after the split, which is visually bad. nsCOMPtr<nsIDOMNode> brNode; NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetNextHTMLNode(parent->AsDOMNode(), offset, address_of(brNode)); - NS_ENSURE_SUCCESS(res, res); + NS_ENSURE_SUCCESS(res, res); if (brNode && nsTextEditUtils::IsBreak(brNode)) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->DeleteNode(brNode); - NS_ENSURE_SUCCESS(res, res); + NS_ENSURE_SUCCESS(res, res); } // do the splits! NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->SplitNodeDeep(curBlock, parent->AsDOMNode(), offset, &offset, true); NS_ENSURE_SUCCESS(res, res); // put a br at the split point NS_ENSURE_STATE(mHTMLEditor); @@ -3485,17 +3485,17 @@ nsHTMLEditRules::WillMakeBasicBlock(Sele // put selection at the split point res = aSelection->Collapse(curBlockPar, offset); selectionResetter.Abort(); // to prevent selection reseter from overriding us. *aHandled = true; } // else nothing to do! } else // we are making a block - { + { // consume a br, if needed NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<nsIContent> brNode = mHTMLEditor->GetNextHTMLNode(parent, offset, true); NS_ENSURE_SUCCESS(res, res); if (brNode && nsTextEditUtils::IsBreak(brNode)) { NS_ENSURE_STATE(mHTMLEditor); @@ -3521,36 +3521,36 @@ nsHTMLEditRules::WillMakeBasicBlock(Sele NS_ENSURE_SUCCESS(res, res); arrayOfNodes.RemoveElementAt(0); } // put selection in new block res = aSelection->Collapse(theBlock,0); selectionResetter.Abort(); // to prevent selection reseter from overriding us. *aHandled = true; } - return res; + return res; } else { - // Ok, now go through all the nodes and make the right kind of blocks, - // or whatever is approriate. Wohoo! + // Ok, now go through all the nodes and make the right kind of blocks, + // or whatever is approriate. Wohoo! // Note: blockquote is handled a little differently if (tString.EqualsLiteral("blockquote")) { res = MakeBlockquote(arrayOfNodes); } else if (tString.EqualsLiteral("normal") || tString.IsEmpty()) { res = RemoveBlockStyle(arrayOfNodes); } else { res = ApplyBlockStyle(arrayOfNodes, *blockType); } return res; } return res; } -nsresult +nsresult nsHTMLEditRules::DidMakeBasicBlock(Selection* aSelection, nsRulesInfo *aInfo, nsresult aResult) { NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER); // check for empty block. if so, put a moz br in it. if (!aSelection->Collapsed()) { return NS_OK; } @@ -3578,35 +3578,35 @@ nsHTMLEditRules::WillIndent(Selection* a return res; } nsresult nsHTMLEditRules::WillCSSIndent(Selection* aSelection, bool* aCancel, bool* aHandled) { if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } - + nsresult res = WillInsert(aSelection, aCancel); NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() *aCancel = false; *aHandled = true; res = NormalizeSelection(aSelection); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); nsTArray<OwningNonNull<nsRange>> arrayOfRanges; nsTArray<OwningNonNull<nsINode>> arrayOfNodes; - + // short circuit: detect case of collapsed selection inside an <li>. // just sublist that <li>. This prevents bug 97797. - + nsCOMPtr<Element> liNode; if (aSelection->Collapsed()) { nsCOMPtr<nsINode> node; nsCOMPtr<Element> block; int32_t offset; NS_ENSURE_STATE(mHTMLEditor); nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset); NS_ENSURE_SUCCESS(res, res); @@ -3614,17 +3614,17 @@ nsHTMLEditRules::WillCSSIndent(Selection block = node->AsElement(); } else { NS_ENSURE_STATE(mHTMLEditor); block = mHTMLEditor->GetBlockNodeParent(node); } if (block && nsHTMLEditUtils::IsListItem(block)) liNode = block; } - + if (liNode) { arrayOfNodes.AppendElement(*liNode); } else { // convert the selection ranges into "promoted" selection ranges: // this basically just expands the range to include the immediate @@ -3662,18 +3662,18 @@ nsHTMLEditRules::WillCSSIndent(Selection arrayOfNodes.RemoveElementAt(0); } // put selection in new block res = aSelection->Collapse(theBlock,0); selectionResetter.Abort(); // to prevent selection reseter from overriding us. *aHandled = true; return res; } - - // Ok, now go through all the nodes and put them in a blockquote, + + // Ok, now go through all the nodes and put them in a blockquote, // or whatever is appropriate. Wohoo! int32_t i; nsCOMPtr<nsINode> curParent; nsCOMPtr<Element> curList, curQuote; nsCOMPtr<nsIContent> sibling; int32_t listCount = arrayOfNodes.Length(); for (i=0; i<listCount; i++) { @@ -3682,17 +3682,17 @@ nsHTMLEditRules::WillCSSIndent(Selection nsCOMPtr<nsIContent> curNode = arrayOfNodes[i]->AsContent(); // Ignore all non-editable nodes. Leave them be. NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsEditable(curNode)) continue; curParent = curNode->GetParentNode(); int32_t offset = curParent ? curParent->IndexOf(curNode) : -1; - + // some logic for putting list items into nested lists... if (nsHTMLEditUtils::IsList(curParent)) { sibling = nullptr; // Check for whether we should join a list that follows curNode. // We do this if the next element is a list, and the list is of the // same type (li/ol) as curNode was a part it. @@ -3719,17 +3719,17 @@ nsHTMLEditRules::WillCSSIndent(Selection curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(curNode, sibling, -1); NS_ENSURE_SUCCESS(res, res); continue; } } sibling = nullptr; - + // check to see if curList is still appropriate. Which it is if // curNode is still right after it in the same list. if (curList) { NS_ENSURE_STATE(mHTMLEditor); sibling = mHTMLEditor->GetPriorHTMLSibling(curNode); } if (!curList || (sibling && sibling != curList)) { @@ -3746,17 +3746,17 @@ nsHTMLEditRules::WillCSSIndent(Selection mNewBlock = curList->AsDOMNode(); } // tuck the node into the end of the active list uint32_t listLen = curList->Length(); NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(curNode, curList, listLen); NS_ENSURE_SUCCESS(res, res); } - + else // not a list item { if (IsBlockNode(curNode->AsDOMNode())) { RelativeChangeIndentationOfElementNode(curNode->AsDOMNode(), +1); curQuote = nullptr; } else { if (!curQuote) @@ -3772,17 +3772,17 @@ nsHTMLEditRules::WillCSSIndent(Selection curQuote = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent, offset); NS_ENSURE_STATE(curQuote); RelativeChangeIndentationOfElementNode(curQuote->AsDOMNode(), +1); // remember our new block for postprocessing mNewBlock = curQuote->AsDOMNode(); // curQuote is now the correct thing to put curNode in } - + // tuck the node into the end of the active blockquote uint32_t quoteLen = curQuote->Length(); NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(curNode, curQuote, quoteLen); NS_ENSURE_SUCCESS(res, res); } } } @@ -3801,30 +3801,30 @@ nsHTMLEditRules::WillHTMLIndent(Selectio // we want to ignore result of WillInsert() *aCancel = false; *aHandled = true; res = NormalizeSelection(aSelection); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); - + // convert the selection ranges into "promoted" selection ranges: // this basically just expands the range to include the immediate // block parent, and then further expands to include any ancestors // whose children are all in the range - + nsTArray<nsRefPtr<nsRange>> arrayOfRanges; GetPromotedRanges(*aSelection, arrayOfRanges, EditAction::indent); - + // use these ranges to contruct a list of nodes to act on. nsTArray<OwningNonNull<nsINode>> arrayOfNodes; res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, EditAction::indent); - NS_ENSURE_SUCCESS(res, res); - + NS_ENSURE_SUCCESS(res, res); + // if nothing visible in list, make an empty block if (ListIsEmptyLine(arrayOfNodes)) { // get selection location NS_ENSURE_STATE(aSelection->RangeCount()); nsCOMPtr<nsINode> parent = aSelection->GetRangeAt(0)->GetStartParent(); int32_t offset = aSelection->GetRangeAt(0)->StartOffset(); NS_ENSURE_STATE(parent); @@ -3848,17 +3848,17 @@ nsHTMLEditRules::WillHTMLIndent(Selectio } // put selection in new block res = aSelection->Collapse(theBlock,0); selectionResetter.Abort(); // to prevent selection reseter from overriding us. *aHandled = true; return res; } - // Ok, now go through all the nodes and put them in a blockquote, + // Ok, now go through all the nodes and put them in a blockquote, // or whatever is appropriate. Wohoo! int32_t i; nsCOMPtr<nsINode> curParent; nsCOMPtr<nsIContent> sibling; nsCOMPtr<Element> curList, curQuote, indentedLI; int32_t listCount = arrayOfNodes.Length(); for (i=0; i<listCount; i++) { @@ -3867,17 +3867,17 @@ nsHTMLEditRules::WillHTMLIndent(Selectio nsCOMPtr<nsIContent> curNode = arrayOfNodes[i]->AsContent(); // Ignore all non-editable nodes. Leave them be. NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsEditable(curNode)) continue; curParent = curNode->GetParentNode(); int32_t offset = curParent ? curParent->IndexOf(curNode) : -1; - + // some logic for putting list items into nested lists... if (nsHTMLEditUtils::IsList(curParent)) { sibling = nullptr; // Check for whether we should join a list that follows curNode. // We do this if the next element is a list, and the list is of the // same type (li/ol) as curNode was a part it. @@ -3931,17 +3931,17 @@ nsHTMLEditRules::WillHTMLIndent(Selectio } // tuck the node into the end of the active list NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(curNode, curList, -1); NS_ENSURE_SUCCESS(res, res); // forget curQuote, if any curQuote = nullptr; } - + else // not a list item, use blockquote? { // if we are inside a list item, we don't want to blockquote, we want // to sublist the list item. We may have several nodes listed in the // array of nodes to act on, that are in the same list item. Since // we only want to indent that li once, we must keep track of the most // recent indented list item, and not indent it if we find another node // to act on that is still inside the same li. @@ -3956,17 +3956,17 @@ nsHTMLEditRules::WillHTMLIndent(Selectio // check to see if curList is still appropriate. Which it is if // curNode is still right after it in the same list. if (curList) { sibling = nullptr; NS_ENSURE_STATE(mHTMLEditor); sibling = mHTMLEditor->GetPriorHTMLSibling(curNode); } - + if (!curList || (sibling && sibling != curList) ) { // create a new nested list of correct type res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); curList = mHTMLEditor->CreateNode(curParent->NodeInfo()->NameAtom(), @@ -3974,45 +3974,45 @@ nsHTMLEditRules::WillHTMLIndent(Selectio NS_ENSURE_STATE(curList); } NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(listItem, curList, -1); NS_ENSURE_SUCCESS(res, res); // remember we indented this li indentedLI = listItem; } - + else { // need to make a blockquote to put things in if we haven't already, // or if this node doesn't go in blockquote we used earlier. // One reason it might not go in prio blockquote is if we are now - // in a different table cell. + // in a different table cell. if (curQuote && InDifferentTableElements(curQuote, curNode)) { curQuote = nullptr; } - - if (!curQuote) + + if (!curQuote) { // First, check that our element can contain a blockquote. if (!mEditor->CanContainTag(*curParent, *nsGkAtoms::blockquote)) { return NS_OK; // cancelled } res = SplitAsNeeded(*nsGkAtoms::blockquote, curParent, offset); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); curQuote = mHTMLEditor->CreateNode(nsGkAtoms::blockquote, curParent, offset); NS_ENSURE_STATE(curQuote); // remember our new block for postprocessing mNewBlock = curQuote->AsDOMNode(); // curQuote is now the correct thing to put curNode in } - + // tuck the node into the end of the active blockquote NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(curNode, curQuote, -1); NS_ENSURE_SUCCESS(res, res); // forget curList, if any curList = nullptr; } } @@ -4035,36 +4035,36 @@ nsHTMLEditRules::WillOutdent(Selection* bool useCSS = mHTMLEditor->IsCSSEnabled(); res = NormalizeSelection(aSelection); NS_ENSURE_SUCCESS(res, res); // some scoping for selection resetting - we may need to tweak it { NS_ENSURE_STATE(mHTMLEditor); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); - + // convert the selection ranges into "promoted" selection ranges: // this basically just expands the range to include the immediate // block parent, and then further expands to include any ancestors // whose children are all in the range nsTArray<OwningNonNull<nsINode>> arrayOfNodes; res = GetNodesFromSelection(*aSelection, EditAction::outdent, arrayOfNodes); NS_ENSURE_SUCCESS(res, res); - // Ok, now go through all the nodes and remove a level of blockquoting, + // Ok, now go through all the nodes and remove a level of blockquoting, // or whatever is appropriate. Wohoo! nsCOMPtr<nsIDOMNode> curBlockQuote, firstBQChild, lastBQChild; bool curBlockQuoteIsIndentedWithCSS = false; for (auto& curNode : arrayOfNodes) { // here's where we actually figure out what to do nsCOMPtr<nsINode> curParent = curNode->GetParentNode(); int32_t offset = curParent ? curParent->IndexOf(curNode) : -1; - + // is it a blockquote? if (curNode->IsHTMLElement(nsGkAtoms::blockquote)) { // if it is a blockquote, remove it. // So we need to finish up dealng with any curBlockQuote first. if (curBlockQuote) { res = OutdentPartOfBlock(curBlockQuote, firstBQChild, lastBQChild, curBlockQuoteIsIndentedWithCSS, @@ -4096,17 +4096,17 @@ nsHTMLEditRules::WillOutdent(Selection* mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit)); if (f > 0) { RelativeChangeIndentationOfElementNode(GetAsDOMNode(curNode), -1); continue; } } // is it a list item? - if (nsHTMLEditUtils::IsListItem(curNode)) + if (nsHTMLEditUtils::IsListItem(curNode)) { // if it is a list item, that means we are not outdenting whole list. // So we need to finish up dealing with any curBlockQuote, and then // pop this list item. if (curBlockQuote) { res = OutdentPartOfBlock(curBlockQuote, firstBQChild, lastBQChild, curBlockQuoteIsIndentedWithCSS, @@ -4128,29 +4128,29 @@ nsHTMLEditRules::WillOutdent(Selection* if (nsEditorUtils::IsDescendantOf(GetAsDOMNode(curNode), curBlockQuote)) { lastBQChild = GetAsDOMNode(curNode); continue; // then we don't need to do anything different for this node } else { // otherwise, we have progressed beyond end of curBlockQuote, - // so lets handle it now. We need to remove the portion of + // so lets handle it now. We need to remove the portion of // curBlockQuote that contains [firstBQChild - lastBQChild]. res = OutdentPartOfBlock(curBlockQuote, firstBQChild, lastBQChild, curBlockQuoteIsIndentedWithCSS, address_of(rememberedLeftBQ), address_of(rememberedRightBQ)); NS_ENSURE_SUCCESS(res, res); curBlockQuote = 0; firstBQChild = 0; lastBQChild = 0; curBlockQuoteIsIndentedWithCSS = false; // fall out and handle curNode } } - + // are we inside a blockquote? nsCOMPtr<nsINode> n = curNode; curBlockQuoteIsIndentedWithCSS = false; // keep looking up the hierarchy as long as we don't hit the body or the // active editing host or a table element (other than an entire table) while (!n->IsHTMLElement(nsGkAtoms::body) && mHTMLEditor && mHTMLEditor->IsDescendantOfEditorRoot(n) && (n->IsHTMLElement(nsGkAtoms::table) || @@ -4313,92 +4313,92 @@ nsHTMLEditRules::RemovePartOfBlock(Eleme aEndChild.AsDOMNode()); NS_ENSURE_SUCCESS(res, res); // Get rid of part of blockquote we are outdenting NS_ENSURE_STATE(mHTMLEditor); return mHTMLEditor->RemoveBlockContainer(aBlock.AsDOMNode()); } -nsresult -nsHTMLEditRules::SplitBlock(nsIDOMNode *aBlock, - nsIDOMNode *aStartChild, +nsresult +nsHTMLEditRules::SplitBlock(nsIDOMNode *aBlock, + nsIDOMNode *aStartChild, nsIDOMNode *aEndChild, nsCOMPtr<nsIDOMNode> *aLeftNode, nsCOMPtr<nsIDOMNode> *aRightNode, nsCOMPtr<nsIDOMNode> *aMiddleNode) { NS_ENSURE_TRUE(aBlock && aStartChild && aEndChild, NS_ERROR_NULL_POINTER); - + nsCOMPtr<nsIDOMNode> leftNode, rightNode; int32_t startOffset, endOffset, offset; nsresult res; // get split point location nsCOMPtr<nsIDOMNode> startParent = nsEditor::GetNodeLocation(aStartChild, &startOffset); - + // do the splits! NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->SplitNodeDeep(aBlock, startParent, startOffset, &offset, + res = mHTMLEditor->SplitNodeDeep(aBlock, startParent, startOffset, &offset, true, address_of(leftNode), address_of(rightNode)); NS_ENSURE_SUCCESS(res, res); if (rightNode) aBlock = rightNode; // remember left portion of block if caller requested - if (aLeftNode) + if (aLeftNode) *aLeftNode = leftNode; // get split point location nsCOMPtr<nsIDOMNode> endParent = nsEditor::GetNodeLocation(aEndChild, &endOffset); endOffset++; // want to be after lastBQChild // do the splits! NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->SplitNodeDeep(aBlock, endParent, endOffset, &offset, + res = mHTMLEditor->SplitNodeDeep(aBlock, endParent, endOffset, &offset, true, address_of(leftNode), address_of(rightNode)); NS_ENSURE_SUCCESS(res, res); if (leftNode) aBlock = leftNode; - + // remember right portion of block if caller requested - if (aRightNode) + if (aRightNode) *aRightNode = rightNode; if (aMiddleNode) *aMiddleNode = aBlock; return NS_OK; } nsresult -nsHTMLEditRules::OutdentPartOfBlock(nsIDOMNode *aBlock, - nsIDOMNode *aStartChild, +nsHTMLEditRules::OutdentPartOfBlock(nsIDOMNode *aBlock, + nsIDOMNode *aStartChild, nsIDOMNode *aEndChild, bool aIsBlockIndentedWithCSS, nsCOMPtr<nsIDOMNode> *aLeftNode, nsCOMPtr<nsIDOMNode> *aRightNode) { nsCOMPtr<nsIDOMNode> middleNode; - nsresult res = SplitBlock(aBlock, aStartChild, aEndChild, + nsresult res = SplitBlock(aBlock, aStartChild, aEndChild, aLeftNode, aRightNode, address_of(middleNode)); NS_ENSURE_SUCCESS(res, res); if (aIsBlockIndentedWithCSS) { res = RelativeChangeIndentationOfElementNode(middleNode, -1); } else { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->RemoveBlockContainer(middleNode); } return res; } /////////////////////////////////////////////////////////////////////////// // ConvertListType: convert list type and list item type. -// -// +// +// nsresult nsHTMLEditRules::ConvertListType(nsIDOMNode* aList, nsCOMPtr<nsIDOMNode>* outList, nsIAtom* aListType, nsIAtom* aItemType) { MOZ_ASSERT(aListType); MOZ_ASSERT(aItemType); @@ -4583,41 +4583,41 @@ nsHTMLEditRules::CreateStyleForInsertTex return NS_OK; } /////////////////////////////////////////////////////////////////////////// // IsEmptyBlock: figure out if aNode is (or is inside) an empty block. // A block can have children and still be considered empty, // if the children are empty or non-editable. -// -nsresult -nsHTMLEditRules::IsEmptyBlock(nsIDOMNode *aNode, - bool *outIsEmptyBlock, +// +nsresult +nsHTMLEditRules::IsEmptyBlock(nsIDOMNode *aNode, + bool *outIsEmptyBlock, bool aMozBRDoesntCount, - bool aListItemsNotEmpty) + bool aListItemsNotEmpty) { NS_ENSURE_TRUE(aNode && outIsEmptyBlock, NS_ERROR_NULL_POINTER); *outIsEmptyBlock = true; - + // nsresult res = NS_OK; nsCOMPtr<nsIDOMNode> nodeToTest; if (IsBlockNode(aNode)) nodeToTest = do_QueryInterface(aNode); // else nsCOMPtr<nsIDOMElement> block; // looks like I forgot to finish this. Wonder what I was going to do? NS_ENSURE_TRUE(nodeToTest, NS_ERROR_NULL_POINTER); return mHTMLEditor->IsEmptyNode(nodeToTest, outIsEmptyBlock, aMozBRDoesntCount, aListItemsNotEmpty); } nsresult nsHTMLEditRules::WillAlign(Selection* aSelection, - const nsAString *alignType, + const nsAString *alignType, bool *aCancel, bool *aHandled) { if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); NS_ENSURE_SUCCESS(res, res); @@ -4699,17 +4699,17 @@ nsHTMLEditRules::WillAlign(Selection* aS // creating extra lines, if possible. NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetNextHTMLNode(parent->AsDOMNode(), offset, address_of(brNode)); NS_ENSURE_SUCCESS(res, res); if (brNode && nsTextEditUtils::IsBreak(brNode)) { // making use of html structure... if next node after where - // we are putting our div is not a block, then the br we + // we are putting our div is not a block, then the br we // found is in same block we are, so its safe to consume it. NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetNextHTMLSibling(parent->AsDOMNode(), offset, address_of(sib)); NS_ENSURE_SUCCESS(res, res); if (!IsBlockNode(sib)) { NS_ENSURE_STATE(mHTMLEditor); @@ -4737,17 +4737,17 @@ nsHTMLEditRules::WillAlign(Selection* aS } // Next we detect all the transitions in the array, where a transition // means that adjacent nodes in the array don't have the same parent. nsTArray<bool> transitionList; MakeTransitionList(nodeArray, transitionList); - // Ok, now go through all the nodes and give them an align attrib or put them in a div, + // Ok, now go through all the nodes and give them an align attrib or put them in a div, // or whatever is appropriate. Wohoo! nsCOMPtr<nsINode> curParent; nsCOMPtr<Element> curDiv; bool useCSS = mHTMLEditor->IsCSSEnabled(); for (int32_t i = 0; i < listCount; ++i) { // here's where we actually figure out what to do nsCOMPtr<nsIDOMNode> curNode = nodeArray[i]->AsDOMNode(); @@ -4806,17 +4806,17 @@ nsHTMLEditRules::WillAlign(Selection* aS // if we don't use CSS, add a contraint to list element : they have // to be inside another list, ie >= second level of nesting res = AlignInnerBlocks(*curContent, alignType); NS_ENSURE_SUCCESS(res, res); curDiv = 0; continue; } // clear out curDiv so that we don't put nodes after this one into it - } + } // need to make a div to put things in if we haven't already, // or if this node doesn't go in div we used earlier. if (!curDiv || transitionList[i]) { // First, check that our element can contain a div. if (!mEditor->CanContainTag(*curParent, *nsGkAtoms::div)) { return NS_OK; // cancelled @@ -4869,26 +4869,26 @@ nsHTMLEditRules::AlignInnerBlocks(nsINod } return NS_OK; } /////////////////////////////////////////////////////////////////////////// // AlignBlockContents: align contents of a block element -// +// nsresult nsHTMLEditRules::AlignBlockContents(nsIDOMNode *aNode, const nsAString *alignType) { nsCOMPtr<nsINode> node = do_QueryInterface(aNode); NS_ENSURE_TRUE(node && alignType, NS_ERROR_NULL_POINTER); nsresult res = NS_OK; nsCOMPtr<nsIContent> firstChild, lastChild; nsCOMPtr<Element> divNode; - + bool useCSS = mHTMLEditor->IsCSSEnabled(); NS_ENSURE_STATE(mHTMLEditor); firstChild = mHTMLEditor->GetFirstEditableChild(*node); NS_ENSURE_STATE(mHTMLEditor); lastChild = mHTMLEditor->GetLastEditableChild(*node); NS_NAMED_LITERAL_STRING(attr, "align"); if (!firstChild) @@ -4896,17 +4896,17 @@ nsHTMLEditRules::AlignBlockContents(nsID // this cell has no content, nothing to align } else if (firstChild == lastChild && firstChild->IsHTMLElement(nsGkAtoms::div)) { // the cell already has a div containing all of its content: just // act on this div. nsCOMPtr<nsIDOMElement> divElem = do_QueryInterface(firstChild); if (useCSS) { NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->SetAttributeOrEquivalent(divElem, attr, *alignType, false); + res = mHTMLEditor->SetAttributeOrEquivalent(divElem, attr, *alignType, false); } else { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->SetAttribute(divElem, attr, *alignType); } NS_ENSURE_SUCCESS(res, res); } else @@ -4914,17 +4914,17 @@ nsHTMLEditRules::AlignBlockContents(nsID // else we need to put in a div, set the alignment, and toss in all the children NS_ENSURE_STATE(mHTMLEditor); divNode = mHTMLEditor->CreateNode(nsGkAtoms::div, node, 0); NS_ENSURE_STATE(divNode); // set up the alignment on the div nsCOMPtr<nsIDOMElement> divElem = do_QueryInterface(divNode); if (useCSS) { NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->SetAttributeOrEquivalent(divElem, attr, *alignType, false); + res = mHTMLEditor->SetAttributeOrEquivalent(divElem, attr, *alignType, false); } else { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->SetAttribute(divElem, attr, *alignType); } NS_ENSURE_SUCCESS(res, res); // tuck the children into the end of the active div while (lastChild && (lastChild != divNode)) @@ -5020,18 +5020,18 @@ nsHTMLEditRules::CheckForEmptyBlock(nsIN res = mHTMLEditor->DeleteNode(emptyBlock); *aHandled = true; NS_ENSURE_SUCCESS(res, res); } return NS_OK; } nsresult -nsHTMLEditRules::CheckForInvisibleBR(nsIDOMNode *aBlock, - BRLocation aWhere, +nsHTMLEditRules::CheckForInvisibleBR(nsIDOMNode *aBlock, + BRLocation aWhere, nsCOMPtr<nsIDOMNode> *outBRNode, int32_t aOffset) { nsCOMPtr<nsINode> block = do_QueryInterface(aBlock); NS_ENSURE_TRUE(block && outBRNode, NS_ERROR_NULL_POINTER); *outBRNode = nullptr; nsCOMPtr<nsIDOMNode> testNode; @@ -5102,40 +5102,40 @@ nsHTMLEditRules::GetInnerContent(nsINode (*aIndex)++; } } } /////////////////////////////////////////////////////////////////////////// // ExpandSelectionForDeletion: this promotes our selection to include blocks // that have all their children selected. -// +// nsresult nsHTMLEditRules::ExpandSelectionForDeletion(Selection* aSelection) { NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER); - + // don't need to touch collapsed selections if (aSelection->Collapsed()) { return NS_OK; } int32_t rangeCount; nsresult res = aSelection->GetRangeCount(&rangeCount); NS_ENSURE_SUCCESS(res, res); - + // we don't need to mess with cell selections, and we assume multirange selections are those. if (rangeCount != 1) return NS_OK; - + // find current sel start and end nsRefPtr<nsRange> range = aSelection->GetRangeAt(0); NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER); nsCOMPtr<nsIDOMNode> selStartNode, selEndNode, selCommon; int32_t selStartOffset, selEndOffset; - + res = range->GetStartContainer(getter_AddRefs(selStartNode)); NS_ENSURE_SUCCESS(res, res); res = range->GetStartOffset(&selStartOffset); NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(selEndNode)); NS_ENSURE_SUCCESS(res, res); res = range->GetEndOffset(&selEndOffset); NS_ENSURE_SUCCESS(res, res); @@ -5170,45 +5170,45 @@ nsHTMLEditRules::ExpandSelectionForDelet // we want to keep looking up. But stop if we are crossing table element // boundaries, or if we hit the root. if (nsHTMLEditUtils::IsTableElement(wsObj.mStartReasonNode) || selCommon == GetAsDOMNode(wsObj.mStartReasonNode) || rootElement == GetAsDOMNode(wsObj.mStartReasonNode)) { stillLooking = false; } else - { + { selStartNode = nsEditor::GetNodeLocation(GetAsDOMNode(wsObj.mStartReasonNode), &selStartOffset); } } else { stillLooking = false; } } } - + stillLooking = true; // find next visible thingy after end of selection if ((selEndNode!=selCommon) && (selEndNode!=rootElement)) { while (stillLooking) { nsWSRunObject wsObj(mHTMLEditor, selEndNode, selEndOffset); nsCOMPtr<nsINode> selEndNode_(do_QueryInterface(selEndNode)); wsObj.NextVisibleNode(selEndNode_, selEndOffset, address_of(unused), &visOffset, &wsType); if (wsType == WSType::br) { if (mHTMLEditor->IsVisBreak(wsObj.mEndReasonNode)) { stillLooking = false; } else - { + { if (!firstBRParent) { firstBRParent = selEndNode; firstBROffset = selEndOffset; } selEndNode = nsEditor::GetNodeLocation(GetAsDOMNode(wsObj.mEndReasonNode), &selEndOffset); ++selEndOffset; } @@ -5216,122 +5216,122 @@ nsHTMLEditRules::ExpandSelectionForDelet // we want to keep looking up. But stop if we are crossing table element // boundaries, or if we hit the root. if (nsHTMLEditUtils::IsTableElement(wsObj.mEndReasonNode) || selCommon == GetAsDOMNode(wsObj.mEndReasonNode) || rootElement == GetAsDOMNode(wsObj.mEndReasonNode)) { stillLooking = false; } else - { + { selEndNode = nsEditor::GetNodeLocation(GetAsDOMNode(wsObj.mEndReasonNode), &selEndOffset); ++selEndOffset; } } else { stillLooking = false; } } } // now set the selection to the new range aSelection->Collapse(selStartNode, selStartOffset); - + // expand selection endpoint only if we didnt pass a br, - // or if we really needed to pass that br (ie, its block is now + // or if we really needed to pass that br (ie, its block is now // totally selected) bool doEndExpansion = true; if (firstBRParent) { // find block node containing br nsCOMPtr<nsIDOMNode> brBlock = firstBRParent; if (!IsBlockNode(brBlock)) brBlock = nsHTMLEditor::GetBlockNodeParent(brBlock); bool nodeBefore=false, nodeAfter=false; - + // create a range that represents expanded selection nsCOMPtr<nsINode> node = do_QueryInterface(selStartNode); NS_ENSURE_STATE(node); nsRefPtr<nsRange> range = new nsRange(node); res = range->SetStart(selStartNode, selStartOffset); NS_ENSURE_SUCCESS(res, res); res = range->SetEnd(selEndNode, selEndOffset); NS_ENSURE_SUCCESS(res, res); - + // check if block is entirely inside range nsCOMPtr<nsIContent> brContentBlock = do_QueryInterface(brBlock); if (brContentBlock) { res = nsRange::CompareNodeToRange(brContentBlock, range, &nodeBefore, &nodeAfter); } - + // if block isn't contained, forgo grabbing the br in the expanded selection if (nodeBefore || nodeAfter) doEndExpansion = false; } if (doEndExpansion) { res = aSelection->Extend(selEndNode, selEndOffset); } else { // only expand to just before br res = aSelection->Extend(firstBRParent, firstBROffset); } - + return res; } /////////////////////////////////////////////////////////////////////////// // NormalizeSelection: tweak non-collapsed selections to be more "natural". // Idea here is to adjust selection endpoint so that they do not cross // breaks or block boundaries unless something editable beyond that boundary // is also selected. This adjustment makes it much easier for the various // block operations to determine what nodes to act on. -// -nsresult +// +nsresult nsHTMLEditRules::NormalizeSelection(Selection* inSelection) { NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER); // don't need to touch collapsed selections if (inSelection->Collapsed()) { return NS_OK; } int32_t rangeCount; nsresult res = inSelection->GetRangeCount(&rangeCount); NS_ENSURE_SUCCESS(res, res); - + // we don't need to mess with cell selections, and we assume multirange selections are those. if (rangeCount != 1) return NS_OK; - + nsRefPtr<nsRange> range = inSelection->GetRangeAt(0); NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER); nsCOMPtr<nsIDOMNode> startNode, endNode; int32_t startOffset, endOffset; nsCOMPtr<nsIDOMNode> newStartNode, newEndNode; int32_t newStartOffset, newEndOffset; - + res = range->GetStartContainer(getter_AddRefs(startNode)); NS_ENSURE_SUCCESS(res, res); res = range->GetStartOffset(&startOffset); NS_ENSURE_SUCCESS(res, res); res = range->GetEndContainer(getter_AddRefs(endNode)); NS_ENSURE_SUCCESS(res, res); res = range->GetEndOffset(&endOffset); NS_ENSURE_SUCCESS(res, res); - + // adjusted values default to original values - newStartNode = startNode; + newStartNode = startNode; newStartOffset = startOffset; - newEndNode = endNode; + newEndNode = endNode; newEndOffset = endOffset; - + // some locals we need for whitespace code nsCOMPtr<nsINode> unused; int32_t offset; WSType wsType; // let the whitespace code do the heavy lifting nsWSRunObject wsEndObj(mHTMLEditor, endNode, endOffset); // is there any intervening visible whitespace? if so we can't push selection past that, @@ -5365,18 +5365,18 @@ nsHTMLEditRules::NormalizeSelection(Sele } // else block is empty - we can leave selection alone here, i think. } else if (wsEndObj.mStartReason == WSType::br) { // endpoint is just after break. lets adjust it to before it. newEndNode = nsEditor::GetNodeLocation(GetAsDOMNode(wsEndObj.mStartReasonNode), &newEndOffset); } } - - + + // similar dealio for start of range nsWSRunObject wsStartObj(mHTMLEditor, startNode, startOffset); // is there any intervening visible whitespace? if so we can't push selection past that, // it would visibly change maening of users selection nsCOMPtr<nsINode> startNode_(do_QueryInterface(startNode)); wsStartObj.NextVisibleNode(startNode_, startOffset, address_of(unused), &offset, &wsType); if (wsType != WSType::text && wsType != WSType::normalWS) { @@ -5404,34 +5404,34 @@ nsHTMLEditRules::NormalizeSelection(Sele // else block is empty - we can leave selection alone here, i think. } else if (wsStartObj.mEndReason == WSType::br) { // startpoint is just before a break. lets adjust it to after it. newStartNode = nsEditor::GetNodeLocation(GetAsDOMNode(wsStartObj.mEndReasonNode), &newStartOffset); ++newStartOffset; // offset *after* break } } - + // there is a demented possiblity we have to check for. We might have a very strange selection // that is not collapsed and yet does not contain any editable content, and satisfies some of the // above conditions that cause tweaking. In this case we don't want to tweak the selection into // a block it was never in, etc. There are a variety of strategies one might use to try to // detect these cases, but I think the most straightforward is to see if the adjusted locations - // "cross" the old values: ie, new end before old start, or new start after old end. If so + // "cross" the old values: ie, new end before old start, or new start after old end. If so // then just leave things alone. - + int16_t comp; comp = nsContentUtils::ComparePoints(startNode, startOffset, newEndNode, newEndOffset); if (comp == 1) return NS_OK; // new end before old start comp = nsContentUtils::ComparePoints(newStartNode, newStartOffset, endNode, endOffset); if (comp == 1) return NS_OK; // new start after old end - - // otherwise set selection to new values. + + // otherwise set selection to new values. inSelection->Collapse(newStartNode, newStartOffset); inSelection->Extend(newEndNode, newEndOffset); return NS_OK; } /////////////////////////////////////////////////////////////////////////// // GetPromotedPoint: figure out where a start or end point for a block @@ -5993,18 +5993,18 @@ nsHTMLEditRules::LookInsideDivBQandList( return; } aNodeArray.AppendElement(*curNode); } /////////////////////////////////////////////////////////////////////////// -// GetDefinitionListItemTypes: -// +// GetDefinitionListItemTypes: +// void nsHTMLEditRules::GetDefinitionListItemTypes(dom::Element* aElement, bool* aDT, bool* aDD) { MOZ_ASSERT(aElement); MOZ_ASSERT(aElement->IsHTMLElement(nsGkAtoms::dl)); MOZ_ASSERT(aDT); MOZ_ASSERT(aDD); @@ -6056,27 +6056,27 @@ nsHTMLEditRules::GetParagraphFormatNodes GetInnerContent(testNode, outArrayOfNodes, &j); } } return NS_OK; } /////////////////////////////////////////////////////////////////////////// -// BustUpInlinesAtRangeEndpoints: -// -nsresult +// BustUpInlinesAtRangeEndpoints: +// +nsresult nsHTMLEditRules::BustUpInlinesAtRangeEndpoints(nsRangeStore &item) { nsresult res = NS_OK; bool isCollapsed = ((item.startNode == item.endNode) && (item.startOffset == item.endOffset)); nsCOMPtr<nsIDOMNode> endInline = GetHighestInlineParent(GetAsDOMNode(item.endNode)); - + // if we have inline parents above range endpoints, split them if (endInline && !isCollapsed) { nsCOMPtr<nsIDOMNode> resultEndNode; int32_t resultEndOffset; endInline->GetParentNode(getter_AddRefs(resultEndNode)); NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->SplitNodeDeep(endInline, GetAsDOMNode(item.endNode), @@ -6099,17 +6099,17 @@ nsHTMLEditRules::BustUpInlinesAtRangeEnd res = mHTMLEditor->SplitNodeDeep(startInline, GetAsDOMNode(item.startNode), item.startOffset, &resultStartOffset, true); NS_ENSURE_SUCCESS(res, res); // reset range item.startNode = do_QueryInterface(resultStartNode); item.startOffset = resultStartOffset; } - + return res; } nsresult nsHTMLEditRules::BustUpInlinesAtBRs(nsINode& aNode, nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes) @@ -6169,17 +6169,17 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIN nsCOMPtr<nsINode> rightNode = do_QueryInterface(rightDOMNode); NS_ENSURE_STATE(rightNode); aOutArrayOfNodes.AppendElement(*rightNode); } return NS_OK; } -nsCOMPtr<nsIDOMNode> +nsCOMPtr<nsIDOMNode> nsHTMLEditRules::GetHighestInlineParent(nsIDOMNode* aNode) { NS_ENSURE_TRUE(aNode, nullptr); if (IsBlockNode(aNode)) return nullptr; nsCOMPtr<nsIDOMNode> inlineNode, node=aNode; while (node && IsInlineNode(node)) { @@ -6267,25 +6267,25 @@ nsHTMLEditRules::MakeTransitionList(nsTA } prevParent = aNodeArray[i]->GetParentNode(); } } /******************************************************** - * main implementation methods + * main implementation methods ********************************************************/ - + /////////////////////////////////////////////////////////////////////////// // IsInListItem: if aNode is the descendant of a listitem, return that li. // But table element boundaries are stoppers on the search. // Also stops on the active editor host (contenteditable). // Also test if aNode is an li itself. -// +// already_AddRefed<nsIDOMNode> nsHTMLEditRules::IsInListItem(nsIDOMNode* aNode) { nsCOMPtr<nsINode> node = do_QueryInterface(aNode); nsCOMPtr<nsIDOMNode> retval = do_QueryInterface(IsInListItem(node)); return retval.forget(); } @@ -6306,25 +6306,25 @@ nsHTMLEditRules::IsInListItem(nsINode* a parent = parent->GetParentElement(); } return nullptr; } /////////////////////////////////////////////////////////////////////////// // ReturnInHeader: do the right thing for returns pressed in headers -// -nsresult -nsHTMLEditRules::ReturnInHeader(Selection* aSelection, - nsIDOMNode *aHeader, - nsIDOMNode *aNode, +// +nsresult +nsHTMLEditRules::ReturnInHeader(Selection* aSelection, + nsIDOMNode *aHeader, + nsIDOMNode *aNode, int32_t aOffset) { - NS_ENSURE_TRUE(aSelection && aHeader && aNode, NS_ERROR_NULL_POINTER); - + NS_ENSURE_TRUE(aSelection && aHeader && aNode, NS_ERROR_NULL_POINTER); + // remeber where the header is int32_t offset; nsCOMPtr<nsIDOMNode> headerParent = nsEditor::GetNodeLocation(aHeader, &offset); // get ws code to adjust any ws nsCOMPtr<nsINode> selNode(do_QueryInterface(aNode)); NS_ENSURE_STATE(mHTMLEditor); nsresult res = nsWSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor, @@ -6348,17 +6348,17 @@ nsHTMLEditRules::ReturnInHeader(Selectio NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->IsEmptyNode(prevItem, &bIsEmptyNode); NS_ENSURE_SUCCESS(res, res); if (bIsEmptyNode) { res = CreateMozBR(prevItem, 0); NS_ENSURE_SUCCESS(res, res); } } - + // if the new (righthand) header node is empty, delete it bool isEmpty; res = IsEmptyBlock(aHeader, &isEmpty, true); NS_ENSURE_SUCCESS(res, res); if (isEmpty) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->DeleteNode(aHeader); @@ -6510,27 +6510,27 @@ nsHTMLEditRules::ReturnInParagraph(Selec } nsCOMPtr<nsIDOMNode> selNode = aNode; *aHandled = true; return SplitParagraph(aPara, sibling, aSelection, address_of(selNode), &aOffset); } /////////////////////////////////////////////////////////////////////////// // SplitParagraph: split a paragraph at selection point, possibly deleting a br -// -nsresult +// +nsresult nsHTMLEditRules::SplitParagraph(nsIDOMNode *aPara, - nsIDOMNode *aBRNode, + nsIDOMNode *aBRNode, Selection* aSelection, - nsCOMPtr<nsIDOMNode> *aSelNode, + nsCOMPtr<nsIDOMNode> *aSelNode, int32_t *aOffset) { NS_ENSURE_TRUE(aPara && aBRNode && aSelNode && *aSelNode && aOffset && aSelection, NS_ERROR_NULL_POINTER); nsresult res = NS_OK; - + // split para int32_t newOffset; // get ws code to adjust any ws nsCOMPtr<nsIDOMNode> leftPara, rightPara; NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<nsINode> selNode(do_QueryInterface(*aSelNode)); res = nsWSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor, address_of(selNode), aOffset); *aSelNode = GetAsDOMNode(selNode); @@ -6540,17 +6540,17 @@ nsHTMLEditRules::SplitParagraph(nsIDOMNo res = mHTMLEditor->SplitNodeDeep(aPara, *aSelNode, *aOffset, &newOffset, false, address_of(leftPara), address_of(rightPara)); NS_ENSURE_SUCCESS(res, res); // get rid of the break, if it is visible (otherwise it may be needed to prevent an empty p) NS_ENSURE_STATE(mHTMLEditor); if (mHTMLEditor->IsVisBreak(aBRNode)) { NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->DeleteNode(aBRNode); + res = mHTMLEditor->DeleteNode(aBRNode); NS_ENSURE_SUCCESS(res, res); } // remove ID attribute on the paragraph we just created nsCOMPtr<nsIDOMElement> rightElt = do_QueryInterface(rightPara); NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->RemoveAttribute(rightElt, NS_LITERAL_STRING("id")); NS_ENSURE_SUCCESS(res, res); @@ -6581,33 +6581,33 @@ nsHTMLEditRules::SplitParagraph(nsIDOMNo aSelection->Collapse(parent,offset); } return res; } /////////////////////////////////////////////////////////////////////////// // ReturnInListItem: do the right thing for returns pressed in list items -// -nsresult -nsHTMLEditRules::ReturnInListItem(Selection* aSelection, - nsIDOMNode *aListItem, - nsIDOMNode *aNode, +// +nsresult +nsHTMLEditRules::ReturnInListItem(Selection* aSelection, + nsIDOMNode *aListItem, + nsIDOMNode *aNode, int32_t aOffset) { nsCOMPtr<Element> listItem = do_QueryInterface(aListItem); NS_ENSURE_TRUE(aSelection && listItem && aNode, NS_ERROR_NULL_POINTER); nsresult res = NS_OK; - + nsCOMPtr<nsIDOMNode> listitem; - + // sanity check NS_PRECONDITION(true == nsHTMLEditUtils::IsListItem(aListItem), "expected a list item and didn't get one"); - + // get the listitem parent and the active editing host. NS_ENSURE_STATE(mHTMLEditor); nsIContent* rootContent = mHTMLEditor->GetActiveEditingHost(); nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(rootContent); nsCOMPtr<nsINode> list = listItem->GetParentNode(); int32_t itemOffset = list ? list->IndexOf(listItem) : -1; // if we are in an empty listitem, then we want to pop up out of the list @@ -6665,17 +6665,17 @@ nsHTMLEditRules::ReturnInListItem(Select res = mHTMLEditor->CreateBR(pNode, 0, address_of(brNode)); NS_ENSURE_SUCCESS(res, res); // set selection to before the break res = aSelection->Collapse(pNode, 0); } return res; } - + // else we want a new list item at the same list level. // get ws code to adjust any ws nsCOMPtr<nsINode> selNode(do_QueryInterface(aNode)); NS_ENSURE_STATE(mHTMLEditor); res = nsWSRunObject::PrepareToSplitAcrossBlocks(mHTMLEditor, address_of(selNode), &aOffset); NS_ENSURE_SUCCESS(res, res); // now split list item int32_t newOffset; @@ -6697,17 +6697,17 @@ nsHTMLEditRules::ReturnInListItem(Select NS_ENSURE_SUCCESS(res, res); if (bIsEmptyNode) { res = CreateMozBR(prevItem, 0); NS_ENSURE_SUCCESS(res, res); } else { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->IsEmptyNode(aListItem, &bIsEmptyNode, true); NS_ENSURE_SUCCESS(res, res); - if (bIsEmptyNode) + if (bIsEmptyNode) { nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aListItem); if (nodeAtom == nsGkAtoms::dd || nodeAtom == nsGkAtoms::dt) { int32_t itemOffset; nsCOMPtr<nsIDOMNode> list = nsEditor::GetNodeLocation(aListItem, &itemOffset); nsAutoString listTag(nodeAtom == nsGkAtoms::dt ? NS_LITERAL_STRING("dd") : NS_LITERAL_STRING("dt")); @@ -6719,17 +6719,17 @@ nsHTMLEditRules::ReturnInListItem(Select NS_ENSURE_SUCCESS(res, res); return aSelection->Collapse(newListItem, 0); } nsCOMPtr<nsIDOMNode> brNode; NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->CopyLastEditableChildStyles(prevItem, aListItem, getter_AddRefs(brNode)); NS_ENSURE_SUCCESS(res, res); - if (brNode) + if (brNode) { int32_t offset; nsCOMPtr<nsIDOMNode> brParent = nsEditor::GetNodeLocation(brNode, &offset); return aSelection->Collapse(brParent, offset); } } else { @@ -7171,17 +7171,17 @@ nsHTMLEditRules::GetTopEnclosingMailCite break; } } return ret; } -nsresult +nsresult nsHTMLEditRules::CacheInlineStyles(nsIDOMNode *aNode) { NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); NS_ENSURE_STATE(mHTMLEditor); bool useCSS = mHTMLEditor->IsCSSEnabled(); for (int32_t j = 0; j < SIZE_STYLE_TABLE; ++j) @@ -7307,61 +7307,61 @@ nsHTMLEditRules::AdjustSpecialBreaks() // still pass the "IsEmptyNode" test, and we want the br's to be after // them. Also, we want the br to be after the selection if the selection // is in this node. nsresult res = CreateMozBR(node->AsDOMNode(), (int32_t)node->Length()); NS_ENSURE_SUCCESS(res, ); } } -nsresult +nsresult nsHTMLEditRules::AdjustWhitespace(Selection* aSelection) { // get selection point nsCOMPtr<nsIDOMNode> selNode; int32_t selOffset; NS_ENSURE_STATE(mHTMLEditor); nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); NS_ENSURE_SUCCESS(res, res); - + // ask whitespace object to tweak nbsp's NS_ENSURE_STATE(mHTMLEditor); return nsWSRunObject(mHTMLEditor, selNode, selOffset).AdjustWhitespace(); } -nsresult +nsresult nsHTMLEditRules::PinSelectionToNewBlock(Selection* aSelection) { NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER); if (!aSelection->Collapsed()) { return NS_OK; } // get the (collapsed) selection location nsCOMPtr<nsIDOMNode> selNode, temp; int32_t selOffset; NS_ENSURE_STATE(mHTMLEditor); nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); NS_ENSURE_SUCCESS(res, res); temp = selNode; - + // use ranges and sRangeHelper to compare sel point to new block nsCOMPtr<nsINode> node = do_QueryInterface(selNode); NS_ENSURE_STATE(node); nsRefPtr<nsRange> range = new nsRange(node); res = range->SetStart(selNode, selOffset); NS_ENSURE_SUCCESS(res, res); res = range->SetEnd(selNode, selOffset); NS_ENSURE_SUCCESS(res, res); nsCOMPtr<nsIContent> block (do_QueryInterface(mNewBlock)); NS_ENSURE_TRUE(block, NS_ERROR_NO_INTERFACE); bool nodeBefore, nodeAfter; res = nsRange::CompareNodeToRange(block, range, &nodeBefore, &nodeAfter); NS_ENSURE_SUCCESS(res, res); - + if (nodeBefore && nodeAfter) return NS_OK; // selection is inside block else if (nodeBefore) { // selection is after block. put at end of block. nsCOMPtr<nsIDOMNode> tmp = mNewBlock; NS_ENSURE_STATE(mHTMLEditor); tmp = GetAsDOMNode(mHTMLEditor->GetLastEditableChild(*block)); @@ -7393,17 +7393,17 @@ nsHTMLEditRules::PinSelectionToNewBlock( { tmp = nsEditor::GetNodeLocation(tmp, &offset); } NS_ENSURE_STATE(mHTMLEditor); return aSelection->Collapse(tmp, 0); } } -nsresult +nsresult nsHTMLEditRules::CheckInterlinePosition(Selection* aSelection) { NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER); // if the selection isn't collapsed, do nothing. if (!aSelection->Collapsed()) { return NS_OK; } @@ -7438,48 +7438,48 @@ nsHTMLEditRules::CheckInterlinePosition( // are we before a block? If so try set caret to prior content NS_ENSURE_STATE(mHTMLEditor); mHTMLEditor->GetNextHTMLSibling(selNode, selOffset, address_of(node)); if (node && IsBlockNode(node)) aSelection->SetInterlinePosition(false); return NS_OK; } -nsresult +nsresult nsHTMLEditRules::AdjustSelection(Selection* aSelection, nsIEditor::EDirection aAction) { NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER); - + // if the selection isn't collapsed, do nothing. // moose: one thing to do instead is check for the case of // only a single break selected, and collapse it. Good thing? Beats me. if (!aSelection->Collapsed()) { return NS_OK; } // get the (collapsed) selection location nsCOMPtr<nsINode> selNode, temp; int32_t selOffset; NS_ENSURE_STATE(mHTMLEditor); nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); NS_ENSURE_SUCCESS(res, res); temp = selNode; - + // are we in an editable node? NS_ENSURE_STATE(mHTMLEditor); while (!mHTMLEditor->IsEditable(selNode)) { // scan up the tree until we find an editable place to be selNode = nsEditor::GetNodeLocation(temp, &selOffset); NS_ENSURE_TRUE(selNode, NS_ERROR_FAILURE); temp = selNode; NS_ENSURE_STATE(mHTMLEditor); } - + // make sure we aren't in an empty block - user will see no cursor. If this // is happening, put a <br> in the block if allowed. nsCOMPtr<nsINode> theblock; if (IsBlockNode(GetAsDOMNode(selNode))) { theblock = selNode; } else { NS_ENSURE_STATE(mHTMLEditor); theblock = mHTMLEditor->GetBlockNodeParent(selNode); @@ -7503,45 +7503,45 @@ nsHTMLEditRules::AdjustSelection(Selecti // CreateBogusNodeIfNeeded()! return NS_OK; } // we know we can skip the rest of this routine given the cirumstance return CreateMozBR(GetAsDOMNode(selNode), selOffset); } } - - // are we in a text node? + + // are we in a text node? nsCOMPtr<nsIDOMCharacterData> textNode = do_QueryInterface(selNode); if (textNode) return NS_OK; // we LIKE it when we are in a text node. that RULZ - + // do we need to insert a special mozBR? We do if we are: // 1) prior node is in same block where selection is AND // 2) prior node is a br AND // 3) that br is not visible NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<nsIContent> nearNode = mHTMLEditor->GetPriorHTMLNode(selNode, selOffset); - if (nearNode) + if (nearNode) { // is nearNode also a descendant of same block? nsCOMPtr<nsINode> block, nearBlock; if (IsBlockNode(GetAsDOMNode(selNode))) { block = selNode; } else { NS_ENSURE_STATE(mHTMLEditor); block = mHTMLEditor->GetBlockNodeParent(selNode); } NS_ENSURE_STATE(mHTMLEditor); nearBlock = mHTMLEditor->GetBlockNodeParent(nearNode); if (block && block == nearBlock) { if (nearNode && nsTextEditUtils::IsBreak(nearNode) ) - { + { NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsVisBreak(nearNode)) { // need to insert special moz BR. Why? Because if we don't // the user will see no new line for the break. Also, things // like table cells won't grow in height. nsCOMPtr<nsIDOMNode> brNode; res = CreateMozBR(GetAsDOMNode(selNode), selOffset, @@ -7557,17 +7557,17 @@ nsHTMLEditRules::AdjustSelection(Selecti else { NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<nsIContent> nextNode = mHTMLEditor->GetNextHTMLNode(nearNode, true); if (nextNode && nsTextEditUtils::IsMozBR(nextNode)) { // selection between br and mozbr. make it stick to mozbr - // so that it will be on blank line. + // so that it will be on blank line. aSelection->SetInterlinePosition(true); } } } } } // we aren't in a textnode: are we adjacent to text or a break or an image? @@ -7616,52 +7616,52 @@ nsHTMLEditRules::AdjustSelection(Selecti res = aSelection->Collapse(selNode, selOffset); } } return res; } nsresult -nsHTMLEditRules::FindNearSelectableNode(nsIDOMNode *aSelNode, - int32_t aSelOffset, +nsHTMLEditRules::FindNearSelectableNode(nsIDOMNode *aSelNode, + int32_t aSelOffset, nsIEditor::EDirection &aDirection, nsCOMPtr<nsIDOMNode> *outSelectableNode) { NS_ENSURE_TRUE(aSelNode && outSelectableNode, NS_ERROR_NULL_POINTER); *outSelectableNode = nullptr; nsresult res = NS_OK; - + nsCOMPtr<nsIDOMNode> nearNode, curNode; if (aDirection == nsIEditor::ePrevious) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset, address_of(nearNode)); } else { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset, address_of(nearNode)); } NS_ENSURE_SUCCESS(res, res); - + if (!nearNode) // try the other direction then { if (aDirection == nsIEditor::ePrevious) aDirection = nsIEditor::eNext; else aDirection = nsIEditor::ePrevious; - + if (aDirection == nsIEditor::ePrevious) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetPriorHTMLNode(aSelNode, aSelOffset, address_of(nearNode)); } else { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetNextHTMLNode(aSelNode, aSelOffset, address_of(nearNode)); } NS_ENSURE_SUCCESS(res, res); } - + // scan in the right direction until we find an eligible text node, // but don't cross any breaks, images, or table elements. NS_ENSURE_STATE(mHTMLEditor); while (nearNode && !(mHTMLEditor->IsTextNode(nearNode) || nsTextEditUtils::IsBreak(nearNode) || nsHTMLEditUtils::IsImage(nearNode))) { curNode = nearNode; @@ -7670,24 +7670,24 @@ nsHTMLEditRules::FindNearSelectableNode( res = mHTMLEditor->GetPriorHTMLNode(curNode, address_of(nearNode)); } else { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetNextHTMLNode(curNode, address_of(nearNode)); } NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); } - + if (nearNode) { // don't cross any table elements if (InDifferentTableElements(nearNode, aSelNode)) { return NS_OK; } - + // otherwise, ok, we have found a good spot to put the selection *outSelectableNode = do_QueryInterface(nearNode); } return res; } bool nsHTMLEditRules::InDifferentTableElements(nsIDOMNode* aNode1, @@ -7851,23 +7851,23 @@ nsHTMLEditRules::RemoveEmptyNodes() } nsresult nsHTMLEditRules::SelectionEndpointInNode(nsINode* aNode, bool* aResult) { NS_ENSURE_TRUE(aNode && aResult, NS_ERROR_NULL_POINTER); nsIDOMNode* node = aNode->AsDOMNode(); - + *aResult = false; - + NS_ENSURE_STATE(mHTMLEditor); nsRefPtr<Selection> selection = mHTMLEditor->GetSelection(); NS_ENSURE_STATE(selection); - + uint32_t rangeCount = selection->RangeCount(); for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) { nsRefPtr<nsRange> range = selection->GetRangeAt(rangeIdx); nsCOMPtr<nsIDOMNode> startParent, endParent; range->GetStartContainer(getter_AddRefs(startParent)); if (startParent) { if (node == startParent) { @@ -7893,23 +7893,23 @@ nsHTMLEditRules::SelectionEndpointInNode } } } return NS_OK; } /////////////////////////////////////////////////////////////////////////// // IsEmptyInline: return true if aNode is an empty inline container -// -// -bool +// +// +bool nsHTMLEditRules::IsEmptyInline(nsIDOMNode *aNode) { if (aNode && IsInlineNode(aNode) && mHTMLEditor && - mHTMLEditor->IsContainer(aNode)) + mHTMLEditor->IsContainer(aNode)) { bool bEmpty; NS_ENSURE_TRUE(mHTMLEditor, false); mHTMLEditor->IsEmptyNode(aNode, &bEmpty); return bEmpty; } return false; } @@ -7943,65 +7943,65 @@ nsHTMLEditRules::ListIsEmptyLine(nsTArra } else { return false; } } return true; } -nsresult +nsresult nsHTMLEditRules::PopListItem(nsIDOMNode *aListItem, bool *aOutOfList) { nsCOMPtr<Element> listItem = do_QueryInterface(aListItem); // check parms NS_ENSURE_TRUE(listItem && aOutOfList, NS_ERROR_NULL_POINTER); - + // init out params *aOutOfList = false; - + nsCOMPtr<nsINode> curParent = listItem->GetParentNode(); int32_t offset = curParent ? curParent->IndexOf(listItem) : -1; - + if (!nsHTMLEditUtils::IsListItem(listItem)) { return NS_ERROR_FAILURE; } - + // if it's first or last list item, don't need to split the list // otherwise we do. nsCOMPtr<nsINode> curParPar = curParent->GetParentNode(); int32_t parOffset = curParPar ? curParPar->IndexOf(curParent) : -1; - + bool bIsFirstListItem; NS_ENSURE_STATE(mHTMLEditor); nsresult res = mHTMLEditor->IsFirstEditableChild(aListItem, &bIsFirstListItem); NS_ENSURE_SUCCESS(res, res); bool bIsLastListItem; NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->IsLastEditableChild(aListItem, &bIsLastListItem); NS_ENSURE_SUCCESS(res, res); - + if (!bIsFirstListItem && !bIsLastListItem) { // split the list nsCOMPtr<nsIDOMNode> newBlock; NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->SplitNode(GetAsDOMNode(curParent), offset, getter_AddRefs(newBlock)); NS_ENSURE_SUCCESS(res, res); } - + if (!bIsFirstListItem) parOffset++; - + NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(listItem, curParPar, parOffset); NS_ENSURE_SUCCESS(res, res); - + // unwrap list item contents if they are no longer in a list if (!nsHTMLEditUtils::IsList(curParPar) && nsHTMLEditUtils::IsListItem(listItem)) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->RemoveBlockContainer(GetAsDOMNode(listItem)); NS_ENSURE_SUCCESS(res, res); *aOutOfList = true; } @@ -8047,106 +8047,106 @@ nsHTMLEditRules::RemoveListStructure(nsI NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->RemoveBlockContainer(aList); NS_ENSURE_SUCCESS(res, res); return res; } -nsresult +nsresult nsHTMLEditRules::ConfirmSelectionInBody() { - // get the body + // get the body NS_ENSURE_STATE(mHTMLEditor); nsCOMPtr<nsIDOMElement> rootElement = do_QueryInterface(mHTMLEditor->GetRoot()); NS_ENSURE_TRUE(rootElement, NS_ERROR_UNEXPECTED); // get the selection NS_ENSURE_STATE(mHTMLEditor); nsRefPtr<Selection> selection = mHTMLEditor->GetSelection(); NS_ENSURE_STATE(selection); - + // get the selection start location nsCOMPtr<nsIDOMNode> selNode, temp, parent; int32_t selOffset; NS_ENSURE_STATE(mHTMLEditor); nsresult res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); NS_ENSURE_SUCCESS(res, res); temp = selNode; - + // check that selNode is inside body while (temp && !nsTextEditUtils::IsBody(temp)) { res = temp->GetParentNode(getter_AddRefs(parent)); temp = parent; } - + // if we aren't in the body, force the issue - if (!temp) + if (!temp) { // uncomment this to see when we get bad selections // NS_NOTREACHED("selection not in body"); selection->Collapse(rootElement, 0); } - + // get the selection end location NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); NS_ENSURE_SUCCESS(res, res); temp = selNode; - + // check that selNode is inside body while (temp && !nsTextEditUtils::IsBody(temp)) { res = temp->GetParentNode(getter_AddRefs(parent)); temp = parent; } - + // if we aren't in the body, force the issue - if (!temp) + if (!temp) { // uncomment this to see when we get bad selections // NS_NOTREACHED("selection not in body"); selection->Collapse(rootElement, 0); } - + return res; } -nsresult +nsresult nsHTMLEditRules::UpdateDocChangeRange(nsRange* aRange) { nsresult res = NS_OK; // first make sure aRange is in the document. It might not be if // portions of our editting action involved manipulating nodes // prior to placing them in the document (e.g., populating a list item // before placing it in its list) nsCOMPtr<nsIDOMNode> startNode; res = aRange->GetStartContainer(getter_AddRefs(startNode)); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsDescendantOfRoot(startNode)) { // just return - we don't need to adjust mDocChangeRange in this case return NS_OK; } - + if (!mDocChangeRange) { // clone aRange. mDocChangeRange = aRange->CloneRange(); } else { int16_t result; - + // compare starts of ranges res = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::START_TO_START, aRange, &result); if (res == NS_ERROR_NOT_INITIALIZED) { // This will happen is mDocChangeRange is non-null, but the range is // uninitialized. In this case we'll set the start to aRange start. // The same test won't be needed further down since after we've set // the start the range will be collapsed to that point. result = 1; @@ -8156,17 +8156,17 @@ nsHTMLEditRules::UpdateDocChangeRange(ns if (result > 0) // positive result means mDocChangeRange start is after aRange start { int32_t startOffset; res = aRange->GetStartOffset(&startOffset); NS_ENSURE_SUCCESS(res, res); res = mDocChangeRange->SetStart(startNode, startOffset); NS_ENSURE_SUCCESS(res, res); } - + // compare ends of ranges res = mDocChangeRange->CompareBoundaryPoints(nsIDOMRange::END_TO_END, aRange, &result); NS_ENSURE_SUCCESS(res, res); if (result < 0) // negative result means mDocChangeRange end is before aRange end { nsCOMPtr<nsIDOMNode> endNode; int32_t endOffset; res = aRange->GetEndContainer(getter_AddRefs(endNode)); @@ -8175,206 +8175,206 @@ nsHTMLEditRules::UpdateDocChangeRange(ns NS_ENSURE_SUCCESS(res, res); res = mDocChangeRange->SetEnd(endNode, endOffset); NS_ENSURE_SUCCESS(res, res); } } return res; } -nsresult +nsresult nsHTMLEditRules::InsertMozBRIfNeeded(nsIDOMNode *aNode) { NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); if (!IsBlockNode(aNode)) return NS_OK; - + bool isEmpty; NS_ENSURE_STATE(mHTMLEditor); nsresult res = mHTMLEditor->IsEmptyNode(aNode, &isEmpty); NS_ENSURE_SUCCESS(res, res); if (!isEmpty) { return NS_OK; } return CreateMozBR(aNode, 0); } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditRules::WillCreateNode(const nsAString& aTag, nsIDOMNode *aParent, int32_t aPosition) { - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLEditRules::DidCreateNode(const nsAString& aTag, - nsIDOMNode *aNode, - nsIDOMNode *aParent, - int32_t aPosition, + return NS_OK; +} + +NS_IMETHODIMP +nsHTMLEditRules::DidCreateNode(const nsAString& aTag, + nsIDOMNode *aNode, + nsIDOMNode *aParent, + int32_t aPosition, nsresult aResult) { if (!mListenerEnabled) { return NS_OK; } // assumption that Join keeps the righthand node nsresult res = mUtilRange->SelectNode(aNode); NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); - return res; -} - - -NS_IMETHODIMP + return res; +} + + +NS_IMETHODIMP nsHTMLEditRules::WillInsertNode(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aPosition) { - return NS_OK; -} - - -NS_IMETHODIMP -nsHTMLEditRules::DidInsertNode(nsIDOMNode *aNode, - nsIDOMNode *aParent, - int32_t aPosition, + return NS_OK; +} + + +NS_IMETHODIMP +nsHTMLEditRules::DidInsertNode(nsIDOMNode *aNode, + nsIDOMNode *aParent, + int32_t aPosition, nsresult aResult) { if (!mListenerEnabled) { return NS_OK; } nsresult res = mUtilRange->SelectNode(aNode); NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); - return res; -} - - -NS_IMETHODIMP + return res; +} + + +NS_IMETHODIMP nsHTMLEditRules::WillDeleteNode(nsIDOMNode *aChild) { if (!mListenerEnabled) { return NS_OK; } nsresult res = mUtilRange->SelectNode(aChild); NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); - return res; -} - - -NS_IMETHODIMP + return res; +} + + +NS_IMETHODIMP nsHTMLEditRules::DidDeleteNode(nsIDOMNode *aChild, nsresult aResult) { - return NS_OK; -} - - -NS_IMETHODIMP + return NS_OK; +} + + +NS_IMETHODIMP nsHTMLEditRules::WillSplitNode(nsIDOMNode *aExistingRightNode, int32_t aOffset) { - return NS_OK; -} - - -NS_IMETHODIMP -nsHTMLEditRules::DidSplitNode(nsIDOMNode *aExistingRightNode, - int32_t aOffset, - nsIDOMNode *aNewLeftNode, + return NS_OK; +} + + +NS_IMETHODIMP +nsHTMLEditRules::DidSplitNode(nsIDOMNode *aExistingRightNode, + int32_t aOffset, + nsIDOMNode *aNewLeftNode, nsresult aResult) { if (!mListenerEnabled) { return NS_OK; } nsresult res = mUtilRange->SetStart(aNewLeftNode, 0); NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(aExistingRightNode, 0); NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); - return res; -} - - -NS_IMETHODIMP + return res; +} + + +NS_IMETHODIMP nsHTMLEditRules::WillJoinNodes(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, nsIDOMNode *aParent) { if (!mListenerEnabled) { return NS_OK; } // remember split point nsresult res = nsEditor::GetLengthOfDOMNode(aLeftNode, mJoinOffset); - return res; -} - - -NS_IMETHODIMP -nsHTMLEditRules::DidJoinNodes(nsIDOMNode *aLeftNode, - nsIDOMNode *aRightNode, - nsIDOMNode *aParent, + return res; +} + + +NS_IMETHODIMP +nsHTMLEditRules::DidJoinNodes(nsIDOMNode *aLeftNode, + nsIDOMNode *aRightNode, + nsIDOMNode *aParent, nsresult aResult) { if (!mListenerEnabled) { return NS_OK; } // assumption that Join keeps the righthand node nsresult res = mUtilRange->SetStart(aRightNode, mJoinOffset); NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(aRightNode, mJoinOffset); NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); - return res; -} - - -NS_IMETHODIMP + return res; +} + + +NS_IMETHODIMP nsHTMLEditRules::WillInsertText(nsIDOMCharacterData *aTextNode, int32_t aOffset, const nsAString &aString) { - return NS_OK; -} - - -NS_IMETHODIMP -nsHTMLEditRules::DidInsertText(nsIDOMCharacterData *aTextNode, - int32_t aOffset, - const nsAString &aString, + return NS_OK; +} + + +NS_IMETHODIMP +nsHTMLEditRules::DidInsertText(nsIDOMCharacterData *aTextNode, + int32_t aOffset, + const nsAString &aString, nsresult aResult) { if (!mListenerEnabled) { return NS_OK; } int32_t length = aString.Length(); nsCOMPtr<nsIDOMNode> theNode = do_QueryInterface(aTextNode); nsresult res = mUtilRange->SetStart(theNode, aOffset); NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(theNode, aOffset+length); NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); - return res; -} - - -NS_IMETHODIMP + return res; +} + + +NS_IMETHODIMP nsHTMLEditRules::WillDeleteText(nsIDOMCharacterData *aTextNode, int32_t aOffset, int32_t aLength) { - return NS_OK; -} - - -NS_IMETHODIMP -nsHTMLEditRules::DidDeleteText(nsIDOMCharacterData *aTextNode, - int32_t aOffset, - int32_t aLength, + return NS_OK; +} + + +NS_IMETHODIMP +nsHTMLEditRules::DidDeleteText(nsIDOMCharacterData *aTextNode, + int32_t aOffset, + int32_t aLength, nsresult aResult) { if (!mListenerEnabled) { return NS_OK; } nsCOMPtr<nsIDOMNode> theNode = do_QueryInterface(aTextNode); nsresult res = mUtilRange->SetStart(theNode, aOffset); NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(theNode, aOffset); NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); - return res; + return res; } NS_IMETHODIMP nsHTMLEditRules::WillDeleteSelection(nsISelection* aSelection) { if (!mListenerEnabled) { return NS_OK; } @@ -8392,17 +8392,17 @@ nsHTMLEditRules::WillDeleteSelection(nsI NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); NS_ENSURE_SUCCESS(res, res); res = mUtilRange->SetEnd(selNode, selOffset); NS_ENSURE_SUCCESS(res, res); res = UpdateDocChangeRange(mUtilRange); - return res; + return res; } NS_IMETHODIMP nsHTMLEditRules::DidDeleteSelection(nsISelection *aSelection) { return NS_OK; } @@ -8471,17 +8471,17 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMN res = mHTMLEditor->RemoveAttribute(curElem, NS_LITERAL_STRING("align")); NS_ENSURE_SUCCESS(res, res); } if (useCSS) { if (nsHTMLEditUtils::IsTable(child) || nsHTMLEditUtils::IsHR(child)) { NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->SetAttributeOrEquivalent(curElem, NS_LITERAL_STRING("align"), aAlignType, false); + res = mHTMLEditor->SetAttributeOrEquivalent(curElem, NS_LITERAL_STRING("align"), aAlignType, false); } else { nsAutoString dummyCssValue; NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->mHTMLCSSUtils->RemoveCSSInlineStyle(child, nsGkAtoms::textAlign, dummyCssValue); } @@ -8600,17 +8600,17 @@ nsHTMLEditRules::AlignBlock(nsIDOMElemen nsresult res = RemoveAlignment(node, *aAlignType, aContentsOnly); NS_ENSURE_SUCCESS(res, res); NS_NAMED_LITERAL_STRING(attr, "align"); NS_ENSURE_STATE(mHTMLEditor); if (mHTMLEditor->IsCSSEnabled()) { // let's use CSS alignment; we use margin-left and margin-right for tables // and text-align for other block-level elements NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->SetAttributeOrEquivalent(aElement, attr, *aAlignType, false); + res = mHTMLEditor->SetAttributeOrEquivalent(aElement, attr, *aAlignType, false); NS_ENSURE_SUCCESS(res, res); } else { // HTML case; this code is supposed to be called ONLY if the element // supports the align attribute but we'll never know... if (nsHTMLEditUtils::SupportsAlignAttr(node)) { NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->SetAttribute(aElement, attr, *aAlignType); @@ -8664,17 +8664,17 @@ nsHTMLEditRules::RelativeChangeIndentati f += NS_EDITOR_INDENT_INCREMENT_PC * aRelativeChange; } else if (nsGkAtoms::em == unit) { f += NS_EDITOR_INDENT_INCREMENT_EM * aRelativeChange; } else if (nsGkAtoms::ex == unit) { f += NS_EDITOR_INDENT_INCREMENT_EX * aRelativeChange; } else if (nsGkAtoms::px == unit) { f += NS_EDITOR_INDENT_INCREMENT_PX * aRelativeChange; } else if (nsGkAtoms::percentage == unit) { - f += NS_EDITOR_INDENT_INCREMENT_PERCENT * aRelativeChange; + f += NS_EDITOR_INDENT_INCREMENT_PERCENT * aRelativeChange; } if (0 < f) { nsAutoString newValue; newValue.AppendFloat(f); newValue.Append(nsDependentAtomString(unit)); NS_ENSURE_STATE(mHTMLEditor); mHTMLEditor->mHTMLCSSUtils->SetCSSProperty(*element, *marginProperty, @@ -8716,48 +8716,48 @@ nsHTMLEditRules::WillAbsolutePosition(Se if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; } nsresult res = WillInsert(aSelection, aCancel); NS_ENSURE_SUCCESS(res, res); // initialize out param // we want to ignore result of WillInsert() *aCancel = false; *aHandled = true; - + nsCOMPtr<nsIDOMElement> focusElement; NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->GetSelectionContainer(getter_AddRefs(focusElement)); if (focusElement) { nsCOMPtr<nsIDOMNode> node = do_QueryInterface(focusElement); if (nsHTMLEditUtils::IsImage(node)) { mNewBlock = node; return NS_OK; } } res = NormalizeSelection(aSelection); NS_ENSURE_SUCCESS(res, res); NS_ENSURE_STATE(mHTMLEditor); nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor); - + // convert the selection ranges into "promoted" selection ranges: // this basically just expands the range to include the immediate // block parent, and then further expands to include any ancestors // whose children are all in the range - + nsTArray<nsRefPtr<nsRange>> arrayOfRanges; GetPromotedRanges(*aSelection, arrayOfRanges, EditAction::setAbsolutePosition); - + // use these ranges to contruct a list of nodes to act on. nsTArray<OwningNonNull<nsINode>> arrayOfNodes; res = GetNodesForOperation(arrayOfRanges, arrayOfNodes, EditAction::setAbsolutePosition); - NS_ENSURE_SUCCESS(res, res); - + NS_ENSURE_SUCCESS(res, res); + // if nothing visible in list, make an empty block if (ListIsEmptyLine(arrayOfNodes)) { // get selection location NS_ENSURE_STATE(aSelection->RangeCount()); nsCOMPtr<nsINode> parent = aSelection->GetRangeAt(0)->GetStartParent(); int32_t offset = aSelection->GetRangeAt(0)->StartOffset(); NS_ENSURE_STATE(parent); @@ -8781,44 +8781,44 @@ nsHTMLEditRules::WillAbsolutePosition(Se } // put selection in new block res = aSelection->Collapse(thePositionedDiv,0); selectionResetter.Abort(); // to prevent selection reseter from overriding us. *aHandled = true; return res; } - // Ok, now go through all the nodes and put them in a blockquote, + // Ok, now go through all the nodes and put them in a blockquote, // or whatever is appropriate. Wohoo! nsCOMPtr<nsINode> curParent; nsCOMPtr<nsIDOMNode> indentedLI, sibling; nsCOMPtr<Element> curList, curPositionedDiv; for (uint32_t i = 0; i < arrayOfNodes.Length(); i++) { // here's where we actually figure out what to do NS_ENSURE_STATE(arrayOfNodes[i]->IsContent()); nsCOMPtr<nsIContent> curNode = arrayOfNodes[i]->AsContent(); // Ignore all non-editable nodes. Leave them be. NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsEditable(curNode)) continue; curParent = curNode->GetParentNode(); int32_t offset = curParent ? curParent->IndexOf(curNode) : -1; - + // some logic for putting list items into nested lists... if (nsHTMLEditUtils::IsList(curParent)) { // check to see if curList is still appropriate. Which it is if // curNode is still right after it in the same list. if (curList) { NS_ENSURE_STATE(mHTMLEditor); sibling = GetAsDOMNode(mHTMLEditor->GetPriorHTMLSibling(curNode)); } - + if (!curList || (sibling && sibling != GetAsDOMNode(curList))) { // create a new nested list of correct type res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset); NS_ENSURE_SUCCESS(res, res); if (!curPositionedDiv) { nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode(); int32_t parentOffset = curParentParent @@ -8838,17 +8838,17 @@ nsHTMLEditRules::WillAbsolutePosition(Se } // tuck the node into the end of the active list NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(curNode, curList, -1); NS_ENSURE_SUCCESS(res, res); // forget curPositionedDiv, if any // curPositionedDiv = nullptr; } - + else // not a list item, use blockquote? { // if we are inside a list item, we don't want to blockquote, we want // to sublist the list item. We may have several nodes listed in the // array of nodes to act on, that are in the same list item. Since // we only want to indent that li once, we must keep track of the most // recent indented list item, and not indent it if we find another node // to act on that is still inside the same li. @@ -8862,17 +8862,17 @@ nsHTMLEditRules::WillAbsolutePosition(Se offset = curParent ? curParent->IndexOf(listItem) : -1; // check to see if curList is still appropriate. Which it is if // curNode is still right after it in the same list. if (curList) { NS_ENSURE_STATE(mHTMLEditor); sibling = GetAsDOMNode(mHTMLEditor->GetPriorHTMLSibling(curNode)); } - + if (!curList || (sibling && sibling != GetAsDOMNode(curList))) { // create a new nested list of correct type res = SplitAsNeeded(*curParent->NodeInfo()->NameAtom(), curParent, offset); NS_ENSURE_SUCCESS(res, res); if (!curPositionedDiv) { nsCOMPtr<nsINode> curParentParent = curParent->GetParentNode(); int32_t parentOffset = curParentParent ? @@ -8889,22 +8889,22 @@ nsHTMLEditRules::WillAbsolutePosition(Se NS_ENSURE_STATE(curList); } NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(listItem, curList, -1); NS_ENSURE_SUCCESS(res, res); // remember we indented this li indentedLI = GetAsDOMNode(listItem); } - + else { // need to make a div to put things in if we haven't already - if (!curPositionedDiv) + if (!curPositionedDiv) { if (curNode->IsHTMLElement(nsGkAtoms::div)) { curPositionedDiv = curNode->AsElement(); mNewBlock = GetAsDOMNode(curPositionedDiv); curList = nullptr; continue; } res = SplitAsNeeded(*nsGkAtoms::div, curParent, offset); @@ -8912,17 +8912,17 @@ nsHTMLEditRules::WillAbsolutePosition(Se NS_ENSURE_STATE(mHTMLEditor); curPositionedDiv = mHTMLEditor->CreateNode(nsGkAtoms::div, curParent, offset); NS_ENSURE_STATE(curPositionedDiv); // remember our new block for postprocessing mNewBlock = GetAsDOMNode(curPositionedDiv); // curPositionedDiv is now the correct thing to put curNode in } - + // tuck the node into the end of the active blockquote NS_ENSURE_STATE(mHTMLEditor); res = mHTMLEditor->MoveNode(curNode, curPositionedDiv, -1); NS_ENSURE_SUCCESS(res, res); // forget curList, if any curList = nullptr; } }
--- a/editor/libeditor/nsHTMLEditRules.h +++ b/editor/libeditor/nsHTMLEditRules.h @@ -36,22 +36,22 @@ class Element; class Selection; } // namespace dom } // namespace mozilla struct DOMPoint; struct StyleCache : public PropItem { bool mPresent; - + StyleCache() : PropItem(), mPresent(false) { MOZ_COUNT_CTOR(StyleCache); } - StyleCache(nsIAtom *aTag, const nsAString &aAttr, const nsAString &aValue) : + StyleCache(nsIAtom *aTag, const nsAString &aAttr, const nsAString &aValue) : PropItem(aTag, aAttr, aValue), mPresent(false) { MOZ_COUNT_CTOR(StyleCache); } ~StyleCache() { MOZ_COUNT_DTOR(StyleCache); } }; @@ -83,17 +83,17 @@ public: nsresult GetListState(bool *aMixed, bool *aOL, bool *aUL, bool *aDL); nsresult GetListItemState(bool *aMixed, bool *aLI, bool *aDT, bool *aDD); nsresult GetIndentState(bool *aCanIndent, bool *aCanOutdent); nsresult GetAlignment(bool *aMixed, nsIHTMLEditor::EAlignment *aAlign); nsresult GetParagraphState(bool *aMixed, nsAString &outFormat); nsresult MakeSureElemStartsOrEndsOnCR(nsIDOMNode *aNode); // nsIEditActionListener methods - + NS_IMETHOD WillCreateNode(const nsAString& aTag, nsIDOMNode *aParent, int32_t aPosition) override; NS_IMETHOD DidCreateNode(const nsAString& aTag, nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aPosition, nsresult aResult) override; NS_IMETHOD WillInsertNode(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aPosition) override; NS_IMETHOD DidInsertNode(nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aPosition, nsresult aResult) override; NS_IMETHOD WillDeleteNode(nsIDOMNode *aChild) override; NS_IMETHOD DidDeleteNode(nsIDOMNode *aChild, nsresult aResult) override; NS_IMETHOD WillSplitNode(nsIDOMNode *aExistingRightNode, int32_t aOffset) override; NS_IMETHOD DidSplitNode(nsIDOMNode *aExistingRightNode, int32_t aOffset, nsIDOMNode *aNewLeftNode, nsresult aResult) override; @@ -139,18 +139,18 @@ protected: mozilla::dom::Selection* aSelection); nsresult DidInsertBreak(mozilla::dom::Selection* aSelection, nsresult aResult); nsresult SplitMailCites(mozilla::dom::Selection* aSelection, bool* aHandled); nsresult WillDeleteSelection(mozilla::dom::Selection* aSelection, nsIEditor::EDirection aAction, nsIEditor::EStripWrappers aStripWrappers, bool* aCancel, bool* aHandled); - nsresult DidDeleteSelection(mozilla::dom::Selection* aSelection, - nsIEditor::EDirection aDir, + nsresult DidDeleteSelection(mozilla::dom::Selection* aSelection, + nsIEditor::EDirection aDir, nsresult aResult); nsresult InsertBRIfNeeded(mozilla::dom::Selection* aSelection); ::DOMPoint GetGoodSelPointForNode(nsINode& aNode, nsIEditor::EDirection aAction); nsresult JoinBlocks(nsIDOMNode *aLeftNode, nsIDOMNode *aRightNode, bool *aCanceled); nsresult MoveBlock(nsIDOMNode *aLeft, nsIDOMNode *aRight, int32_t aLeftOffset, int32_t aRightOffset); nsresult MoveNodeSmart(nsIDOMNode *aSource, nsIDOMNode *aDest, int32_t *aOffset); nsresult MoveContents(nsIDOMNode *aSource, nsIDOMNode *aDest, int32_t *aOffset); @@ -205,70 +205,70 @@ protected: mozilla::dom::Element* IsInListItem(nsINode* aNode); nsresult ReturnInHeader(mozilla::dom::Selection* aSelection, nsIDOMNode* aHeader, nsIDOMNode* aTextNode, int32_t aOffset); nsresult ReturnInParagraph(mozilla::dom::Selection* aSelection, nsIDOMNode* aHeader, nsIDOMNode* aTextNode, int32_t aOffset, bool* aCancel, bool* aHandled); nsresult SplitParagraph(nsIDOMNode *aPara, - nsIDOMNode *aBRNode, + nsIDOMNode *aBRNode, mozilla::dom::Selection* aSelection, - nsCOMPtr<nsIDOMNode> *aSelNode, + nsCOMPtr<nsIDOMNode> *aSelNode, int32_t *aOffset); nsresult ReturnInListItem(mozilla::dom::Selection* aSelection, nsIDOMNode* aHeader, nsIDOMNode* aTextNode, int32_t aOffset); nsresult AfterEditInner(EditAction action, nsIEditor::EDirection aDirection); nsresult RemovePartOfBlock(mozilla::dom::Element& aBlock, nsIContent& aStartChild, nsIContent& aEndChild); - nsresult SplitBlock(nsIDOMNode *aBlock, - nsIDOMNode *aStartChild, + nsresult SplitBlock(nsIDOMNode *aBlock, + nsIDOMNode *aStartChild, nsIDOMNode *aEndChild, nsCOMPtr<nsIDOMNode> *aLeftNode = 0, nsCOMPtr<nsIDOMNode> *aRightNode = 0, nsCOMPtr<nsIDOMNode> *aMiddleNode = 0); - nsresult OutdentPartOfBlock(nsIDOMNode *aBlock, - nsIDOMNode *aStartChild, + nsresult OutdentPartOfBlock(nsIDOMNode *aBlock, + nsIDOMNode *aStartChild, nsIDOMNode *aEndChild, bool aIsBlockIndentedWithCSS, nsCOMPtr<nsIDOMNode> *aLeftNode = 0, nsCOMPtr<nsIDOMNode> *aRightNode = 0); nsresult ConvertListType(nsIDOMNode* aList, nsCOMPtr<nsIDOMNode>* outList, nsIAtom* aListType, nsIAtom* aItemType); nsresult ConvertListType(mozilla::dom::Element* aList, mozilla::dom::Element** aOutList, nsIAtom* aListType, nsIAtom* aItemType); nsresult CreateStyleForInsertText(mozilla::dom::Selection* aSelection, nsIDOMDocument* aDoc); - nsresult IsEmptyBlock(nsIDOMNode *aNode, - bool *outIsEmptyBlock, + nsresult IsEmptyBlock(nsIDOMNode *aNode, + bool *outIsEmptyBlock, bool aMozBRDoesntCount = false, bool aListItemsNotEmpty = false); nsresult CheckForEmptyBlock(nsINode* aStartNode, mozilla::dom::Element* aBodyNode, mozilla::dom::Selection* aSelection, bool* aHandled); - nsresult CheckForInvisibleBR(nsIDOMNode *aBlock, nsHTMLEditRules::BRLocation aWhere, + nsresult CheckForInvisibleBR(nsIDOMNode *aBlock, nsHTMLEditRules::BRLocation aWhere, nsCOMPtr<nsIDOMNode> *outBRNode, int32_t aOffset=0); nsresult ExpandSelectionForDeletion(mozilla::dom::Selection* aSelection); bool IsFirstNode(nsIDOMNode *aNode); bool IsLastNode(nsIDOMNode *aNode); nsresult NormalizeSelection(mozilla::dom::Selection* aSelection); void GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode* aNode, int32_t aOffset, EditAction actionID, nsCOMPtr<nsIDOMNode>* outNode, int32_t* outOffset); - void GetPromotedRanges(mozilla::dom::Selection& aSelection, + void GetPromotedRanges(mozilla::dom::Selection& aSelection, nsTArray<nsRefPtr<nsRange>>& outArrayOfRanges, EditAction inOperationType); void PromoteRange(nsRange& aRange, EditAction inOperationType); enum class TouchContent { no, yes }; nsresult GetNodesForOperation(nsTArray<nsRefPtr<nsRange>>& aArrayOfRanges, nsTArray<mozilla::dom::OwningNonNull<nsINode>>& aOutArrayOfNodes, EditAction aOperationType, TouchContent aTouchContent = TouchContent::yes); @@ -312,18 +312,18 @@ protected: nsresult ReapplyCachedStyles(); void ClearCachedStyles(); void AdjustSpecialBreaks(); nsresult AdjustWhitespace(mozilla::dom::Selection* aSelection); nsresult PinSelectionToNewBlock(mozilla::dom::Selection* aSelection); nsresult CheckInterlinePosition(mozilla::dom::Selection* aSelection); nsresult AdjustSelection(mozilla::dom::Selection* aSelection, nsIEditor::EDirection aAction); - nsresult FindNearSelectableNode(nsIDOMNode *aSelNode, - int32_t aSelOffset, + nsresult FindNearSelectableNode(nsIDOMNode *aSelNode, + int32_t aSelOffset, nsIEditor::EDirection &aDirection, nsCOMPtr<nsIDOMNode> *outSelectableNode); /** * Returns true if aNode1 or aNode2 or both is the descendant of some type of * table element, but their nearest table element ancestors differ. "Table * element" here includes not just <table> but also <td>, <tbody>, <tr>, etc. * The nodes count as being their own descendants for this purpose, so a * table element is its own nearest table element ancestor.
--- a/editor/libeditor/nsHTMLEditUtils.cpp +++ b/editor/libeditor/nsHTMLEditUtils.cpp @@ -23,18 +23,18 @@ #include "nsLiteralString.h" // for NS_LITERAL_STRING #include "nsString.h" // for nsAutoString #include "nsTextEditUtils.h" // for nsTextEditUtils using namespace mozilla; /////////////////////////////////////////////////////////////////////////// // IsInlineStyle true if node is an inline style -// -bool +// +bool nsHTMLEditUtils::IsInlineStyle(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsInlineStyle"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsInlineStyle(node); } bool @@ -51,17 +51,17 @@ nsHTMLEditUtils::IsInlineStyle(nsINode* nsGkAtoms::small, nsGkAtoms::sub, nsGkAtoms::sup, nsGkAtoms::font); } /////////////////////////////////////////////////////////////////////////// // IsFormatNode true if node is a format node -// +// bool nsHTMLEditUtils::IsFormatNode(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsFormatNode"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsFormatNode(node); } @@ -76,17 +76,17 @@ nsHTMLEditUtils::IsFormatNode(nsINode* a nsGkAtoms::h3, nsGkAtoms::h4, nsGkAtoms::h5, nsGkAtoms::h6, nsGkAtoms::address); } /////////////////////////////////////////////////////////////////////////// -// IsNodeThatCanOutdent true if node is a list, list item, or blockquote +// IsNodeThatCanOutdent true if node is a list, list item, or blockquote // bool nsHTMLEditUtils::IsNodeThatCanOutdent(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsNodeThatCanOutdent"); nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode); return (nodeAtom == nsGkAtoms::ul) || (nodeAtom == nsGkAtoms::ol) @@ -95,21 +95,21 @@ nsHTMLEditUtils::IsNodeThatCanOutdent(ns || (nodeAtom == nsGkAtoms::dd) || (nodeAtom == nsGkAtoms::dt) || (nodeAtom == nsGkAtoms::blockquote); } /******************************************************** * helper methods from nsHTMLEditRules ********************************************************/ - + /////////////////////////////////////////////////////////////////////////// // IsHeader: true if node an html header -// -bool +// +bool nsHTMLEditUtils::IsHeader(nsINode& aNode) { return aNode.IsAnyOfHTMLElements(nsGkAtoms::h1, nsGkAtoms::h2, nsGkAtoms::h3, nsGkAtoms::h4, nsGkAtoms::h5, nsGkAtoms::h6); @@ -121,38 +121,38 @@ nsHTMLEditUtils::IsHeader(nsIDOMNode* aN nsCOMPtr<nsINode> node = do_QueryInterface(aNode); NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsHeader"); return IsHeader(*node); } /////////////////////////////////////////////////////////////////////////// // IsParagraph: true if node an html paragraph -// -bool +// +bool nsHTMLEditUtils::IsParagraph(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::p); } /////////////////////////////////////////////////////////////////////////// // IsHR: true if node an horizontal rule -// -bool +// +bool nsHTMLEditUtils::IsHR(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::hr); } /////////////////////////////////////////////////////////////////////////// // IsListItem: true if node an html list item -// -bool +// +bool nsHTMLEditUtils::IsListItem(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsListItem"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsListItem(node); } bool @@ -162,17 +162,17 @@ nsHTMLEditUtils::IsListItem(nsINode* aNo return aNode->IsAnyOfHTMLElements(nsGkAtoms::li, nsGkAtoms::dd, nsGkAtoms::dt); } /////////////////////////////////////////////////////////////////////////// // IsTableElement: true if node an html table, td, tr, ... -// +// bool nsHTMLEditUtils::IsTableElement(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null node passed to nsHTMLEditor::IsTableElement"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsTableElement(node); } @@ -187,18 +187,18 @@ nsHTMLEditUtils::IsTableElement(nsINode* nsGkAtoms::thead, nsGkAtoms::tfoot, nsGkAtoms::tbody, nsGkAtoms::caption); } /////////////////////////////////////////////////////////////////////////// // IsTableElementButNotTable: true if node an html td, tr, ... (doesn't include table) -// -bool +// +bool nsHTMLEditUtils::IsTableElementButNotTable(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null node passed to nsHTMLEditor::IsTableElementButNotTable"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsTableElementButNotTable(node); } bool @@ -211,43 +211,43 @@ nsHTMLEditUtils::IsTableElementButNotTab nsGkAtoms::thead, nsGkAtoms::tfoot, nsGkAtoms::tbody, nsGkAtoms::caption); } /////////////////////////////////////////////////////////////////////////// // IsTable: true if node an html table -// +// bool nsHTMLEditUtils::IsTable(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::table); } bool nsHTMLEditUtils::IsTable(nsINode* aNode) { return aNode && aNode->IsHTMLElement(nsGkAtoms::table); } /////////////////////////////////////////////////////////////////////////// // IsTableRow: true if node an html tr -// -bool +// +bool nsHTMLEditUtils::IsTableRow(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::tr); } /////////////////////////////////////////////////////////////////////////// // IsTableCell: true if node an html td or th -// -bool +// +bool nsHTMLEditUtils::IsTableCell(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsTableCell"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsTableCell(node); } bool @@ -255,31 +255,31 @@ nsHTMLEditUtils::IsTableCell(nsINode* aN { MOZ_ASSERT(aNode); return aNode->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th); } /////////////////////////////////////////////////////////////////////////// // IsTableCell: true if node an html td or th -// -bool +// +bool nsHTMLEditUtils::IsTableCellOrCaption(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsTableCell"); nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode); return (nodeAtom == nsGkAtoms::td) || (nodeAtom == nsGkAtoms::th) || (nodeAtom == nsGkAtoms::caption); } /////////////////////////////////////////////////////////////////////////// // IsList: true if node an html list -// +// bool nsHTMLEditUtils::IsList(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsList"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsList(node); } @@ -290,70 +290,70 @@ nsHTMLEditUtils::IsList(nsINode* aNode) return aNode->IsAnyOfHTMLElements(nsGkAtoms::ul, nsGkAtoms::ol, nsGkAtoms::dl); } /////////////////////////////////////////////////////////////////////////// // IsOrderedList: true if node an html ordered list -// -bool +// +bool nsHTMLEditUtils::IsOrderedList(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::ol); } /////////////////////////////////////////////////////////////////////////// // IsUnorderedList: true if node an html unordered list -// -bool +// +bool nsHTMLEditUtils::IsUnorderedList(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::ul); } /////////////////////////////////////////////////////////////////////////// // IsBlockquote: true if node an html blockquote node -// -bool +// +bool nsHTMLEditUtils::IsBlockquote(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::blockquote); } /////////////////////////////////////////////////////////////////////////// // IsPre: true if node an html pre node -// -bool +// +bool nsHTMLEditUtils::IsPre(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::pre); } /////////////////////////////////////////////////////////////////////////// // IsImage: true if node an html image node -// +// bool nsHTMLEditUtils::IsImage(nsINode* aNode) { return aNode && aNode->IsHTMLElement(nsGkAtoms::img); } -bool +bool nsHTMLEditUtils::IsImage(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::img); } -bool +bool nsHTMLEditUtils::IsLink(nsIDOMNode *aNode) { nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsLink(node); } bool nsHTMLEditUtils::IsLink(nsINode* aNode) @@ -366,17 +366,17 @@ nsHTMLEditUtils::IsLink(nsINode* aNode) nsAutoString tmpText; if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && !tmpText.IsEmpty()) { return true; } } return false; } -bool +bool nsHTMLEditUtils::IsNamedAnchor(nsIDOMNode *aNode) { nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsNamedAnchor(node); } bool nsHTMLEditUtils::IsNamedAnchor(nsINode* aNode) @@ -389,28 +389,28 @@ nsHTMLEditUtils::IsNamedAnchor(nsINode* nsAutoString text; return aNode->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::name, text) && !text.IsEmpty(); } /////////////////////////////////////////////////////////////////////////// // IsDiv: true if node an html div node -// -bool +// +bool nsHTMLEditUtils::IsDiv(nsIDOMNode* aNode) { return nsEditor::NodeIsType(aNode, nsGkAtoms::div); } /////////////////////////////////////////////////////////////////////////// // IsMozDiv: true if node an html div node with type = _moz -// -bool +// +bool nsHTMLEditUtils::IsMozDiv(nsIDOMNode* aNode) { if (IsDiv(aNode) && nsTextEditUtils::HasMozAttr(aNode)) return true; return false; } bool nsHTMLEditUtils::IsMozDiv(nsINode* aNode) @@ -418,17 +418,17 @@ nsHTMLEditUtils::IsMozDiv(nsINode* aNode MOZ_ASSERT(aNode); return aNode->IsHTMLElement(nsGkAtoms::div) && nsTextEditUtils::HasMozAttr(GetAsDOMNode(aNode)); } /////////////////////////////////////////////////////////////////////////// // IsMailCite: true if node an html blockquote with type=cite -// +// bool nsHTMLEditUtils::IsMailCite(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsMailCite"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsMailCite(node); } @@ -454,17 +454,17 @@ nsHTMLEditUtils::IsMailCite(nsINode* aNo } return false; } /////////////////////////////////////////////////////////////////////////// // IsFormWidget: true if node is a form widget of some kind -// +// bool nsHTMLEditUtils::IsFormWidget(nsIDOMNode* aNode) { NS_PRECONDITION(aNode, "null node passed to nsHTMLEditUtils::IsFormWidget"); nsCOMPtr<nsINode> node = do_QueryInterface(aNode); return node && IsFormWidget(node); } @@ -842,17 +842,17 @@ nsHTMLEditUtils::CanContain(int32_t aPar const nsElementInfo& parent = kElements[aParent - 1]; if (aParent == aChild) { return parent.mCanContainSelf; } const nsElementInfo& child = kElements[aChild - 1]; return (parent.mCanContainGroups & child.mGroup) != 0; -} +} bool nsHTMLEditUtils::IsContainer(int32_t aTag) { NS_ASSERTION(aTag > eHTMLTag_unknown && aTag <= eHTMLTag_userdefined, "aTag out of range!"); return kElements[aTag - 1].mIsContainer;
--- a/editor/libeditor/nsHTMLEditor.cpp +++ b/editor/libeditor/nsHTMLEditor.cpp @@ -23,17 +23,17 @@ #include "nsHTMLURIRefObject.h" #include "nsIDOMText.h" #include "nsIDOMMozNamedAttrMap.h" #include "nsIDOMNodeList.h" #include "nsIDOMDocument.h" #include "nsIDOMAttr.h" #include "nsIDocumentInlines.h" -#include "nsIDOMEventTarget.h" +#include "nsIDOMEventTarget.h" #include "nsIDOMKeyEvent.h" #include "nsIDOMMouseEvent.h" #include "nsIDOMHTMLAnchorElement.h" #include "nsISelectionController.h" #include "nsIDOMHTMLDocument.h" #include "nsILinkHandler.h" #include "nsIInlineSpellChecker.h" @@ -104,41 +104,41 @@ nsHTMLEditor::nsHTMLEditor() , mGrabberClicked(false) , mIsMoving(false) , mSnapToGridEnabled(false) , mIsInlineTableEditingEnabled(true) , mInfoXIncrement(20) , mInfoYIncrement(20) , mGridSize(0) { -} +} nsHTMLEditor::~nsHTMLEditor() { // remove the rules as an action listener. Else we get a bad // ownership loop later on. it's ok if the rules aren't a listener; // we ignore the error. nsCOMPtr<nsIEditActionListener> mListener = do_QueryInterface(mRules); RemoveEditActionListener(mListener); - //the autopointers will clear themselves up. + //the autopointers will clear themselves up. //but we need to also remove the listeners or we have a leak nsRefPtr<Selection> selection = GetSelection(); // if we don't get the selection, just skip this if (selection) { nsCOMPtr<nsISelectionListener>listener; listener = do_QueryInterface(mTypeInState); if (listener) { - selection->RemoveSelectionListener(listener); + selection->RemoveSelectionListener(listener); } listener = do_QueryInterface(mSelectionListenerP); if (listener) { - selection->RemoveSelectionListener(listener); + selection->RemoveSelectionListener(listener); } } mTypeInState = nullptr; mSelectionListenerP = nullptr; // free any default style propItems RemoveAllDefaultProperties(); @@ -232,17 +232,17 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc, uint32_t aFlags, const nsAString& aInitialValue) { NS_PRECONDITION(aDoc && !aSelCon, "bad arg"); NS_ENSURE_TRUE(aDoc, NS_ERROR_NULL_POINTER); MOZ_ASSERT(aInitialValue.IsEmpty(), "Non-empty initial values not supported"); nsresult result = NS_OK, rulesRes = NS_OK; - + if (1) { // block to scope nsAutoEditInitRulesTrigger nsAutoEditInitRulesTrigger rulesTrigger(static_cast<nsPlaintextEditor*>(this), rulesRes); // Init the plaintext editor result = nsPlaintextEditor::Init(aDoc, aRoot, nullptr, aFlags, aInitialValue); if (NS_FAILED(result)) { return result; } @@ -279,26 +279,26 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc, mSelectionListenerP = new ResizerSelectionListener(this); if (!IsInteractionAllowed()) { // ignore any errors from this in case the file is missing AddOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/EditorOverride.css")); } nsRefPtr<Selection> selection = GetSelection(); - if (selection) + if (selection) { nsCOMPtr<nsISelectionListener>listener; listener = do_QueryInterface(mTypeInState); if (listener) { - selection->AddSelectionListener(listener); + selection->AddSelectionListener(listener); } listener = do_QueryInterface(mSelectionListenerP); if (listener) { - selection->AddSelectionListener(listener); + selection->AddSelectionListener(listener); } } } NS_ENSURE_SUCCESS(rulesRes, rulesRes); return result; } @@ -335,18 +335,18 @@ nsHTMLEditor::GetRootElement(nsIDOMEleme return nsEditor::GetRootElement(aRootElement); } *aRootElement = nullptr; // Use the HTML documents body element as the editor root if we didn't // get a root element during initialization. - nsCOMPtr<nsIDOMElement> rootElement; - nsCOMPtr<nsIDOMHTMLElement> bodyElement; + nsCOMPtr<nsIDOMElement> rootElement; + nsCOMPtr<nsIDOMHTMLElement> bodyElement; nsresult rv = GetBodyElement(getter_AddRefs(bodyElement)); NS_ENSURE_SUCCESS(rv, rv); if (bodyElement) { rootElement = bodyElement; } else { // If there is no HTML body element, // we should use the document root element instead. @@ -472,17 +472,17 @@ nsHTMLEditor::RemoveEventListeners() } mMouseMotionListenerP = nullptr; mResizeEventListenerP = nullptr; nsPlaintextEditor::RemoveEventListeners(); } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditor::SetFlags(uint32_t aFlags) { nsresult rv = nsPlaintextEditor::SetFlags(aFlags); NS_ENSURE_SUCCESS(rv, rv); // Sets mCSSAware to correspond to aFlags. This toggles whether CSS is // used to style elements in the editor. Note that the editor is only CSS // aware by default in Composer and in the mail editor. @@ -794,28 +794,28 @@ nsHTMLEditor::NodeIsBlock(nsIDOMNode *aN bool nsHTMLEditor::IsBlockNode(nsINode *aNode) { return aNode && NodeIsBlockStatic(aNode); } // Non-static version for the nsIEditor interface and JavaScript -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditor::SetDocumentTitle(const nsAString &aTitle) { nsRefPtr<SetDocTitleTxn> txn = new SetDocTitleTxn(); NS_ENSURE_TRUE(txn, NS_ERROR_OUT_OF_MEMORY); nsresult result = txn->Init(this, &aTitle); NS_ENSURE_SUCCESS(result, result); //Don't let Rules System change the selection nsAutoTxnsConserveSelection dontChangeSelection(this); - return nsEditor::DoTransaction(txn); + return nsEditor::DoTransaction(txn); } /* ------------ Block methods moved from nsEditor -------------- */ /////////////////////////////////////////////////////////////////////////// // GetBlockNodeParent: returns enclosing block level ancestor, if any // already_AddRefed<Element> nsHTMLEditor::GetBlockNodeParent(nsINode* aNode) @@ -932,43 +932,43 @@ nsHTMLEditor::IsVisBreak(nsINode* aNode) nsCOMPtr<nsINode> priorNode = GetPriorHTMLNode(aNode, true); if (priorNode && nsTextEditUtils::IsBreak(priorNode)) { return true; } nsCOMPtr<nsINode> nextNode = GetNextHTMLNode(aNode, true); if (nextNode && nsTextEditUtils::IsBreak(nextNode)) { return true; } - + // If we are right before block boundary, then br not visible if (!nextNode) { // This break is trailer in block, it's not visible return false; } if (IsBlockNode(nextNode)) { // Break is right before a block, it's not visible return false; } - - // Sigh. We have to use expensive whitespace calculation code to + + // Sigh. We have to use expensive whitespace calculation code to // determine what is going on int32_t selOffset; nsCOMPtr<nsINode> selNode = GetNodeLocation(aNode, &selOffset); // Let's look after the break selOffset++; nsWSRunObject wsObj(this, selNode, selOffset); nsCOMPtr<nsINode> unused; int32_t visOffset = 0; WSType visType; wsObj.NextVisibleNode(selNode, selOffset, address_of(unused), &visOffset, &visType); if (visType & WSType::block) { return false; } - + return true; } bool nsHTMLEditor::IsVisBreak(nsIDOMNode* aNode) { nsCOMPtr<nsINode> node = do_QueryInterface(aNode); NS_ENSURE_TRUE(node, false); @@ -1066,45 +1066,45 @@ nsHTMLEditor::TabInTable(bool inIsShift, if (node && nsHTMLEditUtils::IsTableCell(node) && nsCOMPtr<Element>(GetEnclosingTable(node)) == table) { CollapseSelectionToDeepestNonTableFirstChild(nullptr, node); *outHandled = true; return NS_OK; } } while (!iter->IsDone()); - + if (!(*outHandled) && !inIsShift) { // If we haven't handled it yet, then we must have run off the end of the // table. Insert a new row. res = InsertTableRow(1, true); NS_ENSURE_SUCCESS(res, res); *outHandled = true; // Put selection in right place. Use table code to get selection and index // to new row... nsRefPtr<Selection> selection; nsCOMPtr<nsIDOMElement> tblElement, cell; int32_t row; - res = GetCellContext(getter_AddRefs(selection), + res = GetCellContext(getter_AddRefs(selection), getter_AddRefs(tblElement), - getter_AddRefs(cell), + getter_AddRefs(cell), nullptr, nullptr, &row, nullptr); NS_ENSURE_SUCCESS(res, res); // ...so that we can ask for first cell in that row... res = GetCellAt(tblElement, row, 0, getter_AddRefs(cell)); NS_ENSURE_SUCCESS(res, res); // ...and then set selection there. (Note that normally you should use // CollapseSelectionToDeepestNonTableFirstChild(), but we know cell is an // empty new cell, so this works fine) if (cell) { selection->Collapse(cell, 0); } } - + return NS_OK; } already_AddRefed<Element> nsHTMLEditor::CreateBR(nsINode* aNode, int32_t aOffset, EDirection aSelect) { nsCOMPtr<nsIDOMNode> parent = GetAsDOMNode(aNode); int32_t offset = aOffset; @@ -1179,21 +1179,21 @@ nsHTMLEditor::ReplaceHeadContentsWithHTM nsCOMPtr<nsIContent> headNode = nodeList->Item(0); NS_ENSURE_TRUE(headNode, NS_ERROR_NULL_POINTER); // First, make sure there are no return chars in the source. Bad things // happen if you insert returns (instead of dom newlines, \n) into an editor // document. nsAutoString inputString (aSourceToInsert); // hope this does copy-on-write - + // Windows linebreaks: Map CRLF to LF: inputString.ReplaceSubstring(MOZ_UTF16("\r\n"), MOZ_UTF16("\n")); - + // Mac linebreaks: Map any remaining CR to LF: inputString.ReplaceSubstring(MOZ_UTF16("\r"), MOZ_UTF16("\n")); nsAutoEditBatch beginBatching(this); // Get the first range in the selection, for context: nsRefPtr<nsRange> range = selection->GetRangeAt(0); @@ -1274,17 +1274,17 @@ nsHTMLEditor::RebuildDocumentFromSource( // a valid close head appears after a found head if (foundhead && beginhead.get() > beginclosehead.get()) { foundclosehead = false; } // a valid close head appears before a found body if (foundbody && beginclosehead.get() > beginbody.get()) { foundclosehead = false; } - + // Time to change the document nsAutoEditBatch beginBatching(this); nsReadingIterator<char16_t> endtotal; aSourceString.EndReading(endtotal); nsresult res; if (foundhead) { @@ -1346,17 +1346,17 @@ nsHTMLEditor::RebuildDocumentFromSource( } res = LoadHTML(Substring(beginbody, endtotal)); NS_ENSURE_SUCCESS(res, res); // Now we must copy attributes user might have edited on the <body> tag // because InsertHTML (actually, CreateContextualFragment()) will never // return a body node in the DOM fragment - + // We already know where "<body" begins nsReadingIterator<char16_t> beginclosebody = beginbody; nsReadingIterator<char16_t> endclosebody; aSourceString.EndReading(endclosebody); if (!FindInReadable(NS_LITERAL_STRING(">"), beginclosebody, endclosebody)) { return NS_ERROR_FAILURE; } @@ -1372,55 +1372,55 @@ nsHTMLEditor::RebuildDocumentFromSource( ErrorResult rv; nsRefPtr<DocumentFragment> docfrag = range->CreateContextualFragment(bodyTag, rv); NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult()); NS_ENSURE_TRUE(docfrag, NS_ERROR_NULL_POINTER); nsCOMPtr<nsIContent> child = docfrag->GetFirstChild(); NS_ENSURE_TRUE(child && child->IsElement(), NS_ERROR_NULL_POINTER); - + // Copy all attributes from the div child to current body element CloneAttributes(bodyElement, child->AsElement()); - + // place selection at first editable content return BeginningOfDocument(); } void nsHTMLEditor::NormalizeEOLInsertPosition(nsIDOMNode *firstNodeToInsert, nsCOMPtr<nsIDOMNode> *insertParentNode, int32_t *insertOffset) { /* This function will either correct the position passed in, or leave the position unchanged. - When the (first) item to insert is a block level element, - and our insertion position is after the last visible item in a line, - i.e. the insertion position is just before a visible line break <br>, + When the (first) item to insert is a block level element, + and our insertion position is after the last visible item in a line, + i.e. the insertion position is just before a visible line break <br>, we want to skip to the position just after the line break (see bug 68767) However, our logic to detect whether we should skip or not needs to be more clever. We must not skip when the caret appears to be positioned at the beginning of a block, in that case skipping the <br> would not insert the <br> at the caret position, but after the current empty line. - + So we have several cases to test: - + 1) We only ever want to skip, if the next visible thing after the current position is a break - + 2) We do not want to skip if there is no previous visible thing at all That is detected if the call to PriorVisibleNode gives us an offset of zero. Because PriorVisibleNode always positions after the prior node, we would see an offset > 0, if there were a prior node. - + 3) We do not want to skip, if both the next and the previous visible things are breaks. - + 4) We do not want to skip if the previous visible thing is in a different block than the insertion position. */ if (!IsBlockNode(firstNodeToInsert)) return; nsWSRunObject wsObj(this, *insertParentNode, *insertOffset); @@ -1460,21 +1460,21 @@ nsHTMLEditor::NormalizeEOLInsertPosition NS_IMETHODIMP nsHTMLEditor::InsertElementAtSelection(nsIDOMElement* aElement, bool aDeleteSelection) { // Protect the edit rules object from dying nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules); nsresult res = NS_ERROR_NOT_INITIALIZED; - + NS_ENSURE_TRUE(aElement, NS_ERROR_NULL_POINTER); - + nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement); - + ForceCompositionEnd(); nsAutoEditBatch beginBatching(this); nsAutoRules beginRulesSniffing(this, EditAction::insertElement, nsIEditor::eNext); nsRefPtr<Selection> selection = GetSelection(); if (!selection) { return NS_ERROR_FAILURE; } @@ -1524,17 +1524,17 @@ nsHTMLEditor::InsertElementAtSelection(n // XXX: ERROR_HANDLING bad XPCOM usage if (NS_SUCCEEDED(res) && NS_SUCCEEDED(selection->GetAnchorOffset(&offsetForInsert)) && parentSelectedNode) { // Adjust position based on the node we are going to insert. NormalizeEOLInsertPosition(node, address_of(parentSelectedNode), &offsetForInsert); res = InsertNodeAtPoint(node, address_of(parentSelectedNode), &offsetForInsert, false); NS_ENSURE_SUCCESS(res, res); - // Set caret after element, but check for special case + // Set caret after element, but check for special case // of inserting table-related elements: set in first cell instead if (!SetCaretInTableCell(aElement)) { res = SetCaretAfterElement(aElement); NS_ENSURE_SUCCESS(res, res); } // check for inserting a whole table at the end of a block. If so insert a br after it. if (nsHTMLEditUtils::IsTable(node)) @@ -1552,48 +1552,48 @@ nsHTMLEditor::InsertElementAtSelection(n } } } res = mRules->DidDoAction(selection, &ruleInfo, res); return res; } -/* - InsertNodeAtPoint: attempts to insert aNode into the document, at a point specified by +/* + InsertNodeAtPoint: attempts to insert aNode into the document, at a point specified by {*ioParent,*ioOffset}. Checks with strict dtd to see if containment is allowed. If not allowed, will attempt to find a parent in the parent hierarchy of *ioParent that will accept aNode as a child. If such a parent is found, will split the document tree from {*ioParent,*ioOffset} up to parent, and then insert aNode. ioParent & ioOffset are then adjusted to point to the actual location that aNode was inserted at. aNoEmptyNodes specifies if the splitting process is allowed to reslt in empty nodes. nsIDOMNode *aNode node to insert nsCOMPtr<nsIDOMNode> *ioParent insertion parent int32_t *ioOffset insertion offset bool aNoEmptyNodes splitting can result in empty nodes? */ nsresult -nsHTMLEditor::InsertNodeAtPoint(nsIDOMNode *aNode, - nsCOMPtr<nsIDOMNode> *ioParent, - int32_t *ioOffset, +nsHTMLEditor::InsertNodeAtPoint(nsIDOMNode *aNode, + nsCOMPtr<nsIDOMNode> *ioParent, + int32_t *ioOffset, bool aNoEmptyNodes) { nsCOMPtr<nsIContent> node = do_QueryInterface(aNode); NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(ioParent, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(*ioParent, NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(ioOffset, NS_ERROR_NULL_POINTER); - + nsresult res = NS_OK; nsCOMPtr<nsINode> parent = do_QueryInterface(*ioParent); NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER); nsCOMPtr<nsINode> topChild = parent; int32_t offsetOfInsert = *ioOffset; - - // Search up the parent chain to find a suitable container + + // Search up the parent chain to find a suitable container while (!CanContain(*parent, *node)) { // If the current parent is a root (body or table element) // then go no further - we can't insert if (parent->IsHTMLElement(nsGkAtoms::body) || nsHTMLEditUtils::IsTableElement(parent)) { return NS_ERROR_FAILURE; } // Get the next parent @@ -1664,34 +1664,34 @@ nsHTMLEditor::SetCaretAfterElement(nsIDO NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER); int32_t offsetInParent = GetChildOffset(aElement, parent); // Collapse selection to just after desired element, res = selection->Collapse(parent, offsetInParent + 1); } return res; } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditor::SetParagraphFormat(const nsAString& aParagraphFormat) { nsAutoString tag; tag.Assign(aParagraphFormat); ToLowerCase(tag); if (tag.EqualsLiteral("dd") || tag.EqualsLiteral("dt")) return MakeDefinitionItem(tag); else return InsertBasicBlock(tag); } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditor::GetParagraphState(bool *aMixed, nsAString &outFormat) { if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER); nsRefPtr<nsHTMLEditRules> htmlRules = static_cast<nsHTMLEditRules*>(mRules.get()); - + return htmlRules->GetParagraphState(aMixed, outFormat); } NS_IMETHODIMP nsHTMLEditor::GetBackgroundColorState(bool *aMixed, nsAString &aOutColor) { nsresult res; if (IsCSSEnabled()) { @@ -1723,17 +1723,17 @@ nsHTMLEditor::GetHighlightColorState(boo nsresult nsHTMLEditor::GetCSSBackgroundColorState(bool *aMixed, nsAString &aOutColor, bool aBlockLevel) { NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER); *aMixed = false; // the default background color is transparent aOutColor.AssignLiteral("transparent"); - + // get selection nsRefPtr<Selection> selection = GetSelection(); NS_ENSURE_STATE(selection && selection->GetRangeAt(0)); // get selection location nsCOMPtr<nsINode> parent = selection->GetRangeAt(0)->GetStartParent(); int32_t offset = selection->GetRangeAt(0)->StartOffset(); NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER); @@ -1744,17 +1744,17 @@ nsHTMLEditor::GetCSSBackgroundColorState // we want to look at the parent and ancestors nodeToExamine = parent; } else { // otherwise we want to look at the first editable node after // {parent,offset} and its ancestors for divs with alignment on them nodeToExamine = parent->GetChildAt(offset); //GetNextNode(parent, offset, true, address_of(nodeToExamine)); } - + NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER); if (aBlockLevel) { // we are querying the block background (and not the text background), let's // climb to the block container nsCOMPtr<Element> blockParent; if (NodeIsBlockStatic(nodeToExamine)) { blockParent = nodeToExamine->AsElement(); @@ -1804,24 +1804,24 @@ nsHTMLEditor::GetCSSBackgroundColorState } } nodeToExamine = nodeToExamine->GetParentNode(); } while ( aOutColor.EqualsLiteral("transparent") && nodeToExamine ); } return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditor::GetHTMLBackgroundColorState(bool *aMixed, nsAString &aOutColor) { //TODO: We don't handle "mixed" correctly! NS_ENSURE_TRUE(aMixed, NS_ERROR_NULL_POINTER); *aMixed = false; aOutColor.Truncate(); - + nsCOMPtr<nsIDOMElement> domElement; int32_t selectedCount; nsAutoString tagName; nsresult res = GetSelectedOrParentTableElement(tagName, &selectedCount, getter_AddRefs(domElement)); NS_ENSURE_SUCCESS(res, res); @@ -1836,86 +1836,86 @@ nsHTMLEditor::GetHTMLBackgroundColorStat return NS_OK; } // Once we hit the body, we're done if (element->IsHTMLElement(nsGkAtoms::body)) { return NS_OK; } - // No color is set, but we need to report visible color inherited + // No color is set, but we need to report visible color inherited // from nested cells/tables, so search up parent chain element = element->GetParentElement(); } // If no table or cell found, get page body dom::Element* bodyElement = GetRoot(); NS_ENSURE_TRUE(bodyElement, NS_ERROR_NULL_POINTER); bodyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::bgcolor, aOutColor); return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditor::GetListState(bool *aMixed, bool *aOL, bool *aUL, bool *aDL) { if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } NS_ENSURE_TRUE(aMixed && aOL && aUL && aDL, NS_ERROR_NULL_POINTER); nsRefPtr<nsHTMLEditRules> htmlRules = static_cast<nsHTMLEditRules*>(mRules.get()); - + return htmlRules->GetListState(aMixed, aOL, aUL, aDL); } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditor::GetListItemState(bool *aMixed, bool *aLI, bool *aDT, bool *aDD) { if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } NS_ENSURE_TRUE(aMixed && aLI && aDT && aDD, NS_ERROR_NULL_POINTER); nsRefPtr<nsHTMLEditRules> htmlRules = static_cast<nsHTMLEditRules*>(mRules.get()); - + return htmlRules->GetListItemState(aMixed, aLI, aDT, aDD); } NS_IMETHODIMP nsHTMLEditor::GetAlignment(bool *aMixed, nsIHTMLEditor::EAlignment *aAlign) { if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } NS_ENSURE_TRUE(aMixed && aAlign, NS_ERROR_NULL_POINTER); nsRefPtr<nsHTMLEditRules> htmlRules = static_cast<nsHTMLEditRules*>(mRules.get()); - + return htmlRules->GetAlignment(aMixed, aAlign); } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLEditor::GetIndentState(bool *aCanIndent, bool *aCanOutdent) { if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } NS_ENSURE_TRUE(aCanIndent && aCanOutdent, NS_ERROR_NULL_POINTER); nsRefPtr<nsHTMLEditRules> htmlRules = static_cast<nsHTMLEditRules*>(mRules.get()); - + return htmlRules->GetIndentState(aCanIndent, aCanOutdent); } NS_IMETHODIMP nsHTMLEditor::MakeOrChangeList(const nsAString& aListType, bool entireList, const nsAString& aBulletType) { nsresult res; if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } // Protect the edit rules object from dying nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules); bool cancel, handled; nsAutoEditBatch beginBatching(this); nsAutoRules beginRulesSniffing(this, EditAction::makeList, nsIEditor::eNext);