Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bridge/bindings/qjs/qjs_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>
#include "core/binding_object.h"
#include "core/dom/events/event_target.h"
#include "core/executing_context.h"
#include "cppgc/gc_visitor.h"

namespace webf {
Expand Down Expand Up @@ -82,6 +83,7 @@ ScriptValue QJSFunction::Invoke(JSContext* ctx, const ScriptValue& this_val, int
}

ExecutingContext* context = ExecutingContext::From(ctx);
context->SetIsIdle(false);

JSValue returnValue = JS_Call(ctx, function_, JS_IsNull(this_val_) ? this_val.QJSValue() : this_val_, argc, argv);

Expand Down
1 change: 1 addition & 0 deletions bridge/bindings/qjs/script_promise_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ScriptPromise ScriptPromiseResolver::Promise() {
void ScriptPromiseResolver::ResolveOrRejectImmediately(JSValue value) {
if (context_ == nullptr)
return;
context_->SetIsIdle(true);
{
if (state_ == kResolving) {
JSValue arguments[] = {value};
Expand Down
35 changes: 35 additions & 0 deletions bridge/core/binding_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "bindings/qjs/exception_state.h"
#include "bindings/qjs/script_promise_resolver.h"
#include "core/dom/container_node.h"
#include "core/dom/document.h"
#include "core/dom/events/event_target.h"
#include "core/dom/mutation_observer_interest_group.h"
#include "core/executing_context.h"
Expand All @@ -22,6 +23,29 @@

namespace webf {

static bool ShouldUpdateStyleForThisDocumentForDOMGeometry(const AtomicString& prop) {
return prop == binding_call_methods::koffsetLeft || prop == binding_call_methods::koffsetTop ||
prop == binding_call_methods::koffsetWidth || prop == binding_call_methods::koffsetHeight ||
prop == binding_call_methods::kclientLeft || prop == binding_call_methods::kclientTop ||
prop == binding_call_methods::kclientWidth || prop == binding_call_methods::kclientHeight;
}

static bool ShouldUpdateStyleForThisDocumentForDOMGeometryMethod(const AtomicString& method) {
return method == binding_call_methods::kgetBoundingClientRect || method == binding_call_methods::kgetClientRects;
}

static void UpdateStyleForThisDocumentIfBlinkEnabled(ExecutingContext* context) {
if (!context || !context->isBlinkEnabled()) {
return;
}
Document* doc = context->document();
if (!doc) {
return;
}
MemberMutationScope mutation_scope{context};
doc->UpdateStyleForThisDocument();
}

static void ReturnEventResultToDart(Dart_Handle persistent_handle,
NativeValue* result,
DartInvokeResultCallback result_callback) {
Expand Down Expand Up @@ -179,6 +203,9 @@ ScriptPromise BindingObject::InvokeBindingMethodAsync(const webf::AtomicString&
int32_t argc,
const webf::NativeValue* args,
webf::ExceptionState& exception_state) const {
if (ShouldUpdateStyleForThisDocumentForDOMGeometryMethod(method)) {
UpdateStyleForThisDocumentIfBlinkEnabled(GetExecutingContext());
}
NativeValue method_on_stack = NativeValueConverter<NativeTypeString>::ToNativeValue(ctx(), method);
return InvokeBindingMethodAsyncInternal(method_on_stack, argc, args, exception_state);
}
Expand Down Expand Up @@ -260,6 +287,10 @@ ScriptPromise BindingObject::GetBindingPropertyAsync(const webf::AtomicString& p
return ScriptPromise(ctx(), JS_NULL);
}

if (ShouldUpdateStyleForThisDocumentForDOMGeometry(prop)) {
UpdateStyleForThisDocumentIfBlinkEnabled(GetExecutingContext());
}

const NativeValue argv[] = {Native_NewString(prop.ToNativeString().release())};
return InvokeBindingMethodAsync(BindingMethodCallOperations::kGetProperty, 1, argv, exception_state);
}
Expand Down Expand Up @@ -343,6 +374,10 @@ NativeValue BindingObject::GetBindingProperty(const AtomicString& prop,
return Native_NewNull();
}

if (ShouldUpdateStyleForThisDocumentForDOMGeometry(prop)) {
UpdateStyleForThisDocumentIfBlinkEnabled(GetExecutingContext());
}

const NativeValue argv[] = {Native_NewString(prop.ToNativeString().release())};
NativeValue result = InvokeBindingMethod(BindingMethodCallOperations::kGetProperty, 1, argv, reason, exception_state);

Expand Down
Loading
Loading