Преглед на файлове

LibWeb: Define window.outerWidth and window.outerHeight

Timothy Flynn преди 2 години
родител
ревизия
5eeb6bbee3
променени са 2 файла, в които са добавени 39 реда и са изтрити 0 реда
  1. 33 0
      Userland/Libraries/LibWeb/HTML/Window.cpp
  2. 6 0
      Userland/Libraries/LibWeb/HTML/Window.h

+ 33 - 0
Userland/Libraries/LibWeb/HTML/Window.cpp

@@ -524,6 +524,24 @@ int Window::screen_y() const
     return 0;
 }
 
+// https://drafts.csswg.org/cssom-view/#dom-window-outerwidth
+int Window::outer_width() const
+{
+    // The outerWidth attribute must return the width of the client window. If there is no client window this attribute must return zero.
+    if (auto* page = this->page())
+        return page->window_size().width();
+    return 0;
+}
+
+// https://drafts.csswg.org/cssom-view/#dom-window-screeny
+int Window::outer_height() const
+{
+    // The outerHeight attribute must return the height of the client window. If there is no client window this attribute must return zero.
+    if (auto* page = this->page())
+        return page->window_size().height();
+    return 0;
+}
+
 // https://html.spec.whatwg.org/multipage/webstorage.html#dom-localstorage
 JS::NonnullGCPtr<HTML::Storage> Window::local_storage()
 {
@@ -787,6 +805,9 @@ void Window::initialize_web_interfaces(Badge<WindowEnvironmentSettingsObject>)
     define_native_accessor(realm, "screenLeft", screen_left_getter, {}, attr);
     define_native_accessor(realm, "screenTop", screen_top_getter, {}, attr);
 
+    define_native_accessor(realm, "outerWidth", outer_width_getter, {}, attr);
+    define_native_accessor(realm, "outerHeight", outer_height_getter, {}, attr);
+
     define_direct_property("CSS", heap().allocate<Bindings::CSSNamespace>(realm, realm), 0);
 
     define_native_accessor(realm, "localStorage", local_storage_getter, {}, attr);
@@ -1423,6 +1444,18 @@ JS_DEFINE_NATIVE_FUNCTION(Window::screen_y_getter)
     return JS::Value(impl->screen_y());
 }
 
+JS_DEFINE_NATIVE_FUNCTION(Window::outer_width_getter)
+{
+    auto* impl = TRY(impl_from(vm));
+    return JS::Value(impl->outer_width());
+}
+
+JS_DEFINE_NATIVE_FUNCTION(Window::outer_height_getter)
+{
+    auto* impl = TRY(impl_from(vm));
+    return JS::Value(impl->outer_height());
+}
+
 JS_DEFINE_NATIVE_FUNCTION(Window::post_message)
 {
     auto* impl = TRY(impl_from(vm));

+ 6 - 0
Userland/Libraries/LibWeb/HTML/Window.h

@@ -108,6 +108,9 @@ public:
     int screen_x() const;
     int screen_y() const;
 
+    int outer_width() const;
+    int outer_height() const;
+
     JS::NonnullGCPtr<HTML::Storage> local_storage();
     JS::NonnullGCPtr<HTML::Storage> session_storage();
 
@@ -233,6 +236,9 @@ private:
     JS_DECLARE_NATIVE_FUNCTION(screen_left_getter);
     JS_DECLARE_NATIVE_FUNCTION(screen_top_getter);
 
+    JS_DECLARE_NATIVE_FUNCTION(outer_width_getter);
+    JS_DECLARE_NATIVE_FUNCTION(outer_height_getter);
+
     JS_DECLARE_NATIVE_FUNCTION(post_message);
 
     JS_DECLARE_NATIVE_FUNCTION(local_storage_getter);