390414 - text-changed:delete event details no longer correct effective, r=aaronlev, sr=bz, a=dsicore

This commit is contained in:
surkov.alexander@gmail.com 2007-09-05 01:22:17 -07:00
parent 017060dc17
commit d91459d49c
10 changed files with 130 additions and 21 deletions

View File

@ -1171,11 +1171,18 @@ void nsDocAccessible::ContentStatesChanged(nsIDocument* aDocument,
nsHTMLSelectOptionAccessible::SelectionChangedIfOption(aContent2);
}
void nsDocAccessible::CharacterDataWillChange(nsIDocument *aDocument,
nsIContent* aContent,
CharacterDataChangeInfo* aInfo)
{
FireTextChangeEventForText(aContent, aInfo, PR_FALSE);
}
void nsDocAccessible::CharacterDataChanged(nsIDocument *aDocument,
nsIContent* aContent,
CharacterDataChangeInfo* aInfo)
{
FireTextChangedEventOnDOMCharacterDataModified(aContent, aInfo);
FireTextChangeEventForText(aContent, aInfo, PR_TRUE);
}
void
@ -1206,8 +1213,9 @@ nsDocAccessible::ParentChainChanged(nsIContent *aContent)
}
void
nsDocAccessible::FireTextChangedEventOnDOMCharacterDataModified(nsIContent *aContent,
CharacterDataChangeInfo* aInfo)
nsDocAccessible::FireTextChangeEventForText(nsIContent *aContent,
CharacterDataChangeInfo* aInfo,
PRBool aIsInserted)
{
if (!mIsContentLoaded || !mDocument) {
return;
@ -1229,26 +1237,38 @@ nsDocAccessible::FireTextChangedEventOnDOMCharacterDataModified(nsIContent *aCon
return;
PRInt32 start = aInfo->mChangeStart;
PRUint32 end = aInfo->mChangeEnd;
PRInt32 length = end - start;
PRUint32 replaceLen = aInfo->mReplaceLength;
PRInt32 offset = 0;
rv = textAccessible->DOMPointToHypertextOffset(node, start, &offset);
if (NS_FAILED(rv))
return;
// Text has been removed.
if (length > 0) {
nsCOMPtr<nsIAccessibleTextChangeEvent> event =
new nsAccTextChangeEvent(accessible, offset, length, PR_FALSE);
textAccessible->FireAccessibleEvent(event);
}
PRInt32 length = aIsInserted ?
aInfo->mReplaceLength; // text has been added
aInfo->mChangeEnd - start : // text has been removed
if (length > 0) {
nsCOMPtr<nsIPresShell> shell(do_QueryReferent(mWeakShell));
if (!shell)
return;
PRUint32 renderedStartOffset, renderedEndOffset;
nsIFrame* frame = shell->GetPrimaryFrameFor(aContent);
rv = textAccessible->ContentToRenderedOffset(frame, start,
&renderedStartOffset);
if (NS_FAILED(rv))
return;
rv = textAccessible->ContentToRenderedOffset(frame, start + length,
&renderedEndOffset);
if (NS_FAILED(rv))
return;
// Text has been added.
if (replaceLen) {
nsCOMPtr<nsIAccessibleTextChangeEvent> event =
new nsAccTextChangeEvent(accessible, offset, replaceLen, PR_TRUE);
new nsAccTextChangeEvent(accessible, offset,
renderedEndOffset - renderedStartOffset,
aIsInserted, PR_FALSE);
textAccessible->FireAccessibleEvent(event);
}
}

View File

@ -157,10 +157,17 @@ class nsDocAccessible : public nsHyperTextAccessibleWrap,
void ARIAAttributeChanged(nsIContent* aContent, nsIAtom* aAttribute);
/**
* Fire text changed event for charackter data changed.
* Fire text changed event for character data changed. The method is used
* from nsIMutationObserver methods.
*
* @param aContent the text node holding changed data
* @param aInfo info structure describing how the data was changed
* @param aIsInserted the flag pointed whether removed or inserted
* characters should be cause of event
*/
void FireTextChangedEventOnDOMCharacterDataModified(nsIContent *aContent,
CharacterDataChangeInfo* aInfo);
void FireTextChangeEventForText(nsIContent *aContent,
CharacterDataChangeInfo* aInfo,
PRBool aIsInserted);
/**
* Create a text change event for a changed node

View File

@ -45,8 +45,8 @@ class nsIDocument;
class nsINode;
#define NS_IMUTATION_OBSERVER_IID \
{ 0x93542eb8, 0x98e1, 0x46f6, \
{ 0xbb, 0xa2, 0x90, 0x54, 0x05, 0xfe, 0xbe, 0xf9 } }
{ 0x32e68316, 0x67d4, 0x44a5, \
{ 0x8d, 0x35, 0xd, 0x39, 0xf, 0xa9, 0xdf, 0x11 } }
/**
* Information details about a characterdata change
@ -75,6 +75,22 @@ class nsIMutationObserver : public nsISupports
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IMUTATION_OBSERVER_IID)
/**
* Notification that the node value of a data node (text, cdata, pi, comment)
* will be changed.
*
* This notification is not sent when a piece of content is
* added/removed from the document (the other notifications are used
* for that).
*
* @param aDocument The owner-document of aContent. Can be null.
* @param aContent The piece of content that changed. Is never null.
* @param aInfo The structure with information details about the change.
*/
virtual void CharacterDataWillChange(nsIDocument *aDocument,
nsIContent* aContent,
CharacterDataChangeInfo* aInfo) = 0;
/**
* Notification that the node value of a data node (text, cdata, pi, comment)
* has changed.
@ -85,7 +101,7 @@ public:
*
* @param aDocument The owner-document of aContent. Can be null.
* @param aContent The piece of content that changed. Is never null.
* @param aAppend Whether the change was an append
* @param aInfo The structure with information details about the change.
*/
virtual void CharacterDataChanged(nsIDocument *aDocument,
nsIContent* aContent,
@ -194,6 +210,11 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(nsIMutationObserver, NS_IMUTATION_OBSERVER_IID)
#define NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE \
virtual void CharacterDataWillChange(nsIDocument* aDocument, \
nsIContent* aContent, \
CharacterDataChangeInfo* aInfo);
#define NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED \
virtual void CharacterDataChanged(nsIDocument* aDocument, \
nsIContent* aContent, \
@ -231,6 +252,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIMutationObserver, NS_IMUTATION_OBSERVER_IID)
virtual void ParentChainChanged(nsIContent *aContent);
#define NS_DECL_NSIMUTATIONOBSERVER \
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE \
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED \
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED \
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED \
@ -247,6 +269,12 @@ _class::NodeWillBeDestroyed(const nsINode* aNode)
#define NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class) \
void \
_class::CharacterDataWillChange(nsIDocument* aDocument, \
nsIContent* aContent, \
CharacterDataChangeInfo* aInfo) \
{ \
} \
void \
_class::CharacterDataChanged(nsIDocument* aDocument, \
nsIContent* aContent, \
CharacterDataChangeInfo* aInfo) \

View File

@ -423,6 +423,16 @@ nsGenericDOMDataNode::SetTextInternal(PRUint32 aOffset, PRUint32 aCount,
endOffset = textLength;
}
if (aNotify) {
CharacterDataChangeInfo info = {
aOffset == textLength,
aOffset,
endOffset,
aLength
};
nsNodeUtils::CharacterDataWillChange(this, &info);
}
if (aOffset == 0 && endOffset == textLength) {
// Replacing whole text or old text was empty
mText.SetTo(aBuffer, aLength);

View File

@ -79,6 +79,15 @@
PR_END_MACRO
void
nsNodeUtils::CharacterDataWillChange(nsIContent* aContent,
CharacterDataChangeInfo* aInfo)
{
nsIDocument* doc = aContent->GetOwnerDoc();
IMPL_MUTATION_NOTIFICATION(CharacterDataWillChange, aContent,
(doc, aContent, aInfo));
}
void
nsNodeUtils::CharacterDataChanged(nsIContent* aContent,
CharacterDataChangeInfo* aInfo)

View File

@ -55,6 +55,15 @@ struct CharacterDataChangeInfo;
class nsNodeUtils
{
public:
/**
* Send CharacterDataWillChange notifications to nsIMutationObservers.
* @param aContent Node whose data changed
* @param aInfo Struct with information details about the change
* @see nsIMutationObserver::CharacterDataWillChange
*/
static void CharacterDataWillChange(nsIContent* aContent,
CharacterDataChangeInfo* aInfo);
/**
* Send CharacterDataChanged notifications to nsIMutationObservers.
* @param aContent Node whose data changed

View File

@ -347,6 +347,10 @@ nsXMLEventsManager::EndLoad(nsIDocument* aDocument)
AddListeners(aDocument);
}
NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(nsXMLEventsManager)
void
nsXMLEventsManager::CharacterDataWillChange(nsIDocument* aDocument,
nsIContent* aContent,
CharacterDataChangeInfo* aInfo) {}
void
nsXMLEventsManager::CharacterDataChanged(nsIDocument* aDocument,
nsIContent* aContent,

View File

@ -1181,6 +1181,15 @@ nsBindingManager::RemoveObserver(nsIMutationObserver* aObserver)
return mObservers.RemoveObserver(aObserver);
}
void
nsBindingManager::CharacterDataWillChange(nsIDocument* aDocument,
nsIContent* aContent,
CharacterDataChangeInfo* aInfo)
{
NS_BINDINGMANAGER_NOTIFY_OBSERVERS(CharacterDataWillChange,
(aDocument, aContent, aInfo));
}
void
nsBindingManager::CharacterDataChanged(nsIDocument* aDocument,
nsIContent* aContent,

View File

@ -648,6 +648,13 @@ nsSHEntry::NodeWillBeDestroyed(const nsINode* aNode)
NS_NOTREACHED("Document destroyed while we're holding a strong ref to it");
}
void
nsSHEntry::CharacterDataWillChange(nsIDocument* aDocument,
nsIContent* aContent,
CharacterDataChangeInfo* aInfo)
{
}
void
nsSHEntry::CharacterDataChanged(nsIDocument* aDocument,
nsIContent* aContent,

View File

@ -846,6 +846,12 @@ NS_IMETHODIMP nsMenuBarX::Paint()
//
nsMenuBarX::CharacterDataWillChange(nsIDocument * aDocument,
nsIContent * aContent,
CharacterDataChangeInfo * aInfo)
{
}
void
nsMenuBarX::CharacterDataChanged(nsIDocument * aDocument,
nsIContent * aContent,