groundwork for 44684: adding a "GetAlignment" call to the editor so that ui can reflect alignment of selection

This commit is contained in:
jfrancis%netscape.com 2000-08-14 12:07:10 +00:00
Родитель feb7dd02ea
Коммит 008d4be4c9
16 изменённых файлов: 163 добавлений и 50 удалений

Просмотреть файл

@ -1233,6 +1233,34 @@ nsEditorShell::GetListItemState(PRBool *aMixed, PRUnichar **_retval)
return err;
}
NS_IMETHODIMP
nsEditorShell::GetAlignment(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)
{
nsIHTMLEditor::EAlignment firstAlign;
err = htmlEditor->GetAlignment(*aMixed, firstAlign);
if (NS_SUCCEEDED(err))
{
nsAutoString tagStr;
if (firstAlign == nsIHTMLEditor::eLeft)
tagStr.AssignWithConversion("left");
else if (firstAlign == nsIHTMLEditor::eCenter)
tagStr.AssignWithConversion("center");
else if (firstAlign == nsIHTMLEditor::eRight)
tagStr.AssignWithConversion("right");
*_retval = tagStr.ToNewUnicode();
}
}
return err;
}
NS_IMETHODIMP
nsEditorShell::ApplyStyleSheet(const PRUnichar *url)
{

Просмотреть файл

@ -80,7 +80,7 @@ class nsEditorShell : public nsIEditorShell,
{
public:
// These must map onto the button-order for nsICommonDialog::Confirm results
// These must map onto the button-order for nsICommonDialog::Confirm results
// which are rather ugly right now (Cancel in the middle!)
typedef enum {eYes = 0, eCancel = 1, eNo = 2 } EConfirmResult;
@ -100,30 +100,30 @@ class nsEditorShell : public nsIEditorShell,
protected:
typedef enum {
eUninitializedEditorType = 0,
ePlainTextEditorType = 1,
eHTMLTextEditorType = 2
} EEditorType;
typedef enum {
eUninitializedEditorType = 0,
ePlainTextEditorType = 1,
eHTMLTextEditorType = 2
} EEditorType;
typedef enum {
typedef enum {
eCantEditNoReason = 0,
eCantEditFramesets = 1,
eCantEditMimeType = 2,
eCantEditOther = 3
} ECantEditReason;
nsresult DoEditorMode(nsIDocShell *aDocShell);
} ECantEditReason;
nsresult DoEditorMode(nsIDocShell *aDocShell);
// nuke any existing editor in the editorShell, thus preparing it to edit
// a(nother) document.
nsresult ResetEditingState();
nsresult InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
nsresult PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl);
nsresult ScrollSelectionIntoView();
nsresult InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
nsresult PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl);
nsresult ScrollSelectionIntoView();
nsresult TransferDocumentStateListeners();
nsresult RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
nsresult DoFind(PRBool aFindNext);
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);
@ -136,8 +136,8 @@ class nsEditorShell : public nsIEditorShell,
EConfirmResult ConfirmWithCancel(const nsString& aTitle, const nsString& aQuestion,
const nsString *aYesString, const nsString *aNoString);
// this returns an AddReffed nsIScriptContext. You must relase it.
nsIScriptContext* GetScriptContext(nsIDOMWindow * aWin);
// this returns an AddReffed nsIScriptContext. You must relase it.
nsIScriptContext* GetScriptContext(nsIDOMWindow * aWin);
// Get a string from the string bundle file
void GetBundleString(const nsString& name, nsString &outString);
@ -161,7 +161,7 @@ class nsEditorShell : public nsIEditorShell,
// fix rowspan, colspan, and missing cells problems
nsresult CheckPrefAndNormalizeTable();
nsCOMPtr<nsIHTMLEditor> mEditor; // this can be either an HTML or plain text (or other?) editor
nsCOMPtr<nsIHTMLEditor> mEditor; // this can be either an HTML or plain text (or other?) editor
nsCOMPtr<nsISupports> mSearchContext; // context used for search and replace. Owned by the appshell.
nsCOMPtr<nsISpellChecker> mSpellChecker;
@ -176,7 +176,7 @@ class nsEditorShell : public nsIEditorShell,
// These doc listeners are registered with the editor when that gets
// created. We also keep them in this list so we can register if we have
// to blow away the editor (e.g. URL reload)
nsCOMPtr<nsISupportsArray> mDocStateListeners; // contents are nsISupports
nsCOMPtr<nsISupportsArray> mDocStateListeners; // contents are nsISupports
// Pointer to localized strings used for UI
nsCOMPtr<nsIStringBundle> mStringBundle;
@ -197,26 +197,26 @@ class nsEditorShell : public nsIEditorShell,
// so we need to track it separately
PRBool mHTMLSourceMode;
nsIDOMWindow *mWebShellWindow; // weak reference
//nsIDOMWindow *mContentWindow; // weak reference
nsIDOMWindow *mWebShellWindow; // weak reference
//nsIDOMWindow *mContentWindow; // weak reference
nsWeakPtr mContentWindow; // weak reference
nsEditorParserObserver *mParserObserver; // we hold the owning ref to this.
nsInterfaceState *mStateMaintainer; // we hold the owning ref to this.
nsIEditorController *mEditorController; // temporary weak ref to the editor controller
nsIDocShell *mDocShell; // weak reference
nsIDocShell *mDocShell; // weak reference
// The webshell that contains the document being edited.
// Don't assume that webshell directly contains the document being edited;
// if we are in a frameset, this assumption is false.
nsIDocShell *mContentAreaDocShell; // weak reference
nsIDocShell *mContentAreaDocShell; // weak reference
PRPackedBool mCloseWindowWhenLoaded; // error on load. Close window when loaded
ECantEditReason mCantEditReason;
EEditorType mEditorType;
nsString mEditorTypeString; // string which describes which editor type will be instantiated (lowercased)
EEditorType mEditorType;
nsString mEditorTypeString; // string which describes which editor type will be instantiated (lowercased)
PRInt32 mWrapColumn; // can't actually set this 'til the editor is created, so we may have to hold on to it for a while
nsStringArray mSuggestedWordList;

