2003-01-05 08:05:17 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2006-04-18 03:16:46 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2003-01-05 08:05:17 +03:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2003-01-05 08:05:17 +03: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/
|
2003-01-05 08:05:17 +03: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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2003-01-05 08:05:17 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* Contributor(s):
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
* L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
|
2007-07-04 05:13:07 +04:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2003-01-05 08:05:17 +03:00
|
|
|
*
|
|
|
|
* 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"),
|
2003-01-05 08:05:17 +03: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
|
2003-01-05 08:05:17 +03: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.
|
2003-01-05 08:05:17 +03:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsLayoutUtils.h"
|
2006-07-06 14:43:51 +04:00
|
|
|
#include "nsIFontMetrics.h"
|
2005-12-13 02:53:06 +03:00
|
|
|
#include "nsIFormControlFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-01-05 08:05:17 +03:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsFrameList.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2003-04-22 03:06:40 +04:00
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
2008-02-27 12:26:15 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2003-10-15 04:49:03 +04:00
|
|
|
#include "nsIView.h"
|
2004-08-06 19:55:17 +04:00
|
|
|
#include "nsIScrollableView.h"
|
2004-09-13 17:35:46 +04:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2004-09-21 08:41:08 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2005-02-08 05:15:26 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2005-06-02 13:00:48 +04:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsGUIEvent.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsRegion.h"
|
2006-10-19 05:47:47 +04:00
|
|
|
#include "nsFrameManager.h"
|
2007-01-17 05:37:19 +03:00
|
|
|
#include "nsBlockFrame.h"
|
2007-01-23 05:58:55 +03:00
|
|
|
#include "nsBidiPresUtils.h"
|
2007-03-20 03:58:20 +03:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "gfxRect.h"
|
2007-05-15 09:15:45 +04:00
|
|
|
#include "gfxContext.h"
|
2007-07-26 13:47:43 +04:00
|
|
|
#include "gfxFont.h"
|
2007-03-20 03:58:20 +03:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2007-05-10 19:46:42 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2007-07-26 13:47:43 +04:00
|
|
|
#include "nsContentUtils.h"
|
2008-08-13 04:44:14 +04:00
|
|
|
#include "nsThemeConstants.h"
|
2008-07-26 20:14:49 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIWidget.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxTypes.h"
|
2008-10-01 07:01:53 +04:00
|
|
|
#include "gfxUserFontSet.h"
|
2009-02-03 17:42:18 +03:00
|
|
|
#include "nsTArray.h"
|
2009-03-08 22:01:02 +03:00
|
|
|
#include "nsTextFragment.h"
|
2009-06-26 00:30:56 +04:00
|
|
|
#include "nsICanvasElement.h"
|
|
|
|
#include "nsICanvasRenderingContextInternal.h"
|
|
|
|
#include "gfxPlatform.h"
|
2009-09-25 01:01:48 +04:00
|
|
|
#include "nsClientRect.h"
|
2009-07-02 13:57:35 +04:00
|
|
|
#ifdef MOZ_MEDIA
|
2009-06-26 00:30:56 +04:00
|
|
|
#include "nsHTMLVideoElement.h"
|
2009-07-02 13:57:35 +04:00
|
|
|
#endif
|
2009-06-26 00:30:56 +04:00
|
|
|
#include "imgIRequest.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsIImageLoadingContent.h"
|
2009-09-01 20:40:49 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2006-02-21 04:24:42 +03:00
|
|
|
|
2008-02-27 12:26:15 +03:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
#include "nsSVGUtils.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2006-02-21 03:33:27 +03:00
|
|
|
#include "nsSVGForeignObjectFrame.h"
|
2006-06-15 23:10:28 +04:00
|
|
|
#include "nsSVGOuterSVGFrame.h"
|
2006-02-21 04:24:42 +03:00
|
|
|
#endif
|
2003-01-05 08:05:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A namespace class for static layout utilities.
|
|
|
|
*/
|
|
|
|
|
2008-01-30 07:53:46 +03:00
|
|
|
PRBool nsLayoutUtils::sDisableGetUsedXAssertions = PR_FALSE;
|
2008-01-27 11:13:19 +03:00
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetLastContinuationWithChild(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
aFrame = aFrame->GetLastContinuation();
|
|
|
|
while (!aFrame->GetFirstChild(nsnull) &&
|
|
|
|
aFrame->GetPrevContinuation()) {
|
|
|
|
aFrame = aFrame->GetPrevContinuation();
|
|
|
|
}
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
2003-01-05 08:05:17 +03:00
|
|
|
/**
|
|
|
|
* GetFirstChildFrame returns the first "real" child frame of a
|
|
|
|
* given frame. It will descend down into pseudo-frames (unless the
|
|
|
|
* pseudo-frame is the :before generated frame).
|
|
|
|
* @param aFrame the frame
|
|
|
|
* @param aFrame the frame's content node
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
2005-02-18 09:06:47 +03:00
|
|
|
GetFirstChildFrame(nsIFrame* aFrame,
|
2003-01-05 08:05:17 +03:00
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
|
|
|
// Get the first child frame
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = aFrame->GetFirstChild(nsnull);
|
2003-01-05 08:05:17 +03:00
|
|
|
|
|
|
|
// If the child frame is a pseudo-frame, then return its first child.
|
|
|
|
// Note that the frame we create for the generated content is also a
|
|
|
|
// pseudo-frame and so don't drill down in that case
|
|
|
|
if (childFrame &&
|
|
|
|
childFrame->IsPseudoFrame(aContent) &&
|
|
|
|
!childFrame->IsGeneratedContentFrame()) {
|
2005-02-18 09:06:47 +03:00
|
|
|
return GetFirstChildFrame(childFrame, aContent);
|
2003-01-05 08:05:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return childFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetLastChildFrame returns the last "real" child frame of a
|
|
|
|
* given frame. It will descend down into pseudo-frames (unless the
|
|
|
|
* pseudo-frame is the :after generated frame).
|
|
|
|
* @param aFrame the frame
|
|
|
|
* @param aFrame the frame's content node
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
2005-02-18 09:06:47 +03:00
|
|
|
GetLastChildFrame(nsIFrame* aFrame,
|
2003-01-05 08:05:17 +03:00
|
|
|
nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
2008-01-27 11:13:19 +03:00
|
|
|
// Get the last continuation frame that's a parent
|
|
|
|
nsIFrame* lastParentContinuation = nsLayoutUtils::GetLastContinuationWithChild(aFrame);
|
2003-01-05 08:05:17 +03:00
|
|
|
|
2009-09-18 15:09:36 +04:00
|
|
|
nsIFrame* lastChildFrame = lastParentContinuation->GetLastChild(nsnull);
|
|
|
|
if (lastChildFrame) {
|
2007-01-17 21:53:11 +03:00
|
|
|
// Get the frame's first continuation. This matters in case the frame has
|
|
|
|
// been continued across multiple lines or split by BiDi resolution.
|
|
|
|
lastChildFrame = lastChildFrame->GetFirstContinuation();
|
2003-01-16 05:59:04 +03:00
|
|
|
|
2003-01-05 08:05:17 +03:00
|
|
|
// If the last child frame is a pseudo-frame, then return its last child.
|
|
|
|
// Note that the frame we create for the generated content is also a
|
|
|
|
// pseudo-frame and so don't drill down in that case
|
|
|
|
if (lastChildFrame &&
|
|
|
|
lastChildFrame->IsPseudoFrame(aContent) &&
|
|
|
|
!lastChildFrame->IsGeneratedContentFrame()) {
|
2005-02-18 09:06:47 +03:00
|
|
|
return GetLastChildFrame(lastChildFrame, aContent);
|
2003-01-05 08:05:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return lastChildFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIFrame*
|
2005-02-18 09:06:47 +03:00
|
|
|
nsLayoutUtils::GetBeforeFrame(nsIFrame* aFrame)
|
2003-01-05 08:05:17 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
2007-01-17 21:53:11 +03:00
|
|
|
NS_ASSERTION(!aFrame->GetPrevContinuation(),
|
|
|
|
"aFrame must be first continuation");
|
2003-01-05 08:05:17 +03:00
|
|
|
|
2005-02-18 09:06:47 +03:00
|
|
|
nsIFrame* firstFrame = GetFirstChildFrame(aFrame, aFrame->GetContent());
|
2003-01-05 08:05:17 +03:00
|
|
|
|
2003-04-22 03:06:40 +04:00
|
|
|
if (firstFrame && IsGeneratedContentFor(nsnull, firstFrame,
|
|
|
|
nsCSSPseudoElements::before)) {
|
2003-01-05 08:05:17 +03:00
|
|
|
return firstFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIFrame*
|
2005-02-18 09:06:47 +03:00
|
|
|
nsLayoutUtils::GetAfterFrame(nsIFrame* aFrame)
|
2003-01-05 08:05:17 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "NULL frame pointer");
|
|
|
|
|
2005-02-18 09:06:47 +03:00
|
|
|
nsIFrame* lastFrame = GetLastChildFrame(aFrame, aFrame->GetContent());
|
2003-01-05 08:05:17 +03:00
|
|
|
|
2003-04-22 03:06:40 +04:00
|
|
|
if (lastFrame && IsGeneratedContentFor(nsnull, lastFrame,
|
|
|
|
nsCSSPseudoElements::after)) {
|
2003-01-05 08:05:17 +03:00
|
|
|
return lastFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
2003-02-23 05:49:22 +03:00
|
|
|
|
2003-04-22 03:06:40 +04:00
|
|
|
// static
|
2003-02-23 05:49:22 +03:00
|
|
|
nsIFrame*
|
2007-07-04 05:13:07 +04:00
|
|
|
nsLayoutUtils::GetClosestFrameOfType(nsIFrame* aFrame, nsIAtom* aFrameType)
|
2003-02-23 05:49:22 +03:00
|
|
|
{
|
2003-07-02 14:30:00 +04:00
|
|
|
for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) {
|
2007-07-04 05:13:07 +04:00
|
|
|
if (frame->GetType() == aFrameType) {
|
2003-02-23 05:49:22 +03:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
2003-04-22 03:06:40 +04:00
|
|
|
|
2004-09-13 17:35:46 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetFloatFromPlaceholder(nsIFrame* aFrame) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::placeholderFrame != aFrame->GetType()) {
|
2004-09-13 17:35:46 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *outOfFlowFrame =
|
2005-04-14 19:30:35 +04:00
|
|
|
nsPlaceholderFrame::GetRealFrameForPlaceholder(aFrame);
|
|
|
|
if (outOfFlowFrame->GetStyleDisplay()->IsFloating()) {
|
2004-09-13 17:35:46 +04:00
|
|
|
return outOfFlowFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2003-04-22 03:06:40 +04:00
|
|
|
// static
|
|
|
|
PRBool
|
|
|
|
nsLayoutUtils::IsGeneratedContentFor(nsIContent* aContent,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPseudoElement)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Must have a frame");
|
|
|
|
NS_PRECONDITION(aPseudoElement, "Must have a pseudo name");
|
|
|
|
|
|
|
|
if (!aFrame->IsGeneratedContentFrame()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-08-18 05:16:42 +04:00
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
NS_ASSERTION(parent, "Generated content can't be root frame");
|
|
|
|
if (parent->IsGeneratedContentFrame()) {
|
|
|
|
// Not the root of the generated content
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2003-10-31 23:19:18 +03:00
|
|
|
|
2008-08-18 05:16:42 +04:00
|
|
|
if (aContent && parent->GetContent() != aContent) {
|
2003-07-02 14:30:00 +04:00
|
|
|
return PR_FALSE;
|
2003-04-22 03:06:40 +04:00
|
|
|
}
|
|
|
|
|
2008-08-18 05:16:42 +04:00
|
|
|
return (aFrame->GetContent()->Tag() == nsGkAtoms::mozgeneratedcontentbefore) ==
|
|
|
|
(aPseudoElement == nsCSSPseudoElements::before);
|
2003-04-22 03:06:40 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// static
|
|
|
|
nsIFrame*
|
2008-09-04 01:35:52 +04:00
|
|
|
nsLayoutUtils::GetCrossDocParentFrame(const nsIFrame* aFrame,
|
|
|
|
nsPoint* aExtraOffset)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
|
|
|
nsIFrame* p = aFrame->GetParent();
|
|
|
|
if (p)
|
|
|
|
return p;
|
|
|
|
|
|
|
|
nsIView* v = aFrame->GetView();
|
|
|
|
if (!v)
|
|
|
|
return nsnull;
|
|
|
|
v = v->GetParent(); // anonymous inner view
|
|
|
|
if (!v)
|
|
|
|
return nsnull;
|
2008-09-04 01:35:52 +04:00
|
|
|
if (aExtraOffset) {
|
|
|
|
*aExtraOffset += v->GetPosition();
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
v = v->GetParent(); // subdocumentframe's view
|
|
|
|
if (!v)
|
|
|
|
return nsnull;
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsIFrame*>(v->GetClientData());
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
PRBool
|
|
|
|
nsLayoutUtils::IsProperAncestorFrameCrossDoc(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
|
|
|
if (aFrame == aCommonAncestor)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* parentFrame = GetCrossDocParentFrame(aFrame);
|
|
|
|
|
|
|
|
while (parentFrame != aCommonAncestor) {
|
|
|
|
if (parentFrame == aAncestorFrame)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
parentFrame = GetCrossDocParentFrame(parentFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2009-07-22 04:44:56 +04:00
|
|
|
// static
|
|
|
|
PRBool
|
|
|
|
nsLayoutUtils::IsAncestorFrameCrossDoc(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
|
|
|
if (aFrame == aAncestorFrame)
|
|
|
|
return PR_TRUE;
|
|
|
|
return IsProperAncestorFrameCrossDoc(aAncestorFrame, aFrame, aCommonAncestor);
|
|
|
|
}
|
|
|
|
|
2003-10-15 04:49:03 +04:00
|
|
|
// static
|
|
|
|
PRBool
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
|
|
|
if (aFrame == aCommonAncestor) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* parentFrame = aFrame->GetParent();
|
|
|
|
|
|
|
|
while (parentFrame != aCommonAncestor) {
|
|
|
|
if (parentFrame == aAncestorFrame) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
parentFrame = parentFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
PRInt32
|
2004-04-13 01:53:22 +04:00
|
|
|
nsLayoutUtils::DoCompareTreePosition(nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2,
|
|
|
|
PRInt32 aIf1Ancestor,
|
|
|
|
PRInt32 aIf2Ancestor,
|
2009-09-18 22:52:27 +04:00
|
|
|
const nsIContent* aCommonAncestor)
|
2004-04-13 01:53:22 +04:00
|
|
|
{
|
2003-10-15 04:49:03 +04:00
|
|
|
NS_PRECONDITION(aContent1, "aContent1 must not be null");
|
|
|
|
NS_PRECONDITION(aContent2, "aContent2 must not be null");
|
|
|
|
|
2007-11-11 23:35:30 +03:00
|
|
|
nsAutoTArray<nsINode*, 32> content1Ancestors;
|
2006-05-16 19:50:47 +04:00
|
|
|
nsINode* c1;
|
|
|
|
for (c1 = aContent1; c1 && c1 != aCommonAncestor; c1 = c1->GetNodeParent()) {
|
2003-10-17 18:10:02 +04:00
|
|
|
content1Ancestors.AppendElement(c1);
|
|
|
|
}
|
|
|
|
if (!c1 && aCommonAncestor) {
|
|
|
|
// So, it turns out aCommonAncestor was not an ancestor of c1. Oops.
|
|
|
|
// Never mind. We can continue as if aCommonAncestor was null.
|
|
|
|
aCommonAncestor = nsnull;
|
|
|
|
}
|
2003-10-15 04:49:03 +04:00
|
|
|
|
2007-11-11 23:35:30 +03:00
|
|
|
nsAutoTArray<nsINode*, 32> content2Ancestors;
|
2006-05-16 19:50:47 +04:00
|
|
|
nsINode* c2;
|
|
|
|
for (c2 = aContent2; c2 && c2 != aCommonAncestor; c2 = c2->GetNodeParent()) {
|
2003-10-17 18:10:02 +04:00
|
|
|
content2Ancestors.AppendElement(c2);
|
2003-10-15 04:49:03 +04:00
|
|
|
}
|
2003-10-17 18:10:02 +04:00
|
|
|
if (!c2 && aCommonAncestor) {
|
|
|
|
// So, it turns out aCommonAncestor was not an ancestor of c2.
|
|
|
|
// We need to retry with no common ancestor hint.
|
2004-04-13 01:53:22 +04:00
|
|
|
return DoCompareTreePosition(aContent1, aContent2,
|
|
|
|
aIf1Ancestor, aIf2Ancestor, nsnull);
|
2003-10-15 04:49:03 +04:00
|
|
|
}
|
|
|
|
|
2007-11-11 23:35:30 +03:00
|
|
|
int last1 = content1Ancestors.Length() - 1;
|
|
|
|
int last2 = content2Ancestors.Length() - 1;
|
2006-05-16 19:50:47 +04:00
|
|
|
nsINode* content1Ancestor = nsnull;
|
|
|
|
nsINode* content2Ancestor = nsnull;
|
2003-10-15 04:49:03 +04:00
|
|
|
while (last1 >= 0 && last2 >= 0
|
2007-11-11 23:35:30 +03:00
|
|
|
&& ((content1Ancestor = content1Ancestors.ElementAt(last1)) ==
|
|
|
|
(content2Ancestor = content2Ancestors.ElementAt(last2)))) {
|
2003-10-15 04:49:03 +04:00
|
|
|
last1--;
|
|
|
|
last2--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last1 < 0) {
|
|
|
|
if (last2 < 0) {
|
|
|
|
NS_ASSERTION(aContent1 == aContent2, "internal error?");
|
|
|
|
return 0;
|
|
|
|
}
|
2006-05-16 19:50:47 +04:00
|
|
|
// aContent1 is an ancestor of aContent2
|
|
|
|
return aIf1Ancestor;
|
2003-10-15 04:49:03 +04:00
|
|
|
}
|
2006-05-16 19:50:47 +04:00
|
|
|
|
|
|
|
if (last2 < 0) {
|
|
|
|
// aContent2 is an ancestor of aContent1
|
|
|
|
return aIf2Ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// content1Ancestor != content2Ancestor, so they must be siblings with the same parent
|
|
|
|
nsINode* parent = content1Ancestor->GetNodeParent();
|
|
|
|
NS_ASSERTION(parent, "no common ancestor at all???");
|
|
|
|
if (!parent) { // different documents??
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 index1 = parent->IndexOf(content1Ancestor);
|
|
|
|
PRInt32 index2 = parent->IndexOf(content2Ancestor);
|
|
|
|
if (index1 < 0 || index2 < 0) {
|
|
|
|
// one of them must be anonymous; we can't determine the order
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index1 - index2;
|
2003-10-15 04:49:03 +04:00
|
|
|
}
|
|
|
|
|
2007-01-18 01:48:24 +03:00
|
|
|
static nsIFrame* FillAncestors(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aStopAtAncestor, nsFrameManager* aFrameManager,
|
|
|
|
nsTArray<nsIFrame*>* aAncestors)
|
|
|
|
{
|
|
|
|
while (aFrame && aFrame != aStopAtAncestor) {
|
|
|
|
aAncestors->AppendElement(aFrame);
|
|
|
|
aFrame = nsLayoutUtils::GetParentOrPlaceholderFor(aFrameManager, aFrame);
|
|
|
|
}
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if aFrame1 is after aFrame2
|
|
|
|
static PRBool IsFrameAfter(nsIFrame* aFrame1, nsIFrame* aFrame2)
|
|
|
|
{
|
|
|
|
nsIFrame* f = aFrame2;
|
|
|
|
do {
|
|
|
|
f = f->GetNextSibling();
|
|
|
|
if (f == aFrame1)
|
|
|
|
return PR_TRUE;
|
|
|
|
} while (f);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
PRInt32
|
|
|
|
nsLayoutUtils::DoCompareTreePosition(nsIFrame* aFrame1,
|
|
|
|
nsIFrame* aFrame2,
|
|
|
|
PRInt32 aIf1Ancestor,
|
|
|
|
PRInt32 aIf2Ancestor,
|
|
|
|
nsIFrame* aCommonAncestor)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame1, "aFrame1 must not be null");
|
|
|
|
NS_PRECONDITION(aFrame2, "aFrame2 must not be null");
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = aFrame1->PresContext();
|
|
|
|
if (presContext != aFrame2->PresContext()) {
|
2007-01-18 01:48:24 +03:00
|
|
|
NS_ERROR("no common ancestor at all, different documents");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
nsFrameManager* frameManager = presContext->PresShell()->FrameManager();
|
|
|
|
|
|
|
|
nsAutoTArray<nsIFrame*,20> frame1Ancestors;
|
|
|
|
if (!FillAncestors(aFrame1, aCommonAncestor, frameManager, &frame1Ancestors)) {
|
|
|
|
// We reached the root of the frame tree ... if aCommonAncestor was set,
|
|
|
|
// it is wrong
|
|
|
|
aCommonAncestor = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<nsIFrame*,20> frame2Ancestors;
|
|
|
|
if (!FillAncestors(aFrame2, aCommonAncestor, frameManager, &frame2Ancestors) &&
|
|
|
|
aCommonAncestor) {
|
|
|
|
// We reached the root of the frame tree ... aCommonAncestor was wrong.
|
|
|
|
// Try again with no hint.
|
|
|
|
return DoCompareTreePosition(aFrame1, aFrame2,
|
|
|
|
aIf1Ancestor, aIf2Ancestor, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 last1 = PRInt32(frame1Ancestors.Length()) - 1;
|
|
|
|
PRInt32 last2 = PRInt32(frame2Ancestors.Length()) - 1;
|
|
|
|
while (last1 >= 0 && last2 >= 0 &&
|
|
|
|
frame1Ancestors[last1] == frame2Ancestors[last2]) {
|
|
|
|
last1--;
|
|
|
|
last2--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last1 < 0) {
|
|
|
|
if (last2 < 0) {
|
|
|
|
NS_ASSERTION(aFrame1 == aFrame2, "internal error?");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// aFrame1 is an ancestor of aFrame2
|
|
|
|
return aIf1Ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last2 < 0) {
|
|
|
|
// aFrame2 is an ancestor of aFrame1
|
|
|
|
return aIf2Ancestor;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* ancestor1 = frame1Ancestors[last1];
|
|
|
|
nsIFrame* ancestor2 = frame2Ancestors[last2];
|
|
|
|
// Now we should be able to walk sibling chains to find which one is first
|
|
|
|
if (IsFrameAfter(ancestor2, ancestor1))
|
|
|
|
return -1;
|
|
|
|
if (IsFrameAfter(ancestor1, ancestor2))
|
|
|
|
return 1;
|
|
|
|
NS_WARNING("Frames were in different child lists???");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-15 04:49:03 +04:00
|
|
|
// static
|
|
|
|
nsIFrame* nsLayoutUtils::GetLastSibling(nsIFrame* aFrame) {
|
|
|
|
if (!aFrame) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* next;
|
|
|
|
while ((next = aFrame->GetNextSibling()) != nsnull) {
|
|
|
|
aFrame = next;
|
|
|
|
}
|
|
|
|
return aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsIView*
|
|
|
|
nsLayoutUtils::FindSiblingViewFor(nsIView* aParentView, nsIFrame* aFrame) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIFrame* parentViewFrame = static_cast<nsIFrame*>(aParentView->GetClientData());
|
2003-10-15 04:49:03 +04:00
|
|
|
nsIContent* parentViewContent = parentViewFrame ? parentViewFrame->GetContent() : nsnull;
|
|
|
|
for (nsIView* insertBefore = aParentView->GetFirstChild(); insertBefore;
|
|
|
|
insertBefore = insertBefore->GetNextSibling()) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIFrame* f = static_cast<nsIFrame*>(insertBefore->GetClientData());
|
2003-10-15 04:49:03 +04:00
|
|
|
if (!f) {
|
|
|
|
// this view could be some anonymous view attached to a meaningful parent
|
|
|
|
for (nsIView* searchView = insertBefore->GetParent(); searchView;
|
|
|
|
searchView = searchView->GetParent()) {
|
2007-07-08 11:08:04 +04:00
|
|
|
f = static_cast<nsIFrame*>(searchView->GetClientData());
|
2003-10-15 04:49:03 +04:00
|
|
|
if (f) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(f, "Can't find a frame anywhere!");
|
|
|
|
}
|
2005-03-24 04:15:07 +03:00
|
|
|
if (!f || !aFrame->GetContent() || !f->GetContent() ||
|
|
|
|
CompareTreePosition(aFrame->GetContent(), f->GetContent(), parentViewContent) > 0) {
|
|
|
|
// aFrame's content is after f's content (or we just don't know),
|
|
|
|
// so put our view before f's view
|
2003-10-15 04:49:03 +04:00
|
|
|
return insertBefore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
2004-08-06 19:55:17 +04:00
|
|
|
|
2004-11-03 05:52:16 +03:00
|
|
|
//static
|
|
|
|
nsIScrollableFrame*
|
|
|
|
nsLayoutUtils::GetScrollableFrameFor(nsIFrame *aScrolledFrame)
|
|
|
|
{
|
|
|
|
nsIFrame *frame = aScrolledFrame->GetParent();
|
|
|
|
if (!frame) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollableFrame *sf = do_QueryFrame(frame);
|
2004-11-03 05:52:16 +03:00
|
|
|
return sf;
|
|
|
|
}
|
|
|
|
|
2004-09-21 08:41:08 +04:00
|
|
|
//static
|
2004-10-19 06:24:27 +04:00
|
|
|
nsIScrollableFrame*
|
|
|
|
nsLayoutUtils::GetScrollableFrameFor(nsIScrollableView *aScrollableView)
|
2004-09-21 08:41:08 +04:00
|
|
|
{
|
2005-04-04 01:00:41 +04:00
|
|
|
nsIFrame *frame = GetFrameFor(aScrollableView->View()->GetParent());
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollableFrame *sf = do_QueryFrame(frame);
|
|
|
|
return sf;
|
2004-10-19 06:24:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
nsPresContext::ScrollbarStyles
|
|
|
|
nsLayoutUtils::ScrollbarStylesOfView(nsIScrollableView *aScrollableView)
|
|
|
|
{
|
|
|
|
nsIScrollableFrame *sf = GetScrollableFrameFor(aScrollableView);
|
|
|
|
return sf ? sf->GetScrollbarStyles() :
|
|
|
|
nsPresContext::ScrollbarStyles(NS_STYLE_OVERFLOW_HIDDEN,
|
|
|
|
NS_STYLE_OVERFLOW_HIDDEN);
|
2004-09-21 08:41:08 +04:00
|
|
|
}
|
|
|
|
|
2004-08-06 19:55:17 +04:00
|
|
|
// static
|
|
|
|
nsIScrollableView*
|
2004-09-21 08:41:08 +04:00
|
|
|
nsLayoutUtils::GetNearestScrollingView(nsIView* aView, Direction aDirection)
|
2004-08-06 19:55:17 +04:00
|
|
|
{
|
2004-11-19 06:49:20 +03:00
|
|
|
// If aDirection is eEither, find first view with a scrolllable frame.
|
|
|
|
// Otherwise, find the first view that has a scrollable frame whose
|
2004-10-19 06:24:27 +04:00
|
|
|
// ScrollbarStyles is not NS_STYLE_OVERFLOW_HIDDEN in aDirection
|
|
|
|
// and where there is something currently not visible
|
|
|
|
// that can be scrolled to in aDirection.
|
2004-08-06 19:55:17 +04:00
|
|
|
NS_ASSERTION(aView, "GetNearestScrollingView expects a non-null view");
|
|
|
|
nsIScrollableView* scrollableView = nsnull;
|
|
|
|
for (; aView; aView = aView->GetParent()) {
|
2004-11-24 03:19:21 +03:00
|
|
|
scrollableView = aView->ToScrollableView();
|
2004-08-06 19:55:17 +04:00
|
|
|
if (scrollableView) {
|
2004-09-21 08:41:08 +04:00
|
|
|
nsPresContext::ScrollbarStyles ss =
|
|
|
|
nsLayoutUtils::ScrollbarStylesOfView(scrollableView);
|
2004-10-19 06:24:27 +04:00
|
|
|
nsIScrollableFrame *scrollableFrame = GetScrollableFrameFor(scrollableView);
|
2005-06-27 02:22:40 +04:00
|
|
|
NS_ASSERTION(scrollableFrame, "Must have scrollable frame for view!");
|
2004-10-19 06:24:27 +04:00
|
|
|
nsMargin margin = scrollableFrame->GetActualScrollbarSizes();
|
|
|
|
// Get size of total scrollable area
|
|
|
|
nscoord totalWidth, totalHeight;
|
|
|
|
scrollableView->GetContainerSize(&totalWidth, &totalHeight);
|
|
|
|
// Get size of currently visible area
|
2005-04-04 01:00:41 +04:00
|
|
|
nsSize visibleSize = aView->GetBounds().Size();
|
2004-09-21 08:41:08 +04:00
|
|
|
// aDirection can be eHorizontal, eVertical, or eEither
|
2004-11-19 06:49:20 +03:00
|
|
|
// If scrolling in a specific direction, require visible scrollbars or
|
|
|
|
// something to scroll to in that direction.
|
2004-09-21 08:41:08 +04:00
|
|
|
if (aDirection != eHorizontal &&
|
2004-10-19 06:24:27 +04:00
|
|
|
ss.mVertical != NS_STYLE_OVERFLOW_HIDDEN &&
|
2006-03-23 03:11:01 +03:00
|
|
|
(aDirection == eEither || totalHeight > visibleSize.height || margin.LeftRight()))
|
2004-09-21 08:41:08 +04:00
|
|
|
break;
|
|
|
|
if (aDirection != eVertical &&
|
2004-10-19 06:24:27 +04:00
|
|
|
ss.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN &&
|
2006-03-23 03:11:01 +03:00
|
|
|
(aDirection == eEither || totalWidth > visibleSize.width || margin.TopBottom()))
|
2004-09-21 08:41:08 +04:00
|
|
|
break;
|
2004-08-06 19:55:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return scrollableView;
|
|
|
|
}
|
2004-11-25 17:51:00 +03:00
|
|
|
|
2005-06-02 13:00:48 +04:00
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aDOMEvent));
|
|
|
|
NS_ASSERTION(privateEvent, "bad implementation");
|
|
|
|
if (!privateEvent)
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2008-10-10 03:23:07 +04:00
|
|
|
nsEvent *event = privateEvent->GetInternalNSEvent();
|
|
|
|
if (!event)
|
2005-06-02 13:00:48 +04:00
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-08-23 07:57:07 +04:00
|
|
|
return GetEventCoordinatesRelativeTo(event, aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
2007-06-27 04:30:21 +04:00
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(const nsEvent* aEvent, nsIFrame* aFrame)
|
2005-08-23 07:57:07 +04:00
|
|
|
{
|
|
|
|
if (!aEvent || (aEvent->eventStructType != NS_MOUSE_EVENT &&
|
2008-08-27 16:07:27 +04:00
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
|
2009-01-03 15:40:26 +03:00
|
|
|
aEvent->eventStructType != NS_DRAG_EVENT &&
|
2009-05-15 04:46:24 +04:00
|
|
|
aEvent->eventStructType != NS_SIMPLE_GESTURE_EVENT &&
|
2009-08-14 00:54:09 +04:00
|
|
|
aEvent->eventStructType != NS_GESTURENOTIFY_EVENT &&
|
2009-05-15 04:46:24 +04:00
|
|
|
aEvent->eventStructType != NS_QUERY_CONTENT_EVENT))
|
2005-06-02 13:00:48 +04:00
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-08-23 07:57:07 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
const nsGUIEvent* GUIEvent = static_cast<const nsGUIEvent*>(aEvent);
|
2005-06-02 13:00:48 +04:00
|
|
|
if (!GUIEvent->widget)
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-08-23 07:57:07 +04:00
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* If we walk up the frame tree and discover that any of the frames are
|
|
|
|
* transformed, we need to do extra work to convert from the global
|
|
|
|
* space to the local space.
|
|
|
|
*/
|
2006-02-21 04:24:42 +03:00
|
|
|
nsIFrame* rootFrame = aFrame;
|
2008-09-13 13:42:11 +04:00
|
|
|
PRBool transformFound = PR_FALSE;
|
|
|
|
|
2006-02-21 03:33:27 +03:00
|
|
|
for (nsIFrame* f = aFrame; f; f = GetCrossDocParentFrame(f)) {
|
2008-09-13 13:42:11 +04:00
|
|
|
if (f->IsTransformed())
|
|
|
|
transformFound = PR_TRUE;
|
|
|
|
|
2006-02-21 03:33:27 +03:00
|
|
|
rootFrame = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* rootView = rootFrame->GetView();
|
|
|
|
if (!rootView)
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-08-23 07:57:07 +04:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPoint widgetToView = TranslateWidgetToView(rootFrame->PresContext(),
|
2005-08-23 07:57:07 +04:00
|
|
|
GUIEvent->widget, GUIEvent->refPoint,
|
2006-02-21 03:33:27 +03:00
|
|
|
rootView);
|
2005-09-15 08:03:07 +04:00
|
|
|
|
|
|
|
if (widgetToView == nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE))
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* If we encountered a transform, we can't do simple arithmetic to figure
|
|
|
|
* out how to convert back to aFrame's coordinates and must use the CTM.
|
|
|
|
*/
|
|
|
|
if (transformFound)
|
|
|
|
return InvertTransformsToRoot(aFrame, widgetToView);
|
|
|
|
|
|
|
|
/* Otherwise, all coordinate systems are translations of one another,
|
|
|
|
* so we can just subtract out the different.
|
|
|
|
*/
|
2006-02-21 03:33:27 +03:00
|
|
|
return widgetToView - aFrame->GetOffsetTo(rootFrame);
|
2005-08-23 07:57:07 +04:00
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
gfxMatrix
|
|
|
|
nsLayoutUtils::ChangeMatrixBasis(const gfxPoint &aOrigin,
|
|
|
|
const gfxMatrix &aMatrix)
|
|
|
|
{
|
|
|
|
/* These are translation matrices from world-to-origin of relative frame and
|
|
|
|
* vice-versa. Although I could use the gfxMatrix::Translate function to
|
|
|
|
* accomplish this, I'm hoping to reduce the overall number of matrix
|
|
|
|
* operations by hardcoding as many of the matrices as possible.
|
|
|
|
*/
|
|
|
|
gfxMatrix worldToOrigin(1.0, 0.0, 0.0, 1.0, -aOrigin.x, -aOrigin.y);
|
|
|
|
gfxMatrix originToWorld(1.0, 0.0, 0.0, 1.0, aOrigin.x, aOrigin.y);
|
|
|
|
|
|
|
|
/* Multiply all three to get the transform! */
|
|
|
|
gfxMatrix result(worldToOrigin);
|
|
|
|
result.Multiply(aMatrix);
|
|
|
|
result.Multiply(originToWorld);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a gfxFloat, constrains its value to be between nscoord_MIN and nscoord_MAX.
|
|
|
|
*
|
|
|
|
* @param aVal The value to constrain (in/out)
|
|
|
|
*/
|
|
|
|
static void ConstrainToCoordValues(gfxFloat &aVal)
|
|
|
|
{
|
|
|
|
if (aVal <= nscoord_MIN)
|
|
|
|
aVal = nscoord_MIN;
|
|
|
|
else if (aVal >= nscoord_MAX)
|
|
|
|
aVal = nscoord_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor)
|
|
|
|
{
|
|
|
|
/* Get a new gfxRect whose units are app units by scaling by the specified factor. */
|
|
|
|
gfxRect scaledRect(aRect.pos.x * aFactor, aRect.pos.y * aFactor,
|
|
|
|
aRect.size.width * aFactor,
|
|
|
|
aRect.size.height * aFactor);
|
|
|
|
|
|
|
|
/* Round outward. */
|
|
|
|
scaledRect.RoundOut();
|
|
|
|
|
|
|
|
/* We now need to constrain our results to the max and min values for coords. */
|
|
|
|
ConstrainToCoordValues(scaledRect.pos.x);
|
|
|
|
ConstrainToCoordValues(scaledRect.pos.y);
|
|
|
|
ConstrainToCoordValues(scaledRect.size.width);
|
|
|
|
ConstrainToCoordValues(scaledRect.size.height);
|
|
|
|
|
|
|
|
/* Now typecast everything back. This is guaranteed to be safe. */
|
|
|
|
return nsRect(nscoord(scaledRect.pos.x), nscoord(scaledRect.pos.y),
|
|
|
|
nscoord(scaledRect.size.width), nscoord(scaledRect.size.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::MatrixTransformRect(const nsRect &aBounds,
|
|
|
|
const gfxMatrix &aMatrix, float aFactor)
|
|
|
|
{
|
|
|
|
gfxRect image = aMatrix.TransformBounds(gfxRect(NSAppUnitsToFloatPixels(aBounds.x, aFactor),
|
|
|
|
NSAppUnitsToFloatPixels(aBounds.y, aFactor),
|
|
|
|
NSAppUnitsToFloatPixels(aBounds.width, aFactor),
|
|
|
|
NSAppUnitsToFloatPixels(aBounds.height, aFactor)));
|
|
|
|
|
|
|
|
return RoundGfxRectToAppRect(image, aFactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::MatrixTransformPoint(const nsPoint &aPoint,
|
|
|
|
const gfxMatrix &aMatrix, float aFactor)
|
|
|
|
{
|
|
|
|
gfxPoint image = aMatrix.Transform(gfxPoint(NSAppUnitsToFloatPixels(aPoint.x, aFactor),
|
|
|
|
NSAppUnitsToFloatPixels(aPoint.y, aFactor)));
|
|
|
|
return nsPoint(NSFloatPixelsToAppUnits(float(image.x), aFactor),
|
|
|
|
NSFloatPixelsToAppUnits(float(image.y), aFactor));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the CTM at the specified frame.
|
|
|
|
*
|
|
|
|
* @param aFrame The frame at which we should calculate the CTM.
|
|
|
|
* @return The CTM at the specified frame.
|
|
|
|
*/
|
|
|
|
static gfxMatrix GetCTMAt(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
gfxMatrix ctm;
|
|
|
|
|
|
|
|
/* Starting at the specified frame, we'll use the GetTransformMatrix
|
|
|
|
* function of the frame, which gives us a matrix from this frame up
|
|
|
|
* to some other ancestor frame. Once this function returns null,
|
|
|
|
* we've hit the top of the frame tree and can stop. We get the CTM
|
|
|
|
* by simply accumulating all of these matrices together.
|
|
|
|
*/
|
|
|
|
while (aFrame)
|
|
|
|
ctm *= aFrame->GetTransformMatrix(&aFrame);
|
|
|
|
return ctm;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::InvertTransformsToRoot(nsIFrame *aFrame,
|
|
|
|
const nsPoint &aPoint)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Why are you inverting transforms when there is no frame?");
|
|
|
|
|
|
|
|
/* To invert everything to the root, we'll get the CTM, invert it, and use it to transform
|
|
|
|
* the point.
|
|
|
|
*/
|
|
|
|
gfxMatrix ctm = GetCTMAt(aFrame);
|
|
|
|
|
|
|
|
/* If the ctm is singular, hand back (0, 0) as a sentinel. */
|
|
|
|
if (ctm.IsSingular())
|
|
|
|
return nsPoint(0, 0);
|
|
|
|
|
|
|
|
/* Otherwise, invert the CTM and use it to transform the point. */
|
|
|
|
return MatrixTransformPoint(aPoint, ctm.Invert(), aFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
}
|
|
|
|
|
2005-08-23 07:57:07 +04:00
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::GetEventCoordinatesForNearestView(nsEvent* aEvent,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIView** aView)
|
|
|
|
{
|
|
|
|
if (!aEvent || (aEvent->eventStructType != NS_MOUSE_EVENT &&
|
2008-08-27 16:07:27 +04:00
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_DRAG_EVENT))
|
2005-08-23 07:57:07 +04:00
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
nsGUIEvent* GUIEvent = static_cast<nsGUIEvent*>(aEvent);
|
2005-08-23 07:57:07 +04:00
|
|
|
if (!GUIEvent->widget)
|
2005-06-02 13:00:48 +04:00
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
|
|
|
nsPoint viewToFrame;
|
2005-08-23 07:57:07 +04:00
|
|
|
nsIView* frameView;
|
|
|
|
aFrame->GetOffsetFromView(viewToFrame, &frameView);
|
|
|
|
if (aView)
|
|
|
|
*aView = frameView;
|
2005-06-02 13:00:48 +04:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
return TranslateWidgetToView(aFrame->PresContext(), GUIEvent->widget,
|
2005-08-23 07:57:07 +04:00
|
|
|
GUIEvent->refPoint, frameView);
|
|
|
|
}
|
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
static nsIntPoint GetWidgetOffset(nsIWidget* aWidget, nsIWidget*& aRootWidget) {
|
|
|
|
nsIntPoint offset(0, 0);
|
2007-07-23 20:44:34 +04:00
|
|
|
nsIWidget* parent = aWidget->GetParent();
|
|
|
|
while (parent) {
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect bounds;
|
2007-07-23 20:44:34 +04:00
|
|
|
aWidget->GetBounds(bounds);
|
|
|
|
offset += bounds.TopLeft();
|
|
|
|
aWidget = parent;
|
|
|
|
parent = aWidget->GetParent();
|
|
|
|
}
|
|
|
|
aRootWidget = aWidget;
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2005-08-23 07:57:07 +04:00
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext,
|
|
|
|
nsIWidget* aWidget, nsIntPoint aPt,
|
|
|
|
nsIView* aView)
|
|
|
|
{
|
2007-07-23 20:44:34 +04:00
|
|
|
nsPoint viewOffset;
|
|
|
|
nsIWidget* viewWidget = aView->GetNearestWidget(&viewOffset);
|
|
|
|
|
|
|
|
nsIWidget* fromRoot;
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntPoint fromOffset = GetWidgetOffset(aWidget, fromRoot);
|
2007-07-23 20:44:34 +04:00
|
|
|
nsIWidget* toRoot;
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntPoint toOffset = GetWidgetOffset(viewWidget, toRoot);
|
2007-07-23 20:44:34 +04:00
|
|
|
|
|
|
|
nsIntPoint widgetPoint;
|
|
|
|
if (fromRoot == toRoot) {
|
|
|
|
widgetPoint = aPt + fromOffset - toOffset;
|
|
|
|
} else {
|
2009-02-19 03:11:49 +03:00
|
|
|
nsIntPoint screenPoint = aWidget->WidgetToScreenOffset();
|
|
|
|
widgetPoint = aPt + screenPoint - viewWidget->WidgetToScreenOffset();
|
2007-07-23 20:44:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint widgetAppUnits(aPresContext->DevPixelsToAppUnits(widgetPoint.x),
|
|
|
|
aPresContext->DevPixelsToAppUnits(widgetPoint.y));
|
|
|
|
return widgetAppUnits - viewOffset;
|
2005-06-02 13:00:48 +04:00
|
|
|
}
|
|
|
|
|
2004-11-25 17:51:00 +03:00
|
|
|
// Combine aNewBreakType with aOrigBreakType, but limit the break types
|
|
|
|
// to NS_STYLE_CLEAR_LEFT, RIGHT, LEFT_AND_RIGHT.
|
|
|
|
PRUint8
|
|
|
|
nsLayoutUtils::CombineBreakType(PRUint8 aOrigBreakType,
|
|
|
|
PRUint8 aNewBreakType)
|
|
|
|
{
|
|
|
|
PRUint8 breakType = aOrigBreakType;
|
|
|
|
switch(breakType) {
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
|
|
|
if ((NS_STYLE_CLEAR_RIGHT == aNewBreakType) ||
|
|
|
|
(NS_STYLE_CLEAR_LEFT_AND_RIGHT == aNewBreakType)) {
|
|
|
|
breakType = NS_STYLE_CLEAR_LEFT_AND_RIGHT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
|
|
|
if ((NS_STYLE_CLEAR_LEFT == aNewBreakType) ||
|
|
|
|
(NS_STYLE_CLEAR_LEFT_AND_RIGHT == aNewBreakType)) {
|
|
|
|
breakType = NS_STYLE_CLEAR_LEFT_AND_RIGHT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CLEAR_NONE:
|
|
|
|
if ((NS_STYLE_CLEAR_LEFT == aNewBreakType) ||
|
|
|
|
(NS_STYLE_CLEAR_RIGHT == aNewBreakType) ||
|
|
|
|
(NS_STYLE_CLEAR_LEFT_AND_RIGHT == aNewBreakType)) {
|
|
|
|
breakType = aNewBreakType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return breakType;
|
|
|
|
}
|
2005-02-08 05:15:26 +03:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2006-03-23 03:11:01 +03:00
|
|
|
static PRBool gDumpPaintList = PR_FALSE;
|
|
|
|
static PRBool gDumpEventList = PR_FALSE;
|
|
|
|
static PRBool gDumpRepaintRegionForCopy = PR_FALSE;
|
2006-01-26 05:29:17 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIFrame*
|
2007-08-30 00:38:44 +04:00
|
|
|
nsLayoutUtils::GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt,
|
2008-10-27 23:16:23 +03:00
|
|
|
PRBool aShouldIgnoreSuppression,
|
2008-11-28 22:53:33 +03:00
|
|
|
PRBool aIgnoreRootScrollFrame)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2006-04-18 03:16:46 +04:00
|
|
|
nsDisplayListBuilder builder(aFrame, PR_TRUE, PR_FALSE);
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayList list;
|
2006-04-18 03:16:46 +04:00
|
|
|
nsRect target(aPt, nsSize(1, 1));
|
|
|
|
|
2007-08-30 00:38:44 +04:00
|
|
|
if (aShouldIgnoreSuppression)
|
|
|
|
builder.IgnorePaintSuppression();
|
2008-10-27 23:16:23 +03:00
|
|
|
|
2008-11-28 22:53:33 +03:00
|
|
|
if (aIgnoreRootScrollFrame) {
|
2008-10-27 23:16:23 +03:00
|
|
|
nsIFrame* rootScrollFrame =
|
|
|
|
aFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
|
|
|
if (rootScrollFrame) {
|
|
|
|
builder.SetIgnoreScrollFrame(rootScrollFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-18 03:16:46 +04:00
|
|
|
builder.EnterPresShell(aFrame, target);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult rv =
|
2006-04-18 03:16:46 +04:00
|
|
|
aFrame->BuildDisplayListForStackingContext(&builder, target, &list);
|
|
|
|
|
|
|
|
builder.LeavePresShell(aFrame, target);
|
2006-01-26 05:29:17 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpEventList) {
|
|
|
|
fprintf(stderr, "Event handling --- (%d,%d):\n", aPt.x, aPt.y);
|
2009-08-21 01:52:48 +04:00
|
|
|
nsFrame::PrintDisplayList(&builder, list);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-21 01:52:48 +04:00
|
|
|
|
2008-01-04 05:08:29 +03:00
|
|
|
nsDisplayItem::HitTestState hitTestState;
|
|
|
|
nsIFrame* result = list.HitTest(&builder, aPt, &hitTestState);
|
2006-01-26 05:29:17 +03:00
|
|
|
list.DeleteAll();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-04-08 17:06:12 +04:00
|
|
|
/**
|
|
|
|
* Remove all leaf display items that are not for descendants of
|
|
|
|
* aBuilder->GetReferenceFrame() from aList, and move all nsDisplayClip
|
|
|
|
* wrappers to their correct locations.
|
|
|
|
* @param aExtraPage the page we constructed aList for
|
|
|
|
* @param aY the Y-coordinate where aPage would be positioned relative
|
|
|
|
* to the main page (aBuilder->GetReferenceFrame()), considering only
|
|
|
|
* the content and ignoring page margins and dead space
|
|
|
|
* @param aList the list that is modified in-place
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
PruneDisplayListForExtraPage(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aExtraPage, nscoord aY, nsDisplayList* aList)
|
|
|
|
{
|
|
|
|
nsDisplayList newList;
|
|
|
|
// The page which we're really constructing a display list for
|
|
|
|
nsIFrame* mainPage = aBuilder->ReferenceFrame();
|
|
|
|
|
|
|
|
while (PR_TRUE) {
|
|
|
|
nsDisplayItem* i = aList->RemoveBottom();
|
|
|
|
if (!i)
|
|
|
|
break;
|
|
|
|
nsDisplayList* subList = i->GetList();
|
|
|
|
if (subList) {
|
|
|
|
PruneDisplayListForExtraPage(aBuilder, aExtraPage, aY, subList);
|
|
|
|
if (i->GetType() == nsDisplayItem::TYPE_CLIP) {
|
|
|
|
// This might clip an element which should appear on the first
|
|
|
|
// page, and that element might be visible if this uses a 'clip'
|
|
|
|
// property with a negative top.
|
|
|
|
// The clip area needs to be moved because the frame geometry doesn't
|
|
|
|
// put page content frames for adjacent pages vertically adjacent,
|
|
|
|
// there are page margins and dead space between them in print
|
|
|
|
// preview, and in printing all pages are at (0,0)...
|
|
|
|
// XXX we have no way to test this right now that I know of;
|
|
|
|
// the 'clip' property requires an abs-pos element and we never
|
|
|
|
// paint abs-pos elements that start after the main page
|
|
|
|
// (bug 426909).
|
|
|
|
nsDisplayClip* clip = static_cast<nsDisplayClip*>(i);
|
|
|
|
clip->SetClipRect(clip->GetClipRect() + nsPoint(0, aY) -
|
|
|
|
aExtraPage->GetOffsetTo(mainPage));
|
|
|
|
}
|
|
|
|
newList.AppendToTop(i);
|
|
|
|
} else {
|
|
|
|
nsIFrame* f = i->GetUnderlyingFrame();
|
|
|
|
if (f && nsLayoutUtils::IsProperAncestorFrameCrossDoc(mainPage, f)) {
|
|
|
|
// This one is in the page we care about, keep it
|
|
|
|
newList.AppendToTop(i);
|
|
|
|
} else {
|
|
|
|
// We're throwing this away so call its destructor now. The memory
|
|
|
|
// is owned by aBuilder which destroys all items at once.
|
2009-01-17 00:32:09 +03:00
|
|
|
i->~nsDisplayItem();
|
2008-04-08 17:06:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aList->AppendToTop(&newList);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
BuildDisplayListForExtraPage(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aPage, nscoord aY, nsDisplayList* aList)
|
|
|
|
{
|
|
|
|
nsDisplayList list;
|
|
|
|
// Pass an empty dirty rect since we're only interested in finding
|
|
|
|
// placeholders whose out-of-flows are in the page
|
|
|
|
// aBuilder->GetReferenceFrame(), and the paths to those placeholders
|
|
|
|
// have already been marked as NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO.
|
|
|
|
// Note that we should still do a prune step since we don't want to
|
|
|
|
// rely on dirty-rect checking for correctness.
|
|
|
|
nsresult rv = aPage->BuildDisplayListForStackingContext(aBuilder, nsRect(), &list);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
PruneDisplayListForExtraPage(aBuilder, aPage, aY, &list);
|
|
|
|
aList->AppendToTop(&list);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame*
|
|
|
|
GetNextPage(nsIFrame* aPageContentFrame)
|
|
|
|
{
|
|
|
|
// XXX ugh
|
|
|
|
nsIFrame* pageFrame = aPageContentFrame->GetParent();
|
|
|
|
NS_ASSERTION(pageFrame->GetType() == nsGkAtoms::pageFrame,
|
|
|
|
"pageContentFrame has unexpected parent");
|
|
|
|
nsIFrame* nextPageFrame = pageFrame->GetNextSibling();
|
|
|
|
if (!nextPageFrame)
|
|
|
|
return nsnull;
|
|
|
|
NS_ASSERTION(nextPageFrame->GetType() == nsGkAtoms::pageFrame,
|
|
|
|
"pageFrame's sibling is not a page frame...");
|
|
|
|
nsIFrame* f = nextPageFrame->GetFirstChild(nsnull);
|
|
|
|
NS_ASSERTION(f, "pageFrame has no page content frame!");
|
|
|
|
NS_ASSERTION(f->GetType() == nsGkAtoms::pageContentFrame,
|
|
|
|
"pageFrame's child is not page content!");
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::PaintFrame(nsIRenderingContext* aRenderingContext, nsIFrame* aFrame,
|
2009-07-22 04:45:14 +04:00
|
|
|
const nsRegion& aDirtyRegion, nscolor aBackstop,
|
|
|
|
PRUint32 aFlags)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2009-02-15 21:14:21 +03:00
|
|
|
nsAutoDisableGetUsedXAssertions disableAssert;
|
|
|
|
|
2006-04-18 03:16:46 +04:00
|
|
|
nsDisplayListBuilder builder(aFrame, PR_FALSE, PR_TRUE);
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayList list;
|
|
|
|
nsRect dirtyRect = aDirtyRegion.GetBounds();
|
2009-07-22 04:45:14 +04:00
|
|
|
if (aFlags & PAINT_IN_TRANSFORM) {
|
|
|
|
builder.SetInTransform(PR_TRUE);
|
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
if (aFlags & PAINT_SYNC_DECODE_IMAGES) {
|
|
|
|
builder.SetSyncDecodeImages(PR_TRUE);
|
|
|
|
}
|
2009-07-04 13:30:59 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2006-04-18 03:16:46 +04:00
|
|
|
builder.EnterPresShell(aFrame, dirtyRect);
|
|
|
|
|
2009-07-04 13:30:59 +04:00
|
|
|
rv = aFrame->BuildDisplayListForStackingContext(&builder, dirtyRect, &list);
|
|
|
|
|
2009-02-15 21:14:21 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && aFrame->GetType() == nsGkAtoms::pageContentFrame) {
|
|
|
|
// We may need to paint out-of-flow frames whose placeholders are
|
|
|
|
// on other pages. Add those pages to our display list. Note that
|
|
|
|
// out-of-flow frames can't be placed after their placeholders so
|
|
|
|
// we don't have to process earlier pages. The display lists for
|
|
|
|
// these extra pages are pruned so that only display items for the
|
|
|
|
// page we currently care about (which we would have reached by
|
|
|
|
// following placeholders to their out-of-flows) end up on the list.
|
|
|
|
nsIFrame* page = aFrame;
|
|
|
|
nscoord y = aFrame->GetSize().height;
|
|
|
|
while ((page = GetNextPage(page)) != nsnull) {
|
|
|
|
rv = BuildDisplayListForExtraPage(&builder, page, y, &list);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
y += page->GetSize().height;
|
2008-04-08 17:06:12 +04:00
|
|
|
}
|
2008-01-30 07:53:46 +03:00
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2009-07-30 02:10:50 +04:00
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
|
|
|
// For the viewport frame in print preview/page layout we want to paint
|
|
|
|
// the grey background behind the page, not the canvas color.
|
|
|
|
if (frameType == nsGkAtoms::viewportFrame &&
|
|
|
|
aFrame->PresContext()->IsRootPaginatedDocument() &&
|
|
|
|
(aFrame->PresContext()->Type() == nsPresContext::eContext_PrintPreview ||
|
|
|
|
aFrame->PresContext()->Type() == nsPresContext::eContext_PageLayout)) {
|
|
|
|
nsRect bounds = nsRect(builder.ToReferenceFrame(aFrame),
|
|
|
|
aFrame->GetSize());
|
|
|
|
rv = list.AppendNewToBottom(new (&builder) nsDisplaySolidColor(
|
|
|
|
aFrame, bounds, NS_RGB(115, 115, 115)));
|
|
|
|
} else if (frameType != nsGkAtoms::pageFrame) {
|
|
|
|
// For printing, this function is first called on an nsPageFrame, which
|
|
|
|
// creates a display list with a PageContent item. The PageContent item's
|
|
|
|
// paint function calls this function on the nsPageFrame's child which is
|
|
|
|
// an nsPageContentFrame. We only want to add the canvas background color
|
|
|
|
// item once, for the nsPageContentFrame.
|
|
|
|
|
2009-07-04 13:30:59 +04:00
|
|
|
// Add the canvas background color.
|
|
|
|
rv = aFrame->PresContext()->PresShell()->AddCanvasBackgroundColorItem(
|
|
|
|
builder, list, aFrame, nsnull, aBackstop);
|
|
|
|
}
|
|
|
|
|
2006-04-18 03:16:46 +04:00
|
|
|
builder.LeavePresShell(aFrame, dirtyRect);
|
2006-01-26 05:29:17 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpPaintList) {
|
|
|
|
fprintf(stderr, "Painting --- before optimization (dirty %d,%d,%d,%d):\n",
|
|
|
|
dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height);
|
2009-08-21 01:52:48 +04:00
|
|
|
nsFrame::PrintDisplayList(&builder, list);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-21 01:52:48 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRegion visibleRegion = aDirtyRegion;
|
2009-10-07 08:28:41 +04:00
|
|
|
list.ComputeVisibility(&builder, &visibleRegion, nsnull);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpPaintList) {
|
|
|
|
fprintf(stderr, "Painting --- after optimization:\n");
|
2009-08-21 01:52:48 +04:00
|
|
|
nsFrame::PrintDisplayList(&builder, list);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-21 01:52:48 +04:00
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
list.Paint(&builder, aRenderingContext);
|
2006-01-26 05:29:17 +03:00
|
|
|
// Flush the list so we don't trigger the IsEmpty-on-destruction assertion
|
|
|
|
list.DeleteAll();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-06 05:41:51 +03:00
|
|
|
static void
|
2009-08-14 06:09:51 +04:00
|
|
|
AccumulateItemInRegion(nsRegion* aRegion, const nsRect& aUpdateRect,
|
2008-08-16 13:22:02 +04:00
|
|
|
const nsRect& aItemRect, const nsRect& aExclude,
|
|
|
|
nsDisplayItem* aItem)
|
2006-02-06 05:41:51 +03:00
|
|
|
{
|
|
|
|
nsRect damageRect;
|
2009-08-14 06:09:51 +04:00
|
|
|
if (damageRect.IntersectRect(aUpdateRect, aItemRect)) {
|
2008-08-16 13:22:02 +04:00
|
|
|
nsRegion r;
|
|
|
|
r.Sub(damageRect, aExclude);
|
2006-02-06 05:41:51 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpRepaintRegionForCopy) {
|
2008-08-16 13:22:02 +04:00
|
|
|
nsRect bounds = r.GetBounds();
|
2006-02-06 05:41:51 +03:00
|
|
|
fprintf(stderr, "Adding rect %d,%d,%d,%d for frame %p\n",
|
2008-08-16 13:22:02 +04:00
|
|
|
bounds.x, bounds.y, bounds.width, bounds.height,
|
2006-02-06 05:41:51 +03:00
|
|
|
(void*)aItem->GetUnderlyingFrame());
|
|
|
|
}
|
|
|
|
#endif
|
2008-08-16 13:22:02 +04:00
|
|
|
aRegion->Or(*aRegion, r);
|
2006-02-06 05:41:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
static void
|
|
|
|
AddItemsToRegion(nsDisplayListBuilder* aBuilder, nsDisplayList* aList,
|
2009-08-14 06:09:51 +04:00
|
|
|
const nsRect& aUpdateRect, const nsRect& aClipRect, nsPoint aDelta,
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRegion* aRegion)
|
|
|
|
{
|
|
|
|
for (nsDisplayItem* item = aList->GetBottom(); item; item = item->GetAbove()) {
|
|
|
|
nsDisplayList* sublist = item->GetList();
|
|
|
|
if (sublist) {
|
2008-09-11 04:24:16 +04:00
|
|
|
nsDisplayItem::Type type = item->GetType();
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
if (type == nsDisplayItem::TYPE_SVG_EFFECTS) {
|
|
|
|
nsDisplaySVGEffects* effectsItem = static_cast<nsDisplaySVGEffects*>(item);
|
|
|
|
if (!aBuilder->IsMovingFrame(effectsItem->GetEffectsFrame())) {
|
|
|
|
// Invalidate the whole thing
|
|
|
|
nsRect r;
|
|
|
|
r.IntersectRect(aClipRect, effectsItem->GetBounds(aBuilder));
|
|
|
|
aRegion->Or(*aRegion, r);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (type == nsDisplayItem::TYPE_CLIP) {
|
2008-04-18 13:21:21 +04:00
|
|
|
nsDisplayClip* clipItem = static_cast<nsDisplayClip*>(item);
|
|
|
|
nsRect clip = aClipRect;
|
|
|
|
// If the clipping frame is moving, then it isn't clipping any
|
|
|
|
// non-moving content (see ApplyAbsPosClipping), so we don't need
|
|
|
|
// to do anything special, but we should not restrict aClipRect.
|
|
|
|
if (!aBuilder->IsMovingFrame(clipItem->GetClippingFrame())) {
|
|
|
|
clip.IntersectRect(clip, clipItem->GetClipRect());
|
|
|
|
|
|
|
|
// Invalidate the translation of the source area that was clipped out
|
|
|
|
nsRegion clippedOutSource;
|
2009-08-14 06:09:51 +04:00
|
|
|
clippedOutSource.Sub(aUpdateRect - aDelta, clip);
|
2008-04-18 13:21:21 +04:00
|
|
|
clippedOutSource.MoveBy(aDelta);
|
|
|
|
aRegion->Or(*aRegion, clippedOutSource);
|
|
|
|
|
|
|
|
// Invalidate the destination area that is clipped out
|
|
|
|
nsRegion clippedOutDestination;
|
2009-08-14 06:09:51 +04:00
|
|
|
clippedOutDestination.Sub(aUpdateRect, clip);
|
2008-04-18 13:21:21 +04:00
|
|
|
aRegion->Or(*aRegion, clippedOutDestination);
|
|
|
|
}
|
2009-08-14 06:09:51 +04:00
|
|
|
AddItemsToRegion(aBuilder, sublist, aUpdateRect, clip, aDelta, aRegion);
|
2006-01-26 05:29:17 +03:00
|
|
|
} else {
|
|
|
|
// opacity, or a generic sublist
|
2009-08-14 06:09:51 +04:00
|
|
|
AddItemsToRegion(aBuilder, sublist, aUpdateRect, aClipRect, aDelta, aRegion);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsRect r;
|
|
|
|
if (r.IntersectRect(aClipRect, item->GetBounds(aBuilder))) {
|
2008-04-11 07:46:37 +04:00
|
|
|
nsIFrame* f = item->GetUnderlyingFrame();
|
|
|
|
NS_ASSERTION(f, "Must have an underlying frame for leaf item");
|
2008-08-16 13:22:02 +04:00
|
|
|
nsRect exclude;
|
2008-04-11 07:46:37 +04:00
|
|
|
if (aBuilder->IsMovingFrame(f)) {
|
|
|
|
if (item->IsVaryingRelativeToMovingFrame(aBuilder)) {
|
|
|
|
// something like background-attachment:fixed that varies
|
|
|
|
// its drawing when it moves
|
2009-08-14 06:09:51 +04:00
|
|
|
AccumulateItemInRegion(aRegion, aUpdateRect, r, exclude, item);
|
2008-04-11 07:46:37 +04:00
|
|
|
}
|
|
|
|
} else {
|
2008-08-16 13:22:02 +04:00
|
|
|
// not moving.
|
|
|
|
if (item->IsUniform(aBuilder)) {
|
|
|
|
// If it's uniform, we don't need to invalidate where one part
|
|
|
|
// of the item was copied to another part.
|
|
|
|
exclude.IntersectRect(r, r + aDelta);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2008-08-16 13:22:02 +04:00
|
|
|
// area where a non-moving element is visible must be repainted
|
2009-08-14 06:09:51 +04:00
|
|
|
AccumulateItemInRegion(aRegion, aUpdateRect, r, exclude, item);
|
2008-08-16 13:22:02 +04:00
|
|
|
// we may have bitblitted an area that was painted by a non-moving
|
|
|
|
// element. This bitblitted data is invalid and was copied to
|
2008-08-25 12:54:24 +04:00
|
|
|
// "r + aDelta".
|
2009-08-14 06:09:51 +04:00
|
|
|
AccumulateItemInRegion(aRegion, aUpdateRect, r + aDelta,
|
2008-08-25 12:54:24 +04:00
|
|
|
exclude, item);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::ComputeRepaintRegionForCopy(nsIFrame* aRootFrame,
|
|
|
|
nsIFrame* aMovingFrame,
|
|
|
|
nsPoint aDelta,
|
2009-08-14 06:09:51 +04:00
|
|
|
const nsRect& aUpdateRect,
|
|
|
|
nsRegion* aBlitRegion,
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRegion* aRepaintRegion)
|
|
|
|
{
|
2006-09-20 02:05:33 +04:00
|
|
|
NS_ASSERTION(aRootFrame != aMovingFrame,
|
|
|
|
"The root frame shouldn't be the one that's moving, that makes no sense");
|
|
|
|
|
2009-05-15 05:40:29 +04:00
|
|
|
nsAutoDisableGetUsedXAssertions disableAssert;
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Build the 'after' display list over the whole area of interest.
|
|
|
|
// (We have to build the 'after' display list because the frame/view
|
2008-04-11 07:46:37 +04:00
|
|
|
// hierarchy has already been updated for the move.
|
|
|
|
// We need to ensure that the non-moving frame display items we get
|
|
|
|
// are the same ones we would have gotten if we had constructed the
|
|
|
|
// 'before' display list. So opaque moving items are only considered to
|
|
|
|
// cover the intersection of their old and new bounds (see
|
2009-09-07 04:35:14 +04:00
|
|
|
// nsDisplayItem::ComputeVisibility). A moving clip item is not allowed
|
2008-04-11 07:46:37 +04:00
|
|
|
// to clip non-moving items --- this is enforced by the code that sets
|
|
|
|
// up nsDisplayClip items, in particular see ApplyAbsPosClipping.
|
|
|
|
// XXX but currently a non-moving clip item can incorrectly clip
|
2008-04-18 13:21:21 +04:00
|
|
|
// moving items! See bug 428156.
|
2008-04-11 07:46:37 +04:00
|
|
|
nsDisplayListBuilder builder(aRootFrame, PR_FALSE, PR_TRUE);
|
2009-09-07 04:35:13 +04:00
|
|
|
// Retrieve the area of the moving content (considered in both its
|
|
|
|
// before- and after-movement positions) that's visible. This is the
|
2009-08-14 06:09:51 +04:00
|
|
|
// only area that needs to be blitted or repainted.
|
|
|
|
nsRegion visibleRegionOfMovingContent;
|
|
|
|
builder.SetMovingFrame(aMovingFrame, aDelta, &visibleRegionOfMovingContent);
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayList list;
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2009-09-07 04:35:13 +04:00
|
|
|
builder.EnterPresShell(aRootFrame, aUpdateRect);
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult rv =
|
2009-09-07 04:35:13 +04:00
|
|
|
aRootFrame->BuildDisplayListForStackingContext(&builder, aUpdateRect, &list);
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2009-09-07 04:35:13 +04:00
|
|
|
builder.LeavePresShell(aRootFrame, aUpdateRect);
|
2006-01-26 05:29:17 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-02-06 05:41:51 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpRepaintRegionForCopy) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Repaint region for copy --- before optimization (area %d,%d,%d,%d, frame %p):\n",
|
2009-09-07 04:35:13 +04:00
|
|
|
aUpdateRect.x, aUpdateRect.y, aUpdateRect.width, aUpdateRect.height,
|
|
|
|
(void*)aMovingFrame);
|
2009-08-21 01:52:48 +04:00
|
|
|
nsFrame::PrintDisplayList(&builder, list);
|
2006-02-06 05:41:51 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Optimize for visibility, but frames under aMovingFrame will not be
|
|
|
|
// considered opaque, so they don't cover non-moving frames.
|
2009-08-14 06:09:51 +04:00
|
|
|
nsRegion visibleRegion(aUpdateRect);
|
2009-10-07 08:28:41 +04:00
|
|
|
nsRegion visibleRegionBeforeMove(aUpdateRect);
|
|
|
|
list.ComputeVisibility(&builder, &visibleRegion, &visibleRegionBeforeMove);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2006-02-06 05:41:51 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpRepaintRegionForCopy) {
|
|
|
|
fprintf(stderr, "Repaint region for copy --- after optimization:\n");
|
2009-08-21 01:52:48 +04:00
|
|
|
nsFrame::PrintDisplayList(&builder, list);
|
2006-02-06 05:41:51 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:13 +04:00
|
|
|
// It's possible that there was moving content which was visible but
|
|
|
|
// has now been scrolled out of view so it does not intersect aUpdateRect,
|
|
|
|
// so it's not in our display list. So compute the region that that content
|
|
|
|
// could have occupied --- the complete region that has been scrolled out
|
|
|
|
// of view --- and add it to visibleRegionOfMovingContent.
|
|
|
|
// Note that aRepaintRegion does not depend on moving content which has
|
|
|
|
// been scrolled out of view.
|
|
|
|
nsRegion scrolledOutOfView;
|
|
|
|
scrolledOutOfView.Sub(aUpdateRect, aUpdateRect - aDelta);
|
|
|
|
visibleRegionOfMovingContent.Or(visibleRegionOfMovingContent, scrolledOutOfView);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
aRepaintRegion->SetEmpty();
|
|
|
|
// Any visible non-moving display items get added to the repaint region
|
|
|
|
// a) at their current location and b) offset by -aPt (their position in
|
|
|
|
// the 'before' display list) (unless they're uniform and we can exclude them).
|
|
|
|
// Also, any visible position-varying display items get added to the
|
2009-08-14 06:09:51 +04:00
|
|
|
// repaint region. All these areas are confined to aUpdateRect.
|
2006-01-26 05:29:17 +03:00
|
|
|
// We could do more work here: e.g., do another optimize-visibility pass
|
|
|
|
// with the moving items taken into account, either on the before-list
|
|
|
|
// or the after-list, or even both if we cloned the display lists ... but
|
|
|
|
// it's probably not worth it.
|
2009-09-07 04:35:13 +04:00
|
|
|
AddItemsToRegion(&builder, &list, aUpdateRect, aUpdateRect, aDelta, aRepaintRegion);
|
2006-01-26 05:29:17 +03:00
|
|
|
// Flush the list so we don't trigger the IsEmpty-on-destruction assertion
|
|
|
|
list.DeleteAll();
|
2009-08-14 06:09:51 +04:00
|
|
|
|
|
|
|
// Finalize output regions. The region of moving content that's not
|
|
|
|
// visible --- hidden by overlaid opaque non-moving content --- need not
|
|
|
|
// be blitted or repainted.
|
|
|
|
visibleRegionOfMovingContent.And(visibleRegionOfMovingContent, aUpdateRect);
|
|
|
|
aRepaintRegion->And(*aRepaintRegion, visibleRegionOfMovingContent);
|
|
|
|
aBlitRegion->Sub(visibleRegionOfMovingContent, *aRepaintRegion);
|
2006-01-26 05:29:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsLayoutUtils::GetZIndex(nsIFrame* aFrame) {
|
|
|
|
if (!aFrame->GetStyleDisplay()->IsPositioned())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const nsStylePosition* position =
|
|
|
|
aFrame->GetStylePosition();
|
|
|
|
if (position->mZIndex.GetUnit() == eStyleUnit_Integer)
|
|
|
|
return position->mZIndex.GetIntValue();
|
|
|
|
|
|
|
|
// sort the auto and 0 elements together
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-06 03:32:52 +03:00
|
|
|
/**
|
|
|
|
* Uses a binary search for find where the cursor falls in the line of text
|
|
|
|
* It also keeps track of the part of the string that has already been measured
|
|
|
|
* so it doesn't have to keep measuring the same text over and over
|
|
|
|
*
|
|
|
|
* @param "aBaseWidth" contains the width in twips of the portion
|
|
|
|
* of the text that has already been measured, and aBaseInx contains
|
|
|
|
* the index of the text that has already been measured.
|
|
|
|
*
|
|
|
|
* @param aTextWidth returns the (in twips) the length of the text that falls
|
|
|
|
* before the cursor aIndex contains the index of the text where the cursor falls
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
nsLayoutUtils::BinarySearchForPosition(nsIRenderingContext* aRendContext,
|
|
|
|
const PRUnichar* aText,
|
|
|
|
PRInt32 aBaseWidth,
|
|
|
|
PRInt32 aBaseInx,
|
|
|
|
PRInt32 aStartInx,
|
|
|
|
PRInt32 aEndInx,
|
|
|
|
PRInt32 aCursorPos,
|
|
|
|
PRInt32& aIndex,
|
|
|
|
PRInt32& aTextWidth)
|
|
|
|
{
|
|
|
|
PRInt32 range = aEndInx - aStartInx;
|
2006-12-21 10:03:23 +03:00
|
|
|
if ((range == 1) || (range == 2 && NS_IS_HIGH_SURROGATE(aText[aStartInx]))) {
|
2005-12-06 03:32:52 +03:00
|
|
|
aIndex = aStartInx + aBaseInx;
|
|
|
|
aRendContext->GetWidth(aText, aIndex, aTextWidth);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 inx = aStartInx + (range / 2);
|
|
|
|
|
|
|
|
// Make sure we don't leave a dangling low surrogate
|
2006-12-21 10:03:23 +03:00
|
|
|
if (NS_IS_HIGH_SURROGATE(aText[inx-1]))
|
2005-12-06 03:32:52 +03:00
|
|
|
inx++;
|
|
|
|
|
|
|
|
PRInt32 textWidth = 0;
|
|
|
|
aRendContext->GetWidth(aText, inx, textWidth);
|
|
|
|
|
|
|
|
PRInt32 fullWidth = aBaseWidth + textWidth;
|
|
|
|
if (fullWidth == aCursorPos) {
|
|
|
|
aTextWidth = textWidth;
|
|
|
|
aIndex = inx;
|
|
|
|
return PR_TRUE;
|
|
|
|
} else if (aCursorPos < fullWidth) {
|
|
|
|
aTextWidth = aBaseWidth;
|
|
|
|
if (BinarySearchForPosition(aRendContext, aText, aBaseWidth, aBaseInx, aStartInx, inx, aCursorPos, aIndex, aTextWidth)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aTextWidth = fullWidth;
|
|
|
|
if (BinarySearchForPosition(aRendContext, aText, aBaseWidth, aBaseInx, inx, aEndInx, aCursorPos, aIndex, aTextWidth)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-02-27 12:26:15 +03:00
|
|
|
static void
|
2008-09-11 04:24:16 +04:00
|
|
|
AddBoxesForFrame(nsIFrame* aFrame,
|
|
|
|
nsLayoutUtils::BoxCallback* aCallback)
|
2006-06-16 06:40:29 +04:00
|
|
|
{
|
2008-02-27 12:26:15 +03:00
|
|
|
nsIAtom* pseudoType = aFrame->GetStyleContext()->GetPseudoType();
|
|
|
|
|
|
|
|
if (pseudoType == nsCSSAnonBoxes::tableOuter) {
|
2008-09-11 04:24:16 +04:00
|
|
|
AddBoxesForFrame(aFrame->GetFirstChild(nsnull), aCallback);
|
2008-02-27 12:26:15 +03:00
|
|
|
nsIFrame* kid = aFrame->GetFirstChild(nsGkAtoms::captionList);
|
|
|
|
if (kid) {
|
2008-09-11 04:24:16 +04:00
|
|
|
AddBoxesForFrame(kid, aCallback);
|
2008-02-27 12:26:15 +03:00
|
|
|
}
|
|
|
|
} else if (pseudoType == nsCSSAnonBoxes::mozAnonymousBlock ||
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozAnonymousPositionedBlock ||
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozMathMLAnonymousBlock ||
|
|
|
|
pseudoType == nsCSSAnonBoxes::mozXULAnonymousBlock) {
|
|
|
|
for (nsIFrame* kid = aFrame->GetFirstChild(nsnull); kid; kid = kid->GetNextSibling()) {
|
2008-09-11 04:24:16 +04:00
|
|
|
AddBoxesForFrame(kid, aCallback);
|
2008-02-27 12:26:15 +03:00
|
|
|
}
|
|
|
|
} else {
|
2008-09-11 04:24:16 +04:00
|
|
|
aCallback->AddBox(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutUtils::GetAllInFlowBoxes(nsIFrame* aFrame, BoxCallback* aCallback)
|
|
|
|
{
|
|
|
|
while (aFrame) {
|
|
|
|
AddBoxesForFrame(aFrame, aCallback);
|
|
|
|
aFrame = nsLayoutUtils::GetNextContinuationOrSpecialSibling(aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct BoxToBorderRect : public nsLayoutUtils::BoxCallback {
|
|
|
|
nsIFrame* mRelativeTo;
|
|
|
|
nsLayoutUtils::RectCallback* mCallback;
|
|
|
|
|
|
|
|
BoxToBorderRect(nsIFrame* aRelativeTo, nsLayoutUtils::RectCallback* aCallback)
|
2009-05-04 22:08:36 +04:00
|
|
|
: mRelativeTo(aRelativeTo), mCallback(aCallback) {}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
|
|
|
virtual void AddBox(nsIFrame* aFrame) {
|
2008-02-27 12:26:15 +03:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
nsRect r;
|
|
|
|
nsIFrame* outer = nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(aFrame, &r);
|
|
|
|
if (outer) {
|
2008-09-11 04:24:16 +04:00
|
|
|
mCallback->AddRect(r + outer->GetOffsetTo(mRelativeTo));
|
2008-02-27 12:26:15 +03:00
|
|
|
} else
|
|
|
|
#endif
|
2008-09-11 04:24:16 +04:00
|
|
|
mCallback->AddRect(nsRect(aFrame->GetOffsetTo(mRelativeTo), aFrame->GetSize()));
|
2006-06-16 06:40:29 +04:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
};
|
2006-06-16 06:40:29 +04:00
|
|
|
|
2008-02-27 12:26:15 +03:00
|
|
|
void
|
|
|
|
nsLayoutUtils::GetAllInFlowRects(nsIFrame* aFrame, nsIFrame* aRelativeTo,
|
|
|
|
RectCallback* aCallback)
|
|
|
|
{
|
2008-09-11 04:24:16 +04:00
|
|
|
BoxToBorderRect converter(aRelativeTo, aCallback);
|
|
|
|
GetAllInFlowBoxes(aFrame, &converter);
|
2008-02-27 12:26:15 +03:00
|
|
|
}
|
|
|
|
|
2009-09-25 01:01:48 +04:00
|
|
|
nsLayoutUtils::RectAccumulator::RectAccumulator() : mSeenFirstRect(PR_FALSE) {}
|
2006-06-16 06:40:29 +04:00
|
|
|
|
2009-09-25 01:01:48 +04:00
|
|
|
void nsLayoutUtils::RectAccumulator::AddRect(const nsRect& aRect) {
|
|
|
|
mResultRect.UnionRect(mResultRect, aRect);
|
|
|
|
if (!mSeenFirstRect) {
|
|
|
|
mSeenFirstRect = PR_TRUE;
|
|
|
|
mFirstRect = aRect;
|
|
|
|
}
|
|
|
|
}
|
2008-02-27 12:26:15 +03:00
|
|
|
|
2009-09-25 01:01:48 +04:00
|
|
|
nsLayoutUtils::RectListBuilder::RectListBuilder(nsClientRectList* aList)
|
|
|
|
: mRectList(aList), mRV(NS_OK) {}
|
|
|
|
|
|
|
|
void nsLayoutUtils::RectListBuilder::AddRect(const nsRect& aRect) {
|
|
|
|
nsRefPtr<nsClientRect> rect = new nsClientRect();
|
|
|
|
if (!rect) {
|
|
|
|
mRV = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return;
|
2008-02-27 12:26:15 +03:00
|
|
|
}
|
2009-09-25 01:01:48 +04:00
|
|
|
|
|
|
|
rect->SetLayoutRect(aRect);
|
|
|
|
mRectList->Append(rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* nsLayoutUtils::GetContainingBlockForClientRect(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// get the nearest enclosing SVG foreign object frame or the root frame
|
|
|
|
while (aFrame->GetParent() &&
|
|
|
|
!aFrame->IsFrameOfType(nsIFrame::eSVGForeignObject)) {
|
|
|
|
aFrame = aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aFrame;
|
|
|
|
}
|
2008-02-27 12:26:15 +03:00
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::GetAllInFlowRectsUnion(nsIFrame* aFrame, nsIFrame* aRelativeTo) {
|
|
|
|
RectAccumulator accumulator;
|
|
|
|
GetAllInFlowRects(aFrame, aRelativeTo, &accumulator);
|
|
|
|
return accumulator.mResultRect.IsEmpty() ? accumulator.mFirstRect
|
|
|
|
: accumulator.mResultRect;
|
2006-06-16 06:40:29 +04:00
|
|
|
}
|
2006-07-06 14:43:51 +04:00
|
|
|
|
2008-06-13 02:02:32 +04:00
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::GetTextShadowRectsUnion(const nsRect& aTextAndDecorationsRect,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
const nsStyleText* textStyle = aFrame->GetStyleText();
|
2008-07-08 04:56:52 +04:00
|
|
|
if (!textStyle->mTextShadow)
|
2008-06-13 02:02:32 +04:00
|
|
|
return aTextAndDecorationsRect;
|
|
|
|
|
|
|
|
nsRect resultRect = aTextAndDecorationsRect;
|
2008-07-08 04:56:52 +04:00
|
|
|
for (PRUint32 i = 0; i < textStyle->mTextShadow->Length(); ++i) {
|
2008-06-13 02:02:32 +04:00
|
|
|
nsRect tmpRect(aTextAndDecorationsRect);
|
2008-07-08 04:56:52 +04:00
|
|
|
nsCSSShadowItem* shadow = textStyle->mTextShadow->ShadowAt(i);
|
2008-06-13 02:02:32 +04:00
|
|
|
|
2008-09-13 07:45:37 +04:00
|
|
|
tmpRect.MoveBy(nsPoint(shadow->mXOffset, shadow->mYOffset));
|
|
|
|
tmpRect.Inflate(shadow->mRadius, shadow->mRadius);
|
2008-06-13 02:02:32 +04:00
|
|
|
|
|
|
|
resultRect.UnionRect(resultRect, tmpRect);
|
|
|
|
}
|
|
|
|
return resultRect;
|
|
|
|
}
|
|
|
|
|
2006-07-06 14:43:51 +04:00
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(nsIFrame* aFrame,
|
|
|
|
nsIFontMetrics** aFontMetrics)
|
|
|
|
{
|
2007-08-07 23:22:26 +04:00
|
|
|
return nsLayoutUtils::GetFontMetricsForStyleContext(aFrame->GetStyleContext(),
|
|
|
|
aFontMetrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::GetFontMetricsForStyleContext(nsStyleContext* aStyleContext,
|
|
|
|
nsIFontMetrics** aFontMetrics)
|
|
|
|
{
|
2008-10-01 07:01:53 +04:00
|
|
|
// pass the user font set object into the device context to pass along to CreateFontGroup
|
|
|
|
gfxUserFontSet* fs = aStyleContext->PresContext()->GetUserFontSet();
|
|
|
|
|
|
|
|
return aStyleContext->PresContext()->DeviceContext()->GetMetricsFor(
|
|
|
|
aStyleContext->GetStyleFont()->mFont,
|
2007-08-07 23:22:26 +04:00
|
|
|
aStyleContext->GetStyleVisibility()->mLangGroup,
|
2008-12-04 19:09:53 +03:00
|
|
|
fs, *aFontMetrics);
|
2006-07-06 14:43:51 +04:00
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
|
2007-01-17 05:37:19 +03:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* result = aDescendantFrame;
|
|
|
|
|
|
|
|
while (result) {
|
|
|
|
nsIFrame* parent = result->GetParent();
|
|
|
|
if (parent == aParent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The frame is not an immediate child of aParent so walk up another level
|
|
|
|
result = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-12-21 06:28:18 +03:00
|
|
|
nsBlockFrame*
|
|
|
|
nsLayoutUtils::GetAsBlock(nsIFrame* aFrame)
|
|
|
|
{
|
2009-01-12 22:20:59 +03:00
|
|
|
nsBlockFrame* block = do_QueryFrame(aFrame);
|
|
|
|
return block;
|
2007-12-21 06:28:18 +03:00
|
|
|
}
|
|
|
|
|
2007-01-17 05:37:19 +03:00
|
|
|
nsBlockFrame*
|
|
|
|
nsLayoutUtils::FindNearestBlockAncestor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* nextAncestor;
|
|
|
|
for (nextAncestor = aFrame->GetParent(); nextAncestor;
|
|
|
|
nextAncestor = nextAncestor->GetParent()) {
|
2007-12-21 06:28:18 +03:00
|
|
|
nsBlockFrame* block = GetAsBlock(nextAncestor);
|
|
|
|
if (block)
|
2007-01-17 05:37:19 +03:00
|
|
|
return block;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2008-11-26 01:15:41 +03:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetNonGeneratedAncestor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_GENERATED_CONTENT))
|
|
|
|
return aFrame;
|
|
|
|
|
|
|
|
nsFrameManager* frameManager = aFrame->PresContext()->FrameManager();
|
|
|
|
nsIFrame* f = aFrame;
|
|
|
|
do {
|
|
|
|
f = GetParentOrPlaceholderFor(frameManager, f);
|
|
|
|
} while (f->GetStateBits() & NS_FRAME_GENERATED_CONTENT);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetParentOrPlaceholderFor(nsFrameManager* aFrameManager,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
2007-10-02 09:57:45 +04:00
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)
|
2009-08-31 22:25:36 +04:00
|
|
|
&& !aFrame->GetPrevInFlow()) {
|
2006-10-19 05:47:47 +04:00
|
|
|
return aFrameManager->GetPlaceholderFrameFor(aFrame);
|
2007-10-02 09:57:45 +04:00
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
return aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetClosestCommonAncestorViaPlaceholders(nsIFrame* aFrame1,
|
|
|
|
nsIFrame* aFrame2,
|
|
|
|
nsIFrame* aKnownCommonAncestorHint)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame1, "aFrame1 must not be null");
|
|
|
|
NS_PRECONDITION(aFrame2, "aFrame2 must not be null");
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = aFrame1->PresContext();
|
|
|
|
if (presContext != aFrame2->PresContext()) {
|
2006-10-19 05:47:47 +04:00
|
|
|
// different documents, no common ancestor
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
nsFrameManager* frameManager = presContext->PresShell()->FrameManager();
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
nsAutoTArray<nsIFrame*, 8> frame1Ancestors;
|
2006-10-19 05:47:47 +04:00
|
|
|
nsIFrame* f1;
|
|
|
|
for (f1 = aFrame1; f1 && f1 != aKnownCommonAncestorHint;
|
|
|
|
f1 = GetParentOrPlaceholderFor(frameManager, f1)) {
|
|
|
|
frame1Ancestors.AppendElement(f1);
|
|
|
|
}
|
|
|
|
if (!f1 && aKnownCommonAncestorHint) {
|
|
|
|
// So, it turns out aKnownCommonAncestorHint was not an ancestor of f1. Oops.
|
|
|
|
// Never mind. We can continue as if aKnownCommonAncestorHint was null.
|
|
|
|
aKnownCommonAncestorHint = nsnull;
|
|
|
|
}
|
|
|
|
|
2009-02-03 17:42:18 +03:00
|
|
|
nsAutoTArray<nsIFrame*, 8> frame2Ancestors;
|
2006-10-19 05:47:47 +04:00
|
|
|
nsIFrame* f2;
|
|
|
|
for (f2 = aFrame2; f2 && f2 != aKnownCommonAncestorHint;
|
|
|
|
f2 = GetParentOrPlaceholderFor(frameManager, f2)) {
|
|
|
|
frame2Ancestors.AppendElement(f2);
|
|
|
|
}
|
|
|
|
if (!f2 && aKnownCommonAncestorHint) {
|
|
|
|
// So, it turns out aKnownCommonAncestorHint was not an ancestor of f2.
|
|
|
|
// We need to retry with no common ancestor hint.
|
|
|
|
return GetClosestCommonAncestorViaPlaceholders(aFrame1, aFrame2, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
// now frame1Ancestors and frame2Ancestors give us the parent frame chain
|
|
|
|
// up to aKnownCommonAncestorHint, or if that is null, up to and including
|
|
|
|
// the root frame. We need to walk from the end (i.e., the top of the
|
|
|
|
// frame (sub)tree) down to aFrame1/aFrame2 looking for the first difference.
|
|
|
|
nsIFrame* lastCommonFrame = aKnownCommonAncestorHint;
|
2009-02-03 17:42:18 +03:00
|
|
|
PRInt32 last1 = frame1Ancestors.Length() - 1;
|
|
|
|
PRInt32 last2 = frame2Ancestors.Length() - 1;
|
2006-10-19 05:47:47 +04:00
|
|
|
while (last1 >= 0 && last2 >= 0) {
|
2009-02-03 17:42:18 +03:00
|
|
|
nsIFrame* frame1 = frame1Ancestors.ElementAt(last1);
|
2006-10-19 05:47:47 +04:00
|
|
|
if (frame1 != frame2Ancestors.ElementAt(last2))
|
|
|
|
break;
|
|
|
|
lastCommonFrame = frame1;
|
|
|
|
last1--;
|
|
|
|
last2--;
|
|
|
|
}
|
|
|
|
return lastCommonFrame;
|
|
|
|
}
|
2006-11-01 16:56:48 +03:00
|
|
|
|
2007-03-26 07:27:53 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetNextContinuationOrSpecialSibling(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame *result = aFrame->GetNextContinuation();
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_IS_SPECIAL) != 0) {
|
|
|
|
// We only store the "special sibling" annotation with the first
|
2009-04-15 06:28:27 +04:00
|
|
|
// frame in the continuation chain. Walk back to find that frame now.
|
|
|
|
aFrame = aFrame->GetFirstContinuation();
|
2007-03-26 07:27:53 +04:00
|
|
|
|
|
|
|
void* value = aFrame->GetProperty(nsGkAtoms::IBSplitSpecialSibling);
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsIFrame*>(value);
|
2007-03-26 07:27:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetFirstContinuationOrSpecialSibling(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame *result = aFrame->GetFirstContinuation();
|
|
|
|
if (result->GetStateBits() & NS_FRAME_IS_SPECIAL) {
|
|
|
|
while (PR_TRUE) {
|
|
|
|
nsIFrame *f = static_cast<nsIFrame*>
|
|
|
|
(result->GetProperty(nsGkAtoms::IBSplitSpecialPrevSibling));
|
|
|
|
if (!f)
|
|
|
|
break;
|
|
|
|
result = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-11-01 16:56:48 +03:00
|
|
|
PRBool
|
|
|
|
nsLayoutUtils::IsViewportScrollbarFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* rootScrollFrame =
|
2007-03-31 01:11:41 +04:00
|
|
|
aFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
2006-11-01 16:56:48 +03:00
|
|
|
if (!rootScrollFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollableFrame* rootScrollableFrame = do_QueryFrame(rootScrollFrame);
|
2006-11-01 16:56:48 +03:00
|
|
|
NS_ASSERTION(rootScrollableFrame, "The root scorollable frame is null");
|
|
|
|
|
|
|
|
if (!IsProperAncestorFrame(rootScrollFrame, aFrame))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* rootScrolledFrame = rootScrollableFrame->GetScrolledFrame();
|
|
|
|
return !(rootScrolledFrame == aFrame ||
|
|
|
|
IsProperAncestorFrame(rootScrolledFrame, aFrame));
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
static nscoord AddPercents(nsLayoutUtils::IntrinsicWidthType aType,
|
|
|
|
nscoord aCurrent, float aPercent)
|
|
|
|
{
|
|
|
|
nscoord result = aCurrent;
|
|
|
|
if (aPercent > 0.0f && aType == nsLayoutUtils::PREF_WIDTH) {
|
|
|
|
// XXX Should we also consider percentages for min widths, up to a
|
|
|
|
// limit?
|
|
|
|
if (aPercent >= 1.0f)
|
|
|
|
result = nscoord_MAX;
|
|
|
|
else
|
|
|
|
result = NSToCoordRound(float(result) / (1.0f - aPercent));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2006-12-17 17:06:42 +03:00
|
|
|
|
2008-07-18 03:37:12 +04:00
|
|
|
static PRBool GetAbsoluteCoord(const nsStyleCoord& aStyle, nscoord& aResult)
|
|
|
|
{
|
|
|
|
if (eStyleUnit_Coord != aStyle.GetUnit())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
aResult = aStyle.GetCoordValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-06-12 22:27:09 +04:00
|
|
|
static PRBool
|
|
|
|
GetPercentHeight(const nsStyleCoord& aStyle,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nscoord& aResult)
|
|
|
|
{
|
|
|
|
if (eStyleUnit_Percent != aStyle.GetUnit())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame *f;
|
|
|
|
for (f = aFrame->GetParent(); f && !f->IsContainingBlock();
|
|
|
|
f = f->GetParent())
|
|
|
|
;
|
|
|
|
if (!f) {
|
|
|
|
NS_NOTREACHED("top of frame tree not a containing block");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStylePosition *pos = f->GetStylePosition();
|
|
|
|
nscoord h;
|
2008-07-18 03:37:12 +04:00
|
|
|
if (!GetAbsoluteCoord(pos->mHeight, h) &&
|
|
|
|
!GetPercentHeight(pos->mHeight, f, h)) {
|
2007-06-12 22:27:09 +04:00
|
|
|
NS_ASSERTION(pos->mHeight.GetUnit() == eStyleUnit_Auto ||
|
|
|
|
pos->mHeight.GetUnit() == eStyleUnit_Percent,
|
|
|
|
"unknown height unit");
|
|
|
|
// There's no basis for the percentage height, so it acts like auto.
|
|
|
|
// Should we consider a max-height < min-height pair a basis for
|
|
|
|
// percentage heights? The spec is somewhat unclear, and not doing
|
|
|
|
// so is simpler and avoids troubling discontinuities in behavior,
|
|
|
|
// so I'll choose not to. -LDB
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord maxh;
|
2008-07-18 03:37:12 +04:00
|
|
|
if (GetAbsoluteCoord(pos->mMaxHeight, maxh) ||
|
|
|
|
GetPercentHeight(pos->mMaxHeight, f, maxh)) {
|
2007-06-12 22:27:09 +04:00
|
|
|
if (maxh < h)
|
|
|
|
h = maxh;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(pos->mMaxHeight.GetUnit() == eStyleUnit_None ||
|
|
|
|
pos->mMaxHeight.GetUnit() == eStyleUnit_Percent,
|
|
|
|
"unknown max-height unit");
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord minh;
|
2008-07-18 03:37:12 +04:00
|
|
|
if (GetAbsoluteCoord(pos->mMinHeight, minh) ||
|
|
|
|
GetPercentHeight(pos->mMinHeight, f, minh)) {
|
2007-06-12 22:27:09 +04:00
|
|
|
if (minh > h)
|
|
|
|
h = minh;
|
|
|
|
} else {
|
2008-01-05 02:14:50 +03:00
|
|
|
NS_ASSERTION(pos->mMinHeight.GetUnit() == eStyleUnit_Percent,
|
2007-06-12 22:27:09 +04:00
|
|
|
"unknown min-height unit");
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult = NSToCoordRound(aStyle.GetPercentValue() * h);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-11-15 21:10:31 +03:00
|
|
|
// Handles only -moz-max-content and -moz-min-content, and
|
|
|
|
// -moz-fit-content for min-width and max-width, since the others
|
|
|
|
// (-moz-fit-content for width, and -moz-available) have no effect on
|
2007-05-04 03:11:00 +04:00
|
|
|
// intrinsic widths.
|
|
|
|
enum eWidthProperty { PROP_WIDTH, PROP_MAX_WIDTH, PROP_MIN_WIDTH };
|
|
|
|
static PRBool
|
|
|
|
GetIntrinsicCoord(const nsStyleCoord& aStyle,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
eWidthProperty aProperty,
|
|
|
|
nscoord& aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aProperty == PROP_WIDTH || aProperty == PROP_MAX_WIDTH ||
|
|
|
|
aProperty == PROP_MIN_WIDTH, "unexpected property");
|
|
|
|
if (aStyle.GetUnit() != eStyleUnit_Enumerated)
|
|
|
|
return PR_FALSE;
|
|
|
|
PRInt32 val = aStyle.GetIntValue();
|
2007-11-15 21:10:31 +03:00
|
|
|
NS_ASSERTION(val == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
val == NS_STYLE_WIDTH_MIN_CONTENT ||
|
|
|
|
val == NS_STYLE_WIDTH_FIT_CONTENT ||
|
|
|
|
val == NS_STYLE_WIDTH_AVAILABLE,
|
2007-05-04 03:11:00 +04:00
|
|
|
"unexpected enumerated value for width property");
|
2007-11-15 21:10:31 +03:00
|
|
|
if (val == NS_STYLE_WIDTH_AVAILABLE)
|
2007-05-04 03:11:00 +04:00
|
|
|
return PR_FALSE;
|
2007-11-15 21:10:31 +03:00
|
|
|
if (val == NS_STYLE_WIDTH_FIT_CONTENT) {
|
2007-05-04 03:11:00 +04:00
|
|
|
if (aProperty == PROP_WIDTH)
|
|
|
|
return PR_FALSE; // handle like 'width: auto'
|
|
|
|
if (aProperty == PROP_MAX_WIDTH)
|
2007-11-15 21:10:31 +03:00
|
|
|
// constrain large 'width' values down to -moz-max-content
|
|
|
|
val = NS_STYLE_WIDTH_MAX_CONTENT;
|
2007-05-04 03:11:00 +04:00
|
|
|
else
|
2007-11-15 21:10:31 +03:00
|
|
|
// constrain small 'width' or 'max-width' values up to -moz-min-content
|
|
|
|
val = NS_STYLE_WIDTH_MIN_CONTENT;
|
2007-05-04 03:11:00 +04:00
|
|
|
}
|
|
|
|
|
2007-11-15 21:10:31 +03:00
|
|
|
NS_ASSERTION(val == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
val == NS_STYLE_WIDTH_MIN_CONTENT,
|
2007-05-04 03:11:00 +04:00
|
|
|
"should have reduced everything remaining to one of these");
|
2007-11-15 21:10:31 +03:00
|
|
|
if (val == NS_STYLE_WIDTH_MAX_CONTENT)
|
2007-05-04 03:11:00 +04:00
|
|
|
aResult = aFrame->GetPrefWidth(aRenderingContext);
|
|
|
|
else
|
|
|
|
aResult = aFrame->GetMinWidth(aRenderingContext);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
#undef DEBUG_INTRINSIC_WIDTH
|
|
|
|
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
static PRInt32 gNoiseIndent = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(nsIRenderingContext *aRenderingContext,
|
|
|
|
nsIFrame *aFrame,
|
|
|
|
IntrinsicWidthType aType)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null frame");
|
|
|
|
NS_PRECONDITION(aType == MIN_WIDTH || aType == PREF_WIDTH, "bad type");
|
|
|
|
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stdout);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
printf(" %s intrinsic width for container:\n",
|
|
|
|
aType == MIN_WIDTH ? "min" : "pref");
|
|
|
|
#endif
|
|
|
|
|
2006-12-17 17:06:42 +03:00
|
|
|
nsIFrame::IntrinsicWidthOffsetData offsets =
|
|
|
|
aFrame->IntrinsicWidthOffsets(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
const nsStylePosition *stylePos = aFrame->GetStylePosition();
|
2007-05-04 03:11:00 +04:00
|
|
|
PRUint8 boxSizing = stylePos->mBoxSizing;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
const nsStyleCoord &styleWidth = stylePos->mWidth;
|
|
|
|
const nsStyleCoord &styleMinWidth = stylePos->mMinWidth;
|
|
|
|
const nsStyleCoord &styleMaxWidth = stylePos->mMaxWidth;
|
|
|
|
|
|
|
|
// We build up two values starting with the content box, and then
|
|
|
|
// adding padding, border and margin. The result is normally
|
|
|
|
// |result|. Then, when we handle 'width', 'min-width', and
|
|
|
|
// 'max-width', we use the results we've been building in |min| as a
|
|
|
|
// minimum, overriding 'min-width'. This ensures two things:
|
|
|
|
// * that we don't let a value of 'box-sizing' specifying a width
|
|
|
|
// smaller than the padding/border inside the box-sizing box give
|
|
|
|
// a content width less than zero
|
|
|
|
// * that we prevent tables from becoming smaller than their
|
|
|
|
// intrinsic minimum width
|
|
|
|
nscoord result = 0, min = 0;
|
|
|
|
|
|
|
|
// If we have a specified width (or a specified 'min-width' greater
|
|
|
|
// than the specified 'max-width', which works out to the same thing),
|
|
|
|
// don't even bother getting the frame's intrinsic width.
|
2007-05-04 03:11:00 +04:00
|
|
|
if (styleWidth.GetUnit() == eStyleUnit_Enumerated &&
|
2007-11-15 21:10:31 +03:00
|
|
|
(styleWidth.GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT ||
|
|
|
|
styleWidth.GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT)) {
|
|
|
|
// -moz-fit-content and -moz-available enumerated widths compute intrinsic
|
2007-05-04 03:11:00 +04:00
|
|
|
// widths just like auto.
|
2007-11-15 21:10:31 +03:00
|
|
|
// For -moz-max-content and -moz-min-content, we handle them like
|
2007-05-04 03:11:00 +04:00
|
|
|
// specified widths, but ignore -moz-box-sizing.
|
|
|
|
boxSizing = NS_STYLE_BOX_SIZING_CONTENT;
|
|
|
|
} else if (styleWidth.GetUnit() != eStyleUnit_Coord &&
|
|
|
|
(styleMinWidth.GetUnit() != eStyleUnit_Coord ||
|
|
|
|
styleMaxWidth.GetUnit() != eStyleUnit_Coord ||
|
|
|
|
styleMaxWidth.GetCoordValue() > styleMinWidth.GetCoordValue())) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
++gNoiseIndent;
|
|
|
|
#endif
|
|
|
|
if (aType == MIN_WIDTH)
|
|
|
|
result = aFrame->GetMinWidth(aRenderingContext);
|
|
|
|
else
|
|
|
|
result = aFrame->GetPrefWidth(aRenderingContext);
|
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
--gNoiseIndent;
|
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stdout);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
printf(" %s intrinsic width from frame is %d.\n",
|
|
|
|
aType == MIN_WIDTH ? "min" : "pref", result);
|
|
|
|
#endif
|
2007-06-12 22:27:09 +04:00
|
|
|
|
|
|
|
// Handle elements with an intrinsic ratio (or size) and a specified
|
|
|
|
// height, min-height, or max-height.
|
|
|
|
const nsStyleCoord &styleHeight = stylePos->mHeight;
|
|
|
|
const nsStyleCoord &styleMinHeight = stylePos->mMinHeight;
|
|
|
|
const nsStyleCoord &styleMaxHeight = stylePos->mMaxHeight;
|
|
|
|
if (styleHeight.GetUnit() != eStyleUnit_Auto ||
|
|
|
|
!(styleMinHeight.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
styleMinHeight.GetCoordValue() == 0) ||
|
|
|
|
styleMaxHeight.GetUnit() != eStyleUnit_None) {
|
|
|
|
|
|
|
|
nsSize ratio = aFrame->GetIntrinsicRatio();
|
|
|
|
|
|
|
|
if (ratio.height != 0) {
|
|
|
|
|
|
|
|
nscoord h;
|
2008-07-18 03:37:12 +04:00
|
|
|
if (GetAbsoluteCoord(styleHeight, h) ||
|
|
|
|
GetPercentHeight(styleHeight, aFrame, h)) {
|
2007-06-12 22:27:09 +04:00
|
|
|
result =
|
|
|
|
NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
|
|
|
|
}
|
|
|
|
|
2008-07-18 03:37:12 +04:00
|
|
|
if (GetAbsoluteCoord(styleMaxHeight, h) ||
|
|
|
|
GetPercentHeight(styleMaxHeight, aFrame, h)) {
|
2007-06-12 22:27:09 +04:00
|
|
|
h = NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
|
|
|
|
if (h < result)
|
|
|
|
result = h;
|
|
|
|
}
|
|
|
|
|
2008-07-18 03:37:12 +04:00
|
|
|
if (GetAbsoluteCoord(styleMinHeight, h) ||
|
|
|
|
GetPercentHeight(styleMinHeight, aFrame, h)) {
|
2007-06-12 22:27:09 +04:00
|
|
|
h = NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
|
|
|
|
if (h > result)
|
|
|
|
result = h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aFrame->GetType() == nsGkAtoms::tableFrame) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Tables can't shrink smaller than their intrinsic minimum width,
|
|
|
|
// no matter what.
|
|
|
|
min = aFrame->GetMinWidth(aRenderingContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We also need to track what has been added on outside of the box
|
|
|
|
// (controlled by 'box-sizing') where 'width', 'min-width' and
|
|
|
|
// 'max-width' are applied. We have to account for these properties
|
|
|
|
// after getting all the offsets (margin, border, padding) because
|
|
|
|
// percentages do not operate linearly.
|
|
|
|
// Doing this is ok because although percentages aren't handled
|
|
|
|
// linearly, they are handled monotonically.
|
|
|
|
nscoord coordOutsideWidth = offsets.hPadding;
|
|
|
|
float pctOutsideWidth = offsets.hPctPadding;
|
|
|
|
|
|
|
|
float pctTotal = 0.0f;
|
|
|
|
|
|
|
|
if (boxSizing == NS_STYLE_BOX_SIZING_PADDING) {
|
|
|
|
min += coordOutsideWidth;
|
2007-09-24 21:30:42 +04:00
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideWidth);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
|
|
|
coordOutsideWidth = 0;
|
|
|
|
pctOutsideWidth = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
coordOutsideWidth += offsets.hBorder;
|
|
|
|
|
|
|
|
if (boxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
min += coordOutsideWidth;
|
2007-09-24 21:30:42 +04:00
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideWidth);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
|
|
|
coordOutsideWidth = 0;
|
|
|
|
pctOutsideWidth = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
coordOutsideWidth += offsets.hMargin;
|
|
|
|
pctOutsideWidth += offsets.hPctMargin;
|
|
|
|
|
|
|
|
min += coordOutsideWidth;
|
2007-09-24 21:30:42 +04:00
|
|
|
result = NSCoordSaturatingAdd(result, coordOutsideWidth);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
2006-12-17 17:06:42 +03:00
|
|
|
nscoord w;
|
2008-07-18 03:37:12 +04:00
|
|
|
if (GetAbsoluteCoord(styleWidth, w) ||
|
2007-05-04 03:11:00 +04:00
|
|
|
GetIntrinsicCoord(styleWidth, aRenderingContext, aFrame,
|
|
|
|
PROP_WIDTH, w)) {
|
2006-12-17 17:06:42 +03:00
|
|
|
result = AddPercents(aType, w + coordOutsideWidth, pctOutsideWidth);
|
|
|
|
}
|
|
|
|
else if (aType == MIN_WIDTH && eStyleUnit_Percent == styleWidth.GetUnit() &&
|
|
|
|
aFrame->IsFrameOfType(nsIFrame::eReplaced)) {
|
|
|
|
// A percentage width on replaced elements means they can shrink to 0.
|
|
|
|
result = 0; // let |min| handle padding/border/margin
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = AddPercents(aType, result, pctTotal);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2006-12-17 17:06:42 +03:00
|
|
|
nscoord maxw;
|
2008-07-18 03:37:12 +04:00
|
|
|
if (GetAbsoluteCoord(styleMaxWidth, maxw) ||
|
2007-05-04 03:11:00 +04:00
|
|
|
GetIntrinsicCoord(styleMaxWidth, aRenderingContext, aFrame,
|
|
|
|
PROP_MAX_WIDTH, maxw)) {
|
2006-12-17 17:06:42 +03:00
|
|
|
maxw = AddPercents(aType, maxw + coordOutsideWidth, pctOutsideWidth);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (result > maxw)
|
|
|
|
result = maxw;
|
|
|
|
}
|
|
|
|
|
2006-12-17 17:06:42 +03:00
|
|
|
nscoord minw;
|
2008-07-18 03:37:12 +04:00
|
|
|
if (GetAbsoluteCoord(styleMinWidth, minw) ||
|
2007-05-04 03:11:00 +04:00
|
|
|
GetIntrinsicCoord(styleMinWidth, aRenderingContext, aFrame,
|
|
|
|
PROP_MIN_WIDTH, minw)) {
|
2006-12-17 17:06:42 +03:00
|
|
|
minw = AddPercents(aType, minw + coordOutsideWidth, pctOutsideWidth);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (result < minw)
|
|
|
|
result = minw;
|
|
|
|
}
|
|
|
|
|
|
|
|
min = AddPercents(aType, min, pctTotal);
|
|
|
|
if (result < min)
|
|
|
|
result = min;
|
|
|
|
|
2007-01-18 01:31:07 +03:00
|
|
|
const nsStyleDisplay *disp = aFrame->GetStyleDisplay();
|
|
|
|
if (aFrame->IsThemed(disp)) {
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntSize size(0, 0);
|
2007-01-18 01:31:07 +03:00
|
|
|
PRBool canOverride = PR_TRUE;
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
2007-01-18 01:31:07 +03:00
|
|
|
presContext->GetTheme()->
|
|
|
|
GetMinimumWidgetSize(aRenderingContext, aFrame, disp->mAppearance,
|
|
|
|
&size, &canOverride);
|
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
nscoord themeWidth = presContext->DevPixelsToAppUnits(size.width);
|
2007-01-18 01:31:07 +03:00
|
|
|
|
|
|
|
// GMWS() returns a border-box width
|
|
|
|
themeWidth += offsets.hMargin;
|
|
|
|
themeWidth = AddPercents(aType, themeWidth, offsets.hPctMargin);
|
|
|
|
|
|
|
|
if (themeWidth > result || !canOverride)
|
|
|
|
result = themeWidth;
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
#ifdef DEBUG_INTRINSIC_WIDTH
|
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsFrame*>(aFrame)->ListTag(stdout);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
printf(" %s intrinsic width for container is %d twips.\n",
|
|
|
|
aType == MIN_WIDTH ? "min" : "pref", result);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
2006-12-18 16:20:18 +03:00
|
|
|
nsLayoutUtils::ComputeWidthDependentValue(
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
const nsStyleCoord& aCoord)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"unconstrained widths no longer supported");
|
|
|
|
|
2008-07-18 03:37:12 +04:00
|
|
|
if (eStyleUnit_Coord == aCoord.GetUnit()) {
|
|
|
|
return aCoord.GetCoordValue();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
2006-12-17 17:06:42 +03:00
|
|
|
if (eStyleUnit_Percent == aCoord.GetUnit()) {
|
|
|
|
return NSToCoordFloor(aContainingBlockWidth * aCoord.GetPercentValue());
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
2007-05-11 10:01:31 +04:00
|
|
|
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
|
2007-05-04 03:11:00 +04:00
|
|
|
aCoord.GetUnit() == eStyleUnit_Auto,
|
|
|
|
"unexpected width value");
|
2006-12-17 17:06:42 +03:00
|
|
|
return 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2007-05-04 03:11:00 +04:00
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::ComputeWidthValue(
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContentEdgeToBoxSizing,
|
|
|
|
nscoord aBoxSizingToMarginEdge,
|
|
|
|
const nsStyleCoord& aCoord)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "non-null frame expected");
|
|
|
|
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
|
|
|
|
NS_PRECONDITION(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"unconstrained widths no longer supported");
|
|
|
|
NS_PRECONDITION(aContainingBlockWidth >= 0,
|
|
|
|
"width less than zero");
|
|
|
|
|
|
|
|
nscoord result;
|
2008-07-18 03:37:12 +04:00
|
|
|
if (eStyleUnit_Coord == aCoord.GetUnit()) {
|
|
|
|
result = aCoord.GetCoordValue();
|
2007-05-04 03:11:00 +04:00
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
result -= aContentEdgeToBoxSizing;
|
|
|
|
} else if (eStyleUnit_Percent == aCoord.GetUnit()) {
|
|
|
|
NS_ASSERTION(aCoord.GetPercentValue() >= 0.0f, "width less than zero");
|
|
|
|
result = NSToCoordFloor(aContainingBlockWidth * aCoord.GetPercentValue()) -
|
|
|
|
aContentEdgeToBoxSizing;
|
|
|
|
} else if (eStyleUnit_Enumerated == aCoord.GetUnit()) {
|
|
|
|
PRInt32 val = aCoord.GetIntValue();
|
|
|
|
switch (val) {
|
2007-11-15 21:10:31 +03:00
|
|
|
case NS_STYLE_WIDTH_MAX_CONTENT:
|
2007-05-04 03:11:00 +04:00
|
|
|
result = aFrame->GetPrefWidth(aRenderingContext);
|
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
break;
|
2007-11-15 21:10:31 +03:00
|
|
|
case NS_STYLE_WIDTH_MIN_CONTENT:
|
2007-05-04 03:11:00 +04:00
|
|
|
result = aFrame->GetMinWidth(aRenderingContext);
|
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
break;
|
2007-11-15 21:10:31 +03:00
|
|
|
case NS_STYLE_WIDTH_FIT_CONTENT:
|
2007-05-04 03:11:00 +04:00
|
|
|
{
|
|
|
|
nscoord pref = aFrame->GetPrefWidth(aRenderingContext),
|
|
|
|
min = aFrame->GetMinWidth(aRenderingContext),
|
|
|
|
fill = aContainingBlockWidth -
|
|
|
|
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
|
2009-09-16 19:01:36 +04:00
|
|
|
result = NS_MAX(min, NS_MIN(pref, fill));
|
2007-05-04 03:11:00 +04:00
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
}
|
|
|
|
break;
|
2007-11-15 21:10:31 +03:00
|
|
|
case NS_STYLE_WIDTH_AVAILABLE:
|
2007-05-04 03:11:00 +04:00
|
|
|
result = aContainingBlockWidth -
|
|
|
|
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("unexpected width value");
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
if (result < 0)
|
|
|
|
result = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* static */ nscoord
|
2006-12-18 16:20:18 +03:00
|
|
|
nsLayoutUtils::ComputeHeightDependentValue(
|
|
|
|
nscoord aContainingBlockHeight,
|
|
|
|
const nsStyleCoord& aCoord)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
2008-07-18 03:37:12 +04:00
|
|
|
if (eStyleUnit_Coord == aCoord.GetUnit()) {
|
|
|
|
return aCoord.GetCoordValue();
|
2006-12-17 17:06:42 +03:00
|
|
|
}
|
|
|
|
if (eStyleUnit_Percent == aCoord.GetUnit()) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXldb Some callers explicitly check aContainingBlockHeight
|
|
|
|
// against NS_AUTOHEIGHT *and* unit against eStyleUnit_Percent
|
|
|
|
// before calling this function, so this assertion probably needs to
|
|
|
|
// be inside the percentage case. However, it would be much more
|
|
|
|
// likely to catch problems if it were at the start of the function.
|
|
|
|
// XXXldb Many callers pass a non-'auto' containing block height when
|
|
|
|
// according to CSS2.1 they should be passing 'auto'.
|
|
|
|
NS_PRECONDITION(NS_AUTOHEIGHT != aContainingBlockHeight,
|
|
|
|
"unexpected 'containing block height'");
|
|
|
|
|
|
|
|
if (NS_AUTOHEIGHT != aContainingBlockHeight) {
|
2006-12-17 17:06:42 +03:00
|
|
|
return NSToCoordFloor(aContainingBlockHeight * aCoord.GetPercentValue());
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
}
|
2007-05-11 10:01:31 +04:00
|
|
|
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_None ||
|
2007-05-04 03:11:00 +04:00
|
|
|
aCoord.GetUnit() == eStyleUnit_Auto,
|
|
|
|
"unexpected height value");
|
2006-12-17 17:06:42 +03:00
|
|
|
return 0;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
inline PRBool
|
|
|
|
IsAutoHeight(const nsStyleCoord &aCoord, nscoord aCBHeight)
|
|
|
|
{
|
|
|
|
nsStyleUnit unit = aCoord.GetUnit();
|
|
|
|
return unit == eStyleUnit_Auto || // only for 'height'
|
2007-05-11 10:01:31 +04:00
|
|
|
unit == eStyleUnit_None || // only for 'max-height'
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
(unit == eStyleUnit_Percent &&
|
|
|
|
aCBHeight == NS_AUTOHEIGHT);
|
|
|
|
}
|
|
|
|
|
2007-02-19 02:11:32 +03:00
|
|
|
#define MULDIV(a,b,c) (nscoord(PRInt64(a) * PRInt64(b) / PRInt64(c)))
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
/* static */ nsSize
|
|
|
|
nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
|
2007-11-18 15:09:03 +03:00
|
|
|
nsIRenderingContext* aRenderingContext, nsIFrame* aFrame,
|
2007-11-18 17:22:55 +03:00
|
|
|
const nsIFrame::IntrinsicSize& aIntrinsicSize,
|
2007-11-18 15:09:03 +03:00
|
|
|
nsSize aIntrinsicRatio, nsSize aCBSize,
|
2007-05-04 03:11:00 +04:00
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
const nsStylePosition *stylePos = aFrame->GetStylePosition();
|
|
|
|
// 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).
|
|
|
|
|
2007-05-04 03:11:00 +04:00
|
|
|
const PRBool isAutoWidth = stylePos->mWidth.GetUnit() == eStyleUnit_Auto;
|
|
|
|
const PRBool isAutoHeight = IsAutoHeight(stylePos->mHeight, aCBSize.height);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
nsSize boxSizingAdjust(0,0);
|
|
|
|
switch (stylePos->mBoxSizing) {
|
|
|
|
case NS_STYLE_BOX_SIZING_BORDER:
|
|
|
|
boxSizingAdjust += aBorder;
|
|
|
|
// fall through
|
|
|
|
case NS_STYLE_BOX_SIZING_PADDING:
|
|
|
|
boxSizingAdjust += aPadding;
|
|
|
|
}
|
2007-05-04 03:11:00 +04:00
|
|
|
nscoord boxSizingToMarginEdgeWidth =
|
|
|
|
aMargin.width + aBorder.width + aPadding.width - boxSizingAdjust.width;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
nscoord width, minWidth, maxWidth, height, minHeight, maxHeight;
|
|
|
|
|
|
|
|
if (!isAutoWidth) {
|
2007-05-04 03:11:00 +04:00
|
|
|
width = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
|
|
|
|
aFrame, aCBSize.width, boxSizingAdjust.width,
|
|
|
|
boxSizingToMarginEdgeWidth, stylePos->mWidth);
|
|
|
|
NS_ASSERTION(width >= 0, "negative result from ComputeWidthValue");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2007-05-11 10:01:31 +04:00
|
|
|
if (stylePos->mMaxWidth.GetUnit() != eStyleUnit_None) {
|
2007-05-04 03:11:00 +04:00
|
|
|
maxWidth = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
|
|
|
|
aFrame, aCBSize.width, boxSizingAdjust.width,
|
|
|
|
boxSizingToMarginEdgeWidth, stylePos->mMaxWidth);
|
|
|
|
NS_ASSERTION(maxWidth >= 0, "negative result from ComputeWidthValue");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
} else {
|
|
|
|
maxWidth = nscoord_MAX;
|
|
|
|
}
|
|
|
|
|
2007-05-04 03:11:00 +04:00
|
|
|
minWidth = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
|
|
|
|
aFrame, aCBSize.width, boxSizingAdjust.width,
|
|
|
|
boxSizingToMarginEdgeWidth, stylePos->mMinWidth);
|
|
|
|
NS_ASSERTION(minWidth >= 0, "negative result from ComputeWidthValue");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
if (!isAutoHeight) {
|
2008-07-18 03:37:12 +04:00
|
|
|
height = nsLayoutUtils::
|
|
|
|
ComputeHeightDependentValue(aCBSize.height, stylePos->mHeight) -
|
|
|
|
boxSizingAdjust.height;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (height < 0)
|
|
|
|
height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsAutoHeight(stylePos->mMaxHeight, aCBSize.height)) {
|
2008-07-18 03:37:12 +04:00
|
|
|
maxHeight = nsLayoutUtils::
|
|
|
|
ComputeHeightDependentValue(aCBSize.height, stylePos->mMaxHeight) -
|
|
|
|
boxSizingAdjust.height;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (maxHeight < 0)
|
|
|
|
maxHeight = 0;
|
|
|
|
} else {
|
|
|
|
maxHeight = nscoord_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsAutoHeight(stylePos->mMinHeight, aCBSize.height)) {
|
2008-07-18 03:37:12 +04:00
|
|
|
minHeight = nsLayoutUtils::
|
|
|
|
ComputeHeightDependentValue(aCBSize.height, stylePos->mMinHeight) -
|
|
|
|
boxSizingAdjust.height;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (minHeight < 0)
|
|
|
|
minHeight = 0;
|
|
|
|
} else {
|
|
|
|
minHeight = 0;
|
|
|
|
}
|
|
|
|
|
2007-11-18 15:09:03 +03:00
|
|
|
// Resolve percentage intrinsic width/height as necessary:
|
|
|
|
|
|
|
|
NS_ASSERTION(aCBSize.width != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"Our containing block must not have unconstrained width!");
|
|
|
|
|
|
|
|
PRBool hasIntrinsicWidth, hasIntrinsicHeight;
|
|
|
|
nscoord intrinsicWidth, intrinsicHeight;
|
|
|
|
|
|
|
|
if (aIntrinsicSize.width.GetUnit() == eStyleUnit_Coord ||
|
|
|
|
aIntrinsicSize.width.GetUnit() == eStyleUnit_Percent) {
|
|
|
|
hasIntrinsicWidth = PR_TRUE;
|
|
|
|
intrinsicWidth = nsLayoutUtils::ComputeWidthValue(aRenderingContext,
|
|
|
|
aFrame, aCBSize.width, 0, boxSizingAdjust.width +
|
|
|
|
boxSizingToMarginEdgeWidth, aIntrinsicSize.width);
|
|
|
|
} else {
|
|
|
|
hasIntrinsicWidth = PR_FALSE;
|
|
|
|
intrinsicWidth = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIntrinsicSize.height.GetUnit() == eStyleUnit_Coord ||
|
|
|
|
(aIntrinsicSize.height.GetUnit() == eStyleUnit_Percent &&
|
|
|
|
aCBSize.height != NS_AUTOHEIGHT)) {
|
|
|
|
hasIntrinsicHeight = PR_TRUE;
|
2008-07-18 03:37:12 +04:00
|
|
|
intrinsicHeight = nsLayoutUtils::
|
|
|
|
ComputeHeightDependentValue(aCBSize.height, aIntrinsicSize.height);
|
2007-11-18 15:09:03 +03:00
|
|
|
if (intrinsicHeight < 0)
|
|
|
|
intrinsicHeight = 0;
|
|
|
|
} else {
|
|
|
|
hasIntrinsicHeight = PR_FALSE;
|
|
|
|
intrinsicHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aIntrinsicRatio.width >= 0 && aIntrinsicRatio.height >= 0,
|
|
|
|
"Intrinsic ratio has a negative component!");
|
|
|
|
|
|
|
|
// Now calculate the used values for width and height:
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (isAutoWidth) {
|
|
|
|
if (isAutoHeight) {
|
|
|
|
|
|
|
|
// 'auto' width, 'auto' height
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
|
|
// Get tentative values - CSS 2.1 sections 10.3.2 and 10.6.2:
|
|
|
|
|
|
|
|
nscoord tentWidth, tentHeight;
|
|
|
|
|
|
|
|
if (hasIntrinsicWidth) {
|
|
|
|
tentWidth = intrinsicWidth;
|
|
|
|
} else if (hasIntrinsicHeight && aIntrinsicRatio.height > 0) {
|
|
|
|
tentWidth = MULDIV(intrinsicHeight, aIntrinsicRatio.width, aIntrinsicRatio.height);
|
|
|
|
} else if (aIntrinsicRatio.width > 0) {
|
|
|
|
tentWidth = aCBSize.width - boxSizingToMarginEdgeWidth; // XXX scrollbar?
|
|
|
|
if (tentWidth < 0) tentWidth = 0;
|
|
|
|
} else {
|
|
|
|
tentWidth = nsPresContext::CSSPixelsToAppUnits(300);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasIntrinsicHeight) {
|
|
|
|
tentHeight = intrinsicHeight;
|
|
|
|
} else if (aIntrinsicRatio.width > 0) {
|
|
|
|
tentHeight = MULDIV(tentWidth, aIntrinsicRatio.height, aIntrinsicRatio.width);
|
|
|
|
} else {
|
|
|
|
tentHeight = nsPresContext::CSSPixelsToAppUnits(150);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now apply min/max-width/height - CSS 2.1 sections 10.4 and 10.7:
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (minWidth > maxWidth)
|
|
|
|
maxWidth = minWidth;
|
|
|
|
if (minHeight > maxHeight)
|
|
|
|
maxHeight = minHeight;
|
|
|
|
|
|
|
|
nscoord heightAtMaxWidth, heightAtMinWidth,
|
|
|
|
widthAtMaxHeight, widthAtMinHeight;
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
|
|
if (tentWidth > 0) {
|
|
|
|
heightAtMaxWidth = MULDIV(maxWidth, tentHeight, tentWidth);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (heightAtMaxWidth < minHeight)
|
|
|
|
heightAtMaxWidth = minHeight;
|
2007-11-18 15:09:03 +03:00
|
|
|
heightAtMinWidth = MULDIV(minWidth, tentHeight, tentWidth);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (heightAtMinWidth > maxHeight)
|
|
|
|
heightAtMinWidth = maxHeight;
|
|
|
|
} else {
|
2007-11-18 15:09:03 +03:00
|
|
|
heightAtMaxWidth = tentHeight;
|
|
|
|
heightAtMinWidth = tentHeight;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2007-11-18 15:09:03 +03:00
|
|
|
if (tentHeight > 0) {
|
|
|
|
widthAtMaxHeight = MULDIV(maxHeight, tentWidth, tentHeight);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (widthAtMaxHeight < minWidth)
|
|
|
|
widthAtMaxHeight = minWidth;
|
2007-11-18 15:09:03 +03:00
|
|
|
widthAtMinHeight = MULDIV(minHeight, tentWidth, tentHeight);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (widthAtMinHeight > maxWidth)
|
|
|
|
widthAtMinHeight = maxWidth;
|
|
|
|
} else {
|
2007-11-18 15:09:03 +03:00
|
|
|
widthAtMaxHeight = tentWidth;
|
|
|
|
widthAtMinHeight = tentWidth;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2007-11-18 15:09:03 +03:00
|
|
|
// The table at http://www.w3.org/TR/CSS21/visudet.html#min-max-widths :
|
|
|
|
|
|
|
|
if (tentWidth > maxWidth) {
|
|
|
|
if (tentHeight > maxHeight) {
|
|
|
|
if (PRInt64(maxWidth) * PRInt64(tentHeight) <=
|
|
|
|
PRInt64(maxHeight) * PRInt64(tentWidth)) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
width = maxWidth;
|
|
|
|
height = heightAtMaxWidth;
|
|
|
|
} else {
|
|
|
|
width = widthAtMaxHeight;
|
2007-11-18 15:09:03 +03:00
|
|
|
height = maxHeight;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
} else {
|
2007-11-18 15:09:03 +03:00
|
|
|
// This also covers "(w > max-width) and (h < min-height)" since in
|
|
|
|
// that case (max-width/w < 1), and with (h < min-height):
|
|
|
|
// max(max-width * h/w, min-height) == min-height
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
width = maxWidth;
|
|
|
|
height = heightAtMaxWidth;
|
|
|
|
}
|
2007-11-18 15:09:03 +03:00
|
|
|
} else if (tentWidth < minWidth) {
|
|
|
|
if (tentHeight < minHeight) {
|
|
|
|
if (PRInt64(minWidth) * PRInt64(tentHeight) <=
|
|
|
|
PRInt64(minHeight) * PRInt64(tentWidth)) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
width = widthAtMinHeight;
|
2007-11-18 15:09:03 +03:00
|
|
|
height = minHeight;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
} else {
|
|
|
|
width = minWidth;
|
|
|
|
height = heightAtMinWidth;
|
|
|
|
}
|
|
|
|
} else {
|
2007-11-18 15:09:03 +03:00
|
|
|
// This also covers "(w < min-width) and (h > max-height)" since in
|
|
|
|
// that case (min-width/w > 1), and with (h > max-height):
|
|
|
|
// min(min-width * h/w, max-height) == max-height
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
width = minWidth;
|
|
|
|
height = heightAtMinWidth;
|
|
|
|
}
|
|
|
|
} else {
|
2007-11-18 15:09:03 +03:00
|
|
|
if (tentHeight > maxHeight) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
width = widthAtMaxHeight;
|
2007-11-18 15:09:03 +03:00
|
|
|
height = maxHeight;
|
|
|
|
} else if (tentHeight < minHeight) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
width = widthAtMinHeight;
|
2007-11-18 15:09:03 +03:00
|
|
|
height = minHeight;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
} else {
|
2007-11-18 15:09:03 +03:00
|
|
|
width = tentWidth;
|
|
|
|
height = tentHeight;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 'auto' width, non-'auto' height
|
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
2007-11-18 15:09:03 +03:00
|
|
|
if (aIntrinsicRatio.height > 0) {
|
|
|
|
width = MULDIV(height, aIntrinsicRatio.width, aIntrinsicRatio.height);
|
|
|
|
} else if (hasIntrinsicWidth) {
|
|
|
|
width = intrinsicWidth;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
} else {
|
2007-11-18 15:09:03 +03:00
|
|
|
width = nsPresContext::CSSPixelsToAppUnits(300);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isAutoHeight) {
|
|
|
|
|
|
|
|
// non-'auto' width, 'auto' height
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
2007-11-18 15:09:03 +03:00
|
|
|
if (aIntrinsicRatio.width > 0) {
|
|
|
|
height = MULDIV(width, aIntrinsicRatio.height, aIntrinsicRatio.width);
|
|
|
|
} else if (hasIntrinsicHeight) {
|
|
|
|
height = intrinsicHeight;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
} else {
|
2007-11-18 15:09:03 +03:00
|
|
|
height = nsPresContext::CSSPixelsToAppUnits(150);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// non-'auto' width, non-'auto' height
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
2007-11-18 15:09:03 +03:00
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsSize(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
2007-01-23 07:06:56 +03:00
|
|
|
nsLayoutUtils::MinWidthFromInline(nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
nsIFrame::InlineMinWidthData data;
|
|
|
|
DISPLAY_MIN_WIDTH(aFrame, data.prevLines);
|
|
|
|
aFrame->AddInlineMinWidth(aRenderingContext, &data);
|
2007-06-22 02:32:47 +04:00
|
|
|
data.ForceBreak(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
return data.prevLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
2007-01-23 07:06:56 +03:00
|
|
|
nsLayoutUtils::PrefWidthFromInline(nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
nsIFrame::InlinePrefWidthData data;
|
|
|
|
DISPLAY_PREF_WIDTH(aFrame, data.prevLines);
|
|
|
|
aFrame->AddInlinePrefWidth(aRenderingContext, &data);
|
2007-06-22 02:32:47 +04:00
|
|
|
data.ForceBreak(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
return data.prevLines;
|
|
|
|
}
|
2007-01-23 05:58:55 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutUtils::DrawString(const nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aContext,
|
|
|
|
const PRUnichar* aString,
|
|
|
|
PRInt32 aLength,
|
2009-02-15 10:21:40 +03:00
|
|
|
nsPoint aPoint,
|
|
|
|
PRUint8 aDirection)
|
2007-01-23 05:58:55 +03:00
|
|
|
{
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2007-01-25 22:54:38 +03:00
|
|
|
if (presContext->BidiEnabled()) {
|
|
|
|
nsBidiPresUtils* bidiUtils = presContext->GetBidiUtils();
|
2007-01-23 05:58:55 +03:00
|
|
|
|
2007-01-25 22:54:38 +03:00
|
|
|
if (bidiUtils) {
|
2009-02-15 10:21:40 +03:00
|
|
|
if (aDirection == NS_STYLE_DIRECTION_INHERIT) {
|
|
|
|
aDirection = aFrame->GetStyleVisibility()->mDirection;
|
|
|
|
}
|
2007-01-25 22:54:38 +03:00
|
|
|
nsBidiDirection direction =
|
2009-02-15 10:21:40 +03:00
|
|
|
(NS_STYLE_DIRECTION_RTL == aDirection) ?
|
2007-01-25 22:54:38 +03:00
|
|
|
NSBIDI_RTL : NSBIDI_LTR;
|
|
|
|
rv = bidiUtils->RenderText(aString, aLength, direction,
|
|
|
|
presContext, *aContext,
|
|
|
|
aPoint.x, aPoint.y);
|
|
|
|
}
|
2007-01-23 05:58:55 +03:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
#endif // IBMBIDI
|
|
|
|
{
|
|
|
|
aContext->SetTextRunRTL(PR_FALSE);
|
|
|
|
aContext->DrawString(aString, aLength, aPoint.x, aPoint.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsLayoutUtils::GetStringWidth(const nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aContext,
|
|
|
|
const PRUnichar* aString,
|
|
|
|
PRInt32 aLength)
|
|
|
|
{
|
2007-01-25 04:58:55 +03:00
|
|
|
#ifdef IBMBIDI
|
2008-08-11 19:19:01 +04:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
if (presContext->BidiEnabled()) {
|
|
|
|
nsBidiPresUtils* bidiUtils = presContext->GetBidiUtils();
|
|
|
|
|
|
|
|
if (bidiUtils) {
|
|
|
|
const nsStyleVisibility* vis = aFrame->GetStyleVisibility();
|
|
|
|
nsBidiDirection direction =
|
|
|
|
(NS_STYLE_DIRECTION_RTL == vis->mDirection) ?
|
|
|
|
NSBIDI_RTL : NSBIDI_LTR;
|
|
|
|
return bidiUtils->MeasureTextWidth(aString, aLength,
|
|
|
|
direction, presContext, *aContext);
|
2007-01-25 04:58:55 +03:00
|
|
|
}
|
2007-01-23 05:58:55 +03:00
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
aContext->SetTextRunRTL(PR_FALSE);
|
|
|
|
nscoord width;
|
|
|
|
aContext->GetWidth(aString, aLength, width);
|
|
|
|
return width;
|
|
|
|
}
|
2007-01-23 07:06:56 +03:00
|
|
|
|
2009-05-19 02:13:12 +04:00
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::GetCenteredFontBaseline(nsIFontMetrics* aFontMetrics,
|
|
|
|
nscoord aLineHeight)
|
|
|
|
{
|
|
|
|
nscoord fontAscent, fontHeight;
|
|
|
|
aFontMetrics->GetMaxAscent(fontAscent);
|
|
|
|
aFontMetrics->GetHeight(fontHeight);
|
|
|
|
|
|
|
|
nscoord leading = aLineHeight - fontHeight;
|
|
|
|
return fontAscent + leading/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-23 07:06:56 +03:00
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::GetFirstLineBaseline(const nsIFrame* aFrame, nscoord* aResult)
|
2009-04-09 00:52:36 +04:00
|
|
|
{
|
|
|
|
LinePosition position;
|
|
|
|
if (!GetFirstLinePosition(aFrame, &position))
|
|
|
|
return PR_FALSE;
|
|
|
|
*aResult = position.mBaseline;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::GetFirstLinePosition(const nsIFrame* aFrame,
|
|
|
|
LinePosition* aResult)
|
2007-01-23 07:06:56 +03:00
|
|
|
{
|
2008-07-14 02:10:23 +04:00
|
|
|
const nsBlockFrame* block = nsLayoutUtils::GetAsBlock(const_cast<nsIFrame*>(aFrame));
|
|
|
|
if (!block) {
|
2007-01-23 07:06:56 +03:00
|
|
|
// For the first-line baseline we also have to check for a table, and if
|
|
|
|
// so, use the baseline of its first row.
|
|
|
|
nsIAtom* fType = aFrame->GetType();
|
|
|
|
if (fType == nsGkAtoms::tableOuterFrame) {
|
2009-04-09 00:52:36 +04:00
|
|
|
aResult->mTop = 0;
|
|
|
|
aResult->mBaseline = aFrame->GetBaseline();
|
|
|
|
// This is what we want for the list bullet caller; not sure if
|
|
|
|
// other future callers will want the same.
|
|
|
|
aResult->mBottom = aFrame->GetSize().height;
|
2007-01-23 07:06:56 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For first-line baselines, we have to consider scroll frames.
|
|
|
|
if (fType == nsGkAtoms::scrollFrame) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIScrollableFrame *sFrame = do_QueryFrame(const_cast<nsIFrame*>(aFrame));
|
|
|
|
if (!sFrame) {
|
2007-01-23 07:06:56 +03:00
|
|
|
NS_NOTREACHED("not scroll frame");
|
|
|
|
}
|
2009-04-09 00:52:36 +04:00
|
|
|
LinePosition kidPosition;
|
|
|
|
if (GetFirstLinePosition(sFrame->GetScrolledFrame(), &kidPosition)) {
|
2007-01-23 07:06:56 +03:00
|
|
|
// Consider only the border and padding that contributes to the
|
|
|
|
// kid's position, not the scrolling, so we get the initial
|
|
|
|
// position.
|
2009-04-09 00:52:36 +04:00
|
|
|
*aResult = kidPosition + aFrame->GetUsedBorderAndPadding().top;
|
2007-01-23 07:06:56 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No baseline.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nsBlockFrame::const_line_iterator line = block->begin_lines(),
|
|
|
|
line_end = block->end_lines();
|
|
|
|
line != line_end; ++line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
nsIFrame *kid = line->mFirstChild;
|
2009-04-09 00:52:36 +04:00
|
|
|
LinePosition kidPosition;
|
|
|
|
if (GetFirstLinePosition(kid, &kidPosition)) {
|
|
|
|
*aResult = kidPosition + kid->GetPosition().y;
|
2007-01-23 07:06:56 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// XXX Is this the right test? We have some bogus empty lines
|
|
|
|
// floating around, but IsEmpty is perhaps too weak.
|
|
|
|
if (line->GetHeight() != 0 || !line->IsEmpty()) {
|
2009-04-09 00:52:36 +04:00
|
|
|
nscoord top = line->mBounds.y;
|
|
|
|
aResult->mTop = top;
|
|
|
|
aResult->mBaseline = top + line->GetAscent();
|
|
|
|
aResult->mBottom = top + line->GetHeight();
|
2007-01-23 07:06:56 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::GetLastLineBaseline(const nsIFrame* aFrame, nscoord* aResult)
|
|
|
|
{
|
2008-07-14 02:10:23 +04:00
|
|
|
const nsBlockFrame* block = nsLayoutUtils::GetAsBlock(const_cast<nsIFrame*>(aFrame));
|
|
|
|
if (!block)
|
2007-01-23 07:06:56 +03:00
|
|
|
// No baseline. (We intentionally don't descend into scroll frames.)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
for (nsBlockFrame::const_reverse_line_iterator line = block->rbegin_lines(),
|
|
|
|
line_end = block->rend_lines();
|
|
|
|
line != line_end; ++line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
nsIFrame *kid = line->mFirstChild;
|
|
|
|
nscoord kidBaseline;
|
|
|
|
if (GetLastLineBaseline(kid, &kidBaseline)) {
|
|
|
|
*aResult = kidBaseline + kid->GetPosition().y;
|
|
|
|
return PR_TRUE;
|
|
|
|
} else if (kid->GetType() == nsGkAtoms::scrollFrame) {
|
|
|
|
// Use the bottom of the scroll frame.
|
|
|
|
// XXX CSS2.1 really doesn't say what to do here.
|
|
|
|
*aResult = kid->GetRect().YMost();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// XXX Is this the right test? We have some bogus empty lines
|
|
|
|
// floating around, but IsEmpty is perhaps too weak.
|
|
|
|
if (line->GetHeight() != 0 || !line->IsEmpty()) {
|
|
|
|
*aResult = line->mBounds.y + line->GetAscent();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2007-02-18 13:43:12 +03:00
|
|
|
|
2008-04-18 11:40:35 +04:00
|
|
|
static nscoord
|
|
|
|
CalculateBlockContentBottom(nsBlockFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
|
|
|
|
nscoord contentBottom = 0;
|
|
|
|
|
|
|
|
for (nsBlockFrame::line_iterator line = aFrame->begin_lines(),
|
|
|
|
line_end = aFrame->end_lines();
|
|
|
|
line != line_end; ++line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
nsIFrame* child = line->mFirstChild;
|
|
|
|
nscoord offset = child->GetRect().y - child->GetRelativeOffset().y;
|
2009-08-22 21:10:11 +04:00
|
|
|
contentBottom = NS_MAX(contentBottom,
|
2008-04-18 11:40:35 +04:00
|
|
|
nsLayoutUtils::CalculateContentBottom(child) + offset);
|
|
|
|
}
|
|
|
|
else {
|
2009-08-22 21:10:11 +04:00
|
|
|
contentBottom = NS_MAX(contentBottom, line->mBounds.YMost());
|
2008-04-18 11:40:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return contentBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nscoord
|
|
|
|
nsLayoutUtils::CalculateContentBottom(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
|
|
|
|
|
|
|
nscoord contentBottom = aFrame->GetRect().height;
|
|
|
|
|
|
|
|
if (aFrame->GetOverflowRect().height > contentBottom) {
|
|
|
|
nsBlockFrame* blockFrame = GetAsBlock(aFrame);
|
|
|
|
nsIAtom* childList = nsnull;
|
|
|
|
PRIntn nextListID = 0;
|
|
|
|
do {
|
|
|
|
if (childList == nsnull && blockFrame) {
|
2009-08-22 21:10:11 +04:00
|
|
|
contentBottom = NS_MAX(contentBottom, CalculateBlockContentBottom(blockFrame));
|
2008-04-18 11:40:35 +04:00
|
|
|
}
|
|
|
|
else if (childList != nsGkAtoms::overflowList &&
|
|
|
|
childList != nsGkAtoms::excessOverflowContainersList &&
|
|
|
|
childList != nsGkAtoms::overflowOutOfFlowList)
|
|
|
|
{
|
|
|
|
for (nsIFrame* child = aFrame->GetFirstChild(childList);
|
|
|
|
child; child = child->GetNextSibling())
|
|
|
|
{
|
|
|
|
nscoord offset = child->GetRect().y - child->GetRelativeOffset().y;
|
2009-08-22 21:10:11 +04:00
|
|
|
contentBottom = NS_MAX(contentBottom,
|
2008-04-18 11:40:35 +04:00
|
|
|
CalculateContentBottom(child) + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
childList = aFrame->GetAdditionalChildListName(nextListID);
|
|
|
|
nextListID++;
|
|
|
|
} while (childList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return contentBottom;
|
|
|
|
}
|
|
|
|
|
2007-02-18 13:43:12 +03:00
|
|
|
/* static */ nsIFrame*
|
|
|
|
nsLayoutUtils::GetClosestLayer(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* layer;
|
|
|
|
for (layer = aFrame; layer; layer = layer->GetParent()) {
|
|
|
|
if (layer->GetStyleDisplay()->IsPositioned() ||
|
|
|
|
(layer->GetParent() &&
|
|
|
|
layer->GetParent()->GetType() == nsGkAtoms::scrollFrame))
|
|
|
|
break;
|
|
|
|
}
|
2007-02-20 03:26:53 +03:00
|
|
|
if (layer)
|
|
|
|
return layer;
|
2007-03-31 01:11:41 +04:00
|
|
|
return aFrame->PresContext()->PresShell()->FrameManager()->GetRootFrame();
|
2007-02-18 13:43:12 +03:00
|
|
|
}
|
2007-03-20 03:58:20 +03:00
|
|
|
|
2009-04-05 13:52:14 +04:00
|
|
|
gfxPattern::GraphicsFilter
|
2009-04-10 17:41:59 +04:00
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(nsIFrame* aForFrame)
|
2009-04-05 13:52:14 +04:00
|
|
|
{
|
|
|
|
#ifdef MOZ_SVG
|
2009-04-10 17:41:59 +04:00
|
|
|
nsIFrame *frame = nsCSSRendering::IsCanvasFrame(aForFrame) ?
|
|
|
|
nsCSSRendering::FindRootFrame(aForFrame) : aForFrame;
|
|
|
|
|
|
|
|
switch (frame->GetStyleSVG()->mImageRendering) {
|
2009-04-05 13:52:14 +04:00
|
|
|
case NS_STYLE_IMAGE_RENDERING_OPTIMIZESPEED:
|
|
|
|
return gfxPattern::FILTER_FAST;
|
|
|
|
case NS_STYLE_IMAGE_RENDERING_OPTIMIZEQUALITY:
|
|
|
|
return gfxPattern::FILTER_BEST;
|
|
|
|
case NS_STYLE_IMAGE_RENDERING_CRISPEDGES:
|
|
|
|
return gfxPattern::FILTER_NEAREST;
|
|
|
|
default:
|
|
|
|
return gfxPattern::FILTER_GOOD;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
return gfxPattern::FILTER_GOOD;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-11-18 10:48:46 +03:00
|
|
|
/**
|
|
|
|
* Given an image being drawn into an appunit coordinate system, and
|
|
|
|
* a point in that coordinate system, map the point back into image
|
|
|
|
* pixel space.
|
|
|
|
* @param aSize the size of the image, in pixels
|
|
|
|
* @param aDest the rectangle that the image is being mapped into
|
|
|
|
* @param aPt a point in the same coordinate system as the rectangle
|
|
|
|
*/
|
2008-11-05 01:01:21 +03:00
|
|
|
static gfxPoint
|
2008-12-03 04:32:18 +03:00
|
|
|
MapToFloatImagePixels(const gfxSize& aSize,
|
|
|
|
const gfxRect& aDest, const gfxPoint& aPt)
|
2008-11-05 01:01:21 +03:00
|
|
|
{
|
2008-12-03 04:32:18 +03:00
|
|
|
return gfxPoint(((aPt.x - aDest.pos.x)*aSize.width)/aDest.size.width,
|
|
|
|
((aPt.y - aDest.pos.y)*aSize.height)/aDest.size.height);
|
2008-11-05 01:01:21 +03:00
|
|
|
}
|
|
|
|
|
2008-11-18 10:48:46 +03:00
|
|
|
/**
|
|
|
|
* Given an image being drawn into an pixel-based coordinate system, and
|
|
|
|
* a point in image space, map the point into the pixel-based coordinate
|
|
|
|
* system.
|
|
|
|
* @param aSize the size of the image, in pixels
|
|
|
|
* @param aDest the rectangle that the image is being mapped into
|
|
|
|
* @param aPt a point in image space
|
|
|
|
*/
|
|
|
|
static gfxPoint
|
2008-12-03 04:32:18 +03:00
|
|
|
MapToFloatUserPixels(const gfxSize& aSize,
|
2008-11-18 10:48:46 +03:00
|
|
|
const gfxRect& aDest, const gfxPoint& aPt)
|
|
|
|
{
|
|
|
|
return gfxPoint(aPt.x*aDest.size.width/aSize.width + aDest.pos.x,
|
|
|
|
aPt.y*aDest.size.height/aSize.height + aDest.pos.y);
|
|
|
|
}
|
|
|
|
|
2009-01-30 10:33:57 +03:00
|
|
|
static nsresult
|
|
|
|
DrawImageInternal(nsIRenderingContext* aRenderingContext,
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
imgIContainer* aImage,
|
2009-04-05 13:52:14 +04:00
|
|
|
gfxPattern::GraphicsFilter aGraphicsFilter,
|
2009-01-30 10:33:57 +03:00
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
const nsRect& aDirty,
|
2009-09-13 02:44:18 +04:00
|
|
|
const nsIntSize& aImageSize,
|
|
|
|
PRUint32 aImageFlags)
|
2008-11-05 01:01:21 +03:00
|
|
|
{
|
2008-11-07 03:58:42 +03:00
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty())
|
2007-03-20 03:58:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
aRenderingContext->GetDeviceContext(*getter_AddRefs(dc));
|
|
|
|
gfxFloat appUnitsPerDevPixel = dc->AppUnitsPerDevPixel();
|
|
|
|
gfxContext *ctx = aRenderingContext->ThebesContext();
|
|
|
|
|
2008-12-03 04:32:18 +03:00
|
|
|
gfxRect devPixelDest(aDest.x/appUnitsPerDevPixel,
|
|
|
|
aDest.y/appUnitsPerDevPixel,
|
|
|
|
aDest.width/appUnitsPerDevPixel,
|
|
|
|
aDest.height/appUnitsPerDevPixel);
|
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
// Compute the pixel-snapped area that should be drawn
|
2008-11-07 03:58:42 +03:00
|
|
|
gfxRect devPixelFill(aFill.x/appUnitsPerDevPixel,
|
|
|
|
aFill.y/appUnitsPerDevPixel,
|
|
|
|
aFill.width/appUnitsPerDevPixel,
|
|
|
|
aFill.height/appUnitsPerDevPixel);
|
2008-11-05 01:01:21 +03:00
|
|
|
PRBool ignoreScale = PR_FALSE;
|
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
ignoreScale = PR_TRUE;
|
|
|
|
#endif
|
2008-11-07 03:58:42 +03:00
|
|
|
gfxRect fill = devPixelFill;
|
2008-11-05 01:01:21 +03:00
|
|
|
PRBool didSnap = ctx->UserToDevicePixelSnapped(fill, ignoreScale);
|
|
|
|
|
|
|
|
// Compute dirty rect in gfx space
|
|
|
|
gfxRect dirty(aDirty.x/appUnitsPerDevPixel,
|
|
|
|
aDirty.y/appUnitsPerDevPixel,
|
|
|
|
aDirty.width/appUnitsPerDevPixel,
|
|
|
|
aDirty.height/appUnitsPerDevPixel);
|
|
|
|
|
2009-01-30 10:33:57 +03:00
|
|
|
gfxSize imageSize(aImageSize.width, aImageSize.height);
|
2007-03-20 03:58:20 +03:00
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
// Compute the set of pixels that would be sampled by an ideal rendering
|
|
|
|
gfxPoint subimageTopLeft =
|
2008-12-03 05:02:29 +03:00
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.TopLeft());
|
2008-11-05 01:01:21 +03:00
|
|
|
gfxPoint subimageBottomRight =
|
2008-12-03 05:02:29 +03:00
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, devPixelFill.BottomRight());
|
2008-11-05 01:01:21 +03:00
|
|
|
nsIntRect intSubimage;
|
|
|
|
intSubimage.MoveTo(NSToIntFloor(subimageTopLeft.x),
|
|
|
|
NSToIntFloor(subimageTopLeft.y));
|
|
|
|
intSubimage.SizeTo(NSToIntCeil(subimageBottomRight.x) - intSubimage.x,
|
|
|
|
NSToIntCeil(subimageBottomRight.y) - intSubimage.y);
|
|
|
|
|
|
|
|
// Compute the anchor point and compute final fill rect.
|
|
|
|
// This code assumes that pixel-based devices have one pixel per
|
|
|
|
// device unit!
|
|
|
|
gfxPoint anchorPoint(aAnchor.x/appUnitsPerDevPixel,
|
|
|
|
aAnchor.y/appUnitsPerDevPixel);
|
2008-11-18 10:48:46 +03:00
|
|
|
gfxPoint imageSpaceAnchorPoint =
|
2008-12-03 05:02:29 +03:00
|
|
|
MapToFloatImagePixels(imageSize, devPixelDest, anchorPoint);
|
2008-12-02 23:46:44 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(ctx);
|
2008-11-18 10:48:46 +03:00
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
if (didSnap) {
|
2008-12-02 23:46:44 +03:00
|
|
|
NS_ASSERTION(!saveMatrix.Matrix().HasNonAxisAlignedTransform(),
|
2008-11-07 03:58:42 +03:00
|
|
|
"How did we snap, then?");
|
2008-11-18 10:48:46 +03:00
|
|
|
imageSpaceAnchorPoint.Round();
|
|
|
|
anchorPoint = imageSpaceAnchorPoint;
|
|
|
|
anchorPoint = MapToFloatUserPixels(imageSize, devPixelDest, anchorPoint);
|
2008-12-02 23:46:44 +03:00
|
|
|
anchorPoint = saveMatrix.Matrix().Transform(anchorPoint);
|
2008-11-18 00:13:55 +03:00
|
|
|
anchorPoint.Round();
|
2008-11-05 01:01:21 +03:00
|
|
|
|
|
|
|
// This form of Transform is safe to call since non-axis-aligned
|
|
|
|
// transforms wouldn't be snapped.
|
2008-12-02 23:46:44 +03:00
|
|
|
dirty = saveMatrix.Matrix().Transform(dirty);
|
2008-11-05 01:01:21 +03:00
|
|
|
|
|
|
|
ctx->IdentityMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFloat scaleX = imageSize.width*appUnitsPerDevPixel/aDest.width;
|
|
|
|
gfxFloat scaleY = imageSize.height*appUnitsPerDevPixel/aDest.height;
|
|
|
|
if (didSnap) {
|
|
|
|
// ctx now has the identity matrix, so we need to adjust our
|
|
|
|
// scales to match
|
2008-12-02 23:46:44 +03:00
|
|
|
scaleX /= saveMatrix.Matrix().xx;
|
|
|
|
scaleY /= saveMatrix.Matrix().yy;
|
2008-11-05 01:01:21 +03:00
|
|
|
}
|
|
|
|
gfxFloat translateX = imageSpaceAnchorPoint.x - anchorPoint.x*scaleX;
|
|
|
|
gfxFloat translateY = imageSpaceAnchorPoint.y - anchorPoint.y*scaleY;
|
|
|
|
gfxMatrix transform(scaleX, 0, 0, scaleY, translateX, translateY);
|
|
|
|
|
2008-12-02 23:46:44 +03:00
|
|
|
gfxRect finalFillRect = fill;
|
|
|
|
// If the user-space-to-image-space transform is not a straight
|
|
|
|
// translation by integers, then filtering will occur, and
|
|
|
|
// restricting the fill rect to the dirty rect would change the values
|
|
|
|
// computed for edge pixels, which we can't allow.
|
|
|
|
// Also, if didSnap is false then rounding out 'dirty' might not
|
|
|
|
// produce pixel-aligned coordinates, which would also break the values
|
|
|
|
// computed for edge pixels.
|
|
|
|
if (didSnap && !transform.HasNonIntegerTranslation()) {
|
|
|
|
dirty.RoundOut();
|
|
|
|
finalFillRect = fill.Intersect(dirty);
|
|
|
|
}
|
|
|
|
if (finalFillRect.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
aImage->Draw(ctx, aGraphicsFilter, transform, finalFillRect, intSubimage,
|
|
|
|
aImageFlags);
|
2008-11-05 01:01:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-20 03:58:20 +03:00
|
|
|
|
2009-07-28 03:48:13 +04:00
|
|
|
/* static */ nsresult
|
|
|
|
nsLayoutUtils::DrawSingleUnscaledImage(nsIRenderingContext* aRenderingContext,
|
|
|
|
imgIContainer* aImage,
|
|
|
|
const nsPoint& aDest,
|
|
|
|
const nsRect& aDirty,
|
2009-09-13 02:44:18 +04:00
|
|
|
PRUint32 aImageFlags,
|
2009-07-28 03:48:13 +04:00
|
|
|
const nsRect* aSourceArea)
|
|
|
|
{
|
|
|
|
nsIntSize imageSize;
|
|
|
|
aImage->GetWidth(&imageSize.width);
|
|
|
|
aImage->GetHeight(&imageSize.height);
|
|
|
|
NS_ENSURE_TRUE(imageSize.width > 0 && imageSize.height > 0, NS_ERROR_FAILURE);
|
2008-11-05 01:01:21 +03:00
|
|
|
|
|
|
|
nscoord appUnitsPerCSSPixel = nsIDeviceContext::AppUnitsPerCSSPixel();
|
2009-07-28 03:48:13 +04:00
|
|
|
nsSize size(imageSize.width*appUnitsPerCSSPixel,
|
|
|
|
imageSize.height*appUnitsPerCSSPixel);
|
2009-01-30 10:33:57 +03:00
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
nsRect source;
|
|
|
|
if (aSourceArea) {
|
|
|
|
source = *aSourceArea;
|
|
|
|
} else {
|
2009-01-30 10:33:57 +03:00
|
|
|
source.SizeTo(size);
|
2007-03-20 03:58:20 +03:00
|
|
|
}
|
|
|
|
|
2009-01-30 10:33:57 +03:00
|
|
|
nsRect dest(aDest - source.TopLeft(), size);
|
2008-11-05 01:01:21 +03:00
|
|
|
nsRect fill(aDest, source.Size());
|
2008-11-10 10:24:21 +03:00
|
|
|
// Ensure that only a single image tile is drawn. If aSourceArea extends
|
|
|
|
// outside the image bounds, we want to honor the aSourceArea-to-aDest
|
|
|
|
// translation but we don't want to actually tile the image.
|
|
|
|
fill.IntersectRect(fill, dest);
|
2009-04-05 13:52:14 +04:00
|
|
|
return DrawImageInternal(aRenderingContext, aImage, gfxPattern::FILTER_NEAREST,
|
2009-09-13 02:44:18 +04:00
|
|
|
dest, fill, aDest, aDirty, imageSize, aImageFlags);
|
2008-11-05 01:01:21 +03:00
|
|
|
}
|
2009-07-28 03:48:13 +04:00
|
|
|
|
|
|
|
/* static */ nsresult
|
|
|
|
nsLayoutUtils::DrawSingleImage(nsIRenderingContext* aRenderingContext,
|
|
|
|
imgIContainer* aImage,
|
|
|
|
gfxPattern::GraphicsFilter aGraphicsFilter,
|
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aDirty,
|
2009-09-13 02:44:18 +04:00
|
|
|
PRUint32 aImageFlags,
|
2009-07-28 03:48:13 +04:00
|
|
|
const nsRect* aSourceArea)
|
|
|
|
{
|
|
|
|
nsIntSize imageSize;
|
|
|
|
aImage->GetWidth(&imageSize.width);
|
|
|
|
aImage->GetHeight(&imageSize.height);
|
|
|
|
NS_ENSURE_TRUE(imageSize.width > 0 && imageSize.height > 0, NS_ERROR_FAILURE);
|
2009-01-30 10:33:57 +03:00
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
nsRect source;
|
|
|
|
if (aSourceArea) {
|
|
|
|
source = *aSourceArea;
|
|
|
|
} else {
|
2009-01-30 10:33:57 +03:00
|
|
|
nscoord appUnitsPerCSSPixel = nsIDeviceContext::AppUnitsPerCSSPixel();
|
2009-07-28 03:48:13 +04:00
|
|
|
source.SizeTo(imageSize.width*appUnitsPerCSSPixel,
|
|
|
|
imageSize.height*appUnitsPerCSSPixel);
|
2007-03-20 03:58:20 +03:00
|
|
|
}
|
|
|
|
|
2009-07-28 03:48:13 +04:00
|
|
|
nsRect dest = nsLayoutUtils::GetWholeImageDestination(imageSize, source,
|
2009-01-30 10:33:57 +03:00
|
|
|
aDest);
|
2008-11-10 10:24:21 +03:00
|
|
|
// Ensure that only a single image tile is drawn. If aSourceArea extends
|
|
|
|
// outside the image bounds, we want to honor the aSourceArea-to-aDest
|
|
|
|
// transform but we don't want to actually tile the image.
|
|
|
|
nsRect fill;
|
|
|
|
fill.IntersectRect(aDest, dest);
|
2009-04-05 13:52:14 +04:00
|
|
|
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter, dest, fill,
|
2009-09-13 02:44:18 +04:00
|
|
|
fill.TopLeft(), aDirty, imageSize, aImageFlags);
|
2009-01-30 10:33:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
|
|
|
nsLayoutUtils::DrawImage(nsIRenderingContext* aRenderingContext,
|
|
|
|
imgIContainer* aImage,
|
2009-04-05 13:52:14 +04:00
|
|
|
gfxPattern::GraphicsFilter aGraphicsFilter,
|
2009-01-30 10:33:57 +03:00
|
|
|
const nsRect& aDest,
|
|
|
|
const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor,
|
2009-09-13 02:44:18 +04:00
|
|
|
const nsRect& aDirty,
|
|
|
|
PRUint32 aImageFlags)
|
2009-01-30 10:33:57 +03:00
|
|
|
{
|
|
|
|
nsIntSize imageSize;
|
|
|
|
aImage->GetWidth(&imageSize.width);
|
|
|
|
aImage->GetHeight(&imageSize.height);
|
2009-07-28 03:48:13 +04:00
|
|
|
NS_ENSURE_TRUE(imageSize.width > 0 && imageSize.height > 0, NS_ERROR_FAILURE);
|
2009-01-30 10:33:57 +03:00
|
|
|
|
2009-04-05 13:52:14 +04:00
|
|
|
return DrawImageInternal(aRenderingContext, aImage, aGraphicsFilter,
|
2009-01-30 10:33:57 +03:00
|
|
|
aDest, aFill, aAnchor, aDirty,
|
2009-09-13 02:44:18 +04:00
|
|
|
imageSize, aImageFlags);
|
2009-01-30 10:33:57 +03:00
|
|
|
}
|
|
|
|
|
2008-11-05 01:01:21 +03:00
|
|
|
/* static */ nsRect
|
|
|
|
nsLayoutUtils::GetWholeImageDestination(const nsIntSize& aWholeImageSize,
|
|
|
|
const nsRect& aImageSourceArea,
|
|
|
|
const nsRect& aDestArea)
|
|
|
|
{
|
|
|
|
double scaleX = double(aDestArea.width)/aImageSourceArea.width;
|
|
|
|
double scaleY = double(aDestArea.height)/aImageSourceArea.height;
|
|
|
|
nscoord destOffsetX = NSToCoordRound(aImageSourceArea.x*scaleX);
|
|
|
|
nscoord destOffsetY = NSToCoordRound(aImageSourceArea.y*scaleY);
|
|
|
|
nscoord appUnitsPerCSSPixel = nsIDeviceContext::AppUnitsPerCSSPixel();
|
|
|
|
nscoord wholeSizeX = NSToCoordRound(aWholeImageSize.width*appUnitsPerCSSPixel*scaleX);
|
|
|
|
nscoord wholeSizeY = NSToCoordRound(aWholeImageSize.height*appUnitsPerCSSPixel*scaleY);
|
|
|
|
return nsRect(aDestArea.TopLeft() - nsPoint(destOffsetX, destOffsetY),
|
|
|
|
nsSize(wholeSizeX, wholeSizeY));
|
2007-03-20 03:58:20 +03:00
|
|
|
}
|
2007-05-05 10:09:50 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutUtils::SetFontFromStyle(nsIRenderingContext* aRC, nsStyleContext* aSC)
|
|
|
|
{
|
|
|
|
const nsStyleFont* font = aSC->GetStyleFont();
|
|
|
|
const nsStyleVisibility* visibility = aSC->GetStyleVisibility();
|
|
|
|
|
2008-12-04 19:09:53 +03:00
|
|
|
aRC->SetFont(font->mFont, visibility->mLangGroup,
|
|
|
|
aSC->PresContext()->GetUserFontSet());
|
2007-05-05 10:09:50 +04:00
|
|
|
}
|
|
|
|
|
2007-05-10 19:46:42 +04:00
|
|
|
static PRBool NonZeroStyleCoord(const nsStyleCoord& aCoord)
|
|
|
|
{
|
|
|
|
switch (aCoord.GetUnit()) {
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
return aCoord.GetPercentValue() > 0;
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
return aCoord.GetCoordValue() > 0;
|
|
|
|
default:
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-01 09:50:52 +04:00
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::HasNonZeroCorner(const nsStyleCorners& aCorners)
|
2007-05-10 19:46:42 +04:00
|
|
|
{
|
2008-10-01 09:50:52 +04:00
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner) {
|
|
|
|
if (NonZeroStyleCoord(aCorners.Get(corner)))
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
2007-05-10 19:46:42 +04:00
|
|
|
}
|
|
|
|
|
2009-05-08 05:52:22 +04:00
|
|
|
// aCorner is a "full corner" value, i.e. NS_CORNER_TOP_LEFT etc
|
|
|
|
static PRBool IsCornerAdjacentToSide(PRUint8 aCorner, PRUint8 aSide)
|
|
|
|
{
|
|
|
|
PR_STATIC_ASSERT(NS_SIDE_TOP == NS_CORNER_TOP_LEFT);
|
|
|
|
PR_STATIC_ASSERT(NS_SIDE_RIGHT == NS_CORNER_TOP_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_SIDE_BOTTOM == NS_CORNER_BOTTOM_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_SIDE_LEFT == NS_CORNER_BOTTOM_LEFT);
|
|
|
|
PR_STATIC_ASSERT(NS_SIDE_TOP == ((NS_CORNER_TOP_RIGHT - 1)&3));
|
|
|
|
PR_STATIC_ASSERT(NS_SIDE_RIGHT == ((NS_CORNER_BOTTOM_RIGHT - 1)&3));
|
|
|
|
PR_STATIC_ASSERT(NS_SIDE_BOTTOM == ((NS_CORNER_BOTTOM_LEFT - 1)&3));
|
|
|
|
PR_STATIC_ASSERT(NS_SIDE_LEFT == ((NS_CORNER_TOP_LEFT - 1)&3));
|
|
|
|
|
|
|
|
return aSide == aCorner || aSide == ((aCorner - 1)&3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::HasNonZeroCornerOnSide(const nsStyleCorners& aCorners,
|
|
|
|
PRUint8 aSide)
|
|
|
|
{
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_LEFT_X/2 == NS_CORNER_TOP_LEFT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_LEFT_Y/2 == NS_CORNER_TOP_LEFT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_RIGHT_X/2 == NS_CORNER_TOP_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_TOP_RIGHT_Y/2 == NS_CORNER_TOP_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_BOTTOM_RIGHT_X/2 == NS_CORNER_BOTTOM_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_BOTTOM_RIGHT_Y/2 == NS_CORNER_BOTTOM_RIGHT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_BOTTOM_LEFT_X/2 == NS_CORNER_BOTTOM_LEFT);
|
|
|
|
PR_STATIC_ASSERT(NS_CORNER_BOTTOM_LEFT_Y/2 == NS_CORNER_BOTTOM_LEFT);
|
|
|
|
|
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner) {
|
|
|
|
// corner is a "half corner" value, so dividing by two gives us a
|
|
|
|
// "full corner" value.
|
|
|
|
if (NonZeroStyleCoord(aCorners.Get(corner)) &&
|
|
|
|
IsCornerAdjacentToSide(corner/2, aSide))
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-08-13 04:44:14 +04:00
|
|
|
/* static */ nsTransparencyMode
|
2009-08-14 02:08:13 +04:00
|
|
|
nsLayoutUtils::GetFrameTransparency(nsIFrame* aBackgroundFrame,
|
|
|
|
nsIFrame* aCSSRootFrame) {
|
|
|
|
if (aCSSRootFrame->GetStyleContext()->GetStyleDisplay()->mOpacity < 1.0f)
|
2008-08-13 04:44:14 +04:00
|
|
|
return eTransparencyTransparent;
|
2007-05-10 19:46:42 +04:00
|
|
|
|
2009-08-14 02:08:13 +04:00
|
|
|
if (HasNonZeroCorner(aCSSRootFrame->GetStyleContext()->GetStyleBorder()->mBorderRadius))
|
2008-08-13 04:44:14 +04:00
|
|
|
return eTransparencyTransparent;
|
2007-05-10 19:46:42 +04:00
|
|
|
|
2008-12-11 17:37:38 +03:00
|
|
|
nsTransparencyMode transparency;
|
2009-08-14 02:08:13 +04:00
|
|
|
if (aCSSRootFrame->IsThemed(&transparency))
|
2008-12-11 17:37:38 +03:00
|
|
|
return transparency;
|
2007-05-10 19:46:42 +04:00
|
|
|
|
2009-08-14 02:08:13 +04:00
|
|
|
if (aCSSRootFrame->GetStyleDisplay()->mAppearance == NS_THEME_WIN_GLASS)
|
2008-08-13 04:44:14 +04:00
|
|
|
return eTransparencyGlass;
|
2009-02-05 06:05:48 +03:00
|
|
|
|
|
|
|
// We need an uninitialized window to be treated as opaque because
|
|
|
|
// doing otherwise breaks window display effects on some platforms,
|
|
|
|
// specifically Vista. (bug 450322)
|
2009-08-14 02:08:13 +04:00
|
|
|
if (aBackgroundFrame->GetType() == nsGkAtoms::viewportFrame &&
|
|
|
|
!aBackgroundFrame->GetFirstChild(nsnull)) {
|
2009-02-05 06:05:48 +03:00
|
|
|
return eTransparencyOpaque;
|
|
|
|
}
|
|
|
|
|
2007-05-10 19:46:42 +04:00
|
|
|
const nsStyleBackground* bg;
|
2009-08-14 02:08:13 +04:00
|
|
|
if (!nsCSSRendering::FindBackground(aBackgroundFrame->PresContext(),
|
|
|
|
aBackgroundFrame, &bg)) {
|
2008-08-13 04:44:14 +04:00
|
|
|
return eTransparencyTransparent;
|
2009-08-14 02:08:13 +04:00
|
|
|
}
|
2009-02-20 08:29:21 +03:00
|
|
|
if (NS_GET_A(bg->mBackgroundColor) < 255 ||
|
|
|
|
// bottom layer's clip is used for the color
|
|
|
|
bg->BottomLayer().mClip != NS_STYLE_BG_CLIP_BORDER)
|
2008-08-13 04:44:14 +04:00
|
|
|
return eTransparencyTransparent;
|
|
|
|
return eTransparencyOpaque;
|
2007-05-10 19:46:42 +04:00
|
|
|
}
|
2007-07-26 13:47:43 +04:00
|
|
|
|
|
|
|
static PRBool
|
|
|
|
IsNonzeroCoord(const nsStyleCoord& aCoord)
|
|
|
|
{
|
|
|
|
if (eStyleUnit_Coord == aCoord.GetUnit())
|
|
|
|
return aCoord.GetCoordValue() != 0;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PRUint32
|
|
|
|
nsLayoutUtils::GetTextRunFlagsForStyle(nsStyleContext* aStyleContext,
|
|
|
|
const nsStyleText* aStyleText,
|
|
|
|
const nsStyleFont* aStyleFont)
|
|
|
|
{
|
|
|
|
PRUint32 result = 0;
|
|
|
|
if (IsNonzeroCoord(aStyleText->mLetterSpacing)) {
|
|
|
|
result |= gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES;
|
|
|
|
}
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
switch (aStyleContext->GetStyleSVG()->mTextRendering) {
|
|
|
|
case NS_STYLE_TEXT_RENDERING_OPTIMIZESPEED:
|
|
|
|
result |= gfxTextRunFactory::TEXT_OPTIMIZE_SPEED;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_TEXT_RENDERING_AUTO:
|
|
|
|
if (aStyleFont->mFont.size <
|
|
|
|
aStyleContext->PresContext()->GetAutoQualityMinFontSize()) {
|
|
|
|
result |= gfxTextRunFactory::TEXT_OPTIMIZE_SPEED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
2008-02-08 12:36:32 +03:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsLayoutUtils::GetRectDifferenceStrips(const nsRect& aR1, const nsRect& aR2,
|
|
|
|
nsRect* aHStrip, nsRect* aVStrip) {
|
|
|
|
NS_ASSERTION(aR1.TopLeft() == aR2.TopLeft(),
|
|
|
|
"expected rects at the same position");
|
2009-09-16 19:01:36 +04:00
|
|
|
nsRect unionRect(aR1.x, aR1.y, NS_MAX(aR1.width, aR2.width),
|
|
|
|
NS_MAX(aR1.height, aR2.height));
|
|
|
|
nscoord VStripStart = NS_MIN(aR1.width, aR2.width);
|
|
|
|
nscoord HStripStart = NS_MIN(aR1.height, aR2.height);
|
2008-02-08 12:36:32 +03:00
|
|
|
*aVStrip = unionRect;
|
|
|
|
aVStrip->x += VStripStart;
|
|
|
|
aVStrip->width -= VStripStart;
|
|
|
|
*aHStrip = unionRect;
|
|
|
|
aHStrip->y += HStripStart;
|
|
|
|
aHStrip->height -= HStripStart;
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:49 +04:00
|
|
|
nsIDeviceContext*
|
|
|
|
nsLayoutUtils::GetDeviceContextForScreenInfo(nsIDocShell* aDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = aDocShell;
|
|
|
|
while (docShell) {
|
|
|
|
// Now make sure our size is up to date. That will mean that the device
|
|
|
|
// context does the right thing on multi-monitor systems when we return it to
|
|
|
|
// the caller. It will also make sure that our prescontext has been created,
|
|
|
|
// if we're supposed to have one.
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_GetInterface(docShell);
|
|
|
|
if (!win) {
|
|
|
|
// No reason to go on
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
win->EnsureSizeUpToDate();
|
|
|
|
|
2009-09-01 20:40:49 +04:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
|
|
|
docShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
if (presContext) {
|
|
|
|
nsIDeviceContext* context = presContext->DeviceContext();
|
|
|
|
if (context) {
|
|
|
|
return context;
|
|
|
|
}
|
2008-07-26 20:14:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> curItem = do_QueryInterface(docShell);
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
curItem->GetParent(getter_AddRefs(parentItem));
|
|
|
|
docShell = do_QueryInterface(parentItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2008-11-26 00:27:54 +03:00
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::IsReallyFixedPos(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame->GetParent(),
|
|
|
|
"IsReallyFixedPos called on frame not in tree");
|
|
|
|
NS_PRECONDITION(aFrame->GetStyleDisplay()->mPosition ==
|
|
|
|
NS_STYLE_POSITION_FIXED,
|
|
|
|
"IsReallyFixedPos called on non-'position:fixed' frame");
|
|
|
|
|
2008-12-29 18:07:37 +03:00
|
|
|
nsIAtom *parentType = aFrame->GetParent()->GetType();
|
|
|
|
return parentType == nsGkAtoms::viewportFrame ||
|
|
|
|
parentType == nsGkAtoms::pageContentFrame;
|
2008-11-26 00:27:54 +03:00
|
|
|
}
|
|
|
|
|
2009-03-08 22:01:02 +03:00
|
|
|
static void DeleteTextFragment(void* aObject, nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue, void* aData)
|
|
|
|
{
|
|
|
|
delete static_cast<nsTextFragment*>(aPropertyValue);
|
|
|
|
}
|
|
|
|
|
2009-03-18 13:45:00 +03:00
|
|
|
/* static */ nsTextFragment*
|
|
|
|
nsLayoutUtils::GetTextFragmentForPrinting(const nsIFrame* aFrame)
|
2009-03-08 22:01:02 +03:00
|
|
|
{
|
2009-03-18 13:45:00 +03:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
NS_PRECONDITION(!presContext->IsDynamic(),
|
|
|
|
"Shouldn't call this with dynamic PresContext");
|
2009-03-10 07:38:46 +03:00
|
|
|
#ifdef MOZ_SVG
|
2009-03-10 06:40:53 +03:00
|
|
|
NS_PRECONDITION(aFrame->GetType() == nsGkAtoms::textFrame ||
|
|
|
|
aFrame->GetType() == nsGkAtoms::svgGlyphFrame,
|
2009-03-08 22:01:02 +03:00
|
|
|
"Wrong frame type!");
|
2009-03-10 07:38:46 +03:00
|
|
|
#else
|
|
|
|
NS_PRECONDITION(aFrame->GetType() == nsGkAtoms::textFrame,
|
|
|
|
"Wrong frame type!");
|
|
|
|
#endif // MOZ_SVG
|
2009-03-08 22:01:02 +03:00
|
|
|
|
2009-03-18 13:45:00 +03:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
nsTextFragment* frag =
|
|
|
|
static_cast<nsTextFragment*>(presContext->PropertyTable()->
|
|
|
|
GetProperty(content, nsGkAtoms::clonedTextForPrint));
|
|
|
|
|
|
|
|
if (!frag) {
|
|
|
|
frag = new nsTextFragment();
|
|
|
|
NS_ENSURE_TRUE(frag, nsnull);
|
|
|
|
*frag = *content->GetText();
|
2009-03-08 22:01:02 +03:00
|
|
|
nsresult rv = presContext->PropertyTable()->
|
2009-03-18 13:45:00 +03:00
|
|
|
SetProperty(content, nsGkAtoms::clonedTextForPrint, frag,
|
2009-03-08 22:01:02 +03:00
|
|
|
DeleteTextFragment, nsnull);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete frag;
|
2009-03-18 13:45:00 +03:00
|
|
|
return nsnull;
|
2009-03-08 22:01:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-18 13:45:00 +03:00
|
|
|
return frag;
|
2009-03-08 22:01:02 +03:00
|
|
|
}
|
|
|
|
|
2009-06-26 00:30:56 +04:00
|
|
|
nsLayoutUtils::SurfaceFromElementResult
|
|
|
|
nsLayoutUtils::SurfaceFromElement(nsIDOMElement *aElement,
|
|
|
|
PRUint32 aSurfaceFlags)
|
|
|
|
{
|
|
|
|
SurfaceFromElementResult result;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aElement);
|
|
|
|
|
|
|
|
PRBool forceCopy = (aSurfaceFlags & SFE_WANT_NEW_SURFACE) != 0;
|
|
|
|
PRBool wantImageSurface = (aSurfaceFlags & SFE_WANT_IMAGE_SURFACE) != 0;
|
|
|
|
|
|
|
|
// If it's a <canvas>, we may be able to just grab its internal surface
|
|
|
|
nsCOMPtr<nsICanvasElement> canvas = do_QueryInterface(aElement);
|
|
|
|
if (node && canvas) {
|
|
|
|
PRUint32 w, h;
|
|
|
|
rv = canvas->GetSize(&w, &h);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surf;
|
|
|
|
|
|
|
|
if (!forceCopy && canvas->CountContexts() == 1) {
|
|
|
|
nsICanvasRenderingContextInternal *srcCanvas = canvas->GetContextAtIndex(0);
|
|
|
|
rv = srcCanvas->GetThebesSurface(getter_AddRefs(surf));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
surf = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surf && wantImageSurface && surf->GetType() != gfxASurface::SurfaceTypeImage)
|
|
|
|
surf = nsnull;
|
|
|
|
|
|
|
|
if (!surf) {
|
|
|
|
if (wantImageSurface) {
|
|
|
|
surf = new gfxImageSurface(gfxIntSize(w, h), gfxASurface::ImageFormatARGB32);
|
|
|
|
} else {
|
|
|
|
surf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(w, h), gfxASurface::ImageFormatARGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(surf);
|
|
|
|
rv = canvas->RenderContexts(ctx, gfxPattern::FILTER_NEAREST);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = node->NodePrincipal();
|
|
|
|
|
|
|
|
result.mSurface = surf;
|
|
|
|
result.mSize = gfxIntSize(w, h);
|
|
|
|
result.mPrincipal = node->NodePrincipal();
|
|
|
|
result.mIsWriteOnly = canvas->IsWriteOnly();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_MEDIA
|
|
|
|
// Maybe it's <video>?
|
|
|
|
nsCOMPtr<nsIDOMHTMLVideoElement> ve = do_QueryInterface(aElement);
|
|
|
|
if (node && ve) {
|
|
|
|
nsHTMLVideoElement *video = static_cast<nsHTMLVideoElement*>(ve.get());
|
|
|
|
|
|
|
|
// If it doesn't have a principal, just bail
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = video->GetCurrentPrincipal();
|
|
|
|
if (!principal)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
PRUint32 w, h;
|
|
|
|
rv = video->GetVideoWidth(&w);
|
|
|
|
rv |= video->GetVideoHeight(&h);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> surf;
|
|
|
|
if (wantImageSurface) {
|
|
|
|
surf = new gfxImageSurface(gfxIntSize(w, h), gfxASurface::ImageFormatARGB32);
|
|
|
|
} else {
|
|
|
|
surf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(w, h), gfxASurface::ImageFormatARGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(surf);
|
|
|
|
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
video->Paint(ctx, gfxPattern::FILTER_NEAREST, gfxRect(0, 0, w, h));
|
|
|
|
|
|
|
|
result.mSurface = surf;
|
|
|
|
result.mSize = gfxIntSize(w, h);
|
|
|
|
result.mPrincipal = principal;
|
|
|
|
result.mIsWriteOnly = PR_FALSE;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Finally, check if it's a normal image
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(aElement);
|
|
|
|
|
|
|
|
if (!imageLoader)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsCOMPtr<imgIRequest> imgRequest;
|
|
|
|
rv = imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(imgRequest));
|
|
|
|
if (NS_FAILED(rv) || !imgRequest)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
PRUint32 status;
|
|
|
|
imgRequest->GetImageStatus(&status);
|
|
|
|
if ((status & imgIRequest::STATUS_LOAD_COMPLETE) == 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// In case of data: URIs, we want to ignore principals;
|
|
|
|
// they should have the originating content's principal,
|
|
|
|
// but that's broken at the moment in imgLib.
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = imgRequest->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
PRBool isDataURI = PR_FALSE;
|
|
|
|
rv = uri->SchemeIs("data", &isDataURI);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// Data URIs are always OK; set the principal
|
|
|
|
// to null to indicate that.
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
if (!isDataURI) {
|
|
|
|
rv = imgRequest->GetImagePrincipal(getter_AddRefs(principal));
|
|
|
|
if (NS_FAILED(rv) || !principal)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
2009-06-26 00:30:56 +04:00
|
|
|
rv = imgRequest->GetImage(getter_AddRefs(imgContainer));
|
|
|
|
if (NS_FAILED(rv) || !imgContainer)
|
|
|
|
return result;
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
PRUint32 whichFrame = (aSurfaceFlags & SFE_WANT_FIRST_FRAME)
|
|
|
|
? (PRUint32) imgIContainer::FRAME_FIRST
|
|
|
|
: (PRUint32) imgIContainer::FRAME_CURRENT;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
nsRefPtr<gfxASurface> framesurf;
|
2009-09-13 02:44:18 +04:00
|
|
|
rv = imgContainer->GetFrame(whichFrame,
|
|
|
|
imgIContainer::FLAG_SYNC_DECODE,
|
|
|
|
getter_AddRefs(framesurf));
|
2009-06-26 00:30:56 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
PRInt32 imgWidth, imgHeight;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
rv = imgContainer->GetWidth(&imgWidth);
|
|
|
|
rv |= imgContainer->GetHeight(&imgHeight);
|
2009-06-26 00:30:56 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return result;
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
if (wantImageSurface && framesurf->GetType() != gfxASurface::SurfaceTypeImage) {
|
2009-06-26 00:30:56 +04:00
|
|
|
forceCopy = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
nsRefPtr<gfxASurface> gfxsurf = framesurf;
|
|
|
|
if (forceCopy) {
|
2009-06-26 00:30:56 +04:00
|
|
|
if (wantImageSurface) {
|
|
|
|
gfxsurf = new gfxImageSurface (gfxIntSize(imgWidth, imgHeight), gfxASurface::ImageFormatARGB32);
|
|
|
|
} else {
|
|
|
|
gfxsurf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(imgWidth, imgHeight),
|
|
|
|
gfxASurface::ImageFormatARGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(gfxsurf);
|
|
|
|
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
ctx->SetSource(framesurf);
|
2009-06-26 00:30:56 +04:00
|
|
|
ctx->Paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
result.mSurface = gfxsurf;
|
|
|
|
result.mSize = gfxIntSize(imgWidth, imgHeight);
|
|
|
|
result.mPrincipal = principal;
|
|
|
|
result.mIsWriteOnly = PR_FALSE;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-04-15 03:59:21 +04:00
|
|
|
nsSetAttrRunnable::nsSetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName,
|
|
|
|
const nsAString& aValue)
|
|
|
|
: mContent(aContent),
|
|
|
|
mAttrName(aAttrName),
|
|
|
|
mValue(aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent && aAttrName, "Missing stuff, prepare to crash");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSetAttrRunnable::Run()
|
|
|
|
{
|
|
|
|
return mContent->SetAttr(kNameSpaceID_None, mAttrName, mValue, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsUnsetAttrRunnable::nsUnsetAttrRunnable(nsIContent* aContent,
|
|
|
|
nsIAtom* aAttrName)
|
|
|
|
: mContent(aContent),
|
|
|
|
mAttrName(aAttrName)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent && aAttrName, "Missing stuff, prepare to crash");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsUnsetAttrRunnable::Run()
|
|
|
|
{
|
|
|
|
return mContent->UnsetAttr(kNameSpaceID_None, mAttrName, PR_TRUE);
|
|
|
|
}
|
2009-01-19 12:29:48 +03:00
|
|
|
|
|
|
|
nsReflowFrameRunnable::nsReflowFrameRunnable(nsIFrame* aFrame,
|
|
|
|
nsIPresShell::IntrinsicDirty aIntrinsicDirty,
|
|
|
|
nsFrameState aBitToAdd)
|
|
|
|
: mWeakFrame(aFrame),
|
|
|
|
mIntrinsicDirty(aIntrinsicDirty),
|
|
|
|
mBitToAdd(aBitToAdd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsReflowFrameRunnable::Run()
|
|
|
|
{
|
|
|
|
if (mWeakFrame.IsAlive()) {
|
|
|
|
mWeakFrame->PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(mWeakFrame, mIntrinsicDirty, mBitToAdd);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|