Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
- 'src/InputBox/Resources/**'
- 'tests/InputBox.Tests/MainFormUiSmokeTests.cs'
- 'tests/InputBox.Tests/ButtonFeedbackRenderingTests.cs'
- 'tests/InputBox.Tests/BlinkFrameRenderingTests.cs'
- 'tests/InputBox.Tests/UiSmokeTestRequirements.cs'
- 'tests/InputBox.Tests/UiVisualSnapshot.cs'
- 'tests/InputBox.Tests/UiWindowDiscovery.cs'
Expand Down
1 change: 1 addition & 0 deletions src/InputBox/Core/Controls/NumericInputDialog.A11y.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void ApplyAlertVisuals(float intensity)

// 恢復焦點視覺狀態。
UpdateFocusVisuals(_nud.Focused || _nud.ContainsFocus);
_nud.RedrawVisualFrameRecursive();
}
catch (Exception ex)
{
Expand Down
2 changes: 2 additions & 0 deletions src/InputBox/Core/Controls/PhraseEditDialog.A11y.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ void ApplyAlertVisuals(float intensity)
{
ResetInputBoxVisual(target);
}

target.RedrawVisualFrameRecursive();
}
catch (Exception ex)
{
Expand Down
21 changes: 20 additions & 1 deletion src/InputBox/Core/Extensions/ControlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,28 @@ public static void UpdateRecursive(
}
}

/// <summary>
/// 在最終配色套用後重繪控制項樹的客戶區及非客戶區,清除 Latest 邊框/內距的舊色。
/// 僅在 UI 執行緒上使用;不重建 HWND,不改變焦點、選取範圍或版面尺寸。
/// </summary>
/// <param name="control">需要還原框架的自家控制項。</param>
public static void RedrawVisualFrameRecursive(this Control control)
{
if (control.IsDisposed || !control.IsHandleCreated)
{
return;
}

_ = User32.RedrawWindow(control.Handle, 0, 0,
User32.RedrawFlags.Invalidate | User32.RedrawFlags.Frame | User32.RedrawFlags.UpdateNow);
foreach (Control child in control.Controls)
{
child.RedrawVisualFrameRecursive();
}
}
/// <summary>
/// 將控制項及其所有子控制項的顏色屬性重設為 Color.Empty,
/// 這將觸發 .NET 10 的原生主題引擎自動套用正確的系統配色。
/// 這將觸發原生主題引擎自動套用正確的系統配色。
/// </summary>
/// <param name="parent">父控制項。</param>
public static void ResetThemeRecursive(this Control parent)
Expand Down
20 changes: 20 additions & 0 deletions src/InputBox/Core/Interop/User32.Redraw.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Runtime.InteropServices;

namespace InputBox.Core.Interop;

public static partial class User32
{
/// <summary>要求指定自家控制項的客戶區與非客戶區立即重繪。</summary>
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static partial bool RedrawWindow(nint handle, nint updateRectangle, nint updateRegion, RedrawFlags flags);

/// <summary>重繪控制項框架所需的 Win32 旗標,不變更大小或重建 HWND。</summary>
[Flags]
internal enum RedrawFlags : uint
{
Invalidate = 0x0001,
UpdateNow = 0x0100,
Frame = 0x0400
}
}
3 changes: 3 additions & 0 deletions src/InputBox/MainForm.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,9 @@ private void RestoreInputVisualsAfterFlash()

// BackColor 設定完畢後再恢復邊框,確保情境感知選色與當前背景一致。
UpdateBorderColor(TBInput.Focused);

// Latest 的內距屬於非客戶區,顏色屬性還原不會自動清除該處的警示舊色。
PInputHost.RedrawVisualFrameRecursive();
}

/// <summary>
Expand Down
176 changes: 176 additions & 0 deletions tests/InputBox.Tests/BlinkFrameRenderingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
using InputBox.Core.Configuration;
using InputBox.Core.Extensions;
using InputBox.Core.Feedback;
using InputBox.Core.Interop;
using System.Runtime.ExceptionServices;
using Xunit;

namespace InputBox.Tests;

