Skip to content

Commit 56c6d26

Browse files
author
Roy Lin
committed
refactor: remove obsolete native compatibility code
1 parent a8077bf commit 56c6d26

6 files changed

Lines changed: 66 additions & 421 deletions

File tree

src/appkit.rs

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -77,140 +77,6 @@ impl AppKitWidgetKind {
7777
NativeWidgetKind::Toolbar => Self::Toolbar,
7878
}
7979
}
80-
81-
/// Legacy class-name compatibility. Runtime drivers use `from_widget_kind`.
82-
#[deprecated(note = "use AppKitWidgetKind::from_widget_kind with typed NativeWidgetKind")]
83-
pub fn from_widget_class(widget_class: &str) -> GuiResult<Self> {
84-
match widget_class {
85-
"NSWindow" => Ok(AppKitWidgetKind::Window),
86-
"NSView"
87-
| "NSView(document)"
88-
| "NSView(document-head)"
89-
| "NSView(document-body)"
90-
| "NSView(metadata)"
91-
| "NSView(resource-link)"
92-
| "NSView(style-sheet)"
93-
| "NSView(script)"
94-
| "NSView(template)"
95-
| "NSView(slot)"
96-
| "NSView(paragraph)"
97-
| "NSView(preformatted-text)"
98-
| "NSView(block-quote)"
99-
| "NSView(contact-address)"
100-
| "NSView(no-break-text)"
101-
| "NSView(centered-text)"
102-
| "NSView(font-text)"
103-
| "NSView(big-text)"
104-
| "NSView(teletype-text)"
105-
| "NSView(applet)"
106-
| "NSView(background-sound)"
107-
| "NSView(frame)"
108-
| "NSView(frameset)"
109-
| "NSView(noembed-fallback)"
110-
| "NSView(noframes-fallback)"
111-
| "NSView(marquee)"
112-
| "NSView(math)"
113-
| "NSView(nextid)"
114-
| "NSView(selected-content)"
115-
| "NSView(heading-group)"
116-
| "NSView(ruby)"
117-
| "NSView(ruby-text-container)"
118-
| "NSView(main)"
119-
| "NSView(navigation)"
120-
| "NSView(header)"
121-
| "NSView(footer)"
122-
| "NSView(article)"
123-
| "NSView(section)"
124-
| "NSView(aside)"
125-
| "NSView(search)"
126-
| "NSView(disclosure)"
127-
| "NSView(figure)"
128-
| "NSView(description-list)"
129-
| "NSView(description-details)"
130-
| "NSView(form)"
131-
| "NSView(fieldset)"
132-
| "NSView(option-group)"
133-
| "NSView(image-map)"
134-
| "NSImageView"
135-
| "AVPlayerView"
136-
| "NSView(canvas)"
137-
| "NSView(embedded-content)"
138-
| "NSView(table-section)"
139-
| "NSTableRowView"
140-
| "NSTableCellView"
141-
| "NSTableColumn" => Ok(AppKitWidgetKind::View),
142-
"NSTextField(label)"
143-
| "NSTextField(abbreviation)"
144-
| "NSTextField(citation)"
145-
| "NSTextField(definition)"
146-
| "NSTextField(data-value)"
147-
| "NSTextField(inserted-text)"
148-
| "NSTextField(deleted-text)"
149-
| "NSTextField(marked-text)"
150-
| "NSTextField(time)"
151-
| "NSTextField(emphasis)"
152-
| "NSTextField(strong-text)"
153-
| "NSTextField(code)"
154-
| "NSTextField(keyboard-input)"
155-
| "NSTextField(sample-output)"
156-
| "NSTextField(variable)"
157-
| "NSTextField(inline-quote)"
158-
| "NSTextField(subscript)"
159-
| "NSTextField(superscript)"
160-
| "NSTextField(small-text)"
161-
| "NSTextField(bold-text)"
162-
| "NSTextField(italic-text)"
163-
| "NSTextField(struck-text)"
164-
| "NSTextField(underlined-text)"
165-
| "NSTextField(bidi-isolate)"
166-
| "NSTextField(bidi-override)"
167-
| "NSTextField(line-break)"
168-
| "NSTextField(word-break-opportunity)"
169-
| "NSTextField(document-title)"
170-
| "NSTextField(heading)"
171-
| "NSTextField(ruby-base)"
172-
| "NSTextField(ruby-text)"
173-
| "NSTextField(ruby-parenthesis)"
174-
| "NSTextField(figure-caption)"
175-
| "NSTextField(description-term)"
176-
| "NSTextField(legend)"
177-
| "NSTextField(output)"
178-
| "NSTextField(table-caption)" => Ok(AppKitWidgetKind::Label),
179-
"NSButton"
180-
| "NSButton(link)"
181-
| "NSButton(image-map-area)"
182-
| "NSButton(disclosure-summary)" => Ok(AppKitWidgetKind::Button),
183-
"NSTextField(input)"
184-
| "NSTextField(textarea)"
185-
| "NSSearchField"
186-
| "NSSecureTextField" => Ok(AppKitWidgetKind::TextField),
187-
"NSButton(checkbox)" => Ok(AppKitWidgetKind::Checkbox),
188-
"NSSwitch" => Ok(AppKitWidgetKind::Switch),
189-
"NSStackView(radio-group)" => Ok(AppKitWidgetKind::RadioGroup),
190-
"NSButton(radio)" => Ok(AppKitWidgetKind::Radio),
191-
"NSComboBox" => Ok(AppKitWidgetKind::ComboBox),
192-
"NSScrollView+NSStackView" | "NSTableView" | "NSOutlineView" => {
193-
Ok(AppKitWidgetKind::ListView)
194-
}
195-
"NSScrollView+NSStackView(scroll)" => Ok(AppKitWidgetKind::ScrollView),
196-
"NSButton(list-row)" | "NSButton(outline-row)" => Ok(AppKitWidgetKind::ListItem),
197-
"NSPanel" => Ok(AppKitWidgetKind::Panel),
198-
"NSPopover" => Ok(AppKitWidgetKind::Popover),
199-
"NSTabView" => Ok(AppKitWidgetKind::Tabs),
200-
"NSTabViewItem" => Ok(AppKitWidgetKind::Tab),
201-
"NSMenu" => Ok(AppKitWidgetKind::Menu),
202-
"NSMenuItem" => Ok(AppKitWidgetKind::MenuItem),
203-
"NSBox(separator)" => Ok(AppKitWidgetKind::Separator),
204-
"NSSlider" => Ok(AppKitWidgetKind::Slider),
205-
"NSProgressIndicator" | "NSProgressIndicator(meter)" => {
206-
Ok(AppKitWidgetKind::ProgressIndicator)
207-
}
208-
"NSStackView(toolbar)" | "NSToolbar" => Ok(AppKitWidgetKind::Toolbar),
209-
other => Err(GuiError::host(format!(
210-
"unsupported AppKit widget class {other}"
211-
))),
212-
}
213-
}
21480
}
21581

