Merge mozilla-inbound and mozilla-central
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 17 Aug 2011 07:33:32 -0400
changeset 75408 dcb25d71220d814454b68aba05c761c91b265992
parent 75394 3d615a56ad46e4de2494d0f987fc12be7f45d0e9 (current diff)
parent 75407 4533e6c94fe790043a1ebdbb7de1bd1a75bddacb (diff)
child 75409 700eb783676a0609afcf4cf8b0a2897961a5df6b
child 75416 be37d04181293fdaa17d1b5ed5a614eaa481aaf3
child 75471 4c3632a6d26b052fd19fba1491607045a2392ede
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
milestone9.0a1
Merge mozilla-inbound and mozilla-central
--- a/accessible/src/base/AccEvent.cpp
+++ b/accessible/src/base/AccEvent.cpp
@@ -131,49 +131,20 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NATIVE
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AccEvent, AddRef)
 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AccEvent, Release)
 
 ////////////////////////////////////////////////////////////////////////////////
 // AccEvent protected methods
 
-nsAccessible *
+nsAccessible*
 AccEvent::GetAccessibleForNode() const
 {
-  if (!mNode)
-    return nsnull;
-
-  nsAccessible *accessible = GetAccService()->GetAccessible(mNode);
-
-#ifdef MOZ_XUL
-  // hack for xul tree table. We need a better way for firing delayed event
-  // against xul tree table. see bug 386821.
-  // There will be problem if some day we want to fire delayed event against
-  // the xul tree itself or an unselected treeitem.
-  nsCOMPtr<nsIContent> content(do_QueryInterface(mNode));
-  if (content && content->NodeInfo()->Equals(nsAccessibilityAtoms::tree,
-                                             kNameSpaceID_XUL)) {
-
-    nsCOMPtr<nsIDOMXULMultiSelectControlElement> multiSelect =
-      do_QueryInterface(mNode);
-
-    if (multiSelect) {
-      PRInt32 treeIndex = -1;
-      multiSelect->GetCurrentIndex(&treeIndex);
-      if (treeIndex >= 0) {
-        nsRefPtr<nsXULTreeAccessible> treeAcc = do_QueryObject(accessible);
-        if (treeAcc)
-          return treeAcc->GetTreeItemAccessible(treeIndex);
-      }
-    }
-  }
-#endif
-
-  return accessible;
+  return mNode ? GetAccService()->GetAccessible(mNode) : nsnull;
 }
 
 void
 AccEvent::CaptureIsFromUserInput(EIsFromUserInput aIsFromUserInput)
 {
   nsINode *targetNode = GetNode();
 
 #ifdef DEBUG
--- a/accessible/src/base/nsRootAccessible.cpp
+++ b/accessible/src/base/nsRootAccessible.cpp
@@ -388,20 +388,20 @@ nsRootAccessible::FireAccessibleFocusEve
   }
 
   NS_IF_RELEASE(gLastFocusedNode);
   gLastFocusedNode = focusNode;
   NS_IF_ADDREF(gLastFocusedNode);
 
   // Coalesce focus events from the same document, because DOM focus event might
   // be fired for the document node and then for the focused DOM element.
-  focusDocument->FireDelayedAccessibleEvent(nsIAccessibleEvent::EVENT_FOCUS,
-                                            focusNode,
-                                            AccEvent::eCoalesceFromSameDocument,
-                                            aIsFromUserInput);
+  nsRefPtr<AccEvent> focusEvent =
+    new AccEvent(nsIAccessibleEvent::EVENT_FOCUS, focusAccessible,
+                 aIsFromUserInput, AccEvent::eCoalesceFromSameDocument);
+  focusDocument->FireDelayedAccessibleEvent(focusEvent);
 }
 
 void
 nsRootAccessible::FireCurrentFocusEvent()
 {
   if (IsDefunct())
     return;
 
--- a/accessible/tests/mochitest/events/Makefile.in
+++ b/accessible/tests/mochitest/events/Makefile.in
@@ -61,16 +61,17 @@ include $(topsrcdir)/config/rules.mk
 		test_contextmenu.html \
 		test_docload.html \
 		test_docload.xul \
 		test_dragndrop.html \
 		test_flush.html \
 		test_focus.html \
 		test_focus.xul \
 		test_focus_name.html \
+		test_focus_tree.xul \
 		test_focusdoc.html \
 		test_menu.xul \
 		test_mutation.html \
 		test_mutation.xhtml \
 		test_scroll.xul \
 		test_selection.html \
 		test_statechange.html \
 		test_text_alg.html \
new file mode 100644
--- /dev/null
+++ b/accessible/tests/mochitest/events/test_focus_tree.xul
@@ -0,0 +1,120 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="XUL tree focus testing">
+
+  <script type="application/javascript" 
+          src="chrome://mochikit/content/MochiKit/packed.js" />
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+  <script type="application/javascript"
+          src="../treeview.js" />
+
+  <script type="application/javascript"
+          src="../common.js" />
+  <script type="application/javascript"
+          src="../events.js" />
+
+  <script type="application/javascript">
+  <![CDATA[
+
+    ////////////////////////////////////////////////////////////////////////////
+    // Invokers
+
+    function setTreeView(aTreeID, aView)
+    {
+      this.DOMNode = getNode(aTreeID);
+
+      this.eventSeq = [
+        new invokerChecker(EVENT_REORDER, this.DOMNode)
+      ];
+
+      this.invoke = function setTreeView_invoke()
+      {
+        this.DOMNode.treeBoxObject.view = aView;
+      }
+
+      this.getID = function setTreeView_getID()
+        { return "set tree view for " + prettyName(aTreeID); }
+    };
+
+    function focusTree(aTreeID)
+    {
+      var checker = new invokerChecker(EVENT_FOCUS, getFirstTreeItem, aTreeID);
+      this.__proto__ = new synthFocus(aTreeID, [ checker ]);
+    }
+
+    function moveToNextItem(aTreeID)
+    {
+      var checker = new invokerChecker(EVENT_FOCUS, getSecondTreeItem, aTreeID);
+      this.__proto__ = new synthDownKey(aTreeID, [ checker ]);
+    }
+
+    ////////////////////////////////////////////////////////////////////////////
+    // Helpers
+
+    function getTreeItemAt(aTreeID, aIdx)
+      { return getAccessible(aTreeID).getChildAt(aIdx + 1); }
+
+    function getFirstTreeItem(aTreeID)
+      { return getTreeItemAt(aTreeID, 0); }
+
+    function getSecondTreeItem(aTreeID)
+      { return getTreeItemAt(aTreeID, 1); }
+
+    ////////////////////////////////////////////////////////////////////////////
+    // Test
+
+    var gQueue = null;
+
+    //gA11yEventDumpID = "debug"; // debugging
+    //gA11yEventDumpToConsole = true; // debugging
+
+    function doTest()
+    {
+      gQueue = new eventQueue();
+
+      gQueue.push(new setTreeView("tree", new nsTableTreeView(5)));
+      gQueue.push(new focusTree("tree"));
+      gQueue.push(new moveToNextItem("tree"));
+
+      gQueue.invoke();
+    }
+
+    SimpleTest.waitForExplicitFinish();
+    addA11yLoadEvent(doTest);
+  ]]>
+  </script>
+
+  <hbox flex="1" style="overflow: auto;">
+    <body xmlns="http://www.w3.org/1999/xhtml">
+      <a target="_blank"
+         href="https://bugzilla.mozilla.org/show_bug.cgi?id=386821"
+         title="Need better solution for firing delayed event against xul tree">
+        Mozilla Bug 386821
+      </a><br/>
+      <p id="display"></p>
+      <div id="content" style="display: none">
+      </div>
+      <pre id="test">
+      </pre>
+    </body>
+
+    <vbox id="debug"/>
+    <tree id="tree" flex="1">
+      <treecols>
+        <treecol id="col1" flex="1" primary="true" label="column"/>
+        <treecol id="col2" flex="1" label="column 2"/>
+      </treecols>
+      <treechildren id="treechildren"/>
+    </tree>
+  </hbox>
+
+</window>
+
--- a/configure.in
+++ b/configure.in
@@ -5189,29 +5189,30 @@ incorrect])
                       MOZ_ENABLE_QTNETWORK=)
 
     if test "$MOZ_ENABLE_QTNETWORK"; then
       MOZ_ENABLE_QTNETWORK=1
       AC_DEFINE(MOZ_ENABLE_QTNETWORK)
     fi
 
     MOZ_ENABLE_QTMOBILITY=
