|
| 1 | +// Copyright 2023 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 "mouse_cursor_channel.h" |
| 6 | + |
| 7 | +#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h" |
| 8 | +#include "flutter/shell/platform/tizen/logger.h" |
| 9 | + |
| 10 | +namespace flutter { |
| 11 | + |
| 12 | +namespace { |
| 13 | + |
| 14 | +constexpr char kChannelName[] = "flutter/mousecursor"; |
| 15 | +constexpr char kActivateSystemCursorMethod[] = "activateSystemCursor"; |
| 16 | +constexpr char kKindKey[] = "kind"; |
| 17 | + |
| 18 | +} // namespace |
| 19 | + |
| 20 | +MouseCursorChannel::MouseCursorChannel(BinaryMessenger* messenger, |
| 21 | + TizenViewBase* view) |
| 22 | + : view_(view) { |
| 23 | + channel_ = std::make_unique<MethodChannel<EncodableValue>>( |
| 24 | + messenger, kChannelName, &StandardMethodCodec::GetInstance()); |
| 25 | + channel_->SetMethodCallHandler( |
| 26 | + [this](const MethodCall<EncodableValue>& call, |
| 27 | + std::unique_ptr<MethodResult<EncodableValue>> result) { |
| 28 | + HandleMethodCall(call, std::move(result)); |
| 29 | + }); |
| 30 | +} |
| 31 | + |
| 32 | +MouseCursorChannel::~MouseCursorChannel() {} |
| 33 | + |
| 34 | +void MouseCursorChannel::HandleMethodCall( |
| 35 | + const MethodCall<EncodableValue>& method_call, |
| 36 | + std::unique_ptr<MethodResult<EncodableValue>> result) { |
| 37 | + const std::string& method_name = method_call.method_name(); |
| 38 | + if (method_name == kActivateSystemCursorMethod) { |
| 39 | + const auto& arguments = std::get<EncodableMap>(*method_call.arguments()); |
| 40 | + auto kind_iter = arguments.find(EncodableValue(std::string(kKindKey))); |
| 41 | + if (kind_iter == arguments.end()) { |
| 42 | + result->Error("Argument error", |
| 43 | + "Missing argument while trying to activate system cursor"); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + const auto& kind = std::get<std::string>(kind_iter->second); |
| 48 | + view_->UpdateFlutterCursor(kind); |
| 49 | + result->Success(); |
| 50 | + } else { |
| 51 | + result->NotImplemented(); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +} // namespace flutter |
0 commit comments