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

Changeset 248458 in webkit


Ignore:
Timestamp:
Aug 8, 2019, 10:01:21 PM (7 years ago)
Author:
Kocsen Chung
Message:

Cherry-pick r248438. rdar://problem/54093226

[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.

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

Location:
branches/safari-608.1-branch
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-608.1-branch/Source/WebCore/ChangeLog

    r248428 r248458  
     12019-08-08  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r248438. rdar://problem/54093226
     4
     5    [iOS] Position image information should respect the image orientation
     6    https://bugs.webkit.org/show_bug.cgi?id=200487
     7   
     8    Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-08
     9    Reviewed by Simon Fraser.
     10   
     11    Source/WebCore:
     12   
     13    Re-factor CachedImage::imageSizeForRenderer() into another overriding
     14    function which does not scale the imageSize. Therefore the new function
     15    returns FloatSize while the original function returns LayoutSize.
     16   
     17    * loader/cache/CachedImage.cpp:
     18    (WebCore::CachedImage::imageSizeForRenderer const):
     19    * loader/cache/CachedImage.h:
     20    * rendering/RenderElement.h:
     21   
     22    Source/WebKit:
     23   
     24    imagePositionInformation() should respect the image orientation when
     25    drawing an Image to a ShareableBitmap context.
     26   
     27    boundsPositionInformation() already takes care of the image orientation
     28    because it gets RenderImage::enclosingBoundingBox().
     29   
     30    * WebProcess/WebPage/ios/WebPageIOS.mm:
     31    (WebKit::imagePositionInformation):
     32   
     33    Tools:
     34   
     35    Add an API test to verify the position image information is drawn rotated
     36    because of respecting its image orientation.
     37   
     38    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     39    * TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
     40    (TestWebKitAPI::TEST):
     41    * TestWebKitAPI/Tests/WebKitCocoa/exif-orientation-8-llo.jpg: Added.
     42    * TestWebKitAPI/Tests/WebKitCocoa/img-with-rotated-image.html: Added.
     43   
     44    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248438 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     45
     46    2019-08-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
     47
     48            [iOS] Position image information should respect the image orientation
     49            https://bugs.webkit.org/show_bug.cgi?id=200487
     50
     51            Reviewed by Simon Fraser.
     52
     53            Re-factor CachedImage::imageSizeForRenderer() into another overriding
     54            function which does not scale the imageSize. Therefore the new function
     55            returns FloatSize while the original function returns LayoutSize.
     56
     57            * loader/cache/CachedImage.cpp:
     58            (WebCore::CachedImage::imageSizeForRenderer const):
     59            * loader/cache/CachedImage.h:
     60            * rendering/RenderElement.h:
     61
    1622019-08-08  Alan Coon  <alancoon@apple.com>
    263
  • branches/safari-608.1-branch/Source/WebCore/loader/cache/CachedImage.cpp

    r240014 r248458  
    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;
  • branches/safari-608.1-branch/Source/WebCore/loader/cache/CachedImage.h

    r240014 r248458  
    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
  • branches/safari-608.1-branch/Source/WebCore/rendering/RenderElement.h

    r245543 r248458  
    205205    RenderBlock* containingBlockForAbsolutePosition() const;
    206206
    207     RespectImageOrientationEnum shouldRespectImageOrientation() const;
     207    WEBCORE_EXPORT RespectImageOrientationEnum shouldRespectImageOrientation() const;
    208208
    209209    void removeFromRenderFragmentedFlow();
  • branches/safari-608.1-branch/Source/WebKit/ChangeLog

    r248457 r248458  
     12019-08-08  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r248438. rdar://problem/54093226
     4
     5    [iOS] Position image information should respect the image orientation
     6    https://bugs.webkit.org/show_bug.cgi?id=200487
     7   
     8    Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-08
     9    Reviewed by Simon Fraser.
     10   
     11    Source/WebCore:
     12   
     13    Re-factor CachedImage::imageSizeForRenderer() into another overriding
     14    function which does not scale the imageSize. Therefore the new function
     15    returns FloatSize while the original function returns LayoutSize.
     16   
     17    * loader/cache/CachedImage.cpp:
     18    (WebCore::CachedImage::imageSizeForRenderer const):
     19    * loader/cache/CachedImage.h:
     20    * rendering/RenderElement.h:
     21   
     22    Source/WebKit:
     23   
     24    imagePositionInformation() should respect the image orientation when
     25    drawing an Image to a ShareableBitmap context.
     26   
     27    boundsPositionInformation() already takes care of the image orientation
     28    because it gets RenderImage::enclosingBoundingBox().
     29   
     30    * WebProcess/WebPage/ios/WebPageIOS.mm:
     31    (WebKit::imagePositionInformation):
     32   
     33    Tools:
     34   
     35    Add an API test to verify the position image information is drawn rotated
     36    because of respecting its image orientation.
     37   
     38    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     39    * TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
     40    (TestWebKitAPI::TEST):
     41    * TestWebKitAPI/Tests/WebKitCocoa/exif-orientation-8-llo.jpg: Added.
     42    * TestWebKitAPI/Tests/WebKitCocoa/img-with-rotated-image.html: Added.
     43   
     44    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248438 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     45
     46    2019-08-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
     47
     48            [iOS] Position image information should respect the image orientation
     49            https://bugs.webkit.org/show_bug.cgi?id=200487
     50
     51            Reviewed by Simon Fraser.
     52
     53            imagePositionInformation() should respect the image orientation when
     54            drawing an Image to a ShareableBitmap context.
     55
     56            boundsPositionInformation() already takes care of the image orientation
     57            because it gets RenderImage::enclosingBoundingBox().
     58
     59            * WebProcess/WebPage/ios/WebPageIOS.mm:
     60            (WebKit::imagePositionInformation):
     61
    1622019-08-08  Kocsen Chung  <kocsen_chung@apple.com>
    263
  • branches/safari-608.1-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r248352 r248458  
    26482648
    26492649    FloatSize screenSizeInPixels = screenSize();
     2650    FloatSize imageSize = renderImage.cachedImage()->imageSizeForRenderer(&renderImage);
     2651   
    26502652    screenSizeInPixels.scale(page.corePage()->deviceScaleFactor());
    2651     FloatSize scaledSize = largestRectWithAspectRatioInsideRect(image->size().width() / image->size().height(), FloatRect(0, 0, screenSizeInPixels.width(), screenSizeInPixels.height())).size();
    2652     FloatSize bitmapSize = scaledSize.width() < image->size().width() ? scaledSize : image->size();
     2653    FloatSize scaledSize = largestRectWithAspectRatioInsideRect(imageSize.width() / imageSize.height(), FloatRect(0, 0, screenSizeInPixels.width(), screenSizeInPixels.height())).size();
     2654    FloatSize bitmapSize = scaledSize.width() < imageSize.width() ? scaledSize : imageSize;
     2655   
    26532656    // FIXME: Only select ExtendedColor on images known to need wide gamut
    26542657    ShareableBitmap::Configuration bitmapConfiguration;
     
    26632666        return;
    26642667
    2665     graphicsContext->drawImage(*image, FloatRect(0, 0, bitmapSize.width(), bitmapSize.height()));
     2668    auto shouldRespectImageOrientation = renderImage.shouldRespectImageOrientation();
     2669    graphicsContext->drawImage(*image, FloatRect(0, 0, bitmapSize.width(), bitmapSize.height()), ImageOrientationDescription(shouldRespectImageOrientation));
    26662670    info.image = sharedBitmap;
    26672671}
  • branches/safari-608.1-branch/Tools/ChangeLog

    r248429 r248458  
     12019-08-08  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r248438. rdar://problem/54093226
     4
     5    [iOS] Position image information should respect the image orientation
     6    https://bugs.webkit.org/show_bug.cgi?id=200487
     7   
     8    Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-08-08
     9    Reviewed by Simon Fraser.
     10   
     11    Source/WebCore:
     12   
     13    Re-factor CachedImage::imageSizeForRenderer() into another overriding
     14    function which does not scale the imageSize. Therefore the new function
     15    returns FloatSize while the original function returns LayoutSize.
     16   
     17    * loader/cache/CachedImage.cpp:
     18    (WebCore::CachedImage::imageSizeForRenderer const):
     19    * loader/cache/CachedImage.h:
     20    * rendering/RenderElement.h:
     21   
     22    Source/WebKit:
     23   
     24    imagePositionInformation() should respect the image orientation when
     25    drawing an Image to a ShareableBitmap context.
     26   
     27    boundsPositionInformation() already takes care of the image orientation
     28    because it gets RenderImage::enclosingBoundingBox().
     29   
     30    * WebProcess/WebPage/ios/WebPageIOS.mm:
     31    (WebKit::imagePositionInformation):
     32   
     33    Tools:
     34   
     35    Add an API test to verify the position image information is drawn rotated
     36    because of respecting its image orientation.
     37   
     38    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     39    * TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
     40    (TestWebKitAPI::TEST):
     41    * TestWebKitAPI/Tests/WebKitCocoa/exif-orientation-8-llo.jpg: Added.
     42    * TestWebKitAPI/Tests/WebKitCocoa/img-with-rotated-image.html: Added.
     43   
     44    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248438 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     45
     46    2019-08-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
     47
     48            [iOS] Position image information should respect the image orientation
     49            https://bugs.webkit.org/show_bug.cgi?id=200487
     50
     51            Reviewed by Simon Fraser.
     52
     53            Add an API test to verify the position image information is drawn rotated
     54            because of respecting its image orientation.
     55
     56            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     57            * TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm:
     58            (TestWebKitAPI::TEST):
     59            * TestWebKitAPI/Tests/WebKitCocoa/exif-orientation-8-llo.jpg: Added.
     60            * TestWebKitAPI/Tests/WebKitCocoa/img-with-rotated-image.html: Added.
     61
    1622019-08-08  Alan Coon  <alancoon@apple.com>
    263
  • branches/safari-608.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r248428 r248458  
    392392                6BFD294C1D5E6C1D008EC968 /* HashCountedSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */; };
    393393                725C3EF322058A5B007C36FC /* AdditionalSupportedImageTypes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */; };
     394                7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */; };
     395                7283A9D222FB1E0600B21C7D /* exif-orientation-8-llo.jpg in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */; };
    394396                751B05D61F8EAC410028A09E /* DatabaseTrackerTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 751B05D51F8EAC1A0028A09E /* DatabaseTrackerTest.mm */; };
    395397                754CEC811F6722F200D0039A /* AutoFillAvailable.mm in Sources */ = {isa = PBXBuildFile; fileRef = 754CEC801F6722DC00D0039A /* AutoFillAvailable.mm */; };
     
    11771179                                07492B3C1DF8B86600633DE1 /* enumerateMediaDevices.html in Copy Resources */,
    11781180                                C5E1AFFE16B221F1006CC1F2 /* execCopy.html in Copy Resources */,
     1181                                7283A9D222FB1E0600B21C7D /* exif-orientation-8-llo.jpg in Copy Resources */,
    11791182                                CDA29B2B20FD358400F15CED /* ExitFullscreenOnEnterPiP.html in Copy Resources */,
    11801183                                F41AB9A31EF4696B0083FA08 /* file-uploading.html in Copy Resources */,
     
    12181221                                F4DEF6ED1E9B4DB60048EF61 /* image-in-link-and-input.html in Copy Resources */,
    12191222                                F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */,
     1223                                7283A9D022FA754900B21C7D /* img-with-rotated-image.html in Copy Resources */,
    12201224                                935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */,
    12211225                                935786CE20F6A2A10000CDFC /* IndexedDB.sqlite3-shm in Copy Resources */,
     
    18671871                6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPParsers.cpp; sourceTree = "<group>"; };
    18681872                725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = AdditionalSupportedImageTypes.html; sourceTree = "<group>"; };
     1873                7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "img-with-rotated-image.html"; sourceTree = "<group>"; };
     1874                7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "exif-orientation-8-llo.jpg"; sourceTree = "<group>"; };
    18691875                751B05D51F8EAC1A0028A09E /* DatabaseTrackerTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseTrackerTest.mm; sourceTree = "<group>"; };
    18701876                754CEC801F6722DC00D0039A /* AutoFillAvailable.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AutoFillAvailable.mm; sourceTree = "<group>"; };
     
    31313137                                F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */,
    31323138                                F407FE381F1D0DE60017CF25 /* enormous.svg */,
     3139                                7283A9D122FB1D9700B21C7D /* exif-orientation-8-llo.jpg */,
    31333140                                CDA29B2A20FD344E00F15CED /* ExitFullscreenOnEnterPiP.html */,
    31343141                                F41AB99B1EF4692C0083FA08 /* file-uploading.html */,
     
    31553162                                F4DEF6EC1E9B4D950048EF61 /* image-in-link-and-input.html */,
    31563163                                F45B63FA1F197F33009D38B9 /* image-map.html */,
     3164                                7283A9CE22FA6BBE00B21C7D /* img-with-rotated-image.html */,
    31573165                                934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */,
    31583166                                934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */,
  • branches/safari-608.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKRequestActivatedElementInfo.mm

    r247342 r248458  
    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.