Refactor editor window runtime ownership

This commit is contained in:
2026-04-26 20:40:32 +08:00
parent fa4fcbe95b
commit ee05558f86
18 changed files with 1056 additions and 398 deletions

View File

@@ -2,8 +2,8 @@
#include "Platform/Win32/Windowing/EditorWindow.h"
#include "Platform/Win32/Windowing/EditorWindowSupport.h"
#include "Windowing/Content/EditorWindowContentController.h"
#include "Windowing/Host/EditorWindowHostCoordinator.h"
#include "Windowing/Runtime/EditorWindowRuntimeController.h"
#include <XCEditor/Foundation/UIEditorTheme.h>
#include <XCEngine/UI/DrawData.h>
@@ -271,7 +271,8 @@ bool EditorWindowChromeController::HandleSystemCommand(
bool EditorWindowChromeController::HandleGetMinMaxInfo(
const EditorWindow& window,
LPARAM lParam) const {
const ::XCEngine::UI::UISize minimumOuterSize = window.m_runtime->ResolveMinimumOuterSize();
const ::XCEngine::UI::UISize minimumOuterSize =
window.GetOwner().ResolveMinimumOuterSize();
return Host::HandleBorderlessWindowGetMinMaxInfo(
window.GetHwnd(),
lParam,
@@ -348,7 +349,8 @@ bool EditorWindowChromeController::HandleResizePointerMove(
return false;
}
const ::XCEngine::UI::UISize minimumOuterSize = window.m_runtime->ResolveMinimumOuterSize();
const ::XCEngine::UI::UISize minimumOuterSize =
window.GetOwner().ResolveMinimumOuterSize();
RECT targetRect = Host::ComputeBorderlessWindowResizeRect(
GetBorderlessResizeInitialWindowRect(),
GetBorderlessResizeInitialScreenPoint(),
@@ -370,7 +372,7 @@ bool EditorWindowChromeController::HandleResizePointerMove(
if (window.ApplyWindowResize(static_cast<UINT>(width), static_cast<UINT>(height))) {
const auto immediateFrameBegin = std::chrono::steady_clock::now();
window.QueueCompletedImmediateFrame(
hostCoordinator.DriveImmediateWindowFrame(window));
hostCoordinator.DriveImmediateWindowFrame(window.GetOwner()));
const auto immediateFrameEnd = std::chrono::steady_clock::now();
MarkPredictedClientPixelSizePresented();
if (IsVerboseResizeTraceEnabled()) {
@@ -678,24 +680,24 @@ Host::BorderlessWindowChromeHitTarget EditorWindowChromeController::HitTestChrom
const float clientWidthDips =
window.PixelsToDips(static_cast<float>((std::max)(clientRect.right - clientRect.left, 1L)));
const Host::BorderlessWindowChromeLayout layout =
ResolveChromeLayout(window, clientWidthDips);
ResolveChromeLayout(window.GetOwner(), clientWidthDips);
return Host::HitTestBorderlessWindowChrome(
layout,
window.ConvertClientPixelsToDips(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
}
Host::BorderlessWindowChromeLayout EditorWindowChromeController::ResolveChromeLayout(
const EditorWindow& window,
const EditorHostWindow& window,
float clientWidthDips) const {
float leadingOccupiedRight = 0.0f;
if (ShouldUseDetachedTitleBarTabStrip(window)) {
const EditorWindowTitleBarBinding* titleBarBinding =
window.m_runtime->TryGetTitleBarBinding();
window.TryGetTitleBarBinding();
leadingOccupiedRight = ResolveDetachedTabWidth(
titleBarBinding != nullptr
? titleBarBinding->ResolveTabStripTitleText("Panel")
: std::string("Panel"),
&window.m_runtime->GetTextMeasurer());
&window.GetTextMeasurer());
}
return Host::BuildBorderlessWindowChromeLayout(
@@ -705,8 +707,8 @@ Host::BorderlessWindowChromeLayout EditorWindowChromeController::ResolveChromeLa
}
bool EditorWindowChromeController::ShouldUseDetachedTitleBarTabStrip(
const EditorWindow& window) const {
const EditorWindowTitleBarBinding* titleBarBinding = window.m_runtime->TryGetTitleBarBinding();
const EditorHostWindow& window) const {
const EditorWindowTitleBarBinding* titleBarBinding = window.TryGetTitleBarBinding();
return !window.IsPrimary() &&
window.GetChromePolicy().allowDetachedTitleBarTabStrip &&
titleBarBinding != nullptr &&
@@ -714,7 +716,7 @@ bool EditorWindowChromeController::ShouldUseDetachedTitleBarTabStrip(
}
void EditorWindowChromeController::AppendChrome(
const EditorWindow& window,
const EditorHostWindow& window,
UIDrawList& drawList,
float clientWidthDips) const {
const Host::BorderlessWindowChromeLayout layout =
@@ -733,10 +735,10 @@ void EditorWindowChromeController::AppendChrome(
if (!window.IsPrimary()) {
if (useDetachedTitleBarTabStrip) {
if (window.m_runtime->GetTitleBarLogoIcon().IsValid()) {
if (window.GetTitleBarLogoIcon().IsValid()) {
drawList.AddImage(
BuildDetachedTitleLogoRect(layout),
window.m_runtime->GetTitleBarLogoIcon(),
window.GetTitleBarLogoIcon(),
UIColor(1.0f, 1.0f, 1.0f, 1.0f));
}
} else {
@@ -744,17 +746,17 @@ void EditorWindowChromeController::AppendChrome(
const float iconY =
layout.titleBarRect.y +
(std::max)(0.0f, (layout.titleBarRect.height - kTitleBarLogoExtent) * 0.5f);
if (window.m_runtime->GetTitleBarLogoIcon().IsValid()) {
if (window.GetTitleBarLogoIcon().IsValid()) {
drawList.AddImage(
UIRect(iconX, iconY, kTitleBarLogoExtent, kTitleBarLogoExtent),
window.m_runtime->GetTitleBarLogoIcon(),
window.GetTitleBarLogoIcon(),
UIColor(1.0f, 1.0f, 1.0f, 1.0f));
}
drawList.AddText(
UIPoint(
iconX +
(window.m_runtime->GetTitleBarLogoIcon().IsValid()
(window.GetTitleBarLogoIcon().IsValid()
? (kTitleBarLogoExtent + kTitleBarLogoTextGap)
: 4.0f),
layout.titleBarRect.y +
@@ -769,7 +771,7 @@ void EditorWindowChromeController::AppendChrome(
? std::string_view("XCEngine Editor")
: cachedTitleText;
const EditorWindowTitleBarBinding* titleBarBinding =
window.m_runtime->TryGetTitleBarBinding();
window.TryGetTitleBarBinding();
return titleBarBinding != nullptr
? titleBarBinding->ResolveDetachedWindowTitleText(fallbackWindowTitle)
: std::string(fallbackWindowTitle);
@@ -782,10 +784,10 @@ void EditorWindowChromeController::AppendChrome(
const float iconY =
layout.titleBarRect.y +
(std::max)(0.0f, (layout.titleBarRect.height - kTitleBarLogoExtent) * 0.5f);
if (window.m_runtime->GetTitleBarLogoIcon().IsValid()) {
if (window.GetTitleBarLogoIcon().IsValid()) {
drawList.AddImage(
UIRect(iconX, iconY, kTitleBarLogoExtent, kTitleBarLogoExtent),
window.m_runtime->GetTitleBarLogoIcon(),
window.GetTitleBarLogoIcon(),
UIColor(1.0f, 1.0f, 1.0f, 1.0f));
}
@@ -795,12 +797,12 @@ void EditorWindowChromeController::AppendChrome(
: std::string(cachedTitleText);
const std::string frameRateText =
window.GetChromePolicy().showFrameStats
? window.m_runtime->BuildFrameRateText()
? window.BuildFrameRateText()
: std::string();
drawList.AddText(
UIPoint(
iconX +
(window.m_runtime->GetTitleBarLogoIcon().IsValid()
(window.GetTitleBarLogoIcon().IsValid()
? (kTitleBarLogoExtent + kTitleBarLogoTextGap)
: 4.0f),
layout.titleBarRect.y +
@@ -812,7 +814,7 @@ void EditorWindowChromeController::AppendChrome(
kBorderlessTitleBarFontSize);
if (!frameRateText.empty()) {
const float frameRateTextWidth =
window.m_runtime->GetTextMeasurer().MeasureTextWidth(
window.GetTextMeasurer().MeasureTextWidth(
UIEditorTextMeasureRequest{
frameRateText,
kBorderlessTitleBarFontSize });
@@ -898,7 +900,7 @@ bool EditorWindowChromeController::ApplyPredictedWindowRectTransition(
SetPredictedClientPixelSize(static_cast<UINT>(width), static_cast<UINT>(height));
if (window.ApplyWindowResize(static_cast<UINT>(width), static_cast<UINT>(height))) {
window.QueueCompletedImmediateFrame(
hostCoordinator.DriveImmediateWindowFrame(window));
hostCoordinator.DriveImmediateWindowFrame(window.GetOwner()));
MarkPredictedClientPixelSizePresented();
}
SetWindowPos(