2010-04-06 04:41:28 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2012-06-04 16:32:34 +04:00
|
|
|
#include "HTMLImageMapAccessible.h"
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2013-04-25 07:48:26 +04:00
|
|
|
#include "ARIAMap.h"
|
2022-10-11 04:41:42 +03:00
|
|
|
#include "EventTree.h"
|
2023-07-26 05:19:41 +03:00
|
|
|
#include "mozilla/a11y/Role.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2023-07-24 22:31:29 +03:00
|
|
|
#include "nsCoreUtils.h"
|
2010-04-06 04:41:28 +04:00
|
|
|
#include "nsIFrame.h"
|
2011-04-26 10:52:19 +04:00
|
|
|
#include "nsImageFrame.h"
|
2011-04-27 09:51:13 +04:00
|
|
|
#include "nsImageMap.h"
|
2021-10-05 23:44:46 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2017-09-22 03:52:28 +03:00
|
|
|
#include "mozilla/dom/HTMLAreaElement.h"
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2012-01-12 07:07:35 +04:00
|
|
|
using namespace mozilla::a11y;
|
2012-03-16 00:16:02 +04:00
|
|
|
|
2010-04-06 04:41:28 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 16:32:34 +04:00
|
|
|
// HTMLImageMapAccessible
|
2010-04-06 04:41:28 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-04 16:32:34 +04:00
|
|
|
HTMLImageMapAccessible::HTMLImageMapAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2022-11-22 07:55:11 +03:00
|
|
|
: ImageAccessible(aContent, aDoc) {
|
2012-12-18 09:22:26 +04:00
|
|
|
mType = eImageMapType;
|
2016-04-01 04:22:50 +03:00
|
|
|
|
|
|
|
UpdateChildAreas(false);
|
2010-04-06 04:41:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2021-02-20 02:14:32 +03:00
|
|
|
// HTMLImageMapAccessible: LocalAccessible public
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2018-05-07 22:05:50 +03:00
|
|
|
role HTMLImageMapAccessible::NativeRole() const { return roles::IMAGE_MAP; }
|
2010-04-06 04:41:28 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 16:32:34 +04:00
|
|
|
// HTMLImageMapAccessible: public
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2012-06-04 16:32:34 +04:00
|
|
|
void HTMLImageMapAccessible::UpdateChildAreas(bool aDoFireEvents) {
|
2023-03-08 18:40:52 +03:00
|
|
|
if (!mContent || !mContent->GetPrimaryFrame()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-16 00:16:02 +04:00
|
|
|
nsImageFrame* imageFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2010-04-08 10:43:08 +04:00
|
|
|
|
2012-03-16 00:16:02 +04:00
|
|
|
// If image map is not initialized yet then we trigger one time more later.
|
|
|
|
nsImageMap* imageMapObj = imageFrame->GetExistingImageMap();
|
|
|
|
if (!imageMapObj) return;
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2016-04-07 16:30:22 +03:00
|
|
|
TreeMutation mt(this, TreeMutation::kNoEvents & !aDoFireEvents);
|
2010-11-12 22:00:55 +03:00
|
|
|
|
2012-03-16 00:16:02 +04:00
|
|
|
// Remove areas that are not a valid part of the image map anymore.
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t childIdx = mChildren.Length() - 1; childIdx >= 0; childIdx--) {
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* area = mChildren.ElementAt(childIdx);
|
2012-03-16 00:16:02 +04:00
|
|
|
if (area->GetContent()->GetPrimaryFrame()) continue;
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2016-04-01 17:53:52 +03:00
|
|
|
mt.BeforeRemoval(area);
|
2012-03-16 00:16:02 +04:00
|
|
|
RemoveChild(area);
|
|
|
|
}
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2012-03-16 00:16:02 +04:00
|
|
|
// Insert new areas into the tree.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t areaElmCount = imageMapObj->AreaCount();
|
|
|
|
for (uint32_t idx = 0; idx < areaElmCount; idx++) {
|
2012-03-16 00:16:02 +04:00
|
|
|
nsIContent* areaContent = imageMapObj->GetAreaAt(idx);
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* area = mChildren.SafeElementAt(idx);
|
2012-03-16 00:16:02 +04:00
|
|
|
if (!area || area->GetContent() != areaContent) {
|
2021-02-20 02:14:32 +03:00
|
|
|
RefPtr<LocalAccessible> area = new HTMLAreaAccessible(areaContent, mDoc);
|
2016-03-03 15:45:47 +03:00
|
|
|
mDoc->BindToDocument(area, aria::GetRoleMap(areaContent->AsElement()));
|
2012-03-16 00:16:02 +04:00
|
|
|
|
|
|
|
if (!InsertChildAt(idx, area)) {
|
|
|
|
mDoc->UnbindFromDocument(area);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-01 17:53:52 +03:00
|
|
|
mt.AfterInsertion(area);
|
2010-04-06 04:41:28 +04:00
|
|
|
}
|
|
|
|
}
|
2012-03-16 00:16:02 +04:00
|
|
|
|
2016-04-01 17:53:52 +03:00
|
|
|
mt.Done();
|
2012-03-16 00:16:02 +04:00
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* HTMLImageMapAccessible::GetChildAccessibleFor(
|
2014-02-11 00:52:34 +04:00
|
|
|
const nsINode* aNode) const {
|
|
|
|
uint32_t length = mChildren.Length();
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2021-02-20 02:14:32 +03:00
|
|
|
LocalAccessible* area = mChildren[i];
|
2014-02-11 00:52:34 +04:00
|
|
|
if (area->GetContent() == aNode) return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-04-06 04:41:28 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 16:32:34 +04:00
|
|
|
// HTMLAreaAccessible
|
2010-04-06 04:41:28 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-04 16:32:34 +04:00
|
|
|
HTMLAreaAccessible::HTMLAreaAccessible(nsIContent* aContent,
|
|
|
|
DocAccessible* aDoc)
|
2012-06-04 16:32:38 +04:00
|
|
|
: HTMLLinkAccessible(aContent, aDoc) {
|
2012-10-13 10:34:21 +04:00
|
|
|
// Make HTML area DOM element not accessible. HTML image map accessible
|
2012-09-04 10:06:10 +04:00
|
|
|
// manages its tree itself.
|
2012-12-11 07:31:42 +04:00
|
|
|
mStateFlags |= eNotNodeMapEntry;
|
2010-04-06 04:41:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2021-02-20 02:14:32 +03:00
|
|
|
// HTMLAreaAccessible: LocalAccessible
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2023-07-24 22:31:29 +03:00
|
|
|
role HTMLAreaAccessible::NativeRole() const {
|
|
|
|
// A link element without an href attribute and without a click listener
|
|
|
|
// should be reported as a generic.
|
|
|
|
if (mContent->IsElement()) {
|
|
|
|
dom::Element* element = mContent->AsElement();
|
|
|
|
if (!element->HasAttr(nsGkAtoms::href) &&
|
|
|
|
!nsCoreUtils::HasClickListener(element)) {
|
|
|
|
return roles::TEXT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HTMLLinkAccessible::NativeRole();
|
|
|
|
}
|
|
|
|
|
2018-05-15 19:13:02 +03:00
|
|
|
ENameValueFlag HTMLAreaAccessible::NativeName(nsString& aName) const {
|
2021-02-20 02:14:32 +03:00
|
|
|
ENameValueFlag nameFlag = LocalAccessible::NativeName(aName);
|
2010-04-06 04:41:28 +04:00
|
|
|
if (!aName.IsEmpty()) return nameFlag;
|
|
|
|
|
2023-06-23 13:01:32 +03:00
|
|
|
if (!mContent->AsElement()->GetAttr(nsGkAtoms::alt, aName)) {
|
2014-10-22 04:49:28 +04:00
|
|
|
Value(aName);
|
2021-02-20 02:14:32 +03:00
|
|
|
}
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2012-10-14 08:18:39 +04:00
|
|
|
return eNameOK;
|
2010-04-06 04:41:28 +04:00
|
|
|
}
|
|
|
|
|
2021-09-02 21:06:51 +03:00
|
|
|
void HTMLAreaAccessible::Description(nsString& aDescription) const {
|
2010-04-06 04:41:28 +04:00
|
|
|
aDescription.Truncate();
|
|
|
|
|
|
|
|
// Still to do - follow IE's standard here
|
2017-12-07 21:13:50 +03:00
|
|
|
RefPtr<dom::HTMLAreaElement> area =
|
2018-03-22 00:39:04 +03:00
|
|
|
dom::HTMLAreaElement::FromNodeOrNull(mContent);
|
2010-04-06 04:41:28 +04:00
|
|
|
if (area) area->GetShape(aDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2021-02-20 02:14:32 +03:00
|
|
|
// HTMLAreaAccessible: LocalAccessible public
|
2010-04-06 04:41:28 +04:00
|
|
|
|
2021-03-03 09:10:01 +03:00
|
|
|
LocalAccessible* HTMLAreaAccessible::LocalChildAtPoint(
|
2021-02-20 02:14:32 +03:00
|
|
|
int32_t aX, int32_t aY, EWhichChildAtPoint aWhichChild) {
|
2010-04-06 04:41:28 +04:00
|
|
|
// Don't walk into area accessibles.
|
2011-03-29 08:44:20 +04:00
|
|
|
return this;
|
2010-04-06 04:41:28 +04:00
|
|
|
}
|
|
|
|
|
2010-09-01 07:26:13 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 16:32:34 +04:00
|
|
|
// HTMLImageMapAccessible: HyperLinkAccessible
|
2010-09-01 07:26:13 +04:00
|
|
|
|
2012-06-04 16:32:34 +04:00
|
|
|
uint32_t HTMLAreaAccessible::StartOffset() {
|
2010-09-01 07:26:13 +04:00
|
|
|
// Image map accessible is not hypertext accessible therefore
|
2021-02-20 02:14:32 +03:00
|
|
|
// StartOffset/EndOffset implementations of LocalAccessible doesn't work here.
|
2010-09-01 07:26:13 +04:00
|
|
|
// We return index in parent because image map contains area links only which
|
|
|
|
// are embedded objects.
|
|
|
|
// XXX: image map should be a hypertext accessible.
|
2011-06-13 13:08:40 +04:00
|
|
|
return IndexInParent();
|
2010-09-01 07:26:13 +04:00
|
|
|
}
|
|
|
|
|
2012-06-04 16:32:34 +04:00
|
|
|
uint32_t HTMLAreaAccessible::EndOffset() { return IndexInParent() + 1; }
|
2010-09-01 07:26:13 +04:00
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
nsRect HTMLAreaAccessible::RelativeBounds(nsIFrame** aBoundingFrame) const {
|
2012-03-23 21:05:09 +04:00
|
|
|
nsIFrame* frame = GetFrame();
|
2014-09-16 21:30:23 +04:00
|
|
|
if (!frame) return nsRect();
|
2012-03-23 21:05:09 +04:00
|
|
|
|
|
|
|
nsImageFrame* imageFrame = do_QueryFrame(frame);
|
|
|
|
nsImageMap* map = imageFrame->GetImageMap();
|
|
|
|
|
2014-09-16 21:30:23 +04:00
|
|
|
nsRect bounds;
|
|
|
|
nsresult rv = map->GetBoundsForAreaContent(mContent, bounds);
|
2021-10-05 23:44:46 +03:00
|
|
|
|
2012-03-23 21:05:09 +04:00
|
|
|
if (NS_FAILED(rv)) return nsRect();
|
|
|
|
|
|
|
|
// XXX Areas are screwy; they return their rects as a pair of points, one pair
|
|
|
|
// stored into the width and height.
|
|
|
|
*aBoundingFrame = frame;
|
2018-01-12 20:07:29 +03:00
|
|
|
bounds.SizeTo(bounds.Width() - bounds.X(), bounds.Height() - bounds.Y());
|
2014-09-16 21:30:23 +04:00
|
|
|
return bounds;
|
2012-03-23 21:05:09 +04:00
|
|
|
}
|
2021-10-05 23:44:46 +03:00
|
|
|
|
|
|
|
nsRect HTMLAreaAccessible::ParentRelativeBounds() {
|
|
|
|
nsIFrame* boundingFrame = nullptr;
|
|
|
|
nsRect relativeBoundsRect = RelativeBounds(&boundingFrame);
|
2023-11-16 01:37:29 +03:00
|
|
|
if (MOZ_UNLIKELY(!boundingFrame)) {
|
|
|
|
// Area is not attached to an image map?
|
|
|
|
return nsRect();
|
2021-10-05 23:44:46 +03:00
|
|
|
}
|
|
|
|
|
2023-11-16 01:37:29 +03:00
|
|
|
// The relative bounds returned above are relative to this area's
|
|
|
|
// image map, which is technically already "parent relative".
|
|
|
|
// Because area elements are `display:none` to layout, they can't
|
|
|
|
// have transforms or other styling applied directly, and so we
|
|
|
|
// don't apply any additional transforms here. Any transform
|
|
|
|
// at the image map layer will be taken care of when computing bounds
|
|
|
|
// in the parent process.
|
2021-10-05 23:44:46 +03:00
|
|
|
return relativeBoundsRect;
|
|
|
|
}
|