@@ -17,11 +17,13 @@ constexpr char kChannelName[] = "flutter/platform_views";
1717
1818} // namespace
1919
20- PlatformViewChannel::PlatformViewChannel (BinaryMessenger* messenger)
20+ PlatformViewChannel::PlatformViewChannel (BinaryMessenger* messenger,
21+ double pixel_ratio)
2122 : channel_(std::make_unique<MethodChannel<EncodableValue>>(
2223 messenger,
2324 kChannelName ,
24- &StandardMethodCodec::GetInstance ())) {
25+ &StandardMethodCodec::GetInstance ())),
26+ pixel_ratio_(pixel_ratio) {
2527 channel_->SetMethodCallHandler (
2628 [this ](const MethodCall<EncodableValue>& call,
2729 std::unique_ptr<MethodResult<EncodableValue>> result) {
@@ -104,6 +106,8 @@ void PlatformViewChannel::HandleMethodCall(
104106 OnClearFocus (arguments, std::move (result));
105107 } else if (method == " dispose" ) {
106108 OnDispose (arguments, std::move (result));
109+ } else if (method == " offset" ) {
110+ OnOffset (arguments, std::move (result));
107111 } else if (method == " resize" ) {
108112 OnResize (arguments, std::move (result));
109113 } else if (method == " touch" ) {
@@ -147,8 +151,8 @@ void PlatformViewChannel::OnCreate(
147151 if (focused_view) {
148152 focused_view->SetFocus (false );
149153 }
150- PlatformView* view =
151- iter-> second -> Create ( *view_id, *width, *height, byte_message);
154+ PlatformView* view = iter-> second -> Create (
155+ *view_id, *width * pixel_ratio_ , *height * pixel_ratio_ , byte_message);
152156 if (view) {
153157 views_[*view_id] = view;
154158 result->Success (EncodableValue (view->GetTextureId ()));
@@ -206,6 +210,33 @@ void PlatformViewChannel::OnDispose(
206210 result->Success ();
207211}
208212
213+ void PlatformViewChannel::OnOffset (
214+ const EncodableValue* arguments,
215+ std::unique_ptr<MethodResult<EncodableValue>>&& result) {
216+ auto * map = std::get_if<EncodableMap>(arguments);
217+ if (!map) {
218+ result->Error (" Invalid arguments" );
219+ return ;
220+ }
221+
222+ EncodableValueHolder<int > view_id (map, " id" );
223+ EncodableValueHolder<double > left (map, " left" );
224+ EncodableValueHolder<double > top (map, " top" );
225+
226+ if (!view_id || !left || !top) {
227+ result->Error (" Invalid arguments" );
228+ return ;
229+ }
230+ PlatformView* view = FindViewById (*view_id);
231+ if (!view) {
232+ result->Error (" Can't find view id" );
233+ return ;
234+ }
235+ view->Offset (*left * pixel_ratio_, *top * pixel_ratio_);
236+
237+ result->Success ();
238+ }
239+
209240void PlatformViewChannel::OnResize (
210241 const EncodableValue* arguments,
211242 std::unique_ptr<MethodResult<EncodableValue>>&& result) {
@@ -229,7 +260,7 @@ void PlatformViewChannel::OnResize(
229260 result->Error (" Can't find view id" );
230261 return ;
231262 }
232- view->Resize (*width, *height);
263+ view->Resize (*width * pixel_ratio_ , *height * pixel_ratio_ );
233264
234265 result->Success (*arguments);
235266}
@@ -256,10 +287,10 @@ void PlatformViewChannel::OnTouch(
256287
257288 type = std::get<int >(event->at (0 ));
258289 button = std::get<int >(event->at (1 ));
259- x = std::get<double >(event->at (2 ));
260- y = std::get<double >(event->at (3 ));
261- dx = std::get<double >(event->at (4 ));
262- dy = std::get<double >(event->at (5 ));
290+ x = std::get<double >(event->at (2 )) * pixel_ratio_ ;
291+ y = std::get<double >(event->at (3 )) * pixel_ratio_ ;
292+ dx = std::get<double >(event->at (4 )) * pixel_ratio_ ;
293+ dy = std::get<double >(event->at (5 )) * pixel_ratio_ ;
263294
264295 PlatformView* view = FindViewById (*view_id);
265296 if (!view) {
0 commit comments