21682
#[cfg(any(test, feature = "appkit-native"))]

src/event.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,35 @@ use serde::de::DeserializeOwned;
1010
use serde::{Deserialize, Serialize};
1111
use serde_json::Value as JsonValue;
1212

13-
#[allow(dead_code)]
13+
#[cfg(any(
14+
test,
15+
all(feature = "appkit-native", target_os = "macos"),
16+
all(feature = "gtk4-native", target_os = "linux"),
17+
all(feature = "winui-native", target_os = "windows")
18+
))]
1419
mod move_interaction;
15-
#[allow(dead_code)]
20+
#[cfg(any(
21+
test,
22+
all(feature = "appkit-native", target_os = "macos"),
23+
all(feature = "gtk4-native", target_os = "linux"),
24+
all(feature = "winui-native", target_os = "windows")
25+
))]
1626
mod press;
1727

18-
#[allow(unused_imports)]
28+
#[cfg(any(
29+
all(feature = "appkit-native", target_os = "macos"),
30+
all(feature = "gtk4-native", target_os = "linux"),
31+
all(feature = "winui-native", target_os = "windows")
32+
))]
1933
pub(crate) use move_interaction::{keyboard_move_events, PointerMoveState};
20-
#[allow(unused_imports)]
34+
#[cfg(any(
35+
all(feature = "appkit-native", target_os = "macos"),
36+
all(feature = "gtk4-native", target_os = "linux"),
37+
all(feature = "winui-native", target_os = "windows")
38+
))]
2139
pub(crate) use press::{
22-
virtual_press_events, KeyboardPressState, NativeInteractionProfile,
23-
NativeInteractionSubscriptions, NativeLongPressConfig, NativeLongPressMode,
24-
NativeLongPressTimer, NumberFieldStepperPressState, NumberFieldStepperTimer, PointerPressState,
40+
virtual_press_events, KeyboardPressState, NativeInteractionProfile, NativeLongPressTimer,
41+
NumberFieldStepperPressState, NumberFieldStepperTimer, PointerPressState,
2542
};
2643

