WebKitAccessibleUtil.cpp [plain text]
#include "config.h"
#include "WebKitAccessibleUtil.h"
#if HAVE(ACCESSIBILITY)
#include "AccessibilityObject.h"
#include "FrameView.h"
#include "IntRect.h"
#include "Node.h"
#include "Range.h"
#include "VisibleSelection.h"
#include <wtf/text/AtomicString.h>
#include <wtf/text/CString.h>
using namespace WebCore;
AtkAttributeSet* addToAtkAttributeSet(AtkAttributeSet* attributeSet, const char* name, const char* value)
{
AtkAttribute* attribute = static_cast<AtkAttribute*>(g_malloc(sizeof(AtkAttribute)));
attribute->name = g_strdup(name);
attribute->value = g_strdup(value);
attributeSet = g_slist_prepend(attributeSet, attribute);
return attributeSet;
}
void contentsRelativeToAtkCoordinateType(AccessibilityObject* coreObject, AtkCoordType coordType, IntRect rect, gint* x, gint* y, gint* width, gint* height)
{
FrameView* frameView = coreObject->documentFrameView();
if (frameView) {
switch (coordType) {
case ATK_XY_WINDOW:
rect = frameView->contentsToWindow(rect);
break;
case ATK_XY_SCREEN:
rect = frameView->contentsToScreen(rect);
break;
}
}
if (x)
*x = rect.x();
if (y)
*y = rect.y();
if (width)
*width = rect.width();
if (height)
*height = rect.height();
}
static bool titleTagShouldBeUsedInDescriptionField(AccessibilityObject* coreObject)
{
return (coreObject->isLink() && !coreObject->isImageMapLink()) || coreObject->isImage();
}
String accessibilityTitle(AccessibilityObject* coreObject)
{
Vector<AccessibilityText> textOrder;
coreObject->accessibilityText(textOrder);
unsigned length = textOrder.size();
for (unsigned k = 0; k < length; k++) {
const AccessibilityText& text = textOrder[k];
if (text.textSource == VisibleText || text.textSource == ChildrenText)
return text.text;
if (text.textSource == LabelByElementText && !coreObject->exposesTitleUIElement())
return text.text;
if (coreObject->roleValue() == ToolbarRole && text.textSource == AlternativeText)
return text.text;
if (text.textSource == TitleTagText && !titleTagShouldBeUsedInDescriptionField(coreObject))
return text.text;
}
return String();
}
String accessibilityDescription(AccessibilityObject* coreObject)
{
Vector<AccessibilityText> textOrder;
coreObject->accessibilityText(textOrder);
unsigned length = textOrder.size();
for (unsigned k = 0; k < length; k++) {
const AccessibilityText& text = textOrder[k];
if (text.textSource == AlternativeText)
return text.text;
if (text.textSource == TitleTagText && titleTagShouldBeUsedInDescriptionField(coreObject))
return text.text;
}
return String();
}
bool selectionBelongsToObject(AccessibilityObject* coreObject, VisibleSelection& selection)
{
if (!coreObject || !coreObject->isAccessibilityRenderObject())
return false;
if (selection.isNone())
return false;
RefPtr<Range> range = selection.toNormalizedRange();
if (!range)
return false;
Node* node = coreObject->node();
Node* lastDescendant = node->lastDescendant();
return (range->intersectsNode(node, IGNORE_EXCEPTION)
&& (range->endContainer() != node || range->endOffset())
&& (range->startContainer() != lastDescendant || range->startOffset() != lastOffsetInNode(lastDescendant)));
}
#endif