Skip to content
Permalink
Browse files
[Gtk] Regression: text-inserted events lack text inserted and current…
… line

https://bugs.webkit.org/show_bug.cgi?id=72830

Reviewed by Martin Robinson.

Source/WebCore:

Fix issue getting the exposed text for an accessibility object at,
before of after a given offset, after changing it at least once.

* accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
(webkit_accessible_class_init): Don't initialize
gailTextUtilQuark, it won't be used anymore.
(getGailTextUtilForAtk): Don't cache the GailTextUtil as object
data, but create a new one each time this function is called.
(webkit_accessible_text_get_caret_offset): Simplified code by
using the new focusedObjectAndCaretOffsetUnignored function,
instead of the old objectAndOffsetUnignored function.
(focusedObjectAndCaretOffsetUnignored): Rewrite of the old
objectAndOffsetUnignored function so it now needs less
parameters than before and takes care of carefully selecting the
start and end visible positions to calculate the position of the
caret from the point of view of the accessibility object of
reference passed as the only input parameter now. Updated callers.
* accessibility/gtk/AccessibilityObjectWrapperAtk.h:

* editing/gtk/FrameSelectionGtk.cpp:
(WebCore::FrameSelection::notifyAccessibilityForSelectionChange):
Simplified code by calling to focusedObjectAndCaretOffsetUnignored
function, instead of the old objectAndOffsetUnignored function.

Source/WebKit/gtk:

Updated unit tests to check that both getting the current position
for the caret and the exposed text at, before or after a given
offset for an accessible object works as expected.

* tests/testatk.c:
(runGetTextTests): For objects implementing AtkEditableText, try
to change the exposed text and retrieve it again as a full line.
(testWebkitAtkCaretOffsets): For a text control (a text entry),
set the caret offset to a value greater than 1 and retrieve it.

Canonical link: https://commits.webkit.org/92646@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@104446 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
mariospr committed Jan 9, 2012
1 parent 625a6f6 commit 7bf217720a8c0b6ba8ea7fb6219994a9e5f10f87
@@ -1,3 +1,34 @@
2012-01-09 Mario Sanchez Prada <msanchez@igalia.com>

[Gtk] Regression: text-inserted events lack text inserted and current line
https://bugs.webkit.org/show_bug.cgi?id=72830

Reviewed by Martin Robinson.

Fix issue getting the exposed text for an accessibility object at,
before of after a given offset, after changing it at least once.

* accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
(webkit_accessible_class_init): Don't initialize
gailTextUtilQuark, it won't be used anymore.
(getGailTextUtilForAtk): Don't cache the GailTextUtil as object
data, but create a new one each time this function is called.
(webkit_accessible_text_get_caret_offset): Simplified code by
using the new focusedObjectAndCaretOffsetUnignored function,
instead of the old objectAndOffsetUnignored function.
(focusedObjectAndCaretOffsetUnignored): Rewrite of the old
objectAndOffsetUnignored function so it now needs less
parameters than before and takes care of carefully selecting the
start and end visible positions to calculate the position of the
caret from the point of view of the accessibility object of
reference passed as the only input parameter now. Updated callers.
* accessibility/gtk/AccessibilityObjectWrapperAtk.h:

* editing/gtk/FrameSelectionGtk.cpp:
(WebCore::FrameSelection::notifyAccessibilityForSelectionChange):
Simplified code by calling to focusedObjectAndCaretOffsetUnignored
function, instead of the old objectAndOffsetUnignored function.

2012-01-09 Antti Koivisto <antti@apple.com>

Subtree invalidation on stylesheet change
@@ -76,7 +76,6 @@

using namespace WebCore;

static GQuark gailTextUtilQuark = 0;
static GQuark hyperlinkObjectQuark = 0;

