diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 2f2cd3826e..fcb6d093ad 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -112,8 +112,8 @@ group("flutter") { "//flutter/third_party/txt:txt_unittests", ] - # The accessibility library only supports Mac for now. - if (is_mac) { + # The accessibility library only supports Mac and Windows at the moment. + if (is_mac || is_win) { public_deps += [ "//flutter/third_party/accessibility:accessibility_unittests" ] } diff --git a/engine/src/flutter/third_party/accessibility/BUILD.gn b/engine/src/flutter/third_party/accessibility/BUILD.gn index cea4e32185..b1e1fe17cb 100644 --- a/engine/src/flutter/third_party/accessibility/BUILD.gn +++ b/engine/src/flutter/third_party/accessibility/BUILD.gn @@ -45,50 +45,71 @@ if (enable_unittests) { executable("accessibility_unittests") { testonly = true - sources = [ - "ax/ax_enum_util_unittest.cc", - "ax/ax_event_generator_unittest.cc", - "ax/ax_node_data_unittest.cc", - "ax/ax_node_position_unittest.cc", - "ax/ax_range_unittest.cc", - "ax/ax_role_properties_unittest.cc", - "ax/ax_table_info_unittest.cc", - "ax/ax_tree_unittest.cc", - "ax/test_ax_node_helper.cc", - "ax/test_ax_node_helper.h", - "ax/test_ax_tree_manager.cc", - "ax/test_ax_tree_manager.h", - ] + public_configs = [ ":accessibility_config" ] - sources += [ - "ax/platform/ax_platform_node_base_unittest.cc", - "ax/platform/ax_platform_node_unittest.cc", - "ax/platform/ax_platform_node_unittest.h", - "ax/platform/ax_unique_id_unittest.cc", - "ax/platform/test_ax_node_wrapper.cc", - "ax/platform/test_ax_node_wrapper.h", - ] + # TODO(cbracken): make this block unconditional once Windows node support + # is landed. + if (is_mac) { + sources = [ + "ax/ax_enum_util_unittest.cc", + "ax/ax_event_generator_unittest.cc", + "ax/ax_node_data_unittest.cc", + "ax/ax_node_position_unittest.cc", + "ax/ax_range_unittest.cc", + "ax/ax_role_properties_unittest.cc", + "ax/ax_table_info_unittest.cc", + "ax/ax_tree_unittest.cc", + "ax/test_ax_node_helper.cc", + "ax/test_ax_node_helper.h", + "ax/test_ax_tree_manager.cc", + "ax/test_ax_tree_manager.h", + ] - sources += [ - "base/logging_unittests.cc", - "base/string_utils_unittest.cc", - ] + sources += [ + "ax/platform/ax_platform_node_base_unittest.cc", + "ax/platform/ax_platform_node_unittest.cc", + "ax/platform/ax_platform_node_unittest.h", + "ax/platform/ax_unique_id_unittest.cc", + "ax/platform/test_ax_node_wrapper.cc", + "ax/platform/test_ax_node_wrapper.h", + ] - sources += [ - "gfx/geometry/insets_unittest.cc", - "gfx/geometry/point_unittest.cc", - "gfx/geometry/rect_unittest.cc", - "gfx/geometry/size_unittest.cc", - "gfx/geometry/vector2d_unittest.cc", - "gfx/test/gfx_util.cc", - "gfx/test/gfx_util.h", - ] + deps = [ + ":accessibility", + ":accessibility_fixtures", + "//flutter/testing", + "//flutter/testing:dart", + ] + } else if (is_win) { + sources = [ + "base/win/dispatch_stub.cc", + "base/win/dispatch_stub.h", + "base/win/scoped_bstr_unittest.cc", + "base/win/scoped_safearray_unittest.cc", + "base/win/scoped_variant_unittest.cc", + ] - deps = [ - ":accessibility", - ":accessibility_fixtures", - "//flutter/testing", - "//flutter/testing:dart", - ] + deps = [ + ":accessibility_fixtures", + "//flutter/testing", + "//flutter/testing:dart", + "//flutter/third_party/accessibility/base", + ] + } + + if (is_mac || is_win) { + sources += [ + "gfx/geometry/insets_unittest.cc", + "gfx/geometry/point_unittest.cc", + "gfx/geometry/rect_unittest.cc", + "gfx/geometry/size_unittest.cc", + "gfx/geometry/vector2d_unittest.cc", + "gfx/range/range_unittest.cc", + "gfx/test/gfx_util.cc", + "gfx/test/gfx_util.h", + ] + + deps += [ "//flutter/third_party/accessibility/gfx" ] + } } } diff --git a/engine/src/flutter/third_party/accessibility/ax/BUILD.gn b/engine/src/flutter/third_party/accessibility/ax/BUILD.gn index bc85cbbc37..4fca50ec26 100644 --- a/engine/src/flutter/third_party/accessibility/ax/BUILD.gn +++ b/engine/src/flutter/third_party/accessibility/ax/BUILD.gn @@ -29,6 +29,8 @@ source_set("ax") { "ax_action_handler.h", "ax_action_handler_base.cc", "ax_action_handler_base.h", + "ax_active_popup.cc", + "ax_active_popup.h", "ax_base_export.h", "ax_clipping_behavior.h", "ax_constants.h", @@ -82,6 +84,12 @@ source_set("ax") { "platform/ax_platform_node_mac.h", "platform/ax_platform_node_mac.mm", ] + } else if (is_win) { + sources += [ + "platform/uia_registrar_win.cc", + "platform/uia_registrar_win.h", + ] + libs = [ "uiautomationcore.lib" ] } public_deps = [ diff --git a/engine/src/flutter/third_party/accessibility/ax/ax_active_popup.cc b/engine/src/flutter/third_party/accessibility/ax/ax_active_popup.cc index 570838ff53..904de75c4b 100644 --- a/engine/src/flutter/third_party/accessibility/ax/ax_active_popup.cc +++ b/engine/src/flutter/third_party/accessibility/ax/ax_active_popup.cc @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/accessibility/ax_active_popup.h" +#include "ax_active_popup.h" + +#include "base/logging.h" namespace ui { // Represents a global storage for the view accessibility for an @@ -10,13 +12,13 @@ namespace ui { // autofill popup. This singleton is used for communicating the live status of // the autofill popup between web contents and views. // The assumption here is that only one autofill popup can exist at a time. -static base::NoDestructor> g_active_popup_ax_unique_id; +static std::optional g_active_popup_ax_unique_id; -base::Optional GetActivePopupAxUniqueId() { +std::optional GetActivePopupAxUniqueId() { return *g_active_popup_ax_unique_id; } -void SetActivePopupAxUniqueId(base::Optional ax_unique_id) { +void SetActivePopupAxUniqueId(std::optional ax_unique_id) { // When an instance of autofill popup hides, the caller of popup hide should // make sure g_active_popup_ax_unique_id is cleared. The assumption is that // there can only be one active autofill popup existing at a time. If on @@ -24,13 +26,13 @@ void SetActivePopupAxUniqueId(base::Optional ax_unique_id) { // this would indicate two autofill popups are showing at the same time or // previous on popup hide call did not clear the variable, so we should fail // DCHECK here. - DCHECK(!GetActivePopupAxUniqueId()); + BASE_DCHECK(!GetActivePopupAxUniqueId()); - *g_active_popup_ax_unique_id = ax_unique_id; + g_active_popup_ax_unique_id = ax_unique_id; } void ClearActivePopupAxUniqueId() { - *g_active_popup_ax_unique_id = base::nullopt; + g_active_popup_ax_unique_id = std::nullopt; } } // namespace ui diff --git a/engine/src/flutter/third_party/accessibility/ax/ax_active_popup.h b/engine/src/flutter/third_party/accessibility/ax/ax_active_popup.h index 111c8c5468..39b8beda62 100644 --- a/engine/src/flutter/third_party/accessibility/ax/ax_active_popup.h +++ b/engine/src/flutter/third_party/accessibility/ax/ax_active_popup.h @@ -5,15 +5,15 @@ #ifndef UI_ACCESSIBILITY_AX_ACTIVE_POPUP_H_ #define UI_ACCESSIBILITY_AX_ACTIVE_POPUP_H_ +#include + +#include "ax/ax_export.h" #include "base/macros.h" -#include "base/no_destructor.h" -#include "base/optional.h" -#include "ui/accessibility/ax_export.h" namespace ui { -AX_EXPORT base::Optional GetActivePopupAxUniqueId(); +AX_EXPORT std::optional GetActivePopupAxUniqueId(); -AX_EXPORT void SetActivePopupAxUniqueId(base::Optional ax_unique_id); +AX_EXPORT void SetActivePopupAxUniqueId(std::optional ax_unique_id); AX_EXPORT void ClearActivePopupAxUniqueId(); diff --git a/engine/src/flutter/third_party/accessibility/ax/platform/uia_registrar_win.cc b/engine/src/flutter/third_party/accessibility/ax/platform/uia_registrar_win.cc index 40955f8081..0c838d48c7 100644 --- a/engine/src/flutter/third_party/accessibility/ax/platform/uia_registrar_win.cc +++ b/engine/src/flutter/third_party/accessibility/ax/platform/uia_registrar_win.cc @@ -4,7 +4,6 @@ #include "uia_registrar_win.h" #include -#include "base/stl_util.h" namespace ui { diff --git a/engine/src/flutter/third_party/accessibility/base/BUILD.gn b/engine/src/flutter/third_party/accessibility/base/BUILD.gn index c709dae850..d3f76b72a8 100644 --- a/engine/src/flutter/third_party/accessibility/base/BUILD.gn +++ b/engine/src/flutter/third_party/accessibility/base/BUILD.gn @@ -24,9 +24,22 @@ source_set("base") { ] if (is_win) { sources += [ + "win/atl.h", + "win/atl_module.h", + "win/enum_variant.cc", + "win/enum_variant.h", + "win/scoped_bstr.cc", + "win/scoped_bstr.h", + "win/scoped_safearray.h", + "win/scoped_variant.cc", + "win/scoped_variant.h", "win/string_conversion.cc", "win/string_conversion.h", + "win/variant_util.h", + "win/variant_vector.cc", + "win/variant_vector.h", ] + libs = [ "propsys.lib" ] } if (is_mac) { sources += [ diff --git a/engine/src/flutter/third_party/accessibility/base/compiler_specific.h b/engine/src/flutter/third_party/accessibility/base/compiler_specific.h index c1c10c24ea..64dc08becd 100644 --- a/engine/src/flutter/third_party/accessibility/base/compiler_specific.h +++ b/engine/src/flutter/third_party/accessibility/base/compiler_specific.h @@ -27,3 +27,27 @@ #endif #endif // ACCESSIBILITY_BASE_COMPILER_SPECIFIC_H_ + +// Macro for hinting that an expression is likely to be false. +#if !defined(BASE_UNLIKELY) +#if defined(COMPILER_GCC) || defined(__clang__) +#define BASE_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else +#define BASE_UNLIKELY(x) (x) +#endif // defined(COMPILER_GCC) +#endif // !defined(BASE_UNLIKELY) + +#if !defined(BASE_LIKELY) +#if defined(COMPILER_GCC) || defined(__clang__) +#define BASE_LIKELY(x) __builtin_expect(!!(x), 1) +#else +#define BASE_LIKELY(x) (x) +#endif // defined(COMPILER_GCC) +#endif // !defined(BASE_LIKELY) + +// Macro for telling -Wimplicit-fallthrough that a fallthrough is intentional. +#if defined(__clang__) +#define BASE_FALLTHROUGH [[clang::fallthrough]] +#else +#define BASE_FALLTHROUGH +#endif diff --git a/engine/src/flutter/third_party/accessibility/base/test/gtest_util.h b/engine/src/flutter/third_party/accessibility/base/test/gtest_util.h index ae140b9263..c96ccaa504 100644 --- a/engine/src/flutter/third_party/accessibility/base/test/gtest_util.h +++ b/engine/src/flutter/third_party/accessibility/base/test/gtest_util.h @@ -9,10 +9,9 @@ #include #include -#include "base/check_op.h" #include "base/compiler_specific.h" #include "build/build_config.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "gtest/gtest.h" // EXPECT/ASSERT_DCHECK_DEATH is intended to replace EXPECT/ASSERT_DEBUG_DEATH // when the death is expected to be caused by a DCHECK. Contrary to @@ -21,7 +20,9 @@ // happen and as such executing the statement results in undefined behavior // (|statement| is compiled in unsupported configurations nonetheless). // Death tests misbehave on Android. -#if DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) +// TODO(gw280): once https://github.com/flutter/flutter/issues/78491 is resolved +// we can potentially remove the condition on NDEBUG here. +#if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) && !defined(NDEBUG) // EXPECT/ASSERT_DCHECK_DEATH tests verify that a DCHECK is hit ("Check failed" // is part of the error message), but intentionally do not expose the gtest @@ -31,7 +32,7 @@ #define ASSERT_DCHECK_DEATH(statement) ASSERT_DEATH(statement, "Check failed") #else -// DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) +// defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) && !defined(NDEBUG) #define EXPECT_DCHECK_DEATH(statement) \ GTEST_UNSUPPORTED_DEATH_TEST(statement, "Check failed", ) @@ -39,7 +40,7 @@ GTEST_UNSUPPORTED_DEATH_TEST(statement, "Check failed", return ) #endif -// DCHECK_IS_ON() && defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) +// defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) && !defined(NDEBUG) // As above, but for CHECK(). #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) @@ -64,44 +65,4 @@ #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) -namespace base { - -class FilePath; - -struct TestIdentifier { - TestIdentifier(); - TestIdentifier(const TestIdentifier& other); - - std::string test_case_name; - std::string test_name; - std::string file; - int line; -}; - -// Constructs a full test name given a test case name and a test name, -// e.g. for test case "A" and test name "B" returns "A.B". -std::string FormatFullTestName(const std::string& test_case_name, - const std::string& test_name); - -// Returns the full test name with the "DISABLED_" prefix stripped out. -// e.g. for the full test names "A.DISABLED_B", "DISABLED_A.B", and -// "DISABLED_A.DISABLED_B", returns "A.B". -std::string TestNameWithoutDisabledPrefix(const std::string& full_test_name); - -// Returns a vector of gtest-based tests compiled into -// current executable. -std::vector GetCompiledInTests(); - -// Writes the list of gtest-based tests compiled into -// current executable as a JSON file. Returns true on success. -bool WriteCompiledInTestsToFile(const FilePath& path) WARN_UNUSED_RESULT; - -// Reads the list of gtest-based tests from |path| into |output|. -// Returns true on success. -bool ReadTestNamesFromFile(const FilePath& path, - std::vector* output) - WARN_UNUSED_RESULT; - -} // namespace base - #endif // BASE_TEST_GTEST_UTIL_H_ diff --git a/engine/src/flutter/third_party/accessibility/base/win/atl.h b/engine/src/flutter/third_party/accessibility/base/win/atl.h index 464438ed11..3d9ae058d2 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/atl.h +++ b/engine/src/flutter/third_party/accessibility/base/win/atl.h @@ -5,11 +5,6 @@ #ifndef BASE_WIN_ATL_H_ #define BASE_WIN_ATL_H_ -// Check no prior poisonous defines were made. -#include "base/win/windows_defines.inc" -// Undefine before windows header will make the poisonous defines -#include "base/win/windows_undefines.inc" - // atlwin.h relies on std::void_t, but libc++ doesn't define it unless // _LIBCPP_STD_VER > 14. Workaround this by manually defining it. #include @@ -20,9 +15,6 @@ using void_t = void; } #endif -// Declare our own exception thrower (atl_throw.h includes atldef.h). -#include "base/win/atl_throw.h" - #include #include #include @@ -30,9 +22,4 @@ using void_t = void; #include #include -// Undefine the poisonous defines -#include "base/win/windows_undefines.inc" -// Check no poisonous defines follow this include -#include "base/win/windows_defines.inc" - #endif // BASE_WIN_ATL_H_ diff --git a/engine/src/flutter/third_party/accessibility/base/win/enum_variant.cc b/engine/src/flutter/third_party/accessibility/base/win/enum_variant.cc index 654cfc67c1..112774743b 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/enum_variant.cc +++ b/engine/src/flutter/third_party/accessibility/base/win/enum_variant.cc @@ -8,7 +8,7 @@ #include -#include "base/check_op.h" +#include "base/logging.h" namespace base { namespace win { @@ -21,7 +21,7 @@ EnumVariant::EnumVariant(ULONG count) : current_index_(0) { EnumVariant::~EnumVariant() = default; VARIANT* EnumVariant::ItemAt(ULONG index) { - DCHECK_LT(index, items_.size()); + BASE_DCHECK(index < items_.size()); // This is a hack to return a mutable pointer to the ScopedVariant, even // though the original intent of the AsInput method was to allow only readonly // access to the wrapped variant. @@ -34,8 +34,8 @@ HRESULT EnumVariant::Next(ULONG requested_count, if (!out_elements) return E_INVALIDARG; - DCHECK_LE(current_index_, items_.size()); - ULONG available_count = ULONG{items_.size()} - current_index_; + BASE_DCHECK(current_index_ <= items_.size()); + ULONG available_count = static_cast(items_.size()) - current_index_; ULONG count = std::min(requested_count, available_count); for (ULONG i = 0; i < count; ++i) out_elements[i] = items_[current_index_ + i].Copy(); @@ -51,8 +51,8 @@ HRESULT EnumVariant::Next(ULONG requested_count, HRESULT EnumVariant::Skip(ULONG skip_count) { ULONG count = skip_count; - if (current_index_ + count > ULONG{items_.size()}) - count = ULONG{items_.size()} - current_index_; + if (current_index_ + count > static_cast(items_.size())) + count = static_cast(items_.size()) - current_index_; current_index_ += count; return (count == skip_count ? S_OK : S_FALSE); @@ -69,7 +69,7 @@ HRESULT EnumVariant::Clone(IEnumVARIANT** out_cloned_object) { size_t count = items_.size(); Microsoft::WRL::ComPtr other = - Microsoft::WRL::Make(ULONG{count}); + Microsoft::WRL::Make(static_cast(count)); for (size_t i = 0; i < count; ++i) other->items_[i] = static_cast(items_[i]); diff --git a/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr.cc b/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr.cc index 6f8297400d..8b269a37d8 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr.cc +++ b/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr.cc @@ -6,36 +6,32 @@ #include -#include "base/check.h" +#include "base/logging.h" #include "base/numerics/safe_conversions.h" -#include "base/process/memory.h" -#include "base/strings/string_util.h" namespace base { namespace win { namespace { -BSTR AllocBstrOrDie(WStringPiece non_bstr) { +BSTR AllocBstrOrDie(std::wstring_view non_bstr) { BSTR result = ::SysAllocStringLen(non_bstr.data(), checked_cast(non_bstr.length())); - if (!result) { - base::TerminateBecauseOutOfMemory((non_bstr.length() + 1) * - sizeof(wchar_t)); - } + if (!result) + std::abort(); return result; } BSTR AllocBstrBytesOrDie(size_t bytes) { BSTR result = ::SysAllocStringByteLen(nullptr, checked_cast(bytes)); if (!result) - base::TerminateBecauseOutOfMemory(bytes + sizeof(wchar_t)); + std::abort(); return result; } } // namespace -ScopedBstr::ScopedBstr(WStringPiece non_bstr) +ScopedBstr::ScopedBstr(std::wstring_view non_bstr) : bstr_(AllocBstrOrDie(non_bstr)) {} ScopedBstr::~ScopedBstr() { @@ -64,11 +60,11 @@ void ScopedBstr::Swap(ScopedBstr& bstr2) { } BSTR* ScopedBstr::Receive() { - DCHECK(!bstr_) << "BSTR leak."; + BASE_DCHECK(!bstr_) << "BSTR leak."; return &bstr_; } -BSTR ScopedBstr::Allocate(WStringPiece str) { +BSTR ScopedBstr::Allocate(std::wstring_view str) { Reset(AllocBstrOrDie(str)); return bstr_; } @@ -79,7 +75,7 @@ BSTR ScopedBstr::AllocateBytes(size_t bytes) { } void ScopedBstr::SetByteLen(size_t bytes) { - DCHECK(bstr_); + BASE_DCHECK(bstr_); uint32_t* data = reinterpret_cast(bstr_); data[-1] = checked_cast(bytes); } diff --git a/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr.h b/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr.h index 9dbe3b2d52..8ba7eba83e 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr.h +++ b/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr.h @@ -11,9 +11,7 @@ #include #include "base/base_export.h" -#include "base/check.h" -#include "base/macros.h" -#include "base/strings/string_piece.h" +#include "base/logging.h" namespace base { namespace win { @@ -28,7 +26,7 @@ class BASE_EXPORT ScopedBstr { // // NOTE: Do not pass a BSTR to this constructor expecting ownership to // be transferred - even though it compiles! ;-) - explicit ScopedBstr(WStringPiece non_bstr); + explicit ScopedBstr(std::wstring_view non_bstr); ~ScopedBstr(); BSTR Get() const { return bstr_; } @@ -46,7 +44,7 @@ class BASE_EXPORT ScopedBstr { // ScopedBstr instance, call |reset| instead. // // Returns a pointer to the new BSTR. - BSTR Allocate(WStringPiece str); + BSTR Allocate(std::wstring_view str); // Allocates a new BSTR with the specified number of bytes. // Returns a pointer to the new BSTR. @@ -89,7 +87,7 @@ class BASE_EXPORT ScopedBstr { BSTR bstr_ = nullptr; private: - DISALLOW_COPY_AND_ASSIGN(ScopedBstr); + BASE_DISALLOW_COPY_AND_ASSIGN(ScopedBstr); }; } // namespace win diff --git a/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr_unittest.cc b/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr_unittest.cc index 6055b40883..8d89206ee0 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/base/win/scoped_bstr_unittest.cc @@ -6,8 +6,7 @@ #include -#include "base/stl_util.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "gtest/gtest.h" namespace base { namespace win { @@ -16,8 +15,8 @@ namespace { constexpr wchar_t kTestString1[] = L"123"; constexpr wchar_t kTestString2[] = L"456789"; -constexpr size_t test1_len = size(kTestString1) - 1; -constexpr size_t test2_len = size(kTestString2) - 1; +constexpr size_t test1_len = std::size(kTestString1) - 1; +constexpr size_t test2_len = std::size(kTestString2) - 1; } // namespace diff --git a/engine/src/flutter/third_party/accessibility/base/win/scoped_safearray.h b/engine/src/flutter/third_party/accessibility/base/win/scoped_safearray.h index 1233753ab4..64e3fdc7e9 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/scoped_safearray.h +++ b/engine/src/flutter/third_party/accessibility/base/win/scoped_safearray.h @@ -6,11 +6,11 @@ #define BASE_WIN_SCOPED_SAFEARRAY_H_ #include +#include #include "base/base_export.h" -#include "base/check_op.h" +#include "base/logging.h" #include "base/macros.h" -#include "base/optional.h" #include "base/win/variant_util.h" namespace base { @@ -53,7 +53,7 @@ class BASE_EXPORT ScopedSafearray { array_size_(std::exchange(other.array_size_, 0U)) {} LockScope& operator=(LockScope&& other) { - DCHECK_NE(this, &other); + BASE_DCHECK(this != &other); Reset(); safearray_ = std::exchange(other.safearray_, nullptr); vartype_ = std::exchange(other.vartype_, VT_EMPTY); @@ -80,8 +80,8 @@ class BASE_EXPORT ScopedSafearray { const_reference operator[](int index) const { return at(index); } reference at(size_t index) { - DCHECK_NE(array_, nullptr); - DCHECK_LT(index, array_size_); + BASE_DCHECK(array_ != nullptr); + BASE_DCHECK(index < array_size_); return array_[index]; } const_reference at(size_t index) const { @@ -113,7 +113,7 @@ class BASE_EXPORT ScopedSafearray { size_t array_size_; friend class ScopedSafearray; - DISALLOW_COPY_AND_ASSIGN(LockScope); + BASE_DISALLOW_COPY_AND_ASSIGN(LockScope); }; explicit ScopedSafearray(SAFEARRAY* safearray = nullptr) @@ -135,21 +135,21 @@ class BASE_EXPORT ScopedSafearray { // Creates a LockScope for accessing the contents of a // single-dimensional SAFEARRAYs. template - base::Optional> CreateLockScope() const { + std::optional> CreateLockScope() const { if (!safearray_ || SafeArrayGetDim(safearray_) != 1) - return base::nullopt; + return std::nullopt; VARTYPE vartype; HRESULT hr = SafeArrayGetVartype(safearray_, &vartype); if (FAILED(hr) || !internal::VariantUtil::IsConvertibleTo(vartype)) { - return base::nullopt; + return std::nullopt; } typename LockScope::pointer array = nullptr; hr = SafeArrayAccessData(safearray_, reinterpret_cast(&array)); if (FAILED(hr)) - return base::nullopt; + return std::nullopt; const size_t array_size = GetCount(); return LockScope(safearray_, vartype, array, array_size); @@ -158,7 +158,7 @@ class BASE_EXPORT ScopedSafearray { void Destroy() { if (safearray_) { HRESULT hr = SafeArrayDestroy(safearray_); - DCHECK_EQ(S_OK, hr); + BASE_DCHECK(S_OK == hr); safearray_ = nullptr; } } @@ -191,17 +191,17 @@ class BASE_EXPORT ScopedSafearray { // Returns the number of elements in a dimension of the array. size_t GetCount(UINT dimension = 0) const { - DCHECK(safearray_); + BASE_DCHECK(safearray_); // Initialize |lower| and |upper| so this method will return zero if either // SafeArrayGetLBound or SafeArrayGetUBound returns failure because they // only write to the output parameter when successful. LONG lower = 0; LONG upper = -1; - DCHECK_LT(dimension, SafeArrayGetDim(safearray_)); + BASE_DCHECK(dimension < SafeArrayGetDim(safearray_)); HRESULT hr = SafeArrayGetLBound(safearray_, dimension + 1, &lower); - DCHECK(SUCCEEDED(hr)); + BASE_DCHECK(SUCCEEDED(hr)); hr = SafeArrayGetUBound(safearray_, dimension + 1, &upper); - DCHECK(SUCCEEDED(hr)); + BASE_DCHECK(SUCCEEDED(hr)); return (upper - lower + 1); } @@ -215,7 +215,7 @@ class BASE_EXPORT ScopedSafearray { private: SAFEARRAY* safearray_; - DISALLOW_COPY_AND_ASSIGN(ScopedSafearray); + BASE_DISALLOW_COPY_AND_ASSIGN(ScopedSafearray); }; } // namespace win diff --git a/engine/src/flutter/third_party/accessibility/base/win/scoped_safearray_unittest.cc b/engine/src/flutter/third_party/accessibility/base/win/scoped_safearray_unittest.cc index 006664feaa..1c550b22cd 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/scoped_safearray_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/base/win/scoped_safearray_unittest.cc @@ -3,15 +3,14 @@ // found in the LICENSE file. #include "base/win/scoped_safearray.h" +#include "base/test/gtest_util.h" #include #include #include -#include "base/stl_util.h" -#include "base/test/gtest_util.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "gtest/gtest.h" namespace base { namespace win { @@ -169,7 +168,7 @@ TEST(ScopedSafearrayTest, ScopedSafearrayGetCount) { TEST(ScopedSafearrayTest, ScopedSafearrayInitialLockScope) { ScopedSafearray scoped_safe_array; - base::Optional> lock_scope = + std::optional> lock_scope = scoped_safe_array.CreateLockScope(); EXPECT_FALSE(lock_scope.has_value()); } @@ -178,7 +177,7 @@ TEST(ScopedSafearrayTest, ScopedSafearrayLockScopeMoveConstructor) { ScopedSafearray scoped_safe_array; PopulateScopedSafearrayOfInts(scoped_safe_array); - base::Optional> first = + std::optional> first = scoped_safe_array.CreateLockScope(); ASSERT_TRUE(first.has_value()); EXPECT_EQ(first->Type(), VT_I4); @@ -195,7 +194,7 @@ TEST(ScopedSafearrayTest, ScopedSafearrayLockScopeMoveAssignOperator) { ScopedSafearray scoped_safe_array; PopulateScopedSafearrayOfInts(scoped_safe_array); - base::Optional> first = + std::optional> first = scoped_safe_array.CreateLockScope(); ASSERT_TRUE(first.has_value()); EXPECT_EQ(first->Type(), VT_I4); @@ -218,13 +217,13 @@ TEST(ScopedSafearrayTest, ScopedSafearrayLockScopeTypeMismatch) { PopulateScopedSafearrayOfInts(scoped_safe_array); { - base::Optional> invalid_lock_scope = + std::optional> invalid_lock_scope = scoped_safe_array.CreateLockScope(); EXPECT_FALSE(invalid_lock_scope.has_value()); } { - base::Optional> invalid_lock_scope = + std::optional> invalid_lock_scope = scoped_safe_array.CreateLockScope(); EXPECT_FALSE(invalid_lock_scope.has_value()); } @@ -234,7 +233,7 @@ TEST(ScopedSafearrayTest, ScopedSafearrayLockScopeRandomAccess) { ScopedSafearray scoped_safe_array; PopulateScopedSafearrayOfInts(scoped_safe_array); - base::Optional> lock_scope = + std::optional> lock_scope = scoped_safe_array.CreateLockScope(); ASSERT_TRUE(lock_scope.has_value()); EXPECT_EQ(lock_scope->Type(), VT_I4); @@ -249,7 +248,7 @@ TEST(ScopedSafearrayTest, ScopedSafearrayLockScopeIterator) { ScopedSafearray scoped_safe_array; PopulateScopedSafearrayOfInts(scoped_safe_array); - base::Optional> lock_scope = + std::optional> lock_scope = scoped_safe_array.CreateLockScope(); std::vector unpacked_vector(lock_scope->begin(), lock_scope->end()); diff --git a/engine/src/flutter/third_party/accessibility/base/win/scoped_variant.cc b/engine/src/flutter/third_party/accessibility/base/win/scoped_variant.cc index 352c22b300..a3f4da9d45 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/scoped_variant.cc +++ b/engine/src/flutter/third_party/accessibility/base/win/scoped_variant.cc @@ -4,15 +4,14 @@ #include "base/win/scoped_variant.h" +#include #include #include #include -#include "base/check.h" #include "base/logging.h" #include "base/numerics/ranges.h" -#include "base/win/propvarutil.h" #include "base/win/variant_util.h" namespace base { @@ -57,7 +56,7 @@ ScopedVariant::ScopedVariant(bool value) { } ScopedVariant::ScopedVariant(double value, VARTYPE vt) { - DCHECK(vt == VT_R8 || vt == VT_DATE); + BASE_DCHECK(vt == VT_R8 || vt == VT_DATE); var_.vt = vt; var_.dblVal = value; } @@ -102,7 +101,7 @@ void ScopedVariant::Swap(ScopedVariant& var) { } VARIANT* ScopedVariant::Receive() { - DCHECK(!IsLeakableVarType(var_.vt)) << "variant leak. type: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "variant leak. type: " << var_.vt; return &var_; } @@ -113,9 +112,9 @@ VARIANT ScopedVariant::Copy() const { } int ScopedVariant::Compare(const VARIANT& other, bool ignore_case) const { - DCHECK(!V_ISARRAY(&var_)) + BASE_DCHECK(!V_ISARRAY(&var_)) << "Comparison is not supported when |this| owns a SAFEARRAY"; - DCHECK(!V_ISARRAY(&other)) + BASE_DCHECK(!V_ISARRAY(&other)) << "Comparison is not supported when |other| owns a SAFEARRAY"; const bool this_is_empty = var_.vt == VT_EMPTY || var_.vt == VT_NULL; @@ -160,7 +159,7 @@ int ScopedVariant::Compare(const VARIANT& other, bool ignore_case) const { ULONG flags = ignore_case ? NORM_IGNORECASE : 0; HRESULT hr = ::VarBstrCmp(V_BSTR(&var_), V_BSTR(&other), LOCALE_USER_DEFAULT, flags); - DCHECK(SUCCEEDED(hr) && hr != VARCMP_NULL) + BASE_DCHECK(SUCCEEDED(hr) && hr != VARCMP_NULL) << "unsupported variant comparison: " << var_.vt << " and " << other.vt; switch (hr) { @@ -180,79 +179,79 @@ int ScopedVariant::Compare(const VARIANT& other, bool ignore_case) const { } void ScopedVariant::Set(const wchar_t* str) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_BSTR; var_.bstrVal = ::SysAllocString(str); } void ScopedVariant::Set(int8_t i8) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_I1; var_.cVal = i8; } void ScopedVariant::Set(uint8_t ui8) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_UI1; var_.bVal = ui8; } void ScopedVariant::Set(int16_t i16) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_I2; var_.iVal = i16; } void ScopedVariant::Set(uint16_t ui16) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_UI2; var_.uiVal = ui16; } void ScopedVariant::Set(int32_t i32) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_I4; var_.lVal = i32; } void ScopedVariant::Set(uint32_t ui32) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_UI4; var_.ulVal = ui32; } void ScopedVariant::Set(int64_t i64) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_I8; var_.llVal = i64; } void ScopedVariant::Set(uint64_t ui64) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_UI8; var_.ullVal = ui64; } void ScopedVariant::Set(float r32) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_R4; var_.fltVal = r32; } void ScopedVariant::Set(double r64) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_R8; var_.dblVal = r64; } void ScopedVariant::SetDate(DATE date) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_DATE; var_.date = date; } void ScopedVariant::Set(IDispatch* disp) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_DISPATCH; var_.pdispVal = disp; if (disp) @@ -260,13 +259,13 @@ void ScopedVariant::Set(IDispatch* disp) { } void ScopedVariant::Set(bool b) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_BOOL; var_.boolVal = b ? VARIANT_TRUE : VARIANT_FALSE; } void ScopedVariant::Set(IUnknown* unk) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; var_.vt = VT_UNKNOWN; var_.punkVal = unk; if (unk) @@ -274,20 +273,20 @@ void ScopedVariant::Set(IUnknown* unk) { } void ScopedVariant::Set(SAFEARRAY* array) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; if (SUCCEEDED(::SafeArrayGetVartype(array, &var_.vt))) { var_.vt |= VT_ARRAY; var_.parray = array; } else { - DCHECK(!array) << "Unable to determine safearray vartype"; + BASE_DCHECK(!array) << "Unable to determine safearray vartype"; var_.vt = VT_EMPTY; } } void ScopedVariant::Set(const VARIANT& var) { - DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; + BASE_DCHECK(!IsLeakableVarType(var_.vt)) << "leaking variant: " << var_.vt; if (FAILED(::VariantCopy(&var_, &var))) { - DLOG(ERROR) << "VariantCopy failed"; + BASE_DLOG() << "Error: VariantCopy failed"; var_.vt = VT_EMPTY; } } diff --git a/engine/src/flutter/third_party/accessibility/base/win/scoped_variant.h b/engine/src/flutter/third_party/accessibility/base/win/scoped_variant.h index a43e7f4a05..91c2eb07bd 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/scoped_variant.h +++ b/engine/src/flutter/third_party/accessibility/base/win/scoped_variant.h @@ -179,7 +179,7 @@ class BASE_EXPORT ScopedVariant { // Use the Compare method instead. bool operator==(const ScopedVariant& var) const; bool operator!=(const ScopedVariant& var) const; - DISALLOW_COPY_AND_ASSIGN(ScopedVariant); + BASE_DISALLOW_COPY_AND_ASSIGN(ScopedVariant); }; } // namespace win diff --git a/engine/src/flutter/third_party/accessibility/base/win/scoped_variant_unittest.cc b/engine/src/flutter/third_party/accessibility/base/win/scoped_variant_unittest.cc index 437efc2298..cc90bf68a2 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/scoped_variant_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/base/win/scoped_variant_unittest.cc @@ -10,7 +10,7 @@ #include "base/win/dispatch_stub.h" #include "base/win/scoped_variant.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "gtest/gtest.h" using base::win::test::DispatchStub; diff --git a/engine/src/flutter/third_party/accessibility/base/win/variant_util.h b/engine/src/flutter/third_party/accessibility/base/win/variant_util.h index 24f60e58c6..63b04e3c33 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/variant_util.h +++ b/engine/src/flutter/third_party/accessibility/base/win/variant_util.h @@ -132,14 +132,14 @@ struct VariantUtil final { // of managed contents. // e.g. Does not affect IUnknown* reference counts or allocate a BSTR. static Type RawGet(const VARIANT& var) { - DCHECK(IsConvertibleFrom(V_VT(&var))); + BASE_DCHECK(IsConvertibleFrom(V_VT(&var))); return var.*VartypeToNativeType::kMemberOffset; } // Set the associated VARIANT union member value. // The caller is responsible for handling the lifetime of managed contents. // e.g. Incrementing IUnknown* reference counts or allocating a BSTR. static void RawSet(VARIANT* var, Type value) { - DCHECK(IsConvertibleTo(V_VT(var))); + BASE_DCHECK(IsConvertibleTo(V_VT(var))); var->*VartypeToNativeType::kMemberOffset = value; } }; diff --git a/engine/src/flutter/third_party/accessibility/base/win/variant_vector.cc b/engine/src/flutter/third_party/accessibility/base/win/variant_vector.cc index 7dc547a1fc..22a28e0e1c 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/variant_vector.cc +++ b/engine/src/flutter/third_party/accessibility/base/win/variant_vector.cc @@ -4,10 +4,6 @@ #include "base/win/variant_vector.h" -#include "base/check_op.h" -#include "base/notreached.h" -#include "base/optional.h" -#include "base/process/memory.h" #include "base/win/scoped_safearray.h" #include "base/win/scoped_variant.h" @@ -21,7 +17,7 @@ template int CompareAgainstSafearray(const std::vector& vector, const ScopedSafearray& safearray, bool ignore_case) { - base::Optional> lock_scope = + std::optional> lock_scope = safearray.CreateLockScope(); // If we fail to create a lock scope, then arbitrarily treat |this| as // greater. This should only happen when the SAFEARRAY fails to be locked, @@ -65,7 +61,7 @@ VariantVector::VariantVector(VariantVector&& other) vector_(std::move(other.vector_)) {} VariantVector& VariantVector::operator=(VariantVector&& other) { - DCHECK_NE(this, &other); + BASE_DCHECK(this != &other); vartype_ = std::exchange(other.vartype_, VT_EMPTY); vector_ = std::move(other.vector_); return *this; @@ -92,7 +88,7 @@ VARIANT VariantVector::ReleaseAsScalarVariant() { ScopedVariant scoped_variant; if (!Empty()) { - DCHECK_EQ(Size(), 1U); + BASE_DCHECK(Size() == 1U); scoped_variant = std::move(vector_[0]); Reset(); } @@ -163,7 +159,7 @@ VARIANT VariantVector::ReleaseAsSafearrayVariant() { // VARTYPES. For example a value within VT_TYPEMASK that's joined something // outside the typemask like VT_ARRAY or VT_BYREF. default: - NOTREACHED(); + BASE_UNREACHABLE(); break; } @@ -306,7 +302,7 @@ int VariantVector::Compare(SAFEARRAY* safearray, bool ignore_case) const { // VARTYPES. For example a value within VT_TYPEMASK that's joined something // outside the typemask like VT_ARRAY or VT_BYREF. default: - NOTREACHED(); + BASE_UNREACHABLE(); compare_result = 1; break; } @@ -317,20 +313,19 @@ int VariantVector::Compare(SAFEARRAY* safearray, bool ignore_case) const { template SAFEARRAY* VariantVector::CreateAndPopulateSafearray() { - DCHECK(!Empty()); + BASE_DCHECK(!Empty()); ScopedSafearray scoped_safearray( SafeArrayCreateVector(ElementVartype, 0, Size())); if (!scoped_safearray.Get()) { constexpr size_t kElementSize = sizeof(typename internal::VariantUtil::Type); - base::TerminateBecauseOutOfMemory(sizeof(SAFEARRAY) + - (Size() * kElementSize)); + std::abort(); } - base::Optional> lock_scope = + std::optional> lock_scope = scoped_safearray.CreateLockScope(); - DCHECK(lock_scope); + BASE_DCHECK(lock_scope); for (size_t i = 0; i < Size(); ++i) { VARIANT element = vector_[i].Release(); diff --git a/engine/src/flutter/third_party/accessibility/base/win/variant_vector.h b/engine/src/flutter/third_party/accessibility/base/win/variant_vector.h index a65e39d2cc..1f75aa4d6b 100644 --- a/engine/src/flutter/third_party/accessibility/base/win/variant_vector.h +++ b/engine/src/flutter/third_party/accessibility/base/win/variant_vector.h @@ -13,9 +13,7 @@ #include #include "base/base_export.h" -#include "base/check.h" #include "base/logging.h" -#include "base/no_destructor.h" #include "base/win/scoped_variant.h" #include "base/win/variant_util.h" @@ -119,7 +117,8 @@ class BASE_EXPORT VariantVector final { // for inserting into |vector_|. template void AssertVartype() const { - DCHECK(internal::VariantUtil::IsConvertibleTo(vartype_)) + BASE_DCHECK( + internal::VariantUtil::IsConvertibleTo(vartype_)) << "Type mismatch, " << ExpectedVartype << " is not convertible to " << Type(); } diff --git a/engine/src/flutter/third_party/accessibility/gfx/BUILD.gn b/engine/src/flutter/third_party/accessibility/gfx/BUILD.gn index df88fecef6..cf50601c3c 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/BUILD.gn +++ b/engine/src/flutter/third_party/accessibility/gfx/BUILD.gn @@ -39,6 +39,9 @@ source_set("gfx") { "geometry/vector2d_f.h", "gfx_export.h", "native_widget_types.h", + "range/gfx_range_export.h", + "range/range.cc", + "range/range.h", "transform.cc", "transform.h", ] diff --git a/engine/src/flutter/third_party/accessibility/gfx/range/range.cc b/engine/src/flutter/third_party/accessibility/gfx/range/range.cc index 2776f3d75e..82b8c17c78 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/range/range.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/range/range.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/gfx/range/range.h" +#include "range.h" #include #include -#include "base/strings/stringprintf.h" +#include "base/string_utils.h" namespace gfx { diff --git a/engine/src/flutter/third_party/accessibility/gfx/range/range.h b/engine/src/flutter/third_party/accessibility/gfx/range/range.h index ce3b64af7b..ed30494123 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/range/range.h +++ b/engine/src/flutter/third_party/accessibility/gfx/range/range.h @@ -8,12 +8,13 @@ #include #include +#include #include #include #include -#include "build/build_config.h" -#include "ui/gfx/range/gfx_range_export.h" +#include "ax_build/build_config.h" +#include "gfx_range_export.h" #if defined(OS_APPLE) #if __OBJC__ diff --git a/engine/src/flutter/third_party/accessibility/gfx/range/range_unittest.cc b/engine/src/flutter/third_party/accessibility/gfx/range/range_unittest.cc index cd75974f0d..466bea427e 100644 --- a/engine/src/flutter/third_party/accessibility/gfx/range/range_unittest.cc +++ b/engine/src/flutter/third_party/accessibility/gfx/range/range_unittest.cc @@ -4,16 +4,15 @@ #include -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/gfx/range/range.h" -#include "ui/gfx/range/range_f.h" +#include "gtest/gtest.h" +#include "range.h" namespace { template class RangeTest : public testing::Test {}; -typedef testing::Types RangeTypes; +typedef testing::Types RangeTypes; TYPED_TEST_SUITE(RangeTest, RangeTypes); template @@ -278,63 +277,6 @@ TEST(RangeTest, RangeOperations) { } } -TEST(RangeTest, RangeFOperations) { - constexpr gfx::RangeF invalid_range = gfx::RangeF::InvalidRange(); - constexpr gfx::RangeF ranges[] = {{0.f, 0.f}, {0.f, 1.f}, {0.f, 2.f}, - {1.f, 0.f}, {1.f, 1.f}, {1.f, 2.f}, - {2.f, 0.f}, {2.f, 1.f}, {2.f, 2.f}}; - - // Ensures valid behavior over same range. - for (const auto& range : ranges) { - SCOPED_TRACE(range.ToString()); - // A range should contain itself. - EXPECT_TRUE(range.Contains(range)); - // A ranges should intersect with itself. - EXPECT_TRUE(range.Intersects(range)); - } - - // Ensures valid behavior with an invalid range. - for (const auto& range : ranges) { - SCOPED_TRACE(range.ToString()); - EXPECT_FALSE(invalid_range.Contains(range)); - EXPECT_FALSE(invalid_range.Intersects(range)); - EXPECT_FALSE(range.Contains(invalid_range)); - EXPECT_FALSE(range.Intersects(invalid_range)); - } - EXPECT_FALSE(invalid_range.Contains(invalid_range)); - EXPECT_FALSE(invalid_range.Intersects(invalid_range)); - - // Ensures consistent operations between Contains(...) and Intersects(...). - for (const auto& range1 : ranges) { - for (const auto& range2 : ranges) { - SCOPED_TRACE(testing::Message() - << "range1=" << range1 << " range2=" << range2); - if (range1.Contains(range2)) { - EXPECT_TRUE(range1.Intersects(range2)); - EXPECT_EQ(range2.Contains(range1), - range1.EqualsIgnoringDirection(range2)); - } - EXPECT_EQ(range2.Intersects(range1), range1.Intersects(range2)); - - EXPECT_EQ(range1.Intersect(range2) != invalid_range, - range1.Intersects(range2)); - } - } - - // Ranges should behave the same way no matter the direction. - for (const auto& range1 : ranges) { - for (const auto& range2 : ranges) { - SCOPED_TRACE(testing::Message() - << "range1=" << range1 << " range2=" << range2); - EXPECT_EQ(range1.Contains(range2), - range1.Contains(gfx::RangeF(range2.GetMax(), range2.GetMin()))); - EXPECT_EQ( - range1.Intersects(range2), - range1.Intersects(gfx::RangeF(range2.GetMax(), range2.GetMin()))); - } - } -} - TEST(RangeTest, ContainsAndIntersects) { constexpr gfx::Range r1(0, 0); constexpr gfx::Range r2(0, 1); @@ -397,68 +339,6 @@ TEST(RangeTest, ContainsAndIntersects) { EXPECT_TRUE(r8.Intersects(r8)); } -TEST(RangeTest, ContainsAndIntersectsRangeF) { - constexpr gfx::RangeF r1(0.f, 0.f); - constexpr gfx::RangeF r2(0.f, 1.f); - constexpr gfx::RangeF r3(1.f, 2.f); - constexpr gfx::RangeF r4(1.f, 0.f); - constexpr gfx::RangeF r5(2.f, 1.f); - constexpr gfx::RangeF r6(0.f, 2.f); - constexpr gfx::RangeF r7(2.f, 0.f); - constexpr gfx::RangeF r8(1.f, 1.f); - - // Ensures Contains(...) handle the open range. - EXPECT_TRUE(r2.Contains(r1)); - EXPECT_TRUE(r4.Contains(r1)); - EXPECT_TRUE(r3.Contains(r5)); - EXPECT_TRUE(r5.Contains(r3)); - - // Ensures larger ranges contains smaller ranges. - EXPECT_TRUE(r6.Contains(r1)); - EXPECT_TRUE(r6.Contains(r2)); - EXPECT_TRUE(r6.Contains(r3)); - EXPECT_TRUE(r6.Contains(r4)); - EXPECT_TRUE(r6.Contains(r5)); - - EXPECT_TRUE(r7.Contains(r1)); - EXPECT_TRUE(r7.Contains(r2)); - EXPECT_TRUE(r7.Contains(r3)); - EXPECT_TRUE(r7.Contains(r4)); - EXPECT_TRUE(r7.Contains(r5)); - - // Ensures Intersects(...) handle the open range. - EXPECT_TRUE(r2.Intersects(r1)); - EXPECT_TRUE(r4.Intersects(r1)); - - // Ensures larger ranges intersects smaller ranges. - EXPECT_TRUE(r6.Intersects(r1)); - EXPECT_TRUE(r6.Intersects(r2)); - EXPECT_TRUE(r6.Intersects(r3)); - EXPECT_TRUE(r6.Intersects(r4)); - EXPECT_TRUE(r6.Intersects(r5)); - - EXPECT_TRUE(r7.Intersects(r1)); - EXPECT_TRUE(r7.Intersects(r2)); - EXPECT_TRUE(r7.Intersects(r3)); - EXPECT_TRUE(r7.Intersects(r4)); - EXPECT_TRUE(r7.Intersects(r5)); - - // Ensures adjacent ranges don't overlap. - EXPECT_FALSE(r2.Intersects(r3)); - EXPECT_FALSE(r5.Intersects(r4)); - - // Ensures empty ranges are handled correctly. - EXPECT_FALSE(r1.Contains(r8)); - EXPECT_FALSE(r2.Contains(r8)); - EXPECT_TRUE(r3.Contains(r8)); - EXPECT_TRUE(r8.Contains(r8)); - - EXPECT_FALSE(r1.Intersects(r8)); - EXPECT_FALSE(r2.Intersects(r8)); - EXPECT_TRUE(r3.Intersects(r8)); - EXPECT_TRUE(r8.Intersects(r8)); -} - TEST(RangeTest, Intersect) { EXPECT_EQ(gfx::Range(0, 1).Intersect({0, 1}), gfx::Range(0, 1)); EXPECT_EQ(gfx::Range(0, 1).Intersect({0, 0}), gfx::Range(0, 0)); @@ -474,32 +354,6 @@ TEST(RangeTest, Intersect) { EXPECT_EQ(gfx::Range(2, 1).Intersect({1, 0}), gfx::Range::InvalidRange()); } -TEST(RangeTest, IntersectRangeF) { - EXPECT_EQ(gfx::RangeF(0.f, 1.f).Intersect(gfx::RangeF(0.f, 1.f)), - gfx::RangeF(0.f, 1.f)); - EXPECT_EQ(gfx::RangeF(0.f, 1.f).Intersect(gfx::RangeF(0.f, 0.f)), - gfx::RangeF(0.f, 0.f)); - EXPECT_EQ(gfx::RangeF(0.f, 0.f).Intersect(gfx::RangeF(1.f, 0.f)), - gfx::RangeF(0.f, 0.f)); - EXPECT_EQ(gfx::RangeF(0.f, 4.f).Intersect(gfx::RangeF(2.f, 3.f)), - gfx::RangeF(2.f, 3.f)); - EXPECT_EQ(gfx::RangeF(0.f, 4.f).Intersect(gfx::RangeF(2.f, 7.f)), - gfx::RangeF(2.f, 4.f)); - EXPECT_EQ(gfx::RangeF(0.f, 4.f).Intersect(gfx::RangeF(3.f, 4.f)), - gfx::RangeF(3.f, 4.f)); - - EXPECT_EQ(gfx::RangeF(0.f, 1.f).Intersect(gfx::RangeF(1.f, 1.f)), - gfx::RangeF::InvalidRange()); - EXPECT_EQ(gfx::RangeF(1.f, 1.f).Intersect(gfx::RangeF(1.f, 0.f)), - gfx::RangeF::InvalidRange()); - EXPECT_EQ(gfx::RangeF(0.f, 1.f).Intersect(gfx::RangeF(1.f, 2.f)), - gfx::RangeF::InvalidRange()); - EXPECT_EQ(gfx::RangeF(0.f, 1.f).Intersect(gfx::RangeF(2.f, 1.f)), - gfx::RangeF::InvalidRange()); - EXPECT_EQ(gfx::RangeF(2.f, 1.f).Intersect(gfx::RangeF(1.f, 0.f)), - gfx::RangeF::InvalidRange()); -} - TEST(RangeTest, IsBoundedBy) { constexpr gfx::Range r1(0, 0); constexpr gfx::Range r2(0, 1);