Skip to content

Commit 6189f24

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/js_debugger_support
2 parents a12bae4 + 557e5f7 commit 6189f24

File tree

101 files changed

+2134
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2134
-468
lines changed

.github/workflows/integration_test_flutter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ jobs:
111111
path: bridge/build/macos/
112112
- run: cd integration_tests && npm i
113113
- name: Run Test
114-
run: cd integration_tests && SPEC_SCOPE="${{ matrix.value }}" npm run integration
114+
run: cd integration_tests && CI=true SPEC_SCOPE="${{ matrix.value }}" npm run integration
115115
id: test
116116
continue-on-error: true
117117
- uses: actions/upload-artifact@v2
@@ -149,7 +149,7 @@ jobs:
149149
path: bridge/build/macos/
150150
- run: cd integration_tests && npm i
151151
- name: Run Test
152-
run: cd integration_tests && SPEC_SCOPE="${{ matrix.value }}" npm run integration
152+
run: cd integration_tests && CI=true SPEC_SCOPE="${{ matrix.value }}" npm run integration
153153
id: test
154154
continue-on-error: true
155155
- uses: actions/upload-artifact@v2

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# [WebF](https://openwebf.com/) [![pub package](https://img.shields.io/pub/v/webf.svg)](https://pub.dev/packages/webf)
22

3-
WebF (Web on Flutter) is a W3C standards compliant Web rendering engine based on Flutter, it can run web applications on Flutter natively.
3+
WebF (Web on Flutter) is a W3C standards-compliant web rendering engine based on Flutter, allowing web applications to run natively on Flutter.
44

