26 #include "../NativeWindowFromNode.h"
28 #include <nsIWidget.h>
29 #include <nsComponentManagerUtils.h>
31 #define SB_WIN_MOVE_TIMEOUT 100
42 NS_ENSURE_TRUE(winService, );
51 NS_ENSURE_TRUE(winService, );
66 PRInt32 aConfigureHandlerID,
67 PRInt32 aDestroyHandlerID)
68 : mListener(aListener)
69 , mIsTimerSet(PR_FALSE)
70 , mShouldReArmTimer(PR_FALSE)
71 , mPreviousX(aPreviousX)
72 , mPreviousY(aPreviousY)
73 , mConfigureHandlerID(aConfigureHandlerID)
74 , mDestroyHandlerID(aDestroyHandlerID)
77 mTimer = do_CreateInstance(
"@mozilla.org/timer;1", &rv);
78 NS_ENSURE_SUCCESS(rv, );
88 NS_ENSURE_ARG_POINTER(aEvent);
93 if (aEvent->configure.x != mPreviousX ||
94 aEvent->configure.y != mPreviousY)
97 mPreviousX = aEvent->configure.x;
98 mPreviousY = aEvent->configure.y;
103 mShouldReArmTimer = PR_TRUE;
106 rv = mListener->OnMoveStarted();
107 NS_ENSURE_SUCCESS(rv, rv);
110 rv = mTimer->InitWithCallback(
this,
112 nsITimer::TYPE_ONE_SHOT);
113 NS_ENSURE_SUCCESS(rv, rv);
115 mIsTimerSet = PR_TRUE;
116 mShouldReArmTimer = PR_FALSE;
128 nsresult rv = mTimer->Cancel();
129 NS_ENSURE_SUCCESS(rv, rv);
131 mIsTimerSet = PR_FALSE;
132 mShouldReArmTimer = PR_FALSE;
139 PRInt32 *aOutDestroyHandlerID)
141 NS_ENSURE_ARG_POINTER(aOutConfigureHandlerID);
142 NS_ENSURE_ARG_POINTER(aOutDestroyHandlerID);
144 *aOutConfigureHandlerID = mConfigureHandlerID;
145 *aOutDestroyHandlerID = mDestroyHandlerID;
154 sbGtkWindowContext::Notify(nsITimer *aTimer)
156 NS_ENSURE_ARG_POINTER(aTimer);
159 if (mShouldReArmTimer) {
161 rv = mTimer->InitWithCallback(
this,
163 nsITimer::TYPE_ONE_SHOT);
164 NS_ENSURE_SUCCESS(rv, rv);
166 mShouldReArmTimer = PR_FALSE;
170 mIsTimerSet = PR_FALSE;
171 mShouldReArmTimer = PR_FALSE;
173 rv = mListener->OnMoveStopped();
174 NS_ENSURE_SUCCESS(rv, rv);
199 NS_ENSURE_ARG_POINTER(aWindow);
200 NS_ENSURE_ARG_POINTER(aEvent);
205 mWindowContextMap.find(aWindow);
206 NS_ENSURE_TRUE(foundIter != mWindowContextMap.end(), NS_ERROR_FAILURE);
208 nsRefPtr<sbGtkWindowContext> winContext((*foundIter).second);
209 NS_ENSURE_TRUE(winContext, NS_ERROR_FAILURE);
211 nsresult rv = winContext->OnFrameEvent(aEvent);
212 NS_ENSURE_SUCCESS(rv, rv);
220 NS_ENSURE_ARG_POINTER(aWindow);
223 mWindowContextMap.find(aWindow);
224 NS_ENSURE_TRUE(foundIter != mWindowContextMap.end(), NS_ERROR_FAILURE);
226 nsRefPtr<sbGtkWindowContext> winContext((*foundIter).second);
227 NS_ENSURE_TRUE(winContext, NS_ERROR_FAILURE);
229 nsresult rv = winContext->OnWindowDestroyed();
230 NS_ENSURE_SUCCESS(rv, rv);
233 mWindowContextMap.erase(foundIter);
242 sbGtkWindowMoveService::StartWatchingWindow(
nsISupports *aWindow,
245 NS_ENSURE_ARG_POINTER(aWindow);
246 NS_ENSURE_ARG_POINTER(aListener);
249 NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
252 reinterpret_cast<GtkWidget *
>(widget->GetNativeData(NS_NATIVE_SHELLWIDGET));
253 NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
256 gtk_widget_add_events(GTK_WIDGET(window), GDK_CONFIGURE);
257 PRInt32 configureHandlerID = g_signal_connect(G_OBJECT(window),
264 PRInt32 destroyHandlerID = g_signal_connect(G_OBJECT(window),
270 GtkWindow *widgetWindow = GTK_WINDOW(window);
274 gtk_window_get_position(widgetWindow, &curX, &curY);
278 aListener, curX, curY, configureHandlerID, destroyHandlerID);
279 NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
286 sbGtkWindowMoveService::StopWatchingWindow(
nsISupports *aWindow,
289 NS_ENSURE_ARG_POINTER(aWindow);
290 NS_ENSURE_ARG_POINTER(aListener);
294 NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
297 reinterpret_cast<GtkWidget *
>(widget->GetNativeData(NS_NATIVE_SHELLWIDGET));
299 GtkWindow *widgetWindow = GTK_WINDOW(window);
302 mWindowContextMap.find(widgetWindow);
303 if (foundIter != mWindowContextMap.end()) {
306 nsRefPtr<sbGtkWindowContext> winContext((*foundIter).second);
307 NS_ENSURE_TRUE(winContext, NS_ERROR_FAILURE);
309 PRInt32 configureHandlerID, destroyHandlerID;
310 nsresult rv = winContext->GetSignalHandlerIDs(&configureHandlerID,
312 NS_ENSURE_SUCCESS(rv, rv);
314 g_signal_handler_disconnect(window, configureHandlerID);
315 g_signal_handler_disconnect(window, destroyHandlerID);
317 mWindowContextMap.erase(foundIter);
#define SB_WIN_MOVE_TIMEOUT
virtual ~sbGtkWindowContext()
sbGtkWindowContextMap::iterator sbGtkWindowMoveServiceIter
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
static nsIWidget * getWidget(nsISupports *window)
virtual ~sbGtkWindowMoveService()
nsresult OnFrameEvent(GdkEvent *aEvent)
nsresult GetSignalHandlerIDs(PRInt32 *aOutConfigureHandlerID, PRInt32 *aOutDestroyHandlerID)
void window_destroyed(GtkWindow *aWindow, gpointer data)
void frame_callback(GtkWindow *aWindow, GdkEvent *aEvent, gpointer data)
nsresult OnWindowDestroyed(GtkWindow *aWindow)
nsresult OnWindowDestroyed()
sbGtkWindowContextMap::value_type sbGtkWindowContextMapPair
NS_DECL_ISUPPORTS NS_DECL_SBIWINDOWMOVESERVICE nsresult OnWindowFrameCallback(GtkWindow *aWindow, GdkEvent *aEvent)