| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/tray/tray_info_label.h" | |
| 6 | |
| 7 #include "ash/system/tray/tray_popup_item_style.h" | |
| 8 #include "ash/system/tray/tray_popup_utils.h" | |
| 9 #include "ui/accessibility/ax_node_data.h" | |
| 10 #include "ui/base/l10n/l10n_util.h" | |
| 11 #include "ui/views/layout/fill_layout.h" | |
| 12 | |
| 13 namespace ash { | |
| 14 | |
| 15 TrayInfoLabel::TrayInfoLabel(TrayInfoLabel::Delegate* delegate, int message_id) | |
| 16 : ActionableView(nullptr /* owner */, TrayPopupInkDropStyle::FILL_BOUNDS), | |
| 17 label_(TrayPopupUtils::CreateDefaultLabel()), | |
| 18 message_id_(message_id), | |
| 19 delegate_(delegate) { | |
| 20 SetLayoutManager(new views::FillLayout); | |
| 21 | |
| 22 TriView* tri_view = TrayPopupUtils::CreateMultiTargetRowView(); | |
| 23 tri_view->SetInsets(gfx::Insets(0, | |
| 24 kMenuExtraMarginFromLeftEdge + | |
| 25 kTrayPopupPaddingHorizontal - | |
| 26 kTrayPopupLabelHorizontalPadding, | |
| 27 0, kTrayPopupPaddingHorizontal)); | |
| 28 tri_view->SetContainerVisible(TriView::Container::START, false); | |
| 29 tri_view->SetContainerVisible(TriView::Container::END, false); | |
| 30 tri_view->AddView(TriView::Container::CENTER, label_); | |
| 31 | |
| 32 AddChildView(tri_view); | |
| 33 | |
| 34 Update(message_id); | |
| 35 } | |
| 36 | |
| 37 void TrayInfoLabel::Update(int message_id) { | |
| 38 message_id_ = message_id; | |
| 39 | |
| 40 TrayPopupItemStyle::FontStyle font_style; | |
| 41 | |
| 42 if (IsClickable()) { | |
| 43 SetInkDropMode(InkDropHostView::InkDropMode::ON); | |
| 44 font_style = TrayPopupItemStyle::FontStyle::CLICKABLE_SYSTEM_INFO; | |
| 45 } else { | |
| 46 SetInkDropMode(InkDropHostView::InkDropMode::OFF); | |
| 47 font_style = TrayPopupItemStyle::FontStyle::SYSTEM_INFO; | |
| 48 } | |
| 49 | |
| 50 const TrayPopupItemStyle style(font_style); | |
| 51 style.SetupLabel(label_); | |
| 52 | |
| 53 label_->SetText(l10n_util::GetStringUTF16(message_id)); | |
| 54 } | |
| 55 | |
| 56 bool TrayInfoLabel::PerformAction(const ui::Event& event) { | |
| 57 if (IsClickable()) { | |
| 58 delegate_->OnLabelClicked(message_id_); | |
| 59 return true; | |
| 60 } | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 void TrayInfoLabel::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
| 65 if (IsClickable()) | |
| 66 node_data->role = ui::AX_ROLE_BUTTON; | |
| 67 else | |
| 68 node_data->role = ui::AX_ROLE_LABEL_TEXT; | |
| 69 } | |
| 70 | |
| 71 bool TrayInfoLabel::IsClickable() { | |
| 72 if (delegate_) | |
| 73 return delegate_->IsLabelClickable(message_id_); | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 } // namespace ash | |
| OLD | NEW |