static AccessibilityObject* fallbackObject()
@@ -846,7 +845,6 @@ static void webkit_accessible_class_init(AtkObjectClass* klass)
klass->get_attributes = webkit_accessible_get_attributes;
klass->ref_relation_set = webkit_accessible_ref_relation_set;

gailTextUtilQuark = g_quark_from_static_string("webkit-accessible-gail-text-util");
hyperlinkObjectQuark = g_quark_from_static_string("webkit-accessible-hyperlink-object");
}

@@ -1293,13 +1291,8 @@ static gchar* webkit_accessible_text_get_text(AtkText* text, gint startOffset, g

static GailTextUtil* getGailTextUtilForAtk(AtkText* textObject)
{
gpointer data = g_object_get_qdata(G_OBJECT(textObject), gailTextUtilQuark);
if (data)
return static_cast<GailTextUtil*>(data);

GailTextUtil* gailTextUtil = gail_text_util_new();
gail_text_util_text_setup(gailTextUtil, webkit_accessible_text_get_text(textObject, 0, -1));
g_object_set_qdata_full(G_OBJECT(textObject), gailTextUtilQuark, gailTextUtil, g_object_unref);
return gailTextUtil;
}

@@ -1352,20 +1345,8 @@ static gint webkit_accessible_text_get_caret_offset(AtkText* text)
if (!coreObject->isAccessibilityRenderObject())
return 0;

Document* document = coreObject->document();
if (!document)
return 0;

Node* focusedNode = coreObject->selection().end().deprecatedNode();
if (!focusedNode)
return 0;

RenderObject* focusedRenderer = focusedNode->renderer();
AccessibilityObject* focusedObject = document->axObjectCache()->getOrCreate(focusedRenderer);

int offset;
// Don't ignore links if the offset is being requested for a link.
if (!objectAndOffsetUnignored(focusedObject, offset, !coreObject->isLink()))
if (!objectFocusedAndCaretOffsetUnignored(coreObject, offset))
return 0;

RenderObject* renderer = coreObject->renderer();
@@ -2733,40 +2714,67 @@ AtkObject* webkit_accessible_get_focused_element(WebKitAccessible* accessible)
return focusedObj->wrapper();
}

