r13219 chris_y - in /trunk/netsurf/amiga: clipboard.c drag.c drag.h tree.c
by netsurf@semichrome.net
Author: chris_y
Date: Fri Dec 2 07:24:40 2011
New Revision: 13219
URL: http://source.netsurf-browser.org?rev=13219&view=rev
Log:
Support dragging from global history to hotlist
Modified:
trunk/netsurf/amiga/clipboard.c
trunk/netsurf/amiga/drag.c
trunk/netsurf/amiga/drag.h
trunk/netsurf/amiga/tree.c
Modified: trunk/netsurf/amiga/clipboard.c
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/clipboard.c?rev=132...
==============================================================================
--- trunk/netsurf/amiga/clipboard.c (original)
+++ trunk/netsurf/amiga/clipboard.c Fri Dec 2 07:24:40 2011
@@ -334,7 +334,7 @@
char *utf8text;
struct ami_text_selection *sel;
struct IFFHandle *old_iffh = iffh;
- struct gui_window_2 *gwin = ami_window_at_pointer();
+ struct gui_window_2 *gwin = ami_window_at_pointer(AMINS_WINDOW);
if(!gwin)
{
Modified: trunk/netsurf/amiga/drag.c
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/drag.c?rev=13219&r1...
==============================================================================
--- trunk/netsurf/amiga/drag.c (original)
+++ trunk/netsurf/amiga/drag.c Fri Dec 2 07:24:40 2011
@@ -276,7 +276,7 @@
return drag_in_progress;
}
-struct gui_window_2 *ami_find_gwin_by_id(struct Window *win)
+void *ami_find_gwin_by_id(struct Window *win, int type)
{
struct nsObject *node, *nnode;
struct gui_window_2 *gwin;
@@ -289,7 +289,7 @@
{
nnode=(struct nsObject *)GetSucc((struct Node *)node);
- if(node->Type == AMINS_WINDOW) // or frame?
+ if(node->Type == type)
{
gwin = node->objstruct;
if(win == gwin->win) return gwin;
@@ -299,7 +299,7 @@
return NULL;
}
-struct gui_window_2 *ami_window_at_pointer(void)
+void *ami_window_at_pointer(int type)
{
struct Layer *layer;
@@ -309,6 +309,6 @@
UnlockLayerInfo(&scrn->LayerInfo);
- if(layer) return ami_find_gwin_by_id(layer->Window);
+ if(layer) return ami_find_gwin_by_id(layer->Window, type);
else return NULL;
}
Modified: trunk/netsurf/amiga/drag.h
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/drag.h?rev=13219&r1...
==============================================================================
--- trunk/netsurf/amiga/drag.h (original)
+++ trunk/netsurf/amiga/drag.h Fri Dec 2 07:24:40 2011
@@ -32,5 +32,5 @@
void ami_drag_icon_move(void);
BOOL ami_drag_in_progress(void);
-struct gui_window_2 *ami_window_at_pointer(void);
+void *ami_window_at_pointer(int type);
#endif
Modified: trunk/netsurf/amiga/tree.c
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/tree.c?rev=13219&r1...
==============================================================================
--- trunk/netsurf/amiga/tree.c (original)
+++ trunk/netsurf/amiga/tree.c Fri Dec 2 07:24:40 2011
@@ -78,9 +78,9 @@
struct treeview_window {
+ struct nsObject *node;
struct Window *win;
Object *objects[GID_TREE_LAST];
- struct nsObject *node;
int type;
struct NewMenu *menu;
char *menu_name[AMI_TREE_MENU_ITEMS];
@@ -289,12 +289,13 @@
void ami_tree_drag_end(struct treeview_window *twin, int x, int y)
{
struct gui_window_2 *gwin;
+ struct treeview_window *tw;
struct node *selected_node;
BOOL drag;
if(drag = ami_drag_in_progress()) ami_drag_icon_close(twin->win);
- if(drag && (gwin = ami_window_at_pointer()))
+ if(drag && (twin != ami_window_at_pointer(AMINS_TVWINDOW)))
{
selected_node = tree_get_selected_node(tree_get_root(twin->tree));
@@ -304,8 +305,16 @@
}
else
{
- browser_window_go(gwin->bw, tree_url_node_get_url(selected_node),
- NULL, true);
+ if(gwin = ami_window_at_pointer(AMINS_WINDOW))
+ {
+ browser_window_go(gwin->bw, tree_url_node_get_url(selected_node),
+ NULL, true);
+ }
+ else if((tw = ami_window_at_pointer(AMINS_TVWINDOW)) &&
+ (tw != twin) && (tw->type == AMI_TREE_HOTLIST))
+ {
+ hotlist_add_page_xy(tree_url_node_get_url(selected_node), x, y);
+ }
}
tree_drag_end(twin->tree, twin->mouse_state,
twin->drag_x, twin->drag_y,
11 years, 6 months
r13218 chris_y - /trunk/netsurf/amiga/gui.c
by netsurf@semichrome.net
Author: chris_y
Date: Fri Dec 2 06:47:11 2011
New Revision: 13218
URL: http://source.netsurf-browser.org?rev=13218&view=rev
Log:
Use core file drop.
Loop through entire list of dropped files.
If multiple files are dropped and not handled by core, open in tabs;
Activate the window on first file drop to workaround a bug where the window needed to
be clicked before the file would appear.
As using core functionality, DataTypes no longer used to parse dropped files (likely
to be rarely needed anyway).
Modified:
trunk/netsurf/amiga/gui.c
Modified: trunk/netsurf/amiga/gui.c
URL: http://source.netsurf-browser.org/trunk/netsurf/amiga/gui.c?rev=13218&r1=...
==============================================================================
--- trunk/netsurf/amiga/gui.c (original)
+++ trunk/netsurf/amiga/gui.c Fri Dec 2 06:47:11 2011
@@ -986,17 +986,21 @@
}
}
-bool ami_mouse_to_ns_coords(struct gui_window_2 *gwin, int *x, int *y)
+bool ami_mouse_to_ns_coords(struct gui_window_2 *gwin, int *x, int *y,
+ int mouse_x, int mouse_y)
{
int xs, ys;
int ns_x, ns_y;
struct IBox *bbox;
+ if(mouse_x == -1) mouse_x = gwin->win->MouseX;
+ if(mouse_y == -1) mouse_y = gwin->win->MouseY;
+
GetAttr(SPACE_AreaBox, (Object *)gwin->objects[GID_BROWSER],
(ULONG *)&bbox);
- ns_x = (ULONG)(gwin->win->MouseX - bbox->Left);
- ns_y = (ULONG)(gwin->win->MouseY - bbox->Top);
+ ns_x = (ULONG)(mouse_x - bbox->Left);
+ ns_y = (ULONG)(mouse_y - bbox->Top);
if((ns_x < 0) || (ns_x > bbox->Width) || (ns_y < 0) || (ns_y > bbox->Height))
return false;
@@ -1795,15 +1799,11 @@
{
struct AppMessage *appmsg;
struct gui_window_2 *gwin;
- struct IBox *bbox;
- ULONG x,y,xs,ys,width,height,len;
+ int x, y;
struct WBArg *appwinargs;
STRPTR filename;
- struct box *box,*file_box=0,*text_box=0;
- hlcache_handle *content;
- int box_x=0,box_y=0;
- BPTR fh = 0;
- char *utf8text,*urlfilename;
+ char *urlfilename;
+ int i = 0;
while(appmsg=(struct AppMessage *)GetMsg(appport))
{
@@ -1817,136 +1817,56 @@
}
else if(appmsg->am_Type == AMTYPE_APPWINDOW)
{
- GetAttr(SPACE_AreaBox, (Object *)gwin->objects[GID_BROWSER],
- (ULONG *)&bbox);
-
- ami_get_hscroll_pos(gwin, (ULONG *)&xs);
- x = (appmsg->am_MouseX) - (bbox->Left) +xs;
-
- ami_get_vscroll_pos(gwin, (ULONG *)&ys);
- y = appmsg->am_MouseY - bbox->Top + ys;
-
- width=bbox->Width;
- height=bbox->Height;
-
- if(appwinargs = appmsg->am_ArgList)
- {
- if(filename = AllocVec(1024,MEMF_PRIVATE | MEMF_CLEAR))
+ for(i = 0; i < appmsg->am_NumArgs; ++i)
+ {
+ if(appwinargs = &appmsg->am_ArgList[i])
{
- if(appwinargs->wa_Lock)
+ if(filename = AllocVec(1024, MEMF_PRIVATE | MEMF_CLEAR))
{
- NameFromLock(appwinargs->wa_Lock,filename,1024);
- }
-
- AddPart(filename,appwinargs->wa_Name,1024);
-
- if(((gwin->bw->current_content == NULL) ||
- (content_get_type(gwin->bw->current_content) != CONTENT_HTML)) ||
- (!((x>=xs) && (y>=ys) && (x<width+xs) && (y<height+ys))))
- {
- urlfilename = path_to_url(filename);
- browser_window_go(gwin->bw,urlfilename,NULL,true);
- free(urlfilename);
- }
- else
- {
- content = gwin->bw->current_content;
- box = html_get_box_tree(content);
- while ((box = box_at_point(box, x, y, &box_x, &box_y, &content)))
+ if(appwinargs->wa_Lock)
{
- if (box->style && css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) continue;
-
- if (box->gadget)
- {
- switch (box->gadget->type)
- {
- case GADGET_FILE:
- file_box = box;
- break;
-
- case GADGET_TEXTBOX:
- case GADGET_TEXTAREA:
- case GADGET_PASSWORD:
- text_box = box;
- break;
-
- default:
- break;
- }
- }
+ NameFromLock(appwinargs->wa_Lock, filename, 1024);
}
- if((!file_box) && (!text_box))
+ AddPart(filename, appwinargs->wa_Name, 1024);
+
+ if(ami_mouse_to_ns_coords(gwin, &x, &y,
+ appmsg->am_MouseX, appmsg->am_MouseY) == false)
{
urlfilename = path_to_url(filename);
- browser_window_go(gwin->bw, urlfilename, NULL, true);
+
+ if(i == 0)
+ {
+ browser_window_go(gwin->bw, urlfilename, NULL, true);
+ ActivateWindow(gwin->win);
+ }
+ else
+ {
+ browser_window_create(urlfilename, gwin->bw, 0, true, true);
+ }
+
free(urlfilename);
- return;
- }
-
- if(file_box)
- {
- utf8_convert_ret ret;
- char *utf8_fn;
-
- if(utf8_from_local_encoding(filename,0,&utf8_fn) != UTF8_CONVERT_OK)
- {
- warn_user("NoMemory","");
- return;
- }
-
- free(file_box->gadget->value);
- file_box->gadget->value = utf8_fn;
-
- box_coords(file_box, (int *)&x, (int *)&y);
- ami_do_redraw_limits(gwin->bw->window,
- gwin->bw->window->shared->bw, x, y,
- x + file_box->width,
- y + file_box->height);
}
else
{
- Object *dto;
- STRPTR buffer;
- uint32 bufferlen;
-
- browser_window_mouse_click(gwin->bw, BROWSER_MOUSE_PRESS_1, x, y);
-
- if(dto = NewDTObject(filename,
- DTA_GroupID, GID_TEXT, TAG_DONE))
+ if(browser_window_drop_file_at_point(gwin->bw, x, y, filename) == false)
{
- if(GetDTAttrs(dto,
- TDTA_Buffer, &buffer,
- TDTA_BufferLen, &bufferlen,
- TAG_DONE))
+ urlfilename = path_to_url(filename);
+
+ if(i == 0)
{
- uint32 bufferlen2 = 256;
- int32 blen;
-
- blen = bufferlen;
-
- do
- {
- if(blen < 256) bufferlen2 = blen;
-
- if(utf8_from_local_encoding(buffer,
- bufferlen2,
- &utf8text) == UTF8_CONVERT_OK)
- {
- browser_window_paste_text(gwin->bw,
- utf8text, strlen(utf8text),
- (blen <= 256) ? true : false);
- free(utf8text);
- }
- buffer += 256;
- blen -= 256;
- }while(blen > 0);
+ browser_window_go(gwin->bw, urlfilename, NULL, true);
+ ActivateWindow(gwin->win);
}
- DisposeDTObject(dto);
+ else
+ {
+ browser_window_create(urlfilename, gwin->bw, 0, true, true);
+ }
+ free(urlfilename);
}
}
+ FreeVec(filename);
}
- FreeVec(filename);
}
}
}
@@ -2745,13 +2665,13 @@
CHILD_WeightedHeight,0,
LAYOUT_AddChild, gwin->shared->objects[GID_URL] =
NewObject(urlStringClass, NULL,
- STRINGA_MaxChars, 2000,
- GA_ID, GID_URL,
- GA_RelVerify, TRUE,
- GA_HintInfo, gwin->shared->helphints[GID_URL],
- GA_TabCycle, TRUE,
- STRINGA_Buffer, gwin->shared->svbuffer,
- STRINGVIEW_Header, URLHistory_GetList(),
+ STRINGA_MaxChars, 2000,
+ GA_ID, GID_URL,
+ GA_RelVerify, TRUE,
+ GA_HintInfo, gwin->shared->helphints[GID_URL],
+ GA_TabCycle, TRUE,
+ STRINGA_Buffer, gwin->shared->svbuffer,
+ STRINGVIEW_Header, URLHistory_GetList(),
StringEnd,
// GA_ID, GID_TOOLBARLAYOUT,
@@ -3915,7 +3835,7 @@
{
wheel = (struct IntuiWheelData *)msg->IAddress;
- if(ami_mouse_to_ns_coords(gwin, &x, &y) == true)
+ if(ami_mouse_to_ns_coords(gwin, &x, &y, -1, -1) == true)
{
if(browser_window_scroll_at_point(gwin->bw, x, y,
wheel->WheelX * 50, wheel->WheelY * 50) == false)
11 years, 6 months
r13217 tlsa - /trunk/netsurf/render/html.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 1 17:52:45 2011
New Revision: 13217
URL: http://source.netsurf-browser.org?rev=13217&view=rev
Log:
Pass drops into iframes.
Modified:
trunk/netsurf/render/html.c
Modified: trunk/netsurf/render/html.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/html.c?rev=13217&r...
==============================================================================
--- trunk/netsurf/render/html.c (original)
+++ trunk/netsurf/render/html.c Thu Dec 1 17:52:45 2011
@@ -2350,6 +2350,10 @@
CSS_VISIBILITY_HIDDEN)
continue;
+ if (box->iframe)
+ return browser_window_drop_file_at_point(box->iframe,
+ x - box_x, y - box_y, file);
+
if (box->gadget) {
switch (box->gadget->type) {
case GADGET_FILE:
@@ -2393,7 +2397,10 @@
file_box->gadget->value = utf8_fn;
/* Redraw box. */
- html_redraw_a_box(containing_content, file_box);
+ if (containing_content == NULL)
+ html__redraw_a_box(c, file_box);
+ else
+ html_redraw_a_box(containing_content, file_box);
} else if (html->bw != NULL) {
/* File dropped on text input */
@@ -2404,6 +2411,7 @@
char *utf8_buff;
utf8_convert_ret ret;
unsigned int size;
+ struct browser_window *bw;
/* Open file */
fp = fopen(file, "rb");
@@ -2462,8 +2470,10 @@
browser_window_mouse_click(html->bw,
BROWSER_MOUSE_PRESS_1, x, y);
+ bw = browser_window_get_root(html->bw);
+
/* Paste the file as text */
- browser_window_paste_text(html->bw, utf8_buff, size, true);
+ browser_window_paste_text(bw, utf8_buff, size, true);
free(utf8_buff);
}
11 years, 6 months
r13216 tlsa - /trunk/netsurf/riscos/window.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 1 17:51:37 2011
New Revision: 13216
URL: http://source.netsurf-browser.org?rev=13216&view=rev
Log:
Use core handling of file drop over browser window.
Modified:
trunk/netsurf/riscos/window.c
Modified: trunk/netsurf/riscos/window.c
URL: http://source.netsurf-browser.org/trunk/netsurf/riscos/window.c?rev=13216...
==============================================================================
--- trunk/netsurf/riscos/window.c (original)
+++ trunk/netsurf/riscos/window.c Thu Dec 1 17:51:37 2011
@@ -3060,20 +3060,8 @@
bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message)
{
- struct box *box;
- struct box *file_box = 0;
- struct box *text_box = 0;
- struct browser_window *bw = g->bw;
- hlcache_handle *h;
- int box_x, box_y;
os_error *error;
os_coord pos;
-
- h = bw->current_content;
-
- /* HTML content only. */
- if (!bw->current_content || content_get_type(h) != CONTENT_HTML)
- return false;
/* Ignore directories etc. */
if (0x1000 <= message->data.data_xfer.file_type)
@@ -3083,77 +3071,9 @@
message->data.data_xfer.pos.y, &pos))
return false;
- box = html_get_box_tree(h);
-
- /* Consider the margins of the html page now */
- box_x = box->margin[LEFT];
- box_y = box->margin[TOP];
-
- while ((box = box_at_point(box, pos.x, pos.y, &box_x, &box_y, &h))) {
- if (box->style && css_computed_visibility(box->style) ==
- CSS_VISIBILITY_HIDDEN)
- continue;
-
- if (box->gadget) {
- switch (box->gadget->type) {
- case GADGET_FILE:
- file_box = box;
- break;
-
- case GADGET_TEXTBOX:
- case GADGET_TEXTAREA:
- case GADGET_PASSWORD:
- text_box = box;
- break;
-
- default: /* appease compiler */
- break;
- }
- }
- }
-
- if (!file_box && !text_box)
+ if (browser_window_drop_file_at_point(g->bw, pos.x, pos.y,
+ message->data.data_xfer.file_name) == false)
return false;
-
- if (file_box) {
- utf8_convert_ret ret;
- char *utf8_fn;
-
- ret = utf8_from_local_encoding(
- message->data.data_xfer.file_name, 0,
- &utf8_fn);
- if (ret != UTF8_CONVERT_OK) {
- /* A bad encoding should never happen */
- assert(ret != UTF8_CONVERT_BADENC);
- LOG(("utf8_from_local_encoding failed"));
- /* Load was for us - just no memory */
- return true;
- }
-
- /* Found: update form input. */
- free(file_box->gadget->value);
- file_box->gadget->value = utf8_fn;
-
- /* Redraw box. */
- box_coords(file_box, &pos.x, &pos.y);
-
- error = xwimp_force_redraw(bw->window->window,
- pos.x * 2, -(pos.y + file_box->height) * 2,
- (pos.x + file_box->width) * 2, -pos.y * 2);
- if (error) {
- LOG(("xwimp_force_redraw: 0x%x: %s",
- error->errnum, error->errmess));
- warn_user("WimpError", error->errmess);
- }
- } else {
-
- const char *filename = message->data.data_xfer.file_name;
-
- browser_window_mouse_click(g->bw, BROWSER_MOUSE_PRESS_1, pos.x, pos.y);
-
- if (!ro_gui_window_import_text(g, filename, false))
- return true; /* it was for us, it just didn't work! */
- }
/* send DataLoadAck */
message->action = message_DATA_LOAD_ACK;
11 years, 6 months
r13215 tlsa - in /trunk/netsurf/desktop: browser.c browser.h
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 1 15:51:04 2011
New Revision: 13215
URL: http://source.netsurf-browser.org?rev=13215&view=rev
Log:
Currently untested (and unused) "drop file on browser window" handling.
Modified:
trunk/netsurf/desktop/browser.c
trunk/netsurf/desktop/browser.h
Modified: trunk/netsurf/desktop/browser.c
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/browser.c?rev=132...
==============================================================================
--- trunk/netsurf/desktop/browser.c (original)
+++ trunk/netsurf/desktop/browser.c Thu Dec 1 15:51:04 2011
@@ -573,6 +573,43 @@
}
return handled_scroll;
+}
+
+/* exported interface, documented in browser.h */
+bool browser_window_drop_file_at_point(struct browser_window *bw,
+ int x, int y, char *file)
+{
+ assert(bw != NULL);
+
+ if (bw->children) {
+ /* Browser window has children, so pass request on to
+ * appropriate child */
+ struct browser_window *bwc;
+ int cur_child;
+ int children = bw->rows * bw->cols;
+
+ /* Loop through all children of bw */
+ for (cur_child = 0; cur_child < children; cur_child++) {
+ /* Set current child */
+ bwc = &bw->children[cur_child];
+
+ /* Skip this frame if (x, y) coord lies outside */
+ if (x < bwc->x || bwc->x + bwc->width < x ||
+ y < bwc->y || bwc->y + bwc->height < y)
+ continue;
+
+ /* Pass request into this child */
+ return browser_window_drop_file_at_point(bwc,
+ (x - bwc->x), (y - bwc->y), file);
+ }
+ }
+
+ /* Pass file drop on to any content */
+ if (bw->current_content != NULL)
+ return content_drop_file_at_point(bw->current_content,
+ x, y, file);
+
+ return false;
}
Modified: trunk/netsurf/desktop/browser.h
URL: http://source.netsurf-browser.org/trunk/netsurf/desktop/browser.h?rev=132...
==============================================================================
--- trunk/netsurf/desktop/browser.h (original)
+++ trunk/netsurf/desktop/browser.h Thu Dec 1 15:51:04 2011
@@ -264,6 +264,18 @@
bool browser_window_scroll_at_point(struct browser_window *bw,
int x, int y, int scrx, int scry);
+/**
+ * Drop a file onto a browser window at a particular point.
+ *
+ * \param bw browser window to look inside
+ * \param x x-coordinate of point of interest
+ * \param y y-coordinate of point of interest
+ * \param file path to file to be dropped
+ * \return true iff file drop has been handled
+ */
+bool browser_window_drop_file_at_point(struct browser_window *bw,
+ int x, int y, char *file);
+
void browser_window_refresh_url_bar(struct browser_window *bw, nsurl *url,
lwc_string *frag);
11 years, 6 months
r13214 tlsa - in /trunk/netsurf: content/content.c content/content.h content/content_protected.h render/html.c
by netsurf@semichrome.net
Author: tlsa
Date: Thu Dec 1 15:49:57 2011
New Revision: 13214
URL: http://source.netsurf-browser.org?rev=13214&view=rev
Log:
Currently untested (and unused) "drop file on content" handling, and HTML implementation.
Modified:
trunk/netsurf/content/content.c
trunk/netsurf/content/content.h
trunk/netsurf/content/content_protected.h
trunk/netsurf/render/html.c
Modified: trunk/netsurf/content/content.c
URL: http://source.netsurf-browser.org/trunk/netsurf/content/content.c?rev=132...
==============================================================================
--- trunk/netsurf/content/content.c (original)
+++ trunk/netsurf/content/content.c Thu Dec 1 15:49:57 2011
@@ -746,6 +746,19 @@
}
+bool content_drop_file_at_point(struct hlcache_handle *h,
+ int x, int y, char *file)
+{
+ struct content *c = hlcache_handle_get_content(h);
+ assert(c != 0);
+
+ if (c->handler->drop_file_at_point != NULL)
+ return c->handler->drop_file_at_point(c, x, y, file);
+
+ return false;
+}
+
+
void content_add_error(struct content *c, const char *token,
unsigned int line)
{
Modified: trunk/netsurf/content/content.h
URL: http://source.netsurf-browser.org/trunk/netsurf/content/content.h?rev=132...
==============================================================================
--- trunk/netsurf/content/content.h (original)
+++ trunk/netsurf/content/content.h Thu Dec 1 15:49:57 2011
@@ -177,6 +177,8 @@
int x, int y, struct contextual_content *data);
bool content_scroll_at_point(struct hlcache_handle *h,
int x, int y, int scrx, int scry);
+bool content_drop_file_at_point(struct hlcache_handle *h,
+ int x, int y, char *file);
struct content_rfc5988_link *content_find_rfc5988_link(struct hlcache_handle *c,
lwc_string *rel);
Modified: trunk/netsurf/content/content_protected.h
URL: http://source.netsurf-browser.org/trunk/netsurf/content/content_protected...
==============================================================================
--- trunk/netsurf/content/content_protected.h (original)
+++ trunk/netsurf/content/content_protected.h Thu Dec 1 15:49:57 2011
@@ -71,6 +71,8 @@
struct contextual_content *data);
bool (*scroll_at_point)(struct content *c, int x, int y,
int scrx, int scry);
+ bool (*drop_file_at_point)(struct content *c, int x, int y,
+ char *file);
nserror (*clone)(const struct content *old, struct content **newc);
bool (*matches_quirks)(const struct content *c, bool quirks);
content_type (*type)(void);
Modified: trunk/netsurf/render/html.c
URL: http://source.netsurf-browser.org/trunk/netsurf/render/html.c?rev=13214&r...
==============================================================================
--- trunk/netsurf/render/html.c (original)
+++ trunk/netsurf/render/html.c Thu Dec 1 15:49:57 2011
@@ -49,6 +49,7 @@
#include "utils/schedule.h"
#include "utils/talloc.h"
#include "utils/url.h"
+#include "utils/utf8.h"
#include "utils/utils.h"
#define CHUNK 4096
@@ -81,6 +82,8 @@
int x, int y, struct contextual_content *data);
static bool html_scroll_at_point(struct content *c,
int x, int y, int scrx, int scry);
+static bool html_drop_file_at_point(struct content *c,
+ int x, int y, char *file);
struct search_context *html_get_search(struct content *c);
static nserror html_clone(const struct content *old, struct content **newc);
static content_type html_content_type(void);
@@ -128,6 +131,7 @@
.get_selection = html_get_selection,
.get_contextual_content = html_get_contextual_content,
.scroll_at_point = html_scroll_at_point,
+ .drop_file_at_point = html_drop_file_at_point,
.clone = html_clone,
.type = html_content_type,
.no_share = true,
@@ -2318,6 +2322,157 @@
/**
+ * Drop a file onto a content at a particular point.
+ *
+ * \param c html content to look inside
+ * \param x x-coordinate of point of interest
+ * \param y y-coordinate of point of interest
+ * \param file path to file to be dropped
+ * \return true iff file drop has been handled
+ */
+bool html_drop_file_at_point(struct content *c, int x, int y, char *file)
+{
+ html_content *html = (html_content *) c;
+
+ struct box *box = html->layout;
+ struct box *next;
+ struct box *file_box = NULL;
+ struct box *text_box = NULL;
+ int box_x = 0, box_y = 0;
+ hlcache_handle *containing_content = NULL;
+
+ /* Scan box tree for boxes that can handle drop */
+ while ((next = box_at_point(box, x, y, &box_x, &box_y,
+ &containing_content)) != NULL) {
+ box = next;
+
+ if (box->style && css_computed_visibility(box->style) ==
+ CSS_VISIBILITY_HIDDEN)
+ continue;
+
+ if (box->gadget) {
+ switch (box->gadget->type) {
+ case GADGET_FILE:
+ file_box = box;
+ break;
+
+ case GADGET_TEXTBOX:
+ case GADGET_TEXTAREA:
+ case GADGET_PASSWORD:
+ text_box = box;
+ break;
+
+ default: /* appease compiler */
+ break;
+ }
+ }
+ }
+
+ if (!file_box && !text_box)
+ /* No box capable of handling drop */
+ return false;
+
+ /* Handle the drop */
+ if (file_box) {
+ /* File dropped on file input */
+ utf8_convert_ret ret;
+ char *utf8_fn;
+
+ ret = utf8_from_local_encoding(file, 0,
+ &utf8_fn);
+ if (ret != UTF8_CONVERT_OK) {
+ /* A bad encoding should never happen */
+ assert(ret != UTF8_CONVERT_BADENC);
+ LOG(("utf8_from_local_encoding failed"));
+ /* Load was for us - just no memory */
+ return true;
+ }
+
+ /* Found: update form input */
+ free(file_box->gadget->value);
+ file_box->gadget->value = utf8_fn;
+
+ /* Redraw box. */
+ html_redraw_a_box(containing_content, file_box);
+
+ } else if (html->bw != NULL) {
+ /* File dropped on text input */
+
+ size_t file_len;
+ FILE *fp = NULL;
+ char *buffer;
+ char *utf8_buff;
+ utf8_convert_ret ret;
+ unsigned int size;
+
+ /* Open file */
+ fp = fopen(file, "rb");
+ if (fp == NULL) {
+ /* Couldn't open file, but drop was for us */
+ return true;
+ }
+
+ /* Get filesize */
+ fseek(fp, 0, SEEK_END);
+ file_len = ftell(fp);
+ fseek(fp, 0, SEEK_SET);
+
+ /* Allocate buffer for file data */
+ buffer = malloc(file_len + 1);
+ if (buffer == NULL) {
+ /* No memory, but drop was for us */
+ fclose(fp);
+ return true;
+ }
+
+ /* Stick file into buffer */
+ if (file_len != fread(buffer, 1, file_len, fp)) {
+ /* Failed, but drop was for us */
+ free(buffer);
+ fclose(fp);
+ return true;
+ }
+
+ /* Done with file */
+ fclose(fp);
+
+ /* Ensure buffer's string termination */
+ buffer[file_len] = '\0';
+
+ /* TODO: Sniff for text? */
+
+ /* Convert to UTF-8 */
+ ret = utf8_from_local_encoding(buffer, file_len, &utf8_buff);
+ if (ret != UTF8_CONVERT_OK) {
+ /* bad encoding shouldn't happen */
+ assert(ret != UTF8_CONVERT_BADENC);
+ LOG(("utf8_from_local_encoding failed"));
+ free(buffer);
+ warn_user("NoMemory", NULL);
+ return true;
+ }
+
+ /* Done with buffer */
+ free(buffer);
+
+ /* Get new length */
+ size = strlen(utf8_buff);
+
+ /* Simulate a click over the input box, to place caret */
+ browser_window_mouse_click(html->bw,
+ BROWSER_MOUSE_PRESS_1, x, y);
+
+ /* Paste the file as text */
+ browser_window_paste_text(html->bw, utf8_buff, size, true);
+
+ free(utf8_buff);
+ }
+
+ return true;
+}
+
+
+/**
* Set an HTML content's search context
*
* \param c content of type html
11 years, 6 months