mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 748307 part 4 - Clean up ExecCommand and QueryCommand*; r=ehsan
This commit is contained in:
parent
3163c8b65f
commit
fcfd499bd9
@ -3040,10 +3040,10 @@ nsHTMLDocument::DoClipboardSecurityCheck(bool aPaste)
|
|||||||
/* boolean execCommand(in DOMString commandID, in boolean doShowUI,
|
/* boolean execCommand(in DOMString commandID, in boolean doShowUI,
|
||||||
in DOMString value); */
|
in DOMString value); */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsHTMLDocument::ExecCommand(const nsAString & commandID,
|
nsHTMLDocument::ExecCommand(const nsAString& commandID,
|
||||||
bool doShowUI,
|
bool doShowUI,
|
||||||
const nsAString & value,
|
const nsAString& value,
|
||||||
bool *_retval)
|
bool* _retval)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(_retval);
|
NS_ENSURE_ARG_POINTER(_retval);
|
||||||
|
|
||||||
@ -3062,40 +3062,39 @@ nsHTMLDocument::ExecCommand(const nsAString & commandID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if editing is not on, bail
|
// if editing is not on, bail
|
||||||
if (!IsEditingOnAfterFlush())
|
NS_ENSURE_TRUE(IsEditingOnAfterFlush(), NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// if they are requesting UI from us, let's fail since we have no UI
|
// if they are requesting UI from us, let's fail since we have no UI
|
||||||
if (doShowUI)
|
if (doShowUI) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commandID.LowerCaseEqualsLiteral("gethtml")) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
if (commandID.LowerCaseEqualsLiteral("gethtml"))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
if (commandID.LowerCaseEqualsLiteral("cut") ||
|
if (commandID.LowerCaseEqualsLiteral("cut") ||
|
||||||
(commandID.LowerCaseEqualsLiteral("copy"))) {
|
commandID.LowerCaseEqualsLiteral("copy")) {
|
||||||
rv = DoClipboardSecurityCheck(false);
|
rv = DoClipboardSecurityCheck(false);
|
||||||
} else if (commandID.LowerCaseEqualsLiteral("paste")) {
|
} else if (commandID.LowerCaseEqualsLiteral("paste")) {
|
||||||
rv = DoClipboardSecurityCheck(true);
|
rv = DoClipboardSecurityCheck(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return rv;
|
|
||||||
|
|
||||||
// get command manager and dispatch command to our window if it's acceptable
|
// get command manager and dispatch command to our window if it's acceptable
|
||||||
nsCOMPtr<nsICommandManager> cmdMgr;
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
||||||
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
||||||
if (!cmdMgr)
|
NS_ENSURE_TRUE(cmdMgr, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsIDOMWindow *window = GetWindow();
|
nsIDOMWindow* window = GetWindow();
|
||||||
if (!window)
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
if ((cmdToDispatch.EqualsLiteral("cmd_paragraphState") ||
|
if ((cmdToDispatch.EqualsLiteral("cmd_paragraphState") ||
|
||||||
cmdToDispatch.EqualsLiteral("cmd_fontSize")) && paramStr.IsEmpty()) {
|
cmdToDispatch.EqualsLiteral("cmd_fontSize")) &&
|
||||||
|
paramStr.IsEmpty()) {
|
||||||
// Invalid value
|
// Invalid value
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
@ -3106,31 +3105,30 @@ nsHTMLDocument::ExecCommand(const nsAString & commandID,
|
|||||||
// we have a command that requires a parameter, create params
|
// we have a command that requires a parameter, create params
|
||||||
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
||||||
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
||||||
if (!cmdParams)
|
NS_ENSURE_TRUE(cmdParams, NS_ERROR_OUT_OF_MEMORY);
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
if (isBool)
|
if (isBool) {
|
||||||
rv = cmdParams->SetBooleanValue("state_attribute", boolVal);
|
rv = cmdParams->SetBooleanValue("state_attribute", boolVal);
|
||||||
else if (cmdToDispatch.Equals("cmd_fontFace"))
|
} else if (cmdToDispatch.EqualsLiteral("cmd_fontFace")) {
|
||||||
rv = cmdParams->SetStringValue("state_attribute", value);
|
rv = cmdParams->SetStringValue("state_attribute", value);
|
||||||
else if (cmdToDispatch.Equals("cmd_insertHTML"))
|
} else if (cmdToDispatch.EqualsLiteral("cmd_insertHTML")) {
|
||||||
rv = cmdParams->SetStringValue("state_data", value);
|
rv = cmdParams->SetStringValue("state_data", value);
|
||||||
else
|
} else {
|
||||||
rv = cmdParams->SetCStringValue("state_attribute", paramStr.get());
|
rv = cmdParams->SetCStringValue("state_attribute", paramStr.get());
|
||||||
if (NS_FAILED(rv))
|
}
|
||||||
return rv;
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
*_retval = NS_SUCCEEDED(rv);
|
*_retval = NS_SUCCEEDED(rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return rv;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* boolean queryCommandEnabled(in DOMString commandID); */
|
/* boolean queryCommandEnabled(in DOMString commandID); */
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsHTMLDocument::QueryCommandEnabled(const nsAString & commandID,
|
nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID,
|
||||||
bool *_retval)
|
bool* _retval)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(_retval);
|
NS_ENSURE_ARG_POINTER(_retval);
|
||||||
*_retval = false;
|
*_retval = false;
|
||||||
@ -3142,18 +3140,15 @@ nsHTMLDocument::QueryCommandEnabled(const nsAString & commandID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if editing is not on, bail
|
// if editing is not on, bail
|
||||||
if (!IsEditingOnAfterFlush())
|
NS_ENSURE_TRUE(IsEditingOnAfterFlush(), NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// get command manager and dispatch command to our window if it's acceptable
|
// get command manager and dispatch command to our window if it's acceptable
|
||||||
nsCOMPtr<nsICommandManager> cmdMgr;
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
||||||
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
||||||
if (!cmdMgr)
|
NS_ENSURE_TRUE(cmdMgr, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsIDOMWindow *window = GetWindow();
|
nsIDOMWindow* window = GetWindow();
|
||||||
if (!window)
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
return cmdMgr->IsCommandEnabled(cmdToDispatch.get(), window, _retval);
|
return cmdMgr->IsCommandEnabled(cmdToDispatch.get(), window, _retval);
|
||||||
}
|
}
|
||||||
@ -3173,18 +3168,15 @@ nsHTMLDocument::QueryCommandIndeterm(const nsAString & commandID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if editing is not on, bail
|
// if editing is not on, bail
|
||||||
if (!IsEditingOnAfterFlush())
|
NS_ENSURE_TRUE(IsEditingOnAfterFlush(), NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// get command manager and dispatch command to our window if it's acceptable
|
// get command manager and dispatch command to our window if it's acceptable
|
||||||
nsCOMPtr<nsICommandManager> cmdMgr;
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
||||||
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
||||||
if (!cmdMgr)
|
NS_ENSURE_TRUE(cmdMgr, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsIDOMWindow *window = GetWindow();
|
nsIDOMWindow* window = GetWindow();
|
||||||
if (!window)
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
||||||
@ -3192,8 +3184,7 @@ nsHTMLDocument::QueryCommandIndeterm(const nsAString & commandID,
|
|||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
||||||
if (NS_FAILED(rv))
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return rv;
|
|
||||||
|
|
||||||
// If command does not have a state_mixed value, this call fails and sets
|
// If command does not have a state_mixed value, this call fails and sets
|
||||||
// *_retval to false. This is fine -- we want to return false in that case
|
// *_retval to false. This is fine -- we want to return false in that case
|
||||||
@ -3219,18 +3210,15 @@ nsHTMLDocument::QueryCommandState(const nsAString & commandID, bool *_retval)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if editing is not on, bail
|
// if editing is not on, bail
|
||||||
if (!IsEditingOnAfterFlush())
|
NS_ENSURE_TRUE(IsEditingOnAfterFlush(), NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// get command manager and dispatch command to our window if it's acceptable
|
// get command manager and dispatch command to our window if it's acceptable
|
||||||
nsCOMPtr<nsICommandManager> cmdMgr;
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
||||||
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
||||||
if (!cmdMgr)
|
NS_ENSURE_TRUE(cmdMgr, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsIDOMWindow *window = GetWindow();
|
nsIDOMWindow* window = GetWindow();
|
||||||
if (!window)
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
if (commandID.LowerCaseEqualsLiteral("usecss")) {
|
if (commandID.LowerCaseEqualsLiteral("usecss")) {
|
||||||
// Per spec, state is supported for styleWithCSS but not useCSS, so we just
|
// Per spec, state is supported for styleWithCSS but not useCSS, so we just
|
||||||
@ -3242,12 +3230,10 @@ nsHTMLDocument::QueryCommandState(const nsAString & commandID, bool *_retval)
|
|||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
||||||
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
||||||
if (!cmdParams)
|
NS_ENSURE_TRUE(cmdParams, NS_ERROR_OUT_OF_MEMORY);
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
||||||
if (NS_FAILED(rv))
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return rv;
|
|
||||||
|
|
||||||
// handle alignment as a special case (possibly other commands too?)
|
// handle alignment as a special case (possibly other commands too?)
|
||||||
// Alignment is special because the external api is individual
|
// Alignment is special because the external api is individual
|
||||||
@ -3255,15 +3241,17 @@ nsHTMLDocument::QueryCommandState(const nsAString & commandID, bool *_retval)
|
|||||||
// parameters. When getting the state of this command, we need to
|
// parameters. When getting the state of this command, we need to
|
||||||
// return the boolean for this particular alignment rather than the
|
// return the boolean for this particular alignment rather than the
|
||||||
// string of 'which alignment is this?'
|
// string of 'which alignment is this?'
|
||||||
if (cmdToDispatch.Equals("cmd_align")) {
|
if (cmdToDispatch.EqualsLiteral("cmd_align")) {
|
||||||
char * actualAlignmentType = nsnull;
|
char * actualAlignmentType = nsnull;
|
||||||
rv = cmdParams->GetCStringValue("state_attribute", &actualAlignmentType);
|
rv = cmdParams->GetCStringValue("state_attribute", &actualAlignmentType);
|
||||||
if (NS_SUCCEEDED(rv) && actualAlignmentType && actualAlignmentType[0]) {
|
if (NS_SUCCEEDED(rv) && actualAlignmentType && actualAlignmentType[0]) {
|
||||||
*_retval = paramToCheck.Equals(actualAlignmentType);
|
*_retval = paramToCheck.Equals(actualAlignmentType);
|
||||||
}
|
}
|
||||||
if (actualAlignmentType)
|
if (actualAlignmentType) {
|
||||||
nsMemory::Free(actualAlignmentType);
|
nsMemory::Free(actualAlignmentType);
|
||||||
return rv;
|
}
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If command does not have a state_all value, this call fails and sets
|
// If command does not have a state_all value, this call fails and sets
|
||||||
@ -3301,46 +3289,41 @@ nsHTMLDocument::QueryCommandValue(const nsAString & commandID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if editing is not on, bail
|
// if editing is not on, bail
|
||||||
if (!IsEditingOnAfterFlush())
|
NS_ENSURE_TRUE(IsEditingOnAfterFlush(), NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// get command manager and dispatch command to our window if it's acceptable
|
// get command manager and dispatch command to our window if it's acceptable
|
||||||
nsCOMPtr<nsICommandManager> cmdMgr;
|
nsCOMPtr<nsICommandManager> cmdMgr;
|
||||||
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
GetMidasCommandManager(getter_AddRefs(cmdMgr));
|
||||||
if (!cmdMgr)
|
NS_ENSURE_TRUE(cmdMgr, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
nsIDOMWindow *window = GetWindow();
|
nsIDOMWindow* window = GetWindow();
|
||||||
if (!window)
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// create params
|
// create params
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
nsCOMPtr<nsICommandParams> cmdParams = do_CreateInstance(
|
||||||
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
NS_COMMAND_PARAMS_CONTRACTID, &rv);
|
||||||
if (!cmdParams)
|
NS_ENSURE_TRUE(cmdParams, NS_ERROR_OUT_OF_MEMORY);
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
// this is a special command since we are calling "DoCommand rather than
|
// this is a special command since we are calling DoCommand rather than
|
||||||
// GetCommandState like the other commands
|
// GetCommandState like the other commands
|
||||||
if (cmdToDispatch.Equals("cmd_getContents"))
|
if (cmdToDispatch.EqualsLiteral("cmd_getContents")) {
|
||||||
{
|
|
||||||
rv = cmdParams->SetBooleanValue("selection_only", true);
|
rv = cmdParams->SetBooleanValue("selection_only", true);
|
||||||
if (NS_FAILED(rv)) return rv;
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
rv = cmdParams->SetCStringValue("format", "text/html");
|
rv = cmdParams->SetCStringValue("format", "text/html");
|
||||||
if (NS_FAILED(rv)) return rv;
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
|
rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
|
||||||
if (NS_FAILED(rv)) return rv;
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return cmdParams->GetStringValue("result", _retval);
|
rv = cmdParams->GetStringValue("result", _retval);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = cmdParams->SetCStringValue("state_attribute", paramStr.get());
|
rv = cmdParams->SetCStringValue("state_attribute", paramStr.get());
|
||||||
if (NS_FAILED(rv))
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return rv;
|
|
||||||
|
|
||||||
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
rv = cmdMgr->GetCommandState(cmdToDispatch.get(), window, cmdParams);
|
||||||
if (NS_FAILED(rv))
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
return rv;
|
|
||||||
|
|
||||||
// If command does not have a state_attribute value, this call fails, and
|
// If command does not have a state_attribute value, this call fails, and
|
||||||
// _retval will wind up being the empty string. This is fine -- we want to
|
// _retval will wind up being the empty string. This is fine -- we want to
|
||||||
|
Loading…
Reference in New Issue
Block a user