Skip to content

Commit a6e8118

Browse files
Move sub-classes of "UpDownBase", "WebBrowser" and "WebBrowserBase" classes to their own files (#4579)
1 parent 77dcb4f commit a6e8118

8 files changed

+760
-678
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#nullable disable
6+
7+
using System.Drawing;
8+
using static Interop;
9+
10+
namespace System.Windows.Forms
11+
{
12+
public abstract partial class UpDownBase
13+
{
14+
internal partial class UpDownButtons
15+
{
16+
internal partial class UpDownButtonsAccessibleObject : ControlAccessibleObject
17+
{
18+
internal class DirectionButtonAccessibleObject : AccessibleObject
19+
{
20+
private readonly bool _up;
21+
private readonly UpDownButtonsAccessibleObject _parent;
22+
23+
public DirectionButtonAccessibleObject(UpDownButtonsAccessibleObject parent, bool up)
24+
{
25+
_parent = parent;
26+
_up = up;
27+
}
28+
29+
/// <summary>
30+
/// Gets the runtime ID.
31+
/// </summary>
32+
internal override int[] RuntimeId => new int[]
33+
{
34+
_parent.RuntimeId[0],
35+
_parent.RuntimeId[1],
36+
_parent.RuntimeId[2],
37+
_up ? 1 : 0
38+
};
39+
40+
internal override object GetPropertyValue(UiaCore.UIA propertyID) => propertyID switch
41+
{
42+
UiaCore.UIA.NamePropertyId => Name,
43+
UiaCore.UIA.RuntimeIdPropertyId => RuntimeId,
44+
UiaCore.UIA.ControlTypePropertyId => UiaCore.UIA.ButtonControlTypeId,
45+
UiaCore.UIA.BoundingRectanglePropertyId => Bounds,
46+
UiaCore.UIA.LegacyIAccessibleStatePropertyId => State,
47+
UiaCore.UIA.LegacyIAccessibleRolePropertyId => Role,
48+
_ => base.GetPropertyValue(propertyID),
49+
};
50+
51+
internal override UiaCore.IRawElementProviderFragment FragmentNavigate(
52+
UiaCore.NavigateDirection direction) => direction switch
53+
{
54+
UiaCore.NavigateDirection.Parent => Parent,
55+
UiaCore.NavigateDirection.NextSibling => _up ? Parent.GetChild(1) : null,
56+
UiaCore.NavigateDirection.PreviousSibling => _up ? null : Parent.GetChild(0),
57+
_ => base.FragmentNavigate(direction),
58+
};
59+
60+
internal override UiaCore.IRawElementProviderFragmentRoot FragmentRoot => Parent;
61+
62+
public override Rectangle Bounds
63+
{
64+
get
65+
{
66+
if (!_parent.Owner.IsHandleCreated)
67+
{
68+
return Rectangle.Empty;
69+
}
70+
71+
// Get button bounds
72+
Rectangle bounds = ((UpDownButtons)_parent.Owner).Bounds;
73+
bounds.Height /= 2;
74+
75+
if (!_up)
76+
{
77+
bounds.Y += bounds.Height;
78+
}
79+
80+
// Convert to screen co-ords
81+
return (((UpDownButtons)_parent.Owner).ParentInternal).RectangleToScreen(bounds);
82+
}
83+
}
84+
85+
public override string Name
86+
{
87+
get => _up ? SR.UpDownBaseUpButtonAccName : SR.UpDownBaseDownButtonAccName;
88+
set { }
89+
}
90+
91+
public override AccessibleObject Parent => _parent;
92+
93+
public override AccessibleRole Role => AccessibleRole.PushButton;
94+
}
95+
}
96+
}
97+
}
98+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#nullable disable
6+
7+
using System.Diagnostics;
8+
using System.Drawing;
9+
using System.Runtime.InteropServices;
10+
using System.Windows.Forms.VisualStyles;
11+
using static Interop;
12+
13+
namespace System.Windows.Forms
14+
{
15+
public abstract partial class UpDownBase
16+
{
17+
internal partial class UpDownButtons
18+
{
19+
internal partial class UpDownButtonsAccessibleObject : ControlAccessibleObject
20+
{
21+
private DirectionButtonAccessibleObject upButton;
22+
private DirectionButtonAccessibleObject downButton;
23+
24+
private UpDownButtons _owner;
25+
26+
public UpDownButtonsAccessibleObject(UpDownButtons owner) : base(owner)
27+
{
28+
_owner = owner;
29+
}
30+
31+
internal override UiaCore.IRawElementProviderFragment ElementProviderFromPoint(double x, double y)
32+
{
33+
AccessibleObject element = HitTest((int)x, (int)y);
34+
35+
if (element != null)
36+
{
37+
return element;
38+
}
39+
40+
return base.ElementProviderFromPoint(x, y);
41+
}
42+
43+
internal override UiaCore.IRawElementProviderFragment FragmentNavigate(
44+
UiaCore.NavigateDirection direction) => direction switch
45+
{
46+
UiaCore.NavigateDirection.FirstChild => GetChild(0),
47+
UiaCore.NavigateDirection.LastChild => GetChild(1),
48+
_ => base.FragmentNavigate(direction),
49+
};
50+
51+
internal override UiaCore.IRawElementProviderFragmentRoot FragmentRoot => this;
52+
53+
private DirectionButtonAccessibleObject UpButton
54+
=> upButton ??= new DirectionButtonAccessibleObject(this, true);
55+
56+
private DirectionButtonAccessibleObject DownButton
57+
=> downButton ??= new DirectionButtonAccessibleObject(this, false);
58+
59+
public override AccessibleObject GetChild(int index) => index switch
60+
{
61+
0 => UpButton,
62+
1 => DownButton,
63+
_ => null,
64+
};
65+
66+
public override int GetChildCount() => 2;
67+
68+
internal override object GetPropertyValue(UiaCore.UIA propertyID) => propertyID switch
69+
{
70+
UiaCore.UIA.NamePropertyId => Name,
71+
UiaCore.UIA.RuntimeIdPropertyId => RuntimeId,
72+
UiaCore.UIA.BoundingRectanglePropertyId => Bounds,
73+
UiaCore.UIA.LegacyIAccessibleStatePropertyId => State,
74+
UiaCore.UIA.LegacyIAccessibleRolePropertyId => Role,
75+
_ => base.GetPropertyValue(propertyID),
76+
};
77+
78+
public override AccessibleObject HitTest(int x, int y)
79+
{
80+
if (UpButton.Bounds.Contains(x, y))
81+
{
82+
return UpButton;
83+
}
84+
85+
if (DownButton.Bounds.Contains(x, y))
86+
{
87+
return DownButton;
88+
}
89+
90+
return null;
91+
}
92+
93+
internal override UiaCore.IRawElementProviderSimple HostRawElementProvider
94+
{
95+
get
96+
{
97+
if (HandleInternal == IntPtr.Zero)
98+
{
99+
return null;
100+
}
101+
102+
UiaCore.UiaHostProviderFromHwnd(new HandleRef(this, HandleInternal), out UiaCore.IRawElementProviderSimple provider);
103+
return provider;
104+
}
105+
}
106+
107+
public override string Name
108+
{
109+
get
110+
{
111+
string baseName = base.Name;
112+
if (string.IsNullOrEmpty(baseName))
113+
{
114+
return SR.DefaultUpDownButtonsAccessibleName;
115+
}
116+
117+
return baseName;
118+
}
119+
set => base.Name = value;
120+
}
121+
122+
public override AccessibleObject Parent => _owner.AccessibilityObject;
123+
124+
public override AccessibleRole Role
125+
{
126+
get
127+
{
128+
AccessibleRole role = Owner.AccessibleRole;
129+
if (role != AccessibleRole.Default)
130+
{
131+
return role;
132+
}
133+
134+
return AccessibleRole.SpinButton;
135+
}
136+
}
137+
138+
/// <summary>
139+
/// Gets the runtime ID.
140+
/// </summary>
141+
internal override int[] RuntimeId
142+
{
143+
get
144+
{
145+
if (_owner is null)
146+
{
147+
return base.RuntimeId;
148+
}
149+
150+
// We need to provide a unique ID others are implementing this in the same manner first item
151+
// is static - 0x2a (RuntimeIDFirstItem) second item can be anything, but here it is a hash.
152+
153+
var runtimeId = new int[3];
154+
runtimeId[0] = RuntimeIDFirstItem;
155+
runtimeId[1] = (int)(long)_owner.InternalHandle;
156+
runtimeId[2] = _owner.GetHashCode();
157+
158+
return runtimeId;
159+
}
160+
}
161+
}
162+
}
163+
}
164+
}

0 commit comments

Comments
 (0)