Bug 1083597 - Port the code that uses nsRenderingContext::DrawRect() to Moz2D. r=mattwoodrow

This commit is contained in:
Jonathan Watt 2014-10-17 15:06:34 +01:00
parent e20775a0d6
commit 9f5596b76b
6 changed files with 58 additions and 55 deletions

View File

@ -163,21 +163,6 @@ nsRenderingContext::DrawLine(nscoord aX0, nscoord aY0,
}
}
void
nsRenderingContext::DrawRect(const nsRect& aRect)
{
mThebes->NewPath();
mThebes->Rectangle(GFX_RECT_FROM_TWIPS_RECT(aRect), true);
mThebes->Stroke();
}
void
nsRenderingContext::DrawRect(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight)
{
DrawRect(nsRect(aX, aY, aWidth, aHeight));
}
/* Clamp r to (0,0) (2^23,2^23)
* these are to be device coordinates.

View File

@ -56,9 +56,6 @@ public:
void DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
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 FillRect(const nsRect& aRect);
void FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);

View File

@ -11,8 +11,10 @@
#include <stdarg.h>
#include <algorithm>
#include "gfxUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/gfx/2D.h"
#include "nsCOMPtr.h"
#include "nsFrameList.h"
@ -1720,19 +1722,21 @@ ApplyOverflowClipping(nsDisplayListBuilder* aBuilder,
static void PaintDebugBorder(nsIFrame* aFrame, nsRenderingContext* aCtx,
const nsRect& aDirtyRect, nsPoint aPt) {
nsRect r(aPt, aFrame->GetSize());
if (aFrame->HasView()) {
aCtx->SetColor(NS_RGB(0,0,255));
} else {
aCtx->SetColor(NS_RGB(255,0,0));
}
aCtx->DrawRect(r);
DrawTarget* drawTarget = aCtx->GetDrawTarget();
int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
Color blueOrRed(aFrame->HasView() ? Color(0.f, 0.f, 1.f, 1.f) :
Color(1.f, 0.f, 0.f, 1.f));
drawTarget->StrokeRect(NSRectToRect(r, appUnitsPerDevPixel),
ColorPattern(ToDeviceColor(blueOrRed)));
}
static void PaintEventTargetBorder(nsIFrame* aFrame, nsRenderingContext* aCtx,
const nsRect& aDirtyRect, nsPoint aPt) {
nsRect r(aPt, aFrame->GetSize());
aCtx->SetColor(NS_RGB(128,0,128));
aCtx->DrawRect(r);
DrawTarget* drawTarget = aCtx->GetDrawTarget();
int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
ColorPattern purple(ToDeviceColor(Color(.5f, 0.f, .5f, 1.f)));
drawTarget->StrokeRect(NSRectToRect(r, appUnitsPerDevPixel), purple);
}
static void

View File

@ -4,6 +4,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsMathMLFrame.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "nsLayoutUtils.h"
#include "nsNameSpaceManager.h"
#include "nsMathMLChar.h"
#include "nsCSSPseudoElements.h"
@ -15,6 +19,9 @@
#include "nsDisplayList.h"
#include "nsRenderingContext.h"
using namespace mozilla;
using namespace mozilla::gfx;
eMathMLFrameType
nsMathMLFrame::GetMathMLFrameType()
{
@ -309,8 +316,11 @@ private:
void nsDisplayMathMLBoundingMetrics::Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx)
{
aCtx->SetColor(NS_RGB(0,0,255));
aCtx->DrawRect(mRect + ToReferenceFrame());
DrawTarget* drawTarget = aRenderingContext->GetDrawTarget();
Rect r = NSRectToRect(mRect + ToReferenceFrame(),
mFrame->PresContext()->AppUnitsPerDevPixel());
ColorPattern blue(ToDeviceColor(Color(0.f, 0.f, 1.f, 1.f)));
drawTarget->StrokeRect(r, blue);
}
nsresult

View File

@ -2,9 +2,14 @@
/* 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/. */
#include "nsTableCellFrame.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/Helpers.h"
#include "nsTableFrame.h"
#include "nsTableColFrame.h"
#include "nsTableCellFrame.h"
#include "nsTableRowFrame.h"
#include "nsTableRowGroupFrame.h"
#include "nsTablePainter.h"
@ -34,7 +39,7 @@
#include "mozilla/LookAndFeel.h"
using namespace mozilla;
using namespace mozilla::gfx;
nsTableCellFrame::nsTableCellFrame(nsStyleContext* aContext) :
nsContainerFrame(aContext)
@ -318,14 +323,15 @@ nsTableCellFrame::DecorateForSelection(nsRenderingContext& aRenderingContext,
bordercolor = EnsureDifferentColors(bordercolor,
StyleBackground()->mBackgroundColor);
gfxContext* ctx = aRenderingContext.ThebesContext();
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
Point devPixelOffset = NSPointToPoint(aPt, appUnitsPerDevPixel);
gfxPoint devPixelOffset =
nsLayoutUtils::PointToGfxPoint(aPt,
PresContext()->AppUnitsPerDevPixel());
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
AutoRestoreTransform autoRestoreTransform(drawTarget);
drawTarget->SetTransform(
drawTarget->GetTransform().PreTranslate(devPixelOffset));
gfxContextMatrixAutoSaveRestore autoSR(ctx);
ctx->SetMatrix(ctx->CurrentMatrix().Translate(devPixelOffset));
ColorPattern color(ToDeviceColor(bordercolor));
nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1);
@ -335,8 +341,9 @@ nsTableCellFrame::DecorateForSelection(nsRenderingContext& aRenderingContext,
aRenderingContext.DrawLine(onePixel, mRect.height, mRect.width, mRect.height);
aRenderingContext.DrawLine(mRect.width, onePixel, mRect.width, mRect.height);
//middle
aRenderingContext.DrawRect(onePixel, onePixel, mRect.width-onePixel,
mRect.height-onePixel);
nsRect r(onePixel, onePixel,
mRect.width - onePixel, mRect.height - onePixel);
drawTarget->StrokeRect(NSRectToRect(r, appUnitsPerDevPixel), color);
//shading
aRenderingContext.DrawLine(2*onePixel, mRect.height-2*onePixel,
mRect.width-onePixel, mRect.height- (2*onePixel));

View File

@ -31,8 +31,11 @@
// any number of syblings around the box. Basically any children in the reflow chain must have their caches cleared
// so when asked for there current size they can relayout themselves.
#include "nsBoxLayoutState.h"
#include "nsBoxFrame.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "nsBoxLayoutState.h"
#include "mozilla/dom/Touch.h"
#include "nsStyleContext.h"
#include "nsPlaceholderFrame.h"
@ -71,6 +74,7 @@
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::gfx;
//define DEBUG_REDRAW
@ -1429,45 +1433,41 @@ nsBoxFrame::PaintXULDebugBackground(nsRenderingContext& aRenderingContext,
inner.Deflate(border);
//nsRect borderRect(inner);
nscolor color;
if (isHorizontal) {
color = NS_RGB(0,0,255);
} else {
color = NS_RGB(255,0,0);
}
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
aRenderingContext.SetColor(color);
ColorPattern color(ToDeviceColor(isHorizontal ? Color(0.f, 0.f, 1.f, 1.f) :
Color(1.f, 0.f, 0.f, 1.f));
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
//left
nsRect r(inner);
r.width = debugBorder.left;
aRenderingContext.FillRect(r);
drawTarget->FillRect(NSRectToRect(r, appUnitsPerDevPixel), color);
// top
r = inner;
r.height = debugBorder.top;
aRenderingContext.FillRect(r);
drawTarget->FillRect(NSRectToRect(r, appUnitsPerDevPixel), color);
//right
r = inner;
r.x = r.x + r.width - debugBorder.right;
r.width = debugBorder.right;
aRenderingContext.FillRect(r);
drawTarget->FillRect(NSRectToRect(r, appUnitsPerDevPixel), color);
//bottom
r = inner;
r.y = r.y + r.height - debugBorder.bottom;
r.height = debugBorder.bottom;
aRenderingContext.FillRect(r);
drawTarget->FillRect(NSRectToRect(r, appUnitsPerDevPixel), color);
// if we have dirty children or we are dirty
// place a green border around us.
if (NS_SUBTREE_DIRTY(this)) {
nsRect dirtyr(inner);
aRenderingContext.SetColor(NS_RGB(0,255,0));
aRenderingContext.DrawRect(dirtyr);
aRenderingContext.SetColor(color);
nsRect dirty(inner);
ColorPattern green(ToDeviceColor(Color0.f, 1.f, 0.f, 1.f)));
drawTarget->StrokeRect(NSRectToRect(dirty, appUnitsPerDevPixel), green);
}
}