Flutter Engine
The Flutter Engine
MouseCursorChannel.java
Go to the documentation of this file.
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
5package io.flutter.embedding.engine.systemchannels;
6
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9import androidx.annotation.VisibleForTesting;
10import io.flutter.Log;
11import io.flutter.embedding.engine.dart.DartExecutor;
12import io.flutter.plugin.common.MethodCall;
13import io.flutter.plugin.common.MethodChannel;
14import io.flutter.plugin.common.StandardMethodCodec;
15import java.util.HashMap;
16
17/** System channel that receives requests for mouse cursor behavior, e.g., set as system cursors. */
18public class MouseCursorChannel {
19 private static final String TAG = "MouseCursorChannel";
20
21 @NonNull public final MethodChannel channel;
22 @Nullable private MouseCursorMethodHandler mouseCursorMethodHandler;
23
24 public MouseCursorChannel(@NonNull DartExecutor dartExecutor) {
25 channel = new MethodChannel(dartExecutor, "flutter/mousecursor", StandardMethodCodec.INSTANCE);
26 channel.setMethodCallHandler(parsingMethodCallHandler);
27 }
28
29 /**
30 * Sets the {@link MouseCursorMethodHandler} which receives all events and requests that are
31 * parsed from the underlying platform channel.
32 */
33 public void setMethodHandler(@Nullable MouseCursorMethodHandler mouseCursorMethodHandler) {
34 this.mouseCursorMethodHandler = mouseCursorMethodHandler;
35 }
36
37 @NonNull
38 private final MethodChannel.MethodCallHandler parsingMethodCallHandler =
40 @Override
41 public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) {
42 if (mouseCursorMethodHandler == null) {
43 // If no explicit mouseCursorMethodHandler has been registered then we don't
44 // need to forward this call to an API. Return.
45 return;
46 }
47
48 final String method = call.method;
49 Log.v(TAG, "Received '" + method + "' message.");
50 try {
51 // More methods are expected to be added here, hence the switch.
52 switch (method) {
53 case "activateSystemCursor":
54 @SuppressWarnings("unchecked")
55 final HashMap<String, Object> data = (HashMap<String, Object>) call.arguments;
56 final String kind = (String) data.get("kind");
57 try {
58 mouseCursorMethodHandler.activateSystemCursor(kind);
59 } catch (Exception e) {
60 result.error("error", "Error when setting cursors: " + e.getMessage(), null);
61 break;
62 }
63 result.success(true);
64 break;
65 default:
66 }
67 } catch (Exception e) {
68 result.error("error", "Unhandled error: " + e.getMessage(), null);
69 }
70 }
71 };
72
73 @VisibleForTesting
75 parsingMethodCallHandler.onMethodCall(call, result);
76 }
77
78 public interface MouseCursorMethodHandler {
79 // Called when the pointer should start displaying a system mouse cursor
80 // specified by {@code shapeCode}.
81 public void activateSystemCursor(@NonNull String kind);
82 }
83}
static void v(@NonNull String tag, @NonNull String message)
Definition: Log.java:40
void setMethodHandler(@Nullable MouseCursorMethodHandler mouseCursorMethodHandler)
void synthesizeMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result)
void setMethodCallHandler(final @Nullable MethodCallHandler handler)
GAsyncResult * result
def call(args)
Definition: dom.py:159
const myers::Point & get(const myers::Segment &)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63