Serenity Operating System
at master 41 lines 1.3 kB view raw
1/* 2 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <LibGfx/Rect.h> 10#include <LibWeb/Bindings/PlatformObject.h> 11#include <LibWeb/Forward.h> 12 13namespace Web::Geometry { 14 15// https://drafts.fxtf.org/geometry/#domrectreadonly 16class DOMRectReadOnly : public Bindings::PlatformObject { 17 WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject); 18 19public: 20 static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0); 21 22 virtual ~DOMRectReadOnly() override; 23 24 double x() const { return m_rect.x(); } 25 double y() const { return m_rect.y(); } 26 double width() const { return m_rect.width(); } 27 double height() const { return m_rect.height(); } 28 29 double top() const { return min(y(), y() + height()); } 30 double right() const { return max(x(), x() + width()); } 31 double bottom() const { return max(y(), y() + height()); } 32 double left() const { return min(x(), x() + width()); } 33 34protected: 35 DOMRectReadOnly(JS::Realm&, double x, double y, double width, double height); 36 37 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; 38 39 Gfx::FloatRect m_rect; 40}; 41}