layout/xul/nsBoxFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/nsBoxFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,250 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/**
    1.10 +
    1.11 +  Eric D Vaughan
    1.12 +  nsBoxFrame is a frame that can lay its children out either vertically or horizontally.
    1.13 +  It lays them out according to a min max or preferred size.
    1.14 + 
    1.15 +**/
    1.16 +
    1.17 +#ifndef nsBoxFrame_h___
    1.18 +#define nsBoxFrame_h___
    1.19 +
    1.20 +#include "mozilla/Attributes.h"
    1.21 +#include "nsCOMPtr.h"
    1.22 +#include "nsContainerFrame.h"
    1.23 +#include "nsBoxLayout.h"
    1.24 +
    1.25 +class nsBoxLayoutState;
    1.26 +
    1.27 +nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
    1.28 +                         nsStyleContext* aContext,
    1.29 +                         bool aIsRoot,
    1.30 +                         nsBoxLayout* aLayoutManager);
    1.31 +nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
    1.32 +                         nsStyleContext* aContext);
    1.33 +
    1.34 +class nsBoxFrame : public nsContainerFrame
    1.35 +{
    1.36 +public:
    1.37 +  NS_DECL_FRAMEARENA_HELPERS
    1.38 +#ifdef DEBUG
    1.39 +  NS_DECL_QUERYFRAME_TARGET(nsBoxFrame)
    1.40 +  NS_DECL_QUERYFRAME
    1.41 +#endif
    1.42 +
    1.43 +  friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, 
    1.44 +                                  nsStyleContext* aContext,
    1.45 +                                  bool aIsRoot,
    1.46 +                                  nsBoxLayout* aLayoutManager);
    1.47 +  friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
    1.48 +                                  nsStyleContext* aContext);
    1.49 +
    1.50 +  // gets the rect inside our border and debug border. If you wish to paint inside a box
    1.51 +  // call this method to get the rect so you don't draw on the debug border or outer border.
    1.52 +
    1.53 +  virtual void SetLayoutManager(nsBoxLayout* aLayout) MOZ_OVERRIDE { mLayoutManager = aLayout; }
    1.54 +  virtual nsBoxLayout* GetLayoutManager() MOZ_OVERRIDE { return mLayoutManager; }
    1.55 +
    1.56 +  virtual nsresult RelayoutChildAtOrdinal(nsBoxLayoutState& aState, nsIFrame* aChild) MOZ_OVERRIDE;
    1.57 +
    1.58 +  virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.59 +  virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.60 +  virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.61 +  virtual nscoord GetFlex(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.62 +  virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.63 +#ifdef DEBUG_LAYOUT
    1.64 +  virtual nsresult SetDebug(nsBoxLayoutState& aBoxLayoutState, bool aDebug) MOZ_OVERRIDE;
    1.65 +  virtual nsresult GetDebug(bool& aDebug) MOZ_OVERRIDE;
    1.66 +#endif
    1.67 +  virtual Valignment GetVAlign() const MOZ_OVERRIDE { return mValign; }
    1.68 +  virtual Halignment GetHAlign() const MOZ_OVERRIDE { return mHalign; }
    1.69 +  NS_IMETHOD DoLayout(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.70 +
    1.71 +  virtual bool ComputesOwnOverflowArea() MOZ_OVERRIDE { return false; }
    1.72 +
    1.73 +  // ----- child and sibling operations ---
    1.74 +
    1.75 +  // ----- public methods -------
    1.76 +  
    1.77 +  virtual void Init(nsIContent*      aContent,
    1.78 +                    nsIFrame*        aParent,
    1.79 +                    nsIFrame*        asPrevInFlow) MOZ_OVERRIDE;
    1.80 +
    1.81 + 
    1.82 +  virtual nsresult AttributeChanged(int32_t         aNameSpaceID,
    1.83 +                                    nsIAtom*        aAttribute,
    1.84 +                                    int32_t         aModType) MOZ_OVERRIDE;
    1.85 +
    1.86 +  virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE;
    1.87 +  virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    1.88 +  virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    1.89 +
    1.90 +  virtual nsresult Reflow(nsPresContext*          aPresContext,
    1.91 +                          nsHTMLReflowMetrics&     aDesiredSize,
    1.92 +                          const nsHTMLReflowState& aReflowState,
    1.93 +                          nsReflowStatus&          aStatus) MOZ_OVERRIDE;
    1.94 +
    1.95 +  virtual nsresult  AppendFrames(ChildListID     aListID,
    1.96 +                                 nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.97 +
    1.98 +  virtual nsresult  InsertFrames(ChildListID     aListID,
    1.99 +                                 nsIFrame*       aPrevFrame,
   1.100 +                                 nsFrameList&    aFrameList) MOZ_OVERRIDE;
   1.101 +
   1.102 +  virtual nsresult  RemoveFrame(ChildListID     aListID,
   1.103 +                                nsIFrame*       aOldFrame) MOZ_OVERRIDE;
   1.104 +
   1.105 +  virtual nsIFrame* GetContentInsertionFrame() MOZ_OVERRIDE;
   1.106 +
   1.107 +  virtual nsresult  SetInitialChildList(ChildListID  aListID,
   1.108 +                                        nsFrameList& aChildList) MOZ_OVERRIDE;
   1.109 +
   1.110 +  virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
   1.111 +
   1.112 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   1.113 +
   1.114 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
   1.115 +  {
   1.116 +    // record that children that are ignorable whitespace should be excluded 
   1.117 +    // (When content was loaded via the XUL content sink, it's already
   1.118 +    // been excluded, but we need this for when the XUL namespace is used
   1.119 +    // in other MIME types or when the XUL CSS display types are used with
   1.120 +    // non-XUL elements.)
   1.121 +
   1.122 +    // This is bogus, but it's what we've always done.
   1.123 +    // (Given that we're replaced, we need to say we're a replaced element
   1.124 +    // that contains a block so nsHTMLReflowState doesn't tell us to be
   1.125 +    // NS_INTRINSICSIZE wide.)
   1.126 +    return nsContainerFrame::IsFrameOfType(aFlags &
   1.127 +      ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock | eXULBox |
   1.128 +        nsIFrame::eExcludesIgnorableWhitespace));
   1.129 +  }
   1.130 +
   1.131 +#ifdef DEBUG_FRAME_DUMP
   1.132 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   1.133 +#endif
   1.134 +
   1.135 +  virtual nsresult DidReflow(nsPresContext*           aPresContext,
   1.136 +                             const nsHTMLReflowState*  aReflowState,
   1.137 +                             nsDidReflowStatus         aStatus) MOZ_OVERRIDE;
   1.138 +
   1.139 +  virtual bool HonorPrintBackgroundSettings() MOZ_OVERRIDE;
   1.140 +
   1.141 +  virtual ~nsBoxFrame();
   1.142 +  
   1.143 +  nsBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, bool aIsRoot = false, nsBoxLayout* aLayoutManager = nullptr);
   1.144 +
   1.145 +  // virtual so nsStackFrame, nsButtonBoxFrame, nsSliderFrame and nsMenuFrame
   1.146 +  // can override it
   1.147 +  virtual void BuildDisplayListForChildren(nsDisplayListBuilder*   aBuilder,
   1.148 +                                           const nsRect&           aDirtyRect,
   1.149 +                                           const nsDisplayListSet& aLists);
   1.150 +
   1.151 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
   1.152 +                                const nsRect&           aDirtyRect,
   1.153 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
   1.154 +  
   1.155 +#ifdef DEBUG_LAYOUT
   1.156 +    virtual void SetDebugOnChildList(nsBoxLayoutState& aState, nsIFrame* aChild, bool aDebug);
   1.157 +    nsresult DisplayDebugInfoFor(nsIFrame*  aBox, 
   1.158 +                                 nsPoint& aPoint);
   1.159 +#endif
   1.160 +
   1.161 +  static nsresult LayoutChildAt(nsBoxLayoutState& aState, nsIFrame* aBox, const nsRect& aRect);
   1.162 +
   1.163 +  /**
   1.164 +   * Utility method to redirect events on descendants to this frame.
   1.165 +   * Supports 'allowevents' attribute on descendant elements to allow those
   1.166 +   * elements and their descendants to receive events.
   1.167 +   */
   1.168 +  void WrapListsInRedirector(nsDisplayListBuilder*   aBuilder,
   1.169 +                             const nsDisplayListSet& aIn,
   1.170 +                             const nsDisplayListSet& aOut);
   1.171 +
   1.172 +  /**
   1.173 +   * This defaults to true, but some box frames (nsListBoxBodyFrame for
   1.174 +   * example) don't support ordinals in their children.
   1.175 +   */
   1.176 +  virtual bool SupportsOrdinalsInChildren();
   1.177 +
   1.178 +protected:
   1.179 +#ifdef DEBUG_LAYOUT
   1.180 +    virtual void GetBoxName(nsAutoString& aName) MOZ_OVERRIDE;
   1.181 +    void PaintXULDebugBackground(nsRenderingContext& aRenderingContext,
   1.182 +                                 nsPoint aPt);
   1.183 +    void PaintXULDebugOverlay(nsRenderingContext& aRenderingContext,
   1.184 +                              nsPoint aPt);
   1.185 +#endif
   1.186 +
   1.187 +    virtual bool GetInitialEqualSize(bool& aEqualSize); 
   1.188 +    virtual void GetInitialOrientation(bool& aIsHorizontal);
   1.189 +    virtual void GetInitialDirection(bool& aIsNormal);
   1.190 +    virtual bool GetInitialHAlignment(Halignment& aHalign); 
   1.191 +    virtual bool GetInitialVAlignment(Valignment& aValign); 
   1.192 +    virtual bool GetInitialAutoStretch(bool& aStretch); 
   1.193 +  
   1.194 +    virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
   1.195 +
   1.196 +    nsSize mPrefSize;
   1.197 +    nsSize mMinSize;
   1.198 +    nsSize mMaxSize;
   1.199 +    nscoord mFlex;
   1.200 +    nscoord mAscent;
   1.201 +
   1.202 +    nsCOMPtr<nsBoxLayout> mLayoutManager;
   1.203 +
   1.204 +    // Get the point associated with this event. Returns true if a single valid
   1.205 +    // point was found. Otherwise false.
   1.206 +    bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsPoint& aPoint);
   1.207 +    // Gets the event coordinates relative to the widget offset associated with
   1.208 +    // this frame. Return true if a single valid point was found.
   1.209 +    bool GetEventPoint(mozilla::WidgetGUIEvent* aEvent, nsIntPoint& aPoint);
   1.210 +
   1.211 +protected:
   1.212 +    void RegUnregAccessKey(bool aDoReg);
   1.213 +
   1.214 +  NS_HIDDEN_(void) CheckBoxOrder();
   1.215 +
   1.216 +private: 
   1.217 +
   1.218 +#ifdef DEBUG_LAYOUT
   1.219 +    nsresult SetDebug(nsPresContext* aPresContext, bool aDebug);
   1.220 +    bool GetInitialDebug(bool& aDebug);
   1.221 +    void GetDebugPref(nsPresContext* aPresContext);
   1.222 +
   1.223 +    void GetDebugBorder(nsMargin& aInset);
   1.224 +    void GetDebugPadding(nsMargin& aInset);
   1.225 +    void GetDebugMargin(nsMargin& aInset);
   1.226 +
   1.227 +    nsresult GetFrameSizeWithMargin(nsIFrame* aBox, nsSize& aSize);
   1.228 +
   1.229 +    void PixelMarginToTwips(nsPresContext* aPresContext, nsMargin& aMarginPixels);
   1.230 +
   1.231 +    void GetValue(nsPresContext* aPresContext, const nsSize& a, const nsSize& b, char* value);
   1.232 +    void GetValue(nsPresContext* aPresContext, int32_t a, int32_t b, char* value);
   1.233 +    void DrawSpacer(nsPresContext* aPresContext, nsRenderingContext& aRenderingContext, bool aHorizontal, int32_t flex, nscoord x, nscoord y, nscoord size, nscoord spacerSize);
   1.234 +    void DrawLine(nsRenderingContext& aRenderingContext,  bool aHorizontal, nscoord x1, nscoord y1, nscoord x2, nscoord y2);
   1.235 +    void FillRect(nsRenderingContext& aRenderingContext,  bool aHorizontal, nscoord x, nscoord y, nscoord width, nscoord height);
   1.236 +#endif
   1.237 +    virtual void UpdateMouseThrough();
   1.238 +
   1.239 +    void CacheAttributes();
   1.240 +
   1.241 +    // instance variables.
   1.242 +    Halignment mHalign;
   1.243 +    Valignment mValign;
   1.244 +
   1.245 +#ifdef DEBUG_LAYOUT
   1.246 +    static bool gDebug;
   1.247 +    static nsIFrame* mDebugChild;
   1.248 +#endif
   1.249 +
   1.250 +}; // class nsBoxFrame
   1.251 +
   1.252 +#endif
   1.253 +

mercurial