0

Convert narrowing casts from T{} to static_cast<T>(): ui/

The style guide encourages use of T{}-style casts under the assumption
that the compiler will warn about narrowing.  This warning is currently
disabled; enabling it requires fixing up the cases that narrow.

Bug: 1216696
Change-Id: Iabb3bd3ad87dc70d06e5950071c4aa540ce81c6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2946465
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#890399}
This commit is contained in:
Peter Kasting
2021-06-08 19:46:22 +00:00
committed by Chromium LUCI CQ
parent 21abd5310a
commit 071ad44fdc
41 changed files with 189 additions and 149 deletions

@ -759,7 +759,8 @@ std::u16string AXNode::GetHypertext() const {
// Note that the word "hypertext" comes from the IAccessible2 Standard and
// has nothing to do with HTML.
const std::u16string embedded_character_str(kEmbeddedCharacter);
DCHECK_EQ(int{embedded_character_str.length()}, kEmbeddedCharacterLength);
DCHECK_EQ(static_cast<int>(embedded_character_str.length()),
kEmbeddedCharacterLength);
for (size_t i = 0; i < GetUnignoredChildCountCrossingTreeBoundary(); ++i) {
const AXNode* child = GetUnignoredChildAtIndexCrossingTreeBoundary(i);
// Similar to Firefox, we don't expose text nodes in IAccessible2 and ATK
@ -768,10 +769,10 @@ std::u16string AXNode::GetHypertext() const {
if (child->IsText()) {
hypertext_.hypertext += base::UTF8ToUTF16(child->GetInnerText());
} else {
int character_offset = int{hypertext_.hypertext.size()};
int character_offset = static_cast<int>(hypertext_.hypertext.size());
auto inserted =
hypertext_.hypertext_offset_to_hyperlink_child_index.emplace(
character_offset, int{i});
character_offset, static_cast<int>(i));
DCHECK(inserted.second) << "An embedded object at " << character_offset
<< " has already been encountered.";
hypertext_.hypertext += embedded_character_str;
@ -908,7 +909,7 @@ int AXNode::GetInnerTextLength() const {
// computing the length of their inner text if that text should be derived
// from their descendant nodes.
if (node->IsLeaf() && !is_atomic_text_field_with_descendants)
return int{node->GetInnerText().length()};
return static_cast<int>(node->GetInnerText().length());
int inner_text_length = 0;
for (auto it = node->UnignoredChildrenBegin();
@ -964,7 +965,7 @@ absl::optional<int> AXNode::GetTableColCount() const {
const AXTableInfo* table_info = GetAncestorTableInfo();
if (!table_info)
return absl::nullopt;
return int{table_info->col_count};
return static_cast<int>(table_info->col_count);
}
absl::optional<int> AXNode::GetTableRowCount() const {
@ -972,7 +973,7 @@ absl::optional<int> AXNode::GetTableRowCount() const {
const AXTableInfo* table_info = GetAncestorTableInfo();
if (!table_info)
return absl::nullopt;
return int{table_info->row_count};
return static_cast<int>(table_info->row_count);
}
absl::optional<int> AXNode::GetTableAriaColCount() const {
@ -1016,11 +1017,13 @@ AXNode* AXNode::GetTableCellFromIndex(int index) const {
return nullptr;
// There is a table but there is no cell with the given index.
if (index < 0 || size_t{index} >= table_info->unique_cell_ids.size()) {
if (index < 0 ||
static_cast<size_t>(index) >= table_info->unique_cell_ids.size()) {
return nullptr;
}
return tree_->GetFromId(table_info->unique_cell_ids[size_t{index}]);
return tree_->GetFromId(
table_info->unique_cell_ids[static_cast<size_t>(index)]);
}
AXNode* AXNode::GetTableCaption() const {
@ -1039,13 +1042,15 @@ AXNode* AXNode::GetTableCellFromCoords(int row_index, int col_index) const {
return nullptr;
// There is a table but the given coordinates are outside the table.
if (row_index < 0 || size_t{row_index} >= table_info->row_count ||
col_index < 0 || size_t{col_index} >= table_info->col_count) {
if (row_index < 0 ||
static_cast<size_t>(row_index) >= table_info->row_count ||
col_index < 0 ||
static_cast<size_t>(col_index) >= table_info->col_count) {
return nullptr;
}
return tree_->GetFromId(
table_info->cell_ids[size_t{row_index}][size_t{col_index}]);
return tree_->GetFromId(table_info->cell_ids[static_cast<size_t>(row_index)]
[static_cast<size_t>(col_index)]);
}
std::vector<AXNodeID> AXNode::GetTableColHeaderNodeIds() const {
@ -1070,10 +1075,11 @@ std::vector<AXNodeID> AXNode::GetTableColHeaderNodeIds(int col_index) const {
if (!table_info)
return std::vector<AXNodeID>();
if (col_index < 0 || size_t{col_index} >= table_info->col_count)
if (col_index < 0 || static_cast<size_t>(col_index) >= table_info->col_count)
return std::vector<AXNodeID>();
return std::vector<AXNodeID>(table_info->col_headers[size_t{col_index}]);
return std::vector<AXNodeID>(
table_info->col_headers[static_cast<size_t>(col_index)]);
}
std::vector<AXNodeID> AXNode::GetTableRowHeaderNodeIds(int row_index) const {
@ -1082,10 +1088,11 @@ std::vector<AXNodeID> AXNode::GetTableRowHeaderNodeIds(int row_index) const {
if (!table_info)
return std::vector<AXNodeID>();
if (row_index < 0 || size_t{row_index} >= table_info->row_count)
if (row_index < 0 || static_cast<size_t>(row_index) >= table_info->row_count)
return std::vector<AXNodeID>();
return std::vector<AXNodeID>(table_info->row_headers[size_t{row_index}]);
return std::vector<AXNodeID>(
table_info->row_headers[static_cast<size_t>(row_index)]);
}
std::vector<AXNodeID> AXNode::GetTableUniqueCellIds() const {
@ -1126,7 +1133,7 @@ absl::optional<int> AXNode::GetTableRowRowIndex() const {
const auto& iter = table_info->row_id_to_index.find(id());
if (iter == table_info->row_id_to_index.end())
return absl::nullopt;
return int{iter->second};
return static_cast<int>(iter->second);
}
std::vector<AXNodeID> AXNode::GetTableRowNodeIds() const {
@ -1188,7 +1195,7 @@ absl::optional<int> AXNode::GetTableCellIndex() const {
const auto& iter = table_info->cell_id_to_index.find(id());
if (iter != table_info->cell_id_to_index.end())
return int{iter->second};
return static_cast<int>(iter->second);
return absl::nullopt;
}
@ -1201,7 +1208,7 @@ absl::optional<int> AXNode::GetTableCellColIndex() const {
if (!index)
return absl::nullopt;
return int{table_info->cell_data_vector[*index].col_index};
return static_cast<int>(table_info->cell_data_vector[*index].col_index);
}
absl::optional<int> AXNode::GetTableCellRowIndex() const {
@ -1213,7 +1220,7 @@ absl::optional<int> AXNode::GetTableCellRowIndex() const {
if (!index)
return absl::nullopt;
return int{table_info->cell_data_vector[*index].row_index};
return static_cast<int>(table_info->cell_data_vector[*index].row_index);
}
absl::optional<int> AXNode::GetTableCellColSpan() const {
@ -1251,7 +1258,7 @@ absl::optional<int> AXNode::GetTableCellAriaColIndex() const {
if (!index)
return absl::nullopt;
return int{table_info->cell_data_vector[*index].aria_col_index};
return static_cast<int>(table_info->cell_data_vector[*index].aria_col_index);
}
absl::optional<int> AXNode::GetTableCellAriaRowIndex() const {
@ -1263,7 +1270,7 @@ absl::optional<int> AXNode::GetTableCellAriaRowIndex() const {
if (!index)
return absl::nullopt;
return int{table_info->cell_data_vector[*index].aria_row_index};
return static_cast<int>(table_info->cell_data_vector[*index].aria_row_index);
}
std::vector<AXNodeID> AXNode::GetTableCellColHeaderNodeIds() const {

@ -613,7 +613,8 @@ std::unique_ptr<AXTree> AXPositionTest::CreateMultilingualDocument(
std::u16string grapheme = base::WideToUTF16(kGraphemeClusters[i]);
EXPECT_EQ(1u, grapheme.length())
<< "All English characters should be one UTF16 code unit in length.";
text_offsets->push_back(text_offsets->back() + int{grapheme.length()});
text_offsets->push_back(text_offsets->back() +
static_cast<int>(grapheme.length()));
english_text.append(grapheme);
}
@ -622,7 +623,8 @@ std::unique_ptr<AXTree> AXPositionTest::CreateMultilingualDocument(
std::u16string grapheme = base::WideToUTF16(kGraphemeClusters[i]);
EXPECT_LE(2u, grapheme.length()) << "All Hindi characters should be two "
"or more UTF16 code units in length.";
text_offsets->push_back(text_offsets->back() + int{grapheme.length()});
text_offsets->push_back(text_offsets->back() +
static_cast<int>(grapheme.length()));
hindi_text.append(grapheme);
}
@ -632,7 +634,8 @@ std::unique_ptr<AXTree> AXPositionTest::CreateMultilingualDocument(
EXPECT_LT(0u, grapheme.length())
<< "One of the Thai characters should be one UTF16 code unit, "
"whilst others should be two or more.";
text_offsets->push_back(text_offsets->back() + int{grapheme.length()});
text_offsets->push_back(text_offsets->back() +
static_cast<int>(grapheme.length()));
thai_text.append(grapheme);
}

@ -348,9 +348,9 @@ class AXPosition {
const std::u16string text = GetText();
DCHECK_GE(text_offset_, 0);
const size_t max_text_offset = text.size();
DCHECK_LE(text_offset_, int{max_text_offset}) << text;
DCHECK_LE(text_offset_, static_cast<int>(max_text_offset)) << text;
std::u16string annotated_text;
if (text_offset_ == int{max_text_offset}) {
if (text_offset_ == static_cast<int>(max_text_offset)) {
annotated_text = text + u"<>";
} else {
annotated_text = text.substr(0, text_offset_) + u"<" +
@ -2340,13 +2340,14 @@ class AXPosition {
text_position->GetGraphemeIterator();
DCHECK_GE(text_position->text_offset_, 0);
DCHECK_LE(text_position->text_offset_,
int{text_position->name_.length()});
while (
!text_position->AtStartOfAnchor() &&
(!gfx::IsValidCodePointIndex(text_position->name_,
size_t{text_position->text_offset_}) ||
(grapheme_iterator && !grapheme_iterator->IsGraphemeBoundary(
size_t{text_position->text_offset_})))) {
static_cast<int>(text_position->name_.length()));
while (!text_position->AtStartOfAnchor() &&
(!gfx::IsValidCodePointIndex(
text_position->name_,
static_cast<size_t>(text_position->text_offset_)) ||
(grapheme_iterator &&
!grapheme_iterator->IsGraphemeBoundary(
static_cast<size_t>(text_position->text_offset_))))) {
--text_position->text_offset_;
}
return text_position;
@ -2390,18 +2391,20 @@ class AXPosition {
//
// TODO(nektar): Remove this workaround as soon as the source of the bug
// is identified.
if (text_position->text_offset_ > int{text_position->name_.length()})
if (text_position->text_offset_ >
static_cast<int>(text_position->name_.length()))
return CreateNullPosition();
DCHECK_GE(text_position->text_offset_, 0);
DCHECK_LE(text_position->text_offset_,
int{text_position->name_.length()});
while (
!text_position->AtEndOfAnchor() &&
(!gfx::IsValidCodePointIndex(text_position->name_,
size_t{text_position->text_offset_}) ||
(grapheme_iterator && !grapheme_iterator->IsGraphemeBoundary(
size_t{text_position->text_offset_})))) {
static_cast<int>(text_position->name_.length()));
while (!text_position->AtEndOfAnchor() &&
(!gfx::IsValidCodePointIndex(
text_position->name_,
static_cast<size_t>(text_position->text_offset_)) ||
(grapheme_iterator &&
!grapheme_iterator->IsGraphemeBoundary(
static_cast<size_t>(text_position->text_offset_))))) {
++text_position->text_offset_;
}
@ -2470,7 +2473,7 @@ class AXPosition {
} while (text_position->text_offset_ < max_text_offset &&
grapheme_iterator &&
!grapheme_iterator->IsGraphemeBoundary(
size_t{text_position->text_offset_}));
static_cast<size_t>(text_position->text_offset_)));
DCHECK_GT(text_position->text_offset_, 0);
DCHECK_LE(text_position->text_offset_, text_position->MaxTextOffset());
@ -2544,7 +2547,7 @@ class AXPosition {
--text_position->text_offset_;
} while (!text_position->AtStartOfAnchor() && grapheme_iterator &&
!grapheme_iterator->IsGraphemeBoundary(
size_t{text_position->text_offset_}));
static_cast<size_t>(text_position->text_offset_)));
DCHECK_GE(text_position->text_offset_, 0);
DCHECK_LT(text_position->text_offset_, text_position->MaxTextOffset());
@ -3895,9 +3898,10 @@ class AXPosition {
case AXEmbeddedObjectBehavior::kSuppressCharacter:
// TODO(nektar): Switch to anchor->GetInnerTextLength() after AXPosition
// switches to using UTF8.
return int{base::UTF8ToUTF16(GetAnchor()->GetInnerText()).length()};
return static_cast<int>(
base::UTF8ToUTF16(GetAnchor()->GetInnerText()).length());
case AXEmbeddedObjectBehavior::kExposeCharacter:
return int{GetAnchor()->GetHypertext().length()};
return static_cast<int>(GetAnchor()->GetHypertext().length());
}
}
@ -4008,7 +4012,7 @@ class AXPosition {
int AnchorChildCount() const {
if (!GetAnchor())
return 0;
return int{GetAnchor()->GetChildCountCrossingTreeBoundary()};
return static_cast<int>(GetAnchor()->GetChildCountCrossingTreeBoundary());
}
// When a child is ignored, it looks for unignored nodes of that child's
@ -4022,12 +4026,14 @@ class AXPosition {
int AnchorUnignoredChildCount() const {
if (!GetAnchor())
return 0;
return int{GetAnchor()->GetUnignoredChildCountCrossingTreeBoundary()};
return static_cast<int>(
GetAnchor()->GetUnignoredChildCountCrossingTreeBoundary());
}
int AnchorIndexInParent() const {
// If this is the root tree, the index in parent will be 0.
return GetAnchor() ? int{GetAnchor()->index_in_parent()} : INVALID_INDEX;
return GetAnchor() ? static_cast<int>(GetAnchor()->index_in_parent())
: INVALID_INDEX;
}
base::stack<AXNode*> GetAncestorAnchors() const {

@ -337,7 +337,7 @@ class AXRange {
if (current_end_offset > start->text_offset()) {
int characters_to_append =
(max_count > 0)
? std::min(max_count - int{range_text.length()},
? std::min(max_count - static_cast<int>(range_text.length()),
current_end_offset - start->text_offset())
: current_end_offset - start->text_offset();
@ -350,12 +350,13 @@ class AXRange {
(found_trailing_newline && start->IsInWhiteSpace());
}
DCHECK(max_count < 0 || int{range_text.length()} <= max_count);
DCHECK(max_count < 0 ||
static_cast<int>(range_text.length()) <= max_count);
is_first_unignored_leaf = false;
}
if (start->GetAnchor() == end->GetAnchor() ||
int{range_text.length()} == max_count) {
static_cast<int>(range_text.length()) == max_count) {
break;
} else if (concatenation_behavior ==
AXTextConcatenationBehavior::kAsInnerText &&

@ -298,14 +298,14 @@ void AXTableInfo::BuildCellDataVectorFromRowAndCellNodes(
row_count = std::max(row_count, cell_data.row_index + cell_data.row_span);
col_count = std::max(col_count, cell_data.col_index + cell_data.col_span);
if (aria_row_count != ax::mojom::kUnknownAriaColumnOrRowCount) {
aria_row_count =
std::max((aria_row_count),
int{current_aria_row_index + cell_data.row_span - 1});
aria_row_count = std::max(
(aria_row_count),
static_cast<int>(current_aria_row_index + cell_data.row_span - 1));
}
if (aria_col_count != ax::mojom::kUnknownAriaColumnOrRowCount) {
aria_col_count =
std::max((aria_col_count),
int{current_aria_col_index + cell_data.col_span - 1});
aria_col_count = std::max(
(aria_col_count),
static_cast<int>(current_aria_col_index + cell_data.col_span - 1));
}
// Update |current_col_index| to reflect the next available index after
// this cell including its colspan. The next column index in this row
@ -481,7 +481,8 @@ void AXTableInfo::UpdateExtraMacColumnNodeAttributes(size_t col_index) {
data.int_attributes.clear();
// Update the column index.
data.AddIntAttribute(IntAttribute::kTableColumnIndex, int32_t{col_index});
data.AddIntAttribute(IntAttribute::kTableColumnIndex,
static_cast<int32_t>(col_index));
// Update the column header.
if (!col_headers[col_index].empty()) {

@ -72,7 +72,8 @@ size_t FindAccessibleTextBoundary(const std::u16string& text,
if (boundary == ax::mojom::TextBoundary::kLineStart) {
if (direction == ax::mojom::MoveDirection::kForward) {
for (int line_break : line_breaks) {
size_t clamped_line_break = size_t{std::max(0, line_break)};
size_t clamped_line_break =
static_cast<size_t>(std::max(0, line_break));
if ((affinity == ax::mojom::TextAffinity::kDownstream &&
clamped_line_break > start_offset) ||
(affinity == ax::mojom::TextAffinity::kUpstream &&

@ -150,9 +150,9 @@ bool AXTreeSourceChecker<AXSourceNode>::Check(AXSourceNode node,
for (size_t i = 0; i < children.size(); i++) {
auto& child = children[i];
if (!tree_->IsValid(child)) {
std::string msg =
base::StringPrintf("Node %d has an invalid child (index %d): %s\n",
node_id, int{i}, NodeToString(node).c_str());
std::string msg = base::StringPrintf(
"Node %d has an invalid child (index %d): %s\n", node_id,
static_cast<int>(i), NodeToString(node).c_str());
*output = msg + *output;
return false;
}

@ -1724,7 +1724,8 @@ IFACEMETHODIMP AXPlatformNodeWin::setSelectionRanges(LONG nRanges,
return E_INVALIDARG;
if (anchor_node->IsLeaf()) {
if (size_t{ranges->anchorOffset} > anchor_node->GetHypertext().length()) {
if (static_cast<size_t>(ranges->anchorOffset) >
anchor_node->GetHypertext().length()) {
return E_INVALIDARG;
}
} else {
@ -1733,7 +1734,8 @@ IFACEMETHODIMP AXPlatformNodeWin::setSelectionRanges(LONG nRanges,
}
if (focus_node->IsLeaf()) {
if (size_t{ranges->activeOffset} > focus_node->GetHypertext().length())
if (static_cast<size_t>(ranges->activeOffset) >
focus_node->GetHypertext().length())
return E_INVALIDARG;
} else {
if (ranges->activeOffset > focus_node->GetChildCount())
@ -3367,7 +3369,7 @@ IFACEMETHODIMP AXPlatformNodeWin::get_columnHeaderCells(
}
}
*n_column_header_cells = LONG{column_header_ids.size()};
*n_column_header_cells = static_cast<LONG>(column_header_ids.size());
return S_OK;
}
@ -3420,7 +3422,7 @@ IFACEMETHODIMP AXPlatformNodeWin::get_rowHeaderCells(
}
}
*n_row_header_cells = LONG{row_header_ids.size()};
*n_row_header_cells = static_cast<LONG>(row_header_ids.size());
return S_OK;
}
@ -5244,7 +5246,8 @@ AXPlatformNodeWin::GetMarkerTypeFromRange(
if (!start_offset && contiguous_range->first > 0)
return MarkerTypeRangeResult::kMixed;
// 2. The |end_offset| is not specified, treat it as max text offset.
if (!end_offset && size_t{contiguous_range->second} < GetHypertext().length())
if (!end_offset &&
static_cast<size_t>(contiguous_range->second) < GetHypertext().length())
return MarkerTypeRangeResult::kMixed;
// 3. The |start_offset| is specified, but is before the first matching range.
if (start_offset && start_offset.value() < contiguous_range->first)

@ -316,12 +316,13 @@ ComPtr<IRawElementProviderSimple>
AXPlatformNodeWinTest::GetIRawElementProviderSimpleFromChildIndex(
int child_index) {
if (!GetRootAsAXNode() || child_index < 0 ||
size_t{child_index} >= GetRootAsAXNode()->children().size()) {
static_cast<size_t>(child_index) >=
GetRootAsAXNode()->children().size()) {
return ComPtr<IRawElementProviderSimple>();
}
return QueryInterfaceFromNode<IRawElementProviderSimple>(
GetRootAsAXNode()->children()[size_t{child_index}]);
GetRootAsAXNode()->children()[static_cast<size_t>(child_index)]);
}
Microsoft::WRL::ComPtr<IRawElementProviderSimple>
@ -2834,7 +2835,8 @@ TEST_F(AXPlatformNodeWinTest, UnlabeledImageRoleDescription) {
Init(tree);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
for (int child_index = 0; child_index < int{tree.nodes[0].child_ids.size()};
for (int child_index = 0;
child_index < static_cast<int>(tree.nodes[0].child_ids.size());
++child_index) {
ComPtr<IDispatch> child_dispatch;
ASSERT_HRESULT_SUCCEEDED(root_obj->get_accChild(
@ -2870,7 +2872,8 @@ TEST_F(AXPlatformNodeWinTest, UnlabeledImageAttributes) {
Init(tree);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
for (int child_index = 0; child_index < int{tree.nodes[0].child_ids.size()};
for (int child_index = 0;
child_index < static_cast<int>(tree.nodes[0].child_ids.size());
++child_index) {
ComPtr<IDispatch> child_dispatch;
ASSERT_HRESULT_SUCCEEDED(root_obj->get_accChild(

@ -365,7 +365,7 @@ AXPlatformNode* TestAXNodeWrapper::GetFromTreeIDAndNodeID(
}
int TestAXNodeWrapper::GetIndexInParent() {
return node_ ? int{node_->GetUnignoredIndexInParent()} : -1;
return node_ ? static_cast<int>(node_->GetUnignoredIndexInParent()) : -1;
}
void TestAXNodeWrapper::ReplaceIntAttribute(int32_t node_id,
@ -934,13 +934,14 @@ gfx::RectF TestAXNodeWrapper::GetLocation() const {
}
int TestAXNodeWrapper::InternalChildCount() const {
return int{node_->GetUnignoredChildCount()};
return static_cast<int>(node_->GetUnignoredChildCount());
}
TestAXNodeWrapper* TestAXNodeWrapper::InternalGetChild(int index) const {
CHECK_GE(index, 0);
CHECK_LT(index, InternalChildCount());
return GetOrCreate(tree_, node_->GetUnignoredChildAtIndex(size_t{index}));
return GetOrCreate(
tree_, node_->GetUnignoredChildAtIndex(static_cast<size_t>(index)));
}
// Recursive helper function for GetUIADescendants. Aggregates all of the

@ -140,13 +140,14 @@ gfx::RectF TestAXNodeHelper::GetLocation() const {
}
int TestAXNodeHelper::InternalChildCount() const {
return int{node_->GetUnignoredChildCount()};
return static_cast<int>(node_->GetUnignoredChildCount());
}
TestAXNodeHelper* TestAXNodeHelper::InternalGetChild(int index) const {
CHECK_GE(index, 0);
CHECK_LT(index, InternalChildCount());
return GetOrCreate(tree_, node_->GetUnignoredChildAtIndex(size_t{index}));
return GetOrCreate(
tree_, node_->GetUnignoredChildAtIndex(static_cast<size_t>(index)));
}
gfx::RectF TestAXNodeHelper::GetInlineTextRect(const int start_offset,

@ -71,7 +71,7 @@ void TreeGenerator::BuildUniqueTreeWithIgnoredNodes(int tree_index,
AXTreeUpdate update;
BuildUniqueTreeUpdate(tree_index, &update);
int node_count = int{update.nodes.size()};
int node_count = static_cast<int>(update.nodes.size());
CHECK_GE(ignored_index, 0);
CHECK_LT(ignored_index, 1 << (node_count - 1));

@ -229,7 +229,7 @@ ui::EventDispatchDetails InputMethodWinBase::DispatchKeyEvent(
// If only 1 WM_CHAR per the key event, set it as the character of it.
if (char_msgs.size() == 1 &&
!std::iswcntrl(static_cast<wint_t>(char_msgs[0].wParam)))
event->set_character(char16_t{char_msgs[0].wParam});
event->set_character(static_cast<char16_t>(char_msgs[0].wParam));
return ProcessUnhandledKeyEvent(event, &char_msgs);
}

@ -241,7 +241,7 @@ class TreeNodeModel : public TreeModel {
std::unique_ptr<NodeType> Remove(NodeType* parent, NodeType* node) {
DCHECK(parent);
return Remove(parent, size_t{parent->GetIndexOf(node)});
return Remove(parent, static_cast<size_t>(parent->GetIndexOf(node)));
}
void NotifyObserverTreeNodesAdded(NodeType* parent,

@ -60,7 +60,7 @@ absl::optional<int> GetPerMonitorDPI(HMONITOR monitor) {
return absl::nullopt;
DCHECK_EQ(dpi_x, dpi_y);
return int{dpi_x};
return static_cast<int>(dpi_x);
}
float GetScaleFactorForDPI(int dpi, bool include_accessibility) {
@ -457,7 +457,8 @@ std::vector<DisplayInfo> GetDisplayInfosFromSystem() {
std::vector<DisplayInfo> display_infos;
EnumDisplayMonitors(nullptr, nullptr, EnumMonitorForDisplayInfoCallback,
reinterpret_cast<LPARAM>(&display_infos));
DCHECK_EQ(::GetSystemMetrics(SM_CMONITORS), int{display_infos.size()});
DCHECK_EQ(::GetSystemMetrics(SM_CMONITORS),
static_cast<int>(display_infos.size()));
return display_infos;
}
@ -709,7 +710,7 @@ gfx::NativeWindow ScreenWin::GetLocalProcessWindowAtPoint(
}
int ScreenWin::GetNumDisplays() const {
return int{screen_win_displays_.size()};
return static_cast<int>(screen_win_displays_.size());
}
const std::vector<Display>& ScreenWin::GetAllDisplays() const {

@ -163,7 +163,7 @@ class UwpTextScaleFactorImpl : public UwpTextScaleFactor {
// equal to 1. Let's make sure that's the case - if we don't, we could get
// bizarre behavior and divide-by-zeros later on.
DCHECK_GE(result, 1.0);
return float{result};
return static_cast<float>(result);
}
private:

@ -398,7 +398,7 @@ SkColor AlphaBlend(SkColor foreground, SkColor background, float alpha) {
SkColor GetResultingPaintColor(SkColor foreground, SkColor background) {
return AlphaBlend(SkColorSetA(foreground, SK_AlphaOPAQUE), background,
SkAlpha{SkColorGetA(foreground)});
static_cast<SkAlpha>(SkColorGetA(foreground)));
}
bool IsDark(SkColor color) {

@ -300,7 +300,7 @@ TEST(ColorUtils, BlendForMinContrast_MatchesNaiveImplementation) {
SkAlpha alpha = SK_AlphaTRANSPARENT;
SkColor color = default_foreground;
for (int i = SK_AlphaTRANSPARENT; i <= SK_AlphaOPAQUE; ++i) {
alpha = SkAlpha{i};
alpha = static_cast<SkAlpha>(i);
color = AlphaBlend(high_contrast_foreground, default_foreground, alpha);
if (GetContrastRatio(color, background) >= kContrastRatio)
break;

@ -174,8 +174,8 @@ void PaintThrobberSpinningAfterWaiting(Canvas* canvas,
// Blend the color between "waiting" and "spinning" states.
constexpr auto kColorFadeTime = base::TimeDelta::FromMilliseconds(900);
const float color_progress = float{Tween::CalculateValue(
Tween::LINEAR_OUT_SLOW_IN, std::min(elapsed_time / kColorFadeTime, 1.0))};
const float color_progress = static_cast<float>(Tween::CalculateValue(
Tween::LINEAR_OUT_SLOW_IN, std::min(elapsed_time / kColorFadeTime, 1.0)));
const SkColor blend_color =
color_utils::AlphaBlend(color, waiting_state->color, color_progress);

@ -3337,7 +3337,7 @@ TEST_F(RenderTextTest, MoveCursor_UpDown_Scroll) {
line_height =
render_text->GetLineSizeF(render_text->selection_model()).height();
int offset_y = test_api()->display_offset().y();
for (size_t i = kLineSize - 2; i != size_t{-1}; --i) {
for (size_t i = kLineSize - 2; i != static_cast<size_t>(-1); --i) {
SCOPED_TRACE(base::StringPrintf("Testing line [%" PRIuS "]", i));
render_text->MoveCursor(CHARACTER_BREAK, CURSOR_UP, SELECTION_NONE);
ASSERT_EQ(Range(i * 2), render_text->selection());
@ -6146,7 +6146,7 @@ TEST_F(RenderTextTest, Multiline_GetLineContainingCaret) {
// GetCursorBounds should be in the same line as GetLineContainingCaret.
Rect bounds = render_text->GetCursorBounds(sample.caret, true);
EXPECT_EQ(int{sample.line_num},
EXPECT_EQ(static_cast<int>(sample.line_num),
GetLineContainingYCoord(bounds.origin().y() + 1));
}
}

@ -1263,7 +1263,8 @@ void NotificationViewMD::ActionButtonPressed(size_t index,
const absl::optional<std::u16string>& placeholder =
action_buttons_[index]->placeholder();
if (placeholder) {
inline_reply_->textfield()->SetProperty(kTextfieldIndexKey, int{index});
inline_reply_->textfield()->SetProperty(kTextfieldIndexKey,
static_cast<int>(index));
inline_reply_->textfield()->SetPlaceholderText(
placeholder->empty()
? l10n_util::GetStringUTF16(
@ -1278,7 +1279,7 @@ void NotificationViewMD::ActionButtonPressed(size_t index,
SchedulePaint();
} else {
MessageCenter::Get()->ClickOnNotificationButton(notification_id(),
int{index});
static_cast<int>(index));
}
}

@ -77,7 +77,7 @@ void AXVirtualView::AddChildView(std::unique_ptr<AXVirtualView> view) {
DCHECK(view);
if (view->virtual_parent_view_ == this)
return; // Already a child of this virtual view.
AddChildViewAt(std::move(view), int{children_.size()});
AddChildViewAt(std::move(view), static_cast<int>(children_.size()));
}
void AXVirtualView::AddChildViewAt(std::unique_ptr<AXVirtualView> view,
@ -91,7 +91,7 @@ void AXVirtualView::AddChildViewAt(std::unique_ptr<AXVirtualView> view,
"AXVirtualView parent. Call "
"RemoveChildView first.";
DCHECK_GE(index, 0);
DCHECK_LE(index, int{children_.size()});
DCHECK_LE(index, static_cast<int>(children_.size()));
view->virtual_parent_view_ = this;
children_.insert(children_.begin() + index, std::move(view));
@ -103,10 +103,10 @@ void AXVirtualView::AddChildViewAt(std::unique_ptr<AXVirtualView> view,
void AXVirtualView::ReorderChildView(AXVirtualView* view, int index) {
DCHECK(view);
if (index >= int{children_.size()})
if (index >= static_cast<int>(children_.size()))
return;
if (index < 0)
index = int{children_.size()} - 1;
index = static_cast<int>(children_.size()) - 1;
DCHECK_EQ(view->virtual_parent_view_, this);
if (children_[index].get() == view)

@ -80,7 +80,8 @@ ViewAccessibility::~ViewAccessibility() = default;
void ViewAccessibility::AddVirtualChildView(
std::unique_ptr<AXVirtualView> virtual_view) {
AddVirtualChildViewAt(std::move(virtual_view), int{virtual_children_.size()});
AddVirtualChildViewAt(std::move(virtual_view),
static_cast<int>(virtual_children_.size()));
}
void ViewAccessibility::AddVirtualChildViewAt(
@ -88,7 +89,7 @@ void ViewAccessibility::AddVirtualChildViewAt(
int index) {
DCHECK(virtual_view);
DCHECK_GE(index, 0);
DCHECK_LE(size_t{index}, virtual_children_.size());
DCHECK_LE(static_cast<size_t>(index), virtual_children_.size());
if (virtual_view->parent_view() == this)
return;

@ -349,7 +349,8 @@ int ViewAXPlatformNodeDelegate::GetChildCount() const {
}
}
return view_child_count + int{child_widgets_result.child_widgets.size()};
return view_child_count +
static_cast<int>(child_widgets_result.child_widgets.size());
}
gfx::NativeViewAccessible ViewAXPlatformNodeDelegate::ChildAtIndex(int index) {
@ -418,7 +419,7 @@ gfx::NativeViewAccessible ViewAXPlatformNodeDelegate::ChildAtIndex(int index) {
DCHECK_GE(index, 0);
}
if (index < int{child_widgets_result.child_widgets.size()})
if (index < static_cast<int>(child_widgets_result.child_widgets.size()))
return child_widgets[index]->GetRootView()->GetNativeViewAccessible();
NOTREACHED() << "|index| should be less than the unignored child count.";
@ -673,7 +674,7 @@ std::vector<int32_t> ViewAXPlatformNodeDelegate::GetColHeaderNodeIds() const {
std::vector<int32_t> ViewAXPlatformNodeDelegate::GetColHeaderNodeIds(
int col_index) const {
std::vector<int32_t> columns = GetColHeaderNodeIds();
if (columns.size() <= size_t{col_index}) {
if (columns.size() <= static_cast<size_t>(col_index)) {
return {};
}
return {columns[col_index]};

@ -2746,7 +2746,8 @@ MenuItemView* MenuController::FindNextSelectableMenuItem(
int index,
SelectionIncrementDirectionType direction,
bool is_initial) {
int parent_count = int{parent->GetSubmenu()->GetMenuItems().size()};
int parent_count =
static_cast<int>(parent->GetSubmenu()->GetMenuItems().size());
int stop_index = (index + parent_count) % parent_count;
bool include_all_items =
(index == -1 && direction == INCREMENT_SELECTION_DOWN) ||
@ -2814,15 +2815,15 @@ MenuController::SelectByCharDetails MenuController::FindChildForMnemonic(
MenuItemView* child = menu_items[i];
if (child->GetEnabled() && child->GetVisible()) {
if (child == pending_state_.item)
details.index_of_item = int{i};
details.index_of_item = static_cast<int>(i);
if (match_function(child, key)) {
if (details.first_match == -1)
details.first_match = int{i};
details.first_match = static_cast<int>(i);
else
details.has_multiple = true;
if (details.next_match == -1 && details.index_of_item != -1 &&
int{i} > details.index_of_item)
details.next_match = int{i};
static_cast<int>(i) > details.index_of_item)
details.next_match = static_cast<int>(i);
}
}
}

@ -352,7 +352,7 @@ MenuItemView* MenuItemView::AddMenuItemAt(
DCHECK_GE(index, 0);
if (!submenu_)
CreateSubmenu();
DCHECK_LE(size_t{index}, submenu_->children().size());
DCHECK_LE(static_cast<size_t>(index), submenu_->children().size());
if (type == Type::kSeparator) {
submenu_->AddChildViewAt(std::make_unique<MenuSeparator>(separator_style),
index);
@ -426,7 +426,8 @@ MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id,
const std::u16string& label,
const gfx::ImageSkia& icon,
Type type) {
const int index = submenu_ ? int{submenu_->children().size()} : 0;
const int index =
submenu_ ? static_cast<int>(submenu_->children().size()) : 0;
return AddMenuItemAt(index, item_id, label, std::u16string(),
std::u16string(), ui::ImageModel(),
ui::ImageModel::FromImageSkia(icon), type,
@ -1385,7 +1386,7 @@ gfx::Insets MenuItemView::GetContainerMargins() const {
}
int MenuItemView::NonIconChildViewsCount() const {
return int{children().size()} - (icon_view_ ? 1 : 0) -
return static_cast<int>(children().size()) - (icon_view_ ? 1 : 0) -
(radio_check_image_view_ ? 1 : 0) -
(submenu_arrow_image_view_ ? 1 : 0) - (vertical_separator_ ? 1 : 0);
}

@ -136,7 +136,9 @@ MenuItemView* MenuModelAdapter::AppendMenuItemFromModel(ui::MenuModel* model,
MenuItemView* menu,
int item_id) {
const int menu_index =
menu->HasSubmenu() ? int{menu->GetSubmenu()->children().size()} : 0;
menu->HasSubmenu()
? static_cast<int>(menu->GetSubmenu()->children().size())
: 0;
return AddMenuItemFromModelAt(model, model_index, menu, menu_index, item_id);
}

@ -219,7 +219,7 @@ void CheckSubmenu(const RootModel& model,
continue;
}
// Check placement.
EXPECT_EQ(i, size_t{submenu->GetSubmenu()->GetIndexOf(item)});
EXPECT_EQ(i, static_cast<size_t>(submenu->GetSubmenu()->GetIndexOf(item)));
// Check type.
switch (model_item.type) {
@ -264,7 +264,7 @@ void CheckSubmenu(const RootModel& model,
// Check activation.
static_cast<views::MenuDelegate*>(delegate)->ExecuteCommand(id);
EXPECT_EQ(i, size_t{submodel->last_activation()});
EXPECT_EQ(i, static_cast<size_t>(submodel->last_activation()));
submodel->set_last_activation(-1);
}
}
@ -303,7 +303,7 @@ TEST_F(MenuModelAdapterTest, BasicTest) {
}
// Check placement.
EXPECT_EQ(i, size_t{menu->GetSubmenu()->GetIndexOf(item)});
EXPECT_EQ(i, static_cast<size_t>(menu->GetSubmenu()->GetIndexOf(item)));
// Check type.
switch (model_item.type) {
@ -348,7 +348,7 @@ TEST_F(MenuModelAdapterTest, BasicTest) {
// Check activation.
static_cast<views::MenuDelegate*>(&delegate)->ExecuteCommand(id);
EXPECT_EQ(i, size_t{model.last_activation()});
EXPECT_EQ(i, static_cast<size_t>(model.last_activation()));
model.set_last_activation(-1);
}

@ -200,7 +200,7 @@ class TabStrip : public View, public gfx::AnimationDelegate {
METADATA_HEADER(TabStrip);
// The return value of GetSelectedTabIndex() when no tab is selected.
static constexpr size_t kNoSelectedTab = size_t{-1};
static constexpr size_t kNoSelectedTab = static_cast<size_t>(-1);
TabStrip(TabbedPane::Orientation orientation,
TabbedPane::TabStripStyle style);

@ -287,8 +287,10 @@ void TableView::SetColumnVisibility(int id, bool is_visible) {
[id](const auto& column) { return column.column.id == id; });
if (i != visible_columns_.end()) {
visible_columns_.erase(i);
if (active_visible_column_index_ >= int{visible_columns_.size()})
SetActiveVisibleColumnIndex(int{visible_columns_.size()} - 1);
if (active_visible_column_index_ >=
static_cast<int>(visible_columns_.size()))
SetActiveVisibleColumnIndex(static_cast<int>(visible_columns_.size()) -
1);
}
}
@ -380,7 +382,7 @@ int TableView::ModelToView(int model_index) const {
DCHECK_GE(model_index, 0) << " negative model_index " << model_index;
if (!GetIsSorted())
return model_index;
DCHECK_LT(model_index, int{model_to_view_.size()})
DCHECK_LT(model_index, static_cast<int>(model_to_view_.size()))
<< " out of bounds model_index " << model_index;
return model_to_view_[model_index];
}
@ -390,7 +392,7 @@ int TableView::ViewToModel(int view_index) const {
DCHECK_LT(view_index, GetRowCount());
if (!GetIsSorted())
return view_index;
DCHECK_LT(view_index, int{view_to_model_.size()})
DCHECK_LT(view_index, static_cast<int>(view_to_model_.size()))
<< " out of bounds view_index " << view_index;
return view_to_model_[view_index];
}
@ -775,8 +777,8 @@ void TableView::OnItemsRemoved(int start, int length) {
// See (https://crbug.com/1173373).
SortItemsAndUpdateMapping(/*schedule_paint=*/true);
if (GetIsSorted()) {
DCHECK_EQ(GetRowCount(), int{view_to_model_.size()});
DCHECK_EQ(GetRowCount(), int{model_to_view_.size()});
DCHECK_EQ(GetRowCount(), static_cast<int>(view_to_model_.size()));
DCHECK_EQ(GetRowCount(), static_cast<int>(model_to_view_.size()));
}
// If the selection was empty and is no longer empty select the same visual
@ -1676,7 +1678,8 @@ AXVirtualView* TableView::GetVirtualAccessibilityRow(int row) {
DCHECK_LT(row, GetRowCount());
if (header_)
++row;
if (size_t{row} < GetViewAccessibility().virtual_children().size()) {
if (static_cast<size_t>(row) <
GetViewAccessibility().virtual_children().size()) {
const auto& ax_row = GetViewAccessibility().virtual_children()[size_t{row}];
DCHECK(ax_row);
DCHECK_EQ(ax_row->GetData().role, ax::mojom::Role::kRow);

@ -523,7 +523,7 @@ class TableViewTest : public ViewsTestBase,
// Makes sure the virtual row count factors in the presence of the header.
const int first_row_index = helper_->header() ? 1 : 0;
const int virtual_row_count = table_->GetRowCount() + first_row_index;
EXPECT_EQ(virtual_row_count, int{virtual_children.size()});
EXPECT_EQ(virtual_row_count, static_cast<int>(virtual_children.size()));
// Make sure every virtual row is valid.
for (int index = first_row_index; index < virtual_row_count; index++) {
@ -637,7 +637,7 @@ TEST_P(TableViewTest, RebuildVirtualAccessibilityChildren) {
ax::mojom::IntAttribute::kTableColumnCount)));
// The header takes up another row.
ASSERT_EQ(size_t{table_->GetRowCount() + 1},
ASSERT_EQ(static_cast<size_t>(table_->GetRowCount() + 1),
view_accessibility.virtual_children().size());
const auto& header = view_accessibility.virtual_children().front();
ASSERT_TRUE(header);

@ -526,9 +526,10 @@ void TreeView::TreeNodesAdded(TreeModel* model,
std::unique_ptr<AXVirtualView> ax_view =
CreateAndSetAccessibilityView(child.get());
parent_node->Add(std::move(child), i);
DCHECK_LE(int{i}, parent_node->accessibility_view()->GetChildCount());
DCHECK_LE(static_cast<int>(i),
parent_node->accessibility_view()->GetChildCount());
parent_node->accessibility_view()->AddChildViewAt(std::move(ax_view),
int{i});
static_cast<int>(i));
}
if (IsExpanded(parent)) {
NotifyAccessibilityEvent(ax::mojom::Event::kRowCountChanged, true);
@ -953,7 +954,7 @@ void TreeView::PopulateAccessibilityData(InternalNode* node,
// Per the ARIA Spec, aria-posinset and aria-setsize are 1-based
// not 0-based.
int pos_in_parent = node->parent()->GetIndexOf(node) + 1;
int sibling_size = int{node->parent()->children().size()};
int sibling_size = static_cast<int>(node->parent()->children().size());
data->AddIntAttribute(ax::mojom::IntAttribute::kPosInSet,
int32_t{pos_in_parent});
data->AddIntAttribute(ax::mojom::IntAttribute::kSetSize,

@ -237,7 +237,7 @@ std::string TreeViewTest::GetSelectedAccessibilityViewName() const {
const AXVirtualView* parent_view = ax_view->virtual_parent_view();
while (parent_view) {
size_t sibling_index_in_parent =
size_t{parent_view->GetIndexOf(ax_view)} + 1;
static_cast<size_t>(parent_view->GetIndexOf(ax_view)) + 1;
if (sibling_index_in_parent < parent_view->children().size()) {
ax_view = parent_view->children()[sibling_index_in_parent].get();
break;
@ -311,7 +311,7 @@ const AXVirtualView* TreeViewTest::GetAccessibilityViewByName(
const AXVirtualView* parent_view = ax_view->virtual_parent_view();
while (parent_view) {
size_t sibling_index_in_parent =
size_t{parent_view->GetIndexOf(ax_view)} + 1;
static_cast<size_t>(parent_view->GetIndexOf(ax_view)) + 1;
if (sibling_index_in_parent < parent_view->children().size()) {
ax_view = parent_view->children()[sibling_index_in_parent].get();
break;

@ -169,7 +169,7 @@ bool FocusManager::RotatePaneFocus(Direction direction,
// is initially focused.
if (panes.empty())
return false;
int count = int{panes.size()};
int count = static_cast<int>(panes.size());
// Initialize |index| to an appropriate starting index if nothing is
// focused initially.

@ -172,7 +172,7 @@ class SimulatedExtensionsContainer : public SimulatedToolbarElement {
void AddIconAt(int position, bool initially_visible) {
DCHECK_GE(position, 0);
DCHECK_LT(position, int{children().size()});
DCHECK_LT(position, static_cast<int>(children().size()));
auto new_child = std::make_unique<StaticSizedView>(kIconSize);
new_child->SetVisible(initially_visible);
if (initially_visible)
@ -182,13 +182,13 @@ class SimulatedExtensionsContainer : public SimulatedToolbarElement {
void RemoveIconAt(int position) {
DCHECK_GE(position, 0);
DCHECK_LT(position, int{children().size()} - 1);
DCHECK_LT(position, static_cast<int>(children().size()) - 1);
visible_views_.erase(RemoveChildViewT<View>(children()[position]).get());
}
void SetIconVisibility(int position, bool visible) {
DCHECK_GE(position, 0);
DCHECK_LT(position, int{children().size()} - 1);
DCHECK_LT(position, static_cast<int>(children().size()) - 1);
auto* const button = children()[position];
if (visible) {
layout()->FadeIn(button);
@ -203,8 +203,8 @@ class SimulatedExtensionsContainer : public SimulatedToolbarElement {
DCHECK_GE(from, 0);
DCHECK_GE(to, 0);
DCHECK_NE(from, to);
DCHECK_LT(from, int{children().size()} - 1);
DCHECK_LT(to, int{children().size()} - 1);
DCHECK_LT(from, static_cast<int>(children().size()) - 1);
DCHECK_LT(to, static_cast<int>(children().size()) - 1);
ReorderChildView(children()[from], to);
}
@ -229,7 +229,7 @@ class SimulatedExtensionsContainer : public SimulatedToolbarElement {
const int available_width = width() - kIconDimension;
DCHECK_GE(available_width, 0);
int num_visible = 0;
for (int i = 0; i < int{children().size()} - 1; ++i) {
for (int i = 0; i < static_cast<int>(children().size()) - 1; ++i) {
const View* const child = children()[i];
if (child->GetVisible()) {
++num_visible;
@ -249,13 +249,13 @@ class SimulatedExtensionsContainer : public SimulatedToolbarElement {
num_visible,
(available_size.width().value() - kIconDimension) / kIconDimension);
}
DCHECK_LT(num_visible, int{children().size()});
DCHECK_LT(num_visible, static_cast<int>(children().size()));
if (expected_num_icons.has_value())
EXPECT_EQ(expected_num_icons.value(), num_visible);
// Verify that the correct icons are visible and are in the correct place
// with the correct size.
int x = 0;
for (int i = 0; i < int{children().size()} - 1; ++i) {
for (int i = 0; i < static_cast<int>(children().size()) - 1; ++i) {
const View* const child = children()[i];
if (base::Contains(visible_views_, child)) {
if (num_visible > 0) {

@ -897,8 +897,8 @@ void FlexLayout::AllocateFlexShortageAtOrder(
const int weight = flex_child.flex.weight();
DCHECK_GT(weight, 0);
DCHECK(deficit.is_bounded());
const SizeBound to_deduct =
base::ClampRound(deficit.value() * weight / float{flex_total});
const SizeBound to_deduct = base::ClampRound(
deficit.value() * weight / static_cast<float>(flex_total));
const SizeBound new_main = flex_child.preferred_size.main() - to_deduct;
// If a view would shrink smaller than its current size, go with that and
@ -1029,8 +1029,8 @@ void FlexLayout::AllocateFlexExcessAtOrder(
// Round up so we give slightly greater weight to earlier views.
SizeBound flex_amount = remaining;
if (remaining.is_bounded()) {
flex_amount =
base::ClampCeil(remaining.value() * weight / float{flex_total});
flex_amount = base::ClampCeil(remaining.value() * weight /
static_cast<float>(flex_total));
}
const int old_size = flex_child.current_size.main();
const SizeBound new_main = flex_amount + old_size;

@ -290,7 +290,7 @@ void Span::Center(const Span& container, const Inset1D& margins) {
// Case 2: room for only part of the margins.
if (margins.size() > remaining) {
float scale = float{remaining} / float{margins.size()};
float scale = static_cast<float>(remaining) / margins.size();
set_start(container.start() + std::roundf(scale * margins.leading()));
return;
}

@ -3089,8 +3089,8 @@ TEST_F(FlexLayoutCrossAxisFitTest, Layout_CrossCenter) {
// Second child view is smaller than the host view, but margins don't fit.
// The margins will be scaled down.
remain = kHostSize.height() - kChildSizes[0].height();
expected = std::roundf(kChildMargins[1].top() * float{remain} /
float{kChildMargins[1].height()});
expected = std::roundf(kChildMargins[1].top() * static_cast<float>(remain) /
kChildMargins[1].height());
EXPECT_EQ(expected, child_views_[1]->origin().y());
// Third child view does not fit, so is centered.

@ -106,7 +106,7 @@ class LayoutElement {
std::vector<std::unique_ptr<T>>* elements) {
DCHECK_GE(start, 0);
DCHECK_GT(length, 0);
DCHECK_LE(size_t{start + length}, elements->size());
DCHECK_LE(static_cast<size_t>(start + length), elements->size());
return std::accumulate(
elements->cbegin() + start, elements->cbegin() + start + length, 0,
[](int size, const auto& elem) { return size + elem->Size(); });

@ -278,7 +278,8 @@ void View::ReorderChildView(View* view, int index) {
DCHECK(i != children_.end());
// If |view| is already at the desired position, there's nothing to do.
const bool move_to_end = (index < 0) || (size_t{index} >= children_.size());
const bool move_to_end =
(index < 0) || (static_cast<size_t>(index) >= children_.size());
const auto pos = move_to_end ? std::prev(children_.end())
: std::next(children_.begin(), index);
if (i == pos)
@ -2477,7 +2478,7 @@ void View::PaintDebugRects(const PaintInfo& parent_paint_info) {
void View::AddChildViewAtImpl(View* view, int index) {
CHECK_NE(view, this) << "You cannot add a view as its own child";
DCHECK_GE(index, 0);
DCHECK_LE(size_t{index}, children_.size());
DCHECK_LE(static_cast<size_t>(index), children_.size());
// TODO(https://crbug.com/942298): Should just DCHECK(!view->parent_);.
View* parent = view->parent_;

@ -419,7 +419,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// for new code.
template <typename T>
T* AddChildView(T* view) {
AddChildViewAtImpl(view, int{children_.size()});
AddChildViewAtImpl(view, static_cast<int>(children_.size()));
return view;
}
template <typename T>