@gtkx/testing 1.0.0-rc.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/accessible-native.d.ts +16 -0
- package/dist/accessible-native.d.ts.map +1 -0
- package/dist/accessible-native.js +206 -0
- package/dist/accessible-native.js.map +1 -0
- package/dist/build-queries.d.ts +27 -10
- package/dist/build-queries.d.ts.map +1 -1
- package/dist/build-queries.js +22 -24
- package/dist/build-queries.js.map +1 -1
- package/dist/cleanup-registry.d.ts +1 -1
- package/dist/cleanup-registry.d.ts.map +1 -1
- package/dist/cleanup-registry.js.map +1 -1
- package/dist/errors.d.ts +10 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +10 -1
- package/dist/errors.js.map +1 -1
- package/dist/fire-event.d.ts +35 -6
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +23 -7
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts +2 -1
- package/dist/frame-sync.d.ts.map +1 -1
- package/dist/frame-sync.js +15 -5
- package/dist/frame-sync.js.map +1 -1
- package/dist/harness-window.d.ts +4 -0
- package/dist/harness-window.d.ts.map +1 -0
- package/dist/harness-window.js +6 -0
- package/dist/harness-window.js.map +1 -0
- package/dist/index.d.ts +14 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +4 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +4 -0
- package/dist/internal.js.map +1 -0
- package/dist/matchers.d.ts +88 -46
- package/dist/matchers.d.ts.map +1 -1
- package/dist/matchers.js +156 -18
- package/dist/matchers.js.map +1 -1
- package/dist/pretty-format.d.ts +2 -0
- package/dist/pretty-format.d.ts.map +1 -0
- package/dist/pretty-format.js +2 -0
- package/dist/pretty-format.js.map +1 -0
- package/dist/pretty-widget.d.ts +5 -2
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +73 -56
- package/dist/pretty-widget.js.map +1 -1
- package/dist/production.d.ts +8 -0
- package/dist/production.d.ts.map +1 -0
- package/dist/production.js +34 -0
- package/dist/production.js.map +1 -0
- package/dist/queries.d.ts +98 -56
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +123 -83
- package/dist/queries.js.map +1 -1
- package/dist/query-helpers.d.ts +44 -0
- package/dist/query-helpers.d.ts.map +1 -0
- package/dist/query-helpers.js +57 -0
- package/dist/query-helpers.js.map +1 -0
- package/dist/render-children.d.ts +9 -0
- package/dist/render-children.d.ts.map +1 -0
- package/dist/render-children.js +11 -0
- package/dist/render-children.js.map +1 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +11 -9
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts +12 -3
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-helpers.js +13 -4
- package/dist/role-helpers.js.map +1 -1
- package/dist/role-naming.d.ts +5 -0
- package/dist/role-naming.d.ts.map +1 -0
- package/dist/role-naming.js +96 -0
- package/dist/role-naming.js.map +1 -0
- package/dist/screenshot.d.ts +12 -20
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +183 -91
- package/dist/screenshot.js.map +1 -1
- package/dist/traversal.d.ts +4 -1
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +25 -6
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +26 -14
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts +3 -0
- package/dist/user-event/adjustment.d.ts.map +1 -1
- package/dist/user-event/adjustment.js +23 -2
- package/dist/user-event/adjustment.js.map +1 -1
- package/dist/user-event/click.d.ts +43 -8
- package/dist/user-event/click.d.ts.map +1 -1
- package/dist/user-event/click.js +175 -44
- package/dist/user-event/click.js.map +1 -1
- package/dist/user-event/column-header-click.d.ts +4 -0
- package/dist/user-event/column-header-click.d.ts.map +1 -0
- package/dist/user-event/column-header-click.js +65 -0
- package/dist/user-event/column-header-click.js.map +1 -0
- package/dist/user-event/event-wrapper.d.ts.map +1 -1
- package/dist/user-event/event-wrapper.js +2 -1
- package/dist/user-event/event-wrapper.js.map +1 -1
- package/dist/user-event/index.d.ts +51 -10
- package/dist/user-event/index.d.ts.map +1 -1
- package/dist/user-event/index.js +43 -26
- package/dist/user-event/index.js.map +1 -1
- package/dist/user-event/indexed-children.d.ts +10 -0
- package/dist/user-event/indexed-children.d.ts.map +1 -0
- package/dist/user-event/indexed-children.js +50 -0
- package/dist/user-event/indexed-children.js.map +1 -0
- package/dist/user-event/keyboard.d.ts.map +1 -1
- package/dist/user-event/keyboard.js +33 -4
- package/dist/user-event/keyboard.js.map +1 -1
- package/dist/user-event/list-row-click.d.ts +4 -0
- package/dist/user-event/list-row-click.d.ts.map +1 -0
- package/dist/user-event/list-row-click.js +39 -0
- package/dist/user-event/list-row-click.js.map +1 -0
- package/dist/user-event/native-click.d.ts +6 -0
- package/dist/user-event/native-click.d.ts.map +1 -0
- package/dist/user-event/native-click.js +32 -0
- package/dist/user-event/native-click.js.map +1 -0
- package/dist/user-event/pointer.d.ts +1 -1
- package/dist/user-event/pointer.d.ts.map +1 -1
- package/dist/user-event/pointer.js +33 -9
- package/dist/user-event/pointer.js.map +1 -1
- package/dist/user-event/selection.d.ts +11 -8
- package/dist/user-event/selection.d.ts.map +1 -1
- package/dist/user-event/selection.js +49 -38
- package/dist/user-event/selection.js.map +1 -1
- package/dist/user-event/text.d.ts +6 -2
- package/dist/user-event/text.d.ts.map +1 -1
- package/dist/user-event/text.js +68 -18
- package/dist/user-event/text.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +14 -26
- package/dist/widget-accessible-properties.d.ts.map +1 -1
- package/dist/widget-accessible-properties.js +135 -190
- package/dist/widget-accessible-properties.js.map +1 -1
- package/dist/widget-getters.d.ts +8 -0
- package/dist/widget-getters.d.ts.map +1 -0
- package/dist/widget-getters.js +19 -0
- package/dist/widget-getters.js.map +1 -0
- package/dist/within.d.ts +3 -2
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js +3 -2
- package/dist/within.js.map +1 -1
- package/package.json +12 -7
- package/src/accessible-native.ts +333 -0
- package/src/build-queries.ts +47 -41
- package/src/cleanup-registry.ts +1 -1
- package/src/errors.ts +12 -1
- package/src/fire-event.ts +61 -8
- package/src/frame-sync.ts +21 -5
- package/src/harness-window.ts +9 -0
- package/src/index.ts +18 -11
- package/src/internal.ts +11 -0
- package/src/matchers.ts +428 -70
- package/src/pretty-format.ts +1 -0
- package/src/pretty-widget.ts +97 -70
- package/src/production.ts +52 -0
- package/src/queries.ts +127 -89
- package/src/query-helpers.ts +97 -0
- package/src/render-children.ts +25 -0
- package/src/render.tsx +16 -11
- package/src/role-helpers.ts +14 -4
- package/src/role-naming.ts +99 -0
- package/src/screenshot.ts +272 -103
- package/src/traversal.ts +44 -6
- package/src/types.ts +28 -16
- package/src/user-event/adjustment.ts +29 -2
- package/src/user-event/click.ts +247 -52
- package/src/user-event/column-header-click.ts +90 -0
- package/src/user-event/event-wrapper.ts +3 -1
- package/src/user-event/index.ts +100 -37
- package/src/user-event/indexed-children.ts +75 -0
- package/src/user-event/keyboard.ts +52 -4
- package/src/user-event/list-row-click.ts +57 -0
- package/src/user-event/native-click.ts +46 -0
- package/src/user-event/pointer.ts +48 -9
- package/src/user-event/selection.ts +67 -41
- package/src/user-event/text.ts +92 -21
- package/src/widget-accessible-properties.ts +183 -230
- package/src/widget-getters.ts +32 -0
- package/src/within.ts +3 -2
package/src/user-event/index.ts
CHANGED
|
@@ -5,28 +5,61 @@ import { drag, dragAndDrop, drop, hover, longPress, rotate, swipe, unhover, zoom
|
|
|
5
5
|
import { keyboard, tab } from "./keyboard.js";
|
|
6
6
|
import { pointer, type PointerInput } from "./pointer.js";
|
|
7
7
|
import { deselectOptions, selectOptions } from "./selection.js";
|
|
8
|
-
import { createInitialState } from "./state.js";
|
|
8
|
+
import { createInitialState, type UserEventState } from "./state.js";
|
|
9
9
|
import { clear, copy, cut, paste, type } from "./text.js";
|
|
10
10
|
|
|
11
|
+
/** Options shared by every helper on a {@link UserEvent} instance. */
|
|
12
|
+
type UserEventOptions = {
|
|
13
|
+
/** Milliseconds to wait after each helper resolves; null, the default, waits not at all. */
|
|
14
|
+
delay?: number | null | undefined;
|
|
15
|
+
};
|
|
16
|
+
|
|
11
17
|
/**
|
|
12
18
|
* The set of user interaction helpers exposed by {@link userEvent}, covering clicks, typing,
|
|
13
19
|
* keyboard, pointer, gestures, selection, and scrolling.
|
|
14
20
|
*/
|
|
15
21
|
type UserEvent = {
|
|
16
22
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
23
|
+
* Returns a fresh instance whose helpers share one keyboard and pointer state, so held modifiers
|
|
24
|
+
* and buttons carry across its calls but not across instances.
|
|
25
|
+
*/
|
|
26
|
+
setup: (options?: UserEventOptions) => UserEvent;
|
|
27
|
+
/**
|
|
28
|
+
* Activates a widget that neither claims the click nor carries a click gesture of its own, and
|
|
29
|
+
* otherwise presses and releases outwards from the clicked widget through every widget carrying
|
|
30
|
+
* a click gesture, stopping at the first button or indexed child. A list box row or flow box
|
|
31
|
+
* child receives its click gesture at the clicked position, passes one on to the gestures its
|
|
32
|
+
* container carries, and is then activated, or exclusively selected when its container does not
|
|
33
|
+
* activate on a single click. The press also stops at a widget whose click GTK4 implements
|
|
34
|
+
* itself, where the gestures that widget carries of its own still take the press and the same
|
|
35
|
+
* outcome is then applied through GTK's own public action: a list, grid, or column-view row is
|
|
36
|
+
* focused and selected, and activated as well when its view activates on a single click; an
|
|
37
|
+
* expandable tree expander that is itself the clicked widget toggles its expansion; a column
|
|
38
|
+
* header sorts by its column. A column-view cell and the row carrying the column headers stand
|
|
39
|
+
* in the way of the click rather than taking it, so a click on either reaches the row or the
|
|
40
|
+
* view behind it.
|
|
19
41
|
*/
|
|
20
42
|
click: typeof click;
|
|
21
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Delivers a two-press click gesture along the same path a single click takes, without trying
|
|
45
|
+
* activation first, activating a list box row or flow box child on that path and replacing its
|
|
46
|
+
* container's selection whether or not that container activates on a single click. A widget
|
|
47
|
+
* whose click GTK4 implements itself receives that outcome once per press, so a row is selected
|
|
48
|
+
* and activated by the second press, a tree expander ends back where it started, and a column
|
|
49
|
+
* header inverts its order after sorting.
|
|
50
|
+
*/
|
|
22
51
|
dblClick: typeof dblClick;
|
|
23
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Delivers a three-press click gesture the same way a double click is delivered, applying the
|
|
54
|
+
* same outcome to a list box row or flow box child, and applying the outcome GTK4 implements
|
|
55
|
+
* itself once per press to a row, tree expander, or column header.
|
|
56
|
+
*/
|
|
24
57
|
tripleClick: typeof tripleClick;
|
|
25
58
|
/** Moves focus within the widget's root, forward by default and backward with `isShiftHeld`. */
|
|
26
59
|
tab: typeof tab;
|
|
27
60
|
/** Focuses an editable widget, applies any initial selection, and inserts the text at the cursor. */
|
|
28
61
|
type: typeof type;
|
|
29
|
-
/**
|
|
62
|
+
/** Focuses an editable widget and deletes its whole text, leaving nothing selected. */
|
|
30
63
|
clear: typeof clear;
|
|
31
64
|
/** Writes an editable widget's current selection to the clipboard. */
|
|
32
65
|
copy: typeof copy;
|
|
@@ -34,9 +67,12 @@ type UserEvent = {
|
|
|
34
67
|
cut: typeof cut;
|
|
35
68
|
/** Inserts the given text, or the clipboard's text, at an editable widget's cursor. */
|
|
36
69
|
paste: typeof paste;
|
|
37
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* Selects the items at those positions in a view or drop-down, or selects the indexed children of
|
|
72
|
+
* a list box or flow box through their container, without activating them.
|
|
73
|
+
*/
|
|
38
74
|
selectOptions: typeof selectOptions;
|
|
39
|
-
/**
|
|
75
|
+
/** Unselects the items at those positions, leaving list box and flow box children unactivated. */
|
|
40
76
|
deselectOptions: typeof deselectOptions;
|
|
41
77
|
/** Emits a motion `enter` on the widget, adding a motion controller when it has none. */
|
|
42
78
|
hover: typeof hover;
|
|
@@ -62,47 +98,74 @@ type UserEvent = {
|
|
|
62
98
|
scroll: typeof scroll;
|
|
63
99
|
/** Sends a key sequence, dispatching matching shortcuts and tracking held modifiers across calls. */
|
|
64
100
|
keyboard: (widget: Gtk.Widget, input: string) => Promise<void>;
|
|
65
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Applies a pointer token to the click gestures the widget already carries, tracking whether the
|
|
103
|
+
* left button is held across calls. On a widget whose click GTK4 implements itself, the release
|
|
104
|
+
* also applies GTK's own outcome, the way {@link UserEvent.click} does, and a column-view cell
|
|
105
|
+
* or the row carrying the column headers passes the token to the row or view behind it.
|
|
106
|
+
*/
|
|
66
107
|
pointer: (widget: Gtk.Widget, input: PointerInput) => Promise<void>;
|
|
67
108
|
};
|
|
68
109
|
|
|
69
|
-
const state = createInitialState();
|
|
70
|
-
|
|
71
110
|
/**
|
|
72
111
|
* High-level helpers that drive widgets by dispatching the same events and gestures GTK4 delivers
|
|
73
|
-
* when someone clicks, types, or drags.
|
|
112
|
+
* when someone clicks, types, or drags. Call `setup` for an instance with its own keyboard and
|
|
113
|
+
* pointer state.
|
|
74
114
|
*/
|
|
75
115
|
const userEvent: UserEvent = {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
tripleClick,
|
|
79
|
-
tab,
|
|
80
|
-
type,
|
|
81
|
-
clear,
|
|
82
|
-
copy,
|
|
83
|
-
cut,
|
|
84
|
-
paste,
|
|
85
|
-
selectOptions,
|
|
86
|
-
deselectOptions,
|
|
87
|
-
hover,
|
|
88
|
-
unhover,
|
|
89
|
-
rotate,
|
|
90
|
-
zoom,
|
|
91
|
-
swipe,
|
|
92
|
-
longPress,
|
|
93
|
-
drag,
|
|
94
|
-
drop,
|
|
95
|
-
dragAndDrop,
|
|
96
|
-
slide,
|
|
97
|
-
scroll,
|
|
98
|
-
keyboard: (widget: Gtk.Widget, input: string): Promise<void> => keyboard(state, widget, input),
|
|
99
|
-
pointer: (widget: Gtk.Widget, input: PointerInput): Promise<void> => pointer(state, widget, input),
|
|
116
|
+
...createInstance(createInitialState(), {}),
|
|
117
|
+
setup: (options?: UserEventOptions): UserEvent => createInstance(createInitialState(), options ?? {}),
|
|
100
118
|
};
|
|
101
119
|
|
|
120
|
+
const settle = (delay: number | null | undefined): Promise<void> => {
|
|
121
|
+
if (delay === null || delay === undefined) {
|
|
122
|
+
return Promise.resolve();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return new Promise((resolve) => setTimeout(resolve, delay));
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
function createInstance(state: UserEventState, options: UserEventOptions): UserEvent {
|
|
129
|
+
const after =
|
|
130
|
+
<Args extends unknown[]>(helper: (...args: Args) => Promise<void>) =>
|
|
131
|
+
async (...args: Args): Promise<void> => {
|
|
132
|
+
await helper(...args);
|
|
133
|
+
await settle(options.delay);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
setup: (overrides?: UserEventOptions): UserEvent => createInstance(state, { ...options, ...overrides }),
|
|
138
|
+
click: after(click),
|
|
139
|
+
dblClick: after(dblClick),
|
|
140
|
+
tripleClick: after(tripleClick),
|
|
141
|
+
tab: after(tab),
|
|
142
|
+
type: after(type),
|
|
143
|
+
clear: after(clear),
|
|
144
|
+
copy: after(copy),
|
|
145
|
+
cut: after(cut),
|
|
146
|
+
paste: after(paste),
|
|
147
|
+
selectOptions: after(selectOptions),
|
|
148
|
+
deselectOptions: after(deselectOptions),
|
|
149
|
+
hover: after(hover),
|
|
150
|
+
unhover: after(unhover),
|
|
151
|
+
rotate: after(rotate),
|
|
152
|
+
zoom: after(zoom),
|
|
153
|
+
swipe: after(swipe),
|
|
154
|
+
longPress: after(longPress),
|
|
155
|
+
drag: after(drag),
|
|
156
|
+
drop: after(drop),
|
|
157
|
+
dragAndDrop: after(dragAndDrop),
|
|
158
|
+
slide: after(slide),
|
|
159
|
+
scroll: after(scroll),
|
|
160
|
+
keyboard: after((widget: Gtk.Widget, input: string): Promise<void> => keyboard(state, widget, input)),
|
|
161
|
+
pointer: after((widget: Gtk.Widget, input: PointerInput): Promise<void> => pointer(state, widget, input)),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
102
165
|
export type { ScrollDelta } from "./adjustment.js";
|
|
103
166
|
export type { DragOffset, DragOptions, DropContent, DropOptions } from "./gesture.js";
|
|
104
167
|
export type { TabOptions } from "./keyboard.js";
|
|
105
168
|
export type { PointerInput } from "./pointer.js";
|
|
106
169
|
export type { TypeOptions } from "./text.js";
|
|
107
170
|
export { resetClipboard } from "./text.js";
|
|
108
|
-
export { userEvent, type UserEvent };
|
|
171
|
+
export { userEvent, type UserEvent, type UserEventOptions };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import { callBooleanGetter, getCallableMethod, hasWidgetMethod } from "../widget-getters.js";
|
|
3
|
+
|
|
4
|
+
const CHILD_AT_INDEX_GETTERS = ["getRowAtIndex", "getChildAtIndex"];
|
|
5
|
+
const CHILD_SELECTORS = ["selectRow", "selectChild"];
|
|
6
|
+
const CHILD_DESELECTORS = ["unselectRow", "unselectChild"];
|
|
7
|
+
const SELECTED_CHILD_GETTERS = ["getSelectedRows", "getSelectedChildren"];
|
|
8
|
+
const SELECTED_PROBE = "isSelected";
|
|
9
|
+
|
|
10
|
+
const hasIndexedChildren = (widget: Gtk.Widget): boolean =>
|
|
11
|
+
CHILD_AT_INDEX_GETTERS.some((getter) => hasWidgetMethod(widget, getter));
|
|
12
|
+
|
|
13
|
+
const getChildAtIndex = (widget: Gtk.Widget, index: number): Gtk.Widget | null => {
|
|
14
|
+
for (const getter of CHILD_AT_INDEX_GETTERS) {
|
|
15
|
+
const fn = getCallableMethod<[number], Gtk.Widget | null>(widget, getter);
|
|
16
|
+
|
|
17
|
+
if (fn) {
|
|
18
|
+
return fn(index) ?? null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const applyChildMethod = (container: Gtk.Widget, names: string[], child: Gtk.Widget): void => {
|
|
26
|
+
for (const name of names) {
|
|
27
|
+
const fn = getCallableMethod<[Gtk.Widget], unknown>(container, name);
|
|
28
|
+
|
|
29
|
+
if (fn) {
|
|
30
|
+
fn(child);
|
|
31
|
+
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const selectContainerChild = (container: Gtk.Widget, child: Gtk.Widget): void => {
|
|
38
|
+
applyChildMethod(container, CHILD_SELECTORS, child);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const unselectContainerChild = (container: Gtk.Widget, child: Gtk.Widget): void => {
|
|
42
|
+
applyChildMethod(container, CHILD_DESELECTORS, child);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const isChildSelected = (child: Gtk.Widget): boolean => callBooleanGetter(child, SELECTED_PROBE) ?? false;
|
|
46
|
+
|
|
47
|
+
const getSelectedChildren = (container: Gtk.Widget): Gtk.Widget[] => {
|
|
48
|
+
for (const getter of SELECTED_CHILD_GETTERS) {
|
|
49
|
+
const fn = getCallableMethod<[], Gtk.Widget[]>(container, getter);
|
|
50
|
+
|
|
51
|
+
if (fn) {
|
|
52
|
+
return fn();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return [];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const unselectOtherChildren = (container: Gtk.Widget, child: Gtk.Widget): void => {
|
|
60
|
+
for (const selected of getSelectedChildren(container)) {
|
|
61
|
+
if (selected !== child) {
|
|
62
|
+
unselectContainerChild(container, selected);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export {
|
|
68
|
+
getChildAtIndex,
|
|
69
|
+
hasIndexedChildren,
|
|
70
|
+
isChildSelected,
|
|
71
|
+
SELECTED_PROBE,
|
|
72
|
+
selectContainerChild,
|
|
73
|
+
unselectContainerChild,
|
|
74
|
+
unselectOtherChildren,
|
|
75
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Gdk from "@gtkx/gi/gdk";
|
|
2
|
+
import * as Gio from "@gtkx/gi/gio";
|
|
2
3
|
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
4
|
import type { UserEventState } from "./state.js";
|
|
4
5
|
import { getEditableDelegate } from "../editable.js";
|
|
@@ -238,13 +239,55 @@ const didDispatchShortcutsOnWidget = (widget: Gtk.Widget, keyval: number, modifi
|
|
|
238
239
|
return false;
|
|
239
240
|
};
|
|
240
241
|
|
|
241
|
-
const
|
|
242
|
-
const
|
|
242
|
+
const isAccelMatch = (accel: string, keyval: number, modifiers: Gdk.ModifierType): boolean => {
|
|
243
|
+
const [isParsed, accelKeyval, accelModifiers] = Gtk.acceleratorParse(accel);
|
|
244
|
+
|
|
245
|
+
return isParsed && accelKeyval === keyval && accelModifiers === modifiers;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const hasMatchingAccel = (
|
|
249
|
+
application: Gtk.Application,
|
|
250
|
+
detailedActionName: string,
|
|
251
|
+
keyval: number,
|
|
252
|
+
modifiers: number,
|
|
253
|
+
): boolean =>
|
|
254
|
+
application.getAccelsForAction(detailedActionName).some((accel) => isAccelMatch(accel, keyval, modifiers));
|
|
255
|
+
|
|
256
|
+
const didActivateDetailedAction = (window: Gtk.Window, detailedActionName: string): boolean => {
|
|
257
|
+
const [isParsed, actionName, target] = Gio.Action.parseDetailedName(detailedActionName);
|
|
243
258
|
|
|
244
|
-
|
|
245
|
-
|
|
259
|
+
return isParsed && window.activateAction(actionName, target);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const didDispatchAccelsOnWindow = (window: Gtk.Window, keyval: number, modifiers: number): boolean => {
|
|
263
|
+
const application = window.getApplication();
|
|
264
|
+
|
|
265
|
+
if (!application) {
|
|
266
|
+
return false;
|
|
246
267
|
}
|
|
247
268
|
|
|
269
|
+
for (const detailedActionName of application.listActionDescriptions()) {
|
|
270
|
+
if (hasMatchingAccel(application, detailedActionName, keyval, modifiers)) {
|
|
271
|
+
return didActivateDetailedAction(window, detailedActionName);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return false;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const didDispatchApplicationAccels = (widget: Gtk.Widget, keyval: number, modifiers: number): boolean => {
|
|
279
|
+
const root = widget.getRoot();
|
|
280
|
+
|
|
281
|
+
return root instanceof Gtk.Window && didDispatchAccelsOnWindow(root, keyval, modifiers);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const didDispatchDelegateShortcuts = (widget: Gtk.Widget, keyval: number, modifiers: number): boolean => {
|
|
285
|
+
const delegate = getEditableDelegate(widget);
|
|
286
|
+
|
|
287
|
+
return delegate !== null && didDispatchShortcutsOnWidget(delegate, keyval, modifiers);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const didDispatchShortcutsOnAncestors = (widget: Gtk.Widget, keyval: number, modifiers: number): boolean => {
|
|
248
291
|
for (let current: Gtk.Widget | null = widget; current; current = current.getParent()) {
|
|
249
292
|
if (didDispatchShortcutsOnWidget(current, keyval, modifiers)) {
|
|
250
293
|
return true;
|
|
@@ -254,6 +297,11 @@ const didDispatchShortcuts = (widget: Gtk.Widget, keyval: number, modifiers: num
|
|
|
254
297
|
return false;
|
|
255
298
|
};
|
|
256
299
|
|
|
300
|
+
const didDispatchShortcuts = (widget: Gtk.Widget, keyval: number, modifiers: number): boolean =>
|
|
301
|
+
didDispatchApplicationAccels(widget, keyval, modifiers) ||
|
|
302
|
+
didDispatchDelegateShortcuts(widget, keyval, modifiers) ||
|
|
303
|
+
didDispatchShortcutsOnAncestors(widget, keyval, modifiers);
|
|
304
|
+
|
|
257
305
|
const handleKeyPress = async (widget: Gtk.Widget, keyval: number, modifiers: number): Promise<void> => {
|
|
258
306
|
const isHandled = didDispatchShortcuts(widget, keyval, modifiers);
|
|
259
307
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import * as GLib from "@gtkx/gi/glib";
|
|
3
|
+
import { callBooleanGetter, hasWidgetMethod } from "../widget-getters.js";
|
|
4
|
+
|
|
5
|
+
const SELECT_ACTION = "listitem.select";
|
|
6
|
+
const SINGLE_CLICK_ACTIVATE_GETTER = "getSingleClickActivate";
|
|
7
|
+
const DOUBLE_CLICK_PRESS = 2;
|
|
8
|
+
|
|
9
|
+
const viewFor = (row: Gtk.Widget): Gtk.Widget | null => {
|
|
10
|
+
let current: Gtk.Widget | null = row.getParent();
|
|
11
|
+
|
|
12
|
+
while (current !== null) {
|
|
13
|
+
if (hasWidgetMethod(current, SINGLE_CLICK_ACTIVATE_GETTER)) {
|
|
14
|
+
return current;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
current = current.getParent();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const isViewSingleClickActivating = (row: Gtk.Widget): boolean => {
|
|
24
|
+
const view = viewFor(row);
|
|
25
|
+
|
|
26
|
+
return view === null ? false : callBooleanGetter(view, SINGLE_CLICK_ACTIVATE_GETTER) ?? false;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const selectRow = (row: Gtk.Widget): void => {
|
|
30
|
+
row.activateAction(
|
|
31
|
+
SELECT_ACTION,
|
|
32
|
+
GLib.Variant.newTuple([GLib.Variant.newBoolean(false), GLib.Variant.newBoolean(false)]),
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const isRowActivatedByPress = (row: Gtk.Widget, press: number): boolean =>
|
|
37
|
+
press === DOUBLE_CLICK_PRESS || isViewSingleClickActivating(row);
|
|
38
|
+
|
|
39
|
+
const applyRowPress = (row: Gtk.Widget, press: number): void => {
|
|
40
|
+
if (row.getFocusOnClick()) {
|
|
41
|
+
row.grabFocus();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
selectRow(row);
|
|
45
|
+
|
|
46
|
+
if (isRowActivatedByPress(row, press)) {
|
|
47
|
+
row.activate();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const applyRowClick = (row: Gtk.Widget, nPress: number): void => {
|
|
52
|
+
for (let press = 1; press <= nPress; press++) {
|
|
53
|
+
applyRowPress(row, press);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export { applyRowClick };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import { getWidgetTypeName } from "../widget-getters.js";
|
|
3
|
+
import { applyHeaderClick } from "./column-header-click.js";
|
|
4
|
+
import { applyRowClick } from "./list-row-click.js";
|
|
5
|
+
|
|
6
|
+
type NativeClick = (widget: Gtk.Widget, nPress: number) => void;
|
|
7
|
+
|
|
8
|
+
const COLUMN_ROW_TYPE_NAME = "GtkColumnViewRowWidget";
|
|
9
|
+
const ROW_TYPE_NAMES: Set<string> = new Set([COLUMN_ROW_TYPE_NAME, "GtkListItemWidget"]);
|
|
10
|
+
const CELL_TYPE_NAME = "GtkColumnViewCellWidget";
|
|
11
|
+
const TITLE_TYPE_NAME = "GtkColumnViewTitle";
|
|
12
|
+
const TOGGLE_EXPAND_ACTION = "listitem.toggle-expand";
|
|
13
|
+
|
|
14
|
+
const isHeaderRow = (widget: Gtk.Widget): boolean =>
|
|
15
|
+
getWidgetTypeName(widget) === COLUMN_ROW_TYPE_NAME && widget.getParent() instanceof Gtk.ColumnView;
|
|
16
|
+
|
|
17
|
+
const isClickTransparent = (widget: Gtk.Widget): boolean =>
|
|
18
|
+
getWidgetTypeName(widget) === CELL_TYPE_NAME || isHeaderRow(widget);
|
|
19
|
+
|
|
20
|
+
const isExpanderToggling = (widget: Gtk.Widget): boolean =>
|
|
21
|
+
widget instanceof Gtk.TreeExpander &&
|
|
22
|
+
widget.getListRow()?.isExpandable() === true &&
|
|
23
|
+
!widget.getHideExpander();
|
|
24
|
+
|
|
25
|
+
const isColumnHeader = (widget: Gtk.Widget): boolean => getWidgetTypeName(widget) === TITLE_TYPE_NAME;
|
|
26
|
+
const isFactoryRow = (widget: Gtk.Widget): boolean => ROW_TYPE_NAMES.has(getWidgetTypeName(widget) ?? "");
|
|
27
|
+
|
|
28
|
+
const toggleExpander = (widget: Gtk.Widget, nPress: number): void => {
|
|
29
|
+
for (let press = 1; press <= nPress; press++) {
|
|
30
|
+
widget.activateAction(TOGGLE_EXPAND_ACTION, null);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const nativeClickFor = (widget: Gtk.Widget, isClicked: boolean): NativeClick | null => {
|
|
35
|
+
if (isClicked && isExpanderToggling(widget)) {
|
|
36
|
+
return toggleExpander;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isColumnHeader(widget)) {
|
|
40
|
+
return applyHeaderClick;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return isFactoryRow(widget) ? applyRowClick : null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { isClickTransparent, type NativeClick, nativeClickFor };
|
|
@@ -1,39 +1,78 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/gi/gtk";
|
|
1
|
+
import type * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import type { NativeClick } from "./native-click.js";
|
|
2
3
|
import type { UserEventState } from "./state.js";
|
|
3
|
-
import {
|
|
4
|
-
import { getOrCreateControllers } from "./controller.js";
|
|
4
|
+
import { clickGestures, emitClickPhase, getAuthoredClickGestures } from "./click.js";
|
|
5
5
|
import { wrapEvent } from "./event-wrapper.js";
|
|
6
|
+
import { isClickTransparent, nativeClickFor } from "./native-click.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* A pointer action token: a full click (`click`, `[MouseLeft]`), a button press (`down`,
|
|
9
10
|
* `[MouseLeft>]`), or a button release (`up`, `[/MouseLeft]`).
|
|
10
11
|
*/
|
|
11
12
|
type PointerInput = "click" | "down" | "up" | "[MouseLeft]" | "[MouseLeft>]" | "[/MouseLeft]";
|
|
13
|
+
type PointerTarget = { widget: Gtk.Widget; gestures: Gtk.GestureClick[]; native: NativeClick | null };
|
|
12
14
|
|
|
13
15
|
const PRESS_INPUTS: Set<PointerInput> = new Set(["[MouseLeft>]", "down"]);
|
|
14
16
|
const RELEASE_INPUTS: Set<PointerInput> = new Set(["[/MouseLeft]", "up"]);
|
|
15
17
|
const CLICK_INPUTS: Set<PointerInput> = new Set(["[MouseLeft]", "click"]);
|
|
16
18
|
|
|
19
|
+
const pointerWidgetFor = (widget: Gtk.Widget): Gtk.Widget => {
|
|
20
|
+
let current = widget;
|
|
21
|
+
|
|
22
|
+
while (isClickTransparent(current)) {
|
|
23
|
+
const parent = current.getParent();
|
|
24
|
+
|
|
25
|
+
if (parent === null) {
|
|
26
|
+
return current;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
current = parent;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return current;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const pointerGesturesFor = (widget: Gtk.Widget, native: NativeClick | null): Gtk.GestureClick[] =>
|
|
36
|
+
native === null ? clickGestures(widget) : getAuthoredClickGestures(widget);
|
|
37
|
+
|
|
38
|
+
const pointerTargetFor = (widget: Gtk.Widget): PointerTarget => {
|
|
39
|
+
const target = pointerWidgetFor(widget);
|
|
40
|
+
const native = nativeClickFor(target, true);
|
|
41
|
+
|
|
42
|
+
return { widget: target, gestures: pointerGesturesFor(target, native), native };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const pressPointer = ({ widget, gestures }: PointerTarget): void => {
|
|
46
|
+
emitClickPhase(widget, gestures, 1, "pressed");
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const releasePointer = ({ widget, gestures, native }: PointerTarget): void => {
|
|
50
|
+
emitClickPhase(widget, gestures, 1, "released");
|
|
51
|
+
native?.(widget, 1);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const isPointerPressable = (target: PointerTarget): boolean => target.native !== null || target.gestures.length > 0;
|
|
55
|
+
|
|
17
56
|
const applyPointerInput = (widget: Gtk.Widget, state: UserEventState, input: PointerInput): void => {
|
|
18
|
-
const
|
|
57
|
+
const target = pointerTargetFor(widget);
|
|
19
58
|
|
|
20
59
|
if (CLICK_INPUTS.has(input)) {
|
|
21
|
-
|
|
22
|
-
|
|
60
|
+
pressPointer(target);
|
|
61
|
+
releasePointer(target);
|
|
23
62
|
state.isMouseLeftDown = false;
|
|
24
63
|
|
|
25
64
|
return;
|
|
26
65
|
}
|
|
27
66
|
|
|
28
|
-
if (PRESS_INPUTS.has(input) && !state.isMouseLeftDown) {
|
|
29
|
-
|
|
67
|
+
if (PRESS_INPUTS.has(input) && !state.isMouseLeftDown && isPointerPressable(target)) {
|
|
68
|
+
pressPointer(target);
|
|
30
69
|
state.isMouseLeftDown = true;
|
|
31
70
|
|
|
32
71
|
return;
|
|
33
72
|
}
|
|
34
73
|
|
|
35
74
|
if (RELEASE_INPUTS.has(input) && state.isMouseLeftDown) {
|
|
36
|
-
|
|
75
|
+
releasePointer(target);
|
|
37
76
|
state.isMouseLeftDown = false;
|
|
38
77
|
}
|
|
39
78
|
};
|