1998-09-23 21:16:51 +04: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsFileControlFrame.h"
|
1998-10-14 01:31:26 +04:00
|
|
|
#include "nsFormFrame.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsButtonControlFrame.h"
|
|
|
|
#include "nsTextControlFrame.h"
|
1999-06-13 02:29:54 +04:00
|
|
|
#include "nsNativeTextControlFrame.h" // XXX: remove when frame construction is done properly
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIFileWidget.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsIFormControl.h"
|
1998-12-20 04:21:23 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-02-18 03:13:39 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-06-05 15:49:04 +04:00
|
|
|
#include "nsFileSpec.h"
|
1999-07-01 02:17:43 +04:00
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsDocument.h"
|
|
|
|
#include "nsIDOMMouseListener.h"
|
1999-08-21 04:09:24 +04:00
|
|
|
#include "nsIPresShell.h"
|
1999-09-08 03:20:32 +04:00
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
1999-09-15 09:31:31 +04:00
|
|
|
#include "nsIStatefulFrame.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIComponentManager.h"
|
1998-09-23 21:16:51 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
|
|
|
|
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
|
|
|
|
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
|
1999-02-18 03:13:39 +03:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
|
1999-07-01 02:17:43 +04:00
|
|
|
static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIAnonymousContentCreatorIID, NS_IANONYMOUS_CONTENT_CREATOR_IID);
|
1998-09-23 21:16:51 +04:00
|
|
|
|
|
|
|
nsresult
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_NewFileControlFrame(nsIFrame** aNewFrame)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-07-01 02:17:43 +04:00
|
|
|
nsFileControlFrame* it = new nsFileControlFrame();
|
1999-05-12 02:03:29 +04:00
|
|
|
if (!it) {
|
1998-09-23 21:16:51 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = it;
|
1998-09-23 21:16:51 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
nsFileControlFrame::nsFileControlFrame():
|
|
|
|
mTextFrame(nsnull),
|
|
|
|
mFormFrame(nsnull),
|
1999-09-19 11:25:12 +04:00
|
|
|
mTextContent(nsnull),
|
|
|
|
mCachedState(nsnull)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-15 02:00:24 +04:00
|
|
|
//Shrink the area around it's contents
|
|
|
|
SetFlags(NS_BLOCK_SHRINK_WRAP);
|
1999-07-01 02:17:43 +04:00
|
|
|
}
|
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
nsFileControlFrame::~nsFileControlFrame()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mTextContent);
|
1999-09-15 09:31:31 +04:00
|
|
|
if (mCachedState) {
|
|
|
|
delete mCachedState;
|
|
|
|
mCachedState = nsnull;
|
|
|
|
}
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::CreateAnonymousContent(nsISupportsArray& aChildList)
|
|
|
|
{
|
|
|
|
|
|
|
|
// create text field
|
|
|
|
nsIAtom* tag = NS_NewAtom("input");
|
1999-08-19 18:03:53 +04:00
|
|
|
if (NS_OK == NS_NewHTMLInputElement(&mTextContent, tag)) {
|
|
|
|
mTextContent->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, nsAutoString("text"), PR_FALSE);
|
|
|
|
if (nsFormFrame::GetDisabled(this)) {
|
1999-09-08 03:20:32 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> textControl = do_QueryInterface(mTextContent);
|
|
|
|
if (textControl) {
|
|
|
|
textControl->SetDisabled(nsFormFrame::GetDisabled(this));
|
|
|
|
}
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
|
|
|
aChildList.AppendElement(mTextContent);
|
|
|
|
}
|
1999-07-01 02:17:43 +04:00
|
|
|
|
|
|
|
// create browse button
|
|
|
|
nsIHTMLContent* browse = nsnull;
|
|
|
|
tag = NS_NewAtom("input");
|
1999-08-19 18:03:53 +04:00
|
|
|
if (NS_OK == NS_NewHTMLInputElement(&browse, tag)) {
|
|
|
|
browse->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, nsAutoString("button"), PR_FALSE);
|
|
|
|
//browse->SetAttribute(kNameSpaceID_None, nsHTMLAtoms::value, nsAutoString("browse..."), PR_FALSE);
|
1999-07-01 02:17:43 +04:00
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
aChildList.AppendElement(browse);
|
1999-07-01 02:17:43 +04:00
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
// get the reciever interface from the browser button's content node
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(browse));
|
|
|
|
|
|
|
|
// we shouldn't have to unregister this listener because when
|
|
|
|
// our frame goes away all these content node go away as well
|
|
|
|
// because our frame is the only one who references them.
|
|
|
|
reciever->AddEventListenerByIID(this, kIDOMMouseListenerIID);
|
|
|
|
}
|
1999-07-01 02:17:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
1999-09-15 09:31:31 +04:00
|
|
|
NS_IMETHODIMP
|
1998-09-23 21:16:51 +04:00
|
|
|
nsFileControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-09-15 09:31:31 +04:00
|
|
|
} else if (aIID.Equals(kIAnonymousContentCreatorIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIAnonymousContentCreator*) this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
1999-07-01 02:17:43 +04:00
|
|
|
} else if (aIID.Equals(kIFormControlFrameIID)) {
|
1998-09-23 21:16:51 +04:00
|
|
|
*aInstancePtr = (void*) ((nsIFormControlFrame*) this);
|
|
|
|
return NS_OK;
|
1999-09-15 09:31:31 +04:00
|
|
|
} else if (aIID.Equals(kIDOMMouseListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMMouseListener*) this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(NS_GET_IID(nsIStatefulFrame))) {
|
|
|
|
*aInstancePtr = (void*)(nsIStatefulFrame*) this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1998-10-30 21:05:29 +03:00
|
|
|
nsFileControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
|
|
|
nsAutoString name;
|
|
|
|
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFileControlFrame::Reset()
|
|
|
|
{
|
|
|
|
if (mTextFrame) {
|
|
|
|
mTextFrame->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetType(PRInt32* aType) const
|
|
|
|
{
|
|
|
|
*aType = NS_FORM_INPUT_FILE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX this should be removed when nsView exposes it
|
1999-01-06 21:44:59 +03:00
|
|
|
nsIWidget* GetWindowTemp(nsIView *aView);
|
1998-09-23 21:16:51 +04:00
|
|
|
nsIWidget*
|
1999-01-22 18:32:57 +03:00
|
|
|
nsFileControlFrame::GetWindowTemp(nsIView *aView)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
|
|
|
nsIWidget *window = nsnull;
|
|
|
|
|
|
|
|
nsIView *ancestor = aView;
|
|
|
|
while (nsnull != ancestor) {
|
|
|
|
ancestor->GetWidget(window);
|
|
|
|
if (nsnull != window) {
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
ancestor->GetParent(ancestor);
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-23 03:00:37 +04:00
|
|
|
void
|
|
|
|
nsFileControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
if (mTextFrame) {
|
|
|
|
mTextFrame->SetFocus(aOn, aRepaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-21 04:09:24 +04:00
|
|
|
void
|
|
|
|
nsFileControlFrame::ScrollIntoView(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
if (aPresContext) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
presShell->ScrollFrameIntoView(this,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE,NS_PRESSHELL_SCROLL_ANYWHERE);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
/**
|
|
|
|
* This is called when our browse button is clicked
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
|
|
|
nsIView* textView;
|
1999-02-10 08:38:18 +03:00
|
|
|
mTextFrame->GetView(&textView);
|
1998-09-23 21:16:51 +04:00
|
|
|
if (nsnull == textView) {
|
1999-07-01 02:17:43 +04:00
|
|
|
return NS_OK;
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
1999-05-14 03:45:40 +04:00
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
1998-09-23 21:16:51 +04:00
|
|
|
nsIView* parentView;
|
|
|
|
textView->GetParent(parentView);
|
|
|
|
nsIWidget* parentWidget = GetWindowTemp(parentView);
|
|
|
|
|
1999-05-07 08:54:43 +04:00
|
|
|
nsIFileWidget *fileWidget = nsnull;
|
|
|
|
|
1999-04-03 06:32:46 +04:00
|
|
|
nsString title("File Upload");
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCFileWidgetCID, nsnull, kIFileWidgetIID, (void**)&fileWidget);
|
1998-09-23 21:16:51 +04:00
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
if (fileWidget) {
|
1999-09-19 11:25:12 +04:00
|
|
|
nsString titles[] = {"all files"};
|
|
|
|
nsString filters[] = {"*.*"};
|
|
|
|
fileWidget->SetFilterList(1, titles, filters);
|
|
|
|
|
|
|
|
fileWidget->Create(parentWidget, title, eMode_load, nsnull, nsnull);
|
|
|
|
result = fileWidget->Show();
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
nsFileSpec fileSpec;
|
|
|
|
fileWidget->GetFile(fileSpec);
|
|
|
|
char* leafName = fileSpec.GetLeafName();
|
|
|
|
if (leafName) {
|
|
|
|
mTextFrame->SetProperty(nsHTMLAtoms::value,leafName);
|
|
|
|
nsCRT::free(leafName);
|
1999-05-28 04:40:18 +04:00
|
|
|
}
|
1999-09-19 11:25:12 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(fileWidget);
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(parentWidget);
|
1999-07-01 02:17:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-02 08:10:00 +04:00
|
|
|
NS_IMETHODIMP nsFileControlFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-23 21:16:51 +04:00
|
|
|
{
|
1999-07-01 02:17:43 +04:00
|
|
|
if (mFormFrame == nsnull && eReflowReason_Initial == aReflowState.reason) {
|
|
|
|
// add ourself as an nsIFormControlFrame
|
1999-05-08 00:30:16 +04:00
|
|
|
nsFormFrame::AddFormControlFrame(aPresContext, *this);
|
1999-07-01 02:17:43 +04:00
|
|
|
mTextFrame = GetTextControlFrame(this);
|
1999-09-15 09:31:31 +04:00
|
|
|
if (!mTextFrame) return NS_ERROR_UNEXPECTED;
|
|
|
|
if (mCachedState) {
|
|
|
|
mTextFrame->SetProperty(nsHTMLAtoms::value, *mCachedState);
|
|
|
|
delete mCachedState;
|
|
|
|
mCachedState = nsnull;
|
|
|
|
}
|
1999-05-08 00:30:16 +04:00
|
|
|
}
|
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
return nsAreaFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
/*
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::SetInitialChildList(nsIPresContext& aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
|
|
|
nsresult r = nsAreaFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
1998-09-23 21:16:51 +04:00
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
// given that the CSS frame constuctor created all our frames. We need to find the text field
|
|
|
|
// so we can get info from it.
|
|
|
|
mTextFrame = GetTextControlFrame(this);
|
|
|
|
}
|
|
|
|
*/
|
1998-09-23 21:16:51 +04:00
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
/**
|
|
|
|
* Given a start node. Find the given text node inside. We need to do this because the
|
|
|
|
* frame constuctor create the frame and its implementation. So we are given the text
|
|
|
|
* node from the constructor and we find it in our tree.
|
|
|
|
*/
|
|
|
|
nsTextControlFrame*
|
|
|
|
nsFileControlFrame::GetTextControlFrame(nsIFrame* aStart)
|
|
|
|
{
|
|
|
|
// find the text control frame.
|
|
|
|
nsIFrame* childFrame = nsnull;
|
|
|
|
aStart->FirstChild(nsnull, &childFrame);
|
|
|
|
|
1999-09-15 09:31:31 +04:00
|
|
|
while (childFrame) {
|
1999-07-01 02:17:43 +04:00
|
|
|
// see if the child is a text control
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
childFrame->GetContent(getter_AddRefs(content));
|
|
|
|
nsIAtom* atom;
|
|
|
|
if (content->GetTag(atom) == NS_OK && atom == nsHTMLAtoms::input) {
|
|
|
|
nsString value;
|
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::type, value)) {
|
|
|
|
if (value == "text") {
|
1999-07-01 02:17:43 +04:00
|
|
|
return (nsTextControlFrame*)childFrame;
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
1999-07-01 02:17:43 +04:00
|
|
|
}
|
1998-10-01 08:46:11 +04:00
|
|
|
}
|
1998-09-23 21:16:51 +04:00
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
// if not continue looking
|
|
|
|
nsTextControlFrame* frame = GetTextControlFrame(childFrame);
|
1999-09-15 09:31:31 +04:00
|
|
|
if (frame)
|
1999-07-01 02:17:43 +04:00
|
|
|
return frame;
|
|
|
|
|
|
|
|
nsresult rv = childFrame->GetNextSibling(&childFrame);
|
|
|
|
NS_ASSERTION(rv == NS_OK,"failed to get next child");
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
1999-07-01 02:17:43 +04:00
|
|
|
return nsnull;
|
1998-09-23 21:16:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsFileControlFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetName(nsString* aResult)
|
|
|
|
{
|
|
|
|
nsresult result = NS_FORM_NOTOK;
|
|
|
|
if (mContent) {
|
|
|
|
nsIHTMLContent* formControl = nsnull;
|
|
|
|
result = mContent->QueryInterface(kIHTMLContentIID, (void**)&formControl);
|
|
|
|
if ((NS_OK == result) && formControl) {
|
|
|
|
nsHTMLValue value;
|
1998-12-20 04:21:23 +03:00
|
|
|
result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value);
|
1998-09-23 21:16:51 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
|
|
|
if (eHTMLUnit_String == value.GetUnit()) {
|
|
|
|
value.GetStringValue(*aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(formControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-02-11 04:13:28 +03:00
|
|
|
|
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
PRInt32
|
|
|
|
nsFileControlFrame::GetMaxNumValues()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFileControlFrame::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
|
|
|
|
nsString* aValues, nsString* aNames)
|
|
|
|
{
|
|
|
|
nsAutoString name;
|
|
|
|
nsresult result = GetName(&name);
|
|
|
|
if ((aMaxNumValues <= 0) || (NS_CONTENT_ATTR_HAS_VALUE != result)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use our name and the text widgets value
|
|
|
|
aNames[0] = name;
|
|
|
|
nsresult status = PR_FALSE;
|
1999-05-14 03:45:40 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mTextFrame->GetProperty(nsHTMLAtoms::value, aValues[0]))) {
|
1998-09-23 21:16:51 +04:00
|
|
|
aNumValues = 1;
|
|
|
|
status = PR_TRUE;
|
|
|
|
}
|
1999-05-14 03:45:40 +04:00
|
|
|
|
1998-09-23 21:16:51 +04:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1999-08-19 18:03:53 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
1999-10-16 03:16:45 +04:00
|
|
|
PRInt32 aNameSpaceID,
|
1999-08-19 18:03:53 +04:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
// set the text control to readonly or not
|
|
|
|
if (nsHTMLAtoms::disabled == aAttribute) {
|
1999-09-08 03:20:32 +04:00
|
|
|
//nsAutoString val(nsFormFrame::GetDisabled(this) ? "true":"false");
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> textControl = do_QueryInterface(mTextContent);
|
|
|
|
if (textControl)
|
|
|
|
{
|
|
|
|
textControl->SetDisabled(nsFormFrame::GetDisabled(this));
|
|
|
|
}
|
|
|
|
//mTextContent->SetHTMLAttribute(nsHTMLAtoms::disabled, val, PR_TRUE);
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
|
|
|
|
1999-10-16 03:16:45 +04:00
|
|
|
return nsAreaFrame::AttributeChanged(aPresContext, aChild, aNameSpaceID, aAttribute, aHint);
|
1999-08-19 18:03:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
|
|
|
|
{
|
|
|
|
if (nsFormFrame::GetDisabled(this)) {
|
|
|
|
*aFrame = this;
|
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
return nsAreaFrame::GetFrameForPoint(aPoint, aFrame);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("FileControl", aResult);
|
|
|
|
}
|
1999-01-22 18:32:57 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetFormContent(nsIContent*& aContent) const
|
|
|
|
{
|
1999-02-10 03:42:56 +03:00
|
|
|
nsIContent* content;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = GetContent(&content);
|
|
|
|
aContent = content;
|
|
|
|
return rv;
|
1999-01-22 18:32:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetFont(nsIPresContext* aPresContext,
|
|
|
|
nsFont& aFont)
|
|
|
|
{
|
|
|
|
nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nscoord
|
1999-09-30 15:30:04 +04:00
|
|
|
nsFileControlFrame::GetVerticalInsidePadding(nsIPresContext& aPresContext,
|
|
|
|
float aPixToTwip,
|
|
|
|
nscoord aInnerHeight) const
|
1999-01-22 18:32:57 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsFileControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
|
|
|
|
float aPixToTwip,
|
|
|
|
nscoord aInnerWidth,
|
|
|
|
nscoord aCharWidth) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
1999-01-26 01:16:27 +03:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
nsresult nsFileControlFrame::RequiresWidget(PRBool& aRequiresWidget)
|
|
|
|
{
|
|
|
|
aRequiresWidget = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-11 04:13:28 +03:00
|
|
|
|
1999-01-26 01:16:27 +03:00
|
|
|
NS_IMETHODIMP nsFileControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
|
|
|
|
{
|
1999-09-19 11:25:12 +04:00
|
|
|
nsresult rv = NS_OK;
|
1999-02-11 04:13:28 +03:00
|
|
|
if (nsHTMLAtoms::value == aName) {
|
1999-09-19 11:25:12 +04:00
|
|
|
if (mTextFrame) {
|
|
|
|
mTextFrame->SetTextControlFrameState(aValue);
|
|
|
|
} else {
|
|
|
|
if (mCachedState) delete mCachedState;
|
|
|
|
mCachedState = new nsString(aValue);
|
|
|
|
if (!mCachedState) rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-02-11 04:13:28 +03:00
|
|
|
}
|
1999-09-19 11:25:12 +04:00
|
|
|
return rv;
|
1999-02-11 04:13:28 +03:00
|
|
|
}
|
1999-01-26 01:16:27 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsFileControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
|
|
|
|
{
|
1999-02-11 04:13:28 +03: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) {
|
|
|
|
mTextFrame->GetTextControlFrameState(aValue);
|
|
|
|
}
|
|
|
|
|
1999-01-26 01:16:27 +03:00
|
|
|
return NS_OK;
|
1999-02-18 03:13:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-11 04:13:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsFileControlFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
1999-07-01 02:17:43 +04:00
|
|
|
return nsAreaFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1999-01-26 01:16:27 +03:00
|
|
|
}
|
1999-09-15 09:31:31 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIStatefulFrame
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetStateType(nsIStatefulFrame::StateType* aStateType)
|
|
|
|
{
|
|
|
|
*aStateType = nsIStatefulFrame::eFileType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::SaveState(nsISupports** aState)
|
|
|
|
{
|
|
|
|
nsISupportsString* value = nsnull;
|
|
|
|
nsAutoString string;
|
1999-09-17 00:26:44 +04:00
|
|
|
nsresult res = GetProperty(nsHTMLAtoms::value, string);
|
1999-09-15 09:31:31 +04:00
|
|
|
if (NS_SUCCEEDED(res)) {
|
|
|
|
char* chars = string.ToNewCString();
|
|
|
|
if (chars) {
|
|
|
|
res = nsComponentManager::CreateInstance(NS_SUPPORTS_STRING_PROGID, nsnull,
|
|
|
|
NS_GET_IID(nsISupportsString), (void**)&value);
|
|
|
|
if (NS_SUCCEEDED(res) && value) {
|
|
|
|
value->SetData(chars);
|
|
|
|
}
|
|
|
|
nsCRT::free(chars);
|
|
|
|
} else {
|
|
|
|
res = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aState = (nsISupports*)value;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::RestoreState(nsISupports* aState)
|
|
|
|
{
|
|
|
|
char* chars = nsnull;
|
|
|
|
nsresult res = ((nsISupportsString*)aState)->GetData(&chars);
|
|
|
|
if (NS_SUCCEEDED(res) && chars) {
|
1999-09-19 11:25:12 +04:00
|
|
|
nsAutoString value(chars);
|
|
|
|
SetProperty(nsHTMLAtoms::value, value);
|
1999-09-15 09:31:31 +04:00
|
|
|
nsCRT::free(chars);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|