OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_ | 5 #ifndef CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_ |
6 #define CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_ | 6 #define CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "content/public/common/manifest.h" | 9 #include "content/public/common/manifest.h" |
10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 class ManifestIconSelector { | 26 class ManifestIconSelector { |
27 public: | 27 public: |
28 // Runs the algorithm to find the best matching icon in the icons listed in | 28 // Runs the algorithm to find the best matching icon in the icons listed in |
29 // the Manifest. | 29 // the Manifest. |
30 // | 30 // |
31 // Size is defined in Android's density-independent pixels (dp): | 31 // Size is defined in Android's density-independent pixels (dp): |
32 // http://developer.android.com/guide/practices/screens_support.html | 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 | 33 // If/when this class is generalized, it may be a good idea to switch this to |
34 // taking in pixels, instead. | 34 // taking in pixels, instead. |
35 // | 35 // |
| 36 // The icon returned will have a minimum size of an image one density bucket |
| 37 // smaller than the device denisity * preferred_icon_size_in_dp. |
| 38 // |
36 // Returns the icon url if a suitable icon is found. An empty URL otherwise. | 39 // Returns the icon url if a suitable icon is found. An empty URL otherwise. |
37 static GURL FindBestMatchingIcon( | 40 static GURL FindBestMatchingIcon( |
38 const std::vector<content::Manifest::Icon>& icons, | 41 const std::vector<content::Manifest::Icon>& icons, |
39 float preferred_icon_size_in_dp, | 42 float preferred_icon_size_in_dp, |
40 const gfx::Screen* screen); | 43 const gfx::Screen* screen); |
41 | 44 |
42 private: | 45 private: |
43 explicit ManifestIconSelector(float preferred_icon_size_in_pixels); | 46 ManifestIconSelector(float preferred_icon_size_in_pixels, |
| 47 float minimum_icon_size_in_pixels); |
44 virtual ~ManifestIconSelector() {} | 48 virtual ~ManifestIconSelector() {} |
45 | 49 |
46 // Runs the algorithm to find the best matching icon in the icons listed in | 50 // Runs the algorithm to find the best matching icon in the icons listed in |
47 // the Manifest. | 51 // the Manifest. |
48 // Returns the icon url if a suitable icon is found. An empty URL otherwise. | 52 // Returns the icon url if a suitable icon is found. An empty URL otherwise. |
49 GURL FindBestMatchingIcon( | 53 int FindBestMatchingIcon( |
50 const std::vector<content::Manifest::Icon>& icons, | 54 const std::vector<content::Manifest::Icon>& icons, |
51 float density); | 55 float density); |
52 | 56 |
53 // Runs an algorithm only based on icon declared sizes. It will try to find | 57 // 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 | 58 // size that is the closest to preferred_icon_size_in_pixels_ but bigger than |
55 // preferred_icon_size_in_pixels_ if possible. | 59 // preferred_icon_size_in_pixels_ if possible. |
56 // Returns the icon url if a suitable icon is found. An empty URL otherwise. | 60 // Returns the index of a suitable icon if one is found. -1 otherwise. |
57 GURL FindBestMatchingIconForDensity( | 61 int FindBestMatchingIconForDensity( |
58 const std::vector<content::Manifest::Icon>& icons, | 62 const std::vector<content::Manifest::Icon>& icons, |
59 float density); | 63 float density); |
60 | 64 |
61 // Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|. | 65 // Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|. |
62 bool IconSizesContainsPreferredSize(const std::vector<gfx::Size>& sizes); | 66 bool IconSizesContainsPreferredSize(const std::vector<gfx::Size>& sizes); |
63 | 67 |
| 68 // Returns whether a size bigger than |minimun_icon_size_in_pixels_| is in |
| 69 // |sizes|. |
| 70 bool IconSizesContainsBiggerThanMinimum(const std::vector<gfx::Size>& sizes); |
| 71 |
64 // Returns an array containing the items in |icons| without the unsupported | 72 // Returns an array containing the items in |icons| without the unsupported |
65 // image MIME types. | 73 // image MIME types. |
66 static std::vector<content::Manifest::Icon> FilterIconsByType( | 74 static std::vector<content::Manifest::Icon> FilterIconsByType( |
67 const std::vector<content::Manifest::Icon>& icons); | 75 const std::vector<content::Manifest::Icon>& icons); |
68 | 76 |
69 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|. | 77 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|. |
70 static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes); | 78 static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes); |
71 | 79 |
72 const int preferred_icon_size_in_pixels_; | 80 const int preferred_icon_size_in_pixels_; |
| 81 const int minimum_icon_size_in_pixels_; |
73 | 82 |
74 friend class ManifestIconSelectorTest; | 83 friend class ManifestIconSelectorTest; |
75 | 84 |
76 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector); | 85 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector); |
77 }; | 86 }; |
78 | 87 |
79 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_ | 88 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_ |
OLD | NEW |