1999-08-06 09:13:07 +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 "nsGfxButtonControlFrame.h"
|
|
|
|
#include "nsIButton.h"
|
1999-08-10 23:13:57 +04:00
|
|
|
#include "nsWidgetsCID.h"
|
1999-08-06 09:13:07 +04:00
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
|
1999-08-06 09:13:07 +04:00
|
|
|
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
|
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
const nscoord kSuggestedNotSet = -1;
|
|
|
|
|
|
|
|
nsGfxButtonControlFrame::nsGfxButtonControlFrame()
|
|
|
|
{
|
|
|
|
mRenderer.SetNameSpace(kNameSpaceID_None);
|
|
|
|
mSuggestedWidth = kSuggestedNotSet;
|
|
|
|
mSuggestedHeight = kSuggestedNotSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsGfxButtonControlFrame::IsSuccessful(nsIFormControlFrame* aSubmitter)
|
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if ((NS_FORM_INPUT_HIDDEN == type) || (this == aSubmitter)) {
|
1999-08-13 02:06:09 +04:00
|
|
|
// Can not use the nsHTMLButtonControlFrame::IsSuccessful because
|
|
|
|
// it will fail it's test of (this==aSubmitter)
|
|
|
|
nsAutoString name;
|
|
|
|
return (NS_CONTENT_ATTR_HAS_VALUE == GetName(&name));
|
1999-08-10 23:13:57 +04:00
|
|
|
} else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsGfxButtonControlFrame::GetMaxNumValues()
|
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
if ((NS_FORM_INPUT_SUBMIT == type) || (NS_FORM_INPUT_HIDDEN == type)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsGfxButtonControlFrame::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);
|
|
|
|
|
|
|
|
if (NS_FORM_INPUT_RESET == type) {
|
|
|
|
aNumValues = 0;
|
|
|
|
return PR_FALSE;
|
|
|
|
} else {
|
|
|
|
nsAutoString value;
|
|
|
|
GetValue(&value);
|
|
|
|
aValues[0] = value;
|
|
|
|
aNames[0] = name;
|
|
|
|
aNumValues = 1;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-06 09:13:07 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewGfxButtonControlFrame(nsIFrame** aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsGfxButtonControlFrame* it = new nsGfxButtonControlFrame;
|
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-10 23:13:57 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsGfxButtonControlFrame::MouseClicked(nsIPresContext* aPresContext)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
1999-08-10 23:13:57 +04:00
|
|
|
PRInt32 type;
|
|
|
|
GetType(&type);
|
|
|
|
|
|
|
|
if ((nsnull != mFormFrame) && !nsFormFrame::GetDisabled(this)) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
nsIContent *formContent = nsnull;
|
|
|
|
mFormFrame->GetContent(&formContent);
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case NS_FORM_INPUT_RESET:
|
|
|
|
event.message = NS_FORM_RESET;
|
|
|
|
if (nsnull != formContent) {
|
|
|
|
formContent->HandleDOMEvent(*aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
|
|
|
}
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
mFormFrame->OnReset();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_FORM_INPUT_SUBMIT:
|
|
|
|
event.message = NS_FORM_SUBMIT;
|
|
|
|
if (nsnull != formContent) {
|
|
|
|
formContent->HandleDOMEvent(*aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
|
|
|
}
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
mFormFrame->OnSubmit(aPresContext, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(formContent);
|
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
const nsIID&
|
|
|
|
nsGfxButtonControlFrame::GetIID()
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
1999-08-10 23:13:57 +04:00
|
|
|
static NS_DEFINE_IID(kButtonIID, NS_IBUTTON_IID);
|
|
|
|
return kButtonIID;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsIID&
|
|
|
|
nsGfxButtonControlFrame::GetCID()
|
|
|
|
{
|
|
|
|
static NS_DEFINE_IID(kButtonCID, NS_BUTTON_CID);
|
|
|
|
return kButtonCID;
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-10 23:13:57 +04:00
|
|
|
nsGfxButtonControlFrame::GetFrameName(nsString& aResult) const
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
1999-08-10 23:13:57 +04:00
|
|
|
return MakeFrameName("ButtonControl", aResult);
|
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxButtonControlFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
1999-08-10 23:13:57 +04:00
|
|
|
if (!mFormFrame && (eReflowReason_Initial == aReflowState.reason)) {
|
|
|
|
nsFormFrame::AddFormControlFrame(aPresContext, *this);
|
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
if ((kSuggestedNotSet != mSuggestedWidth) ||
|
|
|
|
(kSuggestedNotSet != mSuggestedHeight))
|
|
|
|
{
|
|
|
|
nsHTMLReflowState suggestedReflowState(aReflowState);
|
|
|
|
|
|
|
|
// Honor the suggested width and/or height.
|
|
|
|
if (kSuggestedNotSet != mSuggestedWidth) {
|
|
|
|
suggestedReflowState.mComputedWidth = mSuggestedWidth;
|
1999-08-19 18:00:09 +04:00
|
|
|
suggestedReflowState.mComputedWidth -= aReflowState.mComputedBorderPadding.left + aReflowState.mComputedBorderPadding.right;
|
1999-08-10 23:13:57 +04:00
|
|
|
}
|
1999-08-06 09:13:07 +04:00
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
if (kSuggestedNotSet != mSuggestedHeight) {
|
|
|
|
suggestedReflowState.mComputedHeight = mSuggestedHeight;
|
1999-08-19 18:00:09 +04:00
|
|
|
suggestedReflowState.mComputedHeight -= aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom;
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
return nsHTMLButtonControlFrame::Reflow(aPresContext, aDesiredSize, suggestedReflowState, aStatus);
|
1999-08-06 09:13:07 +04:00
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
} else {
|
|
|
|
// Normal reflow.
|
|
|
|
return nsHTMLButtonControlFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxButtonControlFrame::SetSuggestedSize(nscoord aWidth, nscoord aHeight)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
1999-08-10 23:13:57 +04:00
|
|
|
mSuggestedWidth = aWidth;
|
|
|
|
mSuggestedHeight = aHeight;
|
|
|
|
return NS_OK;
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGfxButtonControlFrame::HandleEvent(nsIPresContext& aPresContext,
|
1999-08-10 23:13:57 +04:00
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
nsEventStatus& aEventStatus)
|
1999-08-06 09:13:07 +04:00
|
|
|
{
|
1999-08-10 23:13:57 +04:00
|
|
|
// Override the HandleEvent to prevent the nsFrame::HandleEvent
|
|
|
|
// from being called. The nsFrame::HandleEvent causes the button label
|
|
|
|
// to be selected (Drawn with an XOR rectangle over the label)
|
|
|
|
|
1999-08-06 09:13:07 +04:00
|
|
|
// if disabled do nothing
|
|
|
|
if (mRenderer.isDisabled()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-10 23:13:57 +04:00
|
|
|
// lets see if the button was clicked
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_CLICK:
|
|
|
|
MouseClicked(&aPresContext);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
1999-08-06 09:13:07 +04:00
|
|
|
}
|
1999-08-10 23:13:57 +04:00
|
|
|
|
|
|
|
|