2006-11-22 03:48:57 +03:00
|
|
|
/* -*- Mode: objc; 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/. */
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2010-06-28 04:25:04 +04:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG
|
|
|
|
#endif
|
|
|
|
#include "prlog.h"
|
|
|
|
|
2005-06-26 07:25:52 +04:00
|
|
|
#include <unistd.h>
|
2011-08-11 21:42:23 +04:00
|
|
|
#include <math.h>
|
2006-09-21 20:25:01 +04:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
#include "nsChildView.h"
|
2007-07-18 00:29:39 +04:00
|
|
|
#include "nsCocoaWindow.h"
|
2005-06-26 07:25:52 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
2001-11-06 18:35:24 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsToolkit.h"
|
2002-12-13 11:43:18 +03:00
|
|
|
#include "nsCRT.h"
|
2005-06-26 07:25:52 +04:00
|
|
|
|
2011-04-08 05:05:49 +04:00
|
|
|
#include "nsFontMetrics.h"
|
2001-11-06 18:35:24 +03:00
|
|
|
#include "nsIRollupListener.h"
|
2007-02-12 22:38:10 +03:00
|
|
|
#include "nsIViewManager.h"
|
2004-09-20 16:51:31 +04:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2007-07-17 06:24:05 +04:00
|
|
|
#include "nsILocalFileMac.h"
|
2006-11-10 01:58:11 +03:00
|
|
|
#include "nsGfxCIID.h"
|
2009-06-18 07:39:22 +04:00
|
|
|
#include "nsIDOMSimpleGestureEvent.h"
|
2011-05-18 05:48:34 +04:00
|
|
|
#include "nsNPAPIPluginInstance.h"
|
2011-01-11 16:03:16 +03:00
|
|
|
#include "nsThemeConstants.h"
|
2006-11-10 01:58:11 +03:00
|
|
|
|
2006-10-26 02:45:22 +04:00
|
|
|
#include "nsDragService.h"
|
2009-03-18 05:04:01 +03:00
|
|
|
#include "nsClipboard.h"
|
2006-12-20 05:13:57 +03:00
|
|
|
#include "nsCursorManager.h"
|
|
|
|
#include "nsWindowMap.h"
|
2012-05-17 11:53:20 +04:00
|
|
|
#include "nsCocoaFeatures.h"
|
2007-02-23 00:56:50 +03:00
|
|
|
#include "nsCocoaUtils.h"
|
2008-10-30 08:36:01 +03:00
|
|
|
#include "nsMenuUtilsX.h"
|
2008-01-29 09:11:06 +03:00
|
|
|
#include "nsMenuBarX.h"
|
2010-06-10 04:56:17 +04:00
|
|
|
#ifdef __LP64__
|
|
|
|
#include "ComplexTextInputPanel.h"
|
|
|
|
#endif
|
2006-11-10 01:58:11 +03:00
|
|
|
|
2006-02-22 04:31:14 +03:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxQuartzSurface.h"
|
2009-11-10 04:00:36 +03:00
|
|
|
#include "nsRegion.h"
|
2010-04-28 02:29:29 +04:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "LayerManagerOGL.h"
|
2011-02-20 01:22:12 +03:00
|
|
|
#include "GLContext.h"
|
2012-01-19 18:45:37 +04:00
|
|
|
#include "mozilla/layers/CompositorCocoaWidgetHelper.h"
|
2012-06-07 04:26:45 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
2006-08-31 02:06:44 +04:00
|
|
|
|
2011-05-27 12:15:20 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2008-05-09 02:03:46 +04:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
2009-04-22 03:53:52 +04:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
|
|
|
|
2012-01-18 00:33:04 +04:00
|
|
|
#include "sampler.h"
|
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2010-04-28 02:29:29 +04:00
|
|
|
using namespace mozilla::layers;
|
2011-02-20 01:22:12 +03:00
|
|
|
using namespace mozilla::gl;
|
2011-05-08 14:19:15 +04:00
|
|
|
using namespace mozilla::widget;
|
2011-05-27 12:15:20 +04:00
|
|
|
using namespace mozilla;
|
2011-05-08 14:19:15 +04:00
|
|
|
|
2006-08-31 02:06:44 +04:00
|
|
|
#undef DEBUG_UPDATE
|
2006-12-20 05:13:57 +03:00
|
|
|
#undef INVALIDATE_DEBUGGING // flash areas as they are invalidated
|
2006-08-31 02:06:44 +04:00
|
|
|
|
2009-02-16 04:06:52 +03:00
|
|
|
// Don't put more than this many rects in the dirty region, just fluff
|
|
|
|
// out to the bounding-box if there are more
|
|
|
|
#define MAX_RECTS_IN_REGION 100
|
|
|
|
|
2007-07-17 06:24:05 +04:00
|
|
|
#ifdef PR_LOGGING
|
2012-07-30 18:20:58 +04:00
|
|
|
PRLogModuleInfo* sCocoaLog = nullptr;
|
2007-07-17 06:24:05 +04:00
|
|
|
#endif
|
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
extern "C" {
|
|
|
|
CG_EXTERN void CGContextResetCTM(CGContextRef);
|
|
|
|
CG_EXTERN void CGContextSetCTM(CGContextRef, CGAffineTransform);
|
|
|
|
CG_EXTERN void CGContextResetClip(CGContextRef);
|
|
|
|
}
|
2006-09-11 19:47:35 +04:00
|
|
|
|
2010-08-17 07:26:17 +04:00
|
|
|
// defined in nsMenuBarX.mm
|
|
|
|
extern NSMenu* sApplicationMenu; // Application menu shared by all menubars
|
|
|
|
|
2009-05-15 00:13:22 +04:00
|
|
|
// these are defined in nsCocoaWindow.mm
|
2011-09-29 10:19:26 +04:00
|
|
|
extern bool gConsumeRollupEvent;
|
2008-02-13 18:57:12 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool gChildViewMethodsSwizzled = false;
|
2009-02-06 20:36:04 +03:00
|
|
|
|
2007-07-18 03:02:40 +04:00
|
|
|
extern nsISupportsArray *gDraggedTransferables;
|
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
ChildView* ChildViewMouseTracker::sLastMouseEventView = nil;
|
2011-08-13 18:25:39 +04:00
|
|
|
NSEvent* ChildViewMouseTracker::sLastMouseMoveEvent = nil;
|
2011-08-08 18:43:13 +04:00
|
|
|
NSWindow* ChildViewMouseTracker::sWindowUnderMouse = nil;
|
2011-08-18 02:30:52 +04:00
|
|
|
NSPoint ChildViewMouseTracker::sLastScrollEventScreenLocation = NSZeroPoint;
|
2007-04-15 17:43:55 +04:00
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
#ifdef INVALIDATE_DEBUGGING
|
|
|
|
static void blinkRect(Rect* r);
|
|
|
|
static void blinkRgn(RgnHandle rgn);
|
2006-09-11 19:47:35 +04:00
|
|
|
#endif
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIRollupListener * gRollupListener = nullptr;
|
|
|
|
nsIWidget * gRollupWidget = nullptr;
|
2006-03-29 22:51:35 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool gUserCancelledDrag = false;
|
2005-02-08 20:34:09 +03:00
|
|
|
|
2009-04-22 03:53:52 +04:00
|
|
|
PRUint32 nsChildView::sLastInputEventCount = 0;
|
|
|
|
|
2002-12-13 11:43:18 +03:00
|
|
|
@interface ChildView(Private)
|
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
// sets up our view, attaching it to its owning gecko view
|
2007-10-09 22:46:30 +04:00
|
|
|
- (id)initWithFrame:(NSRect)inFrame geckoChild:(nsChildView*)inChild;
|
2011-02-04 00:12:33 +03:00
|
|
|
- (void)forceRefreshOpenGL;
|
2005-09-30 04:59:29 +04:00
|
|
|
|
2007-06-13 00:28:26 +04:00
|
|
|
// set up a gecko mouse event based on a cocoa mouse event
|
|
|
|
- (void) convertCocoaMouseEvent:(NSEvent*)aMouseEvent toGeckoEvent:(nsInputEvent*)outGeckoEvent;
|
|
|
|
|
2006-07-31 02:55:37 +04:00
|
|
|
- (NSMenu*)contextMenu;
|
2002-12-13 11:43:18 +03:00
|
|
|
|
|
|
|
- (void)setIsPluginView:(BOOL)aIsPlugin;
|
2009-09-01 05:00:13 +04:00
|
|
|
- (void)setPluginEventModel:(NPEventModel)eventModel;
|
2010-09-17 21:55:39 +04:00
|
|
|
- (void)setPluginDrawingModel:(NPDrawingModel)drawingModel;
|
|
|
|
- (NPDrawingModel)pluginDrawingModel;
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2005-07-16 00:53:13 +04:00
|
|
|
- (BOOL)isRectObscuredBySubview:(NSRect)inRect;
|
2005-03-30 08:05:54 +04:00
|
|
|
|
2006-11-09 17:00:08 +03:00
|
|
|
- (void)processPendingRedraws;
|
|
|
|
|
2010-10-15 14:34:29 +04:00
|
|
|
- (void)drawRect:(NSRect)aRect inContext:(CGContextRef)aContext;
|
|
|
|
|
2011-01-26 00:21:35 +03:00
|
|
|
// Called using performSelector:withObject:afterDelay:0 to release
|
|
|
|
// aWidgetArray (and its contents) the next time through the run loop.
|
|
|
|
- (void)releaseWidgets:(NSArray*)aWidgetArray;
|
|
|
|
|
2004-02-18 19:18:38 +03:00
|
|
|
#if USE_CLICK_HOLD_CONTEXTMENU
|
2004-01-15 22:01:49 +03:00
|
|
|
// called on a timer two seconds after a mouse down to see if we should display
|
|
|
|
// a context menu (click-hold)
|
|
|
|
- (void)clickHoldCallback:(id)inEvent;
|
2004-02-18 19:18:38 +03:00
|
|
|
#endif
|
2004-01-15 22:01:49 +03:00
|
|
|
|
2006-09-11 19:47:35 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
- (id<mozAccessible>)accessible;
|
|
|
|
#endif
|
|
|
|
|
2010-07-16 16:48:02 +04:00
|
|
|
- (BOOL)inactiveWindowAcceptsMouseEvent:(NSEvent*)aEvent;
|
|
|
|
|
2002-12-13 11:43:18 +03:00
|
|
|
@end
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
#pragma mark -
|
|
|
|
|
2006-03-10 23:51:48 +03:00
|
|
|
/* Convenience routines to go from a gecko rect to cocoa NSRects and back
|
|
|
|
*
|
|
|
|
* Gecko rects (nsRect) contain an origin (x,y) in a coordinate
|
|
|
|
* system with (0,0) in the top-left of the screen. Cocoa rects
|
|
|
|
* (NSRect) contain an origin (x,y) in a coordinate system with
|
|
|
|
* (0,0) in the bottom-left of the screen. Both nsRect and NSRect
|
|
|
|
* contain width/height info, with no difference in their use.
|
|
|
|
* If a Cocoa rect is from a flipped view, there is no need to
|
|
|
|
* convert coordinate systems.
|
|
|
|
*/
|
|
|
|
|
2002-12-13 11:43:18 +03:00
|
|
|
static inline void
|
2009-01-15 06:27:09 +03:00
|
|
|
NSRectToGeckoRect(const NSRect & inCocoaRect, nsIntRect & outGeckoRect)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2009-01-15 06:27:09 +03:00
|
|
|
outGeckoRect.x = NSToIntRound(inCocoaRect.origin.x);
|
|
|
|
outGeckoRect.y = NSToIntRound(inCocoaRect.origin.y);
|
|
|
|
outGeckoRect.width = NSToIntRound(inCocoaRect.origin.x + inCocoaRect.size.width) - outGeckoRect.x;
|
|
|
|
outGeckoRect.height = NSToIntRound(inCocoaRect.origin.y + inCocoaRect.size.height) - outGeckoRect.y;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2002-12-13 11:43:18 +03:00
|
|
|
static inline void
|
2009-01-15 06:27:09 +03:00
|
|
|
ConvertGeckoRectToMacRect(const nsIntRect& aRect, Rect& outMacRect)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
|
|
|
outMacRect.left = aRect.x;
|
|
|
|
outMacRect.top = aRect.y;
|
|
|
|
outMacRect.right = aRect.x + aRect.width;
|
|
|
|
outMacRect.bottom = aRect.y + aRect.height;
|
|
|
|
}
|
|
|
|
|
2006-09-07 22:53:59 +04:00
|
|
|
// Flips a screen coordinate from a point in the cocoa coordinate system (bottom-left rect) to a point
|
|
|
|
// that is a "flipped" cocoa coordinate system (starts in the top-left).
|
|
|
|
static inline void
|
2009-06-19 20:15:23 +04:00
|
|
|
FlipCocoaScreenCoordinate(NSPoint &inPoint)
|
2007-02-23 00:56:50 +03:00
|
|
|
{
|
2007-12-06 02:17:08 +03:00
|
|
|
inPoint.y = nsCocoaUtils::FlippedScreenY(inPoint.y);
|
2006-09-07 22:53:59 +04:00
|
|
|
}
|
|
|
|
|
2011-07-06 07:41:27 +04:00
|
|
|
void EnsureLogInitialized()
|
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (!sCocoaLog) {
|
|
|
|
sCocoaLog = PR_NewLogModule("nsCocoaWidgets");
|
|
|
|
}
|
|
|
|
#endif // PR_LOGGING
|
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
#pragma mark -
|
|
|
|
|
2003-04-22 02:24:12 +04:00
|
|
|
nsChildView::nsChildView() : nsBaseWidget()
|
2012-07-30 18:20:58 +04:00
|
|
|
, mView(nullptr)
|
|
|
|
, mParentView(nullptr)
|
|
|
|
, mParentWidget(nullptr)
|
2011-10-01 04:20:33 +04:00
|
|
|
, mVisible(false)
|
|
|
|
, mDrawing(false)
|
|
|
|
, mPluginDrawing(false)
|
|
|
|
, mIsDispatchPaint(false)
|
2012-07-30 18:20:58 +04:00
|
|
|
, mPluginInstanceOwner(nullptr)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2011-07-06 07:41:27 +04:00
|
|
|
EnsureLogInitialized();
|
2007-07-17 06:24:05 +04:00
|
|
|
|
2010-03-25 22:36:44 +03:00
|
|
|
memset(&mPluginCGContext, 0, sizeof(mPluginCGContext));
|
2010-06-15 23:34:32 +04:00
|
|
|
#ifndef NP_NO_QUICKDRAW
|
2010-03-25 22:36:44 +03:00
|
|
|
memset(&mPluginQDPort, 0, sizeof(mPluginQDPort));
|
2010-06-15 23:34:32 +04:00
|
|
|
#endif
|
2010-03-25 22:36:44 +03:00
|
|
|
|
2007-09-05 10:58:16 +04:00
|
|
|
SetBackgroundColor(NS_RGB(255, 255, 255));
|
|
|
|
SetForegroundColor(NS_RGB(0, 0, 0));
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsChildView::~nsChildView()
|
|
|
|
{
|
2009-07-20 19:02:31 +04:00
|
|
|
// Notify the children that we're gone. childView->ResetParent() can change
|
|
|
|
// our list of children while it's being iterated, so the way we iterate the
|
|
|
|
// list must allow for this.
|
|
|
|
for (nsIWidget* kid = mLastChild; kid;) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsChildView* childView = static_cast<nsChildView*>(kid);
|
2009-07-20 19:02:31 +04:00
|
|
|
kid = kid->GetPrevSibling();
|
2009-04-23 19:54:50 +04:00
|
|
|
childView->ResetParent();
|
2005-07-08 21:55:32 +04:00
|
|
|
}
|
|
|
|
|
2008-06-27 21:11:24 +04:00
|
|
|
NS_WARN_IF_FALSE(mOnDestroyCalled, "nsChildView object destroyed without calling Destroy()");
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mResizerImage = nullptr;
|
2011-02-20 01:23:02 +03:00
|
|
|
|
2008-06-27 21:11:24 +04:00
|
|
|
// An nsChildView object that was in use can be destroyed without Destroy()
|
|
|
|
// ever being called on it. So we also need to do a quick, safe cleanup
|
|
|
|
// here (it's too late to just call Destroy(), which can cause crashes).
|
|
|
|
// It's particularly important to make sure widgetDestroyed is called on our
|
|
|
|
// mView -- this method NULLs mView's mGeckoChild, and NULL checks on
|
|
|
|
// mGeckoChild are used throughout the ChildView class to tell if it's safe
|
|
|
|
// to use a ChildView object.
|
|
|
|
[mView widgetDestroyed]; // Safe if mView is nil.
|
|
|
|
mParentWidget = nil;
|
|
|
|
TearDownView(); // Safe if called twice.
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2008-07-14 06:56:18 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsChildView, nsBaseWidget, nsIPluginWidget)
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2009-09-24 10:18:10 +04:00
|
|
|
nsresult nsChildView::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
2011-04-17 05:22:44 +04:00
|
|
|
nsDeviceContext *aContext,
|
2009-09-24 10:18:10 +04:00
|
|
|
nsWidgetInitData *aInitData)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2010-04-14 00:36:03 +04:00
|
|
|
// Because the hidden window is created outside of an event loop,
|
|
|
|
// we need to provide an autorelease pool to avoid leaking cocoa objects
|
|
|
|
// (see bug 559075).
|
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2009-02-06 20:36:04 +03:00
|
|
|
// See NSView (MethodSwizzling) below.
|
2010-02-23 23:10:25 +03:00
|
|
|
if (!gChildViewMethodsSwizzled) {
|
2009-02-06 20:36:04 +03:00
|
|
|
nsToolkit::SwizzleMethods([NSView class], @selector(mouseDownCanMoveWindow),
|
|
|
|
@selector(nsChildView_NSView_mouseDownCanMoveWindow));
|
2011-08-19 00:39:54 +04:00
|
|
|
#ifdef __LP64__
|
2012-05-17 11:53:20 +04:00
|
|
|
if (nsCocoaFeatures::OnLionOrLater()) {
|
2011-08-19 00:39:54 +04:00
|
|
|
nsToolkit::SwizzleMethods([NSEvent class], @selector(addLocalMonitorForEventsMatchingMask:handler:),
|
|
|
|
@selector(nsChildView_NSEvent_addLocalMonitorForEventsMatchingMask:handler:),
|
2011-10-01 04:20:33 +04:00
|
|
|
true);
|
2011-08-19 00:39:54 +04:00
|
|
|
nsToolkit::SwizzleMethods([NSEvent class], @selector(removeMonitor:),
|
2011-10-01 04:20:33 +04:00
|
|
|
@selector(nsChildView_NSEvent_removeMonitor:), true);
|
2011-08-19 00:39:54 +04:00
|
|
|
}
|
|
|
|
#endif
|
2011-01-21 04:08:11 +03:00
|
|
|
#ifndef NP_NO_CARBON
|
2011-02-24 07:48:12 +03:00
|
|
|
TextInputHandler::SwizzleMethods();
|
2011-01-21 04:08:11 +03:00
|
|
|
#endif
|
2011-10-01 04:20:33 +04:00
|
|
|
gChildViewMethodsSwizzled = true;
|
2009-02-06 20:36:04 +03:00
|
|
|
}
|
2008-02-13 18:57:12 +03:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
mBounds = aRect;
|
|
|
|
|
2011-10-25 19:05:32 +04:00
|
|
|
// Ensure that the toolkit is created.
|
|
|
|
nsToolkit::GetToolkit();
|
|
|
|
|
|
|
|
BaseCreate(aParent, aRect, aHandleEventFunction, aContext, aInitData);
|
2001-11-06 18:35:24 +03:00
|
|
|
|
|
|
|
// inherit things from the parent view and create our parallel
|
|
|
|
// NSView in the Cocoa display system
|
2002-02-12 11:30:01 +03:00
|
|
|
mParentView = nil;
|
2006-11-20 08:37:49 +03:00
|
|
|
if (aParent) {
|
2009-09-24 10:18:10 +04:00
|
|
|
// This is the case when we're the popup content view of a popup window.
|
2001-11-09 00:47:44 +03:00
|
|
|
SetBackgroundColor(aParent->GetBackgroundColor());
|
|
|
|
SetForegroundColor(aParent->GetForegroundColor());
|
|
|
|
|
|
|
|
// inherit the top-level window. NS_NATIVE_WIDGET is always a NSView
|
|
|
|
// regardless of if we're asking a window or a view (for compatibility
|
|
|
|
// with windows).
|
2012-06-20 23:48:50 +04:00
|
|
|
mParentView = (NSView<mozView>*)aParent->GetNativeData(NS_NATIVE_WIDGET);
|
2002-12-13 11:43:18 +03:00
|
|
|
mParentWidget = aParent;
|
2009-09-24 10:18:10 +04:00
|
|
|
} else {
|
|
|
|
// This is the normal case. When we're the root widget of the view hiararchy,
|
|
|
|
// aNativeParent will be the contentView of our window, since that's what
|
|
|
|
// nsCocoaWindow returns when asked for an NS_NATIVE_VIEW.
|
2012-06-20 23:48:50 +04:00
|
|
|
mParentView = reinterpret_cast<NSView<mozView>*>(aNativeParent);
|
2009-09-24 10:18:10 +04:00
|
|
|
}
|
2001-11-09 00:47:44 +03:00
|
|
|
|
|
|
|
// create our parallel NSView and hook it up to our parent. Recall
|
|
|
|
// that NS_NATIVE_WIDGET is the NSView.
|
|
|
|
NSRect r;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GeckoRectToNSRect(mBounds, r);
|
2012-06-20 23:48:50 +04:00
|
|
|
mView = [(NSView<mozView>*)CreateCocoaView(r) retain];
|
2002-12-13 11:43:18 +03:00
|
|
|
if (!mView) return NS_ERROR_FAILURE;
|
|
|
|
|
2010-01-24 09:00:39 +03:00
|
|
|
[(ChildView*)mView setIsPluginView:(mWindowType == eWindowType_plugin)];
|
|
|
|
|
2006-05-22 22:15:06 +04:00
|
|
|
// If this view was created in a Gecko view hierarchy, the initial state
|
|
|
|
// is hidden. If the view is attached only to a native NSView but has
|
|
|
|
// no Gecko parent (as in embedding), the initial state is visible.
|
|
|
|
if (mParentWidget)
|
|
|
|
[mView setHidden:YES];
|
|
|
|
else
|
2011-10-01 04:20:33 +04:00
|
|
|
mVisible = true;
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2006-05-22 22:15:06 +04:00
|
|
|
// Hook it up in the NSView hierarchy.
|
|
|
|
if (mParentView) {
|
|
|
|
[mParentView addSubview:mView];
|
2001-11-09 00:47:44 +03:00
|
|
|
}
|
2006-05-22 22:15:06 +04:00
|
|
|
|
2005-06-26 07:25:52 +04:00
|
|
|
// if this is a ChildView, make sure that our per-window data
|
|
|
|
// is set up
|
|
|
|
if ([mView isKindOfClass:[ChildView class]])
|
2009-06-17 22:13:12 +04:00
|
|
|
[[WindowDataMap sharedWindowDataMap] ensureDataForWindow:[mView window]];
|
2005-06-26 07:25:52 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ASSERTION(!mTextInputHandler, "mTextInputHandler has already existed");
|
|
|
|
mTextInputHandler = new TextInputHandler(this, mView);
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2001-11-15 01:29:25 +03:00
|
|
|
// Creates the appropriate child view. Override to create something other than
|
|
|
|
// our |ChildView| object. Autoreleases, so caller must retain.
|
|
|
|
NSView*
|
2005-06-29 23:39:39 +04:00
|
|
|
nsChildView::CreateCocoaView(NSRect inFrame)
|
2001-11-15 01:29:25 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-10-09 22:46:30 +04:00
|
|
|
return [[[ChildView alloc] initWithFrame:inFrame geckoChild:this] autorelease];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2001-11-15 01:29:25 +03:00
|
|
|
}
|
|
|
|
|
2004-02-24 06:40:27 +03:00
|
|
|
void nsChildView::TearDownView()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2006-10-20 03:19:50 +04:00
|
|
|
if (!mView)
|
|
|
|
return;
|
2004-02-24 06:40:27 +03:00
|
|
|
|
2006-10-20 03:19:50 +04:00
|
|
|
NSWindow* win = [mView window];
|
|
|
|
NSResponder* responder = [win firstResponder];
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
|
2006-10-20 03:19:50 +04:00
|
|
|
// We're being unhooked from the view hierarchy, don't leave our view
|
|
|
|
// or a child view as the window first responder.
|
|
|
|
if (responder && [responder isKindOfClass:[NSView class]] &&
|
|
|
|
[(NSView*)responder isDescendantOf:mView]) {
|
2008-01-16 02:11:55 +03:00
|
|
|
[win makeFirstResponder:[mView superview]];
|
2004-02-24 06:40:27 +03:00
|
|
|
}
|
2007-05-30 22:25:44 +04:00
|
|
|
|
|
|
|
// If mView is win's contentView, win (mView's NSWindow) "owns" mView --
|
|
|
|
// win has retained mView, and will detach it from the view hierarchy and
|
|
|
|
// release it when necessary (when win is itself destroyed (in a call to
|
|
|
|
// [win dealloc])). So all we need to do here is call [mView release] (to
|
|
|
|
// match the call to [mView retain] in nsChildView::StandardCreate()).
|
|
|
|
// Also calling [mView removeFromSuperviewWithoutNeedingDisplay] causes
|
|
|
|
// mView to be released again and dealloced, while remaining win's
|
|
|
|
// contentView. So if we do that here, win will (for a short while) have
|
|
|
|
// an invalid contentView (for the consequences see bmo bugs 381087 and
|
|
|
|
// 374260).
|
|
|
|
if ([mView isEqual:[win contentView]]) {
|
|
|
|
[mView release];
|
|
|
|
} else {
|
|
|
|
// Stop NSView hierarchy being changed during [ChildView drawRect:]
|
|
|
|
[mView performSelectorOnMainThread:@selector(delayedTearDown) withObject:nil waitUntilDone:false];
|
|
|
|
}
|
2006-10-20 03:19:50 +04:00
|
|
|
mView = nil;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2004-02-24 06:40:27 +03:00
|
|
|
}
|
2001-11-15 01:29:25 +03:00
|
|
|
|
2009-08-14 02:06:49 +04:00
|
|
|
nsCocoaWindow*
|
|
|
|
nsChildView::GetXULWindowWidget()
|
|
|
|
{
|
2009-09-16 01:56:44 +04:00
|
|
|
id windowDelegate = [[mView window] delegate];
|
2009-08-14 02:06:49 +04:00
|
|
|
if (windowDelegate && [windowDelegate isKindOfClass:[WindowDelegate class]]) {
|
|
|
|
return [(WindowDelegate *)windowDelegate geckoWidget];
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-08-14 02:06:49 +04:00
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
NS_IMETHODIMP nsChildView::Destroy()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2006-01-24 07:01:54 +03:00
|
|
|
if (mOnDestroyCalled)
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2011-10-01 04:20:33 +04:00
|
|
|
mOnDestroyCalled = true;
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2005-09-30 04:59:29 +04:00
|
|
|
[mView widgetDestroyed];
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
nsBaseWidget::Destroy();
|
|
|
|
|
2008-01-16 02:11:55 +03:00
|
|
|
ReportDestroyEvent();
|
2002-12-13 11:43:18 +03:00
|
|
|
mParentWidget = nil;
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2004-02-24 06:40:27 +03:00
|
|
|
TearDownView();
|
|
|
|
|
2009-03-09 19:59:29 +03:00
|
|
|
nsBaseWidget::OnDestroy();
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
2001-11-09 00:47:44 +03:00
|
|
|
|
2006-06-29 05:33:57 +04:00
|
|
|
#if 0
|
2006-12-06 20:04:13 +03:00
|
|
|
static void PrintViewHierarchy(NSView *view)
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2006-10-20 03:19:50 +04:00
|
|
|
while (view) {
|
2006-12-06 20:04:13 +03:00
|
|
|
NSLog(@" view is %x, frame %@", view, NSStringFromRect([view frame]));
|
2005-06-28 03:44:09 +04:00
|
|
|
view = [view superview];
|
|
|
|
}
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
// Return native data according to aDataType
|
2001-11-06 18:35:24 +03:00
|
|
|
void* nsChildView::GetNativeData(PRUint32 aDataType)
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSNULL;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
void* retVal = nullptr;
|
2001-11-06 18:35:24 +03:00
|
|
|
|
|
|
|
switch (aDataType)
|
|
|
|
{
|
2007-09-18 02:55:20 +04:00
|
|
|
case NS_NATIVE_WIDGET:
|
2001-11-09 00:47:44 +03:00
|
|
|
case NS_NATIVE_DISPLAY:
|
2001-11-06 18:35:24 +03:00
|
|
|
retVal = (void*)mView;
|
|
|
|
break;
|
|
|
|
|
2001-11-09 00:47:44 +03:00
|
|
|
case NS_NATIVE_WINDOW:
|
2009-09-16 01:56:44 +04:00
|
|
|
retVal = [mView window];
|
2001-11-09 00:47:44 +03:00
|
|
|
break;
|
2007-09-18 02:55:20 +04:00
|
|
|
|
|
|
|
case NS_NATIVE_GRAPHIC:
|
2009-08-14 18:09:00 +04:00
|
|
|
NS_ERROR("Requesting NS_NATIVE_GRAPHIC on a Mac OS X child view!");
|
2012-07-30 18:20:58 +04:00
|
|
|
retVal = nullptr;
|
2001-11-06 18:35:24 +03:00
|
|
|
break;
|
2007-09-18 02:55:20 +04:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
case NS_NATIVE_OFFSETX:
|
2001-11-19 18:02:23 +03:00
|
|
|
retVal = 0;
|
2001-11-06 18:35:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_OFFSETY:
|
2001-11-19 18:02:23 +03:00
|
|
|
retVal = 0;
|
2001-11-06 18:35:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
2007-03-27 05:07:57 +04:00
|
|
|
case NS_NATIVE_PLUGIN_PORT_QD:
|
|
|
|
case NS_NATIVE_PLUGIN_PORT_CG:
|
|
|
|
{
|
2010-01-24 09:00:39 +03:00
|
|
|
// The NP_CGContext pointer should always be NULL in the Cocoa event model.
|
|
|
|
if ([(ChildView*)mView pluginEventModel] == NPEventModelCocoa)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-03-27 05:07:57 +04:00
|
|
|
|
2009-07-22 12:57:39 +04:00
|
|
|
UpdatePluginPort();
|
2010-06-15 23:34:32 +04:00
|
|
|
#ifndef NP_NO_QUICKDRAW
|
2010-09-17 21:55:39 +04:00
|
|
|
if (aDataType != NS_NATIVE_PLUGIN_PORT_CG) {
|
2009-09-17 05:30:26 +04:00
|
|
|
retVal = (void*)&mPluginQDPort;
|
2010-09-17 21:55:39 +04:00
|
|
|
break;
|
|
|
|
}
|
2010-06-15 23:34:32 +04:00
|
|
|
#endif
|
2010-09-17 21:55:39 +04:00
|
|
|
retVal = (void*)&mPluginCGContext;
|
2002-12-13 11:43:18 +03:00
|
|
|
break;
|
2006-11-22 03:48:57 +03:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2008-08-13 04:44:14 +04:00
|
|
|
nsTransparencyMode nsChildView::GetTransparencyMode()
|
2007-12-19 22:40:18 +03:00
|
|
|
{
|
2009-11-14 01:58:15 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2009-11-14 01:58:15 +03:00
|
|
|
nsCocoaWindow* windowWidget = GetXULWindowWidget();
|
|
|
|
return windowWidget ? windowWidget->GetTransparencyMode() : eTransparencyOpaque;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2009-11-14 01:58:15 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(eTransparencyOpaque);
|
2007-12-19 22:40:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is called by nsContainerFrame on the root widget for all window types
|
2008-08-13 04:44:14 +04:00
|
|
|
// except popup windows (when nsCocoaWindow::SetTransparencyMode is used instead).
|
|
|
|
void nsChildView::SetTransparencyMode(nsTransparencyMode aMode)
|
2007-12-19 22:40:18 +03:00
|
|
|
{
|
2008-08-13 04:44:14 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2009-11-14 01:58:15 +03:00
|
|
|
nsCocoaWindow* windowWidget = GetXULWindowWidget();
|
|
|
|
if (windowWidget) {
|
|
|
|
windowWidget->SetTransparencyMode(aMode);
|
2007-12-19 22:40:18 +03:00
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2008-08-13 04:44:14 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-12-19 22:40:18 +03:00
|
|
|
}
|
|
|
|
|
2012-07-19 12:57:50 +04:00
|
|
|
bool nsChildView::IsVisible() const
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2012-07-19 12:57:50 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2006-08-26 00:36:18 +04:00
|
|
|
if (!mVisible) {
|
2012-07-19 12:57:50 +04:00
|
|
|
return mVisible;
|
2006-08-26 00:36:18 +04:00
|
|
|
}
|
2006-05-22 22:15:06 +04:00
|
|
|
|
2012-07-19 12:57:50 +04:00
|
|
|
// mVisible does not accurately reflect the state of a hidden tabbed view
|
|
|
|
// so verify that the view has a window as well
|
|
|
|
// then check native widget hierarchy visibility
|
|
|
|
return ([mView window] != nil) && !NSIsEmptyRect([mView visibleRect]);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2012-07-19 12:57:50 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2008-04-24 02:56:40 +04:00
|
|
|
void nsChildView::HidePlugin()
|
|
|
|
{
|
2009-09-24 13:32:20 +04:00
|
|
|
NS_ASSERTION(mWindowType == eWindowType_plugin,
|
|
|
|
"HidePlugin called on non-plugin view");
|
2008-04-24 02:56:40 +04:00
|
|
|
|
2010-09-17 21:55:39 +04:00
|
|
|
#ifndef NP_NO_QUICKDRAW
|
|
|
|
if (mPluginInstanceOwner && mView &&
|
|
|
|
[(ChildView*)mView pluginDrawingModel] == NPDrawingModelQuickDraw) {
|
2009-09-17 05:30:26 +04:00
|
|
|
NPWindow* window;
|
2008-04-24 02:56:40 +04:00
|
|
|
mPluginInstanceOwner->GetWindow(window);
|
2011-05-18 05:48:34 +04:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> instance;
|
|
|
|
mPluginInstanceOwner->GetInstance(getter_AddRefs(instance));
|
2008-04-24 02:56:40 +04:00
|
|
|
if (window && instance) {
|
|
|
|
window->clipRect.top = 0;
|
|
|
|
window->clipRect.left = 0;
|
|
|
|
window->clipRect.bottom = 0;
|
|
|
|
window->clipRect.right = 0;
|
|
|
|
instance->SetWindow(window);
|
|
|
|
}
|
|
|
|
}
|
2010-09-17 21:55:39 +04:00
|
|
|
#endif
|
2008-04-24 02:56:40 +04:00
|
|
|
}
|
|
|
|
|
2009-07-22 12:57:39 +04:00
|
|
|
void nsChildView::UpdatePluginPort()
|
|
|
|
{
|
2009-09-24 13:32:20 +04:00
|
|
|
NS_ASSERTION(mWindowType == eWindowType_plugin,
|
|
|
|
"UpdatePluginPort called on non-plugin view");
|
2009-07-22 12:57:39 +04:00
|
|
|
|
2009-09-01 05:00:13 +04:00
|
|
|
#if !defined(NP_NO_CARBON) || !defined(NP_NO_QUICKDRAW)
|
2010-06-15 23:34:32 +04:00
|
|
|
NSWindow* cocoaWindow = [mView window];
|
2009-08-27 04:29:47 +04:00
|
|
|
WindowRef carbonWindow = cocoaWindow ? (WindowRef)[cocoaWindow windowRef] : NULL;
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
2009-08-27 04:29:47 +04:00
|
|
|
|
2010-09-17 21:55:39 +04:00
|
|
|
if (!mView
|
|
|
|
#ifndef NP_NO_QUICKDRAW
|
|
|
|
|| [(ChildView*)mView pluginDrawingModel] != NPDrawingModelQuickDraw
|
|
|
|
#endif
|
|
|
|
) {
|
2009-08-27 04:29:47 +04:00
|
|
|
// [NSGraphicsContext currentContext] is supposed to "return the
|
|
|
|
// current graphics context of the current thread." But sometimes
|
|
|
|
// (when called while mView isn't focused for drawing) it returns a
|
|
|
|
// graphics context for the wrong window. [window graphicsContext]
|
|
|
|
// (which "provides the graphics context associated with the window
|
|
|
|
// for the current thread") seems always to return the "right"
|
|
|
|
// graphics context. See bug 500130.
|
2009-09-17 05:30:26 +04:00
|
|
|
mPluginCGContext.context = NULL;
|
|
|
|
mPluginCGContext.window = NULL;
|
2009-09-01 05:00:13 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2010-01-24 09:00:39 +03:00
|
|
|
if (carbonWindow) {
|
|
|
|
mPluginCGContext.context = (CGContextRef)[[cocoaWindow graphicsContext] graphicsPort];
|
|
|
|
mPluginCGContext.window = carbonWindow;
|
2009-09-01 05:00:13 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifndef NP_NO_QUICKDRAW
|
|
|
|
else {
|
2009-08-27 04:29:47 +04:00
|
|
|
if (carbonWindow) {
|
2009-09-17 05:30:26 +04:00
|
|
|
mPluginQDPort.port = ::GetWindowPort(carbonWindow);
|
2009-07-22 12:57:39 +04:00
|
|
|
|
|
|
|
NSPoint viewOrigin = [mView convertPoint:NSZeroPoint toView:nil];
|
2009-08-27 04:29:47 +04:00
|
|
|
NSRect frame = [[cocoaWindow contentView] frame];
|
2009-07-22 12:57:39 +04:00
|
|
|
viewOrigin.y = frame.size.height - viewOrigin.y;
|
|
|
|
|
|
|
|
// need to convert view's origin to window coordinates.
|
|
|
|
// then, encode as "SetOrigin" ready values.
|
2009-09-17 05:30:26 +04:00
|
|
|
mPluginQDPort.portx = (PRInt32)-viewOrigin.x;
|
|
|
|
mPluginQDPort.porty = (PRInt32)-viewOrigin.y;
|
2009-07-22 12:57:39 +04:00
|
|
|
} else {
|
2009-09-17 05:30:26 +04:00
|
|
|
mPluginQDPort.port = NULL;
|
2009-07-22 12:57:39 +04:00
|
|
|
}
|
|
|
|
}
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
2009-07-22 12:57:39 +04:00
|
|
|
}
|
|
|
|
|
2008-04-24 02:56:40 +04:00
|
|
|
static void HideChildPluginViews(NSView* aView)
|
|
|
|
{
|
|
|
|
NSArray* subviews = [aView subviews];
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < [subviews count]; ++i) {
|
|
|
|
NSView* view = [subviews objectAtIndex: i];
|
|
|
|
|
|
|
|
if (![view isKindOfClass:[ChildView class]])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ChildView* childview = static_cast<ChildView*>(view);
|
|
|
|
if ([childview isPluginView]) {
|
|
|
|
nsChildView* widget = static_cast<nsChildView*>([childview widget]);
|
|
|
|
if (widget) {
|
|
|
|
widget->HidePlugin();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
HideChildPluginViews(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
// Hide or show this component
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsChildView::Show(bool aState)
|
2006-05-22 22:15:06 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2006-05-22 22:15:06 +04:00
|
|
|
if (aState != mVisible) {
|
2010-04-14 00:36:03 +04:00
|
|
|
// Provide an autorelease pool because this gets called during startup
|
|
|
|
// on the "hidden window", resulting in cocoa object leakage if there's
|
|
|
|
// no pool in place.
|
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2006-05-22 22:15:06 +04:00
|
|
|
[mView setHidden:!aState];
|
|
|
|
mVisible = aState;
|
2010-09-07 21:20:03 +04:00
|
|
|
if (!mVisible && IsPluginView())
|
|
|
|
HidePlugin();
|
2002-02-12 11:30:01 +03:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2009-04-23 19:54:50 +04:00
|
|
|
// Change the parent of this widget
|
2008-10-29 08:19:42 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChildView::SetParent(nsIWidget* aNewParent)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
if (mOnDestroyCalled)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
|
2011-11-22 00:15:38 +04:00
|
|
|
if (mParentWidget) {
|
2008-10-29 08:19:42 +03:00
|
|
|
mParentWidget->RemoveChild(this);
|
2011-11-22 00:15:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aNewParent) {
|
|
|
|
ReparentNativeWidget(aNewParent);
|
|
|
|
} else {
|
|
|
|
[mView removeFromSuperview];
|
|
|
|
mParentView = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
mParentWidget = aNewParent;
|
2010-09-18 15:28:50 +04:00
|
|
|
|
2011-11-22 00:15:38 +04:00
|
|
|
if (mParentWidget) {
|
|
|
|
mParentWidget->AddChild(this);
|
|
|
|
}
|
2010-09-18 15:28:50 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2011-11-22 00:15:38 +04:00
|
|
|
|
2010-09-18 15:28:50 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChildView::ReparentNativeWidget(nsIWidget* aNewParent)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
NS_PRECONDITION(aNewParent, "");
|
|
|
|
|
|
|
|
if (mOnDestroyCalled)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NSView<mozView>* newParentView =
|
2012-06-20 23:48:50 +04:00
|
|
|
(NSView<mozView>*)aNewParent->GetNativeData(NS_NATIVE_WIDGET);
|
2010-09-18 15:28:50 +04:00
|
|
|
NS_ENSURE_TRUE(newParentView, NS_ERROR_FAILURE);
|
|
|
|
|
2008-10-29 08:19:42 +03:00
|
|
|
// we hold a ref to mView, so this is safe
|
|
|
|
[mView removeFromSuperview];
|
2011-11-22 00:15:38 +04:00
|
|
|
mParentView = newParentView;
|
2008-10-29 08:19:42 +03:00
|
|
|
[mParentView addSubview:mView];
|
|
|
|
return NS_OK;
|
2010-09-18 15:28:50 +04:00
|
|
|
|
2008-10-29 08:19:42 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
2006-12-20 05:13:57 +03:00
|
|
|
|
2009-04-23 19:54:50 +04:00
|
|
|
void nsChildView::ResetParent()
|
|
|
|
{
|
|
|
|
if (!mOnDestroyCalled) {
|
|
|
|
if (mParentWidget)
|
|
|
|
mParentWidget->RemoveChild(this);
|
|
|
|
if (mView)
|
|
|
|
[mView removeFromSuperview];
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mParentWidget = nullptr;
|
2009-04-23 19:54:50 +04:00
|
|
|
}
|
|
|
|
|
2008-10-21 18:56:35 +04:00
|
|
|
nsIWidget*
|
2010-04-26 00:58:03 +04:00
|
|
|
nsChildView::GetParent()
|
2002-02-12 11:30:01 +03:00
|
|
|
{
|
2002-12-13 11:43:18 +03:00
|
|
|
return mParentWidget;
|
2002-02-12 11:30:01 +03:00
|
|
|
}
|
2006-12-20 05:13:57 +03:00
|
|
|
|
2010-08-13 13:57:55 +04:00
|
|
|
float
|
|
|
|
nsChildView::GetDPI()
|
|
|
|
{
|
|
|
|
NSWindow* window = [mView window];
|
2010-08-19 13:35:08 +04:00
|
|
|
if (window && [window isKindOfClass:[BaseWindow class]]) {
|
|
|
|
return [(BaseWindow*)window getDPI];
|
|
|
|
}
|
|
|
|
|
|
|
|
return 96.0;
|
2010-08-13 13:57:55 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsChildView::Enable(bool aState)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-23 09:19:08 +04:00
|
|
|
bool nsChildView::IsEnabled() const
|
2002-03-01 02:10:04 +03:00
|
|
|
{
|
2012-07-23 09:19:08 +04:00
|
|
|
return true;
|
2002-03-01 02:10:04 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsChildView::SetFocus(bool aRaise)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2010-09-07 21:20:03 +04:00
|
|
|
NSWindow* window = [mView window];
|
|
|
|
if (window)
|
|
|
|
[window makeFirstResponder:mView];
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Override to set the cursor on the mac
|
2005-09-30 04:59:29 +04:00
|
|
|
NS_IMETHODIMP nsChildView::SetCursor(nsCursor aCursor)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2010-03-08 15:35:25 +03:00
|
|
|
if ([mView isDragInProgress])
|
|
|
|
return NS_OK; // Don't change the cursor during dragging.
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
nsBaseWidget::SetCursor(aCursor);
|
2010-03-11 19:44:31 +03:00
|
|
|
return [[nsCursorManager sharedInstance] setCursor:aCursor];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2005-09-30 04:59:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// implement to fix "hidden virtual function" warning
|
|
|
|
NS_IMETHODIMP nsChildView::SetCursor(imgIContainer* aCursor,
|
|
|
|
PRUint32 aHotspotX, PRUint32 aHotspotY)
|
|
|
|
{
|
2010-03-11 19:44:31 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
nsBaseWidget::SetCursor(aCursor, aHotspotX, aHotspotY);
|
|
|
|
return [[nsCursorManager sharedInstance] setCursorWithImage:aCursor hotSpotX:aHotspotX hotSpotY:aHotspotY];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2005-09-30 04:59:29 +04:00
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
#pragma mark -
|
2006-12-20 05:13:57 +03:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
// Get this component dimension
|
2009-01-15 06:27:09 +03:00
|
|
|
NS_IMETHODIMP nsChildView::GetBounds(nsIntRect &aRect)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2010-09-16 20:30:28 +04:00
|
|
|
if (!mView) {
|
|
|
|
aRect = mBounds;
|
|
|
|
} else {
|
|
|
|
NSRect frame = [mView frame];
|
|
|
|
NSRectToGeckoRect(frame, aRect);
|
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsChildView::ConstrainPosition(bool aAllowSlop,
|
2002-01-09 04:29:18 +03:00
|
|
|
PRInt32 *aX, PRInt32 *aY)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
// Move this component, aX and aY are in the parent widget coordinate system
|
2001-11-06 18:35:24 +03:00
|
|
|
NS_IMETHODIMP nsChildView::Move(PRInt32 aX, PRInt32 aY)
|
2002-04-06 23:50:30 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-11-07 10:36:10 +03:00
|
|
|
if (!mView || (mBounds.x == aX && mBounds.y == aY))
|
|
|
|
return NS_OK;
|
2002-04-06 23:50:30 +04:00
|
|
|
|
2007-11-07 10:36:10 +03:00
|
|
|
mBounds.x = aX;
|
|
|
|
mBounds.y = aY;
|
2006-12-20 05:13:57 +03:00
|
|
|
|
2007-11-07 10:36:10 +03:00
|
|
|
NSRect r;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GeckoRectToNSRect(mBounds, r);
|
2007-11-07 10:36:10 +03:00
|
|
|
[mView setFrame:r];
|
2002-02-12 11:30:01 +03:00
|
|
|
|
2007-11-07 10:36:10 +03:00
|
|
|
if (mVisible)
|
|
|
|
[mView setNeedsDisplay:YES];
|
|
|
|
|
2012-06-23 05:13:56 +04:00
|
|
|
NotifyRollupGeometryChange(gRollupListener);
|
2007-11-07 10:36:10 +03:00
|
|
|
ReportMoveEvent();
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsChildView::Resize(PRInt32 aWidth, PRInt32 aHeight, bool aRepaint)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-11-07 10:36:10 +03:00
|
|
|
if (!mView || (mBounds.width == aWidth && mBounds.height == aHeight))
|
|
|
|
return NS_OK;
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2007-11-07 10:36:10 +03:00
|
|
|
mBounds.width = aWidth;
|
|
|
|
mBounds.height = aHeight;
|
2002-02-12 11:30:01 +03:00
|
|
|
|
2007-11-07 10:36:10 +03:00
|
|
|
NSRect r;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GeckoRectToNSRect(mBounds, r);
|
2007-11-07 10:36:10 +03:00
|
|
|
[mView setFrame:r];
|
|
|
|
|
|
|
|
if (mVisible && aRepaint)
|
|
|
|
[mView setNeedsDisplay:YES];
|
|
|
|
|
2012-06-23 05:13:56 +04:00
|
|
|
NotifyRollupGeometryChange(gRollupListener);
|
2007-11-07 10:36:10 +03:00
|
|
|
ReportSizeEvent();
|
2001-11-06 18:35:24 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsChildView::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, bool aRepaint)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-11-07 10:36:10 +03:00
|
|
|
BOOL isMoving = (mBounds.x != aX || mBounds.y != aY);
|
|
|
|
BOOL isResizing = (mBounds.width != aWidth || mBounds.height != aHeight);
|
|
|
|
if (!mView || (!isMoving && !isResizing))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (isMoving) {
|
|
|
|
mBounds.x = aX;
|
|
|
|
mBounds.y = aY;
|
|
|
|
}
|
|
|
|
if (isResizing) {
|
|
|
|
mBounds.width = aWidth;
|
|
|
|
mBounds.height = aHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSRect r;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GeckoRectToNSRect(mBounds, r);
|
2007-11-07 10:36:10 +03:00
|
|
|
[mView setFrame:r];
|
|
|
|
|
|
|
|
if (mVisible && aRepaint)
|
|
|
|
[mView setNeedsDisplay:YES];
|
|
|
|
|
2012-06-23 05:13:56 +04:00
|
|
|
NotifyRollupGeometryChange(gRollupListener);
|
2008-01-16 02:11:55 +03:00
|
|
|
if (isMoving) {
|
2007-11-07 10:36:10 +03:00
|
|
|
ReportMoveEvent();
|
2008-01-16 02:11:55 +03:00
|
|
|
if (mOnDestroyCalled)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-11-07 10:36:10 +03:00
|
|
|
if (isResizing)
|
|
|
|
ReportSizeEvent();
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2008-08-08 20:11:54 +04:00
|
|
|
static const PRInt32 resizeIndicatorWidth = 15;
|
|
|
|
static const PRInt32 resizeIndicatorHeight = 15;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsChildView::ShowsResizeIndicator(nsIntRect* aResizerRect)
|
2008-08-08 20:11:54 +04:00
|
|
|
{
|
|
|
|
NSView *topLevelView = mView, *superView = nil;
|
2008-08-20 08:23:19 +04:00
|
|
|
while ((superView = [topLevelView superview]))
|
2008-08-08 20:11:54 +04:00
|
|
|
topLevelView = superView;
|
|
|
|
|
2009-09-08 01:52:59 +04:00
|
|
|
if (![[topLevelView window] showsResizeIndicator] ||
|
|
|
|
!([[topLevelView window] styleMask] & NSResizableWindowMask))
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2008-08-08 20:11:54 +04:00
|
|
|
|
|
|
|
if (aResizerRect) {
|
|
|
|
NSSize bounds = [topLevelView bounds].size;
|
|
|
|
NSPoint corner = NSMakePoint(bounds.width, [topLevelView isFlipped] ? bounds.height : 0);
|
|
|
|
corner = [topLevelView convertPoint:corner toView:mView];
|
|
|
|
aResizerRect->SetRect(NSToIntRound(corner.x) - resizeIndicatorWidth,
|
|
|
|
NSToIntRound(corner.y) - resizeIndicatorHeight,
|
|
|
|
resizeIndicatorWidth, resizeIndicatorHeight);
|
|
|
|
}
|
2011-10-01 04:20:33 +04:00
|
|
|
return true;
|
2008-08-08 20:11:54 +04:00
|
|
|
}
|
|
|
|
|
2009-02-06 02:31:00 +03:00
|
|
|
// In QuickDraw mode the coordinate system used here should be that of the
|
|
|
|
// browser window's content region (defined as everything but the 22-pixel
|
|
|
|
// high titlebar). But in CoreGraphics mode the coordinate system should be
|
|
|
|
// that of the browser window as a whole (including its titlebar). Both
|
|
|
|
// coordinate systems have a top-left origin. See bmo bug 474491.
|
|
|
|
//
|
|
|
|
// There's a bug in this method's code -- it currently uses the QuickDraw
|
|
|
|
// coordinate system for both the QuickDraw and CoreGraphics drawing modes.
|
|
|
|
// This bug is fixed by the patch for bug 474491. But the Flash plugin (both
|
|
|
|
// version 10.0.12.36 from Adobe and version 9.0 r151 from Apple) has Mozilla-
|
|
|
|
// specific code to work around this bug, which breaks when we fix it (see bmo
|
|
|
|
// bug 477077). So we'll need to coordinate releasing a fix for this bug with
|
|
|
|
// Adobe and other major plugin vendors that support the CoreGraphics mode.
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsChildView::GetPluginClipRect(nsIntRect& outClipRect, nsIntPoint& outOrigin, bool& outWidgetVisible)
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2009-09-24 13:32:20 +04:00
|
|
|
NS_ASSERTION(mWindowType == eWindowType_plugin,
|
|
|
|
"GetPluginClipRect must only be called on a plugin widget");
|
|
|
|
if (mWindowType != eWindowType_plugin) return NS_ERROR_FAILURE;
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2009-09-16 01:56:44 +04:00
|
|
|
NSWindow* window = [mView window];
|
2002-12-13 11:43:18 +03:00
|
|
|
if (!window) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NSPoint viewOrigin = [mView convertPoint:NSZeroPoint toView:nil];
|
2009-02-06 02:05:53 +03:00
|
|
|
NSRect frame = [[window contentView] frame];
|
2002-12-13 11:43:18 +03:00
|
|
|
viewOrigin.y = frame.size.height - viewOrigin.y;
|
|
|
|
|
|
|
|
// set up the clipping region for plugins.
|
|
|
|
NSRect visibleBounds = [mView visibleRect];
|
|
|
|
NSPoint clipOrigin = [mView convertPoint:visibleBounds.origin toView:nil];
|
|
|
|
|
2009-02-06 02:05:53 +03:00
|
|
|
// Convert from cocoa to QuickDraw coordinates
|
2002-12-13 11:43:18 +03:00
|
|
|
clipOrigin.y = frame.size.height - clipOrigin.y;
|
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
outClipRect.x = NSToIntRound(clipOrigin.x);
|
|
|
|
outClipRect.y = NSToIntRound(clipOrigin.y);
|
2009-07-22 04:44:55 +04:00
|
|
|
|
|
|
|
// need to convert view's origin to window coordinates.
|
|
|
|
// then, encode as "SetOrigin" ready values.
|
|
|
|
outOrigin.x = -NSToIntRound(viewOrigin.x);
|
|
|
|
outOrigin.y = -NSToIntRound(viewOrigin.y);
|
|
|
|
|
2012-07-19 12:57:50 +04:00
|
|
|
if (IsVisible() && [mView window] != nil) {
|
2009-01-15 06:27:09 +03:00
|
|
|
outClipRect.width = NSToIntRound(visibleBounds.origin.x + visibleBounds.size.width) - NSToIntRound(visibleBounds.origin.x);
|
|
|
|
outClipRect.height = NSToIntRound(visibleBounds.origin.y + visibleBounds.size.height) - NSToIntRound(visibleBounds.origin.y);
|
2009-07-22 04:44:55 +04:00
|
|
|
|
|
|
|
if (mClipRects) {
|
|
|
|
nsIntRect clipBounds;
|
2011-03-23 21:46:57 +03:00
|
|
|
for (PRUint32 i = 0; i < mClipRectCount; ++i) {
|
2009-07-22 04:44:55 +04:00
|
|
|
clipBounds.UnionRect(clipBounds, mClipRects[i]);
|
|
|
|
}
|
|
|
|
outClipRect.IntersectRect(outClipRect, clipBounds - outOrigin);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXroc should this be !outClipRect.IsEmpty()?
|
2011-10-01 04:20:33 +04:00
|
|
|
outWidgetVisible = true;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
2006-08-26 00:36:18 +04:00
|
|
|
else {
|
2002-12-13 11:43:18 +03:00
|
|
|
outClipRect.width = 0;
|
|
|
|
outClipRect.height = 0;
|
2011-10-01 04:20:33 +04:00
|
|
|
outWidgetVisible = false;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2010-09-17 21:58:26 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
static void InitializeEventRecord(EventRecord* event, Point* aMousePosition)
|
|
|
|
{
|
|
|
|
memset(event, 0, sizeof(EventRecord));
|
|
|
|
if (aMousePosition) {
|
|
|
|
event->where = *aMousePosition;
|
|
|
|
} else {
|
|
|
|
::GetGlobalMouse(&event->where);
|
|
|
|
}
|
|
|
|
event->when = ::TickCount();
|
|
|
|
event->modifiers = ::GetCurrentKeyModifiers();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void nsChildView::PaintQD()
|
|
|
|
{
|
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
void *pluginPort = this->GetNativeData(NS_NATIVE_PLUGIN_PORT_QD);
|
|
|
|
void *window = ::GetWindowFromPort(static_cast<NP_Port*>(pluginPort)->port);
|
|
|
|
|
|
|
|
NS_SUCCEEDED(StartDrawPlugin());
|
|
|
|
EventRecord updateEvent;
|
2012-07-30 18:20:58 +04:00
|
|
|
InitializeEventRecord(&updateEvent, nullptr);
|
2010-09-17 21:58:26 +04:00
|
|
|
updateEvent.what = updateEvt;
|
|
|
|
updateEvent.message = UInt32(window);
|
|
|
|
|
2011-05-18 05:48:34 +04:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> instance;
|
|
|
|
mPluginInstanceOwner->GetInstance(getter_AddRefs(instance));
|
2010-09-17 21:58:26 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
instance->HandleEvent(&updateEvent, nullptr);
|
2010-09-17 21:58:26 +04:00
|
|
|
EndDrawPlugin();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-12-13 11:43:18 +03:00
|
|
|
NS_IMETHODIMP nsChildView::StartDrawPlugin()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2009-09-24 13:32:20 +04:00
|
|
|
NS_ASSERTION(mWindowType == eWindowType_plugin,
|
|
|
|
"StartDrawPlugin must only be called on a plugin widget");
|
|
|
|
if (mWindowType != eWindowType_plugin) return NS_ERROR_FAILURE;
|
2007-03-27 05:07:57 +04:00
|
|
|
|
2009-09-01 05:00:13 +04:00
|
|
|
// This code is necessary for both Quickdraw and CoreGraphics in 32-bit builds.
|
|
|
|
// See comments below about why. In 64-bit CoreGraphics mode we will not keep
|
|
|
|
// this region up to date, plugins should not depend on it.
|
|
|
|
#ifndef __LP64__
|
2009-09-16 01:56:44 +04:00
|
|
|
NSWindow* window = [mView window];
|
2006-11-20 08:37:49 +03:00
|
|
|
if (!window)
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-08-27 04:29:47 +04:00
|
|
|
|
|
|
|
// In QuickDraw drawing mode, prevent reentrant handling of any plugin event
|
|
|
|
// (this emulates behavior on the 1.8 branch, where only QuickDraw mode is
|
|
|
|
// supported). But in CoreGraphics drawing mode only do this if the current
|
|
|
|
// plugin event isn't an update/paint event. This allows popupcontextmenu()
|
|
|
|
// to work properly from a plugin that supports the Cocoa event model,
|
|
|
|
// without regressing bug 409615. See bug 435041. (StartDrawPlugin() and
|
|
|
|
// EndDrawPlugin() wrap every call to nsIPluginInstance::HandleEvent() --
|
|
|
|
// not just calls that "draw" or paint.)
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isQDPlugin = [(ChildView*)mView pluginDrawingModel] == NPDrawingModelQuickDraw;
|
2010-09-17 21:55:39 +04:00
|
|
|
if (isQDPlugin || mIsDispatchPaint) {
|
2009-08-27 04:29:47 +04:00
|
|
|
if (mPluginDrawing)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2006-11-20 08:37:49 +03:00
|
|
|
// It appears that the WindowRef from which we get the plugin port undergoes the
|
|
|
|
// traditional BeginUpdate/EndUpdate cycle, which, if you recall, sets the visible
|
|
|
|
// region to the intersection of the visible region and the update region. Since
|
|
|
|
// we don't know here if we're being drawn inside a BeginUpdate/EndUpdate pair
|
|
|
|
// (which seem to occur in [NSWindow display]), and we don't want to have the burden
|
|
|
|
// of correctly doing Carbon invalidates of the plugin rect, we manually set the
|
2008-04-08 09:45:06 +04:00
|
|
|
// visible region to be the entire port every time. It is necessary to set up our
|
|
|
|
// window's port even for CoreGraphics plugins, because they may still use Carbon
|
|
|
|
// internally (see bug #420527 for details).
|
2011-06-11 11:12:58 +04:00
|
|
|
//
|
|
|
|
// Don't use this code if any of the QuickDraw APIs it currently requires are
|
|
|
|
// missing (as they probably will be on OS X 10.8 and up).
|
|
|
|
if (::NewRgn && ::GetQDGlobalsThePort && ::GetGWorld && ::SetGWorld &&
|
|
|
|
::IsPortOffscreen && ::GetMainDevice && ::SetOrigin && ::RectRgn &&
|
|
|
|
::SetPortVisibleRegion && ::SetPortClipRegion && ::DisposeRgn) {
|
|
|
|
CGrafPtr port = ::GetWindowPort(WindowRef([window windowRef]));
|
|
|
|
if (isQDPlugin) {
|
|
|
|
port = mPluginQDPort.port;
|
|
|
|
}
|
2008-04-08 09:45:06 +04:00
|
|
|
|
2011-06-11 11:12:58 +04:00
|
|
|
RgnHandle pluginRegion = ::NewRgn();
|
|
|
|
if (pluginRegion) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool portChanged = (port != CGrafPtr(::GetQDGlobalsThePort()));
|
2011-06-11 11:12:58 +04:00
|
|
|
CGrafPtr oldPort;
|
|
|
|
GDHandle oldDevice;
|
2006-11-22 03:48:57 +03:00
|
|
|
|
2011-06-11 11:12:58 +04:00
|
|
|
if (portChanged) {
|
|
|
|
::GetGWorld(&oldPort, &oldDevice);
|
2012-07-30 18:20:58 +04:00
|
|
|
::SetGWorld(port, ::IsPortOffscreen(port) ? nullptr : ::GetMainDevice());
|
2011-06-11 11:12:58 +04:00
|
|
|
}
|
2006-11-22 03:48:57 +03:00
|
|
|
|
2011-06-11 11:12:58 +04:00
|
|
|
::SetOrigin(0, 0);
|
|
|
|
|
|
|
|
nsIntRect clipRect; // this is in native window coordinates
|
|
|
|
nsIntPoint origin;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool visible;
|
2011-06-11 11:12:58 +04:00
|
|
|
GetPluginClipRect(clipRect, origin, visible);
|
2006-11-22 03:48:57 +03:00
|
|
|
|
2011-06-11 11:12:58 +04:00
|
|
|
// XXX if we're not visible, set an empty clip region?
|
|
|
|
Rect pluginRect;
|
|
|
|
ConvertGeckoRectToMacRect(clipRect, pluginRect);
|
|
|
|
|
|
|
|
::RectRgn(pluginRegion, &pluginRect);
|
|
|
|
::SetPortVisibleRegion(port, pluginRegion);
|
|
|
|
::SetPortClipRegion(port, pluginRegion);
|
|
|
|
|
|
|
|
// now set up the origin for the plugin
|
|
|
|
::SetOrigin(origin.x, origin.y);
|
|
|
|
|
|
|
|
::DisposeRgn(pluginRegion);
|
|
|
|
|
|
|
|
if (portChanged) {
|
|
|
|
::SetGWorld(oldPort, oldDevice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Cannot set plugin's visible region -- required QuickDraw APIs are missing!");
|
2006-11-20 08:37:49 +03:00
|
|
|
}
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
2006-11-20 08:37:49 +03:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
mPluginDrawing = true;
|
2006-11-20 08:37:49 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsChildView::EndDrawPlugin()
|
|
|
|
{
|
2009-09-24 13:32:20 +04:00
|
|
|
NS_ASSERTION(mWindowType == eWindowType_plugin,
|
|
|
|
"EndDrawPlugin must only be called on a plugin widget");
|
|
|
|
if (mWindowType != eWindowType_plugin) return NS_ERROR_FAILURE;
|
2007-03-27 05:07:57 +04:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
mPluginDrawing = false;
|
2002-12-13 11:43:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-24 02:56:40 +04:00
|
|
|
NS_IMETHODIMP nsChildView::SetPluginInstanceOwner(nsIPluginInstanceOwner* aInstanceOwner)
|
|
|
|
{
|
|
|
|
mPluginInstanceOwner = aInstanceOwner;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
NS_IMETHODIMP nsChildView::SetPluginEventModel(int inEventModel)
|
|
|
|
{
|
2009-09-01 05:00:13 +04:00
|
|
|
[(ChildView*)mView setPluginEventModel:(NPEventModel)inEventModel];
|
2009-08-27 04:29:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsChildView::GetPluginEventModel(int* outEventModel)
|
|
|
|
{
|
2009-09-01 05:00:13 +04:00
|
|
|
*outEventModel = [(ChildView*)mView pluginEventModel];
|
2009-08-27 04:29:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-17 21:55:39 +04:00
|
|
|
NS_IMETHODIMP nsChildView::SetPluginDrawingModel(int inDrawingModel)
|
|
|
|
{
|
|
|
|
[(ChildView*)mView setPluginDrawingModel:(NPDrawingModel)inDrawingModel];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-10 04:56:17 +04:00
|
|
|
NS_IMETHODIMP nsChildView::StartComplexTextInputForCurrentEvent()
|
|
|
|
{
|
2011-02-24 07:48:12 +03:00
|
|
|
return mTextInputHandler->StartComplexTextInputForCurrentEvent();
|
2010-06-10 04:56:17 +04:00
|
|
|
}
|
|
|
|
|
2008-05-07 09:17:40 +04:00
|
|
|
nsresult nsChildView::SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
|
|
|
|
PRInt32 aNativeKeyCode,
|
|
|
|
PRUint32 aModifierFlags,
|
|
|
|
const nsAString& aCharacters,
|
|
|
|
const nsAString& aUnmodifiedCharacters)
|
2008-05-06 03:01:07 +04:00
|
|
|
{
|
2011-02-23 20:25:11 +03:00
|
|
|
return mTextInputHandler->SynthesizeNativeKeyEvent(aNativeKeyboardLayout,
|
|
|
|
aNativeKeyCode,
|
|
|
|
aModifierFlags,
|
|
|
|
aCharacters,
|
|
|
|
aUnmodifiedCharacters);
|
2008-05-06 03:01:07 +04:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
nsresult nsChildView::SynthesizeNativeMouseEvent(nsIntPoint aPoint,
|
|
|
|
PRUint32 aNativeMessage,
|
|
|
|
PRUint32 aModifierFlags)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
// Move the mouse cursor to the requested position and reconnect it to the mouse.
|
|
|
|
CGWarpMouseCursorPosition(CGPointMake(aPoint.x, aPoint.y));
|
|
|
|
CGAssociateMouseAndMouseCursorPosition(true);
|
|
|
|
|
|
|
|
// aPoint is given with the origin on the top left, but convertScreenToBase
|
|
|
|
// expects a point in a coordinate system that has its origin on the bottom left.
|
|
|
|
NSPoint screenPoint = NSMakePoint(aPoint.x, [[NSScreen mainScreen] frame].size.height - aPoint.y);
|
|
|
|
NSPoint windowPoint = [[mView window] convertScreenToBase:screenPoint];
|
|
|
|
|
2009-10-21 19:09:19 +04:00
|
|
|
NSEvent* event = [NSEvent mouseEventWithType:aNativeMessage
|
|
|
|
location:windowPoint
|
|
|
|
modifierFlags:aModifierFlags
|
|
|
|
timestamp:[NSDate timeIntervalSinceReferenceDate]
|
|
|
|
windowNumber:[[mView window] windowNumber]
|
|
|
|
context:nil
|
|
|
|
eventNumber:0
|
|
|
|
clickCount:1
|
|
|
|
pressure:0.0];
|
2009-09-23 06:31:37 +04:00
|
|
|
|
|
|
|
if (!event)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2011-08-08 18:43:13 +04:00
|
|
|
if ([[mView window] isKindOfClass:[BaseWindow class]]) {
|
|
|
|
// Tracking area events don't end up in their tracking areas when sent
|
|
|
|
// through [NSApp sendEvent:], so pass them directly to the right methods.
|
|
|
|
BaseWindow* window = (BaseWindow*)[mView window];
|
|
|
|
if (aNativeMessage == NSMouseEntered) {
|
|
|
|
[window mouseEntered:event];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aNativeMessage == NSMouseExited) {
|
|
|
|
[window mouseExited:event];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aNativeMessage == NSMouseMoved) {
|
|
|
|
[window mouseMoved:event];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
[NSApp sendEvent:event];
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2008-10-30 08:36:01 +03:00
|
|
|
// First argument has to be an NSMenu representing the application's top-level
|
|
|
|
// menu bar. The returned item is *not* retained.
|
|
|
|
static NSMenuItem* NativeMenuItemWithLocation(NSMenu* menubar, NSString* locationString)
|
|
|
|
{
|
|
|
|
NSArray* indexes = [locationString componentsSeparatedByString:@"|"];
|
2008-06-28 11:55:30 +04:00
|
|
|
unsigned int indexCount = [indexes count];
|
|
|
|
if (indexCount == 0)
|
2008-10-30 08:36:01 +03:00
|
|
|
return nil;
|
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
NSMenu* currentSubmenu = [NSApp mainMenu];
|
2008-10-30 08:36:01 +03:00
|
|
|
for (unsigned int i = 0; i < indexCount; i++) {
|
2008-06-28 11:55:30 +04:00
|
|
|
int targetIndex;
|
|
|
|
// We remove the application menu from consideration for the top-level menu
|
|
|
|
if (i == 0)
|
|
|
|
targetIndex = [[indexes objectAtIndex:i] intValue] + 1;
|
|
|
|
else
|
|
|
|
targetIndex = [[indexes objectAtIndex:i] intValue];
|
|
|
|
int itemCount = [currentSubmenu numberOfItems];
|
|
|
|
if (targetIndex < itemCount) {
|
|
|
|
NSMenuItem* menuItem = [currentSubmenu itemAtIndex:targetIndex];
|
2008-10-30 08:36:01 +03:00
|
|
|
// if this is the last index just return the menu item
|
|
|
|
if (i == (indexCount - 1))
|
|
|
|
return menuItem;
|
|
|
|
// if this is not the last index find the submenu and keep going
|
2008-06-28 11:55:30 +04:00
|
|
|
if ([menuItem hasSubmenu])
|
2008-10-30 08:36:01 +03:00
|
|
|
currentSubmenu = [menuItem submenu];
|
|
|
|
else
|
|
|
|
return nil;
|
2008-06-28 11:55:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-30 08:36:01 +03:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used for testing native menu system structure and event handling.
|
|
|
|
NS_IMETHODIMP nsChildView::ActivateNativeMenuItemAt(const nsAString& indexString)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
NSString* locationString = [NSString stringWithCharacters:indexString.BeginReading() length:indexString.Length()];
|
|
|
|
NSMenuItem* item = NativeMenuItemWithLocation([NSApp mainMenu], locationString);
|
2008-07-28 08:46:33 +04:00
|
|
|
// We can't perform an action on an item with a submenu, that will raise
|
|
|
|
// an obj-c exception.
|
2008-10-30 08:36:01 +03:00
|
|
|
if (item && ![item hasSubmenu]) {
|
|
|
|
NSMenu* parent = [item menu];
|
|
|
|
if (parent) {
|
2008-07-28 08:46:33 +04:00
|
|
|
// NSLog(@"Performing action for native menu item titled: %@\n",
|
|
|
|
// [[currentSubmenu itemAtIndex:targetIndex] title]);
|
2008-10-30 08:36:01 +03:00
|
|
|
[parent performActionForItemAtIndex:[parent indexOfItem:item]];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-06-28 11:55:30 +04:00
|
|
|
}
|
2008-10-30 08:36:01 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2008-07-28 08:46:33 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2008-10-30 08:36:01 +03:00
|
|
|
// Used for testing native menu system structure and event handling.
|
|
|
|
NS_IMETHODIMP nsChildView::ForceUpdateNativeMenuAt(const nsAString& indexString)
|
2008-07-28 08:46:33 +04:00
|
|
|
{
|
2008-10-30 08:36:01 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2009-08-14 02:06:49 +04:00
|
|
|
nsCocoaWindow *widget = GetXULWindowWidget();
|
|
|
|
if (widget) {
|
|
|
|
nsMenuBarX* mb = widget->GetMenuBar();
|
|
|
|
if (mb) {
|
|
|
|
if (indexString.IsEmpty())
|
|
|
|
mb->ForceNativeMenuReload();
|
|
|
|
else
|
|
|
|
mb->ForceUpdateNativeMenuAt(indexString);
|
2008-07-28 08:46:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2008-10-30 08:36:01 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2008-06-28 11:55:30 +04:00
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
#pragma mark -
|
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
#ifdef INVALIDATE_DEBUGGING
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
static Boolean KeyDown(const UInt8 theKey)
|
|
|
|
{
|
|
|
|
KeyMap map;
|
|
|
|
GetKeys(map);
|
|
|
|
return ((*((UInt8 *)map + (theKey >> 3)) >> (theKey & 7)) & 1) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Boolean caps_lock()
|
|
|
|
{
|
|
|
|
return KeyDown(0x39);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blinkRect(Rect* r)
|
|
|
|
{
|
|
|
|
StRegionFromPool oldClip;
|
|
|
|
if (oldClip != NULL)
|
|
|
|
::GetClip(oldClip);
|
|
|
|
|
|
|
|
::ClipRect(r);
|
|
|
|
::InvertRect(r);
|
|
|
|
UInt32 end = ::TickCount() + 5;
|
|
|
|
while (::TickCount() < end) ;
|
|
|
|
::InvertRect(r);
|
|
|
|
|
|
|
|
if (oldClip != NULL)
|
|
|
|
::SetClip(oldClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blinkRgn(RgnHandle rgn)
|
|
|
|
{
|
|
|
|
StRegionFromPool oldClip;
|
|
|
|
if (oldClip != NULL)
|
|
|
|
::GetClip(oldClip);
|
|
|
|
|
|
|
|
::SetClip(rgn);
|
|
|
|
::InvertRgn(rgn);
|
|
|
|
UInt32 end = ::TickCount() + 5;
|
|
|
|
while (::TickCount() < end) ;
|
|
|
|
::InvertRgn(rgn);
|
|
|
|
|
|
|
|
if (oldClip != NULL)
|
|
|
|
::SetClip(oldClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Invalidate this component's visible area
|
2011-12-24 07:52:21 +04:00
|
|
|
NS_IMETHODIMP nsChildView::Invalidate(const nsIntRect &aRect)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2005-06-16 16:49:43 +04:00
|
|
|
if (!mView || !mVisible)
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2005-06-16 16:49:43 +04:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
NSRect r;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GeckoRectToNSRect(aRect, r);
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2011-12-24 07:52:21 +04:00
|
|
|
if ([NSView focusView]) {
|
2006-09-15 02:39:58 +04:00
|
|
|
// if a view is focussed (i.e. being drawn), then postpone the invalidate so that we
|
|
|
|
// don't lose it.
|
2006-11-09 17:00:08 +03:00
|
|
|
[mView setNeedsPendingDisplayInRect:r];
|
2006-09-15 02:39:58 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
[mView setNeedsDisplayInRect:r];
|
2006-09-11 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-09-29 22:38:39 +04:00
|
|
|
nsChildView::GetShouldAccelerate()
|
|
|
|
{
|
2011-02-08 15:42:06 +03:00
|
|
|
// Don't use OpenGL for transparent windows or for popup windows.
|
|
|
|
if (!mView || ![[mView window] isOpaque] ||
|
|
|
|
[[mView window] isKindOfClass:[PopupWindow class]])
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2010-09-29 22:38:39 +04:00
|
|
|
|
|
|
|
return nsBaseWidget::GetShouldAccelerate();
|
|
|
|
}
|
|
|
|
|
2012-06-13 23:53:11 +04:00
|
|
|
bool
|
|
|
|
nsChildView::UseOffMainThreadCompositing()
|
|
|
|
{
|
|
|
|
// OMTC doesn't work with Basic Layers on OS X right now. Once it works, we'll
|
|
|
|
// still want to disable it for certain kinds of windows (e.g. popups).
|
|
|
|
return nsBaseWidget::UseOffMainThreadCompositing() && GetShouldAccelerate();
|
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
inline PRUint16 COLOR8TOCOLOR16(PRUint8 color8)
|
|
|
|
{
|
|
|
|
// return (color8 == 0xFF ? 0xFFFF : (color8 << 8));
|
|
|
|
return (color8 << 8) | color8; /* (color8 * 257) == (color8 * 0x0101) */
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2009-07-22 04:44:55 +04:00
|
|
|
nsresult nsChildView::ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < aConfigurations.Length(); ++i) {
|
2010-10-11 04:58:21 +04:00
|
|
|
const Configuration& config = aConfigurations[i];
|
|
|
|
nsChildView* child = static_cast<nsChildView*>(config.mChild);
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsWindowType kidType;
|
|
|
|
child->GetWindowType(kidType);
|
|
|
|
#endif
|
|
|
|
NS_ASSERTION(kidType == eWindowType_plugin,
|
|
|
|
"Configured widget is not a plugin type");
|
|
|
|
NS_ASSERTION(child->GetParent() == this,
|
|
|
|
"Configured widget is not a child of the right widget");
|
|
|
|
|
|
|
|
// nsIWidget::Show() doesn't get called on plugin widgets unless we call
|
|
|
|
// it from here. See bug 592563.
|
|
|
|
child->Show(!config.mClipRegion.IsEmpty());
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool repaint = false;
|
2010-10-11 05:49:32 +04:00
|
|
|
#ifndef NP_NO_QUICKDRAW
|
|
|
|
repaint = child->mView &&
|
2010-10-11 04:58:21 +04:00
|
|
|
[(ChildView*)child->mView pluginDrawingModel] == NPDrawingModelQuickDraw;
|
2010-10-11 05:49:32 +04:00
|
|
|
#endif
|
2010-10-11 04:58:21 +04:00
|
|
|
child->Resize(
|
|
|
|
config.mBounds.x, config.mBounds.y,
|
|
|
|
config.mBounds.width, config.mBounds.height,
|
2010-10-11 04:58:21 +04:00
|
|
|
repaint);
|
2010-10-11 04:58:21 +04:00
|
|
|
|
|
|
|
// Store the clip region here in case GetPluginClipRect needs it.
|
|
|
|
child->StoreWindowClipRegion(config.mClipRegion);
|
2009-07-22 04:44:55 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2010-10-11 04:58:21 +04:00
|
|
|
}
|
2009-07-22 04:44:55 +04:00
|
|
|
|
2007-09-20 02:15:48 +04:00
|
|
|
// Invokes callback and ProcessEvent methods on Event Listener object
|
2001-11-06 18:35:24 +03:00
|
|
|
NS_IMETHODIMP nsChildView::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus)
|
|
|
|
{
|
2008-03-13 01:44:45 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
debug_DumpEvent(stdout, event->widget, event, nsCAutoString("something"), 0);
|
|
|
|
#endif
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ASSERTION(!(mTextInputHandler && mTextInputHandler->IsIMEComposing() &&
|
|
|
|
NS_IS_KEY_EVENT(event)),
|
2008-12-06 12:23:55 +03:00
|
|
|
"Any key events should not be fired during IME composing");
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
2006-07-25 22:51:41 +04:00
|
|
|
|
2009-07-01 22:41:34 +04:00
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip = do_QueryInterface(mParentWidget ? mParentWidget : this);
|
2006-10-20 03:19:50 +04:00
|
|
|
if (mParentWidget) {
|
|
|
|
nsWindowType type;
|
|
|
|
mParentWidget->GetWindowType(type);
|
|
|
|
if (type == eWindowType_popup) {
|
2007-08-02 22:43:31 +04:00
|
|
|
// use the parent popup's widget if there is no view
|
2012-07-30 18:20:58 +04:00
|
|
|
void* clientData = nullptr;
|
2007-08-02 22:43:31 +04:00
|
|
|
if (event->widget)
|
|
|
|
event->widget->GetClientData(clientData);
|
2008-01-16 02:11:55 +03:00
|
|
|
if (!clientData)
|
2007-08-02 22:43:31 +04:00
|
|
|
event->widget = mParentWidget;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
}
|
2007-09-20 12:56:42 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool restoreIsDispatchPaint = mIsDispatchPaint;
|
2010-08-15 21:42:09 +04:00
|
|
|
mIsDispatchPaint = mIsDispatchPaint || event->eventStructType == NS_PAINT_EVENT;
|
|
|
|
|
2006-10-20 03:19:50 +04:00
|
|
|
if (mEventCallback)
|
|
|
|
aStatus = (*mEventCallback)(event);
|
2007-09-20 12:56:42 +04:00
|
|
|
|
2010-08-15 21:42:09 +04:00
|
|
|
mIsDispatchPaint = restoreIsDispatchPaint;
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsChildView::DispatchWindowEvent(nsGUIEvent &event)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
return ConvertStatus(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsChildView::ReportDestroyEvent()
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
nsGUIEvent event(true, NS_DESTROY, this);
|
2006-03-29 04:49:15 +04:00
|
|
|
event.time = PR_IntervalNow();
|
2007-07-19 04:56:33 +04:00
|
|
|
return DispatchWindowEvent(event);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsChildView::ReportMoveEvent()
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
nsGUIEvent moveEvent(true, NS_MOVE, this);
|
2007-07-19 04:56:33 +04:00
|
|
|
moveEvent.refPoint.x = mBounds.x;
|
|
|
|
moveEvent.refPoint.y = mBounds.y;
|
|
|
|
moveEvent.time = PR_IntervalNow();
|
|
|
|
return DispatchWindowEvent(moveEvent);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsChildView::ReportSizeEvent()
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
nsSizeEvent sizeEvent(true, NS_SIZE, this);
|
2001-11-06 18:35:24 +03:00
|
|
|
sizeEvent.time = PR_IntervalNow();
|
|
|
|
sizeEvent.windowSize = &mBounds;
|
|
|
|
sizeEvent.mWinWidth = mBounds.width;
|
|
|
|
sizeEvent.mWinHeight = mBounds.height;
|
2007-07-19 04:56:33 +04:00
|
|
|
return DispatchWindowEvent(sizeEvent);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2009-02-19 03:11:49 +03:00
|
|
|
// Return the offset between this child view and the screen.
|
|
|
|
// @return -- widget origin in screen coordinates
|
|
|
|
nsIntPoint nsChildView::WidgetToScreenOffset()
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2009-02-19 03:11:49 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2009-02-19 03:11:49 +03:00
|
|
|
NSPoint temp;
|
|
|
|
temp.x = 0;
|
|
|
|
temp.y = 0;
|
2005-02-08 20:34:09 +03:00
|
|
|
|
2009-02-19 03:11:49 +03:00
|
|
|
// 1. First translate this point into window coords. The returned point is always in
|
2006-09-21 20:22:44 +04:00
|
|
|
// bottom-left coordinates.
|
2009-02-19 03:11:49 +03:00
|
|
|
temp = [mView convertPoint:temp toView:nil];
|
2006-09-21 20:22:44 +04:00
|
|
|
|
|
|
|
// 2. We turn the window-coord rect's origin into screen (still bottom-left) coords.
|
2009-09-16 01:56:44 +04:00
|
|
|
temp = [[mView window] convertBaseToScreen:temp];
|
2005-02-08 20:34:09 +03:00
|
|
|
|
2006-09-21 20:22:44 +04:00
|
|
|
// 3. Since we're dealing in bottom-left coords, we need to make it top-left coords
|
|
|
|
// before we pass it back to Gecko.
|
2009-02-19 03:11:49 +03:00
|
|
|
FlipCocoaScreenCoordinate(temp);
|
2005-02-08 20:34:09 +03:00
|
|
|
|
2009-02-19 03:11:49 +03:00
|
|
|
return nsIntPoint(NSToIntRound(temp.x), NSToIntRound(temp.y));
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2009-02-19 03:11:49 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(nsIntPoint(0,0));
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsChildView::CaptureRollupEvents(nsIRollupListener * aListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoCapture,
|
|
|
|
bool aConsumeRollupEvent)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2006-06-29 05:33:57 +04:00
|
|
|
// this never gets called, only top-level windows can be rollup widgets
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-19 03:18:23 +04:00
|
|
|
NS_IMETHODIMP nsChildView::SetTitle(const nsAString& title)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2007-07-19 04:56:33 +04:00
|
|
|
// child views don't have titles
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-11 06:46:30 +03:00
|
|
|
NS_IMETHODIMP nsChildView::GetAttention(PRInt32 aCycleCount)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2006-07-11 23:51:56 +04:00
|
|
|
[NSApp requestUserAttention:NSInformationalRequest];
|
2001-11-06 18:35:24 +03:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2009-04-22 03:53:52 +04:00
|
|
|
/* static */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsChildView::DoHasPendingInputEvent()
|
2009-04-22 03:53:52 +04:00
|
|
|
{
|
|
|
|
return sLastInputEventCount != GetCurrentInputEventCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
PRUint32 nsChildView::GetCurrentInputEventCount()
|
|
|
|
{
|
|
|
|
// Can't use kCGAnyInputEventType because that updates too rarely for us (and
|
|
|
|
// always in increments of 30+!) and because apparently it's sort of broken
|
|
|
|
// on Tiger. So just go ahead and query the counters we care about.
|
|
|
|
static const CGEventType eventTypes[] = {
|
|
|
|
kCGEventLeftMouseDown,
|
|
|
|
kCGEventLeftMouseUp,
|
|
|
|
kCGEventRightMouseDown,
|
|
|
|
kCGEventRightMouseUp,
|
|
|
|
kCGEventMouseMoved,
|
|
|
|
kCGEventLeftMouseDragged,
|
|
|
|
kCGEventRightMouseDragged,
|
|
|
|
kCGEventKeyDown,
|
|
|
|
kCGEventKeyUp,
|
|
|
|
kCGEventScrollWheel,
|
|
|
|
kCGEventTabletPointer,
|
|
|
|
kCGEventOtherMouseDown,
|
|
|
|
kCGEventOtherMouseUp,
|
|
|
|
kCGEventOtherMouseDragged
|
|
|
|
};
|
|
|
|
|
|
|
|
PRUint32 eventCount = 0;
|
2011-10-11 09:50:08 +04:00
|
|
|
for (PRUint32 i = 0; i < ArrayLength(eventTypes); ++i) {
|
2009-04-22 03:53:52 +04:00
|
|
|
eventCount +=
|
|
|
|
CGEventSourceCounterForEventType(kCGEventSourceStateCombinedSessionState,
|
|
|
|
eventTypes[i]);
|
|
|
|
}
|
|
|
|
return eventCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void nsChildView::UpdateCurrentInputEventCount()
|
|
|
|
{
|
|
|
|
sLastInputEventCount = GetCurrentInputEventCount();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsChildView::HasPendingInputEvent()
|
2009-04-22 03:53:52 +04:00
|
|
|
{
|
|
|
|
return DoHasPendingInputEvent();
|
|
|
|
}
|
2006-12-20 05:13:57 +03:00
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
#pragma mark -
|
|
|
|
|
2009-01-12 02:51:40 +03:00
|
|
|
// Force Input Method Editor to commit the uncommitted input
|
2008-07-14 06:56:18 +04:00
|
|
|
// Note that this and other IME methods don't necessarily
|
2005-07-25 19:56:25 +04:00
|
|
|
// get called on the same ChildView that input is going through.
|
2001-11-06 18:35:24 +03:00
|
|
|
NS_IMETHODIMP nsChildView::ResetInputState()
|
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
mTextInputHandler->CommitIMEComposition();
|
2005-06-26 07:25:52 +04:00
|
|
|
return NS_OK;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsChildView::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2005-08-23 18:32:09 +04:00
|
|
|
{
|
2011-11-27 15:51:52 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, );
|
2011-11-27 15:51:52 +04:00
|
|
|
mInputContext = aContext;
|
2011-11-27 15:51:53 +04:00
|
|
|
switch (aContext.mIMEState.mEnabled) {
|
|
|
|
case IMEState::ENABLED:
|
|
|
|
case IMEState::PLUGIN:
|
2011-10-01 04:20:33 +04:00
|
|
|
mTextInputHandler->SetASCIICapableOnly(false);
|
|
|
|
mTextInputHandler->EnableIME(true);
|
2011-11-27 15:51:53 +04:00
|
|
|
if (mInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE) {
|
|
|
|
mTextInputHandler->SetIMEOpenState(
|
|
|
|
mInputContext.mIMEState.mOpen == IMEState::OPEN);
|
|
|
|
}
|
2007-04-15 17:43:55 +04:00
|
|
|
break;
|
2011-11-27 15:51:53 +04:00
|
|
|
case IMEState::DISABLED:
|
2011-10-01 04:20:33 +04:00
|
|
|
mTextInputHandler->SetASCIICapableOnly(false);
|
|
|
|
mTextInputHandler->EnableIME(false);
|
2007-04-15 17:43:55 +04:00
|
|
|
break;
|
2011-11-27 15:51:53 +04:00
|
|
|
case IMEState::PASSWORD:
|
2011-10-01 04:20:33 +04:00
|
|
|
mTextInputHandler->SetASCIICapableOnly(true);
|
|
|
|
mTextInputHandler->EnableIME(false);
|
2007-04-15 17:43:55 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("not implemented!");
|
|
|
|
}
|
2005-08-23 18:32:09 +04:00
|
|
|
}
|
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsChildView::GetInputContext()
|
2005-08-23 18:32:09 +04:00
|
|
|
{
|
2011-11-27 15:51:53 +04:00
|
|
|
switch (mInputContext.mIMEState.mEnabled) {
|
|
|
|
case IMEState::ENABLED:
|
|
|
|
case IMEState::PLUGIN:
|
|
|
|
if (mTextInputHandler) {
|
|
|
|
mInputContext.mIMEState.mOpen =
|
|
|
|
mTextInputHandler->IsIMEOpened() ? IMEState::OPEN : IMEState::CLOSED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// If mTextInputHandler is null, set CLOSED instead...
|
|
|
|
default:
|
|
|
|
mInputContext.mIMEState.mOpen = IMEState::CLOSED;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-27 15:51:52 +04:00
|
|
|
return mInputContext;
|
2005-08-23 18:32:09 +04:00
|
|
|
}
|
|
|
|
|
2005-06-26 07:25:52 +04:00
|
|
|
// Destruct and don't commit the IME composition string.
|
2004-11-13 14:27:09 +03:00
|
|
|
NS_IMETHODIMP nsChildView::CancelIMEComposition()
|
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
mTextInputHandler->CancelIMEComposition();
|
2004-12-29 21:27:46 +03:00
|
|
|
return NS_OK;
|
2004-11-13 14:27:09 +03:00
|
|
|
}
|
|
|
|
|
2007-06-16 23:19:46 +04:00
|
|
|
NS_IMETHODIMP nsChildView::GetToggledKeyState(PRUint32 aKeyCode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aLEDState)
|
2007-06-16 23:19:46 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-06-16 23:19:46 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aLEDState);
|
|
|
|
PRUint32 key;
|
|
|
|
switch (aKeyCode) {
|
|
|
|
case NS_VK_CAPS_LOCK:
|
|
|
|
key = alphaLock;
|
|
|
|
break;
|
|
|
|
case NS_VK_NUM_LOCK:
|
|
|
|
key = kEventKeyModifierNumLockMask;
|
|
|
|
break;
|
|
|
|
// Mac doesn't support SCROLL_LOCK state.
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2009-09-26 00:10:04 +04:00
|
|
|
PRUint32 modifierFlags = ::GetCurrentKeyModifiers();
|
2007-06-16 23:19:46 +04:00
|
|
|
*aLEDState = (modifierFlags & key) != 0;
|
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-06-16 23:19:46 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsChildView::OnIMEFocusChange(bool aFocus)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
mTextInputHandler->OnFocusChangeInGecko(aFocus);
|
2009-10-01 06:52:50 +04:00
|
|
|
// XXX Return NS_ERROR_NOT_IMPLEMENTED, see bug 496360.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSView<mozView>* nsChildView::GetEditorView()
|
|
|
|
{
|
|
|
|
NSView<mozView>* editorView = mView;
|
|
|
|
// We need to get editor's view. E.g., when the focus is in the bookmark
|
|
|
|
// dialog, the view is <panel> element of the dialog. At this time, the key
|
|
|
|
// events are processed the parent window's view that has native focus.
|
2011-10-01 04:20:33 +04:00
|
|
|
nsQueryContentEvent textContent(true, NS_QUERY_TEXT_CONTENT, this);
|
2009-10-01 06:52:50 +04:00
|
|
|
textContent.InitForQueryTextContent(0, 0);
|
|
|
|
DispatchWindowEvent(textContent);
|
|
|
|
if (textContent.mSucceeded && textContent.mReply.mFocusedWidget) {
|
|
|
|
NSView<mozView>* view = static_cast<NSView<mozView>*>(
|
|
|
|
textContent.mReply.mFocusedWidget->GetNativeData(NS_NATIVE_WIDGET));
|
|
|
|
if (view)
|
|
|
|
editorView = view;
|
|
|
|
}
|
|
|
|
return editorView;
|
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
#pragma mark -
|
|
|
|
|
2012-01-19 18:45:37 +04:00
|
|
|
void
|
|
|
|
nsChildView::CreateCompositor()
|
|
|
|
{
|
|
|
|
nsBaseWidget::CreateCompositor();
|
|
|
|
if (mCompositorChild) {
|
|
|
|
LayerManagerOGL *manager =
|
|
|
|
static_cast<LayerManagerOGL*>(compositor::GetLayerManager(mCompositorParent));
|
|
|
|
|
|
|
|
NSOpenGLContext *glContext =
|
|
|
|
(NSOpenGLContext *) manager->gl()->GetNativeData(GLContext::NativeGLContext);
|
|
|
|
|
|
|
|
[(ChildView *)mView setGLContext:glContext];
|
|
|
|
[(ChildView *)mView setUsingOMTCompositor:true];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 04:31:14 +03:00
|
|
|
gfxASurface*
|
|
|
|
nsChildView::GetThebesSurface()
|
|
|
|
{
|
2006-08-31 02:06:44 +04:00
|
|
|
if (!mTempThebesSurface) {
|
2007-02-09 00:18:08 +03:00
|
|
|
mTempThebesSurface = new gfxQuartzSurface(gfxSize(1, 1), gfxASurface::ImageFormatARGB32);
|
2006-08-31 02:06:44 +04:00
|
|
|
}
|
|
|
|
|
2007-05-17 10:52:35 +04:00
|
|
|
return mTempThebesSurface;
|
2006-02-22 04:31:14 +03:00
|
|
|
}
|
2006-12-19 23:47:53 +03:00
|
|
|
|
2011-02-20 01:23:02 +03:00
|
|
|
static void
|
|
|
|
DrawResizer(CGContextRef aCtx)
|
2011-01-07 23:32:42 +03:00
|
|
|
{
|
2011-02-20 01:23:02 +03:00
|
|
|
CGContextSetShouldAntialias(aCtx, false);
|
2011-02-20 01:22:12 +03:00
|
|
|
CGPoint points[6];
|
|
|
|
points[0] = CGPointMake(13.0f, 4.0f);
|
|
|
|
points[1] = CGPointMake(3.0f, 14.0f);
|
|
|
|
points[2] = CGPointMake(13.0f, 8.0f);
|
|
|
|
points[3] = CGPointMake(7.0f, 14.0f);
|
|
|
|
points[4] = CGPointMake(13.0f, 12.0f);
|
|
|
|
points[5] = CGPointMake(11.0f, 14.0f);
|
2011-02-20 01:23:02 +03:00
|
|
|
CGContextSetRGBStrokeColor(aCtx, 0.00f, 0.00f, 0.00f, 0.15f);
|
|
|
|
CGContextStrokeLineSegments(aCtx, points, 6);
|
2011-02-20 01:22:12 +03:00
|
|
|
|
|
|
|
points[0] = CGPointMake(13.0f, 5.0f);
|
|
|
|
points[1] = CGPointMake(4.0f, 14.0f);
|
|
|
|
points[2] = CGPointMake(13.0f, 9.0f);
|
|
|
|
points[3] = CGPointMake(8.0f, 14.0f);
|
|
|
|
points[4] = CGPointMake(13.0f, 13.0f);
|
|
|
|
points[5] = CGPointMake(12.0f, 14.0f);
|
2011-02-20 01:23:02 +03:00
|
|
|
CGContextSetRGBStrokeColor(aCtx, 0.13f, 0.13f, 0.13f, 0.54f);
|
|
|
|
CGContextStrokeLineSegments(aCtx, points, 6);
|
2011-02-20 01:22:12 +03:00
|
|
|
|
|
|
|
points[0] = CGPointMake(13.0f, 6.0f);
|
|
|
|
points[1] = CGPointMake(5.0f, 14.0f);
|
|
|
|
points[2] = CGPointMake(13.0f, 10.0f);
|
|
|
|
points[3] = CGPointMake(9.0f, 14.0f);
|
|
|
|
points[5] = CGPointMake(13.0f, 13.9f);
|
|
|
|
points[4] = CGPointMake(13.0f, 14.0f);
|
2011-02-20 01:23:02 +03:00
|
|
|
CGContextSetRGBStrokeColor(aCtx, 0.84f, 0.84f, 0.84f, 0.55f);
|
|
|
|
CGContextStrokeLineSegments(aCtx, points, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-01-22 06:01:17 +04:00
|
|
|
nsChildView::DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect)
|
2011-02-20 01:23:02 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (!ShowsResizeIndicator(nullptr)) {
|
2011-02-20 01:23:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-02-20 01:22:12 +03:00
|
|
|
|
2011-02-20 01:23:02 +03:00
|
|
|
nsRefPtr<LayerManagerOGL> manager(static_cast<LayerManagerOGL*>(aManager));
|
|
|
|
if (!manager) {
|
|
|
|
return;
|
|
|
|
}
|
2011-02-20 01:22:12 +03:00
|
|
|
|
2011-02-20 01:23:02 +03:00
|
|
|
if (!mResizerImage) {
|
|
|
|
mResizerImage = manager->gl()->CreateTextureImage(nsIntSize(15, 15),
|
|
|
|
gfxASurface::CONTENT_COLOR_ALPHA,
|
|
|
|
LOCAL_GL_CLAMP_TO_EDGE,
|
2012-05-10 00:55:31 +04:00
|
|
|
TextureImage::UseNearestFilter);
|
2011-02-20 01:23:02 +03:00
|
|
|
|
|
|
|
// Creation of texture images can fail.
|
|
|
|
if (!mResizerImage)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIntRegion update(nsIntRect(0, 0, 15, 15));
|
|
|
|
gfxASurface *asurf = mResizerImage->BeginUpdate(update);
|
|
|
|
if (!asurf) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mResizerImage = nullptr;
|
2011-02-20 01:23:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(asurf->GetType() == gfxASurface::SurfaceTypeQuartz,
|
|
|
|
"BeginUpdate must return a Quartz surface!");
|
|
|
|
|
|
|
|
nsRefPtr<gfxQuartzSurface> image = static_cast<gfxQuartzSurface*>(asurf);
|
|
|
|
DrawResizer(image->GetCGContext());
|
|
|
|
|
|
|
|
mResizerImage->EndUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(mResizerImage, "Must have a texture allocated by now!");
|
|
|
|
|
|
|
|
float bottomX = aRect.x + aRect.width;
|
|
|
|
float bottomY = aRect.y + aRect.height;
|
|
|
|
|
2011-07-06 22:00:47 +04:00
|
|
|
TextureImage::ScopedBindTexture texBind(mResizerImage, LOCAL_GL_TEXTURE0);
|
2011-02-20 01:22:12 +03:00
|
|
|
|
2012-03-19 00:07:25 +04:00
|
|
|
ShaderProgramOGL *program =
|
|
|
|
manager->GetProgram(mResizerImage->GetShaderProgramType());
|
2011-02-20 01:22:12 +03:00
|
|
|
program->Activate();
|
|
|
|
program->SetLayerQuadRect(nsIntRect(bottomX - 15,
|
|
|
|
bottomY - 15,
|
|
|
|
15,
|
|
|
|
15));
|
|
|
|
program->SetLayerTransform(gfx3DMatrix());
|
|
|
|
program->SetLayerOpacity(1.0);
|
|
|
|
program->SetRenderOffset(nsIntPoint(0,0));
|
|
|
|
program->SetTextureUnit(0);
|
|
|
|
|
|
|
|
manager->BindAndDrawQuad(program);
|
2011-01-07 23:32:42 +03:00
|
|
|
}
|
|
|
|
|
2011-01-11 16:03:16 +03:00
|
|
|
void
|
|
|
|
nsChildView::UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries)
|
|
|
|
{
|
|
|
|
NSWindow* win = [mView window];
|
|
|
|
if (!win || ![win isKindOfClass:[ToolbarWindow class]])
|
|
|
|
return;
|
|
|
|
|
|
|
|
float unifiedToolbarHeight = 0;
|
|
|
|
nsIntRect topPixelStrip(0, 0, [win frame].size.width, 1);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < aThemeGeometries.Length(); ++i) {
|
|
|
|
const ThemeGeometry& g = aThemeGeometries[i];
|
|
|
|
if ((g.mWidgetType == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR ||
|
|
|
|
g.mWidgetType == NS_THEME_TOOLBAR) &&
|
|
|
|
g.mRect.Contains(topPixelStrip)) {
|
|
|
|
unifiedToolbarHeight = g.mRect.YMost();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[(ToolbarWindow*)win setUnifiedToolbarHeight:unifiedToolbarHeight];
|
|
|
|
}
|
|
|
|
|
2007-09-27 20:01:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChildView::BeginSecureKeyboardInput()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-09-27 20:01:32 +04:00
|
|
|
nsresult rv = nsBaseWidget::BeginSecureKeyboardInput();
|
2011-02-09 22:00:58 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-09-27 20:01:32 +04:00
|
|
|
::EnableSecureEventInput();
|
2011-02-09 22:00:58 +03:00
|
|
|
}
|
2007-09-27 20:01:32 +04:00
|
|
|
return rv;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-09-27 20:01:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChildView::EndSecureKeyboardInput()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-09-27 20:01:32 +04:00
|
|
|
nsresult rv = nsBaseWidget::EndSecureKeyboardInput();
|
2011-02-09 22:00:58 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-09-27 20:01:32 +04:00
|
|
|
::DisableSecureEventInput();
|
2011-02-09 22:00:58 +03:00
|
|
|
}
|
2007-09-27 20:01:32 +04:00
|
|
|
return rv;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-09-27 20:01:32 +04:00
|
|
|
}
|
|
|
|
|
2006-09-11 19:47:35 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-05-29 05:18:45 +04:00
|
|
|
already_AddRefed<Accessible>
|
2010-05-12 10:47:35 +04:00
|
|
|
nsChildView::GetDocumentAccessible()
|
2006-09-11 19:47:35 +04:00
|
|
|
{
|
2012-06-07 04:26:45 +04:00
|
|
|
if (!mozilla::a11y::ShouldA11yBeEnabled())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-06-07 04:26:45 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible *docAccessible = nullptr;
|
2010-05-12 10:47:35 +04:00
|
|
|
if (mAccessible) {
|
|
|
|
CallQueryReferent(mAccessible.get(), &docAccessible);
|
|
|
|
return docAccessible;
|
2006-09-27 11:53:07 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 10:47:35 +04:00
|
|
|
// need to fetch the accessible anew, because it has gone away.
|
|
|
|
nsEventStatus status;
|
2011-10-01 04:20:33 +04:00
|
|
|
nsAccessibleEvent event(true, NS_GETACCESSIBLE, this);
|
2010-05-12 10:47:35 +04:00
|
|
|
DispatchEvent(&event, status);
|
|
|
|
|
|
|
|
// cache the accessible in our weak ptr
|
|
|
|
mAccessible =
|
|
|
|
do_GetWeakReference(static_cast<nsIAccessible*>(event.mAccessible));
|
|
|
|
|
|
|
|
NS_IF_ADDREF(event.mAccessible);
|
|
|
|
return event.mAccessible;
|
2006-09-11 19:47:35 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-04-23 07:55:19 +04:00
|
|
|
#pragma mark -
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
@implementation ChildView
|
|
|
|
|
2006-10-26 02:45:22 +04:00
|
|
|
// globalDragPboard is non-null during native drag sessions that did not originate
|
|
|
|
// in our native NSView (it is set in |draggingEntered:|). It is unset when the
|
|
|
|
// drag session ends for this view, either with the mouse exiting or when a drop
|
|
|
|
// occurs in this view.
|
|
|
|
NSPasteboard* globalDragPboard = nil;
|
|
|
|
|
2009-11-06 13:21:41 +03:00
|
|
|
// gLastDragView and gLastDragMouseDownEvent are used to communicate information
|
|
|
|
// to the drag service during drag invocation (starting a drag in from the view).
|
|
|
|
// gLastDragView is only non-null while mouseDragged is on the call stack.
|
2007-09-24 04:01:04 +04:00
|
|
|
NSView* gLastDragView = nil;
|
2009-11-06 13:21:41 +03:00
|
|
|
NSEvent* gLastDragMouseDownEvent = nil;
|
2006-10-26 02:45:22 +04:00
|
|
|
|
2008-12-15 23:56:29 +03:00
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
static BOOL initialized = NO;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
// Inform the OS about the types of services (from the "Services" menu)
|
|
|
|
// that we can handle.
|
2009-03-18 05:04:01 +03:00
|
|
|
|
|
|
|
NSArray *sendTypes = [[NSArray alloc] initWithObjects:NSStringPboardType,NSHTMLPboardType,nil];
|
2010-01-11 04:45:45 +03:00
|
|
|
NSArray *returnTypes = [[NSArray alloc] initWithObjects:NSStringPboardType,NSHTMLPboardType,nil];
|
|
|
|
|
2008-12-15 23:56:29 +03:00
|
|
|
[NSApp registerServicesMenuSendTypes:sendTypes returnTypes:returnTypes];
|
|
|
|
|
2009-03-18 05:04:01 +03:00
|
|
|
[sendTypes release];
|
|
|
|
[returnTypes release];
|
|
|
|
|
2008-12-15 23:56:29 +03:00
|
|
|
initialized = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-09 22:46:30 +04:00
|
|
|
// initWithFrame:geckoChild:
|
|
|
|
- (id)initWithFrame:(NSRect)inFrame geckoChild:(nsChildView*)inChild
|
2002-03-10 01:43:04 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2006-01-24 07:01:54 +03:00
|
|
|
if ((self = [super initWithFrame:inFrame])) {
|
2005-06-16 16:49:43 +04:00
|
|
|
mGeckoChild = inChild;
|
|
|
|
mIsPluginView = NO;
|
2009-09-01 05:00:13 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
mPluginEventModel = NPEventModelCarbon;
|
|
|
|
#else
|
|
|
|
mPluginEventModel = NPEventModelCocoa;
|
2010-09-17 21:55:39 +04:00
|
|
|
#endif
|
|
|
|
#ifndef NP_NO_QUICKDRAW
|
|
|
|
mPluginDrawingModel = NPDrawingModelQuickDraw;
|
|
|
|
#else
|
|
|
|
mPluginDrawingModel = NPDrawingModelCoreGraphics;
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
2010-06-09 08:11:42 +04:00
|
|
|
mPendingDisplay = NO;
|
2010-07-16 16:48:02 +04:00
|
|
|
mBlockedLastMouseDown = NO;
|
2008-02-29 08:47:41 +03:00
|
|
|
|
2008-04-07 03:52:05 +04:00
|
|
|
mLastMouseDownEvent = nil;
|
2010-07-16 16:48:02 +04:00
|
|
|
mClickThroughMouseDownEvent = nil;
|
2012-07-30 18:20:58 +04:00
|
|
|
mDragService = nullptr;
|
2008-06-30 20:30:22 +04:00
|
|
|
|
2008-10-24 00:15:20 +04:00
|
|
|
mGestureState = eGestureState_None;
|
|
|
|
mCumulativeMagnification = 0.0;
|
|
|
|
mCumulativeRotation = 0.0;
|
2009-09-17 02:06:16 +04:00
|
|
|
|
2011-02-04 00:12:33 +03:00
|
|
|
// We can't call forceRefreshOpenGL here because, in order to work around
|
|
|
|
// the bug, it seems we need to have a draw already happening. Therefore,
|
|
|
|
// we call it in drawRect:inContext:, when we know that a draw is in
|
|
|
|
// progress.
|
|
|
|
mDidForceRefreshOpenGL = NO;
|
|
|
|
|
2009-09-17 02:06:16 +04:00
|
|
|
[self setFocusRingType:NSFocusRingTypeNone];
|
2011-08-11 21:42:23 +04:00
|
|
|
|
|
|
|
#ifdef __LP64__
|
|
|
|
mSwipeAnimationCancelled = nil;
|
|
|
|
#endif
|
2005-06-16 16:49:43 +04:00
|
|
|
}
|
2002-03-10 01:58:13 +03:00
|
|
|
|
2006-10-26 02:45:22 +04:00
|
|
|
// register for things we'll take from other applications
|
2007-07-17 06:24:05 +04:00
|
|
|
PR_LOG(sCocoaLog, PR_LOG_ALWAYS, ("ChildView initWithFrame: registering drag types\n"));
|
2006-10-26 02:45:22 +04:00
|
|
|
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
|
|
|
|
NSStringPboardType,
|
2008-11-07 04:08:35 +03:00
|
|
|
NSHTMLPboardType,
|
2006-10-26 02:45:22 +04:00
|
|
|
NSURLPboardType,
|
2007-07-17 06:24:05 +04:00
|
|
|
NSFilesPromisePboardType,
|
2007-05-29 09:06:12 +04:00
|
|
|
kWildcardPboardType,
|
2007-09-25 02:41:10 +04:00
|
|
|
kCorePboardType_url,
|
2007-09-28 05:50:09 +04:00
|
|
|
kCorePboardType_urld,
|
2007-09-25 02:41:10 +04:00
|
|
|
kCorePboardType_urln,
|
2006-10-26 02:45:22 +04:00
|
|
|
nil]];
|
2010-04-21 10:21:46 +04:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(windowBecameMain:)
|
|
|
|
name:NSWindowDidBecomeMainNotification
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(windowResignedMain:)
|
|
|
|
name:NSWindowDidResignMainNotification
|
|
|
|
object:nil];
|
2008-09-17 20:26:57 +04:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
2008-10-14 17:31:09 +04:00
|
|
|
selector:@selector(systemMetricsChanged)
|
2008-09-17 20:26:57 +04:00
|
|
|
name:NSControlTintDidChangeNotification
|
|
|
|
object:nil];
|
2008-09-22 13:09:32 +04:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
2008-10-14 17:31:09 +04:00
|
|
|
selector:@selector(systemMetricsChanged)
|
2008-09-22 13:09:32 +04:00
|
|
|
name:NSSystemColorsDidChangeNotification
|
|
|
|
object:nil];
|
2008-10-14 17:31:09 +04:00
|
|
|
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(systemMetricsChanged)
|
|
|
|
name:@"AppleAquaScrollBarVariantChanged"
|
|
|
|
object:nil
|
|
|
|
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
|
2010-04-28 02:29:29 +04:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(_surfaceNeedsUpdate:)
|
|
|
|
name:NSViewGlobalFrameDidChangeNotification
|
|
|
|
object:self];
|
2006-10-26 02:45:22 +04:00
|
|
|
|
2005-06-16 16:49:43 +04:00
|
|
|
return self;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2002-03-10 01:43:04 +03:00
|
|
|
}
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
- (void)installTextInputHandler:(TextInputHandler*)aHandler
|
|
|
|
{
|
|
|
|
mTextInputHandler = aHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)uninstallTextInputHandler
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mTextInputHandler = nullptr;
|
2011-05-08 14:19:23 +04:00
|
|
|
}
|
|
|
|
|
2011-02-04 00:12:33 +03:00
|
|
|
// Work around bug 603134.
|
|
|
|
// OS X has a bug that causes new OpenGL windows to only paint once or twice,
|
|
|
|
// then stop painting altogether. By clearing the drawable from the GL context,
|
|
|
|
// and then resetting the view to ourselves, we convince OS X to start updating
|
|
|
|
// again.
|
|
|
|
// This can cause a flash in new windows - bug 631339 - but it's very hard to
|
|
|
|
// fix that while maintaining this workaround.
|
|
|
|
- (void)forceRefreshOpenGL
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
[mGLContext clearDrawable];
|
|
|
|
[mGLContext setView:self];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2012-01-19 18:45:37 +04:00
|
|
|
- (void)setGLContext:(NSOpenGLContext *)aGLContext
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
mGLContext = aGLContext;
|
|
|
|
[mGLContext retain];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2005-06-16 16:49:43 +04:00
|
|
|
- (void)dealloc
|
2002-04-12 13:39:59 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2010-06-18 13:22:01 +04:00
|
|
|
[mGLContext release];
|
2006-11-19 16:59:46 +03:00
|
|
|
[mPendingDirtyRects release];
|
2008-04-07 03:52:05 +04:00
|
|
|
[mLastMouseDownEvent release];
|
2010-07-16 16:48:02 +04:00
|
|
|
[mClickThroughMouseDownEvent release];
|
2009-10-21 11:02:13 +04:00
|
|
|
ChildViewMouseTracker::OnDestroyView(self);
|
2007-09-18 02:55:20 +04:00
|
|
|
|
2008-09-17 20:26:57 +04:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2008-10-14 17:31:09 +04:00
|
|
|
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
|
2008-09-17 20:26:57 +04:00
|
|
|
|
2007-09-18 02:55:20 +04:00
|
|
|
[super dealloc];
|
|
|
|
|
2009-09-01 05:00:13 +04:00
|
|
|
#ifndef NP_NO_QUICKDRAW
|
2007-09-18 02:55:20 +04:00
|
|
|
// This sets the current port to _savePort.
|
|
|
|
// todo: Only do if a Quickdraw plugin is present in the hierarchy!
|
2011-06-11 11:12:58 +04:00
|
|
|
// Check if ::SetPort() is available -- it probably won't be on
|
|
|
|
// OS X 10.8 and up.
|
|
|
|
if (::SetPort) {
|
|
|
|
::SetPort(NULL);
|
|
|
|
}
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2002-04-12 13:39:59 +04:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2010-04-21 10:21:46 +04:00
|
|
|
- (void)updatePluginTopLevelWindowStatus:(BOOL)hasMain
|
|
|
|
{
|
2010-04-26 00:58:03 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
nsPluginEvent pluginEvent(true, NS_PLUGIN_FOCUS_EVENT, mGeckoChild);
|
2010-04-21 10:21:46 +04:00
|
|
|
NPCocoaEvent cocoaEvent;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2010-04-21 10:21:46 +04:00
|
|
|
cocoaEvent.type = NPCocoaEventWindowFocusChanged;
|
|
|
|
cocoaEvent.data.focus.hasFocus = hasMain;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitPluginEvent(pluginEvent, cocoaEvent);
|
2010-04-21 10:21:46 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(pluginEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowBecameMain:(NSNotification*)inNotification
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (mIsPluginView && mPluginEventModel == NPEventModelCocoa) {
|
|
|
|
if ((NSWindow*)[inNotification object] == [self window]) {
|
|
|
|
[self updatePluginTopLevelWindowStatus:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowResignedMain:(NSNotification*)inNotification
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (mIsPluginView && mPluginEventModel == NPEventModelCocoa) {
|
|
|
|
if ((NSWindow*)[inNotification object] == [self window]) {
|
|
|
|
[self updatePluginTopLevelWindowStatus:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2005-09-30 04:59:29 +04:00
|
|
|
- (void)widgetDestroyed
|
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
if (mTextInputHandler) {
|
|
|
|
mTextInputHandler->OnDestroyWidget(mGeckoChild);
|
2012-07-30 18:20:58 +04:00
|
|
|
mTextInputHandler = nullptr;
|
2011-05-08 14:19:23 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mGeckoChild = nullptr;
|
2008-10-22 02:15:08 +04:00
|
|
|
|
2007-10-10 16:19:47 +04:00
|
|
|
// Just in case we're destroyed abruptly and missed the draggingExited
|
|
|
|
// or performDragOperation message.
|
|
|
|
NS_IF_RELEASE(mDragService);
|
2005-09-30 04:59:29 +04:00
|
|
|
}
|
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
// mozView method, return our gecko child view widget. Note this does not AddRef.
|
2005-06-16 16:49:43 +04:00
|
|
|
- (nsIWidget*) widget
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsIWidget*>(mGeckoChild);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2008-10-14 17:31:09 +04:00
|
|
|
- (void)systemMetricsChanged
|
2008-09-17 20:26:57 +04:00
|
|
|
{
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
nsGUIEvent guiEvent(true, NS_THEMECHANGED, mGeckoChild);
|
2008-09-17 20:26:57 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(guiEvent);
|
|
|
|
}
|
|
|
|
|
2006-11-09 17:00:08 +03:00
|
|
|
- (void)setNeedsPendingDisplay
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2006-11-09 17:00:08 +03:00
|
|
|
mPendingFullDisplay = YES;
|
2010-06-09 08:11:42 +04:00
|
|
|
if (!mPendingDisplay) {
|
|
|
|
[self performSelector:@selector(processPendingRedraws) withObject:nil afterDelay:0];
|
|
|
|
mPendingDisplay = YES;
|
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-11-09 17:00:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setNeedsPendingDisplayInRect:(NSRect)invalidRect
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2006-11-09 17:00:08 +03:00
|
|
|
if (!mPendingDirtyRects)
|
|
|
|
mPendingDirtyRects = [[NSMutableArray alloc] initWithCapacity:1];
|
|
|
|
[mPendingDirtyRects addObject:[NSValue valueWithRect:invalidRect]];
|
2010-06-09 08:11:42 +04:00
|
|
|
if (!mPendingDisplay) {
|
|
|
|
[self performSelector:@selector(processPendingRedraws) withObject:nil afterDelay:0];
|
|
|
|
mPendingDisplay = YES;
|
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-11-09 17:00:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clears the queue of any pending invalides
|
|
|
|
- (void)processPendingRedraws
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2006-11-09 17:00:08 +03:00
|
|
|
if (mPendingFullDisplay) {
|
|
|
|
[self setNeedsDisplay:YES];
|
2005-06-16 16:49:43 +04:00
|
|
|
}
|
2010-06-09 08:11:42 +04:00
|
|
|
else if (mPendingDirtyRects) {
|
2006-11-09 17:00:08 +03:00
|
|
|
unsigned int count = [mPendingDirtyRects count];
|
|
|
|
for (unsigned int i = 0; i < count; ++i) {
|
|
|
|
[self setNeedsDisplayInRect:[[mPendingDirtyRects objectAtIndex:i] rectValue]];
|
|
|
|
}
|
2005-06-16 16:49:43 +04:00
|
|
|
}
|
2006-11-09 17:00:08 +03:00
|
|
|
mPendingFullDisplay = NO;
|
2010-06-09 08:11:42 +04:00
|
|
|
mPendingDisplay = NO;
|
2006-11-09 17:00:08 +03:00
|
|
|
[mPendingDirtyRects release];
|
|
|
|
mPendingDirtyRects = nil;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2009-10-21 11:05:39 +04:00
|
|
|
- (void)setNeedsDisplayInRect:(NSRect)aRect
|
|
|
|
{
|
|
|
|
[super setNeedsDisplayInRect:aRect];
|
|
|
|
|
|
|
|
if ([[self window] isKindOfClass:[ToolbarWindow class]]) {
|
|
|
|
ToolbarWindow* window = (ToolbarWindow*)[self window];
|
|
|
|
if ([window drawsContentsIntoWindowFrame]) {
|
|
|
|
// Tell it to mark the rect in the titlebar as dirty.
|
|
|
|
NSView* borderView = [[window contentView] superview];
|
|
|
|
[window setTitlebarNeedsDisplayInRect:[self convertRect:aRect toView:borderView]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 08:51:36 +04:00
|
|
|
- (NSString*)description
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2005-04-13 08:51:36 +04:00
|
|
|
return [NSString stringWithFormat:@"ChildView %p, gecko child %p, frame %@", self, mGeckoChild, NSStringFromRect([self frame])];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2005-04-13 08:51:36 +04:00
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
// Make the origin of this view the topLeft corner (gecko origin) rather
|
|
|
|
// than the bottomLeft corner (standard cocoa origin).
|
|
|
|
- (BOOL)isFlipped
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2002-02-20 04:07:39 +03:00
|
|
|
- (BOOL)isOpaque
|
|
|
|
{
|
2010-09-17 22:04:14 +04:00
|
|
|
return [[self window] isOpaque] && !mIsPluginView;
|
2002-04-27 04:19:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void)setIsPluginView:(BOOL)aIsPlugin
|
|
|
|
{
|
|
|
|
mIsPluginView = aIsPlugin;
|
2002-02-20 04:07:39 +03:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2007-03-27 05:07:57 +04:00
|
|
|
-(BOOL)isPluginView
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
|
|
|
return mIsPluginView;
|
|
|
|
}
|
|
|
|
|
2010-11-16 00:12:50 +03:00
|
|
|
// Are we processing an NSLeftMouseDown event that will fail to click through?
|
|
|
|
// If so, we shouldn't focus or unfocus a plugin.
|
|
|
|
- (BOOL)isInFailingLeftClickThrough
|
|
|
|
{
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
if (!mClickThroughMouseDownEvent ||
|
|
|
|
[mClickThroughMouseDownEvent type] != NSLeftMouseDown)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
BOOL retval =
|
|
|
|
!ChildViewMouseTracker::WindowAcceptsEvent([self window],
|
|
|
|
mClickThroughMouseDownEvent,
|
2011-10-01 04:20:33 +04:00
|
|
|
self, true);
|
2010-11-16 00:12:50 +03:00
|
|
|
|
|
|
|
// If we return YES here, this will result in us not being focused,
|
|
|
|
// which will stop us receiving mClickThroughMouseDownEvent in
|
|
|
|
// [ChildView mouseDown:]. So we need to release and null-out
|
|
|
|
// mClickThroughMouseDownEvent here.
|
|
|
|
if (retval) {
|
|
|
|
[mClickThroughMouseDownEvent release];
|
|
|
|
mClickThroughMouseDownEvent = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-09-01 05:00:13 +04:00
|
|
|
- (void)setPluginEventModel:(NPEventModel)eventModel
|
2009-08-27 04:29:47 +04:00
|
|
|
{
|
2009-09-01 05:00:13 +04:00
|
|
|
mPluginEventModel = eventModel;
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
|
|
|
|
2010-09-17 21:55:39 +04:00
|
|
|
- (void)setPluginDrawingModel:(NPDrawingModel)drawingModel
|
|
|
|
{
|
|
|
|
mPluginDrawingModel = drawingModel;
|
|
|
|
}
|
|
|
|
|
2011-01-21 04:08:11 +03:00
|
|
|
- (NPEventModel)pluginEventModel
|
2009-08-27 04:29:47 +04:00
|
|
|
{
|
2009-09-01 05:00:13 +04:00
|
|
|
return mPluginEventModel;
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
|
|
|
|
2011-01-21 04:08:11 +03:00
|
|
|
- (NPDrawingModel)pluginDrawingModel
|
2010-09-17 21:55:39 +04:00
|
|
|
{
|
|
|
|
return mPluginDrawingModel;
|
|
|
|
}
|
|
|
|
|
2007-08-03 03:01:32 +04:00
|
|
|
- (void)sendFocusEvent:(PRUint32)eventType
|
|
|
|
{
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2011-10-01 04:20:33 +04:00
|
|
|
nsGUIEvent focusGuiEvent(true, eventType, mGeckoChild);
|
2007-08-03 03:01:32 +04:00
|
|
|
focusGuiEvent.time = PR_IntervalNow();
|
|
|
|
mGeckoChild->DispatchEvent(&focusGuiEvent, status);
|
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
// We accept key and mouse events, so don't keep passing them up the chain. Allow
|
2010-04-26 00:58:03 +04:00
|
|
|
// this to be a 'focused' widget for event dispatch.
|
2001-11-06 18:35:24 +03:00
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2010-07-16 16:48:02 +04:00
|
|
|
// Accept mouse down events on background windows
|
|
|
|
- (BOOL)acceptsFirstMouse:(NSEvent*)aEvent
|
|
|
|
{
|
|
|
|
if (![[self window] isKindOfClass:[PopupWindow class]]) {
|
|
|
|
// We rely on this function to tell us that the mousedown was on a
|
|
|
|
// background window. Inside mouseDown we can't tell whether we were
|
|
|
|
// inactive because at that point we've already been made active.
|
|
|
|
// Unfortunately, acceptsFirstMouse is called for PopupWindows even when
|
|
|
|
// their parent window is active, so ignore this on them for now.
|
|
|
|
mClickThroughMouseDownEvent = [aEvent retain];
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2008-11-14 13:24:16 +03:00
|
|
|
- (void)viewWillMoveToWindow:(NSWindow *)newWindow
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (!newWindow)
|
|
|
|
HideChildPluginViews(self);
|
|
|
|
|
|
|
|
[super viewWillMoveToWindow:newWindow];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2009-09-16 01:56:44 +04:00
|
|
|
- (void)viewDidMoveToWindow
|
|
|
|
{
|
2010-01-24 09:00:39 +03:00
|
|
|
if (mPluginEventModel == NPEventModelCocoa &&
|
|
|
|
[self window] && [self isPluginView] && mGeckoChild) {
|
2009-09-16 01:56:44 +04:00
|
|
|
mGeckoChild->UpdatePluginPort();
|
|
|
|
}
|
|
|
|
|
|
|
|
[super viewDidMoveToWindow];
|
|
|
|
}
|
|
|
|
|
2006-11-09 17:00:08 +03:00
|
|
|
- (void)scrollRect:(NSRect)aRect by:(NSSize)offset
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2006-11-09 17:00:08 +03:00
|
|
|
// Update any pending dirty rects to reflect the new scroll position
|
|
|
|
if (mPendingDirtyRects) {
|
|
|
|
unsigned int count = [mPendingDirtyRects count];
|
|
|
|
for (unsigned int i = 0; i < count; ++i) {
|
|
|
|
NSRect oldRect = [[mPendingDirtyRects objectAtIndex:i] rectValue];
|
|
|
|
NSRect newRect = NSOffsetRect(oldRect, offset.width, offset.height);
|
|
|
|
[mPendingDirtyRects replaceObjectAtIndex:i
|
|
|
|
withObject:[NSValue valueWithRect:newRect]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[super scrollRect:aRect by:offset];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-11-09 17:00:08 +03:00
|
|
|
}
|
|
|
|
|
2002-12-13 11:43:18 +03:00
|
|
|
- (BOOL)mouseDownCanMoveWindow
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2005-07-06 23:51:31 +04:00
|
|
|
- (void)lockFocus
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2009-09-09 01:25:55 +04:00
|
|
|
#ifndef NP_NO_QUICKDRAW
|
2005-07-06 23:51:31 +04:00
|
|
|
// Set the current GrafPort to a "safe" port before calling [NSQuickDrawView lockFocus],
|
|
|
|
// so that the NSQuickDrawView stashes a pointer to this known-good port internally.
|
|
|
|
// It will set the port back to this port on destruction.
|
2011-06-11 11:12:58 +04:00
|
|
|
// Check if ::SetPort() is available -- it probably won't be on OS X 10.8 and up.
|
|
|
|
if (::SetPort) {
|
|
|
|
::SetPort(NULL); // todo: only do if a Quickdraw plugin is present in the hierarchy!
|
|
|
|
}
|
2009-09-09 01:25:55 +04:00
|
|
|
#endif
|
|
|
|
|
2005-07-06 23:51:31 +04:00
|
|
|
[super lockFocus];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2010-06-18 13:22:01 +04:00
|
|
|
if (mGLContext) {
|
|
|
|
if ([mGLContext view] != self) {
|
|
|
|
[mGLContext setView:self];
|
2010-04-28 02:29:29 +04:00
|
|
|
}
|
|
|
|
|
2010-06-18 13:22:01 +04:00
|
|
|
[mGLContext makeCurrentContext];
|
2010-04-28 02:29:29 +04:00
|
|
|
}
|
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2005-07-06 23:51:31 +04:00
|
|
|
}
|
|
|
|
|
2010-04-28 02:29:29 +04:00
|
|
|
-(void)update
|
|
|
|
{
|
2010-06-18 13:22:01 +04:00
|
|
|
if (mGLContext) {
|
|
|
|
[mGLContext update];
|
2010-04-28 02:29:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _surfaceNeedsUpdate:(NSNotification*)notification
|
|
|
|
{
|
|
|
|
[self update];
|
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
// The display system has told us that a portion of our view is dirty. Tell
|
|
|
|
// gecko to paint it
|
|
|
|
- (void)drawRect:(NSRect)aRect
|
|
|
|
{
|
2009-10-21 11:05:39 +04:00
|
|
|
CGContextRef cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
|
|
|
[self drawRect:aRect inContext:cgContext];
|
|
|
|
|
2009-12-12 00:53:22 +03:00
|
|
|
// If we're a transparent window and our contents have changed, we need
|
2009-10-21 11:05:39 +04:00
|
|
|
// to make sure the shadow is updated to the new contents.
|
2009-12-12 00:53:22 +03:00
|
|
|
if ([[self window] isKindOfClass:[BaseWindow class]]) {
|
|
|
|
[(BaseWindow*)[self window] deferredInvalidateShadow];
|
|
|
|
}
|
2009-10-21 11:05:39 +04:00
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2010-10-15 14:34:29 +04:00
|
|
|
- (void)drawRect:(NSRect)aRect inTitlebarContext:(CGContextRef)aContext
|
|
|
|
{
|
2010-11-19 20:37:18 +03:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2010-10-15 14:34:29 +04:00
|
|
|
// Title bar drawing only works if we really draw into aContext, which only
|
|
|
|
// the basic layer manager will do.
|
|
|
|
nsBaseWidget::AutoUseBasicLayerManager setupLayerManager(mGeckoChild);
|
|
|
|
[self drawRect:aRect inContext:aContext];
|
|
|
|
}
|
|
|
|
|
2009-10-21 11:05:39 +04:00
|
|
|
- (void)drawRect:(NSRect)aRect inContext:(CGContextRef)aContext
|
|
|
|
{
|
2012-01-18 00:33:04 +04:00
|
|
|
SAMPLE_LABEL("widget", "ChildView::drawRect");
|
2012-07-19 12:57:50 +04:00
|
|
|
if (!mGeckoChild || !mGeckoChild->IsVisible())
|
2002-02-17 22:09:07 +03:00
|
|
|
return;
|
2006-02-22 04:31:14 +03:00
|
|
|
|
2010-09-17 21:58:26 +04:00
|
|
|
#ifndef NP_NO_QUICKDRAW
|
|
|
|
if (mIsPluginView && mPluginDrawingModel == NPDrawingModelQuickDraw) {
|
|
|
|
mGeckoChild->PaintQD();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-17 22:04:14 +04:00
|
|
|
// Don't ever draw non-QuickDraw plugin views explicitly; they'll be drawn as
|
|
|
|
// part of their parent widget.
|
|
|
|
if (mIsPluginView)
|
|
|
|
return;
|
|
|
|
|
2009-10-21 11:05:39 +04:00
|
|
|
#ifdef DEBUG_UPDATE
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect geckoBounds;
|
2006-02-22 04:31:14 +03:00
|
|
|
mGeckoChild->GetBounds(geckoBounds);
|
2006-08-31 02:06:44 +04:00
|
|
|
|
|
|
|
fprintf (stderr, "---- Update[%p][%p] [%f %f %f %f] cgc: %p\n gecko bounds: [%d %d %d %d]\n",
|
|
|
|
self, mGeckoChild,
|
2009-10-21 11:05:39 +04:00
|
|
|
aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height, aContext,
|
2006-08-31 02:06:44 +04:00
|
|
|
geckoBounds.x, geckoBounds.y, geckoBounds.width, geckoBounds.height);
|
2006-02-22 04:31:14 +03:00
|
|
|
|
2009-10-21 11:05:39 +04:00
|
|
|
CGAffineTransform xform = CGContextGetCTM(aContext);
|
2006-08-31 02:06:44 +04:00
|
|
|
fprintf (stderr, " xform in: [%f %f %f %f %f %f]\n", xform.a, xform.b, xform.c, xform.d, xform.tx, xform.ty);
|
|
|
|
#endif
|
2010-03-01 11:03:49 +03:00
|
|
|
// Create the event so we can fill in its region
|
2011-10-01 04:20:33 +04:00
|
|
|
nsPaintEvent paintEvent(true, NS_PAINT, mGeckoChild);
|
2011-12-24 07:52:24 +04:00
|
|
|
paintEvent.didSendWillPaint = true;
|
2006-11-28 03:11:42 +03:00
|
|
|
|
2010-10-15 14:36:23 +04:00
|
|
|
nsIntRect boundingRect =
|
|
|
|
nsIntRect(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);
|
2006-02-22 04:31:14 +03:00
|
|
|
const NSRect *rects;
|
2009-09-01 05:00:13 +04:00
|
|
|
NSInteger count, i;
|
2009-10-21 11:05:39 +04:00
|
|
|
[[NSView focusView] getRectsBeingDrawn:&rects count:&count];
|
2009-02-16 04:06:52 +03:00
|
|
|
if (count < MAX_RECTS_IN_REGION) {
|
|
|
|
for (i = 0; i < count; ++i) {
|
2009-10-21 11:05:39 +04:00
|
|
|
// Add the rect to the region.
|
|
|
|
const NSRect& r = [self convertRect:rects[i] fromView:[NSView focusView]];
|
2010-03-01 11:03:49 +03:00
|
|
|
paintEvent.region.Or(paintEvent.region,
|
|
|
|
nsIntRect(r.origin.x, r.origin.y, r.size.width, r.size.height));
|
2009-02-16 04:06:52 +03:00
|
|
|
}
|
2010-10-15 14:36:23 +04:00
|
|
|
paintEvent.region.And(paintEvent.region, boundingRect);
|
2009-02-16 04:06:52 +03:00
|
|
|
} else {
|
2010-10-15 14:36:23 +04:00
|
|
|
paintEvent.region = boundingRect;
|
2006-02-22 04:31:14 +03:00
|
|
|
}
|
2009-07-22 04:44:55 +04:00
|
|
|
|
2010-09-17 22:04:14 +04:00
|
|
|
#ifndef NP_NO_QUICKDRAW
|
|
|
|
// Subtract quickdraw plugin rectangles from the region
|
2009-07-22 04:44:55 +04:00
|
|
|
NSArray* subviews = [self subviews];
|
|
|
|
for (int i = 0; i < int([subviews count]); ++i) {
|
|
|
|
NSView* view = [subviews objectAtIndex:i];
|
|
|
|
if (![view isKindOfClass:[ChildView class]] || [view isHidden])
|
|
|
|
continue;
|
2010-09-17 22:04:14 +04:00
|
|
|
ChildView* cview = (ChildView*) view;
|
|
|
|
if ([cview isPluginView] && [cview pluginDrawingModel] == NPDrawingModelQuickDraw) {
|
|
|
|
NSRect frame = [view frame];
|
|
|
|
paintEvent.region.Sub(paintEvent.region,
|
|
|
|
nsIntRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height));
|
|
|
|
}
|
2009-07-22 04:44:55 +04:00
|
|
|
}
|
2010-09-17 22:04:14 +04:00
|
|
|
#endif
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
LayerManager *layerManager = mGeckoChild->GetLayerManager(nullptr);
|
2012-07-18 20:31:40 +04:00
|
|
|
if (layerManager->GetBackendType() == mozilla::layers::LAYERS_OPENGL) {
|
2012-01-19 18:45:37 +04:00
|
|
|
NSOpenGLContext *glContext;
|
|
|
|
|
|
|
|
LayerManagerOGL *manager = static_cast<LayerManagerOGL*>(layerManager);
|
|
|
|
manager->SetClippingRegion(paintEvent.region);
|
|
|
|
glContext = (NSOpenGLContext *)manager->gl()->GetNativeData(mozilla::gl::GLContext::NativeGLContext);
|
|
|
|
|
2010-06-18 13:22:01 +04:00
|
|
|
if (!mGLContext) {
|
2012-01-19 18:45:37 +04:00
|
|
|
[self setGLContext:glContext];
|
2010-04-28 02:29:29 +04:00
|
|
|
}
|
2012-01-19 18:45:37 +04:00
|
|
|
|
2010-04-28 02:29:29 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(paintEvent);
|
2011-02-04 00:12:33 +03:00
|
|
|
|
|
|
|
// Force OpenGL to refresh the very first time we draw. This works around a
|
|
|
|
// Mac OS X bug that stops windows updating on OS X when we use OpenGL.
|
|
|
|
if (!mDidForceRefreshOpenGL) {
|
|
|
|
[self performSelector:@selector(forceRefreshOpenGL) withObject:nil afterDelay:0];
|
|
|
|
mDidForceRefreshOpenGL = YES;
|
|
|
|
}
|
|
|
|
|
2010-04-28 02:29:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create Cairo objects.
|
|
|
|
NSSize bufferSize = [self bounds].size;
|
|
|
|
nsRefPtr<gfxQuartzSurface> targetSurface =
|
|
|
|
new gfxQuartzSurface(aContext, gfxSize(bufferSize.width, bufferSize.height));
|
2011-10-01 04:20:33 +04:00
|
|
|
targetSurface->SetAllowUseAsSource(false);
|
2010-04-28 02:29:29 +04:00
|
|
|
|
|
|
|
nsRefPtr<gfxContext> targetContext = new gfxContext(targetSurface);
|
2009-07-22 04:44:55 +04:00
|
|
|
|
2009-10-21 11:05:39 +04:00
|
|
|
// Set up the clip region.
|
2010-03-01 11:03:49 +03:00
|
|
|
nsIntRegionRectIterator iter(paintEvent.region);
|
|
|
|
targetContext->NewPath();
|
|
|
|
for (;;) {
|
|
|
|
const nsIntRect* r = iter.Next();
|
|
|
|
if (!r)
|
|
|
|
break;
|
|
|
|
targetContext->Rectangle(gfxRect(r->x, r->y, r->width, r->height));
|
2009-10-21 11:05:39 +04:00
|
|
|
}
|
|
|
|
targetContext->Clip();
|
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool painted;
|
2010-03-01 11:03:49 +03:00
|
|
|
{
|
2010-07-16 01:08:04 +04:00
|
|
|
nsBaseWidget::AutoLayerManagerSetup
|
|
|
|
setupLayerManager(mGeckoChild, targetContext, BasicLayerManager::BUFFER_NONE);
|
2010-03-01 11:03:49 +03:00
|
|
|
painted = mGeckoChild->DispatchWindowEvent(paintEvent);
|
|
|
|
}
|
|
|
|
|
2012-01-19 18:45:37 +04:00
|
|
|
// Force OpenGL to refresh the very first time we draw. This works around a
|
|
|
|
// Mac OS X bug that stops windows updating on OS X when we use OpenGL.
|
|
|
|
if (painted && !mDidForceRefreshOpenGL &&
|
|
|
|
layerManager->AsShadowManager() && mUsingOMTCompositor) {
|
|
|
|
if (!mDidForceRefreshOpenGL) {
|
|
|
|
[self performSelector:@selector(forceRefreshOpenGL) withObject:nil afterDelay:0];
|
|
|
|
mDidForceRefreshOpenGL = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-06 13:17:45 +03:00
|
|
|
if (!painted && [self isOpaque]) {
|
|
|
|
// Gecko refused to draw, but we've claimed to be opaque, so we have to
|
|
|
|
// draw something--fill with white.
|
|
|
|
CGContextSetRGBFillColor(aContext, 1, 1, 1, 1);
|
|
|
|
CGContextFillRect(aContext, CGRectMake(aRect.origin.x, aRect.origin.y,
|
|
|
|
aRect.size.width, aRect.size.height));
|
|
|
|
}
|
2010-01-13 19:08:06 +03:00
|
|
|
|
2006-08-31 02:06:44 +04:00
|
|
|
// note that the cairo surface *MUST* be destroyed at this point,
|
|
|
|
// or bad things will happen (since we can't keep the cgContext around
|
|
|
|
// beyond this drawRect message handler)
|
|
|
|
|
|
|
|
#ifdef DEBUG_UPDATE
|
|
|
|
fprintf (stderr, "---- update done ----\n");
|
|
|
|
|
2007-01-31 21:43:34 +03:00
|
|
|
#if 0
|
2009-10-21 11:05:39 +04:00
|
|
|
CGContextSetRGBStrokeColor (aContext,
|
2006-08-31 02:06:44 +04:00
|
|
|
((((unsigned long)self) & 0xff)) / 255.0,
|
|
|
|
((((unsigned long)self) & 0xff00) >> 8) / 255.0,
|
|
|
|
((((unsigned long)self) & 0xff0000) >> 16) / 255.0,
|
|
|
|
0.5);
|
2007-01-31 21:43:34 +03:00
|
|
|
#endif
|
2009-10-21 11:05:39 +04:00
|
|
|
CGContextSetRGBStrokeColor(aContext, 1, 0, 0, 0.8);
|
|
|
|
CGContextSetLineWidth(aContext, 4.0);
|
|
|
|
CGContextStrokeRect(aContext,
|
|
|
|
CGRectMake(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height));
|
2006-08-31 02:06:44 +04:00
|
|
|
#endif
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2011-01-26 00:21:35 +03:00
|
|
|
- (void)releaseWidgets:(NSArray*)aWidgetArray
|
|
|
|
{
|
|
|
|
if (!aWidgetArray) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NSInteger count = [aWidgetArray count];
|
|
|
|
for (NSInteger i = 0; i < count; ++i) {
|
|
|
|
NSNumber* pointer = (NSNumber*) [aWidgetArray objectAtIndex:i];
|
|
|
|
nsIWidget* widget = (nsIWidget*) [pointer unsignedIntegerValue];
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-14 02:03:46 +03:00
|
|
|
- (void)viewWillDraw
|
|
|
|
{
|
2009-12-11 22:31:42 +03:00
|
|
|
if (mGeckoChild) {
|
2011-01-26 00:21:35 +03:00
|
|
|
// The OS normally *will* draw our NSWindow, no matter what we do here.
|
|
|
|
// But Gecko can delete our parent widget(s) (along with mGeckoChild)
|
|
|
|
// while processing an NS_WILL_PAINT event, which closes our NSWindow and
|
|
|
|
// makes the OS throw an NSInternalInconsistencyException assertion when
|
|
|
|
// it tries to draw it. Sometimes the OS also aborts the browser process.
|
|
|
|
// So we need to retain our parent(s) here and not release it/them until
|
|
|
|
// the next time through the main thread's run loop. When we do this we
|
|
|
|
// also need to retain and release mGeckoChild, which holds a strong
|
|
|
|
// reference to us (otherwise we might have been deleted by the time
|
|
|
|
// releaseWidgets: is called on us). See bug 550392.
|
|
|
|
nsIWidget* parent = mGeckoChild->GetParent();
|
|
|
|
if (parent) {
|
|
|
|
NSMutableArray* widgetArray = [NSMutableArray arrayWithCapacity:3];
|
|
|
|
while (parent) {
|
|
|
|
NS_ADDREF(parent);
|
|
|
|
[widgetArray addObject:[NSNumber numberWithUnsignedInteger:(NSUInteger)parent]];
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
|
|
|
NS_ADDREF(mGeckoChild);
|
|
|
|
[widgetArray addObject:[NSNumber numberWithUnsignedInteger:(NSUInteger)mGeckoChild]];
|
|
|
|
[self performSelector:@selector(releaseWidgets:)
|
|
|
|
withObject:widgetArray
|
|
|
|
afterDelay:0];
|
|
|
|
}
|
2011-10-01 04:20:33 +04:00
|
|
|
nsPaintEvent paintEvent(true, NS_WILL_PAINT, mGeckoChild);
|
2009-12-11 22:31:42 +03:00
|
|
|
mGeckoChild->DispatchWindowEvent(paintEvent);
|
|
|
|
}
|
|
|
|
[super viewWillDraw];
|
2009-11-14 02:03:46 +03:00
|
|
|
}
|
|
|
|
|
2007-07-18 04:07:36 +04:00
|
|
|
// Allows us to turn off setting up the clip region
|
2004-05-07 11:17:41 +04:00
|
|
|
// before each drawRect. We already clip within gecko.
|
|
|
|
- (BOOL)wantsDefaultClipping
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2004-02-18 19:18:38 +03:00
|
|
|
#if USE_CLICK_HOLD_CONTEXTMENU
|
2004-01-15 22:01:49 +03:00
|
|
|
//
|
|
|
|
// -clickHoldCallback:
|
|
|
|
//
|
|
|
|
// called from a timer two seconds after a mouse down to see if we should display
|
|
|
|
// a context menu (click-hold). |anEvent| is the original mouseDown event. If we're
|
|
|
|
// still in that mouseDown by this time, put up the context menu, otherwise just
|
|
|
|
// fuhgeddaboutit. |anEvent| has been retained by the OS until after this callback
|
|
|
|
// fires so we're ok there.
|
|
|
|
//
|
2004-02-18 19:18:38 +03:00
|
|
|
// This code currently messes in a bunch of edge cases (bugs 234751, 232964, 232314)
|
|
|
|
// so removing it until we get it straightened out.
|
|
|
|
//
|
2004-01-15 22:01:49 +03:00
|
|
|
- (void)clickHoldCallback:(id)theEvent;
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2004-01-15 22:01:49 +03:00
|
|
|
if( theEvent == [NSApp currentEvent] ) {
|
|
|
|
// we're still in the middle of the same mousedown event here, activate
|
|
|
|
// click-hold context menu by triggering the right mouseDown action.
|
|
|
|
NSEvent* clickHoldEvent = [NSEvent mouseEventWithType:NSRightMouseDown
|
|
|
|
location:[theEvent locationInWindow]
|
2010-02-24 02:30:39 +03:00
|
|
|
modifierFlags:[theEvent modifierFlags]
|
2004-01-15 22:01:49 +03:00
|
|
|
timestamp:[theEvent timestamp]
|
|
|
|
windowNumber:[theEvent windowNumber]
|
|
|
|
context:[theEvent context]
|
|
|
|
eventNumber:[theEvent eventNumber]
|
|
|
|
clickCount:[theEvent clickCount]
|
|
|
|
pressure:[theEvent pressure]];
|
|
|
|
[self rightMouseDown:clickHoldEvent];
|
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2004-01-15 22:01:49 +03:00
|
|
|
}
|
2004-02-18 19:18:38 +03:00
|
|
|
#endif
|
2004-01-15 22:01:49 +03:00
|
|
|
|
2007-07-18 00:29:39 +04:00
|
|
|
// If we've just created a non-native context menu, we need to mark it as
|
|
|
|
// such and let the OS (and other programs) know when it opens and closes
|
|
|
|
// (this is how the OS knows to close other programs' context menus when
|
|
|
|
// ours open). We send the initial notification here, but others are sent
|
|
|
|
// in nsCocoaWindow::Show().
|
|
|
|
- (void)maybeInitContextMenuTracking
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-07-18 00:29:39 +04:00
|
|
|
if (!gRollupWidget)
|
|
|
|
return;
|
2008-03-04 11:06:47 +03:00
|
|
|
|
2011-06-22 01:00:47 +04:00
|
|
|
#ifdef MOZ_USE_NATIVE_POPUP_WINDOWS
|
|
|
|
return;
|
|
|
|
#endif /* MOZ_USE_NATIVE_POPUP_WINDOWS */
|
2008-03-04 11:06:47 +03:00
|
|
|
|
2007-11-07 10:53:24 +03:00
|
|
|
NSWindow *popupWindow = (NSWindow*)gRollupWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (!popupWindow || ![popupWindow isKindOfClass:[PopupWindow class]])
|
2007-07-18 00:29:39 +04:00
|
|
|
return;
|
2007-11-07 10:53:24 +03:00
|
|
|
|
2007-07-18 00:29:39 +04:00
|
|
|
[[NSDistributedNotificationCenter defaultCenter]
|
|
|
|
postNotificationName:@"com.apple.HIToolbox.beginMenuTrackingNotification"
|
|
|
|
object:@"org.mozilla.gecko.PopupWindow"];
|
2007-11-07 10:53:24 +03:00
|
|
|
[(PopupWindow*)popupWindow setIsContextMenu:YES];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-07-18 00:29:39 +04:00
|
|
|
}
|
|
|
|
|
2009-05-15 00:13:22 +04:00
|
|
|
// Returns true if the event should no longer be processed, false otherwise.
|
|
|
|
// This does not return whether or not anything was rolled up.
|
2007-11-27 02:19:04 +03:00
|
|
|
- (BOOL)maybeRollup:(NSEvent*)theEvent
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2009-05-15 00:13:22 +04:00
|
|
|
BOOL consumeEvent = NO;
|
|
|
|
|
2007-11-27 02:19:04 +03:00
|
|
|
if (gRollupWidget && gRollupListener) {
|
|
|
|
NSWindow* currentPopup = static_cast<NSWindow*>(gRollupWidget->GetNativeData(NS_NATIVE_WINDOW));
|
2007-12-06 02:17:08 +03:00
|
|
|
if (!nsCocoaUtils::IsEventOverWindow(theEvent, currentPopup)) {
|
2009-05-15 00:13:22 +04:00
|
|
|
// event is not over the rollup window, default is to roll up
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldRollup = true;
|
2009-05-15 00:13:22 +04:00
|
|
|
|
|
|
|
// check to see if scroll events should roll up the popup
|
2007-11-27 02:19:04 +03:00
|
|
|
if ([theEvent type] == NSScrollWheel) {
|
2011-11-08 23:59:07 +04:00
|
|
|
shouldRollup = gRollupListener->ShouldRollupOnMouseWheelEvent();
|
2009-05-15 00:13:22 +04:00
|
|
|
// always consume scroll events that aren't over the popup
|
|
|
|
consumeEvent = YES;
|
2007-11-27 02:19:04 +03:00
|
|
|
}
|
2009-05-15 00:13:22 +04:00
|
|
|
|
2007-11-27 02:19:04 +03:00
|
|
|
// if we're dealing with menus, we probably have submenus and
|
2008-04-07 03:52:05 +04:00
|
|
|
// we don't want to rollup if the click is in a parent menu of
|
2007-11-27 02:19:04 +03:00
|
|
|
// the current submenu
|
2009-06-12 22:23:16 +04:00
|
|
|
PRUint32 popupsToRollup = PR_UINT32_MAX;
|
2011-11-08 23:59:07 +04:00
|
|
|
if (gRollupListener) {
|
2008-01-17 09:57:13 +03:00
|
|
|
nsAutoTArray<nsIWidget*, 5> widgetChain;
|
2011-11-08 23:59:07 +04:00
|
|
|
PRUint32 sameTypeCount = gRollupListener->GetSubmenuWidgetChain(&widgetChain);
|
2008-01-17 10:06:43 +03:00
|
|
|
for (PRUint32 i = 0; i < widgetChain.Length(); i++) {
|
|
|
|
nsIWidget* widget = widgetChain[i];
|
|
|
|
NSWindow* currWindow = (NSWindow*)widget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
if (nsCocoaUtils::IsEventOverWindow(theEvent, currWindow)) {
|
2010-05-13 16:19:50 +04:00
|
|
|
// don't roll up if the mouse event occurred within a menu of the
|
|
|
|
// same type. If the mouse event occurred in a menu higher than
|
2009-06-12 22:23:16 +04:00
|
|
|
// that, roll up, but pass the number of popups to Rollup so
|
|
|
|
// that only those of the same type close up.
|
|
|
|
if (i < sameTypeCount) {
|
2011-10-01 04:20:33 +04:00
|
|
|
shouldRollup = false;
|
2009-06-12 22:23:16 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
popupsToRollup = sameTypeCount;
|
|
|
|
}
|
2008-01-17 10:06:43 +03:00
|
|
|
break;
|
|
|
|
}
|
2009-05-15 00:13:22 +04:00
|
|
|
}
|
|
|
|
}
|
2007-11-07 10:53:24 +03:00
|
|
|
|
2009-05-15 00:13:22 +04:00
|
|
|
if (shouldRollup) {
|
2011-11-08 23:59:07 +04:00
|
|
|
gRollupListener->Rollup(popupsToRollup);
|
2009-05-15 00:13:22 +04:00
|
|
|
consumeEvent = (BOOL)gConsumeRollupEvent;
|
2006-04-12 19:10:00 +04:00
|
|
|
}
|
2006-04-06 23:14:02 +04:00
|
|
|
}
|
|
|
|
}
|
2007-11-27 02:19:04 +03:00
|
|
|
|
2009-05-15 00:13:22 +04:00
|
|
|
return consumeEvent;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
2007-11-27 02:19:04 +03:00
|
|
|
}
|
|
|
|
|
2008-10-24 00:15:20 +04:00
|
|
|
/*
|
|
|
|
* XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent,
|
|
|
|
* rotateWithEvent, and endGestureWithEvent methods are part of a
|
|
|
|
* PRIVATE interface exported by nsResponder and reverse-engineering
|
|
|
|
* was necessary to obtain the methods' prototypes. Thus, Apple may
|
|
|
|
* change the interface in the future without notice.
|
|
|
|
*
|
|
|
|
* The prototypes were obtained from the following link:
|
|
|
|
* http://cocoadex.com/2008/02/nsevent-modifications-swipe-ro.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
- (void)swipeWithEvent:(NSEvent *)anEvent
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (!anEvent || !mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
|
|
|
|
float deltaX = [anEvent deltaX]; // left=1.0, right=-1.0
|
|
|
|
float deltaY = [anEvent deltaY]; // up=1.0, down=-1.0
|
|
|
|
|
|
|
|
// Setup the "swipe" event.
|
2011-10-01 04:20:33 +04:00
|
|
|
nsSimpleGestureEvent geckoEvent(true, NS_SIMPLE_GESTURE_SWIPE, mGeckoChild, 0, 0.0);
|
2009-01-03 15:40:26 +03:00
|
|
|
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
|
2008-10-24 00:15:20 +04:00
|
|
|
|
|
|
|
// Record the left/right direction.
|
|
|
|
if (deltaX > 0.0)
|
|
|
|
geckoEvent.direction |= nsIDOMSimpleGestureEvent::DIRECTION_LEFT;
|
|
|
|
else if (deltaX < 0.0)
|
|
|
|
geckoEvent.direction |= nsIDOMSimpleGestureEvent::DIRECTION_RIGHT;
|
|
|
|
|
|
|
|
// Record the up/down direction.
|
|
|
|
if (deltaY > 0.0)
|
|
|
|
geckoEvent.direction |= nsIDOMSimpleGestureEvent::DIRECTION_UP;
|
|
|
|
else if (deltaY < 0.0)
|
|
|
|
geckoEvent.direction |= nsIDOMSimpleGestureEvent::DIRECTION_DOWN;
|
|
|
|
|
|
|
|
// Send the event.
|
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)beginGestureWithEvent:(NSEvent *)anEvent
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mGestureState == eGestureState_None, "mGestureState should be eGestureState_None");
|
|
|
|
|
|
|
|
if (!anEvent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mGestureState = eGestureState_StartGesture;
|
|
|
|
mCumulativeMagnification = 0;
|
|
|
|
mCumulativeRotation = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)magnifyWithEvent:(NSEvent *)anEvent
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (!anEvent || !mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
|
|
|
|
float deltaZ = [anEvent deltaZ];
|
|
|
|
|
|
|
|
PRUint32 msg;
|
|
|
|
switch (mGestureState) {
|
|
|
|
case eGestureState_StartGesture:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY_START;
|
|
|
|
mGestureState = eGestureState_MagnifyGesture;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eGestureState_MagnifyGesture:
|
|
|
|
msg = NS_SIMPLE_GESTURE_MAGNIFY_UPDATE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eGestureState_None:
|
|
|
|
case eGestureState_RotateGesture:
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the event.
|
2011-10-01 04:20:33 +04:00
|
|
|
nsSimpleGestureEvent geckoEvent(true, msg, mGeckoChild, 0, deltaZ);
|
2009-01-03 15:40:26 +03:00
|
|
|
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
|
2008-10-24 00:15:20 +04:00
|
|
|
|
|
|
|
// Send the event.
|
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
|
|
|
|
|
|
|
// Keep track of the cumulative magnification for the final "magnify" event.
|
|
|
|
mCumulativeMagnification += deltaZ;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rotateWithEvent:(NSEvent *)anEvent
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (!anEvent || !mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
|
|
|
|
float rotation = [anEvent rotation];
|
|
|
|
|
|
|
|
PRUint32 msg;
|
|
|
|
switch (mGestureState) {
|
|
|
|
case eGestureState_StartGesture:
|
|
|
|
msg = NS_SIMPLE_GESTURE_ROTATE_START;
|
|
|
|
mGestureState = eGestureState_RotateGesture;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eGestureState_RotateGesture:
|
|
|
|
msg = NS_SIMPLE_GESTURE_ROTATE_UPDATE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eGestureState_None:
|
|
|
|
case eGestureState_MagnifyGesture:
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the event.
|
2011-10-01 04:20:33 +04:00
|
|
|
nsSimpleGestureEvent geckoEvent(true, msg, mGeckoChild, 0, 0.0);
|
2009-01-03 15:40:26 +03:00
|
|
|
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
|
2008-10-24 00:15:20 +04:00
|
|
|
geckoEvent.delta = -rotation;
|
|
|
|
if (rotation > 0.0) {
|
2009-04-02 23:34:31 +04:00
|
|
|
geckoEvent.direction = nsIDOMSimpleGestureEvent::ROTATION_COUNTERCLOCKWISE;
|
2008-10-24 00:15:20 +04:00
|
|
|
} else {
|
2009-04-02 23:34:31 +04:00
|
|
|
geckoEvent.direction = nsIDOMSimpleGestureEvent::ROTATION_CLOCKWISE;
|
2008-10-24 00:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send the event.
|
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
|
|
|
|
|
|
|
// Keep track of the cumulative rotation for the final "rotate" event.
|
|
|
|
mCumulativeRotation += rotation;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)endGestureWithEvent:(NSEvent *)anEvent
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (!anEvent || !mGeckoChild) {
|
|
|
|
// Clear the gestures state if we cannot send an event.
|
|
|
|
mGestureState = eGestureState_None;
|
|
|
|
mCumulativeMagnification = 0.0;
|
|
|
|
mCumulativeRotation = 0.0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
|
|
|
|
switch (mGestureState) {
|
|
|
|
case eGestureState_MagnifyGesture:
|
|
|
|
{
|
|
|
|
// Setup the "magnify" event.
|
2011-10-01 04:20:33 +04:00
|
|
|
nsSimpleGestureEvent geckoEvent(true, NS_SIMPLE_GESTURE_MAGNIFY,
|
2008-10-24 00:15:20 +04:00
|
|
|
mGeckoChild, 0, mCumulativeMagnification);
|
2009-01-03 15:40:26 +03:00
|
|
|
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
|
2008-10-24 00:15:20 +04:00
|
|
|
|
|
|
|
// Send the event.
|
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eGestureState_RotateGesture:
|
|
|
|
{
|
|
|
|
// Setup the "rotate" event.
|
2011-10-01 04:20:33 +04:00
|
|
|
nsSimpleGestureEvent geckoEvent(true, NS_SIMPLE_GESTURE_ROTATE, mGeckoChild, 0, 0.0);
|
2009-01-03 15:40:26 +03:00
|
|
|
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
|
2008-10-24 00:15:20 +04:00
|
|
|
geckoEvent.delta = -mCumulativeRotation;
|
|
|
|
if (mCumulativeRotation > 0.0) {
|
2009-04-02 23:34:31 +04:00
|
|
|
geckoEvent.direction = nsIDOMSimpleGestureEvent::ROTATION_COUNTERCLOCKWISE;
|
2008-10-24 00:15:20 +04:00
|
|
|
} else {
|
2009-04-02 23:34:31 +04:00
|
|
|
geckoEvent.direction = nsIDOMSimpleGestureEvent::ROTATION_CLOCKWISE;
|
2008-10-24 00:15:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send the event.
|
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eGestureState_None:
|
|
|
|
case eGestureState_StartGesture:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the gestures state.
|
|
|
|
mGestureState = eGestureState_None;
|
|
|
|
mCumulativeMagnification = 0.0;
|
|
|
|
mCumulativeRotation = 0.0;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2011-08-11 21:42:23 +04:00
|
|
|
// Support fluid swipe tracking on OS X 10.7 and higher. We must be careful
|
|
|
|
// to only invoke this support on a horizontal two-finger gesture that really
|
|
|
|
// is a swipe (and not a scroll) -- in other words, the app is responsible
|
|
|
|
// for deciding which is which. But once the decision is made, the OS tracks
|
|
|
|
// the swipe until it has finished, and decides whether or not it succeeded.
|
|
|
|
// A swipe has the same functionality as the Back and Forward buttons. For
|
|
|
|
// now swipe animation is unsupported (e.g. no bounces). This method is
|
|
|
|
// partly based on Apple sample code available at
|
|
|
|
// http://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKit.html
|
|
|
|
// (under Fluid Swipe Tracking API).
|
|
|
|
#ifdef __LP64__
|
|
|
|
- (void)maybeTrackScrollEventAsSwipe:(NSEvent *)anEvent
|
|
|
|
scrollOverflow:(PRInt32)overflow
|
|
|
|
{
|
2012-05-17 11:53:20 +04:00
|
|
|
if (!nsCocoaFeatures::OnLionOrLater()) {
|
2011-08-11 21:42:23 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// This method checks whether the AppleEnableSwipeNavigateWithScrolls global
|
|
|
|
// preference is set. If it isn't, fluid swipe tracking is disabled, and a
|
|
|
|
// horizontal two-finger gesture is always a scroll (even in Safari). This
|
|
|
|
// preference can't (currently) be set from the Preferences UI -- only using
|
|
|
|
// 'defaults write'.
|
|
|
|
if (![NSEvent isSwipeTrackingFromScrollEventsEnabled]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ([anEvent type] != NSScrollWheel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a swipe is currently being tracked kill it -- it's been interrupted by
|
|
|
|
// another gesture or legacy scroll wheel event.
|
|
|
|
if (mSwipeAnimationCancelled && (*mSwipeAnimationCancelled == NO)) {
|
|
|
|
*mSwipeAnimationCancelled = YES;
|
|
|
|
mSwipeAnimationCancelled = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only initiate tracking if the user has tried to scroll past the edge of
|
|
|
|
// the current page (as indicated by 'overflow' being non-zero). Gecko only
|
|
|
|
// sets nsMouseScrollEvent.scrollOverflow when it's processing
|
|
|
|
// NS_MOUSE_PIXEL_SCROLL events (not NS_MOUSE_SCROLL events).
|
|
|
|
// nsMouseScrollEvent.scrollOverflow only indicates left or right overflow
|
|
|
|
// for horizontal NS_MOUSE_PIXEL_SCROLL events.
|
|
|
|
if (!overflow) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Only initiate tracking for gestures that have just begun -- otherwise a
|
|
|
|
// scroll to one side of the page can have a swipe tacked on to it.
|
|
|
|
if ([anEvent phase] != NSEventPhaseBegan) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CGFloat deltaX, deltaY;
|
|
|
|
if ([anEvent hasPreciseScrollingDeltas]) {
|
|
|
|
deltaX = [anEvent scrollingDeltaX];
|
|
|
|
deltaY = [anEvent scrollingDeltaY];
|
|
|
|
} else {
|
|
|
|
deltaX = [anEvent deltaX];
|
|
|
|
deltaY = [anEvent deltaY];
|
|
|
|
}
|
|
|
|
// Only initiate tracking for events whose horizontal element is at least
|
|
|
|
// eight times larger than its vertical element. This minimizes performance
|
|
|
|
// problems with vertical scrolls (by minimizing the possibility that they'll
|
|
|
|
// be misinterpreted as horizontal swipes), while still tolerating a small
|
|
|
|
// vertical element to a true horizontal swipe. The number '8' was arrived
|
|
|
|
// at by trial and error.
|
|
|
|
if ((deltaX == 0) || (fabs(deltaX) <= fabs(deltaY) * 8)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
__block BOOL animationCancelled = NO;
|
|
|
|
// At this point, anEvent is the first scroll wheel event in a two-finger
|
|
|
|
// horizontal gesture that we've decided to treat as a swipe. When we call
|
|
|
|
// [NSEvent trackSwipeEventWithOptions:...], the OS interprets all
|
|
|
|
// subsequent scroll wheel events that are part of this gesture as a swipe,
|
|
|
|
// and stops sending them to us. The OS calls the trackingHandler "block"
|
|
|
|
// multiple times, asynchronously (sometimes after [NSEvent
|
|
|
|
// maybeTrackScrollEventAsSwipe:...] has returned). The OS determines when
|
|
|
|
// the gesture has finished, and whether or not it was "successful" -- this
|
|
|
|
// information is passed to trackingHandler. We must be careful to only
|
|
|
|
// call [NSEvent maybeTrackScrollEventAsSwipe:...] on a "real" swipe --
|
|
|
|
// otherwise two-finger scrolling performance will suffer significantly.
|
2011-09-08 17:31:09 +04:00
|
|
|
// Note that we use anEvent inside the block. This extends the lifetime of
|
|
|
|
// the anEvent object because it's retained by the block, see bug 682445.
|
|
|
|
// The block will release it when the block goes away at the end of the
|
|
|
|
// animation, or when the animation is canceled.
|
2011-08-11 21:42:23 +04:00
|
|
|
[anEvent trackSwipeEventWithOptions:0
|
|
|
|
dampenAmountThresholdMin:-1
|
|
|
|
max:1
|
|
|
|
usingHandler:^(CGFloat gestureAmount, NSEventPhase phase, BOOL isComplete, BOOL *stop) {
|
2011-11-23 01:15:45 +04:00
|
|
|
// Since this tracking handler can be called asynchronously, mGeckoChild
|
|
|
|
// might have become NULL here (our child widget might have been
|
|
|
|
// destroyed).
|
|
|
|
if (animationCancelled || !mGeckoChild) {
|
2011-08-11 21:42:23 +04:00
|
|
|
*stop = YES;
|
|
|
|
return;
|
|
|
|
}
|
2011-08-18 02:52:27 +04:00
|
|
|
// gestureAmount is documented to be '-1', '0' or '1' when isComplete
|
|
|
|
// is TRUE, but the docs don't say anything about its value at other
|
|
|
|
// times. However, tests show that, when phase == NSEventPhaseEnded,
|
|
|
|
// gestureAmount is negative when it will be '-1' at isComplete, and
|
|
|
|
// positive when it will be '1'. And phase is never equal to
|
|
|
|
// NSEventPhaseEnded when gestureAmount will be '0' at isComplete.
|
|
|
|
// Not waiting until isComplete is TRUE substantially reduces the
|
|
|
|
// time it takes to change pages after a swipe, and helps resolve
|
|
|
|
// bug 678891.
|
|
|
|
if (phase == NSEventPhaseEnded) {
|
2011-08-11 21:42:23 +04:00
|
|
|
if (gestureAmount) {
|
2011-10-01 04:20:33 +04:00
|
|
|
nsSimpleGestureEvent geckoEvent(true, NS_SIMPLE_GESTURE_SWIPE, mGeckoChild, 0, 0.0);
|
2011-09-08 17:31:09 +04:00
|
|
|
[self convertCocoaMouseEvent:anEvent toGeckoEvent:&geckoEvent];
|
2011-08-11 21:42:23 +04:00
|
|
|
if (gestureAmount > 0) {
|
2011-09-08 17:31:09 +04:00
|
|
|
geckoEvent.direction |= nsIDOMSimpleGestureEvent::DIRECTION_LEFT;
|
2011-08-11 21:42:23 +04:00
|
|
|
} else {
|
2011-09-08 17:31:09 +04:00
|
|
|
geckoEvent.direction |= nsIDOMSimpleGestureEvent::DIRECTION_RIGHT;
|
2011-08-11 21:42:23 +04:00
|
|
|
}
|
2011-09-08 17:31:09 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2011-08-11 21:42:23 +04:00
|
|
|
}
|
|
|
|
mSwipeAnimationCancelled = nil;
|
2011-08-18 02:52:27 +04:00
|
|
|
} else if (phase == NSEventPhaseCancelled) {
|
|
|
|
mSwipeAnimationCancelled = nil;
|
2011-08-11 21:42:23 +04:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
// We keep a pointer to the __block variable (animationCanceled) so we
|
|
|
|
// can cancel our block handler at any time. Note: We must assign
|
|
|
|
// &animationCanceled after our block creation and copy -- its address
|
|
|
|
// isn't resolved until then!
|
|
|
|
mSwipeAnimationCancelled = &animationCancelled;
|
|
|
|
}
|
|
|
|
#endif // #ifdef __LP64__
|
|
|
|
|
2012-01-19 18:45:37 +04:00
|
|
|
- (void)setUsingOMTCompositor:(BOOL)aUseOMTC
|
|
|
|
{
|
|
|
|
mUsingOMTCompositor = aUseOMTC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-12 00:57:40 +03:00
|
|
|
// Returning NO from this method only disallows ordering on mousedown - in order
|
|
|
|
// to prevent it for mouseup too, we need to call [NSApp preventWindowOrdering]
|
|
|
|
// when handling the mousedown event.
|
|
|
|
- (BOOL)shouldDelayWindowOrderingForEvent:(NSEvent*)aEvent
|
|
|
|
{
|
|
|
|
// Always using system-provided window ordering for normal windows.
|
|
|
|
if (![[self window] isKindOfClass:[PopupWindow class]])
|
|
|
|
return NO;
|
|
|
|
|
2010-07-16 16:48:02 +04:00
|
|
|
// Don't reorder when we don't have a parent window, like when we're a
|
|
|
|
// context menu or a tooltip.
|
|
|
|
return ![[self window] parentWindow];
|
2009-12-12 00:57:40 +03:00
|
|
|
}
|
|
|
|
|
2007-11-27 02:19:04 +03:00
|
|
|
- (void)mouseDown:(NSEvent*)theEvent
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2009-12-12 00:57:40 +03:00
|
|
|
if ([self shouldDelayWindowOrderingForEvent:theEvent]) {
|
|
|
|
[NSApp preventWindowOrdering];
|
|
|
|
}
|
|
|
|
|
2008-04-07 03:52:05 +04:00
|
|
|
// If we've already seen this event due to direct dispatch from menuForEvent:
|
|
|
|
// just bail; if not, remember it.
|
|
|
|
if (mLastMouseDownEvent == theEvent) {
|
|
|
|
[mLastMouseDownEvent release];
|
|
|
|
mLastMouseDownEvent = nil;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[mLastMouseDownEvent release];
|
|
|
|
mLastMouseDownEvent = [theEvent retain];
|
|
|
|
}
|
|
|
|
|
2009-11-06 13:21:41 +03:00
|
|
|
[gLastDragMouseDownEvent release];
|
|
|
|
gLastDragMouseDownEvent = [theEvent retain];
|
|
|
|
|
2010-07-16 16:48:02 +04:00
|
|
|
// We need isClickThrough because at this point the window we're in might
|
|
|
|
// already have become main, so the check for isMainWindow in
|
|
|
|
// WindowAcceptsEvent isn't enough. It also has to check isClickThrough.
|
|
|
|
BOOL isClickThrough = (theEvent == mClickThroughMouseDownEvent);
|
|
|
|
[mClickThroughMouseDownEvent release];
|
|
|
|
mClickThroughMouseDownEvent = nil;
|
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
if ([self maybeRollup:theEvent] ||
|
2010-07-16 16:48:02 +04:00
|
|
|
!ChildViewMouseTracker::WindowAcceptsEvent([self window], theEvent, self, isClickThrough)) {
|
|
|
|
// Remember blocking because that means we want to block mouseup as well.
|
|
|
|
mBlockedLastMouseDown = YES;
|
2007-11-27 02:19:04 +03:00
|
|
|
return;
|
2010-07-16 16:48:02 +04:00
|
|
|
}
|
2007-11-27 02:19:04 +03:00
|
|
|
|
2004-02-18 19:18:38 +03:00
|
|
|
#if USE_CLICK_HOLD_CONTEXTMENU
|
2004-01-15 22:01:49 +03:00
|
|
|
// fire off timer to check for click-hold after two seconds. retains |theEvent|
|
|
|
|
[self performSelector:@selector(clickHoldCallback:) withObject:theEvent afterDelay:2.0];
|
2004-02-18 19:18:38 +03:00
|
|
|
#endif
|
2004-01-15 22:01:49 +03:00
|
|
|
|
2007-04-20 00:18:46 +04:00
|
|
|
// in order to send gecko events we'll need a gecko widget
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2010-02-24 02:30:39 +03:00
|
|
|
NSUInteger modifierFlags = [theEvent modifierFlags];
|
2009-08-27 04:29:47 +04:00
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, nsMouseEvent::eReal);
|
2007-06-13 00:28:26 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
2010-07-16 16:48:02 +04:00
|
|
|
|
|
|
|
NSInteger clickCount = [theEvent clickCount];
|
|
|
|
if (mBlockedLastMouseDown && clickCount > 1) {
|
|
|
|
// Don't send a double click if the first click of the double click was
|
|
|
|
// blocked.
|
|
|
|
clickCount--;
|
|
|
|
}
|
|
|
|
geckoEvent.clickCount = clickCount;
|
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
if (modifierFlags & NSControlKeyMask)
|
2006-12-05 21:38:17 +03:00
|
|
|
geckoEvent.button = nsMouseEvent::eRightButton;
|
|
|
|
else
|
|
|
|
geckoEvent.button = nsMouseEvent::eLeftButton;
|
2002-04-27 04:19:49 +04:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
// Create event for use by plugins.
|
|
|
|
// This is going to our child view so we don't need to look up the destination
|
|
|
|
// event type.
|
2009-09-01 05:00:13 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2009-08-27 04:29:47 +04:00
|
|
|
EventRecord carbonEvent;
|
2009-09-01 05:00:13 +04:00
|
|
|
if (mPluginEventModel == NPEventModelCarbon) {
|
2009-08-27 04:29:47 +04:00
|
|
|
carbonEvent.what = mouseDown;
|
|
|
|
carbonEvent.message = 0;
|
|
|
|
carbonEvent.when = ::TickCount();
|
|
|
|
::GetGlobalMouse(&carbonEvent.where);
|
2009-09-26 00:10:04 +04:00
|
|
|
carbonEvent.modifiers = ::GetCurrentKeyModifiers();
|
2009-11-11 00:55:38 +03:00
|
|
|
geckoEvent.pluginEvent = &carbonEvent;
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
|
|
|
NPCocoaEvent cocoaEvent;
|
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2009-08-27 04:29:47 +04:00
|
|
|
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
cocoaEvent.type = NPCocoaEventMouseDown;
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = modifierFlags;
|
|
|
|
cocoaEvent.data.mouse.pluginX = point.x;
|
|
|
|
cocoaEvent.data.mouse.pluginY = point.y;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [theEvent buttonNumber];
|
2010-07-16 16:48:02 +04:00
|
|
|
cocoaEvent.data.mouse.clickCount = clickCount;
|
2009-08-27 04:29:47 +04:00
|
|
|
cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
|
|
|
|
cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
|
|
|
|
cocoaEvent.data.mouse.deltaZ = [theEvent deltaZ];
|
2009-11-11 00:55:38 +03:00
|
|
|
geckoEvent.pluginEvent = &cocoaEvent;
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2002-04-27 04:19:49 +04:00
|
|
|
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2010-07-16 16:48:02 +04:00
|
|
|
mBlockedLastMouseDown = NO;
|
2007-04-20 00:18:46 +04:00
|
|
|
|
2005-06-26 07:25:52 +04:00
|
|
|
// XXX maybe call markedTextSelectionChanged:client: here?
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2005-06-26 07:25:52 +04:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *)theEvent
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2010-07-16 16:48:02 +04:00
|
|
|
if (!mGeckoChild || mBlockedLastMouseDown)
|
2007-06-13 00:28:26 +04:00
|
|
|
return;
|
|
|
|
|
2010-01-22 23:57:04 +03:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
|
2011-04-01 03:31:32 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
EventRecord carbonEvent;
|
|
|
|
#endif // ifndef NP_NO_CARBON
|
|
|
|
NPCocoaEvent cocoaEvent;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, nsMouseEvent::eReal);
|
2007-06-13 00:28:26 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
2010-02-24 02:30:39 +03:00
|
|
|
if ([theEvent modifierFlags] & NSControlKeyMask)
|
2008-09-15 16:50:59 +04:00
|
|
|
geckoEvent.button = nsMouseEvent::eRightButton;
|
|
|
|
else
|
|
|
|
geckoEvent.button = nsMouseEvent::eLeftButton;
|
2002-04-27 04:19:49 +04:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
// Create event for use by plugins.
|
|
|
|
// This is going to our child view so we don't need to look up the destination
|
|
|
|
// event type.
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mIsPluginView) {
|
2009-09-01 05:00:13 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mPluginEventModel == NPEventModelCarbon) {
|
|
|
|
carbonEvent.what = mouseUp;
|
|
|
|
carbonEvent.message = 0;
|
|
|
|
carbonEvent.when = ::TickCount();
|
|
|
|
::GetGlobalMouse(&carbonEvent.where);
|
|
|
|
carbonEvent.modifiers = ::GetCurrentKeyModifiers();
|
|
|
|
geckoEvent.pluginEvent = &carbonEvent;
|
|
|
|
}
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2010-01-22 23:57:04 +03:00
|
|
|
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
cocoaEvent.type = NPCocoaEventMouseUp;
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = [theEvent modifierFlags];
|
|
|
|
cocoaEvent.data.mouse.pluginX = point.x;
|
|
|
|
cocoaEvent.data.mouse.pluginY = point.y;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [theEvent buttonNumber];
|
|
|
|
cocoaEvent.data.mouse.clickCount = [theEvent clickCount];
|
|
|
|
cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
|
|
|
|
cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
|
|
|
|
cocoaEvent.data.mouse.deltaZ = [theEvent deltaZ];
|
|
|
|
geckoEvent.pluginEvent = &cocoaEvent;
|
|
|
|
}
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2002-04-27 04:19:49 +04:00
|
|
|
|
2010-03-03 01:04:13 +03:00
|
|
|
// This might destroy our widget (and null out mGeckoChild).
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2010-01-22 23:57:04 +03:00
|
|
|
// If our mouse-up event's location is over some other object (as might
|
|
|
|
// happen if it came at the end of a dragging operation), also send our
|
|
|
|
// Gecko frame a mouse-exit event.
|
2010-03-03 01:04:13 +03:00
|
|
|
if (mGeckoChild && mIsPluginView) {
|
2010-01-22 23:57:04 +03:00
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
if (mPluginEventModel == NPEventModelCocoa)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (ChildViewMouseTracker::ViewForEvent(theEvent) != self) {
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoExitEvent(true, NS_MOUSE_EXIT, mGeckoChild, nsMouseEvent::eReal);
|
2010-01-22 23:57:04 +03:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoExitEvent];
|
|
|
|
|
|
|
|
NPCocoaEvent cocoaEvent;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2010-01-22 23:57:04 +03:00
|
|
|
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
cocoaEvent.type = NPCocoaEventMouseExited;
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = [theEvent modifierFlags];
|
|
|
|
cocoaEvent.data.mouse.pluginX = point.x;
|
|
|
|
cocoaEvent.data.mouse.pluginY = point.y;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [theEvent buttonNumber];
|
|
|
|
cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
|
|
|
|
cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
|
|
|
|
cocoaEvent.data.mouse.deltaZ = [theEvent deltaZ];
|
|
|
|
geckoExitEvent.pluginEvent = &cocoaEvent;
|
|
|
|
|
|
|
|
mGeckoChild->DispatchWindowEvent(geckoExitEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2005-06-26 07:25:52 +04:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
- (void)sendMouseEnterOrExitEvent:(NSEvent*)aEvent
|
|
|
|
enter:(BOOL)aEnter
|
|
|
|
type:(nsMouseEvent::exitType)aType
|
2007-04-11 00:07:49 +04:00
|
|
|
{
|
2009-09-23 06:31:37 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
NSPoint windowEventLocation = nsCocoaUtils::EventLocationForWindow(aEvent, [self window]);
|
|
|
|
NSPoint localEventLocation = [self convertPoint:windowEventLocation fromView:nil];
|
2007-06-13 00:28:26 +04:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
PRUint32 msg = aEnter ? NS_MOUSE_ENTER : NS_MOUSE_EXIT;
|
2011-10-01 04:20:33 +04:00
|
|
|
nsMouseEvent event(true, msg, mGeckoChild, nsMouseEvent::eReal);
|
2009-09-23 06:31:37 +04:00
|
|
|
event.refPoint.x = nscoord((PRInt32)localEventLocation.x);
|
|
|
|
event.refPoint.y = nscoord((PRInt32)localEventLocation.y);
|
2007-06-13 00:28:26 +04:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
// Create event for use by plugins.
|
2009-09-23 06:31:37 +04:00
|
|
|
// This is going to our child view so we don't need to look up the destination
|
|
|
|
// event type.
|
2010-06-15 23:34:32 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2009-08-27 04:29:47 +04:00
|
|
|
EventRecord carbonEvent;
|
2010-06-15 23:34:32 +04:00
|
|
|
#endif
|
2009-09-01 05:00:13 +04:00
|
|
|
NPCocoaEvent cocoaEvent;
|
2009-11-10 02:08:42 +03:00
|
|
|
if (mIsPluginView) {
|
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
if (mPluginEventModel == NPEventModelCarbon) {
|
|
|
|
carbonEvent.what = NPEventType_AdjustCursorEvent;
|
|
|
|
carbonEvent.message = 0;
|
|
|
|
carbonEvent.when = ::TickCount();
|
|
|
|
::GetGlobalMouse(&carbonEvent.where);
|
|
|
|
carbonEvent.modifiers = ::GetCurrentKeyModifiers();
|
2009-11-11 00:55:38 +03:00
|
|
|
event.pluginEvent = &carbonEvent;
|
2009-11-10 02:08:42 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2009-11-10 02:08:42 +03:00
|
|
|
cocoaEvent.type = ((msg == NS_MOUSE_ENTER) ? NPCocoaEventMouseEntered : NPCocoaEventMouseExited);
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = [aEvent modifierFlags];
|
|
|
|
cocoaEvent.data.mouse.pluginX = 5;
|
|
|
|
cocoaEvent.data.mouse.pluginY = 5;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [aEvent buttonNumber];
|
|
|
|
cocoaEvent.data.mouse.deltaX = [aEvent deltaX];
|
|
|
|
cocoaEvent.data.mouse.deltaY = [aEvent deltaY];
|
|
|
|
cocoaEvent.data.mouse.deltaZ = [aEvent deltaZ];
|
2009-11-11 00:55:38 +03:00
|
|
|
event.pluginEvent = &cocoaEvent;
|
2010-05-14 21:24:42 +04:00
|
|
|
}
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2007-09-06 09:11:35 +04:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
event.exit = aType;
|
2008-04-09 21:23:34 +04:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
nsEventStatus status; // ignored
|
|
|
|
mGeckoChild->DispatchEvent(&event, status);
|
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
- (void)handleMouseMoved:(NSEvent*)theEvent
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
|
2007-06-13 00:28:26 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
// Create event for use by plugins.
|
|
|
|
// This is going to our child view so we don't need to look up the destination
|
|
|
|
// event type.
|
2010-06-15 23:34:32 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2009-08-27 04:29:47 +04:00
|
|
|
EventRecord carbonEvent;
|
2010-06-15 23:34:32 +04:00
|
|
|
#endif
|
2009-09-01 05:00:13 +04:00
|
|
|
NPCocoaEvent cocoaEvent;
|
2009-11-10 02:08:42 +03:00
|
|
|
if (mIsPluginView) {
|
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
if (mPluginEventModel == NPEventModelCarbon) {
|
|
|
|
carbonEvent.what = NPEventType_AdjustCursorEvent;
|
|
|
|
carbonEvent.message = 0;
|
|
|
|
carbonEvent.when = ::TickCount();
|
|
|
|
::GetGlobalMouse(&carbonEvent.where);
|
|
|
|
carbonEvent.modifiers = ::GetCurrentKeyModifiers();
|
2009-11-11 00:55:38 +03:00
|
|
|
geckoEvent.pluginEvent = &carbonEvent;
|
2009-11-10 02:08:42 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2009-11-10 02:08:42 +03:00
|
|
|
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
cocoaEvent.type = NPCocoaEventMouseMoved;
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = [theEvent modifierFlags];
|
|
|
|
cocoaEvent.data.mouse.pluginX = point.x;
|
|
|
|
cocoaEvent.data.mouse.pluginY = point.y;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [theEvent buttonNumber];
|
|
|
|
cocoaEvent.data.mouse.clickCount = [theEvent clickCount];
|
|
|
|
cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
|
|
|
|
cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
|
|
|
|
cocoaEvent.data.mouse.deltaZ = [theEvent deltaZ];
|
2009-11-11 00:55:38 +03:00
|
|
|
geckoEvent.pluginEvent = &cocoaEvent;
|
2009-11-10 02:08:42 +03:00
|
|
|
}
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent*)theEvent
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2007-09-24 04:01:04 +04:00
|
|
|
gLastDragView = self;
|
2006-10-26 02:45:22 +04:00
|
|
|
|
2011-04-01 03:31:32 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
EventRecord carbonEvent;
|
|
|
|
#endif // ifndef NP_NO_CARBON
|
|
|
|
NPCocoaEvent cocoaEvent;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
|
2007-06-13 00:28:26 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
// create event for use by plugins
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mIsPluginView) {
|
2009-09-01 05:00:13 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mPluginEventModel == NPEventModelCarbon) {
|
|
|
|
carbonEvent.what = NPEventType_AdjustCursorEvent;
|
|
|
|
carbonEvent.message = 0;
|
|
|
|
carbonEvent.when = ::TickCount();
|
|
|
|
::GetGlobalMouse(&carbonEvent.where);
|
|
|
|
carbonEvent.modifiers = btnState | ::GetCurrentKeyModifiers();
|
|
|
|
geckoEvent.pluginEvent = &carbonEvent;
|
|
|
|
}
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2010-01-22 23:57:04 +03:00
|
|
|
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
cocoaEvent.type = NPCocoaEventMouseDragged;
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = [theEvent modifierFlags];
|
|
|
|
cocoaEvent.data.mouse.pluginX = point.x;
|
|
|
|
cocoaEvent.data.mouse.pluginY = point.y;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [theEvent buttonNumber];
|
|
|
|
cocoaEvent.data.mouse.clickCount = [theEvent clickCount];
|
|
|
|
cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
|
|
|
|
cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
|
|
|
|
cocoaEvent.data.mouse.deltaZ = [theEvent deltaZ];
|
|
|
|
geckoEvent.pluginEvent = &cocoaEvent;
|
|
|
|
}
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2007-06-13 00:28:26 +04:00
|
|
|
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2008-01-16 02:11:55 +03:00
|
|
|
|
|
|
|
// Note, sending the above event might have destroyed our widget since we didn't retain.
|
|
|
|
// Fine so long as we don't access any local variables from here on.
|
2007-09-24 04:01:04 +04:00
|
|
|
gLastDragView = nil;
|
2009-11-06 13:21:41 +03:00
|
|
|
|
2005-06-26 07:25:52 +04:00
|
|
|
// XXX maybe call markedTextSelectionChanged:client: here?
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2002-12-13 11:43:18 +03:00
|
|
|
- (void)rightMouseDown:(NSEvent *)theEvent
|
2007-11-07 10:53:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:21 +03:00
|
|
|
|
2008-01-16 02:11:55 +03:00
|
|
|
[self maybeRollup:theEvent];
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
2007-11-27 02:19:04 +03:00
|
|
|
|
2006-06-13 01:05:36 +04:00
|
|
|
// The right mouse went down, fire off a right mouse down event to gecko
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, nsMouseEvent::eReal);
|
2007-06-13 00:28:26 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
2006-11-17 00:35:39 +03:00
|
|
|
geckoEvent.button = nsMouseEvent::eRightButton;
|
2007-06-13 00:28:26 +04:00
|
|
|
geckoEvent.clickCount = [theEvent clickCount];
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
// create event for use by plugins
|
2009-09-01 05:00:13 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2009-08-27 04:29:47 +04:00
|
|
|
EventRecord carbonEvent;
|
2009-09-01 05:00:13 +04:00
|
|
|
if (mPluginEventModel == NPEventModelCarbon) {
|
2009-08-27 04:29:47 +04:00
|
|
|
carbonEvent.what = mouseDown;
|
|
|
|
carbonEvent.message = 0;
|
|
|
|
carbonEvent.when = ::TickCount();
|
|
|
|
::GetGlobalMouse(&carbonEvent.where);
|
|
|
|
carbonEvent.modifiers = controlKey; // fake a context menu click
|
2009-11-11 00:55:38 +03:00
|
|
|
geckoEvent.pluginEvent = &carbonEvent;
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
|
|
|
NPCocoaEvent cocoaEvent;
|
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2009-08-27 04:29:47 +04:00
|
|
|
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
cocoaEvent.type = NPCocoaEventMouseDown;
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = [theEvent modifierFlags];
|
|
|
|
cocoaEvent.data.mouse.pluginX = point.x;
|
|
|
|
cocoaEvent.data.mouse.pluginY = point.y;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [theEvent buttonNumber];
|
|
|
|
cocoaEvent.data.mouse.clickCount = [theEvent clickCount];
|
|
|
|
cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
|
|
|
|
cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
|
|
|
|
cocoaEvent.data.mouse.deltaZ = [theEvent deltaZ];
|
2009-11-11 00:55:38 +03:00
|
|
|
geckoEvent.pluginEvent = &cocoaEvent;
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2011-06-02 05:18:27 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2008-01-16 02:11:55 +03:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2011-06-02 05:18:27 +04:00
|
|
|
// Let the superclass do the context menu stuff.
|
|
|
|
[super rightMouseDown:theEvent];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseUp:(NSEvent *)theEvent
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2011-04-01 03:31:32 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
|
|
|
EventRecord carbonEvent;
|
|
|
|
#endif // ifndef NP_NO_CARBON
|
|
|
|
NPCocoaEvent cocoaEvent;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, nsMouseEvent::eReal);
|
2007-06-13 00:28:26 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
2006-11-17 00:35:39 +03:00
|
|
|
geckoEvent.button = nsMouseEvent::eRightButton;
|
2007-06-13 00:28:26 +04:00
|
|
|
geckoEvent.clickCount = [theEvent clickCount];
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2009-08-27 04:29:47 +04:00
|
|
|
// create event for use by plugins
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mIsPluginView) {
|
2009-09-01 05:00:13 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mPluginEventModel == NPEventModelCarbon) {
|
|
|
|
carbonEvent.what = mouseUp;
|
|
|
|
carbonEvent.message = 0;
|
|
|
|
carbonEvent.when = ::TickCount();
|
|
|
|
::GetGlobalMouse(&carbonEvent.where);
|
|
|
|
carbonEvent.modifiers = controlKey; // fake a context menu click
|
|
|
|
geckoEvent.pluginEvent = &carbonEvent;
|
|
|
|
}
|
2009-09-01 05:00:13 +04:00
|
|
|
#endif
|
2010-01-22 23:57:04 +03:00
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2010-01-22 23:57:04 +03:00
|
|
|
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
cocoaEvent.type = NPCocoaEventMouseUp;
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = [theEvent modifierFlags];
|
|
|
|
cocoaEvent.data.mouse.pluginX = point.x;
|
|
|
|
cocoaEvent.data.mouse.pluginY = point.y;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [theEvent buttonNumber];
|
|
|
|
cocoaEvent.data.mouse.clickCount = [theEvent clickCount];
|
|
|
|
cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
|
|
|
|
cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
|
|
|
|
cocoaEvent.data.mouse.deltaZ = [theEvent deltaZ];
|
|
|
|
geckoEvent.pluginEvent = &cocoaEvent;
|
|
|
|
}
|
2009-08-27 04:29:47 +04:00
|
|
|
}
|
2002-12-13 11:43:18 +03:00
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2007-07-18 00:29:39 +04:00
|
|
|
- (void)rightMouseDragged:(NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
|
2007-07-18 00:29:39 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
|
|
|
geckoEvent.button = nsMouseEvent::eRightButton;
|
|
|
|
|
|
|
|
// send event into Gecko by going directly to the
|
|
|
|
// the widget.
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2007-07-18 00:29:39 +04:00
|
|
|
}
|
|
|
|
|
2002-03-10 02:09:34 +03:00
|
|
|
- (void)otherMouseDown:(NSEvent *)theEvent
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
if ([self maybeRollup:theEvent] ||
|
2010-07-16 16:48:02 +04:00
|
|
|
!ChildViewMouseTracker::WindowAcceptsEvent([self window], theEvent, self))
|
2007-11-27 02:19:04 +03:00
|
|
|
return;
|
2007-07-18 00:29:39 +04:00
|
|
|
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, nsMouseEvent::eReal);
|
2007-06-13 00:28:26 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
2006-11-17 00:35:39 +03:00
|
|
|
geckoEvent.button = nsMouseEvent::eMiddleButton;
|
2007-06-13 00:28:26 +04:00
|
|
|
geckoEvent.clickCount = [theEvent clickCount];
|
|
|
|
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-12-20 05:13:57 +03:00
|
|
|
}
|
2002-03-10 02:09:34 +03:00
|
|
|
|
|
|
|
- (void)otherMouseUp:(NSEvent *)theEvent
|
|
|
|
{
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, nsMouseEvent::eReal);
|
2007-06-13 00:28:26 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
2006-11-17 00:35:39 +03:00
|
|
|
geckoEvent.button = nsMouseEvent::eMiddleButton;
|
|
|
|
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2006-12-20 05:13:57 +03:00
|
|
|
}
|
|
|
|
|
2007-07-18 00:29:39 +04:00
|
|
|
- (void)otherMouseDragged:(NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
|
2007-07-18 00:29:39 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
|
|
|
geckoEvent.button = nsMouseEvent::eMiddleButton;
|
|
|
|
|
|
|
|
// send event into Gecko by going directly to the
|
|
|
|
// the widget.
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2007-07-18 00:29:39 +04:00
|
|
|
}
|
|
|
|
|
2005-07-20 02:54:07 +04:00
|
|
|
// Handle an NSScrollWheel event for a single axis only.
|
|
|
|
-(void)scrollWheel:(NSEvent*)theEvent forAxis:(enum nsMouseScrollEvent::nsMouseScrollFlags)inAxis
|
2002-02-17 22:09:07 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
float scrollDelta = 0;
|
|
|
|
float scrollDeltaPixels = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool checkPixels =
|
2011-10-01 04:20:33 +04:00
|
|
|
Preferences::GetBool("mousewheel.enable_pixel_scrolling", true);
|
2008-09-17 15:27:19 +04:00
|
|
|
|
|
|
|
// Calling deviceDeltaX or deviceDeltaY on theEvent will trigger a Cocoa
|
|
|
|
// assertion and an Objective-C NSInternalInconsistencyException if the
|
|
|
|
// underlying "Carbon" event doesn't contain pixel scrolling information.
|
|
|
|
// For these events, carbonEventKind is kEventMouseWheelMoved instead of
|
|
|
|
// kEventMouseScroll.
|
2009-09-28 10:01:05 +04:00
|
|
|
if (checkPixels) {
|
|
|
|
EventRef theCarbonEvent = [theEvent _eventRef];
|
|
|
|
UInt32 carbonEventKind = theCarbonEvent ? ::GetEventKind(theCarbonEvent) : 0;
|
2010-02-23 23:10:25 +03:00
|
|
|
if (carbonEventKind != kEventMouseScroll)
|
2011-10-01 04:20:33 +04:00
|
|
|
checkPixels = false;
|
2009-09-28 10:01:05 +04:00
|
|
|
}
|
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
// Some scrolling devices supports pixel scrolling, e.g. a Macbook
|
2012-06-20 22:34:45 +04:00
|
|
|
// touchpad or a Mighty Mouse. On those devices, [theEvent deviceDeltaX/Y]
|
|
|
|
// contains the amount of pixels to scroll. Since Lion this has changed
|
|
|
|
// to [theEvent scrollingDeltaX/Y].
|
2008-09-17 15:27:19 +04:00
|
|
|
if (inAxis & nsMouseScrollEvent::kIsVertical) {
|
|
|
|
scrollDelta = -[theEvent deltaY];
|
|
|
|
if (checkPixels && (scrollDelta == 0 || scrollDelta != floor(scrollDelta))) {
|
2012-06-20 22:34:45 +04:00
|
|
|
if ([theEvent respondsToSelector:@selector(scrollingDeltaY)]) {
|
|
|
|
scrollDeltaPixels = -[theEvent scrollingDeltaY];
|
|
|
|
} else {
|
|
|
|
scrollDeltaPixels = -[theEvent deviceDeltaY];
|
|
|
|
}
|
2008-09-17 15:27:19 +04:00
|
|
|
}
|
|
|
|
} else if (inAxis & nsMouseScrollEvent::kIsHorizontal) {
|
|
|
|
scrollDelta = -[theEvent deltaX];
|
|
|
|
if (checkPixels && (scrollDelta == 0 || scrollDelta != floor(scrollDelta))) {
|
2012-06-20 22:34:45 +04:00
|
|
|
if ([theEvent respondsToSelector:@selector(scrollingDeltaX)]) {
|
|
|
|
scrollDeltaPixels = -[theEvent scrollingDeltaX];
|
|
|
|
} else {
|
|
|
|
scrollDeltaPixels = -[theEvent deviceDeltaX];
|
|
|
|
}
|
2008-09-17 15:27:19 +04:00
|
|
|
}
|
|
|
|
} else {
|
2008-01-16 02:11:55 +03:00
|
|
|
return; // caller screwed up
|
2008-09-17 15:27:19 +04:00
|
|
|
}
|
2005-07-20 02:54:07 +04:00
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
BOOL hasPixels = (scrollDeltaPixels != 0);
|
2005-07-20 02:54:07 +04:00
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
if (!hasPixels && scrollDelta == 0)
|
|
|
|
// No sense in firing off a Gecko event.
|
|
|
|
return;
|
2003-01-08 09:43:08 +03:00
|
|
|
|
2011-08-18 02:30:52 +04:00
|
|
|
BOOL isMomentumScroll = nsCocoaUtils::IsMomentumScrollEvent(theEvent);
|
2010-11-05 19:04:28 +03:00
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
if (scrollDelta != 0) {
|
|
|
|
// Send the line scroll event.
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseScrollEvent geckoEvent(true, NS_MOUSE_SCROLL, mGeckoChild);
|
2008-09-17 15:27:19 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
|
|
|
geckoEvent.scrollFlags |= inAxis;
|
2005-07-25 19:56:25 +04:00
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
if (hasPixels)
|
|
|
|
geckoEvent.scrollFlags |= nsMouseScrollEvent::kHasPixels;
|
|
|
|
|
2010-11-05 19:04:28 +03:00
|
|
|
if (isMomentumScroll)
|
|
|
|
geckoEvent.scrollFlags |= nsMouseScrollEvent::kIsMomentum;
|
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
// Gecko only understands how to scroll by an integer value. Using floor
|
|
|
|
// and ceil is better than truncating the fraction, especially when
|
|
|
|
// |delta| < 1.
|
|
|
|
if (scrollDelta < 0)
|
|
|
|
geckoEvent.delta = (PRInt32)floorf(scrollDelta);
|
|
|
|
else
|
|
|
|
geckoEvent.delta = (PRInt32)ceilf(scrollDelta);
|
|
|
|
|
2009-11-09 00:51:46 +03:00
|
|
|
NPCocoaEvent cocoaEvent;
|
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2009-11-09 00:51:46 +03:00
|
|
|
NSPoint point = [self convertPoint:[theEvent locationInWindow] fromView:nil];
|
|
|
|
cocoaEvent.type = NPCocoaEventScrollWheel;
|
|
|
|
cocoaEvent.data.mouse.modifierFlags = [theEvent modifierFlags];
|
|
|
|
cocoaEvent.data.mouse.pluginX = point.x;
|
|
|
|
cocoaEvent.data.mouse.pluginY = point.y;
|
|
|
|
cocoaEvent.data.mouse.buttonNumber = [theEvent buttonNumber];
|
|
|
|
cocoaEvent.data.mouse.clickCount = 0;
|
|
|
|
if (inAxis & nsMouseScrollEvent::kIsHorizontal)
|
|
|
|
cocoaEvent.data.mouse.deltaX = [theEvent deltaX];
|
|
|
|
else
|
|
|
|
cocoaEvent.data.mouse.deltaX = 0.0;
|
|
|
|
if (inAxis & nsMouseScrollEvent::kIsVertical)
|
|
|
|
cocoaEvent.data.mouse.deltaY = [theEvent deltaY];
|
|
|
|
else
|
|
|
|
cocoaEvent.data.mouse.deltaY = 0.0;
|
|
|
|
cocoaEvent.data.mouse.deltaZ = 0.0;
|
2009-11-11 00:55:38 +03:00
|
|
|
geckoEvent.pluginEvent = &cocoaEvent;
|
2009-11-09 00:51:46 +03:00
|
|
|
}
|
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return;
|
|
|
|
|
2009-09-28 10:01:05 +04:00
|
|
|
#ifndef NP_NO_CARBON
|
2008-09-17 15:27:19 +04:00
|
|
|
// dispatch scroll wheel carbon event for plugins
|
2009-09-28 10:01:05 +04:00
|
|
|
if (mPluginEventModel == NPEventModelCarbon) {
|
2008-09-17 15:27:19 +04:00
|
|
|
EventRef theEvent;
|
2008-10-30 08:36:01 +03:00
|
|
|
OSStatus err = ::CreateEvent(NULL,
|
|
|
|
kEventClassMouse,
|
|
|
|
kEventMouseWheelMoved,
|
|
|
|
TicksToEventTime(TickCount()),
|
|
|
|
kEventAttributeUserEvent,
|
|
|
|
&theEvent);
|
2008-09-17 15:27:19 +04:00
|
|
|
if (err == noErr) {
|
|
|
|
EventMouseWheelAxis axis;
|
|
|
|
if (inAxis & nsMouseScrollEvent::kIsVertical)
|
|
|
|
axis = kEventMouseWheelAxisY;
|
|
|
|
else if (inAxis & nsMouseScrollEvent::kIsHorizontal)
|
|
|
|
axis = kEventMouseWheelAxisX;
|
|
|
|
|
|
|
|
SetEventParameter(theEvent,
|
|
|
|
kEventParamMouseWheelAxis,
|
|
|
|
typeMouseWheelAxis,
|
|
|
|
sizeof(EventMouseWheelAxis),
|
|
|
|
&axis);
|
|
|
|
|
|
|
|
SInt32 delta = (SInt32)-geckoEvent.delta;
|
|
|
|
SetEventParameter(theEvent,
|
|
|
|
kEventParamMouseWheelDelta,
|
|
|
|
typeLongInteger,
|
|
|
|
sizeof(SInt32),
|
|
|
|
&delta);
|
|
|
|
|
|
|
|
Point mouseLoc;
|
|
|
|
::GetGlobalMouse(&mouseLoc);
|
|
|
|
SetEventParameter(theEvent,
|
|
|
|
kEventParamMouseLocation,
|
|
|
|
typeQDPoint,
|
|
|
|
sizeof(Point),
|
|
|
|
&mouseLoc);
|
|
|
|
|
|
|
|
::SendEventToEventTarget(theEvent, GetWindowEventTarget((WindowRef)[[self window] windowRef]));
|
|
|
|
ReleaseEvent(theEvent);
|
|
|
|
}
|
2005-07-25 19:56:25 +04:00
|
|
|
}
|
2009-09-28 10:01:05 +04:00
|
|
|
#endif
|
2005-07-25 19:56:25 +04:00
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2008-09-17 15:27:19 +04:00
|
|
|
if (hasPixels) {
|
|
|
|
// Send the pixel scroll event.
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseScrollEvent geckoEvent(true, NS_MOUSE_PIXEL_SCROLL, mGeckoChild);
|
2008-09-17 15:27:19 +04:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
|
|
|
geckoEvent.scrollFlags |= inAxis;
|
2010-11-05 19:04:28 +03:00
|
|
|
if (isMomentumScroll)
|
|
|
|
geckoEvent.scrollFlags |= nsMouseScrollEvent::kIsMomentum;
|
2008-09-17 15:27:19 +04:00
|
|
|
geckoEvent.delta = NSToIntRound(scrollDeltaPixels);
|
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2011-08-11 21:42:23 +04:00
|
|
|
#ifdef __LP64__
|
|
|
|
// scrollOverflow tells us when the user has tried to scroll past the edge
|
|
|
|
// of a page (in those cases it's non-zero). Gecko only sets it when
|
|
|
|
// processing NS_MOUSE_PIXEL_SCROLL events (not MS_MOUSE_SCROLL events).
|
|
|
|
// It only means left/right overflow when Gecko is processing a horizontal
|
|
|
|
// event.
|
|
|
|
if (inAxis & nsMouseScrollEvent::kIsHorizontal) {
|
|
|
|
[self maybeTrackScrollEventAsSwipe:theEvent
|
|
|
|
scrollOverflow:geckoEvent.scrollOverflow];
|
|
|
|
}
|
|
|
|
#endif // #ifdef __LP64__
|
2008-09-17 15:27:19 +04:00
|
|
|
}
|
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2002-02-17 22:09:07 +03:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2005-07-20 02:54:07 +04:00
|
|
|
-(void)scrollWheel:(NSEvent*)theEvent
|
|
|
|
{
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2011-08-18 02:30:52 +04:00
|
|
|
ChildViewMouseTracker::MouseScrolled(theEvent);
|
2007-11-27 02:19:04 +03:00
|
|
|
|
2011-08-18 02:30:52 +04:00
|
|
|
if ([self maybeRollup:theEvent])
|
2008-01-16 02:11:55 +03:00
|
|
|
return;
|
|
|
|
|
2005-07-20 02:54:07 +04:00
|
|
|
// It's possible for a single NSScrollWheel event to carry both useful
|
|
|
|
// deltaX and deltaY, for example, when the "wheel" is a trackpad.
|
|
|
|
// NSMouseScrollEvent can only carry one axis at a time, so the system
|
|
|
|
// event will be split into two Gecko events if necessary.
|
|
|
|
[self scrollWheel:theEvent forAxis:nsMouseScrollEvent::kIsVertical];
|
|
|
|
[self scrollWheel:theEvent forAxis:nsMouseScrollEvent::kIsHorizontal];
|
|
|
|
}
|
|
|
|
|
2005-06-16 16:49:43 +04:00
|
|
|
-(NSMenu*)menuForEvent:(NSEvent*)theEvent
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild || [self isPluginView])
|
2005-07-25 19:56:25 +04:00
|
|
|
return nil;
|
2007-08-21 05:02:09 +04:00
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2007-11-27 02:19:04 +03:00
|
|
|
[self maybeRollup:theEvent];
|
2008-01-16 02:11:55 +03:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return nil;
|
2007-11-27 02:19:04 +03:00
|
|
|
|
2008-04-07 03:52:05 +04:00
|
|
|
// Cocoa doesn't always dispatch a mouseDown: for a control-click event,
|
|
|
|
// depends on what we return from menuForEvent:. Gecko always expects one
|
|
|
|
// and expects the mouse down event before the context menu event, so
|
|
|
|
// get that event sent first if this is a left mouse click.
|
|
|
|
if ([theEvent type] == NSLeftMouseDown) {
|
|
|
|
[self mouseDown:theEvent];
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return nil;
|
|
|
|
}
|
2008-01-17 07:59:43 +03:00
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_CONTEXTMENU, mGeckoChild, nsMouseEvent::eReal);
|
2008-01-17 07:59:43 +03:00
|
|
|
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
|
|
|
|
geckoEvent.button = nsMouseEvent::eRightButton;
|
2008-08-26 04:02:26 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2008-01-17 07:59:43 +03:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return nil;
|
|
|
|
|
2008-03-04 11:06:47 +03:00
|
|
|
[self maybeInitContextMenuTracking];
|
2008-02-28 18:58:33 +03:00
|
|
|
|
2005-06-16 16:49:43 +04:00
|
|
|
// Go up our view chain to fetch the correct menu to return.
|
2006-07-31 02:55:37 +04:00
|
|
|
return [self contextMenu];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2005-06-16 16:49:43 +04:00
|
|
|
}
|
|
|
|
|
2006-07-31 02:55:37 +04:00
|
|
|
- (NSMenu*)contextMenu
|
2005-06-16 16:49:43 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2005-09-30 04:59:29 +04:00
|
|
|
NSView* superView = [self superview];
|
2006-07-31 02:55:37 +04:00
|
|
|
if ([superView respondsToSelector:@selector(contextMenu)])
|
|
|
|
return [(NSView<mozView>*)superView contextMenu];
|
2005-09-30 04:59:29 +04:00
|
|
|
|
|
|
|
return nil;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2005-06-16 16:49:43 +04:00
|
|
|
}
|
|
|
|
|
2007-06-13 00:28:26 +04:00
|
|
|
- (void) convertCocoaMouseEvent:(NSEvent*)aMouseEvent toGeckoEvent:(nsInputEvent*)outGeckoEvent
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2010-07-16 16:48:02 +04:00
|
|
|
NS_ASSERTION(outGeckoEvent, "convertCocoaMouseEvent:toGeckoEvent: requires non-null aoutGeckoEvent");
|
|
|
|
if (!outGeckoEvent)
|
2007-06-13 00:28:26 +04:00
|
|
|
return;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsCocoaUtils::InitInputEvent(*outGeckoEvent, aMouseEvent);
|
2007-06-13 00:28:26 +04:00
|
|
|
|
|
|
|
// convert point to view coordinate system
|
2009-09-16 01:56:44 +04:00
|
|
|
NSPoint locationInWindow = nsCocoaUtils::EventLocationForWindow(aMouseEvent, [self window]);
|
2009-08-18 06:36:15 +04:00
|
|
|
NSPoint localPoint = [self convertPoint:locationInWindow fromView:nil];
|
2007-07-08 11:08:04 +04:00
|
|
|
outGeckoEvent->refPoint.x = static_cast<nscoord>(localPoint.x);
|
|
|
|
outGeckoEvent->refPoint.y = static_cast<nscoord>(localPoint.y);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2012-04-25 07:00:01 +04:00
|
|
|
nsMouseEvent_base* mouseEvent =
|
|
|
|
static_cast<nsMouseEvent_base*>(outGeckoEvent);
|
|
|
|
mouseEvent->buttons = 0;
|
|
|
|
NSUInteger mouseButtons =
|
2012-05-17 11:53:20 +04:00
|
|
|
nsCocoaFeatures::OnSnowLeopardOrLater() ? [NSEvent pressedMouseButtons] : 0;
|
2012-04-25 07:00:01 +04:00
|
|
|
|
|
|
|
if (mouseButtons & 0x01) {
|
|
|
|
mouseEvent->buttons |= nsMouseEvent::eLeftButtonFlag;
|
|
|
|
}
|
|
|
|
if (mouseButtons & 0x02) {
|
|
|
|
mouseEvent->buttons |= nsMouseEvent::eRightButtonFlag;
|
|
|
|
}
|
|
|
|
if (mouseButtons & 0x04) {
|
|
|
|
mouseEvent->buttons |= nsMouseEvent::eMiddleButtonFlag;
|
|
|
|
}
|
|
|
|
if (mouseButtons & 0x08) {
|
|
|
|
mouseEvent->buttons |= nsMouseEvent::e4thButtonFlag;
|
|
|
|
}
|
|
|
|
if (mouseButtons & 0x10) {
|
|
|
|
mouseEvent->buttons |= nsMouseEvent::e5thButtonFlag;
|
|
|
|
}
|
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-06-13 00:28:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
// NSTextInput implementation
|
|
|
|
|
|
|
|
- (void)insertText:(id)insertString
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
NS_ENSURE_TRUE(mGeckoChild, );
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2007-08-17 00:30:50 +04:00
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
NSAttributedString* attrStr;
|
|
|
|
if ([insertString isKindOfClass:[NSAttributedString class]]) {
|
|
|
|
attrStr = static_cast<NSAttributedString*>(insertString);
|
|
|
|
} else {
|
|
|
|
attrStr =
|
|
|
|
[[[NSAttributedString alloc] initWithString:insertString] autorelease];
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
mTextInputHandler->InsertText(attrStr);
|
2007-08-17 00:30:50 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)insertNewline:(id)sender
|
|
|
|
{
|
2008-03-05 01:32:55 +03:00
|
|
|
[self insertText:@"\n"];
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (void) doCommandBySelector:(SEL)aSelector
|
2008-02-21 02:47:05 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
2008-03-05 01:32:55 +03:00
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
if (!mGeckoChild || !mTextInputHandler) {
|
|
|
|
return;
|
|
|
|
}
|
2007-04-22 04:37:27 +04:00
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
const char* sel = reinterpret_cast<const char*>(aSelector);
|
|
|
|
if (!mTextInputHandler->DoCommandBySelector(sel)) {
|
2008-03-05 01:32:55 +03:00
|
|
|
[super doCommandBySelector:aSelector];
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, );
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2007-08-17 00:30:50 +04:00
|
|
|
|
2011-02-19 07:55:34 +03:00
|
|
|
NSAttributedString* attrStr;
|
|
|
|
if ([aString isKindOfClass:[NSAttributedString class]]) {
|
|
|
|
attrStr = static_cast<NSAttributedString*>(aString);
|
|
|
|
} else {
|
|
|
|
attrStr = [[[NSAttributedString alloc] initWithString:aString] autorelease];
|
2008-01-16 02:11:55 +03:00
|
|
|
}
|
2008-04-22 07:30:45 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
mTextInputHandler->SetMarkedText(attrStr, selRange);
|
2007-08-17 00:30:50 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (void) unmarkText
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, );
|
|
|
|
mTextInputHandler->CommitIMEComposition();
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (BOOL) hasMarkedText
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, NO);
|
|
|
|
return mTextInputHandler->HasMarkedText();
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2009-09-01 05:00:13 +04:00
|
|
|
- (NSInteger) conversationIdentifier
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, reinterpret_cast<NSInteger>(self));
|
|
|
|
return mTextInputHandler->ConversationIdentifier();
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (NSAttributedString *) attributedSubstringFromRange:(NSRange)theRange
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, nil);
|
|
|
|
return mTextInputHandler->GetAttributedSubstringFromRange(theRange);
|
2002-06-12 02:13:03 +04:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (NSRange) markedRange
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, NSMakeRange(NSNotFound, 0));
|
|
|
|
return mTextInputHandler->MarkedRange();
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSMakeRange(0, 0));
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (NSRange) selectedRange
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, NSMakeRange(NSNotFound, 0));
|
|
|
|
return mTextInputHandler->SelectedRange();
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSMakeRange(0, 0));
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (NSRect) firstRectForCharacterRange:(NSRange)theRange
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2008-02-20 10:40:04 +03:00
|
|
|
NSRect rect;
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, rect);
|
|
|
|
return mTextInputHandler->FirstRectForCharacterRange(theRange);
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2009-09-01 05:00:13 +04:00
|
|
|
- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, 0);
|
|
|
|
return mTextInputHandler->CharacterIndexForPoint(thePoint);
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (NSArray*) validAttributesForMarkedText
|
2002-12-13 11:43:18 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mTextInputHandler, [NSArray array]);
|
|
|
|
return mTextInputHandler->GetValidAttributesForMarkedText();
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2002-12-13 11:43:18 +03:00
|
|
|
}
|
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
#pragma mark -
|
|
|
|
|
2010-06-10 04:56:17 +04:00
|
|
|
#ifdef NP_NO_CARBON
|
|
|
|
- (NSTextInputContext *)inputContext
|
|
|
|
{
|
|
|
|
if (mIsPluginView && mPluginEventModel == NPEventModelCocoa)
|
|
|
|
return [[ComplexTextInputPanel sharedComplexTextInputPanel] inputContext];
|
|
|
|
else
|
|
|
|
return [super inputContext];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-17 07:26:17 +04:00
|
|
|
// This is a private API that Cocoa uses.
|
|
|
|
// Cocoa will call this after the menu system returns "NO" for "performKeyEquivalent:".
|
|
|
|
// We want all they key events we can get so just return YES. In particular, this fixes
|
|
|
|
// ctrl-tab - we don't get a "keyDown:" call for that without this.
|
|
|
|
- (BOOL)_wantsKeyDownForEvent:(NSEvent*)event
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2008-02-29 08:47:41 +03:00
|
|
|
- (void)keyDown:(NSEvent*)theEvent
|
|
|
|
{
|
2008-06-30 20:30:22 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
if (mGeckoChild && mTextInputHandler && mIsPluginView) {
|
2011-02-24 07:48:12 +03:00
|
|
|
mTextInputHandler->HandleKeyDownEventForPlugin(theEvent);
|
2008-06-30 20:30:22 +04:00
|
|
|
return;
|
2010-06-10 04:56:17 +04:00
|
|
|
}
|
2008-06-30 20:30:22 +04:00
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool handled = false;
|
2011-07-21 04:33:16 +04:00
|
|
|
if (mGeckoChild && mTextInputHandler) {
|
|
|
|
handled = mTextInputHandler->HandleKeyDownEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
2010-08-17 07:26:17 +04:00
|
|
|
// We always allow keyboard events to propagate to keyDown: but if they are not
|
|
|
|
// handled we give special Application menu items a chance to act.
|
|
|
|
if (!handled && sApplicationMenu) {
|
|
|
|
[sApplicationMenu performKeyEquivalent:theEvent];
|
|
|
|
}
|
2008-06-30 20:30:22 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2008-02-29 08:47:41 +03:00
|
|
|
}
|
|
|
|
|
2005-05-27 07:49:14 +04:00
|
|
|
- (void)keyUp:(NSEvent*)theEvent
|
2002-02-22 11:44:16 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
NS_ENSURE_TRUE(mGeckoChild, );
|
2011-01-21 04:08:11 +03:00
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2008-06-30 20:30:22 +04:00
|
|
|
if (mIsPluginView) {
|
2011-02-24 07:48:12 +03:00
|
|
|
mTextInputHandler->HandleKeyUpEventForPlugin(theEvent);
|
2008-06-30 20:30:22 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
mTextInputHandler->HandleKeyUpEvent(theEvent);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2002-02-22 11:44:16 +03:00
|
|
|
}
|
2001-11-15 01:29:25 +03:00
|
|
|
|
2003-03-13 23:37:32 +03:00
|
|
|
- (void)flagsChanged:(NSEvent*)theEvent
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
NS_ENSURE_TRUE(mGeckoChild, );
|
2007-06-16 02:34:48 +04:00
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2011-07-21 04:33:16 +04:00
|
|
|
mTextInputHandler->HandleFlagsChanged(theEvent);
|
2007-03-12 19:04:40 +03:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2003-03-13 23:37:32 +03:00
|
|
|
}
|
|
|
|
|
2008-10-13 22:07:27 +04:00
|
|
|
- (BOOL) isFirstResponder
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
|
|
|
NSResponder* resp = [[self window] firstResponder];
|
|
|
|
return (resp == (NSResponder*)self);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
|
|
|
}
|
|
|
|
|
2010-03-08 15:35:25 +03:00
|
|
|
- (BOOL)isDragInProgress
|
|
|
|
{
|
|
|
|
if (!mDragService)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDragSession> dragSession;
|
|
|
|
mDragService->GetCurrentSession(getter_AddRefs(dragSession));
|
2012-07-30 18:20:58 +04:00
|
|
|
return dragSession != nullptr;
|
2010-03-08 15:35:25 +03:00
|
|
|
}
|
|
|
|
|
2010-07-16 16:48:02 +04:00
|
|
|
- (BOOL)inactiveWindowAcceptsMouseEvent:(NSEvent*)aEvent
|
|
|
|
{
|
2010-08-09 20:12:50 +04:00
|
|
|
// If we're being destroyed assume the default -- return YES.
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return YES;
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
nsMouseEvent geckoEvent(true, NS_MOUSE_ACTIVATE, mGeckoChild, nsMouseEvent::eReal);
|
2010-07-16 16:48:02 +04:00
|
|
|
[self convertCocoaMouseEvent:aEvent toGeckoEvent:&geckoEvent];
|
|
|
|
return !mGeckoChild->DispatchWindowEvent(geckoEvent);
|
|
|
|
}
|
|
|
|
|
2011-03-02 00:15:23 +03:00
|
|
|
// Don't focus a plugin if the user has clicked on a DOM element above it.
|
|
|
|
// In this case the user has actually clicked on the plugin's ChildView
|
|
|
|
// (underneath the non-plugin DOM element). But we shouldn't allow the
|
|
|
|
// ChildView to be focused. See bug 627649.
|
|
|
|
- (BOOL)currentEventShouldFocusPlugin
|
|
|
|
{
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
NSEvent* currentEvent = [NSApp currentEvent];
|
|
|
|
if ([currentEvent type] != NSLeftMouseDown)
|
|
|
|
return YES;
|
|
|
|
|
2011-03-31 16:44:00 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
|
2011-03-02 00:15:23 +03:00
|
|
|
NSPoint eventLoc = nsCocoaUtils::ScreenLocationForEvent(currentEvent);
|
|
|
|
eventLoc.y = nsCocoaUtils::FlippedScreenY(eventLoc.y);
|
|
|
|
nsIntPoint widgetLoc(NSToIntRound(eventLoc.x), NSToIntRound(eventLoc.y));
|
|
|
|
widgetLoc -= mGeckoChild->WidgetToScreenOffset();
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
nsQueryContentEvent hitTest(true, NS_QUERY_DOM_WIDGET_HITTEST, mGeckoChild);
|
2011-03-02 00:15:23 +03:00
|
|
|
hitTest.InitForQueryDOMWidgetHittest(widgetLoc);
|
2011-03-31 16:44:00 +04:00
|
|
|
// This might destroy our widget (and null out mGeckoChild).
|
2011-03-02 00:15:23 +03:00
|
|
|
mGeckoChild->DispatchWindowEvent(hitTest);
|
2011-03-31 16:44:00 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return NO;
|
2011-03-02 00:15:23 +03:00
|
|
|
if (hitTest.mSucceeded && !hitTest.mReply.mWidgetIsHit)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2010-11-16 00:12:50 +03:00
|
|
|
// Don't focus a plugin if we're in a left click-through that will fail (see
|
|
|
|
// [ChildView isInFailingLeftClickThrough] above).
|
2011-03-02 00:15:23 +03:00
|
|
|
- (BOOL)shouldFocusPlugin:(BOOL)getFocus
|
2010-04-26 00:58:03 +04:00
|
|
|
{
|
|
|
|
if (!mGeckoChild)
|
2010-11-16 00:12:50 +03:00
|
|
|
return NO;
|
|
|
|
|
|
|
|
nsCocoaWindow* windowWidget = mGeckoChild->GetXULWindowWidget();
|
|
|
|
if (windowWidget && !windowWidget->ShouldFocusPlugin())
|
|
|
|
return NO;
|
|
|
|
|
2011-03-02 00:15:23 +03:00
|
|
|
if (getFocus && ![self currentEventShouldFocusPlugin])
|
|
|
|
return NO;
|
|
|
|
|
2010-11-16 00:12:50 +03:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns NO if the plugin shouldn't be focused/unfocused.
|
2011-03-02 00:15:23 +03:00
|
|
|
- (BOOL)updatePluginFocusStatus:(BOOL)getFocus
|
2010-11-16 00:12:50 +03:00
|
|
|
{
|
|
|
|
if (!mGeckoChild)
|
|
|
|
return NO;
|
|
|
|
|
2011-03-02 00:15:23 +03:00
|
|
|
if (![self shouldFocusPlugin:getFocus])
|
2010-11-16 00:12:50 +03:00
|
|
|
return NO;
|
2010-04-26 00:58:03 +04:00
|
|
|
|
2011-03-02 00:15:23 +03:00
|
|
|
if (mPluginEventModel == NPEventModelCocoa) {
|
2011-10-01 04:20:33 +04:00
|
|
|
nsPluginEvent pluginEvent(true, NS_PLUGIN_FOCUS_EVENT, mGeckoChild);
|
2011-03-02 00:15:23 +03:00
|
|
|
NPCocoaEvent cocoaEvent;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
2011-03-02 00:15:23 +03:00
|
|
|
cocoaEvent.type = NPCocoaEventFocusChanged;
|
|
|
|
cocoaEvent.data.focus.hasFocus = getFocus;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::InitPluginEvent(pluginEvent, cocoaEvent);
|
2011-03-02 00:15:23 +03:00
|
|
|
mGeckoChild->DispatchWindowEvent(pluginEvent);
|
2010-11-16 00:12:50 +03:00
|
|
|
|
2011-03-02 00:15:23 +03:00
|
|
|
if (getFocus)
|
|
|
|
[self sendFocusEvent:NS_PLUGIN_FOCUS];
|
|
|
|
}
|
2010-11-16 00:12:50 +03:00
|
|
|
|
|
|
|
return YES;
|
2010-04-26 00:58:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We must always call through to our superclass, even when mGeckoChild is
|
|
|
|
// nil -- otherwise the keyboard focus can end up in the wrong NSView.
|
|
|
|
- (BOOL)becomeFirstResponder
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2011-03-02 00:15:23 +03:00
|
|
|
if (mIsPluginView) {
|
|
|
|
if (![self updatePluginFocusStatus:YES])
|
2010-11-16 00:12:50 +03:00
|
|
|
return NO;
|
2010-04-26 00:58:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return [super becomeFirstResponder];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(YES);
|
|
|
|
}
|
|
|
|
|
2007-06-22 03:58:16 +04:00
|
|
|
// We must always call through to our superclass, even when mGeckoChild is
|
|
|
|
// nil -- otherwise the keyboard focus can end up in the wrong NSView.
|
2002-03-10 01:43:04 +03:00
|
|
|
- (BOOL)resignFirstResponder
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2011-03-02 00:15:23 +03:00
|
|
|
if (mIsPluginView) {
|
|
|
|
if (![self updatePluginFocusStatus:NO])
|
2010-11-16 00:12:50 +03:00
|
|
|
return NO;
|
2010-04-26 00:58:03 +04:00
|
|
|
}
|
|
|
|
|
2002-03-10 01:43:04 +03:00
|
|
|
return [super resignFirstResponder];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2010-04-26 00:58:03 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(YES);
|
2002-03-10 01:43:04 +03:00
|
|
|
}
|
|
|
|
|
2005-06-26 07:25:52 +04:00
|
|
|
- (void)viewsWindowDidBecomeKey
|
2005-09-30 04:59:29 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2005-09-30 04:59:29 +04:00
|
|
|
if (!mGeckoChild)
|
2007-06-16 02:34:48 +04:00
|
|
|
return;
|
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2005-10-12 21:38:29 +04:00
|
|
|
// check to see if the window implements the mozWindow protocol. This
|
|
|
|
// allows embedders to avoid re-entrant calls to -makeKeyAndOrderFront,
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
// which can happen because these activate calls propagate out
|
2005-10-12 21:38:29 +04:00
|
|
|
// to the embedder via nsIEmbeddingSiteWindow::SetFocus().
|
|
|
|
BOOL isMozWindow = [[self window] respondsToSelector:@selector(setSuppressMakeKeyFront:)];
|
|
|
|
if (isMozWindow)
|
|
|
|
[[self window] setSuppressMakeKeyFront:YES];
|
|
|
|
|
2007-08-03 03:01:32 +04:00
|
|
|
[self sendFocusEvent:NS_ACTIVATE];
|
2005-10-12 21:38:29 +04:00
|
|
|
|
|
|
|
if (isMozWindow)
|
|
|
|
[[self window] setSuppressMakeKeyFront:NO];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2005-06-26 07:25:52 +04:00
|
|
|
}
|
|
|
|
|
2005-10-12 21:38:29 +04:00
|
|
|
- (void)viewsWindowDidResignKey
|
2005-06-26 07:25:52 +04:00
|
|
|
{
|
2005-09-30 04:59:29 +04:00
|
|
|
if (!mGeckoChild)
|
2007-06-16 02:34:48 +04:00
|
|
|
return;
|
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2007-08-03 03:01:32 +04:00
|
|
|
[self sendFocusEvent:NS_DEACTIVATE];
|
2005-09-30 04:59:29 +04:00
|
|
|
}
|
2005-06-26 07:25:52 +04:00
|
|
|
|
2007-06-22 03:58:16 +04:00
|
|
|
// If the call to removeFromSuperview isn't delayed from nsChildView::
|
|
|
|
// TearDownView(), the NSView hierarchy might get changed during calls to
|
|
|
|
// [ChildView drawRect:], which leads to "beyond bounds" exceptions in
|
|
|
|
// NSCFArray. For more info see bmo bug 373122. Apple's docs claim that
|
2007-05-30 22:25:44 +04:00
|
|
|
// removeFromSuperviewWithoutNeedingDisplay "can be safely invoked during
|
|
|
|
// display" (whatever "display" means). But it's _not_ true that it can be
|
2007-06-22 03:58:16 +04:00
|
|
|
// safely invoked during calls to [NSView drawRect:]. We use
|
|
|
|
// removeFromSuperview here because there's no longer any danger of being
|
|
|
|
// "invoked during display", and because doing do clears up bmo bug 384343.
|
2007-05-30 22:25:44 +04:00
|
|
|
- (void)delayedTearDown
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-06-22 03:58:16 +04:00
|
|
|
[self removeFromSuperview];
|
2007-05-30 22:25:44 +04:00
|
|
|
[self release];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-05-30 22:25:44 +04:00
|
|
|
}
|
|
|
|
|
2006-10-26 02:45:22 +04:00
|
|
|
#pragma mark -
|
|
|
|
|
2006-12-20 05:13:57 +03:00
|
|
|
// drag'n'drop stuff
|
2006-10-26 02:45:22 +04:00
|
|
|
#define kDragServiceContractID "@mozilla.org/widget/dragservice;1"
|
|
|
|
|
2010-03-08 15:35:25 +03:00
|
|
|
- (NSDragOperation)dragOperationForSession:(nsIDragSession*)aDragSession
|
|
|
|
{
|
|
|
|
PRUint32 dragAction;
|
|
|
|
aDragSession->GetDragAction(&dragAction);
|
|
|
|
if (nsIDragService::DRAGDROP_ACTION_LINK & dragAction)
|
|
|
|
return NSDragOperationLink;
|
|
|
|
if (nsIDragService::DRAGDROP_ACTION_COPY & dragAction)
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
if (nsIDragService::DRAGDROP_ACTION_MOVE & dragAction)
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2006-10-26 02:45:22 +04:00
|
|
|
// This is a utility function used by NSView drag event methods
|
|
|
|
// to send events. It contains all of the logic needed for Gecko
|
2010-03-08 15:35:25 +03:00
|
|
|
// dragging to work. Returns the appropriate cocoa drag operation code.
|
|
|
|
- (NSDragOperation)doDragAction:(PRUint32)aMessage sender:(id)aSender
|
2006-10-26 02:45:22 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-06-30 07:19:41 +04:00
|
|
|
if (!mGeckoChild)
|
2010-03-08 15:35:25 +03:00
|
|
|
return NSDragOperationNone;
|
2006-10-26 02:45:22 +04:00
|
|
|
|
2007-07-17 06:24:05 +04:00
|
|
|
PR_LOG(sCocoaLog, PR_LOG_ALWAYS, ("ChildView doDragAction: entered\n"));
|
|
|
|
|
2007-06-30 07:19:41 +04:00
|
|
|
if (!mDragService) {
|
|
|
|
CallGetService(kDragServiceContractID, &mDragService);
|
|
|
|
NS_ASSERTION(mDragService, "Couldn't get a drag service - big problem!");
|
|
|
|
if (!mDragService)
|
2010-03-08 15:35:25 +03:00
|
|
|
return NSDragOperationNone;
|
2007-06-30 07:19:41 +04:00
|
|
|
}
|
|
|
|
|
2006-10-26 02:45:22 +04:00
|
|
|
if (aMessage == NS_DRAGDROP_ENTER)
|
|
|
|
mDragService->StartDragSession();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDragSession> dragSession;
|
|
|
|
mDragService->GetCurrentSession(getter_AddRefs(dragSession));
|
|
|
|
if (dragSession) {
|
2007-04-12 08:37:39 +04:00
|
|
|
if (aMessage == NS_DRAGDROP_OVER) {
|
|
|
|
// fire the drag event at the source. Just ignore whether it was
|
|
|
|
// cancelled or not as there isn't actually a means to stop the drag
|
|
|
|
mDragService->FireDragEventAtSource(NS_DRAGDROP_DRAG);
|
2011-10-01 04:20:33 +04:00
|
|
|
dragSession->SetCanDrop(false);
|
2007-04-12 08:37:39 +04:00
|
|
|
}
|
2006-10-26 02:45:22 +04:00
|
|
|
else if (aMessage == NS_DRAGDROP_DROP) {
|
2008-07-21 17:26:34 +04:00
|
|
|
// We make the assumption that the dragOver handlers have correctly set
|
2006-10-26 02:45:22 +04:00
|
|
|
// the |canDrop| property of the Drag Session.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canDrop = false;
|
2008-08-27 16:07:27 +04:00
|
|
|
if (!NS_SUCCEEDED(dragSession->GetCanDrop(&canDrop)) || !canDrop) {
|
2010-02-01 18:11:08 +03:00
|
|
|
[self doDragAction:NS_DRAGDROP_EXIT sender:aSender];
|
|
|
|
|
2008-08-27 16:07:27 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> sourceNode;
|
|
|
|
dragSession->GetSourceNode(getter_AddRefs(sourceNode));
|
|
|
|
if (!sourceNode) {
|
2011-10-01 04:20:33 +04:00
|
|
|
mDragService->EndDragSession(false);
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
2010-03-08 15:35:25 +03:00
|
|
|
return NSDragOperationNone;
|
2008-08-27 16:07:27 +04:00
|
|
|
}
|
2006-10-26 02:45:22 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 02:30:39 +03:00
|
|
|
unsigned int modifierFlags = [[NSApp currentEvent] modifierFlags];
|
2006-10-26 02:45:22 +04:00
|
|
|
PRUint32 action = nsIDragService::DRAGDROP_ACTION_MOVE;
|
|
|
|
// force copy = option, alias = cmd-option, default is move
|
|
|
|
if (modifierFlags & NSAlternateKeyMask) {
|
|
|
|
if (modifierFlags & NSCommandKeyMask)
|
|
|
|
action = nsIDragService::DRAGDROP_ACTION_LINK;
|
|
|
|
else
|
|
|
|
action = nsIDragService::DRAGDROP_ACTION_COPY;
|
|
|
|
}
|
|
|
|
dragSession->SetDragAction(action);
|
|
|
|
}
|
|
|
|
|
2007-10-09 22:46:30 +04:00
|
|
|
// set up gecko event
|
2012-04-25 07:00:02 +04:00
|
|
|
nsDragEvent geckoEvent(true, aMessage, mGeckoChild);
|
|
|
|
nsCocoaUtils::InitInputEvent(geckoEvent, [NSApp currentEvent]);
|
2006-10-26 02:45:22 +04:00
|
|
|
|
2007-10-09 22:46:30 +04:00
|
|
|
// Use our own coordinates in the gecko event.
|
|
|
|
// Convert event from gecko global coords to gecko view coords.
|
|
|
|
NSPoint localPoint = [self convertPoint:[aSender draggingLocation] fromView:nil];
|
|
|
|
geckoEvent.refPoint.x = static_cast<nscoord>(localPoint.x);
|
|
|
|
geckoEvent.refPoint.y = static_cast<nscoord>(localPoint.y);
|
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2007-10-09 22:46:30 +04:00
|
|
|
mGeckoChild->DispatchWindowEvent(geckoEvent);
|
2008-01-16 02:11:55 +03:00
|
|
|
if (!mGeckoChild)
|
2010-03-08 15:35:25 +03:00
|
|
|
return NSDragOperationNone;
|
|
|
|
|
|
|
|
if (dragSession) {
|
|
|
|
switch (aMessage) {
|
|
|
|
case NS_DRAGDROP_ENTER:
|
|
|
|
case NS_DRAGDROP_OVER:
|
|
|
|
return [self dragOperationForSession:dragSession];
|
|
|
|
case NS_DRAGDROP_EXIT:
|
|
|
|
case NS_DRAGDROP_DROP: {
|
|
|
|
nsCOMPtr<nsIDOMNode> sourceNode;
|
|
|
|
dragSession->GetSourceNode(getter_AddRefs(sourceNode));
|
|
|
|
if (!sourceNode) {
|
|
|
|
// We're leaving a window while doing a drag that was
|
|
|
|
// initiated in a different app. End the drag session,
|
|
|
|
// since we're done with it for now (until the user
|
|
|
|
// drags back into mozilla).
|
2011-10-01 04:20:33 +04:00
|
|
|
mDragService->EndDragSession(false);
|
2010-03-08 15:35:25 +03:00
|
|
|
}
|
|
|
|
}
|
2006-10-26 02:45:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-08 15:35:25 +03:00
|
|
|
return NSDragOperationGeneric;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2010-03-08 15:35:25 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSDragOperationNone);
|
2006-10-26 02:45:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2007-07-17 06:24:05 +04:00
|
|
|
PR_LOG(sCocoaLog, PR_LOG_ALWAYS, ("ChildView draggingEntered: entered\n"));
|
|
|
|
|
2006-10-26 02:45:22 +04:00
|
|
|
// there should never be a globalDragPboard when "draggingEntered:" is
|
|
|
|
// called, but just in case we'll take care of it here.
|
|
|
|
[globalDragPboard release];
|
|
|
|
|
|
|
|
// Set the global drag pasteboard that will be used for this drag session.
|
|
|
|
// This will be set back to nil when the drag session ends (mouse exits
|
|
|
|
// the view or a drop happens within the view).
|
|
|
|
globalDragPboard = [[sender draggingPasteboard] retain];
|
|
|
|
|
2010-03-08 15:35:25 +03:00
|
|
|
return [self doDragAction:NS_DRAGDROP_ENTER sender:sender];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSDragOperationNone);
|
2006-10-26 02:45:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2007-07-17 06:24:05 +04:00
|
|
|
PR_LOG(sCocoaLog, PR_LOG_ALWAYS, ("ChildView draggingUpdated: entered\n"));
|
|
|
|
|
2010-03-08 15:35:25 +03:00
|
|
|
return [self doDragAction:NS_DRAGDROP_OVER sender:sender];
|
2006-10-26 02:45:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)draggingExited:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2007-07-17 06:24:05 +04:00
|
|
|
PR_LOG(sCocoaLog, PR_LOG_ALWAYS, ("ChildView draggingExited: entered\n"));
|
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2006-10-26 02:45:22 +04:00
|
|
|
[self doDragAction:NS_DRAGDROP_EXIT sender:sender];
|
2007-10-10 16:19:47 +04:00
|
|
|
NS_IF_RELEASE(mDragService);
|
2006-10-26 02:45:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
|
|
|
{
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2010-03-08 15:35:25 +03:00
|
|
|
BOOL handled = [self doDragAction:NS_DRAGDROP_DROP sender:sender] != NSDragOperationNone;
|
2007-10-10 16:19:47 +04:00
|
|
|
NS_IF_RELEASE(mDragService);
|
|
|
|
return handled;
|
2007-06-30 07:19:41 +04:00
|
|
|
}
|
|
|
|
|
2011-04-26 05:37:20 +04:00
|
|
|
// NSDraggingSource
|
|
|
|
- (void)draggedImage:(NSImage *)anImage movedTo:(NSPoint)aPoint
|
|
|
|
{
|
|
|
|
// Get the drag service if it isn't already cached. The drag service
|
|
|
|
// isn't cached when dragging over a different application.
|
|
|
|
nsCOMPtr<nsIDragService> dragService = mDragService;
|
|
|
|
if (!dragService) {
|
|
|
|
dragService = do_GetService(kDragServiceContractID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dragService) {
|
|
|
|
NSPoint pnt = [NSEvent mouseLocation];
|
|
|
|
FlipCocoaScreenCoordinate(pnt);
|
|
|
|
dragService->DragMoved(NSToIntRound(pnt.x), NSToIntRound(pnt.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-30 07:19:41 +04:00
|
|
|
// NSDraggingSource
|
|
|
|
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
gDraggedTransferables = nullptr;
|
2007-07-18 03:02:40 +04:00
|
|
|
|
2009-02-17 18:51:12 +03:00
|
|
|
NSEvent *currentEvent = [NSApp currentEvent];
|
|
|
|
gUserCancelledDrag = ([currentEvent type] == NSKeyDown &&
|
2012-07-04 09:59:50 +04:00
|
|
|
[currentEvent keyCode] == kVK_Escape);
|
2009-02-17 18:51:12 +03:00
|
|
|
|
2007-06-30 07:19:41 +04:00
|
|
|
if (!mDragService) {
|
|
|
|
CallGetService(kDragServiceContractID, &mDragService);
|
|
|
|
NS_ASSERTION(mDragService, "Couldn't get a drag service - big problem!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDragService) {
|
2009-04-13 17:00:29 +04:00
|
|
|
// set the dragend point from the current mouse location
|
|
|
|
nsDragService* dragService = static_cast<nsDragService *>(mDragService);
|
|
|
|
NSPoint pnt = [NSEvent mouseLocation];
|
|
|
|
FlipCocoaScreenCoordinate(pnt);
|
2009-04-16 19:58:23 +04:00
|
|
|
dragService->SetDragEndPoint(nsIntPoint(NSToIntRound(pnt.x), NSToIntRound(pnt.y)));
|
2009-04-13 17:00:29 +04:00
|
|
|
|
2009-05-27 03:23:15 +04:00
|
|
|
// XXX: dropEffect should be updated per |operation|.
|
|
|
|
// As things stand though, |operation| isn't well handled within "our"
|
|
|
|
// events, that is, when the drop happens within the window: it is set
|
|
|
|
// either to NSDragOperationGeneric or to NSDragOperationNone.
|
|
|
|
// For that reason, it's not yet possible to override dropEffect per the
|
|
|
|
// given OS value, and it's also unclear what's the correct dropEffect
|
|
|
|
// value for NSDragOperationGeneric that is passed by other applications.
|
|
|
|
// All that said, NSDragOperationNone is still reliable.
|
|
|
|
if (operation == NSDragOperationNone) {
|
|
|
|
nsCOMPtr<nsIDOMDataTransfer> dataTransfer;
|
|
|
|
dragService->GetDataTransfer(getter_AddRefs(dataTransfer));
|
2012-02-07 22:02:32 +04:00
|
|
|
if (dataTransfer)
|
|
|
|
dataTransfer->SetDropEffectInt(nsIDragService::DRAGDROP_ACTION_NONE);
|
2009-05-27 03:23:15 +04:00
|
|
|
}
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
mDragService->EndDragSession(true);
|
2007-06-30 07:19:41 +04:00
|
|
|
NS_RELEASE(mDragService);
|
|
|
|
}
|
2006-10-26 02:45:22 +04:00
|
|
|
|
|
|
|
[globalDragPboard release];
|
|
|
|
globalDragPboard = nil;
|
2009-11-06 13:21:41 +03:00
|
|
|
[gLastDragMouseDownEvent release];
|
|
|
|
gLastDragMouseDownEvent = nil;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-06-30 07:19:41 +04:00
|
|
|
}
|
2006-10-26 02:45:22 +04:00
|
|
|
|
2007-06-30 07:19:41 +04:00
|
|
|
// NSDraggingSource
|
|
|
|
// this is just implemented so we comply with the NSDraggingSource informal protocol
|
2009-09-01 05:00:13 +04:00
|
|
|
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
|
2007-06-30 07:19:41 +04:00
|
|
|
{
|
|
|
|
return UINT_MAX;
|
2006-10-26 02:45:22 +04:00
|
|
|
}
|
|
|
|
|
2007-07-17 06:24:05 +04:00
|
|
|
// This method is a callback typically invoked in response to a drag ending on the desktop
|
|
|
|
// or a Findow folder window; the argument passed is a path to the drop location, to be used
|
|
|
|
// in constructing a complete pathname for the file(s) we want to create as a result of
|
|
|
|
// the drag.
|
2009-09-01 05:00:13 +04:00
|
|
|
- (NSArray *)namesOfPromisedFilesDroppedAtDestination:(NSURL*)dropDestination
|
2007-07-17 06:24:05 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-07-17 06:24:05 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
PR_LOG(sCocoaLog, PR_LOG_ALWAYS, ("ChildView namesOfPromisedFilesDroppedAtDestination: entering callback for promised files\n"));
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> targFile;
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_NewLocalFile(EmptyString(), true, getter_AddRefs(targFile));
|
2007-07-17 06:24:05 +04:00
|
|
|
nsCOMPtr<nsILocalFileMac> macLocalFile = do_QueryInterface(targFile);
|
|
|
|
if (!macLocalFile) {
|
|
|
|
NS_ERROR("No Mac local file");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NS_SUCCEEDED(macLocalFile->InitWithCFURL((CFURLRef)dropDestination))) {
|
|
|
|
NS_ERROR("failed InitWithCFURL");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2007-07-18 03:02:40 +04:00
|
|
|
if (!gDraggedTransferables)
|
|
|
|
return nil;
|
2007-07-17 06:24:05 +04:00
|
|
|
|
|
|
|
PRUint32 transferableCount;
|
2007-07-18 03:02:40 +04:00
|
|
|
rv = gDraggedTransferables->Count(&transferableCount);
|
2007-07-17 06:24:05 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < transferableCount; i++) {
|
|
|
|
nsCOMPtr<nsISupports> genericItem;
|
2007-07-18 03:02:40 +04:00
|
|
|
gDraggedTransferables->GetElementAt(i, getter_AddRefs(genericItem));
|
2007-07-17 06:24:05 +04:00
|
|
|
nsCOMPtr<nsITransferable> item(do_QueryInterface(genericItem));
|
|
|
|
if (!item) {
|
|
|
|
NS_ERROR("no transferable");
|
|
|
|
return nil;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
item->Init(nullptr);
|
2007-07-17 06:24:05 +04:00
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
item->SetTransferData(kFilePromiseDirectoryMime, macLocalFile, sizeof(nsIFile*));
|
2007-07-17 06:24:05 +04:00
|
|
|
|
|
|
|
// now request the kFilePromiseMime data, which will invoke the data provider
|
|
|
|
// If successful, the returned data is a reference to the resulting file.
|
|
|
|
nsCOMPtr<nsISupports> fileDataPrimitive;
|
|
|
|
PRUint32 dataSize = 0;
|
|
|
|
item->GetTransferData(kFilePromiseMime, getter_AddRefs(fileDataPrimitive), &dataSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSPasteboard* generalPboard = [NSPasteboard pasteboardWithName:NSDragPboard];
|
|
|
|
NSData* data = [generalPboard dataForType:@"application/x-moz-file-promise-dest-filename"];
|
|
|
|
NSString* name = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
|
|
NSArray* rslt = [NSArray arrayWithObject:name];
|
|
|
|
|
|
|
|
[name release];
|
|
|
|
|
|
|
|
return rslt;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-07-17 06:24:05 +04:00
|
|
|
}
|
2006-10-26 02:45:22 +04:00
|
|
|
|
2008-12-15 23:56:29 +03:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
// Support for the "Services" menu. We currently only support sending strings
|
2009-03-18 05:04:01 +03:00
|
|
|
// and HTML to system services.
|
2008-12-15 23:56:29 +03:00
|
|
|
|
|
|
|
- (id)validRequestorForSendType:(NSString *)sendType
|
|
|
|
returnType:(NSString *)returnType
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
|
|
|
// sendType contains the type of data that the service would like this
|
|
|
|
// application to send to it. sendType is nil if the service is not
|
|
|
|
// requesting any data.
|
|
|
|
//
|
|
|
|
// returnType contains the type of data the the service would like to
|
|
|
|
// return to this application (e.g., to overwrite the selection).
|
|
|
|
// returnType is nil if the service will not return any data.
|
|
|
|
//
|
|
|
|
// The following condition thus triggers when the service expects a string
|
2010-01-11 04:45:45 +03:00
|
|
|
// or HTML from us or no data at all AND when the service will either not
|
|
|
|
// send back any data to us or will send a string or HTML back to us.
|
|
|
|
|
|
|
|
#define IsSupportedType(typeStr) ([typeStr isEqual:NSStringPboardType] || [typeStr isEqual:NSHTMLPboardType])
|
|
|
|
|
|
|
|
id result = nil;
|
2008-12-15 23:56:29 +03:00
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
if ((!sendType || IsSupportedType(sendType)) &&
|
|
|
|
(!returnType || IsSupportedType(returnType))) {
|
2008-12-15 23:56:29 +03:00
|
|
|
if (mGeckoChild) {
|
2010-01-11 04:45:45 +03:00
|
|
|
// Assume that this object will be able to handle this request.
|
|
|
|
result = self;
|
2009-03-18 05:04:01 +03:00
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
// Keep the ChildView alive during this operation.
|
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
|
|
|
|
|
|
|
// Determine if there is a selection (if sending to the service).
|
|
|
|
if (sendType) {
|
2011-10-01 04:20:33 +04:00
|
|
|
nsQueryContentEvent event(true, NS_QUERY_CONTENT_STATE, mGeckoChild);
|
2010-03-11 00:24:40 +03:00
|
|
|
// This might destroy our widget (and null out mGeckoChild).
|
2010-01-11 04:45:45 +03:00
|
|
|
mGeckoChild->DispatchWindowEvent(event);
|
2010-03-11 00:24:40 +03:00
|
|
|
if (!mGeckoChild || !event.mSucceeded || !event.mReply.mHasSelection)
|
2010-01-11 04:45:45 +03:00
|
|
|
result = nil;
|
|
|
|
}
|
2009-12-31 01:29:26 +03:00
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
// Determine if we can paste (if receiving data from the service).
|
2010-03-11 00:24:40 +03:00
|
|
|
if (mGeckoChild && returnType) {
|
2011-10-01 04:20:33 +04:00
|
|
|
nsContentCommandEvent command(true, NS_CONTENT_COMMAND_PASTE_TRANSFERABLE, mGeckoChild, true);
|
2010-03-11 00:24:40 +03:00
|
|
|
// This might possibly destroy our widget (and null out mGeckoChild).
|
2010-01-11 04:45:45 +03:00
|
|
|
mGeckoChild->DispatchWindowEvent(command);
|
2010-03-11 00:24:40 +03:00
|
|
|
if (!mGeckoChild || !command.mSucceeded || !command.mIsEnabled)
|
2010-01-11 04:45:45 +03:00
|
|
|
result = nil;
|
|
|
|
}
|
2009-03-18 05:04:01 +03:00
|
|
|
}
|
2008-12-15 23:56:29 +03:00
|
|
|
}
|
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
#undef IsSupportedType
|
|
|
|
|
|
|
|
// Give the superclass a chance if this object will not handle this request.
|
|
|
|
if (!result)
|
|
|
|
result = [super validRequestorForSendType:sendType returnType:returnType];
|
|
|
|
|
|
|
|
return result;
|
2008-12-15 23:56:29 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard
|
|
|
|
types:(NSArray *)types
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2009-03-18 05:04:01 +03:00
|
|
|
|
|
|
|
// Make sure that the service will accept strings or HTML.
|
|
|
|
if ([types containsObject:NSStringPboardType] == NO &&
|
|
|
|
[types containsObject:NSHTMLPboardType] == NO)
|
2008-12-15 23:56:29 +03:00
|
|
|
return NO;
|
|
|
|
|
2009-03-18 05:04:01 +03:00
|
|
|
// Bail out if there is no Gecko object.
|
2008-12-15 23:56:29 +03:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return NO;
|
2009-03-18 05:04:01 +03:00
|
|
|
|
|
|
|
// Obtain the current selection.
|
2011-10-01 04:20:33 +04:00
|
|
|
nsQueryContentEvent event(true,
|
2009-03-18 05:04:01 +03:00
|
|
|
NS_QUERY_SELECTION_AS_TRANSFERABLE,
|
|
|
|
mGeckoChild);
|
|
|
|
mGeckoChild->DispatchWindowEvent(event);
|
|
|
|
if (!event.mSucceeded || !event.mReply.mTransferable)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
// Transform the transferable to an NSDictionary.
|
|
|
|
NSDictionary* pasteboardOutputDict = nsClipboard::PasteboardDictFromTransferable(event.mReply.mTransferable);
|
|
|
|
if (!pasteboardOutputDict)
|
2008-12-15 23:56:29 +03:00
|
|
|
return NO;
|
|
|
|
|
2009-03-18 05:04:01 +03:00
|
|
|
// Declare the pasteboard types.
|
|
|
|
unsigned int typeCount = [pasteboardOutputDict count];
|
|
|
|
NSMutableArray * types = [NSMutableArray arrayWithCapacity:typeCount];
|
|
|
|
[types addObjectsFromArray:[pasteboardOutputDict allKeys]];
|
|
|
|
[pboard declareTypes:types owner:nil];
|
|
|
|
|
|
|
|
// Write the data to the pasteboard.
|
|
|
|
for (unsigned int i = 0; i < typeCount; i++) {
|
|
|
|
NSString* currentKey = [types objectAtIndex:i];
|
|
|
|
id currentValue = [pasteboardOutputDict valueForKey:currentKey];
|
|
|
|
|
|
|
|
if (currentKey == NSStringPboardType ||
|
|
|
|
currentKey == kCorePboardType_url ||
|
|
|
|
currentKey == kCorePboardType_urld ||
|
|
|
|
currentKey == kCorePboardType_urln) {
|
|
|
|
[pboard setString:currentValue forType:currentKey];
|
|
|
|
} else if (currentKey == NSHTMLPboardType) {
|
|
|
|
[pboard setString:(nsClipboard::WrapHtmlForSystemPasteboard(currentValue)) forType:currentKey];
|
|
|
|
} else if (currentKey == NSTIFFPboardType) {
|
|
|
|
[pboard setData:currentValue forType:currentKey];
|
|
|
|
} else if (currentKey == NSFilesPromisePboardType) {
|
|
|
|
[pboard setPropertyList:currentValue forType:currentKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
2008-12-15 23:56:29 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
|
|
|
|
}
|
|
|
|
|
2010-01-11 04:45:45 +03:00
|
|
|
// Called if the service wants us to replace the current selection.
|
2008-12-15 23:56:29 +03:00
|
|
|
- (BOOL)readSelectionFromPasteboard:(NSPasteboard *)pboard
|
|
|
|
{
|
2010-01-11 04:45:45 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NO;
|
2012-07-30 18:20:58 +04:00
|
|
|
trans->Init(nullptr);
|
2010-01-11 04:45:45 +03:00
|
|
|
|
|
|
|
trans->AddDataFlavor(kUnicodeMime);
|
|
|
|
trans->AddDataFlavor(kHTMLMime);
|
|
|
|
|
|
|
|
rv = nsClipboard::TransferableFromPasteboard(trans, pboard);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NO;
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(mGeckoChild, false);
|
2010-01-11 04:45:45 +03:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
nsContentCommandEvent command(true,
|
2010-01-11 04:45:45 +03:00
|
|
|
NS_CONTENT_COMMAND_PASTE_TRANSFERABLE,
|
|
|
|
mGeckoChild);
|
|
|
|
command.mTransferable = trans;
|
|
|
|
mGeckoChild->DispatchWindowEvent(command);
|
|
|
|
|
|
|
|
return command.mSucceeded && command.mIsEnabled;
|
2008-12-15 23:56:29 +03:00
|
|
|
}
|
|
|
|
|
2006-10-26 02:45:22 +04:00
|
|
|
#pragma mark -
|
|
|
|
|
2006-09-11 19:47:35 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
|
|
|
|
/* Every ChildView has a corresponding mozDocAccessible object that is doing all
|
|
|
|
the heavy lifting. The topmost ChildView corresponds to a mozRootAccessible
|
|
|
|
object.
|
|
|
|
|
|
|
|
All ChildView needs to do is to route all accessibility calls (from the NSAccessibility APIs)
|
|
|
|
down to its object, pretending that they are the same.
|
|
|
|
*/
|
|
|
|
- (id<mozAccessible>)accessible
|
|
|
|
{
|
2007-06-16 02:34:48 +04:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return nil;
|
|
|
|
|
2006-09-14 13:29:28 +04:00
|
|
|
id<mozAccessible> nativeAccessible = nil;
|
2008-01-16 02:11:55 +03:00
|
|
|
|
2008-04-08 08:38:52 +04:00
|
|
|
nsAutoRetainCocoaObject kungFuDeathGrip(self);
|
2008-01-16 02:11:55 +03:00
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip2(mGeckoChild);
|
2012-05-29 05:18:45 +04:00
|
|
|
nsRefPtr<Accessible> accessible = mGeckoChild->GetDocumentAccessible();
|
2008-01-16 02:11:55 +03:00
|
|
|
if (!mGeckoChild)
|
|
|
|
return nil;
|
|
|
|
|
2006-09-14 13:29:28 +04:00
|
|
|
if (accessible)
|
|
|
|
accessible->GetNativeInterface((void**)&nativeAccessible);
|
2006-09-11 19:47:35 +04:00
|
|
|
|
2006-09-13 20:07:14 +04:00
|
|
|
#ifdef DEBUG_hakan
|
2006-11-15 14:08:14 +03:00
|
|
|
NSAssert(![nativeAccessible isExpired], @"native acc is expired!!!");
|
2006-09-11 19:47:35 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return nativeAccessible;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Implementation of formal mozAccessible formal protocol (enabling mozViews
|
|
|
|
to talk to mozAccessible objects in the accessibility module). */
|
|
|
|
|
2006-11-15 14:08:14 +03:00
|
|
|
- (BOOL)hasRepresentedView
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)representedView
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2006-09-19 12:44:03 +04:00
|
|
|
- (BOOL)isRoot
|
2006-09-11 19:47:35 +04:00
|
|
|
{
|
2006-09-19 12:44:03 +04:00
|
|
|
return [[self accessible] isRoot];
|
2006-09-11 19:47:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
- (void)printHierarchy
|
|
|
|
{
|
|
|
|
[[self accessible] printHierarchy];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
// general
|
|
|
|
|
|
|
|
- (BOOL)accessibilityIsIgnored
|
|
|
|
{
|
|
|
|
return [[self accessible] accessibilityIsIgnored];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityHitTest:(NSPoint)point
|
|
|
|
{
|
|
|
|
return [[self accessible] accessibilityHitTest:point];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityFocusedUIElement
|
|
|
|
{
|
|
|
|
return [[self accessible] accessibilityFocusedUIElement];
|
|
|
|
}
|
|
|
|
|
|
|
|
// actions
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityActionNames
|
|
|
|
{
|
|
|
|
return [[self accessible] accessibilityActionNames];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString*)accessibilityActionDescription:(NSString*)action
|
|
|
|
{
|
|
|
|
return [[self accessible] accessibilityActionDescription:action];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)accessibilityPerformAction:(NSString*)action
|
|
|
|
{
|
|
|
|
return [[self accessible] accessibilityPerformAction:action];
|
|
|
|
}
|
|
|
|
|
|
|
|
// attributes
|
|
|
|
|
|
|
|
- (NSArray*)accessibilityAttributeNames
|
|
|
|
{
|
|
|
|
return [[self accessible] accessibilityAttributeNames];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute
|
|
|
|
{
|
|
|
|
return [[self accessible] accessibilityIsAttributeSettable:attribute];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)accessibilityAttributeValue:(NSString*)attribute
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2006-09-14 13:29:28 +04:00
|
|
|
id<mozAccessible> accessible = [self accessible];
|
2006-09-11 19:47:35 +04:00
|
|
|
|
|
|
|
// if we're the root (topmost) accessible, we need to return our native AXParent as we
|
|
|
|
// traverse outside to the hierarchy of whoever embeds us. thus, fall back on NSView's
|
|
|
|
// default implementation for this attribute.
|
2006-09-19 12:44:03 +04:00
|
|
|
if ([attribute isEqualToString:NSAccessibilityParentAttribute] && [accessible isRoot]) {
|
2006-09-11 19:47:35 +04:00
|
|
|
id parentAccessible = [super accessibilityAttributeValue:attribute];
|
|
|
|
return parentAccessible;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [accessible accessibilityAttributeValue:attribute];
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2006-09-11 19:47:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ACCESSIBILITY */
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
@end
|
2007-04-15 17:43:55 +04:00
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
void
|
|
|
|
ChildViewMouseTracker::OnDestroyView(ChildView* aView)
|
|
|
|
{
|
2011-08-08 18:43:13 +04:00
|
|
|
if (sLastMouseEventView == aView) {
|
2009-09-23 06:31:37 +04:00
|
|
|
sLastMouseEventView = nil;
|
2011-08-13 18:25:39 +04:00
|
|
|
[sLastMouseMoveEvent release];
|
|
|
|
sLastMouseMoveEvent = nil;
|
2011-08-08 18:43:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChildViewMouseTracker::OnDestroyWindow(NSWindow* aWindow)
|
|
|
|
{
|
|
|
|
if (sWindowUnderMouse == aWindow) {
|
|
|
|
sWindowUnderMouse = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChildViewMouseTracker::MouseEnteredWindow(NSEvent* aEvent)
|
|
|
|
{
|
|
|
|
sWindowUnderMouse = [aEvent window];
|
|
|
|
ReEvaluateMouseEnterState(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ChildViewMouseTracker::MouseExitedWindow(NSEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (sWindowUnderMouse == [aEvent window]) {
|
|
|
|
sWindowUnderMouse = nil;
|
|
|
|
ReEvaluateMouseEnterState(aEvent);
|
|
|
|
}
|
2009-09-23 06:31:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-12-12 00:56:59 +03:00
|
|
|
ChildViewMouseTracker::ReEvaluateMouseEnterState(NSEvent* aEvent)
|
2009-09-23 06:31:37 +04:00
|
|
|
{
|
2009-10-21 11:02:13 +04:00
|
|
|
ChildView* oldView = sLastMouseEventView;
|
2009-12-12 00:56:59 +03:00
|
|
|
sLastMouseEventView = ViewForEvent(aEvent);
|
|
|
|
if (sLastMouseEventView != oldView) {
|
2009-09-23 06:31:37 +04:00
|
|
|
// Send enter and / or exit events.
|
2009-12-12 00:56:59 +03:00
|
|
|
nsMouseEvent::exitType type = [sLastMouseEventView window] == [oldView window] ?
|
2009-09-23 06:31:37 +04:00
|
|
|
nsMouseEvent::eChild : nsMouseEvent::eTopLevel;
|
2009-10-21 11:02:13 +04:00
|
|
|
[oldView sendMouseEnterOrExitEvent:aEvent enter:NO type:type];
|
2009-09-23 06:31:37 +04:00
|
|
|
// After the cursor exits the window set it to a visible regular arrow cursor.
|
|
|
|
if (type == nsMouseEvent::eTopLevel) {
|
|
|
|
[[nsCursorManager sharedInstance] setCursor:eCursor_standard];
|
|
|
|
}
|
2009-12-12 00:56:59 +03:00
|
|
|
[sLastMouseEventView sendMouseEnterOrExitEvent:aEvent enter:YES type:type];
|
2009-09-23 06:31:37 +04:00
|
|
|
}
|
2009-12-12 00:56:59 +03:00
|
|
|
}
|
|
|
|
|
2011-08-13 18:25:39 +04:00
|
|
|
void
|
|
|
|
ChildViewMouseTracker::ResendLastMouseMoveEvent()
|
|
|
|
{
|
|
|
|
if (sLastMouseMoveEvent) {
|
|
|
|
MouseMoved(sLastMouseMoveEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-12 00:56:59 +03:00
|
|
|
void
|
|
|
|
ChildViewMouseTracker::MouseMoved(NSEvent* aEvent)
|
|
|
|
{
|
2011-08-08 18:43:13 +04:00
|
|
|
MouseEnteredWindow(aEvent);
|
2009-12-12 00:56:59 +03:00
|
|
|
[sLastMouseEventView handleMouseMoved:aEvent];
|
2011-08-13 18:25:39 +04:00
|
|
|
if (sLastMouseMoveEvent != aEvent) {
|
|
|
|
[sLastMouseMoveEvent release];
|
|
|
|
sLastMouseMoveEvent = [aEvent retain];
|
|
|
|
}
|
2009-09-23 06:31:37 +04:00
|
|
|
}
|
|
|
|
|
2011-08-18 02:30:52 +04:00
|
|
|
void
|
|
|
|
ChildViewMouseTracker::MouseScrolled(NSEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!nsCocoaUtils::IsMomentumScrollEvent(aEvent)) {
|
|
|
|
// Store the position so we can pin future momentum scroll events.
|
|
|
|
sLastScrollEventScreenLocation = nsCocoaUtils::ScreenLocationForEvent(aEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
ChildView*
|
|
|
|
ChildViewMouseTracker::ViewForEvent(NSEvent* aEvent)
|
|
|
|
{
|
2011-08-08 18:43:13 +04:00
|
|
|
NSWindow* window = sWindowUnderMouse;
|
2010-07-16 16:48:02 +04:00
|
|
|
if (!window)
|
2009-09-23 06:31:37 +04:00
|
|
|
return nil;
|
|
|
|
|
|
|
|
NSPoint windowEventLocation = nsCocoaUtils::EventLocationForWindow(aEvent, window);
|
|
|
|
NSView* view = [[[window contentView] superview] hitTest:windowEventLocation];
|
2010-07-16 16:48:02 +04:00
|
|
|
if (![view isKindOfClass:[ChildView class]])
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
ChildView* childView = (ChildView*)view;
|
2010-08-09 20:12:50 +04:00
|
|
|
// If childView is being destroyed return nil.
|
|
|
|
if (![childView widget])
|
|
|
|
return nil;
|
2010-07-16 16:48:02 +04:00
|
|
|
return WindowAcceptsEvent(window, aEvent, childView) ? childView : nil;
|
2009-09-23 06:31:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
2010-07-16 16:48:02 +04:00
|
|
|
ChildViewMouseTracker::WindowAcceptsEvent(NSWindow* aWindow, NSEvent* aEvent,
|
|
|
|
ChildView* aView, BOOL aIsClickThrough)
|
2009-09-23 06:31:37 +04:00
|
|
|
{
|
|
|
|
// Right mouse down events may get through to all windows, even to a top level
|
|
|
|
// window with an open sheet.
|
2010-05-14 14:21:25 +04:00
|
|
|
if (!aWindow || [aEvent type] == NSRightMouseDown)
|
2009-09-23 06:31:37 +04:00
|
|
|
return YES;
|
|
|
|
|
|
|
|
id delegate = [aWindow delegate];
|
|
|
|
if (!delegate || ![delegate isKindOfClass:[WindowDelegate class]])
|
|
|
|
return YES;
|
|
|
|
|
|
|
|
nsIWidget *windowWidget = [(WindowDelegate *)delegate geckoWidget];
|
|
|
|
if (!windowWidget)
|
|
|
|
return YES;
|
|
|
|
|
|
|
|
nsWindowType windowType;
|
|
|
|
windowWidget->GetWindowType(windowType);
|
|
|
|
|
2010-05-14 14:21:25 +04:00
|
|
|
NSWindow* topLevelWindow = nil;
|
|
|
|
|
2009-09-23 06:31:37 +04:00
|
|
|
switch (windowType) {
|
|
|
|
case eWindowType_popup:
|
|
|
|
// If this is a context menu, it won't have a parent. So we'll always
|
|
|
|
// accept mouse move events on context menus even when none of our windows
|
|
|
|
// is active, which is the right thing to do.
|
|
|
|
// For panels, the parent window is the XUL window that owns the panel.
|
2010-07-16 16:48:02 +04:00
|
|
|
return WindowAcceptsEvent([aWindow parentWindow], aEvent, aView, aIsClickThrough);
|
2009-09-23 06:31:37 +04:00
|
|
|
|
|
|
|
case eWindowType_toplevel:
|
|
|
|
case eWindowType_dialog:
|
2010-05-14 14:21:25 +04:00
|
|
|
if ([aWindow attachedSheet])
|
|
|
|
return NO;
|
2009-09-23 06:31:37 +04:00
|
|
|
|
2010-05-14 14:21:25 +04:00
|
|
|
topLevelWindow = aWindow;
|
|
|
|
break;
|
2009-09-23 06:31:37 +04:00
|
|
|
case eWindowType_sheet: {
|
|
|
|
nsIWidget* parentWidget = windowWidget->GetSheetWindowParent();
|
|
|
|
if (!parentWidget)
|
|
|
|
return YES;
|
|
|
|
|
2010-05-14 14:21:25 +04:00
|
|
|
topLevelWindow = (NSWindow*)parentWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
break;
|
2009-09-23 06:31:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return YES;
|
|
|
|
}
|
2010-05-14 14:21:25 +04:00
|
|
|
|
|
|
|
if (!topLevelWindow ||
|
2010-07-16 16:48:02 +04:00
|
|
|
([topLevelWindow isMainWindow] && !aIsClickThrough) ||
|
2010-05-14 14:21:25 +04:00
|
|
|
[aEvent type] == NSOtherMouseDown ||
|
|
|
|
(([aEvent modifierFlags] & NSCommandKeyMask) != 0 &&
|
|
|
|
[aEvent type] != NSMouseMoved))
|
|
|
|
return YES;
|
|
|
|
|
|
|
|
// If we're here then we're dealing with a left click or mouse move on an
|
2010-07-16 16:48:02 +04:00
|
|
|
// inactive window or something similar. Ask Gecko what to do.
|
|
|
|
return [aView inactiveWindowAcceptsMouseEvent:aEvent];
|
2009-09-23 06:31:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
2009-02-06 20:36:04 +03:00
|
|
|
@interface NSView (MethodSwizzling)
|
|
|
|
- (BOOL)nsChildView_NSView_mouseDownCanMoveWindow;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSView (MethodSwizzling)
|
|
|
|
|
|
|
|
// All top-level browser windows belong to the ToolbarWindow class and have
|
|
|
|
// NSTexturedBackgroundWindowMask turned on in their "style" (see particularly
|
|
|
|
// [ToolbarWindow initWithContentRect:...] in nsCocoaWindow.mm). This style
|
|
|
|
// normally means the window "may be moved by clicking and dragging anywhere
|
|
|
|
// in the window background", but we've suppressed this by giving the
|
|
|
|
// ChildView class a mouseDownCanMoveWindow method that always returns NO.
|
|
|
|
// Normally a ToolbarWindow's contentView (not a ChildView) returns YES when
|
|
|
|
// NSTexturedBackgroundWindowMask is turned on. But normally this makes no
|
|
|
|
// difference. However, under some (probably very unusual) circumstances
|
|
|
|
// (and only on Leopard) it *does* make a difference -- for example it
|
|
|
|
// triggers bmo bugs 431902 and 476393. So here we make sure that a
|
|
|
|
// ToolbarWindow's contentView always returns NO from the
|
|
|
|
// mouseDownCanMoveWindow method.
|
|
|
|
- (BOOL)nsChildView_NSView_mouseDownCanMoveWindow
|
|
|
|
{
|
|
|
|
NSWindow *ourWindow = [self window];
|
|
|
|
NSView *contentView = [ourWindow contentView];
|
|
|
|
if ([ourWindow isKindOfClass:[ToolbarWindow class]] && (self == contentView))
|
|
|
|
return NO;
|
|
|
|
return [self nsChildView_NSView_mouseDownCanMoveWindow];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2011-08-19 00:39:54 +04:00
|
|
|
|
|
|
|
#ifdef __LP64__
|
|
|
|
// When using blocks, at least on OS X 10.7, the OS sometimes calls
|
|
|
|
// +[NSEvent removeMonitor:] more than once on a single event monitor, which
|
|
|
|
// causes crashes. See bug 678607. We hook these methods to work around
|
|
|
|
// the problem.
|
|
|
|
@interface NSEvent (MethodSwizzling)
|
|
|
|
+ (id)nsChildView_NSEvent_addLocalMonitorForEventsMatchingMask:(unsigned long long)mask handler:(id)block;
|
|
|
|
+ (void)nsChildView_NSEvent_removeMonitor:(id)eventMonitor;
|
|
|
|
@end
|
|
|
|
|
|
|
|
// This is a local copy of the AppKit frameworks sEventObservers hashtable.
|
|
|
|
// It only stores "local monitors". We use it to ensure that +[NSEvent
|
|
|
|
// removeMonitor:] is never called more than once on the same local monitor.
|
|
|
|
static NSHashTable *sLocalEventObservers = nil;
|
|
|
|
|
|
|
|
@implementation NSEvent (MethodSwizzling)
|
|
|
|
|
|
|
|
+ (id)nsChildView_NSEvent_addLocalMonitorForEventsMatchingMask:(unsigned long long)mask handler:(id)block
|
|
|
|
{
|
|
|
|
if (!sLocalEventObservers) {
|
|
|
|
sLocalEventObservers = [[NSHashTable hashTableWithOptions:
|
|
|
|
NSHashTableStrongMemory | NSHashTableObjectPointerPersonality] retain];
|
|
|
|
}
|
|
|
|
id retval =
|
|
|
|
[self nsChildView_NSEvent_addLocalMonitorForEventsMatchingMask:mask handler:block];
|
|
|
|
if (sLocalEventObservers && retval && ![sLocalEventObservers containsObject:retval]) {
|
|
|
|
[sLocalEventObservers addObject:retval];
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)nsChildView_NSEvent_removeMonitor:(id)eventMonitor
|
|
|
|
{
|
|
|
|
if (sLocalEventObservers && [eventMonitor isKindOfClass: ::NSClassFromString(@"_NSLocalEventObserver")]) {
|
|
|
|
if (![sLocalEventObservers containsObject:eventMonitor]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[sLocalEventObservers removeObject:eventMonitor];
|
|
|
|
}
|
|
|
|
[self nsChildView_NSEvent_removeMonitor:eventMonitor];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
#endif // #ifdef __LP64__
|