Commit 411345b2 authored by James Cook's avatar James Cook Committed by Commit Bot

cros: Add a status area indicator when running with --mash

--mash causes thousands of lines of UI code to behave differently, but
in the best case there's no visual indication of what mode you're in.

Add an indicator to the status area that shows if you're running --mash.
This could be generalized later to a "flag warning", like we use in
browser windows when running --no-sandbox.

Bug: 808158
Test: ash_unittests
Change-Id: I477158085bed9665c2fc9e7d2356c1f346083919
Reviewed-on: https://chromium-review.googlesource.com/905631
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534860}
parent 513a946d
...@@ -495,6 +495,8 @@ component("ash") { ...@@ -495,6 +495,8 @@ component("ash") {
"system/enterprise/enterprise_domain_observer.h", "system/enterprise/enterprise_domain_observer.h",
"system/enterprise/tray_enterprise.cc", "system/enterprise/tray_enterprise.cc",
"system/enterprise/tray_enterprise.h", "system/enterprise/tray_enterprise.h",
"system/flag_warning/flag_warning_tray.cc",
"system/flag_warning/flag_warning_tray.h",
"system/ime/ime_observer.h", "system/ime/ime_observer.h",
"system/ime/tray_ime_chromeos.cc", "system/ime/tray_ime_chromeos.cc",
"system/ime/tray_ime_chromeos.h", "system/ime/tray_ime_chromeos.h",
...@@ -1448,6 +1450,7 @@ test("ash_unittests") { ...@@ -1448,6 +1450,7 @@ test("ash_unittests") {
"system/date/date_view_unittest.cc", "system/date/date_view_unittest.cc",
"system/date/system_info_default_view_unittest.cc", "system/date/system_info_default_view_unittest.cc",
"system/enterprise/tray_enterprise_unittest.cc", "system/enterprise/tray_enterprise_unittest.cc",
"system/flag_warning/flag_warning_tray_unittest.cc",
"system/ime/tray_ime_chromeos_unittest.cc", "system/ime/tray_ime_chromeos_unittest.cc",
"system/ime_menu/ime_menu_tray_unittest.cc", "system/ime_menu/ime_menu_tray_unittest.cc",
"system/keyboard_brightness/tray_keyboard_brightness_unittest.cc", "system/keyboard_brightness/tray_keyboard_brightness_unittest.cc",
......
// Copyright 2018 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/flag_warning/flag_warning_tray.h"
#include <memory>
#include "ash/public/cpp/ash_typography.h"
#include "ash/public/cpp/config.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_container.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/layout/fill_layout.h"
namespace ash {
namespace {
const char kTooltipText[] = "Running with flag --mash";
} // namespace
FlagWarningTray::FlagWarningTray(Shelf* shelf) : shelf_(shelf) {
DCHECK(shelf_);
SetLayoutManager(std::make_unique<views::FillLayout>());
// The flag --mash is a chrome-level switch, so check the config instead.
const bool is_mash = Shell::GetAshConfig() == Config::MASH;
if (is_mash) {
container_ = new TrayContainer(shelf);
AddChildView(container_);
button_ = views::MdTextButton::Create(this, base::string16(),
CONTEXT_LAUNCHER_BUTTON);
button_->SetProminent(true);
button_->SetBgColorOverride(gfx::kGoogleYellow300);
button_->SetEnabledTextColors(SK_ColorBLACK);
button_->SetTooltipText(base::ASCIIToUTF16(kTooltipText));
UpdateButton();
container_->AddChildView(button_);
}
SetVisible(is_mash);
}
FlagWarningTray::~FlagWarningTray() = default;
void FlagWarningTray::UpdateAfterShelfAlignmentChange() {
if (!container_)
return;
container_->UpdateAfterShelfAlignmentChange();
UpdateButton();
}
void FlagWarningTray::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK_EQ(button_, sender);
// TODO(jamescook): Use NewWindowController to open about:flags. This will
// require a new mojo interface to chrome.
}
void FlagWarningTray::GetAccessibleNodeData(ui::AXNodeData* node_data) {
View::GetAccessibleNodeData(node_data);
node_data->SetName(button_->GetText());
}
void FlagWarningTray::UpdateButton() {
if (!button_)
return;
// Only the horizontal shelf is wide enough for a text label. Use an icon for
// vertical shelf alignments.
if (shelf_->IsHorizontalAlignment()) {
button_->SetText(base::ASCIIToUTF16("mash"));
button_->SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia());
button_->SetMinSize(gfx::Size(0, kTrayItemSize));
} else {
button_->SetText(base::string16());
button_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kSystemMenuInfoIcon, SK_ColorBLACK));
button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize));
}
}
} // namespace ash
// Copyright 2018 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.
#ifndef ASH_SYSTEM_FLAG_WARNING_FLAG_WARNING_TRAY_H_
#define ASH_SYSTEM_FLAG_WARNING_FLAG_WARNING_TRAY_H_
#include <memory>
#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
namespace views {
class MdTextButton;
}
namespace ash {
class Shelf;
class TrayContainer;
// Adds an indicator to the status area if certain high-risk flags are enabled,
// for example --mash. Clicking the button opens about:flags so the user can
// reset the flag. For consistency with other status area tray views, this view
// is always created but only made visible when the flag is set.
class ASH_EXPORT FlagWarningTray : public views::View,
public views::ButtonListener {
public:
explicit FlagWarningTray(Shelf* shelf);
~FlagWarningTray() override;
// Update the child view layout and appearance for horizontal or vertical
// shelf alignments.
void UpdateAfterShelfAlignmentChange();
// views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
// Update the button label and icon based on shelf state.
void UpdateButton();
const Shelf* const shelf_;
// Owned by views hierarchy.
TrayContainer* container_ = nullptr;
views::MdTextButton* button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(FlagWarningTray);
};
} // namespace ash
#endif // ASH_SYSTEM_FLAG_WARNING_FLAG_WARNING_TRAY_H_
// Copyright 2018 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/flag_warning/flag_warning_tray.h"
#include "ash/public/cpp/config.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/system/status_area_widget.h"
#include "ash/test/ash_test_base.h"
namespace ash {
namespace {
using FlagWarningTrayTest = AshTestBase;
TEST_F(FlagWarningTrayTest, Visibility) {
// Tray is always created.
FlagWarningTray* tray = Shell::GetPrimaryRootWindowController()
->GetStatusAreaWidget()
->flag_warning_tray_for_testing();
ASSERT_TRUE(tray);
// Warning should be visible in ash_unittests --mash, but not in regular
// ash_unittests. The warning does not show for Config::MUS because mus will
// roll out via experiment/Finch trial and showing the tray would reveal
// the experiment state to users.
const bool is_mash = Shell::GetAshConfig() == Config::MASH;
EXPECT_EQ(tray->visible(), is_mash);
}
} // namespace
} // namespace ash
...@@ -25,7 +25,7 @@ namespace ash { ...@@ -25,7 +25,7 @@ namespace ash {
class Shelf; class Shelf;
class TrayContainer; class TrayContainer;
// Adds a logout button to the launcher's status area if enabled by the // Adds a logout button to the shelf's status area if enabled by the
// kShowLogoutButtonInTray pref. // kShowLogoutButtonInTray pref.
class ASH_EXPORT LogoutButtonTray : public views::View, class ASH_EXPORT LogoutButtonTray : public views::View,
public views::ButtonListener, public views::ButtonListener,
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/session/session_controller.h" #include "ash/session/session_controller.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/flag_warning/flag_warning_tray.h"
#include "ash/system/ime_menu/ime_menu_tray.h" #include "ash/system/ime_menu/ime_menu_tray.h"
#include "ash/system/overview/overview_button_tray.h" #include "ash/system/overview/overview_button_tray.h"
#include "ash/system/palette/palette_tray.h" #include "ash/system/palette/palette_tray.h"
...@@ -63,6 +64,9 @@ void StatusAreaWidget::Initialize() { ...@@ -63,6 +64,9 @@ void StatusAreaWidget::Initialize() {
logout_button_tray_ = std::make_unique<LogoutButtonTray>(shelf_); logout_button_tray_ = std::make_unique<LogoutButtonTray>(shelf_);
status_area_widget_delegate_->AddChildView(logout_button_tray_.get()); status_area_widget_delegate_->AddChildView(logout_button_tray_.get());
flag_warning_tray_ = std::make_unique<FlagWarningTray>(shelf_);
status_area_widget_delegate_->AddChildView(flag_warning_tray_.get());
// The layout depends on the number of children, so build it once after // The layout depends on the number of children, so build it once after
// adding all of them. // adding all of them.
status_area_widget_delegate_->UpdateLayout(); status_area_widget_delegate_->UpdateLayout();
...@@ -93,6 +97,7 @@ StatusAreaWidget::~StatusAreaWidget() { ...@@ -93,6 +97,7 @@ StatusAreaWidget::~StatusAreaWidget() {
palette_tray_.reset(); palette_tray_.reset();
logout_button_tray_.reset(); logout_button_tray_.reset();
overview_button_tray_.reset(); overview_button_tray_.reset();
flag_warning_tray_.reset();
// All child tray views have been removed. // All child tray views have been removed.
DCHECK_EQ(0, GetContentsView()->child_count()); DCHECK_EQ(0, GetContentsView()->child_count());
...@@ -106,6 +111,7 @@ void StatusAreaWidget::UpdateAfterShelfAlignmentChange() { ...@@ -106,6 +111,7 @@ void StatusAreaWidget::UpdateAfterShelfAlignmentChange() {
ime_menu_tray_->UpdateAfterShelfAlignmentChange(); ime_menu_tray_->UpdateAfterShelfAlignmentChange();
palette_tray_->UpdateAfterShelfAlignmentChange(); palette_tray_->UpdateAfterShelfAlignmentChange();
overview_button_tray_->UpdateAfterShelfAlignmentChange(); overview_button_tray_->UpdateAfterShelfAlignmentChange();
flag_warning_tray_->UpdateAfterShelfAlignmentChange();
status_area_widget_delegate_->UpdateLayout(); status_area_widget_delegate_->UpdateLayout();
} }
...@@ -162,6 +168,7 @@ void StatusAreaWidget::SchedulePaint() { ...@@ -162,6 +168,7 @@ void StatusAreaWidget::SchedulePaint() {
ime_menu_tray_->SchedulePaint(); ime_menu_tray_->SchedulePaint();
palette_tray_->SchedulePaint(); palette_tray_->SchedulePaint();
overview_button_tray_->SchedulePaint(); overview_button_tray_->SchedulePaint();
flag_warning_tray_->SchedulePaint();
} }
const ui::NativeTheme* StatusAreaWidget::GetNativeTheme() const { const ui::NativeTheme* StatusAreaWidget::GetNativeTheme() const {
......
...@@ -17,6 +17,7 @@ class Window; ...@@ -17,6 +17,7 @@ class Window;
} }
namespace ash { namespace ash {
class FlagWarningTray;
class ImeMenuTray; class ImeMenuTray;
class LogoutButtonTray; class LogoutButtonTray;
class OverviewButtonTray; class OverviewButtonTray;
...@@ -96,23 +97,18 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget, ...@@ -96,23 +97,18 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget,
// ShelfBackgroundAnimatorObserver: // ShelfBackgroundAnimatorObserver:
void UpdateShelfItemBackground(SkColor color) override; void UpdateShelfItemBackground(SkColor color) override;
// TODO(jamescook): Introduce a test API instead of these methods.
LogoutButtonTray* logout_button_tray_for_testing() { LogoutButtonTray* logout_button_tray_for_testing() {
return logout_button_tray_.get(); return logout_button_tray_.get();
} }
VirtualKeyboardTray* virtual_keyboard_tray_for_testing() { VirtualKeyboardTray* virtual_keyboard_tray_for_testing() {
return virtual_keyboard_tray_.get(); return virtual_keyboard_tray_.get();
} }
FlagWarningTray* flag_warning_tray_for_testing() {
return flag_warning_tray_.get();
}
private: private:
void AddSystemTray();
void AddWebNotificationTray();
void AddLogoutButtonTray();
void AddPaletteTray();
void AddVirtualKeyboardTray();
void AddImeMenuTray();
void AddOverviewButtonTray();
StatusAreaWidgetDelegate* status_area_widget_delegate_; StatusAreaWidgetDelegate* status_area_widget_delegate_;
std::unique_ptr<OverviewButtonTray> overview_button_tray_; std::unique_ptr<OverviewButtonTray> overview_button_tray_;
...@@ -122,6 +118,7 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget, ...@@ -122,6 +118,7 @@ class ASH_EXPORT StatusAreaWidget : public views::Widget,
std::unique_ptr<PaletteTray> palette_tray_; std::unique_ptr<PaletteTray> palette_tray_;
std::unique_ptr<VirtualKeyboardTray> virtual_keyboard_tray_; std::unique_ptr<VirtualKeyboardTray> virtual_keyboard_tray_;
std::unique_ptr<ImeMenuTray> ime_menu_tray_; std::unique_ptr<ImeMenuTray> ime_menu_tray_;
std::unique_ptr<FlagWarningTray> flag_warning_tray_;
LoginStatus login_status_ = LoginStatus::NOT_LOGGED_IN; LoginStatus login_status_ = LoginStatus::NOT_LOGGED_IN;
......
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