mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 12:50:09 +00:00
Query pointer for great justice. Part of bug #72556. Not part of the build.
This commit is contained in:
parent
f941b99ef3
commit
9f0dc9f1fe
48
widget/public/nsIPointerService.h
Normal file
48
widget/public/nsIPointerService.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Christopher Blizzard.
|
||||
* Portions created Christopher Blizzard are Copyright (C) Christopher
|
||||
* Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsIPointerService_h_
|
||||
#define nsIPointerService_h_
|
||||
|
||||
#include <nsIWidget.h>
|
||||
|
||||
#define NS_IPOINTERSERVICE_IID \
|
||||
{ 0xabde6104, 0x1dd1, 0x11b2, { 0x8e, 0x8f, 0xb2, 0xe4, 0x76, 0x8b, 0xbb, 0xfb } };
|
||||
|
||||
#define NS_IPOINTERSERVICE_CONTRACTID \
|
||||
"@mozilla.org/widget/pointer-service;1"
|
||||
|
||||
class nsIPointerService : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IPOINTERSERVICE_IID);
|
||||
|
||||
// This method will return the widget that is currently under the
|
||||
// pointer. If there is no widget under the pointer it will return
|
||||
// 0.
|
||||
|
||||
// This call is EXTRAORDINARILY EXPENSIVE UNDER X. Please don't
|
||||
// use it unless you have to.
|
||||
|
||||
NS_IMETHOD WidgetUnderPointer(nsIWidget **_retval,
|
||||
PRUint32 *aXOffset, PRUint32 *aYOffset) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsIPointerService_h_ */
|
115
widget/src/gtk/nsPointerService.cpp
Normal file
115
widget/src/gtk/nsPointerService.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Christopher Blizzard.
|
||||
* Portions created Christopher Blizzard are Copyright (C) Christopher
|
||||
* Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include "nsPointerService.h"
|
||||
#include "nsWindow.h"
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsPointerService, nsBasePointerService)
|
||||
NS_IMPL_RELEASE_INHERITED(nsPointerService, nsBasePointerService)
|
||||
NS_IMPL_QUERY_INTERFACE_INHERITED0(nsPointerService, nsBasePointerService)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPointerService::WidgetUnderPointer(nsIWidget **_retval,
|
||||
PRUint32 *aXOffset, PRUint32 *aYOffset)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
*aXOffset = 0;
|
||||
*aYOffset = 0;
|
||||
|
||||
Bool retval;
|
||||
Window root_return;
|
||||
Window child_return = None;
|
||||
int root_x_return, root_y_return;
|
||||
int win_x_return, win_y_return;
|
||||
unsigned int mask_return;
|
||||
|
||||
// Query the pointer
|
||||
retval = XQueryPointer(GDK_DISPLAY(),
|
||||
GDK_WINDOW_XWINDOW(GDK_ROOT_PARENT()),
|
||||
&root_return, &child_return,
|
||||
&root_x_return, &root_y_return,
|
||||
&win_x_return, &win_y_return,
|
||||
&mask_return);
|
||||
|
||||
// the pointer is on a different window
|
||||
if (!retval || child_return == None)
|
||||
return NS_OK;
|
||||
|
||||
int done = 0;
|
||||
Window dest_w = child_return;
|
||||
int xlate_x_return;
|
||||
int xlate_y_return;
|
||||
|
||||
// loop to find the inner most window
|
||||
while (!done) {
|
||||
Window xlate_return = None;
|
||||
retval = XTranslateCoordinates(GDK_DISPLAY(),
|
||||
GDK_WINDOW_XWINDOW(GDK_ROOT_PARENT()),
|
||||
dest_w,
|
||||
win_x_return, win_y_return,
|
||||
&xlate_x_return, &xlate_y_return,
|
||||
&xlate_return);
|
||||
|
||||
// the pointer is on a different screen
|
||||
if (!retval)
|
||||
return NS_OK;
|
||||
|
||||
// if xlate_return was None then we've reached the inner most window
|
||||
if (xlate_return == None)
|
||||
done = 1;
|
||||
// otherwise set our new destination window to the return from the
|
||||
// translation
|
||||
else
|
||||
dest_w = xlate_return;
|
||||
}
|
||||
|
||||
GdkWindow *window;
|
||||
nsWindow *widget;
|
||||
|
||||
// get the gdk window under the pointer
|
||||
window = gdk_window_lookup(dest_w);
|
||||
// it's not a gdk window
|
||||
if (!window)
|
||||
return NS_OK;
|
||||
|
||||
// is that an nsWindow window?
|
||||
gpointer data = NULL;
|
||||
gdk_window_get_user_data(window, &data);
|
||||
// nope
|
||||
if (!data)
|
||||
return NS_OK;
|
||||
|
||||
// downcast
|
||||
widget = (nsWindow *)gtk_object_get_data(GTK_OBJECT(data), "nsWindow");
|
||||
if (!widget)
|
||||
return NS_OK;
|
||||
|
||||
*_retval = NS_STATIC_CAST(nsIWidget *, widget);
|
||||
*aXOffset = xlate_x_return;
|
||||
*aYOffset = xlate_y_return;
|
||||
|
||||
NS_ADDREF(*_retval);
|
||||
|
||||
return NS_OK;
|
||||
}
|
32
widget/src/gtk/nsPointerService.h
Normal file
32
widget/src/gtk/nsPointerService.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Christopher Blizzard.
|
||||
* Portions created Christopher Blizzard are Copyright (C) Christopher
|
||||
* Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsBasePointerService.h"
|
||||
|
||||
class nsPointerService : public nsBasePointerService {
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_IMETHOD WidgetUnderPointer(nsIWidget **_retval,
|
||||
PRUint32 *aXOffset, PRUint32 *aYOffset);
|
||||
};
|
||||
|
||||
|
43
widget/src/xpwidgets/nsBasePointerService.cpp
Normal file
43
widget/src/xpwidgets/nsBasePointerService.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Christopher Blizzard.
|
||||
* Portions created Christopher Blizzard are Copyright (C) Christopher
|
||||
* Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsBasePointerService.h"
|
||||
|
||||
nsBasePointerService::nsBasePointerService()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsBasePointerService::~nsBasePointerService()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsBasePointerService)
|
||||
NS_IMPL_RELEASE(nsBasePointerService)
|
||||
NS_IMPL_QUERY_INTERFACE1(nsBasePointerService, nsIPointerService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBasePointerService::WidgetUnderPointer(nsIWidget **_retval,
|
||||
PRUint32 *aXOffset,
|
||||
PRUint32 *aYOffset)
|
||||
{
|
||||
*_retval = nsnull;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
40
widget/src/xpwidgets/nsBasePointerService.h
Normal file
40
widget/src/xpwidgets/nsBasePointerService.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Christopher Blizzard.
|
||||
* Portions created Christopher Blizzard are Copyright (C) Christopher
|
||||
* Blizzard. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsBasePointerService_h_
|
||||
#define nsBasePointerService_h_
|
||||
|
||||
#include <nsIPointerService.h>
|
||||
|
||||
class nsBasePointerService : public nsIPointerService {
|
||||
public:
|
||||
nsBasePointerService();
|
||||
virtual ~nsBasePointerService();
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIPointerService
|
||||
NS_IMETHOD WidgetUnderPointer(nsIWidget **_retval,
|
||||
PRUint32 *aXOffset, PRUint32 *aYOffset);
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsBasePointerService_h_ */
|
Loading…
x
Reference in New Issue
Block a user