mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-06-08 05:29:36 +00:00
#601: empty img behaviour M1196668 M1616537 M1506592 (see also M1549742)
This commit is contained in:
parent
5785a7c366
commit
a7f14df010
|
@ -60,7 +60,7 @@ interface nsIImageLoadingContent : imgINotificationObserver
|
||||||
* the image was blocked. This status always refers to the
|
* the image was blocked. This status always refers to the
|
||||||
* CURRENT_REQUEST load.
|
* CURRENT_REQUEST load.
|
||||||
*/
|
*/
|
||||||
readonly attribute short imageBlockingStatus;
|
[infallible] readonly attribute short imageBlockingStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to register an image decoder observer. Typically, this will
|
* Used to register an image decoder observer. Typically, this will
|
||||||
|
|
|
@ -115,7 +115,7 @@ static bool HaveSpecifiedSize(const nsStylePosition* aStylePosition)
|
||||||
|
|
||||||
// Decide whether we can optimize away reflows that result from the
|
// Decide whether we can optimize away reflows that result from the
|
||||||
// image's intrinsic size changing.
|
// image's intrinsic size changing.
|
||||||
inline bool HaveFixedSize(const nsHTMLReflowState& aReflowState)
|
static bool HaveFixedSize(const nsHTMLReflowState& aReflowState)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(aReflowState.mStylePosition, "crappy reflowState - null stylePosition");
|
NS_ASSERTION(aReflowState.mStylePosition, "crappy reflowState - null stylePosition");
|
||||||
// Don't try to make this optimization when an image has percentages
|
// Don't try to make this optimization when an image has percentages
|
||||||
|
@ -437,8 +437,23 @@ nsImageFrame::SourceRectToDest(const nsIntRect& aRect)
|
||||||
(!(_state).HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED) && \
|
(!(_state).HasAtLeastOneOfStates(NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED) && \
|
||||||
(_state).HasState(NS_EVENT_STATE_LOADING) && (_loadingOK)))
|
(_state).HasState(NS_EVENT_STATE_LOADING) && (_loadingOK)))
|
||||||
|
|
||||||
/* static */
|
static bool HasAltText(Element* aElement)
|
||||||
bool
|
{
|
||||||
|
// We always return some alternate text for <input>, 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,
|
nsImageFrame::ShouldCreateImageFrameFor(Element* aElement,
|
||||||
nsStyleContext* aStyleContext)
|
nsStyleContext* aStyleContext)
|
||||||
{
|
{
|
||||||
|
@ -449,44 +464,26 @@ nsImageFrame::ShouldCreateImageFrameFor(Element* aElement,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we want to use a placeholder box with an icon or just
|
// If our special "force icons" style is set, show an icon
|
||||||
// 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 <object> (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 (aStyleContext->StyleUIReset()->mForceBrokenImageIcon) {
|
if (aStyleContext->StyleUIReset()->mForceBrokenImageIcon) {
|
||||||
useSizedBox = true;
|
return true;
|
||||||
}
|
|
||||||
else if (gIconLoad && gIconLoad->mPrefForceInlineAltText) {
|
|
||||||
useSizedBox = false;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
else if (aStyleContext->PresContext()->CompatibilityMode() !=
|
|
||||||
eCompatibility_NavQuirks) {
|
|
||||||
useSizedBox = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// check whether we have specified size
|
|
||||||
useSizedBox = HaveSpecifiedSize(aStyleContext->StylePosition());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return useSizedBox;
|
// If our "do not show placeholders" pref is set, skip the icon
|
||||||
|
if (gIconLoad && gIconLoad->mPrefForceInlineAltText) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is no Alt text, always create an image frame (regardless of src)
|
||||||
|
if (!HasAltText(aElement)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aStyleContext->PresContext()->CompatibilityMode() == eCompatibility_NavQuirks) {
|
||||||
|
return HaveSpecifiedSize(aStyleContext->StylePosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
@ -767,6 +764,34 @@ nsImageFrame::PredictedDestRect(const nsRect& aFrameContentBox)
|
||||||
StylePosition());
|
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<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
||||||
|
if (imageLoader) {
|
||||||
|
// <img alt=""> is special, and it shouldn't draw the broken image icon,
|
||||||
|
// unlike the no-alt attribute or non-empty-alt-attribute case.
|
||||||
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::alt)) {
|
||||||
|
nsAutoString altText;
|
||||||
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, altText);
|
||||||
|
if (altText.IsEmpty())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<imgIRequest> 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
|
void
|
||||||
nsImageFrame::EnsureIntrinsicSizeAndRatio()
|
nsImageFrame::EnsureIntrinsicSizeAndRatio()
|
||||||
{
|
{
|
||||||
|
@ -776,22 +801,21 @@ nsImageFrame::EnsureIntrinsicSizeAndRatio()
|
||||||
mIntrinsicSize.width.GetCoordValue() == 0 &&
|
mIntrinsicSize.width.GetCoordValue() == 0 &&
|
||||||
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord &&
|
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord &&
|
||||||
mIntrinsicSize.height.GetCoordValue() == 0) {
|
mIntrinsicSize.height.GetCoordValue() == 0) {
|
||||||
|
|
||||||
if (mImage) {
|
if (mImage) {
|
||||||
UpdateIntrinsicSize(mImage);
|
UpdateIntrinsicSize(mImage);
|
||||||
UpdateIntrinsicRatio(mImage);
|
UpdateIntrinsicRatio(mImage);
|
||||||
} else {
|
} else {
|
||||||
// image request is null or image size not known, probably an
|
// Image request is null or image size not known.
|
||||||
// invalid image specified
|
|
||||||
// - make the image big enough for the icon (it may not be
|
|
||||||
// used if inline alt expansion is used instead)
|
|
||||||
if (!(GetStateBits() & NS_FRAME_GENERATED_CONTENT)) {
|
if (!(GetStateBits() & NS_FRAME_GENERATED_CONTENT)) {
|
||||||
nscoord edgeLengthToUse =
|
// Likely an invalid image. Check if we should display it as broken.
|
||||||
nsPresContext::CSSPixelsToAppUnits(
|
if (ShouldShowBrokenImageIcon()) {
|
||||||
ICON_SIZE + (2 * (ICON_PADDING + ALT_BORDER_WIDTH)));
|
nscoord edgeLengthToUse =
|
||||||
mIntrinsicSize.width.SetCoordValue(edgeLengthToUse);
|
nsPresContext::CSSPixelsToAppUnits(
|
||||||
mIntrinsicSize.height.SetCoordValue(edgeLengthToUse);
|
ICON_SIZE + (2 * (ICON_PADDING + ALT_BORDER_WIDTH)));
|
||||||
mIntrinsicRatio.SizeTo(1, 1);
|
mIntrinsicSize.width.SetCoordValue(edgeLengthToUse);
|
||||||
|
mIntrinsicSize.height.SetCoordValue(edgeLengthToUse);
|
||||||
|
mIntrinsicRatio.SizeTo(1, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1362,7 +1386,8 @@ nsImageFrame::DisplayAltFeedback(nsRenderingContext& aRenderingContext,
|
||||||
DrawResult result = DrawResult::NOT_READY;
|
DrawResult result = DrawResult::NOT_READY;
|
||||||
|
|
||||||
// Check if we should display image placeholders
|
// Check if we should display image placeholders
|
||||||
if (!gIconLoad->mPrefShowPlaceholders ||
|
if (!ShouldShowBrokenImageIcon() ||
|
||||||
|
!gIconLoad->mPrefShowPlaceholders ||
|
||||||
(isLoading && !gIconLoad->mPrefShowLoadingPlaceholder)) {
|
(isLoading && !gIconLoad->mPrefShowLoadingPlaceholder)) {
|
||||||
result = DrawResult::SUCCESS;
|
result = DrawResult::SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -104,6 +104,8 @@ public:
|
||||||
nsIAtom* aAttribute,
|
nsIAtom* aAttribute,
|
||||||
int32_t aModType) override;
|
int32_t aModType) override;
|
||||||
|
|
||||||
|
bool ShouldShowBrokenImageIcon() const;
|
||||||
|
|
||||||
#ifdef ACCESSIBILITY
|
#ifdef ACCESSIBILITY
|
||||||
virtual mozilla::a11y::AccType AccessibleType() override;
|
virtual mozilla::a11y::AccType AccessibleType() override;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user