mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Instead of a hand-rolled discriminated union (originally used to avoid a C++17 dependency, which is no longer an issue), implement EncodableValue as a std::variant. Rather than simply changing the internals, this makes EncodableValue a minimal std::variant subclass with only a handful of added methodS, replacing the old IsFoo/FooValue APIs with the standard std::holds_alternative/std::get, so that plugin code will use a standard-based API rather than a Flutter-specific API for wrapped values. This is a breaking change for Windows and GLFW plugins. In the short term USE_LEGACY_ENCODABLE_VALUE can be set in builds to use the old version, to separate rolling from updating. Fixes https://github.com/flutter/flutter/issues/61970
53 lines
1.8 KiB
C++
53 lines
1.8 KiB
C++
// Copyright 2013 The Flutter 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 "flutter/shell/platform/windows/cursor_handler.h"
|
|
|
|
#include <windows.h>
|
|
|
|
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_method_codec.h"
|
|
|
|
static constexpr char kChannelName[] = "flutter/mousecursor";
|
|
|
|
static constexpr char kActivateSystemCursorMethod[] = "activateSystemCursor";
|
|
|
|
static constexpr char kKindKey[] = "kind";
|
|
|
|
namespace flutter {
|
|
|
|
CursorHandler::CursorHandler(BinaryMessenger* messenger,
|
|
WindowBindingHandler* delegate)
|
|
: channel_(std::make_unique<MethodChannel<EncodableValue>>(
|
|
messenger,
|
|
kChannelName,
|
|
&StandardMethodCodec::GetInstance())),
|
|
delegate_(delegate) {
|
|
channel_->SetMethodCallHandler(
|
|
[this](const MethodCall<EncodableValue>& call,
|
|
std::unique_ptr<MethodResult<EncodableValue>> result) {
|
|
HandleMethodCall(call, std::move(result));
|
|
});
|
|
}
|
|
|
|
void CursorHandler::HandleMethodCall(
|
|
const MethodCall<EncodableValue>& method_call,
|
|
std::unique_ptr<MethodResult<EncodableValue>> result) {
|
|
const std::string& method = method_call.method_name();
|
|
if (method.compare(kActivateSystemCursorMethod) == 0) {
|
|
const auto& arguments = std::get<EncodableMap>(*method_call.arguments());
|
|
auto kind_iter = arguments.find(EncodableValue(std::string(kKindKey)));
|
|
if (kind_iter == arguments.end()) {
|
|
result->Error("Argument error",
|
|
"Missing argument while trying to activate system cursor");
|
|
}
|
|
const auto& kind = std::get<std::string>(kind_iter->second);
|
|
delegate_->UpdateFlutterCursor(kind);
|
|
result->Success();
|
|
} else {
|
|
result->NotImplemented();
|
|
}
|
|
}
|
|
|
|
} // namespace flutter
|