Bug 811755 - Send notification when BR nodes become content/non-content; r=masayuki

This commit is contained in:
Jim Chen 2012-12-05 11:09:56 -05:00
parent 5a875cad20
commit 648fae1037
3 changed files with 52 additions and 1 deletions

View File

@ -222,7 +222,8 @@ static uint32_t CountNewlinesInNativeLength(nsIContent* aContent,
}
#endif
static uint32_t GetNativeTextLength(nsIContent* aContent, uint32_t aMaxLength = UINT32_MAX)
/* static */ uint32_t
nsContentEventHandler::GetNativeTextLength(nsIContent* aContent, uint32_t aMaxLength)
{
if (aContent->IsNodeOfType(nsINode::eTEXT)) {
uint32_t textLengthDifference =

View File

@ -80,6 +80,9 @@ public:
static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
nsRange* aRange,
uint32_t* aOffset);
// Get the native text length of a content node excluding any children
static uint32_t GetNativeTextLength(nsIContent* aContent,
uint32_t aMaxLength = UINT32_MAX);
protected:
// Make the DOM range from the offset of FlatText and the text length.
// If aExpandToClusterBoundaries is true, the start offset and the end one are

View File

@ -62,6 +62,8 @@ public:
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
void Init(nsIWidget* aWidget,
nsPresContext* aPresContext,
@ -79,6 +81,7 @@ private:
void ObserveEditableNode();
bool mObserving;
uint32_t mPreAttrChangeLength;
};
/******************************************************************/
@ -976,6 +979,50 @@ nsTextStateManager::ContentRemoved(nsIDocument* aDocument,
new TextChangeEvent(this, offset, offset + childOffset, offset));
}
static nsIContent*
GetContentBR(mozilla::dom::Element *aElement) {
if (!aElement->IsNodeOfType(nsINode::eCONTENT)) {
return nullptr;
}
nsIContent *content = static_cast<nsIContent*>(aElement);
return content->IsHTML(nsGkAtoms::br) ? content : nullptr;
}
void
nsTextStateManager::AttributeWillChange(nsIDocument* aDocument,
mozilla::dom::Element* aElement,
int32_t aNameSpaceID,
nsIAtom* aAttribute,
int32_t aModType)
{
nsIContent *content = GetContentBR(aElement);
mPreAttrChangeLength = content ?
nsContentEventHandler::GetNativeTextLength(content) : 0;
}
void
nsTextStateManager::AttributeChanged(nsIDocument* aDocument,
mozilla::dom::Element* aElement,
int32_t aNameSpaceID,
nsIAtom* aAttribute,
int32_t aModType)
{
nsIContent *content = GetContentBR(aElement);
if (!content) {
return;
}
uint32_t postAttrChangeLength =
nsContentEventHandler::GetNativeTextLength(content);
if (postAttrChangeLength != mPreAttrChangeLength) {
uint32_t start;
if (NS_SUCCEEDED(nsContentEventHandler::GetFlatTextOffsetOfRange(
mRootContent, content, 0, &start))) {
nsContentUtils::AddScriptRunner(new TextChangeEvent(this, start,
start + mPreAttrChangeLength, start + postAttrChangeLength));
}
}
}
bool
nsIMEStateManager::IsEditable(nsINode* node)
{