2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-10-08 20:41:19 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-10-08 20:41:19 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-10-08 20:41:19 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-20 06:05:15 +00:00
|
|
|
#include "nsButtonFrameRenderer.h"
|
1999-02-19 18:23:02 +00:00
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2002-11-17 15:37:56 +00:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2004-01-28 00:18:22 +00:00
|
|
|
#include "nsStyleSet.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
2007-02-16 01:53:43 +00:00
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsThemeConstants.h"
|
1999-02-19 18:23:02 +00:00
|
|
|
|
1999-03-06 19:43:13 +00:00
|
|
|
#define ACTIVE "active"
|
|
|
|
#define HOVER "hover"
|
|
|
|
#define FOCUS "focus"
|
1999-02-26 08:48:24 +00:00
|
|
|
|
1999-02-19 18:23:02 +00:00
|
|
|
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsButtonFrameRenderer);
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
nsButtonFrameRenderer::~nsButtonFrameRenderer()
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(nsButtonFrameRenderer);
|
1999-02-26 06:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsButtonFrameRenderer::SetFrame(nsFrame* aFrame, nsPresContext* aPresContext)
|
1999-02-19 18:23:02 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
mFrame = aFrame;
|
|
|
|
ReResolveStyles(aPresContext);
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
1999-09-14 22:17:19 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsButtonFrameRenderer::GetFrame()
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
return mFrame;
|
1999-09-14 22:17:19 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 08:48:24 +00:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::SetDisabled(PRBool aDisabled, PRBool notify)
|
|
|
|
{
|
1999-03-12 23:47:52 +00:00
|
|
|
if (aDisabled)
|
2006-12-26 17:47:52 +00:00
|
|
|
mFrame->GetContent()->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, EmptyString(),
|
2003-07-04 12:50:32 +00:00
|
|
|
notify);
|
1999-03-12 23:47:52 +00:00
|
|
|
else
|
2006-12-26 17:47:52 +00:00
|
|
|
mFrame->GetContent()->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, notify);
|
1999-02-26 08:48:24 +00:00
|
|
|
}
|
1999-02-26 06:41:10 +00:00
|
|
|
|
1999-02-26 08:48:24 +00:00
|
|
|
PRBool
|
|
|
|
nsButtonFrameRenderer::isDisabled()
|
|
|
|
{
|
1999-03-12 23:47:52 +00:00
|
|
|
// get the content
|
2005-10-28 11:25:24 +00:00
|
|
|
return mFrame->GetContent()->HasAttr(kNameSpaceID_None,
|
2006-12-26 17:47:52 +00:00
|
|
|
nsGkAtoms::disabled);
|
1999-02-26 08:48:24 +00:00
|
|
|
}
|
|
|
|
|
2009-02-10 08:45:13 +00:00
|
|
|
class nsDisplayButtonBoxShadowOuter : public nsDisplayItem {
|
|
|
|
public:
|
|
|
|
nsDisplayButtonBoxShadowOuter(nsButtonFrameRenderer* aRenderer)
|
|
|
|
: nsDisplayItem(aRenderer->GetFrame()), mBFR(aRenderer) {
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayButtonBoxShadowOuter);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayButtonBoxShadowOuter() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayButtonBoxShadowOuter);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx);
|
2009-02-10 08:45:13 +00:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder);
|
|
|
|
NS_DISPLAY_DECL_NAME("ButtonBoxShadowOuter")
|
|
|
|
private:
|
|
|
|
nsButtonFrameRenderer* mBFR;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayButtonBoxShadowOuter::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
return mFrame->GetOverflowRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayButtonBoxShadowOuter::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2009-02-10 08:45:13 +00:00
|
|
|
nsRect frameRect = nsRect(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize());
|
|
|
|
|
|
|
|
nsRect buttonRect;
|
|
|
|
mBFR->GetButtonRect(frameRect, buttonRect);
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBoxShadowOuter(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 00:35:14 +00:00
|
|
|
buttonRect, mVisibleRect);
|
2009-02-10 08:45:13 +00:00
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
class nsDisplayButtonBorderBackground : public nsDisplayItem {
|
|
|
|
public:
|
2006-01-29 18:48:58 +00:00
|
|
|
nsDisplayButtonBorderBackground(nsButtonFrameRenderer* aRenderer)
|
2006-03-14 20:43:18 +00:00
|
|
|
: nsDisplayItem(aRenderer->GetFrame()), mBFR(aRenderer) {
|
2006-01-29 18:48:58 +00:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayButtonBorderBackground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayButtonBorderBackground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayButtonBorderBackground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-04 02:08:29 +00:00
|
|
|
virtual nsIFrame* HitTest(nsDisplayListBuilder* aBuilder, nsPoint aPt,
|
|
|
|
HitTestState* aState) {
|
2006-03-14 20:43:18 +00:00
|
|
|
return mFrame;
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2009-09-07 00:35:14 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx);
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_DISPLAY_DECL_NAME("ButtonBorderBackground")
|
|
|
|
private:
|
|
|
|
nsButtonFrameRenderer* mBFR;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDisplayButtonForeground : public nsDisplayItem {
|
|
|
|
public:
|
2006-01-29 18:48:58 +00:00
|
|
|
nsDisplayButtonForeground(nsButtonFrameRenderer* aRenderer)
|
2006-03-14 20:43:18 +00:00
|
|
|
: nsDisplayItem(aRenderer->GetFrame()), mBFR(aRenderer) {
|
2006-01-29 18:48:58 +00:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayButtonForeground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayButtonForeground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayButtonForeground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx);
|
2006-01-26 02:29:17 +00:00
|
|
|
NS_DISPLAY_DECL_NAME("ButtonForeground")
|
|
|
|
private:
|
|
|
|
nsButtonFrameRenderer* mBFR;
|
|
|
|
};
|
1999-03-02 01:25:33 +00:00
|
|
|
|
2006-01-29 18:48:58 +00:00
|
|
|
void nsDisplayButtonBorderBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx)
|
2006-01-26 02:29:17 +00:00
|
|
|
{
|
2006-03-14 20:43:18 +00:00
|
|
|
NS_ASSERTION(mFrame, "No frame?");
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* pc = mFrame->PresContext();
|
2006-03-14 20:43:18 +00:00
|
|
|
nsRect r = nsRect(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize());
|
2006-01-26 02:29:17 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
// draw the border and background inside the focus and outline borders
|
2009-09-07 00:35:14 +00:00
|
|
|
mBFR->PaintBorderAndBackground(pc, *aCtx, mVisibleRect, r,
|
2009-09-12 22:44:18 +00:00
|
|
|
aBuilder->GetBackgroundPaintFlags());
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
1999-02-26 06:41:10 +00:00
|
|
|
|
2006-01-29 18:48:58 +00:00
|
|
|
void nsDisplayButtonForeground::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx)
|
2006-01-26 02:29:17 +00:00
|
|
|
{
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext *presContext = mFrame->PresContext();
|
2007-02-16 01:53:43 +00:00
|
|
|
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());
|
2009-09-07 00:35:14 +00:00
|
|
|
mBFR->PaintOutlineAndFocusBorders(presContext, *aCtx, mVisibleRect, r);
|
2007-02-16 01:53:43 +00:00
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsButtonFrameRenderer::DisplayButton(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aBackground,
|
|
|
|
nsDisplayList* aForeground)
|
|
|
|
{
|
2009-02-10 08:45:13 +00:00
|
|
|
if (mFrame->GetStyleBorder()->mBoxShadow) {
|
|
|
|
nsresult rv = aBackground->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayButtonBoxShadowOuter(this));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
nsresult rv = aBackground->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayButtonBorderBackground(this));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return aForeground->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayButtonForeground(this));
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsPresContext* aPresContext,
|
1999-10-08 20:41:19 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aRect)
|
1999-02-19 18:23:02 +00:00
|
|
|
{
|
2008-08-06 10:33:18 +00:00
|
|
|
// 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.
|
1999-02-19 18:23:02 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
nsRect rect;
|
1999-02-19 18:23:02 +00:00
|
|
|
|
2002-04-06 15:31:53 +00:00
|
|
|
if (mOuterFocusStyle) {
|
|
|
|
// ---------- paint the outer focus border -------------
|
1999-02-19 18:23:02 +00:00
|
|
|
|
2002-04-06 15:31:53 +00:00
|
|
|
GetButtonOuterFocusRect(aRect, rect);
|
1999-02-19 18:23:02 +00:00
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleBorder* border = mOuterFocusStyle->GetStyleBorder();
|
2002-04-06 15:31:53 +00:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
2008-08-06 10:33:18 +00:00
|
|
|
aDirtyRect, rect, *border, mOuterFocusStyle);
|
2002-04-06 15:31:53 +00:00
|
|
|
}
|
1999-02-19 18:23:02 +00:00
|
|
|
|
2002-04-06 15:31:53 +00:00
|
|
|
if (mInnerFocusStyle) {
|
1999-10-08 20:41:19 +00:00
|
|
|
// ---------- paint the inner focus border -------------
|
1999-02-19 18:23:02 +00:00
|
|
|
|
2002-04-06 15:31:53 +00:00
|
|
|
GetButtonInnerFocusRect(aRect, rect);
|
1999-02-19 18:23:02 +00:00
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleBorder* border = mInnerFocusStyle->GetStyleBorder();
|
2002-04-06 15:31:53 +00:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
2008-08-06 10:33:18 +00:00
|
|
|
aDirtyRect, rect, *border, mInnerFocusStyle);
|
1999-10-08 20:41:19 +00:00
|
|
|
}
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsButtonFrameRenderer::PaintBorderAndBackground(nsPresContext* aPresContext,
|
1999-10-08 20:41:19 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
2009-09-12 22:44:18 +00:00
|
|
|
const nsRect& aRect,
|
|
|
|
PRUint32 aBGFlags)
|
1999-02-26 06:41:10 +00:00
|
|
|
|
1999-02-19 18:23:02 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
// get the button rect this is inside the focus and outline rects
|
|
|
|
nsRect buttonRect;
|
|
|
|
GetButtonRect(aRect, buttonRect);
|
1999-02-19 18:23:02 +00:00
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* context = mFrame->GetStyleContext();
|
1999-02-19 18:23:02 +00:00
|
|
|
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleBorder* border = context->GetStyleBorder();
|
1999-03-06 19:43:13 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, mFrame,
|
2009-09-12 22:44:18 +00:00
|
|
|
aDirtyRect, buttonRect, aBGFlags);
|
2009-02-10 08:45:13 +00:00
|
|
|
nsCSSRendering::PaintBoxShadowInner(aPresContext, aRenderingContext,
|
|
|
|
mFrame, buttonRect, aDirtyRect);
|
1999-10-08 20:41:19 +00:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
2008-08-06 10:33:18 +00:00
|
|
|
aDirtyRect, buttonRect, *border, context);
|
1999-02-26 06:41:10 +00:00
|
|
|
}
|
1999-02-19 18:23:02 +00:00
|
|
|
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonOuterFocusRect(const nsRect& aRect, nsRect& focusRect)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
focusRect = aRect;
|
1999-02-26 06:41:10 +00:00
|
|
|
}
|
1999-02-19 18:23:02 +00:00
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonRect(const nsRect& aRect, nsRect& r)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
r = aRect;
|
|
|
|
r.Deflate(GetButtonOuterFocusBorderAndPadding());
|
1999-02-26 06:41:10 +00:00
|
|
|
}
|
1999-02-19 18:23:02 +00:00
|
|
|
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusRect(const nsRect& aRect, nsRect& focusRect)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
GetButtonRect(aRect, focusRect);
|
|
|
|
focusRect.Deflate(GetButtonBorderAndPadding());
|
|
|
|
focusRect.Deflate(GetButtonInnerFocusMargin());
|
1999-02-26 06:41:10 +00:00
|
|
|
}
|
1999-02-19 18:23:02 +00:00
|
|
|
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonOuterFocusBorderAndPadding()
|
|
|
|
{
|
2006-12-20 01:23:45 +00:00
|
|
|
nsMargin result(0,0,0,0);
|
1999-02-19 18:23:02 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
if (mOuterFocusStyle) {
|
2006-12-20 01:23:45 +00:00
|
|
|
if (!mOuterFocusStyle->GetStylePadding()->GetPadding(result)) {
|
|
|
|
NS_NOTYETIMPLEMENTED("percentage padding");
|
1999-07-28 04:48:34 +00:00
|
|
|
}
|
2008-07-17 06:30:25 +00:00
|
|
|
result += mOuterFocusStyle->GetStyleBorder()->GetActualBorder();
|
1999-10-08 20:41:19 +00:00
|
|
|
}
|
1999-02-26 06:41:10 +00:00
|
|
|
|
2006-12-20 01:23:45 +00:00
|
|
|
return result;
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonBorderAndPadding()
|
1999-02-19 18:23:02 +00:00
|
|
|
{
|
2006-12-20 01:23:45 +00:00
|
|
|
return mFrame->GetUsedBorderAndPadding();
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
/**
|
|
|
|
* Gets the size of the buttons border this is the union of the normal and disabled borders.
|
|
|
|
*/
|
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusMargin()
|
1999-02-19 18:23:02 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
nsMargin innerFocusMargin(0,0,0,0);
|
1999-02-19 18:23:02 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
if (mInnerFocusStyle) {
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleMargin* margin = mInnerFocusStyle->GetStyleMargin();
|
2006-12-20 01:23:45 +00:00
|
|
|
if (!margin->GetMargin(innerFocusMargin)) {
|
|
|
|
NS_NOTYETIMPLEMENTED("percentage margin");
|
|
|
|
}
|
1999-10-08 20:41:19 +00:00
|
|
|
}
|
1999-02-26 06:41:10 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
return innerFocusMargin;
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusBorderAndPadding()
|
1999-02-19 18:23:02 +00:00
|
|
|
{
|
2006-12-20 01:23:45 +00:00
|
|
|
nsMargin result(0,0,0,0);
|
1999-02-19 18:23:02 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
if (mInnerFocusStyle) {
|
2006-12-20 01:23:45 +00:00
|
|
|
if (!mInnerFocusStyle->GetStylePadding()->GetPadding(result)) {
|
|
|
|
NS_NOTYETIMPLEMENTED("percentage padding");
|
1999-07-28 04:48:34 +00:00
|
|
|
}
|
2008-07-17 06:30:25 +00:00
|
|
|
result += mInnerFocusStyle->GetStyleBorder()->GetActualBorder();
|
1999-10-08 20:41:19 +00:00
|
|
|
}
|
1999-02-26 06:41:10 +00:00
|
|
|
|
2006-12-20 01:23:45 +00:00
|
|
|
return result;
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 06:41:10 +00:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonOutlineBorderAndPadding()
|
1999-02-19 18:23:02 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
nsMargin borderAndPadding(0,0,0,0);
|
|
|
|
return borderAndPadding;
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
|
|
|
|
1999-03-27 00:58:29 +00:00
|
|
|
// gets the full size of our border with all the focus borders
|
1999-03-06 19:43:13 +00:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetFullButtonBorderAndPadding()
|
|
|
|
{
|
1999-03-27 00:58:29 +00:00
|
|
|
return GetAddedButtonBorderAndPadding() + GetButtonBorderAndPadding();
|
|
|
|
}
|
|
|
|
|
|
|
|
// gets all the focus borders and padding that will be added to the regular border
|
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetAddedButtonBorderAndPadding()
|
|
|
|
{
|
|
|
|
return GetButtonOuterFocusBorderAndPadding() + GetButtonInnerFocusMargin() + GetButtonInnerFocusBorderAndPadding();
|
1999-03-06 19:43:13 +00:00
|
|
|
}
|
|
|
|
|
1999-05-13 01:35:16 +00:00
|
|
|
/**
|
|
|
|
* Call this when styles change
|
|
|
|
*/
|
2007-05-23 20:32:56 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsButtonFrameRenderer::ReResolveStyles(nsPresContext* aPresContext)
|
1999-02-19 18:23:02 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
// get all the styles
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* context = mFrame->GetStyleContext();
|
2004-01-28 00:18:22 +00:00
|
|
|
nsStyleSet *styleSet = aPresContext->StyleSet();
|
1999-02-26 06:41:10 +00:00
|
|
|
|
1999-10-08 20:41:19 +00:00
|
|
|
// style for the inner such as a dotted line (Windows)
|
2009-12-10 22:36:05 +00:00
|
|
|
mInnerFocusStyle =
|
|
|
|
styleSet->ProbePseudoElementStyle(mFrame->GetContent(),
|
|
|
|
nsCSSPseudoElements::ePseudo_mozFocusInner,
|
|
|
|
context);
|
1999-10-08 20:41:19 +00:00
|
|
|
|
|
|
|
// style for outer focus like a ridged border (MAC).
|
2009-12-10 22:36:05 +00:00
|
|
|
mOuterFocusStyle =
|
|
|
|
styleSet->ProbePseudoElementStyle(mFrame->GetContent(),
|
|
|
|
nsCSSPseudoElements::ePseudo_mozFocusOuter,
|
|
|
|
context);
|
1999-02-19 18:23:02 +00:00
|
|
|
}
|
1999-09-03 23:36:32 +00:00
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext*
|
|
|
|
nsButtonFrameRenderer::GetStyleContext(PRInt32 aIndex) const
|
1999-09-03 23:36:32 +00:00
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_BUTTON_RENDERER_FOCUS_INNER_CONTEXT_INDEX:
|
2003-02-22 00:32:13 +00:00
|
|
|
return mInnerFocusStyle;
|
1999-09-03 23:36:32 +00:00
|
|
|
case NS_BUTTON_RENDERER_FOCUS_OUTER_CONTEXT_INDEX:
|
2003-02-22 00:32:13 +00:00
|
|
|
return mOuterFocusStyle;
|
1999-09-21 07:56:18 +00:00
|
|
|
default:
|
2003-02-22 00:32:13 +00:00
|
|
|
return nsnull;
|
1999-09-03 23:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::SetStyleContext(PRInt32 aIndex, nsStyleContext* aStyleContext)
|
1999-09-03 23:36:32 +00:00
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_BUTTON_RENDERER_FOCUS_INNER_CONTEXT_INDEX:
|
|
|
|
mInnerFocusStyle = aStyleContext;
|
|
|
|
break;
|
|
|
|
case NS_BUTTON_RENDERER_FOCUS_OUTER_CONTEXT_INDEX:
|
|
|
|
mOuterFocusStyle = aStyleContext;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|