⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 248438 in webkit


Ignore:
Timestamp:
Aug 8, 2019, 12:13:11 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

[iOS] Position image information should respect the image orientation
https://bugs.webkit.org/show_bug.cgi?id=200487

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-08
Reviewed by Simon Fraser.

Source/WebCore:

Re-factor CachedImage::imageSizeForRenderer() into another overriding
function which does not scale the imageSize. Therefore the new function
returns FloatSize while the original function returns LayoutSize.

  • loader/cache/CachedImage.cpp:

(WebCore::CachedImage::imageSizeForRenderer const):

  • loader/cache/CachedImage.h:
  • rendering/RenderElement.h:

Source/WebKit:

imagePositionInformation() should respect the image orientation when
drawing an Image to a ShareableBitmap context.

boundsPositionInformation() already takes care of the image orientation
because it gets RenderImage::enclosingBoundingBox().

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::imagePositionInformation):

Tools:

Add an API test to verify the position image information is drawn rotated
because of respecting its image orientation.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/exif-orientation-8-llo.jpg: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/img-with-rotated-image.html: Added.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248434 r248438  
     12019-08-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        [iOS] Position image information should respect the image orientation
     4        https://bugs.webkit.org/show_bug.cgi?id=200487
     5
     6        Reviewed by Simon Fraser.
     7
     8        Re-factor CachedImage::imageSizeForRenderer() into another overriding
     9        function which does not scale the imageSize. Therefore the new function
     10        returns FloatSize while the original function returns LayoutSize.
     11
     12        * loader/cache/CachedImage.cpp:
     13        (WebCore::CachedImage::imageSizeForRenderer const):
     14        * loader/cache/CachedImage.h:
     15        * rendering/RenderElement.h:
     16
    1172019-08-08  Devin Rousso  <drousso@apple.com>
    218
  • trunk/Source/WebCore/loader/cache/CachedImage.cpp

    r240014 r248438  
    276276}
    277277
    278 LayoutSize CachedImage::imageSizeForRenderer(const RenderElement* renderer, float multiplier, SizeType sizeType)
     278FloatSize CachedImage::imageSizeForRenderer(const RenderElement* renderer, SizeType sizeType) const
    279279{
    280280    if (!m_image)
    281         return LayoutSize();
    282 
    283     LayoutSize imageSize;
     281        return { };
    284282
    285283    if (is<BitmapImage>(*m_image) && renderer && renderer->shouldRespectImageOrientation() == RespectImageOrientation)
    286         imageSize = LayoutSize(downcast<BitmapImage>(*m_image).sizeRespectingOrientation());
    287     else if (is<SVGImage>(*m_image) && sizeType == UsedSize)
    288         imageSize = LayoutSize(m_svgImageCache->imageSizeForRenderer(renderer));
    289     else
    290         imageSize = LayoutSize(m_image->size());
    291 
    292     if (multiplier == 1.0f)
     284        return downcast<BitmapImage>(*m_image).sizeRespectingOrientation();
     285
     286    if (is<SVGImage>(*m_image) && sizeType == UsedSize)
     287        return m_svgImageCache->imageSizeForRenderer(renderer);
     288
     289    return m_image->size();
     290}
     291
     292LayoutSize CachedImage::imageSizeForRenderer(const RenderElement* renderer, float multiplier, SizeType sizeType) const
     293{
     294    LayoutSize imageSize = LayoutSize(imageSizeForRenderer(renderer, sizeType));
     295    if (imageSize.isEmpty() || multiplier == 1.0f)
    293296        return imageSize;
    294        
     297
    295298    // Don't let images that have a width/height >= 1 shrink below 1 when zoomed.
    296299    float widthScale = m_image->hasRelativeWidth() ? 1.0f : multiplier;
  • trunk/Source/WebCore/loader/cache/CachedImage.h

    r240014 r248438  
    7676        IntrinsicSize
    7777    };
     78    WEBCORE_EXPORT FloatSize imageSizeForRenderer(const RenderElement* renderer, SizeType = UsedSize) const;
    7879    // This method takes a zoom multiplier that can be used to increase the natural size of the image by the zoom.
    79     LayoutSize imageSizeForRenderer(const RenderElement*, float multiplier, SizeType = UsedSize); // returns the size of the complete image.
     80    LayoutSize imageSizeForRenderer(const RenderElement*, float multiplier, SizeType = UsedSize) const; // returns the size of the complete image.
    8081    void computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio);
    8182
  • trunk/Source/WebCore/rendering/RenderElement.h

    r245543 r248438  
    205205    RenderBlock* containingBlockForAbsolutePosition() const;
    206206
    207     RespectImageOrientationEnum shouldRespectImageOrientation() const;
     207    WEBCORE_EXPORT RespectImageOrientationEnum shouldRespectImageOrientation() const;
    208208
    209209    void removeFromRenderFragmentedFlow();
  • trunk/Source/WebKit/ChangeLog

    r248436 r248438  
     12019-08-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        [iOS] Position image information should respect the image orientation
     4        https://bugs.webkit.org/show_bug.cgi?id=200487
     5
     6        Reviewed by Simon Fraser.
     7
     8        imagePositionInformation() should respect the image orientation when
     9        drawing an Image to a ShareableBitmap context.
     10
     11        boundsPositionInformation() already takes care of the image orientation
     12        because it gets RenderImage::enclosingBoundingBox().
     13
     14        * WebProcess/WebPage/ios/WebPageIOS.mm:
     15        (WebKit::imagePositionInformation):
     16
    1172019-08-08  Timothy Hatcher  <timothy@apple.com>
    218
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r247926 r248438  
    26212621
    26222622    FloatSize screenSizeInPixels = screenSize();
     2623    FloatSize imageSize = renderImage.cachedImage()->imageSizeForRenderer(&renderImage);
     2624   
    26232625    screenSizeInPixels.scale(page.corePage()->deviceScaleFactor());
    2624     FloatSize scaledSize = largestRectWithAspectRatioInsideRect(image->size().width() / image->size().height(), FloatRect(0, 0, screenSizeInPixels.width(), screenSizeInPixels.height())).size();
    2625     FloatSize bitmapSize = scaledSize.width() < image->size().width() ? scaledSize : image->size();
     2626    FloatSize scaledSize = largestRectWithAspectRatioInsideRect(imageSize.width() / imageSize.height(), FloatRect(0, 0, screenSizeInPixels.width(), screenSizeInPixels.height())).size();
     2627    FloatSize bitmapSize = scaledSize.width() < imageSize.width() ? scaledSize : imageSize;
     2628   
    26262629    // FIXME: Only select ExtendedColor on images known to need wide gamut
    26272630    ShareableBitmap::Configuration bitmapConfiguration;
     
    26362639        return;
    26372640
    2638     graphicsContext->drawImage(*image, FloatRect(0, 0, bitmapSize.width(), bitmapSize.height()));
     2641    auto shouldRespectImageOrientation = renderImage.shouldRespectImageOrientation();
     2642    graphicsContext->drawImage(*image, FloatRect(0, 0, bitmapSize.width(), bitmapSize.height()), ImageOrientationDescription(shouldRespectImageOrientation));
    26392643    info.image = sharedBitmap;
    26402644}
  • trunk/Tools/ChangeLog

    r248437 r248438  
     12019-08-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        [iOS] Position image information should respect the image orientation
     4        https://bugs.webkit.org/show_bug.cgi?id=200487
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add an API test to verify the position image information is drawn rotated
     9        because of respecting its image orientation.
     10
     11        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     12        * TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
     13        (TestWebKitAPI::TEST):
     14        * TestWebKitAPI/Tests/WebKitCocoa/exif-orientation-8-llo.jpg: Added.
     15        * TestWebKitAPI/Tests/WebKitCocoa/img-with-rotated-image.html: Added.
     16
    1172019-08-08  Claudio Saavedra  <csaavedra@igalia.com>
    218
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r248410 r248438  
    407407                6BFD294C1D5E6C1D008EC968 /* HashCountedSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */; };
    408408                725C3EF322058A5B007C36FC /* AdditionalSupportedImageTypes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */; };
     409                7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */; };
     410                7283A9D222FB1E0600B21C7D /* exif-orientation-8-llo.jpg in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */; };
    409411                751B05D61F8EAC410028A09E /* DatabaseTrackerTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 751B05D51F8EAC1A0028A09E /* DatabaseTrackerTest.mm */; };
    410412                754CEC811F6722F200D0039A /* AutoFillAvailable.mm in Sources */ = {isa = PBXBuildFile; fileRef = 754CEC801F6722DC00D0039A /* AutoFillAvailable.mm */; };
     
    11961198                                07492B3C1DF8B86600633DE1 /* enumerateMediaDevices.html in Copy Resources */,
    11971199                                C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */,
     1200                                7283A9D222FB1E0600B21C7D /* exif-orientation-8-llo.jpg in Copy Resources */,
    11981201                                CDA29B2B20FD358400F15CED /* ExitFullscreenOnEnterPiP.html in Copy Resources */,
    11991202                                F41AB9A31EF4696B0083FA08 /* file-uploading.html in Copy Resources */,
     
    12381241                                F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */,
    12391242                                F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */,
     1243                                7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */,
    12401244                                935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */,
    12411245                                935786CE20F6A2A10000CDFC /* IndexedDB.sqlite3-shm in Copy Resources */,
     
    18901894                6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPParsers.cpp; sourceTree = "<group>"; };
    18911895                725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = AdditionalSupportedImageTypes.html; sourceTree = "<group>"; };
     1896                7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "img-with-rotated-image.html"; sourceTree = "<group>"; };
     1897                7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "exif-orientation-8-llo.jpg"; sourceTree = "<group>"; };
    18921898                751B05D51F8EAC1A0028A09E /* DatabaseTrackerTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseTrackerTest.mm; sourceTree = "<group>"; };
    18931899                754CEC801F6722DC00D0039A /* AutoFillAvailable.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AutoFillAvailable.mm; sourceTree = "<group>"; };
     
    31613167                                F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */,
    31623168                                F407FE381F1D0DE60017CF25 /* enormous.svg */,
     3169                                7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */,
    31633170                                CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */,
    31643171                                F41AB99B1EF4692C0083FA08 /* file-uploading.html */,
     
    31853192                                F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */,
    31863193                                F45B63FA1F197F33009D38B9 /* image-map.html */,
     3194                                7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */,
    31873195                                934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */,
    31883196                                934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm

    r247342 r248438  
    9797    TestWebKitAPI::Util::run(&finished);
    9898}
    99    
     99
     100TEST(WebKit, RequestActivatedElementInfoForRotatedImage)
     101{
     102    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     103    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"img-with-rotated-image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     104
     105    [webView loadRequest:request];
     106    [webView _test_waitForDidFinishNavigation];
     107
     108    __block bool finished = false;
     109    [webView _requestActivatedElementAtPosition:CGPointMake(50, 50) completionBlock: ^(_WKActivatedElementInfo *elementInfo) {
     110
     111        auto image = elementInfo.image.CGImage;
     112        auto data = adoptCF(CGDataProviderCopyData(CGImageGetDataProvider(image)));
     113        auto buffer = reinterpret_cast<const unsigned*>(CFDataGetBytePtr(data.get()));
     114
     115        auto pixelAt = [&](unsigned x, unsigned y) {
     116            unsigned i = y * elementInfo.image.size.width + x;
     117            return buffer[i];
     118        };
     119       
     120        static const unsigned yellow = 0xFFFFFF00;
     121        static const unsigned red = 0xFFF51900;
     122        static const unsigned green = 0xFF278000;
     123        static const unsigned blue = 0xFF0000FF;
     124
     125        EXPECT_TRUE(elementInfo.type == _WKActivatedElementTypeImage);
     126        EXPECT_WK_STREQ(elementInfo.imageURL.lastPathComponent, "exif-orientation-8-llo.jpg");
     127        EXPECT_NOT_NULL(elementInfo.image);
     128        EXPECT_EQ(elementInfo.boundingRect.size.width, 50);
     129        EXPECT_EQ(elementInfo.boundingRect.size.height, 100);
     130        EXPECT_EQ(elementInfo.image.size.width, 50);
     131        EXPECT_EQ(elementInfo.image.size.height, 100);
     132
     133        EXPECT_EQ(pixelAt(0, 0), yellow);
     134        EXPECT_EQ(pixelAt(elementInfo.image.size.width - 1, 0), red);
     135        EXPECT_EQ(pixelAt(0, elementInfo.image.size.height - 1), green);
     136        EXPECT_EQ(pixelAt(elementInfo.image.size.width - 1, elementInfo.image.size.height - 1), blue);
     137
     138        finished = true;
     139    }];
     140
     141    TestWebKitAPI::Util::run(&finished);
     142}
     143
    100144TEST(WebKit, RequestActivatedElementInfoForBlank)
    101145{
Note: See TracChangeset for help on using the changeset viewer.