Skip to content

Commit

Permalink
Adopt more smart pointers in rendering/mathml
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274384

Reviewed by Sihui Liu.

Adopt more smart pointers in endering/mathml based on the
[alpha.webkit.UncountedLocalVarsChecker] warning.

* Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp:
(WebCore::axisHeight):
* Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp:
(WebCore::RenderMathMLFenced::updateFromElement):
* Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp:
(WebCore::RenderMathMLFraction::defaultLineThickness const):
(WebCore::RenderMathMLFraction::fractionParameters const):
(WebCore::RenderMathMLFraction::stackParameters const):
* Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp:
(WebCore::RenderMathMLRoot::horizontalParameters):
(WebCore::RenderMathMLRoot::verticalParameters):
* Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp:
(WebCore::RenderMathMLScripts::spaceAfterScript):
(WebCore::RenderMathMLScripts::verticalParameters const):
* Source/WebCore/rendering/mathml/RenderMathMLSpace.cpp:
(WebCore::RenderMathMLSpace::spaceWidth const):
(WebCore::RenderMathMLSpace::getSpaceHeightAndDepth const):
* Source/WebCore/rendering/mathml/RenderMathMLToken.cpp:
(WebCore::RenderMathMLToken::updateMathVariantGlyph):
* Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp:
(WebCore::RenderMathMLUnderOver::verticalParameters const):

Canonical link: https://commits.webkit.org/279042@main
  • Loading branch information
