Bug 613079 - fix non-libxul build and style fixes - r=dholbert, a=fix-build-nonlibxul
authorBenoit Jacob <bjacob@mozilla.com>
Mon, 06 Dec 2010 09:10:42 -0500
changeset 58728 686e646d23004d082909149f04b4aa0cd35b9200
parent 58727 2f96714fd6d2b46a79a9453bca2b45ab9288c121
child 58729 63fc6076169bace0e7c654bfac71a9d258feb37a
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersdholbert, fix-build-nonlibxul
bugs613079
milestone2.0b8pre
Bug 613079 - fix non-libxul build and style fixes - r=dholbert, a=fix-build-nonlibxul
gfx/src/Makefile.in
gfx/src/X11Util.cpp
gfx/src/X11Util.h
--- a/gfx/src/Makefile.in
+++ b/gfx/src/Makefile.in
@@ -86,28 +86,29 @@ CPPSRCS = \
         nsColor.cpp \
         nsFont.cpp \
         nsRect.cpp \
         nsRegion.cpp \
         nsTransform2D.cpp \
         nsScriptableRegion.cpp \
         $(NULL)
 
-ifdef MOZ_X11
-CPPSRCS += \
-        X11Util.cpp \
-        $(NULL)
-endif
-
 EXTRA_DSO_LDOPTS = \
         $(MOZ_UNICHARUTIL_LIBS) \
         $(MOZ_COMPONENT_LIBS) \
         $(MOZ_JS_LIBS) \
         $(NULL)
 
+ifdef MOZ_X11
+CPPSRCS += \
+        X11Util.cpp \
+        $(NULL)
+EXTRA_DSO_LDOPTS += $(XLDFLAGS) $(XLIBS)
+endif
+
 ifneq (,$(filter cocoa,$(MOZ_WIDGET_TOOLKIT)))
 EXTRA_DSO_LDOPTS += \
         $(TK_LIBS) \
         $(NULL)
 endif
 
 # This library is used by other shared libs in a static build
 FORCE_USE_PIC = 1
--- a/gfx/src/X11Util.cpp
+++ b/gfx/src/X11Util.cpp
@@ -36,11 +36,46 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "X11Util.h"
 
 namespace mozilla {
 
-ScopedXErrorHandler::ErrorEvent* ScopedXErrorHandler::s_xerrorptr;
+ScopedXErrorHandler::ErrorEvent* ScopedXErrorHandler::sXErrorPtr;
+
+int
+ScopedXErrorHandler::ErrorHandler(Display *, XErrorEvent *ev)
+{
+    sXErrorPtr->mError = *ev;
+    return 0;
+}
+
+
+ScopedXErrorHandler::ScopedXErrorHandler()
+{
+    // let sXErrorPtr point to this object's mXError object, but don't reset this mXError object!
+    // think of the case of nested ScopedXErrorHandler's.
+    mOldXErrorPtr = sXErrorPtr;
+    sXErrorPtr = &mXError;
+    mOldErrorHandler = XSetErrorHandler(ErrorHandler);
+}
+
+ScopedXErrorHandler::~ScopedXErrorHandler()
+{
+    sXErrorPtr = mOldXErrorPtr;
+    XSetErrorHandler(mOldErrorHandler);
+}
+
+bool
+ScopedXErrorHandler::SyncAndGetError(Display *dpy, XErrorEvent *ev)
+{
+    XSync(dpy, False);
+    bool retval = mXError.mError.error_code != 0;
+    if (ev)
+        *ev = mXError.mError;
+    mXError = ErrorEvent(); // reset
+    return retval;
+}
+
 
 } // namespace mozilla
--- a/gfx/src/X11Util.h
+++ b/gfx/src/X11Util.h
@@ -49,16 +49,17 @@
 //   enum CursorShape { ... }.  Good times!
 #undef CursorShape
 #  include <QX11Info>
 #  include <X11/Xlib.h>
 #else
 #  error Unknown toolkit
 #endif 
 
+#include "gfxCore.h"
 #include "nsDebug.h"
 
 namespace mozilla {
 
 /**
  * Return the default X Display created and used by the UI toolkit.
  */
 inline Display*
@@ -118,76 +119,53 @@ private:
  * Nesting is correctly handled: multiple nested ScopedXErrorHandler's don't interfere with each other's state. However,
  * if SyncAndGetError is not called on the nested ScopedXErrorHandler, then any X errors caused by X calls made while the nested
  * ScopedXErrorHandler was in place may then be caught by the other ScopedXErrorHandler. This is just a result of X being
  * asynchronous and us not doing any implicit syncing: the only method in this class what causes syncing is SyncAndGetError().
  *
  * This class is not thread-safe at all. It is assumed that only one thread is using any ScopedXErrorHandler's. Given that it's
  * not used on Mac, it should be easy to make it thread-safe by using thread-local storage with __thread.
  */
-class ScopedXErrorHandler
+class NS_GFX ScopedXErrorHandler
 {
     // trivial wrapper around XErrorEvent, just adding ctor initializing by zero.
     struct ErrorEvent
     {
-        XErrorEvent m_error;
+        XErrorEvent mError;
 
         ErrorEvent()
         {
             memset(this, 0, sizeof(ErrorEvent));
         }
     };
 
     // this ScopedXErrorHandler's ErrorEvent object
-    ErrorEvent m_xerror;
+    ErrorEvent mXError;
 
     // static pointer for use by the error handler
-    static ErrorEvent* s_xerrorptr;
+    static ErrorEvent* sXErrorPtr;
 
-    // what to restore s_xerrorptr to on destruction
-    ErrorEvent* m_oldxerrorptr;
+    // what to restore sXErrorPtr to on destruction
+    ErrorEvent* mOldXErrorPtr;
 
     // what to restore the error handler to on destruction
-    int (*m_oldErrorHandler)(Display *, XErrorEvent *);
+    int (*mOldErrorHandler)(Display *, XErrorEvent *);
 
 public:
 
     static int
-    ErrorHandler(Display *, XErrorEvent *ev)
-    {
-        s_xerrorptr->m_error = *ev;
-        return 0;
-    }
+    ErrorHandler(Display *, XErrorEvent *ev);
 
-    ScopedXErrorHandler()
-    {
-        // let s_xerrorptr point to this object's m_xerror object, but don't reset this m_xerror object!
-        // think of the case of nested ScopedXErrorHandler's.
-        m_oldxerrorptr = s_xerrorptr;
-        s_xerrorptr = &m_xerror;
-        m_oldErrorHandler = XSetErrorHandler(ErrorHandler);
-    }
+    ScopedXErrorHandler();
 
-    ~ScopedXErrorHandler()
-    {
-        s_xerrorptr = m_oldxerrorptr;
-        XSetErrorHandler(m_oldErrorHandler);
-    }
+    ~ScopedXErrorHandler();
 
     /** \returns true if a X error occurred since the last time this method was called on this ScopedXErrorHandler object.
      *
      * \param ev this optional parameter, if set, will be filled with the XErrorEvent object
      */
-    bool SyncAndGetError(Display *dpy, XErrorEvent *ev = nsnull)
-    {
-        XSync(dpy, False);
-        bool retval = m_xerror.m_error.error_code != 0;
-        if (ev)
-            *ev = m_xerror.m_error;
-        m_xerror = ErrorEvent(); // reset
-        return retval;
-    }
+    bool SyncAndGetError(Display *dpy, XErrorEvent *ev = nsnull);
 };
 
 
 } // namespace mozilla
 
 #endif  // mozilla_X11Util_h