Changeset 268585 in webkit


Ignore:
Timestamp:
Oct 16, 2020 6:03:49 AM (4 years ago)
Author:
Andres Gonzalez
Message:

Refactor [WebAccessibilityObjectWrapper convertRectToSpace] so that the platform-specific code is in their corresponding AX object platform implementations.
https://bugs.webkit.org/show_bug.cgi?id=217785

Reviewed by Chris Fleizach.

No change in functionality, code refactor and cleanup.

[WebAccessibilityObjectWrapperBase convertRectToSpace] had two different
code paths for Mac and iOS, defeating the purpose of a base class.
This re-factoring Simplifies the wrapper code by moving the platform-
specific implementations to their corresponding AX object implementations
of convertRectToPlatformSpace.
Some code cleanup.

  • accessibility/AccessibilityObject.h:
  • accessibility/AccessibilityObjectInterface.h:
  • accessibility/ios/AccessibilityObjectIOS.mm:

(WebCore::AccessibilityObject::topDocumentFrameView const):
(WebCore::AccessibilityObject::convertRectToPlatformSpace const):

  • accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:

(-[WebAccessibilityObjectWrapper _accessibilityWebDocumentView]):

  • accessibility/isolatedtree/AXIsolatedObject.cpp:

(WebCore::AXIsolatedObject::convertRectToPlatformSpace const):

  • accessibility/isolatedtree/AXIsolatedObject.h:
  • accessibility/mac/AccessibilityObjectMac.mm:

(WebCore::AccessibilityObject::topDocumentFrameView const):
(WebCore::AccessibilityObject::convertRectToPlatformSpace const):

  • accessibility/mac/WebAccessibilityObjectWrapperBase.mm:

(-[WebAccessibilityObjectWrapperBase convertRectToSpace:space:]):

  • accessibility/mac/WebAccessibilityObjectWrapperMac.mm:

