mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Some utility methods, and added ForceUpdate.
This commit is contained in:
parent
628b73338b
commit
8f9b391882
@ -124,6 +124,13 @@ nsInterfaceState::NotifyDocumentStateChanged(PRBool aNowDirty)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifySelectionChanged()
|
||||
{
|
||||
return ForceUpdate();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::ForceUpdate()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -148,6 +155,25 @@ nsInterfaceState::NotifySelectionChanged()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsInterfaceState::SelectionIsCollapsed()
|
||||
{
|
||||
nsresult rv;
|
||||
// we don't care too much about failures here.
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> domSelection;
|
||||
rv = editor->GetSelection(getter_AddRefs(domSelection));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool selectionCollapsed = PR_FALSE;
|
||||
rv = domSelection->GetIsCollapsed(&selectionCollapsed);
|
||||
return selectionCollapsed;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateParagraphState(const char* observerName, const char* attributeName, nsString& ioParaFormat)
|
||||
@ -227,8 +253,15 @@ nsInterfaceState::UpdateFontFace(const char* observerName, const char* attribute
|
||||
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom("font"));
|
||||
nsAutoString faceStr("face");
|
||||
|
||||
rv = mEditor->GetInlineProperty(styleAtom, &faceStr, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
|
||||
if (SelectionIsCollapsed())
|
||||
{
|
||||
rv = mEditor->GetTypingStateValue(styleAtom, ioFontString);
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = mEditor->GetInlineProperty(styleAtom, &faceStr, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
}
|
||||
// XXX this needs finishing.
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -237,23 +270,35 @@ nsresult
|
||||
nsInterfaceState::UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRBool firstOfSelectionHasProp = PR_FALSE;
|
||||
PRBool anyOfSelectionHasProp = PR_FALSE;
|
||||
PRBool allOfSelectionHasProp = PR_FALSE;
|
||||
|
||||
|
||||
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom(tagName));
|
||||
|
||||
rv = mEditor->GetInlineProperty(styleAtom, nsnull, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
|
||||
PRBool &behaviour = allOfSelectionHasProp; // change this to alter the behaviour
|
||||
if (behaviour != ioState)
|
||||
PRBool testBoolean;
|
||||
if (SelectionIsCollapsed())
|
||||
{
|
||||
rv = SetNodeAttribute(observerName, attributeName, behaviour ? "true" : "false");
|
||||
PRBool stateHasProp = PR_FALSE;
|
||||
|
||||
rv = mEditor->GetTypingState(styleAtom, stateHasProp);
|
||||
testBoolean = stateHasProp;
|
||||
}
|
||||
else
|
||||
{
|
||||
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, testBoolean ? "true" : "false");
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
ioState = behaviour;
|
||||
ioState = testBoolean;
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -42,6 +42,10 @@ public:
|
||||
|
||||
NS_IMETHOD Init(nsIHTMLEditor* aEditor, nsIWebShell *aChromeWebShell);
|
||||
|
||||
// force an update of the UI. At some point, we could pass flags
|
||||
// here to target certain things for updating.
|
||||
NS_IMETHOD ForceUpdate();
|
||||
|
||||
// nsIDOMSelectionListener interface
|
||||
NS_IMETHOD NotifySelectionChanged();
|
||||
|
||||
@ -55,6 +59,8 @@ protected:
|
||||
eStateOn = PR_TRUE
|
||||
};
|
||||
|
||||
PRBool SelectionIsCollapsed();
|
||||
|
||||
nsresult SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue);
|
||||
nsresult UnsetNodeAttribute(const char* nodeID, const char* attributeName);
|
||||
|
||||
|
@ -124,6 +124,13 @@ nsInterfaceState::NotifyDocumentStateChanged(PRBool aNowDirty)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::NotifySelectionChanged()
|
||||
{
|
||||
return ForceUpdate();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInterfaceState::ForceUpdate()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -148,6 +155,25 @@ nsInterfaceState::NotifySelectionChanged()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsInterfaceState::SelectionIsCollapsed()
|
||||
{
|
||||
nsresult rv;
|
||||
// we don't care too much about failures here.
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelection> domSelection;
|
||||
rv = editor->GetSelection(getter_AddRefs(domSelection));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRBool selectionCollapsed = PR_FALSE;
|
||||
rv = domSelection->GetIsCollapsed(&selectionCollapsed);
|
||||
return selectionCollapsed;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsInterfaceState::UpdateParagraphState(const char* observerName, const char* attributeName, nsString& ioParaFormat)
|
||||
@ -227,8 +253,15 @@ nsInterfaceState::UpdateFontFace(const char* observerName, const char* attribute
|
||||
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom("font"));
|
||||
nsAutoString faceStr("face");
|
||||
|
||||
rv = mEditor->GetInlineProperty(styleAtom, &faceStr, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
|
||||
if (SelectionIsCollapsed())
|
||||
{
|
||||
rv = mEditor->GetTypingStateValue(styleAtom, ioFontString);
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = mEditor->GetInlineProperty(styleAtom, &faceStr, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
}
|
||||
// XXX this needs finishing.
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -237,23 +270,35 @@ nsresult
|
||||
nsInterfaceState::UpdateTextState(const char* tagName, const char* observerName, const char* attributeName, PRInt8& ioState)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRBool firstOfSelectionHasProp = PR_FALSE;
|
||||
PRBool anyOfSelectionHasProp = PR_FALSE;
|
||||
PRBool allOfSelectionHasProp = PR_FALSE;
|
||||
|
||||
|
||||
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom(tagName));
|
||||
|
||||
rv = mEditor->GetInlineProperty(styleAtom, nsnull, nsnull, firstOfSelectionHasProp, anyOfSelectionHasProp, allOfSelectionHasProp);
|
||||
|
||||
PRBool &behaviour = allOfSelectionHasProp; // change this to alter the behaviour
|
||||
if (behaviour != ioState)
|
||||
PRBool testBoolean;
|
||||
if (SelectionIsCollapsed())
|
||||
{
|
||||
rv = SetNodeAttribute(observerName, attributeName, behaviour ? "true" : "false");
|
||||
PRBool stateHasProp = PR_FALSE;
|
||||
|
||||
rv = mEditor->GetTypingState(styleAtom, stateHasProp);
|
||||
testBoolean = stateHasProp;
|
||||
}
|
||||
else
|
||||
{
|
||||
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, testBoolean ? "true" : "false");
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
ioState = behaviour;
|
||||
ioState = testBoolean;
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -42,6 +42,10 @@ public:
|
||||
|
||||
NS_IMETHOD Init(nsIHTMLEditor* aEditor, nsIWebShell *aChromeWebShell);
|
||||
|
||||
// force an update of the UI. At some point, we could pass flags
|
||||
// here to target certain things for updating.
|
||||
NS_IMETHOD ForceUpdate();
|
||||
|
||||
// nsIDOMSelectionListener interface
|
||||
NS_IMETHOD NotifySelectionChanged();
|
||||
|
||||
@ -55,6 +59,8 @@ protected:
|
||||
eStateOn = PR_TRUE
|
||||
};
|
||||
|
||||
PRBool SelectionIsCollapsed();
|
||||
|
||||
nsresult SetNodeAttribute(const char* nodeID, const char* attributeName, const nsString& newValue);
|
||||
nsresult UnsetNodeAttribute(const char* nodeID, const char* attributeName);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user