Search code examples
iosswiftwebkitwkwebview

What is a WKCompositingView in WebKit?


Can someone explain what a WKCompositingView actually is? Searching Apple Documentation doesn't provide any results. It looks like it contains the website contents and can differ in size from the webView it's contained within.


Solution

  • I really don't know much about WebKit and how it's implemented, but it is Open Source and you can go look at the code. So I did.

    Looking in the WebKit sources, WKCompositingView is defined in the file RemoteLayerTreeViews.mm. By interface a WKCompositingView is a UIView.

    I can't be 100% sure, but it looks like WebKit generates "layers" of information in rendering HTML.

    It looks like the layers that don't have to be hit tested - that are just drawn, are implemented as CALayers on iOS.

    When a tree of drawn elements need to be hit tested. It looks like the system combines the sub-tree of CALayers into a WKCompositingView. This is a UIView (on iOS at least) and composites the subtree beneath it in terms of drawing, but also allows the aggregate element to participate in hit testing.

    In this way it serves as a device that interfaces the world outside of WebKit (the remote world?) with the trees of stuff inside of WebKit (the "local" stuff?) so they are "RemoteTreeViews".

    So a WKCompositingView is a host-defined level in the tree of composited HTML content that participates in drawing and hit testing.

    This is based solely on my own exploration of the code and could be wrong. If someone with better knowledge has a clearer explanation,I will certainly bow to their expertise.

    (and because it's part of the WebKit Open Source project that's why its not documented by Apple)