Back to index

lightning-sunbird  0.9+nobinonly
nsUICommandCollector.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* vim:set ts=2 sw=2 sts=2 et cindent: */
00003 /* ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Metrics extension.
00017  *
00018  * The Initial Developer of the Original Code is Google Inc.
00019  * Portions created by the Initial Developer are Copyright (C) 2006
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Marria Nazif <marria@gmail.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsUICommandCollector_h_
00040 #define nsUICommandCollector_h_
00041 
00042 #include "nsIObserver.h"
00043 #include "nsIDOMEventListener.h"
00044 #include "nsIMetricsCollector.h"
00045 
00046 #include "nsDataHashtable.h"
00047 
00048 class nsIDOMWindow;
00049 class nsIMetricsEventItem;
00050 class nsIWritablePropertyBag2;
00051 
00052 class nsUICommandCollector : public nsIObserver,
00053                              public nsIDOMEventListener,
00054                              public nsIMetricsCollector
00055 {
00056  public:
00057 
00058   NS_DECL_ISUPPORTS
00059   NS_DECL_NSIOBSERVER
00060   NS_DECL_NSIDOMEVENTLISTENER
00061   NS_DECL_NSIMETRICSCOLLECTOR
00062   
00063   static PLDHashOperator PR_CALLBACK AddCommandEventListener(
00064     const nsIDOMWindow* key, PRUint32 windowID, void* userArg);
00065 
00066   static PLDHashOperator PR_CALLBACK RemoveCommandEventListener(
00067     const nsIDOMWindow* key, PRUint32 windowID, void* userArg);
00068 
00069   nsUICommandCollector();
00070 
00071   // Given a command event, determines the appropriate id and anonid values
00072   // to log.  Returns failure if no id or anonid exists for the event target.
00073   nsresult GetEventTargets(nsIDOMEvent *event,
00074                            nsString &targetId, nsString &targetAnonId) const;
00075 
00076   // Given a command event, determines whether the source was a key element.
00077   // If so, keyId is set to the id of the element.
00078   void GetEventKeyId(nsIDOMEvent *event, nsString &keyId) const;
00079 
00080   // Given a DOM event, finds the id of the window that contains the target.
00081   nsresult GetEventWindow(nsIDOMEvent *event, PRUint32 *window) const;
00082 
00083  private:
00084   // This struct specifies an event we want to handle, and the method
00085   // that handles it.
00086   struct EventHandler {
00087     const char* event;
00088     nsresult (nsUICommandCollector::* handler)(nsIDOMEvent*);
00089   };
00090 
00091   // The events we'll handle.
00092   static const EventHandler kEvents[];
00093 
00094   ~nsUICommandCollector();
00095 
00096   // Adds all of our event types as listeners on the window.
00097   void AddEventListeners(nsIDOMEventTarget* window);
00098 
00099   // Removes all of our event types as listeners on the window.
00100   void RemoveEventListeners(nsIDOMEventTarget* window);
00101 
00102   // Handles a XUL command event.
00103   nsresult HandleCommandEvent(nsIDOMEvent* event);
00104 
00105   // Handles a TabMove event from the tabbrowser widget.
00106   nsresult HandleTabMoveEvent(nsIDOMEvent* event);
00107 
00108   // Checks whether the given target id corresponds to a bookmark resource,
00109   // and if so, adds additional data about the bookmark to parentItem.
00110   nsresult LogBookmarkInfo(const nsString& id,
00111                            nsIMetricsEventItem* parentItem);
00112 
00113   // Hashes the given property value and adds it to the property bag.
00114   nsresult SetHashedValue(nsIWritablePropertyBag2 *properties,
00115                           const nsString &propertyName,
00116                           const nsString &propertyValue) const;
00117 };
00118 
00119 #define NS_UICOMMANDCOLLECTOR_CLASSNAME "UI Command Collector"
00120 #define NS_UICOMMANDCOLLECTOR_CID \
00121 { 0xcc2fedc9, 0x8b2e, 0x4e2c, {0x97, 0x07, 0xe2, 0xe5, 0x6b, 0xeb, 0x01, 0x85}}
00122 
00123 #endif // nsUICommandCollector_h_