Index: modules/overlay/overlay.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/overlay/overlay.module,v
retrieving revision 1.4
diff -u -p -r1.4 overlay.module
--- modules/overlay/overlay.module	14 Dec 2009 16:36:56 -0000	1.4
+++ modules/overlay/overlay.module	18 Dec 2009 04:07:05 -0000
@@ -330,11 +330,14 @@ function overlay_form_after_build($form,
  * perform any redirection once the submitted form has been processed.
  *
  * When $form_state['redirect'] is set to FALSE, then Form API will simply
- * re-render the form with the values still in its fields. And this is all
- * we need to output the JavaScript that will tell the parent window to close
- * the child dialog.
+ * re-render the current page. This is all we need in order to output the
+ * JavaScript that will tell the parent window to close the child dialog, so
+ * we store a variable which will cause the page to be rendered by a delivery
+ * callback function that does not actually print visible HTML, thereby
+ * allowing the dialog to be closed faster and with less interruption.
  *
  * @see overlay_get_mode()
+ * @see overlay_page_delivery_callback_alter()
  * @ingroup forms
  */
 function overlay_form_submit($form, &$form_state) {
@@ -384,13 +387,58 @@ function overlay_form_submit($form, &$fo
       }
       drupal_add_js($settings, array('type' => 'setting'));
     }
-    // Tell FAPI to redraw the form without redirection after all submit
-    // callbacks have been processed.
+    // Requess that an empty page be displayed.
+    overlay_display_empty_page(TRUE);
+    // Tell FAPI to stay on the same page after all submit callbacks have been
+    // processed.
     $form_state['redirect'] = FALSE;
   }
 }
 
 /**
+ * Callback to request that the overlay display an empty page.
+ *
+ * This is used to prevent a submitted form which closes the overlay from being
+ * fully re-rendered before the overlay is closed.
+ *
+ * @param $value
+ *   By default, an empty page will not be displayed. Set to TRUE to request
+ *   an empty page display, or FALSE to disable the empty page display (if it
+ *   was previously enabled on this page request).
+ *
+ * @return
+ *   TRUE if the current behavior is to display an empty page, or FALSE if not.
+ */
+function overlay_display_empty_page($value = NULL) {
+  $display_empty_page = &drupal_static(__FUNCTION__, FALSE);
+  if (isset($value)) {
+    $display_empty_page = $value;
+  }
+  return $display_empty_page;
+}
+
+/**
+ * Implements hook_page_delivery_callback_alter().
+ */
+function overlay_page_delivery_callback_alter(&$callback) {
+  if (overlay_display_empty_page()) {
+    $callback = 'overlay_deliver_empty_page';
+  }
+}
+
+/**
+ * Delivery callback to display an empty page.
+ *
+ * This function is used to print out a bare minimum empty page which still has
+ * the scripts and styles necessary in order to trigger the overlay to close.
+ */
+function overlay_deliver_empty_page() {
+  $empty_page = '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head><body class="overlay"></body></html>';
+  print $empty_page;
+  drupal_exit();
+}
+
+/**
  * Get the current overlay mode.
  *
  * @see overlay_set_mode()
