1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsTextBoxFrame_h___
7 #define nsTextBoxFrame_h___
8 
9 #include "mozilla/Attributes.h"
10 #include "nsLeafBoxFrame.h"
11 
12 class nsAccessKeyInfo;
13 class nsAsyncAccesskeyUpdate;
14 class nsFontMetrics;
15 
16 namespace mozilla {
17 class PresShell;
18 }  // namespace mozilla
19 
20 class nsTextBoxFrame final : public nsLeafBoxFrame {
21  public:
22   NS_DECL_QUERYFRAME
23   NS_DECL_FRAMEARENA_HELPERS(nsTextBoxFrame)
24 
25   virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
26   virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
27   virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override;
28   NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override;
29   virtual void MarkIntrinsicISizesDirty() override;
30 
31   enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter, CropAuto };
32 
33   friend nsIFrame* NS_NewTextBoxFrame(mozilla::PresShell* aPresShell,
34                                       ComputedStyle* aStyle);
35 
36   virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
37                     nsIFrame* asPrevInFlow) override;
38 
39   virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
40                                     int32_t aModType) override;
41 
42 #ifdef DEBUG_FRAME_DUMP
43   virtual nsresult GetFrameName(nsAString& aResult) const override;
44 #endif
45 
46   void UpdateAttributes(nsAtom* aAttribute, bool& aResize, bool& aRedraw);
47 
48   virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
49                                 const nsDisplayListSet& aLists) override;
50 
51   virtual ~nsTextBoxFrame();
52 
53   void PaintTitle(gfxContext& aRenderingContext, const nsRect& aDirtyRect,
54                   nsPoint aPt, const nscolor* aOverrideColor);
55 
56   nsRect GetComponentAlphaBounds() const;
57 
58   virtual bool XULComputesOwnOverflowArea() override;
59 
GetCroppedTitle(nsString & aTitle)60   void GetCroppedTitle(nsString& aTitle) const { aTitle = mCroppedTitle; }
61 
62   virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
63 
64  protected:
65   friend class nsAsyncAccesskeyUpdate;
66   friend class nsDisplayXULTextBox;
67   // Should be called only by nsAsyncAccesskeyUpdate.
68   // Returns true if accesskey was updated.
69   bool UpdateAccesskey(WeakFrame& aWeakThis);
70   void UpdateAccessTitle();
71   void UpdateAccessIndex();
72 
73   // Recompute our title, ignoring the access key but taking into
74   // account text-transform.
75   void RecomputeTitle();
76 
77   // REVIEW: SORRY! Couldn't resist devirtualizing these
78   void LayoutTitle(nsPresContext* aPresContext, gfxContext& aRenderingContext,
79                    const nsRect& aRect);
80 
81   void CalculateUnderline(DrawTarget* aDrawTarget, nsFontMetrics& aFontMetrics);
82 
83   void CalcTextSize(nsBoxLayoutState& aBoxLayoutState);
84 
85   void CalcDrawRect(gfxContext& aRenderingContext);
86 
87   explicit nsTextBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
88 
89   nscoord CalculateTitleForWidth(gfxContext& aRenderingContext, nscoord aWidth);
90 
91   void GetTextSize(gfxContext& aRenderingContext, const nsString& aString,
92                    nsSize& aSize, nscoord& aAscent);
93 
94  private:
95   bool AlwaysAppendAccessKey();
96   bool InsertSeparatorBeforeAccessKey();
97 
98   void DrawText(gfxContext& aRenderingContext, const nsRect& aDirtyRect,
99                 const nsRect& aTextRect, const nscolor* aOverrideColor);
100 
101   nsString mTitle;
102   nsString mCroppedTitle;
103   nsString mAccessKey;
104   nsSize mTextSize;
105   nsRect mTextDrawRect;
106   nsAccessKeyInfo* mAccessKeyInfo;
107 
108   CroppingStyle mCropType;
109   nscoord mAscent;
110   bool mNeedsRecalc;
111   bool mNeedsReflowCallback;
112 
113   static bool gAlwaysAppendAccessKey;
114   static bool gAccessKeyPrefInitialized;
115   static bool gInsertSeparatorBeforeAccessKey;
116   static bool gInsertSeparatorPrefInitialized;
117 
118 };  // class nsTextBoxFrame
119 
120 #endif /* nsTextBoxFrame_h___ */
121