Skip to content

Commit

Permalink
Migrate base::{size,empty,data} to STL equivalents in //ui.
Browse files Browse the repository at this point in the history
Bug: 1299695
Change-Id: I23fca511deab45aceaefabeb37541f7fcbe1e306
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3492696
Auto-Submit: Daniel Cheng <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Commit-Queue: Lei Zhang <[email protected]>
Owners-Override: Lei Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#975519}
  • Loading branch information
zetafunction authored and Chromium LUCI CQ committed Feb 27, 2022
1 parent 037fba6 commit f992054
Show file tree
Hide file tree
Showing 128 changed files with 614 additions and 705 deletions.
5 changes: 2 additions & 3 deletions ui/accessibility/ax_generated_tree_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <numeric>
#include <vector>

#include "base/cxx17_backports.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest-param-test.h"
Expand Down Expand Up @@ -136,7 +135,7 @@ TEST(AXGeneratedTreeTest, TestTreeGeneratorNoPermutations) {
// clang-format on

int n = generator.UniqueTreeCount();
ASSERT_EQ(static_cast<int>(base::size(EXPECTED_TREES)), n);
ASSERT_EQ(static_cast<int>(std::size(EXPECTED_TREES)), n);

for (int i = 0; i < n; ++i) {
AXTree tree;
Expand Down Expand Up @@ -208,7 +207,7 @@ TEST(AXGeneratedTreeTest, TestTreeGeneratorWithPermutations) {
// clang-format on

int n = generator.UniqueTreeCount();
ASSERT_EQ(static_cast<int>(base::size(EXPECTED_TREES)), n);
ASSERT_EQ(static_cast<int>(std::size(EXPECTED_TREES)), n);

for (int i = 0; i < n; i++) {
AXTree tree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ std::string UiaIdentifierToStringPretty(int32_t id) {
auto str = base::WideToUTF8(UiaIdentifierToString(id));
// Remove UIA_ prefix, and EventId/PropertyId suffixes
if (base::StartsWith(str, "UIA_", base::CompareCase::SENSITIVE))
str = str.substr(base::size("UIA_") - 1);
str = str.substr(std::size("UIA_") - 1);
if (base::EndsWith(str, "EventId", base::CompareCase::SENSITIVE))
str = str.substr(0, str.size() - base::size("EventId") + 1);
str = str.substr(0, str.size() - std::size("EventId") + 1);
if (base::EndsWith(str, "PropertyId", base::CompareCase::SENSITIVE))
str = str.substr(0, str.size() - base::size("PropertyId") + 1);
str = str.substr(0, str.size() - std::size("PropertyId") + 1);
return str;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <utility>
#include <vector>

#include "base/cxx17_backports.h"
#include "base/logging.h"
#include "base/strings/pattern.h"
#include "ui/accessibility/platform/inspect/ax_inspect.h"
Expand Down Expand Up @@ -109,8 +108,7 @@ const char* ATSPIStateToString(AtspiStateType state) {
#endif
};

return GetNameForPlatformConstant(state_table, base::size(state_table),
state);
return GetNameForPlatformConstant(state_table, std::size(state_table), state);
}

const char* ATSPIRoleToString(AtspiRole role) {
Expand Down Expand Up @@ -251,7 +249,7 @@ const char* ATSPIRoleToString(AtspiRole role) {
#endif
};

return GetNameForPlatformConstant(role_table, base::size(role_table), role);
return GetNameForPlatformConstant(role_table, std::size(role_table), role);
}

// This is used to ensure a standard set of AtkRole name conversions between
Expand Down
14 changes: 6 additions & 8 deletions ui/accessibility/platform/inspect/ax_inspect_utils_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <map>
#include <string>

#include "base/cxx17_backports.h"
#include "base/logging.h"
#include "base/memory/singleton.h"
#include "base/strings/pattern.h"
Expand Down Expand Up @@ -103,7 +102,7 @@ AX_EXPORT std::wstring IAccessibleRoleToString(int32_t ia_role) {
QUOTE(ROLE_SYSTEM_WHITESPACE), QUOTE(ROLE_SYSTEM_WINDOW),
};

return GetNameForPlatformConstant(ia_table, base::size(ia_table), ia_role);
return GetNameForPlatformConstant(ia_table, std::size(ia_table), ia_role);
}

AX_EXPORT std::wstring IAccessible2RoleToString(int32_t ia2_role) {
Expand Down Expand Up @@ -167,7 +166,7 @@ AX_EXPORT std::wstring IAccessible2RoleToString(int32_t ia2_role) {
QUOTE(IA2_ROLE_COMMENT),
};

return GetNameForPlatformConstant(ia2_table, base::size(ia2_table), ia2_role);
return GetNameForPlatformConstant(ia2_table, std::size(ia2_table), ia2_role);
}

AX_EXPORT std::wstring AccessibilityEventToString(int32_t event) {
Expand Down Expand Up @@ -244,8 +243,7 @@ AX_EXPORT std::wstring AccessibilityEventToString(int32_t event) {
QUOTE(IA2_EVENT_ROLE_CHANGED),
};

return GetNameForPlatformConstant(event_table, base::size(event_table),
event);
return GetNameForPlatformConstant(event_table, std::size(event_table), event);
}

void IAccessibleStateToStringVector(int32_t ia_state,
Expand Down Expand Up @@ -668,21 +666,21 @@ AX_EXPORT std::wstring UiaIdentifierToString(int32_t identifier) {
QUOTE(UIA_AppBarControlTypeId),
};

return GetNameForPlatformConstant(id_table, base::size(id_table), identifier);
return GetNameForPlatformConstant(id_table, std::size(id_table), identifier);
}

AX_EXPORT std::wstring UiaOrientationToString(int32_t identifier) {
static const PlatformConstantToNameEntry id_table[] = {
QUOTE(OrientationType_None), QUOTE(OrientationType_Horizontal),
QUOTE(OrientationType_Vertical)};
return GetNameForPlatformConstant(id_table, base::size(id_table), identifier);
return GetNameForPlatformConstant(id_table, std::size(id_table), identifier);
}

AX_EXPORT std::wstring UiaLiveSettingToString(int32_t identifier) {
static const PlatformConstantToNameEntry id_table[] = {
QUOTE(LiveSetting::Off), QUOTE(LiveSetting::Polite),
QUOTE(LiveSetting::Assertive)};
return GetNameForPlatformConstant(id_table, base::size(id_table), identifier);
return GetNameForPlatformConstant(id_table, std::size(id_table), identifier);
}

AX_EXPORT std::string BstrToUTF8(BSTR bstr) {
Expand Down
7 changes: 3 additions & 4 deletions ui/aura/cursor/cursors_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stddef.h>

#include "base/cxx17_backports.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/cursor/cursor.h"
Expand Down Expand Up @@ -273,12 +272,12 @@ const CursorData kLargeCursors[] = {
};

const CursorSizeData kCursorSizes[] = {
{ui::CursorSize::kNormal, kNormalCursors, base::size(kNormalCursors)},
{ui::CursorSize::kLarge, kLargeCursors, base::size(kLargeCursors)},
{ui::CursorSize::kNormal, kNormalCursors, std::size(kNormalCursors)},
{ui::CursorSize::kLarge, kLargeCursors, std::size(kLargeCursors)},
};

const CursorSizeData* GetCursorSizeByType(ui::CursorSize cursor_size) {
for (size_t i = 0; i < base::size(kCursorSizes); ++i) {
for (size_t i = 0; i < std::size(kCursorSizes); ++i) {
if (kCursorSizes[i].id == cursor_size)
return &kCursorSizes[i];
}
Expand Down
7 changes: 3 additions & 4 deletions ui/base/accelerators/accelerator_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "ui/base/accelerators/accelerator_manager.h"

#include "base/cxx17_backports.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
Expand Down Expand Up @@ -32,7 +31,7 @@ const int kAcceleratorModifiers[] = {EF_SHIFT_DOWN, EF_CONTROL_DOWN,
// kAcceleratorModifiers used to determine which flags are set.
int BuildAcceleratorModifier(int id) {
int result = 0;
for (size_t i = 0; i < base::size(kAcceleratorModifiers); ++i) {
for (size_t i = 0; i < std::size(kAcceleratorModifiers); ++i) {
if (((1 << i) & id) != 0)
result |= kAcceleratorModifiers[i];
}
Expand Down Expand Up @@ -130,7 +129,7 @@ TEST_F(AcceleratorManagerTest, Process) {
TestAcceleratorTarget target;

// Test all cases of possible modifiers.
for (size_t i = 0; i < (1 << base::size(kAcceleratorModifiers)); ++i) {
for (size_t i = 0; i < (1 << std::size(kAcceleratorModifiers)); ++i) {
const int modifiers = BuildAcceleratorModifier(i);
Accelerator accelerator(GetAccelerator(VKEY_A, modifiers));
manager_.Register({accelerator}, AcceleratorManager::kNormalPriority,
Expand All @@ -152,7 +151,7 @@ TEST_F(AcceleratorManagerTest, Process) {
EXPECT_FALSE(manager_.Process(GetAccelerator(VKEY_SHIFT, modifiers)))
<< i; // different vkey

for (size_t test_i = 0; test_i < (1 << base::size(kAcceleratorModifiers));
for (size_t test_i = 0; test_i < (1 << std::size(kAcceleratorModifiers));
++test_i) {
if (test_i == i)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stddef.h>

#include "base/cxx17_backports.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace ui {
Expand All @@ -24,7 +23,7 @@ TEST(MenuLabelAcceleratorTest, ConvertAcceleratorsFromWindowsStyle) {
{ "&foo &&bar", "_foo &bar" },
{ "&foo &bar", "_foo _bar" },
};
for (size_t i = 0; i < base::size(cases); ++i) {
for (size_t i = 0; i < std::size(cases); ++i) {
std::string result = ConvertAcceleratorsFromWindowsStyle(cases[i].input);
EXPECT_EQ(cases[i].output, result);
}
Expand All @@ -43,7 +42,7 @@ TEST(MenuLabelAcceleratorTest, RemoveWindowsStyleAccelerators) {
{ "&foo &&bar", "foo &bar" },
{ "&foo &bar", "foo bar" },
};
for (size_t i = 0; i < base::size(cases); ++i) {
for (size_t i = 0; i < std::size(cases); ++i) {
std::string result = RemoveWindowsStyleAccelerators(cases[i].input);
EXPECT_EQ(cases[i].output, result);
}
Expand Down
6 changes: 3 additions & 3 deletions ui/base/clipboard/clipboard_util_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include <shellapi.h>
#include <wininet.h> // For INTERNET_MAX_URL_LENGTH.
#include <wrl/client.h>

#include <algorithm>
#include <limits>
#include <utility>

#include "base/cxx17_backports.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
Expand Down Expand Up @@ -65,11 +65,11 @@ bool GetUrlFromHDrop(IDataObject* data_object,
return false;

wchar_t filename[MAX_PATH];
if (DragQueryFileW(hdrop.get(), 0, filename, base::size(filename))) {
if (DragQueryFileW(hdrop.get(), 0, filename, std::size(filename))) {
wchar_t url_buffer[INTERNET_MAX_URL_LENGTH];
if (0 == _wcsicmp(PathFindExtensionW(filename), L".url") &&
GetPrivateProfileStringW(L"InternetShortcut", L"url", 0, url_buffer,
base::size(url_buffer), filename)) {
std::size(url_buffer), filename)) {
*url = GURL(base::AsStringPiece16(url_buffer));
PathRemoveExtension(filename);
title->assign(base::as_u16cstr(PathFindFileName(filename)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <stdint.h>
#include <stdlib.h>

#include "base/cxx17_backports.h"
#include "base/files/file_path.h"
#include "base/location.h"
#import "base/mac/foundation_util.h"
Expand Down Expand Up @@ -338,7 +337,7 @@ - (void)setWindowStateForValue:(float)value {
};

CGFloat scale = 1;
for (int i = base::size(frames) - 1; i >= 0; --i) {
for (int i = std::size(frames) - 1; i >= 0; --i) {
if (value >= frames[i].value) {
CGFloat delta = frames[i + 1].value - frames[i].value;
CGFloat frame_progress = (value - frames[i].value) / delta;
Expand Down
3 changes: 1 addition & 2 deletions ui/base/dragdrop/os_exchange_data_provider_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "base/callback.h"
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/cxx17_backports.h"
#include "base/files/file_path.h"
#include "base/i18n/file_util_icu.h"
#include "base/no_destructor.h"
Expand Down Expand Up @@ -1262,7 +1261,7 @@ std::wstring CreateValidFileNameFromTitle(const GURL& url,

// Maximum length of title after truncation.
static constexpr size_t kMaxFileTitleLength =
kMaxFileNameLength - base::size(kExtension);
kMaxFileNameLength - std::size(kExtension);

if (validated.size() > kMaxFileTitleLength)
validated.erase(kMaxFileTitleLength);
Expand Down
5 changes: 2 additions & 3 deletions ui/base/ime/ash/input_method_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <unordered_set>
#include <utility>

#include "base/cxx17_backports.h"
#include "base/logging.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
Expand Down Expand Up @@ -196,7 +195,7 @@ const struct EnglishToResouceId {
{"xkb:us:workman:eng", IDS_STATUSBAR_LAYOUT_USA_WORKMAN},
};
const size_t kEnglishToResourceIdArraySize =
base::size(kEnglishToResourceIdArray);
std::size(kEnglishToResourceIdArray);

const struct InputMethodNameMap {
const char* message_name;
Expand Down Expand Up @@ -417,7 +416,7 @@ std::string InputMethodUtil::GetLocalizedDisplayName(
const std::string& disp = descriptor.name();
if (base::StartsWith(disp, "__MSG_", base::CompareCase::SENSITIVE)) {
const InputMethodNameMap* map = kInputMethodNameMap;
size_t map_size = base::size(kInputMethodNameMap);
size_t map_size = std::size(kInputMethodNameMap);
std::string name = base::ToUpperASCII(disp);
const InputMethodNameMap map_key = {name.c_str(), 0};
const InputMethodNameMap* p =
Expand Down
5 changes: 2 additions & 3 deletions ui/base/ime/ash/input_method_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <string>

#include "base/bind.h"
#include "base/cxx17_backports.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/ash/extension_ime_util.h"
Expand Down Expand Up @@ -347,8 +346,8 @@ TEST_F(InputMethodUtilTest, TestInputMethodIDMigration) {

util_.MigrateInputMethods(&input_method_ids);

EXPECT_EQ(base::size(migration_cases), input_method_ids.size());
for (size_t i = 0; i < base::size(migration_cases); ++i) {
EXPECT_EQ(std::size(migration_cases), input_method_ids.size());
for (size_t i = 0; i < std::size(migration_cases); ++i) {
EXPECT_EQ(
extension_ime_util::GetInputMethodIDByEngineID(migration_cases[i][1]),
input_method_ids[i]);
Expand Down
2 changes: 1 addition & 1 deletion ui/base/ime/character_composer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ TEST_F(CharacterComposerTest, HexadecimalComposition) {
ExpectUnicodeKeyComposed(
VKEY_RETURN, DomCode::ENTER, EF_NONE, '\r',
std::u16string(kMusicalKeyboard,
kMusicalKeyboard + base::size(kMusicalKeyboard)));
kMusicalKeyboard + std::size(kMusicalKeyboard)));
}

TEST_F(CharacterComposerTest, HexadecimalCompositionPreedit) {
Expand Down
3 changes: 1 addition & 2 deletions ui/base/ime/linux/composition_text_util_pango_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <string>
#include <utility>

#include "base/cxx17_backports.h"
#include "base/notreached.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/composition_text.h"
Expand Down Expand Up @@ -118,7 +117,7 @@ void CompareImeTextSpan(const ImeTextSpan& a, const ui::ImeTextSpan& b) {
}

TEST(CompositionTextUtilPangoTest, ExtractCompositionText) {
for (size_t i = 0; i < base::size(kTestData); ++i) {
for (size_t i = 0; i < std::size(kTestData); ++i) {
const char* text = kTestData[i].text;
const AttributeInfo* attrs = kTestData[i].attrs;
SCOPED_TRACE(testing::Message() << "Testing:" << i
Expand Down
6 changes: 2 additions & 4 deletions ui/base/ime/mojom/ime_mojom_traits_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/ime/mojom/ime_types_mojom_traits.h"

#include <utility>

#include "base/cxx17_backports.h"
#include "base/test/task_environment.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/mojom/ime_mojom_traits_test.mojom.h"
#include "ui/base/ime/mojom/ime_types_mojom_traits.h"

namespace ui {

Expand Down Expand Up @@ -68,7 +66,7 @@ TEST_F(IMEStructTraitsTest, TextInputType) {
};

mojo::Remote<mojom::IMEStructTraitsTest> remote = GetTraitsTestRemote();
for (size_t i = 0; i < base::size(kTextInputTypes); i++) {
for (size_t i = 0; i < std::size(kTextInputTypes); i++) {
ui::TextInputType type_out;
ASSERT_TRUE(remote->EchoTextInputType(kTextInputTypes[i], &type_out));
EXPECT_EQ(kTextInputTypes[i], type_out);
Expand Down
Loading

0 comments on commit f992054

Please sign in to comment.