drawnui-react 0.1.0-preview.34 → 0.1.0-preview.36

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.
Files changed (40) hide show
  1. package/SKIPPED.md +2 -0
  2. package/dist/controls/SkiaButton.js +2 -2
  3. package/dist/controls/SkiaCheckbox.js +2 -1
  4. package/dist/controls/SkiaEditor.d.ts +4 -0
  5. package/dist/controls/SkiaEditor.js +16 -4
  6. package/dist/controls/SkiaLabel.d.ts +7 -1
  7. package/dist/controls/SkiaLabel.js +44 -8
  8. package/dist/controls/SkiaLayout.d.ts +2 -0
  9. package/dist/controls/SkiaLayout.js +2 -0
  10. package/dist/controls/SkiaProgress.js +2 -2
  11. package/dist/controls/SkiaRadioButton.js +2 -1
  12. package/dist/controls/SkiaSlider.js +2 -2
  13. package/dist/controls/SkiaSwitch.js +4 -2
  14. package/dist/controls/TooltipStyle.d.ts +52 -0
  15. package/dist/controls/TooltipStyle.js +88 -0
  16. package/dist/core/Accessibility.d.ts +18 -0
  17. package/dist/core/Accessibility.js +75 -3
  18. package/dist/core/Canvas.d.ts +60 -3
  19. package/dist/core/Canvas.js +185 -5
  20. package/dist/core/ControlStyle.d.ts +2 -0
  21. package/dist/core/ControlStyle.js +2 -0
  22. package/dist/core/Hover.d.ts +4 -0
  23. package/dist/core/Hover.js +6 -0
  24. package/dist/core/KeyboardManager.d.ts +7 -0
  25. package/dist/core/KeyboardManager.js +31 -2
  26. package/dist/core/PopupWindows.d.ts +92 -0
  27. package/dist/core/PopupWindows.js +203 -0
  28. package/dist/core/SkiaControl.d.ts +20 -0
  29. package/dist/core/SkiaControl.js +33 -0
  30. package/dist/core/Super.d.ts +7 -0
  31. package/dist/core/Super.js +7 -0
  32. package/dist/core/Tooltips.d.ts +69 -0
  33. package/dist/core/Tooltips.js +195 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.js +3 -0
  36. package/dist/react/index.d.ts +13 -0
  37. package/dist/react/index.js +32 -0
  38. package/dist/react/reconciler.d.ts +2 -0
  39. package/dist/react/reconciler.js +5 -0
  40. package/package.json +2 -1
@@ -106,9 +106,19 @@ export class SkiaAccessibilityManager {
106
106
  * Aria.RoleList on a SkiaStack), and the item of that group holding the control (one of its children, a cell).
107
107
  */
108
108
  static TryFindGroup(control) {
109
+ const path = [];
109
110
  for (let child = control, parent = control.Parent; parent; child = parent, parent = parent.Parent) {
110
- if (Aria.IsCompositeRole(parent.AccessibilityRole))
111
- return { Group: parent, Item: child };
111
+ path.push(child);
112
+ if (!Aria.IsCompositeRole(parent.AccessibilityRole))
113
+ continue;
114
+ // drawnui-cross 6ao: the role may sit on a wrapper (a menu shape around a column of lines); the items are the
115
+ // children of the control that holds them, found down the path through single children that are not nodes
116
+ let holder = parent, k = path.length - 1;
117
+ while (k > 0 && ViewsOf(holder).length === 1 && !IsInteractiveNode(path[k])) {
118
+ holder = path[k];
119
+ k--;
120
+ }
121
+ return { Group: parent, Item: path[k], Holder: holder };
112
122
  }
113
123
  return undefined;
114
124
  }
