1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
7 #include "base/logging.h"
8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h"
10 #include "grit/generated_resources.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/resource/resource_bundle.h"
16 bool IsSureError(const autofill::ValidityMessage& message) {
17 return message.sure && !message.text.empty();
24 static const base::char16 kRangeSeparator = '|';
26 DialogNotification::DialogNotification() : type_(NONE) {}
28 DialogNotification::DialogNotification(Type type, const string16& display_text)
30 display_text_(display_text),
32 // If there's a range separated by bars, mark that as the anchor text.
33 std::vector<base::string16> pieces;
34 base::SplitStringDontTrim(display_text, kRangeSeparator, &pieces);
35 if (pieces.size() > 1) {
36 size_t start = pieces[0].size();
37 size_t end = start + pieces[1].size();
38 link_range_ = gfx::Range(start, end);
39 display_text_ = JoinString(pieces, string16());
43 DialogNotification::~DialogNotification() {}
45 SkColor DialogNotification::GetBackgroundColor() const {
47 case DialogNotification::EXPLANATORY_MESSAGE:
48 case DialogNotification::WALLET_USAGE_CONFIRMATION:
49 return SkColorSetRGB(0xf5, 0xf5, 0xf5);
50 case DialogNotification::REQUIRED_ACTION:
51 case DialogNotification::WALLET_ERROR:
52 return SkColorSetRGB(0xfc, 0xf3, 0xbf);
53 case DialogNotification::DEVELOPER_WARNING:
54 case DialogNotification::SECURITY_WARNING:
55 case DialogNotification::VALIDATION_ERROR:
57 case DialogNotification::NONE:
58 return SK_ColorTRANSPARENT;
62 return SK_ColorTRANSPARENT;
65 SkColor DialogNotification::GetBorderColor() const {
67 case DialogNotification::EXPLANATORY_MESSAGE:
68 case DialogNotification::WALLET_USAGE_CONFIRMATION:
69 return SkColorSetRGB(0xe5, 0xe5, 0xe5);
70 case DialogNotification::REQUIRED_ACTION:
71 case DialogNotification::WALLET_ERROR:
72 case DialogNotification::DEVELOPER_WARNING:
73 case DialogNotification::SECURITY_WARNING:
74 case DialogNotification::VALIDATION_ERROR:
75 case DialogNotification::NONE:
76 return GetBackgroundColor();
80 return SK_ColorTRANSPARENT;
83 SkColor DialogNotification::GetTextColor() const {
85 case DialogNotification::REQUIRED_ACTION:
86 case DialogNotification::WALLET_ERROR:
87 case DialogNotification::EXPLANATORY_MESSAGE:
88 case DialogNotification::WALLET_USAGE_CONFIRMATION:
89 return SkColorSetRGB(102, 102, 102);
90 case DialogNotification::DEVELOPER_WARNING:
91 case DialogNotification::SECURITY_WARNING:
92 case DialogNotification::VALIDATION_ERROR:
94 case DialogNotification::NONE:
95 return SK_ColorTRANSPARENT;
99 return SK_ColorTRANSPARENT;
102 bool DialogNotification::HasArrow() const {
103 return type_ == DialogNotification::EXPLANATORY_MESSAGE ||
104 type_ == DialogNotification::WALLET_ERROR ||
105 type_ == DialogNotification::WALLET_USAGE_CONFIRMATION;
108 bool DialogNotification::HasCheckbox() const {
109 return type_ == DialogNotification::WALLET_USAGE_CONFIRMATION;
112 SkColor const kWarningColor = SkColorSetRGB(0xde, 0x49, 0x32);
114 SuggestionState::SuggestionState()
116 SuggestionState::SuggestionState(bool visible,
117 const string16& vertically_compact_text,
118 const string16& horizontally_compact_text,
119 const gfx::Image& icon,
120 const string16& extra_text,
121 const gfx::Image& extra_icon)
123 vertically_compact_text(vertically_compact_text),
124 horizontally_compact_text(horizontally_compact_text),
126 extra_text(extra_text),
127 extra_icon(extra_icon) {}
128 SuggestionState::~SuggestionState() {}
130 DialogOverlayString::DialogOverlayString() {}
131 DialogOverlayString::~DialogOverlayString() {}
133 DialogOverlayState::DialogOverlayState() {}
134 DialogOverlayState::~DialogOverlayState() {}
136 ValidityMessage::ValidityMessage(const base::string16& text, bool sure)
137 : text(text), sure(sure) {}
138 ValidityMessage::~ValidityMessage() {}
140 ValidityMessages::ValidityMessages()
141 : default_message_(ValidityMessage(base::string16(), false)) {}
142 ValidityMessages::~ValidityMessages() {}
144 void ValidityMessages::Set(
145 ServerFieldType field, const ValidityMessage& message) {
146 messages_.erase(field);
147 messages_.insert(MessageMap::value_type(field, message));
150 const ValidityMessage& ValidityMessages::GetMessageOrDefault(
151 ServerFieldType field) const {
152 MessageMap::const_iterator iter = messages_.find(field);
153 return iter != messages_.end() ? iter->second : default_message_;
156 bool ValidityMessages::HasSureError(ServerFieldType field) const {
157 return IsSureError(GetMessageOrDefault(field));
160 bool ValidityMessages::HasErrors() const {
161 for (MessageMap::const_iterator iter = messages_.begin();
162 iter != messages_.end(); ++iter) {
163 if (!iter->second.text.empty())
169 bool ValidityMessages::HasSureErrors() const {
170 for (MessageMap::const_iterator iter = messages_.begin();
171 iter != messages_.end(); ++iter) {
172 if (IsSureError(iter->second))
178 } // namespace autofill