Bug 1698786: part 2) Change some compile-time dependent `printf`s to `MOZ_LOG` in...
[gecko.git] / layout / xul / nsTextBoxFrame.h
blob31aa7d4406d3ef1e3eaeb16bae44ef5192fa9a1a
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___
9 #include "mozilla/Attributes.h"
10 #include "nsLeafBoxFrame.h"
12 class nsAccessKeyInfo;
13 class nsAsyncAccesskeyUpdate;
14 class nsFontMetrics;
16 namespace mozilla {
17 class PresShell;
18 } // namespace mozilla
20 class nsTextBoxFrame final : public nsLeafBoxFrame {
21 public:
22 NS_DECL_QUERYFRAME
23 NS_DECL_FRAMEARENA_HELPERS(nsTextBoxFrame)
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;
31 enum CroppingStyle { CropNone, CropLeft, CropRight, CropCenter, CropAuto };
33 friend nsIFrame* NS_NewTextBoxFrame(mozilla::PresShell* aPresShell,
34 ComputedStyle* aStyle);
36 virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
37 nsIFrame* asPrevInFlow) override;
39 virtual nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
40 int32_t aModType) override;
42 #ifdef DEBUG_FRAME_DUMP
43 virtual nsresult GetFrameName(nsAString& aResult) const override;
44 #endif
46 void UpdateAttributes(nsAtom* aAttribute, bool& aResize, bool& aRedraw);
48 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
49 const nsDisplayListSet& aLists) override;
51 virtual ~nsTextBoxFrame();
53 void PaintTitle(gfxContext& aRenderingContext, const nsRect& aDirtyRect,
54 nsPoint aPt, const nscolor* aOverrideColor);
56 nsRect GetComponentAlphaBounds() const;
58 virtual bool XULComputesOwnOverflowArea() override;
60 void GetCroppedTitle(nsString& aTitle) const { aTitle = mCroppedTitle; }
62 virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
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();
73 // Recompute our title, ignoring the access key but taking into
74 // account text-transform.
75 void RecomputeTitle();
77 // REVIEW: SORRY! Couldn't resist devirtualizing these
78 void LayoutTitle(nsPresContext* aPresContext, gfxContext& aRenderingContext,
79 const nsRect& aRect);
81 void CalculateUnderline(DrawTarget* aDrawTarget, nsFontMetrics& aFontMetrics);
83 void CalcTextSize(nsBoxLayoutState& aBoxLayoutState);
85 void CalcDrawRect(gfxContext& aRenderingContext);
87 explicit nsTextBoxFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);
89 nscoord CalculateTitleForWidth(gfxContext& aRenderingContext, nscoord aWidth);
91 void GetTextSize(gfxContext& aRenderingContext, const nsString& aString,
92 nsSize& aSize, nscoord& aAscent);
94 private:
95 bool AlwaysAppendAccessKey();
96 bool InsertSeparatorBeforeAccessKey();
98 void DrawText(gfxContext& aRenderingContext, const nsRect& aDirtyRect,
99 const nsRect& aTextRect, const nscolor* aOverrideColor);
101 nsString mTitle;
102 nsString mCroppedTitle;
103 nsString mAccessKey;
104 nsSize mTextSize;
105 nsRect mTextDrawRect;
106 nsAccessKeyInfo* mAccessKeyInfo;
108 CroppingStyle mCropType;
109 nscoord mAscent;
110 bool mNeedsRecalc;
111 bool mNeedsReflowCallback;
113 static bool gAlwaysAppendAccessKey;
114 static bool gAccessKeyPrefInitialized;
115 static bool gInsertSeparatorBeforeAccessKey;
116 static bool gInsertSeparatorPrefInitialized;
118 }; // class nsTextBoxFrame
120 #endif /* nsTextBoxFrame_h___ */