2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2000-06-23 05:15:04 +00:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2000-06-23 05:15:04 +00:00
|
|
|
#include "nsButtonBoxFrame.h"
|
2002-09-07 05:38:16 +00:00
|
|
|
#include "nsITimer.h"
|
2000-06-23 05:15:04 +00:00
|
|
|
#include "nsRepeatService.h"
|
2013-10-28 09:03:19 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-10-01 21:01:49 +00:00
|
|
|
#include "nsIContent.h"
|
2000-06-23 05:15:04 +00:00
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2008-02-15 02:04:34 +00:00
|
|
|
class nsAutoRepeatBoxFrame : public nsButtonBoxFrame
|
2000-06-23 05:15:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2006-03-26 21:30:36 +00:00
|
|
|
friend nsIFrame* NS_NewAutoRepeatBoxFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
2000-06-23 05:15:04 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
|
2000-06-23 05:15:04 +00:00
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 08:36:33 +00:00
|
|
|
nsIAtom* aAttribute,
|
2015-03-21 16:28:04 +00:00
|
|
|
int32_t aModType) override;
|
2006-07-14 18:15:31 +00:00
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2014-02-18 08:36:33 +00:00
|
|
|
WidgetGUIEvent* aEvent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsEventStatus* aEventStatus) override;
|
2000-06-23 05:15:04 +00:00
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
NS_IMETHOD HandlePress(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsEventStatus* aEventStatus) override;
|
2006-07-14 18:15:31 +00:00
|
|
|
|
2013-10-02 03:46:03 +00:00
|
|
|
NS_IMETHOD HandleRelease(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsEventStatus* aEventStatus) override;
|
2006-07-14 18:15:31 +00:00
|
|
|
|
2005-05-05 00:07:59 +00:00
|
|
|
protected:
|
2015-01-06 09:27:56 +00:00
|
|
|
explicit nsAutoRepeatBoxFrame(nsStyleContext* aContext):
|
|
|
|
nsButtonBoxFrame(aContext) {}
|
2008-02-15 02:04:34 +00:00
|
|
|
|
|
|
|
void StartRepeat() {
|
2009-12-15 14:36:11 +00:00
|
|
|
if (IsActivatedOnHover()) {
|
|
|
|
// No initial delay on hover.
|
|
|
|
nsRepeatService::GetInstance()->Start(Notify, this, 0);
|
|
|
|
} else {
|
|
|
|
nsRepeatService::GetInstance()->Start(Notify, this);
|
|
|
|
}
|
2008-02-15 02:04:34 +00:00
|
|
|
}
|
|
|
|
void StopRepeat() {
|
|
|
|
nsRepeatService::GetInstance()->Stop(Notify, this);
|
|
|
|
}
|
|
|
|
void Notify();
|
|
|
|
static void Notify(void* aData) {
|
|
|
|
static_cast<nsAutoRepeatBoxFrame*>(aData)->Notify();
|
|
|
|
}
|
2006-03-26 21:30:36 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mTrustedEvent;
|
2008-06-12 22:09:28 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsActivatedOnHover();
|
2000-06-23 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewAutoRepeatBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-06-23 05:15:04 +00:00
|
|
|
{
|
2015-01-06 09:27:56 +00:00
|
|
|
return new (aPresShell) nsAutoRepeatBoxFrame(aContext);
|
2009-09-12 16:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsAutoRepeatBoxFrame)
|
2000-06-23 05:15:04 +00:00
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2013-10-02 03:46:03 +00:00
|
|
|
nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2000-06-23 05:15:04 +00:00
|
|
|
{
|
2009-02-27 10:48:25 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-08-22 01:34:51 +00:00
|
|
|
switch(aEvent->mMessage) {
|
2008-06-12 22:09:28 +00:00
|
|
|
// repeat mode may be "hover" for repeating while the mouse is hovering
|
|
|
|
// over the element, otherwise repetition is done while the element is
|
|
|
|
// active (pressed).
|
2015-08-28 23:58:31 +00:00
|
|
|
case eMouseEnterIntoWidget:
|
2015-08-28 23:58:32 +00:00
|
|
|
case eMouseOver:
|
2008-06-12 22:09:28 +00:00
|
|
|
if (IsActivatedOnHover()) {
|
2008-02-15 02:04:34 +00:00
|
|
|
StartRepeat();
|
2016-03-17 07:01:30 +00:00
|
|
|
mTrustedEvent = aEvent->IsTrusted();
|
2006-07-14 18:15:31 +00:00
|
|
|
}
|
2005-05-05 00:07:59 +00:00
|
|
|
break;
|
2000-06-23 05:15:04 +00:00
|
|
|
|
2015-08-28 23:58:31 +00:00
|
|
|
case eMouseExitFromWidget:
|
2015-08-28 23:58:32 +00:00
|
|
|
case eMouseOut:
|
2006-07-14 18:15:31 +00:00
|
|
|
// always stop on mouse exit
|
2008-02-15 02:04:34 +00:00
|
|
|
StopRepeat();
|
2005-05-05 00:07:59 +00:00
|
|
|
// Not really necessary but do this to be safe
|
2011-10-17 14:59:28 +00:00
|
|
|
mTrustedEvent = false;
|
2005-05-05 00:07:59 +00:00
|
|
|
break;
|
2006-07-14 18:15:31 +00:00
|
|
|
|
2015-08-28 23:58:32 +00:00
|
|
|
case eMouseClick: {
|
2013-10-28 09:03:19 +00:00
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent->IsLeftClickEvent()) {
|
2006-11-16 21:35:39 +00:00
|
|
|
// skip button frame handling to prevent click handling
|
2013-10-28 09:03:19 +00:00
|
|
|
return nsBoxFrame::HandleEvent(aPresContext, mouseEvent, aEventStatus);
|
2006-11-16 21:35:39 +00:00
|
|
|
}
|
2006-07-14 18:15:31 +00:00
|
|
|
break;
|
2013-10-28 09:03:19 +00:00
|
|
|
}
|
2015-08-26 12:56:59 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2000-06-23 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsButtonBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
2006-07-14 18:15:31 +00:00
|
|
|
NS_IMETHODIMP
|
2013-10-02 03:46:03 +00:00
|
|
|
nsAutoRepeatBoxFrame::HandlePress(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2006-07-14 18:15:31 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
2008-06-12 22:09:28 +00:00
|
|
|
if (!IsActivatedOnHover()) {
|
2009-07-02 14:47:00 +00:00
|
|
|
StartRepeat();
|
2016-03-17 07:01:30 +00:00
|
|
|
mTrustedEvent = aEvent->IsTrusted();
|
2006-07-14 18:15:31 +00:00
|
|
|
DoMouseClick(aEvent, mTrustedEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-02 03:46:03 +00:00
|
|
|
nsAutoRepeatBoxFrame::HandleRelease(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2006-07-14 18:15:31 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
2008-06-12 22:09:28 +00:00
|
|
|
if (!IsActivatedOnHover()) {
|
2008-02-15 02:04:34 +00:00
|
|
|
StopRepeat();
|
2006-07-14 18:15:31 +00:00
|
|
|
}
|
2011-08-03 03:39:02 +00:00
|
|
|
return NS_OK;
|
2006-07-14 18:15:31 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsAutoRepeatBoxFrame::AttributeChanged(int32_t aNameSpaceID,
|
2006-07-14 18:15:31 +00:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType)
|
2006-07-14 18:15:31 +00:00
|
|
|
{
|
|
|
|
if (aAttribute == nsGkAtoms::type) {
|
2008-02-15 02:04:34 +00:00
|
|
|
StopRepeat();
|
2006-07-14 18:15:31 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-15 02:04:34 +00:00
|
|
|
void
|
|
|
|
nsAutoRepeatBoxFrame::Notify()
|
2000-06-23 05:15:04 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
DoMouseClick(nullptr, mTrustedEvent);
|
2000-06-23 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 00:16:29 +00:00
|
|
|
void
|
2009-12-24 05:21:15 +00:00
|
|
|
nsAutoRepeatBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2000-06-23 05:15:04 +00:00
|
|
|
{
|
|
|
|
// Ensure our repeat service isn't going... it's possible that a scrollbar can disappear out
|
|
|
|
// from under you while you're in the process of scrolling.
|
2008-02-15 02:04:34 +00:00
|
|
|
StopRepeat();
|
2009-12-24 05:21:15 +00:00
|
|
|
nsButtonBoxFrame::DestroyFrom(aDestructRoot);
|
2000-06-23 05:15:04 +00:00
|
|
|
}
|
2006-07-14 18:15:31 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-06-12 22:09:28 +00:00
|
|
|
nsAutoRepeatBoxFrame::IsActivatedOnHover()
|
2006-07-14 18:15:31 +00:00
|
|
|
{
|
2008-06-12 22:09:28 +00:00
|
|
|
return mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::repeat,
|
|
|
|
nsGkAtoms::hover, eCaseMatters);
|
2006-07-14 18:15:31 +00:00
|
|
|
}
|