Back to index

lightning-sunbird  0.9+nobinonly
nsLayoutUtils.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Boris Zbarsky <bzbarsky@mit.edu>.
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsLayoutUtils_h__
00039 #define nsLayoutUtils_h__
00040 
00041 class nsIFrame;
00042 class nsPresContext;
00043 class nsIContent;
00044 class nsIAtom;
00045 class nsIScrollableView;
00046 class nsIScrollableFrame;
00047 class nsIDOMEvent;
00048 
00049 #include "prtypes.h"
00050 #include "nsStyleContext.h"
00051 #include "nsAutoPtr.h"
00052 #include "nsStyleSet.h"
00053 #include "nsIView.h"
00054 
00060 class nsLayoutUtils
00061 {
00062 public:
00071   static nsIFrame* GetBeforeFrame(nsIFrame* aFrame);
00072 
00082   static nsIFrame* GetAfterFrame(nsIFrame* aFrame);
00083 
00092   static nsIFrame* GetPageFrame(nsIFrame* aFrame);
00093 
00105   static PRBool IsGeneratedContentFor(nsIContent* aContent, nsIFrame* aFrame,
00106                                       nsIAtom* aPseudoElement);
00107 
00123   static PRInt32 CompareTreePosition(nsIContent* aContent1,
00124                                      nsIContent* aContent2,
00125                                      nsIContent* aCommonAncestor = nsnull)
00126   {
00127     return DoCompareTreePosition(aContent1, aContent2, -1, 1, aCommonAncestor);
00128   }
00129 
00130   /*
00131    * More generic version of |CompareTreePosition|.  |aIf1Ancestor|
00132    * gives the value to return when 1 is an ancestor of 2, and likewise
00133    * for |aIf2Ancestor|.  Passing (-1, 1) gives preorder traversal
00134    * order, and (1, -1) gives postorder traversal order.
00135    */
00136   static PRInt32 DoCompareTreePosition(nsIContent* aContent1,
00137                                        nsIContent* aContent2,
00138                                        PRInt32 aIf1Ancestor,
00139                                        PRInt32 aIf2Ancestor,
00140                                        nsIContent* aCommonAncestor = nsnull);
00141   
00146   static nsIFrame* GetLastSibling(nsIFrame* aFrame);
00147 
00155   static nsIView* FindSiblingViewFor(nsIView* aParentView, nsIFrame* aFrame);
00156 
00164   static PRBool IsProperAncestorFrame(nsIFrame* aAncestorFrame, nsIFrame* aFrame,
00165                                       nsIFrame* aCommonAncestor = nsnull);
00166 
00172   static nsIFrame* GetFrameFor(nsIView *aView)
00173   { return NS_STATIC_CAST(nsIFrame*, aView->GetClientData()); }
00174   
00181   static nsIScrollableFrame* GetScrollableFrameFor(nsIScrollableView *aScrollableView);
00182 
00186   static nsIScrollableFrame* GetScrollableFrameFor(nsIFrame *aScrolledFrame);
00187 
00188   static nsPresContext::ScrollbarStyles
00189     ScrollbarStylesOfView(nsIScrollableView *aScrollableView);
00190 
00202   enum Direction { eHorizontal, eVertical, eEither };
00203   static nsIScrollableView* GetNearestScrollingView(nsIView* aView,
00204                                                     Direction aDirection);
00205 
00217   static PRBool HasPseudoStyle(nsIContent* aContent,
00218                                nsStyleContext* aStyleContext,
00219                                nsIAtom* aPseudoElement,
00220                                nsPresContext* aPresContext)
00221   {
00222     NS_PRECONDITION(aPresContext, "Must have a prescontext");
00223     NS_PRECONDITION(aPseudoElement, "Must have a pseudo name");
00224 
00225     nsRefPtr<nsStyleContext> pseudoContext;
00226     if (aContent) {
00227       pseudoContext = aPresContext->StyleSet()->
00228         ProbePseudoStyleFor(aContent, aPseudoElement, aStyleContext);
00229     }
00230     return pseudoContext != nsnull;
00231   }
00232 
00237   static nsIFrame* GetFloatFromPlaceholder(nsIFrame* aPossiblePlaceholder);
00238 
00239   // Combine aNewBreakType with aOrigBreakType, but limit the break types
00240   // to NS_STYLE_CLEAR_LEFT, RIGHT, LEFT_AND_RIGHT.
00241   static PRUint8 CombineBreakType(PRUint8 aOrigBreakType, PRUint8 aNewBreakType);
00242 
00247   static PRBool IsInitialContainingBlock(nsIFrame* aFrame);
00248 
00258   static nsPoint GetDOMEventCoordinatesRelativeTo(nsIDOMEvent* aDOMEvent, nsIFrame* aFrame);
00259 
00273   static nsPoint GetEventCoordinatesForNearestView(nsEvent* aEvent,
00274                                                    nsIFrame* aFrame,
00275                                                    nsIView** aView = nsnull);
00276 
00285   static nsPoint TranslateWidgetToView(nsPresContext* aPresContext, 
00286                                        nsIWidget* aWidget, nsIntPoint aPt,
00287                                        nsIView* aView);
00288 
00289 };
00290 
00291 #endif // nsLayoutUtils_h__