Changed constants to use LookAndFeel values.

git-svn-id: svn://10.0.0.236/trunk@16754 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rods%netscape.com 1998-12-21 16:52:57 +00:00
parent 2fb4a870a1
commit 7acb8d2cbf
4 changed files with 214 additions and 140 deletions

View File

@ -43,6 +43,7 @@
#include "nsCSSRendering.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsILookAndFeel.h"
#ifdef SingleSignon
#include "nsIDocument.h"
@ -61,6 +62,8 @@ static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
nsresult
NS_NewTextControlFrame(nsIFrame*& aResult)
@ -89,27 +92,42 @@ nscoord
nsTextControlFrame::GetVerticalInsidePadding(float aPixToTwip,
nscoord aInnerHeight) const
{
#ifdef XP_PC
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.40f);
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.25f);
// XXX NOTE: the enums eMetric_TextShouldUseVerticalInsidePadding and eMetric_TextVerticalInsidePadding
// are ONLY needed because GTK is not using the "float" padding values and wants to only use an
// integer value for the padding instead of calculating like the other platforms.
//
// If GTK decides to start calculating the value, PLEASE remove these two enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The two enums are:
// eMetric_TextVerticalInsidePadding
// eMetric_TextShouldUseVerticalInsidePadding
//
float padTextArea;
float padTextField;
PRInt32 vertPad;
PRInt32 shouldUseVertPad;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextAreaVerticalInsidePadding, padTextArea);
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextFieldVerticalInsidePadding, padTextField);
// These two (below) are really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextVerticalInsidePadding, vertPad);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextShouldUseVerticalInsidePadding, shouldUseVertPad);
NS_RELEASE(lookAndFeel);
}
#endif
#ifdef XP_UNIX
return NSIntPixelsToTwips(10, aPixToTwip); // XXX this is probably wrong
#endif
#ifdef XP_MAC
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.40f);
if (1 == shouldUseVertPad) {
return NSIntPixelsToTwips(vertPad, aPixToTwip); // XXX this is probably wrong (for GTK)
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.25f);
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextArea);
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextField);
}
}
#endif
}
nscoord
@ -118,41 +136,46 @@ nsTextControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
nscoord aInnerWidth,
nscoord aCharWidth) const
{
#ifdef XP_PC
// XXX NOTE: the enum eMetric_TextShouldUseHorizontalInsideMinimumPadding
// is ONLY needed because GTK is not using the "float" padding values and wants to only use the
// "minimum" integer value for the padding instead of calculating and comparing like the other platforms.
//
// If GTK decides to start calculating and comparing the values,
// PLEASE remove these the enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The enum is:
// eMetric_TextShouldUseHorizontalInsideMinimumPadding
//
float padTextField;
float padTextArea;
PRInt32 padMinText;
PRInt32 shouldUsePadMinText;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextFieldHorizontalInsidePadding, padTextField);
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextAreaHorizontalInsidePadding, padTextArea);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextHorizontalInsideMinimumPadding, padMinText);
// This one (below) is really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextShouldUseHorizontalInsideMinimumPadding, shouldUsePadMinText);
NS_RELEASE(lookAndFeel);
}
nscoord padding;
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
padding = (nscoord)(40 * aCharWidth / 100);
padding = (nscoord)(aCharWidth * padTextArea);
} else {
padding = (nscoord)(95 * aCharWidth / 100);
padding = (nscoord)(aCharWidth * padTextField);
}
nscoord min = NSIntPixelsToTwips(3, aPixToTwip);
if (padding > min) {
nscoord min = NSIntPixelsToTwips(padMinText, aPixToTwip);
if (padding > min && (1 == shouldUsePadMinText)) {
return padding;
} else {
return min;
}
#endif
#ifdef XP_UNIX
return NSIntPixelsToTwips(6, aPixToTwip); // XXX this is probably wrong
#endif
#ifdef XP_MAC
nscoord padding;
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
padding = (nscoord)(40 * aCharWidth / 100);
} else {
padding = (nscoord)(95 * aCharWidth / 100);
}
nscoord min = NSIntPixelsToTwips(3, aPixToTwip);
if (padding > min) {
return padding;
} else {
return min;
}
#endif
}

View File

