mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Make Window::scroll_offsets store keys as OpaqueNode values
This is the type that is supposed to signal that we will never ever try to get back a Node from it in an unsafe way, unlike UntrustedNodeAddress.
This commit is contained in:
parent
887cc62556
commit
e57d09abb8
3 changed files with 12 additions and 14 deletions
|
@ -115,6 +115,7 @@ use std::sync::{Arc, Mutex};
|
||||||
use std::time::{Instant, SystemTime};
|
use std::time::{Instant, SystemTime};
|
||||||
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
|
use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
|
||||||
use style::context::QuirksMode;
|
use style::context::QuirksMode;
|
||||||
|
use style::dom::OpaqueNode;
|
||||||
use style::element_state::*;
|
use style::element_state::*;
|
||||||
use style::media_queries::MediaList;
|
use style::media_queries::MediaList;
|
||||||
use style::properties::PropertyDeclarationBlock;
|
use style::properties::PropertyDeclarationBlock;
|
||||||
|
@ -418,7 +419,7 @@ unsafe_no_jsmanaged_fields!(BufferQueue, QuirksMode, StrTendril);
|
||||||
unsafe_no_jsmanaged_fields!(Runtime);
|
unsafe_no_jsmanaged_fields!(Runtime);
|
||||||
unsafe_no_jsmanaged_fields!(HeaderMap, Method);
|
unsafe_no_jsmanaged_fields!(HeaderMap, Method);
|
||||||
unsafe_no_jsmanaged_fields!(WindowProxyHandler);
|
unsafe_no_jsmanaged_fields!(WindowProxyHandler);
|
||||||
unsafe_no_jsmanaged_fields!(UntrustedNodeAddress);
|
unsafe_no_jsmanaged_fields!(UntrustedNodeAddress, OpaqueNode);
|
||||||
unsafe_no_jsmanaged_fields!(LengthOrPercentageOrAuto);
|
unsafe_no_jsmanaged_fields!(LengthOrPercentageOrAuto);
|
||||||
unsafe_no_jsmanaged_fields!(RGBA);
|
unsafe_no_jsmanaged_fields!(RGBA);
|
||||||
unsafe_no_jsmanaged_fields!(StorageType);
|
unsafe_no_jsmanaged_fields!(StorageType);
|
||||||
|
|
|
@ -102,7 +102,7 @@ use script_layout_interface::{PendingImageState, TrustedNodeAddress};
|
||||||
use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
|
use script_traits::webdriver_msg::{WebDriverJSError, WebDriverJSResult};
|
||||||
use script_traits::{ConstellationControlMsg, DocumentState, LoadData};
|
use script_traits::{ConstellationControlMsg, DocumentState, LoadData};
|
||||||
use script_traits::{ScriptMsg, ScriptToConstellationChan, ScrollState, TimerEvent, TimerEventId};
|
use script_traits::{ScriptMsg, ScriptToConstellationChan, ScrollState, TimerEvent, TimerEventId};
|
||||||
use script_traits::{TimerSchedulerMsg, UntrustedNodeAddress, WindowSizeData, WindowSizeType};
|
use script_traits::{TimerSchedulerMsg, WindowSizeData, WindowSizeType};
|
||||||
use selectors::attr::CaseSensitivity;
|
use selectors::attr::CaseSensitivity;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use servo_geometry::{f32_rect_to_au_rect, MaxRect};
|
use servo_geometry::{f32_rect_to_au_rect, MaxRect};
|
||||||
|
@ -119,6 +119,7 @@ use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use style::dom::OpaqueNode;
|
||||||
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
use style::error_reporting::{ContextualParseError, ParseErrorReporter};
|
||||||
use style::media_queries;
|
use style::media_queries;
|
||||||
use style::parser::ParserContext as CssParserContext;
|
use style::parser::ParserContext as CssParserContext;
|
||||||
|
@ -247,7 +248,7 @@ pub struct Window {
|
||||||
error_reporter: CSSErrorReporter,
|
error_reporter: CSSErrorReporter,
|
||||||
|
|
||||||
/// A list of scroll offsets for each scrollable element.
|
/// A list of scroll offsets for each scrollable element.
|
||||||
scroll_offsets: DomRefCell<HashMap<UntrustedNodeAddress, Vector2D<f32>>>,
|
scroll_offsets: DomRefCell<HashMap<OpaqueNode, Vector2D<f32>>>,
|
||||||
|
|
||||||
/// All the MediaQueryLists we need to update
|
/// All the MediaQueryLists we need to update
|
||||||
media_query_lists: DOMTracker<MediaQueryList>,
|
media_query_lists: DOMTracker<MediaQueryList>,
|
||||||
|
@ -389,7 +390,7 @@ impl Window {
|
||||||
/// Sets a new list of scroll offsets.
|
/// Sets a new list of scroll offsets.
|
||||||
///
|
///
|
||||||
/// This is called when layout gives us new ones and WebRender is in use.
|
/// This is called when layout gives us new ones and WebRender is in use.
|
||||||
pub fn set_scroll_offsets(&self, offsets: HashMap<UntrustedNodeAddress, Vector2D<f32>>) {
|
pub fn set_scroll_offsets(&self, offsets: HashMap<OpaqueNode, Vector2D<f32>>) {
|
||||||
*self.scroll_offsets.borrow_mut() = offsets
|
*self.scroll_offsets.borrow_mut() = offsets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1601,11 +1602,7 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scroll_offset_query(&self, node: &Node) -> Vector2D<f32> {
|
pub fn scroll_offset_query(&self, node: &Node) -> Vector2D<f32> {
|
||||||
if let Some(scroll_offset) = self
|
if let Some(scroll_offset) = self.scroll_offsets.borrow().get(&node.to_opaque()) {
|
||||||
.scroll_offsets
|
|
||||||
.borrow()
|
|
||||||
.get(&node.to_untrusted_node_address())
|
|
||||||
{
|
|
||||||
return *scroll_offset;
|
return *scroll_offset;
|
||||||
}
|
}
|
||||||
Vector2D::new(0.0, 0.0)
|
Vector2D::new(0.0, 0.0)
|
||||||
|
@ -1620,10 +1617,9 @@ impl Window {
|
||||||
// The scroll offsets are immediatly updated since later calls
|
// The scroll offsets are immediatly updated since later calls
|
||||||
// to topScroll and others may access the properties before
|
// to topScroll and others may access the properties before
|
||||||
// webrender has a chance to update the offsets.
|
// webrender has a chance to update the offsets.
|
||||||
self.scroll_offsets.borrow_mut().insert(
|
self.scroll_offsets
|
||||||
node.to_untrusted_node_address(),
|
.borrow_mut()
|
||||||
Vector2D::new(x_ as f32, y_ as f32),
|
.insert(node.to_opaque(), Vector2D::new(x_ as f32, y_ as f32));
|
||||||
);
|
|
||||||
|
|
||||||
let NodeScrollIdResponse(scroll_id) = self.layout_rpc.node_scroll_id();
|
let NodeScrollIdResponse(scroll_id) = self.layout_rpc.node_scroll_id();
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,7 @@ use std::result::Result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
use style::dom::OpaqueNode;
|
||||||
use style::thread_state::{self, ThreadState};
|
use style::thread_state::{self, ThreadState};
|
||||||
use time::{at_utc, get_time, precise_time_ns, Timespec};
|
use time::{at_utc, get_time, precise_time_ns, Timespec};
|
||||||
use url::percent_encoding::percent_decode;
|
use url::percent_encoding::percent_decode;
|
||||||
|
@ -1914,7 +1915,7 @@ impl ScriptThread {
|
||||||
if node_address == UntrustedNodeAddress(ptr::null()) {
|
if node_address == UntrustedNodeAddress(ptr::null()) {
|
||||||
window.update_viewport_for_scroll(-scroll_offset.x, -scroll_offset.y);
|
window.update_viewport_for_scroll(-scroll_offset.x, -scroll_offset.y);
|
||||||
} else {
|
} else {
|
||||||
scroll_offsets.insert(node_address, -*scroll_offset);
|
scroll_offsets.insert(OpaqueNode(node_address.0 as usize), -*scroll_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
window.set_scroll_offsets(scroll_offsets)
|
window.set_scroll_offsets(scroll_offsets)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue