Moved GetPrimaryFrame to nsGenericHTMLElement.

Modifed nsHTMLTextAreaElement to go through it's frame to set and get values
This commit is contained in:
kmcclusk%netscape.com 1999-02-01 18:44:59 +00:00
Родитель f1c963f7b5
Коммит 78015f31f6
10 изменённых файлов: 132 добавлений и 112 удалений

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

@ -67,6 +67,7 @@
#include "nsDOMCSSDeclaration.h"
#include "prprf.h"
#include "prmem.h"
#include "nsIFormControlFrame.h"
// XXX todo: add in missing out-of-memory checks
NS_DEFINE_IID(kIDOMHTMLElementIID, NS_IDOMHTMLELEMENT_IID);
@ -83,6 +84,7 @@ static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID);
static NS_DEFINE_IID(kIHTMLContentContainerIID, NS_IHTMLCONTENTCONTAINER_IID);
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
//----------------------------------------------------------------------
@ -1407,6 +1409,31 @@ nsGenericHTMLElement::ColorToString(const nsHTMLValue& aValue,
return PR_FALSE;
}
// XXX This creates a dependency between content and frames
nsresult
nsGenericHTMLElement::GetPrimaryFrame(nsIHTMLContent* aContent,
nsIFormControlFrame *&aFormControlFrame)
{
nsIDocument* doc = nsnull;
nsresult res;
// Get the document
if (NS_OK == aContent->GetDocument(doc)) {
// Get presentation shell 0
nsIPresShell* presShell = doc->GetShellAt(0);
if (nsnull != presShell) {
nsIFrame *frame = nsnull;
presShell->GetPrimaryFrameFor(aContent, frame);
if (nsnull != frame) {
res = frame->QueryInterface(kIFormControlFrameIID, (void**)&aFormControlFrame);
}
NS_RELEASE(presShell);
}
NS_RELEASE(doc);
}
return res;
}
// XXX check all mappings against ebina's usage
static nsGenericHTMLElement::EnumTable kAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },

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

@ -46,6 +46,7 @@ class nsChildContentList;
class nsDOMCSSDeclaration;
class nsIDOMCSSStyleDeclaration;
class nsIURL;
class nsIFormControlFrame;
class nsGenericHTMLElement : public nsGenericElement {
public:
@ -237,6 +238,10 @@ public:
const nsIAtom* aAttribute,
PRInt32* aHint);
//XXX This creates a dependency between content and frames
static nsresult GetPrimaryFrame(nsIHTMLContent* aContent,
nsIFormControlFrame *&aFormControlFrame);
nsIHTMLAttributes* mAttributes;
};

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