@ -43,9 +43,12 @@
#include "nsIHTMLAttributes.h"
#include "nsGenericHTMLElement.h"
#include "nsFormFrame.h"
#include "nsILookAndFeel.h"
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
void
nsButtonControlFrame::GetDefaultLabel(nsString& aString)
@ -144,16 +147,13 @@ nscoord
nsButtonControlFrame::GetVerticalInsidePadding(float aPixToTwip,
nscoord aInnerHeight) const
{
//return NSIntPixelsToTwips(4, aPixToTwip);
#ifdef XP_PC
return (nscoord)NSToIntRound((float)aInnerHeight * 0.25f);
#endif
#ifdef XP_UNIX
return (nscoord)NSToIntRound((float)aInnerHeight * 0.50f);
#endif
#ifdef XP_MAC
return (nscoord)NSToIntRound((float)aInnerHeight * 0.50f);
#endif
float pad;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ButtonVerticalInsidePadding, pad);
NS_RELEASE(lookAndFeel);
}
return (nscoord)NSToIntRound((float)aInnerHeight * pad);
}
nscoord
@ -165,27 +165,21 @@ nsButtonControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
nsCompatibility mode;
aPresContext.GetCompatibilityMode(mode);
#ifdef XP_PC
if (eCompatibility_NavQuirks == mode) {
return (nscoord)NSToIntRound(float(aInnerWidth) * 0.25f);
} else {
return NSIntPixelsToTwips(10, aPixToTwip) + 8;
float pad;
PRInt32 padQuirks;
PRInt32 padQuirksOffset;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ButtonHorizontalInsidePadding, pad);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ButtonHorizontalInsidePaddingNavQuirks, padQuirks);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks, padQuirksOffset);
NS_RELEASE(lookAndFeel);
}
#endif
#ifdef XP_UNIX
if (eCompatibility_NavQuirks == mode) {
return (nscoord)NSToIntRound(float(aInnerWidth) * 0.5f);
return (nscoord)NSToIntRound(float(aInnerWidth) * pad);
} else {
return NSIntPixelsToTwips(20, aPixToTwip);
return NSIntPixelsToTwips(padQuirks, aPixToTwip) + padQuirksOffset;
}
#endif
#ifdef XP_MAC
if (eCompatibility_NavQuirks == mode) {
return (nscoord)NSToIntRound(float(aInnerWidth) * 0.5f);
} else {
return NSIntPixelsToTwips(20, aPixToTwip);
}
#endif
}

View File

@ -46,6 +46,8 @@
#include "nsFont.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsILookAndFeel.h"
#include "nsRepository.h"
static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID);
@ -56,6 +58,8 @@ static NS_DEFINE_IID(kComboBoxIID, NS_ICOMBOBOX_IID);
static NS_DEFINE_IID(kListBoxIID, NS_ILISTBOX_IID);
static NS_DEFINE_IID(kComboCID, NS_COMBOBOX_CID);
static NS_DEFINE_IID(kListCID, NS_LISTBOX_CID);
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
class nsOption;
@ -163,15 +167,33 @@ nscoord
nsSelectControlFrame::GetVerticalInsidePadding(float aPixToTwip,
nscoord aInnerHeight) const
{
#ifdef XP_PC
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.10f);
#endif
#ifdef XP_UNIX
return NSIntPixelsToTwips(1, aPixToTwip); // XXX this is probably wrong
#endif
#ifdef XP_MAC
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.10f);
#endif
// XXX NOTE: the enums eMetric_ListVerticalInsidePadding and eMetric_ListShouldUseVerticalInsidePadding
// are ONLY needed because GTK is not using the "float" padding values and wants to only use an
// integer value for the padding instead of calculating like the other platforms.
//
// If GTK decides to start calculating the value, PLEASE remove these two enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The two enums are:
// eMetric_ListVerticalInsidePadding
// eMetric_ListShouldUseVerticalInsidePadding
//
float pad;
PRInt32 padInside;
PRInt32 shouldUsePadInside;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ListVerticalInsidePadding, pad);
// These two (below) are really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListVerticalInsidePadding, padInside);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListShouldUseVerticalInsidePadding, shouldUsePadInside);
NS_RELEASE(lookAndFeel);
}
if (1 == shouldUsePadInside) {
return NSIntPixelsToTwips(padInside, aPixToTwip); // XXX this is probably wrong (GTK)
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * pad);
}
}
PRInt32
@ -180,27 +202,39 @@ nsSelectControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
nscoord aInnerWidth,
nscoord aCharWidth) const
{
#ifdef XP_PC
nscoord padding = (nscoord)NSToIntRound(float(aCharWidth) * 0.40f);
nscoord min = NSIntPixelsToTwips(3, aPixToTwip);
if (padding > min) {
return padding;
} else {
return min;
// XXX NOTE: the enum eMetric_ListShouldUseHorizontalInsideMinimumPadding
// is ONLY needed because GTK is not using the "float" padding values and wants to only use the
// "minimum" integer value for the padding instead of calculating and comparing like the other platforms.
//
// If GTK decides to start calculating and comparing the values,
// PLEASE remove these the enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The enum is:
// eMetric_ListShouldUseHorizontalInsideMinimumPadding
//
float pad;
PRInt32 padMin;
PRInt32 shouldUsePadMin;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_ListHorizontalInsidePadding, pad);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListHorizontalInsideMinimumPadding, padMin);
// This one (below) is really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ListShouldUseHorizontalInsideMinimumPadding, shouldUsePadMin);
NS_RELEASE(lookAndFeel);
}
#endif
#ifdef XP_UNIX
return NSIntPixelsToTwips(7, aPixToTwip); // XXX this is probably wrong
#endif
#ifdef XP_MAC
nscoord padding = (nscoord)NSToIntRound(float(aCharWidth) * 0.40f);
nscoord min = NSIntPixelsToTwips(3, aPixToTwip);
if (padding > min) {
return padding;
if (1 == shouldUsePadMin) {
return NSIntPixelsToTwips(padMin, aPixToTwip); // XXX this is probably wrong (GTK)
} else {
return min;
nscoord padding = (nscoord)NSToIntRound(float(aCharWidth) * pad);
nscoord min = NSIntPixelsToTwips(padMin, aPixToTwip);
if (padding > min) {
return padding;
} else {
return min;
}
}
#endif
}
const nsIID&

