Commit f7f00b08 authored by Tim Song's avatar Tim Song Committed by Commit Bot

[CrOS PhoneHub] Create skeleton for the PhoneHub tray UI.

BUG=1122499, 1106937

Change-Id: I543caf8ae059cf7140cb7f88c90c8847c6c1a59c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2379550
Commit-Queue: Tim Song <tengs@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804402}
parent 20ed8c8e
...@@ -1528,8 +1528,9 @@ ...@@ -1528,8 +1528,9 @@
'|permission_context', '|permission_context',
}, },
'phonehub': { 'phonehub': {
'filepath': 'chrome/browser/chromeos/phonehub/|'\ 'filepath': 'chrome/browser/chromeos/phonehub/'\
'chromeos/components/phonehub/', '|chromeos/components/phonehub/'\
'|ash/system/phonehub/',
}, },
'picture_in_picture': { 'picture_in_picture': {
'filepath': 'third_party/blink/renderer/modules/picture_in_picture/' 'filepath': 'third_party/blink/renderer/modules/picture_in_picture/'
......
...@@ -1091,6 +1091,8 @@ component("ash") { ...@@ -1091,6 +1091,8 @@ component("ash") {
"system/palette/tools/magnifier_mode.h", "system/palette/tools/magnifier_mode.h",
"system/palette/tools/metalayer_mode.cc", "system/palette/tools/metalayer_mode.cc",
"system/palette/tools/metalayer_mode.h", "system/palette/tools/metalayer_mode.h",
"system/phonehub/phone_hub_tray.cc",
"system/phonehub/phone_hub_tray.h",
"system/power/backlights_forced_off_setter.cc", "system/power/backlights_forced_off_setter.cc",
"system/power/backlights_forced_off_setter.h", "system/power/backlights_forced_off_setter.h",
"system/power/battery_notification.cc", "system/power/battery_notification.cc",
......
...@@ -947,6 +947,10 @@ This file contains the strings for ash. ...@@ -947,6 +947,10 @@ This file contains the strings for ash.
Screenshots Screenshots
</message> </message>
<message name="IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME" desc="The accessible name of the Phone Hub tray bubble for screen readers.">
Phone Hub
</message>
<message name="IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_ACTION" desc="Title of the capture region action in the stylus tools (a pop-up panel next to the status tray). This causes a partial screenshot to be taken (the user selects an area of the screen to take a screenshot of)."> <message name="IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_ACTION" desc="Title of the capture region action in the stylus tools (a pop-up panel next to the status tray). This causes a partial screenshot to be taken (the user selects an area of the screen to take a screenshot of).">
Capture region Capture region
</message> </message>
......
818fbb2303eba96c468079a0b7400e96440adf47
\ No newline at end of file
tengs@chromium.org
khorimoto@chromium.org
// Copyright 2020 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/phonehub/phone_hub_tray.h"
#include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/tray/system_menu_button.h"
#include "ash/system/tray/tray_bubble_wrapper.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_container.h"
#include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "ash/system/tray/tray_utils.h"
#include "base/bind.h"
#include "chromeos/constants/chromeos_features.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/separator.h"
namespace ash {
namespace {
// Padding for tray icon (dp; the button that shows the phone_hub menu).
constexpr int kTrayIconMainAxisInset = 8;
constexpr int kTrayIconCrossAxisInset = 0;
} // namespace
PhoneHubTray::PhoneHubTray(Shelf* shelf) : TrayBackgroundView(shelf) {
// TODO(tengs): Update icon to spec.
auto icon = std::make_unique<views::ImageView>();
icon->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME));
icon->SetImage(CreateVectorIcon(
kSystemMenuPhoneIcon,
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary,
AshColorProvider::AshColorMode::kDark)));
tray_container()->SetMargin(kTrayIconMainAxisInset, kTrayIconCrossAxisInset);
icon_ = tray_container()->AddChildView(std::move(icon));
}
PhoneHubTray::~PhoneHubTray() {
if (bubble_)
bubble_->bubble_view()->ResetDelegate();
}
void PhoneHubTray::ClickedOutsideBubble() {
CloseBubble();
}
base::string16 PhoneHubTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME);
}
void PhoneHubTray::HandleLocaleChange() {
icon_->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME));
}
void PhoneHubTray::HideBubbleWithView(const TrayBubbleView* bubble_view) {
if (bubble_->bubble_view() == bubble_view)
CloseBubble();
}
base::string16 PhoneHubTray::GetAccessibleNameForBubble() {
return GetAccessibleNameForTray();
}
bool PhoneHubTray::ShouldEnableExtraKeyboardAccessibility() {
return Shell::Get()->accessibility_controller()->spoken_feedback_enabled();
}
void PhoneHubTray::HideBubble(const TrayBubbleView* bubble_view) {
HideBubbleWithView(bubble_view);
}
void PhoneHubTray::AnchorUpdated() {
if (bubble_)
bubble_->bubble_view()->UpdateBubble();
}
void PhoneHubTray::Initialize() {
TrayBackgroundView::Initialize();
UpdateVisibility();
}
bool PhoneHubTray::PerformAction(const ui::Event& event) {
// TODO(tengs): Log usage metrics.
if (bubble_)
CloseBubble();
else
ShowBubble(event.IsMouseEvent() || event.IsGestureEvent());
return true;
}
void PhoneHubTray::ShowBubble(bool show_by_click) {
if (bubble_)
return;
TrayBubbleView::InitParams init_params;
init_params.delegate = this;
init_params.parent_window = GetBubbleWindowContainer();
init_params.anchor_view = GetBubbleAnchor();
init_params.shelf_alignment = shelf()->alignment();
init_params.preferred_width = kTrayMenuWidth;
init_params.close_on_deactivate = true;
init_params.has_shadow = false;
init_params.translucent = true;
init_params.corner_radius = kTrayItemCornerRadius;
init_params.show_by_click = show_by_click;
TrayBubbleView* bubble_view = new TrayBubbleView(init_params);
bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets());
bubble_view->set_margins(GetSecondaryBubbleInsets());
// TODO(tengs): Implement the PhoneHub UI view.
bubble_view->AddChildView(std::make_unique<views::Label>());
bubble_ = std::make_unique<TrayBubbleWrapper>(this, bubble_view,
false /* is_persistent */);
SetIsActive(true);
}
TrayBubbleView* PhoneHubTray::GetBubbleView() {
return bubble_ ? bubble_->bubble_view() : nullptr;
}
const char* PhoneHubTray::GetClassName() const {
return "PhoneHubTray";
}
void PhoneHubTray::CloseBubble() {
bubble_.reset();
SetIsActive(false);
shelf()->UpdateAutoHideState();
}
void PhoneHubTray::UpdateVisibility() {
// TODO(tengs): Hook up visibility with phonehub::FeatureStatusProvider.
SetVisiblePreferred(chromeos::features::IsPhoneHubEnabled());
}
} // namespace ash
// Copyright 2020 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_PHONEHUB_PHONE_HUB_TRAY_H_
#define ASH_SYSTEM_PHONEHUB_PHONE_HUB_TRAY_H_
#include "ash/ash_export.h"
#include "ash/system/tray/tray_background_view.h"
namespace views {
class ImageView;
}
namespace ash {
class TrayBubbleWrapper;
// This class represents the Phone Hub tray button in the status area and
// controls the bubble that is shown when the tray button is clicked.
class ASH_EXPORT PhoneHubTray : public TrayBackgroundView {
public:
explicit PhoneHubTray(Shelf* shelf);
PhoneHubTray(const PhoneHubTray&) = delete;
~PhoneHubTray() override;
PhoneHubTray& operator=(const PhoneHubTray&) = delete;
// TrayBackgroundView:
void ClickedOutsideBubble() override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void AnchorUpdated() override;
void Initialize() override;
bool PerformAction(const ui::Event& event) override;
void CloseBubble() override;
void ShowBubble(bool show_by_click) override;
TrayBubbleView* GetBubbleView() override;
const char* GetClassName() const override;
private:
// TrayBubbleView::Delegate:
base::string16 GetAccessibleNameForBubble() override;
bool ShouldEnableExtraKeyboardAccessibility() override;
void HideBubble(const TrayBubbleView* bubble_view) override;
// Updates the visibility of the tray in the shelf based on the feature is
// enabled.
void UpdateVisibility();
// Icon of the tray. Unowned.
views::ImageView* icon_;
std::unique_ptr<TrayBubbleWrapper> bubble_;
};
} // namespace ash
#endif // ASH_SYSTEM_PHONEHUB_PHONE_HUB_TRAY_H_
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ash/system/media/media_tray.h" #include "ash/system/media/media_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"
#include "ash/system/phonehub/phone_hub_tray.h"
#include "ash/system/session/logout_button_tray.h" #include "ash/system/session/logout_button_tray.h"
#include "ash/system/status_area_widget_delegate.h" #include "ash/system/status_area_widget_delegate.h"
#include "ash/system/tray/status_area_overflow_button_tray.h" #include "ash/system/tray/status_area_overflow_button_tray.h"
...@@ -34,6 +35,7 @@ ...@@ -34,6 +35,7 @@
#include "base/containers/adapters.h" #include "base/containers/adapters.h"
#include "base/i18n/time_formatting.h" #include "base/i18n/time_formatting.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
#include "chromeos/services/assistant/public/cpp/features.h" #include "chromeos/services/assistant/public/cpp/features.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
...@@ -128,6 +130,11 @@ void StatusAreaWidget::Initialize() { ...@@ -128,6 +130,11 @@ void StatusAreaWidget::Initialize() {
AddTrayButton(media_tray_.get()); AddTrayButton(media_tray_.get());
} }
if (chromeos::features::IsPhoneHubEnabled()) {
phone_hub_tray_ = std::make_unique<PhoneHubTray>(shelf_);
AddTrayButton(phone_hub_tray_.get());
}
unified_system_tray_ = std::make_unique<UnifiedSystemTray>(shelf_); unified_system_tray_ = std::make_unique<UnifiedSystemTray>(shelf_);
AddTrayButton(unified_system_tray_.get()); AddTrayButton(unified_system_tray_.get());
......
...@@ -27,6 +27,7 @@ class LogoutButtonTray; ...@@ -27,6 +27,7 @@ class LogoutButtonTray;
class MediaTray; class MediaTray;
class OverviewButtonTray; class OverviewButtonTray;
class PaletteTray; class PaletteTray;
class PhoneHubTray;
class SelectToSpeakTray; class SelectToSpeakTray;
class Shelf; class Shelf;
class StatusAreaOverflowButtonTray; class StatusAreaOverflowButtonTray;
...@@ -220,6 +221,7 @@ class ASH_EXPORT StatusAreaWidget : public SessionObserver, ...@@ -220,6 +221,7 @@ class ASH_EXPORT StatusAreaWidget : public SessionObserver,
std::unique_ptr<UnifiedSystemTray> unified_system_tray_; std::unique_ptr<UnifiedSystemTray> unified_system_tray_;
std::unique_ptr<LogoutButtonTray> logout_button_tray_; std::unique_ptr<LogoutButtonTray> logout_button_tray_;
std::unique_ptr<PaletteTray> palette_tray_; std::unique_ptr<PaletteTray> palette_tray_;
std::unique_ptr<PhoneHubTray> phone_hub_tray_;
std::unique_ptr<StopRecordingButtonTray> stop_recording_button_tray_; std::unique_ptr<StopRecordingButtonTray> stop_recording_button_tray_;
std::unique_ptr<VirtualKeyboardTray> virtual_keyboard_tray_; std::unique_ptr<VirtualKeyboardTray> virtual_keyboard_tray_;
std::unique_ptr<BloomTray> bloom_tray_; std::unique_ptr<BloomTray> bloom_tray_;
......
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