5-
- **W3C Standards Compliant:** WebF use HTML/CSS and JavaScript to render contents on flutter. It can achieve 100% consistency with browser rendering.
6-
- **Front-End Framework Supports:** WebF is W3C standards compliant, so it can be used by many Front-End frameworks, such as [React](https://reactjs.org/), [Vue](https://vuejs.org/).
7-
- **Expand your Web app with Flutter:** WebF is fully customizable. You can define a customized HTML element with Flutter Widget and use it in your application. Or add a JavaScript API for any Dart library from <pub.dev> registry.
8-
- **Web Development Experience:** WebF supports inspecting DOM structure, CSS styles and debugging JavaScript with Chrome DevTools, just like the web development experience of your browser.
9-
- **Write Once, Run Anywhere:** With the power of WebF, You can write your web application and run it on any device flutter supports, and you can still run your apps in Node.js and Web browsers with the same codebase.
5+
- **W3C Standards Compliant:** WebF uses HTML/CSS and JavaScript to render content on Flutter, achieving 100% consistency with browser rendering.
6+
- **Front-End Framework Supports:** As WebF is W3C standards compliant, it can be used with many front-end frameworks, such as [React](https://reactjs.org/), [Vue](https://vuejs.org/).
7+
- **Expand your Web App with Flutter:** WebF is fully customizable. You can define a customized HTML element with Flutter Widgets and use it in your application or add a JavaScript API for any Dart library from <pub.dev> registry.
8+
- **Web Development Experience:** WebF supports inspecting DOM structure, CSS styles and debugging JavaScript with Chrome DevTools, providing a browser-like web development experience.
9+
- **Write Once, Run Anywhere:** With the power of WebF, You can write your web application and run it on any device that Flutter supports. Additionally, you can still run your apps in Node.js and web browsers with the same codebase.
1010

1111
## Check if a Web API or CSS is available in WebF
1212

bridge/bindings/qjs/atomic_string.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ inline AtomicString RemoveCharactersInternal(JSContext* ctx,
295295
}
296296

297297
AtomicString str;
298+
299+
if (outc == 0) {
300+
return AtomicString::Empty();
301+
}
302+
298303
auto data = (CharType*)js_malloc(ctx, outc);
299304
memcpy(data, to, outc);
300305
js_free(ctx, to);

bridge/core/binding_object.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ NativeValue BindingObject::GetBindingProperty(const AtomicString& prop, Exceptio
9696
if (UNLIKELY(binding_object_->disposed_)) {
9797
exception_state.ThrowException(
9898
ctx(), ErrorType::InternalError,
99-
"Can not get binding property on BindingObject , dart binding object had been disposed");
99+
"Can not get binding property on BindingObject, dart binding object had been disposed");
100100
return Native_NewNull();
101101
}
102102
GetExecutingContext()->FlushUICommand();

bridge/core/dom/document.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class Document : public ContainerNode, public TreeScope {
9595

9696
uint32_t RequestAnimationFrame(const std::shared_ptr<FrameCallback>& callback, ExceptionState& exception_state);
9797
void CancelAnimationFrame(uint32_t request_id, ExceptionState& exception_state);
98+
ScriptAnimationController* script_animations() { return &script_animation_controller_; };
9899

99100
// Helper functions for forwarding LocalDOMWindow event related tasks to the
100101
// LocalDOMWindow if it exists.

bridge/core/dom/element.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ void ElementSnapshotReader::HandleFailed(const char* error) {
364364
}
365365

366366
ScriptPromise Element::toBlob(ExceptionState& exception_state) {
367-
return toBlob(1.0, exception_state);
367+
Window* window = GetExecutingContext()->window();
368+
double device_pixel_ratio = NativeValueConverter<NativeTypeDouble>::FromNativeValue(
369+
window->GetBindingProperty(binding_call_methods::kdevicePixelRatio, exception_state));
370+
return toBlob(device_pixel_ratio, exception_state);
368371
}
369372

370373
ScriptPromise Element::toBlob(double device_pixel_ratio, ExceptionState& exception_state) {

bridge/core/dom/frame_request_callback_collection.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,24 @@ void FrameCallback::Trace(GCVisitor* visitor) const {
3939

4040
void FrameRequestCallbackCollection::RegisterFrameCallback(uint32_t callback_id,
4141
const std::shared_ptr<FrameCallback>& frame_callback) {
42-
frameCallbacks_[callback_id] = frame_callback;
42+
assert(frame_callbacks_.count(callback_id) == 0);
43+
frame_callbacks_[callback_id] = frame_callback;
4344
}
4445

45-
void FrameRequestCallbackCollection::CancelFrameCallback(uint32_t callbackId) {
46-
if (frameCallbacks_.count(callbackId) == 0)
46+
void FrameRequestCallbackCollection::RemoveFrameCallback(uint32_t callback_id) {
47+
if (frame_callbacks_.count(callback_id) == 0)
4748
return;
48-
frameCallbacks_.erase(callbackId);
49+
frame_callbacks_.erase(callback_id);
50+
}
51+
52+
std::shared_ptr<FrameCallback> FrameRequestCallbackCollection::GetFrameCallback(uint32_t callback_id) {
53+
if (frame_callbacks_.count(callback_id) == 0)
54+
return nullptr;
55+
return frame_callbacks_[callback_id];
4956
}
5057

5158
void FrameRequestCallbackCollection::Trace(GCVisitor* visitor) const {
52-
for (auto& entry : frameCallbacks_) {
59+
for (auto& entry : frame_callbacks_) {
5360
entry.second->Trace(visitor);
5461
}
5562
}

bridge/core/dom/frame_request_callback_collection.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
namespace webf {
1111

12+
class FrameRequestCallbackCollection;
13+
1214
// |FrameCallback| is an interface type which generalizes callbacks which are
1315
// invoked when a script-based animation needs to be resampled.
1416
class FrameCallback {
1517
public:
18+
enum FrameStatus { kPending, kExecuting, kFinished, kCanceled };
1619
static std::shared_ptr<FrameCallback> Create(ExecutingContext* context, const std::shared_ptr<QJSFunction>& callback);
1720

1821
FrameCallback(ExecutingContext* context, std::shared_ptr<QJSFunction> callback);
@@ -21,22 +24,31 @@ class FrameCallback {
2124

2225
ExecutingContext* context() { return context_; };
2326

27+
FrameStatus status() { return status_; }
28+
void SetStatus(FrameStatus status) { status_ = status; }
29+
30+
uint32_t frameId() { return frame_id_; }
31+
void SetFrameId(uint32_t id) { frame_id_ = id; }
32+
2433
void Trace(GCVisitor* visitor) const;
2534

2635
private:
2736
std::shared_ptr<QJSFunction> callback_;
37+
FrameStatus status_;
38+
uint32_t frame_id_;
2839
ExecutingContext* context_{nullptr};
2940
};
3041

3142
class FrameRequestCallbackCollection final {
3243
public:
3344
void RegisterFrameCallback(uint32_t callback_id, const std::shared_ptr<FrameCallback>& frame_callback);
34-
void CancelFrameCallback(uint32_t callback_id);
45+
void RemoveFrameCallback(uint32_t callback_id);
46+
std::shared_ptr<FrameCallback> GetFrameCallback(uint32_t callback_id);
3547

3648
void Trace(GCVisitor* visitor) const;
3749

3850
private:
39-
std::unordered_map<uint32_t, std::shared_ptr<FrameCallback>> frameCallbacks_;
51+
std::unordered_map<uint32_t, std::shared_ptr<FrameCallback>> frame_callbacks_;
4052
};
4153

4254
} // namespace webf

bridge/core/dom/scripted_animation_controller.cc

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "scripted_animation_controller.h"
7+
#include "document.h"
78
#include "frame_request_callback_collection.h"
89

910
namespace webf {
@@ -21,8 +22,16 @@ static void handleRAFTransientCallback(void* ptr, int32_t contextId, double high
2122
return;
2223
}
2324

25+
assert(frame_callback->status() == FrameCallback::FrameStatus::kPending);
26+
27+
frame_callback->SetStatus(FrameCallback::FrameStatus::kExecuting);
28+
2429
// Trigger callbacks.
2530
frame_callback->Fire(highResTimeStamp);
31+
32+
frame_callback->SetStatus(FrameCallback::FrameStatus::kFinished);
33+
34+
context->document()->script_animations()->callbackCollection()->RemoveFrameCallback(frame_callback->frameId());
2635
}
2736

2837
uint32_t ScriptAnimationController::RegisterFrameCallback(const std::shared_ptr<FrameCallback>& frame_callback,
@@ -36,17 +45,19 @@ uint32_t ScriptAnimationController::RegisterFrameCallback(const std::shared_ptr<
3645
return -1;
3746
}
3847

48+
frame_callback->SetStatus(FrameCallback::FrameStatus::kPending);
49+
3950
uint32_t requestId = context->dartMethodPtr()->requestAnimationFrame(frame_callback.get(), context->contextId(),
4051
handleRAFTransientCallback);
41-
52+
frame_callback->SetFrameId(requestId);
4253
// Register frame callback to collection.
4354
frame_request_callback_collection_.RegisterFrameCallback(requestId, frame_callback);
4455

4556
return requestId;
4657
}
4758

4859
void ScriptAnimationController::CancelFrameCallback(ExecutingContext* context,
49-
uint32_t callbackId,
60+
uint32_t callback_id,
5061
ExceptionState& exception_state) {
5162
if (context->dartMethodPtr()->cancelAnimationFrame == nullptr) {
5263
exception_state.ThrowException(
@@ -55,8 +66,15 @@ void ScriptAnimationController::CancelFrameCallback(ExecutingContext* context,
5566
return;
5667
}
5768

58-
context->dartMethodPtr()->cancelAnimationFrame(context->contextId(), callbackId);
59-
frame_request_callback_collection_.CancelFrameCallback(callbackId);
69+
context->dartMethodPtr()->cancelAnimationFrame(context->contextId(), callback_id);
70+
71+
auto frame_callback = frame_request_callback_collection_.GetFrameCallback(callback_id);
72+
if (frame_callback != nullptr) {
73+
if (frame_callback->status() != FrameCallback::FrameStatus::kExecuting) {
74+
frame_request_callback_collection_.RemoveFrameCallback(callback_id);
75+
}
76+
frame_callback->SetStatus(FrameCallback::kCanceled);
77+
}
6078
}
6179

6280
void ScriptAnimationController::Trace(GCVisitor* visitor) const {

bridge/core/dom/scripted_animation_controller.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class ScriptAnimationController {
1515
public:
1616
// Animation frame callbacks are used for requestAnimationFrame().
1717
uint32_t RegisterFrameCallback(const std::shared_ptr<FrameCallback>& callback, ExceptionState& exception_state);
18-
void CancelFrameCallback(ExecutingContext* context, uint32_t callbackId, ExceptionState& exception_state);
18+
void CancelFrameCallback(ExecutingContext* context, uint32_t callback_id, ExceptionState& exception_state);
19+
20+
FrameRequestCallbackCollection* callbackCollection() { return &frame_request_callback_collection_; };
1921

2022
void Trace(GCVisitor* visitor) const;
2123

0 commit comments

Comments
 (0)