Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lindexi_gd
Uno
提交
109a5729
U
Uno
项目概览
lindexi_gd
/
Uno
11 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
Uno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
109a5729
编写于
3月 07, 2023
作者:
M
Martin Zikmund
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: Enable When_VerifyEnabledXYKeyboardNavigation in Uno Islands
上级
9b795df0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
108 addition
and
108 deletion
+108
-108
src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/Repeater/RepeaterFocusTests.cs
...Microsoft_UI_Xaml_Controls/Repeater/RepeaterFocusTests.cs
+7
-0
src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Input/Given_UnoFocusInputHandler.cs
...sts/Tests/Uno_UI_Xaml_Input/Given_UnoFocusInputHandler.cs
+1
-1
src/Uno.UI/UI/Xaml/Input/FocusManager.mux.static.cs
src/Uno.UI/UI/Xaml/Input/FocusManager.mux.static.cs
+5
-9
src/Uno.UI/UI/Xaml/Input/Internal/UnoFocusInputHandler.cs
src/Uno.UI/UI/Xaml/Input/Internal/UnoFocusInputHandler.cs
+90
-91
src/Uno.UI/UI/Xaml/Internal/VisualTree.cs
src/Uno.UI/UI/Xaml/Internal/VisualTree.cs
+4
-6
src/Uno.UI/UI/Xaml/UIElement.mux.cs
src/Uno.UI/UI/Xaml/UIElement.mux.cs
+1
-1
未找到文件。
src/Uno.UI.RuntimeTests/MUX/Microsoft_UI_Xaml_Controls/Repeater/RepeaterFocusTests.cs
浏览文件 @
109a5729
...
...
@@ -50,6 +50,13 @@ namespace Windows.UI.Xaml.Tests.MUXControls.ApiTests.RepeaterTests
return
;
}
#if HAS_UNO
if
(
TestServices
.
WindowHelper
.
IsXamlIsland
)
{
return
;
}
#endif
ItemsRepeater
repeater
=
null
;
ScrollViewer
scrollViewer
=
null
;
var
data
=
new
ObservableCollection
<
string
>(
Enumerable
.
Range
(
0
,
50
).
Select
(
i
=>
"Item #"
+
i
));
...
...
src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Input/Given_UnoFocusInputHandler.cs
浏览文件 @
109a5729
...
...
@@ -47,7 +47,7 @@ public class Given_UnoFocusInputHandler
centerButton
.
Focus
(
FocusState
.
Programmatic
);
var
inputHandler
=
new
UnoFocusInputHandler
(
VisualTree
.
GetRootForElement
(
centerButton
));
var
inputHandler
=
new
UnoFocusInputHandler
(
VisualTree
.
GetRoot
OrIsland
ForElement
(
centerButton
));
var
result
=
inputHandler
.
TryHandleDirectionalFocus
(
key
);
Assert
.
AreEqual
(
shouldSucceed
,
result
);
...
...
src/Uno.UI/UI/Xaml/Input/FocusManager.mux.static.cs
浏览文件 @
109a5729
...
...
@@ -37,12 +37,8 @@ namespace Windows.UI.Xaml.Input
}
}
private
static
bool
InIslandsMode
()
{
//TODO Uno: Islands mode should be applied for "WinUI" mode as it limits some APIs for
//multi-window use. For now choosing not limiting.
return
false
;
}
// TODO Uno: This should probably apply to multi-window as well #8341.
private
static
bool
InIslandsMode
()
=>
CoreServices
.
Instance
.
InitializationType
==
InitializationType
.
IslandsOnly
;
private
static
object
?
FindNextFocus
(
FocusNavigationDirection
focusNavigationDirection
,
...
...
@@ -54,7 +50,7 @@ namespace Windows.UI.Xaml.Input
}
var
core
=
DXamlCore
.
Current
;
if
(
core
==
null
)
if
(
core
is
null
)
{
throw
new
InvalidOperationException
(
"XamlCore is not set."
);
}
...
...
@@ -77,7 +73,7 @@ namespace Windows.UI.Xaml.Input
var
contentRootCoordinator
=
core
.
GetHandle
().
ContentRootCoordinator
;
var
contentRoot
=
contentRootCoordinator
?.
CoreWindowContentRoot
;
if
(
contentRoot
==
null
)
if
(
contentRoot
is
null
)
{
return
null
;
}
...
...
@@ -85,7 +81,7 @@ namespace Windows.UI.Xaml.Input
focusManager
=
contentRoot
.
FocusManager
;
}
if
(
focusManager
==
null
)
if
(
focusManager
is
null
)
{
return
null
;
}
...
...
src/Uno.UI/UI/Xaml/Input/Internal/UnoFocusInputHandler.cs
浏览文件 @
109a5729
...
...
@@ -5,127 +5,126 @@ using Windows.System;
using
Windows.UI.Xaml
;
using
Windows.UI.Xaml.Input
;
namespace
Uno.UI.Xaml.Input
namespace
Uno.UI.Xaml.Input
;
internal
class
UnoFocusInputHandler
{
internal
class
UnoFocusInputHandler
{
private
readonly
RootVisual
_rootVisual
;
private
readonly
UIElement
_rootElement
;
private
bool
_isShiftDown
;
private
bool
_isShiftDown
;
public
UnoFocusInputHandler
(
UIElement
rootElement
)
{
_rootElement
=
rootElement
;
_rootElement
.
KeyDown
+=
OnKeyDown
;
_rootElement
.
KeyUp
+=
OnKeyUp
;
}
public
UnoFocusInputHandler
(
RootVisual
rootVisual
)
private
void
OnKeyUp
(
object
sender
,
KeyRoutedEventArgs
e
)
{
if
(
e
.
OriginalKey
==
VirtualKey
.
Shift
||
e
.
OriginalKey
==
VirtualKey
.
LeftShift
||
e
.
OriginalKey
==
VirtualKey
.
RightShift
)
{
_rootVisual
=
rootVisual
;
_rootVisual
.
KeyDown
+=
OnKeyDown
;
_rootVisual
.
KeyUp
+=
OnKeyUp
;
_isShiftDown
=
false
;
}
}
private
void
OnKeyUp
(
object
sender
,
KeyRoutedEventArgs
e
)
private
void
OnKeyDown
(
object
sender
,
KeyRoutedEventArgs
e
)
{
if
(
e
.
OriginalKey
==
VirtualKey
.
Shift
||
e
.
OriginalKey
==
VirtualKey
.
LeftShift
||
e
.
OriginalKey
==
VirtualKey
.
RightShift
)
{
if
(
e
.
OriginalKey
==
VirtualKey
.
Shift
||
e
.
OriginalKey
==
VirtualKey
.
LeftShift
||
e
.
OriginalKey
==
VirtualKey
.
RightShift
)
{
_isShiftDown
=
false
;
}
_isShiftDown
=
true
;
}
private
void
OnKeyDown
(
object
sender
,
KeyRoutedEventArgs
e
)
if
(
e
.
Handled
)
{
if
(
e
.
OriginalKey
==
VirtualKey
.
Shift
||
e
.
OriginalKey
==
VirtualKey
.
LeftShift
||
e
.
OriginalKey
==
VirtualKey
.
RightShift
)
{
_isShiftDown
=
true
;
}
if
(
e
.
Handled
)
{
return
;
}
return
;
}
if
(
e
.
OriginalKey
==
VirtualKey
.
Tab
)
{
e
.
Handled
=
TryHandleTabFocus
(
_isShiftDown
);
}
if
(
e
.
OriginalKey
==
VirtualKey
.
Tab
)
{
e
.
Handled
=
TryHandleTabFocus
(
_isShiftDown
);
}
if
(
e
.
OriginalKey
==
VirtualKey
.
Up
||
e
.
OriginalKey
==
VirtualKey
.
Down
||
e
.
OriginalKey
==
VirtualKey
.
Left
||
e
.
OriginalKey
==
VirtualKey
.
Right
)
{
e
.
Handled
=
TryHandleDirectionalFocus
(
e
.
OriginalKey
);
}
if
(
e
.
OriginalKey
==
VirtualKey
.
Up
||
e
.
OriginalKey
==
VirtualKey
.
Down
||
e
.
OriginalKey
==
VirtualKey
.
Left
||
e
.
OriginalKey
==
VirtualKey
.
Right
)
{
e
.
Handled
=
TryHandleDirectionalFocus
(
e
.
OriginalKey
);
}
}
internal
bool
TryHandleTabFocus
(
bool
isShiftDown
)
internal
bool
TryHandleTabFocus
(
bool
isShiftDown
)
{
var
direction
=
isShiftDown
?
FocusNavigationDirection
.
Previous
:
FocusNavigationDirection
.
Next
;
var
contentRoot
=
VisualTree
.
GetContentRootForElement
(
_rootElement
);
if
(
contentRoot
==
null
)
{
var
direction
=
isShiftDown
?
FocusNavigationDirection
.
Previous
:
FocusNavigationDirection
.
Next
;
var
contentRoot
=
VisualTree
.
GetContentRootForElement
(
_rootVisual
);
if
(
contentRoot
==
null
)
{
return
false
;
}
return
false
;
}
contentRoot
.
InputManager
.
LastInputDeviceType
=
InputDeviceType
.
Keyboard
;
contentRoot
.
InputManager
.
LastInputDeviceType
=
InputDeviceType
.
Keyboard
;
var
focusManager
=
VisualTree
.
GetFocusManagerForElement
(
_rootVisual
);
var
focusMovement
=
new
FocusMovement
(
XYFocusOptions
.
Default
,
direction
,
null
);
focusMovement
.
IsShiftPressed
=
_isShiftDown
;
focusMovement
.
IsProcessingTab
=
true
;
var
result
=
focusManager
?.
FindAndSetNextFocus
(
focusMovement
);
return
result
?.
WasMoved
==
true
;
}
var
focusManager
=
VisualTree
.
GetFocusManagerForElement
(
_rootElement
);
var
focusMovement
=
new
FocusMovement
(
XYFocusOptions
.
Default
,
direction
,
null
);
focusMovement
.
IsShiftPressed
=
_isShiftDown
;
focusMovement
.
IsProcessingTab
=
true
;
var
result
=
focusManager
?.
FindAndSetNextFocus
(
focusMovement
);
return
result
?.
WasMoved
==
true
;
}
internal
bool
TryHandleDirectionalFocus
(
VirtualKey
originalKey
)
internal
bool
TryHandleDirectionalFocus
(
VirtualKey
originalKey
)
{
var
contentRoot
=
VisualTree
.
GetContentRootForElement
(
_rootElement
);
if
(
contentRoot
==
null
)
{
var
contentRoot
=
VisualTree
.
GetContentRootForElement
(
_rootVisual
);
if
(
contentRoot
==
null
)
{
return
false
;
}
contentRoot
.
InputManager
.
LastInputDeviceType
=
InputDeviceType
.
Keyboard
;
var
focusManager
=
VisualTree
.
GetFocusManagerForElement
(
_rootVisual
);
var
focusDirection
=
FocusSelection
.
GetNavigationDirectionForKeyboardArrow
(
originalKey
);
return
false
;
}
contentRoot
.
InputManager
.
LastInputDeviceType
=
InputDeviceType
.
Keyboard
;
if
(
focusManager
==
null
||
focusDirection
==
FocusNavigationDirection
.
None
)
{
return
false
;
}
var
focusManager
=
VisualTree
.
GetFocusManagerForElement
(
_rootElement
);
var
focusDirection
=
FocusSelection
.
GetNavigationDirectionForKeyboardArrow
(
originalKey
);
var
source
=
focusManager
.
FocusedElement
;
// Uno specific: This should actually bubble up with the event from the source element to the root visual.
if
(
focusManager
==
null
||
focusDirection
==
FocusNavigationDirection
.
None
)
{
return
false
;
}
var
directionalFocusEnabled
=
false
;
var
focusCandidateFound
=
false
;
bool
handled
=
false
;
while
(
source
!=
null
&&
!
focusCandidateFound
)
{
var
directionalFocusInfo
=
FocusSelection
.
TryDirectionalFocus
(
focusManager
,
focusDirection
,
source
);
handled
|=
directionalFocusInfo
.
Handled
;
var
source
=
focusManager
.
FocusedElement
;
// Uno specific: This should actually bubble up with the event from the source element to the root visual.
focusCandidateFound
|=
directionalFocusInfo
.
FocusCandidateFound
;
directionalFocusEnabled
|=
directionalFocusInfo
.
DirectionalFocusEnabled
;
var
directionalFocusEnabled
=
false
;
var
focusCandidateFound
=
false
;
bool
handled
=
false
;
while
(
source
!=
null
&&
!
focusCandidateFound
)
{
var
directionalFocusInfo
=
FocusSelection
.
TryDirectionalFocus
(
focusManager
,
focusDirection
,
source
);
handled
|=
directionalFocusInfo
.
Handled
;
if
(!
directionalFocusInfo
.
ShouldBubble
)
{
break
;
}
focusCandidateFound
|=
directionalFocusInfo
.
FocusCandidateFound
;
directionalFocusEnabled
|=
directionalFocusInfo
.
DirectionalFocusEnabled
;
if
(!
focusCandidateFound
)
{
source
=
source
.
GetParent
()
as
DependencyObject
;
}
if
(!
directionalFocusInfo
.
ShouldBubble
)
{
break
;
}
// Only raise NoFocusCandidateFound if XYDirectionalFocus was ever set to enabled and a
// focus candidate was never found.
if
(
directionalFocusEnabled
&&
!
focusCandidateFound
)
if
(!
focusCandidateFound
)
{
focusManager
.
RaiseNoFocusCandidateFoundEvent
(
focusDirection
)
;
source
=
source
.
GetParent
()
as
DependencyObject
;
}
}
return
handled
;
// Only raise NoFocusCandidateFound if XYDirectionalFocus was ever set to enabled and a
// focus candidate was never found.
if
(
directionalFocusEnabled
&&
!
focusCandidateFound
)
{
focusManager
.
RaiseNoFocusCandidateFoundEvent
(
focusDirection
);
}
return
handled
;
}
}
src/Uno.UI/UI/Xaml/Internal/VisualTree.cs
浏览文件 @
109a5729
...
...
@@ -83,9 +83,9 @@ namespace Uno.UI.Xaml.Core
RootVisual
.
AssociatedVisualTree
=
this
;
RootVisual
.
SetBackgroundColor
(
backgroundColor
);
RootElement
=
RootVisual
;
_focusInputHandler
=
new
UnoFocusInputHandler
(
RootVisual
);
}
_focusInputHandler
=
new
UnoFocusInputHandler
(
RootElement
);
}
internal
UnoFocusInputHandler
?
UnoFocusInputHandler
=>
_focusInputHandler
;
...
...
@@ -352,10 +352,8 @@ namespace Uno.UI.Xaml.Core
/// </summary>
/// <param name="pObject">Element.</param>
/// <returns>Root visual or null.</returns>
internal
static
RootVisual
?
GetRootForElement
(
DependencyObject
?
pObject
)
{
return
pObject
?.
GetContext
().
MainRootVisual
;
}
internal
static
RootVisual
?
GetRootForElement
(
DependencyObject
?
pObject
)
=>
VisualTree
.
GetForElement
(
pObject
)?.
RootVisual
;
/// <summary>
/// Static helper function that encapsulates getting the FocusManager
...
...
src/Uno.UI/UI/Xaml/UIElement.mux.cs
浏览文件 @
109a5729
...
...
@@ -525,7 +525,7 @@ namespace Windows.UI.Xaml
internal
Rect
GetGlobalBoundsLogical
(
bool
ignoreClipping
=
false
,
bool
useTargetInformation
=
false
)
{
//TODO Uno specific: This implementation is significantly simplified from the actual WinUI implementation.
var
rootVisual
=
VisualTree
.
GetRootForElement
(
this
);
var
rootVisual
=
VisualTree
.
GetRootForElement
(
this
)
??
VisualTree
.
GetRootOrIslandForElement
(
this
)
;
if
(
rootVisual
==
null
)
{
return
Rect
.
Empty
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录