-    PKG_CHECK_MODULES(_QTMOBILITY, QtSensors,
+    PKG_CHECK_MODULES(_QTMOBILITY, QtSensors QtFeedback,
                       MOZ_ENABLE_QTMOBILITY=1,
                       MOZ_ENABLE_QTMOBILITY=)
     if test "$MOZ_ENABLE_QTMOBILITY"; then
        MOZ_ENABLE_QTMOBILITY=1
        MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS $_QTMOBILITY_CFLAGS"
        MOZ_QT_LIBS="$MOZ_QT_LIBS $_QTMOBILITY_LIBS"
     else
-       AC_CHECK_LIB(QtSensors, main, [
+       AC_CHECK_LIB(QtSensors QtFeedback, main, [
           MOZ_ENABLE_QTMOBILITY=1
           MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I/usr/include/qt4/QtMobility"
           MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I/usr/include/qt4/QtSensors"
-          MOZ_QT_LIBS="$MOZ_QT_LIBS -lQtSensors"
+          MOZ_QT_CFLAGS="$MOZ_QT_CFLAGS -I/usr/include/qt4/QtFeedback"
+          MOZ_QT_LIBS="$MOZ_QT_LIBS -lQtSensors -lQtFeedback"
        ])
     fi
     if test "$MOZ_ENABLE_QTMOBILITY"; then
        AC_DEFINE(MOZ_ENABLE_QTMOBILITY)
     fi
 fi
 
 AC_SUBST(GTK_CONFIG)
--- a/dom/plugins/ipc/PPluginModule.ipdl
+++ b/dom/plugins/ipc/PPluginModule.ipdl
@@ -107,16 +107,18 @@ child:
   rpc NPP_GetSitesWithData()
     returns (nsCString[] sites);
 
   // Windows specific message to set up an audio session in the plugin process
   async SetAudioSessionData(nsID aID,
                             nsString aDisplayName,
                             nsString aIconPath);
 
+  async SetParentHangTimeout(uint32_t seconds);
+
 parent:
   /**
    * This message is only used on X11 platforms.
    *
    * Send a dup of the plugin process's X socket to the parent
    * process.  In theory, this scheme keeps the plugin's X resources
    * around until after both the plugin process shuts down *and* the
    * parent process closes the dup fd.  This is used to prevent the
--- a/dom/plugins/ipc/PluginModuleChild.cpp
+++ b/dom/plugins/ipc/PluginModuleChild.cpp
@@ -39,16 +39,17 @@
 
 #ifdef MOZ_WIDGET_QT
 #include <QtCore/QTimer>
 #include "nsQAppInstance.h"
 #include "NestedLoopTimer.h"
 #endif
 
 #include "mozilla/plugins/PluginModuleChild.h"
+#include "mozilla/ipc/SyncChannel.h"
 
 #ifdef MOZ_WIDGET_GTK2
 #include <gtk/gtk.h>
 #endif
 
 #include "nsILocalFile.h"
 
 #include "pratom.h"
@@ -509,16 +510,34 @@ PluginModuleChild::ExitedCxxStack()
                       "nested loop timeout not scheduled");
     delete mNestedLoopTimerObject;
     mNestedLoopTimerObject = NULL;
 }
 
 #endif
 
 bool
+PluginModuleChild::RecvSetParentHangTimeout(const uint32_t& aSeconds)
+{
+#ifdef XP_WIN
+    SetReplyTimeoutMs(((aSeconds > 0) ? (1000 * aSeconds) : 0));
+#endif
+    return true;
+}
+
+bool
+PluginModuleChild::ShouldContinueFromReplyTimeout()
+{
+#ifdef XP_WIN
+    NS_RUNTIMEABORT("terminating child process");
+#endif
+    return true;
+}
+
+bool
 PluginModuleChild::InitGraphics()
 {
 #if defined(MOZ_WIDGET_GTK2)
     // Work around plugins that don't interact well with GDK
     // client-side windows.
     PR_SetEnv("GDK_NATIVE_WINDOWS=1");
 
     gtk_init(0, 0);
--- a/dom/plugins/ipc/PluginModuleChild.h
+++ b/dom/plugins/ipc/PluginModuleChild.h
@@ -106,16 +106,19 @@ class PluginModuleChild : public PPlugin
 protected:
     NS_OVERRIDE
     virtual mozilla::ipc::RPCChannel::RacyRPCPolicy
     MediateRPCRace(const Message& parent, const Message& child)
     {
         return MediateRace(parent, child);
     }
 
+    NS_OVERRIDE
+    virtual bool ShouldContinueFromReplyTimeout();
+
     // Implement the PPluginModuleChild interface
     virtual bool AnswerNP_GetEntryPoints(NPError* rv);
     virtual bool AnswerNP_Initialize(NativeThreadId* tid, NPError* rv);
 
     virtual PPluginIdentifierChild*
     AllocPPluginIdentifier(const nsCString& aString,
                            const int32_t& aInt,
                            const bool& aTemporary);
@@ -163,16 +166,19 @@ protected:
     virtual bool
     AnswerNPP_GetSitesWithData(InfallibleTArray<nsCString>* aResult);
 
     virtual bool
     RecvSetAudioSessionData(const nsID& aId,
                             const nsString& aDisplayName,
                             const nsString& aIconPath);
 
+    virtual bool
+    RecvSetParentHangTimeout(const uint32_t& aSeconds);
+
     virtual void
     ActorDestroy(ActorDestroyReason why);
 
     NS_NORETURN void QuickExit();
 
     NS_OVERRIDE virtual bool
     RecvProcessNativeEventsInRPCCall();
 
--- a/dom/plugins/ipc/PluginModuleParent.cpp
+++ b/dom/plugins/ipc/PluginModuleParent.cpp
@@ -74,17 +74,18 @@ using base::KillProcess;
 
 using mozilla::PluginLibrary;
 using mozilla::ipc::SyncChannel;
 
 using namespace mozilla;
 using namespace mozilla::plugins;
 using namespace mozilla::plugins::parent;
 
-static const char kTimeoutPref[] = "dom.ipc.plugins.timeoutSecs";
+static const char kChildTimeoutPref[] = "dom.ipc.plugins.timeoutSecs";
+static const char kParentTimeoutPref[] = "dom.ipc.plugins.parentTimeoutSecs";
 static const char kLaunchTimeoutPref[] = "dom.ipc.plugins.processLaunchTimeoutSecs";
 
 template<>
 struct RunnableMethodTraits<mozilla::plugins::PluginModuleParent>
 {
     typedef mozilla::plugins::PluginModuleParent Class;
     static void RetainCallee(Class* obj) { }
     static void ReleaseCallee(Class* obj) { }
@@ -104,17 +105,17 @@ PluginModuleParent::LoadModule(const cha
     if (!launched) {
         // Need to set this so the destructor doesn't complain.
         parent->mShutdown = true;
         return nsnull;
     }
     parent->Open(parent->mSubprocess->GetChannel(),
                  parent->mSubprocess->GetChildProcessHandle());
 
-    TimeoutChanged(kTimeoutPref, parent);
+    TimeoutChanged(kChildTimeoutPref, parent);
     return parent.forget();
 }
 
 
 PluginModuleParent::PluginModuleParent(const char* aFilePath)
     : mSubprocess(new PluginProcessParent(aFilePath))
     , mPluginThread(0)
     , mShutdown(false)
@@ -126,17 +127,18 @@ PluginModuleParent::PluginModuleParent(c
     , mTaskFactory(this)
 {
     NS_ASSERTION(mSubprocess, "Out of memory!");
 
     if (!mIdentifiers.Init()) {
         NS_ERROR("Out of memory");
     }
 
-    Preferences::RegisterCallback(TimeoutChanged, kTimeoutPref, this);
+    Preferences::RegisterCallback(TimeoutChanged, kChildTimeoutPref, this);
+    Preferences::RegisterCallback(TimeoutChanged, kParentTimeoutPref, this);
 }
 
 PluginModuleParent::~PluginModuleParent()
 {
     NS_ASSERTION(OkToCleanup(), "unsafe destruction");
 
 #ifdef OS_MACOSX
     if (mCATimer) {
@@ -151,17 +153,18 @@ PluginModuleParent::~PluginModuleParent(
     }
     NS_ASSERTION(mShutdown, "NP_Shutdown didn't");
 
     if (mSubprocess) {
         mSubprocess->Delete();
         mSubprocess = nsnull;
     }
 
-    Preferences::UnregisterCallback(TimeoutChanged, kTimeoutPref, this);
+    Preferences::UnregisterCallback(TimeoutChanged, kChildTimeoutPref, this);
+    Preferences::UnregisterCallback(TimeoutChanged, kParentTimeoutPref, this);
 }
 
 #ifdef MOZ_CRASHREPORTER
 void
 PluginModuleParent::WritePluginExtraDataForMinidump(const nsAString& id)
 {
     typedef nsDependentCString CS;
 
@@ -221,24 +224,27 @@ PluginModuleParent::RecvAppendNotesToCra
     mCrashNotes.Append(aNotes);
     return true;
 }
 
 int
 PluginModuleParent::TimeoutChanged(const char* aPref, void* aModule)
 {
     NS_ASSERTION(NS_IsMainThread(), "Wrong thead!");
-    NS_ABORT_IF_FALSE(!strcmp(aPref, kTimeoutPref),
-                      "unexpected pref callback");
-
-    PRInt32 timeoutSecs = Preferences::GetInt(kTimeoutPref, 0);
-    int32 timeoutMs = (timeoutSecs > 0) ? (1000 * timeoutSecs) :
-                      SyncChannel::kNoTimeout;
-
-    static_cast<PluginModuleParent*>(aModule)->SetReplyTimeoutMs(timeoutMs);
+    if (!strcmp(aPref, kChildTimeoutPref)) {
+      // The timeout value used by the parent for children
+      PRInt32 timeoutSecs = Preferences::GetInt(kChildTimeoutPref, 0);
+      int32 timeoutMs = (timeoutSecs > 0) ? (1000 * timeoutSecs) :
+                        SyncChannel::kNoTimeout;
+      static_cast<PluginModuleParent*>(aModule)->SetReplyTimeoutMs(timeoutMs);
+    } else if (!strcmp(aPref, kParentTimeoutPref)) {
+      // The timeout value used by the child for its parent
+      PRInt32 timeoutSecs = Preferences::GetInt(kParentTimeoutPref, 0);
+      static_cast<PluginModuleParent*>(aModule)->SendSetParentHangTimeout(timeoutSecs);
+    }
     return 0;
 }
 
 void
 PluginModuleParent::CleanupFromTimeout()
 {
     if (!mShutdown)
         Close();
@@ -916,16 +922,18 @@ PluginModuleParent::NPP_New(NPMIMEType p
         return NS_ERROR_FAILURE;
     }
 
     if (*error != NPERR_NO_ERROR) {
         NPP_Destroy(instance, 0);
         return NS_ERROR_FAILURE;
     }
 
+    TimeoutChanged(kParentTimeoutPref, this);
+    
     return NS_OK;
 }
 
 nsresult
 PluginModuleParent::NPP_ClearSiteData(const char* site, uint64_t flags,
                                       uint64_t maxAge)
 {
     if (!mClearSiteDataSupported)
--- a/dom/system/unix/Makefile.in
+++ b/dom/system/unix/Makefile.in
@@ -61,11 +61,15 @@ ifdef MOZ_MAEMO_LIBLOCATION
                            -I$(topsrcdir)/dom/src/geolocation \
                            $(NULL)
 endif
 
 ifdef MOZ_PLATFORM_MAEMO
 CPPSRCS += nsHapticFeedback.cpp
 LOCAL_INCLUDES  += $(MOZ_DBUS_CFLAGS) \
                    $(NULL)
+ifdef MOZ_ENABLE_QTMOBILITY
+LOCAL_INCLUDES  += $(MOZ_QT_CFLAGS) \
+                   $(NULL)
+endif
 endif
 
 include $(topsrcdir)/config/rules.mk
--- a/dom/system/unix/nsHapticFeedback.cpp
+++ b/dom/system/unix/nsHapticFeedback.cpp
@@ -30,21 +30,26 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include "nsHapticFeedback.h"
 #if (MOZ_PLATFORM_MAEMO == 5)
 #include <dbus/dbus.h>
 #include <mce/dbus-names.h>
 #endif
+#if defined(MOZ_ENABLE_QTMOBILITY)
+#include <QFeedbackEffect>
+using namespace QtMobility;
+#endif
+
+#include "nsHapticFeedback.h"
 
 NS_IMPL_ISUPPORTS1(nsHapticFeedback, nsIHapticFeedback)
 
 NS_IMETHODIMP
 nsHapticFeedback::PerformSimpleAction(PRInt32 aType)
 {
 #if (MOZ_PLATFORM_MAEMO == 5)
     DBusError err;
@@ -79,11 +84,17 @@ nsHapticFeedback::PerformSimpleAction(PR
 
     if (dbus_connection_send(connection, msg, NULL)) {
         dbus_connection_flush(connection);
         dbus_message_unref(msg);
     } else {
         dbus_message_unref(msg);
         return NS_ERROR_FAILURE;
     }
+#elif defined(MOZ_ENABLE_QTMOBILITY)
+    if (aType == ShortPress)
+        QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeBasicButton);
+    if (aType == LongPress)
+        QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeLongPress);
 #endif
+
     return NS_OK;
 }
--- a/js/src/assembler/assembler/ARMAssembler.cpp
+++ b/js/src/assembler/assembler/ARMAssembler.cpp
@@ -270,73 +270,73 @@ ARMWord ARMAssembler::encodeComplexImm(A
 }
 
 // Memory load/store helpers
 // TODO: this does not take advantage of all of ARMv7's instruction encodings, it should.
 void ARMAssembler::dataTransferN(bool isLoad, bool isSigned, int size, RegisterID rt, RegisterID base, int32_t offset)
 {
     bool posOffset = true;
 
-    // there may be more elegant ways of handling this, but this one works.
+    // There may be more elegant ways of handling this, but this one works.
     if (offset == 0x80000000) {
-        // for even bigger offsets, load the entire offset into a register, then do an
-        // indexed load using the base register and the index register
+        // For even bigger offsets, load the entire offset into a register, then do an
+        // indexed load using the base register and the index register.
         moveImm(offset, ARMRegisters::S0);
         mem_reg_off(isLoad, isSigned, size, posOffset, rt, base, ARMRegisters::S0);
         return;
     }
     if (offset < 0) {
         offset = - offset;
         posOffset = false;
     }
     if (offset <= 0xfff) {
         // LDR rd, [rb, #+offset]
         mem_imm_off(isLoad, isSigned, size, posOffset, rt, base, offset);
     } else if (offset <= 0xfffff) {
-        // add upper bits of offset to the base, and store the result into the temp registe
+        // Add upper bits of offset to the base, and store the result into the temp register.
         if (posOffset) {
-            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | (10 << 8));
+            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | getOp2RotLSL(12));
         } else {
-            sub_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | (10 << 8));
+            sub_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | getOp2RotLSL(12));
         }
-        // load using the lower bits of the offset
+        // Load using the lower bits of the offset.
         mem_imm_off(isLoad, isSigned, size, posOffset, rt,
                     ARMRegisters::S0, (offset & 0xfff));
     } else {
-        // for even bigger offsets, load the entire offset into a register, then do an
-        // indexed load using the base register and the index register
+        // For even bigger offsets, load the entire offset into a register, then do an
+        // indexed load using the base register and the index register.
         moveImm(offset, ARMRegisters::S0);
         mem_reg_off(isLoad, isSigned, size, posOffset, rt, base, ARMRegisters::S0);
     }
 }
 
 void ARMAssembler::dataTransfer32(bool isLoad, RegisterID srcDst, RegisterID base, int32_t offset)
 {
     if (offset >= 0) {
         if (offset <= 0xfff)
             // LDR rd, [rb, +offset]
             dtr_u(isLoad, srcDst, base, offset);
         else if (offset <= 0xfffff) {
-            // add upper bits of offset to the base, and store the result into the temp registe
-            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | (10 << 8));
-            // load using the lower bits of the register
+            // Add upper bits of offset to the base, and store the result into the temp register.
+            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | getOp2RotLSL(12));
+            // Load using the lower bits of the register.
             dtr_u(isLoad, srcDst, ARMRegisters::S0, (offset & 0xfff));
         } else {
-            // for even bigger offsets, load the entire offset into a registe, then do an
-            // indexed load using the base register and the index register
+            // For even bigger offsets, load the entire offset into a register, then do an
+            // indexed load using the base register and the index register.
             moveImm(offset, ARMRegisters::S0);
             dtr_ur(isLoad, srcDst, base, ARMRegisters::S0);
         }
     } else {
-        // negative offsets 
+        // Negative offsets.
         offset = -offset;
         if (offset <= 0xfff)
             dtr_d(isLoad, srcDst, base, offset);
         else if (offset <= 0xfffff) {
-            sub_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | (10 << 8));
+            sub_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | getOp2RotLSL(12));
             dtr_d(isLoad, srcDst, ARMRegisters::S0, (offset & 0xfff));
         } else {
             moveImm(offset, ARMRegisters::S0);
             dtr_dr(isLoad, srcDst, base, ARMRegisters::S0);
         }
     }
 }
 /* this is large, ugly and obsolete.  dataTransferN is superior.*/
@@ -344,17 +344,17 @@ void ARMAssembler::dataTransfer8(bool is
 {
     if (offset >= 0) {
         if (offset <= 0xfff) {
             if (isSigned)
                 mem_imm_off(isLoad, true, 8, true, srcDst, base, offset);
             else
                 dtrb_u(isLoad, srcDst, base, offset);
         } else if (offset <= 0xfffff) {
-            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | (10 << 8));
+            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | getOp2RotLSL(12));
             if (isSigned)
                 mem_imm_off(isLoad, true, 8, true, srcDst, ARMRegisters::S0, (offset & 0xfff));
             else
                 dtrb_u(isLoad, srcDst, ARMRegisters::S0, (offset & 0xfff));
         } else {
             moveImm(offset, ARMRegisters::S0);
             if (isSigned)
                 mem_reg_off(isLoad, true, 8, true, srcDst, base, ARMRegisters::S0);
@@ -365,17 +365,17 @@ void ARMAssembler::dataTransfer8(bool is
         offset = -offset;
         if (offset <= 0xfff) {
             if (isSigned)
                 mem_imm_off(isLoad, true, 8, false, srcDst, base, offset);
             else
                 dtrb_d(isLoad, srcDst, base, offset);
         }
         else if (offset <= 0xfffff) {
-            sub_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | (10 << 8));
+            sub_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 12) | getOp2RotLSL(12));
             if (isSigned)
                 mem_imm_off(isLoad, true, 8, false, srcDst, ARMRegisters::S0, (offset & 0xfff));
             else
                 dtrb_d(isLoad, srcDst, ARMRegisters::S0, (offset & 0xfff));
 
         } else {
             moveImm(offset, ARMRegisters::S0);
             if (isSigned)
@@ -430,85 +430,85 @@ void ARMAssembler::baseIndexTransferN(bo
     }
     ldr_un_imm(ARMRegisters::S0, offset);
     add_r(ARMRegisters::S0, ARMRegisters::S0, op2);
     mem_reg_off(isLoad, isSigned, size, true, srcDst, base, ARMRegisters::S0);
 }
 
 void ARMAssembler::doubleTransfer(bool isLoad, FPRegisterID srcDst, RegisterID base, int32_t offset)
 {
-    if (offset & 0x3) {
-        if (offset <= 0x3ff && offset >= 0) {
-            fdtr_u(isLoad, srcDst, base, offset >> 2);
-            return;
-        }
-        if (offset <= 0x3ffff && offset >= 0) {
-            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 10) | (11 << 8));
-            fdtr_u(isLoad, srcDst, ARMRegisters::S0, (offset >> 2) & 0xff);
-            return;
-        }
-        offset = -offset;
+    // VFP cannot directly access memory that is not four-byte-aligned, so
+    // special-case support will be required for such cases. However, we don't
+    // currently use any unaligned floating-point memory accesses and probably
+    // never will, so for now just assert that the offset is aligned.
+    //
+    // Note that we cannot assert that the base register is aligned, but in
+    // that case, an alignment fault will be raised at run-time.
+    ASSERT((offset & 0x3) == 0);
 
-        if (offset <= 0x3ff && offset >= 0) {
-            fdtr_d(isLoad, srcDst, base, offset >> 2);
+    // Try to use a single load/store instruction, or at least a simple address
+    // calculation.
+    if (offset >= 0) {
+        if (offset <= 0x3ff) {
+            fmem_imm_off(isLoad, true, true, srcDst, base, offset >> 2);
             return;
         }
-        if (offset <= 0x3ffff && offset >= 0) {
-            sub_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 10) | (11 << 8));
-            fdtr_d(isLoad, srcDst, ARMRegisters::S0, (offset >> 2) & 0xff);
+        if (offset <= 0x3ffff) {
+            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 10) | getOp2RotLSL(10));
+            fmem_imm_off(isLoad, true, true, srcDst, ARMRegisters::S0, (offset >> 2) & 0xff);
             return;
         }
-        offset = -offset;
+    } else {
+        if (offset >= -0x3ff) {
+            fmem_imm_off(isLoad, true, false, srcDst, base, -offset >> 2);
+            return;
+        }
+        if (offset >= -0x3ffff) {
+            sub_r(ARMRegisters::S0, base, OP2_IMM | (-offset >> 10) | getOp2RotLSL(10));
+            fmem_imm_off(isLoad, true, false, srcDst, ARMRegisters::S0, (-offset >> 2) & 0xff);
+            return;
+        }
     }
 
-    // TODO: This is broken in the case that offset is unaligned. VFP can never
-    // perform unaligned accesses, even from an unaligned register base. (NEON
-    // can, but VFP isn't NEON. It is not advisable to interleave a NEON load
-    // with VFP code, so the best solution here is probably to perform an
-    // unaligned integer load, then move the result into VFP using VMOV.)
-    ASSERT((offset & 0x3) == 0);
-
+    // Slow case for long-range accesses.
     ldr_un_imm(ARMRegisters::S0, offset);
     add_r(ARMRegisters::S0, ARMRegisters::S0, base);
-    fdtr_u(isLoad, srcDst, ARMRegisters::S0, 0);
+    fmem_imm_off(isLoad, true, true, srcDst, ARMRegisters::S0, 0);
 }
 
 void ARMAssembler::floatTransfer(bool isLoad, FPRegisterID srcDst, RegisterID base, int32_t offset)
 {
-    if (offset & 0x3) {
-        if (offset <= 0x3ff && offset >= 0) {
+    // Assert that the access is aligned, as in doubleTransfer.
+    ASSERT((offset & 0x3) == 0);
+
+    // Try to use a single load/store instruction, or at least a simple address
+    // calculation.
+    if (offset >= 0) {
+        if (offset <= 0x3ff) {
             fmem_imm_off(isLoad, false, true, srcDst, base, offset >> 2);
             return;
         }
-        if (offset <= 0x3ffff && offset >= 0) {
-            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 10) | (11 << 8));
+        if (offset <= 0x3ffff) {
+            add_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 10) | getOp2RotLSL(10));
             fmem_imm_off(isLoad, false, true, srcDst, ARMRegisters::S0, (offset >> 2) & 0xff);
             return;
         }
-        offset = -offset;
-
-        if (offset <= 0x3ff && offset >= 0) {
-            fmem_imm_off(isLoad, false, false, srcDst, base, offset >> 2);
-            return;
-        }
-        if (offset <= 0x3ffff && offset >= 0) {
-            sub_r(ARMRegisters::S0, base, OP2_IMM | (offset >> 10) | (11 << 8));
-            fmem_imm_off(isLoad, false, true, srcDst, ARMRegisters::S0, (offset >> 2) & 0xff);
+    } else {
+        if (offset >= -0x3ff) {
+            fmem_imm_off(isLoad, false, false, srcDst, base, -offset >> 2);
             return;
         }
-        offset = -offset;
+        if (offset >= -0x3ffff) {
+            sub_r(ARMRegisters::S0, base, OP2_IMM | (-offset >> 10) | getOp2RotLSL(10));
+            fmem_imm_off(isLoad, false, false, srcDst, ARMRegisters::S0, (-offset >> 2) & 0xff);
+            return;
+        }
     }
 
-    // TODO: This is broken in the case that offset is unaligned. VFP can never
-    // perform unaligned accesses, even from an unaligned register base. (NEON
-    // can, but VFP isn't NEON. It is not advisable to interleave a NEON load
-    // with VFP code, so the best solution here is probably to perform an
-    // unaligned integer load, then move the result into VFP using VMOV.)
-    ASSERT((offset & 0x3) == 0);
-
+    // Slow case for long-range accesses.
     ldr_un_imm(ARMRegisters::S0, offset);
     add_r(ARMRegisters::S0, ARMRegisters::S0, base);
     fmem_imm_off(isLoad, false, true, srcDst, ARMRegisters::S0, 0);
 }
 
 void ARMAssembler::baseIndexFloatTransfer(bool isLoad, bool isDouble, FPRegisterID srcDst, RegisterID base, RegisterID index, int scale, int32_t offset)
 {
     ARMWord op2;
--- a/js/src/assembler/assembler/ARMAssembler.h
+++ b/js/src/assembler/assembler/ARMAssembler.h
@@ -314,16 +314,29 @@ namespace JSC {
         // Instruction formating
 
         void emitInst(ARMWord op, int rd, int rn, ARMWord op2)
         {
             ASSERT ( ((op2 & ~OP2_IMM) <= 0xfff) || (((op2 & ~OP2_IMMh) <= 0xfff)) );
             m_buffer.putInt(op | RN(rn) | RD(rd) | op2);
         }
 
+        // Work out the pre-shifted constant necessary to encode the specified
+        // logical shift left for op2 immediates. Only even shifts can be
+        // applied.
+        //
+        // Input validity is asserted in debug builds.
+        ARMWord getOp2RotLSL(int lsl)
+        {
+            ASSERT((lsl >= 0) && (lsl <= 24));
+            ASSERT(!(lsl % 2));
+
+            return (-(lsl/2) & 0xf) << 8;
+        }
+
         void and_r(int rd, int rn, ARMWord op2, Condition cc = AL)
         {
             spewInsWithOp2("and", cc, rd, rn, op2);
             emitInst(static_cast<ARMWord>(cc) | AND, rd, rn, op2);
         }
 
         void ands_r(int rd, int rn, ARMWord op2, Condition cc = AL)
         {
@@ -1649,34 +1662,16 @@ namespace JSC {
         {
             js::JaegerSpew(js::JSpew_Insns,
                     IPFX   "%-15s %s, %s\n", MAYBE_PAD, "vsqrt.f64", nameFpRegD(dd), nameFpRegD(dm));
             // TODO: emitInst doesn't work for VFP instructions, though it
             // seems to work for current usage.
             emitInst(static_cast<ARMWord>(cc) | FSQRTD, dd, 0, dm);
         }
 
-        void fdtr_u(bool isLoad, int dd, int rn, ARMWord offset, Condition cc = AL)
-        {
-            char const * ins = isLoad ? "vldr.f64" : "vstr.f64";
-            js::JaegerSpew(js::JSpew_Insns,
-                    IPFX   "%-15s %s, [%s, #+%u]\n", MAYBE_PAD, ins, nameFpRegD(dd), nameGpReg(rn), offset);
-            ASSERT(offset <= 0xff);
-            emitInst(static_cast<ARMWord>(cc) | FDTR | DT_UP | (isLoad ? DT_LOAD : 0), dd, rn, offset);
-        }
-
-        void fdtr_d(bool isLoad, int dd, int rn, ARMWord offset, Condition cc = AL)
-        {
-            char const * ins = isLoad ? "vldr.f64" : "vstr.f64";
-            js::JaegerSpew(js::JSpew_Insns,
-                    IPFX   "%-15s %s, [%s, #-%u]\n", MAYBE_PAD, ins, nameFpRegD(dd), nameGpReg(rn), offset);
-            ASSERT(offset <= 0xff);
-            emitInst(static_cast<ARMWord>(cc) | FDTR | (isLoad ? DT_LOAD : 0), dd, rn, offset);
-        }
-
         void fmsr_r(int dd, int rn, Condition cc = AL)
         {
             // TODO: emitInst doesn't work for VFP instructions, though it
             // seems to work for current usage.
             emitInst(static_cast<ARMWord>(cc) | FMSR, rn, dd, 0);
         }
 
         void fmrs_r(int rd, int dn, Condition cc = AL)
--- a/js/src/assembler/assembler/MacroAssemblerARM.h
+++ b/js/src/assembler/assembler/MacroAssemblerARM.h
@@ -1132,17 +1132,17 @@ public:
         m_assembler.baseIndexFloatTransfer(true, true, dest,
                                            address.base, address.index,
                                            address.scale, address.offset);
     }
 
     DataLabelPtr loadDouble(const void* address, FPRegisterID dest)
     {
         DataLabelPtr label = moveWithPatch(ImmPtr(address), ARMRegisters::S0);
-        m_assembler.fdtr_u(true, dest, ARMRegisters::S0, 0);
+        m_assembler.doubleTransfer(true, dest, ARMRegisters::S0, 0);
         return label;
     }
 
     void fastLoadDouble(RegisterID lo, RegisterID hi, FPRegisterID fpReg) {
         m_assembler.vmov64(false, true, lo, hi, fpReg);
     }
 
     void loadFloat(ImplicitAddress address, FPRegisterID dest)
--- a/js/src/jsdbgapi.cpp
+++ b/js/src/jsdbgapi.cpp
@@ -1222,17 +1222,17 @@ JS_ClearContextDebugHooks(JSContext *cx)
 
 /* Profiling-related API */
 
 /* Thread-unsafe error management */
 
 static char gLastError[2000];
 
 static void
-#ifdef _GNU_SOURCE
+#ifdef __GNUC__
 __attribute__((unused,format(printf,1,2)))
 #endif
 UnsafeError(const char *format, ...)
 {
     va_list args;
     va_start(args, format);
     (void) vsnprintf(gLastError, sizeof(gLastError), format, args);
     va_end(args);
--- a/mobile/app/mobile.js
+++ b/mobile/app/mobile.js
@@ -158,16 +158,19 @@ pref("browser.download.manager.flashCoun
 pref("browser.download.manager.displayedHistoryDays", 7);
 
 /* download alerts (disabled above) */
 pref("alerts.slideIncrement", 1);
 pref("alerts.slideIncrementTime", 10);
 pref("alerts.totalOpenTime", 6000);
 pref("alerts.height", 50);
 
+/* download helper */
+pref("browser.helperApps.deleteTempFileOnExit", false);
+
 /* password manager */
 pref("signon.rememberSignons", true);
 pref("signon.expireMasterPassword", false);
 pref("signon.SignonFileName", "signons.txt");
 
 /* form helper */
 // 0 = disabled, 1 = enabled, 2 = dynamic depending on screen size
 pref("formhelper.mode", 2);
--- a/mobile/chrome/content/config.js
+++ b/mobile/chrome/content/config.js
@@ -86,16 +86,17 @@ var ViewConfig = {
     let buttons = document.getElementById("editor-buttons-add");
     buttons.setAttribute("hidden", "true");
 
     let shouldFocus = false;
     let setting = document.getElementById("editor-setting");
     switch (aType) {
       case Ci.nsIPrefBranch.PREF_INT:
         setting.setAttribute("type", "integer");
+        setting.setAttribute("min", -Infinity);
         break;
       case Ci.nsIPrefBranch.PREF_BOOL:
         setting.setAttribute("type", "bool");
         break;
       case Ci.nsIPrefBranch.PREF_STRING:
         setting.setAttribute("type", "string");
         break;
     }
@@ -153,16 +154,17 @@ var ViewConfig = {
     switch (pref.type) {
       case Ci.nsIPrefBranch.PREF_BOOL:
         setting.setAttribute("type", "bool");
         break;
 
       case Ci.nsIPrefBranch.PREF_INT:
         setting.setAttribute("type", "integer");
         setting.setAttribute("increment", this.getIncrementForValue(pref.value));
+        setting.setAttribute("min", -Infinity);
         shouldFocus = true;
         break;
 
       case Ci.nsIPrefBranch.PREF_STRING:
         setting.setAttribute("type", "string");
         shouldFocus = true;
         break;
     }
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -1448,23 +1448,28 @@ pref("editor.positioning.offset",       
 
 pref("dom.max_chrome_script_run_time", 20);
 pref("dom.max_script_run_time", 10);
 
 #ifndef DEBUG
 // How long a plugin is allowed to process a synchronous IPC message
 // before we consider it "hung".
 pref("dom.ipc.plugins.timeoutSecs", 45);
+// How long a plugin process will wait for a response from the parent
+// to a synchronous request before terminating itself. After this
+// point the child assumes the parent is hung.
+pref("dom.ipc.plugins.parentTimeoutSecs", 15);
 // How long a plugin launch is allowed to take before
 // we consider it failed.
 pref("dom.ipc.plugins.processLaunchTimeoutSecs", 45);
 #else
 // No timeout in DEBUG builds
 pref("dom.ipc.plugins.timeoutSecs", 0);
 pref("dom.ipc.plugins.processLaunchTimeoutSecs", 0);
+pref("dom.ipc.plugins.parentTimeoutSecs", 0);
 #endif
 
 // Disable oopp for standard java. They run their own process isolation (which
 // conflicts with our implementation, at least on Windows).
 pref("dom.ipc.plugins.java.enabled", false);
 
 #ifndef ANDROID
 #ifndef XP_MACOSX
--- a/netwerk/base/src/nsSocketTransportService2.cpp
+++ b/netwerk/base/src/nsSocketTransportService2.cpp
@@ -673,19 +673,16 @@ nsSocketTransportService::DoPollIteratio
 {
     SOCKET_LOG(("STS poll iter [%d]\n", wait));
 
     PRInt32 i, count;
 
     //
     // poll loop
     //
-    PRBool pollError = PR_FALSE;
-
-    //
     // walk active list backwards to see if any sockets should actually be
     // idle, then walk the idle list backwards to see if any idle sockets
     // should become active.  take care to check only idle sockets that
     // were idle to begin with ;-)
     //
     count = mIdleCount;
     for (i=mActiveCount-1; i>=0; --i) {
         //---
@@ -723,17 +720,16 @@ nsSocketTransportService::DoPollIteratio
     SOCKET_LOG(("  calling PR_Poll [active=%u idle=%u]\n", mActiveCount, mIdleCount));
 
     // Measures seconds spent while blocked on PR_Poll
     PRUint32 pollInterval;
 
     PRInt32 n = Poll(wait, &pollInterval);
     if (n < 0) {
         SOCKET_LOG(("  PR_Poll error [%d]\n", PR_GetError()));
-        pollError = PR_TRUE;
     }
     else {
         //
         // service "active" sockets...
         //
         for (i=0; i<PRInt32(mActiveCount); ++i) {
             PRPollDesc &desc = mPollList[i+1];
             SocketContext &s = mActiveList[i];
--- a/widget/src/qt/nsWindow.cpp
+++ b/widget/src/qt/nsWindow.cpp
@@ -3087,19 +3087,32 @@ nsWindow::AreBoundsSane(void)
 }
 
 NS_IMETHODIMP
 nsWindow::SetInputMode(const IMEContext& aContext)
 {
     NS_ENSURE_TRUE(mWidget, NS_ERROR_FAILURE);
 
     mIMEContext = aContext;
+
+     // Ensure that opening the virtual keyboard is allowed for this specific
+     // IMEContext depending on the content.ime.strict.policy pref
+     if (aContext.mStatus != nsIWidget::IME_STATUS_DISABLED && 
+         aContext.mStatus != nsIWidget::IME_STATUS_PLUGIN) {
+       if (Preferences::GetBool("content.ime.strict_policy", PR_FALSE) &&
+           !aContext.FocusMovedByUser() &&
+           aContext.FocusMovedInContentProcess()) {
+         return NS_OK;
+       }
+     }
+
     switch (aContext.mStatus) {
         case nsIWidget::IME_STATUS_ENABLED:
         case nsIWidget::IME_STATUS_PASSWORD:
+        case nsIWidget::IME_STATUS_PLUGIN:
             {
                 PRInt32 openDelay =
                     Preferences::GetInt("ui.vkb.open.delay", 200);
                 mWidget->requestVKB(openDelay);
             }
             break;
         default:
             mWidget->hideVKB();
--- a/widget/src/windows/nsClipboard.cpp
+++ b/widget/src/windows/nsClipboard.cpp
@@ -65,28 +65,37 @@
 #include "nsImageClipboard.h"
 #include "nsIWidget.h"
 #include "nsIComponentManager.h"
 #include "nsWidgetsCID.h"
 #include "nsCRT.h"
 #include "nsNetUtil.h"
 #include "nsEscape.h"
 
+#ifdef PR_LOGGING
+PRLogModuleInfo* gWin32ClipboardLog = nsnull;
+#endif
 
 // oddly, this isn't in the MSVC headers anywhere.
 UINT nsClipboard::CF_HTML = ::RegisterClipboardFormatW(L"HTML Format");
 
 
 //-------------------------------------------------------------------------
 //
 // nsClipboard constructor
 //
 //-------------------------------------------------------------------------
 nsClipboard::nsClipboard() : nsBaseClipboard()
 {
+#ifdef PR_LOGGING
+  if (!gWin32ClipboardLog) {
+    gWin32ClipboardLog = PR_NewLogModule("nsClipboard");
+  }
+#endif
+
   mIgnoreEmptyNotification = PR_FALSE;
   mWindow         = nsnull;
 }
 
 //-------------------------------------------------------------------------
 // nsClipboard destructor
 //-------------------------------------------------------------------------
 nsClipboard::~nsClipboard()
@@ -336,49 +345,50 @@ nsresult nsClipboard::GetNativeDataOffCl
   }
   return result;
 }
 
 static void DisplayErrCode(HRESULT hres) 
 {
 #if defined(DEBUG_rods) || defined(DEBUG_pinkerton)
   if (hres == E_INVALIDARG) {
-    printf("E_INVALIDARG\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("E_INVALIDARG\n"));
   } else
   if (hres == E_UNEXPECTED) {
-    printf("E_UNEXPECTED\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("E_UNEXPECTED\n"));
   } else
   if (hres == E_OUTOFMEMORY) {
-    printf("E_OUTOFMEMORY\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("E_OUTOFMEMORY\n"));
   } else
   if (hres == DV_E_LINDEX ) {
-    printf("DV_E_LINDEX\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_LINDEX\n"));
   } else
   if (hres == DV_E_FORMATETC) {
-    printf("DV_E_FORMATETC\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_FORMATETC\n"));
   }  else
   if (hres == DV_E_TYMED) {
-    printf("DV_E_TYMED\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_TYMED\n"));
   }  else
   if (hres == DV_E_DVASPECT) {
-    printf("DV_E_DVASPECT\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_DVASPECT\n"));
   }  else
   if (hres == OLE_E_NOTRUNNING) {
-    printf("OLE_E_NOTRUNNING\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("OLE_E_NOTRUNNING\n"));
   }  else
   if (hres == STG_E_MEDIUMFULL) {
-    printf("STG_E_MEDIUMFULL\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("STG_E_MEDIUMFULL\n"));
   }  else
   if (hres == DV_E_CLIPFORMAT) {
-    printf("DV_E_CLIPFORMAT\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("DV_E_CLIPFORMAT\n"));
   }  else
   if (hres == S_OK) {
-    printf("S_OK\n");
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, ("S_OK\n"));
   } else {
-    printf("****** DisplayErrCode 0x%X\n", hres);
+    PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, 
+           ("****** DisplayErrCode 0x%X\n", hres));
   }
 #endif
 }
 
 //-------------------------------------------------------------------------
 static HRESULT FillSTGMedium(IDataObject * aDataObject, UINT aFormat, LPFORMATETC pFE, LPSTGMEDIUM pSTM, DWORD aTymed)
 {
   SET_FORMATETC(*pFE, aFormat, 0, DVASPECT_CONTENT, -1, aTymed);
@@ -535,17 +545,18 @@ nsresult nsClipboard::GetNativeDataOffCl
               }
             } break;
           } // switch
         } break;
 
       case TYMED_GDI: 
         {
 #ifdef DEBUG
-          printf("*********************** TYMED_GDI\n");
+          PR_LOG(gWin32ClipboardLog, PR_LOG_ALWAYS, 
+                 ("*********************** TYMED_GDI\n"));
 #endif
         } break;
 
       default:
         break;
     } //switch
     
     ReleaseStgMedium(&stm);
--- a/widget/src/windows/nsDataObj.cpp
+++ b/widget/src/windows/nsDataObj.cpp
@@ -564,17 +564,18 @@ STDMETHODIMP nsDataObj::GetData(LPFORMAT
         if ( format == uniformResourceLocatorA )
           return GetUniformResourceLocator( *aFormat, *pSTM, PR_FALSE);
         if ( format == uniformResourceLocatorW )
           return GetUniformResourceLocator( *aFormat, *pSTM, PR_TRUE);
         if ( format == fileFlavor )
           return GetFileContents ( *aFormat, *pSTM );
         if ( format == PreferredDropEffect )
           return GetPreferredDropEffect( *aFormat, *pSTM );
-        //printf("***** nsDataObj::GetData - Unknown format %u\n", format);
+        //PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+        //       ("***** nsDataObj::GetData - Unknown format %u\n", format));
         return GetText(df, *aFormat, *pSTM);
       } //switch
     } // if
     dfInx++;
   } // while
 
   return DATA_E_FORMATETC;
 }
--- a/widget/src/windows/nsNativeThemeWin.cpp
+++ b/widget/src/windows/nsNativeThemeWin.cpp
@@ -67,16 +67,20 @@
 #include "gfxMatrix.h"
 #include "gfxWindowsPlatform.h"
 #include "gfxWindowsSurface.h"
 #include "gfxWindowsNativeDrawing.h"
 
 #include "nsUXThemeData.h"
 #include "nsUXThemeConstants.h"
 
+#ifdef PR_LOGGING
+extern PRLogModuleInfo* gWindowsLog;
+#endif
+
 NS_IMPL_ISUPPORTS_INHERITED1(nsNativeThemeWin, nsNativeTheme, nsITheme)
 
 static inline PRBool IsHTMLContent(nsIFrame *frame)
 {
   nsIContent* content = frame->GetContent();
   return content && content->IsHTML();
 }
 
@@ -1280,20 +1284,23 @@ RENDER_AGAIN:
   if (!hdc)
     return NS_ERROR_FAILURE;
 
   nativeDrawing.TransformToNativeRect(tr, widgetRect);
   nativeDrawing.TransformToNativeRect(dr, clipRect);
 
 #if 0
   {
-    fprintf (stderr, "xform: %f %f %f %f [%f %f]\n", m.xx, m.yx, m.xy, m.yy, m.x0, m.y0);
-    fprintf (stderr, "tr: [%d %d %d %d]\ndr: [%d %d %d %d]\noff: [%f %f]\n",
-             tr.x, tr.y, tr.width, tr.height, dr.x, dr.y, dr.width, dr.height,
-             offset.x, offset.y);
+    PR_LOG(gWindowsLog, PR_LOG_ERROR,
+           (stderr, "xform: %f %f %f %f [%f %f]\n", m.xx, m.yx, m.xy, m.yy, 
+            m.x0, m.y0));
+    PR_LOG(gWindowsLog, PR_LOG_ERROR,
+           (stderr, "tr: [%d %d %d %d]\ndr: [%d %d %d %d]\noff: [%f %f]\n",
+            tr.x, tr.y, tr.width, tr.height, dr.x, dr.y, dr.width, dr.height,
+            offset.x, offset.y));
   }
 #endif
 
   if (aWidgetType == NS_THEME_WINDOW_TITLEBAR) {
     // Clip out the left and right corners of the frame, all we want in
     // is the middle section.
     widgetRect.left -= GetSystemMetrics(SM_CXFRAME);
     widgetRect.right += GetSystemMetrics(SM_CXFRAME);
--- a/widget/src/windows/nsSound.cpp
+++ b/widget/src/windows/nsSound.cpp
@@ -46,18 +46,27 @@
 // mmsystem.h is needed to build with WIN32_LEAN_AND_MEAN
 #include <mmsystem.h>
 
 #include "nsSound.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "nsCRT.h"
 
+#include "prlog.h"
+#include "prtime.h"
+#include "prprf.h"
+#include "prmem.h"
+
 #include "nsNativeCharsetUtils.h"
 
+#ifdef PR_LOGGING
+PRLogModuleInfo* gWin32SoundLog = nsnull;
+#endif
+
 class nsSoundPlayer: public nsRunnable {
 public:
   nsSoundPlayer(nsISound *aSound, const wchar_t* aSoundName) :
     mSoundName(aSoundName), mSound(aSound)
   {
     Init();
   }
 
@@ -121,17 +130,23 @@ nsSoundPlayer::SoundReleaser::Run()
 #define SND_PURGE 0
 #endif
 
 NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
 
 
 nsSound::nsSound()
 {
-  mLastSound = nsnull;
+#ifdef PR_LOGGING
+    if (!gWin32SoundLog) {
+      gWin32SoundLog = PR_NewLogModule("nsSound");
+    }
+#endif
+
+    mLastSound = nsnull;
 }
 
 nsSound::~nsSound()
 {
   PurgeLastSound();
 }
 
 void nsSound::PurgeLastSound() {
@@ -172,17 +187,18 @@ NS_IMETHODIMP nsSound::OnStreamComplete(
       if (request)
           channel = do_QueryInterface(request);
       if (channel) {
         nsCOMPtr<nsIURI> uri;
         channel->GetURI(getter_AddRefs(uri));
         if (uri) {
           nsCAutoString uriSpec;
           uri->GetSpec(uriSpec);
-          printf("Failed to load %s\n", uriSpec.get());
+          PR_LOG(gWin32SoundLog, PR_LOG_ALWAYS,
+                 ("Failed to load %s\n", uriSpec.get()));
         }
       }
     }
 #endif
     return aStatus;
   }
 
   PurgeLastSound();
@@ -204,17 +220,18 @@ NS_IMETHODIMP nsSound::OnStreamComplete(
 
 NS_IMETHODIMP nsSound::Play(nsIURL *aURL)
 {
   nsresult rv;
 
 #ifdef DEBUG_SOUND
   char *url;
   aURL->GetSpec(&url);
-  printf("%s\n", url);
+  PR_LOG(gWin32SoundLog, PR_LOG_ALWAYS,
+         ("%s\n", url));
 #endif
 
   nsCOMPtr<nsIStreamLoader> loader;
   rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this);
 
   return rv;
 }
 
--- a/widget/src/windows/nsWinGesture.cpp
+++ b/widget/src/windows/nsWinGesture.cpp
@@ -48,16 +48,20 @@
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
+#ifdef PR_LOGGING
+extern PRLogModuleInfo* gWindowsLog;
+#endif
+
 const PRUnichar nsWinGesture::kGestureLibraryName[] =  L"user32.dll";
 HMODULE nsWinGesture::sLibraryHandle = nsnull;
 nsWinGesture::GetGestureInfoPtr nsWinGesture::getGestureInfo = nsnull;
 nsWinGesture::CloseGestureInfoHandlePtr nsWinGesture::closeGestureInfoHandle = nsnull;
 nsWinGesture::GetGestureExtraArgsPtr nsWinGesture::getGestureExtraArgs = nsnull;
 nsWinGesture::SetGestureConfigPtr nsWinGesture::setGestureConfig = nsnull;
 nsWinGesture::GetGestureConfigPtr nsWinGesture::getGestureConfig = nsnull;
 nsWinGesture::BeginPanningFeedbackPtr nsWinGesture::beginPanningFeedback = nsnull;
@@ -469,18 +473,19 @@ nsWinGesture::ProcessPanMessage(HWND hWn
         mPanActive = PR_TRUE;
         mPanInertiaActive = PR_FALSE;
       }
       else {
 
 #ifdef DBG_jimm
         PRInt32 deltaX = mPanIntermediate.x - coord.x;
         PRInt32 deltaY = mPanIntermediate.y - coord.y;
-        printf("coordX=%d coordY=%d deltaX=%d deltaY=%d x:%d y:%d\n", coord.x,
-          coord.y, deltaX, deltaY, mXAxisFeedback, mYAxisFeedback);
+        PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+               ("coordX=%d coordY=%d deltaX=%d deltaY=%d x:%d y:%d\n", coord.x,
+                coord.y, deltaX, deltaY, mXAxisFeedback, mYAxisFeedback));
 #endif
 
         mPixelScrollDelta.x = mPanIntermediate.x - coord.x;
         mPixelScrollDelta.y = mPanIntermediate.y - coord.y;
         mPanIntermediate = coord;
 
         if (gi.dwFlags & GF_INERTIA)
           mPanInertiaActive = PR_TRUE;
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -353,18 +353,19 @@ static const PRInt32 kGlassMarginAdjustm
  *
  * SECTION: nsWindow construction and destruction
  *
  **************************************************************/
 
 nsWindow::nsWindow() : nsBaseWidget()
 {
 #ifdef PR_LOGGING
-  if (!gWindowsLog)
-    gWindowsLog = PR_NewLogModule("nsWindowsWidgets");
+  if (!gWindowsLog) {
+    gWindowsLog = PR_NewLogModule("nsWindow");
+  }
 #endif
 
   mWnd                  = nsnull;
   mPaintDC              = nsnull;
   mPrevWndProc          = nsnull;
   mNativeDragTarget     = nsnull;
   mInDtor               = PR_FALSE;
   mIsVisible            = PR_FALSE;
@@ -1382,18 +1383,20 @@ NS_METHOD nsWindow::Move(PRInt32 aX, PRI
       // Make sure this window is actually on the screen before we move it
       // XXX: Needs multiple monitor support
       HDC dc = ::GetDC(mWnd);
       if (dc) {
         if (::GetDeviceCaps(dc, TECHNOLOGY) == DT_RASDISPLAY) {
           RECT workArea;
           ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
           // no annoying assertions. just mention the issue.
-          if (aX < 0 || aX >= workArea.right || aY < 0 || aY >= workArea.bottom)
-            printf("window moved to offscreen position\n");
+          if (aX < 0 || aX >= workArea.right || aY < 0 || aY >= workArea.bottom) {
+            PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+                   ("window moved to offscreen position\n"));
+          }
         }
       ::ReleaseDC(mWnd, dc);
       }
     }
 #endif
     ClearThemeRegion();
 
     UINT flags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE;
@@ -1783,20 +1786,23 @@ NS_METHOD nsWindow::IsEnabled(PRBool *aS
  * Give the focus to this widget.
  *
  **************************************************************/
 
 NS_METHOD nsWindow::SetFocus(PRBool aRaise)
 {
   if (mWnd) {
 #ifdef WINSTATE_DEBUG_OUTPUT
-    if (mWnd == GetTopLevelHWND(mWnd))
-      printf("*** SetFocus: [  top] raise=%d\n", aRaise);
-    else
-      printf("*** SetFocus: [child] raise=%d\n", aRaise);
+    if (mWnd == GetTopLevelHWND(mWnd)) {
+      PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+             ("*** SetFocus: [  top] raise=%d\n", aRaise));
+    } else {
+      PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+             ("*** SetFocus: [child] raise=%d\n", aRaise));
+    }
 #endif
     // Uniconify, if necessary
     HWND toplevelWnd = GetTopLevelHWND(mWnd);
     if (aRaise && ::IsIconic(toplevelWnd)) {
       ::ShowWindow(toplevelWnd, SW_RESTORE);
     }
     ::SetFocus(mWnd);
   }
@@ -2877,28 +2883,32 @@ NS_METHOD nsWindow::SetIcon(const nsAStr
   if (bigIcon) {
     HICON icon = (HICON) ::SendMessageW(mWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)bigIcon);
     if (icon)
       ::DestroyIcon(icon);
   }
 #ifdef DEBUG_SetIcon
   else {
     NS_LossyConvertUTF16toASCII cPath(iconPath);
-    printf( "\nIcon load error; icon=%s, rc=0x%08X\n\n", cPath.get(), ::GetLastError() );
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+           ("\nIcon load error; icon=%s, rc=0x%08X\n\n", 
+            cPath.get(), ::GetLastError()));
   }
 #endif
   if (smallIcon) {
     HICON icon = (HICON) ::SendMessageW(mWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)smallIcon);
     if (icon)
       ::DestroyIcon(icon);
   }
 #ifdef DEBUG_SetIcon
   else {
     NS_LossyConvertUTF16toASCII cPath(iconPath);
-    printf( "\nSmall icon load error; icon=%s, rc=0x%08X\n\n", cPath.get(), ::GetLastError() );
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+           ("\nSmall icon load error; icon=%s, rc=0x%08X\n\n", 
+            cPath.get(), ::GetLastError()));
   }
 #endif
   return NS_OK;
 }
 
 /**************************************************************
  *
  * SECTION: nsIWidget::WidgetToScreenOffset
@@ -3589,31 +3599,37 @@ PRBool nsWindow::DispatchKeyEvent(PRUint
   event.flags |= aFlags;
   event.charCode = aCharCode;
   if (aAlternativeCharCodes)
     event.alternativeCharCodes.AppendElements(*aAlternativeCharCodes);
   event.keyCode  = aVirtualCharCode;
 
 #ifdef KE_DEBUG
   static cnt=0;
-  printf("%d DispatchKE Type: %s charCode %d  keyCode %d ", cnt++,
-        (NS_KEY_PRESS == aEventType) ? "PRESS" : (aEventType == NS_KEY_UP ? "Up" : "Down"),
-         event.charCode, event.keyCode);
-  printf("Shift: %s Control %s Alt: %s \n", 
-         (mIsShiftDown ? "D" : "U"), (mIsControlDown ? "D" : "U"), (mIsAltDown ? "D" : "U"));
-  printf("[%c][%c][%c] <==   [%c][%c][%c][ space bar ][%c][%c][%c]\n",
-         IS_VK_DOWN(NS_VK_SHIFT) ? 'S' : ' ',
-         IS_VK_DOWN(NS_VK_CONTROL) ? 'C' : ' ',
-         IS_VK_DOWN(NS_VK_ALT) ? 'A' : ' ',
-         IS_VK_DOWN(VK_LSHIFT) ? 'S' : ' ',
-         IS_VK_DOWN(VK_LCONTROL) ? 'C' : ' ',
-         IS_VK_DOWN(VK_LMENU) ? 'A' : ' ',
-         IS_VK_DOWN(VK_RMENU) ? 'A' : ' ',
-         IS_VK_DOWN(VK_RCONTROL) ? 'C' : ' ',
-         IS_VK_DOWN(VK_RSHIFT) ? 'S' : ' ');
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+         ("%d DispatchKE Type: %s charCode %d  keyCode %d ", cnt++, 
+          NS_KEY_PRESS == aEventType ? "PRESS : 
+                                       (aEventType == NS_KEY_UP ? "Up" : "Down"),
+          event.charCode, event.keyCode));
+
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+         ("Shift: %s Control %s Alt: %s \n", (mIsShiftDown ? "D" : "U"), 
+         (mIsControlDown ? "D" : "U"), (mIsAltDown ? "D" : "U")));
+
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+         ("[%c][%c][%c] <==   [%c][%c][%c][ space bar ][%c][%c][%c]\n",
+          IS_VK_DOWN(NS_VK_SHIFT) ? 'S' : ' ',
+          IS_VK_DOWN(NS_VK_CONTROL) ? 'C' : ' ',
+          IS_VK_DOWN(NS_VK_ALT) ? 'A' : ' ',
+          IS_VK_DOWN(VK_LSHIFT) ? 'S' : ' ',
+          IS_VK_DOWN(VK_LCONTROL) ? 'C' : ' ',
+          IS_VK_DOWN(VK_LMENU) ? 'A' : ' ',
+          IS_VK_DOWN(VK_RMENU) ? 'A' : ' ',
+          IS_VK_DOWN(VK_RCONTROL) ? 'C' : ' ',
+          IS_VK_DOWN(VK_RSHIFT) ? 'S' : ' '));
 #endif
 
   event.isShift   = aModKeyState.mIsShiftDown;
   event.isControl = aModKeyState.mIsControlDown;
   event.isMeta    = PR_FALSE;
   event.isAlt     = aModKeyState.mIsAltDown;
 
   NPEvent pluginEvent;
@@ -3881,17 +3897,18 @@ PRBool nsWindow::DispatchMouseEvent(PRUi
   }
   else if (aEventType == NS_MOUSE_MOZHITTEST)
   {
     event.flags |= NS_EVENT_FLAG_ONLY_CHROME_DISPATCH;
   }
   event.clickCount = sLastClickCount;
 
 #ifdef NS_DEBUG_XX
-  printf("Msg Time: %d Click Count: %d\n", curMsgTime, event.clickCount);
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+         ("Msg Time: %d Click Count: %d\n", curMsgTime, event.clickCount));
 #endif
 
   NPEvent pluginEvent;
 
   switch (aEventType)
   {
     case NS_MOUSE_BUTTON_DOWN:
       switch (aButton) {
@@ -5686,32 +5703,32 @@ void nsWindow::RemoveNextCharMessage(HWN
 }
 
 LRESULT nsWindow::ProcessCharMessage(const MSG &aMsg, PRBool *aEventDispatched)
 {
   NS_PRECONDITION(aMsg.message == WM_CHAR || aMsg.message == WM_SYSCHAR,
                   "message is not keydown event");
   PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
          ("%s charCode=%d scanCode=%d\n",
-         aMsg.message == WM_SYSCHAR ? "WM_SYSCHAR" : "WM_CHAR",
-         aMsg.wParam, HIWORD(aMsg.lParam) & 0xFF));
+          aMsg.message == WM_SYSCHAR ? "WM_SYSCHAR" : "WM_CHAR",
+          aMsg.wParam, HIWORD(aMsg.lParam) & 0xFF));
 
   // These must be checked here too as a lone WM_CHAR could be received
   // if a child window didn't handle it (for example Alt+Space in a content window)
   nsModifierKeyState modKeyState;
   return OnChar(aMsg, modKeyState, aEventDispatched);
 }
 
 LRESULT nsWindow::ProcessKeyUpMessage(const MSG &aMsg, PRBool *aEventDispatched)
 {
   NS_PRECONDITION(aMsg.message == WM_KEYUP || aMsg.message == WM_SYSKEYUP,
                   "message is not keydown event");
   PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
          ("%s VK=%d\n", aMsg.message == WM_SYSKEYDOWN ?
-                          "WM_SYSKEYUP" : "WM_KEYUP", aMsg.wParam));
+                        "WM_SYSKEYUP" : "WM_KEYUP", aMsg.wParam));
 
   nsModifierKeyState modKeyState;
 
   // Note: the original code passed (HIWORD(lParam)) to OnKeyUp as
   // scan code. However, this breaks Alt+Num pad input.
   // MSDN states the following:
   //  Typically, ToAscii performs the translation based on the
   //  virtual-key code. In some cases, however, bit 15 of the
@@ -5737,17 +5754,17 @@ LRESULT nsWindow::ProcessKeyUpMessage(co
   return 0;
 }
 
 LRESULT nsWindow::ProcessKeyDownMessage(const MSG &aMsg,
                                         PRBool *aEventDispatched)
 {
   PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
          ("%s VK=%d\n", aMsg.message == WM_SYSKEYDOWN ?
-                          "WM_SYSKEYDOWN" : "WM_KEYDOWN", aMsg.wParam));
+                        "WM_SYSKEYDOWN" : "WM_KEYDOWN", aMsg.wParam));
   NS_PRECONDITION(aMsg.message == WM_KEYDOWN || aMsg.message == WM_SYSKEYDOWN,
                   "message is not keydown event");
 
   // If this method doesn't call OnKeyDown(), this method must clean up the
   // redirected message information itself.  For more information, see above
   // comment of AutoForgetRedirectedKeyDownMessage struct definition in
   // nsWindow.h.
   AutoForgetRedirectedKeyDownMessage forgetRedirectedMessage(this, aMsg);
@@ -5896,46 +5913,53 @@ nsWindow::SynthesizeNativeMouseEvent(nsI
  * For message handlers that need to be broken out or
  * implemented in specific platform code.
  *
  **************************************************************/
 
 BOOL nsWindow::OnInputLangChange(HKL aHKL)
 {
 #ifdef KE_DEBUG
-  printf("OnInputLanguageChange\n");
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("OnInputLanguageChange\n"));
 #endif
   gKbdLayout.LoadLayout(aHKL);
   return PR_FALSE;   // always pass to child window
 }
 
 void nsWindow::OnWindowPosChanged(WINDOWPOS *wp, PRBool& result)
 {
   if (wp == nsnull)
     return;
 
 #ifdef WINSTATE_DEBUG_OUTPUT
-  if (mWnd == GetTopLevelHWND(mWnd))
-    printf("*** OnWindowPosChanged: [  top] ");
-  else
-    printf("*** OnWindowPosChanged: [child] ");
-  printf("WINDOWPOS flags:");
-  if (wp->flags & SWP_FRAMECHANGED)
-    printf("SWP_FRAMECHANGED ");
-  if (wp->flags & SWP_SHOWWINDOW)
-    printf("SWP_SHOWWINDOW ");
-  if (wp->flags & SWP_NOSIZE)
-    printf("SWP_NOSIZE ");
-  if (wp->flags & SWP_HIDEWINDOW)
-    printf("SWP_HIDEWINDOW ");
-  if (wp->flags & SWP_NOZORDER)
-    printf("SWP_NOZORDER ");
-  if (wp->flags & SWP_NOACTIVATE)
-    printf("SWP_NOACTIVATE ");
-  printf("\n");
+  if (mWnd == GetTopLevelHWND(mWnd)) {
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("*** OnWindowPosChanged: [  top] "));
+  } else {
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("*** OnWindowPosChanged: [child] "));
+  }
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("WINDOWPOS flags:"));
+  if (wp->flags & SWP_FRAMECHANGED) {
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("SWP_FRAMECHANGED "));
+  }
+  if (wp->flags & SWP_SHOWWINDOW) {
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("SWP_SHOWWINDOW "));
+  }
+  if (wp->flags & SWP_NOSIZE) {
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("SWP_NOSIZE "));
+  }
+  if (wp->flags & SWP_HIDEWINDOW) {
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("SWP_HIDEWINDOW "));
+  }
+  if (wp->flags & SWP_NOZORDER) {
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("SWP_NOZORDER "));
+  }
+  if (wp->flags & SWP_NOACTIVATE) {
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("SWP_NOACTIVATE "));
+  }
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("\n"));
 #endif
 
   // Handle window size mode changes
   if (wp->flags & SWP_FRAMECHANGED && mSizeMode != nsSizeMode_Fullscreen) {
 
     // Bug 566135 - Windows theme code calls show window on SW_SHOWMINIMIZED
     // windows when fullscreen games disable desktop composition. If we're
     // minimized and not being activated, ignore the event and let windows
@@ -5973,26 +5997,29 @@ void nsWindow::OnWindowPosChanged(WINDOW
     // After the window is minimized, we need to do some touch up work on the
     // active window. (bugs 76831 & 499816)
     if (!sTrimOnMinimize && nsSizeMode_Minimized == event.mSizeMode)
       ActivateOtherWindowHelper(mWnd);
 
 #ifdef WINSTATE_DEBUG_OUTPUT
     switch (mSizeMode) {
       case nsSizeMode_Normal:
-          printf("*** mSizeMode: nsSizeMode_Normal\n");
+          PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+                 ("*** mSizeMode: nsSizeMode_Normal\n"));
         break;
       case nsSizeMode_Minimized:
-          printf("*** mSizeMode: nsSizeMode_Minimized\n");
+        PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+               ("*** mSizeMode: nsSizeMode_Minimized\n"));
         break;
       case nsSizeMode_Maximized:
-          printf("*** mSizeMode: nsSizeMode_Maximized\n");
+          PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+                 ("*** mSizeMode: nsSizeMode_Maximized\n");
         break;
       default:
-          printf("*** mSizeMode: ??????\n");
+          PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("*** mSizeMode: ??????\n");
         break;
     };
 #endif
 
     InitEvent(event);
 
     result = DispatchWindowEvent(&event);
 
