Remove the special painting code for a 165-twips checkbox. Move the remaining parts of nsFormControlHelper to its consumers and remove nsFormControlHelper.{cpp,h} from the tree. b=343495 r+sr=roc (r=me on roc's part)

This commit is contained in:
mats.palmgren%bredband.net 2006-07-06 10:43:51 +00:00
parent 1119bbd88f
commit 47bd18fde6
18 changed files with 137 additions and 627 deletions

View File

@ -38,6 +38,7 @@
#include "nsLayoutUtils.h"
#include "nsIFrame.h"
#include "nsIFontMetrics.h"
#include "nsIFormControlFrame.h"
#include "nsPresContext.h"
#include "nsIContent.h"
@ -980,3 +981,14 @@ nsLayoutUtils::GetAllInFlowBoundingRect(nsIFrame* aFrame)
return r - aFrame->GetPosition();
}
nsresult
nsLayoutUtils::GetFontMetricsForFrame(nsIFrame* aFrame,
nsIFontMetrics** aFontMetrics)
{
nsStyleContext* sc = aFrame->GetStyleContext();
return aFrame->GetPresContext()->DeviceContext()->
GetMetricsFor(sc->GetStyleFont()->mFont,
sc->GetStyleVisibility()->mLangGroup,
*aFontMetrics);
}

View File

@ -48,6 +48,7 @@ class nsIScrollableFrame;
class nsIDOMEvent;
class nsRegion;
class nsDisplayListBuilder;
class nsIFontMetrics;
#include "prtypes.h"
#include "nsStyleContext.h"
@ -421,6 +422,15 @@ public:
* differently from others.
*/
static nsRect GetAllInFlowBoundingRect(nsIFrame* aFrame);
/**
* Get the font metrics corresponding to the frame's style data.
* @param aFrame the frame
* @param aFontMetrics the font metrics result
* @return success or failure code
*/
static nsresult GetFontMetricsForFrame(nsIFrame* aFrame,
nsIFontMetrics** aFontMetrics);
};
#endif // nsLayoutUtils_h__

View File

@ -89,7 +89,6 @@ CPPSRCS = \
nsFieldSetFrame.cpp \
nsFileControlFrame.cpp \
nsFormControlFrame.cpp \
nsFormControlHelper.cpp \
nsGfxButtonControlFrame.cpp \
nsGfxCheckboxControlFrame.cpp \
nsGfxRadioControlFrame.cpp \

View File