AccessibilityObject* objectAndOffsetUnignored(AccessibilityObject* coreObject, int& offset, bool ignoreLinks)
AccessibilityObject* objectFocusedAndCaretOffsetUnignored(AccessibilityObject* referenceObject, int& offset)
{
// Indication that something bogus has transpired.
offset = -1;

AccessibilityObject* realObject = coreObject;
if (realObject->accessibilityIsIgnored())
realObject = realObject->parentObjectUnignored();
if (!realObject)
Document* document = referenceObject->document();
if (!document)
return 0;

Node* focusedNode = referenceObject->selection().end().containerNode();
if (!focusedNode)
return 0;

if (ignoreLinks && realObject->isLink())
realObject = realObject->parentObjectUnignored();
if (!realObject)
RenderObject* focusedRenderer = focusedNode->renderer();
if (!focusedRenderer)
return 0;

Node* node = realObject->node();
if (node) {
VisiblePosition startPosition = VisiblePosition(positionBeforeNode(node), DOWNSTREAM);
VisiblePosition endPosition = realObject->selection().visibleEnd();
AccessibilityObject* focusedObject = document->axObjectCache()->getOrCreate(focusedRenderer);
if (!focusedObject)
return 0;

if (startPosition == endPosition)
offset = 0;
else if (!isStartOfLine(endPosition)) {
RefPtr<Range> range = makeRange(startPosition, endPosition.previous());
offset = TextIterator::rangeLength(range.get(), true) + 1;
} else {
RefPtr<Range> range = makeRange(startPosition, endPosition);
offset = TextIterator::rangeLength(range.get(), true);
}
// Look for the actual (not ignoring accessibility) selected object.
if (focusedObject->accessibilityIsIgnored())
focusedObject = focusedObject->parentObjectUnignored();
if (!focusedObject)
return 0;

// Don't ignore links if the offset is being requested for a link.
if (!referenceObject->isLink() && focusedObject->isLink())
focusedObject = focusedObject->parentObjectUnignored();
if (!focusedObject)
return 0;

Node* startNode = 0;
if (focusedObject != referenceObject || focusedObject->isTextControl()) {
// We need to use the first child's node of the reference
// object as the start point to calculate the caret offset
// because we want it to be relative to the object of
// reference, not just to the focused object (which could have
// previous siblings which should be taken into account too).
AccessibilityObject* axFirstChild = referenceObject->firstChild();
if (axFirstChild)
startNode = axFirstChild->node();
}
if (!startNode)
startNode = focusedObject->node();

VisiblePosition startPosition = VisiblePosition(firstPositionInNode(startNode), DOWNSTREAM);
VisiblePosition endPosition = focusedObject->selection().visibleEnd();

if (startPosition == endPosition)
offset = 0;
else if (!isStartOfLine(endPosition)) {
RefPtr<Range> range = makeRange(startPosition, endPosition.previous());
offset = TextIterator::rangeLength(range.get(), true) + 1;
} else {
RefPtr<Range> range = makeRange(startPosition, endPosition);
offset = TextIterator::rangeLength(range.get(), true);
}

return realObject;
return focusedObject;
}

#endif // HAVE(ACCESSIBILITY)
@@ -60,7 +60,7 @@ void webkit_accessible_detach (WebKitAccessible* accessible);

AtkObject* webkit_accessible_get_focused_element(WebKitAccessible* accessible);

WebCore::AccessibilityObject* objectAndOffsetUnignored(WebCore::AccessibilityObject* coreObject, int& offset, bool ignoreLinks);
WebCore::AccessibilityObject* objectFocusedAndCaretOffsetUnignored(WebCore::AccessibilityObject*, int& offset);

G_END_DECLS

@@ -80,20 +80,17 @@ void FrameSelection::notifyAccessibilityForSelectionChange()
if (!AXObjectCache::accessibilityEnabled())
return;

// Reset lastFocuseNode and return for no valid selections.
// Return for no valid selections.
if (!m_selection.start().isNotNull() || !m_selection.end().isNotNull())
return;

RenderObject* focusedNode = m_selection.end().deprecatedNode()->renderer();
AccessibilityObject* accessibilityObject = m_frame->document()->axObjectCache()->getOrCreate(focusedNode);

// Need to check this as getOrCreate could return 0,
// Look for the accessibility object for the Frame.
AccessibilityObject* accessibilityObject = m_frame->document()->axObjectCache()->rootObjectForFrame(m_frame);
if (!accessibilityObject)
return;

int offset;
// Always report the events w.r.t. the non-linked unignored parent. (i.e. ignoreLinks == true).
RefPtr<AccessibilityObject> object = objectAndOffsetUnignored(accessibilityObject, offset, true);
RefPtr<AccessibilityObject> object = objectFocusedAndCaretOffsetUnignored(accessibilityObject, offset);
if (!object)
return;

@@ -1,3 +1,20 @@
2012-01-09 Mario Sanchez Prada <msanchez@igalia.com>

[Gtk] Regression: text-inserted events lack text inserted and current line
https://bugs.webkit.org/show_bug.cgi?id=72830

Reviewed by Martin Robinson.

Updated unit tests to check that both getting the current position
for the caret and the exposed text at, before or after a given
offset for an accessible object works as expected.

* tests/testatk.c:
(runGetTextTests): For objects implementing AtkEditableText, try
to change the exposed text and retrieve it again as a full line.
(testWebkitAtkCaretOffsets): For a text control (a text entry),
set the caret offset to a value greater than 1 and retrieve it.

2012-01-05 Martin Robinson <mrobinson@igalia.com>

[GTK] [AC] Introduce AcceleratedCompositingContext to isolate different accelerated compositing implementations
@@ -63,7 +63,7 @@ static const char* linksWithInlineImages = "<html><head><style>a.http:before {co

static const char* listsOfItems = "<html><body><ul><li>text only</li><li><a href='foo'>link only</a></li><li>text and a <a href='bar'>link</a></li></ul><ol><li>text only</li><li><a href='foo'>link only</a></li><li>text and a <a href='bar'>link</a></li></ol></body></html>";

static const char* textForCaretBrowsing = "<html><body><h1>A text header</h1><p>A paragraph <a href='http://foo.bar.baz/'>with a link</a> in the middle</p><ol><li>A list item</li></ol><select><option selected value='foo'>An option in a combo box</option></select></body></html>";
static const char* textForCaretBrowsing = "<html><body><h1>A text header</h1><p>A paragraph <a href='http://foo.bar.baz/'>with a link</a> in the middle</p><ol><li>A list item</li></ol><select><option selected value='foo'>An option in a combo box</option></select><input type='text'' name='foo'' value='foo bar baz' /></body></html>";

static const char* textForSelections = "<html><body><p>A paragraph with plain text</p><p>A paragraph with <a href='http://webkit.org'>a link</a> in the middle</p><ol><li>A list item</li></ol><select></body></html>";

@@ -234,7 +234,7 @@ static void runGetTextTests(AtkText* textObject)
testGetTextFunction(textObject, atk_text_get_text_before_offset, ATK_TEXT_BOUNDARY_SENTENCE_END,
44, " This is the second sentence.", 15, 44);

/* It's trick to test these properly right now, since our a11y
/* It's tricky to test these properly right now, since our a11y
implementation splits different lines in different a11y items. */
/* ATK_TEXT_BOUNDARY_LINE_START */
testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START,
@@ -243,6 +243,15 @@ static void runGetTextTests(AtkText* textObject)
/* ATK_TEXT_BOUNDARY_LINE_END */
testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END,
0, "This is a test. This is the second sentence. And this the third.", 0, 64);

