| Index: components/favicon_base/fallback_icon_style_builder.h
|
| diff --git a/components/favicon_base/fallback_icon_style_builder.h b/components/favicon_base/fallback_icon_style_builder.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..31fe6e63c71fc5400b27e271cc9322ada1a5f0b9
|
| --- /dev/null
|
| +++ b/components/favicon_base/fallback_icon_style_builder.h
|
| @@ -0,0 +1,87 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_BUILDER_H_
|
| +#define COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_BUILDER_H_
|
| +
|
| +#include <memory>
|
| +#include <string>
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/macros.h"
|
| +#include "components/favicon_base/favicon_types.h"
|
| +#include "third_party/skia/include/core/SkColor.h"
|
| +
|
| +namespace favicon_base {
|
| +
|
| +// Helper to initialize FallbackIconStyle. A caller can specify values for data
|
| +// members, then call Build() to assign defaults for missing values, and return
|
| +// an intance of FallbackIconStyle. Validated parsing from a specification
|
| +// string is also supported.
|
| +class FallbackIconStyleBuilder {
|
| + public:
|
| + // One member for each element in FallbackIconStyle.
|
| + enum DataMember {
|
| + BACKGROUND_COLOR = 1 << 0,
|
| + TEXT_COLOR = 1 << 1,
|
| + FONT_SIZE_RATIO = 1 << 2,
|
| + ROUNDNESS = 1 << 3,
|
| + };
|
| +
|
| + FallbackIconStyleBuilder();
|
| + ~FallbackIconStyleBuilder();
|
| +
|
| + // Clear all data members and returns false.
|
| + bool Reset();
|
| +
|
| + // Determines whether a given data member is initialized.
|
| + bool Has(DataMember mask) const;
|
| +
|
| + // Setters, which does not validate |value|.
|
| + void SetBackgroundColor(SkColor value);
|
| +
|
| + void SetTextColor(SkColor value);
|
| +
|
| + void SetFontSizeRatio(double value);
|
| +
|
| + void SetRoundness(double value);
|
| +
|
| + // Parses |str| as |RRGGBBAA|, |RRGGBB|, or |RGB| hex color, no leading '#'.
|
| + // Returns true and writes to |color| on success.
|
| + static bool ParseColor(const std::string& str, SkColor* color);
|
| +
|
| + // Parses a comma-separated list of specification string and populates
|
| + // relevent fields. If parse is successful, returns true. Otherwise clear all
|
| + // fields and return false.
|
| + // Specification string is:
|
| + // <background_color>,<text_color>,<font_size_ratio>,<corner_radius_ratio>
|
| + // where:
|
| + // <background_color> Is color in RRGBBBAA, RRGGBB, or RGB hex format,
|
| + // <text_color> Is color in RRGBBBAA, RRGGBB, or RGB hex format,
|
| + // <font_size_ratio> Is a double in [0.0, 1.0].
|
| + // <corner_radius_ratio> Is a double in [0.0, 0.5].
|
| + // Fields are optional.
|
| + bool Parse(const std::string& specs_str);
|
| +
|
| + // Initializes all data members to default values. These are all constants,
|
| + // except |text_color_|, which is adjusted based on the |background_color_|
|
| + // luminance so it can be seen.
|
| + void AssignDefaults();
|
| +
|
| + // Assigns defaults if necessary, and returns const ref to |specs_|.
|
| + const FallbackIconStyle& Build();
|
| +
|
| + private:
|
| + // A bit mask (over DataMember) to store intialization states of data members.
|
| + unsigned int is_init_;
|
| +
|
| + // Storage of data members.
|
| + FallbackIconStyle specs_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FallbackIconStyleBuilder);
|
| +};
|
| +
|
| +} // namespace favicon_base
|
| +
|
| +#endif // COMPONENTS_FAVICON_BASE_FALLBACK_ICON_STYLE_BUILDER_H_
|
|
|