nsTextBoxFrame.h 4.4 KB

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