Back to index

lightning-sunbird  0.9+nobinonly
Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes
nsNativeTheme Class Reference

#include <nsNativeTheme.h>

Inheritance diagram for nsNativeTheme:
Inheritance graph
[legend]
Collaboration diagram for nsNativeTheme:
Collaboration graph
[legend]

List of all members.

Protected Types

enum  TreeSortDirection { eTreeSortDirection_Descending, eTreeSortDirection_Natural, eTreeSortDirection_Ascending }

Protected Member Functions

 nsNativeTheme ()
PRInt32 GetContentState (nsIFrame *aFrame, PRUint8 aWidgetType)
PRBool IsWidgetStyled (nsPresContext *aPresContext, nsIFrame *aFrame, PRUint8 aWidgetType)
PRBool IsDisabled (nsIFrame *aFrame)
PRBool IsDefaultButton (nsIFrame *aFrame)
PRBool IsChecked (nsIFrame *aFrame)
PRBool IsSelected (nsIFrame *aFrame)
PRBool IsFocused (nsIFrame *aFrame)
PRBool IsSelectedTab (nsIFrame *aFrame)
PRBool IsCheckedButton (nsIFrame *aFrame)
TreeSortDirection GetTreeSortDirection (nsIFrame *aFrame)
PRBool IsBottomTab (nsIFrame *aFrame)
PRBool IsIndeterminateProgress (nsIFrame *aFrame)
PRInt32 GetProgressValue (nsIFrame *aFrame)
PRBool IsReadOnly (nsIFrame *aFrame)
nsIPresShellGetPresShell (nsIFrame *aFrame)
PRInt32 CheckIntAttr (nsIFrame *aFrame, nsIAtom *aAtom)
PRBool CheckBooleanAttr (nsIFrame *aFrame, nsIAtom *aAtom)

Protected Attributes

nsCOMPtr< nsIAtommDisabledAtom
nsCOMPtr< nsIAtommCheckedAtom
nsCOMPtr< nsIAtommSelectedAtom
nsCOMPtr< nsIAtommReadOnlyAtom
nsCOMPtr< nsIAtommFirstTabAtom
nsCOMPtr< nsIAtommFocusedAtom
nsCOMPtr< nsIAtommSortDirectionAtom

Static Protected Attributes

static nsMargin sButtonBorderSize
static nsMargin sButtonDisabledBorderSize
static PRUint8 sButtonActiveBorderStyle = NS_STYLE_BORDER_STYLE_INSET
static PRUint8 sButtonInactiveBorderStyle = NS_STYLE_BORDER_STYLE_OUTSET
static nsILookAndFeel::nsColorID sButtonBorderColorID = nsILookAndFeel::eColor_threedface
static nsILookAndFeel::nsColorID sButtonDisabledBorderColorID = nsILookAndFeel::eColor_threedshadow
static nsILookAndFeel::nsColorID sButtonBGColorID = nsILookAndFeel::eColor_threedface
static nsILookAndFeel::nsColorID sButtonDisabledBGColorID = nsILookAndFeel::eColor_threedface
static nsMargin sTextfieldBorderSize
static PRUint8 sTextfieldBorderStyle = NS_STYLE_BORDER_STYLE_INSET
static nsILookAndFeel::nsColorID sTextfieldBorderColorID = nsILookAndFeel::eColor_threedface
static PRBool sTextfieldBGTransparent = PR_FALSE
static nsILookAndFeel::nsColorID sTextfieldBGColorID = nsILookAndFeel::eColor__moz_field
static nsILookAndFeel::nsColorID sTextfieldDisabledBGColorID = nsILookAndFeel::eColor_threedface
static nsMargin sListboxBorderSize
static PRUint8 sListboxBorderStyle = NS_STYLE_BORDER_STYLE_INSET
static nsILookAndFeel::nsColorID sListboxBorderColorID = nsILookAndFeel::eColor_threedface
static PRBool sListboxBGTransparent = PR_FALSE
static nsILookAndFeel::nsColorID sListboxBGColorID = nsILookAndFeel::eColor__moz_field
static nsILookAndFeel::nsColorID sListboxDisabledBGColorID = nsILookAndFeel::eColor_threedface

Private Member Functions

PRBool GetAttr (nsIFrame *aFrame, nsIAtom *aAtom, nsAString &attrValue)
PRBool GetCheckedOrSelected (nsIFrame *aFrame, PRBool aCheckSelected)

Private Attributes

nsCOMPtr< nsIAtommDefaultAtom
nsCOMPtr< nsIAtommValueAtom
nsCOMPtr< nsIAtommModeAtom
nsCOMPtr< nsIAtommClassAtom

Detailed Description

Definition at line 53 of file nsNativeTheme.h.


Member Enumeration Documentation

