1 // Copyright 2015 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.
5 #ifndef CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
6 #define CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_
8 #include "base/basictypes.h"
9 #include "content/public/common/manifest.h"
14 } // namespace content
24 // Selects the icon most closely matching the size constraints. This follows
25 // very basic heuristics -- improvements are welcome.
26 class ManifestIconSelector
{
28 // Runs the algorithm to find the best matching icon in the icons listed in
31 // Size is defined in Android's density-independent pixels (dp):
32 // http://developer.android.com/guide/practices/screens_support.html
33 // If/when this class is generalized, it may be a good idea to switch this to
34 // taking in pixels, instead.
36 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
37 static GURL
FindBestMatchingIcon(
38 const std::vector
<content::Manifest::Icon
>& icons
,
39 float preferred_icon_size_in_dp
,
40 const gfx::Screen
* screen
);
43 explicit ManifestIconSelector(float preferred_icon_size_in_pixels
);
44 virtual ~ManifestIconSelector() {}
46 // Runs the algorithm to find the best matching icon in the icons listed in
48 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
49 GURL
FindBestMatchingIcon(
50 const std::vector
<content::Manifest::Icon
>& icons
,
53 // Runs an algorithm only based on icon declared sizes. It will try to find
54 // size that is the closest to preferred_icon_size_in_pixels_ but bigger than
55 // preferred_icon_size_in_pixels_ if possible.
56 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
57 GURL
FindBestMatchingIconForDensity(
58 const std::vector
<content::Manifest::Icon
>& icons
,
61 // Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|.
62 bool IconSizesContainsPreferredSize(const std::vector
<gfx::Size
>& sizes
);
64 // Returns an array containing the items in |icons| without the unsupported
66 static std::vector
<content::Manifest::Icon
> FilterIconsByType(
67 const std::vector
<content::Manifest::Icon
>& icons
);
69 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|.
70 static bool IconSizesContainsAny(const std::vector
<gfx::Size
>& sizes
);
72 const int preferred_icon_size_in_pixels_
;
74 friend class ManifestIconSelectorTest
;
76 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector
);
79 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_