docs
Loading...
Searching...
No Matches
DOMRect.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5#pragma once
6
7namespace ultralight {
8namespace dom {
9
10///
11/// A rectangle in CSS pixels, relative to the viewport (DOMRect).
12///
13/// The coordinates are in the same space as event client positions and
14/// Document::elementFromPoint().
15///
16/// \parblock
17/// @note For an element in a subframe, the viewport is that frame's own viewport.
18/// \endparblock
19///
20/// \parblock
21/// @note CSS pixels are device pixels divided by the View's device scale.
22/// \endparblock
23///
24/// @see Element::getBoundingClientRect(), Range::getBoundingClientRect()
25///
26struct DOMRect {
27 double x = 0; ///< The horizontal position.
28 double y = 0; ///< The vertical position.
29 double width = 0; ///< The width (can be negative).
30 double height = 0; ///< The height (can be negative).
31
32 ///
33 /// Get the left edge (left). This is `x` unless the width is negative.
34 ///
35 double left() const { return width >= 0 ? x : x + width; }
36
37 ///
38 /// Get the top edge (top). This is `y` unless the height is negative.
39 ///
40 double top() const { return height >= 0 ? y : y + height; }
41
42 ///
43 /// Get the right edge (right).
44 ///
45 double right() const { return width >= 0 ? x + width : x; }
46
47 ///
48 /// Get the bottom edge (bottom).
49 ///
50 double bottom() const { return height >= 0 ? y + height : y; }
51};
52
53} // namespace dom
54} // namespace ultralight
Direct C++ access to modify page elements and handle events.
Root namespace for every public Ultralight type, function, and enumeration.
A rectangle in CSS pixels, relative to the viewport (DOMRect).
Definition DOMRect.h:26
double top() const
Get the top edge (top).
Definition DOMRect.h:40
double left() const
Get the left edge (left).
Definition DOMRect.h:35
double bottom() const
Get the bottom edge (bottom).
Definition DOMRect.h:50
double height
The height (can be negative).
Definition DOMRect.h:30
double width
The width (can be negative).
Definition DOMRect.h:29
double right() const
Get the right edge (right).
Definition DOMRect.h:45
double y
The vertical position.
Definition DOMRect.h:28
double x
The horizontal position.
Definition DOMRect.h:27