| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "flutter/lib/ui/window/window.h" |
| 6 | |
| 7 | #include <utility> |
| 8 | |
| 9 | #include "third_party/tonic/converter/dart_converter.h" |
| 10 | #include "third_party/tonic/dart_args.h" |
| 11 | #include "third_party/tonic/logging/dart_invoke.h" |
| 12 | #include "third_party/tonic/typed_data/dart_byte_data.h" |
| 13 | |
| 14 | namespace flutter { |
| 15 | |
| 16 | Window::Window(int64_t window_id, ViewportMetrics metrics) |
| 17 | : window_id_(window_id), viewport_metrics_(std::move(metrics)) { |
| 18 | library_.Set(dart_state: tonic::DartState::Current(), |
| 19 | value: Dart_LookupLibrary(url: tonic::ToDart(val: "dart:ui" ))); |
| 20 | } |
| 21 | |
| 22 | Window::~Window() {} |
| 23 | |
| 24 | void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) { |
| 25 | viewport_metrics_ = metrics; |
| 26 | |
| 27 | std::shared_ptr<tonic::DartState> dart_state = library_.dart_state().lock(); |
| 28 | if (!dart_state) { |
| 29 | return; |
| 30 | } |
| 31 | tonic::DartState::Scope scope(dart_state); |
| 32 | tonic::CheckAndHandleError(handle: tonic::DartInvokeField( |
| 33 | target: library_.value(), name: "_updateWindowMetrics" , |
| 34 | args: { |
| 35 | tonic::ToDart(object: window_id_), |
| 36 | tonic::ToDart(object: metrics.device_pixel_ratio), |
| 37 | tonic::ToDart(object: metrics.physical_width), |
| 38 | tonic::ToDart(object: metrics.physical_height), |
| 39 | tonic::ToDart(object: metrics.physical_padding_top), |
| 40 | tonic::ToDart(object: metrics.physical_padding_right), |
| 41 | tonic::ToDart(object: metrics.physical_padding_bottom), |
| 42 | tonic::ToDart(object: metrics.physical_padding_left), |
| 43 | tonic::ToDart(object: metrics.physical_view_inset_top), |
| 44 | tonic::ToDart(object: metrics.physical_view_inset_right), |
| 45 | tonic::ToDart(object: metrics.physical_view_inset_bottom), |
| 46 | tonic::ToDart(object: metrics.physical_view_inset_left), |
| 47 | tonic::ToDart(object: metrics.physical_system_gesture_inset_top), |
| 48 | tonic::ToDart(object: metrics.physical_system_gesture_inset_right), |
| 49 | tonic::ToDart(object: metrics.physical_system_gesture_inset_bottom), |
| 50 | tonic::ToDart(object: metrics.physical_system_gesture_inset_left), |
| 51 | tonic::ToDart(object: metrics.physical_touch_slop), |
| 52 | tonic::ToDart(object: metrics.physical_display_features_bounds), |
| 53 | tonic::ToDart(object: metrics.physical_display_features_type), |
| 54 | tonic::ToDart(object: metrics.physical_display_features_state), |
| 55 | tonic::ToDart(object: metrics.display_id), |
| 56 | })); |
| 57 | } |
| 58 | |
| 59 | } // namespace flutter |
| 60 | |