Title: [154594] trunk/Tools
Revision
154594
Author
carlo...@webkit.org
Date
2013-08-26 03:31:35 -0700 (Mon, 26 Aug 2013)

Log Message

[GTK] Improve the stop/reload button implementation in MiniBrowser
https://bugs.webkit.org/show_bug.cgi?id=120292

Reviewed by Philippe Normand.

- Use an instance member of BrowserWindow for the button widget
  instead of a global variable.
- Use notify::is-loading to monitor the WebView load instead of
  the estimated-load-progress property.
- Use webkit_web_view_is_loading() to check whether the view
  is loading to change the button icon instead of a string
  comparison of the gtk stock icon id.
- Use the right casts to fix compile warning.

* MiniBrowser/gtk/BrowserWindow.c:
(reloadOrStopCallback):
(webViewLoadProgressChanged):
(webViewIsLoadingChanged):
(browser_window_init):
(browserWindowConstructed):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (154593 => 154594)


--- trunk/Tools/ChangeLog	2013-08-26 10:07:28 UTC (rev 154593)
+++ trunk/Tools/ChangeLog	2013-08-26 10:31:35 UTC (rev 154594)
@@ -1,3 +1,26 @@
+2013-08-26  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Improve the stop/reload button implementation in MiniBrowser
+        https://bugs.webkit.org/show_bug.cgi?id=120292
+
+        Reviewed by Philippe Normand.
+
+        - Use an instance member of BrowserWindow for the button widget
+          instead of a global variable.
+        - Use notify::is-loading to monitor the WebView load instead of
+          the estimated-load-progress property.
+        - Use webkit_web_view_is_loading() to check whether the view
+          is loading to change the button icon instead of a string
+          comparison of the gtk stock icon id.
+        - Use the right casts to fix compile warning.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (reloadOrStopCallback):
+        (webViewLoadProgressChanged):
+        (webViewIsLoadingChanged):
+        (browser_window_init):
+        (browserWindowConstructed):
+
 2013-08-26  Arunprasad Rajkumar  <arura...@cisco.com>
 
         [Qt] Remove the fix in QWebPage::_javascript_ConsoleMessage introduced by (r61433)

Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.c (154593 => 154594)


--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.c	2013-08-26 10:07:28 UTC (rev 154593)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.c	2013-08-26 10:31:35 UTC (rev 154594)
@@ -53,6 +53,7 @@
     WebKitWebView *webView;
     GtkWidget *downloadsBar;
     GdkPixbuf *favicon;
+    GtkWidget *reloadOrStopButton;
     GtkWidget *fullScreenMessageLabel;
     guint fullScreenMessageLabelId;
 };
@@ -67,7 +68,6 @@
 static const gdouble maximumZoomLevel = 3;
 static const gdouble zoomStep = 1.2;
 static gint windowCount = 0;
-static GtkToolButton* reloadOrStopButton = 0;
 
 G_DEFINE_TYPE(BrowserWindow, browser_window, GTK_TYPE_WINDOW)
 
@@ -107,7 +107,7 @@
 
 static void reloadOrStopCallback(BrowserWindow *window)
 {
-    if (!g_strcmp0(gtk_tool_button_get_stock_id(reloadOrStopButton), GTK_STOCK_STOP))
+    if (webkit_web_view_is_loading(window->webView))
         webkit_web_view_stop_loading(window->webView);
     else
         webkit_web_view_reload(window->webView);
@@ -159,14 +159,8 @@
 {
     gdouble progress = webkit_web_view_get_estimated_load_progress(webView);
     gtk_entry_set_progress_fraction(GTK_ENTRY(window->uriEntry), progress);
-
-    if (progress > 0.0 && progress < 1.0)
-        gtk_tool_button_set_stock_id(reloadOrStopButton, GTK_STOCK_STOP);
-
-    if (progress == 1.0) {
-        gtk_tool_button_set_stock_id(reloadOrStopButton, GTK_STOCK_REFRESH);
+    if (progress == 1.0)
         g_timeout_add(500, (GSourceFunc)resetEntryProgress, window->uriEntry);
-    }
 }
 
 static void downloadStarted(WebKitWebContext *webContext, WebKitDownload *download, BrowserWindow *window)
@@ -466,6 +460,12 @@
     updateUriEntryIcon(window);
 }
 
+static void webViewIsLoadingChanged(GObject *object, GParamSpec *paramSpec, BrowserWindow *window)
+{
+    gboolean isLoading = webkit_web_view_is_loading(window->webView);
+    gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(window->reloadOrStopButton), isLoading ? GTK_STOCK_STOP : GTK_STOCK_REFRESH);
+}
+
 static void zoomInCallback(BrowserWindow *window)
 {
     gdouble zoomLevel = webkit_web_view_get_zoom_level(window->webView) * zoomStep;
@@ -581,11 +581,12 @@
     gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
     gtk_widget_show(GTK_WIDGET(item));
 
-    reloadOrStopButton = gtk_tool_button_new_from_stock(GTK_STOCK_REFRESH);
-    g_signal_connect_swapped(reloadOrStopButton, "clicked", G_CALLBACK(reloadOrStopCallback), window);
-    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), reloadOrStopButton, -1);
-    gtk_widget_add_accelerator(GTK_WIDGET(reloadOrStopButton), "clicked", accelGroup, GDK_KEY_F5, 0, GTK_ACCEL_VISIBLE);
-    gtk_widget_show(GTK_WIDGET(reloadOrStopButton));
+    item = gtk_tool_button_new_from_stock(GTK_STOCK_REFRESH);
+    window->reloadOrStopButton = GTK_WIDGET(item);
+    g_signal_connect_swapped(item, "clicked", G_CALLBACK(reloadOrStopCallback), window);
+    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
+    gtk_widget_add_accelerator(window->reloadOrStopButton, "clicked", accelGroup, GDK_KEY_F5, 0, GTK_ACCEL_VISIBLE);
+    gtk_widget_show(window->reloadOrStopButton);
 
     GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
     window->mainBox = vbox;
@@ -614,6 +615,7 @@
     g_signal_connect(window->webView, "notify::favicon", G_CALLBACK(faviconChanged), window);
     g_signal_connect(window->webView, "enter-fullscreen", G_CALLBACK(webViewEnterFullScreen), window);
     g_signal_connect(window->webView, "leave-fullscreen", G_CALLBACK(webViewLeaveFullScreen), window);
+    g_signal_connect(window->webView, "notify::is-loading", G_CALLBACK(webViewIsLoadingChanged), window);
 
     g_signal_connect(webkit_web_view_get_context(window->webView), "download-started", G_CALLBACK(downloadStarted), window);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to