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/l10n/l10n_util.h" 12 #include "ui/base/resource/resource_bundle.h" 13 14 namespace { 15 16 bool IsSureError(const autofill::ValidityMessage& message) { 17 return message.sure && !message.text.empty(); 18 } 19 20 } // namespace 21 22 namespace autofill { 23 24 static const base::char16 kRangeSeparator = '|'; 25 26 DialogNotification::DialogNotification() : type_(NONE) {} 27 28 DialogNotification::DialogNotification(Type type, 29 const base::string16& display_text) 30 : type_(type), 31 display_text_(display_text), 32 checked_(false) { 33 // If there's a range separated by bars, mark that as the anchor text. 34 std::vector<base::string16> pieces; 35 base::SplitStringDontTrim(display_text, kRangeSeparator, &pieces); 36 if (pieces.size() > 1) { 37 size_t start = pieces[0].size(); 38 size_t end = start + pieces[1].size(); 39 link_range_ = gfx::Range(start, end); 40 display_text_ = JoinString(pieces, base::string16()); 41 } 42 } 43 44 DialogNotification::~DialogNotification() {} 45 46 SkColor DialogNotification::GetBackgroundColor() const { 47 switch (type_) { 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 return kWarningColor; 56 case DialogNotification::NONE: 57 return SK_ColorTRANSPARENT; 58 } 59 60 NOTREACHED(); 61 return SK_ColorTRANSPARENT; 62 } 63 64 SkColor DialogNotification::GetBorderColor() const { 65 switch (type_) { 66 case DialogNotification::WALLET_USAGE_CONFIRMATION: 67 return SkColorSetRGB(0xe5, 0xe5, 0xe5); 68 case DialogNotification::REQUIRED_ACTION: 69 case DialogNotification::WALLET_ERROR: 70 case DialogNotification::DEVELOPER_WARNING: 71 case DialogNotification::SECURITY_WARNING: 72 case DialogNotification::NONE: 73 return GetBackgroundColor(); 74 } 75 76 NOTREACHED(); 77 return SK_ColorTRANSPARENT; 78 } 79 80 SkColor DialogNotification::GetTextColor() const { 81 switch (type_) { 82 case DialogNotification::REQUIRED_ACTION: 83 case DialogNotification::WALLET_ERROR: 84 case DialogNotification::WALLET_USAGE_CONFIRMATION: 85 return SkColorSetRGB(102, 102, 102); 86 case DialogNotification::DEVELOPER_WARNING: 87 case DialogNotification::SECURITY_WARNING: 88 return SK_ColorWHITE; 89 case DialogNotification::NONE: 90 return SK_ColorTRANSPARENT; 91 } 92 93 NOTREACHED(); 94 return SK_ColorTRANSPARENT; 95 } 96 97 bool DialogNotification::HasArrow() const { 98 return type_ == DialogNotification::WALLET_ERROR || 99 type_ == DialogNotification::WALLET_USAGE_CONFIRMATION; 100 } 101 102 bool DialogNotification::HasCheckbox() const { 103 return type_ == DialogNotification::WALLET_USAGE_CONFIRMATION; 104 } 105 106 SkColor const kWarningColor = SkColorSetRGB(0xde, 0x49, 0x32); 107 108 SuggestionState::SuggestionState() 109 : visible(false) {} 110 SuggestionState::SuggestionState( 111 bool visible, 112 const base::string16& vertically_compact_text, 113 const base::string16& horizontally_compact_text, 114 const gfx::Image& icon, 115 const base::string16& extra_text, 116 const gfx::Image& extra_icon) 117 : visible(visible), 118 vertically_compact_text(vertically_compact_text), 119 horizontally_compact_text(horizontally_compact_text), 120 icon(icon), 121 extra_text(extra_text), 122 extra_icon(extra_icon) {} 123 SuggestionState::~SuggestionState() {} 124 125 DialogOverlayString::DialogOverlayString() {} 126 DialogOverlayString::~DialogOverlayString() {} 127 128 DialogOverlayState::DialogOverlayState() {} 129 DialogOverlayState::~DialogOverlayState() {} 130 131 ValidityMessage::ValidityMessage(const base::string16& text, bool sure) 132 : text(text), sure(sure) {} 133 ValidityMessage::~ValidityMessage() {} 134 135 ValidityMessages::ValidityMessages() 136 : default_message_(ValidityMessage(base::string16(), false)) {} 137 ValidityMessages::~ValidityMessages() {} 138 139 void ValidityMessages::Set( 140 ServerFieldType field, const ValidityMessage& message) { 141 messages_.erase(field); 142 messages_.insert(MessageMap::value_type(field, message)); 143 } 144 145 const ValidityMessage& ValidityMessages::GetMessageOrDefault( 146 ServerFieldType field) const { 147 MessageMap::const_iterator iter = messages_.find(field); 148 return iter != messages_.end() ? iter->second : default_message_; 149 } 150 151 bool ValidityMessages::HasSureError(ServerFieldType field) const { 152 return IsSureError(GetMessageOrDefault(field)); 153 } 154 155 bool ValidityMessages::HasErrors() const { 156 for (MessageMap::const_iterator iter = messages_.begin(); 157 iter != messages_.end(); ++iter) { 158 if (!iter->second.text.empty()) 159 return true; 160 } 161 return false; 162 } 163 164 bool ValidityMessages::HasSureErrors() const { 165 for (MessageMap::const_iterator iter = messages_.begin(); 166 iter != messages_.end(); ++iter) { 167 if (IsSureError(iter->second)) 168 return true; 169 } 170 return false; 171 } 172 173 } // namespace autofill 174