mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-03 22:38:41 +09:00
No Issue - Modernize nsImageFrame/nsImageMap
Primarily flow control improvements, and removing unused `nsresults`.
This commit is contained in:
parent
9f64d0f4b0
commit
8db40dbbb5
3 changed files with 37 additions and 60 deletions
|
|
@ -715,9 +715,7 @@ nsImageMap::GetBoundsForAreaContent(nsIContent *aContent,
|
|||
void
|
||||
nsImageMap::FreeAreas()
|
||||
{
|
||||
uint32_t i, n = mAreas.Length();
|
||||
for (i = 0; i < n; i++) {
|
||||
Area* area = mAreas.ElementAt(i);
|
||||
for (auto* area : mAreas) {
|
||||
if (area->mArea->IsInUncomposedDoc()) {
|
||||
NS_ASSERTION(area->mArea->GetPrimaryFrame() == mImageFrame,
|
||||
"Unexpected primary frame");
|
||||
|
|
@ -731,30 +729,28 @@ nsImageMap::FreeAreas()
|
|||
false);
|
||||
delete area;
|
||||
}
|
||||
|
||||
mAreas.Clear();
|
||||
}
|
||||
|
||||
nsresult
|
||||
void
|
||||
nsImageMap::Init(nsImageFrame* aImageFrame, nsIContent* aMap)
|
||||
{
|
||||
NS_PRECONDITION(aMap, "null ptr");
|
||||
if (!aMap) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
mImageFrame = aImageFrame;
|
||||
MOZ_ASSERT(aMap);
|
||||
MOZ_ASSERT(aImageFrame);
|
||||
|
||||
mImageFrame = aImageFrame;
|
||||
mMap = aMap;
|
||||
mMap->AddMutationObserver(this);
|
||||
|
||||
// "Compile" the areas in the map into faster access versions
|
||||
return UpdateAreas();
|
||||
UpdateAreas();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
void
|
||||
nsImageMap::SearchForAreas(nsIContent* aParent)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
uint32_t n = aParent->GetChildCount();
|
||||
|
||||
// Look for <area> elements.
|
||||
|
|
@ -762,8 +758,7 @@ nsImageMap::SearchForAreas(nsIContent* aParent)
|
|||
child;
|
||||
child = child->GetNextSibling()) {
|
||||
if (auto* area = static_cast<HTMLAreaElement*>(HTMLAreaElement::FromContent(child))) {
|
||||
rv = AddArea(area);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
AddArea(area);
|
||||
|
||||
// Continue to next child. This stops mConsiderWholeSubtree from
|
||||
// getting set. It also makes us ignore children of <area>s which
|
||||
|
|
@ -774,35 +769,28 @@ nsImageMap::SearchForAreas(nsIContent* aParent)
|
|||
|
||||
if (child->IsElement()) {
|
||||
mConsiderWholeSubtree = true;
|
||||
rv = SearchForAreas(child);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
SearchForAreas(child);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
void
|
||||
nsImageMap::UpdateAreas()
|
||||
{
|
||||
// Get rid of old area data
|
||||
FreeAreas();
|
||||
|
||||
mConsiderWholeSubtree = false;
|
||||
nsresult rv = SearchForAreas(mMap);
|
||||
SearchForAreas(mMap);
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAccessibilityService* accService = GetAccService();
|
||||
if (accService) {
|
||||
accService->UpdateImageMap(mImageFrame);
|
||||
}
|
||||
if (nsAccessibilityService* accService = GetAccService()) {
|
||||
accService->UpdateImageMap(mImageFrame);
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
void
|
||||
nsImageMap::AddArea(HTMLAreaElement* aArea)
|
||||
{
|
||||
static nsIContent::AttrValuesArray strings[] =
|
||||
|
|
@ -834,17 +822,13 @@ nsImageMap::AddArea(HTMLAreaElement* aArea)
|
|||
break;
|
||||
default:
|
||||
area = nullptr;
|
||||
NS_NOTREACHED("FindAttrValueIn returned an unexpected value.");
|
||||
MOZ_ASSERT_UNREACHABLE("FindAttrValueIn returned an unexpected value.");
|
||||
break;
|
||||
}
|
||||
if (!area)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
//Add focus listener to track area focus changes
|
||||
aArea->AddSystemEventListener(NS_LITERAL_STRING("focus"), this, false,
|
||||
false);
|
||||
aArea->AddSystemEventListener(NS_LITERAL_STRING("blur"), this, false,
|
||||
false);
|
||||
aArea->AddSystemEventListener(NS_LITERAL_STRING("focus"), this, false, false);
|
||||
aArea->AddSystemEventListener(NS_LITERAL_STRING("blur"), this, false, false);
|
||||
|
||||
// This is a nasty hack. It needs to go away: see bug 135040. Once this is
|
||||
// removed, the code added to RestyleManager::RestyleElement,
|
||||
|
|
@ -857,16 +841,13 @@ nsImageMap::AddArea(HTMLAreaElement* aArea)
|
|||
aArea->GetAttr(kNameSpaceID_None, nsGkAtoms::coords, coords);
|
||||
area->ParseCoords(coords);
|
||||
mAreas.AppendElement(area);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIContent*
|
||||
nsImageMap::GetArea(nscoord aX, nscoord aY) const
|
||||
{
|
||||
NS_ASSERTION(mMap, "Not initialized");
|
||||
uint32_t i, n = mAreas.Length();
|
||||
for (i = 0; i < n; i++) {
|
||||
Area* area = mAreas.ElementAt(i);
|
||||
for (auto* area : mAreas) {
|
||||
if (area->IsInside(aX, aY)) {
|
||||
return area->mArea;
|
||||
}
|
||||
|
|
@ -1000,7 +981,7 @@ nsImageMap::HandleEvent(nsIDOMEvent* aEvent)
|
|||
}
|
||||
|
||||
void
|
||||
nsImageMap::Destroy(void)
|
||||
nsImageMap::Destroy()
|
||||
{
|
||||
FreeAreas();
|
||||
mImageFrame = nullptr;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue