summaryrefslogtreecommitdiffstats
path: root/ui/gfx/favicon_size.cc
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-26 18:25:06 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-26 18:25:06 +0000
commit5097e2d21a11e4f29875c2d66489832311e5038f (patch)
treead1b5f2783c8f91ff6d02fb8e78bf6f9267028d7 /ui/gfx/favicon_size.cc
parent5af129a22b949932f6d856e833b321db916968fe (diff)
downloadchromium_src-5097e2d21a11e4f29875c2d66489832311e5038f.zip
chromium_src-5097e2d21a11e4f29875c2d66489832311e5038f.tar.gz
chromium_src-5097e2d21a11e4f29875c2d66489832311e5038f.tar.bz2
ui/gfx: Refactor favicon_size.h
- Put it into a gfx namespace. - Define the constant into the source file instead. - Rename the function from calc_favicon_target_size to CalculateFaviconTargetSize, so it matches with our style guide. - Move the implementation of the function to the source file. R=sky@chromium.org Review URL: http://codereview.chromium.org/8037011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/favicon_size.cc')
-rw-r--r--ui/gfx/favicon_size.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/ui/gfx/favicon_size.cc b/ui/gfx/favicon_size.cc
new file mode 100644
index 0000000..d0ba48a
--- /dev/null
+++ b/ui/gfx/favicon_size.cc
@@ -0,0 +1,25 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/favicon_size.h"
+
+namespace gfx {
+
+const int kFaviconSize = 16;
+
+void CalculateFaviconTargetSize(int* width, int* height) {
+ if (*width > kFaviconSize || *height > kFaviconSize) {
+ // Too big, resize it maintaining the aspect ratio.
+ float aspect_ratio = static_cast<float>(*width) /
+ static_cast<float>(*height);
+ *height = kFaviconSize;
+ *width = static_cast<int>(aspect_ratio * *height);
+ if (*width > kFaviconSize) {
+ *width = kFaviconSize;
+ *height = static_cast<int>(*width / aspect_ratio);
+ }
+ }
+}
+
+} // namespace gfx