add scroll-wheel support bug 7347. r=beard/sr=sfraser.

This commit is contained in:
pinkerton%netscape.com 2000-11-29 00:30:46 +00:00
Родитель 5a0bb91a06
Коммит 81bd688e04
4 изменённых файлов: 85 добавлений и 5 удалений

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

@ -58,6 +58,52 @@ PRBool nsMacEventHandler::sMouseInWidgetHit = PR_FALSE;
nsMacEventDispatchHandler gEventDispatchHandler;
static pascal void ScrollActionProc (ControlHandle ctrl, ControlPartCode part) ;
//
// ScrollActionProc
//
// Called from ::TrackControl(), this senses which part of the phantom
// scrollbar the click from the wheelMouse driver was in and sends
// the correct NS_MOUSE_SCROLL event into Gecko
//
static pascal void ScrollActionProc(ControlHandle ctrl, ControlPartCode partCode)
{
switch (partCode)
{
case kControlUpButtonPart:
case kControlDownButtonPart:
case kControlPageUpPart:
case kControlPageDownPart:
if ( gEventDispatchHandler.GetActive() ) {
nsMouseScrollEvent scrollEvent;
scrollEvent.scrollFlags = nsMouseScrollEvent::kIsVertical;
if ( partCode == kControlPageUpPart || partCode == kControlPageDownPart )
scrollEvent.scrollFlags |= nsMouseScrollEvent::kIsFullPage;
scrollEvent.delta =
(partCode == kControlUpButtonPart || partCode == kControlPageUpPart) ? -1 : 1;
scrollEvent.eventStructType = NS_MOUSE_SCROLL_EVENT;
scrollEvent.isShift = PR_FALSE;
scrollEvent.isControl = PR_FALSE;
scrollEvent.isMeta = PR_FALSE;
scrollEvent.isAlt = PR_FALSE;
scrollEvent.message = NS_MOUSE_SCROLL;
scrollEvent.point.x = 100;
scrollEvent.point.y = 100;
scrollEvent.time = PR_IntervalNow();
scrollEvent.widget = gEventDispatchHandler.GetActive();
scrollEvent.nativeMsg = nsnull;
// dispatch scroll event
nsEventStatus rv;
scrollEvent.widget->DispatchEvent(&scrollEvent, rv);
}
break;
}
}
//-------------------------------------------------------------------------
//
@ -91,9 +137,10 @@ nsMacEventDispatchHandler::~nsMacEventDispatchHandler()
{
mWidgetPointed->RemoveDeleteObserver(this);
mWidgetPointed = nsnull;
}
}
}
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
@ -318,6 +365,7 @@ nsMacEventHandler::nsMacEventHandler(nsMacWindow* aTopLevelWidget)
mIMEIsComposing = PR_FALSE;
mIMECompositionStr=nsnull;
mControlActionProc = NewControlActionProc(ScrollActionProc);
}
@ -329,6 +377,10 @@ nsMacEventHandler::~nsMacEventHandler()
nsAutoString::Recycle(mIMECompositionStr);
mIMECompositionStr = nsnull;
}
if ( mControlActionProc ) {
DisposeControlActionUPP(mControlActionProc);
mControlActionProc = nsnull;
}
}
@ -1203,7 +1255,20 @@ PRBool nsMacEventHandler::HandleMouseDownEvent(EventRecord& aOSEvent)
// don't allow clicks that rolled up a popup through to the content area.
if ( ignoreClickInContent )
break;
// Check if the mousedown is in our window's phantom scrollbar. If so, track
// the movement of the mouse. The scrolling code is in the action proc.
Point local = aOSEvent.where;
::GlobalToLocal ( &local );
ControlHandle scrollbar;
ControlPartCode partCode = ::FindControl(local, whichWindow, &scrollbar);
if ( partCode >= kControlUpButtonPart && partCode <= kControlPageDownPart &&
scrollbar &&
GetControlReference(scrollbar) == 'mozz' ) {
::TrackControl(scrollbar, local, mControlActionProc);
break;
}
nsMouseEvent mouseEvent;
PRUint32 mouseButton = NS_MOUSE_LEFT_BUTTON_DOWN;
if ( aOSEvent.modifiers & controlKey )
@ -1212,7 +1277,7 @@ PRBool nsMacEventHandler::HandleMouseDownEvent(EventRecord& aOSEvent)
nsCOMPtr<nsIWidget> kungFuDeathGrip ( mouseEvent.widget ); // ensure widget doesn't go away
nsWindow* widgetHit = NS_STATIC_CAST(nsWindow*, mouseEvent.widget); // while we're processing event
if (widgetHit)
{
{
// set the activation and focus on the widget hit, if it accepts it
{
nsMouseEvent mouseActivateEvent;

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

@ -22,9 +22,11 @@
#ifndef MacMacEventHandler_h__
#define MacMacEventHandler_h__
#include <ConditionalMacros.h>
#include <Events.h>
#include <MacWindows.h>
#include <TextServices.h>
#include <Controls.h>
#include "prtypes.h"
#include "nsCOMPtr.h"
#include "nsGUIEvent.h"
@ -64,6 +66,7 @@ public:
virtual void NotifyDelete(void* aDeletedObject);
private:
nsWindow* mActiveWidget;
nsWindow* mWidgetHit;
nsWindow* mWidgetPointed;
@ -127,6 +130,7 @@ protected:
static PRBool sMouseInWidgetHit;
static PRBool sInBackground;
ControlActionUPP mControlActionProc;
nsMacWindow* mTopLevelWidget;
RgnHandle mUpdateRgn;

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

@ -18,7 +18,6 @@
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsMacWindow.h"
@ -272,6 +271,7 @@ nsMacWindow::nsMacWindow() : Inherited()
, mMacEventHandler(nsnull)
, mAcceptsActivation(PR_TRUE)
, mIsActive(PR_FALSE)
, mPhantomScrollbar(nil)
{
//mMacEventHandler.reset(new nsMacEventHandler(this));
mMacEventHandler = (auto_ptr<nsMacEventHandler>) new nsMacEventHandler(this);
@ -290,7 +290,7 @@ nsMacWindow::~nsMacWindow()
{
if (mWindowMadeHere)
::DisposeWindow(mWindowPtr);
// clean up DragManager stuff
#if !TARGET_CARBON
::RemoveTrackingHandler ( sDragTrackingHandlerUPP, mWindowPtr );
@ -505,6 +505,14 @@ nsresult nsMacWindow::StandardCreate(nsIWidget *aParent,
// (note: aParent is ignored. Mac (real) windows don't want parents)
Inherited::StandardCreate(nil, bounds, aHandleEventFunction, aContext, aAppShell, theToolkit, aInitData);
// create a phantom scrollbar to catch the attention of mousewheel
// drivers. We'll catch events sent to this scrollbar in the eventhandler
// and dispatch them into gecko as NS_SCROLL_EVENTs at that point. Stash
// an identifier in the refcon so we can check it before calling TrackControl().
Rect sbRect = { 32000, 32000, 32100, 32016 };
mPhantomScrollbar = ::NewControl ( mWindowPtr, &sbRect, nil, true, 50, 0, 100,
kControlScrollBarLiveProc, (long)'mozz' );
::EmbedControl ( rootControl, mPhantomScrollbar );
// register tracking and receive handlers with the native Drag Manager
#if !TARGET_CARBON

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

@ -23,6 +23,7 @@
#define MacWindow_h__
#include <memory> // for auto_ptr
#include <Controls.h>
using std::auto_ptr;
@ -122,6 +123,8 @@ protected:
nsIWidget *mOffsetParent;
PRBool mAcceptsActivation;
PRBool mIsActive;
ControlHandle mPhantomScrollbar; // a native scrollbar for the scrollwheel
};
#endif // MacWindow_h__