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/. */
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
#include "gfxContext.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsImageBoxFrame.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2018-03-22 21:20:41 +03:00
|
|
|
#include "mozilla/ComputedStyle.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2015-06-13 03:31:21 +03:00
|
|
|
#include "nsStyleUtil.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsBoxLayoutState.h"
|
|
|
|
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsLeafFrame.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsImageMap.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIURL.h"
|
2001-03-20 02:44:55 +03:00
|
|
|
#include "nsILoadGroup.h"
|
2011-12-28 00:18:48 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsTextFragment.h"
|
2001-11-04 12:32:37 +03:00
|
|
|
#include "nsTransform2D.h"
|
2001-12-18 01:51:39 +03:00
|
|
|
#include "nsITheme.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-03-20 02:44:55 +03:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURI.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2012-09-25 00:29:14 +04:00
|
|
|
#include "ImageLayers.h"
|
|
|
|
#include "ImageContainer.h"
|
2014-08-06 09:19:27 +04:00
|
|
|
#include "nsIContent.h"
|
2001-03-20 02:44:55 +03:00
|
|
|
|
2004-08-04 23:48:55 +04:00
|
|
|
#include "nsContentUtils.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2015-06-13 03:31:21 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2017-01-11 04:48:29 +03:00
|
|
|
#include "SVGImageContext.h"
|
2017-02-04 01:21:29 +03:00
|
|
|
#include "Units.h"
|
2017-09-10 07:45:11 +03:00
|
|
|
#include "mozilla/layers/WebRenderLayerManager.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
|
2017-09-10 07:45:11 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
// Undefine LoadImage to prevent naming conflict with Windows.
|
|
|
|
#undef LoadImage
|
|
|
|
#endif
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
#define ONLOAD_CALLED_TOO_EARLY 1
|
|
|
|
|
2013-10-02 07:46:04 +04:00
|
|
|
using namespace mozilla;
|
2014-09-10 17:26:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2015-02-05 00:50:56 +03:00
|
|
|
using namespace mozilla::image;
|
2012-09-25 00:29:14 +04:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsImageBoxFrameEvent : public Runnable
|
2001-11-03 10:10:51 +03:00
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
nsImageBoxFrameEvent(nsIContent* content, EventMessage message)
|
|
|
|
: mozilla::Runnable("nsImageBoxFrameEvent")
|
|
|
|
, mContent(content)
|
|
|
|
, mMessage(message)
|
|
|
|
{
|
|
|
|
}
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override;
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIContent> mContent;
|
2015-08-26 15:56:59 +03:00
|
|
|
EventMessage mMessage;
|
2006-05-10 21:30:15 +04:00
|
|
|
};
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageBoxFrameEvent::Run()
|
|
|
|
{
|
2018-02-21 01:00:10 +03:00
|
|
|
RefPtr<nsPresContext> pres_context = mContent->OwnerDoc()->GetPresContext();
|
2001-11-03 10:10:51 +03:00
|
|
|
if (!pres_context) {
|
2006-05-10 21:30:15 +04:00
|
|
|
return NS_OK;
|
2001-11-03 10:10:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2013-10-02 07:46:04 +04:00
|
|
|
WidgetEvent event(true, mMessage);
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2012-12-16 05:26:03 +04:00
|
|
|
event.mFlags.mBubbles = false;
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(mContent, pres_context, &event, nullptr, &status);
|
2006-05-10 21:30:15 +04:00
|
|
|
return NS_OK;
|
2001-11-03 10:10:51 +03:00
|
|
|
}
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
// Fire off an event that'll asynchronously call the image elements
|
2001-11-03 10:10:51 +03:00
|
|
|
// onload handler once handled. This is needed since the image library
|
2017-03-26 19:37:10 +03:00
|
|
|
// can't decide if it wants to call its observer methods
|
2001-11-03 10:10:51 +03:00
|
|
|
// synchronously or asynchronously. If an image is loaded from the
|
|
|
|
// cache the notifications come back synchronously, but if the image
|
2017-03-26 19:37:10 +03:00
|
|
|
// is loaded from the network the notifications come back
|
2001-11-03 10:10:51 +03:00
|
|
|
// asynchronously.
|
2018-02-23 08:03:45 +03:00
|
|
|
static void
|
2015-08-26 15:56:59 +03:00
|
|
|
FireImageDOMEvent(nsIContent* aContent, EventMessage aMessage)
|
2001-11-03 10:10:51 +03:00
|
|
|
{
|
2015-09-02 09:07:59 +03:00
|
|
|
NS_ASSERTION(aMessage == eLoad || aMessage == eLoadError,
|
2006-05-10 21:30:15 +04:00
|
|
|
"invalid message");
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsImageBoxFrameEvent(aContent, aMessage);
|
2017-07-26 11:13:35 +03:00
|
|
|
nsresult rv = aContent->OwnerDoc()->Dispatch(TaskCategory::Other,
|
2017-03-16 13:09:13 +03:00
|
|
|
event.forget());
|
|
|
|
if (NS_FAILED(rv)) {
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_WARNING("failed to dispatch image event");
|
2017-03-16 13:09:13 +03:00
|
|
|
}
|
2001-11-03 10:10:51 +03:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
//
|
2001-11-03 10:10:51 +03:00
|
|
|
// NS_NewImageBoxFrame
|
2000-03-31 11:02:06 +04:00
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
// Creates a new image frame and returns it
|
2000-03-31 11:02:06 +04:00
|
|
|
//
|
2005-10-27 01:46:39 +04:00
|
|
|
nsIFrame*
|
2018-03-22 21:20:41 +03:00
|
|
|
NS_NewImageBoxFrame (nsIPresShell* aPresShell, ComputedStyle* aStyle)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2018-03-22 21:20:41 +03:00
|
|
|
return new (aPresShell) nsImageBoxFrame(aStyle);
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsImageBoxFrame)
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsImageBoxFrame::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)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2005-09-07 20:49:21 +04:00
|
|
|
nsresult rv = nsLeafBoxFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
2001-12-04 02:41:13 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::src) {
|
2004-08-04 07:23:37 +04:00
|
|
|
UpdateImage();
|
2017-11-09 05:00:48 +03:00
|
|
|
PresShell()->
|
2007-05-06 23:16:51 +04:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aAttribute == nsGkAtoms::validate)
|
2004-08-04 07:23:37 +04:00
|
|
|
UpdateLoadFlags();
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2002-11-19 08:06:36 +03:00
|
|
|
return rv;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
nsImageBoxFrame::nsImageBoxFrame(ComputedStyle* aStyle)
|
|
|
|
: nsLeafBoxFrame(aStyle, kClassID)
|
2017-04-30 18:30:08 +03:00
|
|
|
, mIntrinsicSize(0, 0)
|
|
|
|
, mLoadFlags(nsIRequest::LOAD_NORMAL)
|
|
|
|
, mRequestRegistered(false)
|
|
|
|
, mUseSrcAttr(false)
|
|
|
|
, mSuppressStyleCheck(false)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2014-07-24 21:03:26 +04:00
|
|
|
MarkIntrinsicISizesDirty();
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsImageBoxFrame::~nsImageBoxFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 */ void
|
2014-07-24 21:03:26 +04:00
|
|
|
nsImageBoxFrame::MarkIntrinsicISizesDirty()
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
|
|
|
SizeNeedsRecalc(mImageSize);
|
2014-07-24 21:03:26 +04:00
|
|
|
nsLeafBoxFrame::MarkIntrinsicISizesDirty();
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2017-11-07 03:20:33 +03:00
|
|
|
nsImageBoxFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2011-11-10 01:39:16 +04:00
|
|
|
if (mImageRequest) {
|
|
|
|
nsLayoutUtils::DeregisterImageRequest(PresContext(), mImageRequest,
|
|
|
|
&mRequestRegistered);
|
|
|
|
|
|
|
|
// Release image loader first so that it's refcnt can go to zero
|
2008-12-20 01:35:50 +03:00
|
|
|
mImageRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
2001-03-20 02:44:55 +03:00
|
|
|
|
|
|
|
if (mListener)
|
2012-07-30 18:20:58 +04:00
|
|
|
reinterpret_cast<nsImageBoxListener*>(mListener.get())->SetFrame(nullptr); // set the frame to null so we don't send messages to a dead object.
|
2001-03-20 02:44:55 +03:00
|
|
|
|
2017-11-07 03:20:33 +03:00
|
|
|
nsLeafBoxFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsImageBoxFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2001-03-20 02:44:55 +03:00
|
|
|
if (!mListener) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsImageBoxListener> listener = new nsImageBoxListener();
|
2001-03-20 02:44:55 +03:00
|
|
|
listener->SetFrame(this);
|
2015-03-11 20:19:43 +03:00
|
|
|
mListener = listener.forget();
|
2001-03-20 02:44:55 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mSuppressStyleCheck = true;
|
2013-03-20 05:47:48 +04:00
|
|
|
nsLeafBoxFrame::Init(aContent, aParent, aPrevInFlow);
|
2011-10-17 18:59:28 +04:00
|
|
|
mSuppressStyleCheck = false;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2001-11-07 09:40:04 +03:00
|
|
|
UpdateLoadFlags();
|
2004-02-19 21:56:13 +03:00
|
|
|
UpdateImage();
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-04 07:23:37 +04:00
|
|
|
nsImageBoxFrame::UpdateImage()
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2011-11-10 01:39:16 +04:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
|
2016-05-17 11:13:28 +03:00
|
|
|
RefPtr<imgRequestProxy> oldImageRequest = mImageRequest;
|
|
|
|
|
2004-08-04 07:23:37 +04:00
|
|
|
if (mImageRequest) {
|
2011-11-10 01:39:16 +04:00
|
|
|
nsLayoutUtils::DeregisterImageRequest(presContext, mImageRequest,
|
|
|
|
&mRequestRegistered);
|
2009-09-02 19:45:57 +04:00
|
|
|
mImageRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
|
2012-07-30 18:20:58 +04:00
|
|
|
mImageRequest = nullptr;
|
2004-08-04 07:23:37 +04:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
// get the new image src
|
2003-10-02 02:53:56 +04:00
|
|
|
nsAutoString src;
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src);
|
2003-10-02 02:53:56 +04:00
|
|
|
mUseSrcAttr = !src.IsEmpty();
|
|
|
|
if (mUseSrcAttr) {
|
2014-08-21 04:38:01 +04:00
|
|
|
nsIDocument* doc = mContent->GetComposedDoc();
|
2016-05-17 11:13:28 +03:00
|
|
|
if (doc) {
|
2016-12-14 23:52:57 +03:00
|
|
|
nsContentPolicyType contentPolicyType;
|
2017-10-11 12:07:35 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> triggeringPrincipal;
|
2017-09-21 03:09:00 +03:00
|
|
|
uint64_t requestContextID = 0;
|
2016-12-14 23:52:57 +03:00
|
|
|
nsContentUtils::GetContentPolicyTypeForUIImageLoading(mContent,
|
2017-10-11 12:07:35 +03:00
|
|
|
getter_AddRefs(triggeringPrincipal),
|
2017-09-21 03:09:00 +03:00
|
|
|
contentPolicyType,
|
|
|
|
&requestContextID);
|
2016-10-13 10:43:56 +03:00
|
|
|
|
2016-05-17 11:13:28 +03:00
|
|
|
nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
|
|
|
|
src,
|
|
|
|
doc,
|
|
|
|
baseURI);
|
|
|
|
if (uri) {
|
2017-10-11 12:07:35 +03:00
|
|
|
nsresult rv = nsContentUtils::LoadImage(uri, mContent, doc,
|
|
|
|
triggeringPrincipal,
|
|
|
|
requestContextID,
|
|
|
|
doc->GetDocumentURI(),
|
|
|
|
doc->GetReferrerPolicy(),
|
2016-05-17 11:13:28 +03:00
|
|
|
mListener, mLoadFlags,
|
2017-10-11 12:07:35 +03:00
|
|
|
EmptyString(),
|
|
|
|
getter_AddRefs(mImageRequest),
|
2016-10-13 10:43:56 +03:00
|
|
|
contentPolicyType);
|
2016-05-17 11:13:28 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && mImageRequest) {
|
|
|
|
nsLayoutUtils::RegisterImageRequestIfAnimated(presContext,
|
|
|
|
mImageRequest,
|
|
|
|
&mRequestRegistered);
|
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
2004-08-04 07:23:37 +04:00
|
|
|
}
|
2003-10-02 02:53:56 +04:00
|
|
|
} else {
|
2001-12-18 01:51:39 +03:00
|
|
|
// Only get the list-style-image if we aren't being drawn
|
|
|
|
// by a native theme.
|
2017-05-21 12:15:00 +03:00
|
|
|
uint8_t appearance = StyleDisplay()->mAppearance;
|
2011-11-02 02:28:48 +04:00
|
|
|
if (!(appearance && nsBox::gTheme &&
|
2012-07-30 18:20:58 +04:00
|
|
|
nsBox::gTheme->ThemeSupportsWidget(nullptr, this, appearance))) {
|
2004-08-04 07:23:37 +04:00
|
|
|
// get the list-style-image
|
2013-02-17 01:51:02 +04:00
|
|
|
imgRequestProxy *styleRequest = StyleList()->GetListStyleImage();
|
2004-08-04 07:23:37 +04:00
|
|
|
if (styleRequest) {
|
2017-07-19 21:15:11 +03:00
|
|
|
styleRequest->SyncClone(mListener,
|
|
|
|
mContent->GetComposedDoc(),
|
|
|
|
getter_AddRefs(mImageRequest));
|
2004-08-04 07:23:37 +04:00
|
|
|
}
|
|
|
|
}
|
2004-07-31 11:42:12 +04:00
|
|
|
}
|
2005-02-04 20:39:43 +03:00
|
|
|
|
|
|
|
if (!mImageRequest) {
|
|
|
|
// We have no image, so size to 0
|
|
|
|
mIntrinsicSize.SizeTo(0, 0);
|
2010-08-24 02:43:06 +04:00
|
|
|
} else {
|
|
|
|
// We don't want discarding or decode-on-draw for xul images.
|
2016-11-26 10:56:26 +03:00
|
|
|
mImageRequest->StartDecoding(imgIContainer::FLAG_NONE);
|
2010-08-24 02:43:06 +04:00
|
|
|
mImageRequest->LockImage();
|
2005-02-04 20:39:43 +03:00
|
|
|
}
|
2016-05-17 11:13:28 +03:00
|
|
|
|
|
|
|
// Do this _after_ locking the new image in case they are the same image.
|
|
|
|
if (oldImageRequest) {
|
|
|
|
oldImageRequest->UnlockImage();
|
|
|
|
}
|
2004-07-31 11:42:12 +04:00
|
|
|
}
|
|
|
|
|
2001-11-07 09:40:04 +03:00
|
|
|
void
|
|
|
|
nsImageBoxFrame::UpdateLoadFlags()
|
|
|
|
{
|
2017-12-07 21:13:50 +03:00
|
|
|
static Element::AttrValuesArray strings[] =
|
2012-07-30 18:20:58 +04:00
|
|
|
{&nsGkAtoms::always, &nsGkAtoms::never, nullptr};
|
2017-12-07 21:13:50 +03:00
|
|
|
switch (mContent->AsElement()->FindAttrValueIn(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::validate, strings,
|
|
|
|
eCaseMatters)) {
|
2006-04-24 09:40:11 +04:00
|
|
|
case 0:
|
|
|
|
mLoadFlags = nsIRequest::VALIDATE_ALWAYS;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
mLoadFlags = nsIRequest::VALIDATE_NEVER|nsIRequest::LOAD_FROM_CACHE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mLoadFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
break;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsImageBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists)
|
2011-11-02 02:28:48 +04:00
|
|
|
{
|
2017-08-07 05:23:35 +03:00
|
|
|
nsLeafBoxFrame::BuildDisplayList(aBuilder, aLists);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
if ((0 == mRect.width) || (0 == mRect.height)) {
|
|
|
|
// Do not render when given a zero area. This avoids some useless
|
|
|
|
// scaling work while we wait for our image dimensions to arrive
|
|
|
|
// asynchronously.
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2012-10-11 09:44:59 +04:00
|
|
|
|
2015-06-13 03:31:21 +03:00
|
|
|
uint32_t clipFlags =
|
|
|
|
nsStyleUtil::ObjectPropsMightCauseOverflow(StylePosition()) ?
|
|
|
|
0 : DisplayListClipState::ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT;
|
|
|
|
|
|
|
|
DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox
|
|
|
|
clip(aBuilder, this, clipFlags);
|
|
|
|
|
2017-11-16 06:09:28 +03:00
|
|
|
nsDisplayList list;
|
2017-12-13 20:23:04 +03:00
|
|
|
list.AppendToTop(
|
2018-02-13 03:43:28 +03:00
|
|
|
MakeDisplayItem<nsDisplayXULImage>(aBuilder, this));
|
2012-10-11 09:44:59 +04:00
|
|
|
|
|
|
|
CreateOwnLayerIfNeeded(aBuilder, &list);
|
|
|
|
|
|
|
|
aLists.Content()->AppendToTop(&list);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2017-09-10 07:45:11 +03:00
|
|
|
already_AddRefed<imgIContainer>
|
|
|
|
nsImageBoxFrame::GetImageContainerForPainting(const nsPoint& aPt,
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult& aDrawResult,
|
2017-09-10 07:45:11 +03:00
|
|
|
Maybe<nsPoint>& aAnchorPoint,
|
|
|
|
nsRect& aDest)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2015-02-05 00:50:56 +03:00
|
|
|
if (!mImageRequest) {
|
|
|
|
// This probably means we're drawn by a native theme.
|
2017-12-11 18:37:59 +03:00
|
|
|
aDrawResult = ImgDrawResult::SUCCESS;
|
2017-09-10 07:45:11 +03:00
|
|
|
return nullptr;
|
2015-02-05 00:50:56 +03:00
|
|
|
}
|
2004-02-19 21:56:13 +03:00
|
|
|
|
2016-03-01 02:09:13 +03:00
|
|
|
// Don't draw if the image's size isn't available.
|
|
|
|
uint32_t imgStatus;
|
|
|
|
if (!NS_SUCCEEDED(mImageRequest->GetImageStatus(&imgStatus)) ||
|
|
|
|
!(imgStatus & imgIRequest::STATUS_SIZE_AVAILABLE)) {
|
2017-12-11 18:37:59 +03:00
|
|
|
aDrawResult = ImgDrawResult::NOT_READY;
|
2017-09-10 07:45:11 +03:00
|
|
|
return nullptr;
|
2016-03-01 02:09:13 +03:00
|
|
|
}
|
|
|
|
|
2001-04-11 13:01:29 +04:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
2001-03-20 02:44:55 +03:00
|
|
|
mImageRequest->GetImage(getter_AddRefs(imgCon));
|
|
|
|
|
2015-06-13 03:31:21 +03:00
|
|
|
if (!imgCon) {
|
2017-12-11 18:37:59 +03:00
|
|
|
aDrawResult = ImgDrawResult::NOT_READY;
|
2017-09-10 07:45:11 +03:00
|
|
|
return nullptr;
|
2001-03-20 02:44:55 +03:00
|
|
|
}
|
2015-02-05 00:50:56 +03:00
|
|
|
|
2017-09-10 07:45:11 +03:00
|
|
|
aDest = GetDestRect(aPt, aAnchorPoint);
|
2017-12-11 18:37:59 +03:00
|
|
|
aDrawResult = ImgDrawResult::SUCCESS;
|
2017-09-10 07:45:11 +03:00
|
|
|
return imgCon.forget();
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult
|
2017-09-10 07:45:11 +03:00
|
|
|
nsImageBoxFrame::PaintImage(gfxContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect, nsPoint aPt,
|
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result;
|
2017-05-22 12:26:17 +03:00
|
|
|
Maybe<nsPoint> anchorPoint;
|
2017-09-10 07:45:11 +03:00
|
|
|
nsRect dest;
|
|
|
|
nsCOMPtr<imgIContainer> imgCon = GetImageContainerForPainting(aPt, result,
|
|
|
|
anchorPoint,
|
|
|
|
dest);
|
|
|
|
if (!imgCon) {
|
|
|
|
return result;
|
|
|
|
}
|
2017-05-22 12:26:17 +03:00
|
|
|
|
|
|
|
// don't draw if the image is not dirty
|
|
|
|
// XXX(seth): Can this actually happen anymore?
|
|
|
|
nsRect dirty;
|
|
|
|
if (!dirty.IntersectRect(aDirtyRect, dest)) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2017-05-22 12:26:17 +03:00
|
|
|
}
|
|
|
|
|
2015-06-13 03:31:21 +03:00
|
|
|
bool hasSubRect = !mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0);
|
2015-06-13 03:31:21 +03:00
|
|
|
|
2017-05-22 12:26:17 +03:00
|
|
|
Maybe<SVGImageContext> svgContext;
|
|
|
|
SVGImageContext::MaybeStoreContextPaint(svgContext, this, imgCon);
|
|
|
|
return nsLayoutUtils::DrawSingleImage(
|
2017-06-09 22:14:53 +03:00
|
|
|
aRenderingContext,
|
2017-05-22 12:26:17 +03:00
|
|
|
PresContext(), imgCon,
|
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(this),
|
|
|
|
dest, dirty,
|
|
|
|
svgContext, aFlags,
|
|
|
|
anchorPoint.ptrOr(nullptr),
|
|
|
|
hasSubRect ? &mSubRect : nullptr);
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult
|
2017-09-10 07:45:11 +03:00
|
|
|
nsImageBoxFrame::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-09-10 07:45:11 +03:00
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
nsPoint aPt,
|
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result;
|
2017-09-10 07:45:11 +03:00
|
|
|
Maybe<nsPoint> anchorPoint;
|
|
|
|
nsRect dest;
|
|
|
|
nsCOMPtr<imgIContainer> imgCon = GetImageContainerForPainting(aPt, result,
|
|
|
|
anchorPoint,
|
|
|
|
dest);
|
|
|
|
if (!imgCon) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-11-23 14:55:06 +03:00
|
|
|
uint32_t containerFlags = imgIContainer::FLAG_ASYNC_NOTIFY;
|
|
|
|
if (aFlags & nsImageRenderer::FLAG_PAINTING_TO_WINDOW) {
|
|
|
|
containerFlags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
}
|
2017-09-10 07:45:11 +03:00
|
|
|
if (aFlags & nsImageRenderer::FLAG_SYNC_DECODE_IMAGES) {
|
|
|
|
containerFlags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
2017-11-23 14:55:06 +03:00
|
|
|
|
|
|
|
const int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
|
|
|
|
LayoutDeviceRect fillRect = LayoutDeviceRect::FromAppUnits(dest,
|
|
|
|
appUnitsPerDevPixel);
|
|
|
|
Maybe<SVGImageContext> svgContext;
|
|
|
|
gfx::IntSize decodeSize =
|
|
|
|
nsLayoutUtils::ComputeImageContainerDrawingParameters(imgCon, aItem->Frame(), fillRect,
|
|
|
|
aSc, containerFlags, svgContext);
|
2017-09-10 07:45:11 +03:00
|
|
|
RefPtr<layers::ImageContainer> container =
|
2017-11-23 14:55:06 +03:00
|
|
|
imgCon->GetImageContainerAtSize(aManager, decodeSize, svgContext, containerFlags);
|
2017-09-10 07:45:11 +03:00
|
|
|
if (!container) {
|
|
|
|
NS_WARNING("Failed to get image container");
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::NOT_READY;
|
2017-09-10 07:45:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntSize size;
|
2017-09-25 10:48:29 +03:00
|
|
|
Maybe<wr::ImageKey> key = aManager->CommandBuilder().CreateImageKey(aItem, container,
|
|
|
|
aBuilder, aResources,
|
2017-10-18 08:56:53 +03:00
|
|
|
aSc, size, Nothing());
|
2017-09-10 07:45:11 +03:00
|
|
|
if (key.isNothing()) {
|
2018-03-13 16:16:04 +03:00
|
|
|
return ImgDrawResult::NOT_READY;
|
2017-09-10 07:45:11 +03:00
|
|
|
}
|
|
|
|
wr::LayoutRect fill = aSc.ToRelativeLayoutRect(fillRect);
|
|
|
|
|
|
|
|
LayoutDeviceSize gapSize(0, 0);
|
|
|
|
SamplingFilter sampleFilter = nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame());
|
2017-09-21 09:41:38 +03:00
|
|
|
aBuilder.PushImage(fill, fill, !BackfaceIsHidden(),
|
2017-09-10 07:45:11 +03:00
|
|
|
wr::ToLayoutSize(fillRect.Size()), wr::ToLayoutSize(gapSize),
|
|
|
|
wr::ToImageRendering(sampleFilter), key.value());
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-09-10 07:45:11 +03:00
|
|
|
}
|
|
|
|
|
2017-05-22 12:26:17 +03:00
|
|
|
nsRect
|
|
|
|
nsImageBoxFrame::GetDestRect(const nsPoint& aOffset, Maybe<nsPoint>& aAnchorPoint)
|
|
|
|
{
|
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
mImageRequest->GetImage(getter_AddRefs(imgCon));
|
|
|
|
MOZ_ASSERT(imgCon);
|
|
|
|
|
|
|
|
nsRect clientRect;
|
|
|
|
GetXULClientRect(clientRect);
|
|
|
|
clientRect += aOffset;
|
2015-06-13 03:31:21 +03:00
|
|
|
nsRect dest;
|
|
|
|
if (!mUseSrcAttr) {
|
|
|
|
// Our image (if we have one) is coming from the CSS property
|
|
|
|
// 'list-style-image' (combined with '-moz-image-region'). For now, ignore
|
|
|
|
// 'object-fit' & 'object-position' in this case, and just fill our rect.
|
|
|
|
// XXXdholbert Should we even honor these properties in this case? They only
|
|
|
|
// apply to replaced elements, and I'm not sure we count as a replaced
|
|
|
|
// element when our image data is determined by CSS.
|
2017-05-22 12:26:17 +03:00
|
|
|
dest = clientRect;
|
2015-06-13 03:31:21 +03:00
|
|
|
} else {
|
|
|
|
// Determine dest rect based on intrinsic size & ratio, along with
|
|
|
|
// 'object-fit' & 'object-position' properties:
|
|
|
|
IntrinsicSize intrinsicSize;
|
|
|
|
nsSize intrinsicRatio;
|
|
|
|
if (mIntrinsicSize.width > 0 && mIntrinsicSize.height > 0) {
|
|
|
|
// Image has a valid size; use it as intrinsic size & ratio.
|
|
|
|
intrinsicSize.width.SetCoordValue(mIntrinsicSize.width);
|
|
|
|
intrinsicSize.height.SetCoordValue(mIntrinsicSize.height);
|
|
|
|
intrinsicRatio = mIntrinsicSize;
|
|
|
|
} else {
|
|
|
|
// Image doesn't have a (valid) intrinsic size.
|
|
|
|
// Try to look up intrinsic ratio and use that at least.
|
|
|
|
imgCon->GetIntrinsicRatio(&intrinsicRatio);
|
|
|
|
}
|
2017-05-22 12:26:17 +03:00
|
|
|
aAnchorPoint.emplace();
|
|
|
|
dest = nsLayoutUtils::ComputeObjectDestRect(clientRect,
|
2015-06-13 03:31:21 +03:00
|
|
|
intrinsicSize,
|
|
|
|
intrinsicRatio,
|
|
|
|
StylePosition(),
|
2017-05-22 12:26:17 +03:00
|
|
|
aAnchorPoint.ptr());
|
2015-06-13 03:31:21 +03:00
|
|
|
}
|
|
|
|
|
2017-05-22 12:26:17 +03:00
|
|
|
return dest;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2012-09-25 00:29:14 +04:00
|
|
|
void nsDisplayXULImage::Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx)
|
2012-09-25 00:29:14 +04:00
|
|
|
{
|
2017-01-16 23:12:51 +03:00
|
|
|
// Even though we call StartDecoding when we get a new image we pass
|
|
|
|
// FLAG_SYNC_DECODE_IF_FAST here for the case where the size we draw at is not
|
|
|
|
// the intrinsic size of the image and we aren't likely to implement predictive
|
|
|
|
// decoding at the correct size for this class like nsImageFrame has.
|
|
|
|
uint32_t flags = imgIContainer::FLAG_SYNC_DECODE_IF_FAST;
|
2013-04-26 02:08:58 +04:00
|
|
|
if (aBuilder->ShouldSyncDecodeImages())
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
if (aBuilder->IsPaintingToWindow())
|
|
|
|
flags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result = static_cast<nsImageBoxFrame*>(mFrame)->
|
2013-04-26 02:08:58 +04:00
|
|
|
PaintImage(*aCtx, mVisibleRect, ToReferenceFrame(), flags);
|
2015-02-05 00:50:56 +03:00
|
|
|
|
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
|
|
|
}
|
|
|
|
|
2017-09-10 07:45:11 +03:00
|
|
|
bool
|
|
|
|
nsDisplayXULImage::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-09-10 07:45:11 +03:00
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
|
|
|
{
|
2017-11-24 02:17:17 +03:00
|
|
|
nsImageBoxFrame* imageFrame = static_cast<nsImageBoxFrame*>(mFrame);
|
|
|
|
if (!imageFrame->CanOptimizeToImageLayer()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!imageFrame->mImageRequest) {
|
2017-10-03 23:31:07 +03:00
|
|
|
return false;
|
2017-09-10 07:45:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t flags = imgIContainer::FLAG_SYNC_DECODE_IF_FAST;
|
|
|
|
if (aDisplayListBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
|
|
|
if (aDisplayListBuilder->IsPaintingToWindow()) {
|
|
|
|
flags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result = imageFrame->
|
2017-09-14 19:48:55 +03:00
|
|
|
CreateWebRenderCommands(aBuilder, aResources, aSc, aManager, this, ToReferenceFrame(), flags);
|
2017-09-10 07:45:11 +03:00
|
|
|
|
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
nsDisplayItemGeometry*
|
|
|
|
nsDisplayXULImage::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
2012-09-25 00:29:14 +04:00
|
|
|
}
|
|
|
|
|
2013-06-26 20:43:27 +04:00
|
|
|
void
|
|
|
|
nsDisplayXULImage::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 boxFrame = static_cast<nsImageBoxFrame*>(mFrame);
|
|
|
|
auto geometry =
|
|
|
|
static_cast<const nsDisplayItemGenericImageGeometry*>(aGeometry);
|
2013-06-26 20:43:27 +04:00
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
if (aBuilder->ShouldSyncDecodeImages() &&
|
|
|
|
boxFrame->mImageRequest &&
|
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);
|
|
|
|
}
|
|
|
|
|
2015-05-13 10:23:46 +03:00
|
|
|
bool
|
|
|
|
nsDisplayXULImage::CanOptimizeToImageLayer(LayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
2016-04-07 09:52:35 +03:00
|
|
|
nsImageBoxFrame* imageFrame = static_cast<nsImageBoxFrame*>(mFrame);
|
|
|
|
if (!imageFrame->CanOptimizeToImageLayer()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-13 10:23:46 +03:00
|
|
|
|
2016-04-07 09:52:35 +03:00
|
|
|
return nsDisplayImageContainer::CanOptimizeToImageLayer(aManager, aBuilder);
|
2015-05-13 10:23:46 +03:00
|
|
|
}
|
|
|
|
|
2016-04-07 09:52:35 +03:00
|
|
|
already_AddRefed<imgIContainer>
|
|
|
|
nsDisplayXULImage::GetImage()
|
2015-05-13 10:23:46 +03:00
|
|
|
{
|
2016-04-07 09:52:35 +03:00
|
|
|
nsImageBoxFrame* imageFrame = static_cast<nsImageBoxFrame*>(mFrame);
|
|
|
|
if (!imageFrame->mImageRequest) {
|
|
|
|
return nullptr;
|
2015-05-13 10:23:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
2016-04-07 09:52:35 +03:00
|
|
|
imageFrame->mImageRequest->GetImage(getter_AddRefs(imgCon));
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2016-04-07 09:52:35 +03:00
|
|
|
return imgCon.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2017-08-24 18:09:44 +03:00
|
|
|
nsDisplayXULImage::GetDestRect() const
|
2016-04-07 09:52:35 +03:00
|
|
|
{
|
2017-05-22 12:26:17 +03:00
|
|
|
Maybe<nsPoint> anchorPoint;
|
|
|
|
return static_cast<nsImageBoxFrame*>(mFrame)->GetDestRect(ToReferenceFrame(), anchorPoint);
|
2016-04-07 09:52:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsImageBoxFrame::CanOptimizeToImageLayer()
|
|
|
|
{
|
|
|
|
bool hasSubRect = !mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0);
|
|
|
|
if (hasSubRect) {
|
2015-05-13 10:23:46 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-07 09:52:35 +03:00
|
|
|
return true;
|
2015-05-13 10:23:46 +03:00
|
|
|
}
|
|
|
|
|
2000-03-31 11:02:06 +04:00
|
|
|
//
|
2018-03-22 21:20:41 +03:00
|
|
|
// DidSetComputedStyle
|
2000-03-31 11:02:06 +04:00
|
|
|
//
|
|
|
|
// When the style context changes, make sure that all of our image is up to date.
|
|
|
|
//
|
2008-10-14 02:03:28 +04:00
|
|
|
/* virtual */ void
|
2018-03-22 21:20:41 +03:00
|
|
|
nsImageBoxFrame::DidSetComputedStyle(ComputedStyle* aOldComputedStyle)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2018-03-22 21:20:41 +03:00
|
|
|
nsLeafBoxFrame::DidSetComputedStyle(aOldComputedStyle);
|
2008-10-14 02:03:28 +04:00
|
|
|
|
2001-12-05 11:35:05 +03:00
|
|
|
// Fetch our subrect.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleList* myList = StyleList();
|
2004-07-28 03:31:08 +04:00
|
|
|
mSubRect = myList->mImageRegion; // before |mSuppressStyleCheck| test!
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
if (mUseSrcAttr || mSuppressStyleCheck)
|
2008-10-14 02:03:28 +04:00
|
|
|
return; // No more work required, since the image isn't specified by style.
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2002-02-06 06:46:07 +03:00
|
|
|
// If we're using a native theme implementation, we shouldn't draw anything.
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay* disp = StyleDisplay();
|
2017-05-21 12:15:00 +03:00
|
|
|
if (disp->mAppearance && nsBox::gTheme &&
|
|
|
|
nsBox::gTheme->ThemeSupportsWidget(nullptr, this, disp->mAppearance))
|
2008-10-14 02:03:28 +04:00
|
|
|
return;
|
2002-02-06 06:46:07 +03:00
|
|
|
|
2001-12-05 11:35:05 +03:00
|
|
|
// If list-style-image changes, we have a new image.
|
2004-08-04 07:23:37 +04:00
|
|
|
nsCOMPtr<nsIURI> oldURI, newURI;
|
|
|
|
if (mImageRequest)
|
|
|
|
mImageRequest->GetURI(getter_AddRefs(oldURI));
|
2009-12-11 07:02:13 +03:00
|
|
|
if (myList->GetListStyleImage())
|
|
|
|
myList->GetListStyleImage()->GetURI(getter_AddRefs(newURI));
|
2011-09-29 10:19:26 +04:00
|
|
|
bool equal;
|
2004-08-04 07:23:37 +04:00
|
|
|
if (newURI == oldURI || // handles null==null
|
|
|
|
(newURI && oldURI &&
|
|
|
|
NS_SUCCEEDED(newURI->Equals(oldURI, &equal)) && equal))
|
2008-10-14 02:03:28 +04:00
|
|
|
return;
|
2001-12-05 11:35:05 +03:00
|
|
|
|
2004-02-19 21:56:13 +03:00
|
|
|
UpdateImage();
|
2018-03-22 21:20:41 +03:00
|
|
|
} // DidSetComputedStyle
|
2000-03-31 11:02:06 +04:00
|
|
|
|
|
|
|
void
|
2004-02-19 21:56:13 +03:00
|
|
|
nsImageBoxFrame::GetImageSize()
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2004-08-04 07:23:37 +04:00
|
|
|
if (mIntrinsicSize.width > 0 && mIntrinsicSize.height > 0) {
|
|
|
|
mImageSize.width = mIntrinsicSize.width;
|
|
|
|
mImageSize.height = mIntrinsicSize.height;
|
|
|
|
} else {
|
|
|
|
mImageSize.width = 0;
|
|
|
|
mImageSize.height = 0;
|
|
|
|
}
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ok return our dimensions
|
|
|
|
*/
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
2016-04-21 07:28:31 +03:00
|
|
|
nsImageBoxFrame::GetXULPrefSize(nsBoxLayoutState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize size(0,0);
|
|
|
|
DISPLAY_PREF_SIZE(this, size);
|
|
|
|
if (DoesNeedRecalc(mImageSize))
|
2004-02-19 21:56:13 +03:00
|
|
|
GetImageSize();
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2002-10-04 04:56:43 +04:00
|
|
|
if (!mUseSrcAttr && (mSubRect.width > 0 || mSubRect.height > 0))
|
2013-08-14 16:27:20 +04:00
|
|
|
size = mSubRect.Size();
|
2001-12-05 11:35:05 +03:00
|
|
|
else
|
2007-01-08 05:57:59 +03:00
|
|
|
size = mImageSize;
|
2011-08-05 23:24:24 +04:00
|
|
|
|
|
|
|
nsSize intrinsicSize = size;
|
|
|
|
|
|
|
|
nsMargin borderPadding(0,0,0,0);
|
2016-04-21 07:28:32 +03:00
|
|
|
GetXULBorderAndPadding(borderPadding);
|
2011-08-05 23:24:24 +04:00
|
|
|
size.width += borderPadding.LeftRight();
|
|
|
|
size.height += borderPadding.TopBottom();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool widthSet, heightSet;
|
2016-04-21 07:28:34 +03:00
|
|
|
nsIFrame::AddXULPrefSize(this, size, widthSet, heightSet);
|
2011-08-05 23:24:24 +04:00
|
|
|
NS_ASSERTION(size.width != NS_INTRINSICSIZE && size.height != NS_INTRINSICSIZE,
|
2011-11-02 02:29:15 +04:00
|
|
|
"non-intrinsic size expected");
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize minSize = GetXULMinSize(aState);
|
2016-04-21 07:28:31 +03:00
|
|
|
nsSize maxSize = GetXULMaxSize(aState);
|
2011-08-05 23:24:24 +04:00
|
|
|
|
|
|
|
if (!widthSet && !heightSet) {
|
|
|
|
if (minSize.width != NS_INTRINSICSIZE)
|
|
|
|
minSize.width -= borderPadding.LeftRight();
|
|
|
|
if (minSize.height != NS_INTRINSICSIZE)
|
|
|
|
minSize.height -= borderPadding.TopBottom();
|
|
|
|
if (maxSize.width != NS_INTRINSICSIZE)
|
|
|
|
maxSize.width -= borderPadding.LeftRight();
|
|
|
|
if (maxSize.height != NS_INTRINSICSIZE)
|
|
|
|
maxSize.height -= borderPadding.TopBottom();
|
|
|
|
|
|
|
|
size = nsLayoutUtils::ComputeAutoSizeWithIntrinsicDimensions(minSize.width, minSize.height,
|
|
|
|
maxSize.width, maxSize.height,
|
|
|
|
intrinsicSize.width, intrinsicSize.height);
|
|
|
|
NS_ASSERTION(size.width != NS_INTRINSICSIZE && size.height != NS_INTRINSICSIZE,
|
2011-11-02 02:29:15 +04:00
|
|
|
"non-intrinsic size expected");
|
2011-08-05 23:24:24 +04:00
|
|
|
size.width += borderPadding.LeftRight();
|
|
|
|
size.height += borderPadding.TopBottom();
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!widthSet) {
|
|
|
|
if (intrinsicSize.height > 0) {
|
|
|
|
// Subtract off the border and padding from the height because the
|
|
|
|
// content-box needs to be used to determine the ratio
|
|
|
|
nscoord height = size.height - borderPadding.TopBottom();
|
2012-08-22 19:56:38 +04:00
|
|
|
size.width = nscoord(int64_t(height) * int64_t(intrinsicSize.width) /
|
|
|
|
int64_t(intrinsicSize.height));
|
2011-08-05 23:24:24 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
size.width = intrinsicSize.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
size.width += borderPadding.LeftRight();
|
|
|
|
}
|
|
|
|
else if (!heightSet) {
|
|
|
|
if (intrinsicSize.width > 0) {
|
|
|
|
nscoord width = size.width - borderPadding.LeftRight();
|
2012-08-22 19:56:38 +04:00
|
|
|
size.height = nscoord(int64_t(width) * int64_t(intrinsicSize.height) /
|
|
|
|
int64_t(intrinsicSize.width));
|
2011-08-05 23:24:24 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
size.height = intrinsicSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
size.height += borderPadding.TopBottom();
|
|
|
|
}
|
2002-02-14 08:51:47 +03:00
|
|
|
|
2008-01-05 08:49:44 +03:00
|
|
|
return BoundsCheck(minSize, size, maxSize);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize
|
2016-04-21 07:28:31 +03:00
|
|
|
nsImageBoxFrame::GetXULMinSize(nsBoxLayoutState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2001-11-04 12:32:37 +03:00
|
|
|
// An image can always scale down to (0,0).
|
2007-01-08 05:57:59 +03:00
|
|
|
nsSize size(0,0);
|
|
|
|
DISPLAY_MIN_SIZE(this, size);
|
|
|
|
AddBorderAndPadding(size);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool widthSet, heightSet;
|
2016-04-21 07:28:34 +03:00
|
|
|
nsIFrame::AddXULMinSize(aState, this, size, widthSet, heightSet);
|
2007-01-08 05:57:59 +03:00
|
|
|
return size;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2007-02-22 21:05:14 +03:00
|
|
|
nscoord
|
2016-04-21 07:28:32 +03:00
|
|
|
nsImageBoxFrame::GetXULBoxAscent(nsBoxLayoutState& aState)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2016-04-21 07:28:31 +03:00
|
|
|
return GetXULPrefSize(aState).height;
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2001-11-14 04:33:42 +03:00
|
|
|
nsImageBoxFrame::GetFrameName(nsAString& aResult) const
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2001-11-14 04:33:42 +03:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ImageBox"), aResult);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
2001-09-15 04:45:54 +04:00
|
|
|
#endif
|
2001-03-20 02:44:55 +03:00
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsresult
|
2014-11-18 01:29:56 +03:00
|
|
|
nsImageBoxFrame::Notify(imgIRequest* aRequest,
|
|
|
|
int32_t aType,
|
|
|
|
const nsIntRect* aData)
|
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::DECODE_COMPLETE) {
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnDecodeComplete(aRequest);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (aType == imgINotificationObserver::IS_ANIMATED) {
|
|
|
|
return OnImageIsAnimated(aRequest);
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::FRAME_UPDATE) {
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnFrameUpdate(aRequest);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
2001-03-20 02:44:55 +03:00
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult
|
|
|
|
nsImageBoxFrame::OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage)
|
2001-04-17 13:04:12 +04:00
|
|
|
{
|
2014-11-18 01:29:56 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aImage);
|
2003-02-26 08:51:32 +03:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
// Ensure the animation (if any) is started. Note: There is no
|
|
|
|
// corresponding call to Decrement for this. This Increment will be
|
|
|
|
// 'cleaned up' by the Request when it is destroyed, but only then.
|
2014-11-18 01:29:56 +03:00
|
|
|
aRequest->IncrementAnimationConsumers();
|
2004-01-08 21:29:28 +03:00
|
|
|
|
2001-03-20 02:44:55 +03:00
|
|
|
nscoord w, h;
|
2014-11-18 01:29:56 +03:00
|
|
|
aImage->GetWidth(&w);
|
|
|
|
aImage->GetHeight(&h);
|
2001-03-20 02:44:55 +03:00
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
mIntrinsicSize.SizeTo(nsPresContext::CSSPixelsToAppUnits(w),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(h));
|
2001-03-20 02:44:55 +03:00
|
|
|
|
2007-04-30 10:17:03 +04:00
|
|
|
if (!(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2017-11-09 05:00:48 +03:00
|
|
|
PresShell()->
|
2007-05-06 23:16:51 +04:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
2007-04-30 10:17:03 +04:00
|
|
|
}
|
2001-03-20 02:44:55 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult
|
|
|
|
nsImageBoxFrame::OnDecodeComplete(imgIRequest* aRequest)
|
2001-03-20 02:44:55 +03:00
|
|
|
{
|
2007-03-31 01:11:41 +04:00
|
|
|
nsBoxLayoutState state(PresContext());
|
2016-04-21 07:28:34 +03:00
|
|
|
this->XULRedraw(state);
|
2001-03-20 02:44:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult
|
|
|
|
nsImageBoxFrame::OnLoadComplete(imgIRequest* aRequest, nsresult aStatus)
|
2001-03-20 02:44:55 +03:00
|
|
|
{
|
2015-07-07 03:11:11 +03:00
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
|
|
|
// Fire an onload DOM event.
|
2015-09-02 09:07:59 +03:00
|
|
|
FireImageDOMEvent(mContent, eLoad);
|
2013-03-16 06:53:25 +04:00
|
|
|
} else {
|
2015-07-07 03:11:11 +03:00
|
|
|
// Fire an onerror DOM event.
|
|
|
|
mIntrinsicSize.SizeTo(0, 0);
|
2017-11-09 05:00:48 +03:00
|
|
|
PresShell()->
|
2015-07-07 03:11:11 +03:00
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
2015-09-02 09:07:59 +03:00
|
|
|
FireImageDOMEvent(mContent, eLoadError);
|
2005-02-04 20:39:43 +03:00
|
|
|
}
|
2001-11-03 10:10:51 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-03-20 02:44:55 +03:00
|
|
|
}
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult
|
|
|
|
nsImageBoxFrame::OnImageIsAnimated(imgIRequest* aRequest)
|
2011-11-10 01:39:16 +04:00
|
|
|
{
|
|
|
|
// Register with our refresh driver, if we're animated.
|
|
|
|
nsLayoutUtils::RegisterImageRequest(PresContext(), aRequest,
|
|
|
|
&mRequestRegistered);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult
|
|
|
|
nsImageBoxFrame::OnFrameUpdate(imgIRequest* aRequest)
|
2001-03-20 02:44:55 +03:00
|
|
|
{
|
2012-08-29 09:39:31 +04:00
|
|
|
if ((0 == mRect.width) || (0 == mRect.height)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2017-08-07 07:07:43 +03:00
|
|
|
InvalidateLayer(DisplayItemType::TYPE_XUL_IMAGE);
|
2001-03-20 02:44:55 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-01 13:59:10 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsImageBoxListener, imgINotificationObserver)
|
2001-03-20 02:44:55 +03:00
|
|
|
|
|
|
|
nsImageBoxListener::nsImageBoxListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageBoxListener::~nsImageBoxListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageBoxListener::Notify(imgIRequest *request, int32_t aType, const nsIntRect* aData)
|
2012-10-12 05:58:24 +04:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
return mFrame->Notify(request, aType, aData);
|
2012-10-12 05:58:24 +04:00
|
|
|
}
|