Skip to content

Commit 4b14600

Browse files
authored
Implement the mouse cursor channel (#32)
1 parent 4f461b2 commit 4b14600

15 files changed

+186
-1
lines changed

flutter/shell/platform/tizen/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ config("flutter_tizen_config") {
4646
"${sysroot_path}/usr/include/feedback",
4747
"${sysroot_path}/usr/include/system",
4848
"${sysroot_path}/usr/include/tzsh",
49+
"${sysroot_path}/usr/include/vconf",
4950
"${sysroot_path}/usr/include/wayland-extension",
5051
]
5152

@@ -85,6 +86,7 @@ template("embedder") {
8586
"channels/key_event_channel.cc",
8687
"channels/key_mapping.cc",
8788
"channels/lifecycle_channel.cc",
89+
"channels/mouse_cursor_channel.cc",
8890
"channels/navigation_channel.cc",
8991
"channels/platform_channel.cc",
9092
"channels/platform_view_channel.cc",
@@ -134,6 +136,7 @@ template("embedder") {
134136
"feedback",
135137
"flutter_engine",
136138
"tbm",
139+
"vconf",
137140
"wayland-client",
138141
]
139142

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#ifndef EMBEDDER_MOUSE_CURSOR_CHANNEL_H_
6+
#define EMBEDDER_MOUSE_CURSOR_CHANNEL_H_
7+
8+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
9+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h"
10+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
11+
#include "flutter/shell/platform/tizen/tizen_view_base.h"
12+
13+
namespace flutter {
14+
15+
// Channel to set the system's cursor type.
16+
class MouseCursorChannel {
17+
public:
18+
explicit MouseCursorChannel(BinaryMessenger* messenger, TizenViewBase* view);
19+
virtual ~MouseCursorChannel();
20+
21+
private:
22+
// Called when a method is called on |channel_|;
23+
void HandleMethodCall(
24+
const flutter::MethodCall<EncodableValue>& method_call,
25+
std::unique_ptr<flutter::MethodResult<EncodableValue>> result);
26+
27+
// The MethodChannel used for communication with the Flutter engine.
28+
std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel_;
29+
30+
// A reference to the native view managed by FlutterTizenView.
31+
TizenViewBase* view_ = nullptr;
32+
};
33+
34+
} // namespace flutter
35+
36+
#endif // EMBEDDER_MOUSE_CURSOR_CHANNEL_H_

flutter/shell/platform/tizen/flutter_tizen_view.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ void FlutterTizenView::SetEngine(std::unique_ptr<FlutterTizenEngine> engine) {
8484

8585
platform_channel_ =
8686
std::make_unique<PlatformChannel>(messenger, tizen_view_.get());
87+
mouse_cursor_channel_ =
88+
std::make_unique<MouseCursorChannel>(messenger, tizen_view_.get());
8789
text_input_channel_ = std::make_unique<TextInputChannel>(
8890
internal_plugin_registrar_->messenger(),
8991
tizen_view_->input_method_context());

flutter/shell/platform/tizen/flutter_tizen_view.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
1313
#include "flutter/shell/platform/embedder/embedder.h"
14+
#include "flutter/shell/platform/tizen/channels/mouse_cursor_channel.h"
1415
#include "flutter/shell/platform/tizen/channels/platform_channel.h"
1516
#include "flutter/shell/platform/tizen/channels/text_input_channel.h"
1617
#include "flutter/shell/platform/tizen/channels/window_channel.h"
@@ -177,6 +178,9 @@ class FlutterTizenView : public TizenViewEventHandlerDelegate {
177178
// A plugin that implements the Flutter platform channel.
178179
std::unique_ptr<PlatformChannel> platform_channel_;
179180

181+
// A plugin that implements the Flutter cursor channel.
182+
std::unique_ptr<MouseCursorChannel> mouse_cursor_channel_;
183+
180184
// A plugin that implements the Flutter textinput channel.
181185
std::unique_ptr<TextInputChannel> text_input_channel_;
182186

flutter/shell/platform/tizen/tizen_view_base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class TizenViewBase {
4141
// Returns the dpi of the screen.
4242
virtual int32_t GetDpi() = 0;
4343

44+
virtual void UpdateFlutterCursor(const std::string& kind) = 0;
45+
4446
// Sets the delegate used to communicate state changes from render target to
4547
// view such as key presses, mouse position updates etc.
4648
void SetView(TizenViewEventHandlerDelegate* view_delegate) {

flutter/shell/platform/tizen/tizen_view_elementary.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ void TizenViewElementary::Show() {
367367
evas_object_show(image_);
368368
}
369369

370+
void TizenViewElementary::UpdateFlutterCursor(const std::string& kind) {
371+
FT_LOG(Info) << "UpdateFlutterCursor is not supported.";
372+
}
373+
370374
void TizenViewElementary::PrepareInputMethod() {
371375
input_method_context_ =
372376
std::make_unique<TizenInputMethodContext>(GetWindowId());

flutter/shell/platform/tizen/tizen_view_elementary.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class TizenViewElementary : public TizenView {
3737

3838
void Show() override;
3939

40+
void UpdateFlutterCursor(const std::string& kind) override;
41+
4042
private:
4143
bool CreateView();
4244

flutter/shell/platform/tizen/tizen_view_nui.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ void TizenViewNui::OnKey(const char* device_name,
9797
}
9898
}
9999

100+
void TizenViewNui::UpdateFlutterCursor(const std::string& kind) {
101+
FT_LOG(Info) << "UpdateFlutterCursor is not supported.";
102+
}
103+
100104
void TizenViewNui::PrepareInputMethod() {
101105
input_method_context_ =
102106
std::make_unique<TizenInputMethodContext>(GetWindowId());

flutter/shell/platform/tizen/tizen_view_nui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class TizenViewNui : public TizenView {
5353
size_t timestamp,
5454
bool is_down);
5555

56+
void UpdateFlutterCursor(const std::string& kind) override;
57+
5658
private:
5759
void RegisterEventHandlers();
5860

0 commit comments

Comments
 (0)