43 #include "nsServiceManagerUtils.h"
44 #include "nsIInterfaceRequestorUtils.h"
45 #include "imgILoader.h"
46 #include "imgIRequest.h"
47 #include "nsNetError.h"
48 #include "nsIImageToPixbuf.h"
50 #include "nsIDOMNode.h"
51 #include "nsIDOMDocumentEvent.h"
52 #include "nsIDOMDocument.h"
53 #include "nsStringGlue.h"
54 #include "nsIDOMDocumentView.h"
55 #include "nsIDOMMouseEvent.h"
56 #include "nsIDOMAbstractView.h"
63 imgIContainerObserver)
66 :mSigPopup(G_MAXULONG),
67 mSigActivate(G_MAXULONG)
70 mIcon = gtk_status_icon_new_from_stock(GTK_STOCK_MISSING_IMAGE);
76 g_object_unref(
mIcon);
88 nsCOMPtr<imgILoader> imgloader =
89 do_GetService(
"@mozilla.org/image/loader;1", &rv);
90 NS_ENSURE_SUCCESS(rv, rv);
95 rv = imgloader->LoadImage(aURI, aURI, aURI, nsnull,
this, nsnull,
96 nsIRequest::LOAD_BACKGROUND, nsnull, nsnull,
98 NS_ENSURE_SUCCESS(rv, rv);
106 return NS_ERROR_NOT_INITIALIZED;
132 printf(
"dispatching context menu event\n");
136 self->DispatchEvent(NS_LITERAL_STRING(
"mouseup"), 2 );
137 self->DispatchEvent(NS_LITERAL_STRING(
"click"), 2 );
138 self->DispatchEvent(NS_LITERAL_STRING(
"contextmenu"), 2 );
147 self->DispatchEvent(NS_LITERAL_STRING(
"mouseup"), 0 );
148 self->DispatchEvent(NS_LITERAL_STRING(
"click"), 0 );
157 if (NS_FAILED(rv))
return;
159 nsCOMPtr<nsIDOMDocument>
doc;
160 rv = node->GetOwnerDocument(getter_AddRefs(doc));
161 if (NS_FAILED(rv))
return;
163 nsCOMPtr<nsIDOMDocumentEvent> docEvent(do_QueryInterface(doc, &rv));
164 if (NS_FAILED(rv))
return;
166 nsCOMPtr<nsIDOMEvent>
event;
167 rv = docEvent->CreateEvent(NS_LITERAL_STRING(
"mouseevent"),
168 getter_AddRefs(event));
169 if (NS_FAILED(rv))
return;
171 nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(event, &rv));
172 if (NS_FAILED(rv))
return;
175 nsCOMPtr<nsIDOMDocumentView> documentView(do_QueryInterface(doc, &rv));
176 if (NS_FAILED(rv))
return;
178 nsCOMPtr<nsIDOMAbstractView> view;
179 rv = documentView->GetDefaultView(getter_AddRefs(view));
180 if (NS_FAILED(rv))
return;
185 hasRect = gtk_status_icon_get_geometry(
mIcon, NULL, &rect, NULL);
192 rv = mouseEvent->InitMouseEvent(aType,
193 PR_FALSE, PR_TRUE, view, 1 ,
194 rect.x, rect.y, rect.x, rect.y,
195 0, 0, 0, 0, aButton, nsnull);
196 if (NS_FAILED(rv))
return;
205 NS_IMETHODIMP nsSystemTrayIconGTK::OnStartRequest(imgIRequest *aRequest)
211 NS_IMETHODIMP nsSystemTrayIconGTK::OnStartDecode(imgIRequest *aRequest)
217 NS_IMETHODIMP nsSystemTrayIconGTK::OnStartContainer(imgIRequest *aRequest, imgIContainer *aContainer)
224 nsSystemTrayIconGTK::OnStartFrame(imgIRequest *aRequest,
233 nsSystemTrayIconGTK::OnDataAvailable(imgIRequest *aRequest,
234 PRBool aCurrentFrame,
235 const nsIntRect * aRect)
242 nsSystemTrayIconGTK::OnStopFrame(imgIRequest *aRequest,
250 return NS_ERROR_UNEXPECTED;
253 nsCOMPtr<imgIContainer> image;
254 rv = aRequest->GetImage(getter_AddRefs(image));
255 NS_ENSURE_SUCCESS(rv, rv);
257 nsCOMPtr<nsIImageToPixbuf> imgToPixbuf =
258 do_GetService(
"@mozilla.org/widget/image-to-gdk-pixbuf;1", &rv);
259 NS_ENSURE_SUCCESS(rv, rv);
261 GdkPixbuf* pixbuf = imgToPixbuf->ConvertImageToPixbuf(image);
263 return NS_ERROR_FAILURE;
266 gtk_status_icon_set_from_pixbuf(
mIcon, pixbuf);
271 NS_IMETHODIMP nsSystemTrayIconGTK::OnStopContainer(imgIRequest *aRequest, imgIContainer *aContainer)
277 NS_IMETHODIMP nsSystemTrayIconGTK::OnStopDecode(imgIRequest *aRequest, nsresult status,
const PRUnichar *statusArg)
283 NS_IMETHODIMP nsSystemTrayIconGTK::OnStopRequest(imgIRequest *aRequest, PRBool aIsLastPart)
292 nsSystemTrayIconGTK::FrameChanged(imgIContainer *aContainer,
293 nsIntRect * aDirtyRect)
nsresult SetEventTarget(nsIDOMEventTarget *aEventTarget)
nsresult SetImageFromURI(nsIURI *aURI)
static void OnActivate(GtkStatusIcon *status_icon, gpointer user_data)
function doc() browser.contentDocument
void DispatchEvent(const nsAString &aType, PRUint16 aButton)
nsCOMPtr< imgIRequest > mRequest
NS_IMPL_ISUPPORTS2(nsSystemTrayIconGTK, imgIDecoderObserver, imgIContainerObserver) nsSystemTrayIconGTK
nsCOMPtr< nsIDOMEventTarget > mEventTarget
static void OnPopupMenu(GtkStatusIcon *status_icon, guint button, guint activate_time, gpointer user_data)