NetSurf
Data Structures | Functions
interaction.h File Reference

HTML content user interaction handling. More...

#include "desktop/search.h"
Include dependency graph for interaction.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  html_scrollbar_data
 Context for scrollbar. More...
 

Functions

nserror html_mouse_track (struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
 Handle mouse tracking (including drags) in an HTML content window. More...
 
nserror html_mouse_action (struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y)
 Handle mouse clicks and movements in an HTML content window. More...
 
bool html_keypress (struct content *c, uint32_t key)
 Handle keypresses. More...
 
void html_overflow_scroll_callback (void *client_data, struct scrollbar_msg_data *scrollbar_data)
 Callback for in-page scrollbars. More...
 
void html_search (struct content *c, void *context, search_flags_t flags, const char *string)
 
void html_search_clear (struct content *c)
 
void html_set_drag_type (html_content *html, html_drag_type drag_type, union html_drag_owner drag_owner, const struct rect *rect)
 Set our drag status, and inform whatever owns the content. More...
 
void html_set_selection (html_content *html, html_selection_type selection_type, union html_selection_owner selection_owner, bool read_only)
 Set our selection status, and inform whatever owns the content. More...
 
void html_set_focus (html_content *html, html_focus_type focus_type, union html_focus_owner focus_owner, bool hide_caret, int x, int y, int height, const struct rect *clip)
 Set our input focus, and inform whatever owns the content. More...
 

Detailed Description

HTML content user interaction handling.

Definition in file interaction.h.

Function Documentation

◆ html_keypress()

bool html_keypress ( struct content c,
uint32_t  key 
)

Handle keypresses.

Parameters
ccontent of type HTML
keyThe UCS4 character codepoint
Returns
true if key handled, false otherwise
Todo:
At the moment, the front end interface for keypress only gives us a UCS4 key value. This doesn't doesn't have all the information we need to fill out the event properly. We don't get to know about modifier keys, and things like CTRL+C are passed in as NS_KEY_COPY_SELECTION, a magic value outside the valid Unicode range.

We need to:

  1. Update the front end interface so that both press and release events reach the core.
  2. Stop encoding the special keys like NS_KEY_COPY_SELECTION as magic values in the front ends, so we just get the events, e.g.:
    1. Press ctrl
    2. Press c
    3. Release c
    4. Release ctrl
  3. Pass all the new info to the DOM KeyboardEvent events.
  4. If there is a focused element, fire the event at that, instead of html->layout->node.
  5. Rebuild the NS_KEY_COPY_SELECTION values from the info we now get given, and use that for the code below this fire_dom_keyboard_event call.
  6. Move the code after this fire_dom_keyboard_event call into the default action handler for DOM events.

This will mean that if the JavaScript event listener does event.preventDefault() then we won't handle the event when we're not supposed to.

Definition at line 1519 of file interaction.c.

References box_textarea_keypress(), html_focus_owner::content, content_keypress(), fire_dom_keyboard_event(), html_content::focus_owner, html_content::focus_type, HTML_FOCUS_CONTENT, HTML_FOCUS_TEXTAREA, html_content::layout, box::node, NS_KEY_CLEAR_SELECTION, NS_KEY_COPY_SELECTION, NS_KEY_ESCAPE, NS_KEY_SELECT_ALL, NSERROR_OK, box::object, html_content::sel, selection_clear(), selection_copy_to_clipboard(), selection_select_all(), and html_focus_owner::textarea.

Here is the call graph for this function:

◆ html_mouse_action()

nserror html_mouse_action ( struct content c,
struct browser_window bw,
browser_mouse_state  mouse,
int  x,
int  y 
)

Handle mouse clicks and movements in an HTML content window.

This function handles both hovering and clicking. It is important that the code path is identical (except that hovering doesn't carry out the action), so that the status bar reflects exactly what will happen. Having separate code paths opens the possibility that an attacker will make the status bar show some harmless action where clicking will be harmful.

Parameters
ccontent of type html
bwbrowser window
mousestate of mouse buttons and modifier keys
xx coordinate of mouse
yy coordinate of mouse
Returns
NSERROR_OK or appropriate error code.

Definition at line 1462 of file interaction.c.

References html_content::drag_type, HTML_DRAG_CONTENT_SCROLL, HTML_DRAG_CONTENT_SELECTION, HTML_DRAG_NONE, HTML_DRAG_SCROLLBAR, HTML_DRAG_SELECTION, HTML_DRAG_TEXTAREA_SCROLLBAR, HTML_DRAG_TEXTAREA_SELECTION, messages_get_errorcode(), mouse_action_drag_content(), mouse_action_drag_none(), mouse_action_drag_scrollbar(), mouse_action_drag_selection(), mouse_action_drag_textarea(), mouse_action_select_menu(), NSERROR_OK, NSLOG, and html_content::visible_select_menu.

Referenced by html_mouse_track().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_mouse_track()

nserror html_mouse_track ( struct content c,
struct browser_window bw,
browser_mouse_state  mouse,
int  x,
int  y 
)

Handle mouse tracking (including drags) in an HTML content window.

Parameters
ccontent of type html
bwbrowser window
mousestate of mouse buttons and modifier keys
xcoordinate of mouse
ycoordinate of mouse

Definition at line 1451 of file interaction.c.

References html_mouse_action().

Here is the call graph for this function:

◆ html_overflow_scroll_callback()

void html_overflow_scroll_callback ( void *  client_data,
struct scrollbar_msg_data scrollbar_data 
)

Callback for in-page scrollbars.

Definition at line 1601 of file interaction.c.

References html_scrollbar_data::box, BROWSER_POINTER_AUTO, html_scrollbar_data::c, content_broadcast(), CONTENT_MSG_POINTER, html__redraw_a_box(), HTML_DRAG_NONE, HTML_DRAG_SCROLLBAR, html_set_drag_type(), scrollbar_msg_data::msg, html_content::reflowing, scrollbar_msg_data::scrollbar, SCROLLBAR_MSG_MOVED, SCROLLBAR_MSG_SCROLL_FINISHED, SCROLLBAR_MSG_SCROLL_START, scrollbar_msg_data::x0, rect::x0, scrollbar_msg_data::x1, scrollbar_msg_data::y0, and scrollbar_msg_data::y1.

Referenced by box_handle_scrollbars().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_search()

void html_search ( struct content c,
void *  context,
search_flags_t  flags,
const char *  string 
)

◆ html_search_clear()

void html_search_clear ( struct content c)

◆ html_set_drag_type()

void html_set_drag_type ( html_content html,
html_drag_type  drag_type,
union html_drag_owner  drag_owner,
const struct rect rect 
)

Set our drag status, and inform whatever owns the content.

Parameters
htmlHTML content
drag_typeType of drag
drag_ownerWhat owns the drag
rectPointer movement bounds

Definition at line 1648 of file interaction.c.

References content_broadcast(), content_msg_data::CONTENT_DRAG_NONE, content_msg_data::CONTENT_DRAG_SCROLL, content_msg_data::CONTENT_DRAG_SELECTION, CONTENT_MSG_DRAG, content_msg_data::drag, html_content::drag_owner, html_content::drag_type, fallthrough, HTML_DRAG_CONTENT_SCROLL, HTML_DRAG_CONTENT_SELECTION, HTML_DRAG_NONE, HTML_DRAG_SCROLLBAR, HTML_DRAG_SELECTION, HTML_DRAG_TEXTAREA_SCROLLBAR, HTML_DRAG_TEXTAREA_SELECTION, html_drag_owner::no_owner, content_msg_data::rect, and content_msg_data::type.

Referenced by box_textarea_callback(), default_mouse_action(), html_object_callback(), html_overflow_scroll_callback(), and mouse_action_drag_selection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_set_focus()

void html_set_focus ( html_content html,
html_focus_type  focus_type,
union html_focus_owner  focus_owner,
bool  hide_caret,
int  x,
int  y,
int  height,
const struct rect clip 
)

Set our input focus, and inform whatever owns the content.

Parameters
htmlHTML content
focus_typeType of input focus
focus_ownerWhat owns the focus
hide_caretTrue iff caret to be hidden
xCarret x-coord rel to owner
yCarret y-coord rel to owner
heightCarret height
clipCarret clip rect

Definition at line 1685 of file interaction.c.

References box_coords(), content_msg_data::caret, content_msg_data::clip, clip(), html_focus_owner::content, content_broadcast(), CONTENT_MSG_CARET, html_content::focus_owner, html_content::focus_type, content_msg_data::height, height, HTML_FOCUS_CONTENT, HTML_FOCUS_SELF, HTML_FOCUS_TEXTAREA, content_msg_data::pos, html_focus_owner::self, html_focus_owner::textarea, content_msg_data::type, content_msg_data::x, rect::x0, rect::x1, content_msg_data::y, rect::y0, and rect::y1.

Referenced by box_textarea_callback(), default_mouse_action(), and html_object_callback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ html_set_selection()

void html_set_selection ( html_content html,
html_selection_type  selection_type,
union html_selection_owner  selection_owner,
bool  read_only 
)

Set our selection status, and inform whatever owns the content.

Parameters
htmlHTML content
selection_typeType of selection
selection_ownerWhat owns the selection
read_onlyTrue iff selection is read only

Definition at line 1743 of file interaction.c.

References html_selection_owner::content, content_broadcast(), content_clear_selection(), CONTENT_MSG_SELECTION, form_control::data, fallthrough, box::gadget, HTML_SELECTION_CONTENT, HTML_SELECTION_NONE, HTML_SELECTION_SELF, HTML_SELECTION_TEXTAREA, html_selection_owner::none, box::object, html_content::sel, content_msg_data::selection, selection_clear(), html_content::selection_owner, html_content::selection_type, html_selection_owner::textarea, and textarea_clear_selection().

Referenced by box_textarea_callback(), default_mouse_action(), gadget_mouse_action(), html_object_callback(), and html_object_mouse_action().

Here is the call graph for this function:
Here is the caller graph for this function: