-
Notifications
You must be signed in to change notification settings - Fork 6k
Add Platform View Manager to Windows shell #50598
Changes from all commits
500e60c
8dd4543
ae0d049
5f14af0
200f13a
ed90810
5d410ff
484c8c1
b8fadd7
1d203f4
b9acc1a
35eb688
659ebd6
db2851b
db48ddd
f87ed96
42f976e
284b309
e000930
676868f
6e6ef7e
22a9e46
95a8498
1fa97f3
5453b29
dfa6b73
cde468e
585ca11
54d91a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
#include "flutter/shell/platform/windows/testing/egl/mock_manager.h" | ||
#include "flutter/shell/platform/windows/testing/engine_modifier.h" | ||
#include "flutter/shell/platform/windows/testing/flutter_windows_engine_builder.h" | ||
#include "flutter/shell/platform/windows/testing/mock_platform_view_manager.h" | ||
#include "flutter/shell/platform/windows/testing/mock_window_binding_handler.h" | ||
#include "flutter/shell/platform/windows/testing/mock_windows_proc_table.h" | ||
#include "flutter/shell/platform/windows/testing/test_keyboard.h" | ||
|
@@ -1171,5 +1172,30 @@ TEST_F(FlutterWindowsEngineTest, ChannelListenedTo) { | |
} | ||
} | ||
|
||
TEST_F(FlutterWindowsEngineTest, ReceivePlatformViewMessage) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my understanding, this file is more for engine unit tests. Since this launches & runs a full app, should we move this to the integration tests in I don't feel strongly about this, feel free to keep as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me that this test is quite similar in most regards to the handful of unit tests immediately preceding it in this file. Would you disagree? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's probably fine to land as-is, but I do think we should probably do a followup evaluation of which tests belong where. We're definitely not super consistent and to be honest, I'm not sure we've ever drawn a really clear line (not just in the Windows embedder but also on macOS). |
||
FlutterWindowsEngineBuilder builder{GetContext()}; | ||
builder.SetDartEntrypoint("sendCreatePlatformViewMethod"); | ||
auto engine = builder.Build(); | ||
|
||
EngineModifier modifier{engine.get()}; | ||
modifier.embedder_api().RunsAOTCompiledDartCode = []() { return false; }; | ||
|
||
bool received_call = false; | ||
|
||
auto manager = std::make_unique<MockPlatformViewManager>(engine.get()); | ||
EXPECT_CALL(*manager, AddPlatformView) | ||
.WillOnce([&](PlatformViewId id, std::string_view type_name) { | ||
received_call = true; | ||
return true; | ||
}); | ||
modifier.SetPlatformViewPlugin(std::move(manager)); | ||
|
||
engine->Run(); | ||
|
||
while (!received_call) { | ||
engine->task_runner()->ProcessTasks(); | ||
} | ||
} | ||
|
||
} // namespace testing | ||
} // namespace flutter |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_INTERNAL_H_ | ||
#define FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_INTERNAL_H_ | ||
|
||
#include "flutter/shell/platform/windows/public/flutter_windows.h" | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
// Declare functions that are currently in-progress and shall be exposed to the | ||
// public facing API upon completion. | ||
|
||
typedef int64_t PlatformViewId; | ||
|
||
typedef struct { | ||
size_t struct_size; | ||
HWND parent_window; | ||
const char* platform_view_type; | ||
// user_data may hold any necessary additional information for creating a new | ||
// platform view. For example, an instance of FlutterWindow. | ||
void* user_data; | ||
PlatformViewId platform_view_id; | ||
} FlutterPlatformViewCreationParameters; | ||
|
||
typedef HWND (*FlutterPlatformViewFactory)( | ||
const FlutterPlatformViewCreationParameters*); | ||
|
||
typedef struct { | ||
size_t struct_size; | ||
FlutterPlatformViewFactory factory; | ||
void* user_data; // Arbitrary user data supplied to the creation struct. | ||
} FlutterPlatformViewTypeEntry; | ||
|
||
FLUTTER_EXPORT void FlutterDesktopEngineRegisterPlatformViewType( | ||
FlutterDesktopEngineRef engine, | ||
const char* view_type_name, | ||
FlutterPlatformViewTypeEntry view_type); | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_WINDOWS_FLUTTER_WINDOWS_INTERNAL_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/shell/platform/windows/platform_view_manager.h" | ||
|
||
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h" | ||
|
||
namespace flutter { | ||
|
||
namespace { | ||
constexpr char kChannelName[] = "flutter/platform_views"; | ||
constexpr char kCreateMethod[] = "create"; | ||
constexpr char kFocusMethod[] = "focus"; | ||
constexpr char kViewTypeParameter[] = "viewType"; | ||
constexpr char kIdParameter[] = "id"; | ||
constexpr char kDirectionParameter[] = "direction"; | ||
constexpr char kFocusParameter[] = "focus"; | ||
} // namespace | ||
|
||
PlatformViewManager::PlatformViewManager(BinaryMessenger* binary_messenger) | ||
: channel_(std::make_unique<MethodChannel<EncodableValue>>( | ||
binary_messenger, | ||
kChannelName, | ||
&StandardMethodCodec::GetInstance())) { | ||
channel_->SetMethodCallHandler( | ||
[this](const MethodCall<EncodableValue>& call, | ||
std::unique_ptr<MethodResult<EncodableValue>> result) { | ||
const auto& args = std::get<EncodableMap>(*call.arguments()); | ||
if (call.method_name() == kCreateMethod) { | ||
const auto& type_itr = args.find(EncodableValue(kViewTypeParameter)); | ||
const auto& id_itr = args.find(EncodableValue(kIdParameter)); | ||
if (type_itr == args.end()) { | ||
result->Error("AddPlatformView", "Parameter viewType is required"); | ||
return; | ||
} | ||
if (id_itr == args.end()) { | ||
result->Error("AddPlatformView", "Parameter id is required"); | ||
return; | ||
} | ||
const auto& type = std::get<std::string>(type_itr->second); | ||
const auto& id = std::get<std::int32_t>(id_itr->second); | ||
if (AddPlatformView(id, type)) { | ||
result->Success(); | ||
} else { | ||
result->Error("AddPlatformView", "Failed to add platform view"); | ||
} | ||
return; | ||
} else if (call.method_name() == kFocusMethod) { | ||
const auto& id_itr = args.find(EncodableValue(kIdParameter)); | ||
const auto& direction_itr = | ||
args.find(EncodableValue(kDirectionParameter)); | ||
const auto& focus_itr = args.find(EncodableValue(kFocusParameter)); | ||
if (id_itr == args.end()) { | ||
result->Error("FocusPlatformView", "Parameter id is required"); | ||
return; | ||
} | ||
if (direction_itr == args.end()) { | ||
result->Error("FocusPlatformView", | ||
"Parameter direction is required"); | ||
return; | ||
} | ||
if (focus_itr == args.end()) { | ||
result->Error("FocusPlatformView", "Parameter focus is required"); | ||
return; | ||
} | ||
const auto& id = std::get<std::int32_t>(id_itr->second); | ||
const auto& direction = std::get<std::int32_t>(direction_itr->second); | ||
const auto& focus = std::get<bool>(focus_itr->second); | ||
if (FocusPlatformView( | ||
id, static_cast<FocusChangeDirection>(direction), focus)) { | ||
result->Success(); | ||
} else { | ||
result->Error("FocusPlatformView", "Failed to focus platform view"); | ||
} | ||
return; | ||
} | ||
result->NotImplemented(); | ||
}); | ||
loic-sharma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
PlatformViewManager::~PlatformViewManager() {} | ||
|
||
} // namespace flutter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a permalink here. The line number will be wrong as the code continues to evolve