#493: image max-width M823483 M1247929

This commit is contained in:
Cameron Kaiser 2018-04-08 09:12:03 -07:00
parent 84b5506db7
commit 5f4c3c9c15
12 changed files with 86 additions and 16 deletions

View File

@ -1971,6 +1971,7 @@ GK_ATOM(letterFrame, "LetterFrame")
GK_ATOM(lineFrame, "LineFrame")
GK_ATOM(listControlFrame,"ListControlFrame")
GK_ATOM(menuFrame,"MenuFrame")
GK_ATOM(meterFrame, "MeterFrame")
GK_ATOM(menuPopupFrame,"MenuPopupFrame")
GK_ATOM(numberControlFrame, "NumberControlFrame")
GK_ATOM(objectFrame, "ObjectFrame")
@ -1979,6 +1980,7 @@ GK_ATOM(pageBreakFrame, "PageBreakFrame")
GK_ATOM(pageContentFrame, "PageContentFrame")
GK_ATOM(placeholderFrame, "PlaceholderFrame")
GK_ATOM(popupSetFrame, "PopupSetFrame")
GK_ATOM(progressFrame, "ProgressFrame")
GK_ATOM(canvasFrame, "CanvasFrame")
GK_ATOM(rangeFrame, "RangeFrame")
GK_ATOM(rootFrame, "RootFrame")

View File