@@ -6053,17 +6080,19 @@ void nsWindow::OnWindowPosChanged(WINDOW
     }
 
     mBounds.width    = newWidth;
     mBounds.height   = newHeight;
     mLastSize.width  = newWidth;
     mLastSize.height = newHeight;
 
 #ifdef WINSTATE_DEBUG_OUTPUT
-    printf("*** Resize window: %d x %d x %d x %d\n", wp->x, wp->y, newWidth, newHeight);
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+           ("*** Resize window: %d x %d x %d x %d\n", wp->x, wp->y, 
+            newWidth, newHeight));
 #endif
     
     // If a maximized window is resized, recalculate the non-client margins and
     // ensure a 1 pixel margin at screen bottom to allow taskbar unhiding to
     // work properly.
     if (mSizeMode == nsSizeMode_Maximized) {
       if (UpdateNonClientMargins(nsSizeMode_Maximized, PR_TRUE)) {
         // gecko resize event already sent by UpdateNonClientMargins.
@@ -6664,17 +6693,17 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
   }
 
   // Use only DOMKeyCode for XP processing.
   // Use virtualKeyCode for gKbdLayout and native processing.
   UINT DOMKeyCode = nsIMM32Handler::IsComposingOn(this) ?
                       virtualKeyCode : MapFromNativeToDOM(virtualKeyCode);
 
 #ifdef DEBUG
-  //printf("In OnKeyDown virt: %d\n", DOMKeyCode);
+  //PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("In OnKeyDown virt: %d\n", DOMKeyCode));
 #endif
 
   static PRBool sRedirectedKeyDownEventPreventedDefault = PR_FALSE;
   PRBool noDefault;
   if (aFakeCharMessage || !IsRedirectedKeyDownMessage(aMsg)) {
     nsIMEContext IMEContext(mWnd);
     noDefault =
       DispatchKeyEvent(NS_KEY_DOWN, 0, nsnull, DOMKeyCode, &aMsg, aModKeyState);
@@ -6769,17 +6798,18 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
     if (aFakeCharMessage) {
       RemoveMessageAndDispatchPluginEvent(WM_KEYFIRST, WM_KEYLAST,
                                           aFakeCharMessage);
       anyCharMessagesRemoved = PR_TRUE;
     } else {
       while (gotMsg && (msg.message == WM_CHAR || msg.message == WM_SYSCHAR))
       {
         PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
-               ("%s charCode=%d scanCode=%d\n", msg.message == WM_SYSCHAR ? "WM_SYSCHAR" : "WM_CHAR",
+               ("%s charCode=%d scanCode=%d\n", msg.message == WM_SYSCHAR ? 
+                                                "WM_SYSCHAR" : "WM_CHAR",
                 msg.wParam, HIWORD(msg.lParam) & 0xFF));
         RemoveMessageAndDispatchPluginEvent(WM_KEYFIRST, WM_KEYLAST);
         anyCharMessagesRemoved = PR_TRUE;
 
         gotMsg = ::PeekMessageW (&msg, mWnd, WM_KEYFIRST, WM_KEYLAST, PM_NOREMOVE | PM_NOYIELD);
       }
     }
 
@@ -7402,19 +7432,20 @@ PRBool nsWindow::OnResize(nsIntRect &aWi
       event.mWinWidth  = PRInt32(r.right - r.left);
       event.mWinHeight = PRInt32(r.bottom - r.top);
     } else {
       event.mWinWidth  = 0;
       event.mWinHeight = 0;
     }
 
 #if 0
-    printf("[%X] OnResize: client:(%d x %d x %d x %d) window:(%d x %d)\n", this,
-      aWindowRect.x, aWindowRect.y, aWindowRect.width, aWindowRect.height,
-      event.mWinWidth, event.mWinHeight);
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
+           ("[%X] OnResize: client:(%d x %d x %d x %d) window:(%d x %d)\n", this,
+            aWindowRect.x, aWindowRect.y, aWindowRect.width, aWindowRect.height,
+            event.mWinWidth, event.mWinHeight));
 #endif
 
     return DispatchWindowEvent(&event);
   }
 
   return PR_FALSE;
 }
 