@ -139,9 +139,6 @@ protected:
nsIForm* mForm;
PRInt32 mType;
// Return the primary frame associated with this content
nsresult GetPrimaryFrame(nsIFormControlFrame *&aFormControlFrame);
PRBool IsImage() const {
nsAutoString tmp;
mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, tmp);
@ -324,7 +321,7 @@ nsHTMLInputElement::GetValue(nsString& aValue)
GetType(&type);
if (NS_FORM_INPUT_TEXT == type || NS_FORM_INPUT_PASSWORD == type) {
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->GetProperty(nsHTMLAtoms::value, aValue);
NS_RELEASE(formControlFrame);
return NS_OK;
@ -341,7 +338,7 @@ nsHTMLInputElement::SetValue(const nsString& aValue)
GetType(&type);
if (NS_FORM_INPUT_TEXT == type) {
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->SetProperty(nsHTMLAtoms::value, aValue);
NS_RELEASE(formControlFrame);
}
@ -353,7 +350,7 @@ NS_IMETHODIMP
nsHTMLInputElement::GetChecked(PRBool* aValue)
{
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
if (nsnull != formControlFrame) {
nsString value("0");
formControlFrame->GetProperty(nsHTMLAtoms::checked, value);
@ -373,7 +370,7 @@ NS_IMETHODIMP
nsHTMLInputElement::SetChecked(PRBool aValue)
{
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
if (PR_TRUE == aValue) {
formControlFrame->SetProperty(nsHTMLAtoms::checked, "1");
}
@ -679,26 +676,4 @@ nsHTMLInputElement::GetStyleHintForAttributeChange(
return NS_OK;
}
nsresult nsHTMLInputElement::GetPrimaryFrame(nsIFormControlFrame *&aFormControlFrame)
{
nsIDocument* doc = nsnull;
nsresult res = NS_NOINTERFACE;
// Get the document
if (NS_OK == GetDocument(doc)) {
// Get presentation shell 0
nsIPresShell* presShell = doc->GetShellAt(0);
if (nsnull != presShell) {
nsIFrame *frame = nsnull;
presShell->GetPrimaryFrameFor(this, frame);
if (nsnull != frame) {
res = frame->QueryInterface(kIFormControlFrameIID, (void**)&aFormControlFrame);
}
NS_RELEASE(presShell);
}
NS_RELEASE(doc);
}
return res;
}

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

@ -32,6 +32,7 @@
#include "nsIWidget.h"
#include "nsITextAreaWidget.h"
#include "nsIHTMLAttributes.h"
#include "nsIFormControlFrame.h"
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
@ -265,39 +266,32 @@ nsHTMLTextAreaElement::GetType(nsString& aType)
NS_IMETHODIMP
nsHTMLTextAreaElement::GetValue(nsString& aValue)
{
if (nsnull != mWidget) {
nsITextAreaWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&text)) {
PRUint32 size;
text->GetText(aValue,0,size);
NS_RELEASE(text);
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->GetProperty(nsHTMLAtoms::value, aValue);
NS_RELEASE(formControlFrame);
return NS_OK;
}
}
return mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, aValue);
}
//XXX: Should this ASSERT instead of getting the default value here?
return mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, aValue);
}
NS_IMETHODIMP
nsHTMLTextAreaElement::SetValue(const nsString& aValue)
{
if (nsnull != mWidget) {
nsITextAreaWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&text)) {
PRUint32 size;
text->SetText(aValue,size);
NS_RELEASE(text);
}
}
return mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, aValue, PR_TRUE);
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->SetProperty(nsHTMLAtoms::value, aValue);
NS_RELEASE(formControlFrame);
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLTextAreaElement::GetDefaultValue(nsString& aDefaultValue)
{
mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::defaultvalue, aDefaultValue);
mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, aDefaultValue);
return NS_OK;
}
@ -308,7 +302,6 @@ nsHTMLTextAreaElement::SetDefaultValue(const nsString& aDefaultValue)
static char whitespace[] = " \r\n\t";
nsString value(aDefaultValue);
value.Trim(whitespace, PR_TRUE, PR_FALSE);
mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::defaultvalue, value, PR_TRUE);
mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, value, PR_TRUE);
return NS_OK;

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

