Bug 1083221 - Port the code that uses nsRenderingContext::DrawEllipse/FillEllipse and gfxContext::Ellipse to Moz2D. r=mattwoodrow

This commit is contained in:
Jonathan Watt 2014-10-16 12:03:44 +01:00
parent cd9122458b
commit 953853c7bd
8 changed files with 83 additions and 81 deletions

View File

@ -328,36 +328,6 @@ nsRenderingContext::FillRect(nscoord aX, nscoord aY,
FillRect(nsRect(aX, aY, aWidth, aHeight)); FillRect(nsRect(aX, aY, aWidth, aHeight));
} }
void
nsRenderingContext::DrawEllipse(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight)
{
mThebes->NewPath();
mThebes->Ellipse(gfxPoint(FROM_TWIPS(aX) + FROM_TWIPS(aWidth)/2.0,
FROM_TWIPS(aY) + FROM_TWIPS(aHeight)/2.0),
gfxSize(FROM_TWIPS(aWidth),
FROM_TWIPS(aHeight)));
mThebes->Stroke();
}
void
nsRenderingContext::FillEllipse(const nsRect& aRect)
{
FillEllipse(aRect.x, aRect.y, aRect.width, aRect.height);
}
void
nsRenderingContext::FillEllipse(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight)
{
mThebes->NewPath();
mThebes->Ellipse(gfxPoint(FROM_TWIPS(aX) + FROM_TWIPS(aWidth)/2.0,
FROM_TWIPS(aY) + FROM_TWIPS(aHeight)/2.0),
gfxSize(FROM_TWIPS(aWidth),
FROM_TWIPS(aHeight)));
mThebes->Fill();
}
void void
nsRenderingContext::FillPolygon(const nsPoint twPoints[], int32_t aNumPoints) nsRenderingContext::FillPolygon(const nsPoint twPoints[], int32_t aNumPoints)
{ {

View File

@ -62,15 +62,11 @@ public:
void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1); void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
void DrawRect(const nsRect& aRect); void DrawRect(const nsRect& aRect);
void DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); void DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
void DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
void FillRect(const nsRect& aRect); void FillRect(const nsRect& aRect);
void FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); void FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
void FillPolygon(const nsPoint aPoints[], int32_t aNumPoints); void FillPolygon(const nsPoint aPoints[], int32_t aNumPoints);
void FillEllipse(const nsRect& aRect);
void FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
// Text // Text
void SetFont(nsFontMetrics *aFontMetrics); void SetFont(nsFontMetrics *aFontMetrics);

View File

@ -386,16 +386,6 @@ gfxContext::Rectangle(const gfxRect& rect, bool snapToPixels)
mPathBuilder->Close(); mPathBuilder->Close();
} }
void
gfxContext::Ellipse(const gfxPoint& center, const gfxSize& dimensions)
{
gfxSize halfDim = dimensions / 2.0;
gfxRect r(center - gfxPoint(halfDim.width, halfDim.height), dimensions);
gfxCornerSizes c(halfDim, halfDim, halfDim, halfDim);
RoundedRectangle (r, c);
}
void void
gfxContext::Polygon(const gfxPoint *points, uint32_t numPoints) gfxContext::Polygon(const gfxPoint *points, uint32_t numPoints)
{ {

View File

@ -205,14 +205,6 @@ public:
void Rectangle(const gfxRect& rect, bool snapToPixels = false); void Rectangle(const gfxRect& rect, bool snapToPixels = false);
void SnappedRectangle(const gfxRect& rect) { return Rectangle(rect, true); } void SnappedRectangle(const gfxRect& rect) { return Rectangle(rect, true); }
/**
* Draw an ellipse at the center corner with the given dimensions.
* It extends dimensions.width / 2.0 in the horizontal direction
* from the center, and dimensions.height / 2.0 in the vertical
* direction.
*/
void Ellipse(const gfxPoint& center, const gfxSize& dimensions);
/** /**
* Draw a polygon from the given points * Draw a polygon from the given points
*/ */

View File

@ -4,10 +4,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsGfxRadioControlFrame.h" #include "nsGfxRadioControlFrame.h"
#include "gfx2DGlue.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PathHelpers.h"
#include "nsLayoutUtils.h"
#include "nsRenderingContext.h" #include "nsRenderingContext.h"
#include "nsDisplayList.h" #include "nsDisplayList.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::gfx;
nsIFrame* nsIFrame*
NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
@ -49,8 +55,17 @@ PaintCheckedRadioButton(nsIFrame* aFrame,
rect.Deflate(nsPresContext::CSSPixelsToAppUnits(2), rect.Deflate(nsPresContext::CSSPixelsToAppUnits(2),
nsPresContext::CSSPixelsToAppUnits(2)); nsPresContext::CSSPixelsToAppUnits(2));
aCtx->SetColor(aFrame->StyleColor()->mColor); Rect devPxRect =
aCtx->FillEllipse(rect); ToRect(nsLayoutUtils::RectToGfxRect(rect,
aFrame->PresContext()->AppUnitsPerDevPixel()));
ColorPattern color(nsLayoutUtils::NSColorToColor(aFrame->StyleColor()->mColor));
DrawTarget* drawTarget = aCtx->GetDrawTarget();
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size());
RefPtr<Path> ellipse = builder->Finish();
drawTarget->Fill(ellipse, color);
} }
void void

