1998-10-14 01:31:26 +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.
|
|
|
|
*/
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-10-14 01:31:26 +04:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1999-01-22 18:32:57 +03:00
|
|
|
#include "nsFormControlHelper.h"
|
1998-10-14 01:31:26 +04:00
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsFormFrame.h"
|
|
|
|
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsLeafFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsHTMLImage.h"
|
|
|
|
#include "nsStyleUtil.h"
|
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIHTMLAttributes.h"
|
|
|
|
#include "nsGenericHTMLElement.h"
|
|
|
|
#include "nsIWidget.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1998-10-14 01:31:26 +04:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsViewsCID.h"
|
1998-10-17 04:35:32 +04:00
|
|
|
#include "nsColor.h"
|
1999-01-23 02:10:02 +03:00
|
|
|
#include "nsIDocument.h"
|
1999-03-06 22:43:13 +03:00
|
|
|
#include "nsButtonFrameRenderer.h"
|
1998-10-14 01:31:26 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
|
|
|
|
static NS_DEFINE_IID(kIFormControlFrameIID, NS_IFORMCONTROLFRAME_IID);
|
|
|
|
static NS_DEFINE_IID(kViewCID, NS_VIEW_CID);
|
|
|
|
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
|
|
|
|
|
|
|
|
class nsHTMLButtonControlFrame : public nsHTMLContainerFrame,
|
|
|
|
public nsIFormControlFrame
|
|
|
|
{
|
|
|
|
public:
|
1998-12-03 09:31:43 +03:00
|
|
|
nsHTMLButtonControlFrame();
|
1998-10-14 01:31:26 +04:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
|
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
|
|
|
|
|
|
|
NS_IMETHOD Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 18:54:23 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer);
|
1998-10-14 01:31:26 +04:00
|
|
|
|
|
|
|
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
|
|
|
NS_IMETHOD HandleEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus);
|
|
|
|
|
1998-11-18 08:25:26 +03:00
|
|
|
NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame);
|
|
|
|
|
1998-11-10 09:05:32 +03:00
|
|
|
NS_IMETHOD SetInitialChildList(nsIPresContext& aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList);
|
1998-10-14 01:31:26 +04:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
NS_IMETHOD Init(nsIPresContext& aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* asPrevInFlow);
|
|
|
|
|
|
|
|
NS_IMETHOD ReResolveStyleContext ( nsIPresContext* aPresContext,
|
|
|
|
nsIStyleContext* aParentContext) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHOD GetFrameName(nsString& aResult) const {
|
|
|
|
return MakeFrameName("ButtonControl", aResult);
|
|
|
|
}
|
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
virtual nsresult RequiresWidget(PRBool &aRequiresWidget);
|
|
|
|
|
|
|
|
|
1998-10-30 21:05:29 +03:00
|
|
|
virtual PRBool IsSuccessful(nsIFormControlFrame* aSubmitter);
|
1998-10-14 01:31:26 +04:00
|
|
|
NS_IMETHOD GetType(PRInt32* aType) const;
|
|
|
|
NS_IMETHOD GetName(nsString* aName);
|
|
|
|
NS_IMETHOD GetValue(nsString* aName);
|
|
|
|
virtual PRInt32 GetMaxNumValues();
|
|
|
|
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
|
|
|
|
nsString* aValues, nsString* aNames);
|
|
|
|
virtual void MouseClicked(nsIPresContext* aPresContext);
|
|
|
|
virtual void Reset() {};
|
|
|
|
virtual void SetFormFrame(nsFormFrame* aFormFrame) { mFormFrame = aFormFrame; }
|
|
|
|
|
1998-10-23 03:00:37 +04:00
|
|
|
void SetFocus(PRBool aOn, PRBool aRepaint);
|
|
|
|
|
1999-01-22 18:32:57 +03:00
|
|
|
NS_IMETHOD GetFont(nsIPresContext* aPresContext,
|
|
|
|
nsFont& aFont);
|
|
|
|
|
|
|
|
NS_IMETHOD GetFormContent(nsIContent*& aContent) const;
|
|
|
|
virtual nscoord GetVerticalInsidePadding(float aPixToTwip,
|
|
|
|
nscoord aInnerHeight) const;
|
|
|
|
virtual nscoord GetHorizontalInsidePadding(nsIPresContext& aPresContext,
|
|
|
|
float aPixToTwip,
|
|
|
|
nscoord aInnerWidth,
|
|
|
|
nscoord aCharWidth) const;
|
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
void GetDefaultLabel(nsString& aLabel);
|
|
|
|
|
1999-01-26 01:16:27 +03:00
|
|
|
// nsIFormControlFrame
|
|
|
|
NS_IMETHOD SetProperty(nsIAtom* aName, const nsString& aValue);
|
|
|
|
NS_IMETHOD GetProperty(nsIAtom* aName, nsString& aValue);
|
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
protected:
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
1998-10-17 04:35:32 +04:00
|
|
|
void GetTranslatedRect(nsRect& aRect);
|
1998-10-14 01:31:26 +04:00
|
|
|
|
|
|
|
PRIntn GetSkipSides() const;
|
|
|
|
PRBool mInline;
|
|
|
|
nsFormFrame* mFormFrame;
|
1998-10-15 03:01:44 +04:00
|
|
|
nsCursor mPreviousCursor;
|
1998-10-17 04:35:32 +04:00
|
|
|
nsRect mTranslatedRect;
|
1998-11-14 02:13:42 +03:00
|
|
|
PRBool mDidInit;
|
1999-03-06 22:43:13 +03:00
|
|
|
nsButtonFrameRenderer mRenderer;
|
1998-10-14 01:31:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
1998-12-03 09:31:43 +03:00
|
|
|
NS_NewHTMLButtonControlFrame(nsIFrame*& aResult)
|
1998-10-14 01:31:26 +04:00
|
|
|
{
|
1998-12-03 09:31:43 +03:00
|
|
|
aResult = new nsHTMLButtonControlFrame;
|
1998-10-14 01:31:26 +04:00
|
|
|
if (nsnull == aResult) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
nsHTMLButtonControlFrame::nsHTMLButtonControlFrame()
|
|
|
|
: nsHTMLContainerFrame()
|
1998-10-14 01:31:26 +04:00
|
|
|
{
|
|
|
|
mInline = PR_TRUE;
|
1998-10-15 03:01:44 +04:00
|
|
|
mPreviousCursor = eCursor_standard;
|
1998-10-17 04:35:32 +04:00
|
|
|
mTranslatedRect = nsRect(0,0,0,0);
|
1998-11-14 02:13:42 +03:00
|
|
|
mDidInit = PR_FALSE;
|
1999-03-06 22:43:13 +03:00
|
|
|
mRenderer.SetNameSpace(kNameSpaceID_None);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::Init(nsIPresContext& aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
mRenderer.SetFrame(this,aPresContext);
|
|
|
|
return rv;
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsHTMLButtonControlFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsHTMLButtonControlFrame::Release(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLButtonControlFrame::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLButtonControlFrame::GetDefaultLabel(nsString& aString)
|
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if (NS_FORM_BUTTON_BUTTON == type) {
|
|
|
|
aString = "Button";
|
|
|
|
}
|
|
|
|
else if (NS_FORM_BUTTON_RESET == type) {
|
|
|
|
aString = "Reset";
|
|
|
|
}
|
|
|
|
else if (NS_FORM_BUTTON_SUBMIT == type) {
|
|
|
|
aString = "Submit";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsHTMLButtonControlFrame::GetMaxNumValues()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsHTMLButtonControlFrame::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;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
nsAutoString value;
|
|
|
|
nsresult valResult = GetValue(&value);
|
|
|
|
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == valResult) {
|
|
|
|
aValues[0] = value;
|
|
|
|
aNames[0] = name;
|
|
|
|
aNumValues = 1;
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
aNumValues = 0;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::GetType(PRInt32* aType) const
|
|
|
|
{
|
|
|
|
nsresult result = NS_FORM_NOTOK;
|
|
|
|
if (mContent) {
|
|
|
|
nsIFormControl* formControl = nsnull;
|
|
|
|
result = mContent->QueryInterface(kIFormControlIID, (void**)&formControl);
|
|
|
|
if ((NS_OK == result) && formControl) {
|
|
|
|
result = formControl->GetType(aType);
|
|
|
|
NS_RELEASE(formControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::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-10-14 01:31:26 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
|
|
|
if (eHTMLUnit_String == value.GetUnit()) {
|
|
|
|
value.GetStringValue(*aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(formControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::GetValue(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::value, value);
|
1998-10-14 01:31:26 +04:00
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
|
|
|
|
if (eHTMLUnit_String == value.GetUnit()) {
|
|
|
|
value.GetStringValue(*aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(formControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
1998-10-30 21:05:29 +03:00
|
|
|
nsHTMLButtonControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
|
1998-10-14 01:31:26 +04:00
|
|
|
{
|
1998-10-30 21:05:29 +03:00
|
|
|
if (this == (aSubmitter)) {
|
|
|
|
nsAutoString name;
|
|
|
|
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
|
|
|
|
} else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLButtonControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if (nsnull != mFormFrame) {
|
|
|
|
if (NS_FORM_BUTTON_RESET == type) {
|
|
|
|
//Send DOM event
|
|
|
|
nsEventStatus mStatus;
|
|
|
|
nsEvent mEvent;
|
|
|
|
mEvent.eventStructType = NS_EVENT;
|
|
|
|
mEvent.message = NS_FORM_RESET;
|
|
|
|
mContent->HandleDOMEvent(*aPresContext, &mEvent, nsnull, DOM_EVENT_INIT, mStatus);
|
|
|
|
|
|
|
|
mFormFrame->OnReset();
|
1998-10-17 04:35:32 +04:00
|
|
|
} else if (NS_FORM_BUTTON_SUBMIT == type) {
|
1998-10-14 01:31:26 +04:00
|
|
|
//Send DOM event
|
|
|
|
nsEventStatus mStatus;
|
|
|
|
nsEvent mEvent;
|
|
|
|
mEvent.eventStructType = NS_EVENT;
|
|
|
|
mEvent.message = NS_FORM_SUBMIT;
|
|
|
|
mContent->HandleDOMEvent(*aPresContext, &mEvent, nsnull, DOM_EVENT_INIT, mStatus);
|
|
|
|
|
|
|
|
mFormFrame->OnSubmit(aPresContext, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-23 03:00:37 +04:00
|
|
|
void
|
|
|
|
nsHTMLButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
1999-03-06 22:43:13 +03:00
|
|
|
mRenderer.SetFocus(aOn, aRepaint);
|
1998-10-17 04:35:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLButtonControlFrame::GetTranslatedRect(nsRect& aRect)
|
|
|
|
{
|
|
|
|
nsIView* view;
|
|
|
|
nsPoint viewOffset(0,0);
|
1999-02-10 08:38:18 +03:00
|
|
|
GetOffsetFromView(viewOffset, &view);
|
1998-10-17 04:35:32 +04:00
|
|
|
while (nsnull != view) {
|
|
|
|
nsPoint tempOffset;
|
|
|
|
view->GetPosition(&tempOffset.x, &tempOffset.y);
|
|
|
|
viewOffset += tempOffset;
|
|
|
|
view->GetParent(view);
|
|
|
|
}
|
|
|
|
aRect = nsRect(viewOffset.x, viewOffset.y, mRect.width, mRect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
|
1998-11-18 08:25:26 +03:00
|
|
|
NS_IMETHODIMP
|
1998-10-14 01:31:26 +04:00
|
|
|
nsHTMLButtonControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
|
|
|
{
|
1999-03-06 22:43:13 +03:00
|
|
|
nsWidgetRendering mode;
|
|
|
|
aPresContext.GetWidgetRenderingMode(&mode);
|
|
|
|
|
|
|
|
// if disabled do nothing
|
|
|
|
if (mRenderer.isDisabled()) {
|
1998-10-17 04:35:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-15 03:01:44 +04:00
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
nsresult result = mRenderer.HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
if (NS_OK != result)
|
|
|
|
return result;
|
|
|
|
|
1998-10-15 03:01:44 +04:00
|
|
|
aEventStatus = nsEventStatus_eIgnore;
|
1999-03-06 22:43:13 +03:00
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
|
|
|
|
case NS_MOUSE_ENTER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
|
|
|
mRenderer.SetFocus(PR_TRUE, PR_TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
if (mRenderer.isHover())
|
|
|
|
MouseClicked(&aPresContext);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_EXIT:
|
|
|
|
break;
|
1998-10-15 03:01:44 +04:00
|
|
|
}
|
1999-03-06 22:43:13 +03:00
|
|
|
|
1998-11-18 08:25:26 +03:00
|
|
|
return NS_OK;
|
1999-03-06 22:43:13 +03:00
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
1998-10-15 03:01:44 +04:00
|
|
|
|
1998-11-18 08:25:26 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
|
|
|
|
{
|
|
|
|
*aFrame = this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
NS_IMETHODIMP
|
1998-11-10 09:05:32 +03:00
|
|
|
nsHTMLButtonControlFrame::SetInitialChildList(nsIPresContext& aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
1998-10-14 01:31:26 +04:00
|
|
|
{
|
1998-10-30 21:05:29 +03:00
|
|
|
// add ourself as an nsIFormControlFrame
|
|
|
|
nsFormFrame::AddFormControlFrame(aPresContext, *this);
|
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
// cache our display type
|
|
|
|
const nsStyleDisplay* styleDisplay;
|
|
|
|
GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&) styleDisplay);
|
|
|
|
mInline = (NS_STYLE_DISPLAY_BLOCK != styleDisplay->mDisplay);
|
|
|
|
|
1999-01-12 19:42:03 +03:00
|
|
|
PRUint8 flags = (mInline) ? NS_BLOCK_SHRINK_WRAP : 0;
|
1999-01-16 01:52:05 +03:00
|
|
|
nsIFrame* areaFrame;
|
|
|
|
NS_NewAreaFrame(areaFrame, flags);
|
|
|
|
mFrames.SetFrames(areaFrame);
|
1998-10-14 01:31:26 +04:00
|
|
|
|
1998-12-03 09:31:43 +03:00
|
|
|
// Resolve style and initialize the frame
|
1999-02-11 18:56:23 +03:00
|
|
|
nsIStyleContext* styleContext;
|
|
|
|
aPresContext.ResolvePseudoStyleContextFor(mContent, nsHTMLAtoms::buttonContentPseudo,
|
1999-02-12 20:45:58 +03:00
|
|
|
mStyleContext, PR_FALSE,
|
|
|
|
&styleContext);
|
1999-02-25 06:27:57 +03:00
|
|
|
mFrames.FirstChild()->Init(aPresContext, mContent, this, styleContext, nsnull);
|
1998-10-14 01:31:26 +04:00
|
|
|
NS_RELEASE(styleContext);
|
|
|
|
|
1999-01-14 08:16:23 +03:00
|
|
|
// Set the parent for each of the child frames
|
1999-02-10 09:13:38 +03:00
|
|
|
for (nsIFrame* frame = aChildList; nsnull != frame; frame->GetNextSibling(&frame)) {
|
1999-01-16 01:52:05 +03:00
|
|
|
frame->SetParent(mFrames.FirstChild());
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Queue up the frames for the inline frame
|
1999-01-16 01:52:05 +03:00
|
|
|
return mFrames.FirstChild()->SetInitialChildList(aPresContext, nsnull, aChildList);
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 18:54:23 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-10-14 01:31:26 +04:00
|
|
|
{
|
1999-03-06 22:43:13 +03:00
|
|
|
|
|
|
|
nsRect rect(0, 0, mRect.width, mRect.height);
|
|
|
|
mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, rect);
|
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
|
|
|
|
return NS_OK;
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
|
|
|
|
1999-02-23 06:48:01 +03:00
|
|
|
// XXX a hack until the reflow state does this correctly
|
|
|
|
// XXX when it gets fixed, leave in the printf statements or add an assertion
|
1999-03-02 18:15:46 +03:00
|
|
|
static
|
1999-02-23 06:48:01 +03:00
|
|
|
void ButtonHack(nsHTMLReflowState& aReflowState, char* aMessage)
|
|
|
|
{
|
|
|
|
if (aReflowState.computedWidth == 0) {
|
|
|
|
aReflowState.computedWidth = aReflowState.availableWidth;
|
|
|
|
}
|
|
|
|
if ((aReflowState.computedWidth != NS_INTRINSICSIZE) &&
|
|
|
|
(aReflowState.computedWidth > aReflowState.availableWidth) &&
|
|
|
|
(aReflowState.availableWidth > 0)) {
|
|
|
|
// printf("BUG - %s has a computed width = %d, available width = %d \n",
|
|
|
|
// aMessage, aReflowState.computedWidth, aReflowState.availableWidth);
|
|
|
|
aReflowState.computedWidth = aReflowState.availableWidth;
|
|
|
|
}
|
|
|
|
if (aReflowState.computedHeight == 0) {
|
|
|
|
aReflowState.computedHeight = aReflowState.availableHeight;
|
|
|
|
}
|
|
|
|
if ((aReflowState.computedHeight != NS_INTRINSICSIZE) &&
|
|
|
|
(aReflowState.computedHeight > aReflowState.availableHeight) &&
|
|
|
|
(aReflowState.availableHeight > 0)) {
|
|
|
|
// printf("BUG - %s has a computed height = %d, available height = %d \n",
|
|
|
|
// aMessage, aReflowState.computedHeight, aReflowState.availableHeight);
|
|
|
|
aReflowState.computedHeight = aReflowState.availableHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
1999-02-23 06:48:01 +03:00
|
|
|
// XXX remove the following when the reflow state is fixed
|
|
|
|
ButtonHack((nsHTMLReflowState&)aReflowState, "html4 button");
|
1999-03-06 22:43:13 +03:00
|
|
|
|
|
|
|
// commenting this out for now. We need a view to do mouse grabbing but
|
|
|
|
// it doesn't really seem to work correctly. When you press the only event
|
|
|
|
// you can get after that is a release. You need mouse enter and exit.
|
|
|
|
// the view also breaks the outline code. For some reason you can not reset
|
|
|
|
// the clip rect to draw outside you bounds if you have a view. And you need to
|
|
|
|
// because the outline must be drawn outside of our bounds according to CSS. -EDV
|
|
|
|
#if 0
|
1998-11-14 02:13:42 +03:00
|
|
|
if (!mDidInit) {
|
|
|
|
// create our view, we need a view to grab the mouse
|
|
|
|
nsIView* view;
|
1999-02-10 08:38:18 +03:00
|
|
|
GetView(&view);
|
1998-11-14 02:13:42 +03:00
|
|
|
if (!view) {
|
1999-03-09 12:44:27 +03:00
|
|
|
nsresult result = nsComponentManager::CreateInstance(kViewCID, nsnull, kIViewIID, (void **)&view);
|
1999-02-12 20:45:58 +03:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext.GetShell(getter_AddRefs(presShell));
|
|
|
|
nsCOMPtr<nsIViewManager> viewMan;
|
|
|
|
presShell->GetViewManager(getter_AddRefs(viewMan));
|
1998-11-14 02:13:42 +03:00
|
|
|
|
|
|
|
nsIFrame* parWithView;
|
|
|
|
nsIView *parView;
|
1999-02-10 08:38:18 +03:00
|
|
|
GetParentWithView(&parWithView);
|
|
|
|
parWithView->GetView(&parView);
|
1998-11-14 02:13:42 +03:00
|
|
|
// the view's size is not know yet, but its size will be kept in synch with our frame.
|
|
|
|
nsRect boundBox(0, 0, 500, 500);
|
|
|
|
result = view->Init(viewMan, boundBox, parView, nsnull);
|
|
|
|
viewMan->InsertChild(parView, view, 0);
|
|
|
|
SetView(view);
|
|
|
|
|
|
|
|
const nsStyleColor* color = (const nsStyleColor*) mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
// set the opacity
|
|
|
|
viewMan->SetViewOpacity(view, color->mOpacity);
|
|
|
|
|
|
|
|
}
|
|
|
|
mDidInit = PR_TRUE;
|
|
|
|
}
|
1999-03-06 22:43:13 +03:00
|
|
|
#endif
|
1998-11-14 02:13:42 +03:00
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
// reflow the child
|
1999-01-16 01:52:05 +03:00
|
|
|
nsIFrame* firstKid = mFrames.FirstChild();
|
1999-02-23 06:48:01 +03:00
|
|
|
nsSize availSize(aReflowState.computedWidth, aReflowState.computedHeight);
|
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
nsMargin borderPadding = mRenderer.GetFullButtonBorderAndPadding();
|
1999-02-23 06:48:01 +03:00
|
|
|
|
|
|
|
if (NS_INTRINSICSIZE != availSize.width) {
|
|
|
|
availSize.width -= borderPadding.left + borderPadding.right;
|
|
|
|
availSize.width = PR_MAX(availSize.width,0);
|
|
|
|
}
|
|
|
|
if (NS_AUTOHEIGHT != availSize.height) {
|
|
|
|
availSize.height -= borderPadding.top + borderPadding.bottom;
|
|
|
|
availSize.height = PR_MAX(availSize.height,0);
|
|
|
|
}
|
|
|
|
|
1999-03-05 07:19:09 +03:00
|
|
|
nsHTMLReflowState reflowState(aPresContext, aReflowState, firstKid, availSize);
|
1999-02-23 06:48:01 +03:00
|
|
|
// XXX remove the following when the reflow state is fixed
|
|
|
|
ButtonHack(reflowState, "html4 button's area");
|
1999-01-23 02:10:02 +03:00
|
|
|
|
|
|
|
// XXX Proper handling of incremental reflow...
|
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
|
|
|
nsIFrame* targetFrame;
|
|
|
|
|
|
|
|
// See if it's targeted at us
|
|
|
|
aReflowState.reflowCommand->GetTarget(targetFrame);
|
|
|
|
if (this == targetFrame) {
|
|
|
|
// XXX Handle this...
|
|
|
|
reflowState.reason = eReflowReason_Resize;
|
|
|
|
} else {
|
|
|
|
nsIFrame* nextFrame;
|
|
|
|
|
|
|
|
// Remove the next frame from the reflow path
|
|
|
|
aReflowState.reflowCommand->GetNext(nextFrame);
|
|
|
|
NS_ASSERTION(nextFrame == firstKid, "unexpected next frame");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-16 01:52:05 +03:00
|
|
|
ReflowChild(firstKid, aPresContext, aDesiredSize, reflowState, aStatus);
|
1998-10-14 01:31:26 +04:00
|
|
|
|
|
|
|
// Place the child
|
|
|
|
nsRect rect = nsRect(borderPadding.left, borderPadding.top, aDesiredSize.width, aDesiredSize.height);
|
1999-01-16 01:52:05 +03:00
|
|
|
firstKid->SetRect(rect);
|
1998-10-14 01:31:26 +04:00
|
|
|
|
|
|
|
// add in our border and padding to the size of the child
|
|
|
|
aDesiredSize.width += borderPadding.left + borderPadding.right;
|
|
|
|
aDesiredSize.height += borderPadding.top + borderPadding.bottom;
|
|
|
|
|
1999-02-23 06:48:01 +03:00
|
|
|
//adjust our max element size, if necessary
|
1998-10-14 01:31:26 +04:00
|
|
|
if (aDesiredSize.maxElementSize) {
|
1998-12-17 21:55:42 +03:00
|
|
|
aDesiredSize.AddBorderPaddingToMaxElementSize(borderPadding);
|
1998-10-14 01:31:26 +04:00
|
|
|
}
|
1998-10-20 03:02:41 +04:00
|
|
|
|
|
|
|
// if we are constrained and the child is smaller, use the constrained values
|
1999-02-23 06:48:01 +03:00
|
|
|
//if (aReflowState.HaveFixedContentWidth() && (aDesiredSize.width < aReflowState.computedWidth)) {
|
|
|
|
// aDesiredSize.width = aReflowState.computedWidth;
|
|
|
|
//}
|
|
|
|
//if (aReflowState.HaveFixedContentHeight() && (aDesiredSize.height < aReflowState.computedHeight)) {
|
|
|
|
// aDesiredSize.height = aReflowState.computedHeight;
|
|
|
|
//}
|
1998-10-20 03:02:41 +04:00
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRIntn
|
|
|
|
nsHTMLButtonControlFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-01-22 18:32:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::GetFont(nsIPresContext* aPresContext,
|
|
|
|
nsFont& aFont)
|
|
|
|
{
|
|
|
|
nsFormControlHelper::GetFont(this, aPresContext, mStyleContext, aFont);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::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
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsHTMLButtonControlFrame::GetVerticalInsidePadding(float aPixToTwip,
|
|
|
|
nscoord aInnerHeight) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsHTMLButtonControlFrame::GetHorizontalInsidePadding(nsIPresContext& aPresContext,
|
|
|
|
float aPixToTwip,
|
|
|
|
nscoord aInnerWidth,
|
|
|
|
nscoord aCharWidth) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
nsresult nsHTMLButtonControlFrame::RequiresWidget(PRBool& aRequiresWidget)
|
|
|
|
{
|
|
|
|
aRequiresWidget = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-26 01:16:27 +03:00
|
|
|
NS_IMETHODIMP nsHTMLButtonControlFrame::SetProperty(nsIAtom* aName, const nsString& aValue)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsHTMLButtonControlFrame::GetProperty(nsIAtom* aName, nsString& aValue)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-06 22:43:13 +03:00
|
|
|
//
|
|
|
|
// ReResolveStyleContext
|
|
|
|
//
|
|
|
|
// When the style context changes, make sure that all of our styles are still up to date.
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::ReResolveStyleContext ( nsIPresContext* aPresContext, nsIStyleContext* aParentContext)
|
|
|
|
{
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStyleContext> old ( dont_QueryInterface(mStyleContext) );
|
|
|
|
|
|
|
|
// this re-resolves |mStyleContext|, so it may change
|
|
|
|
nsresult rv = nsHTMLContainerFrame::ReResolveStyleContext(aPresContext, aParentContext);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mRenderer.ReResolveStyles(*aPresContext);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
} // ReResolveStyleContext
|
|
|
|
|
|
|
|
|
1999-01-26 01:16:27 +03:00
|
|
|
|
1998-10-14 01:31:26 +04:00
|
|
|
|