gecko/layout/forms/nsGfxCheckboxControlFrame.cpp
Ehsan Akhgari 0fd9123eac Bug 579517 - Part 1: Automated conversion of NSPR numeric types to stdint types in Gecko; r=bsmedberg
This patch was generated by a script.  Here's the source of the script for
future reference:

function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
       ! -wholename "*security/nss*" \
       ! -wholename "*/.hg*" \
       ! -wholename "obj-ff-dbg*" \
       ! -name nsXPCOMCID.h \
       ! -name prtypes.h \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t

convert PRIntn int
convert PRUintn unsigned

convert PRSize size_t

convert PROffset32 int32_t
convert PROffset64 int64_t

convert PRPtrdiff ptrdiff_t

convert PRFloat64 double
2012-08-22 11:56:38 -04:00

147 lines
4.8 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "nsGfxCheckboxControlFrame.h"
#include "nsIContent.h"
#include "nsCOMPtr.h"
#include "nsCSSRendering.h"
#include "nsRenderingContext.h"
#ifdef ACCESSIBILITY
#include "nsAccessibilityService.h"
#endif
#include "nsIServiceManager.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsDisplayList.h"
#include "nsCSSAnonBoxes.h"
static void
PaintCheckMark(nsIFrame* aFrame,
nsRenderingContext* aCtx,
const nsRect& aDirtyRect,
nsPoint aPt)
{
nsRect rect(aPt, aFrame->GetSize());
rect.Deflate(aFrame->GetUsedBorderAndPadding());
// Points come from the coordinates on a 7X7 unit box centered at 0,0
const int32_t checkPolygonX[] = { -3, -1, 3, 3, -1, -3 };
const int32_t checkPolygonY[] = { -1, 1, -3, -1, 3, 1 };
const int32_t checkNumPoints = sizeof(checkPolygonX) / sizeof(int32_t);
const int32_t checkSize = 9; // 2 units of padding on either side
// of the 7x7 unit checkmark
// Scale the checkmark based on the smallest dimension
nscoord paintScale = NS_MIN(rect.width, rect.height) / checkSize;
nsPoint paintCenter(rect.x + rect.width / 2,
rect.y + rect.height / 2);
nsPoint paintPolygon[checkNumPoints];
// Convert checkmark for screen rendering
for (int32_t polyIndex = 0; polyIndex < checkNumPoints; polyIndex++) {
paintPolygon[polyIndex] = paintCenter +
nsPoint(checkPolygonX[polyIndex] * paintScale,
checkPolygonY[polyIndex] * paintScale);
}
aCtx->SetColor(aFrame->GetStyleColor()->mColor);
aCtx->FillPolygon(paintPolygon, checkNumPoints);
}
static void
PaintIndeterminateMark(nsIFrame* aFrame,
nsRenderingContext* aCtx,
const nsRect& aDirtyRect,
nsPoint aPt)
{
nsRect rect(aPt, aFrame->GetSize());
rect.Deflate(aFrame->GetUsedBorderAndPadding());
rect.y += (rect.height - rect.height/4) / 2;
rect.height /= 4;
aCtx->SetColor(aFrame->GetStyleColor()->mColor);
aCtx->FillRect(rect);
}
//------------------------------------------------------------
nsIFrame*
NS_NewGfxCheckboxControlFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext)
{
return new (aPresShell) nsGfxCheckboxControlFrame(aContext);
}
NS_IMPL_FRAMEARENA_HELPERS(nsGfxCheckboxControlFrame)
//------------------------------------------------------------
// Initialize GFX-rendered state
nsGfxCheckboxControlFrame::nsGfxCheckboxControlFrame(nsStyleContext* aContext)
: nsFormControlFrame(aContext)
{
}
nsGfxCheckboxControlFrame::~nsGfxCheckboxControlFrame()
{
}
#ifdef ACCESSIBILITY
already_AddRefed<Accessible>
nsGfxCheckboxControlFrame::CreateAccessible()
{
nsAccessibilityService* accService = nsIPresShell::AccService();
if (accService) {
return accService->CreateHTMLCheckboxAccessible(mContent,
PresContext()->PresShell());
}
return nullptr;
}
#endif
//------------------------------------------------------------
NS_IMETHODIMP
nsGfxCheckboxControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists)
{
nsresult rv = nsFormControlFrame::BuildDisplayList(aBuilder, aDirtyRect,
aLists);
NS_ENSURE_SUCCESS(rv, rv);
// Get current checked state through content model.
if ((!IsChecked() && !IsIndeterminate()) || !IsVisibleForPainting(aBuilder))
return NS_OK; // we're not checked or not visible, nothing to paint.
if (IsThemed())
return NS_OK; // No need to paint the checkmark. The theme will do it.
return aLists.Content()->AppendNewToTop(new (aBuilder)
nsDisplayGeneric(aBuilder, this,
IsIndeterminate()
? PaintIndeterminateMark : PaintCheckMark,
"CheckedCheckbox",
nsDisplayItem::TYPE_CHECKED_CHECKBOX));
}
//------------------------------------------------------------
bool
nsGfxCheckboxControlFrame::IsChecked()
{
nsCOMPtr<nsIDOMHTMLInputElement> elem(do_QueryInterface(mContent));
bool retval = false;
elem->GetChecked(&retval);
return retval;
}
bool
nsGfxCheckboxControlFrame::IsIndeterminate()
{
nsCOMPtr<nsIDOMHTMLInputElement> elem(do_QueryInterface(mContent));
bool retval = false;
elem->GetIndeterminate(&retval);
return retval;
}