Simon Lydell [Thu, 28 Jan 2016 21:05:54 +0000 (22:05 +0100)]
Rework programmatic customization of VimFx
- The public API has been removed. While the idea of allowing other extensions
to extend VimFx is neat, I don't think it'll ever be used. KISS. As a
replacement, the config files have become more top-notch.
- The former public API is now the config file API.
- Config files are no longer regular add-ons. We used to provide a boilerplate
for such an add-on, which consisted of a bunch of files users most likely
wouldn't touch as well as `config.js` and `frame.js`. Now, the concept of
`config.js` and `frame.js` has been kept, but they are loaded directly, if the
path to their parent directory is given in the `config_file_directory` pref.
This is much easier and simpler, and does not require the user to install a
version of Firefox with the ability to install unsign add-ons (or having to go
through the hassle of actually signing the "config file add-on").
- `zr` reloads the config file(s). This is possible because of the above point
and is much nicer than having to restart Firefox every time you change your
config (or setting up something like the Extension Auto-Installer).
- `vimfx.send(...)` and `vimfx.listen(...)` have been added, to make it easier
to create custom commands that interact with web page content, which is quite
common. These are basically `messageManager.send` and `messageManager.listen`.
To make the API simpler, instead of passing the name of the callback message
to listeners and having to do `messageManager.send(callback, data)` to respond
to a message, a real callback _function_ is now passed instead, which does the
message sending behind the scenes. This also resulted in some nice code
cleanup overall.
- `vimfx.off(...)` has been added, to remove `vimfx.on(...)` listeners. This is
mostly used internally. Since `zr` allows reloading the config file,
everything in it must be undoable.
- By loading `frame.js` directly, it is now possible to pass a real API to it,
rather than relying on `VimFx*` properties on the global frame script object.
- The new, "real" frame script API now has tests. This involved adding support
for running tests in frame scripts.
Simon Lydell [Sat, 6 Feb 2016 16:52:18 +0000 (17:52 +0100)]
Improve and add more documentation
- Improved wording and consistency.
- Add short summaries of each section in the table of contents.
- Document how to install VimFx. Fixes #686.
- Document modes.
- Don't refer to the "Public API" anymore, but the "config file API". It is no
longer intended to be used by other add-ons. (The plan is to load config files
in a different way in the future.)
Simon Lydell [Sat, 6 Feb 2016 17:22:42 +0000 (18:22 +0100)]
Improve CONTRIBUTING.md
- Remove "Use English". That's understood since the bug template is in English.
- Put the instruction about bugs at the top.
- Make the paragraph about the changelog a bullet point. It makes the
instructions look shorter. Since the "Use English" bullet point was removed,
the list does not look too long either.
- Move the "Contributing code?" link off to the right to get it out of the way.
- Use fewer words in a few places. The less to read the better.
Also: Link to CONTRIBUTING.md instead of directly to the issue tracker in the
readme, to increase the chance of people actually reading it. Therefore a "Go to
the issue tracker" link was added in CONTRIBUTING.md (it goes to the issues
list, not a new issue, to increase the chance of people looking for duplicates).
Simon Lydell [Wed, 3 Feb 2016 17:11:33 +0000 (18:11 +0100)]
Make the `H` and `L` commands more reliable
It seems like using `window.BrowserBack()` and `window.BrowserForward()` are the
most reliable ways of navigating the history, rather than having to wait for
`SessionStore.getSessionHistory()` to finish and then going to a certain history
index. This commit optimizes the case where the count is 1 to use the mentioned
functions instead. Some extensions also override those, so calling them results
in better interoperability.
(Hopefully/Likely) fixes #687.
To keep the code changes simple, the support for Firefox < 43 was dropped.
That's fine, since Firefox 44 has already been released.
Simon Lydell [Tue, 26 Jan 2016 21:50:10 +0000 (22:50 +0100)]
Use async messaging in bootstrap.coffee
The initial message from new frame scripts is now async. This is possible since
commit bd00a85e0. Other than following the recommendation to avoid sync
messaging whenever possible, this fixes #679 and fixes #624.
Simon Lydell [Tue, 26 Jan 2016 18:41:38 +0000 (19:41 +0100)]
Use strings instead of functions in the `modes` object
Since we run things properly in the `startup()` function of bootstrap.js since
last commit, the `chrome://` URI to the string bundles is now available when the
`modes` object is constructed. This means that there's no need anymore to let
mode names, category names and command descriptions be functions. Instead they
can be the sane thing: Simply strings.
Note that this is a backwards incompatible change. Luckily it does not affect
the `.addCommand()` API method, so propably won't impact anyone.
Simon Lydell [Tue, 26 Jan 2016 18:15:05 +0000 (19:15 +0100)]
Use `chrome://` URIs for `require()` calls
Apparently, `chrome://` URIs registered in chrome.manifest cannot be used in
bootstrap.js until its `startup()` function is called. Therefore this commit
reorganizes the code of bootstrap.coffee a bit, so that actual work is done
inside `startup()` (where it is supposed to be, after all). Outside of that
function we now mostly simply declare variables that the `shutdown()` function
needs to access as well. Some things were moved into main.coffee as well.
- Using `chrome://` URIs is the way add-ons are "supposed" to do it.
- If a `require()` call fails, we now get much shorter URIs in the error
message, making things easier to debug.
- This allows to get rid of the hack of sending `__SCRIPT_URI_SPEC__` to frame
scripts.
Simon Lydell [Tue, 26 Jan 2016 07:31:39 +0000 (08:31 +0100)]
Improve CPU usage in Hints mode
Raising the "check for marker element movements" interval from 0 to 15 results
in no noticeable CPU usage change on my system, while still allowing markers to
move smoothly. Setting it to 20 results in noticeable stutter.
This commit also add the `hints_sleep` pref to control the interval, or disable
the feature altogether.
Additionally, the interval now doesn't run at all for the `zF` command.
Previously, it ran as usual, but didn't do anything (as marker movement isn't
supported (YAGNI) for the `zF` command).
The "real" tab elements are the rectangles to the left of the dotted vertical
lines. The triangle parts are made using the `::before` or `::after`
pseudo-elements of the tabs.
When calling `.elementFromPoint()` on a pseudo-element, its parent element is
returned. But calling `.getBoundingClientRect()` on the parent element returns a
rectangle only around the the parent element, excluding the pseudo-element.
Because of the pseudo-elements overlap the next tab, the second tab is
considered covered by the first tab.
Previously, a point to the right of the first tab would then be tried. But since
the pseudo-element isn't included in `.getBoundingClientRect()` that would mean
the point marked with a `+`, which is actually to the _left_ of the original
point, not to the right! That obviously didn't work.
With this commit, if the "try-right point" is to the left of the initial point
and the covering element and the queried element are in the same frame, the
point is tried again but this time forcing the element to be considered located
at that point, solving the issue.
Using pseudo-elements to create non-rectangular tabs is quite common, so this
will help on other sites as well.
Simon Lydell [Sun, 24 Jan 2016 09:22:55 +0000 (10:22 +0100)]
Remove check for 'close' class for clickable elements
It gave too many false positives because of the word 'closed' in many classes.
Instead of trying to switch to a regex to avoid those cases, I'm trying to
completely remove the check. Hopefully the other matching rules are enough.
Simon Lydell [Sat, 23 Jan 2016 18:31:37 +0000 (19:31 +0100)]
Remove hints and help on shutdown
Previously, if you disabled VimFx by using the `f` command to click VimFx's
"Disable" button in the Add-ons Manager, the hint markers would be left behind
(though losing their styling). This meant that the entire page would be covered
by a transparent element impossible to remove (other than closing the tab) and
impossible to click through.
A similar thing happened if you left the help dialog open in another tab while
disabling VimFx.
This commit makes sure that both those pieces of UI are removed on shutdown.
Simon Lydell [Thu, 21 Jan 2016 06:47:18 +0000 (07:47 +0100)]
Recognize more elements as clickable
- Elements with `data-` attributes used for clickable things by Bootstrap are
now recognized. This is a huge win since Bootstrap is very popular and many
developers use it with semantically unclickable elements (even though the
Bootstrap documentation always reminds of accessibility concerns). Since these
elements are or _should have been_ semantically clickable elements, they are
always treated as such, in order not to give them too bad hints.
- A few `aria-` attributes are now recognized as semantically clickable.
- ARIA roles are now treated as _semantically_ clickable, instead of just
clickable.
- "Close" buttons are now attempted to be recognized. This is useful for many of
those obtrusive EU cookie law notices. Recognizing Bootstrap elements also
helps greatly here.
- Finally, elements with 'click' event listeners (added using
`element.addEventListener('click', ...)`) are now recognized, by using a
Firefox API. This is really useful on DuckDuckGo's image search. Fixes #671
and fixes #672.
Note that event delegation is not supported, since that would require
inspecting the code of the event listeners. One _could_ inspect the global
`jQuery` object (if any) to get to solve that problem to a great extent (like
Firefox's devtools do), but I'm not sure if that's a good idea.
It should also be noted that I tried recognizing elements matching
`/\bjs-/.test(element.className)`, but that proved give too many false
positives.
Simon Lydell [Fri, 22 Jan 2016 06:40:01 +0000 (07:40 +0100)]
Never prevent autofocus in XUL pages
- Every time I go to `about:config` I wish that the filter field was focused.
- Even though `vim.markPageInteraction()` was called, the "click to go to
command" feature of the help dialog sometimes failed to autofocus the text
input for the command.
Thus, I think it's sensible to simply _not_ prevent autofocus in XUL pages. Such
pages are few and well-behaved (it seems).
Simon Lydell [Thu, 21 Jan 2016 16:34:04 +0000 (17:34 +0100)]
Improve autofocus prevention after `[` and `]`
When you go to the next page of GitHub’s code search results, the page is loaded
with AJAX. GitHub then annoyingly focuses its search input. This autofocus
cannot be prevented in a reliable way, because the case is indistinguishable
from a button whose job is to focus some text input. However, after the `[` and
`]` command we know for sure that we can prevent the next focus. This commit
resets the `vim.state.hasInteraction` flag in those commands to allow for this
behavior, by adding the `value=true` parameter to `vim.markPageInteraction()`
and passing in `false`.
Simon Lydell [Tue, 12 Jan 2016 08:13:55 +0000 (09:13 +0100)]
Fix misplaced hint markers when zoomed
Hint markers are supposed to be centered vertically on the non-covered point.
This didn't work properly when zoomed, but now does. For simplicity, that fix
removed the "make sure the marker stays within its element" constraint, which
turned out to be nice and more consistent. The hint markers are now _always_
centered vertically on the non-covered point, even for very small links.
This commit also fixes hint marker placement in the devtools when the devtools
have been independently zoomed. The above issue needed to be fixed before this
could be fixed. Fixes #667.
Simon Lydell [Mon, 11 Jan 2016 18:32:02 +0000 (19:32 +0100)]
Fix memory leak in non-multi-process Firefox
Apparently, 'overflow' and 'underflow' events in web page content can be caught
in UI listeners in non-multi-process. `event.target` of 'overflow' events in the
browser UI are saved as scrollable elements, which accidentaly included web page
elements as well. Holding on to such elements after their owner tab is closed
caused a memory leak (ghost windows). This commit checks that the overflown
elements really are UI elements before saving them.
Simon Lydell [Sat, 9 Jan 2016 16:39:07 +0000 (17:39 +0100)]
Fix `:hover` clearing on click in multi-process
Because clicks simulated by VimFx apparently cannot be caught in non-frame
listeners (which is good), _two_ real clicks were needed to clear `:hover`. This
commit fixes that, which allowed for a nice code cleanup. Instead, a temporary
hack is used for non-multi-process to make it work there.
Simon Lydell [Wed, 6 Jan 2016 13:22:25 +0000 (14:22 +0100)]
Lock `:hover` when clicking with the `f` commands
Fixes #388.
Note that this commit also adds `pointer-evets: none;` to the hints container,
allowing to generate hints for elements only visible because of the mouse
pointer hovering something. Getting hints for hover-menus opened by `zf` but not
for hover-menus opened by moving the mouse was too confusing. The reason
`pointer-events: none;` wasn’t added before was that it prevented from scrolling
while hints were shown. While that was nice, it was just an edge case that
doesn't really matter. It is better to allow hints for hover-menus.
Simon Lydell [Wed, 6 Jan 2016 09:40:50 +0000 (10:40 +0100)]
Improve element matching for the `zF` command
- Always exclude `<menuitem>`s. They are never clickable by VimFx. (This could
be seen in the Responsive Design View).
- Oddly, `<menuseparator>`s are considered focusable, but of course shouldn't
get hints. Now they don't anymore.
- Make sure that browser elements in the web page content area (such as in the
Responsive Design View) only show up when their containing tab is selected.