2744
/// Maximum number of successful action invocations retained for diagnostics by default.

src/event/move_interaction.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ pub(crate) struct PointerMoveState {
1414
}
1515

1616
impl PointerMoveState {
17+
#[cfg(any(
18+
test,
19+
all(feature = "appkit-native", target_os = "macos"),
20+
all(feature = "gtk4-native", target_os = "linux")
21+
))]
1722
pub(crate) fn begin(&mut self, context: NativeEventContext) {
1823
self.begin_pointer(0, context);
1924
}
@@ -25,6 +30,11 @@ impl PointerMoveState {
2530
self.last_position = self.active.then_some(context.position).flatten();
2631
}
2732

33+
#[cfg(any(
34+
test,
35+
all(feature = "appkit-native", target_os = "macos"),
36+
all(feature = "gtk4-native", target_os = "linux")
37+
))]
2838
pub(crate) fn update(
2939
&mut self,
3040
node: HostNodeId,
@@ -70,6 +80,11 @@ impl PointerMoveState {
7080
}
7181
}
7282

83+
#[cfg(any(
84+
test,
85+
all(feature = "appkit-native", target_os = "macos"),
86+
all(feature = "gtk4-native", target_os = "linux")
87+
))]
7388
pub(crate) fn end(
7489
&mut self,
7590
node: HostNodeId,

src/event/press.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) struct NativeInteractionSubscriptions {
2727
}
2828

2929
impl NativeInteractionSubscriptions {
30+
#[cfg(test)]
3031
pub(crate) fn from_blueprint(blueprint: &NativeWidgetBlueprint) -> Self {
3132
let mut subscriptions = Self::from_events(
3233
&blueprint.events,
@@ -114,6 +115,11 @@ pub(crate) struct NativeLongPressConfig {
114115
}
115116

116117
impl NativeLongPressConfig {
118+
#[cfg(any(
119+
test,
120+
all(feature = "appkit-native", target_os = "macos"),
121+
all(feature = "gtk4-native", target_os = "linux")
122+
))]
117123
pub(crate) const fn disabled() -> Self {
118124
Self {
119125
mode: NativeLongPressMode::Disabled,
@@ -165,14 +171,11 @@ pub(crate) struct NativeLongPressRecognition {
165171
}
166172

167173
impl NativeLongPressRecognition {
174+
#[cfg(all(feature = "appkit-native", target_os = "macos"))]
168175
pub(crate) fn node(&self) -> HostNodeId {
169176
self.node
170177
}
171178

172-
pub(crate) fn context(&self) -> NativeEventContext {
173-
self.context
174-
}
175-
176179
pub(crate) fn cancellation_events(&self) -> [NativeEvent; 2] {
177180
[
178181
event(self.node, NativeEventKind::LongPressEnd, self.context),
@@ -560,6 +563,11 @@ impl NativeInteractionProfile {
560563
}
561564
}
562565

566+
#[cfg(any(
567+
test,
568+
all(feature = "appkit-native", target_os = "macos"),
569+
all(feature = "gtk4-native", target_os = "linux")
570+
))]
563571
pub(crate) fn normalizes_keyboard_press(self) -> bool {
564572
self.subscriptions.tracks_press()
565573
&& matches!(
@@ -746,13 +754,22 @@ impl KeyboardPressState {
746754
}
747755
}
748756

749-
#[allow(dead_code)]
757+
#[cfg(any(
758+
all(feature = "appkit-native", target_os = "macos"),
759+
all(feature = "gtk4-native", target_os = "linux"),
760+
all(feature = "winui-native", target_os = "windows")
761+
))]
750762
pub(crate) fn remove(&mut self, node: HostNodeId) {
751763
self.active.remove(&node);
752764
}
753765
}
754766

755767
impl PointerPressState {
768+
#[cfg(any(
769+
test,
770+
all(feature = "appkit-native", target_os = "macos"),
771+
all(feature = "gtk4-native", target_os = "linux")
772+
))]
756773
pub(crate) fn begin(
757774
&mut self,
758775
node: HostNodeId,
@@ -766,6 +783,11 @@ impl PointerPressState {
766783
)
767784
}
768785

786+
#[cfg(any(
787+
all(feature = "appkit-native", target_os = "macos"),
788+
all(feature = "gtk4-native", target_os = "linux"),
789+
all(feature = "winui-native", target_os = "windows")
790+
))]
769791
pub(crate) fn begin_with_long_press(
770792
&mut self,
771793
node: HostNodeId,

0 commit comments

Comments
 (0)