зеркало из https://github.com/mozilla/pjs.git
Fixes for 48474 (JS errors typing in plain text compose), 44684 (make align buttons reflect state), 49155 (UMR in editor code). r=anthonyd
This commit is contained in:
Родитель
e7f5570974
Коммит
e709e5e99e
|
@ -129,7 +129,14 @@ nsBaseStateUpdatingCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISuppo
|
|||
*outCmdEnabled = !sourceMode;
|
||||
|
||||
// also udpate the command state
|
||||
return UpdateCommandState(aCommand, refCon);
|
||||
nsresult rv = UpdateCommandState(aCommand, refCon);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
*outCmdEnabled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -454,6 +461,7 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam
|
|||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRemoveListCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
|
||||
{
|
||||
|
@ -595,7 +603,13 @@ nsMultiStateCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * r
|
|||
}
|
||||
}
|
||||
|
||||
return UpdateCommandState(aCommand, refCon);
|
||||
nsresult rv = UpdateCommandState(aCommand, refCon);
|
||||
if (NS_FAILED(rv)) {
|
||||
*outCmdEnabled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -840,44 +854,62 @@ nsBackgroundColorStateCommand::SetState(nsIEditorShell *aEditorShell, nsString&
|
|||
#pragma mark -
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAlignCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
|
||||
nsAlignCommand::nsAlignCommand()
|
||||
: nsMultiStateCommand()
|
||||
{
|
||||
nsCOMPtr<nsIEditorShell> editorShell = do_QueryInterface(refCon);
|
||||
*outCmdEnabled = PR_FALSE;
|
||||
if (editorShell)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAlignCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed)
|
||||
{
|
||||
NS_ASSERTION(aEditorShell, "Need an editor shell here");
|
||||
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIHTMLEditor::EAlignment firstAlign;
|
||||
nsresult rv = htmlEditor->GetAlignment(outMixed, firstAlign);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
switch (firstAlign)
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
editorShell->GetEditor(getter_AddRefs(editor));
|
||||
if (editor)
|
||||
{
|
||||
*outCmdEnabled = PR_TRUE;
|
||||
}
|
||||
default:
|
||||
case nsIHTMLEditor::eLeft:
|
||||
outStateString.AssignWithConversion("left");
|
||||
break;
|
||||
|
||||
case nsIHTMLEditor::eCenter:
|
||||
outStateString.AssignWithConversion("center");
|
||||
break;
|
||||
|
||||
case nsIHTMLEditor::eRight:
|
||||
outStateString.AssignWithConversion("right");
|
||||
break;
|
||||
|
||||
case nsIHTMLEditor::eJustify:
|
||||
outStateString.AssignWithConversion("justify");
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAlignCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
|
||||
nsresult
|
||||
nsAlignCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState)
|
||||
{
|
||||
nsCOMPtr<nsIEditorShell> editorShell = do_QueryInterface(refCon);
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (editorShell)
|
||||
{
|
||||
// we have to grab the state attribute on our command node to find out
|
||||
// what format to set the paragraph to
|
||||
nsAutoString stateAttribute;
|
||||
rv = GetCommandNodeState(aCommand, editorShell, stateAttribute);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = editorShell->Align(stateAttribute.GetUnicode());
|
||||
}
|
||||
NS_ASSERTION(aEditorShell, "Need an editor shell here");
|
||||
|
||||
return rv;
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_FAILURE;
|
||||
|
||||
return htmlEditor->Align(newState);
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
|
|
@ -207,6 +207,17 @@ protected:
|
|||
virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState);
|
||||
};
|
||||
|
||||
class nsAlignCommand : public nsMultiStateCommand
|
||||
{
|
||||
public:
|
||||
nsAlignCommand();
|
||||
|
||||
protected:
|
||||
|
||||
virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed);
|
||||
virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState);
|
||||
};
|
||||
|
||||
class nsBackgroundColorStateCommand : public nsMultiStateCommand
|
||||
{
|
||||
public:
|
||||
|
@ -239,7 +250,6 @@ NS_DECL_COMPOSER_COMMAND(nsPasteQuotationCommand)
|
|||
NS_DECL_COMPOSER_COMMAND(nsIndentCommand)
|
||||
NS_DECL_COMPOSER_COMMAND(nsOutdentCommand)
|
||||
|
||||
NS_DECL_COMPOSER_COMMAND(nsAlignCommand)
|
||||
NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand)
|
||||
NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
|
||||
NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
|
||||
|
|
|
@ -4120,6 +4120,8 @@ NS_IMETHODIMP nsEditor::IncDocModCount(PRInt32 inNumMods)
|
|||
NS_IMETHODIMP nsEditor::GetDocModCount(PRInt32 &outModCount)
|
||||
{
|
||||
if (!mDocWeak) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
outModCount = 0;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
|
||||
if (!doc) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
|
|
@ -488,6 +488,7 @@ nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)
|
|||
// this routine assumes that alignment is done ONLY via divs
|
||||
|
||||
// default alignment is left
|
||||
aMixed = PR_FALSE;
|
||||
aAlign = nsIHTMLEditor::eLeft;
|
||||
|
||||
// get selection
|
||||
|
@ -546,6 +547,8 @@ nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)
|
|||
aAlign = nsIHTMLEditor::eCenter;
|
||||
else if (typeAttrVal.EqualsWithConversion("right"))
|
||||
aAlign = nsIHTMLEditor::eRight;
|
||||
else if (typeAttrVal.EqualsWithConversion("justify"))
|
||||
aAlign = nsIHTMLEditor::eJustify;
|
||||
else
|
||||
aAlign = nsIHTMLEditor::eLeft;
|
||||
return res;
|
||||
|
|
|
@ -42,7 +42,6 @@ nsHTMLEditUtils::IsBody(nsIDOMNode *node)
|
|||
{
|
||||
nsAutoString tag;
|
||||
nsEditor::GetTagString(node,tag);
|
||||
tag.ToLowerCase();
|
||||
if (tag.EqualsWithConversion("body"))
|
||||
{
|
||||
return PR_TRUE;
|
||||
|
|
|
@ -129,7 +129,14 @@ nsBaseStateUpdatingCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISuppo
|
|||
*outCmdEnabled = !sourceMode;
|
||||
|
||||
// also udpate the command state
|
||||
return UpdateCommandState(aCommand, refCon);
|
||||
nsresult rv = UpdateCommandState(aCommand, refCon);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
*outCmdEnabled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -454,6 +461,7 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam
|
|||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRemoveListCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
|
||||
{
|
||||
|
@ -595,7 +603,13 @@ nsMultiStateCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * r
|
|||
}
|
||||
}
|
||||
|
||||
return UpdateCommandState(aCommand, refCon);
|
||||
nsresult rv = UpdateCommandState(aCommand, refCon);
|
||||
if (NS_FAILED(rv)) {
|
||||
*outCmdEnabled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -840,44 +854,62 @@ nsBackgroundColorStateCommand::SetState(nsIEditorShell *aEditorShell, nsString&
|
|||
#pragma mark -
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAlignCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
|
||||
nsAlignCommand::nsAlignCommand()
|
||||
: nsMultiStateCommand()
|
||||
{
|
||||
nsCOMPtr<nsIEditorShell> editorShell = do_QueryInterface(refCon);
|
||||
*outCmdEnabled = PR_FALSE;
|
||||
if (editorShell)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAlignCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed)
|
||||
{
|
||||
NS_ASSERTION(aEditorShell, "Need an editor shell here");
|
||||
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_FAILURE;
|
||||
|
||||
nsIHTMLEditor::EAlignment firstAlign;
|
||||
nsresult rv = htmlEditor->GetAlignment(outMixed, firstAlign);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
switch (firstAlign)
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
editorShell->GetEditor(getter_AddRefs(editor));
|
||||
if (editor)
|
||||
{
|
||||
*outCmdEnabled = PR_TRUE;
|
||||
}
|
||||
default:
|
||||
case nsIHTMLEditor::eLeft:
|
||||
outStateString.AssignWithConversion("left");
|
||||
break;
|
||||
|
||||
case nsIHTMLEditor::eCenter:
|
||||
outStateString.AssignWithConversion("center");
|
||||
break;
|
||||
|
||||
case nsIHTMLEditor::eRight:
|
||||
outStateString.AssignWithConversion("right");
|
||||
break;
|
||||
|
||||
case nsIHTMLEditor::eJustify:
|
||||
outStateString.AssignWithConversion("justify");
|
||||
break;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAlignCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
|
||||
nsresult
|
||||
nsAlignCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState)
|
||||
{
|
||||
nsCOMPtr<nsIEditorShell> editorShell = do_QueryInterface(refCon);
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (editorShell)
|
||||
{
|
||||
// we have to grab the state attribute on our command node to find out
|
||||
// what format to set the paragraph to
|
||||
nsAutoString stateAttribute;
|
||||
rv = GetCommandNodeState(aCommand, editorShell, stateAttribute);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = editorShell->Align(stateAttribute.GetUnicode());
|
||||
}
|
||||
NS_ASSERTION(aEditorShell, "Need an editor shell here");
|
||||
|
||||
return rv;
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_FAILURE;
|
||||
|
||||
return htmlEditor->Align(newState);
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
|
|
@ -207,6 +207,17 @@ protected:
|
|||
virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState);
|
||||
};
|
||||
|
||||
class nsAlignCommand : public nsMultiStateCommand
|
||||
{
|
||||
public:
|
||||
nsAlignCommand();
|
||||
|
||||
protected:
|
||||
|
||||
virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed);
|
||||
virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState);
|
||||
};
|
||||
|
||||
class nsBackgroundColorStateCommand : public nsMultiStateCommand
|
||||
{
|
||||
public:
|
||||
|
@ -239,7 +250,6 @@ NS_DECL_COMPOSER_COMMAND(nsPasteQuotationCommand)
|
|||
NS_DECL_COMPOSER_COMMAND(nsIndentCommand)
|
||||
NS_DECL_COMPOSER_COMMAND(nsOutdentCommand)
|
||||
|
||||
NS_DECL_COMPOSER_COMMAND(nsAlignCommand)
|
||||
NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand)
|
||||
NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
|
||||
NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
|
||||
|
|
|
@ -4120,6 +4120,8 @@ NS_IMETHODIMP nsEditor::IncDocModCount(PRInt32 inNumMods)
|
|||
NS_IMETHODIMP nsEditor::GetDocModCount(PRInt32 &outModCount)
|
||||
{
|
||||
if (!mDocWeak) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
outModCount = 0;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> doc = do_QueryReferent(mDocWeak);
|
||||
if (!doc) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
|
|
@ -488,6 +488,7 @@ nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)
|
|||
// this routine assumes that alignment is done ONLY via divs
|
||||
|
||||
// default alignment is left
|
||||
aMixed = PR_FALSE;
|
||||
aAlign = nsIHTMLEditor::eLeft;
|
||||
|
||||
// get selection
|
||||
|
@ -546,6 +547,8 @@ nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)
|
|||
aAlign = nsIHTMLEditor::eCenter;
|
||||
else if (typeAttrVal.EqualsWithConversion("right"))
|
||||
aAlign = nsIHTMLEditor::eRight;
|
||||
else if (typeAttrVal.EqualsWithConversion("justify"))
|
||||
aAlign = nsIHTMLEditor::eJustify;
|
||||
else
|
||||
aAlign = nsIHTMLEditor::eLeft;
|
||||
return res;
|
||||
|
|
|
@ -42,7 +42,6 @@ nsHTMLEditUtils::IsBody(nsIDOMNode *node)
|
|||
{
|
||||
nsAutoString tag;
|
||||
nsEditor::GetTagString(node,tag);
|
||||
tag.ToLowerCase();
|
||||
if (tag.EqualsWithConversion("body"))
|
||||
{
|
||||
return PR_TRUE;
|
||||
|
|
|
@ -87,7 +87,8 @@ public:
|
|||
typedef enum {
|
||||
eLeft,
|
||||
eCenter,
|
||||
eRight
|
||||
eRight,
|
||||
eJustify
|
||||
} EAlignment;
|
||||
|
||||
/* ------------ Document info methods -------------- */
|
||||
|
|
|
@ -774,13 +774,18 @@ var nsObjectPropertiesCommand =
|
|||
{
|
||||
isCommandEnabled: function(aCommand, dummy)
|
||||
{
|
||||
var isEnabled = false;
|
||||
if (window.editorShell && window.editorShell.documentEditable)
|
||||
{
|
||||
try {
|
||||
// Launch Object properties for appropriate selected element
|
||||
return (GetSelectedElementOrParentCellOrLink() != null ||
|
||||
window.editorShell.GetSelectedElement("href") != null);
|
||||
isEnabled = (GetSelectedElementOrParentCellOrLink() != null ||
|
||||
window.editorShell.GetSelectedElement("href") != null);
|
||||
} catch(e)
|
||||
{
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return isEnabled;
|
||||
},
|
||||
doCommand: function(aCommand)
|
||||
{
|
||||
|
|
|
@ -1682,6 +1682,16 @@ function onButtonUpdate(button, commmandID)
|
|||
button.setAttribute("toggled", state);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
function onStateButtonUpdate(button, commmandID, onState)
|
||||
{
|
||||
// dump(" === onButtonUpdate called\n");
|
||||
var commandNode = document.getElementById(commmandID);
|
||||
var state = commandNode.getAttribute("state");
|
||||
|
||||
button.setAttribute("toggled", (state == onState) ? "true" : "false");
|
||||
}
|
||||
|
||||
|
||||
// --------------------------- Status calls ---------------------------
|
||||
function onStyleChange(theStyle)
|
||||
|
@ -1724,20 +1734,6 @@ function onDirtyChange()
|
|||
}
|
||||
}
|
||||
|
||||
function onListFormatChange(listType)
|
||||
{
|
||||
var theButton = document.getElementById(listType + "Button");
|
||||
if (theButton)
|
||||
{
|
||||
var isOn = theButton.getAttribute(listType);
|
||||
if (isOn == "true") {
|
||||
theButton.setAttribute("toggled", "true");
|
||||
} else {
|
||||
theButton.setAttribute("toggled", "false");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getColorAndSetColorWell(ColorPickerID, ColorWellID)
|
||||
{
|
||||
var colorWell;
|
||||
|
|
|
@ -747,10 +747,18 @@
|
|||
tooltip="aTooltip" tooltiptext="&AlignPopupButton.tooltip;"/>
|
||||
|
||||
<!-- alignment buttons -->
|
||||
<button class="button-toolbar" id="align-left-button" oncommand="doStatefulCommand('cmd_align', 'left')"/>
|
||||
<button class="button-toolbar" id="align-center-button" oncommand="doStatefulCommand('cmd_align', 'center')"/>
|
||||
<button class="button-toolbar" id="align-right-button" oncommand="doStatefulCommand('cmd_align', 'right')"/>
|
||||
<button class="button-toolbar" id="align-justify-button" oncommand="doStatefulCommand('cmd_align', 'justify')"/>
|
||||
<button class="button-toolbar" id="align-left-button" oncommand="doStatefulCommand('cmd_align', 'left')">
|
||||
<observes element="cmd_align" attribute="state" onbroadcast="onStateButtonUpdate(this.parentNode, 'cmd_align', 'left')"/>
|
||||
</button>
|
||||
<button class="button-toolbar" id="align-center-button" oncommand="doStatefulCommand('cmd_align', 'center')">
|
||||
<observes element="cmd_align" attribute="state" onbroadcast="onStateButtonUpdate(this.parentNode, 'cmd_align', 'center')"/>
|
||||
</button>
|
||||
<button class="button-toolbar" id="align-right-button" oncommand="doStatefulCommand('cmd_align', 'right')">
|
||||
<observes element="cmd_align" attribute="state" onbroadcast="onStateButtonUpdate(this.parentNode, 'cmd_align', 'right')"/>
|
||||
</button>
|
||||
<button class="button-toolbar" id="align-justify-button" oncommand="doStatefulCommand('cmd_align', 'justify')">
|
||||
<observes element="cmd_align" attribute="state" onbroadcast="onStateButtonUpdate(this.parentNode, 'cmd_align', 'justify')"/>
|
||||
</button>
|
||||
|
||||
<!-- Edit Mode toolbar -->
|
||||
<button id="NormalModeButton" class="edit-mode _plain" type="text" selected="1" value="&NormalModeTab.label;" onclick="SetEditMode(1)"
|
||||
|
|
Загрузка…
Ссылка в новой задаче