View File

@ -43,6 +43,7 @@
#include "nsCSSRendering.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include "nsILookAndFeel.h"
#ifdef SingleSignon
#include "nsIDocument.h"
@ -61,6 +62,8 @@ static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
nsresult
NS_NewTextControlFrame(nsIFrame*& aResult)
@ -89,27 +92,42 @@ nscoord
nsTextControlFrame::GetVerticalInsidePadding(float aPixToTwip,
nscoord aInnerHeight) const
{
#ifdef XP_PC
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.40f);
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.25f);
// XXX NOTE: the enums eMetric_TextShouldUseVerticalInsidePadding and eMetric_TextVerticalInsidePadding
// are ONLY needed because GTK is not using the "float" padding values and wants to only use an
// integer value for the padding instead of calculating like the other platforms.
//
// If GTK decides to start calculating the value, PLEASE remove these two enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The two enums are:
// eMetric_TextVerticalInsidePadding
// eMetric_TextShouldUseVerticalInsidePadding
//
float padTextArea;
float padTextField;
PRInt32 vertPad;
PRInt32 shouldUseVertPad;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextAreaVerticalInsidePadding, padTextArea);
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextFieldVerticalInsidePadding, padTextField);
// These two (below) are really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextVerticalInsidePadding, vertPad);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextShouldUseVerticalInsidePadding, shouldUseVertPad);
NS_RELEASE(lookAndFeel);
}
#endif
#ifdef XP_UNIX
return NSIntPixelsToTwips(10, aPixToTwip); // XXX this is probably wrong
#endif
#ifdef XP_MAC
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.40f);
if (1 == shouldUseVertPad) {
return NSIntPixelsToTwips(vertPad, aPixToTwip); // XXX this is probably wrong (for GTK)
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * 0.25f);
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextArea);
} else {
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextField);
}
}
#endif
}
nscoord
@ -118,41 +136,46 @@ nsTextControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
nscoord aInnerWidth,
nscoord aCharWidth) const
{
#ifdef XP_PC
// XXX NOTE: the enum eMetric_TextShouldUseHorizontalInsideMinimumPadding
// is ONLY needed because GTK is not using the "float" padding values and wants to only use the
// "minimum" integer value for the padding instead of calculating and comparing like the other platforms.
//
// If GTK decides to start calculating and comparing the values,
// PLEASE remove these the enum from nsILookAndFeel and
// all the platforms nsLookAndFeel impementations so we don't have these extra values remaining in the code.
// The enum is:
// eMetric_TextShouldUseHorizontalInsideMinimumPadding
//
float padTextField;
float padTextArea;
PRInt32 padMinText;
PRInt32 shouldUsePadMinText;
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextFieldHorizontalInsidePadding, padTextField);
lookAndFeel->GetMetric(nsILookAndFeel::eMetricFloat_TextAreaHorizontalInsidePadding, padTextArea);
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextHorizontalInsideMinimumPadding, padMinText);
// This one (below) is really only needed for GTK
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextShouldUseHorizontalInsideMinimumPadding, shouldUsePadMinText);
NS_RELEASE(lookAndFeel);
}
nscoord padding;
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
padding = (nscoord)(40 * aCharWidth / 100);
padding = (nscoord)(aCharWidth * padTextArea);
} else {
padding = (nscoord)(95 * aCharWidth / 100);
padding = (nscoord)(aCharWidth * padTextField);
}
nscoord min = NSIntPixelsToTwips(3, aPixToTwip);
if (padding > min) {
nscoord min = NSIntPixelsToTwips(padMinText, aPixToTwip);
if (padding > min && (1 == shouldUsePadMinText)) {
return padding;
} else {
return min;
}
#endif
#ifdef XP_UNIX
return NSIntPixelsToTwips(6, aPixToTwip); // XXX this is probably wrong
#endif
#ifdef XP_MAC
nscoord padding;
PRInt32 type;
GetType(&type);
if (NS_FORM_TEXTAREA == type) {
padding = (nscoord)(40 * aCharWidth / 100);
} else {
padding = (nscoord)(95 * aCharWidth / 100);
}
nscoord min = NSIntPixelsToTwips(3, aPixToTwip);
if (padding > min) {
return padding;
} else {
return min;
}
#endif
}