nsComputedDOMStyle.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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. /* DOM object returned from element.getComputedStyle() */
  6. #ifndef nsComputedDOMStyle_h__
  7. #define nsComputedDOMStyle_h__
  8. #include "mozilla/ArenaRefPtr.h"
  9. #include "mozilla/ArenaRefPtrInlines.h"
  10. #include "mozilla/Attributes.h"
  11. #include "mozilla/StyleComplexColor.h"
  12. #include "nsCOMPtr.h"
  13. #include "nscore.h"
  14. #include "nsCSSProps.h"
  15. #include "nsDOMCSSDeclaration.h"
  16. #include "nsStyleContext.h"
  17. #include "nsIWeakReferenceUtils.h"
  18. #include "mozilla/gfx/Types.h"
  19. #include "nsCoord.h"
  20. #include "nsColor.h"
  21. #include "nsIContent.h"
  22. #include "nsStyleStruct.h"
  23. #include "mozilla/WritingModes.h"
  24. namespace mozilla {
  25. namespace dom {
  26. class DocGroup;
  27. class Element;
  28. } // namespace dom
  29. struct ComputedGridTrackInfo;
  30. } // namespace mozilla
  31. struct nsComputedStyleMap;
  32. class nsIFrame;
  33. class nsIPresShell;
  34. class nsDOMCSSValueList;
  35. struct nsMargin;
  36. class nsROCSSPrimitiveValue;
  37. class nsStyleCoord;
  38. class nsStyleCorners;
  39. struct nsStyleFilter;
  40. class nsStyleGradient;
  41. struct nsStyleImage;
  42. class nsStyleSides;
  43. struct nsTimingFunction;
  44. class nsComputedDOMStyle final : public nsDOMCSSDeclaration
  45. , public nsStubMutationObserver
  46. {
  47. private:
  48. // Convenience typedefs:
  49. typedef nsCSSProps::KTableEntry KTableEntry;
  50. typedef mozilla::dom::CSSValue CSSValue;
  51. typedef mozilla::StyleGeometryBox StyleGeometryBox;
  52. public:
  53. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  54. NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsComputedDOMStyle,
  55. nsICSSDeclaration)
  56. NS_DECL_NSICSSDECLARATION
  57. NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER
  58. virtual already_AddRefed<CSSValue>
  59. GetPropertyCSSValue(const nsAString& aProp, mozilla::ErrorResult& aRv)
  60. override;
  61. using nsICSSDeclaration::GetPropertyCSSValue;
  62. virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override;
  63. enum StyleType {
  64. eDefaultOnly, // Only includes UA and user sheets
  65. eAll // Includes all stylesheets
  66. };
  67. nsComputedDOMStyle(mozilla::dom::Element* aElement,
  68. const nsAString& aPseudoElt,
  69. nsIDocument* aDocument,
  70. StyleType aStyleType);
  71. nsINode *GetParentObject() override
  72. {
  73. return mElement;
  74. }
  75. virtual mozilla::dom::DocGroup* GetDocGroup() const override
  76. {
  77. return mElement ? mElement->GetDocGroup() : nullptr;
  78. }
  79. static already_AddRefed<nsStyleContext>
  80. GetStyleContextForElement(mozilla::dom::Element* aElement, nsIAtom* aPseudo,
  81. nsIPresShell* aPresShell,
  82. StyleType aStyleType = eAll);
  83. static already_AddRefed<nsStyleContext>
  84. GetStyleContextForElementNoFlush(mozilla::dom::Element* aElement,
  85. nsIAtom* aPseudo,
  86. nsIPresShell* aPresShell,
  87. StyleType aStyleType = eAll);
  88. static nsIPresShell*
  89. GetPresShellForContent(nsIContent* aContent);
  90. // Helper for nsDOMWindowUtils::GetVisitedDependentComputedStyle
  91. void SetExposeVisitedStyle(bool aExpose) {
  92. NS_ASSERTION(aExpose != mExposeVisitedStyle, "should always be changing");
  93. mExposeVisitedStyle = aExpose;
  94. }
  95. // nsDOMCSSDeclaration abstract methods which should never be called
  96. // on a nsComputedDOMStyle object, but must be defined to avoid
  97. // compile errors.
  98. virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation) override;
  99. virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock*) override;
  100. virtual nsIDocument* DocToUpdate() override;
  101. virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override;
  102. static already_AddRefed<nsROCSSPrimitiveValue>
  103. MatrixToCSSValue(const mozilla::gfx::Matrix4x4& aMatrix);
  104. static void RegisterPrefChangeCallbacks();
  105. static void UnregisterPrefChangeCallbacks();
  106. // nsIMutationObserver
  107. NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
  108. private:
  109. virtual ~nsComputedDOMStyle();
  110. void AssertFlushedPendingReflows() {
  111. NS_ASSERTION(mFlushedPendingReflows,
  112. "property getter should have been marked layout-dependent");
  113. }
  114. nsMargin GetAdjustedValuesForBoxSizing();
  115. // Helper method for DoGetTextAlign[Last].
  116. already_AddRefed<CSSValue> CreateTextAlignValue(uint8_t aAlign,
  117. bool aAlignTrue,
  118. const KTableEntry aTable[]);
  119. // This indicates error by leaving mStyleContext null.
  120. void UpdateCurrentStyleSources(bool aNeedsLayoutFlush);
  121. void ClearCurrentStyleSources();
  122. // Helper functions called by UpdateCurrentStyleSources.
  123. void ClearStyleContext();
  124. void SetResolvedStyleContext(RefPtr<nsStyleContext>&& aContext);
  125. void SetFrameStyleContext(nsStyleContext* aContext);
  126. #define STYLE_STRUCT(name_, checkdata_cb_) \
  127. const nsStyle##name_ * Style##name_() { \
  128. return mStyleContext->Style##name_(); \
  129. }
  130. #include "nsStyleStructList.h"
  131. #undef STYLE_STRUCT
  132. already_AddRefed<CSSValue> GetEllipseRadii(const nsStyleCorners& aRadius,
  133. uint8_t aFullCorner);
  134. already_AddRefed<CSSValue> GetOffsetWidthFor(mozilla::css::Side aSide);
  135. already_AddRefed<CSSValue> GetAbsoluteOffset(mozilla::css::Side aSide);
  136. already_AddRefed<CSSValue> GetRelativeOffset(mozilla::css::Side aSide);
  137. already_AddRefed<CSSValue> GetStickyOffset(mozilla::css::Side aSide);
  138. already_AddRefed<CSSValue> GetStaticOffset(mozilla::css::Side aSide);
  139. already_AddRefed<CSSValue> GetPaddingWidthFor(mozilla::css::Side aSide);
  140. already_AddRefed<CSSValue> GetBorderColorsFor(mozilla::css::Side aSide);
  141. already_AddRefed<CSSValue> GetBorderStyleFor(mozilla::css::Side aSide);
  142. already_AddRefed<CSSValue> GetBorderWidthFor(mozilla::css::Side aSide);
  143. already_AddRefed<CSSValue> GetBorderColorFor(mozilla::css::Side aSide);
  144. already_AddRefed<CSSValue> GetMarginWidthFor(mozilla::css::Side aSide);
  145. already_AddRefed<CSSValue> GetSVGPaintFor(bool aFill);
  146. // Appends all aLineNames (may be empty) space-separated to aResult.
  147. void AppendGridLineNames(nsString& aResult,
  148. const nsTArray<nsString>& aLineNames);
  149. // Appends aLineNames as a CSSValue* to aValueList. If aLineNames is empty
  150. // a value ("[]") is only appended if aSuppressEmptyList is false.
  151. void AppendGridLineNames(nsDOMCSSValueList* aValueList,
  152. const nsTArray<nsString>& aLineNames,
  153. bool aSuppressEmptyList = true);
  154. // Appends aLineNames1/2 (if non-empty) as a CSSValue* to aValueList.
  155. void AppendGridLineNames(nsDOMCSSValueList* aValueList,
  156. const nsTArray<nsString>& aLineNames1,
  157. const nsTArray<nsString>& aLineNames2);
  158. already_AddRefed<CSSValue> GetGridTrackSize(const nsStyleCoord& aMinSize,
  159. const nsStyleCoord& aMaxSize);
  160. already_AddRefed<CSSValue> GetGridTemplateColumnsRows(
  161. const nsStyleGridTemplate& aTrackList,
  162. const mozilla::ComputedGridTrackInfo* aTrackInfo);
  163. already_AddRefed<CSSValue> GetGridLine(const nsStyleGridLine& aGridLine);
  164. bool GetLineHeightCoord(nscoord& aCoord);
  165. already_AddRefed<CSSValue> GetCSSShadowArray(nsCSSShadowArray* aArray,
  166. const nscolor& aDefaultColor,
  167. bool aIsBoxShadow);
  168. void GetCSSGradientString(const nsStyleGradient* aGradient,
  169. nsAString& aString);
  170. void GetImageRectString(nsIURI* aURI,
  171. const nsStyleSides& aCropRect,
  172. nsString& aString);
  173. already_AddRefed<CSSValue> GetScrollSnapPoints(const nsStyleCoord& aCoord);
  174. void AppendTimingFunction(nsDOMCSSValueList *aValueList,
  175. const nsTimingFunction& aTimingFunction);
  176. bool ShouldHonorMinSizeAutoInAxis(mozilla::PhysicalAxis aAxis);
  177. /* Properties queryable as CSSValues.
  178. * To avoid a name conflict with nsIDOM*CSS2Properties, these are all
  179. * DoGetXXX instead of GetXXX.
  180. */
  181. already_AddRefed<CSSValue> DoGetAppearance();
  182. /* Box properties */
  183. already_AddRefed<CSSValue> DoGetBoxAlign();
  184. already_AddRefed<CSSValue> DoGetBoxDecorationBreak();
  185. already_AddRefed<CSSValue> DoGetBoxDirection();
  186. already_AddRefed<CSSValue> DoGetBoxFlex();
  187. already_AddRefed<CSSValue> DoGetBoxOrdinalGroup();
  188. already_AddRefed<CSSValue> DoGetBoxOrient();
  189. already_AddRefed<CSSValue> DoGetBoxPack();
  190. already_AddRefed<CSSValue> DoGetBoxSizing();
  191. already_AddRefed<CSSValue> DoGetWidth();
  192. already_AddRefed<CSSValue> DoGetHeight();
  193. already_AddRefed<CSSValue> DoGetMaxHeight();
  194. already_AddRefed<CSSValue> DoGetMaxWidth();
  195. already_AddRefed<CSSValue> DoGetMinHeight();
  196. already_AddRefed<CSSValue> DoGetMinWidth();
  197. already_AddRefed<CSSValue> DoGetMixBlendMode();
  198. already_AddRefed<CSSValue> DoGetIsolation();
  199. already_AddRefed<CSSValue> DoGetObjectFit();
  200. already_AddRefed<CSSValue> DoGetObjectPosition();
  201. already_AddRefed<CSSValue> DoGetLeft();
  202. already_AddRefed<CSSValue> DoGetTop();
  203. already_AddRefed<CSSValue> DoGetRight();
  204. already_AddRefed<CSSValue> DoGetBottom();
  205. already_AddRefed<CSSValue> DoGetStackSizing();
  206. /* Font properties */
  207. already_AddRefed<CSSValue> DoGetColor();
  208. already_AddRefed<CSSValue> DoGetFontFamily();
  209. already_AddRefed<CSSValue> DoGetFontFeatureSettings();
  210. already_AddRefed<CSSValue> DoGetFontVariationSettings();
  211. already_AddRefed<CSSValue> DoGetFontKerning();
  212. already_AddRefed<CSSValue> DoGetFontLanguageOverride();
  213. already_AddRefed<CSSValue> DoGetFontSize();
  214. already_AddRefed<CSSValue> DoGetFontSizeAdjust();
  215. already_AddRefed<CSSValue> DoGetOsxFontSmoothing();
  216. already_AddRefed<CSSValue> DoGetFontStretch();
  217. already_AddRefed<CSSValue> DoGetFontStyle();
  218. already_AddRefed<CSSValue> DoGetFontSynthesis();
  219. already_AddRefed<CSSValue> DoGetFontVariant();
  220. already_AddRefed<CSSValue> DoGetFontVariantAlternates();
  221. already_AddRefed<CSSValue> DoGetFontVariantCaps();
  222. already_AddRefed<CSSValue> DoGetFontVariantEastAsian();
  223. already_AddRefed<CSSValue> DoGetFontVariantLigatures();
  224. already_AddRefed<CSSValue> DoGetFontVariantNumeric();
  225. already_AddRefed<CSSValue> DoGetFontVariantPosition();
  226. already_AddRefed<CSSValue> DoGetFontWeight();
  227. /* Grid properties */
  228. already_AddRefed<CSSValue> DoGetGridAutoFlow();
  229. already_AddRefed<CSSValue> DoGetGridAutoColumns();
  230. already_AddRefed<CSSValue> DoGetGridAutoRows();
  231. already_AddRefed<CSSValue> DoGetGridTemplateAreas();
  232. already_AddRefed<CSSValue> DoGetGridTemplateColumns();
  233. already_AddRefed<CSSValue> DoGetGridTemplateRows();
  234. already_AddRefed<CSSValue> DoGetGridColumnStart();
  235. already_AddRefed<CSSValue> DoGetGridColumnEnd();
  236. already_AddRefed<CSSValue> DoGetGridRowStart();
  237. already_AddRefed<CSSValue> DoGetGridRowEnd();
  238. already_AddRefed<CSSValue> DoGetGridColumnGap();
  239. already_AddRefed<CSSValue> DoGetGridRowGap();
  240. /* StyleImageLayer properties */
  241. already_AddRefed<CSSValue> DoGetImageLayerImage(const nsStyleImageLayers& aLayers);
  242. already_AddRefed<CSSValue> DoGetImageLayerPosition(const nsStyleImageLayers& aLayers);
  243. already_AddRefed<CSSValue> DoGetImageLayerPositionX(const nsStyleImageLayers& aLayers);
  244. already_AddRefed<CSSValue> DoGetImageLayerPositionY(const nsStyleImageLayers& aLayers);
  245. already_AddRefed<CSSValue> DoGetImageLayerRepeat(const nsStyleImageLayers& aLayers);
  246. already_AddRefed<CSSValue> DoGetImageLayerSize(const nsStyleImageLayers& aLayers);
  247. /* Background properties */
  248. already_AddRefed<CSSValue> DoGetBackgroundAttachment();
  249. already_AddRefed<CSSValue> DoGetBackgroundColor();
  250. already_AddRefed<CSSValue> DoGetBackgroundImage();
  251. already_AddRefed<CSSValue> DoGetBackgroundPosition();
  252. already_AddRefed<CSSValue> DoGetBackgroundPositionX();
  253. already_AddRefed<CSSValue> DoGetBackgroundPositionY();
  254. already_AddRefed<CSSValue> DoGetBackgroundRepeat();
  255. already_AddRefed<CSSValue> DoGetBackgroundClip();
  256. already_AddRefed<CSSValue> DoGetBackgroundBlendMode();
  257. already_AddRefed<CSSValue> DoGetBackgroundOrigin();
  258. already_AddRefed<CSSValue> DoGetBackgroundSize();
  259. /* Mask properties */
  260. already_AddRefed<CSSValue> DoGetMask();
  261. already_AddRefed<CSSValue> DoGetMaskImage();
  262. already_AddRefed<CSSValue> DoGetMaskPosition();
  263. already_AddRefed<CSSValue> DoGetMaskPositionX();
  264. already_AddRefed<CSSValue> DoGetMaskPositionY();
  265. already_AddRefed<CSSValue> DoGetMaskRepeat();
  266. already_AddRefed<CSSValue> DoGetMaskClip();
  267. already_AddRefed<CSSValue> DoGetMaskOrigin();
  268. already_AddRefed<CSSValue> DoGetMaskSize();
  269. already_AddRefed<CSSValue> DoGetMaskMode();
  270. already_AddRefed<CSSValue> DoGetMaskComposite();
  271. /* Padding properties */
  272. already_AddRefed<CSSValue> DoGetPaddingTop();
  273. already_AddRefed<CSSValue> DoGetPaddingBottom();
  274. already_AddRefed<CSSValue> DoGetPaddingLeft();
  275. already_AddRefed<CSSValue> DoGetPaddingRight();
  276. /* Table Properties */
  277. already_AddRefed<CSSValue> DoGetBorderCollapse();
  278. already_AddRefed<CSSValue> DoGetBorderSpacing();
  279. already_AddRefed<CSSValue> DoGetCaptionSide();
  280. already_AddRefed<CSSValue> DoGetEmptyCells();
  281. already_AddRefed<CSSValue> DoGetTableLayout();
  282. already_AddRefed<CSSValue> DoGetVerticalAlign();
  283. /* Border Properties */
  284. already_AddRefed<CSSValue> DoGetBorderTopStyle();
  285. already_AddRefed<CSSValue> DoGetBorderBottomStyle();
  286. already_AddRefed<CSSValue> DoGetBorderLeftStyle();
  287. already_AddRefed<CSSValue> DoGetBorderRightStyle();
  288. already_AddRefed<CSSValue> DoGetBorderTopWidth();
  289. already_AddRefed<CSSValue> DoGetBorderBottomWidth();
  290. already_AddRefed<CSSValue> DoGetBorderLeftWidth();
  291. already_AddRefed<CSSValue> DoGetBorderRightWidth();
  292. already_AddRefed<CSSValue> DoGetBorderTopColor();
  293. already_AddRefed<CSSValue> DoGetBorderBottomColor();
  294. already_AddRefed<CSSValue> DoGetBorderLeftColor();
  295. already_AddRefed<CSSValue> DoGetBorderRightColor();
  296. already_AddRefed<CSSValue> DoGetBorderBottomColors();
  297. already_AddRefed<CSSValue> DoGetBorderLeftColors();
  298. already_AddRefed<CSSValue> DoGetBorderRightColors();
  299. already_AddRefed<CSSValue> DoGetBorderTopColors();
  300. already_AddRefed<CSSValue> DoGetBorderBottomLeftRadius();
  301. already_AddRefed<CSSValue> DoGetBorderBottomRightRadius();
  302. already_AddRefed<CSSValue> DoGetBorderTopLeftRadius();
  303. already_AddRefed<CSSValue> DoGetBorderTopRightRadius();
  304. already_AddRefed<CSSValue> DoGetFloatEdge();
  305. /* Border Image */
  306. already_AddRefed<CSSValue> DoGetBorderImageSource();
  307. already_AddRefed<CSSValue> DoGetBorderImageSlice();
  308. already_AddRefed<CSSValue> DoGetBorderImageWidth();
  309. already_AddRefed<CSSValue> DoGetBorderImageOutset();
  310. already_AddRefed<CSSValue> DoGetBorderImageRepeat();
  311. /* Box Shadow */
  312. already_AddRefed<CSSValue> DoGetBoxShadow();
  313. /* Window Shadow */
  314. already_AddRefed<CSSValue> DoGetWindowShadow();
  315. /* Margin Properties */
  316. already_AddRefed<CSSValue> DoGetMarginTopWidth();
  317. already_AddRefed<CSSValue> DoGetMarginBottomWidth();
  318. already_AddRefed<CSSValue> DoGetMarginLeftWidth();
  319. already_AddRefed<CSSValue> DoGetMarginRightWidth();
  320. /* Outline Properties */
  321. already_AddRefed<CSSValue> DoGetOutlineWidth();
  322. already_AddRefed<CSSValue> DoGetOutlineStyle();
  323. already_AddRefed<CSSValue> DoGetOutlineColor();
  324. already_AddRefed<CSSValue> DoGetOutlineOffset();
  325. already_AddRefed<CSSValue> DoGetOutlineRadiusBottomLeft();
  326. already_AddRefed<CSSValue> DoGetOutlineRadiusBottomRight();
  327. already_AddRefed<CSSValue> DoGetOutlineRadiusTopLeft();
  328. already_AddRefed<CSSValue> DoGetOutlineRadiusTopRight();
  329. /* Content Properties */
  330. already_AddRefed<CSSValue> DoGetContent();
  331. already_AddRefed<CSSValue> DoGetCounterIncrement();
  332. already_AddRefed<CSSValue> DoGetCounterReset();
  333. /* Quotes Properties */
  334. already_AddRefed<CSSValue> DoGetQuotes();
  335. /* z-index */
  336. already_AddRefed<CSSValue> DoGetZIndex();
  337. /* List properties */
  338. already_AddRefed<CSSValue> DoGetListStyleImage();
  339. already_AddRefed<CSSValue> DoGetListStylePosition();
  340. already_AddRefed<CSSValue> DoGetListStyleType();
  341. already_AddRefed<CSSValue> DoGetImageRegion();
  342. /* Text Properties */
  343. already_AddRefed<CSSValue> DoGetInitialLetter();
  344. already_AddRefed<CSSValue> DoGetLineHeight();
  345. already_AddRefed<CSSValue> DoGetRubyAlign();
  346. already_AddRefed<CSSValue> DoGetRubyPosition();
  347. already_AddRefed<CSSValue> DoGetTextAlign();
  348. already_AddRefed<CSSValue> DoGetTextAlignLast();
  349. already_AddRefed<CSSValue> DoGetTextCombineUpright();
  350. already_AddRefed<CSSValue> DoGetTextDecoration();
  351. already_AddRefed<CSSValue> DoGetTextDecorationColor();
  352. already_AddRefed<CSSValue> DoGetTextDecorationLine();
  353. already_AddRefed<CSSValue> DoGetTextDecorationStyle();
  354. already_AddRefed<CSSValue> DoGetTextEmphasisColor();
  355. already_AddRefed<CSSValue> DoGetTextEmphasisPosition();
  356. already_AddRefed<CSSValue> DoGetTextEmphasisStyle();
  357. already_AddRefed<CSSValue> DoGetTextIndent();
  358. already_AddRefed<CSSValue> DoGetTextJustify();
  359. already_AddRefed<CSSValue> DoGetTextOrientation();
  360. already_AddRefed<CSSValue> DoGetTextOverflow();
  361. already_AddRefed<CSSValue> DoGetTextTransform();
  362. already_AddRefed<CSSValue> DoGetTextShadow();
  363. already_AddRefed<CSSValue> DoGetLetterSpacing();
  364. already_AddRefed<CSSValue> DoGetWordSpacing();
  365. already_AddRefed<CSSValue> DoGetWhiteSpace();
  366. already_AddRefed<CSSValue> DoGetWordBreak();
  367. already_AddRefed<CSSValue> DoGetOverflowWrap();
  368. already_AddRefed<CSSValue> DoGetHyphens();
  369. already_AddRefed<CSSValue> DoGetTabSize();
  370. already_AddRefed<CSSValue> DoGetTextSizeAdjust();
  371. already_AddRefed<CSSValue> DoGetWebkitTextFillColor();
  372. already_AddRefed<CSSValue> DoGetWebkitTextStrokeColor();
  373. already_AddRefed<CSSValue> DoGetWebkitTextStrokeWidth();
  374. /* Visibility properties */
  375. already_AddRefed<CSSValue> DoGetColorAdjust();
  376. already_AddRefed<CSSValue> DoGetOpacity();
  377. already_AddRefed<CSSValue> DoGetPointerEvents();
  378. already_AddRefed<CSSValue> DoGetVisibility();
  379. already_AddRefed<CSSValue> DoGetWritingMode();
  380. /* Direction properties */
  381. already_AddRefed<CSSValue> DoGetDirection();
  382. already_AddRefed<CSSValue> DoGetUnicodeBidi();
  383. /* Display properties */
  384. already_AddRefed<CSSValue> DoGetBinding();
  385. already_AddRefed<CSSValue> DoGetClear();
  386. already_AddRefed<CSSValue> DoGetFloat();
  387. already_AddRefed<CSSValue> DoGetDisplay();
  388. already_AddRefed<CSSValue> DoGetContain();
  389. already_AddRefed<CSSValue> DoGetPosition();
  390. already_AddRefed<CSSValue> DoGetClip();
  391. already_AddRefed<CSSValue> DoGetImageOrientation();
  392. already_AddRefed<CSSValue> DoGetWillChange();
  393. already_AddRefed<CSSValue> DoGetOverflow();
  394. already_AddRefed<CSSValue> DoGetOverflowX();
  395. already_AddRefed<CSSValue> DoGetOverflowY();
  396. already_AddRefed<CSSValue> DoGetOverflowClipBox();
  397. already_AddRefed<CSSValue> DoGetResize();
  398. already_AddRefed<CSSValue> DoGetPageBreakAfter();
  399. already_AddRefed<CSSValue> DoGetPageBreakBefore();
  400. already_AddRefed<CSSValue> DoGetPageBreakInside();
  401. already_AddRefed<CSSValue> DoGetTouchAction();
  402. already_AddRefed<CSSValue> DoGetTransform();
  403. already_AddRefed<CSSValue> DoGetTransformBox();
  404. already_AddRefed<CSSValue> DoGetTransformOrigin();
  405. already_AddRefed<CSSValue> DoGetPerspective();
  406. already_AddRefed<CSSValue> DoGetBackfaceVisibility();
  407. already_AddRefed<CSSValue> DoGetPerspectiveOrigin();
  408. already_AddRefed<CSSValue> DoGetTransformStyle();
  409. already_AddRefed<CSSValue> DoGetOrient();
  410. already_AddRefed<CSSValue> DoGetScrollBehavior();
  411. already_AddRefed<CSSValue> DoGetScrollSnapType();
  412. already_AddRefed<CSSValue> DoGetScrollSnapTypeX();
  413. already_AddRefed<CSSValue> DoGetScrollSnapTypeY();
  414. already_AddRefed<CSSValue> DoGetScrollSnapPointsX();
  415. already_AddRefed<CSSValue> DoGetScrollSnapPointsY();
  416. already_AddRefed<CSSValue> DoGetScrollSnapDestination();
  417. already_AddRefed<CSSValue> DoGetScrollSnapCoordinate();
  418. already_AddRefed<CSSValue> DoGetShapeOutside();
  419. /* User interface properties */
  420. already_AddRefed<CSSValue> DoGetCaretColor();
  421. already_AddRefed<CSSValue> DoGetCursor();
  422. already_AddRefed<CSSValue> DoGetForceBrokenImageIcon();
  423. already_AddRefed<CSSValue> DoGetIMEMode();
  424. already_AddRefed<CSSValue> DoGetScrollbarWidth();
  425. already_AddRefed<CSSValue> DoGetUserFocus();
  426. already_AddRefed<CSSValue> DoGetUserInput();
  427. already_AddRefed<CSSValue> DoGetUserModify();
  428. already_AddRefed<CSSValue> DoGetUserSelect();
  429. already_AddRefed<CSSValue> DoGetWindowDragging();
  430. /* Column properties */
  431. already_AddRefed<CSSValue> DoGetColumnCount();
  432. already_AddRefed<CSSValue> DoGetColumnFill();
  433. already_AddRefed<CSSValue> DoGetColumnWidth();
  434. already_AddRefed<CSSValue> DoGetColumnGap();
  435. already_AddRefed<CSSValue> DoGetColumnRuleWidth();
  436. already_AddRefed<CSSValue> DoGetColumnRuleStyle();
  437. already_AddRefed<CSSValue> DoGetColumnRuleColor();
  438. /* CSS Transitions */
  439. already_AddRefed<CSSValue> DoGetTransitionProperty();
  440. already_AddRefed<CSSValue> DoGetTransitionDuration();
  441. already_AddRefed<CSSValue> DoGetTransitionDelay();
  442. already_AddRefed<CSSValue> DoGetTransitionTimingFunction();
  443. /* CSS Animations */
  444. already_AddRefed<CSSValue> DoGetAnimationName();
  445. already_AddRefed<CSSValue> DoGetAnimationDuration();
  446. already_AddRefed<CSSValue> DoGetAnimationDelay();
  447. already_AddRefed<CSSValue> DoGetAnimationTimingFunction();
  448. already_AddRefed<CSSValue> DoGetAnimationDirection();
  449. already_AddRefed<CSSValue> DoGetAnimationFillMode();
  450. already_AddRefed<CSSValue> DoGetAnimationIterationCount();
  451. already_AddRefed<CSSValue> DoGetAnimationPlayState();
  452. /* CSS Flexbox properties */
  453. already_AddRefed<CSSValue> DoGetFlexBasis();
  454. already_AddRefed<CSSValue> DoGetFlexDirection();
  455. already_AddRefed<CSSValue> DoGetFlexGrow();
  456. already_AddRefed<CSSValue> DoGetFlexShrink();
  457. already_AddRefed<CSSValue> DoGetFlexWrap();
  458. /* CSS Flexbox/Grid properties */
  459. already_AddRefed<CSSValue> DoGetOrder();
  460. /* CSS Box Alignment properties */
  461. already_AddRefed<CSSValue> DoGetAlignContent();
  462. already_AddRefed<CSSValue> DoGetAlignItems();
  463. already_AddRefed<CSSValue> DoGetAlignSelf();
  464. already_AddRefed<CSSValue> DoGetJustifyContent();
  465. already_AddRefed<CSSValue> DoGetJustifyItems();
  466. already_AddRefed<CSSValue> DoGetJustifySelf();
  467. /* SVG properties */
  468. already_AddRefed<CSSValue> DoGetFill();
  469. already_AddRefed<CSSValue> DoGetStroke();
  470. already_AddRefed<CSSValue> DoGetMarkerEnd();
  471. already_AddRefed<CSSValue> DoGetMarkerMid();
  472. already_AddRefed<CSSValue> DoGetMarkerStart();
  473. already_AddRefed<CSSValue> DoGetStrokeDasharray();
  474. already_AddRefed<CSSValue> DoGetStrokeDashoffset();
  475. already_AddRefed<CSSValue> DoGetStrokeWidth();
  476. already_AddRefed<CSSValue> DoGetVectorEffect();
  477. already_AddRefed<CSSValue> DoGetFillOpacity();
  478. already_AddRefed<CSSValue> DoGetFloodOpacity();
  479. already_AddRefed<CSSValue> DoGetStopOpacity();
  480. already_AddRefed<CSSValue> DoGetStrokeMiterlimit();
  481. already_AddRefed<CSSValue> DoGetStrokeOpacity();
  482. already_AddRefed<CSSValue> DoGetClipRule();
  483. already_AddRefed<CSSValue> DoGetFillRule();
  484. already_AddRefed<CSSValue> DoGetStrokeLinecap();
  485. already_AddRefed<CSSValue> DoGetStrokeLinejoin();
  486. already_AddRefed<CSSValue> DoGetTextAnchor();
  487. already_AddRefed<CSSValue> DoGetColorInterpolation();
  488. already_AddRefed<CSSValue> DoGetColorInterpolationFilters();
  489. already_AddRefed<CSSValue> DoGetDominantBaseline();
  490. already_AddRefed<CSSValue> DoGetImageRendering();
  491. already_AddRefed<CSSValue> DoGetShapeRendering();
  492. already_AddRefed<CSSValue> DoGetTextRendering();
  493. already_AddRefed<CSSValue> DoGetFloodColor();
  494. already_AddRefed<CSSValue> DoGetLightingColor();
  495. already_AddRefed<CSSValue> DoGetStopColor();
  496. already_AddRefed<CSSValue> DoGetClipPath();
  497. already_AddRefed<CSSValue> DoGetFilter();
  498. already_AddRefed<CSSValue> DoGetMaskType();
  499. already_AddRefed<CSSValue> DoGetPaintOrder();
  500. /* Custom properties */
  501. already_AddRefed<CSSValue> DoGetCustomProperty(const nsAString& aPropertyName);
  502. /* Helper functions */
  503. void SetToRGBAColor(nsROCSSPrimitiveValue* aValue, nscolor aColor);
  504. void SetValueFromComplexColor(nsROCSSPrimitiveValue* aValue,
  505. const mozilla::StyleComplexColor& aColor);
  506. void SetValueToStyleImage(const nsStyleImage& aStyleImage,
  507. nsROCSSPrimitiveValue* aValue);
  508. void SetValueToPositionCoord(const mozilla::Position::Coord& aCoord,
  509. nsROCSSPrimitiveValue* aValue);
  510. void SetValueToPosition(const mozilla::Position& aPosition,
  511. nsDOMCSSValueList* aValueList);
  512. void SetValueToURLValue(const mozilla::css::URLValueData* aURL,
  513. nsROCSSPrimitiveValue* aValue);
  514. /**
  515. * A method to get a percentage base for a percentage value. Returns true
  516. * if a percentage base value was determined, false otherwise.
  517. */
  518. typedef bool (nsComputedDOMStyle::*PercentageBaseGetter)(nscoord&);
  519. /**
  520. * Method to set aValue to aCoord. If aCoord is a percentage value and
  521. * aPercentageBaseGetter is not null, aPercentageBaseGetter is called. If it
  522. * returns true, the percentage base it outputs in its out param is used
  523. * to compute an nscoord value. If the getter is null or returns false,
  524. * the percent value of aCoord is set as a percent value on aValue. aTable,
  525. * if not null, is the keyword table to handle eStyleUnit_Enumerated. When
  526. * calling SetAppUnits on aValue (for coord or percent values), the value
  527. * passed in will be clamped to be no less than aMinAppUnits and no more than
  528. * aMaxAppUnits.
  529. *
  530. * XXXbz should caller pass in some sort of bitfield indicating which units
  531. * can be expected or something?
  532. */
  533. void SetValueToCoord(nsROCSSPrimitiveValue* aValue,
  534. const nsStyleCoord& aCoord,
  535. bool aClampNegativeCalc,
  536. PercentageBaseGetter aPercentageBaseGetter = nullptr,
  537. const KTableEntry aTable[] = nullptr,
  538. nscoord aMinAppUnits = nscoord_MIN,
  539. nscoord aMaxAppUnits = nscoord_MAX);
  540. /**
  541. * If aCoord is a eStyleUnit_Coord returns the nscoord. If it's
  542. * eStyleUnit_Percent, attempts to resolve the percentage base and returns
  543. * the resulting nscoord. If it's some other unit or a percentge base can't
  544. * be determined, returns aDefaultValue.
  545. */
  546. nscoord StyleCoordToNSCoord(const nsStyleCoord& aCoord,
  547. PercentageBaseGetter aPercentageBaseGetter,
  548. nscoord aDefaultValue,
  549. bool aClampNegativeCalc);
  550. bool GetCBContentWidth(nscoord& aWidth);
  551. bool GetCBContentHeight(nscoord& aWidth);
  552. bool GetScrollFrameContentWidth(nscoord& aWidth);
  553. bool GetScrollFrameContentHeight(nscoord& aHeight);
  554. bool GetFrameBoundsWidthForTransform(nscoord &aWidth);
  555. bool GetFrameBoundsHeightForTransform(nscoord &aHeight);
  556. bool GetFrameBorderRectWidth(nscoord& aWidth);
  557. bool GetFrameBorderRectHeight(nscoord& aHeight);
  558. /* Helper functions for computing the filter property style. */
  559. void SetCssTextToCoord(nsAString& aCssText, const nsStyleCoord& aCoord);
  560. already_AddRefed<CSSValue> CreatePrimitiveValueForStyleFilter(
  561. const nsStyleFilter& aStyleFilter);
  562. template<typename ReferenceBox>
  563. already_AddRefed<CSSValue>
  564. GetShapeSource(const mozilla::StyleShapeSource<ReferenceBox>& aShapeSource,
  565. const KTableEntry aBoxKeywordTable[]);
  566. template<typename ReferenceBox>
  567. already_AddRefed<CSSValue>
  568. CreatePrimitiveValueForShapeSource(
  569. const mozilla::StyleBasicShape* aStyleBasicShape,
  570. ReferenceBox aReferenceBox,
  571. const KTableEntry aBoxKeywordTable[]);
  572. // Helper function for computing basic shape styles.
  573. already_AddRefed<CSSValue> CreatePrimitiveValueForBasicShape(
  574. const mozilla::StyleBasicShape* aStyleBasicShape);
  575. void BoxValuesToString(nsAString& aString,
  576. const nsTArray<nsStyleCoord>& aBoxValues);
  577. void BasicShapeRadiiToString(nsAString& aCssText,
  578. const nsStyleCorners& aCorners);
  579. static nsComputedStyleMap* GetComputedStyleMap();
  580. // We don't really have a good immutable representation of "presentation".
  581. // Given the way GetComputedStyle is currently used, we should just grab the
  582. // presshell, if any, from the document.
  583. nsWeakPtr mDocumentWeak;
  584. RefPtr<mozilla::dom::Element> mElement;
  585. /**
  586. * Strong reference to the style context we access data from. This can be
  587. * either a style context we resolved ourselves or a style context we got
  588. * from our frame.
  589. *
  590. * If we got the style context from the frame, we clear out mStyleContext
  591. * in ClearCurrentStyleSources. If we resolved one ourselves, then
  592. * ClearCurrentStyleSources leaves it in mStyleContext for use the next
  593. * time this nsComputedDOMStyle object is queried. UpdateCurrentStyleSources
  594. * in this case will check that the style context is still valid to be used,
  595. * by checking whether flush styles results in any restyles having been
  596. * processed.
  597. *
  598. * Since an ArenaRefPtr is used to hold the style context, it will be cleared
  599. * if the pres arena from which it was allocated goes away.
  600. */
  601. mozilla::ArenaRefPtr<nsStyleContext> mStyleContext;
  602. nsCOMPtr<nsIAtom> mPseudo;
  603. /*
  604. * While computing style data, the primary frame for mContent --- named "outer"
  605. * because we should use it to compute positioning data. Null
  606. * otherwise.
  607. */
  608. nsIFrame* mOuterFrame;
  609. /*
  610. * While computing style data, the "inner frame" for mContent --- the frame
  611. * which we should use to compute margin, border, padding and content data. Null
  612. * otherwise.
  613. */
  614. nsIFrame* mInnerFrame;
  615. /*
  616. * While computing style data, the presshell we're working with. Null
  617. * otherwise.
  618. */
  619. nsIPresShell* mPresShell;
  620. /*
  621. * The kind of styles we should be returning.
  622. */
  623. StyleType mStyleType;
  624. /**
  625. * The nsComputedDOMStyle generation at the time we last resolved a style
  626. * context and stored it in mStyleContext.
  627. */
  628. uint64_t mStyleContextGeneration;
  629. bool mExposeVisitedStyle;
  630. /**
  631. * Whether we resolved a style context last time we called
  632. * UpdateCurrentStyleSources. Initially false.
  633. */
  634. bool mResolvedStyleContext;
  635. #ifdef DEBUG
  636. bool mFlushedPendingReflows;
  637. #endif
  638. };
  639. already_AddRefed<nsComputedDOMStyle>
  640. NS_NewComputedDOMStyle(mozilla::dom::Element* aElement,
  641. const nsAString& aPseudoElt,
  642. nsIDocument* aDocument,
  643. nsComputedDOMStyle::StyleType aStyleType =
  644. nsComputedDOMStyle::eAll);
  645. #endif /* nsComputedDOMStyle_h__ */