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