widget/xpwidgets/nsNativeTheme.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial