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