diff --git a/docs/engineering/a11y-safety.md b/docs/engineering/a11y-safety.md
index 93d0b3ad..8e1e5946 100644
--- a/docs/engineering/a11y-safety.md
+++ b/docs/engineering/a11y-safety.md
@@ -22,22 +22,25 @@
- 鍵盤焦點:強烈靜態視覺回饋 (反轉、字體加粗)。
- 按壓狀態:獨立於焦點的第三層級。深色模式使用飽和暖色 (琥珀色 `255,200,120`),亮度差 **ΔL*≥13**。
- **Tritanopia 調整亮度公式**:$L_{tritan} = (R_{lin} \times 0.2126 + G_{lin} \times 0.7152) / 0.9278$。
- - **Dwell 與 Latest 交接**:共用眼動儀回饋按鈕使用 "FeedbackButton";回饋結束先還原 Color.Empty,再清除該按鈕的原生背景動畫快取,讓背景、文字與提示框於同一幀還原。不得為此切換 VisualStylesMode、重建 HWND 或改變版面。
- - 視窗未啟用時仍須保持懸停文字與背景成對,不以略過自訂回饋後交回原生懸停取代;這不應啟用視窗或移動焦點。
- - Dwell 更新在 UI 寫入前再次檢查動畫識別碼,避免過期更新重啟已結束的視覺。測試須涵蓋三種主題、啟用/未啟用視窗、預設/一般按鈕的整段過渡取樣,不能只檢查最後一幀。
+ - **Standard/Latest 與必要疊層**:共用回饋使用 `FeedbackButton`,一般、懸停及停用沿用原生 Standard 表面;不得將系統強調色假設為藍色,不以固定黑/白文字取代原生選色。
+ - 焦點反轉、粗體、按壓及提示框使用必要疊層,不寫入按鈕 BackColor/ForeColor,不切換 VisualStylesMode、不重建 HWND。保留 System 色彩模式、Deferred 顯示與必要重啟提示。
+ - 高對比焦點使用 Highlight/HighlightText;按壓交換此系統色對並加入固定位置的內框。兩狀態的文字與內框都須通過實際相鄰像素對比,不只依賴色相區分。
+ - 視窗未啟用時仍提供成對原生懸停與提示,不啟用視窗或移動焦點。滑鼠與 Space 按壓獨立管理;MouseLeave/Capture 取消只清除滑鼠來源,失焦或停用清除所有按壓。
+ - Dwell 使用控制項自己的 UI Timer。更新字型、DPI、語系或系統色只更新設定與繪圖,不重建互動狀態/重啟進度;取消、表單權杖結束、HandleDestroyed 與 Dispose 終止計時。進度不作為懸停狀態的替代旗標。權杖取消必須有獨立 UI 通知,滿格停止 Timer 或停用 UI 特效時也須清除提示;更換權杖及 Dispose 時解除舊註冊,已排程的舊通知不可影響新生命週期。
+ - 點擊後接合不得覆蓋更新的互動或明確取消,也不得自動產生點擊。測試涵蓋三主題、啟用/未啟用視窗、預設/一般按鈕、完整過渡與滑鼠/鍵盤交錯。
- **預設動作引導**:當焦點在輸入框時,`AcceptButton` 必須顯示與焦點框一致的情境感知邊框色;強視覺反轉情境使用 **Cyan / MediumBlue**,中性情境使用 **LightBlue / MediumBlue**。
- 輸入框與預設動作提示須共用情境選色,並在輸入框底色/焦點變更時重繪。Latest 的強調色按鈕不得使提示對比下降;可在提示邊框緊鄰處繪製對比襯底,保留按鈕本體與原生主題外觀,不得改變尺寸、Margin 或 Padding。
- 測試須量測實際渲染的邊框與相鄰背景,不得只比對顏色名稱;同時覆蓋反轉及中性情境、三種主題與進度條主填色的對比。文件中對比數值為四捨五入顯示,不取代未取整的最低門檻。
- **眼動儀優化與視覺穩定性**:
- **視覺凍結 (Zero-Jitter)**:狀態變更嚴禁變動物理尺寸、Margin 或 Padding。
- - **抗抖動鎖定 (Anti-Jitter Lock)**:初始化時預先計算 **Bold** 狀態最大寬度並鎖定為 `MinimumSize`。
- - **懸停進度條對比 (WCAG 1.4.11)**:填色須以按鈕「**實際**底色」為基準,使用 `btn.BackColor.GetBrightness() > 0.5f`(`Color.Empty` 時退回至 `!isDark`)動態選色,**禁止**直接使用 `isDark` 旗標(懸停時 `ApplyStrongVisual` 會反轉底色,`isDark` 與實際底色脫節):
- - 底色為淺色(亮度 > 0.5,含懸停反轉後的 White)→ **Green** + CVD 紋理 PaleGreen。
- - 底色為深色(亮度 ≤ 0.5,含懸停反轉後的 Black)→ **LimeGreen** + CVD 紋理 DarkGreen。
- - 自然狀態對比:淺色模式 Green vs `#DCDCDC` = 3.75:1 ✅;深色模式 LimeGreen vs `#3C3C3C` = 5.21:1 ✅。
- - 懸停反轉對比:深色模式 bg→White,Green vs White = 5.14:1 ✅;淺色模式 bg→Black,LimeGreen vs Black = 9.91:1 ✅。
+ - **抗抖動鎖定 (Anti-Jitter Lock)**:初始化時預先計算 **Bold** 狀態最大寬度並鎖定為 `MinimumSize`。AutoSize 的偏好高度須依 Bold 文字及 DPI 預留原生置中文字上下的固定空間,確保完整 Dwell 襯底與字形不重疊;不得等懸停才擴高或改 Padding。
+ - **懸停進度條對比 (WCAG 1.4.11)**:以實際相鄰的可見襯底為基準,不以原生按鈕 BackColor 屬性推測已渲染的強調色。填滿至 100% 時襯底仍須在四邊可見(至少 1 個實體像素,依 DPI 縮放)。
+ - 淺色使用 #DCDCDC 襯底、Green 主填色、PaleGreen 色覺紋理,主填色對比約 3.75:1。
+ - 深色使用 #3C3C3C 襯底、LimeGreen 主填色、DarkGreen 色覺紋理,主填色對比約 5.21:1。
+ - 高對比使用 Highlight 襯底與 HighlightText 填色,不硬編碼替代系統色。
+ - 主填色對襯底須 ≥3:1;紋理不能取代主填色門檻,亦不把裝飾混色像素誤當成主填色。襯底與進度皆在固定範圍內繪製,不變動控制項尺寸、Margin 或 Padding。
- **色覺友善 (CVD) 與亮度計算**:
- - **情境感知焦點邊框色**:依 `BackColor` 實際值與主題動態選取(完整 4 情境):
+ - **情境感知焦點邊框色**:依目前視覺表面/輸入情境與主題動態選取(完整 4 情境):
- `BackColor == Black`(淺色反轉,強視覺)→ `Cyan` (16.75:1 AAA)
- `BackColor == White`(深色反轉,強視覺)→ `MediumBlue` (11.16:1 AAA)
- 深色中性(未反轉,深色主題)→ `LightBlue` (≥7.2:1 AAA)
diff --git a/src/InputBox/Core/Controls/FeedbackButton.cs b/src/InputBox/Core/Controls/FeedbackButton.cs
index 64333378..d92841be 100644
--- a/src/InputBox/Core/Controls/FeedbackButton.cs
+++ b/src/InputBox/Core/Controls/FeedbackButton.cs
@@ -1,8 +1,406 @@
-namespace InputBox.Core.Controls;
+using InputBox.Core.Configuration;
+using InputBox.Core.Extensions;
+using InputBox.Resources;
+using System.Drawing.Drawing2D;
-/// 保留原生 Latest 外觀,並提供自訂回饋結束時的原生色彩快取重設。
+namespace InputBox.Core.Controls;
+
+/// 原生 Standard/Latest 表面與專案必要的焦點、按壓及凝視提示。
public class FeedbackButton : Button
{
- /// 透過 WinForms 既有主題刷新路徑終止舊色動畫,不改變樣式、HWND 或版面。
- internal void ResetNativeColorTransition() => base.OnSystemColorsChanged(EventArgs.Empty);
-}
\ No newline at end of file
+ private readonly System.Windows.Forms.Timer _timer = new() { Interval = (int)Math.Round(AppSettings.TargetFrameTimeMs) };
+ private bool _hovered;
+ private bool _pointerPressed;
+ private bool _keyboardPressed;
+ private long _started;
+ private float _progress;
+ private Font? _regular;
+ private Font? _bold;
+ private bool _configured;
+ private string _description = string.Empty;
+ private Action? _onFocusStateChanged;
+ private CancellationToken _formToken;
+ private CancellationTokenRegistration _formRegistration;
+ private int _lifetimeVersion;
+ private int _interactionVersion;
+
+ public FeedbackButton()
+ {
+ FlatStyle = FlatStyle.Standard;
+ SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
+ _timer.Tick += (_, _) =>
+ {
+ if (!_hovered || Pressed || !Enabled || IsDisposed || !IsHandleCreated || _formToken.IsCancellationRequested)
+ {
+ StopDwell();
+ return;
+ }
+ _progress = Math.Min(1, (Environment.TickCount64 - _started) / 1000f);
+ Invalidate();
+ if (_progress >= 1)
+ {
+ _timer.Stop();
+ }
+ };
+ }
+
+ /// 目前的按壓視覺,滑鼠與鍵盤來源分開清理。
+ internal bool Pressed => _pointerPressed || _keyboardPressed;
+ /// 供畫面回歸驗證讀取,不以進度推導互動狀態。
+ internal float Progress => _progress;
+
+ /// 初始化或更新字型/在地化設定,不重新建立互動狀態或動畫。
+ internal void ConfigureFeedback(string description, Font? regular, Font? bold,
+ Action? onFocusStateChanged, CancellationToken formToken)
+ {
+ _regular = regular ?? Font;
+ _bold = bold;
+ _description = description;
+ _onFocusStateChanged = onFocusStateChanged;
+ FlatStyle = FlatStyle.Standard;
+ bool replaceLifetime = !_configured || _formToken != formToken;
+ _configured = true;
+ if (replaceLifetime)
+ {
+ int version = ++_lifetimeVersion;
+ _formRegistration.Dispose();
+ _formToken = formToken;
+ _formRegistration = formToken.Register(() =>
+ {
+ if (IsDisposed || Disposing || !IsHandleCreated) { return; }
+ this.SafeBeginInvoke(() =>
+ {
+ if (_configured && version == _lifetimeVersion && _formToken.IsCancellationRequested)
+ {
+ CancelDwell();
+ }
+ });
+ });
+ }
+ Reconcile();
+ }
+
+ /// 初始化版面時在置中文字上下保留固定空間,讓底部 Dwell 不遮住字形。
+ public override Size GetPreferredSize(Size proposedSize)
+ {
+ Size preferred = base.GetPreferredSize(proposedSize);
+ Font measuringFont = _bold ?? _regular ?? Font;
+ Size text = TextRenderer.MeasureText(Text, measuringFont);
+ float scale = DeviceDpi / AppSettings.BaseDpi;
+ int dwellSpace = (int)Math.Ceiling(7 * scale) + (int)Math.Ceiling(6 * scale) +
+ 2 * (int)Math.Max(1, Math.Ceiling(scale)) + (int)Math.Ceiling(2 * scale);
+ return new Size(Math.Max(preferred.Width, text.Width + Padding.Horizontal + (int)Math.Ceiling(8 * scale)),
+ Math.Max(preferred.Height, text.Height + Padding.Vertical + 2 * dwellSpace));
+ }
+ /// 更新呼叫端提供的共享字型,保留描述、回呼與正在進行的互動。
+ internal void UpdateFeedbackFonts(Font regular, Font? bold)
+ {
+ _regular = regular;
+ _bold = bold;
+ Reconcile();
+ }
+ internal void CancelDwell()
+ {
+ ++_interactionVersion;
+ StopDwell();
+ Reconcile();
+ }
+
+ /// 點擊結束後依實際游標重接視線;新的互動會使舊接合失效。
+ internal async Task ReGazeAfterClickAsync()
+ {
+ int version = ++_interactionVersion;
+ StopDwell();
+ Invalidate();
+ await Task.Yield();
+ if (IsDisposed || !Enabled || _formToken.IsCancellationRequested || version != _interactionVersion)
+ {
+ return;
+ }
+ _hovered = ClientRectangle.Contains(PointToClient(Cursor.Position));
+ RestartDwell();
+ Reconcile();
+ }
+ private void RestartDwell()
+ {
+ StopDwell();
+ if (!_configured || !_hovered || Pressed || !Enabled || _formToken.IsCancellationRequested)
+ {
+ return;
+ }
+ _started = Environment.TickCount64;
+ if (SystemInformation.UIEffectsEnabled)
+ {
+ _timer.Start();
+ }
+ else
+ {
+ _progress = 1;
+ }
+ }
+
+ private void StopDwell()
+ {
+ _timer.Stop();
+ bool visibleProgress = _progress > 0;
+ _progress = 0;
+ if (visibleProgress && IsHandleCreated && !IsDisposed && !Disposing) { Invalidate(); }
+ }
+
+ private void Reconcile()
+ {
+ if (!_configured || IsDisposed || Disposing) { return; }
+ Font? desired = Pressed || (Focused && !_hovered) ? _bold : _regular;
+ if (desired is not null && !ReferenceEquals(Font, desired))
+ {
+ Font = desired;
+ }
+ AccessibleDescription = !Enabled ? _description : Pressed ?
+ $"{_description} ({Strings.A11y_State_Pressed})" : _hovered ?
+ $"{_description} ({Strings.A11y_State_Hover})" : Focused ?
+ $"{_description} ({Strings.A11y_State_Focused})" : _description;
+ Invalidate();
+ }
+
+ protected override void OnMouseEnter(EventArgs e)
+ {
+ ++_interactionVersion;
+ _hovered = true;
+ RestartDwell();
+ Reconcile();
+ _onFocusStateChanged?.Invoke(true);
+ base.OnMouseEnter(e);
+ }
+
+ protected override void OnMouseLeave(EventArgs e)
+ {
+ ++_interactionVersion;
+ _hovered = false;
+ _pointerPressed = false;
+ StopDwell();
+ Reconcile();
+ _onFocusStateChanged?.Invoke(Focused);
+ base.OnMouseLeave(e);
+ }
+
+ protected override void OnMouseDown(MouseEventArgs e)
+ {
+ ++_interactionVersion;
+ if (Enabled && e.Button == MouseButtons.Left)
+ {
+ _pointerPressed = true;
+ StopDwell();
+ Reconcile();
+ }
+ base.OnMouseDown(e);
+ }
+
+ protected override void OnMouseUp(MouseEventArgs e)
+ {
+ ++_interactionVersion;
+ if (e.Button == MouseButtons.Left)
+ {
+ _pointerPressed = false;
+ RestartDwell();
+ Reconcile();
+ }
+ base.OnMouseUp(e);
+ }
+
+ protected override void OnKeyDown(KeyEventArgs e)
+ {
+ ++_interactionVersion;
+ if (Enabled && Focused && e.KeyCode == Keys.Space)
+ {
+ _keyboardPressed = true;
+ StopDwell();
+ Reconcile();
+ }
+ base.OnKeyDown(e);
+ }
+
+ protected override void OnKeyUp(KeyEventArgs e)
+ {
+ ++_interactionVersion;
+ if (e.KeyCode == Keys.Space)
+ {
+ _keyboardPressed = false;
+ RestartDwell();
+ Reconcile();
+ }
+ base.OnKeyUp(e);
+ }
+
+ protected override void OnGotFocus(EventArgs e)
+ {
+ ++_interactionVersion;
+ Reconcile();
+ _onFocusStateChanged?.Invoke(true);
+ base.OnGotFocus(e);
+ }
+
+ protected override void OnLostFocus(EventArgs e)
+ {
+ ++_interactionVersion;
+ _pointerPressed = false;
+ _keyboardPressed = false;
+ RestartDwell();
+ Reconcile();
+ _onFocusStateChanged?.Invoke(_hovered);
+ base.OnLostFocus(e);
+ }
+
+ protected override void OnMouseCaptureChanged(EventArgs e)
+ {
+ if (!Capture && _pointerPressed)
+ {
+ ++_interactionVersion;
+ _pointerPressed = false;
+ RestartDwell();
+ Reconcile();
+ }
+ base.OnMouseCaptureChanged(e);
+ }
+
+ protected override void OnEnabledChanged(EventArgs e)
+ {
+ ++_interactionVersion;
+ if (!Enabled)
+ {
+ _hovered = false;
+ _pointerPressed = false;
+ _keyboardPressed = false;
+ StopDwell();
+ }
+ Reconcile();
+ base.OnEnabledChanged(e);
+ }
+
+ protected override void OnSystemColorsChanged(EventArgs e)
+ {
+ base.OnSystemColorsChanged(e);
+ Invalidate();
+ }
+
+ protected override void OnHandleDestroyed(EventArgs e)
+ {
+ ++_interactionVersion;
+ StopDwell();
+ _hovered = false;
+ _pointerPressed = false;
+ _keyboardPressed = false;
+ base.OnHandleDestroyed(e);
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ _configured = false;
+ ++_lifetimeVersion;
+ _formRegistration.Dispose();
+ StopDwell();
+ _regular = null;
+ _bold = null;
+ _onFocusStateChanged = null;
+ }
+ try
+ {
+ base.Dispose(disposing);
+ }
+ finally
+ {
+ if (disposing) { _timer.Dispose(); }
+ }
+ }
+ protected override void OnPaint(PaintEventArgs e)
+ {
+ if (Width <= 0 || Height <= 0)
+ {
+ return;
+ }
+ base.OnPaint(e);
+ if (!_configured) { return; }
+ Graphics graphics = e.Graphics;
+ bool dark = this.IsDarkModeActive();
+ bool highContrast = SystemInformation.HighContrast;
+ bool strong = Enabled && (Pressed || (Focused && !_hovered));
+ bool isDefault = Enabled && FindForm() is Form form &&
+ ReferenceEquals(form.AcceptButton, this) && form.ActiveControl is not Button;
+ float scale = DeviceDpi / AppSettings.BaseDpi;
+ Color back = Color.Empty;
+ Color fore = ForeColor;
+ if (strong)
+ {
+ (back, fore) = highContrast
+ ? Pressed ? (SystemColors.HighlightText, SystemColors.Highlight) : (SystemColors.Highlight, SystemColors.HighlightText)
+ : Pressed ? (dark ? Color.FromArgb(255, 200, 120) : Color.FromArgb(28, 28, 28), dark ? Color.Black : Color.White)
+ : dark ? (Color.White, Color.Black) : (Color.Black, Color.White);
+ using Brush surface = new SolidBrush(back);
+ graphics.FillRectangle(surface, ClientRectangle);
+ int inset = (int)Math.Ceiling(4 * scale);
+ TextFormatFlags flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter |
+ TextFormatFlags.WordBreak | TextFormatFlags.PreserveGraphicsClipping;
+ if (!UseMnemonic)
+ {
+ flags |= TextFormatFlags.NoPrefix;
+ }
+ if (RightToLeft == RightToLeft.Yes)
+ {
+ flags |= TextFormatFlags.RightToLeft;
+ }
+ if (!ShowKeyboardCues) { flags |= TextFormatFlags.HidePrefix; }
+ Rectangle textBounds = Rectangle.FromLTRB(inset + Padding.Left, inset + Padding.Top,
+ Width - inset - Padding.Right, Height - inset - Padding.Bottom);
+ TextRenderer.DrawText(graphics, Text, Font, textBounds, fore, flags);
+ }
+
+ if (Enabled && (strong || _hovered || isDefault))
+ {
+ (Color border, Color backing) = strong
+ ? highContrast ? (fore, back) : (dark ? Color.MediumBlue : Color.Cyan, back)
+ : ControlExtensions.GetContextualFocusColors(isDefault ? GetInputContext()?.BackColor ?? Color.Empty : Color.Empty, dark);
+ this.DrawButtonInteractiveBorder(graphics, border, scale, out int inset, out int thickness, backing);
+ if (Pressed)
+ {
+ // 高對比也保留固定位置的內框,提供不只依賴色彩的按壓線索。
+ int inner = inset + thickness + (int)Math.Ceiling(scale);
+ using Pen line = new(fore, Math.Max(1, 2 * scale));
+ graphics.DrawRectangle(line, inner, inner, Width - 2 * inner - 1, Height - 2 * inner - 1);
+ }
+ }
+
+ if (Enabled && _hovered && !Pressed && _progress > 0)
+ {
+ int inset = (int)Math.Ceiling(7 * scale);
+ int backing = (int)Math.Max(1, Math.Ceiling(scale));
+ int height = (int)Math.Ceiling(6 * scale) + 2 * backing;
+ Rectangle track = new(inset, Height - inset - height, Width - 2 * inset, height);
+ Color trackColor = highContrast ? SystemColors.Highlight : dark ? Color.FromArgb(60, 60, 60) : Color.FromArgb(220, 220, 220);
+ Color fillColor = highContrast ? SystemColors.HighlightText : dark ? Color.LimeGreen : Color.Green;
+ using Brush trackBrush = new SolidBrush(trackColor);
+ using Brush fillBrush = new SolidBrush(fillColor);
+ graphics.FillRectangle(trackBrush, track);
+ Rectangle fill = Rectangle.Inflate(track, -backing, -backing);
+ fill.Width = (int)(fill.Width * _progress);
+ graphics.FillRectangle(fillBrush, fill);
+ if (!highContrast)
+ {
+ using HatchBrush texture = new(HatchStyle.BackwardDiagonal, dark ? Color.DarkGreen : Color.PaleGreen, Color.Transparent);
+ graphics.FillRectangle(texture, fill);
+ }
+ }
+
+ }
+
+ /// 沿巢狀容器尋找實際輸入焦點,與輸入框提示共用情境選色。
+ private Control? GetInputContext()
+ {
+ Control? context = FindForm()?.ActiveControl;
+ while (context is ContainerControl { ActiveControl: not null } container)
+ {
+ context = container.ActiveControl;
+ }
+ return context;
+ }
+}
diff --git a/src/InputBox/Core/Controls/GamepadCalibrationDialog.Layout.cs b/src/InputBox/Core/Controls/GamepadCalibrationDialog.Layout.cs
index c9068990..de46acfd 100644
--- a/src/InputBox/Core/Controls/GamepadCalibrationDialog.Layout.cs
+++ b/src/InputBox/Core/Controls/GamepadCalibrationDialog.Layout.cs
@@ -70,9 +70,9 @@ protected override void OnDpiChanged(DpiChangedEventArgs e)
_lblStatus?.Font = _a11yFont;
- _btnReset?.Font = _a11yFont;
+ _btnReset?.UpdateEyeTrackerFonts(_a11yFont, MainForm.GetSharedA11yFont(DeviceDpi, FontStyle.Bold, _a11yFont.FontFamily));
- _btnClose?.Font = _a11yFont;
+ _btnClose?.UpdateEyeTrackerFonts(_a11yFont, MainForm.GetSharedA11yFont(DeviceDpi, FontStyle.Bold, _a11yFont.FontFamily));
}
UpdateMinimumSize(forceRecalculate: true);
diff --git a/src/InputBox/Core/Controls/GamepadCalibrationDialog.cs b/src/InputBox/Core/Controls/GamepadCalibrationDialog.cs
index 20fb41c6..cd7112fa 100644
--- a/src/InputBox/Core/Controls/GamepadCalibrationDialog.cs
+++ b/src/InputBox/Core/Controls/GamepadCalibrationDialog.cs
@@ -393,7 +393,7 @@ private Button CreateEyeTrackerButton(string text, string accessibleName, string
AutoSize = true,
MinimumSize = new Size(Math.Max((int)(120 * scale), boldTextSize.Width + (int)(32 * scale)), Math.Max((int)(56 * scale), boldTextSize.Height + (int)(20 * scale))),
Margin = new Padding((int)(8 * scale), (int)(6 * scale), (int)(8 * scale), (int)(4 * scale)),
- FlatStyle = FlatStyle.Flat,
+ FlatStyle = FlatStyle.Standard,
BackColor = Color.Empty,
ForeColor = Color.Empty
};
diff --git a/src/InputBox/Core/Controls/GamepadMessageBox.cs b/src/InputBox/Core/Controls/GamepadMessageBox.cs
index 01ab3a01..1827c42c 100644
--- a/src/InputBox/Core/Controls/GamepadMessageBox.cs
+++ b/src/InputBox/Core/Controls/GamepadMessageBox.cs
@@ -429,7 +429,7 @@ private Button CreateEyeTrackerButton(string label)
AccessibleRole = AccessibleRole.PushButton,
Font = font,
AutoSize = true,
- FlatStyle = FlatStyle.Flat,
+ FlatStyle = FlatStyle.Standard,
BackColor = Color.Empty,
ForeColor = Color.Empty,
};
@@ -785,7 +785,7 @@ private void ApplyFont()
continue;
}
- btn.Font = shared;
+ btn.UpdateEyeTrackerFonts(shared, boldFont);
DialogLayoutHelper.UpdateButtonMinimumSize(btn, boldFont, scale, 88, 0, 24, 8);
}
diff --git a/src/InputBox/Core/Controls/HelpDialog.cs b/src/InputBox/Core/Controls/HelpDialog.cs
index da85c6ff..c97ccdc2 100644
--- a/src/InputBox/Core/Controls/HelpDialog.cs
+++ b/src/InputBox/Core/Controls/HelpDialog.cs
@@ -175,7 +175,7 @@ public HelpDialog()
AutoSize = true,
Anchor = AnchorStyles.Right,
Margin = Padding.Empty, // 移除預設外距避免被底部面板裁切
- FlatStyle = FlatStyle.Flat,
+ FlatStyle = FlatStyle.Standard,
AccessibleName = Strings.Help_Btn_Close,
AccessibleRole = AccessibleRole.PushButton,
DialogResult = DialogResult.Cancel,
diff --git a/src/InputBox/Core/Controls/NumericInputDialog.Layout.cs b/src/InputBox/Core/Controls/NumericInputDialog.Layout.cs
index 546e57fd..64c0f946 100644
--- a/src/InputBox/Core/Controls/NumericInputDialog.Layout.cs
+++ b/src/InputBox/Core/Controls/NumericInputDialog.Layout.cs
@@ -89,11 +89,11 @@ protected override void OnDpiChanged(DpiChangedEventArgs e)
// 同步更新所有按鈕的基礎字體。
if (_a11yFont != null)
{
- _btnOk!.Font = _a11yFont;
- _btnCancel!.Font = _a11yFont;
- _btnPlus!.Font = _a11yFont;
- _btnMinus!.Font = _a11yFont;
- _btnReset!.Font = _a11yFont;
+ _btnOk!.UpdateEyeTrackerFonts(_a11yFont, MainForm.GetSharedA11yFont(DeviceDpi, FontStyle.Bold, _a11yFont.FontFamily));
+ _btnCancel!.UpdateEyeTrackerFonts(_a11yFont, MainForm.GetSharedA11yFont(DeviceDpi, FontStyle.Bold, _a11yFont.FontFamily));
+ _btnPlus!.UpdateEyeTrackerFonts(_a11yFont, MainForm.GetSharedA11yFont(DeviceDpi, FontStyle.Bold, _a11yFont.FontFamily));
+ _btnMinus!.UpdateEyeTrackerFonts(_a11yFont, MainForm.GetSharedA11yFont(DeviceDpi, FontStyle.Bold, _a11yFont.FontFamily));
+ _btnReset!.UpdateEyeTrackerFonts(_a11yFont, MainForm.GetSharedA11yFont(DeviceDpi, FontStyle.Bold, _a11yFont.FontFamily));
}
// 數值顯示區字體需重新依據新縮放比例建立。
diff --git a/src/InputBox/Core/Controls/NumericInputDialog.cs b/src/InputBox/Core/Controls/NumericInputDialog.cs
index 166dd77f..28921328 100644
--- a/src/InputBox/Core/Controls/NumericInputDialog.cs
+++ b/src/InputBox/Core/Controls/NumericInputDialog.cs
@@ -916,7 +916,7 @@ private Button CreateEyeTrackerButton(
AutoSize = true,
MinimumSize = new Size(baseMinWidth, baseMinHeight),
Margin = new Padding((int)(12 * scale)),
- FlatStyle = FlatStyle.Flat,
+ FlatStyle = FlatStyle.Standard,
BackColor = Color.Empty,
ForeColor = Color.Empty
};
diff --git a/src/InputBox/Core/Controls/PhraseEditDialog.cs b/src/InputBox/Core/Controls/PhraseEditDialog.cs
index 4b6ba881..1d724d27 100644
--- a/src/InputBox/Core/Controls/PhraseEditDialog.cs
+++ b/src/InputBox/Core/Controls/PhraseEditDialog.cs
@@ -338,7 +338,7 @@ public PhraseEditDialog(string name, string content, Font? a11yFont)
{
Text = profile.FormatCancelButtonText(Strings.Phrase_Btn_Cancel),
AutoSize = true,
- FlatStyle = FlatStyle.Flat,
+ FlatStyle = FlatStyle.Standard,
DialogResult = DialogResult.Cancel,
BackColor = Color.Empty,
ForeColor = Color.Empty,
@@ -354,7 +354,7 @@ public PhraseEditDialog(string name, string content, Font? a11yFont)
{
Text = profile.FormatConfirmButtonText(Strings.Phrase_Btn_Confirm),
AutoSize = true,
- FlatStyle = FlatStyle.Flat,
+ FlatStyle = FlatStyle.Standard,
// 重要:確認按鈕不可直接回傳 OK,必須先經過 HandleConfirm 驗證。
DialogResult = DialogResult.None,
BackColor = Color.Empty,
diff --git a/src/InputBox/Core/Controls/PhraseManagerDialog.Layout.cs b/src/InputBox/Core/Controls/PhraseManagerDialog.Layout.cs
index fb4bde54..2df74e61 100644
--- a/src/InputBox/Core/Controls/PhraseManagerDialog.Layout.cs
+++ b/src/InputBox/Core/Controls/PhraseManagerDialog.Layout.cs
@@ -127,7 +127,7 @@ private static Button CreateActionButton(
{
Text = ControlExtensions.GetMnemonicText(text, mnemonic),
AutoSize = true,
- FlatStyle = FlatStyle.Flat,
+ FlatStyle = FlatStyle.Standard,
AccessibleName = text,
AccessibleDescription = a11yDesc,
AccessibleRole = AccessibleRole.PushButton,
diff --git a/src/InputBox/Core/Controls/PhraseManagerDialog.cs b/src/InputBox/Core/Controls/PhraseManagerDialog.cs
index 5126f728..ba0fe58f 100644
--- a/src/InputBox/Core/Controls/PhraseManagerDialog.cs
+++ b/src/InputBox/Core/Controls/PhraseManagerDialog.cs
@@ -361,7 +361,7 @@ public PhraseManagerDialog(PhraseService phraseService)
Text = profile.FormatCancelButtonText(Strings.Phrase_Btn_Close),
AutoSize = true,
Anchor = AnchorStyles.Right,
- FlatStyle = FlatStyle.Flat,
+ FlatStyle = FlatStyle.Standard,
AccessibleName = Strings.Phrase_Btn_Close,
AccessibleDescription = Strings.Phrase_A11y_Btn_Close_Desc,
AccessibleRole = AccessibleRole.PushButton,
diff --git a/src/InputBox/Core/Extensions/ButtonEyeTrackerExtensions.cs b/src/InputBox/Core/Extensions/ButtonEyeTrackerExtensions.cs
index 8d7470b4..a2e33e98 100644
--- a/src/InputBox/Core/Extensions/ButtonEyeTrackerExtensions.cs
+++ b/src/InputBox/Core/Extensions/ButtonEyeTrackerExtensions.cs
@@ -1,749 +1,27 @@
-using InputBox.Core.Configuration;
-using InputBox.Core.Controls;
-using InputBox.Resources;
-using System.Diagnostics;
-using System.Drawing.Drawing2D;
-using System.Runtime.CompilerServices;
+using InputBox.Core.Controls;
namespace InputBox.Core.Extensions;
-///
-/// 按鈕眼動儀回饋擴充方法,
-/// 統一收斂對話框的 A11y Boilerplate
-///
+/// 將現有表單的回饋設定與點擊接合呼叫導向共用按鈕,不維護第二份狀態。
public static class ButtonEyeTrackerExtensions
{
- ///
- /// 按鈕視覺狀態封裝類別,
- /// 包含當前是否懸停、按壓、凝視進度,以及相關的字型與描述資訊
- ///
- private sealed class ButtonVisualState
+ /// 更新共用按鈕的描述、共享字型與表單生命週期;不重建正在進行的互動。
+ public static void AttachEyeTrackerFeedback(this Button btn, string baseDescription,
+ Font? regularFont, Font? boldFont, CancellationToken formCt, Action? onFocusStateChanged = null)
{
- ///
- /// 是否懸停在按鈕上
- ///
- public bool IsHovered { get; set; }
-
- ///
- /// 是否按壓按鈕(包含實際的鼠標按壓或鍵盤焦點狀態下的強視覺反饋)
- ///
- public bool IsPressed => IsPointerPressed || IsKeyboardPressed;
-
- /// 滑鼠按壓狀態,與鍵盤狀態獨立清理。
- public bool IsPointerPressed { get; set; }
-
- /// Space 按壓狀態,失焦時必須清理。
- public bool IsKeyboardPressed { get; set; }
-
- ///
- /// 凝視進度(Dwell Progress),表示使用者注視按鈕的時間比例
- ///
- public float DwellProgress { get; set; }
-
- ///
- /// 動畫識別碼,用於取消過時的動畫回饋,確保視覺狀態與當前互動一致
- ///
- public long AnimId;
-
- /// 重設原生色彩快取期間避免系統色事件重入。
- public bool IsResettingNativeColors { get; set; }
-
- ///
- /// 基礎無障礙描述,供不同互動狀態下的 AccessibleDescription 組合使用
- ///
- public string BaseDescription { get; set; } = string.Empty;
-
- ///
- /// 按鈕預設狀態下的字型(傳入 null 則 fallback 為按鈕現有字型)
- ///
- public Font? RegularFont { get; set; }
-
- ///
- /// 粗體字型,用於按鈕取得焦點或按壓時的強調視覺(傳入 null 則維持 RegularFont),建議外部預先建立好 Font 實例以避免頻繁產生造成效能問題
- ///
- public Font? BoldFont { get; set; }
-
- ///
- /// 當按鈕焦點狀態或懸停狀態改變時觸發的回呼,供外部連動處理(例如提示標籤顯示)
- ///
- public Action? OnFocusStateChanged { get; set; }
-
- ///
- /// 綁定 UI 表單生命週期的 CancellationToken,用於安全終止按鈕內部非同步動畫
- ///
- public CancellationToken FormCt { get; set; }
-
- ///
- /// 按鈕的原始內邊距,用於在視覺狀態改變時恢復原始佈局
- ///
- public Padding OriginalPadding { get; set; }
- }
-
- ///
- /// 按鈕與其視覺狀態的映射表,
- /// 用於管理按鈕的眼動儀回饋與無障礙狀態
- ///
- private static readonly ConditionalWeakTable