Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1728)

Unified Diff: ash/system/session/logout_button_tray.cc

Issue 2807693002: Make LogoutButtonTray a regular View (Closed)
Patch Set: Rebased Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/session/logout_button_tray.cc
diff --git a/ash/system/session/logout_button_tray.cc b/ash/system/session/logout_button_tray.cc
index fb0cf211a8ee030d9575e3fc9fe1722a9e06b6be..4cd7017d41e2ce11eeb65fccd12568ad4b35b819 100644
--- a/ash/system/session/logout_button_tray.cc
+++ b/ash/system/session/logout_button_tray.cc
@@ -4,83 +4,59 @@
#include "ash/system/session/logout_button_tray.h"
-#include <memory>
-#include <utility>
-
-#include "ash/public/cpp/shelf_types.h"
-#include "ash/resources/grit/ash_resources.h"
#include "ash/resources/vector_icons/vector_icons.h"
-#include "ash/shelf/wm_shelf_util.h"
+#include "ash/shelf/wm_shelf.h"
#include "ash/shell.h"
#include "ash/system/session/logout_confirmation_controller.h"
+#include "ash/system/status_area_widget.h"
#include "ash/system/tray/system_tray_controller.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
-#include "ash/system/tray/tray_utils.h"
+#include "ash/system/tray/tray_container.h"
#include "ash/system/user/login_status.h"
-#include "base/logging.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "ui/events/event.h"
+#include "ui/accessibility/ax_node_data.h"
#include "ui/gfx/color_palette.h"
-#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/paint_vector_icon.h"
-#include "ui/views/bubble/tray_bubble_view.h"
-#include "ui/views/controls/button/label_button.h"
-#include "ui/views/controls/button/label_button_border.h"
#include "ui/views/controls/button/md_text_button.h"
-#include "ui/views/painter.h"
+#include "ui/views/layout/fill_layout.h"
namespace ash {
LogoutButtonTray::LogoutButtonTray(WmShelf* wm_shelf)
- : TrayBackgroundView(wm_shelf, false),
- button_(nullptr),
- login_status_(LoginStatus::NOT_LOGGED_IN),
+ : wm_shelf_(wm_shelf),
+ container_(new TrayContainer(wm_shelf)),
+ button_(views::MdTextButton::Create(this, base::string16())),
show_logout_button_in_tray_(false) {
- views::MdTextButton* button =
- views::MdTextButton::Create(this, base::string16());
- button->SetProminent(true);
- button->SetBgColorOverride(gfx::kGoogleRed700);
+ SetLayoutManager(new views::FillLayout);
+ AddChildView(container_);
+
+ button_->SetProminent(true);
+ button_->SetBgColorOverride(gfx::kGoogleRed700);
// Base font size + 2 = 14.
// TODO(estade): should this 2 be shared with other tray views? See
// crbug.com/623987
- button->AdjustFontSize(2);
- button_ = button;
+ button_->AdjustFontSize(2);
- // Since LogoutButtonTray has a red background and it is distinguished
- // by itself, no separator is needed on its right side.
- set_separator_visibility(false);
- tray_container()->AddChildView(button_);
+ container_->AddChildView(button_);
Shell::Get()->system_tray_notifier()->AddLogoutButtonObserver(this);
+ SetVisible(false);
}
LogoutButtonTray::~LogoutButtonTray() {
Shell::Get()->system_tray_notifier()->RemoveLogoutButtonObserver(this);
}
-void LogoutButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
- // We must first update the button so that
- // TrayBackgroundView::SetShelfAlignment() can lay it out correctly.
- UpdateButtonTextAndImage(login_status_, alignment);
- TrayBackgroundView::SetShelfAlignment(alignment);
+void LogoutButtonTray::UpdateAfterShelfAlignmentChange() {
+ // We must first update the button so that |container_| can lay it out
+ // correctly.
+ UpdateButtonTextAndImage();
+ container_->UpdateAfterShelfAlignmentChange();
}
-base::string16 LogoutButtonTray::GetAccessibleNameForTray() {
- return button_->GetText();
-}
-
-void LogoutButtonTray::HideBubbleWithView(
- const views::TrayBubbleView* bubble_view) {}
-
-void LogoutButtonTray::ClickedOutsideBubble() {}
-
void LogoutButtonTray::ButtonPressed(views::Button* sender,
const ui::Event& event) {
- if (sender != button_) {
- TrayBackgroundView::ButtonPressed(sender, event);
- return;
- }
+ DCHECK_EQ(button_, sender);
if (dialog_duration_ <= base::TimeDelta()) {
// Sign out immediately if |dialog_duration_| is non-positive.
@@ -91,6 +67,11 @@ void LogoutButtonTray::ButtonPressed(views::Button* sender,
}
}
+void LogoutButtonTray::GetAccessibleNodeData(ui::AXNodeData* node_data) {
+ View::GetAccessibleNodeData(node_data);
+ node_data->SetName(button_->GetText());
+}
+
void LogoutButtonTray::OnShowLogoutButtonInTrayChanged(bool show) {
show_logout_button_in_tray_ = show;
UpdateVisibility();
@@ -100,29 +81,29 @@ void LogoutButtonTray::OnLogoutDialogDurationChanged(base::TimeDelta duration) {
dialog_duration_ = duration;
}
-void LogoutButtonTray::UpdateAfterLoginStatusChange(LoginStatus login_status) {
- UpdateButtonTextAndImage(login_status, shelf_alignment());
+void LogoutButtonTray::UpdateAfterLoginStatusChange() {
+ UpdateButtonTextAndImage();
}
void LogoutButtonTray::UpdateVisibility() {
+ LoginStatus login_status = wm_shelf_->GetStatusAreaWidget()->login_status();
SetVisible(show_logout_button_in_tray_ &&
- login_status_ != LoginStatus::NOT_LOGGED_IN &&
- login_status_ != LoginStatus::LOCKED);
+ login_status != LoginStatus::NOT_LOGGED_IN &&
+ login_status != LoginStatus::LOCKED);
}
-void LogoutButtonTray::UpdateButtonTextAndImage(LoginStatus login_status,
- ShelfAlignment alignment) {
- login_status_ = login_status;
+void LogoutButtonTray::UpdateButtonTextAndImage() {
+ LoginStatus login_status = wm_shelf_->GetStatusAreaWidget()->login_status();
const base::string16 title =
user::GetLocalizedSignOutStringForStatus(login_status, false);
- if (IsHorizontalAlignment(alignment)) {
+ if (wm_shelf_->IsHorizontalAlignment()) {
button_->SetText(title);
- button_->SetImage(views::LabelButton::STATE_NORMAL, gfx::ImageSkia());
+ button_->SetImage(views::Button::STATE_NORMAL, gfx::ImageSkia());
button_->SetMinSize(gfx::Size(0, kTrayItemSize));
} else {
button_->SetText(base::string16());
button_->SetAccessibleName(title);
- button_->SetImage(views::LabelButton::STATE_NORMAL,
+ button_->SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kShelfLogoutIcon, kTrayIconColor));
button_->SetMinSize(gfx::Size(kTrayItemSize, kTrayItemSize));
}

Powered by Google App Engine
This is Rietveld 408576698