зеркало из https://github.com/mozilla/pjs.git
182554 r=caillon sr=roc+moz cleanup nsImageMap.cpp
This commit is contained in:
Родитель
e57b39458d
Коммит
ce88084032
|
@ -76,19 +76,18 @@ public:
|
|||
Area(nsIContent* aArea, PRBool aHasURL);
|
||||
virtual ~Area();
|
||||
|
||||
virtual void ParseCoords(const nsString& aSpec);
|
||||
virtual void ParseCoords(const nsAString& aSpec);
|
||||
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) = 0;
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const = 0;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC) = 0;
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect) = 0;
|
||||
virtual void GetShapeName(nsString& aResult) const = 0;
|
||||
|
||||
void HasFocus(PRBool aHasFocus);
|
||||
|
||||
void GetHREF(nsString& aHref) const;
|
||||
void GetTarget(nsString& aTarget) const;
|
||||
void GetAltText(nsString& aAltText) const;
|
||||
void GetHREF(nsAString& aHref) const;
|
||||
void GetTarget(nsAString& aTarget) const;
|
||||
void GetAltText(nsAString& aAltText) const;
|
||||
PRBool GetHasURL() const { return mHasURL; }
|
||||
void GetArea(nsIContent** aArea) const;
|
||||
|
||||
|
@ -121,7 +120,7 @@ Area::~Area()
|
|||
}
|
||||
|
||||
void
|
||||
Area::GetHREF(nsString& aHref) const
|
||||
Area::GetHREF(nsAString& aHref) const
|
||||
{
|
||||
aHref.Truncate();
|
||||
if (mArea) {
|
||||
|
@ -130,7 +129,7 @@ Area::GetHREF(nsString& aHref) const
|
|||
}
|
||||
|
||||
void
|
||||
Area::GetTarget(nsString& aTarget) const
|
||||
Area::GetTarget(nsAString& aTarget) const
|
||||
{
|
||||
aTarget.Truncate();
|
||||
if (mArea) {
|
||||
|
@ -139,7 +138,7 @@ Area::GetTarget(nsString& aTarget) const
|
|||
}
|
||||
|
||||
void
|
||||
Area::GetAltText(nsString& aAltText) const
|
||||
Area::GetAltText(nsAString& aAltText) const
|
||||
{
|
||||
aAltText.Truncate();
|
||||
if (mArea) {
|
||||
|
@ -333,7 +332,7 @@ static nscoord* lo_parse_coord_list(char *str, PRInt32* value_cnt)
|
|||
return value_list;
|
||||
}
|
||||
|
||||
void Area::ParseCoords(const nsString& aSpec)
|
||||
void Area::ParseCoords(const nsAString& aSpec)
|
||||
{
|
||||
char* cp = ToNewCString(aSpec);
|
||||
if (cp) {
|
||||
|
@ -354,11 +353,10 @@ public:
|
|||
DefaultArea(nsIContent* aArea, PRBool aHasURL);
|
||||
~DefaultArea();
|
||||
|
||||
virtual PRBool IsInside(nscoord x, nscoord y);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC);
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
||||
virtual void GetShapeName(nsString& aResult) const;
|
||||
};
|
||||
|
||||
DefaultArea::DefaultArea(nsIContent* aArea, PRBool aHasURL)
|
||||
|
@ -370,7 +368,7 @@ DefaultArea::~DefaultArea()
|
|||
{
|
||||
}
|
||||
|
||||
PRBool DefaultArea::IsInside(nscoord x, nscoord y)
|
||||
PRBool DefaultArea::IsInside(nscoord x, nscoord y) const
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
@ -383,11 +381,6 @@ void DefaultArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|||
{
|
||||
}
|
||||
|
||||
void DefaultArea::GetShapeName(nsString& aResult) const
|
||||
{
|
||||
aResult.Append(NS_LITERAL_STRING("default"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class RectArea : public Area {
|
||||
|
@ -395,12 +388,11 @@ public:
|
|||
RectArea(nsIContent* aArea, PRBool aHasURL);
|
||||
~RectArea();
|
||||
|
||||
virtual void ParseCoords(const nsString& aSpec);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y);
|
||||
virtual void ParseCoords(const nsAString& aSpec);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC);
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
||||
virtual void GetShapeName(nsString& aResult) const;
|
||||
};
|
||||
|
||||
RectArea::RectArea(nsIContent* aArea, PRBool aHasURL)
|
||||
|
@ -412,7 +404,7 @@ RectArea::~RectArea()
|
|||
{
|
||||
}
|
||||
|
||||
void RectArea::ParseCoords(const nsString& aSpec)
|
||||
void RectArea::ParseCoords(const nsAString& aSpec)
|
||||
{
|
||||
Area::ParseCoords(aSpec);
|
||||
|
||||
|
@ -489,7 +481,7 @@ void RectArea::ParseCoords(const nsString& aSpec)
|
|||
}
|
||||
rv = errorObject->Init(errorText.get(),
|
||||
NS_ConvertUTF8toUCS2(urlSpec).get(), /* file name */
|
||||
aSpec.get(), /* source line */
|
||||
PromiseFlatString(aSpec).get(), /* source line */
|
||||
0, /* line number */
|
||||
0, /* column number */
|
||||
flag,
|
||||
|
@ -501,7 +493,7 @@ void RectArea::ParseCoords(const nsString& aSpec)
|
|||
}
|
||||
}
|
||||
|
||||
PRBool RectArea::IsInside(nscoord x, nscoord y)
|
||||
PRBool RectArea::IsInside(nscoord x, nscoord y) const
|
||||
{
|
||||
if (mNumCoords >= 4) { // Note: > is for nav compatabilty
|
||||
nscoord x1 = mCoords[0];
|
||||
|
@ -549,16 +541,10 @@ void RectArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|||
NS_ASSERTION(x1 <= x2 && y1 <= y2,
|
||||
"Someone screwed up RectArea::ParseCoords");
|
||||
|
||||
nsRect tmp(x1, y1, x2, y2);
|
||||
aRect = tmp;
|
||||
aRect.SetRect(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
void RectArea::GetShapeName(nsString& aResult) const
|
||||
{
|
||||
aResult.Append(NS_LITERAL_STRING("rect"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class PolyArea : public Area {
|
||||
|
@ -566,11 +552,10 @@ public:
|
|||
PolyArea(nsIContent* aArea, PRBool aHasURL);
|
||||
~PolyArea();
|
||||
|
||||
virtual PRBool IsInside(nscoord x, nscoord y);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC);
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
||||
virtual void GetShapeName(nsString& aResult) const;
|
||||
};
|
||||
|
||||
PolyArea::PolyArea(nsIContent* aArea, PRBool aHasURL)
|
||||
|
@ -582,7 +567,7 @@ PolyArea::~PolyArea()
|
|||
{
|
||||
}
|
||||
|
||||
PRBool PolyArea::IsInside(nscoord x, nscoord y)
|
||||
PRBool PolyArea::IsInside(nscoord x, nscoord y) const
|
||||
{
|
||||
if (mNumCoords >= 6) {
|
||||
PRInt32 intersects = 0;
|
||||
|
@ -684,16 +669,10 @@ void PolyArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|||
y2 = y2 > ytmp ? y2 : ytmp;
|
||||
}
|
||||
|
||||
nsRect tmp(x1, y1, x2, y2);
|
||||
aRect = tmp;
|
||||
aRect.SetRect(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
void PolyArea::GetShapeName(nsString& aResult) const
|
||||
{
|
||||
aResult.Append(NS_LITERAL_STRING("polygon"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class CircleArea : public Area {
|
||||
|
@ -701,11 +680,10 @@ public:
|
|||
CircleArea(nsIContent* aArea, PRBool aHasURL);
|
||||
~CircleArea();
|
||||
|
||||
virtual PRBool IsInside(nscoord x, nscoord y);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC);
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
||||
virtual void GetShapeName(nsString& aResult) const;
|
||||
};
|
||||
|
||||
CircleArea::CircleArea(nsIContent* aArea, PRBool aHasURL)
|
||||
|
@ -717,7 +695,7 @@ CircleArea::~CircleArea()
|
|||
{
|
||||
}
|
||||
|
||||
PRBool CircleArea::IsInside(nscoord x, nscoord y)
|
||||
PRBool CircleArea::IsInside(nscoord x, nscoord y) const
|
||||
{
|
||||
// Note: > is for nav compatabilty
|
||||
if (mNumCoords >= 3) {
|
||||
|
@ -769,24 +747,16 @@ void CircleArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|||
return;
|
||||
}
|
||||
|
||||
nsRect tmp(x1 - radius, y1 - radius, x1 + radius, y1 + radius);
|
||||
aRect = tmp;
|
||||
aRect.SetRect(x1 - radius, y1 - radius, x1 + radius, y1 + radius);
|
||||
}
|
||||
}
|
||||
|
||||
void CircleArea::GetShapeName(nsString& aResult) const
|
||||
{
|
||||
aResult.Append(NS_LITERAL_STRING("circle"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
nsImageMap::nsImageMap()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mMap = nsnull;
|
||||
mDomMap = nsnull;
|
||||
mDocument = nsnull;
|
||||
mContainsBlockContents = PR_FALSE;
|
||||
}
|
||||
|
@ -811,37 +781,13 @@ nsImageMap::~nsImageMap()
|
|||
if (nsnull != mDocument) {
|
||||
mDocument->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
||||
}
|
||||
NS_IF_RELEASE(mMap);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsImageMap)
|
||||
NS_IMPL_RELEASE(nsImageMap)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageMap::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(NS_GET_IID(nsISupports)) ||
|
||||
iid.Equals(NS_GET_IID(nsIDocumentObserver))) {
|
||||
*result = NS_STATIC_CAST(nsIDocumentObserver*, this);
|
||||
}
|
||||
else if (iid.Equals(NS_GET_IID(nsIDOMFocusListener)) ||
|
||||
iid.Equals(NS_GET_IID(nsIDOMEventListener))) {
|
||||
*result = NS_STATIC_CAST(nsIDOMFocusListener*, this);
|
||||
}
|
||||
else if (iid.Equals(NS_GET_IID(nsIImageMap))) {
|
||||
*result = NS_STATIC_CAST(nsIImageMap*, this);
|
||||
}
|
||||
else {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMPL_ISUPPORTS4(nsImageMap,
|
||||
nsIDocumentObserver,
|
||||
nsIDOMFocusListener,
|
||||
nsIDOMEventListener,
|
||||
nsIImageMap);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageMap::GetBoundsForAreaContent(nsIContent *aContent,
|
||||
|
@ -884,17 +830,16 @@ nsImageMap::Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapE
|
|||
}
|
||||
mPresShell = aPresShell;
|
||||
mImageFrame = aImageFrame;
|
||||
mDomMap = aMap;
|
||||
|
||||
nsresult rv = aMap->QueryInterface(NS_GET_IID(nsIContent), (void**) &mMap);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = mMap->GetDocument(mDocument);
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != mDocument)) {
|
||||
mDocument->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
||||
// mDocument is a weak reference, so release the reference we got
|
||||
nsIDocument *temp = mDocument;
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
nsresult rv;
|
||||
mMap = do_QueryInterface(aMap, &rv);
|
||||
NS_ASSERTION(mMap, "aMap is not an nsIHTMLContent!");
|
||||
rv = mMap->GetDocument(mDocument);
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != mDocument)) {
|
||||
mDocument->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
||||
// mDocument is a weak reference, so release the reference we got
|
||||
nsIDocument *temp = mDocument;
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
|
||||
// "Compile" the areas in the map into faster access versions
|
||||
|
@ -907,23 +852,20 @@ nsresult
|
|||
nsImageMap::UpdateAreasForBlock(nsIContent* aParent, PRBool* aFoundAnchor)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* child;
|
||||
PRInt32 i, n;
|
||||
aParent->ChildCount(n);
|
||||
for (i = 0; (i < n) && NS_SUCCEEDED(rv); i++) {
|
||||
rv = aParent->ChildAt(i, child);
|
||||
nsCOMPtr<nsIContent> child;
|
||||
rv = aParent->ChildAt(i, *getter_AddRefs(child));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsIDOMHTMLAnchorElement* area;
|
||||
rv = child->QueryInterface(NS_GET_IID(nsIDOMHTMLAnchorElement), (void**) &area);
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> area = do_QueryInterface(child, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aFoundAnchor = PR_TRUE;
|
||||
rv = AddArea(child);
|
||||
NS_RELEASE(area);
|
||||
}
|
||||
else {
|
||||
rv = UpdateAreasForBlock(child, aFoundAnchor);
|
||||
}
|
||||
NS_RELEASE(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1022,10 +964,11 @@ nsImageMap::AddArea(nsIContent* aArea)
|
|||
PRBool
|
||||
nsImageMap::IsInside(nscoord aX, nscoord aY,
|
||||
nsIContent** aContent,
|
||||
nsString& aAbsURL,
|
||||
nsString& aTarget,
|
||||
nsString& aAltText)
|
||||
nsAString& aAbsURL,
|
||||
nsAString& aTarget,
|
||||
nsAString& aAltText) const
|
||||
{
|
||||
NS_ASSERTION(mMap, "Not initialized");
|
||||
PRInt32 i, n = mAreas.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
Area* area = (Area*) mAreas.ElementAt(i);
|
||||
|
@ -1034,21 +977,7 @@ nsImageMap::IsInside(nscoord aX, nscoord aY,
|
|||
// Set the image loader's source URL and base URL
|
||||
nsCOMPtr<nsIURI> baseUri;
|
||||
|
||||
if (mMap) {
|
||||
nsCOMPtr<nsIHTMLContent> htmlContent(do_QueryInterface(mMap));
|
||||
if (htmlContent) {
|
||||
htmlContent->GetBaseURL(*getter_AddRefs(baseUri));
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
mMap->GetDocument(*getter_AddRefs(doc));
|
||||
|
||||
if (doc) {
|
||||
// Could just use mDocument here...
|
||||
doc->GetBaseURL(*getter_AddRefs(baseUri));
|
||||
}
|
||||
}
|
||||
}
|
||||
mMap->GetBaseURL(*getter_AddRefs(baseUri));
|
||||
|
||||
if (!baseUri) {
|
||||
return PR_FALSE;
|
||||
|
@ -1060,13 +989,8 @@ nsImageMap::IsInside(nscoord aX, nscoord aY,
|
|||
}
|
||||
|
||||
area->GetTarget(aTarget);
|
||||
if (mMap && (aTarget.Length() == 0)) {
|
||||
nsCOMPtr<nsIHTMLContent> content(do_QueryInterface(mMap));
|
||||
|
||||
if (content) {
|
||||
content->GetBaseTarget(aTarget);
|
||||
}
|
||||
}
|
||||
if (aTarget.IsEmpty())
|
||||
mMap->GetBaseTarget(aTarget);
|
||||
|
||||
area->GetAltText(aAltText);
|
||||
|
||||
|
@ -1080,7 +1004,7 @@ nsImageMap::IsInside(nscoord aX, nscoord aY,
|
|||
}
|
||||
|
||||
PRBool
|
||||
nsImageMap::IsInside(nscoord aX, nscoord aY)
|
||||
nsImageMap::IsInside(nscoord aX, nscoord aY) const
|
||||
{
|
||||
PRInt32 i, n = mAreas.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
|
@ -1121,18 +1045,11 @@ PRBool
|
|||
nsImageMap::IsAncestorOf(nsIContent* aContent,
|
||||
nsIContent* aAncestorContent)
|
||||
{
|
||||
nsIContent* parent;
|
||||
nsresult rv = aContent->GetParent(parent);
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != parent)) {
|
||||
PRBool rBool;
|
||||
if (parent == aAncestorContent) {
|
||||
rBool = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
rBool = IsAncestorOf(parent, aAncestorContent);
|
||||
}
|
||||
NS_RELEASE(parent);
|
||||
return rBool;
|
||||
nsCOMPtr<nsIContent> parent;
|
||||
aContent->GetParent(*getter_AddRefs(parent));
|
||||
if (parent) {
|
||||
return parent == aAncestorContent ||
|
||||
IsAncestorOf(parent, aAncestorContent);
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
|
@ -1145,14 +1062,13 @@ nsImageMap::ContentChanged(nsIDocument *aDocument,
|
|||
{
|
||||
// If the parent of the changing content node is our map then update
|
||||
// the map.
|
||||
nsIContent* parent;
|
||||
nsresult rv = aContent->GetParent(parent);
|
||||
nsCOMPtr<nsIContent> parent;
|
||||
nsresult rv = aContent->GetParent(*getter_AddRefs(parent));
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != parent)) {
|
||||
if ((parent == mMap) ||
|
||||
(mContainsBlockContents && IsAncestorOf(parent, mMap))) {
|
||||
UpdateAreas();
|
||||
}
|
||||
NS_RELEASE(parent);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1167,14 +1083,11 @@ nsImageMap::AttributeChanged(nsIDocument *aDocument,
|
|||
{
|
||||
// If the parent of the changing content node is our map then update
|
||||
// the map.
|
||||
nsIContent* parent;
|
||||
nsresult rv = aContent->GetParent(parent);
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != parent)) {
|
||||
if ((parent == mMap) ||
|
||||
(mContainsBlockContents && IsAncestorOf(parent, mMap))) {
|
||||
UpdateAreas();
|
||||
}
|
||||
NS_RELEASE(parent);
|
||||
nsCOMPtr<nsIContent> parent;
|
||||
aContent->GetParent(*getter_AddRefs(parent));
|
||||
if ((parent == mMap) ||
|
||||
(mContainsBlockContents && IsAncestorOf(parent, mMap))) {
|
||||
UpdateAreas();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@
|
|||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIImageMap.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsIDOMHTMLAreaElement;
|
||||
class nsIDOMHTMLMapElement;
|
||||
class nsIPresContext;
|
||||
|
@ -71,16 +71,16 @@ public:
|
|||
*/
|
||||
PRBool IsInside(nscoord aX, nscoord aY,
|
||||
nsIContent** aContent,
|
||||
nsString& aAbsURL,
|
||||
nsString& aTarget,
|
||||
nsString& aAltText);
|
||||
nsAString& aAbsURL,
|
||||
nsAString& aTarget,
|
||||
nsAString& aAltText) const;
|
||||
|
||||
/**
|
||||
* See if the given aX,aY <b>pixel</b> coordinates are in the image
|
||||
* map. If they are then NS_OK is returned otherwise NS_NOT_INSIDE
|
||||
* is returned.
|
||||
*/
|
||||
PRBool IsInside(nscoord aX, nscoord aY);
|
||||
PRBool IsInside(nscoord aX, nscoord aY) const;
|
||||
|
||||
void Draw(nsIPresContext* aCX, nsIRenderingContext& aRC);
|
||||
|
||||
|
@ -129,8 +129,7 @@ protected:
|
|||
nsIPresShell* mPresShell; // WEAK - owns the frame that owns us
|
||||
nsIFrame* mImageFrame; // the frame that owns us
|
||||
nsIDocument* mDocument; // WEAK - the imagemap will not outlive the document
|
||||
nsIDOMHTMLMapElement* mDomMap;
|
||||
nsIContent* mMap;
|
||||
nsCOMPtr<nsIHTMLContent> mMap;
|
||||
nsAutoVoidArray mAreas; // almost always has some entries
|
||||
PRBool mContainsBlockContents;
|
||||
};
|
||||
|
|
|
@ -76,19 +76,18 @@ public:
|
|||
Area(nsIContent* aArea, PRBool aHasURL);
|
||||
virtual ~Area();
|
||||
|
||||
virtual void ParseCoords(const nsString& aSpec);
|
||||
virtual void ParseCoords(const nsAString& aSpec);
|
||||
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) = 0;
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const = 0;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC) = 0;
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect) = 0;
|
||||
virtual void GetShapeName(nsString& aResult) const = 0;
|
||||
|
||||
void HasFocus(PRBool aHasFocus);
|
||||
|
||||
void GetHREF(nsString& aHref) const;
|
||||
void GetTarget(nsString& aTarget) const;
|
||||
void GetAltText(nsString& aAltText) const;
|
||||
void GetHREF(nsAString& aHref) const;
|
||||
void GetTarget(nsAString& aTarget) const;
|
||||
void GetAltText(nsAString& aAltText) const;
|
||||
PRBool GetHasURL() const { return mHasURL; }
|
||||
void GetArea(nsIContent** aArea) const;
|
||||
|
||||
|
@ -121,7 +120,7 @@ Area::~Area()
|
|||
}
|
||||
|
||||
void
|
||||
Area::GetHREF(nsString& aHref) const
|
||||
Area::GetHREF(nsAString& aHref) const
|
||||
{
|
||||
aHref.Truncate();
|
||||
if (mArea) {
|
||||
|
@ -130,7 +129,7 @@ Area::GetHREF(nsString& aHref) const
|
|||
}
|
||||
|
||||
void
|
||||
Area::GetTarget(nsString& aTarget) const
|
||||
Area::GetTarget(nsAString& aTarget) const
|
||||
{
|
||||
aTarget.Truncate();
|
||||
if (mArea) {
|
||||
|
@ -139,7 +138,7 @@ Area::GetTarget(nsString& aTarget) const
|
|||
}
|
||||
|
||||
void
|
||||
Area::GetAltText(nsString& aAltText) const
|
||||
Area::GetAltText(nsAString& aAltText) const
|
||||
{
|
||||
aAltText.Truncate();
|
||||
if (mArea) {
|
||||
|
@ -333,7 +332,7 @@ static nscoord* lo_parse_coord_list(char *str, PRInt32* value_cnt)
|
|||
return value_list;
|
||||
}
|
||||
|
||||
void Area::ParseCoords(const nsString& aSpec)
|
||||
void Area::ParseCoords(const nsAString& aSpec)
|
||||
{
|
||||
char* cp = ToNewCString(aSpec);
|
||||
if (cp) {
|
||||
|
@ -354,11 +353,10 @@ public:
|
|||
DefaultArea(nsIContent* aArea, PRBool aHasURL);
|
||||
~DefaultArea();
|
||||
|
||||
virtual PRBool IsInside(nscoord x, nscoord y);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC);
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
||||
virtual void GetShapeName(nsString& aResult) const;
|
||||
};
|
||||
|
||||
DefaultArea::DefaultArea(nsIContent* aArea, PRBool aHasURL)
|
||||
|
@ -370,7 +368,7 @@ DefaultArea::~DefaultArea()
|
|||
{
|
||||
}
|
||||
|
||||
PRBool DefaultArea::IsInside(nscoord x, nscoord y)
|
||||
PRBool DefaultArea::IsInside(nscoord x, nscoord y) const
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
@ -383,11 +381,6 @@ void DefaultArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|||
{
|
||||
}
|
||||
|
||||
void DefaultArea::GetShapeName(nsString& aResult) const
|
||||
{
|
||||
aResult.Append(NS_LITERAL_STRING("default"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class RectArea : public Area {
|
||||
|
@ -395,12 +388,11 @@ public:
|
|||
RectArea(nsIContent* aArea, PRBool aHasURL);
|
||||
~RectArea();
|
||||
|
||||
virtual void ParseCoords(const nsString& aSpec);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y);
|
||||
virtual void ParseCoords(const nsAString& aSpec);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC);
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
||||
virtual void GetShapeName(nsString& aResult) const;
|
||||
};
|
||||
|
||||
RectArea::RectArea(nsIContent* aArea, PRBool aHasURL)
|
||||
|
@ -412,7 +404,7 @@ RectArea::~RectArea()
|
|||
{
|
||||
}
|
||||
|
||||
void RectArea::ParseCoords(const nsString& aSpec)
|
||||
void RectArea::ParseCoords(const nsAString& aSpec)
|
||||
{
|
||||
Area::ParseCoords(aSpec);
|
||||
|
||||
|
@ -489,7 +481,7 @@ void RectArea::ParseCoords(const nsString& aSpec)
|
|||
}
|
||||
rv = errorObject->Init(errorText.get(),
|
||||
NS_ConvertUTF8toUCS2(urlSpec).get(), /* file name */
|
||||
aSpec.get(), /* source line */
|
||||
PromiseFlatString(aSpec).get(), /* source line */
|
||||
0, /* line number */
|
||||
0, /* column number */
|
||||
flag,
|
||||
|
@ -501,7 +493,7 @@ void RectArea::ParseCoords(const nsString& aSpec)
|
|||
}
|
||||
}
|
||||
|
||||
PRBool RectArea::IsInside(nscoord x, nscoord y)
|
||||
PRBool RectArea::IsInside(nscoord x, nscoord y) const
|
||||
{
|
||||
if (mNumCoords >= 4) { // Note: > is for nav compatabilty
|
||||
nscoord x1 = mCoords[0];
|
||||
|
@ -549,16 +541,10 @@ void RectArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|||
NS_ASSERTION(x1 <= x2 && y1 <= y2,
|
||||
"Someone screwed up RectArea::ParseCoords");
|
||||
|
||||
nsRect tmp(x1, y1, x2, y2);
|
||||
aRect = tmp;
|
||||
aRect.SetRect(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
void RectArea::GetShapeName(nsString& aResult) const
|
||||
{
|
||||
aResult.Append(NS_LITERAL_STRING("rect"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class PolyArea : public Area {
|
||||
|
@ -566,11 +552,10 @@ public:
|
|||
PolyArea(nsIContent* aArea, PRBool aHasURL);
|
||||
~PolyArea();
|
||||
|
||||
virtual PRBool IsInside(nscoord x, nscoord y);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC);
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
||||
virtual void GetShapeName(nsString& aResult) const;
|
||||
};
|
||||
|
||||
PolyArea::PolyArea(nsIContent* aArea, PRBool aHasURL)
|
||||
|
@ -582,7 +567,7 @@ PolyArea::~PolyArea()
|
|||
{
|
||||
}
|
||||
|
||||
PRBool PolyArea::IsInside(nscoord x, nscoord y)
|
||||
PRBool PolyArea::IsInside(nscoord x, nscoord y) const
|
||||
{
|
||||
if (mNumCoords >= 6) {
|
||||
PRInt32 intersects = 0;
|
||||
|
@ -684,16 +669,10 @@ void PolyArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|||
y2 = y2 > ytmp ? y2 : ytmp;
|
||||
}
|
||||
|
||||
nsRect tmp(x1, y1, x2, y2);
|
||||
aRect = tmp;
|
||||
aRect.SetRect(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
void PolyArea::GetShapeName(nsString& aResult) const
|
||||
{
|
||||
aResult.Append(NS_LITERAL_STRING("polygon"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class CircleArea : public Area {
|
||||
|
@ -701,11 +680,10 @@ public:
|
|||
CircleArea(nsIContent* aArea, PRBool aHasURL);
|
||||
~CircleArea();
|
||||
|
||||
virtual PRBool IsInside(nscoord x, nscoord y);
|
||||
virtual PRBool IsInside(nscoord x, nscoord y) const;
|
||||
virtual void Draw(nsIPresContext* aCX,
|
||||
nsIRenderingContext& aRC);
|
||||
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
||||
virtual void GetShapeName(nsString& aResult) const;
|
||||
};
|
||||
|
||||
CircleArea::CircleArea(nsIContent* aArea, PRBool aHasURL)
|
||||
|
@ -717,7 +695,7 @@ CircleArea::~CircleArea()
|
|||
{
|
||||
}
|
||||
|
||||
PRBool CircleArea::IsInside(nscoord x, nscoord y)
|
||||
PRBool CircleArea::IsInside(nscoord x, nscoord y) const
|
||||
{
|
||||
// Note: > is for nav compatabilty
|
||||
if (mNumCoords >= 3) {
|
||||
|
@ -769,24 +747,16 @@ void CircleArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|||
return;
|
||||
}
|
||||
|
||||
nsRect tmp(x1 - radius, y1 - radius, x1 + radius, y1 + radius);
|
||||
aRect = tmp;
|
||||
aRect.SetRect(x1 - radius, y1 - radius, x1 + radius, y1 + radius);
|
||||
}
|
||||
}
|
||||
|
||||
void CircleArea::GetShapeName(nsString& aResult) const
|
||||
{
|
||||
aResult.Append(NS_LITERAL_STRING("circle"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
||||
nsImageMap::nsImageMap()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mMap = nsnull;
|
||||
mDomMap = nsnull;
|
||||
mDocument = nsnull;
|
||||
mContainsBlockContents = PR_FALSE;
|
||||
}
|
||||
|
@ -811,37 +781,13 @@ nsImageMap::~nsImageMap()
|
|||
if (nsnull != mDocument) {
|
||||
mDocument->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
||||
}
|
||||
NS_IF_RELEASE(mMap);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsImageMap)
|
||||
NS_IMPL_RELEASE(nsImageMap)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageMap::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(NS_GET_IID(nsISupports)) ||
|
||||
iid.Equals(NS_GET_IID(nsIDocumentObserver))) {
|
||||
*result = NS_STATIC_CAST(nsIDocumentObserver*, this);
|
||||
}
|
||||
else if (iid.Equals(NS_GET_IID(nsIDOMFocusListener)) ||
|
||||
iid.Equals(NS_GET_IID(nsIDOMEventListener))) {
|
||||
*result = NS_STATIC_CAST(nsIDOMFocusListener*, this);
|
||||
}
|
||||
else if (iid.Equals(NS_GET_IID(nsIImageMap))) {
|
||||
*result = NS_STATIC_CAST(nsIImageMap*, this);
|
||||
}
|
||||
else {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMPL_ISUPPORTS4(nsImageMap,
|
||||
nsIDocumentObserver,
|
||||
nsIDOMFocusListener,
|
||||
nsIDOMEventListener,
|
||||
nsIImageMap);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsImageMap::GetBoundsForAreaContent(nsIContent *aContent,
|
||||
|
@ -884,17 +830,16 @@ nsImageMap::Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapE
|
|||
}
|
||||
mPresShell = aPresShell;
|
||||
mImageFrame = aImageFrame;
|
||||
mDomMap = aMap;
|
||||
|
||||
nsresult rv = aMap->QueryInterface(NS_GET_IID(nsIContent), (void**) &mMap);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = mMap->GetDocument(mDocument);
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != mDocument)) {
|
||||
mDocument->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
||||
// mDocument is a weak reference, so release the reference we got
|
||||
nsIDocument *temp = mDocument;
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
nsresult rv;
|
||||
mMap = do_QueryInterface(aMap, &rv);
|
||||
NS_ASSERTION(mMap, "aMap is not an nsIHTMLContent!");
|
||||
rv = mMap->GetDocument(mDocument);
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != mDocument)) {
|
||||
mDocument->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
||||
// mDocument is a weak reference, so release the reference we got
|
||||
nsIDocument *temp = mDocument;
|
||||
NS_RELEASE(temp);
|
||||
}
|
||||
|
||||
// "Compile" the areas in the map into faster access versions
|
||||
|
@ -907,23 +852,20 @@ nsresult
|
|||
nsImageMap::UpdateAreasForBlock(nsIContent* aParent, PRBool* aFoundAnchor)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIContent* child;
|
||||
PRInt32 i, n;
|
||||
aParent->ChildCount(n);
|
||||
for (i = 0; (i < n) && NS_SUCCEEDED(rv); i++) {
|
||||
rv = aParent->ChildAt(i, child);
|
||||
nsCOMPtr<nsIContent> child;
|
||||
rv = aParent->ChildAt(i, *getter_AddRefs(child));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsIDOMHTMLAnchorElement* area;
|
||||
rv = child->QueryInterface(NS_GET_IID(nsIDOMHTMLAnchorElement), (void**) &area);
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> area = do_QueryInterface(child, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aFoundAnchor = PR_TRUE;
|
||||
rv = AddArea(child);
|
||||
NS_RELEASE(area);
|
||||
}
|
||||
else {
|
||||
rv = UpdateAreasForBlock(child, aFoundAnchor);
|
||||
}
|
||||
NS_RELEASE(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1022,10 +964,11 @@ nsImageMap::AddArea(nsIContent* aArea)
|
|||
PRBool
|
||||
nsImageMap::IsInside(nscoord aX, nscoord aY,
|
||||
nsIContent** aContent,
|
||||
nsString& aAbsURL,
|
||||
nsString& aTarget,
|
||||
nsString& aAltText)
|
||||
nsAString& aAbsURL,
|
||||
nsAString& aTarget,
|
||||
nsAString& aAltText) const
|
||||
{
|
||||
NS_ASSERTION(mMap, "Not initialized");
|
||||
PRInt32 i, n = mAreas.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
Area* area = (Area*) mAreas.ElementAt(i);
|
||||
|
@ -1034,21 +977,7 @@ nsImageMap::IsInside(nscoord aX, nscoord aY,
|
|||
// Set the image loader's source URL and base URL
|
||||
nsCOMPtr<nsIURI> baseUri;
|
||||
|
||||
if (mMap) {
|
||||
nsCOMPtr<nsIHTMLContent> htmlContent(do_QueryInterface(mMap));
|
||||
if (htmlContent) {
|
||||
htmlContent->GetBaseURL(*getter_AddRefs(baseUri));
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
mMap->GetDocument(*getter_AddRefs(doc));
|
||||
|
||||
if (doc) {
|
||||
// Could just use mDocument here...
|
||||
doc->GetBaseURL(*getter_AddRefs(baseUri));
|
||||
}
|
||||
}
|
||||
}
|
||||
mMap->GetBaseURL(*getter_AddRefs(baseUri));
|
||||
|
||||
if (!baseUri) {
|
||||
return PR_FALSE;
|
||||
|
@ -1060,13 +989,8 @@ nsImageMap::IsInside(nscoord aX, nscoord aY,
|
|||
}
|
||||
|
||||
area->GetTarget(aTarget);
|
||||
if (mMap && (aTarget.Length() == 0)) {
|
||||
nsCOMPtr<nsIHTMLContent> content(do_QueryInterface(mMap));
|
||||
|
||||
if (content) {
|
||||
content->GetBaseTarget(aTarget);
|
||||
}
|
||||
}
|
||||
if (aTarget.IsEmpty())
|
||||
mMap->GetBaseTarget(aTarget);
|
||||
|
||||
area->GetAltText(aAltText);
|
||||
|
||||
|
@ -1080,7 +1004,7 @@ nsImageMap::IsInside(nscoord aX, nscoord aY,
|
|||
}
|
||||
|
||||
PRBool
|
||||
nsImageMap::IsInside(nscoord aX, nscoord aY)
|
||||
nsImageMap::IsInside(nscoord aX, nscoord aY) const
|
||||
{
|
||||
PRInt32 i, n = mAreas.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
|
@ -1121,18 +1045,11 @@ PRBool
|
|||
nsImageMap::IsAncestorOf(nsIContent* aContent,
|
||||
nsIContent* aAncestorContent)
|
||||
{
|
||||
nsIContent* parent;
|
||||
nsresult rv = aContent->GetParent(parent);
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != parent)) {
|
||||
PRBool rBool;
|
||||
if (parent == aAncestorContent) {
|
||||
rBool = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
rBool = IsAncestorOf(parent, aAncestorContent);
|
||||
}
|
||||
NS_RELEASE(parent);
|
||||
return rBool;
|
||||
nsCOMPtr<nsIContent> parent;
|
||||
aContent->GetParent(*getter_AddRefs(parent));
|
||||
if (parent) {
|
||||
return parent == aAncestorContent ||
|
||||
IsAncestorOf(parent, aAncestorContent);
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
|
@ -1145,14 +1062,13 @@ nsImageMap::ContentChanged(nsIDocument *aDocument,
|
|||
{
|
||||
// If the parent of the changing content node is our map then update
|
||||
// the map.
|
||||
nsIContent* parent;
|
||||
nsresult rv = aContent->GetParent(parent);
|
||||
nsCOMPtr<nsIContent> parent;
|
||||
nsresult rv = aContent->GetParent(*getter_AddRefs(parent));
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != parent)) {
|
||||
if ((parent == mMap) ||
|
||||
(mContainsBlockContents && IsAncestorOf(parent, mMap))) {
|
||||
UpdateAreas();
|
||||
}
|
||||
NS_RELEASE(parent);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1167,14 +1083,11 @@ nsImageMap::AttributeChanged(nsIDocument *aDocument,
|
|||
{
|
||||
// If the parent of the changing content node is our map then update
|
||||
// the map.
|
||||
nsIContent* parent;
|
||||
nsresult rv = aContent->GetParent(parent);
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != parent)) {
|
||||
if ((parent == mMap) ||
|
||||
(mContainsBlockContents && IsAncestorOf(parent, mMap))) {
|
||||
UpdateAreas();
|
||||
}
|
||||
NS_RELEASE(parent);
|
||||
nsCOMPtr<nsIContent> parent;
|
||||
aContent->GetParent(*getter_AddRefs(parent));
|
||||
if ((parent == mMap) ||
|
||||
(mContainsBlockContents && IsAncestorOf(parent, mMap))) {
|
||||
UpdateAreas();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@
|
|||
#include "nsIDOMFocusListener.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIImageMap.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsIDOMHTMLAreaElement;
|
||||
class nsIDOMHTMLMapElement;
|
||||
class nsIPresContext;
|
||||
|
@ -71,16 +71,16 @@ public:
|
|||
*/
|
||||
PRBool IsInside(nscoord aX, nscoord aY,
|
||||
nsIContent** aContent,
|
||||
nsString& aAbsURL,
|
||||
nsString& aTarget,
|
||||
nsString& aAltText);
|
||||
nsAString& aAbsURL,
|
||||
nsAString& aTarget,
|
||||
nsAString& aAltText) const;
|
||||
|
||||
/**
|
||||
* See if the given aX,aY <b>pixel</b> coordinates are in the image
|
||||
* map. If they are then NS_OK is returned otherwise NS_NOT_INSIDE
|
||||
* is returned.
|
||||
*/
|
||||
PRBool IsInside(nscoord aX, nscoord aY);
|
||||
PRBool IsInside(nscoord aX, nscoord aY) const;
|
||||
|
||||
void Draw(nsIPresContext* aCX, nsIRenderingContext& aRC);
|
||||
|
||||
|
@ -129,8 +129,7 @@ protected:
|
|||
nsIPresShell* mPresShell; // WEAK - owns the frame that owns us
|
||||
nsIFrame* mImageFrame; // the frame that owns us
|
||||
nsIDocument* mDocument; // WEAK - the imagemap will not outlive the document
|
||||
nsIDOMHTMLMapElement* mDomMap;
|
||||
nsIContent* mMap;
|
||||
nsCOMPtr<nsIHTMLContent> mMap;
|
||||
nsAutoVoidArray mAreas; // almost always has some entries
|
||||
PRBool mContainsBlockContents;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче