Struct headless_chrome::browser::tab::element::ElementQuad
source · pub struct ElementQuad {
pub top_left: Point,
pub top_right: Point,
pub bottom_left: Point,
pub bottom_right: Point,
}
Fields§
§top_left: Point
§top_right: Point
§bottom_left: Point
§bottom_right: Point
Implementations§
source§impl ElementQuad
impl ElementQuad
sourcepub fn from_raw_points(raw_quad: &[f64]) -> Self
pub fn from_raw_points(raw_quad: &[f64]) -> Self
Examples found in repository?
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
pub fn get_box_model(&self) -> Result<BoxModel> {
let model = self
.parent
.call_method(DOM::GetBoxModel {
node_id: None,
backend_node_id: Some(self.backend_node_id),
object_id: None,
})?
.model;
Ok(BoxModel {
content: ElementQuad::from_raw_points(&model.content),
padding: ElementQuad::from_raw_points(&model.padding),
border: ElementQuad::from_raw_points(&model.border),
margin: ElementQuad::from_raw_points(&model.margin),
width: model.width as f64,
height: model.height as f64,
})
}
pub fn get_midpoint(&self) -> Result<Point> {
match self
.parent
.call_method(DOM::GetContentQuads {
node_id: None,
backend_node_id: Some(self.backend_node_id),
object_id: None,
})
.and_then(|quad| {
let raw_quad = quad.quads.first().unwrap();
let input_quad = ElementQuad::from_raw_points(&raw_quad);
Ok((input_quad.bottom_right + input_quad.top_left) / 2.0)
}) {
Ok(e) => return Ok(e),
Err(_) => {
let mut p = Point { x: 0.0, y: 0.0 };
p = util::Wait::with_timeout(Duration::from_secs(20)).until(|| {
let r = self
.call_js_fn(
r#"
function() {
let rect = this.getBoundingClientRect();
if(rect.x != 0) {
this.scrollIntoView();
}
return this.getBoundingClientRect();
}
"#,
vec![],
false,
)
.unwrap();
let res = util::extract_midpoint(r);
match res {
Ok(v) => {
if v.x != 0.0 {
Some(v)
} else {
None
}
}
_ => None,
}
})?;
return Ok(p);
}
}
}
sourcepub fn height(&self) -> f64
pub fn height(&self) -> f64
Examples found in repository?
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
pub fn aspect_ratio(&self) -> f64 {
self.width() / self.height()
}
/// The most left (smallest) x-coordinate
pub fn most_left(&self) -> f64 {
self.top_right
.x
.min(self.top_left.x)
.min(self.bottom_right.x)
.min(self.bottom_left.x)
}
/// The most right (largest) x-coordinate
pub fn most_right(&self) -> f64 {
self.top_right
.x
.max(self.top_left.x)
.max(self.bottom_right.x)
.max(self.bottom_left.x)
}
/// The most top (smallest) y-coordinate
pub fn most_top(&self) -> f64 {
self.top_right
.y
.min(self.top_left.y)
.min(self.bottom_right.y)
.min(self.bottom_left.y)
}
/// The most bottom (largest) y-coordinate
fn most_bottom(&self) -> f64 {
self.top_right
.y
.max(self.top_left.y)
.max(self.bottom_right.y)
.max(self.bottom_left.y)
}
/// If the most bottom point of `self` is above the most top point of `other`
pub fn strictly_above(&self, other: &Self) -> bool {
self.most_bottom() < other.most_top()
}
/// If the most bottom point of `self` is above or on the same line as the
/// most top point of `other`
pub fn above(&self, other: &Self) -> bool {
self.most_bottom() <= other.most_top()
}
/// If the most top point of `self` is below the most bottom point of `other`
pub fn strictly_below(&self, other: &Self) -> bool {
self.most_top() > other.most_bottom()
}
/// If the most top point of `self` is below or on the same line as the
/// most bottom point of `other`
pub fn below(&self, other: &Self) -> bool {
self.most_top() >= other.most_bottom()
}
/// If the most right point of `self` is left of the most left point of `other`
pub fn strictly_left_of(&self, other: &Self) -> bool {
self.most_right() < other.most_left()
}
/// If the most right point of `self` is left or on the same line as the
/// most left point of `other`
pub fn left_of(&self, other: &Self) -> bool {
self.most_right() <= other.most_left()
}
/// If the most left point of `self` is right of the most right point of `other`
pub fn strictly_right_of(&self, other: &Self) -> bool {
self.most_left() > other.most_right()
}
/// If the most left point of `self` is right or on the same line as the
/// most right point of `other`
pub fn right_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_right()
}
/// If `self` is within the left/right boundaries defined by `other`.
pub fn within_horizontal_bounds_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_left() && self.most_right() <= other.most_right()
}
/// If `self` is within the top/bottom boundaries defined by `other`.
pub fn within_vertical_bounds_of(&self, other: &Self) -> bool {
self.most_top() >= other.most_top() && self.most_bottom() <= other.most_bottom()
}
/// If `self` is within the boundaries defined by `other`.
pub fn within_bounds_of(&self, other: &Self) -> bool {
self.within_horizontal_bounds_of(&other) && self.within_vertical_bounds_of(&other)
}
}
#[derive(Debug, Clone)]
pub struct BoxModel {
pub content: ElementQuad,
pub padding: ElementQuad,
pub border: ElementQuad,
pub margin: ElementQuad,
pub width: f64,
pub height: f64,
}
impl BoxModel {
/// Create a `page::Viewport` equal to the content-box, using a scale of 1.0
pub fn content_viewport(&self) -> Page::Viewport {
Page::Viewport {
x: self.content.top_left.x,
y: self.content.top_left.y,
width: self.content.width(),
height: self.content.height(),
scale: 1.0,
}
}
/// Create a `page::Viewport` equal to the padding-box, using a scale of 1.0
pub fn padding_viewport(&self) -> Page::Viewport {
Page::Viewport {
x: self.padding.top_left.x,
y: self.padding.top_left.y,
width: self.padding.width(),
height: self.padding.height(),
scale: 1.0,
}
}
/// Create a `page::Viewport` equal to the border-box, using a scale of 1.0
pub fn border_viewport(&self) -> Page::Viewport {
Page::Viewport {
x: self.border.top_left.x,
y: self.border.top_left.y,
width: self.border.width(),
height: self.border.height(),
scale: 1.0,
}
}
/// Create a `page::Viewport` equal to the margin-box, using a scale of 1.0
pub fn margin_viewport(&self) -> Page::Viewport {
Page::Viewport {
x: self.margin.top_left.x,
y: self.margin.top_left.y,
width: self.margin.width(),
height: self.margin.height(),
scale: 1.0,
}
}
sourcepub fn width(&self) -> f64
pub fn width(&self) -> f64
Examples found in repository?
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
pub fn aspect_ratio(&self) -> f64 {
self.width() / self.height()
}
/// The most left (smallest) x-coordinate
pub fn most_left(&self) -> f64 {
self.top_right
.x
.min(self.top_left.x)
.min(self.bottom_right.x)
.min(self.bottom_left.x)
}
/// The most right (largest) x-coordinate
pub fn most_right(&self) -> f64 {
self.top_right
.x
.max(self.top_left.x)
.max(self.bottom_right.x)
.max(self.bottom_left.x)
}
/// The most top (smallest) y-coordinate
pub fn most_top(&self) -> f64 {
self.top_right
.y
.min(self.top_left.y)
.min(self.bottom_right.y)
.min(self.bottom_left.y)
}
/// The most bottom (largest) y-coordinate
fn most_bottom(&self) -> f64 {
self.top_right
.y
.max(self.top_left.y)
.max(self.bottom_right.y)
.max(self.bottom_left.y)
}
/// If the most bottom point of `self` is above the most top point of `other`
pub fn strictly_above(&self, other: &Self) -> bool {
self.most_bottom() < other.most_top()
}
/// If the most bottom point of `self` is above or on the same line as the
/// most top point of `other`
pub fn above(&self, other: &Self) -> bool {
self.most_bottom() <= other.most_top()
}
/// If the most top point of `self` is below the most bottom point of `other`
pub fn strictly_below(&self, other: &Self) -> bool {
self.most_top() > other.most_bottom()
}
/// If the most top point of `self` is below or on the same line as the
/// most bottom point of `other`
pub fn below(&self, other: &Self) -> bool {
self.most_top() >= other.most_bottom()
}
/// If the most right point of `self` is left of the most left point of `other`
pub fn strictly_left_of(&self, other: &Self) -> bool {
self.most_right() < other.most_left()
}
/// If the most right point of `self` is left or on the same line as the
/// most left point of `other`
pub fn left_of(&self, other: &Self) -> bool {
self.most_right() <= other.most_left()
}
/// If the most left point of `self` is right of the most right point of `other`
pub fn strictly_right_of(&self, other: &Self) -> bool {
self.most_left() > other.most_right()
}
/// If the most left point of `self` is right or on the same line as the
/// most right point of `other`
pub fn right_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_right()
}
/// If `self` is within the left/right boundaries defined by `other`.
pub fn within_horizontal_bounds_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_left() && self.most_right() <= other.most_right()
}
/// If `self` is within the top/bottom boundaries defined by `other`.
pub fn within_vertical_bounds_of(&self, other: &Self) -> bool {
self.most_top() >= other.most_top() && self.most_bottom() <= other.most_bottom()
}
/// If `self` is within the boundaries defined by `other`.
pub fn within_bounds_of(&self, other: &Self) -> bool {
self.within_horizontal_bounds_of(&other) && self.within_vertical_bounds_of(&other)
}
}
#[derive(Debug, Clone)]
pub struct BoxModel {
pub content: ElementQuad,
pub padding: ElementQuad,
pub border: ElementQuad,
pub margin: ElementQuad,
pub width: f64,
pub height: f64,
}
impl BoxModel {
/// Create a `page::Viewport` equal to the content-box, using a scale of 1.0
pub fn content_viewport(&self) -> Page::Viewport {
Page::Viewport {
x: self.content.top_left.x,
y: self.content.top_left.y,
width: self.content.width(),
height: self.content.height(),
scale: 1.0,
}
}
/// Create a `page::Viewport` equal to the padding-box, using a scale of 1.0
pub fn padding_viewport(&self) -> Page::Viewport {
Page::Viewport {
x: self.padding.top_left.x,
y: self.padding.top_left.y,
width: self.padding.width(),
height: self.padding.height(),
scale: 1.0,
}
}
/// Create a `page::Viewport` equal to the border-box, using a scale of 1.0
pub fn border_viewport(&self) -> Page::Viewport {
Page::Viewport {
x: self.border.top_left.x,
y: self.border.top_left.y,
width: self.border.width(),
height: self.border.height(),
scale: 1.0,
}
}
/// Create a `page::Viewport` equal to the margin-box, using a scale of 1.0
pub fn margin_viewport(&self) -> Page::Viewport {
Page::Viewport {
x: self.margin.top_left.x,
y: self.margin.top_left.y,
width: self.margin.width(),
height: self.margin.height(),
scale: 1.0,
}
}
sourcepub fn aspect_ratio(&self) -> f64
pub fn aspect_ratio(&self) -> f64
The width divided by the height
sourcepub fn most_left(&self) -> f64
pub fn most_left(&self) -> f64
The most left (smallest) x-coordinate
Examples found in repository?
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
pub fn strictly_left_of(&self, other: &Self) -> bool {
self.most_right() < other.most_left()
}
/// If the most right point of `self` is left or on the same line as the
/// most left point of `other`
pub fn left_of(&self, other: &Self) -> bool {
self.most_right() <= other.most_left()
}
/// If the most left point of `self` is right of the most right point of `other`
pub fn strictly_right_of(&self, other: &Self) -> bool {
self.most_left() > other.most_right()
}
/// If the most left point of `self` is right or on the same line as the
/// most right point of `other`
pub fn right_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_right()
}
/// If `self` is within the left/right boundaries defined by `other`.
pub fn within_horizontal_bounds_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_left() && self.most_right() <= other.most_right()
}
sourcepub fn most_right(&self) -> f64
pub fn most_right(&self) -> f64
The most right (largest) x-coordinate
Examples found in repository?
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
pub fn strictly_left_of(&self, other: &Self) -> bool {
self.most_right() < other.most_left()
}
/// If the most right point of `self` is left or on the same line as the
/// most left point of `other`
pub fn left_of(&self, other: &Self) -> bool {
self.most_right() <= other.most_left()
}
/// If the most left point of `self` is right of the most right point of `other`
pub fn strictly_right_of(&self, other: &Self) -> bool {
self.most_left() > other.most_right()
}
/// If the most left point of `self` is right or on the same line as the
/// most right point of `other`
pub fn right_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_right()
}
/// If `self` is within the left/right boundaries defined by `other`.
pub fn within_horizontal_bounds_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_left() && self.most_right() <= other.most_right()
}
sourcepub fn most_top(&self) -> f64
pub fn most_top(&self) -> f64
The most top (smallest) y-coordinate
Examples found in repository?
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
pub fn strictly_above(&self, other: &Self) -> bool {
self.most_bottom() < other.most_top()
}
/// If the most bottom point of `self` is above or on the same line as the
/// most top point of `other`
pub fn above(&self, other: &Self) -> bool {
self.most_bottom() <= other.most_top()
}
/// If the most top point of `self` is below the most bottom point of `other`
pub fn strictly_below(&self, other: &Self) -> bool {
self.most_top() > other.most_bottom()
}
/// If the most top point of `self` is below or on the same line as the
/// most bottom point of `other`
pub fn below(&self, other: &Self) -> bool {
self.most_top() >= other.most_bottom()
}
/// If the most right point of `self` is left of the most left point of `other`
pub fn strictly_left_of(&self, other: &Self) -> bool {
self.most_right() < other.most_left()
}
/// If the most right point of `self` is left or on the same line as the
/// most left point of `other`
pub fn left_of(&self, other: &Self) -> bool {
self.most_right() <= other.most_left()
}
/// If the most left point of `self` is right of the most right point of `other`
pub fn strictly_right_of(&self, other: &Self) -> bool {
self.most_left() > other.most_right()
}
/// If the most left point of `self` is right or on the same line as the
/// most right point of `other`
pub fn right_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_right()
}
/// If `self` is within the left/right boundaries defined by `other`.
pub fn within_horizontal_bounds_of(&self, other: &Self) -> bool {
self.most_left() >= other.most_left() && self.most_right() <= other.most_right()
}
/// If `self` is within the top/bottom boundaries defined by `other`.
pub fn within_vertical_bounds_of(&self, other: &Self) -> bool {
self.most_top() >= other.most_top() && self.most_bottom() <= other.most_bottom()
}
sourcepub fn strictly_above(&self, other: &Self) -> bool
pub fn strictly_above(&self, other: &Self) -> bool
If the most bottom point of self
is above the most top point of other
sourcepub fn above(&self, other: &Self) -> bool
pub fn above(&self, other: &Self) -> bool
If the most bottom point of self
is above or on the same line as the
most top point of other
sourcepub fn strictly_below(&self, other: &Self) -> bool
pub fn strictly_below(&self, other: &Self) -> bool
If the most top point of self
is below the most bottom point of other
sourcepub fn below(&self, other: &Self) -> bool
pub fn below(&self, other: &Self) -> bool
If the most top point of self
is below or on the same line as the
most bottom point of other
sourcepub fn strictly_left_of(&self, other: &Self) -> bool
pub fn strictly_left_of(&self, other: &Self) -> bool
If the most right point of self
is left of the most left point of other
sourcepub fn left_of(&self, other: &Self) -> bool
pub fn left_of(&self, other: &Self) -> bool
If the most right point of self
is left or on the same line as the
most left point of other
sourcepub fn strictly_right_of(&self, other: &Self) -> bool
pub fn strictly_right_of(&self, other: &Self) -> bool
If the most left point of self
is right of the most right point of other
sourcepub fn right_of(&self, other: &Self) -> bool
pub fn right_of(&self, other: &Self) -> bool
If the most left point of self
is right or on the same line as the
most right point of other
sourcepub fn within_horizontal_bounds_of(&self, other: &Self) -> bool
pub fn within_horizontal_bounds_of(&self, other: &Self) -> bool
If self
is within the left/right boundaries defined by other
.
sourcepub fn within_vertical_bounds_of(&self, other: &Self) -> bool
pub fn within_vertical_bounds_of(&self, other: &Self) -> bool
If self
is within the top/bottom boundaries defined by other
.
sourcepub fn within_bounds_of(&self, other: &Self) -> bool
pub fn within_bounds_of(&self, other: &Self) -> bool
If self
is within the boundaries defined by other
.
Trait Implementations§
source§impl Clone for ElementQuad
impl Clone for ElementQuad
source§fn clone(&self) -> ElementQuad
fn clone(&self) -> ElementQuad
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more