Skip to content

Commit

Permalink
Use the flutter namespace (flutter-tizen#121)
Browse files Browse the repository at this point in the history
* Remove engine dependency of LifecycleChannel

* Minor formatting

* Organize headers

* Use the flutter namespace

* Revert "Remove engine dependency of LifecycleChannel"

This reverts commit a45473d.
  • Loading branch information
swift-kim committed Sep 27, 2021
1 parent 365189d commit 06a050d
Show file tree
Hide file tree
Showing 42 changed files with 423 additions and 208 deletions.
47 changes: 27 additions & 20 deletions shell/platform/tizen/channels/key_event_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@

#include "flutter/shell/platform/tizen/tizen_log.h"

static constexpr char kChannelName[] = "flutter/keyevent";
namespace flutter {

static constexpr char kKeyMapKey[] = "keymap";
static constexpr char kKeyCodeKey[] = "keyCode";
static constexpr char kScanCodeKey[] = "scanCode";
static constexpr char kTypeKey[] = "type";
static constexpr char kModifiersKey[] = "modifiers";
static constexpr char kToolkitKey[] = "toolkit";
static constexpr char kUnicodeScalarValuesKey[] = "unicodeScalarValues";
namespace {

static constexpr char kKeyUp[] = "keyup";
static constexpr char kKeyDown[] = "keydown";
static constexpr char kGtkToolkit[] = "gtk";
static constexpr char kLinuxKeyMap[] = "linux";
constexpr char kChannelName[] = "flutter/keyevent";

constexpr char kKeyMapKey[] = "keymap";
constexpr char kKeyCodeKey[] = "keyCode";
constexpr char kScanCodeKey[] = "scanCode";
constexpr char kTypeKey[] = "type";
constexpr char kModifiersKey[] = "modifiers";
constexpr char kToolkitKey[] = "toolkit";
constexpr char kUnicodeScalarValuesKey[] = "unicodeScalarValues";

constexpr char kKeyUp[] = "keyup";
constexpr char kKeyDown[] = "keydown";
constexpr char kGtkToolkit[] = "gtk";
constexpr char kLinuxKeyMap[] = "linux";

// Mapping from physical (xkb) to logical (GTK) key codes.
// The values are defined in:
// - flutter/keyboard_maps.dart (kLinuxToPhysicalKey, kGtkToLogicalKey)
static const std::map<int, int> kKeyCodeMap = {
const std::map<int, int> kKeyCodeMap = {
{0x00000009, 65307}, // LogicalKeyboardKey.escape
{0x0000000a, 49}, // LogicalKeyboardKey.digit1
{0x0000000b, 50}, // LogicalKeyboardKey.digit2
Expand Down Expand Up @@ -202,7 +206,7 @@ static const std::map<int, int> kKeyCodeMap = {
// The values are defined in:
// - efl/Ecore_Input.h
// - flutter/raw_keyboard_linux.dart (GtkKeyHelper)
static const std::map<int, int> kModifierMap = {
const std::map<int, int> kModifierMap = {
{0x0001, 1 << 0}, // SHIFT (modifierShift)
{0x0002, 1 << 2}, // CTRL (modifierControl)
{0x0004, 1 << 3}, // ALT (modifierMod1)
Expand All @@ -212,12 +216,13 @@ static const std::map<int, int> kModifierMap = {
{0x0040, 1 << 1}, // CAPS (modifierCapsLock)
};

KeyEventChannel::KeyEventChannel(flutter::BinaryMessenger* messenger)
: channel_(
std::make_unique<flutter::BasicMessageChannel<rapidjson::Document>>(
messenger,
kChannelName,
&flutter::JsonMessageCodec::GetInstance())) {}
} // namespace

KeyEventChannel::KeyEventChannel(BinaryMessenger* messenger)
: channel_(std::make_unique<BasicMessageChannel<rapidjson::Document>>(
messenger,
kChannelName,
&JsonMessageCodec::GetInstance())) {}

KeyEventChannel::~KeyEventChannel() {}

Expand Down Expand Up @@ -251,3 +256,5 @@ void KeyEventChannel::SendKeyEvent(Ecore_Event_Key* key, bool is_down) {
}
channel_->Send(event);
}

} // namespace flutter
10 changes: 8 additions & 2 deletions shell/platform/tizen/channels/key_event_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@

#include <Ecore_Input.h>

#include <memory>

#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
#include "flutter/shell/platform/common/json_message_codec.h"
#include "rapidjson/document.h"

namespace flutter {

class KeyEventChannel {
public:
explicit KeyEventChannel(flutter::BinaryMessenger* messenger);
explicit KeyEventChannel(BinaryMessenger* messenger);
virtual ~KeyEventChannel();

void SendKeyEvent(Ecore_Event_Key* key, bool is_down);

private:
std::unique_ptr<flutter::BasicMessageChannel<rapidjson::Document>> channel_;
std::unique_ptr<BasicMessageChannel<rapidjson::Document>> channel_;
};

} // namespace flutter

#endif // EMBEDDER_KEY_EVENT_CHANNEL_H_
19 changes: 14 additions & 5 deletions shell/platform/tizen/channels/lifecycle_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/tizen_log.h"

static constexpr char kChannelName[] = "flutter/lifecycle";
static constexpr char kInactive[] = "AppLifecycleState.inactive";
static constexpr char kResumed[] = "AppLifecycleState.resumed";
static constexpr char kPaused[] = "AppLifecycleState.paused";
static constexpr char kDetached[] = "AppLifecycleState.detached";
namespace flutter {

namespace {

constexpr char kChannelName[] = "flutter/lifecycle";

constexpr char kInactive[] = "AppLifecycleState.inactive";
constexpr char kResumed[] = "AppLifecycleState.resumed";
constexpr char kPaused[] = "AppLifecycleState.paused";
constexpr char kDetached[] = "AppLifecycleState.detached";

} // namespace

LifecycleChannel::LifecycleChannel(FlutterTizenEngine* engine)
: engine_(engine) {}
Expand Down Expand Up @@ -43,3 +50,5 @@ void LifecycleChannel::AppIsDetached() {
FT_LOGI("send app lifecycle state detached.");
SendLifecycleMessage(kDetached);
}

} // namespace flutter
4 changes: 4 additions & 0 deletions shell/platform/tizen/channels/lifecycle_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef EMBEDDER_LIFECYCLE_CHANNEL_H_
#define EMBEDDER_LIFECYCLE_CHANNEL_H_

namespace flutter {

class FlutterTizenEngine;

class LifecycleChannel {
Expand All @@ -22,4 +24,6 @@ class LifecycleChannel {
FlutterTizenEngine* engine_{nullptr};
};

} // namespace flutter

#endif // EMBEDDER_LIFECYCLE_CHANNEL_H_
4 changes: 4 additions & 0 deletions shell/platform/tizen/channels/localization_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

static constexpr char kChannelName[] = "flutter/localization";

namespace flutter {

LocalizationChannel::LocalizationChannel(FlutterTizenEngine* engine)
: engine_(engine) {}

Expand Down Expand Up @@ -197,3 +199,5 @@ void LocalizationChannel::DestroyFlutterLocale(FlutterLocale* flutter_locale) {
flutter_locale = nullptr;
}
}

} // namespace flutter
4 changes: 4 additions & 0 deletions shell/platform/tizen/channels/localization_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "flutter/shell/platform/embedder/embedder.h"

namespace flutter {

class FlutterTizenEngine;

class LocalizationChannel {
Expand All @@ -24,4 +26,6 @@ class LocalizationChannel {
FlutterTizenEngine* engine_;
};

} // namespace flutter

#endif // EMBEDDER_LOCALIZATION_CHANNEL_H_
22 changes: 15 additions & 7 deletions shell/platform/tizen/channels/navigation_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

#include "flutter/shell/platform/common/json_method_codec.h"

static constexpr char kChannelName[] = "flutter/navigation";
namespace flutter {

static constexpr char kSetInitialRouteMethod[] = "setInitialRoute";
static constexpr char kPushRouteMethod[] = "pushRoute";
static constexpr char kPopRouteMethod[] = "popRoute";
namespace {

NavigationChannel::NavigationChannel(flutter::BinaryMessenger* messenger)
: channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
constexpr char kChannelName[] = "flutter/navigation";

constexpr char kSetInitialRouteMethod[] = "setInitialRoute";
constexpr char kPushRouteMethod[] = "pushRoute";
constexpr char kPopRouteMethod[] = "popRoute";

} // namespace

NavigationChannel::NavigationChannel(BinaryMessenger* messenger)
: channel_(std::make_unique<MethodChannel<rapidjson::Document>>(
messenger,
kChannelName,
&flutter::JsonMethodCodec::GetInstance())) {}
&JsonMethodCodec::GetInstance())) {}

NavigationChannel::~NavigationChannel() {}

Expand All @@ -41,3 +47,5 @@ void NavigationChannel::PushRoute(const std::string& route) {
void NavigationChannel::PopRoute() {
channel_->InvokeMethod(kPopRouteMethod, nullptr);
}

} // namespace flutter
13 changes: 10 additions & 3 deletions shell/platform/tizen/channels/navigation_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@
#ifndef EMBEDDER_NAVIGATION_CHANNEL_H_
#define EMBEDDER_NAVIGATION_CHANNEL_H_

#include <memory>
#include <string>

#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
#include "rapidjson/document.h"

namespace flutter {

class NavigationChannel {
public:
explicit NavigationChannel(flutter::BinaryMessenger* messenger);
explicit NavigationChannel(BinaryMessenger* messenger);
virtual ~NavigationChannel();

void SetInitialRoute(const std::string& initialRoute);
void PushRoute(const std::string& route);
void PopRoute();

private:
std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
std::unique_ptr<MethodChannel<rapidjson::Document>> channel_;
};

#endif // EMBEDDER_NAVIGATION_CHANNEL_H_
} // namespace flutter

#endif // EMBEDDER_NAVIGATION_CHANNEL_H_
Loading

0 comments on commit 06a050d

Please sign in to comment.