eww submit button logic
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Fri, 14 Jun 2013 10:58:57 +0000 (12:58 +0200)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Fri, 14 Jun 2013 10:58:57 +0000 (12:58 +0200)
* eww.el (eww-submit): Get submit button logic right when hitting RET
on non-submit buttons.

* shr.el: Remove shr-preliminary-table-render, since that can't really
be used for anything in practice.

lisp/ChangeLog
lisp/eww.el
lisp/shr.el

index 36c6cf7..609beef 100644 (file)
@@ -1,3 +1,11 @@
+2013-06-14  Lars Magne Ingebrigtsen  <larsi@gnus.org>
+
+       * eww.el (eww-submit): Get submit button logic right when hitting RET
+       on non-submit buttons.
+
+       * shr.el: Remove shr-preliminary-table-render, since that can't really
+       be used for anything in practice.
+
 2013-06-13  Albert Krewinkel  <tarleb@moltkeplatz.de>
 
        * sieve.el: Rebind q to (sieve-bury-buffer), bind Q to
index e973f7d..270c3ee 100644 (file)
         (widget
          (cond
           ((equal type "submit")
-           (list
-            'push-button
-            :notify 'eww-submit
-            :name (cdr (assq :name cont))
-            :eww-form eww-form
-            (or (cdr (assq :value cont)) "Submit")))
+           (list 'push-button
+                 :notify 'eww-submit
+                 :name (cdr (assq :name cont))
+                 :value (cdr (assq :value cont))
+                 :eww-form eww-form
+                 (or (cdr (assq :value cont)) "Submit")))
           ((or (equal type "radio")
                (equal type "checkbox"))
            (list 'checkbox
                  :name (cdr (assq :name cont))
                  :value (cdr (assq :value cont))))
           (t
-           (list
-            'editable-field
-            :size (string-to-number
-                   (or (cdr (assq :size cont))
-                       "40"))
-            :value (or (cdr (assq :value cont)) "")
-            :secret (and (equal type "password") ?*)
-            :action 'eww-submit
-            :name (cdr (assq :name cont))
-            :eww-form eww-form)))))
-    (if (eq (car widget) 'hidden)
-       (nconc eww-form (list widget))
+           (list 'editable-field
+                 :size (string-to-number
+                        (or (cdr (assq :size cont))
+                            "40"))
+                 :value (or (cdr (assq :value cont)) "")
+                 :secret (and (equal type "password") ?*)
+                 :action 'eww-submit
+                 :name (cdr (assq :name cont))
+                 :eww-form eww-form)))))
+    (nconc eww-form (list widget))
+    (unless (eq (car widget) 'hidden)
       (apply 'widget-create widget)
       (put-text-property start (point) 'eww-widget widget))))
 
 
 (defun eww-submit (widget &rest ignore)
   (let ((form (plist-get (cdr widget) :eww-form))
-       (first-button t)
        values)
     (dolist (overlay (sort (overlays-in (point-min) (point-max))
                           (lambda (o1 o2)
                             (< (overlay-start o1) (overlay-start o2)))))
       (let ((field (or (plist-get (overlay-properties overlay) 'field)
-                      (plist-get (overlay-properties overlay) 'button)
-                      (plist-get (overlay-properties overlay) 'eww-hidden))))
+                      (plist-get (overlay-properties overlay) 'button))))
        (when (eq (plist-get (cdr field) :eww-form) form)
          (let ((name (plist-get (cdr field) :name)))
            (when name
                (when (widget-value field)
                  (push (cons name (plist-get (cdr field) :checkbox-value))
                        values)))
-              ((eq (car field) 'eww-hidden)
-               (push (cons name (plist-get (cdr field) :value))
-                     values))
               ((eq (car field) 'push-button)
                ;; We want the values from buttons if we hit a button,
-               ;; or we're submitting something and this is the first
-               ;; button displayed.
-               (when (or (and (eq (car widget) 'push-button)
-                              (eq widget field))
-                         (and (not (eq (car widget) 'push-button))
-                              (eq (car field) 'push-button)
-                              first-button))
-                 (setq first-button nil)
+               ;; if it's the first button in the DOM after the field
+               ;; hit ENTER on.
+               (when (and (eq (car widget) 'push-button)
+                          (eq widget field))
                  (push (cons name (widget-value field))
                        values)))
               (t
        (push (cons (plist-get (cdr elem) :name)
                    (plist-get (cdr elem) :value))
              values)))
+    ;; If we hit ENTER in a non-button field, include the value of the
+    ;; first submit button after it.
+    (unless (eq (car widget) 'push-button)
+      (let ((rest form)
+           (name (plist-get (cdr widget) :name)))
+       (when rest
+         (while (and rest
+                     (or (not (consp (car rest)))
+                         (not (equal name (plist-get (cdar rest) :name)))))
+           (pop rest)))
+       (while rest
+         (let ((elem (pop rest)))
+           (when (and (consp (car rest))
+                      (eq (car elem) 'push-button))
+             (push (cons (plist-get (cdr elem) :name)
+                         (plist-get (cdr elem) :value))
+                   values)
+             (setq rest nil))))))
+    (debug values)
     (let ((shr-base eww-current-url))
       (if (and (stringp (cdr (assq :method form)))
               (equal (downcase (cdr (assq :method form))) "post"))
index b5e3b42..c93357e 100644 (file)
@@ -115,7 +115,6 @@ cid: URL as the argument.")
 (defvar shr-base nil)
 (defvar shr-ignore-cache nil)
 (defvar shr-external-rendering-functions nil)
-(defvar shr-preliminary-table-render nil)
 
 (defvar shr-map
   (let ((map (make-sparse-keymap)))
@@ -158,6 +157,7 @@ DOM should be a parse tree as generated by
        (shr-state nil)
        (shr-start nil)
        (shr-base nil)
+       (shr-preliminary-table-render 0)
        (shr-width (or shr-width (window-width))))
     (shr-descend (shr-transform-dom dom))
     (shr-remove-trailing-whitespace start (point))))
@@ -1167,7 +1167,6 @@ ones, in case fg and bg are nil."
   (setq cont (or (cdr (assq 'tbody cont))
                 cont))
   (let* ((shr-inhibit-images t)
-        (shr-preliminary-table-render t)
         (shr-table-depth (1+ shr-table-depth))
         (shr-kinsoku-shorten t)
         ;; Find all suggested widths.
@@ -1189,7 +1188,6 @@ ones, in case fg and bg are nil."
             (frame-width))
       (setq truncate-lines t))
     ;; Then render the table again with these new "hard" widths.
-    (setq shr-preliminary-table-render nil)
     (shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths))
   ;; Finally, insert all the images after the table.  The Emacs buffer
   ;; model isn't strong enough to allow us to put the images actually