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/. */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/* rendering object for list-item bullets */
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "nsBulletFrame.h"
|
2013-09-25 05:43:43 +04:00
|
|
|
|
2014-10-16 15:03:44 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2017-06-09 22:14:53 +03:00
|
|
|
#include "gfxContext.h"
|
2017-02-15 01:01:59 +03:00
|
|
|
#include "gfxPrefs.h"
|
2014-10-17 15:53:16 +04:00
|
|
|
#include "gfxUtils.h"
|
2014-10-16 15:03:44 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2017-01-24 11:53:42 +03:00
|
|
|
#include "mozilla/layers/LayersMessages.h"
|
2017-05-03 15:48:08 +03:00
|
|
|
#include "mozilla/layers/StackingContextHelper.h"
|
2017-10-03 23:31:08 +03:00
|
|
|
#include "mozilla/layers/WebRenderLayerManager.h"
|
2017-02-20 05:22:58 +03:00
|
|
|
#include "mozilla/layers/WebRenderMessages.h"
|
2014-01-28 18:15:24 +04:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2014-11-11 00:37:49 +03:00
|
|
|
#include "mozilla/Move.h"
|
2013-09-25 05:43:43 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2014-10-24 19:28:14 +04:00
|
|
|
#include "nsFontMetrics.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2005-01-12 22:45:38 +03:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-12-01 19:13:49 +03:00
|
|
|
#include "nsIPresShell.h"
|
1999-01-15 04:57:58 +03:00
|
|
|
#include "nsIDocument.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2013-02-22 22:13:37 +04:00
|
|
|
#include "nsCounterManager.h"
|
2014-05-30 12:00:26 +04:00
|
|
|
#include "nsBidiUtils.h"
|
2014-06-12 05:12:00 +04:00
|
|
|
#include "CounterStyleManager.h"
|
2017-05-03 15:48:07 +03:00
|
|
|
#include "UnitTransforms.h"
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
#include "imgIContainer.h"
|
2017-01-24 11:53:42 +03:00
|
|
|
#include "ImageLayers.h"
|
2012-10-12 16:43:01 +04:00
|
|
|
#include "imgRequestProxy.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "nsIURI.h"
|
2017-01-11 04:48:29 +03:00
|
|
|
#include "SVGImageContext.h"
|
2017-02-22 21:19:57 +03:00
|
|
|
#include "mozilla/layers/WebRenderBridgeChild.h"
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2011-03-28 17:59:54 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-24 06:48:23 +04:00
|
|
|
using namespace mozilla;
|
2014-10-16 15:03:44 +04:00
|
|
|
using namespace mozilla::gfx;
|
2015-02-05 00:50:56 +03:00
|
|
|
using namespace mozilla::image;
|
2011-11-24 06:48:23 +04:00
|
|
|
|
2016-01-28 06:23:59 +03:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(FontSizeInflationProperty, float)
|
2010-08-31 22:54:44 +04:00
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsBulletFrame)
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2014-01-18 11:08:22 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_QUERYFRAME_HEAD(nsBulletFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsBulletFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsFrame)
|
|
|
|
#endif
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
nsBulletFrame::~nsBulletFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2017-11-07 03:20:33 +03:00
|
|
|
nsBulletFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2014-11-11 00:37:49 +03:00
|
|
|
// Stop image loading first.
|
|
|
|
DeregisterAndCancelImageRequest();
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2011-12-24 12:28:23 +04:00
|
|
|
if (mListener) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener->SetFrame(nullptr);
|
2011-12-24 12:28:23 +04:00
|
|
|
}
|
1999-04-14 01:49:58 +04:00
|
|
|
|
|
|
|
// Let base class do the rest
|
2017-11-07 03:20:33 +03:00
|
|
|
nsFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2004-08-05 01:18:20 +04:00
|
|
|
nsBulletFrame::GetFrameName(nsAString& aResult) const
|
1999-04-14 01:49:58 +04:00
|
|
|
{
|
2004-08-05 01:18:20 +04:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Bullet"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-03-12 03:46:18 +03:00
|
|
|
nsBulletFrame::IsEmpty()
|
|
|
|
{
|
|
|
|
return IsSelfEmpty();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-01-24 11:53:42 +03:00
|
|
|
nsBulletFrame::IsSelfEmpty()
|
2008-03-12 03:46:18 +03:00
|
|
|
{
|
2017-05-13 14:42:23 +03:00
|
|
|
return StyleList()->mCounterStyle->IsNone();
|
2008-03-12 03:46:18 +03:00
|
|
|
}
|
|
|
|
|
2008-10-14 02:03:28 +04:00
|
|
|
/* virtual */ void
|
2008-10-26 13:11:34 +03:00
|
|
|
nsBulletFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
2004-08-05 01:18:20 +04:00
|
|
|
{
|
2008-10-26 13:11:34 +03:00
|
|
|
nsFrame::DidSetStyleContext(aOldStyleContext);
|
2008-10-14 02:03:28 +04:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
imgRequestProxy *newRequest = StyleList()->GetListStyleImage();
|
2004-08-05 01:18:20 +04:00
|
|
|
|
|
|
|
if (newRequest) {
|
1999-04-14 01:49:58 +04:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
if (!mListener) {
|
2011-12-24 12:28:23 +04:00
|
|
|
mListener = new nsBulletListener();
|
|
|
|
mListener->SetFrame(this);
|
1999-04-14 01:49:58 +04:00
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needNewRequest = true;
|
2004-08-05 01:18:20 +04:00
|
|
|
|
|
|
|
if (mImageRequest) {
|
|
|
|
// Reload the image, maybe...
|
|
|
|
nsCOMPtr<nsIURI> oldURI;
|
|
|
|
mImageRequest->GetURI(getter_AddRefs(oldURI));
|
|
|
|
nsCOMPtr<nsIURI> newURI;
|
|
|
|
newRequest->GetURI(getter_AddRefs(newURI));
|
|
|
|
if (oldURI && newURI) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool same;
|
2004-08-05 01:18:20 +04:00
|
|
|
newURI->Equals(oldURI, &same);
|
|
|
|
if (same) {
|
2011-10-17 18:59:28 +04:00
|
|
|
needNewRequest = false;
|
2004-08-05 01:18:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needNewRequest) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<imgRequestProxy> newRequestClone;
|
2017-07-19 21:15:11 +03:00
|
|
|
newRequest->SyncClone(mListener,
|
|
|
|
PresContext()->Document(),
|
|
|
|
getter_AddRefs(newRequestClone));
|
2013-04-12 21:05:57 +04:00
|
|
|
|
|
|
|
// Deregister the old request. We wait until after Clone is done in case
|
|
|
|
// the old request and the new request are the same underlying image
|
|
|
|
// accessed via different URLs.
|
2014-11-11 00:37:49 +03:00
|
|
|
DeregisterAndCancelImageRequest();
|
2013-04-12 21:05:57 +04:00
|
|
|
|
|
|
|
// Register the new request.
|
2014-11-11 00:37:49 +03:00
|
|
|
mImageRequest = Move(newRequestClone);
|
|
|
|
RegisterImageRequest(/* aKnownToBeAnimated = */ false);
|
2004-08-05 01:18:20 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-11-11 00:37:49 +03:00
|
|
|
// No image request on the new style context.
|
|
|
|
DeregisterAndCancelImageRequest();
|
1999-04-14 01:49:58 +04:00
|
|
|
}
|
2011-03-28 17:59:54 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
// Update the list bullet accessible. If old style list isn't available then
|
|
|
|
// no need to update the accessible tree because it's not created yet.
|
|
|
|
if (aOldStyleContext) {
|
|
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
|
|
|
if (accService) {
|
|
|
|
const nsStyleList* oldStyleList = aOldStyleContext->PeekStyleList();
|
|
|
|
if (oldStyleList) {
|
|
|
|
bool hadBullet = oldStyleList->GetListStyleImage() ||
|
2017-05-13 14:42:23 +03:00
|
|
|
!oldStyleList->mCounterStyle->IsNone();
|
2011-03-28 17:59:54 +04:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleList* newStyleList = StyleList();
|
2011-03-28 17:59:54 +04:00
|
|
|
bool hasBullet = newStyleList->GetListStyleImage() ||
|
2017-05-13 14:42:23 +03:00
|
|
|
!newStyleList->mCounterStyle->IsNone();
|
2011-03-28 17:59:54 +04:00
|
|
|
|
|
|
|
if (hadBullet != hasBullet) {
|
|
|
|
accService->UpdateListBullet(PresContext()->GetPresShell(), mContent,
|
|
|
|
hasBullet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1999-04-14 01:49:58 +04:00
|
|
|
}
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
class nsDisplayBulletGeometry
|
|
|
|
: public nsDisplayItemGenericGeometry
|
|
|
|
, public nsImageGeometryMixin<nsDisplayBulletGeometry>
|
2012-12-21 13:09:23 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDisplayBulletGeometry(nsDisplayItem* aItem, nsDisplayListBuilder* aBuilder)
|
|
|
|
: nsDisplayItemGenericGeometry(aItem, aBuilder)
|
2015-02-10 10:27:39 +03:00
|
|
|
, nsImageGeometryMixin(aItem, aBuilder)
|
2012-12-21 13:09:23 +04:00
|
|
|
{
|
2013-04-19 16:02:13 +04:00
|
|
|
nsBulletFrame* f = static_cast<nsBulletFrame*>(aItem->Frame());
|
2012-12-21 13:09:23 +04:00
|
|
|
mOrdinal = f->GetOrdinal();
|
|
|
|
}
|
|
|
|
|
2017-09-27 07:03:38 +03:00
|
|
|
virtual bool InvalidateForSyncDecodeImages() const override
|
|
|
|
{
|
|
|
|
return ShouldInvalidateToSyncDecodeImages();
|
|
|
|
}
|
|
|
|
|
2012-12-21 13:09:23 +04:00
|
|
|
int32_t mOrdinal;
|
|
|
|
};
|
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
class BulletRenderer final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BulletRenderer(imgIContainer* image, const nsRect& dest)
|
|
|
|
: mImage(image)
|
|
|
|
, mDest(dest)
|
|
|
|
, mListStyleType(NS_STYLE_LIST_STYLE_NONE)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsImageType());
|
|
|
|
}
|
|
|
|
|
|
|
|
BulletRenderer(Path* path, nscolor color, int32_t listStyleType)
|
|
|
|
: mColor(color)
|
|
|
|
, mPath(path)
|
|
|
|
, mListStyleType(listStyleType)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPathType());
|
|
|
|
}
|
|
|
|
|
2017-11-24 16:46:13 +03:00
|
|
|
BulletRenderer(const LayoutDeviceRect& aPathRect, nscolor color, int32_t listStyleType)
|
|
|
|
: mPathRect(aPathRect)
|
|
|
|
, mColor(color)
|
|
|
|
, mListStyleType(listStyleType)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPathType());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
BulletRenderer(const nsString& text,
|
|
|
|
nsFontMetrics* fm,
|
|
|
|
nscolor color,
|
|
|
|
const nsPoint& point,
|
|
|
|
int32_t listStyleType)
|
|
|
|
: mColor(color)
|
|
|
|
, mText(text)
|
|
|
|
, mFontMetrics(fm)
|
|
|
|
, mPoint(point)
|
|
|
|
, mListStyleType(listStyleType)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsTextType());
|
|
|
|
}
|
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
CreateWebRenderCommands(nsDisplayItem* aItem,
|
2017-03-03 18:45:29 +03:00
|
|
|
wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-06-28 23:39:34 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder);
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult
|
2017-06-09 22:14:53 +03:00
|
|
|
Paint(gfxContext& aRenderingContext, nsPoint aPt,
|
2017-01-24 11:53:42 +03:00
|
|
|
const nsRect& aDirtyRect, uint32_t aFlags,
|
2017-02-20 05:22:58 +03:00
|
|
|
bool aDisableSubpixelAA, nsIFrame* aFrame);
|
2017-01-24 11:53:42 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
IsImageType() const
|
|
|
|
{
|
|
|
|
return mListStyleType == NS_STYLE_LIST_STYLE_NONE && mImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsPathType() const
|
|
|
|
{
|
2017-11-24 16:46:13 +03:00
|
|
|
return mListStyleType == NS_STYLE_LIST_STYLE_DISC ||
|
|
|
|
mListStyleType == NS_STYLE_LIST_STYLE_CIRCLE ||
|
|
|
|
mListStyleType == NS_STYLE_LIST_STYLE_SQUARE ||
|
|
|
|
mListStyleType == NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN ||
|
|
|
|
mListStyleType == NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED;
|
2017-01-24 11:53:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsTextType() const
|
|
|
|
{
|
|
|
|
return mListStyleType != NS_STYLE_LIST_STYLE_NONE &&
|
|
|
|
mListStyleType != NS_STYLE_LIST_STYLE_DISC &&
|
|
|
|
mListStyleType != NS_STYLE_LIST_STYLE_CIRCLE &&
|
|
|
|
mListStyleType != NS_STYLE_LIST_STYLE_SQUARE &&
|
|
|
|
mListStyleType != NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN &&
|
|
|
|
mListStyleType != NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED &&
|
|
|
|
!mText.IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
BuildGlyphForText(nsDisplayItem* aItem, bool disableSubpixelAA);
|
2017-01-24 11:53:42 +03:00
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
void
|
|
|
|
PaintTextToContext(nsIFrame* aFrame,
|
|
|
|
gfxContext* aCtx,
|
|
|
|
bool aDisableSubpixelAA);
|
|
|
|
|
2017-02-20 05:22:58 +03:00
|
|
|
bool
|
|
|
|
IsImageContainerAvailable(layers::LayerManager* aManager, uint32_t aFlags);
|
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
private:
|
2017-10-17 23:05:29 +03:00
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
CreateWebRenderCommandsForImage(nsDisplayItem* aItem,
|
2017-05-03 15:48:07 +03:00
|
|
|
wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-06-28 23:39:34 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder);
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
CreateWebRenderCommandsForPath(nsDisplayItem* aItem,
|
2017-03-03 18:45:29 +03:00
|
|
|
wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-06-28 23:39:34 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder);
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
CreateWebRenderCommandsForText(nsDisplayItem* aItem,
|
2017-03-03 18:45:29 +03:00
|
|
|
wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-06-28 23:39:34 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder);
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
private:
|
|
|
|
// mImage and mDest are the properties for list-style-image.
|
|
|
|
// mImage is the image content and mDest is the image position.
|
|
|
|
RefPtr<imgIContainer> mImage;
|
|
|
|
nsRect mDest;
|
|
|
|
|
2017-11-24 16:46:13 +03:00
|
|
|
// Some bullet types are stored as a rect (in device pixels) instead of a Path to allow
|
|
|
|
// generating proper WebRender commands. When webrender is disabled the Path is lazily created
|
|
|
|
// for these items before painting.
|
|
|
|
// TODO: The size of this structure doesn't seem to be an issue since it has so many fields
|
|
|
|
// that are specific to a bullet style or another, but if it becomes one we can easily
|
|
|
|
// store mDest and mPathRect into the same memory location since they are never used by
|
|
|
|
// the same bullet types.
|
|
|
|
LayoutDeviceRect mPathRect;
|
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
// mColor indicate the color of list-style. Both text and path type would use this memeber.
|
|
|
|
nscolor mColor;
|
|
|
|
|
|
|
|
// mPath record the path of the list-style for later drawing.
|
|
|
|
// Included following types: square, circle, disc, disclosure open and disclosure closed.
|
|
|
|
RefPtr<Path> mPath;
|
|
|
|
|
|
|
|
// mText, mFontMertrics, mPoint, mFont and mGlyphs are for other
|
|
|
|
// list-style-type which can be drawed by text.
|
|
|
|
nsString mText;
|
|
|
|
RefPtr<nsFontMetrics> mFontMetrics;
|
|
|
|
nsPoint mPoint;
|
|
|
|
RefPtr<ScaledFont> mFont;
|
|
|
|
nsTArray<layers::GlyphArray> mGlyphs;
|
|
|
|
|
|
|
|
// Store the type of list-style-type.
|
|
|
|
int32_t mListStyleType;
|
|
|
|
};
|
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
BulletRenderer::CreateWebRenderCommands(nsDisplayItem* aItem,
|
2017-03-03 18:45:29 +03:00
|
|
|
wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-06-28 23:39:34 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
2017-02-20 05:22:58 +03:00
|
|
|
{
|
|
|
|
if (IsImageType()) {
|
2017-10-17 23:05:29 +03:00
|
|
|
return CreateWebRenderCommandsForImage(aItem, aBuilder, aResources,
|
2017-09-20 14:36:53 +03:00
|
|
|
aSc, aManager, aDisplayListBuilder);
|
2017-02-20 05:22:58 +03:00
|
|
|
} else if (IsPathType()) {
|
2017-10-17 23:05:29 +03:00
|
|
|
return CreateWebRenderCommandsForPath(aItem, aBuilder, aResources,
|
2017-09-20 14:36:53 +03:00
|
|
|
aSc, aManager, aDisplayListBuilder);
|
2017-02-20 05:22:58 +03:00
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(IsTextType());
|
2017-10-17 23:05:29 +03:00
|
|
|
return CreateWebRenderCommandsForText(aItem, aBuilder, aResources, aSc,
|
|
|
|
aManager, aDisplayListBuilder);
|
2017-02-20 05:22:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult
|
2017-06-09 22:14:53 +03:00
|
|
|
BulletRenderer::Paint(gfxContext& aRenderingContext, nsPoint aPt,
|
2017-02-20 05:22:58 +03:00
|
|
|
const nsRect& aDirtyRect, uint32_t aFlags,
|
|
|
|
bool aDisableSubpixelAA, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (IsImageType()) {
|
|
|
|
SamplingFilter filter = nsLayoutUtils::GetSamplingFilterForFrame(aFrame);
|
2017-06-09 22:14:53 +03:00
|
|
|
return nsLayoutUtils::DrawSingleImage(aRenderingContext,
|
2017-02-20 05:22:58 +03:00
|
|
|
aFrame->PresContext(), mImage, filter,
|
|
|
|
mDest, aDirtyRect,
|
|
|
|
/* no SVGImageContext */ Nothing(),
|
|
|
|
aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsPathType()) {
|
|
|
|
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
|
2017-11-24 16:46:13 +03:00
|
|
|
|
|
|
|
if (!mPath) {
|
|
|
|
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
|
|
|
|
switch (mListStyleType) {
|
|
|
|
case NS_STYLE_LIST_STYLE_CIRCLE:
|
|
|
|
case NS_STYLE_LIST_STYLE_DISC:
|
|
|
|
AppendEllipseToPath(builder, mPathRect.Center().ToUnknownPoint(), mPathRect.Size().ToUnknownSize());
|
|
|
|
break;
|
|
|
|
case NS_STYLE_LIST_STYLE_SQUARE:
|
|
|
|
AppendRectToPath(builder, mPathRect.ToUnknownRect());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT(false, "Should have a parth.");
|
|
|
|
}
|
|
|
|
mPath = builder->Finish();
|
|
|
|
}
|
|
|
|
|
2017-02-20 05:22:58 +03:00
|
|
|
switch (mListStyleType) {
|
|
|
|
case NS_STYLE_LIST_STYLE_CIRCLE:
|
|
|
|
drawTarget->Stroke(mPath, ColorPattern(ToDeviceColor(mColor)));
|
|
|
|
break;
|
|
|
|
case NS_STYLE_LIST_STYLE_DISC:
|
|
|
|
case NS_STYLE_LIST_STYLE_SQUARE:
|
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED:
|
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN:
|
|
|
|
drawTarget->Fill(mPath, ColorPattern(ToDeviceColor(mColor)));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("unreachable");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsTextType()) {
|
2017-10-17 23:05:29 +03:00
|
|
|
PaintTextToContext(aFrame, &aRenderingContext, aDisableSubpixelAA);
|
2017-02-20 05:22:58 +03:00
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-02-20 05:22:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BulletRenderer::BuildGlyphForText(nsDisplayItem* aItem, bool disableSubpixelAA)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsTextType());
|
|
|
|
|
2017-07-27 01:43:00 +03:00
|
|
|
RefPtr<DrawTarget> screenTarget = gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
|
2017-02-20 05:22:58 +03:00
|
|
|
RefPtr<DrawTargetCapture> capture =
|
2017-07-27 01:43:00 +03:00
|
|
|
Factory::CreateCaptureDrawTarget(screenTarget->GetBackendType(),
|
|
|
|
IntSize(),
|
|
|
|
screenTarget->GetFormat());
|
|
|
|
|
2017-02-20 05:22:58 +03:00
|
|
|
RefPtr<gfxContext> captureCtx = gfxContext::CreateOrNull(capture);
|
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
PaintTextToContext(aItem->Frame(), captureCtx, disableSubpixelAA);
|
2017-02-20 05:22:58 +03:00
|
|
|
|
|
|
|
layers::GlyphArray* g = mGlyphs.AppendElement();
|
|
|
|
std::vector<Glyph> glyphs;
|
|
|
|
Color color;
|
|
|
|
if (!capture->ContainsOnlyColoredGlyphs(mFont, color, glyphs)) {
|
|
|
|
mFont = nullptr;
|
|
|
|
mGlyphs.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
g->glyphs().SetLength(glyphs.size());
|
|
|
|
PodCopy(g->glyphs().Elements(), glyphs.data(), glyphs.size());
|
|
|
|
g->color() = color;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
void
|
|
|
|
BulletRenderer::PaintTextToContext(nsIFrame* aFrame,
|
|
|
|
gfxContext* aCtx,
|
|
|
|
bool aDisableSubpixelAA)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsTextType());
|
|
|
|
|
|
|
|
DrawTarget* drawTarget = aCtx->GetDrawTarget();
|
|
|
|
DrawTargetAutoDisableSubpixelAntialiasing
|
|
|
|
disable(drawTarget, aDisableSubpixelAA);
|
|
|
|
|
|
|
|
aCtx->SetColor(Color::FromABGR(mColor));
|
|
|
|
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
if (!presContext->BidiEnabled() && HasRTLChars(mText)) {
|
|
|
|
presContext->SetBidiEnabled();
|
|
|
|
}
|
|
|
|
nsLayoutUtils::DrawString(aFrame, *mFontMetrics, aCtx,
|
|
|
|
mText.get(), mText.Length(), mPoint);
|
|
|
|
}
|
|
|
|
|
2017-02-20 05:22:58 +03:00
|
|
|
bool
|
|
|
|
BulletRenderer::IsImageContainerAvailable(layers::LayerManager* aManager, uint32_t aFlags)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsImageType());
|
|
|
|
|
|
|
|
return mImage->IsImageContainerAvailable(aManager, aFlags);
|
|
|
|
}
|
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
BulletRenderer::CreateWebRenderCommandsForImage(nsDisplayItem* aItem,
|
2017-03-03 18:45:29 +03:00
|
|
|
wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-06-28 23:39:34 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
2017-02-20 05:22:58 +03:00
|
|
|
{
|
2017-10-17 23:05:29 +03:00
|
|
|
MOZ_RELEASE_ASSERT(IsImageType());
|
|
|
|
MOZ_RELEASE_ASSERT(mImage);
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-11-23 14:55:06 +03:00
|
|
|
uint32_t flags = imgIContainer::FLAG_ASYNC_NOTIFY;
|
|
|
|
if (aDisplayListBuilder->IsPaintingToWindow()) {
|
|
|
|
flags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
}
|
|
|
|
if (aDisplayListBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
2017-10-17 23:05:29 +03:00
|
|
|
}
|
|
|
|
|
2017-11-23 14:55:06 +03:00
|
|
|
const int32_t appUnitsPerDevPixel = aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
LayoutDeviceRect destRect = LayoutDeviceRect::FromAppUnits(mDest, appUnitsPerDevPixel);
|
|
|
|
Maybe<SVGImageContext> svgContext;
|
|
|
|
gfx::IntSize decodeSize =
|
|
|
|
nsLayoutUtils::ComputeImageContainerDrawingParameters(mImage, aItem->Frame(), destRect,
|
|
|
|
aSc, flags, svgContext);
|
2017-02-20 05:22:58 +03:00
|
|
|
RefPtr<layers::ImageContainer> container =
|
2017-11-23 14:55:06 +03:00
|
|
|
mImage->GetImageContainerAtSize(aManager, decodeSize, svgContext, flags);
|
2017-02-20 05:22:58 +03:00
|
|
|
if (!container) {
|
2017-10-17 23:05:29 +03:00
|
|
|
return false;
|
2017-02-20 05:22:58 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 23:39:34 +03:00
|
|
|
gfx::IntSize size;
|
2017-10-18 08:56:53 +03:00
|
|
|
Maybe<wr::ImageKey> key = aManager->CommandBuilder().CreateImageKey(aItem, container, aBuilder, aResources,
|
|
|
|
aSc, size, Nothing());
|
2017-04-14 03:13:12 +03:00
|
|
|
if (key.isNothing()) {
|
2017-10-17 23:05:29 +03:00
|
|
|
return true; // Nothing to do
|
2017-04-14 03:13:12 +03:00
|
|
|
}
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-08-31 12:59:41 +03:00
|
|
|
wr::LayoutRect dest = aSc.ToRelativeLayoutRect(destRect);
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-05-03 15:48:08 +03:00
|
|
|
aBuilder.PushImage(dest,
|
2017-06-26 14:49:52 +03:00
|
|
|
dest,
|
2017-09-21 09:41:38 +03:00
|
|
|
!aItem->BackfaceIsHidden(),
|
2017-07-19 10:28:58 +03:00
|
|
|
wr::ImageRendering::Auto,
|
2017-04-14 03:13:12 +03:00
|
|
|
key.value());
|
2017-10-17 23:05:29 +03:00
|
|
|
|
|
|
|
return true;
|
2017-02-20 05:22:58 +03:00
|
|
|
}
|
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
BulletRenderer::CreateWebRenderCommandsForPath(nsDisplayItem* aItem,
|
2017-03-03 18:45:29 +03:00
|
|
|
wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-06-28 23:39:34 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
2017-02-20 05:22:58 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsPathType());
|
2017-11-24 16:46:13 +03:00
|
|
|
wr::LayoutRect dest = aSc.ToRelativeLayoutRect(mPathRect);
|
|
|
|
auto color = wr::ToColorF(ToDeviceColor(mColor));
|
|
|
|
bool isBackfaceVisible = !aItem->BackfaceIsHidden();
|
|
|
|
switch (mListStyleType) {
|
|
|
|
case NS_STYLE_LIST_STYLE_CIRCLE: {
|
|
|
|
LayoutDeviceSize radii = mPathRect.Size() / 2.0;
|
|
|
|
auto borderWidths = wr::ToBorderWidths(1.0, 1.0, 1.0, 1.0);
|
|
|
|
wr::BorderSide side = { color, wr::BorderStyle::Solid };
|
|
|
|
wr::BorderSide sides[4] = { side, side, side, side };
|
|
|
|
Range<const wr::BorderSide> sidesRange(sides, 4);
|
|
|
|
aBuilder.PushBorder(dest, dest, isBackfaceVisible, borderWidths,
|
|
|
|
sidesRange,
|
|
|
|
wr::ToBorderRadius(radii, radii, radii, radii));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case NS_STYLE_LIST_STYLE_DISC: {
|
|
|
|
nsTArray<wr::ComplexClipRegion> clips;
|
|
|
|
clips.AppendElement(wr::ToComplexClipRegion(
|
|
|
|
RoundedRect(ThebesRect(mPathRect.ToUnknownRect()),
|
|
|
|
RectCornerRadii(dest.size.width / 2.0))
|
|
|
|
));
|
|
|
|
auto clipId = aBuilder.DefineClip(Nothing(), Nothing(), dest, &clips, nullptr);
|
|
|
|
aBuilder.PushClip(clipId);
|
|
|
|
aBuilder.PushRect(dest, dest, isBackfaceVisible, color);
|
|
|
|
aBuilder.PopClip();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case NS_STYLE_LIST_STYLE_SQUARE: {
|
|
|
|
aBuilder.PushRect(dest, dest, isBackfaceVisible, color);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if (!aManager->CommandBuilder().PushItemAsImage(aItem, aBuilder, aResources, aSc, aDisplayListBuilder)) {
|
|
|
|
NS_WARNING("Fail to create WebRender commands for Bullet path.");
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-18 09:26:41 +03:00
|
|
|
}
|
2017-10-17 23:05:29 +03:00
|
|
|
|
|
|
|
return true;
|
2017-02-20 05:22:58 +03:00
|
|
|
}
|
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
bool
|
2017-02-20 05:22:58 +03:00
|
|
|
BulletRenderer::CreateWebRenderCommandsForText(nsDisplayItem* aItem,
|
2017-03-03 18:45:29 +03:00
|
|
|
wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 15:48:07 +03:00
|
|
|
const layers::StackingContextHelper& aSc,
|
2017-06-28 23:39:34 +03:00
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
2017-02-20 05:22:58 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsTextType());
|
|
|
|
|
|
|
|
bool dummy;
|
2017-10-17 23:05:29 +03:00
|
|
|
nsRect bounds = aItem->GetBounds(aDisplayListBuilder, &dummy);
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
if (bounds.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-04 20:49:51 +03:00
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
RefPtr<TextDrawTarget> textDrawer = new TextDrawTarget(aBuilder, aSc, aManager, aItem, bounds);
|
|
|
|
RefPtr<gfxContext> captureCtx = gfxContext::CreateOrNull(textDrawer);
|
|
|
|
PaintTextToContext(aItem->Frame(), captureCtx, aItem);
|
|
|
|
textDrawer->TerminateShadows();
|
2017-10-04 20:49:51 +03:00
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
return !textDrawer->HasUnsupportedFeatures();
|
2017-02-20 05:22:58 +03:00
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsDisplayBullet final : public nsDisplayItem {
|
2006-01-26 05:29:17 +03:00
|
|
|
public:
|
2016-05-31 21:56:22 +03:00
|
|
|
nsDisplayBullet(nsDisplayListBuilder* aBuilder, nsBulletFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
{
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayBullet);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayBullet() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayBullet);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
2011-01-03 04:48:09 +03:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2011-10-21 21:45:32 +04:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
2017-01-24 11:53:42 +03:00
|
|
|
|
|
|
|
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters) override;
|
|
|
|
|
|
|
|
virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters) override;
|
|
|
|
|
2017-06-28 23:39:34 +03:00
|
|
|
virtual bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue&,
|
2017-06-28 23:39:34 +03:00
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) override;
|
2017-02-20 05:22:58 +03:00
|
|
|
|
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);
|
|
|
|
}
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx) override;
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("Bullet", TYPE_BULLET)
|
2010-10-11 04:58:20 +04:00
|
|
|
|
2017-08-24 18:09:44 +03:00
|
|
|
virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) const override
|
2011-01-03 04:48:09 +03:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
bool snap;
|
|
|
|
return GetBounds(aBuilder, &snap);
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
2012-12-21 13:09:23 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override
|
2012-12-21 13:09:23 +04:00
|
|
|
{
|
|
|
|
return new nsDisplayBulletGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2017-08-24 18:09:44 +03:00
|
|
|
nsRegion *aInvalidRegion) const override
|
2012-12-21 13:09:23 +04:00
|
|
|
{
|
|
|
|
const nsDisplayBulletGeometry* geometry = static_cast<const nsDisplayBulletGeometry*>(aGeometry);
|
|
|
|
nsBulletFrame* f = static_cast<nsBulletFrame*>(mFrame);
|
|
|
|
|
|
|
|
if (f->GetOrdinal() != geometry->mOrdinal) {
|
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(geometry->mBounds, GetBounds(aBuilder, &snap));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-22 20:30:57 +04:00
|
|
|
nsCOMPtr<imgIContainer> image = f->GetImage();
|
2015-02-05 00:50:56 +03:00
|
|
|
if (aBuilder->ShouldSyncDecodeImages() && image &&
|
2015-02-10 10:27:39 +03:00
|
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
2013-06-22 20:30:57 +04:00
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
|
|
|
|
2012-12-21 13:09:23 +04:00
|
|
|
return nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
2016-05-31 21:56:22 +03:00
|
|
|
|
|
|
|
protected:
|
2017-01-24 11:53:42 +03:00
|
|
|
Maybe<BulletRenderer> mBulletRenderer;
|
2006-01-26 05:29:17 +03:00
|
|
|
};
|
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
LayerState
|
|
|
|
nsDisplayBullet::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters)
|
|
|
|
{
|
2017-04-21 18:11:38 +03:00
|
|
|
if (!ShouldUseAdvancedLayer(aManager, gfxPrefs::LayersAllowBulletLayers)) {
|
2017-01-24 11:53:42 +03:00
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
2017-08-09 13:00:01 +03:00
|
|
|
RefPtr<gfxContext> screenRefCtx = gfxContext::CreateOrNull(
|
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget().get());
|
2017-01-24 11:53:42 +03:00
|
|
|
|
|
|
|
Maybe<BulletRenderer> br = static_cast<nsBulletFrame*>(mFrame)->
|
2017-06-09 22:14:53 +03:00
|
|
|
CreateBulletRenderer(*screenRefCtx, ToReferenceFrame());
|
2017-01-24 11:53:42 +03:00
|
|
|
|
|
|
|
if (!br) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
|
|
|
|
2017-02-20 05:22:58 +03:00
|
|
|
if (br->IsImageType()) {
|
|
|
|
uint32_t flags = aBuilder->ShouldSyncDecodeImages()
|
|
|
|
? imgIContainer::FLAG_SYNC_DECODE
|
|
|
|
: imgIContainer::FLAG_NONE;
|
|
|
|
|
|
|
|
if (!br->IsImageContainerAvailable(aManager, flags)) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
if (br->IsTextType()) {
|
|
|
|
if (!br->BuildGlyphForText(this, mDisableSubpixelAA)) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mBulletRenderer = br;
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<layers::Layer>
|
|
|
|
nsDisplayBullet::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
|
|
|
{
|
|
|
|
if (!mBulletRenderer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-02-20 05:22:58 +03:00
|
|
|
return BuildDisplayItemLayer(aBuilder, aManager, aContainerParameters);
|
|
|
|
}
|
|
|
|
|
2017-06-28 23:39:34 +03:00
|
|
|
bool
|
|
|
|
nsDisplayBullet::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder,
|
2017-09-14 19:48:55 +03:00
|
|
|
wr::IpcResourceUpdateQueue& aResources,
|
2017-06-28 23:39:34 +03:00
|
|
|
const StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aDisplayListBuilder)
|
2017-02-20 05:22:58 +03:00
|
|
|
{
|
2017-10-17 23:05:29 +03:00
|
|
|
// FIXME: avoid needing to make this target if we're drawing text
|
|
|
|
// (non-trivial refactor of all this code)
|
|
|
|
RefPtr<gfxContext> screenRefCtx = gfxContext::CreateOrNull(
|
|
|
|
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget().get());
|
|
|
|
Maybe<BulletRenderer> br = static_cast<nsBulletFrame*>(mFrame)->
|
|
|
|
CreateBulletRenderer(*screenRefCtx, ToReferenceFrame());
|
2017-02-20 05:22:58 +03:00
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
if (!br) {
|
2017-10-19 20:53:57 +03:00
|
|
|
return false;
|
2017-10-17 23:05:29 +03:00
|
|
|
}
|
2017-10-19 20:53:57 +03:00
|
|
|
|
2017-10-17 23:05:29 +03:00
|
|
|
return br->CreateWebRenderCommands(this, aBuilder, aResources, aSc,
|
|
|
|
aManager, aDisplayListBuilder);
|
2017-01-24 11:53:42 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void nsDisplayBullet::Paint(nsDisplayListBuilder* aBuilder,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext* aCtx)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2013-05-30 03:23:31 +04:00
|
|
|
uint32_t flags = imgIContainer::FLAG_NONE;
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
2015-02-05 00:50:56 +03:00
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result = static_cast<nsBulletFrame*>(mFrame)->
|
2016-05-31 21:56:22 +03:00
|
|
|
PaintBullet(*aCtx, ToReferenceFrame(), mVisibleRect, flags,
|
|
|
|
mDisableSubpixelAA);
|
2015-02-05 00:50:56 +03:00
|
|
|
|
|
|
|
nsDisplayBulletGeometry::UpdateDrawResult(this, result);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsBulletFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2006-01-26 05:29:17 +03:00
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2006-09-19 08:26:20 +04:00
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsBulletFrame");
|
2017-01-24 11:53:42 +03:00
|
|
|
|
2017-12-13 20:23:04 +03:00
|
|
|
aLists.Content()->AppendToTop(
|
2013-02-14 15:08:08 +04:00
|
|
|
new (aBuilder) nsDisplayBullet(aBuilder, this));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
1998-12-18 18:54:23 +03:00
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
Maybe<BulletRenderer>
|
2017-06-09 22:14:53 +03:00
|
|
|
nsBulletFrame::CreateBulletRenderer(gfxContext& aRenderingContext, nsPoint aPt)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleList* myList = StyleList();
|
2017-05-13 14:42:23 +03:00
|
|
|
CounterStyle* listStyleType = myList->mCounterStyle;
|
2014-07-24 12:30:07 +04:00
|
|
|
nsMargin padding = mPadding.GetPhysicalMargin(GetWritingMode());
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
if (myList->GetListStyleImage() && mImageRequest) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t status;
|
2006-01-26 05:29:17 +03:00
|
|
|
mImageRequest->GetImageStatus(&status);
|
|
|
|
if (status & imgIRequest::STATUS_LOAD_COMPLETE &&
|
|
|
|
!(status & imgIRequest::STATUS_ERROR)) {
|
|
|
|
nsCOMPtr<imgIContainer> imageCon;
|
|
|
|
mImageRequest->GetImage(getter_AddRefs(imageCon));
|
|
|
|
if (imageCon) {
|
2014-07-24 12:30:07 +04:00
|
|
|
nsRect dest(padding.left, padding.top,
|
|
|
|
mRect.width - (padding.left + padding.right),
|
|
|
|
mRect.height - (padding.top + padding.bottom));
|
2017-01-24 11:53:42 +03:00
|
|
|
BulletRenderer br(imageCon, dest + aPt);
|
|
|
|
return Some(br);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
nscolor color = nsLayoutUtils::GetColor(this, &nsStyleColor::mColor);
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2014-10-19 14:55:36 +04:00
|
|
|
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
|
|
|
|
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
2014-06-12 05:12:00 +04:00
|
|
|
switch (listStyleType->GetStyle()) {
|
2006-01-26 05:29:17 +03:00
|
|
|
case NS_STYLE_LIST_STYLE_NONE:
|
2017-01-24 11:53:42 +03:00
|
|
|
return Nothing();
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
case NS_STYLE_LIST_STYLE_DISC:
|
|
|
|
case NS_STYLE_LIST_STYLE_CIRCLE:
|
2014-10-16 15:03:44 +04:00
|
|
|
{
|
|
|
|
nsRect rect(padding.left + aPt.x,
|
|
|
|
padding.top + aPt.y,
|
|
|
|
mRect.width - (padding.left + padding.right),
|
|
|
|
mRect.height - (padding.top + padding.bottom));
|
2017-11-24 16:46:13 +03:00
|
|
|
auto devPxRect = LayoutDeviceRect::FromAppUnits(rect, appUnitsPerDevPixel);
|
|
|
|
return Some(BulletRenderer(devPxRect, color, listStyleType->GetStyle()));
|
2014-10-16 15:03:44 +04:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
case NS_STYLE_LIST_STYLE_SQUARE:
|
2010-02-18 20:26:54 +03:00
|
|
|
{
|
2011-04-19 07:07:22 +04:00
|
|
|
nsRect rect(aPt, mRect.Size());
|
2014-07-24 12:30:07 +04:00
|
|
|
rect.Deflate(padding);
|
2011-04-19 07:07:22 +04:00
|
|
|
|
2010-02-18 20:26:54 +03:00
|
|
|
// Snap the height and the width of the rectangle to device pixels,
|
|
|
|
// and then center the result within the original rectangle, so that
|
|
|
|
// all square bullets at the same font size have the same visual
|
|
|
|
// size (bug 376690).
|
|
|
|
// FIXME: We should really only do this if we're not transformed
|
|
|
|
// (like gfxContext::UserToDevicePixelSnapped does).
|
|
|
|
nsPresContext *pc = PresContext();
|
2017-01-24 11:53:42 +03:00
|
|
|
nsRect snapRect(rect.x, rect.y,
|
2010-02-18 20:26:54 +03:00
|
|
|
pc->RoundAppUnitsToNearestDevPixels(rect.width),
|
|
|
|
pc->RoundAppUnitsToNearestDevPixels(rect.height));
|
|
|
|
snapRect.MoveBy((rect.width - snapRect.width) / 2,
|
|
|
|
(rect.height - snapRect.height) / 2);
|
2017-11-24 16:46:13 +03:00
|
|
|
auto devPxRect = LayoutDeviceRect::FromAppUnits(snapRect, appUnitsPerDevPixel);
|
|
|
|
return Some(BulletRenderer(devPxRect, color, listStyleType->GetStyle()));
|
2010-02-18 20:26:54 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2014-06-13 19:34:00 +04:00
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED:
|
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN:
|
|
|
|
{
|
|
|
|
nsRect rect(aPt, mRect.Size());
|
2014-07-24 12:30:07 +04:00
|
|
|
rect.Deflate(padding);
|
2014-06-13 19:34:00 +04:00
|
|
|
|
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
bool isVertical = wm.IsVertical();
|
|
|
|
bool isClosed =
|
|
|
|
listStyleType->GetStyle() == NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED;
|
|
|
|
bool isDown = (!isVertical && !isClosed) || (isVertical && isClosed);
|
|
|
|
nscoord diff = NSToCoordRound(0.1f * rect.height);
|
|
|
|
if (isDown) {
|
|
|
|
rect.y += diff * 2;
|
|
|
|
rect.height -= diff * 2;
|
|
|
|
} else {
|
|
|
|
rect.Deflate(diff, 0);
|
|
|
|
}
|
|
|
|
nsPresContext *pc = PresContext();
|
|
|
|
rect.x = pc->RoundAppUnitsToNearestDevPixels(rect.x);
|
|
|
|
rect.y = pc->RoundAppUnitsToNearestDevPixels(rect.y);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
|
2014-06-13 19:34:00 +04:00
|
|
|
if (isDown) {
|
|
|
|
// to bottom
|
2014-10-17 18:06:34 +04:00
|
|
|
builder->MoveTo(NSPointToPoint(rect.TopLeft(), appUnitsPerDevPixel));
|
|
|
|
builder->LineTo(NSPointToPoint(rect.TopRight(), appUnitsPerDevPixel));
|
|
|
|
builder->LineTo(NSPointToPoint((rect.BottomLeft() + rect.BottomRight()) / 2,
|
|
|
|
appUnitsPerDevPixel));
|
2014-06-13 19:34:00 +04:00
|
|
|
} else {
|
|
|
|
bool isLR = isVertical ? wm.IsVerticalLR() : wm.IsBidiLTR();
|
|
|
|
if (isLR) {
|
|
|
|
// to right
|
2014-10-17 18:06:34 +04:00
|
|
|
builder->MoveTo(NSPointToPoint(rect.TopLeft(), appUnitsPerDevPixel));
|
|
|
|
builder->LineTo(NSPointToPoint((rect.TopRight() + rect.BottomRight()) / 2,
|
|
|
|
appUnitsPerDevPixel));
|
|
|
|
builder->LineTo(NSPointToPoint(rect.BottomLeft(), appUnitsPerDevPixel));
|
2014-06-13 19:34:00 +04:00
|
|
|
} else {
|
|
|
|
// to left
|
2014-10-17 18:06:34 +04:00
|
|
|
builder->MoveTo(NSPointToPoint(rect.TopRight(), appUnitsPerDevPixel));
|
|
|
|
builder->LineTo(NSPointToPoint(rect.BottomRight(), appUnitsPerDevPixel));
|
|
|
|
builder->LineTo(NSPointToPoint((rect.TopLeft() + rect.BottomLeft()) / 2,
|
|
|
|
appUnitsPerDevPixel));
|
2014-06-13 19:34:00 +04:00
|
|
|
}
|
|
|
|
}
|
2017-01-24 11:53:42 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Path> path = builder->Finish();
|
2017-01-24 11:53:42 +03:00
|
|
|
BulletRenderer br(path, color, listStyleType->GetStyle());
|
|
|
|
return Some(br);
|
2014-06-13 19:34:00 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 05:12:00 +04:00
|
|
|
default:
|
2015-01-06 23:56:03 +03:00
|
|
|
{
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, GetFontSizeInflation());
|
2015-01-06 23:56:03 +03:00
|
|
|
nsAutoString text;
|
|
|
|
GetListItemText(text);
|
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
nscoord ascent = wm.IsLineInverted()
|
|
|
|
? fm->MaxDescent() : fm->MaxAscent();
|
|
|
|
aPt.MoveBy(padding.left, padding.top);
|
|
|
|
if (wm.IsVertical()) {
|
2015-02-11 13:59:06 +03:00
|
|
|
if (wm.IsVerticalLR()) {
|
|
|
|
aPt.x = NSToCoordRound(nsLayoutUtils::GetSnappedBaselineX(
|
2017-06-09 22:14:53 +03:00
|
|
|
this, &aRenderingContext, aPt.x, ascent));
|
2015-02-11 13:59:06 +03:00
|
|
|
} else {
|
|
|
|
aPt.x = NSToCoordRound(nsLayoutUtils::GetSnappedBaselineX(
|
2017-06-09 22:14:53 +03:00
|
|
|
this, &aRenderingContext, aPt.x + mRect.width,
|
2015-02-11 13:59:06 +03:00
|
|
|
-ascent));
|
|
|
|
}
|
2015-01-06 23:56:03 +03:00
|
|
|
} else {
|
|
|
|
aPt.y = NSToCoordRound(nsLayoutUtils::GetSnappedBaselineY(
|
2017-06-09 22:14:53 +03:00
|
|
|
this, &aRenderingContext, aPt.y, ascent));
|
2015-01-06 23:56:03 +03:00
|
|
|
}
|
2017-01-24 11:53:42 +03:00
|
|
|
|
|
|
|
BulletRenderer br(text, fm, color, aPt, listStyleType->GetStyle());
|
|
|
|
return Some(br);
|
2014-05-30 12:00:26 +04:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2015-02-05 00:50:56 +03:00
|
|
|
|
2017-01-24 11:53:42 +03:00
|
|
|
MOZ_CRASH("unreachable");
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult
|
2017-06-09 22:14:53 +03:00
|
|
|
nsBulletFrame::PaintBullet(gfxContext& aRenderingContext, nsPoint aPt,
|
2017-01-24 11:53:42 +03:00
|
|
|
const nsRect& aDirtyRect, uint32_t aFlags,
|
|
|
|
bool aDisableSubpixelAA)
|
|
|
|
{
|
|
|
|
Maybe<BulletRenderer> br = CreateBulletRenderer(aRenderingContext, aPt);
|
|
|
|
|
|
|
|
if (!br) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-01-24 11:53:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return br->Paint(aRenderingContext, aPt, aDirtyRect,
|
|
|
|
aFlags, aDisableSubpixelAA, this);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
|
|
|
nsBulletFrame::SetListItemOrdinal(int32_t aNextOrdinal,
|
2012-09-08 06:30:24 +04:00
|
|
|
bool* aChanged,
|
|
|
|
int32_t aIncrement)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2012-09-08 06:30:24 +04:00
|
|
|
MOZ_ASSERT(aIncrement == 1 || aIncrement == -1,
|
|
|
|
"We shouldn't have weird increments here");
|
|
|
|
|
1999-09-16 23:56:00 +04:00
|
|
|
// Assume that the ordinal comes from the caller
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t oldOrdinal = mOrdinal;
|
1998-12-01 19:13:49 +03:00
|
|
|
mOrdinal = aNextOrdinal;
|
|
|
|
|
|
|
|
// Try to get value directly from the list-item, if it specifies a
|
|
|
|
// value attribute. Note: we do this with our parent's content
|
|
|
|
// because our parent is the list-item.
|
2014-05-25 02:20:41 +04:00
|
|
|
nsIContent* parentContent = GetParent()->GetContent();
|
1999-09-16 23:56:00 +04:00
|
|
|
if (parentContent) {
|
2005-01-12 22:45:38 +03:00
|
|
|
nsGenericHTMLElement *hc =
|
|
|
|
nsGenericHTMLElement::FromContent(parentContent);
|
1999-09-16 23:56:00 +04:00
|
|
|
if (hc) {
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* attr = hc->GetParsedAttr(nsGkAtoms::value);
|
2005-01-25 03:02:58 +03:00
|
|
|
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
|
|
|
// Use ordinal specified by the value attribute
|
|
|
|
mOrdinal = attr->GetIntegerValue();
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-16 23:56:00 +04:00
|
|
|
|
|
|
|
*aChanged = oldOrdinal != mOrdinal;
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2013-02-22 22:13:37 +04:00
|
|
|
return nsCounterManager::IncrementCounter(mOrdinal, aIncrement);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2013-12-02 21:51:25 +04:00
|
|
|
void
|
2014-06-12 05:12:00 +04:00
|
|
|
nsBulletFrame::GetListItemText(nsAString& aResult)
|
2005-04-02 03:07:00 +04:00
|
|
|
{
|
2017-05-13 14:42:23 +03:00
|
|
|
CounterStyle* style = StyleList()->mCounterStyle;
|
2014-06-12 05:12:00 +04:00
|
|
|
NS_ASSERTION(style->GetStyle() != NS_STYLE_LIST_STYLE_NONE &&
|
|
|
|
style->GetStyle() != NS_STYLE_LIST_STYLE_DISC &&
|
|
|
|
style->GetStyle() != NS_STYLE_LIST_STYLE_CIRCLE &&
|
2014-06-13 19:34:00 +04:00
|
|
|
style->GetStyle() != NS_STYLE_LIST_STYLE_SQUARE &&
|
|
|
|
style->GetStyle() != NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED &&
|
|
|
|
style->GetStyle() != NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN,
|
2005-04-02 03:07:00 +04:00
|
|
|
"we should be using specialized code for these types");
|
|
|
|
|
2014-05-30 12:00:26 +04:00
|
|
|
bool isRTL;
|
2014-06-12 05:12:00 +04:00
|
|
|
nsAutoString counter, prefix, suffix;
|
|
|
|
style->GetPrefix(prefix);
|
|
|
|
style->GetSuffix(suffix);
|
2014-06-13 19:34:00 +04:00
|
|
|
style->GetCounterText(mOrdinal, GetWritingMode(), counter, isRTL);
|
2014-05-30 12:00:26 +04:00
|
|
|
|
2014-06-12 05:12:00 +04:00
|
|
|
aResult.Truncate();
|
|
|
|
aResult.Append(prefix);
|
2014-05-30 12:00:26 +04:00
|
|
|
if (GetWritingMode().IsBidiLTR() != isRTL) {
|
2014-06-12 05:12:00 +04:00
|
|
|
aResult.Append(counter);
|
2014-05-30 12:00:26 +04:00
|
|
|
} else {
|
|
|
|
// RLM = 0x200f, LRM = 0x200e
|
|
|
|
char16_t mark = isRTL ? 0x200f : 0x200e;
|
2014-06-12 05:12:00 +04:00
|
|
|
aResult.Append(mark);
|
|
|
|
aResult.Append(counter);
|
|
|
|
aResult.Append(mark);
|
2014-05-30 12:00:26 +04:00
|
|
|
}
|
2014-06-12 05:12:00 +04:00
|
|
|
aResult.Append(suffix);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2005-06-21 01:25:41 +04:00
|
|
|
#define MIN_BULLET_SIZE 1
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2014-06-13 19:34:00 +04:00
|
|
|
void
|
2015-03-12 12:53:54 +03:00
|
|
|
nsBulletFrame::AppendSpacingToPadding(nsFontMetrics* aFontMetrics,
|
|
|
|
LogicalMargin* aPadding)
|
2014-06-13 19:34:00 +04:00
|
|
|
{
|
2015-03-12 12:53:54 +03:00
|
|
|
aPadding->IEnd(GetWritingMode()) += aFontMetrics->EmHeight() / 2;
|
2014-06-13 19:34:00 +04:00
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBulletFrame::GetDesiredSize(nsPresContext* aCX,
|
2017-06-09 22:14:53 +03:00
|
|
|
gfxContext *aRenderingContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aMetrics,
|
2015-03-12 12:53:54 +03:00
|
|
|
float aFontSizeInflation,
|
|
|
|
LogicalMargin* aPadding)
|
1998-12-01 19:13:49 +03:00
|
|
|
{
|
2004-04-01 23:48:55 +04:00
|
|
|
// Reset our padding. If we need it, we'll set it below.
|
2014-07-24 12:30:07 +04:00
|
|
|
WritingMode wm = GetWritingMode();
|
2015-03-12 12:53:54 +03:00
|
|
|
aPadding->SizeTo(wm, 0, 0, 0, 0);
|
2014-07-24 12:30:07 +04:00
|
|
|
LogicalSize finalSize(wm);
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleList* myList = StyleList();
|
1998-12-01 19:13:49 +03:00
|
|
|
nscoord ascent;
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, aFontSizeInflation);
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2010-08-31 22:54:44 +04:00
|
|
|
RemoveStateBits(BULLET_FRAME_IMAGE_LOADING);
|
|
|
|
|
2009-12-11 07:02:13 +03:00
|
|
|
if (myList->GetListStyleImage() && mImageRequest) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t status;
|
2002-11-06 04:58:22 +03:00
|
|
|
mImageRequest->GetImageStatus(&status);
|
|
|
|
if (status & imgIRequest::STATUS_SIZE_AVAILABLE &&
|
|
|
|
!(status & imgIRequest::STATUS_ERROR)) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// auto size the image
|
2014-07-24 12:30:07 +04:00
|
|
|
finalSize.ISize(wm) = mIntrinsicSize.ISize(wm);
|
|
|
|
aMetrics.SetBlockStartAscent(finalSize.BSize(wm) =
|
|
|
|
mIntrinsicSize.BSize(wm));
|
|
|
|
aMetrics.SetSize(wm, finalSize);
|
2002-11-06 04:58:22 +03:00
|
|
|
|
2015-03-12 12:53:54 +03:00
|
|
|
AppendSpacingToPadding(fm, aPadding);
|
2014-06-04 13:18:52 +04:00
|
|
|
|
2010-08-31 22:54:44 +04:00
|
|
|
AddStateBits(BULLET_FRAME_IMAGE_LOADING);
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-02 18:35:32 +04:00
|
|
|
// If we're getting our desired size and don't have an image, reset
|
|
|
|
// mIntrinsicSize to (0,0). Otherwise, if we used to have an image, it
|
|
|
|
// changed, and the new one is coming in, but we're reflowing before it's
|
|
|
|
// fully there, we'll end up with mIntrinsicSize not matching our size, but
|
|
|
|
// won't trigger a reflow in OnStartContainer (because mIntrinsicSize will
|
|
|
|
// match the image size).
|
2014-07-24 12:30:07 +04:00
|
|
|
mIntrinsicSize.SizeTo(wm, 0, 0);
|
2005-08-02 18:35:32 +04:00
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
nscoord bulletSize;
|
|
|
|
|
|
|
|
nsAutoString text;
|
2017-05-13 14:42:23 +03:00
|
|
|
switch (myList->mCounterStyle->GetStyle()) {
|
1999-07-03 02:27:03 +04:00
|
|
|
case NS_STYLE_LIST_STYLE_NONE:
|
2014-07-24 12:30:07 +04:00
|
|
|
finalSize.ISize(wm) = finalSize.BSize(wm) = 0;
|
2014-06-11 13:45:31 +04:00
|
|
|
aMetrics.SetBlockStartAscent(0);
|
1999-07-03 02:27:03 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_LIST_STYLE_DISC:
|
|
|
|
case NS_STYLE_LIST_STYLE_CIRCLE:
|
2014-05-30 12:00:26 +04:00
|
|
|
case NS_STYLE_LIST_STYLE_SQUARE: {
|
2011-04-08 08:18:43 +04:00
|
|
|
ascent = fm->MaxAscent();
|
2013-01-15 16:22:03 +04:00
|
|
|
bulletSize = std::max(nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE),
|
2007-02-07 10:46:44 +03:00
|
|
|
NSToCoordRound(0.8f * (float(ascent) / 2.0f)));
|
2015-03-12 12:53:54 +03:00
|
|
|
aPadding->BEnd(wm) = NSToCoordRound(float(ascent) / 8.0f);
|
2014-07-24 12:30:07 +04:00
|
|
|
finalSize.ISize(wm) = finalSize.BSize(wm) = bulletSize;
|
2015-03-12 12:53:54 +03:00
|
|
|
aMetrics.SetBlockStartAscent(bulletSize + aPadding->BEnd(wm));
|
|
|
|
AppendSpacingToPadding(fm, aPadding);
|
2014-06-13 19:34:00 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-05-30 12:00:26 +04:00
|
|
|
|
2014-06-13 19:34:00 +04:00
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED:
|
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN:
|
|
|
|
ascent = fm->EmAscent();
|
|
|
|
bulletSize = std::max(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE),
|
|
|
|
NSToCoordRound(0.75f * ascent));
|
2015-03-12 12:53:54 +03:00
|
|
|
aPadding->BEnd(wm) = NSToCoordRound(0.125f * ascent);
|
2014-07-24 12:30:07 +04:00
|
|
|
finalSize.ISize(wm) = finalSize.BSize(wm) = bulletSize;
|
|
|
|
if (!wm.IsVertical()) {
|
2015-03-12 12:53:54 +03:00
|
|
|
aMetrics.SetBlockStartAscent(bulletSize + aPadding->BEnd(wm));
|
2014-05-30 12:00:26 +04:00
|
|
|
}
|
2015-03-12 12:53:54 +03:00
|
|
|
AppendSpacingToPadding(fm, aPadding);
|
1999-07-03 02:27:03 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-06-12 05:12:00 +04:00
|
|
|
GetListItemText(text);
|
2014-07-24 12:30:07 +04:00
|
|
|
finalSize.BSize(wm) = fm->MaxHeight();
|
|
|
|
finalSize.ISize(wm) =
|
2015-12-16 00:56:41 +03:00
|
|
|
nsLayoutUtils::AppUnitWidthOfStringBidi(text, this, *fm, *aRenderingContext);
|
2015-01-06 23:56:03 +03:00
|
|
|
aMetrics.SetBlockStartAscent(wm.IsLineInverted()
|
|
|
|
? fm->MaxDescent() : fm->MaxAscent());
|
1999-07-03 02:27:03 +04:00
|
|
|
break;
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
2014-07-24 12:30:07 +04:00
|
|
|
aMetrics.SetSize(wm, finalSize);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBulletFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aMetrics,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
1998-12-01 19:13:49 +03:00
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsBulletFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aMetrics, aStatus);
|
2017-09-13 13:00:25 +03:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "The reflow status should be empty!");
|
2002-05-10 22:22:41 +04:00
|
|
|
|
2012-05-21 09:18:28 +04:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2011-11-24 06:48:23 +04:00
|
|
|
SetFontSizeInflation(inflation);
|
|
|
|
|
1998-12-01 19:13:49 +03:00
|
|
|
// Get the base size
|
2016-07-21 13:36:39 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowInput.mRenderingContext, aMetrics, inflation,
|
2015-12-16 00:56:41 +03:00
|
|
|
&mPadding);
|
1998-12-01 19:13:49 +03:00
|
|
|
|
|
|
|
// Add in the border and padding; split the top/bottom between the
|
|
|
|
// ascent and descent to make things look nice
|
2016-07-21 13:36:39 +03:00
|
|
|
WritingMode wm = aReflowInput.GetWritingMode();
|
|
|
|
const LogicalMargin& bp = aReflowInput.ComputedLogicalBorderPadding();
|
2014-07-24 12:30:07 +04:00
|
|
|
mPadding.BStart(wm) += NSToCoordRound(bp.BStart(wm) * inflation);
|
|
|
|
mPadding.IEnd(wm) += NSToCoordRound(bp.IEnd(wm) * inflation);
|
|
|
|
mPadding.BEnd(wm) += NSToCoordRound(bp.BEnd(wm) * inflation);
|
|
|
|
mPadding.IStart(wm) += NSToCoordRound(bp.IStart(wm) * inflation);
|
|
|
|
|
|
|
|
WritingMode lineWM = aMetrics.GetWritingMode();
|
|
|
|
LogicalMargin linePadding = mPadding.ConvertTo(lineWM, wm);
|
|
|
|
aMetrics.ISize(lineWM) += linePadding.IStartEnd(lineWM);
|
|
|
|
aMetrics.BSize(lineWM) += linePadding.BStartEnd(lineWM);
|
|
|
|
aMetrics.SetBlockStartAscent(aMetrics.BlockStartAscent() +
|
|
|
|
linePadding.BStart(lineWM));
|
1998-12-01 19:13:49 +03:00
|
|
|
|
2007-09-24 06:19:14 +04:00
|
|
|
// XXX this is a bit of a hack, we're assuming that no glyphs used for bullets
|
|
|
|
// overflow their font-boxes. It'll do for now; to fix it for real, we really
|
|
|
|
// should rewrite all the text-handling code here to use gfxTextRun (bug
|
|
|
|
// 397294).
|
2010-10-07 08:25:46 +04:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aMetrics);
|
1998-12-01 19:13:49 +03:00
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* virtual */ nscoord
|
2017-06-09 22:14:53 +03:00
|
|
|
nsBulletFrame::GetMinISize(gfxContext *aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
2014-07-24 12:30:07 +04:00
|
|
|
WritingMode wm = GetWritingMode();
|
2016-07-26 12:10:52 +03:00
|
|
|
ReflowOutput reflowOutput(wm);
|
|
|
|
DISPLAY_MIN_WIDTH(this, reflowOutput.ISize(wm));
|
2015-03-12 12:53:54 +03:00
|
|
|
LogicalMargin padding(wm);
|
2016-07-26 12:10:52 +03:00
|
|
|
GetDesiredSize(PresContext(), aRenderingContext, reflowOutput, 1.0f, &padding);
|
|
|
|
reflowOutput.ISize(wm) += padding.IStartEnd(wm);
|
|
|
|
return reflowOutput.ISize(wm);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2017-06-09 22:14:53 +03:00
|
|
|
nsBulletFrame::GetPrefISize(gfxContext *aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
2014-07-24 12:30:07 +04:00
|
|
|
WritingMode wm = GetWritingMode();
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput metrics(wm);
|
2014-07-24 12:30:07 +04:00
|
|
|
DISPLAY_PREF_WIDTH(this, metrics.ISize(wm));
|
2015-03-12 12:53:54 +03:00
|
|
|
LogicalMargin padding(wm);
|
|
|
|
GetDesiredSize(PresContext(), aRenderingContext, metrics, 1.0f, &padding);
|
|
|
|
metrics.ISize(wm) += padding.IStartEnd(wm);
|
2014-07-24 12:30:07 +04:00
|
|
|
return metrics.ISize(wm);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
2016-04-14 02:32:12 +03:00
|
|
|
// If a bullet has zero size and is "ignorable" from its styling, we behave
|
|
|
|
// as if it doesn't exist, from a line-breaking/isize-computation perspective.
|
|
|
|
// Otherwise, we use the default implementation, same as nsFrame.
|
|
|
|
static inline bool
|
|
|
|
IsIgnoreable(const nsIFrame* aFrame, nscoord aISize)
|
|
|
|
{
|
|
|
|
if (aISize != nscoord(0)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto listStyle = aFrame->StyleList();
|
2017-05-13 14:42:23 +03:00
|
|
|
return listStyle->mCounterStyle->IsNone() &&
|
2016-04-14 02:32:12 +03:00
|
|
|
!listStyle->GetListStyleImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2017-06-09 22:14:53 +03:00
|
|
|
nsBulletFrame::AddInlineMinISize(gfxContext* aRenderingContext,
|
2016-04-14 02:32:12 +03:00
|
|
|
nsIFrame::InlineMinISizeData* aData)
|
|
|
|
{
|
|
|
|
nscoord isize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
this, nsLayoutUtils::MIN_ISIZE);
|
|
|
|
if (MOZ_LIKELY(!::IsIgnoreable(this, isize))) {
|
|
|
|
aData->DefaultAddInlineMinISize(this, isize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2017-06-09 22:14:53 +03:00
|
|
|
nsBulletFrame::AddInlinePrefISize(gfxContext* aRenderingContext,
|
2016-04-14 02:32:12 +03:00
|
|
|
nsIFrame::InlinePrefISizeData* aData)
|
|
|
|
{
|
|
|
|
nscoord isize = nsLayoutUtils::IntrinsicForContainer(aRenderingContext,
|
|
|
|
this, nsLayoutUtils::PREF_ISIZE);
|
|
|
|
if (MOZ_LIKELY(!::IsIgnoreable(this, isize))) {
|
|
|
|
aData->DefaultAddInlinePrefISize(isize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBulletFrame::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData)
|
|
|
|
{
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
2014-11-18 01:29:56 +03:00
|
|
|
return OnSizeAvailable(aRequest, image);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::FRAME_UPDATE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
// The image has changed.
|
|
|
|
// Invalidate the entire content area. Maybe it's not optimal but it's simple and
|
|
|
|
// always correct, and I'll be a stunned mullet if it ever matters for performance
|
|
|
|
InvalidateFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aType == imgINotificationObserver::IS_ANIMATED) {
|
|
|
|
// Register the image request with the refresh driver now that we know it's
|
|
|
|
// animated.
|
|
|
|
if (aRequest == mImageRequest) {
|
2014-11-11 00:37:49 +03:00
|
|
|
RegisterImageRequest(/* aKnownToBeAnimated = */ true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
|
|
|
|
// Unconditionally start decoding for now.
|
|
|
|
// XXX(seth): We eventually want to decide whether to do this based on
|
|
|
|
// visibility. We should get that for free from bug 1091236.
|
2015-10-30 02:37:42 +03:00
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
aRequest->GetImage(getter_AddRefs(container));
|
|
|
|
if (container) {
|
|
|
|
// Retrieve the intrinsic size of the image.
|
|
|
|
int32_t width = 0;
|
|
|
|
int32_t height = 0;
|
|
|
|
container->GetWidth(&width);
|
|
|
|
container->GetHeight(&height);
|
|
|
|
|
|
|
|
// Request a decode at that size.
|
|
|
|
container->RequestDecodeForSize(IntSize(width, height),
|
|
|
|
imgIContainer::DECODE_FLAGS_DEFAULT);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
2015-10-30 02:37:42 +03:00
|
|
|
|
2014-11-11 00:37:49 +03:00
|
|
|
InvalidateFrame();
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
|
|
|
|
2015-06-03 20:42:07 +03:00
|
|
|
if (aType == imgINotificationObserver::DECODE_COMPLETE) {
|
|
|
|
if (nsIDocument* parent = GetOurCurrentDoc()) {
|
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
aRequest->GetImage(getter_AddRefs(container));
|
|
|
|
if (container) {
|
|
|
|
container->PropagateUseCounters(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2014-11-11 00:37:49 +03:00
|
|
|
nsIDocument*
|
|
|
|
nsBulletFrame::GetOurCurrentDoc() const
|
|
|
|
{
|
|
|
|
nsIContent* parentContent = GetParent()->GetContent();
|
|
|
|
return parentContent ? parentContent->GetComposedDoc()
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-18 01:29:56 +03:00
|
|
|
nsresult
|
|
|
|
nsBulletFrame::OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage)
|
2001-08-10 00:22:39 +04:00
|
|
|
{
|
|
|
|
if (!aImage) return NS_ERROR_INVALID_ARG;
|
2002-11-06 04:58:22 +03:00
|
|
|
if (!aRequest) return NS_ERROR_INVALID_ARG;
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t status;
|
2002-11-06 04:58:22 +03:00
|
|
|
aRequest->GetImageStatus(&status);
|
|
|
|
if (status & imgIRequest::STATUS_ERROR) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-01-24 11:53:42 +03:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
nscoord w, h;
|
|
|
|
aImage->GetWidth(&w);
|
|
|
|
aImage->GetHeight(&h);
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* presContext = PresContext();
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2014-07-24 12:30:07 +04:00
|
|
|
LogicalSize newsize(GetWritingMode(),
|
|
|
|
nsSize(nsPresContext::CSSPixelsToAppUnits(w),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(h)));
|
2001-08-10 00:22:39 +04:00
|
|
|
|
|
|
|
if (mIntrinsicSize != newsize) {
|
|
|
|
mIntrinsicSize = newsize;
|
|
|
|
|
|
|
|
// Now that the size is available (or an error occurred), trigger
|
|
|
|
// a reflow of the bullet frame.
|
2004-08-05 01:18:20 +04:00
|
|
|
nsIPresShell *shell = presContext->GetPresShell();
|
2003-12-21 08:36:36 +03:00
|
|
|
if (shell) {
|
2007-05-06 23:16:51 +04:00
|
|
|
shell->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2001-08-10 00:22:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-08 21:29:28 +03:00
|
|
|
// Handle animations
|
2004-08-05 01:18:20 +04:00
|
|
|
aImage->SetAnimationMode(presContext->ImageAnimationMode());
|
2010-09-08 04:33:02 +04:00
|
|
|
// Ensure the animation (if any) is started. Note: There is no
|
|
|
|
// corresponding call to Decrement for this. This Increment will be
|
|
|
|
// 'cleaned up' by the Request when it is destroyed, but only then.
|
|
|
|
aRequest->IncrementAnimationConsumers();
|
2017-01-24 11:53:42 +03:00
|
|
|
|
2001-08-10 00:22:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsBulletFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGroup)
|
2001-08-10 00:22:39 +04:00
|
|
|
{
|
|
|
|
if (!aPresContext)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aLoadGroup, "null OUT parameter pointer");
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2003-12-21 08:36:36 +03:00
|
|
|
nsIPresShell *shell = aPresContext->GetPresShell();
|
2001-08-10 00:22:39 +04:00
|
|
|
|
|
|
|
if (!shell)
|
|
|
|
return;
|
|
|
|
|
2004-08-02 08:52:55 +04:00
|
|
|
nsIDocument *doc = shell->GetDocument();
|
2001-08-10 00:22:39 +04:00
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
2014-03-15 23:00:15 +04:00
|
|
|
*aLoadGroup = doc->GetDocumentLoadGroup().take();
|
2001-08-10 00:22:39 +04:00
|
|
|
}
|
|
|
|
|
2011-11-24 06:48:23 +04:00
|
|
|
float
|
|
|
|
nsBulletFrame::GetFontSizeInflation() const
|
|
|
|
{
|
|
|
|
if (!HasFontSizeInflation()) {
|
|
|
|
return 1.0f;
|
|
|
|
}
|
2017-05-27 14:36:00 +03:00
|
|
|
return GetProperty(FontSizeInflationProperty());
|
2011-11-24 06:48:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBulletFrame::SetFontSizeInflation(float aInflation)
|
|
|
|
{
|
|
|
|
if (aInflation == 1.0f) {
|
|
|
|
if (HasFontSizeInflation()) {
|
|
|
|
RemoveStateBits(BULLET_FRAME_HAS_FONT_INFLATION);
|
2017-05-27 14:36:00 +03:00
|
|
|
DeleteProperty(FontSizeInflationProperty());
|
2011-11-24 06:48:23 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddStateBits(BULLET_FRAME_HAS_FONT_INFLATION);
|
2017-05-27 14:36:00 +03:00
|
|
|
SetProperty(FontSizeInflationProperty(), aInflation);
|
2011-11-24 06:48:23 +04:00
|
|
|
}
|
|
|
|
|
2013-06-22 20:30:57 +04:00
|
|
|
already_AddRefed<imgIContainer>
|
|
|
|
nsBulletFrame::GetImage() const
|
|
|
|
{
|
|
|
|
if (mImageRequest && StyleList()->GetListStyleImage()) {
|
|
|
|
nsCOMPtr<imgIContainer> imageCon;
|
|
|
|
mImageRequest->GetImage(getter_AddRefs(imageCon));
|
|
|
|
return imageCon.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2010-08-31 22:54:44 +04:00
|
|
|
nscoord
|
2014-06-17 16:19:38 +04:00
|
|
|
nsBulletFrame::GetLogicalBaseline(WritingMode aWritingMode) const
|
2010-08-31 22:54:44 +04:00
|
|
|
{
|
2014-07-24 12:30:07 +04:00
|
|
|
nscoord ascent = 0, baselinePadding;
|
2010-08-31 22:54:44 +04:00
|
|
|
if (GetStateBits() & BULLET_FRAME_IMAGE_LOADING) {
|
2014-06-17 16:19:38 +04:00
|
|
|
ascent = BSize(aWritingMode);
|
2010-08-31 22:54:44 +04:00
|
|
|
} else {
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, GetFontSizeInflation());
|
2017-05-13 14:42:23 +03:00
|
|
|
CounterStyle* listStyleType = StyleList()->mCounterStyle;
|
2014-06-12 05:12:00 +04:00
|
|
|
switch (listStyleType->GetStyle()) {
|
2010-08-31 22:54:44 +04:00
|
|
|
case NS_STYLE_LIST_STYLE_NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_LIST_STYLE_DISC:
|
|
|
|
case NS_STYLE_LIST_STYLE_CIRCLE:
|
|
|
|
case NS_STYLE_LIST_STYLE_SQUARE:
|
2011-04-08 08:18:43 +04:00
|
|
|
ascent = fm->MaxAscent();
|
2014-07-24 12:30:07 +04:00
|
|
|
baselinePadding = NSToCoordRound(float(ascent) / 8.0f);
|
2013-01-15 16:22:03 +04:00
|
|
|
ascent = std::max(nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE),
|
2010-08-31 22:54:44 +04:00
|
|
|
NSToCoordRound(0.8f * (float(ascent) / 2.0f)));
|
2014-07-24 12:30:07 +04:00
|
|
|
ascent += baselinePadding;
|
2010-08-31 22:54:44 +04:00
|
|
|
break;
|
|
|
|
|
2014-06-13 19:34:00 +04:00
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED:
|
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN:
|
|
|
|
ascent = fm->EmAscent();
|
2014-07-24 12:30:07 +04:00
|
|
|
baselinePadding = NSToCoordRound(0.125f * ascent);
|
2014-06-13 19:34:00 +04:00
|
|
|
ascent = std::max(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE),
|
|
|
|
NSToCoordRound(0.75f * ascent));
|
2014-07-24 12:30:07 +04:00
|
|
|
ascent += baselinePadding;
|
2014-06-13 19:34:00 +04:00
|
|
|
break;
|
|
|
|
|
2010-08-31 22:54:44 +04:00
|
|
|
default:
|
2011-04-08 08:18:43 +04:00
|
|
|
ascent = fm->MaxAscent();
|
2010-08-31 22:54:44 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-17 16:19:38 +04:00
|
|
|
return ascent +
|
|
|
|
GetLogicalUsedMargin(aWritingMode).BStart(aWritingMode);
|
2010-08-31 22:54:44 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 05:12:00 +04:00
|
|
|
void
|
|
|
|
nsBulletFrame::GetSpokenText(nsAString& aText)
|
|
|
|
{
|
2017-05-13 14:42:23 +03:00
|
|
|
CounterStyle* style = StyleList()->mCounterStyle;
|
2014-06-12 05:12:00 +04:00
|
|
|
bool isBullet;
|
2014-06-13 19:34:00 +04:00
|
|
|
style->GetSpokenCounterText(mOrdinal, GetWritingMode(), aText, isBullet);
|
2014-06-12 05:12:00 +04:00
|
|
|
if (isBullet) {
|
2014-10-24 03:10:00 +04:00
|
|
|
if (!style->IsNone()) {
|
|
|
|
aText.Append(' ');
|
|
|
|
}
|
2014-06-12 05:12:00 +04:00
|
|
|
} else {
|
|
|
|
nsAutoString prefix, suffix;
|
|
|
|
style->GetPrefix(prefix);
|
|
|
|
style->GetSuffix(suffix);
|
|
|
|
aText = prefix + aText + suffix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-11 00:37:49 +03:00
|
|
|
void
|
|
|
|
nsBulletFrame::RegisterImageRequest(bool aKnownToBeAnimated)
|
|
|
|
{
|
|
|
|
if (mImageRequest) {
|
|
|
|
// mRequestRegistered is a bitfield; unpack it temporarily so we can take
|
|
|
|
// the address.
|
|
|
|
bool isRequestRegistered = mRequestRegistered;
|
|
|
|
|
|
|
|
if (aKnownToBeAnimated) {
|
|
|
|
nsLayoutUtils::RegisterImageRequest(PresContext(), mImageRequest,
|
|
|
|
&isRequestRegistered);
|
|
|
|
} else {
|
|
|
|
nsLayoutUtils::RegisterImageRequestIfAnimated(PresContext(),
|
|
|
|
mImageRequest,
|
|
|
|
&isRequestRegistered);
|
|
|
|
}
|
|
|
|
|
|
|
|
isRequestRegistered = mRequestRegistered;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBulletFrame::DeregisterAndCancelImageRequest()
|
|
|
|
{
|
|
|
|
if (mImageRequest) {
|
|
|
|
// mRequestRegistered is a bitfield; unpack it temporarily so we can take
|
|
|
|
// the address.
|
|
|
|
bool isRequestRegistered = mRequestRegistered;
|
|
|
|
|
|
|
|
// Deregister our image request from the refresh driver.
|
|
|
|
nsLayoutUtils::DeregisterImageRequest(PresContext(),
|
|
|
|
mImageRequest,
|
|
|
|
&isRequestRegistered);
|
|
|
|
|
|
|
|
isRequestRegistered = mRequestRegistered;
|
2001-08-10 00:22:39 +04:00
|
|
|
|
2014-11-11 00:37:49 +03:00
|
|
|
// Cancel the image request and forget about it.
|
|
|
|
mImageRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
|
|
|
|
mImageRequest = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2001-08-10 00:22:39 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsBulletListener, imgINotificationObserver)
|
2001-08-10 00:22:39 +04:00
|
|
|
|
|
|
|
nsBulletListener::nsBulletListener() :
|
2012-07-30 18:20:58 +04:00
|
|
|
mFrame(nullptr)
|
2001-08-10 00:22:39 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBulletListener::~nsBulletListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBulletListener::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData)
|
2001-08-10 00:22:39 +04:00
|
|
|
{
|
2014-11-11 00:37:49 +03:00
|
|
|
if (!mFrame) {
|
2001-08-10 00:22:39 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-11-11 00:37:49 +03:00
|
|
|
}
|
2012-10-12 20:11:22 +04:00
|
|
|
return mFrame->Notify(aRequest, aType, aData);
|
2001-08-10 00:22:39 +04:00
|
|
|
}
|