@ -739,11 +739,17 @@ void nsTextControlFrame::GetTextControlFrameState(nsString& aValue)
{
if (nsnull != mWidget) {
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
PRUint32 size = 0;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
PRUint32 size;
text->GetText(aValue,0,size);
NS_RELEASE(text);
}
else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,
(void**)&textArea)) {
textArea->GetText(aValue,0, size);
NS_RELEASE(textArea);
}
}
else {
//XXX: this should return the a local field for GFX-rendered widgets aValue = "";
@ -754,13 +760,18 @@ void nsTextControlFrame::SetTextControlFrameState(const nsString& aValue)
{
if (nsnull != mWidget) {
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
PRUint32 size = 0;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
PRUint32 size;
text->SetText(aValue,size);
NS_RELEASE(text);
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,
(void**)&textArea)) {
textArea->SetText(aValue,size);
NS_RELEASE(textArea);
}
}
}
}
}
NS_IMETHODIMP nsTextControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
{
@ -769,7 +780,6 @@ NS_IMETHODIMP nsTextControlFrame::SetProperty(nsIAtom* aName, const nsString& aV
else {
return nsFormControlFrame::SetProperty(aName, aValue);
}
return NS_OK;
}

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

@ -67,6 +67,7 @@
#include "nsDOMCSSDeclaration.h"
#include "prprf.h"
#include "prmem.h"
#include "nsIFormControlFrame.h"
// XXX todo: add in missing out-of-memory checks
NS_DEFINE_IID(kIDOMHTMLElementIID, NS_IDOMHTMLELEMENT_IID);
@ -83,6 +84,7 @@ static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMDocumentFragmentIID, NS_IDOMDOCUMENTFRAGMENT_IID);
static NS_DEFINE_IID(kIHTMLContentContainerIID, NS_IHTMLCONTENTCONTAINER_IID);
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
//----------------------------------------------------------------------
@ -1407,6 +1409,31 @@ nsGenericHTMLElement::ColorToString(const nsHTMLValue& aValue,
return PR_FALSE;
}
// XXX This creates a dependency between content and frames
nsresult
nsGenericHTMLElement::GetPrimaryFrame(nsIHTMLContent* aContent,
nsIFormControlFrame *&aFormControlFrame)
{
nsIDocument* doc = nsnull;
nsresult res;
// Get the document
if (NS_OK == aContent->GetDocument(doc)) {
// Get presentation shell 0
nsIPresShell* presShell = doc->GetShellAt(0);
if (nsnull != presShell) {
nsIFrame *frame = nsnull;
presShell->GetPrimaryFrameFor(aContent, frame);
if (nsnull != frame) {
res = frame->QueryInterface(kIFormControlFrameIID, (void**)&aFormControlFrame);
}
NS_RELEASE(presShell);
}
NS_RELEASE(doc);
}
return res;
}
// XXX check all mappings against ebina's usage
static nsGenericHTMLElement::EnumTable kAlignTable[] = {
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },

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

@ -46,6 +46,7 @@ class nsChildContentList;
class nsDOMCSSDeclaration;
class nsIDOMCSSStyleDeclaration;
class nsIURL;
class nsIFormControlFrame;
class nsGenericHTMLElement : public nsGenericElement {
public:
@ -237,6 +238,10 @@ public:
const nsIAtom* aAttribute,
PRInt32* aHint);
//XXX This creates a dependency between content and frames
static nsresult GetPrimaryFrame(nsIHTMLContent* aContent,
nsIFormControlFrame *&aFormControlFrame);
nsIHTMLAttributes* mAttributes;
};

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

