collapse_button.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2018 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/unified/collapse_button.h"
  5. #include "ash/resources/vector_icons/vector_icons.h"
  6. #include "ash/strings/grit/ash_strings.h"
  7. #include "ash/style/icon_button.h"
  8. #include "ui/base/l10n/l10n_util.h"
  9. #include "ui/base/metadata/metadata_impl_macros.h"
  10. #include "ui/gfx/scoped_canvas.h"
  11. namespace ash {
  12. CollapseButton::CollapseButton(PressedCallback callback)
  13. : IconButton(std::move(callback),
  14. IconButton::Type::kSmallFloating,
  15. &kUnifiedMenuExpandIcon,
  16. IDS_ASH_STATUS_TRAY_COLLAPSE) {}
  17. CollapseButton::~CollapseButton() = default;
  18. void CollapseButton::SetExpandedAmount(double expanded_amount) {
  19. expanded_amount_ = expanded_amount;
  20. if (expanded_amount == 0.0 || expanded_amount == 1.0) {
  21. SetTooltipText(l10n_util::GetStringUTF16(expanded_amount == 1.0
  22. ? IDS_ASH_STATUS_TRAY_COLLAPSE
  23. : IDS_ASH_STATUS_TRAY_EXPAND));
  24. }
  25. SchedulePaint();
  26. }
  27. void CollapseButton::PaintButtonContents(gfx::Canvas* canvas) {
  28. gfx::ScopedCanvas scoped(canvas);
  29. canvas->Translate(gfx::Vector2d(size().width() / 2, size().height() / 2));
  30. canvas->sk_canvas()->rotate(expanded_amount_ * 180.);
  31. gfx::ImageSkia image = GetImageToPaint();
  32. canvas->DrawImageInt(image, -image.width() / 2, -image.height() / 2);
  33. }
  34. BEGIN_METADATA(CollapseButton, IconButton)
  35. END_METADATA
  36. } // namespace ash