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/. */
|
2000-06-23 09:15:04 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2000-06-23 09:15:04 +04:00
|
|
|
#include "nsButtonBoxFrame.h"
|
2002-09-07 09:38:16 +04:00
|
|
|
#include "nsITimer.h"
|
2000-06-23 09:15:04 +04:00
|
|
|
#include "nsRepeatService.h"
|
2013-10-28 13:03:19 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-10-02 01:01:49 +04:00
|
|
|
#include "nsIContent.h"
|
2000-06-23 09:15:04 +04:00
|
|
|
|
2013-10-02 07:46:03 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2008-02-15 05:04:34 +03:00
|
|
|
class nsAutoRepeatBoxFrame : public nsButtonBoxFrame
|
2000-06-23 09:15:04 +04:00
|
|
|
{
|
|
|
|
public:
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2006-03-27 01:30:36 +04:00
|
|
|
friend nsIFrame* NS_NewAutoRepeatBoxFrame(nsIPresShell* aPresShell,
|
|
|
|
nsStyleContext* aContext);
|
2000-06-23 09:15:04 +04:00
|
|
|
|
2009-12-24 08:21:15 +03:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
2000-06-23 09:15:04 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2006-07-14 22:15:31 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType);
|
2006-07-14 22:15:31 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult HandleEvent(nsPresContext* aPresContext,
|
2013-10-02 07:46:03 +04:00
|
|
|
WidgetGUIEvent* aEvent,
|
2000-06-23 09:15:04 +04:00
|
|
|
nsEventStatus* aEventStatus);
|
|
|
|
|
2013-10-02 07:46:03 +04:00
|
|
|
NS_IMETHOD HandlePress(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus);
|
2006-07-14 22:15:31 +04:00
|
|
|
|
2013-10-02 07:46:03 +04:00
|
|
|
NS_IMETHOD HandleRelease(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus);
|
2006-07-14 22:15:31 +04:00
|
|
|
|
2005-05-05 04:07:59 +04:00
|
|
|
protected:
|
2006-03-27 01:30:36 +04:00
|
|
|
nsAutoRepeatBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext):
|
|
|
|
nsButtonBoxFrame(aPresShell, aContext) {}
|
2008-02-15 05:04:34 +03:00
|
|
|
|
|
|
|
void StartRepeat() {
|
2009-12-15 17:36:11 +03:00
|
|
|
if (IsActivatedOnHover()) {
|
|
|
|
// No initial delay on hover.
|
|
|
|
nsRepeatService::GetInstance()->Start(Notify, this, 0);
|
|
|
|
} else {
|
|
|
|
nsRepeatService::GetInstance()->Start(Notify, this);
|
|
|
|
}
|
2008-02-15 05:04:34 +03:00
|
|
|
}
|
|
|
|
void StopRepeat() {
|
|
|
|
nsRepeatService::GetInstance()->Stop(Notify, this);
|
|
|
|
}
|
|
|
|
void Notify();
|
|
|
|
static void Notify(void* aData) {
|
|
|
|
static_cast<nsAutoRepeatBoxFrame*>(aData)->Notify();
|
|
|
|
}
|
2006-03-27 01:30:36 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mTrustedEvent;
|
2008-06-13 02:09:28 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsActivatedOnHover();
|
2000-06-23 09:15:04 +04:00
|
|
|
};
|
|
|
|
|
2005-10-27 01:46:39 +04:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewAutoRepeatBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-06-23 09:15:04 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsAutoRepeatBoxFrame (aPresShell, aContext);
|
2009-09-12 20:49:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsAutoRepeatBoxFrame)
|
2000-06-23 09:15:04 +04:00
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2013-10-02 07:46:03 +04:00
|
|
|
nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
|
|
|
nsEventStatus* aEventStatus)
|
2000-06-23 09:15:04 +04:00
|
|
|
{
|
2009-02-27 13:48:25 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-23 09:15:04 +04:00
|
|
|
switch(aEvent->message)
|
|
|
|
{
|
2008-06-13 02:09:28 +04: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).
|
2000-06-23 09:15:04 +04:00
|
|
|
case NS_MOUSE_ENTER:
|
|
|
|
case NS_MOUSE_ENTER_SYNTH:
|
2008-06-13 02:09:28 +04:00
|
|
|
if (IsActivatedOnHover()) {
|
2008-02-15 05:04:34 +03:00
|
|
|
StartRepeat();
|
2012-12-16 05:26:03 +04:00
|
|
|
mTrustedEvent = aEvent->mFlags.mIsTrusted;
|
2006-07-14 22:15:31 +04:00
|
|
|
}
|
2005-05-05 04:07:59 +04:00
|
|
|
break;
|
2000-06-23 09:15:04 +04:00
|
|
|
|
|
|
|
case NS_MOUSE_EXIT:
|
|
|
|
case NS_MOUSE_EXIT_SYNTH:
|
2006-07-14 22:15:31 +04:00
|
|
|
// always stop on mouse exit
|
2008-02-15 05:04:34 +03:00
|
|
|
StopRepeat();
|
2005-05-05 04:07:59 +04:00
|
|
|
// Not really necessary but do this to be safe
|
2011-10-17 18:59:28 +04:00
|
|
|
mTrustedEvent = false;
|
2005-05-05 04:07:59 +04:00
|
|
|
break;
|
2006-07-14 22:15:31 +04:00
|
|
|
|
2013-10-28 13:03:19 +04:00
|
|
|
case NS_MOUSE_CLICK: {
|
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent->IsLeftClickEvent()) {
|
2006-11-17 00:35:39 +03:00
|
|
|
// skip button frame handling to prevent click handling
|
2013-10-28 13:03:19 +04:00
|
|
|
return nsBoxFrame::HandleEvent(aPresContext, mouseEvent, aEventStatus);
|
2006-11-17 00:35:39 +03:00
|
|
|
}
|
2006-07-14 22:15:31 +04:00
|
|
|
break;
|
2013-10-28 13:03:19 +04:00
|
|
|
}
|
2000-06-23 09:15:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsButtonBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
2006-07-14 22:15:31 +04:00
|
|
|
NS_IMETHODIMP
|
2013-10-02 07:46:03 +04:00
|
|
|
nsAutoRepeatBoxFrame::HandlePress(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2006-07-14 22:15:31 +04:00
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
2008-06-13 02:09:28 +04:00
|
|
|
if (!IsActivatedOnHover()) {
|
2009-07-02 18:47:00 +04:00
|
|
|
StartRepeat();
|
2012-12-16 05:26:03 +04:00
|
|
|
mTrustedEvent = aEvent->mFlags.mIsTrusted;
|
2006-07-14 22:15:31 +04:00
|
|
|
DoMouseClick(aEvent, mTrustedEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-02 07:46:03 +04:00
|
|
|
nsAutoRepeatBoxFrame::HandleRelease(nsPresContext* aPresContext,
|
|
|
|
WidgetGUIEvent* aEvent,
|
2006-07-14 22:15:31 +04:00
|
|
|
nsEventStatus* aEventStatus)
|
|
|
|
{
|
2008-06-13 02:09:28 +04:00
|
|
|
if (!IsActivatedOnHover()) {
|
2008-02-15 05:04:34 +03:00
|
|
|
StopRepeat();
|
2006-07-14 22:15:31 +04:00
|
|
|
}
|
2011-08-03 07:39:02 +04:00
|
|
|
return NS_OK;
|
2006-07-14 22:15:31 +04:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAutoRepeatBoxFrame::AttributeChanged(int32_t aNameSpaceID,
|
2006-07-14 22:15:31 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2006-07-14 22:15:31 +04:00
|
|
|
{
|
|
|
|
if (aAttribute == nsGkAtoms::type) {
|
2008-02-15 05:04:34 +03:00
|
|
|
StopRepeat();
|
2006-07-14 22:15:31 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-15 05:04:34 +03:00
|
|
|
void
|
|
|
|
nsAutoRepeatBoxFrame::Notify()
|
2000-06-23 09:15:04 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
DoMouseClick(nullptr, mTrustedEvent);
|
2000-06-23 09:15:04 +04:00
|
|
|
}
|
|
|
|
|
2006-04-10 04:16:29 +04:00
|
|
|
void
|
2009-12-24 08:21:15 +03:00
|
|
|
nsAutoRepeatBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2000-06-23 09:15:04 +04: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 05:04:34 +03:00
|
|
|
StopRepeat();
|
2009-12-24 08:21:15 +03:00
|
|
|
nsButtonBoxFrame::DestroyFrom(aDestructRoot);
|
2000-06-23 09:15:04 +04:00
|
|
|
}
|
2006-07-14 22:15:31 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-06-13 02:09:28 +04:00
|
|
|
nsAutoRepeatBoxFrame::IsActivatedOnHover()
|
2006-07-14 22:15:31 +04:00
|
|
|
{
|
2008-06-13 02:09:28 +04:00
|
|
|
return mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::repeat,
|
|
|
|
nsGkAtoms::hover, eCaseMatters);
|
2006-07-14 22:15:31 +04:00
|
|
|
}
|