Enumerator:
eTreeSortDirection_Descending 
eTreeSortDirection_Natural 
eTreeSortDirection_Ascending 

Definition at line 57 of file nsNativeTheme.h.


Constructor & Destructor Documentation

Definition at line 74 of file nsNativeTheme.cpp.

{
  mDisabledAtom = do_GetAtom("disabled");
  mCheckedAtom = do_GetAtom("checked");
  mSelectedAtom = do_GetAtom("selected");
  mFocusedAtom = do_GetAtom("focused");
  mFirstTabAtom = do_GetAtom("first-tab");
  mDefaultAtom = do_GetAtom("default");
  mValueAtom = do_GetAtom("value");
  mModeAtom = do_GetAtom("mode");
  mClassAtom = do_GetAtom("class");
  mSortDirectionAtom = do_GetAtom("sortDirection");
  mReadOnlyAtom = do_GetAtom("readonly");
}

Here is the call graph for this function:


Member Function Documentation

PRBool nsNativeTheme::CheckBooleanAttr ( nsIFrame aFrame,
nsIAtom aAtom 
) [protected]

Definition at line 129 of file nsNativeTheme.cpp.

{
  if (!aFrame)
    return PR_FALSE;

  nsIContent* content = aFrame->GetContent();
  if (content->IsContentOfType(nsIContent::eHTML))
    return content->HasAttr(kNameSpaceID_None, aAtom);

  nsAutoString attr;
  content->GetAttr(kNameSpaceID_None, aAtom, attr);

  // For XML/XUL elements, an attribute must be equal to the literal
  // string "true" to be counted as true.  An empty string should _not_
  // be counted as true.

  return attr.EqualsLiteral("true");
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsNativeTheme::CheckIntAttr ( nsIFrame aFrame,
nsIAtom aAtom 
) [protected]

Definition at line 149 of file nsNativeTheme.cpp.

{
  if (!aFrame)
    return 0;

  nsAutoString attr;
  aFrame->GetContent()->GetAttr(kNameSpaceID_None, aAtom, attr);
  PRInt32 err, value = attr.ToInteger(&err);
  if (NS_FAILED(err))
    return 0;

  return value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::GetAttr ( nsIFrame aFrame,
nsIAtom aAtom,
nsAString &  attrValue 
) [private]

Definition at line 164 of file nsNativeTheme.cpp.

{
  if (!aFrame)
    return PR_FALSE;

  nsresult res = aFrame->GetContent()->GetAttr(kNameSpaceID_None, aAtom, attrValue);
  return ((res != NS_CONTENT_ATTR_NOT_THERE) &&
         !(res != NS_CONTENT_ATTR_NO_VALUE && attrValue.IsEmpty()));
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::GetCheckedOrSelected ( nsIFrame aFrame,
PRBool  aCheckSelected 
) [private]

Definition at line 175 of file nsNativeTheme.cpp.

{
  if (!aFrame)
    return PR_FALSE;

  nsIContent* content = aFrame->GetContent();

  if (content->IsContentOfType(nsIContent::eXUL)) {
    // For a XUL checkbox or radio button, the state of the parent determines
    // the checked state
    aFrame = aFrame->GetParent();
  } else {
    // Check for an HTML input element
    nsCOMPtr<nsIDOMHTMLInputElement> inputElt = do_QueryInterface(content);
    if (inputElt) {
      PRBool checked;
      inputElt->GetChecked(&checked);
      return checked;
    }
  }

  return CheckBooleanAttr(aFrame, aCheckSelected ? mSelectedAtom : mCheckedAtom);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsNativeTheme::GetContentState ( nsIFrame aFrame,
PRUint8  aWidgetType 
) [protected]

Definition at line 102 of file nsNativeTheme.cpp.

{
  if (!aFrame)
    return 0;

  PRBool isXULCheckboxRadio = 
    (aWidgetType == NS_THEME_CHECKBOX || aWidgetType == NS_THEME_RADIO) &&
    aFrame->GetContent()->IsContentOfType(nsIContent::eXUL);
  if (isXULCheckboxRadio)
    aFrame = aFrame->GetParent();

  nsIPresShell *shell = GetPresShell(aFrame);
  if (!shell)
    return 0;

  PRInt32 flags = 0;
  shell->GetPresContext()->EventStateManager()->GetContentState(aFrame->GetContent(), flags);
  
  if (isXULCheckboxRadio && aWidgetType == NS_THEME_RADIO) {
    if (IsFocused(aFrame))
      flags |= NS_EVENT_STATE_FOCUS;
  }
  
  return flags;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIPresShell * nsNativeTheme::GetPresShell ( nsIFrame aFrame) [protected]

Definition at line 90 of file nsNativeTheme.cpp.

{
  if (!aFrame)
    return nsnull;

  // this is a workaround for the egcs 1.1.2 not inliningg
  // aFrame->GetPresContext(), which causes an undefined symbol
  nsPresContext *context = aFrame->GetStyleContext()->GetRuleNode()->GetPresContext();
  return context ? context->GetPresShell() : nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsNativeTheme::GetProgressValue ( nsIFrame aFrame) [inline, protected]

Definition at line 139 of file nsNativeTheme.h.

                                             {
    return CheckIntAttr(aFrame, mValueAtom);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 111 of file nsNativeTheme.h.

                                                           {
    nsAutoString sortdir;
    if (GetAttr(aFrame, mSortDirectionAtom, sortdir)) {
      if (sortdir.EqualsLiteral("descending"))
        return eTreeSortDirection_Descending;
      else if (sortdir.EqualsLiteral("ascending"))
        return eTreeSortDirection_Ascending;
    }

    return eTreeSortDirection_Natural;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsBottomTab ( nsIFrame aFrame) [inline, protected]

Definition at line 124 of file nsNativeTheme.h.

                                       {
    nsAutoString classStr;
    if (GetAttr(aFrame, mClassAtom, classStr))
      return classStr.Find("tab-bottom") != kNotFound;
    return PR_FALSE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsChecked ( nsIFrame aFrame) [inline, protected]

Definition at line 87 of file nsNativeTheme.h.

                                     {
    return GetCheckedOrSelected(aFrame, PR_FALSE);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsCheckedButton ( nsIFrame aFrame) [inline, protected]

Definition at line 106 of file nsNativeTheme.h.

                                           {
    return CheckBooleanAttr(aFrame, mCheckedAtom);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsDefaultButton ( nsIFrame aFrame) [inline, protected]

Definition at line 82 of file nsNativeTheme.h.

                                           {
    return CheckBooleanAttr(aFrame, mDefaultAtom);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsDisabled ( nsIFrame aFrame) [inline, protected]

Definition at line 77 of file nsNativeTheme.h.

                                      {
    return CheckBooleanAttr(aFrame, mDisabledAtom);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsFocused ( nsIFrame aFrame) [inline, protected]

Definition at line 96 of file nsNativeTheme.h.

                                     {
    return CheckBooleanAttr(aFrame, mFocusedAtom);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsIndeterminateProgress ( nsIFrame aFrame) [inline, protected]

Definition at line 132 of file nsNativeTheme.h.

                                                   {
    nsAutoString mode;
    if (GetAttr(aFrame, mModeAtom, mode))
      return mode.EqualsLiteral("undetermined");
    return PR_FALSE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsReadOnly ( nsIFrame aFrame) [inline, protected]

Definition at line 144 of file nsNativeTheme.h.

                                      {
      return CheckBooleanAttr(aFrame, mReadOnlyAtom);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsSelected ( nsIFrame aFrame) [inline, protected]

Definition at line 92 of file nsNativeTheme.h.

                                      {
    return GetCheckedOrSelected(aFrame, PR_TRUE);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsSelectedTab ( nsIFrame aFrame) [inline, protected]

Definition at line 101 of file nsNativeTheme.h.

                                         {
    return CheckBooleanAttr(aFrame, mSelectedAtom);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsNativeTheme::IsWidgetStyled ( nsPresContext aPresContext,
nsIFrame aFrame,
PRUint8  aWidgetType 
) [protected]

Definition at line 209 of file nsNativeTheme.cpp.

{
  // Check for specific widgets to see if HTML has overridden the style.
  if (aFrame && (aWidgetType == NS_THEME_BUTTON ||
                 aWidgetType == NS_THEME_TEXTFIELD ||
                 aWidgetType == NS_THEME_LISTBOX ||
                 aWidgetType == NS_THEME_DROPDOWN)) {

    if (aFrame->GetContent()->IsContentOfType(nsIContent::eHTML)) {
      nscolor defaultBGColor, defaultBorderColor;
      PRUint8 defaultBorderStyle;
      nsMargin defaultBorderSize;
      PRBool defaultBGTransparent = PR_FALSE;

      float p2t;
      p2t = aPresContext->PixelsToTwips();

      nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel();

      switch (aWidgetType) {
      case NS_THEME_BUTTON:
        if (IsDisabled(aFrame)) {
          ConvertMarginToTwips(sButtonDisabledBorderSize, defaultBorderSize, p2t);
          defaultBorderStyle = sButtonInactiveBorderStyle;
          lookAndFeel->GetColor(sButtonDisabledBorderColorID,
                                defaultBorderColor);
          lookAndFeel->GetColor(sButtonDisabledBGColorID,
                                defaultBGColor);
        } else {
          PRInt32 contentState = GetContentState(aFrame, aWidgetType);
          ConvertMarginToTwips(sButtonBorderSize, defaultBorderSize, p2t);
          if (contentState & NS_EVENT_STATE_HOVER &&
              contentState & NS_EVENT_STATE_ACTIVE)
            defaultBorderStyle = sButtonActiveBorderStyle;
          else
            defaultBorderStyle = sButtonInactiveBorderStyle;
          lookAndFeel->GetColor(sButtonBorderColorID,
                                defaultBorderColor);
          lookAndFeel->GetColor(sButtonBGColorID,
                                defaultBGColor);
        }
        break;

      case NS_THEME_TEXTFIELD:
        defaultBorderStyle = sTextfieldBorderStyle;
        ConvertMarginToTwips(sTextfieldBorderSize, defaultBorderSize, p2t);
        lookAndFeel->GetColor(sTextfieldBorderColorID,
                              defaultBorderColor);
        if (!(defaultBGTransparent = sTextfieldBGTransparent)) {
          if (IsDisabled(aFrame))
            lookAndFeel->GetColor(sTextfieldDisabledBGColorID,
                                  defaultBGColor);
          else
            lookAndFeel->GetColor(sTextfieldBGColorID,
                                  defaultBGColor);
        }
        break;

      case NS_THEME_LISTBOX:
      case NS_THEME_DROPDOWN:
        defaultBorderStyle = sListboxBorderStyle;
        ConvertMarginToTwips(sListboxBorderSize, defaultBorderSize, p2t);
        lookAndFeel->GetColor(sListboxBorderColorID,
                              defaultBorderColor);
        if (!(defaultBGTransparent = sListboxBGTransparent)) {
          if (IsDisabled(aFrame))
            lookAndFeel->GetColor(sListboxDisabledBGColorID,
                                  defaultBGColor);
          else
            lookAndFeel->GetColor(sListboxBGColorID,
                                  defaultBGColor);
        }
        break;

      default:
        NS_ERROR("nsNativeTheme::IsWidgetStyled widget type not handled");
        return PR_FALSE;
      }

      // Check whether background differs from default
      const nsStyleBackground* ourBG = aFrame->GetStyleBackground();

      if (defaultBGTransparent) {
        if (!(ourBG->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT))
          return PR_TRUE;
      } else if (ourBG->mBackgroundColor != defaultBGColor ||
                 ourBG->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT)
        return PR_TRUE;

      if (!(ourBG->mBackgroundFlags & NS_STYLE_BG_IMAGE_NONE))
        return PR_TRUE;

      // Check whether border style or color differs from default
      const nsStyleBorder* ourBorder = aFrame->GetStyleBorder();

      for (PRInt32 i = 0; i < 4; ++i) {
        if (ourBorder->GetBorderStyle(i) != defaultBorderStyle)
          return PR_TRUE;

        PRBool borderFG, borderClear;
        nscolor borderColor;
        ourBorder->GetBorderColor(i, borderColor, borderFG, borderClear);
        if (borderColor != defaultBorderColor || borderClear)
          return PR_TRUE;
      }

      // Check whether border size differs from default
      if (ourBorder->GetBorder() != defaultBorderSize)
        return PR_TRUE;
    }
  }

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 161 of file nsNativeTheme.h.

Definition at line 195 of file nsNativeTheme.h.

Definition at line 192 of file nsNativeTheme.h.

Definition at line 160 of file nsNativeTheme.h.

Definition at line 164 of file nsNativeTheme.h.

Definition at line 165 of file nsNativeTheme.h.

Definition at line 194 of file nsNativeTheme.h.

Definition at line 163 of file nsNativeTheme.h.

Definition at line 162 of file nsNativeTheme.h.

Definition at line 166 of file nsNativeTheme.h.

Definition at line 193 of file nsNativeTheme.h.

Definition at line 172 of file nsNativeTheme.h.

Definition at line 176 of file nsNativeTheme.h.

Definition at line 174 of file nsNativeTheme.h.

Definition at line 170 of file nsNativeTheme.h.

Definition at line 177 of file nsNativeTheme.h.

Definition at line 175 of file nsNativeTheme.h.

Definition at line 171 of file nsNativeTheme.h.

Definition at line 173 of file nsNativeTheme.h.

Definition at line 188 of file nsNativeTheme.h.

Definition at line 187 of file nsNativeTheme.h.

Definition at line 186 of file nsNativeTheme.h.

Definition at line 184 of file nsNativeTheme.h.

Definition at line 185 of file nsNativeTheme.h.

Definition at line 189 of file nsNativeTheme.h.

Definition at line 182 of file nsNativeTheme.h.

Definition at line 181 of file nsNativeTheme.h.

Definition at line 180 of file nsNativeTheme.h.

Definition at line 178 of file nsNativeTheme.h.

Definition at line 179 of file nsNativeTheme.h.

Definition at line 183 of file nsNativeTheme.h.


The documentation for this class was generated from the following files: