Bug 1399956 - Add logging to headless widget. r=jrmuizel
authorBrendan Dahl <brendan.dahl@gmail.com>
Wed, 20 Sep 2017 17:40:18 -0700
changeset 386572 b9fb2b57d6675036b6eb65e59ca9713ab7a28f11
parent 386571 ef8fcf9b9152e357c83db9f0de44a6577b40ccb6
child 386573 d41de10195a075ee501738cb09246438b0bfaea9
push id32695
push userarchaeopteryx@coole-files.de
push dateTue, 17 Oct 2017 09:45:44 +0000
treeherdermozilla-central@0d9c6250f99d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1399956
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1399956 - Add logging to headless widget. r=jrmuizel Use similar logging to the various nsWindows to make debugging easier. MozReview-Commit-ID: 5AsaehQsOtA
widget/headless/HeadlessWidget.cpp
--- a/widget/headless/HeadlessWidget.cpp
+++ b/widget/headless/HeadlessWidget.cpp
@@ -9,16 +9,33 @@
 #include "BasicEvents.h"
 #include "MouseEvents.h"
 #include "mozilla/gfx/gfxVars.h"
 #include "mozilla/ClearOnShutdown.h"
 
 using namespace mozilla::gfx;
 using namespace mozilla::layers;
 
+using mozilla::LogLevel;
+
+#ifdef MOZ_LOGGING
+
+#include "mozilla/Logging.h"
+static mozilla::LazyLogModule sWidgetLog("Widget");
+static mozilla::LazyLogModule sWidgetFocusLog("WidgetFocus");
+#define LOG(args) MOZ_LOG(sWidgetLog, mozilla::LogLevel::Debug, args)
+#define LOGFOCUS(args) MOZ_LOG(sWidgetFocusLog, mozilla::LogLevel::Debug, args)
+
+#else
+
+#define LOG(args)
+#define LOGFOCUS(args)
+
+#endif /* MOZ_LOGGING */
+
 /*static*/ already_AddRefed<nsIWidget>
 nsIWidget::CreateHeadlessWidget()
 {
   nsCOMPtr<nsIWidget> widget = new mozilla::widget::HeadlessWidget();
   return widget.forget();
 }
 
 namespace mozilla {
@@ -66,25 +83,28 @@ HeadlessWidget::HeadlessWidget()
   if (!sActiveWindows) {
     sActiveWindows = new nsTArray<HeadlessWidget*>();
     ClearOnShutdown(&sActiveWindows);
   }
 }
 
 HeadlessWidget::~HeadlessWidget()
 {
+  LOG(("HeadlessWidget::~HeadlessWidget() [%p]\n", (void *)this));
+
   Destroy();
 }
 
 void
 HeadlessWidget::Destroy()
 {
   if (mDestroyed) {
     return;
   }
+  LOG(("HeadlessWidget::Destroy [%p]\n", (void *)this));
   mDestroyed = true;
 
   if (sActiveWindows) {
     int32_t index = sActiveWindows->IndexOf(this);
     if (index != -1) {
       RefPtr<HeadlessWidget> activeWindow = GetActiveWindow();
       sActiveWindows->RemoveElementAt(index);
       // If this is the currently active widget and there's a previously active
@@ -184,16 +204,18 @@ HeadlessWidget::RaiseWindow()
     mWidgetListener->WindowActivated();
 }
 
 void
 HeadlessWidget::Show(bool aState)
 {
   mVisible = aState;
 
+  LOG(("HeadlessWidget::Show [%p] state %d\n", (void *)this, aState));
+
   // Top-level window and dialogs are activated/raised when shown.
   if (aState && (mTopLevel == this || mWindowType == eWindowType_dialog)) {
     RaiseWindow();
   }
 
   ApplySizeModeSideEffects();
 }
 
@@ -201,16 +223,18 @@ bool
 HeadlessWidget::IsVisible() const
 {
   return mVisible;
 }
 
 nsresult
 HeadlessWidget::SetFocus(bool aRaise)
 {
+  LOGFOCUS(("  SetFocus %d [%p]\n", aRaise, (void *)this));
+
   // aRaise == true means we request activation of our toplevel window.
   if (aRaise) {
     HeadlessWidget* topLevel = (HeadlessWidget*) GetTopLevelWidget();
 
     // The toplevel only becomes active if it's currently visible; otherwise, it
     // will be activated anyway when it's shown.
     if (topLevel->IsVisible())
       topLevel->RaiseWindow();
@@ -228,16 +252,19 @@ bool
 HeadlessWidget::IsEnabled() const
 {
   return mEnabled;
 }
 
 void
 HeadlessWidget::Move(double aX, double aY)
 {
+  LOG(("HeadlessWidget::Move [%p] %f %f\n", (void *)this,
+       aX, aY));
+
   double scale = BoundsUseDesktopPixels() ? GetDesktopToDeviceScale().scale : 1.0;
   int32_t x = NSToIntRound(aX * scale);
   int32_t y = NSToIntRound(aY * scale);
 
   if (mWindowType == eWindowType_toplevel ||
       mWindowType == eWindowType_dialog) {
       SetSizeMode(nsSizeMode_Normal);
   }
@@ -313,16 +340,18 @@ HeadlessWidget::Resize(double aX,
     NotifyWindowMoved(aX, aY);
   }
   return Resize(aWidth, aHeight, aRepaint);
 }
 
 void
 HeadlessWidget::SetSizeMode(nsSizeMode aMode)
 {
+  LOG(("HeadlessWidget::SetSizeMode [%p] %d\n", (void *)this, aMode));
+
   if (aMode == mSizeMode) {
     return;
   }
 
   nsBaseWidget::SetSizeMode(aMode);
 
   // Normally in real widget backends a window event would be triggered that
   // would cause the window manager to handle resizing the window. In headless