@ -4489,6 +4489,43 @@ GetIntrinsicCoord(const nsStyleCoord& aStyle,
static int32_t gNoiseIndent = 0;
#endif
// Return true for form controls whose minimum intrinsic inline-size
// shrinks to 0 when they have a percentage inline-size (but not
// percentage max-inline-size). (Proper replaced elements, whose
// intrinsic minimium inline-size shrinks to 0 for both percentage
// inline-size and percentage max-inline-size, are handled elsewhere.)
inline static bool
FormControlShrinksForPercentISize(nsIFrame* aFrame)
{
if (!aFrame->IsFrameOfType(nsIFrame::eReplaced)) {
// Quick test to reject most frames.
return false;
}
nsIAtom* fType = aFrame->GetType();
if (fType == nsGkAtoms::meterFrame || fType == nsGkAtoms::progressFrame) {
// progress and meter do have this shrinking behavior
// FIXME: Maybe these should be nsIFormControlFrame?
return true;
}
if (!static_cast<nsIFormControlFrame*>(do_QueryFrame(aFrame))) {
// Not a form control. This includes fieldsets, which do not
// shrink.
return false;
}
if (fType == nsGkAtoms::gfxButtonControlFrame ||
fType == nsGkAtoms::HTMLButtonControlFrame) {
// Buttons don't have this shrinking behavior. (Note that color
// inputs do, even though they inherit from button, so we can't use
// do_QueryFrame here.)
return false;
}
return true;
}
/**
* Add aOffsets which describes what to add on outside of the content box
* aContentSize (controlled by 'box-sizing') and apply min/max properties.
@ -4565,19 +4602,23 @@ AddIntrinsicSizeOffset(nsRenderingContext* aRenderingContext,
pctTotal += pctOutsideSize;
nscoord size;
if (GetAbsoluteCoord(aStyleSize, size) ||
GetIntrinsicCoord(aStyleSize, aRenderingContext, aFrame,
PROP_WIDTH, size)) {
if (aType == nsLayoutUtils::MIN_ISIZE &&
(((aStyleSize.HasPercent() || aStyleMaxSize.HasPercent()) &&
aFrame->IsFrameOfType(nsIFrame::eReplacedSizing)) ||
(aStyleSize.HasPercent() &&
FormControlShrinksForPercentISize(aFrame)))) {
// A percentage width or max-width on replaced elements means they
// can shrink to 0.
// This is also true for percentage widths (but not max-widths) on
// text inputs.
// Note that if this is max-width, this overrides the fixed-width
// rule in the next condition.
result = 0; // let |min| handle padding/border/margin
} else if (GetAbsoluteCoord(aStyleSize, size) ||
GetIntrinsicCoord(aStyleSize, aRenderingContext, aFrame,
PROP_WIDTH, size)) {
result = nsLayoutUtils::AddPercents(aType, size + coordOutsideSize,
pctOutsideSize);
} else if (aType == nsLayoutUtils::MIN_ISIZE &&
// The only cases of coord-percent-calc() units that
// GetAbsoluteCoord didn't handle are percent and calc()s
// containing percent.
aStyleSize.IsCoordPercentCalcUnit() &&
aFrame->IsFrameOfType(nsIFrame::eReplaced)) {
// A percentage width on replaced elements means they can shrink to 0.
result = 0; // let |min| handle padding/border/margin
} else {
// NOTE: We could really do a lot better for percents and for some
// cases of calc() containing percent (certainly including any where

View File

@ -56,6 +56,12 @@ nsMeterFrame::DestroyFrom(nsIFrame* aDestructRoot)
nsContainerFrame::DestroyFrom(aDestructRoot);
}
nsIAtom*
nsMeterFrame::GetType() const
{
return nsGkAtoms::meterFrame;
}
nsresult
nsMeterFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{

View File

@ -32,6 +32,8 @@ public:
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus) override;
virtual nsIAtom* GetType() const override;
#ifdef DEBUG_FRAME_DUMP
virtual nsresult GetFrameName(nsAString& aResult) const override {
return MakeFrameName(NS_LITERAL_STRING("Meter"), aResult);

View File

@ -55,6 +55,12 @@ nsProgressFrame::DestroyFrom(nsIFrame* aDestructRoot)
nsContainerFrame::DestroyFrom(aDestructRoot);
}
nsIAtom*
nsProgressFrame::GetType() const
{
return nsGkAtoms::progressFrame;
}
nsresult
nsProgressFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{

View File

@ -35,6 +35,8 @@ public:
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus) override;
virtual nsIAtom* GetType() const override;
#ifdef DEBUG_FRAME_DUMP
virtual nsresult GetFrameName(nsAString& aResult) const override {
return MakeFrameName(NS_LITERAL_STRING("Progress"), aResult);

View File

@ -86,7 +86,8 @@ public:
virtual bool IsFrameOfType(uint32_t aFlags) const override
{
return nsSplittableFrame::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced));
return nsSplittableFrame::IsFrameOfType(aFlags &
~(nsIFrame::eReplaced | nsIFrame::eReplacedSizing));
}
#ifdef DEBUG_FRAME_DUMP

View File

@ -2123,6 +2123,11 @@ public:
eExcludesIgnorableWhitespace = 1 << 14,
eSupportsCSSTransforms = 1 << 15,
// A replaced element that has replaced-element sizing
// characteristics (i.e., like images or iframes), as opposed to
// inline-block sizing characteristics (like form controls).
eReplacedSizing = 1 << 16,
// These are to allow nsFrame::Init to assert that IsFrameOfType
// implementations all call the base class method. They are only
// meaningful in DEBUG builds.

View File

@ -112,7 +112,8 @@ public:
virtual bool IsFrameOfType(uint32_t aFlags) const override
{
return ImageFrameSuper::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced));
return ImageFrameSuper::IsFrameOfType(aFlags &
~(nsIFrame::eReplaced | nsIFrame::eReplacedSizing));
}
#ifdef DEBUG_FRAME_DUMP

View File

@ -91,7 +91,8 @@ public:
virtual bool IsFrameOfType(uint32_t aFlags) const override
{
return nsPluginFrameSuper::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced));
return nsPluginFrameSuper::IsFrameOfType(aFlags &
~(nsIFrame::eReplaced | nsIFrame::eReplacedSizing));
}
virtual bool NeedsView() override { return true; }

View File

@ -37,7 +37,9 @@ public:
{
// nsLeafFrame is already eReplacedContainsBlock, but that's somewhat bogus
return nsLeafFrame::IsFrameOfType(aFlags &
~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
~(nsIFrame::eReplaced |
nsIFrame::eReplacedSizing |
nsIFrame::eReplacedContainsBlock));
}
virtual void Init(nsIContent* aContent,

View File

@ -77,7 +77,8 @@ public:
virtual bool IsFrameOfType(uint32_t aFlags) const override
{
return nsSplittableFrame::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced));
return nsSplittableFrame::IsFrameOfType(aFlags &
~(nsIFrame::eReplaced | nsIFrame::eReplacedSizing));
}
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;