Line data Source code
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/. */
5 : #ifndef nsTextBoxFrame_h___
6 : #define nsTextBoxFrame_h___
7 :
8 : #include "mozilla/Attributes.h"
9 : #include "nsLeafBoxFrame.h"
10 :
11 : class nsAccessKeyInfo;
12 : class nsAsyncAccesskeyUpdate;
13 : class nsFontMetrics;
14 :
15 : class nsTextBoxFrame final : public nsLeafBoxFrame
16 : {
17 : public:
18 : NS_DECL_QUERYFRAME
19 49 : NS_DECL_FRAMEARENA_HELPERS(nsTextBoxFrame)
20 :
21 : virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
22 : virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
23 : virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override;
24 : NS_IMETHOD DoXULLayout(nsBoxLayoutState& aBoxLayoutState) override;
25 : virtual void MarkIntrinsicISizesDirty() override;
26 :
27 : enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter, CropAuto };
28 :
29 : friend nsIFrame* NS_NewTextBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
30 :
31 : virtual void Init(nsIContent* aContent,
32 : nsContainerFrame* aParent,
33 : nsIFrame* asPrevInFlow) override;
34 :
35 : virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
36 :
37 : virtual nsresult AttributeChanged(int32_t aNameSpaceID,
38 : nsIAtom* aAttribute,
39 : int32_t aModType) override;
40 :
41 : #ifdef DEBUG_FRAME_DUMP
42 : virtual nsresult GetFrameName(nsAString& aResult) const override;
43 : #endif
44 :
45 : void UpdateAttributes(nsIAtom* aAttribute,
46 : bool& aResize,
47 : bool& aRedraw);
48 :
49 : virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
50 : const nsRect& aDirtyRect,
51 : const nsDisplayListSet& aLists) override;
52 :
53 : virtual ~nsTextBoxFrame();
54 :
55 : void PaintTitle(gfxContext& aRenderingContext,
56 : const nsRect& aDirtyRect,
57 : nsPoint aPt,
58 : const nscolor* aOverrideColor);
59 :
60 : nsRect GetComponentAlphaBounds();
61 :
62 : virtual bool ComputesOwnOverflowArea() override;
63 :
64 0 : void GetCroppedTitle(nsString& aTitle) const { aTitle = mCroppedTitle; }
65 :
66 : virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
67 :
68 : protected:
69 : friend class nsAsyncAccesskeyUpdate;
70 : friend class nsDisplayXULTextBox;
71 : // Should be called only by nsAsyncAccesskeyUpdate.
72 : // Returns true if accesskey was updated.
73 : bool UpdateAccesskey(WeakFrame& aWeakThis);
74 : void UpdateAccessTitle();
75 : void UpdateAccessIndex();
76 :
77 : // Recompute our title, ignoring the access key but taking into
78 : // account text-transform.
79 : void RecomputeTitle();
80 :
81 : // REVIEW: SORRY! Couldn't resist devirtualizing these
82 : void LayoutTitle(nsPresContext* aPresContext,
83 : gfxContext& aRenderingContext,
84 : const nsRect& aRect);
85 :
86 : void CalculateUnderline(DrawTarget* aDrawTarget, nsFontMetrics& aFontMetrics);
87 :
88 : void CalcTextSize(nsBoxLayoutState& aBoxLayoutState);
89 :
90 : void CalcDrawRect(gfxContext &aRenderingContext);
91 :
92 : explicit nsTextBoxFrame(nsStyleContext* aContext);
93 :
94 : nscoord CalculateTitleForWidth(gfxContext& aRenderingContext,
95 : nscoord aWidth);
96 :
97 : void GetTextSize(gfxContext& aRenderingContext,
98 : const nsString& aString,
99 : nsSize& aSize,
100 : nscoord& aAscent);
101 :
102 : nsresult RegUnregAccessKey(bool aDoReg);
103 :
104 : private:
105 :
106 : bool AlwaysAppendAccessKey();
107 : bool InsertSeparatorBeforeAccessKey();
108 :
109 : void DrawText(gfxContext& aRenderingContext,
110 : const nsRect& aDirtyRect,
111 : const nsRect& aTextRect,
112 : const nscolor* aOverrideColor);
113 :
114 : nsString mTitle;
115 : nsString mCroppedTitle;
116 : nsString mAccessKey;
117 : nsSize mTextSize;
118 : nsRect mTextDrawRect;
119 : nsAccessKeyInfo* mAccessKeyInfo;
120 :
121 : CroppingStyle mCropType;
122 : nscoord mAscent;
123 : bool mNeedsRecalc;
124 : bool mNeedsReflowCallback;
125 :
126 : static bool gAlwaysAppendAccessKey;
127 : static bool gAccessKeyPrefInitialized;
128 : static bool gInsertSeparatorBeforeAccessKey;
129 : static bool gInsertSeparatorPrefInitialized;
130 :
131 : }; // class nsTextBoxFrame
132 :
133 : #endif /* nsTextBoxFrame_h___ */
|