Text manipulation should not aggregate text from different navigation anchor elements
https://bugs.webkit.org/show_bug.cgi?id=211081
<rdar://problem/59553658>
Reviewed by Megan Gardner.
Source/WebCore:
Tweak the item boundary heuristic in `TextManipulationController::observeParagraphs` to separate text in
links and list items under navigation elements (either nav elements, or elements with the "navigation"
accessibility role) into separate paragraphs.
Also, extend the item boundary rule for button elements to apply to elements with the "button"
accessibility role as well.
Test: TextManipulation.StartTextManipulationTreatsInlineBlockLinksAndButtonsAsParagraphs
TextManipulation.StartTextManipulationTreatsLinksInNavigationElementsAsParagraphs
* editing/TextManipulationController.cpp:
(WebCore::TextManipulationController::observeParagraphs):
Tools:
Add a new API test, and augment an existing test.
* TestWebKitAPI/Tests/WebKitCocoa/TextManipulation.mm:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@260783 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/editing/TextManipulationController.cpp b/Source/WebCore/editing/TextManipulationController.cpp
index 7e444d0..50faf28 100644
--- a/Source/WebCore/editing/TextManipulationController.cpp
+++ b/Source/WebCore/editing/TextManipulationController.cpp
@@ -26,6 +26,7 @@
#include "config.h"
#include "TextManipulationController.h"
+#include "AccessibilityObject.h"
#include "CharacterData.h"
#include "Editing.h"
#include "ElementAncestorIterator.h"
@@ -281,12 +282,22 @@
if (!renderer)
return false;
- if (element.hasTagName(HTMLNames::buttonTag))
+ auto role = [](const Element& element) -> AccessibilityRole {
+ return AccessibilityObject::ariaRoleToWebCoreRole(element.attributeWithoutSynchronization(HTMLNames::roleAttr));
+ };
+
+ if (element.hasTagName(HTMLNames::buttonTag) || role(element) == AccessibilityRole::Button)
return true;
if (element.hasTagName(HTMLNames::liTag) || element.hasTagName(HTMLNames::aTag)) {
auto displayType = renderer->style().display();
- return displayType == DisplayType::Block || displayType == DisplayType::InlineBlock;
+ if (displayType == DisplayType::Block || displayType == DisplayType::InlineBlock)
+ return true;
+
+ for (auto parent = makeRefPtr(element.parentElement()); parent; parent = parent->parentElement()) {
+ if (parent->hasTagName(HTMLNames::navTag) || role(*parent) == AccessibilityRole::LandmarkNavigation)
+ return true;
+ }
}
return false;