2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsImageFrame.h"
|
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsFormControlFrame.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2012-09-28 14:53:44 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-19 00:21:56 -08:00
|
|
|
typedef nsImageFrame nsImageControlFrameSuper;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsImageControlFrame : public nsImageControlFrameSuper,
|
|
|
|
public nsIFormControlFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsImageControlFrame(nsStyleContext* aContext);
|
|
|
|
~nsImageControlFrame();
|
|
|
|
|
2014-02-19 00:21:57 -08:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
2013-03-19 18:47:48 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2009-01-12 11:20:59 -08:00
|
|
|
|
|
|
|
NS_DECL_QUERYFRAME
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2014-02-19 00:21:57 -08:00
|
|
|
nsReflowStatus& aStatus) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 00:36:33 -08:00
|
|
|
WidgetGUIEvent* aEvent,
|
2014-02-19 00:21:57 -08:00
|
|
|
nsEventStatus* aEventStatus) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-19 00:21:57 -08:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 14:53:44 -07:00
|
|
|
virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-19 00:21:57 -08:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE {
|
2007-03-22 10:30:00 -07:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ImageControl"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult GetCursor(const nsPoint& aPoint,
|
2014-02-19 00:21:57 -08:00
|
|
|
nsIFrame::Cursor& aCursor) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIFormContromFrame
|
2014-02-19 00:21:57 -08:00
|
|
|
virtual void SetFocus(bool aOn, bool aRepaint) MOZ_OVERRIDE;
|
|
|
|
virtual nsresult SetFormProperty(nsIAtom* aName,
|
|
|
|
const nsAString& aValue) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsImageControlFrame::nsImageControlFrame(nsStyleContext* aContext):
|
|
|
|
nsImageControlFrameSuper(aContext)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageControlFrame::~nsImageControlFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-23 21:21:15 -08:00
|
|
|
nsImageControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-04 22:44:38 -08:00
|
|
|
if (!GetPrevInFlow()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, false);
|
2008-01-04 22:44:38 -08:00
|
|
|
}
|
2009-12-23 21:21:15 -08:00
|
|
|
nsImageControlFrameSuper::DestroyFrom(aDestructRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewImageControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsImageControlFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsImageControlFrame)
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsImageControlFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-03-19 18:47:48 -07:00
|
|
|
nsImageControlFrameSuper::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-04 22:44:38 -08:00
|
|
|
if (aPrevInFlow) {
|
2013-03-19 18:47:48 -07:00
|
|
|
return;
|
2008-01-04 22:44:38 -08:00
|
|
|
}
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
mContent->SetProperty(nsGkAtoms::imageClickedPoint,
|
|
|
|
new nsIntPoint(0, 0),
|
2014-03-25 06:25:47 -07:00
|
|
|
nsINode::DeleteProperty<nsIntPoint>);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsImageControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsImageControlFrameSuper)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 14:53:44 -07:00
|
|
|
a11y::AccType
|
|
|
|
nsImageControlFrame::AccessibleType()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-28 14:53:44 -07:00
|
|
|
if (mContent->Tag() == nsGkAtoms::button ||
|
|
|
|
mContent->Tag() == nsGkAtoms::input) {
|
2012-12-17 17:25:52 -08:00
|
|
|
return a11y::eHTMLButtonType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-12 02:04:12 -08:00
|
|
|
return a11y::eNoType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsImageControlFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::imageControlFrame;
|
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsImageControlFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsImageControlFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
2008-01-04 22:44:38 -08:00
|
|
|
if (!GetPrevInFlow() && (mState & NS_FRAME_FIRST_REFLOW)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsFormControlFrame::RegUnRegAccessKey(this, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return nsImageControlFrameSuper::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2013-10-01 20:46:03 -07:00
|
|
|
nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
|
|
|
|
// Don't do anything if the event has already been handled by someone
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do we have user-input style?
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleUserInterface* uiStyle = StyleUserInterface();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED)
|
|
|
|
return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
|
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) { // XXX cache disabled
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aEventStatus = nsEventStatus_eIgnore;
|
|
|
|
|
2013-10-22 01:55:20 -07:00
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_UP &&
|
|
|
|
aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
|
2013-03-28 12:41:32 -07:00
|
|
|
// Store click point for HTMLInputElement::SubmitNamesValues
|
2007-03-22 10:30:00 -07:00
|
|
|
// Do this on MouseUp because the specs don't say and that's what IE does
|
|
|
|
nsIntPoint* lastClickPoint =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsIntPoint*>
|
|
|
|
(mContent->GetProperty(nsGkAtoms::imageClickedPoint));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (lastClickPoint) {
|
|
|
|
// normally lastClickedPoint is not null, as it's allocated in Init()
|
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
|
|
|
|
TranslateEventCoords(pt, *lastClickPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsImageControlFrameSuper::HandleEvent(aPresContext, aEvent,
|
|
|
|
aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsImageControlFrame::SetFocus(bool aOn, bool aRepaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsImageControlFrame::GetCursor(const nsPoint& aPoint,
|
|
|
|
nsIFrame::Cursor& aCursor)
|
|
|
|
{
|
|
|
|
// Use style defined cursor if one is provided, otherwise when
|
|
|
|
// the cursor style is "auto" we use the pointer cursor.
|
2013-02-16 13:51:02 -08:00
|
|
|
FillCursorInformationFromStyle(StyleUserInterface(), aCursor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
|
|
|
|
aCursor.mCursor = NS_STYLE_CURSOR_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsImageControlFrame::SetFormProperty(nsIAtom* aName,
|
|
|
|
const nsAString& aValue)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|