Bug 376662. Make nsIFrame::GetOffsetTo not explicitly use views. r+sr=bzbarsky
[mozilla-central.git] / layout / base / nsLayoutUtils.h
blob0929c02ce5b7ba7b1c1d6722b17cf2ba51df7040
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Boris Zbarsky <bzbarsky@mit.edu>.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Boris Zbarsky <bzbarsky@mit.edu> (original author)
24 * L. David Baron <dbaron@dbaron.org>, Mozilla Corporation
25 * Mats Palmgren <mats.palmgren@bredband.net>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef nsLayoutUtils_h__
42 #define nsLayoutUtils_h__
44 class nsIFormControlFrame;
45 class nsPresContext;
46 class nsIContent;
47 class nsIAtom;
48 class nsIScrollableView;
49 class nsIScrollableFrame;
50 class nsIDOMEvent;
51 class nsRegion;
52 class nsDisplayListBuilder;
53 class nsIFontMetrics;
55 #include "prtypes.h"
56 #include "nsStyleContext.h"
57 #include "nsAutoPtr.h"
58 #include "nsStyleSet.h"
59 #include "nsIView.h"
60 #include "nsIFrame.h"
61 #include "nsThreadUtils.h"
63 class nsBlockFrame;
65 /**
66 * nsLayoutUtils is a namespace class used for various helper
67 * functions that are useful in multiple places in layout. The goal
68 * is not to define multiple copies of the same static helper.
70 class nsLayoutUtils
72 public:
73 /**
74 * GetBeforeFrame returns the outermost :before frame of the given frame, if
75 * one exists. This is typically O(1). The frame passed in must be
76 * the first-in-flow.
78 * @param aFrame the frame whose :before is wanted
79 * @return the :before frame or nsnull if there isn't one
81 static nsIFrame* GetBeforeFrame(nsIFrame* aFrame);
83 /**
84 * GetAfterFrame returns the outermost :after frame of the given frame, if one
85 * exists. This will walk the in-flow chain to the last-in-flow if
86 * needed. This function is typically O(N) in the number of child
87 * frames, following in-flows, etc.
89 * @param aFrame the frame whose :after is wanted
90 * @return the :after frame or nsnull if there isn't one
92 static nsIFrame* GetAfterFrame(nsIFrame* aFrame);
94 /**
95 * Given a frame, search up the frame tree until we find an
96 * ancestor that (or the frame itself) is of type aFrameType, if any.
98 * @param aFrame the frame to start at
99 * @param aFrameType the frame type to look for
100 * @return a frame of the given type or nsnull if no
101 * such ancestor exists
103 static nsIFrame* GetClosestFrameOfType(nsIFrame* aFrame, nsIAtom* aFrameType);
105 /**
106 * Given a frame, search up the frame tree until we find an
107 * ancestor that (or the frame itself) is a "Page" frame, if any.
109 * @param aFrame the frame to start at
110 * @return a frame of type nsGkAtoms::pageFrame or nsnull if no
111 * such ancestor exists
113 static nsIFrame* GetPageFrame(nsIFrame* aFrame)
115 return GetClosestFrameOfType(aFrame, nsGkAtoms::pageFrame);
119 * IsGeneratedContentFor returns PR_TRUE if aFrame is the outermost
120 * frame for generated content of type aPseudoElement for aContent.
121 * aFrame *might not* have the aPseudoElement pseudo-style! For example
122 * it might be a table outer frame and the inner table frame might
123 * have the pseudo-style.
125 * @param aContent the content node we're looking at. If this is
126 * null, then we just assume that aFrame has the right content
127 * pointer.
128 * @param aFrame the frame we're looking at
129 * @param aPseudoElement the pseudo type we're interested in
130 * @return whether aFrame is the generated aPseudoElement frame for aContent
132 static PRBool IsGeneratedContentFor(nsIContent* aContent, nsIFrame* aFrame,
133 nsIAtom* aPseudoElement);
136 * CompareTreePosition determines whether aContent1 comes before or
137 * after aContent2 in a preorder traversal of the content tree.
139 * @param aCommonAncestor either null, or a common ancestor of
140 * aContent1 and aContent2. Actually this is
141 * only a hint; if it's not an ancestor of
142 * aContent1 or aContent2, this function will
143 * still work, but it will be slower than
144 * normal.
145 * @return < 0 if aContent1 is before aContent2
146 * > 0 if aContent1 is after aContent2,
147 * 0 otherwise (meaning they're the same, or they're in
148 * different documents)
150 static PRInt32 CompareTreePosition(nsIContent* aContent1,
151 nsIContent* aContent2,
152 nsIContent* aCommonAncestor = nsnull)
154 return DoCompareTreePosition(aContent1, aContent2, -1, 1, aCommonAncestor);
158 * More generic version of |CompareTreePosition|. |aIf1Ancestor|
159 * gives the value to return when 1 is an ancestor of 2, and likewise
160 * for |aIf2Ancestor|. Passing (-1, 1) gives preorder traversal
161 * order, and (1, -1) gives postorder traversal order.
163 static PRInt32 DoCompareTreePosition(nsIContent* aContent1,
164 nsIContent* aContent2,
165 PRInt32 aIf1Ancestor,
166 PRInt32 aIf2Ancestor,
167 nsIContent* aCommonAncestor = nsnull);
170 * CompareTreePosition determines whether aFrame1 comes before or
171 * after aFrame2 in a preorder traversal of the frame tree, where out
172 * of flow frames are treated as children of their placeholders. This is
173 * basically the same ordering as DoCompareTreePosition(nsIContent*) except
174 * that it handles anonymous content properly and there are subtleties with
175 * continuations.
177 * @param aCommonAncestor either null, or a common ancestor of
178 * aContent1 and aContent2. Actually this is
179 * only a hint; if it's not an ancestor of
180 * aContent1 or aContent2, this function will
181 * still work, but it will be slower than
182 * normal.
183 * @return < 0 if aContent1 is before aContent2
184 * > 0 if aContent1 is after aContent2,
185 * 0 otherwise (meaning they're the same, or they're in
186 * different frame trees)
188 static PRInt32 CompareTreePosition(nsIFrame* aFrame1,
189 nsIFrame* aFrame2,
190 nsIFrame* aCommonAncestor = nsnull)
192 return DoCompareTreePosition(aFrame1, aFrame2, -1, 1, aCommonAncestor);
196 * More generic version of |CompareTreePosition|. |aIf1Ancestor|
197 * gives the value to return when 1 is an ancestor of 2, and likewise
198 * for |aIf2Ancestor|. Passing (-1, 1) gives preorder traversal
199 * order, and (1, -1) gives postorder traversal order.
201 static PRInt32 DoCompareTreePosition(nsIFrame* aFrame1,
202 nsIFrame* aFrame2,
203 PRInt32 aIf1Ancestor,
204 PRInt32 aIf2Ancestor,
205 nsIFrame* aCommonAncestor = nsnull);
208 * GetLastContinuationWithChild gets the last continuation in aFrame's chain
209 * that has a child, or the first continuation if the frame has no children.
211 static nsIFrame* GetLastContinuationWithChild(nsIFrame* aFrame);
214 * GetLastSibling simply finds the last sibling of aFrame, or returns nsnull if
215 * aFrame is null.
217 static nsIFrame* GetLastSibling(nsIFrame* aFrame);
220 * FindSiblingViewFor locates the child of aParentView that aFrame's
221 * view should be inserted 'above' (i.e., before in sibling view
222 * order). This is the first child view of aParentView whose
223 * corresponding content is before aFrame's content (view siblings
224 * are in reverse content order).
226 static nsIView* FindSiblingViewFor(nsIView* aParentView, nsIFrame* aFrame);
229 * Get the parent of aFrame. If aFrame is the root frame for a document,
230 * and the document has a parent document in the same view hierarchy, then
231 * we try to return the subdocumentframe in the parent document.
232 * @param aExtraOffset [in/out] if non-null, then as we cross documents
233 * an extra offset may be required and it will be added to aCrossDocOffset
235 static nsIFrame* GetCrossDocParentFrame(const nsIFrame* aFrame,
236 nsPoint* aCrossDocOffset = nsnull);
239 * IsProperAncestorFrame checks whether aAncestorFrame is an ancestor
240 * of aFrame and not equal to aFrame.
241 * @param aCommonAncestor nsnull, or a common ancestor of aFrame and
242 * aAncestorFrame. If non-null, this can bound the search and speed up
243 * the function
245 static PRBool IsProperAncestorFrame(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
246 nsIFrame* aCommonAncestor = nsnull);
249 * Like IsProperAncestorFrame, but looks across document boundaries.
251 static PRBool IsProperAncestorFrameCrossDoc(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
252 nsIFrame* aCommonAncestor = nsnull);
255 * GetFrameFor returns the root frame for a view
256 * @param aView is the view to return the root frame for
257 * @return the root frame for the view
259 static nsIFrame* GetFrameFor(nsIView *aView)
260 { return static_cast<nsIFrame*>(aView->GetClientData()); }
263 * GetScrollableFrameFor returns the scrollable frame for a scrollable view
264 * @param aScrollableView is the scrollable view to return the
265 * scrollable frame for.
266 * @return the scrollable frame for the scrollable view
268 static nsIScrollableFrame* GetScrollableFrameFor(nsIScrollableView *aScrollableView);
271 * GetScrollableFrameFor returns the scrollable frame for a scrolled frame
273 static nsIScrollableFrame* GetScrollableFrameFor(nsIFrame *aScrolledFrame);
275 static nsPresContext::ScrollbarStyles
276 ScrollbarStylesOfView(nsIScrollableView *aScrollableView);
279 * GetNearestScrollingView locates the first ancestor of aView (or
280 * aView itself) that is scrollable. It does *not* count an
281 * 'overflow' style of 'hidden' as scrollable, even though a scrolling
282 * view is present. Thus, the direction of the scroll is needed as
283 * an argument.
285 * @param aView the view we're looking at
286 * @param aDirection Whether it's for horizontal or vertical scrolling.
287 * @return the nearest scrollable view or nsnull if not found
289 enum Direction { eHorizontal, eVertical, eEither };
290 static nsIScrollableView* GetNearestScrollingView(nsIView* aView,
291 Direction aDirection);
294 * HasPseudoStyle returns PR_TRUE if aContent (whose primary style
295 * context is aStyleContext) has the aPseudoElement pseudo-style
296 * attached to it; returns PR_FALSE otherwise.
298 * @param aContent the content node we're looking at
299 * @param aStyleContext aContent's style context
300 * @param aPseudoElement the name of the pseudo style we care about
301 * @param aPresContext the presentation context
302 * @return whether aContent has aPseudoElement style attached to it
304 static PRBool HasPseudoStyle(nsIContent* aContent,
305 nsStyleContext* aStyleContext,
306 nsIAtom* aPseudoElement,
307 nsPresContext* aPresContext)
309 NS_PRECONDITION(aPresContext, "Must have a prescontext");
310 NS_PRECONDITION(aPseudoElement, "Must have a pseudo name");
312 nsRefPtr<nsStyleContext> pseudoContext;
313 if (aContent) {
314 pseudoContext = aPresContext->StyleSet()->
315 ProbePseudoStyleFor(aContent, aPseudoElement, aStyleContext);
317 return pseudoContext != nsnull;
321 * If this frame is a placeholder for a float, then return the float,
322 * otherwise return nsnull.
324 static nsIFrame* GetFloatFromPlaceholder(nsIFrame* aPossiblePlaceholder);
326 // Combine aNewBreakType with aOrigBreakType, but limit the break types
327 // to NS_STYLE_CLEAR_LEFT, RIGHT, LEFT_AND_RIGHT.
328 static PRUint8 CombineBreakType(PRUint8 aOrigBreakType, PRUint8 aNewBreakType);
331 * @return PR_TRUE if aFrame is the CSS initial containing block for
332 * its pres-shell
334 static PRBool IsInitialContainingBlock(nsIFrame* aFrame);
337 * Get the coordinates of a given DOM mouse event, relative to a given
338 * frame. Works only for DOM events generated by nsGUIEvents.
339 * @param aDOMEvent the event
340 * @param aFrame the frame to make coordinates relative to
341 * @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
342 * for some reason the coordinates for the mouse are not known (e.g.,
343 * the event is not a GUI event).
345 static nsPoint GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent,
346 nsIFrame* aFrame);
349 * Get the coordinates of a given native mouse event, relative to a given
350 * frame.
351 * @param aEvent the event
352 * @param aFrame the frame to make coordinates relative to
353 * @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
354 * for some reason the coordinates for the mouse are not known (e.g.,
355 * the event is not a GUI event).
357 static nsPoint GetEventCoordinatesRelativeTo(const nsEvent* aEvent,
358 nsIFrame* aFrame);
361 * Get the coordinates of a given native mouse event, relative to the nearest
362 * view for a given frame.
363 * The "nearest view" is the view returned by nsFrame::GetOffsetFromView.
364 * XXX this is extremely BOGUS because "nearest view" is a mess; every
365 * use of this method is really a bug!
366 * @param aEvent the event
367 * @param aFrame the frame to make coordinates relative to
368 * @param aView view to which returned coordinates are relative
369 * @return the point, or (NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE) if
370 * for some reason the coordinates for the mouse are not known (e.g.,
371 * the event is not a GUI event).
373 static nsPoint GetEventCoordinatesForNearestView(nsEvent* aEvent,
374 nsIFrame* aFrame,
375 nsIView** aView = nsnull);
378 * Translate from widget coordinates to the view's coordinates
379 * @param aPresContext the PresContext for the view
380 * @param aWidget the widget
381 * @param aPt the point relative to the widget
382 * @param aView view to which returned coordinates are relative
383 * @return the point in the view's coordinates
385 static nsPoint TranslateWidgetToView(nsPresContext* aPresContext,
386 nsIWidget* aWidget, nsIntPoint aPt,
387 nsIView* aView);
390 * Given aFrame, the root frame of a stacking context, find its descendant
391 * frame under the point aPt that receives a mouse event at that location,
392 * or nsnull if there is no such frame.
393 * @param aPt the point, relative to the frame origin
394 * @param aShouldIgnoreSuppression a boolean to control if the display
395 * list builder should ignore paint suppression or not
397 static nsIFrame* GetFrameForPoint(nsIFrame* aFrame, nsPoint aPt,
398 PRBool aShouldIgnoreSuppression = PR_FALSE);
401 * Given aFrame, the root frame of a stacking context, paint it and its
402 * descendants to aRenderingContext.
403 * @param aRenderingContext a rendering context translated so that (0,0)
404 * is the origin of aFrame; for best results, (0,0) should transform
405 * to pixel-aligned coordinates
406 * @param aDirtyRegion the region that must be painted, in the coordinates
407 * of aFrame
408 * @param aBackground paint the dirty area with this color before drawing
409 * the actual content; pass NS_RGBA(0,0,0,0) to draw no background
411 static nsresult PaintFrame(nsIRenderingContext* aRenderingContext, nsIFrame* aFrame,
412 const nsRegion& aDirtyRegion, nscolor aBackground);
415 * @param aRootFrame the root frame of the tree to be displayed
416 * @param aMovingFrame a frame that has moved
417 * @param aPt the amount by which aMovingFrame has moved and the rect will
418 * be copied
419 * @param aCopyRect a rectangle that will be copied, relative to aRootFrame
420 * @param aRepaintRegion a subregion of aCopyRect+aDelta that must be repainted
421 * after doing the bitblt
423 * Ideally this function would actually have the rect-to-copy as an output
424 * rather than an input, but for now, scroll bitblitting is limited to
425 * the whole of a single widget, so we cannot choose the rect.
427 * This function assumes that the caller will do a bitblt copy of aCopyRect
428 * to aCopyRect+aPt. It computes a region that must be repainted in order
429 * for the resulting rendering to be correct. Frame geometry must have
430 * already been adjusted for the scroll/copy operation.
432 * Conceptually it works by computing a display list in the before-state
433 * and a display list in the after-state and analyzing them to find the
434 * differences. In practice it is only feasible to build a display list
435 * in the after-state (plus building two display lists would be less
436 * efficient), so we use some unfortunately tricky techniques to get by
437 * with just the after-list.
439 * The output region consists of:
440 * a) any visible background-attachment:fixed areas in the after-move display
441 * list
442 * b) any visible areas of the before-move display list corresponding to
443 * frames that will not move (translated by aDelta)
444 * c) any visible areas of the after-move display list corresponding to
445 * frames that did not move
446 * d) except that if the same display list element is visible in b) and c)
447 * for a frame that did not move and paints a uniform color within its
448 * bounds, then the intersection of its old and new bounds can be excluded
449 * when it is processed by b) and c).
451 * We may return a larger region if computing the above region precisely is
452 * too expensive.
454 static nsresult ComputeRepaintRegionForCopy(nsIFrame* aRootFrame,
455 nsIFrame* aMovingFrame,
456 nsPoint aDelta,
457 const nsRect& aCopyRect,
458 nsRegion* aRepaintRegion);
461 * Compute the used z-index of aFrame; returns zero for elements to which
462 * z-index does not apply, and for z-index:auto
464 static PRInt32 GetZIndex(nsIFrame* aFrame);
467 * Uses a binary search for find where the cursor falls in the line of text
468 * It also keeps track of the part of the string that has already been measured
469 * so it doesn't have to keep measuring the same text over and over
471 * @param "aBaseWidth" contains the width in twips of the portion
472 * of the text that has already been measured, and aBaseInx contains
473 * the index of the text that has already been measured.
475 * @param aTextWidth returns the (in twips) the length of the text that falls
476 * before the cursor aIndex contains the index of the text where the cursor falls
478 static PRBool
479 BinarySearchForPosition(nsIRenderingContext* acx,
480 const PRUnichar* aText,
481 PRInt32 aBaseWidth,
482 PRInt32 aBaseInx,
483 PRInt32 aStartInx,
484 PRInt32 aEndInx,
485 PRInt32 aCursorPos,
486 PRInt32& aIndex,
487 PRInt32& aTextWidth);
489 class RectCallback {
490 public:
491 virtual void AddRect(const nsRect& aRect) = 0;
494 * Collect all CSS border-boxes associated with aFrame and its
495 * continuations, "drilling down" through outer table frames and
496 * some anonymous blocks since they're not real CSS boxes.
497 * The boxes are positioned relative to aRelativeTo (taking scrolling
498 * into account) and passed to the callback in frame-tree order.
499 * If aFrame is null, no boxes are returned.
500 * For SVG frames, returns one rectangle, the bounding box.
502 static void GetAllInFlowRects(nsIFrame* aFrame, nsIFrame* aRelativeTo,
503 RectCallback* aCallback);
506 * Computes the union of all rects returned by GetAllInFlowRects. If
507 * the union is empty, returns the first rect.
509 static nsRect GetAllInFlowRectsUnion(nsIFrame* aFrame, nsIFrame* aRelativeTo);
512 * Takes a text-shadow array from the style properties of a given nsIFrame and
513 * computes the union of those shadows along with the given initial rect.
514 * If there are no shadows, the initial rect is returned.
516 static nsRect GetTextShadowRectsUnion(const nsRect& aTextAndDecorationsRect,
517 nsIFrame* aFrame);
520 * Get the font metrics corresponding to the frame's style data.
521 * @param aFrame the frame
522 * @param aFontMetrics the font metrics result
523 * @return success or failure code
525 static nsresult GetFontMetricsForFrame(nsIFrame* aFrame,
526 nsIFontMetrics** aFontMetrics);
529 * Get the font metrics corresponding to the given style data.
530 * @param aStyleContext the style data
531 * @param aFontMetrics the font metrics result
532 * @return success or failure code
534 static nsresult GetFontMetricsForStyleContext(nsStyleContext* aStyleContext,
535 nsIFontMetrics** aFontMetrics);
538 * Find the immediate child of aParent whose frame subtree contains
539 * aDescendantFrame. Returns null if aDescendantFrame is not a descendant
540 * of aParent.
542 static nsIFrame* FindChildContainingDescendant(nsIFrame* aParent, nsIFrame* aDescendantFrame);
545 * Find the nearest ancestor that's a block
547 static nsBlockFrame* FindNearestBlockAncestor(nsIFrame* aFrame);
550 * Cast aFrame to an nsBlockFrame* or return null if it's not
551 * an nsBlockFrame.
553 static nsBlockFrame* GetAsBlock(nsIFrame* aFrame);
556 * If aFrame is an out of flow frame, return its placeholder, otherwise
557 * return its parent.
559 static nsIFrame* GetParentOrPlaceholderFor(nsFrameManager* aFrameManager,
560 nsIFrame* aFrame);
563 * Find the closest common ancestor of aFrame1 and aFrame2, following
564 * out of flow frames to their placeholders instead of their parents. Returns
565 * nsnull if the frames are in different frame trees.
567 * @param aKnownCommonAncestorHint a frame that is believed to be on the
568 * ancestor chain of both aFrame1 and aFrame2. If null, or a frame that is
569 * not in fact on both ancestor chains, then this function will still return
570 * the correct result, but it will be slower.
572 static nsIFrame*
573 GetClosestCommonAncestorViaPlaceholders(nsIFrame* aFrame1, nsIFrame* aFrame2,
574 nsIFrame* aKnownCommonAncestorHint);
577 * Get a frame's next-in-flow, or, if it doesn't have one, its special sibling.
579 static nsIFrame*
580 GetNextContinuationOrSpecialSibling(nsIFrame *aFrame);
583 * Check whether aFrame is a part of the scrollbar or scrollcorner of
584 * the root content.
585 * @param aFrame the checking frame
586 * @return if TRUE, the frame is a part of the scrollbar or scrollcorner of
587 * the root content.
589 static PRBool IsViewportScrollbarFrame(nsIFrame* aFrame);
592 * Get the contribution of aFrame to its containing block's intrinsic
593 * width. This considers the child's intrinsic width, its 'width',
594 * 'min-width', and 'max-width' properties, and its padding, border,
595 * and margin.
597 enum IntrinsicWidthType { MIN_WIDTH, PREF_WIDTH };
598 static nscoord IntrinsicForContainer(nsIRenderingContext* aRenderingContext,
599 nsIFrame* aFrame,
600 IntrinsicWidthType aType);
603 * Convert nsStyleCoord to nscoord when percentages depend on the
604 * containing block width.
606 static nscoord ComputeWidthDependentValue(
607 nscoord aContainingBlockWidth,
608 const nsStyleCoord& aCoord);
611 * Convert nsStyleCoord to nscoord when percentages depend on the
612 * containing block width, and enumerated values are for width,
613 * min-width, or max-width. Returns the content-box width value based
614 * on aContentEdgeToBoxSizing and aBoxSizingToMarginEdge (which are
615 * also used for the enumerated values for width. This function does
616 * not handle 'auto'. It ensures that the result is nonnegative.
618 * @param aRenderingContext Rendering context for font measurement/metrics.
619 * @param aFrame Frame whose (min-/max-/)width is being computed
620 * @param aContainingBlockWidth Width of aFrame's containing block.
621 * @param aContentEdgeToBoxSizing The sum of any left/right padding and
622 * border that goes inside the rect chosen by -moz-box-sizing.
623 * @param aBoxSizingToMarginEdge The sum of any left/right padding, border,
624 * and margin that goes outside the rect chosen by -moz-box-sizing.
625 * @param aCoord The width value to compute.
627 static nscoord ComputeWidthValue(
628 nsIRenderingContext* aRenderingContext,
629 nsIFrame* aFrame,
630 nscoord aContainingBlockWidth,
631 nscoord aContentEdgeToBoxSizing,
632 nscoord aBoxSizingToMarginEdge,
633 const nsStyleCoord& aCoord);
636 * Convert nsStyleCoord to nscoord when percentages depend on the
637 * containing block height.
639 static nscoord ComputeHeightDependentValue(
640 nscoord aContainingBlockHeight,
641 const nsStyleCoord& aCoord);
644 * Calculate the used values for 'width' and 'height' for a replaced element.
646 * http://www.w3.org/TR/CSS21/visudet.html#min-max-widths
648 static nsSize ComputeSizeWithIntrinsicDimensions(
649 nsIRenderingContext* aRenderingContext, nsIFrame* aFrame,
650 const nsIFrame::IntrinsicSize& aIntrinsicSize,
651 nsSize aIntrinsicRatio, nsSize aCBSize,
652 nsSize aMargin, nsSize aBorder, nsSize aPadding);
654 // Implement nsIFrame::GetPrefWidth in terms of nsIFrame::AddInlinePrefWidth
655 static nscoord PrefWidthFromInline(nsIFrame* aFrame,
656 nsIRenderingContext* aRenderingContext);
658 // Implement nsIFrame::GetMinWidth in terms of nsIFrame::AddInlineMinWidth
659 static nscoord MinWidthFromInline(nsIFrame* aFrame,
660 nsIRenderingContext* aRenderingContext);
662 static void DrawString(const nsIFrame* aFrame,
663 nsIRenderingContext* aContext,
664 const PRUnichar* aString,
665 PRInt32 aLength,
666 nsPoint aPoint);
668 static nscoord GetStringWidth(const nsIFrame* aFrame,
669 nsIRenderingContext* aContext,
670 const PRUnichar* aString,
671 PRInt32 aLength);
674 * Derive a baseline of |aFrame| (measured from its top border edge)
675 * from its first in-flow line box (not descending into anything with
676 * 'overflow' not 'visible', potentially including aFrame itself).
678 * Returns true if a baseline was found (and fills in aResult).
679 * Otherwise returns false.
681 static PRBool GetFirstLineBaseline(const nsIFrame* aFrame, nscoord* aResult);
684 * Derive a baseline of |aFrame| (measured from its top border edge)
685 * from its last in-flow line box (not descending into anything with
686 * 'overflow' not 'visible', potentially including aFrame itself).
688 * Returns true if a baseline was found (and fills in aResult).
689 * Otherwise returns false.
691 static PRBool GetLastLineBaseline(const nsIFrame* aFrame, nscoord* aResult);
694 * Returns a y coordinate relative to this frame's origin that represents
695 * the logical bottom of the frame or its visible content, whichever is lower.
696 * Relative positioning is ignored and margins and glyph bounds are not
697 * considered.
698 * This value will be >= mRect.height() and <= overflowRect.YMost() unless
699 * relative positioning is applied.
701 static nscoord CalculateContentBottom(nsIFrame* aFrame);
704 * Gets the closest frame (the frame passed in or one of its parents) that
705 * qualifies as a "layer"; used in DOM0 methods that depends upon that
706 * definition. This is the nearest frame that is either positioned or scrolled
707 * (the child of a scroll frame). In Gecko terms, it's approximately
708 * equivalent to having a view, at least for simple HTML. However, views are
709 * going away, so this is a cleaner definition.
711 static nsIFrame* GetClosestLayer(nsIFrame* aFrame);
714 * Draw a single image.
715 * @param aRenderingContext Where to draw the image, set up with an
716 * appropriate scale and transform for drawing in
717 * app units (aDestRect).
718 * @param aImage The image.
719 * @param aDestRect Where to draw the image (app units).
720 * @param aDirtyRect Draw only within this region (rounded to the
721 * nearest pixel); the intersection of
722 * invalidation and clipping (this is the
723 * destination clip)
724 * @param aSourceRect If null, draw the entire image so it fits in
725 * aDestRect. If non-null, the subregion of the
726 * image that should be drawn (in app units, such
727 * that converting it to CSS pixels yields image
728 * pixels).
730 static nsresult DrawImage(nsIRenderingContext* aRenderingContext,
731 imgIContainer* aImage,
732 const nsRect& aDestRect,
733 const nsRect& aDirtyRect,
734 const nsRect* aSourceRect = nsnull);
737 * Set the font on aRC based on the style in aSC
739 static void SetFontFromStyle(nsIRenderingContext* aRC, nsStyleContext* aSC);
742 * Determine if any style coordinate is nonzero
743 * @param aCoord the style sides
744 * @return PR_TRUE unless all the coordinates are 0%, 0 or null.
746 static PRBool HasNonZeroSide(const nsStyleSides& aSides);
749 * Determine if a widget is likely to require transparency or translucency.
750 * @param aFrame the frame of a <window>, <popup> or <menupopup> element.
751 * @return a value suitable for passing to SetWindowTranslucency
753 static nsTransparencyMode GetFrameTransparency(nsIFrame* aFrame);
756 * Get textrun construction flags determined by a given style; in particular
757 * some combination of:
758 * -- TEXT_DISABLE_OPTIONAL_LIGATURES if letter-spacing is in use
759 * -- TEXT_OPTIMIZE_SPEED if the text-rendering CSS property and font size
760 * and prefs indicate we should be optimizing for speed over quality
762 static PRUint32 GetTextRunFlagsForStyle(nsStyleContext* aStyleContext,
763 const nsStyleText* aStyleText,
764 const nsStyleFont* aStyleFont);
767 * Takes two rectangles whose origins must be the same, and computes
768 * the difference between their union and their intersection as two
769 * rectangles. (This difference is a superset of the difference
770 * between the two rectangles.)
772 static void GetRectDifferenceStrips(const nsRect& aR1, const nsRect& aR2,
773 nsRect* aHStrip, nsRect* aVStrip);
776 * Get a device context that can be used to get up-to-date device
777 * dimensions for the given docshell. For some reason, this is more
778 * complicated than it ought to be in multi-monitor situations.
780 static nsIDeviceContext*
781 GetDeviceContextForScreenInfo(nsIDocShell* aDocShell);
784 * Indicates if the nsIFrame::GetUsedXXX assertions in nsFrame.cpp should
785 * disabled.
787 #ifdef DEBUG
788 static PRBool sDisableGetUsedXAssertions;
789 #endif
792 class nsAutoDisableGetUsedXAssertions
794 #ifdef DEBUG
795 public:
796 nsAutoDisableGetUsedXAssertions()
797 : mOldValue(nsLayoutUtils::sDisableGetUsedXAssertions)
799 nsLayoutUtils::sDisableGetUsedXAssertions = PR_TRUE;
801 ~nsAutoDisableGetUsedXAssertions()
803 nsLayoutUtils::sDisableGetUsedXAssertions = mOldValue;
806 private:
807 PRBool mOldValue;
808 #endif
811 class nsSetAttrRunnable : public nsRunnable
813 public:
814 nsSetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName,
815 const nsAString& aValue);
817 NS_DECL_NSIRUNNABLE
819 nsCOMPtr<nsIContent> mContent;
820 nsCOMPtr<nsIAtom> mAttrName;
821 nsAutoString mValue;
824 class nsUnsetAttrRunnable : public nsRunnable
826 public:
827 nsUnsetAttrRunnable(nsIContent* aContent, nsIAtom* aAttrName);
829 NS_DECL_NSIRUNNABLE
831 nsCOMPtr<nsIContent> mContent;
832 nsCOMPtr<nsIAtom> mAttrName;
835 #endif // nsLayoutUtils_h__