Skip to content

Commit

Permalink
StyleRuleCSSStyleDeclaration should use RefCounted instead of re-impl…
Browse files Browse the repository at this point in the history
…ementing the same thing

https://bugs.webkit.org/show_bug.cgi?id=258087
rdar://110795757

Reviewed by Chris Dumez.

Do the same thing with a few other classes.
No change in behavior.

* Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration):
(WebCore::StyleRuleCSSStyleDeclaration::ref): Deleted.
(WebCore::StyleRuleCSSStyleDeclaration::deref): Deleted.
* Source/WebCore/css/PropertySetCSSStyleDeclaration.h:

Canonical link: https://commits.webkit.org/266165@main
  • Loading branch information
achristensen07 committed Jul 19, 2023
1 parent eaa5055 commit 35296e9
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 70 deletions.
12 changes: 0 additions & 12 deletions Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ Ref<CSSComputedStyleDeclaration> CSSComputedStyleDeclaration::create(Element& el
return adoptRef(*new CSSComputedStyleDeclaration(element, allowVisitedStyle, pseudoElementName));
}

void CSSComputedStyleDeclaration::ref()
{
++m_refCount;
}

void CSSComputedStyleDeclaration::deref()
{
ASSERT(m_refCount);
if (!--m_refCount)
delete this;
}

