;;; Code:
(eval-when-compile (require 'cl))
+(require 'format-spec)
(require 'shr)
(require 'url)
(require 'mm-url)
:group 'eww
:type 'string)
+(defface eww-button
+ '((((type x w32 ns) (class color)) ; Like default mode line
+ :box (:line-width 2 :style released-button)
+ :background "lightgrey" :foreground "black"))
+ "Face for eww buffer buttons."
+ :version "24.4"
+ :group 'eww)
+
(defvar eww-current-url nil)
(defvar eww-current-title ""
"Title of current page.")
(let ((new-colors (shr-color-check fg bg)))
(when new-colors
(when fg
- (eww-put-color start end :foreground (cadr new-colors)))
+ (add-face-text-property start end
+ (list :foreground (cadr new-colors))))
(when bg
- (eww-put-color start end :background (car new-colors)))))))
-
-(defun eww-put-color (start end type color)
- (shr-put-color-1 start end type color))
+ (add-face-text-property start end
+ (list :background (car new-colors))))))))
(defun eww-display-raw (charset)
(let ((data (buffer-substring (point) (point-max))))
(let* ((start (point))
(type (downcase (or (cdr (assq :type cont))
"text")))
+ (value (cdr (assq :value cont)))
(widget
(cond
((equal type "submit")
(list 'push-button
:notify 'eww-submit
:name (cdr (assq :name cont))
- :value (cdr (assq :value cont))
+ :value (if (zerop (length value))
+ "Submit"
+ value)
:eww-form eww-form
- (or (cdr (assq :value cont)) "Submit")))
+ (or (if (zerop (length value))
+ "Submit"
+ value))))
((or (equal type "radio")
(equal type "checkbox"))
(list 'checkbox
:notify 'eww-click-radio
:name (cdr (assq :name cont))
- :checkbox-value (cdr (assq :value cont))
+ :checkbox-value value
:checkbox-type type
:eww-form eww-form
(cdr (assq :checked cont))))
((equal type "hidden")
(list 'hidden
:name (cdr (assq :name cont))
- :value (cdr (assq :value cont))))
+ :value value))
(t
(list 'editable-field
:size (string-to-number
(or (cdr (assq :size cont))
"40"))
- :value (or (cdr (assq :value cont)) "")
+ :value value
:secret (and (equal type "password") ?*)
:action 'eww-submit
:name (cdr (assq :name cont))
(nconc eww-form (list widget))
(unless (eq (car widget) 'hidden)
(apply 'widget-create widget)
- (put-text-property start (point) 'eww-widget widget))))
+ (put-text-property start (point) 'eww-widget widget)
+ (insert " "))))
(defun eww-tag-textarea (cont)
(let* ((start (point))
:value (cdr (assq :value (cdr elem)))
:tag (cdr (assq 'text (cdr elem))))
options)))
- ;; If we have no selected values, default to the first value.
- (unless (plist-get (cdr menu) :value)
- (nconc menu (list :value (nth 2 (car options)))))
- (nconc menu options)
- (apply 'widget-create menu)
- (put-text-property start (point) 'eww-widget menu)
- (shr-ensure-paragraph)))
+ (when options
+ ;; If we have no selected values, default to the first value.
+ (unless (plist-get (cdr menu) :value)
+ (nconc menu (list :value (nth 2 (car options)))))
+ (nconc menu options)
+ (apply 'widget-create menu)
+ (put-text-property start (point) 'eww-widget menu)
+ (shr-ensure-paragraph))))
(defun eww-click-radio (widget &rest ignore)
(let ((form (plist-get (cdr widget) :eww-form))
(delete-region start end))
(when (and widget
(not (eq (car widget) 'hidden)))
- (apply 'widget-create widget)))
+ (apply 'widget-create widget)
+ (put-text-property start (point) 'help-echo
+ (if (memq (car widget) '(text editable-field))
+ "Input field"
+ "Button"))
+ (when (eq (car widget) 'push-button)
+ (add-face-text-property start (point) 'eww-button t))))
(widget-setup)
(eww-fix-widget-keymap)))