Skip to content

Commit

Permalink
Create a RenderLineBreak when BR element has unsupported content data…
Browse files Browse the repository at this point in the history
… style

https://bugs.webkit.org/show_bug.cgi?id=224849

Patch by Carlos Garcia Campos <cgarcia@igalia.com> on 2021-08-23
Reviewed by Antti Koivisto.

Source/WebCore:

Instead of falling back to RenderElement::createFor(), create a RenderLineBreak just ignoring the unsupported
content data.

* html/HTMLBRElement.cpp:
(WebCore::HTMLBRElement::createElementRenderer):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::isContentDataSupported):
(WebCore::RenderElement::createFor):
* rendering/RenderElement.h:

LayoutTests:

* editing/execCommand/insert-image-in-composed-list-expected.txt: Rebaseline.

Canonical link: https://commits.webkit.org/240827@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281444 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos authored and webkit-commit-queue committed Aug 23, 2021
1 parent 6f1d674 commit 0e86f37
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
9 changes: 9 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,12 @@
2021-08-23 Carlos Garcia Campos <cgarcia@igalia.com>

Create a RenderLineBreak when BR element has unsupported content data style
https://bugs.webkit.org/show_bug.cgi?id=224849

Reviewed by Antti Koivisto.

* editing/execCommand/insert-image-in-composed-list-expected.txt: Rebaseline.

2021-08-23 Chris Dumez <cdumez@apple.com>

HTMLStyleElement should be able to fire the load event more than once
Expand Down
@@ -1 +1,2 @@
Test passes if it does not crash.
Test passes if it does not crash. 

17 changes: 17 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,20 @@
2021-08-23 Carlos Garcia Campos <cgarcia@igalia.com>

Create a RenderLineBreak when BR element has unsupported content data style
https://bugs.webkit.org/show_bug.cgi?id=224849

Reviewed by Antti Koivisto.

Instead of falling back to RenderElement::createFor(), create a RenderLineBreak just ignoring the unsupported
content data.

* html/HTMLBRElement.cpp:
(WebCore::HTMLBRElement::createElementRenderer):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::isContentDataSupported):
(WebCore::RenderElement::createFor):
* rendering/RenderElement.h:

2021-08-23 Chris Dumez <cdumez@apple.com>

HTMLStyleElement should be able to fire the load event more than once
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLBRElement.cpp
Expand Up @@ -75,7 +75,7 @@ void HTMLBRElement::collectPresentationalHintsForAttribute(const QualifiedName&

RenderPtr<RenderElement> HTMLBRElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
{
if (style.hasContent())
if (style.hasContent() && RenderElement::isContentDataSupported(*style.contentData()))
return RenderElement::createFor(*this, WTFMove(style));

return createRenderer<RenderLineBreak>(*this, WTFMove(style));
Expand Down
10 changes: 8 additions & 2 deletions Source/WebCore/rendering/RenderElement.cpp
Expand Up @@ -145,13 +145,19 @@ RenderElement::~RenderElement()
ASSERT(!m_firstChild);
}

RenderPtr<RenderElement> RenderElement::createFor(Element& element, RenderStyle&& style, OptionSet<ConstructBlockLevelRendererFor> rendererTypeOverride)
bool RenderElement::isContentDataSupported(const ContentData& contentData)
{
// Minimal support for content properties replacing an entire element.
// Works only if we have exactly one piece of content and it's a URL.
// Otherwise acts as if we didn't support this feature.
return is<ImageContentData>(contentData) && !contentData.next();
}

RenderPtr<RenderElement> RenderElement::createFor(Element& element, RenderStyle&& style, OptionSet<ConstructBlockLevelRendererFor> rendererTypeOverride)
{

const ContentData* contentData = style.contentData();
if (!rendererTypeOverride && contentData && !contentData->next() && is<ImageContentData>(*contentData) && !element.isPseudoElement()) {
if (!rendererTypeOverride && contentData && isContentDataSupported(*contentData) && !element.isPseudoElement()) {
Style::loadPendingResources(style, element.document(), &element);
auto& styleImage = downcast<ImageContentData>(*contentData).image();
auto image = createRenderer<RenderImage>(element, WTFMove(style), const_cast<StyleImage*>(&styleImage));
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/rendering/RenderElement.h
Expand Up @@ -28,6 +28,7 @@

namespace WebCore {

class ContentData;
class ControlStates;
class KeyframeList;
class RenderBlock;
Expand All @@ -39,6 +40,8 @@ class RenderElement : public RenderObject {
public:
virtual ~RenderElement();

static bool isContentDataSupported(const ContentData&);

enum class ConstructBlockLevelRendererFor {
Inline = 1 << 0,
ListItem = 1 << 1,
Expand Down

0 comments on commit 0e86f37

Please sign in to comment.