mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 49122. Make the image map manage addition and removal of the <area>'s to the primary-frame-for map in the frame manager. r=saari
This commit is contained in:
parent
ee77cd74b8
commit
baab3d1f7f
@ -184,46 +184,6 @@ if (NS_CONTENT_ATTR_HAS_VALUE == lowSrcResult && lowSrc.Length() > 0) {
|
||||
mImageLoader.Init(this, UpdateImageFrame, (void*)&mImageLoader, baseURL, src);
|
||||
NS_IF_RELEASE(baseURL);
|
||||
|
||||
nsAutoString usemap;
|
||||
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::usemap, usemap);
|
||||
if (usemap.Length()) {
|
||||
//Image is an imagemap. We need to get its maps and set the primary
|
||||
//frame for its children to us.
|
||||
usemap.StripWhitespace();
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
if (NS_SUCCEEDED(mContent->GetDocument(*getter_AddRefs(doc))) && doc) {
|
||||
if (usemap.First() == '#') {
|
||||
usemap.Cut(0, 1);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIHTMLDocument> hdoc(do_QueryInterface(doc));
|
||||
if (hdoc) {
|
||||
nsCOMPtr<nsIDOMHTMLMapElement> hmap;
|
||||
if (NS_SUCCEEDED(hdoc->GetImageMap(usemap, getter_AddRefs(hmap))) && hmap) {
|
||||
nsCOMPtr<nsIContent> map(do_QueryInterface(hmap));
|
||||
if (map) {
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
if (NS_SUCCEEDED(aPresContext->GetShell(getter_AddRefs(presShell))) &&
|
||||
presShell) {
|
||||
nsCOMPtr<nsIFrameManager> frameManager;
|
||||
if (NS_SUCCEEDED(presShell->GetFrameManager(getter_AddRefs(frameManager))) &&
|
||||
frameManager) {
|
||||
nsCOMPtr<nsIContent> childArea;
|
||||
PRInt32 count, index;
|
||||
map->ChildCount(count);
|
||||
for (index = 0; index < count; index++) {
|
||||
map->ChildAt(index, *getter_AddRefs(childArea));
|
||||
frameManager->SetPrimaryFrameFor(childArea, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mInitialLoadCompleted = PR_FALSE;
|
||||
return rv;
|
||||
}
|
||||
@ -670,7 +630,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext,
|
||||
|
||||
}
|
||||
|
||||
nsImageMap* map = GetImageMap();
|
||||
nsImageMap* map = GetImageMap(aPresContext);
|
||||
if (nsnull != map) {
|
||||
nsRect inner;
|
||||
GetInnerArea(aPresContext, inner);
|
||||
@ -686,7 +646,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext,
|
||||
#ifdef DEBUG
|
||||
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) &&
|
||||
GetShowFrameBorders()) {
|
||||
nsImageMap* map = GetImageMap();
|
||||
nsImageMap* map = GetImageMap(aPresContext);
|
||||
if (nsnull != map) {
|
||||
nsRect inner;
|
||||
GetInnerArea(aPresContext, inner);
|
||||
@ -709,7 +669,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext,
|
||||
}
|
||||
|
||||
nsImageMap*
|
||||
nsImageFrame::GetImageMap()
|
||||
nsImageFrame::GetImageMap(nsIPresContext* aPresContext)
|
||||
{
|
||||
if (nsnull == mImageMap) {
|
||||
nsAutoString usemap;
|
||||
@ -739,10 +699,13 @@ nsImageFrame::GetImageMap()
|
||||
rv = hdoc->GetImageMap(usemap, &map);
|
||||
NS_RELEASE(hdoc);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||
|
||||
mImageMap = new nsImageMap();
|
||||
if (nsnull != mImageMap) {
|
||||
NS_ADDREF(mImageMap);
|
||||
mImageMap->Init(map);
|
||||
mImageMap->Init(presShell, this, map);
|
||||
}
|
||||
NS_IF_RELEASE(map);
|
||||
}
|
||||
@ -896,7 +859,7 @@ nsImageFrame::GetContentForEvent(nsIPresContext* aPresContext,
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aContent);
|
||||
nsImageMap* map;
|
||||
map = GetImageMap();
|
||||
map = GetImageMap(aPresContext);
|
||||
|
||||
if (nsnull != map) {
|
||||
nsPoint p;
|
||||
@ -931,7 +894,7 @@ nsImageFrame::HandleEvent(nsIPresContext* aPresContext,
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
case NS_MOUSE_MOVE:
|
||||
{
|
||||
map = GetImageMap();
|
||||
map = GetImageMap(aPresContext);
|
||||
PRBool isServerMap = IsServerImageMap();
|
||||
if ((nsnull != map) || isServerMap) {
|
||||
nsPoint p;
|
||||
@ -1008,7 +971,7 @@ nsImageFrame::GetCursor(nsIPresContext* aPresContext,
|
||||
nsPoint& aPoint,
|
||||
PRInt32& aCursor)
|
||||
{
|
||||
nsImageMap* map = GetImageMap();
|
||||
nsImageMap* map = GetImageMap(aPresContext);
|
||||
if (nsnull != map) {
|
||||
nsPoint p;
|
||||
TranslateEventCoords(aPresContext, aPoint, p);
|
||||
|
@ -86,7 +86,7 @@ protected:
|
||||
|
||||
nsresult UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus, void* aClosure);
|
||||
|
||||
nsImageMap* GetImageMap();
|
||||
nsImageMap* GetImageMap(nsIPresContext* aPresContext);
|
||||
|
||||
void TriggerLink(nsIPresContext* aPresContext,
|
||||
const nsString& aURLSpec,
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIFrameManager.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsCoord.h"
|
||||
|
||||
@ -859,21 +860,27 @@ nsImageMap::QueryInterface(REFNSIID iid, void** result)
|
||||
void
|
||||
nsImageMap::FreeAreas()
|
||||
{
|
||||
nsCOMPtr<nsIFrameManager> frameManager;
|
||||
mPresShell->GetFrameManager(getter_AddRefs(frameManager));
|
||||
|
||||
PRInt32 i, n = mAreas.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
Area* area = (Area*) mAreas.ElementAt(i);
|
||||
frameManager->SetPrimaryFrameFor(area->mArea, nsnull);
|
||||
delete area;
|
||||
}
|
||||
mAreas.Clear();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsImageMap::Init(nsIDOMHTMLMapElement* aMap)
|
||||
nsImageMap::Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapElement* aMap)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aMap, "null ptr");
|
||||
if (nsnull == aMap) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
mPresShell = aPresShell;
|
||||
mImageFrame = aImageFrame;
|
||||
mDomMap = aMap;
|
||||
|
||||
nsresult rv = aMap->QueryInterface(kIContentIID, (void**) &mMap);
|
||||
@ -989,6 +996,10 @@ nsImageMap::AddArea(nsIContent* aArea)
|
||||
rec->AddEventListenerByIID(this, NS_GET_IID(nsIDOMFocusListener));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFrameManager> frameManager;
|
||||
mPresShell->GetFrameManager(getter_AddRefs(frameManager));
|
||||
frameManager->SetPrimaryFrameFor(aArea, mImageFrame);
|
||||
|
||||
Area* area;
|
||||
if ((0 == shape.Length()) ||
|
||||
shape.EqualsIgnoreCase("rect") ||
|
||||
|
@ -44,7 +44,7 @@ class nsImageMap : public nsIDocumentObserver, public nsIDOMFocusListener
|
||||
public:
|
||||
nsImageMap();
|
||||
|
||||
nsresult Init(nsIDOMHTMLMapElement* aMap);
|
||||
nsresult Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapElement* aMap);
|
||||
|
||||
/**
|
||||
* See if the given aX,aY <b>pixel</b> coordinates are in the image
|
||||
@ -156,6 +156,8 @@ protected:
|
||||
nsresult ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus);
|
||||
nsresult Invalidate(nsIPresContext* aPresContext, nsIFrame* aFrame, nsRect& aRect);
|
||||
|
||||
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;
|
||||
|
@ -184,46 +184,6 @@ if (NS_CONTENT_ATTR_HAS_VALUE == lowSrcResult && lowSrc.Length() > 0) {
|
||||
mImageLoader.Init(this, UpdateImageFrame, (void*)&mImageLoader, baseURL, src);
|
||||
NS_IF_RELEASE(baseURL);
|
||||
|
||||
nsAutoString usemap;
|
||||
mContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::usemap, usemap);
|
||||
if (usemap.Length()) {
|
||||
//Image is an imagemap. We need to get its maps and set the primary
|
||||
//frame for its children to us.
|
||||
usemap.StripWhitespace();
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
if (NS_SUCCEEDED(mContent->GetDocument(*getter_AddRefs(doc))) && doc) {
|
||||
if (usemap.First() == '#') {
|
||||
usemap.Cut(0, 1);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIHTMLDocument> hdoc(do_QueryInterface(doc));
|
||||
if (hdoc) {
|
||||
nsCOMPtr<nsIDOMHTMLMapElement> hmap;
|
||||
if (NS_SUCCEEDED(hdoc->GetImageMap(usemap, getter_AddRefs(hmap))) && hmap) {
|
||||
nsCOMPtr<nsIContent> map(do_QueryInterface(hmap));
|
||||
if (map) {
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
if (NS_SUCCEEDED(aPresContext->GetShell(getter_AddRefs(presShell))) &&
|
||||
presShell) {
|
||||
nsCOMPtr<nsIFrameManager> frameManager;
|
||||
if (NS_SUCCEEDED(presShell->GetFrameManager(getter_AddRefs(frameManager))) &&
|
||||
frameManager) {
|
||||
nsCOMPtr<nsIContent> childArea;
|
||||
PRInt32 count, index;
|
||||
map->ChildCount(count);
|
||||
for (index = 0; index < count; index++) {
|
||||
map->ChildAt(index, *getter_AddRefs(childArea));
|
||||
frameManager->SetPrimaryFrameFor(childArea, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mInitialLoadCompleted = PR_FALSE;
|
||||
return rv;
|
||||
}
|
||||
@ -670,7 +630,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext,
|
||||
|
||||
}
|
||||
|
||||
nsImageMap* map = GetImageMap();
|
||||
nsImageMap* map = GetImageMap(aPresContext);
|
||||
if (nsnull != map) {
|
||||
nsRect inner;
|
||||
GetInnerArea(aPresContext, inner);
|
||||
@ -686,7 +646,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext,
|
||||
#ifdef DEBUG
|
||||
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) &&
|
||||
GetShowFrameBorders()) {
|
||||
nsImageMap* map = GetImageMap();
|
||||
nsImageMap* map = GetImageMap(aPresContext);
|
||||
if (nsnull != map) {
|
||||
nsRect inner;
|
||||
GetInnerArea(aPresContext, inner);
|
||||
@ -709,7 +669,7 @@ nsImageFrame::Paint(nsIPresContext* aPresContext,
|
||||
}
|
||||
|
||||
nsImageMap*
|
||||
nsImageFrame::GetImageMap()
|
||||
nsImageFrame::GetImageMap(nsIPresContext* aPresContext)
|
||||
{
|
||||
if (nsnull == mImageMap) {
|
||||
nsAutoString usemap;
|
||||
@ -739,10 +699,13 @@ nsImageFrame::GetImageMap()
|
||||
rv = hdoc->GetImageMap(usemap, &map);
|
||||
NS_RELEASE(hdoc);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
aPresContext->GetShell(getter_AddRefs(presShell));
|
||||
|
||||
mImageMap = new nsImageMap();
|
||||
if (nsnull != mImageMap) {
|
||||
NS_ADDREF(mImageMap);
|
||||
mImageMap->Init(map);
|
||||
mImageMap->Init(presShell, this, map);
|
||||
}
|
||||
NS_IF_RELEASE(map);
|
||||
}
|
||||
@ -896,7 +859,7 @@ nsImageFrame::GetContentForEvent(nsIPresContext* aPresContext,
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aContent);
|
||||
nsImageMap* map;
|
||||
map = GetImageMap();
|
||||
map = GetImageMap(aPresContext);
|
||||
|
||||
if (nsnull != map) {
|
||||
nsPoint p;
|
||||
@ -931,7 +894,7 @@ nsImageFrame::HandleEvent(nsIPresContext* aPresContext,
|
||||
case NS_MOUSE_LEFT_BUTTON_UP:
|
||||
case NS_MOUSE_MOVE:
|
||||
{
|
||||
map = GetImageMap();
|
||||
map = GetImageMap(aPresContext);
|
||||
PRBool isServerMap = IsServerImageMap();
|
||||
if ((nsnull != map) || isServerMap) {
|
||||
nsPoint p;
|
||||
@ -1008,7 +971,7 @@ nsImageFrame::GetCursor(nsIPresContext* aPresContext,
|
||||
nsPoint& aPoint,
|
||||
PRInt32& aCursor)
|
||||
{
|
||||
nsImageMap* map = GetImageMap();
|
||||
nsImageMap* map = GetImageMap(aPresContext);
|
||||
if (nsnull != map) {
|
||||
nsPoint p;
|
||||
TranslateEventCoords(aPresContext, aPoint, p);
|
||||
|
@ -86,7 +86,7 @@ protected:
|
||||
|
||||
nsresult UpdateImage(nsIPresContext* aPresContext, PRUint32 aStatus, void* aClosure);
|
||||
|
||||
nsImageMap* GetImageMap();
|
||||
nsImageMap* GetImageMap(nsIPresContext* aPresContext);
|
||||
|
||||
void TriggerLink(nsIPresContext* aPresContext,
|
||||
const nsString& aURLSpec,
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIFrameManager.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsCoord.h"
|
||||
|
||||
@ -859,21 +860,27 @@ nsImageMap::QueryInterface(REFNSIID iid, void** result)
|
||||
void
|
||||
nsImageMap::FreeAreas()
|
||||
{
|
||||
nsCOMPtr<nsIFrameManager> frameManager;
|
||||
mPresShell->GetFrameManager(getter_AddRefs(frameManager));
|
||||
|
||||
PRInt32 i, n = mAreas.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
Area* area = (Area*) mAreas.ElementAt(i);
|
||||
frameManager->SetPrimaryFrameFor(area->mArea, nsnull);
|
||||
delete area;
|
||||
}
|
||||
mAreas.Clear();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsImageMap::Init(nsIDOMHTMLMapElement* aMap)
|
||||
nsImageMap::Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapElement* aMap)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aMap, "null ptr");
|
||||
if (nsnull == aMap) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
mPresShell = aPresShell;
|
||||
mImageFrame = aImageFrame;
|
||||
mDomMap = aMap;
|
||||
|
||||
nsresult rv = aMap->QueryInterface(kIContentIID, (void**) &mMap);
|
||||
@ -989,6 +996,10 @@ nsImageMap::AddArea(nsIContent* aArea)
|
||||
rec->AddEventListenerByIID(this, NS_GET_IID(nsIDOMFocusListener));
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIFrameManager> frameManager;
|
||||
mPresShell->GetFrameManager(getter_AddRefs(frameManager));
|
||||
frameManager->SetPrimaryFrameFor(aArea, mImageFrame);
|
||||
|
||||
Area* area;
|
||||
if ((0 == shape.Length()) ||
|
||||
shape.EqualsIgnoreCase("rect") ||
|
||||
|
@ -44,7 +44,7 @@ class nsImageMap : public nsIDocumentObserver, public nsIDOMFocusListener
|
||||
public:
|
||||
nsImageMap();
|
||||
|
||||
nsresult Init(nsIDOMHTMLMapElement* aMap);
|
||||
nsresult Init(nsIPresShell* aPresShell, nsIFrame* aImageFrame, nsIDOMHTMLMapElement* aMap);
|
||||
|
||||
/**
|
||||
* See if the given aX,aY <b>pixel</b> coordinates are in the image
|
||||
@ -156,6 +156,8 @@ protected:
|
||||
nsresult ChangeFocus(nsIDOMEvent* aEvent, PRBool aFocus);
|
||||
nsresult Invalidate(nsIPresContext* aPresContext, nsIFrame* aFrame, nsRect& aRect);
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user