huangs | 3382fc9d | 2015-02-11 22:18:38 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_H_ |
| 6 | #define COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_H_ |
| 7 | |
beaudoin | 3e75e592 | 2015-04-22 17:12:14 | [diff] [blame] | 8 | #include "base/memory/ref_counted_memory.h" |
huangs | 3382fc9d | 2015-02-11 22:18:38 | [diff] [blame] | 9 | #include "third_party/skia/include/core/SkColor.h" |
| 10 | |
| 11 | namespace favicon_base { |
| 12 | |
| 13 | // Styling specifications of a fallback icon. The icon is composed of a solid |
| 14 | // rounded square containing a single letter. The specification excludes the |
| 15 | // icon URL and size, which are given when the icon is rendered. |
| 16 | struct FallbackIconStyle { |
| 17 | FallbackIconStyle(); |
| 18 | ~FallbackIconStyle(); |
| 19 | |
| 20 | // If any member changes, also update FallbackIconStyleBuilder. |
| 21 | |
| 22 | // Icon background fill color. |
| 23 | SkColor background_color; |
| 24 | |
| 25 | // Icon text color. |
| 26 | SkColor text_color; |
| 27 | |
| 28 | // Ratio in [0.0, 1.0] of the text font size (pixels) to the icon size. |
| 29 | double font_size_ratio; |
| 30 | |
| 31 | // The roundness of the icon's corners. 0 => square icon, 1 => circle icon. |
| 32 | double roundness; |
huangs | 73fa324 | 2015-05-08 06:27:15 | [diff] [blame] | 33 | |
| 34 | bool operator==(const FallbackIconStyle& other) const; |
huangs | 3382fc9d | 2015-02-11 22:18:38 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | // Reassigns |style|'s |text_color| to matches well against |background_color|. |
| 38 | void MatchFallbackIconTextColorAgainstBackgroundColor(FallbackIconStyle* style); |
| 39 | |
| 40 | // Returns whether |style| values are within bounds. |
| 41 | bool ValidateFallbackIconStyle(const FallbackIconStyle& style); |
| 42 | |
beaudoin | 3e75e592 | 2015-04-22 17:12:14 | [diff] [blame] | 43 | // Set |style|'s background color to the dominant color of |bitmap_data|, |
| 44 | // clamping luminance down to a reasonable maximum value so that light text is |
| 45 | // readable. |
| 46 | void SetDominantColorAsBackground( |
| 47 | const scoped_refptr<base::RefCountedMemory>& bitmap_data, |
| 48 | FallbackIconStyle* style); |
| 49 | |
huangs | 3382fc9d | 2015-02-11 22:18:38 | [diff] [blame] | 50 | } // namespace favicon_base |
| 51 | |
| 52 | #endif // COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_H_ |