From db14019a23d96bc8a444b6576a5da8bd1cfbc8b0 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Wed, 4 Aug 2010 11:41:34 +0100 Subject: Merge WebKit at r64523 : Initial merge by git. Change-Id: Ibb796c6802e757b1d9b40f58205cfbe4da95fcd4 --- WebCore/accessibility/AccessibilityObject.cpp | 19 +++++++++++- WebCore/accessibility/AccessibilityObject.h | 6 ++++ .../accessibility/AccessibilityRenderObject.cpp | 6 ++-- .../accessibility/gtk/AccessibilityObjectAtk.cpp | 5 ++++ .../gtk/AccessibilityObjectWrapperAtk.cpp | 34 +++++++++++++++++----- 5 files changed, 59 insertions(+), 11 deletions(-) (limited to 'WebCore/accessibility') diff --git a/WebCore/accessibility/AccessibilityObject.cpp b/WebCore/accessibility/AccessibilityObject.cpp index a0959e6..b0ae86b 100644 --- a/WebCore/accessibility/AccessibilityObject.cpp +++ b/WebCore/accessibility/AccessibilityObject.cpp @@ -373,7 +373,24 @@ VisiblePositionRange AccessibilityObject::styleRangeForPosition(const VisiblePos // NOTE: Consider providing this utility method as AX API VisiblePositionRange AccessibilityObject::visiblePositionRangeForRange(const PlainTextRange& range) const { - if (range.start + range.length > text().length()) + unsigned textLength = text().length(); +#if PLATFORM(GTK) + // Gtk ATs need this for all text objects; not just text controls. + if (!textLength) { + Node* node = this->node(); + if (node) { + RenderText* renderText = toRenderText(node->renderer()); + if (renderText) + textLength = renderText->textLength(); + + // Get the text length from the elements under the + // accessibility object if not a RenderText object. + if (!textLength && allowsTextRanges()) + textLength = textUnderElement().length(); + } + } +#endif + if (range.start + range.length > textLength) return VisiblePositionRange(); VisiblePosition startPosition = visiblePositionForIndex(range.start); diff --git a/WebCore/accessibility/AccessibilityObject.h b/WebCore/accessibility/AccessibilityObject.h index b8b0875..c517855 100644 --- a/WebCore/accessibility/AccessibilityObject.h +++ b/WebCore/accessibility/AccessibilityObject.h @@ -571,6 +571,12 @@ protected: virtual void clearChildren(); virtual bool isDetached() const { return true; } +#if PLATFORM(GTK) + bool allowsTextRanges() const; +#else + bool allowsTextRanges() const { return isTextControl(); } +#endif + #if PLATFORM(MAC) RetainPtr m_wrapper; #elif PLATFORM(WIN) && !OS(WINCE) diff --git a/WebCore/accessibility/AccessibilityRenderObject.cpp b/WebCore/accessibility/AccessibilityRenderObject.cpp index 5144950..a5e1cc3 100644 --- a/WebCore/accessibility/AccessibilityRenderObject.cpp +++ b/WebCore/accessibility/AccessibilityRenderObject.cpp @@ -2393,8 +2393,8 @@ VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) co if (isNativeTextControl()) return toRenderTextControl(m_renderer)->visiblePositionForIndex(index); - - if (!isTextControl() && !m_renderer->isText()) + + if (!allowsTextRanges() && !m_renderer->isText()) return VisiblePosition(); Node* node = m_renderer->node(); @@ -2653,7 +2653,7 @@ String AccessibilityRenderObject::doAXStringForRange(const PlainTextRange& range // on the display screen, in pixels. IntRect AccessibilityRenderObject::doAXBoundsForRange(const PlainTextRange& range) const { - if (isTextControl()) + if (allowsTextRanges()) return boundsForVisiblePositionRange(visiblePositionRangeForRange(range)); return IntRect(); } diff --git a/WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp b/WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp index e32340a..d00574b 100644 --- a/WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp +++ b/WebCore/accessibility/gtk/AccessibilityObjectAtk.cpp @@ -93,6 +93,11 @@ void AccessibilityObject::setWrapper(AccessibilityObjectWrapper* wrapper) g_object_ref(m_wrapper); } +bool AccessibilityObject::allowsTextRanges() const +{ + return isTextControl() || isWebArea() || isGroup() || isLink() || isHeading(); +} + } // namespace WebCore #endif // HAVE(ACCESSIBILITY) diff --git a/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp b/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp index 3d7e712..716188a 100644 --- a/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp +++ b/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp @@ -1259,29 +1259,48 @@ static AtkAttributeSet* webkit_accessible_text_get_default_attributes(AtkText* t return getAttributeSetForAccessibilityObject(coreObject); } -static void webkit_accessible_text_get_character_extents(AtkText* text, gint offset, gint* x, gint* y, gint* width, gint* height, AtkCoordType coords) +static IntRect textExtents(AtkText* text, gint startOffset, gint length, AtkCoordType coords) { - IntRect extents = core(text)->doAXBoundsForRange(PlainTextRange(offset, 1)); - // FIXME: Use the AtkCoordType - // Requires WebCore::ScrollView::contentsToScreen() to be implemented + gchar* textContent = webkit_accessible_text_get_text(text, startOffset, -1); + gint textLength = g_utf8_strlen(textContent, -1); + + // The first case (endOffset of -1) should work, but seems broken for all Gtk+ apps. + gint rangeLength = length; + if (rangeLength < 0 || rangeLength > textLength) + rangeLength = textLength; + AccessibilityObject* coreObject = core(text); -#if 0 + IntRect extents = coreObject->doAXBoundsForRange(PlainTextRange(startOffset, rangeLength)); switch(coords) { case ATK_XY_SCREEN: - extents = core(text)->document()->view()->contentsToScreen(extents); + extents = coreObject->document()->view()->contentsToScreen(extents); break; case ATK_XY_WINDOW: // No-op break; } -#endif + return extents; +} + +static void webkit_accessible_text_get_character_extents(AtkText* text, gint offset, gint* x, gint* y, gint* width, gint* height, AtkCoordType coords) +{ + IntRect extents = textExtents(text, offset, 1, coords); *x = extents.x(); *y = extents.y(); *width = extents.width(); *height = extents.height(); } +static void webkit_accessible_text_get_range_extents(AtkText* text, gint startOffset, gint endOffset, AtkCoordType coords, AtkTextRectangle* rect) +{ + IntRect extents = textExtents(text, startOffset, endOffset - startOffset + 1, coords); + rect->x = extents.x(); + rect->y = extents.y(); + rect->width = extents.width(); + rect->height = extents.height(); +} + static gint webkit_accessible_text_get_character_count(AtkText* text) { AccessibilityObject* coreObject = core(text); @@ -1391,6 +1410,7 @@ static void atk_text_interface_init(AtkTextIface* iface) iface->get_run_attributes = webkit_accessible_text_get_run_attributes; iface->get_default_attributes = webkit_accessible_text_get_default_attributes; iface->get_character_extents = webkit_accessible_text_get_character_extents; + iface->get_range_extents = webkit_accessible_text_get_range_extents; iface->get_character_count = webkit_accessible_text_get_character_count; iface->get_offset_at_point = webkit_accessible_text_get_offset_at_point; iface->get_n_selections = webkit_accessible_text_get_n_selections; -- cgit v1.1