mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Fix for 41034 - new list submenu command support for doing DL lists. r=sfraser, a=beppe
This commit is contained in:
parent
7ebb2f9065
commit
946b869f76
@ -403,26 +403,16 @@ nsresult
|
||||
nsListCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagName, PRBool& outInList)
|
||||
{
|
||||
NS_ASSERTION(aEditorShell, "Need editorShell here");
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
if (!editor) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// tagStr will hold the list state when we're done.
|
||||
nsAutoString tagStr;
|
||||
PRBool bMixed, bOL, bUL, bDL;
|
||||
nsresult rv = htmlEditor->GetListState(bMixed, bOL, bUL, bDL);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!bMixed)
|
||||
{
|
||||
if (bOL) tagStr.AssignWithConversion("ol");
|
||||
else if (bUL) tagStr.AssignWithConversion("ul");
|
||||
else if (bDL) tagStr.AssignWithConversion("dl");
|
||||
}
|
||||
|
||||
outInList = tagStr.EqualsWithConversion(mTagName);
|
||||
PRBool bMixed;
|
||||
PRUnichar *tagStr;
|
||||
nsresult rv = aEditorShell->GetListState(&bMixed, &tagStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
outInList = (0 == nsCRT::strcmp(tagStr, aTagName));
|
||||
|
||||
if (tagStr) nsCRT::free(tagStr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -433,8 +423,9 @@ nsListCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName)
|
||||
PRBool inList;
|
||||
nsresult rv = GetCurrentState(aEditorShell, aTagName, inList);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
nsAutoString listType; listType.AssignWithConversion(aTagName);
|
||||
|
||||
if (inList)
|
||||
rv = aEditorShell->RemoveList(listType.GetUnicode());
|
||||
else
|
||||
@ -444,6 +435,77 @@ nsListCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName)
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
nsListItemCommand::nsListItemCommand(const char* aTagName)
|
||||
: nsBaseStateUpdatingCommand(aTagName)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsListItemCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagName, PRBool& outInList)
|
||||
{
|
||||
NS_ASSERTION(aEditorShell, "Need editorShell here");
|
||||
|
||||
PRBool bMixed;
|
||||
PRUnichar *tagStr;
|
||||
nsresult rv = aEditorShell->GetListItemState(&bMixed, &tagStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
outInList = (0 == nsCRT::strcmp(tagStr, aTagName));
|
||||
|
||||
if (tagStr) nsCRT::free(tagStr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName)
|
||||
{
|
||||
NS_ASSERTION(aEditorShell, "Need editorShell here");
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
if (!editor) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
PRBool inList;
|
||||
nsresult rv = GetCurrentState(aEditorShell, aTagName, inList);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (inList)
|
||||
{
|
||||
// To remove a list, first get what kind of list we're in
|
||||
PRBool bMixed;
|
||||
PRUnichar *tagStr;
|
||||
rv = aEditorShell->GetListState(&bMixed, &tagStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (tagStr)
|
||||
{
|
||||
if (!bMixed)
|
||||
{
|
||||
nsAutoString listType(tagStr);
|
||||
rv = htmlEditor->RemoveList(listType);
|
||||
}
|
||||
nsCRT::free(tagStr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsAutoString itemType; itemType.AssignWithConversion(aTagName);
|
||||
// Set to the requested paragraph type
|
||||
//XXX Note: This actually doesn't work for "LI",
|
||||
// but we currently don't use this for non DL lists anyway.
|
||||
// Problem: won't this replace any current block paragraph style?
|
||||
rv = htmlEditor->SetParagraphFormat(itemType);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
@ -623,18 +685,6 @@ nsParagraphStateCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString&
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_FAILURE;
|
||||
#if 0
|
||||
// some proof of concept code for list item state.
|
||||
// Just leaving in for Charlie to see.
|
||||
PRBool bLI,bDT,bDD;
|
||||
htmlEditor->GetListItemState(outMixed, bLI, bDT, bDD);
|
||||
if (!outMixed && (bDT || bDD))
|
||||
{
|
||||
if (bDT) outStateString.AssignWithConversion("DT");
|
||||
if (bDD) outStateString.AssignWithConversion("DD");
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
return htmlEditor->GetParagraphState(outMixed, outStateString);
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,20 @@ protected:
|
||||
virtual nsresult ToggleState(nsIEditorShell *aEditorShell, const char* aTagName);
|
||||
};
|
||||
|
||||
class nsListItemCommand : public nsBaseStateUpdatingCommand
|
||||
{
|
||||
public:
|
||||
|
||||
nsListItemCommand(const char* aTagName);
|
||||
|
||||
protected:
|
||||
|
||||
// get the current state (on or off) for this style or block format
|
||||
virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagName, PRBool& outStateSet);
|
||||
|
||||
// add/remove the style
|
||||
virtual nsresult ToggleState(nsIEditorShell *aEditorShell, const char* aTagName);
|
||||
};
|
||||
|
||||
// Base class for commands whose state consists of a string (e.g. para format)
|
||||
class nsMultiStateCommand : public nsBaseComposerCommand,
|
||||
|
@ -324,6 +324,8 @@ nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandMana
|
||||
// lists
|
||||
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", "dt");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", "dd");
|
||||
|
||||
// format stuff
|
||||
NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");
|
||||
|
@ -1166,6 +1166,83 @@ nsEditorShell::SetBackgroundColor(const PRUnichar *color)
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetParagraphState(PRBool *aMixed, PRUnichar **_retval)
|
||||
{
|
||||
if (!aMixed || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
*_retval = nsnull;
|
||||
*aMixed = PR_FALSE;
|
||||
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
|
||||
if (htmlEditor)
|
||||
{
|
||||
PRBool bMixed;
|
||||
nsAutoString state;
|
||||
err = htmlEditor->GetParagraphState(bMixed, state);
|
||||
if (!bMixed)
|
||||
*_retval = state.ToNewUnicode();
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetListState(PRBool *aMixed, PRUnichar **_retval)
|
||||
{
|
||||
if (!aMixed || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
*_retval = nsnull;
|
||||
*aMixed = PR_FALSE;
|
||||
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
{
|
||||
PRBool bOL, bUL, bDL;
|
||||
err = htmlEditor->GetListState(*aMixed, bOL, bUL, bDL);
|
||||
if (NS_SUCCEEDED(err))
|
||||
{
|
||||
if (!*aMixed)
|
||||
{
|
||||
nsAutoString tagStr;
|
||||
if (bOL) tagStr.AssignWithConversion("ol");
|
||||
else if (bUL) tagStr.AssignWithConversion("ul");
|
||||
else if (bDL) tagStr.AssignWithConversion("dl");
|
||||
*_retval = tagStr.ToNewUnicode();
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetListItemState(PRBool *aMixed, PRUnichar **_retval)
|
||||
{
|
||||
if (!aMixed || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
*_retval = nsnull;
|
||||
*aMixed = PR_FALSE;
|
||||
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
{
|
||||
PRBool bLI,bDT,bDD;
|
||||
err = htmlEditor->GetListItemState(*aMixed, bLI, bDT, bDD);
|
||||
if (NS_SUCCEEDED(err))
|
||||
{
|
||||
if (!*aMixed)
|
||||
{
|
||||
nsAutoString tagStr;
|
||||
if (bLI) tagStr.AssignWithConversion("li");
|
||||
else if (bDT) tagStr.AssignWithConversion("dt");
|
||||
else if (bDD) tagStr.AssignWithConversion("dd");
|
||||
*_retval = tagStr.ToNewUnicode();
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::ApplyStyleSheet(const PRUnichar *url)
|
||||
{
|
||||
@ -1188,7 +1265,7 @@ nsEditorShell::SetDisplayMode(PRInt32 aDisplayMode)
|
||||
if (aDisplayMode == eDisplayModeSource && mDisplayMode == eDisplayModeSource)
|
||||
return NS_OK;
|
||||
|
||||
// The rest of the HTML Source display work is in EditorCommand.js
|
||||
// The rest of the HTML Source display work is in editor.js
|
||||
|
||||
nsCOMPtr<nsIEditorStyleSheets> styleSheets = do_QueryInterface(mEditor);
|
||||
if (!styleSheets) return NS_NOINTERFACE;
|
||||
@ -4909,7 +4986,6 @@ nsEditorShell::DocumentIsRootDoc(nsIDocumentLoader* aLoader, PRBool& outIsRoot)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClickCount,
|
||||
PRInt32 x, PRInt32 y, PRBool *_retval)
|
||||
@ -4955,25 +5031,6 @@ nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClick
|
||||
// For double-click, edit element properties
|
||||
if (aClickCount == 2)
|
||||
{
|
||||
// Get the ComposerController:
|
||||
nsCOMPtr<nsIControllers> controllers;
|
||||
if(!mContentWindow)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
||||
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
||||
rv = cwP->GetControllers(getter_AddRefs(controllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!controllers) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// TODO: Don't use eComposerController index! must search
|
||||
// through controllers to find the one we want - UGH!
|
||||
nsCOMPtr<nsIController> controller;
|
||||
rv = controllers->GetControllerAt(eComposerController, getter_AddRefs(controller));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!controller) return NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIEditorController> composerController = do_QueryInterface(controller);
|
||||
|
||||
// Execute the command
|
||||
nsAutoString commandName;
|
||||
|
||||
// In "All Tags" mode, use AdvancedProperties,
|
||||
@ -4982,13 +5039,43 @@ nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClick
|
||||
commandName = NS_ConvertASCIItoUCS2("cmd_objectProperties");
|
||||
else
|
||||
commandName = NS_ConvertASCIItoUCS2("cmd_advancedProperties");
|
||||
|
||||
rv = DoControllerCommand(commandName);
|
||||
|
||||
rv = composerController->DoCommand(commandName.GetUnicode());
|
||||
|
||||
// We handled the message -- don't propogate to frames
|
||||
if (NS_SUCCEEDED(rv))
|
||||
*_retval = PR_TRUE;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditorShell::DoControllerCommand(nsString& aCommand)
|
||||
{
|
||||
// Get the list of controllers...
|
||||
nsCOMPtr<nsIControllers> controllers;
|
||||
if(!mContentWindow)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
||||
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = cwP->GetControllers(getter_AddRefs(controllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!controllers) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
//... then find the specific controller supporting desired command
|
||||
nsCOMPtr<nsIController> controller;
|
||||
|
||||
rv = controllers->GetControllerForCommand(aCommand.GetUnicode(), getter_AddRefs(controller));
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (!controller) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIEditorController> composerController = do_QueryInterface(controller);
|
||||
// Execute the command
|
||||
rv = composerController->DoCommand(aCommand.GetUnicode());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -124,6 +124,8 @@ class nsEditorShell : public nsIEditorShell,
|
||||
nsresult TransferDocumentStateListeners();
|
||||
nsresult RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
|
||||
nsresult DoFind(PRBool aFindNext);
|
||||
// To allow executing JavaScript commands from C++ via nsIEditorControler interface
|
||||
nsresult DoControllerCommand(nsString& aCommand);
|
||||
|
||||
void Alert(const nsString& aTitle, const nsString& aMsg);
|
||||
// Bring up a Yes/No dialog WE REALLY NEED A Yes/No/Cancel dialog and would like to set our own caption as well!
|
||||
|
@ -521,25 +521,21 @@ nsHTMLEditRules::GetParagraphState(PRBool &aMixed, nsString &outFormat)
|
||||
|
||||
if (mEditor->IsInlineNode(curNode))
|
||||
format.AssignWithConversion("");
|
||||
else if (nsIEditProperty::p == atom.get())
|
||||
format.AssignWithConversion("P");
|
||||
else if (nsHTMLEditUtils::IsHeader(curNode))
|
||||
{
|
||||
nsAutoString tag;
|
||||
nsEditor::GetTagString(curNode,tag);
|
||||
tag.ToUpperCase();
|
||||
format = tag;
|
||||
}
|
||||
else if (nsIEditProperty::blockquote == atom.get())
|
||||
format.AssignWithConversion("BLOCKQUOTE");
|
||||
else if (nsIEditProperty::address == atom.get())
|
||||
format.AssignWithConversion("ADDRESS");
|
||||
else if (nsIEditProperty::pre == atom.get())
|
||||
format.AssignWithConversion("PRE");
|
||||
else if (nsIEditProperty::dt == atom.get())
|
||||
format.AssignWithConversion("DT");
|
||||
else if (nsIEditProperty::dd == atom.get())
|
||||
format.AssignWithConversion("DD");
|
||||
else if (nsIEditProperty::p == atom.get() ||
|
||||
nsIEditProperty::blockquote == atom.get() ||
|
||||
nsIEditProperty::address == atom.get() ||
|
||||
nsIEditProperty::pre == atom.get() ||
|
||||
nsIEditProperty::dt == atom.get() ||
|
||||
nsIEditProperty::dd == atom.get() )
|
||||
{
|
||||
atom->ToString(format);
|
||||
}
|
||||
|
||||
// if this is the first node, we've found, remember it as the format
|
||||
if (formatStr.EqualsWithConversion("x"))
|
||||
@ -682,7 +678,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
||||
if (isPRE)
|
||||
{
|
||||
char newlineChar = '\n';
|
||||
while (unicodeBuf && (pos != -1) && (pos < inString->Length()))
|
||||
while (unicodeBuf && (pos != -1) && (pos < (PRInt32)inString->Length()))
|
||||
{
|
||||
PRInt32 oldPos = pos;
|
||||
PRInt32 subStrLen;
|
||||
@ -720,7 +716,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
||||
{
|
||||
char specialChars[] = {'\t','\n',0};
|
||||
nsAutoString tabString; tabString.AssignWithConversion(" ");
|
||||
while (unicodeBuf && (pos != -1) && (pos < inString->Length()))
|
||||
while (unicodeBuf && (pos != -1) && (pos < (PRInt32)inString->Length()))
|
||||
{
|
||||
PRInt32 oldPos = pos;
|
||||
PRInt32 subStrLen;
|
||||
@ -3175,7 +3171,7 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode,
|
||||
PRInt32 splitOffset, resultOffset, i;
|
||||
inNode->GetParentNode(getter_AddRefs(inlineParentNode));
|
||||
|
||||
for (i=0; i<listCount; i++)
|
||||
for (i=0; i< (PRInt32)listCount; i++)
|
||||
{
|
||||
isupports = (dont_AddRef)(arrayOfBreaks->ElementAt(i));
|
||||
breakNode = do_QueryInterface(isupports);
|
||||
@ -3230,13 +3226,13 @@ nsHTMLEditRules::MakeTransitionList(nsISupportsArray *inArrayOfNodes,
|
||||
if (!inArrayOfNodes || !inTransitionArray) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRUint32 listCount;
|
||||
PRInt32 i;
|
||||
PRUint32 i;
|
||||
inArrayOfNodes->Count(&listCount);
|
||||
nsVoidArray transitionList;
|
||||
nsCOMPtr<nsIDOMNode> prevElementParent;
|
||||
nsCOMPtr<nsIDOMNode> curElementParent;
|
||||
|
||||
for (i=0; i<(PRInt32)listCount; i++)
|
||||
for (i=0; i<listCount; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> isupports = (dont_AddRef)(inArrayOfNodes->ElementAt(i));
|
||||
nsCOMPtr<nsIDOMNode> transNode( do_QueryInterface(isupports ) );
|
||||
|
@ -403,26 +403,16 @@ nsresult
|
||||
nsListCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagName, PRBool& outInList)
|
||||
{
|
||||
NS_ASSERTION(aEditorShell, "Need editorShell here");
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
if (!editor) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// tagStr will hold the list state when we're done.
|
||||
nsAutoString tagStr;
|
||||
PRBool bMixed, bOL, bUL, bDL;
|
||||
nsresult rv = htmlEditor->GetListState(bMixed, bOL, bUL, bDL);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!bMixed)
|
||||
{
|
||||
if (bOL) tagStr.AssignWithConversion("ol");
|
||||
else if (bUL) tagStr.AssignWithConversion("ul");
|
||||
else if (bDL) tagStr.AssignWithConversion("dl");
|
||||
}
|
||||
|
||||
outInList = tagStr.EqualsWithConversion(mTagName);
|
||||
PRBool bMixed;
|
||||
PRUnichar *tagStr;
|
||||
nsresult rv = aEditorShell->GetListState(&bMixed, &tagStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
outInList = (0 == nsCRT::strcmp(tagStr, aTagName));
|
||||
|
||||
if (tagStr) nsCRT::free(tagStr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -433,8 +423,9 @@ nsListCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName)
|
||||
PRBool inList;
|
||||
nsresult rv = GetCurrentState(aEditorShell, aTagName, inList);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
nsAutoString listType; listType.AssignWithConversion(aTagName);
|
||||
|
||||
if (inList)
|
||||
rv = aEditorShell->RemoveList(listType.GetUnicode());
|
||||
else
|
||||
@ -444,6 +435,77 @@ nsListCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName)
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
nsListItemCommand::nsListItemCommand(const char* aTagName)
|
||||
: nsBaseStateUpdatingCommand(aTagName)
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsListItemCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagName, PRBool& outInList)
|
||||
{
|
||||
NS_ASSERTION(aEditorShell, "Need editorShell here");
|
||||
|
||||
PRBool bMixed;
|
||||
PRUnichar *tagStr;
|
||||
nsresult rv = aEditorShell->GetListItemState(&bMixed, &tagStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
outInList = (0 == nsCRT::strcmp(tagStr, aTagName));
|
||||
|
||||
if (tagStr) nsCRT::free(tagStr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName)
|
||||
{
|
||||
NS_ASSERTION(aEditorShell, "Need editorShell here");
|
||||
nsCOMPtr<nsIEditor> editor;
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
if (!editor) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
PRBool inList;
|
||||
nsresult rv = GetCurrentState(aEditorShell, aTagName, inList);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (inList)
|
||||
{
|
||||
// To remove a list, first get what kind of list we're in
|
||||
PRBool bMixed;
|
||||
PRUnichar *tagStr;
|
||||
rv = aEditorShell->GetListState(&bMixed, &tagStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (tagStr)
|
||||
{
|
||||
if (!bMixed)
|
||||
{
|
||||
nsAutoString listType(tagStr);
|
||||
rv = htmlEditor->RemoveList(listType);
|
||||
}
|
||||
nsCRT::free(tagStr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nsAutoString itemType; itemType.AssignWithConversion(aTagName);
|
||||
// Set to the requested paragraph type
|
||||
//XXX Note: This actually doesn't work for "LI",
|
||||
// but we currently don't use this for non DL lists anyway.
|
||||
// Problem: won't this replace any current block paragraph style?
|
||||
rv = htmlEditor->SetParagraphFormat(itemType);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
@ -623,18 +685,6 @@ nsParagraphStateCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString&
|
||||
aEditorShell->GetEditor(getter_AddRefs(editor));
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(editor);
|
||||
if (!htmlEditor) return NS_ERROR_FAILURE;
|
||||
#if 0
|
||||
// some proof of concept code for list item state.
|
||||
// Just leaving in for Charlie to see.
|
||||
PRBool bLI,bDT,bDD;
|
||||
htmlEditor->GetListItemState(outMixed, bLI, bDT, bDD);
|
||||
if (!outMixed && (bDT || bDD))
|
||||
{
|
||||
if (bDT) outStateString.AssignWithConversion("DT");
|
||||
if (bDD) outStateString.AssignWithConversion("DD");
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
return htmlEditor->GetParagraphState(outMixed, outStateString);
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,20 @@ protected:
|
||||
virtual nsresult ToggleState(nsIEditorShell *aEditorShell, const char* aTagName);
|
||||
};
|
||||
|
||||
class nsListItemCommand : public nsBaseStateUpdatingCommand
|
||||
{
|
||||
public:
|
||||
|
||||
nsListItemCommand(const char* aTagName);
|
||||
|
||||
protected:
|
||||
|
||||
// get the current state (on or off) for this style or block format
|
||||
virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagName, PRBool& outStateSet);
|
||||
|
||||
// add/remove the style
|
||||
virtual nsresult ToggleState(nsIEditorShell *aEditorShell, const char* aTagName);
|
||||
};
|
||||
|
||||
// Base class for commands whose state consists of a string (e.g. para format)
|
||||
class nsMultiStateCommand : public nsBaseComposerCommand,
|
||||
|
@ -1166,6 +1166,83 @@ nsEditorShell::SetBackgroundColor(const PRUnichar *color)
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetParagraphState(PRBool *aMixed, PRUnichar **_retval)
|
||||
{
|
||||
if (!aMixed || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
*_retval = nsnull;
|
||||
*aMixed = PR_FALSE;
|
||||
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
|
||||
if (htmlEditor)
|
||||
{
|
||||
PRBool bMixed;
|
||||
nsAutoString state;
|
||||
err = htmlEditor->GetParagraphState(bMixed, state);
|
||||
if (!bMixed)
|
||||
*_retval = state.ToNewUnicode();
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetListState(PRBool *aMixed, PRUnichar **_retval)
|
||||
{
|
||||
if (!aMixed || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
*_retval = nsnull;
|
||||
*aMixed = PR_FALSE;
|
||||
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
{
|
||||
PRBool bOL, bUL, bDL;
|
||||
err = htmlEditor->GetListState(*aMixed, bOL, bUL, bDL);
|
||||
if (NS_SUCCEEDED(err))
|
||||
{
|
||||
if (!*aMixed)
|
||||
{
|
||||
nsAutoString tagStr;
|
||||
if (bOL) tagStr.AssignWithConversion("ol");
|
||||
else if (bUL) tagStr.AssignWithConversion("ul");
|
||||
else if (bDL) tagStr.AssignWithConversion("dl");
|
||||
*_retval = tagStr.ToNewUnicode();
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::GetListItemState(PRBool *aMixed, PRUnichar **_retval)
|
||||
{
|
||||
if (!aMixed || !_retval) return NS_ERROR_NULL_POINTER;
|
||||
*_retval = nsnull;
|
||||
*aMixed = PR_FALSE;
|
||||
|
||||
nsresult err = NS_NOINTERFACE;
|
||||
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
||||
if (htmlEditor)
|
||||
{
|
||||
PRBool bLI,bDT,bDD;
|
||||
err = htmlEditor->GetListItemState(*aMixed, bLI, bDT, bDD);
|
||||
if (NS_SUCCEEDED(err))
|
||||
{
|
||||
if (!*aMixed)
|
||||
{
|
||||
nsAutoString tagStr;
|
||||
if (bLI) tagStr.AssignWithConversion("li");
|
||||
else if (bDT) tagStr.AssignWithConversion("dt");
|
||||
else if (bDD) tagStr.AssignWithConversion("dd");
|
||||
*_retval = tagStr.ToNewUnicode();
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::ApplyStyleSheet(const PRUnichar *url)
|
||||
{
|
||||
@ -1188,7 +1265,7 @@ nsEditorShell::SetDisplayMode(PRInt32 aDisplayMode)
|
||||
if (aDisplayMode == eDisplayModeSource && mDisplayMode == eDisplayModeSource)
|
||||
return NS_OK;
|
||||
|
||||
// The rest of the HTML Source display work is in EditorCommand.js
|
||||
// The rest of the HTML Source display work is in editor.js
|
||||
|
||||
nsCOMPtr<nsIEditorStyleSheets> styleSheets = do_QueryInterface(mEditor);
|
||||
if (!styleSheets) return NS_NOINTERFACE;
|
||||
@ -4909,7 +4986,6 @@ nsEditorShell::DocumentIsRootDoc(nsIDocumentLoader* aLoader, PRBool& outIsRoot)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClickCount,
|
||||
PRInt32 x, PRInt32 y, PRBool *_retval)
|
||||
@ -4955,25 +5031,6 @@ nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClick
|
||||
// For double-click, edit element properties
|
||||
if (aClickCount == 2)
|
||||
{
|
||||
// Get the ComposerController:
|
||||
nsCOMPtr<nsIControllers> controllers;
|
||||
if(!mContentWindow)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
||||
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
||||
rv = cwP->GetControllers(getter_AddRefs(controllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!controllers) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// TODO: Don't use eComposerController index! must search
|
||||
// through controllers to find the one we want - UGH!
|
||||
nsCOMPtr<nsIController> controller;
|
||||
rv = controllers->GetControllerAt(eComposerController, getter_AddRefs(controller));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!controller) return NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIEditorController> composerController = do_QueryInterface(controller);
|
||||
|
||||
// Execute the command
|
||||
nsAutoString commandName;
|
||||
|
||||
// In "All Tags" mode, use AdvancedProperties,
|
||||
@ -4982,13 +5039,43 @@ nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClick
|
||||
commandName = NS_ConvertASCIItoUCS2("cmd_objectProperties");
|
||||
else
|
||||
commandName = NS_ConvertASCIItoUCS2("cmd_advancedProperties");
|
||||
|
||||
rv = DoControllerCommand(commandName);
|
||||
|
||||
rv = composerController->DoCommand(commandName.GetUnicode());
|
||||
|
||||
// We handled the message -- don't propogate to frames
|
||||
if (NS_SUCCEEDED(rv))
|
||||
*_retval = PR_TRUE;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsEditorShell::DoControllerCommand(nsString& aCommand)
|
||||
{
|
||||
// Get the list of controllers...
|
||||
nsCOMPtr<nsIControllers> controllers;
|
||||
if(!mContentWindow)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
||||
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = cwP->GetControllers(getter_AddRefs(controllers));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!controllers) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
//... then find the specific controller supporting desired command
|
||||
nsCOMPtr<nsIController> controller;
|
||||
|
||||
rv = controllers->GetControllerForCommand(aCommand.GetUnicode(), getter_AddRefs(controller));
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (!controller) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIEditorController> composerController = do_QueryInterface(controller);
|
||||
// Execute the command
|
||||
rv = composerController->DoCommand(aCommand.GetUnicode());
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -124,6 +124,8 @@ class nsEditorShell : public nsIEditorShell,
|
||||
nsresult TransferDocumentStateListeners();
|
||||
nsresult RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
|
||||
nsresult DoFind(PRBool aFindNext);
|
||||
// To allow executing JavaScript commands from C++ via nsIEditorControler interface
|
||||
nsresult DoControllerCommand(nsString& aCommand);
|
||||
|
||||
void Alert(const nsString& aTitle, const nsString& aMsg);
|
||||
// Bring up a Yes/No dialog WE REALLY NEED A Yes/No/Cancel dialog and would like to set our own caption as well!
|
||||
|
@ -324,6 +324,8 @@ nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandMana
|
||||
// lists
|
||||
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", "dt");
|
||||
NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", "dd");
|
||||
|
||||
// format stuff
|
||||
NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");
|
||||
|
@ -521,25 +521,21 @@ nsHTMLEditRules::GetParagraphState(PRBool &aMixed, nsString &outFormat)
|
||||
|
||||
if (mEditor->IsInlineNode(curNode))
|
||||
format.AssignWithConversion("");
|
||||
else if (nsIEditProperty::p == atom.get())
|
||||
format.AssignWithConversion("P");
|
||||
else if (nsHTMLEditUtils::IsHeader(curNode))
|
||||
{
|
||||
nsAutoString tag;
|
||||
nsEditor::GetTagString(curNode,tag);
|
||||
tag.ToUpperCase();
|
||||
format = tag;
|
||||
}
|
||||
else if (nsIEditProperty::blockquote == atom.get())
|
||||
format.AssignWithConversion("BLOCKQUOTE");
|
||||
else if (nsIEditProperty::address == atom.get())
|
||||
format.AssignWithConversion("ADDRESS");
|
||||
else if (nsIEditProperty::pre == atom.get())
|
||||
format.AssignWithConversion("PRE");
|
||||
else if (nsIEditProperty::dt == atom.get())
|
||||
format.AssignWithConversion("DT");
|
||||
else if (nsIEditProperty::dd == atom.get())
|
||||
format.AssignWithConversion("DD");
|
||||
else if (nsIEditProperty::p == atom.get() ||
|
||||
nsIEditProperty::blockquote == atom.get() ||
|
||||
nsIEditProperty::address == atom.get() ||
|
||||
nsIEditProperty::pre == atom.get() ||
|
||||
nsIEditProperty::dt == atom.get() ||
|
||||
nsIEditProperty::dd == atom.get() )
|
||||
{
|
||||
atom->ToString(format);
|
||||
}
|
||||
|
||||
// if this is the first node, we've found, remember it as the format
|
||||
if (formatStr.EqualsWithConversion("x"))
|
||||
@ -682,7 +678,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
||||
if (isPRE)
|
||||
{
|
||||
char newlineChar = '\n';
|
||||
while (unicodeBuf && (pos != -1) && (pos < inString->Length()))
|
||||
while (unicodeBuf && (pos != -1) && (pos < (PRInt32)inString->Length()))
|
||||
{
|
||||
PRInt32 oldPos = pos;
|
||||
PRInt32 subStrLen;
|
||||
@ -720,7 +716,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
||||
{
|
||||
char specialChars[] = {'\t','\n',0};
|
||||
nsAutoString tabString; tabString.AssignWithConversion(" ");
|
||||
while (unicodeBuf && (pos != -1) && (pos < inString->Length()))
|
||||
while (unicodeBuf && (pos != -1) && (pos < (PRInt32)inString->Length()))
|
||||
{
|
||||
PRInt32 oldPos = pos;
|
||||
PRInt32 subStrLen;
|
||||
@ -3175,7 +3171,7 @@ nsHTMLEditRules::BustUpInlinesAtBRs(nsIDOMNode *inNode,
|
||||
PRInt32 splitOffset, resultOffset, i;
|
||||
inNode->GetParentNode(getter_AddRefs(inlineParentNode));
|
||||
|
||||
for (i=0; i<listCount; i++)
|
||||
for (i=0; i< (PRInt32)listCount; i++)
|
||||
{
|
||||
isupports = (dont_AddRef)(arrayOfBreaks->ElementAt(i));
|
||||
breakNode = do_QueryInterface(isupports);
|
||||
@ -3230,13 +3226,13 @@ nsHTMLEditRules::MakeTransitionList(nsISupportsArray *inArrayOfNodes,
|
||||
if (!inArrayOfNodes || !inTransitionArray) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRUint32 listCount;
|
||||
PRInt32 i;
|
||||
PRUint32 i;
|
||||
inArrayOfNodes->Count(&listCount);
|
||||
nsVoidArray transitionList;
|
||||
nsCOMPtr<nsIDOMNode> prevElementParent;
|
||||
nsCOMPtr<nsIDOMNode> curElementParent;
|
||||
|
||||
for (i=0; i<(PRInt32)listCount; i++)
|
||||
for (i=0; i<listCount; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> isupports = (dont_AddRef)(inArrayOfNodes->ElementAt(i));
|
||||
nsCOMPtr<nsIDOMNode> transNode( do_QueryInterface(isupports ) );
|
||||
|
Loading…
Reference in New Issue
Block a user