Handle readonly attribute for text inputs and textareas.

This commit is contained in:
Michael Drake 2013-02-23 17:44:20 +00:00
parent 3cc90f2f30
commit bba74b7a0b
3 changed files with 25 additions and 15 deletions

View File

@ -116,6 +116,7 @@ form { display: block; }
input, button { background-color: #fff; color: #000; text-align: left;
font-family: sans-serif; width: auto; height: auto; overflow: hidden;
border: 2px solid #333; padding: 1px 2px; line-height: 1.33; }
input[readonly] { background-color: #ddd; color: #333; }
input[type=button], input[type=reset], input[type=submit], button {
background-color: #d9d9d9; color: #000; text-align: center;
border: medium outset #d9d9d9; padding: 1px 0.5em; }
@ -137,6 +138,7 @@ select:after { content: "\25bc"; border-left: 4px ridge #d9d9d9; }
textarea { background-color: #fff; color: #000; text-align: left;
font-family: monospace; width: auto; height: auto; overflow: scroll;
margin: 1px; border: 2px solid #333; padding: 0 2px; }
textarea[readonly] { background-color: #ddd; color: #333; }
fieldset { display: block; border: thin solid #888; margin: 1.12em 0; }

View File

@ -852,9 +852,6 @@ static bool textarea_set_caret_xy(struct textarea *ta, int x, int y)
{
unsigned int c_off;
if (ta->flags & TEXTAREA_READONLY)
return true;
textarea_get_xy_offset(ta, x, y, &c_off);
return textarea_set_caret(ta, c_off);
@ -949,7 +946,9 @@ static bool textarea_replace_text(struct textarea *ta, unsigned int start,
{
size_t b_start, b_end;
if (ta->flags & TEXTAREA_READONLY)
if ((ta->flags & TEXTAREA_READONLY) &&
!(rep == NULL && rep_len == 0 && add_to_clipboard))
/* Can't edit if readonly, and we're not just copying */
return true;
if (start > ta->text.utf8_len)
@ -1333,9 +1332,6 @@ bool textarea_set_caret(struct textarea *ta, int caret)
struct textarea_msg msg;
bool scrolled;
if (ta->flags & TEXTAREA_READONLY)
return true;
c_len = ta->show->utf8_len;
if (caret != -1 && caret > (signed)c_len)
@ -2273,13 +2269,11 @@ bool textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse,
return textarea_select_paragraph(ta);
} else if (mouse & BROWSER_MOUSE_PRESS_1) {
if (!(ta->flags & TEXTAREA_READONLY)) {
/* Place caret */
textarea_get_xy_offset(ta, x, y, &c_off);
ta->drag_start_char = c_off;
/* Place caret */
textarea_get_xy_offset(ta, x, y, &c_off);
ta->drag_start_char = c_off;
textarea_set_caret(ta, c_off);
}
textarea_set_caret(ta, c_off);
if (ta->sel_start != -1) {
/* Clear selection */
textarea_clear_selection(ta);

View File

@ -209,11 +209,10 @@ bool box_textarea_create_textarea(html_content *html,
textarea_setup ta_setup;
textarea_flags ta_flags;
plot_font_style_t fstyle;
bool read_only = false;
struct form_control *gadget = box->gadget;
const char *text;
/** TODO: Read only textarea */
assert(gadget != NULL);
assert(gadget->type == GADGET_TEXTAREA ||
gadget->type == GADGET_TEXTBOX ||
@ -221,6 +220,13 @@ bool box_textarea_create_textarea(html_content *html,
if (gadget->type == GADGET_TEXTAREA) {
ta_flags = TEXTAREA_MULTILINE;
dom_html_text_area_element *textarea =
(dom_html_text_area_element *) node;
err = dom_html_text_area_element_get_read_only(
textarea, &read_only);
if (err != DOM_NO_ERR)
return false;
/* Get the textarea's initial content */
err = dom_node_get_text_content(node, &dom_text);
@ -230,6 +236,11 @@ bool box_textarea_create_textarea(html_content *html,
} else {
dom_html_input_element *input = (dom_html_input_element *) node;
err = dom_html_input_element_get_read_only(
input, &read_only);
if (err != DOM_NO_ERR)
return false;
if (gadget->type == GADGET_PASSWORD)
ta_flags = TEXTAREA_PASSWORD;
else
@ -249,6 +260,9 @@ bool box_textarea_create_textarea(html_content *html,
text = "";
}
if (read_only)
ta_flags |= TEXTAREA_READONLY;
gadget->data.text.data.html = html;
gadget->data.text.data.gadget = gadget;