Просмотреть файл

@ -455,6 +455,11 @@ nsHTMLEditRules::GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBo
return res;
}
NS_IMETHODIMP
nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEditRules::GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent)

Просмотреть файл

@ -56,6 +56,7 @@ public:
NS_IMETHOD GetListState(PRBool &aMixed, PRBool &aOL, PRBool &aUL, PRBool &aDL);
NS_IMETHOD GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool &aDD);
NS_IMETHOD GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent);
NS_IMETHOD GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign);
NS_IMETHOD GetParagraphState(PRBool &aMixed, nsString &outFormat);
// nsIEditActionListener methods

Просмотреть файл

@ -3082,6 +3082,18 @@ nsHTMLEditor::GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool
return htmlRules->GetListItemState(aMixed, aLI, aDT, aDD);
}
NS_IMETHODIMP
nsHTMLEditor::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)
{
if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
if (!htmlRules) return NS_ERROR_FAILURE;
return htmlRules->GetAlignment(aMixed, aAlign);
}
NS_IMETHODIMP
nsHTMLEditor::GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent)
{

Просмотреть файл

@ -138,6 +138,7 @@ public:
NS_IMETHOD GetFontFaceState(PRBool &aMixed, nsString &outFace);
NS_IMETHOD GetListState(PRBool &aMixed, PRBool &aOL, PRBool &aUL, PRBool &aDL);
NS_IMETHOD GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool &aDD);
NS_IMETHOD GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign);
NS_IMETHOD GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent);
NS_IMETHOD MakeOrChangeList(const nsString& aListType);

Просмотреть файл

@ -36,6 +36,7 @@ public:
NS_IMETHOD GetListState(PRBool &aMixed, PRBool &aOL, PRBool &aUL, PRBool &aDL)=0;
NS_IMETHOD GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool &aDD)=0;
NS_IMETHOD GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent)=0;
NS_IMETHOD GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)=0;
NS_IMETHOD GetParagraphState(PRBool &aMixed, nsString &outFormat)=0;
};

Просмотреть файл

