WebKitAccessibleUtil.cpp [plain text]
#include "config.h"
#include "WebKitAccessibleUtil.h"
#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();
}
const char* returnString(const String& str)
{
static CString returnedString;
returnedString = str.utf8();
return returnedString.data();
}
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();
ExceptionCode ec = 0;
return (range->intersectsNode(node, ec)
&& (range->endContainer() != node || range->endOffset())
&& (range->startContainer() != lastDescendant || range->startOffset() != lastOffsetInNode(lastDescendant)));
}