@@ -7913,31 +7944,32 @@ nsWindow::HasBogusPopupsDropShadowOnMult
  ** Handles managing IME input and accessibility.
  **
  **************************************************************
  **************************************************************/
 
 NS_IMETHODIMP nsWindow::ResetInputState()
 {
 #ifdef DEBUG_KBSTATE
-  printf("ResetInputState\n");
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("ResetInputState\n"));
 #endif
 
 #ifdef NS_ENABLE_TSF
   nsTextStore::CommitComposition(PR_FALSE);
 #endif //NS_ENABLE_TSF
 
   nsIMM32Handler::CommitComposition(this);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsWindow::SetIMEOpenState(PRBool aState)
 {
 #ifdef DEBUG_KBSTATE
-  printf("SetIMEOpenState %s\n", (aState ? "Open" : "Close"));
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+         ("SetIMEOpenState %s\n", (aState ? "Open" : "Close")));
 #endif 
 
 #ifdef NS_ENABLE_TSF
   nsTextStore::SetIMEOpenState(aState);
 #endif //NS_ENABLE_TSF
 
   nsIMEContext IMEContext(mWnd);
   if (IMEContext.IsValid()) {
@@ -7964,59 +7996,61 @@ NS_IMETHODIMP nsWindow::GetIMEOpenState(
 
 NS_IMETHODIMP nsWindow::SetInputMode(const IMEContext& aContext)
 {
   PRUint32 status = aContext.mStatus;
 #ifdef NS_ENABLE_TSF
   nsTextStore::SetInputMode(aContext);
 #endif //NS_ENABLE_TSF
 #ifdef DEBUG_KBSTATE
-  printf("SetInputMode: %s\n", (status == nsIWidget::IME_STATUS_ENABLED ||
-                                status == nsIWidget::IME_STATUS_PLUGIN) ? 
-                               "Enabled" : "Disabled");
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+         ("SetInputMode: %s\n", (status == nsIWidget::IME_STATUS_ENABLED ||
+                                 status == nsIWidget::IME_STATUS_PLUGIN) ? 
+                                 "Enabled" : "Disabled"));
 #endif 
   if (nsIMM32Handler::IsComposing()) {
     ResetInputState();
   }
   mIMEContext = aContext;
   PRBool enable = (status == nsIWidget::IME_STATUS_ENABLED ||
                    status == nsIWidget::IME_STATUS_PLUGIN);
 
   AssociateDefaultIMC(enable);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsWindow::GetInputMode(IMEContext& aContext)
 {
 #ifdef DEBUG_KBSTATE
-  printf("GetInputMode: %s\n", mIMEContext.mStatus ? "Enabled" : "Disabled");
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+         ("GetInputMode: %s\n", mIMEContext.mStatus ? "Enabled" : "Disabled");
 #endif 
   aContext = mIMEContext;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsWindow::CancelIMEComposition()
 {
 #ifdef DEBUG_KBSTATE
-  printf("CancelIMEComposition\n");
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("CancelIMEComposition\n"));
 #endif 
 
 #ifdef NS_ENABLE_TSF
   nsTextStore::CommitComposition(PR_TRUE);
 #endif //NS_ENABLE_TSF
 
   nsIMM32Handler::CancelComposition(this);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindow::GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState)
 {
 #ifdef DEBUG_KBSTATE
-  printf("GetToggledKeyState\n");
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("GetToggledKeyState\n"));
 #endif 
   NS_ENSURE_ARG_POINTER(aLEDState);
   *aLEDState = (::GetKeyState(aKeyCode) & 1) != 0;
   return NS_OK;
 }
 
 #ifdef NS_ENABLE_TSF
 NS_IMETHODIMP
@@ -8080,43 +8114,47 @@ PRBool nsWindow::AssociateDefaultIMC(PRB
 }
 
 #ifdef ACCESSIBILITY
 
 #ifdef DEBUG_WMGETOBJECT
 #define NS_LOG_WMGETOBJECT_WNDACC(aWnd)                                        \
   nsAccessible* acc = aWnd ?                                                   \
     aWnd->DispatchAccessibleEvent(NS_GETACCESSIBLE) : nsnull;                  \
-  printf("     acc: %p", acc);                                                 \
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("     acc: %p", acc));                   \
   if (acc) {                                                                   \
     nsAutoString name;                                                         \
     acc->GetName(name);                                                        \
-    printf(", accname: %s", NS_ConvertUTF16toUTF8(name).get());                \
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS,                                         \
+           (", accname: %s", NS_ConvertUTF16toUTF8(name).get()));              \
     nsCOMPtr<nsIAccessibleDocument> doc = do_QueryObject(acc);                 \
     void *hwnd = nsnull;                                                       \
     doc->GetWindowHandle(&hwnd);                                               \
