Bug 1235941 - Detect DPI change for GTK3. r?karlt draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 16 Feb 2016 16:01:17 +0900
changeset 332076 9f86aa2e3ef26a7db81fe6f41ff9a87f22d4d8f4
parent 331960 d5daf10d3b74b04e8fa63c4e5429de8a0adf79f8
child 514537 c5977bd8932e6e71affc27743183a52ced287f53
push id11155
push userm_kato@ga2.so-net.ne.jp
push dateFri, 19 Feb 2016 08:14:49 +0000
reviewerskarlt
bugs1235941
milestone47.0a1
Bug 1235941 - Detect DPI change for GTK3. r?karlt Use scale-facotr signal to detect DPI change. Also, we should update mBounds for current scaling setting. MozReview-Commit-ID: 9fuFORzSzaD
widget/gtk/nsWindow.cpp
widget/gtk/nsWindow.h
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -214,16 +214,19 @@ static gboolean visibility_notify_event_
                                            GdkEventVisibility *event);
 static void     hierarchy_changed_cb      (GtkWidget *widget,
                                            GtkWidget *previous_toplevel);
 static gboolean window_state_event_cb     (GtkWidget *widget,
                                            GdkEventWindowState *event);
 static void     theme_changed_cb          (GtkSettings *settings,
                                            GParamSpec *pspec,
                                            nsWindow *data);
+#if (MOZ_WIDGET_GTK == 3)
+static void     scale_changed_cb          (GtkWidget *widget);
+#endif
 #if GTK_CHECK_VERSION(3,4,0)
 static gboolean touch_event_cb            (GtkWidget* aWidget,
                                            GdkEventTouch* aEvent);
 #endif
 static nsWindow* GetFirstNSWindowForGDKWindow (GdkWindow *aGdkWindow);
 
 #ifdef __cplusplus
 extern "C" {
@@ -3353,16 +3356,29 @@ nsWindow::ThemeChanged()
             win->ThemeChanged();
         }
 
         children = children->next;
     }
 }
 
 void
+nsWindow::OnDPIChanged()
+{
+  if (mWidgetListener) {
+    nsIPresShell* presShell = mWidgetListener->GetPresShell();
+    if (presShell) {
+      presShell->BackingScaleFactorChanged();
+      // Update menu's font size etc
+      presShell->ThemeChanged();
+    }
+  }
+}
+
+void
 nsWindow::DispatchDragEvent(EventMessage aMsg, const LayoutDeviceIntPoint& aRefPoint,
                             guint aTime)
 {
     WidgetDragEvent event(true, aMsg, this);
 
     if (aMsg == eDragOver) {
         InitDragEvent(event);
     }
@@ -3827,16 +3843,20 @@ nsWindow::Create(nsIWidget* aParent,
     if (mContainer) {
         // Widget signals
         g_signal_connect(mContainer, "unrealize",
                          G_CALLBACK(container_unrealize_cb), nullptr);
         g_signal_connect_after(mContainer, "size_allocate",
                                G_CALLBACK(size_allocate_cb), nullptr);
         g_signal_connect(mContainer, "hierarchy-changed",
                          G_CALLBACK(hierarchy_changed_cb), nullptr);
+#if (MOZ_WIDGET_GTK == 3)
+        g_signal_connect(mContainer, "notify::scale-factor",
+                         G_CALLBACK(scale_changed_cb), nullptr);
+#endif
         // Initialize mHasMappedToplevel.
         hierarchy_changed_cb(GTK_WIDGET(mContainer), nullptr);
         // Expose, focus, key, and drag events are sent even to GTK_NO_WINDOW
         // widgets.
 #if (MOZ_WIDGET_GTK == 2)
         g_signal_connect(mContainer, "expose_event",
                          G_CALLBACK(expose_event_cb), nullptr);
 #else
@@ -5975,16 +5995,34 @@ window_state_event_cb (GtkWidget *widget
 
 static void
 theme_changed_cb (GtkSettings *settings, GParamSpec *pspec, nsWindow *data)
 {
     RefPtr<nsWindow> window = data;
     window->ThemeChanged();
 }
 
+#if (MOZ_WIDGET_GTK == 3)
+static void
+scale_changed_cb (GtkWidget *widget)
+{
+    RefPtr<nsWindow> window = get_window_for_gtk_widget(widget);
+    if (!window) {
+      return;
+    }
+    window->OnDPIChanged();
+
+    // configure_event is already fired before scaling_facotr signal,
+    // but size-allocate isn't fired by changing scale
+    GtkAllocation allocation;
+    gtk_widget_get_allocation(widget, &allocation);
+    window->OnSizeAllocate(&allocation);
+}
+#endif
+
 #if GTK_CHECK_VERSION(3,4,0)
 static gboolean
 touch_event_cb(GtkWidget* aWidget, GdkEventTouch* aEvent)
 {
     UpdateLastInputEventTime(aEvent);
 
     nsWindow* window = GetFirstNSWindowForGDKWindow(aEvent->window);
     if (!window) {
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -250,16 +250,17 @@ public:
 
     void               SetPluginType(PluginType aPluginType);
 #ifdef MOZ_X11
     void               SetNonXEmbedPluginFocus(void);
     void               LoseNonXEmbedPluginFocus(void);
 #endif /* MOZ_X11 */
 
     void               ThemeChanged(void);
+    void               OnDPIChanged(void);
 
 #ifdef MOZ_X11
     Window             mOldFocusWindow;
 #endif /* MOZ_X11 */
 
     static guint32     sLastButtonPressTime;
 
     NS_IMETHOD         BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent,