Skip to content

Commit d5b9405

Browse files
swift-kimGitHub Enterprise
authored andcommitted
Handle back button events (#19)
* Create channels directory * Handle back button events
1 parent e45fefe commit d5b9405

17 files changed

+248
-24
lines changed

shell/platform/tizen/BUILD.gn

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,20 @@ source_set("flutter_tizen_headers") {
5050

5151
source_set("flutter_tizen") {
5252
sources = [
53+
"channels/key_event_channel.cc",
54+
"channels/lifecycle_channel.cc",
55+
"channels/localization_channel.cc",
56+
"channels/navigation_channel.cc",
57+
"channels/platform_channel.cc",
58+
"channels/text_input_plugin.cc",
59+
"channels/touch_event_channel.cc",
5360
"flutter_tizen.cc",
54-
"key_event_channel.cc",
55-
"lifecycle_channel.cc",
56-
"localization_channel.cc",
57-
"text_input_plugin.cc",
5861
"tizen_embedder_engine.cc",
5962
"tizen_event_loop.cc",
6063
"tizen_surface.cc",
6164
"tizen_surface_gl.cc",
6265
"tizen_surface_software.cc",
6366
"tizen_vsync_waiter.cc",
64-
"touch_event_channel.cc",
6567
]
6668

6769
defines = [ "USE_RAPID_JSON" ]

shell/platform/tizen/key_event_channel.cc renamed to shell/platform/tizen/channels/key_event_channel.cc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
#include "key_event_channel.h"
1818

19+
#include "flutter/shell/platform/tizen/channels/navigation_channel.h"
20+
#include "flutter/shell/platform/tizen/channels/text_input_plugin.h"
1921
#include "flutter/shell/platform/tizen/logger.h"
20-
#include "flutter/shell/platform/tizen/text_input_plugin.h"
2122

2223
static constexpr char kChannelName[] = "flutter/keyevent";
24+
2325
static constexpr char kKeyMapKey[] = "keymap";
2426
static constexpr char kKeyCodeKey[] = "keyCode";
2527
static constexpr char kTypeKey[] = "type";
@@ -30,6 +32,8 @@ static constexpr char kTizenKeyMap[] = "tizen";
3032
static constexpr char kKeyUp[] = "keyup";
3133
static constexpr char kKeyDown[] = "keydown";
3234

35+
static constexpr char kPlatformBackButtonName[] = "XF86Back";
36+
3337
KeyEventChannel::KeyEventChannel(flutter::BinaryMessenger* messenger)
3438
: channel_(
3539
std::make_unique<flutter::BasicMessageChannel<rapidjson::Document>>(
@@ -41,8 +45,13 @@ KeyEventChannel::KeyEventChannel(flutter::BinaryMessenger* messenger)
4145
[](void* data, int type, void* event) -> Eina_Bool {
4246
Ecore_Event_Key* keyEvent = reinterpret_cast<Ecore_Event_Key*>(event);
4347
auto self = reinterpret_cast<KeyEventChannel*>(data);
44-
if (!self->textInputPlugin_ ||
45-
!self->textInputPlugin_->isSoftwareKeyboardShowing()) {
48+
49+
if (strcmp(keyEvent->keyname, kPlatformBackButtonName) == 0) {
50+
// The device back button was pressed. Do nothing.
51+
} else if (self->textInputPlugin_ &&
52+
self->textInputPlugin_->isSoftwareKeyboardShowing()) {
53+
// Handled by software keyboard.
54+
} else {
4655
self->OnKeyDown(keyEvent);
4756
}
4857
return ECORE_CALLBACK_PASS_ON;
@@ -54,8 +63,16 @@ KeyEventChannel::KeyEventChannel(flutter::BinaryMessenger* messenger)
5463
[](void* data, int type, void* event) -> Eina_Bool {
5564
Ecore_Event_Key* keyEvent = reinterpret_cast<Ecore_Event_Key*>(event);
5665
auto self = reinterpret_cast<KeyEventChannel*>(data);
57-
if (!self->textInputPlugin_ ||
58-
!self->textInputPlugin_->isSoftwareKeyboardShowing()) {
66+
67+
if (strcmp(keyEvent->keyname, kPlatformBackButtonName) == 0) {
68+
// The device back button was pressed.
69+
if (self->navigation_channel_) {
70+
self->navigation_channel_->PopRoute();
71+
}
72+
} else if (self->textInputPlugin_ &&
73+
self->textInputPlugin_->isSoftwareKeyboardShowing()) {
74+
// Handled by software keyboard.
75+
} else {
5976
self->OnKeyUp(keyEvent);
6077
}
6178
return ECORE_CALLBACK_PASS_ON;

shell/platform/tizen/key_event_channel.h renamed to shell/platform/tizen/channels/key_event_channel.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,31 @@
2424
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/basic_message_channel.h"
2525
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h"
2626
#include "flutter/shell/platform/common/cpp/json_message_codec.h"
27-
#include "logger.h"
2827
#include "rapidjson/document.h"
2928

29+
class NavigationChannel;
3030
class TextInputPlugin;
3131

3232
class KeyEventChannel {
3333
public:
3434
explicit KeyEventChannel(flutter::BinaryMessenger* messenger);
3535
virtual ~KeyEventChannel();
36+
37+
void setNavigationChannel(NavigationChannel* channel) {
38+
navigation_channel_ = channel;
39+
}
3640
void setTextInputPlugin(TextInputPlugin* textInputPlugin) {
3741
textInputPlugin_ = textInputPlugin;
3842
}
3943

4044
private:
4145
std::unique_ptr<flutter::BasicMessageChannel<rapidjson::Document>> channel_;
4246
std::vector<Ecore_Event_Handler*> key_event_handlers;
47+
4348
void OnKeyDown(Ecore_Event_Key* keyDownEvent);
4449
void OnKeyUp(Ecore_Event_Key* keyDownEvent);
50+
51+
NavigationChannel* navigation_channel_;
4552
TextInputPlugin* textInputPlugin_;
4653
};
4754

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "navigation_channel.h"
18+
19+
#include "flutter/shell/platform/common/cpp/json_method_codec.h"
20+
#include "flutter/shell/platform/tizen/logger.h"
21+
22+
static constexpr char kChannelName[] = "flutter/navigation";
23+
24+
static constexpr char kSetInitialRouteMethod[] = "setInitialRoute";
25+
static constexpr char kPushRouteMethod[] = "pushRoute";
26+
static constexpr char kPopRouteMethod[] = "popRoute";
27+
28+
NavigationChannel::NavigationChannel(flutter::BinaryMessenger* messenger)
29+
: channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
30+
messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())) {}
31+
32+
NavigationChannel::~NavigationChannel() {}
33+
34+
void NavigationChannel::SetInitialRoute(const std::string& initialRoute) {
35+
auto args = std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
36+
args->Parse("\"" + initialRoute + "\"");
37+
38+
if (!args->HasParseError()) {
39+
channel_->InvokeMethod(kSetInitialRouteMethod, std::move(args));
40+
}
41+
}
42+
43+
void NavigationChannel::PushRoute(const std::string& route) {
44+
auto args = std::make_unique<rapidjson::Document>(rapidjson::kObjectType);
45+
args->Parse("\"" + route + "\"");
46+
47+
if (!args->HasParseError()) {
48+
channel_->InvokeMethod(kPushRouteMethod, std::move(args));
49+
}
50+
}
51+
52+
void NavigationChannel::PopRoute() {
53+
channel_->InvokeMethod(kPopRouteMethod, nullptr);
54+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef EMBEDDER_NAVIGATION_CHANNEL_H_
18+
#define EMBEDDER_NAVIGATION_CHANNEL_H_
19+
20+
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h"
21+
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h"
22+
#include "rapidjson/document.h"
23+
24+
class NavigationChannel {
25+
public:
26+
explicit NavigationChannel(flutter::BinaryMessenger* messenger);
27+
virtual ~NavigationChannel();
28+
29+
void SetInitialRoute(const std::string& initialRoute);
30+
void PushRoute(const std::string& route);
31+
void PopRoute();
32+
33+
private:
34+
std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
35+
};
36+
37+
#endif // EMBEDDER_NAVIGATION_CHANNEL_H_
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "platform_channel.h"
18+
19+
#include "flutter/shell/platform/common/cpp/json_method_codec.h"
20+
#include "flutter/shell/platform/tizen/logger.h"
21+
22+
static constexpr char kChannelName[] = "flutter/platform";
23+
24+
PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger)
25+
: channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
26+
messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())) {
27+
channel_->SetMethodCallHandler(
28+
[this](
29+
const flutter::MethodCall<rapidjson::Document>& call,
30+
std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
31+
HandleMethodCall(call, std::move(result));
32+
});
33+
}
34+
35+
PlatformChannel::~PlatformChannel() {}
36+
37+
void PlatformChannel::HandleMethodCall(
38+
const flutter::MethodCall<rapidjson::Document>& call,
39+
std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
40+
const auto method = call.method_name();
41+
42+
if (method == "SystemNavigator.pop") {
43+
exit(EXIT_SUCCESS);
44+
result->Success();
45+
} else if (method == "SystemSound.play") {
46+
result->NotImplemented();
47+
} else if (method == "HapticFeedback.vibrate") {
48+
result->NotImplemented();
49+
} else if (method == "Clipboard.getData") {
50+
result->NotImplemented();
51+
} else if (method == "Clipboard.setData") {
52+
result->NotImplemented();
53+
} else if (method == "Clipboard.hasStrings") {
54+
result->NotImplemented();
55+
} else if (method == "SystemChrome.setPreferredOrientations") {
56+
result->NotImplemented();
57+
} else if (method == "SystemChrome.setApplicationSwitcherDescription") {
58+
result->NotImplemented();
59+
} else if (method == "SystemChrome.setEnabledSystemUIOverlays") {
60+
result->NotImplemented();
61+
} else if (method == "SystemChrome.restoreSystemUIOverlays") {
62+
result->NotImplemented();
63+
} else if (method == "SystemChrome.setSystemUIOverlayStyle") {
64+
result->NotImplemented();
65+
} else {
66+
LoggerI("Unimplemented method: %s", method.c_str());
67+
result->NotImplemented();
68+
}
69+
}

0 commit comments

Comments
 (0)