-    printf(", acc hwnd: %d", hwnd);                                            \
+    PR_LOG(gWindowsLog, PR_LOG_ALWAYS, (", acc hwnd: %d", hwnd));              \
   }
 
 #define NS_LOG_WMGETOBJECT_THISWND                                             \
 {                                                                              \
-  printf("\n*******Get Doc Accessible*******\nOrig Window: ");                 \
-  printf("\n  {\n     HWND: %d, parent HWND: %d, wndobj: %p,\n",               \
-         mWnd, ::GetParent(mWnd), this);                                       \
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS,                                           \
+         ("\n*******Get Doc Accessible*******\nOrig Window: "));               \
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS,                                           \
+         ("\n  {\n     HWND: %d, parent HWND: %d, wndobj: %p,\n",              \
+          mWnd, ::GetParent(mWnd), this));                                     \
   NS_LOG_WMGETOBJECT_WNDACC(this)                                              \
-  printf("\n  }\n");                                                           \
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("\n  }\n"));                             \
 }
 
 #define NS_LOG_WMGETOBJECT_WND(aMsg, aHwnd)                                    \
 {                                                                              \
   nsWindow* wnd = GetNSWindowPtr(aHwnd);                                       \
-  printf("Get " aMsg ":\n  {\n     HWND: %d, parent HWND: %d, wndobj: %p,\n",  \
-         aHwnd, ::GetParent(aHwnd), wnd);                                      \
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS,                                           \
+         ("Get " aMsg ":\n  {\n     HWND: %d, parent HWND: %d, wndobj: %p,\n", \
+          aHwnd, ::GetParent(aHwnd), wnd));                                    \
   NS_LOG_WMGETOBJECT_WNDACC(wnd);                                              \
