зеркало из https://github.com/mozilla/pjs.git
bug 241070 patch by npeninguy@gmail.com (Nicolas PENINGUY), r=bryner sr=blizzard
Refactor nsNativeThemeGTK
This commit is contained in:
Родитель
ac10db12f6
Коммит
be0b470ae0
|
@ -77,13 +77,8 @@ nsNativeThemeGTK::nsNativeThemeGTK()
|
|||
do_GetService("@mozilla.org/observer-service;1");
|
||||
obsServ->AddObserver(this, "quit-application", PR_FALSE);
|
||||
|
||||
mDisabledAtom = do_GetAtom("disabled");
|
||||
mCheckedAtom = do_GetAtom("checked");
|
||||
mSelectedAtom = do_GetAtom("selected");
|
||||
mInputCheckedAtom = do_GetAtom("_moz-input-checked");
|
||||
mInputAtom = do_GetAtom("input");
|
||||
mFocusedAtom = do_GetAtom("focused");
|
||||
mFirstTabAtom = do_GetAtom("first-tab");
|
||||
mCurPosAtom = do_GetAtom("curpos");
|
||||
mMaxPosAtom = do_GetAtom("maxpos");
|
||||
mMenuActiveAtom = do_GetAtom("_moz-menuactive");
|
||||
|
@ -117,21 +112,10 @@ nsNativeThemeGTK::Observe(nsISupports *aSubject, const char *aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsIPresShell *
|
||||
GetPrimaryPresShell(nsIFrame* aFrame)
|
||||
void
|
||||
nsNativeThemeGTK::RefreshWidgetWindow(nsIFrame* aFrame)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static void RefreshWidgetWindow(nsIFrame* aFrame)
|
||||
{
|
||||
nsIPresShell *shell = GetPrimaryPresShell(aFrame);
|
||||
nsIPresShell *shell = GetPresShell(aFrame);
|
||||
if (!shell)
|
||||
return;
|
||||
|
||||
|
@ -142,57 +126,6 @@ static void RefreshWidgetWindow(nsIFrame* aFrame)
|
|||
vm->UpdateAllViews(NS_VMREFRESH_NO_SYNC);
|
||||
}
|
||||
|
||||
static PRInt32 GetContentState(nsIFrame* aFrame)
|
||||
{
|
||||
if (!aFrame)
|
||||
return 0;
|
||||
|
||||
nsIPresShell *shell = GetPrimaryPresShell(aFrame);
|
||||
if (!shell)
|
||||
return 0;
|
||||
|
||||
PRInt32 flags = 0;
|
||||
shell->GetPresContext()->EventStateManager()->GetContentState(aFrame->GetContent(), flags);
|
||||
return flags;
|
||||
}
|
||||
|
||||
static PRBool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom)
|
||||
{
|
||||
if (!aFrame)
|
||||
return PR_FALSE;
|
||||
nsAutoString attr;
|
||||
nsresult res = aFrame->GetContent()->GetAttr(kNameSpaceID_None, aAtom, attr);
|
||||
if (res == NS_CONTENT_ATTR_NO_VALUE ||
|
||||
(res != NS_CONTENT_ATTR_NOT_THERE && attr.IsEmpty()))
|
||||
return PR_TRUE; // This handles the HTML case (an attr with no value is like a true val)
|
||||
return attr.LowerCaseEqualsLiteral("true"); // This handles the XUL case.
|
||||
}
|
||||
|
||||
static PRInt32 CheckIntegerAttr(nsIFrame *aFrame, nsIAtom *aAtom)
|
||||
{
|
||||
if (!aFrame)
|
||||
return 0;
|
||||
|
||||
nsIContent* content = aFrame->GetContent();
|
||||
if (!content)
|
||||
return 0;
|
||||
|
||||
nsAutoString attr;
|
||||
content->GetAttr(kNameSpaceID_None, aAtom, attr);
|
||||
if (attr.IsEmpty())
|
||||
return 0;
|
||||
|
||||
PRInt32 error;
|
||||
PRInt32 retval = attr.ToInteger(&error);
|
||||
return retval;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsNativeThemeGTK::IsDisabled(nsIFrame* aFrame)
|
||||
{
|
||||
return CheckBooleanAttr(aFrame, mDisabledAtom);
|
||||
}
|
||||
|
||||
static PRBool IsWidgetTypeDisabled(PRUint8* aDisabledVector, PRUint8 aWidgetType) {
|
||||
return aDisabledVector[aWidgetType >> 3] & (1 << (aWidgetType & 7));
|
||||
}
|
||||
|
@ -270,7 +203,7 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
|
|||
}
|
||||
}
|
||||
|
||||
PRInt32 eventState = GetContentState(aFrame);
|
||||
PRInt32 eventState = GetContentState(aFrame, aWidgetType);
|
||||
|
||||
aState->disabled = IsDisabled(aFrame);
|
||||
aState->active = (eventState & NS_EVENT_STATE_ACTIVE) == NS_EVENT_STATE_ACTIVE;
|
||||
|
@ -287,7 +220,7 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
|
|||
aWidgetType == NS_THEME_RADIO_CONTAINER ||
|
||||
aWidgetType == NS_THEME_RADIO_LABEL ||
|
||||
aWidgetType == NS_THEME_RADIO) {
|
||||
aState->focused = CheckBooleanAttr(aFrame, mFocusedAtom);
|
||||
aState->focused = IsFocused(aFrame);
|
||||
}
|
||||
|
||||
if (aWidgetType == NS_THEME_SCROLLBAR_THUMB_VERTICAL ||
|
||||
|
@ -296,8 +229,8 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
|
|||
// the slider to the actual scrollbar object
|
||||
nsIFrame *tmpFrame = aFrame->GetParent()->GetParent();
|
||||
|
||||
aState->curpos = CheckIntegerAttr(tmpFrame, mCurPosAtom);
|
||||
aState->maxpos = CheckIntegerAttr(tmpFrame, mMaxPosAtom);
|
||||
aState->curpos = CheckIntAttr(tmpFrame, mCurPosAtom);
|
||||
aState->maxpos = CheckIntAttr(tmpFrame, mMaxPosAtom);
|
||||
}
|
||||
|
||||
// menu item state is determined by the attribute "_moz-menuactive",
|
||||
|
@ -720,7 +653,6 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext,
|
|||
nsIFrame* aFrame,
|
||||
PRUint8 aWidgetType)
|
||||
{
|
||||
// Check for specific widgets to see if HTML has overridden the style.
|
||||
if (aFrame) {
|
||||
// For now don't support HTML.
|
||||
if (aFrame->GetContent()->IsContentOfType(nsIContent::eHTML))
|
||||
|
@ -801,7 +733,7 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext,
|
|||
case NS_THEME_DROPDOWN:
|
||||
case NS_THEME_DROPDOWN_TEXT:
|
||||
#endif
|
||||
return PR_TRUE;
|
||||
return !IsWidgetStyled(aPresContext, aFrame, aWidgetType);
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
|
|
|
@ -40,11 +40,14 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsNativeTheme.h"
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include "gtkdrawing.h"
|
||||
|
||||
class nsNativeThemeGTK: public nsITheme, public nsIObserver {
|
||||
class nsNativeThemeGTK: private nsNativeTheme,
|
||||
public nsITheme,
|
||||
public nsIObserver {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -82,22 +85,16 @@ public:
|
|||
nsNativeThemeGTK();
|
||||
virtual ~nsNativeThemeGTK();
|
||||
|
||||
protected:
|
||||
private:
|
||||
PRBool GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
|
||||
GtkThemeWidgetType& aGtkWidgetType,
|
||||
GtkWidgetState* aState, gint* aWidgetFlags);
|
||||
|
||||
PRBool IsDisabled(nsIFrame* aFrame);
|
||||
void RefreshWidgetWindow(nsIFrame* aFrame);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIAtom> mCheckedAtom;
|
||||
nsCOMPtr<nsIAtom> mDisabledAtom;
|
||||
nsCOMPtr<nsIAtom> mSelectedAtom;
|
||||
nsCOMPtr<nsIAtom> mTypeAtom;
|
||||
nsCOMPtr<nsIAtom> mInputCheckedAtom;
|
||||
nsCOMPtr<nsIAtom> mInputAtom;
|
||||
nsCOMPtr<nsIAtom> mFocusedAtom;
|
||||
nsCOMPtr<nsIAtom> mFirstTabAtom;
|
||||
nsCOMPtr<nsIAtom> mCurPosAtom;
|
||||
nsCOMPtr<nsIAtom> mMaxPosAtom;
|
||||
nsCOMPtr<nsIAtom> mMenuActiveAtom;
|
||||
|
|
|
@ -77,13 +77,8 @@ nsNativeThemeGTK::nsNativeThemeGTK()
|
|||
do_GetService("@mozilla.org/observer-service;1");
|
||||
obsServ->AddObserver(this, "quit-application", PR_FALSE);
|
||||
|
||||
mDisabledAtom = do_GetAtom("disabled");
|
||||
mCheckedAtom = do_GetAtom("checked");
|
||||
mSelectedAtom = do_GetAtom("selected");
|
||||
mInputCheckedAtom = do_GetAtom("_moz-input-checked");
|
||||
mInputAtom = do_GetAtom("input");
|
||||
mFocusedAtom = do_GetAtom("focused");
|
||||
mFirstTabAtom = do_GetAtom("first-tab");
|
||||
mCurPosAtom = do_GetAtom("curpos");
|
||||
mMaxPosAtom = do_GetAtom("maxpos");
|
||||
mMenuActiveAtom = do_GetAtom("_moz-menuactive");
|
||||
|
@ -117,21 +112,10 @@ nsNativeThemeGTK::Observe(nsISupports *aSubject, const char *aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsIPresShell *
|
||||
GetPrimaryPresShell(nsIFrame* aFrame)
|
||||
void
|
||||
nsNativeThemeGTK::RefreshWidgetWindow(nsIFrame* aFrame)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static void RefreshWidgetWindow(nsIFrame* aFrame)
|
||||
{
|
||||
nsIPresShell *shell = GetPrimaryPresShell(aFrame);
|
||||
nsIPresShell *shell = GetPresShell(aFrame);
|
||||
if (!shell)
|
||||
return;
|
||||
|
||||
|
@ -142,57 +126,6 @@ static void RefreshWidgetWindow(nsIFrame* aFrame)
|
|||
vm->UpdateAllViews(NS_VMREFRESH_NO_SYNC);
|
||||
}
|
||||
|
||||
static PRInt32 GetContentState(nsIFrame* aFrame)
|
||||
{
|
||||
if (!aFrame)
|
||||
return 0;
|
||||
|
||||
nsIPresShell *shell = GetPrimaryPresShell(aFrame);
|
||||
if (!shell)
|
||||
return 0;
|
||||
|
||||
PRInt32 flags = 0;
|
||||
shell->GetPresContext()->EventStateManager()->GetContentState(aFrame->GetContent(), flags);
|
||||
return flags;
|
||||
}
|
||||
|
||||
static PRBool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom)
|
||||
{
|
||||
if (!aFrame)
|
||||
return PR_FALSE;
|
||||
nsAutoString attr;
|
||||
nsresult res = aFrame->GetContent()->GetAttr(kNameSpaceID_None, aAtom, attr);
|
||||
if (res == NS_CONTENT_ATTR_NO_VALUE ||
|
||||
(res != NS_CONTENT_ATTR_NOT_THERE && attr.IsEmpty()))
|
||||
return PR_TRUE; // This handles the HTML case (an attr with no value is like a true val)
|
||||
return attr.LowerCaseEqualsLiteral("true"); // This handles the XUL case.
|
||||
}
|
||||
|
||||
static PRInt32 CheckIntegerAttr(nsIFrame *aFrame, nsIAtom *aAtom)
|
||||
{
|
||||
if (!aFrame)
|
||||
return 0;
|
||||
|
||||
nsIContent* content = aFrame->GetContent();
|
||||
if (!content)
|
||||
return 0;
|
||||
|
||||
nsAutoString attr;
|
||||
content->GetAttr(kNameSpaceID_None, aAtom, attr);
|
||||
if (attr.IsEmpty())
|
||||
return 0;
|
||||
|
||||
PRInt32 error;
|
||||
PRInt32 retval = attr.ToInteger(&error);
|
||||
return retval;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsNativeThemeGTK::IsDisabled(nsIFrame* aFrame)
|
||||
{
|
||||
return CheckBooleanAttr(aFrame, mDisabledAtom);
|
||||
}
|
||||
|
||||
static PRBool IsWidgetTypeDisabled(PRUint8* aDisabledVector, PRUint8 aWidgetType) {
|
||||
return aDisabledVector[aWidgetType >> 3] & (1 << (aWidgetType & 7));
|
||||
}
|
||||
|
@ -270,7 +203,7 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
|
|||
}
|
||||
}
|
||||
|
||||
PRInt32 eventState = GetContentState(aFrame);
|
||||
PRInt32 eventState = GetContentState(aFrame, aWidgetType);
|
||||
|
||||
aState->disabled = IsDisabled(aFrame);
|
||||
aState->active = (eventState & NS_EVENT_STATE_ACTIVE) == NS_EVENT_STATE_ACTIVE;
|
||||
|
@ -287,7 +220,7 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
|
|||
aWidgetType == NS_THEME_RADIO_CONTAINER ||
|
||||
aWidgetType == NS_THEME_RADIO_LABEL ||
|
||||
aWidgetType == NS_THEME_RADIO) {
|
||||
aState->focused = CheckBooleanAttr(aFrame, mFocusedAtom);
|
||||
aState->focused = IsFocused(aFrame);
|
||||
}
|
||||
|
||||
if (aWidgetType == NS_THEME_SCROLLBAR_THUMB_VERTICAL ||
|
||||
|
@ -296,8 +229,8 @@ nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
|
|||
// the slider to the actual scrollbar object
|
||||
nsIFrame *tmpFrame = aFrame->GetParent()->GetParent();
|
||||
|
||||
aState->curpos = CheckIntegerAttr(tmpFrame, mCurPosAtom);
|
||||
aState->maxpos = CheckIntegerAttr(tmpFrame, mMaxPosAtom);
|
||||
aState->curpos = CheckIntAttr(tmpFrame, mCurPosAtom);
|
||||
aState->maxpos = CheckIntAttr(tmpFrame, mMaxPosAtom);
|
||||
}
|
||||
|
||||
// menu item state is determined by the attribute "_moz-menuactive",
|
||||
|
@ -720,7 +653,6 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext,
|
|||
nsIFrame* aFrame,
|
||||
PRUint8 aWidgetType)
|
||||
{
|
||||
// Check for specific widgets to see if HTML has overridden the style.
|
||||
if (aFrame) {
|
||||
// For now don't support HTML.
|
||||
if (aFrame->GetContent()->IsContentOfType(nsIContent::eHTML))
|
||||
|
@ -801,7 +733,7 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext,
|
|||
case NS_THEME_DROPDOWN:
|
||||
case NS_THEME_DROPDOWN_TEXT:
|
||||
#endif
|
||||
return PR_TRUE;
|
||||
return !IsWidgetStyled(aPresContext, aFrame, aWidgetType);
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
|
|
|
@ -40,11 +40,14 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsNativeTheme.h"
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include "gtkdrawing.h"
|
||||
|
||||
class nsNativeThemeGTK: public nsITheme, public nsIObserver {
|
||||
class nsNativeThemeGTK: private nsNativeTheme,
|
||||
public nsITheme,
|
||||
public nsIObserver {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
@ -82,22 +85,16 @@ public:
|
|||
nsNativeThemeGTK();
|
||||
virtual ~nsNativeThemeGTK();
|
||||
|
||||
protected:
|
||||
private:
|
||||
PRBool GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame,
|
||||
GtkThemeWidgetType& aGtkWidgetType,
|
||||
GtkWidgetState* aState, gint* aWidgetFlags);
|
||||
|
||||
PRBool IsDisabled(nsIFrame* aFrame);
|
||||
void RefreshWidgetWindow(nsIFrame* aFrame);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIAtom> mCheckedAtom;
|
||||
nsCOMPtr<nsIAtom> mDisabledAtom;
|
||||
nsCOMPtr<nsIAtom> mSelectedAtom;
|
||||
nsCOMPtr<nsIAtom> mTypeAtom;
|
||||
nsCOMPtr<nsIAtom> mInputCheckedAtom;
|
||||
nsCOMPtr<nsIAtom> mInputAtom;
|
||||
nsCOMPtr<nsIAtom> mFocusedAtom;
|
||||
nsCOMPtr<nsIAtom> mFirstTabAtom;
|
||||
nsCOMPtr<nsIAtom> mCurPosAtom;
|
||||
nsCOMPtr<nsIAtom> mMaxPosAtom;
|
||||
nsCOMPtr<nsIAtom> mMenuActiveAtom;
|
||||
|
|
|
@ -73,20 +73,15 @@ nsNativeTheme::nsNativeTheme()
|
|||
}
|
||||
|
||||
nsIPresShell *
|
||||
nsNativeTheme::GetPrimaryPresShell(nsIFrame* aFrame)
|
||||
nsNativeTheme::GetPresShell(nsIFrame* aFrame)
|
||||
{
|
||||
if (!aFrame)
|
||||
return nsnull;
|
||||
|
||||
nsIDocument *doc = aFrame->GetContent()->GetDocument();
|
||||
|
||||
nsIPresShell *shell = nsnull;
|
||||
|
||||
if (doc) {
|
||||
shell = doc->GetShellAt(0);
|
||||
}
|
||||
|
||||
return shell;
|
||||
// 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;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
|
@ -101,7 +96,7 @@ nsNativeTheme::GetContentState(nsIFrame* aFrame, PRUint8 aWidgetType)
|
|||
if (isXULCheckboxRadio)
|
||||
aFrame = aFrame->GetParent();
|
||||
|
||||
nsIPresShell *shell = GetPrimaryPresShell(aFrame);
|
||||
nsIPresShell *shell = GetPresShell(aFrame);
|
||||
if (!shell)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -133,11 +133,13 @@ class nsNativeTheme
|
|||
PRBool IsReadOnly(nsIFrame* aFrame) {
|
||||
return CheckBooleanAttr(aFrame, mReadOnlyAtom);
|
||||
}
|
||||
|
||||
private:
|
||||
nsIPresShell *GetPrimaryPresShell(nsIFrame* aFrame);
|
||||
PRBool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom);
|
||||
|
||||
// These are used by nsNativeThemeGtk
|
||||
nsIPresShell *GetPresShell(nsIFrame* aFrame);
|
||||
PRInt32 CheckIntAttr(nsIFrame* aFrame, nsIAtom* aAtom);
|
||||
PRBool CheckBooleanAttr(nsIFrame* aFrame, nsIAtom* aAtom);
|
||||
|
||||
private:
|
||||
PRBool GetAttr(nsIFrame* aFrame, nsIAtom* aAtom, nsAString& attrValue);
|
||||
PRBool GetCheckedOrSelected(nsIFrame* aFrame, PRBool aCheckSelected);
|
||||
|
||||
|
@ -148,6 +150,8 @@ protected:
|
|||
nsCOMPtr<nsIAtom> mCheckedAtom;
|
||||
nsCOMPtr<nsIAtom> mSelectedAtom;
|
||||
nsCOMPtr<nsIAtom> mReadOnlyAtom;
|
||||
nsCOMPtr<nsIAtom> mFirstTabAtom;
|
||||
nsCOMPtr<nsIAtom> mFocusedAtom;
|
||||
|
||||
// these should be set to appropriate platform values by the subclass, to
|
||||
// match the values in platform-forms.css. These defaults match forms.css
|
||||
|
@ -159,8 +163,6 @@ protected:
|
|||
static PRBool sListboxBGTransparent;
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIAtom> mFocusedAtom;
|
||||
nsCOMPtr<nsIAtom> mFirstTabAtom;
|
||||
nsCOMPtr<nsIAtom> mDefaultAtom;
|
||||
nsCOMPtr<nsIAtom> mValueAtom;
|
||||
nsCOMPtr<nsIAtom> mModeAtom;
|
||||
|
|
Загрузка…
Ссылка в новой задаче