phone_hub_recent_app_button.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2021 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/phonehub/phone_hub_recent_app_button.h"
  5. #include "ash/style/ash_color_provider.h"
  6. #include "ash/style/style_util.h"
  7. #include "ui/base/metadata/metadata_impl_macros.h"
  8. #include "ui/color/color_id.h"
  9. #include "ui/gfx/image/image_skia_operations.h"
  10. #include "ui/views/controls/focus_ring.h"
  11. #include "ui/views/controls/highlight_path_generator.h"
  12. #include "ui/views/controls/image_view.h"
  13. namespace ash {
  14. namespace {
  15. // Appearance in DIPs.
  16. constexpr int kRecentAppButtonSize = 32;
  17. } // namespace
  18. PhoneHubRecentAppButton::PhoneHubRecentAppButton(
  19. const gfx::Image& icon,
  20. const std::u16string& visible_app_name,
  21. PressedCallback callback)
  22. : views::ImageButton(callback) {
  23. SetImage(views::Button::STATE_NORMAL,
  24. gfx::ImageSkiaOperations::CreateResizedImage(
  25. icon.AsImageSkia(), skia::ImageOperations::RESIZE_BEST,
  26. gfx::Size(kRecentAppButtonSize, kRecentAppButtonSize)));
  27. SetImageHorizontalAlignment(ALIGN_CENTER);
  28. SetImageVerticalAlignment(ALIGN_MIDDLE);
  29. StyleUtil::SetUpInkDropForButton(this);
  30. views::InstallCircleHighlightPathGenerator(this);
  31. SetAccessibleName(visible_app_name);
  32. SetTooltipText(visible_app_name);
  33. views::FocusRing::Get(this)->SetColorId(ui::kColorAshFocusRing);
  34. }
  35. PhoneHubRecentAppButton::~PhoneHubRecentAppButton() = default;
  36. gfx::Size PhoneHubRecentAppButton::CalculatePreferredSize() const {
  37. return gfx::Size(kRecentAppButtonSize, kRecentAppButtonSize);
  38. }
  39. void PhoneHubRecentAppButton::PaintButtonContents(gfx::Canvas* canvas) {
  40. cc::PaintFlags flags;
  41. flags.setAntiAlias(true);
  42. flags.setColor(AshColorProvider::Get()->GetControlsLayerColor(
  43. AshColorProvider::ControlsLayerType::kControlBackgroundColorInactive));
  44. flags.setStyle(cc::PaintFlags::kFill_Style);
  45. canvas->DrawPath(views::GetHighlightPath(this), flags);
  46. views::ImageButton::PaintButtonContents(canvas);
  47. }
  48. BEGIN_METADATA(PhoneHubRecentAppButton, views::ImageButton)
  49. END_METADATA
  50. } // namespace ash