mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-31 21:21:08 +00:00
Bug 1083221 - Port the code that uses nsRenderingContext::DrawEllipse/FillEllipse and gfxContext::Ellipse to Moz2D. r=mattwoodrow
This commit is contained in:
parent
cd9122458b
commit
953853c7bd
@ -328,36 +328,6 @@ nsRenderingContext::FillRect(nscoord aX, nscoord aY,
|
||||
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
|
||||
nsRenderingContext::FillPolygon(const nsPoint twPoints[], int32_t aNumPoints)
|
||||
{
|
||||
|
@ -62,15 +62,11 @@ public:
|
||||
void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
|
||||
void DrawRect(const nsRect& aRect);
|
||||
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(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
void FillPolygon(const nsPoint aPoints[], int32_t aNumPoints);
|
||||
|
||||
void FillEllipse(const nsRect& aRect);
|
||||
void FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
// Text
|
||||
|
||||
void SetFont(nsFontMetrics *aFontMetrics);
|
||||
|
@ -386,16 +386,6 @@ gfxContext::Rectangle(const gfxRect& rect, bool snapToPixels)
|
||||
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
|
||||
gfxContext::Polygon(const gfxPoint *points, uint32_t numPoints)
|
||||
{
|
||||
|
@ -205,14 +205,6 @@ public:
|
||||
void Rectangle(const gfxRect& rect, bool snapToPixels = false);
|
||||
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
|
||||
*/
|
||||
|
@ -4,10 +4,16 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsGfxRadioControlFrame.h"
|
||||
|
||||
#include "gfx2DGlue.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/PathHelpers.h"
|
||||
#include "nsLayoutUtils.h"
|
||||
#include "nsRenderingContext.h"
|
||||
#include "nsDisplayList.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
nsIFrame*
|
||||
NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
||||
@ -49,8 +55,17 @@ PaintCheckedRadioButton(nsIFrame* aFrame,
|
||||
rect.Deflate(nsPresContext::CSSPixelsToAppUnits(2),
|
||||
nsPresContext::CSSPixelsToAppUnits(2));
|
||||
|
||||
aCtx->SetColor(aFrame->StyleColor()->mColor);
|
||||
aCtx->FillEllipse(rect);
|
||||
Rect devPxRect =
|
||||
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
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
#include "nsBulletFrame.h"
|
||||
|
||||
#include "gfx2DGlue.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/PathHelpers.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsGkAtoms.h"
|
||||
@ -32,6 +35,7 @@
|
||||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
NS_DECLARE_FRAME_PROPERTY(FontSizeInflationProperty, nullptr)
|
||||
|
||||
@ -312,7 +316,9 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
|
||||
}
|
||||
|
||||
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;
|
||||
switch (listStyleType->GetStyle()) {
|
||||
@ -320,15 +326,24 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
|
||||
break;
|
||||
|
||||
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:
|
||||
aRenderingContext.DrawEllipse(padding.left + aPt.x, padding.top + aPt.y,
|
||||
mRect.width - (padding.left + padding.right),
|
||||
mRect.height - (padding.top + padding.bottom));
|
||||
{
|
||||
nsRect rect(padding.left + aPt.x,
|
||||
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;
|
||||
|
||||
case NS_STYLE_LIST_STYLE_SQUARE:
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "mozilla/EventStates.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/Helpers.h"
|
||||
#include "mozilla/gfx/PathHelpers.h"
|
||||
#include "mozilla/MouseEvents.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
@ -73,24 +74,21 @@
|
||||
#include "mozilla/dom/Link.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::layers;
|
||||
|
||||
// sizes (pixels) for image icon, padding and border frame
|
||||
#define ICON_SIZE (16)
|
||||
#define ICON_PADDING (3)
|
||||
#define ALT_BORDER_WIDTH (1)
|
||||
|
||||
|
||||
//we must add hooks soon
|
||||
#define IMAGE_EDITOR_CHECK 1
|
||||
|
||||
// Default alignment value (so we can tell an unset value from a set value)
|
||||
#define ALIGN_UNSET uint8_t(-1)
|
||||
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
// static icon information
|
||||
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
|
||||
// just draw some graffiti in the mean time
|
||||
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) ?
|
||||
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);
|
||||
aRenderingContext.DrawRect(iconXPos, inner.y,size,size);
|
||||
aRenderingContext.ThebesContext()->Save();
|
||||
aRenderingContext.SetColor(NS_RGB(0xFF,0,0));
|
||||
aRenderingContext.FillEllipse(size/2 + iconXPos, size/2 + inner.y,
|
||||
size/2 - twoPX, size/2 - twoPX);
|
||||
aRenderingContext.ThebesContext()->Restore();
|
||||
rect = nsRect(iconXPos + size/2, inner.y + size/2,
|
||||
size/2 - twoPX, size/2 - twoPX);
|
||||
devPxRect =
|
||||
ToRect(nsLayoutUtils::RectToGfxRect(rect, PresContext()->AppUnitsPerDevPixel()));
|
||||
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
|
||||
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
|
||||
|
@ -4,6 +4,10 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsMathMLmencloseFrame.h"
|
||||
|
||||
#include "gfx2DGlue.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/PathHelpers.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsRenderingContext.h"
|
||||
#include "nsWhitespaceTokenizer.h"
|
||||
@ -13,6 +17,9 @@
|
||||
#include "nsMathMLChar.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
//
|
||||
// <menclose> -- enclose content with a stretching symbol such
|
||||
// as a long division sign. - implementation
|
||||
@ -764,7 +771,11 @@ void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
|
||||
gfxRect rect = presContext->AppUnitsToGfxUnits(mRect + ToReferenceFrame());
|
||||
|
||||
// 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
|
||||
gfxContext *gfxCtx = aCtx->ThebesContext();
|
||||
@ -775,12 +786,14 @@ void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
|
||||
rect.Deflate(e / 2.0);
|
||||
|
||||
switch(mType)
|
||||
{
|
||||
case NOTATION_CIRCLE:
|
||||
gfxCtx->NewPath();
|
||||
gfxCtx->Ellipse(rect.Center(), rect.Size());
|
||||
gfxCtx->Stroke();
|
||||
{
|
||||
case NOTATION_CIRCLE: {
|
||||
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
|
||||
AppendEllipseToPath(builder, ToPoint(rect.Center()), ToSize(rect.Size()));
|
||||
RefPtr<Path> ellipse = builder->Finish();
|
||||
drawTarget->Stroke(ellipse, color);
|
||||
break;
|
||||
}
|
||||
|
||||
case NOTATION_ROUNDEDBOX:
|
||||
gfxCtx->NewPath();
|
||||
@ -844,7 +857,7 @@ void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
|
||||
default:
|
||||
NS_NOTREACHED("This notation can not be drawn using nsDisplayNotation");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gfxCtx->Restore();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user