[webkit-changes] [WebKit/WebKit] afc670: Inserting consecutive <picture> elements displays ...

Aditya Keerthi noreply at github.com
Wed Mar 27 14:44:00 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: afc67068fec68a95864c3a7c4b14d28c5dba277c
      https://github.com/WebKit/WebKit/commit/afc67068fec68a95864c3a7c4b14d28c5dba277c
  Author: Aditya Keerthi <akeerthi at apple.com>
  Date:   2024-03-27 (Wed, 27 Mar 2024)

  Changed paths:
    A LayoutTests/editing/inserting/insert-text-after-picture-expected.txt
    A LayoutTests/editing/inserting/insert-text-after-picture.html
    A LayoutTests/editing/pasteboard/copy-picture-expected.txt
    A LayoutTests/editing/pasteboard/copy-picture.html
    M Source/WebCore/editing/Editing.cpp
    M Source/WebCore/editing/markup.cpp

  Log Message:
  -----------
  Inserting consecutive <picture> elements displays the same image twice
https://bugs.webkit.org/show_bug.cgi?id=271715
rdar://123795045

Reviewed by Ryosuke Niwa and Wenson Hsieh.

Currently, when inserting two successive elements of the form:

```
<picture>
    <source>
    <img>
</picture>
```

the resulting markup is:

```
<picture>
    <source>
    <img>
    <img>
</picture>
```

This results in two images displaying the same `<source>` content.

There are two distinct issues which result in the undesirable markup.

1. The second `<picture>` and `<source>` are dropped by `serializePreservingVisualAppearance`.
   When getting `VisiblePosition`s encompassing the inserted content, only the
   `<img>` is selected, as the first visible position inside the inserted element
   is before the `<picture>`. Consequently, the inserted `<picture>` and
   `<source>` are skipped when serializing nodes.

2. As the selection is inside the first `<picture>` after insertion, subsequent
   content also gets added to the same `<picture>` element.

To fix, `serializePreservingVisualAppearance` must preserve the `<picture>` and
`<source>`. Additionally, any insertions made while the selection is inside
`<picture>`, should be moved outside.

* LayoutTests/editing/inserting/insert-text-after-picture-expected.txt: Added.
* LayoutTests/editing/inserting/insert-text-after-picture.html: Added.
* LayoutTests/editing/pasteboard/copy-picture-expected.txt: Added.
* LayoutTests/editing/pasteboard/copy-picture.html: Added.
* Source/WebCore/editing/Editing.cpp:
(WebCore::canHaveChildrenForEditing):

Return false to ensure children added by editing appear before or after the
`<picture>`, rather than inside it.

`canContainRangeEndPoint` itself is not modified, as doing that introduces
selection and caret painting issues with <picture>. The <img> element itself
should remain selectable.

* Source/WebCore/editing/markup.cpp:
(WebCore::highestAncestorToWrapMarkup):

Return the `<picture>` element if it is a common ancestor of start/end, ensuring
`<picture>` is preserved in the serialized markup.

(WebCore::serializePreservingVisualAppearanceInternal):

Adjust the start Position, so that the `<source>` is included.

Canonical link: https://commits.webkit.org/276754@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list