mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
We now respect the "route" field in Intents to load a route other than '/'. Also, use popRoute rather than events to indicate that the framework has asked us to go back.
134 lines
3.5 KiB
C++
134 lines
3.5 KiB
C++
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "sky/engine/core/window/window.h"
|
|
|
|
#include "sky/engine/core/compositing/Scene.h"
|
|
#include "sky/engine/core/script/dom_dart_state.h"
|
|
#include "sky/engine/public/platform/sky_display_metrics.h"
|
|
#include "sky/engine/tonic/dart_converter.h"
|
|
#include "sky/engine/tonic/dart_invoke.h"
|
|
#include "sky/engine/tonic/dart_library_natives.h"
|
|
|
|
namespace blink {
|
|
namespace {
|
|
|
|
void ScheduleFrame(Dart_NativeArguments args) {
|
|
DOMDartState::Current()->window()->client()->ScheduleFrame();
|
|
}
|
|
|
|
void Render(Dart_NativeArguments args) {
|
|
Dart_Handle exception = nullptr;
|
|
Scene* scene = DartConverter<Scene*>::FromArgumentsWithNullCheck(
|
|
args, 1, exception);
|
|
if (exception) {
|
|
Dart_ThrowException(exception);
|
|
return;
|
|
}
|
|
DOMDartState::Current()->window()->client()->Render(scene);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
WindowClient::~WindowClient() {
|
|
}
|
|
|
|
Window::Window(WindowClient* client)
|
|
: client_(client) {
|
|
}
|
|
|
|
Window::~Window() {
|
|
}
|
|
|
|
void Window::DidCreateIsolate() {
|
|
library_.Set(DartState::Current(), Dart_LookupLibrary(ToDart("dart:ui")));
|
|
}
|
|
|
|
void Window::UpdateWindowMetrics(const SkyDisplayMetrics& metrics) {
|
|
DartState* dart_state = library_.dart_state().get();
|
|
if (!dart_state)
|
|
return;
|
|
DartState::Scope scope(dart_state);
|
|
|
|
double device_pixel_ratio = metrics.device_pixel_ratio;
|
|
double width = metrics.physical_size.width / device_pixel_ratio;
|
|
double height = metrics.physical_size.height / device_pixel_ratio;
|
|
|
|
DartInvokeField(library_.value(), "_updateWindowMetrics", {
|
|
ToDart(device_pixel_ratio),
|
|
ToDart(width),
|
|
ToDart(height),
|
|
ToDart(metrics.padding_top),
|
|
ToDart(metrics.padding_right),
|
|
ToDart(metrics.padding_bottom),
|
|
ToDart(metrics.padding_left),
|
|
});
|
|
}
|
|
|
|
void Window::PushRoute(const std::string& route) {
|
|
DartState* dart_state = library_.dart_state().get();
|
|
if (!dart_state)
|
|
return;
|
|
DartState::Scope scope(dart_state);
|
|
|
|
DartInvokeField(library_.value(), "_pushRoute", {
|
|
StdStringToDart(route),
|
|
});
|
|
}
|
|
|
|
void Window::PopRoute() {
|
|
DartState* dart_state = library_.dart_state().get();
|
|
if (!dart_state)
|
|
return;
|
|
DartState::Scope scope(dart_state);
|
|
|
|
DartInvokeField(library_.value(), "_popRoute", {});
|
|
}
|
|
|
|
void Window::DispatchPointerPacket(const pointer::PointerPacketPtr& packet) {
|
|
DartState* dart_state = library_.dart_state().get();
|
|
if (!dart_state)
|
|
return;
|
|
DartState::Scope scope(dart_state);
|
|
|
|
Dart_Handle data_handle = Dart_NewTypedData(Dart_TypedData_kByteData,
|
|
packet->GetSerializedSize());
|
|
if (Dart_IsError(data_handle))
|
|
return;
|
|
|
|
Dart_TypedData_Type type;
|
|
void* data;
|
|
intptr_t len;
|
|
if (Dart_IsError(Dart_TypedDataAcquireData(data_handle, &type, &data, &len)))
|
|
return;
|
|
|
|
packet->Serialize(data, len);
|
|
|
|
Dart_TypedDataReleaseData(data_handle);
|
|
|
|
DartInvokeField(library_.value(), "_dispatchPointerPacket", {data_handle});
|
|
}
|
|
|
|
void Window::BeginFrame(base::TimeTicks frameTime) {
|
|
DartState* dart_state = library_.dart_state().get();
|
|
if (!dart_state)
|
|
return;
|
|
DartState::Scope scope(dart_state);
|
|
|
|
int64_t microseconds = (frameTime - base::TimeTicks()).InMicroseconds();
|
|
|
|
DartInvokeField(library_.value(), "_beginFrame", {
|
|
Dart_NewInteger(microseconds),
|
|
});
|
|
}
|
|
|
|
void Window::RegisterNatives(DartLibraryNatives* natives) {
|
|
natives->Register({
|
|
{ "Window_scheduleFrame", ScheduleFrame, 1, true },
|
|
{ "Window_render", Render, 2, true },
|
|
});
|
|
}
|
|
|
|
} // namespace blink
|