Commit e6e89116 authored by minch's avatar minch Committed by Commit Bot

dark_mode: Remove the clickable logic of TrayInfoLabel.

After crrev.com/c/693322, the clickable logic of TrayInfoLabel hasn't
been used by any class.

Bug: 1131543
Change-Id: I81e3234f7c6b88c1d2083986adb95a61746ffad3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2510730Reviewed-by: default avatarTim Song <tengs@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823713}
parent d638f460
...@@ -2209,7 +2209,6 @@ test("ash_unittests") { ...@@ -2209,7 +2209,6 @@ test("ash_unittests") {
"system/tray/size_range_layout_unittest.cc", "system/tray/size_range_layout_unittest.cc",
"system/tray/status_area_overflow_button_tray_unittest.cc", "system/tray/status_area_overflow_button_tray_unittest.cc",
"system/tray/tray_event_filter_unittest.cc", "system/tray/tray_event_filter_unittest.cc",
"system/tray/tray_info_label_unittest.cc",
"system/tray/tri_view_unittest.cc", "system/tray/tri_view_unittest.cc",
"system/unified/camera_mic_tray_item_view_unittest.cc", "system/unified/camera_mic_tray_item_view_unittest.cc",
"system/unified/feature_pods_container_view_unittest.cc", "system/unified/feature_pods_container_view_unittest.cc",
......
...@@ -237,8 +237,8 @@ void BluetoothDetailedView::UpdateDeviceScrollList( ...@@ -237,8 +237,8 @@ void BluetoothDetailedView::UpdateDeviceScrollList(
// Show user Bluetooth state if there is no bluetooth devices in list. // Show user Bluetooth state if there is no bluetooth devices in list.
if (device_map_.empty()) { if (device_map_.empty()) {
if (!bluetooth_discovering_label_) { if (!bluetooth_discovering_label_) {
bluetooth_discovering_label_ = new TrayInfoLabel( bluetooth_discovering_label_ =
nullptr /* delegate */, IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING); new TrayInfoLabel(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING);
scroll_content()->AddChildViewAt(bluetooth_discovering_label_, index++); scroll_content()->AddChildViewAt(bluetooth_discovering_label_, index++);
} else { } else {
scroll_content()->ReorderChildView(bluetooth_discovering_label_, index++); scroll_content()->ReorderChildView(bluetooth_discovering_label_, index++);
......
...@@ -591,7 +591,7 @@ void NetworkListView::UpdateInfoLabel(int message_id, ...@@ -591,7 +591,7 @@ void NetworkListView::UpdateInfoLabel(int message_id,
return; return;
} }
if (!info_label) if (!info_label)
info_label = new TrayInfoLabel(nullptr /* delegate */, message_id); info_label = new TrayInfoLabel(message_id);
else else
info_label->Update(message_id); info_label->Update(message_id);
......
...@@ -6,18 +6,13 @@ ...@@ -6,18 +6,13 @@
#include "ash/system/tray/tray_popup_item_style.h" #include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h" #include "ash/system/tray/tray_popup_utils.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
namespace ash { namespace ash {
TrayInfoLabel::TrayInfoLabel(TrayInfoLabel::Delegate* delegate, int message_id) TrayInfoLabel::TrayInfoLabel(int message_id)
: ActionableView(TrayPopupInkDropStyle::FILL_BOUNDS), : label_(TrayPopupUtils::CreateDefaultLabel()) {
label_(TrayPopupUtils::CreateDefaultLabel()),
message_id_(message_id),
delegate_(delegate) {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); TriView* tri_view = TrayPopupUtils::CreateDefaultRowView();
...@@ -31,60 +26,20 @@ TrayInfoLabel::TrayInfoLabel(TrayInfoLabel::Delegate* delegate, int message_id) ...@@ -31,60 +26,20 @@ TrayInfoLabel::TrayInfoLabel(TrayInfoLabel::Delegate* delegate, int message_id)
tri_view->AddView(TriView::Container::CENTER, label_); tri_view->AddView(TriView::Container::CENTER, label_);
AddChildView(tri_view); AddChildView(tri_view);
SetFocusBehavior(IsClickable() ? FocusBehavior::ALWAYS SetFocusBehavior(FocusBehavior::NEVER);
: FocusBehavior::NEVER);
Update(message_id); Update(message_id);
} }
TrayInfoLabel::~TrayInfoLabel() = default; TrayInfoLabel::~TrayInfoLabel() = default;
void TrayInfoLabel::Update(int message_id) { void TrayInfoLabel::Update(int message_id) {
message_id_ = message_id; const TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SYSTEM_INFO);
TrayPopupItemStyle::FontStyle font_style;
if (IsClickable()) {
SetInkDropMode(InkDropMode::ON);
font_style = TrayPopupItemStyle::FontStyle::CLICKABLE_SYSTEM_INFO;
} else {
SetInkDropMode(InkDropMode::OFF);
font_style = TrayPopupItemStyle::FontStyle::SYSTEM_INFO;
}
const TrayPopupItemStyle style(font_style);
style.SetupLabel(label_); style.SetupLabel(label_);
label_->SetText(l10n_util::GetStringUTF16(message_id));
base::string16 text = l10n_util::GetStringUTF16(message_id);
label_->SetText(text);
SetAccessibleName(text);
SetFocusBehavior(IsClickable() ? FocusBehavior::ALWAYS
: FocusBehavior::NEVER);
}
bool TrayInfoLabel::PerformAction(const ui::Event& event) {
if (IsClickable()) {
delegate_->OnLabelClicked(message_id_);
return true;
}
return false;
}
void TrayInfoLabel::GetAccessibleNodeData(ui::AXNodeData* node_data) {
ActionableView::GetAccessibleNodeData(node_data);
if (!IsClickable())
node_data->role = ax::mojom::Role::kLabelText;
} }
const char* TrayInfoLabel::GetClassName() const { const char* TrayInfoLabel::GetClassName() const {
return "TrayInfoLabel"; return "TrayInfoLabel";
} }
bool TrayInfoLabel::IsClickable() {
if (delegate_)
return delegate_->IsLabelClickable(message_id_);
return false;
}
} // namespace ash } // namespace ash
...@@ -6,52 +6,28 @@ ...@@ -6,52 +6,28 @@
#define ASH_SYSTEM_TRAY_TRAY_INFO_LABEL_H_ #define ASH_SYSTEM_TRAY_TRAY_INFO_LABEL_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/system/tray/actionable_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/view.h"
namespace ash { namespace ash {
// A view containing only a label, which is to be inserted as a // A view containing only a label, which is to be inserted as a
// row within a system menu detailed view (e.g., the "Scanning for devices..." // row within a system menu detailed view (e.g., the "Scanning for devices..."
// message that can appear at the top of the Bluetooth detailed view). // message that can appear at the top of the Bluetooth detailed view).
// TrayInfoLabel can be clickable; this property is configured by its delegate. class ASH_EXPORT TrayInfoLabel : public views::View {
class ASH_EXPORT TrayInfoLabel : public ActionableView {
public: public:
// A delegate for determining whether or not a TrayInfoLabel is clickable, and explicit TrayInfoLabel(int message_id);
// handling actions when it is clicked.
class Delegate {
public:
virtual ~Delegate() {}
virtual void OnLabelClicked(int message_id) = 0;
virtual bool IsLabelClickable(int message_id) const = 0;
};
// |delegate| may be null, which results in a TrayInfoLabel which cannot be
// clicked.
TrayInfoLabel(Delegate* delegate, int message_id);
~TrayInfoLabel() override; ~TrayInfoLabel() override;
// Updates the TrayInfoLabel to display the message associated with // Updates the TrayInfoLabel to display the message associated with
// |message_id|. This may update text styling if the delegate indicates that // |message_id|.
// the TrayInfoLabel should be clickable.
void Update(int message_id); void Update(int message_id);
// ActionableView:
bool PerformAction(const ui::Event& event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// views::View: // views::View:
const char* GetClassName() const override; const char* GetClassName() const override;
private: private:
friend class TrayInfoLabelTest;
bool IsClickable();
views::Label* const label_; views::Label* const label_;
int message_id_;
Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(TrayInfoLabel); DISALLOW_COPY_AND_ASSIGN(TrayInfoLabel);
}; };
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/tray/tray_info_label.h"
#include <memory>
#include "ash/strings/grit/ash_strings.h"
#include "ash/test/ash_test_base.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
namespace ash {
namespace {
class TestClickEvent : public ui::Event {
public:
TestClickEvent() : ui::Event(ui::ET_MOUSE_PRESSED, base::TimeTicks(), 0) {}
};
class TestDelegate : public TrayInfoLabel::Delegate {
public:
TestDelegate() = default;
const std::vector<int>& clicked_message_ids() { return clicked_message_ids_; }
void AddClickableMessageId(int message_id) {
clickable_message_ids_.insert(message_id);
}
// TrayInfoLabel::Delegate:
void OnLabelClicked(int message_id) override {
clicked_message_ids_.push_back(message_id);
}
bool IsLabelClickable(int message_id) const override {
return clickable_message_ids_.find(message_id) !=
clickable_message_ids_.end();
}
private:
std::unordered_set<int> clickable_message_ids_;
std::vector<int> clicked_message_ids_;
};
} // namespace
class TrayInfoLabelTest : public AshTestBase {
public:
void SetUp() override {
AshTestBase::SetUp();
delegate_ = std::make_unique<TestDelegate>();
}
void TearDown() override {
AshTestBase::TearDown();
label_.reset();
delegate_.reset();
}
void CreateLabel(bool use_delegate, int message_id) {
label_ = std::make_unique<TrayInfoLabel>(
use_delegate ? delegate_.get() : nullptr, message_id);
use_delegate_ = use_delegate;
}
void ClickOnLabel(bool expect_click_was_handled) {
bool click_was_handled = label_->PerformAction(TestClickEvent());
EXPECT_EQ(expect_click_was_handled, click_was_handled);
}
void VerifyClickability(bool expected_clickable) {
EXPECT_EQ(expected_clickable, label_->IsClickable());
EXPECT_EQ(expected_clickable ? views::View::FocusBehavior::ALWAYS
: views::View::FocusBehavior::NEVER,
label_->GetFocusBehavior());
ui::AXNodeData node_data;
label_->GetAccessibleNodeData(&node_data);
if (expected_clickable)
EXPECT_EQ(ax::mojom::Role::kButton, node_data.role);
else
EXPECT_EQ(ax::mojom::Role::kLabelText, node_data.role);
}
void VerifyClicks(const std::vector<int>& expected_clicked_message_ids) {
if (!use_delegate_) {
EXPECT_TRUE(expected_clicked_message_ids.empty());
return;
}
EXPECT_EQ(expected_clicked_message_ids, delegate_->clicked_message_ids());
}
void VerifyNoClicks() { VerifyClicks(std::vector<int>()); }
protected:
std::unique_ptr<TrayInfoLabel> label_;
std::unique_ptr<TestDelegate> delegate_;
bool use_delegate_;
};
TEST_F(TrayInfoLabelTest, NoDelegate) {
CreateLabel(false /* use_delegate */, IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED),
label_->GetAccessibleName());
VerifyClickability(false /* expected_clickable */);
label_->Update(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED);
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED),
label_->GetAccessibleName());
VerifyClickability(false /* expected_clickable */);
label_->Update(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING);
EXPECT_EQ(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING),
label_->GetAccessibleName());
VerifyClickability(false /* expected_clickable */);
}
TEST_F(TrayInfoLabelTest, PerformAction) {
const int kClickableMessageId1 = IDS_ASH_STATUS_TRAY_BLUETOOTH_ENABLED;
const int kClickableMessageId2 = IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED;
const int kNonClickableMessageId = IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING;
delegate_->AddClickableMessageId(kClickableMessageId1);
delegate_->AddClickableMessageId(kClickableMessageId2);
CreateLabel(true /* use_delegate */, kClickableMessageId1);
VerifyNoClicks();
EXPECT_EQ(l10n_util::GetStringUTF16(kClickableMessageId1),
label_->GetAccessibleName());
VerifyClickability(true /* expected_clickable */);
ClickOnLabel(true /* expect_click_was_handled */);
VerifyClicks(std::vector<int>{kClickableMessageId1});
ClickOnLabel(true /* expect_click_was_handled */);
VerifyClicks(std::vector<int>{kClickableMessageId1, kClickableMessageId1});
label_->Update(kNonClickableMessageId);
EXPECT_EQ(l10n_util::GetStringUTF16(kNonClickableMessageId),
label_->GetAccessibleName());
VerifyClickability(false /* expected_clickable */);
ClickOnLabel(false /* expect_click_was_handled */);
VerifyClicks(std::vector<int>{kClickableMessageId1, kClickableMessageId1});
label_->Update(kClickableMessageId2);
EXPECT_EQ(l10n_util::GetStringUTF16(kClickableMessageId2),
label_->GetAccessibleName());
VerifyClickability(true /* expected_clickable */);
ClickOnLabel(true /* expect_click_was_handled */);
VerifyClicks(std::vector<int>{kClickableMessageId1, kClickableMessageId1,
kClickableMessageId2});
}
} // namespace ash
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
namespace ash { namespace ash {
...@@ -91,13 +90,6 @@ void TrayPopupItemStyle::SetupLabel(views::Label* label) const { ...@@ -91,13 +90,6 @@ void TrayPopupItemStyle::SetupLabel(views::Label* label) const {
label->SetFontList(base_font_list.Derive(1, gfx::Font::NORMAL, label->SetFontList(base_font_list.Derive(1, gfx::Font::NORMAL,
gfx::Font::Weight::NORMAL)); gfx::Font::Weight::NORMAL));
break; break;
case FontStyle::CLICKABLE_SYSTEM_INFO:
label->SetFontList(base_font_list.Derive(1, gfx::Font::NORMAL,
gfx::Font::Weight::NORMAL));
label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor));
label->SetAutoColorReadabilityEnabled(false);
break;
case FontStyle::CAPTION: case FontStyle::CAPTION:
label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL, label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL,
gfx::Font::Weight::NORMAL)); gfx::Font::Weight::NORMAL));
......
...@@ -45,8 +45,6 @@ class TrayPopupItemStyle { ...@@ -45,8 +45,6 @@ class TrayPopupItemStyle {
// System information text (e.g. date/time, battery status, "Scanning for // System information text (e.g. date/time, battery status, "Scanning for
// devices..." seen in the Bluetooth detailed view, etc). // devices..." seen in the Bluetooth detailed view, etc).
SYSTEM_INFO, SYSTEM_INFO,
// System information text within a clickable row.
CLICKABLE_SYSTEM_INFO,
// Sub text within a row (e.g. user name in user row). // Sub text within a row (e.g. user name in user row).
CAPTION, CAPTION,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment