Bug 1351630 - Override BaseWidget::GetWidgetScreen r=karlt draft
authorKan-Ru Chen <kanru@kanru.info>
Thu, 30 Mar 2017 09:51:44 -0400
changeset 554485 2fb450cc9d933346cebfdbff0b32ea4130550395
parent 551547 8d1ad73ba4f2796a8a69ac28217efdf3395b9e6f
child 622349 d2b39cc9b960e42b644004b2980fef057d66dd24
push id51946
push userkchen@mozilla.com
push dateFri, 31 Mar 2017 17:37:57 +0000
reviewerskarlt
bugs1351630
milestone55.0a1
Bug 1351630 - Override BaseWidget::GetWidgetScreen r=karlt GetScreenBounds() is slow for the GTK port so we override and use mBounds directly in nsWindow::GetWidgetScreen() MozReview-Commit-ID: ICElOCEzswf
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -4884,16 +4884,40 @@ nsWindow::PerformFullscreenTransition(Fu
     auto transitionData = new FullscreenTransitionData(aStage, aDuration,
                                                        aCallback, data);
     g_timeout_add_full(G_PRIORITY_HIGH,
                        FullscreenTransitionData::sInterval,
                        FullscreenTransitionData::TimeoutCallback,
                        transitionData, nullptr);
 }
 
+already_AddRefed<nsIScreen>
+nsWindow::GetWidgetScreen()
+{
+  nsCOMPtr<nsIScreenManager> screenManager;
+  screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
+  if (!screenManager) {
+    return nullptr;
+  }
+
+  // GetScreenBounds() is slow for the GTK port so we override and use
+  // mBounds directly.
+  LayoutDeviceIntRect bounds = mBounds;
+  if (!mIsTopLevel) {
+      bounds.MoveTo(WidgetToScreenOffset());
+  }
+
+  DesktopIntRect deskBounds = RoundedToInt(bounds / GetDesktopToDeviceScale());
+  nsCOMPtr<nsIScreen> screen;
+  screenManager->ScreenForRect(deskBounds.x, deskBounds.y,
+                               deskBounds.width, deskBounds.height,
+                               getter_AddRefs(screen));
+  return screen.forget();
+}
+
 static bool
 IsFullscreenSupported(GtkWidget* aShell)
 {
 #ifdef MOZ_X11
     GdkScreen* screen = gtk_widget_get_screen(aShell);
     GdkAtom atom = gdk_atom_intern("_NET_WM_STATE_FULLSCREEN", FALSE);
     if (!gdk_x11_screen_supports_net_wm_hint(screen, atom)) {
         return false;
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -151,16 +151,17 @@ public:
                                            bool aIntersectWithExisting) override;
     virtual bool       HasPendingInputEvent() override;
 
     virtual bool PrepareForFullscreenTransition(nsISupports** aData) override;
     virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
                                              uint16_t aDuration,
                                              nsISupports* aData,
                                              nsIRunnable* aCallback) override;
+    virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
     virtual nsresult   MakeFullScreen(bool aFullScreen,
                                       nsIScreen* aTargetScreen = nullptr) override;
     virtual void       HideWindowChrome(bool aShouldHide) override;
 
     /**
      * GetLastUserInputTime returns a timestamp for the most recent user input
      * event.  This is intended for pointer grab requests (including drags).
      */