From 5fd0e1df8644075dc4e4d1ed42a6e0683ce3726d Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Fri, 10 Jun 2016 13:10:03 +0900 Subject: [PATCH] Bug 382721 - Part 9: Warn about too large dotted/dashed corner. r=jrmuizel --- .../en-US/chrome/layout/css.properties | 3 +++ layout/base/nsCSSRendering.cpp | 21 ++++++++++++++--- layout/base/nsCSSRenderingBorders.cpp | 23 ++++++++++++++++--- layout/base/nsCSSRenderingBorders.h | 11 ++++++--- layout/base/nsPresContext.h | 10 ++++++++ 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/dom/locales/en-US/chrome/layout/css.properties b/dom/locales/en-US/chrome/layout/css.properties index 5328d0435989..ecb536910caf 100644 --- a/dom/locales/en-US/chrome/layout/css.properties +++ b/dom/locales/en-US/chrome/layout/css.properties @@ -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. diff --git a/layout/base/nsCSSRendering.cpp b/layout/base/nsCSSRendering.cpp index 5562bcbcb803..8bd496a42743 100644 --- a/layout/base/nsCSSRendering.cpp +++ b/layout/base/nsCSSRendering.cpp @@ -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, @@ -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, @@ -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, diff --git a/layout/base/nsCSSRenderingBorders.cpp b/layout/base/nsCSSRenderingBorders.cpp index 04e672ccfe0d..a37831feb4d7 100644 --- a/layout/base/nsCSSRenderingBorders.cpp +++ b/layout/base/nsCSSRenderingBorders.cpp @@ -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" @@ -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, @@ -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), @@ -2465,6 +2469,19 @@ nsCSSBorderRenderer::DrawFallbackSolidCorner(mozilla::css::Side aSide, RefPtr 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 @@ -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]), diff --git a/layout/base/nsCSSRenderingBorders.h b/layout/base/nsCSSRenderingBorders.h index 9bd5e1e0edbd..ccde72298ad5 100644 --- a/layout/base/nsCSSRenderingBorders.h +++ b/layout/base/nsCSSRenderingBorders.h @@ -60,6 +60,9 @@ typedef enum { BorderColorStyleDark } BorderColorStyle; +class nsIDocument; +class nsPresContext; + class nsCSSBorderRenderer final { typedef mozilla::gfx::Bezier Bezier; @@ -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, @@ -105,8 +109,9 @@ private: 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; diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index d146d8ca71f7..9d0c69f65cc8 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -1093,6 +1093,14 @@ public: 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 @@ -1382,6 +1390,8 @@ protected: unsigned mHasWarnedAboutPositionedTableParts : 1; + unsigned mHasWarnedAboutTooLargeDashedOrDottedRadius : 1; + // Have we added quirk.css to the style set? unsigned mQuirkSheetAdded : 1;