mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
[OH] Provide correct geometry offset and fix available screen dimensions (#36915)
This commit corrects the geometry details provided under the OH platform by getting the offset from the OS. OH port provides correct offset and available space. Fixes: #36466 --------- Signed-off-by: Astraea Quinn Skoutelli <astraea.quinn.skoutelli@huawei.com> Signed-off-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Co-authored-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com>
This commit is contained in:
parent
2aaf9695df
commit
366515f256
3 changed files with 47 additions and 6 deletions
|
@ -38,6 +38,14 @@ impl Coordinates {
|
||||||
viewport: Rect::new(Point2D::new(x, y), Size2D::new(width, height)),
|
viewport: Rect::new(Point2D::new(x, y), Size2D::new(width, height)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn origin(&self) -> Point2D<i32, DevicePixel> {
|
||||||
|
self.viewport.origin
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size(&self) -> Size2D<i32, DevicePixel> {
|
||||||
|
self.viewport.size
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct ServoWindowCallbacks {
|
pub(super) struct ServoWindowCallbacks {
|
||||||
|
@ -115,11 +123,13 @@ impl ServoDelegate for ServoShellServoDelegate {
|
||||||
impl WebViewDelegate for RunningAppState {
|
impl WebViewDelegate for RunningAppState {
|
||||||
fn screen_geometry(&self, _webview: WebView) -> Option<ScreenGeometry> {
|
fn screen_geometry(&self, _webview: WebView) -> Option<ScreenGeometry> {
|
||||||
let coord = self.callbacks.coordinates.borrow();
|
let coord = self.callbacks.coordinates.borrow();
|
||||||
let screen_size = DeviceIntSize::new(coord.viewport.size.width, coord.viewport.size.height);
|
let offset = coord.origin();
|
||||||
|
let available_size = coord.size();
|
||||||
|
let screen_size = coord.size();
|
||||||
Some(ScreenGeometry {
|
Some(ScreenGeometry {
|
||||||
size: screen_size,
|
size: screen_size,
|
||||||
available_size: screen_size,
|
available_size,
|
||||||
offset: Point2D::zero(),
|
offset,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,8 +28,9 @@ use servo::{
|
||||||
use xcomponent_sys::{
|
use xcomponent_sys::{
|
||||||
OH_NativeXComponent, OH_NativeXComponent_Callback, OH_NativeXComponent_GetKeyEvent,
|
OH_NativeXComponent, OH_NativeXComponent_Callback, OH_NativeXComponent_GetKeyEvent,
|
||||||
OH_NativeXComponent_GetKeyEventAction, OH_NativeXComponent_GetKeyEventCode,
|
OH_NativeXComponent_GetKeyEventAction, OH_NativeXComponent_GetKeyEventCode,
|
||||||
OH_NativeXComponent_GetTouchEvent, OH_NativeXComponent_GetXComponentSize,
|
OH_NativeXComponent_GetTouchEvent, OH_NativeXComponent_GetXComponentOffset,
|
||||||
OH_NativeXComponent_KeyAction, OH_NativeXComponent_KeyCode, OH_NativeXComponent_KeyEvent,
|
OH_NativeXComponent_GetXComponentSize, OH_NativeXComponent_KeyAction,
|
||||||
|
OH_NativeXComponent_KeyCode, OH_NativeXComponent_KeyEvent,
|
||||||
OH_NativeXComponent_RegisterCallback, OH_NativeXComponent_RegisterKeyEventCallback,
|
OH_NativeXComponent_RegisterCallback, OH_NativeXComponent_RegisterKeyEventCallback,
|
||||||
OH_NativeXComponent_TouchEvent, OH_NativeXComponent_TouchEventType,
|
OH_NativeXComponent_TouchEvent, OH_NativeXComponent_TouchEventType,
|
||||||
};
|
};
|
||||||
|
@ -267,6 +268,33 @@ extern "C" fn on_surface_created_cb(xcomponent: *mut OH_NativeXComponent, window
|
||||||
info!("Returning from on_surface_created_cb");
|
info!("Returning from on_surface_created_cb");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the offset of the surface relative to its parent's top left corner
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// `xcomponent` and `native_window` must be valid, non-null and aligned pointers to a
|
||||||
|
/// live xcomponent and associated native window surface.
|
||||||
|
unsafe fn get_xcomponent_offset(
|
||||||
|
xcomponent: *mut OH_NativeXComponent,
|
||||||
|
native_window: *mut c_void,
|
||||||
|
) -> Result<(i32, i32), i32> {
|
||||||
|
let mut x: f64 = 0.0;
|
||||||
|
let mut y: f64 = 0.0;
|
||||||
|
|
||||||
|
let result = unsafe {
|
||||||
|
OH_NativeXComponent_GetXComponentOffset(xcomponent, native_window, &raw mut x, &raw mut y)
|
||||||
|
};
|
||||||
|
if result != 0 {
|
||||||
|
error!("OH_NativeXComponent_GetXComponentOffset failed with {result}");
|
||||||
|
return Err(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((
|
||||||
|
(x.round() as i64).try_into().expect("X offset too large"),
|
||||||
|
(y.round() as i64).try_into().expect("Y offset too large"),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the size of the surface
|
/// Returns the size of the surface
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
|
|
|
@ -97,7 +97,10 @@ pub fn init(
|
||||||
let Ok(window_size) = (unsafe { super::get_xcomponent_size(xcomponent, native_window) }) else {
|
let Ok(window_size) = (unsafe { super::get_xcomponent_size(xcomponent, native_window) }) else {
|
||||||
return Err("Failed to get xcomponent size");
|
return Err("Failed to get xcomponent size");
|
||||||
};
|
};
|
||||||
let coordinates = Coordinates::new(0, 0, window_size.width, window_size.height);
|
let Ok((x, y)) = (unsafe { super::get_xcomponent_offset(xcomponent, native_window) }) else {
|
||||||
|
return Err("Failed to get xcomponent offset");
|
||||||
|
};
|
||||||
|
let coordinates = Coordinates::new(x, y, window_size.width, window_size.height);
|
||||||
|
|
||||||
let display_handle = RawDisplayHandle::Ohos(OhosDisplayHandle::new());
|
let display_handle = RawDisplayHandle::Ohos(OhosDisplayHandle::new());
|
||||||
let display_handle = unsafe { DisplayHandle::borrow_raw(display_handle) };
|
let display_handle = unsafe { DisplayHandle::borrow_raw(display_handle) };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue