From 446dec40b6d745fdb9143d2d87a7b4cef4aeb11b Mon Sep 17 00:00:00 2001 From: "vidur%netscape.com" Date: Mon, 28 Sep 1998 21:22:31 +0000 Subject: [PATCH] Fixed image.src=. Forwarded AttributeChanged notifications from nsPlaceholderFrame to its anchored item. Got rid of redundant calls to AttributeChanged. --- .../html/content/src/nsGenericHTMLElement.cpp | 1 + layout/generic/nsImageFrame.cpp | 65 +++++++------------ layout/generic/nsPlaceholderFrame.cpp | 14 ++++ layout/generic/nsPlaceholderFrame.h | 5 ++ layout/html/base/src/nsImageFrame.cpp | 65 +++++++------------ layout/html/base/src/nsPlaceholderFrame.cpp | 14 ++++ layout/html/base/src/nsPlaceholderFrame.h | 5 ++ .../html/content/src/nsGenericHTMLElement.cpp | 1 + 8 files changed, 86 insertions(+), 84 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 9a65313cc6e1..ea83dd54c97a 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -1197,6 +1197,7 @@ nsGenericHTMLElement::SetAttribute(nsIAtom* aAttribute, mContent->StringToAttribute(aAttribute, aValue, val)) { // string value was mapped to nsHTMLValue, set it that way result = SetAttribute(aAttribute, val, aNotify); + return result; } else { // set as string value to avoid another string copy diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 92b2a4d78dd3..44d5062dc5be 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -71,10 +71,6 @@ public: nsIFrame** aFrame, nsIContent** aContent, PRInt32& aCursor); - NS_IMETHOD ContentChanged(nsIPresShell* aShell, - nsIPresContext* aPresContext, - nsIContent* aChild, - nsISupports* aSubContent); NS_IMETHOD AttributeChanged(nsIPresShell* aShell, nsIPresContext* aPresContext, nsIContent* aChild, @@ -898,29 +894,36 @@ ImageFrame::GetCursorAndContentAt(nsIPresContext& aPresContext, } NS_IMETHODIMP -ImageFrame::ContentChanged(nsIPresShell* aShell, - nsIPresContext* aPresContext, - nsIContent* aChild, - nsISupports* aSubContent) +ImageFrame::AttributeChanged(nsIPresShell* aShell, + nsIPresContext* aPresContext, + nsIContent* aChild, + nsIAtom* aAttribute) { - // See if the src attribute changed; if it did then trigger a redraw - // by firing up a new image load request. Otherwise let our base - // class handle the content-changed request. - nsAutoString oldSRC; - mImageLoader.GetURL(oldSRC); + nsresult rv = nsLeafFrame::AttributeChanged(aShell, aPresContext, aChild, + aAttribute); + if (NS_OK != rv) { + return rv; + } + if ((nsHTMLAtoms::width == aAttribute) || + (nsHTMLAtoms::height == aAttribute)) { + nsHTMLContainerFrame::ApplyStyleChangeToTree(*aPresContext, this); + nsHTMLContainerFrame::StyleChangeReflow(*aPresContext, this); + } + else if (nsHTMLAtoms::src == aAttribute) { + nsAutoString oldSRC; + mImageLoader.GetURL(oldSRC); + nsAutoString newSRC; - // Get src attribute's value and construct a new absolute url from it - nsAutoString newSRC; - if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("SRC", newSRC)) { + aChild->GetAttribute("src", newSRC); if (!oldSRC.Equals(newSRC)) { mSizeFrozen = PR_TRUE; - + #ifdef NS_DEBUG char oldcbuf[100], newcbuf[100]; oldSRC.ToCString(oldcbuf, sizeof(oldcbuf)); newSRC.ToCString(newcbuf, sizeof(newcbuf)); NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, - ("ImageFrame::ContentChanged: new image source; old='%s' new='%s'", + ("ImageFrame::AttributeChanged: new image source; old='%s' new='%s'", oldcbuf, newcbuf)); #endif @@ -934,8 +937,8 @@ ImageFrame::ContentChanged(nsIPresShell* aShell, PR_FALSE, loadStatus); NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, - ("ImageFrame::ContentChanged: loadImage status=%x", - loadStatus)); + ("ImageFrame::AttributeChanged: loadImage status=%x", + loadStatus)); // If the image is already ready then we need to trigger a // redraw because the image loader won't. @@ -954,30 +957,8 @@ ImageFrame::ContentChanged(nsIPresShell* aShell, vm->UpdateView(view, bounds, 0); NS_RELEASE(vm); } - - return NS_OK; } } - return ImageFrameSuper::ContentChanged(aShell, aPresContext, aChild, - aSubContent); -} - -NS_IMETHODIMP -ImageFrame::AttributeChanged(nsIPresShell* aShell, - nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute) -{ - nsresult rv = nsLeafFrame::AttributeChanged(aShell, aPresContext, aChild, - aAttribute); - if (NS_OK != rv) { - return rv; - } - if ((nsHTMLAtoms::width == aAttribute) || - (nsHTMLAtoms::height == aAttribute)) { - nsHTMLContainerFrame::ApplyStyleChangeToTree(*aPresContext, this); - nsHTMLContainerFrame::StyleChangeReflow(*aPresContext, this); - } return NS_OK; } diff --git a/layout/generic/nsPlaceholderFrame.cpp b/layout/generic/nsPlaceholderFrame.cpp index 2d8b4c6d63c6..2f5c16b8d27d 100644 --- a/layout/generic/nsPlaceholderFrame.cpp +++ b/layout/generic/nsPlaceholderFrame.cpp @@ -154,6 +154,20 @@ NS_IMETHODIMP nsPlaceholderFrame::ContentChanged(nsIPresShell* aShell, return NS_OK; } +NS_IMETHODIMP +nsPlaceholderFrame::AttributeChanged(nsIPresShell* aShell, + nsIPresContext* aPresContext, + nsIContent* aChild, + nsIAtom* aAttribute) +{ + // Forward the notification to the floater + if (nsnull != mAnchoredItem) { + return mAnchoredItem->AttributeChanged(aShell, aPresContext, aChild, aAttribute); + } + + return NS_OK; +} + NS_IMETHODIMP nsPlaceholderFrame::ListTag(FILE* out) const { fputs("*placeholder", out); diff --git a/layout/generic/nsPlaceholderFrame.h b/layout/generic/nsPlaceholderFrame.h index 2a0b350e51b3..b1e8a9b909de 100644 --- a/layout/generic/nsPlaceholderFrame.h +++ b/layout/generic/nsPlaceholderFrame.h @@ -55,6 +55,11 @@ public: nsIContent* aChild, nsISupports* aSubContent); + NS_IMETHOD AttributeChanged(nsIPresShell* aShell, + nsIPresContext* aPresContext, + nsIContent* aChild, + nsIAtom* aAttribute); + NS_IMETHOD ListTag(FILE* out = stdout) const; protected: diff --git a/layout/html/base/src/nsImageFrame.cpp b/layout/html/base/src/nsImageFrame.cpp index 92b2a4d78dd3..44d5062dc5be 100644 --- a/layout/html/base/src/nsImageFrame.cpp +++ b/layout/html/base/src/nsImageFrame.cpp @@ -71,10 +71,6 @@ public: nsIFrame** aFrame, nsIContent** aContent, PRInt32& aCursor); - NS_IMETHOD ContentChanged(nsIPresShell* aShell, - nsIPresContext* aPresContext, - nsIContent* aChild, - nsISupports* aSubContent); NS_IMETHOD AttributeChanged(nsIPresShell* aShell, nsIPresContext* aPresContext, nsIContent* aChild, @@ -898,29 +894,36 @@ ImageFrame::GetCursorAndContentAt(nsIPresContext& aPresContext, } NS_IMETHODIMP -ImageFrame::ContentChanged(nsIPresShell* aShell, - nsIPresContext* aPresContext, - nsIContent* aChild, - nsISupports* aSubContent) +ImageFrame::AttributeChanged(nsIPresShell* aShell, + nsIPresContext* aPresContext, + nsIContent* aChild, + nsIAtom* aAttribute) { - // See if the src attribute changed; if it did then trigger a redraw - // by firing up a new image load request. Otherwise let our base - // class handle the content-changed request. - nsAutoString oldSRC; - mImageLoader.GetURL(oldSRC); + nsresult rv = nsLeafFrame::AttributeChanged(aShell, aPresContext, aChild, + aAttribute); + if (NS_OK != rv) { + return rv; + } + if ((nsHTMLAtoms::width == aAttribute) || + (nsHTMLAtoms::height == aAttribute)) { + nsHTMLContainerFrame::ApplyStyleChangeToTree(*aPresContext, this); + nsHTMLContainerFrame::StyleChangeReflow(*aPresContext, this); + } + else if (nsHTMLAtoms::src == aAttribute) { + nsAutoString oldSRC; + mImageLoader.GetURL(oldSRC); + nsAutoString newSRC; - // Get src attribute's value and construct a new absolute url from it - nsAutoString newSRC; - if (NS_CONTENT_ATTR_HAS_VALUE == mContent->GetAttribute("SRC", newSRC)) { + aChild->GetAttribute("src", newSRC); if (!oldSRC.Equals(newSRC)) { mSizeFrozen = PR_TRUE; - + #ifdef NS_DEBUG char oldcbuf[100], newcbuf[100]; oldSRC.ToCString(oldcbuf, sizeof(oldcbuf)); newSRC.ToCString(newcbuf, sizeof(newcbuf)); NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, - ("ImageFrame::ContentChanged: new image source; old='%s' new='%s'", + ("ImageFrame::AttributeChanged: new image source; old='%s' new='%s'", oldcbuf, newcbuf)); #endif @@ -934,8 +937,8 @@ ImageFrame::ContentChanged(nsIPresShell* aShell, PR_FALSE, loadStatus); NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, - ("ImageFrame::ContentChanged: loadImage status=%x", - loadStatus)); + ("ImageFrame::AttributeChanged: loadImage status=%x", + loadStatus)); // If the image is already ready then we need to trigger a // redraw because the image loader won't. @@ -954,30 +957,8 @@ ImageFrame::ContentChanged(nsIPresShell* aShell, vm->UpdateView(view, bounds, 0); NS_RELEASE(vm); } - - return NS_OK; } } - return ImageFrameSuper::ContentChanged(aShell, aPresContext, aChild, - aSubContent); -} - -NS_IMETHODIMP -ImageFrame::AttributeChanged(nsIPresShell* aShell, - nsIPresContext* aPresContext, - nsIContent* aChild, - nsIAtom* aAttribute) -{ - nsresult rv = nsLeafFrame::AttributeChanged(aShell, aPresContext, aChild, - aAttribute); - if (NS_OK != rv) { - return rv; - } - if ((nsHTMLAtoms::width == aAttribute) || - (nsHTMLAtoms::height == aAttribute)) { - nsHTMLContainerFrame::ApplyStyleChangeToTree(*aPresContext, this); - nsHTMLContainerFrame::StyleChangeReflow(*aPresContext, this); - } return NS_OK; } diff --git a/layout/html/base/src/nsPlaceholderFrame.cpp b/layout/html/base/src/nsPlaceholderFrame.cpp index 2d8b4c6d63c6..2f5c16b8d27d 100644 --- a/layout/html/base/src/nsPlaceholderFrame.cpp +++ b/layout/html/base/src/nsPlaceholderFrame.cpp @@ -154,6 +154,20 @@ NS_IMETHODIMP nsPlaceholderFrame::ContentChanged(nsIPresShell* aShell, return NS_OK; } +NS_IMETHODIMP +nsPlaceholderFrame::AttributeChanged(nsIPresShell* aShell, + nsIPresContext* aPresContext, + nsIContent* aChild, + nsIAtom* aAttribute) +{ + // Forward the notification to the floater + if (nsnull != mAnchoredItem) { + return mAnchoredItem->AttributeChanged(aShell, aPresContext, aChild, aAttribute); + } + + return NS_OK; +} + NS_IMETHODIMP nsPlaceholderFrame::ListTag(FILE* out) const { fputs("*placeholder", out); diff --git a/layout/html/base/src/nsPlaceholderFrame.h b/layout/html/base/src/nsPlaceholderFrame.h index 2a0b350e51b3..b1e8a9b909de 100644 --- a/layout/html/base/src/nsPlaceholderFrame.h +++ b/layout/html/base/src/nsPlaceholderFrame.h @@ -55,6 +55,11 @@ public: nsIContent* aChild, nsISupports* aSubContent); + NS_IMETHOD AttributeChanged(nsIPresShell* aShell, + nsIPresContext* aPresContext, + nsIContent* aChild, + nsIAtom* aAttribute); + NS_IMETHOD ListTag(FILE* out = stdout) const; protected: diff --git a/layout/html/content/src/nsGenericHTMLElement.cpp b/layout/html/content/src/nsGenericHTMLElement.cpp index 9a65313cc6e1..ea83dd54c97a 100644 --- a/layout/html/content/src/nsGenericHTMLElement.cpp +++ b/layout/html/content/src/nsGenericHTMLElement.cpp @@ -1197,6 +1197,7 @@ nsGenericHTMLElement::SetAttribute(nsIAtom* aAttribute, mContent->StringToAttribute(aAttribute, aValue, val)) { // string value was mapped to nsHTMLValue, set it that way result = SetAttribute(aAttribute, val, aNotify); + return result; } else { // set as string value to avoid another string copy