network_list_header_view.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2022 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. #include "ash/system/network/network_list_header_view.h"
  5. #include <string>
  6. #include "ash/ash_export.h"
  7. #include "ash/constants/ash_features.h"
  8. #include "ash/style/ash_color_provider.h"
  9. #include "ash/system/tray/tray_popup_utils.h"
  10. #include "ash/system/tray/tri_view.h"
  11. #include "ui/base/l10n/l10n_util.h"
  12. #include "ui/gfx/font.h"
  13. #include "ui/gfx/font_list.h"
  14. #include "ui/views/controls/image_view.h"
  15. #include "ui/views/controls/label.h"
  16. #include "ui/views/layout/fill_layout.h"
  17. #include "ui/views/view.h"
  18. namespace ash {
  19. namespace {
  20. const int kLineHeight = 20;
  21. } // namespace
  22. NetworkListHeaderView::NetworkListHeaderView(int label_id) {
  23. DCHECK(ash::features::IsQuickSettingsNetworkRevampEnabled());
  24. TrayPopupUtils::ConfigureAsStickyHeader(this);
  25. SetLayoutManager(std::make_unique<views::FillLayout>());
  26. container_ = TrayPopupUtils::CreateSubHeaderRowView(/*start_visible=*/true);
  27. container_->AddView(TriView::Container::START,
  28. TrayPopupUtils::CreateMainImageView());
  29. AddChildView(container_);
  30. AddTitleView(label_id);
  31. }
  32. void NetworkListHeaderView::AddTitleView(int label_id) {
  33. DCHECK(container_);
  34. views::Label* const titleLabelView = TrayPopupUtils::CreateDefaultLabel();
  35. titleLabelView->SetEnabledColor(
  36. ash::AshColorProvider::Get()->GetContentLayerColor(
  37. ash::AshColorProvider::ContentLayerType::kTextColorPrimary));
  38. TrayPopupUtils::SetLabelFontList(titleLabelView,
  39. TrayPopupUtils::FontStyle::kSubHeader);
  40. titleLabelView->SetLineHeight(kLineHeight);
  41. titleLabelView->SetText(l10n_util::GetStringUTF16(label_id));
  42. titleLabelView->SetID(kTitleLabelViewId);
  43. container_->AddView(TriView::Container::CENTER, titleLabelView);
  44. }
  45. } // namespace ash