message_center_style.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2012 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 "ui/message_center/message_center_style.h"
  5. #include <algorithm>
  6. #include "ui/gfx/color_palette.h"
  7. #include "ui/gfx/image/image_skia.h"
  8. #include "ui/gfx/paint_vector_icon.h"
  9. namespace message_center {
  10. gfx::Size GetImageSizeForContainerSize(const gfx::Size& container_size,
  11. const gfx::Size& image_size) {
  12. if (container_size.IsEmpty() || image_size.IsEmpty())
  13. return gfx::Size();
  14. gfx::Size scaled_size = image_size;
  15. double proportion =
  16. scaled_size.height() / static_cast<double>(scaled_size.width());
  17. // We never want to return an empty image given a non-empty container and
  18. // image, so round the height to 1.
  19. scaled_size.SetSize(container_size.width(),
  20. std::max(0.5 + container_size.width() * proportion, 1.0));
  21. if (scaled_size.height() > container_size.height()) {
  22. scaled_size.SetSize(
  23. std::max(0.5 + container_size.height() / proportion, 1.0),
  24. container_size.height());
  25. }
  26. return scaled_size;
  27. }
  28. } // namespace message_center