Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: components/favicon_base/fallback_icon_style_builder.h

Issue 835903005: [Favicon] Add new fallback icon rendering flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding new host chrome://fallback-icon. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_BUILDER_H_
6 #define COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_BUILDER_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/logging.h"
12 #include "base/macros.h"
13 #include "components/favicon_base/favicon_types.h"
14 #include "third_party/skia/include/core/SkColor.h"
15
16 namespace favicon_base {
17
18 // Helper to initialize FallbackIconStyle. A caller can specify values for data
19 // members, then call Build() to assign defaults for missing values, and return
20 // an intance of FallbackIconStyle. Validated parsing from a specification
21 // string is also supported.
22 class FallbackIconStyleBuilder {
23 public:
24 // One member for each element in FallbackIconStyle.
25 enum DataMember {
26 BACKGROUND_COLOR = 1 << 0,
27 TEXT_COLOR = 1 << 1,
28 FONT_SIZE_RATIO = 1 << 2,
29 ROUNDNESS = 1 << 3,
30 };
31
32 FallbackIconStyleBuilder();
33 ~FallbackIconStyleBuilder();
34
35 // Clear all data members and returns false.
36 bool Reset();
37
38 // Determines whether a given data member is initialized.
39 bool Has(DataMember mask) const;
40
41 // Setters, which does not validate |value|.
42 void SetBackgroundColor(SkColor value);
43
44 void SetTextColor(SkColor value);
45
46 void SetFontSizeRatio(double value);
47
48 void SetRoundness(double value);
49
50 // Parses |str| as |RRGGBBAA|, |RRGGBB|, or |RGB| hex color, no leading '#'.
51 // Returns true and writes to |color| on success.
52 static bool ParseColor(const std::string& str, SkColor* color);
53
54 // Parses a comma-separated list of specification string and populates
55 // relevent fields. If parse is successful, returns true. Otherwise clear all
56 // fields and return false.
57 // Specification string is:
58 // <background_color>,<text_color>,<font_size_ratio>,<corner_radius_ratio>
59 // where:
60 // <background_color> Is color in RRGBBBAA, RRGGBB, or RGB hex format,
61 // <text_color> Is color in RRGBBBAA, RRGGBB, or RGB hex format,
62 // <font_size_ratio> Is a double in [0.0, 1.0].
63 // <corner_radius_ratio> Is a double in [0.0, 0.5].
64 // Fields are optional.
65 bool Parse(const std::string& specs_str);
66
67 // Initializes all data members to default values. These are all constants,
68 // except |text_color_|, which is adjusted based on the |background_color_|
69 // luminance so it can be seen.
70 void AssignDefaults();
71
72 // Assigns defaults if necessary, and returns const ref to |specs_|.
73 const FallbackIconStyle& Build();
74
75 private:
76 // A bit mask (over DataMember) to store intialization states of data members.
77 unsigned int is_init_;
78
79 // Storage of data members.
80 FallbackIconStyle specs_;
81
82 DISALLOW_COPY_AND_ASSIGN(FallbackIconStyleBuilder);
83 };
84
85 } // namespace favicon_base
86
87 #endif // COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698