View File

@ -7,6 +7,9 @@
#include "nsBulletFrame.h" #include "nsBulletFrame.h"
#include "gfx2DGlue.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PathHelpers.h"
#include "mozilla/MathAlgorithms.h" #include "mozilla/MathAlgorithms.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
@ -32,6 +35,7 @@
#endif #endif
using namespace mozilla; using namespace mozilla;
using namespace mozilla::gfx;
NS_DECLARE_FRAME_PROPERTY(FontSizeInflationProperty, nullptr) NS_DECLARE_FRAME_PROPERTY(FontSizeInflationProperty, nullptr)
@ -312,7 +316,9 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
} }
nsRefPtr<nsFontMetrics> fm; nsRefPtr<nsFontMetrics> fm;
aRenderingContext.SetColor(nsLayoutUtils::GetColor(this, eCSSProperty_color)); nscolor col = nsLayoutUtils::GetColor(this, eCSSProperty_color);
Color color = nsLayoutUtils::NSColorToColor(col);
aRenderingContext.SetColor(col);
nsAutoString text; nsAutoString text;
switch (listStyleType->GetStyle()) { switch (listStyleType->GetStyle()) {
@ -320,15 +326,24 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
break; break;
case NS_STYLE_LIST_STYLE_DISC: case NS_STYLE_LIST_STYLE_DISC:
aRenderingContext.FillEllipse(padding.left + aPt.x, padding.top + aPt.y,
mRect.width - (padding.left + padding.right),
mRect.height - (padding.top + padding.bottom));
break;
case NS_STYLE_LIST_STYLE_CIRCLE: case NS_STYLE_LIST_STYLE_CIRCLE:
aRenderingContext.DrawEllipse(padding.left + aPt.x, padding.top + aPt.y, {
mRect.width - (padding.left + padding.right), nsRect rect(padding.left + aPt.x,
mRect.height - (padding.top + padding.bottom)); padding.top + aPt.y,
mRect.width - (padding.left + padding.right),
mRect.height - (padding.top + padding.bottom));
Rect devPxRect =
ToRect(nsLayoutUtils::RectToGfxRect(rect, PresContext()->AppUnitsPerDevPixel()));
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size());
RefPtr<Path> ellipse = builder->Finish();
if (listStyleType->GetStyle() == NS_STYLE_LIST_STYLE_DISC) {
drawTarget->Fill(ellipse, ColorPattern(color));
} else {
drawTarget->Stroke(ellipse, ColorPattern(color));
}
}
break; break;
case NS_STYLE_LIST_STYLE_SQUARE: case NS_STYLE_LIST_STYLE_SQUARE:

View File

@ -12,6 +12,7 @@
#include "mozilla/EventStates.h" #include "mozilla/EventStates.h"
#include "mozilla/gfx/2D.h" #include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Helpers.h" #include "mozilla/gfx/Helpers.h"
#include "mozilla/gfx/PathHelpers.h"
#include "mozilla/MouseEvents.h" #include "mozilla/MouseEvents.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -73,24 +74,21 @@
#include "mozilla/dom/Link.h" #include "mozilla/dom/Link.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::gfx; using namespace mozilla::gfx;
using namespace mozilla::layers;
// sizes (pixels) for image icon, padding and border frame // sizes (pixels) for image icon, padding and border frame
#define ICON_SIZE (16) #define ICON_SIZE (16)
#define ICON_PADDING (3) #define ICON_PADDING (3)
#define ALT_BORDER_WIDTH (1) #define ALT_BORDER_WIDTH (1)
//we must add hooks soon //we must add hooks soon
#define IMAGE_EDITOR_CHECK 1 #define IMAGE_EDITOR_CHECK 1
// Default alignment value (so we can tell an unset value from a set value) // Default alignment value (so we can tell an unset value from a set value)
#define ALIGN_UNSET uint8_t(-1) #define ALIGN_UNSET uint8_t(-1)
using namespace mozilla::layers;
using namespace mozilla::dom;
using namespace mozilla::gfx;
// static icon information // static icon information
nsImageFrame::IconLoad* nsImageFrame::gIconLoad = nullptr; nsImageFrame::IconLoad* nsImageFrame::gIconLoad = nullptr;
@ -1261,15 +1259,28 @@ nsImageFrame::DisplayAltFeedback(nsRenderingContext& aRenderingContext,
// if we could not draw the icon, flag that we're waiting for it and // if we could not draw the icon, flag that we're waiting for it and
// just draw some graffiti in the mean time // just draw some graffiti in the mean time
if (!iconUsed) { if (!iconUsed) {
ColorPattern color(Color(1.f, 0.f, 0.f, 1.f));
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
nscoord iconXPos = (vis->mDirection == NS_STYLE_DIRECTION_RTL) ? nscoord iconXPos = (vis->mDirection == NS_STYLE_DIRECTION_RTL) ?
inner.XMost() - size : inner.x; inner.XMost() - size : inner.x;
// stroked rect:
nsRect rect(iconXPos, inner.y, size, size);
Rect devPxRect =
ToRect(nsLayoutUtils::RectToGfxRect(rect, PresContext()->AppUnitsPerDevPixel()));
drawTarget->StrokeRect(devPxRect, color);
// filled circle in bottom right quadrant of stroked rect:
nscoord twoPX = nsPresContext::CSSPixelsToAppUnits(2); nscoord twoPX = nsPresContext::CSSPixelsToAppUnits(2);
aRenderingContext.DrawRect(iconXPos, inner.y,size,size); rect = nsRect(iconXPos + size/2, inner.y + size/2,
aRenderingContext.ThebesContext()->Save(); size/2 - twoPX, size/2 - twoPX);
aRenderingContext.SetColor(NS_RGB(0xFF,0,0)); devPxRect =
aRenderingContext.FillEllipse(size/2 + iconXPos, size/2 + inner.y, ToRect(nsLayoutUtils::RectToGfxRect(rect, PresContext()->AppUnitsPerDevPixel()));
size/2 - twoPX, size/2 - twoPX); RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
aRenderingContext.ThebesContext()->Restore(); AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size());
RefPtr<Path> ellipse = builder->Finish();
drawTarget->Fill(ellipse, color);
} }
// Reduce the inner rect by the width of the icon, and leave an // Reduce the inner rect by the width of the icon, and leave an

View File

@ -4,6 +4,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMathMLmencloseFrame.h" #include "nsMathMLmencloseFrame.h"
#include "gfx2DGlue.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PathHelpers.h"
#include "nsPresContext.h" #include "nsPresContext.h"
#include "nsRenderingContext.h" #include "nsRenderingContext.h"
#include "nsWhitespaceTokenizer.h" #include "nsWhitespaceTokenizer.h"
@ -13,6 +17,9 @@
#include "nsMathMLChar.h" #include "nsMathMLChar.h"
#include <algorithm> #include <algorithm>
using namespace mozilla;
using namespace mozilla::gfx;
// //
// <menclose> -- enclose content with a stretching symbol such // <menclose> -- enclose content with a stretching symbol such
// as a long division sign. - implementation // as a long division sign. - implementation
@ -764,7 +771,11 @@ void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
gfxRect rect = presContext->AppUnitsToGfxUnits(mRect + ToReferenceFrame()); gfxRect rect = presContext->AppUnitsToGfxUnits(mRect + ToReferenceFrame());
// paint the frame with the current text color // paint the frame with the current text color
aCtx->SetColor(mFrame->GetVisitedDependentColor(eCSSProperty_color)); nscolor col = mFrame->GetVisitedDependentColor(eCSSProperty_color);
ColorPattern color(nsLayoutUtils::NSColorToColor(col));
aCtx->SetColor(col);
DrawTarget* drawTarget = aCtx->GetDrawTarget();
// change line width to mThickness // change line width to mThickness
gfxContext *gfxCtx = aCtx->ThebesContext(); gfxContext *gfxCtx = aCtx->ThebesContext();
@ -775,12 +786,14 @@ void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
rect.Deflate(e / 2.0); rect.Deflate(e / 2.0);
switch(mType) switch(mType)
{ {
case NOTATION_CIRCLE: case NOTATION_CIRCLE: {
gfxCtx->NewPath(); RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
gfxCtx->Ellipse(rect.Center(), rect.Size()); AppendEllipseToPath(builder, ToPoint(rect.Center()), ToSize(rect.Size()));
gfxCtx->Stroke(); RefPtr<Path> ellipse = builder->Finish();
drawTarget->Stroke(ellipse, color);
break; break;
}
case NOTATION_ROUNDEDBOX: case NOTATION_ROUNDEDBOX:
gfxCtx->NewPath(); gfxCtx->NewPath();
@ -844,7 +857,7 @@ void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
default: default:
NS_NOTREACHED("This notation can not be drawn using nsDisplayNotation"); NS_NOTREACHED("This notation can not be drawn using nsDisplayNotation");
break; break;
} }
gfxCtx->Restore(); gfxCtx->Restore();
} }