Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webkit2 page source view #361

Closed
rti opened this issue Apr 11, 2017 · 25 comments
Closed

Webkit2 page source view #361

rti opened this issue Apr 11, 2017 · 25 comments

Comments

@rti
Copy link
Contributor

rti commented Apr 11, 2017

webkit2 does not provide the view mode source so maybe this is going to be removed together with the gf keybinding or we find a simple workaround for this

@fanglingsu fanglingsu modified the milestone: Version 3: Migration to webkit2 Apr 11, 2017
@fanglingsu fanglingsu removed this from the Version 3: Migration to webkit2 milestone Jun 21, 2017
@stale
Copy link

stale bot commented Oct 2, 2018

This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 2, 2018
@stale
Copy link

stale bot commented Oct 9, 2018

This issue has been automatically closed because it has not had activity since it was marked as stale. Thank you for your contributions.

@stale stale bot closed this as completed Oct 9, 2018
@fanglingsu
Copy link
Owner

There is now a possible solution to show the source by changing the HTML via JavaScript from within vimb on the mailing list https://sourceforge.net/p/vimb/vimb/message/36441932/.

@fanglingsu fanglingsu reopened this Oct 16, 2018
@stale stale bot removed the stale label Oct 16, 2018
@iamleot
Copy link
Contributor

iamleot commented Oct 16, 2018 via email

@fanglingsu
Copy link
Owner

@iamleot There is not much traffic on the ML and I announce only new releases. Most of the communication is done via github. So maybe your mail will change this.

I liked the gf too and in fact it both, the weninspector and the source view where different. The webinspector shows the actual dom like it is parsed by webkit. This reflects also DOM-changes made by JavaScript and possibly by webkit. The source view showed the content like it arrived from webserver.
What do you think about fetching the sites html and to show it in the editor (set editor-command could be reused). So highlighting the source would be done by the editor. One drawback of this would be that the html is not indented but I think we can accept this.

@iamleot
Copy link
Contributor

iamleot commented Oct 17, 2018 via email

@fanglingsu
Copy link
Owner

@iamleot I haven't seen a patch for surf that allows to show the source in editor. But spawning external tools is the way suckless goes.
Feel free to work on this feature.

@iamleot
Copy link
Contributor

iamleot commented Oct 17, 2018

normal_view_support.txt

Sure!

Here it is an initial and experimental version of it! Please note that most of the
code/logic was stolen from input_open_editor() (but I'm not sure if it's easy
to refactor both in order to share common code). Feedback/testing/comments
are welcomed, and of course feel free to ping me when you think it can be ready
to be shared as a pull request!

Thank you!

@fanglingsu
Copy link
Owner

@iamleot It would be nice if we can avoid doubling the code.
Maybe we can extract the common logic of both into a new function. I've used to write functions that are used from multiple modes in src/command.c. I think this function needs to get the content to show as string and optionally a callback similar to (GChildWatchFunc) and the data that are given to the callback.

gboolean command_spawn_editor(Client *c, const Arg *arg, GChildWatchFunc
callback, gpointer data)
{
    /* Check if editor-command is set */
    /* Write string arg->s to new temp file */
    /* spawn editor-command async */
    /* watch the child with own callback e.g. resume_editor (src/command.c) 
     * The given callback and data must be given in the data for the cild
     * watcher. */
}

static void resume_editor(GPid pid, int status, EditorData *data)
{
    /* Read the contents from the file */
    /* Call the callback out of editor data (Client* c, gpointer) */
    /* Free memory of the file contents */
    /* unlink the temporary file */
}

This is only my first thought about the way we could do it and it might be a
little more complicated in real. The input_open_editor needs to get the
form field value and give it to command_spawn_editor(). If this succeeds
the form field should be disabled. The callback mus be adapted, because this
will get the file contents instead of the current editor data.

@iamleot
Copy link
Contributor

