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
Родитель 2d862ef87d
Коммит 3c7c571960
18 изменённых файлов: 137 добавлений и 39 удалений

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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__

Просмотреть файл

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

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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)

Просмотреть файл

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

Просмотреть файл

Просмотреть файл

Просмотреть файл

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

Просмотреть файл

@ -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);
}
//------------------------------------------------------------

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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;
}

Просмотреть файл

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

Просмотреть файл

@ -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

Просмотреть файл

@ -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));

Просмотреть файл

@ -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"

Просмотреть файл

@ -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);