String CSSComputedStyleDeclaration::cssText() const
{
return emptyString();
Expand Down
9 changes: 4 additions & 5 deletions Source/WebCore/css/CSSComputedStyleDeclaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ namespace WebCore {
class Element;
class MutableStyleProperties;

class CSSComputedStyleDeclaration final : public CSSStyleDeclaration {
class CSSComputedStyleDeclaration final : public CSSStyleDeclaration, public RefCounted<CSSComputedStyleDeclaration> {
WTF_MAKE_ISO_ALLOCATED_EXPORT(CSSComputedStyleDeclaration, WEBCORE_EXPORT);
public:
WEBCORE_EXPORT static Ref<CSSComputedStyleDeclaration> create(Element&, bool allowVisitedStyle = false, StringView pseudoElementName = StringView { });
virtual ~CSSComputedStyleDeclaration();
WEBCORE_EXPORT virtual ~CSSComputedStyleDeclaration();

WEBCORE_EXPORT void ref() final;
WEBCORE_EXPORT void deref() final;
void ref() final { RefCounted::ref(); }
void deref() final { RefCounted::deref(); }

String getPropertyValue(CSSPropertyID) const;

Expand Down Expand Up @@ -73,7 +73,6 @@ class CSSComputedStyleDeclaration final : public CSSStyleDeclaration {
mutable Ref<Element> m_element;
PseudoId m_pseudoElementSpecifier;
bool m_allowVisitedStyle;
unsigned m_refCount { 1 };
};

} // namespace WebCore
14 changes: 1 addition & 13 deletions Source/WebCore/css/CSSRuleList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,14 @@
#include "config.h"
#include "CSSRuleList.h"

#include "CSSRule.h"

namespace WebCore {

CSSRuleList::CSSRuleList() = default;

CSSRuleList::~CSSRuleList() = default;

StaticCSSRuleList::StaticCSSRuleList()
: m_refCount(1)
{
}
StaticCSSRuleList::StaticCSSRuleList() = default;

StaticCSSRuleList::~StaticCSSRuleList() = default;

void StaticCSSRuleList::deref()
{
ASSERT(m_refCount);
if (!--m_refCount)
delete this;
}

} // namespace WebCore
13 changes: 7 additions & 6 deletions Source/WebCore/css/CSSRuleList.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#pragma once

#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>

Expand All @@ -30,7 +31,7 @@ class CSSRule;
class CSSStyleSheet;

class CSSRuleList {
WTF_MAKE_NONCOPYABLE(CSSRuleList); WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(CSSRuleList);
public:
virtual ~CSSRuleList();

Expand All @@ -47,31 +48,31 @@ class CSSRuleList {
CSSRuleList();
};

class StaticCSSRuleList final : public CSSRuleList {
class StaticCSSRuleList final : public CSSRuleList, public RefCounted<StaticCSSRuleList> {
public:
static Ref<StaticCSSRuleList> create() { return adoptRef(*new StaticCSSRuleList); }

void ref() final { ++m_refCount; }
void deref() final;
void ref() final { RefCounted::ref(); }
void deref() final { RefCounted::deref(); }

Vector<RefPtr<CSSRule>>& rules() { return m_rules; }

CSSStyleSheet* styleSheet() const final { return nullptr; }

~StaticCSSRuleList();
private:
StaticCSSRuleList();
~StaticCSSRuleList();

unsigned length() const final { return m_rules.size(); }
CSSRule* item(unsigned index) const final { return index < m_rules.size() ? m_rules[index].get() : nullptr; }

Vector<RefPtr<CSSRule>> m_rules;
unsigned m_refCount;
};

// The rule owns the live list.
template <class Rule>
class LiveCSSRuleList final : public CSSRuleList {
WTF_MAKE_FAST_ALLOCATED;
public:
LiveCSSRuleList(Rule& rule)
: m_rule(rule)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/css/CSSStyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static Style::Scope& styleScopeFor(ContainerNode& treeScope)
}

class StyleSheetCSSRuleList final : public CSSRuleList {
WTF_MAKE_FAST_ALLOCATED;
public:
StyleSheetCSSRuleList(CSSStyleSheet* sheet) : m_styleSheet(sheet) { }

Expand Down
13 changes: 0 additions & 13 deletions Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ Ref<MutableStyleProperties> PropertySetCSSStyleDeclaration::copyProperties() con

StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration(MutableStyleProperties& propertySet, CSSRule& parentRule)
: PropertySetCSSStyleDeclaration(propertySet)
, m_refCount(1)
, m_parentRuleType(parentRule.styleRuleType())
, m_parentRule(&parentRule)
{
Expand All @@ -388,18 +387,6 @@ StyleRuleCSSStyleDeclaration::~StyleRuleCSSStyleDeclaration()
m_propertySet->deref();
}

void StyleRuleCSSStyleDeclaration::ref()
{
++m_refCount;
}

void StyleRuleCSSStyleDeclaration::deref()
{
ASSERT(m_refCount);
if (!--m_refCount)
delete this;
}

bool StyleRuleCSSStyleDeclaration::willMutate()
{
if (!m_parentRule || !m_parentRule->parentStyleSheet())
Expand Down
9 changes: 4 additions & 5 deletions Source/WebCore/css/PropertySetCSSStyleDeclaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
virtual void didMutate(MutationType) { }
};

class StyleRuleCSSStyleDeclaration final : public PropertySetCSSStyleDeclaration {
class StyleRuleCSSStyleDeclaration final : public PropertySetCSSStyleDeclaration, public RefCounted<StyleRuleCSSStyleDeclaration> {
WTF_MAKE_ISO_ALLOCATED(StyleRuleCSSStyleDeclaration);
public:
static Ref<StyleRuleCSSStyleDeclaration> create(MutableStyleProperties& propertySet, CSSRule& parentRule)
Expand All @@ -100,9 +100,9 @@ class StyleRuleCSSStyleDeclaration final : public PropertySetCSSStyleDeclaration
virtual ~StyleRuleCSSStyleDeclaration();

void clearParentRule() { m_parentRule = nullptr; }
void ref() final;
void deref() final;

void ref() final { RefCounted::ref(); }
void deref() final { RefCounted::deref(); }

void reattach(MutableStyleProperties&);

Expand All @@ -117,7 +117,6 @@ class StyleRuleCSSStyleDeclaration final : public PropertySetCSSStyleDeclaration
void didMutate(MutationType) final;
CSSParserContext cssParserContext() const final;

unsigned m_refCount;
StyleRuleType m_parentRuleType;
CSSRule* m_parentRule;
};
Expand Down
6 changes: 2 additions & 4 deletions Source/WebCore/rendering/RenderWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static void moveWidgetToParentSoon(Widget& child, LocalFrameView* parent)
RenderWidget::RenderWidget(HTMLFrameOwnerElement& element, RenderStyle&& style)
: RenderReplaced(element, WTFMove(style))
{
relaxAdoptionRequirement();
setInline(false);
}

Expand All @@ -120,10 +121,7 @@ void RenderWidget::willBeDestroyed()
RenderReplaced::willBeDestroyed();
}

RenderWidget::~RenderWidget()
{
ASSERT(!m_refCount);
}
RenderWidget::~RenderWidget() = default;

// Widgets are always placed on integer boundaries, so rounding the size is actually
// the desired behavior. This function is here because it's otherwise seldom what we
Expand Down
13 changes: 1 addition & 12 deletions Source/WebCore/rendering/RenderWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ inline void WidgetHierarchyUpdatesSuspensionScope::scheduleWidgetToMove(Widget&
widgetNewParentMap().set(&widget, frame);
}

class RenderWidget : public RenderReplaced, private OverlapTestRequestClient {
class RenderWidget : public RenderReplaced, private OverlapTestRequestClient, public RefCounted<RenderWidget> {
WTF_MAKE_ISO_ALLOCATED(RenderWidget);
public:
virtual ~RenderWidget();
Expand All @@ -82,9 +82,6 @@ class RenderWidget : public RenderReplaced, private OverlapTestRequestClient {

RemoteFrame* remoteFrame() const;

void ref() { ++m_refCount; }
void deref();

protected:
RenderWidget(HTMLFrameOwnerElement&, RenderStyle&&);

Expand Down Expand Up @@ -113,16 +110,8 @@ class RenderWidget : public RenderReplaced, private OverlapTestRequestClient {

RefPtr<Widget> m_widget;
IntRect m_clipRect; // The rectangle needs to remain correct after scrolling, so it is stored in content view coordinates, and not clipped to window.
unsigned m_refCount { 1 };
};

inline void RenderWidget::deref()
{
ASSERT(m_refCount);
if (!--m_refCount)
delete this;
}

} // namespace WebCore

SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderWidget, isWidget())

0 comments on commit 35296e9

Please sign in to comment.