Skip to content

Commit 872427c

Browse files
authored
refactor: simplify logic between CefTexture and CefTexture2D (#171)
1 parent f770eb8 commit 872427c

14 files changed

Lines changed: 1316 additions & 788 deletions

File tree

crates/gdcef/src/cef_texture/browser_lifecycle.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
use super::{CefTexture, backend};
1+
use super::CefTexture;
22
use crate::browser::LifecycleState;
3+
use crate::cef_texture::backend;
34
use crate::error::CefError;
45
use godot::prelude::*;
56

67
impl CefTexture {
78
fn log_cleanup_state_violations(&self) {
8-
if self.app.state.is_some() {
9+
if self.with_app(|app| app.state.is_some()) {
910
godot::global::godot_warn!(
1011
"[CefTexture] Cleanup invariant violation: runtime state not fully cleared"
1112
);
1213
}
14+
let lifecycle_state = self.with_app(|app| app.lifecycle_state());
1315
if !matches!(
14-
self.app.lifecycle_state(),
16+
lifecycle_state,
1517
LifecycleState::Closed | LifecycleState::Retained
1618
) {
1719
godot::global::godot_warn!(
1820
"[CefTexture] Cleanup invariant violation: unexpected lifecycle state {:?}",
19-
self.app.lifecycle_state()
21+
lifecycle_state
2022
);
2123
}
2224
}
2325

2426
pub(super) fn cleanup_instance(&mut self) {
2527
self.base_mut().set_visible(false);
26-
backend::cleanup_runtime(&mut self.app, self.popup_texture_2d_rd.as_mut());
28+
let mut popup_texture_2d_rd = self.popup_texture_2d_rd.take();
29+
self.with_app_mut(|app| backend::cleanup_runtime(app, popup_texture_2d_rd.as_mut()));
30+
self.popup_texture_2d_rd = popup_texture_2d_rd;
2731

2832
self.ime_active = false;
2933
self.ime_proxy = None;
30-
self.last_find_query = GString::new();
31-
self.last_find_match_case = false;
3234

3335
if let Some(mut overlay) = self.popup_overlay.take() {
3436
overlay.queue_free();
@@ -50,33 +52,35 @@ impl CefTexture {
5052
}
5153

5254
pub(super) fn try_create_browser(&mut self) -> Result<(), CefError> {
53-
if self.app.state.is_some() {
55+
if self.with_app(|app| app.state.is_some()) {
5456
return Ok(());
5557
}
56-
if !self.app.begin_browser_create() {
58+
if !self.with_app_mut(|app| app.begin_browser_create()) {
5759
return Ok(());
5860
}
5961

6062
let logical_size = self.base().get_size();
6163
let dpi = self.get_pixel_scale_factor();
64+
let max_fps = self.get_max_fps();
6265
let params = backend::BackendCreateParams {
6366
logical_size,
6467
dpi,
65-
max_fps: self.get_max_fps(),
68+
max_fps,
6669
url: self.url.to_string(),
6770
enable_accelerated_osr: self.enable_accelerated_osr,
6871
background_color: self.background_color,
6972
popup_policy: self.popup_policy,
7073
software_target_texture: None,
7174
log_prefix: "CefTexture",
7275
};
73-
if let Err(err) = backend::try_create_browser(&mut self.app, &params) {
74-
self.app.mark_browser_closed();
76+
if let Err(err) = self.with_app_mut(|app| backend::try_create_browser(app, &params)) {
77+
self.with_app_mut(|app| app.mark_browser_closed());
7578
return Err(err);
7679
}
77-
self.app.mark_browser_running();
78-
if let Some(state) = self.app.state.as_ref() {
79-
let texture = state.render_mode.texture_2d();
80+
self.with_app_mut(|app| app.mark_browser_running());
81+
if let Some(texture) =
82+
self.with_app(|app| app.state.as_ref().map(|s| s.render_mode.texture_2d()))
83+
{
8084
self.base_mut().set_texture(&texture);
8185
}
8286

crates/gdcef/src/cef_texture/ime.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl CefTexture {
6666

6767
/// Called when the IME proxy LineEdit text changes during composition.
6868
pub(super) fn on_ime_proxy_text_changed_impl(&mut self, new_text: GString) {
69-
let Some(host) = self.app.host() else {
69+
let Some(host) = self.with_app(|app| app.host()) else {
7070
return;
7171
};
7272

@@ -124,7 +124,7 @@ impl CefTexture {
124124
proxy.grab_focus();
125125
}
126126

127-
if let Some(host) = self.app.host() {
127+
if let Some(host) = self.with_app(|app| app.host()) {
128128
host.set_focus(true as _);
129129
}
130130

@@ -159,7 +159,7 @@ impl CefTexture {
159159
let end = ime_selection.y.max(0) as u32;
160160

161161
// Update the IME composition text
162-
if let Some(host) = self.app.host() {
162+
if let Some(host) = self.with_app(|app| app.host()) {
163163
input::ime_set_composition(&host, &ime_text, start, end);
164164
}
165165
}

0 commit comments

Comments
 (0)