code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_MANAGEMENT_SURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_MANAGEMENT_SURFACE_H_ #include "base/memory/scoped_refptr.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space.h" namespace ui { class WaylandConnection; // TODO(b/237094484): merge into wayland_surface.h along with // color_space_creator zcr_color_mangement_surface_v1 class WaylandZcrColorManagementSurface { public: explicit WaylandZcrColorManagementSurface( struct zcr_color_management_surface_v1* management_surface, WaylandConnection* connection); WaylandZcrColorManagementSurface(const WaylandZcrColorManagementSurface&) = delete; WaylandZcrColorManagementSurface& operator=( const WaylandZcrColorManagementSurface&) = delete; ~WaylandZcrColorManagementSurface(); void SetDefaultColorSpace(); void SetColorSpace( scoped_refptr<WaylandZcrColorSpace> wayland_zcr_color_space); private: // zcr_color_management_surface_v1_listener static void OnPreferredColorSpace(void* data, struct zcr_color_management_surface_v1* cms, struct wl_output* output); wl::Object<zcr_color_management_surface_v1> zcr_color_management_surface_; const raw_ptr<WaylandConnection> connection_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_MANAGEMENT_SURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_color_management_surface.h
C++
unknown
1,638
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zcr_color_manager.h" #include <chrome-color-management-client-protocol.h> #include <memory> #include "base/functional/bind.h" #include "base/logging.h" #include "base/memory/scoped_refptr.h" #include "third_party/skia/include/core/SkColorSpace.h" #include "ui/base/wayland/color_manager_util.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_output_manager.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space_creator.h" #include "ui/ozone/platform/wayland/wayland_utils.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; constexpr uint32_t kMaxVersion = 4; } // namespace // static constexpr char WaylandZcrColorManager::kInterfaceName[]; // static void WaylandZcrColorManager::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->zcr_color_manager_ || !wl::CanBind(interface, version, kMinVersion, kMaxVersion)) { return; } auto color_manager = wl::Bind<struct zcr_color_manager_v1>( registry, name, std::min(version, kMaxVersion)); if (!color_manager) { LOG(ERROR) << "Failed to bind zcr_color_manager_v1"; return; } connection->zcr_color_manager_ = std::make_unique<WaylandZcrColorManager>( color_manager.release(), connection); if (connection->wayland_output_manager()) connection->wayland_output_manager()->InitializeAllColorManagementOutputs(); } WaylandZcrColorManager::WaylandZcrColorManager( zcr_color_manager_v1* zcr_color_manager, WaylandConnection* connection) : zcr_color_manager_(zcr_color_manager), connection_(connection) {} WaylandZcrColorManager::~WaylandZcrColorManager() = default; void WaylandZcrColorManager::OnColorSpaceCreated( gfx::ColorSpace color_space, scoped_refptr<WaylandZcrColorSpace> zcr_color_space, absl::optional<uint32_t> error) { if (error.has_value()) { // TODO(mrfemi): Store in a creation failed map. LOG(ERROR) << "Failed to create WaylandZcrColorSpace"; return; } saved_color_spaces_.Put(color_space, std::move(zcr_color_space)); pending_color_spaces_.erase(color_space); } wl::Object<zcr_color_space_creator_v1> WaylandZcrColorManager::CreateZcrColorSpaceCreator( const gfx::ColorSpace& color_space) { auto eotf = wayland::ToColorManagerEOTF(color_space); if (eotf == ZCR_COLOR_MANAGER_V1_EOTF_NAMES_UNKNOWN) { LOG(ERROR) << "Attempt to create color space from" << " unsupported or invalid TransferID: " << color_space.ToString() << "."; if (zcr_color_manager_v1_get_version(zcr_color_manager_.get()) < ZCR_COLOR_SPACE_V1_COMPLETE_NAMES_SINCE_VERSION) { return wl::Object<zcr_color_space_creator_v1>( zcr_color_manager_v1_create_color_space_from_names( zcr_color_manager_.get(), ZCR_COLOR_MANAGER_V1_EOTF_NAMES_SRGB, ZCR_COLOR_MANAGER_V1_CHROMATICITY_NAMES_BT709, ZCR_COLOR_MANAGER_V1_WHITEPOINT_NAMES_D65)); } return wl::Object<zcr_color_space_creator_v1>( zcr_color_manager_v1_create_color_space_from_complete_names( zcr_color_manager_.get(), ZCR_COLOR_MANAGER_V1_EOTF_NAMES_SRGB, ZCR_COLOR_MANAGER_V1_CHROMATICITY_NAMES_BT709, ZCR_COLOR_MANAGER_V1_WHITEPOINT_NAMES_D65, ZCR_COLOR_MANAGER_V1_MATRIX_NAMES_RGB, ZCR_COLOR_MANAGER_V1_RANGE_NAMES_FULL)); } auto matrix = wayland::ToColorManagerMatrix(color_space.GetMatrixID()); if (matrix == ZCR_COLOR_MANAGER_V1_MATRIX_NAMES_UNKNOWN) { LOG(WARNING) << "Attempt to create color space from" << " unsupported or invalid MatrixID: " << color_space.ToString(); matrix = ZCR_COLOR_MANAGER_V1_MATRIX_NAMES_RGB; } auto range = wayland::ToColorManagerRange(color_space.GetRangeID()); if (range == ZCR_COLOR_MANAGER_V1_RANGE_NAMES_UNKNOWN) { LOG(WARNING) << "Attempt to create color space from" << " unsupported or invalid RangeID: " << color_space.ToString(); range = ZCR_COLOR_MANAGER_V1_RANGE_NAMES_FULL; } auto chromaticity = wayland::ToColorManagerChromaticity(color_space.GetPrimaryID()); if (chromaticity != ZCR_COLOR_MANAGER_V1_CHROMATICITY_NAMES_UNKNOWN) { if (zcr_color_manager_v1_get_version(zcr_color_manager_.get()) < ZCR_COLOR_SPACE_V1_COMPLETE_NAMES_SINCE_VERSION) { return wl::Object<zcr_color_space_creator_v1>( zcr_color_manager_v1_create_color_space_from_names( zcr_color_manager_.get(), eotf, chromaticity, ZCR_COLOR_MANAGER_V1_WHITEPOINT_NAMES_D65)); } return wl::Object<zcr_color_space_creator_v1>( zcr_color_manager_v1_create_color_space_from_complete_names( zcr_color_manager_.get(), eotf, chromaticity, ZCR_COLOR_MANAGER_V1_WHITEPOINT_NAMES_D65, matrix, range)); } auto primaries = color_space.GetPrimaries(); if (zcr_color_manager_v1_get_version(zcr_color_manager_.get()) < ZCR_COLOR_SPACE_V1_COMPLETE_PARAMS_SINCE_VERSION) { return wl::Object<zcr_color_space_creator_v1>( zcr_color_manager_v1_create_color_space_from_params( zcr_color_manager_.get(), eotf, FLOAT_TO_PARAM(primaries.fRX), FLOAT_TO_PARAM(primaries.fRY), FLOAT_TO_PARAM(primaries.fGX), FLOAT_TO_PARAM(primaries.fGY), FLOAT_TO_PARAM(primaries.fBX), FLOAT_TO_PARAM(primaries.fBY), FLOAT_TO_PARAM(primaries.fWX), FLOAT_TO_PARAM(primaries.fWY))); } return wl::Object<zcr_color_space_creator_v1>( zcr_color_manager_v1_create_color_space_from_complete_params( zcr_color_manager_.get(), eotf, matrix, range, FLOAT_TO_PARAM(primaries.fRX), FLOAT_TO_PARAM(primaries.fRY), FLOAT_TO_PARAM(primaries.fGX), FLOAT_TO_PARAM(primaries.fGY), FLOAT_TO_PARAM(primaries.fBX), FLOAT_TO_PARAM(primaries.fBY), FLOAT_TO_PARAM(primaries.fWX), FLOAT_TO_PARAM(primaries.fWY))); } scoped_refptr<WaylandZcrColorSpace> WaylandZcrColorManager::GetColorSpace( const gfx::ColorSpace& color_space) { auto it = saved_color_spaces_.Get(color_space); if (it != saved_color_spaces_.end()) { return it->second; } if (pending_color_spaces_.count(color_space) != 0) return nullptr; pending_color_spaces_[color_space] = std::make_unique<WaylandZcrColorSpaceCreator>( CreateZcrColorSpaceCreator(color_space), base::BindOnce(&WaylandZcrColorManager::OnColorSpaceCreated, base::Unretained(this), color_space)); return nullptr; } wl::Object<zcr_color_management_output_v1> WaylandZcrColorManager::CreateColorManagementOutput(wl_output* output) { return wl::Object<zcr_color_management_output_v1>( zcr_color_manager_v1_get_color_management_output(zcr_color_manager_.get(), output)); } wl::Object<zcr_color_management_surface_v1> WaylandZcrColorManager::CreateColorManagementSurface(wl_surface* surface) { return wl::Object<zcr_color_management_surface_v1>( zcr_color_manager_v1_get_color_management_surface( zcr_color_manager_.get(), surface)); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_color_manager.cc
C++
unknown
7,826
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_MANAGER_H_ #include <chrome-color-management-client-protocol.h> #include <memory> #include "base/containers/flat_map.h" #include "base/containers/lru_cache.h" #include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/common/wayland_util.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space_creator.h" struct zcr_color_manager_v1; namespace ui { class WaylandConnection; // Wrapper around |zcr_color_manager_v1| Wayland factory class WaylandZcrColorManager : public wl::GlobalObjectRegistrar<WaylandZcrColorManager> { public: static constexpr char kInterfaceName[] = "zcr_color_manager_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); WaylandZcrColorManager(zcr_color_manager_v1* zcr_color_manager_, WaylandConnection* connection); WaylandZcrColorManager(const WaylandZcrColorManager&) = delete; WaylandZcrColorManager& operator=(const WaylandZcrColorManager&) = delete; ~WaylandZcrColorManager(); wl::Object<zcr_color_management_output_v1> CreateColorManagementOutput( wl_output* output); wl::Object<zcr_color_management_surface_v1> CreateColorManagementSurface( wl_surface* surface); scoped_refptr<WaylandZcrColorSpace> GetColorSpace( const gfx::ColorSpace& color_space); private: void OnColorSpaceCreated(gfx::ColorSpace color_space, scoped_refptr<WaylandZcrColorSpace> zcr_color_space, absl::optional<uint32_t> error); wl::Object<zcr_color_space_creator_v1> CreateZcrColorSpaceCreator( const gfx::ColorSpace& color_space); // in flight base::flat_map<gfx::ColorSpace, std::unique_ptr<WaylandZcrColorSpaceCreator>> pending_color_spaces_; // cache base::LRUCache<gfx::ColorSpace, scoped_refptr<WaylandZcrColorSpace>> saved_color_spaces_{100}; // Holds pointer to the zcr_color_manager_v1 Wayland factory. const wl::Object<zcr_color_manager_v1> zcr_color_manager_; // Non-owned. const raw_ptr<WaylandConnection> connection_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_color_manager.h
C++
unknown
2,885
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <chrome-color-management-client-protocol.h> #include "base/check.h" #include "base/files/file_util.h" #include "base/memory/raw_ptr.h" #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/display/test/test_screen.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_output.h" #include "ui/ozone/platform/wayland/host/wayland_output_manager.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_management_output.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_manager.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/mock_wayland_zcr_color_manager.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_output.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_surface.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_space.h" #include "ui/ozone/platform/wayland/test/wayland_test.h" using ::testing::Values; namespace ui { namespace { base::ScopedFD MakeFD() { base::FilePath temp_path; EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); auto file = base::File(temp_path, base::File::FLAG_READ | base::File::FLAG_WRITE | base::File::FLAG_CREATE_ALWAYS); return base::ScopedFD(file.TakePlatformFile()); } class WaylandZcrColorManagerTest : public WaylandTest { public: WaylandZcrColorManagerTest() = default; WaylandZcrColorManagerTest(const WaylandZcrColorManagerTest&) = delete; WaylandZcrColorManagerTest& operator=(const WaylandZcrColorManagerTest&) = delete; ~WaylandZcrColorManagerTest() override = default; void SetUp() override { WaylandTest::SetUp(); ASSERT_TRUE(connection_->zcr_color_manager()); } WaylandWindow* window() { return window_.get(); } }; } // namespace TEST_P(WaylandZcrColorManagerTest, CreateColorManagementOutput) { // Set default values for the output. PostToServerAndWait([](wl::TestWaylandServerThread* server) { wl::TestOutput* output = server->output(); output->SetPhysicalAndLogicalBounds({800, 600}); output->Flush(); }); auto* output_manager = connection_->wayland_output_manager(); WaylandOutput* wayland_output = output_manager->GetPrimaryOutput(); ASSERT_TRUE(wayland_output); EXPECT_TRUE(wayland_output->IsReady()); auto* color_management_output = wayland_output->color_management_output(); ASSERT_TRUE(color_management_output); // Set HDR10 on server output, notify color management output with event. PostToServerAndWait([&](wl::TestWaylandServerThread* server) { auto params_vector = server->zcr_color_manager_v1()->color_management_outputs(); for (auto* mock_params : params_vector) { mock_params->SetGfxColorSpace(gfx::ColorSpace::CreateHDR10()); zcr_color_management_output_v1_send_color_space_changed( mock_params->resource()); } }); // Allow output to respond to server event, then send color space events. PostToServerAndWait([&](wl::TestWaylandServerThread* server) { auto params_vector = server->zcr_color_manager_v1()->color_management_outputs(); for (auto* mock_params : params_vector) { auto* zcr_color_space = mock_params->GetZcrColorSpace(); // assert that the color space is the same as the one in output. EXPECT_EQ(zcr_color_space->GetGfxColorSpace(), gfx::ColorSpace::CreateHDR10()); // send HDR10 over wayland. zcr_color_space_v1_send_names(zcr_color_space->resource(), 5, 5, 3); zcr_color_space_v1_send_done(zcr_color_space->resource()); } }); // Check that the received color space is equal to the one on server output. auto* gfx_color_space = color_management_output->gfx_color_space(); gfx_color_space->ToString(); EXPECT_EQ(*gfx_color_space, gfx::ColorSpace::CreateHDR10()); } TEST_P(WaylandZcrColorManagerTest, CreateColorManagementSurface) { auto* surface = window_.get()->root_surface(); PostToServerAndWait([&](wl::TestWaylandServerThread* server) { auto params_vector = server->zcr_color_manager_v1()->color_management_surfaces(); for (auto* mock_params : params_vector) { EXPECT_EQ(gfx::ColorSpace::CreateSRGB(), mock_params->GetGfxColorSpace()); } }); // Updated buffer handle needed for ApplyPendingState() to set color_space EXPECT_TRUE(connection_->buffer_manager_host()); auto interface_ptr = connection_->buffer_manager_host()->BindInterface(); buffer_manager_gpu_->Initialize(std::move(interface_ptr), {}, false, true, false, true, 0); // Setup wl_buffers. constexpr uint32_t buffer_id = 1; gfx::Size buffer_size(1024, 768); auto length = 1024 * 768 * 4; buffer_manager_gpu_->CreateShmBasedBuffer(MakeFD(), length, buffer_size, buffer_id); base::RunLoop().RunUntilIdle(); // preload color_space in color manager cache, since first call with a // new color_space always returns null. connection_->zcr_color_manager()->GetColorSpace( gfx::ColorSpace::CreateHDR10()); connection_->RoundTripQueue(); surface->set_color_space(gfx::ColorSpace::CreateHDR10()); surface->AttachBuffer(connection_->buffer_manager_host()->EnsureBufferHandle( surface, buffer_id)); surface->ApplyPendingState(); // Assert that surface on server has correct color_space. PostToServerAndWait([&](wl::TestWaylandServerThread* server) { auto params_vector = server->zcr_color_manager_v1()->color_management_surfaces(); EXPECT_EQ(gfx::ColorSpace::CreateHDR10(), params_vector.front()->GetGfxColorSpace()); }); } TEST_P(WaylandZcrColorManagerTest, DoNotSetInvaliColorSpace) { auto* surface = window_.get()->root_surface(); PostToServerAndWait([&](wl::TestWaylandServerThread* server) { auto params_vector = server->zcr_color_manager_v1()->color_management_surfaces(); for (auto* mock_params : params_vector) { EXPECT_EQ(gfx::ColorSpace::CreateSRGB(), mock_params->GetGfxColorSpace()); } }); // Updated buffer handle needed for ApplyPendingState() to set color_space EXPECT_TRUE(connection_->buffer_manager_host()); auto interface_ptr = connection_->buffer_manager_host()->BindInterface(); buffer_manager_gpu_->Initialize(std::move(interface_ptr), {}, false, true, false, true, 0); // Setup wl_buffers. constexpr uint32_t buffer_id = 1; gfx::Size buffer_size(1024, 768); auto length = 1024 * 768 * 4; buffer_manager_gpu_->CreateShmBasedBuffer(MakeFD(), length, buffer_size, buffer_id); base::RunLoop().RunUntilIdle(); gfx::ColorSpace invalid_space = gfx::ColorSpace(gfx::ColorSpace::PrimaryID::INVALID, gfx::ColorSpace::TransferID::INVALID); // Attempt to set an invalid color space on the surface and expect that the // original default color space remains unchanged on the surface. connection_->zcr_color_manager()->GetColorSpace(invalid_space); connection_->RoundTripQueue(); surface->set_color_space(invalid_space); surface->AttachBuffer(connection_->buffer_manager_host()->EnsureBufferHandle( surface, buffer_id)); surface->ApplyPendingState(); // Assert that surface on server has correct color_space. PostToServerAndWait([&](wl::TestWaylandServerThread* server) { auto params_vector = server->zcr_color_manager_v1()->color_management_surfaces(); EXPECT_EQ(gfx::ColorSpace::CreateSRGB(), params_vector.front()->GetGfxColorSpace()); }); } INSTANTIATE_TEST_SUITE_P(XdgVersionStableTest, WaylandZcrColorManagerTest, Values(wl::ServerConfig{})); } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_color_manager_unittest.cc
C++
unknown
8,300
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space.h" #include <chrome-color-management-client-protocol.h> #include <cstdint> #include "base/logging.h" #include "base/notreached.h" #include "base/strings/stringprintf.h" #include "skia/ext/skcolorspace_trfn.h" #include "ui/base/wayland/color_manager_util.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/wayland_utils.h" namespace ui { WaylandZcrColorSpace::WaylandZcrColorSpace( struct zcr_color_space_v1* color_space) : zcr_color_space_(color_space) { DCHECK(color_space); static const zcr_color_space_v1_listener listener = { &WaylandZcrColorSpace::OnIccFile, &WaylandZcrColorSpace::OnNames, &WaylandZcrColorSpace::OnParams, &WaylandZcrColorSpace::OnDone, &WaylandZcrColorSpace::OnCompleteNames, &WaylandZcrColorSpace::OnCompleteParams, }; zcr_color_space_v1_add_listener(zcr_color_space_.get(), &listener, this); zcr_color_space_v1_get_information(zcr_color_space_.get()); } WaylandZcrColorSpace::~WaylandZcrColorSpace() = default; // static void WaylandZcrColorSpace::OnIccFile(void* data, struct zcr_color_space_v1* cs, int32_t icc, uint32_t icc_size) { WaylandZcrColorSpace* zcr_color_space = static_cast<WaylandZcrColorSpace*>(data); DCHECK(zcr_color_space); // TODO(b/192562912): construct a color space from an icc file. } // static deprecated void WaylandZcrColorSpace::OnNames(void* data, struct zcr_color_space_v1* cs, uint32_t eotf, uint32_t chromaticity, uint32_t whitepoint) { OnCompleteNames(data, cs, eotf, chromaticity, whitepoint, ZCR_COLOR_MANAGER_V1_MATRIX_NAMES_RGB, ZCR_COLOR_MANAGER_V1_RANGE_NAMES_FULL); } // static void WaylandZcrColorSpace::OnCompleteNames(void* data, struct zcr_color_space_v1* cs, uint32_t eotf, uint32_t chromaticity, uint32_t whitepoint, uint32_t matrix, uint32_t range) { WaylandZcrColorSpace* zcr_color_space = static_cast<WaylandZcrColorSpace*>(data); DCHECK(zcr_color_space); auto primaryID = ui::wayland::kChromaticityMap.contains(chromaticity) ? ui::wayland::kChromaticityMap.at(chromaticity) : gfx::ColorSpace::PrimaryID::INVALID; auto matrixID = ui::wayland::kMatrixMap.contains(matrix) ? ui::wayland::kMatrixMap.at(matrix) : gfx::ColorSpace::MatrixID::INVALID; auto rangeID = ui::wayland::kRangeMap.contains(range) ? ui::wayland::kRangeMap.at(range) : gfx::ColorSpace::RangeID::INVALID; auto transferID = ui::wayland::kEotfMap.contains(eotf) ? ui::wayland::kEotfMap.at(eotf) : gfx::ColorSpace::TransferID::INVALID; if (transferID == gfx::ColorSpace::TransferID::INVALID && wayland::kHDRTransferMap.contains(eotf)) { auto transfer_fn = ui::wayland::kHDRTransferMap.at(eotf); zcr_color_space ->gathered_information[static_cast<uint8_t>(InformationType::kNames)] = gfx::ColorSpace(primaryID, gfx::ColorSpace::TransferID::CUSTOM_HDR, matrixID, rangeID, nullptr, &transfer_fn); return; } zcr_color_space ->gathered_information[static_cast<uint8_t>(InformationType::kNames)] = gfx::ColorSpace(primaryID, transferID, matrixID, rangeID); } // static deprecated void WaylandZcrColorSpace::OnParams(void* data, struct zcr_color_space_v1* cs, uint32_t eotf, uint32_t primary_r_x, uint32_t primary_r_y, uint32_t primary_g_x, uint32_t primary_g_y, uint32_t primary_b_x, uint32_t primary_b_y, uint32_t whitepoint_x, uint32_t whitepoint_y) { OnCompleteParams(data, cs, eotf, ZCR_COLOR_MANAGER_V1_MATRIX_NAMES_RGB, ZCR_COLOR_MANAGER_V1_RANGE_NAMES_FULL, primary_r_x, primary_r_y, primary_g_x, primary_g_y, primary_b_x, primary_b_y, whitepoint_x, whitepoint_y); } // static void WaylandZcrColorSpace::OnCompleteParams(void* data, struct zcr_color_space_v1* cs, uint32_t eotf, uint32_t matrix, uint32_t range, uint32_t primary_r_x, uint32_t primary_r_y, uint32_t primary_g_x, uint32_t primary_g_y, uint32_t primary_b_x, uint32_t primary_b_y, uint32_t whitepoint_x, uint32_t whitepoint_y) { WaylandZcrColorSpace* zcr_color_space = static_cast<WaylandZcrColorSpace*>(data); DCHECK(zcr_color_space); SkColorSpacePrimaries primaries = { PARAM_TO_FLOAT(primary_r_x), PARAM_TO_FLOAT(primary_r_y), PARAM_TO_FLOAT(primary_g_x), PARAM_TO_FLOAT(primary_g_y), PARAM_TO_FLOAT(primary_b_x), PARAM_TO_FLOAT(primary_b_y), PARAM_TO_FLOAT(whitepoint_x), PARAM_TO_FLOAT(whitepoint_y)}; skcms_Matrix3x3 xyzd50 = {}; if (!primaries.toXYZD50(&xyzd50)) { DLOG(ERROR) << base::StringPrintf( "Unable to translate color space primaries to XYZD50: " "{%f, %f, %f, %f, %f, %f, %f, %f}", primaries.fRX, primaries.fRY, primaries.fGX, primaries.fGY, primaries.fBX, primaries.fBY, primaries.fWX, primaries.fWY); return; } auto matrixID = ui::wayland::kMatrixMap.contains(matrix) ? ui::wayland::kMatrixMap.at(matrix) : gfx::ColorSpace::MatrixID::INVALID; auto rangeID = ui::wayland::kRangeMap.contains(range) ? ui::wayland::kRangeMap.at(range) : gfx::ColorSpace::RangeID::INVALID; auto transferID = ui::wayland::kEotfMap.contains(eotf) ? ui::wayland::kEotfMap.at(eotf) : gfx::ColorSpace::TransferID::INVALID; if (transferID == gfx::ColorSpace::TransferID::INVALID && ui::wayland::kHDRTransferMap.contains(eotf)) { auto transfer_fn = ui::wayland::kHDRTransferMap.at(eotf); zcr_color_space ->gathered_information[static_cast<uint8_t>(InformationType::kParams)] = gfx::ColorSpace(gfx::ColorSpace::PrimaryID::CUSTOM, gfx::ColorSpace::TransferID::CUSTOM_HDR, matrixID, rangeID, &xyzd50, &transfer_fn); return; } zcr_color_space ->gathered_information[static_cast<uint8_t>(InformationType::kParams)] = gfx::ColorSpace::CreateCustom(xyzd50, transferID); } gfx::ColorSpace WaylandZcrColorSpace::GetPriorityInformationType() { for (auto maybe_colorspace : gathered_information) { if (maybe_colorspace.has_value()) return maybe_colorspace.value(); } DLOG(ERROR) << "No color space information gathered"; return gfx::ColorSpace::CreateSRGB(); } // static void WaylandZcrColorSpace::OnDone(void* data, struct zcr_color_space_v1* cs) { WaylandZcrColorSpace* zcr_color_space = static_cast<WaylandZcrColorSpace*>(data); DCHECK(zcr_color_space); if (zcr_color_space->HasColorSpaceDoneCallback()) std::move(zcr_color_space->color_space_done_callback_) .Run(zcr_color_space->GetPriorityInformationType()); zcr_color_space->gathered_information.fill({}); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_color_space.cc
C++
unknown
8,578
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_SPACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_SPACE_H_ #include <array> #include <memory> #include <utility> #include "base/functional/callback.h" #include "base/memory/ref_counted.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace ui { class WaylandZcrColorSpace; // ZcrColorSpace is used to send color space information over wayland protocol. // its requests and events are specified in chrome-color-management.xml. // The ui::gfx::ColorSpace equivalent of ZcrColorSpace can be gotten with // gfx_color_space(). class WaylandZcrColorSpace : public base::RefCounted<WaylandZcrColorSpace> { public: using WaylandZcrColorSpaceDoneCallback = base::OnceCallback<void(const gfx::ColorSpace&)>; explicit WaylandZcrColorSpace(zcr_color_space_v1* color_space); WaylandZcrColorSpace(const WaylandZcrColorSpace&) = delete; WaylandZcrColorSpace& operator=(const WaylandZcrColorSpace&) = delete; zcr_color_space_v1* zcr_color_space() const { return zcr_color_space_.get(); } bool HasColorSpaceDoneCallback() const { return !color_space_done_callback_.is_null(); } void SetColorSpaceDoneCallback(WaylandZcrColorSpaceDoneCallback callback) { color_space_done_callback_ = std::move(callback); } private: friend class base::RefCounted<WaylandZcrColorSpace>; ~WaylandZcrColorSpace(); // InformationType is an enumeration of the possible events following a // get_information request in order of their priority (0 is highest). enum class InformationType : uint8_t { kCompleteNames = 0, kCompleteParams = 1, kNames = 2, kIccFile = 3, kParams = 4, kMaxValue = kParams, }; gfx::ColorSpace GetPriorityInformationType(); // zcr_color_space_v1_listener static void OnIccFile(void* data, struct zcr_color_space_v1* cs, int32_t icc, uint32_t icc_size); static void OnNames(void* data, struct zcr_color_space_v1* cs, uint32_t eotf, uint32_t chromaticity, uint32_t whitepoint); static void OnParams(void* data, struct zcr_color_space_v1* cs, uint32_t eotf, uint32_t primary_r_x, uint32_t primary_r_y, uint32_t primary_g_x, uint32_t primary_g_y, uint32_t primary_b_x, uint32_t primary_b_y, uint32_t whitepoint_x, uint32_t whitepoint_y); static void OnCompleteNames(void* data, struct zcr_color_space_v1* cs, uint32_t eotf, uint32_t chromaticity, uint32_t whitepoint, uint32_t matrix, uint32_t range); static void OnCompleteParams(void* data, struct zcr_color_space_v1* cs, uint32_t eotf, uint32_t matrix, uint32_t range, uint32_t primary_r_x, uint32_t primary_r_y, uint32_t primary_g_x, uint32_t primary_g_y, uint32_t primary_b_x, uint32_t primary_b_y, uint32_t whitepoint_x, uint32_t whitepoint_y); static void OnDone(void* data, struct zcr_color_space_v1* cs); // Information events should store color space info at their enum index in // this array. Cleared on the OnDone event. Choosing the highest priority // InformationType available is simple with forward iteration. std::array<absl::optional<gfx::ColorSpace>, static_cast<uint8_t>(InformationType::kMaxValue) + 1> gathered_information; wl::Object<zcr_color_space_v1> zcr_color_space_; WaylandZcrColorSpaceDoneCallback color_space_done_callback_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_SPACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_color_space.h
C++
unknown
4,514
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space_creator.h" #include <chrome-color-management-client-protocol.h> #include <cstddef> #include <memory> #include "base/check.h" #include "base/memory/scoped_refptr.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space.h" namespace ui { WaylandZcrColorSpaceCreator::WaylandZcrColorSpaceCreator( wl::Object<zcr_color_space_creator_v1> color_space_creator, CreatorResultCallback on_creation) : zcr_color_space_creator_(std::move(color_space_creator)), on_creation_(std::move(on_creation)) { DCHECK(zcr_color_space_creator_); static const zcr_color_space_creator_v1_listener listener = { &WaylandZcrColorSpaceCreator::OnCreated, &WaylandZcrColorSpaceCreator::OnError, }; zcr_color_space_creator_v1_add_listener(zcr_color_space_creator_.get(), &listener, this); } WaylandZcrColorSpaceCreator::~WaylandZcrColorSpaceCreator() = default; // static void WaylandZcrColorSpaceCreator::OnCreated( void* data, struct zcr_color_space_creator_v1* css, struct zcr_color_space_v1* color_space) { WaylandZcrColorSpaceCreator* zcr_color_space_creator = static_cast<WaylandZcrColorSpaceCreator*>(data); DCHECK(zcr_color_space_creator); std::move(zcr_color_space_creator->on_creation_) .Run(base::MakeRefCounted<WaylandZcrColorSpace>(color_space), {}); } // static void WaylandZcrColorSpaceCreator::OnError( void* data, struct zcr_color_space_creator_v1* css, uint32_t error) { WaylandZcrColorSpaceCreator* zcr_color_space_creator = static_cast<WaylandZcrColorSpaceCreator*>(data); DCHECK(zcr_color_space_creator); std::move(zcr_color_space_creator->on_creation_).Run(nullptr, error); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_color_space_creator.cc
C++
unknown
1,976
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_SPACE_CREATOR_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_SPACE_CREATOR_H_ #include "base/functional/callback_forward.h" #include "base/memory/scoped_refptr.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_zcr_color_space.h" namespace ui { // WaylandZcrColorSpaceCreator is used to create a zcr_color_space_v1 object // that can be sent to exo over wayland protocol. class WaylandZcrColorSpaceCreator { public: using CreatorResultCallback = base::OnceCallback<void(scoped_refptr<WaylandZcrColorSpace>, absl::optional<uint32_t>)>; WaylandZcrColorSpaceCreator(wl::Object<zcr_color_space_creator_v1> creator, CreatorResultCallback on_creation); WaylandZcrColorSpaceCreator(const WaylandZcrColorSpaceCreator&) = delete; WaylandZcrColorSpaceCreator& operator=(const WaylandZcrColorSpaceCreator&) = delete; ~WaylandZcrColorSpaceCreator(); private: // zcr_color_space_creator_v1_listener static void OnCreated(void* data, struct zcr_color_space_creator_v1* css, struct zcr_color_space_v1* color_space); static void OnError(void* data, struct zcr_color_space_creator_v1* css, uint32_t error); wl::Object<zcr_color_space_creator_v1> zcr_color_space_creator_; CreatorResultCallback on_creation_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_COLOR_SPACE_CREATOR_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_color_space_creator.h
C++
unknown
1,849
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zcr_cursor_shapes.h" #include <cursor-shapes-unstable-v1-client-protocol.h> #include "base/check.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" #include "ui/gfx/native_widget_types.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_pointer.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; } using mojom::CursorType; // static constexpr char WaylandZcrCursorShapes::kInterfaceName[]; // static void WaylandZcrCursorShapes::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->zcr_cursor_shapes_ || !wl::CanBind(interface, version, kMinVersion, kMinVersion)) { return; } auto zcr_cursor_shapes = wl::Bind<zcr_cursor_shapes_v1>(registry, name, kMinVersion); if (!zcr_cursor_shapes) { LOG(ERROR) << "Failed to bind zcr_cursor_shapes_v1"; return; } connection->zcr_cursor_shapes_ = std::make_unique<WaylandZcrCursorShapes>( zcr_cursor_shapes.release(), connection); } WaylandZcrCursorShapes::WaylandZcrCursorShapes( zcr_cursor_shapes_v1* zcr_cursor_shapes, WaylandConnection* connection) : zcr_cursor_shapes_v1_(zcr_cursor_shapes), connection_(connection) { // |zcr_cursor_shapes_v1_| and |connection_| may be null in tests. } WaylandZcrCursorShapes::~WaylandZcrCursorShapes() = default; // static absl::optional<int32_t> WaylandZcrCursorShapes::ShapeFromType(CursorType type) { switch (type) { case CursorType::kNull: // kNull is an alias for kPointer. Fall through. case CursorType::kPointer: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_POINTER; case CursorType::kCross: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_CROSS; case CursorType::kHand: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_HAND; case CursorType::kIBeam: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_IBEAM; case CursorType::kWait: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_WAIT; case CursorType::kHelp: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_HELP; case CursorType::kEastResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_EAST_RESIZE; case CursorType::kNorthResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_RESIZE; case CursorType::kNorthEastResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_EAST_RESIZE; case CursorType::kNorthWestResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_WEST_RESIZE; case CursorType::kSouthResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_SOUTH_RESIZE; case CursorType::kSouthEastResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_SOUTH_EAST_RESIZE; case CursorType::kSouthWestResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_SOUTH_WEST_RESIZE; case CursorType::kWestResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_WEST_RESIZE; case CursorType::kNorthSouthResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_SOUTH_RESIZE; case CursorType::kEastWestResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_EAST_WEST_RESIZE; case CursorType::kNorthEastSouthWestResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_EAST_SOUTH_WEST_RESIZE; case CursorType::kNorthWestSouthEastResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_WEST_SOUTH_EAST_RESIZE; case CursorType::kColumnResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_COLUMN_RESIZE; case CursorType::kRowResize: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_ROW_RESIZE; case CursorType::kMiddlePanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_MIDDLE_PANNING; case CursorType::kEastPanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_EAST_PANNING; case CursorType::kNorthPanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_PANNING; case CursorType::kNorthEastPanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_EAST_PANNING; case CursorType::kNorthWestPanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NORTH_WEST_PANNING; case CursorType::kSouthPanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_SOUTH_PANNING; case CursorType::kSouthEastPanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_SOUTH_EAST_PANNING; case CursorType::kSouthWestPanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_SOUTH_WEST_PANNING; case CursorType::kWestPanning: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_WEST_PANNING; case CursorType::kMove: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_MOVE; case CursorType::kVerticalText: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_VERTICAL_TEXT; case CursorType::kCell: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_CELL; case CursorType::kContextMenu: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_CONTEXT_MENU; case CursorType::kAlias: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_ALIAS; case CursorType::kProgress: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_PROGRESS; case CursorType::kNoDrop: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NO_DROP; case CursorType::kCopy: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_COPY; case CursorType::kNone: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NONE; case CursorType::kNotAllowed: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_NOT_ALLOWED; case CursorType::kZoomIn: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_ZOOM_IN; case CursorType::kZoomOut: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_ZOOM_OUT; case CursorType::kGrab: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_GRAB; case CursorType::kGrabbing: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_GRABBING; case CursorType::kMiddlePanningVertical: case CursorType::kMiddlePanningHorizontal: case CursorType::kEastWestNoResize: case CursorType::kNorthEastSouthWestNoResize: case CursorType::kNorthSouthNoResize: case CursorType::kNorthWestSouthEastNoResize: // Not supported by this API. return absl::nullopt; case CursorType::kCustom: // Custom means a bitmap cursor, which can't use the shape API. return absl::nullopt; case CursorType::kDndNone: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_DND_NONE; case CursorType::kDndMove: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_DND_MOVE; case CursorType::kDndCopy: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_DND_COPY; case CursorType::kDndLink: return ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_DND_LINK; // NOTE: If you add a new cursor shape, please also update // UseDefaultCursorForType() in bitmap_cursor_factory_ozone.cc. } } void WaylandZcrCursorShapes::SetCursorShape(int32_t shape) { // Nothing to do if there's no pointer (mouse) connected. if (!connection_->seat()->pointer()) return; zcr_cursor_shapes_v1_set_cursor_shape( zcr_cursor_shapes_v1_.get(), connection_->seat()->pointer()->wl_object(), shape); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_cursor_shapes.cc
C++
unknown
7,855
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_CURSOR_SHAPES_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_CURSOR_SHAPES_H_ #include "base/memory/raw_ptr.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace ui { class WaylandConnection; // Wraps the zcr_cursor_shapes interface for Wayland (exo) server-side cursor // support. Exists to support Lacros, which uses server-side cursors for // consistency with ARC++ and for accessibility support. class WaylandZcrCursorShapes : public wl::GlobalObjectRegistrar<WaylandZcrCursorShapes> { public: static constexpr char kInterfaceName[] = "zcr_cursor_shapes_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); WaylandZcrCursorShapes(zcr_cursor_shapes_v1* zcr_cursor_shapes, WaylandConnection* connection); WaylandZcrCursorShapes(const WaylandZcrCursorShapes&) = delete; WaylandZcrCursorShapes& operator=(const WaylandZcrCursorShapes&) = delete; virtual ~WaylandZcrCursorShapes(); // Returns the cursor shape value for a cursor |type|, or nullopt if the // type isn't supported by the cursor API. static absl::optional<int32_t> ShapeFromType(mojom::CursorType type); // Calls zcr_cursor_shapes_v1_set_cursor_shape(). See interface description // for values for |shape|. Virtual for testing. virtual void SetCursorShape(int32_t shape); private: wl::Object<zcr_cursor_shapes_v1> zcr_cursor_shapes_v1_; const raw_ptr<WaylandConnection> connection_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_CURSOR_SHAPES_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_cursor_shapes.h
C++
unknown
2,045
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zcr_touchpad_haptics.h" #include <touchpad-haptics-unstable-v1-client-protocol.h> #include "base/logging.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; } // static constexpr char WaylandZcrTouchpadHaptics::kInterfaceName[]; // static void WaylandZcrTouchpadHaptics::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->zcr_touchpad_haptics_ || !wl::CanBind(interface, version, kMinVersion, kMinVersion)) { return; } auto zcr_touchpad_haptics = wl::Bind<zcr_touchpad_haptics_v1>(registry, name, kMinVersion); if (!zcr_touchpad_haptics) { LOG(ERROR) << "Failed to bind zcr_touchpad_haptics_v1"; return; } connection->zcr_touchpad_haptics_ = std::make_unique<WaylandZcrTouchpadHaptics>( zcr_touchpad_haptics.release(), connection); } WaylandZcrTouchpadHaptics::WaylandZcrTouchpadHaptics( zcr_touchpad_haptics_v1* zcr_touchpad_haptics, WaylandConnection* connection) : obj_(zcr_touchpad_haptics), connection_(connection) { DCHECK(obj_); DCHECK(connection_); static constexpr zcr_touchpad_haptics_v1_listener zcr_touchpad_haptics_v1_listener = { &WaylandZcrTouchpadHaptics::OnActivated, &WaylandZcrTouchpadHaptics::OnDeactivated, }; zcr_touchpad_haptics_v1_add_listener(obj_.get(), &zcr_touchpad_haptics_v1_listener, this); } WaylandZcrTouchpadHaptics::~WaylandZcrTouchpadHaptics() = default; // static void WaylandZcrTouchpadHaptics::OnActivated( void* data, struct zcr_touchpad_haptics_v1* zcr_touchpad_haptics_v1) { NOTIMPLEMENTED_LOG_ONCE(); } // static void WaylandZcrTouchpadHaptics::OnDeactivated( void* data, struct zcr_touchpad_haptics_v1* zcr_touchpad_haptics_v1) { NOTIMPLEMENTED_LOG_ONCE(); } void WaylandZcrTouchpadHaptics::Play(int32_t effect, int32_t strength) { zcr_touchpad_haptics_v1_play(obj_.get(), effect, strength); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_touchpad_haptics.cc
C++
unknown
2,630
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_TOUCHPAD_HAPTICS_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_TOUCHPAD_HAPTICS_H_ #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace ui { class WaylandConnection; // Wraps the zcr_touchpad_haptics object. class WaylandZcrTouchpadHaptics : public wl::GlobalObjectRegistrar<WaylandZcrTouchpadHaptics> { public: static constexpr char kInterfaceName[] = "zcr_touchpad_haptics_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); WaylandZcrTouchpadHaptics(zcr_touchpad_haptics_v1* zcr_touchpad_haptics, WaylandConnection* connection); WaylandZcrTouchpadHaptics(const WaylandZcrTouchpadHaptics&) = delete; WaylandZcrTouchpadHaptics& operator=(const WaylandZcrTouchpadHaptics&) = delete; virtual ~WaylandZcrTouchpadHaptics(); // Calls zcr_touchpad_haptics_v1_play(). See interface descriptions for values // for |effect| and |strength| void Play(int32_t effect, int32_t strength); private: // zcr_touchpad_haptics_v1_listener static void OnActivated( void* data, struct zcr_touchpad_haptics_v1* zcr_touchpad_haptics_v1); static void OnDeactivated( void* data, struct zcr_touchpad_haptics_v1* zcr_touchpad_haptics_v1); wl::Object<zcr_touchpad_haptics_v1> obj_; const raw_ptr<WaylandConnection> connection_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZCR_TOUCHPAD_HAPTICS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zcr_touchpad_haptics.h
C++
unknown
1,853
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.h" #include <drm_fourcc.h> #include <linux-dmabuf-unstable-v1-client-protocol.h> #include "base/logging.h" #include "base/ranges/algorithm.h" #include "ui/gfx/linux/drm_util_linux.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_factory.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; constexpr uint32_t kMaxVersion = 3; } // static constexpr char WaylandZwpLinuxDmabuf::kInterfaceName[]; // static void WaylandZwpLinuxDmabuf::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; auto* buffer_factory = connection->buffer_factory(); if (buffer_factory->wayland_zwp_dmabuf_ || !wl::CanBind(interface, version, kMinVersion, kMaxVersion)) { return; } auto zwp_linux_dmabuf = wl::Bind<zwp_linux_dmabuf_v1>( registry, name, std::min(version, kMaxVersion)); if (!zwp_linux_dmabuf) { LOG(ERROR) << "Failed to bind zwp_linux_dmabuf_v1"; return; } buffer_factory->wayland_zwp_dmabuf_ = std::make_unique<WaylandZwpLinuxDmabuf>( zwp_linux_dmabuf.release(), connection); } WaylandZwpLinuxDmabuf::WaylandZwpLinuxDmabuf( zwp_linux_dmabuf_v1* zwp_linux_dmabuf, WaylandConnection* connection) : zwp_linux_dmabuf_(zwp_linux_dmabuf), connection_(connection) { static constexpr zwp_linux_dmabuf_v1_listener dmabuf_listener = { &Format, &Modifiers, }; zwp_linux_dmabuf_v1_add_listener(zwp_linux_dmabuf_.get(), &dmabuf_listener, this); // A roundtrip after binding guarantees that the client has received all // supported formats. connection_->RoundTripQueue(); } WaylandZwpLinuxDmabuf::~WaylandZwpLinuxDmabuf() = default; void WaylandZwpLinuxDmabuf::CreateBuffer(const base::ScopedFD& fd, const gfx::Size& size, const std::vector<uint32_t>& strides, const std::vector<uint32_t>& offsets, const std::vector<uint64_t>& modifiers, uint32_t format, uint32_t planes_count, wl::OnRequestBufferCallback callback) { static constexpr zwp_linux_buffer_params_v1_listener params_listener = { &CreateSucceeded, &CreateFailed}; // Params will be destroyed immediately if create_immed is available. // Otherwise, they will be destroyed after Wayland notifies a new buffer is // created or failed to be created. wl::Object<zwp_linux_buffer_params_v1> params( zwp_linux_dmabuf_v1_create_params(zwp_linux_dmabuf_.get())); for (size_t i = 0; i < planes_count; i++) { zwp_linux_buffer_params_v1_add(params.get(), fd.get(), i /* plane id */, offsets[i], strides[i], modifiers[i] >> 32, modifiers[i] & UINT32_MAX); } // It's possible to avoid waiting until the buffer is created and have it // immediately. This method is only available since the protocol version 2. if (CanCreateBufferImmed()) { wl::Object<wl_buffer> buffer(zwp_linux_buffer_params_v1_create_immed( params.get(), size.width(), size.height(), format, 0)); std::move(callback).Run(std::move(buffer)); } else { zwp_linux_buffer_params_v1_add_listener(params.get(), &params_listener, this); zwp_linux_buffer_params_v1_create(params.get(), size.width(), size.height(), format, 0); // Store the |params| with the corresponding |callback| to identify newly // created buffer and notify the client about it via the |callback|. pending_params_.emplace(std::move(params), std::move(callback)); } connection_->Flush(); } bool WaylandZwpLinuxDmabuf::CanCreateBufferImmed() const { return wl::get_version_of_object(zwp_linux_dmabuf_.get()) >= ZWP_LINUX_BUFFER_PARAMS_V1_CREATE_IMMED_SINCE_VERSION; } void WaylandZwpLinuxDmabuf::AddSupportedFourCCFormatAndModifier( uint32_t fourcc_format, absl::optional<uint64_t> modifier) { // Return on not supported fourcc formats. if (!IsValidBufferFormat(fourcc_format)) return; uint64_t format_modifier = modifier.value_or(DRM_FORMAT_MOD_INVALID); // If the buffer format has already been stored, it must be another supported // modifier sent by the Wayland compositor. gfx::BufferFormat format = GetBufferFormatFromFourCCFormat(fourcc_format); auto it = supported_buffer_formats_with_modifiers_.find(format); if (it != supported_buffer_formats_with_modifiers_.end()) { if (format_modifier != DRM_FORMAT_MOD_INVALID) it->second.emplace_back(format_modifier); return; } else { std::vector<uint64_t> modifiers; if (format_modifier != DRM_FORMAT_MOD_INVALID) modifiers.emplace_back(format_modifier); supported_buffer_formats_with_modifiers_.emplace(format, std::move(modifiers)); } } void WaylandZwpLinuxDmabuf::NotifyRequestCreateBufferDone( struct zwp_linux_buffer_params_v1* params, struct wl_buffer* new_buffer) { auto it = base::ranges::find(pending_params_, params, [](const auto& item) { return item.first.get(); }); DCHECK(it != pending_params_.end()); std::move(it->second).Run(wl::Object<struct wl_buffer>(new_buffer)); pending_params_.erase(it); connection_->Flush(); } // static void WaylandZwpLinuxDmabuf::Modifiers( void* data, struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf, uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo) { if (auto* self = static_cast<WaylandZwpLinuxDmabuf*>(data)) { uint64_t modifier = static_cast<uint64_t>(modifier_hi) << 32 | modifier_lo; self->AddSupportedFourCCFormatAndModifier(format, {modifier}); } } // static void WaylandZwpLinuxDmabuf::Format(void* data, struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf, uint32_t format) { if (auto* self = static_cast<WaylandZwpLinuxDmabuf*>(data)) self->AddSupportedFourCCFormatAndModifier(format, absl::nullopt); } // static void WaylandZwpLinuxDmabuf::CreateSucceeded( void* data, struct zwp_linux_buffer_params_v1* params, struct wl_buffer* new_buffer) { if (auto* self = static_cast<WaylandZwpLinuxDmabuf*>(data)) self->NotifyRequestCreateBufferDone(params, new_buffer); } // static void WaylandZwpLinuxDmabuf::CreateFailed( void* data, struct zwp_linux_buffer_params_v1* params) { if (auto* self = static_cast<WaylandZwpLinuxDmabuf*>(data)) self->NotifyRequestCreateBufferDone(params, nullptr); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc
C++
unknown
7,405
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_LINUX_DMABUF_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_LINUX_DMABUF_H_ #include <vector> #include "base/files/scoped_file.h" #include "base/memory/raw_ptr.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/common/wayland_util.h" struct zwp_linux_dmabuf_v1; struct zwp_linux_buffer_params_v1; namespace gfx { enum class BufferFormat : uint8_t; class Size; } // namespace gfx namespace ui { class WaylandConnection; // Wrapper around |zwp_linux_dmabuf_v1| Wayland factory, which creates // |wl_buffer|s backed by dmabuf prime file descriptor. class WaylandZwpLinuxDmabuf : public wl::GlobalObjectRegistrar<WaylandZwpLinuxDmabuf> { public: static constexpr char kInterfaceName[] = "zwp_linux_dmabuf_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); WaylandZwpLinuxDmabuf(zwp_linux_dmabuf_v1* zwp_linux_dmabuf, WaylandConnection* connection); WaylandZwpLinuxDmabuf(const WaylandZwpLinuxDmabuf&) = delete; WaylandZwpLinuxDmabuf& operator=(const WaylandZwpLinuxDmabuf&) = delete; ~WaylandZwpLinuxDmabuf(); // Requests to create a wl_buffer backed by the dmabuf prime |fd| descriptor. // The result is sent back via the |callback|. If buffer creation failed, // nullptr is sent back via the callback. Otherwise, a pointer to the // |wl_buffer| is sent. void CreateBuffer(const base::ScopedFD& fd, const gfx::Size& size, const std::vector<uint32_t>& strides, const std::vector<uint32_t>& offsets, const std::vector<uint64_t>& modifiers, uint32_t format, uint32_t planes_count, wl::OnRequestBufferCallback callback); // Returns supported buffer formats received from the Wayland compositor. wl::BufferFormatsWithModifiersMap supported_buffer_formats() const { return supported_buffer_formats_with_modifiers_; } // Says if a new buffer can be created immediately. Depends on the version of // the |zwp_linux_dmabuf| object. bool CanCreateBufferImmed() const; private: // Receives supported |fourcc_format| from either ::Modifers or ::Format call // (depending on the protocol version), and stores it as gfx::BufferFormat to // the |supported_buffer_formats_| container. Modifiers can also be passed to // this method to be stored as a map of the format and modifier. void AddSupportedFourCCFormatAndModifier(uint32_t fourcc_format, absl::optional<uint64_t> modifier); // Finds the stored callback corresponding to the |params| created in the // RequestBufferAsync call, and passes the wl_buffer to the client. The // |new_buffer| can be null. void NotifyRequestCreateBufferDone(struct zwp_linux_buffer_params_v1* params, struct wl_buffer* new_buffer); // zwp_linux_dmabuf_v1_listener static void Modifiers(void* data, struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf, uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo); static void Format(void* data, struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf, uint32_t format); // zwp_linux_buffer_params_v1_listener static void CreateSucceeded(void* data, struct zwp_linux_buffer_params_v1* params, struct wl_buffer* new_buffer); static void CreateFailed(void* data, struct zwp_linux_buffer_params_v1* params); // Holds pointer to the // zwp_linux_dmabuf_v1 Wayland // factory. const wl::Object<zwp_linux_dmabuf_v1> zwp_linux_dmabuf_; // Non-owned. const raw_ptr<WaylandConnection> connection_; // Holds supported DRM formats translated to gfx::BufferFormat. wl::BufferFormatsWithModifiersMap supported_buffer_formats_with_modifiers_; // Contains callbacks for requests to create |wl_buffer|s using // |zwp_linux_dmabuf_| factory. base::flat_map<wl::Object<zwp_linux_buffer_params_v1>, wl::OnRequestBufferCallback> pending_params_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_LINUX_DMABUF_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.h
C++
unknown
4,784
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zwp_pointer_constraints.h" #include <pointer-constraints-unstable-v1-client-protocol.h> #include "base/logging.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_pointer.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_surface.h" #include "ui/ozone/platform/wayland/host/wayland_zwp_relative_pointer_manager.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; } // static constexpr char WaylandZwpPointerConstraints::kInterfaceName[]; // static void WaylandZwpPointerConstraints::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->zwp_pointer_constraints_ || !wl::CanBind(interface, version, kMinVersion, kMinVersion)) { return; } auto zwp_pointer_constraints_v1 = wl::Bind<struct zwp_pointer_constraints_v1>(registry, name, kMinVersion); if (!zwp_pointer_constraints_v1) { LOG(ERROR) << "Failed to bind wp_pointer_constraints_v1"; return; } connection->zwp_pointer_constraints_ = std::make_unique<WaylandZwpPointerConstraints>( zwp_pointer_constraints_v1.release(), connection); } WaylandZwpPointerConstraints::WaylandZwpPointerConstraints( zwp_pointer_constraints_v1* pointer_constraints, WaylandConnection* connection) : obj_(pointer_constraints), connection_(connection) { DCHECK(obj_); DCHECK(connection_); } WaylandZwpPointerConstraints::~WaylandZwpPointerConstraints() = default; void WaylandZwpPointerConstraints::LockPointer(WaylandSurface* surface) { locked_pointer_.reset(zwp_pointer_constraints_v1_lock_pointer( obj_.get(), surface->surface(), connection_->seat()->pointer()->wl_object(), nullptr, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT)); static constexpr zwp_locked_pointer_v1_listener zwp_locked_pointer_v1_listener = { &OnLock, &OnUnlock, }; zwp_locked_pointer_v1_add_listener(locked_pointer_.get(), &zwp_locked_pointer_v1_listener, this); } void WaylandZwpPointerConstraints::UnlockPointer() { locked_pointer_.reset(); connection_->zwp_relative_pointer_manager()->DisableRelativePointer(); } // static void WaylandZwpPointerConstraints::OnLock( void* data, struct zwp_locked_pointer_v1* zwp_locked_pointer_v1) { auto* pointer_constraints = static_cast<WaylandZwpPointerConstraints*>(data); pointer_constraints->connection_->zwp_relative_pointer_manager() ->EnableRelativePointer(); } // static void WaylandZwpPointerConstraints::OnUnlock( void* data, struct zwp_locked_pointer_v1* zwp_locked_pointer_v1) { auto* pointer_constraints = static_cast<WaylandZwpPointerConstraints*>(data); pointer_constraints->UnlockPointer(); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_pointer_constraints.cc
C++
unknown
3,443
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_POINTER_CONSTRAINTS_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_POINTER_CONSTRAINTS_H_ #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace ui { class WaylandConnection; class WaylandSurface; // Wraps the zwp_pointer_constraints_v1 object. class WaylandZwpPointerConstraints : public wl::GlobalObjectRegistrar<WaylandZwpPointerConstraints> { public: static constexpr char kInterfaceName[] = "zwp_pointer_constraints_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); WaylandZwpPointerConstraints(zwp_pointer_constraints_v1* pointer_constraints, WaylandConnection* connection); WaylandZwpPointerConstraints(const WaylandZwpPointerConstraints&) = delete; WaylandZwpPointerConstraints& operator=(const WaylandZwpPointerConstraints&) = delete; ~WaylandZwpPointerConstraints(); void LockPointer(WaylandSurface* surface); void UnlockPointer(); private: // zwp_locked_pointer_v1_listener static void OnLock(void* data, struct zwp_locked_pointer_v1* zwp_locked_pointer_v1); static void OnUnlock(void* data, struct zwp_locked_pointer_v1* zwp_locked_pointer_v1); wl::Object<zwp_pointer_constraints_v1> obj_; wl::Object<zwp_locked_pointer_v1> locked_pointer_; const raw_ptr<WaylandConnection> connection_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_POINTER_CONSTRAINTS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_pointer_constraints.h
C++
unknown
1,877
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures.h" #include <pointer-gestures-unstable-v1-client-protocol.h> #include <wayland-util.h> #include "base/logging.h" #include "build/chromeos_buildflags.h" #include "ui/gfx/geometry/vector2d_f.h" #include "ui/ozone/platform/wayland/common/wayland_util.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_cursor_position.h" #include "ui/ozone/platform/wayland/host/wayland_event_source.h" #include "ui/ozone/platform/wayland/host/wayland_pointer.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_window_manager.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; } // static constexpr char WaylandZwpPointerGestures::kInterfaceName[]; // static void WaylandZwpPointerGestures::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->zwp_pointer_gestures_ || !wl::CanBind(interface, version, kMinVersion, kMinVersion)) { return; } auto zwp_pointer_gestures_v1 = wl::Bind<struct zwp_pointer_gestures_v1>(registry, name, kMinVersion); if (!zwp_pointer_gestures_v1) { LOG(ERROR) << "Failed to bind wp_pointer_gestures_v1"; return; } connection->zwp_pointer_gestures_ = std::make_unique<WaylandZwpPointerGestures>( zwp_pointer_gestures_v1.release(), connection, connection->event_source()); } WaylandZwpPointerGestures::WaylandZwpPointerGestures( zwp_pointer_gestures_v1* pointer_gestures, WaylandConnection* connection, Delegate* delegate) : obj_(pointer_gestures), connection_(connection), delegate_(delegate) { DCHECK(obj_); DCHECK(connection_); DCHECK(delegate_); } WaylandZwpPointerGestures::~WaylandZwpPointerGestures() = default; void WaylandZwpPointerGestures::Init() { DCHECK(connection_->seat()->pointer()); pinch_.reset(zwp_pointer_gestures_v1_get_pinch_gesture( obj_.get(), connection_->seat()->pointer()->wl_object())); static constexpr zwp_pointer_gesture_pinch_v1_listener zwp_pointer_gesture_pinch_v1_listener = { &WaylandZwpPointerGestures::OnPinchBegin, &WaylandZwpPointerGestures::OnPinchUpdate, &WaylandZwpPointerGestures::OnPinchEnd, }; zwp_pointer_gesture_pinch_v1_add_listener( pinch_.get(), &zwp_pointer_gesture_pinch_v1_listener, this); } // static void WaylandZwpPointerGestures::OnPinchBegin( void* data, struct zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, struct wl_surface* surface, uint32_t fingers) { auto* self = static_cast<WaylandZwpPointerGestures*>(data); base::TimeTicks timestamp = base::TimeTicks() + base::Milliseconds(time); self->current_scale_ = 1; self->delegate_->OnPinchEvent(ET_GESTURE_PINCH_BEGIN, gfx::Vector2dF() /*delta*/, timestamp, self->obj_.id()); } // static void WaylandZwpPointerGestures::OnPinchUpdate( void* data, struct zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1, uint32_t time, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t scale, wl_fixed_t rotation) { auto* self = static_cast<WaylandZwpPointerGestures*>(data); #if !BUILDFLAG(IS_CHROMEOS_LACROS) // During the pinch zoom session, libinput sends the current scale relative to // the start of the session. On the other hand, the compositor expects the // change of the scale relative to the previous update in form of a multiplier // applied to the current value. // See https://crbug.com/1283652 const auto new_scale = wl_fixed_to_double(scale); const auto scale_delta = new_scale / self->current_scale_; self->current_scale_ = new_scale; #else // TODO(crbug.com/1298099): Remove this code when exo is fixed. // Exo currently sends relative scale values so it should be passed along to // Chrome without modification until exo can be fixed. const auto scale_delta = wl_fixed_to_double(scale); #endif base::TimeTicks timestamp = base::TimeTicks() + base::Milliseconds(time); gfx::Vector2dF delta = {static_cast<float>(wl_fixed_to_double(dx)), static_cast<float>(wl_fixed_to_double(dy))}; self->delegate_->OnPinchEvent(ET_GESTURE_PINCH_UPDATE, delta, timestamp, self->obj_.id(), scale_delta); } void WaylandZwpPointerGestures::OnPinchEnd( void* data, struct zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, int32_t cancelled) { auto* self = static_cast<WaylandZwpPointerGestures*>(data); base::TimeTicks timestamp = base::TimeTicks() + base::Milliseconds(time); self->delegate_->OnPinchEvent(ET_GESTURE_PINCH_END, gfx::Vector2dF() /*delta*/, timestamp, self->obj_.id()); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures.cc
C++
unknown
5,541
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_POINTER_GESTURES_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_POINTER_GESTURES_H_ #include "base/memory/raw_ptr.h" #include "base/time/time.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/events/types/event_type.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace gfx { class Vector2dF; } namespace ui { class WaylandConnection; // Wraps the zwp_pointer_gestures and zwp_pointer_gesture_pinch_v1 objects. class WaylandZwpPointerGestures : public wl::GlobalObjectRegistrar<WaylandZwpPointerGestures> { public: static constexpr char kInterfaceName[] = "zwp_pointer_gestures_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); class Delegate; WaylandZwpPointerGestures(zwp_pointer_gestures_v1* pointer_gestures, WaylandConnection* connection, Delegate* delegate); WaylandZwpPointerGestures(const WaylandZwpPointerGestures&) = delete; WaylandZwpPointerGestures& operator=(const WaylandZwpPointerGestures&) = delete; ~WaylandZwpPointerGestures(); // Init is called by WaylandConnection when its wl_pointer object is // instantiated. void Init(); private: // zwp_pointer_gesture_pinch_v1_listener static void OnPinchBegin( void* data, struct zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, struct wl_surface* surface, uint32_t fingers); static void OnPinchUpdate( void* data, struct zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1, uint32_t time, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t scale, wl_fixed_t rotation); static void OnPinchEnd( void* data, struct zwp_pointer_gesture_pinch_v1* zwp_pointer_gesture_pinch_v1, uint32_t serial, uint32_t time, int32_t cancelled); wl::Object<zwp_pointer_gestures_v1> obj_; wl::Object<zwp_pointer_gesture_pinch_v1> pinch_; double current_scale_ = 1; const raw_ptr<WaylandConnection> connection_; const raw_ptr<Delegate> delegate_; }; class WaylandZwpPointerGestures::Delegate { public: // Handles the events coming during the pinch zoom session. // |event_type| is one of ET_GESTURE_PINCH_### members. // |delta| is empty on the BEGIN and END, and shows the movement of the centre // of the gesture compared to the previous event. // |scale_delta| is the change to the scale compared to the previous event, to // be applied as multiplier (as the compositor expects it). virtual void OnPinchEvent( EventType event_type, const gfx::Vector2dF& delta, base::TimeTicks timestamp, int device_id, absl::optional<float> scale_delta = absl::nullopt) = 0; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_POINTER_GESTURES_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures.h
C++
unknown
3,253
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <pointer-gestures-unstable-v1-server-protocol.h> #include <wayland-util.h> #include "build/chromeos_buildflags.h" #include "ui/events/event.h" #include "ui/events/platform/platform_event_observer.h" #include "ui/ozone/platform/wayland/host/wayland_event_source.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures.h" #include "ui/ozone/platform/wayland/test/mock_pointer.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/wayland_test.h" namespace ui { namespace { // Observes events, filters the pinch zoom updates, and records the latest // update to the scale. class PinchEventScaleRecorder : public PlatformEventObserver { public: PinchEventScaleRecorder() { PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); } PinchEventScaleRecorder(const PinchEventScaleRecorder&) = delete; PinchEventScaleRecorder& operator=(const PinchEventScaleRecorder&) = delete; ~PinchEventScaleRecorder() override { PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); } double latest_scale_update() const { return latest_scale_update_; } protected: // PlatformEventObserver: void WillProcessEvent(const PlatformEvent& event) override { if (!event->IsGestureEvent()) return; const GestureEvent* const gesture = event->AsGestureEvent(); if (!gesture->IsPinchEvent() || gesture->type() != ET_GESTURE_PINCH_UPDATE) return; latest_scale_update_ = gesture->details().scale(); } void DidProcessEvent(const PlatformEvent& event) override {} double latest_scale_update_ = 1.0; }; } // namespace class WaylandPointerGesturesTest : public WaylandTestSimple { public: void SetUp() override { WaylandTestSimple::SetUp(); // Pointer capability is required for gesture objects to be initialised. PostToServerAndWait([](wl::TestWaylandServerThread* server) { wl_seat_send_capabilities(server->seat()->resource(), WL_SEAT_CAPABILITY_POINTER); }); ASSERT_TRUE(connection_->seat()->pointer()); ASSERT_TRUE(connection_->zwp_pointer_gestures()); } }; // Tests that scale in pinch zoom events is fixed to the progression expected by // the compositor. // // During the pinch zoom session, libinput sends the current scale relative to // the start of the session. The compositor, however, expects every update to // have the relative change of the scale, compared to the previous update in // form of a multiplier applied to the current value. The factor is fixed at // the low level immediately after values are received from the server via // WaylandZwpPointerGestures methods. // // See https://crbug.com/1283652 TEST_F(WaylandPointerGesturesTest, PinchZoomScale) { PostToServerAndWait([surface_id = window_->root_surface()->get_surface_id()]( wl::TestWaylandServerThread* server) { auto* const pointer = server->seat()->pointer()->resource(); auto* const surface = server->GetObject<wl::MockSurface>(surface_id)->resource(); wl_pointer_send_enter(pointer, server->GetNextSerial(), surface, wl_fixed_from_int(50), wl_fixed_from_int(50)); wl_pointer_send_frame(pointer); }); PinchEventScaleRecorder observer; PostToServerAndWait([surface_id = window_->root_surface()->get_surface_id()]( wl::TestWaylandServerThread* server) { auto* const pinch = server->wp_pointer_gestures().pinch()->resource(); auto* const surface = server->GetObject<wl::MockSurface>(surface_id)->resource(); zwp_pointer_gesture_pinch_v1_send_begin(pinch, server->GetNextSerial(), server->GetNextTime(), surface, /* fingers */ 2); }); constexpr double kScales[] = {1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.4, 1.3, 1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}; [[maybe_unused]] auto previous_scale = kScales[0]; for (auto scale : kScales) { PostToServerAndWait([scale](wl::TestWaylandServerThread* server) { auto* const pinch = server->wp_pointer_gestures().pinch()->resource(); zwp_pointer_gesture_pinch_v1_send_update( pinch, /* time */ 0, /* dx */ 0, /* dy */ 0, wl_fixed_from_double(scale), /* rotation */ 0); }); #if BUILDFLAG(IS_CHROMEOS_LACROS) EXPECT_FLOAT_EQ(observer.latest_scale_update(), wl_fixed_to_double(wl_fixed_from_double(scale))); #else // The conversion from double to fixed and back is necessary because it // happens during the roundtrip, and it creates significant error. EXPECT_FLOAT_EQ( observer.latest_scale_update(), wl_fixed_to_double(wl_fixed_from_double(scale)) / previous_scale); previous_scale = wl_fixed_to_double(wl_fixed_from_double(scale)); #endif } } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_pointer_gestures_unittest.cc
C++
unknown
5,207
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/wayland_zwp_relative_pointer_manager.h" #include <relative-pointer-unstable-v1-client-protocol.h> #include "base/logging.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_event_source.h" #include "ui/ozone/platform/wayland/host/wayland_pointer.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; } // static constexpr char WaylandZwpRelativePointerManager::kInterfaceName[]; // static void WaylandZwpRelativePointerManager::Instantiate( WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->zwp_relative_pointer_manager_ || !wl::CanBind(interface, version, kMinVersion, kMinVersion)) { return; } auto zwp_relative_pointer_manager_v1 = wl::Bind<struct zwp_relative_pointer_manager_v1>(registry, name, kMinVersion); if (!zwp_relative_pointer_manager_v1) { LOG(ERROR) << "Failed to bind zwp_relative_pointer_manager_v1"; return; } connection->zwp_relative_pointer_manager_ = std::make_unique<WaylandZwpRelativePointerManager>( zwp_relative_pointer_manager_v1.release(), connection); } WaylandZwpRelativePointerManager::WaylandZwpRelativePointerManager( zwp_relative_pointer_manager_v1* relative_pointer_manager, WaylandConnection* connection) : obj_(relative_pointer_manager), connection_(connection), delegate_(connection_->event_source()) { DCHECK(obj_); DCHECK(connection_); DCHECK(delegate_); } WaylandZwpRelativePointerManager::~WaylandZwpRelativePointerManager() = default; void WaylandZwpRelativePointerManager::EnableRelativePointer() { relative_pointer_.reset(zwp_relative_pointer_manager_v1_get_relative_pointer( obj_.get(), connection_->seat()->pointer()->wl_object())); static constexpr zwp_relative_pointer_v1_listener relative_pointer_listener = { &WaylandZwpRelativePointerManager::OnHandleMotion, }; zwp_relative_pointer_v1_add_listener(relative_pointer_.get(), &relative_pointer_listener, this); delegate_->SetRelativePointerMotionEnabled(true); } void WaylandZwpRelativePointerManager::DisableRelativePointer() { relative_pointer_.reset(); delegate_->SetRelativePointerMotionEnabled(false); } // static void WaylandZwpRelativePointerManager::OnHandleMotion( void* data, struct zwp_relative_pointer_v1* pointer, uint32_t utime_hi, uint32_t utime_lo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel) { auto* relative_pointer_manager = static_cast<WaylandZwpRelativePointerManager*>(data); gfx::Vector2dF delta = {static_cast<float>(wl_fixed_to_double(dx)), static_cast<float>(wl_fixed_to_double(dy))}; gfx::Vector2dF delta_unaccel = { static_cast<float>(wl_fixed_to_double(dx_unaccel)), static_cast<float>(wl_fixed_to_double(dy_unaccel))}; relative_pointer_manager->delegate_->OnRelativePointerMotion(delta); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_relative_pointer_manager.cc
C++
unknown
3,561
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_RELATIVE_POINTER_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_RELATIVE_POINTER_MANAGER_H_ #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace gfx { class Vector2dF; } // namespace gfx namespace ui { class WaylandConnection; // Wraps the zwp_relative_pointer_manager_v1 object. class WaylandZwpRelativePointerManager : public wl::GlobalObjectRegistrar<WaylandZwpRelativePointerManager> { public: static constexpr char kInterfaceName[] = "zwp_relative_pointer_manager_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); class Delegate; WaylandZwpRelativePointerManager( zwp_relative_pointer_manager_v1* relative_pointer_manager, WaylandConnection* connection); WaylandZwpRelativePointerManager(const WaylandZwpRelativePointerManager&) = delete; WaylandZwpRelativePointerManager& operator=( const WaylandZwpRelativePointerManager&) = delete; ~WaylandZwpRelativePointerManager(); void EnableRelativePointer(); void DisableRelativePointer(); private: // zwp_relative_pointer_v1_listener static void OnHandleMotion(void* data, struct zwp_relative_pointer_v1* pointer, uint32_t utime_hi, uint32_t utime_lo, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel); wl::Object<zwp_relative_pointer_manager_v1> obj_; wl::Object<zwp_relative_pointer_v1> relative_pointer_; const raw_ptr<WaylandConnection> connection_; const raw_ptr<Delegate> delegate_; }; class WaylandZwpRelativePointerManager::Delegate { public: virtual void SetRelativePointerMotionEnabled(bool enabled) = 0; virtual void OnRelativePointerMotion(const gfx::Vector2dF& delta) = 0; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_WAYLAND_ZWP_RELATIVE_POINTER_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/wayland_zwp_relative_pointer_manager.h
C++
unknown
2,411
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/xdg_activation.h" #include <xdg-activation-v1-client-protocol.h> #include <memory> #include "base/check_op.h" #include "base/functional/bind.h" #include "base/functional/callback.h" #include "base/logging.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_serial_tracker.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" namespace ui { namespace { constexpr uint32_t kMaxVersion = 1; } using ActivationDoneCallback = base::OnceCallback<void(std::string token)>; // Wraps the actual activation token. class XdgActivation::Token { public: Token(wl::Object<xdg_activation_token_v1> token, wl_surface* surface, wl_seat* seat, absl::optional<wl::Serial> serial, ActivationDoneCallback callback); Token(const Token&) = delete; Token& operator=(const Token&) = delete; ~Token(); private: static void Done(void* data, struct xdg_activation_token_v1* xdg_activation_token_v1, const char* token); wl::Object<xdg_activation_token_v1> token_; ActivationDoneCallback callback_; }; // static constexpr char XdgActivation::kInterfaceName[]; // static void XdgActivation::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->xdg_activation_) return; auto instance = wl::Bind<::xdg_activation_v1>(registry, name, std::min(version, kMaxVersion)); if (!instance) { LOG(ERROR) << "Failed to bind " << kInterfaceName; return; } connection->xdg_activation_ = std::make_unique<XdgActivation>(std::move(instance), connection); } XdgActivation::XdgActivation(wl::Object<xdg_activation_v1> xdg_activation_v1, WaylandConnection* connection) : xdg_activation_v1_(std::move(xdg_activation_v1)), connection_(connection) {} XdgActivation::~XdgActivation() = default; void XdgActivation::Activate(wl_surface* surface) const { // The spec isn't clear about what types of surfaces should be used as // the requestor surface, but all implementations of xdg_activation_v1 // known to date accept the currently keyboard focused surface for // activation. Update if needed once the upstream issue gets fixed: // https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/129 const WaylandWindow* const keyboard_focused_window = connection_->window_manager()->GetCurrentKeyboardFocusedWindow(); if (token_.get() != nullptr) { // If the earlier activation request is still being served, store the // incoming request and try to serve it after the current one is done. activation_queue_.emplace(surface); return; } wl_surface* const keyboard_focused_surface = keyboard_focused_window ? keyboard_focused_window->root_surface()->surface() : nullptr; auto* const token = xdg_activation_v1_get_activation_token(xdg_activation_v1_.get()); if (!token) { LOG(WARNING) << "Could not get an XDG activation token!"; return; } token_ = std::make_unique<Token>( wl::Object<xdg_activation_token_v1>(token), keyboard_focused_surface, connection_->seat()->wl_object(), connection_->serial_tracker().GetSerial( {wl::SerialType::kTouchPress, wl::SerialType::kMousePress, wl::SerialType::kMouseEnter, wl::SerialType::kKeyPress}), base::BindOnce(&XdgActivation::OnActivateDone, weak_factory_.GetMutableWeakPtr(), surface)); } void XdgActivation::OnActivateDone(wl_surface* surface, std::string token) { xdg_activation_v1_activate(xdg_activation_v1_.get(), token.c_str(), surface); token_.reset(); if (!activation_queue_.empty()) { Activate(activation_queue_.front()); activation_queue_.pop(); } } XdgActivation::Token::Token(wl::Object<xdg_activation_token_v1> token, wl_surface* surface, wl_seat* seat, absl::optional<wl::Serial> serial, ActivationDoneCallback callback) : token_(std::move(token)), callback_(std::move(callback)) { static constexpr xdg_activation_token_v1_listener kListener = {&Done}; xdg_activation_token_v1_add_listener(token_.get(), &kListener, this); if (surface) { xdg_activation_token_v1_set_surface(token_.get(), surface); } if (serial) { xdg_activation_token_v1_set_serial(token_.get(), serial->value, seat); } xdg_activation_token_v1_commit(token_.get()); } XdgActivation::Token::~Token() = default; // static void XdgActivation::Token::Done( void* data, struct xdg_activation_token_v1* xdg_activation_token_v1, const char* token) { auto* const self = static_cast<XdgActivation::Token*>(data); std::move(self->callback_).Run(token); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_activation.cc
C++
unknown
5,471
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_ACTIVATION_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_ACTIVATION_H_ #include "base/containers/queue.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace ui { // Implements the XDG activation Wayland protocol extension. class XdgActivation : public wl::GlobalObjectRegistrar<XdgActivation> { public: static constexpr char kInterfaceName[] = "xdg_activation_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); XdgActivation(wl::Object<xdg_activation_v1> xdg_activation_v1, WaylandConnection* connection); XdgActivation(const XdgActivation&) = delete; XdgActivation& operator=(const XdgActivation&) = delete; ~XdgActivation(); // Requests activation of the `surface`. // The actual activation happens asynchronously, after a round trip to the // server. // If there is another unfinished activation request, the method chains the // new request in the `activation_queue_` and handles it after the current // request is completed. // Does nothing if no other window is currently active. void Activate(wl_surface* surface) const; private: class Token; void OnActivateDone(wl_surface* surface, std::string token); // Wayland object wrapped by this class. wl::Object<xdg_activation_v1> xdg_activation_v1_; // The actual activation token. mutable std::unique_ptr<Token> token_; // Surfaces to activate next. mutable base::queue<raw_ptr<wl_surface>> activation_queue_; const raw_ptr<WaylandConnection> connection_; base::WeakPtrFactory<XdgActivation> weak_factory_{this}; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_ACTIVATION_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_activation.h
C++
unknown
2,101
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/xdg_activation.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/mock_wayland_platform_window_delegate.h" #include "ui/ozone/platform/wayland/test/test_keyboard.h" #include "ui/ozone/platform/wayland/test/test_util.h" #include "ui/ozone/platform/wayland/test/wayland_test.h" using ::testing::_; using ::testing::StrEq; using ::testing::Values; namespace ui { namespace { constexpr gfx::Rect kDefaultBounds(0, 0, 100, 100); const char kMockStaticTestToken[] = "CHROMIUM_MOCK_XDG_ACTIVATION_TOKEN"; } // namespace using XdgActivationTest = WaylandTest; // Tests that XdgActivation uses the proper surface to request window // activation. TEST_P(XdgActivationTest, WindowActivation) { MockWaylandPlatformWindowDelegate delegate; PostToServerAndWait([](wl::TestWaylandServerThread* server) { wl_seat_send_capabilities(server->seat()->resource(), WL_SEAT_CAPABILITY_KEYBOARD); }); ASSERT_TRUE(connection_->seat()->keyboard()); window_.reset(); auto window1 = CreateWaylandWindowWithParams(PlatformWindowType::kWindow, kDefaultBounds, &delegate); auto window2 = CreateWaylandWindowWithParams(PlatformWindowType::kWindow, kDefaultBounds, &delegate); // When window is shown, it automatically gets keyboard focus. Reset it connection_->window_manager()->SetKeyboardFocusedWindow(nullptr); auto surface_id1 = window1->root_surface()->get_surface_id(); auto surface_id2 = window2->root_surface()->get_surface_id(); ActivateSurface(surface_id1); ActivateSurface(surface_id2); PostToServerAndWait([surface_id2](wl::TestWaylandServerThread* server) { auto* const keyboard = server->seat()->keyboard()->resource(); auto* const xdg_activation = server->xdg_activation_v1(); auto* const surface2 = server->GetObject<wl::MockSurface>(surface_id2)->resource(); wl::ScopedWlArray empty({}); wl_keyboard_send_enter(keyboard, server->GetNextSerial(), surface2, empty.get()); EXPECT_CALL(*xdg_activation, TokenSetSurface(_, _, surface2)); EXPECT_CALL(*xdg_activation, TokenCommit(_, _)); }); connection_->xdg_activation()->Activate(window1->root_surface()->surface()); PostToServerAndWait([surface_id1](wl::TestWaylandServerThread* server) { auto* const xdg_activation = server->xdg_activation_v1(); auto* const token = xdg_activation->get_token(); auto* const surface1 = server->GetObject<wl::MockSurface>(surface_id1)->resource(); xdg_activation_token_v1_send_done(token->resource(), kMockStaticTestToken); EXPECT_CALL(*xdg_activation, Activate(_, xdg_activation->resource(), StrEq(kMockStaticTestToken), surface1)); }); } INSTANTIATE_TEST_SUITE_P(XdgVersionStableTest, XdgActivationTest, Values(wl::ServerConfig{})); } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_activation_unittest.cc
C++
unknown
3,328
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/xdg_foreign_wrapper.h" #include <xdg-foreign-unstable-v1-client-protocol.h> #include <xdg-foreign-unstable-v2-client-protocol.h> #include "base/logging.h" #include "base/memory/raw_ptr.h" #include "base/ranges/algorithm.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/platform_window/platform_window_init_properties.h" namespace ui { // static constexpr char XdgForeignWrapper::kInterfaceNameV1[]; // static constexpr char XdgForeignWrapper::kInterfaceNameV2[]; constexpr uint32_t kMinVersion = 1; using OnHandleExported = XdgForeignWrapper::OnHandleExported; namespace { template <typename ExporterType> std::unique_ptr<XdgForeignWrapper> CreateWrapper(WaylandConnection* connection, wl_registry* registry, uint32_t name, uint32_t version) { auto zxdg_exporter = wl::Bind<ExporterType>(registry, name, version); if (!zxdg_exporter) { LOG(ERROR) << "Failed to bind zxdg_exporter"; return {}; } return std::make_unique<XdgForeignWrapper>(connection, std::move(zxdg_exporter)); } } // namespace template <typename ExportedType> struct ExportedSurface { ExportedSurface(wl_surface* surface, OnHandleExported cb) : surface_for_export(surface) { callbacks.emplace_back((std::move(cb))); } ExportedSurface(ExportedSurface&& buffer) = default; ExportedSurface& operator=(ExportedSurface&& buffer) = default; ~ExportedSurface() = default; // Surface that is exported. raw_ptr<wl_surface> surface_for_export = nullptr; // Exported |surface|. wl::Object<ExportedType> exported; // Handle of the exported |surface|. std::string exported_handle; // The cb that will be executed when |handle| is exported. std::vector<OnHandleExported> callbacks; }; class XdgForeignWrapper::XdgForeignWrapperInternal { public: virtual ~XdgForeignWrapperInternal() = default; virtual void ExportSurfaceToForeign(wl_surface* surface, OnHandleExported cb) = 0; // WaylandWindowObserver: virtual void OnWindowRemoved(WaylandWindow* window) = 0; }; template <typename ExporterType, typename ExportedType> class XdgForeignWrapperImpl : public XdgForeignWrapper::XdgForeignWrapperInternal { public: XdgForeignWrapperImpl(WaylandConnection* connection, wl::Object<ExporterType> exporter) : connection_(connection), exporter_(std::move(exporter)) {} XdgForeignWrapperImpl(const XdgForeignWrapperImpl&) = delete; XdgForeignWrapperImpl& operator=(const XdgForeignWrapperImpl&) = delete; ~XdgForeignWrapperImpl() override = default; void ExportSurfaceToForeign(wl_surface* surface, OnHandleExported cb) override { auto* exported_surface = GetExportedSurface(surface); if (!exported_surface) { // The |surface| has never been exported. Export it and return the handle // via the |cb|. ExportSurfaceInternal(surface, std::move(cb)); } else if (exported_surface->exported_handle.empty()) { // The |surface| has already been exported, but its handle hasn't been // received yet. Store the |cb| and execute when the handle is obtained. exported_surface->callbacks.emplace_back(std::move(cb)); } else { // The |surface| has already been exported and its handle has been // received. Execute the |cb| and send the handle. DCHECK(!exported_surface->exported_handle.empty()); std::move(cb).Run(exported_surface->exported_handle); } } void ExportSurfaceInternal(wl_surface* surface, OnHandleExported cb); void OnWindowRemoved(WaylandWindow* window) override { auto it = base::ranges::find( exported_surfaces_, window->root_surface()->surface(), &ExportedSurface<ExportedType>::surface_for_export); if (it != exported_surfaces_.end()) exported_surfaces_.erase(it); } ExportedSurface<ExportedType>* GetExportedSurface(wl_surface* surface) { for (auto& item : exported_surfaces_) { if (item.surface_for_export == surface) return &item; } return nullptr; } private: // static static void OnExported(void* data, ExportedType* exported, const char* handle) { auto* self = static_cast<XdgForeignWrapperImpl<ExporterType, ExportedType>*>(data); DCHECK(self); auto exported_surface_it = base::ranges::find( self->exported_surfaces_, exported, [](const auto& item) { return item.exported.get(); }); DCHECK(exported_surface_it != self->exported_surfaces_.end()); exported_surface_it->exported_handle = handle; for (auto& cb : exported_surface_it->callbacks) std::move(cb).Run(exported_surface_it->exported_handle); exported_surface_it->callbacks.clear(); } const raw_ptr<WaylandConnection> connection_; wl::Object<ExporterType> exporter_; std::vector<ExportedSurface<ExportedType>> exported_surfaces_; }; template <> void XdgForeignWrapperImpl<zxdg_exporter_v1, zxdg_exported_v1>:: ExportSurfaceInternal(wl_surface* surface, OnHandleExported cb) { static constexpr zxdg_exported_v1_listener kExportedListener = {&OnExported}; ExportedSurface<zxdg_exported_v1> exported_surface(surface, std::move(cb)); exported_surface.exported.reset( zxdg_exporter_v1_export(exporter_.get(), surface)); zxdg_exported_v1_add_listener(exported_surface.exported.get(), &kExportedListener, this); exported_surfaces_.emplace_back(std::move(exported_surface)); connection_->Flush(); } template <> void XdgForeignWrapperImpl<zxdg_exporter_v2, zxdg_exported_v2>:: ExportSurfaceInternal(wl_surface* surface, OnHandleExported cb) { static constexpr zxdg_exported_v2_listener kExportedListener = {&OnExported}; ExportedSurface<zxdg_exported_v2> exported_surface(surface, std::move(cb)); exported_surface.exported.reset( zxdg_exporter_v2_export_toplevel(exporter_.get(), surface)); zxdg_exported_v2_add_listener(exported_surface.exported.get(), &kExportedListener, this); exported_surfaces_.emplace_back(std::move(exported_surface)); connection_->Flush(); } // static void XdgForeignWrapper::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { if (connection->xdg_foreign_ || !wl::CanBind(interface, version, kMinVersion, kMinVersion)) { return; } if (interface == kInterfaceNameV1) { connection->xdg_foreign_ = CreateWrapper<zxdg_exporter_v1>( connection, registry, name, kMinVersion); } else if (interface == kInterfaceNameV2) { connection->xdg_foreign_ = CreateWrapper<zxdg_exporter_v2>( connection, registry, name, kMinVersion); } else { NOTREACHED() << " unexpected interface name: " << interface; } } XdgForeignWrapper::XdgForeignWrapper(WaylandConnection* connection, wl::Object<zxdg_exporter_v1> exporter_v1) { impl_ = std::make_unique< XdgForeignWrapperImpl<zxdg_exporter_v1, zxdg_exported_v1>>( connection, std::move(exporter_v1)); } XdgForeignWrapper::XdgForeignWrapper(WaylandConnection* connection, wl::Object<zxdg_exporter_v2> exporter_v2) { impl_ = std::make_unique< XdgForeignWrapperImpl<zxdg_exporter_v2, zxdg_exported_v2>>( connection, std::move(exporter_v2)); } XdgForeignWrapper::~XdgForeignWrapper() = default; void XdgForeignWrapper::ExportSurfaceToForeign(WaylandWindow* window, OnHandleExported cb) { DCHECK_EQ(window->type(), PlatformWindowType::kWindow); auto* surface = window->root_surface()->surface(); impl_->ExportSurfaceToForeign(surface, std::move(cb)); } void XdgForeignWrapper::OnWindowRemoved(WaylandWindow* window) { impl_->OnWindowRemoved(window); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc
C++
unknown
8,505
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_FOREIGN_WRAPPER_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_FOREIGN_WRAPPER_H_ #include <string> #include "base/functional/callback.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_window_observer.h" namespace ui { class WaylandConnection; // A wrapper for xdg foreign objects. Exports surfaces that have xdg_surface // roles and asynchronously returns handles for them. Only xdg_surface surfaces // may be exported. Currently supports only exporting surfaces. class XdgForeignWrapper : public wl::GlobalObjectRegistrar<XdgForeignWrapper>, public WaylandWindowObserver { public: class XdgForeignWrapperInternal; static constexpr char kInterfaceNameV1[] = "zxdg_exporter_v1"; static constexpr char kInterfaceNameV2[] = "zxdg_exporter_v2"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); using OnHandleExported = base::OnceCallback<void(const std::string&)>; XdgForeignWrapper(WaylandConnection* connection, wl::Object<zxdg_exporter_v1> exporter_v1); XdgForeignWrapper(WaylandConnection* connection, wl::Object<zxdg_exporter_v2> exporter_v2); XdgForeignWrapper(const XdgForeignWrapper&) = delete; XdgForeignWrapper& operator=(const XdgForeignWrapper&) = delete; ~XdgForeignWrapper() override; // Exports |window|'s wl_surface and asynchronously returns a handle for that // via the |cb|. Please note that wl_surface that has xdg_surface role can be // exported. void ExportSurfaceToForeign(WaylandWindow* window, OnHandleExported cb); private: // WaylandWindowObserver: void OnWindowRemoved(WaylandWindow* window) override; std::unique_ptr<XdgForeignWrapperInternal> impl_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_FOREIGN_WRAPPER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_foreign_wrapper.h
C++
unknown
2,289
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/xdg_output.h" #include <xdg-output-unstable-v1-client-protocol.h> #include "ui/ozone/platform/wayland/host/wayland_output.h" namespace ui { XDGOutput::XDGOutput(zxdg_output_v1* xdg_output) : xdg_output_(xdg_output) { static const zxdg_output_v1_listener listener = { &XDGOutput::OutputHandleLogicalPosition, &XDGOutput::OutputHandleLogicalSize, &XDGOutput::OutputHandleDone, &XDGOutput::OutputHandleName, &XDGOutput::OutputHandleDescription, }; // Can be nullptr in tests. if (xdg_output_) zxdg_output_v1_add_listener(xdg_output_.get(), &listener, this); } XDGOutput::~XDGOutput() = default; // static void XDGOutput::OutputHandleLogicalPosition( void* data, struct zxdg_output_v1* zxdg_output_v1, int32_t x, int32_t y) { if (XDGOutput* xdg_output = static_cast<XDGOutput*>(data)) xdg_output->logical_position_ = gfx::Point(x, y); } // static void XDGOutput::OutputHandleLogicalSize(void* data, struct zxdg_output_v1* zxdg_output_v1, int32_t width, int32_t height) { if (XDGOutput* xdg_output = static_cast<XDGOutput*>(data)) xdg_output->logical_size_ = gfx::Size(width, height); } // static void XDGOutput::OutputHandleDone(void* data, struct zxdg_output_v1* zxdg_output_v1) { // deprecated since version 3 } bool XDGOutput::IsReady() const { return is_ready_; } void XDGOutput::OnDone() { // If `logical_size` has been set the server must have propagated all the // necessary state events for this xdg_output. is_ready_ = !logical_size_.IsEmpty(); } void XDGOutput::UpdateMetrics(bool surface_submission_in_pixel_coordinates, WaylandOutput::Metrics& metrics) { if (!IsReady()) { return; } metrics.origin = logical_position_; metrics.logical_size = logical_size_; // Name is an optional xdg_output event. if (!name_.empty()) { metrics.name = name_; } // Description is an optional xdg_output event. if (!description_.empty()) { metrics.description = description_; } const gfx::Size logical_size = logical_size_; if (surface_submission_in_pixel_coordinates && !logical_size.IsEmpty()) { const gfx::Size physical_size = metrics.physical_size; DCHECK(!physical_size.IsEmpty()); const float max_physical_side = std::max(physical_size.width(), physical_size.height()); const float max_logical_side = std::max(logical_size.width(), logical_size.height()); metrics.scale_factor = max_physical_side / max_logical_side; } } // static void XDGOutput::OutputHandleName(void* data, struct zxdg_output_v1* zxdg_output_v1, const char* name) { if (XDGOutput* xdg_output = static_cast<XDGOutput*>(data)) { xdg_output->name_ = name ? std::string(name) : std::string(); } } // static void XDGOutput::OutputHandleDescription(void* data, struct zxdg_output_v1* zxdg_output_v1, const char* description) { if (XDGOutput* xdg_output = static_cast<XDGOutput*>(data)) { xdg_output->description_ = description ? std::string(description) : std::string(); } } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_output.cc
C++
unknown
3,562
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_OUTPUT_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_OUTPUT_H_ #include <stdint.h> #include "base/gtest_prod_util.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/size.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/host/wayland_output.h" namespace ui { class XDGOutput { public: explicit XDGOutput(struct zxdg_output_v1* xdg_output); XDGOutput(const XDGOutput&) = delete; XDGOutput& operator=(const XDGOutput&) = delete; ~XDGOutput(); // Returns true if all state defined by this extension necessary to correctly // represent the Display has successfully arrived from the server. bool IsReady() const; // Called after wl_output.done event has been received for this output. void OnDone(); // Called after processing the wl_output.done event. Translates the received // state into the metrics object as part of a chained atomic update. void UpdateMetrics(bool surface_submission_in_pixel_coordinates, WaylandOutput::Metrics& metrics); private: FRIEND_TEST_ALL_PREFIXES(WaylandOutputTest, NameAndDescriptionFallback); FRIEND_TEST_ALL_PREFIXES(WaylandOutputTest, ScaleFactorFallback); static void OutputHandleLogicalPosition(void* data, struct zxdg_output_v1* zxdg_output_v1, int32_t x, int32_t y); static void OutputHandleLogicalSize(void* data, struct zxdg_output_v1* zxdg_output_v1, int32_t width, int32_t height); static void OutputHandleDone(void* data, struct zxdg_output_v1* zxdg_output_v1); static void OutputHandleName(void* data, struct zxdg_output_v1* zxdg_output_v1, const char* name); static void OutputHandleDescription(void* data, struct zxdg_output_v1* zxdg_output_v1, const char* description); // Tracks whether this xdg_output is considered "ready". I.e. it has received // all of its relevant Display state from the server followed by a // wl_output.done event. bool is_ready_ = false; wl::Object<zxdg_output_v1> xdg_output_; gfx::Point logical_position_; gfx::Size logical_size_; std::string description_; std::string name_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_OUTPUT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_output.h
C++
unknown
2,832
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/xdg_popup_wrapper_impl.h" #include <aura-shell-client-protocol.h> #include <xdg-shell-client-protocol.h> #include <memory> #include "base/environment.h" #include "base/logging.h" #include "base/nix/xdg_util.h" #include "ui/base/ui_base_types.h" #include "ui/events/event.h" #include "ui/events/event_constants.h" #include "ui/events/types/event_type.h" #include "ui/gfx/geometry/rect.h" #include "ui/ozone/common/features.h" #include "ui/ozone/platform/wayland/common/wayland_util.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_event_source.h" #include "ui/ozone/platform/wayland/host/wayland_pointer.h" #include "ui/ozone/platform/wayland/host/wayland_popup.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_serial_tracker.h" #include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h" #include "ui/ozone/platform/wayland/host/wayland_zaura_shell.h" #include "ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.h" #include "ui/ozone/platform/wayland/host/xdg_toplevel_wrapper_impl.h" namespace ui { namespace { uint32_t TranslateAnchor(OwnedWindowAnchorPosition anchor) { switch (anchor) { case OwnedWindowAnchorPosition::kNone: return XDG_POSITIONER_ANCHOR_NONE; case OwnedWindowAnchorPosition::kTop: return XDG_POSITIONER_ANCHOR_TOP; case OwnedWindowAnchorPosition::kBottom: return XDG_POSITIONER_ANCHOR_BOTTOM; case OwnedWindowAnchorPosition::kLeft: return XDG_POSITIONER_ANCHOR_LEFT; case OwnedWindowAnchorPosition::kRight: return XDG_POSITIONER_ANCHOR_RIGHT; case OwnedWindowAnchorPosition::kTopLeft: return XDG_POSITIONER_ANCHOR_TOP_LEFT; case OwnedWindowAnchorPosition::kBottomLeft: return XDG_POSITIONER_ANCHOR_BOTTOM_LEFT; case OwnedWindowAnchorPosition::kTopRight: return XDG_POSITIONER_ANCHOR_TOP_RIGHT; case OwnedWindowAnchorPosition::kBottomRight: return XDG_POSITIONER_ANCHOR_BOTTOM_RIGHT; } } uint32_t TranslateGravity(OwnedWindowAnchorGravity gravity) { switch (gravity) { case OwnedWindowAnchorGravity::kNone: return XDG_POSITIONER_GRAVITY_NONE; case OwnedWindowAnchorGravity::kTop: return XDG_POSITIONER_GRAVITY_TOP; case OwnedWindowAnchorGravity::kBottom: return XDG_POSITIONER_GRAVITY_BOTTOM; case OwnedWindowAnchorGravity::kLeft: return XDG_POSITIONER_GRAVITY_LEFT; case OwnedWindowAnchorGravity::kRight: return XDG_POSITIONER_GRAVITY_RIGHT; case OwnedWindowAnchorGravity::kTopLeft: return XDG_POSITIONER_GRAVITY_TOP_LEFT; case OwnedWindowAnchorGravity::kBottomLeft: return XDG_POSITIONER_GRAVITY_BOTTOM_LEFT; case OwnedWindowAnchorGravity::kTopRight: return XDG_POSITIONER_GRAVITY_TOP_RIGHT; case OwnedWindowAnchorGravity::kBottomRight: return XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT; } } uint32_t TranslateConstraintAdjustment( OwnedWindowConstraintAdjustment constraint_adjustment) { uint32_t res = 0; if ((constraint_adjustment & OwnedWindowConstraintAdjustment::kAdjustmentSlideX) != OwnedWindowConstraintAdjustment::kAdjustmentNone) res |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X; if ((constraint_adjustment & OwnedWindowConstraintAdjustment::kAdjustmentSlideY) != OwnedWindowConstraintAdjustment::kAdjustmentNone) res |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y; if ((constraint_adjustment & OwnedWindowConstraintAdjustment::kAdjustmentFlipX) != OwnedWindowConstraintAdjustment::kAdjustmentNone) res |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_X; if ((constraint_adjustment & OwnedWindowConstraintAdjustment::kAdjustmentFlipY) != OwnedWindowConstraintAdjustment::kAdjustmentNone) res |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y; if ((constraint_adjustment & OwnedWindowConstraintAdjustment::kAdjustmentResizeX) != OwnedWindowConstraintAdjustment::kAdjustmentNone) res |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_X; if ((constraint_adjustment & OwnedWindowConstraintAdjustment::kAdjustmentRezizeY) != OwnedWindowConstraintAdjustment::kAdjustmentNone) res |= XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_RESIZE_Y; return res; } } // namespace XDGPopupWrapperImpl::XDGPopupWrapperImpl( std::unique_ptr<XDGSurfaceWrapperImpl> surface, WaylandWindow* wayland_window, WaylandConnection* connection) : wayland_window_(wayland_window), connection_(connection), xdg_surface_wrapper_(std::move(surface)) { DCHECK(xdg_surface_wrapper_); DCHECK(wayland_window_ && wayland_window_->parent_window()); } XDGPopupWrapperImpl::~XDGPopupWrapperImpl() = default; bool XDGPopupWrapperImpl::Initialize(const ShellPopupParams& params) { if (!connection_->shell()) { NOTREACHED() << "Wrong shell protocol"; return false; } XDGSurfaceWrapperImpl* parent_xdg_surface = nullptr; // If the parent window is a popup, the surface of that popup must be used as // a parent. if (auto* parent_popup = wayland_window_->parent_window()->AsWaylandPopup()) { XDGPopupWrapperImpl* popup = static_cast<XDGPopupWrapperImpl*>(parent_popup->shell_popup()); parent_xdg_surface = popup->xdg_surface_wrapper(); } else { WaylandToplevelWindow* wayland_surface = static_cast<WaylandToplevelWindow*>(wayland_window_->parent_window()); parent_xdg_surface = static_cast<XDGToplevelWrapperImpl*>(wayland_surface->shell_toplevel()) ->xdg_surface_wrapper(); } if (!xdg_surface_wrapper_ || !parent_xdg_surface) return false; params_ = params; // Wayland doesn't allow empty bounds. If a zero or negative size is set, the // invalid_input error is raised. Thus, use the least possible one. // WaylandPopup will update its bounds upon the following configure event. if (params_.bounds.IsEmpty()) params_.bounds.set_size({1, 1}); static constexpr struct xdg_popup_listener xdg_popup_listener = { &XDGPopupWrapperImpl::Configure, &XDGPopupWrapperImpl::PopupDone, &XDGPopupWrapperImpl::Repositioned, }; auto positioner = CreatePositioner(); if (!positioner) return false; xdg_popup_.reset(xdg_surface_get_popup(xdg_surface_wrapper_->xdg_surface(), parent_xdg_surface->xdg_surface(), positioner.get())); if (!xdg_popup_) return false; connection_->window_manager()->NotifyWindowRoleAssigned(wayland_window_); if (connection_->zaura_shell()) { uint32_t version = zaura_shell_get_version(connection_->zaura_shell()->wl_object()); if (version >= ZAURA_SHELL_GET_AURA_POPUP_FOR_XDG_POPUP_SINCE_VERSION) { aura_popup_.reset(zaura_shell_get_aura_popup_for_xdg_popup( connection_->zaura_shell()->wl_object(), xdg_popup_.get())); if (IsWaylandSurfaceSubmissionInPixelCoordinatesEnabled() && version >= ZAURA_POPUP_SURFACE_SUBMISSION_IN_PIXEL_COORDINATES_SINCE_VERSION) { zaura_popup_surface_submission_in_pixel_coordinates(aura_popup_.get()); } if (version >= ZAURA_POPUP_SET_MENU_SINCE_VERSION && wayland_window_->type() == PlatformWindowType::kMenu) { zaura_popup_set_menu(aura_popup_.get()); } } } GrabIfPossible(connection_, wayland_window_->parent_window()); xdg_popup_add_listener(xdg_popup_.get(), &xdg_popup_listener, this); wayland_window_->root_surface()->Commit(); return true; } void XDGPopupWrapperImpl::AckConfigure(uint32_t serial) { DCHECK(xdg_surface_wrapper_); xdg_surface_wrapper_->AckConfigure(serial); } bool XDGPopupWrapperImpl::IsConfigured() { DCHECK(xdg_surface_wrapper_); return xdg_surface_wrapper_->IsConfigured(); } bool XDGPopupWrapperImpl::SetBounds(const gfx::Rect& new_bounds) { if (xdg_popup_get_version(xdg_popup_.get()) < XDG_POPUP_REPOSITIONED_SINCE_VERSION) { return false; } params_.bounds = new_bounds; // Create a new positioner with new bounds. auto positioner = CreatePositioner(); if (!positioner) return false; // TODO(msisov): figure out how we can make use of the reposition token. // The protocol says the token itself is opaque, and has no other special // meaning. xdg_popup_reposition(xdg_popup_.get(), positioner.get(), ++next_reposition_token_); connection_->Flush(); return true; } void XDGPopupWrapperImpl::SetWindowGeometry(const gfx::Rect& bounds) { xdg_surface_set_window_geometry(xdg_surface_wrapper_->xdg_surface(), bounds.x(), bounds.y(), bounds.width(), bounds.height()); } void XDGPopupWrapperImpl::Grab(uint32_t serial) { xdg_popup_grab(xdg_popup_.get(), connection_->seat()->wl_object(), serial); } bool XDGPopupWrapperImpl::SupportsDecoration() { if (!aura_popup_) return false; uint32_t version = zaura_popup_get_version(aura_popup_.get()); return version >= ZAURA_POPUP_SET_DECORATION_SINCE_VERSION; } void XDGPopupWrapperImpl::Decorate() { zaura_popup_set_decoration(aura_popup_.get(), ZAURA_POPUP_DECORATION_TYPE_SHADOW); } void XDGPopupWrapperImpl::SetScaleFactor(float scale_factor) { if (aura_popup_ && zaura_popup_get_version(aura_popup_.get()) >= ZAURA_POPUP_SET_SCALE_FACTOR_SINCE_VERSION) { uint32_t value = *reinterpret_cast<uint32_t*>(&scale_factor); zaura_popup_set_scale_factor(aura_popup_.get(), value); } } XDGPopupWrapperImpl* XDGPopupWrapperImpl::AsXDGPopupWrapper() { return this; } wl::Object<xdg_positioner> XDGPopupWrapperImpl::CreatePositioner() { wl::Object<xdg_positioner> positioner( xdg_wm_base_create_positioner(connection_->shell())); if (!positioner) return {}; gfx::Rect anchor_rect; OwnedWindowAnchorPosition anchor_position; OwnedWindowAnchorGravity anchor_gravity; OwnedWindowConstraintAdjustment constraint_adjustment; FillAnchorData(params_, &anchor_rect, &anchor_position, &anchor_gravity, &constraint_adjustment); xdg_positioner_set_anchor_rect(positioner.get(), anchor_rect.x(), anchor_rect.y(), anchor_rect.width(), anchor_rect.height()); xdg_positioner_set_size(positioner.get(), params_.bounds.width(), params_.bounds.height()); xdg_positioner_set_anchor(positioner.get(), TranslateAnchor(anchor_position)); xdg_positioner_set_gravity(positioner.get(), TranslateGravity(anchor_gravity)); xdg_positioner_set_constraint_adjustment( positioner.get(), TranslateConstraintAdjustment(constraint_adjustment)); return positioner; } // static void XDGPopupWrapperImpl::Configure(void* data, struct xdg_popup* xdg_popup, int32_t x, int32_t y, int32_t width, int32_t height) { // As long as the Wayland compositor repositions/requires to position windows // relative to their parents, do not propagate final bounds information to // Chromium. The browser places windows in respect to screen origin, but // Wayland requires doing so in respect to parent window's origin. To properly // place windows, the bounds are translated and adjusted according to the // Wayland compositor needs during WaylandWindow::CreateXdgPopup call. WaylandWindow* window = static_cast<XDGPopupWrapperImpl*>(data)->wayland_window_; DCHECK(window); window->HandlePopupConfigure({x, y, width, height}); } // static void XDGPopupWrapperImpl::PopupDone(void* data, struct xdg_popup* xdg_popup) { WaylandWindow* window = static_cast<XDGPopupWrapperImpl*>(data)->wayland_window_; DCHECK(window); window->Hide(); window->OnCloseRequest(); } // static void XDGPopupWrapperImpl::Repositioned(void* data, struct xdg_popup* xdg_popup, uint32_t token) { NOTIMPLEMENTED_LOG_ONCE(); } XDGSurfaceWrapperImpl* XDGPopupWrapperImpl::xdg_surface_wrapper() const { DCHECK(xdg_surface_wrapper_.get()); return xdg_surface_wrapper_.get(); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_popup_wrapper_impl.cc
C++
unknown
12,632
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_POPUP_WRAPPER_IMPL_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_POPUP_WRAPPER_IMPL_H_ #include <memory> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/host/shell_popup_wrapper.h" namespace ui { class XDGSurfaceWrapperImpl; class WaylandConnection; class WaylandWindow; // Popup wrapper for xdg-shell stable class XDGPopupWrapperImpl : public ShellPopupWrapper { public: XDGPopupWrapperImpl(std::unique_ptr<XDGSurfaceWrapperImpl> surface, WaylandWindow* wayland_window, WaylandConnection* connection); XDGPopupWrapperImpl(const XDGPopupWrapperImpl&) = delete; XDGPopupWrapperImpl& operator=(const XDGPopupWrapperImpl&) = delete; ~XDGPopupWrapperImpl() override; // ShellPopupWrapper overrides: bool Initialize(const ShellPopupParams& params) override; void AckConfigure(uint32_t serial) override; bool IsConfigured() override; bool SetBounds(const gfx::Rect& new_bounds) override; void SetWindowGeometry(const gfx::Rect& bounds) override; void Grab(uint32_t serial) override; bool SupportsDecoration() override; void Decorate() override; void SetScaleFactor(float scale_factor) override; XDGPopupWrapperImpl* AsXDGPopupWrapper() override; private: wl::Object<xdg_positioner> CreatePositioner(); // xdg_popup_listener static void Configure(void* data, struct xdg_popup* xdg_popup, int32_t x, int32_t y, int32_t width, int32_t height); static void PopupDone(void* data, struct xdg_popup* xdg_popup); static void Repositioned(void* data, struct xdg_popup* xdg_popup, uint32_t token); XDGSurfaceWrapperImpl* xdg_surface_wrapper() const; // Non-owned WaylandWindow that uses this popup. const raw_ptr<WaylandWindow> wayland_window_; const raw_ptr<WaylandConnection> connection_; // Ground surface for this popup. std::unique_ptr<XDGSurfaceWrapperImpl> xdg_surface_wrapper_; // XDG Shell Stable object. wl::Object<xdg_popup> xdg_popup_; // Aura shell popup object wl::Object<zaura_popup> aura_popup_; // Parameters that help to configure this popup. ShellPopupParams params_; uint32_t next_reposition_token_ = 1; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_POPUP_WRAPPER_IMPL_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_popup_wrapper_impl.h
C++
unknown
2,641
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.h" #include <xdg-shell-client-protocol.h> #include "base/logging.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" namespace ui { XDGSurfaceWrapperImpl::XDGSurfaceWrapperImpl(WaylandWindow* wayland_window, WaylandConnection* connection) : wayland_window_(wayland_window), connection_(connection) {} XDGSurfaceWrapperImpl::~XDGSurfaceWrapperImpl() { is_configured_ = false; connection_->window_manager()->NotifyWindowConfigured(wayland_window_); } bool XDGSurfaceWrapperImpl::Initialize() { if (!connection_->shell()) { NOTREACHED() << "Wrong shell protocol"; return false; } static constexpr xdg_surface_listener xdg_surface_listener = { &Configure, }; xdg_surface_.reset(xdg_wm_base_get_xdg_surface( connection_->shell(), wayland_window_->root_surface()->surface())); if (!xdg_surface_) { LOG(ERROR) << "Failed to create xdg_surface"; return false; } xdg_surface_add_listener(xdg_surface_.get(), &xdg_surface_listener, this); connection_->Flush(); return true; } void XDGSurfaceWrapperImpl::AckConfigure(uint32_t serial) { // We must not ack any serial more than once, so check for that here. DCHECK_LE(last_acked_serial_, serial); if (serial == last_acked_serial_) { return; } last_acked_serial_ = serial; DCHECK(xdg_surface_); xdg_surface_ack_configure(xdg_surface_.get(), serial); is_configured_ = true; connection_->window_manager()->NotifyWindowConfigured(wayland_window_); } bool XDGSurfaceWrapperImpl::IsConfigured() { return is_configured_; } void XDGSurfaceWrapperImpl::SetWindowGeometry(const gfx::Rect& bounds) { DCHECK(xdg_surface_); CHECK(!bounds.IsEmpty()) << "The xdg-shell protocol specification forbids " "empty bounds (zero width or height). bounds=" << bounds.ToString(); xdg_surface_set_window_geometry(xdg_surface_.get(), bounds.x(), bounds.y(), bounds.width(), bounds.height()); } XDGSurfaceWrapperImpl* XDGSurfaceWrapperImpl::AsXDGSurfaceWrapper() { return this; } xdg_surface* XDGSurfaceWrapperImpl::xdg_surface() const { DCHECK(xdg_surface_); return xdg_surface_.get(); } // static void XDGSurfaceWrapperImpl::Configure(void* data, struct xdg_surface* xdg_surface, uint32_t serial) { auto* surface = static_cast<XDGSurfaceWrapperImpl*>(data); DCHECK(surface); // Calls to HandleSurfaceConfigure() might end up hiding the enclosing // toplevel window, and deleting this object. auto weak_window = surface->wayland_window_->AsWeakPtr(); weak_window->HandleSurfaceConfigure(serial); if (!weak_window) return; weak_window->OnSurfaceConfigureEvent(); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.cc
C++
unknown
3,123
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_SURFACE_WRAPPER_IMPL_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_SURFACE_WRAPPER_IMPL_H_ #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/host/shell_surface_wrapper.h" #include <cstdint> #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace gfx { class Rect; } namespace ui { class WaylandConnection; class WaylandWindow; // Surface wrapper for xdg-shell stable class XDGSurfaceWrapperImpl : public ShellSurfaceWrapper { public: XDGSurfaceWrapperImpl(WaylandWindow* wayland_window, WaylandConnection* connection); XDGSurfaceWrapperImpl(const XDGSurfaceWrapperImpl&) = delete; XDGSurfaceWrapperImpl& operator=(const XDGSurfaceWrapperImpl&) = delete; ~XDGSurfaceWrapperImpl() override; // ShellSurfaceWrapper overrides: bool Initialize() override; void AckConfigure(uint32_t serial) override; bool IsConfigured() override; void SetWindowGeometry(const gfx::Rect& bounds) override; XDGSurfaceWrapperImpl* AsXDGSurfaceWrapper() override; struct xdg_surface* xdg_surface() const; private: // xdg_surface_listener static void Configure(void* data, struct xdg_surface* xdg_surface, uint32_t serial); // Non-owing WaylandWindow that uses this surface wrapper. const raw_ptr<WaylandWindow> wayland_window_; const raw_ptr<WaylandConnection> connection_; bool is_configured_ = false; int64_t last_acked_serial_ = -1; wl::Object<struct xdg_surface> xdg_surface_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_SURFACE_WRAPPER_IMPL_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.h
C++
unknown
1,796
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/xdg_toplevel_wrapper_impl.h" #include <aura-shell-client-protocol.h> #include <xdg-decoration-unstable-v1-client-protocol.h> #include "base/logging.h" #include "base/notreached.h" #include "base/strings/utf_string_conversions.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "ui/base/hit_test.h" #include "ui/base/ui_base_features.h" #include "ui/ozone/common/features.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/common/wayland_util.h" #include "ui/ozone/platform/wayland/host/shell_surface_wrapper.h" #include "ui/ozone/platform/wayland/host/shell_toplevel_wrapper.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_output.h" #include "ui/ozone/platform/wayland/host/wayland_output_manager.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_serial_tracker.h" #include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/host/wayland_zaura_shell.h" #include "ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.h" namespace ui { namespace { static_assert(sizeof(uint32_t) == sizeof(float), "Sizes much match for reinterpret cast to be meaningful"); XDGToplevelWrapperImpl::DecorationMode ToDecorationMode(uint32_t mode) { switch (mode) { case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: return XDGToplevelWrapperImpl::DecorationMode::kClientSide; case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: return XDGToplevelWrapperImpl::DecorationMode::kServerSide; default: NOTREACHED(); return XDGToplevelWrapperImpl::DecorationMode::kClientSide; } } uint32_t ToInt32(XDGToplevelWrapperImpl::DecorationMode mode) { switch (mode) { case XDGToplevelWrapperImpl::DecorationMode::kClientSide: return ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; case XDGToplevelWrapperImpl::DecorationMode::kServerSide: return ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE; default: NOTREACHED(); return ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE; } } absl::optional<wl::Serial> GetSerialForMoveResize( WaylandConnection* connection) { return connection->serial_tracker().GetSerial({wl::SerialType::kTouchPress, wl::SerialType::kMousePress, wl::SerialType::kKeyPress}); } zaura_toplevel_z_order_level ToZauraToplevelZOrderLevel( ZOrderLevel z_order_level) { switch (z_order_level) { case ZOrderLevel::kNormal: return ZAURA_TOPLEVEL_Z_ORDER_LEVEL_NORMAL; case ZOrderLevel::kFloatingWindow: return ZAURA_TOPLEVEL_Z_ORDER_LEVEL_FLOATING_WINDOW; case ZOrderLevel::kFloatingUIElement: return ZAURA_TOPLEVEL_Z_ORDER_LEVEL_FLOATING_UI_ELEMENT; case ZOrderLevel::kSecuritySurface: return ZAURA_TOPLEVEL_Z_ORDER_LEVEL_SECURITY_SURFACE; } NOTREACHED(); return ZAURA_TOPLEVEL_Z_ORDER_LEVEL_NORMAL; } } // namespace XDGToplevelWrapperImpl::XDGToplevelWrapperImpl( std::unique_ptr<XDGSurfaceWrapperImpl> surface, WaylandWindow* wayland_window, WaylandConnection* connection) : xdg_surface_wrapper_(std::move(surface)), wayland_window_(wayland_window), connection_(connection), decoration_mode_(DecorationMode::kNone) {} XDGToplevelWrapperImpl::~XDGToplevelWrapperImpl() = default; bool XDGToplevelWrapperImpl::Initialize() { if (!connection_->shell()) { NOTREACHED() << "Wrong shell protocol"; return false; } static constexpr xdg_toplevel_listener xdg_toplevel_listener = { &ConfigureTopLevel, &CloseTopLevel, // Since v4 &ConfigureBounds, // Since v5 &WmCapabilities, }; if (!xdg_surface_wrapper_) return false; xdg_toplevel_.reset( xdg_surface_get_toplevel(xdg_surface_wrapper_->xdg_surface())); if (!xdg_toplevel_) { LOG(ERROR) << "Failed to create xdg_toplevel"; return false; } connection_->window_manager()->NotifyWindowRoleAssigned(wayland_window_); if (connection_->zaura_shell()) { uint32_t version = zaura_shell_get_version(connection_->zaura_shell()->wl_object()); if (version >= ZAURA_SHELL_GET_AURA_TOPLEVEL_FOR_XDG_TOPLEVEL_SINCE_VERSION) { aura_toplevel_.reset(zaura_shell_get_aura_toplevel_for_xdg_toplevel( connection_->zaura_shell()->wl_object(), xdg_toplevel_.get())); if (ui::IsWaylandSurfaceSubmissionInPixelCoordinatesEnabled() && version >= ZAURA_TOPLEVEL_SURFACE_SUBMISSION_IN_PIXEL_COORDINATES_SINCE_VERSION) { zaura_toplevel_surface_submission_in_pixel_coordinates( aura_toplevel_.get()); } } } xdg_toplevel_add_listener(xdg_toplevel_.get(), &xdg_toplevel_listener, this); InitializeXdgDecoration(); return true; } bool XDGToplevelWrapperImpl::IsSupportedOnAuraToplevel(uint32_t version) const { return aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= version; } void XDGToplevelWrapperImpl::SetMaximized() { DCHECK(xdg_toplevel_); xdg_toplevel_set_maximized(xdg_toplevel_.get()); } void XDGToplevelWrapperImpl::UnSetMaximized() { DCHECK(xdg_toplevel_); xdg_toplevel_unset_maximized(xdg_toplevel_.get()); } void XDGToplevelWrapperImpl::SetFullscreen() { DCHECK(xdg_toplevel_); xdg_toplevel_set_fullscreen(xdg_toplevel_.get(), nullptr); } #if BUILDFLAG(IS_CHROMEOS_LACROS) void XDGToplevelWrapperImpl::SetUseImmersiveMode(bool immersive) { if (SupportsTopLevelImmersiveStatus()) { auto mode = immersive ? ZAURA_TOPLEVEL_FULLSCREEN_MODE_IMMERSIVE : ZAURA_TOPLEVEL_FULLSCREEN_MODE_PLAIN; zaura_toplevel_set_fullscreen_mode(aura_toplevel_.get(), mode); } } bool XDGToplevelWrapperImpl::SupportsTopLevelImmersiveStatus() const { return aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_FULLSCREEN_MODE_SINCE_VERSION; } #endif void XDGToplevelWrapperImpl::UnSetFullscreen() { DCHECK(xdg_toplevel_); xdg_toplevel_unset_fullscreen(xdg_toplevel_.get()); } void XDGToplevelWrapperImpl::SetMinimized() { DCHECK(xdg_toplevel_); xdg_toplevel_set_minimized(xdg_toplevel_.get()); } void XDGToplevelWrapperImpl::SurfaceMove(WaylandConnection* connection) { DCHECK(xdg_toplevel_); if (auto serial = GetSerialForMoveResize(connection)) xdg_toplevel_move(xdg_toplevel_.get(), connection->seat()->wl_object(), serial->value); } void XDGToplevelWrapperImpl::SurfaceResize(WaylandConnection* connection, uint32_t hittest) { DCHECK(xdg_toplevel_); if (auto serial = GetSerialForMoveResize(connection)) { xdg_toplevel_resize(xdg_toplevel_.get(), connection->seat()->wl_object(), serial->value, wl::IdentifyDirection(hittest)); } } void XDGToplevelWrapperImpl::SetTitle(const std::u16string& title) { DCHECK(xdg_toplevel_); // TODO(crbug.com/1241097): find a better way to handle long titles, or change // this logic completely (and at the platform-agnostic level) because a title // that long does not make any sense. // // A long title may exceed the maximum size of the Wayland event sent below // upon calling xdg_toplevel_set_title(), which results in a fatal Wayland // communication error and termination of the process. 4096 bytes is the // limit for the size of the entire message; here we set 4000 as the maximum // length of the string so it would fit the message with some margin. const size_t kMaxLengh = 4000; auto short_title = base::UTF16ToUTF8(title); if (short_title.size() > kMaxLengh) short_title.resize(kMaxLengh); xdg_toplevel_set_title(xdg_toplevel_.get(), short_title.c_str()); } void XDGToplevelWrapperImpl::SetWindowGeometry(const gfx::Rect& bounds) { xdg_surface_wrapper_->SetWindowGeometry(bounds); } void XDGToplevelWrapperImpl::SetMinSize(int32_t width, int32_t height) { DCHECK(xdg_toplevel_); xdg_toplevel_set_min_size(xdg_toplevel_.get(), width, height); } void XDGToplevelWrapperImpl::SetMaxSize(int32_t width, int32_t height) { DCHECK(xdg_toplevel_); xdg_toplevel_set_max_size(xdg_toplevel_.get(), width, height); } void XDGToplevelWrapperImpl::SetAppId(const std::string& app_id) { DCHECK(xdg_toplevel_); xdg_toplevel_set_app_id(xdg_toplevel_.get(), app_id.c_str()); } void XDGToplevelWrapperImpl::SetDecoration(DecorationMode decoration) { SetTopLevelDecorationMode(decoration); } void XDGToplevelWrapperImpl::AckConfigure(uint32_t serial) { DCHECK(xdg_surface_wrapper_); xdg_surface_wrapper_->AckConfigure(serial); } bool XDGToplevelWrapperImpl::IsConfigured() { DCHECK(xdg_surface_wrapper_); return xdg_surface_wrapper_->IsConfigured(); } // static void XDGToplevelWrapperImpl::ConfigureTopLevel( void* data, struct xdg_toplevel* xdg_toplevel, int32_t width, int32_t height, struct wl_array* states) { auto* surface = static_cast<XDGToplevelWrapperImpl*>(data); DCHECK(surface); WaylandWindow::WindowStates window_states{ .is_maximized = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_MAXIMIZED), .is_fullscreen = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_FULLSCREEN), .is_activated = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_ACTIVATED), }; #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) if (xdg_toplevel_get_version(xdg_toplevel) >= XDG_TOPLEVEL_STATE_TILED_LEFT_SINCE_VERSION) { // All four tiled states have the same since version, so it is enough to // check only one. window_states.tiled_edges = { .left = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_TILED_LEFT), .right = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_TILED_RIGHT), .top = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_TILED_TOP), .bottom = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_TILED_BOTTOM)}; } #endif // IS_LINUX || IS_CHROMEOS_LACROS surface->wayland_window_->HandleToplevelConfigure(width, height, window_states); } // static void XDGToplevelWrapperImpl::ConfigureAuraTopLevel( void* data, struct zaura_toplevel* zaura_toplevel, int32_t x, int32_t y, int32_t width, int32_t height, struct wl_array* states) { auto* surface = static_cast<XDGToplevelWrapperImpl*>(data); DCHECK(surface); surface->wayland_window_->HandleAuraToplevelConfigure(x, y, width, height, { .is_maximized = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_MAXIMIZED), .is_fullscreen = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_FULLSCREEN), #if BUILDFLAG(IS_CHROMEOS_LACROS) .is_immersive_fullscreen = CheckIfWlArrayHasValue(states, ZAURA_TOPLEVEL_STATE_IMMERSIVE), #endif .is_activated = CheckIfWlArrayHasValue(states, XDG_TOPLEVEL_STATE_ACTIVATED), .is_minimized = CheckIfWlArrayHasValue(states, ZAURA_TOPLEVEL_STATE_MINIMIZED), .is_snapped_primary = CheckIfWlArrayHasValue(states, ZAURA_TOPLEVEL_STATE_SNAPPED_PRIMARY), .is_snapped_secondary = CheckIfWlArrayHasValue(states, ZAURA_TOPLEVEL_STATE_SNAPPED_SECONDARY), .is_floated = CheckIfWlArrayHasValue(states, ZAURA_TOPLEVEL_STATE_FLOATED) }); } // static void XDGToplevelWrapperImpl::OnOriginChange( void* data, struct zaura_toplevel* zaura_toplevel, int32_t x, int32_t y) { auto* surface = static_cast<XDGToplevelWrapperImpl*>(data); DCHECK(surface); auto* wayland_toplevel_window = static_cast<WaylandToplevelWindow*>(surface->wayland_window_); wayland_toplevel_window->SetOrigin(gfx::Point(x, y)); } // static void XDGToplevelWrapperImpl::ConfigureRasterScale( void* data, struct zaura_toplevel* zaura_toplevel, uint32_t scale_as_uint) { auto* surface = static_cast<XDGToplevelWrapperImpl*>(data); DCHECK(surface); auto* wayland_window = static_cast<WaylandWindow*>(surface->wayland_window_); float scale = *reinterpret_cast<float*>(&scale_as_uint); wayland_window->SetPendingRasterScale(scale); } // static void XDGToplevelWrapperImpl::CloseTopLevel(void* data, struct xdg_toplevel* xdg_toplevel) { auto* surface = static_cast<XDGToplevelWrapperImpl*>(data); DCHECK(surface); surface->wayland_window_->OnCloseRequest(); } // static void XDGToplevelWrapperImpl::ConfigureBounds(void* data, struct xdg_toplevel* xdg_toplevel, int32_t width, int32_t height) { NOTIMPLEMENTED_LOG_ONCE(); } // static void XDGToplevelWrapperImpl::WmCapabilities(void* data, struct xdg_toplevel* xdg_toplevel, struct wl_array* capabilities) { NOTIMPLEMENTED_LOG_ONCE(); } void XDGToplevelWrapperImpl::SetTopLevelDecorationMode( DecorationMode requested_mode) { if (!zxdg_toplevel_decoration_ || requested_mode == decoration_mode_) return; zxdg_toplevel_decoration_v1_set_mode(zxdg_toplevel_decoration_.get(), ToInt32(requested_mode)); } // static void XDGToplevelWrapperImpl::ConfigureDecoration( void* data, struct zxdg_toplevel_decoration_v1* decoration, uint32_t mode) { auto* surface = static_cast<XDGToplevelWrapperImpl*>(data); DCHECK(surface); surface->decoration_mode_ = ToDecorationMode(mode); } void XDGToplevelWrapperImpl::InitializeXdgDecoration() { if (connection_->xdg_decoration_manager_v1()) { DCHECK(!zxdg_toplevel_decoration_); static constexpr zxdg_toplevel_decoration_v1_listener decoration_listener = { &ConfigureDecoration, }; zxdg_toplevel_decoration_.reset( zxdg_decoration_manager_v1_get_toplevel_decoration( connection_->xdg_decoration_manager_v1(), xdg_toplevel_.get())); zxdg_toplevel_decoration_v1_add_listener(zxdg_toplevel_decoration_.get(), &decoration_listener, this); } } XDGSurfaceWrapperImpl* XDGToplevelWrapperImpl::xdg_surface_wrapper() const { DCHECK(xdg_surface_wrapper_.get()); return xdg_surface_wrapper_.get(); } zaura_toplevel_orientation_lock ToZauraSurfaceOrientationLock( WaylandOrientationLockType lock_type) { switch (lock_type) { case WaylandOrientationLockType::kLandscape: return ZAURA_TOPLEVEL_ORIENTATION_LOCK_LANDSCAPE; case WaylandOrientationLockType::kLandscapePrimary: return ZAURA_TOPLEVEL_ORIENTATION_LOCK_LANDSCAPE_PRIMARY; case WaylandOrientationLockType::kLandscapeSecondary: return ZAURA_TOPLEVEL_ORIENTATION_LOCK_LANDSCAPE_SECONDARY; case WaylandOrientationLockType::kPortrait: return ZAURA_TOPLEVEL_ORIENTATION_LOCK_PORTRAIT; case WaylandOrientationLockType::kPortraitPrimary: return ZAURA_TOPLEVEL_ORIENTATION_LOCK_PORTRAIT_PRIMARY; case WaylandOrientationLockType::kPortraitSecondary: return ZAURA_TOPLEVEL_ORIENTATION_LOCK_PORTRAIT_SECONDARY; case WaylandOrientationLockType::kAny: return ZAURA_TOPLEVEL_ORIENTATION_LOCK_NONE; case WaylandOrientationLockType::kNatural: return ZAURA_TOPLEVEL_ORIENTATION_LOCK_CURRENT; } return ZAURA_TOPLEVEL_ORIENTATION_LOCK_NONE; } void XDGToplevelWrapperImpl::Lock(WaylandOrientationLockType lock_type) { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_ORIENTATION_LOCK_SINCE_VERSION) { zaura_toplevel_set_orientation_lock( aura_toplevel_.get(), ToZauraSurfaceOrientationLock(lock_type)); } } void XDGToplevelWrapperImpl::Unlock() { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_ORIENTATION_LOCK_SINCE_VERSION) { zaura_toplevel_set_orientation_lock(aura_toplevel_.get(), ZAURA_TOPLEVEL_ORIENTATION_LOCK_NONE); } } void XDGToplevelWrapperImpl::RequestWindowBounds(const gfx::Rect& bounds) { DCHECK(SupportsScreenCoordinates()); const auto entered_id = wayland_window_->GetPreferredEnteredOutputId(); const WaylandOutputManager* manager = connection_->wayland_output_manager(); WaylandOutput* entered_output = entered_id.has_value() ? manager->GetOutput(entered_id.value()) : manager->GetPrimaryOutput(); // Output can be null when the surface has been just created. It should // probably be inferred in that case. LOG_IF(WARNING, !entered_id.has_value()) << "No output has been entered yet."; // `entered_output` can be null in unit tests, where it doesn't wait for // output events. if (!entered_output) { DLOG(WARNING) << "Entered output is null, cannot request window bounds."; return; } if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_WINDOW_BOUNDS_SINCE_VERSION) { zaura_toplevel_set_window_bounds( aura_toplevel_.get(), bounds.x(), bounds.y(), bounds.width(), bounds.height(), entered_output->get_output()); } } void XDGToplevelWrapperImpl::SetSystemModal(bool modal) { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_SYSTEM_MODAL_SINCE_VERSION) { if (modal) { zaura_toplevel_set_system_modal(aura_toplevel_.get()); } else { zaura_toplevel_unset_system_modal(aura_toplevel_.get()); } } } bool XDGToplevelWrapperImpl::SupportsScreenCoordinates() const { return aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_SUPPORTS_SCREEN_COORDINATES_SINCE_VERSION; } void XDGToplevelWrapperImpl::EnableScreenCoordinates() { if (!features::IsWaylandScreenCoordinatesEnabled()) return; if (!SupportsScreenCoordinates()) { LOG(WARNING) << "Server implementation of wayland is incompatible, " "WaylandScreenCoordinatesEnabled has no effect."; return; } zaura_toplevel_set_supports_screen_coordinates(aura_toplevel_.get()); static constexpr zaura_toplevel_listener aura_toplevel_listener = { &ConfigureAuraTopLevel, &OnOriginChange, &ConfigureRasterScale}; zaura_toplevel_add_listener(aura_toplevel_.get(), &aura_toplevel_listener, this); } void XDGToplevelWrapperImpl::SetZOrder(ZOrderLevel z_order) { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_Z_ORDER_SINCE_VERSION) { zaura_toplevel_set_z_order(aura_toplevel_.get(), ToZauraToplevelZOrderLevel(z_order)); } } bool XDGToplevelWrapperImpl::SupportsActivation() { static_assert( ZAURA_TOPLEVEL_ACTIVATE_SINCE_VERSION == ZAURA_TOPLEVEL_DEACTIVATE_SINCE_VERSION, "Support for activation and deactivation was added in the same version."); return aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_ACTIVATE_SINCE_VERSION; } void XDGToplevelWrapperImpl::Activate() { if (aura_toplevel_ && SupportsActivation()) { zaura_toplevel_activate(aura_toplevel_.get()); } } void XDGToplevelWrapperImpl::Deactivate() { if (aura_toplevel_ && SupportsActivation()) { zaura_toplevel_deactivate(aura_toplevel_.get()); } } void XDGToplevelWrapperImpl::SetScaleFactor(float scale_factor) { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_SCALE_FACTOR_SINCE_VERSION) { uint32_t value = *reinterpret_cast<uint32_t*>(&scale_factor); zaura_toplevel_set_scale_factor(aura_toplevel_.get(), value); } } void XDGToplevelWrapperImpl::SetRestoreInfo(int32_t restore_session_id, int32_t restore_window_id) { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_RESTORE_INFO_SINCE_VERSION) { zaura_toplevel_set_restore_info(aura_toplevel_.get(), restore_session_id, restore_window_id); } } void XDGToplevelWrapperImpl::SetRestoreInfoWithWindowIdSource( int32_t restore_session_id, const std::string& restore_window_id_source) { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_RESTORE_INFO_WITH_WINDOW_ID_SOURCE_SINCE_VERSION) { zaura_toplevel_set_restore_info_with_window_id_source( aura_toplevel_.get(), restore_session_id, restore_window_id_source.c_str()); } } void XDGToplevelWrapperImpl::SetFloat() { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_FLOAT_SINCE_VERSION) { zaura_toplevel_set_float(aura_toplevel_.get()); } } void XDGToplevelWrapperImpl::UnSetFloat() { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_UNSET_FLOAT_SINCE_VERSION) { zaura_toplevel_unset_float(aura_toplevel_.get()); } } void XDGToplevelWrapperImpl::CommitSnap( WaylandWindowSnapDirection snap_direction, float snap_ratio) { if (!aura_toplevel_) { return; } if (zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_UNSET_SNAP_SINCE_VERSION && snap_direction == WaylandWindowSnapDirection::kNone) { zaura_toplevel_unset_snap(aura_toplevel_.get()); return; } if (zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_SET_SNAP_PRIMARY_SINCE_VERSION) { uint32_t value = *reinterpret_cast<uint32_t*>(&snap_ratio); switch (snap_direction) { case WaylandWindowSnapDirection::kPrimary: zaura_toplevel_set_snap_primary(aura_toplevel_.get(), value); return; case WaylandWindowSnapDirection::kSecondary: zaura_toplevel_set_snap_secondary(aura_toplevel_.get(), value); return; case WaylandWindowSnapDirection::kNone: NOTREACHED() << "Toplevel does not support UnsetSnap yet"; return; } } } void XDGToplevelWrapperImpl::ShowSnapPreview( WaylandWindowSnapDirection snap_direction, bool allow_haptic_feedback) { if (aura_toplevel_ && zaura_toplevel_get_version(aura_toplevel_.get()) >= ZAURA_TOPLEVEL_INTENT_TO_SNAP_SINCE_VERSION) { uint32_t zaura_shell_snap_direction = ZAURA_TOPLEVEL_SNAP_DIRECTION_NONE; switch (snap_direction) { case WaylandWindowSnapDirection::kPrimary: zaura_shell_snap_direction = ZAURA_TOPLEVEL_SNAP_DIRECTION_PRIMARY; break; case WaylandWindowSnapDirection::kSecondary: zaura_shell_snap_direction = ZAURA_TOPLEVEL_SNAP_DIRECTION_SECONDARY; break; case WaylandWindowSnapDirection::kNone: break; } zaura_toplevel_intent_to_snap(aura_toplevel_.get(), zaura_shell_snap_direction); return; } } XDGToplevelWrapperImpl* XDGToplevelWrapperImpl::AsXDGToplevelWrapper() { return this; } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_toplevel_wrapper_impl.cc
C++
unknown
23,837
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_TOPLEVEL_WRAPPER_IMPL_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_TOPLEVEL_WRAPPER_IMPL_H_ #include <xdg-shell-client-protocol.h> #include <memory> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/host/shell_toplevel_wrapper.h" namespace ui { class XDGSurfaceWrapperImpl; class WaylandConnection; class WaylandWindow; // Toplevel wrapper for xdg-shell stable class XDGToplevelWrapperImpl : public ShellToplevelWrapper { public: XDGToplevelWrapperImpl(std::unique_ptr<XDGSurfaceWrapperImpl> surface, WaylandWindow* wayland_window, WaylandConnection* connection); XDGToplevelWrapperImpl(const XDGToplevelWrapperImpl&) = delete; XDGToplevelWrapperImpl& operator=(const XDGToplevelWrapperImpl&) = delete; ~XDGToplevelWrapperImpl() override; // ShellToplevelWrapper overrides: bool Initialize() override; bool IsSupportedOnAuraToplevel(uint32_t version) const override; void SetMaximized() override; void UnSetMaximized() override; void SetFullscreen() override; void UnSetFullscreen() override; #if BUILDFLAG(IS_CHROMEOS_LACROS) void SetUseImmersiveMode(bool immersive) override; bool SupportsTopLevelImmersiveStatus() const override; #endif void SetMinimized() override; void SurfaceMove(WaylandConnection* connection) override; void SurfaceResize(WaylandConnection* connection, uint32_t hittest) override; void SetTitle(const std::u16string& title) override; void AckConfigure(uint32_t serial) override; bool IsConfigured() override; void SetWindowGeometry(const gfx::Rect& bounds) override; void SetMinSize(int32_t width, int32_t height) override; void SetMaxSize(int32_t width, int32_t height) override; void SetAppId(const std::string& app_id) override; void SetDecoration(DecorationMode decoration) override; void Lock(WaylandOrientationLockType lock_type) override; void Unlock() override; void RequestWindowBounds(const gfx::Rect& bounds) override; void SetRestoreInfo(int32_t, int32_t) override; void SetRestoreInfoWithWindowIdSource(int32_t, const std::string&) override; void SetSystemModal(bool modal) override; bool SupportsScreenCoordinates() const override; void EnableScreenCoordinates() override; void SetFloat() override; void UnSetFloat() override; void SetZOrder(ZOrderLevel z_order) override; bool SupportsActivation() override; void Activate() override; void Deactivate() override; void SetScaleFactor(float scale_factor) override; void CommitSnap(WaylandWindowSnapDirection snap_direction, float snap_ratio) override; void ShowSnapPreview(WaylandWindowSnapDirection snap_direction, bool allow_haptic_feedback) override; XDGToplevelWrapperImpl* AsXDGToplevelWrapper() override; XDGSurfaceWrapperImpl* xdg_surface_wrapper() const; private: // xdg_toplevel_listener static void ConfigureTopLevel(void* data, struct xdg_toplevel* xdg_toplevel, int32_t width, int32_t height, struct wl_array* states); static void CloseTopLevel(void* data, struct xdg_toplevel* xdg_toplevel); static void ConfigureBounds(void* data, struct xdg_toplevel* xdg_toplevel, int32_t width, int32_t height); static void WmCapabilities(void* data, struct xdg_toplevel* xdg_toplevel, struct wl_array* capabilities); // zxdg_decoration_listener static void ConfigureDecoration( void* data, struct zxdg_toplevel_decoration_v1* decoration, uint32_t mode); // aura_toplevel_listener static void ConfigureAuraTopLevel(void* data, struct zaura_toplevel* zaura_toplevel, int32_t x, int32_t y, int32_t width, int32_t height, struct wl_array* states); static void OnOriginChange(void* data, struct zaura_toplevel* zaura_toplevel, int32_t x, int32_t y); static void ConfigureRasterScale(void* data, struct zaura_toplevel* zaura_toplevel, uint32_t scale_as_uint); // Send request to wayland compositor to enable a requested decoration mode. void SetTopLevelDecorationMode(DecorationMode requested_mode); // Initializes the xdg-decoration protocol extension, if available. void InitializeXdgDecoration(); // Called when raster scale is changed. void OnConfigureRasterScale(double scale); // Ground surface for this toplevel wrapper. std::unique_ptr<XDGSurfaceWrapperImpl> xdg_surface_wrapper_; // Non-owing WaylandWindow that uses this toplevel wrapper. const raw_ptr<WaylandWindow> wayland_window_; const raw_ptr<WaylandConnection> connection_; // XDG Shell Stable object. wl::Object<xdg_toplevel> xdg_toplevel_; // Aura shell toplevel addons. wl::Object<zaura_toplevel> aura_toplevel_; wl::Object<zxdg_toplevel_decoration_v1> zxdg_toplevel_decoration_; // On client side, it keeps track of the decoration mode currently in // use if xdg-decoration protocol extension is available. DecorationMode decoration_mode_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_XDG_TOPLEVEL_WRAPPER_IMPL_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/xdg_toplevel_wrapper_impl.h
C++
unknown
5,821
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/zwp_idle_inhibit_manager.h" #include <idle-inhibit-unstable-v1-client-protocol.h> #include "base/logging.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; } // static constexpr char ZwpIdleInhibitManager::kInterfaceName[]; // static void ZwpIdleInhibitManager::Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->zwp_idle_inhibit_manager_ || !wl::CanBind(interface, version, kMinVersion, kMinVersion)) { return; } auto manager = wl::Bind<zwp_idle_inhibit_manager_v1>(registry, name, kMinVersion); if (!manager) { LOG(ERROR) << "Failed to bind zwp_idle_inhibit_manager_v1"; return; } connection->zwp_idle_inhibit_manager_ = std::make_unique<ZwpIdleInhibitManager>(manager.release(), connection); } ZwpIdleInhibitManager::ZwpIdleInhibitManager( zwp_idle_inhibit_manager_v1* manager, WaylandConnection* connection) : manager_(manager) {} ZwpIdleInhibitManager::~ZwpIdleInhibitManager() = default; wl::Object<zwp_idle_inhibitor_v1> ZwpIdleInhibitManager::CreateInhibitor( wl_surface* surface) { return wl::Object<zwp_idle_inhibitor_v1>( zwp_idle_inhibit_manager_v1_create_inhibitor(manager_.get(), surface)); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_idle_inhibit_manager.cc
C++
unknown
1,875
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_IDLE_INHIBIT_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_IDLE_INHIBIT_MANAGER_H_ #include "ui/ozone/platform/wayland/common/wayland_object.h" namespace ui { class WaylandConnection; // Wraps the idle inhibit manager, which is provided via // zwp_idle_inhibit_manager_v1 interface. class ZwpIdleInhibitManager : public wl::GlobalObjectRegistrar<ZwpIdleInhibitManager> { public: static constexpr char kInterfaceName[] = "zwp_idle_inhibit_manager_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); explicit ZwpIdleInhibitManager(zwp_idle_inhibit_manager_v1* manager, WaylandConnection* connection); ZwpIdleInhibitManager(const ZwpIdleInhibitManager&) = delete; ZwpIdleInhibitManager& operator=(const ZwpIdleInhibitManager&) = delete; ~ZwpIdleInhibitManager(); wl::Object<zwp_idle_inhibitor_v1> CreateInhibitor(wl_surface* surface); private: // Wayland object wrapped by this class. wl::Object<zwp_idle_inhibit_manager_v1> manager_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_IDLE_INHIBIT_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_idle_inhibit_manager.h
C++
unknown
1,485
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/zwp_primary_selection_device.h" #include <primary-selection-unstable-v1-client-protocol.h> #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_data_source.h" #include "ui/ozone/platform/wayland/host/zwp_primary_selection_offer.h" namespace ui { // static ZwpPrimarySelectionDevice::ZwpPrimarySelectionDevice( WaylandConnection* connection, zwp_primary_selection_device_v1* data_device) : WaylandDataDeviceBase(connection), data_device_(data_device) { static constexpr zwp_primary_selection_device_v1_listener kListener = { &OnDataOffer, &OnSelection}; zwp_primary_selection_device_v1_add_listener(data_device_.get(), &kListener, this); } ZwpPrimarySelectionDevice::~ZwpPrimarySelectionDevice() = default; void ZwpPrimarySelectionDevice::SetSelectionSource( ZwpPrimarySelectionSource* source, uint32_t serial) { auto* data_source = source ? source->data_source() : nullptr; zwp_primary_selection_device_v1_set_selection(data_device_.get(), data_source, serial); connection()->Flush(); } // static void ZwpPrimarySelectionDevice::OnDataOffer( void* data, zwp_primary_selection_device_v1* data_device, zwp_primary_selection_offer_v1* offer) { auto* self = static_cast<ZwpPrimarySelectionDevice*>(data); DCHECK(self); self->set_data_offer(std::make_unique<ZwpPrimarySelectionOffer>(offer)); } // static void ZwpPrimarySelectionDevice::OnSelection( void* data, zwp_primary_selection_device_v1* data_device, zwp_primary_selection_offer_v1* offer) { auto* self = static_cast<ZwpPrimarySelectionDevice*>(data); DCHECK(self); // 'offer' will be null to indicate that the selection is no longer valid, // i.e. there is no longer selection data available to be fetched. if (!offer) { self->ResetDataOffer(); } else { DCHECK(self->data_offer()); self->data_offer()->EnsureTextMimeTypeIfNeeded(); } self->NotifySelectionOffer(self->data_offer()); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_primary_selection_device.cc
C++
unknown
2,300
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_DEVICE_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_DEVICE_H_ #include <cstdint> #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/host/wayland_data_device_base.h" #include "ui/ozone/platform/wayland/host/wayland_data_source.h" struct zwp_primary_selection_device_v1; namespace ui { class WaylandConnection; // This class provides access to primary selection clipboard class ZwpPrimarySelectionDevice : public WaylandDataDeviceBase { public: ZwpPrimarySelectionDevice(WaylandConnection* connection, zwp_primary_selection_device_v1* data_device); ZwpPrimarySelectionDevice(const ZwpPrimarySelectionDevice&) = delete; ZwpPrimarySelectionDevice& operator=(const ZwpPrimarySelectionDevice&) = delete; ~ZwpPrimarySelectionDevice() override; zwp_primary_selection_device_v1* data_device() const { return data_device_.get(); } void SetSelectionSource(ZwpPrimarySelectionSource* source, uint32_t serial); private: // primary_selection_device_listener callbacks static void OnDataOffer(void* data, zwp_primary_selection_device_v1* data_device, zwp_primary_selection_offer_v1* offer); static void OnSelection(void* data, zwp_primary_selection_device_v1* data_device, zwp_primary_selection_offer_v1* offer); // The Wayland object wrapped by this instance. wl::Object<zwp_primary_selection_device_v1> data_device_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_DEVICE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_primary_selection_device.h
C++
unknown
1,852
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.h" #include <primary-selection-unstable-v1-client-protocol.h> #include <memory> #include "base/logging.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_data_source.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/zwp_primary_selection_device.h" namespace ui { namespace { constexpr uint32_t kMinVersion = 1; } // namespace // static constexpr char ZwpPrimarySelectionDeviceManager::kInterfaceName[]; // static void ZwpPrimarySelectionDeviceManager::Instantiate( WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version) { CHECK_EQ(interface, kInterfaceName) << "Expected \"" << kInterfaceName << "\" but got \"" << interface << "\""; if (connection->zwp_primary_selection_device_manager_ || !wl::CanBind(interface, version, kMinVersion, kMinVersion)) { return; } auto manager = wl::Bind<zwp_primary_selection_device_manager_v1>( registry, name, kMinVersion); if (!manager) { LOG(ERROR) << "Failed to bind zwp_primary_selection_device_manager_v1"; return; } connection->zwp_primary_selection_device_manager_ = std::make_unique<ZwpPrimarySelectionDeviceManager>(manager.release(), connection); } ZwpPrimarySelectionDeviceManager::ZwpPrimarySelectionDeviceManager( zwp_primary_selection_device_manager_v1* manager, WaylandConnection* connection) : device_manager_(manager), connection_(connection) { DCHECK(connection_); DCHECK(device_manager_); } ZwpPrimarySelectionDeviceManager::~ZwpPrimarySelectionDeviceManager() = default; ZwpPrimarySelectionDevice* ZwpPrimarySelectionDeviceManager::GetDevice() { DCHECK(connection_->seat()); if (!device_) { device_ = std::make_unique<ZwpPrimarySelectionDevice>( connection_, zwp_primary_selection_device_manager_v1_get_device( device_manager_.get(), connection_->seat()->wl_object())); connection_->Flush(); } DCHECK(device_); return device_.get(); } std::unique_ptr<ZwpPrimarySelectionSource> ZwpPrimarySelectionDeviceManager::CreateSource( ZwpPrimarySelectionSource::Delegate* delegate) { auto* data_source = zwp_primary_selection_device_manager_v1_create_source( device_manager_.get()); connection_->Flush(); return std::make_unique<ZwpPrimarySelectionSource>(data_source, connection_, delegate); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc
C++
unknown
2,864
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_DEVICE_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_DEVICE_MANAGER_H_ #include <memory> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/host/wayland_data_source.h" namespace ui { class ZwpPrimarySelectionDevice; class WaylandConnection; class ZwpPrimarySelectionDeviceManager : public wl::GlobalObjectRegistrar<ZwpPrimarySelectionDeviceManager> { public: static constexpr char kInterfaceName[] = "zwp_primary_selection_device_manager_v1"; static void Instantiate(WaylandConnection* connection, wl_registry* registry, uint32_t name, const std::string& interface, uint32_t version); using DataSource = ZwpPrimarySelectionSource; using DataDevice = ZwpPrimarySelectionDevice; ZwpPrimarySelectionDeviceManager( zwp_primary_selection_device_manager_v1* manager, WaylandConnection* connection); ZwpPrimarySelectionDeviceManager(const ZwpPrimarySelectionDeviceManager&) = delete; ZwpPrimarySelectionDeviceManager& operator=( const ZwpPrimarySelectionDeviceManager&) = delete; ~ZwpPrimarySelectionDeviceManager(); ZwpPrimarySelectionDevice* GetDevice(); std::unique_ptr<ZwpPrimarySelectionSource> CreateSource( ZwpPrimarySelectionSource::Delegate* delegate); private: wl::Object<zwp_primary_selection_device_manager_v1> device_manager_; const raw_ptr<WaylandConnection> connection_; std::unique_ptr<ZwpPrimarySelectionDevice> device_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_DEVICE_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.h
C++
unknown
1,931
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/zwp_primary_selection_offer.h" #include <primary-selection-unstable-v1-client-protocol.h> #include <fcntl.h> #include <algorithm> #include "base/check.h" #include "base/containers/contains.h" #include "base/files/file_util.h" #include "ui/base/clipboard/clipboard_constants.h" namespace ui { ZwpPrimarySelectionOffer::ZwpPrimarySelectionOffer( zwp_primary_selection_offer_v1* data_offer) : data_offer_(data_offer) { static constexpr zwp_primary_selection_offer_v1_listener kListener = { &OnOffer}; zwp_primary_selection_offer_v1_add_listener(data_offer, &kListener, this); } ZwpPrimarySelectionOffer::~ZwpPrimarySelectionOffer() { data_offer_.reset(); } base::ScopedFD ZwpPrimarySelectionOffer::Receive(const std::string& mime_type) { if (!base::Contains(mime_types(), mime_type)) return base::ScopedFD(); base::ScopedFD read_fd; base::ScopedFD write_fd; PCHECK(base::CreatePipe(&read_fd, &write_fd)); // If we needed to forcibly write "text/plain" as an available // mimetype, then it is safer to "read" the clipboard data with // a mimetype mime_type known to be available. std::string effective_mime_type = mime_type; if (mime_type == kMimeTypeText && text_plain_mime_type_inserted()) effective_mime_type = kMimeTypeTextUtf8; zwp_primary_selection_offer_v1_receive( data_offer_.get(), effective_mime_type.data(), write_fd.get()); return read_fd; } // static void ZwpPrimarySelectionOffer::OnOffer(void* data, zwp_primary_selection_offer_v1* data_offer, const char* mime_type) { auto* self = static_cast<ZwpPrimarySelectionOffer*>(data); self->AddMimeType(mime_type); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_primary_selection_offer.cc
C++
unknown
1,920
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_OFFER_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_OFFER_H_ #include <string> #include "base/files/scoped_file.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/host/wayland_data_offer_base.h" struct zwp_primary_selection_offer_v1; namespace ui { // This class represents a piece of data offered for transfer by another client, // the source client (see ZwpPrimarySelectionSource for more). It is used by the // primary selection mechanism. // // The offer describes MIME types that the data can be converted to and provides // the mechanism for transferring the data directly from the source client. class ZwpPrimarySelectionOffer : public WaylandDataOfferBase { public: // Takes ownership of data_offer. explicit ZwpPrimarySelectionOffer(zwp_primary_selection_offer_v1* data_offer); ZwpPrimarySelectionOffer(const ZwpPrimarySelectionOffer &) = delete; ZwpPrimarySelectionOffer &operator =(const ZwpPrimarySelectionOffer &) = delete; ~ZwpPrimarySelectionOffer() override; // WaylandDataOfferBase overrides: base::ScopedFD Receive(const std::string& mime_type) override; private: // primary_selection_offer_listener callbacks. static void OnOffer(void* data, zwp_primary_selection_offer_v1* data_offer, const char* mime_type); // The Wayland object wrapped by this instance. wl::Object<zwp_primary_selection_offer_v1> data_offer_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_PRIMARY_SELECTION_OFFER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_primary_selection_offer.h
C++
unknown
1,780
// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_TEXT_INPUT_WRAPPER_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_TEXT_INPUT_WRAPPER_H_ #include <stdint.h> #include <string> #include <vector> #include "base/strings/string_piece.h" #include "ui/base/ime/grammar_fragment.h" #include "ui/base/ime/text_input_client.h" #include "ui/base/ime/text_input_mode.h" #include "ui/base/ime/text_input_type.h" namespace gfx { class Rect; class Range; } // namespace gfx namespace ui { class WaylandWindow; // Client interface which handles wayland text input callbacks class ZWPTextInputWrapperClient { public: struct SpanStyle { uint32_t index; // Byte offset. uint32_t length; // Length in bytes. uint32_t style; // One of preedit_style. }; virtual ~ZWPTextInputWrapperClient() = default; // Called when a new composing text (pre-edit) should be set around the // current cursor position. Any previously set composing text should // be removed. // Note that the preedit_cursor is byte-offset. virtual void OnPreeditString(base::StringPiece text, const std::vector<SpanStyle>& spans, int32_t preedit_cursor) = 0; // Called when a complete input sequence has been entered. The text to // commit could be either just a single character after a key press or the // result of some composing (pre-edit). virtual void OnCommitString(base::StringPiece text) = 0; // Called when the cursor position or selection should be modified. The new // cursor position is applied on the next OnCommitString. |index| and |anchor| // are measured in UTF-8 bytes. virtual void OnCursorPosition(int32_t index, int32_t anchor) = 0; // Called when client needs to delete all or part of the text surrounding // the cursor. |index| and |length| are expected to be a byte offset of |text| // passed via ZWPTextInputWrapper::SetSurroundingText. virtual void OnDeleteSurroundingText(int32_t index, uint32_t length) = 0; // Notify when a key event was sent. Key events should not be used // for normal text input operations, which should be done with // commit_string, delete_surrounding_text, etc. virtual void OnKeysym(uint32_t key, uint32_t state, uint32_t modifiers) = 0; // Called when a new preedit region is specified. The region is specified // by |index| and |length| on the surrounding text sent do wayland compositor // in advance. |index| is relative to the current caret position, and |length| // is the preedit length. Both are measured in UTF-8 bytes. // |spans| are representing the text spanning for the new preedit. All its // indices and length are relative to the beginning of the new preedit, // and measured in UTF-8 bytes. virtual void OnSetPreeditRegion(int32_t index, uint32_t length, const std::vector<SpanStyle>& spans) = 0; // Called when client needs to clear all grammar fragments in |range|. All // indices are measured in UTF-8 bytes. virtual void OnClearGrammarFragments(const gfx::Range& range) = 0; // Called when client requests to add a new grammar marker. All indices are // measured in UTF-8 bytes. virtual void OnAddGrammarFragment(const ui::GrammarFragment& fragment) = 0; // Sets the autocorrect range in the text input client. // |range| is in UTF-16 code range. virtual void OnSetAutocorrectRange(const gfx::Range& range) = 0; // Called when the virtual keyboard's occluded bounds is updated. // The bounds are in screen DIP. virtual void OnSetVirtualKeyboardOccludedBounds( const gfx::Rect& screen_bounds) = 0; // Called when the visibility state of the input panel changed. // There's no detailed spec of |state|, and no actual implementor except // components/exo is found in the world at this moment. // Thus, in ozone/wayland use the lowest bit as boolean // (visible=1/invisible=0), and ignore other bits for future compatibility. // This behavior must be consistent with components/exo. virtual void OnInputPanelState(uint32_t state) = 0; // Called when the modifiers map is updated. // Each element holds the XKB name represents a modifier, such as "Shift". // The position of the element represents the bit position of modifiers // on OnKeysym. E.g., if LSB of modifiers is set, modifiers_map[0] is // set, if (1 << 1) of modifiers is set, modifiers_map[1] is set, and so on. virtual void OnModifiersMap(std::vector<std::string> modifiers_map) = 0; }; // A wrapper around different versions of wayland text input protocols. // Wayland compositors support various different text input protocols which // all from Chromium point of view provide the functionality needed by Chromium // IME. This interface collects the functionality behind one wrapper API. class ZWPTextInputWrapper { public: virtual ~ZWPTextInputWrapper() = default; virtual void Reset() = 0; virtual void Activate(WaylandWindow* window, ui::TextInputClient::FocusReason reason) = 0; virtual void Deactivate() = 0; virtual void ShowInputPanel() = 0; virtual void HideInputPanel() = 0; virtual void SetCursorRect(const gfx::Rect& rect) = 0; virtual void SetSurroundingText(const std::string& text, const gfx::Range& selection_range) = 0; virtual void SetContentType(ui::TextInputType type, ui::TextInputMode mode, uint32_t flags, bool should_do_learning, bool can_compose_inline) = 0; virtual void SetGrammarFragmentAtCursor( const ui::GrammarFragment& fragment) = 0; virtual void SetAutocorrectInfo(const gfx::Range& autocorrect_range, const gfx::Rect& autocorrect_bounds) = 0; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_TEXT_INPUT_WRAPPER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_text_input_wrapper.h
C++
unknown
6,122
// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/host/zwp_text_input_wrapper_v1.h" #include <string> #include <utility> #include "base/check.h" #include "base/location.h" #include "base/strings/string_piece.h" #include "base/strings/string_split.h" #include "base/time/time.h" #include "ui/base/wayland/wayland_client_input_types.h" #include "ui/gfx/range/range.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" namespace ui { namespace { // Converts Chrome's TextInputType into wayland's content_purpose. // Some of TextInputType values do not have clearly corresponding wayland value, // and they fallback to closer type. uint32_t InputTypeToContentPurpose(TextInputType input_type) { switch (input_type) { case TEXT_INPUT_TYPE_NONE: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NORMAL; case TEXT_INPUT_TYPE_TEXT: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NORMAL; case TEXT_INPUT_TYPE_PASSWORD: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PASSWORD; case TEXT_INPUT_TYPE_SEARCH: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NORMAL; case TEXT_INPUT_TYPE_EMAIL: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_EMAIL; case TEXT_INPUT_TYPE_NUMBER: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NUMBER; case TEXT_INPUT_TYPE_TELEPHONE: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PHONE; case TEXT_INPUT_TYPE_URL: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_URL; case TEXT_INPUT_TYPE_DATE: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DATE; case TEXT_INPUT_TYPE_DATE_TIME: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DATETIME; case TEXT_INPUT_TYPE_DATE_TIME_LOCAL: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DATETIME; case TEXT_INPUT_TYPE_MONTH: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DATE; case TEXT_INPUT_TYPE_TIME: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_TIME; case TEXT_INPUT_TYPE_WEEK: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DATE; case TEXT_INPUT_TYPE_TEXT_AREA: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NORMAL; case TEXT_INPUT_TYPE_CONTENT_EDITABLE: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NORMAL; case TEXT_INPUT_TYPE_DATE_TIME_FIELD: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_DATETIME; case TEXT_INPUT_TYPE_NULL: return ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NORMAL; } } // Converts Chrome's TextInputType into wayland's content_hint. uint32_t InputFlagsToContentHint(int input_flags) { uint32_t hint = 0; if (input_flags & TEXT_INPUT_FLAG_AUTOCOMPLETE_ON) hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_AUTO_COMPLETION; if (input_flags & TEXT_INPUT_FLAG_AUTOCORRECT_ON) hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_AUTO_CORRECTION; // No good match. Fallback to AUTO_CORRECTION. if (input_flags & TEXT_INPUT_FLAG_SPELLCHECK_ON) hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_AUTO_CORRECTION; if (input_flags & TEXT_INPUT_FLAG_AUTOCAPITALIZE_CHARACTERS) hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_UPPERCASE; if (input_flags & TEXT_INPUT_FLAG_AUTOCAPITALIZE_WORDS) hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_TITLECASE; if (input_flags & TEXT_INPUT_FLAG_AUTOCAPITALIZE_SENTENCES) hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_AUTO_CAPITALIZATION; if (input_flags & TEXT_INPUT_FLAG_HAS_BEEN_PASSWORD) hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_PASSWORD; return hint; } // Parses the content of |array|, and creates a map of modifiers. // The content of array is just a concat of modifier names in c-style string // (i.e., '\0' terminated string), thus this splits the whole byte array by // '\0' character. std::vector<std::string> ParseModifiersMap(wl_array* array) { return base::SplitString( base::StringPiece(static_cast<char*>(array->data), array->size - 1), // exclude trailing '\0'. base::StringPiece("\0", 1), // '\0' as a delimiter. base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); } } // namespace ZWPTextInputWrapperV1::ZWPTextInputWrapperV1( WaylandConnection* connection, ZWPTextInputWrapperClient* client, zwp_text_input_manager_v1* text_input_manager, zcr_text_input_extension_v1* text_input_extension) : connection_(connection), client_(client) { static constexpr zwp_text_input_v1_listener text_input_listener = { &OnEnter, // text_input_enter, &OnLeave, // text_input_leave, &OnModifiersMap, // text_input_modifiers_map, &OnInputPanelState, // text_input_input_panel_state, &OnPreeditString, // text_input_preedit_string, &OnPreeditStyling, // text_input_preedit_styling, &OnPreeditCursor, // text_input_preedit_cursor, &OnCommitString, // text_input_commit_string, &OnCursorPosition, // text_input_cursor_position, &OnDeleteSurroundingText, // text_input_delete_surrounding_text, &OnKeysym, // text_input_keysym, &OnLanguage, // text_input_language, &OnTextDirection, // text_input_text_direction }; static constexpr zcr_extended_text_input_v1_listener extended_text_input_listener = { &OnSetPreeditRegion, // extended_text_input_set_preedit_region, &OnClearGrammarFragments, // extended_text_input_clear_grammar_fragments, &OnAddGrammarFragment, // extended_text_input_add_grammar_fragment, &OnSetAutocorrectRange, // extended_text_input_set_autocorrect_range, &OnSetVirtualKeyboardOccludedBounds, // extended_text_input_set_virtual_keyboard_occluded_bounds, }; obj_ = wl::Object<zwp_text_input_v1>( zwp_text_input_manager_v1_create_text_input(text_input_manager)); DCHECK(obj_.get()); zwp_text_input_v1_add_listener(obj_.get(), &text_input_listener, this); if (text_input_extension) { extended_obj_ = wl::Object<zcr_extended_text_input_v1>( zcr_text_input_extension_v1_get_extended_text_input( text_input_extension, obj_.get())); DCHECK(extended_obj_.get()); zcr_extended_text_input_v1_add_listener( extended_obj_.get(), &extended_text_input_listener, this); } } ZWPTextInputWrapperV1::~ZWPTextInputWrapperV1() = default; void ZWPTextInputWrapperV1::Reset() { ResetInputEventState(); zwp_text_input_v1_reset(obj_.get()); } void ZWPTextInputWrapperV1::Activate(WaylandWindow* window, TextInputClient::FocusReason reason) { DCHECK(connection_->seat()); if (extended_obj_.get() && wl::get_version_of_object(extended_obj_.get()) >= ZCR_EXTENDED_TEXT_INPUT_V1_SET_FOCUS_REASON_SINCE_VERSION) { absl::optional<uint32_t> wayland_focus_reason; switch (reason) { case ui::TextInputClient::FocusReason::FOCUS_REASON_NONE: wayland_focus_reason = ZCR_EXTENDED_TEXT_INPUT_V1_FOCUS_REASON_TYPE_NONE; break; case ui::TextInputClient::FocusReason::FOCUS_REASON_MOUSE: wayland_focus_reason = ZCR_EXTENDED_TEXT_INPUT_V1_FOCUS_REASON_TYPE_MOUSE; break; case ui::TextInputClient::FocusReason::FOCUS_REASON_TOUCH: wayland_focus_reason = ZCR_EXTENDED_TEXT_INPUT_V1_FOCUS_REASON_TYPE_TOUCH; break; case ui::TextInputClient::FocusReason::FOCUS_REASON_PEN: wayland_focus_reason = ZCR_EXTENDED_TEXT_INPUT_V1_FOCUS_REASON_TYPE_PEN; break; case ui::TextInputClient::FocusReason::FOCUS_REASON_OTHER: wayland_focus_reason = ZCR_EXTENDED_TEXT_INPUT_V1_FOCUS_REASON_TYPE_OTHER; break; } if (wayland_focus_reason.has_value()) { zcr_extended_text_input_v1_set_focus_reason(extended_obj_.get(), wayland_focus_reason.value()); } } zwp_text_input_v1_activate(obj_.get(), connection_->seat()->wl_object(), window->root_surface()->surface()); } void ZWPTextInputWrapperV1::Deactivate() { DCHECK(connection_->seat()); zwp_text_input_v1_deactivate(obj_.get(), connection_->seat()->wl_object()); } void ZWPTextInputWrapperV1::ShowInputPanel() { zwp_text_input_v1_show_input_panel(obj_.get()); TryScheduleFinalizeVirtualKeyboardChanges(); } void ZWPTextInputWrapperV1::HideInputPanel() { zwp_text_input_v1_hide_input_panel(obj_.get()); TryScheduleFinalizeVirtualKeyboardChanges(); } void ZWPTextInputWrapperV1::SetCursorRect(const gfx::Rect& rect) { zwp_text_input_v1_set_cursor_rectangle(obj_.get(), rect.x(), rect.y(), rect.width(), rect.height()); } void ZWPTextInputWrapperV1::SetSurroundingText( const std::string& text, const gfx::Range& selection_range) { zwp_text_input_v1_set_surrounding_text( obj_.get(), text.c_str(), selection_range.start(), selection_range.end()); } void ZWPTextInputWrapperV1::SetContentType(ui::TextInputType type, ui::TextInputMode mode, uint32_t flags, bool should_do_learning, bool can_compose_inline) { // If wayland compositor supports the extended version of set input type, // use it to avoid losing the info. if (extended_obj_.get()) { uint32_t wl_server_version = wl::get_version_of_object(extended_obj_.get()); if (wl_server_version >= ZCR_EXTENDED_TEXT_INPUT_V1_SET_INPUT_TYPE_SINCE_VERSION) { zcr_extended_text_input_v1_set_input_type( extended_obj_.get(), ui::wayland::ConvertFromTextInputType(type), ui::wayland::ConvertFromTextInputMode(mode), ui::wayland::ConvertFromTextInputFlags(flags), should_do_learning ? ZCR_EXTENDED_TEXT_INPUT_V1_LEARNING_MODE_ENABLED : ZCR_EXTENDED_TEXT_INPUT_V1_LEARNING_MODE_DISABLED, can_compose_inline ? ZCR_EXTENDED_TEXT_INPUT_V1_INLINE_COMPOSITION_SUPPORT_SUPPORTED : ZCR_EXTENDED_TEXT_INPUT_V1_INLINE_COMPOSITION_SUPPORT_UNSUPPORTED); return; } if (wl_server_version >= ZCR_EXTENDED_TEXT_INPUT_V1_DEPRECATED_SET_INPUT_TYPE_SINCE_VERSION) { // TODO(crbug.com/1420448) This deprecated method is used here only to // maintain backwards compatibility with an older version of Exo. Once // Exo has stabilized on the new set_input_type, remove this call. zcr_extended_text_input_v1_deprecated_set_input_type( extended_obj_.get(), ui::wayland::ConvertFromTextInputType(type), ui::wayland::ConvertFromTextInputMode(mode), ui::wayland::ConvertFromTextInputFlags(flags), should_do_learning ? ZCR_EXTENDED_TEXT_INPUT_V1_LEARNING_MODE_ENABLED : ZCR_EXTENDED_TEXT_INPUT_V1_LEARNING_MODE_DISABLED); return; } } // Otherwise, fallback to the standard set_content_type. uint32_t content_purpose = InputTypeToContentPurpose(type); uint32_t content_hint = InputFlagsToContentHint(flags); if (!should_do_learning) content_hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_SENSITIVE_DATA; zwp_text_input_v1_set_content_type(obj_.get(), content_hint, content_purpose); } void ZWPTextInputWrapperV1::SetGrammarFragmentAtCursor( const ui::GrammarFragment& fragment) { if (extended_obj_.get() && wl::get_version_of_object(extended_obj_.get()) >= ZCR_EXTENDED_TEXT_INPUT_V1_SET_GRAMMAR_FRAGMENT_AT_CURSOR_SINCE_VERSION) { zcr_extended_text_input_v1_set_grammar_fragment_at_cursor( extended_obj_.get(), fragment.range.start(), fragment.range.end(), fragment.suggestion.c_str()); } } void ZWPTextInputWrapperV1::SetAutocorrectInfo( const gfx::Range& autocorrect_range, const gfx::Rect& autocorrect_bounds) { if (extended_obj_.get() && wl::get_version_of_object(extended_obj_.get()) >= ZCR_EXTENDED_TEXT_INPUT_V1_SET_AUTOCORRECT_INFO_SINCE_VERSION) { zcr_extended_text_input_v1_set_autocorrect_info( extended_obj_.get(), autocorrect_range.start(), autocorrect_range.end(), autocorrect_bounds.x(), autocorrect_bounds.y(), autocorrect_bounds.width(), autocorrect_bounds.height()); } } void ZWPTextInputWrapperV1::ResetInputEventState() { spans_.clear(); preedit_cursor_ = -1; } void ZWPTextInputWrapperV1::TryScheduleFinalizeVirtualKeyboardChanges() { if (!SupportsFinalizeVirtualKeyboardChanges() || send_vk_finalize_timer_.IsRunning()) { return; } send_vk_finalize_timer_.Start( FROM_HERE, base::Microseconds(0), this, &ZWPTextInputWrapperV1::FinalizeVirtualKeyboardChanges); } void ZWPTextInputWrapperV1::FinalizeVirtualKeyboardChanges() { DCHECK(SupportsFinalizeVirtualKeyboardChanges()); zcr_extended_text_input_v1_finalize_virtual_keyboard_changes( extended_obj_.get()); } bool ZWPTextInputWrapperV1::SupportsFinalizeVirtualKeyboardChanges() { return extended_obj_.get() && wl::get_version_of_object(extended_obj_.get()) >= ZCR_EXTENDED_TEXT_INPUT_V1_FINALIZE_VIRTUAL_KEYBOARD_CHANGES_SINCE_VERSION; } // static void ZWPTextInputWrapperV1::OnEnter(void* data, struct zwp_text_input_v1* text_input, struct wl_surface* surface) { NOTIMPLEMENTED_LOG_ONCE(); } // static void ZWPTextInputWrapperV1::OnLeave(void* data, struct zwp_text_input_v1* text_input) { NOTIMPLEMENTED_LOG_ONCE(); } // static void ZWPTextInputWrapperV1::OnModifiersMap(void* data, struct zwp_text_input_v1* text_input, struct wl_array* map) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->client_->OnModifiersMap(ParseModifiersMap(map)); } // static void ZWPTextInputWrapperV1::OnInputPanelState( void* data, struct zwp_text_input_v1* text_input, uint32_t state) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->client_->OnInputPanelState(state); } // static void ZWPTextInputWrapperV1::OnPreeditString( void* data, struct zwp_text_input_v1* text_input, uint32_t serial, const char* text, const char* commit) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); auto spans = std::move(self->spans_); int32_t preedit_cursor = self->preedit_cursor_; self->ResetInputEventState(); self->client_->OnPreeditString(text, spans, preedit_cursor); } // static void ZWPTextInputWrapperV1::OnPreeditStyling( void* data, struct zwp_text_input_v1* text_input, uint32_t index, uint32_t length, uint32_t style) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->spans_.push_back( ZWPTextInputWrapperClient::SpanStyle{index, length, style}); } // static void ZWPTextInputWrapperV1::OnPreeditCursor( void* data, struct zwp_text_input_v1* text_input, int32_t index) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->preedit_cursor_ = index; } // static void ZWPTextInputWrapperV1::OnCommitString(void* data, struct zwp_text_input_v1* text_input, uint32_t serial, const char* text) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->ResetInputEventState(); self->client_->OnCommitString(text); } // static void ZWPTextInputWrapperV1::OnCursorPosition( void* data, struct zwp_text_input_v1* text_input, int32_t index, int32_t anchor) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->client_->OnCursorPosition(index, anchor); } // static void ZWPTextInputWrapperV1::OnDeleteSurroundingText( void* data, struct zwp_text_input_v1* text_input, int32_t index, uint32_t length) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->client_->OnDeleteSurroundingText(index, length); } // static void ZWPTextInputWrapperV1::OnKeysym(void* data, struct zwp_text_input_v1* text_input, uint32_t serial, uint32_t time, uint32_t key, uint32_t state, uint32_t modifiers) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->client_->OnKeysym(key, state, modifiers); } // static void ZWPTextInputWrapperV1::OnLanguage(void* data, struct zwp_text_input_v1* text_input, uint32_t serial, const char* language) { NOTIMPLEMENTED_LOG_ONCE(); } // static void ZWPTextInputWrapperV1::OnTextDirection( void* data, struct zwp_text_input_v1* text_input, uint32_t serial, uint32_t direction) { NOTIMPLEMENTED_LOG_ONCE(); } // static void ZWPTextInputWrapperV1::OnSetPreeditRegion( void* data, struct zcr_extended_text_input_v1* extended_text_input, int32_t index, uint32_t length) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); auto spans = std::move(self->spans_); self->ResetInputEventState(); self->client_->OnSetPreeditRegion(index, length, spans); } // static void ZWPTextInputWrapperV1::OnClearGrammarFragments( void* data, struct zcr_extended_text_input_v1* extended_text_input, uint32_t start, uint32_t end) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->client_->OnClearGrammarFragments(gfx::Range(start, end)); } // static void ZWPTextInputWrapperV1::OnAddGrammarFragment( void* data, struct zcr_extended_text_input_v1* extended_text_input, uint32_t start, uint32_t end, const char* suggestion) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->client_->OnAddGrammarFragment( ui::GrammarFragment(gfx::Range(start, end), suggestion)); } // static void ZWPTextInputWrapperV1::OnSetAutocorrectRange( void* data, struct zcr_extended_text_input_v1* extended_text_input, uint32_t start, uint32_t end) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); self->client_->OnSetAutocorrectRange(gfx::Range(start, end)); } // static void ZWPTextInputWrapperV1::OnSetVirtualKeyboardOccludedBounds( void* data, struct zcr_extended_text_input_v1* extended_text_input, int32_t x, int32_t y, int32_t width, int32_t height) { auto* self = static_cast<ZWPTextInputWrapperV1*>(data); gfx::Rect screen_bounds(x, y, width, height); self->client_->OnSetVirtualKeyboardOccludedBounds(screen_bounds); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_text_input_wrapper_v1.cc
C++
unknown
19,061
// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_TEXT_INPUT_WRAPPER_V1_H_ #define UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_TEXT_INPUT_WRAPPER_V1_H_ #include <cstdint> #include <string> #include <vector> #include <text-input-extension-unstable-v1-client-protocol.h> #include <text-input-unstable-v1-client-protocol.h> #include "base/memory/raw_ptr.h" #include "base/timer/timer.h" #include "ui/ozone/platform/wayland/common/wayland_object.h" #include "ui/ozone/platform/wayland/host/zwp_text_input_wrapper.h" namespace gfx { class Rect; } namespace ui { class WaylandConnection; class WaylandWindow; // Text input wrapper for text-input-unstable-v1 class ZWPTextInputWrapperV1 : public ZWPTextInputWrapper { public: ZWPTextInputWrapperV1(WaylandConnection* connection, ZWPTextInputWrapperClient* client, zwp_text_input_manager_v1* text_input_manager, zcr_text_input_extension_v1* text_input_extension); ZWPTextInputWrapperV1(const ZWPTextInputWrapperV1&) = delete; ZWPTextInputWrapperV1& operator=(const ZWPTextInputWrapperV1&) = delete; ~ZWPTextInputWrapperV1() override; void Reset() override; void Activate(WaylandWindow* window, ui::TextInputClient::FocusReason reason) override; void Deactivate() override; void ShowInputPanel() override; void HideInputPanel() override; void SetCursorRect(const gfx::Rect& rect) override; void SetSurroundingText(const std::string& text, const gfx::Range& selection_range) override; void SetContentType(TextInputType type, TextInputMode mode, uint32_t flags, bool should_do_learning, bool can_compose_inline) override; void SetGrammarFragmentAtCursor(const ui::GrammarFragment& fragment) override; void SetAutocorrectInfo(const gfx::Range& autocorrect_range, const gfx::Rect& autocorrect_bounds) override; private: void ResetInputEventState(); void TryScheduleFinalizeVirtualKeyboardChanges(); void FinalizeVirtualKeyboardChanges(); bool SupportsFinalizeVirtualKeyboardChanges(); // zwp_text_input_v1_listener static void OnEnter(void* data, struct zwp_text_input_v1* text_input, struct wl_surface* surface); static void OnLeave(void* data, struct zwp_text_input_v1* text_input); static void OnModifiersMap(void* data, struct zwp_text_input_v1* text_input, struct wl_array* map); static void OnInputPanelState(void* data, struct zwp_text_input_v1* text_input, uint32_t state); static void OnPreeditString(void* data, struct zwp_text_input_v1* text_input, uint32_t serial, const char* text, const char* commit); static void OnPreeditStyling(void* data, struct zwp_text_input_v1* text_input, uint32_t index, uint32_t length, uint32_t style); static void OnPreeditCursor(void* data, struct zwp_text_input_v1* text_input, int32_t index); static void OnCommitString(void* data, struct zwp_text_input_v1* text_input, uint32_t serial, const char* text); static void OnCursorPosition(void* data, struct zwp_text_input_v1* text_input, int32_t index, int32_t anchor); static void OnDeleteSurroundingText(void* data, struct zwp_text_input_v1* text_input, int32_t index, uint32_t length); static void OnKeysym(void* data, struct zwp_text_input_v1* text_input, uint32_t serial, uint32_t time, uint32_t key, uint32_t state, uint32_t modifiers); static void OnLanguage(void* data, struct zwp_text_input_v1* text_input, uint32_t serial, const char* language); static void OnTextDirection(void* data, struct zwp_text_input_v1* text_input, uint32_t serial, uint32_t direction); // zcr_extended_text_input_v1_listener static void OnSetPreeditRegion( void* data, struct zcr_extended_text_input_v1* extended_text_input, int32_t index, uint32_t length); static void OnClearGrammarFragments( void* data, struct zcr_extended_text_input_v1* extended_text_input, uint32_t start, uint32_t end); static void OnAddGrammarFragment( void* data, struct zcr_extended_text_input_v1* extended_text_input, uint32_t start, uint32_t end, const char* suggestion); static void OnSetAutocorrectRange( void* data, struct zcr_extended_text_input_v1* extended_text_input, uint32_t start, uint32_t end); static void OnSetVirtualKeyboardOccludedBounds( void* data, struct zcr_extended_text_input_v1* extended_text_input, int32_t x, int32_t y, int32_t width, int32_t height); const raw_ptr<WaylandConnection> connection_; wl::Object<zwp_text_input_v1> obj_; wl::Object<zcr_extended_text_input_v1> extended_obj_; const raw_ptr<ZWPTextInputWrapperClient> client_; std::vector<ZWPTextInputWrapperClient::SpanStyle> spans_; int32_t preedit_cursor_ = -1; // Timer for sending the finalize_virtual_keyboard_changes request. base::OneShotTimer send_vk_finalize_timer_; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_HOST_ZWP_TEXT_INPUT_WRAPPER_V1_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_text_input_wrapper_v1.h
C++
unknown
6,324
// Copyright 2020 The Chromium 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 "ui/ozone/platform/wayland/host/zwp_text_input_wrapper_v1.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/test/mock_zcr_extended_text_input.h" #include "ui/ozone/platform/wayland/test/mock_zwp_text_input.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" #include "ui/ozone/platform/wayland/test/test_zcr_text_input_extension.h" #include "ui/ozone/platform/wayland/test/wayland_test.h" using ::testing::InSequence; using ::testing::Mock; namespace ui { class ZWPTextInputWrapperV1Test : public WaylandTestSimple { public: void SetUp() override { WaylandTestSimple::SetUp(); wrapper_ = std::make_unique<ZWPTextInputWrapperV1>( connection_.get(), nullptr, connection_->text_input_manager_v1(), connection_->text_input_extension_v1()); } protected: std::unique_ptr<ZWPTextInputWrapperV1> wrapper_; }; TEST_F(ZWPTextInputWrapperV1Test, FinalizeVirtualKeyboardChangesShowInputPanel) { PostToServerAndWait([](wl::TestWaylandServerThread* server) { InSequence s; EXPECT_CALL(*server->text_input_manager_v1()->text_input(), ShowInputPanel()); EXPECT_CALL(*server->text_input_extension_v1()->extended_text_input(), FinalizeVirtualKeyboardChanges()); }); wrapper_->ShowInputPanel(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { Mock::VerifyAndClearExpectations( server->text_input_manager_v1()->text_input()); Mock::VerifyAndClearExpectations(server->text_input_extension_v1()); }); } TEST_F(ZWPTextInputWrapperV1Test, FinalizeVirtualKeyboardChangesHideInputPanel) { PostToServerAndWait([](wl::TestWaylandServerThread* server) { InSequence s; EXPECT_CALL(*server->text_input_manager_v1()->text_input(), HideInputPanel()); EXPECT_CALL(*server->text_input_extension_v1()->extended_text_input(), FinalizeVirtualKeyboardChanges()); }); wrapper_->HideInputPanel(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { Mock::VerifyAndClearExpectations( server->text_input_manager_v1()->text_input()); }); // The text input extension gets updated and called after another round trip. PostToServerAndWait([](wl::TestWaylandServerThread* server) { Mock::VerifyAndClearExpectations( server->text_input_extension_v1()->extended_text_input()); }); } TEST_F(ZWPTextInputWrapperV1Test, FinalizeVirtualKeyboardChangesMultipleInputPanelChanges) { PostToServerAndWait([](wl::TestWaylandServerThread* server) { auto* const mock_text_input = server->text_input_manager_v1()->text_input(); InSequence s; EXPECT_CALL(*mock_text_input, ShowInputPanel()); EXPECT_CALL(*mock_text_input, HideInputPanel()); EXPECT_CALL(*mock_text_input, ShowInputPanel()); EXPECT_CALL(*mock_text_input, HideInputPanel()); EXPECT_CALL(*mock_text_input, ShowInputPanel()); EXPECT_CALL(*server->text_input_extension_v1()->extended_text_input(), FinalizeVirtualKeyboardChanges()); }); wrapper_->ShowInputPanel(); wrapper_->HideInputPanel(); wrapper_->ShowInputPanel(); wrapper_->HideInputPanel(); wrapper_->ShowInputPanel(); PostToServerAndWait([](wl::TestWaylandServerThread* server) { Mock::VerifyAndClearExpectations( server->text_input_manager_v1()->text_input()); }); // The text input extension gets updated and called after another round trip. PostToServerAndWait([](wl::TestWaylandServerThread* server) { Mock::VerifyAndClearExpectations( server->text_input_extension_v1()->extended_text_input()); }); } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/host/zwp_text_input_wrapper_v1_unittest.cc
C++
unknown
3,970
specific_include_rules = { "wayland_overlay_config_mojom_traits.*" : [ "+components/crash/core/common/crash_key.h", "+skia/public/mojom/skcolor4f_mojom_traits.h", ], }
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/mojom/DEPS
Python
unknown
180
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/mojom/wayland_overlay_config_mojom_traits.h" #include "components/crash/core/common/crash_key.h" namespace mojo { namespace { void SetDeserializationCrashKeyString(base::StringPiece str) { static crash_reporter::CrashKeyString<128> key("wayland_deserialization"); key.Set(str); } } // namespace // static bool StructTraits<wl::mojom::WaylandOverlayConfigDataView, wl::WaylandOverlayConfig>:: Read(wl::mojom::WaylandOverlayConfigDataView data, wl::WaylandOverlayConfig* out) { out->z_order = data.z_order(); if (!data.ReadColorSpace(&out->color_space)) return false; if (!data.ReadTransform(&out->transform)) return false; out->buffer_id = data.buffer_id(); if (data.surface_scale_factor() <= 0) { SetDeserializationCrashKeyString("Invalid surface scale factor."); return false; } out->surface_scale_factor = data.surface_scale_factor(); if (!data.ReadBoundsRect(&out->bounds_rect)) return false; if (!data.ReadCropRect(&out->crop_rect)) return false; if (!data.ReadDamageRegion(&out->damage_region)) return false; out->enable_blend = data.enable_blend(); if (data.opacity() < 0 || data.opacity() > 1.f) { SetDeserializationCrashKeyString("Invalid opacity value."); return false; } out->opacity = data.opacity(); if (!data.ReadAccessFenceHandle(&out->access_fence_handle)) return false; if (!data.ReadPriorityHint(&out->priority_hint)) return false; if (!data.ReadRoundedClipBounds(&out->rounded_clip_bounds)) return false; if (!data.ReadBackgroundColor(&out->background_color)) return false; if (!data.ReadClipRect(&out->clip_rect)) return false; return true; } } // namespace mojo
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/mojom/wayland_overlay_config_mojom_traits.cc
C++
unknown
1,913
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_MOJOM_WAYLAND_OVERLAY_CONFIG_MOJOM_TRAITS_H_ #define UI_OZONE_PLATFORM_WAYLAND_MOJOM_WAYLAND_OVERLAY_CONFIG_MOJOM_TRAITS_H_ #include "skia/public/mojom/skcolor4f_mojom_traits.h" #include "ui/gfx/mojom/color_space_mojom_traits.h" #include "ui/gfx/mojom/gpu_fence_handle_mojom_traits.h" #include "ui/gfx/mojom/overlay_priority_hint_mojom_traits.h" #include "ui/gfx/mojom/overlay_transform_mojom_traits.h" #include "ui/gfx/mojom/rrect_f_mojom_traits.h" #include "ui/ozone/platform/wayland/common/wayland_overlay_config.h" #include "ui/ozone/platform/wayland/mojom/wayland_overlay_config.mojom-shared.h" namespace mojo { template <> struct StructTraits<wl::mojom::WaylandOverlayConfigDataView, wl::WaylandOverlayConfig> { static int z_order(const wl::WaylandOverlayConfig& input) { return input.z_order; } static const absl::optional<gfx::ColorSpace>& color_space( const wl::WaylandOverlayConfig& input) { return input.color_space; } static const gfx::OverlayTransform& transform( const wl::WaylandOverlayConfig& input) { return input.transform; } static uint32_t buffer_id(const wl::WaylandOverlayConfig& input) { return input.buffer_id; } static float surface_scale_factor(const wl::WaylandOverlayConfig& input) { return input.surface_scale_factor; } static const gfx::RectF& bounds_rect(const wl::WaylandOverlayConfig& input) { return input.bounds_rect; } static const gfx::RectF& crop_rect(const wl::WaylandOverlayConfig& input) { return input.crop_rect; } static const gfx::Rect& damage_region(const wl::WaylandOverlayConfig& input) { return input.damage_region; } static bool enable_blend(const wl::WaylandOverlayConfig& input) { return input.enable_blend; } static float opacity(const wl::WaylandOverlayConfig& input) { return input.opacity; } static gfx::GpuFenceHandle access_fence_handle( const wl::WaylandOverlayConfig& input) { return input.access_fence_handle.Clone(); } static const gfx::OverlayPriorityHint& priority_hint( const wl::WaylandOverlayConfig& input) { return input.priority_hint; } static const absl::optional<gfx::RRectF>& rounded_clip_bounds( const wl::WaylandOverlayConfig& input) { return input.rounded_clip_bounds; } static const absl::optional<SkColor4f>& background_color( const wl::WaylandOverlayConfig& input) { return input.background_color; } static const absl::optional<gfx::Rect>& clip_rect( const wl::WaylandOverlayConfig& input) { return input.clip_rect; } static bool Read(wl::mojom::WaylandOverlayConfigDataView data, wl::WaylandOverlayConfig* out); }; } // namespace mojo #endif // UI_OZONE_PLATFORM_WAYLAND_MOJOM_WAYLAND_OVERLAY_CONFIG_MOJOM_TRAITS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/mojom/wayland_overlay_config_mojom_traits.h
C++
unknown
2,997
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/mojom/wayland_presentation_info_mojom_traits.h" namespace mojo { // static bool StructTraits<wl::mojom::WaylandPresentationInfoDataView, wl::WaylandPresentationInfo>:: Read(wl::mojom::WaylandPresentationInfoDataView data, wl::WaylandPresentationInfo* out) { out->frame_id = data.frame_id(); if (!data.ReadFeedback(&out->feedback)) { return false; } return true; } } // namespace mojo
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/mojom/wayland_presentation_info_mojom_traits.cc
C++
unknown
613
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_MOJOM_WAYLAND_PRESENTATION_INFO_MOJOM_TRAITS_H_ #define UI_OZONE_PLATFORM_WAYLAND_MOJOM_WAYLAND_PRESENTATION_INFO_MOJOM_TRAITS_H_ #include "ui/gfx/mojom/presentation_feedback_mojom_traits.h" #include "ui/ozone/platform/wayland/common/wayland_presentation_info.h" #include "ui/ozone/platform/wayland/mojom/wayland_presentation_info.mojom-shared.h" namespace mojo { template <> struct StructTraits<wl::mojom::WaylandPresentationInfoDataView, wl::WaylandPresentationInfo> { static uint32_t frame_id(const wl::WaylandPresentationInfo& input) { return input.frame_id; } static const gfx::PresentationFeedback& feedback( const wl::WaylandPresentationInfo& input) { return input.feedback; } static bool Read(wl::mojom::WaylandPresentationInfoDataView data, wl::WaylandPresentationInfo* out); }; } // namespace mojo #endif // UI_OZONE_PLATFORM_WAYLAND_MOJOM_WAYLAND_PRESENTATION_INFO_MOJOM_TRAITS_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/mojom/wayland_presentation_info_mojom_traits.h
C++
unknown
1,142
// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/ozone_platform_wayland.h" #include <memory> #include <string> #include <utility> #include <vector> #include <components/exo/wayland/protocol/aura-shell-client-protocol.h> #include "base/command_line.h" #include "base/functional/bind.h" #include "base/memory/ptr_util.h" #include "base/message_loop/message_pump_type.h" #include "base/no_destructor.h" #include "base/task/single_thread_task_runner.h" #include "build/build_config.h" #include "ui/base/buildflags.h" #include "ui/base/cursor/cursor_factory.h" #include "ui/base/dragdrop/os_exchange_data_provider_factory_ozone.h" #include "ui/base/ime/linux/input_method_auralinux.h" #include "ui/base/ime/linux/linux_input_method_context_factory.h" #include "ui/base/ui_base_features.h" #include "ui/display/display_switches.h" #include "ui/events/devices/device_data_manager.h" #include "ui/events/event.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/gfx/buffer_format_util.h" #include "ui/gfx/linux/client_native_pixmap_dmabuf.h" #include "ui/gfx/native_widget_types.h" #include "ui/ozone/common/base_keyboard_hook.h" #include "ui/ozone/common/features.h" #include "ui/ozone/platform/wayland/common/wayland_util.h" #include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h" #include "ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.h" #include "ui/ozone/platform/wayland/gpu/wayland_overlay_manager.h" #include "ui/ozone/platform/wayland/gpu/wayland_surface_factory.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_connector.h" #include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h" #include "ui/ozone/platform/wayland/host/wayland_connection.h" #include "ui/ozone/platform/wayland/host/wayland_event_source.h" #include "ui/ozone/platform/wayland/host/wayland_exchange_data_provider.h" #include "ui/ozone/platform/wayland/host/wayland_input_controller.h" #include "ui/ozone/platform/wayland/host/wayland_input_method_context.h" #include "ui/ozone/platform/wayland/host/wayland_menu_utils.h" #include "ui/ozone/platform/wayland/host/wayland_output_manager.h" #include "ui/ozone/platform/wayland/host/wayland_seat.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" #include "ui/ozone/platform/wayland/host/wayland_window_manager.h" #include "ui/ozone/platform/wayland/host/wayland_zaura_shell.h" #include "ui/ozone/platform/wayland/wayland_utils.h" #include "ui/ozone/public/gpu_platform_support_host.h" #include "ui/ozone/public/ozone_platform.h" #include "ui/ozone/public/platform_menu_utils.h" #include "ui/ozone/public/system_input_injector.h" #include "ui/platform_window/platform_window_init_properties.h" #if BUILDFLAG(USE_XKBCOMMON) #include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h" #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" #else #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" #endif #if BUILDFLAG(IS_CHROMEOS) #include "ui/ozone/common/bitmap_cursor_factory.h" #else #include "ui/ozone/platform/wayland/host/wayland_cursor_factory.h" #endif #if BUILDFLAG(IS_LINUX) #include "ui/ozone/platform/wayland/host/linux_ui_delegate_wayland.h" #endif #if defined(WAYLAND_GBM) #include "ui/ozone/platform/wayland/gpu/drm_render_node_path_finder.h" #endif namespace ui { namespace { class OzonePlatformWayland : public OzonePlatform, public OSExchangeDataProviderFactoryOzone { public: OzonePlatformWayland() : old_synthesize_key_repeat_enabled_( KeyEvent::IsSynthesizeKeyRepeatEnabled()) { // Forcing the device scale factor on Wayland is not fully/well supported // and is provided for test purposes only. // See https://crbug.com/1241546 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(switches::kForceDeviceScaleFactor)) { LOG(WARNING) << "--" << switches::kForceDeviceScaleFactor << " on Wayland is TEST ONLY. Use it at your own risk."; } // Disable key-repeat flag synthesizing. On Wayland, key repeat events are // generated inside Chrome, and the flag is properly set. // See also WaylandEventSource. KeyEvent::SetSynthesizeKeyRepeatEnabled(false); OSExchangeDataProviderFactoryOzone::SetInstance(this); } OzonePlatformWayland(const OzonePlatformWayland&) = delete; OzonePlatformWayland& operator=(const OzonePlatformWayland&) = delete; ~OzonePlatformWayland() override { KeyEvent::SetSynthesizeKeyRepeatEnabled(old_synthesize_key_repeat_enabled_); GetInputMethodContextFactoryForOzone() = LinuxInputMethodContextFactory(); } // OzonePlatform SurfaceFactoryOzone* GetSurfaceFactoryOzone() override { return surface_factory_.get(); } OverlayManagerOzone* GetOverlayManager() override { return overlay_manager_.get(); } CursorFactory* GetCursorFactory() override { return cursor_factory_.get(); } InputController* GetInputController() override { return input_controller_.get(); } GpuPlatformSupportHost* GetGpuPlatformSupportHost() override { return buffer_manager_connector_ ? buffer_manager_connector_.get() : gpu_platform_support_host_.get(); } std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override { return nullptr; } std::unique_ptr<PlatformWindow> CreatePlatformWindow( PlatformWindowDelegate* delegate, PlatformWindowInitProperties properties) override { return WaylandWindow::Create(delegate, connection_.get(), std::move(properties)); } std::unique_ptr<display::NativeDisplayDelegate> CreateNativeDisplayDelegate() override { return nullptr; } std::unique_ptr<PlatformScreen> CreateScreen() override { // The WaylandConnection and the WaylandOutputManager must be created // before PlatformScreen. DCHECK(connection_ && connection_->wayland_output_manager()); return connection_->wayland_output_manager()->CreateWaylandScreen(); } void InitScreen(PlatformScreen* screen) override { DCHECK(connection_ && connection_->wayland_output_manager()); // InitScreen is always called with the same screen that CreateScreen // hands back, so it is safe to cast here. connection_->wayland_output_manager()->InitWaylandScreen( static_cast<WaylandScreen*>(screen)); } PlatformClipboard* GetPlatformClipboard() override { DCHECK(connection_); return connection_->clipboard(); } PlatformGLEGLUtility* GetPlatformGLEGLUtility() override { if (!gl_egl_utility_) gl_egl_utility_ = std::make_unique<WaylandGLEGLUtility>(); return gl_egl_utility_.get(); } std::unique_ptr<InputMethod> CreateInputMethod( ImeKeyEventDispatcher* ime_key_event_dispatcher, gfx::AcceleratedWidget widget) override { return std::make_unique<InputMethodAuraLinux>(ime_key_event_dispatcher); } PlatformMenuUtils* GetPlatformMenuUtils() override { return menu_utils_.get(); } WaylandUtils* GetPlatformUtils() override { return wayland_utils_.get(); } bool IsNativePixmapConfigSupported(gfx::BufferFormat format, gfx::BufferUsage usage) const override { #if defined(WAYLAND_GBM) // If there is no drm render node device available, native pixmaps are not // supported. if (path_finder_.GetDrmRenderNodePath().empty()) return false; if (supported_buffer_formats_.find(format) == supported_buffer_formats_.end()) { return false; } return gfx::ClientNativePixmapDmaBuf::IsConfigurationSupported(format, usage); #else return false; #endif } bool ShouldUseCustomFrame() override { return connection_->xdg_decoration_manager_v1() == nullptr; } bool InitializeUI(const InitParams& args) override { if (ShouldFailInitializeUIForTest()) { LOG(ERROR) << "Failing for test"; return false; } // Initialize DeviceDataManager early as devices are set during // WaylandConnection::Initialize(). DeviceDataManager::CreateInstance(); #if BUILDFLAG(USE_XKBCOMMON) keyboard_layout_engine_ = std::make_unique<XkbKeyboardLayoutEngine>(xkb_evdev_code_converter_); #else keyboard_layout_engine_ = std::make_unique<StubKeyboardLayoutEngine>(); #endif KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( keyboard_layout_engine_.get()); connection_ = std::make_unique<WaylandConnection>(); if (!connection_->Initialize()) { LOG(ERROR) << "Failed to initialize Wayland platform"; return false; } buffer_manager_connector_ = std::make_unique<WaylandBufferManagerConnector>( connection_->buffer_manager_host()); #if BUILDFLAG(IS_CHROMEOS) cursor_factory_ = std::make_unique<BitmapCursorFactory>(); #else cursor_factory_ = std::make_unique<WaylandCursorFactory>(connection_.get()); #endif input_controller_ = CreateWaylandInputController(connection_.get()); gpu_platform_support_host_.reset(CreateStubGpuPlatformSupportHost()); supported_buffer_formats_ = connection_->buffer_manager_host()->GetSupportedBufferFormats(); #if BUILDFLAG(IS_LINUX) linux_ui_delegate_ = std::make_unique<LinuxUiDelegateWayland>(connection_.get()); #endif menu_utils_ = std::make_unique<WaylandMenuUtils>(connection_.get()); wayland_utils_ = std::make_unique<WaylandUtils>(connection_.get()); GetInputMethodContextFactoryForOzone() = base::BindRepeating( [](WaylandConnection* connection, WaylandKeyboard::Delegate* key_delegate, LinuxInputMethodContextDelegate* ime_delegate) -> std::unique_ptr<LinuxInputMethodContext> { return std::make_unique<WaylandInputMethodContext>( connection, key_delegate, ime_delegate); }, base::Unretained(connection_.get()), base::Unretained(connection_->event_source())); return true; } void InitializeGPU(const InitParams& args) override { base::FilePath drm_node_path; #if defined(WAYLAND_GBM) drm_node_path = path_finder_.GetDrmRenderNodePath(); if (drm_node_path.empty()) LOG(WARNING) << "Failed to find drm render node path."; #endif buffer_manager_ = std::make_unique<WaylandBufferManagerGpu>(drm_node_path); surface_factory_ = std::make_unique<WaylandSurfaceFactory>( connection_.get(), buffer_manager_.get()); overlay_manager_ = std::make_unique<WaylandOverlayManager>(buffer_manager_.get()); } const PlatformProperties& GetPlatformProperties() override { static base::NoDestructor<OzonePlatform::PlatformProperties> properties; static bool initialised = false; if (!initialised) { // Server-side decorations on Wayland require support of xdg-decoration or // some other protocol extensions specific for the particular environment. // Whether the environment has any support only gets known at run time, so // we use the custom frame by default. If there is support, the user will // be able to enable the system frame. properties->custom_frame_pref_default = true; // Wayland uses sub-surfaces to show tooltips, and sub-surfaces must be // bound to their root surfaces always, but finding the correct root // surface at the moment of creating the tooltip is not always possible // due to how Wayland handles focus and activation. // Therefore, the platform should be given a hint at the moment when the // surface is initialised, where it is known for sure which root surface // shows the tooltip. properties->set_parent_for_non_top_level_windows = true; properties->app_modal_dialogs_use_event_blocker = true; // Xdg/Wl shell protocol does not disallow clients to manipulate global // screen coordinates, instead only surface-local ones are supported. // Non-toplevel surfaces, for example, must be positioned relative to // their parents. As for toplevel surfaces, clients simply don't know // their position on screens and always assume they are located at some // arbitrary position. properties->supports_global_screen_coordinates = features::IsWaylandScreenCoordinatesEnabled(); initialised = true; } return *properties; } const PlatformRuntimeProperties& GetPlatformRuntimeProperties() override { using SupportsSsdForTest = OzonePlatform::PlatformRuntimeProperties::SupportsSsdForTest; const auto& override_supports_ssd_for_test = OzonePlatform:: PlatformRuntimeProperties::override_supports_ssd_for_test; static OzonePlatform::PlatformRuntimeProperties properties; if (connection_) { DCHECK(has_initialized_ui()); // These properties are set when GetPlatformRuntimeProperties is called on // the browser process side. properties.supports_server_side_window_decorations = (connection_->xdg_decoration_manager_v1() != nullptr && override_supports_ssd_for_test == SupportsSsdForTest::kNotSet) || override_supports_ssd_for_test == SupportsSsdForTest::kYes; properties.supports_overlays = connection_->ShouldUseOverlayDelegation() && connection_->viewporter(); properties.supports_non_backed_solid_color_buffers = connection_->ShouldUseOverlayDelegation() && connection_->buffer_manager_host() ->SupportsNonBackedSolidColorBuffers(); // Primary planes can be transluscent due to underlay strategy. As a // result Wayland server draws contents occluded by an accelerated widget. // To prevent this, an opaque background image is stacked below the // accelerated widget to occlude contents below. properties.needs_background_image = connection_->ShouldUseOverlayDelegation() && connection_->viewporter(); if (connection_->zaura_shell()) { properties.supports_activation = zaura_shell_get_version(connection_->zaura_shell()->wl_object()) >= ZAURA_TOPLEVEL_ACTIVATE_SINCE_VERSION; properties.supports_tooltip = (wl::get_version_of_object( connection_->zaura_shell()->wl_object()) >= ZAURA_SURFACE_SHOW_TOOLTIP_SINCE_VERSION) && connection_->zaura_shell()->HasBugFix(1402158) && connection_->zaura_shell()->HasBugFix(1410676); } if (surface_factory_) { DCHECK(has_initialized_gpu()); properties.supports_native_pixmaps = surface_factory_->SupportsNativePixmaps(); } } else if (buffer_manager_) { DCHECK(has_initialized_gpu()); // These properties are set when the GetPlatformRuntimeProperties is // called on the gpu process side. properties.supports_non_backed_solid_color_buffers = buffer_manager_->supports_overlays() && buffer_manager_->supports_non_backed_solid_color_buffers(); // See the comment above. properties.needs_background_image = buffer_manager_->supports_overlays() && buffer_manager_->supports_viewporter(); properties.supports_native_pixmaps = surface_factory_->SupportsNativePixmaps(); properties.supports_clip_rect = buffer_manager_->supports_clip_rect(); } return properties; } void AddInterfaces(mojo::BinderMap* binders) override { // It's preferred to reuse the same task runner where the // WaylandBufferManagerGpu has been created. However, when tests are // executed, the task runner might not have been set at that time. Thus, use // the current one. See the comment in WaylandBufferManagerGpu why it takes // a task runner. // // Please note this call happens on the gpu. auto gpu_task_runner = buffer_manager_->gpu_thread_runner(); if (!gpu_task_runner) gpu_task_runner = base::SingleThreadTaskRunner::GetCurrentDefault(); binders->Add<ozone::mojom::WaylandBufferManagerGpu>( base::BindRepeating( &OzonePlatformWayland::CreateWaylandBufferManagerGpuBinding, base::Unretained(this)), gpu_task_runner); } void CreateWaylandBufferManagerGpuBinding( mojo::PendingReceiver<ozone::mojom::WaylandBufferManagerGpu> receiver) { buffer_manager_->AddBindingWaylandBufferManagerGpu(std::move(receiver)); } void PostCreateMainMessageLoop( base::OnceCallback<void()> shutdown_cb, scoped_refptr<base::SingleThreadTaskRunner>) override { DCHECK(connection_); connection_->SetShutdownCb(std::move(shutdown_cb)); } std::unique_ptr<PlatformKeyboardHook> CreateKeyboardHook( PlatformKeyboardHookTypes type, base::RepeatingCallback<void(KeyEvent* event)> callback, absl::optional<base::flat_set<DomCode>> dom_codes, gfx::AcceleratedWidget accelerated_widget) override { DCHECK(connection_); auto* seat = connection_->seat(); auto* window = connection_->window_manager()->GetWindow(accelerated_widget); if (!seat || !seat->keyboard() || !window) { return nullptr; } switch (type) { case PlatformKeyboardHookTypes::kModifier: return seat->keyboard()->CreateKeyboardHook( window, std::move(dom_codes), std::move(callback)); case PlatformKeyboardHookTypes::kMedia: return nullptr; } } // OSExchangeDataProviderFactoryOzone: std::unique_ptr<OSExchangeDataProvider> CreateProvider() override { return std::make_unique<WaylandExchangeDataProvider>(); } private: // Keeps the old value of KeyEvent::IsSynthesizeKeyRepeatEnabled(), to // restore it on destruction. const bool old_synthesize_key_repeat_enabled_; #if BUILDFLAG(USE_XKBCOMMON) XkbEvdevCodes xkb_evdev_code_converter_; #endif std::unique_ptr<KeyboardLayoutEngine> keyboard_layout_engine_; std::unique_ptr<WaylandConnection> connection_; std::unique_ptr<WaylandSurfaceFactory> surface_factory_; std::unique_ptr<CursorFactory> cursor_factory_; std::unique_ptr<InputController> input_controller_; std::unique_ptr<GpuPlatformSupportHost> gpu_platform_support_host_; std::unique_ptr<WaylandBufferManagerConnector> buffer_manager_connector_; std::unique_ptr<WaylandMenuUtils> menu_utils_; std::unique_ptr<WaylandUtils> wayland_utils_; // Objects, which solely live in the GPU process. std::unique_ptr<WaylandBufferManagerGpu> buffer_manager_; std::unique_ptr<WaylandOverlayManager> overlay_manager_; std::unique_ptr<WaylandGLEGLUtility> gl_egl_utility_; // Provides supported buffer formats for native gpu memory buffers // framework. wl::BufferFormatsWithModifiersMap supported_buffer_formats_; #if defined(WAYLAND_GBM) // This is used both in the gpu and browser processes to find out if a drm // render node is available. DrmRenderNodePathFinder path_finder_; #endif #if BUILDFLAG(IS_LINUX) std::unique_ptr<LinuxUiDelegateWayland> linux_ui_delegate_; #endif }; } // namespace OzonePlatform* CreateOzonePlatformWayland() { return new OzonePlatformWayland; } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/ozone_platform_wayland.cc
C++
unknown
19,402
// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_OZONE_PLATFORM_WAYLAND_H_ #define UI_OZONE_PLATFORM_WAYLAND_OZONE_PLATFORM_WAYLAND_H_ namespace ui { class OzonePlatform; // Constructor hook for use in ozone_platform_list.cc OzonePlatform* CreateOzonePlatformWayland(); } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_OZONE_PLATFORM_WAYLAND_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/ozone_platform_wayland.h
C++
unknown
486
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/global_object.h" #include <algorithm> #include <wayland-server-core.h> #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { void GlobalObject::Deleter::operator()(wl_global* global) { wl_global_destroy(global); } GlobalObject::GlobalObject(const wl_interface* interface, const void* implementation, uint32_t version) : interface_(interface), implementation_(implementation), version_(version) {} GlobalObject::~GlobalObject() {} bool GlobalObject::Initialize(wl_display* display) { global_.reset(wl_global_create(display, interface_, version_, this, &Bind)); return global_ != nullptr; } void GlobalObject::DestroyGlobal() { global_.reset(); } // static void GlobalObject::Bind(wl_client* client, void* data, uint32_t version, uint32_t id) { auto* global = static_cast<GlobalObject*>(data); wl_resource* resource = wl_resource_create( client, global->interface_, std::min(version, global->version_), id); if (!resource) { wl_client_post_no_memory(client); return; } if (!global->resource_) global->resource_ = resource; wl_resource_set_implementation(resource, global->implementation_, global, &GlobalObject::OnResourceDestroyed); global->OnBind(); } // static void GlobalObject::OnResourceDestroyed(wl_resource* resource) { auto* global = GetUserDataAs<GlobalObject>(resource); if (global->resource_ == resource) global->resource_ = nullptr; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/global_object.cc
C++
unknown
1,804
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_GLOBAL_OBJECT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_GLOBAL_OBJECT_H_ #include <memory> #include "base/memory/raw_ptr.h" struct wl_client; struct wl_display; struct wl_global; struct wl_interface; struct wl_resource; namespace wl { // Base class for managing the lifecycle of global objects. // Represents a global object used to emit global events to all clients. class GlobalObject { public: GlobalObject(const wl_interface* interface, const void* implementation, uint32_t version); GlobalObject(const GlobalObject&) = delete; GlobalObject& operator=(const GlobalObject&) = delete; virtual ~GlobalObject(); // Creates a global object. bool Initialize(wl_display* display); // Can be used by clients to explicitly destroy global objects and send // global_remove event. void DestroyGlobal(); // Called from Bind() to send additional information to clients. virtual void OnBind() {} // The first resource bound to this global, which is usually all that is // useful when testing a simple client. wl_resource* resource() const { return resource_; } // Sends the global event to clients. static void Bind(wl_client* client, void* data, uint32_t version, uint32_t id); static void OnResourceDestroyed(wl_resource* resource); private: struct Deleter { void operator()(wl_global* global); }; std::unique_ptr<wl_global, Deleter> global_; raw_ptr<const wl_interface> interface_; raw_ptr<const void> implementation_; const uint32_t version_; raw_ptr<wl_resource> resource_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_GLOBAL_OBJECT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/global_object.h
C++
unknown
1,901
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_pointer.h" namespace wl { namespace { void SetCursor(wl_client* client, wl_resource* pointer_resource, uint32_t serial, wl_resource* surface_resource, int32_t hotspot_x, int32_t hotspot_y) { GetUserDataAs<MockPointer>(pointer_resource) ->SetCursor(surface_resource, hotspot_x, hotspot_y); } } // namespace const struct wl_pointer_interface kMockPointerImpl = { &SetCursor, // set_cursor &DestroyResource, // release }; MockPointer::MockPointer(wl_resource* resource) : ServerObject(resource) {} MockPointer::~MockPointer() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_pointer.cc
C++
unknown
851
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_POINTER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_POINTER_H_ #include <wayland-server-protocol.h> #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct wl_pointer_interface kMockPointerImpl; class TestZcrPointerStylus; class MockPointer : public ServerObject { public: explicit MockPointer(wl_resource* resource); MockPointer(const MockPointer&) = delete; MockPointer& operator=(const MockPointer&) = delete; ~MockPointer() override; MOCK_METHOD3(SetCursor, void(wl_resource* surface_resource, int32_t hotspot_x, int32_t hotspot_y)); void set_pointer_stylus(TestZcrPointerStylus* pointer_stylus) { pointer_stylus_ = pointer_stylus; } TestZcrPointerStylus* pointer_stylus() const { return pointer_stylus_; } private: raw_ptr<TestZcrPointerStylus> pointer_stylus_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_POINTER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_pointer.h
C++
unknown
1,278
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_surface.h" #include <linux-explicit-synchronization-unstable-v1-client-protocol.h> #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/test_region.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" #include "ui/ozone/platform/wayland/test/test_zwp_linux_explicit_synchronization.h" namespace wl { namespace { void Attach(wl_client* client, wl_resource* resource, wl_resource* buffer_resource, int32_t x, int32_t y) { auto* surface = GetUserDataAs<MockSurface>(resource); surface->AttachNewBuffer(buffer_resource, x, y); } void SetOpaqueRegion(wl_client* client, wl_resource* resource, wl_resource* region) { GetUserDataAs<MockSurface>(resource)->SetOpaqueRegionImpl(region); } void SetInputRegion(wl_client* client, wl_resource* resource, wl_resource* region) { GetUserDataAs<MockSurface>(resource)->SetInputRegionImpl(region); } void Damage(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { GetUserDataAs<MockSurface>(resource)->Damage(x, y, width, height); } void Frame(struct wl_client* client, struct wl_resource* resource, uint32_t callback) { auto* surface = GetUserDataAs<MockSurface>(resource); wl_resource* callback_resource = wl_resource_create(client, &wl_callback_interface, 1, callback); surface->set_frame_callback(callback_resource); surface->Frame(callback); } void Commit(wl_client* client, wl_resource* resource) { GetUserDataAs<MockSurface>(resource)->Commit(); } void SetBufferScale(wl_client* client, wl_resource* resource, int32_t scale) { auto* mock_surface = GetUserDataAs<MockSurface>(resource); mock_surface->SetBufferScale(scale); mock_surface->set_buffer_scale(scale); } void SetBufferTransform(struct wl_client* client, struct wl_resource* resource, int32_t transform) { auto* mock_surface = GetUserDataAs<MockSurface>(resource); mock_surface->SetBufferTransform(transform); } void DamageBuffer(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { GetUserDataAs<MockSurface>(resource)->DamageBuffer(x, y, width, height); } void SetAcquireFence(wl_client* client, wl_resource* resource, int32_t fd) { // TODO(crbug.com/1211240): Implement this. NOTIMPLEMENTED(); } void GetRelease(wl_client* client, wl_resource* resource, uint32_t id) { auto* linux_buffer_release_resource = wl_resource_create(client, &zwp_linux_buffer_release_v1_interface, 1, id); auto* linux_surface_synchronization = GetUserDataAs<TestLinuxSurfaceSynchronization>(resource); auto* surface = GetUserDataAs<MockSurface>( linux_surface_synchronization->surface_resource()); surface->set_linux_buffer_release(surface->attached_buffer(), linux_buffer_release_resource); } } // namespace const struct wl_surface_interface kMockSurfaceImpl = { DestroyResource, // destroy Attach, // attach Damage, // damage Frame, // frame SetOpaqueRegion, // set_opaque_region SetInputRegion, // set_input_region Commit, // commit SetBufferTransform, // set_buffer_transform SetBufferScale, // set_buffer_scale DamageBuffer, // damage_buffer }; const struct zwp_linux_surface_synchronization_v1_interface kMockZwpLinuxSurfaceSynchronizationImpl = { DestroyResource, SetAcquireFence, GetRelease, }; MockSurface::MockSurface(wl_resource* resource) : ServerObject(resource) {} MockSurface::~MockSurface() { if (xdg_surface_ && xdg_surface_->resource()) wl_resource_destroy(xdg_surface_->resource()); if (sub_surface_ && sub_surface_->resource()) wl_resource_destroy(sub_surface_->resource()); if (viewport_ && viewport_->resource()) wl_resource_destroy(viewport_->resource()); if (blending_ && blending_->resource()) wl_resource_destroy(blending_->resource()); if (prioritized_surface_ && prioritized_surface_->resource()) wl_resource_destroy(prioritized_surface_->resource()); if (augmented_surface_ && augmented_surface_->resource()) wl_resource_destroy(augmented_surface_->resource()); } MockSurface* MockSurface::FromResource(wl_resource* resource) { if (!ResourceHasImplementation(resource, &wl_surface_interface, &kMockSurfaceImpl)) return nullptr; return GetUserDataAs<MockSurface>(resource); } void MockSurface::ClearBufferReleases() { linux_buffer_releases_.clear(); } void MockSurface::SetOpaqueRegionImpl(wl_resource* region) { if (!region) { opaque_region_ = gfx::Rect(-1, -1, 0, 0); return; } auto bounds = GetUserDataAs<TestRegion>(region)->getBounds(); opaque_region_ = gfx::Rect(bounds.fLeft, bounds.fTop, bounds.fRight - bounds.fLeft, bounds.fBottom - bounds.fTop); SetOpaqueRegion(region); } void MockSurface::SetInputRegionImpl(wl_resource* region) { // It is unsafe to always treat |region| as a valid pointer. // According to the protocol about wl_surface::set_input_region // "A NULL wl_region cuases the input region to be set to infinite." if (!region) { input_region_ = gfx::Rect(-1, -1, 0, 0); return; } auto bounds = GetUserDataAs<TestRegion>(region)->getBounds(); input_region_ = gfx::Rect(bounds.fLeft, bounds.fTop, bounds.fRight - bounds.fLeft, bounds.fBottom - bounds.fTop); SetInputRegion(region); } void MockSurface::AttachNewBuffer(wl_resource* buffer_resource, int32_t x, int32_t y) { if (attached_buffer_) prev_attached_buffer_ = attached_buffer_; attached_buffer_ = buffer_resource; Attach(buffer_resource, x, y); } void MockSurface::DestroyPrevAttachedBuffer() { DCHECK(prev_attached_buffer_); prev_attached_buffer_ = nullptr; } void MockSurface::ReleaseBuffer(wl_resource* buffer) { // Strictly speaking, Wayland protocol requires that we send both an explicit // release and a buffer release if an explicit release has been asked for. // But, this makes testing harder, and ozone/wayland should work with // just one of these signals (and handle both gracefully). // TODO(fangzhoug): Make buffer release mechanism a testing config variation. if (linux_buffer_releases_.find(buffer) != linux_buffer_releases_.end()) { ReleaseBufferFenced(buffer, {}); wl_buffer_send_release(buffer); wl_client_flush(wl_resource_get_client(buffer)); } DCHECK(buffer); wl_buffer_send_release(buffer); wl_client_flush(wl_resource_get_client(buffer)); if (buffer == prev_attached_buffer_) prev_attached_buffer_ = nullptr; if (buffer == attached_buffer_) attached_buffer_ = nullptr; } void MockSurface::ReleaseBufferFenced(wl_resource* buffer, gfx::GpuFenceHandle release_fence) { DCHECK(buffer); auto iter = linux_buffer_releases_.find(buffer); DCHECK(iter != linux_buffer_releases_.end()); auto* linux_buffer_release = iter->second; if (!release_fence.is_null()) { zwp_linux_buffer_release_v1_send_fenced_release( linux_buffer_release, release_fence.owned_fd.get()); } else { zwp_linux_buffer_release_v1_send_immediate_release(linux_buffer_release); } wl_client_flush(wl_resource_get_client(linux_buffer_release)); linux_buffer_releases_.erase(iter); if (buffer == prev_attached_buffer_) prev_attached_buffer_ = nullptr; if (buffer == attached_buffer_) attached_buffer_ = nullptr; } void MockSurface::SendFrameCallback() { if (!frame_callback_) return; wl_callback_send_done( frame_callback_, 0 /* trequest-specific data for the callback. not used */); wl_client_flush(wl_resource_get_client(frame_callback_)); wl_resource_destroy(frame_callback_); frame_callback_ = nullptr; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_surface.cc
C++
unknown
8,468
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_SURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_SURFACE_H_ #include <linux-explicit-synchronization-unstable-v1-server-protocol.h> #include <wayland-server-protocol.h> #include "base/containers/flat_map.h" #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/gpu_fence_handle.h" #include "ui/ozone/platform/wayland/test/mock_xdg_surface.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_alpha_blending.h" #include "ui/ozone/platform/wayland/test/test_augmented_surface.h" #include "ui/ozone/platform/wayland/test/test_overlay_prioritized_surface.h" #include "ui/ozone/platform/wayland/test/test_subsurface.h" #include "ui/ozone/platform/wayland/test/test_viewport.h" #include "ui/ozone/platform/wayland/test/test_xdg_popup.h" struct wl_resource; namespace wl { extern const struct wl_surface_interface kMockSurfaceImpl; extern const struct zwp_linux_surface_synchronization_v1_interface kMockZwpLinuxSurfaceSynchronizationImpl; // Manage client surface class MockSurface : public ServerObject { public: explicit MockSurface(wl_resource* resource); MockSurface(const MockSurface&) = delete; MockSurface& operator=(const MockSurface&) = delete; ~MockSurface() override; static MockSurface* FromResource(wl_resource* resource); MOCK_METHOD3(Attach, void(wl_resource* buffer, int32_t x, int32_t y)); MOCK_METHOD1(SetOpaqueRegion, void(wl_resource* region)); MOCK_METHOD1(SetInputRegion, void(wl_resource* region)); MOCK_METHOD1(Frame, void(uint32_t callback)); MOCK_METHOD4(Damage, void(int32_t x, int32_t y, int32_t width, int32_t height)); MOCK_METHOD0(Commit, void()); MOCK_METHOD1(SetBufferScale, void(int32_t scale)); MOCK_METHOD1(SetBufferTransform, void(int32_t transform)); MOCK_METHOD4(DamageBuffer, void(int32_t x, int32_t y, int32_t width, int32_t height)); void set_xdg_surface(MockXdgSurface* xdg_surface) { xdg_surface_ = xdg_surface; } MockXdgSurface* xdg_surface() const { return xdg_surface_; } // Must be set iff this MockSurface has role of subsurface. void set_sub_surface(TestSubSurface* sub_surface) { sub_surface_ = sub_surface; } TestSubSurface* sub_surface() const { return sub_surface_; } void set_viewport(TestViewport* viewport) { viewport_ = viewport; } TestViewport* viewport() { return viewport_; } void set_overlay_prioritized_surface( TestOverlayPrioritizedSurface* prioritized_surface) { prioritized_surface_ = prioritized_surface; } TestOverlayPrioritizedSurface* prioritized_surface() { return prioritized_surface_; } void set_augmented_surface(TestAugmentedSurface* augmented_surface) { augmented_surface_ = augmented_surface; } TestAugmentedSurface* augmented_surface() { return augmented_surface_; } void set_blending(TestAlphaBlending* blending) { blending_ = blending; } TestAlphaBlending* blending() { return blending_; } gfx::Rect opaque_region() const { return opaque_region_; } gfx::Rect input_region() const { return input_region_; } void set_frame_callback(wl_resource* callback_resource) { DCHECK(!frame_callback_); frame_callback_ = callback_resource; } void set_linux_buffer_release(wl_resource* buffer, wl_resource* linux_buffer_release) { DCHECK(!linux_buffer_releases_.contains(buffer)); linux_buffer_releases_.emplace(buffer, linux_buffer_release); } bool has_linux_buffer_release() const { return !linux_buffer_releases_.empty(); } void ClearBufferReleases(); wl_resource* attached_buffer() const { return attached_buffer_; } wl_resource* prev_attached_buffer() const { return prev_attached_buffer_; } bool has_role() const { return !!xdg_surface_ || !!sub_surface_; } void SetOpaqueRegionImpl(wl_resource* region); void SetInputRegionImpl(wl_resource* region); void AttachNewBuffer(wl_resource* buffer_resource, int32_t x, int32_t y); void DestroyPrevAttachedBuffer(); void ReleaseBuffer(wl_resource* buffer); void ReleaseBufferFenced(wl_resource* buffer, gfx::GpuFenceHandle release_fence); void SendFrameCallback(); int32_t buffer_scale() const { return buffer_scale_; } void set_buffer_scale(int32_t buffer_scale) { buffer_scale_ = buffer_scale; } private: raw_ptr<MockXdgSurface> xdg_surface_ = nullptr; raw_ptr<TestSubSurface> sub_surface_ = nullptr; raw_ptr<TestViewport> viewport_ = nullptr; raw_ptr<TestAlphaBlending> blending_ = nullptr; raw_ptr<TestOverlayPrioritizedSurface> prioritized_surface_ = nullptr; raw_ptr<TestAugmentedSurface> augmented_surface_ = nullptr; gfx::Rect opaque_region_ = {-1, -1, 0, 0}; gfx::Rect input_region_ = {-1, -1, 0, 0}; raw_ptr<wl_resource> frame_callback_ = nullptr; base::flat_map<wl_resource*, wl_resource*> linux_buffer_releases_; raw_ptr<wl_resource> attached_buffer_ = nullptr; raw_ptr<wl_resource> prev_attached_buffer_ = nullptr; int32_t buffer_scale_ = -1; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_SURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_surface.h
C++
unknown
5,339
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_wayland_platform_window_delegate.h" #include "ui/gfx/geometry/rect_conversions.h" #include "ui/ozone/platform/wayland/host/wayland_window.h" namespace ui { gfx::Rect MockWaylandPlatformWindowDelegate::ConvertRectToPixels( const gfx::Rect& rect_in_dp) const { float scale = wayland_window_ ? wayland_window_->applied_state().window_scale : 1.0f; return gfx::ScaleToEnclosingRect(rect_in_dp, scale); } gfx::Rect MockWaylandPlatformWindowDelegate::ConvertRectToDIP( const gfx::Rect& rect_in_pixels) const { float scale = wayland_window_ ? wayland_window_->applied_state().window_scale : 1.0f; return gfx::ScaleToEnclosedRect(rect_in_pixels, 1.0f / scale); } std::unique_ptr<WaylandWindow> MockWaylandPlatformWindowDelegate::CreateWaylandWindow( WaylandConnection* connection, PlatformWindowInitProperties properties) { auto window = WaylandWindow::Create(this, connection, std::move(properties)); wayland_window_ = window.get(); return window; } int64_t MockWaylandPlatformWindowDelegate::OnStateUpdate( const PlatformWindowDelegate::State& old, const PlatformWindowDelegate::State& latest) { if (old.bounds_dip != latest.bounds_dip || old.size_px != latest.size_px || old.window_scale != latest.window_scale) { bool origin_changed = old.bounds_dip.origin() != latest.bounds_dip.origin(); OnBoundsChanged({origin_changed}); } if (!latest.ProducesFrameOnUpdateFrom(old)) { return -1; } return ++viz_seq_; } } // namespace ui
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_wayland_platform_window_delegate.cc
C++
unknown
1,699
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WAYLAND_PLATFORM_WINDOW_DELEGATE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WAYLAND_PLATFORM_WINDOW_DELEGATE_H_ #include "base/memory/raw_ptr.h" #include "ui/ozone/test/mock_platform_window_delegate.h" namespace ui { class WaylandConnection; class WaylandWindow; struct PlatformWindowInitProperties; class MockWaylandPlatformWindowDelegate : public MockPlatformWindowDelegate { public: MockWaylandPlatformWindowDelegate() = default; MockWaylandPlatformWindowDelegate(const MockWaylandPlatformWindowDelegate&) = delete; MockWaylandPlatformWindowDelegate operator=( const MockWaylandPlatformWindowDelegate&) = delete; ~MockWaylandPlatformWindowDelegate() override = default; std::unique_ptr<WaylandWindow> CreateWaylandWindow( WaylandConnection* connection, PlatformWindowInitProperties properties); // MockPlatformWindowDelegate: gfx::Rect ConvertRectToPixels(const gfx::Rect& rect_in_dp) const override; gfx::Rect ConvertRectToDIP(const gfx::Rect& rect_in_pixels) const override; int64_t OnStateUpdate(const PlatformWindowDelegate::State& old, const PlatformWindowDelegate::State& latest) override; int64_t viz_seq() const { return viz_seq_; } private: raw_ptr<WaylandWindow> wayland_window_ = nullptr; // |viz_seq_| is used to save an incrementing sequence point on each // call to InsertSequencePoint. Test code can check this value to know // what sequence point is required to advance to the latest state. int64_t viz_seq_ = 0; }; } // namespace ui #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WAYLAND_PLATFORM_WINDOW_DELEGATE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_wayland_platform_window_delegate.h
C++
unknown
1,819
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_wayland_zcr_color_manager.h" #include <chrome-color-management-server-protocol.h> #include <cstdint> #include <iterator> #include "base/ranges/algorithm.h" #include "ui/base/wayland/color_manager_util.h" #include "ui/gfx/color_space.h" #include "ui/ozone/platform/wayland/test/global_object.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_output.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_management_surface.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_space.h" #include "ui/ozone/platform/wayland/test/test_wayland_zcr_color_space_creator.h" namespace wl { namespace { constexpr uint32_t kZcrColorManagerVersion = 1; void CreateColorSpaceFromIcc(wl_client* client, wl_resource* resource, uint32_t id, int32_t fd) { auto* zcr_color_manager = GetUserDataAs<MockZcrColorManagerV1>(resource); zcr_color_manager->CreateColorSpaceFromIcc(client, resource, id, fd); } void CreateColorSpaceFromNames(wl_client* client, wl_resource* resource, uint32_t id, uint32_t eotf, uint32_t chromaticity, uint32_t whitepoint) { wl_resource* color_space_resource = CreateResourceWithImpl<TestZcrColorSpaceV1>( client, &zcr_color_space_v1_interface, 1, &kTestZcrColorSpaceV1Impl, 0); DCHECK(color_space_resource); auto* zcr_color_manager = GetUserDataAs<MockZcrColorManagerV1>(resource); auto* zcr_color_space = GetUserDataAs<TestZcrColorSpaceV1>(color_space_resource); auto chromaticity_id = gfx::ColorSpace::PrimaryID::INVALID; const auto* maybe_primary = ui::wayland::kChromaticityMap.find(chromaticity); if (maybe_primary != ui::wayland::kChromaticityMap.end()) { chromaticity_id = maybe_primary->second; } auto eotf_id = gfx::ColorSpace::TransferID::INVALID; const auto* maybe_eotf = ui::wayland::kEotfMap.find(eotf); if (maybe_eotf != ui::wayland::kEotfMap.end()) { eotf_id = maybe_eotf->second; } zcr_color_space->SetGfxColorSpace(gfx::ColorSpace(chromaticity_id, eotf_id)); zcr_color_space->SetZcrColorManager(zcr_color_manager); wl_resource* creator_resource = CreateResourceWithImpl<TestZcrColorSpaceCreatorV1>( client, &zcr_color_space_creator_v1_interface, 1, nullptr, id); DCHECK(creator_resource); zcr_color_space_creator_v1_send_created(creator_resource, color_space_resource); zcr_color_manager->StoreZcrColorSpace(zcr_color_space); zcr_color_manager->CreateColorSpaceFromNames(client, resource, id, eotf, chromaticity, whitepoint); } void CreateColorSpaceFromParams(wl_client* client, wl_resource* resource, uint32_t id, uint32_t eotf, uint32_t primary_r_x, uint32_t primary_r_y, uint32_t primary_g_x, uint32_t primary_g_y, uint32_t primary_b_x, uint32_t primary_b_y, uint32_t whitepoint_x, uint32_t whitepoint_y) { wl_resource* color_space_resource = CreateResourceWithImpl<TestZcrColorSpaceV1>( client, &zcr_color_space_v1_interface, 1, &kTestZcrColorSpaceV1Impl, 0); DCHECK(color_space_resource); auto* zcr_color_manager = GetUserDataAs<MockZcrColorManagerV1>(resource); auto* zcr_color_space = GetUserDataAs<TestZcrColorSpaceV1>(color_space_resource); zcr_color_space->SetGfxColorSpace(gfx::ColorSpace::CreateSRGB()); zcr_color_space->SetZcrColorManager(zcr_color_manager); wl_resource* creator_resource = CreateResourceWithImpl<TestZcrColorSpaceCreatorV1>( client, &zcr_color_space_creator_v1_interface, 1, nullptr, id); DCHECK(creator_resource); zcr_color_space_creator_v1_send_created(creator_resource, color_space_resource); zcr_color_manager->StoreZcrColorSpace(zcr_color_space); zcr_color_manager->CreateColorSpaceFromParams( client, resource, id, eotf, primary_r_x, primary_r_y, primary_g_x, primary_g_y, primary_b_x, primary_b_y, whitepoint_x, whitepoint_y); } void GetColorManagementOutput(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* output) { wl_resource* output_resource = CreateResourceWithImpl<TestZcrColorManagementOutputV1>( client, &zcr_color_management_output_v1_interface, 1, &kTestZcrColorManagementOutputV1Impl, id); DCHECK(output_resource); auto* zcr_color_manager = GetUserDataAs<MockZcrColorManagerV1>(resource); auto* color_manager_output = GetUserDataAs<TestZcrColorManagementOutputV1>(output_resource); gfx::ColorSpace color_space; color_manager_output->SetGfxColorSpace(color_space); color_manager_output->StoreZcrColorManager(zcr_color_manager); zcr_color_manager->StoreZcrColorManagementOutput(color_manager_output); zcr_color_manager->GetColorManagementOutput(client, resource, id, output); } void GetColorManagementSurface(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* output) { wl_resource* surface_resource = CreateResourceWithImpl<TestZcrColorManagementSurfaceV1>( client, &zcr_color_management_surface_v1_interface, 1, &kTestZcrColorManagementSurfaceV1Impl, id); DCHECK(surface_resource); auto* zcr_color_manager = GetUserDataAs<MockZcrColorManagerV1>(resource); auto* color_manager_surface = GetUserDataAs<TestZcrColorManagementSurfaceV1>(surface_resource); gfx::ColorSpace color_space; color_manager_surface->SetGfxColorSpace(color_space); color_manager_surface->StoreZcrColorManager(zcr_color_manager); zcr_color_manager->StoreZcrColorManagementSurface(color_manager_surface); zcr_color_manager->GetColorManagementSurface(client, resource, id, output); } } // namespace const struct zcr_color_manager_v1_interface kMockZcrColorManagerV1Impl = { &CreateColorSpaceFromIcc, &CreateColorSpaceFromNames, &CreateColorSpaceFromParams, &GetColorManagementOutput, &GetColorManagementSurface, &DestroyResource}; MockZcrColorManagerV1::MockZcrColorManagerV1() : GlobalObject(&zcr_color_manager_v1_interface, &kMockZcrColorManagerV1Impl, kZcrColorManagerVersion) {} MockZcrColorManagerV1::~MockZcrColorManagerV1() { DCHECK(color_manager_outputs_.empty()); DCHECK(color_manager_surfaces_.empty()); } void MockZcrColorManagerV1::StoreZcrColorManagementOutput( TestZcrColorManagementOutputV1* params) { color_manager_outputs_.push_back(params); } void MockZcrColorManagerV1::StoreZcrColorManagementSurface( TestZcrColorManagementSurfaceV1* params) { color_manager_surfaces_.push_back(params); } void MockZcrColorManagerV1::StoreZcrColorSpace(TestZcrColorSpaceV1* params) { color_manager_color_spaces_.push_back(params); } void MockZcrColorManagerV1::OnZcrColorManagementOutputDestroyed( TestZcrColorManagementOutputV1* params) { auto it = base::ranges::find(color_manager_outputs_, params); DCHECK(it != color_manager_outputs_.end()); color_manager_outputs_.erase(it); } void MockZcrColorManagerV1::OnZcrColorManagementSurfaceDestroyed( TestZcrColorManagementSurfaceV1* params) { auto it = base::ranges::find(color_manager_surfaces_, params); DCHECK(it != color_manager_surfaces_.end()); color_manager_surfaces_.erase(it); } void MockZcrColorManagerV1::OnZcrColorSpaceDestroyed( TestZcrColorSpaceV1* params) { auto it = base::ranges::find(color_manager_color_spaces_, params); DCHECK(it != color_manager_color_spaces_.end()); color_manager_color_spaces_.erase(it); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_wayland_zcr_color_manager.cc
C++
unknown
8,502
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WAYLAND_ZCR_COLOR_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WAYLAND_ZCR_COLOR_MANAGER_H_ #include <chrome-color-management-server-protocol.h> #include <vector> #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/global_object.h" struct wl_client; struct wl_resource; namespace wl { extern const struct zcr_color_manager_v1_interface kMockZcrColorManagerV1Impl; class TestZcrColorManagementOutputV1; class TestZcrColorManagementSurfaceV1; class TestZcrColorSpaceV1; // Manage zwp_linux_buffer_params_v1 class MockZcrColorManagerV1 : public GlobalObject { public: MockZcrColorManagerV1(); MockZcrColorManagerV1(const MockZcrColorManagerV1&) = delete; MockZcrColorManagerV1& operator=(const MockZcrColorManagerV1&) = delete; ~MockZcrColorManagerV1() override; MOCK_METHOD4( CreateColorSpaceFromIcc, void(wl_client* client, wl_resource* resource, uint32_t id, int32_t fd)); MOCK_METHOD6(CreateColorSpaceFromNames, void(wl_client* client, wl_resource* resource, uint32_t id, uint32_t eotf, uint32_t chromaticity, uint32_t whitepoint)); MOCK_METHOD(void, CreateColorSpaceFromParams, (wl_client * client, wl_resource* resource, uint32_t id, uint32_t eotf, uint32_t primary_r_x, uint32_t primary_r_y, uint32_t primary_g_x, uint32_t primary_g_y, uint32_t primary_b_x, uint32_t primary_b_y, uint32_t whitepoint_x, uint32_t whitepoint_y)); MOCK_METHOD4(GetColorManagementOutput, void(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* output)); MOCK_METHOD4(GetColorManagementSurface, void(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* surface)); MOCK_METHOD2(Destroy, void(wl_client* client, wl_resource* resource)); const std::vector<TestZcrColorManagementOutputV1*> color_management_outputs() const { return color_manager_outputs_; } const std::vector<TestZcrColorManagementSurfaceV1*> color_management_surfaces() const { return color_manager_surfaces_; } void StoreZcrColorManagementOutput(TestZcrColorManagementOutputV1* params); void StoreZcrColorManagementSurface(TestZcrColorManagementSurfaceV1* params); void StoreZcrColorSpace(TestZcrColorSpaceV1* params); void OnZcrColorManagementOutputDestroyed( TestZcrColorManagementOutputV1* params); void OnZcrColorManagementSurfaceDestroyed( TestZcrColorManagementSurfaceV1* params); void OnZcrColorSpaceDestroyed(TestZcrColorSpaceV1* params); private: std::vector<TestZcrColorManagementOutputV1*> color_manager_outputs_; std::vector<TestZcrColorManagementSurfaceV1*> color_manager_surfaces_; std::vector<TestZcrColorSpaceV1*> color_manager_color_spaces_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WAYLAND_ZCR_COLOR_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_wayland_zcr_color_manager.h
C++
unknown
3,432
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_wp_presentation.h" #include <wayland-server-core.h> #include "base/logging.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { namespace { void Feedback(struct wl_client* client, struct wl_resource* resource, struct wl_resource* surface, uint32_t callback) { auto* wp_presentation = GetUserDataAs<MockWpPresentation>(resource); wl_resource* presentation_feedback_resource = wl_resource_create(client, &wp_presentation_feedback_interface, wl_resource_get_version(resource), callback); DCHECK(presentation_feedback_resource); wp_presentation->OnFeedback(presentation_feedback_resource); wp_presentation->Feedback(client, resource, surface, callback); } } // namespace const struct wp_presentation_interface kMockWpPresentationImpl = { &DestroyResource, // destroy &Feedback, // feedback }; MockWpPresentation::MockWpPresentation() : GlobalObject(&wp_presentation_interface, &kMockWpPresentationImpl, 1) {} MockWpPresentation::~MockWpPresentation() = default; void MockWpPresentation::OnFeedback(wl_resource* callback_resource) { DCHECK(callback_resource); presentation_callbacks_.emplace_back(callback_resource); } void MockWpPresentation::DropPresentationCallback(bool last) { wl_resource* callback_resource = GetPresentationCallbackResource(last); wl_resource_destroy(callback_resource); } void MockWpPresentation::SendPresentationCallback() { SendPresentationFeedbackToClient(/*last=*/false, /*discarded=*/false); } void MockWpPresentation::SendPresentationCallbackDiscarded(bool last) { SendPresentationFeedbackToClient(last, /*discarded=*/true); } void MockWpPresentation::SendPresentationFeedbackToClient(bool last, bool discarded) { wl_resource* callback_resource = GetPresentationCallbackResource(last); if (!callback_resource) return; if (discarded) { wp_presentation_feedback_send_discarded(callback_resource); } else { // TODO(msisov): add support for test provided presentation feedback values. wp_presentation_feedback_send_presented( callback_resource, 0 /* tv_sec_hi */, 0 /* tv_sec_lo */, 0 /* tv_nsec */, 0 /* refresh */, 0 /* seq_hi */, 0 /* seq_lo */, 0 /* flags */); } wl_client_flush(wl_resource_get_client(callback_resource)); wl_resource_destroy(callback_resource); } wl_resource* MockWpPresentation::GetPresentationCallbackResource(bool last) { if (presentation_callbacks_.empty()) { LOG(WARNING) << "MockWpPresentation doesn't have pending requests for " "presentation feedbacks."; return nullptr; } wl_resource* callback_resource = nullptr; if (last) { callback_resource = presentation_callbacks_.back(); presentation_callbacks_.pop_back(); } else { callback_resource = presentation_callbacks_.front(); presentation_callbacks_.erase(presentation_callbacks_.begin()); } return callback_resource; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_wp_presentation.cc
C++
unknown
3,259
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WP_PRESENTATION_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WP_PRESENTATION_H_ #include <presentation-time-server-protocol.h> #include "base/check.h" #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { extern const struct wp_presentation_interface kMockWpPresentationImpl; class MockWpPresentation : public GlobalObject { public: MockWpPresentation(); MockWpPresentation(const MockWpPresentation&) = delete; MockWpPresentation& operator=(const MockWpPresentation&) = delete; ~MockWpPresentation() override; MOCK_METHOD2(Destroy, void(struct wl_client* client, struct wl_resource* resource)); MOCK_METHOD4(Feedback, void(struct wl_client* client, struct wl_resource* resource, struct wl_resource* surface, uint32_t callback)); size_t num_of_presentation_callbacks() const { return presentation_callbacks_.size(); } void OnFeedback(wl_resource* callback_resource); // Drops first presentation callback from |presentation_callbacks|. If |last| // is true, the last item is dropped instead. void DropPresentationCallback(bool last = false); // Sends successful presentation callback for the first callback item in // |presentation_callbacks| and deletes that. void SendPresentationCallback(); // Sends failed presentation callback for the first callback item (if |last| // is true, then the very recent one) in |presentation_callbacks| and deletes // that. void SendPresentationCallbackDiscarded(bool last = false); private: // Sends either discarded or succeeded, which is based on |discarded|, // feedback to client and deletes the feedback resource. Which feedback is // sent (the oldest or the most recent) is based on |last| value. void SendPresentationFeedbackToClient(bool last, bool discarded); wl_resource* GetPresentationCallbackResource(bool last); std::vector<raw_ptr<wl_resource>> presentation_callbacks_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_WP_PRESENTATION_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_wp_presentation.h
C++
unknown
2,358
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_xdg_activation_v1.h" #include <wayland-server-core.h> #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { namespace { void SetSerial(struct wl_client* client, struct wl_resource* resource, uint32_t serial, struct wl_resource* seat) {} void SetAppId(struct wl_client* client, struct wl_resource* resource, const char* app_id) {} void SetSurface(struct wl_client* client, struct wl_resource* resource, struct wl_resource* surface) { GetUserDataAs<MockXdgActivationTokenV1>(resource)->SetSurface( client, resource, surface); } void Commit(struct wl_client* client, struct wl_resource* resource) { GetUserDataAs<MockXdgActivationTokenV1>(resource)->Commit(client, resource); } } // namespace const struct xdg_activation_token_v1_interface kMockXdgActivationTokenV1Impl = { &SetSerial, // set_serial &SetAppId, // set_app_id &SetSurface, // set_surface &Commit, // commit &DestroyResource, // destroy }; MockXdgActivationTokenV1::MockXdgActivationTokenV1(wl_resource* resource, MockXdgActivationV1* global) : ServerObject(resource), global_(global) {} MockXdgActivationTokenV1::~MockXdgActivationTokenV1() = default; namespace { void GetActivationToken(struct wl_client* client, struct wl_resource* resource, uint32_t id) { auto* global = GetUserDataAs<MockXdgActivationV1>(resource); wl_resource* token = CreateResourceWithImpl<MockXdgActivationTokenV1>( client, &xdg_activation_token_v1_interface, 1, &kMockXdgActivationTokenV1Impl, id, global); global->set_token(GetUserDataAs<MockXdgActivationTokenV1>(token)); } void Activate(struct wl_client* client, struct wl_resource* resource, const char* token, struct wl_resource* surface) { GetUserDataAs<MockXdgActivationV1>(resource)->Activate(client, resource, token, surface); } } // namespace const struct xdg_activation_v1_interface kMockXdgActivationV1Impl = { &DestroyResource, &GetActivationToken, &Activate, }; MockXdgActivationV1::MockXdgActivationV1() : GlobalObject(&xdg_activation_v1_interface, &kMockXdgActivationV1Impl, 1) { } MockXdgActivationV1::~MockXdgActivationV1() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_xdg_activation_v1.cc
C++
unknown
2,696
// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_ACTIVATION_V1_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_ACTIVATION_V1_H_ #include <xdg-activation-v1-server-protocol.h> #include "base/check.h" #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/global_object.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct xdg_activation_token_v1_interface kMockXdgActivationTokenV1Impl; extern const struct xdg_activation_v1_interface kMockXdgActivationV1Impl; class MockXdgActivationTokenV1; class MockXdgActivationV1 : public GlobalObject { public: MockXdgActivationV1(); MockXdgActivationV1(const MockXdgActivationV1&) = delete; MockXdgActivationV1& operator=(const MockXdgActivationV1&) = delete; ~MockXdgActivationV1() override; MockXdgActivationTokenV1* get_token() { return token_; } void set_token(MockXdgActivationTokenV1* token) { token_ = token; } MOCK_METHOD4(Activate, void(struct wl_client* client, struct wl_resource* resource, const char* token, struct wl_resource* surface)); MOCK_METHOD3(TokenSetSurface, void(struct wl_client* client, struct wl_resource* resource, struct wl_resource* surface)); MOCK_METHOD2(TokenCommit, void(struct wl_client* client, struct wl_resource* resource)); private: raw_ptr<MockXdgActivationTokenV1> token_ = nullptr; }; class MockXdgActivationTokenV1 : public ServerObject { public: explicit MockXdgActivationTokenV1(wl_resource* resource, MockXdgActivationV1* global); MockXdgActivationTokenV1(const MockXdgActivationTokenV1&) = delete; MockXdgActivationTokenV1& operator=(const MockXdgActivationTokenV1&) = delete; ~MockXdgActivationTokenV1() override; void SetSurface(struct wl_client* client, struct wl_resource* resource, struct wl_resource* surface) { global_->TokenSetSurface(client, resource, surface); } void Commit(struct wl_client* client, struct wl_resource* resource) { global_->TokenCommit(client, resource); } private: raw_ptr<MockXdgActivationV1> global_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_ACTIVATION_V1_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_xdg_activation_v1.h
C++
unknown
2,565
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_xdg_shell.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_positioner.h" #include "ui/ozone/platform/wayland/test/test_xdg_popup.h" namespace wl { namespace { constexpr uint32_t kXdgShellVersion = 3; void GetXdgSurfaceImpl(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* surface_resource, const struct wl_interface* interface, const void* implementation) { auto* surface = GetUserDataAs<MockSurface>(surface_resource); if (surface->xdg_surface()) { uint32_t xdg_error = static_cast<uint32_t>(XDG_WM_BASE_ERROR_ROLE); wl_resource_post_error(resource, xdg_error, "surface already has a role"); return; } wl_resource* xdg_surface_resource = CreateResourceWithImpl<::testing::NiceMock<MockXdgSurface>>( client, interface, wl_resource_get_version(resource), implementation, id, surface_resource); if (!xdg_surface_resource) { wl_client_post_no_memory(client); return; } surface->set_xdg_surface(GetUserDataAs<MockXdgSurface>(xdg_surface_resource)); } void CreatePositioner(wl_client* client, struct wl_resource* resource, uint32_t id) { CreateResourceWithImpl<TestPositioner>(client, &xdg_positioner_interface, wl_resource_get_version(resource), &kTestXdgPositionerImpl, id); } void GetXdgSurface(wl_client* client, wl_resource* resource, uint32_t id, wl_resource* surface_resource) { GetXdgSurfaceImpl(client, resource, id, surface_resource, &xdg_surface_interface, &kMockXdgSurfaceImpl); } void Pong(wl_client* client, wl_resource* resource, uint32_t serial) { GetUserDataAs<MockXdgShell>(resource)->Pong(serial); } } // namespace const struct xdg_wm_base_interface kMockXdgShellImpl = { &DestroyResource, // destroy &CreatePositioner, // create_positioner &GetXdgSurface, // get_xdg_surface &Pong, // pong }; MockXdgShell::MockXdgShell() : GlobalObject(&xdg_wm_base_interface, &kMockXdgShellImpl, kXdgShellVersion) {} MockXdgShell::~MockXdgShell() {} } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_xdg_shell.cc
C++
unknown
2,670
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SHELL_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SHELL_H_ #include <xdg-shell-server-protocol.h> #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { extern const struct xdg_wm_base_interface kMockXdgShellImpl; extern const struct zxdg_shell_v6_interface kMockZxdgShellV6Impl; // Manage xdg_shell object. class MockXdgShell : public GlobalObject { public: MockXdgShell(); MockXdgShell(const MockXdgShell&) = delete; MockXdgShell& operator=(const MockXdgShell&) = delete; ~MockXdgShell() override; MOCK_METHOD1(Pong, void(uint32_t serial)); }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SHELL_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_xdg_shell.h
C++
unknown
910
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/mock_xdg_surface.h" #include "ui/ozone/platform/wayland/test/test_positioner.h" #include "ui/ozone/platform/wayland/test/test_xdg_popup.h" namespace wl { void SetTitle(wl_client* client, wl_resource* resource, const char* title) { auto* toplevel = GetUserDataAs<MockXdgTopLevel>(resource); // As it this can be envoked during construction of the XdgSurface, cache the // result so that tests are able to access that information. toplevel->set_title(title); toplevel->SetTitle(toplevel->title()); } void SetAppId(wl_client* client, wl_resource* resource, const char* app_id) { auto* toplevel = GetUserDataAs<MockXdgTopLevel>(resource); toplevel->SetAppId(app_id); // As it this can be envoked during construction of the XdgSurface, cache the // result so that tests are able to access that information. toplevel->set_app_id(app_id); } void Move(wl_client* client, wl_resource* resource, wl_resource* seat, uint32_t serial) { GetUserDataAs<MockXdgTopLevel>(resource)->Move(serial); } void Resize(wl_client* client, wl_resource* resource, wl_resource* seat, uint32_t serial, uint32_t edges) { GetUserDataAs<MockXdgTopLevel>(resource)->Resize(serial, edges); } void AckConfigure(wl_client* client, wl_resource* resource, uint32_t serial) { GetUserDataAs<MockXdgSurface>(resource)->AckConfigure(serial); } void SetWindowGeometry(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { GetUserDataAs<MockXdgSurface>(resource)->SetWindowGeometry( {x, y, width, height}); } void SetMaximized(wl_client* client, wl_resource* resource) { GetUserDataAs<MockXdgTopLevel>(resource)->SetMaximized(); } void UnsetMaximized(wl_client* client, wl_resource* resource) { GetUserDataAs<MockXdgTopLevel>(resource)->UnsetMaximized(); } void SetFullscreen(wl_client* client, wl_resource* resource, wl_resource* output) { GetUserDataAs<MockXdgTopLevel>(resource)->SetFullscreen(); } void UnsetFullscreen(wl_client* client, wl_resource* resource) { GetUserDataAs<MockXdgTopLevel>(resource)->UnsetFullscreen(); } void SetMinimized(wl_client* client, wl_resource* resource) { GetUserDataAs<MockXdgTopLevel>(resource)->SetMinimized(); } void SetMaxSize(wl_client* client, wl_resource* resource, int32_t width, int32_t height) { auto* toplevel = GetUserDataAs<MockXdgTopLevel>(resource); toplevel->SetMaxSize(width, height); // As it this can be envoked during construction of the XdgSurface, cache the // result so that tests are able to access that information. toplevel->set_max_size(gfx::Size(width, height)); } void SetMinSize(wl_client* client, wl_resource* resource, int32_t width, int32_t height) { auto* toplevel = GetUserDataAs<MockXdgTopLevel>(resource); toplevel->SetMinSize(width, height); // As it this can be envoked during construction of the XdgSurface, cache the // result so that tests are able to access that information. toplevel->set_min_size(gfx::Size(width, height)); } void GetTopLevel(wl_client* client, wl_resource* resource, uint32_t id) { auto* surface = GetUserDataAs<MockXdgSurface>(resource); if (surface->xdg_toplevel()) { wl_resource_post_error(resource, XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED, "surface has already been constructed"); return; } wl_resource* xdg_toplevel_resource = wl_resource_create(client, &xdg_toplevel_interface, 1, id); if (!xdg_toplevel_resource) { wl_client_post_no_memory(client); return; } surface->set_xdg_toplevel( std::make_unique<testing::NiceMock<MockXdgTopLevel>>( xdg_toplevel_resource, &kMockXdgToplevelImpl)); } void GetXdgPopup(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* parent, struct wl_resource* positioner_resource) { auto* mock_xdg_surface = GetUserDataAs<MockXdgSurface>(resource); wl_resource* current_resource = mock_xdg_surface->resource(); if (current_resource && (ResourceHasImplementation(current_resource, &xdg_popup_interface, &kXdgPopupImpl) || ResourceHasImplementation(current_resource, &xdg_positioner_interface, &kTestXdgPositionerImpl))) { wl_resource_post_error(resource, XDG_SURFACE_ERROR_ALREADY_CONSTRUCTED, "surface has already been constructed"); return; } wl_resource* xdg_popup_resource = CreateResourceWithImpl<::testing::NiceMock<TestXdgPopup>>( client, &xdg_popup_interface, wl_resource_get_version(resource), &kXdgPopupImpl, id, resource); if (!xdg_popup_resource) { wl_client_post_no_memory(client); return; } auto* test_xdg_popup = GetUserDataAs<TestXdgPopup>(xdg_popup_resource); DCHECK(test_xdg_popup); auto* positioner = GetUserDataAs<TestPositioner>(positioner_resource); DCHECK(positioner); test_xdg_popup->set_position(positioner->position()); if (test_xdg_popup->size().IsEmpty() || test_xdg_popup->anchor_rect().IsEmpty()) { wl_resource_post_error(resource, XDG_WM_BASE_ERROR_INVALID_POSITIONER, "Positioner object is not complete"); return; } mock_xdg_surface->set_xdg_popup(test_xdg_popup); } const struct xdg_surface_interface kMockXdgSurfaceImpl = { &DestroyResource, // destroy &GetTopLevel, // get_toplevel &GetXdgPopup, // get_popup &SetWindowGeometry, // set_window_geometry &AckConfigure, // ack_configure }; const struct xdg_toplevel_interface kMockXdgToplevelImpl = { &DestroyResource, // destroy nullptr, // set_parent &SetTitle, // set_title &SetAppId, // set_app_id nullptr, // show_window_menu &Move, // move &Resize, // resize &SetMaxSize, // set_max_size &SetMinSize, // set_min_size &SetMaximized, // set_maximized &UnsetMaximized, // set_unmaximized &SetFullscreen, // set_fullscreen &UnsetFullscreen, // unset_fullscreen &SetMinimized, // set_minimized }; MockXdgSurface::MockXdgSurface(wl_resource* resource, wl_resource* surface) : ServerObject(resource), surface_(surface) {} MockXdgSurface::~MockXdgSurface() { auto* mock_surface = GetUserDataAs<MockSurface>(surface_); if (mock_surface) mock_surface->set_xdg_surface(nullptr); } MockXdgTopLevel::MockXdgTopLevel(wl_resource* resource, const void* implementation) : ServerObject(resource) { SetImplementationUnretained(resource, implementation, this); } MockXdgTopLevel::~MockXdgTopLevel() {} } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_xdg_surface.cc
C++
unknown
7,320
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SURFACE_H_ #include <memory> #include <utility> #include <xdg-shell-server-protocol.h> #include "base/memory/raw_ptr.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_xdg_popup.h" struct wl_resource; namespace wl { extern const struct xdg_surface_interface kMockXdgSurfaceImpl; extern const struct xdg_toplevel_interface kMockXdgToplevelImpl; extern const struct zxdg_surface_v6_interface kMockZxdgSurfaceV6Impl; extern const struct zxdg_toplevel_v6_interface kMockZxdgToplevelV6Impl; class MockXdgTopLevel; // Manage xdg_surface, zxdg_surface_v6 and zxdg_toplevel for providing desktop // UI. class MockXdgSurface : public ServerObject { public: MockXdgSurface(wl_resource* resource, wl_resource* surface); MockXdgSurface(const MockXdgSurface&) = delete; MockXdgSurface& operator=(const MockXdgSurface&) = delete; ~MockXdgSurface() override; MOCK_METHOD1(AckConfigure, void(uint32_t serial)); MOCK_METHOD1(SetWindowGeometry, void(const gfx::Rect&)); void set_xdg_toplevel(std::unique_ptr<MockXdgTopLevel> xdg_toplevel) { xdg_toplevel_ = std::move(xdg_toplevel); } MockXdgTopLevel* xdg_toplevel() const { return xdg_toplevel_.get(); } void set_xdg_popup(TestXdgPopup* xdg_popup) { xdg_popup_ = xdg_popup; } TestXdgPopup* xdg_popup() const { return xdg_popup_; } private: // Has either toplevel role.. std::unique_ptr<MockXdgTopLevel> xdg_toplevel_; // Or popup role. raw_ptr<TestXdgPopup> xdg_popup_ = nullptr; // MockSurface that is the ground for this xdg_surface. raw_ptr<wl_resource> surface_ = nullptr; }; // Manage zxdg_toplevel for providing desktop UI. class MockXdgTopLevel : public ServerObject { public: MockXdgTopLevel(wl_resource* resource, const void* implementation); MockXdgTopLevel(const MockXdgTopLevel&) = delete; MockXdgTopLevel& operator=(const MockXdgTopLevel&) = delete; ~MockXdgTopLevel() override; MOCK_METHOD1(SetParent, void(wl_resource* parent)); MOCK_METHOD1(SetTitle, void(const std::string& title)); MOCK_METHOD1(SetAppId, void(const char* app_id)); MOCK_METHOD1(Move, void(uint32_t serial)); MOCK_METHOD2(Resize, void(uint32_t serial, uint32_t edges)); MOCK_METHOD0(SetMaximized, void()); MOCK_METHOD0(UnsetMaximized, void()); MOCK_METHOD0(SetFullscreen, void()); MOCK_METHOD0(UnsetFullscreen, void()); MOCK_METHOD0(SetMinimized, void()); MOCK_METHOD2(SetMaxSize, void(int32_t width, int32_t height)); MOCK_METHOD2(SetMinSize, void(int32_t width, int32_t height)); const std::string& app_id() const { return app_id_; } void set_app_id(const char* app_id) { app_id_ = std::string(app_id); } std::string title() const { return title_; } void set_title(const char* title) { title_ = std::string(title); } const gfx::Size& min_size() const { return min_size_; } void set_min_size(const gfx::Size& min_size) { min_size_ = min_size; } const gfx::Size& max_size() const { return max_size_; } void set_max_size(const gfx::Size& max_size) { max_size_ = max_size; } private: gfx::Size min_size_; gfx::Size max_size_; std::string title_; std::string app_id_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_xdg_surface.h
C++
unknown
3,544
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_zcr_extended_text_input.h" namespace wl { namespace { void DeprecatedSetInputType(wl_client* client, wl_resource* resource, uint32_t input_type, uint32_t input_mode, uint32_t input_flags, uint32_t learning_mode) { GetUserDataAs<MockZcrExtendedTextInput>(resource)->DeprecatedSetInputType( input_type, input_mode, input_flags, learning_mode); } void SetInputType(wl_client* client, wl_resource* resource, uint32_t input_type, uint32_t input_mode, uint32_t input_flags, uint32_t learning_mode, uint32_t inline_composition_support) { GetUserDataAs<MockZcrExtendedTextInput>(resource)->SetInputType( input_type, input_mode, input_flags, learning_mode, inline_composition_support); } void SetGrammarFragmentAtCursor(wl_client* client, wl_resource* resource, uint32_t start, uint32_t end, const char* suggestion) { GetUserDataAs<MockZcrExtendedTextInput>(resource)->SetGrammarFragmentAtCursor( gfx::Range(start, end), suggestion); } void SetAutocorrectInfo(wl_client* client, wl_resource* resource, uint32_t start, uint32_t end, uint32_t x, uint32_t y, uint32_t width, uint32_t height) { GetUserDataAs<MockZcrExtendedTextInput>(resource)->SetAutocorrectInfo( gfx::Range(start, end), gfx::Rect(x, y, width, height)); } void FinalizeVirtualKeyboardChanges(wl_client* client, wl_resource* resource) { GetUserDataAs<MockZcrExtendedTextInput>(resource) ->FinalizeVirtualKeyboardChanges(); } void SetFocusReason(wl_client* client, wl_resource* resource, uint32_t reason) { GetUserDataAs<MockZcrExtendedTextInput>(resource)->SetFocusReason(reason); } } // namespace const struct zcr_extended_text_input_v1_interface kMockZcrExtendedTextInputV1Impl = { &DestroyResource, // destroy &DeprecatedSetInputType, // deprecated_set_input_type &SetGrammarFragmentAtCursor, // set_grammar_fragment_at_cursor &SetAutocorrectInfo, // set_autocorrect_info &FinalizeVirtualKeyboardChanges, // finalize_virtual_keyboard_changes &SetFocusReason, // set_focus_reason &SetInputType, // set_input_type }; MockZcrExtendedTextInput::MockZcrExtendedTextInput(wl_resource* resource) : ServerObject(resource) {} MockZcrExtendedTextInput::~MockZcrExtendedTextInput() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_zcr_extended_text_input.cc
C++
unknown
3,099
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZCR_EXTENDED_TEXT_INPUT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZCR_EXTENDED_TEXT_INPUT_H_ #include <text-input-extension-unstable-v1-server-protocol.h> #include <string> #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/range/range.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct zcr_extended_text_input_v1_interface kMockZcrExtendedTextInputV1Impl; // Manage zcr_extended_text_input_v1. class MockZcrExtendedTextInput : public ServerObject { public: explicit MockZcrExtendedTextInput(wl_resource* resource); MockZcrExtendedTextInput(const MockZcrExtendedTextInput&) = delete; MockZcrExtendedTextInput& operator=(const MockZcrExtendedTextInput&) = delete; ~MockZcrExtendedTextInput() override; MOCK_METHOD(void, DeprecatedSetInputType, (uint32_t input_type, uint32_t input_mode, uint32_t input_flags, uint32_t learning_mode)); MOCK_METHOD(void, SetInputType, (uint32_t input_type, uint32_t input_mode, uint32_t input_flags, uint32_t learning_mode, uint32_t inline_composition_support)); MOCK_METHOD(void, SetGrammarFragmentAtCursor, (const gfx::Range& range, const std::string& suggestion)); MOCK_METHOD(void, SetAutocorrectInfo, (const gfx::Range& range, const gfx::Rect& bounds)); MOCK_METHOD(void, FinalizeVirtualKeyboardChanges, ()); MOCK_METHOD(void, SetFocusReason, (uint32_t reason)); }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_TEXT_INPUT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_zcr_extended_text_input.h
C++
unknown
1,942
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_zwp_linux_dmabuf.h" #include <linux-dmabuf-unstable-v1-server-protocol.h> #include <wayland-server-core.h> #include "base/ranges/algorithm.h" #include "ui/ozone/platform/wayland/test/test_buffer.h" #include "ui/ozone/platform/wayland/test/test_zwp_linux_buffer_params.h" namespace wl { namespace { constexpr uint32_t kLinuxDmabufVersion = 1; void CreateParams(wl_client* client, wl_resource* resource, uint32_t id) { wl_resource* params_resource = CreateResourceWithImpl<TestZwpLinuxBufferParamsV1>( client, &zwp_linux_buffer_params_v1_interface, wl_resource_get_version(resource), &kTestZwpLinuxBufferParamsV1Impl, id); auto* zwp_linux_dmabuf = GetUserDataAs<MockZwpLinuxDmabufV1>(resource); auto* buffer_params = GetUserDataAs<TestZwpLinuxBufferParamsV1>(params_resource); DCHECK(buffer_params); zwp_linux_dmabuf->StoreBufferParams(buffer_params); buffer_params->SetZwpLinuxDmabuf(zwp_linux_dmabuf); zwp_linux_dmabuf->CreateParams(client, resource, id); } } // namespace const struct zwp_linux_dmabuf_v1_interface kMockZwpLinuxDmabufV1Impl = { &DestroyResource, // destroy &CreateParams, // create_params }; MockZwpLinuxDmabufV1::MockZwpLinuxDmabufV1() : GlobalObject(&zwp_linux_dmabuf_v1_interface, &kMockZwpLinuxDmabufV1Impl, kLinuxDmabufVersion) {} MockZwpLinuxDmabufV1::~MockZwpLinuxDmabufV1() { DCHECK(buffer_params_.empty()); } void MockZwpLinuxDmabufV1::StoreBufferParams( TestZwpLinuxBufferParamsV1* params) { buffer_params_.push_back(params); } void MockZwpLinuxDmabufV1::OnBufferParamsDestroyed( TestZwpLinuxBufferParamsV1* params) { auto it = base::ranges::find(buffer_params_, params); DCHECK(it != buffer_params_.end()); buffer_params_.erase(it); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_zwp_linux_dmabuf.cc
C++
unknown
2,018
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_LINUX_DMABUF_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_LINUX_DMABUF_H_ #include <linux-dmabuf-unstable-v1-server-protocol.h> #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/global_object.h" struct wl_client; struct wl_resource; namespace wl { extern const struct zwp_linux_dmabuf_v1_interface kMockZwpLinuxDmabufV1Impl; class TestZwpLinuxBufferParamsV1; // Manage zwp_linux_dmabuf_v1 object. class MockZwpLinuxDmabufV1 : public GlobalObject { public: MockZwpLinuxDmabufV1(); MockZwpLinuxDmabufV1(const MockZwpLinuxDmabufV1&) = delete; MockZwpLinuxDmabufV1& operator=(const MockZwpLinuxDmabufV1&) = delete; ~MockZwpLinuxDmabufV1() override; MOCK_METHOD2(Destroy, void(wl_client* client, wl_resource* resource)); MOCK_METHOD3(CreateParams, void(wl_client* client, wl_resource* resource, uint32_t params_id)); const std::vector<TestZwpLinuxBufferParamsV1*>& buffer_params() const { return buffer_params_; } void StoreBufferParams(TestZwpLinuxBufferParamsV1* params); void OnBufferParamsDestroyed(TestZwpLinuxBufferParamsV1* params); private: std::vector<TestZwpLinuxBufferParamsV1*> buffer_params_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_LINUX_DMABUF_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_zwp_linux_dmabuf.h
C++
unknown
1,525
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/mock_zwp_text_input.h" namespace wl { namespace { void TextInputV1Activate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface) { GetUserDataAs<MockZwpTextInput>(resource)->Activate(surface); } void TextInputV1Deactivate(wl_client* client, wl_resource* resource, wl_resource* seat) { GetUserDataAs<MockZwpTextInput>(resource)->Deactivate(); } void TextInputV1ShowInputPanel(wl_client* client, wl_resource* resource) { GetUserDataAs<MockZwpTextInput>(resource)->ShowInputPanel(); } void TextInputV1HideInputPanel(wl_client* client, wl_resource* resource) { GetUserDataAs<MockZwpTextInput>(resource)->HideInputPanel(); } void TextInputV1Reset(wl_client* client, wl_resource* resource) { GetUserDataAs<MockZwpTextInput>(resource)->Reset(); } void TextInputV1SetSurroundingText(wl_client* client, wl_resource* resource, const char* text, uint32_t cursor, uint32_t anchor) { GetUserDataAs<MockZwpTextInput>(resource)->SetSurroundingText( text, gfx::Range(cursor, anchor)); } void TextInputV1SetContentType(wl_client* client, wl_resource* resource, uint32_t content_hint, uint32_t content_purpose) { GetUserDataAs<MockZwpTextInput>(resource)->SetContentType(content_hint, content_purpose); } void TextInputV1SetCursorRectangle(wl_client* client, wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height) { GetUserDataAs<MockZwpTextInput>(resource)->SetCursorRect(x, y, width, height); } } // namespace const struct zwp_text_input_v1_interface kMockZwpTextInputV1Impl = { &TextInputV1Activate, // activate &TextInputV1Deactivate, // deactivate &TextInputV1ShowInputPanel, // show_input_panel &TextInputV1HideInputPanel, // hide_input_panel &TextInputV1Reset, // reset &TextInputV1SetSurroundingText, // set_surrounding_text &TextInputV1SetContentType, // set_content_type &TextInputV1SetCursorRectangle, // set_cursor_rectangle nullptr, // set_preferred_language nullptr, // commit_state nullptr, // invoke_action }; MockZwpTextInput::MockZwpTextInput(wl_resource* resource) : ServerObject(resource) {} MockZwpTextInput::~MockZwpTextInput() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_zwp_text_input.cc
C++
unknown
3,103
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_TEXT_INPUT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_TEXT_INPUT_H_ #include <text-input-unstable-v1-server-protocol.h> #include "testing/gmock/include/gmock/gmock.h" #include "ui/gfx/range/range.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct zwp_text_input_v1_interface kMockZwpTextInputV1Impl; // Manage zwp_text_input_v1. class MockZwpTextInput : public ServerObject { public: explicit MockZwpTextInput(wl_resource* resource); MockZwpTextInput(const MockZwpTextInput&) = delete; MockZwpTextInput& operator=(const MockZwpTextInput&) = delete; ~MockZwpTextInput() override; MOCK_METHOD(void, Reset, ()); MOCK_METHOD(void, Activate, (wl_resource * window)); MOCK_METHOD(void, Deactivate, ()); MOCK_METHOD(void, ShowInputPanel, ()); MOCK_METHOD(void, HideInputPanel, ()); MOCK_METHOD(void, SetCursorRect, (int32_t x, int32_t y, int32_t width, int32_t height)); MOCK_METHOD(void, SetSurroundingText, (std::string text, gfx::Range selection_range)); MOCK_METHOD(void, SetContentType, (uint32_t content_hint, uint32_t content_purpose)); }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_TEXT_INPUT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/mock_zwp_text_input.h
C++
unknown
1,509
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/scoped_wl_array.h" #include <wayland-server-core.h> namespace wl { ScopedWlArray::ScopedWlArray(const std::vector<int32_t> states) { wl_array_init(&array_); for (const auto& state : states) AddStateToWlArray(state); } ScopedWlArray::ScopedWlArray(const ScopedWlArray& rhs) { wl_array_init(&array_); wl_array_copy(&array_, const_cast<wl_array*>(&rhs.array_)); } ScopedWlArray::ScopedWlArray(ScopedWlArray&& rhs) { array_ = rhs.array_; // wl_array_init sets rhs.array_'s fields to nullptr, so that // the free() in wl_array_release() is a no-op. wl_array_init(&rhs.array_); } ScopedWlArray& ScopedWlArray::operator=(ScopedWlArray&& rhs) { wl_array_release(&array_); array_ = rhs.array_; // wl_array_init sets rhs.array_'s fields to nullptr, so that // the free() in wl_array_release() is a no-op. wl_array_init(&rhs.array_); return *this; } ScopedWlArray::~ScopedWlArray() { wl_array_release(&array_); } void ScopedWlArray::AddStateToWlArray(uint32_t state) { *static_cast<uint32_t*>(wl_array_add(&array_, sizeof(uint32_t))) = state; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/scoped_wl_array.cc
C++
unknown
1,283
// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_SCOPED_WL_ARRAY_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_SCOPED_WL_ARRAY_H_ #include <wayland-server-core.h> #include <vector> namespace wl { class ScopedWlArray { public: explicit ScopedWlArray(const std::vector<int32_t> states); ScopedWlArray(const ScopedWlArray& rhs); ScopedWlArray(ScopedWlArray&& rhs); ScopedWlArray& operator=(ScopedWlArray&& rhs); ~ScopedWlArray(); wl_array* get() { return &array_; } void AddStateToWlArray(uint32_t state); private: wl_array array_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_SCOPED_WL_ARRAY_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/scoped_wl_array.h
C++
unknown
769
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { bool ResourceHasImplementation(wl_resource* resource, const wl_interface* interface, const void* impl) { return wl_resource_instance_of(resource, interface, impl); } void DestroyResource(wl_client* client, wl_resource* resource) { wl_resource_destroy(resource); } ServerObject::ServerObject(wl_resource* resource) : resource_(resource) {} ServerObject::~ServerObject() { if (resource_) wl_resource_destroy(resource_); } // static void ServerObject::OnResourceDestroyed(wl_resource* resource) { auto* obj = GetUserDataAs<ServerObject>(resource); obj->resource_ = nullptr; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/server_object.cc
C++
unknown
892
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_SERVER_OBJECT_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_SERVER_OBJECT_H_ #include <memory> #include <type_traits> #include <utility> #include <wayland-server-core.h> #include "base/memory/raw_ptr.h" struct wl_client; struct wl_resource; namespace wl { // Base class for managing the life cycle of server objects. class ServerObject { public: explicit ServerObject(wl_resource* resource); ServerObject(const ServerObject&) = delete; ServerObject& operator=(const ServerObject&) = delete; virtual ~ServerObject(); wl_resource* resource() const { return resource_; } static void OnResourceDestroyed(wl_resource* resource); private: raw_ptr<wl_resource> resource_; }; template <class T> T* GetUserDataAs(wl_resource* resource) { return static_cast<T*>(wl_resource_get_user_data(resource)); } template <class T> std::unique_ptr<T> TakeUserDataAs(wl_resource* resource) { std::unique_ptr<T> user_data(GetUserDataAs<T>(resource)); if (std::is_base_of<ServerObject, T>::value) { // Make sure ServerObject doesn't try to destroy the resource twice. ServerObject::OnResourceDestroyed(resource); } wl_resource_set_user_data(resource, nullptr); return user_data; } template <class T> void DestroyUserData(wl_resource* resource) { TakeUserDataAs<T>(resource); } template <class T> void SetImplementation(wl_resource* resource, const void* implementation, std::unique_ptr<T> user_data) { wl_resource_set_implementation(resource, implementation, user_data.release(), DestroyUserData<T>); } template <typename ImplClass, typename... ImplArgs> wl_resource* CreateResourceWithImpl(wl_client* client, const struct wl_interface* interface, int version, const void* implementation, uint32_t id, ImplArgs&&... impl_args) { wl_resource* resource = wl_resource_create(client, interface, version, id); if (!resource) { wl_client_post_no_memory(client); return nullptr; } SetImplementation(resource, implementation, std::make_unique<ImplClass>( resource, std::forward<ImplArgs&&>(impl_args)...)); return resource; } // Does not transfer ownership of the user_data. Use with caution. The only // legitimate purpose is setting more than one implementation to the same user // data. template <class T> void SetImplementationUnretained(wl_resource* resource, const void* implementation, T* user_data) { static_assert(std::is_base_of<ServerObject, T>::value, "Only types derived from ServerObject are supported!"); wl_resource_set_implementation(resource, implementation, user_data, &ServerObject::OnResourceDestroyed); } bool ResourceHasImplementation(wl_resource* resource, const wl_interface* interface, const void* impl); void DestroyResource(wl_client* client, wl_resource* resource); } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_SERVER_OBJECT_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/server_object.h
C++
unknown
3,485
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_alpha_compositing.h" #include <alpha-compositing-unstable-v1-server-protocol.h> #include <wayland-server-core.h> #include "base/check.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/test_viewport.h" namespace wl { namespace { void SetBlending(wl_client* client, wl_resource* resource, uint32_t equation) { NOTIMPLEMENTED_LOG_ONCE(); } void SetAlpha(wl_client* client, wl_resource* resource, wl_fixed_t value) { NOTIMPLEMENTED_LOG_ONCE(); } } // namespace const struct zcr_blending_v1_interface kTestAlphaBlendingImpl = { DestroyResource, SetBlending, SetAlpha, }; TestAlphaBlending::TestAlphaBlending(wl_resource* resource, wl_resource* surface) : ServerObject(resource), surface_(surface) { DCHECK(surface_); } TestAlphaBlending::~TestAlphaBlending() { auto* mock_surface = GetUserDataAs<MockSurface>(surface_); if (mock_surface) mock_surface->set_blending(nullptr); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_alpha_blending.cc
C++
unknown
1,240
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ALPHA_BLENDING_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ALPHA_BLENDING_H_ #include <alpha-compositing-unstable-v1-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct zcr_blending_v1_interface kTestAlphaBlendingImpl; class TestAlphaBlending : public ServerObject { public: explicit TestAlphaBlending(wl_resource* resource, wl_resource* surface); TestAlphaBlending(const TestAlphaBlending& rhs) = delete; TestAlphaBlending& operator=(const TestAlphaBlending& rhs) = delete; ~TestAlphaBlending() override; private: // Surface resource that is the ground for this Viewport. raw_ptr<wl_resource> surface_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ALPHA_BLENDING_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_alpha_blending.h
C++
unknown
1,028
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_alpha_compositing.h" #include <alpha-compositing-unstable-v1-server-protocol.h> #include <wayland-server-core.h> #include "base/check.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/test_alpha_blending.h" namespace wl { namespace { constexpr uint32_t kAlphaCompositingVersion = 1; void GetBlending(struct wl_client* client, struct wl_resource* resource, uint32_t id, struct wl_resource* surface) { auto* mock_surface = GetUserDataAs<MockSurface>(surface); if (mock_surface->blending()) { wl_resource_post_error(resource, ZCR_ALPHA_COMPOSITING_V1_ERROR_BLENDING_EXISTS, "Alpha Compositing exists"); return; } wl_resource* blending_resource = CreateResourceWithImpl<::testing::NiceMock<TestAlphaBlending>>( client, &zcr_blending_v1_interface, wl_resource_get_version(resource), &kTestAlphaBlendingImpl, id, surface); DCHECK(blending_resource); mock_surface->set_blending( GetUserDataAs<TestAlphaBlending>(blending_resource)); } } // namespace const struct zcr_alpha_compositing_v1_interface kTestAlphaCompositingImpl = { DestroyResource, GetBlending, }; TestAlphaCompositing::TestAlphaCompositing() : GlobalObject(&zcr_alpha_compositing_v1_interface, &kTestAlphaCompositingImpl, kAlphaCompositingVersion) {} TestAlphaCompositing::~TestAlphaCompositing() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_alpha_compositing.cc
C++
unknown
1,745
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ALPHA_COMPOSITING_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ALPHA_COMPOSITING_H_ #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { // Manage wl_viewporter object. class TestAlphaCompositing : public GlobalObject { public: TestAlphaCompositing(); TestAlphaCompositing(const TestAlphaCompositing& rhs) = delete; TestAlphaCompositing& operator=(const TestAlphaCompositing& rhs) = delete; ~TestAlphaCompositing() override; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ALPHA_COMPOSITING_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_alpha_compositing.h
C++
unknown
739
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_augmented_subsurface.h" #include "base/logging.h" #include "base/notreached.h" #include "ui/gfx/geometry/rounded_corners_f.h" #include "ui/gfx/geometry/rrect_f.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" namespace wl { namespace { void SetPosition(struct wl_client* client, struct wl_resource* resource, wl_fixed_t x, wl_fixed_t y) { auto* test_augmented_subsurface = GetUserDataAs<TestAugmentedSubSurface>(resource); DCHECK(test_augmented_subsurface); auto* test_subsurface = GetUserDataAs<TestSubSurface>(test_augmented_subsurface->sub_surface()); DCHECK(test_subsurface); test_subsurface->SetPositionImpl(wl_fixed_to_double(x), wl_fixed_to_double(y)); } } // namespace const struct augmented_sub_surface_interface kTestAugmentedSubSurfaceImpl = { DestroyResource, SetPosition, }; TestAugmentedSubSurface::TestAugmentedSubSurface(wl_resource* resource, wl_resource* sub_surface) : ServerObject(resource), sub_surface_(sub_surface) { DCHECK(sub_surface_); } TestAugmentedSubSurface::~TestAugmentedSubSurface() { auto* test_sub_surface = GetUserDataAs<TestSubSurface>(sub_surface_); if (test_sub_surface) test_sub_surface->set_augmented_subsurface(nullptr); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_augmented_subsurface.cc
C++
unknown
1,575
// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_AUGMENTED_SUBSURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_AUGMENTED_SUBSURFACE_H_ #include <surface-augmenter-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/server_object.h" namespace wl { extern const struct augmented_sub_surface_interface kTestAugmentedSubSurfaceImpl; // Manage surface_augmenter object. class TestAugmentedSubSurface : public ServerObject { public: TestAugmentedSubSurface(wl_resource* resource, wl_resource* sub_surface); ~TestAugmentedSubSurface() override; TestAugmentedSubSurface(const TestAugmentedSubSurface& rhs) = delete; TestAugmentedSubSurface& operator=(const TestAugmentedSubSurface& rhs) = delete; wl_resource* sub_surface() const { return sub_surface_; } private: // Subsurface resource that is the ground for this augmented surface. raw_ptr<wl_resource> sub_surface_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_AUGMENTED_SUBSURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_augmented_subsurface.h
C++
unknown
1,185
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_augmented_surface.h" #include "base/logging.h" #include "ui/gfx/geometry/rounded_corners_f.h" #include "ui/gfx/geometry/rrect_f.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" namespace wl { namespace { void SetRoundedCornersDEPRECATED(struct wl_client* client, struct wl_resource* resource, wl_fixed_t top_left, wl_fixed_t top_right, wl_fixed_t bottom_right, wl_fixed_t bottom_left) { LOG(ERROR) << "Deprecated."; } void SetDestinationSize(struct wl_client* client, struct wl_resource* resource, wl_fixed_t width, wl_fixed_t height) { auto* res = GetUserDataAs<TestAugmentedSurface>(resource)->surface(); DCHECK(res); auto* mock_surface = GetUserDataAs<MockSurface>(res); auto* viewport = mock_surface->viewport(); DCHECK(viewport); viewport->SetDestinationImpl(wl_fixed_to_double(width), wl_fixed_to_double(height)); } void SetRoundedClipBounds(struct wl_client* client, struct wl_resource* resource, int32_t x, int32_t y, int32_t width, int32_t height, wl_fixed_t top_left, wl_fixed_t top_right, wl_fixed_t bottom_right, wl_fixed_t bottom_left) { GetUserDataAs<TestAugmentedSurface>(resource)->set_rounded_clip_bounds( gfx::RRectF(gfx::RectF(x, y, width, height), gfx::RoundedCornersF(wl_fixed_to_double(top_left), wl_fixed_to_double(top_right), wl_fixed_to_double(bottom_right), wl_fixed_to_double(bottom_left)))); } } // namespace const struct augmented_surface_interface kTestAugmentedSurfaceImpl = { DestroyResource, SetRoundedCornersDEPRECATED, SetDestinationSize, SetRoundedClipBounds, }; TestAugmentedSurface::TestAugmentedSurface(wl_resource* resource, wl_resource* surface) : ServerObject(resource), surface_(surface) { DCHECK(surface_); } TestAugmentedSurface::~TestAugmentedSurface() { auto* mock_surface = GetUserDataAs<MockSurface>(surface_); if (mock_surface) mock_surface->set_augmented_surface(nullptr); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_augmented_surface.cc
C++
unknown
2,792
// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_AUGMENTED_SURFACE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_AUGMENTED_SURFACE_H_ #include <surface-augmenter-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/gfx/geometry/rrect_f.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct augmented_surface_interface kTestAugmentedSurfaceImpl; class TestAugmentedSurface : public ServerObject { public: TestAugmentedSurface(wl_resource* resource, wl_resource* surface); ~TestAugmentedSurface() override; TestAugmentedSurface(const TestAugmentedSurface& rhs) = delete; TestAugmentedSurface& operator=(const TestAugmentedSurface& rhs) = delete; void set_rounded_clip_bounds(const gfx::RRectF& rounded_clip_bounds) { rounded_clip_bounds_ = rounded_clip_bounds; } const gfx::RRectF& rounded_clip_bounds() { return rounded_clip_bounds_; } wl_resource* surface() const { return surface_; } private: // Surface resource that is the ground for this augmented surface. raw_ptr<wl_resource> surface_ = nullptr; gfx::RRectF rounded_clip_bounds_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_AUGMENTED_SURFACE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_augmented_surface.h
C++
unknown
1,380
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_buffer.h" namespace wl { const struct wl_buffer_interface kTestWlBufferImpl = {&DestroyResource}; TestBuffer::TestBuffer(wl_resource* resource, std::vector<base::ScopedFD>&& fds) : ServerObject(resource), fds_(std::move(fds)) {} TestBuffer::~TestBuffer() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_buffer.cc
C++
unknown
484
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_BUFFER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_BUFFER_H_ #include <linux-dmabuf-unstable-v1-server-protocol.h> #include "base/files/scoped_file.h" #include "testing/gmock/include/gmock/gmock.h" #include "ui/ozone/platform/wayland/test/server_object.h" struct wl_resource; namespace wl { extern const struct wl_buffer_interface kTestWlBufferImpl; // Manage wl_buffer object. class TestBuffer : public ServerObject { public: TestBuffer(wl_resource* resource, std::vector<base::ScopedFD>&& fds); TestBuffer(const TestBuffer&) = delete; TestBuffer& operator=(const TestBuffer&) = delete; ~TestBuffer() override; private: std::vector<base::ScopedFD> fds_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_BUFFER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_buffer.h
C++
unknown
948
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_compositor.h" #include <wayland-server-core.h> #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_region.h" namespace wl { namespace { void CreateSurface(wl_client* client, wl_resource* compositor_resource, uint32_t id) { wl_resource* resource = CreateResourceWithImpl<::testing::NiceMock<MockSurface>>( client, &wl_surface_interface, wl_resource_get_version(compositor_resource), &kMockSurfaceImpl, id); GetUserDataAs<TestCompositor>(compositor_resource) ->AddSurface(GetUserDataAs<MockSurface>(resource)); } void CreateRegion(wl_client* client, wl_resource* resource, uint32_t id) { wl_resource* region_resource = wl_resource_create(client, &wl_region_interface, 1, id); SetImplementation(region_resource, &kTestWlRegionImpl, std::make_unique<TestRegion>()); } } // namespace const struct wl_compositor_interface kTestCompositorImpl = { CreateSurface, // create_surface CreateRegion, // create_region }; TestCompositor::TestCompositor(TestCompositor::Version intended_version) : GlobalObject(&wl_compositor_interface, &kTestCompositorImpl, static_cast<uint32_t>(intended_version)), version_(intended_version) {} TestCompositor::~TestCompositor() = default; void TestCompositor::AddSurface(MockSurface* surface) { surfaces_.push_back(surface); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_compositor.cc
C++
unknown
1,744
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_COMPOSITOR_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_COMPOSITOR_H_ #include <cstdint> #include <vector> #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { class MockSurface; // Manage wl_compositor object. class TestCompositor : public GlobalObject { public: enum class Version : uint32_t { kV3 = 3, kV4 = 4, }; explicit TestCompositor(Version intended_version); TestCompositor(const TestCompositor&) = delete; TestCompositor& operator=(const TestCompositor&) = delete; ~TestCompositor() override; void AddSurface(MockSurface* surface); Version GetVersion() { return version_; } private: Version version_; std::vector<MockSurface*> surfaces_; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_COMPOSITOR_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_compositor.h
C++
unknown
982
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_data_device.h" #include <wayland-server-core.h> #include <cstdint> #include <memory> #include "base/memory/raw_ptr.h" #include "base/notreached.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/server_object.h" #include "ui/ozone/platform/wayland/test/test_data_device_manager.h" #include "ui/ozone/platform/wayland/test/test_data_offer.h" #include "ui/ozone/platform/wayland/test/test_data_source.h" #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" namespace wl { namespace { void DataDeviceStartDrag(wl_client* client, wl_resource* resource, wl_resource* source, wl_resource* origin, wl_resource* icon, uint32_t serial) { auto* data_source = GetUserDataAs<TestDataSource>(source); auto* origin_surface = GetUserDataAs<MockSurface>(origin); GetUserDataAs<TestDataDevice>(resource)->StartDrag(data_source, origin_surface, serial); } void DataDeviceRelease(wl_client* client, wl_resource* resource) { wl_resource_destroy(resource); } struct WlDataDeviceImpl : public TestSelectionDevice::Delegate { explicit WlDataDeviceImpl(TestDataDevice* device) : device_(device) {} ~WlDataDeviceImpl() override = default; WlDataDeviceImpl(const WlDataDeviceImpl&) = delete; WlDataDeviceImpl& operator=(const WlDataDeviceImpl&) = delete; TestSelectionOffer* CreateAndSendOffer() override { wl_resource* device_resource = device_->resource(); wl_resource* new_offer_resource = CreateResourceWithImpl<TestDataOffer>( wl_resource_get_client(device_resource), &wl_data_offer_interface, wl_resource_get_version(device_resource), &kTestDataOfferImpl, 0); wl_data_device_send_data_offer(device_resource, new_offer_resource); return GetUserDataAs<TestSelectionOffer>(new_offer_resource); } void HandleSetSelection(TestSelectionSource* source, uint32_t serial) override { device_->SetSelection(static_cast<TestDataSource*>(source), serial); } void SendSelection(TestSelectionOffer* selection_offer) override { CHECK(selection_offer); wl_data_device_send_selection(device_->resource(), selection_offer->resource()); } private: const raw_ptr<TestDataDevice> device_; }; } // namespace const struct wl_data_device_interface kTestDataDeviceImpl = { &DataDeviceStartDrag, &TestSelectionDevice::SetSelection, &DataDeviceRelease}; TestDataDevice::TestDataDevice(wl_resource* resource, TestDataDeviceManager* manager) : TestSelectionDevice(resource, std::make_unique<WlDataDeviceImpl>(this)), manager_(manager) {} TestDataDevice::~TestDataDevice() = default; void TestDataDevice::SetSelection(TestDataSource* data_source, uint32_t serial) { CHECK(manager_); manager_->set_data_source(data_source); } TestDataOffer* TestDataDevice::CreateAndSendDataOffer() { return static_cast<TestDataOffer*>(TestSelectionDevice::OnDataOffer()); } void TestDataDevice::StartDrag(TestDataSource* source, MockSurface* origin, uint32_t serial) { DCHECK(source); DCHECK(origin); CHECK(manager_); drag_serial_ = serial; manager_->set_data_source(source); SendOfferAndEnter(origin, {}); wl_client_flush(wl_resource_get_client(resource())); } void TestDataDevice::SendOfferAndEnter(MockSurface* origin, const gfx::Point& location) { DCHECK(manager_->data_source()); auto* data_offer = OnDataOffer(); DCHECK(data_offer); for (const auto& mime_type : manager_->data_source()->mime_types()) data_offer->OnOffer(mime_type, {}); auto* client = wl_resource_get_client(resource()); auto* display = wl_client_get_display(client); DCHECK(display); wl_data_device_send_enter(resource(), wl_display_get_serial(display), origin->resource(), wl_fixed_from_int(location.x()), wl_fixed_from_int(location.y()), data_offer->resource()); } void TestDataDevice::OnEnter(uint32_t serial, wl_resource* surface, wl_fixed_t x, wl_fixed_t y, TestDataOffer* data_offer) { wl_data_device_send_enter(resource(), serial, surface, x, y, data_offer->resource()); } void TestDataDevice::OnLeave() { wl_data_device_send_leave(resource()); } void TestDataDevice::OnMotion(uint32_t time, wl_fixed_t x, wl_fixed_t y) { wl_data_device_send_motion(resource(), time, x, y); } void TestDataDevice::OnDrop() { wl_data_device_send_drop(resource()); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_data_device.cc
C++
unknown
5,215
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_H_ #include <wayland-server-protocol.h> #include <cstdint> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/mock_surface.h" #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" struct wl_resource; namespace wl { extern const struct wl_data_device_interface kTestDataDeviceImpl; class TestDataOffer; class TestDataSource; class TestDataDeviceManager; class TestDataDevice : public TestSelectionDevice { public: TestDataDevice(wl_resource* resource, TestDataDeviceManager* manager); TestDataDevice(const TestDataDevice&) = delete; TestDataDevice& operator=(const TestDataDevice&) = delete; ~TestDataDevice() override; TestDataOffer* CreateAndSendDataOffer(); void SetSelection(TestDataSource* data_source, uint32_t serial); void StartDrag(TestDataSource* data_source, MockSurface* origin, uint32_t serial); void SendOfferAndEnter(MockSurface* origin, const gfx::Point& location); void OnEnter(uint32_t serial, wl_resource* surface, wl_fixed_t x, wl_fixed_t y, TestDataOffer* data_offer); void OnLeave(); void OnMotion(uint32_t time, wl_fixed_t x, wl_fixed_t y); void OnDrop(); uint32_t drag_serial() const { return drag_serial_; } private: const raw_ptr<TestDataDeviceManager> manager_; uint32_t drag_serial_ = 0; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_data_device.h
C++
unknown
1,744
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_data_device_manager.h" #include <wayland-server-core.h> #include "ui/ozone/platform/wayland/test/test_data_device.h" #include "ui/ozone/platform/wayland/test/test_data_source.h" #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" namespace wl { namespace { constexpr uint32_t kDataDeviceManagerVersion = 3; void CreateDataSource(wl_client* client, wl_resource* resource, uint32_t id) { CreateResourceWithImpl<TestDataSource>(client, &wl_data_source_interface, wl_resource_get_version(resource), &kTestDataSourceImpl, id); } void GetDataDevice(wl_client* client, wl_resource* manager_resource, uint32_t id, wl_resource* seat_resource) { auto* manager = GetUserDataAs<TestDataDeviceManager>(manager_resource); CHECK(manager); wl_resource* resource = CreateResourceWithImpl<TestDataDevice>( client, &wl_data_device_interface, wl_resource_get_version(manager_resource), &kTestDataDeviceImpl, id, manager); CHECK(GetUserDataAs<TestDataDevice>(resource)); manager->set_data_device(GetUserDataAs<TestDataDevice>(resource)); } } // namespace const struct wl_data_device_manager_interface kTestDataDeviceManagerImpl = { &CreateDataSource, &GetDataDevice}; TestDataDeviceManager::TestDataDeviceManager() : GlobalObject(&wl_data_device_manager_interface, &kTestDataDeviceManagerImpl, kDataDeviceManagerVersion) {} TestDataDeviceManager::~TestDataDeviceManager() = default; } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_data_device_manager.cc
C++
unknown
1,823
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_MANAGER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_MANAGER_H_ #include <wayland-server-protocol.h> #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/global_object.h" namespace wl { extern const struct wl_data_device_manager_interface kTestDataDeviceManagerImpl; class TestDataDevice; class TestDataSource; // Manage wl_data_device_manager object. class TestDataDeviceManager : public GlobalObject { public: TestDataDeviceManager(); TestDataDeviceManager(const TestDataDeviceManager&) = delete; TestDataDeviceManager& operator=(const TestDataDeviceManager&) = delete; ~TestDataDeviceManager() override; TestDataDevice* data_device() const { return data_device_; } void set_data_device(TestDataDevice* data_device) { data_device_ = data_device; } TestDataSource* data_source() const { return data_source_; } void set_data_source(TestDataSource* data_source) { data_source_ = data_source; } private: raw_ptr<TestDataDevice> data_device_ = nullptr; raw_ptr<TestDataSource> data_source_ = nullptr; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_MANAGER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_data_device_manager.h
C++
unknown
1,372
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_data_offer.h" #include <wayland-server-core.h> #include <utility> #include "base/functional/bind.h" #include "base/logging.h" #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" namespace wl { namespace { void DataOfferAccept(wl_client* client, wl_resource* resource, uint32_t serial, const char* mime_type) { NOTIMPLEMENTED(); } void DataOfferDestroy(wl_client* client, wl_resource* resource) { wl_resource_destroy(resource); } void DataOfferFinish(wl_client* client, wl_resource* resource) { NOTIMPLEMENTED(); } void DataOfferSetActions(wl_client* client, wl_resource* resource, uint32_t dnd_actions, uint32_t preferred_action) { GetUserDataAs<TestDataOffer>(resource)->SetActions(dnd_actions, preferred_action); } struct WlDataOfferImpl : public TestSelectionOffer::Delegate { explicit WlDataOfferImpl(TestDataOffer* offer) : offer_(offer) {} ~WlDataOfferImpl() override = default; WlDataOfferImpl(const WlDataOfferImpl&) = delete; WlDataOfferImpl& operator=(const WlDataOfferImpl&) = delete; void SendOffer(const std::string& mime_type) override { wl_data_offer_send_offer(offer_->resource(), mime_type.c_str()); } private: const raw_ptr<TestDataOffer> offer_; }; } // namespace const struct wl_data_offer_interface kTestDataOfferImpl = { DataOfferAccept, &TestSelectionOffer::Receive, DataOfferDestroy, DataOfferFinish, DataOfferSetActions}; TestDataOffer::TestDataOffer(wl_resource* resource) : TestSelectionOffer(resource, std::make_unique<WlDataOfferImpl>(this)) {} TestDataOffer::~TestDataOffer() = default; // static TestDataOffer* TestDataOffer::FromResource(wl_resource* resource) { if (!ResourceHasImplementation(resource, &wl_data_offer_interface, &kTestDataOfferImpl)) { return nullptr; } return GetUserDataAs<TestDataOffer>(resource); } void TestDataOffer::SetActions(uint32_t dnd_actions, uint32_t preferred_action) { client_supported_actions_ = dnd_actions; client_preferred_action_ = preferred_action; OnAction(client_preferred_action_); } void TestDataOffer::OnSourceActions(uint32_t source_actions) { wl_data_offer_send_source_actions(resource(), source_actions); } void TestDataOffer::OnAction(uint32_t dnd_action) { wl_data_offer_send_action(resource(), dnd_action); } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_data_offer.cc
C++
unknown
2,792
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_OFFER_H_ #define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_OFFER_H_ #include <wayland-server-protocol.h> #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" struct wl_resource; namespace wl { extern const struct wl_data_offer_interface kTestDataOfferImpl; class TestDataOffer : public TestSelectionOffer { public: explicit TestDataOffer(wl_resource* resource); TestDataOffer(const TestDataOffer&) = delete; TestDataOffer& operator=(const TestDataOffer&) = delete; ~TestDataOffer() override; static TestDataOffer* FromResource(wl_resource* resource); void SetActions(uint32_t dnd_actions, uint32_t preferred_action); void OnSourceActions(uint32_t source_actions); void OnAction(uint32_t dnd_action); uint32_t supported_actions() const { return client_supported_actions_; } uint32_t preferred_action() const { return client_preferred_action_; } private: uint32_t client_supported_actions_ = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE; uint32_t client_preferred_action_ = WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE; }; } // namespace wl #endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_OFFER_H_
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_data_offer.h
C++
unknown
1,343
// Copyright 2019 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ui/ozone/platform/wayland/test/test_data_source.h" #include <wayland-server-core.h> #include <memory> #include <string> #include "base/logging.h" #include "base/memory/raw_ptr.h" #include "ui/ozone/platform/wayland/test/test_selection_device_manager.h" #include "ui/ozone/platform/wayland/test/test_wayland_server_thread.h" namespace wl { namespace { void DataSourceDestroy(wl_client* client, wl_resource* resource) { wl_resource_destroy(resource); } void DataSourceSetActions(wl_client* client, wl_resource* resource, uint32_t dnd_actions) { GetUserDataAs<TestDataSource>(resource)->SetActions(dnd_actions); } struct WlDataSourceImpl : public TestSelectionSource::Delegate { explicit WlDataSourceImpl(TestDataSource* source) : source_(source) {} ~WlDataSourceImpl() override = default; WlDataSourceImpl(const WlDataSourceImpl&) = delete; WlDataSourceImpl& operator=(const WlDataSourceImpl&) = delete; void SendSend(const std::string& mime_type, base::ScopedFD write_fd) override { wl_data_source_send_send(source_->resource(), mime_type.c_str(), write_fd.get()); wl_client_flush(wl_resource_get_client(source_->resource())); } void SendFinished() override { wl_data_source_send_dnd_finished(source_->resource()); wl_client_flush(wl_resource_get_client(source_->resource())); } void SendCancelled() override { wl_data_source_send_cancelled(source_->resource()); wl_client_flush(wl_resource_get_client(source_->resource())); } void SendDndAction(uint32_t action) override { wl_data_source_send_action(source_->resource(), action); wl_client_flush(wl_resource_get_client(source_->resource())); } private: const raw_ptr<TestDataSource> source_; }; } // namespace const struct wl_data_source_interface kTestDataSourceImpl = { TestSelectionSource::Offer, DataSourceDestroy, DataSourceSetActions}; TestDataSource::TestDataSource(wl_resource* resource) : TestSelectionSource(resource, std::make_unique<WlDataSourceImpl>(this)) {} TestDataSource::~TestDataSource() = default; void TestDataSource::SetActions(uint32_t dnd_actions) { actions_ |= dnd_actions; } } // namespace wl
Zhao-PengFei35/chromium_src_4
ui/ozone/platform/wayland/test/test_data_source.cc
C++
unknown
2,415