зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1503473 - part 5: Move InsertParagraphSeparator*() into HTMLEditor r=m_kato
Now, TextEditor needs only InsertLineBreak*() so that InsertParagraphSeparator*() is necessary only in HTMLEditor. With overriding nsIPlaintextEditor::InsertLineBreak() in HTMLEditor, we can do it simply. Differential Revision: https://phabricator.services.mozilla.com/D10525 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
b1587d8dd4
Коммит
d481dba0c1
|
@ -1178,9 +1178,11 @@ InsertParagraphCommand::DoCommand(const char* aCommandName,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
TextEditor* textEditor = editor->AsTextEditor();
|
||||
MOZ_ASSERT(textEditor);
|
||||
return textEditor->InsertParagraphSeparatorAsAction();
|
||||
HTMLEditor* htmlEditor = editor->AsHTMLEditor();
|
||||
if (!htmlEditor) {
|
||||
return NS_OK; // Do nothing for now.
|
||||
}
|
||||
return htmlEditor->InsertParagraphSeparatorAsAction();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -1122,6 +1122,18 @@ HTMLEditor::UpdateBaseURL()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HTMLEditor::InsertLineBreak()
|
||||
{
|
||||
// XPCOM method's InsertLineBreak() should insert paragraph separator in
|
||||
// HTMLEditor.
|
||||
nsresult rv = InsertParagraphSeparatorAsSubAction();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLEditor::InsertLineBreakAsAction()
|
||||
{
|
||||
|
@ -1130,6 +1142,8 @@ HTMLEditor::InsertLineBreakAsAction()
|
|||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
// XXX This method may be called by "insertLineBreak" command. So, using
|
||||
// TypingTxnName here is odd in such case.
|
||||
AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName);
|
||||
nsresult rv = InsertBrElementAtSelectionWithTransaction();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -1138,6 +1152,61 @@ HTMLEditor::InsertLineBreakAsAction()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLEditor::InsertParagraphSeparatorAsAction()
|
||||
{
|
||||
AutoEditActionDataSetter editActionData(
|
||||
*this,
|
||||
EditAction::eInsertParagraphSeparator);
|
||||
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
// XXX This may be called by execCommand() with "insertParagraph".
|
||||
// In such case, naming the transaction "TypingTxnName" is odd.
|
||||
AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName);
|
||||
nsresult rv = InsertParagraphSeparatorAsSubAction();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLEditor::InsertParagraphSeparatorAsSubAction()
|
||||
{
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
if (!mRules) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
// Protect the edit rules object from dying
|
||||
RefPtr<TextEditRules> rules(mRules);
|
||||
|
||||
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
|
||||
*this,
|
||||
EditSubAction::eInsertParagraphSeparator,
|
||||
nsIEditor::eNext);
|
||||
|
||||
EditSubActionInfo subActionInfo(EditSubAction::eInsertParagraphSeparator);
|
||||
subActionInfo.maxLength = mMaxTextLength;
|
||||
bool cancel, handled;
|
||||
nsresult rv = rules->WillDoAction(subActionInfo, &cancel, &handled);
|
||||
if (cancel) {
|
||||
return rv; // We don't need to call DidDoAction() if canceled.
|
||||
}
|
||||
// XXX DidDoAction() does nothing for eInsertParagraphSeparator. However,
|
||||
// we should call it until we keep using this style. Perhaps, each
|
||||
// editor method should call necessary method of
|
||||
// TextEditRules/HTMLEditRules directly.
|
||||
rv = rules->DidDoAction(subActionInfo, rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLEditor::TabInTable(bool inIsShift,
|
||||
bool* outHandled)
|
||||
|
|
|
@ -139,6 +139,8 @@ public:
|
|||
|
||||
NS_IMETHOD DeleteNode(nsINode* aNode) override;
|
||||
|
||||
NS_IMETHOD InsertLineBreak() override;
|
||||
|
||||
virtual nsresult HandleKeyPressEvent(
|
||||
WidgetKeyboardEvent* aKeyboardEvent) override;
|
||||
virtual nsIContent* GetFocusedContent() override;
|
||||
|
@ -176,6 +178,12 @@ public:
|
|||
*/
|
||||
virtual nsresult InsertLineBreakAsAction() override;
|
||||
|
||||
/**
|
||||
* InsertParagraphSeparatorAsAction() is called when user tries to separate
|
||||
* current paragraph with Enter key press in HTMLEditor or something.
|
||||
*/
|
||||
nsresult InsertParagraphSeparatorAsAction();
|
||||
|
||||
/**
|
||||
* CreateElementWithDefaults() creates new element whose name is
|
||||
* aTagName with some default attributes are set. Note that this is a
|
||||
|
@ -998,6 +1006,12 @@ protected: // Called by helper classes.
|
|||
protected: // Shouldn't be used by friend classes
|
||||
virtual ~HTMLEditor();
|
||||
|
||||
/**
|
||||
* InsertParagraphSeparatorAsSubAction() inserts a line break if it's
|
||||
* HTMLEditor and it's possible.
|
||||
*/
|
||||
nsresult InsertParagraphSeparatorAsSubAction();
|
||||
|
||||
virtual nsresult SelectAllInternal() override;
|
||||
|
||||
/**
|
||||
|
|
|
@ -460,26 +460,6 @@ TextEditor::InsertLineBreakAsAction()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TextEditor::InsertParagraphSeparatorAsAction()
|
||||
{
|
||||
AutoEditActionDataSetter editActionData(
|
||||
*this,
|
||||
EditAction::eInsertParagraphSeparator);
|
||||
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
// XXX This may be called by execCommand() with "insertParagraph".
|
||||
// In such case, naming the transaction "TypingTxnName" is odd.
|
||||
AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName);
|
||||
nsresult rv = InsertParagraphSeparatorAsSubAction();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
template<typename PT, typename CT>
|
||||
already_AddRefed<Element>
|
||||
TextEditor::InsertBrElementWithTransaction(
|
||||
|
@ -1090,23 +1070,13 @@ TextEditor::InsertTextAsSubAction(const nsAString& aStringToInsert)
|
|||
NS_IMETHODIMP
|
||||
TextEditor::InsertLineBreak()
|
||||
{
|
||||
EditAction editAction =
|
||||
AsHTMLEditor() ? EditAction::eInsertParagraphSeparator :
|
||||
EditAction::eInsertLineBreak;
|
||||
AutoEditActionDataSetter editActionData(*this, editAction);
|
||||
AutoEditActionDataSetter editActionData(*this, EditAction::eInsertLineBreak);
|
||||
if (NS_WARN_IF(!editActionData.CanHandle())) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
AutoPlaceholderBatch treatAsOneTransaction(*this);
|
||||
if (editAction == EditAction::eInsertLineBreak) {
|
||||
nsresult rv = InsertLineBreakAsSubAction();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult rv = InsertParagraphSeparatorAsSubAction();
|
||||
nsresult rv = InsertLineBreakAsSubAction();
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -1148,41 +1118,6 @@ TextEditor::InsertLineBreakAsSubAction()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TextEditor::InsertParagraphSeparatorAsSubAction()
|
||||
{
|
||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||
|
||||
if (!mRules) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
// Protect the edit rules object from dying
|
||||
RefPtr<TextEditRules> rules(mRules);
|
||||
|
||||
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
|
||||
*this,
|
||||
EditSubAction::eInsertParagraphSeparator,
|
||||
nsIEditor::eNext);
|
||||
|
||||
EditSubActionInfo subActionInfo(EditSubAction::eInsertParagraphSeparator);
|
||||
subActionInfo.maxLength = mMaxTextLength;
|
||||
bool cancel, handled;
|
||||
nsresult rv = rules->WillDoAction(subActionInfo, &cancel, &handled);
|
||||
if (cancel) {
|
||||
return rv; // We don't need to call DidDoAction() if canceled.
|
||||
}
|
||||
// XXX DidDoAction() does nothing for eInsertParagraphSeparator. However,
|
||||
// we should call it until we keep using this style. Perhaps, each
|
||||
// editor method should call necessary method of
|
||||
// TextEditRules/HTMLEditRules directly.
|
||||
rv = rules->DidDoAction(subActionInfo, rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TextEditor::SetText(const nsAString& aString)
|
||||
{
|
||||
|
|
|
@ -192,12 +192,6 @@ public:
|
|||
*/
|
||||
virtual nsresult InsertLineBreakAsAction();
|
||||
|
||||
/**
|
||||
* InsertParagraphSeparatorAsAction() is called when user tries to separate
|
||||
* current paragraph with Enter key press in HTMLEditor or something.
|
||||
*/
|
||||
nsresult InsertParagraphSeparatorAsAction();
|
||||
|
||||
/**
|
||||
* OnCompositionStart() is called when editor receives eCompositionStart
|
||||
* event which should be handled in this editor.
|
||||
|
@ -387,12 +381,6 @@ protected: // Shouldn't be used by friend classes
|
|||
*/
|
||||
nsresult InsertLineBreakAsSubAction();
|
||||
|
||||
/**
|
||||
* InsertParagraphSeparatorAsSubAction() inserts a line break if it's
|
||||
* HTMLEditor and it's possible.
|
||||
*/
|
||||
nsresult InsertParagraphSeparatorAsSubAction();
|
||||
|
||||
nsresult InsertTextAt(const nsAString& aStringToInsert,
|
||||
nsINode* aDestinationNode,
|
||||
int32_t aDestOffset,
|
||||
|
|
Загрузка…
Ссылка в новой задаче