@ -88,6 +88,7 @@
#include "nsStyleSet.h"
#include "nsNodeInfoManager.h"
#include "nsContentCreatorFunctions.h"
#include "nsLayoutUtils.h"
#include "nsDisplayList.h"
#ifdef MOZ_XUL
@ -625,7 +626,9 @@ nsComboboxControlFrame::ReflowItems(nsPresContext* aPresContext,
//printf("*****************\n");
nscoord visibleHeight = 0;
nsCOMPtr<nsIFontMetrics> fontMet;
nsresult res = nsFormControlHelper::GetFrameFontFM(mDisplayFrame, getter_AddRefs(fontMet));
nsresult res =
nsLayoutUtils::GetFontMetricsForFrame(mDisplayFrame,
getter_AddRefs(fontMet));
if (fontMet) {
fontMet->GetHeight(visibleHeight);
}
@ -1481,7 +1484,7 @@ nsComboboxControlFrame::GetFrameName(nsAString& aResult) const
void
nsComboboxControlFrame::ShowDropDown(PRBool aDoDropDown)
{
if (nsFormControlHelper::GetDisabled(mContent)) {
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) {
return;
}
@ -1702,7 +1705,7 @@ nsComboboxControlFrame::HandleEvent(nsPresContext* aPresContext,
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
return NS_OK;
}
if (nsFormControlHelper::GetDisabled(mContent)) {
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) {
return NS_OK;
}
@ -2073,7 +2076,8 @@ void nsComboboxControlFrame::PaintFocus(nsIRenderingContext& aRenderingContext,
/////////////////////
// draw focus
// XXX This is only temporary
if (!nsFormControlHelper::GetDisabled(mContent) && mFocused == this) {
if (!mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled) &&
mFocused == this) {
aRenderingContext.SetLineStyle(nsLineStyle_kDotted);
aRenderingContext.SetColor(0);
} else {

View File

@ -581,7 +581,7 @@ nsFileControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
// just to catch events
// REVIEW: I'm not sure why we do this, but that's what nsFileControlFrame::
// GetFrameForPoint was doing
if (nsFormControlHelper::GetDisabled(mContent) &&
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled) &&
IsVisibleForPainting(aBuilder)) {
nsDisplayItem* item = new (aBuilder) nsDisplayEventReceiver(this);
if (!item)

View File

@ -45,7 +45,6 @@
#include "nsCOMPtr.h"
#include "nsTextControlFrame.h"
#include "nsFormControlHelper.h"
typedef nsTextControlFrame nsNewFrame;
class nsISupportsArray;

View File

@ -1,333 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsFormControlHelper.h"
#include "nsHTMLParts.h"
#include "nsGenericHTMLElement.h"
#include "nsIRenderingContext.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "nsStyleContext.h"
#include "nsLeafFrame.h"
#include "nsCSSRendering.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsCoord.h"
#include "nsWidgetsCID.h"
#include "nsViewsCID.h"
#include "nsIComponentManager.h"
#include "nsGUIEvent.h"
#include "nsIFontMetrics.h"
#include "nsIFormControl.h"
#include "nsIDeviceContext.h"
#include "nsHTMLAtoms.h"
#include "nsISupports.h"
#include "nsStyleConsts.h"
#include "nsUnitConversion.h"
#include "nsIContent.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsNetCID.h"
// Needed for Localization
#include "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsITextContent.h"
#include "nsISupportsArray.h"
#include "nsXPIDLString.h"
// done I10N
nsFormControlHelper::nsFormControlHelper()
{
MOZ_COUNT_CTOR(nsFormControlHelper);
}
nsFormControlHelper::~nsFormControlHelper()
{
MOZ_COUNT_DTOR(nsFormControlHelper);
}
void nsFormControlHelper::PlatformToDOMLineBreaks(nsString &aString)
{
// Windows linebreaks: Map CRLF to LF:
aString.ReplaceSubstring(NS_LITERAL_STRING("\r\n").get(), NS_LITERAL_STRING("\n").get());
// Mac linebreaks: Map any remaining CR to LF:
aString.ReplaceSubstring(NS_LITERAL_STRING("\r").get(), NS_LITERAL_STRING("\n").get());
}
PRBool nsFormControlHelper::GetBool(const nsAString& aValue)
{
return aValue.Equals(NS_STRING_TRUE);
}
void nsFormControlHelper::GetBoolString(const PRBool aValue,
nsAString& aResult)
{
if (aValue)
aResult.Assign(NS_STRING_TRUE);
else
aResult.Assign(NS_STRING_FALSE);
}
nsresult nsFormControlHelper::GetFrameFontFM(nsIFrame* aFrame,
nsIFontMetrics** aFontMet)
{
nsStyleContext* sc = aFrame->GetStyleContext();
return aFrame->GetPresContext()->DeviceContext()->
GetMetricsFor(sc->GetStyleFont()->mFont,
sc->GetStyleVisibility()->mLangGroup,
*aFontMet);
}
PRBool
nsFormControlHelper::GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp)
{
// soft is the default; "physical" defaults to soft as well because all other
// browsers treat it that way and there is no real reason to maintain physical
// and virtual as separate entities if no one else does. Only hard and off
// do anything different.
aWrapProp = eHTMLTextWrap_Soft; // the default
nsAutoString wrap;
if (aContent->IsNodeOfType(nsINode::eHTML)) {
static nsIContent::AttrValuesArray strings[] =
{&nsHTMLAtoms::HARD, &nsHTMLAtoms::OFF, nsnull};
switch (aContent->FindAttrValueIn(kNameSpaceID_None, nsHTMLAtoms::wrap,
strings, eIgnoreCase)) {
case 0: aWrapProp = eHTMLTextWrap_Hard; break;
case 1: aWrapProp = eHTMLTextWrap_Off; break;
}
return PR_TRUE;
}
return PR_FALSE;
}
//
//-------------------------------------------------------------------------------------
// Utility methods for rendering Form Elements using GFX
//-------------------------------------------------------------------------------------
//
void
nsFormControlHelper::PaintLine(nsIRenderingContext& aRenderingContext,
nscoord aSX, nscoord aSY, nscoord aEX, nscoord aEY,
PRBool aHorz, nscoord aWidth, nscoord aOnePixel)
{
nsPoint p[5];
if (aHorz) {
aEX++;
p[0].x = nscoord(float(aSX)*aOnePixel);
p[0].y = nscoord(float(aSY)*aOnePixel);
p[1].x = nscoord(float(aEX)*aOnePixel);
p[1].y = nscoord(float(aEY)*aOnePixel);
p[2].x = nscoord(float(aEX)*aOnePixel);
p[2].y = nscoord(float(aEY+1)*aOnePixel);
p[3].x = nscoord(float(aSX)*aOnePixel);
p[3].y = nscoord(float(aSY+1)*aOnePixel);
p[4].x = nscoord(float(aSX)*aOnePixel);
p[4].y = nscoord(float(aSY)*aOnePixel);
} else {
aEY++;
p[0].x = nscoord(float(aSX)*aOnePixel);
p[0].y = nscoord(float(aSY)*aOnePixel);
p[1].x = nscoord(float(aEX)*aOnePixel);
p[1].y = nscoord(float(aEY)*aOnePixel);
p[2].x = nscoord(float(aEX+1)*aOnePixel);
p[2].y = nscoord(float(aEY)*aOnePixel);
p[3].x = nscoord(float(aSX+1)*aOnePixel);
p[3].y = nscoord(float(aSY)*aOnePixel);
p[4].x = nscoord(float(aSX)*aOnePixel);
p[4].y = nscoord(float(aSY)*aOnePixel);
}
aRenderingContext.FillPolygon(p, 5);
}
//---------------------------------------------------------------------------
void
nsFormControlHelper::SetupPoints(PRUint32 aNumberOfPoints, nscoord* aPoints, nsPoint* aPolygon, nscoord aScaleFactor, nscoord aX, nscoord aY,
nscoord aCenterX, nscoord aCenterY)
{
const nscoord offsetX = aCenterX * aScaleFactor;
const nscoord offsetY = aCenterY * aScaleFactor;
PRUint32 i = 0;
PRUint32 count = 0;
for (i = 0; i < aNumberOfPoints; i++) {
aPolygon[i].x = (aPoints[count] * aScaleFactor) + aX - offsetX;
count++;
aPolygon[i].y = (aPoints[count] * aScaleFactor) + aY - offsetY;
count++;
}
}
void
nsFormControlHelper::PaintFixedSizeCheckMark(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips)
{
// Offsets to x,y location, These offsets are used to place the checkmark in the middle
// of it's 12X12 pixel box.
const PRUint32 ox = 3;
const PRUint32 oy = 3;
nscoord onePixel = NSIntPixelsToTwips(1, aPixelsToTwips);
// Draw checkmark using a series of rectangles. This builds an replica of the
// way the checkmark looks under Windows. Using a polygon does not correctly
// represent a checkmark under Windows. This is due to round-off error in the
// Twips to Pixel conversions.
PaintLine(aRenderingContext, 0 + ox, 2 + oy, 0 + ox, 4 + oy, PR_FALSE, 1, onePixel);
PaintLine(aRenderingContext, 1 + ox, 3 + oy, 1 + ox, 5 + oy, PR_FALSE, 1, onePixel);
PaintLine(aRenderingContext, 2 + ox, 4 + oy, 2 + ox, 6 + oy, PR_FALSE, 1, onePixel);
PaintLine(aRenderingContext, 3 + ox, 3 + oy, 3 + ox, 5 + oy, PR_FALSE, 1, onePixel);
PaintLine(aRenderingContext, 4 + ox, 2 + oy, 4 + ox, 4 + oy, PR_FALSE, 1, onePixel);
PaintLine(aRenderingContext, 5 + ox, 1 + oy, 5 + ox, 3 + oy, PR_FALSE, 1, onePixel);
PaintLine(aRenderingContext, 6 + ox, 0 + oy, 6 + ox, 2 + oy, PR_FALSE, 1, onePixel);
}
void
nsFormControlHelper::PaintFixedSizeCheckMarkBorder(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips, const nsStyleColor& aBackgroundColor)
{
// Offsets to x,y location
PRUint32 ox = 0;
PRUint32 oy = 0;
nscoord onePixel = NSIntPixelsToTwips(1, aPixelsToTwips);
nscoord twelvePixels = NSIntPixelsToTwips(12, aPixelsToTwips);
// Draw Background
aRenderingContext.SetColor(aBackgroundColor.mColor);
nsRect rect(0, 0, twelvePixels, twelvePixels);
aRenderingContext.FillRect(rect);
// Draw Border
aRenderingContext.SetColor(NS_RGB(128, 128, 128));
PaintLine(aRenderingContext, 0 + ox, 0 + oy, 11 + ox, 0 + oy, PR_TRUE, 1, onePixel);
PaintLine(aRenderingContext, 0 + ox, 0 + oy, 0 + ox, 11 + oy, PR_FALSE, 1, onePixel);
aRenderingContext.SetColor(NS_RGB(192, 192, 192));
PaintLine(aRenderingContext, 1 + ox, 11 + oy, 11 + ox, 11 + oy, PR_TRUE, 1, onePixel);
PaintLine(aRenderingContext, 11 + ox, 1 + oy, 11 + ox, 11 + oy, PR_FALSE, 1, onePixel);
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
PaintLine(aRenderingContext, 1 + ox, 1 + oy, 10 + ox, 1 + oy, PR_TRUE, 1, onePixel);
PaintLine(aRenderingContext, 1 + ox, 1 + oy, 1 + ox, 10 + oy, PR_FALSE, 1, onePixel);
}
//Draw a checkmark in any size.
void
nsFormControlHelper::PaintCheckMark(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips, const nsRect & aRect)
{
// Width and height of the fixed size checkmark in TWIPS.
const PRInt32 fixedSizeCheckmarkWidth = 165;
const PRInt32 fixedSizeCheckmarkHeight = 165;
if ((fixedSizeCheckmarkWidth == aRect.width) &&
(fixedSizeCheckmarkHeight == aRect.height)) {
// Standard size, so draw a fixed size check mark instead of a scaled check mark.
PaintFixedSizeCheckMark(aRenderingContext, aPixelsToTwips);
return;
}
const PRUint32 checkpoints = 7;
const PRUint32 checksize = 9; //This is value is determined by added 2 units to the end
//of the 7X& pixel rectangle below to provide some white space
//around the checkmark when it is rendered.
// Points come from the coordinates on a 7X7 pixels
// box with 0,0 at the lower left.
nscoord checkedPolygonDef[] = {0,2, 2,4, 6,0 , 6,2, 2,6, 0,4, 0,2 };
// Location of the center point of the checkmark
const PRUint32 centerx = 3;
const PRUint32 centery = 3;
nsPoint checkedPolygon[checkpoints];
PRUint32 defIndex = 0;
PRUint32 polyIndex = 0;
// Scale the checkmark based on the smallest dimension
PRUint32 size = aRect.width / checksize;
if (aRect.height < aRect.width) {
size = aRect.height / checksize;
}
// Center and offset each point in the polygon definition.
for (defIndex = 0; defIndex < (checkpoints * 2); defIndex++) {
checkedPolygon[polyIndex].x = nscoord((((checkedPolygonDef[defIndex]) - centerx) * (size)) + (aRect.width / 2) + aRect.x);
defIndex++;
checkedPolygon[polyIndex].y = nscoord((((checkedPolygonDef[defIndex]) - centery) * (size)) + (aRect.height / 2) + aRect.y);
polyIndex++;
}
aRenderingContext.FillPolygon(checkedPolygon, checkpoints);
}
//----------------------------------------------------------------------------------
nsresult
nsFormControlHelper::Reset(nsIFrame* aFrame, nsPresContext* aPresContext)
{
nsCOMPtr<nsIFormControl> control = do_QueryInterface(aFrame->GetContent());
if (control) {
control->Reset();
return NS_OK;
}
return NS_ERROR_FAILURE;
}
void
nsFormControlHelper::StyleChangeReflow(nsPresContext* aPresContext,
nsIFrame* aFrame)
{
aPresContext->PresShell()->AppendReflowCommand(aFrame,
eReflowType_StyleChanged,
nsnull);
}

View File

@ -1,255 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsFormControlHelper_h___
#define nsFormControlHelper_h___
#include "nsIFormControlFrame.h"
#include "nsISupports.h"
#include "nsIWidget.h"
#include "nsLeafFrame.h"
#include "nsCoord.h"
#include "nsHTMLAtoms.h"
#include "nsINameSpaceManager.h"
class nsIView;
class nsPresContext;
class nsStyleCoord;
class nsStyleContext;
#define CSS_NOTSET -1
#define ATTR_NOTSET -1
#define NS_STRING_TRUE NS_LITERAL_STRING("1")
#define NS_STRING_FALSE NS_LITERAL_STRING("0")
/**
* Enumeration of possible mouse states used to detect mouse clicks
*/
enum nsMouseState {
eMouseNone,
eMouseEnter,
eMouseExit,
eMouseDown,
eMouseUp
};
/**
* nsFormControlHelper is the base class for frames of form controls. It
* provides a uniform way of creating widgets, resizing, and painting.
* @see nsLeafFrame and its base classes for more info
*/
class nsFormControlHelper
{
public:
// returns the an addref'ed FontMetrics for the default font for the frame
static nsresult GetFrameFontFM(nsIFrame* aFrame,
nsIFontMetrics** aFontMet);
// Map platform line endings (CR, CRLF, LF) to DOM line endings (LF)
static void PlatformToDOMLineBreaks(nsString &aString);
/**
* Get whether a form control is disabled
* @param aContent the content of the form control in question
* @return whether the form control is disabled
*/
static PRBool GetDisabled(nsIContent* aContent) {
return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled);
};
/**
* Cause the form control to reset its value
* @param aFrame the frame who owns the form control
* @param aPresContext the pres context
*/
static nsresult Reset(nsIFrame* aFrame, nsPresContext* aPresContext);
/**
* Utility to convert a string to a PRBool
* @param aValue string to convert to a PRBool
* @returns PR_TRUE if aValue = "1", PR_FALSE otherwise
*/
static PRBool GetBool(const nsAString& aValue);
/**
* Utility to convert a PRBool to a string
* @param aValue Boolean value to convert to string.
* @param aResult string to hold the boolean value. It is set to "1"
* if aValue equals PR_TRUE, "0" if aValue equals PR_FALSE.
*/
static void GetBoolString(const PRBool aValue, nsAString& aResult);
static void GetRepChars(char& char1, char& char2) {
char1 = 'W';
char2 = 'w';
}
// wrap can be one of these three values.
typedef enum {
eHTMLTextWrap_Off = 1, // "off"
eHTMLTextWrap_Hard = 2, // "hard"
eHTMLTextWrap_Soft = 3 // the default
} nsHTMLTextWrap;
static PRBool GetWrapPropertyEnum(nsIContent * aContent, nsHTMLTextWrap& aWrapProp);
//
//-------------------------------------------------------------------------------------
// Utility methods for rendering Form Elements using GFX
//-------------------------------------------------------------------------------------
//
// XXX: The following location for the paint code is TEMPORARY.
// It is being used to get printing working
// under windows. Later it will be used to GFX-render the controls to the display.
// Expect this code to repackaged and moved to a new location in the future.
/**
* Enumeration of possible mouse states used to detect mouse clicks
*/
enum nsArrowDirection {
eArrowDirection_Left,
eArrowDirection_Right,
eArrowDirection_Up,
eArrowDirection_Down
};
/**
* Scale, translate and convert an arrow of poitns from nscoord's to nsPoints's.
*
* @param aNumberOfPoints number of (x,y) pairs
* @param aPoints arrow of points to convert
* @param aScaleFactor scale factor to apply to each points translation.
* @param aX x coordinate to add to each point after scaling
* @param aY y coordinate to add to each point after scaling
* @param aCenterX x coordinate of the center point in the original array of points.
* @param aCenterY y coordiante of the center point in the original array of points.
*/
static void SetupPoints(PRUint32 aNumberOfPoints, nscoord* aPoints,
nsPoint* aPolygon, nscoord aScaleFactor, nscoord aX, nscoord aY,
nscoord aCenterX, nscoord aCenterY);
/**
* Paint a fat line. The line is drawn as a polygon with a specified width.
*
* @param aRenderingContext the rendering context
* @param aSX starting x in pixels
* @param aSY starting y in pixels
* @param aEX ending x in pixels
* @param aEY ending y in pixels
* @param aHorz PR_TRUE if aWidth is added to x coordinates to form polygon. If
* PR_FALSE then aWidth as added to the y coordinates.
* @param aOnePixel number of twips in a single pixel.
*/
static void PaintLine(nsIRenderingContext& aRenderingContext,
nscoord aSX, nscoord aSY, nscoord aEX, nscoord aEY,
PRBool aHorz, nscoord aWidth, nscoord aOnePixel);
/**
* Paint a fixed size checkmark
*
* @param aRenderingContext the rendering context
* @param aPixelsToTwips scale factor for convering pixels to twips.
*/
static void PaintFixedSizeCheckMark(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips);
/**
* Paint a checkmark
*
* @param aRenderingContext the rendering context
* @param aPixelsToTwips scale factor for convering pixels to twips.
* @param aWidth width in twips
* @param aHeight height in twips
*/
static void PaintCheckMark(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips, const nsRect & aRect);
/**
* Paint a fixed size checkmark border
*
* @param aRenderingContext the rendering context
* @param aPixelsToTwips scale factor for convering pixels to twips.
* @param aBackgroundColor color for background of the checkbox
*/
static void PaintFixedSizeCheckMarkBorder(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips, const nsStyleColor& aBackgroundColor);
/**
* Paint a rectangular button. Includes background, string, and focus indicator
*
* @param aPresContext the presentation context
* @param aRenderingContext the rendering context
* @param aDirtyRect rectangle requiring update
* @param aRect x,y, width, and height of the button in TWIPS
* @param aShift if PR_TRUE offset button as if it were pressed
* @param aShowFocus if PR_TRUE draw focus rectangle over button
* @param aStyleContext style context used for drawing button background
* @param aLabel label for button
* @param aForFrame the frame that the scrollbar will be rendered in to
*/
static void PaintRectangularButton(nsPresContext* aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect, const nsRect& aRect,
PRBool aShift, PRBool aShowFocus, PRBool aDisabled,
PRBool aDrawOutline,
nsStyleContext* aOutlineStyle,
nsStyleContext* aFocusStyle,
nsStyleContext* aStyleContext, nsString& aLabel,
nsIFrame* aForFrame);
static void StyleChangeReflow(nsPresContext* aPresContext,
nsIFrame* aFrame);
protected:
nsFormControlHelper();
virtual ~nsFormControlHelper();
};
#endif

View File

@ -52,6 +52,7 @@
#include "nsAutoPtr.h"
#include "nsStyleSet.h"
#include "nsContentUtils.h"
#include "nsHTMLAtoms.h"
// MouseEvent suppression in PP
#include "nsGUIEvent.h"

View File

@ -54,7 +54,45 @@
#include "nsITheme.h"
#include "imgIRequest.h"
#include "nsDisplayList.h"
#include "nsFormControlHelper.h"
static void
PaintCheckMark(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips, const nsRect& aRect)
{
const PRUint32 checkpoints = 7;
const PRUint32 checksize = 9; //This is value is determined by added 2 units to the end
//of the 7X7 pixel rectangle below to provide some white space
//around the checkmark when it is rendered.
// Points come from the coordinates on a 7X7 pixels
// box with 0,0 at the lower left.
nscoord checkedPolygonDef[] = {0,2, 2,4, 6,0 , 6,2, 2,6, 0,4, 0,2 };
// Location of the center point of the checkmark
const PRUint32 centerx = 3;
const PRUint32 centery = 3;
nsPoint checkedPolygon[checkpoints];
PRUint32 defIndex = 0;
PRUint32 polyIndex = 0;
// Scale the checkmark based on the smallest dimension
PRUint32 size = aRect.width / checksize;
if (aRect.height < aRect.width) {
size = aRect.height / checksize;
}
// Center and offset each point in the polygon definition.
for (defIndex = 0; defIndex < (checkpoints * 2); defIndex++) {
checkedPolygon[polyIndex].x =
nscoord((((checkedPolygonDef[defIndex]) - centerx) * (size)) + (aRect.width / 2) + aRect.x);
defIndex++;
checkedPolygon[polyIndex].y =
nscoord((((checkedPolygonDef[defIndex]) - centery) * (size)) + (aRect.height / 2) + aRect.y);
polyIndex++;
}
aRenderingContext.FillPolygon(checkedPolygon, checkpoints);
}
//------------------------------------------------------------
nsIFrame*
@ -200,8 +238,6 @@ nsGfxCheckboxControlFrame::PaintCheckBox(nsIRenderingContext& aRenderingContext,
{
// REVIEW: moved the mAppearance test out so we avoid constructing
// a display item if it's not needed
aRenderingContext.PushState();
nsMargin borderPadding(0,0,0,0);
CalcBorderPadding(borderPadding);
@ -211,11 +247,9 @@ nsGfxCheckboxControlFrame::PaintCheckBox(nsIRenderingContext& aRenderingContext,
const nsStyleColor* color = GetStyleColor();
aRenderingContext.SetColor(color->mColor);
nsFormControlHelper::PaintCheckMark(aRenderingContext,
GetPresContext()->ScaledPixelsToTwips(),
checkRect);
aRenderingContext.PopState();
::PaintCheckMark(aRenderingContext,
GetPresContext()->ScaledPixelsToTwips(),
checkRect);
}
//------------------------------------------------------------

View File

@ -39,7 +39,6 @@
#include "nsCOMPtr.h"
#include "nsHTMLContainerFrame.h"
#include "nsFormControlHelper.h"
#include "nsIFormControlFrame.h"
#include "nsHTMLParts.h"
#include "nsIFormControl.h"

View File

@ -40,7 +40,6 @@
#include "nsCOMPtr.h"
#include "nsHTMLContainerFrame.h"
#include "nsFormControlHelper.h"
#include "nsIFormControlFrame.h"
#include "nsHTMLParts.h"

View File

@ -37,7 +37,6 @@
#include "nsCOMPtr.h"
#include "nsIImageControlFrame.h"
#include "nsImageFrame.h"
#include "nsFormControlHelper.h"
#include "nsIFormControlFrame.h"
#include "nsIFormControl.h"
#include "nsHTMLParts.h"
@ -225,7 +224,7 @@ nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
if (nsFormControlHelper::GetDisabled(mContent)) { // XXX cache disabled
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) { // XXX cache disabled
return NS_OK;
}

View File

@ -46,7 +46,6 @@
#include "nsIDOMKeyListener.h"
#include "nsTextControlFrame.h"
#include "nsFormControlHelper.h"
typedef nsTextControlFrame nsNewFrame;
class nsISupportsArray;

View File

@ -43,7 +43,6 @@
#include "nsUnicharUtils.h"
#include "nsListControlFrame.h"
#include "nsFormControlFrame.h" // for COMPARE macro
#include "nsFormControlHelper.h"
#include "nsHTMLAtoms.h"
#include "nsIFormControl.h"
#include "nsIDeviceContext.h"
@ -965,7 +964,8 @@ nsListControlFrame::Reflow(nsPresContext* aPresContext,
if (visibleHeight == 0) {
if (aReflowState.mComputedHeight != 0) {
nsCOMPtr<nsIFontMetrics> fontMet;
nsresult rvv = nsFormControlHelper::GetFrameFontFM(this, getter_AddRefs(fontMet));
nsresult rvv =
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
if (NS_SUCCEEDED(rvv) && fontMet) {
aReflowState.rendContext->SetFont(fontMet);
fontMet->GetHeight(visibleHeight);
@ -1386,7 +1386,7 @@ nsListControlFrame::HandleEvent(nsPresContext* aPresContext,
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
if (nsFormControlHelper::GetDisabled(mContent))
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled))
return NS_OK;
return nsHTMLScrollFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
@ -2055,7 +2055,7 @@ nsListControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
if (error == 0)
selected = IsContentSelectedByIndex(indx);
nsFormControlHelper::GetBoolString(selected, aValue);
aValue.Assign(selected ? NS_LITERAL_STRING("1") : NS_LITERAL_STRING("0"));
// For selectedIndex, get the value from the widget
} else if (nsHTMLAtoms::selectedindex == aName) {
@ -2260,7 +2260,7 @@ nsListControlFrame::MouseUp(nsIDOMEvent* aMouseEvent)
mButtonDown = PR_FALSE;
if (nsFormControlHelper::GetDisabled(mContent)) {
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) {
return NS_OK;
}
@ -2509,7 +2509,7 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent)
mButtonDown = PR_TRUE;
if (nsFormControlHelper::GetDisabled(mContent)) {
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) {
return NS_OK;
}
@ -2839,7 +2839,7 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
{
NS_ASSERTION(aKeyEvent, "keyEvent is null.");
if (nsFormControlHelper::GetDisabled(mContent))
if (mContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled))
return NS_OK;
// Start by making sure we can query for a key event

View File

@ -48,7 +48,6 @@
#include "nsIPlaintextEditor.h"
#include "nsEditorCID.h"
#include "nsLayoutCID.h"
#include "nsFormControlHelper.h"
#include "nsIDocumentEncoder.h"
#include "nsICaret.h"
#include "nsISelectionListener.h"
@ -77,6 +76,7 @@
#include "nsIPrintPreviewContext.h"
#endif // USE_QI_IN_SUPPRESS_EVENT_HANDLERS
#include "nsHTMLAtoms.h"
#include "nsLayoutUtils.h"
#include "nsIComponentManager.h"
#include "nsIView.h"
#include "nsIDOMHTMLInputElement.h"
@ -144,6 +144,51 @@ static const PRInt32 DEFAULT_UNDO_CAP = 1000;
static nsINativeKeyBindings *sNativeInputBindings = nsnull;
static nsINativeKeyBindings *sNativeTextAreaBindings = nsnull;
static void
PlatformToDOMLineBreaks(nsString &aString)
{
// Windows linebreaks: Map CRLF to LF:
aString.ReplaceSubstring(NS_LITERAL_STRING("\r\n").get(),
NS_LITERAL_STRING("\n").get());
// Mac linebreaks: Map any remaining CR to LF:
aString.ReplaceSubstring(NS_LITERAL_STRING("\r").get(),
NS_LITERAL_STRING("\n").get());
}
// wrap can be one of these three values.
typedef enum {
eHTMLTextWrap_Off = 1, // "off"
eHTMLTextWrap_Hard = 2, // "hard"
eHTMLTextWrap_Soft = 3 // the default
} nsHTMLTextWrap;
static PRBool
GetWrapPropertyEnum(nsIContent* aContent, nsHTMLTextWrap& aWrapProp)
{
// soft is the default; "physical" defaults to soft as well because all other
// browsers treat it that way and there is no real reason to maintain physical
// and virtual as separate entities if no one else does. Only hard and off
// do anything different.
aWrapProp = eHTMLTextWrap_Soft; // the default
nsAutoString wrap;
if (aContent->IsNodeOfType(nsINode::eHTML)) {
static nsIContent::AttrValuesArray strings[] =
{&nsHTMLAtoms::HARD, &nsHTMLAtoms::OFF, nsnull};
switch (aContent->FindAttrValueIn(kNameSpaceID_None, nsHTMLAtoms::wrap,
strings, eIgnoreCase)) {
case 0: aWrapProp = eHTMLTextWrap_Hard; break;
case 1: aWrapProp = eHTMLTextWrap_Off; break;
}
return PR_TRUE;
}
return PR_FALSE;
}
class nsTextInputListener : public nsISelectionListener,
public nsIDOMFocusListener,
public nsIDOMKeyListener,
@ -1305,7 +1350,8 @@ nsTextControlFrame::CalculateSizeStandard(nsPresContext* aPresContext,
nscoord charMaxAdvance = 0;
nsCOMPtr<nsIFontMetrics> fontMet;
nsresult rv = nsFormControlHelper::GetFrameFontFM(this, getter_AddRefs(fontMet));
nsresult rv =
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet));
NS_ENSURE_SUCCESS(rv, rv);
nsIRenderingContext* rendContext = aReflowState.rendContext;
rendContext->SetFont(fontMet);
@ -1502,9 +1548,9 @@ nsTextControlFrame::CreateFrameFor(nsPresContext* aPresContext,
// Set up wrapping
if (IsTextArea()) {
// wrap=off means -1 for wrap width no matter what cols is
nsFormControlHelper::nsHTMLTextWrap wrapProp;
nsFormControlHelper::GetWrapPropertyEnum(mContent, wrapProp);
if (wrapProp == nsFormControlHelper::eHTMLTextWrap_Off) {
nsHTMLTextWrap wrapProp;
::GetWrapPropertyEnum(mContent, wrapProp);
if (wrapProp == eHTMLTextWrap_Off) {
// do not wrap when wrap=off
textEditor->SetWrapWidth(-1);
} else {
@ -2646,9 +2692,9 @@ nsTextControlFrame::GetValue(nsAString& aValue, PRBool aIgnoreWrap) const
flags |= nsIDocumentEncoder::OutputPreformatted;
if (!aIgnoreWrap) {
nsFormControlHelper::nsHTMLTextWrap wrapProp;
if (nsFormControlHelper::GetWrapPropertyEnum(mContent, wrapProp) &&
wrapProp == nsFormControlHelper::eHTMLTextWrap_Hard) {
nsHTMLTextWrap wrapProp;
if (::GetWrapPropertyEnum(mContent, wrapProp) &&
wrapProp == eHTMLTextWrap_Hard) {
flags |= nsIDocumentEncoder::OutputWrap;
}
}
@ -2724,7 +2770,7 @@ nsTextControlFrame::SetValue(const nsAString& aValue)
// Unfortunately aValue is declared const, so we have to copy
// in order to do this substitution.
currentValue.Assign(aValue);
nsFormControlHelper::PlatformToDOMLineBreaks(currentValue);
::PlatformToDOMLineBreaks(currentValue);
nsCOMPtr<nsIDOMDocument>domDoc;
nsresult rv = mEditor->GetDocument(getter_AddRefs(domDoc));

View File

@ -45,7 +45,6 @@
#include "nsIAnonymousContentCreator.h"
#include "nsIEditor.h"
#include "nsITextControlFrame.h"
#include "nsFormControlHelper.h"//for the inputdimensions
#include "nsIFontMetrics.h"
#include "nsWeakReference.h" //for service and presshell pointers
#include "nsIScrollableViewProvider.h"

View File

@ -41,8 +41,6 @@
#include "nsParserMsgUtils.h"
#include "nsNetCID.h"
// This code is derived from nsFormControlHelper::GetLocalizedString()
static nsresult GetBundle(const char * aPropFileName, nsIStringBundle **aBundle)
{
NS_ENSURE_ARG_POINTER(aPropFileName);