rwlbuis committed May 21, 2024
1 parent faa8131 commit 63e956c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ bool RenderMathMLBlock::isChildAllowed(const RenderObject& child, const RenderSt
static LayoutUnit axisHeight(const RenderStyle& style)
{
// If we have a MATH table we just return the AxisHeight constant.
const auto& primaryFont = style.fontCascade().primaryFont();
if (auto* mathData = primaryFont.mathData())
const Ref primaryFont = style.fontCascade().primaryFont();
if (RefPtr mathData = primaryFont->mathData())
return LayoutUnit(mathData->getMathConstant(primaryFont, OpenTypeMathData::AxisHeight));

// Otherwise, the idea is to try and use the middle of operators as the math axis which we thus approximate by "half of the x-height".
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/rendering/mathml/RenderMathMLFenced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ RenderMathMLFenced::~RenderMathMLFenced() = default;

void RenderMathMLFenced::updateFromElement()
{
const auto& fenced = element();
const Ref fenced = element();

// The open operator defaults to a left parenthesis.
auto& open = fenced.attributeWithoutSynchronization(MathMLNames::openAttr);
auto& open = fenced->attributeWithoutSynchronization(MathMLNames::openAttr);
m_open = open.isNull() ? gOpeningBraceChar : open;

// The close operator defaults to a right parenthesis.
auto& close = fenced.attributeWithoutSynchronization(MathMLNames::closeAttr);
auto& close = fenced->attributeWithoutSynchronization(MathMLNames::closeAttr);
m_close = close.isNull() ? gClosingBraceChar : close;

auto& separators = fenced.attributeWithoutSynchronization(MathMLNames::separatorsAttr);
auto& separators = fenced->attributeWithoutSynchronization(MathMLNames::separatorsAttr);
if (!separators.isNull()) {
StringBuilder characters;
for (unsigned i = 0; i < separators.length(); i++) {
Expand Down
14 changes: 6 additions & 8 deletions Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ RenderBox& RenderMathMLFraction::denominator() const

LayoutUnit RenderMathMLFraction::defaultLineThickness() const
{
const auto& primaryFont = style().fontCascade().primaryFont();
if (const auto* mathData = primaryFont.mathData())
const Ref primaryFont = style().fontCascade().primaryFont();
if (RefPtr mathData = primaryFont->mathData())
return LayoutUnit(mathData->getMathConstant(primaryFont, OpenTypeMathData::FractionRuleThickness));
return ruleThicknessFallback();
}
Expand All @@ -101,10 +101,9 @@ RenderMathMLFraction::FractionParameters RenderMathMLFraction::fractionParameter
LayoutUnit numeratorGapMin, denominatorGapMin, numeratorMinShiftUp, denominatorMinShiftDown;

// We try and read constants to draw the fraction from the OpenType MATH and use fallback values otherwise.
const auto& primaryFont = style().fontCascade().primaryFont();
const auto* mathData = style().fontCascade().primaryFont().mathData();
bool display = style().mathStyle() == MathStyle::Normal;
if (mathData) {
const Ref primaryFont = style().fontCascade().primaryFont();
if (RefPtr mathData = primaryFont->mathData()) {
numeratorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumDisplayStyleGapMin : OpenTypeMathData::FractionNumeratorGapMin);
denominatorGapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionDenomDisplayStyleGapMin : OpenTypeMathData::FractionDenominatorGapMin);
numeratorMinShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::FractionNumeratorDisplayStyleShiftUp : OpenTypeMathData::FractionNumeratorShiftUp);
Expand Down Expand Up @@ -140,10 +139,9 @@ RenderMathMLFraction::FractionParameters RenderMathMLFraction::stackParameters()
LayoutUnit gapMin;

// We try and read constants to draw the stack from the OpenType MATH and use fallback values otherwise.
const auto& primaryFont = style().fontCascade().primaryFont();
const auto* mathData = style().fontCascade().primaryFont().mathData();
bool display = style().mathStyle() == MathStyle::Normal;
if (mathData) {
const Ref primaryFont = style().fontCascade().primaryFont();
if (RefPtr mathData = primaryFont->mathData()) {
gapMin = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackDisplayStyleGapMin : OpenTypeMathData::StackGapMin);
parameters.numeratorShiftUp = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackTopDisplayStyleShiftUp : OpenTypeMathData::StackTopShiftUp);
parameters.denominatorShiftDown = mathData->getMathConstant(primaryFont, display ? OpenTypeMathData::StackBottomDisplayStyleShiftDown : OpenTypeMathData::StackBottomShiftDown);
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ RenderMathMLRoot::HorizontalParameters RenderMathMLRoot::horizontalParameters()
return parameters;

// We try and read constants to draw the radical from the OpenType MATH and use fallback values otherwise.
const auto& primaryFont = style().fontCascade().primaryFont();
if (auto* mathData = style().fontCascade().primaryFont().mathData()) {
const Ref primaryFont = style().fontCascade().primaryFont();
if (RefPtr mathData = primaryFont->mathData()) {
parameters.kernBeforeDegree = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalKernBeforeDegree);
parameters.kernAfterDegree = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalKernAfterDegree);
} else {
Expand All @@ -128,8 +128,8 @@ RenderMathMLRoot::VerticalParameters RenderMathMLRoot::verticalParameters()
{
VerticalParameters parameters;
// We try and read constants to draw the radical from the OpenType MATH and use fallback values otherwise.
const auto& primaryFont = style().fontCascade().primaryFont();
if (auto* mathData = style().fontCascade().primaryFont().mathData()) {
const Ref primaryFont = style().fontCascade().primaryFont();
if (RefPtr mathData = primaryFont->mathData()) {
parameters.ruleThickness = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalRuleThickness);
parameters.verticalGap = mathData->getMathConstant(primaryFont, style().mathStyle() == MathStyle::Normal ? OpenTypeMathData::RadicalDisplayStyleVerticalGap : OpenTypeMathData::RadicalVerticalGap);
parameters.extraAscender = mathData->getMathConstant(primaryFont, OpenTypeMathData::RadicalExtraAscender);
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/rendering/mathml/RenderMathMLScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ std::optional<RenderMathMLScripts::ReferenceChildren> RenderMathMLScripts::valid

LayoutUnit RenderMathMLScripts::spaceAfterScript()
{
const auto& primaryFont = style().fontCascade().primaryFont();
if (auto* mathData = primaryFont.mathData())
const Ref primaryFont = style().fontCascade().primaryFont();
if (RefPtr mathData = primaryFont->mathData())
return LayoutUnit(mathData->getMathConstant(primaryFont, OpenTypeMathData::SpaceAfterScript));
return LayoutUnit(style().fontCascade().size() / 5);
}
Expand Down Expand Up @@ -231,8 +231,8 @@ void RenderMathMLScripts::computePreferredLogicalWidths()
auto RenderMathMLScripts::verticalParameters() const -> VerticalParameters
{
VerticalParameters parameters;
const auto& primaryFont = style().fontCascade().primaryFont();
if (auto* mathData = primaryFont.mathData()) {
const Ref primaryFont = style().fontCascade().primaryFont();
if (RefPtr mathData = primaryFont->mathData()) {
parameters.subscriptShiftDown = mathData->getMathConstant(primaryFont, OpenTypeMathData::SubscriptShiftDown);
parameters.superscriptShiftUp = mathData->getMathConstant(primaryFont, OpenTypeMathData::SuperscriptShiftUp);
parameters.subscriptBaselineDropMin = mathData->getMathConstant(primaryFont, OpenTypeMathData::SubscriptBaselineDropMin);
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/rendering/mathml/RenderMathMLSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ void RenderMathMLSpace::computePreferredLogicalWidths()

LayoutUnit RenderMathMLSpace::spaceWidth() const
{
auto& spaceElement = element();
Ref spaceElement = element();
// FIXME: Negative width values are not supported yet.
return std::max<LayoutUnit>(0, toUserUnits(spaceElement.width(), style(), 0));
return std::max<LayoutUnit>(0, toUserUnits(spaceElement->width(), style(), 0));
}

void RenderMathMLSpace::getSpaceHeightAndDepth(LayoutUnit& height, LayoutUnit& depth) const
{
auto& spaceElement = element();
height = toUserUnits(spaceElement.height(), style(), 0);
depth = toUserUnits(spaceElement.depth(), style(), 0);
Ref spaceElement = element();
height = toUserUnits(spaceElement->height(), style(), 0);
depth = toUserUnits(spaceElement->depth(), style(), 0);

// If the total height is negative, set vertical dimensions to 0.
if (height + depth < 0) {
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/rendering/mathml/RenderMathMLToken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,11 @@ void RenderMathMLToken::updateMathVariantGlyph()
return;
}

const auto& tokenElement = element();
const Ref tokenElement = element();
if (auto codePoint = MathMLTokenElement::convertToSingleCodePoint(element().textContent())) {
MathMLElement::MathVariant mathvariant = mathMLStyle().mathVariant();
if (mathvariant == MathMLElement::MathVariant::None)
mathvariant = tokenElement.hasTagName(MathMLNames::miTag) ? MathMLElement::MathVariant::Italic : MathMLElement::MathVariant::Normal;
mathvariant = tokenElement->hasTagName(MathMLNames::miTag) ? MathMLElement::MathVariant::Italic : MathMLElement::MathVariant::Normal;
char32_t transformedCodePoint = mathVariant(codePoint.value(), mathvariant);
if (transformedCodePoint != codePoint.value()) {
m_mathVariantCodePoint = mathVariant(codePoint.value(), mathvariant);
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/rendering/mathml/RenderMathMLUnderOver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ RenderMathMLUnderOver::VerticalParameters RenderMathMLUnderOver::verticalParamet
parameters.overExtraAscender = 0;
parameters.accentBaseHeight = 0;

const auto& primaryFont = style().fontCascade().primaryFont();
auto* mathData = primaryFont.mathData();
const Ref primaryFont = style().fontCascade().primaryFont();
RefPtr mathData = primaryFont->mathData();
if (!mathData) {
// The MATH table specification does not really provide any suggestions, except for some underbar/overbar values and AccentBaseHeight.
LayoutUnit defaultLineThickness = ruleThicknessFallback();
Expand Down

0 comments on commit 63e956c

Please sign in to comment.