0

Change GetClassName() to return a std::string_view and clean up callers.

Bug: 364987728
Change-Id: I4e0a43b49c93f0ad9f73dc3ca0ade26988cfff25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6230223
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Allen Bauer <kylixrd@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Owners-Override: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1416424}
This commit is contained in:
Peter Kasting
2025-02-05 13:17:23 -08:00
committed by Chromium LUCI CQ
parent eb5f5ee80d
commit 0600f5d827
62 changed files with 208 additions and 259 deletions
ash
chrome
components
ui

@@ -56,8 +56,7 @@ void NativeFocusWatcher::UpdateFocusedView() {
gfx::Rect view_bounds = view->GetContentsBounds(); gfx::Rect view_bounds = view->GetContentsBounds();
// Workarounds that attempts to pick a better bounds. // Workarounds that attempts to pick a better bounds.
if (std::string_view(view->GetClassName()) == if (view->GetClassName() == views::LabelButton::kViewClassName) {
std::string_view(views::LabelButton::kViewClassName)) {
view_bounds = view->GetLocalBounds(); view_bounds = view->GetLocalBounds();
view_bounds.Inset(2); view_bounds.Inset(2);
} }

@@ -1183,8 +1183,7 @@ void AppListControllerImpl::SetKeyboardTraversalMode(bool engaged) {
// TODO(https://crbug.com/1262236): class name comparision and static cast // TODO(https://crbug.com/1262236): class name comparision and static cast
// should be avoided in the production code. Find a better way to guarantee // should be avoided in the production code. Find a better way to guarantee
// the item's selection status. // the item's selection status.
if (std::string_view(focused_view->GetClassName()) == if (focused_view->GetClassName() == AppListItemView::kViewClassName) {
std::string_view(AppListItemView::kViewClassName)) {
static_cast<AppListItemView*>(focused_view)->EnsureSelected(); static_cast<AppListItemView*>(focused_view)->EnsureSelected();
} }

@@ -185,7 +185,7 @@ class AppListBubbleViewTest : public AshTestBase {
->IsBubbleShown(); ->IsBubbleShown();
} }
const char* GetFocusedViewName() { std::string_view GetFocusedViewName() {
auto* view = GetFocusedView(); auto* view = GetFocusedView();
return view ? view->GetClassName() : "none"; return view ? view->GetClassName() : "none";
} }

@@ -21,6 +21,7 @@
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/view_utils.h"
namespace ash { namespace ash {
namespace hud_display { namespace hud_display {
@@ -183,23 +184,17 @@ void Legend::Layout(PassKey) {
gfx::Size max_size; gfx::Size max_size;
bool updated = false; bool updated = false;
for (views::View* view : children()) { for (views::View* view : children()) {
if (std::string_view(view->GetClassName()) != if (auto* entry = views::AsViewClass<LegendEntry>(view)) {
std::string_view(LegendEntry::kViewClassName)) { views::View* value = entry->value();
continue; max_size.SetToMax(value->GetPreferredSize());
updated |= max_size != value->GetPreferredSize();
} }
views::View* value = static_cast<LegendEntry*>(view)->value();
max_size.SetToMax(value->GetPreferredSize());
updated |= max_size != value->GetPreferredSize();
} }
if (updated) { if (updated) {
for (views::View* view : children()) { for (views::View* view : children()) {
if (std::string_view(view->GetClassName()) != if (auto* entry = views::AsViewClass<LegendEntry>(view)) {
std::string_view(LegendEntry::kViewClassName)) { entry->value()->SetPreferredSize(max_size);
continue;
} }
static_cast<LegendEntry*>(view)->value()->SetPreferredSize(max_size);
} }
LayoutSuperclass<views::View>(this); LayoutSuperclass<views::View>(this);
} }
@@ -207,23 +202,17 @@ void Legend::Layout(PassKey) {
void Legend::SetValuesIndex(size_t index) { void Legend::SetValuesIndex(size_t index) {
for (views::View* view : children()) { for (views::View* view : children()) {
if (std::string_view(view->GetClassName()) != if (auto* entry = views::AsViewClass<LegendEntry>(view)) {
std::string_view(LegendEntry::kViewClassName)) { entry->SetValueIndex(index);
continue;
} }
static_cast<LegendEntry*>(view)->SetValueIndex(index);
} }
} }
void Legend::RefreshValues() { void Legend::RefreshValues() {
for (views::View* view : children()) { for (views::View* view : children()) {
if (std::string_view(view->GetClassName()) != if (auto* entry = views::AsViewClass<LegendEntry>(view)) {
std::string_view(LegendEntry::kViewClassName)) { entry->RefreshValue();
continue;
} }
static_cast<LegendEntry*>(view)->RefreshValue();
} }
} }

@@ -881,12 +881,10 @@ gfx::Rect LoginScreenTestApi::GetShutDownButtonMirroredBounds() {
// static // static
std::string LoginScreenTestApi::GetAppsButtonClassName() { std::string LoginScreenTestApi::GetAppsButtonClassName() {
views::View* button = GetAppsButton(); if (views::View* button = GetAppsButton()) {
if (!button) { return std::string(button->GetClassName());
return "";
} }
return {};
return button->GetClassName();
} }
// static // static

@@ -103,7 +103,7 @@ class AssistantOverlayTest : public AshTestBase,
protected: protected:
const views::View* GetAssistantOverlay() { const views::View* GetAssistantOverlay() {
for (const views::View* child : home_button()->children()) { for (const views::View* child : home_button()->children()) {
if (std::string(child->GetClassName()) == kAssistantOverlayClassName) { if (child->GetClassName() == kAssistantOverlayClassName) {
return child; return child;
} }
} }

@@ -491,10 +491,6 @@ class AccessibilityDetailedViewTest : public AshTestBase,
detailed_menu_->color_correction_view_); detailed_menu_->color_correction_view_);
} }
const char* GetDetailedViewClassName() {
return detailed_menu_->GetClassName();
}
void SetUpKioskSession() { void SetUpKioskSession() {
auto* session_controller = Shell::Get()->session_controller(); auto* session_controller = Shell::Get()->session_controller();
SessionInfo info; SessionInfo info;

@@ -238,7 +238,7 @@ TEST_F(DictationBubbleControllerTest, DictationHintViewClassHasTheRightName) {
Show(DictationBubbleIconType::kStandby, std::optional<std::u16string>(), Show(DictationBubbleIconType::kStandby, std::optional<std::u16string>(),
std::optional<std::vector<DictationBubbleHintType>>()); std::optional<std::vector<DictationBubbleHintType>>());
EXPECT_TRUE(GetView()); EXPECT_TRUE(GetView());
EXPECT_STREQ(GetHintView()->GetClassName(), "DictationHintView"); EXPECT_EQ(GetHintView()->GetClassName(), "DictationHintView");
HideAndCheckExpectations(); HideAndCheckExpectations();
} }

@@ -276,8 +276,8 @@ class UnifiedAudioDetailedViewControllerTest : public AshTestBase {
slider_button->GetViewAccessibility().IsAccessibilityFocusable()); slider_button->GetViewAccessibility().IsAccessibilityFocusable());
slider->RequestFocus(); slider->RequestFocus();
EXPECT_STREQ(slider->GetFocusManager()->GetFocusedView()->GetClassName(), EXPECT_EQ(slider->GetFocusManager()->GetFocusedView()->GetClassName(),
"QuickSettingsSlider"); "QuickSettingsSlider");
// Check the accessibility role of QuickSettingsSlider. // Check the accessibility role of QuickSettingsSlider.
ui::AXNodeData node_data; ui::AXNodeData node_data;
slider->GetFocusManager() slider->GetFocusManager()

@@ -80,13 +80,13 @@ class UnifiedVolumeViewTest : public AshTestBase {
// `LiveCaption` button, and a drill-in button that leads to // `LiveCaption` button, and a drill-in button that leads to
// `AudioDetailedView`. // `AudioDetailedView`.
TEST_F(UnifiedVolumeViewTest, SliderButtonComponents) { TEST_F(UnifiedVolumeViewTest, SliderButtonComponents) {
EXPECT_STREQ(unified_volume_view()->children()[0]->GetClassName(), EXPECT_EQ(unified_volume_view()->children()[0]->GetClassName(),
"QuickSettingsSlider"); "QuickSettingsSlider");
// TODO(b/257151067): Updates the a11y name id and tooltip text. // TODO(b/257151067): Updates the a11y name id and tooltip text.
auto* live_caption_button = auto* live_caption_button =
static_cast<IconButton*>(unified_volume_view()->children()[1]); static_cast<IconButton*>(unified_volume_view()->children()[1]);
EXPECT_STREQ(live_caption_button->GetClassName(), "IconButton"); EXPECT_EQ(live_caption_button->GetClassName(), "IconButton");
EXPECT_EQ(live_caption_button->GetViewAccessibility().GetCachedName(), EXPECT_EQ(live_caption_button->GetViewAccessibility().GetCachedName(),
l10n_util::GetStringFUTF16( l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_LIVE_CAPTION_TOGGLE_TOOLTIP, IDS_ASH_STATUS_TRAY_LIVE_CAPTION_TOGGLE_TOOLTIP,
@@ -97,7 +97,7 @@ TEST_F(UnifiedVolumeViewTest, SliderButtonComponents) {
auto* audio_subpage_drill_in_button = auto* audio_subpage_drill_in_button =
static_cast<IconButton*>(unified_volume_view()->children()[2]); static_cast<IconButton*>(unified_volume_view()->children()[2]);
EXPECT_STREQ(audio_subpage_drill_in_button->GetClassName(), "IconButton"); EXPECT_EQ(audio_subpage_drill_in_button->GetClassName(), "IconButton");
EXPECT_EQ( EXPECT_EQ(
audio_subpage_drill_in_button->GetViewAccessibility().GetCachedName(), audio_subpage_drill_in_button->GetViewAccessibility().GetCachedName(),
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO)); l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO));
@@ -234,11 +234,11 @@ TEST_F(UnifiedVolumeViewTest, SliderFocusToggleMute) {
// Presses the tab key to activate the focus on the bubble. // Presses the tab key to activate the focus on the bubble.
generator->PressAndReleaseKey(ui::KeyboardCode::VKEY_TAB); generator->PressAndReleaseKey(ui::KeyboardCode::VKEY_TAB);
slider()->RequestFocus(); slider()->RequestFocus();
EXPECT_STREQ(unified_volume_view() EXPECT_EQ(unified_volume_view()
->GetFocusManager() ->GetFocusManager()
->GetFocusedView() ->GetFocusedView()
->GetClassName(), ->GetClassName(),
"QuickSettingsSlider"); "QuickSettingsSlider");
const bool is_muted = CrasAudioHandler::Get()->IsOutputMuted(); const bool is_muted = CrasAudioHandler::Get()->IsOutputMuted();
// Presses the enter key when focused on the slider will toggle mute state. // Presses the enter key when focused on the slider will toggle mute state.

@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/system/bluetooth/bluetooth_device_list_controller_impl.h"
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/bluetooth/bluetooth_detailed_view.h" #include "ash/system/bluetooth/bluetooth_detailed_view.h"
#include "ash/system/bluetooth/bluetooth_device_list_controller_impl.h"
#include "ash/system/bluetooth/bluetooth_device_list_item_view.h" #include "ash/system/bluetooth/bluetooth_device_list_item_view.h"
#include "ash/system/bluetooth/fake_bluetooth_detailed_view.h" #include "ash/system/bluetooth/fake_bluetooth_detailed_view.h"
#include "ash/system/tray/tri_view.h" #include "ash/system/tray/tri_view.h"
@@ -17,6 +16,7 @@
#include "chromeos/ash/services/bluetooth_config/public/mojom/cros_bluetooth_config.mojom.h" #include "chromeos/ash/services/bluetooth_config/public/mojom/cros_bluetooth_config.mojom.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/view_utils.h"
namespace ash { namespace ash {
@@ -154,11 +154,10 @@ class BluetoothDeviceListControllerTest : public AshTestBase {
private: private:
const TriView* FindSubHeaderWithText(const std::u16string& text) { const TriView* FindSubHeaderWithText(const std::u16string& text) {
for (const views::View* view : device_list()->children()) { for (const views::View* view : device_list()->children()) {
if (std::strcmp("TriView", view->GetClassName())) if (const auto* sub_header = views::AsViewClass<TriView>(view);
continue; sub_header && GetSubHeaderText(sub_header) == text) {
const TriView* sub_header = static_cast<const TriView*>(view);
if (GetSubHeaderText(sub_header) == text)
return sub_header; return sub_header;
}
} }
return nullptr; return nullptr;
} }

@@ -284,9 +284,8 @@ void BluetoothDeviceListItemView::UpdateMultipleBatteryView(
// Remove battery view if it is not a multiple battery view. // Remove battery view if it is not a multiple battery view.
if (!sub_row()->children().empty()) { if (!sub_row()->children().empty()) {
DCHECK(sub_row()->children().size() == 1); DCHECK(sub_row()->children().size() == 1);
if (std::string_view(sub_row()->children().at(0)->GetClassName()) != if (sub_row()->children().at(0)->GetClassName() !=
std::string_view( BluetoothDeviceListItemMultipleBatteryView::kViewClassName) {
BluetoothDeviceListItemMultipleBatteryView::kViewClassName)) {
sub_row()->RemoveAllChildViews(); sub_row()->RemoveAllChildViews();
} }
} }
@@ -312,8 +311,8 @@ void BluetoothDeviceListItemView::UpdateSingleBatteryView(
// Remove battery view if it is not a single battery view. // Remove battery view if it is not a single battery view.
if (!sub_row()->children().empty()) { if (!sub_row()->children().empty()) {
DCHECK(sub_row()->children().size() == 1); DCHECK(sub_row()->children().size() == 1);
if (std::string_view(sub_row()->children().at(0)->GetClassName()) != if (sub_row()->children().at(0)->GetClassName() !=
std::string_view(BluetoothDeviceListItemBatteryView::kViewClassName)) { BluetoothDeviceListItemBatteryView::kViewClassName) {
sub_row()->RemoveAllChildViews(); sub_row()->RemoveAllChildViews();
} }
} }

@@ -137,7 +137,7 @@ class BluetoothFeaturePodControllerTest
const views::View::Views& children = container->children(); const views::View::Views& children = container->children();
if (is_showing) { if (is_showing) {
EXPECT_EQ(1u, children.size()); EXPECT_EQ(1u, children.size());
EXPECT_STREQ("BluetoothDetailedViewImpl", children.at(0)->GetClassName()); EXPECT_EQ("BluetoothDetailedViewImpl", children.at(0)->GetClassName());
return; return;
} }
EXPECT_EQ(0u, children.size()); EXPECT_EQ(0u, children.size());

@@ -60,14 +60,13 @@ TEST_F(DisplayDetailedViewTest, ScrollContentChildren) {
views::View* tile_container = GetTileContainer(&detailed_view); views::View* tile_container = GetTileContainer(&detailed_view);
ASSERT_TRUE(tile_container); ASSERT_TRUE(tile_container);
ASSERT_EQ(tile_container->children().size(), 2u); ASSERT_EQ(tile_container->children().size(), 2u);
EXPECT_STREQ(tile_container->children()[0]->GetClassName(), "FeatureTile"); EXPECT_EQ(tile_container->children()[0]->GetClassName(), "FeatureTile");
EXPECT_STREQ(tile_container->children()[1]->GetClassName(), "FeatureTile"); EXPECT_EQ(tile_container->children()[1]->GetClassName(), "FeatureTile");
// The second children of scroll content is the `UnifiedBrightnessView`. // The second children of scroll content is the `UnifiedBrightnessView`.
views::View* unified_brightness_view = views::View* unified_brightness_view =
scroll_content->GetViewByID(VIEW_ID_QS_DISPLAY_BRIGHTNESS_SLIDER); scroll_content->GetViewByID(VIEW_ID_QS_DISPLAY_BRIGHTNESS_SLIDER);
EXPECT_STREQ(unified_brightness_view->GetClassName(), EXPECT_EQ(unified_brightness_view->GetClassName(), "UnifiedBrightnessView");
"UnifiedBrightnessView");
} }
TEST_F(DisplayDetailedViewTest, FeatureTileVisibility) { TEST_F(DisplayDetailedViewTest, FeatureTileVisibility) {

@@ -127,13 +127,13 @@ TEST_F(UnifiedBrightnessViewTest, SliderButtonClickThrough) {
// `NightLight` button, and a drill-in button that leads to the display subpage. // `NightLight` button, and a drill-in button that leads to the display subpage.
TEST_F(UnifiedBrightnessViewTest, SliderButtonComponents) { TEST_F(UnifiedBrightnessViewTest, SliderButtonComponents) {
EXPECT_EQ(unified_brightness_view()->children().size(), 3u); EXPECT_EQ(unified_brightness_view()->children().size(), 3u);
EXPECT_STREQ(unified_brightness_view()->children()[0]->GetClassName(), EXPECT_EQ(unified_brightness_view()->children()[0]->GetClassName(),
"QuickSettingsSlider"); "QuickSettingsSlider");
// TODO(b/257151067): Updates the a11y name id and tooltip text. // TODO(b/257151067): Updates the a11y name id and tooltip text.
auto* night_light_button = auto* night_light_button =
static_cast<IconButton*>(unified_brightness_view()->children()[1]); static_cast<IconButton*>(unified_brightness_view()->children()[1]);
EXPECT_STREQ(night_light_button->GetClassName(), "IconButton"); EXPECT_EQ(night_light_button->GetClassName(), "IconButton");
EXPECT_EQ(night_light_button->GetViewAccessibility().GetCachedName(), EXPECT_EQ(night_light_button->GetViewAccessibility().GetCachedName(),
l10n_util::GetStringFUTF16( l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_NIGHT_LIGHT_TOGGLE_TOOLTIP, IDS_ASH_STATUS_TRAY_NIGHT_LIGHT_TOGGLE_TOOLTIP,
@@ -144,7 +144,7 @@ TEST_F(UnifiedBrightnessViewTest, SliderButtonComponents) {
auto* display_subpage_drill_in_button = auto* display_subpage_drill_in_button =
static_cast<IconButton*>(unified_brightness_view()->children()[2]); static_cast<IconButton*>(unified_brightness_view()->children()[2]);
EXPECT_STREQ(display_subpage_drill_in_button->GetClassName(), "IconButton"); EXPECT_EQ(display_subpage_drill_in_button->GetClassName(), "IconButton");
EXPECT_EQ( EXPECT_EQ(
display_subpage_drill_in_button->GetViewAccessibility().GetCachedName(), display_subpage_drill_in_button->GetViewAccessibility().GetCachedName(),
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
@@ -162,8 +162,8 @@ TEST_F(UnifiedBrightnessViewTest, SliderButtonComponents) {
// `QuickSettingsSlider`. // `QuickSettingsSlider`.
TEST_F(UnifiedBrightnessViewTest, SliderComponent) { TEST_F(UnifiedBrightnessViewTest, SliderComponent) {
EXPECT_EQ(brightness_slider()->children().size(), 1u); EXPECT_EQ(brightness_slider()->children().size(), 1u);
EXPECT_STREQ(brightness_slider()->children()[0]->GetClassName(), EXPECT_EQ(brightness_slider()->children()[0]->GetClassName(),
"QuickSettingsSlider"); "QuickSettingsSlider");
} }
// Tests the slider icon matches the slider level. // Tests the slider icon matches the slider level.

@@ -101,7 +101,7 @@ TEST_F(CastDetailedViewTest, ViewsCreatedForCastDevices) {
for (views::View* view : GetDeviceViews()) { for (views::View* view : GetDeviceViews()) {
// Device views are children of the rounded container. // Device views are children of the rounded container.
EXPECT_STREQ(view->parent()->GetClassName(), "RoundedContainer"); EXPECT_EQ(view->parent()->GetClassName(), "RoundedContainer");
// Device views don't have a "stop casting" button by default. // Device views don't have a "stop casting" button by default.
ASSERT_TRUE(views::IsViewClass<HoverHighlightView>(view)); ASSERT_TRUE(views::IsViewClass<HoverHighlightView>(view));

@@ -35,6 +35,7 @@
#include "ash/system/unified/unified_system_tray.h" #include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h" #include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/containers/contains.h"
#include "base/i18n/time_formatting.h" #include "base/i18n/time_formatting.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
@@ -936,8 +937,7 @@ TEST_F(FocusModeDetailedViewTest,
ASSERT_TRUE(hover_highlight_view); ASSERT_TRUE(hover_highlight_view);
ASSERT_TRUE(right_view); ASSERT_TRUE(right_view);
ASSERT_TRUE(std::string(right_view->GetClassName()).find("Button") != ASSERT_TRUE(base::Contains(right_view->GetClassName(), "Button"));
std::string::npos);
hover_highlight_view->GetViewAccessibility().GetAccessibleNodeData(&data); hover_highlight_view->GetViewAccessibility().GetAccessibleNodeData(&data);
EXPECT_EQ(data.GetDefaultActionVerb(), ax::mojom::DefaultActionVerb::kClick); EXPECT_EQ(data.GetDefaultActionVerb(), ax::mojom::DefaultActionVerb::kClick);

@@ -241,8 +241,7 @@ class NetworkFeaturePodControllerTest : public AshTestBase {
children = quick_settings_view()->detailed_view_container()->children(); children = quick_settings_view()->detailed_view_container()->children();
ASSERT_EQ(1u, children.size()); ASSERT_EQ(1u, children.size());
EXPECT_STREQ("NetworkDetailedNetworkViewImpl", EXPECT_EQ("NetworkDetailedNetworkViewImpl", children.at(0)->GetClassName());
children.at(0)->GetClassName());
} }
void CheckSignalStrengthSubLabel( void CheckSignalStrengthSubLabel(

@@ -380,8 +380,8 @@ class NetworkListViewControllerTest : public AshTestBase,
size_t index, size_t index,
const std::optional<std::string>& guid) { const std::optional<std::string>& guid) {
ASSERT_GT(network_list(type)->children().size(), index); ASSERT_GT(network_list(type)->children().size(), index);
EXPECT_STREQ(network_list(type)->children().at(index)->GetClassName(), EXPECT_EQ(network_list(type)->children().at(index)->GetClassName(),
kNetworkListNetworkItemView); kNetworkListNetworkItemView);
const NetworkStatePropertiesPtr& network = const NetworkStatePropertiesPtr& network =
static_cast<NetworkListNetworkItemView*>( static_cast<NetworkListNetworkItemView*>(
@@ -395,8 +395,8 @@ class NetworkListViewControllerTest : public AshTestBase,
} }
bool GetNetworkListItemIsEnabled(NetworkType type, size_t index) { bool GetNetworkListItemIsEnabled(NetworkType type, size_t index) {
EXPECT_STREQ(network_list(type)->children().at(index)->GetClassName(), EXPECT_EQ(network_list(type)->children().at(index)->GetClassName(),
kNetworkListNetworkItemView); kNetworkListNetworkItemView);
NetworkListNetworkItemView* network = NetworkListNetworkItemView* network =
static_cast<NetworkListNetworkItemView*>( static_cast<NetworkListNetworkItemView*>(

@@ -165,11 +165,11 @@ TEST_F(VpnDetailedViewTest, ParentContainerConfiguration) {
AddVpnProvidersAndNetwork(); AddVpnProvidersAndNetwork();
for (const views::View* view : GetProviderViews()) { for (const views::View* view : GetProviderViews()) {
const views::View* parent = view->parent(); const views::View* parent = view->parent();
EXPECT_STREQ(parent->GetClassName(), "RoundedContainer"); EXPECT_EQ(parent->GetClassName(), "RoundedContainer");
} }
for (const views::View* view : GetNetworkViews()) { for (const views::View* view : GetNetworkViews()) {
const views::View* parent = view->parent(); const views::View* parent = view->parent();
EXPECT_STREQ(parent->GetClassName(), "RoundedContainer"); EXPECT_EQ(parent->GetClassName(), "RoundedContainer");
} }
} }

@@ -193,7 +193,7 @@ TEST_F(CameraRollThumbnailTest, ViewLayout) {
EXPECT_EQ(camera_roll_thumbnail()->GetFocusBehavior(), EXPECT_EQ(camera_roll_thumbnail()->GetFocusBehavior(),
CameraRollThumbnail::FocusBehavior::ALWAYS); CameraRollThumbnail::FocusBehavior::ALWAYS);
EXPECT_STREQ("CameraRollThumbnail", camera_roll_thumbnail()->GetClassName()); EXPECT_EQ("CameraRollThumbnail", camera_roll_thumbnail()->GetClassName());
} }
TEST_F(CameraRollThumbnailTest, ImageThumbnail) { TEST_F(CameraRollThumbnailTest, ImageThumbnail) {

@@ -195,12 +195,10 @@ void CalendarEventListView::Layout(PassKey) {
// to the current or next event. Otherwise `scroll_view_` won't scroll with // to the current or next event. Otherwise `scroll_view_` won't scroll with
// the focus change. // the focus change.
if (GetFocusManager() && GetFocusManager()->GetFocusedView()) { if (GetFocusManager() && GetFocusManager()->GetFocusedView()) {
const auto focused_view_class_name = if (const auto focused_view_class_name =
std::string_view(GetFocusManager()->GetFocusedView()->GetClassName()); GetFocusManager()->GetFocusedView()->GetClassName();
if (focused_view_class_name == focused_view_class_name == CalendarEventListItemView::kViewClassName ||
std::string_view(CalendarEventListItemView::kViewClassName) || focused_view_class_name == PillButton::kViewClassName) {
focused_view_class_name ==
std::string_view(PillButton::kViewClassName)) {
return; return;
} }
} }

@@ -559,8 +559,8 @@ TEST_F(CalendarUpNextViewTest, ShouldFocusViewsInCorrectOrder_WhenPressingTab) {
auto* first_item = GetContentsView()->children()[0].get(); auto* first_item = GetContentsView()->children()[0].get();
ASSERT_TRUE(first_item); ASSERT_TRUE(first_item);
EXPECT_EQ(first_item, focus_manager->GetFocusedView()); EXPECT_EQ(first_item, focus_manager->GetFocusedView());
EXPECT_STREQ("CalendarEventListItemView", EXPECT_EQ("CalendarEventListItemView",
focus_manager->GetFocusedView()->GetClassName()); focus_manager->GetFocusedView()->GetClassName());
// Next, the "Join" button should be focused. // Next, the "Join" button should be focused.
PressTab(); PressTab();
@@ -572,8 +572,8 @@ TEST_F(CalendarUpNextViewTest, ShouldFocusViewsInCorrectOrder_WhenPressingTab) {
auto* second_item = GetContentsView()->children()[1].get(); auto* second_item = GetContentsView()->children()[1].get();
ASSERT_TRUE(second_item); ASSERT_TRUE(second_item);
EXPECT_EQ(second_item, focus_manager->GetFocusedView()); EXPECT_EQ(second_item, focus_manager->GetFocusedView());
EXPECT_STREQ("CalendarEventListItemView", EXPECT_EQ("CalendarEventListItemView",
focus_manager->GetFocusedView()->GetClassName()); focus_manager->GetFocusedView()->GetClassName());
// Next, the second event list item view "Join" button should be focused. // Next, the second event list item view "Join" button should be focused.
PressTab(); PressTab();
@@ -593,8 +593,8 @@ TEST_F(CalendarUpNextViewTest, ShouldFocusViewsInCorrectOrder_WhenPressingTab) {
// Going back again, the second event list item view should be focused. // Going back again, the second event list item view should be focused.
PressShiftTab(); PressShiftTab();
EXPECT_EQ(second_item, focus_manager->GetFocusedView()); EXPECT_EQ(second_item, focus_manager->GetFocusedView());
EXPECT_STREQ("CalendarEventListItemView", EXPECT_EQ("CalendarEventListItemView",
focus_manager->GetFocusedView()->GetClassName()); focus_manager->GetFocusedView()->GetClassName());
} }
// Add unittest for the fix of this bug: b/286596205. // Add unittest for the fix of this bug: b/286596205.
@@ -615,16 +615,16 @@ TEST_F(CalendarUpNextViewTest, ShouldPreserveFocusAfterRefreshEvent) {
auto* first_item = GetContentsView()->children()[0].get(); auto* first_item = GetContentsView()->children()[0].get();
ASSERT_TRUE(first_item); ASSERT_TRUE(first_item);
EXPECT_EQ(first_item, focus_manager->GetFocusedView()); EXPECT_EQ(first_item, focus_manager->GetFocusedView());
EXPECT_STREQ("CalendarEventListItemView", EXPECT_EQ("CalendarEventListItemView",
focus_manager->GetFocusedView()->GetClassName()); focus_manager->GetFocusedView()->GetClassName());
up_next_view()->RefreshEvents(); up_next_view()->RefreshEvents();
// After refresh the events, the first event list item view should still be // After refresh the events, the first event list item view should still be
// focused. // focused.
EXPECT_EQ(first_item, focus_manager->GetFocusedView()); EXPECT_EQ(first_item, focus_manager->GetFocusedView());
EXPECT_STREQ("CalendarEventListItemView", EXPECT_EQ("CalendarEventListItemView",
focus_manager->GetFocusedView()->GetClassName()); focus_manager->GetFocusedView()->GetClassName());
} }
class CalendarUpNextViewAnimationTest : public CalendarUpNextViewTest { class CalendarUpNextViewAnimationTest : public CalendarUpNextViewTest {

@@ -510,7 +510,7 @@ CalendarView::CalendarView(bool use_glanceables_container_style)
// Focusable nodes must have an accessible name and valid role. // Focusable nodes must have an accessible name and valid role.
// TODO(crbug.com/1348930): Review the accessible name and role. // TODO(crbug.com/1348930): Review the accessible name and role.
GetViewAccessibility().SetRole(ax::mojom::Role::kPane); GetViewAccessibility().SetRole(ax::mojom::Role::kPane);
GetViewAccessibility().SetName(GetClassName(), GetViewAccessibility().SetName(std::string(GetClassName()),
ax::mojom::NameFrom::kAttribute); ax::mojom::NameFrom::kAttribute);
views::View* calendar_header_view = nullptr; views::View* calendar_header_view = nullptr;
@@ -572,7 +572,7 @@ CalendarView::CalendarView(bool use_glanceables_container_style)
// TODO(crbug.com/1348930): Review the accessible name and role. // TODO(crbug.com/1348930): Review the accessible name and role.
content_view_->GetViewAccessibility().SetRole(ax::mojom::Role::kPane); content_view_->GetViewAccessibility().SetRole(ax::mojom::Role::kPane);
content_view_->GetViewAccessibility().SetName( content_view_->GetViewAccessibility().SetName(
GetClassName(), ax::mojom::NameFrom::kAttribute); std::string(GetClassName()), ax::mojom::NameFrom::kAttribute);
content_view_->SetFocusBehavior(FocusBehavior::ALWAYS); content_view_->SetFocusBehavior(FocusBehavior::ALWAYS);
// Set up layer for animations. // Set up layer for animations.

@@ -603,8 +603,8 @@ TEST_F(CalendarViewTest, HeaderFocusing) {
auto* focus_manager = calendar_view()->GetFocusManager(); auto* focus_manager = calendar_view()->GetFocusManager();
// Todays DateCellView should be focused on open. // Todays DateCellView should be focused on open.
EXPECT_STREQ(focus_manager->GetFocusedView()->GetClassName(), EXPECT_EQ(focus_manager->GetFocusedView()->GetClassName(),
"CalendarDateCellView"); "CalendarDateCellView");
EXPECT_EQ( EXPECT_EQ(
static_cast<const views::LabelButton*>(focus_manager->GetFocusedView()) static_cast<const views::LabelButton*>(focus_manager->GetFocusedView())
->GetText(), ->GetText(),
@@ -884,7 +884,7 @@ TEST_F(CalendarViewTest, FocusAfterClosingEventListView) {
close_button()); close_button());
PressEnter(); PressEnter();
EXPECT_STREQ( EXPECT_EQ(
calendar_view()->GetFocusManager()->GetFocusedView()->GetClassName(), calendar_view()->GetFocusManager()->GetFocusedView()->GetClassName(),
"CalendarDateCellView"); "CalendarDateCellView");
} }
@@ -1378,7 +1378,6 @@ TEST_F(CalendarViewTest, AdminDisabledTest) {
auto* focus_manager = calendar_view()->GetFocusManager(); auto* focus_manager = calendar_view()->GetFocusManager();
// Todays `DateCellView` should be focused on open. // Todays `DateCellView` should be focused on open.
ASSERT_TRUE(focus_manager->GetFocusedView()->GetClassName());
ASSERT_TRUE(focus_manager->GetFocusedView()); ASSERT_TRUE(focus_manager->GetFocusedView());
// Moves to the next focusable view - managed icon button. // Moves to the next focusable view - managed icon button.

@@ -17,6 +17,7 @@
#include "ash/system/tray/tri_view.h" #include "ash/system/tray/tri_view.h"
#include "ash/system/tray/unfocusable_label.h" #include "ash/system/tray/unfocusable_label.h"
#include "ash/system/tray/view_click_listener.h" #include "ash/system/tray/view_click_listener.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h" #include "base/functional/bind.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
@@ -320,12 +321,10 @@ void HoverHighlightView::OnEnabledChanged() {
} }
void HoverHighlightView::SetAndUpdateAccessibleDefaultAction() { void HoverHighlightView::SetAndUpdateAccessibleDefaultAction() {
SetDefaultActionVerb( SetDefaultActionVerb((right_view_ && right_view_->GetVisible() &&
(right_view_ && right_view_->GetVisible() && base::Contains(right_view_->GetClassName(), "Button"))
std::string(right_view_->GetClassName()).find("Button") != ? ax::mojom::DefaultActionVerb::kClick
std::string::npos) : ax::mojom::DefaultActionVerb::kPress);
? ax::mojom::DefaultActionVerb::kClick
: ax::mojom::DefaultActionVerb::kPress);
UpdateAccessibleDefaultActionVerb(); UpdateAccessibleDefaultActionVerb();
} }

@@ -442,7 +442,7 @@ TEST_P(DateTrayTest, DontActivateBubbleIfShownByTap) {
EXPECT_TRUE( EXPECT_TRUE(
GetGlanceableTrayBubble()->GetCalendarView()->Contains(focused_view)); GetGlanceableTrayBubble()->GetCalendarView()->Contains(focused_view));
} }
EXPECT_STREQ("CalendarDateCellView", focused_view->GetClassName()); EXPECT_EQ("CalendarDateCellView", focused_view->GetClassName());
} }
TEST_P(DateTrayTest, ActivateBubbleIfShownByKeyboard) { TEST_P(DateTrayTest, ActivateBubbleIfShownByKeyboard) {
@@ -477,7 +477,7 @@ TEST_P(DateTrayTest, ActivateBubbleIfShownByKeyboard) {
EXPECT_TRUE( EXPECT_TRUE(
GetGlanceableTrayBubble()->GetCalendarView()->Contains(focused_view)); GetGlanceableTrayBubble()->GetCalendarView()->Contains(focused_view));
} }
EXPECT_STREQ("CalendarDateCellView", focused_view->GetClassName()); EXPECT_EQ("CalendarDateCellView", focused_view->GetClassName());
} }
// Tests the behavior when clicking on different areas. // Tests the behavior when clicking on different areas.
@@ -632,11 +632,11 @@ TEST_P(DateTrayTest, RendersClassroomBubblesForActiveRoles) {
// Both calendar and the `TimeManagementContainer` should be rendered in // Both calendar and the `TimeManagementContainer` should be rendered in
// `GlanceableTrayBubbleView`. // `GlanceableTrayBubbleView`.
EXPECT_EQ(GetGlanceableTrayBubble()->GetBubbleView()->children().size(), 2u); EXPECT_EQ(GetGlanceableTrayBubble()->GetBubbleView()->children().size(), 2u);
EXPECT_STREQ("TimeManagementContainer", GetGlanceableTrayBubble() EXPECT_EQ("TimeManagementContainer", GetGlanceableTrayBubble()
->GetBubbleView() ->GetBubbleView()
->children() ->children()
.at(0) .at(0)
->GetClassName()); ->GetClassName());
} }
TEST_P(DateTrayTest, AccessibleName) { TEST_P(DateTrayTest, AccessibleName) {

@@ -507,8 +507,8 @@ TEST_P(UnifiedSystemTrayTest, CalendarAcceleratorFocusesDateCell) {
auto* focus_manager = auto* focus_manager =
GetUnifiedSystemTrayBubble()->GetBubbleWidget()->GetFocusManager(); GetUnifiedSystemTrayBubble()->GetBubbleWidget()->GetFocusManager();
EXPECT_TRUE(focus_manager->GetFocusedView()); EXPECT_TRUE(focus_manager->GetFocusedView());
EXPECT_STREQ(focus_manager->GetFocusedView()->GetClassName(), EXPECT_EQ(focus_manager->GetFocusedView()->GetClassName(),
"CalendarDateCellView"); "CalendarDateCellView");
} }
// Tests that using functional keys to change brightness/volume when the // Tests that using functional keys to change brightness/volume when the

@@ -4,6 +4,7 @@
#include "chrome/browser/ash/notifications/echo_dialog_view.h" #include "chrome/browser/ash/notifications/echo_dialog_view.h"
#include "base/containers/contains.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ash/notifications/echo_dialog_listener.h" #include "chrome/browser/ash/notifications/echo_dialog_listener.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
@@ -12,6 +13,7 @@
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
#include "ui/views/test/views_test_base.h" #include "ui/views/test/views_test_base.h"
#include "ui/views/view_utils.h"
namespace ash { namespace ash {
@@ -34,14 +36,11 @@ class TestEchoDialogListener : public EchoDialogListener {
}; };
bool IsLabelWithText(const views::View* view, const std::u16string& text) { bool IsLabelWithText(const views::View* view, const std::u16string& text) {
const char* class_name = view->GetClassName(); if (const auto* label = views::AsViewClass<views::Label>(view)) {
if (!strcmp(class_name, "Label")) { return base::Contains(label->GetText(), text);
auto* label = static_cast<const views::Label*>(view);
return label->GetText().find(text) != label->GetText().npos;
} }
if (!strcmp(class_name, "StyledLabel")) { if (const auto* styled_label = views::AsViewClass<views::StyledLabel>(view)) {
auto* styled_label = static_cast<const views::StyledLabel*>(view); return base::Contains(styled_label->GetText(), text);
return styled_label->GetText().find(text) != styled_label->GetText().npos;
} }
return false; return false;
} }

@@ -1731,8 +1731,7 @@ IN_PROC_BROWSER_TEST_F(DesksClientTest, SystemUICaptureIncognitoBrowserTest) {
ash::GetSavedDeskDialogAcceptButton(); ash::GetSavedDeskDialogAcceptButton();
ASSERT_TRUE(dialog_accept_button); ASSERT_TRUE(dialog_accept_button);
// MaterialNext uses PillButton instead of dialog buttons. // MaterialNext uses PillButton instead of dialog buttons.
if (std::string_view(dialog_accept_button->GetClassName()) == if (dialog_accept_button->GetClassName() == ash::PillButton::kViewClassName) {
std::string_view(ash::PillButton::kViewClassName)) {
ClickView(dialog_accept_button); ClickView(dialog_accept_button);
} else { } else {
// Use a key press to accept the dialog instead of a click as // Use a key press to accept the dialog instead of a click as

@@ -180,9 +180,7 @@ TEST_F(AddressEditorViewTest, WholeFormValidationState) {
TEST_F(AddressEditorViewTest, InitialFocusViewPointsToCountryCombobox) { TEST_F(AddressEditorViewTest, InitialFocusViewPointsToCountryCombobox) {
EXPECT_NE(view_->initial_focus_view(), nullptr); EXPECT_NE(view_->initial_focus_view(), nullptr);
EXPECT_EQ( EXPECT_EQ(view_->initial_focus_view()->GetClassName(), "Combobox");
std::string(view_->initial_focus_view()->GetClassMetaData()->type_name()),
"Combobox");
} }
TEST_F(AddressEditorViewTest, FocusIsNotLostAfterEditorContentChange) { TEST_F(AddressEditorViewTest, FocusIsNotLostAfterEditorContentChange) {

@@ -251,10 +251,7 @@ TEST_F(EditAddressProfileViewTest, GetInitiallyFocusedView) {
dialog->ShowForWebContents(test_web_contents()); dialog->ShowForWebContents(test_web_contents());
EXPECT_NE(dialog->GetInitiallyFocusedView(), nullptr); EXPECT_NE(dialog->GetInitiallyFocusedView(), nullptr);
EXPECT_EQ( EXPECT_EQ(dialog->GetInitiallyFocusedView()->GetClassName(), "Combobox");
std::string(
dialog->GetInitiallyFocusedView()->GetClassMetaData()->type_name()),
"Combobox");
} }
} // namespace autofill } // namespace autofill

@@ -77,8 +77,7 @@ TEST_F(PopupSearchBarViewTest, SetsFocusOnTextfield) {
views::View* focused_field = widget().GetFocusManager()->GetFocusedView(); views::View* focused_field = widget().GetFocusManager()->GetFocusedView();
ASSERT_NE(focused_field, nullptr); ASSERT_NE(focused_field, nullptr);
EXPECT_EQ(focused_field->GetClassMetaData()->type_name(), EXPECT_EQ(focused_field->GetClassName(), "Textfield");
std::string("Textfield"));
} }
TEST_F(PopupSearchBarViewTest, OnFocusLostCalled) { TEST_F(PopupSearchBarViewTest, OnFocusLostCalled) {

@@ -24,7 +24,7 @@
namespace { namespace {
bool IsDesktopMediaTabList(views::View* view) { bool IsDesktopMediaTabList(views::View* view) {
return !strcmp(view->GetClassName(), "DesktopMediaTabList"); return view->GetClassName() == "DesktopMediaTabList";
} }
} // namespace } // namespace

@@ -141,8 +141,7 @@ class SuppressBubbleSettingRow : public views::View,
views::ViewTargeterDelegate::TargetForRect(root, rect); views::ViewTargeterDelegate::TargetForRect(root, rect);
// Links should operate as expected, but all other gestures on this view // Links should operate as expected, but all other gestures on this view
// should be forwarded to the checkbox. // should be forwarded to the checkbox.
if (std::string_view(target->GetClassName()) == if (target->GetClassName() == views::LinkFragment::kViewClassName) {
std::string_view(views::LinkFragment::kViewClassName)) {
return target; return target;
} }

@@ -762,7 +762,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogWithWithholdPermissionsUI,
const views::View* const extra_view = delegate_view->GetExtraView(); const views::View* const extra_view = delegate_view->GetExtraView();
EXPECT_TRUE(extra_view); EXPECT_TRUE(extra_view);
EXPECT_EQ("Checkbox", std::string(extra_view->GetClassName())); EXPECT_EQ("Checkbox", extra_view->GetClassName());
CloseAndWait(delegate_view->GetWidget()); CloseAndWait(delegate_view->GetWidget());
} }

@@ -267,7 +267,7 @@ class FindBarViewsUiTest : public InteractiveBrowserTest {
focused->GetProperty(views::kElementIdentifierKey)) { focused->GetProperty(views::kElementIdentifierKey)) {
return id.GetName(); return id.GetName();
} }
return focused->GetClassName(); return std::string(focused->GetClassName());
} }
return "(none)"; return "(none)";
}), }),

@@ -102,8 +102,7 @@ void BrowserFrameViewLinuxNative::MaybeUpdateCachedFrameButtonImages() {
views::Button::ButtonState button_state = views::Button::ButtonState button_state =
static_cast<views::Button::ButtonState>(state); static_cast<views::Button::ButtonState>(state);
views::Button* button = GetButtonFromDisplayType(type); views::Button* button = GetButtonFromDisplayType(type);
DCHECK_EQ(std::string(views::ImageButton::kViewClassName), DCHECK_EQ(views::ImageButton::kViewClassName, button->GetClassName());
button->GetClassName());
static_cast<views::ImageButton*>(button)->SetImageModel( static_cast<views::ImageButton*>(button)->SetImageModel(
button_state, button_state,
ui::ImageModel::FromImageSkia(nav_button_provider_->GetImage( ui::ImageModel::FromImageSkia(nav_button_provider_->GetImage(

@@ -630,7 +630,7 @@ void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
if (GetFrameButtonStyle() == FrameButtonStyle::kMdButton) { if (GetFrameButtonStyle() == FrameButtonStyle::kMdButton) {
for (views::Button* button : for (views::Button* button :
{minimize_button_, maximize_button_, restore_button_, close_button_}) { {minimize_button_, maximize_button_, restore_button_, close_button_}) {
DCHECK_EQ(std::string(views::FrameCaptionButton::kViewClassName), DCHECK_EQ(views::FrameCaptionButton::kViewClassName,
button->GetClassName()); button->GetClassName());
views::FrameCaptionButton* frame_caption_button = views::FrameCaptionButton* frame_caption_button =
static_cast<views::FrameCaptionButton*>(button); static_cast<views::FrameCaptionButton*>(button);

@@ -485,7 +485,7 @@ void OpaqueBrowserFrameViewLayout::SetBoundsForButton(
gfx::Size button_size = button->GetPreferredSize(); gfx::Size button_size = button->GetPreferredSize();
if (delegate_->GetFrameButtonStyle() == if (delegate_->GetFrameButtonStyle() ==
OpaqueBrowserFrameViewLayoutDelegate::FrameButtonStyle::kMdButton) { OpaqueBrowserFrameViewLayoutDelegate::FrameButtonStyle::kMdButton) {
DCHECK_EQ(std::string(views::FrameCaptionButton::kViewClassName), DCHECK_EQ(views::FrameCaptionButton::kViewClassName,
button->GetClassName()); button->GetClassName());
const int caption_button_center_size = const int caption_button_center_size =
button_width - 2 * views::kCaptionButtonInkDropDefaultCornerRadius; button_width - 2 * views::kCaptionButtonInkDropDefaultCornerRadius;
@@ -501,8 +501,7 @@ void OpaqueBrowserFrameViewLayout::SetBoundsForButton(
} else if (delegate_->GetFrameButtonStyle() == } else if (delegate_->GetFrameButtonStyle() ==
OpaqueBrowserFrameViewLayoutDelegate::FrameButtonStyle:: OpaqueBrowserFrameViewLayoutDelegate::FrameButtonStyle::
kImageButton) { kImageButton) {
DCHECK_EQ(std::string(views::ImageButton::kViewClassName), DCHECK_EQ(views::ImageButton::kViewClassName, button->GetClassName());
button->GetClassName());
auto* const image_button = static_cast<views::ImageButton*>(button); auto* const image_button = static_cast<views::ImageButton*>(button);
image_button->SetImageHorizontalAlignment( image_button->SetImageHorizontalAlignment(
(alignment == ALIGN_LEADING) ? views::ImageButton::ALIGN_RIGHT (alignment == ALIGN_LEADING) ? views::ImageButton::ALIGN_RIGHT
@@ -591,11 +590,7 @@ void OpaqueBrowserFrameViewLayout::SetView(int id, views::View* view) {
window_icon_ = view; window_icon_ = view;
break; break;
case VIEW_ID_WINDOW_TITLE: case VIEW_ID_WINDOW_TITLE:
if (view) { window_title_ = views::AsViewClass<views::Label>(view);
DCHECK_EQ(std::string(views::Label::kViewClassName),
view->GetClassName());
}
window_title_ = static_cast<views::Label*>(view);
break; break;
} }

@@ -75,8 +75,7 @@ TEST_F(TaskManagerSearchBarViewTest, SetsFocusOnTextfield) {
views::View* focused_field = widget().GetFocusManager()->GetFocusedView(); views::View* focused_field = widget().GetFocusManager()->GetFocusedView();
ASSERT_NE(focused_field, nullptr); ASSERT_NE(focused_field, nullptr);
EXPECT_EQ(focused_field->GetClassMetaData()->type_name(), EXPECT_EQ(focused_field->GetClassName(), "Textfield");
std::string("Textfield"));
} }
TEST_F(TaskManagerSearchBarViewTest, KeyPressedFromTextfield) { TEST_F(TaskManagerSearchBarViewTest, KeyPressedFromTextfield) {

@@ -26,6 +26,7 @@
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/link.h" #include "ui/views/controls/link.h"
#include "ui/views/test/test_widget_observer.h" #include "ui/views/test/test_widget_observer.h"
#include "ui/views/view_utils.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace { namespace {
@@ -309,7 +310,7 @@ TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewIconOnly) {
ShowBubble(&delegate); ShowBubble(&delegate);
const views::View* const extra_view = bubble()->GetExtraView(); const views::View* const extra_view = bubble()->GetExtraView();
ASSERT_TRUE(extra_view); ASSERT_TRUE(extra_view);
ASSERT_EQ(std::string(extra_view->GetClassName()), "ImageView"); ASSERT_EQ(extra_view->GetClassName(), "ImageView");
EXPECT_TRUE(gfx::test::AreImagesEqual( EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(static_cast<const views::ImageView*>(extra_view)->GetImage()), gfx::Image(static_cast<const views::ImageView*>(extra_view)->GetImage()),
gfx::Image(gfx::CreateVectorIcon( gfx::Image(gfx::CreateVectorIcon(
@@ -331,7 +332,7 @@ TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewLinkedTextOnly) {
const views::View* const extra_view = bubble()->GetExtraView(); const views::View* const extra_view = bubble()->GetExtraView();
ASSERT_TRUE(extra_view); ASSERT_TRUE(extra_view);
ASSERT_EQ(std::string(extra_view->GetClassName()), "ImageButton"); ASSERT_EQ(extra_view->GetClassName(), "ImageButton");
EXPECT_EQ(extra_view->GetRenderedTooltipText(gfx::Point(0, 0)), EXPECT_EQ(extra_view->GetRenderedTooltipText(gfx::Point(0, 0)),
kExtraViewText); kExtraViewText);
CloseBubble(); CloseBubble();
@@ -350,7 +351,7 @@ TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewLabelTextOnly) {
const views::View* const extra_view = bubble()->GetExtraView(); const views::View* const extra_view = bubble()->GetExtraView();
ASSERT_TRUE(extra_view); ASSERT_TRUE(extra_view);
EXPECT_EQ(std::string(extra_view->GetClassName()), "Label"); EXPECT_EQ(extra_view->GetClassName(), "Label");
EXPECT_EQ(static_cast<const views::Label*>(extra_view)->GetText(), EXPECT_EQ(static_cast<const views::Label*>(extra_view)->GetText(),
kExtraViewText); kExtraViewText);
CloseBubble(); CloseBubble();
@@ -370,17 +371,17 @@ TEST_F(ToolbarActionsBarBubbleViewsTest, TestCreateExtraViewImageAndText) {
const views::View* const extra_view = bubble()->GetExtraView(); const views::View* const extra_view = bubble()->GetExtraView();
ASSERT_TRUE(extra_view); ASSERT_TRUE(extra_view);
EXPECT_STREQ(extra_view->GetClassName(), "View"); EXPECT_EQ(extra_view->GetClassName(), "View");
EXPECT_EQ(extra_view->children().size(), 2u); EXPECT_EQ(extra_view->children().size(), 2u);
for (const views::View* v : extra_view->children()) { for (const views::View* v : extra_view->children()) {
std::string class_name = v->GetClassName(); if (const auto* label = views::AsViewClass<views::Label>(v)) {
if (class_name == "Label") { EXPECT_EQ(label->GetText(), kExtraViewText);
EXPECT_EQ(static_cast<const views::Label*>(v)->GetText(), kExtraViewText);
} else { } else {
ASSERT_EQ(class_name, "ImageView"); const auto* image = views::AsViewClass<views::ImageView>(v);
ASSERT_TRUE(image);
EXPECT_TRUE(gfx::test::AreImagesEqual( EXPECT_TRUE(gfx::test::AreImagesEqual(
gfx::Image(static_cast<const views::ImageView*>(v)->GetImage()), gfx::Image(image->GetImage()),
gfx::Image(gfx::CreateVectorIcon( gfx::Image(gfx::CreateVectorIcon(
vector_icons::kBusinessIcon, kIconSize, vector_icons::kBusinessIcon, kIconSize,
v->GetColorProvider()->GetColor(ui::kColorIcon))))); v->GetColorProvider()->GetColor(ui::kColorIcon)))));

@@ -445,7 +445,7 @@ class AccountSelectionBubbleViewTest : public ChromeViewsTestBase,
void CheckMismatchIdp(views::View* idp_row, void CheckMismatchIdp(views::View* idp_row,
const std::u16string& expected_idp) { const std::u16string& expected_idp) {
ASSERT_STREQ("HoverButton", idp_row->GetClassName()); ASSERT_EQ("HoverButton", idp_row->GetClassName());
HoverButton* idp_button = static_cast<HoverButton*>(idp_row); HoverButton* idp_button = static_cast<HoverButton*>(idp_row);
ASSERT_TRUE(idp_button); ASSERT_TRUE(idp_button);
EXPECT_EQ(GetHoverButtonTitle(idp_button), u"Sign in to " + expected_idp); EXPECT_EQ(GetHoverButtonTitle(idp_button), u"Sign in to " + expected_idp);
@@ -1218,10 +1218,10 @@ TEST_F(MultipleIdpAccountSelectionBubbleViewTest, HoverChangesIdpCircle) {
std::vector<raw_ptr<views::View, VectorExperimental>> icon_children = std::vector<raw_ptr<views::View, VectorExperimental>> icon_children =
icon_view->children(); icon_view->children();
ASSERT_EQ(icon_children.size(), 2u); ASSERT_EQ(icon_children.size(), 2u);
EXPECT_STREQ(icon_children[1]->GetClassName(), "BoxLayoutView"); EXPECT_EQ(icon_children[1]->GetClassName(), "BoxLayoutView");
ASSERT_EQ(icon_children[1]->children().size(), 1u); ASSERT_EQ(icon_children[1]->children().size(), 1u);
EXPECT_STREQ(icon_children[1]->children()[0]->GetClassName(), EXPECT_EQ(icon_children[1]->children()[0]->GetClassName(),
"BrandIconImageView"); "BrandIconImageView");
auto* brand_icon_image_view = auto* brand_icon_image_view =
static_cast<BrandIconImageView*>(icon_children[1]->children()[0]); static_cast<BrandIconImageView*>(icon_children[1]->children()[0]);
auto* color_provider = account_row->GetColorProvider(); auto* color_provider = account_row->GetColorProvider();

@@ -456,7 +456,7 @@ void AccountSelectionModalView::ShowVerifyingSheet(
for (const auto& child : account_chooser_->children()) { for (const auto& child : account_chooser_->children()) {
// If one of the immediate children is HoverButton, this is a single account // If one of the immediate children is HoverButton, this is a single account
// chooser. // chooser.
if (std::string(child->GetClassName()) == "HoverButton") { if (child->GetClassName() == "HoverButton") {
is_single_account_chooser = true; is_single_account_chooser = true;
AccountHoverButton* button = static_cast<AccountHoverButton*>(child); AccountHoverButton* button = static_cast<AccountHoverButton*>(child);
if (button->HasBeenClicked()) { if (button->HasBeenClicked()) {
@@ -477,7 +477,7 @@ void AccountSelectionModalView::ShowVerifyingSheet(
views::View* wrapper = account_chooser_->children()[0]; views::View* wrapper = account_chooser_->children()[0];
views::View* contents = wrapper->children()[0]; views::View* contents = wrapper->children()[0];
for (const auto& child : contents->children()) { for (const auto& child : contents->children()) {
if (std::string(child->GetClassName()) == "HoverButton") { if (child->GetClassName() == "HoverButton") {
AccountHoverButton* button = static_cast<AccountHoverButton*>(child); AccountHoverButton* button = static_cast<AccountHoverButton*>(child);
if (button->HasBeenClicked()) { if (button->HasBeenClicked()) {
has_spinner_ = true; has_spinner_ = true;

@@ -322,7 +322,7 @@ class AccountSelectionModalViewTest : public DialogBrowserTest,
bool has_spinner = false; bool has_spinner = false;
for (const auto& child : button->children()) { for (const auto& child : button->children()) {
// Spinner is placed in a BoxLayoutView. // Spinner is placed in a BoxLayoutView.
if (std::string(child->GetClassName()) == "BoxLayoutView") { if (child->GetClassName() == "BoxLayoutView") {
views::Throbber* spinner = views::Throbber* spinner =
static_cast<views::Throbber*>(child->children()[0]); static_cast<views::Throbber*>(child->children()[0]);
EXPECT_TRUE(spinner); EXPECT_TRUE(spinner);
@@ -335,9 +335,8 @@ class AccountSelectionModalViewTest : public DialogBrowserTest,
void CheckDisabledButtonRow(views::View* button_row) { void CheckDisabledButtonRow(views::View* button_row) {
for (const auto& button : button_row->children()) { for (const auto& button : button_row->children()) {
auto* text_button = static_cast<views::MdTextButton*>( auto* text_button = static_cast<views::MdTextButton*>(
std::string(button->GetClassName()) == "FlexLayoutView" (button->GetClassName() == "FlexLayoutView") ? button->children()[0]
? button->children()[0] : button);
: button);
if (text_button->GetText() == l10n_util::GetStringUTF16(IDS_CANCEL)) { if (text_button->GetText() == l10n_util::GetStringUTF16(IDS_CANCEL)) {
ASSERT_TRUE(text_button->GetEnabled()); ASSERT_TRUE(text_button->GetEnabled());
@@ -495,7 +494,7 @@ class AccountSelectionModalViewTest : public DialogBrowserTest,
// account_chooser section. e.g. accounts, disclosure text, scroll view etc. // account_chooser section. e.g. accounts, disclosure text, scroll view etc.
// and all of them should be disabled. // and all of them should be disabled.
for (const auto& item : account_chooser) { for (const auto& item : account_chooser) {
if (std::string(item->GetClassName()) == "HoverButton") { if (item->GetClassName() == "HoverButton") {
AccountHoverButton* button = static_cast<AccountHoverButton*>(item); AccountHoverButton* button = static_cast<AccountHoverButton*>(item);
ASSERT_FALSE(item->GetEnabled()); ASSERT_FALSE(item->GetEnabled());
ASSERT_TRUE(button->HasDisabledOpacity()); ASSERT_TRUE(button->HasDisabledOpacity());
@@ -604,8 +603,7 @@ class AccountSelectionModalViewTest : public DialogBrowserTest,
size_t accounts_index = 0; size_t accounts_index = 0;
for (const auto& account_suffix : account_suffixes) { for (const auto& account_suffix : account_suffixes) {
if (std::string(accounts[accounts_index]->GetClassName()) == if (accounts[accounts_index]->GetClassName() == "Separator") {
"Separator") {
++accounts_index; ++accounts_index;
} }
CheckHoverableAccountRow(accounts[accounts_index++], account_suffix, CheckHoverableAccountRow(accounts[accounts_index++], account_suffix,
@@ -639,11 +637,11 @@ class AccountSelectionModalViewTest : public DialogBrowserTest,
std::vector<raw_ptr<views::View, VectorExperimental>> accounts = std::vector<raw_ptr<views::View, VectorExperimental>> accounts =
TestStructureAndGetAccounts(children[1]); TestStructureAndGetAccounts(children[1]);
ASSERT_EQ(std::string(accounts[0]->GetClassName()), "Separator"); ASSERT_EQ(accounts[0]->GetClassName(), "Separator");
CheckHoverableAccountRow(accounts[1], "enabled", CheckHoverableAccountRow(accounts[1], "enabled",
/*expect_idp=*/false, /*is_modal_dialog=*/true, /*expect_idp=*/false, /*is_modal_dialog=*/true,
/*is_disabled=*/false); /*is_disabled=*/false);
ASSERT_EQ(std::string(accounts[2]->GetClassName()), "Separator"); ASSERT_EQ(accounts[2]->GetClassName(), "Separator");
CheckHoverableAccountRow(accounts[3], "disabled", CheckHoverableAccountRow(accounts[3], "disabled",
/*expect_idp=*/false, /*is_modal_dialog=*/true, /*expect_idp=*/false, /*is_modal_dialog=*/true,
/*is_disabled=*/true); /*is_disabled=*/true);

@@ -114,7 +114,7 @@ std::vector<std::string> AccountSelectionViewTestBase::GetChildClassNames(
views::View* parent) { views::View* parent) {
std::vector<std::string> child_class_names; std::vector<std::string> child_class_names;
for (views::View* child_view : parent->children()) { for (views::View* child_view : parent->children()) {
child_class_names.push_back(child_view->GetClassName()); child_class_names.emplace_back(child_view->GetClassName());
} }
return child_class_names; return child_class_names;
} }
@@ -176,7 +176,7 @@ void AccountSelectionViewTestBase::CheckHoverableAccountRows(
// `accounts_index` to the first unused index in `accounts`, or to // `accounts_index` to the first unused index in `accounts`, or to
// `accounts.size()` if done. // `accounts.size()` if done.
for (const auto& account_suffix : account_suffixes) { for (const auto& account_suffix : account_suffixes) {
if (std::string(accounts[accounts_index]->GetClassName()) == "Separator") { if (accounts[accounts_index]->GetClassName() == "Separator") {
++accounts_index; ++accounts_index;
} }
CheckHoverableAccountRow(accounts[accounts_index++], account_suffix, CheckHoverableAccountRow(accounts[accounts_index++], account_suffix,
@@ -190,7 +190,7 @@ void AccountSelectionViewTestBase::CheckHoverableAccountRow(
bool expect_idp, bool expect_idp,
bool is_modal_dialog, bool is_modal_dialog,
bool is_disabled) { bool is_disabled) {
ASSERT_STREQ("HoverButton", account->GetClassName()); ASSERT_EQ("HoverButton", account->GetClassName());
HoverButton* account_row = static_cast<HoverButton*>(account); HoverButton* account_row = static_cast<HoverButton*>(account);
ASSERT_TRUE(account_row); ASSERT_TRUE(account_row);
@@ -254,16 +254,16 @@ void AccountSelectionViewTestBase::CheckHoverableAccountRow(
std::vector<raw_ptr<views::View, VectorExperimental>> icon_children = std::vector<raw_ptr<views::View, VectorExperimental>> icon_children =
icon_view->children(); icon_view->children();
ASSERT_EQ(icon_children.size(), 2u); ASSERT_EQ(icon_children.size(), 2u);
EXPECT_STREQ(icon_children[0]->GetClassName(), "AccountImageView"); EXPECT_EQ(icon_children[0]->GetClassName(), "AccountImageView");
EXPECT_EQ(icon_children[0]->size(), EXPECT_EQ(icon_children[0]->size(),
gfx::Size(kDesiredAvatarSize + kIdpBadgeOffset, gfx::Size(kDesiredAvatarSize + kIdpBadgeOffset,
kDesiredAvatarSize + kIdpBadgeOffset)); kDesiredAvatarSize + kIdpBadgeOffset));
EXPECT_STREQ(icon_children[1]->GetClassName(), "BoxLayoutView"); EXPECT_EQ(icon_children[1]->GetClassName(), "BoxLayoutView");
ASSERT_EQ(icon_children[1]->children().size(), 1u); ASSERT_EQ(icon_children[1]->children().size(), 1u);
views::View* brand_icon_image_view = icon_children[1]->children()[0]; views::View* brand_icon_image_view = icon_children[1]->children()[0];
EXPECT_STREQ(brand_icon_image_view->GetClassName(), "BrandIconImageView"); EXPECT_EQ(brand_icon_image_view->GetClassName(), "BrandIconImageView");
} else { } else {
EXPECT_STREQ(icon_view->GetClassName(), "AccountImageView"); EXPECT_EQ(icon_view->GetClassName(), "AccountImageView");
} }
} }

@@ -61,8 +61,7 @@ IN_PROC_BROWSER_TEST_F(InteractionSequenceUiTest, OpenMainMenuAndViewHelpItem) {
kToolbarAppMenuButtonElementId, context); kToolbarAppMenuButtonElementId, context);
BrowserAppMenuButton* const app_menu_button = BrowserAppMenuButton* const app_menu_button =
static_cast<BrowserAppMenuButton*>(button_view); static_cast<BrowserAppMenuButton*>(button_view);
DCHECK_EQ(std::string("BrowserAppMenuButton"), DCHECK_EQ("BrowserAppMenuButton", app_menu_button->GetClassName());
std::string(app_menu_button->GetClassName()));
// Define a simple sequence of: // Define a simple sequence of:
// - spotting the app menu button // - spotting the app menu button

@@ -928,15 +928,15 @@ TEST_F(KeyboardTest, FocusWithArcOverlay) {
EXPECT_EQ(keyboard.focused_surface_for_testing(), surface.get()); EXPECT_EQ(keyboard.focused_surface_for_testing(), surface.get());
constexpr char kFocusedViewClassName[] = "OverlayNativeViewHost"; constexpr char kFocusedViewClassName[] = "OverlayNativeViewHost";
EXPECT_STREQ(kFocusedViewClassName, EXPECT_EQ(kFocusedViewClassName,
widget1->GetFocusManager()->GetFocusedView()->GetClassName()); widget1->GetFocusManager()->GetFocusedView()->GetClassName());
// Tabbing should not move the focus away from the overlay. // Tabbing should not move the focus away from the overlay.
ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow()); ui::test::EventGenerator generator(ash::Shell::GetPrimaryRootWindow());
generator.PressKey(ui::VKEY_TAB, 0); generator.PressKey(ui::VKEY_TAB, 0);
EXPECT_STREQ(kFocusedViewClassName, EXPECT_EQ(kFocusedViewClassName,
widget1->GetFocusManager()->GetFocusedView()->GetClassName()); widget1->GetFocusManager()->GetFocusedView()->GetClassName());
EXPECT_EQ(keyboard.focused_surface_for_testing(), surface.get()); EXPECT_EQ(keyboard.focused_surface_for_testing(), surface.get());
hold.RunAndReset(); hold.RunAndReset();

@@ -144,7 +144,8 @@ void ViewElement::SetBounds(const gfx::Rect& bounds) {
std::vector<std::string> ViewElement::GetAttributes() const { std::vector<std::string> ViewElement::GetAttributes() const {
// TODO(lgrey): Change name to class after updating tests. // TODO(lgrey): Change name to class after updating tests.
return {"class", view_->GetClassName(), "name", view_->GetObjectName()}; return {"class", std::string(view_->GetClassName()), "name",
view_->GetObjectName()};
} }
std::pair<gfx::NativeWindow, gfx::Rect> std::pair<gfx::NativeWindow, gfx::Rect>

@@ -6,6 +6,7 @@
#define UI_BASE_METADATA_METADATA_MACROS_INTERNAL_H_ #define UI_BASE_METADATA_METADATA_MACROS_INTERNAL_H_
#include <string> #include <string>
#include <string_view>
#include <utility> #include <utility>
#include "ui/base/metadata/metadata_types.h" #include "ui/base/metadata/metadata_types.h"
@@ -60,7 +61,7 @@
#define METADATA_ACCESSORS_INTERNAL_BASE(class_name) \ #define METADATA_ACCESSORS_INTERNAL_BASE(class_name) \
using kMetadataTag = class_name; \ using kMetadataTag = class_name; \
[[maybe_unused]] static const char kViewClassName[]; \ [[maybe_unused]] static const char kViewClassName[]; \
const char* GetClassName() const; \ std::string_view GetClassName() const; \
static ui::metadata::ClassMetaData* MetaData(); \ static ui::metadata::ClassMetaData* MetaData(); \
class_name* ReinterpretToBaseClass(void* obj); \ class_name* ReinterpretToBaseClass(void* obj); \
/* Don't hide non-const base class version. */ \ /* Don't hide non-const base class version. */ \
@@ -169,7 +170,7 @@
#define BEGIN_METADATA_INTERNAL_BASE(qualified_class_name, \ #define BEGIN_METADATA_INTERNAL_BASE(qualified_class_name, \
metadata_class_name, parent_class_name) \ metadata_class_name, parent_class_name) \
const char* qualified_class_name::GetClassName() const { \ std::string_view qualified_class_name::GetClassName() const { \
return GetClassMetaData()->type_name(); \ return GetClassMetaData()->type_name(); \
} \ } \
\ \

@@ -99,17 +99,7 @@ class COMPONENT_EXPORT(UI_BASE_METADATA) ClassMetaData {
ClassMetaData& operator=(const ClassMetaData&) = delete; ClassMetaData& operator=(const ClassMetaData&) = delete;
virtual ~ClassMetaData(); virtual ~ClassMetaData();
const char* type_name() const { std::string_view type_name() const { return type_name_; }
static_assert(
std::is_same<decltype(type_name_), std::string_view>::value,
"This string is logged in plaintext via UMA trace events uploads, so "
"must be static as a privacy requirement.");
// This is safe because the underlying string is a C string and null
// terminated.
// TODO(325589481): See if directly returning the string_view would be
// desirable.
return type_name_.data();
}
const std::vector<raw_ptr<MemberMetaDataBase, VectorExperimental>>& members() const std::vector<raw_ptr<MemberMetaDataBase, VectorExperimental>>& members()
const { const {
return members_; return members_;
@@ -152,9 +142,6 @@ class COMPONENT_EXPORT(UI_BASE_METADATA) ClassMetaData {
ClassMemberIterator operator++(int); ClassMemberIterator operator++(int);
bool operator==(const ClassMemberIterator& rhs) const; bool operator==(const ClassMemberIterator& rhs) const;
bool operator!=(const ClassMemberIterator& rhs) const {
return !(*this == rhs);
}
MemberMetaDataBase* operator*() { MemberMetaDataBase* operator*() {
if (current_collection_ == nullptr || if (current_collection_ == nullptr ||
@@ -201,9 +188,10 @@ class COMPONENT_EXPORT(UI_BASE_METADATA) ClassMetaData {
class COMPONENT_EXPORT(UI_BASE_METADATA) MemberMetaDataBase { class COMPONENT_EXPORT(UI_BASE_METADATA) MemberMetaDataBase {
public: public:
using ValueStrings = std::vector<std::u16string>; using ValueStrings = std::vector<std::u16string>;
MemberMetaDataBase(const std::string& member_name,
const std::string& member_type) MemberMetaDataBase(std::string member_name, std::string member_type)
: member_name_(member_name), member_type_(member_type) {} : member_name_(std::move(member_name)),
member_type_(std::move(member_type)) {}
MemberMetaDataBase(const MemberMetaDataBase&) = delete; MemberMetaDataBase(const MemberMetaDataBase&) = delete;
MemberMetaDataBase& operator=(const MemberMetaDataBase&) = delete; MemberMetaDataBase& operator=(const MemberMetaDataBase&) = delete;
virtual ~MemberMetaDataBase() = default; virtual ~MemberMetaDataBase() = default;

@@ -7,6 +7,7 @@
#include <string> #include <string>
#include "base/memory/raw_ptr.h" #include "base/memory/raw_ptr.h"
#include "base/strings/strcat.h"
#include "ui/views/accessibility/ax_view_obj_wrapper.h" #include "ui/views/accessibility/ax_view_obj_wrapper.h"
#include "ui/views/accessibility/ax_virtual_view.h" #include "ui/views/accessibility/ax_virtual_view.h"
#include "ui/views/accessibility/view_accessibility.h" #include "ui/views/accessibility/view_accessibility.h"
@@ -61,8 +62,8 @@ bool AXVirtualViewWrapper::HandleAccessibleAction(
} }
std::string AXVirtualViewWrapper::ToString() const { std::string AXVirtualViewWrapper::ToString() const {
std::string description = "Virtual view child of "; return base::StrCat({"Virtual view child of ",
return description + virtual_view_->GetOwnerView()->GetClassName(); virtual_view_->GetOwnerView()->GetClassName()});
} }
} // namespace views } // namespace views

@@ -5,6 +5,7 @@
#include "ui/views/accessibility/view_accessibility.h" #include "ui/views/accessibility/view_accessibility.h"
#include <algorithm> #include <algorithm>
#include <string>
#include <utility> #include <utility>
#include "base/functional/callback.h" #include "base/functional/callback.h"
@@ -848,7 +849,7 @@ void ViewAccessibility::OnViewAddedToWidget() {
// this would be done in the ctor, but due to inheritance and the // this would be done in the ctor, but due to inheritance and the
// implementation of `GetClassName`, it would not work. As such, we set it // implementation of `GetClassName`, it would not work. As such, we set it
// here, since at this point the view object is fully initialized. // here, since at this point the view object is fully initialized.
SetClassName(view_->GetClassName()); SetClassName(std::string(view_->GetClassName()));
} }
void ViewAccessibility::SetPlaceholder(const std::string& placeholder) { void ViewAccessibility::SetPlaceholder(const std::string& placeholder) {

@@ -907,17 +907,17 @@ BubbleDialogDelegate::BubbleUmaLogger::GetBubbleName() const {
// Some dialogs might only use BDD and not BDDV. In those cases, the class // Some dialogs might only use BDD and not BDDV. In those cases, the class
// name should be based on BDDs' content view. // name should be based on BDDs' content view.
if (delegate_.has_value()) { if (delegate_.has_value()) {
std::string class_name = std::string class_name(
delegate_.value()->GetContentsView()->GetClassName(); delegate_.value()->GetContentsView()->GetClassName());
if (class_name != "View") { if (class_name != "View") {
return class_name; return class_name;
} }
} }
if (bubble_view_.has_value()) { if (bubble_view_.has_value()) {
return bubble_view_.value()->GetClassName(); return std::string(bubble_view_.value()->GetClassName());
} }
return std::optional<std::string>(); return std::nullopt;
} }
template <typename Value> template <typename Value>

@@ -47,7 +47,7 @@ void PrintFocusHierarchyImp(const View* view,
std::string PrintViewGraphImpl(const View* view) { std::string PrintViewGraphImpl(const View* view) {
std::string result; std::string result;
const std::string class_name(view->GetClassName()); const std::string_view class_name = view->GetClassName();
size_t base_name_index = class_name.find_last_of('/'); size_t base_name_index = class_name.find_last_of('/');
if (base_name_index == std::string::npos) { if (base_name_index == std::string::npos) {
base_name_index = 0; base_name_index = 0;
@@ -60,7 +60,7 @@ std::string PrintViewGraphImpl(const View* view) {
result.append(base::StringPrintf("%p", view)); result.append(base::StringPrintf("%p", view));
result.append(" [label=\""); result.append(" [label=\"");
result.append(class_name.substr(base_name_index).c_str()); result.append(class_name.substr(base_name_index));
result.append(base::StringPrintf( result.append(base::StringPrintf(
"\\n bounds: (%d, %d), (%dx%d)", view->bounds().x(), view->bounds().y(), "\\n bounds: (%d, %d), (%dx%d)", view->bounds().x(), view->bounds().y(),

@@ -146,7 +146,7 @@ class ClassRegistration : public BaseClassRegistration {
~ClassRegistration() override = default; ~ClassRegistration() override = default;
std::unique_ptr<View> CreateView() override { return std::make_unique<C>(); } std::unique_ptr<View> CreateView() override { return std::make_unique<C>(); }
std::u16string GetViewClassName() override { std::u16string GetViewClassName() override {
return base::ASCIIToUTF16(C::MetaData()->type_name()); return base::ASCIIToUTF16(C::kViewClassName);
} }
}; };
@@ -164,7 +164,7 @@ class ClassRegistration<Combobox> : public BaseClassRegistration,
.Build(); .Build();
} }
std::u16string GetViewClassName() override { std::u16string GetViewClassName() override {
return base::ASCIIToUTF16(Combobox::MetaData()->type_name()); return base::ASCIIToUTF16(Combobox::kViewClassName);
} }
// ui::ComboboxModel // ui::ComboboxModel
@@ -182,7 +182,7 @@ class ClassRegistration<MdTextButton> : public BaseClassRegistration {
return Builder<MdTextButton>().SetText(u"Button").Build(); return Builder<MdTextButton>().SetText(u"Button").Build();
} }
std::u16string GetViewClassName() override { std::u16string GetViewClassName() override {
return base::ASCIIToUTF16(MdTextButton::MetaData()->type_name()); return base::ASCIIToUTF16(MdTextButton::kViewClassName);
} }
}; };
@@ -201,7 +201,7 @@ class ClassRegistration<Textfield> : public BaseClassRegistration {
.Build(); .Build();
} }
std::u16string GetViewClassName() override { std::u16string GetViewClassName() override {
return base::ASCIIToUTF16(Textfield::MetaData()->type_name()); return base::ASCIIToUTF16(Textfield::kViewClassName);
} }
}; };
@@ -214,7 +214,7 @@ class ClassRegistration<Checkbox> : public BaseClassRegistration {
return std::make_unique<Checkbox>(u"<Checkbox>"); return std::make_unique<Checkbox>(u"<Checkbox>");
} }
std::u16string GetViewClassName() override { std::u16string GetViewClassName() override {
return base::ASCIIToUTF16(Checkbox::MetaData()->type_name()); return base::ASCIIToUTF16(Checkbox::kViewClassName);
} }
}; };
@@ -227,7 +227,7 @@ class ClassRegistration<RadioButton> : public BaseClassRegistration {
return std::make_unique<RadioButton>(u"<RadioButton>", 0); return std::make_unique<RadioButton>(u"<RadioButton>", 0);
} }
std::u16string GetViewClassName() override { std::u16string GetViewClassName() override {
return base::ASCIIToUTF16(RadioButton::MetaData()->type_name()); return base::ASCIIToUTF16(RadioButton::kViewClassName);
} }
}; };
@@ -243,7 +243,7 @@ class ClassRegistration<ToggleButton> : public BaseClassRegistration {
.Build(); .Build();
} }
std::u16string GetViewClassName() override { std::u16string GetViewClassName() override {
return base::ASCIIToUTF16(ToggleButton::MetaData()->type_name()); return base::ASCIIToUTF16(ToggleButton::kViewClassName);
} }
}; };
@@ -261,7 +261,7 @@ class ClassRegistration<ImageButton> : public BaseClassRegistration {
.Build(); .Build();
} }
std::u16string GetViewClassName() override { std::u16string GetViewClassName() override {
return base::ASCIIToUTF16(ImageButton::MetaData()->type_name()); return base::ASCIIToUTF16(ImageButton::kViewClassName);
} }
}; };

@@ -549,7 +549,7 @@ ui::InteractionSequence::StepBuilder InteractiveViewsTestApi::NameViewRelative(
if (!IsViewClass<V>(view)) { if (!IsViewClass<V>(view)) {
LOG(ERROR) << "NameView(): Target View is of type " LOG(ERROR) << "NameView(): Target View is of type "
<< view->GetClassName() << " but expected " << view->GetClassName() << " but expected "
<< V::MetaData()->type_name(); << V::kViewClassName;
seq->FailForTesting(); seq->FailForTesting();
return; return;
} }
@@ -690,7 +690,7 @@ InteractiveViewsTestApi::NameChildViewByType(ElementSpecifier parent,
base::OwnedRef(index))) base::OwnedRef(index)))
.SetDescription(base::StringPrintf( .SetDescription(base::StringPrintf(
"NameChildViewByType<%s>( \"%s\" %zu )", "NameChildViewByType<%s>( \"%s\" %zu )",
V::MetaData()->type_name(), name.data(), index))); V::kViewClassName, name.data(), index)));
} }
// static // static
@@ -714,7 +714,7 @@ InteractiveViewsTestApi::NameDescendantViewByType(ElementSpecifier ancestor,
base::OwnedRef(index))) base::OwnedRef(index)))
.SetDescription(base::StringPrintf( .SetDescription(base::StringPrintf(
"NameDescendantViewByType<%s>( \"%s\" %zu )", "NameDescendantViewByType<%s>( \"%s\" %zu )",
V::MetaData()->type_name(), name.data(), index))); V::kViewClassName, name.data(), index)));
} }
// static // static

@@ -14,7 +14,7 @@
#include "base/containers/map_util.h" #include "base/containers/map_util.h"
#include "base/scoped_observation.h" #include "base/scoped_observation.h"
#include "base/strings/stringprintf.h" #include "base/strings/strcat.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/base/interaction/element_identifier.h" #include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h" #include "ui/base/interaction/element_tracker.h"
@@ -351,19 +351,18 @@ gfx::NativeWindow InteractiveViewsTestPrivate::GetNativeWindowFromContext(
std::string InteractiveViewsTestPrivate::DebugDumpWidget( std::string InteractiveViewsTestPrivate::DebugDumpWidget(
const Widget& widget) const { const Widget& widget) const {
std::string description = widget.GetName(); std::string description = widget.GetName();
return base::StringPrintf( return base::StrCat({widget.GetClassName(), " \"", widget.GetName(), "\" at ",
"%s \"%s\" at %s", widget.GetClassName(), widget.GetName().c_str(), DebugDumpBounds(widget.GetWindowBoundsInScreen())});
DebugDumpBounds(widget.GetWindowBoundsInScreen()).c_str());
} }
InteractiveViewsTestPrivate::DebugTreeNode InteractiveViewsTestPrivate::DebugTreeNode
InteractiveViewsTestPrivate::DebugDumpElement( InteractiveViewsTestPrivate::DebugDumpElement(
const ui::TrackedElement* el) const { const ui::TrackedElement* el) const {
if (const auto* view = el->AsA<TrackedElementViews>()) { if (const auto* view = el->AsA<TrackedElementViews>()) {
return DebugTreeNode(base::StringPrintf( return DebugTreeNode(base::StrCat(
"%s%s - %s at %s", (view->view()->HasFocus() ? "[FOCUSED] " : ""), {(view->view()->HasFocus() ? "[FOCUSED] " : ""),
view->view()->GetClassName(), el->identifier().GetName().c_str(), view->view()->GetClassName(), " - ", el->identifier().GetName(),
DebugDumpBounds(el->GetScreenBounds()))); " at ", DebugDumpBounds(el->GetScreenBounds())}));
} }
return InteractiveTestPrivate::DebugDumpElement(el); return InteractiveTestPrivate::DebugDumpElement(el);
} }

@@ -1087,7 +1087,7 @@ View* View::GetSelectedViewForGroup(int group) {
} }
std::string View::GetObjectName() const { std::string View::GetObjectName() const {
return GetClassName(); return std::string(GetClassName());
} }
// Coordinate conversion ------------------------------------------------------- // Coordinate conversion -------------------------------------------------------
@@ -3403,7 +3403,7 @@ void View::CreateLayer(ui::LayerType layer_type) {
SetLayer(std::make_unique<ui::Layer>(layer_type)); SetLayer(std::make_unique<ui::Layer>(layer_type));
layer()->set_delegate(this); layer()->set_delegate(this);
layer()->SetName(GetClassName()); layer()->SetName(std::string(GetClassName()));
UpdateParentLayers(); UpdateParentLayers();
UpdateLayerVisibility(); UpdateLayerVisibility();
@@ -3521,7 +3521,7 @@ void View::LayoutImmediately() {
TRACE_EVENT("ui", "View::LayoutImmediately", [&](perfetto::EventContext ctx) { TRACE_EVENT("ui", "View::LayoutImmediately", [&](perfetto::EventContext ctx) {
auto* event = ctx.event<perfetto::protos::pbzero::ChromeTrackEvent>(); auto* event = ctx.event<perfetto::protos::pbzero::ChromeTrackEvent>();
auto* data = event->set_view_class_name(); auto* data = event->set_view_class_name();
data->set_name(GetClassName()); data->set_name(std::string(GetClassName()));
}); });
invalidates_during_layout_ = 0; invalidates_during_layout_ = 0;
++layouts_since_last_paint_; ++layouts_since_last_paint_;
@@ -3845,7 +3845,7 @@ void BaseActionViewInterface::ActionItemChangedImpl(
BEGIN_METADATA_BASE(View) BEGIN_METADATA_BASE(View)
ADD_PROPERTY_METADATA(std::unique_ptr<Background>, Background) ADD_PROPERTY_METADATA(std::unique_ptr<Background>, Background)
ADD_PROPERTY_METADATA(std::unique_ptr<Border>, Border) ADD_PROPERTY_METADATA(std::unique_ptr<Border>, Border)
ADD_READONLY_PROPERTY_METADATA(const char*, ClassName) ADD_READONLY_PROPERTY_METADATA(std::string_view, ClassName)
ADD_PROPERTY_METADATA(bool, Enabled) ADD_PROPERTY_METADATA(bool, Enabled)
ADD_PROPERTY_METADATA(View::FocusBehavior, FocusBehavior) ADD_PROPERTY_METADATA(View::FocusBehavior, FocusBehavior)
ADD_PROPERTY_METADATA(bool, FlipCanvasOnPaintForRTLUI) ADD_PROPERTY_METADATA(bool, FlipCanvasOnPaintForRTLUI)

@@ -4,11 +4,15 @@
#include "ui/views/view_utils.h" #include "ui/views/view_utils.h"
#include <sstream> #include <memory>
#include <string>
#include <string_view>
#include <vector>
#include "base/command_line.h" #include "base/command_line.h"
#include "base/debug/stack_trace.h" #include "base/debug/stack_trace.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/strcat.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/views_switches.h" #include "ui/views/views_switches.h"
@@ -22,9 +26,10 @@ namespace {
std::string GetViewTreeAsString(View* view) { std::string GetViewTreeAsString(View* view) {
if (!view->parent()) { if (!view->parent()) {
return view->GetClassName(); return std::string(view->GetClassName());
} }
return GetViewTreeAsString(view->parent()) + " -> " + view->GetClassName(); return base::StrCat(
{GetViewTreeAsString(view->parent()), " -> ", view->GetClassName()});
} }
} // namespace } // namespace
@@ -34,7 +39,7 @@ ViewDebugWrapperImpl::ViewDebugWrapperImpl(View* view) : view_(view) {}
ViewDebugWrapperImpl::~ViewDebugWrapperImpl() = default; ViewDebugWrapperImpl::~ViewDebugWrapperImpl() = default;
std::string ViewDebugWrapperImpl::GetViewClassName() { std::string ViewDebugWrapperImpl::GetViewClassName() {
return view_->GetClassName(); return std::string(view_->GetClassName());
} }
int ViewDebugWrapperImpl::GetID() { int ViewDebugWrapperImpl::GetID() {
@@ -89,23 +94,21 @@ std::string PrintViewHierarchy(View* view, bool verbose) {
std::string GetViewDebugInfo(View* view) { std::string GetViewDebugInfo(View* view) {
std::string debug_string = std::string debug_string =
std::string("View: ") + view->GetClassName() + "\n"; base::StrCat({"\nView: ", view->GetClassName(), "\nHierarchy:\n ",
debug_string += std::string("Hierarchy:\n ") + GetViewTreeAsString(view); GetViewTreeAsString(view), "\nView created here:\n"});
debug_string += "\nView created here:\n";
static bool has_stack_trace = static bool has_stack_trace =
base::CommandLine::ForCurrentProcess()->HasSwitch( base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kViewStackTraces); switches::kViewStackTraces);
if (has_stack_trace) { if (has_stack_trace) {
debug_string += view->GetProperty(kViewStackTraceKey)->ToString(); debug_string += view->GetProperty(kViewStackTraceKey)->ToString();
} else { } else {
debug_string += std::string(" Run with --") + switches::kViewStackTraces + debug_string +=
" to get a stack trace for when this View was created."; base::StrCat({" Run with --", switches::kViewStackTraces,
" to get a stack trace for when this View was created."});
} }
return "\n" + debug_string; return debug_string;
} }
} // namespace views } // namespace views

@@ -120,7 +120,7 @@ class NativeWidgetMac::ZoomFocusMonitor : public FocusChangeListener {
return; return;
} }
// Web content handles its own zooming. // Web content handles its own zooming.
if (strcmp("WebView", focused_now->GetClassName()) == 0) { if (focused_now->GetClassName() == "WebView") {
return; return;
} }
NSRect rect = NSRectFromCGRect(focused_now->GetBoundsInScreen().ToCGRect()); NSRect rect = NSRectFromCGRect(focused_now->GetBoundsInScreen().ToCGRect());

@@ -2708,7 +2708,7 @@ void Widget::OnChildRemoved(Widget* child_widget) {
} }
BEGIN_METADATA_BASE(Widget) BEGIN_METADATA_BASE(Widget)
ADD_READONLY_PROPERTY_METADATA(const char*, ClassName) ADD_READONLY_PROPERTY_METADATA(std::string_view, ClassName)
ADD_READONLY_PROPERTY_METADATA(gfx::Rect, ClientAreaBoundsInScreen) ADD_READONLY_PROPERTY_METADATA(gfx::Rect, ClientAreaBoundsInScreen)
ADD_READONLY_PROPERTY_METADATA(std::string, Name) ADD_READONLY_PROPERTY_METADATA(std::string, Name)
ADD_READONLY_PROPERTY_METADATA(gfx::Rect, RestoredBounds) ADD_READONLY_PROPERTY_METADATA(gfx::Rect, RestoredBounds)