-  printf("\n }\n");                                                            \
+  PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("\n }\n"));                              \
 }
 #else
 #define NS_LOG_WMGETOBJECT_THISWND
 #define NS_LOG_WMGETOBJECT_WND(aMsg, aHwnd)
 #endif // DEBUG_WMGETOBJECT
 
 nsAccessible*
 nsWindow::GetRootAccessible()
@@ -8357,21 +8395,25 @@ LRESULT CALLBACK nsWindow::MozSpecialMsg
 
     int inx = 0;
     while (gMSGFEvents[inx].mId != code && gMSGFEvents[inx].mStr != NULL) {
       inx++;
     }
     if (code != gLastMsgCode) {
       if (gMSGFEvents[inx].mId == code) {
 #ifdef DEBUG
-        printf("MozSpecialMessageProc - code: 0x%X  - %s  hw: %p\n", code, gMSGFEvents[inx].mStr, pMsg->hwnd);
+        PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+               ("MozSpecialMessageProc - code: 0x%X  - %s  hw: %p\n", 
+                code, gMSGFEvents[inx].mStr, pMsg->hwnd));
 #endif
       } else {
 #ifdef DEBUG
-        printf("MozSpecialMessageProc - code: 0x%X  - %d  hw: %p\n", code, gMSGFEvents[inx].mId, pMsg->hwnd);
+        PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+               ("MozSpecialMessageProc - code: 0x%X  - %d  hw: %p\n", 
+                code, gMSGFEvents[inx].mId, pMsg->hwnd));
 #endif
       }
       gLastMsgCode = code;
     }
     PrintEvent(pMsg->message, FALSE, FALSE);
   }
 #endif // #ifdef POPUP_ROLLUP_DEBUG_OUTPUT
 
