2003-01-05 08:05:17 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Boris Zbarsky <bzbarsky@mit.edu>.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2007-03-20 03:58:20 +03:00
|
|
|
* Boris Zbarsky <bzbarsky@mit.edu> (original author)
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
#ifndef nsLayoutUtils_h__
|
|
|
|
#define nsLayoutUtils_h__
|
|
|
|
|
|
|
|
class nsIFrame;
|
2005-12-13 02:53:06 +03:00
|
|
|
class nsIFormControlFrame;
|
2004-08-01 03:15:21 +04:00
|
|
|
class nsPresContext;
|
2003-04-22 03:06:40 +04:00
|
|
|
class nsIContent;
|
|
|
|
class nsIAtom;
|
2004-08-06 19:55:17 +04:00
|
|
|
class nsIScrollableView;
|
2004-10-19 06:24:27 +04:00
|
|
|
class nsIScrollableFrame;
|
2005-06-02 13:00:48 +04:00
|
|
|
class nsIDOMEvent;
|
2006-01-26 05:29:17 +03:00
|
|
|
class nsRegion;
|
2006-04-18 03:16:46 +04:00
|
|
|
class nsDisplayListBuilder;
|
2006-07-06 14:43:51 +04:00
|
|
|
class nsIFontMetrics;
|
2003-04-22 03:06:40 +04:00
|
|
|
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2004-01-28 03:18:22 +03:00
|
|
|
#include "nsStyleSet.h"
|
2004-10-19 06:24:27 +04:00
|
|
|
#include "nsIView.h"
|
2003-01-05 08:05:17 +03:00
|
|
|
|
2007-01-17 05:37:19 +03:00
|
|
|
class nsBlockFrame;
|
|
|
|
|
2003-01-05 08:05:17 +03:00
|
|
|
/**
|
|
|
|
* nsLayoutUtils is a namespace class used for various helper
|
|
|
|
* functions that are useful in multiple places in layout. The goal
|
|
|
|
* is not to define multiple copies of the same static helper.
|
|
|
|
*/
|
|
|
|
class nsLayoutUtils
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* GetBeforeFrame returns the :before frame of the given frame, if
|
|
|
|
* one exists. This is typically O(1). The frame passed in must be
|
|
|
|
* the first-in-flow.
|
|
|
|
*
|
|
|
|
* @param aFrame the frame whose :before is wanted
|
|
|
|
* @return the :before frame or nsnull if there isn't one
|
|
|
|
*/
|
2005-02-18 09:06:47 +03:00
|
|
|
static nsIFrame* GetBeforeFrame(nsIFrame* aFrame);
|
2003-01-05 08:05:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GetAfterFrame returns the :after frame of the given frame, if one
|
|
|
|
* exists. This will walk the in-flow chain to the last-in-flow if
|
|
|
|
* needed. This function is typically O(N) in the number of child
|
|
|
|
* frames, following in-flows, etc.
|
|
|
|
*
|
|
|
|
* @param aFrame the frame whose :after is wanted
|
|
|
|
* @return the :after frame or nsnull if there isn't one
|
|
|
|
*/
|
2005-02-18 09:06:47 +03:00
|
|
|
static nsIFrame* GetAfterFrame(nsIFrame* aFrame);
|
2003-01-05 08:05:17 +03:00
|
|
|
|
2003-04-22 03:06:40 +04:00
|
|
|
/**
|
|
|
|
* Given a frame, search up the frame tree until we find an
|
|
|
|
* ancestor "Page" frame, if any.
|
|
|
|
*
|
|
|
|
* @param the frame to start at
|
2007-01-30 03:06:41 +03:00
|
|
|
* @return a frame of type nsGkAtoms::pageFrame or nsnull if no
|
2003-04-22 03:06:40 +04:00
|
|
|
* such ancestor exists
|
2003-02-23 05:49:22 +03:00
|
|
|
*/
|
|
|
|
static nsIFrame* GetPageFrame(nsIFrame* aFrame);
|
2003-04-22 03:06:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IsGeneratedContentFor returns PR_TRUE if aFrame is generated
|
|
|
|
* content of type aPseudoElement for aContent
|
|
|
|
*
|
|
|
|
* @param aContent the content node we're looking at. If this is
|
|
|
|
* null, then we just assume that aFrame has the right content
|
|
|
|
* pointer.
|
|
|
|
* @param aFrame the frame we're looking at
|
|
|
|
* @param aPseudoElement the pseudo type we're interested in
|
|
|
|
* @return whether aFrame is the generated aPseudoElement frame for aContent
|
|
|
|
*/
|
|
|
|
static PRBool IsGeneratedContentFor(nsIContent* aContent, nsIFrame* aFrame,
|
|
|
|
nsIAtom* aPseudoElement);
|
2003-10-15 04:49:03 +04:00
|
|
|
|
|
|
|
/**
|
2004-04-13 01:53:22 +04:00
|
|
|
* CompareTreePosition determines whether aContent1 comes before or
|
|
|
|
* after aContent2 in a preorder traversal of the content tree.
|
2003-10-15 04:49:03 +04:00
|
|
|
*
|
2004-04-13 01:53:22 +04:00
|
|
|
* @param aCommonAncestor either null, or a common ancestor of
|
|
|
|
* aContent1 and aContent2. Actually this is
|
|
|
|
* only a hint; if it's not an ancestor of
|
|
|
|
* aContent1 or aContent2, this function will
|
|
|
|
* still work, but it will be slower than
|
|
|
|
* normal.
|
|
|
|
* @return < 0 if aContent1 is before aContent2
|
|
|
|
* > 0 if aContent1 is after aContent2,
|
|
|
|
* 0 otherwise (meaning they're the same, or they're in
|
|
|
|
* different documents)
|
2003-10-15 04:49:03 +04:00
|
|
|
*/
|
2004-04-13 01:53:22 +04:00
|
|
|
static PRInt32 CompareTreePosition(nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2,
|
|
|
|
nsIContent* aCommonAncestor = nsnull)
|
|
|
|
{
|
|
|
|
return DoCompareTreePosition(aContent1, aContent2, -1, 1, aCommonAncestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* More generic version of |CompareTreePosition|. |aIf1Ancestor|
|
|
|
|
* gives the value to return when 1 is an ancestor of 2, and likewise
|
|
|
|
* for |aIf2Ancestor|. Passing (-1, 1) gives preorder traversal
|
|
|
|
* order, and (1, -1) gives postorder traversal order.
|
|
|
|
*/
|
|
|
|
static PRInt32 DoCompareTreePosition(nsIContent* aContent1,
|
|
|
|
nsIContent* aContent2,
|
|
|
|
PRInt32 aIf1Ancestor,
|
|
|
|
PRInt32 aIf2Ancestor,
|
|
|
|
nsIContent* aCommonAncestor = nsnull);
|
2007-01-18 01:48:24 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CompareTreePosition determines whether aFrame1 comes before or
|
|
|
|
* after aFrame2 in a preorder traversal of the frame tree, where out
|
|
|
|
* of flow frames are treated as children of their placeholders. This is
|
|
|
|
* basically the same ordering as DoCompareTreePosition(nsIContent*) except
|
|
|
|
* that it handles anonymous content properly and there are subtleties with
|
|
|
|
* continuations.
|
|
|
|
*
|
|
|
|
* @param aCommonAncestor either null, or a common ancestor of
|
|
|
|
* aContent1 and aContent2. Actually this is
|
|
|
|
* only a hint; if it's not an ancestor of
|
|
|
|
* aContent1 or aContent2, this function will
|
|
|
|
* still work, but it will be slower than
|
|
|
|
* normal.
|
|
|
|
* @return < 0 if aContent1 is before aContent2
|
|
|
|
* > 0 if aContent1 is after aContent2,
|
|
|
|
* 0 otherwise (meaning they're the same, or they're in
|
|
|
|
* different frame trees)
|
|
|
|
*/
|
|
|
|
static PRInt32 CompareTreePosition(nsIFrame* aFrame1,
|
|
|
|
nsIFrame* aFrame2,
|
|
|
|
nsIFrame* aCommonAncestor = nsnull)
|
|
|
|
{
|
|
|
|
return DoCompareTreePosition(aFrame1, aFrame2, -1, 1, aCommonAncestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* More generic version of |CompareTreePosition|. |aIf1Ancestor|
|
|
|
|
* gives the value to return when 1 is an ancestor of 2, and likewise
|
|
|
|
* for |aIf2Ancestor|. Passing (-1, 1) gives preorder traversal
|
|
|
|
* order, and (1, -1) gives postorder traversal order.
|
|
|
|
*/
|
|
|
|
static PRInt32 DoCompareTreePosition(nsIFrame* aFrame1,
|
|
|
|
nsIFrame* aFrame2,
|
|
|
|
PRInt32 aIf1Ancestor,
|
|
|
|
PRInt32 aIf2Ancestor,
|
|
|
|
nsIFrame* aCommonAncestor = nsnull);
|
|
|
|
|
2003-10-15 04:49:03 +04:00
|
|
|
/**
|
|
|
|
* GetLastSibling simply finds the last sibling of aFrame, or returns nsnull if
|
|
|
|
* aFrame is null.
|
|
|
|
*/
|
|
|
|
static nsIFrame* GetLastSibling(nsIFrame* aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FindSiblingViewFor locates the child of aParentView that aFrame's
|
|
|
|
* view should be inserted 'above' (i.e., before in sibling view
|
|
|
|
* order). This is the first child view of aParentView whose
|
|
|
|
* corresponding content is before aFrame's content (view siblings
|
|
|
|
* are in reverse content order).
|
|
|
|
*/
|
|
|
|
static nsIView* FindSiblingViewFor(nsIView* aParentView, nsIFrame* aFrame);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
/**
|
|
|
|
* Get the parent of aFrame. If aFrame is the root frame for a document,
|
|
|
|
* and the document has a parent document in the same view hierarchy, then
|
|
|
|
* we try to return the subdocumentframe in the parent document.
|
|
|
|
*/
|
|
|
|
static nsIFrame* GetCrossDocParentFrame(nsIFrame* aFrame);
|
|
|
|
|
2003-10-15 04:49:03 +04:00
|
|
|
/**
|
|
|
|
* IsProperAncestorFrame checks whether aAncestorFrame is an ancestor
|
|
|
|
* of aFrame and not equal to aFrame.
|
|
|
|
* @param aCommonAncestor nsnull, or a common ancestor of aFrame and
|
|
|
|
* aAncestorFrame. If non-null, this can bound the search and speed up
|
|
|
|
* the function
|
|
|
|
*/
|
|
|
|
static PRBool IsProperAncestorFrame(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
nsIFrame* aCommonAncestor = nsnull);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
/**
|
|
|
|
* Like IsProperAncestorFrame, but looks across document boundaries.
|
|
|
|
*/
|
|
|
|
static PRBool IsProperAncestorFrameCrossDoc(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
|
|
|
|
nsIFrame* aCommonAncestor = nsnull);
|
|
|
|
|
2004-10-19 06:24:27 +04:00
|
|
|
/**
|
|
|
|
* GetFrameFor returns the root frame for a view
|
|
|
|
* @param aView is the view to return the root frame for
|
|
|
|
* @return the root frame for the view
|
|
|
|
*/
|
|
|
|
static nsIFrame* GetFrameFor(nsIView *aView)
|
|
|
|
{ return NS_STATIC_CAST(nsIFrame*, aView->GetClientData()); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetScrollableFrameFor returns the scrollable frame for a scrollable view
|
|
|
|
* @param aScrollableView is the scrollable view to return the
|
|
|
|
* scrollable frame for.
|
|
|
|
* @return the scrollable frame for the scrollable view
|
|
|
|
*/
|
|
|
|
static nsIScrollableFrame* GetScrollableFrameFor(nsIScrollableView *aScrollableView);
|
|
|
|
|
2004-11-03 05:52:16 +03:00
|
|
|
/**
|
|
|
|
* GetScrollableFrameFor returns the scrollable frame for a scrolled frame
|
|
|
|
*/
|
|
|
|
static nsIScrollableFrame* GetScrollableFrameFor(nsIFrame *aScrolledFrame);
|
|
|
|
|
2004-09-21 08:41:08 +04:00
|
|
|
static nsPresContext::ScrollbarStyles
|
|
|
|
ScrollbarStylesOfView(nsIScrollableView *aScrollableView);
|
|
|
|
|
2004-08-06 19:55:17 +04:00
|
|
|
/**
|
|
|
|
* GetNearestScrollingView locates the first ancestor of aView (or
|
2004-09-21 08:41:08 +04:00
|
|
|
* aView itself) that is scrollable. It does *not* count an
|
|
|
|
* 'overflow' style of 'hidden' as scrollable, even though a scrolling
|
|
|
|
* view is present. Thus, the direction of the scroll is needed as
|
|
|
|
* an argument.
|
2004-08-06 19:55:17 +04:00
|
|
|
*
|
|
|
|
* @param aView the view we're looking at
|
2004-09-21 08:41:08 +04:00
|
|
|
* @param aDirection Whether it's for horizontal or vertical scrolling.
|
2004-08-06 19:55:17 +04:00
|
|
|
* @return the nearest scrollable view or nsnull if not found
|
|
|
|
*/
|
2004-09-21 08:41:08 +04:00
|
|
|
enum Direction { eHorizontal, eVertical, eEither };
|
|
|
|
static nsIScrollableView* GetNearestScrollingView(nsIView* aView,
|
|
|
|
Direction aDirection);
|
2004-08-06 19:55:17 +04:00
|
|
|
|
2003-04-22 03:06:40 +04:00
|
|
|
/**
|
|
|
|
* HasPseudoStyle returns PR_TRUE if aContent (whose primary style
|
|
|
|
* context is aStyleContext) has the aPseudoElement pseudo-style
|
|
|
|
* attached to it; returns PR_FALSE otherwise.
|
|
|
|
*
|
|
|
|
* @param aContent the content node we're looking at
|
|
|
|
* @param aStyleContext aContent's style context
|
|
|
|
* @param aPseudoElement the name of the pseudo style we care about
|
|
|
|
* @param aPresContext the presentation context
|
|
|
|
* @return whether aContent has aPseudoElement style attached to it
|
|
|
|
*/
|
|
|
|
static PRBool HasPseudoStyle(nsIContent* aContent,
|
|
|
|
nsStyleContext* aStyleContext,
|
|
|
|
nsIAtom* aPseudoElement,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* aPresContext)
|
2003-04-22 03:06:40 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPresContext, "Must have a prescontext");
|
|
|
|
NS_PRECONDITION(aPseudoElement, "Must have a pseudo name");
|
|
|
|
|
|
|
|
nsRefPtr<nsStyleContext> pseudoContext;
|
|
|
|
if (aContent) {
|
2004-01-28 03:18:22 +03:00
|
|
|
pseudoContext = aPresContext->StyleSet()->
|
|
|
|
ProbePseudoStyleFor(aContent, aPseudoElement, aStyleContext);
|
2003-04-22 03:06:40 +04:00
|
|
|
}
|
|
|
|
return pseudoContext != nsnull;
|
|
|
|
}
|
2004-09-13 17:35:46 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this frame is a placeholder for a float, then return the float,
|
|
|
|
* otherwise return nsnull.
|
|
|
|
*/
|
|
|
|
static nsIFrame* GetFloatFromPlaceholder(nsIFrame* aPossiblePlaceholder);
|
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.
|
|
|
|
static PRUint8 CombineBreakType(PRUint8 aOrigBreakType, PRUint8 aNewBreakType);
|
2005-02-08 05:15:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return PR_TRUE if aFrame is the CSS initial containing block for
|
|
|
|
* its pres-shell
|
|
|
|
*/
|
|
|
|
static PRBool IsInitialContainingBlock(nsIFrame* aFrame);
|
2005-06-02 13:00:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the coordinates of a given DOM mouse event, relative to a given
|
|
|
|
* frame. Works only for DOM events generated by nsGUIEvents.
|
|
|
|
* @param aDOMEvent the event
|
|
|
|
* @param aFrame the frame to make coordinates relative to
|
|
|
|
* @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
|
|
|
|
* for some reason the coordinates for the mouse are not known (e.g.,
|
|
|
|
* the event is not a GUI event).
|
|
|
|
*/
|
2005-08-23 07:57:07 +04:00
|
|
|
static nsPoint GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent,
|
|
|
|
nsIFrame* aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the coordinates of a given native mouse event, relative to a given
|
|
|
|
* frame.
|
|
|
|
* @param aEvent the event
|
|
|
|
* @param aFrame the frame to make coordinates relative to
|
|
|
|
* @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
|
|
|
|
* for some reason the coordinates for the mouse are not known (e.g.,
|
|
|
|
* the event is not a GUI event).
|
|
|
|
*/
|
|
|
|
static nsPoint GetEventCoordinatesRelativeTo(nsEvent* aEvent,
|
|
|
|
nsIFrame* aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the coordinates of a given native mouse event, relative to the nearest
|
|
|
|
* view for a given frame.
|
|
|
|
* The "nearest view" is the view returned by nsFrame::GetOffsetFromView.
|
|
|
|
* XXX this is extremely BOGUS because "nearest view" is a mess; every
|
|
|
|
* use of this method is really a bug!
|
|
|
|
* @param aEvent the event
|
|
|
|
* @param aFrame the frame to make coordinates relative to
|
|
|
|
* @param aView view to which returned coordinates are relative
|
|
|
|
* @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
|
|
|
|
* for some reason the coordinates for the mouse are not known (e.g.,
|
|
|
|
* the event is not a GUI event).
|
|
|
|
*/
|
|
|
|
static nsPoint GetEventCoordinatesForNearestView(nsEvent* aEvent,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIView** aView = nsnull);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translate from widget coordinates to the view's coordinates
|
|
|
|
* @param aPresContext the PresContext for the view
|
|
|
|
* @param aWidget the widget
|
|
|
|
* @param aPt the point relative to the widget
|
|
|
|
* @param aView view to which returned coordinates are relative
|
|
|
|
* @return the point in the view's coordinates
|
|
|
|
*/
|
|
|
|
static nsPoint TranslateWidgetToView(nsPresContext* aPresContext,
|
|
|
|
nsIWidget* aWidget, nsIntPoint aPt,
|
|
|
|
nsIView* aView);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
/**
|
|
|
|
* Given aFrame, the root frame of a stacking context, find its descendant
|
|
|
|
* frame under the point aPt that receives a mouse event at that location,
|
|
|
|
* or nsnull if there is no such frame.
|
|
|
|
* @param aPt the point, relative to the frame origin
|
|
|
|
*/
|
|
|
|
static nsIFrame* GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given aFrame, the root frame of a stacking context, paint it and its
|
|
|
|
* descendants to aRenderingContext.
|
|
|
|
* @param aRenderingContext a rendering context translated so that (0,0)
|
|
|
|
* is the origin of aFrame
|
|
|
|
* @param aDirtyRegion the region that must be painted, in the coordinates
|
|
|
|
* of aFrame
|
2006-02-06 23:38:47 +03:00
|
|
|
* @param aBackground paint the dirty area with this color before drawing
|
|
|
|
* the actual content; pass NS_RGBA(0,0,0,0) to draw no background
|
2006-01-26 05:29:17 +03:00
|
|
|
*/
|
|
|
|
static nsresult 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
|
|
|
|
|
|
|
/**
|
|
|
|
* @param aRootFrame the root frame of the tree to be displayed
|
|
|
|
* @param aMovingFrame a frame that has moved
|
|
|
|
* @param aPt the amount by which aMovingFrame has moved and the rect will
|
|
|
|
* be copied
|
|
|
|
* @param aCopyRect a rectangle that will be copied, relative to aRootFrame
|
|
|
|
* @param aRepaintRegion a subregion of aCopyRect+aDelta that must be repainted
|
|
|
|
* after doing the bitblt
|
|
|
|
*
|
|
|
|
* Ideally this function would actually have the rect-to-copy as an output
|
|
|
|
* rather than an input, but for now, scroll bitblitting is limited to
|
|
|
|
* the whole of a single widget, so we cannot choose the rect.
|
|
|
|
*
|
|
|
|
* This function assumes that the caller will do a bitblt copy of aCopyRect
|
|
|
|
* to aCopyRect+aPt. It computes a region that must be repainted in order
|
|
|
|
* for the resulting rendering to be correct.
|
|
|
|
*
|
|
|
|
* The region consists of:
|
|
|
|
* a) any visible background-attachment:fixed areas in the after-move display
|
|
|
|
* list
|
|
|
|
* b) any visible areas of the before-move display list corresponding to
|
|
|
|
* frames that will not move (translated by aDelta)
|
|
|
|
* c) any visible areas of the after-move display list corresponding to
|
|
|
|
* frames that did not move
|
|
|
|
* d) except that if the same display list element is visible in b) and c)
|
|
|
|
* for a frame that did not move and paints a uniform color within its
|
|
|
|
* bounds, then the intersection of its old and new bounds can be excluded
|
|
|
|
* when it is processed by b) and c).
|
|
|
|
*
|
|
|
|
* We may return a larger region if computing the above region precisely is
|
|
|
|
* too expensive.
|
|
|
|
*/
|
|
|
|
static nsresult ComputeRepaintRegionForCopy(nsIFrame* aRootFrame,
|
|
|
|
nsIFrame* aMovingFrame,
|
|
|
|
nsPoint aDelta,
|
|
|
|
const nsRect& aCopyRect,
|
|
|
|
nsRegion* aRepaintRegion);
|
|
|
|
|
|
|
|
static nsresult CreateOffscreenContext(nsIDeviceContext* deviceContext,
|
|
|
|
nsIDrawingSurface* surface,
|
|
|
|
const nsRect& aRect,
|
|
|
|
nsIRenderingContext** aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compute the used z-index of aFrame; returns zero for elements to which
|
|
|
|
* z-index does not apply, and for z-index:auto
|
|
|
|
*/
|
|
|
|
static PRInt32 GetZIndex(nsIFrame* aFrame);
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
BinarySearchForPosition(nsIRenderingContext* acx,
|
|
|
|
const PRUnichar* aText,
|
|
|
|
PRInt32 aBaseWidth,
|
|
|
|
PRInt32 aBaseInx,
|
|
|
|
PRInt32 aStartInx,
|
|
|
|
PRInt32 aEndInx,
|
|
|
|
PRInt32 aCursorPos,
|
|
|
|
PRInt32& aIndex,
|
|
|
|
PRInt32& aTextWidth);
|
2005-12-13 02:53:06 +03:00
|
|
|
|
2006-06-16 06:40:29 +04:00
|
|
|
/**
|
|
|
|
* Get the union of all rects in aFrame and its continuations, relative
|
|
|
|
* to aFrame's origin. Scrolling is taken into account, but this shouldn't
|
|
|
|
* matter because it should be impossible to have some continuations scrolled
|
|
|
|
* differently from others.
|
|
|
|
*/
|
|
|
|
static nsRect GetAllInFlowBoundingRect(nsIFrame* aFrame);
|
2006-07-06 14:43:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the font metrics corresponding to the frame's style data.
|
|
|
|
* @param aFrame the frame
|
|
|
|
* @param aFontMetrics the font metrics result
|
|
|
|
* @return success or failure code
|
|
|
|
*/
|
|
|
|
static nsresult GetFontMetricsForFrame(nsIFrame* aFrame,
|
|
|
|
nsIFontMetrics** aFontMetrics);
|
2006-10-19 05:47:47 +04:00
|
|
|
|
2007-01-17 05:37:19 +03:00
|
|
|
/**
|
|
|
|
* Find the immediate child of aParent whose frame subtree contains
|
|
|
|
* aDescendantFrame. Returns null if aDescendantFrame is not a descendant
|
|
|
|
* of aParent.
|
|
|
|
*/
|
|
|
|
static nsIFrame* FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the nearest ancestor that's a block
|
|
|
|
*/
|
|
|
|
static nsBlockFrame* FindNearestBlockAncestor(nsIFrame* aFrame);
|
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
/**
|
|
|
|
* If aFrame is an out of flow frame, return its placeholder, otherwise
|
|
|
|
* return its parent.
|
|
|
|
*/
|
|
|
|
static nsIFrame* GetParentOrPlaceholderFor(nsFrameManager* aFrameManager,
|
|
|
|
nsIFrame* aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find the closest common ancestor of aFrame1 and aFrame2, following
|
|
|
|
* out of flow frames to their placeholders instead of their parents. Returns
|
|
|
|
* nsnull if the frames are in different frame trees.
|
|
|
|
*
|
|
|
|
* @param aKnownCommonAncestorHint a frame that is believed to be on the
|
|
|
|
* ancestor chain of both aFrame1 and aFrame2. If null, or a frame that is
|
|
|
|
* not in fact on both ancestor chains, then this function will still return
|
|
|
|
* the correct result, but it will be slower.
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
|
|
|
GetClosestCommonAncestorViaPlaceholders(nsIFrame* aFrame1, nsIFrame* aFrame2,
|
|
|
|
nsIFrame* aKnownCommonAncestorHint);
|
2006-11-01 16:56:48 +03:00
|
|
|
|
2007-03-26 07:27:53 +04:00
|
|
|
/**
|
|
|
|
* Get a frame's next-in-flow, or, if it doesn't have one, its special sibling.
|
|
|
|
*/
|
|
|
|
static nsIFrame*
|
|
|
|
GetNextContinuationOrSpecialSibling(nsIFrame *aFrame);
|
|
|
|
|
2006-11-01 16:56:48 +03:00
|
|
|
/**
|
|
|
|
* Check whether aFrame is a part of the scrollbar or scrollcorner of
|
|
|
|
* the root content.
|
|
|
|
* @param aFrame the checking frame
|
|
|
|
* @return if TRUE, the frame is a part of the scrollbar or scrollcorner of
|
|
|
|
* the root content.
|
|
|
|
*/
|
|
|
|
static PRBool IsViewportScrollbarFrame(nsIFrame* 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the contribution of aFrame to its containing block's intrinsic
|
|
|
|
* width. This considers the child's intrinsic width, its 'width',
|
|
|
|
* 'min-width', and 'max-width' properties, and its padding, border,
|
|
|
|
* and margin.
|
|
|
|
*/
|
|
|
|
enum IntrinsicWidthType { MIN_WIDTH, PREF_WIDTH };
|
|
|
|
static nscoord IntrinsicForContainer(nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
IntrinsicWidthType aType);
|
|
|
|
|
2007-05-04 03:11:02 +04:00
|
|
|
/*
|
|
|
|
* Convert nsStyleCoord to nscoord when percentages depend on the
|
|
|
|
* containing block width.
|
|
|
|
*/
|
2006-12-18 16:20:18 +03:00
|
|
|
static nscoord ComputeWidthDependentValue(
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
const nsStyleCoord& aCoord);
|
|
|
|
|
2007-05-04 03:11:02 +04:00
|
|
|
/*
|
|
|
|
* Convert nsStyleCoord to nscoord when percentages depend on the
|
|
|
|
* containing block width, and enumerated values are for width,
|
|
|
|
* min-width, or max-width. Returns the content-box width value based
|
|
|
|
* on aContentEdgeToBoxSizing and aBoxSizingToMarginEdge (which are
|
|
|
|
* also used for the enumerated values for width. This function does
|
|
|
|
* not handle 'auto'. It ensures that the result is nonnegative.
|
|
|
|
*
|
|
|
|
* @param aRenderingContext Rendering context for font measurement/metrics.
|
|
|
|
* @param aFrame Frame whose (min-/max-/)width is being computed
|
|
|
|
* @param aContainingBlockWidth Width of aFrame's containing block.
|
|
|
|
* @param aContentEdgeToBoxSizing The sum of any left/right padding and
|
|
|
|
* border that goes inside the rect chosen by -moz-box-sizing.
|
|
|
|
* @param aBoxSizingToMarginEdge The sum of any left/right padding, border,
|
|
|
|
* and margin that goes outside the rect chosen by -moz-box-sizing.
|
|
|
|
* @param aCoord The width value to compute.
|
|
|
|
*/
|
|
|
|
static nscoord ComputeWidthValue(
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nscoord aContainingBlockWidth,
|
|
|
|
nscoord aContentEdgeToBoxSizing,
|
|
|
|
nscoord aBoxSizingToMarginEdge,
|
|
|
|
const nsStyleCoord& aCoord);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert nsStyleCoord to nscoord when percentages depend on the
|
|
|
|
* containing block height.
|
|
|
|
*/
|
2006-12-18 16:20:18 +03:00
|
|
|
static nscoord 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
|
|
|
|
|
|
|
static nsSize ComputeSizeWithIntrinsicDimensions(
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsIFrame* aFrame, nsSize aIntrinsicSize, nsSize aCBSize,
|
2007-05-04 03:11:02 +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
|
|
|
|
|
|
|
// Implement nsIFrame::GetPrefWidth in terms of nsIFrame::AddInlinePrefWidth
|
|
|
|
static nscoord PrefWidthFromInline(nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aRenderingContext);
|
|
|
|
|
|
|
|
// Implement nsIFrame::GetMinWidth in terms of nsIFrame::AddInlineMinWidth
|
|
|
|
static nscoord MinWidthFromInline(nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aRenderingContext);
|
2007-01-23 05:58:55 +03:00
|
|
|
|
|
|
|
static void DrawString(const nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aContext,
|
|
|
|
const PRUnichar* aString,
|
|
|
|
PRInt32 aLength,
|
|
|
|
nsPoint aPoint);
|
|
|
|
|
|
|
|
static nscoord GetStringWidth(const nsIFrame* aFrame,
|
|
|
|
nsIRenderingContext* aContext,
|
|
|
|
const PRUnichar* aString,
|
|
|
|
PRInt32 aLength);
|
2007-01-23 07:06:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Derive a baseline of |aFrame| (measured from its top border edge)
|
|
|
|
* from its first in-flow line box (not descending into anything with
|
|
|
|
* 'overflow' not 'visible', potentially including aFrame itself).
|
|
|
|
*
|
|
|
|
* Returns true if a baseline was found (and fills in aResult).
|
|
|
|
* Otherwise returns false.
|
|
|
|
*/
|
|
|
|
static PRBool GetFirstLineBaseline(const nsIFrame* aFrame, nscoord* aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Derive a baseline of |aFrame| (measured from its top border edge)
|
|
|
|
* from its last in-flow line box (not descending into anything with
|
|
|
|
* 'overflow' not 'visible', potentially including aFrame itself).
|
|
|
|
*
|
|
|
|
* Returns true if a baseline was found (and fills in aResult).
|
|
|
|
* Otherwise returns false.
|
|
|
|
*/
|
|
|
|
static PRBool GetLastLineBaseline(const nsIFrame* aFrame, nscoord* aResult);
|
2007-02-18 13:43:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the closest frame (the frame passed in or one of its parents) that
|
|
|
|
* qualifies as a "layer"; used in DOM0 methods that depends upon that
|
|
|
|
* definition. This is the nearest frame that is either positioned or scrolled
|
|
|
|
* (the child of a scroll frame). In Gecko terms, it's approximately
|
|
|
|
* equivalent to having a view, at least for simple HTML. However, views are
|
|
|
|
* going away, so this is a cleaner definition.
|
|
|
|
*/
|
|
|
|
static nsIFrame* GetClosestLayer(nsIFrame* aFrame);
|
2007-03-20 03:58:20 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a single image.
|
|
|
|
* @param aImage The image.
|
|
|
|
* @param aRenderingContext Where to draw the image, set up with an
|
|
|
|
* appropriate scale and transform for drawing in
|
|
|
|
* app units (aDestRect).
|
|
|
|
* @param aDestRect Where to draw the image (app units).
|
|
|
|
* @param aDirtyRect Draw only within this region (rounded to the
|
|
|
|
* nearest pixel); the intersection of
|
|
|
|
* invalidation and clipping.
|
|
|
|
* @param aSourceRect If null, draw the entire image so it fits in
|
|
|
|
* aDestRect. If non-null, the subregion of the
|
|
|
|
* image that should be drawn (in app units, such
|
|
|
|
* that converting it to CSS pixels yields image
|
|
|
|
* pixels).
|
|
|
|
*/
|
|
|
|
static nsresult DrawImage(nsIRenderingContext* aRenderingContext,
|
|
|
|
imgIContainer* aImage,
|
|
|
|
const nsRect& aDestRect,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect* aSourceRect = nsnull);
|
2007-05-05 10:09:50 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the font on aRC based on the style in aSC
|
|
|
|
*/
|
|
|
|
static void SetFontFromStyle(nsIRenderingContext* aRC, nsStyleContext* aSC);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert an eStyleUnit_Chars nsStyleCoord to an nscoord.
|
|
|
|
*
|
|
|
|
* @param aStyle the style coord
|
|
|
|
* @param aRenderingContext the rendering context to use for font measurement
|
|
|
|
* @param aStyleContext the style context to use for font infomation
|
|
|
|
*/
|
|
|
|
static nscoord CharsToCoord(const nsStyleCoord& aStyle,
|
|
|
|
nsIRenderingContext* aRenderingContext,
|
|
|
|
nsStyleContext* aStyleContext);
|
2003-01-05 08:05:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsLayoutUtils_h__
|