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/. */
|
2014-08-06 09:19:27 +04:00
|
|
|
|
1999-04-14 01:51:43 +04:00
|
|
|
#include "nsImageFrame.h"
|
1998-11-10 02:30:16 +03:00
|
|
|
#include "nsIFormControlFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.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"
|
2005-08-23 07:57:07 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2014-08-06 09:19:27 +04:00
|
|
|
#include "nsIContent.h"
|
2012-09-29 01:53:44 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2016-04-18 08:47:53 +03:00
|
|
|
class nsImageControlFrame : public nsImageFrame,
|
2007-02-18 19:49:54 +03:00
|
|
|
public nsIFormControlFrame
|
1998-11-10 02:30:16 +03:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit nsImageControlFrame(nsStyleContext* aContext);
|
1999-11-05 02:16:47 +03:00
|
|
|
~nsImageControlFrame();
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
|
2014-05-25 02:20:40 +04:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* aPrevInFlow) override;
|
2009-01-12 22:20:59 +03:00
|
|
|
|
|
|
|
NS_DECL_QUERYFRAME
|
2017-05-26 13:11:11 +03:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsImageControlFrame)
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
|
|
|
ReflowOutput& aDesiredSize,
|
|
|
|
const ReflowInput& aReflowInput,
|
|
|
|
nsReflowStatus& aStatus) override;
|
1999-04-27 04:06:03 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 12:36:33 +04:00
|
|
|
WidgetGUIEvent* aEvent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsEventStatus* aEventStatus) override;
|
1998-11-10 02:30:16 +03:00
|
|
|
|
2001-08-17 07:13:07 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual mozilla::a11y::AccType AccessibleType() override;
|
2001-08-17 07:13:07 +04:00
|
|
|
#endif
|
2001-05-18 03:52:32 +04:00
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override {
|
2001-11-14 04:33:42 +03:00
|
|
|
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
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult GetCursor(const nsPoint& aPoint,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame::Cursor& aCursor) override;
|
2005-12-13 02:53:06 +03:00
|
|
|
// nsIFormContromFrame
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetFocus(bool aOn, bool aRepaint) override;
|
2016-04-18 08:47:53 +03:00
|
|
|
virtual nsresult SetFormProperty(nsIAtom* aName,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsAString& aValue) override;
|
1998-11-10 02:30:16 +03:00
|
|
|
};
|
|
|
|
|
2016-04-18 08:47:53 +03:00
|
|
|
nsImageControlFrame::nsImageControlFrame(nsStyleContext* aContext)
|
2017-05-26 13:11:11 +03:00
|
|
|
: nsImageFrame(aContext, kClassID)
|
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
|
|
|
}
|
2016-04-18 08:47:53 +03:00
|
|
|
nsImageFrame::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)
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsImageControlFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-02-18 19:49:54 +03:00
|
|
|
{
|
2016-04-18 08:47:53 +03:00
|
|
|
nsImageFrame::Init(aContent, aParent, aPrevInFlow);
|
2007-02-18 19:49:54 +03:00
|
|
|
|
2008-01-05 09:44:38 +03:00
|
|
|
if (aPrevInFlow) {
|
2013-03-20 05:47:48 +04:00
|
|
|
return;
|
2008-01-05 09:44:38 +03:00
|
|
|
}
|
2016-04-18 08:47:53 +03:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
mContent->SetProperty(nsGkAtoms::imageClickedPoint,
|
|
|
|
new nsIntPoint(0, 0),
|
2014-03-25 17:25:47 +04:00
|
|
|
nsINode::DeleteProperty<nsIntPoint>);
|
2007-02-18 19:49:54 +03:00
|
|
|
}
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsImageControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
2016-04-18 08:47:53 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsImageFrame)
|
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
|
|
|
{
|
2015-03-03 14:09:00 +03:00
|
|
|
if (mContent->IsAnyOfHTMLElements(nsGkAtoms::button, nsGkAtoms::input)) {
|
2012-12-18 05:25:52 +04:00
|
|
|
return a11y::eHTMLButtonType;
|
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
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2015-03-30 01:38:40 +03:00
|
|
|
nsImageControlFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2015-03-30 01:38:40 +03:00
|
|
|
nsReflowStatus& aStatus)
|
1999-04-27 04:06:03 +04:00
|
|
|
{
|
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");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, 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
|
|
|
}
|
2016-07-21 13:36:39 +03:00
|
|
|
return nsImageFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
|
|
|
|
2016-04-18 08:47:53 +03:00
|
|
|
nsresult
|
2013-10-02 07:46:03 +04:00
|
|
|
nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* 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?
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleUserInterface* uiStyle = StyleUserInterface();
|
2016-10-23 01:08:18 +03:00
|
|
|
if (uiStyle->mUserInput == StyleUserInput::None ||
|
|
|
|
uiStyle->mUserInput == StyleUserInput::Disabled) {
|
2000-08-09 03:38:00 +04:00
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
2016-10-23 01:08:18 +03:00
|
|
|
}
|
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
|
|
|
|
2015-08-29 02:58:30 +03:00
|
|
|
if (aEvent->mMessage == eMouseUp &&
|
2013-10-22 12:55:20 +04:00
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2013-03-28 23:41:32 +04:00
|
|
|
// Store click point for HTMLInputElement::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
|
|
|
}
|
2016-04-18 08:47:53 +03:00
|
|
|
return nsImageFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
1998-11-10 02:30:16 +03:00
|
|
|
}
|
|
|
|
|
2016-04-18 08:47:53 +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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
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.
|
2013-02-17 01:51:02 +04:00
|
|
|
FillCursorInformationFromStyle(StyleUserInterface(), aCursor);
|
2004-12-31 00:56:11 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|