• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
6 
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/resource/resource_bundle.h"
12 
13 namespace {
14 
IsSureError(const autofill::ValidityMessage & message)15 bool IsSureError(const autofill::ValidityMessage& message) {
16   return message.sure && !message.text.empty();
17 }
18 
19 }  // namespace
20 
21 namespace autofill {
22 
23 static const base::char16 kRangeSeparator = '|';
24 
25 // Street address is multi-line, except in countries where it shares a line
26 // with other inputs (such as Coite d'Ivoire).
IsMultiline() const27 bool DetailInput::IsMultiline() const {
28   return (type == ADDRESS_HOME_STREET_ADDRESS ||
29           type == ADDRESS_BILLING_STREET_ADDRESS) &&
30       length == DetailInput::LONG;
31 }
32 
DialogNotification()33 DialogNotification::DialogNotification() : type_(NONE) {}
34 
DialogNotification(Type type,const base::string16 & display_text)35 DialogNotification::DialogNotification(Type type,
36                                        const base::string16& display_text)
37     : type_(type),
38       display_text_(display_text),
39       checked_(false) {
40   // If there's a range separated by bars, mark that as the anchor text.
41   std::vector<base::string16> pieces;
42   base::SplitStringDontTrim(display_text, kRangeSeparator, &pieces);
43   if (pieces.size() > 1) {
44     size_t start = pieces[0].size();
45     size_t end = start + pieces[1].size();
46     link_range_ = gfx::Range(start, end);
47     display_text_ = JoinString(pieces, base::string16());
48   }
49 }
50 
~DialogNotification()51 DialogNotification::~DialogNotification() {}
52 
GetBackgroundColor() const53 SkColor DialogNotification::GetBackgroundColor() const {
54   switch (type_) {
55     case DialogNotification::WALLET_USAGE_CONFIRMATION:
56       return SkColorSetRGB(0xf5, 0xf5, 0xf5);
57     case DialogNotification::REQUIRED_ACTION:
58     case DialogNotification::WALLET_ERROR:
59       return SkColorSetRGB(0xfc, 0xf3, 0xbf);
60     case DialogNotification::DEVELOPER_WARNING:
61     case DialogNotification::SECURITY_WARNING:
62       return kWarningColor;
63     case DialogNotification::NONE:
64       return SK_ColorTRANSPARENT;
65   }
66 
67   NOTREACHED();
68   return SK_ColorTRANSPARENT;
69 }
70 
GetBorderColor() const71 SkColor DialogNotification::GetBorderColor() const {
72   switch (type_) {
73     case DialogNotification::WALLET_USAGE_CONFIRMATION:
74       return SkColorSetRGB(0xe5, 0xe5, 0xe5);
75     case DialogNotification::REQUIRED_ACTION:
76     case DialogNotification::WALLET_ERROR:
77     case DialogNotification::DEVELOPER_WARNING:
78     case DialogNotification::SECURITY_WARNING:
79     case DialogNotification::NONE:
80       return GetBackgroundColor();
81   }
82 
83   NOTREACHED();
84   return SK_ColorTRANSPARENT;
85 }
86 
GetTextColor() const87 SkColor DialogNotification::GetTextColor() const {
88   switch (type_) {
89     case DialogNotification::REQUIRED_ACTION:
90     case DialogNotification::WALLET_ERROR:
91     case DialogNotification::WALLET_USAGE_CONFIRMATION:
92       return SkColorSetRGB(102, 102, 102);
93     case DialogNotification::DEVELOPER_WARNING:
94     case DialogNotification::SECURITY_WARNING:
95       return SK_ColorWHITE;
96     case DialogNotification::NONE:
97       return SK_ColorTRANSPARENT;
98   }
99 
100   NOTREACHED();
101   return SK_ColorTRANSPARENT;
102 }
103 
HasArrow() const104 bool DialogNotification::HasArrow() const {
105   return type_ == DialogNotification::WALLET_ERROR ||
106          type_ == DialogNotification::WALLET_USAGE_CONFIRMATION;
107 }
108 
HasCheckbox() const109 bool DialogNotification::HasCheckbox() const {
110   return type_ == DialogNotification::WALLET_USAGE_CONFIRMATION;
111 }
112 
113 SkColor const kWarningColor = SkColorSetRGB(0xde, 0x49, 0x32);
114 
SuggestionState()115 SuggestionState::SuggestionState()
116     : visible(false) {}
SuggestionState(bool visible,const base::string16 & vertically_compact_text,const base::string16 & horizontally_compact_text,const gfx::Image & icon,const base::string16 & extra_text,const gfx::Image & extra_icon)117 SuggestionState::SuggestionState(
118     bool visible,
119     const base::string16& vertically_compact_text,
120     const base::string16& horizontally_compact_text,
121     const gfx::Image& icon,
122     const base::string16& extra_text,
123     const gfx::Image& extra_icon)
124     : visible(visible),
125       vertically_compact_text(vertically_compact_text),
126       horizontally_compact_text(horizontally_compact_text),
127       icon(icon),
128       extra_text(extra_text),
129       extra_icon(extra_icon) {}
~SuggestionState()130 SuggestionState::~SuggestionState() {}
131 
DialogOverlayString()132 DialogOverlayString::DialogOverlayString() {}
~DialogOverlayString()133 DialogOverlayString::~DialogOverlayString() {}
134 
DialogOverlayState()135 DialogOverlayState::DialogOverlayState() {}
~DialogOverlayState()136 DialogOverlayState::~DialogOverlayState() {}
137 
ValidityMessage(const base::string16 & text,bool sure)138 ValidityMessage::ValidityMessage(const base::string16& text, bool sure)
139     : text(text), sure(sure) {}
~ValidityMessage()140 ValidityMessage::~ValidityMessage() {}
141 
ValidityMessages()142 ValidityMessages::ValidityMessages()
143     : default_message_(ValidityMessage(base::string16(), false)) {}
~ValidityMessages()144 ValidityMessages::~ValidityMessages() {}
145 
Set(ServerFieldType field,const ValidityMessage & message)146 void ValidityMessages::Set(
147     ServerFieldType field, const ValidityMessage& message) {
148   MessageMap::iterator iter = messages_.find(field);
149   if (iter != messages_.end()) {
150     if (!iter->second.text.empty())
151       return;
152 
153     messages_.erase(iter);
154   }
155 
156   messages_.insert(MessageMap::value_type(field, message));
157 }
158 
GetMessageOrDefault(ServerFieldType field) const159 const ValidityMessage& ValidityMessages::GetMessageOrDefault(
160     ServerFieldType field) const {
161   MessageMap::const_iterator iter = messages_.find(field);
162   return iter != messages_.end() ? iter->second : default_message_;
163 }
164 
HasSureError(ServerFieldType field) const165 bool ValidityMessages::HasSureError(ServerFieldType field) const {
166   return IsSureError(GetMessageOrDefault(field));
167 }
168 
HasErrors() const169 bool ValidityMessages::HasErrors() const {
170   for (MessageMap::const_iterator iter = messages_.begin();
171        iter != messages_.end(); ++iter) {
172     if (!iter->second.text.empty())
173       return true;
174   }
175   return false;
176 }
177 
HasSureErrors() const178 bool ValidityMessages::HasSureErrors() const {
179  for (MessageMap::const_iterator iter = messages_.begin();
180       iter != messages_.end(); ++iter) {
181     if (IsSureError(iter->second))
182       return true;
183   }
184   return false;
185 }
186 
187 }  // namespace autofill
188