2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
2014-09-13 00:15:24 +04:00
|
|
|
/* rendering object for replaced elements with image data */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
2013-09-25 05:43:43 +04:00
|
|
|
#include "nsImageFrame.h"
|
|
|
|
|
2014-10-16 13:51:14 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2017-06-09 22:14:53 +03:00
|
|
|
#include "gfxContext.h"
|
2014-10-17 15:53:16 +04:00
|
|
|
#include "gfxUtils.h"
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2017-06-18 14:37:50 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2014-10-16 13:51:14 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/Helpers.h"
|
2014-10-16 15:03:44 +04:00
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2017-06-29 01:12:36 +03:00
|
|
|
#include "mozilla/layers/WebRenderLayerManager.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
1999-07-08 23:38:08 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2014-10-24 19:28:14 +04:00
|
|
|
#include "nsFontMetrics.h"
|
2003-03-19 06:47:09 +03:00
|
|
|
#include "nsIImageLoadingContent.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsString.h"
|
2002-11-20 03:44:26 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIPresShell.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIDocument.h"
|
2004-04-30 03:34:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
2007-12-03 12:24:49 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2010-09-09 00:40:38 +04:00
|
|
|
#include "nsStyleCoord.h"
|
2014-11-15 03:45:23 +03:00
|
|
|
#include "nsStyleUtil.h"
|
2010-09-09 00:40:38 +04:00
|
|
|
#include "nsTransform2D.h"
|
1999-01-09 03:13:19 +03:00
|
|
|
#include "nsImageMap.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIIOService.h"
|
2001-03-22 04:38:35 +03:00
|
|
|
#include "nsILoadGroup.h"
|
2005-02-21 23:58:01 +03:00
|
|
|
#include "nsISupportsPriority.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsNetCID.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2011-01-28 07:38:14 +03:00
|
|
|
#include "nsAccessibilityService.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-04-01 05:01:33 +04:00
|
|
|
#include "nsIDOMNode.h"
|
2005-08-23 07:57:07 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2014-08-06 09:19:25 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsISelection.h"
|
2001-04-01 05:01:33 +04:00
|
|
|
|
2001-05-04 10:29:59 +04:00
|
|
|
#include "imgIContainer.h"
|
2012-11-16 22:24:58 +04:00
|
|
|
#include "imgLoader.h"
|
2012-10-12 16:43:01 +04:00
|
|
|
#include "imgRequestProxy.h"
|
2001-05-04 10:29:59 +04:00
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2003-04-23 03:18:34 +04:00
|
|
|
#include "nsIDOMRange.h"
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2006-07-31 11:08:45 +04:00
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#include "nsBidiPresUtils.h"
|
2003-04-22 03:57:47 +04:00
|
|
|
|
2011-01-18 00:47:18 +03:00
|
|
|
#include "gfxRect.h"
|
2011-04-26 10:04:18 +04:00
|
|
|
#include "ImageLayers.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
#include "ImageContainer.h"
|
2016-02-24 10:01:11 +03:00
|
|
|
#include "mozilla/StyleSetHandle.h"
|
|
|
|
#include "mozilla/StyleSetHandleInlines.h"
|
2013-08-20 02:55:18 +04:00
|
|
|
#include "nsBlockFrame.h"
|
2013-10-02 01:01:49 +04:00
|
|
|
#include "nsStyleStructInlines.h"
|
2011-01-18 00:47:18 +03:00
|
|
|
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2013-08-08 09:26:32 +04:00
|
|
|
#include "mozilla/dom/Link.h"
|
2017-01-11 04:48:29 +03:00
|
|
|
#include "SVGImageContext.h"
|
2017-09-23 00:56:51 +03:00
|
|
|
#include "mozilla/dom/HTMLAnchorElement.h"
|
2013-08-08 09:26:32 +04:00
|
|
|
|
2011-05-25 10:31:59 +04:00
|
|
|
using namespace mozilla;
|
2014-10-16 15:03:44 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-10-16 13:51:14 +04:00
|
|
|
using namespace mozilla::gfx;
|
2015-02-05 00:50:56 +03:00
|
|
|
using namespace mozilla::image;
|
2014-10-16 15:03:44 +04:00
|
|
|
using namespace mozilla::layers;
|
2011-05-25 10:31:59 +04:00
|
|
|
|
2002-03-26 23:14:05 +03:00
|
|
|
// sizes (pixels) for image icon, padding and border frame
|
|
|
|
#define ICON_SIZE (16)
|
|
|
|
#define ICON_PADDING (3)
|
|
|
|
#define ALT_BORDER_WIDTH (1)
|
|
|
|
|
2003-04-23 03:18:34 +04:00
|
|
|
//we must add hooks soon
|
|
|
|
#define IMAGE_EDITOR_CHECK 1
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Default alignment value (so we can tell an unset value from a set value)
|
2012-08-22 19:56:38 +04:00
|
|
|
#define ALIGN_UNSET uint8_t(-1)
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
// static icon information
|
2012-07-30 18:20:58 +04:00
|
|
|
nsImageFrame::IconLoad* nsImageFrame::gIconLoad = nullptr;
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2004-01-21 12:35:59 +03:00
|
|
|
// cached IO service for loading icons
|
|
|
|
nsIIOService* nsImageFrame::sIOService;
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// test if the width and height are fixed, looking at the style data
|
2015-05-06 09:52:19 +03:00
|
|
|
// This is used by nsImageFrame::ShouldCreateImageFrameFor and should
|
|
|
|
// not be used for layout decisions.
|
|
|
|
static bool HaveSpecifiedSize(const nsStylePosition* aStylePosition)
|
2001-11-07 08:02:42 +03:00
|
|
|
{
|
|
|
|
// check the width and height values in the reflow state's style struct
|
|
|
|
// - if width and height are specified as either coord or percentage, then
|
|
|
|
// the size of the image frame is constrained
|
2010-08-11 23:32:53 +04:00
|
|
|
return aStylePosition->mWidth.IsCoordPercentCalcUnit() &&
|
|
|
|
aStylePosition->mHeight.IsCoordPercentCalcUnit();
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
2014-11-11 19:46:06 +03:00
|
|
|
|
2015-05-06 09:52:19 +03:00
|
|
|
// Decide whether we can optimize away reflows that result from the
|
|
|
|
// image's intrinsic size changing.
|
2016-07-21 13:36:39 +03:00
|
|
|
inline bool HaveFixedSize(const ReflowInput& aReflowInput)
|
2014-11-11 19:46:06 +03:00
|
|
|
{
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_ASSERTION(aReflowInput.mStylePosition, "crappy reflowInput - null stylePosition");
|
2015-05-06 09:52:19 +03:00
|
|
|
// Don't try to make this optimization when an image has percentages
|
|
|
|
// in its 'width' or 'height'. The percentages might be treated like
|
|
|
|
// auto (especially for intrinsic width calculations and for heights).
|
2016-07-21 13:36:39 +03:00
|
|
|
return aReflowInput.mStylePosition->mHeight.ConvertsToLength() &&
|
|
|
|
aReflowInput.mStylePosition->mWidth.ConvertsToLength();
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
2001-03-06 03:47:46 +03:00
|
|
|
|
2005-11-01 23:40:54 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsImageFrame(aContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsImageFrame)
|
|
|
|
|
2017-05-26 13:11:11 +03:00
|
|
|
nsImageFrame::nsImageFrame(nsStyleContext* aContext, ClassID aID)
|
|
|
|
: nsAtomicContainerFrame(aContext, aID)
|
2017-04-30 18:30:08 +03:00
|
|
|
, mComputedSize(0, 0)
|
|
|
|
, mIntrinsicRatio(0, 0)
|
|
|
|
, mDisplayingIcon(false)
|
|
|
|
, mFirstFrameComplete(false)
|
|
|
|
, mReflowCallbackPosted(false)
|
|
|
|
, mForceSyncDecoding(false)
|
2000-04-19 18:00:11 +04:00
|
|
|
{
|
2016-03-26 00:49:43 +03:00
|
|
|
EnableVisibilityTracking();
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
// We assume our size is not constrained and we haven't gotten an
|
|
|
|
// initial reflow yet, so don't touch those flags.
|
2010-09-09 00:40:38 +04:00
|
|
|
mIntrinsicSize.width.SetCoordValue(0);
|
|
|
|
mIntrinsicSize.height.SetCoordValue(0);
|
2000-04-19 18:00:11 +04:00
|
|
|
}
|
|
|
|
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::~nsImageFrame()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsImageFrame)
|
2011-04-26 10:52:19 +04:00
|
|
|
NS_QUERYFRAME_ENTRY(nsImageFrame)
|
2016-04-18 08:58:30 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsAtomicContainerFrame)
|
2001-02-20 00:50:04 +03:00
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-29 01:53:44 +04:00
|
|
|
a11y::AccType
|
|
|
|
nsImageFrame::AccessibleType()
|
2001-05-18 03:52:32 +04:00
|
|
|
{
|
2012-09-29 01:53:44 +04:00
|
|
|
// Don't use GetImageMap() to avoid reentrancy into accessibility.
|
|
|
|
if (HasImageMap()) {
|
2012-12-18 05:25:52 +04:00
|
|
|
return a11y::eHTMLImageMapType;
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
|
|
|
|
2012-12-18 05:25:52 +04:00
|
|
|
return a11y::eImageType;
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2011-10-29 14:44:50 +04:00
|
|
|
nsImageFrame::DisconnectMap()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2017-07-03 21:35:14 +03:00
|
|
|
if (!mImageMap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mImageMap->Destroy();
|
|
|
|
mImageMap = nullptr;
|
2012-03-16 00:16:02 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2017-07-03 21:35:14 +03:00
|
|
|
if (nsAccessibilityService* accService = GetAccService()) {
|
2017-11-09 05:00:48 +03:00
|
|
|
accService->RecreateAccessible(PresShell(), mContent);
|
2012-03-16 00:16:02 +04:00
|
|
|
}
|
|
|
|
#endif
|
2011-10-29 14:44:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-11-07 03:20:33 +03:00
|
|
|
nsImageFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData)
|
2011-10-29 14:44:50 +04:00
|
|
|
{
|
2013-09-15 04:05:05 +04:00
|
|
|
if (mReflowCallbackPosted) {
|
2017-11-09 05:00:48 +03:00
|
|
|
PresShell()->CancelReflowCallback(this);
|
2013-09-15 04:05:05 +04:00
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
}
|
|
|
|
|
2011-10-29 14:44:50 +04:00
|
|
|
// Tell our image map, if there is one, to clean up
|
|
|
|
// This causes the nsImageMap to unregister itself as
|
|
|
|
// a DOM listener.
|
|
|
|
DisconnectMap();
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
// set the frame to null so we don't send messages to a dead object.
|
2003-03-19 06:47:09 +03:00
|
|
|
if (mListener) {
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader) {
|
2011-11-10 01:39:16 +04:00
|
|
|
// Notify our image loading content that we are going away so it can
|
|
|
|
// deregister with our refresh driver.
|
|
|
|
imageLoader->FrameDestroyed(this);
|
|
|
|
|
2017-07-19 21:15:12 +03:00
|
|
|
imageLoader->RemoveNativeObserver(mListener);
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
reinterpret_cast<nsImageListener*>(mListener.get())->SetFrame(nullptr);
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2009-08-12 18:23:38 +04:00
|
|
|
// If we were displaying an icon, take ourselves off the list
|
|
|
|
if (mDisplayingIcon)
|
|
|
|
gIconLoad->RemoveIconObserver(this);
|
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
nsAtomicContainerFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2014-06-28 07:50:26 +04:00
|
|
|
void
|
|
|
|
nsImageFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
|
|
|
{
|
2016-04-18 08:58:30 +03:00
|
|
|
nsAtomicContainerFrame::DidSetStyleContext(aOldStyleContext);
|
2014-06-28 07:50:26 +04:00
|
|
|
|
|
|
|
if (!mImage) {
|
|
|
|
// We'll pick this change up whenever we do get an image.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleImageOrientation newOrientation = StyleVisibility()->mImageOrientation;
|
|
|
|
|
|
|
|
// We need to update our orientation either if we had no style context before
|
|
|
|
// because this is the first time it's been set, or if the image-orientation
|
|
|
|
// property changed from its previous value.
|
|
|
|
bool shouldUpdateOrientation =
|
|
|
|
!aOldStyleContext ||
|
|
|
|
aOldStyleContext->StyleVisibility()->mImageOrientation != newOrientation;
|
|
|
|
|
|
|
|
if (shouldUpdateOrientation) {
|
|
|
|
nsCOMPtr<imgIContainer> image(mImage->Unwrap());
|
|
|
|
mImage = nsLayoutUtils::OrientImage(image, newOrientation);
|
|
|
|
|
|
|
|
UpdateIntrinsicSize(mImage);
|
|
|
|
UpdateIntrinsicRatio(mImage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsImageFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1998-12-29 06:38:16 +03:00
|
|
|
{
|
2016-04-18 08:58:30 +03:00
|
|
|
nsAtomicContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2003-02-26 08:51:32 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
mListener = new nsImageListener(this);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aContent);
|
2013-03-20 05:47:48 +04:00
|
|
|
if (!imageLoader) {
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("Why do we have an nsImageFrame here at all?");
|
2013-03-20 05:47:48 +04:00
|
|
|
}
|
2011-02-01 07:50:01 +03:00
|
|
|
|
2017-07-19 21:15:12 +03:00
|
|
|
imageLoader->AddNativeObserver(mListener);
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext *aPresContext = PresContext();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
if (!gIconLoad)
|
|
|
|
LoadIcons(aPresContext);
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
// We have a PresContext now, so we need to notify the image content node
|
|
|
|
// that it can register images.
|
|
|
|
imageLoader->FrameCreated(this);
|
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
// Give image loads associated with an image frame a small priority boost!
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
2017-04-18 11:38:23 +03:00
|
|
|
|
|
|
|
if (currentRequest) {
|
2017-03-27 10:53:49 +03:00
|
|
|
uint32_t categoryToBoostPriority = imgIRequest::CATEGORY_FRAME_INIT;
|
|
|
|
|
|
|
|
// Increase load priority further if intrinsic size might be important for layout.
|
|
|
|
if (!HaveSpecifiedSize(StylePosition())) {
|
|
|
|
categoryToBoostPriority |= imgIRequest::CATEGORY_SIZE_QUERY;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentRequest->BoostPriority(categoryToBoostPriority);
|
2017-04-18 11:38:23 +03:00
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-03-20 03:58:20 +03:00
|
|
|
nsImageFrame::UpdateIntrinsicSize(imgIContainer* aImage)
|
2003-03-19 06:47:09 +03:00
|
|
|
{
|
2007-03-20 03:58:20 +03:00
|
|
|
NS_PRECONDITION(aImage, "null image");
|
2010-09-09 00:40:38 +04:00
|
|
|
if (!aImage)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-03-20 03:58:20 +03:00
|
|
|
|
2013-10-01 01:26:04 +04:00
|
|
|
IntrinsicSize oldIntrinsicSize = mIntrinsicSize;
|
|
|
|
mIntrinsicSize = IntrinsicSize();
|
2013-01-11 07:38:34 +04:00
|
|
|
|
|
|
|
// Set intrinsic size to match aImage's reported intrinsic width & height.
|
|
|
|
nsSize intrinsicSize;
|
|
|
|
if (NS_SUCCEEDED(aImage->GetIntrinsicSize(&intrinsicSize))) {
|
|
|
|
// If the image has no intrinsic width, intrinsicSize.width will be -1, and
|
|
|
|
// we can leave mIntrinsicSize.width at its default value of eStyleUnit_None.
|
|
|
|
// Otherwise we use intrinsicSize.width. Height works the same way.
|
|
|
|
if (intrinsicSize.width != -1)
|
|
|
|
mIntrinsicSize.width.SetCoordValue(intrinsicSize.width);
|
|
|
|
if (intrinsicSize.height != -1)
|
|
|
|
mIntrinsicSize.height.SetCoordValue(intrinsicSize.height);
|
2010-09-09 00:40:38 +04:00
|
|
|
} else {
|
2013-01-11 07:38:34 +04:00
|
|
|
// Failure means that the image hasn't loaded enough to report a result. We
|
|
|
|
// treat this case as if the image's intrinsic size was 0x0.
|
|
|
|
mIntrinsicSize.width.SetCoordValue(0);
|
|
|
|
mIntrinsicSize.height.SetCoordValue(0);
|
1999-02-27 03:57:04 +03:00
|
|
|
}
|
|
|
|
|
2010-09-09 00:40:38 +04:00
|
|
|
return mIntrinsicSize != oldIntrinsicSize;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-09-09 00:40:38 +04:00
|
|
|
nsImageFrame::UpdateIntrinsicRatio(imgIContainer* aImage)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aImage, "null image");
|
|
|
|
|
|
|
|
if (!aImage)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-09-09 00:40:38 +04:00
|
|
|
|
|
|
|
nsSize oldIntrinsicRatio = mIntrinsicRatio;
|
|
|
|
|
2013-01-11 07:38:34 +04:00
|
|
|
// Set intrinsic ratio to match aImage's reported intrinsic ratio.
|
|
|
|
if (NS_FAILED(aImage->GetIntrinsicRatio(&mIntrinsicRatio)))
|
|
|
|
mIntrinsicRatio.SizeTo(0, 0);
|
2010-09-09 00:40:38 +04:00
|
|
|
|
|
|
|
return mIntrinsicRatio != oldIntrinsicRatio;
|
2007-03-20 03:58:20 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-09-09 00:40:38 +04:00
|
|
|
nsImageFrame::GetSourceToDestTransform(nsTransform2D& aTransform)
|
2007-03-20 03:58:20 +03:00
|
|
|
{
|
2014-11-15 03:45:24 +03:00
|
|
|
// First, figure out destRect (the rect we're rendering into).
|
|
|
|
// NOTE: We use mComputedSize instead of just GetInnerArea()'s own size here,
|
|
|
|
// because GetInnerArea() might be smaller if we're fragmented, whereas
|
|
|
|
// mComputedSize has our full content-box size (which we need for
|
|
|
|
// ComputeObjectDestRect to work correctly).
|
|
|
|
nsRect constraintRect(GetInnerArea().TopLeft(), mComputedSize);
|
|
|
|
constraintRect.y -= GetContinuationOffset();
|
|
|
|
|
|
|
|
nsRect destRect = nsLayoutUtils::ComputeObjectDestRect(constraintRect,
|
|
|
|
mIntrinsicSize,
|
|
|
|
mIntrinsicRatio,
|
|
|
|
StylePosition());
|
|
|
|
// Set the translation components, based on destRect
|
2003-03-19 06:47:09 +03:00
|
|
|
// XXXbz does this introduce rounding errors because of the cast to
|
|
|
|
// float? Should we just manually add that stuff in every time
|
|
|
|
// instead?
|
2014-11-15 03:45:24 +03:00
|
|
|
aTransform.SetToTranslate(float(destRect.x),
|
|
|
|
float(destRect.y));
|
2010-09-09 00:40:38 +04:00
|
|
|
|
2014-11-15 03:45:24 +03:00
|
|
|
// Set the scale factors, based on destRect and intrinsic size.
|
2010-09-09 00:40:38 +04:00
|
|
|
if (mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.width.GetCoordValue() != 0 &&
|
|
|
|
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.height.GetCoordValue() != 0 &&
|
2014-11-15 03:45:24 +03:00
|
|
|
mIntrinsicSize.width.GetCoordValue() != destRect.width &&
|
|
|
|
mIntrinsicSize.height.GetCoordValue() != destRect.height) {
|
2010-09-09 00:40:38 +04:00
|
|
|
|
2014-11-15 03:45:24 +03:00
|
|
|
aTransform.SetScale(float(destRect.width) /
|
2010-09-09 00:40:38 +04:00
|
|
|
float(mIntrinsicSize.width.GetCoordValue()),
|
2014-11-15 03:45:24 +03:00
|
|
|
float(destRect.height) /
|
2010-09-09 00:40:38 +04:00
|
|
|
float(mIntrinsicSize.height.GetCoordValue()));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2010-09-09 00:40:38 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2015-02-11 12:11:43 +03:00
|
|
|
// This function checks whether the given request is the current request for our
|
|
|
|
// mContent.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2003-03-19 06:47:09 +03:00
|
|
|
nsImageFrame::IsPendingLoad(imgIRequest* aRequest) const
|
|
|
|
{
|
|
|
|
// Default to pending load in case of errors
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader(do_QueryInterface(mContent));
|
|
|
|
NS_ASSERTION(imageLoader, "No image loading content?");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t requestType = nsIImageLoadingContent::UNKNOWN_REQUEST;
|
2003-03-19 06:47:09 +03:00
|
|
|
imageLoader->GetRequestType(aRequest, &requestType);
|
|
|
|
|
|
|
|
return requestType != nsIImageLoadingContent::CURRENT_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2009-01-15 06:27:09 +03:00
|
|
|
nsImageFrame::SourceRectToDest(const nsIntRect& aRect)
|
2003-03-19 06:47:09 +03:00
|
|
|
{
|
2004-08-29 03:59:15 +04:00
|
|
|
// When scaling the image, row N of the source image may (depending on
|
|
|
|
// the scaling function) be used to draw any row in the destination image
|
|
|
|
// between floor(F * (N-1)) and ceil(F * (N+1)), where F is the
|
|
|
|
// floating-point scaling factor. The same holds true for columns.
|
|
|
|
// So, we start by computing that bound without the floor and ceiling.
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
nsRect r(nsPresContext::CSSPixelsToAppUnits(aRect.x - 1),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aRect.y - 1),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aRect.width + 2),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aRect.height + 2));
|
2004-08-29 03:59:15 +04:00
|
|
|
|
2010-09-09 00:40:38 +04:00
|
|
|
nsTransform2D sourceToDest;
|
|
|
|
if (!GetSourceToDestTransform(sourceToDest)) {
|
|
|
|
// Failed to generate transform matrix. Return our whole inner area,
|
|
|
|
// to be on the safe side (since this method is used for generating
|
|
|
|
// invalidation rects).
|
|
|
|
return GetInnerArea();
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceToDest.TransformCoord(&r.x, &r.y, &r.width, &r.height);
|
2004-08-29 03:59:15 +04:00
|
|
|
|
|
|
|
// Now, round the edges out to the pixel boundary.
|
2010-09-09 00:40:38 +04:00
|
|
|
nscoord scale = nsPresContext::CSSPixelsToAppUnits(1);
|
2004-08-29 03:59:15 +04:00
|
|
|
nscoord right = r.x + r.width;
|
|
|
|
nscoord bottom = r.y + r.height;
|
|
|
|
|
|
|
|
r.x -= (scale + (r.x % scale)) % scale;
|
|
|
|
r.y -= (scale + (r.y % scale)) % scale;
|
|
|
|
r.width = right + ((scale - (right % scale)) % scale) - r.x;
|
|
|
|
r.height = bottom + ((scale - (bottom % scale)) % scale) - r.y;
|
|
|
|
|
|
|
|
return r;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2005-11-02 03:04:29 +03:00
|
|
|
// Note that we treat NS_EVENT_STATE_SUPPRESSED images as "OK". This means
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
// This is a macro so that we don't evaluate the boolean last arg
|
|
|
|
// unless we have to; it can be expensive
|
2010-10-20 15:26:32 +04:00
|
|
|
#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)))
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
/* static */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-06-01 05:46:56 +04:00
|
|
|
nsImageFrame::ShouldCreateImageFrameFor(Element* aElement,
|
2005-09-18 22:05:40 +04:00
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = aElement->State();
|
2005-11-02 03:04:29 +03:00
|
|
|
if (IMAGE_OK(state,
|
2015-05-06 09:52:19 +03:00
|
|
|
HaveSpecifiedSize(aStyleContext->StylePosition()))) {
|
2005-09-18 22:05:40 +04:00
|
|
|
// Image is fine; do the image frame thing
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2005-10-17 04:50:39 +04:00
|
|
|
|
2003-04-29 22:49:42 +04:00
|
|
|
// Check if we want to use a placeholder box with an icon or just
|
2005-11-21 01:05:24 +03:00
|
|
|
// let the presShell make us into inline text. Decide as follows:
|
2003-04-29 22:49:42 +04:00
|
|
|
//
|
|
|
|
// - 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:
|
2013-10-06 00:25:49 +04:00
|
|
|
// - 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.
|
2005-09-18 22:05:40 +04:00
|
|
|
// - if QuirksMode, and the IMG has a size show an icon.
|
2003-04-29 22:49:42 +04:00
|
|
|
// - otherwise, skip the icon
|
2011-09-29 10:19:26 +04:00
|
|
|
bool useSizedBox;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aStyleContext->StyleUIReset()->mForceBrokenImageIcon) {
|
2011-10-17 18:59:28 +04:00
|
|
|
useSizedBox = true;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2004-02-03 23:30:02 +03:00
|
|
|
else if (gIconLoad && gIconLoad->mPrefForceInlineAltText) {
|
2011-10-17 18:59:28 +04:00
|
|
|
useSizedBox = false;
|
2003-04-29 22:49:42 +04:00
|
|
|
}
|
2013-10-06 00:25:49 +04:00
|
|
|
else if (aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
|
|
|
|
!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::alt) &&
|
2015-03-03 14:08:59 +03:00
|
|
|
!aElement->IsHTMLElement(nsGkAtoms::object) &&
|
|
|
|
!aElement->IsHTMLElement(nsGkAtoms::input)) {
|
2013-10-06 00:25:49 +04:00
|
|
|
// 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;
|
|
|
|
}
|
2003-04-29 22:49:42 +04:00
|
|
|
else {
|
2015-05-06 09:52:19 +03:00
|
|
|
// check whether we have specified size
|
|
|
|
useSizedBox = HaveSpecifiedSize(aStyleContext->StylePosition());
|
2003-04-29 22:49:42 +04:00
|
|
|
}
|
2013-10-06 00:25:49 +04:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
return useSizedBox;
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
nsImageFrame::Notify(imgIRequest* aRequest,
|
|
|
|
int32_t aType,
|
|
|
|
const nsIntRect* aRect)
|
2012-10-12 20:11:22 +04:00
|
|
|
{
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnSizeAvailable(aRequest, image);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::FRAME_UPDATE) {
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnFrameUpdate(aRequest, aRect);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::FRAME_COMPLETE) {
|
|
|
|
mFirstFrameComplete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
uint32_t imgStatus;
|
|
|
|
aRequest->GetImageStatus(&imgStatus);
|
|
|
|
nsresult status =
|
|
|
|
imgStatus & imgIRequest::STATUS_ERROR ? NS_ERROR_FAILURE : NS_OK;
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnLoadComplete(aRequest, status);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-29 02:39:06 +04:00
|
|
|
static bool
|
|
|
|
SizeIsAvailable(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (!aRequest)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
uint32_t imageStatus = 0;
|
|
|
|
nsresult rv = aRequest->GetImageStatus(&imageStatus);
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
return NS_SUCCEEDED(rv) && (imageStatus & imgIRequest::STATUS_SIZE_AVAILABLE);
|
2013-08-29 02:39:06 +04:00
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
nsImageFrame::OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2001-10-06 09:08:16 +04:00
|
|
|
if (!aImage) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2003-12-26 07:24:11 +03:00
|
|
|
/* Get requested animation policy from the pres context:
|
|
|
|
* normal = 0
|
|
|
|
* one frame = 1
|
|
|
|
* one loop = 2
|
|
|
|
*/
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext *presContext = PresContext();
|
2004-02-03 23:30:02 +03:00
|
|
|
aImage->SetAnimationMode(presContext->ImageAnimationMode());
|
2001-04-17 02:02:39 +04:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
if (IsPendingLoad(aRequest)) {
|
|
|
|
// We don't care
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-08-29 02:39:06 +04:00
|
|
|
|
|
|
|
bool intrinsicSizeChanged = false;
|
|
|
|
if (SizeIsAvailable(aRequest)) {
|
|
|
|
// This is valid and for the current request, so update our stored image
|
2013-08-29 02:39:07 +04:00
|
|
|
// container, orienting according to our style.
|
|
|
|
mImage = nsLayoutUtils::OrientImage(aImage, StyleVisibility()->mImageOrientation);
|
2016-04-22 16:08:25 +03:00
|
|
|
|
2013-08-29 02:39:06 +04:00
|
|
|
intrinsicSizeChanged = UpdateIntrinsicSize(mImage);
|
|
|
|
intrinsicSizeChanged = UpdateIntrinsicRatio(mImage) || intrinsicSizeChanged;
|
|
|
|
} else {
|
|
|
|
// We no longer have a valid image, so release our stored image container.
|
2016-04-22 16:08:25 +03:00
|
|
|
mImage = mPrevImage = nullptr;
|
2013-08-29 02:39:06 +04:00
|
|
|
|
|
|
|
// Have to size to 0,0 so that GetDesiredSize recalculates the size.
|
|
|
|
mIntrinsicSize.width.SetCoordValue(0);
|
|
|
|
mIntrinsicSize.height.SetCoordValue(0);
|
|
|
|
mIntrinsicRatio.SizeTo(0, 0);
|
|
|
|
intrinsicSizeChanged = true;
|
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2011-08-24 01:03:02 +04:00
|
|
|
if (intrinsicSizeChanged && (mState & IMAGE_GOTINITIALREFLOW)) {
|
2009-02-06 19:52:13 +03:00
|
|
|
// Now we need to reflow if we have an unconstrained size and have
|
|
|
|
// already gotten the initial reflow
|
2017-07-06 15:00:35 +03:00
|
|
|
if (!(mState & IMAGE_SIZECONSTRAINED)) {
|
2009-02-06 19:52:13 +03:00
|
|
|
nsIPresShell *presShell = presContext->GetPresShell();
|
|
|
|
NS_ASSERTION(presShell, "No PresShell.");
|
2017-07-06 15:00:35 +03:00
|
|
|
if (presShell) {
|
2009-02-06 19:52:13 +03:00
|
|
|
presShell->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
2015-07-20 05:30:35 +03:00
|
|
|
} else {
|
|
|
|
// We've already gotten the initial reflow, and our size hasn't changed,
|
|
|
|
// so we're ready to request a decode.
|
|
|
|
MaybeDecodeForPredictedSize();
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
2016-04-22 16:08:25 +03:00
|
|
|
|
|
|
|
mPrevImage = nullptr;
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
nsImageFrame::OnFrameUpdate(imgIRequest* aRequest, const nsIntRect* aRect)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aRect);
|
2003-03-19 09:51:46 +03:00
|
|
|
|
|
|
|
if (!(mState & IMAGE_GOTINITIALREFLOW)) {
|
|
|
|
// Don't bother to do anything; we have a reflow coming up!
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2015-02-11 12:11:43 +03:00
|
|
|
if (mFirstFrameComplete && !StyleVisibility()->IsVisible()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
if (IsPendingLoad(aRequest)) {
|
|
|
|
// We don't care
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2015-02-11 12:11:43 +03:00
|
|
|
nsIntRect layerInvalidRect = mImage
|
|
|
|
? mImage->GetImageSpaceInvalidationRect(*aRect)
|
|
|
|
: *aRect;
|
2012-09-26 03:59:56 +04:00
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
if (layerInvalidRect.IsEqualInterior(GetMaxSizedIntRect())) {
|
2015-02-11 12:11:43 +03:00
|
|
|
// Invalidate our entire area.
|
|
|
|
InvalidateSelf(nullptr, nullptr);
|
|
|
|
return NS_OK;
|
2012-08-29 09:48:45 +04:00
|
|
|
}
|
2012-10-12 20:11:23 +04:00
|
|
|
|
2015-02-11 12:11:43 +03:00
|
|
|
nsRect frameInvalidRect = SourceRectToDest(layerInvalidRect);
|
|
|
|
InvalidateSelf(&layerInvalidRect, &frameInvalidRect);
|
2003-03-19 06:47:09 +03:00
|
|
|
return NS_OK;
|
2001-07-11 09:44:12 +04:00
|
|
|
}
|
|
|
|
|
2015-02-11 12:11:43 +03:00
|
|
|
void
|
|
|
|
nsImageFrame::InvalidateSelf(const nsIntRect* aLayerInvalidRect,
|
|
|
|
const nsRect* aFrameInvalidRect)
|
|
|
|
{
|
2017-07-24 09:43:55 +03:00
|
|
|
if (HasProperty(nsIFrame::WebRenderUserDataProperty())) {
|
|
|
|
nsIFrame::WebRenderUserDataTable* userDataTable =
|
|
|
|
GetProperty(nsIFrame::WebRenderUserDataProperty());
|
|
|
|
RefPtr<WebRenderUserData> data;
|
2017-08-07 07:07:43 +03:00
|
|
|
userDataTable->Get(static_cast<uint32_t>(DisplayItemType::TYPE_IMAGE), getter_AddRefs(data));
|
2017-07-24 09:43:55 +03:00
|
|
|
if (data && data->AsFallbackData()) {
|
|
|
|
data->AsFallbackData()->SetInvalid(true);
|
|
|
|
}
|
|
|
|
SchedulePaint();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-07 07:07:43 +03:00
|
|
|
InvalidateLayer(DisplayItemType::TYPE_IMAGE,
|
2015-02-11 12:11:43 +03:00
|
|
|
aLayerInvalidRect,
|
|
|
|
aFrameInvalidRect);
|
|
|
|
|
|
|
|
if (!mFirstFrameComplete) {
|
2017-08-07 07:07:43 +03:00
|
|
|
InvalidateLayer(DisplayItemType::TYPE_ALT_FEEDBACK,
|
2015-02-11 12:11:43 +03:00
|
|
|
aLayerInvalidRect,
|
|
|
|
aFrameInvalidRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
nsImageFrame::OnLoadComplete(imgIRequest* aRequest, nsresult aStatus)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
// Check what request type we're dealing with
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
NS_ASSERTION(imageLoader, "Who's notifying us??");
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t loadType = nsIImageLoadingContent::UNKNOWN_REQUEST;
|
2003-03-19 06:47:09 +03:00
|
|
|
imageLoader->GetRequestType(aRequest, &loadType);
|
|
|
|
if (loadType != nsIImageLoadingContent::CURRENT_REQUEST &&
|
|
|
|
loadType != nsIImageLoadingContent::PENDING_REQUEST) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2013-08-29 02:39:06 +04:00
|
|
|
NotifyNewCurrentRequest(aRequest, aStatus);
|
2012-03-20 02:22:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageFrame::NotifyNewCurrentRequest(imgIRequest *aRequest,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
2013-08-29 02:39:06 +04:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
|
|
|
NS_ASSERTION(image || NS_FAILED(aStatus), "Successful load with no container?");
|
|
|
|
|
2012-03-20 02:22:02 +04:00
|
|
|
// May have to switch sizes here!
|
|
|
|
bool intrinsicSizeChanged = true;
|
2013-08-29 02:39:06 +04:00
|
|
|
if (NS_SUCCEEDED(aStatus) && image && SizeIsAvailable(aRequest)) {
|
2013-08-29 02:39:07 +04:00
|
|
|
// Update our stored image container, orienting according to our style.
|
|
|
|
mImage = nsLayoutUtils::OrientImage(image, StyleVisibility()->mImageOrientation);
|
|
|
|
|
2013-08-29 02:39:06 +04:00
|
|
|
intrinsicSizeChanged = UpdateIntrinsicSize(mImage);
|
|
|
|
intrinsicSizeChanged = UpdateIntrinsicRatio(mImage) || intrinsicSizeChanged;
|
2013-08-29 02:39:07 +04:00
|
|
|
} else {
|
2013-08-29 02:39:06 +04:00
|
|
|
// We no longer have a valid image, so release our stored image container.
|
2016-04-22 16:08:25 +03:00
|
|
|
mImage = mPrevImage = nullptr;
|
2013-08-29 02:39:06 +04:00
|
|
|
|
2012-03-20 02:22:02 +04:00
|
|
|
// Have to size to 0,0 so that GetDesiredSize recalculates the size
|
|
|
|
mIntrinsicSize.width.SetCoordValue(0);
|
|
|
|
mIntrinsicSize.height.SetCoordValue(0);
|
|
|
|
mIntrinsicRatio.SizeTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mState & IMAGE_GOTINITIALREFLOW) { // do nothing if we haven't gotten the initial reflow yet
|
2016-02-03 01:51:52 +03:00
|
|
|
if (intrinsicSizeChanged) {
|
|
|
|
if (!(mState & IMAGE_SIZECONSTRAINED)) {
|
|
|
|
nsIPresShell *presShell = PresContext()->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
presShell->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We've already gotten the initial reflow, and our size hasn't changed,
|
|
|
|
// so we're ready to request a decode.
|
|
|
|
MaybeDecodeForPredictedSize();
|
2002-06-19 01:28:53 +04:00
|
|
|
}
|
2016-04-22 16:08:25 +03:00
|
|
|
|
|
|
|
mPrevImage = nullptr;
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
2012-11-01 05:25:44 +04:00
|
|
|
// Update border+content to account for image change
|
|
|
|
InvalidateFrame();
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2015-07-20 05:30:35 +03:00
|
|
|
void
|
|
|
|
nsImageFrame::MaybeDecodeForPredictedSize()
|
|
|
|
{
|
|
|
|
// Check that we're ready to decode.
|
|
|
|
if (!mImage) {
|
|
|
|
return; // Nothing to do yet.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mComputedSize.IsEmpty()) {
|
|
|
|
return; // We won't draw anything, so no point in decoding.
|
|
|
|
}
|
|
|
|
|
2016-09-12 08:19:08 +03:00
|
|
|
if (GetVisibility() != Visibility::APPROXIMATELY_VISIBLE) {
|
2015-07-20 05:30:35 +03:00
|
|
|
return; // We're not visible, so don't decode.
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK, we're ready to decode. Compute the scale to the screen...
|
|
|
|
nsIPresShell* presShell = PresContext()->GetPresShell();
|
|
|
|
LayoutDeviceToScreenScale2D resolutionToScreen(
|
|
|
|
presShell->GetCumulativeResolution()
|
2015-07-20 05:30:40 +03:00
|
|
|
* nsLayoutUtils::GetTransformToAncestorScaleExcludingAnimated(this));
|
2015-07-20 05:30:35 +03:00
|
|
|
|
|
|
|
// ...and this frame's content box...
|
|
|
|
const nsPoint offset =
|
|
|
|
GetOffsetToCrossDoc(nsLayoutUtils::GetReferenceFrame(this));
|
|
|
|
const nsRect frameContentBox = GetInnerArea() + offset;
|
|
|
|
|
|
|
|
// ...and our predicted dest rect...
|
|
|
|
const int32_t factor = PresContext()->AppUnitsPerDevPixel();
|
|
|
|
const LayoutDeviceRect destRect =
|
|
|
|
LayoutDeviceRect::FromAppUnits(PredictedDestRect(frameContentBox), factor);
|
|
|
|
|
|
|
|
// ...and use them to compute our predicted size in screen pixels.
|
|
|
|
const ScreenSize predictedScreenSize = destRect.Size() * resolutionToScreen;
|
|
|
|
const ScreenIntSize predictedScreenIntSize = RoundedToInt(predictedScreenSize);
|
|
|
|
if (predictedScreenIntSize.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the optimal image size to use.
|
|
|
|
uint32_t flags = imgIContainer::FLAG_HIGH_QUALITY_SCALING
|
|
|
|
| imgIContainer::FLAG_ASYNC_NOTIFY;
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter samplingFilter =
|
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(this);
|
2015-07-20 05:30:35 +03:00
|
|
|
gfxSize gfxPredictedScreenSize = gfxSize(predictedScreenIntSize.width,
|
|
|
|
predictedScreenIntSize.height);
|
|
|
|
nsIntSize predictedImageSize =
|
|
|
|
mImage->OptimalImageSizeForDest(gfxPredictedScreenSize,
|
|
|
|
imgIContainer::FRAME_CURRENT,
|
2016-05-25 19:01:18 +03:00
|
|
|
samplingFilter, flags);
|
2015-07-20 05:30:35 +03:00
|
|
|
|
|
|
|
// Request a decode.
|
|
|
|
mImage->RequestDecodeForSize(predictedImageSize, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsImageFrame::PredictedDestRect(const nsRect& aFrameContentBox)
|
|
|
|
{
|
|
|
|
// Note: To get the "dest rect", we have to provide the "constraint rect"
|
|
|
|
// (which is the content-box, with the effects of fragmentation undone).
|
|
|
|
nsRect constraintRect(aFrameContentBox.TopLeft(), mComputedSize);
|
|
|
|
constraintRect.y -= GetContinuationOffset();
|
|
|
|
|
2015-12-03 17:20:10 +03:00
|
|
|
return nsLayoutUtils::ComputeObjectDestRect(constraintRect,
|
|
|
|
mIntrinsicSize,
|
|
|
|
mIntrinsicRatio,
|
|
|
|
StylePosition());
|
2015-07-20 05:30:35 +03:00
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
void
|
2014-09-13 00:15:23 +04:00
|
|
|
nsImageFrame::EnsureIntrinsicSizeAndRatio()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2013-08-29 02:39:06 +04:00
|
|
|
// If mIntrinsicSize.width and height are 0, then we need to update from the
|
|
|
|
// image container.
|
2010-09-09 00:40:38 +04:00
|
|
|
if (mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.width.GetCoordValue() == 0 &&
|
|
|
|
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.height.GetCoordValue() == 0) {
|
2009-08-12 18:23:38 +04:00
|
|
|
|
2013-08-29 02:39:06 +04:00
|
|
|
if (mImage) {
|
|
|
|
UpdateIntrinsicSize(mImage);
|
|
|
|
UpdateIntrinsicRatio(mImage);
|
2003-03-19 06:47:09 +03:00
|
|
|
} else {
|
|
|
|
// image request is null or image size not known, probably an
|
|
|
|
// invalid image specified
|
2013-10-06 00:25:49 +04:00
|
|
|
if (!(GetStateBits() & NS_FRAME_GENERATED_CONTENT)) {
|
2017-06-02 17:19:48 +03:00
|
|
|
bool imageInvalid = false;
|
2016-06-03 01:05:46 +03:00
|
|
|
// 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) {
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
2017-06-02 17:19:48 +03:00
|
|
|
if (currentRequest) {
|
|
|
|
uint32_t imageStatus;
|
|
|
|
imageInvalid =
|
|
|
|
NS_SUCCEEDED(currentRequest->GetImageStatus(&imageStatus)) &&
|
|
|
|
(imageStatus & imgIRequest::STATUS_ERROR);
|
|
|
|
} else {
|
|
|
|
// check if images are user-disabled (or blocked for other
|
|
|
|
// reasons)
|
|
|
|
int16_t imageBlockingStatus;
|
|
|
|
imageLoader->GetImageBlockingStatus(&imageBlockingStatus);
|
|
|
|
imageInvalid = imageBlockingStatus != nsIContentPolicy::ACCEPT;
|
|
|
|
}
|
2016-06-03 01:05:46 +03:00
|
|
|
}
|
|
|
|
// invalid image specified. make the image big enough for the "broken" icon
|
2017-06-02 17:19:48 +03:00
|
|
|
if (imageInvalid) {
|
2016-06-03 01:05:46 +03:00
|
|
|
nscoord edgeLengthToUse =
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(
|
|
|
|
ICON_SIZE + (2 * (ICON_PADDING + ALT_BORDER_WIDTH)));
|
|
|
|
mIntrinsicSize.width.SetCoordValue(edgeLengthToUse);
|
|
|
|
mIntrinsicSize.height.SetCoordValue(edgeLengthToUse);
|
|
|
|
mIntrinsicRatio.SizeTo(1, 1);
|
|
|
|
}
|
2001-10-06 12:19:44 +04:00
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2014-08-24 18:34:44 +04:00
|
|
|
/* virtual */
|
|
|
|
LogicalSize
|
2017-06-09 22:14:53 +03:00
|
|
|
nsImageFrame::ComputeSize(gfxContext *aRenderingContext,
|
2014-08-24 18:34:44 +04:00
|
|
|
WritingMode aWM,
|
|
|
|
const LogicalSize& aCBSize,
|
|
|
|
nscoord aAvailableISize,
|
|
|
|
const LogicalSize& aMargin,
|
|
|
|
const LogicalSize& aBorder,
|
|
|
|
const LogicalSize& aPadding,
|
2014-11-11 14:02:41 +03:00
|
|
|
ComputeSizeFlags aFlags)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
2014-09-13 00:15:23 +04:00
|
|
|
EnsureIntrinsicSizeAndRatio();
|
2007-11-18 15:09:03 +03:00
|
|
|
|
2014-05-24 03:05:42 +04:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
NS_ASSERTION(imageLoader, "No content node??");
|
|
|
|
mozilla::IntrinsicSize intrinsicSize(mIntrinsicSize);
|
|
|
|
|
2015-03-19 04:29:32 +03:00
|
|
|
// XXX(seth): We may sometimes find ourselves in the situation where we have
|
|
|
|
// mImage, but imageLoader's current request does not have a size yet.
|
|
|
|
// This can happen when we load an image speculatively from cache, it fails
|
|
|
|
// to validate, and the new image load hasn't fired SIZE_AVAILABLE yet. In
|
|
|
|
// this situation we should always use mIntrinsicSize, because
|
|
|
|
// GetNaturalWidth/Height will return 0, so we check CurrentRequestHasSize()
|
|
|
|
// below. See bug 1019840. We will fix this in bug 1141395.
|
|
|
|
|
2014-05-28 00:53:34 +04:00
|
|
|
// Content may override our default dimensions. This is termed as overriding
|
|
|
|
// the intrinsic size by the spec, but all other consumers of mIntrinsic*
|
|
|
|
// values are being used to refer to the real/true size of the image data.
|
2015-03-19 04:29:32 +03:00
|
|
|
if (imageLoader && imageLoader->CurrentRequestHasSize() && mImage &&
|
2014-05-28 00:53:34 +04:00
|
|
|
intrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
intrinsicSize.height.GetUnit() == eStyleUnit_Coord) {
|
2014-05-24 03:05:42 +04:00
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
2014-05-28 00:53:34 +04:00
|
|
|
if (NS_SUCCEEDED(imageLoader->GetNaturalWidth(&width)) &&
|
|
|
|
NS_SUCCEEDED(imageLoader->GetNaturalHeight(&height))) {
|
|
|
|
nscoord appWidth = nsPresContext::CSSPixelsToAppUnits((int32_t)width);
|
2014-05-24 03:05:42 +04:00
|
|
|
nscoord appHeight = nsPresContext::CSSPixelsToAppUnits((int32_t)height);
|
2014-05-28 00:53:34 +04:00
|
|
|
// If this image is rotated, we'll need to transpose the natural
|
|
|
|
// width/height.
|
|
|
|
bool coordFlip;
|
|
|
|
if (StyleVisibility()->mImageOrientation.IsFromImage()) {
|
|
|
|
coordFlip = mImage->GetOrientation().SwapsWidthAndHeight();
|
|
|
|
} else {
|
|
|
|
coordFlip = StyleVisibility()->mImageOrientation.SwapsWidthAndHeight();
|
|
|
|
}
|
|
|
|
intrinsicSize.width.SetCoordValue(coordFlip ? appHeight : appWidth);
|
|
|
|
intrinsicSize.height.SetCoordValue(coordFlip ? appWidth : appHeight);
|
2014-05-24 03:05:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-05 04:57:06 +03:00
|
|
|
return ComputeSizeWithIntrinsicDimensions(aRenderingContext, aWM,
|
|
|
|
intrinsicSize, mIntrinsicRatio,
|
2016-11-05 04:57:06 +03:00
|
|
|
aCBSize, aMargin, aBorder, aPadding,
|
|
|
|
aFlags);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 01:29:59 +04:00
|
|
|
// XXXdholbert This function's clients should probably just be calling
|
|
|
|
// GetContentRectRelativeToSelf() directly.
|
2017-07-06 15:00:35 +03:00
|
|
|
nsRect
|
2004-12-26 22:48:54 +03:00
|
|
|
nsImageFrame::GetInnerArea() const
|
1998-11-20 20:21:02 +03:00
|
|
|
{
|
2014-09-12 01:29:59 +04:00
|
|
|
return GetContentRectRelativeToSelf();
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:25 +04:00
|
|
|
Element*
|
|
|
|
nsImageFrame::GetMapElement() const
|
|
|
|
{
|
|
|
|
nsAutoString usemap;
|
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usemap, usemap)) {
|
|
|
|
return mContent->OwnerDoc()->FindImageMap(usemap);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
// get the offset into the content area of the image where aImg starts if it is a continuation.
|
2017-07-06 15:00:35 +03:00
|
|
|
nscoord
|
2007-03-20 03:58:20 +03:00
|
|
|
nsImageFrame::GetContinuationOffset() const
|
2001-11-01 18:31:13 +03:00
|
|
|
{
|
|
|
|
nscoord offset = 0;
|
2007-03-20 03:58:20 +03:00
|
|
|
for (nsIFrame *f = GetPrevInFlow(); f; f = f->GetPrevInFlow()) {
|
|
|
|
offset += f->GetContentRect().height;
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
2007-03-20 03:58:20 +03:00
|
|
|
NS_ASSERTION(offset >= 0, "bogus GetContentRect");
|
2001-11-01 18:31:13 +03:00
|
|
|
return offset;
|
1998-11-20 20:21:02 +03:00
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* virtual */ nscoord
|
2017-06-09 22:14:53 +03:00
|
|
|
nsImageFrame::GetMinISize(gfxContext *aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2011-06-21 19:37:47 +04:00
|
|
|
DebugOnly<nscoord> result;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
2014-09-13 00:15:23 +04:00
|
|
|
EnsureIntrinsicSizeAndRatio();
|
2010-09-09 00:40:38 +04:00
|
|
|
return mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord ?
|
|
|
|
mIntrinsicSize.width.GetCoordValue() : 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2017-06-09 22:14:53 +03:00
|
|
|
nsImageFrame::GetPrefISize(gfxContext *aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2011-06-21 19:37:47 +04:00
|
|
|
DebugOnly<nscoord> result;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
2014-09-13 00:15:23 +04:00
|
|
|
EnsureIntrinsicSizeAndRatio();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// convert from normal twips to scaled twips (printing...)
|
2010-09-09 00:40:38 +04:00
|
|
|
return mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord ?
|
|
|
|
mIntrinsicSize.width.GetCoordValue() : 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2013-10-01 01:26:04 +04:00
|
|
|
/* virtual */ IntrinsicSize
|
2010-09-15 00:20:32 +04:00
|
|
|
nsImageFrame::GetIntrinsicSize()
|
|
|
|
{
|
|
|
|
return mIntrinsicSize;
|
|
|
|
}
|
|
|
|
|
2007-06-12 22:27:09 +04:00
|
|
|
/* virtual */ nsSize
|
|
|
|
nsImageFrame::GetIntrinsicRatio()
|
|
|
|
{
|
2010-09-09 00:40:38 +04:00
|
|
|
return mIntrinsicRatio;
|
2007-06-12 22:27:09 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aMetrics,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsImageFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aMetrics, aStatus);
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
1998-11-20 20:21:02 +03:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2000-05-14 08:43:52 +04:00
|
|
|
("enter nsImageFrame::Reflow: availSize=%d,%d",
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight()));
|
1998-11-20 20:21:02 +03:00
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
2001-03-06 03:47:46 +03:00
|
|
|
// see if we have a frozen size (i.e. a fixed width and height)
|
2016-07-21 13:36:39 +03:00
|
|
|
if (HaveFixedSize(aReflowInput)) {
|
2017-08-24 14:09:42 +03:00
|
|
|
AddStateBits(IMAGE_SIZECONSTRAINED);
|
2003-02-25 01:20:26 +03:00
|
|
|
} else {
|
2017-08-24 12:55:28 +03:00
|
|
|
RemoveStateBits(IMAGE_SIZECONSTRAINED);
|
2003-02-25 01:20:26 +03:00
|
|
|
}
|
2001-03-06 03:47:46 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXldb These two bits are almost exact opposites (except in the
|
|
|
|
// middle of the initial reflow); remove IMAGE_GOTINITIALREFLOW.
|
|
|
|
if (GetStateBits() & NS_FRAME_FIRST_REFLOW) {
|
2017-08-24 14:09:42 +03:00
|
|
|
AddStateBits(IMAGE_GOTINITIALREFLOW);
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
mComputedSize =
|
2016-07-21 13:36:39 +03:00
|
|
|
nsSize(aReflowInput.ComputedWidth(), aReflowInput.ComputedHeight());
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2013-12-27 21:59:52 +04:00
|
|
|
aMetrics.Width() = mComputedSize.width;
|
|
|
|
aMetrics.Height() = mComputedSize.height;
|
2001-11-01 18:31:13 +03:00
|
|
|
|
|
|
|
// add borders and padding
|
2016-07-21 13:36:39 +03:00
|
|
|
aMetrics.Width() += aReflowInput.ComputedPhysicalBorderPadding().LeftRight();
|
|
|
|
aMetrics.Height() += aReflowInput.ComputedPhysicalBorderPadding().TopBottom();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
if (GetPrevInFlow()) {
|
2013-12-27 21:59:52 +04:00
|
|
|
aMetrics.Width() = GetPrevInFlow()->GetSize().width;
|
2007-03-20 03:58:20 +03:00
|
|
|
nscoord y = GetContinuationOffset();
|
2016-07-21 13:36:39 +03:00
|
|
|
aMetrics.Height() -= y + aReflowInput.ComputedPhysicalBorderPadding().top;
|
2013-12-27 21:59:52 +04:00
|
|
|
aMetrics.Height() = std::max(0, aMetrics.Height());
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
|
|
|
|
2002-01-11 22:32:55 +03:00
|
|
|
|
|
|
|
// we have to split images if we are:
|
|
|
|
// in Paginated mode, we need to have a constrained height, and have a height larger than our available height
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t loadStatus = imgIRequest::STATUS_NONE;
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
NS_ASSERTION(imageLoader, "No content node??");
|
|
|
|
if (imageLoader) {
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
if (currentRequest) {
|
|
|
|
currentRequest->GetImageStatus(&loadStatus);
|
|
|
|
}
|
2002-08-29 05:44:15 +04:00
|
|
|
}
|
2004-03-03 21:24:20 +03:00
|
|
|
if (aPresContext->IsPaginated() &&
|
2003-02-25 01:20:26 +03:00
|
|
|
((loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE) || (mState & IMAGE_SIZECONSTRAINED)) &&
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_UNCONSTRAINEDSIZE != aReflowInput.AvailableHeight() &&
|
|
|
|
aMetrics.Height() > aReflowInput.AvailableHeight()) {
|
2008-01-05 09:44:38 +03:00
|
|
|
// our desired height was greater than 0, so to avoid infinite
|
|
|
|
// splitting, use 1 pixel as the min
|
2016-07-21 13:36:39 +03:00
|
|
|
aMetrics.Height() = std::max(nsPresContext::CSSPixelsToAppUnits(1), aReflowInput.AvailableHeight());
|
2017-02-14 12:30:56 +03:00
|
|
|
aStatus.SetIncomplete();
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
|
|
|
|
2010-10-07 08:25:46 +04:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates contentState = mContent->AsElement()->State();
|
2012-08-29 09:48:44 +04:00
|
|
|
bool imageOK = IMAGE_OK(contentState, true);
|
|
|
|
|
|
|
|
// Determine if the size is available
|
|
|
|
bool haveSize = false;
|
|
|
|
if (loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE) {
|
|
|
|
haveSize = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!imageOK || !haveSize) {
|
|
|
|
nsRect altFeedbackSize(0, 0,
|
2012-11-14 22:05:41 +04:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(ICON_SIZE+2*(ICON_PADDING+ALT_BORDER_WIDTH)),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(ICON_SIZE+2*(ICON_PADDING+ALT_BORDER_WIDTH)));
|
2013-01-18 08:17:41 +04:00
|
|
|
// We include the altFeedbackSize in our visual overflow, but not in our
|
|
|
|
// scrollable overflow, since it doesn't really need to be scrolled to
|
|
|
|
// outside the image.
|
2013-07-18 21:59:53 +04:00
|
|
|
static_assert(eOverflowType_LENGTH == 2, "Unknown overflow types?");
|
2013-01-18 08:17:41 +04:00
|
|
|
nsRect& visualOverflow = aMetrics.VisualOverflow();
|
|
|
|
visualOverflow.UnionRect(visualOverflow, altFeedbackSize);
|
2015-07-20 05:30:35 +03:00
|
|
|
} else {
|
|
|
|
// We've just reflowed and we should have an accurate size, so we're ready
|
|
|
|
// to request a decode.
|
|
|
|
MaybeDecodeForPredictedSize();
|
2012-08-29 09:48:44 +04:00
|
|
|
}
|
2017-05-17 17:47:31 +03:00
|
|
|
FinishAndStoreOverflow(&aMetrics, aReflowInput.mStyleDisplay);
|
2012-08-29 09:48:44 +04:00
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
if ((GetStateBits() & NS_FRAME_FIRST_REFLOW) && !mReflowCallbackPosted) {
|
2017-11-09 05:00:48 +03:00
|
|
|
nsIPresShell* shell = PresShell();
|
2013-09-15 04:05:06 +04:00
|
|
|
mReflowCallbackPosted = true;
|
|
|
|
shell->PostReflowCallback(this);
|
2013-09-15 04:05:05 +04:00
|
|
|
}
|
|
|
|
|
1998-11-20 20:21:02 +03:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2000-05-14 08:43:52 +04:00
|
|
|
("exit nsImageFrame::Reflow: size=%d,%d",
|
2013-12-27 21:59:52 +04:00
|
|
|
aMetrics.Width(), aMetrics.Height()));
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aMetrics);
|
1998-11-20 20:21:02 +03:00
|
|
|
}
|
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
bool
|
|
|
|
nsImageFrame::ReflowFinished()
|
|
|
|
{
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
|
2016-03-26 00:49:43 +03:00
|
|
|
// XXX(seth): We don't need this. The purpose of updating visibility
|
|
|
|
// synchronously is to ensure that animated images start animating
|
|
|
|
// immediately. In the short term, however,
|
|
|
|
// nsImageLoadingContent::OnUnlockedDraw() is enough to ensure that
|
|
|
|
// animations start as soon as the image is painted for the first time, and in
|
|
|
|
// the long term we want to update visibility information from the display
|
|
|
|
// list whenever we paint, so we don't actually need to do this. However, to
|
|
|
|
// avoid behavior changes during the transition from the old image visibility
|
|
|
|
// code, we'll leave it in for now.
|
|
|
|
UpdateVisibilitySynchronously();
|
2013-09-15 04:05:05 +04:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageFrame::ReflowCallbackCanceled()
|
|
|
|
{
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Computes the width of the specified string. aMaxWidth specifies the maximum
|
|
|
|
// width available. Once this limit is reached no more characters are measured.
|
|
|
|
// The number of characters that fit within the maximum width are returned in
|
1998-10-02 05:12:39 +04:00
|
|
|
// aMaxFit. NOTE: it is assumed that the fontmetrics have already been selected
|
|
|
|
// into the rendering context before this is called (for performance). MMP
|
2006-07-31 11:08:45 +04:00
|
|
|
nscoord
|
2014-01-04 19:02:17 +04:00
|
|
|
nsImageFrame::MeasureString(const char16_t* aString,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aLength,
|
1998-11-20 20:21:02 +03:00
|
|
|
nscoord aMaxWidth,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t& aMaxFit,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext& aContext,
|
2014-10-24 19:28:14 +04:00
|
|
|
nsFontMetrics& aFontMetrics)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
nscoord totalWidth = 0;
|
2014-10-24 19:28:14 +04:00
|
|
|
aFontMetrics.SetTextRunRTL(false);
|
|
|
|
nscoord spaceWidth = aFontMetrics.SpaceWidth();
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
aMaxFit = 0;
|
|
|
|
while (aLength > 0) {
|
|
|
|
// Find the next place we can line break
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = aLength;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool trailingSpace = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < aLength; i++) {
|
2012-11-30 20:04:11 +04:00
|
|
|
if (dom::IsSpaceCharacter(aString[i]) && (i > 0)) {
|
1998-09-09 02:34:40 +04:00
|
|
|
len = i; // don't include the space when measuring
|
2011-10-17 18:59:28 +04:00
|
|
|
trailingSpace = true;
|
1998-09-09 02:34:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Measure this chunk of text, and see if it fits
|
2007-01-23 05:58:55 +03:00
|
|
|
nscoord width =
|
2014-10-26 20:57:49 +03:00
|
|
|
nsLayoutUtils::AppUnitWidthOfStringBidi(aString, len, this, aFontMetrics,
|
|
|
|
aContext);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool fits = (totalWidth + width) <= aMaxWidth;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// If it fits on the line, or it's the first word we've processed then
|
|
|
|
// include it
|
|
|
|
if (fits || (0 == totalWidth)) {
|
|
|
|
// New piece fits
|
|
|
|
totalWidth += width;
|
|
|
|
|
|
|
|
// If there's a trailing space then see if it fits as well
|
|
|
|
if (trailingSpace) {
|
|
|
|
if ((totalWidth + spaceWidth) <= aMaxWidth) {
|
|
|
|
totalWidth += spaceWidth;
|
|
|
|
} else {
|
|
|
|
// Space won't fit. Leave it at the end but don't include it in
|
|
|
|
// the width
|
2011-10-17 18:59:28 +04:00
|
|
|
fits = false;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMaxFit += len;
|
|
|
|
aString += len;
|
|
|
|
aLength -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fits) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-31 11:08:45 +04:00
|
|
|
return totalWidth;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Formats the alt-text to fit within the specified rectangle. Breaks lines
|
|
|
|
// between words if a word would extend past the edge of the rectangle
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::DisplayAltText(nsPresContext* aPresContext,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext& aRenderingContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
const nsString& aAltText,
|
|
|
|
const nsRect& aRect)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
// Set font and color
|
2017-06-09 22:14:53 +03:00
|
|
|
aRenderingContext.SetColor(Color::FromABGR(StyleColor()->mColor));
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetInflatedFontMetricsForFrame(this);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Format the text to display within the formatting rect
|
|
|
|
|
2011-04-08 08:18:43 +04:00
|
|
|
nscoord maxAscent = fm->MaxAscent();
|
|
|
|
nscoord maxDescent = fm->MaxDescent();
|
2015-01-06 23:56:03 +03:00
|
|
|
nscoord lineHeight = fm->MaxHeight(); // line-relative, so an x-coordinate
|
|
|
|
// length if writing mode is vertical
|
|
|
|
|
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
bool isVertical = wm.IsVertical();
|
|
|
|
|
|
|
|
fm->SetVertical(isVertical);
|
|
|
|
fm->SetTextOrientation(StyleVisibility()->mTextOrientation);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// XXX It would be nice if there was a way to have the font metrics tell
|
|
|
|
// use where to break the text given a maximum width. At a minimum we need
|
|
|
|
// to be able to get the break character...
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* str = aAltText.get();
|
2015-01-06 23:56:03 +03:00
|
|
|
int32_t strLen = aAltText.Length();
|
|
|
|
nsPoint pt = wm.IsVerticalRL() ? aRect.TopRight() - nsPoint(lineHeight, 0)
|
|
|
|
: aRect.TopLeft();
|
|
|
|
nscoord iSize = isVertical ? aRect.height : aRect.width;
|
2009-07-12 17:32:48 +04:00
|
|
|
|
|
|
|
if (!aPresContext->BidiEnabled() && HasRTLChars(aAltText)) {
|
|
|
|
aPresContext->SetBidiEnabled();
|
|
|
|
}
|
|
|
|
|
2004-10-12 01:52:36 +04:00
|
|
|
// Always show the first line, even if we have to clip it below
|
2011-09-29 10:19:26 +04:00
|
|
|
bool firstLine = true;
|
2015-01-06 23:56:03 +03:00
|
|
|
while (strLen > 0) {
|
|
|
|
if (!firstLine) {
|
|
|
|
// If we've run out of space, break out of the loop
|
|
|
|
if ((!isVertical && (pt.y + maxDescent) >= aRect.YMost()) ||
|
|
|
|
(wm.IsVerticalRL() && (pt.x + maxDescent < aRect.x)) ||
|
|
|
|
(wm.IsVerticalLR() && (pt.x + maxDescent >= aRect.XMost()))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Determine how much of the text to display on this line
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t maxFit; // number of characters that fit
|
2015-01-06 23:56:03 +03:00
|
|
|
nscoord strWidth = MeasureString(str, strLen, iSize, maxFit,
|
2014-10-24 19:28:14 +04:00
|
|
|
aRenderingContext, *fm);
|
2015-01-06 23:56:03 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Display the text
|
2006-07-31 11:08:45 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (aPresContext->BidiEnabled()) {
|
2015-01-06 23:56:03 +03:00
|
|
|
nsBidiDirection dir;
|
|
|
|
nscoord x, y;
|
|
|
|
|
|
|
|
if (isVertical) {
|
2015-09-24 12:23:35 +03:00
|
|
|
x = pt.x + maxDescent;
|
2015-01-06 23:56:03 +03:00
|
|
|
if (wm.IsBidiLTR()) {
|
|
|
|
y = aRect.y;
|
|
|
|
dir = NSBIDI_LTR;
|
|
|
|
} else {
|
|
|
|
y = aRect.YMost() - strWidth;
|
|
|
|
dir = NSBIDI_RTL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
y = pt.y + maxAscent;
|
|
|
|
if (wm.IsBidiLTR()) {
|
|
|
|
x = aRect.x;
|
|
|
|
dir = NSBIDI_LTR;
|
|
|
|
} else {
|
|
|
|
x = aRect.XMost() - strWidth;
|
|
|
|
dir = NSBIDI_RTL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = nsBidiPresUtils::RenderText(str, maxFit, dir,
|
|
|
|
aPresContext, aRenderingContext,
|
2015-12-16 00:56:41 +03:00
|
|
|
aRenderingContext.GetDrawTarget(),
|
|
|
|
*fm, x, y);
|
2006-07-31 11:08:45 +04:00
|
|
|
}
|
2014-10-24 14:00:23 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsLayoutUtils::DrawUniDirString(str, maxFit,
|
2015-01-06 23:56:03 +03:00
|
|
|
isVertical
|
|
|
|
? nsPoint(pt.x + maxDescent, pt.y)
|
|
|
|
: nsPoint(pt.x, pt.y + maxAscent),
|
|
|
|
*fm, aRenderingContext);
|
2014-10-24 14:00:23 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Move to the next line
|
|
|
|
str += maxFit;
|
|
|
|
strLen -= maxFit;
|
2015-01-06 23:56:03 +03:00
|
|
|
if (wm.IsVerticalRL()) {
|
|
|
|
pt.x -= lineHeight;
|
|
|
|
} else if (wm.IsVerticalLR()) {
|
|
|
|
pt.x += lineHeight;
|
|
|
|
} else {
|
|
|
|
pt.y += lineHeight;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
firstLine = false;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
struct nsRecessedBorder : public nsStyleBorder {
|
2006-12-27 17:21:43 +03:00
|
|
|
nsRecessedBorder(nscoord aBorderWidth, nsPresContext* aPresContext)
|
|
|
|
: nsStyleBorder(aPresContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2005-04-29 19:44:38 +04:00
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2016-09-27 13:16:35 +03:00
|
|
|
mBorderColor[side] = StyleComplexColor::FromColor(NS_RGB(0, 0, 0));
|
2011-04-19 07:07:22 +04:00
|
|
|
mBorder.Side(side) = aBorderWidth;
|
2005-05-05 20:03:06 +04:00
|
|
|
// Note: use SetBorderStyle here because we want to affect
|
|
|
|
// mComputedBorder
|
2005-04-29 19:44:38 +04:00
|
|
|
SetBorderStyle(side, NS_STYLE_BORDER_STYLE_INSET);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-29 09:48:44 +04:00
|
|
|
class nsDisplayAltFeedback : public nsDisplayItem {
|
|
|
|
public:
|
|
|
|
nsDisplayAltFeedback(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {}
|
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
virtual nsDisplayItemGeometry*
|
2015-03-21 19:28:04 +03:00
|
|
|
AllocateGeometry(nsDisplayListBuilder* aBuilder) override
|
2015-03-18 05:40:16 +03:00
|
|
|
{
|
|
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2017-08-24 18:09:44 +03:00
|
|
|
nsRegion* aInvalidRegion) const override
|
2015-03-18 05:40:16 +03:00
|
|
|
{
|
|
|
|
auto geometry =
|
|
|
|
static_cast<const nsDisplayItemGenericImageGeometry*>(aGeometry);
|
|
|
|
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages() &&
|
|
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
2017-08-24 18:09:44 +03:00
|
|
|
bool* aSnap) const override
|
2012-08-29 09:48:44 +04:00
|
|
|
{
|
|
|
|
*aSnap = false;
|
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
|
|
|
}
|
|
|
|
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx) override
|
2012-08-29 09:48:44 +04:00
|
|
|
{
|
2015-03-18 05:40:16 +03:00
|
|
|
// Always sync decode, because these icons are UI, and since they're not
|
|
|
|
// discardable we'll pay the price of sync decoding at most once.
|
|
|
|
uint32_t flags = imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
|
2012-08-29 09:48:44 +04:00
|
|
|
nsImageFrame* f = static_cast<nsImageFrame*>(mFrame);
|
2017-12-12 10:49:59 +03:00
|
|
|
DrawResult result =
|
2015-03-18 05:40:16 +03:00
|
|
|
f->DisplayAltFeedback(*aCtx,
|
|
|
|
mVisibleRect,
|
|
|
|
ToReferenceFrame(),
|
|
|
|
flags);
|
|
|
|
|
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
2012-08-29 09:48:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("AltFeedback", TYPE_ALT_FEEDBACK)
|
|
|
|
};
|
|
|
|
|
2017-12-12 10:49:59 +03:00
|
|
|
DrawResult
|
2017-06-09 22:14:53 +03:00
|
|
|
nsImageFrame::DisplayAltFeedback(gfxContext& aRenderingContext,
|
2015-03-18 05:40:16 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsPoint aPt,
|
|
|
|
uint32_t aFlags)
|
1998-09-22 07:34:44 +04:00
|
|
|
{
|
2009-08-12 18:23:38 +04:00
|
|
|
// We should definitely have a gIconLoad here.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(gIconLoad, "How did we succeed in Init then?");
|
2009-08-12 18:23:38 +04:00
|
|
|
|
2015-07-10 03:13:31 +03:00
|
|
|
// Whether we draw the broken or loading icon.
|
|
|
|
bool isLoading = IMAGE_OK(GetContent()->AsElement()->State(), true);
|
|
|
|
|
1999-09-17 01:37:37 +04:00
|
|
|
// Calculate the inner area
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect inner = GetInnerArea() + aPt;
|
1998-09-22 07:34:44 +04:00
|
|
|
|
1999-09-17 01:37:37 +04:00
|
|
|
// Display a recessed one pixel border
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord borderEdgeWidth = nsPresContext::CSSPixelsToAppUnits(ALT_BORDER_WIDTH);
|
1999-09-17 01:37:37 +04:00
|
|
|
|
2002-03-26 23:14:05 +03:00
|
|
|
// if inner area is empty, then make it big enough for at least the icon
|
|
|
|
if (inner.IsEmpty()){
|
2007-02-07 10:46:44 +03:00
|
|
|
inner.SizeTo(2*(nsPresContext::CSSPixelsToAppUnits(ICON_SIZE+ICON_PADDING+ALT_BORDER_WIDTH)),
|
|
|
|
2*(nsPresContext::CSSPixelsToAppUnits(ICON_SIZE+ICON_PADDING+ALT_BORDER_WIDTH)));
|
2002-03-26 23:14:05 +03:00
|
|
|
}
|
|
|
|
|
1999-09-17 01:37:37 +04:00
|
|
|
// Make sure we have enough room to actually render the border within
|
|
|
|
// our frame bounds
|
|
|
|
if ((inner.width < 2 * borderEdgeWidth) || (inner.height < 2 * borderEdgeWidth)) {
|
2017-12-12 10:49:59 +03:00
|
|
|
return DrawResult::SUCCESS;
|
1999-09-17 01:37:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paint the border
|
2015-07-10 03:13:31 +03:00
|
|
|
if (!isLoading || gIconLoad->mPrefShowLoadingPlaceholder) {
|
|
|
|
nsRecessedBorder recessedBorder(borderEdgeWidth, PresContext());
|
2015-10-23 05:54:49 +03:00
|
|
|
|
|
|
|
// Assert that we're not drawing a border-image here; if we were, we
|
2017-12-12 10:49:59 +03:00
|
|
|
// couldn't ignore the DrawResult that PaintBorderWithStyleBorder returns.
|
2015-10-23 05:54:49 +03:00
|
|
|
MOZ_ASSERT(recessedBorder.mBorderImageSource.GetType() == eStyleImageType_Null);
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused <<
|
2015-10-23 05:54:49 +03:00
|
|
|
nsCSSRendering::PaintBorderWithStyleBorder(PresContext(), aRenderingContext,
|
|
|
|
this, inner, inner,
|
|
|
|
recessedBorder, mStyleContext,
|
|
|
|
PaintBorderFlags::SYNC_DECODE_IMAGES);
|
2015-07-10 03:13:31 +03:00
|
|
|
}
|
1998-09-22 07:34:44 +04:00
|
|
|
|
|
|
|
// Adjust the inner rect to account for the one pixel recessed border,
|
|
|
|
// and a six pixel padding on each edge
|
2017-07-06 15:00:35 +03:00
|
|
|
inner.Deflate(nsPresContext::CSSPixelsToAppUnits(ICON_PADDING+ALT_BORDER_WIDTH),
|
2007-02-07 10:46:44 +03:00
|
|
|
nsPresContext::CSSPixelsToAppUnits(ICON_PADDING+ALT_BORDER_WIDTH));
|
1998-09-22 07:34:44 +04:00
|
|
|
if (inner.IsEmpty()) {
|
2017-12-12 10:49:59 +03:00
|
|
|
return DrawResult::SUCCESS;
|
1998-09-22 07:34:44 +04:00
|
|
|
}
|
|
|
|
|
2014-10-20 13:55:48 +04:00
|
|
|
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
|
|
|
|
|
1998-09-22 07:34:44 +04:00
|
|
|
// Clip so we don't render outside the inner rect
|
2017-06-09 22:14:53 +03:00
|
|
|
aRenderingContext.Save();
|
|
|
|
aRenderingContext.Clip(
|
|
|
|
NSRectToSnappedRect(inner, PresContext()->AppUnitsPerDevPixel(), *drawTarget));
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2017-12-12 10:49:59 +03:00
|
|
|
DrawResult result = DrawResult::NOT_READY;
|
2015-03-18 05:40:16 +03:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// Check if we should display image placeholders
|
2015-07-10 03:13:31 +03:00
|
|
|
if (!gIconLoad->mPrefShowPlaceholders ||
|
|
|
|
(isLoading && !gIconLoad->mPrefShowLoadingPlaceholder)) {
|
2017-12-12 10:49:59 +03:00
|
|
|
result = DrawResult::SUCCESS;
|
2015-03-18 05:40:16 +03:00
|
|
|
} else {
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord size = nsPresContext::CSSPixelsToAppUnits(ICON_SIZE);
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2015-07-10 03:13:31 +03:00
|
|
|
imgIRequest* request = isLoading
|
|
|
|
? nsImageFrame::gIconLoad->mLoadingImage
|
|
|
|
: nsImageFrame::gIconLoad->mBrokenImage;
|
|
|
|
|
2009-08-12 18:23:38 +04:00
|
|
|
// If we weren't previously displaying an icon, register ourselves
|
|
|
|
// as an observer for load and animation updates and flag that we're
|
|
|
|
// doing so now.
|
2015-07-10 03:13:31 +03:00
|
|
|
if (request && !mDisplayingIcon) {
|
2009-08-12 18:23:38 +04:00
|
|
|
gIconLoad->AddIconObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisplayingIcon = true;
|
2009-08-12 18:23:38 +04:00
|
|
|
}
|
|
|
|
|
2015-01-06 23:56:03 +03:00
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
bool flushRight =
|
|
|
|
(!wm.IsVertical() && !wm.IsBidiLTR()) || wm.IsVerticalRL();
|
2009-08-12 18:23:38 +04:00
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
// If the icon in question is loaded, draw it.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t imageStatus = 0;
|
2015-07-10 03:13:31 +03:00
|
|
|
if (request)
|
|
|
|
request->GetImageStatus(&imageStatus);
|
2017-11-01 09:54:17 +03:00
|
|
|
if (imageStatus & imgIRequest::STATUS_LOAD_COMPLETE &&
|
|
|
|
!(imageStatus & imgIRequest::STATUS_ERROR)) {
|
2002-04-10 18:45:05 +04:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
2015-07-10 03:13:31 +03:00
|
|
|
request->GetImage(getter_AddRefs(imgCon));
|
2014-12-11 05:42:37 +03:00
|
|
|
MOZ_ASSERT(imgCon, "Load complete, but no image container?");
|
2015-01-06 23:56:03 +03:00
|
|
|
nsRect dest(flushRight ? inner.XMost() - size : inner.x,
|
2009-08-12 18:23:38 +04:00
|
|
|
inner.y, size, size);
|
2017-06-09 22:14:53 +03:00
|
|
|
result = nsLayoutUtils::DrawSingleImage(aRenderingContext, PresContext(), imgCon,
|
2016-05-25 19:01:18 +03:00
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(this), dest, aDirtyRect,
|
2017-01-11 04:48:29 +03:00
|
|
|
/* no SVGImageContext */ Nothing(), aFlags);
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
// If we could not draw the icon, just draw some graffiti in the mean time.
|
2017-12-12 10:49:59 +03:00
|
|
|
if (result == DrawResult::NOT_READY) {
|
2014-10-17 15:53:16 +04:00
|
|
|
ColorPattern color(ToDeviceColor(Color(1.f, 0.f, 0.f, 1.f)));
|
2014-10-16 15:03:44 +04:00
|
|
|
|
2015-01-06 23:56:03 +03:00
|
|
|
nscoord iconXPos = flushRight ? inner.XMost() - size : inner.x;
|
2014-10-16 15:03:44 +04:00
|
|
|
|
|
|
|
// stroked rect:
|
|
|
|
nsRect rect(iconXPos, inner.y, size, size);
|
|
|
|
Rect devPxRect =
|
|
|
|
ToRect(nsLayoutUtils::RectToGfxRect(rect, PresContext()->AppUnitsPerDevPixel()));
|
|
|
|
drawTarget->StrokeRect(devPxRect, color);
|
|
|
|
|
|
|
|
// filled circle in bottom right quadrant of stroked rect:
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord twoPX = nsPresContext::CSSPixelsToAppUnits(2);
|
2014-10-16 15:03:44 +04:00
|
|
|
rect = nsRect(iconXPos + size/2, inner.y + size/2,
|
|
|
|
size/2 - twoPX, size/2 - twoPX);
|
|
|
|
devPxRect =
|
|
|
|
ToRect(nsLayoutUtils::RectToGfxRect(rect, PresContext()->AppUnitsPerDevPixel()));
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
|
2014-10-16 15:03:44 +04:00
|
|
|
AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Path> ellipse = builder->Finish();
|
2014-10-16 15:03:44 +04:00
|
|
|
drawTarget->Fill(ellipse, color);
|
2011-04-08 05:04:40 +04:00
|
|
|
}
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// Reduce the inner rect by the width of the icon, and leave an
|
|
|
|
// additional ICON_PADDING pixels for padding
|
2015-01-06 23:56:03 +03:00
|
|
|
int32_t paddedIconSize =
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(ICON_SIZE + ICON_PADDING);
|
|
|
|
if (wm.IsVertical()) {
|
|
|
|
inner.y += paddedIconSize;
|
|
|
|
inner.height -= paddedIconSize;
|
|
|
|
} else {
|
|
|
|
if (!flushRight) {
|
|
|
|
inner.x += paddedIconSize;
|
|
|
|
}
|
|
|
|
inner.width -= paddedIconSize;
|
|
|
|
}
|
2002-04-10 18:45:05 +04:00
|
|
|
}
|
1998-09-22 07:34:44 +04:00
|
|
|
|
|
|
|
// If there's still room, display the alt-text
|
|
|
|
if (!inner.IsEmpty()) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIContent* content = GetContent();
|
2001-11-07 08:02:42 +03:00
|
|
|
if (content) {
|
2017-08-04 07:40:52 +03:00
|
|
|
nsAutoString altText;
|
2015-03-03 14:09:00 +03:00
|
|
|
nsCSSFrameConstructor::GetAlternateTextFor(content,
|
|
|
|
content->NodeInfo()->NameAtom(),
|
2003-11-19 04:20:56 +03:00
|
|
|
altText);
|
2007-03-31 01:11:41 +04:00
|
|
|
DisplayAltText(PresContext(), aRenderingContext, altText, inner);
|
1998-09-22 07:34:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
aRenderingContext.Restore();
|
2015-03-18 05:40:16 +03:00
|
|
|
|
|
|
|
return result;
|
1998-09-22 07:34:44 +04:00
|
|
|
}
|
|
|
|
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2015-12-04 06:16:59 +03:00
|
|
|
static void PaintDebugImageMap(nsIFrame* aFrame, DrawTarget* aDrawTarget,
|
2014-10-16 13:51:14 +04:00
|
|
|
const nsRect& aDirtyRect, nsPoint aPt)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsImageFrame* f = static_cast<nsImageFrame*>(aFrame);
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect inner = f->GetInnerArea() + aPt;
|
2014-09-11 10:48:10 +04:00
|
|
|
gfxPoint devPixelOffset =
|
|
|
|
nsLayoutUtils::PointToGfxPoint(inner.TopLeft(),
|
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel());
|
2015-12-04 06:16:59 +03:00
|
|
|
AutoRestoreTransform autoRestoreTransform(aDrawTarget);
|
|
|
|
aDrawTarget->SetTransform(
|
|
|
|
aDrawTarget->GetTransform().PreTranslate(ToPoint(devPixelOffset)));
|
|
|
|
f->GetImageMap()->Draw(aFrame, *aDrawTarget,
|
2014-10-17 15:53:16 +04:00
|
|
|
ColorPattern(ToDeviceColor(Color(0.f, 0.f, 0.f, 1.f))));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
#endif
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void
|
|
|
|
nsDisplayImage::Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx)
|
2016-04-22 16:08:25 +03:00
|
|
|
{
|
2013-04-26 02:08:58 +04:00
|
|
|
uint32_t flags = imgIContainer::FLAG_NONE;
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
|
|
|
if (aBuilder->IsPaintingToWindow()) {
|
|
|
|
flags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
}
|
2015-02-05 00:50:56 +03:00
|
|
|
|
2017-12-12 10:49:59 +03:00
|
|
|
DrawResult result = static_cast<nsImageFrame*>(mFrame)->
|
2013-04-26 02:08:58 +04:00
|
|
|
PaintImage(*aCtx, ToReferenceFrame(), mVisibleRect, mImage, flags);
|
2015-02-05 00:50:56 +03:00
|
|
|
|
2017-12-12 10:49:59 +03:00
|
|
|
if (result == DrawResult::NOT_READY ||
|
|
|
|
result == DrawResult::INCOMPLETE ||
|
|
|
|
result == DrawResult::TEMPORARY_ERROR) {
|
2016-04-22 16:08:25 +03:00
|
|
|
// If the current image failed to paint because it's still loading or
|
|
|
|
// decoding, try painting the previous image.
|
|
|
|
if (mPrevImage) {
|
|
|
|
result = static_cast<nsImageFrame*>(mFrame)->
|
|
|
|
PaintImage(*aCtx, ToReferenceFrame(), mVisibleRect, mPrevImage, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItemGeometry*
|
|
|
|
nsDisplayImage::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2002-03-26 23:14:05 +03:00
|
|
|
|
2013-06-26 20:43:27 +04:00
|
|
|
void
|
|
|
|
nsDisplayImage::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2017-08-24 18:09:44 +03:00
|
|
|
nsRegion* aInvalidRegion) const
|
2013-06-26 20:43:27 +04:00
|
|
|
{
|
2015-02-05 00:50:56 +03:00
|
|
|
auto geometry =
|
|
|
|
static_cast<const nsDisplayItemGenericImageGeometry*>(aGeometry);
|
|
|
|
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages() &&
|
2015-02-10 10:27:39 +03:00
|
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
2013-06-26 20:43:27 +04:00
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayImageContainer::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
2016-04-07 09:52:35 +03:00
|
|
|
already_AddRefed<imgIContainer>
|
|
|
|
nsDisplayImage::GetImage()
|
|
|
|
{
|
|
|
|
nsCOMPtr<imgIContainer> image = mImage;
|
|
|
|
return image.forget();
|
|
|
|
}
|
|
|
|
|
2015-04-08 04:55:28 +03:00
|
|
|
nsRect
|
2017-08-24 18:09:44 +03:00
|
|
|
nsDisplayImage::GetDestRect() const
|
2011-01-18 00:47:18 +03:00
|
|
|
{
|
2015-04-08 04:55:28 +03:00
|
|
|
bool snap = true;
|
|
|
|
const nsRect frameContentBox = GetBounds(&snap);
|
|
|
|
|
|
|
|
nsImageFrame* imageFrame = static_cast<nsImageFrame*>(mFrame);
|
2015-07-20 05:30:35 +03:00
|
|
|
return imageFrame->PredictedDestRect(frameContentBox);
|
2012-05-03 18:05:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LayerState
|
|
|
|
nsDisplayImage::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters)
|
2012-05-03 18:05:55 +04:00
|
|
|
{
|
2017-04-21 18:11:38 +03:00
|
|
|
if (!nsDisplayItem::ForceActiveLayers() &&
|
|
|
|
!ShouldUseAdvancedLayer(aManager, gfxPrefs::LayersAllowImageLayers)) {
|
2016-11-24 08:11:30 +03:00
|
|
|
bool animated = false;
|
|
|
|
if (!nsLayoutUtils::AnimatedImageLayersEnabled() ||
|
|
|
|
mImage->GetType() != imgIContainer::TYPE_RASTER ||
|
|
|
|
NS_FAILED(mImage->GetAnimated(&animated)) ||
|
|
|
|
!animated) {
|
|
|
|
if (!aManager->IsCompositingCheap() ||
|
|
|
|
!nsLayoutUtils::GPUImageScalingEnabled()) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
2013-05-30 17:50:50 +04:00
|
|
|
}
|
2012-05-03 18:05:55 +04:00
|
|
|
|
2016-11-24 08:11:30 +03:00
|
|
|
if (!animated) {
|
|
|
|
int32_t imageWidth;
|
|
|
|
int32_t imageHeight;
|
|
|
|
mImage->GetWidth(&imageWidth);
|
|
|
|
mImage->GetHeight(&imageHeight);
|
2012-05-03 18:05:55 +04:00
|
|
|
|
2016-11-24 08:11:30 +03:00
|
|
|
NS_ASSERTION(imageWidth != 0 && imageHeight != 0, "Invalid image size!");
|
2012-05-03 18:05:55 +04:00
|
|
|
|
2016-11-24 08:11:30 +03:00
|
|
|
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
const LayoutDeviceRect destRect =
|
|
|
|
LayoutDeviceRect::FromAppUnits(GetDestRect(), factor);
|
|
|
|
const LayerRect destLayerRect = destRect * aParameters.Scale();
|
2012-05-03 18:05:55 +04:00
|
|
|
|
2016-11-24 08:11:30 +03:00
|
|
|
// Calculate the scaling factor for the frame.
|
|
|
|
const gfxSize scale = gfxSize(destLayerRect.width / imageWidth,
|
|
|
|
destLayerRect.height / imageHeight);
|
2012-05-03 18:05:55 +04:00
|
|
|
|
2016-11-24 08:11:30 +03:00
|
|
|
// If we are not scaling at all, no point in separating this into a layer.
|
|
|
|
if (scale.width == 1.0f && scale.height == 1.0f) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
2012-05-03 18:05:55 +04:00
|
|
|
|
2016-11-24 08:11:30 +03:00
|
|
|
// If the target size is pretty small, no point in using a layer.
|
|
|
|
if (destLayerRect.width * destLayerRect.height < 64 * 64) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
2013-05-30 17:50:50 +04:00
|
|
|
}
|
2012-11-28 06:34:45 +04:00
|
|
|
}
|
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
|
2017-06-23 17:11:42 +03:00
|
|
|
if (!CanOptimizeToImageLayer(aManager, aBuilder)) {
|
2012-11-28 06:34:45 +04:00
|
|
|
return LAYER_NONE;
|
2012-05-03 18:05:55 +04:00
|
|
|
}
|
|
|
|
|
2017-05-24 11:16:40 +03:00
|
|
|
// Image layer doesn't support draw focus ring for image map.
|
|
|
|
nsImageFrame* f = static_cast<nsImageFrame*>(mFrame);
|
|
|
|
if (f->HasImageMap()) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
|
|
|
|
2012-05-03 18:05:55 +04:00
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
|
2014-11-20 05:34:50 +03:00
|
|
|
|
|
|
|
/* virtual */ nsRegion
|
|
|
|
nsDisplayImage::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2017-08-24 18:09:44 +03:00
|
|
|
bool* aSnap) const
|
2014-11-20 05:34:50 +03:00
|
|
|
{
|
2016-01-05 07:38:17 +03:00
|
|
|
*aSnap = false;
|
2016-08-23 05:15:38 +03:00
|
|
|
if (mImage && mImage->WillDrawOpaqueNow()) {
|
2015-12-03 17:20:10 +03:00
|
|
|
const nsRect frameContentBox = GetBounds(aSnap);
|
|
|
|
return GetDestRect().Intersect(frameContentBox);
|
2014-11-20 05:34:50 +03:00
|
|
|
}
|
|
|
|
return nsRegion();
|
|
|
|
}
|
|
|
|
|
2012-05-03 18:05:55 +04:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayImage::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters)
|
2012-05-03 18:05:55 +04:00
|
|
|
{
|
2016-11-25 08:48:04 +03:00
|
|
|
uint32_t flags = imgIContainer::FLAG_ASYNC_NOTIFY;
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
2015-03-18 05:40:16 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageContainer> container =
|
2015-03-18 05:40:16 +03:00
|
|
|
mImage->GetImageContainer(aManager, flags);
|
|
|
|
if (!container) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-05-03 18:05:55 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageLayer> layer = static_cast<ImageLayer*>
|
2013-05-30 06:42:28 +04:00
|
|
|
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, this));
|
|
|
|
if (!layer) {
|
|
|
|
layer = aManager->CreateImageLayer();
|
|
|
|
if (!layer)
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-05-03 18:05:55 +04:00
|
|
|
layer->SetContainer(container);
|
2015-04-08 04:55:28 +03:00
|
|
|
ConfigureLayer(layer, aParameters);
|
2012-05-03 18:05:55 +04:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2017-06-29 01:12:36 +03:00
|
|
|
bool
|
|
|
|
nsDisplayImage::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-06-29 01:12:36 +03:00
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
|
|
|
{
|
2017-11-23 14:55:06 +03:00
|
|
|
if (!mImage) {
|
2017-06-29 01:12:36 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:55:06 +03:00
|
|
|
if (mFrame->IsImageFrame()) {
|
|
|
|
// Image layer doesn't support draw focus ring for image map.
|
|
|
|
nsImageFrame* f = static_cast<nsImageFrame*>(mFrame);
|
|
|
|
if (f->HasImageMap()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-29 01:12:36 +03:00
|
|
|
uint32_t flags = imgIContainer::FLAG_ASYNC_NOTIFY;
|
2017-11-23 14:55:06 +03:00
|
|
|
if (aDisplayListBuilder->IsPaintingToWindow()) {
|
|
|
|
flags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
}
|
2017-06-29 01:12:36 +03:00
|
|
|
if (aDisplayListBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:55:06 +03:00
|
|
|
const int32_t factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
const LayoutDeviceRect destRect(
|
|
|
|
LayoutDeviceRect::FromAppUnits(GetDestRect(), factor));
|
|
|
|
Maybe<SVGImageContext> svgContext;
|
|
|
|
IntSize decodeSize =
|
|
|
|
nsLayoutUtils::ComputeImageContainerDrawingParameters(mImage, mFrame, destRect,
|
|
|
|
aSc, flags, svgContext);
|
2017-06-29 01:12:36 +03:00
|
|
|
RefPtr<ImageContainer> container =
|
2017-11-23 14:55:06 +03:00
|
|
|
mImage->GetImageContainerAtSize(aManager, decodeSize, svgContext, flags);
|
2017-06-29 01:12:36 +03:00
|
|
|
if (!container) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-19 05:25:11 +03:00
|
|
|
return aManager->CommandBuilder().PushImage(this, container, aBuilder, aResources, aSc, destRect);
|
2017-06-29 01:12:36 +03:00
|
|
|
}
|
|
|
|
|
2017-12-12 10:49:59 +03:00
|
|
|
DrawResult
|
2017-06-09 22:14:53 +03:00
|
|
|
nsImageFrame::PaintImage(gfxContext& aRenderingContext, nsPoint aPt,
|
2009-09-13 02:44:18 +04:00
|
|
|
const nsRect& aDirtyRect, imgIContainer* aImage,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2014-10-16 13:51:14 +04:00
|
|
|
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Render the image into our content area (the area inside
|
|
|
|
// the borders and padding)
|
2007-03-20 03:58:20 +03:00
|
|
|
NS_ASSERTION(GetInnerArea().width == mComputedSize.width, "bad width");
|
2014-11-15 03:45:24 +03:00
|
|
|
|
|
|
|
// NOTE: We use mComputedSize instead of just GetInnerArea()'s own size here,
|
|
|
|
// because GetInnerArea() might be smaller if we're fragmented, whereas
|
|
|
|
// mComputedSize has our full content-box size (which we need for
|
|
|
|
// ComputeObjectDestRect to work correctly).
|
|
|
|
nsRect constraintRect(aPt + GetInnerArea().TopLeft(), mComputedSize);
|
|
|
|
constraintRect.y -= GetContinuationOffset();
|
|
|
|
|
2014-11-26 03:46:14 +03:00
|
|
|
nsPoint anchorPoint;
|
2014-11-15 03:45:24 +03:00
|
|
|
nsRect dest = nsLayoutUtils::ComputeObjectDestRect(constraintRect,
|
|
|
|
mIntrinsicSize,
|
|
|
|
mIntrinsicRatio,
|
2014-11-26 03:46:14 +03:00
|
|
|
StylePosition(),
|
|
|
|
&anchorPoint);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2015-07-08 00:00:08 +03:00
|
|
|
uint32_t flags = aFlags;
|
|
|
|
if (mForceSyncDecoding) {
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
|
|
|
|
2017-03-02 17:52:25 +03:00
|
|
|
Maybe<SVGImageContext> svgContext;
|
2017-03-28 13:43:15 +03:00
|
|
|
SVGImageContext::MaybeStoreContextPaint(svgContext, this, aImage);
|
2017-03-02 17:52:25 +03:00
|
|
|
|
2017-12-12 10:49:59 +03:00
|
|
|
DrawResult result =
|
2017-06-09 22:14:53 +03:00
|
|
|
nsLayoutUtils::DrawSingleImage(aRenderingContext,
|
2015-02-05 00:50:56 +03:00
|
|
|
PresContext(), aImage,
|
2016-05-25 19:01:18 +03:00
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(this), dest, aDirtyRect,
|
2017-03-02 17:52:25 +03:00
|
|
|
svgContext, flags, &anchorPoint);
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
2017-07-03 21:35:14 +03:00
|
|
|
if (nsImageMap* map = GetImageMap()) {
|
2014-09-11 10:48:10 +04:00
|
|
|
gfxPoint devPixelOffset =
|
2014-11-15 03:45:24 +03:00
|
|
|
nsLayoutUtils::PointToGfxPoint(dest.TopLeft(),
|
2014-09-11 10:48:10 +04:00
|
|
|
PresContext()->AppUnitsPerDevPixel());
|
2014-10-16 13:51:14 +04:00
|
|
|
AutoRestoreTransform autoRestoreTransform(drawTarget);
|
|
|
|
drawTarget->SetTransform(
|
|
|
|
drawTarget->GetTransform().PreTranslate(ToPoint(devPixelOffset)));
|
|
|
|
|
|
|
|
// solid white stroke:
|
2014-10-19 16:22:22 +04:00
|
|
|
ColorPattern white(ToDeviceColor(Color(1.f, 1.f, 1.f, 1.f)));
|
|
|
|
map->Draw(this, *drawTarget, white);
|
2014-10-16 13:51:14 +04:00
|
|
|
|
|
|
|
// then dashed black stroke over the top:
|
2014-10-19 16:22:22 +04:00
|
|
|
ColorPattern black(ToDeviceColor(Color(0.f, 0.f, 0.f, 1.f)));
|
2014-10-16 13:51:14 +04:00
|
|
|
StrokeOptions strokeOptions;
|
|
|
|
nsLayoutUtils::InitDashPattern(strokeOptions, NS_STYLE_BORDER_STYLE_DOTTED);
|
2014-10-19 16:22:22 +04:00
|
|
|
map->Draw(this, *drawTarget, black, strokeOptions);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2015-02-05 00:50:56 +03:00
|
|
|
|
2017-12-12 10:49:59 +03:00
|
|
|
if (result == DrawResult::SUCCESS) {
|
2016-04-22 16:08:25 +03:00
|
|
|
mPrevImage = aImage;
|
2017-12-12 10:49:59 +03:00
|
|
|
} else if (result == DrawResult::BAD_IMAGE) {
|
2016-04-22 16:08:25 +03:00
|
|
|
mPrevImage = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
return result;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2003-11-06 19:03:34 +03:00
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsImageFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2010-09-09 19:21:47 +04:00
|
|
|
|
2014-11-15 03:45:23 +03:00
|
|
|
uint32_t clipFlags =
|
|
|
|
nsStyleUtil::ObjectPropsMightCauseOverflow(StylePosition()) ?
|
|
|
|
0 : DisplayListClipState::ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT;
|
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox
|
2014-11-15 03:45:23 +03:00
|
|
|
clip(aBuilder, this, clipFlags);
|
2013-03-04 13:56:02 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
if (mComputedSize.width != 0 && mComputedSize.height != 0) {
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
NS_ASSERTION(imageLoader, "Not an image loading content?");
|
|
|
|
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates contentState = mContent->AsElement()->State();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool imageOK = IMAGE_OK(contentState, true);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-08-29 02:39:06 +04:00
|
|
|
// 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
|
|
|
|
// currently some code that violates this invariant.
|
|
|
|
if (!imageOK || !mImage || !SizeIsAvailable(currentRequest)) {
|
2006-01-26 05:29:17 +03:00
|
|
|
// No image yet, or image load failed. Draw the alt-text and an icon
|
|
|
|
// indicating the status
|
2013-03-04 13:56:02 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 15:08:08 +04:00
|
|
|
nsDisplayAltFeedback(aBuilder, this));
|
2015-07-13 03:10:07 +03:00
|
|
|
|
|
|
|
// This image is visible (we are being asked to paint it) but it's not
|
|
|
|
// decoded yet. And we are not going to ask the image to draw, so this
|
|
|
|
// may be the only chance to tell it that it should decode.
|
|
|
|
if (currentRequest) {
|
2015-10-30 02:37:42 +03:00
|
|
|
uint32_t status = 0;
|
|
|
|
currentRequest->GetImageStatus(&status);
|
|
|
|
if (!(status & imgIRequest::STATUS_DECODE_COMPLETE)) {
|
|
|
|
MaybeDecodeForPredictedSize();
|
|
|
|
}
|
2017-03-27 10:54:00 +03:00
|
|
|
// Increase loading priority if the image is ready to be displayed.
|
|
|
|
if (!(status & imgIRequest::STATUS_LOAD_COMPLETE)){
|
|
|
|
currentRequest->BoostPriority(imgIRequest::CATEGORY_DISPLAY);
|
|
|
|
}
|
2015-07-13 03:10:07 +03:00
|
|
|
}
|
2013-08-29 02:39:06 +04:00
|
|
|
} else {
|
2013-03-04 13:56:02 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2016-04-22 16:08:25 +03:00
|
|
|
nsDisplayImage(aBuilder, this, mImage, mPrevImage));
|
2009-08-12 18:23:38 +04:00
|
|
|
|
|
|
|
// If we were previously displaying an icon, we're not anymore
|
|
|
|
if (mDisplayingIcon) {
|
|
|
|
gIconLoad->RemoveIconObserver(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisplayingIcon = false;
|
2009-08-12 18:23:38 +04:00
|
|
|
}
|
|
|
|
|
2003-11-06 19:03:34 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-27 00:55:04 +04:00
|
|
|
if (GetShowFrameBorders() && GetImageMap()) {
|
2013-02-14 15:08:08 +04:00
|
|
|
aLists.Outlines()->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayGeneric(aBuilder, this, PaintDebugImageMap, "DebugImageMap",
|
2017-08-07 07:07:43 +03:00
|
|
|
DisplayItemType::TYPE_DEBUG_IMAGE_MAP));
|
2003-11-06 19:03:34 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
#endif
|
1999-04-10 21:32:33 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
2001-12-18 04:29:49 +03:00
|
|
|
|
2010-10-07 08:25:47 +04:00
|
|
|
if (ShouldDisplaySelection()) {
|
2013-03-04 13:56:02 +04:00
|
|
|
DisplaySelectionOverlay(aBuilder, aLists.Content(),
|
2013-02-14 15:08:08 +04:00
|
|
|
nsISelectionDisplay::DISPLAY_IMAGES);
|
2010-10-07 08:25:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsImageFrame::ShouldDisplaySelection()
|
|
|
|
{
|
2006-01-26 05:29:17 +03:00
|
|
|
// XXX what on EARTH is this code for?
|
|
|
|
nsresult result;
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = PresContext();
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t displaySelection = presContext->PresShell()->GetSelectionFlags();
|
2001-12-18 04:29:49 +03:00
|
|
|
if (!(displaySelection & nsISelectionDisplay::DISPLAY_IMAGES))
|
2010-10-07 08:25:47 +04:00
|
|
|
return false;//no need to check the blue border, we cannot be drawn selected
|
2003-04-23 03:18:34 +04:00
|
|
|
//insert hook here for image selection drawing
|
|
|
|
#if IMAGE_EDITOR_CHECK
|
|
|
|
//check to see if this frame is in an editor context
|
|
|
|
//isEditor check. this needs to be changed to have better way to check
|
2017-07-06 15:00:35 +03:00
|
|
|
if (displaySelection == nsISelectionDisplay::DISPLAY_ALL)
|
2003-04-23 03:18:34 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
2006-01-26 05:29:17 +03:00
|
|
|
result = GetSelectionController(presContext, getter_AddRefs(selCon));
|
2003-04-23 03:18:34 +04:00
|
|
|
if (NS_SUCCEEDED(result) && selCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
|
|
|
|
if (NS_SUCCEEDED(result) && selection)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t rangeCount;
|
2003-04-23 03:18:34 +04:00
|
|
|
selection->GetRangeCount(&rangeCount);
|
|
|
|
if (rangeCount == 1) //if not one then let code drop to nsFrame::Paint
|
|
|
|
{
|
2003-07-29 01:25:13 +04:00
|
|
|
nsCOMPtr<nsIContent> parentContent = mContent->GetParent();
|
2003-04-23 03:18:34 +04:00
|
|
|
if (parentContent)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t thisOffset = parentContent->IndexOf(mContent);
|
2003-04-23 03:18:34 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> parentNode = do_QueryInterface(parentContent);
|
|
|
|
nsCOMPtr<nsIDOMNode> rangeNode;
|
2017-07-19 16:49:52 +03:00
|
|
|
uint32_t rangeOffset;
|
2003-04-23 03:18:34 +04:00
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
selection->GetRangeAt(0,getter_AddRefs(range));
|
|
|
|
if (range)
|
|
|
|
{
|
|
|
|
range->GetStartContainer(getter_AddRefs(rangeNode));
|
|
|
|
range->GetStartOffset(&rangeOffset);
|
|
|
|
|
2017-07-19 16:49:52 +03:00
|
|
|
if (parentNode && rangeNode && rangeNode == parentNode &&
|
|
|
|
static_cast<int32_t>(rangeOffset) == thisOffset) {
|
2003-04-23 03:18:34 +04:00
|
|
|
range->GetEndContainer(getter_AddRefs(rangeNode));
|
|
|
|
range->GetEndOffset(&rangeOffset);
|
2017-07-19 16:49:52 +03:00
|
|
|
// +1 since that would mean this whole content is selected only
|
|
|
|
if (rangeNode == parentNode &&
|
|
|
|
static_cast<int32_t>(rangeOffset) == thisOffset + 1) {
|
|
|
|
// Do not allow nsFrame do draw any further selection
|
|
|
|
return false;
|
|
|
|
}
|
2003-04-23 03:18:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-10-07 08:25:47 +04:00
|
|
|
return true;
|
2002-08-17 05:46:58 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:19 +03:00
|
|
|
nsImageMap*
|
2011-09-27 00:55:04 +04:00
|
|
|
nsImageFrame::GetImageMap()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2001-04-18 04:14:34 +04:00
|
|
|
if (!mImageMap) {
|
2017-07-03 21:35:14 +03:00
|
|
|
if (nsIContent* map = GetMapElement()) {
|
2001-04-18 04:14:34 +04:00
|
|
|
mImageMap = new nsImageMap();
|
2011-09-27 00:55:04 +04:00
|
|
|
mImageMap->Init(this, map);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
1999-01-09 03:13:19 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
return mImageMap;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::IsServerImageMap()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::ismap);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2005-08-23 07:57:07 +04:00
|
|
|
// Translate an point that is relative to our frame
|
|
|
|
// into a localized pixel coordinate that is relative to the
|
1999-07-08 23:38:08 +04:00
|
|
|
// content area of this frame (inside the border+padding).
|
|
|
|
void
|
2004-12-26 22:48:54 +03:00
|
|
|
nsImageFrame::TranslateEventCoords(const nsPoint& aPoint,
|
2007-02-18 19:49:54 +03:00
|
|
|
nsIntPoint& aResult)
|
1999-07-08 23:38:08 +04:00
|
|
|
{
|
|
|
|
nscoord x = aPoint.x;
|
|
|
|
nscoord y = aPoint.y;
|
|
|
|
|
|
|
|
// Subtract out border and padding here so that the coordinates are
|
|
|
|
// now relative to the content area of this frame.
|
2004-12-26 22:48:54 +03:00
|
|
|
nsRect inner = GetInnerArea();
|
1999-07-08 23:38:08 +04:00
|
|
|
x -= inner.x;
|
|
|
|
y -= inner.y;
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
aResult.x = nsPresContext::AppUnitsToIntCSSPixels(x);
|
|
|
|
aResult.y = nsPresContext::AppUnitsToIntCSSPixels(y);
|
1999-07-08 23:38:08 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-02-02 23:02:34 +03:00
|
|
|
nsImageFrame::GetAnchorHREFTargetAndNode(nsIURI** aHref, nsString& aTarget,
|
2007-07-11 17:05:05 +04:00
|
|
|
nsIContent** aNode)
|
1999-07-08 23:38:08 +04:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool status = false;
|
2001-04-11 12:12:10 +04:00
|
|
|
aTarget.Truncate();
|
2012-07-30 18:20:58 +04:00
|
|
|
*aHref = nullptr;
|
|
|
|
*aNode = nullptr;
|
1999-07-08 23:38:08 +04:00
|
|
|
|
|
|
|
// Walk up the content tree, looking for an nsIDOMAnchorElement
|
2003-07-29 01:25:13 +04:00
|
|
|
for (nsIContent* content = mContent->GetParent();
|
|
|
|
content; content = content->GetParent()) {
|
2013-08-08 09:26:32 +04:00
|
|
|
nsCOMPtr<dom::Link> link(do_QueryInterface(content));
|
2004-02-10 19:57:00 +03:00
|
|
|
if (link) {
|
2009-09-23 19:11:48 +04:00
|
|
|
nsCOMPtr<nsIURI> href = content->GetHrefURI();
|
|
|
|
if (href) {
|
|
|
|
href->Clone(aHref);
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
status = (*aHref != nullptr);
|
2004-02-10 19:57:00 +03:00
|
|
|
|
2017-09-23 00:56:51 +03:00
|
|
|
RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::FromContent(content);
|
2004-02-10 19:57:00 +03:00
|
|
|
if (anchor) {
|
|
|
|
anchor->GetTarget(aTarget);
|
1999-07-08 23:44:42 +04:00
|
|
|
}
|
2006-02-02 23:02:34 +03:00
|
|
|
NS_ADDREF(*aNode = content);
|
1999-07-08 23:38:08 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-07-08 23:44:42 +04:00
|
|
|
return status;
|
1999-07-08 23:38:08 +04:00
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
nsresult
|
2013-10-02 07:46:04 +04:00
|
|
|
nsImageFrame::GetContentForEvent(WidgetEvent* aEvent,
|
2000-02-11 04:24:59 +03:00
|
|
|
nsIContent** aContent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aContent);
|
2009-09-02 06:46:33 +04:00
|
|
|
|
|
|
|
nsIFrame* f = nsLayoutUtils::GetNonGeneratedAncestor(this);
|
|
|
|
if (f != this) {
|
2011-09-27 00:55:04 +04:00
|
|
|
return f->GetContentForEvent(aEvent, aContent);
|
2009-09-02 06:46:33 +04:00
|
|
|
}
|
|
|
|
|
2010-02-03 05:07:19 +03:00
|
|
|
// XXX We need to make this special check for area element's capturing the
|
|
|
|
// mouse due to bug 135040. Remove it once that's fixed.
|
|
|
|
nsIContent* capturingContent =
|
2013-09-24 14:04:16 +04:00
|
|
|
aEvent->HasMouseEventMessage() ? nsIPresShell::GetCapturingContent() :
|
|
|
|
nullptr;
|
2010-02-03 05:07:19 +03:00
|
|
|
if (capturingContent && capturingContent->GetPrimaryFrame() == this) {
|
|
|
|
*aContent = capturingContent;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-03 21:35:14 +03:00
|
|
|
if (nsImageMap* map = GetImageMap()) {
|
2007-02-18 19:49:54 +03:00
|
|
|
nsIntPoint p;
|
2005-08-23 07:57:07 +04:00
|
|
|
TranslateEventCoords(
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
|
2011-10-30 23:51:19 +04:00
|
|
|
nsCOMPtr<nsIContent> area = map->GetArea(p.x, p.y);
|
|
|
|
if (area) {
|
2011-11-17 22:01:24 +04:00
|
|
|
area.forget(aContent);
|
2000-02-11 04:24:59 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-29 07:43:05 +04:00
|
|
|
*aContent = GetContent();
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
2000-02-11 04:24:59 +03:00
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// XXX what should clicks on transparent pixels do?
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::HandleEvent(nsPresContext* aPresContext,
|
2013-10-02 07:46:03 +04:00
|
|
|
WidgetGUIEvent* aEvent,
|
1999-11-24 09:03:41 +03:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2016-05-16 10:45:43 +03:00
|
|
|
if ((aEvent->mMessage == eMouseClick &&
|
2013-10-22 12:55:20 +04:00
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) ||
|
2015-08-29 02:58:29 +03:00
|
|
|
aEvent->mMessage == eMouseMove) {
|
2011-09-27 00:55:04 +04:00
|
|
|
nsImageMap* map = GetImageMap();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isServerMap = IsServerImageMap();
|
2017-07-03 21:35:14 +03:00
|
|
|
if (map || isServerMap) {
|
2007-02-18 19:49:54 +03:00
|
|
|
nsIntPoint p;
|
2006-11-17 00:35:39 +03:00
|
|
|
TranslateEventCoords(
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool inside = false;
|
2006-11-17 00:35:39 +03:00
|
|
|
// Even though client-side image map triggering happens
|
|
|
|
// through content, we need to make sure we're not inside
|
|
|
|
// (in case we deal with a case of both client-side and
|
|
|
|
// sever-side on the same image - it happens!)
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != map) {
|
2011-10-30 23:51:19 +04:00
|
|
|
inside = !!map->GetArea(p.x, p.y);
|
2006-11-17 00:35:39 +03:00
|
|
|
}
|
2001-05-23 11:00:37 +04:00
|
|
|
|
2006-11-17 00:35:39 +03:00
|
|
|
if (!inside && isServerMap) {
|
|
|
|
|
|
|
|
// Server side image maps use the href in a containing anchor
|
|
|
|
// element to provide the basis for the destination url.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsAutoString target;
|
2007-07-11 17:05:05 +04:00
|
|
|
nsCOMPtr<nsIContent> anchorNode;
|
2006-11-17 00:35:39 +03:00
|
|
|
if (GetAnchorHREFTargetAndNode(getter_AddRefs(uri), target,
|
|
|
|
getter_AddRefs(anchorNode))) {
|
|
|
|
// XXX if the mouse is over/clicked in the border/padding area
|
|
|
|
// we should probably just pretend nothing happened. Nav4
|
|
|
|
// keeps the x,y coordinates positive as we do; IE doesn't
|
|
|
|
// bother. Both of them send the click through even when the
|
|
|
|
// mouse is over the border.
|
|
|
|
if (p.x < 0) p.x = 0;
|
|
|
|
if (p.y < 0) p.y = 0;
|
2016-08-31 13:10:10 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2016-08-31 13:10:10 +03:00
|
|
|
nsresult rv = uri->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-11-17 00:35:39 +03:00
|
|
|
spec += nsPrintfCString("?%d,%d", p.x, p.y);
|
2016-08-31 13:10:10 +03:00
|
|
|
rv = uri->SetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool clicked = false;
|
2016-05-16 10:45:43 +03:00
|
|
|
if (aEvent->mMessage == eMouseClick && !aEvent->DefaultPrevented()) {
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
2011-10-17 18:59:28 +04:00
|
|
|
clicked = true;
|
1999-07-08 23:44:42 +04:00
|
|
|
}
|
2007-07-11 17:05:05 +04:00
|
|
|
nsContentUtils::TriggerLink(anchorNode, aPresContext, uri, target,
|
2011-10-17 18:59:28 +04:00
|
|
|
clicked, true, true);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-13 01:24:07 +04:00
|
|
|
|
2016-04-18 08:58:30 +03:00
|
|
|
return nsAtomicContainerFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2004-12-31 00:56:11 +03:00
|
|
|
nsImageFrame::GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2017-07-03 21:35:14 +03:00
|
|
|
if (nsImageMap* map = GetImageMap()) {
|
2007-02-18 19:49:54 +03:00
|
|
|
nsIntPoint p;
|
2004-12-26 22:48:54 +03:00
|
|
|
TranslateEventCoords(aPoint, p);
|
2011-10-30 23:51:19 +04:00
|
|
|
nsCOMPtr<nsIContent> area = map->GetArea(p.x, p.y);
|
|
|
|
if (area) {
|
2006-04-21 01:02:10 +04:00
|
|
|
// Use the cursor from the style of the *area* element.
|
|
|
|
// XXX Using the image as the parent style context isn't
|
|
|
|
// technically correct, but it's probably the right thing to do
|
|
|
|
// here, since it means that areas on which the cursor isn't
|
|
|
|
// specified will inherit the style from the image.
|
2017-07-06 15:00:35 +03:00
|
|
|
RefPtr<nsStyleContext> areaStyle =
|
2017-11-09 05:00:48 +03:00
|
|
|
PresShell()->StyleSet()->
|
2016-11-02 09:11:24 +03:00
|
|
|
ResolveStyleFor(area->AsElement(), StyleContext(),
|
|
|
|
LazyComputeBehavior::Allow);
|
2013-08-03 08:11:06 +04:00
|
|
|
FillCursorInformationFromStyle(areaStyle->StyleUserInterface(),
|
|
|
|
aCursor);
|
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
|
|
|
|
aCursor.mCursor = NS_STYLE_CURSOR_DEFAULT;
|
1998-11-24 01:21:13 +03:00
|
|
|
}
|
2013-08-03 08:11:06 +04:00
|
|
|
return NS_OK;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
2004-12-31 00:56:11 +03:00
|
|
|
return nsFrame::GetCursor(aPoint, aCursor);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsImageFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2016-04-18 08:58:30 +03:00
|
|
|
nsresult rv = nsAtomicContainerFrame::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
2004-09-30 23:23:40 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-09-29 01:22:31 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::alt == aAttribute)
|
2004-09-30 23:23:40 +04:00
|
|
|
{
|
2017-11-09 05:00:48 +03:00
|
|
|
PresShell()->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2000-04-17 18:40:46 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-09-25 20:35:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
|
2016-03-26 00:49:43 +03:00
|
|
|
void
|
2016-09-12 08:19:07 +03:00
|
|
|
nsImageFrame::OnVisibilityChange(Visibility aNewVisibility,
|
2017-02-13 20:07:40 +03:00
|
|
|
const Maybe<OnNonvisible>& aNonvisibleAction)
|
2016-03-26 00:49:43 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (!imageLoader) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Should have an nsIImageLoadingContent");
|
2016-09-12 08:19:07 +03:00
|
|
|
nsAtomicContainerFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction);
|
2016-03-26 00:49:43 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-12 08:19:07 +03:00
|
|
|
imageLoader->OnVisibilityChange(aNewVisibility, aNonvisibleAction);
|
2016-03-26 00:49:43 +03:00
|
|
|
|
2016-09-12 08:19:08 +03:00
|
|
|
if (aNewVisibility == Visibility::APPROXIMATELY_VISIBLE) {
|
2016-03-26 00:49:43 +03:00
|
|
|
MaybeDecodeForPredictedSize();
|
|
|
|
}
|
|
|
|
|
2016-09-12 08:19:07 +03:00
|
|
|
nsAtomicContainerFrame::OnVisibilityChange(aNewVisibility, aNonvisibleAction);
|
2016-03-26 00:49:43 +03:00
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2005-05-09 21:46:06 +04:00
|
|
|
nsImageFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ImageFrame"), aResult);
|
|
|
|
}
|
|
|
|
|
2013-04-30 22:38:52 +04:00
|
|
|
void
|
2014-01-27 02:07:02 +04:00
|
|
|
nsImageFrame::List(FILE* out, const char* aPrefix, uint32_t aFlags) const
|
2001-10-31 07:43:48 +03:00
|
|
|
{
|
2014-01-27 02:07:02 +04:00
|
|
|
nsCString str;
|
|
|
|
ListGeneric(str, aPrefix, aFlags);
|
2001-10-31 07:43:48 +03:00
|
|
|
|
|
|
|
// output the img src url
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
if (currentRequest) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
currentRequest->GetURI(getter_AddRefs(uri));
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString uristr;
|
2003-03-19 06:47:09 +03:00
|
|
|
uri->GetAsciiSpec(uristr);
|
2014-01-27 02:07:02 +04:00
|
|
|
str += nsPrintfCString(" [src=%s]", uristr.get());
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2002-03-21 01:14:27 +03:00
|
|
|
}
|
2014-01-27 02:07:02 +04:00
|
|
|
fprintf_stderr(out, "%s\n", str.get());
|
2001-10-31 07:43:48 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-28 14:13:13 +04:00
|
|
|
nsIFrame::LogicalSides
|
2016-07-21 13:36:39 +03:00
|
|
|
nsImageFrame::GetLogicalSkipSides(const ReflowInput* aReflowInput) const
|
2007-03-20 03:58:20 +03:00
|
|
|
{
|
2014-05-05 21:55:54 +04:00
|
|
|
if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak ==
|
2016-08-26 10:14:32 +03:00
|
|
|
StyleBoxDecorationBreak::Clone)) {
|
2014-06-28 14:13:13 +04:00
|
|
|
return LogicalSides();
|
2014-05-05 21:55:54 +04:00
|
|
|
}
|
2014-06-28 14:13:13 +04:00
|
|
|
LogicalSides skip;
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != GetPrevInFlow()) {
|
2014-06-28 14:13:14 +04:00
|
|
|
skip |= eLogicalSideBitsBStart;
|
2007-03-20 03:58:20 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != GetNextInFlow()) {
|
2014-06-28 14:13:14 +04:00
|
|
|
skip |= eLogicalSideBitsBEnd;
|
2007-03-20 03:58:20 +03:00
|
|
|
}
|
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
2011-04-26 10:52:19 +04:00
|
|
|
nsresult
|
2000-01-04 06:06:13 +03:00
|
|
|
nsImageFrame::GetIntrinsicImageSize(nsSize& aSize)
|
|
|
|
{
|
2010-09-09 00:40:38 +04:00
|
|
|
if (mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
aSize.SizeTo(mIntrinsicSize.width.GetCoordValue(),
|
|
|
|
mIntrinsicSize.height.GetCoordValue());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-01-04 06:06:13 +03:00
|
|
|
}
|
|
|
|
|
2001-10-07 22:02:13 +04:00
|
|
|
nsresult
|
2003-03-19 06:47:09 +03:00
|
|
|
nsImageFrame::LoadIcon(const nsAString& aSpec,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext *aPresContext,
|
2012-10-12 16:43:01 +04:00
|
|
|
imgRequestProxy** aRequest)
|
2001-05-04 10:29:59 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2003-03-19 06:47:09 +03:00
|
|
|
NS_PRECONDITION(!aSpec.IsEmpty(), "What happened??");
|
2001-05-04 10:29:59 +04:00
|
|
|
|
2004-01-21 12:35:59 +03:00
|
|
|
if (!sIOService) {
|
2006-06-19 01:18:22 +04:00
|
|
|
rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
|
2004-01-21 12:35:59 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2001-06-06 00:22:52 +04:00
|
|
|
nsCOMPtr<nsIURI> realURI;
|
2004-01-21 12:35:59 +03:00
|
|
|
SpecToURI(aSpec, sIOService, getter_AddRefs(realURI));
|
2014-08-20 01:49:38 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgLoader> il =
|
2012-06-26 08:20:12 +04:00
|
|
|
nsContentUtils::GetImgLoaderForDocument(aPresContext->Document());
|
2001-05-04 10:29:59 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
GetLoadGroup(aPresContext, getter_AddRefs(loadGroup));
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
// For icon loads, we don't need to merge with the loadgroup flags
|
2001-09-29 21:50:15 +04:00
|
|
|
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
|
2015-09-21 00:55:59 +03:00
|
|
|
nsContentPolicyType contentPolicyType = nsIContentPolicy::TYPE_INTERNAL_IMAGE;
|
2001-09-29 21:50:15 +04:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
return il->LoadImage(realURI, /* icon URI */
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, /* initial document URI; this is only
|
2003-03-19 06:47:09 +03:00
|
|
|
relevant for cookies, so does not
|
|
|
|
apply to icons. */
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, /* referrer (not relevant for icons) */
|
2017-01-05 06:29:56 +03:00
|
|
|
mozilla::net::RP_Unset,
|
2016-06-14 14:43:21 +03:00
|
|
|
nullptr, /* principal (not relevant for icons) */
|
2017-09-21 03:09:00 +03:00
|
|
|
0,
|
2003-03-19 06:47:09 +03:00
|
|
|
loadGroup,
|
2009-08-12 18:23:38 +04:00
|
|
|
gIconLoad,
|
2016-04-11 11:58:03 +03:00
|
|
|
nullptr, /* No context */
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, /* Not associated with any particular document */
|
2003-03-19 06:47:09 +03:00
|
|
|
loadFlags,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2014-08-20 01:49:38 +04:00
|
|
|
contentPolicyType,
|
2013-10-16 05:35:44 +04:00
|
|
|
EmptyString(),
|
2017-04-25 04:17:38 +03:00
|
|
|
false, /* aUseUrgentStartForChannel */
|
2003-03-19 06:47:09 +03:00
|
|
|
aRequest);
|
2001-05-04 10:29:59 +04:00
|
|
|
}
|
|
|
|
|
2002-03-13 01:26:11 +03:00
|
|
|
void
|
2003-06-17 20:40:34 +04:00
|
|
|
nsImageFrame::GetDocumentCharacterSet(nsACString& aCharset) const
|
2002-03-13 01:26:11 +03:00
|
|
|
{
|
2003-07-29 01:25:13 +04:00
|
|
|
if (mContent) {
|
2014-08-21 04:38:01 +04:00
|
|
|
NS_ASSERTION(mContent->GetComposedDoc(),
|
2003-07-29 01:25:13 +04:00
|
|
|
"Frame still alive after content removed from document!");
|
2017-06-18 14:37:50 +03:00
|
|
|
mContent->GetComposedDoc()->GetDocumentCharacterSet()->Name(aCharset);
|
2002-03-13 01:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
void
|
2003-03-19 06:47:09 +03:00
|
|
|
nsImageFrame::SpecToURI(const nsAString& aSpec, nsIIOService *aIOService,
|
2002-11-06 15:58:05 +03:00
|
|
|
nsIURI **aURI)
|
2001-05-04 10:29:59 +04:00
|
|
|
{
|
2001-04-15 06:13:49 +04:00
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2003-07-03 06:45:34 +04:00
|
|
|
if (mContent) {
|
2004-01-10 02:54:21 +03:00
|
|
|
baseURI = mContent->GetBaseURI();
|
2003-07-03 06:45:34 +04:00
|
|
|
}
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString charset;
|
2002-03-13 01:26:11 +03:00
|
|
|
GetDocumentCharacterSet(charset);
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_NewURI(aURI, aSpec,
|
|
|
|
charset.IsEmpty() ? nullptr : charset.get(),
|
2002-11-06 15:58:05 +03:00
|
|
|
baseURI, aIOService);
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGroup)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
if (!aPresContext)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aLoadGroup, "null OUT parameter pointer");
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2003-12-21 08:36:36 +03:00
|
|
|
nsIPresShell *shell = aPresContext->GetPresShell();
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
if (!shell)
|
|
|
|
return;
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = shell->GetDocument();
|
2001-03-22 04:38:35 +03:00
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
2014-03-15 23:00:15 +04:00
|
|
|
*aLoadGroup = doc->GetDocumentLoadGroup().take();
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult nsImageFrame::LoadIcons(nsPresContext *aPresContext)
|
2001-11-07 08:02:42 +03:00
|
|
|
{
|
2004-02-03 23:30:02 +03:00
|
|
|
NS_ASSERTION(!gIconLoad, "called LoadIcons twice");
|
|
|
|
|
2009-10-12 23:31:50 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(loadingSrc,"resource://gre-resources/loading-image.png");
|
|
|
|
NS_NAMED_LITERAL_STRING(brokenSrc,"resource://gre-resources/broken-image.png");
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2009-08-12 18:23:38 +04:00
|
|
|
gIconLoad = new IconLoad();
|
2004-02-03 23:30:02 +03:00
|
|
|
NS_ADDREF(gIconLoad);
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult rv;
|
|
|
|
// create a loader and load the images
|
|
|
|
rv = LoadIcon(loadingSrc,
|
|
|
|
aPresContext,
|
2004-02-03 23:30:02 +03:00
|
|
|
getter_AddRefs(gIconLoad->mLoadingImage));
|
2003-03-19 06:47:09 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = LoadIcon(brokenSrc,
|
|
|
|
aPresContext,
|
2004-02-03 23:30:02 +03:00
|
|
|
getter_AddRefs(gIconLoad->mBrokenImage));
|
2014-12-11 05:42:37 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsImageFrame::IconLoad, nsIObserver,
|
|
|
|
imgINotificationObserver)
|
2004-02-03 23:30:02 +03:00
|
|
|
|
2011-05-29 03:39:27 +04:00
|
|
|
static const char* kIconLoadPrefs[] = {
|
2004-02-03 23:30:02 +03:00
|
|
|
"browser.display.force_inline_alttext",
|
2011-05-29 03:39:27 +04:00
|
|
|
"browser.display.show_image_placeholders",
|
2015-07-10 03:13:31 +03:00
|
|
|
"browser.display.show_loading_image_placeholder",
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2004-02-03 23:30:02 +03:00
|
|
|
};
|
|
|
|
|
2009-08-12 18:23:38 +04:00
|
|
|
nsImageFrame::IconLoad::IconLoad()
|
2004-02-03 23:30:02 +03:00
|
|
|
{
|
2011-05-29 03:39:27 +04:00
|
|
|
// register observers
|
2011-05-29 03:39:27 +04:00
|
|
|
Preferences::AddStrongObservers(this, kIconLoadPrefs);
|
2004-04-30 03:34:19 +04:00
|
|
|
GetPrefs();
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
|
|
|
|
2011-06-03 10:07:10 +04:00
|
|
|
void
|
|
|
|
nsImageFrame::IconLoad::Shutdown()
|
|
|
|
{
|
|
|
|
Preferences::RemoveObservers(this, kIconLoadPrefs);
|
|
|
|
// in case the pref service releases us later
|
|
|
|
if (mLoadingImage) {
|
|
|
|
mLoadingImage->CancelAndForgetObserver(NS_ERROR_FAILURE);
|
2012-07-30 18:20:58 +04:00
|
|
|
mLoadingImage = nullptr;
|
2011-06-03 10:07:10 +04:00
|
|
|
}
|
|
|
|
if (mBrokenImage) {
|
|
|
|
mBrokenImage->CancelAndForgetObserver(NS_ERROR_FAILURE);
|
2012-07-30 18:20:58 +04:00
|
|
|
mBrokenImage = nullptr;
|
2011-06-03 10:07:10 +04:00
|
|
|
}
|
|
|
|
}
|
2004-02-03 23:30:02 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::Observe(nsISupports *aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData)
|
2001-11-07 08:02:42 +03:00
|
|
|
{
|
2004-02-03 23:30:02 +03:00
|
|
|
NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
|
|
|
|
"wrong topic");
|
|
|
|
#ifdef DEBUG
|
|
|
|
// assert |aData| is one of our prefs.
|
2015-04-19 04:23:50 +03:00
|
|
|
uint32_t i = 0;
|
|
|
|
for (; i < ArrayLength(kIconLoadPrefs); ++i) {
|
2004-02-03 23:30:02 +03:00
|
|
|
if (NS_ConvertASCIItoUTF16(kIconLoadPrefs[i]) == nsDependentString(aData))
|
|
|
|
break;
|
2015-04-19 04:23:50 +03:00
|
|
|
}
|
|
|
|
MOZ_ASSERT(i < ArrayLength(kIconLoadPrefs));
|
2004-02-03 23:30:02 +03:00
|
|
|
#endif
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2004-04-30 03:34:19 +04:00
|
|
|
GetPrefs();
|
2004-02-03 23:30:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-30 03:34:19 +04:00
|
|
|
void nsImageFrame::IconLoad::GetPrefs()
|
2004-02-03 23:30:02 +03:00
|
|
|
{
|
2004-04-30 03:34:19 +04:00
|
|
|
mPrefForceInlineAltText =
|
2011-05-25 10:31:59 +04:00
|
|
|
Preferences::GetBool("browser.display.force_inline_alttext");
|
2004-04-30 03:34:19 +04:00
|
|
|
|
|
|
|
mPrefShowPlaceholders =
|
2011-09-29 10:19:26 +04:00
|
|
|
Preferences::GetBool("browser.display.show_image_placeholders", true);
|
2015-07-10 03:13:31 +03:00
|
|
|
|
|
|
|
mPrefShowLoadingPlaceholder =
|
|
|
|
Preferences::GetBool("browser.display.show_loading_image_placeholder", true);
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2009-08-12 18:23:38 +04:00
|
|
|
NS_IMETHODIMP
|
2015-10-30 02:37:42 +03:00
|
|
|
nsImageFrame::IconLoad::Notify(imgIRequest* aRequest,
|
|
|
|
int32_t aType,
|
|
|
|
const nsIntRect* aData)
|
2009-08-12 18:23:38 +04:00
|
|
|
{
|
2015-10-30 02:37:42 +03:00
|
|
|
MOZ_ASSERT(aRequest);
|
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType != imgINotificationObserver::LOAD_COMPLETE &&
|
|
|
|
aType != imgINotificationObserver::FRAME_UPDATE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
return NS_OK;
|
2009-08-12 18:23:38 +04:00
|
|
|
}
|
|
|
|
|
2015-10-30 02:37:42 +03:00
|
|
|
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
|
|
|
if (!image) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the image's intrinsic size.
|
|
|
|
int32_t width = 0;
|
|
|
|
int32_t height = 0;
|
|
|
|
image->GetWidth(&width);
|
|
|
|
image->GetHeight(&height);
|
|
|
|
|
|
|
|
// Request a decode at that size.
|
|
|
|
image->RequestDecodeForSize(IntSize(width, height),
|
|
|
|
imgIContainer::DECODE_FLAGS_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2009-08-12 18:23:38 +04:00
|
|
|
nsTObserverArray<nsImageFrame*>::ForwardIterator iter(mIconObservers);
|
|
|
|
nsImageFrame *frame;
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
frame = iter.GetNext();
|
2012-08-29 09:39:31 +04:00
|
|
|
frame->InvalidateFrame();
|
2009-08-12 18:23:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsImageListener, imgINotificationObserver)
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
nsImageListener::nsImageListener(nsImageFrame *aFrame) :
|
|
|
|
mFrame(aFrame)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageListener::~nsImageListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageListener::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
return mFrame->Notify(aRequest, aType, aData);
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2007-12-03 12:24:49 +03:00
|
|
|
IsInAutoWidthTableCellForQuirk(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
if (eCompatibility_NavQuirks != aFrame->PresContext()->CompatibilityMode())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-12-03 12:24:49 +03:00
|
|
|
// Check if the parent of the closest nsBlockFrame has auto width.
|
|
|
|
nsBlockFrame *ancestor = nsLayoutUtils::FindNearestBlockAncestor(aFrame);
|
2013-02-16 09:38:33 +04:00
|
|
|
if (ancestor->StyleContext()->GetPseudo() == nsCSSAnonBoxes::cellContent) {
|
2007-12-03 12:24:49 +03:00
|
|
|
// Assume direct parent is a table cell frame.
|
|
|
|
nsFrame *grandAncestor = static_cast<nsFrame*>(ancestor->GetParent());
|
|
|
|
return grandAncestor &&
|
2013-02-17 01:51:02 +04:00
|
|
|
grandAncestor->StylePosition()->mWidth.GetUnit() == eStyleUnit_Auto;
|
2007-12-03 12:24:49 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-12-03 12:24:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2017-06-09 22:14:53 +03:00
|
|
|
nsImageFrame::AddInlineMinISize(gfxContext* aRenderingContext,
|
2016-04-14 02:32:12 +03:00
|
|
|
nsIFrame::InlineMinISizeData* aData)
|
2007-12-03 12:24:49 +03:00
|
|
|
{
|
2016-04-14 02:32:12 +03:00
|
|
|
nscoord isize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
this, nsLayoutUtils::MIN_ISIZE);
|
|
|
|
bool canBreak = !IsInAutoWidthTableCellForQuirk(this);
|
|
|
|
aData->DefaultAddInlineMinISize(this, isize, canBreak);
|
2007-12-03 12:24:49 +03:00
|
|
|
}
|