1998-09-23 17:16:51 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsTextControlFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsITextWidget.h"
|
|
|
|
#include "nsITextAreaWidget.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsSize.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsFont.h"
|
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsFormFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsIDOMHTMLTextAreaElement.h"
|
|
|
|
|
1998-12-10 17:53:34 +00:00
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
1998-12-21 16:52:57 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-11-18 04:38:13 +00:00
|
|
|
#ifdef SingleSignon
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsIURL.h"
|
1999-04-03 22:56:18 +00:00
|
|
|
#include "nsIWalletService.h"
|
1998-11-18 04:38:13 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-04-03 22:56:18 +00:00
|
|
|
static NS_DEFINE_IID(kIWalletServiceIID, NS_IWALLETSERVICE_IID);
|
|
|
|
static NS_DEFINE_IID(kWalletServiceCID, NS_WALLETSERVICE_CID);
|
1998-11-18 04:38:13 +00:00
|
|
|
#endif
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
|
|
|
|
static NS_DEFINE_IID(kTextCID, NS_TEXTFIELD_CID);
|
|
|
|
static NS_DEFINE_IID(kTextAreaCID, NS_TEXTAREA_CID);
|
|
|
|
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);
|
1998-12-21 16:52:57 +00:00
|
|
|
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
|
|
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
nsresult
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_NewTextControlFrame(nsIFrame** aNewFrame)
|
1998-09-23 17:16:51 +00:00
|
|
|
{
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsTextControlFrame* it = new nsTextControlFrame;
|
|
|
|
if (!it) {
|
1998-09-23 17:16:51 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-11 22:03:29 +00:00
|
|
|
*aNewFrame = it;
|
1998-09-23 17:16:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsTextControlFrame::GetVerticalBorderWidth(float aPixToTwip) const
|
|
|
|
{
|
|
|
|
return NSIntPixelsToTwips(4, aPixToTwip);
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsTextControlFrame::GetHorizontalBorderWidth(float aPixToTwip) const
|
|
|
|
{
|
|
|
|
return GetVerticalBorderWidth(aPixToTwip);
|
|
|
|
}
|
|
|
|
|
|
|
|
// for a text area aInnerHeight is the height of one line
|
|
|
|
nscoord
|
|
|
|
nsTextControlFrame::GetVerticalInsidePadding(float aPixToTwip,
|
|
|
|
nscoord aInnerHeight) const
|
|
|
|
{
|
1998-12-21 16:52:57 +00:00
|
|
|
|
|
|
|
// 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;
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
1998-12-21 16:52:57 +00:00
|
|
|
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);
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
1998-12-21 16:52:57 +00:00
|
|
|
|
|
|
|
if (1 == shouldUseVertPad) {
|
|
|
|
return NSIntPixelsToTwips(vertPad, aPixToTwip); // XXX this is probably wrong (for GTK)
|
1998-12-20 13:18:10 +00:00
|
|
|
} else {
|
1998-12-21 16:52:57 +00:00
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if (NS_FORM_TEXTAREA == type) {
|
|
|
|
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextArea);
|
|
|
|
} else {
|
|
|
|
return (nscoord)NSToIntRound(float(aInnerHeight) * padTextField);
|
|
|
|
}
|
1998-12-20 13:18:10 +00:00
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsTextControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
|
|
|
|
float aPixToTwip,
|
|
|
|
nscoord aInnerWidth,
|
|
|
|
nscoord aCharWidth) const
|
|
|
|
{
|
1998-12-21 16:52:57 +00:00
|
|
|
// 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;
|
1999-03-09 09:44:27 +00:00
|
|
|
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
1998-12-21 16:52:57 +00:00
|
|
|
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);
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
1998-12-21 16:52:57 +00:00
|
|
|
|
1998-12-20 13:18:10 +00:00
|
|
|
nscoord padding;
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if (NS_FORM_TEXTAREA == type) {
|
1998-12-21 16:52:57 +00:00
|
|
|
padding = (nscoord)(aCharWidth * padTextArea);
|
1998-12-20 13:18:10 +00:00
|
|
|
} else {
|
1998-12-21 16:52:57 +00:00
|
|
|
padding = (nscoord)(aCharWidth * padTextField);
|
1998-12-20 13:18:10 +00:00
|
|
|
}
|
1998-12-21 16:52:57 +00:00
|
|
|
nscoord min = NSIntPixelsToTwips(padMinText, aPixToTwip);
|
|
|
|
if (padding > min && (1 == shouldUsePadMinText)) {
|
1998-12-20 13:18:10 +00:00
|
|
|
return padding;
|
|
|
|
} else {
|
|
|
|
return min;
|
|
|
|
}
|
1998-12-21 16:52:57 +00:00
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const nsIID&
|
|
|
|
nsTextControlFrame::GetIID()
|
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if (NS_FORM_TEXTAREA == type) {
|
|
|
|
return kITextAreaWidgetIID;
|
|
|
|
} else {
|
|
|
|
return kITextWidgetIID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsIID&
|
|
|
|
nsTextControlFrame::GetCID()
|
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if (NS_FORM_TEXTAREA == type) {
|
|
|
|
return kTextAreaCID;
|
|
|
|
} else {
|
|
|
|
return kTextCID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextControlFrame::EnterPressed(nsIPresContext& aPresContext)
|
|
|
|
{
|
|
|
|
if (mFormFrame && mFormFrame->CanSubmit(*this)) {
|
1998-12-28 21:28:53 +00:00
|
|
|
nsIContent *formContent = nsnull;
|
|
|
|
|
1999-02-10 00:42:56 +00:00
|
|
|
mFormFrame->GetContent(&formContent);
|
1998-12-28 21:28:53 +00:00
|
|
|
if (nsnull != formContent) {
|
|
|
|
nsEvent event;
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_FORM_SUBMIT;
|
1999-03-28 22:22:54 +00:00
|
|
|
formContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
1998-12-28 21:28:53 +00:00
|
|
|
NS_RELEASE(formContent);
|
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
mFormFrame->OnSubmit(&aPresContext, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-23 03:48:01 +00:00
|
|
|
#define DEFAULT_PIXEL_WIDTH 20
|
1998-09-23 17:16:51 +00:00
|
|
|
void
|
|
|
|
nsTextControlFrame::GetDesiredSize(nsIPresContext* aPresContext,
|
1998-10-02 04:10:00 +00:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
1998-10-01 04:46:11 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredLayoutSize,
|
1998-09-23 17:16:51 +00:00
|
|
|
nsSize& aDesiredWidgetSize)
|
|
|
|
{
|
1998-09-28 21:32:24 +00:00
|
|
|
nsCompatibility mode;
|
1999-02-12 17:45:58 +00:00
|
|
|
aPresContext->GetCompatibilityMode(&mode);
|
1998-09-28 21:32:24 +00:00
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
// get the css size and let the frame use or override it
|
|
|
|
nsSize styleSize;
|
|
|
|
GetStyleSize(*aPresContext, aReflowState, styleSize);
|
|
|
|
|
1999-02-23 03:48:01 +00:00
|
|
|
nsSize desiredSize;
|
|
|
|
nsSize minSize;
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
PRBool widthExplicit, heightExplicit;
|
|
|
|
PRInt32 ignore;
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
|
|
|
PRInt32 width;
|
1999-02-03 22:56:50 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE != GetSizeFromContent(&width)) {
|
1999-02-23 03:48:01 +00:00
|
|
|
width = DEFAULT_PIXEL_WIDTH;
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
1998-10-30 18:05:29 +00:00
|
|
|
//if (eCompatibility_NavQuirks == mode) {
|
|
|
|
// width += 1;
|
|
|
|
//}
|
1998-09-23 17:16:51 +00:00
|
|
|
nsInputDimensionSpec textSpec(nsnull, PR_FALSE, nsnull,
|
|
|
|
nsnull, width, PR_FALSE, nsnull, 1);
|
1999-02-23 03:48:01 +00:00
|
|
|
nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize,
|
|
|
|
textSpec, desiredSize, minSize, widthExplicit, heightExplicit, ignore);
|
1998-09-23 17:16:51 +00:00
|
|
|
} else {
|
1999-02-23 03:48:01 +00:00
|
|
|
nsInputDimensionSpec areaSpec(nsHTMLAtoms::cols, PR_FALSE, nsnull, nsnull, DEFAULT_PIXEL_WIDTH,
|
1998-09-23 17:16:51 +00:00
|
|
|
PR_FALSE, nsHTMLAtoms::rows, 1);
|
1999-02-23 03:48:01 +00:00
|
|
|
nsFormControlHelper::CalculateSize(aPresContext, aReflowState.rendContext, this, styleSize,
|
|
|
|
areaSpec, desiredSize, minSize, widthExplicit, heightExplicit, ignore);
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FORM_TEXTAREA == type) {
|
1998-12-15 19:03:36 +00:00
|
|
|
nscoord scrollbarWidth = 0;
|
|
|
|
nscoord scrollbarHeight = 0;
|
|
|
|
float scale;
|
1999-02-12 17:45:58 +00:00
|
|
|
float p2t;
|
|
|
|
aPresContext->GetPixelsToTwips(&p2t);
|
|
|
|
nsCOMPtr<nsIDeviceContext> dx;
|
|
|
|
aPresContext->GetDeviceContext(getter_AddRefs(dx));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (dx) {
|
1998-12-15 19:03:36 +00:00
|
|
|
float sbWidth;
|
|
|
|
float sbHeight;
|
|
|
|
dx->GetCanonicalPixelScale(scale);
|
|
|
|
dx->GetScrollBarDimensions(sbWidth, sbHeight);
|
|
|
|
scrollbarWidth = PRInt32(sbWidth * scale);
|
|
|
|
scrollbarHeight = PRInt32(sbHeight * scale);
|
|
|
|
} else {
|
|
|
|
scrollbarWidth = GetScrollbarWidth(p2t);
|
|
|
|
scrollbarHeight = scrollbarWidth;
|
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
if (!heightExplicit) {
|
1999-02-23 03:48:01 +00:00
|
|
|
desiredSize.height += scrollbarHeight;
|
|
|
|
minSize.height += scrollbarHeight;
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
if (!widthExplicit) {
|
1999-02-23 03:48:01 +00:00
|
|
|
desiredSize.width += scrollbarWidth;
|
|
|
|
minSize.width += scrollbarWidth;
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-23 03:48:01 +00:00
|
|
|
aDesiredLayoutSize.width = desiredSize.width;
|
|
|
|
aDesiredLayoutSize.height = desiredSize.height;
|
1998-09-23 17:16:51 +00:00
|
|
|
aDesiredLayoutSize.ascent = aDesiredLayoutSize.height;
|
|
|
|
aDesiredLayoutSize.descent = 0;
|
1999-02-23 03:48:01 +00:00
|
|
|
|
|
|
|
if (aDesiredLayoutSize.maxElementSize) {
|
|
|
|
aDesiredLayoutSize.maxElementSize->width = minSize.width;
|
1999-03-05 19:23:24 +00:00
|
|
|
aDesiredLayoutSize.maxElementSize->height = minSize.height;
|
1999-02-23 03:48:01 +00:00
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
|
|
|
|
aDesiredWidgetSize.height = aDesiredLayoutSize.height;
|
1999-02-23 03:48:01 +00:00
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsWidgetInitData*
|
|
|
|
nsTextControlFrame::GetWidgetInitData(nsIPresContext& aPresContext)
|
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
|
|
|
|
nsTextWidgetInitData* data = nsnull;
|
|
|
|
|
1998-10-19 20:37:40 +00:00
|
|
|
PRBool readOnly = nsFormFrame::GetReadonly(this);
|
|
|
|
|
|
|
|
if ((NS_FORM_INPUT_PASSWORD == type) || readOnly) {
|
1998-09-23 17:16:51 +00:00
|
|
|
data = new nsTextWidgetInitData();
|
1998-10-19 20:37:40 +00:00
|
|
|
data->mIsPassword = PR_FALSE;
|
|
|
|
data->mIsReadOnly = PR_FALSE;
|
|
|
|
if (NS_FORM_INPUT_PASSWORD == type) {
|
|
|
|
data->clipChildren = PR_TRUE;
|
|
|
|
data->mIsPassword = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (readOnly) {
|
|
|
|
data->mIsReadOnly = PR_TRUE;
|
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-01-28 21:58:01 +00:00
|
|
|
nsTextControlFrame::GetText(nsString* aText, PRBool aInitialValue)
|
1998-09-23 17:16:51 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_CONTENT_ATTR_NOT_THERE;
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
1998-10-19 20:37:40 +00:00
|
|
|
if ((NS_FORM_INPUT_TEXT == type) || (NS_FORM_INPUT_PASSWORD == type)) {
|
1999-03-03 03:06:36 +00:00
|
|
|
result = nsFormControlHelper::GetInputElementValue(mContent, aText, aInitialValue);
|
1999-02-18 00:13:39 +00:00
|
|
|
/* XXX REMOVE
|
|
|
|
nsIDOMHTMLInputElement* textElem = nsnull;
|
1998-10-13 21:31:26 +00:00
|
|
|
result = mContent->QueryInterface(kIDOMHTMLInputElementIID, (void**)&textElem);
|
1998-09-23 17:16:51 +00:00
|
|
|
if ((NS_OK == result) && textElem) {
|
1999-01-28 21:58:01 +00:00
|
|
|
if (PR_TRUE == aInitialValue) {
|
|
|
|
result = textElem->GetDefaultValue(*aText);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = textElem->GetValue(*aText);
|
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
NS_RELEASE(textElem);
|
|
|
|
}
|
1999-02-18 00:13:39 +00:00
|
|
|
*/
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
} else {
|
|
|
|
nsIDOMHTMLTextAreaElement* textArea = nsnull;
|
1998-10-13 21:31:26 +00:00
|
|
|
result = mContent->QueryInterface(kIDOMHTMLTextAreaElementIID, (void**)&textArea);
|
1998-09-23 17:16:51 +00:00
|
|
|
if ((NS_OK == result) && textArea) {
|
1999-01-28 21:58:01 +00:00
|
|
|
if (PR_TRUE == aInitialValue) {
|
|
|
|
result = textArea->GetDefaultValue(*aText);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = textArea->GetValue(*aText);
|
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
NS_RELEASE(textArea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-11-09 23:30:16 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextControlFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
if (mWidget) {
|
|
|
|
nsITextWidget* text = nsnull;
|
|
|
|
result = mWidget->QueryInterface(kITextWidgetIID, (void**)&text);
|
1999-03-03 03:06:36 +00:00
|
|
|
if ((NS_OK == result) && (nsnull != text)) {
|
|
|
|
if (nsHTMLAtoms::value == aAttribute) {
|
1999-01-26 07:57:54 +00:00
|
|
|
nsString value;
|
1999-02-12 17:45:58 +00:00
|
|
|
/*XXXnsresult rv = */GetText(&value, PR_TRUE);
|
1999-01-26 07:57:54 +00:00
|
|
|
PRUint32 ignore;
|
|
|
|
text->SetText(value, ignore);
|
1998-11-09 23:30:16 +00:00
|
|
|
nsFormFrame::StyleChangeReflow(aPresContext, this);
|
1999-03-03 03:06:36 +00:00
|
|
|
} else if (nsHTMLAtoms::maxlength == aAttribute) {
|
|
|
|
PRInt32 maxLength;
|
|
|
|
nsresult rv = GetMaxLength(&maxLength);
|
|
|
|
if (NS_CONTENT_ATTR_NOT_THERE != rv) {
|
|
|
|
text->SetMaxTextLength(maxLength);
|
|
|
|
}
|
|
|
|
} else if (nsHTMLAtoms::readonly == aAttribute) {
|
|
|
|
PRBool oldReadOnly;
|
|
|
|
text->SetReadOnly(nsFormFrame::GetReadonly(this),oldReadOnly);
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::size == aAttribute) {
|
|
|
|
nsFormFrame::StyleChangeReflow(aPresContext, this);
|
1998-11-09 23:30:16 +00:00
|
|
|
}
|
1999-03-03 03:06:36 +00:00
|
|
|
// Allow the base class to handle common attributes supported
|
|
|
|
// by all form elements...
|
|
|
|
else {
|
|
|
|
result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint);
|
|
|
|
}
|
|
|
|
NS_RELEASE(text);
|
1998-12-10 17:22:31 +00:00
|
|
|
}
|
1999-03-03 03:06:36 +00:00
|
|
|
// XXX Ick, create an common interface that has the functionality of nsTextHelper
|
|
|
|
else { // We didn't get a Text, is it a TextArea?
|
|
|
|
nsITextAreaWidget* textArea = nsnull;
|
|
|
|
result = mWidget->QueryInterface(kITextAreaWidgetIID, (void**)&textArea);
|
|
|
|
if ((NS_OK == result) && (nsnull != textArea)) {
|
|
|
|
if (nsHTMLAtoms::value == aAttribute) {
|
|
|
|
nsString value;
|
|
|
|
/*XXXnsresult rv = */GetText(&value, PR_TRUE);
|
|
|
|
PRUint32 ignore;
|
|
|
|
textArea->SetText(value, ignore);
|
|
|
|
nsFormFrame::StyleChangeReflow(aPresContext, this);
|
|
|
|
} else if (nsHTMLAtoms::maxlength == aAttribute) {
|
|
|
|
PRInt32 maxLength;
|
|
|
|
nsresult rv = GetMaxLength(&maxLength);
|
|
|
|
if (NS_CONTENT_ATTR_NOT_THERE != rv) {
|
|
|
|
textArea->SetMaxTextLength(maxLength);
|
|
|
|
}
|
|
|
|
} else if (nsHTMLAtoms::readonly == aAttribute) {
|
|
|
|
PRBool oldReadOnly;
|
|
|
|
textArea->SetReadOnly(nsFormFrame::GetReadonly(this),oldReadOnly);
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::size == aAttribute) {
|
|
|
|
nsFormFrame::StyleChangeReflow(aPresContext, this);
|
|
|
|
}
|
|
|
|
// Allow the base class to handle common attributes supported
|
|
|
|
// by all form elements...
|
|
|
|
else {
|
|
|
|
result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint);
|
|
|
|
}
|
|
|
|
NS_RELEASE(textArea);
|
|
|
|
}
|
|
|
|
else { // We didn't get a Text or TextArea. Uh oh...
|
|
|
|
result = nsFormControlFrame::AttributeChanged(aPresContext, aChild, aAttribute, aHint);
|
|
|
|
}
|
1999-01-26 07:57:54 +00:00
|
|
|
}
|
1998-11-09 23:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
void
|
1998-10-14 23:01:44 +00:00
|
|
|
nsTextControlFrame::PostCreateWidget(nsIPresContext* aPresContext,
|
|
|
|
nscoord& aWidth,
|
|
|
|
nscoord& aHeight)
|
1998-09-23 17:16:51 +00:00
|
|
|
{
|
|
|
|
if (!mWidget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
nsFont font(aPresContext->GetDefaultFixedFontDeprecated());
|
1998-09-28 21:32:24 +00:00
|
|
|
GetFont(aPresContext, font);
|
|
|
|
mWidget->SetFont(font);
|
1998-10-08 04:38:41 +00:00
|
|
|
SetColors(*aPresContext);
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
PRUint32 ignore;
|
|
|
|
nsAutoString value;
|
|
|
|
|
|
|
|
nsITextAreaWidget* textArea = nsnull;
|
|
|
|
nsITextWidget* text = nsnull;
|
|
|
|
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
|
1998-11-18 04:38:13 +00:00
|
|
|
|
|
|
|
#ifdef SingleSignon
|
|
|
|
/* get name of text */
|
1999-03-10 21:38:34 +00:00
|
|
|
PRBool failed = PR_TRUE;
|
1998-11-18 04:38:13 +00:00
|
|
|
nsAutoString name;
|
|
|
|
GetName(&name);
|
|
|
|
|
|
|
|
/* get url name */
|
1999-01-29 05:05:02 +00:00
|
|
|
char *URLName = nsnull;
|
1998-11-18 04:38:13 +00:00
|
|
|
nsIURL* docURL = nsnull;
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
mContent->GetDocument(doc);
|
|
|
|
if (nsnull != doc) {
|
|
|
|
docURL = doc->GetDocumentURL();
|
|
|
|
NS_RELEASE(doc);
|
1999-03-10 21:38:34 +00:00
|
|
|
if (nsnull != docURL) {
|
|
|
|
const char* spec;
|
|
|
|
(void)docURL->GetSpec(&spec);
|
|
|
|
if (nsnull != spec) {
|
|
|
|
URLName = (char*)PR_Malloc(PL_strlen(spec)+1);
|
|
|
|
PL_strcpy(URLName, spec);
|
|
|
|
}
|
|
|
|
NS_RELEASE(docURL);
|
|
|
|
}
|
1998-11-18 04:38:13 +00:00
|
|
|
}
|
|
|
|
|
1999-03-10 21:38:34 +00:00
|
|
|
if (nsnull != URLName) {
|
|
|
|
/* invoke single-signon to get previously-used value of text */
|
1999-04-03 22:56:18 +00:00
|
|
|
nsIWalletService *service;
|
|
|
|
nsresult res = nsServiceManager::GetService(kWalletServiceCID,
|
|
|
|
kIWalletServiceIID,
|
1999-03-10 21:38:34 +00:00
|
|
|
(nsISupports **)&service);
|
|
|
|
if ((NS_OK == res) && (nsnull != service)) {
|
|
|
|
char* valueString = NULL;
|
|
|
|
char* nameString = name.ToNewCString();
|
|
|
|
res = service->SI_RestoreSignonData(URLName, nameString, &valueString);
|
|
|
|
delete[] nameString;
|
|
|
|
NS_RELEASE(service);
|
|
|
|
PR_FREEIF(URLName);
|
|
|
|
if (valueString && *valueString) {
|
|
|
|
value = valueString;
|
|
|
|
failed = PR_FALSE;
|
|
|
|
}
|
1998-11-18 04:38:13 +00:00
|
|
|
}
|
|
|
|
}
|
1999-03-10 21:38:34 +00:00
|
|
|
if (failed) {
|
|
|
|
GetText(&value, PR_TRUE);
|
|
|
|
}
|
1998-11-18 04:38:13 +00:00
|
|
|
#else
|
1999-01-28 21:58:01 +00:00
|
|
|
GetText(&value, PR_TRUE);
|
1998-11-18 04:38:13 +00:00
|
|
|
#endif
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
text->SetText(value, ignore);
|
|
|
|
PRInt32 maxLength;
|
|
|
|
nsresult result = GetMaxLength(&maxLength);
|
|
|
|
if (NS_CONTENT_ATTR_NOT_THERE != result) {
|
|
|
|
text->SetMaxTextLength(maxLength);
|
|
|
|
}
|
|
|
|
NS_RELEASE(text);
|
|
|
|
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&textArea)) {
|
1999-02-01 23:49:21 +00:00
|
|
|
GetText(&value, PR_TRUE);
|
1998-09-23 17:16:51 +00:00
|
|
|
textArea->SetText(value, ignore);
|
|
|
|
NS_RELEASE(textArea);
|
|
|
|
}
|
1998-10-19 20:37:40 +00:00
|
|
|
if (nsFormFrame::GetDisabled(this)) {
|
|
|
|
mWidget->Enable(PR_FALSE);
|
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsTextControlFrame::GetMaxNumValues()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsTextControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
|
|
|
|
nsString* aValues, nsString* aNames)
|
|
|
|
{
|
|
|
|
if (!mWidget) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString name;
|
|
|
|
nsresult result = GetName(&name);
|
|
|
|
if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_NOT_THERE == result)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 size;
|
|
|
|
nsITextWidget* text = nsnull;
|
|
|
|
nsITextAreaWidget* textArea = nsnull;
|
|
|
|
|
|
|
|
aNames[0] = name;
|
|
|
|
aNumValues = 1;
|
|
|
|
|
|
|
|
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
|
|
|
|
text->GetText(aValues[0],0,size); // the last parm is not used
|
|
|
|
NS_RELEASE(text);
|
|
|
|
return PR_TRUE;
|
|
|
|
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&textArea)) {
|
|
|
|
textArea->GetText(aValues[0],0,size); // the last parm is not used
|
|
|
|
NS_RELEASE(textArea);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextControlFrame::Reset()
|
|
|
|
{
|
|
|
|
if (!mWidget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsITextWidget* text = nsnull;
|
|
|
|
nsITextAreaWidget* textArea = nsnull;
|
|
|
|
|
|
|
|
nsAutoString value;
|
1999-01-28 21:58:01 +00:00
|
|
|
nsresult valStatus = GetText(&value, PR_TRUE);
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
PRUint32 size;
|
|
|
|
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == valStatus) {
|
|
|
|
text->SetText(value,size);
|
|
|
|
} else {
|
|
|
|
text->SetText("",size);
|
|
|
|
}
|
|
|
|
NS_RELEASE(text);
|
|
|
|
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&textArea)) {
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == valStatus) {
|
|
|
|
textArea->SetText(value,size);
|
|
|
|
} else {
|
|
|
|
textArea->SetText("",size);
|
|
|
|
}
|
|
|
|
NS_RELEASE(textArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextControlFrame::GetCursor(nsIPresContext& aPresContext, nsPoint& aPoint, PRInt32& aCursor)
|
|
|
|
{
|
|
|
|
/*const nsStyleColor* styleColor;
|
|
|
|
GetStyleData(eStyleStruct_Color, (const nsStyleStruct*&)styleColor);
|
|
|
|
aCursor = styleColor->mCursor;*/
|
|
|
|
|
|
|
|
//XXX This is wrong, should be through style.
|
|
|
|
aCursor = NS_STYLE_CURSOR_TEXT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
|
1998-11-19 17:22:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextControlFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("TextControl", aResult);
|
|
|
|
}
|
1998-12-10 17:53:34 +00:00
|
|
|
|
|
|
|
|
1999-02-18 00:13:39 +00:00
|
|
|
void
|
|
|
|
nsTextControlFrame::PaintTextControlBackground(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer) {
|
|
|
|
nsFormControlFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
}
|
|
|
|
|
1998-12-10 17:53:34 +00:00
|
|
|
void
|
|
|
|
nsTextControlFrame::PaintTextControl(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
1999-02-11 01:13:28 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsString& aText,
|
1999-02-18 00:13:39 +00:00
|
|
|
nsIStyleContext* aStyleContext, nsRect& aRect)
|
1998-12-10 17:53:34 +00:00
|
|
|
{
|
1998-12-16 18:12:55 +00:00
|
|
|
aRenderingContext.PushState();
|
1998-12-15 19:03:36 +00:00
|
|
|
|
1998-12-10 17:53:34 +00:00
|
|
|
const nsStyleSpacing* spacing =
|
1999-02-11 01:13:28 +00:00
|
|
|
(const nsStyleSpacing*)aStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-12-10 17:53:34 +00:00
|
|
|
nsMargin border;
|
|
|
|
spacing->CalcBorderFor(this, border);
|
|
|
|
|
|
|
|
float p2t;
|
1999-02-12 17:45:58 +00:00
|
|
|
aPresContext.GetScaledPixelsToTwips(&p2t);
|
1998-12-10 17:53:34 +00:00
|
|
|
nscoord onePixel = NSIntPixelsToTwips(1, p2t);
|
|
|
|
|
1999-02-18 00:13:39 +00:00
|
|
|
nsRect outside(aRect.x, aRect.y, aRect.width, aRect.height);
|
1998-12-10 17:53:34 +00:00
|
|
|
outside.Deflate(border);
|
|
|
|
outside.Deflate(onePixel, onePixel);
|
|
|
|
|
|
|
|
nsRect inside(outside);
|
|
|
|
inside.Deflate(onePixel, onePixel);
|
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
#if 0
|
|
|
|
if (mGotFocus) {
|
|
|
|
PaintFocus(aRenderingContext,
|
|
|
|
aDirtyRect, inside, outside);
|
1998-12-10 17:53:34 +00:00
|
|
|
}
|
1998-12-16 18:12:55 +00:00
|
|
|
#endif
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
float appUnits;
|
|
|
|
float devUnits;
|
|
|
|
float scale;
|
|
|
|
nsIDeviceContext * context;
|
|
|
|
aRenderingContext.GetDeviceContext(context);
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
context->GetCanonicalPixelScale(scale);
|
|
|
|
context->GetAppUnitsToDevUnits(devUnits);
|
|
|
|
context->GetDevUnitsToAppUnits(appUnits);
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
nsFont font(aPresContext.GetDefaultFixedFontDeprecated());
|
1998-12-16 18:12:55 +00:00
|
|
|
GetFont(&aPresContext, font);
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
aRenderingContext.SetFont(font);
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
nscoord textWidth;
|
|
|
|
nscoord textHeight;
|
1999-02-11 01:13:28 +00:00
|
|
|
|
|
|
|
aRenderingContext.GetWidth(aText, textWidth);
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
nsIFontMetrics* metrics;
|
|
|
|
context->GetMetricsFor(font, metrics);
|
|
|
|
metrics->GetHeight(textHeight);
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if (NS_FORM_INPUT_TEXT == type || NS_FORM_INPUT_PASSWORD == type) {
|
|
|
|
nscoord x = inside.x + onePixel + onePixel;
|
|
|
|
nscoord y;
|
1998-12-15 19:03:36 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
if (NS_FORM_INPUT_TEXT == type) {
|
|
|
|
y = ((inside.height - textHeight) / 2) + inside.y;
|
|
|
|
} else {
|
|
|
|
metrics->GetMaxAscent(textHeight);
|
|
|
|
y = ((inside.height - textHeight) / 2) + inside.y;
|
|
|
|
PRInt32 i;
|
1999-02-11 01:13:28 +00:00
|
|
|
PRInt32 len = aText.Length();
|
|
|
|
aText.SetLength(0);
|
1998-12-16 18:12:55 +00:00
|
|
|
for (i=0;i<len;i++) {
|
1999-02-11 01:13:28 +00:00
|
|
|
aText.Append("*");
|
1998-12-16 18:12:55 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-11 01:13:28 +00:00
|
|
|
aRenderingContext.DrawString(aText, x, y);
|
1998-12-15 19:03:36 +00:00
|
|
|
} else {
|
1998-12-16 18:12:55 +00:00
|
|
|
float sbWidth;
|
|
|
|
float sbHeight;
|
|
|
|
context->GetCanonicalPixelScale(scale);
|
|
|
|
context->GetScrollBarDimensions(sbWidth, sbHeight);
|
|
|
|
PRInt32 scrollbarScaledWidth = PRInt32(sbWidth * scale);
|
|
|
|
PRInt32 scrollbarScaledHeight = PRInt32(sbWidth * scale);
|
|
|
|
|
|
|
|
inside.width -= scrollbarScaledWidth;
|
|
|
|
inside.height -= scrollbarScaledHeight;
|
|
|
|
PRBool clipEmpty;
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(inside, nsClipCombine_kReplace, clipEmpty);
|
|
|
|
|
|
|
|
nscoord x = inside.x + onePixel;
|
|
|
|
nscoord y = inside.y + onePixel;
|
|
|
|
|
|
|
|
// Draw multi-line text
|
|
|
|
PRInt32 oldPos = 0;
|
1999-02-11 01:13:28 +00:00
|
|
|
PRInt32 pos = aText.Find('\n', 0);
|
1998-12-16 18:12:55 +00:00
|
|
|
while (1) {
|
|
|
|
nsString substr;
|
|
|
|
if (-1 == pos) {
|
1999-02-01 23:09:06 +00:00
|
|
|
// Single line, no carriage return.
|
1999-02-11 01:13:28 +00:00
|
|
|
aText.Right(substr, aText.Length()-oldPos);
|
1999-01-28 05:03:58 +00:00
|
|
|
aRenderingContext.DrawString(substr, x, y);
|
1998-12-16 18:12:55 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-02-01 23:09:06 +00:00
|
|
|
// Strip off substr up to carriage return
|
1999-02-11 01:13:28 +00:00
|
|
|
aText.Mid(substr, oldPos, ((pos - oldPos) - 1));
|
1999-02-01 23:09:06 +00:00
|
|
|
|
1999-01-28 05:03:58 +00:00
|
|
|
aRenderingContext.DrawString(substr, x, y);
|
1998-12-16 18:12:55 +00:00
|
|
|
y += textHeight;
|
1999-02-01 23:09:06 +00:00
|
|
|
// Advance to the next carriage return
|
1998-12-16 18:12:55 +00:00
|
|
|
pos++;
|
|
|
|
oldPos = pos;
|
1999-02-11 01:13:28 +00:00
|
|
|
pos = aText.Find('\n', pos);
|
1998-12-15 19:03:36 +00:00
|
|
|
}
|
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
aRenderingContext.PopState(clipEmpty);
|
|
|
|
|
|
|
|
// Scrollbars
|
1999-02-12 06:19:07 +00:00
|
|
|
nsIAtom * sbAtom = NS_NewAtom(":scrollbar-look");
|
1999-02-11 15:56:23 +00:00
|
|
|
nsIStyleContext* scrollbarStyle;
|
1999-02-12 17:45:58 +00:00
|
|
|
aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, aStyleContext, PR_FALSE, &scrollbarStyle);
|
1998-12-16 18:12:55 +00:00
|
|
|
NS_RELEASE(sbAtom);
|
1999-02-12 17:45:58 +00:00
|
|
|
|
1999-02-12 06:19:07 +00:00
|
|
|
sbAtom = NS_NewAtom(":scrollbar-arrow-look");
|
1999-02-11 15:56:23 +00:00
|
|
|
nsIStyleContext* arrowStyle;
|
1999-02-12 17:45:58 +00:00
|
|
|
aPresContext.ResolvePseudoStyleContextFor(mContent, sbAtom, aStyleContext, PR_FALSE, &arrowStyle);
|
1998-12-16 18:12:55 +00:00
|
|
|
NS_RELEASE(sbAtom);
|
|
|
|
|
1999-02-18 00:13:39 +00:00
|
|
|
nsRect srect(aRect.width-scrollbarScaledWidth-(2*onePixel), 2*onePixel, scrollbarScaledWidth, aRect.height-(onePixel*4)-scrollbarScaledWidth);
|
1998-12-16 18:12:55 +00:00
|
|
|
|
1999-01-22 15:32:57 +00:00
|
|
|
nsFormControlHelper::PaintScrollbar(aRenderingContext,aPresContext, aDirtyRect, srect, PR_FALSE, onePixel,
|
1999-02-18 00:13:39 +00:00
|
|
|
scrollbarStyle, arrowStyle, this, aRect);
|
1998-12-16 18:12:55 +00:00
|
|
|
// Horizontal
|
1999-02-18 00:13:39 +00:00
|
|
|
srect.SetRect(2*onePixel, aRect.height-scrollbarScaledHeight-(2*onePixel), aRect.width-(onePixel*4)-scrollbarScaledHeight, scrollbarScaledHeight);
|
1999-01-22 15:32:57 +00:00
|
|
|
nsFormControlHelper::PaintScrollbar(aRenderingContext,aPresContext, aDirtyRect, srect, PR_TRUE, onePixel,
|
1999-02-18 00:13:39 +00:00
|
|
|
scrollbarStyle, arrowStyle, this, aRect);
|
1998-12-16 18:12:55 +00:00
|
|
|
|
|
|
|
// Draw the small rect "gap" in the bottom right that the two scrollbars don't cover
|
|
|
|
const nsStyleColor* sbColor = (const nsStyleColor*)scrollbarStyle->GetStyleData(eStyleStruct_Color);
|
1999-02-18 00:13:39 +00:00
|
|
|
srect.SetRect(aRect.width-scrollbarScaledWidth-(2*onePixel), aRect.height-scrollbarScaledHeight-(onePixel*2), scrollbarScaledWidth, scrollbarScaledHeight);
|
1998-12-16 18:12:55 +00:00
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
1999-01-15 18:25:58 +00:00
|
|
|
aDirtyRect, srect, *sbColor, *spacing, 0, 0);
|
1998-12-15 19:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
NS_RELEASE(context);
|
1998-12-10 17:53:34 +00:00
|
|
|
|
1998-12-16 18:12:55 +00:00
|
|
|
PRBool status;
|
|
|
|
aRenderingContext.PopState(status);
|
1998-12-10 17:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsTextControlFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 15:54:23 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-12-10 17:53:34 +00:00
|
|
|
{
|
1999-02-18 00:13:39 +00:00
|
|
|
PaintTextControlBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1999-03-26 00:39:35 +00:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
1999-02-11 01:13:28 +00:00
|
|
|
nsString text;
|
|
|
|
GetText(&text, PR_FALSE);
|
1999-02-18 00:13:39 +00:00
|
|
|
nsRect rect(0, 0, mRect.width, mRect.height);
|
|
|
|
PaintTextControl(aPresContext, aRenderingContext, aDirtyRect, text, mStyleContext, rect);
|
1998-12-18 15:54:23 +00:00
|
|
|
}
|
1998-12-10 17:53:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-25 22:16:27 +00:00
|
|
|
|
1999-01-28 18:58:11 +00:00
|
|
|
void nsTextControlFrame::GetTextControlFrameState(nsString& aValue)
|
|
|
|
{
|
|
|
|
if (nsnull != mWidget) {
|
|
|
|
nsITextWidget* text = nsnull;
|
1999-02-01 18:44:59 +00:00
|
|
|
nsITextAreaWidget* textArea = nsnull;
|
|
|
|
PRUint32 size = 0;
|
1999-01-28 18:58:11 +00:00
|
|
|
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
|
|
|
|
text->GetText(aValue,0,size);
|
|
|
|
NS_RELEASE(text);
|
|
|
|
}
|
1999-02-01 18:44:59 +00:00
|
|
|
else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,
|
|
|
|
(void**)&textArea)) {
|
|
|
|
textArea->GetText(aValue,0, size);
|
|
|
|
NS_RELEASE(textArea);
|
|
|
|
}
|
1999-01-28 18:58:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
//XXX: this should return the a local field for GFX-rendered widgets aValue = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTextControlFrame::SetTextControlFrameState(const nsString& aValue)
|
|
|
|
{
|
|
|
|
if (nsnull != mWidget) {
|
|
|
|
nsITextWidget* text = nsnull;
|
1999-02-01 18:44:59 +00:00
|
|
|
nsITextAreaWidget* textArea = nsnull;
|
|
|
|
PRUint32 size = 0;
|
1999-02-11 01:13:28 +00:00
|
|
|
if (NS_SUCCEEDED(mWidget->QueryInterface(kITextWidgetIID,(void**)&text))) {
|
1999-01-28 18:58:11 +00:00
|
|
|
text->SetText(aValue,size);
|
|
|
|
NS_RELEASE(text);
|
1999-02-01 18:44:59 +00:00
|
|
|
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,
|
|
|
|
(void**)&textArea)) {
|
|
|
|
textArea->SetText(aValue,size);
|
|
|
|
NS_RELEASE(textArea);
|
1999-01-28 18:58:11 +00:00
|
|
|
}
|
1999-02-01 18:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
1999-01-28 18:58:11 +00:00
|
|
|
|
1999-01-25 22:16:27 +00:00
|
|
|
NS_IMETHODIMP nsTextControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
|
|
|
|
{
|
1999-01-28 18:58:11 +00:00
|
|
|
if (nsHTMLAtoms::value == aName) {
|
1999-03-03 03:06:36 +00:00
|
|
|
SetTextControlFrameState(aValue);
|
|
|
|
}
|
1999-01-28 18:58:11 +00:00
|
|
|
else {
|
|
|
|
return nsFormControlFrame::SetProperty(aName, aValue);
|
|
|
|
}
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
1999-01-28 18:58:11 +00:00
|
|
|
}
|
1999-01-25 22:16:27 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsTextControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
|
|
|
|
{
|
1999-01-28 18:58:11 +00:00
|
|
|
// Return the value of the property from the widget it is not null.
|
|
|
|
// If widget is null, assume the widget is GFX-rendered and return a member variable instead.
|
|
|
|
|
|
|
|
if (nsHTMLAtoms::value == aName) {
|
|
|
|
GetTextControlFrameState(aValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return nsFormControlFrame::GetProperty(aName, aValue);
|
|
|
|
}
|
|
|
|
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
1999-01-28 18:58:11 +00:00
|
|
|
}
|