2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-08 22:34:40 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-09-08 22:34:40 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-09-08 22:34:40 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2007-03-20 00:58:20 +00:00
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-29 18:29:03 +00:00
|
|
|
|
|
|
|
/* rendering object for replaced elements with bitmap image data */
|
|
|
|
|
2011-10-11 05:50:08 +00:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsHTMLParts.h"
|
1999-07-08 19:38:08 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-04-13 21:51:20 +00:00
|
|
|
#include "nsImageFrame.h"
|
2003-03-19 03:47:09 +00:00
|
|
|
#include "nsIImageLoadingContent.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsString.h"
|
2002-11-20 00:44:26 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2011-04-08 01:04:40 +00:00
|
|
|
#include "nsRenderingContext.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsIPresShell.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsIDocument.h"
|
2002-11-20 00:44:26 +00:00
|
|
|
#include "nsINodeInfo.h"
|
2004-04-29 23:34:19 +00:00
|
|
|
#include "nsContentUtils.h"
|
2007-12-03 09:24:49 +00:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsStyleConsts.h"
|
2010-09-08 20:40:38 +00:00
|
|
|
#include "nsStyleCoord.h"
|
2010-09-08 20:40:38 +00:00
|
|
|
#include "nsTransform2D.h"
|
1999-01-09 00:13:19 +00:00
|
|
|
#include "nsImageMap.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
2001-03-22 01:38:35 +00:00
|
|
|
#include "nsILoadGroup.h"
|
2005-02-21 20:58:01 +00:00
|
|
|
#include "nsISupportsPriority.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1998-09-23 02:30:21 +00:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2004-02-10 16:57:00 +00:00
|
|
|
#include "nsILink.h"
|
1999-07-08 19:38:08 +00:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
1998-09-08 22:34:40 +00:00
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
1998-12-20 01:21:23 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-01-05 23:02:27 +00:00
|
|
|
#include "nsTextFragment.h"
|
1999-01-30 01:04:35 +00:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
2000-08-08 20:35:12 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2011-01-28 04:38:14 +00:00
|
|
|
#include "nsAccessibilityService.h"
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
2001-04-01 01:01:33 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMNode.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsGUIEvent.h"
|
2005-08-23 03:57:07 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
2001-04-01 01:01:33 +00:00
|
|
|
|
2001-05-04 06:29:59 +00:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgILoader.h"
|
|
|
|
|
2001-11-07 05:02:42 +00:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2003-04-22 23:18:34 +00: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-08 21:31:05 +00:00
|
|
|
|
2005-03-02 04:05:12 +00:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
2011-04-21 17:35:52 +00:00
|
|
|
#include "nsEventStates.h"
|
2003-04-21 23:57:47 +00:00
|
|
|
#include "nsLayoutErrors.h"
|
2006-07-31 07:08:45 +00:00
|
|
|
#include "nsBidiUtils.h"
|
|
|
|
#include "nsBidiPresUtils.h"
|
2003-04-21 23:57:47 +00:00
|
|
|
|
2011-01-17 21:47:18 +00:00
|
|
|
#include "gfxRect.h"
|
2011-04-26 06:04:18 +00:00
|
|
|
#include "ImageLayers.h"
|
2011-01-17 21:47:18 +00:00
|
|
|
|
2011-05-25 06:31:59 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-06-21 15:37:47 +00:00
|
|
|
#include "mozilla/Util.h" // for DebugOnly
|
2011-05-25 06:31:59 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2002-03-26 20:14:05 +00: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-22 23:18:34 +00:00
|
|
|
//we must add hooks soon
|
|
|
|
#define IMAGE_EDITOR_CHECK 1
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
// Default alignment value (so we can tell an unset value from a set value)
|
|
|
|
#define ALIGN_UNSET PRUint8(-1)
|
|
|
|
|
2011-01-17 21:47:18 +00:00
|
|
|
using namespace mozilla::layers;
|
2011-06-01 01:46:56 +00:00
|
|
|
using namespace mozilla::dom;
|
2011-01-17 21:47:18 +00:00
|
|
|
|
2004-02-03 20:30:02 +00:00
|
|
|
// static icon information
|
|
|
|
nsImageFrame::IconLoad* nsImageFrame::gIconLoad = nsnull;
|
2001-11-07 05:02:42 +00:00
|
|
|
|
2004-01-21 09:35:59 +00:00
|
|
|
// cached IO service for loading icons
|
|
|
|
nsIIOService* nsImageFrame::sIOService;
|
|
|
|
|
2001-11-07 05:02:42 +00:00
|
|
|
// test if the width and height are fixed, looking at the style data
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool HaveFixedSize(const nsStylePosition* aStylePosition)
|
2001-11-07 05:02:42 +00: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 19:32:53 +00:00
|
|
|
return aStylePosition->mWidth.IsCoordPercentCalcUnit() &&
|
|
|
|
aStylePosition->mHeight.IsCoordPercentCalcUnit();
|
2001-11-07 05:02:42 +00:00
|
|
|
}
|
2001-03-06 00:47:46 +00:00
|
|
|
// use the data in the reflow state to decide if the image has a constrained size
|
|
|
|
// (i.e. width and height that are based on the containing block size and not the image size)
|
|
|
|
// so we can avoid animated GIF related reflows
|
2011-09-29 06:19:26 +00:00
|
|
|
inline bool HaveFixedSize(const nsHTMLReflowState& aReflowState)
|
2001-11-07 05:02:42 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aReflowState.mStylePosition, "crappy reflowState - null stylePosition");
|
2007-08-02 18:08:05 +00:00
|
|
|
// when an image has percent css style height or width, but ComputedHeight()
|
2007-01-26 00:05:12 +00:00
|
|
|
// or ComputedWidth() of reflow state is NS_UNCONSTRAINEDSIZE
|
2011-10-17 14:59:28 +00:00
|
|
|
// it needs to return false to cause an incremental reflow later
|
2002-11-07 02:50:39 +00:00
|
|
|
// if an image is inside table like bug 156731 simple testcase III,
|
2007-01-26 00:05:12 +00:00
|
|
|
// during pass 1 reflow, ComputedWidth() is NS_UNCONSTRAINEDSIZE
|
2011-10-17 14:59:28 +00:00
|
|
|
// in pass 2 reflow, ComputedWidth() is 0, it also needs to return false
|
2002-11-07 02:50:39 +00:00
|
|
|
// see bug 156731
|
2010-08-11 19:32:53 +00:00
|
|
|
const nsStyleCoord &height = aReflowState.mStylePosition->mHeight;
|
|
|
|
const nsStyleCoord &width = aReflowState.mStylePosition->mWidth;
|
2010-08-25 10:17:55 +00:00
|
|
|
return ((height.HasPercent() &&
|
2010-08-11 19:32:53 +00:00
|
|
|
NS_UNCONSTRAINEDSIZE == aReflowState.ComputedHeight()) ||
|
2010-08-25 10:17:55 +00:00
|
|
|
(width.HasPercent() &&
|
2010-08-11 19:32:53 +00:00
|
|
|
(NS_UNCONSTRAINEDSIZE == aReflowState.ComputedWidth() ||
|
|
|
|
0 == aReflowState.ComputedWidth())))
|
2011-10-17 14:59:28 +00:00
|
|
|
? false
|
2003-05-15 03:42:21 +00:00
|
|
|
: HaveFixedSize(aReflowState.mStylePosition);
|
2001-11-07 05:02:42 +00:00
|
|
|
}
|
2001-03-06 00:47:46 +00:00
|
|
|
|
2005-11-01 20:40:54 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsImageFrame(aContext);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsImageFrame)
|
|
|
|
|
2001-10-06 05:08:16 +00:00
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
nsImageFrame::nsImageFrame(nsStyleContext* aContext) :
|
|
|
|
ImageFrameSuper(aContext),
|
2003-03-19 03:47:09 +00:00
|
|
|
mComputedSize(0, 0),
|
2010-09-08 20:40:38 +00:00
|
|
|
mIntrinsicRatio(0, 0),
|
2011-10-17 14:59:28 +00:00
|
|
|
mDisplayingIcon(false)
|
2000-04-19 14:00:11 +00:00
|
|
|
{
|
2003-03-19 03:47:09 +00: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-08 20:40:38 +00:00
|
|
|
mIntrinsicSize.width.SetCoordValue(0);
|
|
|
|
mIntrinsicSize.height.SetCoordValue(0);
|
2000-04-19 14:00:11 +00:00
|
|
|
}
|
|
|
|
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::~nsImageFrame()
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsImageFrame)
|
2011-04-26 06:52:19 +00:00
|
|
|
NS_QUERYFRAME_ENTRY(nsImageFrame)
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(ImageFrameSuper)
|
2001-02-19 21:50:04 +00:00
|
|
|
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2010-06-28 12:02:03 +00:00
|
|
|
already_AddRefed<nsAccessible>
|
|
|
|
nsImageFrame::CreateAccessible()
|
2001-05-17 23:52:32 +00:00
|
|
|
{
|
2011-01-28 04:38:14 +00:00
|
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
2001-05-17 23:52:32 +00:00
|
|
|
if (accService) {
|
2010-06-28 12:02:03 +00:00
|
|
|
return accService->CreateHTMLImageAccessible(mContent,
|
|
|
|
PresContext()->PresShell());
|
2001-05-17 23:52:32 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 12:02:03 +00:00
|
|
|
return nsnull;
|
2001-05-17 23:52:32 +00:00
|
|
|
}
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
2001-05-17 23:52:32 +00:00
|
|
|
|
2006-04-10 00:16:29 +00:00
|
|
|
void
|
2011-10-29 10:44:50 +00:00
|
|
|
nsImageFrame::DisconnectMap()
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2003-03-19 03:47:09 +00:00
|
|
|
if (mImageMap) {
|
2001-05-04 06:29:59 +00:00
|
|
|
mImageMap->Destroy();
|
|
|
|
NS_RELEASE(mImageMap);
|
|
|
|
}
|
2011-10-29 10:44:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
|
|
{
|
|
|
|
// 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-08 22:34:40 +00:00
|
|
|
|
2001-04-15 02:13:49 +00:00
|
|
|
// set the frame to null so we don't send messages to a dead object.
|
2003-03-19 03:47:09 +00:00
|
|
|
if (mListener) {
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader) {
|
2011-02-01 04:50:01 +00:00
|
|
|
// Push a null JSContext on the stack so that code that runs
|
|
|
|
// within the below code doesn't think it's being called by
|
|
|
|
// JS. See bug 604262.
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
|
|
|
|
2011-11-09 21:39:16 +00:00
|
|
|
// Notify our image loading content that we are going away so it can
|
|
|
|
// deregister with our refresh driver.
|
|
|
|
imageLoader->FrameDestroyed(this);
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
imageLoader->RemoveObserver(mListener);
|
|
|
|
}
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
reinterpret_cast<nsImageListener*>(mListener.get())->SetFrame(nsnull);
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
|
|
|
|
2001-04-15 02:13:49 +00:00
|
|
|
mListener = nsnull;
|
2001-03-22 01:38:35 +00:00
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
// If we were displaying an icon, take ourselves off the list
|
|
|
|
if (mDisplayingIcon)
|
|
|
|
gIconLoad->RemoveIconObserver(this);
|
|
|
|
|
2009-12-24 05:21:15 +00:00
|
|
|
nsSplittableFrame::DestroyFrom(aDestructRoot);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 01:38:35 +00:00
|
|
|
|
|
|
|
|
1998-12-29 03:38:16 +00:00
|
|
|
NS_IMETHODIMP
|
2006-03-09 18:55:21 +00:00
|
|
|
nsImageFrame::Init(nsIContent* aContent,
|
1999-01-14 05:16:23 +00:00
|
|
|
nsIFrame* aParent,
|
1999-02-25 03:27:57 +00:00
|
|
|
nsIFrame* aPrevInFlow)
|
1998-12-29 03:38:16 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
nsresult rv = nsSplittableFrame::Init(aContent, aParent, aPrevInFlow);
|
2003-03-19 03:47:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-02-26 05:51:32 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
mListener = new nsImageListener(this);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aContent);
|
|
|
|
NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
|
2011-02-01 04:50:01 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
// Push a null JSContext on the stack so that code that runs
|
|
|
|
// within the below code doesn't think it's being called by
|
|
|
|
// JS. See bug 604262.
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
|
|
|
|
|
|
|
imageLoader->AddObserver(mListener);
|
|
|
|
}
|
2003-03-19 03:47:09 +00:00
|
|
|
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext *aPresContext = PresContext();
|
2006-03-09 18:55:21 +00:00
|
|
|
|
2004-02-03 20:30:02 +00:00
|
|
|
if (!gIconLoad)
|
|
|
|
LoadIcons(aPresContext);
|
2003-03-19 03:47:09 +00:00
|
|
|
|
2011-11-09 21:39:16 +00: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 18:05:40 +00:00
|
|
|
// Give image loads associated with an image frame a small priority boost!
|
2003-03-19 03:47:09 +00:00
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
2005-09-18 18:05:40 +00:00
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(currentRequest);
|
|
|
|
if (p)
|
|
|
|
p->AdjustPriority(-1);
|
2005-02-21 20:58:01 +00:00
|
|
|
|
2003-05-04 18:06:10 +00:00
|
|
|
// If we already have an image container, OnStartContainer won't be called
|
|
|
|
// Set the animation mode here
|
2003-12-26 04:24:11 +00:00
|
|
|
if (currentRequest) {
|
2004-01-08 18:29:28 +00:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
2003-05-04 18:06:10 +00:00
|
|
|
currentRequest->GetImage(getter_AddRefs(image));
|
2004-01-08 18:29:28 +00:00
|
|
|
if (image) {
|
2004-02-03 20:30:02 +00:00
|
|
|
image->SetAnimationMode(aPresContext->ImageAnimationMode());
|
2004-01-08 18:29:28 +00:00
|
|
|
}
|
2003-05-04 18:06:10 +00:00
|
|
|
}
|
2003-12-26 04:24:11 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2007-03-20 00:58:20 +00:00
|
|
|
nsImageFrame::UpdateIntrinsicSize(imgIContainer* aImage)
|
2003-03-19 03:47:09 +00:00
|
|
|
{
|
2007-03-20 00:58:20 +00:00
|
|
|
NS_PRECONDITION(aImage, "null image");
|
2010-09-08 20:40:38 +00:00
|
|
|
if (!aImage)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2007-03-20 00:58:20 +00:00
|
|
|
|
2010-09-08 20:40:38 +00:00
|
|
|
nsIFrame::IntrinsicSize oldIntrinsicSize = mIntrinsicSize;
|
|
|
|
|
|
|
|
nsIFrame* rootFrame = aImage->GetRootLayoutFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
// Set intrinsic size to match that of aImage's rootFrame.
|
|
|
|
mIntrinsicSize = rootFrame->GetIntrinsicSize();
|
|
|
|
} else {
|
|
|
|
// Set intrinsic size to match aImage's reported width & height.
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntSize imageSizeInPx;
|
2010-01-24 20:06:19 +00:00
|
|
|
if (NS_FAILED(aImage->GetWidth(&imageSizeInPx.width)) ||
|
|
|
|
NS_FAILED(aImage->GetHeight(&imageSizeInPx.height))) {
|
|
|
|
imageSizeInPx.SizeTo(0, 0);
|
|
|
|
}
|
2010-09-08 20:40:38 +00:00
|
|
|
mIntrinsicSize.width.SetCoordValue(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(imageSizeInPx.width));
|
|
|
|
mIntrinsicSize.height.SetCoordValue(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(imageSizeInPx.height));
|
1999-02-27 00:57:04 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:38 +00:00
|
|
|
return mIntrinsicSize != oldIntrinsicSize;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-09-08 20:40:38 +00:00
|
|
|
nsImageFrame::UpdateIntrinsicRatio(imgIContainer* aImage)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aImage, "null image");
|
|
|
|
|
|
|
|
if (!aImage)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-09-08 20:40:38 +00:00
|
|
|
|
|
|
|
nsSize oldIntrinsicRatio = mIntrinsicRatio;
|
|
|
|
|
|
|
|
nsIFrame* rootFrame = aImage->GetRootLayoutFrame();
|
|
|
|
if (rootFrame) {
|
|
|
|
// Set intrinsic ratio to match that of aImage's rootFrame.
|
|
|
|
mIntrinsicRatio = rootFrame->GetIntrinsicRatio();
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord,
|
|
|
|
"since aImage doesn't have a rootFrame, our intrinsic "
|
|
|
|
"dimensions must have coord units (not percent units)");
|
|
|
|
mIntrinsicRatio.width = mIntrinsicSize.width.GetCoordValue();
|
|
|
|
mIntrinsicRatio.height = mIntrinsicSize.height.GetCoordValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mIntrinsicRatio != oldIntrinsicRatio;
|
2007-03-20 00:58:20 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-09-08 20:40:38 +00:00
|
|
|
nsImageFrame::GetSourceToDestTransform(nsTransform2D& aTransform)
|
2007-03-20 00:58:20 +00:00
|
|
|
{
|
2010-09-08 20:40:38 +00:00
|
|
|
// Set the translation components.
|
2003-03-19 03:47:09 +00:00
|
|
|
// XXXbz does this introduce rounding errors because of the cast to
|
|
|
|
// float? Should we just manually add that stuff in every time
|
|
|
|
// instead?
|
2010-09-08 20:40:38 +00:00
|
|
|
nsRect innerArea = GetInnerArea();
|
|
|
|
aTransform.SetToTranslate(float(innerArea.x),
|
|
|
|
float(innerArea.y - GetContinuationOffset()));
|
|
|
|
|
|
|
|
// Set the scale factors.
|
2010-09-08 20:40:38 +00:00
|
|
|
if (mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.width.GetCoordValue() != 0 &&
|
|
|
|
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.height.GetCoordValue() != 0 &&
|
|
|
|
mIntrinsicSize.width.GetCoordValue() != mComputedSize.width &&
|
|
|
|
mIntrinsicSize.height.GetCoordValue() != mComputedSize.height) {
|
2010-09-08 20:40:38 +00:00
|
|
|
|
|
|
|
aTransform.SetScale(float(mComputedSize.width) /
|
2010-09-08 20:40:38 +00:00
|
|
|
float(mIntrinsicSize.width.GetCoordValue()),
|
|
|
|
float(mComputedSize.height) /
|
|
|
|
float(mIntrinsicSize.height.GetCoordValue()));
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
2010-09-08 20:40:38 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
2001-03-22 01:38:35 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
/*
|
|
|
|
* These two functions basically do the same check. The first one
|
|
|
|
* checks that the given request is the current request for our
|
|
|
|
* mContent. The second checks that the given image container the
|
|
|
|
* same as the image container on the current request for our
|
|
|
|
* mContent.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2003-03-19 03:47:09 +00: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?");
|
|
|
|
|
|
|
|
PRInt32 requestType = nsIImageLoadingContent::UNKNOWN_REQUEST;
|
|
|
|
imageLoader->GetRequestType(aRequest, &requestType);
|
|
|
|
|
|
|
|
return requestType != nsIImageLoadingContent::CURRENT_REQUEST;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2003-03-19 03:47:09 +00:00
|
|
|
nsImageFrame::IsPendingLoad(imgIContainer* aContainer) const
|
|
|
|
{
|
|
|
|
// default to pending load in case of errors
|
|
|
|
if (!aContainer) {
|
|
|
|
NS_ERROR("No image container!");
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader(do_QueryInterface(mContent));
|
|
|
|
NS_ASSERTION(imageLoader, "No image loading content?");
|
|
|
|
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
if (!currentRequest) {
|
|
|
|
NS_ERROR("No current request");
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> currentContainer;
|
|
|
|
currentRequest->GetImage(getter_AddRefs(currentContainer));
|
|
|
|
|
|
|
|
return currentContainer != aContainer;
|
|
|
|
|
1998-12-29 03:38:16 +00:00
|
|
|
}
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
nsRect
|
2009-01-15 03:27:09 +00:00
|
|
|
nsImageFrame::SourceRectToDest(const nsIntRect& aRect)
|
2003-03-19 03:47:09 +00:00
|
|
|
{
|
2004-08-28 23:59:15 +00: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 07:46:44 +00: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-28 23:59:15 +00:00
|
|
|
|
2010-09-08 20:40:38 +00: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-28 23:59:15 +00:00
|
|
|
|
|
|
|
// Now, round the edges out to the pixel boundary.
|
2010-09-08 20:40:38 +00:00
|
|
|
nscoord scale = nsPresContext::CSSPixelsToAppUnits(1);
|
2004-08-28 23:59:15 +00: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 03:47:09 +00:00
|
|
|
}
|
2001-03-22 01:38:35 +00:00
|
|
|
|
2005-11-02 00:04:29 +00: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 11:26:32 +00: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 03:47:09 +00:00
|
|
|
|
2005-09-18 18:05:40 +00:00
|
|
|
/* static */
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-06-01 01:46:56 +00:00
|
|
|
nsImageFrame::ShouldCreateImageFrameFor(Element* aElement,
|
2005-09-18 18:05:40 +00:00
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
2011-06-01 01:46:57 +00:00
|
|
|
nsEventStates state = aElement->State();
|
2005-11-02 00:04:29 +00:00
|
|
|
if (IMAGE_OK(state,
|
|
|
|
HaveFixedSize(aStyleContext->GetStylePosition()))) {
|
2005-09-18 18:05:40 +00:00
|
|
|
// Image is fine; do the image frame thing
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
2005-10-17 00:50:39 +00:00
|
|
|
|
2003-04-29 18:49:42 +00:00
|
|
|
// Check if we want to use a placeholder box with an icon or just
|
2005-11-20 22:05:24 +00:00
|
|
|
// let the presShell make us into inline text. Decide as follows:
|
2003-04-29 18:49:42 +00: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:
|
|
|
|
// - if QuirksMode, and 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 18:05:40 +00:00
|
|
|
// - if QuirksMode, and the IMG has a size show an icon.
|
2003-04-29 18:49:42 +00:00
|
|
|
// - otherwise, skip the icon
|
2011-09-29 06:19:26 +00:00
|
|
|
bool useSizedBox;
|
2003-04-29 18:49:42 +00:00
|
|
|
|
2005-09-18 18:05:40 +00:00
|
|
|
if (aStyleContext->GetStyleUIReset()->mForceBrokenImageIcon) {
|
2011-10-17 14:59:28 +00:00
|
|
|
useSizedBox = true;
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
2004-02-03 20:30:02 +00:00
|
|
|
else if (gIconLoad && gIconLoad->mPrefForceInlineAltText) {
|
2011-10-17 14:59:28 +00:00
|
|
|
useSizedBox = false;
|
2003-04-29 18:49:42 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-09-18 18:05:40 +00:00
|
|
|
if (aStyleContext->PresContext()->CompatibilityMode() !=
|
|
|
|
eCompatibility_NavQuirks) {
|
2011-10-17 14:59:28 +00:00
|
|
|
useSizedBox = false;
|
2003-04-29 18:49:42 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We are in quirks mode, so we can just check the tag name; no need to
|
|
|
|
// check the namespace.
|
2011-06-01 01:46:56 +00:00
|
|
|
nsIAtom *localName = aElement->Tag();
|
2003-09-27 04:18:26 +00:00
|
|
|
|
2005-09-18 18:05:40 +00: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).
|
2011-06-01 01:46:56 +00:00
|
|
|
if (!aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::alt) &&
|
2006-12-26 17:47:52 +00:00
|
|
|
localName != nsGkAtoms::object &&
|
|
|
|
localName != nsGkAtoms::input) {
|
2011-10-17 14:59:28 +00:00
|
|
|
useSizedBox = true;
|
2003-04-29 18:49:42 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// check whether we have fixed size
|
2005-09-18 18:05:40 +00:00
|
|
|
useSizedBox = HaveFixedSize(aStyleContext->GetStylePosition());
|
2003-04-29 18:49:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 18:05:40 +00:00
|
|
|
return useSizedBox;
|
2001-03-22 01:38:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
nsresult
|
|
|
|
nsImageFrame::OnStartContainer(imgIRequest *aRequest, imgIContainer *aImage)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
2001-10-06 05:08:16 +00:00
|
|
|
if (!aImage) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2003-12-26 04:24:11 +00:00
|
|
|
/* Get requested animation policy from the pres context:
|
|
|
|
* normal = 0
|
|
|
|
* one frame = 1
|
|
|
|
* one loop = 2
|
|
|
|
*/
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext *presContext = PresContext();
|
2004-02-03 20:30:02 +00:00
|
|
|
aImage->SetAnimationMode(presContext->ImageAnimationMode());
|
2001-04-16 22:02:39 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
if (IsPendingLoad(aRequest)) {
|
|
|
|
// We don't care
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool intrinsicSizeChanged = UpdateIntrinsicSize(aImage);
|
2011-08-23 21:03:02 +00:00
|
|
|
intrinsicSizeChanged = UpdateIntrinsicRatio(aImage) || intrinsicSizeChanged;
|
2001-03-22 01:38:35 +00:00
|
|
|
|
2011-08-23 21:03:02 +00:00
|
|
|
if (intrinsicSizeChanged && (mState & IMAGE_GOTINITIALREFLOW)) {
|
2009-02-06 16:52:13 +00:00
|
|
|
// Now we need to reflow if we have an unconstrained size and have
|
|
|
|
// already gotten the initial reflow
|
|
|
|
if (!(mState & IMAGE_SIZECONSTRAINED)) {
|
|
|
|
nsIPresShell *presShell = presContext->GetPresShell();
|
|
|
|
NS_ASSERTION(presShell, "No PresShell.");
|
|
|
|
if (presShell) {
|
|
|
|
presShell->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
|
|
|
}
|
2001-03-22 01:38:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
nsresult
|
|
|
|
nsImageFrame::OnDataAvailable(imgIRequest *aRequest,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCurrentFrame,
|
2009-01-15 03:27:09 +00:00
|
|
|
const nsIntRect *aRect)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
2003-03-19 03:47:09 +00:00
|
|
|
// XXX do we need to make sure that the reflow from the
|
|
|
|
// OnStartContainer has been processed before we start calling
|
|
|
|
// invalidate?
|
2001-04-04 08:23:14 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aRect);
|
2003-03-19 06:51:46 +00:00
|
|
|
|
|
|
|
if (!(mState & IMAGE_GOTINITIALREFLOW)) {
|
|
|
|
// Don't bother to do anything; we have a reflow coming up!
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
if (IsPendingLoad(aRequest)) {
|
|
|
|
// We don't care
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-06 05:08:16 +00:00
|
|
|
|
2003-03-05 23:55:53 +00:00
|
|
|
// Don't invalidate if the current visible frame isn't the one the data is
|
|
|
|
// from
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
if (!aCurrentFrame)
|
|
|
|
return NS_OK;
|
2001-10-06 05:08:16 +00:00
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
// XXX We really need to round this out, now that we're doing better
|
|
|
|
// image scaling!
|
2011-04-19 03:07:23 +00:00
|
|
|
nsRect r = aRect->IsEqualInterior(nsIntRect::GetMaxSizedIntRect()) ?
|
2010-09-08 20:40:39 +00:00
|
|
|
GetInnerArea() :
|
|
|
|
SourceRectToDest(*aRect);
|
|
|
|
|
2004-08-28 23:59:15 +00:00
|
|
|
#ifdef DEBUG_decode
|
|
|
|
printf("Source rect (%d,%d,%d,%d) -> invalidate dest rect (%d,%d,%d,%d)\n",
|
|
|
|
aRect->x, aRect->y, aRect->width, aRect->height,
|
|
|
|
r.x, r.y, r.width, r.height);
|
|
|
|
#endif
|
|
|
|
|
2008-09-18 09:47:21 +00:00
|
|
|
Invalidate(r);
|
2003-03-19 03:47:09 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-07-11 05:44:12 +00:00
|
|
|
}
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
nsresult
|
|
|
|
nsImageFrame::OnStopDecode(imgIRequest *aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar *aStatusArg)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext *presContext = PresContext();
|
2004-02-03 20:30:02 +00:00
|
|
|
nsIPresShell *presShell = presContext->GetPresShell();
|
2003-02-26 05:51:32 +00:00
|
|
|
NS_ASSERTION(presShell, "No PresShell.");
|
2001-04-15 02:13:49 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
// Check what request type we're dealing with
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
NS_ASSERTION(imageLoader, "Who's notifying us??");
|
|
|
|
PRInt32 loadType = nsIImageLoadingContent::UNKNOWN_REQUEST;
|
|
|
|
imageLoader->GetRequestType(aRequest, &loadType);
|
|
|
|
if (loadType != nsIImageLoadingContent::CURRENT_REQUEST &&
|
|
|
|
loadType != nsIImageLoadingContent::PENDING_REQUEST) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-10-06 05:08:16 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
if (loadType == nsIImageLoadingContent::PENDING_REQUEST) {
|
|
|
|
// May have to switch sizes here!
|
2011-09-29 06:19:26 +00:00
|
|
|
bool intrinsicSizeChanged = true;
|
2001-10-06 05:08:16 +00:00
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
2003-03-19 03:47:09 +00:00
|
|
|
nsCOMPtr<imgIContainer> imageContainer;
|
|
|
|
aRequest->GetImage(getter_AddRefs(imageContainer));
|
|
|
|
NS_ASSERTION(imageContainer, "Successful load with no container?");
|
2007-03-20 00:58:20 +00:00
|
|
|
intrinsicSizeChanged = UpdateIntrinsicSize(imageContainer);
|
2010-09-08 20:40:38 +00:00
|
|
|
intrinsicSizeChanged = UpdateIntrinsicRatio(imageContainer) ||
|
|
|
|
intrinsicSizeChanged;
|
2002-06-18 21:28:53 +00:00
|
|
|
}
|
2003-05-30 19:47:08 +00:00
|
|
|
else {
|
|
|
|
// Have to size to 0,0 so that GetDesiredSize recalculates the size
|
2010-09-08 20:40:38 +00:00
|
|
|
mIntrinsicSize.width.SetCoordValue(0);
|
|
|
|
mIntrinsicSize.height.SetCoordValue(0);
|
|
|
|
mIntrinsicRatio.SizeTo(0, 0);
|
2003-05-30 19:47:08 +00:00
|
|
|
}
|
2002-06-18 21:28:53 +00:00
|
|
|
|
2005-11-20 22:05:24 +00:00
|
|
|
if (mState & IMAGE_GOTINITIALREFLOW) { // do nothing if we haven't gotten the initial reflow yet
|
2003-03-19 06:51:46 +00:00
|
|
|
if (!(mState & IMAGE_SIZECONSTRAINED) && intrinsicSizeChanged) {
|
2007-05-06 19:16:51 +00:00
|
|
|
if (presShell) {
|
|
|
|
presShell->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2003-03-19 06:51:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-06-29 03:43:05 +00:00
|
|
|
nsSize s = GetSize();
|
2003-03-19 06:51:46 +00:00
|
|
|
nsRect r(0, 0, s.width, s.height);
|
2004-03-10 03:09:05 +00:00
|
|
|
// Update border+content to account for image change
|
2008-09-18 09:47:21 +00:00
|
|
|
Invalidate(r);
|
2002-06-18 21:28:53 +00:00
|
|
|
}
|
2001-10-06 05:08:16 +00:00
|
|
|
}
|
2001-04-15 02:13:49 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 01:38:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
nsresult
|
2010-08-14 04:09:48 +00:00
|
|
|
nsImageFrame::FrameChanged(imgIContainer *aContainer,
|
|
|
|
const nsIntRect *aDirtyRect)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
2003-05-15 03:42:21 +00:00
|
|
|
if (!GetStyleVisibility()->IsVisible()) {
|
2002-07-01 18:17:35 +00:00
|
|
|
return NS_OK;
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
2002-07-01 18:17:35 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
if (IsPendingLoad(aContainer)) {
|
|
|
|
// We don't care about it
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2011-04-19 03:07:23 +00:00
|
|
|
nsRect r = aDirtyRect->IsEqualInterior(nsIntRect::GetMaxSizedIntRect()) ?
|
2010-09-08 20:40:39 +00:00
|
|
|
GetInnerArea() :
|
|
|
|
SourceRectToDest(*aDirtyRect);
|
2001-03-22 01:38:35 +00:00
|
|
|
|
2004-03-10 03:09:05 +00:00
|
|
|
// Update border+content to account for image change
|
2008-09-18 09:47:21 +00:00
|
|
|
Invalidate(r);
|
2001-03-22 01:38:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-13 11:32:43 +00:00
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
void
|
2010-09-08 20:40:38 +00:00
|
|
|
nsImageFrame::EnsureIntrinsicSizeAndRatio(nsPresContext* aPresContext)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2003-03-19 03:47:09 +00:00
|
|
|
// if mIntrinsicSize.width and height are 0, then we should
|
2001-12-11 03:21:13 +00:00
|
|
|
// check to see if the size is already known by the image container.
|
2010-09-08 20:40:38 +00:00
|
|
|
if (mIntrinsicSize.width.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.width.GetCoordValue() == 0 &&
|
|
|
|
mIntrinsicSize.height.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
mIntrinsicSize.height.GetCoordValue() == 0) {
|
2009-08-12 14:23:38 +00:00
|
|
|
|
|
|
|
// Jump through all the hoops to get the status of the request
|
2003-03-19 03:47:09 +00:00
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
2009-08-12 14:23:38 +00:00
|
|
|
if (imageLoader)
|
2003-03-19 03:47:09 +00:00
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
2009-08-12 14:23:38 +00:00
|
|
|
PRUint32 status = 0;
|
|
|
|
if (currentRequest)
|
|
|
|
currentRequest->GetImageStatus(&status);
|
2002-03-26 20:14:05 +00:00
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
// If we know the size, we can grab it and use it for an update
|
|
|
|
if (status & imgIRequest::STATUS_SIZE_AVAILABLE) {
|
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
currentRequest->GetImage(getter_AddRefs(imgCon));
|
|
|
|
NS_ABORT_IF_FALSE(imgCon, "SIZE_AVAILABLE, but no imgContainer?");
|
|
|
|
UpdateIntrinsicSize(imgCon);
|
2010-09-08 20:40:38 +00:00
|
|
|
UpdateIntrinsicRatio(imgCon);
|
2003-03-19 03:47:09 +00:00
|
|
|
} else {
|
|
|
|
// image request is null or image size not known, probably an
|
|
|
|
// invalid image specified
|
|
|
|
// - make the image big enough for the icon (it may not be
|
|
|
|
// used if inline alt expansion is used instead)
|
|
|
|
// XXX: we need this in composer, but it is also good for
|
|
|
|
// XXX: general quirks mode to always have room for the icon
|
2003-12-24 21:51:50 +00:00
|
|
|
if (aPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
|
2010-09-08 20:40:38 +00: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 08:19:44 +00:00
|
|
|
}
|
2001-10-06 05:08:16 +00: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 05:38:33 +00:00
|
|
|
}
|
2001-10-06 05:08:16 +00: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 05:38:33 +00:00
|
|
|
/* virtual */ nsSize
|
2011-04-08 01:04:40 +00:00
|
|
|
nsImageFrame::ComputeSize(nsRenderingContext *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 05:38:33 +00:00
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aShrinkWrap)
|
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 05:38:33 +00:00
|
|
|
{
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext *presContext = PresContext();
|
2010-09-08 20:40:38 +00:00
|
|
|
EnsureIntrinsicSizeAndRatio(presContext);
|
2007-11-18 12:09:03 +00: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 05:38:33 +00:00
|
|
|
return nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
|
|
|
|
aRenderingContext, this,
|
2010-09-08 20:40:38 +00:00
|
|
|
mIntrinsicSize, mIntrinsicRatio, aCBSize,
|
2007-11-18 12:09:03 +00:00
|
|
|
aMargin, aBorder, aPadding);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
2004-12-26 19:48:54 +00:00
|
|
|
nsRect
|
|
|
|
nsImageFrame::GetInnerArea() const
|
1998-11-20 17:21:02 +00:00
|
|
|
{
|
2007-03-20 00:58:20 +00:00
|
|
|
return GetContentRect() - GetPosition();
|
2001-11-01 15:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the offset into the content area of the image where aImg starts if it is a continuation.
|
|
|
|
nscoord
|
2007-03-20 00:58:20 +00:00
|
|
|
nsImageFrame::GetContinuationOffset() const
|
2001-11-01 15:31:13 +00:00
|
|
|
{
|
|
|
|
nscoord offset = 0;
|
2007-03-20 00:58:20 +00:00
|
|
|
for (nsIFrame *f = GetPrevInFlow(); f; f = f->GetPrevInFlow()) {
|
|
|
|
offset += f->GetContentRect().height;
|
2001-11-01 15:31:13 +00:00
|
|
|
}
|
2007-03-20 00:58:20 +00:00
|
|
|
NS_ASSERTION(offset >= 0, "bogus GetContentRect");
|
2001-11-01 15:31:13 +00:00
|
|
|
return offset;
|
1998-11-20 17:21:02 +00: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 05:38:33 +00:00
|
|
|
/* virtual */ nscoord
|
2011-04-08 01:04:40 +00:00
|
|
|
nsImageFrame::GetMinWidth(nsRenderingContext *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 05:38:33 +00:00
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2011-06-21 15:37:47 +00: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 05:38:33 +00:00
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext *presContext = PresContext();
|
2010-09-08 20:40:38 +00:00
|
|
|
EnsureIntrinsicSizeAndRatio(presContext);
|
|
|
|
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 05:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-08 01:04:40 +00:00
|
|
|
nsImageFrame::GetPrefWidth(nsRenderingContext *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 05:38:33 +00:00
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2011-06-21 15:37:47 +00: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 05:38:33 +00:00
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext *presContext = PresContext();
|
2010-09-08 20:40:38 +00:00
|
|
|
EnsureIntrinsicSizeAndRatio(presContext);
|
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 05:38:33 +00:00
|
|
|
// convert from normal twips to scaled twips (printing...)
|
2010-09-08 20:40:38 +00: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 05:38:33 +00:00
|
|
|
}
|
|
|
|
|
2010-09-14 20:20:32 +00:00
|
|
|
/* virtual */ nsIFrame::IntrinsicSize
|
|
|
|
nsImageFrame::GetIntrinsicSize()
|
|
|
|
{
|
|
|
|
return mIntrinsicSize;
|
|
|
|
}
|
|
|
|
|
2007-06-12 18:27:09 +00:00
|
|
|
/* virtual */ nsSize
|
|
|
|
nsImageFrame::GetIntrinsicRatio()
|
|
|
|
{
|
2010-09-08 20:40:38 +00:00
|
|
|
return mIntrinsicRatio;
|
2007-06-12 18:27:09 +00:00
|
|
|
}
|
|
|
|
|
1998-11-20 17:21:02 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsImageFrame::Reflow(nsPresContext* aPresContext,
|
1998-11-20 17:21:02 +00:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsImageFrame");
|
2001-11-14 13:40:03 +00:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
1998-11-20 17:21:02 +00:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2000-05-14 04:43:52 +00:00
|
|
|
("enter nsImageFrame::Reflow: availSize=%d,%d",
|
1999-01-05 23:31:18 +00:00
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight));
|
1998-11-20 17:21:02 +00:00
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
2001-11-01 15:31:13 +00:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
2001-03-06 00:47:46 +00:00
|
|
|
// see if we have a frozen size (i.e. a fixed width and height)
|
2003-02-24 22:20:26 +00:00
|
|
|
if (HaveFixedSize(aReflowState)) {
|
|
|
|
mState |= IMAGE_SIZECONSTRAINED;
|
|
|
|
} else {
|
2003-03-19 03:47:09 +00:00
|
|
|
mState &= ~IMAGE_SIZECONSTRAINED;
|
2003-02-24 22:20:26 +00:00
|
|
|
}
|
2001-03-06 00:47:46 +00: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 05:38:33 +00: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) {
|
2003-02-24 22:20:26 +00:00
|
|
|
mState |= IMAGE_GOTINITIALREFLOW;
|
2003-03-19 03:47:09 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 00:58:20 +00:00
|
|
|
mComputedSize =
|
2007-08-02 18:08:05 +00:00
|
|
|
nsSize(aReflowState.ComputedWidth(), aReflowState.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 05:38:33 +00:00
|
|
|
|
|
|
|
aMetrics.width = mComputedSize.width;
|
|
|
|
aMetrics.height = mComputedSize.height;
|
2001-11-01 15:31:13 +00:00
|
|
|
|
|
|
|
// add borders and padding
|
2007-03-20 00:58:20 +00:00
|
|
|
aMetrics.width += aReflowState.mComputedBorderPadding.LeftRight();
|
|
|
|
aMetrics.height += aReflowState.mComputedBorderPadding.TopBottom();
|
2001-11-01 15:31:13 +00:00
|
|
|
|
2006-02-21 21:33:47 +00:00
|
|
|
if (GetPrevInFlow()) {
|
2007-03-20 00:58:20 +00:00
|
|
|
aMetrics.width = GetPrevInFlow()->GetSize().width;
|
|
|
|
nscoord y = GetContinuationOffset();
|
|
|
|
aMetrics.height -= y + aReflowState.mComputedBorderPadding.top;
|
2009-09-16 15:01:36 +00:00
|
|
|
aMetrics.height = NS_MAX(0, aMetrics.height);
|
2001-11-01 15:31:13 +00:00
|
|
|
}
|
|
|
|
|
2002-01-11 19:32:55 +00: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
|
2002-08-29 01:44:15 +00:00
|
|
|
PRUint32 loadStatus = imgIRequest::STATUS_NONE;
|
2003-03-19 03:47:09 +00: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 01:44:15 +00:00
|
|
|
}
|
2004-03-03 18:24:20 +00:00
|
|
|
if (aPresContext->IsPaginated() &&
|
2003-02-24 22:20:26 +00:00
|
|
|
((loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE) || (mState & IMAGE_SIZECONSTRAINED)) &&
|
2003-03-19 03:47:09 +00:00
|
|
|
NS_UNCONSTRAINEDSIZE != aReflowState.availableHeight &&
|
|
|
|
aMetrics.height > aReflowState.availableHeight) {
|
2008-01-05 06:44:38 +00:00
|
|
|
// our desired height was greater than 0, so to avoid infinite
|
|
|
|
// splitting, use 1 pixel as the min
|
2009-09-16 15:01:36 +00:00
|
|
|
aMetrics.height = NS_MAX(nsPresContext::CSSPixelsToAppUnits(1), aReflowState.availableHeight);
|
2008-01-05 06:44:38 +00:00
|
|
|
aStatus = NS_FRAME_NOT_COMPLETE;
|
2001-11-01 15:31:13 +00:00
|
|
|
}
|
|
|
|
|
2010-10-07 04:25:46 +00:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
2004-07-16 16:56:21 +00:00
|
|
|
FinishAndStoreOverflow(&aMetrics);
|
1998-11-20 17:21:02 +00:00
|
|
|
|
2005-03-03 04:42:48 +00:00
|
|
|
// Now that that's all done, check whether we're resizing... if we are,
|
|
|
|
// invalidate our rect.
|
|
|
|
// XXXbz we really only want to do this when reflow is completely done, but
|
|
|
|
// we have no way to detect when mRect changes (since SetRect is non-virtual,
|
|
|
|
// so this is the best we can do).
|
|
|
|
if (mRect.width != aMetrics.width || mRect.height != aMetrics.height) {
|
2008-09-18 09:47:21 +00:00
|
|
|
Invalidate(nsRect(0, 0, mRect.width, mRect.height));
|
2005-03-03 04:42:48 +00:00
|
|
|
}
|
|
|
|
|
1998-11-20 17:21:02 +00:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2000-05-14 04:43:52 +00:00
|
|
|
("exit nsImageFrame::Reflow: size=%d,%d",
|
1998-11-20 17:21:02 +00:00
|
|
|
aMetrics.width, aMetrics.height));
|
2002-05-28 22:50:43 +00:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
1998-11-20 17:21:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00: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 01:12:39 +00: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 07:08:45 +00:00
|
|
|
nscoord
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::MeasureString(const PRUnichar* aString,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nscoord aMaxWidth,
|
|
|
|
PRUint32& aMaxFit,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aContext)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
nscoord totalWidth = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
aContext.SetTextRunRTL(false);
|
2011-04-08 01:04:40 +00:00
|
|
|
nscoord spaceWidth = aContext.GetWidth(' ');
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
aMaxFit = 0;
|
|
|
|
while (aLength > 0) {
|
|
|
|
// Find the next place we can line break
|
|
|
|
PRUint32 len = aLength;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool trailingSpace = false;
|
1998-09-08 22:34:40 +00:00
|
|
|
for (PRInt32 i = 0; i < aLength; i++) {
|
|
|
|
if (XP_IS_SPACE(aString[i]) && (i > 0)) {
|
|
|
|
len = i; // don't include the space when measuring
|
2011-10-17 14:59:28 +00:00
|
|
|
trailingSpace = true;
|
1998-09-08 22:34:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measure this chunk of text, and see if it fits
|
2007-01-23 02:58:55 +00:00
|
|
|
nscoord width =
|
|
|
|
nsLayoutUtils::GetStringWidth(this, &aContext, aString, len);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool fits = (totalWidth + width) <= aMaxWidth;
|
1998-09-08 22:34:40 +00: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 14:59:28 +00:00
|
|
|
fits = false;
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMaxFit += len;
|
|
|
|
aString += len;
|
|
|
|
aLength -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fits) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-31 07:08:45 +00:00
|
|
|
return totalWidth;
|
1998-09-08 22:34:40 +00: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-07-31 23:15:21 +00:00
|
|
|
nsImageFrame::DisplayAltText(nsPresContext* aPresContext,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext& aRenderingContext,
|
1998-11-20 17:21:02 +00:00
|
|
|
const nsString& aAltText,
|
|
|
|
const nsRect& aRect)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
|
|
|
// Set font and color
|
2003-05-15 03:42:21 +00:00
|
|
|
aRenderingContext.SetColor(GetStyleColor()->mColor);
|
2011-08-14 17:08:04 +00:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
Backout changesets c9abc8ef4626, d62512892555, 69f89ee5d08f, c511af7d8f58, 6a6a560a1492, ac0ec1183d19, 46669afabd15, 74f32abaa8c0, f197554cf989, 0a2405eb5b90, b48954598d7d, e0a82577259c, 0235d1541e58, 450f2557d3a2, e24d196602bf, 03c2ea0eeba3, 7aca4ef8e538, 11ec362e780b, 4b92a3b96446 (bug 627842) for Windows crashtest assertions and Android reftest failures
--HG--
extra : rebase_source : fc8946055314369bfba5038ded32afcb00bf134d
2011-11-15 06:12:31 +00:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
|
2011-08-14 17:08:04 +00:00
|
|
|
aRenderingContext.SetFont(fm);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
// Format the text to display within the formatting rect
|
|
|
|
|
2011-04-08 04:18:43 +00:00
|
|
|
nscoord maxAscent = fm->MaxAscent();
|
|
|
|
nscoord maxDescent = fm->MaxDescent();
|
|
|
|
nscoord height = fm->MaxHeight();
|
1998-09-08 22:34:40 +00: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...
|
2001-06-30 11:02:25 +00:00
|
|
|
const PRUnichar* str = aAltText.get();
|
1998-09-08 22:34:40 +00:00
|
|
|
PRInt32 strLen = aAltText.Length();
|
|
|
|
nscoord y = aRect.y;
|
2009-07-12 13:32:48 +00:00
|
|
|
|
|
|
|
if (!aPresContext->BidiEnabled() && HasRTLChars(aAltText)) {
|
|
|
|
aPresContext->SetBidiEnabled();
|
|
|
|
}
|
|
|
|
|
2004-10-11 21:52:36 +00:00
|
|
|
// Always show the first line, even if we have to clip it below
|
2011-09-29 06:19:26 +00:00
|
|
|
bool firstLine = true;
|
2004-10-11 21:52:36 +00:00
|
|
|
while ((strLen > 0) && (firstLine || (y + maxDescent) < aRect.YMost())) {
|
1998-09-08 22:34:40 +00:00
|
|
|
// Determine how much of the text to display on this line
|
|
|
|
PRUint32 maxFit; // number of characters that fit
|
2006-07-31 07:08:45 +00:00
|
|
|
nscoord strWidth = MeasureString(str, strLen, aRect.width, maxFit,
|
|
|
|
aRenderingContext);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
// Display the text
|
2006-07-31 07:08:45 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (aPresContext->BidiEnabled()) {
|
2011-04-13 09:23:49 +00:00
|
|
|
const nsStyleVisibility* vis = GetStyleVisibility();
|
|
|
|
if (vis->mDirection == NS_STYLE_DIRECTION_RTL)
|
|
|
|
rv = nsBidiPresUtils::RenderText(str, maxFit, NSBIDI_RTL,
|
|
|
|
aPresContext, aRenderingContext,
|
|
|
|
aRenderingContext,
|
|
|
|
aRect.XMost() - strWidth, y + maxAscent);
|
|
|
|
else
|
|
|
|
rv = nsBidiPresUtils::RenderText(str, maxFit, NSBIDI_LTR,
|
|
|
|
aPresContext, aRenderingContext,
|
|
|
|
aRenderingContext,
|
|
|
|
aRect.x, y + maxAscent);
|
2006-07-31 07:08:45 +00:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
aRenderingContext.DrawString(str, maxFit, aRect.x, y + maxAscent);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
|
|
|
// Move to the next line
|
|
|
|
str += maxFit;
|
|
|
|
strLen -= maxFit;
|
|
|
|
y += height;
|
2011-10-17 14:59:28 +00:00
|
|
|
firstLine = false;
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-07 09:57:26 +00:00
|
|
|
struct nsRecessedBorder : public nsStyleBorder {
|
2006-12-27 14:21:43 +00:00
|
|
|
nsRecessedBorder(nscoord aBorderWidth, nsPresContext* aPresContext)
|
|
|
|
: nsStyleBorder(aPresContext)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2005-04-29 15:44:38 +00:00
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2005-05-05 16:03:06 +00:00
|
|
|
// Note: use SetBorderColor here because we want to make sure
|
|
|
|
// the "special" flags are unset.
|
|
|
|
SetBorderColor(side, NS_RGB(0, 0, 0));
|
2011-04-19 03:07:22 +00:00
|
|
|
mBorder.Side(side) = aBorderWidth;
|
2005-05-05 16:03:06 +00:00
|
|
|
// Note: use SetBorderStyle here because we want to affect
|
|
|
|
// mComputedBorder
|
2005-04-29 15:44:38 +00:00
|
|
|
SetBorderStyle(side, NS_STYLE_BORDER_STYLE_INSET);
|
|
|
|
}
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1998-09-22 03:34:44 +00:00
|
|
|
void
|
2011-04-08 01:04:40 +00:00
|
|
|
nsImageFrame::DisplayAltFeedback(nsRenderingContext& aRenderingContext,
|
2007-03-20 00:58:20 +00:00
|
|
|
const nsRect& aDirtyRect,
|
2006-01-26 02:29:17 +00:00
|
|
|
imgIRequest* aRequest,
|
|
|
|
nsPoint aPt)
|
1998-09-22 03:34:44 +00:00
|
|
|
{
|
2009-08-12 14:23:38 +00:00
|
|
|
// We should definitely have a gIconLoad here.
|
|
|
|
NS_ABORT_IF_FALSE(gIconLoad, "How did we succeed in Init then?");
|
|
|
|
|
1999-09-16 21:37:37 +00:00
|
|
|
// Calculate the inner area
|
2006-01-26 02:29:17 +00:00
|
|
|
nsRect inner = GetInnerArea() + aPt;
|
1998-09-22 03:34:44 +00:00
|
|
|
|
1999-09-16 21:37:37 +00:00
|
|
|
// Display a recessed one pixel border
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord borderEdgeWidth = nsPresContext::CSSPixelsToAppUnits(ALT_BORDER_WIDTH);
|
1999-09-16 21:37:37 +00:00
|
|
|
|
2002-03-26 20:14:05 +00:00
|
|
|
// if inner area is empty, then make it big enough for at least the icon
|
|
|
|
if (inner.IsEmpty()){
|
2007-02-07 07:46:44 +00: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 20:14:05 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 21:37:37 +00: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)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paint the border
|
2007-03-30 21:11:41 +00:00
|
|
|
nsRecessedBorder recessedBorder(borderEdgeWidth, PresContext());
|
2010-04-03 01:58:26 +00:00
|
|
|
nsCSSRendering::PaintBorderWithStyleBorder(PresContext(), aRenderingContext,
|
|
|
|
this, inner, inner,
|
|
|
|
recessedBorder, mStyleContext);
|
1998-09-22 03:34:44 +00:00
|
|
|
|
|
|
|
// Adjust the inner rect to account for the one pixel recessed border,
|
|
|
|
// and a six pixel padding on each edge
|
2007-02-07 07:46:44 +00:00
|
|
|
inner.Deflate(nsPresContext::CSSPixelsToAppUnits(ICON_PADDING+ALT_BORDER_WIDTH),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(ICON_PADDING+ALT_BORDER_WIDTH));
|
1998-09-22 03:34:44 +00:00
|
|
|
if (inner.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clip so we don't render outside the inner rect
|
|
|
|
aRenderingContext.PushState();
|
2011-04-08 01:04:40 +00:00
|
|
|
aRenderingContext.IntersectClip(inner);
|
1998-09-22 03:34:44 +00:00
|
|
|
|
2002-04-10 14:45:05 +00:00
|
|
|
// Check if we should display image placeholders
|
2009-08-12 14:23:38 +00:00
|
|
|
if (gIconLoad->mPrefShowPlaceholders) {
|
2006-07-31 07:08:45 +00:00
|
|
|
const nsStyleVisibility* vis = GetStyleVisibility();
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord size = nsPresContext::CSSPixelsToAppUnits(ICON_SIZE);
|
1998-09-22 03:34:44 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool iconUsed = false;
|
1998-09-22 03:34:44 +00:00
|
|
|
|
2009-08-12 14:23:38 +00: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.
|
2009-08-30 21:06:11 +00:00
|
|
|
if (aRequest && !mDisplayingIcon) {
|
2009-08-12 14:23:38 +00:00
|
|
|
gIconLoad->AddIconObserver(this);
|
2011-10-17 14:59:28 +00:00
|
|
|
mDisplayingIcon = true;
|
2009-08-12 14:23:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the image in question is loaded and decoded, draw it
|
2009-08-30 21:06:11 +00:00
|
|
|
PRUint32 imageStatus = 0;
|
|
|
|
if (aRequest)
|
|
|
|
aRequest->GetImageStatus(&imageStatus);
|
2009-08-12 14:23:38 +00:00
|
|
|
if (imageStatus & imgIRequest::STATUS_FRAME_COMPLETE) {
|
2002-04-10 14:45:05 +00:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
2009-08-12 14:23:38 +00:00
|
|
|
aRequest->GetImage(getter_AddRefs(imgCon));
|
|
|
|
NS_ABORT_IF_FALSE(imgCon, "Frame Complete, but no image container?");
|
|
|
|
nsRect dest((vis->mDirection == NS_STYLE_DIRECTION_RTL) ?
|
|
|
|
inner.XMost() - size : inner.x,
|
|
|
|
inner.y, size, size);
|
|
|
|
nsLayoutUtils::DrawSingleImage(&aRenderingContext, imgCon,
|
2009-09-12 22:44:18 +00:00
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this), dest, aDirtyRect,
|
|
|
|
imgIContainer::FLAG_NONE);
|
2011-10-17 14:59:28 +00:00
|
|
|
iconUsed = true;
|
2001-11-07 05:02:42 +00:00
|
|
|
}
|
1998-09-22 03:34:44 +00:00
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
// if we could not draw the icon, flag that we're waiting for it and
|
|
|
|
// just draw some graffiti in the mean time
|
2002-04-10 14:45:05 +00:00
|
|
|
if (!iconUsed) {
|
2006-07-31 07:08:45 +00:00
|
|
|
nscoord iconXPos = (vis->mDirection == NS_STYLE_DIRECTION_RTL) ?
|
|
|
|
inner.XMost() - size : inner.x;
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord twoPX = nsPresContext::CSSPixelsToAppUnits(2);
|
2006-07-31 07:08:45 +00:00
|
|
|
aRenderingContext.DrawRect(iconXPos, inner.y,size,size);
|
2011-04-08 01:04:40 +00:00
|
|
|
aRenderingContext.PushState();
|
2004-02-03 20:30:02 +00:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0xFF,0,0));
|
2007-02-07 07:46:44 +00:00
|
|
|
aRenderingContext.FillEllipse(size/2 + iconXPos, size/2 + inner.y,
|
|
|
|
size/2 - twoPX, size/2 - twoPX);
|
2011-04-08 01:04:40 +00:00
|
|
|
aRenderingContext.PopState();
|
|
|
|
}
|
2001-11-07 05:02:42 +00:00
|
|
|
|
2002-04-10 14:45:05 +00:00
|
|
|
// Reduce the inner rect by the width of the icon, and leave an
|
|
|
|
// additional ICON_PADDING pixels for padding
|
2007-02-07 07:46:44 +00:00
|
|
|
PRInt32 iconWidth = nsPresContext::CSSPixelsToAppUnits(ICON_SIZE + ICON_PADDING);
|
2006-07-31 07:08:45 +00:00
|
|
|
if (vis->mDirection != NS_STYLE_DIRECTION_RTL)
|
|
|
|
inner.x += iconWidth;
|
2002-04-10 14:45:05 +00:00
|
|
|
inner.width -= iconWidth;
|
|
|
|
}
|
1998-09-22 03:34:44 +00:00
|
|
|
|
|
|
|
// If there's still room, display the alt-text
|
|
|
|
if (!inner.IsEmpty()) {
|
2003-06-29 03:43:05 +00:00
|
|
|
nsIContent* content = GetContent();
|
2001-11-07 05:02:42 +00:00
|
|
|
if (content) {
|
2005-01-18 23:46:59 +00:00
|
|
|
nsXPIDLString altText;
|
2003-11-19 01:20:56 +00:00
|
|
|
nsCSSFrameConstructor::GetAlternateTextFor(content, content->Tag(),
|
|
|
|
altText);
|
2007-03-30 21:11:41 +00:00
|
|
|
DisplayAltText(PresContext(), aRenderingContext, altText, inner);
|
1998-09-22 03:34:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-18 13:13:35 +00:00
|
|
|
aRenderingContext.PopState();
|
1998-09-22 03:34:44 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 01:04:40 +00:00
|
|
|
static void PaintAltFeedback(nsIFrame* aFrame, nsRenderingContext* aCtx,
|
2006-01-26 02:29:17 +00:00
|
|
|
const nsRect& aDirtyRect, nsPoint aPt)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsImageFrame* f = static_cast<nsImageFrame*>(aFrame);
|
2011-06-01 01:46:57 +00:00
|
|
|
nsEventStates state = f->GetContent()->AsElement()->State();
|
2006-01-26 02:29:17 +00:00
|
|
|
f->DisplayAltFeedback(*aCtx,
|
2007-03-20 00:58:20 +00:00
|
|
|
aDirtyRect,
|
2011-10-17 14:59:28 +00:00
|
|
|
IMAGE_OK(state, true)
|
2006-01-26 02:29:17 +00:00
|
|
|
? nsImageFrame::gIconLoad->mLoadingImage
|
|
|
|
: nsImageFrame::gIconLoad->mBrokenImage,
|
|
|
|
aPt);
|
|
|
|
}
|
2005-11-02 00:04:29 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
#ifdef NS_DEBUG
|
2011-04-08 01:04:40 +00:00
|
|
|
static void PaintDebugImageMap(nsIFrame* aFrame, nsRenderingContext* aCtx,
|
2006-01-26 02:29:17 +00:00
|
|
|
const nsRect& aDirtyRect, nsPoint aPt) {
|
2007-07-08 07:08:04 +00:00
|
|
|
nsImageFrame* f = static_cast<nsImageFrame*>(aFrame);
|
2006-01-26 02:29:17 +00:00
|
|
|
nsRect inner = f->GetInnerArea() + aPt;
|
|
|
|
|
|
|
|
aCtx->SetColor(NS_RGB(0, 0, 0));
|
|
|
|
aCtx->PushState();
|
2011-04-08 01:04:39 +00:00
|
|
|
aCtx->Translate(inner.TopLeft());
|
2011-09-26 20:55:04 +00:00
|
|
|
f->GetImageMap()->Draw(aFrame, *aCtx);
|
2006-01-26 02:29:17 +00:00
|
|
|
aCtx->PopState();
|
|
|
|
}
|
|
|
|
#endif
|
2001-10-06 05:08:16 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
void
|
|
|
|
nsDisplayImage::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 01:04:40 +00:00
|
|
|
nsRenderingContext* aCtx) {
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsImageFrame*>(mFrame)->
|
2010-08-13 10:01:58 +00:00
|
|
|
PaintImage(*aCtx, ToReferenceFrame(), mVisibleRect, mImage,
|
2009-09-12 22:44:18 +00:00
|
|
|
aBuilder->ShouldSyncDecodeImages()
|
|
|
|
? (PRUint32) imgIContainer::FLAG_SYNC_DECODE
|
|
|
|
: (PRUint32) imgIContainer::FLAG_NONE);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2002-03-26 20:14:05 +00:00
|
|
|
|
2011-01-17 21:47:18 +00:00
|
|
|
nsCOMPtr<imgIContainer>
|
|
|
|
nsDisplayImage::GetImage()
|
|
|
|
{
|
|
|
|
return mImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<ImageContainer>
|
|
|
|
nsDisplayImage::GetContainer(LayerManager* aManager)
|
|
|
|
{
|
2011-11-09 03:14:41 +00:00
|
|
|
ImageContainer* container;
|
|
|
|
nsresult rv = mImage->GetImageContainer(aManager, &container);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NULL);
|
|
|
|
return container;
|
2011-01-17 21:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayImage::ConfigureLayer(ImageLayer* aLayer)
|
|
|
|
{
|
|
|
|
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
|
|
|
|
|
2011-11-08 03:57:55 +00:00
|
|
|
PRInt32 factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2011-01-17 21:47:18 +00:00
|
|
|
nsImageFrame* imageFrame = static_cast<nsImageFrame*>(mFrame);
|
|
|
|
|
|
|
|
nsRect dest = imageFrame->GetInnerArea() + ToReferenceFrame();
|
|
|
|
gfxRect destRect(dest.x, dest.y, dest.width, dest.height);
|
|
|
|
destRect.ScaleInverse(factor);
|
|
|
|
|
|
|
|
PRInt32 imageWidth;
|
|
|
|
PRInt32 imageHeight;
|
|
|
|
mImage->GetWidth(&imageWidth);
|
|
|
|
mImage->GetHeight(&imageHeight);
|
|
|
|
|
|
|
|
gfxMatrix transform;
|
2011-04-19 03:07:21 +00:00
|
|
|
transform.Translate(destRect.TopLeft());
|
|
|
|
transform.Scale(destRect.Width()/imageWidth,
|
|
|
|
destRect.Height()/imageHeight);
|
2011-01-17 21:47:18 +00:00
|
|
|
aLayer->SetTransform(gfx3DMatrix::From2D(transform));
|
|
|
|
|
|
|
|
aLayer->SetVisibleRegion(nsIntRect(0, 0, imageWidth, imageHeight));
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
void
|
2011-04-08 01:04:40 +00:00
|
|
|
nsImageFrame::PaintImage(nsRenderingContext& aRenderingContext, nsPoint aPt,
|
2009-09-12 22:44:18 +00:00
|
|
|
const nsRect& aDirtyRect, imgIContainer* aImage,
|
|
|
|
PRUint32 aFlags)
|
2006-01-26 02:29:17 +00:00
|
|
|
{
|
|
|
|
// Render the image into our content area (the area inside
|
|
|
|
// the borders and padding)
|
2007-03-20 00:58:20 +00:00
|
|
|
NS_ASSERTION(GetInnerArea().width == mComputedSize.width, "bad width");
|
2006-01-26 02:29:17 +00:00
|
|
|
nsRect inner = GetInnerArea() + aPt;
|
2007-03-20 00:58:20 +00:00
|
|
|
nsRect dest(inner.TopLeft(), mComputedSize);
|
|
|
|
dest.y -= GetContinuationOffset();
|
2001-03-22 01:38:35 +00:00
|
|
|
|
2009-04-05 09:52:14 +00:00
|
|
|
nsLayoutUtils::DrawSingleImage(&aRenderingContext, aImage,
|
2009-09-12 22:44:18 +00:00
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this), dest, aDirtyRect,
|
|
|
|
aFlags);
|
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-08 21:31:05 +00:00
|
|
|
|
2011-09-26 20:55:04 +00:00
|
|
|
nsImageMap* map = GetImageMap();
|
2006-01-26 02:29:17 +00:00
|
|
|
if (nsnull != map) {
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
|
|
|
aRenderingContext.SetLineStyle(nsLineStyle_kDotted);
|
2011-04-08 01:04:39 +00:00
|
|
|
aRenderingContext.Translate(inner.TopLeft());
|
2008-08-07 14:44:04 +00:00
|
|
|
map->Draw(this, aRenderingContext);
|
2006-01-26 02:29:17 +00:00
|
|
|
aRenderingContext.PopState();
|
|
|
|
}
|
|
|
|
}
|
2003-11-06 16:03:34 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// REVIEW: We don't need any special logic here for deciding which layer
|
|
|
|
// to put the background in ... it goes in aLists.BorderBackground() and
|
|
|
|
// then if we have a block parent, it will put our background in the right
|
|
|
|
// place.
|
|
|
|
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// REVIEW: Checking mRect.IsEmpty() makes no sense to me, so I removed it.
|
|
|
|
// It can't have been protecting us against bad situations with zero-size
|
|
|
|
// images since adding a border would make the rect non-empty.
|
2010-09-09 15:21:47 +00:00
|
|
|
|
|
|
|
nsDisplayList replacedContent;
|
2006-01-26 02:29:17 +00: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));
|
|
|
|
}
|
|
|
|
|
2011-06-01 01:46:57 +00:00
|
|
|
nsEventStates contentState = mContent->AsElement()->State();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool imageOK = IMAGE_OK(contentState, true);
|
2006-01-26 02:29:17 +00:00
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
|
|
|
if (currentRequest) {
|
|
|
|
currentRequest->GetImage(getter_AddRefs(imgCon));
|
|
|
|
}
|
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
// Determine if the size is available
|
2011-09-29 06:19:26 +00:00
|
|
|
bool haveSize = false;
|
2009-08-12 14:23:38 +00:00
|
|
|
PRUint32 imageStatus = 0;
|
|
|
|
if (currentRequest)
|
|
|
|
currentRequest->GetImageStatus(&imageStatus);
|
|
|
|
if (imageStatus & imgIRequest::STATUS_SIZE_AVAILABLE)
|
2011-10-17 14:59:28 +00:00
|
|
|
haveSize = true;
|
2009-08-12 14:23:38 +00:00
|
|
|
|
|
|
|
// We should never have the size and not have an image container
|
|
|
|
NS_ABORT_IF_FALSE(!haveSize || imgCon, "Have size but not container?");
|
|
|
|
|
|
|
|
if (!imageOK || !haveSize) {
|
2006-01-26 02:29:17 +00:00
|
|
|
// No image yet, or image load failed. Draw the alt-text and an icon
|
|
|
|
// indicating the status
|
2010-09-09 15:21:47 +00:00
|
|
|
rv = replacedContent.AppendNewToTop(new (aBuilder)
|
2010-08-13 10:01:13 +00:00
|
|
|
nsDisplayGeneric(aBuilder, this, PaintAltFeedback, "AltFeedback",
|
2010-07-15 21:07:49 +00:00
|
|
|
nsDisplayItem::TYPE_ALT_FEEDBACK));
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
2010-09-09 15:21:47 +00:00
|
|
|
rv = replacedContent.AppendNewToTop(new (aBuilder)
|
2010-08-13 10:01:13 +00:00
|
|
|
nsDisplayImage(aBuilder, this, imgCon));
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-08-12 14:23:38 +00:00
|
|
|
|
|
|
|
// If we were previously displaying an icon, we're not anymore
|
|
|
|
if (mDisplayingIcon) {
|
|
|
|
gIconLoad->RemoveIconObserver(this);
|
2011-10-17 14:59:28 +00:00
|
|
|
mDisplayingIcon = false;
|
2009-08-12 14:23:38 +00:00
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2003-11-06 16:03:34 +00:00
|
|
|
#ifdef DEBUG
|
2011-09-26 20:55:04 +00:00
|
|
|
if (GetShowFrameBorders() && GetImageMap()) {
|
2006-01-26 02:29:17 +00:00
|
|
|
rv = aLists.Outlines()->AppendNewToTop(new (aBuilder)
|
2010-08-13 10:01:13 +00:00
|
|
|
nsDisplayGeneric(aBuilder, this, PaintDebugImageMap, "DebugImageMap",
|
2010-07-15 21:07:49 +00:00
|
|
|
nsDisplayItem::TYPE_DEBUG_IMAGE_MAP));
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-11-06 16:03:34 +00:00
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
#endif
|
1999-04-10 17:32:33 +00:00
|
|
|
}
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
2001-12-18 01:29:49 +00:00
|
|
|
|
2010-10-07 04:25:47 +00:00
|
|
|
if (ShouldDisplaySelection()) {
|
|
|
|
rv = DisplaySelectionOverlay(aBuilder, &replacedContent,
|
|
|
|
nsISelectionDisplay::DISPLAY_IMAGES);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
WrapReplacedContentForBorderRadius(aBuilder, &replacedContent, aLists);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsImageFrame::ShouldDisplaySelection()
|
|
|
|
{
|
2006-01-26 02:29:17 +00:00
|
|
|
// XXX what on EARTH is this code for?
|
|
|
|
nsresult result;
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
2010-03-20 21:54:19 +00:00
|
|
|
PRInt16 displaySelection = presContext->PresShell()->GetSelectionFlags();
|
2001-12-18 01:29:49 +00:00
|
|
|
if (!(displaySelection & nsISelectionDisplay::DISPLAY_IMAGES))
|
2010-10-07 04:25:47 +00:00
|
|
|
return false;//no need to check the blue border, we cannot be drawn selected
|
2003-04-22 23:18:34 +00: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
|
|
|
|
if (displaySelection == nsISelectionDisplay::DISPLAY_ALL)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
2006-01-26 02:29:17 +00:00
|
|
|
result = GetSelectionController(presContext, getter_AddRefs(selCon));
|
2003-04-22 23:18:34 +00:00
|
|
|
if (NS_SUCCEEDED(result) && selCon)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelection> selection;
|
|
|
|
result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection));
|
|
|
|
if (NS_SUCCEEDED(result) && selection)
|
|
|
|
{
|
|
|
|
PRInt32 rangeCount;
|
|
|
|
selection->GetRangeCount(&rangeCount);
|
|
|
|
if (rangeCount == 1) //if not one then let code drop to nsFrame::Paint
|
|
|
|
{
|
2003-07-28 21:25:13 +00:00
|
|
|
nsCOMPtr<nsIContent> parentContent = mContent->GetParent();
|
2003-04-22 23:18:34 +00:00
|
|
|
if (parentContent)
|
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
PRInt32 thisOffset = parentContent->IndexOf(mContent);
|
2003-04-22 23:18:34 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> parentNode = do_QueryInterface(parentContent);
|
|
|
|
nsCOMPtr<nsIDOMNode> rangeNode;
|
|
|
|
PRInt32 rangeOffset;
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
selection->GetRangeAt(0,getter_AddRefs(range));
|
|
|
|
if (range)
|
|
|
|
{
|
|
|
|
range->GetStartContainer(getter_AddRefs(rangeNode));
|
|
|
|
range->GetStartOffset(&rangeOffset);
|
|
|
|
|
|
|
|
if (parentNode && rangeNode && (rangeNode == parentNode) && rangeOffset == thisOffset)
|
|
|
|
{
|
|
|
|
range->GetEndContainer(getter_AddRefs(rangeNode));
|
|
|
|
range->GetEndOffset(&rangeOffset);
|
|
|
|
if ((rangeNode == parentNode) && (rangeOffset == (thisOffset +1))) //+1 since that would mean this whole content is selected only
|
2010-10-07 04:25:47 +00:00
|
|
|
return false; //do not allow nsFrame do draw any further selection
|
2003-04-22 23:18:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-10-07 04:25:47 +00:00
|
|
|
return true;
|
2002-08-17 01:46:58 +00:00
|
|
|
}
|
|
|
|
|
1999-01-09 00:13:19 +00:00
|
|
|
nsImageMap*
|
2011-09-26 20:55:04 +00:00
|
|
|
nsImageFrame::GetImageMap()
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2001-04-18 00:14:34 +00:00
|
|
|
if (!mImageMap) {
|
2003-07-28 21:25:13 +00:00
|
|
|
nsIDocument* doc = mContent->GetDocument();
|
2001-04-18 00:14:34 +00:00
|
|
|
if (!doc) {
|
1998-09-08 22:34:40 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2001-04-18 00:14:34 +00:00
|
|
|
nsAutoString usemap;
|
2006-12-26 17:47:52 +00:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usemap, usemap);
|
1999-08-19 22:22:02 +00:00
|
|
|
|
2011-05-30 11:35:45 +00:00
|
|
|
nsCOMPtr<nsIContent> map = doc->FindImageMap(usemap);
|
2004-02-19 18:56:13 +00:00
|
|
|
if (map) {
|
2001-04-18 00:14:34 +00:00
|
|
|
mImageMap = new nsImageMap();
|
2011-05-30 11:00:00 +00:00
|
|
|
NS_ADDREF(mImageMap);
|
2011-09-26 20:55:04 +00:00
|
|
|
mImageMap->Init(this, map);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
1999-01-09 00:13:19 +00:00
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
return mImageMap;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
1998-11-20 17:21:02 +00:00
|
|
|
nsImageFrame::IsServerImageMap()
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::ismap);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
2005-08-23 03:57:07 +00:00
|
|
|
// Translate an point that is relative to our frame
|
|
|
|
// into a localized pixel coordinate that is relative to the
|
1999-07-08 19:38:08 +00:00
|
|
|
// content area of this frame (inside the border+padding).
|
|
|
|
void
|
2004-12-26 19:48:54 +00:00
|
|
|
nsImageFrame::TranslateEventCoords(const nsPoint& aPoint,
|
2007-02-18 16:49:54 +00:00
|
|
|
nsIntPoint& aResult)
|
1999-07-08 19:38:08 +00: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 19:48:54 +00:00
|
|
|
nsRect inner = GetInnerArea();
|
1999-07-08 19:38:08 +00:00
|
|
|
x -= inner.x;
|
|
|
|
y -= inner.y;
|
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
aResult.x = nsPresContext::AppUnitsToIntCSSPixels(x);
|
|
|
|
aResult.y = nsPresContext::AppUnitsToIntCSSPixels(y);
|
1999-07-08 19:38:08 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2006-02-02 20:02:34 +00:00
|
|
|
nsImageFrame::GetAnchorHREFTargetAndNode(nsIURI** aHref, nsString& aTarget,
|
2007-07-11 13:05:05 +00:00
|
|
|
nsIContent** aNode)
|
1999-07-08 19:38:08 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool status = false;
|
2001-04-11 08:12:10 +00:00
|
|
|
aTarget.Truncate();
|
2006-02-02 20:02:34 +00:00
|
|
|
*aHref = nsnull;
|
|
|
|
*aNode = nsnull;
|
1999-07-08 19:38:08 +00:00
|
|
|
|
|
|
|
// Walk up the content tree, looking for an nsIDOMAnchorElement
|
2003-07-28 21:25:13 +00:00
|
|
|
for (nsIContent* content = mContent->GetParent();
|
|
|
|
content; content = content->GetParent()) {
|
2004-02-10 16:57:00 +00:00
|
|
|
nsCOMPtr<nsILink> link(do_QueryInterface(content));
|
|
|
|
if (link) {
|
2009-09-23 15:11:48 +00:00
|
|
|
nsCOMPtr<nsIURI> href = content->GetHrefURI();
|
|
|
|
if (href) {
|
|
|
|
href->Clone(aHref);
|
|
|
|
}
|
2004-02-10 16:57:00 +00:00
|
|
|
status = (*aHref != nsnull);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(content));
|
|
|
|
if (anchor) {
|
|
|
|
anchor->GetTarget(aTarget);
|
1999-07-08 19:44:42 +00:00
|
|
|
}
|
2006-02-02 20:02:34 +00:00
|
|
|
NS_ADDREF(*aNode = content);
|
1999-07-08 19:38:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-07-08 19:44:42 +00:00
|
|
|
return status;
|
1999-07-08 19:38:08 +00:00
|
|
|
}
|
|
|
|
|
2000-02-11 01:24:59 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-26 20:55:04 +00:00
|
|
|
nsImageFrame::GetContentForEvent(nsEvent* aEvent,
|
2000-02-11 01:24:59 +00:00
|
|
|
nsIContent** aContent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aContent);
|
2009-09-02 02:46:33 +00:00
|
|
|
|
|
|
|
nsIFrame* f = nsLayoutUtils::GetNonGeneratedAncestor(this);
|
|
|
|
if (f != this) {
|
2011-09-26 20:55:04 +00:00
|
|
|
return f->GetContentForEvent(aEvent, aContent);
|
2009-09-02 02:46:33 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 02:07:19 +00: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 =
|
|
|
|
NS_IS_MOUSE_EVENT(aEvent) ? nsIPresShell::GetCapturingContent() : nsnull;
|
|
|
|
if (capturingContent && capturingContent->GetPrimaryFrame() == this) {
|
|
|
|
*aContent = capturingContent;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-26 20:55:04 +00:00
|
|
|
nsImageMap* map = GetImageMap();
|
2000-02-11 01:24:59 +00:00
|
|
|
|
|
|
|
if (nsnull != map) {
|
2007-02-18 16:49:54 +00:00
|
|
|
nsIntPoint p;
|
2005-08-23 03:57:07 +00:00
|
|
|
TranslateEventCoords(
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
|
2011-10-30 19:51:19 +00:00
|
|
|
nsCOMPtr<nsIContent> area = map->GetArea(p.x, p.y);
|
|
|
|
if (area) {
|
2011-11-17 18:01:24 +00:00
|
|
|
area.forget(aContent);
|
2000-02-11 01:24:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-29 03:43:05 +00:00
|
|
|
*aContent = GetContent();
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
2000-02-11 01:24:59 +00:00
|
|
|
}
|
|
|
|
|
1998-09-08 22:34:40 +00:00
|
|
|
// XXX what should clicks on transparent pixels do?
|
2006-04-20 21:02:10 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsImageFrame::HandleEvent(nsPresContext* aPresContext,
|
1998-11-20 17:21:02 +00:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
1998-09-08 22:34:40 +00:00
|
|
|
|
2008-09-15 15:40:25 +00:00
|
|
|
if ((aEvent->eventStructType == NS_MOUSE_EVENT &&
|
|
|
|
aEvent->message == NS_MOUSE_BUTTON_UP &&
|
|
|
|
static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) ||
|
2006-11-16 21:35:39 +00:00
|
|
|
aEvent->message == NS_MOUSE_MOVE) {
|
2011-09-26 20:55:04 +00:00
|
|
|
nsImageMap* map = GetImageMap();
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isServerMap = IsServerImageMap();
|
2006-11-16 21:35:39 +00:00
|
|
|
if ((nsnull != map) || isServerMap) {
|
2007-02-18 16:49:54 +00:00
|
|
|
nsIntPoint p;
|
2006-11-16 21:35:39 +00:00
|
|
|
TranslateEventCoords(
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool inside = false;
|
2006-11-16 21:35:39 +00: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!)
|
|
|
|
if (nsnull != map) {
|
2011-10-30 19:51:19 +00:00
|
|
|
inside = !!map->GetArea(p.x, p.y);
|
2006-11-16 21:35:39 +00:00
|
|
|
}
|
2001-05-23 07:00:37 +00:00
|
|
|
|
2006-11-16 21:35:39 +00: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 13:05:05 +00:00
|
|
|
nsCOMPtr<nsIContent> anchorNode;
|
2006-11-16 21:35:39 +00: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;
|
|
|
|
nsCAutoString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
spec += nsPrintfCString("?%d,%d", p.x, p.y);
|
|
|
|
uri->SetSpec(spec);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool clicked = false;
|
2006-11-16 21:35:39 +00:00
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
2011-10-17 14:59:28 +00:00
|
|
|
clicked = true;
|
1999-07-08 19:44:42 +00:00
|
|
|
}
|
2007-07-11 13:05:05 +00:00
|
|
|
nsContentUtils::TriggerLink(anchorNode, aPresContext, uri, target,
|
2011-10-17 14:59:28 +00:00
|
|
|
clicked, true, true);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-04-12 21:24:07 +00:00
|
|
|
|
2001-11-01 15:31:13 +00:00
|
|
|
return nsSplittableFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
2006-04-20 21:02:10 +00:00
|
|
|
NS_IMETHODIMP
|
2004-12-30 21:56:11 +00:00
|
|
|
nsImageFrame::GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2011-09-26 20:55:04 +00:00
|
|
|
nsImageMap* map = GetImageMap();
|
1998-11-18 05:25:26 +00:00
|
|
|
if (nsnull != map) {
|
2007-02-18 16:49:54 +00:00
|
|
|
nsIntPoint p;
|
2004-12-26 19:48:54 +00:00
|
|
|
TranslateEventCoords(aPoint, p);
|
2011-10-30 19:51:19 +00:00
|
|
|
nsCOMPtr<nsIContent> area = map->GetArea(p.x, p.y);
|
|
|
|
if (area) {
|
2006-04-20 21:02:10 +00: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.
|
|
|
|
nsRefPtr<nsStyleContext> areaStyle =
|
2007-03-30 21:11:41 +00:00
|
|
|
PresContext()->PresShell()->StyleSet()->
|
2010-04-30 13:12:06 +00:00
|
|
|
ResolveStyleFor(area->AsElement(), GetStyleContext());
|
2006-04-20 21:02:10 +00:00
|
|
|
if (areaStyle) {
|
|
|
|
FillCursorInformationFromStyle(areaStyle->GetStyleUserInterface(),
|
|
|
|
aCursor);
|
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
|
|
|
|
aCursor.mCursor = NS_STYLE_CURSOR_DEFAULT;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-11-23 22:21:13 +00:00
|
|
|
}
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-30 21:56:11 +00:00
|
|
|
return nsFrame::GetCursor(aPoint, aCursor);
|
1998-09-08 22:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-09-07 16:49:21 +00:00
|
|
|
nsImageFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
1998-11-20 17:21:02 +00:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-11 21:16:12 +00:00
|
|
|
PRInt32 aModType)
|
1998-09-08 22:34:40 +00:00
|
|
|
{
|
2005-09-07 16:49:21 +00:00
|
|
|
nsresult rv = nsSplittableFrame::AttributeChanged(aNameSpaceID,
|
2004-12-31 01:13:27 +00:00
|
|
|
aAttribute, aModType);
|
2004-09-30 19:23:40 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-09-28 21:22:31 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
if (nsGkAtoms::alt == aAttribute)
|
2004-09-30 19:23:40 +00:00
|
|
|
{
|
2007-05-06 19:16:51 +00:00
|
|
|
PresContext()->PresShell()->FrameNeedsReflow(this,
|
|
|
|
nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2000-04-17 14:40:46 +00:00
|
|
|
}
|
1998-09-08 22:34:40 +00:00
|
|
|
|
1998-09-25 16:35:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-31 03:09:40 +00:00
|
|
|
|
2003-10-31 20:19:18 +00:00
|
|
|
nsIAtom*
|
|
|
|
nsImageFrame::GetType() const
|
1999-08-31 03:09:40 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::imageFrame;
|
1999-08-31 03:09:40 +00:00
|
|
|
}
|
|
|
|
|
2001-10-31 04:43:48 +00:00
|
|
|
#ifdef DEBUG
|
2005-05-09 17:46:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ImageFrame"), aResult);
|
|
|
|
}
|
|
|
|
|
2001-10-31 04:43:48 +00:00
|
|
|
NS_IMETHODIMP
|
2005-09-06 21:34:50 +00:00
|
|
|
nsImageFrame::List(FILE* out, PRInt32 aIndent) const
|
2001-10-31 04:43:48 +00:00
|
|
|
{
|
|
|
|
IndentBy(out, aIndent);
|
|
|
|
ListTag(out);
|
|
|
|
#ifdef DEBUG_waterson
|
|
|
|
fprintf(out, " [parent=%p]", mParent);
|
|
|
|
#endif
|
2003-06-19 23:44:01 +00:00
|
|
|
if (HasView()) {
|
2006-01-26 02:29:17 +00:00
|
|
|
fprintf(out, " [view=%p]", (void*)GetView());
|
2001-10-31 04:43:48 +00:00
|
|
|
}
|
2010-06-25 21:51:17 +00:00
|
|
|
fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width, mRect.height);
|
2001-10-31 04:43:48 +00:00
|
|
|
if (0 != mState) {
|
2010-06-10 18:26:57 +00:00
|
|
|
fprintf(out, " [state=%016llx]", mState);
|
2001-10-31 04:43:48 +00:00
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
fprintf(out, " [content=%p]", (void*)mContent);
|
2010-06-25 21:51:17 +00:00
|
|
|
fprintf(out, " [sc=%p]", static_cast<void*>(mStyleContext));
|
2001-10-31 04:43:48 +00:00
|
|
|
|
|
|
|
// output the img src url
|
2003-03-19 03:47:09 +00: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));
|
|
|
|
nsCAutoString uristr;
|
|
|
|
uri->GetAsciiSpec(uristr);
|
|
|
|
fprintf(out, " [src=%s]", uristr.get());
|
|
|
|
}
|
2002-03-20 22:14:27 +00:00
|
|
|
}
|
2001-10-31 04:43:48 +00:00
|
|
|
fputs("\n", out);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-20 00:58:20 +00:00
|
|
|
PRIntn
|
|
|
|
nsImageFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
PRIntn skip = 0;
|
|
|
|
if (nsnull != GetPrevInFlow()) {
|
|
|
|
skip |= 1 << NS_SIDE_TOP;
|
|
|
|
}
|
|
|
|
if (nsnull != GetNextInFlow()) {
|
|
|
|
skip |= 1 << NS_SIDE_BOTTOM;
|
|
|
|
}
|
|
|
|
return skip;
|
|
|
|
}
|
|
|
|
|
2011-04-26 06:52:19 +00:00
|
|
|
nsresult
|
2000-01-04 03:06:13 +00:00
|
|
|
nsImageFrame::GetIntrinsicImageSize(nsSize& aSize)
|
|
|
|
{
|
2010-09-08 20:40:38 +00: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 03:06:13 +00:00
|
|
|
}
|
|
|
|
|
2001-10-07 18:02:13 +00:00
|
|
|
nsresult
|
2003-03-19 03:47:09 +00:00
|
|
|
nsImageFrame::LoadIcon(const nsAString& aSpec,
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext *aPresContext,
|
2003-03-19 03:47:09 +00:00
|
|
|
imgIRequest** aRequest)
|
2001-05-04 06:29:59 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2003-03-19 03:47:09 +00:00
|
|
|
NS_PRECONDITION(!aSpec.IsEmpty(), "What happened??");
|
2001-05-04 06:29:59 +00:00
|
|
|
|
2004-01-21 09:35:59 +00:00
|
|
|
if (!sIOService) {
|
2006-06-18 21:18:22 +00:00
|
|
|
rv = CallGetService(NS_IOSERVICE_CONTRACTID, &sIOService);
|
2004-01-21 09:35:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2001-06-05 20:22:52 +00:00
|
|
|
nsCOMPtr<nsIURI> realURI;
|
2004-01-21 09:35:59 +00:00
|
|
|
SpecToURI(aSpec, sIOService, getter_AddRefs(realURI));
|
2003-03-19 03:47:09 +00:00
|
|
|
|
2001-05-04 06:29:59 +00:00
|
|
|
nsCOMPtr<imgILoader> il(do_GetService("@mozilla.org/image/loader;1", &rv));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> loadGroup;
|
|
|
|
GetLoadGroup(aPresContext, getter_AddRefs(loadGroup));
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
// For icon loads, we don't need to merge with the loadgroup flags
|
2001-09-29 17:50:15 +00:00
|
|
|
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
return il->LoadImage(realURI, /* icon URI */
|
|
|
|
nsnull, /* initial document URI; this is only
|
|
|
|
relevant for cookies, so does not
|
|
|
|
apply to icons. */
|
|
|
|
nsnull, /* referrer (not relevant for icons) */
|
2011-07-14 18:47:32 +00:00
|
|
|
nsnull, /* principal (not relevant for icons) */
|
2003-03-19 03:47:09 +00:00
|
|
|
loadGroup,
|
2009-08-12 14:23:38 +00:00
|
|
|
gIconLoad,
|
2003-03-19 03:47:09 +00:00
|
|
|
nsnull, /* Not associated with any particular document */
|
|
|
|
loadFlags,
|
|
|
|
nsnull,
|
|
|
|
nsnull,
|
2010-05-20 20:08:02 +00:00
|
|
|
nsnull, /* channel policy not needed */
|
2003-03-19 03:47:09 +00:00
|
|
|
aRequest);
|
2001-05-04 06:29:59 +00:00
|
|
|
}
|
|
|
|
|
2002-03-12 22:26:11 +00:00
|
|
|
void
|
2003-06-17 16:40:34 +00:00
|
|
|
nsImageFrame::GetDocumentCharacterSet(nsACString& aCharset) const
|
2002-03-12 22:26:11 +00:00
|
|
|
{
|
2003-07-28 21:25:13 +00:00
|
|
|
if (mContent) {
|
|
|
|
NS_ASSERTION(mContent->GetDocument(),
|
|
|
|
"Frame still alive after content removed from document!");
|
2003-10-22 06:09:48 +00:00
|
|
|
aCharset = mContent->GetDocument()->GetDocumentCharacterSet();
|
2002-03-12 22:26:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-15 02:13:49 +00:00
|
|
|
void
|
2003-03-19 03:47:09 +00:00
|
|
|
nsImageFrame::SpecToURI(const nsAString& aSpec, nsIIOService *aIOService,
|
2002-11-06 12:58:05 +00:00
|
|
|
nsIURI **aURI)
|
2001-05-04 06:29:59 +00:00
|
|
|
{
|
2001-04-15 02:13:49 +00:00
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2003-07-03 02:45:34 +00:00
|
|
|
if (mContent) {
|
2004-01-09 23:54:21 +00:00
|
|
|
baseURI = mContent->GetBaseURI();
|
2003-07-03 02:45:34 +00:00
|
|
|
}
|
2003-06-17 16:40:34 +00:00
|
|
|
nsCAutoString charset;
|
2002-03-12 22:26:11 +00:00
|
|
|
GetDocumentCharacterSet(charset);
|
|
|
|
NS_NewURI(aURI, aSpec,
|
2003-06-17 16:40:34 +00:00
|
|
|
charset.IsEmpty() ? nsnull : charset.get(),
|
2002-11-06 12:58:05 +00:00
|
|
|
baseURI, aIOService);
|
2001-04-15 02:13:49 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 01:38:35 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsImageFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGroup)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
|
|
|
if (!aPresContext)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull != aLoadGroup, "null OUT parameter pointer");
|
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *shell = aPresContext->GetPresShell();
|
2001-03-22 01:38:35 +00:00
|
|
|
|
|
|
|
if (!shell)
|
|
|
|
return;
|
|
|
|
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = shell->GetDocument();
|
2001-03-22 01:38:35 +00:00
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
*aLoadGroup = doc->GetDocumentLoadGroup().get(); // already_AddRefed
|
2001-03-22 01:38:35 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
nsresult nsImageFrame::LoadIcons(nsPresContext *aPresContext)
|
2001-11-07 05:02:42 +00:00
|
|
|
{
|
2004-02-03 20:30:02 +00:00
|
|
|
NS_ASSERTION(!gIconLoad, "called LoadIcons twice");
|
|
|
|
|
2009-10-12 19:31:50 +00: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 05:02:42 +00:00
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
gIconLoad = new IconLoad();
|
2004-02-03 20:30:02 +00:00
|
|
|
NS_ADDREF(gIconLoad);
|
2001-11-07 05:02:42 +00:00
|
|
|
|
2003-03-19 03:47:09 +00:00
|
|
|
nsresult rv;
|
|
|
|
// create a loader and load the images
|
|
|
|
rv = LoadIcon(loadingSrc,
|
|
|
|
aPresContext,
|
2004-02-03 20:30:02 +00:00
|
|
|
getter_AddRefs(gIconLoad->mLoadingImage));
|
2003-03-19 03:47:09 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = LoadIcon(brokenSrc,
|
|
|
|
aPresContext,
|
2004-02-03 20:30:02 +00:00
|
|
|
getter_AddRefs(gIconLoad->mBrokenImage));
|
2001-11-07 05:02:42 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsImageFrame::IconLoad, nsIObserver,
|
|
|
|
imgIDecoderObserver)
|
2004-02-03 20:30:02 +00:00
|
|
|
|
2011-05-28 23:39:27 +00:00
|
|
|
static const char* kIconLoadPrefs[] = {
|
2004-02-03 20:30:02 +00:00
|
|
|
"browser.display.force_inline_alttext",
|
2011-05-28 23:39:27 +00:00
|
|
|
"browser.display.show_image_placeholders",
|
|
|
|
nsnull
|
2004-02-03 20:30:02 +00:00
|
|
|
};
|
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
nsImageFrame::IconLoad::IconLoad()
|
2004-02-03 20:30:02 +00:00
|
|
|
{
|
2011-05-28 23:39:27 +00:00
|
|
|
// register observers
|
2011-05-28 23:39:27 +00:00
|
|
|
Preferences::AddStrongObservers(this, kIconLoadPrefs);
|
2004-04-29 23:34:19 +00:00
|
|
|
GetPrefs();
|
2001-11-07 05:02:42 +00:00
|
|
|
}
|
|
|
|
|
2011-06-03 06:07:10 +00:00
|
|
|
void
|
|
|
|
nsImageFrame::IconLoad::Shutdown()
|
|
|
|
{
|
|
|
|
Preferences::RemoveObservers(this, kIconLoadPrefs);
|
|
|
|
// in case the pref service releases us later
|
|
|
|
if (mLoadingImage) {
|
|
|
|
mLoadingImage->CancelAndForgetObserver(NS_ERROR_FAILURE);
|
|
|
|
mLoadingImage = nsnull;
|
|
|
|
}
|
|
|
|
if (mBrokenImage) {
|
|
|
|
mBrokenImage->CancelAndForgetObserver(NS_ERROR_FAILURE);
|
|
|
|
mBrokenImage = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2004-02-03 20:30:02 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::Observe(nsISupports *aSubject, const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
2001-11-07 05:02:42 +00:00
|
|
|
{
|
2004-02-03 20:30:02 +00:00
|
|
|
NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
|
|
|
|
"wrong topic");
|
|
|
|
#ifdef DEBUG
|
|
|
|
// assert |aData| is one of our prefs.
|
2011-10-11 05:50:08 +00:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(kIconLoadPrefs) ||
|
2011-10-17 14:59:28 +00:00
|
|
|
(NS_NOTREACHED("wrong pref"), false); ++i)
|
2004-02-03 20:30:02 +00:00
|
|
|
if (NS_ConvertASCIItoUTF16(kIconLoadPrefs[i]) == nsDependentString(aData))
|
|
|
|
break;
|
|
|
|
#endif
|
2001-11-07 05:02:42 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
GetPrefs();
|
2004-02-03 20:30:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
void nsImageFrame::IconLoad::GetPrefs()
|
2004-02-03 20:30:02 +00:00
|
|
|
{
|
2004-04-29 23:34:19 +00:00
|
|
|
mPrefForceInlineAltText =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("browser.display.force_inline_alttext");
|
2004-04-29 23:34:19 +00:00
|
|
|
|
|
|
|
mPrefShowPlaceholders =
|
2011-09-29 06:19:26 +00:00
|
|
|
Preferences::GetBool("browser.display.show_image_placeholders", true);
|
2001-11-07 05:02:42 +00:00
|
|
|
}
|
2001-04-15 02:13:49 +00:00
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnStartRequest(imgIRequest *aRequest)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnStartDecode(imgIRequest *aRequest)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnStartContainer(imgIRequest *aRequest,
|
|
|
|
imgIContainer *aContainer)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnStartFrame(imgIRequest *aRequest,
|
|
|
|
PRUint32 aFrame)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnDataAvailable(imgIRequest *aRequest,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCurrentFrame,
|
2009-08-12 14:23:38 +00:00
|
|
|
const nsIntRect * aRect)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnStopFrame(imgIRequest *aRequest,
|
|
|
|
PRUint32 aFrame)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnStopContainer(imgIRequest *aRequest,
|
|
|
|
imgIContainer *aContainer)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnStopDecode(imgIRequest *aRequest,
|
|
|
|
nsresult status,
|
|
|
|
const PRUnichar *statusArg)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-09 21:39:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnImageIsAnimated(imgIRequest *aRequest)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnStopRequest(imgIRequest *aRequest,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIsLastPart)
|
2009-08-12 14:23:38 +00:00
|
|
|
{
|
|
|
|
nsTObserverArray<nsImageFrame*>::ForwardIterator iter(mIconObservers);
|
|
|
|
nsImageFrame *frame;
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
frame = iter.GetNext();
|
|
|
|
frame->Invalidate(frame->GetRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::OnDiscard(imgIRequest *aRequest)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-12 14:23:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::FrameChanged(imgIContainer *aContainer,
|
2010-08-14 04:09:48 +00:00
|
|
|
const nsIntRect *aDirtyRect)
|
2009-08-12 14:23:38 +00:00
|
|
|
{
|
|
|
|
nsTObserverArray<nsImageFrame*>::ForwardIterator iter(mIconObservers);
|
|
|
|
nsImageFrame *frame;
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
frame = iter.GetNext();
|
|
|
|
frame->Invalidate(frame->GetRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-03-22 01:38:35 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(nsImageListener, imgIDecoderObserver, imgIContainerObserver)
|
|
|
|
|
2001-04-15 02:13:49 +00:00
|
|
|
nsImageListener::nsImageListener(nsImageFrame *aFrame) :
|
|
|
|
mFrame(aFrame)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageListener::~nsImageListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-02-26 05:51:32 +00:00
|
|
|
NS_IMETHODIMP nsImageListener::OnStartContainer(imgIRequest *aRequest,
|
|
|
|
imgIContainer *aImage)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-02-26 05:51:32 +00:00
|
|
|
return mFrame->OnStartContainer(aRequest, aImage);
|
2001-03-22 01:38:35 +00:00
|
|
|
}
|
|
|
|
|
2003-02-26 05:51:32 +00:00
|
|
|
NS_IMETHODIMP nsImageListener::OnDataAvailable(imgIRequest *aRequest,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aCurrentFrame,
|
2009-01-15 03:27:09 +00:00
|
|
|
const nsIntRect *aRect)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
return mFrame->OnDataAvailable(aRequest, aCurrentFrame, aRect);
|
2001-03-22 01:38:35 +00:00
|
|
|
}
|
|
|
|
|
2003-02-26 05:51:32 +00:00
|
|
|
NS_IMETHODIMP nsImageListener::OnStopDecode(imgIRequest *aRequest,
|
|
|
|
nsresult status,
|
|
|
|
const PRUnichar *statusArg)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-02-26 05:51:32 +00:00
|
|
|
return mFrame->OnStopDecode(aRequest, status, statusArg);
|
2001-03-22 01:38:35 +00:00
|
|
|
}
|
|
|
|
|
2003-02-26 05:51:32 +00:00
|
|
|
NS_IMETHODIMP nsImageListener::FrameChanged(imgIContainer *aContainer,
|
2010-08-14 04:09:48 +00:00
|
|
|
const nsIntRect *aDirtyRect)
|
2001-03-22 01:38:35 +00:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
return mFrame->FrameChanged(aContainer, aDirtyRect);
|
2001-03-22 01:38:35 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2007-12-03 09:24:49 +00:00
|
|
|
IsInAutoWidthTableCellForQuirk(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
if (eCompatibility_NavQuirks != aFrame->PresContext()->CompatibilityMode())
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2007-12-03 09:24:49 +00:00
|
|
|
// Check if the parent of the closest nsBlockFrame has auto width.
|
|
|
|
nsBlockFrame *ancestor = nsLayoutUtils::FindNearestBlockAncestor(aFrame);
|
2009-10-29 21:17:56 +00:00
|
|
|
if (ancestor->GetStyleContext()->GetPseudo() == nsCSSAnonBoxes::cellContent) {
|
2007-12-03 09:24:49 +00:00
|
|
|
// Assume direct parent is a table cell frame.
|
|
|
|
nsFrame *grandAncestor = static_cast<nsFrame*>(ancestor->GetParent());
|
|
|
|
return grandAncestor &&
|
|
|
|
grandAncestor->GetStylePosition()->mWidth.GetUnit() == eStyleUnit_Auto;
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2007-12-03 09:24:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2011-04-08 01:04:40 +00:00
|
|
|
nsImageFrame::AddInlineMinWidth(nsRenderingContext *aRenderingContext,
|
2007-12-03 09:24:49 +00:00
|
|
|
nsIFrame::InlineMinWidthData *aData)
|
|
|
|
{
|
|
|
|
|
|
|
|
NS_ASSERTION(GetParent(), "Must have a parent if we get here!");
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool canBreak =
|
2007-12-03 09:24:49 +00:00
|
|
|
!CanContinueTextRun() &&
|
|
|
|
GetParent()->GetStyleText()->WhiteSpaceCanWrap() &&
|
|
|
|
!IsInAutoWidthTableCellForQuirk(this);
|
|
|
|
|
|
|
|
if (canBreak)
|
|
|
|
aData->OptionallyBreak(aRenderingContext);
|
|
|
|
|
|
|
|
aData->trailingWhitespace = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
aData->skipWhitespace = false;
|
2007-12-03 09:24:49 +00:00
|
|
|
aData->trailingTextFrame = nsnull;
|
|
|
|
aData->currentLine += nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
this, nsLayoutUtils::MIN_WIDTH);
|
2011-10-17 14:59:28 +00:00
|
|
|
aData->atStartOfLine = false;
|
2007-12-03 09:24:49 +00:00
|
|
|
|
|
|
|
if (canBreak)
|
|
|
|
aData->OptionallyBreak(aRenderingContext);
|
|
|
|
|
|
|
|
}
|