favicon_size.cc 766 B

12345678910111213141516171819202122232425
  1. // Copyright (c) 2011 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/gfx/favicon_size.h"
  5. namespace gfx {
  6. const int kFaviconSize = 16;
  7. void CalculateFaviconTargetSize(int* width, int* height) {
  8. if (*width > kFaviconSize || *height > kFaviconSize) {
  9. // Too big, resize it maintaining the aspect ratio.
  10. float aspect_ratio = static_cast<float>(*width) /
  11. static_cast<float>(*height);
  12. *height = kFaviconSize;
  13. *width = static_cast<int>(aspect_ratio * *height);
  14. if (*width > kFaviconSize) {
  15. *width = kFaviconSize;
  16. *height = static_cast<int>(*width / aspect_ratio);
  17. }
  18. }
  19. }
  20. } // namespace gfx