1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-14 00:24:54 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
1999-01-09 03:13:53 +03:00
|
|
|
#include "nsImageMap.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIURL.h"
|
1999-06-23 07:29:44 +04:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1998-06-06 01:06:24 +04:00
|
|
|
#include "nsISizeOfHandler.h"
|
1999-01-06 02:02:27 +03:00
|
|
|
#include "nsTextFragment.h"
|
1999-01-09 03:13:53 +03:00
|
|
|
#include "nsIContent.h"
|
1999-03-01 19:57:35 +03:00
|
|
|
#include "nsIDOMHTMLElement.h"
|
1999-01-09 03:13:53 +03:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
|
|
|
#include "nsIDOMHTMLAreaElement.h"
|
1999-03-01 19:57:35 +03:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
1999-01-09 03:13:53 +03:00
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIDocument.h"
|
1999-03-01 19:57:35 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
1999-07-22 22:47:23 +04:00
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
#include "nsIDOMEventReceiver.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIFrame.h"
|
2000-08-18 10:27:42 +04:00
|
|
|
#include "nsIFrameManager.h"
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsCoord.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
class Area {
|
|
|
|
public:
|
2000-02-11 04:24:59 +03:00
|
|
|
Area(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL);
|
1998-04-14 00:24:54 +04:00
|
|
|
virtual ~Area();
|
|
|
|
|
|
|
|
void ParseCoords(const nsString& aSpec);
|
|
|
|
|
|
|
|
virtual PRBool IsInside(nscoord x, nscoord y) = 0;
|
1999-11-24 09:03:41 +03:00
|
|
|
virtual void Draw(nsIPresContext* aCX,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIRenderingContext& aRC) = 0;
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect) = 0;
|
1998-07-15 02:34:27 +04:00
|
|
|
virtual void GetShapeName(nsString& aResult) const = 0;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
void ToHTML(nsString& aResult);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
void HasFocus(PRBool aHasFocus);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
void GetHREF(nsString& aHref) const;
|
|
|
|
void GetTarget(nsString& aTarget) const;
|
|
|
|
void GetAltText(nsString& aAltText) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
PRBool GetSuppress() const { return mSuppressFeedback; }
|
2000-02-11 04:24:59 +03:00
|
|
|
PRBool GetHasURL() const { return mHasURL; }
|
|
|
|
void GetArea(nsIContent** aArea) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#ifdef DEBUG
|
1999-08-31 07:09:40 +04:00
|
|
|
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|
1998-06-06 01:06:24 +04:00
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
nsCOMPtr<nsIContent> mArea;
|
1998-04-14 00:24:54 +04:00
|
|
|
nscoord* mCoords;
|
|
|
|
PRInt32 mNumCoords;
|
|
|
|
PRBool mSuppressFeedback;
|
1999-03-19 00:03:25 +03:00
|
|
|
PRBool mHasURL;
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
PRBool mHasFocus;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(Area)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
Area::Area(nsIContent* aArea,
|
1999-03-01 19:57:35 +03:00
|
|
|
PRBool aSuppress, PRBool aHasURL)
|
2000-02-11 04:24:59 +03:00
|
|
|
: mArea(aArea), mSuppressFeedback(aSuppress), mHasURL(aHasURL)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(Area);
|
1998-04-14 00:24:54 +04:00
|
|
|
mCoords = nsnull;
|
|
|
|
mNumCoords = 0;
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
mHasFocus = PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Area::~Area()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(Area);
|
1998-04-14 00:24:54 +04:00
|
|
|
delete [] mCoords;
|
|
|
|
}
|
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
void
|
|
|
|
Area::GetHREF(nsString& aHref) const
|
|
|
|
{
|
|
|
|
aHref.Truncate();
|
|
|
|
if (mArea) {
|
|
|
|
mArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::href, aHref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Area::GetTarget(nsString& aTarget) const
|
|
|
|
{
|
|
|
|
aTarget.Truncate();
|
|
|
|
if (mArea) {
|
|
|
|
mArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::target, aTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Area::GetAltText(nsString& aAltText) const
|
|
|
|
{
|
|
|
|
aAltText.Truncate();
|
|
|
|
if (mArea) {
|
|
|
|
mArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::alt, aAltText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Area::GetArea(nsIContent** aArea) const
|
|
|
|
{
|
|
|
|
*aArea = mArea;
|
|
|
|
NS_IF_ADDREF(*aArea);
|
|
|
|
}
|
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#ifdef DEBUG
|
1998-06-06 01:06:24 +04:00
|
|
|
void
|
1999-08-31 07:09:40 +04:00
|
|
|
Area::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
1998-06-06 01:06:24 +04:00
|
|
|
{
|
1999-08-31 07:09:40 +04:00
|
|
|
if (aResult) {
|
|
|
|
PRUint32 sum = sizeof(*this);
|
|
|
|
sum += mNumCoords * sizeof(nscoord);
|
|
|
|
*aResult = sum;
|
|
|
|
}
|
1998-06-06 01:06:24 +04:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|
1998-06-06 01:06:24 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#define XP_ATOI(_s) ::atoi(_s)
|
|
|
|
|
|
|
|
// XXX straight copy from laymap.c
|
|
|
|
static nscoord* lo_parse_coord_list(char *str, PRInt32* value_cnt)
|
|
|
|
{
|
|
|
|
char *tptr;
|
|
|
|
char *n_str;
|
|
|
|
PRInt32 i, cnt;
|
|
|
|
PRInt32 *value_list;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Nothing in an empty list
|
|
|
|
*/
|
|
|
|
*value_cnt = 0;
|
|
|
|
if ((str == NULL)||(*str == '\0'))
|
|
|
|
{
|
|
|
|
return((PRInt32 *)NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip beginning whitespace, all whitespace is empty list.
|
|
|
|
*/
|
|
|
|
n_str = str;
|
|
|
|
while (XP_IS_SPACE(*n_str))
|
|
|
|
{
|
|
|
|
n_str++;
|
|
|
|
}
|
|
|
|
if (*n_str == '\0')
|
|
|
|
{
|
|
|
|
return((PRInt32 *)NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make a pass where any two numbers separated by just whitespace
|
|
|
|
* are given a comma separator. Count entries while passing.
|
|
|
|
*/
|
|
|
|
cnt = 0;
|
|
|
|
while (*n_str != '\0')
|
|
|
|
{
|
|
|
|
PRBool has_comma;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to a separator
|
|
|
|
*/
|
|
|
|
tptr = n_str;
|
|
|
|
while ((!XP_IS_SPACE(*tptr))&&(*tptr != ',')&&(*tptr != '\0'))
|
|
|
|
{
|
|
|
|
tptr++;
|
|
|
|
}
|
|
|
|
n_str = tptr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no more entries, break out here
|
|
|
|
*/
|
|
|
|
if (*n_str == '\0')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip to the end of the separator, noting if we have a
|
|
|
|
* comma.
|
|
|
|
*/
|
|
|
|
has_comma = PR_FALSE;
|
|
|
|
while ((XP_IS_SPACE(*tptr))||(*tptr == ','))
|
|
|
|
{
|
|
|
|
if (*tptr == ',')
|
|
|
|
{
|
|
|
|
if (has_comma == PR_FALSE)
|
|
|
|
{
|
|
|
|
has_comma = PR_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tptr++;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If this was trailing whitespace we skipped, we are done.
|
|
|
|
*/
|
|
|
|
if ((*tptr == '\0')&&(has_comma == PR_FALSE))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Else if the separator is all whitespace, and this is not the
|
|
|
|
* end of the string, add a comma to the separator.
|
|
|
|
*/
|
|
|
|
else if (has_comma == PR_FALSE)
|
|
|
|
{
|
|
|
|
*n_str = ',';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* count the entry skipped.
|
|
|
|
*/
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
n_str = tptr;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* count the last entry in the list.
|
|
|
|
*/
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
*value_cnt = cnt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for the coordinate array.
|
|
|
|
*/
|
|
|
|
value_list = new nscoord[cnt];
|
|
|
|
if (value_list == NULL)
|
|
|
|
{
|
|
|
|
return((PRInt32 *)NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Second pass to copy integer values into list.
|
|
|
|
*/
|
|
|
|
tptr = str;
|
|
|
|
for (i=0; i<cnt; i++)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
ptr = strchr(tptr, ',');
|
|
|
|
if (ptr != NULL)
|
|
|
|
{
|
|
|
|
*ptr = '\0';
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Strip whitespace in front of number because I don't
|
|
|
|
* trust atoi to do it on all platforms.
|
|
|
|
*/
|
|
|
|
while (XP_IS_SPACE(*tptr))
|
|
|
|
{
|
|
|
|
tptr++;
|
|
|
|
}
|
|
|
|
if (*tptr == '\0')
|
|
|
|
{
|
|
|
|
value_list[i] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value_list[i] = (nscoord)XP_ATOI(tptr);
|
|
|
|
}
|
|
|
|
if (ptr != NULL)
|
|
|
|
{
|
|
|
|
*ptr = ',';
|
|
|
|
tptr = (char *)(ptr + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(value_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Area::ParseCoords(const nsString& aSpec)
|
|
|
|
{
|
|
|
|
char* cp = aSpec.ToNewCString();
|
1999-10-28 18:33:34 +04:00
|
|
|
if (cp) {
|
|
|
|
mCoords = lo_parse_coord_list(cp, &mNumCoords);
|
|
|
|
nsCRT::free(cp);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Area::ToHTML(nsString& aResult)
|
|
|
|
{
|
2000-02-11 04:24:59 +03:00
|
|
|
nsAutoString href, target, altText;
|
|
|
|
|
|
|
|
if (mArea) {
|
|
|
|
mArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::href, href);
|
|
|
|
mArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::target, target);
|
|
|
|
mArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::alt, altText);
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
aResult.Truncate();
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("<AREA SHAPE=");
|
1998-04-14 00:24:54 +04:00
|
|
|
nsAutoString shape;
|
|
|
|
GetShapeName(shape);
|
|
|
|
aResult.Append(shape);
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion(" COORDS=\"");
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull != mCoords) {
|
|
|
|
PRInt32 i, n = mNumCoords;
|
|
|
|
for (i = 0; i < n; i++) {
|
2000-04-16 00:15:37 +04:00
|
|
|
aResult.AppendInt(mCoords[i], 10);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (i < n - 1) {
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion(',');
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("\" HREF=\"");
|
2000-02-11 04:24:59 +03:00
|
|
|
aResult.Append(href);
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("\"");
|
2000-02-11 04:24:59 +03:00
|
|
|
if (0 < target.Length()) {
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion(" TARGET=\"");
|
2000-02-11 04:24:59 +03:00
|
|
|
aResult.Append(target);
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("\"");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2000-02-11 04:24:59 +03:00
|
|
|
if (0 < altText.Length()) {
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion(" ALT=\"");
|
2000-02-11 04:24:59 +03:00
|
|
|
aResult.Append(altText);
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("\"");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
if (mSuppressFeedback) {
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion(" SUPPRESS");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion('>');
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
void Area::HasFocus(PRBool aHasFocus)
|
|
|
|
{
|
|
|
|
mHasFocus = aHasFocus;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class DefaultArea : public Area {
|
|
|
|
public:
|
2000-02-11 04:24:59 +03:00
|
|
|
DefaultArea(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL);
|
1998-04-14 00:24:54 +04:00
|
|
|
~DefaultArea();
|
|
|
|
|
|
|
|
virtual PRBool IsInside(nscoord x, nscoord y);
|
1999-11-24 09:03:41 +03:00
|
|
|
virtual void Draw(nsIPresContext* aCX,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIRenderingContext& aRC);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
1998-07-15 02:34:27 +04:00
|
|
|
virtual void GetShapeName(nsString& aResult) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
DefaultArea::DefaultArea(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL)
|
|
|
|
: Area(aArea, aSuppress, aHasURL)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DefaultArea::~DefaultArea()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool DefaultArea::IsInside(nscoord x, nscoord y)
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
void DefaultArea::Draw(nsIPresContext* aCX, nsIRenderingContext& aRC)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
void DefaultArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-07-15 02:34:27 +04:00
|
|
|
void DefaultArea::GetShapeName(nsString& aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("default");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class RectArea : public Area {
|
|
|
|
public:
|
2000-02-11 04:24:59 +03:00
|
|
|
RectArea(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL);
|
1998-04-14 00:24:54 +04:00
|
|
|
~RectArea();
|
|
|
|
|
|
|
|
virtual PRBool IsInside(nscoord x, nscoord y);
|
1999-11-24 09:03:41 +03:00
|
|
|
virtual void Draw(nsIPresContext* aCX,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIRenderingContext& aRC);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
1998-07-15 02:34:27 +04:00
|
|
|
virtual void GetShapeName(nsString& aResult) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
RectArea::RectArea(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL)
|
|
|
|
: Area(aArea, aSuppress, aHasURL)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RectArea::~RectArea()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool RectArea::IsInside(nscoord x, nscoord y)
|
|
|
|
{
|
|
|
|
if (mNumCoords >= 4) { // Note: > is for nav compatabilty
|
|
|
|
nscoord x1 = mCoords[0];
|
|
|
|
nscoord y1 = mCoords[1];
|
|
|
|
nscoord x2 = mCoords[2];
|
|
|
|
nscoord y2 = mCoords[3];
|
|
|
|
if ((x1 > x2)|| (y1 > y2)) {
|
|
|
|
// Can't be inside a screwed up rect
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if ((x >= x1) && (x <= x2) && (y >= y1) && (y <= y2)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
void RectArea::Draw(nsIPresContext* aCX, nsIRenderingContext& aRC)
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
{
|
|
|
|
if (mHasFocus) {
|
|
|
|
if (mNumCoords >= 4) {
|
|
|
|
float p2t;
|
|
|
|
aCX->GetPixelsToTwips(&p2t);
|
|
|
|
nscoord x1 = NSIntPixelsToTwips(mCoords[0], p2t);
|
|
|
|
nscoord y1 = NSIntPixelsToTwips(mCoords[1], p2t);
|
|
|
|
nscoord x2 = NSIntPixelsToTwips(mCoords[2], p2t);
|
|
|
|
nscoord y2 = NSIntPixelsToTwips(mCoords[3], p2t);
|
|
|
|
if ((x1 > x2)|| (y1 > y2)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aRC.DrawLine(x1, y1, x1, y2);
|
|
|
|
aRC.DrawLine(x1, y2, x2, y2);
|
|
|
|
aRC.DrawLine(x1, y1, x2, y1);
|
|
|
|
aRC.DrawLine(x2, y1, x2, y2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RectArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (mNumCoords >= 4) {
|
1999-02-12 20:45:58 +03:00
|
|
|
float p2t;
|
1999-11-24 09:03:41 +03:00
|
|
|
aCX->GetPixelsToTwips(&p2t);
|
1998-08-01 03:34:45 +04:00
|
|
|
nscoord x1 = NSIntPixelsToTwips(mCoords[0], p2t);
|
|
|
|
nscoord y1 = NSIntPixelsToTwips(mCoords[1], p2t);
|
|
|
|
nscoord x2 = NSIntPixelsToTwips(mCoords[2], p2t);
|
|
|
|
nscoord y2 = NSIntPixelsToTwips(mCoords[3], p2t);
|
1998-04-14 00:24:54 +04:00
|
|
|
if ((x1 > x2)|| (y1 > y2)) {
|
|
|
|
return;
|
|
|
|
}
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
|
|
|
nsRect tmp(x1, y1, x2, y2);
|
|
|
|
aRect = tmp;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-15 02:34:27 +04:00
|
|
|
void RectArea::GetShapeName(nsString& aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("rect");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class PolyArea : public Area {
|
|
|
|
public:
|
2000-02-11 04:24:59 +03:00
|
|
|
PolyArea(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL);
|
1998-04-14 00:24:54 +04:00
|
|
|
~PolyArea();
|
|
|
|
|
|
|
|
virtual PRBool IsInside(nscoord x, nscoord y);
|
1999-11-24 09:03:41 +03:00
|
|
|
virtual void Draw(nsIPresContext* aCX,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIRenderingContext& aRC);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
1998-07-15 02:34:27 +04:00
|
|
|
virtual void GetShapeName(nsString& aResult) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
PolyArea::PolyArea(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL)
|
|
|
|
: Area(aArea, aSuppress, aHasURL)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PolyArea::~PolyArea()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool PolyArea::IsInside(nscoord x, nscoord y)
|
|
|
|
{
|
|
|
|
if (mNumCoords >= 6) {
|
|
|
|
PRInt32 intersects = 0;
|
|
|
|
nscoord wherex = x;
|
|
|
|
nscoord wherey = y;
|
|
|
|
PRInt32 totalv = mNumCoords / 2;
|
|
|
|
PRInt32 totalc = totalv * 2;
|
|
|
|
nscoord xval = mCoords[totalc - 2];
|
|
|
|
nscoord yval = mCoords[totalc - 1];
|
|
|
|
PRInt32 end = totalc;
|
|
|
|
PRInt32 pointer = 1;
|
|
|
|
|
|
|
|
if ((yval >= wherey) != (mCoords[pointer] >= wherey))
|
|
|
|
if ((xval >= wherex) == (mCoords[0] >= wherex))
|
|
|
|
intersects += (xval >= wherex) ? 1 : 0;
|
|
|
|
else
|
|
|
|
intersects += ((xval - (yval - wherey) *
|
|
|
|
(mCoords[0] - xval) /
|
|
|
|
(mCoords[pointer] - yval)) >= wherex) ? 1 : 0;
|
|
|
|
|
|
|
|
// XXX I wonder what this is doing; this is a translation of ptinpoly.c
|
|
|
|
while (pointer < end) {
|
|
|
|
yval = mCoords[pointer];
|
|
|
|
pointer += 2;
|
|
|
|
if (yval >= wherey) {
|
|
|
|
while((pointer < end) && (mCoords[pointer] >= wherey))
|
|
|
|
pointer+=2;
|
|
|
|
if (pointer >= end)
|
|
|
|
break;
|
|
|
|
if ((mCoords[pointer-3] >= wherex) ==
|
|
|
|
(mCoords[pointer-1] >= wherex)) {
|
|
|
|
intersects += (mCoords[pointer-3] >= wherex) ? 1 : 0;
|
|
|
|
} else {
|
|
|
|
intersects +=
|
|
|
|
((mCoords[pointer-3] - (mCoords[pointer-2] - wherey) *
|
|
|
|
(mCoords[pointer-1] - mCoords[pointer-3]) /
|
|
|
|
(mCoords[pointer] - mCoords[pointer - 2])) >= wherex) ? 1:0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while((pointer < end) && (mCoords[pointer] < wherey))
|
|
|
|
pointer+=2;
|
|
|
|
if (pointer >= end)
|
|
|
|
break;
|
|
|
|
if ((mCoords[pointer-3] >= wherex) ==
|
|
|
|
(mCoords[pointer-1] >= wherex)) {
|
|
|
|
intersects += (mCoords[pointer-3] >= wherex) ? 1:0;
|
|
|
|
} else {
|
|
|
|
intersects +=
|
|
|
|
((mCoords[pointer-3] - (mCoords[pointer-2] - wherey) *
|
|
|
|
(mCoords[pointer-1] - mCoords[pointer-3]) /
|
|
|
|
(mCoords[pointer] - mCoords[pointer - 2])) >= wherex) ? 1:0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((intersects & 1) != 0) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
void PolyArea::Draw(nsIPresContext* aCX, nsIRenderingContext& aRC)
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
{
|
|
|
|
if (mHasFocus) {
|
|
|
|
if (mNumCoords >= 6) {
|
|
|
|
float p2t;
|
|
|
|
aCX->GetPixelsToTwips(&p2t);
|
|
|
|
nscoord x0 = NSIntPixelsToTwips(mCoords[0], p2t);
|
|
|
|
nscoord y0 = NSIntPixelsToTwips(mCoords[1], p2t);
|
|
|
|
nscoord x1, y1;
|
|
|
|
for (PRInt32 i = 2; i < mNumCoords; i += 2) {
|
|
|
|
x1 = NSIntPixelsToTwips(mCoords[i], p2t);
|
|
|
|
y1 = NSIntPixelsToTwips(mCoords[i+1], p2t);
|
|
|
|
aRC.DrawLine(x0, y0, x1, y1);
|
|
|
|
x0 = x1;
|
|
|
|
y0 = y1;
|
|
|
|
}
|
|
|
|
x1 = NSIntPixelsToTwips(mCoords[0], p2t);
|
|
|
|
y1 = NSIntPixelsToTwips(mCoords[1], p2t);
|
|
|
|
aRC.DrawLine(x0, y0, x1, y1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PolyArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (mNumCoords >= 6) {
|
1999-02-12 20:45:58 +03:00
|
|
|
float p2t;
|
1999-11-24 09:03:41 +03:00
|
|
|
aCX->GetPixelsToTwips(&p2t);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
nscoord x1, x2, y1, y2, xtmp, ytmp;
|
|
|
|
x1 = x2 = NSIntPixelsToTwips(mCoords[0], p2t);
|
|
|
|
y1 = y2 = NSIntPixelsToTwips(mCoords[1], p2t);
|
1998-04-14 00:24:54 +04:00
|
|
|
for (PRInt32 i = 2; i < mNumCoords; i += 2) {
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
xtmp = NSIntPixelsToTwips(mCoords[i], p2t);
|
|
|
|
ytmp = NSIntPixelsToTwips(mCoords[i+1], p2t);
|
|
|
|
x1 = x1 < xtmp ? x1 : xtmp;
|
|
|
|
y1 = y1 < ytmp ? y1 : ytmp;
|
|
|
|
x2 = x2 > xtmp ? x2 : xtmp;
|
|
|
|
y2 = y2 > ytmp ? y2 : ytmp;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
|
|
|
nsRect tmp(x1, y1, x2, y2);
|
|
|
|
aRect = tmp;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-15 02:34:27 +04:00
|
|
|
void PolyArea::GetShapeName(nsString& aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("polygon");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class CircleArea : public Area {
|
|
|
|
public:
|
2000-02-11 04:24:59 +03:00
|
|
|
CircleArea(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL);
|
1998-04-14 00:24:54 +04:00
|
|
|
~CircleArea();
|
|
|
|
|
|
|
|
virtual PRBool IsInside(nscoord x, nscoord y);
|
1999-11-24 09:03:41 +03:00
|
|
|
virtual void Draw(nsIPresContext* aCX,
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIRenderingContext& aRC);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
virtual void GetRect(nsIPresContext* aCX, nsRect& aRect);
|
1998-07-15 02:34:27 +04:00
|
|
|
virtual void GetShapeName(nsString& aResult) const;
|
1998-04-14 00:24:54 +04:00
|
|
|
};
|
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
CircleArea::CircleArea(nsIContent* aArea, PRBool aSuppress, PRBool aHasURL)
|
|
|
|
: Area(aArea, aSuppress, aHasURL)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CircleArea::~CircleArea()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool CircleArea::IsInside(nscoord x, nscoord y)
|
|
|
|
{
|
|
|
|
// Note: > is for nav compatabilty
|
|
|
|
if (mNumCoords >= 3) {
|
|
|
|
nscoord x1 = mCoords[0];
|
|
|
|
nscoord y1 = mCoords[1];
|
|
|
|
nscoord radius = mCoords[2];
|
|
|
|
if (radius < 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nscoord dx = x1 - x;
|
|
|
|
nscoord dy = y1 - y;
|
|
|
|
nscoord dist = (dx * dx) + (dy * dy);
|
|
|
|
if (dist <= (radius * radius)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
void CircleArea::Draw(nsIPresContext* aCX, nsIRenderingContext& aRC)
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
{
|
|
|
|
if (mHasFocus) {
|
|
|
|
if (mNumCoords >= 3) {
|
|
|
|
float p2t;
|
|
|
|
aCX->GetPixelsToTwips(&p2t);
|
|
|
|
nscoord x1 = NSIntPixelsToTwips(mCoords[0], p2t);
|
|
|
|
nscoord y1 = NSIntPixelsToTwips(mCoords[1], p2t);
|
|
|
|
nscoord radius = NSIntPixelsToTwips(mCoords[2], p2t);
|
|
|
|
if (radius < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nscoord x = x1 - radius;
|
|
|
|
nscoord y = y1 - radius;
|
|
|
|
nscoord w = 2 * radius;
|
|
|
|
aRC.DrawEllipse(x, y, w, w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CircleArea::GetRect(nsIPresContext* aCX, nsRect& aRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
if (mNumCoords >= 3) {
|
1999-02-12 20:45:58 +03:00
|
|
|
float p2t;
|
1999-11-24 09:03:41 +03:00
|
|
|
aCX->GetPixelsToTwips(&p2t);
|
1998-08-01 03:34:45 +04:00
|
|
|
nscoord x1 = NSIntPixelsToTwips(mCoords[0], p2t);
|
|
|
|
nscoord y1 = NSIntPixelsToTwips(mCoords[1], p2t);
|
|
|
|
nscoord radius = NSIntPixelsToTwips(mCoords[2], p2t);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (radius < 0) {
|
|
|
|
return;
|
|
|
|
}
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
|
|
|
nsRect tmp(x1 - radius, y1 - radius, x1 + radius, y1 + radius);
|
|
|
|
aRect = tmp;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-15 02:34:27 +04:00
|
|
|
void CircleArea::GetShapeName(nsString& aResult) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-03 15:39:09 +04:00
|
|
|
aResult.AppendWithConversion("circle");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
nsImageMap::nsImageMap()
|
|
|
|
{
|
1999-10-08 05:49:06 +04:00
|
|
|
NS_INIT_REFCNT();
|
1999-01-09 03:13:53 +03:00
|
|
|
mMap = nsnull;
|
|
|
|
mDomMap = nsnull;
|
|
|
|
mDocument = nsnull;
|
1999-03-01 19:57:35 +03:00
|
|
|
mContainsBlockContents = PR_FALSE;
|
1999-01-09 03:13:53 +03:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
nsImageMap::~nsImageMap()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
//Remove all our focus listeners
|
|
|
|
PRInt32 i, n = mAreas.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
Area* area = (Area*) mAreas.ElementAt(i);
|
|
|
|
nsCOMPtr<nsIContent> areaContent;
|
|
|
|
area->GetArea(getter_AddRefs(areaContent));
|
|
|
|
if (areaContent) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(areaContent));
|
|
|
|
if (rec) {
|
|
|
|
rec->RemoveEventListenerByIID(this, NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
FreeAreas();
|
|
|
|
if (nsnull != mDocument) {
|
|
|
|
mDocument->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(mMap);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
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 {
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-09 03:13:53 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsImageMap::FreeAreas()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-08-18 10:27:42 +04:00
|
|
|
nsCOMPtr<nsIFrameManager> frameManager;
|
|
|
|
mPresShell->GetFrameManager(getter_AddRefs(frameManager));
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 i, n = mAreas.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
Area* area = (Area*) mAreas.ElementAt(i);
|
2000-08-18 10:27:42 +04:00
|
|
|
frameManager->SetPrimaryFrameFor(area->mArea, nsnull);
|
1998-04-14 00:24:54 +04:00
|
|
|
delete area;
|
|
|
|
}
|
1999-01-09 03:13:53 +03:00
|
|
|
mAreas.Clear();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
nsresult
|
2000-08-18 10:27:42 +04:00
|
|
|
nsImageMap::Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapElement* aMap)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-01-09 03:13:53 +03:00
|
|
|
NS_PRECONDITION(nsnull != aMap, "null ptr");
|
|
|
|
if (nsnull == aMap) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2000-08-18 10:27:42 +04:00
|
|
|
mPresShell = aPresShell;
|
|
|
|
mImageFrame = aImageFrame;
|
1999-01-09 03:13:53 +03:00
|
|
|
mDomMap = aMap;
|
|
|
|
|
2001-01-04 23:44:42 +03:00
|
|
|
nsresult rv = aMap->QueryInterface(NS_GET_IID(nsIContent), (void**) &mMap);
|
1999-01-09 03:13:53 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = mMap->GetDocument(mDocument);
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != mDocument)) {
|
|
|
|
mDocument->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this));
|
2000-08-11 06:11:53 +04:00
|
|
|
// mDocument is a weak reference, so release the reference we got
|
|
|
|
nsIDocument *temp = mDocument;
|
|
|
|
NS_RELEASE(temp);
|
1999-01-09 03:13:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Compile" the areas in the map into faster access versions
|
|
|
|
rv = UpdateAreas();
|
|
|
|
return rv;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-03-01 19:57:35 +03:00
|
|
|
|
|
|
|
nsresult
|
2001-04-01 04:45:59 +04:00
|
|
|
nsImageMap::UpdateAreasForBlock(nsIContent* aParent, PRBool* aFoundAnchor)
|
1999-03-01 19:57:35 +03:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsIDOMHTMLAnchorElement* area;
|
2001-01-04 23:44:42 +03:00
|
|
|
rv = child->QueryInterface(NS_GET_IID(nsIDOMHTMLAnchorElement), (void**) &area);
|
1999-03-01 19:57:35 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2001-04-01 04:45:59 +04:00
|
|
|
*aFoundAnchor = PR_TRUE;
|
1999-03-01 19:57:35 +03:00
|
|
|
rv = AddArea(child);
|
|
|
|
NS_RELEASE(area);
|
|
|
|
}
|
|
|
|
else {
|
2001-04-01 04:45:59 +04:00
|
|
|
rv = UpdateAreasForBlock(child, aFoundAnchor);
|
1999-03-01 19:57:35 +03:00
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
nsresult
|
|
|
|
nsImageMap::UpdateAreas()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-01-09 03:13:53 +03:00
|
|
|
// Get rid of old area data
|
|
|
|
FreeAreas();
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsresult rv = NS_OK;
|
1999-03-01 19:57:35 +03:00
|
|
|
PRInt32 i, n;
|
|
|
|
PRBool containsBlock = PR_FALSE, containsArea = PR_FALSE;
|
|
|
|
|
|
|
|
mMap->ChildCount(n);
|
2001-04-01 04:45:59 +04:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
mMap->ChildAt(i, *getter_AddRefs(child));
|
|
|
|
|
|
|
|
// Only look at elements and not text, comments, etc.
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryInterface(child);
|
|
|
|
if (! element)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// First check if this map element contains an AREA element.
|
|
|
|
// If so, we only look for AREA elements
|
|
|
|
if (!containsBlock) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLAreaElement> area = do_QueryInterface(child);
|
|
|
|
if (area) {
|
|
|
|
containsArea = PR_TRUE;
|
|
|
|
AddArea(child);
|
1999-03-01 19:57:35 +03:00
|
|
|
}
|
2001-04-01 04:45:59 +04:00
|
|
|
}
|
1999-03-01 19:57:35 +03:00
|
|
|
|
2001-04-01 04:45:59 +04:00
|
|
|
// If we haven't determined that the map element contains an
|
|
|
|
// AREA element yet, the look for a block element with children
|
|
|
|
// that are anchors.
|
|
|
|
if (!containsArea) {
|
|
|
|
UpdateAreasForBlock(child, &containsBlock);
|
|
|
|
|
|
|
|
if (containsBlock)
|
|
|
|
mContainsBlockContents = PR_TRUE;
|
1999-01-09 03:13:53 +03:00
|
|
|
}
|
|
|
|
}
|
1999-03-01 19:57:35 +03:00
|
|
|
|
2001-04-01 04:45:59 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
nsresult
|
1999-03-01 19:57:35 +03:00
|
|
|
nsImageMap::AddArea(nsIContent* aArea)
|
|
|
|
{
|
2000-02-11 04:24:59 +03:00
|
|
|
nsAutoString shape, coords, baseURL, noHref;
|
|
|
|
aArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::shape, shape);
|
|
|
|
aArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::coords, coords);
|
|
|
|
PRBool hasURL = (PRBool)(NS_CONTENT_ATTR_HAS_VALUE != aArea->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::nohref, noHref));
|
1999-01-09 03:13:53 +03:00
|
|
|
PRBool suppress = PR_FALSE;/* XXX */
|
|
|
|
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
//Add focus listener to track area focus changes
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(aArea));
|
|
|
|
if (rec) {
|
|
|
|
rec->AddEventListenerByIID(this, NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
}
|
|
|
|
|
2000-08-18 10:27:42 +04:00
|
|
|
nsCOMPtr<nsIFrameManager> frameManager;
|
|
|
|
mPresShell->GetFrameManager(getter_AddRefs(frameManager));
|
|
|
|
frameManager->SetPrimaryFrameFor(aArea, mImageFrame);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
Area* area;
|
1999-09-02 00:58:17 +04:00
|
|
|
if ((0 == shape.Length()) ||
|
|
|
|
shape.EqualsIgnoreCase("rect") ||
|
|
|
|
shape.EqualsIgnoreCase("rectangle")) {
|
2000-02-11 04:24:59 +03:00
|
|
|
area = new RectArea(aArea, suppress, hasURL);
|
1999-09-02 00:58:17 +04:00
|
|
|
}
|
|
|
|
else if (shape.EqualsIgnoreCase("poly") ||
|
|
|
|
shape.EqualsIgnoreCase("polygon")) {
|
2000-02-11 04:24:59 +03:00
|
|
|
area = new PolyArea(aArea, suppress, hasURL);
|
1999-09-02 00:58:17 +04:00
|
|
|
}
|
|
|
|
else if (shape.EqualsIgnoreCase("circle") ||
|
|
|
|
shape.EqualsIgnoreCase("circ")) {
|
2000-02-11 04:24:59 +03:00
|
|
|
area = new CircleArea(aArea, suppress, hasURL);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
else {
|
2000-02-11 04:24:59 +03:00
|
|
|
area = new DefaultArea(aArea, suppress, hasURL);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-01-09 03:13:53 +03:00
|
|
|
area->ParseCoords(coords);
|
1998-04-14 00:24:54 +04:00
|
|
|
mAreas.AppendElement(area);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
PRBool
|
|
|
|
nsImageMap::IsInside(nscoord aX, nscoord aY,
|
2000-02-11 04:24:59 +03:00
|
|
|
nsIContent** aContent,
|
1999-01-09 03:13:53 +03:00
|
|
|
nsString& aAbsURL,
|
|
|
|
nsString& aTarget,
|
|
|
|
nsString& aAltText,
|
|
|
|
PRBool* aSuppress)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 i, n = mAreas.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
Area* area = (Area*) mAreas.ElementAt(i);
|
2000-02-11 04:24:59 +03:00
|
|
|
if (area->IsInside(aX, aY)) {
|
|
|
|
if (area->GetHasURL()) {
|
|
|
|
// Set the image loader's source URL and base URL
|
|
|
|
nsIURI* baseUri = nsnull;
|
|
|
|
if (mMap) {
|
2000-11-28 02:23:28 +03:00
|
|
|
nsIHTMLContent* htmlContent;
|
|
|
|
if (NS_SUCCEEDED( mMap->QueryInterface(kIHTMLContentIID, (void**)&htmlContent) )) {
|
2000-02-11 04:24:59 +03:00
|
|
|
htmlContent->GetBaseURL(baseUri);
|
|
|
|
NS_RELEASE(htmlContent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIDocument* doc;
|
2000-11-28 02:23:28 +03:00
|
|
|
if (NS_SUCCEEDED( mMap->GetDocument(doc) ) && doc) {
|
2000-02-11 04:24:59 +03:00
|
|
|
doc->GetBaseURL(baseUri); // Could just use mDocument here...
|
|
|
|
NS_RELEASE(doc);
|
|
|
|
}
|
1999-10-13 05:37:30 +04:00
|
|
|
}
|
1999-07-11 19:46:10 +04:00
|
|
|
}
|
2000-11-28 02:23:28 +03:00
|
|
|
if (!baseUri) return PR_FALSE;
|
2000-02-11 04:24:59 +03:00
|
|
|
|
|
|
|
nsAutoString href;
|
|
|
|
area->GetHREF(href);
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_MakeAbsoluteURI(aAbsURL, href, baseUri);
|
1999-06-18 21:34:08 +04:00
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
NS_RELEASE(baseUri);
|
|
|
|
}
|
1999-07-11 19:46:10 +04:00
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
area->GetTarget(aTarget);
|
1999-07-22 22:47:23 +04:00
|
|
|
if (mMap && (aTarget.Length() == 0)) {
|
|
|
|
nsIHTMLContent* content = nsnull;
|
|
|
|
nsresult result = mMap->QueryInterface(kIHTMLContentIID, (void**)&content);
|
|
|
|
if ((NS_OK == result) && content) {
|
|
|
|
content->GetBaseTarget(aTarget);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
}
|
2000-02-11 04:24:59 +03:00
|
|
|
area->GetAltText(aAltText);
|
1998-04-14 00:24:54 +04:00
|
|
|
*aSuppress = area->mSuppressFeedback;
|
2000-02-11 04:24:59 +03:00
|
|
|
area->GetArea(aContent);
|
1999-01-09 03:13:53 +03:00
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-01-09 03:13:53 +03:00
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
PRBool
|
|
|
|
nsImageMap::IsInside(nscoord aX, nscoord aY)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 i, n = mAreas.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
Area* area = (Area*) mAreas.ElementAt(i);
|
|
|
|
if (area->IsInside(aX, aY)) {
|
2000-02-11 04:24:59 +03:00
|
|
|
nsAutoString href;
|
|
|
|
area->GetHREF(href);
|
|
|
|
if (href.Length() > 0) {
|
1999-01-09 03:13:53 +03:00
|
|
|
return PR_TRUE;
|
1998-11-21 03:19:36 +03:00
|
|
|
}
|
2000-04-24 08:41:27 +04:00
|
|
|
else {
|
|
|
|
//We need to return here so we don't hit an overlapping map area
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-01-09 03:13:53 +03:00
|
|
|
return PR_FALSE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
void
|
1999-11-24 09:03:41 +03:00
|
|
|
nsImageMap::Draw(nsIPresContext* aCX, nsIRenderingContext& aRC)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
PRInt32 i, n = mAreas.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
Area* area = (Area*) mAreas.ElementAt(i);
|
|
|
|
area->Draw(aCX, aRC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::BeginUpdate(nsIDocument *aDocument)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-01-09 03:13:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::EndUpdate(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::BeginLoad(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::EndLoad(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::EndReflow(nsIDocument *aDocument, nsIPresShell* aShell)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-01 19:57:35 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::ContentChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
|
|
|
// 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)) {
|
1999-03-01 19:57:35 +03:00
|
|
|
if ((parent == mMap) ||
|
|
|
|
(mContainsBlockContents && IsAncestorOf(parent, mMap))) {
|
1999-01-09 03:13:53 +03:00
|
|
|
UpdateAreas();
|
|
|
|
}
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-27 10:15:09 +03:00
|
|
|
NS_IMETHODIMP
|
1999-04-20 04:06:58 +04:00
|
|
|
nsImageMap::ContentStatesChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2)
|
1999-02-27 10:15:09 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-09 03:13:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::AttributeChanged(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContent,
|
1999-10-16 03:16:45 +04:00
|
|
|
PRInt32 aNameSpaceID,
|
1999-01-09 03:13:53 +03:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
// 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)) {
|
1999-03-01 19:57:35 +03:00
|
|
|
if ((parent == mMap) ||
|
|
|
|
(mContainsBlockContents && IsAncestorOf(parent, mMap))) {
|
1999-01-09 03:13:53 +03:00
|
|
|
UpdateAreas();
|
|
|
|
}
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::ContentAppended(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
PRInt32 aNewIndexInContainer)
|
|
|
|
{
|
1999-03-01 19:57:35 +03:00
|
|
|
if ((mMap == aContainer) ||
|
|
|
|
(mContainsBlockContents && IsAncestorOf(aContainer, mMap))) {
|
1999-01-09 03:13:53 +03:00
|
|
|
UpdateAreas();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::ContentInserted(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
1999-03-01 19:57:35 +03:00
|
|
|
if ((mMap == aContainer) ||
|
|
|
|
(mContainsBlockContents && IsAncestorOf(aContainer, mMap))) {
|
1999-01-09 03:13:53 +03:00
|
|
|
UpdateAreas();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::ContentReplaced(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
1999-03-01 19:57:35 +03:00
|
|
|
if ((mMap == aContainer) ||
|
|
|
|
(mContainsBlockContents && IsAncestorOf(aContainer, mMap))) {
|
1999-01-09 03:13:53 +03:00
|
|
|
UpdateAreas();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-01-09 03:13:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::ContentRemoved(nsIDocument *aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInContainer)
|
|
|
|
{
|
1999-03-01 19:57:35 +03:00
|
|
|
if ((mMap == aContainer) ||
|
|
|
|
(mContainsBlockContents && IsAncestorOf(aContainer, mMap))) {
|
1999-01-09 03:13:53 +03:00
|
|
|
UpdateAreas();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-01-09 03:13:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::StyleSheetAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet)
|
1999-02-03 22:38:16 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::StyleSheetRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet)
|
1999-01-09 03:13:53 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
PRBool aDisabled)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::StyleRuleChanged(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::StyleRuleAdded(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::StyleRuleRemoved(nsIDocument *aDocument,
|
|
|
|
nsIStyleSheet* aStyleSheet,
|
|
|
|
nsIStyleRule* aStyleRule)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageMap::DocumentWillBeDestroyed(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
nsresult
|
|
|
|
nsImageMap::Focus(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
return ChangeFocus(aEvent, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageMap::Blur(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
return ChangeFocus(aEvent, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageMap::ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus) {
|
|
|
|
//Set which one of our areas changed focus
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target;
|
|
|
|
if (NS_SUCCEEDED(aEvent->GetTarget(getter_AddRefs(target))) && target) {
|
|
|
|
nsCOMPtr<nsIContent> targetContent(do_QueryInterface(target));
|
|
|
|
if (targetContent) {
|
|
|
|
PRInt32 i, n = mAreas.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
Area* area = (Area*) mAreas.ElementAt(i);
|
|
|
|
nsCOMPtr<nsIContent> areaContent;
|
|
|
|
area->GetArea(getter_AddRefs(areaContent));
|
|
|
|
if (areaContent) {
|
|
|
|
if (areaContent.get() == targetContent.get()) {
|
|
|
|
//Set or Remove internal focus
|
|
|
|
area->HasFocus(aFocus);
|
|
|
|
//Now invalidate the rect
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
//This check is necessary to see if we're still attached to the doc
|
|
|
|
if (NS_SUCCEEDED(targetContent->GetDocument(*getter_AddRefs(doc))) && doc) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = getter_AddRefs(doc->GetShellAt(0));
|
|
|
|
if (presShell) {
|
|
|
|
nsIFrame* imgFrame;
|
|
|
|
if (NS_SUCCEEDED(presShell->GetPrimaryFrameFor(targetContent, &imgFrame)) && imgFrame) {
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
if (NS_SUCCEEDED(presShell->GetPresContext(getter_AddRefs(presContext))) && presContext) {
|
|
|
|
nsRect dmgRect;
|
|
|
|
area->GetRect(presContext, dmgRect);
|
|
|
|
Invalidate(presContext, imgFrame, dmgRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageMap::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageMap::Invalidate(nsIPresContext* aPresContext, nsIFrame* aFrame, nsRect& aRect)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
PRUint32 flags = NS_VMREFRESH_IMMEDIATE;
|
|
|
|
nsIView* view;
|
|
|
|
nsRect damageRect(aRect);
|
|
|
|
|
|
|
|
aFrame->GetView(aPresContext, &view);
|
|
|
|
if (view) {
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
viewManager->UpdateView(view, damageRect, flags);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsPoint offset;
|
|
|
|
|
|
|
|
aFrame->GetOffsetFromView(aPresContext, offset, &view);
|
|
|
|
NS_ASSERTION(nsnull != view, "no view");
|
|
|
|
damageRect += offset;
|
|
|
|
view->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
viewManager->UpdateView(view, damageRect, flags);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-08-12 04:38:22 +04:00
|
|
|
void
|
|
|
|
nsImageMap::Destroy(void)
|
|
|
|
{
|
|
|
|
//Remove all our focus listeners
|
|
|
|
PRInt32 i, n = mAreas.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
Area* area = (Area*) mAreas.ElementAt(i);
|
|
|
|
nsCOMPtr<nsIContent> areaContent;
|
|
|
|
area->GetArea(getter_AddRefs(areaContent));
|
|
|
|
if (areaContent) {
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(areaContent));
|
|
|
|
if (rec) {
|
|
|
|
rec->RemoveEventListenerByIID(this, NS_GET_IID(nsIDOMFocusListener));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
#ifdef DEBUG
|
1999-08-31 07:09:40 +04:00
|
|
|
void
|
|
|
|
nsImageMap::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
|
|
|
if (aResult) {
|
|
|
|
PRUint32 sum = sizeof(*this);
|
|
|
|
PRInt32 i, n = mAreas.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
Area* area = (Area*) mAreas.ElementAt(i);
|
|
|
|
PRUint32 areaSize;
|
|
|
|
area->SizeOf(aHandler, &areaSize);
|
|
|
|
sum += areaSize;
|
|
|
|
}
|
|
|
|
*aResult = sum;
|
|
|
|
}
|
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|