widget/xpwidgets/nsNativeTheme.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/xpwidgets/nsNativeTheme.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,187 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// This defines a common base class for nsITheme implementations, to reduce
    1.10 +// code duplication.
    1.11 +
    1.12 +#include "nsAlgorithm.h"
    1.13 +#include "nsIAtom.h"
    1.14 +#include "nsCOMPtr.h"
    1.15 +#include "nsString.h"
    1.16 +#include "nsMargin.h"
    1.17 +#include "nsGkAtoms.h"
    1.18 +#include "nsTArray.h"
    1.19 +#include "nsITimer.h"
    1.20 +#include "nsIContent.h"
    1.21 +
    1.22 +class nsIFrame;
    1.23 +class nsIPresShell;
    1.24 +class nsPresContext;
    1.25 +
    1.26 +namespace mozilla {
    1.27 +class EventStates;
    1.28 +} // namespace mozilla
    1.29 +
    1.30 +class nsNativeTheme : public nsITimerCallback
    1.31 +{
    1.32 + protected:
    1.33 +
    1.34 +  NS_DECL_ISUPPORTS
    1.35 +  NS_DECL_NSITIMERCALLBACK
    1.36 +
    1.37 +  enum ScrollbarButtonType {
    1.38 +    eScrollbarButton_UpTop   = 0,
    1.39 +    eScrollbarButton_Down    = 1 << 0,
    1.40 +    eScrollbarButton_Bottom  = 1 << 1
    1.41 +  };
    1.42 +
    1.43 +  enum TreeSortDirection {
    1.44 +    eTreeSortDirection_Descending,
    1.45 +    eTreeSortDirection_Natural,
    1.46 +    eTreeSortDirection_Ascending
    1.47 +  };
    1.48 +
    1.49 +  nsNativeTheme();
    1.50 +  virtual ~nsNativeTheme() {}
    1.51 +
    1.52 +  // Returns the content state (hover, focus, etc), see EventStateManager.h
    1.53 +  mozilla::EventStates GetContentState(nsIFrame* aFrame, uint8_t aWidgetType);
    1.54 +
    1.55 +  // Returns whether the widget is already styled by content
    1.56 +  // Normally called from ThemeSupportsWidget to turn off native theming
    1.57 +  // for elements that are already styled.
    1.58 +  bool IsWidgetStyled(nsPresContext* aPresContext, nsIFrame* aFrame,
    1.59 +                        uint8_t aWidgetType);                                              
    1.60 +
    1.61 +  // Accessors to widget-specific state information
    1.62 +
    1.63 +  bool IsDisabled(nsIFrame* aFrame, mozilla::EventStates aEventStates);
    1.64 +
    1.65 +  // RTL chrome direction
    1.66 +  bool IsFrameRTL(nsIFrame* aFrame);
    1.67 +
    1.68 +  bool IsHTMLContent(nsIFrame *aFrame);
    1.69 +  
    1.70 +  // button:
    1.71 +  bool IsDefaultButton(nsIFrame* aFrame) {
    1.72 +    return CheckBooleanAttr(aFrame, nsGkAtoms::_default);
    1.73 +  }
    1.74 +
    1.75 +  bool IsButtonTypeMenu(nsIFrame* aFrame);
    1.76 +
    1.77 +  // checkbox:
    1.78 +  bool IsChecked(nsIFrame* aFrame) {
    1.79 +    return GetCheckedOrSelected(aFrame, false);
    1.80 +  }
    1.81 +
    1.82 +  // radiobutton:
    1.83 +  bool IsSelected(nsIFrame* aFrame) {
    1.84 +    return GetCheckedOrSelected(aFrame, true);
    1.85 +  }
    1.86 +
    1.87 +  bool IsFocused(nsIFrame* aFrame) {
    1.88 +    return CheckBooleanAttr(aFrame, nsGkAtoms::focused);
    1.89 +  }
    1.90 +
    1.91 +  // scrollbar button:
    1.92 +  int32_t GetScrollbarButtonType(nsIFrame* aFrame);
    1.93 +
    1.94 +  // tab:
    1.95 +  bool IsSelectedTab(nsIFrame* aFrame) {
    1.96 +    return CheckBooleanAttr(aFrame, nsGkAtoms::selected);
    1.97 +  }
    1.98 +  
    1.99 +  bool IsNextToSelectedTab(nsIFrame* aFrame, int32_t aOffset);
   1.100 +  
   1.101 +  bool IsBeforeSelectedTab(nsIFrame* aFrame) {
   1.102 +    return IsNextToSelectedTab(aFrame, -1);
   1.103 +  }
   1.104 +  
   1.105 +  bool IsAfterSelectedTab(nsIFrame* aFrame) {
   1.106 +    return IsNextToSelectedTab(aFrame, 1);
   1.107 +  }
   1.108 +
   1.109 +  bool IsLeftToSelectedTab(nsIFrame* aFrame) {
   1.110 +    return IsFrameRTL(aFrame) ? IsAfterSelectedTab(aFrame) : IsBeforeSelectedTab(aFrame);
   1.111 +  }
   1.112 +
   1.113 +  bool IsRightToSelectedTab(nsIFrame* aFrame) {
   1.114 +    return IsFrameRTL(aFrame) ? IsBeforeSelectedTab(aFrame) : IsAfterSelectedTab(aFrame);
   1.115 +  }
   1.116 +
   1.117 +  // button / toolbarbutton:
   1.118 +  bool IsCheckedButton(nsIFrame* aFrame) {
   1.119 +    return CheckBooleanAttr(aFrame, nsGkAtoms::checked);
   1.120 +  }
   1.121 +
   1.122 +  bool IsSelectedButton(nsIFrame* aFrame) {
   1.123 +    return CheckBooleanAttr(aFrame, nsGkAtoms::checked) ||
   1.124 +           CheckBooleanAttr(aFrame, nsGkAtoms::selected);
   1.125 +  }
   1.126 +
   1.127 +  bool IsOpenButton(nsIFrame* aFrame) {
   1.128 +    return CheckBooleanAttr(aFrame, nsGkAtoms::open);
   1.129 +  }
   1.130 +
   1.131 +  bool IsPressedButton(nsIFrame* aFrame);
   1.132 +
   1.133 +  // treeheadercell:
   1.134 +  TreeSortDirection GetTreeSortDirection(nsIFrame* aFrame);
   1.135 +  bool IsLastTreeHeaderCell(nsIFrame* aFrame);
   1.136 +
   1.137 +  // tab:
   1.138 +  bool IsBottomTab(nsIFrame* aFrame);
   1.139 +  bool IsFirstTab(nsIFrame* aFrame);
   1.140 +  
   1.141 +  bool IsHorizontal(nsIFrame* aFrame);
   1.142 +
   1.143 +  // progressbar:
   1.144 +  bool IsIndeterminateProgress(nsIFrame* aFrame,
   1.145 +                               mozilla::EventStates aEventStates);
   1.146 +  bool IsVerticalProgress(nsIFrame* aFrame);
   1.147 +
   1.148 +  // meter:
   1.149 +  bool IsVerticalMeter(nsIFrame* aFrame);
   1.150 +
   1.151 +  // textfield:
   1.152 +  bool IsReadOnly(nsIFrame* aFrame) {
   1.153 +      return CheckBooleanAttr(aFrame, nsGkAtoms::readonly);
   1.154 +  }
   1.155 +
   1.156 +  // menupopup:
   1.157 +  bool IsSubmenu(nsIFrame* aFrame, bool* aLeftOfParent);
   1.158 +
   1.159 +  // True if it's not a menubar item or menulist item
   1.160 +  bool IsRegularMenuItem(nsIFrame *aFrame);
   1.161 +
   1.162 +  bool IsMenuListEditable(nsIFrame *aFrame);
   1.163 +
   1.164 +  nsIPresShell *GetPresShell(nsIFrame* aFrame);
   1.165 +  static bool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom);
   1.166 +  static int32_t CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom, int32_t defaultValue);
   1.167 +
   1.168 +  // Helpers for progressbar.
   1.169 +  static double GetProgressValue(nsIFrame* aFrame);
   1.170 +  static double GetProgressMaxValue(nsIFrame* aFrame);
   1.171 +
   1.172 +  bool GetCheckedOrSelected(nsIFrame* aFrame, bool aCheckSelected);
   1.173 +  bool GetIndeterminate(nsIFrame* aFrame);
   1.174 +
   1.175 +  bool QueueAnimatedContentForRefresh(nsIContent* aContent,
   1.176 +                                        uint32_t aMinimumFrameRate);
   1.177 +
   1.178 +  nsIFrame* GetAdjacentSiblingFrameWithSameAppearance(nsIFrame* aFrame,
   1.179 +                                                      bool aNextSibling);
   1.180 +
   1.181 +  bool IsRangeHorizontal(nsIFrame* aFrame);
   1.182 +
   1.183 +  // scrollbar
   1.184 +  bool IsDarkBackground(nsIFrame* aFrame);
   1.185 +
   1.186 + private:
   1.187 +  uint32_t mAnimatedContentTimeout;
   1.188 +  nsCOMPtr<nsITimer> mAnimatedContentTimer;
   1.189 +  nsAutoTArray<nsCOMPtr<nsIContent>, 20> mAnimatedContentList;
   1.190 +};

mercurial