layout/xul/nsBoxFrame.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /**
     8   Eric D Vaughan
     9   nsBoxFrame is a frame that can lay its children out either vertically or horizontally.
    10   It lays them out according to a min max or preferred size.
    12 **/
    14 #ifndef nsBoxFrame_h___
    15 #define nsBoxFrame_h___
    17 #include "mozilla/Attributes.h"
    18 #include "nsCOMPtr.h"
    19 #include "nsContainerFrame.h"
    20 #include "nsBoxLayout.h"
    22 class nsBoxLayoutState;
    24 nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
    25                          nsStyleContext* aContext,
    26                          bool aIsRoot,
    27                          nsBoxLayout* aLayoutManager);
    28 nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
    29                          nsStyleContext* aContext);
    31 class nsBoxFrame : public nsContainerFrame
    32 {
    33 public:
    34   NS_DECL_FRAMEARENA_HELPERS
    35 #ifdef DEBUG
    36   NS_DECL_QUERYFRAME_TARGET(nsBoxFrame)
    37   NS_DECL_QUERYFRAME
    38 #endif
    40   friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, 
    41                                   nsStyleContext* aContext,
    42                                   bool aIsRoot,
    43                                   nsBoxLayout* aLayoutManager);
    44   friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
    45                                   nsStyleContext* aContext);
    47   // gets the rect inside our border and debug border. If you wish to paint inside a box
    48   // call this method to get the rect so you don't draw on the debug border or outer border.
    50   virtual void SetLayoutManager(nsBoxLayout* aLayout) MOZ_OVERRIDE { mLayoutManager = aLayout; }
    51   virtual nsBoxLayout* GetLayoutManager() MOZ_OVERRIDE { return mLayoutManager; }
    53   virtual nsresult RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIFrame* aChild) MOZ_OVERRIDE;
    55   virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    56   virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    57   virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    58   virtual nscoord GetFlex(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    59   virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    60 #ifdef DEBUG_LAYOUT
    61   virtual nsresult SetDebug(nsBoxLayoutState& aBoxLayoutState, bool aDebug) MOZ_OVERRIDE;
    62   virtual nsresult GetDebug(bool& aDebug) MOZ_OVERRIDE;
    63 #endif
    64   virtual Valignment GetVAlign() const MOZ_OVERRIDE { return mValign; }
    65   virtual Halignment GetHAlign() const MOZ_OVERRIDE { return mHalign; }
    66   NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    68   virtual bool ComputesOwnOverflowArea() MOZ_OVERRIDE { return false; }
    70   // ----- child and sibling operations ---
    72   // ----- public methods -------
    74   virtual void Init(nsIContent*      aContent,
    75                     nsIFrame*        aParent,
    76                     nsIFrame*        asPrevInFlow) MOZ_OVERRIDE;
    79   virtual nsresult AttributeChanged(int32_t         aNameSpaceID,
    80                                     nsIAtom*        aAttribute,
    81                                     int32_t         aModType) MOZ_OVERRIDE;
    83   virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE;
    84   virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    85   virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    87   virtual nsresult Reflow(nsPresContext*          aPresContext,
    88                           nsHTMLReflowMetrics&     aDesiredSize,
    89                           const nsHTMLReflowState& aReflowState,
    90                           nsReflowStatus&          aStatus) MOZ_OVERRIDE;
    92   virtual nsresult  AppendFrames(ChildListID     aListID,
    93                                  nsFrameList&    aFrameList) MOZ_OVERRIDE;
    95   virtual nsresult  InsertFrames(ChildListID     aListID,
    96                                  nsIFrame*       aPrevFrame,
    97                                  nsFrameList&    aFrameList) MOZ_OVERRIDE;
    99   virtual nsresult  RemoveFrame(ChildListID     aListID,
   100                                 nsIFrame*       aOldFrame) MOZ_OVERRIDE;
   102   virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE;
   104   virtual nsresult  SetInitialChildList(ChildListID  aListID,
   105                                         nsFrameList& aChildList) MOZ_OVERRIDE;
   107   virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
   109   virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   111   virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
   112   {
   113     // record that children that are ignorable whitespace should be excluded 
   114     // (When content was loaded via the XUL content sink, it's already
   115     // been excluded, but we need this for when the XUL namespace is used
   116     // in other MIME types or when the XUL CSS display types are used with
   117     // non-XUL elements.)
   119     // This is bogus, but it's what we've always done.
   120     // (Given that we're replaced, we need to say we're a replaced element
   121     // that contains a block so nsHTMLReflowState doesn't tell us to be
   122     // NS_INTRINSICSIZE wide.)
   123     return nsContainerFrame::IsFrameOfType(aFlags &
   124       ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock | eXULBox |
   125         nsIFrame::eExcludesIgnorableWhitespace));
   126   }
   128 #ifdef DEBUG_FRAME_DUMP
   129   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   130 #endif
   132   virtual nsresult DidReflow(nsPresContext*           aPresContext,
   133                              const nsHTMLReflowState*  aReflowState,
   134                              nsDidReflowStatus         aStatus) MOZ_OVERRIDE;
   136   virtual bool HonorPrintBackgroundSettings() MOZ_OVERRIDE;
   138   virtual ~nsBoxFrame();
   140   nsBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, bool aIsRoot = false, nsBoxLayout* aLayoutManager = nullptr);
   142   // virtual so nsStackFrame, nsButtonBoxFrame, nsSliderFrame and nsMenuFrame
   143   // can override it
   144   virtual void BuildDisplayListForChildren(nsDisplayListBuilder*   aBuilder,
   145                                            const nsRect&           aDirtyRect,
   146                                            const nsDisplayListSet& aLists);
   148   virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
   149                                 const nsRect&           aDirtyRect,
   150                                 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
   152 #ifdef DEBUG_LAYOUT
   153     virtual void SetDebugOnChildList(nsBoxLayoutState& aState, nsIFrame* aChild, bool aDebug);
   154     nsresult DisplayDebugInfoFor(nsIFrame*  aBox, 
   155                                  nsPoint& aPoint);
   156 #endif
   158   static nsresult LayoutChildAt(nsBoxLayoutState& aState, nsIFrame* aBox, const nsRect& aRect);
   160   /**
   161    * Utility method to redirect events on descendants to this frame.
   162    * Supports 'allowevents' attribute on descendant elements to allow those
   163    * elements and their descendants to receive events.
   164    */
   165   void WrapListsInRedirector(nsDisplayListBuilder*   aBuilder,
   166                              const nsDisplayListSet& aIn,
   167                              const nsDisplayListSet& aOut);
   169   /**
   170    * This defaults to true, but some box frames (nsListBoxBodyFrame for
   171    * example) don't support ordinals in their children.
   172    */
   173   virtual bool SupportsOrdinalsInChildren();
   175 protected:
   176 #ifdef DEBUG_LAYOUT
   177     virtual void GetBoxName(nsAutoString& aName) MOZ_OVERRIDE;
   178     void PaintXULDebugBackground(nsRenderingContext& aRenderingContext,
   179                                  nsPoint aPt);
   180     void PaintXULDebugOverlay(nsRenderingContext& aRenderingContext,
   181                               nsPoint aPt);
   182 #endif
   184     virtual bool GetInitialEqualSize(bool& aEqualSize); 
   185     virtual void GetInitialOrientation(bool& aIsHorizontal);
   186     virtual void GetInitialDirection(bool& aIsNormal);
   187     virtual bool GetInitialHAlignment(Halignment& aHalign); 
   188     virtual bool GetInitialVAlignment(Valignment& aValign); 
   189     virtual bool GetInitialAutoStretch(bool& aStretch); 
   191     virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
   193     nsSize mPrefSize;
   194     nsSize mMinSize;
   195     nsSize mMaxSize;
   196     nscoord mFlex;
   197     nscoord mAscent;
   199     nsCOMPtr<nsBoxLayout> mLayoutManager;
   201     // Get the point associated with this event. Returns true if a single valid
   202     // point was found. Otherwise false.
   203     bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsPoint& aPoint);
   204     // Gets the event coordinates relative to the widget offset associated with
   205     // this frame. Return true if a single valid point was found.
   206     bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsIntPoint& aPoint);
   208 protected:
   209     void RegUnregAccessKey(bool aDoReg);
   211   NS_HIDDEN_(void) CheckBoxOrder();
   213 private: 
   215 #ifdef DEBUG_LAYOUT
   216     nsresult SetDebug(nsPresContext* aPresContext, bool aDebug);
   217     bool GetInitialDebug(bool& aDebug);
   218     void GetDebugPref(nsPresContext* aPresContext);
   220     void GetDebugBorder(nsMargin& aInset);
   221     void GetDebugPadding(nsMargin& aInset);
   222     void GetDebugMargin(nsMargin& aInset);
   224     nsresult GetFrameSizeWithMargin(nsIFrame* aBox, nsSize& aSize);
   226     void PixelMarginToTwips(nsPresContext* aPresContext, nsMargin& aMarginPixels);
   228     void GetValue(nsPresContext* aPresContext, const nsSize& a, const nsSize& b, char* value);
   229     void GetValue(nsPresContext* aPresContext, int32_t a, int32_t b, char* value);
   230     void DrawSpacer(nsPresContext* aPresContext, nsRenderingContext& aRenderingContext, bool aHorizontal, int32_t flex, nscoord x, nscoord y, nscoord size, nscoord spacerSize);
   231     void DrawLine(nsRenderingContext& aRenderingContext,  bool aHorizontal, nscoord x1, nscoord y1, nscoord x2, nscoord y2);
   232     void FillRect(nsRenderingContext& aRenderingContext,  bool aHorizontal, nscoord x, nscoord y, nscoord width, nscoord height);
   233 #endif
   234     virtual void UpdateMouseThrough();
   236     void CacheAttributes();
   238     // instance variables.
   239     Halignment mHalign;
   240     Valignment mValign;
   242 #ifdef DEBUG_LAYOUT
   243     static bool gDebug;
   244     static nsIFrame* mDebugChild;
   245 #endif
   247 }; // class nsBoxFrame
   249 #endif

mercurial