nsNativeTheme.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // This defines a common base class for nsITheme implementations, to reduce
  6. // code duplication.
  7. #include "nsAlgorithm.h"
  8. #include "nsIAtom.h"
  9. #include "nsCOMPtr.h"
  10. #include "nsString.h"
  11. #include "nsMargin.h"
  12. #include "nsGkAtoms.h"
  13. #include "nsTArray.h"
  14. #include "nsITimer.h"
  15. #include "nsIContent.h"
  16. class nsIFrame;
  17. class nsIPresShell;
  18. class nsPresContext;
  19. namespace mozilla {
  20. class EventStates;
  21. } // namespace mozilla
  22. class nsNativeTheme : public nsITimerCallback
  23. {
  24. protected:
  25. virtual ~nsNativeTheme() {}
  26. NS_DECL_ISUPPORTS
  27. NS_DECL_NSITIMERCALLBACK
  28. enum ScrollbarButtonType {
  29. eScrollbarButton_UpTop = 0,
  30. eScrollbarButton_Down = 1 << 0,
  31. eScrollbarButton_Bottom = 1 << 1
  32. };
  33. enum TreeSortDirection {
  34. eTreeSortDirection_Descending,
  35. eTreeSortDirection_Natural,
  36. eTreeSortDirection_Ascending
  37. };
  38. nsNativeTheme();
  39. // Returns the content state (hover, focus, etc), see EventStateManager.h
  40. mozilla::EventStates GetContentState(nsIFrame* aFrame, uint8_t aWidgetType);
  41. // Returns whether the widget is already styled by content
  42. // Normally called from ThemeSupportsWidget to turn off native theming
  43. // for elements that are already styled.
  44. bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
  45. uint8_t aWidgetType);
  46. // Accessors to widget-specific state information
  47. bool IsDisabled(nsIFrame* aFrame, mozilla::EventStates aEventStates);
  48. // RTL chrome direction
  49. static bool IsFrameRTL(nsIFrame* aFrame);
  50. bool IsHTMLContent(nsIFrame *aFrame);
  51. // button:
  52. bool IsDefaultButton(nsIFrame* aFrame) {
  53. return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
  54. }
  55. bool IsButtonTypeMenu(nsIFrame* aFrame);
  56. // checkbox:
  57. bool IsChecked(nsIFrame* aFrame) {
  58. return GetCheckedOrSelected(aFrame, false);
  59. }
  60. // radiobutton:
  61. bool IsSelected(nsIFrame* aFrame) {
  62. return GetCheckedOrSelected(aFrame, true);
  63. }
  64. bool IsFocused(nsIFrame* aFrame) {
  65. return CheckBooleanAttr(aFrame, nsGkAtoms::focused);
  66. }
  67. // scrollbar button:
  68. int32_t GetScrollbarButtonType(nsIFrame* aFrame);
  69. // tab:
  70. bool IsSelectedTab(nsIFrame* aFrame) {
  71. return CheckBooleanAttr(aFrame, nsGkAtoms::visuallyselected);
  72. }
  73. bool IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset);
  74. bool IsBeforeSelectedTab(nsIFrame* aFrame) {
  75. return IsNextToSelectedTab(aFrame, -1);
  76. }
  77. bool IsAfterSelectedTab(nsIFrame* aFrame) {
  78. return IsNextToSelectedTab(aFrame, 1);
  79. }
  80. bool IsLeftToSelectedTab(nsIFrame* aFrame) {
  81. return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame) : IsBeforeSelectedTab(aFrame);
  82. }
  83. bool IsRightToSelectedTab(nsIFrame* aFrame) {
  84. return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame) : IsAfterSelectedTab(aFrame);
  85. }
  86. // button / toolbarbutton:
  87. bool IsCheckedButton(nsIFrame* aFrame) {
  88. return CheckBooleanAttr(aFrame, nsGkAtoms::checked);
  89. }
  90. bool IsSelectedButton(nsIFrame* aFrame) {
  91. return CheckBooleanAttr(aFrame, nsGkAtoms::checked) ||
  92. CheckBooleanAttr(aFrame, nsGkAtoms::selected);
  93. }
  94. bool IsOpenButton(nsIFrame* aFrame) {
  95. return CheckBooleanAttr(aFrame, nsGkAtoms::open);
  96. }
  97. bool IsPressedButton(nsIFrame* aFrame);
  98. // treeheadercell:
  99. TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
  100. bool IsLastTreeHeaderCell(nsIFrame* aFrame);
  101. // tab:
  102. bool IsBottomTab(nsIFrame* aFrame);
  103. bool IsFirstTab(nsIFrame* aFrame);
  104. bool IsHorizontal(nsIFrame* aFrame);
  105. // progressbar:
  106. bool IsIndeterminateProgress(nsIFrame* aFrame,
  107. mozilla::EventStates aEventStates);
  108. bool IsVerticalProgress(nsIFrame* aFrame);
  109. // meter:
  110. bool IsVerticalMeter(nsIFrame* aFrame);
  111. // textfield:
  112. bool IsReadOnly(nsIFrame* aFrame) {
  113. return CheckBooleanAttr(aFrame, nsGkAtoms::readonly);
  114. }
  115. // menupopup:
  116. bool IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent);
  117. // True if it's not a menubar item or menulist item
  118. bool IsRegularMenuItem(nsIFrame *aFrame);
  119. bool IsMenuListEditable(nsIFrame *aFrame);
  120. nsIPresShell *GetPresShell(nsIFrame* aFrame);
  121. static bool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom);
  122. static int32_t CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom, int32_t defaultValue);
  123. // Helpers for progressbar.
  124. static double GetProgressValue(nsIFrame* aFrame);
  125. static double GetProgressMaxValue(nsIFrame* aFrame);
  126. bool GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected);
  127. bool GetIndeterminate(nsIFrame* aFrame);
  128. bool QueueAnimatedContentForRefresh(nsIContent* aContent,
  129. uint32_t aMinimumFrameRate);
  130. nsIFrame* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame,
  131. bool aNextSibling);
  132. bool IsRangeHorizontal(nsIFrame* aFrame);
  133. // scrollbar
  134. bool IsDarkBackground(nsIFrame* aFrame);
  135. private:
  136. uint32_t mAnimatedContentTimeout;
  137. nsCOMPtr<nsITimer> mAnimatedContentTimer;
  138. AutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;
  139. };