iamleot commented Oct 18, 2018 via email

@fanglingsu
Copy link
Owner

@iamleot That the parameter of both functions are named data is a little bit misleading. The command_spawn_editor data parameter is untouched and this function does not need to know what it is. The data parameter of resume_editor is a new structure that needs to be known to only these two functions. This structure holds the file path (to remove the file), the callback and the gpointer that were given to command_spawn_editor (to call the use case specific callback - do nothing in case of the source view or put the text into the form field in case of the existing form field editing).

@iamleot
Copy link
Contributor

iamleot commented Oct 18, 2018 via email

@fanglingsu
Copy link
Owner

@iamleot I think it would be easier when you do this in a separate branch. So we can discuss and comment on single lines or commits.

I thought of adding a resume function to src/command.c too which is responsible to g_spawn_close() the pid and unlinking the temporary file. But bevore that, this function should read the file contents and give them to the original callback (but only if a callback was given). So the callbacks do not need to know if the data came from a file or where the file is located. So the EditorData struct can be moved out of main.h into command.c because this is only used by the two function in command.c.
So we need some typedef for the callback in main.h. I think we need at least the contents of the file (must be freed in the callback after use) and the Client.

@iamleot
Copy link
Contributor

iamleot commented Oct 19, 2018 via email

@iamleot
Copy link
Contributor

iamleot commented Oct 19, 2018

I have committed and pushed in view_source_support branch (and, it
contains also further clean ups compared to the patch previously shared here).

Any comments/reviews are welcomed!

@iamleot
Copy link
Contributor

iamleot commented Oct 19, 2018

I thought of adding a resume function to src/command.c too which is responsible to g_spawn_close() the pid and unlinking the temporary file. But bevore that, this function should read the file contents and give them to the original callback (but only if a callback was given). So the callbacks do not need to know if the data came from a file or where the file is located. So the EditorData struct can be moved out of main.h into command.c because this is only used by the two function in command.c.
So we need some typedef for the callback in main.h. I think we need at least the contents of the file (must be freed in the callback after use) and the Client.

Regarding a resume function to src/command.c, IMHO at least at the moment it is not worth the effort and probably will not ease any reusability of the code. The "cleanup" (g_free() and similar) of resume_editor() function are just 2-3 LOCs and resume_editor() function are already pretty customised in the context where they are used.

@fanglingsu
Copy link
Owner

@iamleot I did not though in LOC for the resume functions but in responsibilities. The caller od the edior command does not know anything about a file and can therefore not be responsible for unlinking it. So we don't add a global structure to provide internals that are only used in src/command.c.
We can't expect each caller to implement a resume function to unlink the file and free some memory and do some child close pid stuff.

@iamleot
Copy link
Contributor

iamleot commented Oct 19, 2018 via email

@fanglingsu
Copy link
Owner

@iamleot I've added what I've already written into the commits. Hope this makes it easier to understand.
Thank you that you spent so much time contributing to vimb!

@iamleot
Copy link
Contributor

iamleot commented Oct 19, 2018 via email

@iamleot
Copy link
Contributor

iamleot commented Oct 21, 2018

I have readjusted normal_view_source() to directly retrieve the data via
webkit_web_resource_get_data() instead of injecting JavaScript and inspecting
the DOM. Now RSS/Atom feed sources can be seen as well via gf.

@iamleot
Copy link
Contributor

iamleot commented Oct 24, 2018

Hopefully I've addressed all comments and I think it is in a state to request a possible pull request.

If there are any further possible changes to do I would like to reorder a bit the commits and open a pull request.

@fanglingsu
Copy link
Owner

@iamleot It would be nice if you would squash commits together into some few commits. I don't think we need this many commits that fix indentation. Put together what belongs together.

@fanglingsu
Copy link
Owner

@iamleot Thank you very much for your work. This works fine!

@iamleot
Copy link
Contributor

iamleot commented Oct 25, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants