objc2_web_kit/generated/NSAttributedString.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9use objc2_foundation::*;
10
11use crate::*;
12
13extern "C" {
14 /// Indicates which local files WebKit can access when loading content.
15 ///
16 /// If NSReadAccessURLDocumentOption references a single file, only that file may be
17 /// loaded by WebKit. If NSReadAccessURLDocumentOption references a directory, files inside that
18 /// directory may be loaded by WebKit.
19 ///
20 /// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/nsreadaccessurldocumentoption?language=objc)
21 #[cfg(feature = "objc2-app-kit")]
22 #[cfg(target_os = "macos")]
23 pub static NSReadAccessURLDocumentOption: &'static NSAttributedStringDocumentReadingOptionKey;
24}
25
26/// Type definition for the completion handler block used to get asynchronous attributed strings.
27///
28/// The completion handler block is passed the attributed string result along with any
29/// document-level attributes, like NSBackgroundColorDocumentAttribute, or an error. An implementation
30/// of this block type must expect to be called asynchronously when passed to HTML loading methods.
31///
32/// See also [Apple's documentation](https://developer.apple.com/documentation/webkit/nsattributedstringcompletionhandler?language=objc)
33#[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
34#[cfg(target_os = "macos")]
35pub type NSAttributedStringCompletionHandler = *mut block2::DynBlock<
36 dyn Fn(
37 *mut NSAttributedString,
38 *mut NSDictionary<NSAttributedStringDocumentAttributeKey, AnyObject>,
39 *mut NSError,
40 ),
41>;
42
43mod private_NSAttributedStringWebKitAdditions {
44 pub trait Sealed {}
45}
46
47/// Category on [`NSAttributedString`].
48///
49/// Extension of
50///
51/// ```text
52/// //apple_ref/occ/NSAttributedString NSAttributedString
53/// ```
54///
55/// to
56/// create attributed strings from HTML content using WebKit.
57pub unsafe trait NSAttributedStringWebKitAdditions:
58 ClassType + Sized + private_NSAttributedStringWebKitAdditions::Sealed
59{
60 extern_methods!(
61 #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
62 #[cfg(target_os = "macos")]
63 /// Loads an HTML URL request and converts the contents into an attributed string.
64 ///
65 /// Parameter `request`: The request specifying the URL to load.
66 ///
67 /// Parameter `options`: Document attributes for interpreting the document contents.
68 /// NSTextSizeMultiplierDocumentOption and NSTimeoutDocumentOption are supported option keys.
69 ///
70 /// Parameter `completionHandler`: A block to invoke when the operation completes or fails.
71 ///
72 /// The completionHandler is passed the attributed string result along with any
73 /// document-level attributes, or an error.
74 ///
75 /// # Safety
76 ///
77 /// - `options` generic should be of the correct type.
78 /// - `completion_handler` must be a valid pointer.
79 #[unsafe(method(loadFromHTMLWithRequest:options:completionHandler:))]
80 #[unsafe(method_family = none)]
81 unsafe fn loadFromHTMLWithRequest_options_completionHandler(
82 request: &NSURLRequest,
83 options: &NSDictionary<NSAttributedStringDocumentReadingOptionKey, AnyObject>,
84 completion_handler: NSAttributedStringCompletionHandler,
85 );
86
87 #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
88 #[cfg(target_os = "macos")]
89 /// Converts a local HTML file into an attributed string.
90 ///
91 /// Parameter `fileURL`: The file URL to load.
92 ///
93 /// Parameter `options`: Document attributes for interpreting the document contents.
94 /// NSTextSizeMultiplierDocumentOption, NSTimeoutDocumentOption and NSReadAccessURLDocumentOption
95 /// are supported option keys.
96 ///
97 /// Parameter `completionHandler`: A block to invoke when the operation completes or fails.
98 ///
99 /// The completionHandler is passed the attributed string result along with any
100 /// document-level attributes, or an error. If NSReadAccessURLDocumentOption references a single file,
101 /// only that file may be loaded by WebKit. If NSReadAccessURLDocumentOption references a directory,
102 /// files inside that directory may be loaded by WebKit.
103 ///
104 /// # Safety
105 ///
106 /// - `options` generic should be of the correct type.
107 /// - `completion_handler` must be a valid pointer.
108 #[unsafe(method(loadFromHTMLWithFileURL:options:completionHandler:))]
109 #[unsafe(method_family = none)]
110 unsafe fn loadFromHTMLWithFileURL_options_completionHandler(
111 file_url: &NSURL,
112 options: &NSDictionary<NSAttributedStringDocumentReadingOptionKey, AnyObject>,
113 completion_handler: NSAttributedStringCompletionHandler,
114 );
115
116 #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
117 #[cfg(target_os = "macos")]
118 /// Converts an HTML string into an attributed string.
119 ///
120 /// Parameter `string`: The HTML string to use as the contents.
121 ///
122 /// Parameter `options`: Document attributes for interpreting the document contents.
123 /// NSTextSizeMultiplierDocumentOption, NSTimeoutDocumentOption and NSBaseURLDocumentOption
124 /// are supported option keys.
125 ///
126 /// Parameter `completionHandler`: A block to invoke when the operation completes or fails.
127 ///
128 /// The completionHandler is passed the attributed string result along with any
129 /// document-level attributes, or an error. NSBaseURLDocumentOption is used to resolve relative URLs
130 /// within the document.
131 ///
132 /// # Safety
133 ///
134 /// - `options` generic should be of the correct type.
135 /// - `completion_handler` must be a valid pointer.
136 #[unsafe(method(loadFromHTMLWithString:options:completionHandler:))]
137 #[unsafe(method_family = none)]
138 unsafe fn loadFromHTMLWithString_options_completionHandler(
139 string: &NSString,
140 options: &NSDictionary<NSAttributedStringDocumentReadingOptionKey, AnyObject>,
141 completion_handler: NSAttributedStringCompletionHandler,
142 );
143
144 #[cfg(all(feature = "block2", feature = "objc2-app-kit"))]
145 #[cfg(target_os = "macos")]
146 /// Converts HTML data into an attributed string.
147 ///
148 /// Parameter `data`: The HTML data to use as the contents.
149 ///
150 /// Parameter `options`: Document attributes for interpreting the document contents.
151 /// NSTextSizeMultiplierDocumentOption, NSTimeoutDocumentOption, NSTextEncodingNameDocumentOption,
152 /// and NSCharacterEncodingDocumentOption are supported option keys.
153 ///
154 /// Parameter `completionHandler`: A block to invoke when the operation completes or fails.
155 ///
156 /// The completionHandler is passed the attributed string result along with any
157 /// document-level attributes, or an error. If neither NSTextEncodingNameDocumentOption nor
158 /// NSCharacterEncodingDocumentOption is supplied, a best-guess encoding is used.
159 ///
160 /// # Safety
161 ///
162 /// - `options` generic should be of the correct type.
163 /// - `completion_handler` must be a valid pointer.
164 #[unsafe(method(loadFromHTMLWithData:options:completionHandler:))]
165 #[unsafe(method_family = none)]
166 unsafe fn loadFromHTMLWithData_options_completionHandler(
167 data: &NSData,
168 options: &NSDictionary<NSAttributedStringDocumentReadingOptionKey, AnyObject>,
169 completion_handler: NSAttributedStringCompletionHandler,
170 );
171 );
172}
173
174impl private_NSAttributedStringWebKitAdditions::Sealed for NSAttributedString {}
175unsafe impl NSAttributedStringWebKitAdditions for NSAttributedString {}