Files
tubestation/layout/mathml/nsMathMLmpaddedFrame.h
Frédéric Wang 8e33f7a364 Bug 1917763 - Do not override MeasureForWidth/Reflow for mpadded. r=emilio
The only reasons why we override MeasureForWidth and Reflow in
nsMathMLmpaddedFrame is to make sure attribute parsing is performed.
This patch just uses the implementation of nsMathMLContainerFrame
instead, by lazily parsing the attributes in nsMathMLmpaddedFrame::Place
and adding proper caching & invalidation to make it optimal.

Differential Revision: https://phabricator.services.mozilla.com/D221613
2024-09-13 08:03:55 +00:00

101 lines
2.8 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsMathMLmpaddedFrame_h___
#define nsMathMLmpaddedFrame_h___
#include "mozilla/Attributes.h"
#include "nsCSSValue.h"
#include "nsMathMLContainerFrame.h"
namespace mozilla {
class PresShell;
} // namespace mozilla
//
// <mpadded> -- adjust space around content
//
class nsMathMLmpaddedFrame final : public nsMathMLContainerFrame {
public:
NS_DECL_FRAMEARENA_HELPERS(nsMathMLmpaddedFrame)
friend nsIFrame* NS_NewMathMLmpaddedFrame(mozilla::PresShell* aPresShell,
ComputedStyle* aStyle);
NS_IMETHOD
InheritAutomaticData(nsIFrame* aParent) override;
NS_IMETHOD
TransmitAutomaticData() override {
return TransmitAutomaticDataForMrowLikeElement();
}
nsresult Place(DrawTarget* aDrawTarget, const PlaceFlags& aFlags,
ReflowOutput& aDesiredSize) override;
bool IsMrowLike() override {
return mFrames.FirstChild() != mFrames.LastChild() || !mFrames.FirstChild();
}
protected:
explicit nsMathMLmpaddedFrame(ComputedStyle* aStyle,
nsPresContext* aPresContext)
: nsMathMLContainerFrame(aStyle, aPresContext, kClassID) {}
virtual ~nsMathMLmpaddedFrame();
private:
struct Attribute {
enum class Sign : uint8_t {
Unspecified,
Minus,
Plus,
};
enum class PseudoUnit : uint8_t {
Unspecified,
ItSelf,
Width,
Height,
Depth,
NamedSpace,
};
nsCSSValue mValue;
Sign mSign = Sign::Unspecified;
PseudoUnit mPseudoUnit = PseudoUnit::Unspecified;
enum class ParsingState : uint8_t {
Valid,
Invalid,
Dirty,
};
ParsingState mState = ParsingState::Dirty;
void Reset() {
mValue.Reset();
mSign = Sign::Unspecified;
mPseudoUnit = PseudoUnit::Unspecified;
mState = ParsingState::Dirty;
}
bool IsValid() const { return mState == ParsingState::Valid; }
};
Attribute mWidth;
Attribute mHeight;
Attribute mDepth;
Attribute mLeadingSpace;
Attribute mVerticalOffset;
nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
int32_t aModType) final;
void ParseAttribute(nsAtom* aAtom, Attribute& aAttribute);
bool ParseAttribute(nsString& aString, Attribute& aAttribute);
void UpdateValue(const Attribute& aAttribute, Attribute::PseudoUnit aSelfUnit,
const ReflowOutput& aDesiredSize, nscoord& aValueToUpdate,
float aFontSizeInflation) const;
};
#endif /* nsMathMLmpaddedFrame_h___ */