| 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/macros.h" | 8 #include "base/macros.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" |
| 11 | 11 |
| 12 // Selects the icon most closely matching the size constraints. This follows | 12 // Selects the square icon with the supported image MIME types and the specified |
| 13 // very basic heuristics -- improvements are welcome. | 13 // icon purpose that most closely matches the size constraints. |
| 14 // This follows very basic heuristics -- improvements are welcome. |
| 14 class ManifestIconSelector { | 15 class ManifestIconSelector { |
| 15 public: | 16 public: |
| 16 // Runs the algorithm to find the best matching icon in the icons listed in | 17 // Runs the algorithm to find the best matching icon in the icons listed in |
| 17 // the Manifest. | 18 // the Manifest. Size is defined in pixels. |
| 18 // | |
| 19 // Size is defined in pixels. | |
| 20 // | 19 // |
| 21 // Any icon returned will be close as possible to |ideal_icon_size_in_px| | 20 // Any icon returned will be close as possible to |ideal_icon_size_in_px| |
| 22 // with a size not less than |minimum_icon_size_in_px|. | 21 // with a size not less than |minimum_icon_size_in_px|. Additionally, it must |
| 22 // be square, have supported image MIME types, and have icon purpose |
| 23 // |purpose|. |
| 23 // | 24 // |
| 24 // Returns the icon url if a suitable icon is found. An empty URL otherwise. | 25 // Returns the icon url if a suitable icon is found. An empty URL otherwise. |
| 25 static GURL FindBestMatchingIcon( | 26 static GURL FindBestMatchingIcon( |
| 26 const std::vector<content::Manifest::Icon>& icons, | 27 const std::vector<content::Manifest::Icon>& icons, |
| 27 int ideal_icon_size_in_px, | 28 int ideal_icon_size_in_px, |
| 28 int minimum_icon_size_in_px); | 29 int minimum_icon_size_in_px, |
| 30 content::Manifest::Icon::IconPurpose purpose); |
| 29 | 31 |
| 30 private: | 32 private: |
| 31 ManifestIconSelector(int ideal_icon_size_in_px, | 33 DISALLOW_IMPLICIT_CONSTRUCTORS(ManifestIconSelector); |
| 32 int minimum_icon_size_in_px); | |
| 33 virtual ~ManifestIconSelector() {} | |
| 34 | |
| 35 // Returns the square icon that is the smallest icon larger than | |
| 36 // ideal_icon_size_in_px_ (if it exists), or the largest icon smaller than | |
| 37 // ideal_icon_size_in_px_ otherwise. | |
| 38 int FindClosestIconToIdealSize( | |
| 39 const std::vector<content::Manifest::Icon>& icons) const; | |
| 40 | |
| 41 // Runs the algorithm to find the best matching icon in the icons listed in | |
| 42 // the Manifest. | |
| 43 // Returns the icon url if a suitable icon is found. An empty URL otherwise. | |
| 44 int FindBestMatchingIcon( | |
| 45 const std::vector<content::Manifest::Icon>& icons) const; | |
| 46 | |
| 47 // Returns whether the |preferred_icon_size_in_pixels_| is in |sizes|. | |
| 48 bool IconSizesContainsPreferredSize( | |
| 49 const std::vector<gfx::Size>& sizes) const; | |
| 50 | |
| 51 // Returns whether a size bigger than |minimun_icon_size_in_pixels_| is in | |
| 52 // |sizes|. | |
| 53 bool IconSizesContainsBiggerThanMinimumSize( | |
| 54 const std::vector<gfx::Size>& sizes) const; | |
| 55 | |
| 56 // Returns an array containing the items in |icons| without the unsupported | |
| 57 // image MIME types. | |
| 58 static std::vector<content::Manifest::Icon> FilterIconsByType( | |
| 59 const std::vector<content::Manifest::Icon>& icons); | |
| 60 | |
| 61 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in |sizes|. | |
| 62 static bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes); | |
| 63 | |
| 64 const int ideal_icon_size_in_px_; | |
| 65 const int minimum_icon_size_in_px_; | |
| 66 | |
| 67 friend class ManifestIconSelectorTest; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(ManifestIconSelector); | |
| 70 }; | 34 }; |
| 71 | 35 |
| 72 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_ | 36 #endif // CHROME_BROWSER_MANIFEST_MANIFEST_ICON_SELECTOR_H_ |
| OLD | NEW |