fuchsia: Fix occlusion_hint handling (#26208)
diff --git a/shell/platform/fuchsia/flutter/platform_view.cc b/shell/platform/fuchsia/flutter/platform_view.cc
index 5061240..7fe2e22 100644
--- a/shell/platform/fuchsia/flutter/platform_view.cc
+++ b/shell/platform/fuchsia/flutter/platform_view.cc
@@ -1011,7 +1011,7 @@
}
SkRect view_occlusion_hint_raw = SkRect::MakeEmpty();
- auto view_occlusion_hint = args.FindMember("");
+ auto view_occlusion_hint = args.FindMember("viewOcclusionHintLTRB");
if (view_occlusion_hint != args.MemberEnd()) {
if (view_occlusion_hint->value.IsArray()) {
const auto& view_occlusion_hint_array =
diff --git a/shell/platform/fuchsia/flutter/platform_view_unittest.cc b/shell/platform/fuchsia/flutter/platform_view_unittest.cc
index 63cdec2..64b8e31 100644
--- a/shell/platform/fuchsia/flutter/platform_view_unittest.cc
+++ b/shell/platform/fuchsia/flutter/platform_view_unittest.cc
@@ -651,14 +651,17 @@
flutter::TaskRunners task_runners =
flutter::TaskRunners("test_runners", nullptr, nullptr, nullptr, nullptr);
- // Test wireframe callback function. If the message sent to the platform
- // view was properly handled and parsed, this function should be called,
- // setting |wireframe_enabled| to true.
- bool update_view_called = false;
- auto UpdateViewCallback = [&update_view_called](
+ std::optional<SkRect> occlusion_hint_for_test;
+ std::optional<bool> hit_testable_for_test;
+ std::optional<bool> focusable_for_test;
+ auto UpdateViewCallback = [&occlusion_hint_for_test, &hit_testable_for_test,
+ &focusable_for_test](
int64_t view_id, SkRect occlusion_hint,
- bool hit_testable,
- bool focusable) { update_view_called = true; };
+ bool hit_testable, bool focusable) {
+ occlusion_hint_for_test = occlusion_hint;
+ hit_testable_for_test = hit_testable;
+ focusable_for_test = focusable;
+ };
flutter_runner::PlatformView platform_view =
PlatformViewBuilder(delegate, std::move(task_runners),
@@ -671,8 +674,8 @@
auto base_view = static_cast<flutter::PlatformView*>(&platform_view);
EXPECT_TRUE(base_view);
- // JSON for the message to be passed into the PlatformView.
- const uint8_t txt[] =
+ // Send a basic message.
+ const uint8_t json[] =
"{"
" \"method\":\"View.update\","
" \"args\": {"
@@ -681,16 +684,81 @@
" \"focusable\":true"
" }"
"}";
-
std::unique_ptr<flutter::PlatformMessage> message =
std::make_unique<flutter::PlatformMessage>(
- "flutter/platform_views", fml::MallocMapping::Copy(txt, sizeof(txt)),
+ "flutter/platform_views",
+ fml::MallocMapping::Copy(json, sizeof(json)),
fml::RefPtr<flutter::PlatformMessageResponse>());
base_view->HandlePlatformMessage(std::move(message));
RunLoopUntilIdle();
+ ASSERT_TRUE(occlusion_hint_for_test.has_value());
+ ASSERT_TRUE(hit_testable_for_test.has_value());
+ ASSERT_TRUE(focusable_for_test.has_value());
+ EXPECT_EQ(occlusion_hint_for_test.value(), SkRect::MakeEmpty());
+ EXPECT_EQ(hit_testable_for_test.value(), true);
+ EXPECT_EQ(focusable_for_test.value(), true);
- EXPECT_TRUE(update_view_called);
+ // Reset for the next message.
+ occlusion_hint_for_test.reset();
+ hit_testable_for_test.reset();
+ focusable_for_test.reset();
+
+ // Send another basic message.
+ const uint8_t json_false[] =
+ "{"
+ " \"method\":\"View.update\","
+ " \"args\": {"
+ " \"viewId\":42,"
+ " \"hitTestable\":false,"
+ " \"focusable\":false"
+ " }"
+ "}";
+ std::unique_ptr<flutter::PlatformMessage> message_false =
+ std::make_unique<flutter::PlatformMessage>(
+ "flutter/platform_views",
+ fml::MallocMapping::Copy(json_false, sizeof(json_false)),
+ fml::RefPtr<flutter::PlatformMessageResponse>());
+ base_view->HandlePlatformMessage(std::move(message_false));
+ RunLoopUntilIdle();
+ ASSERT_TRUE(occlusion_hint_for_test.has_value());
+ ASSERT_TRUE(hit_testable_for_test.has_value());
+ ASSERT_TRUE(focusable_for_test.has_value());
+ EXPECT_EQ(occlusion_hint_for_test.value(), SkRect::MakeEmpty());
+ EXPECT_EQ(hit_testable_for_test.value(), false);
+ EXPECT_EQ(focusable_for_test.value(), false);
+
+ // Reset for the next message.
+ occlusion_hint_for_test.reset();
+ hit_testable_for_test.reset();
+ focusable_for_test.reset();
+
+ // Send a message including an occlusion hint.
+ const uint8_t json_occlusion_hint[] =
+ "{"
+ " \"method\":\"View.update\","
+ " \"args\": {"
+ " \"viewId\":42,"
+ " \"hitTestable\":true,"
+ " \"focusable\":true,"
+ " \"viewOcclusionHintLTRB\":[0.1,0.2,0.3,0.4]"
+ " }"
+ "}";
+ std::unique_ptr<flutter::PlatformMessage> message_occlusion_hint =
+ std::make_unique<flutter::PlatformMessage>(
+ "flutter/platform_views",
+ fml::MallocMapping::Copy(json_occlusion_hint,
+ sizeof(json_occlusion_hint)),
+ fml::RefPtr<flutter::PlatformMessageResponse>());
+ base_view->HandlePlatformMessage(std::move(message_occlusion_hint));
+ RunLoopUntilIdle();
+ ASSERT_TRUE(occlusion_hint_for_test.has_value());
+ ASSERT_TRUE(hit_testable_for_test.has_value());
+ ASSERT_TRUE(focusable_for_test.has_value());
+ EXPECT_EQ(occlusion_hint_for_test.value(),
+ SkRect::MakeLTRB(0.1, 0.2, 0.3, 0.4));
+ EXPECT_EQ(hit_testable_for_test.value(), true);
+ EXPECT_EQ(focusable_for_test.value(), true);
}
// This test makes sure that the PlatformView forwards messages on the