2020-03-20 14:07:44 +11:00
|
|
|
//! A `WebViewHandle` represents an underlying `WKWebView`. You're passed a reference to one during your
|
|
|
|
//! `WebViewController::did_load()` method. This method is safe to store and use, however as it's
|
2020-03-18 12:19:56 +11:00
|
|
|
//! UI-specific it's not thread safe.
|
|
|
|
//!
|
|
|
|
//! You can use this struct to configure how a view should look and layout. It implements
|
|
|
|
//! AutoLayout - for more information, see the AutoLayout tutorial.
|
2020-03-05 13:33:11 +11:00
|
|
|
|
|
|
|
use objc_id::ShareId;
|
|
|
|
use objc::runtime::Object;
|
2020-03-07 14:35:18 +11:00
|
|
|
use objc::{msg_send, sel, sel_impl};
|
2020-03-05 13:33:11 +11:00
|
|
|
|
2020-03-18 12:19:56 +11:00
|
|
|
use crate::foundation::{id, YES, NSArray, NSString};
|
2020-03-07 14:35:18 +11:00
|
|
|
use crate::color::Color;
|
2020-03-18 12:19:56 +11:00
|
|
|
use crate::constants::BACKGROUND_COLOR;
|
2020-03-13 12:18:32 +11:00
|
|
|
use crate::layout::{Layout, LayoutAnchorX, LayoutAnchorY, LayoutAnchorDimension};
|
2020-03-07 14:35:18 +11:00
|
|
|
use crate::pasteboard::PasteboardType;
|
2020-03-05 13:33:11 +11:00
|
|
|
|
2020-03-12 11:56:17 +11:00
|
|
|
/// A clone-able handler to a `ViewController` reference in the Objective C runtime. We use this
|
2020-03-20 14:07:44 +11:00
|
|
|
/// instead of a stock `WKWebView` for easier recordkeeping, since it'll need to hold the `WKWebView` on that
|
2020-03-12 11:56:17 +11:00
|
|
|
/// side anyway.
|
|
|
|
#[derive(Debug, Default, Clone)]
|
2020-03-20 14:07:44 +11:00
|
|
|
pub struct WebViewHandle {
|
2020-03-13 12:18:32 +11:00
|
|
|
/// A pointer to the Objective-C runtime view controller.
|
|
|
|
pub objc: Option<ShareId<Object>>,
|
|
|
|
|
|
|
|
/// A pointer to the Objective-C runtime top layout constraint.
|
|
|
|
pub top: LayoutAnchorY,
|
|
|
|
|
|
|
|
/// A pointer to the Objective-C runtime leading layout constraint.
|
|
|
|
pub leading: LayoutAnchorX,
|
|
|
|
|
|
|
|
/// A pointer to the Objective-C runtime trailing layout constraint.
|
|
|
|
pub trailing: LayoutAnchorX,
|
|
|
|
|
|
|
|
/// A pointer to the Objective-C runtime bottom layout constraint.
|
|
|
|
pub bottom: LayoutAnchorY,
|
|
|
|
|
|
|
|
/// A pointer to the Objective-C runtime width layout constraint.
|
|
|
|
pub width: LayoutAnchorDimension,
|
|
|
|
|
|
|
|
/// A pointer to the Objective-C runtime height layout constraint.
|
|
|
|
pub height: LayoutAnchorDimension,
|
|
|
|
|
|
|
|
/// A pointer to the Objective-C runtime center X layout constraint.
|
|
|
|
pub center_x: LayoutAnchorX,
|
|
|
|
|
|
|
|
/// A pointer to the Objective-C runtime center Y layout constraint.
|
|
|
|
pub center_y: LayoutAnchorY
|
|
|
|
}
|
2020-03-05 13:33:11 +11:00
|
|
|
|
2020-03-20 14:07:44 +11:00
|
|
|
impl WebViewHandle {
|
2020-03-13 12:18:32 +11:00
|
|
|
pub(crate) fn new(object: ShareId<Object>) -> Self {
|
|
|
|
let view: id = unsafe {
|
|
|
|
msg_send![&*object, view]
|
|
|
|
};
|
|
|
|
|
2020-03-20 14:07:44 +11:00
|
|
|
WebViewHandle {
|
2020-03-13 12:18:32 +11:00
|
|
|
objc: Some(object),
|
|
|
|
top: LayoutAnchorY::new(unsafe { msg_send![view, topAnchor] }),
|
|
|
|
leading: LayoutAnchorX::new(unsafe { msg_send![view, leadingAnchor] }),
|
|
|
|
trailing: LayoutAnchorX::new(unsafe { msg_send![view, trailingAnchor] }),
|
|
|
|
bottom: LayoutAnchorY::new(unsafe { msg_send![view, bottomAnchor] }),
|
|
|
|
width: LayoutAnchorDimension::new(unsafe { msg_send![view, widthAnchor] }),
|
|
|
|
height: LayoutAnchorDimension::new(unsafe { msg_send![view, heightAnchor] }),
|
|
|
|
center_x: LayoutAnchorX::new(unsafe { msg_send![view, centerXAnchor] }),
|
|
|
|
center_y: LayoutAnchorY::new(unsafe { msg_send![view, centerYAnchor] }),
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 11:56:17 +11:00
|
|
|
}
|