2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-10-13 21:31:26 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-10-13 21:31:26 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-10-13 21:31:26 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-04-21 22:46:15 +00:00
|
|
|
|
|
|
|
#include "nsHTMLButtonControlFrame.h"
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-10-13 21:31:26 +00:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
1999-01-22 15:32:57 +00:00
|
|
|
#include "nsFormControlHelper.h"
|
1998-10-13 21:31:26 +00:00
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
|
|
|
|
#include "nsIRenderingContext.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1998-10-13 21:31:26 +00:00
|
|
|
#include "nsIPresShell.h"
|
2003-02-22 00:32:13 +00:00
|
|
|
#include "nsStyleContext.h"
|
1998-10-13 21:31:26 +00:00
|
|
|
#include "nsLeafFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
2002-11-17 15:37:56 +00:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
1998-10-13 21:31:26 +00:00
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIWidget.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsIComponentManager.h"
|
1999-01-22 23:10:02 +00:00
|
|
|
#include "nsIDocument.h"
|
1999-03-06 19:43:13 +00:00
|
|
|
#include "nsButtonFrameRenderer.h"
|
2000-01-08 15:53:48 +00:00
|
|
|
#include "nsFormControlFrame.h"
|
2004-02-23 21:29:06 +00:00
|
|
|
#include "nsFrameManager.h"
|
2000-12-30 19:22:22 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2002-06-04 00:44:04 +00:00
|
|
|
#include "nsReflowPath.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2002-06-26 01:53:11 +00:00
|
|
|
#include "nsIDOMHTMLButtonElement.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2004-01-28 00:18:22 +00:00
|
|
|
#include "nsStyleSet.h"
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-11 21:11:38 +00:00
|
|
|
#include "nsIAccessibilityService.h"
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
1998-10-13 21:31:26 +00:00
|
|
|
|
2005-11-01 20:40:54 +00:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewHTMLButtonControlFrame(nsIPresShell* aPresShell)
|
1998-10-13 21:31:26 +00:00
|
|
|
{
|
2005-11-01 20:40:54 +00:00
|
|
|
return new (aPresShell) nsHTMLButtonControlFrame;
|
1998-10-13 21:31:26 +00:00
|
|
|
}
|
|
|
|
|
1998-12-03 06:31:43 +00:00
|
|
|
nsHTMLButtonControlFrame::nsHTMLButtonControlFrame()
|
|
|
|
: nsHTMLContainerFrame()
|
1998-10-13 21:31:26 +00:00
|
|
|
{
|
2000-01-08 15:53:48 +00:00
|
|
|
mCacheSize.width = -1;
|
|
|
|
mCacheSize.height = -1;
|
2003-01-09 14:26:32 +00:00
|
|
|
mCachedMaxElementWidth = -1;
|
1999-03-06 19:43:13 +00:00
|
|
|
}
|
|
|
|
|
1999-11-04 23:16:47 +00:00
|
|
|
nsHTMLButtonControlFrame::~nsHTMLButtonControlFrame()
|
|
|
|
{
|
2000-05-16 12:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLButtonControlFrame::Destroy(nsPresContext *aPresContext)
|
2000-05-16 12:44:32 +00:00
|
|
|
{
|
|
|
|
nsFormControlFrame::RegUnRegAccessKey(aPresContext, NS_STATIC_CAST(nsIFrame*, this), PR_FALSE);
|
|
|
|
return nsHTMLContainerFrame::Destroy(aPresContext);
|
1999-11-04 23:16:47 +00:00
|
|
|
}
|
|
|
|
|
1999-03-06 19:43:13 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLButtonControlFrame::Init(nsPresContext* aPresContext,
|
1999-03-06 19:43:13 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* aContext,
|
1999-03-06 19:43:13 +00:00
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
mRenderer.SetFrame(this,aPresContext);
|
1999-11-12 01:45:53 +00:00
|
|
|
|
2005-11-22 23:39:48 +00:00
|
|
|
PRUint32 flags = NS_BLOCK_SPACE_MGR | NS_BLOCK_SHRINK_WRAP;
|
1999-12-04 23:49:50 +00:00
|
|
|
|
2004-01-28 00:18:22 +00:00
|
|
|
nsIPresShell *shell = aPresContext->PresShell();
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame* areaFrame = NS_NewAreaFrame(shell, flags);
|
1999-11-12 01:45:53 +00:00
|
|
|
mFrames.SetFrames(areaFrame);
|
|
|
|
|
|
|
|
// Resolve style and initialize the frame
|
2003-02-22 00:32:13 +00:00
|
|
|
nsRefPtr<nsStyleContext> styleContext;
|
2004-01-28 00:18:22 +00:00
|
|
|
styleContext = shell->StyleSet()->ResolvePseudoStyleFor(mContent,
|
|
|
|
nsCSSAnonBoxes::buttonContent,
|
|
|
|
mStyleContext);
|
1999-11-12 01:45:53 +00:00
|
|
|
mFrames.FirstChild()->Init(aPresContext, mContent, this, styleContext, nsnull);
|
|
|
|
|
1999-03-06 19:43:13 +00:00
|
|
|
return rv;
|
1998-10-13 21:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsHTMLButtonControlFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsHTMLButtonControlFrame::Release(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-11-02 01:50:15 +00:00
|
|
|
// Frames are not refcounted, no need to AddRef
|
|
|
|
NS_IMETHODIMP
|
1998-10-13 21:31:26 +00:00
|
|
|
nsHTMLButtonControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 != aInstancePtr, "null ptr");
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2001-01-04 20:44:42 +00:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
|
1998-10-13 21:31:26 +00:00
|
|
|
*aInstancePtr = (void*) ((nsIFormControlFrame*) this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-05-11 21:11:38 +00:00
|
|
|
|
1998-10-13 21:31:26 +00:00
|
|
|
return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
2001-08-17 03:13:07 +00:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-17 23:52:32 +00:00
|
|
|
NS_IMETHODIMP nsHTMLButtonControlFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
2003-07-04 12:50:32 +00:00
|
|
|
nsIContent* content = GetContent();
|
2002-06-26 01:53:11 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLButtonElement> buttonElement(do_QueryInterface(content));
|
|
|
|
if (buttonElement) //If turned XBL-base form control off, the frame contains HTML 4 button
|
|
|
|
return accService->CreateHTML4ButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(content));
|
|
|
|
if (inputElement) //If turned XBL-base form control on, the frame contains normal HTML button
|
|
|
|
return accService->CreateHTMLButtonAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
2001-05-17 23:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-08-17 03:13:07 +00:00
|
|
|
#endif
|
2001-05-17 23:52:32 +00:00
|
|
|
|
2003-11-18 02:12:24 +00:00
|
|
|
void
|
2004-02-23 21:29:06 +00:00
|
|
|
nsHTMLButtonControlFrame::ReParentFrameList(nsFrameManager* aFrameManager,
|
2003-11-18 02:12:24 +00:00
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
// get the new parent context from the first child: that is the
|
|
|
|
// frame that the subsequent children will be made children of
|
|
|
|
nsStyleContext* newParentContext = mFrames.FirstChild()->GetStyleContext();
|
|
|
|
|
|
|
|
// Set the parent for each of the child frames
|
|
|
|
for (nsIFrame* frame = aFrameList; frame; frame = frame->GetNextSibling()) {
|
|
|
|
frame->SetParent(mFrames.FirstChild());
|
|
|
|
// now reparent the contexts for the reparented frame too
|
|
|
|
aFrameManager->ReParentStyleContext(frame, newParentContext);
|
|
|
|
}
|
2005-01-03 07:27:11 +00:00
|
|
|
|
|
|
|
// Set NS_FRAME_HAS_CHILD_WITH_VIEW on the area frame if needed, bug 276236.
|
|
|
|
mFrames.FirstChild()->AddStateBits(GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW);
|
2003-11-18 02:12:24 +00:00
|
|
|
}
|
|
|
|
|
1999-09-13 20:40:59 +00:00
|
|
|
PRBool
|
|
|
|
nsHTMLButtonControlFrame::IsReset(PRInt32 type)
|
|
|
|
{
|
|
|
|
if (NS_FORM_BUTTON_RESET == type) {
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2001-09-19 13:00:23 +00:00
|
|
|
nsHTMLButtonControlFrame::IsSubmit(PRInt32 type)
|
1999-09-13 20:40:59 +00:00
|
|
|
{
|
2001-09-19 13:00:23 +00:00
|
|
|
if (NS_FORM_BUTTON_SUBMIT == type) {
|
1999-09-13 20:40:59 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-22 23:00:37 +00:00
|
|
|
void
|
|
|
|
nsHTMLButtonControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
1998-10-17 00:35:32 +00:00
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLButtonControlFrame::HandleEvent(nsPresContext* aPresContext,
|
1999-03-31 06:02:12 +00:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-10-13 21:31:26 +00:00
|
|
|
{
|
1999-03-06 19:43:13 +00:00
|
|
|
// if disabled do nothing
|
|
|
|
if (mRenderer.isDisabled()) {
|
1998-10-17 00:35:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-14 23:01:44 +00:00
|
|
|
|
2000-06-21 00:40:11 +00:00
|
|
|
// mouse clicks are handled by content
|
1999-05-13 01:35:16 +00:00
|
|
|
// we don't want our children to get any events. So just pass it to frame.
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1998-10-13 21:31:26 +00:00
|
|
|
}
|
|
|
|
|
1998-10-14 23:01:44 +00:00
|
|
|
|
2005-09-19 02:15:54 +00:00
|
|
|
nsIFrame*
|
2005-01-01 17:26:29 +00:00
|
|
|
nsHTMLButtonControlFrame::GetFrameForPoint(const nsPoint& aPoint,
|
2005-09-19 02:15:54 +00:00
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-11-18 05:25:26 +00:00
|
|
|
{
|
2005-09-19 02:15:54 +00:00
|
|
|
nsRect thisRect(nsPoint(0,0), GetSize());
|
2002-04-06 15:31:53 +00:00
|
|
|
if (aWhichLayer == NS_FRAME_PAINT_LAYER_FOREGROUND &&
|
2005-09-19 02:15:54 +00:00
|
|
|
thisRect.Contains(aPoint) && GetStyleVisibility()->IsVisible()) {
|
|
|
|
return this;
|
2000-03-22 02:43:08 +00:00
|
|
|
}
|
2005-09-19 02:15:54 +00:00
|
|
|
return nsnull;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
1998-10-13 21:31:26 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLButtonControlFrame::SetInitialChildList(nsPresContext* aPresContext,
|
1998-11-10 06:05:32 +00:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
1998-10-13 21:31:26 +00:00
|
|
|
{
|
2000-09-12 19:41:27 +00:00
|
|
|
// NOTE: the whole reparenting should not need to happen: see bugzilla bug 51767
|
2004-02-23 21:29:06 +00:00
|
|
|
ReParentFrameList(aPresContext->FrameManager(), aChildList);
|
2003-11-18 02:12:24 +00:00
|
|
|
|
2004-10-30 21:43:49 +00:00
|
|
|
return mFrames.FirstChild()->SetInitialChildList(aPresContext, aListName, aChildList);
|
1998-10-13 21:31:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLButtonControlFrame::Paint(nsPresContext* aPresContext,
|
1998-10-13 21:31:26 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-09-19 12:35:19 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
1998-10-13 21:31:26 +00:00
|
|
|
{
|
2001-01-27 14:09:34 +00:00
|
|
|
PRBool isVisible;
|
2002-04-06 15:31:53 +00:00
|
|
|
if (aWhichLayer != NS_FRAME_PAINT_LAYER_FOREGROUND ||
|
|
|
|
(NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext, PR_TRUE, &isVisible)) && !isVisible)) {
|
2001-01-27 14:09:34 +00:00
|
|
|
return NS_OK;
|
1999-04-25 20:07:45 +00:00
|
|
|
}
|
1999-03-06 19:43:13 +00:00
|
|
|
|
2001-01-27 14:09:34 +00:00
|
|
|
nsRect rect(0, 0, mRect.width, mRect.height);
|
2002-04-06 15:31:53 +00:00
|
|
|
mRenderer.PaintButton(aPresContext, aRenderingContext, aDirtyRect, rect);
|
2001-01-27 14:09:34 +00:00
|
|
|
|
1999-11-03 00:05:30 +00:00
|
|
|
#if 0 // old way
|
2002-04-06 15:31:53 +00:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, NS_FRAME_PAINT_LAYER_BACKGROUND);
|
2003-10-13 21:51:02 +00:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, NS_FRAME_PAINT_LAYER_FLOATS);
|
2002-04-06 15:31:53 +00:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, NS_FRAME_PAINT_LAYER_FOREGROUND);
|
1999-03-06 19:43:13 +00:00
|
|
|
|
1999-11-03 00:05:30 +00:00
|
|
|
#else // temporary
|
|
|
|
// XXX This is temporary
|
2005-11-20 22:05:24 +00:00
|
|
|
// clips to its size minus the border
|
1999-11-03 00:05:30 +00:00
|
|
|
// but the real problem is the FirstChild (the AreaFrame)
|
|
|
|
// isn't being constrained properly
|
|
|
|
// Bug #17474
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleBorder* borderStyle = GetStyleBorder();
|
1999-12-02 22:07:43 +00:00
|
|
|
nsMargin border;
|
|
|
|
border.SizeTo(0, 0, 0, 0);
|
2001-02-07 09:57:26 +00:00
|
|
|
borderStyle->CalcBorderFor(this, border);
|
1999-11-03 00:05:30 +00:00
|
|
|
|
1999-12-02 22:07:43 +00:00
|
|
|
rect.Deflate(border);
|
1999-11-03 00:05:30 +00:00
|
|
|
aRenderingContext.PushState();
|
|
|
|
|
2004-04-23 15:21:24 +00:00
|
|
|
aRenderingContext.SetClipRect(rect, nsClipCombine_kIntersect);
|
1999-11-03 00:05:30 +00:00
|
|
|
|
2002-04-06 15:31:53 +00:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, NS_FRAME_PAINT_LAYER_BACKGROUND);
|
2003-10-13 21:51:02 +00:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, NS_FRAME_PAINT_LAYER_FLOATS);
|
2002-04-06 15:31:53 +00:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, NS_FRAME_PAINT_LAYER_FOREGROUND);
|
1999-11-03 00:05:30 +00:00
|
|
|
|
2004-04-18 13:13:35 +00:00
|
|
|
aRenderingContext.PopState();
|
1999-11-03 00:05:30 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2004-11-11 15:07:22 +00:00
|
|
|
// Paint outline
|
|
|
|
const nsStyleOutline* outlineStyle = GetStyleOutline();
|
|
|
|
nsCSSRendering::PaintOutline(aPresContext, aRenderingContext, this,
|
|
|
|
aDirtyRect, rect, *borderStyle, *outlineStyle,
|
|
|
|
mStyleContext, 0);
|
|
|
|
|
2000-08-08 23:38:00 +00:00
|
|
|
// to draw border when selected in editor
|
|
|
|
return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1998-10-13 21:31:26 +00:00
|
|
|
}
|
|
|
|
|
1999-08-31 13:05:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLButtonControlFrame::AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aSuggestedReflowState)
|
|
|
|
{
|
|
|
|
aDesiredSize.width += aSuggestedReflowState.mComputedBorderPadding.left + aSuggestedReflowState.mComputedBorderPadding.right;
|
|
|
|
aDesiredSize.height += aSuggestedReflowState.mComputedBorderPadding.top + aSuggestedReflowState.mComputedBorderPadding.bottom;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-13 21:31:26 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLButtonControlFrame::Reflow(nsPresContext* aPresContext,
|
1998-10-13 21:31:26 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2000-04-21 21:51:35 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsHTMLButtonControlFrame", aReflowState.reason);
|
2001-11-14 13:40:03 +00:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2000-04-21 21:51:35 +00:00
|
|
|
|
2002-06-04 00:44:04 +00:00
|
|
|
if (eReflowReason_Initial == aReflowState.reason) {
|
2000-02-09 19:34:39 +00:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(aPresContext, NS_STATIC_CAST(nsIFrame*, this), PR_TRUE);
|
1999-09-13 20:40:59 +00:00
|
|
|
}
|
|
|
|
|
2000-02-09 19:34:39 +00:00
|
|
|
#if 0
|
2003-01-09 14:26:32 +00:00
|
|
|
nsresult skiprv = nsFormControlFrame::SkipResizeReflow(mCacheSize, mCachedMaxElementWidth, aPresContext,
|
2000-01-08 15:53:48 +00:00
|
|
|
aDesiredSize, aReflowState, aStatus);
|
|
|
|
if (NS_SUCCEEDED(skiprv)) {
|
|
|
|
return skiprv;
|
|
|
|
}
|
2000-02-09 19:34:39 +00:00
|
|
|
#endif
|
1999-03-06 19:43:13 +00:00
|
|
|
|
2003-02-22 19:48:29 +00:00
|
|
|
// Reflow the child
|
1999-01-15 22:52:05 +00:00
|
|
|
nsIFrame* firstKid = mFrames.FirstChild();
|
1999-07-23 00:11:21 +00:00
|
|
|
nsSize availSize(aReflowState.mComputedWidth, NS_INTRINSICSIZE);
|
1999-02-23 03:48:01 +00:00
|
|
|
|
2005-11-20 22:05:24 +00:00
|
|
|
// Indent the child inside us by the focus border. We must do this separate from the
|
1999-05-09 21:46:24 +00:00
|
|
|
// regular border.
|
|
|
|
nsMargin focusPadding = mRenderer.GetAddedButtonBorderAndPadding();
|
1999-02-23 03:48:01 +00:00
|
|
|
|
1999-07-23 00:11:21 +00:00
|
|
|
|
1999-02-23 03:48:01 +00:00
|
|
|
if (NS_INTRINSICSIZE != availSize.width) {
|
1999-05-09 21:46:24 +00:00
|
|
|
availSize.width -= focusPadding.left + focusPadding.right;
|
1999-02-23 03:48:01 +00:00
|
|
|
availSize.width = PR_MAX(availSize.width,0);
|
|
|
|
}
|
|
|
|
if (NS_AUTOHEIGHT != availSize.height) {
|
1999-05-09 21:46:24 +00:00
|
|
|
availSize.height -= focusPadding.top + focusPadding.bottom;
|
1999-02-23 03:48:01 +00:00
|
|
|
availSize.height = PR_MAX(availSize.height,0);
|
|
|
|
}
|
1999-07-23 00:11:21 +00:00
|
|
|
|
1999-01-22 23:10:02 +00:00
|
|
|
// XXX Proper handling of incremental reflow...
|
2002-05-10 18:22:41 +00:00
|
|
|
nsReflowReason reason = aReflowState.reason;
|
|
|
|
if (eReflowReason_Incremental == reason) {
|
1999-01-22 23:10:02 +00:00
|
|
|
// See if it's targeted at us
|
2002-05-10 18:22:41 +00:00
|
|
|
nsHTMLReflowCommand *command = aReflowState.path->mReflowCommand;
|
|
|
|
if (command) {
|
2004-03-10 03:09:05 +00:00
|
|
|
// I'm not sure what exactly this Invalidate is for
|
|
|
|
Invalidate(nsRect(0,0,mRect.width,mRect.height), PR_FALSE);
|
1999-07-23 00:11:21 +00:00
|
|
|
|
2001-12-17 22:39:59 +00:00
|
|
|
nsReflowType reflowType;
|
2002-05-10 18:22:41 +00:00
|
|
|
command->GetType(reflowType);
|
2001-12-17 22:39:59 +00:00
|
|
|
if (eReflowType_StyleChanged == reflowType) {
|
2002-05-10 18:22:41 +00:00
|
|
|
reason = eReflowReason_StyleChange;
|
1999-09-29 03:35:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-05-10 18:22:41 +00:00
|
|
|
reason = eReflowReason_Resize;
|
1999-09-29 03:35:51 +00:00
|
|
|
}
|
1999-01-22 23:10:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-22 19:48:29 +00:00
|
|
|
// Reflow the contents of the button a first time.
|
|
|
|
ReflowButtonContents(aPresContext, aDesiredSize, aReflowState, firstKid,
|
|
|
|
availSize, reason, focusPadding, aStatus);
|
2002-05-10 18:22:41 +00:00
|
|
|
|
2003-02-22 19:48:29 +00:00
|
|
|
// If we just performed the first pass of a shrink-wrap reflow (which will have
|
|
|
|
// found the requested size of the children, but not placed them), perform
|
|
|
|
// the second pass of a shrink-wrap reflow (which places the children
|
|
|
|
// within this parent button which has now shrink-wrapped around them).
|
|
|
|
if (availSize.width == NS_SHRINKWRAPWIDTH) {
|
|
|
|
nsSize newAvailSize(aDesiredSize.width, NS_INTRINSICSIZE);
|
2000-01-18 20:29:22 +00:00
|
|
|
|
2003-02-22 19:48:29 +00:00
|
|
|
ReflowButtonContents(aPresContext, aDesiredSize, aReflowState, firstKid,
|
|
|
|
newAvailSize, eReflowReason_Resize, focusPadding, aStatus);
|
2002-11-16 19:32:49 +00:00
|
|
|
}
|
1998-10-13 21:31:26 +00:00
|
|
|
|
2003-02-22 19:48:29 +00:00
|
|
|
// If computed use the computed values.
|
1999-11-03 00:05:30 +00:00
|
|
|
if (aReflowState.mComputedWidth != NS_INTRINSICSIZE)
|
|
|
|
aDesiredSize.width = aReflowState.mComputedWidth;
|
|
|
|
else
|
|
|
|
aDesiredSize.width += focusPadding.left + focusPadding.right;
|
|
|
|
|
|
|
|
if (aReflowState.mComputedHeight != NS_INTRINSICSIZE)
|
|
|
|
aDesiredSize.height = aReflowState.mComputedHeight;
|
|
|
|
else
|
|
|
|
aDesiredSize.height += focusPadding.top + focusPadding.bottom;
|
|
|
|
|
1999-08-31 13:05:31 +00:00
|
|
|
AddComputedBorderPaddingToDesiredSize(aDesiredSize, aReflowState);
|
2002-11-12 19:17:51 +00:00
|
|
|
|
1999-08-31 13:05:31 +00:00
|
|
|
//aDesiredSize.width += aReflowState.mComputedBorderPadding.left + aReflowState.mComputedBorderPadding.right;
|
|
|
|
//aDesiredSize.height += aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom;
|
1998-10-13 21:31:26 +00:00
|
|
|
|
2003-01-09 14:26:32 +00:00
|
|
|
if (aDesiredSize.mComputeMEW) {
|
2004-08-31 18:50:40 +00:00
|
|
|
aDesiredSize.SetMEWToActualWidth(aReflowState.mStylePosition->mWidth.GetUnit());
|
2000-04-30 13:27:49 +00:00
|
|
|
}
|
1999-07-23 00:11:21 +00:00
|
|
|
|
2000-12-20 15:12:06 +00:00
|
|
|
// Make sure we obey min/max-width and min/max-height
|
|
|
|
if (aDesiredSize.width > aReflowState.mComputedMaxWidth) {
|
|
|
|
aDesiredSize.width = aReflowState.mComputedMaxWidth;
|
|
|
|
}
|
|
|
|
if (aDesiredSize.width < aReflowState.mComputedMinWidth) {
|
|
|
|
aDesiredSize.width = aReflowState.mComputedMinWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDesiredSize.height > aReflowState.mComputedMaxHeight) {
|
|
|
|
aDesiredSize.height = aReflowState.mComputedMaxHeight;
|
|
|
|
}
|
|
|
|
if (aDesiredSize.height < aReflowState.mComputedMinHeight) {
|
|
|
|
aDesiredSize.height = aReflowState.mComputedMinHeight;
|
2002-11-12 19:17:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aDesiredSize.ascent += aReflowState.mComputedBorderPadding.top + focusPadding.top;
|
|
|
|
aDesiredSize.descent = aDesiredSize.height - aDesiredSize.ascent;
|
|
|
|
|
2005-03-31 02:19:48 +00:00
|
|
|
aDesiredSize.mOverflowArea = nsRect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
ConsiderChildOverflow(aDesiredSize.mOverflowArea, firstKid);
|
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
2004-11-11 15:07:22 +00:00
|
|
|
|
1998-10-13 21:31:26 +00:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2000-01-08 15:53:48 +00:00
|
|
|
|
2002-11-12 19:17:51 +00:00
|
|
|
nsFormControlFrame::SetupCachedSizes(mCacheSize, mCachedAscent,
|
2003-01-09 14:26:32 +00:00
|
|
|
mCachedMaxElementWidth, aDesiredSize);
|
2002-05-28 22:50:43 +00:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
1998-10-13 21:31:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-02-22 19:48:29 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext,
|
2003-02-22 19:48:29 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame* aFirstKid,
|
|
|
|
const nsSize& aAvailSize,
|
|
|
|
nsReflowReason aReason,
|
|
|
|
nsMargin aFocusPadding,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsHTMLReflowState reflowState(aPresContext, aReflowState, aFirstKid, aAvailSize, aReason);
|
|
|
|
|
|
|
|
ReflowChild(aFirstKid, aPresContext, aDesiredSize, reflowState,
|
|
|
|
aFocusPadding.left + aReflowState.mComputedBorderPadding.left,
|
|
|
|
aFocusPadding.top + aReflowState.mComputedBorderPadding.top,
|
|
|
|
0, aStatus);
|
|
|
|
|
|
|
|
// calculate the min internal size so the contents gets centered correctly
|
|
|
|
// minInternalWidth is not being used at all and causes a warning--commenting
|
|
|
|
// out until someone wants it.
|
|
|
|
// nscoord minInternalWidth = aReflowState.mComputedMinWidth == 0?0:aReflowState.mComputedMinWidth -
|
|
|
|
// (aReflowState.mComputedBorderPadding.left + aReflowState.mComputedBorderPadding.right);
|
|
|
|
nscoord minInternalHeight = aReflowState.mComputedMinHeight == 0?0:aReflowState.mComputedMinHeight -
|
|
|
|
(aReflowState.mComputedBorderPadding.top + aReflowState.mComputedBorderPadding.bottom);
|
|
|
|
|
|
|
|
// center child vertically
|
|
|
|
nscoord yoff = 0;
|
|
|
|
if (aReflowState.mComputedHeight != NS_INTRINSICSIZE) {
|
|
|
|
yoff = (aReflowState.mComputedHeight - aDesiredSize.height)/2;
|
|
|
|
if (yoff < 0) {
|
|
|
|
yoff = 0;
|
|
|
|
}
|
|
|
|
} else if (aDesiredSize.height < minInternalHeight) {
|
|
|
|
yoff = (minInternalHeight - aDesiredSize.height) / 2;
|
|
|
|
}
|
|
|
|
|
2004-01-20 23:57:40 +00:00
|
|
|
// Adjust the ascent by our offset (since we moved the child's
|
|
|
|
// baseline by that much).
|
|
|
|
aDesiredSize.ascent += yoff;
|
|
|
|
|
2003-02-22 19:48:29 +00:00
|
|
|
// Place the child. If we have a non-intrinsic width, we want to
|
|
|
|
// reduce the left padding as needed to try and fit the text in the
|
|
|
|
// button
|
|
|
|
nscoord xoffset = aFocusPadding.left + aReflowState.mComputedBorderPadding.left;
|
|
|
|
if (aReflowState.mComputedWidth != NS_INTRINSICSIZE) {
|
|
|
|
// First, how much did we "overflow"? This is the width of our
|
|
|
|
// kid plus our special focus stuff (which did not get accounted
|
|
|
|
// for in calculating aReflowState.mComputedWidth minus the width
|
|
|
|
// we're forced to be.
|
|
|
|
nscoord extrawidth =
|
|
|
|
aDesiredSize.width + aFocusPadding.left + aFocusPadding.right
|
|
|
|
- aReflowState.mComputedWidth;
|
|
|
|
if (extrawidth > 0) {
|
|
|
|
// Split it evenly between right and left
|
|
|
|
extrawidth /= 2;
|
|
|
|
// But do not shoot out the left side of the button, please
|
|
|
|
extrawidth = PR_MIN(extrawidth, aReflowState.mComputedPadding.left);
|
|
|
|
xoffset -= extrawidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place the child
|
|
|
|
FinishReflowChild(aFirstKid, aPresContext, &reflowState, aDesiredSize,
|
|
|
|
xoffset,
|
|
|
|
yoff + aFocusPadding.top + aReflowState.mComputedBorderPadding.top, 0);
|
|
|
|
}
|
|
|
|
|
2004-03-12 04:40:17 +00:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsHTMLButtonControlFrame::IsContainingBlock() const
|
2002-11-19 03:39:44 +00:00
|
|
|
{
|
2004-03-12 04:40:17 +00:00
|
|
|
return PR_TRUE;
|
2002-11-19 03:39:44 +00:00
|
|
|
}
|
|
|
|
|
1998-10-13 21:31:26 +00:00
|
|
|
PRIntn
|
|
|
|
nsHTMLButtonControlFrame::GetSkipSides() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-12 23:53:06 +00:00
|
|
|
nsresult nsHTMLButtonControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
1999-01-25 22:16:27 +00:00
|
|
|
{
|
2001-02-06 01:31:18 +00:00
|
|
|
if (nsHTMLAtoms::value == aName) {
|
2005-01-12 19:45:38 +00:00
|
|
|
return mContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::value,
|
|
|
|
aValue, PR_TRUE);
|
2001-02-06 01:31:18 +00:00
|
|
|
}
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-12 23:53:06 +00:00
|
|
|
nsresult nsHTMLButtonControlFrame::GetFormProperty(nsIAtom* aName, nsAString& aValue) const
|
1999-01-25 22:16:27 +00:00
|
|
|
{
|
2005-01-12 19:45:38 +00:00
|
|
|
if (nsHTMLAtoms::value == aName)
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::value, aValue);
|
|
|
|
|
1999-01-25 22:16:27 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext*
|
|
|
|
nsHTMLButtonControlFrame::GetAdditionalStyleContext(PRInt32 aIndex) const
|
1999-09-03 23:36:32 +00:00
|
|
|
{
|
2003-02-22 00:32:13 +00:00
|
|
|
return mRenderer.GetStyleContext(aIndex);
|
1999-09-03 23:36:32 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 00:32:13 +00:00
|
|
|
void
|
1999-09-03 23:36:32 +00:00
|
|
|
nsHTMLButtonControlFrame::SetAdditionalStyleContext(PRInt32 aIndex,
|
2003-02-22 00:32:13 +00:00
|
|
|
nsStyleContext* aStyleContext)
|
1999-09-03 23:36:32 +00:00
|
|
|
{
|
2003-02-22 00:32:13 +00:00
|
|
|
mRenderer.SetStyleContext(aIndex, aStyleContext);
|
1999-09-03 23:36:32 +00:00
|
|
|
}
|
|
|
|
|
2000-08-02 22:16:12 +00:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:58:25 +00:00
|
|
|
nsHTMLButtonControlFrame::AppendFrames(nsIAtom* aListName,
|
2000-08-02 22:16:12 +00:00
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
2005-02-07 01:58:25 +00:00
|
|
|
ReParentFrameList(GetPresContext()->FrameManager(), aFrameList);
|
|
|
|
return mFrames.FirstChild()->AppendFrames(aListName, aFrameList);
|
2003-11-18 02:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:58:25 +00:00
|
|
|
nsHTMLButtonControlFrame::InsertFrames(nsIAtom* aListName,
|
2003-11-18 02:12:24 +00:00
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
2005-02-07 01:58:25 +00:00
|
|
|
ReParentFrameList(GetPresContext()->FrameManager(), aFrameList);
|
|
|
|
return mFrames.FirstChild()->InsertFrames(aListName, aPrevFrame, aFrameList);
|
2003-11-18 02:12:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 01:58:25 +00:00
|
|
|
nsHTMLButtonControlFrame::RemoveFrame(nsIAtom* aListName,
|
2003-11-18 02:12:24 +00:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2005-02-07 01:58:25 +00:00
|
|
|
return mFrames.FirstChild()->RemoveFrame(aListName, aOldFrame);
|
2003-11-18 02:12:24 +00:00
|
|
|
}
|