@ -1233,6 +1233,34 @@ nsEditorShell::GetListItemState(PRBool *aMixed, PRUnichar **_retval)
return err;
}
NS_IMETHODIMP
nsEditorShell::GetAlignment(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)
{
nsIHTMLEditor::EAlignment firstAlign;
err = htmlEditor->GetAlignment(*aMixed, firstAlign);
if (NS_SUCCEEDED(err))
{
nsAutoString tagStr;
if (firstAlign == nsIHTMLEditor::eLeft)
tagStr.AssignWithConversion("left");
else if (firstAlign == nsIHTMLEditor::eCenter)
tagStr.AssignWithConversion("center");
else if (firstAlign == nsIHTMLEditor::eRight)
tagStr.AssignWithConversion("right");
*_retval = tagStr.ToNewUnicode();
}
}
return err;
}
NS_IMETHODIMP
nsEditorShell::ApplyStyleSheet(const PRUnichar *url)
{

Просмотреть файл

@ -80,7 +80,7 @@ class nsEditorShell : public nsIEditorShell,
{
public:
// These must map onto the button-order for nsICommonDialog::Confirm results
// These must map onto the button-order for nsICommonDialog::Confirm results
// which are rather ugly right now (Cancel in the middle!)
typedef enum {eYes = 0, eCancel = 1, eNo = 2 } EConfirmResult;
@ -100,30 +100,30 @@ class nsEditorShell : public nsIEditorShell,
protected:
typedef enum {
eUninitializedEditorType = 0,
ePlainTextEditorType = 1,
eHTMLTextEditorType = 2
} EEditorType;
typedef enum {
eUninitializedEditorType = 0,
ePlainTextEditorType = 1,
eHTMLTextEditorType = 2
} EEditorType;
typedef enum {
typedef enum {
eCantEditNoReason = 0,
eCantEditFramesets = 1,
eCantEditMimeType = 2,
eCantEditOther = 3
} ECantEditReason;
nsresult DoEditorMode(nsIDocShell *aDocShell);
} ECantEditReason;
nsresult DoEditorMode(nsIDocShell *aDocShell);
// nuke any existing editor in the editorShell, thus preparing it to edit
// a(nother) document.
nsresult ResetEditingState();
nsresult InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
nsresult PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl);
nsresult ScrollSelectionIntoView();
nsresult InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
nsresult PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl);
nsresult ScrollSelectionIntoView();
nsresult TransferDocumentStateListeners();
nsresult RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
nsresult DoFind(PRBool aFindNext);
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);
@ -136,8 +136,8 @@ class nsEditorShell : public nsIEditorShell,
EConfirmResult ConfirmWithCancel(const nsString& aTitle, const nsString& aQuestion,
const nsString *aYesString, const nsString *aNoString);
// this returns an AddReffed nsIScriptContext. You must relase it.
nsIScriptContext* GetScriptContext(nsIDOMWindow * aWin);
// this returns an AddReffed nsIScriptContext. You must relase it.
nsIScriptContext* GetScriptContext(nsIDOMWindow * aWin);
// Get a string from the string bundle file
void GetBundleString(const nsString& name, nsString &outString);
@ -161,7 +161,7 @@ class nsEditorShell : public nsIEditorShell,
// fix rowspan, colspan, and missing cells problems
nsresult CheckPrefAndNormalizeTable();
nsCOMPtr<nsIHTMLEditor> mEditor; // this can be either an HTML or plain text (or other?) editor
nsCOMPtr<nsIHTMLEditor> mEditor; // this can be either an HTML or plain text (or other?) editor
nsCOMPtr<nsISupports> mSearchContext; // context used for search and replace. Owned by the appshell.
nsCOMPtr<nsISpellChecker> mSpellChecker;
@ -176,7 +176,7 @@ class nsEditorShell : public nsIEditorShell,
// These doc listeners are registered with the editor when that gets
// created. We also keep them in this list so we can register if we have
// to blow away the editor (e.g. URL reload)
nsCOMPtr<nsISupportsArray> mDocStateListeners; // contents are nsISupports
nsCOMPtr<nsISupportsArray> mDocStateListeners; // contents are nsISupports
// Pointer to localized strings used for UI
nsCOMPtr<nsIStringBundle> mStringBundle;
@ -197,26 +197,26 @@ class nsEditorShell : public nsIEditorShell,
// so we need to track it separately
PRBool mHTMLSourceMode;
nsIDOMWindow *mWebShellWindow; // weak reference
//nsIDOMWindow *mContentWindow; // weak reference
nsIDOMWindow *mWebShellWindow; // weak reference
//nsIDOMWindow *mContentWindow; // weak reference
nsWeakPtr mContentWindow; // weak reference
nsEditorParserObserver *mParserObserver; // we hold the owning ref to this.
nsInterfaceState *mStateMaintainer; // we hold the owning ref to this.
nsIEditorController *mEditorController; // temporary weak ref to the editor controller
nsIDocShell *mDocShell; // weak reference
nsIDocShell *mDocShell; // weak reference
// The webshell that contains the document being edited.
// Don't assume that webshell directly contains the document being edited;
// if we are in a frameset, this assumption is false.
nsIDocShell *mContentAreaDocShell; // weak reference
nsIDocShell *mContentAreaDocShell; // weak reference
PRPackedBool mCloseWindowWhenLoaded; // error on load. Close window when loaded
ECantEditReason mCantEditReason;
EEditorType mEditorType;
nsString mEditorTypeString; // string which describes which editor type will be instantiated (lowercased)
EEditorType mEditorType;
nsString mEditorTypeString; // string which describes which editor type will be instantiated (lowercased)
PRInt32 mWrapColumn; // can't actually set this 'til the editor is created, so we may have to hold on to it for a while
nsStringArray mSuggestedWordList;

