| Flutter Windows Embedder |

platform_view_manager.cc
Go to the documentation of this file.
1 // Copyright 2013 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 "flutter/shell/platform/windows/platform_view_manager.h"
6
7 #include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
8
9 namespace flutter {
10
11 namespace {
12 constexpr char kChannelName[] = "flutter/platform_views";
13 constexpr char kCreateMethod[] = "create";
14 constexpr char kFocusMethod[] = "focus";
15 constexpr char kViewTypeParameter[] = "viewType";
16 constexpr char kIdParameter[] = "id";
17 constexpr char kDirectionParameter[] = "direction";
18 constexpr char kFocusParameter[] = "focus";
19 } // namespace
20
21 PlatformViewManager::PlatformViewManager(BinaryMessenger* binary_messenger)
22 : channel_(std::make_unique<MethodChannel<EncodableValue>>(
23 binary_messenger,
24 kChannelName,
25 &StandardMethodCodec::GetInstance())) {
26 channel_->SetMethodCallHandler(
27 [this](const MethodCall<EncodableValue>& call,
28 std::unique_ptr<MethodResult<EncodableValue>> result) {
29 const auto& args = std::get<EncodableMap>(*call.arguments());
30 if (call.method_name() == kCreateMethod) {
31 const auto& type_itr = args.find(EncodableValue(kViewTypeParameter));
32 const auto& id_itr = args.find(EncodableValue(kIdParameter));
33 if (type_itr == args.end()) {
34 result->Error("AddPlatformView", "Parameter viewType is required");
35 return;
36 }
37 if (id_itr == args.end()) {
38 result->Error("AddPlatformView", "Parameter id is required");
39 return;
40 }
41 const auto& type = std::get<std::string>(type_itr->second);
42 const auto& id = std::get<std::int32_t>(id_itr->second);
43 if (AddPlatformView(id, type)) {
44 result->Success();
45 } else {
46 result->Error("AddPlatformView", "Failed to add platform view");
47 }
48 return;
49 } else if (call.method_name() == kFocusMethod) {
50 const auto& id_itr = args.find(EncodableValue(kIdParameter));
51 const auto& direction_itr =
52 args.find(EncodableValue(kDirectionParameter));
53 const auto& focus_itr = args.find(EncodableValue(kFocusParameter));
54 if (id_itr == args.end()) {
55 result->Error("FocusPlatformView", "Parameter id is required");
56 return;
57 }
58 if (direction_itr == args.end()) {
59 result->Error("FocusPlatformView",
60 "Parameter direction is required");
61 return;
62 }
63 if (focus_itr == args.end()) {
64 result->Error("FocusPlatformView", "Parameter focus is required");
65 return;
66 }
67 const auto& id = std::get<std::int32_t>(id_itr->second);
68 const auto& direction = std::get<std::int32_t>(direction_itr->second);
69 const auto& focus = std::get<bool>(focus_itr->second);
70 if (FocusPlatformView(
71 id, static_cast<FocusChangeDirection>(direction), focus)) {
72 result->Success();
73 } else {
74 result->Error("FocusPlatformView", "Failed to focus platform view");
75 }
76 return;
77 }
78 result->NotImplemented();
79 });
80 }
81
82 PlatformViewManager::~PlatformViewManager() {}
83
84 } // namespace flutter
flutter::BinaryMessenger
Definition: binary_messenger.h:28
flutter::EncodableValue
Definition: encodable_value.h:165
flutter::MethodCall
Definition: method_call.h:18
flutter::MethodCall::method_name
const std::string & method_name() const
Definition: method_call.h:31
flutter::MethodCall::arguments
const T * arguments() const
Definition: method_call.h:34
flutter::MethodChannel
Definition: method_channel.h:34
flutter::MethodResult< EncodableValue >
flutter::PlatformViewManager::~PlatformViewManager
virtual ~PlatformViewManager()
Definition: platform_view_manager.cc:82
flutter::PlatformViewManager::FocusPlatformView
virtual bool FocusPlatformView(PlatformViewId id, FocusChangeDirection direction, bool focus)=0
flutter::PlatformViewManager::PlatformViewManager
PlatformViewManager(BinaryMessenger *binary_messenger)
Definition: platform_view_manager.cc:21
flutter::PlatformViewManager::AddPlatformView
virtual bool AddPlatformView(PlatformViewId id, std::string_view type_name)=0
flutter::StandardMethodCodec
Definition: standard_method_codec.h:18
kChannelName
static constexpr char kChannelName[]
Definition: cursor_handler.cc:12
type
enum flutter::testing::@88::KeyboardChange::Type type
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::FocusChangeDirection
FocusChangeDirection
Definition: platform_view_manager.h:17
platform_view_manager.h
standard_method_codec.h