From aa4d5be8ea92d8f294f87ec547b159dac912647b Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Fri, 17 Nov 2000 01:25:28 +0000 Subject: [PATCH] Removal of some crufty old code that used to do UI udpating, and was obsolete by XUL command nodes. r=akkana --- editor/base/nsEditorShell.cpp | 16 +- editor/base/nsInterfaceState.cpp | 368 +---------------------- editor/base/nsInterfaceState.h | 45 +-- editor/composer/src/nsEditorShell.cpp | 16 +- editor/composer/src/nsInterfaceState.cpp | 368 +---------------------- editor/composer/src/nsInterfaceState.h | 45 +-- editor/idl/nsIEditorShell.idl | 5 - 7 files changed, 38 insertions(+), 825 deletions(-) diff --git a/editor/base/nsEditorShell.cpp b/editor/base/nsEditorShell.cpp index 04bca30e2fd..05668e862ad 100644 --- a/editor/base/nsEditorShell.cpp +++ b/editor/base/nsEditorShell.cpp @@ -973,16 +973,6 @@ nsEditorShell::DoEditorMode(nsIDocShell *aDocShell) return InstantiateEditor(domDoc, presShell); } - -NS_IMETHODIMP -nsEditorShell::UpdateInterfaceState(const PRUnichar *tagToUpdate) -{ - if (!mStateMaintainer) - return NS_ERROR_NOT_INITIALIZED; - - return mStateMaintainer->ForceUpdate(tagToUpdate); -} - // Deletion routines nsresult nsEditorShell::ScrollSelectionIntoView() @@ -1071,7 +1061,7 @@ nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const nsAutoString valueStr(value); result = editor->SetAttribute(element, attributeStr, valueStr); } - UpdateInterfaceState(nsnull); + return result; } @@ -1087,7 +1077,7 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr) nsAutoString attributeStr(attr); result = editor->RemoveAttribute(element, attributeStr); } - UpdateInterfaceState(nsnull); + return result; } @@ -1115,7 +1105,6 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con err = NS_ERROR_NOT_IMPLEMENTED; } - UpdateInterfaceState(prop); return err; } @@ -1140,7 +1129,6 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr) err = NS_ERROR_NOT_IMPLEMENTED; } - UpdateInterfaceState(aProp.GetUnicode()); return err; } diff --git a/editor/base/nsInterfaceState.cpp b/editor/base/nsInterfaceState.cpp index 1e36dc29103..dfb80a84042 100644 --- a/editor/base/nsInterfaceState.cpp +++ b/editor/base/nsInterfaceState.cpp @@ -44,46 +44,10 @@ #include "nsInterfaceState.h" - -/* -static PRBool StringHashDestroyFunc(nsHashKey *aKey, void *aData, void* closure) -{ - nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData); - delete stringData; - return PR_FALSE; -} - -static void* StringHashCloneElementFunc(nsHashKey *aKey, void *aData, void* closure) -{ - nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData); - if (stringData) - { - nsString* newString = new nsString(*stringData); - return newString; - } - - return nsnull; -} - -*/ - -#ifdef XP_MAC -#pragma mark - -#endif - nsInterfaceState::nsInterfaceState() : mEditor(nsnull) , mChromeDoc(nsnull) , mDOMWindow(nsnull) -, mUpdateParagraph(PR_FALSE) -, mUpdateFont(PR_FALSE) -, mUpdateList(PR_FALSE) -, mUpdateBold(PR_FALSE) -, mUpdateItalics(PR_FALSE) -, mUpdateUnderline(PR_FALSE) -, mBoldState(eStateUninitialized) -, mItalicState(eStateUninitialized) -, mUnderlineState(eStateUninitialized) , mDirtyState(eStateUninitialized) , mSelectionCollapsed(eStateUninitialized) , mFirstDoOfFirstUndo(PR_TRUE) @@ -111,16 +75,6 @@ nsInterfaceState::Init(nsIHTMLEditor* aEditor, nsIDOMDocument *aChromeDoc) mEditor = aEditor; // no addreffing here mChromeDoc = aChromeDoc; - // it sucks explicitly naming XUL nodes here. Would be better to have - // some way to register things that we want to observe from JS - mUpdateParagraph = XULNodeExists("ParagraphSelect"); - mUpdateFont = XULNodeExists("FontFaceSelect"); - mUpdateList = XULNodeExists("ulButton") || XULNodeExists("olButton"); - - mUpdateBold = XULNodeExists("boldButton"); - mUpdateItalics = XULNodeExists("italicButton"); - mUpdateUnderline = XULNodeExists("underlineButton"); - return NS_OK; } @@ -286,10 +240,21 @@ void nsInterfaceState::TimerCallback() mSelectionCollapsed = isCollapsed; } - // (void)ForceUpdate(); CallUpdateCommands(NS_ConvertASCIItoUCS2("style")); } +nsresult +nsInterfaceState::UpdateDirtyState(PRBool aNowDirty) +{ + if (mDirtyState != aNowDirty) + { + CallUpdateCommands(NS_ConvertASCIItoUCS2("save")); + + mDirtyState = aNowDirty; + } + + return NS_OK; +} nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand) { @@ -316,65 +281,6 @@ nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand) return mDOMWindow->UpdateCommands(aCommand); } -NS_IMETHODIMP -nsInterfaceState::ForceUpdate(const PRUnichar *tagToUpdate) -{ - PRBool updateEverything = !tagToUpdate || !*tagToUpdate; - -#if 0 - // This code is obsolete now that commanders are doing the work - nsresult rv; - - // update bold - if (mUpdateBold && (updateEverything || nsAutoString("b").Equals(tagToUpdate))) - { - rv = UpdateTextState("b", "cmd_bold", "bold", mBoldState); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // update italic - if (mUpdateItalics && (updateEverything || nsAutoString("i").Equals(tagToUpdate))) - { - rv = UpdateTextState("i", "cmd_italic", "italic", mItalicState); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // update underline - if (mUpdateUnderline && (updateEverything || nsAutoString("u").Equals(tagToUpdate))) - { - rv = UpdateTextState("u", "cmd_underline", "underline", mUnderlineState); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // update the paragraph format popup - if (mUpdateParagraph && (updateEverything || nsAutoString("format").Equals(tagToUpdate))) - { - rv = UpdateParagraphState("Editor:Paragraph:Format", "format"); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // udpate the font face - if (mUpdateFont && (updateEverything || nsAutoString("font").Equals(tagToUpdate))) - { - rv = UpdateFontFace("Editor:Font:Face", "font"); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // TODO: FINISH FONT FACE AND ADD FONT SIZE ("Editor:Font:Size", "fontsize", mFontSize) - - // update the list buttons - if (mUpdateList && (updateEverything || - nsAutoString("ol").Equals(tagToUpdate) || - nsAutoString("ul").Equals(tagToUpdate))) - { - rv = UpdateListState("Editor:Paragraph:ListType"); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } -#endif - - return NS_OK; -} - PRBool nsInterfaceState::SelectionIsCollapsed() { @@ -395,256 +301,6 @@ nsInterfaceState::SelectionIsCollapsed() return PR_FALSE; } -nsresult -nsInterfaceState::UpdateParagraphState(const char* observerName, const char* attributeName) -{ - nsCOMPtr domSelection; - nsCOMPtr editor = do_QueryInterface(mEditor); - // Get the nsIEditor pointer (mEditor is nsIHTMLEditor) - if (!editor) return NS_ERROR_NULL_POINTER; - nsresult rv = editor->GetSelection(getter_AddRefs(domSelection)); - if (NS_FAILED(rv)) return rv; - - PRBool selectionCollapsed = PR_FALSE; - rv = domSelection->GetIsCollapsed(&selectionCollapsed); - if (NS_FAILED(rv)) return rv; - - // Get anchor and focus nodes: - nsCOMPtr anchorNode; - rv = domSelection->GetAnchorNode(getter_AddRefs(anchorNode)); - if (NS_FAILED(rv)) return rv; - if (!anchorNode) return NS_ERROR_NULL_POINTER; - - nsCOMPtr focusNode; - rv = domSelection->GetFocusNode(getter_AddRefs(focusNode)); - if (NS_FAILED(rv)) return rv; - if (!focusNode) return NS_ERROR_NULL_POINTER; - - nsCOMPtr anchorNodeBlockParent; - PRBool isBlock; - rv = editor->NodeIsBlock(anchorNode, isBlock); - if (NS_FAILED(rv)) return rv; - - if (isBlock) - { - anchorNodeBlockParent = anchorNode; - } - else - { - // Get block parent of anchorNode node - // We could simply use this if it was in nsIEditor interface! - //rv = editor->GetBlockParent(anchorNode, getter_AddRefs(anchorNodeBlockParent)); - // if (NS_FAILED(rv)) return rv; - - nsCOMPtrparent; - nsCOMPtrtemp; - rv = anchorNode->GetParentNode(getter_AddRefs(parent)); - while (NS_SUCCEEDED(rv) && parent) - { - rv = editor->NodeIsBlock(parent, isBlock); - if (NS_FAILED(rv)) return rv; - if (isBlock) - { - anchorNodeBlockParent = parent; - break; - } - rv = parent->GetParentNode(getter_AddRefs(temp)); - parent = do_QueryInterface(temp); - } - } - if (!anchorNodeBlockParent) // return NS_ERROR_NULL_POINTER; - anchorNodeBlockParent = anchorNode; - - nsAutoString tagName; - - // Check if we have a selection that extends into multiple nodes, - // so we can check for "mixed" selection state - if (selectionCollapsed || focusNode == anchorNode) - { - // Entire selection is within one block - anchorNodeBlockParent->GetNodeName(tagName); - } - else - { - // We may have different block parent node types WITHIN the selection, - // even if the anchor and focus parents are the same type. - // Getting the list of all block, e.g., by using GetParagraphTags(&tagList) - // is too inefficient for long documents. - // TODO: Change to use selection iterator to detect each block node in the - // selection and if different from the anchorNodeBlockParent, use "mixed" state - // *** Not doing this now reduces risk for Beta1 -- simply assume mixed state - // Note that "mixed" displays as "normal" in UI as of 3/6. - tagName.AssignWithConversion("mixed"); - } - - if (tagName != mParagraphFormat) - { - rv = SetNodeAttribute(observerName, attributeName, tagName); - if (NS_FAILED(rv)) return rv; - mParagraphFormat = tagName; - } - return NS_OK; -} - -nsresult -nsInterfaceState::UpdateListState(const char* observerName) -{ - nsresult rv = NS_ERROR_NO_INTERFACE; - nsAutoString tagStr; // empty by default. - - PRBool bMixed, bOL, bUL, bDL; - rv = mEditor->GetListState(bMixed, bOL, bUL, bDL); - if (NS_FAILED(rv)) return rv; - - if (bMixed) - {} // leave tagStr empty - else if (bOL) - tagStr.AssignWithConversion("ol"); - else if (bUL) - tagStr.AssignWithConversion("ul"); - else if (bDL) - tagStr.AssignWithConversion("dl"); - // else leave tagStr empty - - rv = SetNodeAttribute(observerName, "format", tagStr); - - mListTag = tagStr; - - return rv; -} - -nsresult -nsInterfaceState::UpdateFontFace(const char* observerName, const char* attributeName) -{ - nsresult rv; - - PRBool firstOfSelectionHasProp = PR_FALSE; - PRBool anyOfSelectionHasProp = PR_FALSE; - PRBool allOfSelectionHasProp = PR_FALSE; - - nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom("font")); - nsAutoString faceStr; faceStr.AssignWithConversion("face"); - nsAutoString thisFace; - - // Use to test for "Default Fixed Width" - nsCOMPtr fixedStyleAtom = getter_AddRefs(NS_NewAtom("tt")); - - PRBool testBoolean; - - rv = mEditor->GetInlineProperty(styleAtom, &faceStr, &thisFace, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp); - if( !anyOfSelectionHasProp ) - { - // No font face set -- check for "tt". This can return an error if the selection isn't in a node - rv = mEditor->GetInlineProperty(fixedStyleAtom, nsnull, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp); - if (NS_SUCCEEDED(rv)) - { - testBoolean = anyOfSelectionHasProp; - if (anyOfSelectionHasProp) - thisFace.AssignWithConversion("tt"); - } - else - rv = NS_OK; // we don't want to propagate this error - } - - // TODO: HANDLE "MIXED" STATE - if (thisFace != mFontString) - { - rv = SetNodeAttribute(observerName, "face", thisFace); - if (NS_SUCCEEDED(rv)) - mFontString = thisFace; - } - return rv; -} - - -nsresult -nsInterfaceState::UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState) -{ - nsresult rv; - - nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(tagName)); - - PRBool testBoolean; - PRBool firstOfSelectionHasProp = PR_FALSE; - PRBool anyOfSelectionHasProp = PR_FALSE; - PRBool allOfSelectionHasProp = PR_FALSE; - - rv = mEditor->GetInlineProperty(styleAtom, nsnull, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp); - testBoolean = allOfSelectionHasProp; // change this to alter the behaviour - - if (NS_FAILED(rv)) return rv; - - if (testBoolean != ioState) - { - rv = SetNodeAttribute(observerName, attributeName, NS_ConvertASCIItoUCS2(testBoolean ? "true" : "false")); - if (NS_FAILED(rv)) - return rv; - - ioState = testBoolean; - } - - return NS_OK; -} - -nsresult -nsInterfaceState::UpdateDirtyState(PRBool aNowDirty) -{ - if (mDirtyState != aNowDirty) - { - CallUpdateCommands(NS_ConvertASCIItoUCS2("save")); - - mDirtyState = aNowDirty; - } - - return NS_OK; -} - - -PRBool -nsInterfaceState::XULNodeExists(const char* nodeID) -{ - nsresult rv; - - if (!mChromeDoc) - return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr elem; - rv = mChromeDoc->GetElementById( NS_ConvertASCIItoUCS2(nodeID), getter_AddRefs(elem) ); - - return NS_SUCCEEDED(rv) && elem; -} - -nsresult -nsInterfaceState::SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue) -{ - nsresult rv = NS_OK; - - if (!mChromeDoc) - return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr elem; - rv = mChromeDoc->GetElementById( NS_ConvertASCIItoUCS2(nodeID), getter_AddRefs(elem) ); - if (NS_FAILED(rv) || !elem) return rv; - - return elem->SetAttribute(NS_ConvertASCIItoUCS2(attributeName), newValue); -} - - -nsresult -nsInterfaceState::UnsetNodeAttribute(const char* nodeID, const char* attributeName) -{ - nsresult rv = NS_OK; - - if (!mChromeDoc) - return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr elem; - rv = mChromeDoc->GetElementById( NS_ConvertASCIItoUCS2(nodeID), getter_AddRefs(elem) ); - if (NS_FAILED(rv) || !elem) return rv; - - return elem->RemoveAttribute(NS_ConvertASCIItoUCS2(attributeName)); -} - #ifdef XP_MAC #pragma mark - diff --git a/editor/base/nsInterfaceState.h b/editor/base/nsInterfaceState.h index 190edea72d4..c783a69599b 100644 --- a/editor/base/nsInterfaceState.h +++ b/editor/base/nsInterfaceState.h @@ -52,10 +52,6 @@ public: NS_IMETHOD Init(nsIHTMLEditor* aEditor, nsIDOMDocument *aChromeDoc); - // force an update of the UI. At some point, we could pass flags - // here to target certain things for updating. - NS_IMETHOD ForceUpdate(const PRUnichar *tagToUpdate); - // nsISelectionListener interface NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason); @@ -92,18 +88,7 @@ protected: }; PRBool SelectionIsCollapsed(); - - PRBool XULNodeExists(const char* nodeID); - - nsresult SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue); - nsresult UnsetNodeAttribute(const char* nodeID, const char* attributeName); - - nsresult UpdateParagraphState(const char* observerName, const char* attributeName); - nsresult UpdateListState(const char* observerName); - nsresult UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState); - nsresult UpdateFontFace(const char* observerName, const char* attributeName); - nsresult UpdateDirtyState(PRBool aNowDirty); - + nsresult UpdateDirtyState(PRBool aNowDirty); nsresult CallUpdateCommands(const nsString& aCommand); nsresult PrimeUpdateTimer(); @@ -112,37 +97,17 @@ protected: // this class should not hold references to the editor or editorShell. Doing // so would result in cirular reference chains. - nsIHTMLEditor* mEditor; // the HTML editor + nsIHTMLEditor* mEditor; // the HTML editor nsIDOMDocument* mChromeDoc; // XUL document for the chrome area nsIDOMWindowInternal* mDOMWindow; // nsIDOMWindowInternal used for calling UpdateCommands nsCOMPtr mUpdateTimer; - - // what we need to update - PRPackedBool mUpdateParagraph; - PRPackedBool mUpdateFont; - PRPackedBool mUpdateList; - - PRPackedBool mUpdateBold; - PRPackedBool mUpdateItalics; - PRPackedBool mUpdateUnderline; - // current state - PRInt8 mBoldState; - PRInt8 mItalicState; - PRInt8 mUnderlineState; - - PRInt8 mDirtyState; - - PRInt8 mSelectionCollapsed; - + PRInt8 mDirtyState; + PRInt8 mSelectionCollapsed; PRPackedBool mFirstDoOfFirstUndo; - - nsString mParagraphFormat; - nsString mFontString; - nsString mListTag; // contains "" for none, "ol" or "ul" - + }; extern "C" nsresult NS_NewInterfaceState(nsIHTMLEditor* aEditor, nsIDOMDocument* aChromeDoc, nsISelectionListener** aInstancePtrResult); diff --git a/editor/composer/src/nsEditorShell.cpp b/editor/composer/src/nsEditorShell.cpp index 04bca30e2fd..05668e862ad 100644 --- a/editor/composer/src/nsEditorShell.cpp +++ b/editor/composer/src/nsEditorShell.cpp @@ -973,16 +973,6 @@ nsEditorShell::DoEditorMode(nsIDocShell *aDocShell) return InstantiateEditor(domDoc, presShell); } - -NS_IMETHODIMP -nsEditorShell::UpdateInterfaceState(const PRUnichar *tagToUpdate) -{ - if (!mStateMaintainer) - return NS_ERROR_NOT_INITIALIZED; - - return mStateMaintainer->ForceUpdate(tagToUpdate); -} - // Deletion routines nsresult nsEditorShell::ScrollSelectionIntoView() @@ -1071,7 +1061,7 @@ nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const nsAutoString valueStr(value); result = editor->SetAttribute(element, attributeStr, valueStr); } - UpdateInterfaceState(nsnull); + return result; } @@ -1087,7 +1077,7 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr) nsAutoString attributeStr(attr); result = editor->RemoveAttribute(element, attributeStr); } - UpdateInterfaceState(nsnull); + return result; } @@ -1115,7 +1105,6 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con err = NS_ERROR_NOT_IMPLEMENTED; } - UpdateInterfaceState(prop); return err; } @@ -1140,7 +1129,6 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr) err = NS_ERROR_NOT_IMPLEMENTED; } - UpdateInterfaceState(aProp.GetUnicode()); return err; } diff --git a/editor/composer/src/nsInterfaceState.cpp b/editor/composer/src/nsInterfaceState.cpp index 1e36dc29103..dfb80a84042 100644 --- a/editor/composer/src/nsInterfaceState.cpp +++ b/editor/composer/src/nsInterfaceState.cpp @@ -44,46 +44,10 @@ #include "nsInterfaceState.h" - -/* -static PRBool StringHashDestroyFunc(nsHashKey *aKey, void *aData, void* closure) -{ - nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData); - delete stringData; - return PR_FALSE; -} - -static void* StringHashCloneElementFunc(nsHashKey *aKey, void *aData, void* closure) -{ - nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData); - if (stringData) - { - nsString* newString = new nsString(*stringData); - return newString; - } - - return nsnull; -} - -*/ - -#ifdef XP_MAC -#pragma mark - -#endif - nsInterfaceState::nsInterfaceState() : mEditor(nsnull) , mChromeDoc(nsnull) , mDOMWindow(nsnull) -, mUpdateParagraph(PR_FALSE) -, mUpdateFont(PR_FALSE) -, mUpdateList(PR_FALSE) -, mUpdateBold(PR_FALSE) -, mUpdateItalics(PR_FALSE) -, mUpdateUnderline(PR_FALSE) -, mBoldState(eStateUninitialized) -, mItalicState(eStateUninitialized) -, mUnderlineState(eStateUninitialized) , mDirtyState(eStateUninitialized) , mSelectionCollapsed(eStateUninitialized) , mFirstDoOfFirstUndo(PR_TRUE) @@ -111,16 +75,6 @@ nsInterfaceState::Init(nsIHTMLEditor* aEditor, nsIDOMDocument *aChromeDoc) mEditor = aEditor; // no addreffing here mChromeDoc = aChromeDoc; - // it sucks explicitly naming XUL nodes here. Would be better to have - // some way to register things that we want to observe from JS - mUpdateParagraph = XULNodeExists("ParagraphSelect"); - mUpdateFont = XULNodeExists("FontFaceSelect"); - mUpdateList = XULNodeExists("ulButton") || XULNodeExists("olButton"); - - mUpdateBold = XULNodeExists("boldButton"); - mUpdateItalics = XULNodeExists("italicButton"); - mUpdateUnderline = XULNodeExists("underlineButton"); - return NS_OK; } @@ -286,10 +240,21 @@ void nsInterfaceState::TimerCallback() mSelectionCollapsed = isCollapsed; } - // (void)ForceUpdate(); CallUpdateCommands(NS_ConvertASCIItoUCS2("style")); } +nsresult +nsInterfaceState::UpdateDirtyState(PRBool aNowDirty) +{ + if (mDirtyState != aNowDirty) + { + CallUpdateCommands(NS_ConvertASCIItoUCS2("save")); + + mDirtyState = aNowDirty; + } + + return NS_OK; +} nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand) { @@ -316,65 +281,6 @@ nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand) return mDOMWindow->UpdateCommands(aCommand); } -NS_IMETHODIMP -nsInterfaceState::ForceUpdate(const PRUnichar *tagToUpdate) -{ - PRBool updateEverything = !tagToUpdate || !*tagToUpdate; - -#if 0 - // This code is obsolete now that commanders are doing the work - nsresult rv; - - // update bold - if (mUpdateBold && (updateEverything || nsAutoString("b").Equals(tagToUpdate))) - { - rv = UpdateTextState("b", "cmd_bold", "bold", mBoldState); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // update italic - if (mUpdateItalics && (updateEverything || nsAutoString("i").Equals(tagToUpdate))) - { - rv = UpdateTextState("i", "cmd_italic", "italic", mItalicState); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // update underline - if (mUpdateUnderline && (updateEverything || nsAutoString("u").Equals(tagToUpdate))) - { - rv = UpdateTextState("u", "cmd_underline", "underline", mUnderlineState); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // update the paragraph format popup - if (mUpdateParagraph && (updateEverything || nsAutoString("format").Equals(tagToUpdate))) - { - rv = UpdateParagraphState("Editor:Paragraph:Format", "format"); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // udpate the font face - if (mUpdateFont && (updateEverything || nsAutoString("font").Equals(tagToUpdate))) - { - rv = UpdateFontFace("Editor:Font:Face", "font"); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } - - // TODO: FINISH FONT FACE AND ADD FONT SIZE ("Editor:Font:Size", "fontsize", mFontSize) - - // update the list buttons - if (mUpdateList && (updateEverything || - nsAutoString("ol").Equals(tagToUpdate) || - nsAutoString("ul").Equals(tagToUpdate))) - { - rv = UpdateListState("Editor:Paragraph:ListType"); - NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state"); - } -#endif - - return NS_OK; -} - PRBool nsInterfaceState::SelectionIsCollapsed() { @@ -395,256 +301,6 @@ nsInterfaceState::SelectionIsCollapsed() return PR_FALSE; } -nsresult -nsInterfaceState::UpdateParagraphState(const char* observerName, const char* attributeName) -{ - nsCOMPtr domSelection; - nsCOMPtr editor = do_QueryInterface(mEditor); - // Get the nsIEditor pointer (mEditor is nsIHTMLEditor) - if (!editor) return NS_ERROR_NULL_POINTER; - nsresult rv = editor->GetSelection(getter_AddRefs(domSelection)); - if (NS_FAILED(rv)) return rv; - - PRBool selectionCollapsed = PR_FALSE; - rv = domSelection->GetIsCollapsed(&selectionCollapsed); - if (NS_FAILED(rv)) return rv; - - // Get anchor and focus nodes: - nsCOMPtr anchorNode; - rv = domSelection->GetAnchorNode(getter_AddRefs(anchorNode)); - if (NS_FAILED(rv)) return rv; - if (!anchorNode) return NS_ERROR_NULL_POINTER; - - nsCOMPtr focusNode; - rv = domSelection->GetFocusNode(getter_AddRefs(focusNode)); - if (NS_FAILED(rv)) return rv; - if (!focusNode) return NS_ERROR_NULL_POINTER; - - nsCOMPtr anchorNodeBlockParent; - PRBool isBlock; - rv = editor->NodeIsBlock(anchorNode, isBlock); - if (NS_FAILED(rv)) return rv; - - if (isBlock) - { - anchorNodeBlockParent = anchorNode; - } - else - { - // Get block parent of anchorNode node - // We could simply use this if it was in nsIEditor interface! - //rv = editor->GetBlockParent(anchorNode, getter_AddRefs(anchorNodeBlockParent)); - // if (NS_FAILED(rv)) return rv; - - nsCOMPtrparent; - nsCOMPtrtemp; - rv = anchorNode->GetParentNode(getter_AddRefs(parent)); - while (NS_SUCCEEDED(rv) && parent) - { - rv = editor->NodeIsBlock(parent, isBlock); - if (NS_FAILED(rv)) return rv; - if (isBlock) - { - anchorNodeBlockParent = parent; - break; - } - rv = parent->GetParentNode(getter_AddRefs(temp)); - parent = do_QueryInterface(temp); - } - } - if (!anchorNodeBlockParent) // return NS_ERROR_NULL_POINTER; - anchorNodeBlockParent = anchorNode; - - nsAutoString tagName; - - // Check if we have a selection that extends into multiple nodes, - // so we can check for "mixed" selection state - if (selectionCollapsed || focusNode == anchorNode) - { - // Entire selection is within one block - anchorNodeBlockParent->GetNodeName(tagName); - } - else - { - // We may have different block parent node types WITHIN the selection, - // even if the anchor and focus parents are the same type. - // Getting the list of all block, e.g., by using GetParagraphTags(&tagList) - // is too inefficient for long documents. - // TODO: Change to use selection iterator to detect each block node in the - // selection and if different from the anchorNodeBlockParent, use "mixed" state - // *** Not doing this now reduces risk for Beta1 -- simply assume mixed state - // Note that "mixed" displays as "normal" in UI as of 3/6. - tagName.AssignWithConversion("mixed"); - } - - if (tagName != mParagraphFormat) - { - rv = SetNodeAttribute(observerName, attributeName, tagName); - if (NS_FAILED(rv)) return rv; - mParagraphFormat = tagName; - } - return NS_OK; -} - -nsresult -nsInterfaceState::UpdateListState(const char* observerName) -{ - nsresult rv = NS_ERROR_NO_INTERFACE; - nsAutoString tagStr; // empty by default. - - PRBool bMixed, bOL, bUL, bDL; - rv = mEditor->GetListState(bMixed, bOL, bUL, bDL); - if (NS_FAILED(rv)) return rv; - - if (bMixed) - {} // leave tagStr empty - else if (bOL) - tagStr.AssignWithConversion("ol"); - else if (bUL) - tagStr.AssignWithConversion("ul"); - else if (bDL) - tagStr.AssignWithConversion("dl"); - // else leave tagStr empty - - rv = SetNodeAttribute(observerName, "format", tagStr); - - mListTag = tagStr; - - return rv; -} - -nsresult -nsInterfaceState::UpdateFontFace(const char* observerName, const char* attributeName) -{ - nsresult rv; - - PRBool firstOfSelectionHasProp = PR_FALSE; - PRBool anyOfSelectionHasProp = PR_FALSE; - PRBool allOfSelectionHasProp = PR_FALSE; - - nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom("font")); - nsAutoString faceStr; faceStr.AssignWithConversion("face"); - nsAutoString thisFace; - - // Use to test for "Default Fixed Width" - nsCOMPtr fixedStyleAtom = getter_AddRefs(NS_NewAtom("tt")); - - PRBool testBoolean; - - rv = mEditor->GetInlineProperty(styleAtom, &faceStr, &thisFace, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp); - if( !anyOfSelectionHasProp ) - { - // No font face set -- check for "tt". This can return an error if the selection isn't in a node - rv = mEditor->GetInlineProperty(fixedStyleAtom, nsnull, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp); - if (NS_SUCCEEDED(rv)) - { - testBoolean = anyOfSelectionHasProp; - if (anyOfSelectionHasProp) - thisFace.AssignWithConversion("tt"); - } - else - rv = NS_OK; // we don't want to propagate this error - } - - // TODO: HANDLE "MIXED" STATE - if (thisFace != mFontString) - { - rv = SetNodeAttribute(observerName, "face", thisFace); - if (NS_SUCCEEDED(rv)) - mFontString = thisFace; - } - return rv; -} - - -nsresult -nsInterfaceState::UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState) -{ - nsresult rv; - - nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(tagName)); - - PRBool testBoolean; - PRBool firstOfSelectionHasProp = PR_FALSE; - PRBool anyOfSelectionHasProp = PR_FALSE; - PRBool allOfSelectionHasProp = PR_FALSE; - - rv = mEditor->GetInlineProperty(styleAtom, nsnull, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp); - testBoolean = allOfSelectionHasProp; // change this to alter the behaviour - - if (NS_FAILED(rv)) return rv; - - if (testBoolean != ioState) - { - rv = SetNodeAttribute(observerName, attributeName, NS_ConvertASCIItoUCS2(testBoolean ? "true" : "false")); - if (NS_FAILED(rv)) - return rv; - - ioState = testBoolean; - } - - return NS_OK; -} - -nsresult -nsInterfaceState::UpdateDirtyState(PRBool aNowDirty) -{ - if (mDirtyState != aNowDirty) - { - CallUpdateCommands(NS_ConvertASCIItoUCS2("save")); - - mDirtyState = aNowDirty; - } - - return NS_OK; -} - - -PRBool -nsInterfaceState::XULNodeExists(const char* nodeID) -{ - nsresult rv; - - if (!mChromeDoc) - return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr elem; - rv = mChromeDoc->GetElementById( NS_ConvertASCIItoUCS2(nodeID), getter_AddRefs(elem) ); - - return NS_SUCCEEDED(rv) && elem; -} - -nsresult -nsInterfaceState::SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue) -{ - nsresult rv = NS_OK; - - if (!mChromeDoc) - return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr elem; - rv = mChromeDoc->GetElementById( NS_ConvertASCIItoUCS2(nodeID), getter_AddRefs(elem) ); - if (NS_FAILED(rv) || !elem) return rv; - - return elem->SetAttribute(NS_ConvertASCIItoUCS2(attributeName), newValue); -} - - -nsresult -nsInterfaceState::UnsetNodeAttribute(const char* nodeID, const char* attributeName) -{ - nsresult rv = NS_OK; - - if (!mChromeDoc) - return NS_ERROR_NOT_INITIALIZED; - - nsCOMPtr elem; - rv = mChromeDoc->GetElementById( NS_ConvertASCIItoUCS2(nodeID), getter_AddRefs(elem) ); - if (NS_FAILED(rv) || !elem) return rv; - - return elem->RemoveAttribute(NS_ConvertASCIItoUCS2(attributeName)); -} - #ifdef XP_MAC #pragma mark - diff --git a/editor/composer/src/nsInterfaceState.h b/editor/composer/src/nsInterfaceState.h index 190edea72d4..c783a69599b 100644 --- a/editor/composer/src/nsInterfaceState.h +++ b/editor/composer/src/nsInterfaceState.h @@ -52,10 +52,6 @@ public: NS_IMETHOD Init(nsIHTMLEditor* aEditor, nsIDOMDocument *aChromeDoc); - // force an update of the UI. At some point, we could pass flags - // here to target certain things for updating. - NS_IMETHOD ForceUpdate(const PRUnichar *tagToUpdate); - // nsISelectionListener interface NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsISelection *aSel, short aReason); @@ -92,18 +88,7 @@ protected: }; PRBool SelectionIsCollapsed(); - - PRBool XULNodeExists(const char* nodeID); - - nsresult SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue); - nsresult UnsetNodeAttribute(const char* nodeID, const char* attributeName); - - nsresult UpdateParagraphState(const char* observerName, const char* attributeName); - nsresult UpdateListState(const char* observerName); - nsresult UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState); - nsresult UpdateFontFace(const char* observerName, const char* attributeName); - nsresult UpdateDirtyState(PRBool aNowDirty); - + nsresult UpdateDirtyState(PRBool aNowDirty); nsresult CallUpdateCommands(const nsString& aCommand); nsresult PrimeUpdateTimer(); @@ -112,37 +97,17 @@ protected: // this class should not hold references to the editor or editorShell. Doing // so would result in cirular reference chains. - nsIHTMLEditor* mEditor; // the HTML editor + nsIHTMLEditor* mEditor; // the HTML editor nsIDOMDocument* mChromeDoc; // XUL document for the chrome area nsIDOMWindowInternal* mDOMWindow; // nsIDOMWindowInternal used for calling UpdateCommands nsCOMPtr mUpdateTimer; - - // what we need to update - PRPackedBool mUpdateParagraph; - PRPackedBool mUpdateFont; - PRPackedBool mUpdateList; - - PRPackedBool mUpdateBold; - PRPackedBool mUpdateItalics; - PRPackedBool mUpdateUnderline; - // current state - PRInt8 mBoldState; - PRInt8 mItalicState; - PRInt8 mUnderlineState; - - PRInt8 mDirtyState; - - PRInt8 mSelectionCollapsed; - + PRInt8 mDirtyState; + PRInt8 mSelectionCollapsed; PRPackedBool mFirstDoOfFirstUndo; - - nsString mParagraphFormat; - nsString mFontString; - nsString mListTag; // contains "" for none, "ol" or "ul" - + }; extern "C" nsresult NS_NewInterfaceState(nsIHTMLEditor* aEditor, nsIDOMDocument* aChromeDoc, nsISelectionListener** aInstancePtrResult); diff --git a/editor/idl/nsIEditorShell.idl b/editor/idl/nsIEditorShell.idl index 8b077f3e79a..c809cef0194 100644 --- a/editor/idl/nsIEditorShell.idl +++ b/editor/idl/nsIEditorShell.idl @@ -178,11 +178,6 @@ interface nsIEditorShell : nsISupports /* General Utilities */ - /* UI updating - * tagToUpdate can be null or "" to update everything - */ - void UpdateInterfaceState(in wstring tagToUpdate); - /* Get string from the Editor's localized string bundle */ wstring GetString(in wstring name);