Commit Graph
102 Commits
Author SHA1 Message Date
John O'Keefe 914ade8a79 Custom touch selection: own the gesture, clamp to the page
Chromium's native touch selection cannot be used in the columned
layout: quick taps select words, the word iterator re-anchors at
page boundaries (jumping to other pages), and the browser
auto-scrolls the container when selections cross pages.
preventDefault on touchstart disables it; long-press selects the
word under the finger, drag extends word by word clamped to the
visible page, and pan/snap stand down while a selection gesture is
active. Native rendering still paints the selection.
2026-09-15 08:54:56 -04:00
John O'Keefe 9cfe266929 Ignore small height-only viewport resizes
Mobile browser toolbar transitions change the viewport height by a
fraction mid-gesture; re-rendering for them re-wraps the whole book
and reads as a page refresh. Re-render only for width changes or
height changes of 25% or more.
2026-09-14 19:45:50 -04:00
John O'Keefe ea34de5bf5 Revert experimental touch selection work back to the minimal auto-paging gate
The custom gesture system and the selection clamp/repair chain
replaced browser behavior with worse approximations. Keep only the
non-touch gate on selection auto-paging (de70103), which fixes
drag-selecting paging away mid-gesture; everything else returns to
upstream behavior.
2026-09-14 08:44:26 -04:00
John O'Keefe 28f1e78855 Replace native touch selection with a custom gesture
Chrome's native touch selection misbehaves in the paginated column
layout: quick taps select words, and dragging from a line-start word
re-anchors at a rendered line break, dropping the word and freezing
the gesture. preventDefault on touchstart disables it entirely; a
long-press timer selects the word under the finger instead and drag
moves extend word by word, clamped to the visible page and identical
for every word. Clean taps clear the selection or follow links
(click events being suppressed by the preventDefault).
2026-09-14 08:08:48 -04:00
John O'Keefe 4cae16013e Repair the anchor word only from the stability-gated deferred path
A selection write at the moment Chrome re-anchors the drag detaches
its touch selection controller; the same writes on a settled
selection are fine. Record the word synchronously, repair only when
the selection has been unchanged for 150ms.
2026-09-13 20:25:40 -04:00
John O'Keefe 1bd7e52417 Repair backward word clipping with extend, not setBaseAndExtent
Rewriting both selection boundaries mid-gesture detaches Chrome's
touch selection controller and the selection stops following the
finger. extend() moves only the focus, which the controller
tolerates.
2026-09-13 20:19:26 -04:00
John O'Keefe 3fcfc30bd0 Keep the long-pressed word covered when Chrome re-anchors a touch drag
Dragging just past a line-start word makes Chrome flip the touch
selection and re-anchor it at a rendered line break, silently
dropping the long-pressed word from the selection. Record the word
at the initial long-press and restore its start boundary whenever
the selection no longer covers it.
2026-09-13 20:16:10 -04:00
John O'Keefe 800fb2fa02 Fix inverted probe collapse in the touch selection clamp 2026-09-13 18:32:58 -04:00
John O'Keefe cae618ac87 Fix selectionIsBackward for iframe selections
The helper created its probe range in the module's own document
(the host, in the bundled web reader), so boundary points in the
content iframe collapsed the range and every selection read as
backward.
2026-09-13 18:30:09 -04:00
John O'Keefe 2e392e80d3 Retry the touch selection clamp after the gesture ends 2026-09-13 18:26:47 -04:00
John O'Keefe 5102fc70dd Clamp by geometry, not the visible range
The last visible range can extend past the visible column on text
nodes that span multiple columns (its end-offset bisect uses union
rects), so comparing DOM boundary points against it misses off-view
selection endpoints. Test the endpoint caret rect against the
visible column bounds instead.
2026-09-13 18:23:52 -04:00
John O'Keefe 2a54b52fdb Keep touchSelecting armed through collapsed selectionchange events
Chrome emits collapsed selectionchange events while the long-press
word selection is being set up; clearing the flag on them disarmed
the clamp before the selection ever became a Range.
2026-09-13 18:18:03 -04:00
John O'Keefe 8ac36efbda Fix clamp coordinates: caretRangeFromPoint needs content-space bounds 2026-09-13 18:14:25 -04:00
John O'Keefe e1fa4698c6 Clamp touch selection endpoints to the visible page
Chrome word-snapping during a touch selection drag can map the
endpoint past the visible column into the next (off-screen) page,
selecting the entire visible page at once. Re-map the endpoint via
caretRangeFromPoint at the same line height inside the visible
column whenever it lands outside the last visible range.
2026-09-13 18:07:36 -04:00
John O'Keefe de70103651 Fix touch selection paging away mid-drag: gate selection auto-paging to non-touch pointers 2026-09-13 17:18:47 -04:00
Huang Xin 9fd2209b4d Fix blocked animate when running in background (#80) 2025-08-01 23:43:27 +00:00
Protected 55f1a28406 Prevent exception on Firefox due to getSelection returning null (#57) 2025-05-13 12:49:18 +00:00
John Factotum 052123beaf Add an EventTarget for transforming the book
And use it to do paginator-specific CSS replacements.

And use it to catch loading errors in reader.js.

Fixes #14
Closes #18
2025-03-29 15:09:23 +08:00
Ray-D-Song e2014ee753 Fix selection handling in Paginator component (#46) 2025-02-13 07:52:19 +00:00
John Factotum 63a5dbf3e3 Don't scroll to anchor if caret's moved by pointer
In Safari, clicking on links triggers `selectionchange`. Since we do not
move the caret when flipping through pages, when you have flipped to the
next or previous pages and click on any link, it would take you back to
the caret instead of activating the link.

Note that the bug occurs in Safari 17 but not in WebKitGTK 2.46.

Not sure if there's a way to fix this and still retain the "set anchor
to caret on click" behavior. But I guess this behavior isn't really that
essential, anyway. So removing it for now.

Fixes #44
2024-12-12 09:35:33 +08:00
John Factotum bf9adef636 Paginator: react to selection only on input 2024-09-30 19:00:11 +08:00
John Factotum dcd4ff403e Paginator: fix scrolling to collapsed ranges that contain elements 2024-09-25 22:41:20 +08:00
John Factotum 02a24ea25c Grammar 2024-09-25 22:33:02 +08:00
John Factotum 59a5aa22a0 Paginator: respond to selection change
The view follows caret when using caret browsing (F7). Also allows
selecting across pages. And if you click on or select some text and
resize the window, the caret/selection always stays visible.

Some quirks regarding caret browsing:
- In Chromium, in paginated mode, it scrolls when changing selection
  (https://issues.chromium.org/issues/40889650)
- In WebKitGTK, in scrolled mode, the view doesn't follow the caret
  (which would be a WebKit bug)
2024-09-24 11:54:47 +08:00
John Factotum 329e22227a Paginator: fix offset
What's `margin` doing here?! It's like this since the first commit, but
it makes no sense... I think I added it incorrectly, being misled by
the getBoundingClientRect bug in Firefox...
2024-09-24 11:36:43 +08:00
John Factotum 59bb647057 Paginator: fix visible range in Firefox 2024-09-24 11:34:57 +08:00
John Factotum 4ef87c2ca7 Paginator: fix caret position when navigating
The effect of this is more obvious if you enable caret browsing (F7 in
all browsers). Previously, if you go to a fragment, the caret isn't
moved. Now it works as expected.
2024-09-23 20:33:46 +08:00
John Factotum b8a0d11910 Paginator: fix changing background in Chromium 2024-09-23 16:48:11 +08:00
John Factotum e6937eed15 Paginator: fix focus lost when loading new section
Also add method for setting focus on the content window
2024-09-15 13:13:44 +08:00
John Factotum c17b542b5c Paginator: needn't fix tabbing in scrolled mode 2024-09-14 23:18:27 +08:00
John Factotum 3b96ddf3e6 Paginator: fix scroll offset when tabbing 2024-09-14 23:14:04 +08:00
John Factotum 327031aca1 Paginator: add scroll event
Unlike `relocate`, which is debounced, a scroll event is useful when you
want to do stuff as soon as it scrolls.
2024-09-12 05:30:58 +08:00
John Factotum 92964699af Paginator: make grid columns follow text block
This is a purely internal change, but it might make things easier in the
future if one wants to place stuff on the margins (e.g. to fade the edge
of the iframe when animating, or place prev/next buttons on the sides)
2024-06-22 18:34:19 +08:00
John Factotum b7ff640943 Paginator: prevent spread in portrait
Or, for vertical writing, in landscape
2024-04-27 16:14:36 +08:00
John Factotum b45e08b10b Paginator: fix unnecessary wrapping in tables
Fixes https://github.com/johnfactotum/foliate/issues/1278
2024-03-25 05:52:49 +08:00
John Factotum b0d7ed481f Paginator: destroy view before removing it 2024-03-23 12:12:39 +08:00
John Factotum 18159a4d07 Don't check document's existence when expanding
`expand()` is only called after `render()`, which assumes that it exists
2024-03-21 20:22:31 +08:00
John Factotum b0a869b7ed Fix page end cut off when starting with page break
Fixes https://github.com/johnfactotum/foliate/issues/1179
2024-03-20 08:44:47 +08:00
John Factotum cbe9e0009c Make animation setting an attribute instead of a property 2023-11-28 11:07:56 +08:00
John Factotum 2ea63929c7 Fix broken layout when book has !important styles 2023-11-15 04:33:02 +08:00
John Factotum 05329eba6e Fix viewer background not updated when page background changes
Bit of a band-aid fix. Ideally it should have some sort of
"ComputedStyleObserver" but this should fix the most common problem
for now.
2023-10-27 15:13:54 +08:00
John Factotum ecefeb86e1 TTS: split document into ranges of block elements 2023-10-01 01:18:43 +08:00
John Factotum 3833ce5702 Paginator: make scrollToAnchor() public 2023-09-27 02:15:09 +08:00
John Factotum ad25f6b5c3 Paginator: fix anchoring in scrolled mode
Anchoring triggers the `scroll` event, which in scrolled mode causes
`#afterScroll()` to be called again with the reason `scroll`, which
shouldn't happen as it's just anchoring, not scrolling.
2023-08-26 06:32:32 +08:00
John Factotum df95960f82 Expose relocation reason
And fix history not updated when scrolling in scroll mode
2023-08-17 15:18:20 +08:00
John Factotum 44c5eca4e9 Paginator: add scroll amount option 2023-08-11 08:14:30 +08:00
John Factotum 5261c48a90 Paginator: account for margin when getting visible area in scrolled mode
Follows 17fb71943f
2023-06-03 01:26:35 +08:00
John Factotum 4732a23e17 Paginator: allow touchscreen pinch zoom 2023-06-02 22:01:36 +08:00
John Factotum 481d28cced Clamp divisor
Although the max width is min-inline-size * max-column-count, sometimes
the actual width apparently doesn't match that exactly.
2023-06-02 04:45:34 +08:00
John Factotum 2e5dda77e0 Unload section when destroying the renderer 2023-06-01 01:44:00 +08:00