@@ -8446,39 +8488,42 @@ void nsWindow::RegisterSpecialDropdownHo
   //HMODULE hMod = GetModuleHandle("gkwidget.dll");
 
   // Install msg hook for moving the window and resizing
   if (!sMsgFilterHook) {
     DISPLAY_NMM_PRT("***** Hooking sMsgFilterHook!\n");
     sMsgFilterHook = SetWindowsHookEx(WH_MSGFILTER, MozSpecialMsgFilter, NULL, GetCurrentThreadId());
 #ifdef POPUP_ROLLUP_DEBUG_OUTPUT
     if (!sMsgFilterHook) {
-      printf("***** SetWindowsHookEx is NOT installed for WH_MSGFILTER!\n");
+      PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+             ("***** SetWindowsHookEx is NOT installed for WH_MSGFILTER!\n"));
     }
 #endif
   }
 
   // Install msg hook for menus
   if (!sCallProcHook) {
     DISPLAY_NMM_PRT("***** Hooking sCallProcHook!\n");
     sCallProcHook  = SetWindowsHookEx(WH_CALLWNDPROC, MozSpecialWndProc, NULL, GetCurrentThreadId());
 #ifdef POPUP_ROLLUP_DEBUG_OUTPUT
     if (!sCallProcHook) {
-      printf("***** SetWindowsHookEx is NOT installed for WH_CALLWNDPROC!\n");
+      PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+             ("***** SetWindowsHookEx is NOT installed for WH_CALLWNDPROC!\n"));
     }
 #endif
   }
 
   // Install msg hook for the mouse
   if (!sCallMouseHook) {
     DISPLAY_NMM_PRT("***** Hooking sCallMouseHook!\n");
     sCallMouseHook  = SetWindowsHookEx(WH_MOUSE, MozSpecialMouseProc, NULL, GetCurrentThreadId());
 #ifdef POPUP_ROLLUP_DEBUG_OUTPUT
     if (!sCallMouseHook) {
-      printf("***** SetWindowsHookEx is NOT installed for WH_MOUSE!\n");
+      PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+             ("***** SetWindowsHookEx is NOT installed for WH_MOUSE!\n"));
     }
 #endif
   }
 }
 
 // Unhook special message hooks for dropdowns.
 void nsWindow::UnregisterSpecialDropdownHooks()
 {
--- a/widget/src/windows/nsWindowDbg.cpp
+++ b/widget/src/windows/nsWindowDbg.cpp
@@ -37,17 +37,21 @@
  * ***** END LICENSE BLOCK ***** */
 
 /*
  * nsWindowDbg - Debug related utilities for nsWindow.
  */
 
 #include "nsWindowDbg.h"
 
-#if defined(POPUP_ROLLUP_DEBUG_OUTPUT) || defined(EVENT_DEBUG_OUTPUT)
+#ifdef PR_LOGGING
+extern PRLogModuleInfo* gWindowsLog;
+#endif
+
+#if defined(POPUP_ROLLUP_DEBUG_OUTPUT) || defined(EVENT_DEBUG_OUTPUT) || 1
 
 typedef struct {
   char * mStr;
   long   mId;
 } EventMsgInfo;
 
 #if defined(POPUP_ROLLUP_DEBUG_OUTPUT)
 MSGFEventMsgInfo gMSGFEvents[] = {
@@ -404,34 +408,37 @@ static long gLastEventMsg = 0;
 void PrintEvent(UINT msg, PRBool aShowAllEvents, PRBool aShowMouseMoves)
 {
   int inx = 0;
   while (gAllEvents[inx].mId != (long)msg && gAllEvents[inx].mStr != NULL) {
     inx++;
   }
   if (aShowAllEvents || (!aShowAllEvents && gLastEventMsg != (long)msg)) {
     if (aShowMouseMoves || (!aShowMouseMoves && msg != 0x0020 && msg != 0x0200 && msg != 0x0084)) {
-      printf("%6d - 0x%04X %s\n", gEventCounter++, msg, gAllEvents[inx].mStr ? gAllEvents[inx].mStr : "Unknown");
+      PR_LOG(gWindowsLog, PR_LOG_ALWAYS, 
+             ("%6d - 0x%04X %s\n", gEventCounter++, msg, 
+              gAllEvents[inx].mStr ? gAllEvents[inx].mStr : "Unknown"));
       gLastEventMsg = msg;
     }
   }
 }
 
 #endif // defined(POPUP_ROLLUP_DEBUG_OUTPUT) || defined(EVENT_DEBUG_OUTPUT)
 
 #ifdef DEBUG
 void DDError(const char *msg, HRESULT hr)
 {
   /*XXX make nicer */
-  fprintf(stderr, "direct draw error %s: 0x%08lx\n", msg, hr);
+  PR_LOG(gWindowsLog, PR_LOG_ERROR,
+         ("direct draw error %s: 0x%08lx\n", msg, hr));
 }
 #endif
 
 #ifdef DEBUG_VK
 PRBool is_vk_down(int vk)
 {
    SHORT st = GetKeyState(vk);
 #ifdef DEBUG
-   printf("is_vk_down vk=%x st=%x\n",vk, st);
+   PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ("is_vk_down vk=%x st=%x\n",vk, st));
 #endif
    return (st < 0);
 }
 #endif
--- a/widget/src/windows/nsWindowDbg.h
+++ b/widget/src/windows/nsWindowDbg.h
@@ -62,27 +62,27 @@
 //#define DEBUG_VK
 
 // Main event loop debug output flags
 #if defined(EVENT_DEBUG_OUTPUT)
 #define SHOW_REPEAT_EVENTS      PR_TRUE
 #define SHOW_MOUSEMOVE_EVENTS   PR_FALSE
 #endif // defined(EVENT_DEBUG_OUTPUT)
 
-#if defined(POPUP_ROLLUP_DEBUG_OUTPUT) || defined(EVENT_DEBUG_OUTPUT)
+#if defined(POPUP_ROLLUP_DEBUG_OUTPUT) || defined(EVENT_DEBUG_OUTPUT) || 1
 void PrintEvent(UINT msg, PRBool aShowAllEvents, PRBool aShowMouseMoves);
 #endif // defined(POPUP_ROLLUP_DEBUG_OUTPUT) || defined(EVENT_DEBUG_OUTPUT)
 
 #if defined(POPUP_ROLLUP_DEBUG_OUTPUT)
 typedef struct {
   char * mStr;
   int    mId;
 } MSGFEventMsgInfo;
 
-#define DISPLAY_NMM_PRT(_arg) printf((_arg));
+#define DISPLAY_NMM_PRT(_arg) PR_LOG(gWindowsLog, PR_LOG_ALWAYS, ((_arg)));
 #else
 #define DISPLAY_NMM_PRT(_arg)
 #endif // defined(POPUP_ROLLUP_DEBUG_OUTPUT)
 
 #if defined(DEBUG)
 void DDError(const char *msg, HRESULT hr);
 #endif // defined(DEBUG)
 
--- a/widget/src/windows/nsdefs.h
+++ b/widget/src/windows/nsdefs.h
@@ -47,11 +47,31 @@
 #endif  
 
 #ifdef _DEBUG
   #define VERIFY(exp)                 if (!(exp)) { GetLastError(); BREAK_TO_DEBUGGER; }
 #else   // !_DEBUG
   #define VERIFY(exp)                 (exp)
 #endif  // !_DEBUG
 
+// NSPR Win32 modules:
+// nsWindow, nsSound, and nsClipboard
+//
+// Logging can be changed at runtime without recompiling in the General
+// property page of Visual Studio under the "Environment" property.
+//
+// Two variables are of importance to be set: 
+// NSPR_LOG_MODULES and NSPR_LOG_FILE
+//
+// NSPR_LOG_MODULES:
+// NSPR_LOG_MODULES=all:5         (To log everything completely)
+// NSPR_LOG_MODULES=nsWindow:5,nsSound:5,nsClipboard:5 
+//                                (To log windows widget stuff)
+// NSPR_LOG_MODULES=              (To turn off logging)
+//
+// NSPR_LOG_FILE:
+// NSPR_LOG_FILE=C:\nsprlog.txt   (To a file on disk)
+// NSPR_LOG_FILE=WinDebug         (To the debug window)
+// NSPR_LOG_FILE=                 (To stdout/stderr)
+
 #endif  // NSDEFS_H