2010-04-06 00:41:28 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 00:41:28 +00:00
|
|
|
|
2012-06-04 12:32:34 +00:00
|
|
|
#include "HTMLImageMapAccessible.h"
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2013-04-25 03:48:26 +00:00
|
|
|
#include "ARIAMap.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
#include "nsAccUtils.h"
|
2012-11-20 04:53:38 +00:00
|
|
|
#include "DocAccessible-inl.h"
|
2012-01-12 03:07:35 +00:00
|
|
|
#include "Role.h"
|
2010-04-27 06:52:03 +00:00
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
#include "nsIDOMHTMLCollection.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMHTMLAreaElement.h"
|
|
|
|
#include "nsIFrame.h"
|
2011-04-26 06:52:19 +00:00
|
|
|
#include "nsImageFrame.h"
|
2011-04-27 05:51:13 +00:00
|
|
|
#include "nsImageMap.h"
|
2013-09-07 13:01:08 +00:00
|
|
|
#include "nsIURI.h"
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
using namespace mozilla::a11y;
|
2012-03-15 20:16:02 +00:00
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:34 +00:00
|
|
|
// HTMLImageMapAccessible
|
2010-04-06 00:41:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-04 12:32:34 +00:00
|
|
|
HTMLImageMapAccessible::
|
|
|
|
HTMLImageMapAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-06-02 11:30:34 +00:00
|
|
|
ImageAccessibleWrap(aContent, aDoc)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2012-12-18 05:22:26 +00:00
|
|
|
mType = eImageMapType;
|
2016-04-01 01:22:50 +00:00
|
|
|
|
|
|
|
UpdateChildAreas(false);
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:34 +00:00
|
|
|
// HTMLImageMapAccessible: nsISupports
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-06-04 12:32:34 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(HTMLImageMapAccessible, ImageAccessible)
|
2010-04-06 00:41:28 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:34 +00:00
|
|
|
// HTMLImageMapAccessible: Accessible public
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-01-12 03:07:35 +00:00
|
|
|
role
|
2012-06-04 12:32:34 +00:00
|
|
|
HTMLImageMapAccessible::NativeRole()
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2012-01-12 03:07:35 +00:00
|
|
|
return roles::IMAGE_MAP;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:34 +00:00
|
|
|
// HTMLImageMapAccessible: HyperLinkAccessible
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-06-04 12:32:34 +00:00
|
|
|
HTMLImageMapAccessible::AnchorCount()
|
2010-09-01 03:26:13 +00:00
|
|
|
{
|
2012-05-25 10:53:45 +00:00
|
|
|
return ChildCount();
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible*
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLImageMapAccessible::AnchorAt(uint32_t aAnchorIndex)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2010-09-01 03:26:13 +00:00
|
|
|
return GetChildAt(aAnchorIndex);
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
already_AddRefed<nsIURI>
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLImageMapAccessible::AnchorURIAt(uint32_t aAnchorIndex)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* area = GetChildAt(aAnchorIndex);
|
2010-09-01 03:26:13 +00:00
|
|
|
if (!area)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-09-01 03:26:13 +00:00
|
|
|
|
|
|
|
nsIContent* linkContent = area->GetContent();
|
2012-07-30 14:20:58 +00:00
|
|
|
return linkContent ? linkContent->GetHrefURI() : nullptr;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:34 +00:00
|
|
|
// HTMLImageMapAccessible: public
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-03-15 20:16:02 +00:00
|
|
|
void
|
2012-06-04 12:32:34 +00:00
|
|
|
HTMLImageMapAccessible::UpdateChildAreas(bool aDoFireEvents)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2012-03-15 20:16:02 +00:00
|
|
|
nsImageFrame* imageFrame = do_QueryFrame(mContent->GetPrimaryFrame());
|
2010-04-08 06:43:08 +00:00
|
|
|
|
2012-03-15 20:16:02 +00:00
|
|
|
// If image map is not initialized yet then we trigger one time more later.
|
|
|
|
nsImageMap* imageMapObj = imageFrame->GetExistingImageMap();
|
|
|
|
if (!imageMapObj)
|
2010-04-06 00:41:28 +00:00
|
|
|
return;
|
|
|
|
|
2016-04-07 13:30:22 +00:00
|
|
|
TreeMutation mt(this, TreeMutation::kNoEvents & !aDoFireEvents);
|
2010-11-12 19:00:55 +00:00
|
|
|
|
2012-03-15 20:16:02 +00:00
|
|
|
// Remove areas that are not a valid part of the image map anymore.
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t childIdx = mChildren.Length() - 1; childIdx >= 0; childIdx--) {
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* area = mChildren.ElementAt(childIdx);
|
2012-03-15 20:16:02 +00:00
|
|
|
if (area->GetContent()->GetPrimaryFrame())
|
|
|
|
continue;
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2016-04-01 14:53:52 +00:00
|
|
|
mt.BeforeRemoval(area);
|
2012-03-15 20:16:02 +00:00
|
|
|
RemoveChild(area);
|
|
|
|
}
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-03-15 20:16:02 +00:00
|
|
|
// Insert new areas into the tree.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t areaElmCount = imageMapObj->AreaCount();
|
|
|
|
for (uint32_t idx = 0; idx < areaElmCount; idx++) {
|
2012-03-15 20:16:02 +00:00
|
|
|
nsIContent* areaContent = imageMapObj->GetAreaAt(idx);
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible* area = mChildren.SafeElementAt(idx);
|
2012-03-15 20:16:02 +00:00
|
|
|
if (!area || area->GetContent() != areaContent) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<Accessible> area = new HTMLAreaAccessible(areaContent, mDoc);
|
2016-03-03 12:45:47 +00:00
|
|
|
mDoc->BindToDocument(area, aria::GetRoleMap(areaContent->AsElement()));
|
2012-03-15 20:16:02 +00:00
|
|
|
|
|
|
|
if (!InsertChildAt(idx, area)) {
|
|
|
|
mDoc->UnbindFromDocument(area);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-01 14:53:52 +00:00
|
|
|
mt.AfterInsertion(area);
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-15 20:16:02 +00:00
|
|
|
|
2016-04-01 14:53:52 +00:00
|
|
|
mt.Done();
|
2012-03-15 20:16:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 20:52:34 +00:00
|
|
|
Accessible*
|
|
|
|
HTMLImageMapAccessible::GetChildAccessibleFor(const nsINode* aNode) const
|
|
|
|
{
|
|
|
|
uint32_t length = mChildren.Length();
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
|
|
|
Accessible* area = mChildren[i];
|
|
|
|
if (area->GetContent() == aNode)
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-04-06 00:41:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:34 +00:00
|
|
|
// HTMLAreaAccessible
|
2010-04-06 00:41:28 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-04 12:32:34 +00:00
|
|
|
HTMLAreaAccessible::
|
|
|
|
HTMLAreaAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-06-04 12:32:38 +00:00
|
|
|
HTMLLinkAccessible(aContent, aDoc)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2012-10-13 06:34:21 +00:00
|
|
|
// Make HTML area DOM element not accessible. HTML image map accessible
|
2012-09-04 06:06:10 +00:00
|
|
|
// manages its tree itself.
|
2012-12-11 03:31:42 +00:00
|
|
|
mStateFlags |= eNotNodeMapEntry;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-10-22 00:49:28 +00:00
|
|
|
// HTMLAreaAccessible: Accessible
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-10-14 04:18:39 +00:00
|
|
|
ENameValueFlag
|
|
|
|
HTMLAreaAccessible::NativeName(nsString& aName)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
2012-10-17 06:38:16 +00:00
|
|
|
ENameValueFlag nameFlag = Accessible::NativeName(aName);
|
2010-04-06 00:41:28 +00:00
|
|
|
if (!aName.IsEmpty())
|
2012-10-17 06:38:16 +00:00
|
|
|
return nameFlag;
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2011-06-03 21:35:17 +00:00
|
|
|
if (!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName))
|
2014-10-22 00:49:28 +00:00
|
|
|
Value(aName);
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-10-14 04:18:39 +00:00
|
|
|
return eNameOK;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2011-04-23 13:14:05 +00:00
|
|
|
void
|
2012-06-04 12:32:34 +00:00
|
|
|
HTMLAreaAccessible::Description(nsString& aDescription)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
|
|
|
aDescription.Truncate();
|
|
|
|
|
|
|
|
// Still to do - follow IE's standard here
|
2010-06-11 08:23:18 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(mContent));
|
2012-06-02 11:30:34 +00:00
|
|
|
if (area)
|
2010-04-06 00:41:28 +00:00
|
|
|
area->GetShape(aDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:34 +00:00
|
|
|
// HTMLAreaAccessible: Accessible public
|
2010-04-06 00:41:28 +00:00
|
|
|
|
2012-05-29 01:18:45 +00:00
|
|
|
Accessible*
|
2012-08-22 15:56:38 +00:00
|
|
|
HTMLAreaAccessible::ChildAtPoint(int32_t aX, int32_t aY,
|
2012-06-04 12:32:38 +00:00
|
|
|
EWhichChildAtPoint aWhichChild)
|
2010-04-06 00:41:28 +00:00
|
|
|
{
|
|
|
|
// Don't walk into area accessibles.
|
2011-03-29 04:44:20 +00:00
|
|
|
return this;
|
2010-04-06 00:41:28 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 03:26:13 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-04 12:32:34 +00:00
|
|
|
// HTMLImageMapAccessible: HyperLinkAccessible
|
2010-09-01 03:26:13 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-06-04 12:32:34 +00:00
|
|
|
HTMLAreaAccessible::StartOffset()
|
2010-09-01 03:26:13 +00:00
|
|
|
{
|
|
|
|
// Image map accessible is not hypertext accessible therefore
|
2012-05-29 01:18:45 +00:00
|
|
|
// StartOffset/EndOffset implementations of Accessible doesn't work here.
|
2010-09-01 03:26:13 +00: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 09:08:40 +00:00
|
|
|
return IndexInParent();
|
2010-09-01 03:26:13 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-06-04 12:32:34 +00:00
|
|
|
HTMLAreaAccessible::EndOffset()
|
2010-09-01 03:26:13 +00:00
|
|
|
{
|
2011-06-13 09:08:40 +00:00
|
|
|
return IndexInParent() + 1;
|
2010-09-01 03:26:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 17:30:23 +00:00
|
|
|
nsRect
|
|
|
|
HTMLAreaAccessible::RelativeBounds(nsIFrame** aBoundingFrame) const
|
2012-03-23 17:05:09 +00:00
|
|
|
{
|
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
if (!frame)
|
2014-09-16 17:30:23 +00:00
|
|
|
return nsRect();
|
2012-03-23 17:05:09 +00:00
|
|
|
|
|
|
|
nsImageFrame* imageFrame = do_QueryFrame(frame);
|
|
|
|
nsImageMap* map = imageFrame->GetImageMap();
|
|
|
|
|
2014-09-16 17:30:23 +00:00
|
|
|
nsRect bounds;
|
|
|
|
nsresult rv = map->GetBoundsForAreaContent(mContent, bounds);
|
2012-03-23 17:05:09 +00:00
|
|
|
if (NS_FAILED(rv))
|
2014-09-16 17:30:23 +00:00
|
|
|
return nsRect();
|
2012-03-23 17:05:09 +00:00
|
|
|
|
|
|
|
// XXX Areas are screwy; they return their rects as a pair of points, one pair
|
|
|
|
// stored into the width and height.
|
|
|
|
*aBoundingFrame = frame;
|
2014-09-16 17:30:23 +00:00
|
|
|
bounds.width -= bounds.x;
|
|
|
|
bounds.height -= bounds.y;
|
|
|
|
return bounds;
|
2012-03-23 17:05:09 +00:00
|
|
|
}
|