Skip to content

[SystemChrome] setPreferredOrientations implementation added #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions shell/platform/tizen/channels/platform_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

#include <app.h>

#include <map>

#include "flutter/shell/platform/common/cpp/json_method_codec.h"
#include "flutter/shell/platform/tizen/tizen_log.h"

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

PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger)
PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger,
TizenRenderer* renderer)
: channel_(std::make_unique<flutter::MethodChannel<rapidjson::Document>>(
messenger, kChannelName, &flutter::JsonMethodCodec::GetInstance())) {
channel_->SetMethodCallHandler(
Expand All @@ -20,6 +23,9 @@ PlatformChannel::PlatformChannel(flutter::BinaryMessenger* messenger)
std::unique_ptr<flutter::MethodResult<rapidjson::Document>> result) {
HandleMethodCall(call, std::move(result));
});
// renderer pointer is managed by TizenEmbedderEngine
// !! can be nullptr in case of service application !!
tizen_renderer = renderer;
}

PlatformChannel::~PlatformChannel() {}
Expand All @@ -43,7 +49,41 @@ void PlatformChannel::HandleMethodCall(
} else if (method == "Clipboard.hasStrings") {
result->NotImplemented();
} else if (method == "SystemChrome.setPreferredOrientations") {
result->NotImplemented();
if (tizen_renderer) {
static const std::string kPortraitUp = "DeviceOrientation.portraitUp";
static const std::string kPortraitDown = "DeviceOrientation.portraitDown";
static const std::string kLandscapeLeft =
"DeviceOrientation.landscapeLeft";
static const std::string kLandscapeRight =
"DeviceOrientation.landscapeRight";
static const std::map<std::string, int> orientation_mapping = {
{kPortraitUp, 0},
{kLandscapeLeft, 90},
{kPortraitDown, 180},
{kLandscapeRight, 270},
};

const auto& list = call.arguments()[0];
std::vector<int> rotations;
for (rapidjson::Value::ConstValueIterator itr = list.Begin();
itr != list.End(); ++itr) {
const std::string& rot = itr->GetString();
FT_LOGD("Passed rotation: %s", rot.c_str());
rotations.push_back(orientation_mapping.at(rot));
}
if (rotations.size() == 0) {
// According do docs
// https://api.flutter.dev/flutter/services/SystemChrome/setPreferredOrientations.html
// "The empty list causes the application to defer to the operating
// system default."
FT_LOGD("No rotations passed, using default values");
rotations = {0, 90, 180, 270};
}
tizen_renderer->SetPreferredOrientations(rotations);
result->Success();
} else {
result->Error("Not supported for service applications");
}
} else if (method == "SystemChrome.setApplicationSwitcherDescription") {
result->NotImplemented();
} else if (method == "SystemChrome.setEnabledSystemUIOverlays") {
Expand Down
5 changes: 4 additions & 1 deletion shell/platform/tizen/channels/platform_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@

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

class PlatformChannel {
public:
explicit PlatformChannel(flutter::BinaryMessenger* messenger);
explicit PlatformChannel(flutter::BinaryMessenger* messenger,
TizenRenderer* renderer);
virtual ~PlatformChannel();

private:
std::unique_ptr<flutter::MethodChannel<rapidjson::Document>> channel_;
TizenRenderer* tizen_renderer;

void HandleMethodCall(
const flutter::MethodCall<rapidjson::Document>& call,
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/tizen/tizen_embedder_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool TizenEmbedderEngine::RunEngine(
navigation_channel = std::make_unique<NavigationChannel>(
internal_plugin_registrar_->messenger());
platform_channel = std::make_unique<PlatformChannel>(
internal_plugin_registrar_->messenger());
internal_plugin_registrar_->messenger(), tizen_renderer.get());
settings_channel = std::make_unique<SettingsChannel>(
internal_plugin_registrar_->messenger());
text_input_channel = std::make_unique<TextInputChannel>(
Expand Down
2 changes: 2 additions & 0 deletions shell/platform/tizen/tizen_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define EMBEDDER_TIZEN_RENDERER_H

#include <cstdint>
#include <vector>

class TizenRenderer {
public:
Expand Down Expand Up @@ -36,6 +37,7 @@ class TizenRenderer {
virtual void SetRotate(int angle) = 0;
virtual void ResizeWithRotation(int32_t x, int32_t y, int32_t width,
int32_t height, int32_t degree) = 0;
virtual void SetPreferredOrientations(const std::vector<int>& rotations) = 0;

protected:
explicit TizenRenderer(TizenRenderer::Delegate& delegate);
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/tizen/tizen_renderer_ecore_wl2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -585,3 +585,9 @@ void TizenRendererEcoreWl2::SendRotationChangeDone() {
ecore_wl2_window_, ecore_wl2_window_rotation_get(ecore_wl2_window_), w,
h);
}

void TizenRendererEcoreWl2::SetPreferredOrientations(
const std::vector<int> &rotations) {
ecore_wl2_window_available_rotations_set(ecore_wl2_window_, rotations.data(),
rotations.size());
}
1 change: 1 addition & 0 deletions shell/platform/tizen/tizen_renderer_ecore_wl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TizenRendererEcoreWl2 : public TizenRenderer {
void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height,
int32_t angle) override;
void SetRotate(int angle) override;
void SetPreferredOrientations(const std::vector<int> &rotations) override;

private:
bool InitializeRenderer();
Expand Down
7 changes: 7 additions & 0 deletions shell/platform/tizen/tizen_renderer_evas_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -709,3 +709,10 @@ void TizenRendererEvasGL::ResizeWithRotation(int32_t x, int32_t y,
void TizenRendererEvasGL::SendRotationChangeDone() {
elm_win_wm_rotation_manual_rotation_done(evas_window_);
}

void TizenRendererEvasGL::SetPreferredOrientations(
const std::vector<int>& rotations) {
elm_win_wm_rotation_available_rotations_set(
evas_window_, static_cast<const int*>(rotations.data()),
rotations.size());
}
1 change: 1 addition & 0 deletions shell/platform/tizen/tizen_renderer_evas_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TizenRendererEvasGL : public TizenRenderer {
void ResizeWithRotation(int32_t x, int32_t y, int32_t width, int32_t height,
int32_t angle) override;
void SetRotate(int angle) override;
void SetPreferredOrientations(const std::vector<int>& rotations) override;

void* GetImageHandle();

Expand Down