Files
msime-windows/server/docs/ui-backends.md
T
Lu Fan(SonnyCalcr) 53649d9d12 feat(server,ui,ui-html): 新增实验性的 Direct2D 设置窗口 (#999)
* feat(ui): 动画时钟、渲染剔除与文本框扩展,并优化 msimeui 性能

- 新增 Animation.h:cubic-bezier 缓动、Tween、颜色插值,Window 提供
  RequestAnimationFrame / GetFrameTime,动画帧随显示刷新率推进
- Window 可选 DirectComposition 渲染(含不透明模式以支持 ClearType)、
  双击按下、捕获丢失时结束按压、悬停刷新、可关闭销毁时退出消息循环
- Scene 把滚轮交给光标下最内层可滚动元素并逐级冒泡
- DeviceResources:裁剪栈驱动的离屏剔除、按帧回收的笔刷缓存、SVG 栅格缓存
- ScrollViewer 可配置外观与平滑滚动;Popup 支持阴影通道与出现动画;
  卡片阴影缓存抽成可复用的 ShadowCache
- TextBox 支持 SetText、密码掩码、多行滚动、字重/字间距/行高与外观设置
- 调试日志默认关闭(MSIMEUI_DEBUG_LOG=1 才写文件),不再在每次点击和
  TSF GetTextExt 时打开文件
- 字体回退在 CJK/emoji 映射之后保留系统回退,缺字不再显示方框
- 新增动画与剔除单元测试

* feat(server): 新增实验性的 Direct2D 设置窗口

设置窗口可通过 appearance.settings_ui_backend 选择渲染方式:默认 webview2,
d2d 为实验性的 msimeui 原生实现(server/src/settings/native/),1:1 复刻
网页设置页,包括侧栏切换时竖向高亮条的滑动动画。

- 两个前端共用同一套 webview 契约消息与 HandleClientMessage,配置读写
  映射仍只在 settings_app.cpp
- 切换渲染方式后设置进程自动以新方式重新打开;--d2d / --webview2 可临时指定
- 新配置项写入出厂模板与开发配置,UiBackendPolicy 与测试同步更新
- METASEQUOIA_IME_SETTINGS_INSTANCE 允许开发版与已安装的设置窗口并存
- 更新 ui-backends 文档与 server/AGENTS.md

* feat(ui-html): 外观页新增设置窗口渲染方式选项
2026-10-16 16:13:13 +08:00

4.2 KiB
Raw Blame History

UI ownership and compatibility

Surface Long-term backend Compatibility scope
Candidate, floating toolbar, tray menu msimeui native Direct2D/DirectWrite appearance.ui_backend=webview2 explicitly selects existing WebView skins
Settings UiHtml hosted by the separate native settings application appearance.settings_ui_backend=d2d selects the experimental Direct2D frontend; small-window backend settings never change this host
Keyboard, handwriting, emoji and voice panels Their existing native application/presenter Shared actions/configuration stay in Server; panels do not own input sessions

window/ui_backend_policy.h owns backend selection. D2D is the default; existing WebView aliases remain readable. Unknown/retired stored values migrate to D2D, while new invalid configuration writes fail. A backend setting applies at process startup, preserving the existing controller lifetime and restart behavior.

The candidate worker resolves output text, auxiliary codes, source badges and translations once into CandidateViewItem. Both native and Web renderers consume these values. HTML escaping and the legacy comma framing are confined to the Web adapter; native rendering receives plain text. Both click paths enter the existing EnqueueCandidateUiAction queue with the same focus owner checks and action policy. The ten-entry mouse range is distinct from the 1–9 keyboard shortcuts.

WebView small windows remain a compatibility backend for existing skins. Their removal requires: a supported conversion path for CSS-dependent external skins; parity for candidate/context-menu actions, translations and accessibility; and recorded mixed-DPI, cold-start and signed/uiAccess host validation of the native replacement. Until those conditions are met, keep compatibility tests and do not silently reinterpret a configured WebView skin as a native skin. New business behavior belongs in shared actions/session/view models, not either renderer.

Direct2D settings window (experimental)

MetasequoiaImeSettings.exe has two frontends for the same window. WebView2 hosting ui-html/webview2/settings/ime-settings stays the default; appearance.settings_ui_backend = "d2d" (or --d2d on the command line for one run) draws the window with msimeui instead, in server/src/settings/native/. Both frontends speak the same webview contract: the native window receives configSnapshot and the response messages as JSON and posts configUpdate and the request messages through the dispatcher the WebView2 page uses (HandleClientMessage in settings_app.cpp), so config paths are still mapped in one place. Switching the setting reopens the settings process in the other renderer.

The native pages reproduce the HTML/CSS page one to one: each page builder in native_page_*.cpp follows its partial and module, and the controls in native_settings_controls.* name the CSS rule they mirror. A change to a settings page therefore has to be made on both sides until the WebView2 frontend is retired.

Sciter is not an active product backend. The old unreferenced handwritten D2D prototype is removed; native small windows use msimeui presenters. The msimeui library owns generic controls and rendering, never Server configuration, pipe sessions, dictionary access, or global input state.

v2 皮肤在两个后端下的渲染

schema_version = 2 的皮肤(九宫格贴图面板、自由锚定挂件、面板外空白)两个后端都支持,但走的是不同的实现:

  • WebView2 把面板翻成 CSS:border-image 铺九宫格,content_insets_dip 落成容器内边距,挂件用 .containerParent 的伪元素绝对定位。
  • D2D 用 CandidatePresenter 的本地场景:面板由 msimeui::Card::SetBackgroundImageNineSlice 画成九宫格,挂件由 CandidateSkinOverlay 这一层浮在卡片上,outer_insets_dip 换成窗口在卡片四边多留的空白。

两侧读同一份 skin.toml,字段语义必须一致,尤其是 anchor 与 offset_*_dip:正数向右、向下。改一侧的定位规则要同时改另一侧。

content_insets_dip 在两个后端都从面板外缘量起,D2D 侧由卡片内边距承担,不需要再扣边框。