2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2018-03-29 14:15:46 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2017-08-28 06:29:35 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2007-02-16 04:53:43 +03:00
|
|
|
#include "nsITheme.h"
|
2013-08-28 18:30:02 +04:00
|
|
|
#include "nsFrame.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2017-03-08 19:31:46 +03:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "gfxPrefs.h"
|
|
|
|
#include "gfxUtils.h"
|
2017-10-03 23:31:08 +03:00
|
|
|
#include "mozilla/layers/WebRenderLayerManager.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
|
|
|
|
2015-10-23 05:54:48 +03:00
|
|
|
using namespace mozilla;
|
2015-02-10 10:27:40 +03:00
|
|
|
using namespace mozilla::image;
|
2017-03-08 19:31:46 +03:00
|
|
|
using namespace mozilla::layers;
|
2015-02-10 10:27:40 +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
|
2017-12-05 20:05:51 +03:00
|
|
|
nsButtonFrameRenderer::SetDisabled(bool aDisabled, bool aNotify)
|
1999-02-26 11:48:24 +03:00
|
|
|
{
|
2017-12-05 20:05:51 +03:00
|
|
|
Element* element = mFrame->GetContent()->AsElement();
|
1999-03-13 02:47:52 +03:00
|
|
|
if (aDisabled)
|
2017-12-05 20:05:51 +03:00
|
|
|
element->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, EmptyString(),
|
|
|
|
aNotify);
|
1999-03-13 02:47:52 +03:00
|
|
|
else
|
2017-12-05 20:05:51 +03:00
|
|
|
element->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, aNotify);
|
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
|
2017-07-06 15:00:35 +03:00
|
|
|
nsButtonFrameRenderer::isDisabled()
|
1999-02-26 11:48:24 +03:00
|
|
|
{
|
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)
|
2017-03-08 19:31:46 +03:00
|
|
|
: nsDisplayItem(aBuilder, aRenderer->GetFrame()) {
|
2009-02-10 11:45:13 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayButtonBoxShadowOuter);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayButtonBoxShadowOuter() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayButtonBoxShadowOuter);
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
#endif
|
|
|
|
|
2017-08-28 06:29:35 +03:00
|
|
|
virtual bool CreateWebRenderCommands(
|
|
|
|
mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-08-28 06:29:35 +03:00
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) override;
|
|
|
|
|
|
|
|
bool CanBuildWebRenderDisplayItems();
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx) override;
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
2017-08-24 18:09:44 +03:00
|
|
|
bool* aSnap) const override;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
nsRect
|
2017-08-24 18:09:44 +03:00
|
|
|
nsDisplayButtonBoxShadowOuter::GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) const
|
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*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,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect frameRect = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2009-02-10 11:45:13 +03:00
|
|
|
|
|
|
|
nsCSSRendering::PaintBoxShadowOuter(mFrame->PresContext(), *aCtx, mFrame,
|
2017-03-08 19:31:46 +03:00
|
|
|
frameRect, mVisibleRect);
|
2009-02-10 11:45:13 +03:00
|
|
|
}
|
|
|
|
|
2017-08-28 06:29:35 +03:00
|
|
|
bool
|
|
|
|
nsDisplayButtonBoxShadowOuter::CanBuildWebRenderDisplayItems()
|
|
|
|
{
|
|
|
|
nsCSSShadowArray* shadows = mFrame->StyleEffects()->mBoxShadow;
|
|
|
|
if (!shadows) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasBorderRadius;
|
|
|
|
bool nativeTheme =
|
|
|
|
nsCSSRendering::HasBoxShadowNativeTheme(mFrame, hasBorderRadius);
|
|
|
|
|
|
|
|
// We don't support native themed things yet like box shadows around
|
|
|
|
// input buttons.
|
|
|
|
if (nativeTheme) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayButtonBoxShadowOuter::CreateWebRenderCommands(
|
|
|
|
mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-08-28 06:29:35 +03:00
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
|
|
|
{
|
2017-11-10 06:41:15 +03:00
|
|
|
if (!CanBuildWebRenderDisplayItems()) {
|
2017-10-03 23:31:07 +03:00
|
|
|
return false;
|
2017-08-28 06:29:35 +03:00
|
|
|
}
|
|
|
|
int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
nsRect shadowRect = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
LayoutDeviceRect deviceBox =
|
|
|
|
LayoutDeviceRect::FromAppUnits(shadowRect, appUnitsPerDevPixel);
|
2018-03-30 00:57:43 +03:00
|
|
|
wr::LayoutRect deviceBoxRect = wr::ToRoundedLayoutRect(deviceBox);
|
2017-08-28 06:29:35 +03:00
|
|
|
|
|
|
|
LayoutDeviceRect clipRect =
|
|
|
|
LayoutDeviceRect::FromAppUnits(mVisibleRect, appUnitsPerDevPixel);
|
2018-03-30 00:57:43 +03:00
|
|
|
wr::LayoutRect deviceClipRect = wr::ToRoundedLayoutRect(clipRect);
|
2017-08-28 06:29:35 +03:00
|
|
|
|
|
|
|
bool hasBorderRadius;
|
|
|
|
Unused << nsCSSRendering::HasBoxShadowNativeTheme(mFrame, hasBorderRadius);
|
|
|
|
|
2017-10-24 09:44:29 +03:00
|
|
|
LayoutDeviceSize zeroSize;
|
|
|
|
wr::BorderRadius borderRadius = wr::ToBorderRadius(zeroSize, zeroSize,
|
|
|
|
zeroSize, zeroSize);
|
2017-08-28 06:29:35 +03:00
|
|
|
if (hasBorderRadius) {
|
|
|
|
mozilla::gfx::RectCornerRadii borderRadii;
|
|
|
|
hasBorderRadius = nsCSSRendering::GetBorderRadii(
|
|
|
|
shadowRect, shadowRect, mFrame, borderRadii);
|
2017-10-24 09:44:29 +03:00
|
|
|
if (hasBorderRadius) {
|
|
|
|
borderRadius = wr::ToBorderRadius(
|
|
|
|
LayoutDeviceSize::FromUnknownSize(borderRadii.TopLeft()),
|
|
|
|
LayoutDeviceSize::FromUnknownSize(borderRadii.TopRight()),
|
|
|
|
LayoutDeviceSize::FromUnknownSize(borderRadii.BottomLeft()),
|
|
|
|
LayoutDeviceSize::FromUnknownSize(borderRadii.BottomRight()));
|
|
|
|
}
|
|
|
|
|
2017-08-28 06:29:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSShadowArray* shadows = mFrame->StyleEffects()->mBoxShadow;
|
|
|
|
MOZ_ASSERT(shadows);
|
|
|
|
|
|
|
|
for (uint32_t i = shadows->Length(); i > 0; i--) {
|
|
|
|
nsCSSShadowItem* shadow = shadows->ShadowAt(i - 1);
|
|
|
|
if (shadow->mInset) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
float blurRadius = float(shadow->mRadius) / float(appUnitsPerDevPixel);
|
|
|
|
gfx::Color shadowColor =
|
|
|
|
nsCSSRendering::GetShadowColor(shadow, mFrame, 1.0);
|
|
|
|
|
2017-10-19 05:25:11 +03:00
|
|
|
LayoutDevicePoint shadowOffset = LayoutDevicePoint::FromAppUnits(
|
|
|
|
nsPoint(shadow->mXOffset, shadow->mYOffset),
|
|
|
|
appUnitsPerDevPixel);
|
2017-08-28 06:29:35 +03:00
|
|
|
|
|
|
|
float spreadRadius = float(shadow->mSpread) / float(appUnitsPerDevPixel);
|
|
|
|
|
|
|
|
aBuilder.PushBoxShadow(deviceBoxRect,
|
|
|
|
deviceClipRect,
|
2017-09-21 09:41:38 +03:00
|
|
|
!BackfaceIsHidden(),
|
2017-08-28 06:29:35 +03:00
|
|
|
deviceBoxRect,
|
|
|
|
wr::ToLayoutVector2D(shadowOffset),
|
|
|
|
wr::ToColorF(shadowColor),
|
|
|
|
blurRadius,
|
|
|
|
spreadRadius,
|
|
|
|
borderRadius,
|
|
|
|
wr::BoxShadowClipMode::Outset);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-04 21:12:23 +03:00
|
|
|
class nsDisplayButtonBorder : public nsDisplayItem {
|
2006-01-26 05:29:17 +03:00
|
|
|
public:
|
2016-05-04 21:12:23 +03:00
|
|
|
nsDisplayButtonBorder(nsDisplayListBuilder* aBuilder,
|
2010-08-13 14:01:13 +04:00
|
|
|
nsButtonFrameRenderer* aRenderer)
|
2017-10-31 20:18:14 +03:00
|
|
|
: nsDisplayItem(aBuilder, aRenderer->GetFrame())
|
|
|
|
, mBFR(aRenderer)
|
|
|
|
{
|
2016-05-04 21:12:23 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayButtonBorder);
|
2006-01-29 21:48:58 +03:00
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2016-05-04 21:12:23 +03:00
|
|
|
virtual ~nsDisplayButtonBorder() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayButtonBorder);
|
2006-01-29 21:48:58 +03:00
|
|
|
}
|
2016-05-04 21:12:23 +03:00
|
|
|
#endif
|
2017-07-20 12:34:15 +03:00
|
|
|
virtual bool MustPaintOnContentSide() const override { return true; }
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
2014-02-24 18:41:56 +04:00
|
|
|
HitTestState* aState,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsTArray<nsIFrame*> *aOutFrames) override {
|
2010-04-08 04:31:26 +04:00
|
|
|
aOutFrames->AppendElement(mFrame);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx) override;
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
2017-08-24 18:09:44 +03:00
|
|
|
bool* aSnap) const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override;
|
2013-06-26 20:43:26 +04:00
|
|
|
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2017-08-24 18:09:44 +03:00
|
|
|
nsRegion *aInvalidRegion) const override;
|
2017-07-01 03:23:20 +03:00
|
|
|
virtual bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const StackingContextHelper& aSc,
|
2017-07-01 03:23:20 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) 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;
|
|
|
|
};
|
|
|
|
|
2015-10-23 05:54:48 +03:00
|
|
|
nsDisplayItemGeometry*
|
2016-05-04 21:12:23 +03:00
|
|
|
nsDisplayButtonBorder::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
2015-10-23 05:54:48 +03:00
|
|
|
{
|
|
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
2017-07-01 03:23:20 +03:00
|
|
|
bool
|
2017-03-08 19:31:46 +03:00
|
|
|
nsDisplayButtonBorder::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const StackingContextHelper& aSc,
|
2017-07-01 03:23:20 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
2017-03-08 19:31:46 +03:00
|
|
|
{
|
2017-11-17 12:09:33 +03:00
|
|
|
// This is really a combination of paint box shadow inner +
|
|
|
|
// paint border.
|
|
|
|
nsRect buttonRect = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
bool snap;
|
|
|
|
nsRegion visible = GetBounds(aDisplayListBuilder, &snap);
|
|
|
|
nsDisplayBoxShadowInner::CreateInsetBoxShadowWebRenderCommands(aBuilder,
|
|
|
|
aSc,
|
|
|
|
visible,
|
|
|
|
mFrame,
|
|
|
|
buttonRect);
|
|
|
|
|
2017-11-10 06:41:15 +03:00
|
|
|
bool borderIsEmpty = false;
|
|
|
|
Maybe<nsCSSBorderRenderer> br =
|
|
|
|
nsCSSRendering::CreateBorderRenderer(mFrame->PresContext(),
|
|
|
|
nullptr,
|
|
|
|
mFrame,
|
|
|
|
nsRect(),
|
|
|
|
nsRect(ToReferenceFrame(), mFrame->GetSize()),
|
2018-03-22 21:20:41 +03:00
|
|
|
mFrame->Style(),
|
2017-11-10 06:41:15 +03:00
|
|
|
&borderIsEmpty,
|
|
|
|
mFrame->GetSkipSides());
|
|
|
|
if (!br) {
|
2018-01-15 05:35:20 +03:00
|
|
|
return borderIsEmpty;
|
2017-07-01 03:23:20 +03:00
|
|
|
}
|
|
|
|
|
2017-11-10 06:41:15 +03:00
|
|
|
br->CreateWebRenderCommands(this, aBuilder, aResources, aSc);
|
2017-07-01 03:23:20 +03:00
|
|
|
|
|
|
|
return true;
|
2017-03-08 19:31:46 +03:00
|
|
|
}
|
|
|
|
|
2015-10-23 05:54:48 +03:00
|
|
|
void
|
2017-08-24 18:09:44 +03:00
|
|
|
nsDisplayButtonBorder::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion *aInvalidRegion) const
|
2015-10-23 05:54:48 +03:00
|
|
|
{
|
|
|
|
auto geometry =
|
|
|
|
static_cast<const nsDisplayItemGenericImageGeometry*>(aGeometry);
|
|
|
|
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages() &&
|
|
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
2017-03-08 19:31:46 +03:00
|
|
|
void
|
|
|
|
nsDisplayButtonBorder::Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx)
|
2015-10-23 05:54:48 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mFrame, "No frame?");
|
|
|
|
nsPresContext* pc = mFrame->PresContext();
|
|
|
|
nsRect r = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2016-05-04 21:12:23 +03:00
|
|
|
|
2015-10-23 05:54:48 +03:00
|
|
|
// draw the border and background inside the focus and outline borders
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result =
|
2016-05-04 21:12:23 +03:00
|
|
|
mBFR->PaintBorder(aBuilder, pc, *aCtx, mVisibleRect, r);
|
2015-10-23 05:54:48 +03:00
|
|
|
|
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
|
|
|
}
|
|
|
|
|
2012-08-29 09:39:01 +04:00
|
|
|
nsRect
|
2017-08-24 18:09:44 +03:00
|
|
|
nsDisplayButtonBorder::GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) const
|
|
|
|
{
|
2012-08-29 09:39:01 +04:00
|
|
|
*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);
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
#endif
|
2006-01-29 21:48:58 +03:00
|
|
|
|
2015-10-23 05:54:48 +03:00
|
|
|
nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override;
|
|
|
|
void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2017-08-24 18:09:44 +03:00
|
|
|
nsRegion *aInvalidRegion) const override;
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx) override;
|
2017-07-01 03:23:20 +03:00
|
|
|
virtual bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const StackingContextHelper& aSc,
|
2017-07-01 03:23:20 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) override;
|
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
|
|
|
|
2015-02-10 10:27:40 +03:00
|
|
|
nsDisplayItemGeometry*
|
2015-10-23 05:54:48 +03:00
|
|
|
nsDisplayButtonForeground::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
2015-02-10 10:27:40 +03:00
|
|
|
{
|
|
|
|
return new nsDisplayItemGenericImageGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
2013-06-26 20:43:26 +04:00
|
|
|
void
|
2017-08-24 18:09:44 +03:00
|
|
|
nsDisplayButtonForeground::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion) const
|
2013-06-26 20:43:26 +04:00
|
|
|
{
|
2015-02-10 10:27:40 +03:00
|
|
|
auto geometry =
|
|
|
|
static_cast<const nsDisplayItemGenericImageGeometry*>(aGeometry);
|
|
|
|
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages() &&
|
|
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
2013-06-26 20:43:26 +04:00
|
|
|
|
|
|
|
nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
2006-01-29 21:48:58 +03:00
|
|
|
void nsDisplayButtonForeground::Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* 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) ||
|
2017-05-21 12:15:00 +03:00
|
|
|
!presContext->GetTheme()->ThemeDrawsFocusForWidget(disp->mAppearance)) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect r = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2015-10-23 05:54:48 +03:00
|
|
|
|
2016-12-02 09:11:48 +03:00
|
|
|
// Draw the -moz-focus-inner border
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result =
|
2016-12-02 09:11:48 +03:00
|
|
|
mBFR->PaintInnerFocusBorder(aBuilder, presContext, *aCtx, mVisibleRect, r);
|
2015-10-23 05:54:48 +03:00
|
|
|
|
|
|
|
nsDisplayItemGenericImageGeometry::UpdateDrawResult(this, result);
|
2007-02-16 04:53:43 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2017-07-01 03:23:20 +03:00
|
|
|
bool
|
|
|
|
nsDisplayButtonForeground::CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const StackingContextHelper& aSc,
|
2017-07-01 03:23:20 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
2017-03-09 11:58:39 +03:00
|
|
|
{
|
2017-11-10 06:41:15 +03:00
|
|
|
Maybe<nsCSSBorderRenderer> br;
|
|
|
|
bool borderIsEmpty = false;
|
|
|
|
nsPresContext *presContext = mFrame->PresContext();
|
|
|
|
const nsStyleDisplay *disp = mFrame->StyleDisplay();
|
|
|
|
if (!mFrame->IsThemed(disp) ||
|
|
|
|
!presContext->GetTheme()->ThemeDrawsFocusForWidget(disp->mAppearance)) {
|
|
|
|
nsRect r = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
br = mBFR->CreateInnerFocusBorderRenderer(aDisplayListBuilder, presContext, nullptr,
|
|
|
|
mVisibleRect, r, &borderIsEmpty);
|
2017-07-01 03:23:20 +03:00
|
|
|
}
|
|
|
|
|
2017-11-10 06:41:15 +03:00
|
|
|
if (!br) {
|
2018-01-15 05:35:20 +03:00
|
|
|
return borderIsEmpty;
|
2017-11-01 12:30:04 +03:00
|
|
|
}
|
|
|
|
|
2017-11-10 06:41:15 +03:00
|
|
|
br->CreateWebRenderCommands(this, aBuilder, aResources, aSc);
|
2017-07-01 03:23:20 +03:00
|
|
|
return true;
|
2017-03-09 11:58:39 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsresult
|
|
|
|
nsButtonFrameRenderer::DisplayButton(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aBackground,
|
|
|
|
nsDisplayList* aForeground)
|
|
|
|
{
|
2016-04-12 08:52:42 +03:00
|
|
|
if (mFrame->StyleEffects()->mBoxShadow) {
|
2018-02-13 03:43:28 +03:00
|
|
|
aBackground->AppendToTop(
|
|
|
|
MakeDisplayItem<nsDisplayButtonBoxShadowOuter>(aBuilder, this));
|
2009-02-10 11:45:13 +03:00
|
|
|
}
|
|
|
|
|
2017-03-08 19:31:46 +03:00
|
|
|
nsRect buttonRect = mFrame->GetRectRelativeToSelf();
|
2016-05-04 21:12:23 +03:00
|
|
|
|
|
|
|
nsDisplayBackgroundImage::AppendBackgroundItemsToTop(
|
|
|
|
aBuilder, mFrame, buttonRect, aBackground);
|
|
|
|
|
2018-02-13 03:43:28 +03:00
|
|
|
aBackground->AppendToTop(
|
|
|
|
MakeDisplayItem<nsDisplayButtonBorder>(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.
|
2016-10-21 19:19:03 +03:00
|
|
|
if (mInnerFocusStyle && mInnerFocusStyle->StyleBorder()->HasBorder()) {
|
2018-02-13 03:43:28 +03:00
|
|
|
aForeground->AppendToTop(
|
|
|
|
MakeDisplayItem<nsDisplayButtonForeground>(aBuilder, this));
|
2013-03-22 06:17:27 +04:00
|
|
|
}
|
2013-02-14 15:08:08 +04:00
|
|
|
return NS_OK;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
2016-12-02 09:11:48 +03:00
|
|
|
void
|
|
|
|
nsButtonFrameRenderer::GetButtonInnerFocusRect(const nsRect& aRect, nsRect& aResult)
|
|
|
|
{
|
2017-03-08 19:31:46 +03:00
|
|
|
aResult = aRect;
|
2016-12-02 09:11:48 +03:00
|
|
|
aResult.Deflate(mFrame->GetUsedBorderAndPadding());
|
|
|
|
|
|
|
|
nsMargin innerFocusPadding(0,0,0,0);
|
|
|
|
if (mInnerFocusStyle) {
|
|
|
|
mInnerFocusStyle->StylePadding()->GetPadding(innerFocusPadding);
|
|
|
|
}
|
|
|
|
aResult.Inflate(innerFocusPadding);
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult
|
2016-12-02 09:11:48 +03:00
|
|
|
nsButtonFrameRenderer::PaintInnerFocusBorder(
|
2015-10-23 05:54:48 +03:00
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsPresContext* aPresContext,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext& aRenderingContext,
|
2015-10-23 05:54:48 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aRect)
|
1999-02-19 21:23:02 +03:00
|
|
|
{
|
2016-12-02 09:11:48 +03:00
|
|
|
// we draw the -moz-focus-inner border just inside the button's
|
|
|
|
// normal border and padding, to match Windows themes.
|
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
|
|
|
|
2015-10-23 05:54:48 +03:00
|
|
|
PaintBorderFlags flags = aBuilder->ShouldSyncDecodeImages()
|
|
|
|
? PaintBorderFlags::SYNC_DECODE_IMAGES
|
|
|
|
: PaintBorderFlags();
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result = ImgDrawResult::SUCCESS;
|
2015-10-23 05:54:48 +03:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
if (mInnerFocusStyle) {
|
2002-04-06 19:31:53 +04:00
|
|
|
GetButtonInnerFocusRect(aRect, rect);
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2015-10-23 05:54:48 +03:00
|
|
|
result &=
|
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
|
|
|
aDirtyRect, rect, mInnerFocusStyle, flags);
|
1999-10-09 00:41:19 +04:00
|
|
|
}
|
2015-10-23 05:54:48 +03:00
|
|
|
|
|
|
|
return result;
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 11:58:39 +03:00
|
|
|
Maybe<nsCSSBorderRenderer>
|
|
|
|
nsButtonFrameRenderer::CreateInnerFocusBorderRenderer(
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsPresContext* aPresContext,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aRenderingContext,
|
2017-03-09 11:58:39 +03:00
|
|
|
const nsRect& aDirtyRect,
|
2017-11-01 12:30:04 +03:00
|
|
|
const nsRect& aRect,
|
|
|
|
bool* aBorderIsEmpty)
|
2017-03-09 11:58:39 +03:00
|
|
|
{
|
|
|
|
if (mInnerFocusStyle) {
|
|
|
|
nsRect rect;
|
|
|
|
GetButtonInnerFocusRect(aRect, rect);
|
|
|
|
|
|
|
|
gfx::DrawTarget* dt = aRenderingContext ? aRenderingContext->GetDrawTarget() : nullptr;
|
|
|
|
return nsCSSRendering::CreateBorderRenderer(aPresContext,
|
|
|
|
dt,
|
|
|
|
mFrame,
|
|
|
|
aDirtyRect,
|
|
|
|
rect,
|
2017-11-01 12:30:04 +03:00
|
|
|
mInnerFocusStyle,
|
|
|
|
aBorderIsEmpty);
|
2017-03-09 11:58:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult
|
2016-05-04 21:12:23 +03:00
|
|
|
nsButtonFrameRenderer::PaintBorder(
|
2015-10-23 05:54:48 +03:00
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsPresContext* aPresContext,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext& aRenderingContext,
|
2015-10-23 05:54:48 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aRect)
|
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
|
2017-03-08 19:31:46 +03:00
|
|
|
nsRect buttonRect = aRect;
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* context = mFrame->Style();
|
1999-02-19 21:23:02 +03:00
|
|
|
|
2015-10-23 05:54:48 +03:00
|
|
|
PaintBorderFlags borderFlags = aBuilder->ShouldSyncDecodeImages()
|
|
|
|
? PaintBorderFlags::SYNC_DECODE_IMAGES
|
|
|
|
: PaintBorderFlags();
|
|
|
|
|
2009-02-10 11:45:13 +03:00
|
|
|
nsCSSRendering::PaintBoxShadowInner(aPresContext, aRenderingContext,
|
2016-01-06 03:08:17 +03:00
|
|
|
mFrame, buttonRect);
|
2015-10-23 05:54:48 +03:00
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result =
|
2015-10-23 05:54:48 +03:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, mFrame,
|
|
|
|
aDirtyRect, buttonRect, context, borderFlags);
|
2015-02-10 10:27:40 +03:00
|
|
|
|
|
|
|
return result;
|
1999-02-26 09:41:10 +03:00
|
|
|
}
|
1999-02-19 21:23:02 +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
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* context = mFrame->Style();
|
2018-03-29 14:15:46 +03:00
|
|
|
ServoStyleSet* styleSet = aPresContext->StyleSet();
|
1999-02-26 09:41:10 +03:00
|
|
|
|
2018-04-07 01:39:26 +03:00
|
|
|
// get styles assigned to -moz-focus-inner (ie dotted border on Windows)
|
2009-12-11 10:37:40 +03:00
|
|
|
mInnerFocusStyle =
|
2010-04-30 17:12:06 +04:00
|
|
|
styleSet->ProbePseudoElementStyle(mFrame->GetContent()->AsElement(),
|
2016-02-17 01:07:00 +03:00
|
|
|
CSSPseudoElementType::mozFocusInner,
|
2009-12-11 10:37:40 +03:00
|
|
|
context);
|
1999-02-19 21:23:02 +03:00
|
|
|
}
|
1999-09-04 03:36:32 +04:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle*
|
|
|
|
nsButtonFrameRenderer::GetComputedStyle(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-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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
void
|
2018-03-22 21:20:41 +03:00
|
|
|
nsButtonFrameRenderer::SetComputedStyle(int32_t aIndex, ComputedStyle* aComputedStyle)
|
1999-09-04 03:36:32 +04:00
|
|
|
{
|
|
|
|
switch (aIndex) {
|
|
|
|
case NS_BUTTON_RENDERER_FOCUS_INNER_CONTEXT_INDEX:
|
2018-03-22 21:20:41 +03:00
|
|
|
mInnerFocusStyle = aComputedStyle;
|
1999-09-04 03:36:32 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|