layout/generic/nsFontInflationData.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/generic/nsFontInflationData.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     1.4 +/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
     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 +/* Per-block-formatting-context manager of font size inflation for pan and zoom UI. */
    1.10 +
    1.11 +#ifndef nsFontInflationData_h_
    1.12 +#define nsFontInflationData_h_
    1.13 +
    1.14 +#include "nsIFrame.h"
    1.15 +
    1.16 +struct nsHTMLReflowState;
    1.17 +
    1.18 +class nsFontInflationData
    1.19 +{
    1.20 +public:
    1.21 +
    1.22 +  static nsFontInflationData* FindFontInflationDataFor(const nsIFrame *aFrame);
    1.23 +
    1.24 +  // Returns whether the effective width changed (which requires the
    1.25 +  // caller to mark its descendants dirty
    1.26 +  static bool
    1.27 +    UpdateFontInflationDataWidthFor(const nsHTMLReflowState& aReflowState);
    1.28 +
    1.29 +  static void MarkFontInflationDataTextDirty(nsIFrame *aFrame);
    1.30 +
    1.31 +  bool InflationEnabled() {
    1.32 +    if (mTextDirty) {
    1.33 +      ScanText();
    1.34 +    }
    1.35 +    return mInflationEnabled;
    1.36 +  }
    1.37 +
    1.38 +  nscoord EffectiveWidth() const {
    1.39 +    return mNCAWidth;
    1.40 +  }
    1.41 +
    1.42 +private:
    1.43 +
    1.44 +  nsFontInflationData(nsIFrame* aBFCFrame);
    1.45 +
    1.46 +  nsFontInflationData(const nsFontInflationData&) MOZ_DELETE;
    1.47 +  void operator=(const nsFontInflationData&) MOZ_DELETE;
    1.48 +
    1.49 +  void UpdateWidth(const nsHTMLReflowState &aReflowState);
    1.50 +  enum SearchDirection { eFromStart, eFromEnd };
    1.51 +  static nsIFrame* FindEdgeInflatableFrameIn(nsIFrame *aFrame,
    1.52 +                                             SearchDirection aDirection);
    1.53 +
    1.54 +  void MarkTextDirty() { mTextDirty = true; }
    1.55 +  void ScanText();
    1.56 +  // Scan text in the subtree rooted at aFrame.  Increment mTextAmount
    1.57 +  // by multiplying the number of characters found by the font size
    1.58 +  // (yielding the width that would be occupied by the characters if
    1.59 +  // they were all em squares).  But stop scanning if mTextAmount
    1.60 +  // crosses mTextThreshold.
    1.61 +  void ScanTextIn(nsIFrame *aFrame);
    1.62 +
    1.63 +  static const nsIFrame* FlowRootFor(const nsIFrame *aFrame)
    1.64 +  {
    1.65 +    while (!(aFrame->GetStateBits() & NS_FRAME_FONT_INFLATION_FLOW_ROOT)) {
    1.66 +      aFrame = aFrame->GetParent();
    1.67 +    }
    1.68 +    return aFrame;
    1.69 +  }
    1.70 +
    1.71 +  nsIFrame *mBFCFrame;
    1.72 +  nscoord mNCAWidth;
    1.73 +  nscoord mTextAmount, mTextThreshold;
    1.74 +  bool mInflationEnabled; // for this BFC
    1.75 +  bool mTextDirty;
    1.76 +};
    1.77 +
    1.78 +#endif /* !defined(nsFontInflationData_h_) */

mercurial