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
|
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"
|
|
|
|
#include "nsIFrame.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"
|
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 "gfxIImageFrame.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "gfxRect.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2007-05-10 19:46:42 +04:00
|
|
|
#include "nsCSSRendering.h"
|
2006-02-21 04:24:42 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_SVG_FOREIGNOBJECT
|
2006-02-21 03:33:27 +03:00
|
|
|
#include "nsSVGForeignObjectFrame.h"
|
|
|
|
#include "nsSVGUtils.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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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");
|
|
|
|
|
2007-01-17 21:53:11 +03:00
|
|
|
// Get the last continuation frame
|
|
|
|
nsIFrame* lastContinuation = aFrame->GetLastContinuation();
|
2003-01-05 08:05:17 +03:00
|
|
|
|
|
|
|
// Get the last child frame
|
2007-01-17 21:53:11 +03:00
|
|
|
nsIFrame* firstChildFrame = lastContinuation->GetFirstChild(nsnull);
|
2003-01-05 08:05:17 +03:00
|
|
|
if (firstChildFrame) {
|
|
|
|
nsFrameList frameList(firstChildFrame);
|
|
|
|
nsIFrame* lastChildFrame = frameList.LastChild();
|
|
|
|
|
|
|
|
NS_ASSERTION(lastChildFrame, "unexpected error");
|
|
|
|
|
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*
|
|
|
|
nsLayoutUtils::GetPageFrame(nsIFrame* aFrame)
|
|
|
|
{
|
2003-07-02 14:30:00 +04:00
|
|
|
for (nsIFrame* frame = aFrame; frame; frame = frame->GetParent()) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (frame->GetType() == nsGkAtoms::pageFrame) {
|
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;
|
|
|
|
}
|
2003-10-31 23:19:18 +03:00
|
|
|
|
2003-07-02 14:30:00 +04:00
|
|
|
if (aContent && aFrame->GetContent() != aContent) {
|
|
|
|
return PR_FALSE;
|
2003-04-22 03:06:40 +04:00
|
|
|
}
|
|
|
|
|
2003-10-17 06:38:37 +04:00
|
|
|
return aFrame->GetStyleContext()->GetPseudoType() == aPseudoElement;
|
2003-04-22 03:06:40 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// static
|
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetCrossDocParentFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
v = v->GetParent(); // subdocumentframe's view
|
|
|
|
if (!v)
|
|
|
|
return nsnull;
|
|
|
|
return NS_STATIC_CAST(nsIFrame*, v->GetClientData());
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
nsIContent* aCommonAncestor)
|
|
|
|
{
|
2003-10-15 04:49:03 +04:00
|
|
|
NS_PRECONDITION(aContent1, "aContent1 must not be null");
|
|
|
|
NS_PRECONDITION(aContent2, "aContent2 must not be null");
|
|
|
|
|
|
|
|
nsAutoVoidArray 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
|
|
|
|
2003-10-17 18:10:02 +04:00
|
|
|
nsAutoVoidArray 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
|
|
|
}
|
|
|
|
|
|
|
|
int last1 = content1Ancestors.Count() - 1;
|
|
|
|
int last2 = content2Ancestors.Count() - 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
|
2006-05-16 19:50:47 +04:00
|
|
|
&& ((content1Ancestor = NS_STATIC_CAST(nsINode*, content1Ancestors.ElementAt(last1)))
|
|
|
|
== (content2Ancestor = NS_STATIC_CAST(nsINode*, 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) {
|
|
|
|
nsIFrame* parentViewFrame = NS_STATIC_CAST(nsIFrame*, aParentView->GetClientData());
|
|
|
|
nsIContent* parentViewContent = parentViewFrame ? parentViewFrame->GetContent() : nsnull;
|
|
|
|
for (nsIView* insertBefore = aParentView->GetFirstChild(); insertBefore;
|
|
|
|
insertBefore = insertBefore->GetNextSibling()) {
|
|
|
|
nsIFrame* f = NS_STATIC_CAST(nsIFrame*, insertBefore->GetClientData());
|
|
|
|
if (!f) {
|
|
|
|
// this view could be some anonymous view attached to a meaningful parent
|
|
|
|
for (nsIView* searchView = insertBefore->GetParent(); searchView;
|
|
|
|
searchView = searchView->GetParent()) {
|
|
|
|
f = NS_STATIC_CAST(nsIFrame*, searchView->GetClientData());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
nsIScrollableFrame *sf;
|
|
|
|
CallQueryInterface(frame, &sf);
|
|
|
|
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());
|
|
|
|
if (frame) {
|
2004-09-21 08:41:08 +04:00
|
|
|
nsIScrollableFrame *sf;
|
|
|
|
CallQueryInterface(frame, &sf);
|
2004-10-19 06:24:27 +04:00
|
|
|
return sf;
|
2004-09-21 08:41:08 +04:00
|
|
|
}
|
2004-10-19 06:24:27 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
//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);
|
|
|
|
nsEvent* event;
|
|
|
|
nsresult rv = privateEvent->GetInternalNSEvent(&event);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-08-23 07:57:07 +04:00
|
|
|
return GetEventCoordinatesRelativeTo(event, aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(nsEvent* aEvent, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aEvent || (aEvent->eventStructType != NS_MOUSE_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT))
|
2005-06-02 13:00:48 +04:00
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-08-23 07:57:07 +04:00
|
|
|
|
|
|
|
nsGUIEvent* GUIEvent = NS_STATIC_CAST(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
|
|
|
|
2006-02-21 03:33:27 +03:00
|
|
|
// If it is, or is a descendant of, an SVG foreignobject frame,
|
|
|
|
// then we need to do extra work
|
2006-02-21 04:24:42 +03:00
|
|
|
nsIFrame* rootFrame = aFrame;
|
2006-02-21 03:33:27 +03:00
|
|
|
for (nsIFrame* f = aFrame; f; f = GetCrossDocParentFrame(f)) {
|
2006-02-21 04:07:59 +03:00
|
|
|
#ifdef MOZ_SVG_FOREIGNOBJECT
|
2006-06-20 02:06:41 +04:00
|
|
|
if (f->IsFrameOfType(nsIFrame::eSVGForeignObject) && f->GetFirstChild(nsnull)) {
|
2006-02-21 03:33:27 +03:00
|
|
|
nsSVGForeignObjectFrame* fo = NS_STATIC_CAST(nsSVGForeignObjectFrame*, f);
|
2006-06-15 23:10:28 +04:00
|
|
|
nsIFrame* outer = nsSVGUtils::GetOuterSVGFrame(fo);
|
2006-02-21 03:33:27 +03:00
|
|
|
return fo->TransformPointFromOuter(
|
|
|
|
GetEventCoordinatesRelativeTo(aEvent, outer)) -
|
2006-06-20 02:06:41 +04:00
|
|
|
aFrame->GetOffsetTo(fo->GetFirstChild(nsnull));
|
2006-02-21 03:33:27 +03:00
|
|
|
}
|
2006-02-21 04:07:59 +03:00
|
|
|
#endif
|
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);
|
|
|
|
|
2006-02-21 03:33:27 +03:00
|
|
|
return widgetToView - aFrame->GetOffsetTo(rootFrame);
|
2005-08-23 07:57:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::GetEventCoordinatesForNearestView(nsEvent* aEvent,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIView** aView)
|
|
|
|
{
|
|
|
|
if (!aEvent || (aEvent->eventStructType != NS_MOUSE_EVENT &&
|
|
|
|
aEvent->eventStructType != NS_MOUSE_SCROLL_EVENT))
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
|
|
|
nsGUIEvent* GUIEvent = NS_STATIC_CAST(nsGUIEvent*, aEvent);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsLayoutUtils::TranslateWidgetToView(nsPresContext* aPresContext,
|
|
|
|
nsIWidget* aWidget, nsIntPoint aPt,
|
|
|
|
nsIView* aView)
|
|
|
|
{
|
|
|
|
nsIView* baseView = nsIView::GetViewFor(aWidget);
|
2005-09-15 08:03:07 +04:00
|
|
|
if (!baseView)
|
|
|
|
return nsPoint(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
2005-09-18 22:03:06 +04:00
|
|
|
nsPoint viewToWidget;
|
|
|
|
nsIWidget* wid = baseView->GetNearestWidget(&viewToWidget);
|
2005-08-23 07:57:07 +04:00
|
|
|
NS_ASSERTION(aWidget == wid, "Clashing widgets");
|
2007-02-07 10:46:44 +03:00
|
|
|
nsPoint refPointAppUnits(aPresContext->DevPixelsToAppUnits(aPt.x),
|
|
|
|
aPresContext->DevPixelsToAppUnits(aPt.y));
|
|
|
|
return refPointAppUnits - viewToWidget - aView->GetOffsetTo(baseView);
|
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
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsLayoutUtils::IsInitialContainingBlock(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return aFrame ==
|
2007-03-31 01:11:41 +04:00
|
|
|
aFrame->PresContext()->PresShell()->FrameConstructor()->GetInitialContainingBlock();
|
2005-02-08 05:15:26 +03:00
|
|
|
}
|
2005-12-06 03:32:52 +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*
|
|
|
|
nsLayoutUtils::GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt)
|
|
|
|
{
|
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));
|
|
|
|
|
|
|
|
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);
|
|
|
|
nsIFrameDebug::PrintDisplayList(&builder, list);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIFrame* result = list.HitTest(&builder, aPt);
|
|
|
|
list.DeleteAll();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-02-06 23:38:47 +03:00
|
|
|
/**
|
|
|
|
* A simple display item that just renders a solid color across the entire
|
|
|
|
* visible area.
|
|
|
|
*/
|
|
|
|
class nsDisplaySolidColor : public nsDisplayItem {
|
|
|
|
public:
|
|
|
|
nsDisplaySolidColor(nsIFrame* aFrame, nscolor aColor)
|
2006-03-14 23:43:18 +03:00
|
|
|
: nsDisplayItem(aFrame), mColor(aColor) {
|
2006-02-06 23:38:47 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplaySolidColor);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplaySolidColor() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplaySolidColor);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, nsIRenderingContext* aCtx,
|
|
|
|
const nsRect& aDirtyRect);
|
|
|
|
NS_DISPLAY_DECL_NAME("SolidColor")
|
|
|
|
private:
|
|
|
|
nscolor mColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplaySolidColor::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect)
|
|
|
|
{
|
|
|
|
aCtx->SetColor(mColor);
|
|
|
|
aCtx->FillRect(aDirtyRect);
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::PaintFrame(nsIRenderingContext* aRenderingContext, nsIFrame* aFrame,
|
2006-02-06 23:38:47 +03:00
|
|
|
const nsRegion& aDirtyRegion, nscolor aBackground)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
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();
|
2006-04-18 03:16:46 +04:00
|
|
|
|
|
|
|
builder.EnterPresShell(aFrame, dirtyRect);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult rv =
|
|
|
|
aFrame->BuildDisplayListForStackingContext(&builder, dirtyRect, &list);
|
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);
|
|
|
|
|
2006-02-06 23:38:47 +03:00
|
|
|
if (NS_GET_A(aBackground) > 0) {
|
|
|
|
// Fill the visible area with a background color. In the common case,
|
|
|
|
// the visible area is entirely covered by the background of the root
|
|
|
|
// document (at least!) so this will be removed by the optimizer. In some
|
|
|
|
// cases we might not have a root frame, so this will prevent garbage
|
|
|
|
// from being drawn.
|
|
|
|
rv = list.AppendNewToBottom(new (&builder) nsDisplaySolidColor(aFrame, aBackground));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpPaintList) {
|
|
|
|
fprintf(stderr, "Painting --- before optimization (dirty %d,%d,%d,%d):\n",
|
|
|
|
dirtyRect.x, dirtyRect.y, dirtyRect.width, dirtyRect.height);
|
|
|
|
nsIFrameDebug::PrintDisplayList(&builder, list);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsRegion visibleRegion = aDirtyRegion;
|
|
|
|
list.OptimizeVisibility(&builder, &visibleRegion);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpPaintList) {
|
|
|
|
fprintf(stderr, "Painting --- after optimization:\n");
|
|
|
|
nsIFrameDebug::PrintDisplayList(&builder, list);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
list.Paint(&builder, aRenderingContext, aDirtyRegion.GetBounds());
|
|
|
|
// 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
|
|
|
|
AccumulateItemInRegion(nsRegion* aRegion, const nsRect& aAreaRect,
|
|
|
|
const nsRect& aItemRect, nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
nsRect damageRect;
|
|
|
|
if (damageRect.IntersectRect(aAreaRect, aItemRect)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpRepaintRegionForCopy) {
|
|
|
|
fprintf(stderr, "Adding rect %d,%d,%d,%d for frame %p\n",
|
|
|
|
damageRect.x, damageRect.y, damageRect.width, damageRect.height,
|
|
|
|
(void*)aItem->GetUnderlyingFrame());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
aRegion->Or(*aRegion, damageRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
static void
|
|
|
|
AddItemsToRegion(nsDisplayListBuilder* aBuilder, nsDisplayList* aList,
|
|
|
|
const nsRect& aRect, const nsRect& aClipRect, nsPoint aDelta,
|
|
|
|
nsRegion* aRegion)
|
|
|
|
{
|
|
|
|
for (nsDisplayItem* item = aList->GetBottom(); item; item = item->GetAbove()) {
|
|
|
|
nsDisplayList* sublist = item->GetList();
|
|
|
|
if (sublist) {
|
|
|
|
if (item->GetType() == nsDisplayItem::TYPE_CLIP) {
|
|
|
|
nsRect clip;
|
|
|
|
clip.IntersectRect(aClipRect, NS_STATIC_CAST(nsDisplayClip*, item)->GetClipRect());
|
|
|
|
AddItemsToRegion(aBuilder, sublist, aRect, clip, aDelta, aRegion);
|
|
|
|
} else {
|
|
|
|
// opacity, or a generic sublist
|
|
|
|
AddItemsToRegion(aBuilder, sublist, aRect, aClipRect, aDelta, aRegion);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Items left in the list are either IsVaryingRelativeToFrame
|
|
|
|
// or !IsMovingFrame (i.e., not in the moving subtree)
|
|
|
|
nsRect r;
|
|
|
|
if (r.IntersectRect(aClipRect, item->GetBounds(aBuilder))) {
|
|
|
|
PRBool inMovingSubtree = PR_FALSE;
|
|
|
|
if (item->IsVaryingRelativeToFrame(aBuilder, aBuilder->GetRootMovingFrame())) {
|
|
|
|
nsIFrame* f = item->GetUnderlyingFrame();
|
|
|
|
NS_ASSERTION(f, "Must have an underlying frame for leaf item");
|
|
|
|
inMovingSubtree = aBuilder->IsMovingFrame(f);
|
2006-02-06 05:41:51 +03:00
|
|
|
AccumulateItemInRegion(aRegion, aRect + aDelta, r, item);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!inMovingSubtree) {
|
|
|
|
// if it's uniform and it includes both the old and new areas, then
|
|
|
|
// we don't need to paint it
|
2006-02-06 05:41:51 +03:00
|
|
|
PRBool skip = r.Contains(aRect) && r.Contains(aRect + aDelta) &&
|
|
|
|
item->IsUniform(aBuilder);
|
|
|
|
if (!skip) {
|
2006-01-26 05:29:17 +03:00
|
|
|
// area where a non-moving element is visible must be repainted
|
2006-02-06 05:41:51 +03:00
|
|
|
AccumulateItemInRegion(aRegion, aRect + aDelta, r, item);
|
2006-01-26 05:29:17 +03:00
|
|
|
// we may have bitblitted an area that was painted by a non-moving
|
|
|
|
// element. This bitblitted data is invalid and was copied to
|
|
|
|
// "r + aDelta".
|
2006-02-06 05:41:51 +03:00
|
|
|
AccumulateItemInRegion(aRegion, aRect + aDelta, r + aDelta, item);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::ComputeRepaintRegionForCopy(nsIFrame* aRootFrame,
|
|
|
|
nsIFrame* aMovingFrame,
|
|
|
|
nsPoint aDelta,
|
|
|
|
const nsRect& aCopyRect,
|
|
|
|
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");
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
// Build the 'after' display list over the whole area of interest.
|
|
|
|
// Frames under aMovingFrame will not be allowed to affect (clip or cover)
|
|
|
|
// non-moving frame display items ... then we can be sure the non-moving
|
|
|
|
// frame display items we get are the same ones we would have gotten if
|
|
|
|
// we had constructed the 'before' display list.
|
|
|
|
// (We have to build the 'after' display list because the frame/view
|
|
|
|
// hierarchy has already been updated for the move.)
|
|
|
|
nsRect rect;
|
|
|
|
rect.UnionRect(aCopyRect, aCopyRect + aDelta);
|
2006-04-18 03:16:46 +04:00
|
|
|
nsDisplayListBuilder builder(aRootFrame, PR_FALSE, PR_TRUE, aMovingFrame);
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayList list;
|
2006-04-18 03:16:46 +04:00
|
|
|
|
|
|
|
builder.EnterPresShell(aRootFrame, rect);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult rv =
|
|
|
|
aRootFrame->BuildDisplayListForStackingContext(&builder, rect, &list);
|
2006-04-18 03:16:46 +04:00
|
|
|
|
|
|
|
builder.LeavePresShell(aRootFrame, rect);
|
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",
|
|
|
|
rect.x, rect.y, rect.width, rect.height, (void*)aMovingFrame);
|
|
|
|
nsIFrameDebug::PrintDisplayList(&builder, list);
|
|
|
|
}
|
|
|
|
#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.
|
|
|
|
nsRegion visibleRegion(aCopyRect);
|
|
|
|
visibleRegion.Or(visibleRegion, aCopyRect + aDelta);
|
|
|
|
list.OptimizeVisibility(&builder, &visibleRegion);
|
|
|
|
|
2006-02-06 05:41:51 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (gDumpRepaintRegionForCopy) {
|
|
|
|
fprintf(stderr, "Repaint region for copy --- after optimization:\n");
|
|
|
|
nsIFrameDebug::PrintDisplayList(&builder, list);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
// repaint region. All these areas are confined to aCopyRect+aDelta.
|
|
|
|
// 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.
|
|
|
|
AddItemsToRegion(&builder, &list, aCopyRect, rect, aDelta, aRepaintRegion);
|
|
|
|
// Flush the list so we don't trigger the IsEmpty-on-destruction assertion
|
|
|
|
list.DeleteAll();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::CreateOffscreenContext(nsIDeviceContext* deviceContext, nsIDrawingSurface* surface,
|
|
|
|
const nsRect& aRect, nsIRenderingContext** aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIRenderingContext *context = nsnull;
|
|
|
|
|
|
|
|
rv = deviceContext->CreateRenderingContext(surface, context);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// always initialize clipping, linux won't draw images otherwise.
|
|
|
|
nsRect clip(0, 0, aRect.width, aRect.height);
|
|
|
|
context->SetClipRect(clip, nsClipCombine_kReplace);
|
|
|
|
|
|
|
|
context->Translate(-aRect.x, -aRect.y);
|
|
|
|
|
|
|
|
*aResult = context;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-06-16 06:40:29 +04:00
|
|
|
nsRect
|
|
|
|
nsLayoutUtils::GetAllInFlowBoundingRect(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// Get the union of all rectangles in this and continuation frames
|
|
|
|
nsRect r = aFrame->GetRect();
|
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
if (!parent)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
for (nsIFrame* f = aFrame->GetNextContinuation(); f; f = f->GetNextContinuation()) {
|
2007-02-05 22:32:26 +03:00
|
|
|
r.UnionRect(r, nsRect(f->GetOffsetTo(parent), f->GetSize()));
|
2006-06-16 06:40:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r.IsEmpty()) {
|
|
|
|
// It could happen that all the rects are empty (eg zero-width or
|
|
|
|
// zero-height). In that case, use the first rect for the frame.
|
|
|
|
r = aFrame->GetRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
return r - aFrame->GetPosition();
|
|
|
|
}
|
2006-07-06 14:43:51 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(nsIFrame* aFrame,
|
|
|
|
nsIFontMetrics** aFontMetrics)
|
|
|
|
{
|
|
|
|
nsStyleContext* sc = aFrame->GetStyleContext();
|
2007-03-31 01:11:41 +04:00
|
|
|
return aFrame->PresContext()->DeviceContext()->
|
2006-07-06 14:43:51 +04:00
|
|
|
GetMetricsFor(sc->GetStyleFont()->mFont,
|
|
|
|
sc->GetStyleVisibility()->mLangGroup,
|
|
|
|
*aFontMetrics);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBlockFrame*
|
|
|
|
nsLayoutUtils::FindNearestBlockAncestor(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame* nextAncestor;
|
|
|
|
for (nextAncestor = aFrame->GetParent(); nextAncestor;
|
|
|
|
nextAncestor = nextAncestor->GetParent()) {
|
|
|
|
nsBlockFrame* block;
|
|
|
|
if (NS_SUCCEEDED(nextAncestor->QueryInterface(kBlockFrameCID, (void**)&block)))
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsLayoutUtils::GetParentOrPlaceholderFor(nsFrameManager* aFrameManager,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW)
|
|
|
|
return aFrameManager->GetPlaceholderFrameFor(aFrame);
|
|
|
|
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();
|
|
|
|
|
|
|
|
nsAutoVoidArray frame1Ancestors;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoVoidArray frame2Ancestors;
|
|
|
|
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;
|
|
|
|
PRInt32 last1 = frame1Ancestors.Count() - 1;
|
|
|
|
PRInt32 last2 = frame2Ancestors.Count() - 1;
|
|
|
|
while (last1 >= 0 && last2 >= 0) {
|
|
|
|
nsIFrame* frame1 = NS_STATIC_CAST(nsIFrame*, frame1Ancestors.ElementAt(last1));
|
|
|
|
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
|
|
|
|
// frame in the flow. Walk back to find that frame now.
|
|
|
|
aFrame = aFrame->GetFirstInFlow();
|
|
|
|
|
|
|
|
void* value = aFrame->GetProperty(nsGkAtoms::IBSplitSpecialSibling);
|
|
|
|
return NS_STATIC_CAST(nsIFrame*, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
nsIScrollableFrame* rootScrollableFrame = nsnull;
|
|
|
|
CallQueryInterface(rootScrollFrame, &rootScrollableFrame);
|
|
|
|
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
|
|
|
|
2007-05-09 12:48:38 +04:00
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::GetAbsoluteCoord(const nsStyleCoord& aStyle,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nscoord& aResult)
|
2006-12-17 17:06:42 +03:00
|
|
|
{
|
|
|
|
nsStyleUnit unit = aStyle.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
aResult = aStyle.GetCoordValue();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (eStyleUnit_Chars == unit) {
|
2007-05-05 10:09:50 +04:00
|
|
|
aResult = nsLayoutUtils::CharsToCoord(aStyle, aRenderingContext,
|
|
|
|
aFrame->GetStyleContext());
|
2006-12-17 17:06:42 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-05-04 03:11:00 +04:00
|
|
|
// Handles only -moz-intrinsic and -moz-min-intrinsic, and
|
|
|
|
// -moz-shrink-wrap for min-width and max-width, since the others
|
|
|
|
// (-moz-shrink-wrap for width, and -moz-fill) have no effect on
|
|
|
|
// 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();
|
|
|
|
NS_ASSERTION(val == NS_STYLE_WIDTH_INTRINSIC ||
|
|
|
|
val == NS_STYLE_WIDTH_MIN_INTRINSIC ||
|
|
|
|
val == NS_STYLE_WIDTH_SHRINK_WRAP ||
|
|
|
|
val == NS_STYLE_WIDTH_FILL,
|
|
|
|
"unexpected enumerated value for width property");
|
|
|
|
if (val == NS_STYLE_WIDTH_FILL)
|
|
|
|
return PR_FALSE;
|
|
|
|
if (val == NS_STYLE_WIDTH_SHRINK_WRAP) {
|
|
|
|
if (aProperty == PROP_WIDTH)
|
|
|
|
return PR_FALSE; // handle like 'width: auto'
|
|
|
|
if (aProperty == PROP_MAX_WIDTH)
|
|
|
|
// constrain large 'width' values down to -moz-intrinsic
|
|
|
|
val = NS_STYLE_WIDTH_INTRINSIC;
|
|
|
|
else
|
|
|
|
// constrain small 'width' or 'max-width' values up to -moz-min-intrinsic
|
|
|
|
val = NS_STYLE_WIDTH_MIN_INTRINSIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(val == NS_STYLE_WIDTH_INTRINSIC ||
|
|
|
|
val == NS_STYLE_WIDTH_MIN_INTRINSIC,
|
|
|
|
"should have reduced everything remaining to one of these");
|
|
|
|
if (val == NS_STYLE_WIDTH_INTRINSIC)
|
|
|
|
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);
|
|
|
|
NS_STATIC_CAST(nsFrame*, aFrame)->ListTag(stdout);
|
|
|
|
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 &&
|
|
|
|
(styleWidth.GetIntValue() == NS_STYLE_WIDTH_INTRINSIC ||
|
|
|
|
styleWidth.GetIntValue() == NS_STYLE_WIDTH_MIN_INTRINSIC)) {
|
|
|
|
// -moz-shrink-wrap and -moz-fill enumerated widths compute intrinsic
|
|
|
|
// widths just like auto.
|
|
|
|
// For -moz-intrinsic and -moz-min-intrinsic, we handle them like
|
|
|
|
// 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);
|
|
|
|
NS_STATIC_CAST(nsFrame*, aFrame)->ListTag(stdout);
|
|
|
|
printf(" %s intrinsic width from frame is %d.\n",
|
|
|
|
aType == MIN_WIDTH ? "min" : "pref", result);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
result += coordOutsideWidth;
|
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
|
|
|
coordOutsideWidth = 0;
|
|
|
|
pctOutsideWidth = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
coordOutsideWidth += offsets.hBorder;
|
|
|
|
|
|
|
|
if (boxSizing == NS_STYLE_BOX_SIZING_BORDER) {
|
|
|
|
min += coordOutsideWidth;
|
|
|
|
result += coordOutsideWidth;
|
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
|
|
|
coordOutsideWidth = 0;
|
|
|
|
pctOutsideWidth = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
coordOutsideWidth += offsets.hMargin;
|
|
|
|
pctOutsideWidth += offsets.hPctMargin;
|
|
|
|
|
|
|
|
min += coordOutsideWidth;
|
|
|
|
result += coordOutsideWidth;
|
|
|
|
pctTotal += pctOutsideWidth;
|
|
|
|
|
2006-12-17 17:06:42 +03:00
|
|
|
nscoord w;
|
2007-05-04 03:11:00 +04:00
|
|
|
if (GetAbsoluteCoord(styleWidth, aRenderingContext, aFrame, w) ||
|
|
|
|
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;
|
2007-05-04 03:11:00 +04:00
|
|
|
if (GetAbsoluteCoord(styleMaxWidth, aRenderingContext, aFrame, maxw) ||
|
|
|
|
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;
|
2007-05-04 03:11:00 +04:00
|
|
|
if (GetAbsoluteCoord(styleMinWidth, aRenderingContext, aFrame, minw) ||
|
|
|
|
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)) {
|
|
|
|
nsSize size(0, 0);
|
|
|
|
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);
|
|
|
|
NS_STATIC_CAST(nsFrame*, aFrame)->ListTag(stdout);
|
|
|
|
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(
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
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(aFrame, "non-null frame expected");
|
|
|
|
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
|
|
|
|
NS_PRECONDITION(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"unconstrained widths no longer supported");
|
|
|
|
|
2006-12-17 17:06:42 +03:00
|
|
|
nscoord result;
|
|
|
|
if (GetAbsoluteCoord(aCoord, aRenderingContext, aFrame, result)) {
|
|
|
|
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
|
|
|
}
|
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-04 03:11:00 +04:00
|
|
|
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_Null ||
|
|
|
|
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;
|
|
|
|
if (GetAbsoluteCoord(aCoord, aRenderingContext, aFrame, result)) {
|
|
|
|
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) {
|
|
|
|
case NS_STYLE_WIDTH_INTRINSIC:
|
|
|
|
result = aFrame->GetPrefWidth(aRenderingContext);
|
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
break;
|
|
|
|
case NS_STYLE_WIDTH_MIN_INTRINSIC:
|
|
|
|
result = aFrame->GetMinWidth(aRenderingContext);
|
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
break;
|
|
|
|
case NS_STYLE_WIDTH_SHRINK_WRAP:
|
|
|
|
{
|
|
|
|
nscoord pref = aFrame->GetPrefWidth(aRenderingContext),
|
|
|
|
min = aFrame->GetMinWidth(aRenderingContext),
|
|
|
|
fill = aContainingBlockWidth -
|
|
|
|
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
|
|
|
|
result = PR_MAX(min, PR_MIN(pref, fill));
|
|
|
|
NS_ASSERTION(result >= 0, "width less than zero");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_WIDTH_FILL:
|
|
|
|
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(
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
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
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "non-null frame expected");
|
|
|
|
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
|
2006-12-17 17:06:42 +03:00
|
|
|
|
|
|
|
nscoord result;
|
|
|
|
if (GetAbsoluteCoord(aCoord, aRenderingContext, aFrame, result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
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-04 03:11:00 +04:00
|
|
|
NS_ASSERTION(aCoord.GetUnit() == eStyleUnit_Null ||
|
|
|
|
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'
|
|
|
|
unit == eStyleUnit_Null || // only for 'max-height'
|
|
|
|
(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(
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame, nsSize aIntrinsicSize, 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
|
|
|
}
|
|
|
|
|
|
|
|
if (stylePos->mMaxWidth.GetUnit() != eStyleUnit_Null) {
|
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) {
|
2006-12-18 16:20:18 +03:00
|
|
|
height = nsLayoutUtils::ComputeHeightDependentValue(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
|
|
|
aFrame, aCBSize.height, stylePos->mHeight) -
|
|
|
|
boxSizingAdjust.height;
|
|
|
|
if (height < 0)
|
|
|
|
height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsAutoHeight(stylePos->mMaxHeight, aCBSize.height)) {
|
2006-12-18 16:20:18 +03:00
|
|
|
maxHeight = nsLayoutUtils::ComputeHeightDependentValue(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
|
|
|
aFrame, aCBSize.height, stylePos->mMaxHeight) -
|
|
|
|
boxSizingAdjust.height;
|
|
|
|
if (maxHeight < 0)
|
|
|
|
maxHeight = 0;
|
|
|
|
} else {
|
|
|
|
maxHeight = nscoord_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsAutoHeight(stylePos->mMinHeight, aCBSize.height)) {
|
2006-12-18 16:20:18 +03:00
|
|
|
minHeight = nsLayoutUtils::ComputeHeightDependentValue(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
|
|
|
aFrame, aCBSize.height, stylePos->mMinHeight) -
|
|
|
|
boxSizingAdjust.height;
|
|
|
|
if (minHeight < 0)
|
|
|
|
minHeight = 0;
|
|
|
|
} else {
|
|
|
|
minHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAutoWidth) {
|
|
|
|
if (isAutoHeight) {
|
|
|
|
|
|
|
|
// 'auto' width, 'auto' height
|
|
|
|
if (minWidth > maxWidth)
|
|
|
|
maxWidth = minWidth;
|
|
|
|
if (minHeight > maxHeight)
|
|
|
|
maxHeight = minHeight;
|
|
|
|
|
|
|
|
nscoord heightAtMaxWidth, heightAtMinWidth,
|
|
|
|
widthAtMaxHeight, widthAtMinHeight;
|
|
|
|
if (aIntrinsicSize.width > 0) {
|
2007-02-19 02:11:32 +03:00
|
|
|
heightAtMaxWidth = MULDIV(maxWidth, aIntrinsicSize.height, aIntrinsicSize.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
|
|
|
if (heightAtMaxWidth < minHeight)
|
|
|
|
heightAtMaxWidth = minHeight;
|
2007-02-19 02:11:32 +03:00
|
|
|
heightAtMinWidth = MULDIV(minWidth, aIntrinsicSize.height, aIntrinsicSize.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
|
|
|
if (heightAtMinWidth > maxHeight)
|
|
|
|
heightAtMinWidth = maxHeight;
|
|
|
|
} else {
|
|
|
|
heightAtMaxWidth = aIntrinsicSize.height;
|
|
|
|
heightAtMinWidth = aIntrinsicSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIntrinsicSize.height > 0) {
|
2007-02-19 02:11:32 +03:00
|
|
|
widthAtMaxHeight = MULDIV(maxHeight, aIntrinsicSize.width, aIntrinsicSize.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 (widthAtMaxHeight < minWidth)
|
|
|
|
widthAtMaxHeight = minWidth;
|
2007-02-19 02:11:32 +03:00
|
|
|
widthAtMinHeight = MULDIV(minHeight, aIntrinsicSize.width, aIntrinsicSize.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 (widthAtMinHeight > maxWidth)
|
|
|
|
widthAtMinHeight = maxWidth;
|
|
|
|
} else {
|
|
|
|
widthAtMaxHeight = aIntrinsicSize.width;
|
|
|
|
widthAtMinHeight = aIntrinsicSize.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIntrinsicSize.width > maxWidth) {
|
|
|
|
if (aIntrinsicSize.height > maxHeight) {
|
2007-02-19 02:11:32 +03:00
|
|
|
if (PRInt64(maxWidth) * PRInt64(aIntrinsicSize.height) <=
|
|
|
|
PRInt64(maxHeight) * PRInt64(aIntrinsicSize.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
|
|
|
width = maxWidth;
|
|
|
|
height = heightAtMaxWidth;
|
|
|
|
} else {
|
|
|
|
height = maxHeight;
|
|
|
|
width = widthAtMaxHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
width = maxWidth;
|
|
|
|
height = heightAtMaxWidth;
|
|
|
|
}
|
|
|
|
} else if (aIntrinsicSize.width < minWidth) {
|
|
|
|
if (aIntrinsicSize.height < minHeight) {
|
2007-02-19 02:11:32 +03:00
|
|
|
if (PRInt64(minWidth) * PRInt64(aIntrinsicSize.height) <=
|
|
|
|
PRInt64(minHeight) * PRInt64(aIntrinsicSize.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
|
|
|
height = minHeight;
|
|
|
|
width = widthAtMinHeight;
|
|
|
|
} else {
|
|
|
|
width = minWidth;
|
|
|
|
height = heightAtMinWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
width = minWidth;
|
|
|
|
height = heightAtMinWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aIntrinsicSize.height > maxHeight) {
|
|
|
|
height = maxHeight;
|
|
|
|
width = widthAtMaxHeight;
|
|
|
|
} else if (aIntrinsicSize.height < minHeight) {
|
|
|
|
height = minHeight;
|
|
|
|
width = widthAtMinHeight;
|
|
|
|
} else {
|
|
|
|
width = aIntrinsicSize.width;
|
|
|
|
height = aIntrinsicSize.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 'auto' width, non-'auto' height
|
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
|
|
|
if (aIntrinsicSize.height != 0) {
|
2007-02-19 02:11:32 +03:00
|
|
|
width = MULDIV(aIntrinsicSize.width, height, aIntrinsicSize.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
|
|
|
} else {
|
|
|
|
width = aIntrinsicSize.width;
|
|
|
|
}
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isAutoHeight) {
|
|
|
|
|
|
|
|
// non-'auto' width, 'auto' height
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
|
|
|
if (aIntrinsicSize.width != 0) {
|
2007-02-19 02:11:32 +03:00
|
|
|
height = MULDIV(aIntrinsicSize.height, width, aIntrinsicSize.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
|
|
|
} else {
|
|
|
|
height = aIntrinsicSize.height;
|
|
|
|
}
|
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// non-'auto' width, non-'auto' height
|
|
|
|
height = NS_CSS_MINMAX(height, minHeight, maxHeight);
|
|
|
|
width = NS_CSS_MINMAX(width, minWidth, maxWidth);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
data.Break(aRenderingContext);
|
|
|
|
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);
|
|
|
|
data.Break(aRenderingContext);
|
|
|
|
return data.prevLines;
|
|
|
|
}
|
2007-01-23 05:58:55 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsLayoutUtils::DrawString(const nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aContext,
|
|
|
|
const PRUnichar* aString,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nsPoint aPoint)
|
|
|
|
{
|
|
|
|
#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) {
|
|
|
|
const nsStyleVisibility* vis = aFrame->GetStyleVisibility();
|
|
|
|
nsBidiDirection direction =
|
|
|
|
(NS_STYLE_DIRECTION_RTL == vis->mDirection) ?
|
|
|
|
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
|
|
|
|
PRUint32 hints = 0;
|
|
|
|
aContext->GetHints(hints);
|
2007-01-23 05:58:55 +03:00
|
|
|
// Only do bidi resolution for width measurement if we have a "real"
|
|
|
|
// textrun implementation. Otherwise assume the platform can get
|
|
|
|
// things right for a mixed-direction string.
|
2007-01-25 04:58:55 +03:00
|
|
|
if (hints & NS_RENDERING_HINT_NEW_TEXT_RUNS) {
|
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();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::GetFirstLineBaseline(const nsIFrame* aFrame, nscoord* aResult)
|
|
|
|
{
|
|
|
|
const nsBlockFrame* block;
|
|
|
|
if (NS_FAILED(NS_CONST_CAST(nsIFrame*, aFrame)->
|
|
|
|
QueryInterface(kBlockFrameCID, (void**)&block))) {
|
|
|
|
// 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) {
|
|
|
|
*aResult = aFrame->GetBaseline();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For first-line baselines, we have to consider scroll frames.
|
|
|
|
if (fType == nsGkAtoms::scrollFrame) {
|
|
|
|
nsIScrollableFrame *sFrame;
|
|
|
|
if (NS_FAILED(CallQueryInterface(NS_CONST_CAST(nsIFrame*,
|
|
|
|
aFrame), &sFrame)) || !sFrame) {
|
|
|
|
NS_NOTREACHED("not scroll frame");
|
|
|
|
}
|
|
|
|
nscoord kidBaseline;
|
|
|
|
if (GetFirstLineBaseline(sFrame->GetScrolledFrame(), &kidBaseline)) {
|
|
|
|
// Consider only the border and padding that contributes to the
|
|
|
|
// kid's position, not the scrolling, so we get the initial
|
|
|
|
// position.
|
|
|
|
*aResult = kidBaseline + aFrame->GetUsedBorderAndPadding().top;
|
|
|
|
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;
|
|
|
|
nscoord kidBaseline;
|
|
|
|
if (GetFirstLineBaseline(kid, &kidBaseline)) {
|
|
|
|
*aResult = kidBaseline + kid->GetPosition().y;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::GetLastLineBaseline(const nsIFrame* aFrame, nscoord* aResult)
|
|
|
|
{
|
|
|
|
const nsBlockFrame* block;
|
|
|
|
if (NS_FAILED(NS_CONST_CAST(nsIFrame*, aFrame)->
|
|
|
|
QueryInterface(kBlockFrameCID, (void**)&block)))
|
|
|
|
// 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
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
/* static */ nsresult
|
|
|
|
nsLayoutUtils::DrawImage(nsIRenderingContext* aRenderingContext,
|
|
|
|
imgIContainer* aImage,
|
|
|
|
const nsRect& aDestRect,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect* aSourceRect)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_CAIRO_GFX
|
|
|
|
nsRect dirtyRect;
|
|
|
|
dirtyRect.IntersectRect(aDirtyRect, aDestRect);
|
|
|
|
if (dirtyRect.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<gfxIImageFrame> imgFrame;
|
|
|
|
aImage->GetCurrentFrame(getter_AddRefs(imgFrame));
|
|
|
|
if (!imgFrame) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIImage> img(do_GetInterface(imgFrame));
|
|
|
|
if (!img) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// twSrcRect is always in appunits (twips),
|
|
|
|
// and has nothing to do with the current transform (it's a region
|
|
|
|
// of the image)
|
|
|
|
gfxRect pxSrc;
|
|
|
|
if (aSourceRect) {
|
|
|
|
PRInt32 p2a = nsIDeviceContext::AppUnitsPerCSSPixel();
|
|
|
|
pxSrc.pos.x = NSAppUnitsToFloatPixels(aSourceRect->x, p2a);
|
|
|
|
pxSrc.pos.y = NSAppUnitsToFloatPixels(aSourceRect->y, p2a);
|
|
|
|
pxSrc.size.width = NSAppUnitsToFloatPixels(aSourceRect->width, p2a);
|
|
|
|
pxSrc.size.height = NSAppUnitsToFloatPixels(aSourceRect->height, p2a);
|
|
|
|
} else {
|
|
|
|
pxSrc.pos.x = pxSrc.pos.y = 0.0;
|
|
|
|
PRInt32 w = 0, h = 0;
|
|
|
|
aImage->GetWidth(&w);
|
|
|
|
aImage->GetHeight(&h);
|
|
|
|
pxSrc.size.width = gfxFloat(w);
|
|
|
|
pxSrc.size.height = gfxFloat(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDeviceContext> dc;
|
|
|
|
aRenderingContext->GetDeviceContext(*getter_AddRefs(dc));
|
|
|
|
PRInt32 d2a = dc->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
// the dest rect is affected by the current transform; that'll be
|
|
|
|
// handled by Image::Draw(), when we actually set up the rectangle.
|
|
|
|
|
|
|
|
// Snap the edges of where layout wants the image to the nearest
|
|
|
|
// pixel, but then convert back to gfxFloats for the rest of the math.
|
|
|
|
gfxRect pxDest;
|
|
|
|
{
|
|
|
|
nsIntRect r;
|
|
|
|
r.x = NSAppUnitsToIntPixels(aDestRect.x, d2a);
|
|
|
|
r.y = NSAppUnitsToIntPixels(aDestRect.y, d2a);
|
|
|
|
r.width = NSAppUnitsToIntPixels(aDestRect.XMost(), d2a) - r.x;
|
|
|
|
r.height = NSAppUnitsToIntPixels(aDestRect.YMost(), d2a) - r.y;
|
|
|
|
pxDest.pos.x = gfxFloat(r.x);
|
|
|
|
pxDest.pos.y = gfxFloat(r.y);
|
|
|
|
pxDest.size.width = gfxFloat(r.width);
|
|
|
|
pxDest.size.height = gfxFloat(r.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// And likewise for the dirty rect. (Is should be OK to round to
|
|
|
|
// nearest rather than outwards, since any dirty rects coming from the
|
|
|
|
// OS should be on pixel boundaries; the rest is other things it's
|
|
|
|
// been intersected with, and we should be rounding those consistently.)
|
|
|
|
gfxRect pxDirty;
|
|
|
|
{
|
|
|
|
nsIntRect r;
|
2007-03-20 23:36:59 +03:00
|
|
|
r.x = NSAppUnitsToIntPixels(dirtyRect.x, d2a);
|
|
|
|
r.y = NSAppUnitsToIntPixels(dirtyRect.y, d2a);
|
|
|
|
r.width = NSAppUnitsToIntPixels(dirtyRect.XMost(), d2a) - r.x;
|
|
|
|
r.height = NSAppUnitsToIntPixels(dirtyRect.YMost(), d2a) - r.y;
|
2007-03-20 03:58:20 +03:00
|
|
|
pxDirty.pos.x = gfxFloat(r.x);
|
|
|
|
pxDirty.pos.y = gfxFloat(r.y);
|
|
|
|
pxDirty.size.width = gfxFloat(r.width);
|
|
|
|
pxDirty.size.height = gfxFloat(r.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reduce the src rect to what's needed for the dirty rect.
|
|
|
|
if (pxDirty.size.width != pxDest.size.width) {
|
|
|
|
const gfxFloat ratio = pxSrc.size.width / pxDest.size.width;
|
|
|
|
pxSrc.pos.x += (pxDirty.pos.x - pxDest.pos.x) * ratio;
|
|
|
|
pxSrc.size.width = pxDirty.size.width * ratio;
|
|
|
|
}
|
|
|
|
if (pxDirty.size.height != pxDest.size.height) {
|
|
|
|
const gfxFloat ratio = pxSrc.size.height / pxDest.size.height;
|
|
|
|
pxSrc.pos.y += (pxDirty.pos.y - pxDest.pos.y) * ratio;
|
|
|
|
pxSrc.size.height = pxDirty.size.height * ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we were asked to draw a 0-width or 0-height image,
|
|
|
|
// as either the src or dst, just bail; we can't do anything
|
|
|
|
// useful with this.
|
|
|
|
if (pxSrc.IsEmpty() || pxDirty.IsEmpty())
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For Bug 87819
|
|
|
|
// imgFrame may want image to start at different position, so adjust
|
|
|
|
nsIntRect pxImgFrameRect;
|
|
|
|
imgFrame->GetRect(pxImgFrameRect);
|
|
|
|
|
|
|
|
if (pxImgFrameRect.x > 0) {
|
|
|
|
pxSrc.pos.x -= gfxFloat(pxImgFrameRect.x);
|
|
|
|
|
|
|
|
gfxFloat scaled_x = pxSrc.pos.x;
|
|
|
|
if (pxDirty.size.width != pxSrc.size.width) {
|
|
|
|
scaled_x = scaled_x * (pxDirty.size.width / pxSrc.size.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pxSrc.pos.x < 0.0) {
|
|
|
|
pxDirty.pos.x -= scaled_x;
|
|
|
|
pxSrc.size.width += pxSrc.pos.x;
|
|
|
|
pxDirty.size.width += scaled_x;
|
|
|
|
if (pxSrc.size.width <= 0.0 || pxDirty.size.width <= 0.0)
|
|
|
|
return NS_OK;
|
|
|
|
pxSrc.pos.x = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pxSrc.pos.x > gfxFloat(pxImgFrameRect.width)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pxImgFrameRect.y > 0) {
|
|
|
|
pxSrc.pos.y -= gfxFloat(pxImgFrameRect.y);
|
|
|
|
|
|
|
|
gfxFloat scaled_y = pxSrc.pos.y;
|
|
|
|
if (pxDirty.size.height != pxSrc.size.height) {
|
|
|
|
scaled_y = scaled_y * (pxDirty.size.height / pxSrc.size.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pxSrc.pos.y < 0.0) {
|
|
|
|
pxDirty.pos.y -= scaled_y;
|
|
|
|
pxSrc.size.height += pxSrc.pos.y;
|
|
|
|
pxDirty.size.height += scaled_y;
|
|
|
|
if (pxSrc.size.height <= 0.0 || pxDirty.size.height <= 0.0)
|
|
|
|
return NS_OK;
|
|
|
|
pxSrc.pos.y = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pxSrc.pos.y > gfxFloat(pxImgFrameRect.height)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return img->Draw(*aRenderingContext, pxSrc, pxDirty);
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* If somebody wants non-cairo GFX to work again, they could write
|
|
|
|
* appropriate code to call nsIRenderingContext::DrawImage here
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
aRC->SetFont(font->mFont, visibility->mLangGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsLayoutUtils::CharsToCoord(const nsStyleCoord& aStyle,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsStyleContext* aStyleContext)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aStyle.GetUnit() == eStyleUnit_Chars,
|
|
|
|
"Shouldn't have called this");
|
|
|
|
|
|
|
|
SetFontFromStyle(aRenderingContext, aStyleContext);
|
|
|
|
nscoord fontWidth;
|
|
|
|
aRenderingContext->SetTextRunRTL(PR_FALSE);
|
|
|
|
aRenderingContext->GetWidth('M', fontWidth);
|
|
|
|
return aStyle.GetIntValue() * fontWidth;
|
|
|
|
}
|
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;
|
|
|
|
case eStyleUnit_Null:
|
|
|
|
return PR_FALSE;
|
|
|
|
default:
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::HasNonZeroSide(const nsStyleSides& aSides)
|
|
|
|
{
|
|
|
|
nsStyleCoord coord;
|
|
|
|
aSides.GetTop(coord);
|
|
|
|
if (NonZeroStyleCoord(coord)) return PR_TRUE;
|
|
|
|
aSides.GetRight(coord);
|
|
|
|
if (NonZeroStyleCoord(coord)) return PR_TRUE;
|
|
|
|
aSides.GetBottom(coord);
|
|
|
|
if (NonZeroStyleCoord(coord)) return PR_TRUE;
|
|
|
|
aSides.GetLeft(coord);
|
|
|
|
if (NonZeroStyleCoord(coord)) return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PRBool
|
|
|
|
nsLayoutUtils::FrameHasTransparency(nsIFrame* aFrame) {
|
|
|
|
if (aFrame->GetStyleContext()->GetStyleDisplay()->mOpacity < 1.0f)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
const nsStyleBorder* border = aFrame->GetStyleContext()->GetStyleBorder();
|
|
|
|
if (HasNonZeroSide(border->mBorderRadius))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
if (aFrame->IsThemed())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRBool isCanvas;
|
|
|
|
const nsStyleBackground* bg;
|
|
|
|
if (!nsCSSRendering::FindBackground(aFrame->PresContext(), aFrame, &bg, &isCanvas))
|
|
|
|
return PR_TRUE;
|
|
|
|
if (bg->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)
|
|
|
|
return PR_TRUE;
|
|
|
|
if (NS_GET_A(bg->mBackgroundColor) < 255)
|
|
|
|
return PR_TRUE;
|
|
|
|
if (bg->mBackgroundClip != NS_STYLE_BG_CLIP_BORDER)
|
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|