/* For objects implementing AtkEditableText, try to change the
exposed text and retrieve it again as a full line.
(see https://bugs.webkit.org/show_bug.cgi?id=72830) */
if (ATK_IS_EDITABLE_TEXT(textObject)) {
atk_editable_text_set_text_contents(ATK_EDITABLE_TEXT(textObject), "foo bar baz");
testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 0, "foo bar baz", 0, 11);
testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 0, "foo bar baz", 0, 11);
}
}

static void testWebkitAtkCaretOffsets()
@@ -334,6 +343,18 @@ static void testWebkitAtkCaretOffsets()
result = atk_text_set_caret_offset(ATK_TEXT(comboBoxOption), 1);
g_assert_cmpint(result, ==, FALSE);

AtkObject* textEntry = atk_object_ref_accessible_child(panel, 1);
g_assert(ATK_IS_OBJECT(textEntry));
g_assert(atk_object_get_role(textEntry) == ATK_ROLE_ENTRY);
g_assert(ATK_IS_TEXT(textEntry));
text = atk_text_get_text(ATK_TEXT(textEntry), 0, -1);
g_assert_cmpstr(text, ==, "foo bar baz");

result = atk_text_set_caret_offset(ATK_TEXT(textEntry), 5);
g_assert_cmpint(result, ==, TRUE);
offset = atk_text_get_caret_offset(ATK_TEXT(textEntry));
g_assert_cmpint(offset, ==, 5);

g_object_unref(header);
g_object_unref(paragraph);
g_object_unref(list);
@@ -342,6 +363,7 @@ static void testWebkitAtkCaretOffsets()
g_object_unref(comboBox);
g_object_unref(menuPopup);
g_object_unref(comboBoxOption);
g_object_unref(textEntry);
g_object_unref(webView);
}

0 comments on commit 7bf2177

Please sign in to comment.