autofill_dialog_types.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 13namespace { 14 15bool IsSureError(const autofill::ValidityMessage& message) { 16 return message.sure && !message.text.empty(); 17} 18 19} // namespace 20 21namespace autofill { 22 23static const base::char16 kRangeSeparator = '|'; 24 25DialogNotification::DialogNotification() : type_(NONE) {} 26 27DialogNotification::DialogNotification(Type type, 28 const base::string16& display_text) 29 : type_(type), 30 display_text_(display_text), 31 checked_(false) { 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, base::string16()); 40 } 41} 42 43DialogNotification::~DialogNotification() {} 44 45SkColor DialogNotification::GetBackgroundColor() const { 46 switch (type_) { 47 case DialogNotification::WALLET_USAGE_CONFIRMATION: 48 return SkColorSetRGB(0xf5, 0xf5, 0xf5); 49 case DialogNotification::REQUIRED_ACTION: 50 case DialogNotification::WALLET_ERROR: 51 return SkColorSetRGB(0xfc, 0xf3, 0xbf); 52 case DialogNotification::DEVELOPER_WARNING: 53 case DialogNotification::SECURITY_WARNING: 54 return kWarningColor; 55 case DialogNotification::NONE: 56 return SK_ColorTRANSPARENT; 57 } 58 59 NOTREACHED(); 60 return SK_ColorTRANSPARENT; 61} 62 63SkColor DialogNotification::GetBorderColor() const { 64 switch (type_) { 65 case DialogNotification::WALLET_USAGE_CONFIRMATION: 66 return SkColorSetRGB(0xe5, 0xe5, 0xe5); 67 case DialogNotification::REQUIRED_ACTION: 68 case DialogNotification::WALLET_ERROR: 69 case DialogNotification::DEVELOPER_WARNING: 70 case DialogNotification::SECURITY_WARNING: 71 case DialogNotification::NONE: 72 return GetBackgroundColor(); 73 } 74 75 NOTREACHED(); 76 return SK_ColorTRANSPARENT; 77} 78 79SkColor DialogNotification::GetTextColor() const { 80 switch (type_) { 81 case DialogNotification::REQUIRED_ACTION: 82 case DialogNotification::WALLET_ERROR: 83 case DialogNotification::WALLET_USAGE_CONFIRMATION: 84 return SkColorSetRGB(102, 102, 102); 85 case DialogNotification::DEVELOPER_WARNING: 86 case DialogNotification::SECURITY_WARNING: 87 return SK_ColorWHITE; 88 case DialogNotification::NONE: 89 return SK_ColorTRANSPARENT; 90 } 91 92 NOTREACHED(); 93 return SK_ColorTRANSPARENT; 94} 95 96bool DialogNotification::HasArrow() const { 97 return type_ == DialogNotification::WALLET_ERROR || 98 type_ == DialogNotification::WALLET_USAGE_CONFIRMATION; 99} 100 101bool DialogNotification::HasCheckbox() const { 102 return type_ == DialogNotification::WALLET_USAGE_CONFIRMATION; 103} 104 105SkColor const kWarningColor = SkColorSetRGB(0xde, 0x49, 0x32); 106 107SuggestionState::SuggestionState() 108 : visible(false) {} 109SuggestionState::SuggestionState( 110 bool visible, 111 const base::string16& vertically_compact_text, 112 const base::string16& horizontally_compact_text, 113 const gfx::Image& icon, 114 const base::string16& extra_text, 115 const gfx::Image& extra_icon) 116 : visible(visible), 117 vertically_compact_text(vertically_compact_text), 118 horizontally_compact_text(horizontally_compact_text), 119 icon(icon), 120 extra_text(extra_text), 121 extra_icon(extra_icon) {} 122SuggestionState::~SuggestionState() {} 123 124DialogOverlayString::DialogOverlayString() {} 125DialogOverlayString::~DialogOverlayString() {} 126 127DialogOverlayState::DialogOverlayState() {} 128DialogOverlayState::~DialogOverlayState() {} 129 130ValidityMessage::ValidityMessage(const base::string16& text, bool sure) 131 : text(text), sure(sure) {} 132ValidityMessage::~ValidityMessage() {} 133 134ValidityMessages::ValidityMessages() 135 : default_message_(ValidityMessage(base::string16(), false)) {} 136ValidityMessages::~ValidityMessages() {} 137 138void ValidityMessages::Set( 139 ServerFieldType field, const ValidityMessage& message) { 140 MessageMap::iterator iter = messages_.find(field); 141 if (iter != messages_.end()) { 142 if (!iter->second.text.empty()) 143 return; 144 145 messages_.erase(iter); 146 } 147 148 messages_.insert(MessageMap::value_type(field, message)); 149} 150 151const ValidityMessage& ValidityMessages::GetMessageOrDefault( 152 ServerFieldType field) const { 153 MessageMap::const_iterator iter = messages_.find(field); 154 return iter != messages_.end() ? iter->second : default_message_; 155} 156 157bool ValidityMessages::HasSureError(ServerFieldType field) const { 158 return IsSureError(GetMessageOrDefault(field)); 159} 160 161bool ValidityMessages::HasErrors() const { 162 for (MessageMap::const_iterator iter = messages_.begin(); 163 iter != messages_.end(); ++iter) { 164 if (!iter->second.text.empty()) 165 return true; 166 } 167 return false; 168} 169 170bool ValidityMessages::HasSureErrors() const { 171 for (MessageMap::const_iterator iter = messages_.begin(); 172 iter != messages_.end(); ++iter) { 173 if (IsSureError(iter->second)) 174 return true; 175 } 176 return false; 177} 178 179} // namespace autofill 180