0

Revert of Remove some pre-md code and assets. (patchset id:40001 of https://codereview.chromium.org/2770953003/ )

Reason for revert:
Causing failures on chromium.chromiumos/Linux ChromiumOS Tests (dbg)(1)

BUG=705678

Original issue's description:
> Remove some pre-md code and assets.
>
> BUG=687816,686234,686335
>
> Review-Url: https://codereview.chromium.org/2770953003
> Cr-Commit-Position: refs/heads/master@{#459837}
> Committed: 36cfbe932e

TBR=tdanderson@chromium.org,estade@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=687816,686234,686335

Review-Url: https://codereview.chromium.org/2776973005
Cr-Commit-Position: refs/heads/master@{#459887}
This commit is contained in:
jwd
2017-03-27 14:30:57 -07:00
committed by Commit bot
parent 77d815be2a
commit cd95e00836
24 changed files with 427 additions and 79 deletions

@ -310,6 +310,8 @@ component("ash") {
"common/system/chromeos/session/session_length_limit_observer.h",
"common/system/chromeos/session/tray_session_length_limit.cc",
"common/system/chromeos/session/tray_session_length_limit.h",
"common/system/chromeos/settings/tray_settings.cc",
"common/system/chromeos/settings/tray_settings.h",
"common/system/chromeos/supervised/custodian_info_tray_observer.h",
"common/system/chromeos/supervised/tray_supervised_user.cc",
"common/system/chromeos/supervised/tray_supervised_user.h",

@ -6,6 +6,7 @@
#include <algorithm>
#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/shell_observer.h"
#include "ash/common/system/brightness_control_delegate.h"
#include "ash/common/system/tray/tray_constants.h"
@ -102,8 +103,13 @@ BrightnessView::BrightnessView(bool default_view, double initial_percent)
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
views::ImageView* icon = TrayPopupUtils::CreateMainImageView();
icon->SetImage(
gfx::CreateVectorIcon(kSystemMenuBrightnessIcon, kMenuIconColor));
if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
icon->SetImage(
gfx::CreateVectorIcon(kSystemMenuBrightnessIcon, kMenuIconColor));
} else {
icon->SetImage(
rb.GetImageNamed(IDR_AURA_UBER_TRAY_BRIGHTNESS).ToImageSkia());
}
tri_view->AddView(TriView::Container::START, icon);
slider_ = TrayPopupUtils::CreateSlider(this);

@ -7,6 +7,8 @@
#include <algorithm>
#include <cmath>
#include "ash/common/material_design/material_design_controller.h"
#include "ash/resources/grit/ash_resources.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/logging.h"
@ -16,6 +18,7 @@
#include "chromeos/dbus/power_manager_client.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h"
@ -97,29 +100,55 @@ int PowerSourceToMessageID(
return 0;
}
const gfx::VectorIcon& VectorIconForIconBadge(
PowerStatus::IconBadge icon_badge) {
switch (icon_badge) {
case PowerStatus::ICON_BADGE_NONE:
return gfx::kNoneIcon;
case PowerStatus::ICON_BADGE_ALERT:
return kSystemTrayBatteryAlertIcon;
case PowerStatus::ICON_BADGE_BOLT:
return kSystemTrayBatteryBoltIcon;
case PowerStatus::ICON_BADGE_X:
return kSystemTrayBatteryXIcon;
case PowerStatus::ICON_BADGE_UNRELIABLE:
return kSystemTrayBatteryUnreliableIcon;
}
NOTREACHED();
return gfx::kNoneIcon;
}
static PowerStatus* g_power_status = NULL;
// Minimum battery percentage rendered in UI.
const int kMinBatteryPercent = 1;
// The height of the battery icon (as measured from the user-visible bottom of
// the icon to the user-visible top of the icon).
const int kBatteryImageHeight = 12;
// Width and height of battery images.
const int kBatteryImageHeight = 25;
const int kBatteryImageWidth = 25;
// The dimensions of the canvas containing the battery icon.
const int kBatteryCanvasSize = 16;
// Number of different power states.
const int kNumPowerImages = 15;
// The minimum height (in dp) of the charged region of the battery icon when the
// battery is present and has a charge greater than 0.
const int kMinVisualChargeLevel = 1;
// The height of the battery icon in material design (as measured from the
// user-visible bottom of the icon to the user-visible top of the icon).
const int kBatteryImageHeightMd = 12;
// The empty background color of the battery icon in the system tray.
// The dimensions of the canvas containing the material design battery icon.
const int kBatteryCanvasSizeMd = 16;
// The minimum height (in dp) of the charged region of the material design
// battery icon when the battery is present and has a charge greater than 0.
const int kMinVisualChargeLevelMd = 1;
// The empty background color of the battery icon in the system tray. Used
// for material design.
// TODO(tdanderson): Move these constants to a shared location if they are
// shared by more than one material design system icon.
const SkColor kBatteryBaseColor = SkColorSetA(SK_ColorWHITE, 0x4C);
// The background color of the charged region of the battery in the system
// tray.
// tray. Used for material design.
const SkColor kBatteryChargeColor = SK_ColorWHITE;
// The color of the battery's badge (bolt, unreliable, X).
@ -133,12 +162,17 @@ const SkColor kBatteryAlertColor = SkColorSetRGB(0xDA, 0x27, 0x12);
bool PowerStatus::BatteryImageInfo::operator==(
const BatteryImageInfo& o) const {
return icon_badge == o.icon_badge && charge_level == o.charge_level;
if (ash::MaterialDesignController::UseMaterialDesignSystemIcons())
return icon_badge == o.icon_badge && charge_level == o.charge_level;
// TODO(tdanderson): |resource_id|, |offset|, and |index| are only used for
// non-MD. Remove these once MD is enabled by default. See crbug.com/614453.
return resource_id == o.resource_id && offset == o.offset && index == o.index;
}
const int PowerStatus::kMaxBatteryTimeToDisplaySec = 24 * 60 * 60;
const double PowerStatus::kCriticalBatteryChargePercentage = 5;
const double PowerStatus::kCriticalBatteryChargePercentageMd = 5;
// static
void PowerStatus::Initialize() {
@ -293,81 +327,127 @@ std::string PowerStatus::GetCurrentPowerSourceID() const {
PowerStatus::BatteryImageInfo PowerStatus::GetBatteryImageInfo(
IconSet icon_set) const {
BatteryImageInfo info;
CalculateBatteryImageInfo(&info);
if (MaterialDesignController::UseMaterialDesignSystemIcons())
CalculateBatteryImageInfoMd(&info);
else
CalculateBatteryImageInfoNonMd(&info, icon_set);
return info;
}
void PowerStatus::CalculateBatteryImageInfo(BatteryImageInfo* info) const {
void PowerStatus::CalculateBatteryImageInfoMd(BatteryImageInfo* info) const {
if (!IsUsbChargerConnected() && !IsBatteryPresent()) {
info->icon_badge = &kSystemTrayBatteryXIcon;
info->icon_badge = ICON_BADGE_X;
info->charge_level = 0;
return;
}
if (IsUsbChargerConnected())
info->icon_badge = &kSystemTrayBatteryUnreliableIcon;
info->icon_badge = ICON_BADGE_UNRELIABLE;
else if (IsLinePowerConnected())
info->icon_badge = &kSystemTrayBatteryBoltIcon;
info->icon_badge = ICON_BADGE_BOLT;
else
info->icon_badge = nullptr;
info->icon_badge = ICON_BADGE_NONE;
// |charge_state| is a value between 0 and kBatteryImageHeight representing
// |charge_state| is a value between 0 and kBatteryImageHeightMd representing
// the number of device pixels the battery image should be shown charged. The
// exception is when |charge_state| is 0 (a critically-low battery); in this
// case, still draw 1dp of charge.
int charge_state =
static_cast<int>(GetBatteryPercent() / 100.0 * kBatteryImageHeight);
charge_state = std::max(std::min(charge_state, kBatteryImageHeight), 0);
info->charge_level = std::max(charge_state, kMinVisualChargeLevel);
static_cast<int>(GetBatteryPercent() / 100.0 * kBatteryImageHeightMd);
charge_state = std::max(std::min(charge_state, kBatteryImageHeightMd), 0);
info->charge_level = std::max(charge_state, kMinVisualChargeLevelMd);
// Use an alert badge if the battery is critically low and does not already
// Use ICON_BADGE_ALERT if the battery is critically low and does not already
// have a badge assigned.
if (GetBatteryPercent() < kCriticalBatteryChargePercentage &&
!info->icon_badge) {
info->icon_badge = &kSystemTrayBatteryAlertIcon;
if (GetBatteryPercent() < kCriticalBatteryChargePercentageMd &&
info->icon_badge == ICON_BADGE_NONE) {
info->icon_badge = ICON_BADGE_ALERT;
}
}
void PowerStatus::CalculateBatteryImageInfoNonMd(
BatteryImageInfo* info,
const IconSet& icon_set) const {
if (IsUsbChargerConnected()) {
info->resource_id =
(icon_set == ICON_DARK)
? IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE_DARK
: IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE;
} else {
info->resource_id = (icon_set == ICON_DARK)
? IDR_AURA_UBER_TRAY_POWER_SMALL_DARK
: IDR_AURA_UBER_TRAY_POWER_SMALL;
}
info->offset = IsUsbChargerConnected() ? 0 : (IsLinePowerConnected() ? 1 : 0);
if (GetBatteryPercent() >= 100.0) {
info->index = kNumPowerImages - 1;
} else if (!IsBatteryPresent()) {
info->index = kNumPowerImages;
} else {
info->index =
static_cast<int>(GetBatteryPercent() / 100.0 * (kNumPowerImages - 1));
info->index = std::max(std::min(info->index, kNumPowerImages - 2), 0);
}
}
gfx::ImageSkia PowerStatus::GetBatteryImage(
const BatteryImageInfo& info) const {
if (!MaterialDesignController::UseMaterialDesignSystemIcons())
return GetBatteryImageNonMd(info);
const bool use_alert_color =
(info.charge_level == kMinVisualChargeLevel && !IsLinePowerConnected());
(info.charge_level == kMinVisualChargeLevelMd && !IsLinePowerConnected());
const SkColor badge_color =
use_alert_color ? kBatteryAlertColor : kBatteryBadgeColor;
const SkColor charge_color =
use_alert_color ? kBatteryAlertColor : kBatteryChargeColor;
gfx::Canvas canvas(
gfx::Size(kBatteryCanvasSize, kBatteryCanvasSize),
gfx::Size(kBatteryCanvasSizeMd, kBatteryCanvasSizeMd),
display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(),
false);
// Paint the battery's base (background) color.
PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kBatteryCanvasSize,
PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kBatteryCanvasSizeMd,
kBatteryBaseColor);
// Paint the charged portion of the battery. Note that |charge_height| adjusts
// for the 2dp of padding between the bottom of the battery icon and the
// bottom edge of |canvas|.
const int charge_height = info.charge_level + 2;
gfx::Rect clip_rect(0, kBatteryCanvasSize - charge_height, kBatteryCanvasSize,
charge_height);
gfx::Rect clip_rect(0, kBatteryCanvasSizeMd - charge_height,
kBatteryCanvasSizeMd, charge_height);
canvas.Save();
canvas.ClipRect(clip_rect);
PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kBatteryCanvasSize,
PaintVectorIcon(&canvas, kSystemTrayBatteryIcon, kBatteryCanvasSizeMd,
charge_color);
canvas.Restore();
// Paint the badge over top of the battery, if applicable.
if (info.icon_badge)
PaintVectorIcon(&canvas, *info.icon_badge, kBatteryCanvasSize, badge_color);
if (info.icon_badge != ICON_BADGE_NONE) {
PaintVectorIcon(&canvas, VectorIconForIconBadge(info.icon_badge),
kBatteryCanvasSizeMd, badge_color);
}
return gfx::ImageSkia(canvas.ExtractImageRep());
}
gfx::ImageSkia PowerStatus::GetBatteryImageNonMd(
const BatteryImageInfo& info) const {
gfx::Image all;
all = ui::ResourceBundle::GetSharedInstance().GetImageNamed(info.resource_id);
gfx::Rect region(info.offset * kBatteryImageWidth,
info.index * kBatteryImageHeight, kBatteryImageWidth,
kBatteryImageHeight);
return gfx::ImageSkiaOperations::ExtractSubset(*all.ToImageSkia(), region);
}
base::string16 PowerStatus::GetAccessibleNameString(
bool full_description) const {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (IsBatteryFull()) {
return l10n_util::GetStringUTF16(
return rb.GetLocalizedString(
IDS_ASH_STATUS_TRAY_BATTERY_FULL_CHARGE_ACCESSIBLE);
}
@ -384,10 +464,10 @@ base::string16 PowerStatus::GetAccessibleNameString(
IsBatteryCharging() ? GetBatteryTimeToFull() : GetBatteryTimeToEmpty();
if (IsUsbChargerConnected()) {
battery_time_accessible = l10n_util::GetStringUTF16(
battery_time_accessible = rb.GetLocalizedString(
IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE_ACCESSIBLE);
} else if (IsBatteryTimeBeingCalculated()) {
battery_time_accessible = l10n_util::GetStringUTF16(
battery_time_accessible = rb.GetLocalizedString(
IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING_ACCESSIBLE);
} else if (ShouldDisplayBatteryTime(time) &&
!IsBatteryDischargingOnLinePower()) {

@ -17,10 +17,6 @@
#include "chromeos/dbus/power_manager_client.h"
#include "ui/gfx/image/image_skia.h"
namespace gfx {
struct VectorIcon;
}
namespace ash {
// PowerStatus is a singleton that receives updates about the system's
@ -28,6 +24,15 @@ namespace ash {
// available to interested classes within Ash.
class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
public:
// Types of badges which can be drawn on top of a battery icon.
enum IconBadge {
ICON_BADGE_NONE,
ICON_BADGE_ALERT,
ICON_BADGE_BOLT,
ICON_BADGE_X,
ICON_BADGE_UNRELIABLE
};
// Different styles of battery icons.
enum IconSet { ICON_LIGHT, ICON_DARK };
@ -68,18 +73,39 @@ class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
// updating onscreen icons (GetBatteryImage() creates a new image on each
// call).
struct BatteryImageInfo {
BatteryImageInfo() : icon_badge(nullptr), charge_level(-1) {}
BatteryImageInfo()
: resource_id(-1),
offset(-1),
index(-1),
icon_badge(ICON_BADGE_NONE),
charge_level(-1) {}
bool operator==(const BatteryImageInfo& o) const;
bool operator!=(const BatteryImageInfo& o) const { return !(*this == o); }
// The badge (lightning bolt, exclamation mark, etc) that should be drawn
// on top of the battery icon.
const gfx::VectorIcon* icon_badge;
// Resource ID of the image containing the specific battery icon to use.
// Only used in non-MD.
int resource_id;
// A value between 0 and kBatteryImageHeight representing the height
// of the battery's charge level in dp.
// Horizontal offset in the battery icon array image. The USB / "unreliable
// charging" image has a single column of icons; the other image contains a
// "battery" column on the left and a "line power" column on the right.
// Only used in non-MD.
int offset;
// Vertical offset corresponding to the current battery level. Only used in
// non-MD.
int index;
// The badge (lightning bolt, exclamation mark, etc) that should be drawn
// on top of the battery icon. Only used for MD.
// TODO(tdanderson): Consider using gfx::VectorIconId instead of this enum
// once all possible badges have been vectorized. See crbug.com/617298.
IconBadge icon_badge;
// A value between 0 and kBatteryImageHeightMD representing the height
// of the battery's charge level in dp. Only used for MD.
int charge_level;
};
@ -88,10 +114,10 @@ class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
// get very large; avoid displaying these large numbers.
static const int kMaxBatteryTimeToDisplaySec;
// An alert badge is drawn over the battery icon if the battery is not
// connected to a charger and has less than |kCriticalBatteryChargePercentage|
// percentage of charge remaining.
static const double kCriticalBatteryChargePercentage;
// An alert badge is drawn over the material design battery icon if the
// battery is not connected to a charger and has less than
// |kCriticalBatteryChargePercentageMd| percentage of charge remaining.
static const double kCriticalBatteryChargePercentageMd;
// Sets the global instance. Must be called before any calls to Get().
static void Initialize();
@ -194,13 +220,24 @@ class ASH_EXPORT PowerStatus : public chromeos::PowerManagerClient::Observer {
// returned by this method to avoid creating new images unnecessarily.
BatteryImageInfo GetBatteryImageInfo(IconSet icon_set) const;
// A helper function called by GetBatteryImageInfo(). Populates the fields of
// |info|.
void CalculateBatteryImageInfo(BatteryImageInfo* info) const;
// A helper function called by GetBatteryImageInfo(). Populates the
// MD-specific fields of |info|.
void CalculateBatteryImageInfoMd(BatteryImageInfo* info) const;
// A helper function called by GetBatteryImageInfo(). Populates the
// non-MD-specific fields of |info|.
void CalculateBatteryImageInfoNonMd(BatteryImageInfo* info,
const IconSet& icon_set) const;
// Creates a new image that should be shown for the battery's current state.
gfx::ImageSkia GetBatteryImage(const BatteryImageInfo& info) const;
// A version of GetBatteryImage() that is used when material design is not
// enabled.
// TODO(tdanderson): Remove this once material design is enabled by default.
// See crbug.com/614453.
gfx::ImageSkia GetBatteryImageNonMd(const BatteryImageInfo& info) const;
// Returns an string describing the current state for accessibility.
base::string16 GetAccessibleNameString(bool full_description) const;

@ -6,7 +6,6 @@
#include <memory>
#include "ash/resources/vector_icons/vector_icons.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "chromeos/dbus/dbus_thread_manager.h"
@ -200,65 +199,65 @@ TEST_F(PowerStatusTest, GetBatteryImageInfo) {
TEST_F(PowerStatusTest, BatteryImageInfoIconBadge) {
PowerSupplyProperties prop;
// A charging battery connected to AC power should have a bolt badge.
// A charging battery connected to AC power should have an ICON_BADGE_BOLT.
prop.set_external_power(PowerSupplyProperties::AC);
prop.set_battery_state(PowerSupplyProperties::CHARGING);
prop.set_battery_percent(98.0);
power_status_->SetProtoForTesting(prop);
EXPECT_EQ(
&kSystemTrayBatteryBoltIcon,
PowerStatus::ICON_BADGE_BOLT,
power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
// A discharging battery connected to AC should also have a bolt badge.
// A discharging battery connected to AC should also have an ICON_BADGE_BOLT.
prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
power_status_->SetProtoForTesting(prop);
EXPECT_EQ(
&kSystemTrayBatteryBoltIcon,
PowerStatus::ICON_BADGE_BOLT,
power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
// A charging battery connected to USB power should have an
// unreliable badge.
// ICON_BADGE_UNRELIABLE.
prop.set_external_power(PowerSupplyProperties::USB);
prop.set_battery_state(PowerSupplyProperties::CHARGING);
power_status_->SetProtoForTesting(prop);
EXPECT_EQ(
&kSystemTrayBatteryUnreliableIcon,
PowerStatus::ICON_BADGE_UNRELIABLE,
power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
// A discharging battery connected to USB power should also have an
// unreliable badge.
// ICON_BADGE_UNRELIABLE.
prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
power_status_->SetProtoForTesting(prop);
EXPECT_EQ(
&kSystemTrayBatteryUnreliableIcon,
PowerStatus::ICON_BADGE_UNRELIABLE,
power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
// Show the right icon when no battery is present.
// Show an ICON_BADGE_X when no battery is present.
prop.set_external_power(PowerSupplyProperties::DISCONNECTED);
prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT);
power_status_->SetProtoForTesting(prop);
EXPECT_EQ(
&kSystemTrayBatteryXIcon,
PowerStatus::ICON_BADGE_X,
power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
// Do not show a badge when the battery is discharging.
prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
power_status_->SetProtoForTesting(prop);
EXPECT_EQ(
nullptr,
PowerStatus::ICON_BADGE_NONE,
power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
// Show the right icon for a discharging battery when it falls below
// a charge level of PowerStatus::kCriticalBatteryChargePercentage.
prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage);
// Show ICON_BADGE_ALERT for a discharging battery when it falls below
// a charge level of PowerStatus::kCriticalBatteryChargePercentageMd.
prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentageMd);
power_status_->SetProtoForTesting(prop);
EXPECT_EQ(
nullptr,
PowerStatus::ICON_BADGE_NONE,
power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage - 1);
prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentageMd - 1);
power_status_->SetProtoForTesting(prop);
EXPECT_EQ(
&kSystemTrayBatteryAlertIcon,
PowerStatus::ICON_BADGE_ALERT,
power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
}

@ -13,16 +13,14 @@
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/system_tray_delegate.h"
#include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/system/tray/tray_constants.h"
#include "ash/resources/grit/ash_resources.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
#include "ui/views/view.h"
@ -143,6 +141,7 @@ void TraySessionLengthLimit::UpdateNotification() {
return;
}
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
message_center::RichNotificationData data;
data.should_make_spoken_feedback_for_popup_updates =
(limit_state_ != last_limit_state_);
@ -151,8 +150,8 @@ void TraySessionLengthLimit::UpdateNotification() {
message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId,
base::string16() /* title */,
ComposeNotificationMessage() /* message */,
gfx::Image(
gfx::CreateVectorIcon(kSystemMenuTimerIcon, kMenuIconColor)),
bundle.GetImageNamed(
IDR_AURA_UBER_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT),
base::string16() /* display_source */, GURL(),
message_center::NotifierId(
message_center::NotifierId::SYSTEM_COMPONENT,

@ -0,0 +1,175 @@
// Copyright (c) 2012 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/common/system/chromeos/settings/tray_settings.h"
#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/session/session_controller.h"
#include "ash/common/system/chromeos/power/power_status.h"
#include "ash/common/system/chromeos/power/power_status_view.h"
#include "ash/common/system/tray/actionable_view.h"
#include "ash/common/system/tray/fixed_sized_image_view.h"
#include "ash/common/system/tray/system_tray_controller.h"
#include "ash/common/system/tray/system_tray_delegate.h"
#include "ash/common/system/tray/tray_constants.h"
#include "ash/common/system/tray/tray_popup_utils.h"
#include "ash/common/wm_shell.h"
#include "ash/resources/grit/ash_resources.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
namespace ash {
namespace tray {
// TODO(tdanderson): Remove this class once material design is enabled by
// default. See crbug.com/614453.
class SettingsDefaultView : public ActionableView,
public PowerStatus::Observer {
public:
SettingsDefaultView(SystemTrayItem* owner, LoginStatus status)
: ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
login_status_(status),
label_(nullptr),
power_status_view_(nullptr) {
PowerStatus::Get()->AddObserver(this);
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
ash::kTrayPopupPaddingHorizontal, 0,
ash::kTrayPopupPaddingBetweenItems));
bool power_view_right_align = false;
if (login_status_ != LoginStatus::NOT_LOGGED_IN &&
login_status_ != LoginStatus::LOCKED &&
!Shell::Get()->session_controller()->IsInSecondaryLoginScreen()) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
views::ImageView* icon = TrayPopupUtils::CreateMainImageView();
icon->SetImage(
rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia());
icon->set_id(test::kSettingsTrayItemViewId);
AddChildView(icon);
base::string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS);
label_ = TrayPopupUtils::CreateDefaultLabel();
label_->SetText(text);
AddChildView(label_);
SetAccessibleName(text);
power_view_right_align = true;
}
if (PowerStatus::Get()->IsBatteryPresent()) {
power_status_view_ = new ash::PowerStatusView(power_view_right_align);
AddChildView(power_status_view_);
OnPowerStatusChanged();
}
if (MaterialDesignController::IsSystemTrayMenuMaterial())
SetInkDropMode(InkDropHostView::InkDropMode::ON);
}
~SettingsDefaultView() override { PowerStatus::Get()->RemoveObserver(this); }
// Overridden from ash::ActionableView.
bool PerformAction(const ui::Event& event) override {
if (login_status_ == LoginStatus::NOT_LOGGED_IN ||
login_status_ == LoginStatus::LOCKED ||
Shell::Get()->session_controller()->IsInSecondaryLoginScreen()) {
return false;
}
Shell::Get()->system_tray_controller()->ShowSettings();
CloseSystemBubble();
return true;
}
// Overridden from views::View.
void Layout() override {
views::View::Layout();
if (label_ && power_status_view_) {
// Let the box-layout do the layout first. Then move power_status_view_
// to right align if it is created.
gfx::Size size = power_status_view_->GetPreferredSize();
gfx::Rect bounds(size);
bounds.set_x(width() - size.width() - ash::kTrayPopupPaddingBetweenItems);
bounds.set_y((height() - size.height()) / 2);
power_status_view_->SetBoundsRect(bounds);
}
}
// Overridden from views::View.
void ChildPreferredSizeChanged(views::View* child) override {
views::View::ChildPreferredSizeChanged(child);
Layout();
}
// Overridden from PowerStatus::Observer.
void OnPowerStatusChanged() override {
if (!PowerStatus::Get()->IsBatteryPresent())
return;
base::string16 accessible_name =
label_
? label_->text() + base::ASCIIToUTF16(", ") +
PowerStatus::Get()->GetAccessibleNameString(true)
: PowerStatus::Get()->GetAccessibleNameString(true);
SetAccessibleName(accessible_name);
}
private:
LoginStatus login_status_;
views::Label* label_;
ash::PowerStatusView* power_status_view_;
DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView);
};
} // namespace tray
TraySettings::TraySettings(SystemTray* system_tray)
: SystemTrayItem(system_tray, UMA_SETTINGS), default_view_(nullptr) {}
TraySettings::~TraySettings() {}
views::View* TraySettings::CreateTrayView(LoginStatus status) {
return nullptr;
}
views::View* TraySettings::CreateDefaultView(LoginStatus status) {
if ((status == LoginStatus::NOT_LOGGED_IN || status == LoginStatus::LOCKED) &&
!PowerStatus::Get()->IsBatteryPresent())
return nullptr;
if (!Shell::Get()->system_tray_delegate()->ShouldShowSettings())
return nullptr;
CHECK(default_view_ == nullptr);
default_view_ = new tray::SettingsDefaultView(this, status);
return default_view_;
}
views::View* TraySettings::CreateDetailedView(LoginStatus status) {
NOTIMPLEMENTED();
return nullptr;
}
void TraySettings::DestroyTrayView() {}
void TraySettings::DestroyDefaultView() {
default_view_ = nullptr;
}
void TraySettings::DestroyDetailedView() {}
void TraySettings::UpdateAfterLoginStatusChange(LoginStatus status) {}
} // namespace ash

@ -0,0 +1,40 @@
// Copyright (c) 2012 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_COMMON_SYSTEM_CHROMEOS_SETTINGS_TRAY_SETTINGS_H_
#define ASH_COMMON_SYSTEM_CHROMEOS_SETTINGS_TRAY_SETTINGS_H_
#include "ash/common/system/tray/system_tray_item.h"
#include "base/macros.h"
namespace ash {
namespace tray {
class SettingsDefaultView;
}
// TODO(tdanderson): Remove this class once material design is enabled by
// default. See crbug.com/614453.
class TraySettings : public SystemTrayItem {
public:
explicit TraySettings(SystemTray* system_tray);
~TraySettings() override;
private:
// Overridden from SystemTrayItem
views::View* CreateTrayView(LoginStatus status) override;
views::View* CreateDefaultView(LoginStatus status) override;
views::View* CreateDetailedView(LoginStatus status) override;
void DestroyTrayView() override;
void DestroyDefaultView() override;
void DestroyDetailedView() override;
void UpdateAfterLoginStatusChange(LoginStatus status) override;
tray::SettingsDefaultView* default_view_;
DISALLOW_COPY_AND_ASSIGN(TraySettings);
};
} // namespace ash
#endif // ASH_COMMON_SYSTEM_CHROMEOS_SETTINGS_TRAY_SETTINGS_H_

@ -27,6 +27,7 @@
#include "ash/common/system/chromeos/screen_security/screen_capture_tray_item.h"
#include "ash/common/system/chromeos/screen_security/screen_share_tray_item.h"
#include "ash/common/system/chromeos/session/tray_session_length_limit.h"
#include "ash/common/system/chromeos/settings/tray_settings.h"
#include "ash/common/system/chromeos/supervised/tray_supervised_user.h"
#include "ash/common/system/chromeos/tray_caps_lock.h"
#include "ash/common/system/chromeos/tray_tracing.h"
@ -308,6 +309,8 @@ void SystemTray::CreateItems(SystemTrayDelegate* delegate) {
delegate->CreateRotationLockTrayItem(this);
if (tray_rotation_lock)
AddTrayItem(std::move(tray_rotation_lock));
if (!use_md)
AddTrayItem(base::MakeUnique<TraySettings>(this));
AddTrayItem(base::WrapUnique(tray_update_));
if (use_md) {
tray_tiles_ = new TrayTiles(this);

@ -55,10 +55,17 @@
<structure type="chrome_scaled_image" name="IDR_AURA_NOTIFICATION_BLUETOOTH" file="cros/notification/notification_bluetooth_icon.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_NOTIFICATION_DISPLAY" file="cros/notification/display_notification_icon.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_NOTIFICATION_LOW_POWER_CHARGER" file="cros/notification/notification_low_power_charger.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_BRIGHTNESS" file="cros/status/status_brightness.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_BUBBLE_SESSION_LENGTH_LIMIT" file="cros/status/status_session_length_timer.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_CHILD_USER" file="cros/status/status_child_user.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_ENTERPRISE" file="cros/status/status_managed.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SUPERVISED_USER" file="cros/status/status_managed_mode_user.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_NOTIFICATION_SESSION_LENGTH_LIMIT" file="cros/notification/notification_session_length_timer.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL" file="cros/status/status_power_small_all.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE" file="cros/status/status_power_small_all_fluctuating.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL_CHARGING_UNRELIABLE_DARK" file="cros/status/status_power_small_all_dark_fluctuating.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_POWER_SMALL_DARK" file="cros/status/status_power_small_all_dark.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_UBER_TRAY_SETTINGS" file="cros/status/status_settings.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_BOTTOM" file="common/window_header_shade_bottom_inactive.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_LEFT" file="common/window_header_shade_left_inactive.png" />

Binary file not shown.

After

(image error) Size: 654 B

Binary file not shown.

After

(image error) Size: 356 B

Binary file not shown.

After

(image error) Size: 2.8 KiB

Binary file not shown.

After

(image error) Size: 2.9 KiB

Binary file not shown.

After

(image error) Size: 907 B

Binary file not shown.

After

(image error) Size: 718 B

Binary file not shown.

After

(image error) Size: 513 B

Binary file not shown.

After

(image error) Size: 1.3 KiB

Binary file not shown.

After

(image error) Size: 829 B

Binary file not shown.

After

(image error) Size: 5.9 KiB

Binary file not shown.

After

(image error) Size: 6.4 KiB

Binary file not shown.

After

(image error) Size: 3.1 KiB

Binary file not shown.

After

(image error) Size: 2.2 KiB

Binary file not shown.

After

(image error) Size: 1.0 KiB