extend nsITheme to support native focus drawing. b=370549 r=dbaron sr=roc

This commit is contained in:
joshmoz%gmail.com 2007-02-16 01:53:43 +00:00
Родитель ce50ea7ace
Коммит 32d7a05759
9 изменённых файлов: 57 добавлений и 18 удалений

Просмотреть файл

@ -57,9 +57,9 @@ class nsIContent;
class nsIAtom;
// IID for the nsITheme interface
// {75220e36-b77a-464c-bd82-988cf86391cc}
// {df8baf21-5ea7-49eb-a2bc-f2fd4a9fd896}
#define NS_ITHEME_IID \
{ 0x75220e36, 0xb77a, 0x464c, { 0xbd, 0x82, 0x98, 0x8c, 0xf8, 0x63, 0x91, 0xcc } }
{ 0xdf8baf21, 0x5ea7, 0x49eb, { 0xa2, 0xbc, 0xf2, 0xfd, 0x4a, 0x9f, 0xd8, 0x96 } }
// {D930E29B-6909-44e5-AB4B-AF10D6923705}
#define NS_THEMERENDERER_CID \
@ -144,6 +144,13 @@ public:
PRUint8 aWidgetType)=0;
virtual PRBool WidgetIsContainer(PRUint8 aWidgetType)=0;
/**
* Does the nsITheme implementation draw its own focus ring for this widget?
*/
virtual PRBool ThemeDrawsFocusForWidget(nsPresContext* aPresContext,
nsIFrame* aFrame,
PRUint8 aWidgetType)=0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsITheme, NS_ITHEME_IID)

Просмотреть файл

@ -43,6 +43,8 @@
#include "nsINameSpaceManager.h"
#include "nsStyleSet.h"
#include "nsDisplayList.h"
#include "nsITheme.h"
#include "nsThemeConstants.h"
#define ACTIVE "active"
#define HOVER "hover"
@ -146,12 +148,14 @@ void nsDisplayButtonForeground::Paint(nsDisplayListBuilder* aBuilder,
nsIRenderingContext* aCtx,
const nsRect& aDirtyRect)
{
NS_ASSERTION(mFrame, "No frame?");
nsPresContext* pc = mFrame->GetPresContext();
nsRect r = nsRect(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize());
// draw the focus and outline borders
mBFR->PaintOutlineAndFocusBorders(pc, *aCtx, aDirtyRect, r);
nsPresContext *presContext = mFrame->GetPresContext();
const nsStyleDisplay *disp = mFrame->GetStyleDisplay();
if (!mFrame->IsThemed(disp) ||
!presContext->GetTheme()->ThemeDrawsFocusForWidget(presContext, mFrame, disp->mAppearance)) {
// draw the focus and outline borders
nsRect r = nsRect(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize());
mBFR->PaintOutlineAndFocusBorders(presContext, *aCtx, aDirtyRect, r);
}
}
nsresult
@ -173,7 +177,7 @@ nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsPresContext* aPresContext,
const nsRect& aDirtyRect,
const nsRect& aRect)
{
// once we have all that let draw the focus if we have it. We will need to draw 2 focuses.
// once we have all that we'll draw the focus if we have it. We will need to draw 2 focuses,
// the inner and the outer. This is so we can do any kind of look and feel some buttons have
// focus on the outside like mac and motif. While others like windows have it inside (dotted line).
// Usually only one will be specifed. But I guess you could have both if you wanted to.

Просмотреть файл

@ -90,6 +90,8 @@
#include "nsLayoutUtils.h"
#include "nsDisplayList.h"
#include "nsBoxLayoutState.h"
#include "nsITheme.h"
#include "nsThemeConstants.h"
NS_IMETHODIMP
nsComboboxControlFrame::RedisplayTextEvent::Run()
@ -1334,16 +1336,13 @@ nsComboboxControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
NS_ENSURE_SUCCESS(rv, rv);
}
// nsITheme should take care of drawing the focus border, but currently does so only on Mac.
// If all of the nsITheme implementations are fixed to draw the focus border correctly,
// this #ifdef should be replaced with a -moz-appearance / ThemeSupportsWidget() check.
if (!ToolkitHasNativePopup() && mDisplayFrame &&
IsVisibleForPainting(aBuilder)) {
// REVIEW: We used to paint mDisplayFrame *again* here, with clipping,
// but that makes no sense.
nsPresContext *presContext = GetPresContext();
const nsStyleDisplay *disp = GetStyleDisplay();
if ((!IsThemed(disp) ||
!presContext->GetTheme()->ThemeDrawsFocusForWidget(presContext, this, disp->mAppearance)) &&
mDisplayFrame && IsVisibleForPainting(aBuilder)) {
nsresult rv = aLists.Content()->AppendNewToTop(new (aBuilder)
nsDisplayComboboxFocus(this));
nsDisplayComboboxFocus(this));
NS_ENSURE_SUCCESS(rv, rv);
}

Просмотреть файл

@ -80,6 +80,7 @@ public:
NS_IMETHOD ThemeChanged();
PRBool ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame, PRUint8 aWidgetType);
PRBool WidgetIsContainer(PRUint8 aWidgetType);
PRBool ThemeDrawsFocusForWidget(nsPresContext* aPresContext, nsIFrame* aFrame, PRUint8 aWidgetType);
protected:

Просмотреть файл

@ -1010,3 +1010,15 @@ nsNativeThemeCocoa::WidgetIsContainer(PRUint8 aWidgetType)
}
return PR_TRUE;
}
PRBool
nsNativeThemeCocoa::ThemeDrawsFocusForWidget(nsPresContext* aPresContext, nsIFrame* aFrame, PRUint8 aWidgetType)
{
if (aWidgetType == NS_THEME_DROPDOWN ||
aWidgetType == NS_THEME_BUTTON ||
aWidgetType == NS_THEME_BUTTON_SMALL)
return PR_TRUE;
return PR_FALSE;
}

Просмотреть файл

@ -1059,3 +1059,9 @@ nsNativeThemeGTK::WidgetIsContainer(PRUint8 aWidgetType)
return PR_FALSE;
return PR_TRUE;
}
PRBool
nsNativeThemeGTK::ThemeDrawsFocusForWidget(nsPresContext* aPresContext, nsIFrame* aFrame, PRUint8 aWidgetType)
{
return PR_FALSE;
}

Просмотреть файл

@ -86,6 +86,9 @@ public:
PRUint8 aWidgetType);
NS_IMETHOD_(PRBool) WidgetIsContainer(PRUint8 aWidgetType);
NS_IMETHOD_(PRBool) ThemeDrawsFocusForWidget(nsPresContext* aPresContext,
nsIFrame* aFrame, PRUint8 aWidgetType);
nsNativeThemeGTK();
virtual ~nsNativeThemeGTK();

Просмотреть файл

@ -1330,6 +1330,11 @@ nsNativeThemeWin::WidgetIsContainer(PRUint8 aWidgetType)
return PR_TRUE;
}
PRBool
nsNativeThemeWin::ThemeDrawsFocusForWidget(nsPresContext* aPresContext, nsIFrame* aFrame, PRUint8 aWidgetType)
{
return PR_FALSE;
}
/* Windows 9x/NT/2000/Classic XP Theme Support */

Просмотреть файл

@ -81,6 +81,8 @@ public:
PRBool WidgetIsContainer(PRUint8 aWidgetType);
PRBool ThemeDrawsFocusForWidget(nsPresContext* aPresContext, nsIFrame* aFrame, PRUint8 aWidgetType);
nsNativeThemeWin();
virtual ~nsNativeThemeWin();