2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04: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-09 02:34:40 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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-09 02:34:40 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04: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-29 00:14:13 +04: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 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04: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 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsHTMLParts.h"
|
1999-07-08 23:38:08 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1999-04-14 01:51:20 +04:00
|
|
|
#include "nsImageFrame.h"
|
2003-03-19 06:47:09 +03:00
|
|
|
#include "nsIImageLoadingContent.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsString.h"
|
2002-11-20 03:44:26 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIDocument.h"
|
2002-11-20 03:44:26 +03:00
|
|
|
#include "nsINodeInfo.h"
|
2004-04-30 03:34:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsStyleConsts.h"
|
1999-01-09 03:13:19 +03:00
|
|
|
#include "nsImageMap.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 07:29:44 +04:00
|
|
|
#include "nsIURL.h"
|
2001-03-22 04:38:35 +03:00
|
|
|
#include "nsILoadGroup.h"
|
2005-02-21 23:58:01 +03:00
|
|
|
#include "nsISupportsPriority.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
1998-09-23 06:30:21 +04:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2004-02-10 19:57:00 +03:00
|
|
|
#include "nsILink.h"
|
1999-07-08 23:38:08 +04:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
1998-09-20 04:08:24 +04:00
|
|
|
#include "nsIDeviceContext.h"
|
1998-12-20 04:21:23 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-01-06 02:02:27 +03:00
|
|
|
#include "nsTextFragment.h"
|
1999-01-30 04:04:35 +03:00
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
1999-08-31 07:09:40 +04:00
|
|
|
#include "nsLayoutAtoms.h"
|
2001-04-18 04:14:34 +04:00
|
|
|
#include "nsImageMapUtils.h"
|
2000-08-09 00:35:12 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-04-01 05:01:33 +04:00
|
|
|
#include "nsIAccessibilityService.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-04-01 05:01:33 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIDOMNode.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsGUIEvent.h"
|
2005-08-23 07:57:07 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2001-04-01 05:01:33 +04:00
|
|
|
|
2001-05-04 10:29:59 +04:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "imgILoader.h"
|
|
|
|
|
2001-07-11 09:44:12 +04:00
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "plevent.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
#include "nsContentPolicyUtils.h"
|
2001-05-22 02:40:10 +04:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2001-07-11 09:44:12 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2001-11-07 08:02:42 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2005-02-25 23:46:35 +03:00
|
|
|
#include "nsIPrefBranch2.h"
|
2002-12-11 17:05:41 +03:00
|
|
|
#include "nsIPrefService.h"
|
2003-03-06 02:55:53 +03:00
|
|
|
#include "gfxIImageFrame.h"
|
2003-04-23 03:18:34 +04:00
|
|
|
#include "nsIDOMRange.h"
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
2005-03-02 07:05:12 +03:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsContentPolicyUtils.h"
|
2005-09-18 22:05:40 +04:00
|
|
|
#include "nsIEventStateManager.h"
|
2003-04-22 03:57:47 +04:00
|
|
|
#include "nsLayoutErrors.h"
|
|
|
|
|
1999-04-14 01:51:20 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#undef NOISY_IMAGE_LOADING
|
2001-11-07 08:02:42 +03:00
|
|
|
#undef NOISY_ICON_LOADING
|
1999-04-14 01:51:20 +04:00
|
|
|
#else
|
|
|
|
#undef NOISY_IMAGE_LOADING
|
2001-11-07 08:02:42 +03:00
|
|
|
#undef NOISY_ICON_LOADING
|
1998-11-14 00:31:50 +03:00
|
|
|
#endif
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2002-03-26 23:14:05 +03:00
|
|
|
// sizes (pixels) for image icon, padding and border frame
|
|
|
|
#define ICON_SIZE (16)
|
|
|
|
#define ICON_PADDING (3)
|
|
|
|
#define ALT_BORDER_WIDTH (1)
|
|
|
|
|
|
|
|
|
2003-04-23 03:18:34 +04:00
|
|
|
//we must add hooks soon
|
|
|
|
#define IMAGE_EDITOR_CHECK 1
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Default alignment value (so we can tell an unset value from a set value)
|
|
|
|
#define ALIGN_UNSET PRUint8(-1)
|
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
// static icon information
|
|
|
|
nsImageFrame::IconLoad* nsImageFrame::gIconLoad = nsnull;
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2004-01-21 12:35:59 +03:00
|
|
|
// cached IO service for loading icons
|
|
|
|
nsIIOService* nsImageFrame::sIOService;
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// test if the width and height are fixed, looking at the style data
|
2003-05-15 07:42:21 +04:00
|
|
|
static PRBool HaveFixedSize(const nsStylePosition* aStylePosition)
|
2001-11-07 08:02:42 +03:00
|
|
|
{
|
|
|
|
// check the width and height values in the reflow state's style struct
|
|
|
|
// - if width and height are specified as either coord or percentage, then
|
|
|
|
// the size of the image frame is constrained
|
2003-05-15 07:42:21 +04:00
|
|
|
nsStyleUnit widthUnit = aStylePosition->mWidth.GetUnit();
|
|
|
|
nsStyleUnit heightUnit = aStylePosition->mHeight.GetUnit();
|
2001-11-07 08:02:42 +03:00
|
|
|
|
|
|
|
return ((widthUnit == eStyleUnit_Coord ||
|
|
|
|
widthUnit == eStyleUnit_Percent) &&
|
|
|
|
(heightUnit == eStyleUnit_Coord ||
|
|
|
|
heightUnit == eStyleUnit_Percent));
|
|
|
|
}
|
2001-03-06 03:47:46 +03: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
|
2001-11-07 08:02:42 +03:00
|
|
|
inline PRBool HaveFixedSize(const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aReflowState.mStylePosition, "crappy reflowState - null stylePosition");
|
2002-11-07 05:50:39 +03:00
|
|
|
// when an image has percent css style height or width, but mComputedHeight
|
|
|
|
// or mComputedWidth of reflow state is NS_UNCONSTRAINEDSIZE
|
|
|
|
// it needs to return PR_FALSE to cause an incremental reflow later
|
|
|
|
// if an image is inside table like bug 156731 simple testcase III,
|
|
|
|
// during pass 1 reflow, mComputedWidth is NS_UNCONSTRAINEDSIZE
|
|
|
|
// in pass 2 reflow, mComputedWidth is 0, it also needs to return PR_FALSE
|
|
|
|
// see bug 156731
|
|
|
|
nsStyleUnit heightUnit = (*(aReflowState.mStylePosition)).mHeight.GetUnit();
|
|
|
|
nsStyleUnit widthUnit = (*(aReflowState.mStylePosition)).mWidth.GetUnit();
|
|
|
|
return ((eStyleUnit_Percent == heightUnit && NS_UNCONSTRAINEDSIZE == aReflowState.mComputedHeight) ||
|
|
|
|
(eStyleUnit_Percent == widthUnit && (NS_UNCONSTRAINEDSIZE == aReflowState.mComputedWidth ||
|
|
|
|
0 == aReflowState.mComputedWidth)))
|
|
|
|
? PR_FALSE
|
2003-05-15 07:42:21 +04:00
|
|
|
: HaveFixedSize(aReflowState.mStylePosition);
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
2001-03-06 03:47:46 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewImageFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
nsImageFrame* it = new (aPresShell) nsImageFrame;
|
1999-05-12 02:03:29 +04:00
|
|
|
if (nsnull == it) {
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = it;
|
1998-09-09 02:34:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2000-04-19 18:00:11 +04:00
|
|
|
nsImageFrame::nsImageFrame() :
|
2003-03-19 06:47:09 +03:00
|
|
|
mComputedSize(0, 0),
|
2004-02-03 23:30:02 +03:00
|
|
|
mIntrinsicSize(0, 0)
|
2000-04-19 18:00:11 +04:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
// We assume our size is not constrained and we haven't gotten an
|
|
|
|
// initial reflow yet, so don't touch those flags.
|
2000-04-19 18:00:11 +04:00
|
|
|
}
|
|
|
|
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::~nsImageFrame()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
|
|
|
*aInstancePtr = nsnull;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIFrameDebug))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIFrameDebug*,this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIImageFrame))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this);
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIFrame))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIFrame*,this);
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
|
|
|
*aInstancePtr = NS_STATIC_CAST(nsIImageFrame*,this);
|
|
|
|
return NS_OK;
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
2001-04-01 05:01:33 +04:00
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-18 03:52:32 +04:00
|
|
|
NS_IMETHODIMP nsImageFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
|
|
|
return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
2001-02-20 00:50:04 +03:00
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsImageFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported for frames");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsrefcnt) nsImageFrame::Release(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported for frames");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::Destroy(nsPresContext* aPresContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2000-08-12 04:38:22 +04:00
|
|
|
// Tell our image map, if there is one, to clean up
|
|
|
|
// This causes the nsImageMap to unregister itself as
|
|
|
|
// a DOM listener.
|
2003-03-19 06:47:09 +03:00
|
|
|
if (mImageMap) {
|
2001-05-04 10:29:59 +04:00
|
|
|
mImageMap->Destroy();
|
|
|
|
NS_RELEASE(mImageMap);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
// set the frame to null so we don't send messages to a dead object.
|
2003-03-19 06:47:09 +03:00
|
|
|
if (mListener) {
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->RemoveObserver(mListener);
|
|
|
|
}
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
NS_REINTERPRET_CAST(nsImageListener*, mListener.get())->SetFrame(nsnull);
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
mListener = nsnull;
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
return nsSplittableFrame::Destroy(aPresContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::Init(nsPresContext* aPresContext,
|
1998-12-29 06:38:16 +03:00
|
|
|
nsIContent* aContent,
|
1999-01-14 08:16:23 +03:00
|
|
|
nsIFrame* aParent,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aContext,
|
1999-02-25 06:27:57 +03:00
|
|
|
nsIFrame* aPrevInFlow)
|
1998-12-29 06:38:16 +03:00
|
|
|
{
|
2001-11-01 18:31:13 +03:00
|
|
|
nsresult rv = nsSplittableFrame::Init(aPresContext, aContent, aParent,
|
|
|
|
aContext, aPrevInFlow);
|
2003-03-19 06:47:09 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-02-26 08:51:32 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
mListener = new nsImageListener(this);
|
|
|
|
if (!mListener) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aContent);
|
|
|
|
NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
|
|
|
|
imageLoader->AddObserver(mListener);
|
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
if (!gIconLoad)
|
|
|
|
LoadIcons(aPresContext);
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
// Give image loads associated with an image frame a small priority boost!
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
2005-09-18 22:05:40 +04:00
|
|
|
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(currentRequest);
|
|
|
|
if (p)
|
|
|
|
p->AdjustPriority(-1);
|
2005-02-21 23:58:01 +03:00
|
|
|
|
2003-05-04 22:06:10 +04:00
|
|
|
// If we already have an image container, OnStartContainer won't be called
|
|
|
|
// Set the animation mode here
|
2003-12-26 07:24:11 +03:00
|
|
|
if (currentRequest) {
|
2004-01-08 21:29:28 +03:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
2003-05-04 22:06:10 +04:00
|
|
|
currentRequest->GetImage(getter_AddRefs(image));
|
2004-01-08 21:29:28 +03:00
|
|
|
if (image) {
|
2004-02-03 23:30:02 +03:00
|
|
|
image->SetAnimationMode(aPresContext->ImageAnimationMode());
|
2004-01-08 21:29:28 +03:00
|
|
|
// Ensure the animation (if any) is started.
|
|
|
|
image->StartAnimation();
|
|
|
|
}
|
2003-05-04 22:06:10 +04:00
|
|
|
}
|
2003-12-26 07:24:11 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsImageFrame::RecalculateTransform(imgIContainer* aImage)
|
|
|
|
{
|
|
|
|
PRBool intrinsicSizeChanged = PR_FALSE;
|
|
|
|
|
|
|
|
if (aImage) {
|
|
|
|
float p2t;
|
2004-02-11 07:57:07 +03:00
|
|
|
p2t = GetPresContext()->PixelsToTwips();
|
2003-03-19 06:47:09 +03:00
|
|
|
|
|
|
|
nsSize imageSizeInPx;
|
|
|
|
aImage->GetWidth(&imageSizeInPx.width);
|
|
|
|
aImage->GetHeight(&imageSizeInPx.height);
|
|
|
|
nsSize newSize(NSIntPixelsToTwips(imageSizeInPx.width, p2t),
|
|
|
|
NSIntPixelsToTwips(imageSizeInPx.height, p2t));
|
|
|
|
if (mIntrinsicSize != newSize) {
|
|
|
|
intrinsicSizeChanged = PR_TRUE;
|
|
|
|
mIntrinsicSize = newSize;
|
|
|
|
}
|
1999-02-27 03:57:04 +03:00
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
// In any case, we need to translate this over appropriately. Set
|
|
|
|
// translation _before_ setting scaling so that it does not get
|
|
|
|
// scaled!
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
// XXXbz does this introduce rounding errors because of the cast to
|
|
|
|
// float? Should we just manually add that stuff in every time
|
|
|
|
// instead?
|
|
|
|
mTransform.SetToTranslate(float(mBorderPadding.left),
|
|
|
|
float(mBorderPadding.top - GetContinuationOffset()));
|
|
|
|
|
|
|
|
// Set the scale factors
|
|
|
|
if (mIntrinsicSize.width != 0 && mIntrinsicSize.height != 0 &&
|
|
|
|
mIntrinsicSize != mComputedSize) {
|
|
|
|
mTransform.AddScale(float(mComputedSize.width) / float(mIntrinsicSize.width),
|
|
|
|
float(mComputedSize.height) / float(mIntrinsicSize.height));
|
|
|
|
}
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
return intrinsicSizeChanged;
|
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2003-03-19 06:47:09 +03: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.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsImageFrame::IsPendingLoad(imgIContainer* aContainer) const
|
|
|
|
{
|
|
|
|
// default to pending load in case of errors
|
|
|
|
if (!aContainer) {
|
|
|
|
NS_ERROR("No image container!");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> currentContainer;
|
|
|
|
currentRequest->GetImage(getter_AddRefs(currentContainer));
|
|
|
|
|
|
|
|
return currentContainer != aContainer;
|
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsRect
|
2004-08-29 03:59:15 +04:00
|
|
|
nsImageFrame::SourceRectToDest(const nsRect& aRect)
|
2003-03-19 06:47:09 +03:00
|
|
|
{
|
2004-08-29 03:59:15 +04:00
|
|
|
float p2t = GetPresContext()->PixelsToTwips();
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
nsRect r(NSIntPixelsToTwips(aRect.x - 1, p2t),
|
|
|
|
NSIntPixelsToTwips(aRect.y - 1, p2t),
|
|
|
|
NSIntPixelsToTwips(aRect.width + 2, p2t),
|
|
|
|
NSIntPixelsToTwips(aRect.height + 2, p2t));
|
|
|
|
|
|
|
|
mTransform.TransformCoord(&r.x, &r.y, &r.width, &r.height);
|
|
|
|
|
|
|
|
// Now, round the edges out to the pixel boundary.
|
|
|
|
int scale = (int) p2t;
|
|
|
|
nscoord right = r.x + r.width;
|
|
|
|
nscoord bottom = r.y + r.height;
|
|
|
|
|
|
|
|
r.x -= (scale + (r.x % scale)) % scale;
|
|
|
|
r.y -= (scale + (r.y % scale)) % scale;
|
|
|
|
r.width = right + ((scale - (right % scale)) % scale) - r.x;
|
|
|
|
r.height = bottom + ((scale - (bottom % scale)) % scale) - r.y;
|
|
|
|
|
|
|
|
return r;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
static PRBool
|
2005-10-17 04:50:39 +04:00
|
|
|
ImageOK(PRInt32 aContentState)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2005-09-18 22:05:40 +04: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).
|
2005-10-17 04:50:39 +04:00
|
|
|
return !(aContentState &
|
|
|
|
(NS_EVENT_STATE_BROKEN | NS_EVENT_STATE_USERDISABLED |
|
|
|
|
NS_EVENT_STATE_LOADING));
|
2005-09-18 22:05:40 +04:00
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
/* static */
|
|
|
|
PRBool
|
|
|
|
nsImageFrame::ShouldCreateImageFrameFor(nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
2005-10-17 04:50:39 +04:00
|
|
|
PRInt32 state = aContent->IntrinsicState();
|
|
|
|
if (ImageOK(state)) {
|
2005-09-18 22:05:40 +04:00
|
|
|
// Image is fine; do the image frame thing
|
|
|
|
return PR_TRUE;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2005-10-17 04:50:39 +04:00
|
|
|
|
|
|
|
if ((state & NS_EVENT_STATE_LOADING) &&
|
|
|
|
HaveFixedSize(aStyleContext->GetStylePosition())) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2003-04-29 22:49:42 +04:00
|
|
|
// Check if we want to use a placeholder box with an icon or just
|
|
|
|
// let the the presShell make us into inline text. Decide as follows:
|
|
|
|
//
|
|
|
|
// - if our special "force icons" style is set, show an icon
|
|
|
|
// - else if our "do not show placeholders" pref is set, skip the icon
|
|
|
|
// - else:
|
|
|
|
// - if 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 22:05:40 +04:00
|
|
|
// - if QuirksMode, and the IMG has a size show an icon.
|
2003-04-29 22:49:42 +04:00
|
|
|
// - otherwise, skip the icon
|
|
|
|
PRBool useSizedBox;
|
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
if (aStyleContext->GetStyleUIReset()->mForceBrokenImageIcon) {
|
2003-04-29 22:49:42 +04:00
|
|
|
useSizedBox = PR_TRUE;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2004-02-03 23:30:02 +03:00
|
|
|
else if (gIconLoad && gIconLoad->mPrefForceInlineAltText) {
|
2003-04-29 22:49:42 +04:00
|
|
|
useSizedBox = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
2005-09-18 22:05:40 +04:00
|
|
|
if (aStyleContext->PresContext()->CompatibilityMode() !=
|
|
|
|
eCompatibility_NavQuirks) {
|
2003-04-29 22:49:42 +04:00
|
|
|
useSizedBox = PR_FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We are in quirks mode, so we can just check the tag name; no need to
|
|
|
|
// check the namespace.
|
2005-09-24 22:43:15 +04:00
|
|
|
nsIAtom *localName = aContent->NodeInfo()->NameAtom();
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
// Use a sized box if we have no alt text. This means no alt attribute
|
|
|
|
// and the node is not an object or an input (since those always have alt
|
|
|
|
// text).
|
|
|
|
if (!aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::alt) &&
|
2005-09-24 22:43:15 +04:00
|
|
|
localName != nsHTMLAtoms::object &&
|
|
|
|
localName != nsHTMLAtoms::input) {
|
2003-04-29 22:49:42 +04:00
|
|
|
useSizedBox = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// check whether we have fixed size
|
2005-09-18 22:05:40 +04:00
|
|
|
useSizedBox = HaveFixedSize(aStyleContext->GetStylePosition());
|
2003-04-29 22:49:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
return useSizedBox;
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult
|
|
|
|
nsImageFrame::OnStartContainer(imgIRequest *aRequest, imgIContainer *aImage)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2001-10-06 09:08:16 +04:00
|
|
|
if (!aImage) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// handle iconLoads first...
|
|
|
|
if (HandleIconLoads(aRequest, PR_FALSE)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-12-26 07:24:11 +03:00
|
|
|
/* Get requested animation policy from the pres context:
|
|
|
|
* normal = 0
|
|
|
|
* one frame = 1
|
|
|
|
* one loop = 2
|
|
|
|
*/
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext *presContext = GetPresContext();
|
2004-02-03 23:30:02 +03:00
|
|
|
aImage->SetAnimationMode(presContext->ImageAnimationMode());
|
2004-01-08 21:29:28 +03:00
|
|
|
// Ensure the animation (if any) is started.
|
|
|
|
aImage->StartAnimation();
|
2001-04-17 02:02:39 +04:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
if (IsPendingLoad(aRequest)) {
|
|
|
|
// We don't care
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RecalculateTransform(aImage);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
// Now we need to reflow if we have an unconstrained size and have
|
|
|
|
// already gotten the initial reflow
|
|
|
|
if (!(mState & IMAGE_SIZECONSTRAINED) && (mState & IMAGE_GOTINITIALREFLOW)) {
|
2004-02-03 23:30:02 +03:00
|
|
|
nsIPresShell *presShell = presContext->GetPresShell();
|
2003-03-19 06:47:09 +03:00
|
|
|
NS_ASSERTION(mParent, "No parent to pass the reflow request up to.");
|
|
|
|
NS_ASSERTION(presShell, "No PresShell.");
|
|
|
|
if (mParent && presShell) {
|
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
|
|
|
mParent->ReflowDirtyChild(presShell, NS_STATIC_CAST(nsIFrame*, this));
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult
|
|
|
|
nsImageFrame::OnDataAvailable(imgIRequest *aRequest,
|
|
|
|
gfxIImageFrame *aFrame,
|
|
|
|
const nsRect *aRect)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03: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 12:23:14 +04:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aRect);
|
2003-03-19 09:51:46 +03:00
|
|
|
|
|
|
|
if (!(mState & IMAGE_GOTINITIALREFLOW)) {
|
|
|
|
// Don't bother to do anything; we have a reflow coming up!
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// handle iconLoads first...
|
|
|
|
if (HandleIconLoads(aRequest, PR_FALSE)) {
|
2004-03-10 06:09:05 +03:00
|
|
|
// Image changed, invalidate
|
|
|
|
Invalidate(*aRect, PR_FALSE);
|
2001-11-07 08:02:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
if (IsPendingLoad(aRequest)) {
|
|
|
|
// We don't care
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2003-03-06 02:55:53 +03:00
|
|
|
// Don't invalidate if the current visible frame isn't the one the data is
|
|
|
|
// from
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
aRequest->GetImage(getter_AddRefs(container));
|
|
|
|
if (container) {
|
|
|
|
nsCOMPtr<gfxIImageFrame> currentFrame;
|
|
|
|
container->GetCurrentFrame(getter_AddRefs(currentFrame));
|
|
|
|
if (aFrame != currentFrame) {
|
|
|
|
// just bail
|
|
|
|
return NS_OK;
|
2003-03-06 02:55:53 +03:00
|
|
|
}
|
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2004-08-29 03:59:15 +04:00
|
|
|
nsRect r = SourceRectToDest(*aRect);
|
|
|
|
#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
|
|
|
|
|
2004-03-10 06:09:05 +03:00
|
|
|
Invalidate(r, PR_FALSE);
|
2003-03-19 06:47:09 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-07-11 09:44:12 +04:00
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult
|
|
|
|
nsImageFrame::OnStopDecode(imgIRequest *aRequest,
|
|
|
|
nsresult aStatus,
|
|
|
|
const PRUnichar *aStatusArg)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext *presContext = GetPresContext();
|
2004-02-03 23:30:02 +03:00
|
|
|
nsIPresShell *presShell = presContext->GetPresShell();
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_ASSERTION(presShell, "No PresShell.");
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
// handle iconLoads first...
|
|
|
|
if (HandleIconLoads(aRequest, NS_SUCCEEDED(aStatus))) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
// Check what request type we're dealing with
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
NS_ASSERTION(imageLoader, "Who's notifying us??");
|
|
|
|
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 09:08:16 +04:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
if (loadType == nsIImageLoadingContent::PENDING_REQUEST) {
|
|
|
|
// May have to switch sizes here!
|
2003-05-26 00:43:08 +04:00
|
|
|
PRBool intrinsicSizeChanged = PR_TRUE;
|
2001-10-06 09:08:16 +04:00
|
|
|
if (NS_SUCCEEDED(aStatus)) {
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<imgIContainer> imageContainer;
|
|
|
|
aRequest->GetImage(getter_AddRefs(imageContainer));
|
|
|
|
NS_ASSERTION(imageContainer, "Successful load with no container?");
|
|
|
|
intrinsicSizeChanged = RecalculateTransform(imageContainer);
|
2002-06-19 01:28:53 +04:00
|
|
|
}
|
2003-05-30 23:47:08 +04:00
|
|
|
else {
|
|
|
|
// Have to size to 0,0 so that GetDesiredSize recalculates the size
|
2003-05-26 00:43:08 +04:00
|
|
|
mIntrinsicSize.SizeTo(0, 0);
|
2003-05-30 23:47:08 +04:00
|
|
|
}
|
2002-06-19 01:28:53 +04:00
|
|
|
|
2003-03-19 09:51:46 +03:00
|
|
|
if (mState & IMAGE_GOTINITIALREFLOW) { // do nothing if we havn't gotten the inital reflow yet
|
|
|
|
if (!(mState & IMAGE_SIZECONSTRAINED) && intrinsicSizeChanged) {
|
|
|
|
NS_ASSERTION(mParent, "No parent to pass the reflow request up to.");
|
|
|
|
if (mParent && presShell) {
|
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
|
|
|
mParent->ReflowDirtyChild(presShell, NS_STATIC_CAST(nsIFrame*, this));
|
|
|
|
}
|
|
|
|
} else {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsSize s = GetSize();
|
2003-03-19 09:51:46 +03:00
|
|
|
nsRect r(0, 0, s.width, s.height);
|
2004-03-10 06:09:05 +03:00
|
|
|
// Update border+content to account for image change
|
|
|
|
Invalidate(r, PR_FALSE);
|
2002-06-19 01:28:53 +04:00
|
|
|
}
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult
|
|
|
|
nsImageFrame::FrameChanged(imgIContainer *aContainer,
|
|
|
|
gfxIImageFrame *aNewFrame,
|
|
|
|
nsRect *aDirtyRect)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2003-05-15 07:42:21 +04:00
|
|
|
if (!GetStyleVisibility()->IsVisible()) {
|
2002-07-01 22:17:35 +04:00
|
|
|
return NS_OK;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2002-07-01 22:17:35 +04:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
if (IsPendingLoad(aContainer)) {
|
|
|
|
// We don't care about it
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-29 03:59:15 +04:00
|
|
|
nsRect r = SourceRectToDest(*aDirtyRect);
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2004-03-10 06:09:05 +03:00
|
|
|
// Update border+content to account for image change
|
|
|
|
Invalidate(r, PR_FALSE);
|
2001-03-22 04:38:35 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-13 14:32:43 +03:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
#define MINMAX(_value,_min,_max) \
|
|
|
|
((_value) < (_min) \
|
|
|
|
? (_min) \
|
|
|
|
: ((_value) > (_max) \
|
|
|
|
? (_max) \
|
|
|
|
: (_value)))
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::GetDesiredSize(nsPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
// if mIntrinsicSize.width and height are 0, then we should
|
2001-12-11 06:21:13 +03:00
|
|
|
// check to see if the size is already known by the image container.
|
2003-03-19 06:47:09 +03:00
|
|
|
if (mIntrinsicSize.width == 0 && mIntrinsicSize.height == 0) {
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
}
|
|
|
|
nsCOMPtr<imgIContainer> currentContainer;
|
|
|
|
if (currentRequest) {
|
|
|
|
currentRequest->GetImage(getter_AddRefs(currentContainer));
|
|
|
|
}
|
|
|
|
|
2002-03-26 23:14:05 +03:00
|
|
|
float p2t;
|
2004-02-11 07:57:07 +03:00
|
|
|
p2t = aPresContext->PixelsToTwips();
|
2002-03-26 23:14:05 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
if (currentContainer) {
|
|
|
|
RecalculateTransform(currentContainer);
|
|
|
|
} 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-25 00:51:50 +03:00
|
|
|
if (aPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
|
2003-03-19 06:47:09 +03:00
|
|
|
mIntrinsicSize.SizeTo(NSIntPixelsToTwips(ICON_SIZE+(2*(ICON_PADDING+ALT_BORDER_WIDTH)), p2t),
|
|
|
|
NSIntPixelsToTwips(ICON_SIZE+(2*(ICON_PADDING+ALT_BORDER_WIDTH)), p2t));
|
2001-10-06 12:19:44 +04:00
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
RecalculateTransform(nsnull);
|
2001-10-06 09:08:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-05 04:17:11 +04:00
|
|
|
// Handle intrinsic sizes and their interaction with
|
|
|
|
// {min-,max-,}{width,height} according to the rules in
|
|
|
|
// http://www.w3.org/TR/CSS21/visudet.html#min-max-widths
|
|
|
|
|
|
|
|
// Note: throughout the following section of the function, I avoid
|
|
|
|
// a * (b / c) because of its reduced accuracy relative to a * b / c
|
|
|
|
// or (a * b) / c (which are equivalent).
|
|
|
|
|
2001-04-17 13:03:20 +04:00
|
|
|
// convert from normal twips to scaled twips (printing...)
|
2004-07-29 23:41:39 +04:00
|
|
|
float t2st = aPresContext->TwipsToPixels() *
|
|
|
|
aPresContext->ScaledPixelsToTwips(); // twips to scaled twips
|
2001-12-11 06:21:13 +03:00
|
|
|
nscoord intrinsicWidth =
|
|
|
|
NSToCoordRound(float(mIntrinsicSize.width) * t2st);
|
|
|
|
nscoord intrinsicHeight =
|
|
|
|
NSToCoordRound(float(mIntrinsicSize.height) * t2st);
|
|
|
|
|
|
|
|
// Determine whether the image has fixed content width
|
2004-07-05 04:17:11 +04:00
|
|
|
nscoord width = aReflowState.mComputedWidth;
|
2001-12-11 06:21:13 +03:00
|
|
|
nscoord minWidth = aReflowState.mComputedMinWidth;
|
|
|
|
nscoord maxWidth = aReflowState.mComputedMaxWidth;
|
|
|
|
|
|
|
|
// Determine whether the image has fixed content height
|
2004-07-05 04:17:11 +04:00
|
|
|
nscoord height = aReflowState.mComputedHeight;
|
2001-12-11 06:21:13 +03:00
|
|
|
nscoord minHeight = aReflowState.mComputedMinHeight;
|
|
|
|
nscoord maxHeight = aReflowState.mComputedMaxHeight;
|
|
|
|
|
2004-07-05 04:17:11 +04:00
|
|
|
PRBool isAutoWidth = width == NS_INTRINSICSIZE;
|
|
|
|
PRBool isAutoHeight = height == NS_UNCONSTRAINEDSIZE;
|
2003-03-19 06:47:09 +03:00
|
|
|
if (isAutoWidth) {
|
2004-07-05 04:17:11 +04:00
|
|
|
if (isAutoHeight) {
|
|
|
|
|
|
|
|
// 'auto' width, 'auto' height
|
|
|
|
// XXX nsHTMLReflowState should already ensure this
|
|
|
|
if (minWidth > maxWidth)
|
|
|
|
maxWidth = minWidth;
|
|
|
|
if (minHeight > maxHeight)
|
|
|
|
maxHeight = minHeight;
|
|
|
|
|
|
|
|
nscoord heightAtMaxWidth, heightAtMinWidth,
|
|
|
|
widthAtMaxHeight, widthAtMinHeight;
|
|
|
|
if (intrinsicWidth > 0) {
|
|
|
|
heightAtMaxWidth = maxWidth * intrinsicHeight / intrinsicWidth;
|
|
|
|
if (heightAtMaxWidth < minHeight)
|
|
|
|
heightAtMaxWidth = minHeight;
|
|
|
|
heightAtMinWidth = minWidth * intrinsicHeight / intrinsicWidth;
|
|
|
|
if (heightAtMinWidth > maxHeight)
|
|
|
|
heightAtMinWidth = maxHeight;
|
|
|
|
} else {
|
|
|
|
heightAtMaxWidth = intrinsicHeight;
|
|
|
|
heightAtMinWidth = intrinsicHeight;
|
|
|
|
}
|
2001-12-11 06:21:13 +03:00
|
|
|
|
2004-07-05 04:17:11 +04:00
|
|
|
if (intrinsicHeight > 0) {
|
|
|
|
widthAtMaxHeight = maxHeight * intrinsicWidth / intrinsicHeight;
|
|
|
|
if (widthAtMaxHeight < minWidth)
|
|
|
|
widthAtMaxHeight = minWidth;
|
|
|
|
widthAtMinHeight = minHeight * intrinsicWidth / intrinsicHeight;
|
|
|
|
if (widthAtMinHeight > maxWidth)
|
|
|
|
widthAtMinHeight = maxWidth;
|
|
|
|
} else {
|
|
|
|
widthAtMaxHeight = intrinsicWidth;
|
|
|
|
widthAtMinHeight = intrinsicWidth;
|
|
|
|
}
|
2001-12-11 06:21:13 +03:00
|
|
|
|
2004-07-05 04:17:11 +04:00
|
|
|
if (intrinsicWidth > maxWidth) {
|
|
|
|
if (intrinsicHeight > maxHeight) {
|
|
|
|
if (maxWidth * intrinsicHeight <= maxHeight * intrinsicWidth) {
|
|
|
|
width = maxWidth;
|
|
|
|
height = heightAtMaxWidth;
|
|
|
|
} else {
|
|
|
|
height = maxHeight;
|
|
|
|
width = widthAtMaxHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
width = maxWidth;
|
|
|
|
height = heightAtMaxWidth;
|
|
|
|
}
|
|
|
|
} else if (intrinsicWidth < minWidth) {
|
|
|
|
if (intrinsicHeight < minHeight) {
|
|
|
|
if (minWidth * intrinsicHeight <= minHeight * intrinsicWidth) {
|
|
|
|
height = minHeight;
|
|
|
|
width = widthAtMinHeight;
|
|
|
|
} else {
|
|
|
|
width = minWidth;
|
|
|
|
height = heightAtMinWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
width = minWidth;
|
|
|
|
height = heightAtMinWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (intrinsicHeight > maxHeight) {
|
|
|
|
height = maxHeight;
|
|
|
|
width = widthAtMaxHeight;
|
|
|
|
} else if (intrinsicHeight < minHeight) {
|
|
|
|
height = minHeight;
|
|
|
|
width = widthAtMinHeight;
|
|
|
|
} else {
|
|
|
|
width = intrinsicWidth;
|
|
|
|
height = intrinsicHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 'auto' width, non-'auto' height
|
|
|
|
// XXX nsHTMLReflowState should already ensure this
|
|
|
|
height = MINMAX(height, minHeight, maxHeight);
|
|
|
|
if (intrinsicHeight != 0) {
|
|
|
|
width = intrinsicWidth * height / intrinsicHeight;
|
|
|
|
} else {
|
|
|
|
width = intrinsicWidth;
|
|
|
|
}
|
|
|
|
width = MINMAX(width, minWidth, maxWidth);
|
2001-12-11 06:21:13 +03:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
} else {
|
2004-07-05 04:17:11 +04:00
|
|
|
if (isAutoHeight) {
|
|
|
|
|
|
|
|
// non-'auto' width, 'auto' height
|
|
|
|
// XXX nsHTMLReflowState should already ensure this
|
|
|
|
width = MINMAX(width, minWidth, maxWidth);
|
|
|
|
if (intrinsicWidth != 0) {
|
|
|
|
height = intrinsicHeight * width / intrinsicWidth;
|
|
|
|
} else {
|
|
|
|
height = intrinsicHeight;
|
|
|
|
}
|
|
|
|
height = MINMAX(height, minHeight, maxHeight);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// non-'auto' width, non-'auto' height
|
|
|
|
// XXX nsHTMLReflowState should already ensure this
|
|
|
|
height = MINMAX(height, minHeight, maxHeight);
|
|
|
|
// XXX nsHTMLReflowState should already ensure this
|
|
|
|
width = MINMAX(width, minWidth, maxWidth);
|
|
|
|
|
2001-12-11 06:21:13 +03:00
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2004-07-05 04:17:11 +04:00
|
|
|
if (mComputedSize.width != width || mComputedSize.height != height) {
|
|
|
|
mComputedSize.SizeTo(width, height);
|
2003-03-19 06:47:09 +03:00
|
|
|
RecalculateTransform(nsnull);
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
aDesiredSize.width = mComputedSize.width;
|
|
|
|
aDesiredSize.height = mComputedSize.height;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2004-12-26 22:48:54 +03:00
|
|
|
nsRect
|
|
|
|
nsImageFrame::GetInnerArea() const
|
1998-11-20 20:21:02 +03:00
|
|
|
{
|
2004-12-26 22:48:54 +03:00
|
|
|
nsRect r;
|
|
|
|
r.x = mBorderPadding.left;
|
|
|
|
r.y = mPrevInFlow ? 0 : mBorderPadding.top;
|
|
|
|
r.width = mRect.width - mBorderPadding.left - mBorderPadding.right;
|
|
|
|
r.height = mRect.height -
|
2003-03-19 06:47:09 +03:00
|
|
|
(mPrevInFlow ? 0 : mBorderPadding.top) -
|
|
|
|
(mNextInFlow ? 0 : mBorderPadding.bottom);
|
2004-12-26 22:48:54 +03:00
|
|
|
return r;
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the offset into the content area of the image where aImg starts if it is a continuation.
|
|
|
|
nscoord
|
|
|
|
nsImageFrame::GetContinuationOffset(nscoord* aWidth) const
|
|
|
|
{
|
|
|
|
nscoord offset = 0;
|
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPrevInFlow) {
|
2004-09-14 06:28:03 +04:00
|
|
|
for (nsIFrame* prevInFlow = mPrevInFlow ; prevInFlow; prevInFlow = prevInFlow->GetPrevInFlow()) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsRect rect = prevInFlow->GetRect();
|
2001-11-01 18:31:13 +03:00
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = rect.width;
|
|
|
|
}
|
|
|
|
offset += rect.height;
|
|
|
|
}
|
|
|
|
offset -= mBorderPadding.top;
|
|
|
|
offset = PR_MAX(0, offset);
|
|
|
|
}
|
|
|
|
return offset;
|
1998-11-20 20:21:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::Reflow(nsPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2000-04-21 18:59:47 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsImageFrame", aReflowState.reason);
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
1998-11-20 20:21:02 +03:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2000-05-14 08:43:52 +04:00
|
|
|
("enter nsImageFrame::Reflow: availSize=%d,%d",
|
1999-01-06 02:31:18 +03:00
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight));
|
1998-11-20 20:21:02 +03:00
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
2001-03-06 03:47:46 +03:00
|
|
|
// see if we have a frozen size (i.e. a fixed width and height)
|
2003-02-25 01:20:26 +03:00
|
|
|
if (HaveFixedSize(aReflowState)) {
|
|
|
|
mState |= IMAGE_SIZECONSTRAINED;
|
|
|
|
} else {
|
2003-03-19 06:47:09 +03:00
|
|
|
mState &= ~IMAGE_SIZECONSTRAINED;
|
2003-02-25 01:20:26 +03:00
|
|
|
}
|
2001-03-06 03:47:46 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
if (aReflowState.reason == eReflowReason_Initial) {
|
2003-02-25 01:20:26 +03:00
|
|
|
mState |= IMAGE_GOTINITIALREFLOW;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set our borderpadding so that if GetDesiredSize has to recalc the
|
|
|
|
// transform it can.
|
|
|
|
mBorderPadding = aReflowState.mComputedBorderPadding;
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
// get the desired size of the complete image
|
1999-11-24 09:03:41 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
2001-11-01 18:31:13 +03:00
|
|
|
|
|
|
|
// add borders and padding
|
|
|
|
aMetrics.width += mBorderPadding.left + mBorderPadding.right;
|
|
|
|
aMetrics.height += mBorderPadding.top + mBorderPadding.bottom;
|
|
|
|
|
|
|
|
if (mPrevInFlow) {
|
|
|
|
nscoord y = GetContinuationOffset(&aMetrics.width);
|
|
|
|
aMetrics.height -= y + mBorderPadding.top;
|
|
|
|
aMetrics.height = PR_MAX(0, aMetrics.height);
|
|
|
|
}
|
|
|
|
|
2002-01-11 22:32:55 +03:00
|
|
|
|
|
|
|
// we have to split images if we are:
|
|
|
|
// in Paginated mode, we need to have a constrained height, and have a height larger than our available height
|
2002-08-29 05:44:15 +04:00
|
|
|
PRUint32 loadStatus = imgIRequest::STATUS_NONE;
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
NS_ASSERTION(imageLoader, "No content node??");
|
|
|
|
if (imageLoader) {
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
if (currentRequest) {
|
|
|
|
currentRequest->GetImageStatus(&loadStatus);
|
|
|
|
}
|
2002-08-29 05:44:15 +04:00
|
|
|
}
|
2004-03-03 21:24:20 +03:00
|
|
|
if (aPresContext->IsPaginated() &&
|
2003-02-25 01:20:26 +03:00
|
|
|
((loadStatus & imgIRequest::STATUS_SIZE_AVAILABLE) || (mState & IMAGE_SIZECONSTRAINED)) &&
|
2003-03-19 06:47:09 +03:00
|
|
|
NS_UNCONSTRAINEDSIZE != aReflowState.availableHeight &&
|
|
|
|
aMetrics.height > aReflowState.availableHeight) {
|
2001-11-01 18:31:13 +03:00
|
|
|
// split an image frame but not an image control frame
|
2003-10-31 23:19:18 +03:00
|
|
|
if (nsLayoutAtoms::imageFrame == GetType()) {
|
2002-02-25 17:42:12 +03:00
|
|
|
// our desired height was greater than 0, so to avoid infinite splitting, use 1 pixel as the min
|
2004-07-29 23:41:39 +04:00
|
|
|
aMetrics.height = PR_MAX(NSToCoordRound(aPresContext->ScaledPixelsToTwips()), aReflowState.availableHeight);
|
2001-11-01 18:31:13 +03:00
|
|
|
aStatus = NS_FRAME_NOT_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
aMetrics.descent = 0;
|
|
|
|
|
2003-01-09 17:26:32 +03:00
|
|
|
if (aMetrics.mComputeMEW) {
|
2004-09-14 06:28:03 +04:00
|
|
|
aMetrics.SetMEWToActualWidth(aReflowState.mStylePosition->mWidth.GetUnit());
|
1998-11-20 20:21:02 +03:00
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2000-05-14 08:43:52 +04:00
|
|
|
if (aMetrics.mFlags & NS_REFLOW_CALC_MAX_WIDTH) {
|
|
|
|
aMetrics.mMaximumWidth = aMetrics.width;
|
|
|
|
}
|
2004-09-01 17:33:17 +04:00
|
|
|
aMetrics.mOverflowArea.SetRect(0, 0, aMetrics.width, aMetrics.height);
|
2004-07-16 20:56:21 +04:00
|
|
|
FinishAndStoreOverflow(&aMetrics);
|
1998-11-20 20:21:02 +03:00
|
|
|
|
2005-03-03 07:42:48 +03: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) {
|
|
|
|
Invalidate(nsRect(0, 0, mRect.width, mRect.height), PR_FALSE);
|
|
|
|
}
|
|
|
|
|
1998-11-20 20:21:02 +03:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
2000-05-14 08:43:52 +04:00
|
|
|
("exit nsImageFrame::Reflow: size=%d,%d",
|
1998-11-20 20:21:02 +03:00
|
|
|
aMetrics.width, aMetrics.height));
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
1998-11-20 20:21:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// Computes the width of the specified string. aMaxWidth specifies the maximum
|
|
|
|
// width available. Once this limit is reached no more characters are measured.
|
|
|
|
// The number of characters that fit within the maximum width are returned in
|
1998-10-02 05:12:39 +04:00
|
|
|
// aMaxFit. NOTE: it is assumed that the fontmetrics have already been selected
|
|
|
|
// into the rendering context before this is called (for performance). MMP
|
1999-02-12 20:45:58 +03:00
|
|
|
void
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::MeasureString(const PRUnichar* aString,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nscoord aMaxWidth,
|
|
|
|
PRUint32& aMaxFit,
|
|
|
|
nsIRenderingContext& aContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
nscoord totalWidth = 0;
|
|
|
|
nscoord spaceWidth;
|
1998-10-02 05:12:39 +04:00
|
|
|
aContext.GetWidth(' ', spaceWidth);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
aMaxFit = 0;
|
|
|
|
while (aLength > 0) {
|
|
|
|
// Find the next place we can line break
|
|
|
|
PRUint32 len = aLength;
|
|
|
|
PRBool trailingSpace = PR_FALSE;
|
|
|
|
for (PRInt32 i = 0; i < aLength; i++) {
|
|
|
|
if (XP_IS_SPACE(aString[i]) && (i > 0)) {
|
|
|
|
len = i; // don't include the space when measuring
|
|
|
|
trailingSpace = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measure this chunk of text, and see if it fits
|
|
|
|
nscoord width;
|
1998-10-02 05:12:39 +04:00
|
|
|
aContext.GetWidth(aString, len, width);
|
1998-09-09 02:34:40 +04:00
|
|
|
PRBool fits = (totalWidth + width) <= aMaxWidth;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
fits = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMaxFit += len;
|
|
|
|
aString += len;
|
|
|
|
aLength -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fits) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Formats the alt-text to fit within the specified rectangle. Breaks lines
|
|
|
|
// between words if a word would extend past the edge of the rectangle
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::DisplayAltText(nsPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsString& aAltText,
|
|
|
|
const nsRect& aRect)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
// Set font and color
|
2003-05-15 07:42:21 +04:00
|
|
|
aRenderingContext.SetColor(GetStyleColor()->mColor);
|
2002-05-25 00:11:14 +04:00
|
|
|
SetFontFromStyle(&aRenderingContext, mStyleContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Format the text to display within the formatting rect
|
1998-10-30 05:08:25 +03:00
|
|
|
nsIFontMetrics* fm;
|
|
|
|
aRenderingContext.GetFontMetrics(fm);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2001-10-31 01:58:00 +03:00
|
|
|
nscoord maxAscent, maxDescent, height;
|
|
|
|
fm->GetMaxAscent(maxAscent);
|
1998-09-09 02:34:40 +04:00
|
|
|
fm->GetMaxDescent(maxDescent);
|
|
|
|
fm->GetHeight(height);
|
|
|
|
|
|
|
|
// 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 15:02:25 +04:00
|
|
|
const PRUnichar* str = aAltText.get();
|
1998-09-09 02:34:40 +04:00
|
|
|
PRInt32 strLen = aAltText.Length();
|
|
|
|
nscoord y = aRect.y;
|
2004-10-12 01:52:36 +04:00
|
|
|
// Always show the first line, even if we have to clip it below
|
|
|
|
PRBool firstLine = PR_TRUE;
|
|
|
|
while ((strLen > 0) && (firstLine || (y + maxDescent) < aRect.YMost())) {
|
1998-09-09 02:34:40 +04:00
|
|
|
// Determine how much of the text to display on this line
|
|
|
|
PRUint32 maxFit; // number of characters that fit
|
1999-02-12 20:45:58 +03:00
|
|
|
MeasureString(str, strLen, aRect.width, maxFit, aRenderingContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Display the text
|
2001-10-31 01:58:00 +03:00
|
|
|
aRenderingContext.DrawString(str, maxFit, aRect.x, y + maxAscent);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
// Move to the next line
|
|
|
|
str += maxFit;
|
|
|
|
strLen -= maxFit;
|
|
|
|
y += height;
|
2004-10-12 01:52:36 +04:00
|
|
|
firstLine = PR_FALSE;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(fm);
|
|
|
|
}
|
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
struct nsRecessedBorder : public nsStyleBorder {
|
1998-09-09 02:34:40 +04:00
|
|
|
nsRecessedBorder(nscoord aBorderWidth)
|
2001-02-07 12:57:26 +03:00
|
|
|
: nsStyleBorder()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2005-04-29 19:44:38 +04:00
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2005-05-05 20:03:06 +04:00
|
|
|
// Note: use SetBorderColor here because we want to make sure
|
|
|
|
// the "special" flags are unset.
|
|
|
|
SetBorderColor(side, NS_RGB(0, 0, 0));
|
2005-04-29 19:44:38 +04:00
|
|
|
mBorder.side(side) = aBorderWidth;
|
2005-05-05 20:03:06 +04:00
|
|
|
// Note: use SetBorderStyle here because we want to affect
|
|
|
|
// mComputedBorder
|
2005-04-29 19:44:38 +04:00
|
|
|
SetBorderStyle(side, NS_STYLE_BORDER_STYLE_INSET);
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
1998-09-22 07:34:44 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::DisplayAltFeedback(nsPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2004-02-03 23:30:02 +03:00
|
|
|
imgIRequest* aRequest)
|
1998-09-22 07:34:44 +04:00
|
|
|
{
|
1999-09-17 01:37:37 +04:00
|
|
|
// Calculate the inner area
|
2004-12-26 22:48:54 +03:00
|
|
|
nsRect inner = GetInnerArea();
|
1998-09-22 07:34:44 +04:00
|
|
|
|
1999-09-17 01:37:37 +04:00
|
|
|
// Display a recessed one pixel border
|
|
|
|
nscoord borderEdgeWidth;
|
2004-07-29 23:41:39 +04:00
|
|
|
float p2t = aPresContext->ScaledPixelsToTwips();
|
2001-11-07 08:02:42 +03:00
|
|
|
borderEdgeWidth = NSIntPixelsToTwips(ALT_BORDER_WIDTH, p2t);
|
1999-09-17 01:37:37 +04:00
|
|
|
|
2002-03-26 23:14:05 +03:00
|
|
|
// if inner area is empty, then make it big enough for at least the icon
|
|
|
|
if (inner.IsEmpty()){
|
2003-03-19 06:47:09 +03:00
|
|
|
inner.SizeTo(2*(NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING+ALT_BORDER_WIDTH,p2t)),
|
2002-03-26 23:14:05 +03:00
|
|
|
2*(NSIntPixelsToTwips(ICON_SIZE+ICON_PADDING+ALT_BORDER_WIDTH,p2t)));
|
|
|
|
}
|
|
|
|
|
1999-09-17 01:37:37 +04:00
|
|
|
// Make sure we have enough room to actually render the border within
|
|
|
|
// our frame bounds
|
|
|
|
if ((inner.width < 2 * borderEdgeWidth) || (inner.height < 2 * borderEdgeWidth)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paint the border
|
|
|
|
nsRecessedBorder recessedBorder(borderEdgeWidth);
|
1998-09-22 07:34:44 +04:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this, inner,
|
1999-01-23 01:26:29 +03:00
|
|
|
inner, recessedBorder, mStyleContext, 0);
|
1998-09-22 07:34:44 +04:00
|
|
|
|
|
|
|
// Adjust the inner rect to account for the one pixel recessed border,
|
|
|
|
// and a six pixel padding on each edge
|
2001-11-07 08:02:42 +03:00
|
|
|
inner.Deflate(NSIntPixelsToTwips(ICON_PADDING+ALT_BORDER_WIDTH, p2t),
|
|
|
|
NSIntPixelsToTwips(ICON_PADDING+ALT_BORDER_WIDTH, p2t));
|
1998-09-22 07:34:44 +04:00
|
|
|
if (inner.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clip so we don't render outside the inner rect
|
|
|
|
aRenderingContext.PushState();
|
2004-04-23 19:21:24 +04:00
|
|
|
aRenderingContext.SetClipRect(inner, nsClipCombine_kIntersect);
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
PRBool dispIcon = gIconLoad ? gIconLoad->mPrefShowPlaceholders : PR_TRUE;
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// Check if we should display image placeholders
|
|
|
|
if (dispIcon) {
|
|
|
|
PRInt32 size = NSIntPixelsToTwips(ICON_SIZE, p2t);
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
PRBool iconUsed = PR_FALSE;
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// see if the icon images are present...
|
2004-02-03 23:30:02 +03:00
|
|
|
if (gIconLoad && gIconLoad->mIconsLoaded) {
|
2002-04-10 18:45:05 +04:00
|
|
|
// pick the correct image
|
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
2004-02-03 23:30:02 +03:00
|
|
|
if (aRequest) {
|
|
|
|
aRequest->GetImage(getter_AddRefs(imgCon));
|
2002-04-10 18:45:05 +04:00
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
if (imgCon) {
|
2002-04-10 18:45:05 +04:00
|
|
|
// draw it
|
2004-05-04 05:32:26 +04:00
|
|
|
nsRect source(0,0,size,size);
|
|
|
|
nsRect dest(inner.x,inner.y,size,size);
|
|
|
|
aRenderingContext.DrawImage(imgCon, source, dest);
|
2002-04-10 18:45:05 +04:00
|
|
|
iconUsed = PR_TRUE;
|
|
|
|
}
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
1998-09-22 07:34:44 +04:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// if we could not draw the image, then just draw some grafitti
|
|
|
|
if (!iconUsed) {
|
|
|
|
nscolor oldColor;
|
|
|
|
aRenderingContext.DrawRect(0,0,size,size);
|
|
|
|
aRenderingContext.GetColor(oldColor);
|
2004-02-03 23:30:02 +03:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0xFF,0,0));
|
2002-04-10 18:45:05 +04:00
|
|
|
aRenderingContext.FillEllipse(NS_STATIC_CAST(int,size/2),NS_STATIC_CAST(int,size/2),
|
|
|
|
NS_STATIC_CAST(int,(size/2)-(2*p2t)),NS_STATIC_CAST(int,(size/2)-(2*p2t)));
|
|
|
|
aRenderingContext.SetColor(oldColor);
|
|
|
|
}
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2002-04-10 18:45:05 +04:00
|
|
|
// Reduce the inner rect by the width of the icon, and leave an
|
|
|
|
// additional ICON_PADDING pixels for padding
|
|
|
|
PRInt32 iconWidth = NSIntPixelsToTwips(ICON_SIZE + ICON_PADDING, p2t);
|
|
|
|
inner.x += iconWidth;
|
|
|
|
inner.width -= iconWidth;
|
|
|
|
}
|
1998-09-22 07:34:44 +04:00
|
|
|
|
|
|
|
// If there's still room, display the alt-text
|
|
|
|
if (!inner.IsEmpty()) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIContent* content = GetContent();
|
2001-11-07 08:02:42 +03:00
|
|
|
if (content) {
|
2005-01-19 02:46:59 +03:00
|
|
|
nsXPIDLString altText;
|
2003-11-19 04:20:56 +03:00
|
|
|
nsCSSFrameConstructor::GetAlternateTextFor(content, content->Tag(),
|
|
|
|
altText);
|
|
|
|
DisplayAltText(aPresContext, aRenderingContext, altText, inner);
|
1998-09-22 07:34:44 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-18 17:13:35 +04:00
|
|
|
aRenderingContext.PopState();
|
1998-09-22 07:34:44 +04:00
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_METHOD
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::Paint(nsPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-09-19 16:35:19 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2001-01-27 17:09:34 +03:00
|
|
|
PRBool isVisible;
|
|
|
|
if (NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) &&
|
|
|
|
isVisible && mRect.width && mRect.height) {
|
2001-04-25 23:52:49 +04:00
|
|
|
// If painting is suppressed, we need to stop image painting. We
|
|
|
|
// have to cover <img> here because of input image controls.
|
|
|
|
PRBool paintingSuppressed = PR_FALSE;
|
2003-12-21 08:36:36 +03:00
|
|
|
aPresContext->PresShell()->IsPaintingSuppressed(&paintingSuppressed);
|
2003-03-19 06:47:09 +03:00
|
|
|
if (paintingSuppressed) {
|
2001-04-25 23:52:49 +04:00
|
|
|
return NS_OK;
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2001-04-25 23:52:49 +04:00
|
|
|
|
2002-04-09 05:16:48 +04:00
|
|
|
// First paint background and borders, which should be in the
|
|
|
|
// FOREGROUND or BACKGROUND paint layer if the element is
|
2003-05-03 06:34:42 +04:00
|
|
|
// inline-level or block-level, respectively (bug 36710). (See
|
|
|
|
// CSS2 9.5, which is the rationale for paint layers.)
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* display = GetStyleDisplay();
|
2002-04-09 05:16:48 +04:00
|
|
|
nsFramePaintLayer backgroundLayer = display->IsBlockLevel()
|
|
|
|
? NS_FRAME_PAINT_LAYER_BACKGROUND
|
|
|
|
: NS_FRAME_PAINT_LAYER_FOREGROUND;
|
|
|
|
if (aWhichLayer == backgroundLayer) {
|
2002-12-24 01:05:47 +03:00
|
|
|
PaintSelf(aPresContext, aRenderingContext, aDirtyRect);
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2003-11-06 19:03:34 +03:00
|
|
|
if (mComputedSize.width != 0 && mComputedSize.height != 0) {
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
2005-09-18 22:05:40 +04:00
|
|
|
NS_ASSERTION(imageLoader, "Not an image loading content?");
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2003-11-06 19:03:34 +03:00
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2005-10-17 04:50:39 +04:00
|
|
|
PRBool imageOK = ImageOK(mContent->IntrinsicState());
|
2001-10-06 09:08:16 +04:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
nsCOMPtr<imgIContainer> imgCon;
|
2003-11-06 19:03:34 +03:00
|
|
|
if (currentRequest) {
|
|
|
|
currentRequest->GetImage(getter_AddRefs(imgCon));
|
|
|
|
}
|
2001-04-17 13:03:20 +04:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
if (!imageOK || !imgCon) {
|
2003-11-06 19:03:34 +03:00
|
|
|
// No image yet, or image load failed. Draw the alt-text and an icon
|
2005-09-18 22:05:40 +04:00
|
|
|
// indicating the status
|
2002-03-26 23:14:05 +03:00
|
|
|
|
2005-09-18 22:05:40 +04:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
2003-11-06 19:03:34 +03:00
|
|
|
DisplayAltFeedback(aPresContext, aRenderingContext,
|
2005-09-18 22:05:40 +04:00
|
|
|
imageOK ? gIconLoad->mLoadingImage
|
|
|
|
: gIconLoad->mBrokenImage);
|
2003-03-19 06:47:09 +03:00
|
|
|
}
|
2003-11-06 19:03:34 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer && imgCon) {
|
|
|
|
// Render the image into our content area (the area inside
|
|
|
|
// the borders and padding)
|
2004-12-26 22:48:54 +03:00
|
|
|
nsRect inner = GetInnerArea();
|
2003-11-06 19:03:34 +03:00
|
|
|
nsRect paintArea(inner);
|
|
|
|
|
|
|
|
nscoord offsetY = 0;
|
|
|
|
|
|
|
|
// if the image is split account for y-offset
|
|
|
|
if (mPrevInFlow) {
|
|
|
|
offsetY = GetContinuationOffset();
|
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
|
2003-11-06 19:03:34 +03:00
|
|
|
if (mIntrinsicSize == mComputedSize) {
|
|
|
|
// Find the actual rect to be painted to in the rendering context
|
|
|
|
paintArea.IntersectRect(paintArea, aDirtyRect);
|
2001-11-01 18:31:13 +03:00
|
|
|
|
2003-11-06 19:03:34 +03:00
|
|
|
// Rect in the image to paint
|
|
|
|
nsRect r(paintArea.x - inner.x,
|
|
|
|
paintArea.y - inner.y + offsetY,
|
|
|
|
paintArea.width,
|
|
|
|
paintArea.height);
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2004-05-04 05:32:26 +04:00
|
|
|
aRenderingContext.DrawImage(imgCon, r, paintArea);
|
2003-11-06 19:03:34 +03:00
|
|
|
} else {
|
|
|
|
// The computed size is the total size of all the continuations,
|
|
|
|
// including ourselves. Note that we're basically inverting
|
|
|
|
// mTransform here (would it too much to ask for
|
|
|
|
// nsTransform2D::Invert?), since we need to convert from
|
|
|
|
// rendering context coords to image coords...
|
|
|
|
nsTransform2D trans;
|
|
|
|
trans.SetToScale((float(mIntrinsicSize.width) / float(mComputedSize.width)),
|
|
|
|
(float(mIntrinsicSize.height) / float(mComputedSize.height)));
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2003-11-06 19:03:34 +03:00
|
|
|
// XXXbz it looks like we should take
|
|
|
|
// IntersectRect(paintArea, aDirtyRect) here too, but things
|
|
|
|
// get very weird if I do that ....
|
|
|
|
// paintArea.IntersectRect(paintArea, aDirtyRect);
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2003-11-06 19:03:34 +03:00
|
|
|
// dirty rect in image our coord size...
|
|
|
|
nsRect r(paintArea.x - inner.x,
|
|
|
|
paintArea.y - inner.y + offsetY,
|
|
|
|
paintArea.width,
|
|
|
|
paintArea.height);
|
|
|
|
|
|
|
|
// Transform that to image coords
|
|
|
|
trans.TransformCoord(&r.x, &r.y, &r.width, &r.height);
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2004-08-29 03:59:15 +04:00
|
|
|
#ifdef DEBUG_decode
|
|
|
|
printf("IF draw src (%d,%d,%d,%d) -> dst (%d,%d,%d,%d)\n",
|
|
|
|
r.x, r.y, r.width, r.height, paintArea.x, paintArea.y,
|
|
|
|
paintArea.width, paintArea.height);
|
|
|
|
#endif
|
|
|
|
|
2004-05-04 05:32:26 +04:00
|
|
|
aRenderingContext.DrawImage(imgCon, r, paintArea);
|
2003-11-06 19:03:34 +03:00
|
|
|
}
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-09 01:31:05 +04:00
|
|
|
|
2000-08-18 10:27:42 +04:00
|
|
|
nsImageMap* map = GetImageMap(aPresContext);
|
1999-04-10 21:32:33 +04:00
|
|
|
if (nsnull != map) {
|
2004-12-26 22:48:54 +03:00
|
|
|
nsRect inner = GetInnerArea();
|
2005-04-10 23:30:40 +04:00
|
|
|
aRenderingContext.PushState();
|
1999-04-10 21:32:33 +04:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
2003-11-06 19:03:34 +03:00
|
|
|
aRenderingContext.SetLineStyle(nsLineStyle_kDotted);
|
1999-04-10 21:32:33 +04:00
|
|
|
aRenderingContext.Translate(inner.x, inner.y);
|
|
|
|
map->Draw(aPresContext, aRenderingContext);
|
2004-04-18 17:13:35 +04:00
|
|
|
aRenderingContext.PopState();
|
2003-11-06 19:03:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) &&
|
|
|
|
GetShowFrameBorders()) {
|
|
|
|
nsImageMap* map = GetImageMap(aPresContext);
|
|
|
|
if (nsnull != map) {
|
2004-12-26 22:48:54 +03:00
|
|
|
nsRect inner = GetInnerArea();
|
2003-11-06 19:03:34 +03:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.Translate(inner.x, inner.y);
|
|
|
|
map->Draw(aPresContext, aRenderingContext);
|
2004-04-18 17:13:35 +04:00
|
|
|
aRenderingContext.PopState();
|
2003-11-06 19:03:34 +03:00
|
|
|
}
|
1999-04-10 21:32:33 +04:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
2003-11-06 19:03:34 +03:00
|
|
|
}
|
1999-04-10 21:32:33 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
2001-12-18 04:29:49 +03:00
|
|
|
PRInt16 displaySelection = 0;
|
|
|
|
|
|
|
|
nsresult result;
|
2003-12-21 08:36:36 +03:00
|
|
|
result = aPresContext->PresShell()->GetSelectionFlags(&displaySelection);
|
2001-12-18 04:29:49 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
if (!(displaySelection & nsISelectionDisplay::DISPLAY_IMAGES))
|
|
|
|
return NS_OK;//no need to check the blue border, we cannot be drawn selected
|
2003-04-23 03:18:34 +04:00
|
|
|
//insert hook here for image selection drawing
|
|
|
|
#if IMAGE_EDITOR_CHECK
|
|
|
|
//check to see if this frame is in an editor context
|
|
|
|
//isEditor check. this needs to be changed to have better way to check
|
|
|
|
if (displaySelection == nsISelectionDisplay::DISPLAY_ALL)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
result = GetSelectionController(aPresContext, getter_AddRefs(selCon));
|
|
|
|
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-29 01:25:13 +04:00
|
|
|
nsCOMPtr<nsIContent> parentContent = mContent->GetParent();
|
2003-04-23 03:18:34 +04:00
|
|
|
if (parentContent)
|
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
PRInt32 thisOffset = parentContent->IndexOf(mContent);
|
2003-04-23 03:18:34 +04: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
|
|
|
|
return NS_OK; //do not allow nsFrame do draw any further selection
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1999-05-17 04:21:18 +04:00
|
|
|
|
2002-04-11 05:11:23 +04:00
|
|
|
return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, nsISelectionDisplay::DISPLAY_IMAGES);
|
2002-08-17 05:46:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::GetImageMap(nsPresContext *aPresContext, nsIImageMap **aImageMap)
|
2002-08-17 05:46:58 +04:00
|
|
|
{
|
|
|
|
nsImageMap *map = GetImageMap(aPresContext);
|
2003-03-19 06:47:09 +03:00
|
|
|
return CallQueryInterface(map, aImageMap);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 03:13:19 +03:00
|
|
|
nsImageMap*
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::GetImageMap(nsPresContext* aPresContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2001-04-18 04:14:34 +04:00
|
|
|
if (!mImageMap) {
|
2003-07-29 01:25:13 +04:00
|
|
|
nsIDocument* doc = mContent->GetDocument();
|
2001-04-18 04:14:34 +04:00
|
|
|
if (!doc) {
|
1998-09-09 02:34:40 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2001-04-18 04:14:34 +04:00
|
|
|
nsAutoString usemap;
|
2002-05-21 02:47:02 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::usemap, usemap);
|
1999-08-20 02:22:02 +04:00
|
|
|
|
2004-02-19 21:56:13 +03:00
|
|
|
nsCOMPtr<nsIDOMHTMLMapElement> map = nsImageMapUtils::FindImageMap(doc,usemap);
|
|
|
|
if (map) {
|
2001-04-18 04:14:34 +04:00
|
|
|
mImageMap = new nsImageMap();
|
|
|
|
if (mImageMap) {
|
|
|
|
NS_ADDREF(mImageMap);
|
2003-12-21 08:36:36 +03:00
|
|
|
mImageMap->Init(aPresContext->PresShell(), this, map);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-01-09 03:13:19 +03:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
return mImageMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::TriggerLink(nsPresContext* aPresContext,
|
2002-11-20 03:44:26 +03:00
|
|
|
nsIURI* aURI,
|
1998-11-20 20:21:02 +03:00
|
|
|
const nsString& aTargetSpec,
|
|
|
|
PRBool aClick)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2000-08-09 00:35:12 +04:00
|
|
|
// We get here with server side image map
|
2004-02-01 13:09:07 +03:00
|
|
|
nsILinkHandler *handler = aPresContext->GetLinkHandler();
|
|
|
|
if (handler) {
|
1998-09-09 02:34:40 +04:00
|
|
|
if (aClick) {
|
2000-08-09 00:35:12 +04:00
|
|
|
// Check that this page is allowed to load this URI.
|
|
|
|
// Almost a copy of the similarly named method in nsGenericElement
|
|
|
|
nsresult rv;
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> securityManager =
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
2000-08-09 00:35:12 +04:00
|
|
|
|
2003-12-21 08:36:36 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIPresShell *ps = aPresContext->GetPresShell();
|
|
|
|
if (!ps)
|
|
|
|
return;
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = ps->GetDocument();
|
2004-04-25 20:55:27 +04:00
|
|
|
if (doc) {
|
|
|
|
rv = securityManager->
|
|
|
|
CheckLoadURIWithPrincipal(doc->GetPrincipal(), aURI,
|
|
|
|
nsIScriptSecurityManager::STANDARD);
|
2003-10-22 10:09:48 +04:00
|
|
|
|
|
|
|
// Only pass off the click event if the script security manager
|
|
|
|
// says it's ok.
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
handler->OnLinkClick(mContent, eLinkVerb_Replace, aURI,
|
|
|
|
aTargetSpec.get());
|
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
else {
|
2002-11-20 03:44:26 +03:00
|
|
|
handler->OnOverLink(mContent, aURI, aTargetSpec.get());
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1998-11-20 20:21:02 +03:00
|
|
|
nsImageFrame::IsServerImageMap()
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
|
|
|
nsAutoString ismap;
|
1999-07-08 23:38:08 +04:00
|
|
|
return NS_CONTENT_ATTR_HAS_VALUE ==
|
2002-05-21 02:47:02 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::ismap, ismap);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
2005-08-23 07:57:07 +04:00
|
|
|
// Translate an point that is relative to our frame
|
|
|
|
// into a localized pixel coordinate that is relative to the
|
1999-07-08 23:38:08 +04:00
|
|
|
// content area of this frame (inside the border+padding).
|
|
|
|
void
|
2004-12-26 22:48:54 +03:00
|
|
|
nsImageFrame::TranslateEventCoords(const nsPoint& aPoint,
|
2005-08-23 07:57:07 +04:00
|
|
|
nsPoint& aResult)
|
1999-07-08 23:38:08 +04:00
|
|
|
{
|
|
|
|
nscoord x = aPoint.x;
|
|
|
|
nscoord y = aPoint.y;
|
|
|
|
|
|
|
|
// Subtract out border and padding here so that the coordinates are
|
|
|
|
// now relative to the content area of this frame.
|
2004-12-26 22:48:54 +03:00
|
|
|
nsRect inner = GetInnerArea();
|
1999-07-08 23:38:08 +04:00
|
|
|
x -= inner.x;
|
|
|
|
y -= inner.y;
|
|
|
|
|
|
|
|
// Translate the coordinates from twips to pixels
|
|
|
|
float t2p;
|
2004-12-26 22:48:54 +03:00
|
|
|
t2p = GetPresContext()->TwipsToPixels();
|
1999-07-08 23:38:08 +04:00
|
|
|
aResult.x = NSTwipsToIntPixels(x, t2p);
|
|
|
|
aResult.y = NSTwipsToIntPixels(y, t2p);
|
|
|
|
}
|
|
|
|
|
1999-07-08 23:44:42 +04:00
|
|
|
PRBool
|
2004-02-10 19:57:00 +03:00
|
|
|
nsImageFrame::GetAnchorHREFAndTarget(nsIURI** aHref, nsString& aTarget)
|
1999-07-08 23:38:08 +04:00
|
|
|
{
|
1999-07-08 23:44:42 +04:00
|
|
|
PRBool status = PR_FALSE;
|
2001-04-11 12:12:10 +04:00
|
|
|
aTarget.Truncate();
|
1999-07-08 23:38:08 +04:00
|
|
|
|
|
|
|
// Walk up the content tree, looking for an nsIDOMAnchorElement
|
2003-07-29 01:25:13 +04:00
|
|
|
for (nsIContent* content = mContent->GetParent();
|
|
|
|
content; content = content->GetParent()) {
|
2004-02-10 19:57:00 +03:00
|
|
|
nsCOMPtr<nsILink> link(do_QueryInterface(content));
|
|
|
|
if (link) {
|
|
|
|
link->GetHrefURI(aHref);
|
|
|
|
status = (*aHref != nsnull);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(content));
|
|
|
|
if (anchor) {
|
|
|
|
anchor->GetTarget(aTarget);
|
1999-07-08 23:44:42 +04:00
|
|
|
}
|
1999-07-08 23:38:08 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-07-08 23:44:42 +04:00
|
|
|
return status;
|
1999-07-08 23:38:08 +04:00
|
|
|
}
|
|
|
|
|
2001-08-30 02:59:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::CanContinueTextRun(PRBool& aContinueTextRun) const
|
|
|
|
{
|
2001-09-08 23:26:34 +04:00
|
|
|
// images really CAN continue text runs, but the textFrame needs to be
|
|
|
|
// educated before we can indicate that it can. For now, we handle the fixing up
|
|
|
|
// of max element widths in nsLineLayout::VerticalAlignFrames, but hopefully
|
|
|
|
// this can be eliminated and the textFrame can be convinced to handle inlines
|
|
|
|
// that take up space in text runs.
|
2001-08-30 02:59:09 +04:00
|
|
|
|
2001-09-08 23:26:34 +04:00
|
|
|
aContinueTextRun = PR_FALSE;
|
2001-08-30 02:59:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-11 04:24:59 +03:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::GetContentForEvent(nsPresContext* aPresContext,
|
2000-02-11 04:24:59 +03:00
|
|
|
nsEvent* aEvent,
|
|
|
|
nsIContent** aContent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aContent);
|
|
|
|
nsImageMap* map;
|
2000-08-18 10:27:42 +04:00
|
|
|
map = GetImageMap(aPresContext);
|
2000-02-11 04:24:59 +03:00
|
|
|
|
|
|
|
if (nsnull != map) {
|
|
|
|
nsPoint p;
|
2005-08-23 07:57:07 +04:00
|
|
|
TranslateEventCoords(
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
|
2000-02-11 04:24:59 +03:00
|
|
|
PRBool inside = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIContent> area;
|
2004-02-20 22:00:43 +03:00
|
|
|
inside = map->IsInside(p.x, p.y, getter_AddRefs(area));
|
2000-02-11 04:24:59 +03:00
|
|
|
if (inside && area) {
|
|
|
|
*aContent = area;
|
|
|
|
NS_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-29 07:43:05 +04:00
|
|
|
*aContent = GetContent();
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
2000-02-11 04:24:59 +03:00
|
|
|
}
|
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
// XXX what should clicks on transparent pixels do?
|
|
|
|
NS_METHOD
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::HandleEvent(nsPresContext* aPresContext,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 09:03:41 +03:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
1999-01-09 03:13:19 +03:00
|
|
|
nsImageMap* map;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_MOVE:
|
1999-08-20 02:22:02 +04:00
|
|
|
{
|
2000-08-18 10:27:42 +04:00
|
|
|
map = GetImageMap(aPresContext);
|
1999-08-20 02:22:02 +04:00
|
|
|
PRBool isServerMap = IsServerImageMap();
|
|
|
|
if ((nsnull != map) || isServerMap) {
|
|
|
|
nsPoint p;
|
2005-08-23 07:57:07 +04:00
|
|
|
TranslateEventCoords(
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p);
|
1999-02-06 05:07:49 +03:00
|
|
|
PRBool inside = PR_FALSE;
|
2000-02-11 04:24:59 +03:00
|
|
|
// Even though client-side image map triggering happens
|
|
|
|
// through content, we need to make sure we're not inside
|
|
|
|
// (in case we deal with a case of both client-side and
|
|
|
|
// sever-side on the same image - it happens!)
|
1999-08-20 02:22:02 +04:00
|
|
|
if (nsnull != map) {
|
2000-02-11 04:24:59 +03:00
|
|
|
nsCOMPtr<nsIContent> area;
|
2004-02-20 22:00:43 +03:00
|
|
|
inside = map->IsInside(p.x, p.y, getter_AddRefs(area));
|
1999-01-15 04:57:58 +03:00
|
|
|
}
|
2001-05-23 11:00:37 +04:00
|
|
|
|
1999-08-20 02:22:02 +04:00
|
|
|
if (!inside && isServerMap) {
|
2004-02-10 19:57:00 +03:00
|
|
|
|
|
|
|
// Server side image maps use the href in a containing anchor
|
|
|
|
// element to provide the basis for the destination url.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2004-02-20 22:00:43 +03:00
|
|
|
nsAutoString target;
|
2004-02-10 19:57:00 +03:00
|
|
|
if (GetAnchorHREFAndTarget(getter_AddRefs(uri), target)) {
|
|
|
|
// 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);
|
1999-08-20 02:22:02 +04:00
|
|
|
|
2004-02-10 19:57:00 +03:00
|
|
|
PRBool clicked = PR_FALSE;
|
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) {
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeDoDefault;
|
|
|
|
clicked = PR_TRUE;
|
1999-08-20 02:22:02 +04:00
|
|
|
}
|
2004-02-10 19:57:00 +03:00
|
|
|
TriggerLink(aPresContext, uri, target, clicked);
|
1999-07-08 23:44:42 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-04-13 01:24:07 +04:00
|
|
|
default:
|
|
|
|
break;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-04-13 01:24:07 +04:00
|
|
|
|
2001-11-01 18:31:13 +03:00
|
|
|
return nsSplittableFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
1999-07-08 23:38:08 +04:00
|
|
|
//XXX This will need to be rewritten once we have content for areas
|
2003-03-19 06:47:09 +03:00
|
|
|
//XXXbz We have content for areas now....
|
1998-09-09 02:34:40 +04:00
|
|
|
NS_METHOD
|
2004-12-31 00:56:11 +03:00
|
|
|
nsImageFrame::GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2004-12-31 00:56:11 +03:00
|
|
|
nsPresContext* context = GetPresContext();
|
|
|
|
nsImageMap* map = GetImageMap(context);
|
1998-11-18 08:25:26 +03:00
|
|
|
if (nsnull != map) {
|
1999-07-08 23:38:08 +04:00
|
|
|
nsPoint p;
|
2004-12-26 22:48:54 +03:00
|
|
|
TranslateEventCoords(aPoint, p);
|
2004-12-31 00:56:11 +03:00
|
|
|
aCursor.mCursor = NS_STYLE_CURSOR_DEFAULT;
|
1999-07-08 23:38:08 +04:00
|
|
|
if (map->IsInside(p.x, p.y)) {
|
1998-11-24 01:21:13 +03:00
|
|
|
// Use style defined cursor if one is provided, otherwise when
|
|
|
|
// the cursor style is "auto" we use the pointer cursor.
|
2004-12-31 00:56:11 +03:00
|
|
|
FillCursorInformationFromStyle(GetStyleUserInterface(), aCursor);
|
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
|
|
|
|
aCursor.mCursor = NS_STYLE_CURSOR_POINTER;
|
1998-11-24 01:21:13 +03:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1998-11-18 08:25:26 +03:00
|
|
|
return NS_OK;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
2004-12-31 00:56:11 +03:00
|
|
|
return nsFrame::GetCursor(aPoint, aCursor);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-09-07 20:49:21 +04:00
|
|
|
nsImageFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
1998-11-20 20:21:02 +03:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-12 01:16:12 +04:00
|
|
|
PRInt32 aModType)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2005-09-07 20:49:21 +04:00
|
|
|
nsresult rv = nsSplittableFrame::AttributeChanged(aNameSpaceID,
|
2004-12-31 04:13:27 +03:00
|
|
|
aAttribute, aModType);
|
2004-09-30 23:23:40 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
1998-09-29 01:22:31 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2004-09-30 23:23:40 +04:00
|
|
|
if (nsHTMLAtoms::alt == aAttribute)
|
|
|
|
{
|
2000-04-17 18:40:46 +04:00
|
|
|
mState |= NS_FRAME_IS_DIRTY;
|
2004-12-31 04:13:27 +03:00
|
|
|
mParent->ReflowDirtyChild(GetPresContext()->PresShell(), (nsIFrame*) this);
|
2000-04-17 18:40:46 +04:00
|
|
|
}
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1998-09-25 20:35:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsImageFrame::GetType() const
|
1999-08-31 07:09:40 +04:00
|
|
|
{
|
2003-10-31 23:19:18 +03:00
|
|
|
return nsLayoutAtoms::imageFrame;
|
1999-08-31 07:09:40 +04:00
|
|
|
}
|
|
|
|
|
2001-10-31 07:43:48 +03:00
|
|
|
#ifdef DEBUG
|
2005-05-09 21:46:06 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ImageFrame"), aResult);
|
|
|
|
}
|
|
|
|
|
2001-10-31 07:43:48 +03:00
|
|
|
NS_IMETHODIMP
|
2005-09-07 01:34:50 +04:00
|
|
|
nsImageFrame::List(FILE* out, PRInt32 aIndent) const
|
2001-10-31 07:43:48 +03:00
|
|
|
{
|
|
|
|
IndentBy(out, aIndent);
|
|
|
|
ListTag(out);
|
|
|
|
#ifdef DEBUG_waterson
|
|
|
|
fprintf(out, " [parent=%p]", mParent);
|
|
|
|
#endif
|
2003-06-20 03:44:01 +04:00
|
|
|
if (HasView()) {
|
2003-06-29 07:43:05 +04:00
|
|
|
fprintf(out, " [view=%p]", GetView());
|
2001-10-31 07:43:48 +03:00
|
|
|
}
|
|
|
|
fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width,
|
|
|
|
mRect.height);
|
|
|
|
if (0 != mState) {
|
|
|
|
fprintf(out, " [state=%08x]", mState);
|
|
|
|
}
|
|
|
|
fprintf(out, " [content=%p]", mContent);
|
|
|
|
|
|
|
|
// output the img src url
|
2003-03-19 06:47:09 +03:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader) {
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
if (currentRequest) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
currentRequest->GetURI(getter_AddRefs(uri));
|
|
|
|
nsCAutoString uristr;
|
|
|
|
uri->GetAsciiSpec(uristr);
|
|
|
|
fprintf(out, " [src=%s]", uristr.get());
|
|
|
|
}
|
2002-03-21 01:14:27 +03:00
|
|
|
}
|
2001-10-31 07:43:48 +03:00
|
|
|
fputs("\n", out);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-01-04 06:06:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::GetIntrinsicImageSize(nsSize& aSize)
|
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
aSize = mIntrinsicSize;
|
2000-01-04 06:06:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-07 22:02:13 +04:00
|
|
|
nsresult
|
2003-03-19 06:47:09 +03:00
|
|
|
nsImageFrame::LoadIcon(const nsAString& aSpec,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext *aPresContext,
|
2003-03-19 06:47:09 +03:00
|
|
|
imgIRequest** aRequest)
|
2001-05-04 10:29:59 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2003-03-19 06:47:09 +03:00
|
|
|
NS_PRECONDITION(!aSpec.IsEmpty(), "What happened??");
|
2001-05-04 10:29:59 +04:00
|
|
|
|
2004-01-21 12:35:59 +03:00
|
|
|
if (!sIOService) {
|
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|
|
|
rv = CallGetService(kIOServiceCID, &sIOService);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2001-06-06 00:22:52 +04:00
|
|
|
nsCOMPtr<nsIURI> realURI;
|
2004-01-21 12:35:59 +03:00
|
|
|
SpecToURI(aSpec, sIOService, getter_AddRefs(realURI));
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2001-05-04 10:29:59 +04: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 06:47:09 +03:00
|
|
|
// For icon loads, we don't need to merge with the loadgroup flags
|
2001-09-29 21:50:15 +04:00
|
|
|
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
|
|
|
|
|
2003-03-19 06:47:09 +03: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) */
|
|
|
|
loadGroup,
|
|
|
|
mListener,
|
|
|
|
nsnull, /* Not associated with any particular document */
|
|
|
|
loadFlags,
|
|
|
|
nsnull,
|
|
|
|
nsnull,
|
|
|
|
aRequest);
|
2001-05-04 10:29:59 +04:00
|
|
|
}
|
|
|
|
|
2002-03-13 01:26:11 +03:00
|
|
|
void
|
2003-06-17 20:40:34 +04:00
|
|
|
nsImageFrame::GetDocumentCharacterSet(nsACString& aCharset) const
|
2002-03-13 01:26:11 +03:00
|
|
|
{
|
2003-07-29 01:25:13 +04:00
|
|
|
if (mContent) {
|
|
|
|
NS_ASSERTION(mContent->GetDocument(),
|
|
|
|
"Frame still alive after content removed from document!");
|
2003-10-22 10:09:48 +04:00
|
|
|
aCharset = mContent->GetDocument()->GetDocumentCharacterSet();
|
2002-03-13 01:26:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
void
|
2003-03-19 06:47:09 +03:00
|
|
|
nsImageFrame::SpecToURI(const nsAString& aSpec, nsIIOService *aIOService,
|
2002-11-06 15:58:05 +03:00
|
|
|
nsIURI **aURI)
|
2001-05-04 10:29:59 +04:00
|
|
|
{
|
2001-04-15 06:13:49 +04:00
|
|
|
nsCOMPtr<nsIURI> baseURI;
|
2003-07-03 06:45:34 +04:00
|
|
|
if (mContent) {
|
2004-01-10 02:54:21 +03:00
|
|
|
baseURI = mContent->GetBaseURI();
|
2003-07-03 06:45:34 +04:00
|
|
|
}
|
2003-06-17 20:40:34 +04:00
|
|
|
nsCAutoString charset;
|
2002-03-13 01:26:11 +03:00
|
|
|
GetDocumentCharacterSet(charset);
|
|
|
|
NS_NewURI(aURI, aSpec,
|
2003-06-17 20:40:34 +04:00
|
|
|
charset.IsEmpty() ? nsnull : charset.get(),
|
2002-11-06 15:58:05 +03:00
|
|
|
baseURI, aIOService);
|
2001-04-15 06:13:49 +04:00
|
|
|
}
|
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGroup)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
if (!aPresContext)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull != aLoadGroup, "null OUT parameter pointer");
|
|
|
|
|
2003-12-21 08:36:36 +03:00
|
|
|
nsIPresShell *shell = aPresContext->GetPresShell();
|
2001-03-22 04:38:35 +03:00
|
|
|
|
|
|
|
if (!shell)
|
|
|
|
return;
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = shell->GetDocument();
|
2001-03-22 04:38:35 +03:00
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
2003-10-22 10:09:48 +04:00
|
|
|
*aLoadGroup = doc->GetDocumentLoadGroup().get(); // already_AddRefed
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsresult nsImageFrame::LoadIcons(nsPresContext *aPresContext)
|
2001-11-07 08:02:42 +03:00
|
|
|
{
|
2004-02-03 23:30:02 +03:00
|
|
|
NS_ASSERTION(!gIconLoad, "called LoadIcons twice");
|
|
|
|
|
2003-09-13 21:55:56 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(loadingSrc,"resource://gre/res/loading-image.gif");
|
|
|
|
NS_NAMED_LITERAL_STRING(brokenSrc,"resource://gre/res/broken-image.gif");
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
gIconLoad = new IconLoad(mListener);
|
|
|
|
if (!gIconLoad)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(gIconLoad);
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2003-03-19 06:47:09 +03:00
|
|
|
nsresult rv;
|
|
|
|
// create a loader and load the images
|
|
|
|
rv = LoadIcon(loadingSrc,
|
|
|
|
aPresContext,
|
2004-02-03 23:30:02 +03:00
|
|
|
getter_AddRefs(gIconLoad->mLoadingImage));
|
2001-11-07 08:02:42 +03:00
|
|
|
#ifdef NOISY_ICON_LOADING
|
2003-03-19 06:47:09 +03:00
|
|
|
printf("Loading request %p, rv=%u\n",
|
2004-02-03 23:30:02 +03:00
|
|
|
gIconLoad->mLoadingImage.get(), rv);
|
2001-11-07 08:02:42 +03:00
|
|
|
#endif
|
2003-03-19 06:47:09 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = LoadIcon(brokenSrc,
|
|
|
|
aPresContext,
|
2004-02-03 23:30:02 +03:00
|
|
|
getter_AddRefs(gIconLoad->mBrokenImage));
|
2001-11-07 08:02:42 +03:00
|
|
|
#ifdef NOISY_ICON_LOADING
|
2003-03-19 06:47:09 +03:00
|
|
|
printf("Loading request %p, rv=%u\n",
|
2004-02-03 23:30:02 +03:00
|
|
|
gIconLoad->mBrokenImage.get(), rv);
|
2001-11-07 08:02:42 +03:00
|
|
|
#endif
|
2003-03-19 06:47:09 +03:00
|
|
|
|
|
|
|
// ImageLoader will callback into OnStartContainer, which will
|
|
|
|
// handle the mIconsLoaded flag
|
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsImageFrame::HandleIconLoads(imgIRequest* aRequest, PRBool aLoaded)
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
if (gIconLoad) {
|
2001-11-07 08:02:42 +03:00
|
|
|
// check which image it is
|
2004-02-03 23:30:02 +03:00
|
|
|
if (aRequest == gIconLoad->mLoadingImage ||
|
|
|
|
aRequest == gIconLoad->mBrokenImage) {
|
2001-11-07 08:02:42 +03:00
|
|
|
result = PR_TRUE;
|
2004-02-03 23:30:02 +03:00
|
|
|
if (aLoaded && (++gIconLoad->mIconsLoaded == 2))
|
|
|
|
gIconLoad->mLoadObserver = nsnull;
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NOISY_ICON_LOADING
|
2004-02-03 23:30:02 +03:00
|
|
|
if (gIconLoad->mIconsLoaded && result) {
|
2003-03-19 06:47:09 +03:00
|
|
|
printf( "Icons Loaded: request for %s\n",
|
2004-02-03 23:30:02 +03:00
|
|
|
aRequest == gIconLoad->mLoadingImage
|
|
|
|
? "mLoadingImage" : "mBrokenImage" );
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2003-03-19 06:47:09 +03:00
|
|
|
|
2001-11-07 08:02:42 +03:00
|
|
|
#ifdef NOISY_ICON_LOADING
|
|
|
|
printf( "HandleIconLoads returned %s (%p)\n", result ? "TRUE" : "FALSE", this);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
NS_IMPL_ISUPPORTS1(nsImageFrame::IconLoad, nsIObserver)
|
|
|
|
|
|
|
|
static const char kIconLoadPrefs[][40] = {
|
|
|
|
"browser.display.force_inline_alttext",
|
|
|
|
"browser.display.show_image_placeholders"
|
|
|
|
};
|
|
|
|
|
|
|
|
nsImageFrame::IconLoad::IconLoad(imgIDecoderObserver *aObserver)
|
|
|
|
: mLoadObserver(aObserver),
|
|
|
|
mIconsLoaded(0)
|
|
|
|
{
|
2005-02-25 23:46:35 +03:00
|
|
|
nsCOMPtr<nsIPrefBranch2> prefBranch =
|
2004-04-30 03:34:19 +04:00
|
|
|
do_QueryInterface(nsContentUtils::GetPrefBranch());
|
2004-02-03 23:30:02 +03:00
|
|
|
|
|
|
|
// register observers
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kIconLoadPrefs); ++i)
|
2004-04-30 03:34:19 +04:00
|
|
|
prefBranch->AddObserver(kIconLoadPrefs[i], this, PR_FALSE);
|
2004-02-03 23:30:02 +03:00
|
|
|
|
2004-04-30 03:34:19 +04:00
|
|
|
GetPrefs();
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
|
|
|
|
2004-02-03 23:30:02 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageFrame::IconLoad::Observe(nsISupports *aSubject, const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
2001-11-07 08:02:42 +03:00
|
|
|
{
|
2004-02-03 23:30:02 +03:00
|
|
|
NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
|
|
|
|
"wrong topic");
|
|
|
|
#ifdef DEBUG
|
|
|
|
// assert |aData| is one of our prefs.
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kIconLoadPrefs) ||
|
|
|
|
(NS_NOTREACHED("wrong pref"), PR_FALSE); ++i)
|
|
|
|
if (NS_ConvertASCIItoUTF16(kIconLoadPrefs[i]) == nsDependentString(aData))
|
|
|
|
break;
|
|
|
|
#endif
|
2001-11-07 08:02:42 +03:00
|
|
|
|
2004-04-30 03:34:19 +04:00
|
|
|
GetPrefs();
|
2004-02-03 23:30:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-30 03:34:19 +04:00
|
|
|
void nsImageFrame::IconLoad::GetPrefs()
|
2004-02-03 23:30:02 +03:00
|
|
|
{
|
2004-04-30 03:34:19 +04:00
|
|
|
mPrefForceInlineAltText =
|
|
|
|
nsContentUtils::GetBoolPref("browser.display.force_inline_alttext");
|
|
|
|
|
|
|
|
mPrefShowPlaceholders =
|
|
|
|
nsContentUtils::GetBoolPref("browser.display.show_image_placeholders",
|
|
|
|
PR_TRUE);
|
2001-11-07 08:02:42 +03:00
|
|
|
}
|
2001-04-15 06:13:49 +04:00
|
|
|
|
2001-03-22 04:38:35 +03:00
|
|
|
NS_IMPL_ISUPPORTS2(nsImageListener, imgIDecoderObserver, imgIContainerObserver)
|
|
|
|
|
2001-04-15 06:13:49 +04:00
|
|
|
nsImageListener::nsImageListener(nsImageFrame *aFrame) :
|
|
|
|
mFrame(aFrame)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageListener::~nsImageListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_IMETHODIMP nsImageListener::OnStartDecode(imgIRequest *aRequest)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
// Not useful to us yet.
|
|
|
|
return NS_OK;
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_IMETHODIMP nsImageListener::OnStartContainer(imgIRequest *aRequest,
|
|
|
|
imgIContainer *aImage)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
return mFrame->OnStartContainer(aRequest, aImage);
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_IMETHODIMP nsImageListener::OnStartFrame(imgIRequest *aRequest,
|
|
|
|
gfxIImageFrame *aFrame)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
// Not useful to us yet.
|
|
|
|
return NS_OK;
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_IMETHODIMP nsImageListener::OnDataAvailable(imgIRequest *aRequest,
|
|
|
|
gfxIImageFrame *aFrame,
|
|
|
|
const nsRect *aRect)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
return mFrame->OnDataAvailable(aRequest, aFrame, aRect);
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_IMETHODIMP nsImageListener::OnStopFrame(imgIRequest *aRequest,
|
|
|
|
gfxIImageFrame *aFrame)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
// Not useful to us yet.
|
|
|
|
return NS_OK;
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_IMETHODIMP nsImageListener::OnStopContainer(imgIRequest *aRequest,
|
|
|
|
imgIContainer *aImage)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
2003-03-19 06:47:09 +03:00
|
|
|
// Not useful to us yet.
|
|
|
|
return NS_OK;
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_IMETHODIMP nsImageListener::OnStopDecode(imgIRequest *aRequest,
|
|
|
|
nsresult status,
|
|
|
|
const PRUnichar *statusArg)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
return mFrame->OnStopDecode(aRequest, status, statusArg);
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
NS_IMETHODIMP nsImageListener::FrameChanged(imgIContainer *aContainer,
|
|
|
|
gfxIImageFrame *newframe,
|
|
|
|
nsRect * dirtyRect)
|
2001-03-22 04:38:35 +03:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-02-26 08:51:32 +03:00
|
|
|
return mFrame->FrameChanged(aContainer, newframe, dirtyRect);
|
2001-03-22 04:38:35 +03:00
|
|
|
}
|
|
|
|
|