2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-11-10 02:30:16 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04: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-11-10 02:30:16 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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-11-10 02:30:16 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04: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-29 00:14:13 +04: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 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04: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 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1999-04-14 01:51:43 +04:00
|
|
|
#include "nsImageFrame.h"
|
1998-11-10 02:30:16 +03:00
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-11-10 02:30:16 +03:00
|
|
|
#include "nsIPresShell.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-11-10 02:30:16 +03:00
|
|
|
#include "nsLeafFrame.h"
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsISupports.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-11-10 02:30:16 +03:00
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsIImage.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2000-02-09 22:34:39 +03:00
|
|
|
#include "nsFormControlFrame.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsGUIEvent.h"
|
2002-06-04 04:44:04 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2002-09-30 15:56:37 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2005-08-23 07:57:07 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-12 01:11:38 +04:00
|
|
|
#include "nsIAccessibilityService.h"
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2007-02-18 19:49:54 +03:00
|
|
|
void
|
|
|
|
IntPointDtorFunc(void *aObject, nsIAtom *aPropertyName,
|
|
|
|
void *aPropertyValue, void *aData)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
nsIntPoint *propertyValue = static_cast<nsIntPoint*>(aPropertyValue);
|
2007-02-18 19:49:54 +03:00
|
|
|
delete propertyValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-11-20 20:22:08 +03:00
|
|
|
#define nsImageControlFrameSuper nsImageFrame
|
|
|
|
class nsImageControlFrame : public nsImageControlFrameSuper,
|
2007-02-18 19:49:54 +03:00
|
|
|
public nsIFormControlFrame
|
1998-11-10 02:30:16 +03:00
|
|
|
{
|
|
|
|
public:
|
2006-03-27 01:30:36 +04:00
|
|
|
nsImageControlFrame(nsStyleContext* aContext);
|
1999-11-05 02:16:47 +03:00
|
|
|
~nsImageControlFrame();
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
virtual void Destroy();
|
2007-02-18 19:49:54 +03:00
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
2000-05-16 16:44:32 +04:00
|
|
|
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
1999-04-27 04:06:03 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
|
1998-11-10 02:30:16 +03:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 09:03:41 +03:00
|
|
|
nsEventStatus* aEventStatus);
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
virtual nsIAtom* GetType() const;
|
2001-11-01 18:31:13 +03:00
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-18 03:52:32 +04:00
|
|
|
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
2001-11-14 04:33:42 +03:00
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const {
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ImageControl"), aResult);
|
1998-11-19 20:22:29 +03:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1998-11-19 20:22:29 +03:00
|
|
|
|
2004-12-31 00:56:11 +03:00
|
|
|
NS_IMETHOD GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor);
|
2005-12-13 02:53:06 +03:00
|
|
|
// nsIFormContromFrame
|
|
|
|
virtual void SetFocus(PRBool aOn, PRBool aRepaint);
|
|
|
|
virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue);
|
|
|
|
virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const;
|
2001-11-02 10:40:01 +03:00
|
|
|
|
1998-11-10 02:30:16 +03:00
|
|
|
protected:
|
|
|
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
|
|
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
nsImageControlFrame::nsImageControlFrame(nsStyleContext* aContext):
|
|
|
|
nsImageControlFrameSuper(aContext)
|
1998-11-10 02:30:16 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-11-05 02:16:47 +03:00
|
|
|
nsImageControlFrame::~nsImageControlFrame()
|
|
|
|
{
|
2000-05-16 16:44:32 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
|
|
|
nsImageControlFrame::Destroy()
|
2000-05-16 16:44:32 +04:00
|
|
|
{
|
2008-01-05 09:44:38 +03:00
|
|
|
if (!GetPrevInFlow()) {
|
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, PR_FALSE);
|
|
|
|
}
|
2006-04-10 04:16:29 +04:00
|
|
|
nsImageControlFrameSuper::Destroy();
|
1999-11-05 02:16:47 +03:00
|
|
|
}
|
|
|
|
|
2005-11-01 23:40:54 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewImageControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1998-11-10 02:30:16 +03:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsImageControlFrame(aContext);
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
|
|
|
|
2007-02-18 19:49:54 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsImageControlFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
nsresult rv = nsImageControlFrameSuper::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// nsIntPoint allocation can fail, in which case we just set the property
|
|
|
|
// to null, which is safe
|
2008-01-05 09:44:38 +03:00
|
|
|
if (aPrevInFlow) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-18 19:49:54 +03:00
|
|
|
return mContent->SetProperty(nsGkAtoms::imageClickedPoint,
|
|
|
|
new nsIntPoint(0, 0),
|
|
|
|
IntPointDtorFunc);
|
|
|
|
}
|
|
|
|
|
1999-11-02 04:50:15 +03:00
|
|
|
// Frames are not refcounted, no need to AddRef
|
|
|
|
NS_IMETHODIMP
|
1998-11-10 02:30:16 +03:00
|
|
|
nsImageControlFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
2007-07-04 06:15:31 +04:00
|
|
|
NS_PRECONDITION(aInstancePtr, "null out param");
|
|
|
|
|
2001-01-04 23:44:42 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(nsIFormControlFrame))) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*aInstancePtr = static_cast<nsIFormControlFrame*>(this);
|
1998-11-10 02:30:16 +03:00
|
|
|
return NS_OK;
|
2001-05-12 01:11:38 +04:00
|
|
|
}
|
|
|
|
|
1998-11-20 20:22:08 +03:00
|
|
|
return nsImageControlFrameSuper::QueryInterface(aIID, aInstancePtr);
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2001-05-18 03:52:32 +04:00
|
|
|
NS_IMETHODIMP nsImageControlFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
|
|
|
|
if (accService) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mContent->Tag() == nsGkAtoms::button) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return accService->CreateHTML4ButtonAccessible(static_cast<nsIFrame*>(this), aAccessible);
|
2005-03-27 07:03:11 +04:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (mContent->Tag() == nsGkAtoms::input) {
|
2007-07-08 11:08:04 +04:00
|
|
|
return accService->CreateHTMLButtonAccessible(static_cast<nsIFrame*>(this), aAccessible);
|
2005-03-27 07:03:11 +04:00
|
|
|
}
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
1998-11-10 02:30:16 +03:00
|
|
|
nsrefcnt nsImageControlFrame::AddRef(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsImageControlFrame::Release(void)
|
|
|
|
{
|
|
|
|
NS_WARNING("not supported");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsImageControlFrame::GetType() const
|
2001-11-01 18:31:13 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::imageControlFrame;
|
2001-11-01 18:31:13 +03:00
|
|
|
}
|
|
|
|
|
1999-04-27 04:06:03 +04:00
|
|
|
NS_METHOD
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageControlFrame::Reflow(nsPresContext* aPresContext,
|
1999-04-27 04:06:03 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsImageControlFrame");
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2008-01-05 09:44:38 +03:00
|
|
|
if (!GetPrevInFlow() && (mState & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, PR_TRUE);
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
1999-04-27 04:06:03 +04:00
|
|
|
return nsImageControlFrameSuper::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
2004-08-01 03:15:21 +04:00
|
|
|
nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
|
1999-01-27 03:25:40 +03:00
|
|
|
nsGUIEvent* aEvent,
|
1999-11-24 09:03:41 +03:00
|
|
|
nsEventStatus* aEventStatus)
|
1998-11-10 02:30:16 +03:00
|
|
|
{
|
1999-11-24 09:03:41 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
2000-08-09 03:38:00 +04:00
|
|
|
|
2002-05-02 00:15:44 +04:00
|
|
|
// Don't do anything if the event has already been handled by someone
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-09 03:38:00 +04:00
|
|
|
// do we have user-input style?
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleUserInterface* uiStyle = GetStyleUserInterface();
|
2000-08-09 03:38:00 +04:00
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) { // XXX cache disabled
|
1998-11-10 02:30:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
*aEventStatus = nsEventStatus_eIgnore;
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2006-11-17 00:35:39 +03:00
|
|
|
if (aEvent->eventStructType == NS_MOUSE_EVENT &&
|
|
|
|
aEvent->message == NS_MOUSE_BUTTON_UP &&
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton) {
|
2007-02-18 19:49:54 +03:00
|
|
|
// Store click point for nsHTMLInputElement::SubmitNamesValues
|
2006-11-17 00:35:39 +03:00
|
|
|
// Do this on MouseUp because the specs don't say and that's what IE does
|
2007-02-18 19:49:54 +03:00
|
|
|
nsIntPoint* lastClickPoint =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIntPoint*>
|
|
|
|
(mContent->GetProperty(nsGkAtoms::imageClickedPoint));
|
2007-02-18 19:49:54 +03:00
|
|
|
if (lastClickPoint) {
|
|
|
|
// normally lastClickedPoint is not null, as it's allocated in Init()
|
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
|
|
|
|
TranslateEventCoords(pt, *lastClickPoint);
|
|
|
|
}
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
1998-11-20 20:22:08 +03:00
|
|
|
return nsImageControlFrameSuper::HandleEvent(aPresContext, aEvent,
|
|
|
|
aEventStatus);
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsImageControlFrame::SetFocus(PRBool aOn, PRBool aRepaint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-04-28 02:54:15 +04:00
|
|
|
NS_IMETHODIMP
|
2004-12-31 00:56:11 +03:00
|
|
|
nsImageControlFrame::GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor)
|
1999-04-28 02:54:15 +04:00
|
|
|
{
|
1999-06-25 04:19:44 +04:00
|
|
|
// Use style defined cursor if one is provided, otherwise when
|
|
|
|
// the cursor style is "auto" we use the pointer cursor.
|
2004-12-31 00:56:11 +03:00
|
|
|
FillCursorInformationFromStyle(GetStyleUserInterface(), aCursor);
|
|
|
|
|
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
|
|
|
|
aCursor.mCursor = NS_STYLE_CURSOR_POINTER;
|
1999-06-25 04:19:44 +04:00
|
|
|
}
|
2004-12-31 00:56:11 +03:00
|
|
|
|
1999-04-28 02:54:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
nsresult
|
|
|
|
nsImageControlFrame::SetFormProperty(nsIAtom* aName,
|
|
|
|
const nsAString& aValue)
|
1999-01-26 01:16:27 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-13 02:53:06 +03:00
|
|
|
nsresult
|
|
|
|
nsImageControlFrame::GetFormProperty(nsIAtom* aName,
|
|
|
|
nsAString& aValue) const
|
1999-01-26 01:16:27 +03:00
|
|
|
{
|
2000-08-23 21:27:06 +04:00
|
|
|
aValue.Truncate();
|
1999-01-26 01:16:27 +03:00
|
|
|
return NS_OK;
|
1999-01-27 03:25:40 +03:00
|
|
|
}
|