2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* rendering object for list-item bullets */
|
|
|
|
|
|
|
|
#include "nsBulletFrame.h"
|
2013-09-24 18:43:43 -07:00
|
|
|
|
2014-10-16 04:03:44 -07:00
|
|
|
#include "gfx2DGlue.h"
|
2014-10-17 04:53:16 -07:00
|
|
|
#include "gfxUtils.h"
|
2014-10-16 04:03:44 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2014-01-28 06:15:24 -08:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2014-11-10 13:37:49 -08:00
|
|
|
#include "mozilla/Move.h"
|
2013-09-24 18:43:43 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2014-10-24 08:28:14 -07:00
|
|
|
#include "nsFontMetrics.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDocument.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDisplayList.h"
|
2013-02-22 10:13:37 -08:00
|
|
|
#include "nsCounterManager.h"
|
2014-05-30 01:00:26 -07:00
|
|
|
#include "nsBidiUtils.h"
|
2014-06-11 18:12:00 -07:00
|
|
|
#include "CounterStyleManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
2012-10-12 05:43:01 -07:00
|
|
|
#include "imgRequestProxy.h"
|
2013-09-07 06:01:08 -07:00
|
|
|
#include "nsIURI.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-28 06:59:54 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
using namespace mozilla;
|
2014-10-16 04:03:44 -07:00
|
|
|
using namespace mozilla::gfx;
|
2011-11-23 18:48:23 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_DECLARE_FRAME_PROPERTY(FontSizeInflationProperty, nullptr)
|
2010-08-31 11:54:44 -07:00
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsBulletFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-17 23:08:22 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_QUERYFRAME_HEAD(nsBulletFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsBulletFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsFrame)
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBulletFrame::~nsBulletFrame()
|
|
|
|
{
|
2014-11-10 13:37:49 -08:00
|
|
|
NS_ASSERTION(!mBlockingOnload, "Still blocking onload in destructor?");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsBulletFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-11-10 13:37:49 -08:00
|
|
|
// Stop image loading first.
|
|
|
|
DeregisterAndCancelImageRequest();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-24 00:28:23 -08:00
|
|
|
if (mListener) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mListener->SetFrame(nullptr);
|
2011-12-24 00:28:23 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Let base class do the rest
|
2009-12-23 21:21:15 -08:00
|
|
|
nsFrame::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBulletFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("Bullet"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsBulletFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::bulletFrame;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-03-11 17:46:18 -07:00
|
|
|
nsBulletFrame::IsEmpty()
|
|
|
|
{
|
|
|
|
return IsSelfEmpty();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-03-11 17:46:18 -07:00
|
|
|
nsBulletFrame::IsSelfEmpty()
|
|
|
|
{
|
2014-06-11 18:12:00 -07:00
|
|
|
return StyleList()->GetCounterStyle()->IsNone();
|
2008-03-11 17:46:18 -07:00
|
|
|
}
|
|
|
|
|
2008-10-13 15:03:28 -07:00
|
|
|
/* virtual */ void
|
2008-10-26 03:11:34 -07:00
|
|
|
nsBulletFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-26 03:11:34 -07:00
|
|
|
nsFrame::DidSetStyleContext(aOldStyleContext);
|
2008-10-13 15:03:28 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
imgRequestProxy *newRequest = StyleList()->GetListStyleImage();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (newRequest) {
|
|
|
|
|
|
|
|
if (!mListener) {
|
2011-12-24 00:28:23 -08:00
|
|
|
mListener = new nsBulletListener();
|
|
|
|
mListener->SetFrame(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needNewRequest = true;
|
2007-03-22 10:30:00 -07: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-28 23:19:26 -07:00
|
|
|
bool same;
|
2007-03-22 10:30:00 -07:00
|
|
|
newURI->Equals(oldURI, &same);
|
|
|
|
if (same) {
|
2011-10-17 07:59:28 -07:00
|
|
|
needNewRequest = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needNewRequest) {
|
2014-11-10 13:37:49 -08:00
|
|
|
nsRefPtr<imgRequestProxy> newRequestClone;
|
|
|
|
newRequest->Clone(mListener, getter_AddRefs(newRequestClone));
|
2013-04-12 10:05:57 -07: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-10 13:37:49 -08:00
|
|
|
DeregisterAndCancelImageRequest();
|
2013-04-12 10:05:57 -07:00
|
|
|
|
|
|
|
// Register the new request.
|
2014-11-10 13:37:49 -08:00
|
|
|
mImageRequest = Move(newRequestClone);
|
|
|
|
RegisterImageRequest(/* aKnownToBeAnimated = */ false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
2014-11-10 13:37:49 -08:00
|
|
|
// No image request on the new style context.
|
|
|
|
DeregisterAndCancelImageRequest();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-03-28 06:59:54 -07: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() ||
|
2014-06-11 18:12:00 -07:00
|
|
|
!oldStyleList->GetCounterStyle()->IsNone();
|
2011-03-28 06:59:54 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleList* newStyleList = StyleList();
|
2011-03-28 06:59:54 -07:00
|
|
|
bool hasBullet = newStyleList->GetListStyleImage() ||
|
2014-06-11 18:12:00 -07:00
|
|
|
!newStyleList->GetCounterStyle()->IsNone();
|
2011-03-28 06:59:54 -07:00
|
|
|
|
|
|
|
if (hadBullet != hasBullet) {
|
|
|
|
accService->UpdateListBullet(PresContext()->GetPresShell(), mContent,
|
|
|
|
hasBullet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-21 01:09:23 -08:00
|
|
|
class nsDisplayBulletGeometry : public nsDisplayItemGenericGeometry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDisplayBulletGeometry(nsDisplayItem* aItem, nsDisplayListBuilder* aBuilder)
|
|
|
|
: nsDisplayItemGenericGeometry(aItem, aBuilder)
|
|
|
|
{
|
2013-04-19 05:02:13 -07:00
|
|
|
nsBulletFrame* f = static_cast<nsBulletFrame*>(aItem->Frame());
|
2012-12-21 01:09:23 -08:00
|
|
|
mOrdinal = f->GetOrdinal();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t mOrdinal;
|
|
|
|
};
|
|
|
|
|
2014-08-05 10:33:55 -07:00
|
|
|
class nsDisplayBullet MOZ_FINAL : public nsDisplayItem {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayBullet(nsDisplayListBuilder* aBuilder, nsBulletFrame* aFrame) :
|
|
|
|
nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayBullet);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayBullet() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayBullet);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) MOZ_OVERRIDE
|
2011-01-02 17:48:09 -08:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2011-10-21 10:45:32 -07:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
2010-04-07 17:31:26 -07:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
2014-02-24 06:41:56 -08:00
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE {
|
2010-04-07 17:31:26 -07:00
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("Bullet", TYPE_BULLET)
|
2010-10-10 17:58:20 -07:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsRect GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
|
2011-01-02 17:48:09 -08:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
|
|
|
return GetBounds(aBuilder, &snap);
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
2012-12-21 01:09:23 -08:00
|
|
|
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
|
2012-12-21 01:09:23 -08:00
|
|
|
{
|
|
|
|
return new nsDisplayBulletGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2014-02-24 06:41:56 -08:00
|
|
|
nsRegion *aInvalidRegion) MOZ_OVERRIDE
|
2012-12-21 01:09:23 -08: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 09:30:57 -07:00
|
|
|
nsCOMPtr<imgIContainer> image = f->GetImage();
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages() && image && !image->IsDecoded()) {
|
|
|
|
// If we are going to do a sync decode and we are not decoded then we are
|
|
|
|
// going to be drawing something different from what is currently there,
|
|
|
|
// so we add our bounds to the invalid region.
|
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
|
|
|
|
2012-12-21 01:09:23 -08:00
|
|
|
return nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayBullet::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-05-29 16:23:31 -07:00
|
|
|
uint32_t flags = imgIContainer::FLAG_NONE;
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
flags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsBulletFrame*>(mFrame)->
|
2013-05-29 16:23:31 -07:00
|
|
|
PaintBullet(*aCtx, ToReferenceFrame(), mVisibleRect, flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBulletFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsBulletFrame");
|
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
aLists.Content()->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayBullet(aBuilder, this));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
|
2013-05-29 16:23:31 -07:00
|
|
|
const nsRect& aDirtyRect, uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleList* myList = StyleList();
|
2014-06-11 18:12:00 -07:00
|
|
|
CounterStyle* listStyleType = myList->GetCounterStyle();
|
2014-07-24 01:30:07 -07:00
|
|
|
nsMargin padding = mPadding.GetPhysicalMargin(GetWritingMode());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-10 20:02:13 -08:00
|
|
|
if (myList->GetListStyleImage() && mImageRequest) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t status;
|
2007-03-22 10:30:00 -07: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 01:30:07 -07:00
|
|
|
nsRect dest(padding.left, padding.top,
|
|
|
|
mRect.width - (padding.left + padding.right),
|
|
|
|
mRect.height - (padding.top + padding.bottom));
|
2014-11-01 03:45:09 -07:00
|
|
|
nsLayoutUtils::DrawSingleImage(*aRenderingContext.ThebesContext(),
|
|
|
|
PresContext(),
|
2009-04-05 02:52:14 -07:00
|
|
|
imageCon, nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
2013-05-29 16:23:31 -07:00
|
|
|
dest + aPt, aDirtyRect, nullptr, aFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-07 18:05:49 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
2014-10-17 04:53:16 -07:00
|
|
|
ColorPattern color(ToDeviceColor(
|
|
|
|
nsLayoutUtils::GetColor(this, eCSSProperty_color)));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-10-19 03:55:36 -07:00
|
|
|
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
|
|
|
|
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString text;
|
2014-06-11 18:12:00 -07:00
|
|
|
switch (listStyleType->GetStyle()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_STYLE_LIST_STYLE_NONE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_LIST_STYLE_DISC:
|
|
|
|
case NS_STYLE_LIST_STYLE_CIRCLE:
|
2014-10-16 04:03:44 -07:00
|
|
|
{
|
|
|
|
nsRect rect(padding.left + aPt.x,
|
|
|
|
padding.top + aPt.y,
|
|
|
|
mRect.width - (padding.left + padding.right),
|
|
|
|
mRect.height - (padding.top + padding.bottom));
|
2014-11-21 07:48:05 -08:00
|
|
|
Rect devPxRect = NSRectToRect(rect, appUnitsPerDevPixel);
|
2014-10-16 04:03:44 -07:00
|
|
|
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
|
|
|
|
AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size());
|
|
|
|
RefPtr<Path> ellipse = builder->Finish();
|
|
|
|
if (listStyleType->GetStyle() == NS_STYLE_LIST_STYLE_DISC) {
|
2014-10-17 04:53:16 -07:00
|
|
|
drawTarget->Fill(ellipse, color);
|
2014-10-16 04:03:44 -07:00
|
|
|
} else {
|
2014-10-17 04:53:16 -07:00
|
|
|
drawTarget->Stroke(ellipse, color);
|
2014-10-16 04:03:44 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_LIST_STYLE_SQUARE:
|
2010-02-18 09:26:54 -08:00
|
|
|
{
|
2011-04-18 20:07:22 -07:00
|
|
|
nsRect rect(aPt, mRect.Size());
|
2014-07-24 01:30:07 -07:00
|
|
|
rect.Deflate(padding);
|
2011-04-18 20:07:22 -07:00
|
|
|
|
2010-02-18 09:26:54 -08: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();
|
|
|
|
nsRect snapRect(rect.x, rect.y,
|
|
|
|
pc->RoundAppUnitsToNearestDevPixels(rect.width),
|
|
|
|
pc->RoundAppUnitsToNearestDevPixels(rect.height));
|
|
|
|
snapRect.MoveBy((rect.width - snapRect.width) / 2,
|
|
|
|
(rect.height - snapRect.height) / 2);
|
2014-10-22 04:29:06 -07:00
|
|
|
Rect devPxRect =
|
|
|
|
NSRectToSnappedRect(snapRect, appUnitsPerDevPixel, *drawTarget);
|
2014-10-19 03:55:36 -07:00
|
|
|
drawTarget->FillRect(devPxRect, color);
|
2010-02-18 09:26:54 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
2014-06-13 08:34:00 -07:00
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED:
|
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN:
|
|
|
|
{
|
|
|
|
nsRect rect(aPt, mRect.Size());
|
2014-07-24 01:30:07 -07:00
|
|
|
rect.Deflate(padding);
|
2014-06-13 08:34:00 -07: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);
|
|
|
|
|
2014-10-17 07:06:34 -07:00
|
|
|
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
|
2014-06-13 08:34:00 -07:00
|
|
|
if (isDown) {
|
|
|
|
// to bottom
|
2014-10-17 07:06:34 -07: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 08:34:00 -07:00
|
|
|
} else {
|
|
|
|
bool isLR = isVertical ? wm.IsVerticalLR() : wm.IsBidiLTR();
|
|
|
|
if (isLR) {
|
|
|
|
// to right
|
2014-10-17 07:06:34 -07: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 08:34:00 -07:00
|
|
|
} else {
|
|
|
|
// to left
|
2014-10-17 07:06:34 -07: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 08:34:00 -07:00
|
|
|
}
|
|
|
|
}
|
2014-10-17 07:06:34 -07:00
|
|
|
RefPtr<Path> path = builder->Finish();
|
|
|
|
drawTarget->Fill(path, color);
|
2014-06-13 08:34:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-06-11 18:12:00 -07:00
|
|
|
default:
|
2014-10-20 02:55:49 -07:00
|
|
|
aRenderingContext.ThebesContext()->SetColor(
|
|
|
|
nsLayoutUtils::GetColor(this, eCSSProperty_color));
|
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
|
|
|
|
GetFontSizeInflation());
|
2014-06-11 18:12:00 -07:00
|
|
|
GetListItemText(text);
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord ascent = fm->MaxAscent();
|
2014-07-24 01:30:07 -07:00
|
|
|
aPt.MoveBy(padding.left, padding.top);
|
2014-05-30 01:00:26 -07:00
|
|
|
aPt.y = NSToCoordRound(nsLayoutUtils::GetSnappedBaselineY(
|
|
|
|
this, aRenderingContext.ThebesContext(), aPt.y, ascent));
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
if (!presContext->BidiEnabled() && HasRTLChars(text)) {
|
|
|
|
presContext->SetBidiEnabled();
|
|
|
|
}
|
2014-10-24 08:28:14 -07:00
|
|
|
nsLayoutUtils::DrawString(this, *fm, &aRenderingContext,
|
2014-05-30 01:00:26 -07:00
|
|
|
text.get(), text.Length(), aPt);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
|
|
|
nsBulletFrame::SetListItemOrdinal(int32_t aNextOrdinal,
|
2012-09-07 19:30:24 -07:00
|
|
|
bool* aChanged,
|
|
|
|
int32_t aIncrement)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-07 19:30:24 -07:00
|
|
|
MOZ_ASSERT(aIncrement == 1 || aIncrement == -1,
|
|
|
|
"We shouldn't have weird increments here");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Assume that the ordinal comes from the caller
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t oldOrdinal = mOrdinal;
|
2007-03-22 10:30:00 -07: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-24 15:20:41 -07:00
|
|
|
nsIContent* parentContent = GetParent()->GetContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parentContent) {
|
|
|
|
nsGenericHTMLElement *hc =
|
|
|
|
nsGenericHTMLElement::FromContent(parentContent);
|
|
|
|
if (hc) {
|
|
|
|
const nsAttrValue* attr = hc->GetParsedAttr(nsGkAtoms::value);
|
|
|
|
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
|
|
|
// Use ordinal specified by the value attribute
|
|
|
|
mOrdinal = attr->GetIntegerValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aChanged = oldOrdinal != mOrdinal;
|
|
|
|
|
2013-02-22 10:13:37 -08:00
|
|
|
return nsCounterManager::IncrementCounter(mOrdinal, aIncrement);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-12-02 09:51:25 -08:00
|
|
|
void
|
2014-06-11 18:12:00 -07:00
|
|
|
nsBulletFrame::GetListItemText(nsAString& aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-06-11 18:12:00 -07:00
|
|
|
CounterStyle* style = StyleList()->GetCounterStyle();
|
|
|
|
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 08:34:00 -07:00
|
|
|
style->GetStyle() != NS_STYLE_LIST_STYLE_SQUARE &&
|
|
|
|
style->GetStyle() != NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED &&
|
|
|
|
style->GetStyle() != NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN,
|
2007-03-22 10:30:00 -07:00
|
|
|
"we should be using specialized code for these types");
|
|
|
|
|
2014-05-30 01:00:26 -07:00
|
|
|
bool isRTL;
|
2014-06-11 18:12:00 -07:00
|
|
|
nsAutoString counter, prefix, suffix;
|
|
|
|
style->GetPrefix(prefix);
|
|
|
|
style->GetSuffix(suffix);
|
2014-06-13 08:34:00 -07:00
|
|
|
style->GetCounterText(mOrdinal, GetWritingMode(), counter, isRTL);
|
2014-05-30 01:00:26 -07:00
|
|
|
|
2014-06-11 18:12:00 -07:00
|
|
|
aResult.Truncate();
|
|
|
|
aResult.Append(prefix);
|
2014-05-30 01:00:26 -07:00
|
|
|
if (GetWritingMode().IsBidiLTR() != isRTL) {
|
2014-06-11 18:12:00 -07:00
|
|
|
aResult.Append(counter);
|
2014-05-30 01:00:26 -07:00
|
|
|
} else {
|
|
|
|
// RLM = 0x200f, LRM = 0x200e
|
|
|
|
char16_t mark = isRTL ? 0x200f : 0x200e;
|
2014-06-11 18:12:00 -07:00
|
|
|
aResult.Append(mark);
|
|
|
|
aResult.Append(counter);
|
|
|
|
aResult.Append(mark);
|
2014-05-30 01:00:26 -07:00
|
|
|
}
|
2014-06-11 18:12:00 -07:00
|
|
|
aResult.Append(suffix);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MIN_BULLET_SIZE 1
|
|
|
|
|
2014-06-13 08:34:00 -07:00
|
|
|
void
|
|
|
|
nsBulletFrame::AppendSpacingToPadding(nsFontMetrics* aFontMetrics)
|
|
|
|
{
|
2014-07-24 01:30:07 -07:00
|
|
|
mPadding.IEnd(GetWritingMode()) += aFontMetrics->EmHeight() / 2;
|
2014-06-13 08:34:00 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
nsBulletFrame::GetDesiredSize(nsPresContext* aCX,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext *aRenderingContext,
|
2011-11-23 18:48:23 -08:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
float aFontSizeInflation)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Reset our padding. If we need it, we'll set it below.
|
2014-07-24 01:30:07 -07:00
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
mPadding.SizeTo(wm, 0, 0, 0, 0);
|
|
|
|
LogicalSize finalSize(wm);
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleList* myList = StyleList();
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord ascent;
|
2014-06-04 02:18:52 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
|
|
|
|
aFontSizeInflation);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-31 11:54:44 -07:00
|
|
|
RemoveStateBits(BULLET_FRAME_IMAGE_LOADING);
|
|
|
|
|
2009-12-10 20:02:13 -08:00
|
|
|
if (myList->GetListStyleImage() && mImageRequest) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t status;
|
2007-03-22 10:30:00 -07:00
|
|
|
mImageRequest->GetImageStatus(&status);
|
|
|
|
if (status & imgIRequest::STATUS_SIZE_AVAILABLE &&
|
|
|
|
!(status & imgIRequest::STATUS_ERROR)) {
|
|
|
|
// auto size the image
|
2014-07-24 01:30:07 -07:00
|
|
|
finalSize.ISize(wm) = mIntrinsicSize.ISize(wm);
|
|
|
|
aMetrics.SetBlockStartAscent(finalSize.BSize(wm) =
|
|
|
|
mIntrinsicSize.BSize(wm));
|
|
|
|
aMetrics.SetSize(wm, finalSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-13 08:34:00 -07:00
|
|
|
AppendSpacingToPadding(fm);
|
2014-06-04 02:18:52 -07:00
|
|
|
|
2010-08-31 11:54:44 -07:00
|
|
|
AddStateBits(BULLET_FRAME_IMAGE_LOADING);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 01:30:07 -07:00
|
|
|
mIntrinsicSize.SizeTo(wm, 0, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nscoord bulletSize;
|
|
|
|
|
|
|
|
nsAutoString text;
|
2014-06-11 18:12:00 -07:00
|
|
|
switch (myList->GetCounterStyle()->GetStyle()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_STYLE_LIST_STYLE_NONE:
|
2014-07-24 01:30:07 -07:00
|
|
|
finalSize.ISize(wm) = finalSize.BSize(wm) = 0;
|
2014-06-11 02:45:31 -07:00
|
|
|
aMetrics.SetBlockStartAscent(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_LIST_STYLE_DISC:
|
|
|
|
case NS_STYLE_LIST_STYLE_CIRCLE:
|
2014-05-30 01:00:26 -07:00
|
|
|
case NS_STYLE_LIST_STYLE_SQUARE: {
|
2011-04-07 21:18:43 -07:00
|
|
|
ascent = fm->MaxAscent();
|
2013-01-15 04:22:03 -08:00
|
|
|
bulletSize = std::max(nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE),
|
2007-03-22 10:30:00 -07:00
|
|
|
NSToCoordRound(0.8f * (float(ascent) / 2.0f)));
|
2014-07-24 01:30:07 -07:00
|
|
|
mPadding.BEnd(wm) = NSToCoordRound(float(ascent) / 8.0f);
|
|
|
|
finalSize.ISize(wm) = finalSize.BSize(wm) = bulletSize;
|
|
|
|
aMetrics.SetBlockStartAscent(bulletSize + mPadding.BEnd(wm));
|
2014-06-13 08:34:00 -07:00
|
|
|
AppendSpacingToPadding(fm);
|
|
|
|
break;
|
|
|
|
}
|
2014-05-30 01:00:26 -07:00
|
|
|
|
2014-06-13 08:34:00 -07: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));
|
2014-07-24 01:30:07 -07:00
|
|
|
mPadding.BEnd(wm) = NSToCoordRound(0.125f * ascent);
|
|
|
|
finalSize.ISize(wm) = finalSize.BSize(wm) = bulletSize;
|
|
|
|
if (!wm.IsVertical()) {
|
|
|
|
aMetrics.SetBlockStartAscent(bulletSize + mPadding.BEnd(wm));
|
2014-05-30 01:00:26 -07:00
|
|
|
}
|
2014-06-13 08:34:00 -07:00
|
|
|
AppendSpacingToPadding(fm);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-06-11 18:12:00 -07:00
|
|
|
GetListItemText(text);
|
2014-07-24 01:30:07 -07:00
|
|
|
finalSize.BSize(wm) = fm->MaxHeight();
|
|
|
|
finalSize.ISize(wm) =
|
2014-10-26 10:57:49 -07:00
|
|
|
nsLayoutUtils::AppUnitWidthOfStringBidi(text, this, *fm,
|
|
|
|
*aRenderingContext);
|
2014-06-11 02:45:31 -07:00
|
|
|
aMetrics.SetBlockStartAscent(fm->MaxAscent());
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-07-24 01:30:07 -07:00
|
|
|
aMetrics.SetSize(wm, finalSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBulletFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsBulletFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
|
|
|
|
2012-05-20 22:18:28 -07:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2011-11-23 18:48:23 -08:00
|
|
|
SetFontSizeInflation(inflation);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the base size
|
2011-11-23 18:48:23 -08:00
|
|
|
GetDesiredSize(aPresContext, aReflowState.rendContext, aMetrics, inflation);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Add in the border and padding; split the top/bottom between the
|
|
|
|
// ascent and descent to make things look nice
|
2014-07-24 01:30:07 -07:00
|
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
|
|
|
const LogicalMargin& bp = aReflowState.ComputedLogicalBorderPadding();
|
|
|
|
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));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-23 19:19:14 -07: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-06 21:25:46 -07:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-07-24 10:03:25 -07:00
|
|
|
nsBulletFrame::GetMinISize(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-24 01:30:07 -07:00
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
nsHTMLReflowMetrics metrics(wm);
|
|
|
|
DISPLAY_MIN_WIDTH(this, metrics.ISize(wm));
|
2011-11-23 18:48:23 -08:00
|
|
|
GetDesiredSize(PresContext(), aRenderingContext, metrics, 1.0f);
|
2014-07-24 01:30:07 -07:00
|
|
|
return metrics.ISize(wm);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-07-24 10:03:25 -07:00
|
|
|
nsBulletFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-07-24 01:30:07 -07:00
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
nsHTMLReflowMetrics metrics(wm);
|
|
|
|
DISPLAY_PREF_WIDTH(this, metrics.ISize(wm));
|
2011-11-23 18:48:23 -08:00
|
|
|
GetDesiredSize(PresContext(), aRenderingContext, metrics, 1.0f);
|
2014-07-24 01:30:07 -07:00
|
|
|
return metrics.ISize(wm);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:22 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBulletFrame::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData)
|
|
|
|
{
|
2012-10-12 09:11:23 -07:00
|
|
|
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
|
2012-10-12 09:11:22 -07:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
aRequest->GetImage(getter_AddRefs(image));
|
2014-11-17 14:29:56 -08:00
|
|
|
return OnSizeAvailable(aRequest, image);
|
2012-10-12 09:11:22 -07:00
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:23 -07:00
|
|
|
if (aType == imgINotificationObserver::FRAME_UPDATE) {
|
2012-10-12 09:11:22 -07: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-10 13:37:49 -08: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.
|
|
|
|
if (aRequest == mImageRequest) {
|
|
|
|
mImageRequest->RequestDecode();
|
2012-10-12 09:11:22 -07:00
|
|
|
}
|
2014-11-10 13:37:49 -08:00
|
|
|
InvalidateFrame();
|
2012-10-12 09:11:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-11-10 13:37:49 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBulletFrame::BlockOnload(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (aRequest != mImageRequest) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mBlockingOnload, "Double BlockOnload for an nsBulletFrame?");
|
|
|
|
|
|
|
|
nsIDocument* doc = GetOurCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
mBlockingOnload = true;
|
|
|
|
doc->BlockOnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBulletFrame::UnblockOnload(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (aRequest != mImageRequest) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mBlockingOnload, "Double UnblockOnload for an nsBulletFrame?");
|
|
|
|
|
|
|
|
nsIDocument* doc = GetOurCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->UnblockOnload(false);
|
|
|
|
}
|
|
|
|
mBlockingOnload = false;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument*
|
|
|
|
nsBulletFrame::GetOurCurrentDoc() const
|
|
|
|
{
|
|
|
|
nsIContent* parentContent = GetParent()->GetContent();
|
|
|
|
return parentContent ? parentContent->GetComposedDoc()
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-17 14:29:56 -08:00
|
|
|
nsresult
|
|
|
|
nsBulletFrame::OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aImage) return NS_ERROR_INVALID_ARG;
|
|
|
|
if (!aRequest) return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t status;
|
2007-03-22 10:30:00 -07:00
|
|
|
aRequest->GetImageStatus(&status);
|
|
|
|
if (status & imgIRequest::STATUS_ERROR) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord w, h;
|
|
|
|
aImage->GetWidth(&w);
|
|
|
|
aImage->GetHeight(&h);
|
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-07-24 01:30:07 -07:00
|
|
|
LogicalSize newsize(GetWritingMode(),
|
|
|
|
nsSize(nsPresContext::CSSPixelsToAppUnits(w),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(h)));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mIntrinsicSize != newsize) {
|
|
|
|
mIntrinsicSize = newsize;
|
|
|
|
|
|
|
|
// Now that the size is available (or an error occurred), trigger
|
|
|
|
// a reflow of the bullet frame.
|
|
|
|
nsIPresShell *shell = presContext->GetPresShell();
|
|
|
|
if (shell) {
|
2007-05-06 12:16:51 -07:00
|
|
|
shell->FrameNeedsReflow(this, nsIPresShell::eStyleChange,
|
|
|
|
NS_FRAME_IS_DIRTY);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle animations
|
|
|
|
aImage->SetAnimationMode(presContext->ImageAnimationMode());
|
2010-09-07 17:33:02 -07: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();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBulletFrame::GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGroup)
|
|
|
|
{
|
|
|
|
if (!aPresContext)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != aLoadGroup, "null OUT parameter pointer");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIPresShell *shell = aPresContext->GetPresShell();
|
|
|
|
|
|
|
|
if (!shell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIDocument *doc = shell->GetDocument();
|
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
2014-03-15 12:00:15 -07:00
|
|
|
*aLoadGroup = doc->GetDocumentLoadGroup().take();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
union VoidPtrOrFloat {
|
2012-07-30 07:20:58 -07:00
|
|
|
VoidPtrOrFloat() : p(nullptr) {}
|
2011-11-23 18:48:23 -08:00
|
|
|
|
|
|
|
void *p;
|
|
|
|
float f;
|
|
|
|
};
|
|
|
|
|
|
|
|
float
|
|
|
|
nsBulletFrame::GetFontSizeInflation() const
|
|
|
|
{
|
|
|
|
if (!HasFontSizeInflation()) {
|
|
|
|
return 1.0f;
|
|
|
|
}
|
|
|
|
VoidPtrOrFloat u;
|
|
|
|
u.p = Properties().Get(FontSizeInflationProperty());
|
|
|
|
return u.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBulletFrame::SetFontSizeInflation(float aInflation)
|
|
|
|
{
|
|
|
|
if (aInflation == 1.0f) {
|
|
|
|
if (HasFontSizeInflation()) {
|
|
|
|
RemoveStateBits(BULLET_FRAME_HAS_FONT_INFLATION);
|
|
|
|
Properties().Delete(FontSizeInflationProperty());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AddStateBits(BULLET_FRAME_HAS_FONT_INFLATION);
|
|
|
|
VoidPtrOrFloat u;
|
|
|
|
u.f = aInflation;
|
|
|
|
Properties().Set(FontSizeInflationProperty(), u.p);
|
|
|
|
}
|
|
|
|
|
2013-06-22 09:30:57 -07: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 11:54:44 -07:00
|
|
|
nscoord
|
2014-06-17 05:19:38 -07:00
|
|
|
nsBulletFrame::GetLogicalBaseline(WritingMode aWritingMode) const
|
2010-08-31 11:54:44 -07:00
|
|
|
{
|
2014-07-24 01:30:07 -07:00
|
|
|
nscoord ascent = 0, baselinePadding;
|
2010-08-31 11:54:44 -07:00
|
|
|
if (GetStateBits() & BULLET_FRAME_IMAGE_LOADING) {
|
2014-06-17 05:19:38 -07:00
|
|
|
ascent = BSize(aWritingMode);
|
2010-08-31 11:54:44 -07:00
|
|
|
} else {
|
2011-04-07 18:05:49 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
2011-11-23 18:48:23 -08:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
|
|
|
|
GetFontSizeInflation());
|
2014-06-11 18:12:00 -07:00
|
|
|
CounterStyle* listStyleType = StyleList()->GetCounterStyle();
|
|
|
|
switch (listStyleType->GetStyle()) {
|
2010-08-31 11:54:44 -07: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-07 21:18:43 -07:00
|
|
|
ascent = fm->MaxAscent();
|
2014-07-24 01:30:07 -07:00
|
|
|
baselinePadding = NSToCoordRound(float(ascent) / 8.0f);
|
2013-01-15 04:22:03 -08:00
|
|
|
ascent = std::max(nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE),
|
2010-08-31 11:54:44 -07:00
|
|
|
NSToCoordRound(0.8f * (float(ascent) / 2.0f)));
|
2014-07-24 01:30:07 -07:00
|
|
|
ascent += baselinePadding;
|
2010-08-31 11:54:44 -07:00
|
|
|
break;
|
|
|
|
|
2014-06-13 08:34:00 -07:00
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED:
|
|
|
|
case NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN:
|
|
|
|
ascent = fm->EmAscent();
|
2014-07-24 01:30:07 -07:00
|
|
|
baselinePadding = NSToCoordRound(0.125f * ascent);
|
2014-06-13 08:34:00 -07:00
|
|
|
ascent = std::max(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(MIN_BULLET_SIZE),
|
|
|
|
NSToCoordRound(0.75f * ascent));
|
2014-07-24 01:30:07 -07:00
|
|
|
ascent += baselinePadding;
|
2014-06-13 08:34:00 -07:00
|
|
|
break;
|
|
|
|
|
2010-08-31 11:54:44 -07:00
|
|
|
default:
|
2011-04-07 21:18:43 -07:00
|
|
|
ascent = fm->MaxAscent();
|
2010-08-31 11:54:44 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-17 05:19:38 -07:00
|
|
|
return ascent +
|
|
|
|
GetLogicalUsedMargin(aWritingMode).BStart(aWritingMode);
|
2010-08-31 11:54:44 -07:00
|
|
|
}
|
|
|
|
|
2014-06-11 18:12:00 -07:00
|
|
|
void
|
|
|
|
nsBulletFrame::GetSpokenText(nsAString& aText)
|
|
|
|
{
|
|
|
|
CounterStyle* style = StyleList()->GetCounterStyle();
|
|
|
|
bool isBullet;
|
2014-06-13 08:34:00 -07:00
|
|
|
style->GetSpokenCounterText(mOrdinal, GetWritingMode(), aText, isBullet);
|
2014-06-11 18:12:00 -07:00
|
|
|
if (isBullet) {
|
2014-10-23 16:10:00 -07:00
|
|
|
if (!style->IsNone()) {
|
|
|
|
aText.Append(' ');
|
|
|
|
}
|
2014-06-11 18:12:00 -07:00
|
|
|
} else {
|
|
|
|
nsAutoString prefix, suffix;
|
|
|
|
style->GetPrefix(prefix);
|
|
|
|
style->GetSuffix(suffix);
|
|
|
|
aText = prefix + aText + suffix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-10 13:37:49 -08: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-11-10 13:37:49 -08:00
|
|
|
// Unblock onload if we blocked it.
|
|
|
|
if (mBlockingOnload) {
|
|
|
|
nsIDocument* doc = GetOurCurrentDoc();
|
|
|
|
if (doc) {
|
|
|
|
doc->UnblockOnload(false);
|
|
|
|
}
|
|
|
|
mBlockingOnload = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel the image request and forget about it.
|
|
|
|
mImageRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
|
|
|
|
mImageRequest = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsBulletListener, imgINotificationObserver)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsBulletListener::nsBulletListener() :
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrame(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBulletListener::~nsBulletListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:22 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBulletListener::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-11-10 13:37:49 -08:00
|
|
|
if (!mFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-11-10 13:37:49 -08:00
|
|
|
}
|
2012-10-12 09:11:22 -07:00
|
|
|
return mFrame->Notify(aRequest, aType, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-11-10 13:37:49 -08:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBulletListener::BlockOnload(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (!mFrame) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return mFrame->BlockOnload(aRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBulletListener::UnblockOnload(imgIRequest* aRequest)
|
|
|
|
{
|
|
|
|
if (!mFrame) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return mFrame->UnblockOnload(aRequest);
|
|
|
|
}
|