@@ -124,6 +134,15 @@ export class SkiaAccessibilityManager {
124
134
  * item; the arrow keys move between items. Every node outside a group is a stop.
125
135
  */
126
136
  IsTabStop(node) {
137
+ // an open popup window keeps the keyboard: Tab never leaves it, as with native menus
138
+ const scope = this.KeyboardScope;
139
+ if (scope) {
140
+ let c = node;
141
+ while (c && c !== scope)
142
+ c = c.Parent;
143
+ if (!c)
144
+ return false;
145
+ }
127
146
  const found = SkiaAccessibilityManager.TryFindGroup(node);
128
147
  if (!found)
129
148
  return true;
@@ -158,7 +177,7 @@ export class SkiaAccessibilityManager {
158
177
  const found = SkiaAccessibilityManager.TryFindGroup(focused);
159
178
  if (!found)
160
179
  return false;
161
- const { Group: group, Item: item } = found;
180
+ const { Holder: group, Item: item } = found;
162
181
  const scroll = FindScroll(group), axis = AxisOf(group), count = ItemCount(group);
163
182
  const current = this.groupRequest?.Group === group ? this.groupRequest.Index : IndexOf(group, item);
164
183
  if (current < 0 || count < 1)
@@ -212,6 +231,53 @@ export class SkiaAccessibilityManager {
212
231
  group.Superview?.Update(); // resolved at the end of the next frame, together with the snapshot
213
232
  return true;
214
233
  }
234
+ // ---- keyboard focus moved by popup windows (drawnui-cross 6ao rule 2, and back to the opener on close) ----
235
+ focusRequest;
236
+ popupFocusRoot;
237
+ /** The keyboard goes to this control at the end of the next frame (a popup closed: back to what opened it). */
238
+ RequestKeyboardFocus(control) { this.focusRequest = control; }
239
+ /**
240
+ * While set, Tab stays inside this control: only its nodes are Tab stops and Tab / Shift+Tab go round them. The canvas
241
+ * sets it to the top popup window that takes input (a menu, a dropdown), undefined when none is open.
242
+ */
243
+ KeyboardScope;
244
+ /** The Tab stop after (or before) `from` in reading order; inside a KeyboardScope it goes round, never leaving. */
245
+ NextTabStop(from, forward) {
246
+ const stops = this.Snapshot.filter((n) => n.CanInteract && this.IsTabStop(n.Source)).map((n) => n.Source);
247
+ if (stops.length === 0)
248
+ return undefined;
249
+ let current = from ? stops.indexOf(from) : -1;
250
+ if (current < 0)
251
+ current = forward ? -1 : stops.length;
252
+ const next = forward ? current + 1 : current - 1;
253
+ if (this.KeyboardScope)
254
+ return stops[(next + stops.length) % stops.length];
255
+ return next >= 0 && next < stops.length ? stops[next] : undefined;
256
+ }
257
+ /**
258
+ * A popup window just opened: at the end of the frame that draws it, the keyboard goes to its arrow-key group's current
259
+ * choice (a checked radio, menuitemradio, option or tab), else to its first interactive item, however it was opened.
260
+ */
261
+ FocusOpenedPopup(root) { this.popupFocusRoot = root; }
262
+ ProcessFocusRequests(scale, w, h) {
263
+ const request = this.focusRequest, root = this.popupFocusRoot;
264
+ this.focusRequest = this.popupFocusRoot = undefined;
265
+ if (root && !root.IsDisposed && root.Superview) {
266
+ this.Rebuild(scale, w, h);
267
+ const inside = (c) => { for (let p = c; p; p = p.Parent)
268
+ if (p === root)
269
+ return true; return false; };
270
+ const choice = (role) => role === Aria.RoleRadio || role === Aria.RoleMenuItemRadio || role === "option" || role === "tab";
271
+ const items = this.Snapshot.filter((n) => n.CanInteract && inside(n.Source) && SkiaAccessibilityManager.TryFindGroup(n.Source));
272
+ const target = items.find((n) => n.IsPressed === true && choice(n.Role)) ?? items[0];
273
+ if (target) {
274
+ this.FocusFromKeyboard(target.Source, scale, w, h);
275
+ return;
276
+ }
277
+ }
278
+ if (request && !request.IsDisposed && request.Superview && request.AccessibilityCanInteract)
279
+ this.FocusFromKeyboard(request, scale, w, h);
280
+ }
215
281
  /** Frame end: focus the requested item once it is drawn, skipping items that cannot take input. */
216
282
  ProcessGroupFocus(scale, w, h, requestFrame) {
217
283
  const request = this.groupRequest;
@@ -285,6 +351,8 @@ export class SkiaAccessibilityManager {
285
351
  */
286
352
  OnFrameEnd(scale, canvasWidthPx, canvasHeightPx, requestFrame) {
287
353
  this.ProcessGroupFocus(scale, canvasWidthPx, canvasHeightPx, requestFrame);
354
+ if (this.focusRequest || this.popupFocusRoot)
355
+ this.ProcessFocusRequests(scale, canvasWidthPx, canvasHeightPx);
288
356
  if (this.nodes.size === 0 && this.Snapshot.length === 0)
289
357
  return;
290
358
  const now = performance.now();
@@ -401,6 +469,10 @@ function SameValue(a, b) {
401
469
  return a === b || (!!a && !!b && a.Now === b.Now && a.Min === b.Min && a.Max === b.Max && a.Step === b.Step && a.Text === b.Text);
402
470
  }
403
471
  // ---- group helpers (duck-typed layouts and scrolls) ----
472
+ /** A node the keyboard can land on: a role that is not presentation and takes input. */
473
+ function IsInteractiveNode(c) {
474
+ return !!c.AccessibilityRole && c.AccessibilityRole !== Aria.RolePresentation && c.IsAccessibilityElement && c.AccessibilityCanInteract;
475
+ }
404
476
  /** Children of a control (a layout's Views, a scroll's Content). */
405
477
  function ViewsOf(c) {
406
478
  if ("Views" in c)
@@ -3,8 +3,10 @@ import type { DrawingContext, SkiaControl } from "./SkiaControl";
3
3
  import type { AnimatorBase } from "./Animators";
4
4
  import { SkiaAccessibilityManager } from "./Accessibility";
5
5
  import { HoverManager } from "./Hover";
6
- import { type Color, type RenderingModeType } from "./Types";
7
- import { ContextMenuEventArgs, type GesturesMode, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
6
+ import { type TooltipStyleLike } from "./Tooltips";
7
+ import { PopupAnchor, type PopupId, type PopupWindowOptions } from "./PopupWindows";
8
+ import { type Color, type RenderingModeType, SKRect } from "./Types";
9
+ import { ContextMenuEventArgs, type GesturesMode, SKPoint, SkiaGesturesParameters, TouchActionEventArgs } from "./Gestures";
8
10
  /**
9
11
  * Mirrors DrawnUi Canvas (DrawnView): hosts one Content control on an HTML canvas element,
10
12
  * owns RenderingScale (devicePixelRatio), the surface, the on-demand frame loop and raw input.
@@ -45,6 +47,47 @@ export declare class Canvas {
45
47
  readonly AccessibilityManager: SkiaAccessibilityManager;
46
48
  /** Mouse hover of the controls (drawnui-cross 6m): ReceivesHover / IsHovered / HoverChanged. */
47
49
  readonly Hover: HoverManager;
50
+ private tooltipController?;
51
+ /** Made on first use: a canvas that never shows a tooltip allocates nothing for it. */
52
+ private get tooltip();
53
+ /** Look and timing of the tooltips on this canvas; unset uses `Super.TooltipStyle`. */
54
+ TooltipStyle?: TooltipStyleLike;
55
+ get TooltipStyleUsed(): TooltipStyleLike;
56
+ /** The text of the tooltip shown now, undefined when none is shown. */
57
+ get ShownTooltip(): string | undefined;
58
+ private popupLayer?;
59
+ /** Made on first use, like the tooltip. */
60
+ private get popups();
61
+ private popupKeysHooked;
62
+ /** Raised when a popup window closed: picked, a press outside, Escape, the wheel, window blur or ClosePopupWindow. */
63
+ readonly PopupWindowClosed: Set<(id: PopupId) => void>;
64
+ /**
65
+ * Shows `content` over everything, opening from `anchor` the way native menus do: at a point (a right click, canvas
66
+ * points), or below a rect or a control (a dropdown), flipped to the other side where it does not fit. It closes with
67
+ * a press outside it, Escape, the wheel outside it, window blur, `ClosePopupWindow` and the options.
68
+ */
69
+ OpenPopupWindow(content: SkiaControl, anchor: PopupAnchor | SKPoint | SKRect | SkiaControl | {
70
+ X: number;
71
+ Y: number;
72
+ }, options?: PopupWindowOptions): PopupId;
73
+ /** Closes the popup window (nothing when it is closed already). */
74
+ ClosePopupWindow(id: PopupId): void;
75
+ /** Closes every popup window. */
76
+ ClosePopupWindows(): void;
77
+ /** The popup window is still open. */
78
+ IsPopupWindowOpen(id: PopupId): boolean;
79
+ /** True while a popup window that takes input is open. */
80
+ get HasPopupWindows(): boolean;
81
+ /** The content of the top popup window that takes input. */
82
+ get TopPopupWindow(): SkiaControl | undefined;
83
+ /** The window stopped being active (blur): popup windows and the tooltip close, as native menus do. */
84
+ OnWindowDeactivated(): void;
85
+ RaisePopupWindowClosed(id: PopupId): void;
86
+ private AfterPopupsChanged;
87
+ private readonly onPopupKey;
88
+ private readonly onPopupChar;
89
+ private HookPopupKeys;
90
+ private readonly onWindowBlur;
48
91
  private content?;
49
92
  get Content(): SkiaControl | undefined;
50
93
  set Content(value: SkiaControl | undefined);
@@ -210,6 +253,20 @@ export declare class Canvas {
210
253
  private gestureOwner;
211
254
  /** DrawnUi IsSavedGesture: the types replayed to the owner instead of being routed again. */
212
255
  private static IsSavedGesture;
213
- /** Entry into the control tree, same shape as DrawnUi Canvas.ProcessGestures. */
256
+ private focusedChild?;
257
+ private focusAtDown?;
258
+ private tapNoFocus;
259
+ private reportingFocus;
260
+ /** The control that has the canvas focus (an editor while it edits, a CanBeFocused control that was tapped). */
261
+ get FocusedChild(): SkiaControl | undefined;
262
+ /**
263
+ * Moves the focus. The new control is asked first and the focus moves only when it takes it (a tap on a button leaves an
264
+ * editor focused); undefined clears it. Nothing moves while the focused control has LockFocus. `setter` is a control
265
+ * that focused itself already (an editor on its press) or the focused control letting go itself (Escape, submit).
266
+ */
267
+ ReportFocus(value: SkiaControl | undefined, setter?: SkiaControl): void;
268
+ /** Entry into the control tree; on a completed tap the focus follows it (C# Canvas: focus only on Tapped). */
214
269
  protected ProcessGestures(root: SkiaControl, args: SkiaGesturesParameters): SkiaControl | null;
270
+ /** Same shape as DrawnUi Canvas.ProcessGestures. */
271
+ private RouteGestures;
215
272
  }
@@ -1,6 +1,9 @@
1
1
  import { Super } from "./Super";
2
2
  import { SkiaAccessibilityManager } from "./Accessibility";
3
3
  import { HoverManager } from "./Hover";
4
+ import { TooltipController } from "./Tooltips";
5
+ import { PopupAnchor, PopupLayer } from "./PopupWindows";
6
+ import { KeyboardManager } from "./KeyboardManager";
4
7
  import { Colors, SKRect } from "./Types";
5
8
  import { ContextMenuEventArgs, GestureEventProcessingInfo, PointerData, SKPoint, SkiaGesturesParameters, TouchActionEventArgs, } from "./Gestures";
6
9
  /**
@@ -43,6 +46,69 @@ export class Canvas {
43
46
  AccessibilityManager = new SkiaAccessibilityManager();
44
47
  /** Mouse hover of the controls (drawnui-cross 6m): ReceivesHover / IsHovered / HoverChanged. */
45
48
  Hover = new HoverManager();
49
+ // ---- tooltips (drawnui-cross 6ar) ----
50
+ tooltipController;
51
+ /** Made on first use: a canvas that never shows a tooltip allocates nothing for it. */
52
+ get tooltip() { return this.tooltipController ??= new TooltipController(this); }
53
+ /** Look and timing of the tooltips on this canvas; unset uses `Super.TooltipStyle`. */
54
+ TooltipStyle;
55
+ get TooltipStyleUsed() { return this.TooltipStyle ?? Super.TooltipStyle; }
56
+ /** The text of the tooltip shown now, undefined when none is shown. */
57
+ get ShownTooltip() { return this.tooltip.ShownText; }
58
+ // ---- popup windows (drawnui-cross 6at, the DrawnUi.Rust / .NET API) ----
59
+ popupLayer;
60
+ /** Made on first use, like the tooltip. */
61
+ get popups() { return this.popupLayer ??= new PopupLayer(this); }
62
+ popupKeysHooked = false;
63
+ /** Raised when a popup window closed: picked, a press outside, Escape, the wheel, window blur or ClosePopupWindow. */
64
+ PopupWindowClosed = new Set();
65
+ /**
66
+ * Shows `content` over everything, opening from `anchor` the way native menus do: at a point (a right click, canvas
67
+ * points), or below a rect or a control (a dropdown), flipped to the other side where it does not fit. It closes with
68
+ * a press outside it, Escape, the wheel outside it, window blur, `ClosePopupWindow` and the options.
69
+ */
70
+ OpenPopupWindow(content, anchor, options = {}) {
71
+ const id = this.popups.Open(content, PopupAnchor.From(anchor), options, this);
72
+ this.HookPopupKeys(true);
73
+ if (!options.Passive)
74
+ this.tooltip.Reset(); // a menu opening closes the tooltip
75
+ this.Hover.RequestCheck();
76
+ this.Update();
77
+ return id;
78
+ }
79
+ /** Closes the popup window (nothing when it is closed already). */
80
+ ClosePopupWindow(id) { this.popups.Close(id); this.AfterPopupsChanged(); }
81
+ /** Closes every popup window. */
82
+ ClosePopupWindows() { this.popups.CloseAll(true); this.AfterPopupsChanged(); }
83
+ /** The popup window is still open. */
84
+ IsPopupWindowOpen(id) { return this.popups.IsOpen(id); }
85
+ /** True while a popup window that takes input is open. */
86
+ get HasPopupWindows() { return this.popups.HasInteractive; }
87
+ /** The content of the top popup window that takes input. */
88
+ get TopPopupWindow() { return this.popups.TopInteractive; }
89
+ /** The window stopped being active (blur): popup windows and the tooltip close, as native menus do. */
90
+ OnWindowDeactivated() { this.ClosePopupWindows(); this.tooltip.CloseOnInput(); }
91
+ RaisePopupWindowClosed(id) { for (const h of [...this.PopupWindowClosed])
92
+ h(id); }
93
+ AfterPopupsChanged() {
94
+ if (!this.popups.HasAny)
95
+ this.HookPopupKeys(false);
96
+ this.Hover.RequestCheck();
97
+ this.Update();
98
+ }
99
+ onPopupKey = (key) => { if (key === "Escape" && this.popups.CloseTop())
100
+ this.AfterPopupsChanged(); };
101
+ onPopupChar = () => { };
102
+ HookPopupKeys(on) {
103
+ if (on === this.popupKeysHooked)
104
+ return;
105
+ this.popupKeysHooked = on;
106
+ if (on)
107
+ KeyboardManager.Subscribe(this.onPopupKey, this.onPopupChar);
108
+ else
109
+ KeyboardManager.Unsubscribe(this.onPopupKey, this.onPopupChar);
110
+ }
111
+ onWindowBlur = () => this.OnWindowDeactivated();
46
112
  content;
47
113
  get Content() { return this.content; }
48
114
  set Content(value) {
@@ -78,6 +144,7 @@ export class Canvas {
78
144
  init?.(this);
79
145
  Element.addEventListener("webglcontextlost", this.onContextLost);
80
146
  Element.addEventListener("webglcontextrestored", this.onContextRestored);
147
+ this.Hover.RootAt = (x, y) => this.popupLayer?.At(x, y) ?? this.content;
81
148
  this.observer = new ResizeObserver(() => this.OnResized());
82
149
  this.observer.observe(Element);
83
150
  this.OnResized();
@@ -209,8 +276,15 @@ export class Canvas {
209
276
  root.Arrange(new SKRect(0, 0, w, h), root.WidthRequest, root.HeightRequest, scale);
210
277
  root.Render({ Context: { Canvas: canvas, Surface: this.surface }, Destination: new SKRect(0, 0, w, h), Scale: scale });
211
278
  }
279
+ // popup windows, then the tooltip, over everything
280
+ const top = { Context: { Canvas: canvas, Surface: this.surface }, Destination: new SKRect(0, 0, this.Element.width, this.Element.height), Scale: this.RenderingScale };
281
+ if (this.popupLayer?.HasAny)
282
+ this.popupLayer.Draw(top, top.Destination);
283
+ this.tooltipController?.Draw(top, top.Destination);
212
284
  this.AccessibilityManager.OnFrameEnd(this.RenderingScale, this.Element.width, this.Element.height, () => this.Update());
213
285
  this.Hover.AfterFrame(this.content, this.activeTouchIds.size > 0);
286
+ if (this.Hover.Paused)
287
+ this.tooltipController?.Reset(); // content moves under the pointer
214
288
  const now = performance.now();
215
289
  this.FrameTime = now - started;
216
290
  this.FrameIndex++;
@@ -357,6 +431,9 @@ export class Canvas {
357
431
  this.Element.removeEventListener("webglcontextlost", this.onContextLost);
358
432
  this.Element.removeEventListener("webglcontextrestored", this.onContextRestored);
359
433
  this.Gestures = "Disabled";
434
+ this.tooltipController?.Dispose();
435
+ this.popupLayer?.Dispose();
436
+ this.HookPopupKeys(false);
360
437
  this.observer.disconnect();
361
438
  this.content?.Dispose();
362
439
  this.Content = undefined;
@@ -394,8 +471,13 @@ export class Canvas {
394
471
  if (type === "Moved" && !this.activeTouchIds.has(e.pointerId)) {
395
472
  if (e.pointerType === "touch")
396
473
  return; // touch never hovers
397
- if (this.activeTouchIds.size === 0)
398
- this.Hover.Move(this.content, e.offsetX * this.RenderingScale, e.offsetY * this.RenderingScale);
474
+ const hx = e.offsetX * this.RenderingScale, hy = e.offsetY * this.RenderingScale;
475
+ if (this.activeTouchIds.size === 0) {
476
+ this.Hover.Move(this.content, hx, hy);
477
+ this.tooltip.OnPointerMove(this.Hover.Path, hx, hy);
478
+ }
479
+ if (this.popups.HasAny)
480
+ this.popups.PointerAt(hx, hy);
399
481
  if (e.pointerType === "mouse")
400
482
  this.UpdateCursor();
401
483
  return;
@@ -403,6 +485,8 @@ export class Canvas {
403
485
  if ((type === "Released" || type === "Cancelled") && !this.activeTouchIds.has(e.pointerId))
404
486
  return; // Up of a pointer that never pressed here
405
487
  // Capture so Up outside the element still arrives; throws for synthetic events (tests) — harmless.
488
+ if (type === "Pressed")
489
+ this.tooltip.CloseOnInput();
406
490
  if (type === "Pressed") {
407
491
  try {
408
492
  this.Element.setPointerCapture(e.pointerId);
@@ -430,8 +514,14 @@ export class Canvas {
430
514
  }
431
515
  };
432
516
  /** The mouse left the canvas: hover ends at once, also while content moves. */
433
- onPointerLeave = (e) => { if (e.pointerType !== "touch")
434
- this.Hover.Leave(); };
517
+ onPointerLeave = (e) => {
518
+ if (e.pointerType === "touch")
519
+ return;
520
+ this.Hover.Leave();
521
+ this.tooltip.Reset();
522
+ if (this.popups.HasAny)
523
+ this.popups.PointerAt(undefined, undefined);
524
+ };
435
525
  preventTouch = (e) => e.preventDefault();
436
526
  /** Gestures="Enabled": touch / pen pointers whose Down a control used (see OnTouchAction). */
437
527
  claimedTouches = new Set();
@@ -448,6 +538,19 @@ export class Canvas {
448
538
  const pointerType = e.pointerType;
449
539
  const source = pointerType === "touch" || pointerType === "pen" ? "touch" : pointerType === "mouse" || e.button === 2 ? "mouse" : "keyboard";
450
540
  const args = new ContextMenuEventArgs(new SKPoint(x, y), new SKPoint(x * scale, y * scale), source, e);
541
+ this.tooltip.CloseOnInput();
542
+ // over a popup window its content is asked; elsewhere the popups close and the request goes on, so a new menu can
543
+ // open there (C# PopupLayer ContextMenu)
544
+ const popupRoot = this.popups.HasInteractive ? this.popups.At(args.Pixels.X, args.Pixels.Y) : undefined;
545
+ if (popupRoot) {
546
+ popupRoot.ProcessContextMenu(args.Pixels, args);
547
+ e.preventDefault();
548
+ return;
549
+ }
550
+ if (this.popups.HasInteractive) {
551
+ this.popups.CloseAll(false);
552
+ this.AfterPopupsChanged();
553
+ }
451
554
  let handled = this.content?.ProcessContextMenu(args.Pixels, args) ?? false;
452
555
  if (!handled && this.ContextMenu)
453
556
  handled = this.ContextMenu(this, args) === true;
@@ -496,6 +599,7 @@ export class Canvas {
496
599
  const factor = e.deltaMode === 1 ? 40 : e.deltaMode === 2 ? 800 : 1;
497
600
  const horizontal = Math.abs(e.deltaX) > Math.abs(e.deltaY);
498
601
  args.Wheel = { Delta: (horizontal ? e.deltaX : e.deltaY) * factor, IsHorizontal: horizontal };
602
+ this.tooltip.CloseOnInput();
499
603
  if (this.gestures === "Lock") {
500
604
  e.preventDefault();
501
605
  this.OnGestureEvent(args, "Wheel");
@@ -573,6 +677,7 @@ export class Canvas {
573
677
  el.addEventListener("pointerleave", this.onPointerLeave);
574
678
  el.addEventListener("contextmenu", this.onContextMenu);
575
679
  el.addEventListener("wheel", this.onWheel, { passive: false });
680
+ window.addEventListener("blur", this.onWindowBlur);
576
681
  if (this.gestures === "Lock") {
577
682
  el.addEventListener("touchmove", this.preventTouch, { passive: false });
578
683
  // the canvas owns every touch (DrawnUi.Web applyGestureStyle, DrawnUi.Rust host): no iOS callout or text
@@ -601,6 +706,7 @@ export class Canvas {
601
706
  el.removeEventListener("pointerleave", this.onPointerLeave);
602
707
  el.removeEventListener("contextmenu", this.onContextMenu);
603
708
  el.removeEventListener("wheel", this.onWheel);
709
+ window.removeEventListener("blur", this.onWindowBlur);
604
710
  el.removeEventListener("touchmove", this.preventTouch);
605
711
  el.removeEventListener("touchmove", this.preventClaimedTouch);
606
712
  if (this.pageOverscroll) {
@@ -721,9 +827,66 @@ export class Canvas {
721
827
  static IsSavedGesture(type) {
722
828
  return type === "Panning" || type === "Wheel" || type === "Up";
723
829
  }
724
- /** Entry into the control tree, same shape as DrawnUi Canvas.ProcessGestures. */
830
+ // ---- focus (C# DrawnView FocusedChild / ReportFocus, drawnui-cross 6ap) ----
831
+ focusedChild;
832
+ focusAtDown;
833
+ tapNoFocus = false;
834
+ reportingFocus = false;
835
+ /** The control that has the canvas focus (an editor while it edits, a CanBeFocused control that was tapped). */
836
+ get FocusedChild() { return this.focusedChild; }
837
+ /**
838
+ * Moves the focus. The new control is asked first and the focus moves only when it takes it (a tap on a button leaves an
839
+ * editor focused); undefined clears it. Nothing moves while the focused control has LockFocus. `setter` is a control
840
+ * that focused itself already (an editor on its press) or the focused control letting go itself (Escape, submit).
841
+ */
842
+ ReportFocus(value, setter) {
843
+ if (value === this.focusedChild || this.reportingFocus)
844
+ return;
845
+ if (this.focusedChild?.LockFocus && setter !== this.focusedChild)
846
+ return;
847
+ this.reportingFocus = true;
848
+ try {
849
+ if (value && value !== setter && !value.SetFrameworkFocus(true))
850
+ return;
851
+ const previous = this.focusedChild;
852
+ this.focusedChild = value;
853
+ if (previous && !previous.IsDisposed)
854
+ previous.SetFrameworkFocus(false);
855
+ }
856
+ finally {
857
+ this.reportingFocus = false;
858
+ }
859
+ }
860
+ /** Entry into the control tree; on a completed tap the focus follows it (C# Canvas: focus only on Tapped). */
725
861
  ProcessGestures(root, args) {
862
+ if (args.Type === "Down") {
863
+ this.focusAtDown = this.focusedChild;
864
+ this.tapNoFocus = false;
865
+ }
866
+ const consumed = this.RouteGestures(root, args);
867
+ // a control that claimed the focus during this gesture (an editor on its press) keeps it; a press that closed the
868
+ // popup windows moves nothing
869
+ if (args.Type === "Tapped" && !this.tapNoFocus && this.focusedChild === this.focusAtDown)
870
+ this.ReportFocus(consumed ?? undefined);
871
+ return consumed;
872
+ }
873
+ /** Same shape as DrawnUi Canvas.ProcessGestures. */
874
+ RouteGestures(root, args) {
726
875
  const info = () => new GestureEventProcessingInfo(args.Event.Location, SKPoint.Empty, SKPoint.Empty, null);
876
+ const popups = this.popups, at = args.Event.Location;
877
+ // the rest of a press that closed the popup windows goes nowhere (native menus)
878
+ if (args.Type === "Down")
879
+ popups.SwallowPress = false;
880
+ if (popups.SwallowPress) {
881
+ if (args.Type === "Up")
882
+ popups.SwallowPress = false;
883
+ return null;
884
+ }
885
+ // the wheel outside the popup windows closes them (what they opened from is about to move), before any owner takes it
886
+ if (args.Type === "Wheel" && popups.HasInteractive && !popups.At(at.X, at.Y)) {
887
+ popups.CloseAll(false);
888
+ this.AfterPopupsChanged();
889
+ }
727
890
  // the wheel goes to the press owner only while a press is held; between presses it goes by position, and it
728
891
  // never makes an owner: a wheel over a second scroll moves that one, not the last one the wheel moved
729
892
  // (DrawnUi.Rust input_router "the wheel goes to the owner of the press first"; C# keeps the last wheel consumer)
@@ -745,6 +908,23 @@ export class Canvas {
745
908
  if (!wheel)
746
909
  this.gestureOwner = null;
747
910
  }
911
+ // over a popup window its controls take the gesture and nothing below sees it; a press elsewhere closes them
912
+ if (popups.HasInteractive) {
913
+ const popupRoot = popups.At(at.X, at.Y);
914
+ if (popupRoot) {
915
+ const used = popupRoot.ProcessGestures(args, info()) ?? popupRoot;
916
+ if (!wheel)
917
+ this.gestureOwner = args.Type !== "Up" ? used : null;
918
+ return used;
919
+ }
920
+ if (args.Type === "Down") {
921
+ this.tapNoFocus = true;
922
+ popups.CloseAll(false);
923
+ popups.SwallowPress = true;
924
+ this.AfterPopupsChanged();
925
+ return null;
926
+ }
927
+ }
748
928
  const consumed = root.ProcessGestures(args, info());
749
929
  if (!wheel)
750
930
  this.gestureOwner = consumed && args.Type !== "Up" ? consumed : null;
@@ -1,5 +1,7 @@
1
1
  /** DrawnUi PrebuiltControlStyle: the look a styled control builds its default content with. */
2
2
  export type PrebuiltControlStyle = "Unset" | "Platform" | "Cupertino" | "Material" | "Material3" | "Windows";
3
+ /** Accent of the default look (controls without a ControlStyle): blue #3B82F6, the DrawnUI Designer's and Agent Signals' accent (C# DefaultStyle.Accent). */
4
+ export declare const DefaultAccent = "#3B82F6";
3
5
  /** Resolved look: `Platform` picks from the browser's OS (C# picks from the running platform). */
4
6
  export type ResolvedControlStyle = Exclude<PrebuiltControlStyle, "Platform">;
5
7
  /** C# UsingControlStyle: Platform -> iOS/macOS = Cupertino, Android = Material, Windows = Windows, else the DrawnUi default look. */
@@ -1,3 +1,5 @@
1
+ /** Accent of the default look (controls without a ControlStyle): blue #3B82F6, the DrawnUI Designer's and Agent Signals' accent (C# DefaultStyle.Accent). */
2
+ export const DefaultAccent = "#3B82F6";
1
3
  let platformStyle;
2
4
  /** C# UsingControlStyle: Platform -> iOS/macOS = Cupertino, Android = Material, Windows = Windows, else the DrawnUi default look. */
3
5
  export function ResolveControlStyle(style) {
@@ -23,6 +23,10 @@ export declare class HoverManager {
23
23
  private y;
24
24
  private paused;
25
25
  private check;
26
+ /** Picks the root under a point (canvas pixels): a popup window over the content, else the content. */
27
+ RootAt?: (x: number, y: number) => SkiaControl | undefined;
28
+ /** Content moves under the pointer (a scroll glide, a carousel transition): hover waits. */
29
+ get Paused(): boolean;
26
30
  /**
27
31
  * The mouse (or a pen in range) moved to (x, y), canvas pixels, nothing pressed. The hit path is taken also while
28
32
  * hover waits (the cursor follows it), hover changes only when nothing moves.
@@ -23,6 +23,10 @@ export class HoverManager {
23
23
  y = 0;
24
24
  paused = false;
25
25
  check = false;
26
+ /** Picks the root under a point (canvas pixels): a popup window over the content, else the content. */
27
+ RootAt;
28
+ /** Content moves under the pointer (a scroll glide, a carousel transition): hover waits. */
29
+ get Paused() { return this.paused; }
26
30
  /**
27
31
  * The mouse (or a pen in range) moved to (x, y), canvas pixels, nothing pressed. The hit path is taken also while
28
32
  * hover waits (the cursor follows it), hover changes only when nothing moves.
@@ -43,6 +47,8 @@ export class HoverManager {
43
47
  path.length = 0;
44
48
  this.PathX.length = 0;
45
49
  this.PathY.length = 0;
50
+ if (this.RootAt)
51
+ root = this.RootAt(this.x, this.y);
46
52
  if (root && root.IsVisible && !root.InputTransparent) {
47
53
  const point = root.TransformPointToLocalSpace(new SKPoint(this.x, this.y));
48
54
  if (root.HitIsInside(point.X, point.Y))
@@ -15,9 +15,16 @@ export declare class KeyboardManager {
15
15
  private static readonly keyChar;
16
16
  static get IsShiftPressed(): boolean;
17
17
  static get IsControlPressed(): boolean;
18
+ /** True while the keydown handlers run: a popup opened now was opened from the keyboard (Alt+F). */
19
+ static IsDispatchingKeyDown: boolean;
18
20
  static get IsAltPressed(): boolean;
19
21
  /** C# AttachToKeyboardAsync / JS attachGlobalKeyboard: idempotent. */
20
22
  static AttachToKeyboard(): void;
23
+ /**
24
+ * The modifier state follows each key event's own flags: a modifier pressed while the page had no focus (its keydown
25
+ * went elsewhere) still counts, and one released elsewhere stops counting.
26
+ */
27
+ private static SyncModifiers;
21
28
  static Subscribe(down: (key: InputKey, e: KeyboardEvent) => void, char: (ch: string, e: KeyboardEvent) => void, up?: (key: InputKey, e: KeyboardEvent) => void): void;
22
29
  static Unsubscribe(down: (key: InputKey, e: KeyboardEvent) => void, char: (ch: string, e: KeyboardEvent) => void, up?: (key: InputKey, e: KeyboardEvent) => void): void;
23
30
  /**
@@ -6,6 +6,8 @@ export class KeyboardManager {
6
6
  static keyChar = new Set();
7
7
  static get IsShiftPressed() { return KeyboardManager.pressed.has("ShiftLeft") || KeyboardManager.pressed.has("ShiftRight"); }
8
8
  static get IsControlPressed() { return KeyboardManager.pressed.has("ControlLeft") || KeyboardManager.pressed.has("ControlRight") || KeyboardManager.pressed.has("MetaLeft") || KeyboardManager.pressed.has("MetaRight"); }
9
+ /** True while the keydown handlers run: a popup opened now was opened from the keyboard (Alt+F). */
10
+ static IsDispatchingKeyDown = false;
9
11
  static get IsAltPressed() { return KeyboardManager.pressed.has("AltLeft") || KeyboardManager.pressed.has("AltRight"); }
10
12
  /** C# AttachToKeyboardAsync / JS attachGlobalKeyboard: idempotent. */
11
13
  static AttachToKeyboard() {
@@ -16,9 +18,16 @@ export class KeyboardManager {
16
18
  window.addEventListener("pointerdown", () => window.focus(), true);
17
19
  window.addEventListener("keydown", (e) => {
18
20
  const code = e.code || "";
21
+ KeyboardManager.SyncModifiers(e);
19
22
  KeyboardManager.pressed.add(code);
20
- for (const h of [...KeyboardManager.keyDown])
21
- h(code, e);
23
+ KeyboardManager.IsDispatchingKeyDown = true;
24
+ try {
25
+ for (const h of [...KeyboardManager.keyDown])
26
+ h(code, e);
27
+ }
28
+ finally {
29
+ KeyboardManager.IsDispatchingKeyDown = false;
30
+ }
22
31
  const proxied = e.target?.dataset?.drawnuiTextInput === "1"; // TextInputProxy: characters come through its input events
23
32
  if (!proxied && e.key && e.key.length === 1 && !e.ctrlKey && !e.altKey && !e.metaKey)
24
33
  for (const h of [...KeyboardManager.keyChar])
@@ -26,12 +35,32 @@ export class KeyboardManager {
26
35
  }, true);
27
36
  window.addEventListener("keyup", (e) => {
28
37
  const code = e.code || "";
38
+ KeyboardManager.SyncModifiers(e);
29
39
  KeyboardManager.pressed.delete(code);
30
40
  for (const h of [...KeyboardManager.keyUp])
31
41
  h(code, e);
32
42
  }, true);
33
43
  window.addEventListener("blur", () => KeyboardManager.pressed.clear());
34
44
  }
45
+ /**
46
+ * The modifier state follows each key event's own flags: a modifier pressed while the page had no focus (its keydown
47
+ * went elsewhere) still counts, and one released elsewhere stops counting.
48
+ */
49
+ static SyncModifiers(e) {
50
+ const sync = (down, left, right) => {
51
+ const p = KeyboardManager.pressed;
52
+ if (!down) {
53
+ p.delete(left);
54
+ p.delete(right);
55
+ }
56
+ else if (!p.has(left) && !p.has(right))
57
+ p.add(left);
58
+ };
59
+ sync(!!e.altKey, "AltLeft", "AltRight");
60
+ sync(!!e.ctrlKey, "ControlLeft", "ControlRight");
61
+ sync(!!e.shiftKey, "ShiftLeft", "ShiftRight");
62
+ sync(!!e.metaKey, "MetaLeft", "MetaRight");
63
+ }
35
64
  static Subscribe(down, char, up) {
36
65
  KeyboardManager.AttachToKeyboard();
37
66
  KeyboardManager.keyDown.add(down);