Просмотреть файл

@ -531,6 +531,8 @@ interface nsIEditorShell : nsISupports
wstring GetListState(out boolean mixed);
/* Returns "li", "dt", or "dd" */
wstring GetListItemState(out boolean mixed);
/* Returns "left", "center", or "right" */
wstring GetAlignment(out boolean mixed);
void ApplyStyleSheet(in wstring url);

Просмотреть файл

@ -455,6 +455,11 @@ nsHTMLEditRules::GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBo
return res;
}
NS_IMETHODIMP
nsHTMLEditRules::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsHTMLEditRules::GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent)

Просмотреть файл

@ -56,6 +56,7 @@ public:
NS_IMETHOD GetListState(PRBool &aMixed, PRBool &aOL, PRBool &aUL, PRBool &aDL);
NS_IMETHOD GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool &aDD);
NS_IMETHOD GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent);
NS_IMETHOD GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign);
NS_IMETHOD GetParagraphState(PRBool &aMixed, nsString &outFormat);
// nsIEditActionListener methods

Просмотреть файл

@ -3082,6 +3082,18 @@ nsHTMLEditor::GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool
return htmlRules->GetListItemState(aMixed, aLI, aDT, aDD);
}
NS_IMETHODIMP
nsHTMLEditor::GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)
{
if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
nsCOMPtr<nsIHTMLEditRules> htmlRules = do_QueryInterface(mRules);
if (!htmlRules) return NS_ERROR_FAILURE;
return htmlRules->GetAlignment(aMixed, aAlign);
}
NS_IMETHODIMP
nsHTMLEditor::GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent)
{

Просмотреть файл

@ -138,6 +138,7 @@ public:
NS_IMETHOD GetFontFaceState(PRBool &aMixed, nsString &outFace);
NS_IMETHOD GetListState(PRBool &aMixed, PRBool &aOL, PRBool &aUL, PRBool &aDL);
NS_IMETHOD GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool &aDD);
NS_IMETHOD GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign);
NS_IMETHOD GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent);
NS_IMETHOD MakeOrChangeList(const nsString& aListType);

Просмотреть файл

@ -36,6 +36,7 @@ public:
NS_IMETHOD GetListState(PRBool &aMixed, PRBool &aOL, PRBool &aUL, PRBool &aDL)=0;
NS_IMETHOD GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool &aDD)=0;
NS_IMETHOD GetIndentState(PRBool &aCanIndent, PRBool &aCanOutdent)=0;
NS_IMETHOD GetAlignment(PRBool &aMixed, nsIHTMLEditor::EAlignment &aAlign)=0;
NS_IMETHOD GetParagraphState(PRBool &aMixed, nsString &outFormat)=0;
};

Просмотреть файл

@ -83,6 +83,13 @@ public:
eTypedBreak // user typed enter
};
// used by GetAlignment()
typedef enum {
eLeft,
eCenter,
eRight
} EAlignment;
/* ------------ Document info methods -------------- */
/** get the length of the document in characters */
@ -334,6 +341,14 @@ public:
*/
NS_IMETHOD GetListItemState(PRBool &aMixed, PRBool &aLI, PRBool &aDT, PRBool &aDD)=0;
/**
* GetAlignment returns what alignment is in the selection.
* @param aMixed True if there is more than one type of list item, or
* if there is some list and non-list
* @param aAlign enum value for first encountered alignment (left/center/right)
*/
NS_IMETHOD GetAlignment(PRBool &aMixed, EAlignment &aAlign)=0;
/**
* Document me!
*