(-[WebAccessibilityObjectWrapper position]):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268579 r268585  
     12020-10-16  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        Refactor [WebAccessibilityObjectWrapper convertRectToSpace] so that the platform-specific code is in their corresponding AX object platform implementations.
     4        https://bugs.webkit.org/show_bug.cgi?id=217785
     5
     6        Reviewed by Chris Fleizach.
     7
     8        No change in functionality, code refactor and cleanup.
     9
     10        [WebAccessibilityObjectWrapperBase convertRectToSpace] had two different
     11        code paths for Mac and iOS, defeating the purpose of a base class.
     12        This re-factoring Simplifies the wrapper code by moving the platform-
     13        specific implementations to their corresponding AX object implementations
     14        of convertRectToPlatformSpace.
     15        Some code cleanup.
     16
     17        * accessibility/AccessibilityObject.h:
     18        * accessibility/AccessibilityObjectInterface.h:
     19        * accessibility/ios/AccessibilityObjectIOS.mm:
     20        (WebCore::AccessibilityObject::topDocumentFrameView const):
     21        (WebCore::AccessibilityObject::convertRectToPlatformSpace const):
     22        * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
     23        (-[WebAccessibilityObjectWrapper _accessibilityWebDocumentView]):
     24        * accessibility/isolatedtree/AXIsolatedObject.cpp:
     25        (WebCore::AXIsolatedObject::convertRectToPlatformSpace const):
     26        * accessibility/isolatedtree/AXIsolatedObject.h:
     27        * accessibility/mac/AccessibilityObjectMac.mm:
     28        (WebCore::AccessibilityObject::topDocumentFrameView const):
     29        (WebCore::AccessibilityObject::convertRectToPlatformSpace const):
     30        * accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
     31        (-[WebAccessibilityObjectWrapperBase convertRectToSpace:space:]):
     32        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
     33        (-[WebAccessibilityObjectWrapper position]):
     34
    1352020-10-16  Philippe Normand  <pnormand@igalia.com>
    236
  • trunk/Source/WebCore/accessibility/AccessibilityObject.h

    r268454 r268585  
    441441#if PLATFORM(COCOA)
    442442    RemoteAXObjectRef remoteParentObject() const override;
     443    FloatRect convertRectToPlatformSpace(const FloatRect&, AccessibilityConversionSpace) const override;
     444    NSView *topDocumentFrameView() const override;
    443445#endif
    444446    Widget* widgetForAttachmentView() const override { return nullptr; }
     
    730732#endif
    731733
    732 #if PLATFORM(COCOA) && !PLATFORM(IOS_FAMILY)
     734#if PLATFORM(MAC)
    733735    bool caretBrowsingEnabled() const override;
    734736    void setCaretBrowsingEnabled(bool) override;
  • trunk/Source/WebCore/accessibility/AccessibilityObjectInterface.h

    r268454 r268585  
    11811181#if PLATFORM(COCOA)
    11821182    virtual RemoteAXObjectRef remoteParentObject() const = 0;
     1183    virtual FloatRect convertRectToPlatformSpace(const FloatRect&, AccessibilityConversionSpace) const = 0;
     1184    virtual NSView *topDocumentFrameView() const = 0;
    11831185#endif
    11841186    virtual Widget* widgetForAttachmentView() const = 0;
     
    14681470#endif
    14691471
    1470 #if PLATFORM(COCOA) && !PLATFORM(IOS_FAMILY)
     1472#if PLATFORM(MAC)
    14711473    virtual bool caretBrowsingEnabled() const = 0;
    14721474    virtual void setCaretBrowsingEnabled(bool) = 0;
  • trunk/Source/WebCore/accessibility/ios/AccessibilityObjectIOS.mm

    r265645 r268585  
    3131#import "AccessibilityRenderObject.h"
    3232#import "EventNames.h"
     33#import "FrameView.h"
    3334#import "HTMLInputElement.h"
    3435#import "RenderObject.h"
     
    4546void AccessibilityObject::detachFromParent()
    4647{
     48}
     49
     50NSView *AccessibilityObject::topDocumentFrameView() const
     51{
     52    // This method performs the crucial task of connecting to the UIWebDocumentView.
     53    // This is needed to correctly calculate the screen position of the AX object.
     54    static Class webViewClass = nil;
     55    if (!webViewClass)
     56        webViewClass = NSClassFromString(@"WebView");
     57    if (!webViewClass)
     58        return nil;
     59
     60    auto* frameView = documentFrameView();
     61    if (!frameView)
     62        return nil;
     63
     64    // If this is the top level frame, the UIWebDocumentView should be returned.
     65    NSView *parentView = frameView->documentView();
     66    while (parentView && ![parentView isKindOfClass:webViewClass])
     67        parentView = [parentView superview];
     68
     69    // The parentView should have an accessibilityContainer, if the UIKit accessibility bundle was loaded.
     70    // The exception is DRT, which tests accessibility without the entire system turning accessibility on. Hence,
     71    // this check should be valid for everything except DRT.
     72    ASSERT([parentView accessibilityContainer] || IOSApplication::isDumpRenderTree());
     73
     74    return parentView;
     75}
     76
     77FloatRect AccessibilityObject::convertRectToPlatformSpace(const FloatRect& rect, AccessibilityConversionSpace space) const
     78{
     79    auto* frameView = documentFrameView();
     80    WAKView *documentView = frameView ? frameView->documentView() : nullptr;
     81    if (documentView) {
     82        CGPoint point = CGPointMake(rect.x(), rect.y());
     83        CGSize size = CGSizeMake(rect.size().width(), rect.size().height());
     84        CGRect cgRect = CGRectMake(point.x, point.y, size.width, size.height);
     85
     86        cgRect = [documentView convertRect:cgRect toView:nil];
     87
     88        // we need the web document view to give us our final screen coordinates
     89        // because that can take account of the scroller
     90        NSView *webDocument = topDocumentFrameView();
     91        if (webDocument)
     92            cgRect = [webDocument convertRect:cgRect toView:nil];
     93        return cgRect;
     94    }
     95
     96    return convertFrameToSpace(rect, space);
    4797}
    4898
  • trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm

    r268084 r268585  
    3838#import "ChromeClient.h"
    3939#import "FontCascade.h"
    40 #import "Frame.h"
    4140#import "FrameSelection.h"
    42 #import "FrameView.h"
    4341#import "HitTestResult.h"
    4442#import "HTMLFrameOwnerElement.h"
     
    17421740        return nil;
    17431741
    1744     // This method performs the crucial task of connecting to the UIWebDocumentView.
    1745     // This is needed to correctly calculate the screen position of the AX object.
    1746     static Class webViewClass = nil;
    1747     if (!webViewClass)
    1748         webViewClass = NSClassFromString(@"WebView");
    1749 
    1750     if (!webViewClass)
    1751         return nil;
    1752    
    1753     FrameView* frameView = self.axBackingObject->documentFrameView();
    1754 
    1755     if (!frameView)
    1756         return nil;
    1757    
    1758     // If this is the top level frame, the UIWebDocumentView should be returned.
    1759     id parentView = frameView->documentView();
    1760     while (parentView && ![parentView isKindOfClass:webViewClass])
    1761         parentView = [parentView superview];
    1762    
    1763     // The parentView should have an accessibilityContainer, if the UIKit accessibility bundle was loaded.
    1764     // The exception is DRT, which tests accessibility without the entire system turning accessibility on. Hence,
    1765     // this check should be valid for everything except DRT.
    1766     ASSERT([parentView accessibilityContainer] || IOSApplication::isDumpRenderTree());
    1767    
    1768     return [parentView accessibilityContainer];
     1742    return [(id)self.axBackingObject->topDocumentFrameView() accessibilityContainer];
    17691743}
    17701744
  • trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp

    r268541 r268585  
    966966}
    967967
     968FloatRect AXIsolatedObject::convertRectToPlatformSpace(const FloatRect& rect, AccessibilityConversionSpace space) const
     969{
     970    return Accessibility::retrieveValueFromMainThread<FloatRect>([&rect, &space, this] () -> FloatRect {
     971        if (auto* axObject = associatedAXObject())
     972            return axObject->convertRectToPlatformSpace(rect, space);
     973        return { };
     974    });
     975}
     976
    968977bool AXIsolatedObject::replaceTextInRange(const String& replacementText, const PlainTextRange& textRange)
    969978{
     
    11401149Optional<SimpleRange> AXIsolatedObject::elementRange() const
    11411150{
     1151    ASSERT(isMainThread());
    11421152    auto* axObject = associatedAXObject();
    11431153    return axObject ? axObject->elementRange() : WTF::nullopt;
  • trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h

    r268541 r268585  
    335335    String helpTextAttributeValue() const override { return stringAttributeValue(AXPropertyName::HelpText); }
    336336    String titleAttributeValue() const override { return stringAttributeValue(AXPropertyName::TitleAttributeValue); }
    337 #if PLATFORM(COCOA) && !PLATFORM(IOS_FAMILY)
     337#if PLATFORM(MAC)
    338338    bool caretBrowsingEnabled() const override { return boolAttributeValue(AXPropertyName::CaretBrowsingEnabled); }
    339339#endif
     
    444444    void setSelectedTextRange(const PlainTextRange&) override;
    445445    bool setValue(const String&) override;
    446 #if PLATFORM(COCOA) && !PLATFORM(IOS_FAMILY)
     446#if PLATFORM(MAC)
    447447    void setCaretBrowsingEnabled(bool) override;
    448448#endif
     
    580580#if PLATFORM(COCOA)
    581581    RemoteAXObjectRef remoteParentObject() const override;
     582    FloatRect convertRectToPlatformSpace(const FloatRect&, AccessibilityConversionSpace) const override;
     583    NSView *topDocumentFrameView() const override { return nil; } // FIXME: implement, currently only used on iOS.
    582584#endif
    583585    Widget* widgetForAttachmentView() const override;
  • trunk/Source/WebCore/accessibility/mac/AccessibilityObjectMac.mm

    r267878 r268585  
    2929#import "AccessibilityList.h"
    3030#import "ElementAncestorIterator.h"
     31#import "FrameView.h"
    3132#import "HTMLFieldSetElement.h"
    3233#import "HTMLInputElement.h"
     
    6869    [[wrapper() attachmentView] accessibilitySetOverrideValue:parentWrapper forAttribute:NSAccessibilityParentAttribute];
    6970    ALLOW_DEPRECATED_DECLARATIONS_END
     71}
     72
     73NSView *AccessibilityObject::topDocumentFrameView() const
     74{
     75    // FIXME: implement, currently only used on iOS.
     76    return nil;
     77}
     78
     79FloatRect AccessibilityObject::convertRectToPlatformSpace(const FloatRect& rect, AccessibilityConversionSpace space) const
     80{
     81    // WebKit1 code path... platformWidget() exists.
     82    auto* frameView = documentFrameView();
     83    if (frameView && frameView->platformWidget()) {
     84        CGPoint point = CGPointMake(rect.x(), rect.y());
     85        CGSize size = CGSizeMake(rect.size().width(), rect.size().height());
     86        CGRect cgRect = CGRectMake(point.x, point.y, size.width, size.height);
     87
     88        NSRect nsRect = NSRectFromCGRect(cgRect);
     89        NSView *view = frameView->documentView();
     90        ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     91        nsRect = [[view window] convertRectToScreen:[view convertRect:nsRect toView:nil]];
     92        ALLOW_DEPRECATED_DECLARATIONS_END
     93        return NSRectToCGRect(nsRect);
     94    }
     95
     96    return convertFrameToSpace(rect, space);
    7097}
    7198
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm

    r265311 r268585  
    5151#import "Font.h"
    5252#import "FontCascade.h"
    53 #import "Frame.h"
    54 #import "FrameLoaderClient.h"
    5553#import "FrameSelection.h"
    5654#import "HTMLNames.h"
     
    6462#import "TextCheckerClient.h"
    6563#import "VisibleUnits.h"
    66 #import "WebCoreFrameView.h"
    6764#import <wtf/cocoa/VectorCocoa.h>
    6865
    6966#if PLATFORM(MAC)
    7067#import "WebAccessibilityObjectWrapperMac.h"
    71 #import <pal/spi/mac/HIServicesSPI.h>
    7268#else
    73 #import "WAKView.h"
    74 #import "WAKWindow.h"
    7569#import "WebAccessibilityObjectWrapperIOS.h"
    7670#endif
     
    464458- (CGRect)convertRectToSpace:(const WebCore::FloatRect&)rect space:(AccessibilityConversionSpace)space
    465459{
    466     if (!self.axBackingObject)
     460    auto* backingObject = self.axBackingObject;
     461    if (!backingObject)
    467462        return CGRectZero;
    468    
    469     CGSize size = CGSizeMake(rect.size().width(), rect.size().height());
    470     CGPoint point = CGPointMake(rect.x(), rect.y());
    471    
    472     CGRect cgRect = CGRectMake(point.x, point.y, size.width, size.height);
    473 
    474     // WebKit1 code path... platformWidget() exists.
    475     FrameView* frameView = self.axBackingObject->documentFrameView();
    476 #if PLATFORM(IOS_FAMILY)
    477     WAKView* documentView = frameView ? frameView->documentView() : nullptr;
    478     if (documentView) {
    479         cgRect = [documentView convertRect:cgRect toView:nil];
    480        
    481         // we need the web document view to give us our final screen coordinates
    482         // because that can take account of the scroller
    483         id webDocument = [self _accessibilityWebDocumentView];
    484         if (webDocument)
    485             cgRect = [webDocument convertRect:cgRect toView:nil];
    486         return cgRect;
    487     }
    488 #else
    489     if (frameView && frameView->platformWidget()) {
    490         NSRect nsRect = NSRectFromCGRect(cgRect);
    491         NSView* view = frameView->documentView();
    492         ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    493         nsRect = [[view window] convertRectToScreen:[view convertRect:nsRect toView:nil]];
    494         ALLOW_DEPRECATED_DECLARATIONS_END
    495         return NSRectToCGRect(nsRect);
    496     }
    497 #endif
    498     else
    499         return static_cast<CGRect>(self.axBackingObject->convertFrameToSpace(rect, space));
     463
     464    return backingObject->convertRectToPlatformSpace(rect, space);
    500465}
    501466
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

    r268541 r268585  
    19761976
    19771977    // The Cocoa accessibility API wants the lower-left corner.
    1978     auto floatPoint = FloatPoint(rect.x(), rect.maxY());
    1979 
    1980     auto floatRect = FloatRect(floatPoint, FloatSize());
    1981     CGPoint cgPoint = [self convertRectToSpace:floatRect space:AccessibilityConversionSpace::Screen].origin;
    1982     return [NSValue valueWithPoint:NSPointFromCGPoint(cgPoint)];
     1978    FloatPoint floatPoint(rect.x(), rect.maxY());
     1979
     1980    // FIXME: add a function to convert a point, no need to convert a rect when you only need a point.
     1981    FloatRect floatRect(floatPoint, FloatSize());
     1982    CGRect cgRect(backingObject->convertRectToPlatformSpace(floatRect, AccessibilityConversionSpace::Screen));
     1983    return @(cgRect.origin);
    19831984}
    19841985
Note: See TracChangeset for help on using the changeset viewer.