2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-02-20 09:05:15 +03:00
|
|
|
#include "nsButtonFrameRenderer.h"
|
1999-02-19 21:23:02 +03:00
|
|
|
#include "nsCSSRendering.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
2004-01-28 03:18:22 +03:00
|
|
|
#include "nsStyleSet.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2007-02-16 04:53:43 +03:00
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsThemeConstants.h"
|
2011-04-21 21:35:52 +04:00
|
|
|
#include "nsEventStates.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
#define ACTIVE "active"
|
|
|
|
#define HOVER "hover"
|
|
|
|
#define FOCUS "focus"
|
1999-02-26 11:48:24 +03:00
|
|
|
|
1999-02-19 21:23:02 +03:00
|
|
|
nsButtonFrameRenderer::nsButtonFrameRenderer()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsButtonFrameRenderer);
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsButtonFrameRenderer::~nsButtonFrameRenderer()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(nsButtonFrameRenderer);
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsButtonFrameRenderer::SetFrame(nsFrame* aFrame, nsPresContext* aPresContext)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
mFrame = aFrame;
|
|
|
|
ReResolveStyles(aPresContext);
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-09-15 02:17:19 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsButtonFrameRenderer::GetFrame()
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
return mFrame;
|
1999-09-15 02:17:19 +04:00
|
|
|
}
|
|
|
|
|
1999-02-26 11:48:24 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsButtonFrameRenderer::SetDisabled(bool aDisabled, bool notify)
|
1999-02-26 11:48:24 +03:00
|
|
|
{
|
1999-03-13 02:47:52 +03:00
|
|
|
if (aDisabled)
|
2006-12-26 20:47:52 +03:00
|
|
|
mFrame->GetContent()->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, EmptyString(),
|
2003-07-04 16:50:32 +04:00
|
|
|
notify);
|
1999-03-13 02:47:52 +03:00
|
|
|
else
|
2006-12-26 20:47:52 +03:00
|
|
|
mFrame->GetContent()->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, notify);
|
1999-02-26 11:48:24 +03:00
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
1999-02-26 11:48:24 +03:00
|
|
|
nsButtonFrameRenderer::isDisabled()
|
|
|
|
{
|
2011-06-01 05:46:56 +04:00
|
|
|
return mFrame->GetContent()->AsElement()->
|
2011-06-01 05:46:57 +04:00
|
|
|
State().HasState(NS_EVENT_STATE_DISABLED);
|
1999-02-26 11:48:24 +03:00
|
|
|
}
|
|
|
|
|
2009-02-10 11:45:13 +03:00
|
|
|
class nsDisplayButtonBoxShadowOuter : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayButtonBoxShadowOuter(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsButtonFrameRenderer* aRenderer)
|
|
|
|
: nsDisplayItem(aBuilder, aRenderer->GetFrame()), mBFR(aRenderer) {
|
2009-02-10 11:45:13 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayButtonBoxShadowOuter);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayButtonBoxShadowOuter() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayButtonBoxShadowOuter);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx);
|
2012-04-10 15:24:18 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap);
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("ButtonBoxShadowOuter", TYPE_BUTTON_BOX_SHADOW_OUTER)
|
2009-02-10 11:45:13 +03:00
|
|
|
private:
|
|
|
|
nsButtonFrameRenderer* mBFR;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplayButtonBoxShadowOuter::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2011-10-21 21:45:32 +04:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2009-02-10 11:45:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayButtonBoxShadowOuter::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect frameRect = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2009-02-10 11:45:13 +03:00
|
|
|
|
|
|
|
nsRect buttonRect;
|
|
|
|
mBFR->GetButtonRect(frameRect, buttonRect);
|
|
|
|
|
|
|
|
nsCSSRendering::PaintBoxShadowOuter(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 04:35:14 +04:00
|
|
|
buttonRect, mVisibleRect);
|
2009-02-10 11:45:13 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
class nsDisplayButtonBorderBackground : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayButtonBorderBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsButtonFrameRenderer* aRenderer)
|
|
|
|
: nsDisplayItem(aBuilder, aRenderer->GetFrame()), mBFR(aRenderer) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayButtonBorderBackground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayButtonBorderBackground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayButtonBorderBackground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) {
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx);
|
2012-08-29 09:39:01 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap);
|
2013-06-26 20:43:26 +04:00
|
|
|
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion *aInvalidRegion) MOZ_OVERRIDE;
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("ButtonBorderBackground", TYPE_BUTTON_BORDER_BACKGROUND)
|
2006-01-26 05:29:17 +03:00
|
|
|
private:
|
|
|
|
nsButtonFrameRenderer* mBFR;
|
|
|
|
};
|
|
|
|
|
2012-08-29 09:39:01 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayButtonBorderBackground::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2012-09-28 15:19:38 +04:00
|
|
|
return aBuilder->IsForEventDelivery() ? nsRect(ToReferenceFrame(), mFrame->GetSize())
|
|
|
|
: mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2012-08-29 09:39:01 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
class nsDisplayButtonForeground : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayButtonForeground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsButtonFrameRenderer* aRenderer)
|
|
|
|
: nsDisplayItem(aBuilder, aRenderer->GetFrame()), mBFR(aRenderer) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayButtonForeground);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayButtonForeground() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayButtonForeground);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("ButtonForeground", TYPE_BUTTON_FOREGROUND)
|
2006-01-26 05:29:17 +03:00
|
|
|
private:
|
|
|
|
nsButtonFrameRenderer* mBFR;
|
|
|
|
};
|
1999-03-02 04:25:33 +03:00
|
|
|
|
2013-06-26 20:43:26 +04:00
|
|
|
void
|
|
|
|
nsDisplayButtonBorderBackground::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion *aInvalidRegion)
|
|
|
|
{
|
|
|
|
AddInvalidRegionForSyncDecodeBackgroundImages(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
|
|
|
|
nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
2006-01-29 21:48:58 +03:00
|
|
|
void nsDisplayButtonBorderBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2006-03-14 23:43:18 +03:00
|
|
|
NS_ASSERTION(mFrame, "No frame?");
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* pc = mFrame->PresContext();
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect r = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2006-01-26 05:29:17 +03:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
// draw the border and background inside the focus and outline borders
|
2009-09-07 04:35:14 +04:00
|
|
|
mBFR->PaintBorderAndBackground(pc, *aCtx, mVisibleRect, r,
|
2009-09-13 02:44:18 +04:00
|
|
|
aBuilder->GetBackgroundPaintFlags());
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
2006-01-29 21:48:58 +03:00
|
|
|
void nsDisplayButtonForeground::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext *presContext = mFrame->PresContext();
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay *disp = mFrame->StyleDisplay();
|
2007-02-16 04:53:43 +03:00
|
|
|
if (!mFrame->IsThemed(disp) ||
|
2013-05-14 03:47:03 +04:00
|
|
|
!presContext->GetTheme()->ThemeDrawsFocusForWidget(disp->mAppearance)) {
|
2007-02-16 04:53:43 +03:00
|
|
|
// draw the focus and outline borders
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect r = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2009-09-07 04:35:14 +04:00
|
|
|
mBFR->PaintOutlineAndFocusBorders(presContext, *aCtx, mVisibleRect, r);
|
2007-02-16 04:53:43 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsButtonFrameRenderer::DisplayButton(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aBackground,
|
|
|
|
nsDisplayList* aForeground)
|
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
if (mFrame->StyleBorder()->mBoxShadow) {
|
2013-02-14 15:08:08 +04:00
|
|
|
aBackground->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayButtonBoxShadowOuter(aBuilder, this));
|
2009-02-10 11:45:13 +03:00
|
|
|
}
|
|
|
|
|
2013-03-22 06:17:27 +04:00
|
|
|
// Almost all buttons draw some kind of background so there's not much
|
|
|
|
// point in checking whether we should create this item.
|
2013-02-14 15:08:08 +04:00
|
|
|
aBackground->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayButtonBorderBackground(aBuilder, this));
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-03-22 06:17:27 +04:00
|
|
|
// Only display focus rings if we actually have them. Since at most one
|
|
|
|
// button would normally display a focus ring, most buttons won't have them.
|
|
|
|
if ((mOuterFocusStyle && mOuterFocusStyle->StyleBorder()->HasBorder()) ||
|
|
|
|
(mInnerFocusStyle && mInnerFocusStyle->StyleBorder()->HasBorder())) {
|
|
|
|
aForeground->AppendNewToTop(new (aBuilder)
|
|
|
|
nsDisplayButtonForeground(aBuilder, this));
|
|
|
|
}
|
2013-02-14 15:08:08 +04:00
|
|
|
return NS_OK;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsButtonFrameRenderer::PaintOutlineAndFocusBorders(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext& aRenderingContext,
|
1999-10-09 00:41:19 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aRect)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
2008-08-06 14:33:18 +04: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 21:23:02 +03:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
nsRect rect;
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2002-04-06 19:31:53 +04:00
|
|
|
if (mOuterFocusStyle) {
|
|
|
|
// ---------- paint the outer focus border -------------
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2002-04-06 19:31:53 +04:00
|
|
|
GetButtonOuterFocusRect(aRect, rect);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2002-04-06 19:31:53 +04:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
2010-04-03 05:58:26 +04:00
|
|
|
aDirtyRect, rect, mOuterFocusStyle);
|
2002-04-06 19:31:53 +04:00
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2002-04-06 19:31:53 +04:00
|
|
|
if (mInnerFocusStyle) {
|
1999-10-09 00:41:19 +04:00
|
|
|
// ---------- paint the inner focus border -------------
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2002-04-06 19:31:53 +04:00
|
|
|
GetButtonInnerFocusRect(aRect, rect);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2002-04-06 19:31:53 +04:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
2010-04-03 05:58:26 +04:00
|
|
|
aDirtyRect, rect, mInnerFocusStyle);
|
1999-10-09 00:41:19 +04:00
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsButtonFrameRenderer::PaintBorderAndBackground(nsPresContext* aPresContext,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext& aRenderingContext,
|
1999-10-09 00:41:19 +04:00
|
|
|
const nsRect& aDirtyRect,
|
2009-09-13 02:44:18 +04:00
|
|
|
const nsRect& aRect,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aBGFlags)
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
// get the button rect this is inside the focus and outline rects
|
|
|
|
nsRect buttonRect;
|
|
|
|
GetButtonRect(aRect, buttonRect);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2013-02-16 09:38:33 +04:00
|
|
|
nsStyleContext* context = mFrame->StyleContext();
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, mFrame,
|
2009-09-13 02:44:18 +04:00
|
|
|
aDirtyRect, buttonRect, aBGFlags);
|
2009-02-10 11:45:13 +03:00
|
|
|
nsCSSRendering::PaintBoxShadowInner(aPresContext, aRenderingContext,
|
|
|
|
mFrame, buttonRect, aDirtyRect);
|
1999-10-09 00:41:19 +04:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
2010-04-03 05:58:26 +04:00
|
|
|
aDirtyRect, buttonRect, context);
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonOuterFocusRect(const nsRect& aRect, nsRect& focusRect)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
focusRect = aRect;
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonRect(const nsRect& aRect, nsRect& r)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
r = aRect;
|
|
|
|
r.Deflate(GetButtonOuterFocusBorderAndPadding());
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusRect(const nsRect& aRect, nsRect& focusRect)
|
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
GetButtonRect(aRect, focusRect);
|
|
|
|
focusRect.Deflate(GetButtonBorderAndPadding());
|
|
|
|
focusRect.Deflate(GetButtonInnerFocusMargin());
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
1999-02-19 21:23:02 +03:00
|
|
|
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonOuterFocusBorderAndPadding()
|
|
|
|
{
|
2006-12-20 04:23:45 +03:00
|
|
|
nsMargin result(0,0,0,0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
if (mOuterFocusStyle) {
|
2013-02-17 01:51:02 +04:00
|
|
|
if (!mOuterFocusStyle->StylePadding()->GetPadding(result)) {
|
2006-12-20 04:23:45 +03:00
|
|
|
NS_NOTYETIMPLEMENTED("percentage padding");
|
1999-07-28 08:48:34 +04:00
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
result += mOuterFocusStyle->StyleBorder()->GetComputedBorder();
|
1999-10-09 00:41:19 +04:00
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
2006-12-20 04:23:45 +03:00
|
|
|
return result;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonBorderAndPadding()
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
2006-12-20 04:23:45 +03:00
|
|
|
return mFrame->GetUsedBorderAndPadding();
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
/**
|
|
|
|
* Gets the size of the buttons border this is the union of the normal and disabled borders.
|
|
|
|
*/
|
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusMargin()
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
nsMargin innerFocusMargin(0,0,0,0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
if (mInnerFocusStyle) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleMargin* margin = mInnerFocusStyle->StyleMargin();
|
2006-12-20 04:23:45 +03:00
|
|
|
if (!margin->GetMargin(innerFocusMargin)) {
|
|
|
|
NS_NOTYETIMPLEMENTED("percentage margin");
|
|
|
|
}
|
1999-10-09 00:41:19 +04:00
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
return innerFocusMargin;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-02-26 09:41:10 +03:00
|
|
|
nsMargin
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusBorderAndPadding()
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
2006-12-20 04:23:45 +03:00
|
|
|
nsMargin result(0,0,0,0);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
if (mInnerFocusStyle) {
|
2013-02-17 01:51:02 +04:00
|
|
|
if (!mInnerFocusStyle->StylePadding()->GetPadding(result)) {
|
2006-12-20 04:23:45 +03:00
|
|
|
NS_NOTYETIMPLEMENTED("percentage padding");
|
1999-07-28 08:48:34 +04:00
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
result += mInnerFocusStyle->StyleBorder()->GetComputedBorder();
|
1999-10-09 00:41:19 +04:00
|
|
|
}
|
1999-02-26 09:41:10 +03:00
|
|
|
|
2006-12-20 04:23:45 +03:00
|
|
|
return result;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
1999-03-27 03:58:29 +03:00
|
|
|
// 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 22:43:13 +03:00
|
|
|
}
|
|
|
|
|
1999-05-13 05:35:16 +04:00
|
|
|
/**
|
|
|
|
* Call this when styles change
|
|
|
|
*/
|
2007-05-24 00:32:56 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsButtonFrameRenderer::ReResolveStyles(nsPresContext* aPresContext)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
// get all the styles
|
2013-02-16 09:38:33 +04:00
|
|
|
nsStyleContext* context = mFrame->StyleContext();
|
2004-01-28 03:18:22 +03:00
|
|
|
nsStyleSet *styleSet = aPresContext->StyleSet();
|
1999-02-26 09:41:10 +03:00
|
|
|
|
1999-10-09 00:41:19 +04:00
|
|
|
// style for the inner such as a dotted line (Windows)
|
2009-12-11 10:37:40 +03:00
|
|
|
mInnerFocusStyle =
|
2010-04-30 17:12:06 +04:00
|
|
|
styleSet->ProbePseudoElementStyle(mFrame->GetContent()->AsElement(),
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::ePseudo_mozFocusInner,
|
|
|
|
context);
|
1999-10-09 00:41:19 +04:00
|
|
|
|
|
|
|
// style for outer focus like a ridged border (MAC).
|
2009-12-11 10:37:40 +03:00
|
|
|
mOuterFocusStyle =
|
2010-04-30 17:12:06 +04:00
|
|
|
styleSet->ProbePseudoElementStyle(mFrame->GetContent()->AsElement(),
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::ePseudo_mozFocusOuter,
|
|
|
|
context);
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
1999-09-04 03:36:32 +04:00
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsButtonFrameRenderer::GetStyleContext(int32_t aIndex) const
|
1999-09-04 03:36:32 +04:00
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_BUTTON_RENDERER_FOCUS_INNER_CONTEXT_INDEX:
|
2003-02-22 03:32:13 +03:00
|
|
|
return mInnerFocusStyle;
|
1999-09-04 03:36:32 +04:00
|
|
|
case NS_BUTTON_RENDERER_FOCUS_OUTER_CONTEXT_INDEX:
|
2003-02-22 03:32:13 +03:00
|
|
|
return mOuterFocusStyle;
|
1999-09-21 11:56:18 +04:00
|
|
|
default:
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1999-09-04 03:36:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsButtonFrameRenderer::SetStyleContext(int32_t aIndex, nsStyleContext* aStyleContext)
|
1999-09-04 03:36:32 +04: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;
|
|
|
|
}
|
|
|
|
}
|