Bug 1083753, part 1 - Port the code that uses nsRenderingContext::FillRect(nscoord,...) to Moz2D. r=mattwoodrow

This commit is contained in:
Jonathan Watt 2014-10-19 11:55:36 +01:00
parent 9e43325322
commit c6407bc7fb
8 changed files with 56 additions and 72 deletions

View File

@ -259,13 +259,6 @@ nsRenderingContext::FillRect(const nsRect& aRect)
mThebes->Fill();
}
void
nsRenderingContext::FillRect(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight)
{
FillRect(nsRect(aX, aY, aWidth, aHeight));
}
//
// text
//

View File

@ -57,7 +57,6 @@ public:
void DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
void FillRect(const nsRect& aRect);
void FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
// Text

View File

@ -321,6 +321,9 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
nsLayoutUtils::GetColor(this, eCSSProperty_color)));
aRenderingContext.SetColor(nsLayoutUtils::GetColor(this, eCSSProperty_color));
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
nsAutoString text;
switch (listStyleType->GetStyle()) {
case NS_STYLE_LIST_STYLE_NONE:
@ -333,9 +336,7 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
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();
Rect devPxRect = NSRectToRect(rect, appUnitsPerDevPixel, *drawTarget);
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
AppendEllipseToPath(builder, devPxRect.Center(), devPxRect.Size());
RefPtr<Path> ellipse = builder->Finish();
@ -364,8 +365,8 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
pc->RoundAppUnitsToNearestDevPixels(rect.height));
snapRect.MoveBy((rect.width - snapRect.width) / 2,
(rect.height - snapRect.height) / 2);
aRenderingContext.FillRect(snapRect.x, snapRect.y,
snapRect.width, snapRect.height);
Rect devPxRect = NSRectToRect(snapRect, appUnitsPerDevPixel, *drawTarget);
drawTarget->FillRect(devPxRect, color);
}
break;
@ -391,9 +392,7 @@ nsBulletFrame::PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt,
rect.x = pc->RoundAppUnitsToNearestDevPixels(rect.x);
rect.y = pc->RoundAppUnitsToNearestDevPixels(rect.y);
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
int32_t appUnitsPerDevPixel = pc->AppUnitsPerDevPixel();
if (isDown) {
// to bottom
builder->MoveTo(NSPointToPoint(rect.TopLeft(), appUnitsPerDevPixel));

View File

@ -10,6 +10,8 @@
#include "nsPlaceholderFrame.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "nsDisplayList.h"
#include "nsFrameManager.h"
#include "nsLayoutUtils.h"
@ -17,6 +19,9 @@
#include "nsRenderingContext.h"
#include "nsIFrameInlines.h"
using namespace mozilla;
using namespace mozilla::gfx;
nsIFrame*
NS_NewPlaceholderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
nsFrameState aTypeBit)
@ -201,15 +206,21 @@ static void
PaintDebugPlaceholder(nsIFrame* aFrame, nsRenderingContext* aCtx,
const nsRect& aDirtyRect, nsPoint aPt)
{
aCtx->SetColor(NS_RGB(0, 255, 255));
ColorPattern cyan(ToDeviceColor(Color(0.f, 1.f, 1.f, 1.f)));
DrawTarget* drawTarget = aCtx->GetDrawTarget();
int32_t appUnitsPerDevPixel = aFrame->PresContext()->AppUnitsPerDevPixel();
nscoord x = nsPresContext::CSSPixelsToAppUnits(-5);
aCtx->FillRect(aPt.x + x, aPt.y,
nsPresContext::CSSPixelsToAppUnits(13),
nsPresContext::CSSPixelsToAppUnits(3));
nsRect r(aPt.x + x, aPt.y,
nsPresContext::CSSPixelsToAppUnits(13),
nsPresContext::CSSPixelsToAppUnits(3));
drawTarget->FillRect(NSRectToRect(r, appUnitsPerDevPixel), cyan);
nscoord y = nsPresContext::CSSPixelsToAppUnits(-10);
aCtx->FillRect(aPt.x, aPt.y + y,
nsPresContext::CSSPixelsToAppUnits(3),
nsPresContext::CSSPixelsToAppUnits(10));
r = nsRect(aPt.x, aPt.y + y,
nsPresContext::CSSPixelsToAppUnits(3),
nsPresContext::CSSPixelsToAppUnits(10));
drawTarget->FillRect(NSRectToRect(r, appUnitsPerDevPixel), cyan);
}
#endif // DEBUG

View File

@ -134,36 +134,3 @@ inFlasher::ScrollElementIntoView(nsIDOMElement *aElement)
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////
// inFlasher
void
inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
nsRenderingContext* aRenderContext,
bool aDrawBegin, bool aDrawEnd)
{
aRenderContext->SetColor(mColor);
DrawLine(aX, aY, aWidth, DIR_HORIZONTAL, BOUND_OUTER, aRenderContext);
if (aDrawBegin) {
DrawLine(aX, aY, aHeight, DIR_VERTICAL, BOUND_OUTER, aRenderContext);
}
DrawLine(aX, aY+aHeight, aWidth, DIR_HORIZONTAL, BOUND_INNER, aRenderContext);
if (aDrawEnd) {
DrawLine(aX+aWidth, aY, aHeight, DIR_VERTICAL, BOUND_INNER, aRenderContext);
}
}
void
inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength,
bool aDir, bool aBounds,
nsRenderingContext* aRenderContext)
{
nscoord thickTwips = nsPresContext::CSSPixelsToAppUnits(mThickness);
if (aDir) { // horizontal
aRenderContext->FillRect(aX, aY+(aBounds?0:-thickTwips), aLength, thickTwips);
} else { // vertical
aRenderContext->FillRect(aX+(aBounds?0:-thickTwips), aY, thickTwips, aLength);
}
}

