Skip to content

Commit

Permalink
Bug 382721 - Part 9: Warn about too large dotted/dashed corner. r=jrm…
Browse files Browse the repository at this point in the history
…uizel
  • Loading branch information
arai-a committed Jun 10, 2016
1 parent eaa81ff commit 3bc0de7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
3 changes: 3 additions & 0 deletions dom/locales/en-US/chrome/layout/css.properties
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,6 @@ PESubgridNotSupported=Support for the ‘subgrid’ keyword of CSS Grid is not e
PEMoreThanOneGridRepeatAutoFillInNameList=Only one repeat(auto-fill, …) is allowed in a name list for a subgrid.
PEMoreThanOneGridRepeatAutoFillFitInTrackList=Only one repeat(auto-fill, …) or repeat(auto-fit, …) is allowed in a track list.
PEMoreThanOneGridRepeatTrackSize=Only one track size is allowed inside repeat(auto-fit/auto-fill, …).

TooLargeDashedRadius=Border radius is too large for ‘dashed’ style (the limit is 100000px). Rendering as solid.
TooLargeDottedRadius=Border radius is too large for ‘dotted’ style (the limit is 100000px). Rendering as solid.
21 changes: 18 additions & 3 deletions layout/base/nsCSSRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,14 @@ nsCSSRendering::PaintBorderWithStyleBorder(nsPresContext* aPresContext,
aDrawTarget.FillRect(joinedBorderAreaPx, color);
#endif

nsCSSBorderRenderer br(aPresContext->Type(),
nsIDocument* document = nullptr;
nsIContent* content = aForFrame->GetContent();
if (content) {
document = content->OwnerDoc();
}

nsCSSBorderRenderer br(aPresContext,
document,
&aDrawTarget,
dirtyRect,
joinedBorderAreaPx,
Expand Down Expand Up @@ -936,9 +943,16 @@ nsCSSRendering::PaintOutline(nsPresContext* aPresContext,
Float(width / twipsPerPixel) };
Rect dirtyRect = NSRectToRect(aDirtyRect, twipsPerPixel);

nsIDocument* document = nullptr;
nsIContent* content = aForFrame->GetContent();
if (content) {
document = content->OwnerDoc();
}

// start drawing

nsCSSBorderRenderer br(aPresContext->Type(),
nsCSSBorderRenderer br(aPresContext,
document,
aRenderingContext.GetDrawTarget(),
dirtyRect,
oRect,
Expand Down Expand Up @@ -986,7 +1000,8 @@ nsCSSRendering::PaintFocus(nsPresContext* aPresContext,
// something that CSS can style, this function will then have access
// to a style context and can use the same logic that PaintBorder
// and PaintOutline do.)
nsCSSBorderRenderer br(aPresContext->Type(),
nsCSSBorderRenderer br(aPresContext,
nullptr,
aDrawTarget,
focusRect,
focusRect,
Expand Down
23 changes: 20 additions & 3 deletions layout/base/nsCSSRenderingBorders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
#include "DottedCornerFinder.h"
#include "nsLayoutUtils.h"
#include "nsStyleConsts.h"
#include "nsContentUtils.h"
#include "nsCSSColorUtils.h"
#include "GeckoProfiler.h"
#include "nsExpirationTracker.h"
#include "RoundedRect.h"
#include "nsClassHashtable.h"
#include "nsPresContext.h"
#include "nsStyleStruct.h"
#include "mozilla/gfx/2D.h"
#include "gfx2DGlue.h"
Expand Down Expand Up @@ -162,7 +164,8 @@ typedef enum {
CORNER_DOT
} CornerStyle;

nsCSSBorderRenderer::nsCSSBorderRenderer(nsPresContext::nsPresContextType aPresContextType,
nsCSSBorderRenderer::nsCSSBorderRenderer(nsPresContext* aPresContext,
const nsIDocument* aDocument,
DrawTarget* aDrawTarget,
const Rect& aDirtyRect,
Rect& aOuterRect,
Expand All @@ -172,7 +175,8 @@ nsCSSBorderRenderer::nsCSSBorderRenderer(nsPresContext::nsPresContextType aPresC
const nscolor* aBorderColors,
nsBorderColors* const* aCompositeColors,
nscolor aBackgroundColor)
: mPresContextType(aPresContextType),
: mPresContext(aPresContext),
mDocument(aDocument),
mDrawTarget(aDrawTarget),
mDirtyRect(aDirtyRect),
mOuterRect(aOuterRect),
Expand Down Expand Up @@ -2465,6 +2469,19 @@ nsCSSBorderRenderer::DrawFallbackSolidCorner(mozilla::css::Side aSide,

RefPtr<Path> path = builder->Finish();
mDrawTarget->Fill(path, ColorPattern(ToDeviceColor(borderColor)));

if (mDocument) {
if (!mPresContext->HasWarnedAboutTooLargeDashedOrDottedRadius()) {
mPresContext->SetHasWarnedAboutTooLargeDashedOrDottedRadius();
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
NS_LITERAL_CSTRING("CSS"),
mDocument,
nsContentUtils::eCSS_PROPERTIES,
mBorderStyles[aSide] == NS_STYLE_BORDER_STYLE_DASHED
? "TooLargeDashedRadius"
: "TooLargeDottedRadius");
}
}
}

bool
Expand Down Expand Up @@ -2910,7 +2927,7 @@ nsCSSBorderRenderer::DrawNoCompositeColorSolidBorder()
Float skirtSize = 0.0f, skirtSlope = 0.0f;
// the sides don't match, so compute a skirt
if (firstColor != secondColor &&
mPresContextType != nsPresContext::eContext_Print) {
mPresContext->Type() != nsPresContext::eContext_Print) {
Point cornerDir = outerCorner - innerCorner;
ComputeCornerSkirtSize(firstColor.a, secondColor.a,
cornerDir.DotProduct(cornerMults[i]),
Expand Down
11 changes: 8 additions & 3 deletions layout/base/nsCSSRenderingBorders.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ typedef enum {
BorderColorStyleDark
} BorderColorStyle;

class nsIDocument;
class nsPresContext;

class nsCSSBorderRenderer final
{
typedef mozilla::gfx::Bezier Bezier;
Expand All @@ -74,7 +77,8 @@ class nsCSSBorderRenderer final

public:

nsCSSBorderRenderer(nsPresContext::nsPresContextType aPresContextType,
nsCSSBorderRenderer(nsPresContext* aPresContext,
const nsIDocument* aDocument,
DrawTarget* aDrawTarget,
const Rect& aDirtyRect,
Rect& aOuterRect,
Expand Down Expand Up @@ -105,8 +109,9 @@ class nsCSSBorderRenderer final

RectCornerRadii mBorderCornerDimensions;

// the PresContext type
nsPresContext::nsPresContextType mPresContextType;
// Target document to report warning
nsPresContext* mPresContext;
const nsIDocument* mDocument;

// destination DrawTarget and dirty rect
DrawTarget* mDrawTarget;
Expand Down
10 changes: 10 additions & 0 deletions layout/base/nsPresContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,14 @@ class nsPresContext : public nsIObserver {
mHasWarnedAboutPositionedTableParts = true;
}

bool HasWarnedAboutTooLargeDashedOrDottedRadius() const {
return mHasWarnedAboutTooLargeDashedOrDottedRadius;
}

void SetHasWarnedAboutTooLargeDashedOrDottedRadius() {
mHasWarnedAboutTooLargeDashedOrDottedRadius = true;
}

static bool StyloEnabled()
{
// Stylo (the Servo backend for Gecko's style system) is generally enabled
Expand Down Expand Up @@ -1382,6 +1390,8 @@ class nsPresContext : public nsIObserver {

unsigned mHasWarnedAboutPositionedTableParts : 1;

unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1;

// Have we added quirk.css to the style set?
unsigned mQuirkSheetAdded : 1;

Expand Down

0 comments on commit 3bc0de7

Please sign in to comment.