@ -139,9 +139,6 @@ protected:
nsIForm* mForm;
PRInt32 mType;
// Return the primary frame associated with this content
nsresult GetPrimaryFrame(nsIFormControlFrame *&aFormControlFrame);
PRBool IsImage() const {
nsAutoString tmp;
mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, tmp);
@ -324,7 +321,7 @@ nsHTMLInputElement::GetValue(nsString& aValue)
GetType(&type);
if (NS_FORM_INPUT_TEXT == type || NS_FORM_INPUT_PASSWORD == type) {
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->GetProperty(nsHTMLAtoms::value, aValue);
NS_RELEASE(formControlFrame);
return NS_OK;
@ -341,7 +338,7 @@ nsHTMLInputElement::SetValue(const nsString& aValue)
GetType(&type);
if (NS_FORM_INPUT_TEXT == type) {
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->SetProperty(nsHTMLAtoms::value, aValue);
NS_RELEASE(formControlFrame);
}
@ -353,7 +350,7 @@ NS_IMETHODIMP
nsHTMLInputElement::GetChecked(PRBool* aValue)
{
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
if (nsnull != formControlFrame) {
nsString value("0");
formControlFrame->GetProperty(nsHTMLAtoms::checked, value);
@ -373,7 +370,7 @@ NS_IMETHODIMP
nsHTMLInputElement::SetChecked(PRBool aValue)
{
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == GetPrimaryFrame(formControlFrame)) {
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
if (PR_TRUE == aValue) {
formControlFrame->SetProperty(nsHTMLAtoms::checked, "1");
}
@ -679,26 +676,4 @@ nsHTMLInputElement::GetStyleHintForAttributeChange(
return NS_OK;
}
nsresult nsHTMLInputElement::GetPrimaryFrame(nsIFormControlFrame *&aFormControlFrame)
{
nsIDocument* doc = nsnull;
nsresult res = NS_NOINTERFACE;
// Get the document
if (NS_OK == GetDocument(doc)) {
// Get presentation shell 0
nsIPresShell* presShell = doc->GetShellAt(0);
if (nsnull != presShell) {
nsIFrame *frame = nsnull;
presShell->GetPrimaryFrameFor(this, frame);
if (nsnull != frame) {
res = frame->QueryInterface(kIFormControlFrameIID, (void**)&aFormControlFrame);
}
NS_RELEASE(presShell);
}
NS_RELEASE(doc);
}
return res;
}

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

@ -32,6 +32,7 @@
#include "nsIWidget.h"
#include "nsITextAreaWidget.h"
#include "nsIHTMLAttributes.h"
#include "nsIFormControlFrame.h"
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID);
@ -265,39 +266,32 @@ nsHTMLTextAreaElement::GetType(nsString& aType)
NS_IMETHODIMP
nsHTMLTextAreaElement::GetValue(nsString& aValue)
{
if (nsnull != mWidget) {
nsITextAreaWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&text)) {
PRUint32 size;
text->GetText(aValue,0,size);
NS_RELEASE(text);
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->GetProperty(nsHTMLAtoms::value, aValue);
NS_RELEASE(formControlFrame);
return NS_OK;
}
}
return mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, aValue);
}
//XXX: Should this ASSERT instead of getting the default value here?
return mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, aValue);
}
NS_IMETHODIMP
nsHTMLTextAreaElement::SetValue(const nsString& aValue)
{
if (nsnull != mWidget) {
nsITextAreaWidget* text = nsnull;
if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,(void**)&text)) {
PRUint32 size;
text->SetText(aValue,size);
NS_RELEASE(text);
}
}
return mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, aValue, PR_TRUE);
nsIFormControlFrame* formControlFrame = nsnull;
if (NS_OK == nsGenericHTMLElement::GetPrimaryFrame(this, formControlFrame)) {
formControlFrame->SetProperty(nsHTMLAtoms::value, aValue);
NS_RELEASE(formControlFrame);
}
return NS_OK;
}
NS_IMETHODIMP
nsHTMLTextAreaElement::GetDefaultValue(nsString& aDefaultValue)
{
mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::defaultvalue, aDefaultValue);
mInner.GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, aDefaultValue);
return NS_OK;
}
@ -308,7 +302,6 @@ nsHTMLTextAreaElement::SetDefaultValue(const nsString& aDefaultValue)
static char whitespace[] = " \r\n\t";
nsString value(aDefaultValue);
value.Trim(whitespace, PR_TRUE, PR_FALSE);
mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::defaultvalue, value, PR_TRUE);
mInner.SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::value, value, PR_TRUE);
return NS_OK;

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

@ -739,11 +739,17 @@ void nsTextControlFrame::GetTextControlFrameState(nsString& aValue)
{
if (nsnull != mWidget) {
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
PRUint32 size = 0;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
PRUint32 size;
text->GetText(aValue,0,size);
NS_RELEASE(text);
}
else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,
(void**)&textArea)) {
textArea->GetText(aValue,0, size);
NS_RELEASE(textArea);
}
}
else {
//XXX: this should return the a local field for GFX-rendered widgets aValue = "";
@ -754,13 +760,18 @@ void nsTextControlFrame::SetTextControlFrameState(const nsString& aValue)
{
if (nsnull != mWidget) {
nsITextWidget* text = nsnull;
nsITextAreaWidget* textArea = nsnull;
PRUint32 size = 0;
if (NS_OK == mWidget->QueryInterface(kITextWidgetIID,(void**)&text)) {
PRUint32 size;
text->SetText(aValue,size);
NS_RELEASE(text);
} else if (NS_OK == mWidget->QueryInterface(kITextAreaWidgetIID,
(void**)&textArea)) {
textArea->SetText(aValue,size);
NS_RELEASE(textArea);
}
}
}
}
}
NS_IMETHODIMP nsTextControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
{
@ -769,7 +780,6 @@ NS_IMETHODIMP nsTextControlFrame::SetProperty(nsIAtom* aName, const nsString& aV
else {
return nsFormControlFrame::SetProperty(aName, aValue);
}
return NS_OK;
}