clipboard_history_file_item_view.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2020 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/clipboard/views/clipboard_history_file_item_view.h"
  5. #include <array>
  6. #include "ash/public/cpp/style/scoped_light_mode_as_default.h"
  7. #include "ui/views/controls/image_view.h"
  8. #include "ui/views/view_class_properties.h"
  9. namespace {
  10. // The file icon's preferred size.
  11. constexpr gfx::Size kIconSize(20, 20);
  12. // The file icon's margin.
  13. constexpr auto kIconMargin = gfx::Insets::TLBR(0, 0, 0, 12);
  14. } // namespace
  15. namespace ash {
  16. ClipboardHistoryFileItemView::ClipboardHistoryFileItemView(
  17. const ClipboardHistoryItem* clipboard_history_item,
  18. views::MenuItemView* container)
  19. : ClipboardHistoryTextItemView(clipboard_history_item, container) {}
  20. ClipboardHistoryFileItemView::~ClipboardHistoryFileItemView() = default;
  21. std::unique_ptr<ClipboardHistoryFileItemView::ContentsView>
  22. ClipboardHistoryFileItemView::CreateContentsView() {
  23. auto contents_view = ClipboardHistoryTextItemView::CreateContentsView();
  24. // `file_icon` should be `contents_view`'s first child.
  25. file_icon_ = contents_view->AddChildViewAt(
  26. std::make_unique<views::ImageView>(), /*index=*/0);
  27. file_icon_->SetImageSize(kIconSize);
  28. file_icon_->SetProperty(views::kMarginsKey, kIconMargin);
  29. return contents_view;
  30. }
  31. const char* ClipboardHistoryFileItemView::GetClassName() const {
  32. return "ClipboardHistoryFileItemView";
  33. }
  34. void ClipboardHistoryFileItemView::OnThemeChanged() {
  35. ClipboardHistoryTextItemView::OnThemeChanged();
  36. // Use the light mode as default because the light mode is the default mode
  37. // of the native theme which decides the context menu's background color.
  38. // TODO(andrewxu): remove this line after https://crbug.com/1143009 is fixed.
  39. ScopedLightModeAsDefault scoped_light_mode_as_default;
  40. file_icon_->SetImage(ClipboardHistoryUtil::GetIconForFileClipboardItem(
  41. *clipboard_history_item(), base::UTF16ToUTF8(text())));
  42. }
  43. } // namespace ash