/// <summary>以實際畫面驗證 Blink 完成/取消後的非客戶區框架,不以重新繪圖的截圖 API 掩蓋殘影。</summary>
[Collection(UiSmokeTestRequirements.CollectionName)]
[Trait("Category", "UI")]
public sealed class BlinkFrameRenderingTests
{
/// <summary>以明確色彩模式建立獨立驗證程序,保留實際 Windows 高對比判斷。</summary>
static BlinkFrameRenderingTests()
{
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
Application.SetColorMode(Environment.GetEnvironmentVariable("INPUTBOX_BUTTON_TEST_DARK") == "1" ?
SystemColorMode.Dark : SystemColorMode.Classic);
}

/// <summary>焦點與非焦點的 Blink 完成及取消都應還原框架像素,並保留 HWND、選取及版面。</summary>
[Theory(Skip = "Requires explicit UI test opt-in.",
SkipUnless = nameof(UiSmokeTestRequirements.IsEnabled), SkipType = typeof(UiSmokeTestRequirements))]
[InlineData(true, false)]
[InlineData(false, false)]
[InlineData(true, true)]
[InlineData(false, true)]
public void Blink_Finally_RestoresFrameWithoutChangingInputState(bool focused, bool cancel)
{
Exception? failure = null;
var thread = new Thread(() =>
{
using var form = new Form { ClientSize = new Size(420, 180), TopMost = true, StartPosition = FormStartPosition.Manual, Location = new Point(10, 10) };
Rectangle screen = Screen.PrimaryScreen!.WorkingArea;
if (form.Bounds.Contains(Cursor.Position))
{
form.Location = new Point(screen.Right - form.Width - 20, screen.Bottom - form.Height - 20);
}
using var host = new Panel { Bounds = new Rectangle(10, 10, 350, 90), Padding = new Padding(4) };
using var input = new TextBox
{
Multiline = true, BorderStyle = BorderStyle.None, Dock = DockStyle.Fill,
VisualStylesMode = VisualStylesMode.Latest, Text = "Blink check"
};
using var other = new Button { Top = 120, Text = "Other" };
host.Controls.Add(input);
form.Controls.AddRange([host, other]);
form.Shown += async (_, _) =>
{
try
{
if (focused)
{
Assert.True(input.Focus());
}
else
{
Assert.True(other.Focus());
}
Restore(host, input);
host.RedrawVisualFrameRecursive();
await Task.Delay(500, TestContext.Current.CancellationToken);
input.Select(3, 2);
using Bitmap before = Capture(input);
Color expectedBack = input.BackColor;
Color expectedFore = input.ForeColor;
Color expectedBorder = host.BackColor;
nint handle = input.Handle;
Rectangle bounds = input.Bounds;
Padding padding = host.Padding;
using var stop = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
bool framePaintedDuringAlert = false;
try
{
await FlashAlertAnimator.RunAsync(form, intensity =>
{
(Color back, Color fore) = FlashAlertAnimator.ComputeFrameColors(intensity,
input.IsDarkModeActive(), FlashAlertAnimator.GetAlertColor(input.IsDarkModeActive(), SystemInformation.HighContrast),
SystemInformation.HighContrast);
host.UpdateRecursive(back, fore);
if (!framePaintedDuringAlert && intensity > 0.8f)
{
framePaintedDuringAlert = true;
_ = User32.RedrawWindow(input.Handle, 0, 0,
User32.RedrawFlags.Invalidate | User32.RedrawFlags.Frame | User32.RedrawFlags.UpdateNow);
if (cancel)
{
stop.Cancel();
}
}
}, stop.Token);
}
catch (OperationCanceledException) when (cancel && stop.IsCancellationRequested)
{
}
finally
{
Restore(host, input);
host.RedrawVisualFrameRecursive();
}
await Task.Delay(500, TestContext.Current.CancellationToken);
using Bitmap after = Capture(input);
Assert.True(framePaintedDuringAlert);
Assert.Equal(expectedBack, input.BackColor);
Assert.Equal(expectedFore, input.ForeColor);
Assert.Equal(expectedBorder, host.BackColor);
Assert.Equal(handle, input.Handle);
Assert.Equal(bounds, input.Bounds);
Assert.Equal(padding, host.Padding);
Assert.Equal(focused, input.Focused);
Assert.Equal(3, input.SelectionStart);
Assert.Equal(2, input.SelectionLength);
for (int x = 8; x < input.Width - 8; x++)
{
AssertFramePixel(before.GetPixel(x, 0), after.GetPixel(x, 0));
AssertFramePixel(before.GetPixel(x, input.Height - 1), after.GetPixel(x, input.Height - 1));
}
for (int y = input.Height / 2; y < input.Height - 8; y++)
{
AssertFramePixel(before.GetPixel(0, y), after.GetPixel(0, y));
AssertFramePixel(before.GetPixel(input.Width - 1, y), after.GetPixel(input.Width - 1, y));
}
}
catch (Exception ex)
{
failure = ex;
}
finally
{
form.Close();
}
};
Application.Run(form);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
if (failure != null)
{
ExceptionDispatchInfo.Capture(failure).Throw();
}
}

/// <summary>容許螢幕合成的兩階 RGB 量化差;警示殘色仍會產生遠大於此值的差異。</summary>
private static void AssertFramePixel(Color expected, Color actual)
{
Assert.InRange(Math.Abs(expected.R - actual.R), 0, 2);
Assert.InRange(Math.Abs(expected.G - actual.G), 0, 2);
Assert.InRange(Math.Abs(expected.B - actual.B), 0, 2);
}
/// <summary>依與主視窗相同的還原順序先重設主題,再套用焦點背景與外框。</summary>
private static void Restore(Panel host, TextBox input)
{
host.ResetThemeRecursive();
if (input.Focused)
{
input.BackColor = SystemInformation.HighContrast ? SystemColors.Highlight :
input.IsDarkModeActive() ? Color.White : Color.Black;
input.ForeColor = SystemInformation.HighContrast ? SystemColors.HighlightText :
input.IsDarkModeActive() ? Color.Black : Color.White;
host.BackColor = ControlExtensions.GetContextualFocusColors(input.BackColor, input.IsDarkModeActive()).Border;
}
}

/// <summary>只讀取自家控制項所在的螢幕像素,不透過 DrawToBitmap 觸發額外框架重繪。</summary>
private static Bitmap Capture(Control control)
{
Point origin = control.Parent!.PointToScreen(control.Location);
var bitmap = new Bitmap(control.Width, control.Height);
using Graphics graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(origin, Point.Empty, control.Size);
return bitmap;
}
}
8 changes: 7 additions & 1 deletion tests/InputBox.Tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
| `VibrationPatternsTests` | `VibrationPatterns` 與方向性震動設定、語意情境解析、能力感知的多段式微震動序列,以及歷程滾輪阻尼感、字數上限硬牆、震動強度預覽、右搖桿選取粒度、組合鍵進入提示與喚起握手回饋的回歸保護 | 37 |
| `VibrationSafetyLimiterTests` | `VibrationSafetyLimiter` 熱保護、Duty Cycle 限制器與極端邊界保護;馬達數量熱成本倍率正規化,以及所有內建震動模式在冷啟動下不得被拒絕、單次超出預算改為降強度,以及Critical 自動連發(含不同模式交錯)降級、熱負載不失控,以及冷啟動短序列仍完整送出的回歸保護 | 20 |
| `ButtonFeedbackRenderingTests` | Latest 預設/一般按鈕實際文字與背景、焦點/預設動作同步及對比襯底、四種底色進度條與色覺紋理、粗體、按下亮度差、零抖動與配色還原、焦點懸停組合、Space 按放/失焦及空文字反例 | 23 |
| **合計** | | **490** |
| `BlinkFrameRenderingTests` | 實際螢幕非客戶區像素:Blink 完成/取消、有/無焦點還原;HWND、選取範圍及尺寸不變 | 4 |
| **合計** | | **494** |

## 二、執行方式 🚀

Expand Down Expand Up @@ -202,3 +203,8 @@ PR #92 審查補強:重新套色時保留焦點與懸停組合,Space 與滑
即時安全邊界檢查:本次 Space 事件僅更新 InputBox 自己按鈕的視覺狀態,不模擬輸入、不攔截外部輸入、不改變剪貼簿或第三方程式行為。已抓取工程規範列出的五個官方網址;FFXIV 合約與 USERJOY 隱私/使用條款僅取得頁面框架,未能擷取完整本文,因此不宣稱完整條款審查通過,亦不進行高風險核心輸入/輸出異動。

審查修正驗證:按鈕三種主題各 23 項(淺色包含於完整 UI 執行),完整 UI 34/34、非 UI 456/456;Release -warnaserror 為 0 警告/0 錯誤。高對比已還原,未改變原生 Space 點擊及輸出邊界。


Blink 非客戶區殘框修正:.NET 11 Latest 文字框在警示中重繪非客戶區後,僅還原 BackColor/ForeColor 不會清除舊框色;還原配色與焦點提示後明確重繪框架及子控制項,保留 HWND、選取範圍、尺寸與焦點。新增 4 項完成/取消及有/無焦點的實際螢幕像素測試。v0.0.69、原版 v0.0.71 與本機修正版在 125%/120 DPI 下完成淺色、深色、高對比的 Blink 前/中/後截圖;一般主題原版 v0.0.71 殘留 2517 個警示色像素,v0.0.69 與修正版均為 0。高對比三組均正常,驗證後還原系統設定。

本輪驗證:三種主題新增測試各 4/4,完整 UI 38/38、非 UI 456/456;Release -warnaserror 建置 0 警告/0 錯誤;修改 C# 的 severity info style/analyzers 報告皆為空。非客戶區繪製參考:[.NET 11 TextBoxBase](https://github.com/dotnet/winforms/blob/v11.0.0/src/System.Windows.Forms/System/Windows/Forms/Controls/TextBox/TextBoxBase.cs)。
Loading