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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsFileControlFrame.h"
|
1998-10-13 21:31:26 +00:00
|
|
|
#include "nsFormFrame.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsButtonControlFrame.h"
|
|
|
|
#include "nsTextControlFrame.h"
|
1999-06-12 22:29:54 +00:00
|
|
|
#include "nsNativeTextControlFrame.h" // XXX: remove when frame construction is done properly
|
1998-09-23 17:16:51 +00: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 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#include "nsIFormControl.h"
|
1998-12-20 01:21:23 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
1999-02-18 00:13:39 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-06-05 11:49:04 +00:00
|
|
|
#include "nsFileSpec.h"
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
// XXX make this pixels
|
|
|
|
#define CONTROL_SPACING 40
|
|
|
|
|
|
|
|
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 00:13:39 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
nsresult
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_NewFileControlFrame(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;
|
|
|
|
}
|
|
|
|
nsFileControlFrame* it = new nsFileControlFrame;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-12-03 06:31:43 +00:00
|
|
|
nsFileControlFrame::nsFileControlFrame()
|
|
|
|
: nsHTMLContainerFrame()
|
1998-09-23 17:16:51 +00:00
|
|
|
{
|
|
|
|
mTextFrame = nsnull;
|
|
|
|
mBrowseFrame = nsnull;
|
|
|
|
mFormFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFileControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIFormControlFrameIID)) {
|
|
|
|
*aInstancePtr = (void*) ((nsIFormControlFrame*) this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1998-10-30 18:05:29 +00:00
|
|
|
nsFileControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
|
1998-09-23 17:16:51 +00: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 18:44:59 +00:00
|
|
|
nsIWidget* GetWindowTemp(nsIView *aView);
|
1998-09-23 17:16:51 +00:00
|
|
|
nsIWidget*
|
1999-01-22 15:32:57 +00:00
|
|
|
nsFileControlFrame::GetWindowTemp(nsIView *aView)
|
1998-09-23 17:16:51 +00: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-22 23:00:37 +00:00
|
|
|
void
|
|
|
|
nsFileControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
if (mTextFrame) {
|
|
|
|
mTextFrame->SetFocus(aOn, aRepaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
// this is in response to the MouseClick from the containing browse button
|
|
|
|
// XXX still need to get filters from accept attribute
|
|
|
|
void nsFileControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsIView* textView;
|
1999-02-10 05:38:18 +00:00
|
|
|
mTextFrame->GetView(&textView);
|
1998-09-23 17:16:51 +00:00
|
|
|
if (nsnull == textView) {
|
|
|
|
return;
|
|
|
|
}
|
1999-05-13 23:45:40 +00:00
|
|
|
|
|
|
|
nsresult result = NS_OK;
|
1998-09-23 17:16:51 +00:00
|
|
|
nsIView* parentView;
|
|
|
|
textView->GetParent(parentView);
|
|
|
|
nsIWidget* parentWidget = GetWindowTemp(parentView);
|
|
|
|
|
1999-05-07 04:54:43 +00:00
|
|
|
nsIFileWidget *fileWidget = nsnull;
|
|
|
|
|
1999-04-03 02:32:46 +00:00
|
|
|
nsString title("File Upload");
|
1999-03-09 09:44:27 +00:00
|
|
|
nsComponentManager::CreateInstance(kCFileWidgetCID, nsnull, kIFileWidgetIID, (void**)&fileWidget);
|
1998-09-23 17:16:51 +00:00
|
|
|
|
1999-05-07 04:54:43 +00:00
|
|
|
if (fileWidget)
|
|
|
|
{
|
|
|
|
nsString titles[] = {"all files"};
|
|
|
|
nsString filters[] = {"*.*"};
|
|
|
|
fileWidget->SetFilterList(1, titles, filters);
|
|
|
|
|
|
|
|
fileWidget->Create(parentWidget, title, eMode_load, nsnull, nsnull);
|
|
|
|
result = fileWidget->Show();
|
|
|
|
|
|
|
|
if (result) {
|
1999-05-15 22:01:21 +00:00
|
|
|
nsFileSpec fileSpec;
|
|
|
|
fileWidget->GetFile(fileSpec);
|
1999-05-28 00:40:18 +00:00
|
|
|
char* leafName = fileSpec.GetLeafName();
|
|
|
|
if (leafName) {
|
|
|
|
mTextFrame->SetProperty(nsHTMLAtoms::value,leafName);
|
|
|
|
nsCRT::free(leafName);
|
|
|
|
}
|
1999-05-07 04:54:43 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(fileWidget);
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
NS_RELEASE(parentWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-10-02 04:10:00 +00:00
|
|
|
NS_IMETHODIMP nsFileControlFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-23 17:16:51 +00:00
|
|
|
{
|
1999-05-07 20:30:16 +00:00
|
|
|
// add ourself as an nsIFormControlFrame
|
|
|
|
if (!mFormFrame && (eReflowReason_Initial == aReflowState.reason)) {
|
|
|
|
nsFormFrame::AddFormControlFrame(aPresContext, *this);
|
|
|
|
}
|
|
|
|
|
1999-01-15 22:52:05 +00:00
|
|
|
PRInt32 numChildren = mFrames.GetLength();
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
nsIFrame* childFrame;
|
|
|
|
if (0 == numChildren) {
|
|
|
|
// XXX This code should move to Init(), someday when the frame construction
|
|
|
|
// changes are all done and Init() is always getting called...
|
1998-10-13 21:31:26 +00:00
|
|
|
PRBool disabled = nsFormFrame::GetDisabled(this);
|
1998-09-23 17:16:51 +00:00
|
|
|
nsIHTMLContent* text = nsnull;
|
|
|
|
nsIAtom* tag = NS_NewAtom("text");
|
|
|
|
NS_NewHTMLInputElement(&text, tag);
|
1998-12-20 01:21:23 +00:00
|
|
|
text->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, nsAutoString("text"), PR_FALSE);
|
1998-10-13 21:31:26 +00:00
|
|
|
if (disabled) {
|
1998-12-20 01:21:23 +00:00
|
|
|
text->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, nsAutoString("1"), PR_FALSE); // XXX this should use an "empty" bool value
|
1998-10-13 21:31:26 +00:00
|
|
|
}
|
1999-06-12 22:29:54 +00:00
|
|
|
|
|
|
|
// XXX: hard-wired for the native text control frame
|
|
|
|
// construction of the text control should happen in nsCSSFrameConstruction
|
|
|
|
NS_NewNativeTextControlFrame(&childFrame);
|
1999-02-18 00:13:39 +00:00
|
|
|
|
1999-02-18 22:07:23 +00:00
|
|
|
//XXX: This style should be cached, rather than resolved each time.
|
1999-02-18 00:13:39 +00:00
|
|
|
// Get pseudo style for the text field
|
|
|
|
nsCOMPtr<nsIStyleContext> textFieldStyleContext;
|
|
|
|
nsresult rv = aPresContext.ResolvePseudoStyleContextFor(mContent, nsHTMLAtoms::fileTextStylePseudo,
|
|
|
|
mStyleContext, PR_FALSE,
|
|
|
|
getter_AddRefs(textFieldStyleContext));
|
|
|
|
|
1999-02-18 22:07:23 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Found the pseudo style for the text field
|
1999-02-25 03:27:57 +00:00
|
|
|
childFrame->Init(aPresContext, text, this, textFieldStyleContext, nsnull);
|
1999-02-18 22:07:23 +00:00
|
|
|
} else {
|
|
|
|
// Can't find pseduo style so use the style set for the file updload element
|
1999-02-25 03:27:57 +00:00
|
|
|
childFrame->Init(aPresContext, mContent, this, mStyleContext, nsnull);
|
1999-02-18 22:07:23 +00:00
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
mTextFrame = (nsTextControlFrame*)childFrame;
|
1999-01-15 22:52:05 +00:00
|
|
|
mFrames.SetFrames(childFrame);
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
nsIHTMLContent* browse = nsnull;
|
|
|
|
tag = NS_NewAtom("browse");
|
|
|
|
NS_NewHTMLInputElement(&browse, tag);
|
1998-12-20 01:21:23 +00:00
|
|
|
browse->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::type, nsAutoString("browse"), PR_FALSE);
|
1998-10-13 21:31:26 +00:00
|
|
|
if (disabled) {
|
1998-12-20 01:21:23 +00:00
|
|
|
browse->SetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::disabled, nsAutoString("1"), PR_FALSE); // XXX should be "empty"
|
1998-10-13 21:31:26 +00:00
|
|
|
}
|
1999-05-11 22:03:29 +00:00
|
|
|
NS_NewButtonControlFrame(&childFrame);
|
1999-01-22 15:32:57 +00:00
|
|
|
((nsButtonControlFrame*)childFrame)->SetMouseListener((nsIFormControlFrame*)this);
|
1998-09-23 17:16:51 +00:00
|
|
|
mBrowseFrame = (nsButtonControlFrame*)childFrame;
|
1999-02-18 00:13:39 +00:00
|
|
|
|
1999-02-18 22:07:23 +00:00
|
|
|
//XXX: This style should be cached, rather than resolved each time.
|
|
|
|
// Get pseudo style for the button
|
1999-02-18 00:13:39 +00:00
|
|
|
nsCOMPtr<nsIStyleContext> buttonStyleContext;
|
|
|
|
rv = aPresContext.ResolvePseudoStyleContextFor(mContent, nsHTMLAtoms::fileButtonStylePseudo,
|
|
|
|
mStyleContext, PR_FALSE,
|
|
|
|
getter_AddRefs(buttonStyleContext));
|
1999-02-18 22:07:23 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Found pseduo style for the button
|
1999-02-25 03:27:57 +00:00
|
|
|
childFrame->Init(aPresContext, browse, this, buttonStyleContext, nsnull);
|
1999-02-18 22:07:23 +00:00
|
|
|
} else {
|
|
|
|
// Can't find pseudo style for the button so use the style set for the file upload element
|
1999-02-25 03:27:57 +00:00
|
|
|
childFrame->Init(aPresContext, mContent, this, mStyleContext, nsnull);
|
1999-02-18 22:07:23 +00:00
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
|
1999-01-15 22:52:05 +00:00
|
|
|
mFrames.FirstChild()->SetNextSibling(childFrame);
|
1998-09-23 17:16:51 +00:00
|
|
|
|
|
|
|
NS_RELEASE(text);
|
|
|
|
NS_RELEASE(browse);
|
|
|
|
}
|
|
|
|
|
1999-01-05 23:31:18 +00:00
|
|
|
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
|
1998-10-01 04:46:11 +00:00
|
|
|
nsHTMLReflowMetrics desiredSize = aDesiredSize;
|
1998-09-23 17:16:51 +00:00
|
|
|
aDesiredSize.width = CONTROL_SPACING;
|
|
|
|
aDesiredSize.height = 0;
|
1999-01-15 22:52:05 +00:00
|
|
|
childFrame = mFrames.FirstChild();
|
1998-09-23 17:16:51 +00:00
|
|
|
nsPoint offset(0,0);
|
|
|
|
while (nsnull != childFrame) { // reflow, place, size the children
|
1999-03-05 04:19:09 +00:00
|
|
|
nsHTMLReflowState reflowState(aPresContext, aReflowState, childFrame,
|
1998-10-12 14:48:02 +00:00
|
|
|
maxSize);
|
1998-10-02 04:10:00 +00:00
|
|
|
nsIHTMLReflow* htmlReflow;
|
1998-10-01 04:46:11 +00:00
|
|
|
|
|
|
|
if (NS_OK == childFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
|
|
|
htmlReflow->WillReflow(aPresContext);
|
1999-02-12 17:45:58 +00:00
|
|
|
htmlReflow->Reflow(aPresContext, desiredSize, reflowState, aStatus);
|
1998-10-01 04:46:11 +00:00
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "bad status");
|
|
|
|
nsRect rect(offset.x, offset.y, desiredSize.width, desiredSize.height);
|
|
|
|
childFrame->SetRect(rect);
|
|
|
|
maxSize.width -= desiredSize.width;
|
|
|
|
aDesiredSize.width += desiredSize.width;
|
|
|
|
aDesiredSize.height = desiredSize.height;
|
1999-02-10 06:13:38 +00:00
|
|
|
childFrame->GetNextSibling(&childFrame);
|
1998-10-01 04:46:11 +00:00
|
|
|
offset.x += desiredSize.width + CONTROL_SPACING;
|
|
|
|
}
|
1998-09-23 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
|
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
1998-12-17 18:55:42 +00:00
|
|
|
//XXX aDesiredSize.AddBorderPaddingToMaxElementSize(borderPadding);
|
1998-09-23 17:16:51 +00:00
|
|
|
aDesiredSize.maxElementSize->width = aDesiredSize.width;
|
|
|
|
aDesiredSize.maxElementSize->height = aDesiredSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 01:21:23 +00:00
|
|
|
result = formControl->GetHTMLAttribute(nsHTMLAtoms::name, value);
|
1998-09-23 17:16:51 +00:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
|
|
|
if (eHTMLUnit_String == value.GetUnit()) {
|
|
|
|
value.GetStringValue(*aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(formControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-02-11 01:13:28 +00:00
|
|
|
|
|
|
|
|
1998-09-23 17:16:51 +00: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-13 23:45:40 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mTextFrame->GetProperty(nsHTMLAtoms::value, aValues[0]))) {
|
1998-09-23 17:16:51 +00:00
|
|
|
aNumValues = 1;
|
|
|
|
status = PR_TRUE;
|
|
|
|
}
|
1999-05-13 23:45:40 +00:00
|
|
|
|
1998-09-23 17:16:51 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
1998-11-19 17:22:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("FileControl", aResult);
|
|
|
|
}
|
1999-01-22 15:32:57 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetFormContent(nsIContent*& aContent) const
|
|
|
|
{
|
1999-02-10 00:42:56 +00:00
|
|
|
nsIContent* content;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = GetContent(&content);
|
|
|
|
aContent = content;
|
|
|
|
return rv;
|
1999-01-22 15:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFileControlFrame::GetFont(nsIPresContext* aPresContext,
|
|
|
|
nsFont& aFont)
|
|
|
|
{
|
|
|
|
nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nscoord
|
|
|
|
nsFileControlFrame::GetVerticalInsidePadding(float aPixToTwip,
|
|
|
|
nscoord aInnerHeight) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsFileControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
|
|
|
|
float aPixToTwip,
|
|
|
|
nscoord aInnerWidth,
|
|
|
|
nscoord aCharWidth) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
1999-01-25 22:16:27 +00:00
|
|
|
|
1999-03-06 19:43:13 +00:00
|
|
|
nsresult nsFileControlFrame::RequiresWidget(PRBool& aRequiresWidget)
|
|
|
|
{
|
|
|
|
aRequiresWidget = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-11 01:13:28 +00:00
|
|
|
|
1999-01-25 22:16:27 +00:00
|
|
|
NS_IMETHODIMP nsFileControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
|
|
|
|
{
|
1999-02-11 01:13:28 +00:00
|
|
|
if (nsHTMLAtoms::value == aName) {
|
|
|
|
mTextFrame->SetTextControlFrameState(aValue);
|
|
|
|
}
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
1999-02-11 01:13:28 +00:00
|
|
|
}
|
1999-01-25 22:16:27 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsFileControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
|
|
|
|
{
|
1999-02-11 01:13:28 +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) {
|
|
|
|
mTextFrame->GetTextControlFrameState(aValue);
|
|
|
|
}
|
|
|
|
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
1999-02-18 00:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFileControlFrame::HasWidget()
|
|
|
|
{
|
|
|
|
PRBool hasWidget = PR_FALSE;
|
|
|
|
nsIWidget* widget;
|
|
|
|
mTextFrame->GetWidget(&widget);
|
|
|
|
if (widget) {
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
hasWidget = PR_TRUE;
|
|
|
|
}
|
|
|
|
return(hasWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-11 01:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsFileControlFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
1999-02-18 00:13:39 +00:00
|
|
|
#ifndef XP_MAC
|
|
|
|
// XXX: This is temporary until we can find out whats going wrong on the MAC
|
|
|
|
// where widget's are not being created in presentation shell 0.
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
// Since the file control has a mTextFrame which does not live in
|
|
|
|
// the content model it is necessary to get the current text value
|
|
|
|
// from the nsFileControlFrame through the content model, then
|
|
|
|
// explicitly ask the test frame to draw it. The mTextFrame's Paint
|
|
|
|
// method will still be called, but it will not render the current
|
|
|
|
// contents because it will not be possible for the content
|
|
|
|
// associated with the mTextFrame to get a handle to it frame in the
|
|
|
|
// presentation shell 0.
|
1999-02-18 00:13:39 +00:00
|
|
|
|
|
|
|
// Only paint if it doesn't have a widget.
|
|
|
|
if (HasWidget())
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-05-13 23:45:40 +00:00
|
|
|
|
1999-02-18 00:13:39 +00:00
|
|
|
nsAutoString browse("Browse...");
|
|
|
|
nsRect rect;
|
|
|
|
mBrowseFrame->GetRect(rect);
|
1999-02-12 17:45:58 +00:00
|
|
|
mBrowseFrame->PaintButton(aPresContext, aRenderingContext, aDirtyRect,
|
1999-02-18 22:07:23 +00:00
|
|
|
browse, rect);
|
1999-02-18 00:13:39 +00:00
|
|
|
|
1999-05-13 23:45:40 +00:00
|
|
|
|
1999-02-18 00:13:39 +00:00
|
|
|
mTextFrame->PaintTextControlBackground(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
|
1999-03-26 00:39:35 +00:00
|
|
|
if (NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsString text;
|
1999-02-18 00:13:39 +00:00
|
|
|
if (NS_SUCCEEDED(nsFormControlHelper::GetInputElementValue(mContent, &text, PR_FALSE))) {
|
|
|
|
nsRect rect;
|
|
|
|
mTextFrame->GetRect(rect);
|
|
|
|
mTextFrame->PaintTextControl(aPresContext, aRenderingContext, aDirtyRect, text, mStyleContext, rect);
|
1999-02-11 01:13:28 +00:00
|
|
|
}
|
1999-02-12 17:45:58 +00:00
|
|
|
}
|
1999-02-18 00:13:39 +00:00
|
|
|
#endif
|
1999-02-12 17:45:58 +00:00
|
|
|
return NS_OK;
|
1999-01-25 22:16:27 +00:00
|
|
|
}
|