2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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"
|
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 "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"
|
2012-09-29 01:53:44 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
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
|
|
|
|
2009-12-24 08:21:15 +03:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
2007-02-18 19:49:54 +03:00
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
2009-01-12 22:20:59 +03:00
|
|
|
|
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
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
|
2012-09-29 01:53:44 +04:00
|
|
|
virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
|
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
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual void SetFocus(bool aOn, bool aRepaint);
|
2005-12-13 02:53:06 +03:00
|
|
|
virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue);
|
|
|
|
virtual nsresult GetFormProperty(nsIAtom* aName, nsAString& aValue) const;
|
1998-11-10 02:30:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
2009-12-24 08:21:15 +03:00
|
|
|
nsImageControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2000-05-16 16:44:32 +04:00
|
|
|
{
|
2008-01-05 09:44:38 +03:00
|
|
|
if (!GetPrevInFlow()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, false);
|
2008-01-05 09:44:38 +03:00
|
|
|
}
|
2009-12-24 08:21:15 +03:00
|
|
|
nsImageControlFrameSuper::DestroyFrom(aDestructRoot);
|
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
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsImageControlFrame)
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsImageControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsImageControlFrameSuper)
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-29 01:53:44 +04:00
|
|
|
a11y::AccType
|
|
|
|
nsImageControlFrame::AccessibleType()
|
2001-05-18 03:52:32 +04:00
|
|
|
{
|
2012-09-29 01:53:44 +04:00
|
|
|
if (mContent->Tag() == nsGkAtoms::button ||
|
|
|
|
mContent->Tag() == nsGkAtoms::input) {
|
2012-12-12 14:04:12 +04:00
|
|
|
return a11y::eHTMLButton;
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
|
|
|
|
2012-12-12 14:04:12 +04:00
|
|
|
return a11y::eNoType;
|
2001-05-18 03:52:32 +04:00
|
|
|
}
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
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)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, 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
|
2011-09-29 10:19:26 +04:00
|
|
|
nsImageControlFrame::SetFocus(bool aOn, bool aRepaint)
|
1998-11-10 02:30:16 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|