bug 331055, add repeat button, meant to check in with spinbuttons, r=neil,sr=roc

This commit is contained in:
enndeakin%sympatico.ca 2006-07-14 18:15:31 +00:00
Родитель 9e2f1fe8eb
Коммит feadb93dca
7 изменённых файлов: 107 добавлений и 19 удалений

Просмотреть файл

@ -39,23 +39,9 @@
* ***** END LICENSE BLOCK ***** */
#include "nsCOMPtr.h"
#include "nsHTMLParts.h"
#include "nsPresContext.h"
#include "nsIDeviceContext.h"
#include "nsPageFrame.h"
#include "nsIView.h"
#include "nsIViewManager.h"
#include "nsHTMLContainerFrame.h"
#include "nsCSSRendering.h"
#include "nsIScrollableView.h"
#include "nsWidgetsCID.h"
#include "nsLayoutAtoms.h"
#include "nsBoxLayoutState.h"
#include "nsIScrollbarMediator.h"
#include "nsIFormControlFrame.h"
#include "nsGfxScrollFrame.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsGUIEvent.h"
#include "nsButtonBoxFrame.h"
#include "nsITimer.h"
#include "nsRepeatService.h"
@ -69,12 +55,28 @@ public:
friend nsIFrame* NS_NewAutoRepeatBoxFrame(nsIPresShell* aPresShell,
nsStyleContext* aContext);
NS_IMETHOD Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow);
virtual void Destroy();
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType);
NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
NS_IMETHOD HandlePress(nsPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
NS_IMETHOD HandleRelease(nsPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
NS_DECL_NSITIMERCALLBACK
protected:
@ -82,6 +84,9 @@ protected:
nsButtonBoxFrame(aPresShell, aContext) {}
PRPackedBool mTrustedEvent;
PRPackedBool mIsPressMode;
void InitRepeatMode();
};
nsIFrame*
@ -97,6 +102,19 @@ NS_INTERFACE_MAP_END_INHERITING(nsButtonBoxFrame)
NS_IMPL_ADDREF_INHERITED(nsAutoRepeatBoxFrame, nsButtonBoxFrame)
NS_IMPL_RELEASE_INHERITED(nsAutoRepeatBoxFrame, nsButtonBoxFrame)
NS_IMETHODIMP
nsAutoRepeatBoxFrame::Init(nsIContent* aContent,
nsIFrame* aParent,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsBoxFrame::Init(aContent, aParent, aPrevInFlow);
InitRepeatMode();
return rv;
}
NS_IMETHODIMP
nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext,
nsGUIEvent* aEvent,
@ -106,21 +124,66 @@ nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext,
{
case NS_MOUSE_ENTER:
case NS_MOUSE_ENTER_SYNTH:
nsRepeatService::GetInstance()->Start(this);
mTrustedEvent = NS_IS_TRUSTED_EVENT(aEvent);
if (!mIsPressMode) {
nsRepeatService::GetInstance()->Start(this);
mTrustedEvent = NS_IS_TRUSTED_EVENT(aEvent);
}
break;
case NS_MOUSE_EXIT:
case NS_MOUSE_EXIT_SYNTH:
// always stop on mouse exit
nsRepeatService::GetInstance()->Stop();
// Not really necessary but do this to be safe
mTrustedEvent = PR_FALSE;
break;
case NS_MOUSE_LEFT_CLICK:
// skip button frame handling to prevent click handling
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
break;
}
return nsButtonBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
NS_IMETHODIMP
nsAutoRepeatBoxFrame::HandlePress(nsPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
if (mIsPressMode) {
mTrustedEvent = NS_IS_TRUSTED_EVENT(aEvent);
DoMouseClick(aEvent, mTrustedEvent);
nsRepeatService::GetInstance()->Start(this);
}
return NS_OK;
}
NS_IMETHODIMP
nsAutoRepeatBoxFrame::HandleRelease(nsPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
if (mIsPressMode) {
nsRepeatService::GetInstance()->Stop();
}
return NS_OK;
}
NS_IMETHODIMP
nsAutoRepeatBoxFrame::AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType)
{
if (aAttribute == nsGkAtoms::type) {
nsRepeatService::GetInstance()->Stop();
InitRepeatMode();
}
return NS_OK;
}
NS_IMETHODIMP
nsAutoRepeatBoxFrame::Notify(nsITimer *timer)
{
@ -136,3 +199,14 @@ nsAutoRepeatBoxFrame::Destroy()
nsRepeatService::GetInstance()->Stop();
nsButtonBoxFrame::Destroy();
}
void
nsAutoRepeatBoxFrame::InitRepeatMode()
{
// 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).
nsAutoString repeat;
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::repeat, repeat);
mIsPressMode = !repeat.EqualsLiteral("hover");
}

Просмотреть файл

@ -348,4 +348,7 @@
</content>
</binding>
<binding id="button-repeat" display="xul:autorepeatbutton"
extends="chrome://global/content/bindings/button.xml#button"/>
</bindings>

Просмотреть файл

@ -17,7 +17,7 @@
</binding>
<binding id="scrollbox" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
<content>
<content repeat="hover">
<xul:box class="box-inherit scrollbox-innerbox" xbl:inherits="orient,align,pack,dir" flex="1">
<children/>
</xul:box>

Просмотреть файл

@ -110,6 +110,10 @@ button {
-moz-binding: url("chrome://global/content/bindings/button.xml#button");
}
button[type="repeat"] {
-moz-binding: url("chrome://global/content/bindings/button.xml#button-repeat");
}
button[type="menu"] {
-moz-binding: url("chrome://global/content/bindings/button.xml#menu");
}

Просмотреть файл

@ -334,4 +334,7 @@
</content>
</binding>
<binding id="button-repeat" display="xul:autorepeatbutton"
extends="chrome://global/content/bindings/button.xml#button"/>
</bindings>

Просмотреть файл

@ -64,7 +64,7 @@
</binding>
<binding id="autorepeatbutton" extends="chrome://global/content/bindings/scrollbox.xml#scrollbox-base">
<content>
<content repeat="hover">
<xul:image class="autorepeatbutton-icon"/>
</content>
</binding>

Просмотреть файл

@ -109,6 +109,10 @@ button {
-moz-binding: url("chrome://global/content/bindings/button.xml#button");
}
button[type="repeat"] {
-moz-binding: url("chrome://global/content/bindings/button.xml#button-repeat");
}
button[type="menu"] {
-moz-binding: url("chrome://global/content/bindings/button.xml#menu");
}