From 71137783ac6927bd0dc02fce1d6e61e6ec027753 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Fri, 8 May 2020 15:20:01 +0300 Subject: Issue #1355 - Store the dirty rect on the display list builder rather than passing it as a parameter to BuildDisplayList Also fix build bustage for De-unified layout/xul in nsRootBoxFrame.cpp --- layout/generic/nsImageFrame.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'layout/generic/nsImageFrame.cpp') diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index c64520f2e..342370050 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1730,7 +1730,6 @@ nsImageFrame::PaintImage(nsRenderingContext& aRenderingContext, nsPoint aPt, void nsImageFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, - const nsRect& aDirtyRect, const nsDisplayListSet& aLists) { if (!IsVisibleForPainting(aBuilder)) -- cgit v1.2.3 From d050188cd525b769d33e2a2d94454b32aaa0b622 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 11 May 2020 23:17:47 +0000 Subject: Issue #1543 - Align with no src to the updated spec. --- layout/generic/nsImageFrame.cpp | 112 ++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 55 deletions(-) (limited to 'layout/generic/nsImageFrame.cpp') diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 342370050..226cca2cf 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -116,7 +116,7 @@ static bool HaveSpecifiedSize(const nsStylePosition* aStylePosition) // Decide whether we can optimize away reflows that result from the // image's intrinsic size changing. -inline bool HaveFixedSize(const ReflowInput& aReflowInput) +static bool HaveFixedSize(const ReflowInput& aReflowInput) { NS_ASSERTION(aReflowInput.mStylePosition, "crappy reflowInput - null stylePosition"); // Don't try to make this optimization when an image has percentages @@ -440,8 +440,22 @@ nsImageFrame::SourceRectToDest(const nsIntRect& aRect) (!(_state).HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED) && \ (_state).HasState(NS_EVENT_STATE_LOADING) && (_loadingOK))) -/* static */ -bool +static bool HasAltText(Element* aElement) +{ + // We always return some alternate text for , see + // nsCSSFrameConstructor::GetAlternateTextFor. + if (aElement->IsHTMLElement(nsGkAtoms::input)) { + return true; + } + + MOZ_ASSERT(aElement->IsHTMLElement(nsGkAtoms::img)); + nsAutoString altText; + return aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, altText) && !altText.IsEmpty(); +} + +// Check if we want to use an image frame or just let the frame constructor make +// us into an inline. +/* static */ bool nsImageFrame::ShouldCreateImageFrameFor(Element* aElement, nsStyleContext* aStyleContext) { @@ -452,44 +466,26 @@ nsImageFrame::ShouldCreateImageFrameFor(Element* aElement, return true; } - // Check if we want to use a placeholder box with an icon or just - // let the presShell make us into inline text. Decide as follows: - // - // - if our special "force icons" style is set, show an icon - // - else if our "do not show placeholders" pref is set, skip the icon - // - else: - // - if there is a src attribute, there is no alt attribute, - // and this is not an (which could not possibly have - // such an attribute), show an icon. - // - if QuirksMode, and the IMG has a size show an icon. - // - otherwise, skip the icon - bool useSizedBox; - + // If our special "force icons" style is set, show an icon if (aStyleContext->StyleUIReset()->mForceBrokenImageIcon) { - useSizedBox = true; - } - else if (gIconLoad && gIconLoad->mPrefForceInlineAltText) { - useSizedBox = false; + return true; } - else if (aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::src) && - !aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::alt) && - !aElement->IsHTMLElement(nsGkAtoms::object) && - !aElement->IsHTMLElement(nsGkAtoms::input)) { - // Use a sized box if we have no alt text. This means no alt attribute - // and the node is not an object or an input (since those always have alt - // text). - useSizedBox = true; + + // If our "do not show placeholders" pref is set, skip the icon + if (gIconLoad && gIconLoad->mPrefForceInlineAltText) { + return false; } - else if (aStyleContext->PresContext()->CompatibilityMode() != - eCompatibility_NavQuirks) { - useSizedBox = false; + + // If there is no Alt text, always create an image frame (regardless of src) + if (!HasAltText(aElement)) { + return true; } - else { - // check whether we have specified size - useSizedBox = HaveSpecifiedSize(aStyleContext->StylePosition()); + + if (aStyleContext->PresContext()->CompatibilityMode() == eCompatibility_NavQuirks) { + return HaveSpecifiedSize(aStyleContext->StylePosition()); } - - return useSizedBox; + + return false; } nsresult @@ -775,6 +771,25 @@ nsImageFrame::PredictedDestRect(const nsRect& aFrameContentBox) StylePosition()); } +bool nsImageFrame::ShouldShowBrokenImageIcon() const +{ + bool imageBroken = false; + // Check for broken images. valid null images (eg. img src="") are + // not considered broken because they have no image requests + nsCOMPtr imageLoader = do_QueryInterface(mContent); + if (imageLoader) { + nsCOMPtr currentRequest; + imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, + getter_AddRefs(currentRequest)); + uint32_t imageStatus; + imageBroken = + currentRequest && + NS_SUCCEEDED(currentRequest->GetImageStatus(&imageStatus)) && + (imageStatus & imgIRequest::STATUS_ERROR); + } + return imageBroken; +} + void nsImageFrame::EnsureIntrinsicSizeAndRatio() { @@ -789,25 +804,11 @@ nsImageFrame::EnsureIntrinsicSizeAndRatio() UpdateIntrinsicSize(mImage); UpdateIntrinsicRatio(mImage); } else { - // image request is null or image size not known, probably an - // invalid image specified + // Image request is null or image size not known. if (!(GetStateBits() & NS_FRAME_GENERATED_CONTENT)) { - bool imageBroken = false; - // check for broken images. valid null images (eg. img src="") are - // not considered broken because they have no image requests - nsCOMPtr imageLoader = do_QueryInterface(mContent); - if (imageLoader) { - nsCOMPtr currentRequest; - imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST, - getter_AddRefs(currentRequest)); - uint32_t imageStatus; - imageBroken = - currentRequest && - NS_SUCCEEDED(currentRequest->GetImageStatus(&imageStatus)) && - (imageStatus & imgIRequest::STATUS_ERROR); - } - // invalid image specified. make the image big enough for the "broken" icon - if (imageBroken) { + // Likely an invalid image. Check if we should display it as broken. + if (ShouldShowBrokenImageIcon()) { + // Invalid image specified. make the image big enough for the "broken" icon nscoord edgeLengthToUse = nsPresContext::CSSPixelsToAppUnits( ICON_SIZE + (2 * (ICON_PADDING + ALT_BORDER_WIDTH))); @@ -1389,7 +1390,8 @@ nsImageFrame::DisplayAltFeedback(nsRenderingContext& aRenderingContext, DrawResult result = DrawResult::NOT_READY; // Check if we should display image placeholders - if (!gIconLoad->mPrefShowPlaceholders || + if (!ShouldShowBrokenImageIcon() || + !gIconLoad->mPrefShowPlaceholders || (isLoading && !gIconLoad->mPrefShowLoadingPlaceholder)) { result = DrawResult::SUCCESS; } else { -- cgit v1.2.3 From a444b5cc390cbf522671e7a3f7c35fb4cadd3bb0 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 12 May 2020 18:28:25 +0000 Subject: Issue #1543 - Follow-up: avoid displaying the Alt text if an image is loading. This prevents the Alt text from briefly being shown before being replaced with the image. --- layout/generic/nsImageFrame.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'layout/generic/nsImageFrame.cpp') diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 226cca2cf..03fcbd8e3 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -430,15 +430,11 @@ nsImageFrame::SourceRectToDest(const nsIntRect& aRect) // that we'll construct image frames for them as needed if their display is // toggled from "none" (though we won't paint them, unless their visibility // is changed too). -#define BAD_STATES (NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED | \ - NS_EVENT_STATE_LOADING) +#define BAD_STATES (NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED) -// This is a macro so that we don't evaluate the boolean last arg -// unless we have to; it can be expensive -#define IMAGE_OK(_state, _loadingOK) \ - (!(_state).HasAtLeastOneOfStates(BAD_STATES) || \ - (!(_state).HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED) && \ - (_state).HasState(NS_EVENT_STATE_LOADING) && (_loadingOK))) +static bool ImageOk(EventStates aState) { + return !aState.HasAtLeastOneOfStates(BAD_STATES); +} static bool HasAltText(Element* aElement) { @@ -459,10 +455,8 @@ static bool HasAltText(Element* aElement) nsImageFrame::ShouldCreateImageFrameFor(Element* aElement, nsStyleContext* aStyleContext) { - EventStates state = aElement->State(); - if (IMAGE_OK(state, - HaveSpecifiedSize(aStyleContext->StylePosition()))) { - // Image is fine; do the image frame thing + if (ImageOk(aElement->State())) { + // Image is fine or loading; do the image frame thing return true; } @@ -1016,8 +1010,7 @@ nsImageFrame::Reflow(nsPresContext* aPresContext, } aMetrics.SetOverflowAreasToDesiredBounds(); - EventStates contentState = mContent->AsElement()->State(); - bool imageOK = IMAGE_OK(contentState, true); + bool imageOK = ImageOk(mContent->AsElement()->State()); // Determine if the size is available bool haveSize = false; @@ -1336,7 +1329,7 @@ nsImageFrame::DisplayAltFeedback(nsRenderingContext& aRenderingContext, MOZ_ASSERT(gIconLoad, "How did we succeed in Init then?"); // Whether we draw the broken or loading icon. - bool isLoading = IMAGE_OK(GetContent()->AsElement()->State(), true); + bool isLoading = ImageOk(mContent->AsElement()->State()); // Calculate the inner area nsRect inner = GetInnerArea() + aPt; @@ -1756,8 +1749,7 @@ nsImageFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, getter_AddRefs(currentRequest)); } - EventStates contentState = mContent->AsElement()->State(); - bool imageOK = IMAGE_OK(contentState, true); + bool imageOK = ImageOk(mContent->AsElement()->State()); // XXX(seth): The SizeIsAvailable check here should not be necessary - the // intention is that a non-null mImage means we have a size, but there is -- cgit v1.2.3