2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsImageBoxFrame.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2014-10-31 23:08:49 +03:00
|
|
|
#include "nsRenderingContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.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 "prprf.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2000-03-31 11:02:06 +04:00
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsIDOMHTMLMapElement.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"
|
2013-09-25 15:21:22 +04:00
|
|
|
|
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;
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
class nsImageBoxFrameEvent : public nsRunnable
|
2001-11-03 10:10:51 +03:00
|
|
|
{
|
2006-05-10 21:30:15 +04:00
|
|
|
public:
|
2015-08-26 15:56:59 +03:00
|
|
|
nsImageBoxFrameEvent(nsIContent *content, EventMessage message)
|
2006-05-10 21:30:15 +04:00
|
|
|
: 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()
|
|
|
|
{
|
2011-10-18 15:19:44 +04:00
|
|
|
nsIPresShell *pres_shell = mContent->OwnerDoc()->GetShell();
|
2001-11-03 10:10:51 +03:00
|
|
|
if (!pres_shell) {
|
2006-05-10 21:30:15 +04:00
|
|
|
return NS_OK;
|
2001-11-03 10:10:51 +03:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> pres_context = pres_shell->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
|
|
|
|
// can't decide if it wants to call it's observer methods
|
|
|
|
// synchronously or asynchronously. If an image is loaded from the
|
|
|
|
// cache the notifications come back synchronously, but if the image
|
|
|
|
// is loaded from the netswork the notifications come back
|
|
|
|
// asynchronously.
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (NS_FAILED(NS_DispatchToCurrentThread(event)))
|
|
|
|
NS_WARNING("failed to dispatch image event");
|
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*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewImageBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2015-01-06 12:27:56 +03:00
|
|
|
return new (aPresShell) nsImageBoxFrame(aContext);
|
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,
|
2004-12-31 04:13:27 +03:00
|
|
|
nsIAtom* 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();
|
2007-03-31 01:11:41 +04:00
|
|
|
PresContext()->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
|
|
|
}
|
|
|
|
|
2015-01-06 12:27:56 +03:00
|
|
|
nsImageBoxFrame::nsImageBoxFrame(nsStyleContext* aContext):
|
|
|
|
nsLeafBoxFrame(aContext),
|
2003-02-26 08:51:32 +03:00
|
|
|
mIntrinsicSize(0,0),
|
2009-05-12 14:13:09 +04:00
|
|
|
mLoadFlags(nsIRequest::LOAD_NORMAL),
|
2015-04-09 19:56:25 +03:00
|
|
|
mRequestRegistered(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mUseSrcAttr(false),
|
2015-07-07 03:11:11 +03:00
|
|
|
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
|
2009-12-24 08:21:15 +03:00
|
|
|
nsImageBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
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
|
|
|
|
2009-12-24 08:21:15 +03:00
|
|
|
nsLeafBoxFrame::DestroyFrom(aDestructRoot);
|
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();
|
|
|
|
|
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;
|
2006-12-26 20:47:52 +03:00
|
|
|
mContent->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();
|
2004-08-04 23:48:55 +04:00
|
|
|
if (!doc) {
|
|
|
|
// No need to do anything here...
|
|
|
|
return;
|
2003-10-02 02:53:56 +04:00
|
|
|
}
|
2004-08-04 23:48:55 +04:00
|
|
|
nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
|
2004-08-04 07:23:37 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2004-08-04 23:48:55 +04:00
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
|
|
|
|
src,
|
|
|
|
doc,
|
|
|
|
baseURI);
|
|
|
|
|
2007-07-03 22:45:39 +04:00
|
|
|
if (uri && nsContentUtils::CanLoadImage(uri, mContent, doc,
|
|
|
|
mContent->NodePrincipal())) {
|
2016-04-11 11:58:03 +03:00
|
|
|
nsContentUtils::LoadImage(uri, mContent, doc, mContent->NodePrincipal(),
|
2014-11-18 16:46:53 +03:00
|
|
|
doc->GetDocumentURI(), doc->GetReferrerPolicy(),
|
|
|
|
mListener, mLoadFlags,
|
2013-10-16 05:35:44 +04:00
|
|
|
EmptyString(), getter_AddRefs(mImageRequest));
|
2011-11-10 01:39:16 +04:00
|
|
|
|
|
|
|
if (mImageRequest) {
|
|
|
|
nsLayoutUtils::RegisterImageRequestIfAnimated(presContext,
|
|
|
|
mImageRequest,
|
|
|
|
&mRequestRegistered);
|
|
|
|
}
|
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.
|
2013-02-17 01:51:02 +04: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) {
|
|
|
|
styleRequest->Clone(mListener, getter_AddRefs(mImageRequest));
|
|
|
|
}
|
|
|
|
}
|
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.
|
2012-10-05 00:02:15 +04:00
|
|
|
mImageRequest->StartDecoding();
|
2010-08-24 02:43:06 +04:00
|
|
|
mImageRequest->LockImage();
|
2005-02-04 20:39:43 +03:00
|
|
|
}
|
2004-07-31 11:42:12 +04:00
|
|
|
}
|
|
|
|
|
2001-11-07 09:40:04 +03:00
|
|
|
void
|
|
|
|
nsImageBoxFrame::UpdateLoadFlags()
|
|
|
|
{
|
2006-04-24 09:40:11 +04:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 18:20:58 +04:00
|
|
|
{&nsGkAtoms::always, &nsGkAtoms::never, nullptr};
|
2006-12-26 20:47:52 +03:00
|
|
|
switch (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::validate,
|
2006-04-24 09:40:11 +04:00
|
|
|
strings, eCaseMatters)) {
|
|
|
|
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 nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2011-11-02 02:28:48 +04:00
|
|
|
{
|
2013-02-14 15:08:08 +04:00
|
|
|
nsLeafBoxFrame::BuildDisplayList(aBuilder, aDirtyRect, 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);
|
|
|
|
|
2012-10-11 09:44:59 +04:00
|
|
|
nsDisplayList list;
|
2013-02-14 15:08:08 +04:00
|
|
|
list.AppendNewToTop(
|
|
|
|
new (aBuilder) 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
|
|
|
}
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
DrawResult
|
2011-04-08 05:04:40 +04:00
|
|
|
nsImageBoxFrame::PaintImage(nsRenderingContext& aRenderingContext,
|
2009-09-13 02:44:18 +04:00
|
|
|
const nsRect& aDirtyRect, nsPoint aPt,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2015-06-13 03:31:21 +03:00
|
|
|
nsRect constraintRect;
|
2016-04-21 07:28:33 +03:00
|
|
|
GetXULClientRect(constraintRect);
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2015-06-13 03:31:21 +03:00
|
|
|
constraintRect += aPt;
|
2000-03-31 11:02:06 +04:00
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
if (!mImageRequest) {
|
|
|
|
// This probably means we're drawn by a native theme.
|
|
|
|
return DrawResult::SUCCESS;
|
|
|
|
}
|
2004-02-19 21:56:13 +03:00
|
|
|
|
|
|
|
// don't draw if the image is not dirty
|
2015-02-05 00:50:56 +03:00
|
|
|
// XXX(seth): Can this actually happen anymore?
|
2007-03-20 03:58:20 +03:00
|
|
|
nsRect dirty;
|
2015-06-13 03:31:21 +03:00
|
|
|
if (!dirty.IntersectRect(aDirtyRect, constraintRect)) {
|
2015-02-05 00:50:56 +03:00
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
|
|
|
}
|
2001-04-11 13:01:29 +04: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)) {
|
|
|
|
return DrawResult::NOT_READY;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
return DrawResult::NOT_READY;
|
2001-03-20 02:44:55 +03:00
|
|
|
}
|
2015-02-05 00:50:56 +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
|
|
|
|
|
|
|
Maybe<nsPoint> anchorPoint;
|
|
|
|
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.
|
|
|
|
dest = constraintRect;
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
anchorPoint.emplace();
|
|
|
|
dest = nsLayoutUtils::ComputeObjectDestRect(constraintRect,
|
|
|
|
intrinsicSize,
|
|
|
|
intrinsicRatio,
|
|
|
|
StylePosition(),
|
|
|
|
anchorPoint.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-13 03:31:21 +03:00
|
|
|
return nsLayoutUtils::DrawSingleImage(
|
|
|
|
*aRenderingContext.ThebesContext(),
|
|
|
|
PresContext(), imgCon,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
2015-06-13 03:31:21 +03:00
|
|
|
dest, dirty, nullptr, aFlags,
|
|
|
|
anchorPoint.ptrOr(nullptr),
|
2015-06-13 03:31:21 +03:00
|
|
|
hasSubRect ? &mSubRect : nullptr);
|
2000-03-31 11:02:06 +04:00
|
|
|
}
|
|
|
|
|
2012-09-25 00:29:14 +04:00
|
|
|
void nsDisplayXULImage::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
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
|
|
|
DrawResult 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
nsRegion* aInvalidRegion)
|
|
|
|
{
|
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));
|
|
|
|
|
|
|
|
return imgCon.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayXULImage::GetDestRect()
|
|
|
|
{
|
|
|
|
nsImageBoxFrame* imageFrame = static_cast<nsImageBoxFrame*>(mFrame);
|
|
|
|
|
|
|
|
nsRect clientRect;
|
2016-04-21 07:28:33 +03:00
|
|
|
imageFrame->GetXULClientRect(clientRect);
|
2016-04-07 09:52:35 +03:00
|
|
|
|
|
|
|
return clientRect + ToReferenceFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
//
|
|
|
|
// DidSetStyleContext
|
|
|
|
//
|
|
|
|
// 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
|
2008-10-26 13:11:34 +03:00
|
|
|
nsImageBoxFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
2000-03-31 11:02:06 +04:00
|
|
|
{
|
2008-10-26 13:11:34 +03:00
|
|
|
nsLeafBoxFrame::DidSetStyleContext(aOldStyleContext);
|
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();
|
2011-11-02 02:28:48 +04:00
|
|
|
if (disp->mAppearance && nsBox::gTheme &&
|
2012-07-30 18:20:58 +04:00
|
|
|
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();
|
2000-03-31 11:02:06 +04:00
|
|
|
} // DidSetStyleContext
|
|
|
|
|
|
|
|
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;
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame::AddCSSPrefSize(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;
|
2012-08-06 07:00:57 +04:00
|
|
|
nsIFrame::AddCSSMinSize(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
|
|
|
}
|
|
|
|
|
2004-07-28 03:31:08 +04:00
|
|
|
nsIAtom*
|
|
|
|
nsImageBoxFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::imageBoxFrame;
|
2004-07-28 03:31:08 +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)) {
|
|
|
|
PresContext()->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());
|
2001-04-25 23:52:49 +04:00
|
|
|
this->Redraw(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);
|
|
|
|
PresContext()->PresShell()->
|
|
|
|
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;
|
|
|
|
}
|
2012-09-25 00:31:30 +04:00
|
|
|
|
|
|
|
InvalidateLayer(nsDisplayItem::TYPE_XUL_IMAGE);
|
2001-03-20 02:44:55 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsImageBoxListener, imgINotificationObserver, imgIOnloadBlocker)
|
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
|
|
|
}
|
2013-03-16 06:53:25 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageBoxListener::BlockOnload(imgIRequest *aRequest)
|
|
|
|
{
|
2016-03-31 14:46:32 +03:00
|
|
|
if (mFrame && mFrame->GetContent() && mFrame->GetContent()->GetUncomposedDoc()) {
|
|
|
|
mFrame->GetContent()->GetUncomposedDoc()->BlockOnload();
|
2013-03-16 06:53:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageBoxListener::UnblockOnload(imgIRequest *aRequest)
|
|
|
|
{
|
2016-03-31 14:46:32 +03:00
|
|
|
if (mFrame && mFrame->GetContent() && mFrame->GetContent()->GetUncomposedDoc()) {
|
|
|
|
mFrame->GetContent()->GetUncomposedDoc()->UnblockOnload(false);
|
2013-03-16 06:53:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|