View File

@ -28,13 +28,6 @@ public:
protected:
virtual ~inFlasher();
void DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
nsRenderingContext* aRenderContext,
bool aDrawBegin, bool aDrawEnd);
void DrawLine(nscoord aX, nscoord aY, nscoord aLength,
bool aDir, bool aBounds,
nsRenderingContext* aRenderContext);
nscolor mColor;
uint16_t mThickness;

View File

@ -5,6 +5,8 @@
#include "nsTextBoxFrame.h"
#include "gfxUtils.h"
#include "mozilla/gfx/2D.h"
#include "nsReadableUtils.h"
#include "nsCOMPtr.h"
#include "nsGkAtoms.h"
@ -39,6 +41,7 @@
#include "nsBidiPresUtils.h"
using namespace mozilla;
using namespace mozilla::gfx;
class nsAccessKeyInfo
{
@ -385,6 +388,8 @@ nsTextBoxFrame::DrawText(nsRenderingContext& aRenderingContext,
const nscolor* aOverrideColor)
{
nsPresContext* presContext = PresContext();
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
// paint the title
nscolor overColor;
@ -500,7 +505,9 @@ nsTextBoxFrame::DrawText(nsRenderingContext& aRenderingContext,
CalculateUnderline(*refContext);
aRenderingContext.SetColor(aOverrideColor ? *aOverrideColor : StyleColor()->mColor);
nscolor c = aOverrideColor ? *aOverrideColor : StyleColor()->mColor;
ColorPattern color(ToDeviceColor(c));
aRenderingContext.SetColor(c);
nsresult rv = NS_ERROR_FAILURE;
@ -550,10 +557,12 @@ nsTextBoxFrame::DrawText(nsRenderingContext& aRenderingContext,
}
if (mAccessKeyInfo && mAccessKeyInfo->mAccesskeyIndex != kNotFound) {
aRenderingContext.FillRect(aTextRect.x + mAccessKeyInfo->mBeforeWidth,
aTextRect.y + mAccessKeyInfo->mAccessOffset,
mAccessKeyInfo->mAccessWidth,
mAccessKeyInfo->mAccessUnderlineSize);
nsRect r(aTextRect.x + mAccessKeyInfo->mBeforeWidth,
aTextRect.y + mAccessKeyInfo->mAccessOffset,
mAccessKeyInfo->mAccessWidth,
mAccessKeyInfo->mAccessUnderlineSize);
Rect devPxRect = NSRectToRect(r, appUnitsPerDevPixel, *drawTarget);
drawTarget->FillRect(devPxRect, color);
}
// Strikeout is drawn on top of the text, per

View File

@ -3560,6 +3560,9 @@ nsTreeBodyFrame::PaintText(int32_t aRowIndex,
if (text.Length() == 0)
return; // Don't paint an empty string. XXX What about background/borders? Still paint?
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
// Resolve style for the text. It contains all the info we need to lay ourselves
// out and to paint.
nsStyleContext* textContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreecelltext);
@ -3609,6 +3612,7 @@ nsTreeBodyFrame::PaintText(int32_t aRowIndex,
textRect.Deflate(bp);
// Set our color.
ColorPattern color(ToDeviceColor(textContext->StyleColor()->mColor));
aRenderingContext.SetColor(textContext->StyleColor()->mColor);
// Draw decorations.
@ -3618,14 +3622,23 @@ nsTreeBodyFrame::PaintText(int32_t aRowIndex,
nscoord size;
if (decorations & (NS_FONT_DECORATION_OVERLINE | NS_FONT_DECORATION_UNDERLINE)) {
fontMet->GetUnderline(offset, size);
if (decorations & NS_FONT_DECORATION_OVERLINE)
aRenderingContext.FillRect(textRect.x, textRect.y, textRect.width, size);
if (decorations & NS_FONT_DECORATION_UNDERLINE)
aRenderingContext.FillRect(textRect.x, textRect.y + baseline - offset, textRect.width, size);
if (decorations & NS_FONT_DECORATION_OVERLINE) {
nsRect r(textRect.x, textRect.y, textRect.width, size);
Rect devPxRect = NSRectToRect(r, appUnitsPerDevPixel, *drawTarget);
drawTarget->FillRect(devPxRect, color);
}
if (decorations & NS_FONT_DECORATION_UNDERLINE) {
nsRect r(textRect.x, textRect.y + baseline - offset,
textRect.width, size);
Rect devPxRect = NSRectToRect(r, appUnitsPerDevPixel, *drawTarget);
drawTarget->FillRect(devPxRect, color);
}
}
if (decorations & NS_FONT_DECORATION_LINE_THROUGH) {
fontMet->GetStrikeout(offset, size);
aRenderingContext.FillRect(textRect.x, textRect.y + baseline - offset, textRect.width, size);
nsRect r(textRect.x, textRect.y + baseline - offset, textRect.width, size);
Rect devPxRect = NSRectToRect(r, appUnitsPerDevPixel, *drawTarget);
drawTarget->FillRect(devPxRect, color);
}
nsStyleContext* cellContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreecell);