Reviewed by Darin.
authorharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Aug 2006 15:54:41 +0000 (15:54 +0000)
committerharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Aug 2006 15:54:41 +0000 (15:54 +0000)
        <rdar://problem/3942647> Support AXStyleTextMarkerRangeForTextMarker parameterized attribute

        * bridge/mac/WebCoreAXObject.mm:
        (-[WebCoreAXObject accessibilityParameterizedAttributeNames]):
        Add AXStyleTextMarkerRangeForTextMarker.

        (startOfStyleRange):
        (endOfStyleRange):
        Return first/last VisiblePosition in range having the same style has the specified VisiblePosition.

        (-[WebCoreAXObject doAXStyleTextMarkerRangeForTextMarker:]):
        Return AXTextMarkerRange for startOfStyleRange/endOfStyleRange of the specified AXTextMarker.

        (-[WebCoreAXObject accessibilityAttributeValue:forParameter:]):
        Call doAXStyleTextMarkerRangeForTextMarker for AXStyleTextMarkerRangeForTextMarker.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16072 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bridge/mac/WebCoreAXObject.mm

index 33fa7ce814821f51a08b5498a1fb9891e7b5b199..0e98cea347de62b552ee451daa60b2af559d235d 100644 (file)
@@ -1,4 +1,24 @@
-2006-08-25  David Harrison  <harrison@apple.com>
+2006-08-28  David Harrison  <harrison@apple.com>
+
+        Reviewed by Darin.
+
+        <rdar://problem/3942647> Support AXStyleTextMarkerRangeForTextMarker parameterized attribute
+
+        * bridge/mac/WebCoreAXObject.mm:
+        (-[WebCoreAXObject accessibilityParameterizedAttributeNames]):
+        Add AXStyleTextMarkerRangeForTextMarker.
+        
+        (startOfStyleRange):
+        (endOfStyleRange):
+        Return first/last VisiblePosition in range having the same style has the specified VisiblePosition.
+
+        (-[WebCoreAXObject doAXStyleTextMarkerRangeForTextMarker:]):
+        Return AXTextMarkerRange for startOfStyleRange/endOfStyleRange of the specified AXTextMarker.
+        
+        (-[WebCoreAXObject accessibilityAttributeValue:forParameter:]):
+        Call doAXStyleTextMarkerRangeForTextMarker for AXStyleTextMarkerRangeForTextMarker.
+
+2006-08-28  David Harrison  <harrison@apple.com>
 
         Reviewed by Darin.
 
index f27124268a85d9581076d160d01280efde19dab8..73639bd997d3bc0448b242db45111b3f8daad651 100644 (file)
@@ -1060,6 +1060,7 @@ static IntRect boundingBoxRect(RenderObject* obj)
             @"AXPreviousSentenceStartTextMarkerForTextMarker",
             @"AXNextParagraphEndTextMarkerForTextMarker",
             @"AXPreviousParagraphStartTextMarkerForTextMarker",
+            @"AXStyleTextMarkerRangeForTextMarker",
             @"AXLengthForTextMarkerRange",
             nil];
     }
@@ -1778,6 +1779,63 @@ static void AXAttributedStringAppendReplaced (NSMutableAttributedString* attrStr
     return (id) [self textMarkerForVisiblePosition: startPosition];
 }
 
+static VisiblePosition startOfStyleRange (const VisiblePosition visiblePos)
+{
+    RenderObject* renderer = visiblePos.deepEquivalent().node()->renderer();
+    RenderObject* startRenderer = renderer;
+    RenderStyle* style = renderer->style();
+    
+    // traverse backward by renderer to look for style change
+    for (RenderObject* r = renderer->previousInPreOrder(); r; r = r->previousInPreOrder()) {
+        // skip non-leaf nodes
+        if (r->firstChild())
+            continue;
+        
+        // stop at style change
+        if (r->style() != style)
+            break;
+            
+        // remember match
+        startRenderer = r;
+    }
+    
+    return VisiblePosition(startRenderer->node(), 0, VP_DEFAULT_AFFINITY);
+}
+
+static VisiblePosition endOfStyleRange (const VisiblePosition visiblePos)
+{
+    RenderObject* renderer = visiblePos.deepEquivalent().node()->renderer();
+    RenderObject* endRenderer = renderer;
+    RenderStyle* style = renderer->style();
+
+    // traverse forward by renderer to look for style change
+    for (RenderObject* r = renderer->nextInPreOrder(); r; r = r->nextInPreOrder()) {
+        // skip non-leaf nodes
+        if (r->firstChild())
+            continue;
+        
+        // stop at style change
+        if (r->style() != style)
+            break;
+        
+        // remember match
+        endRenderer = r;
+    }
+    
+    return VisiblePosition(endRenderer->node(), maxDeepOffset(endRenderer->node()), VP_DEFAULT_AFFINITY);
+}
+
+- (id)doAXStyleTextMarkerRangeForTextMarker: (WebCoreTextMarker*) textMarker
+{
+    VisiblePosition visiblePos = [self visiblePositionForTextMarker:textMarker];
+    if (visiblePos.isNull())
+        return nil;
+
+    VisiblePosition startPosition = startOfStyleRange(visiblePos);
+    VisiblePosition endPosition = endOfStyleRange(visiblePos);
+    return (id) [self textMarkerRangeFromVisiblePositions:startPosition andEndPos:endPosition];
+}
+
 - (id)doAXLengthForTextMarkerRange: (WebCoreTextMarkerRange*) textMarkerRange
 {
     // NOTE: BUG Multi-byte support
@@ -1906,7 +1964,10 @@ static void AXAttributedStringAppendReplaced (NSMutableAttributedString* attrStr
 
     if ([attribute isEqualToString: @"AXPreviousParagraphStartTextMarkerForTextMarker"])
         return [self doAXPreviousParagraphStartTextMarkerForTextMarker: textMarker];
-        
+    
+    if ([attribute isEqualToString: @"AXStyleTextMarkerRangeForTextMarker"])
+        return [self doAXStyleTextMarkerRangeForTextMarker: textMarker];
+    
     if ([attribute isEqualToString: @"AXLengthForTextMarkerRange"])
         return [self doAXLengthForTextMarkerRange: textMarkerRange];