OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #include "chrome/browser/autofill/autofill_profiles_view_win.h" |
| 5 |
| 6 #include <vsstyle.h> |
| 7 #include <vssym32.h> |
| 8 |
| 9 #include "app/gfx/canvas.h" |
| 10 #include "app/gfx/native_theme_win.h" |
| 11 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" |
| 13 #include "base/gfx/size.h" |
| 14 #include "base/message_loop.h" |
| 15 #include "grit/generated_resources.h" |
| 16 #include "grit/locale_settings.h" |
| 17 #include "views/controls/button/native_button.h" |
| 18 #include "views/controls/label.h" |
| 19 #include "views/controls/scroll_view.h" |
| 20 #include "views/grid_layout.h" |
| 21 #include "views/standard_layout.h" |
| 22 #include "views/window/window.h" |
| 23 |
| 24 namespace { |
| 25 |
| 26 // padding on the sides of AutoFill settings dialog. |
| 27 const int kDialogPadding = 7; |
| 28 |
| 29 // Insets for subview controls. |
| 30 const int kSubViewInsets = 5; |
| 31 |
| 32 // TODO(georgey) remove this code into a separate file as it is already the same |
| 33 // elsewhere. |
| 34 // A background object that paints the scrollable list background, |
| 35 // which may be rendered by the system visual styles system. |
| 36 class ListBackground : public views::Background { |
| 37 public: |
| 38 explicit ListBackground() { |
| 39 SkColor list_color = |
| 40 gfx::NativeTheme::instance()->GetThemeColorWithDefault( |
| 41 gfx::NativeTheme::LIST, 1, TS_NORMAL, TMT_FILLCOLOR, COLOR_WINDOW); |
| 42 SetNativeControlColor(list_color); |
| 43 } |
| 44 virtual ~ListBackground() {} |
| 45 |
| 46 virtual void Paint(gfx::Canvas* canvas, views::View* view) const { |
| 47 HDC dc = canvas->beginPlatformPaint(); |
| 48 RECT native_lb = view->GetLocalBounds(true).ToRECT(); |
| 49 gfx::NativeTheme::instance()->PaintListBackground(dc, true, &native_lb); |
| 50 canvas->endPlatformPaint(); |
| 51 } |
| 52 |
| 53 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(ListBackground); |
| 55 }; |
| 56 |
| 57 }; // namespace |
| 58 |
| 59 ///////////////////////////////////////////////////////////////////////////// |
| 60 // AutoFillProfilesView, static data: |
| 61 AutoFillProfilesView *AutoFillProfilesView::instance_ = NULL; |
| 62 |
| 63 ///////////////////////////////////////////////////////////////////////////// |
| 64 // AutoFillProfilesView::ScrollViewContents, static data: |
| 65 int AutoFillProfilesView::ScrollViewContents::line_height_ = 0; |
| 66 |
| 67 ///////////////////////////////////////////////////////////////////////////// |
| 68 // AutoFillProfilesView, public: |
| 69 AutoFillProfilesView::AutoFillProfilesView( |
| 70 AutoFillDialogObserver* observer, |
| 71 const std::vector<AutoFillProfile*>& profiles, |
| 72 const std::vector<CreditCard*>& credit_cards) |
| 73 : observer_(observer), |
| 74 scroll_view_(NULL), |
| 75 save_changes_(NULL) { |
| 76 profiles_set_.reserve(profiles.size()); |
| 77 for (std::vector<AutoFillProfile*>::const_iterator address_it = |
| 78 profiles.begin(); |
| 79 address_it != profiles.end(); |
| 80 ++address_it) { |
| 81 profiles_set_.push_back(EditableSetInfo(*address_it, true)); |
| 82 } |
| 83 credit_card_set_.reserve(credit_cards.size()); |
| 84 for (std::vector<CreditCard*>::const_iterator cc_it = credit_cards.begin(); |
| 85 cc_it != credit_cards.end(); |
| 86 ++cc_it) { |
| 87 credit_card_set_.push_back(EditableSetInfo(*cc_it, true)); |
| 88 } |
| 89 } |
| 90 |
| 91 AutoFillProfilesView::~AutoFillProfilesView() { |
| 92 } |
| 93 |
| 94 int AutoFillProfilesView::Show(AutoFillDialogObserver* observer, |
| 95 const std::vector<AutoFillProfile*>& profiles, |
| 96 const std::vector<CreditCard*>& credit_cards) { |
| 97 if (!instance_) { |
| 98 instance_ = new AutoFillProfilesView(observer, profiles, credit_cards); |
| 99 |
| 100 // |instance_| will get deleted once Close() is called. |
| 101 views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_); |
| 102 } |
| 103 if (!instance_->window()->IsVisible()) |
| 104 instance_->window()->Show(); |
| 105 else |
| 106 instance_->window()->Activate(); |
| 107 return 0; |
| 108 } |
| 109 |
| 110 ///////////////////////////////////////////////////////////////////////////// |
| 111 // AutoFillProfilesView, protected: |
| 112 ///////////////////////////////////////////////////////////////////////////// |
| 113 // AutoFillProfilesView, views::View implementations |
| 114 void AutoFillProfilesView::Layout() { |
| 115 scroll_view_->SetBounds(kDialogPadding, kDialogPadding, |
| 116 width() - (2 * kDialogPadding), |
| 117 height() - (2 * kDialogPadding)); |
| 118 } |
| 119 |
| 120 gfx::Size AutoFillProfilesView::GetPreferredSize() { |
| 121 return views::Window::GetLocalizedContentsSize( |
| 122 IDS_AUTOFILL_DIALOG_WIDTH_CHARS, |
| 123 IDS_AUTOFILL_DIALOG_HEIGHT_LINES); |
| 124 } |
| 125 |
| 126 void AutoFillProfilesView::ViewHierarchyChanged(bool is_add, |
| 127 views::View* parent, |
| 128 views::View* child) { |
| 129 if (is_add && child == this) |
| 130 Init(); |
| 131 } |
| 132 |
| 133 ///////////////////////////////////////////////////////////////////////////// |
| 134 // AutoFillProfilesView, views::DialogDelegate implementations: |
| 135 int AutoFillProfilesView::GetDialogButtons() const { |
| 136 return MessageBoxFlags::DIALOGBUTTON_CANCEL | |
| 137 MessageBoxFlags::DIALOGBUTTON_OK; |
| 138 } |
| 139 |
| 140 std::wstring AutoFillProfilesView::GetDialogButtonLabel( |
| 141 MessageBoxFlags::DialogButton button) const { |
| 142 switch (button) { |
| 143 case MessageBoxFlags::DIALOGBUTTON_OK: |
| 144 return l10n_util::GetString(IDS_AUTOFILL_DIALOG_SAVE); |
| 145 case MessageBoxFlags::DIALOGBUTTON_CANCEL: |
| 146 return std::wstring(); |
| 147 default: |
| 148 break; |
| 149 } |
| 150 NOTREACHED(); |
| 151 return std::wstring(); |
| 152 } |
| 153 |
| 154 std::wstring AutoFillProfilesView::GetWindowTitle() const { |
| 155 return l10n_util::GetString(IDS_AUTOFILL_DIALOG_TITLE); |
| 156 } |
| 157 |
| 158 void AutoFillProfilesView::WindowClosing() { |
| 159 instance_ = NULL; |
| 160 } |
| 161 |
| 162 views::View* AutoFillProfilesView::GetContentsView() { |
| 163 return this; |
| 164 } |
| 165 |
| 166 bool AutoFillProfilesView::Accept() { |
| 167 DCHECK(observer_); |
| 168 std::vector<AutoFillProfile> profiles; |
| 169 profiles.reserve(profiles_set_.size()); |
| 170 std::vector<EditableSetInfo>::iterator it; |
| 171 for (it = profiles_set_.begin(); it != profiles_set_.end(); ++it) { |
| 172 profiles.push_back(it->address); |
| 173 } |
| 174 std::vector<CreditCard> credit_cards; |
| 175 credit_cards.reserve(credit_card_set_.size()); |
| 176 for (it = credit_card_set_.begin(); it != credit_card_set_.end(); ++it) { |
| 177 credit_cards.push_back(it->credit_card); |
| 178 } |
| 179 observer_->OnAutoFillDialogApply(&profiles, &credit_cards); |
| 180 return true; |
| 181 } |
| 182 |
| 183 ///////////////////////////////////////////////////////////////////////////// |
| 184 // AutoFillProfilesView, views::ButtonListener implementations: |
| 185 void AutoFillProfilesView::ButtonPressed(views::Button* sender, |
| 186 const views::Event& event) { |
| 187 NOTIMPLEMENTED(); |
| 188 } |
| 189 |
| 190 ///////////////////////////////////////////////////////////////////////////// |
| 191 // AutoFillProfilesView, private: |
| 192 void AutoFillProfilesView::Init() { |
| 193 scroll_view_ = new AutoFillScrollView(&profiles_set_, &credit_card_set_); |
| 194 |
| 195 views::GridLayout* layout = CreatePanelGridLayout(this); |
| 196 SetLayoutManager(layout); |
| 197 |
| 198 const int single_column_view_set_id = 0; |
| 199 views::ColumnSet* column_set = |
| 200 layout->AddColumnSet(single_column_view_set_id); |
| 201 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 202 views::GridLayout::USE_PREF, 0, 0); |
| 203 layout->StartRow(1, single_column_view_set_id); |
| 204 layout->AddView(scroll_view_); |
| 205 } |
| 206 |
| 207 ///////////////////////////////////////////////////////////////////////////// |
| 208 // AutoFillProfilesView::PhoneSubView, public: |
| 209 AutoFillProfilesView::PhoneSubView::PhoneSubView( |
| 210 views::Label* label, |
| 211 views::Textfield* text_country, |
| 212 views::Textfield* text_area, |
| 213 views::Textfield* text_phone) |
| 214 : label_(label), |
| 215 text_country_(text_country), |
| 216 text_area_(text_area), |
| 217 text_phone_(text_phone) { |
| 218 DCHECK(label_); |
| 219 DCHECK(text_country_); |
| 220 DCHECK(text_area_); |
| 221 DCHECK(text_phone_); |
| 222 } |
| 223 |
| 224 ///////////////////////////////////////////////////////////////////////////// |
| 225 // AutoFillProfilesView::PhoneSubView, protected: |
| 226 ///////////////////////////////////////////////////////////////////////////// |
| 227 // AutoFillProfilesView::PhoneSubView, views::View implementations |
| 228 void AutoFillProfilesView::PhoneSubView::ViewHierarchyChanged( |
| 229 bool is_add, views::View* parent, views::View* child) { |
| 230 if (is_add && this == child) { |
| 231 views::GridLayout* layout = new views::GridLayout(this); |
| 232 SetLayoutManager(layout); |
| 233 const int triple_column_fill_view_set_id = 0; |
| 234 views::ColumnSet* column_set = |
| 235 layout->AddColumnSet(triple_column_fill_view_set_id); |
| 236 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
| 237 views::GridLayout::USE_PREF, 0, 0); |
| 238 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 239 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
| 240 views::GridLayout::USE_PREF, 0, 0); |
| 241 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 242 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
| 243 views::GridLayout::USE_PREF, 0, 0); |
| 244 layout->StartRow(0, triple_column_fill_view_set_id); |
| 245 layout->AddView(label_, 5, 1); |
| 246 layout->StartRow(0, triple_column_fill_view_set_id); |
| 247 text_country_->set_default_width_in_chars(3); |
| 248 text_area_->set_default_width_in_chars(3); |
| 249 text_phone_->set_default_width_in_chars(7); |
| 250 layout->AddView(text_country_); |
| 251 layout->AddView(text_area_); |
| 252 layout->AddView(text_phone_); |
| 253 } |
| 254 } |
| 255 |
| 256 ///////////////////////////////////////////////////////////////////////////// |
| 257 // AutoFillProfilesView::EditableSetViewContents, static data: |
| 258 AutoFillProfilesView::EditableSetViewContents::TextFieldToAutoFill |
| 259 AutoFillProfilesView::EditableSetViewContents::address_fields_[] = { |
| 260 { AutoFillProfilesView::EditableSetViewContents::TEXT_LABEL, NO_SERVER_DATA }, |
| 261 { AutoFillProfilesView::EditableSetViewContents::TEXT_FIRST_NAME, |
| 262 NAME_FIRST }, |
| 263 { AutoFillProfilesView::EditableSetViewContents::TEXT_MIDDLE_NAME, |
| 264 NAME_MIDDLE }, |
| 265 { AutoFillProfilesView::EditableSetViewContents::TEXT_LAST_NAME, |
| 266 NAME_LAST }, |
| 267 { AutoFillProfilesView::EditableSetViewContents::TEXT_EMAIL, EMAIL_ADDRESS }, |
| 268 { AutoFillProfilesView::EditableSetViewContents::TEXT_COMPANY_NAME, |
| 269 COMPANY_NAME }, |
| 270 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_LINE_1, |
| 271 ADDRESS_HOME_LINE1 }, |
| 272 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_LINE_2, |
| 273 ADDRESS_HOME_LINE2 }, |
| 274 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_CITY, |
| 275 ADDRESS_HOME_CITY }, |
| 276 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_STATE, |
| 277 ADDRESS_HOME_STATE }, |
| 278 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_ZIP, |
| 279 ADDRESS_HOME_ZIP }, |
| 280 { AutoFillProfilesView::EditableSetViewContents::TEXT_ADDRESS_COUNTRY, |
| 281 ADDRESS_HOME_COUNTRY }, |
| 282 { AutoFillProfilesView::EditableSetViewContents::TEXT_PHONE_COUNTRY, |
| 283 PHONE_HOME_COUNTRY_CODE }, |
| 284 { AutoFillProfilesView::EditableSetViewContents::TEXT_PHONE_AREA, |
| 285 PHONE_HOME_CITY_CODE }, |
| 286 { AutoFillProfilesView::EditableSetViewContents::TEXT_PHONE_PHONE, |
| 287 PHONE_HOME_NUMBER }, |
| 288 { AutoFillProfilesView::EditableSetViewContents::TEXT_FAX_COUNTRY, |
| 289 PHONE_FAX_COUNTRY_CODE }, |
| 290 { AutoFillProfilesView::EditableSetViewContents::TEXT_FAX_AREA, |
| 291 PHONE_FAX_CITY_CODE }, |
| 292 { AutoFillProfilesView::EditableSetViewContents::TEXT_FAX_PHONE, |
| 293 PHONE_FAX_NUMBER }, |
| 294 }; |
| 295 |
| 296 AutoFillProfilesView::EditableSetViewContents::TextFieldToAutoFill |
| 297 AutoFillProfilesView::EditableSetViewContents::credit_card_fields_[] = { |
| 298 { AutoFillProfilesView::EditableSetViewContents::TEXT_LABEL, NO_SERVER_DATA }, |
| 299 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_NAME, |
| 300 CREDIT_CARD_NAME }, |
| 301 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_NUMBER, |
| 302 CREDIT_CARD_NUMBER }, |
| 303 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_EXPIRATION_MONTH, |
| 304 CREDIT_CARD_EXP_MONTH }, |
| 305 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_EXPIRATION_YEAR, |
| 306 CREDIT_CARD_EXP_2_DIGIT_YEAR }, |
| 307 { AutoFillProfilesView::EditableSetViewContents::TEXT_CC_EXPIRATION_CVC, |
| 308 CREDIT_CARD_VERIFICATION_CODE }, |
| 309 /* phone is disabled for now |
| 310 { AutoFillProfilesView::EditableSetViewContents::TEXT_PHONE_COUNTRY, |
| 311 PHONE_HOME_COUNTRY_CODE }, |
| 312 { AutoFillProfilesView::EditableSetViewContents::TEXT_PHONE_AREA, |
| 313 PHONE_HOME_CITY_CODE }, |
| 314 { AutoFillProfilesView::EditableSetViewContents::TEXT_PHONE_PHONE, |
| 315 PHONE_HOME_NUMBER }, |
| 316 */ |
| 317 }; |
| 318 |
| 319 ///////////////////////////////////////////////////////////////////////////// |
| 320 // AutoFillProfilesView::EditableSetViewContents, public: |
| 321 AutoFillProfilesView::EditableSetViewContents::EditableSetViewContents( |
| 322 std::vector<EditableSetInfo>::iterator field_set) |
| 323 : editable_fields_set_(field_set), |
| 324 delete_button_(NULL), |
| 325 title_label_(NULL) { |
| 326 ZeroMemory(text_fields_, sizeof(text_fields_)); |
| 327 } |
| 328 |
| 329 ///////////////////////////////////////////////////////////////////////////// |
| 330 // AutoFillProfilesView::EditableSetViewContents, protected: |
| 331 ///////////////////////////////////////////////////////////////////////////// |
| 332 // AutoFillProfilesView::EditableSetViewContents, views::View implementations |
| 333 void AutoFillProfilesView::EditableSetViewContents::Layout() { |
| 334 View::Layout(); |
| 335 } |
| 336 |
| 337 gfx::Size AutoFillProfilesView::EditableSetViewContents::GetPreferredSize() { |
| 338 gfx::Size prefsize; |
| 339 views::View* parent = GetParent(); |
| 340 if (parent && parent->width()) { |
| 341 const int width = parent->width(); |
| 342 prefsize = gfx::Size(width, GetHeightForWidth(width)); |
| 343 } |
| 344 return prefsize; |
| 345 } |
| 346 |
| 347 void AutoFillProfilesView::EditableSetViewContents::ViewHierarchyChanged( |
| 348 bool is_add, views::View* parent, views::View* child) { |
| 349 if (is_add && this == child) { |
| 350 views::GridLayout* layout = new views::GridLayout(this); |
| 351 layout->SetInsets(kSubViewInsets, kSubViewInsets, |
| 352 kSubViewInsets, kSubViewInsets); |
| 353 SetLayoutManager(layout); |
| 354 InitLayoutGrid(layout); |
| 355 delete_button_ = new views::NativeButton(this, |
| 356 l10n_util::GetString(IDS_AUTOFILL_DELETE_BUTTON)); |
| 357 if (editable_fields_set_->is_address) |
| 358 InitAddressFields(layout); |
| 359 else |
| 360 InitCreditCardFields(layout); |
| 361 } |
| 362 } |
| 363 |
| 364 ///////////////////////////////////////////////////////////////////////////// |
| 365 // AutoFillProfilesView::EditableSetViewContents, |
| 366 // views::Textfield::Controller implementations |
| 367 void AutoFillProfilesView::EditableSetViewContents::ContentsChanged( |
| 368 views::Textfield* sender, const string16& new_contents) { |
| 369 if (editable_fields_set_->is_address) { |
| 370 for (int field = 0; field < arraysize(address_fields_); ++field) { |
| 371 DCHECK(text_fields_[address_fields_[field].text_field]); |
| 372 if (text_fields_[address_fields_[field].text_field] == sender) { |
| 373 if (address_fields_[field].text_field == TEXT_LABEL) |
| 374 editable_fields_set_->address.set_label(new_contents); |
| 375 else |
| 376 editable_fields_set_->address.SetInfo( |
| 377 AutoFillType(address_fields_[field].type), new_contents); |
| 378 return; |
| 379 } |
| 380 } |
| 381 } else { |
| 382 for (int field = 0; field < arraysize(credit_card_fields_); ++field) { |
| 383 DCHECK(text_fields_[credit_card_fields_[field].text_field]); |
| 384 if (text_fields_[credit_card_fields_[field].text_field] == sender) { |
| 385 if (credit_card_fields_[field].text_field == TEXT_LABEL) |
| 386 editable_fields_set_->credit_card.set_label(new_contents); |
| 387 else |
| 388 editable_fields_set_->credit_card.SetInfo( |
| 389 AutoFillType(credit_card_fields_[field].type), new_contents); |
| 390 return; |
| 391 } |
| 392 } |
| 393 } |
| 394 } |
| 395 |
| 396 bool AutoFillProfilesView::EditableSetViewContents::HandleKeystroke( |
| 397 views::Textfield* sender, const views::Textfield::Keystroke& keystroke) { |
| 398 return false; |
| 399 } |
| 400 |
| 401 ///////////////////////////////////////////////////////////////////////////// |
| 402 // AutoFillProfilesView::EditableSetViewContents, |
| 403 // views::ButtonListener implementations |
| 404 void AutoFillProfilesView::EditableSetViewContents::ButtonPressed( |
| 405 views::Button* sender, const views::Event& event) { |
| 406 } |
| 407 |
| 408 ///////////////////////////////////////////////////////////////////////////// |
| 409 // AutoFillProfilesView::EditableSetViewContents, private: |
| 410 void AutoFillProfilesView::EditableSetViewContents::InitAddressFields( |
| 411 views::GridLayout* layout) { |
| 412 DCHECK(editable_fields_set_->is_address); |
| 413 std::wstring title = editable_fields_set_->address.Label(); |
| 414 if (title.empty()) |
| 415 title = l10n_util::GetString(IDS_AUTOFILL_NEW_ADDRESS); |
| 416 title_label_ = new views::Label(title); |
| 417 |
| 418 for (int field = 0; field < arraysize(address_fields_); ++field) { |
| 419 DCHECK(!text_fields_[address_fields_[field].text_field]); |
| 420 text_fields_[address_fields_[field].text_field] = |
| 421 new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 422 text_fields_[address_fields_[field].text_field]->SetController(this); |
| 423 if (address_fields_[field].text_field == TEXT_LABEL) { |
| 424 text_fields_[TEXT_LABEL]->SetText( |
| 425 editable_fields_set_->address.Label()); |
| 426 } else { |
| 427 text_fields_[address_fields_[field].text_field]->SetText( |
| 428 editable_fields_set_->address.GetFieldText( |
| 429 AutoFillType(address_fields_[field].type))); |
| 430 } |
| 431 } |
| 432 |
| 433 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 434 gfx::Font title_font = |
| 435 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD); |
| 436 title_label_->SetFont(title_font); |
| 437 |
| 438 SkColor title_color = |
| 439 gfx::NativeTheme::instance()->GetThemeColorWithDefault( |
| 440 gfx::NativeTheme::BUTTON, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, |
| 441 COLOR_WINDOWTEXT); |
| 442 title_label_->SetColor(title_color); |
| 443 SkColor bk_color = |
| 444 gfx::NativeTheme::instance()->GetThemeColorWithDefault( |
| 445 gfx::NativeTheme::BUTTON, BP_PUSHBUTTON, PBS_NORMAL, TMT_BTNFACE, |
| 446 COLOR_BTNFACE); |
| 447 title_label_->set_background( |
| 448 views::Background::CreateSolidBackground(bk_color)); |
| 449 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 450 |
| 451 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 452 layout->AddView(title_label_, 5, 1); |
| 453 layout->StartRow(0, triple_column_leading_view_set_id_); |
| 454 layout->AddView(new views::Label( |
| 455 l10n_util::GetString(IDS_AUTOFILL_DIALOG_LABEL))); |
| 456 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 457 layout->AddView(text_fields_[TEXT_LABEL]); |
| 458 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 459 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_FIRST_NAME)); |
| 460 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_MIDDLE_NAME)); |
| 461 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_LAST_NAME)); |
| 462 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 463 layout->AddView(text_fields_[TEXT_FIRST_NAME]); |
| 464 layout->AddView(text_fields_[TEXT_MIDDLE_NAME]); |
| 465 layout->AddView(text_fields_[TEXT_LAST_NAME]); |
| 466 |
| 467 layout->StartRow(0, triple_column_leading_view_set_id_); |
| 468 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_EMAIL)); |
| 469 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_COMPANY_NAME)); |
| 470 |
| 471 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 472 layout->AddView(text_fields_[TEXT_EMAIL]); |
| 473 layout->AddView(text_fields_[TEXT_COMPANY_NAME]); |
| 474 |
| 475 layout->StartRow(0, triple_column_leading_view_set_id_); |
| 476 layout->AddView(new views::Label(l10n_util::GetString( |
| 477 IDS_AUTOFILL_DIALOG_ADDRESS_LINE_1)), 3, 1); |
| 478 |
| 479 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 480 layout->AddView(text_fields_[TEXT_ADDRESS_LINE_1], 3, 1); |
| 481 |
| 482 layout->StartRow(0, triple_column_leading_view_set_id_); |
| 483 layout->AddView(new views::Label(l10n_util::GetString( |
| 484 IDS_AUTOFILL_DIALOG_ADDRESS_LINE_2)), 3, 1); |
| 485 |
| 486 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 487 layout->AddView(text_fields_[TEXT_ADDRESS_LINE_2], 3, 1); |
| 488 |
| 489 layout->StartRow(0, four_column_city_state_zip_set_id_); |
| 490 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_CITY)); |
| 491 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_STATE)); |
| 492 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_ZIP_CODE)); |
| 493 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_COUNTRY)); |
| 494 // City (33% - 16/48), state(33%), zip (12.7% - 5/42), country (21% - 11/48) |
| 495 text_fields_[TEXT_ADDRESS_CITY]->set_default_width_in_chars(16); |
| 496 text_fields_[TEXT_ADDRESS_STATE]->set_default_width_in_chars(16); |
| 497 text_fields_[TEXT_ADDRESS_ZIP]->set_default_width_in_chars(5); |
| 498 text_fields_[TEXT_ADDRESS_COUNTRY]->set_default_width_in_chars(11); |
| 499 |
| 500 layout->StartRow(0, four_column_city_state_zip_set_id_); |
| 501 layout->AddView(text_fields_[TEXT_ADDRESS_CITY]); |
| 502 layout->AddView(text_fields_[TEXT_ADDRESS_STATE]); |
| 503 layout->AddView(text_fields_[TEXT_ADDRESS_ZIP]); |
| 504 layout->AddView(text_fields_[TEXT_ADDRESS_COUNTRY]); |
| 505 |
| 506 PhoneSubView *phone = new PhoneSubView( |
| 507 CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_PHONE), |
| 508 text_fields_[TEXT_PHONE_COUNTRY], |
| 509 text_fields_[TEXT_PHONE_AREA], |
| 510 text_fields_[TEXT_PHONE_PHONE]); |
| 511 |
| 512 PhoneSubView *fax = new PhoneSubView( |
| 513 CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_FAX), |
| 514 text_fields_[TEXT_FAX_COUNTRY], |
| 515 text_fields_[TEXT_FAX_AREA], |
| 516 text_fields_[TEXT_FAX_PHONE]); |
| 517 |
| 518 layout->StartRow(0, double_column_fill_view_set_id_); |
| 519 layout->AddView(phone); |
| 520 layout->AddView(fax); |
| 521 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 522 |
| 523 layout->StartRow(0, triple_column_leading_view_set_id_); |
| 524 layout->AddView(delete_button_); |
| 525 } |
| 526 |
| 527 void AutoFillProfilesView::EditableSetViewContents::InitCreditCardFields( |
| 528 views::GridLayout* layout) { |
| 529 DCHECK(!editable_fields_set_->is_address); |
| 530 std::wstring title = editable_fields_set_->credit_card.Label(); |
| 531 if (title.empty()) |
| 532 title = l10n_util::GetString(IDS_AUTOFILL_NEW_CREDITCARD); |
| 533 title_label_ = new views::Label(title); |
| 534 |
| 535 for (int field = 0; field < arraysize(credit_card_fields_); ++field) { |
| 536 DCHECK(!text_fields_[credit_card_fields_[field].text_field]); |
| 537 text_fields_[credit_card_fields_[field].text_field] = |
| 538 new views::Textfield(views::Textfield::STYLE_DEFAULT); |
| 539 text_fields_[credit_card_fields_[field].text_field]->SetController(this); |
| 540 if (credit_card_fields_[field].text_field == TEXT_LABEL) { |
| 541 text_fields_[TEXT_LABEL]->SetText( |
| 542 editable_fields_set_->credit_card.Label()); |
| 543 } else { |
| 544 text_fields_[credit_card_fields_[field].text_field]->SetText( |
| 545 editable_fields_set_->credit_card.GetFieldText( |
| 546 AutoFillType(credit_card_fields_[field].type))); |
| 547 } |
| 548 } |
| 549 |
| 550 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 551 gfx::Font title_font = |
| 552 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD); |
| 553 title_label_->SetFont(title_font); |
| 554 |
| 555 SkColor title_color = |
| 556 gfx::NativeTheme::instance()->GetThemeColorWithDefault( |
| 557 gfx::NativeTheme::BUTTON, BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, |
| 558 COLOR_WINDOWTEXT); |
| 559 title_label_->SetColor(title_color); |
| 560 SkColor bk_color = |
| 561 gfx::NativeTheme::instance()->GetThemeColorWithDefault( |
| 562 gfx::NativeTheme::BUTTON, BP_PUSHBUTTON, PBS_NORMAL, TMT_BTNFACE, |
| 563 COLOR_BTNFACE); |
| 564 title_label_->set_background( |
| 565 views::Background::CreateSolidBackground(bk_color)); |
| 566 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 567 |
| 568 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 569 layout->AddView(title_label_, 5, 1); |
| 570 |
| 571 layout->StartRow(0, triple_column_leading_view_set_id_); |
| 572 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_LABEL)); |
| 573 layout->StartRow(0, triple_column_fill_view_set_id_); |
| 574 layout->AddView(text_fields_[TEXT_LABEL]); |
| 575 layout->StartRow(0, double_column_fill_view_set_id_); |
| 576 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); |
| 577 layout->StartRow(0, double_column_fill_view_set_id_); |
| 578 layout->AddView(text_fields_[TEXT_CC_NAME]); |
| 579 layout->StartRow(0, four_column_ccnumber_expiration_cvc_); |
| 580 layout->AddView( |
| 581 CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); |
| 582 layout->AddView( |
| 583 CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_EXPIRATION_DATE), 2, 1); |
| 584 layout->AddView(CreateLeftAlignedLabel(IDS_AUTOFILL_DIALOG_CVC)); |
| 585 layout->StartRow(0, four_column_ccnumber_expiration_cvc_); |
| 586 // Number (20 chars), month(2 chars), year (4 chars), cvc (4 chars) |
| 587 text_fields_[TEXT_CC_NUMBER]->set_default_width_in_chars(20); |
| 588 text_fields_[TEXT_CC_EXPIRATION_MONTH]->set_default_width_in_chars(2); |
| 589 text_fields_[TEXT_CC_EXPIRATION_YEAR]->set_default_width_in_chars(4); |
| 590 text_fields_[TEXT_CC_EXPIRATION_CVC]->set_default_width_in_chars(4); |
| 591 layout->AddView(text_fields_[TEXT_CC_NUMBER]); |
| 592 layout->AddView(text_fields_[TEXT_CC_EXPIRATION_MONTH]); |
| 593 layout->AddView(text_fields_[TEXT_CC_EXPIRATION_YEAR]); |
| 594 layout->AddView(text_fields_[TEXT_CC_EXPIRATION_CVC]); |
| 595 } |
| 596 |
| 597 void AutoFillProfilesView::EditableSetViewContents::InitLayoutGrid( |
| 598 views::GridLayout* layout) { |
| 599 views::ColumnSet* column_set = |
| 600 layout->AddColumnSet(double_column_fill_view_set_id_); |
| 601 int i; |
| 602 for (i = 0; i < 2; ++i) { |
| 603 if (i) |
| 604 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 605 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
| 606 views::GridLayout::USE_PREF, 0, 0); |
| 607 } |
| 608 column_set = layout->AddColumnSet(double_column_leading_view_set_id_); |
| 609 for (i = 0; i < 2; ++i) { |
| 610 if (i) |
| 611 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 612 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| 613 1, views::GridLayout::USE_PREF, 0, 0); |
| 614 } |
| 615 column_set = layout->AddColumnSet(triple_column_fill_view_set_id_); |
| 616 for (i = 0; i < 3; ++i) { |
| 617 if (i) |
| 618 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 619 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
| 620 views::GridLayout::USE_PREF, 0, 0); |
| 621 } |
| 622 column_set = layout->AddColumnSet(triple_column_leading_view_set_id_); |
| 623 for (i = 0; i < 3; ++i) { |
| 624 if (i) |
| 625 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 626 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| 627 1, views::GridLayout::USE_PREF, 0, 0); |
| 628 } |
| 629 column_set = layout->AddColumnSet(four_column_city_state_zip_set_id_); |
| 630 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 631 1, views::GridLayout::USE_PREF, 0, 0); |
| 632 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 633 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 634 1, views::GridLayout::USE_PREF, 0, 0); |
| 635 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 636 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 637 1, views::GridLayout::USE_PREF, 0, 0); |
| 638 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 639 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 640 1, views::GridLayout::USE_PREF, 0, 0); |
| 641 |
| 642 column_set = layout->AddColumnSet(four_column_ccnumber_expiration_cvc_); |
| 643 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 644 1, views::GridLayout::USE_PREF, 0, 0); |
| 645 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 646 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 647 1, views::GridLayout::USE_PREF, 0, 0); |
| 648 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 649 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 650 1, views::GridLayout::USE_PREF, 0, 0); |
| 651 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 652 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 653 1, views::GridLayout::USE_PREF, 0, 0); |
| 654 } |
| 655 |
| 656 views::Label* |
| 657 AutoFillProfilesView::EditableSetViewContents::CreateLeftAlignedLabel( |
| 658 int label_id) { |
| 659 views::Label* label = new views::Label(l10n_util::GetString(label_id)); |
| 660 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 661 return label; |
| 662 } |
| 663 |
| 664 ///////////////////////////////////////////////////////////////////////////// |
| 665 // AutoFillProfilesView::ScrollViewContents, public: |
| 666 AutoFillProfilesView::ScrollViewContents::ScrollViewContents( |
| 667 std::vector<EditableSetInfo>* profiles, |
| 668 std::vector<EditableSetInfo>* credit_cards) |
| 669 : profiles_(profiles), |
| 670 credit_cards_(credit_cards), |
| 671 add_address_(NULL), |
| 672 add_credit_card_(NULL) { |
| 673 } |
| 674 |
| 675 ///////////////////////////////////////////////////////////////////////////// |
| 676 // AutoFillProfilesView::ScrollViewContents, protected: |
| 677 ///////////////////////////////////////////////////////////////////////////// |
| 678 // AutoFillProfilesView::ScrollViewContents, views::View implementations |
| 679 int AutoFillProfilesView::ScrollViewContents::GetLineScrollIncrement( |
| 680 views::ScrollView* scroll_view, bool is_horizontal, bool is_positive) { |
| 681 if (!is_horizontal) |
| 682 return line_height_; |
| 683 return View::GetPageScrollIncrement(scroll_view, is_horizontal, is_positive); |
| 684 } |
| 685 |
| 686 void AutoFillProfilesView::ScrollViewContents::Layout() { |
| 687 views::View* parent = GetParent(); |
| 688 if (parent && parent->width()) { |
| 689 const int width = parent->width(); |
| 690 const int height = GetHeightForWidth(width); |
| 691 SetBounds(0, 0, width, height); |
| 692 } else { |
| 693 gfx::Size prefsize = GetPreferredSize(); |
| 694 SetBounds(0, 0, prefsize.width(), prefsize.height()); |
| 695 } |
| 696 View::Layout(); |
| 697 } |
| 698 |
| 699 gfx::Size AutoFillProfilesView::ScrollViewContents::GetPreferredSize() { |
| 700 return gfx::Size(); |
| 701 } |
| 702 |
| 703 void AutoFillProfilesView::ScrollViewContents::ViewHierarchyChanged( |
| 704 bool is_add, views::View* parent, views::View* child) { |
| 705 if (is_add && this == child) { |
| 706 if (!line_height_) { |
| 707 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 708 line_height_ = rb.GetFont(ResourceBundle::BaseFont).height(); |
| 709 } |
| 710 |
| 711 gfx::Rect lb = GetLocalBounds(false); |
| 712 SetBounds(lb); |
| 713 |
| 714 views::GridLayout* layout = new views::GridLayout(this); |
| 715 SetLayoutManager(layout); |
| 716 |
| 717 const int single_column_filled_view_set_id = 0; |
| 718 views::ColumnSet* column_set = |
| 719 layout->AddColumnSet(single_column_filled_view_set_id); |
| 720 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 721 views::GridLayout::USE_PREF, 0, 0); |
| 722 const int single_column_left_view_set_id = 1; |
| 723 column_set = layout->AddColumnSet(single_column_left_view_set_id); |
| 724 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, |
| 725 1, views::GridLayout::USE_PREF, 0, 0); |
| 726 views::Label *title_label = new views::Label( |
| 727 l10n_util::GetString(IDS_AUTOFILL_ADDRESSES_GROUP_NAME)); |
| 728 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 729 gfx::Font title_font = |
| 730 rb.GetFont(ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD); |
| 731 title_label->SetFont(title_font); |
| 732 layout->StartRow(0, single_column_left_view_set_id); |
| 733 layout->AddView(title_label); |
| 734 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 735 |
| 736 std::vector<EditableSetInfo>::iterator it; |
| 737 for (it = profiles_->begin(); it != profiles_->end(); ++it) { |
| 738 EditableSetViewContents *address_view = |
| 739 new EditableSetViewContents(it); |
| 740 layout->StartRow(0, single_column_filled_view_set_id); |
| 741 layout->AddView(address_view); |
| 742 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 743 } |
| 744 |
| 745 add_address_ = new views::NativeButton(this, |
| 746 l10n_util::GetString(IDS_AUTOFILL_ADD_ADDRESS_BUTTON)); |
| 747 layout->StartRow(0, single_column_left_view_set_id); |
| 748 layout->AddView(add_address_); |
| 749 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 750 |
| 751 title_label = new views::Label( |
| 752 l10n_util::GetString(IDS_AUTOFILL_CREDITCARDS_GROUP_NAME)); |
| 753 title_label->SetFont(title_font); |
| 754 layout->StartRow(0, single_column_left_view_set_id); |
| 755 layout->AddView(title_label); |
| 756 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 757 |
| 758 for (it = credit_cards_->begin(); it != credit_cards_->end(); ++it) { |
| 759 EditableSetViewContents *address_view = |
| 760 new EditableSetViewContents(it); |
| 761 layout->StartRow(0, single_column_filled_view_set_id); |
| 762 layout->AddView(address_view); |
| 763 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 764 } |
| 765 |
| 766 add_credit_card_ = new views::NativeButton(this, |
| 767 l10n_util::GetString(IDS_AUTOFILL_ADD_CREDITCARD_BUTTON)); |
| 768 |
| 769 layout->StartRow(0, single_column_left_view_set_id); |
| 770 layout->AddView(add_credit_card_); |
| 771 } |
| 772 } |
| 773 |
| 774 ///////////////////////////////////////////////////////////////////////////// |
| 775 // AutoFillProfilesView::ScrollViewContents, |
| 776 // views::ButtonListener implementations |
| 777 void AutoFillProfilesView::ScrollViewContents::ButtonPressed( |
| 778 views::Button* sender, const views::Event& event) { |
| 779 NOTIMPLEMENTED(); |
| 780 } |
| 781 |
| 782 ///////////////////////////////////////////////////////////////////////////// |
| 783 // AutoFillProfilesView::AutoFillScrollView, public: |
| 784 AutoFillProfilesView::AutoFillScrollView::AutoFillScrollView( |
| 785 std::vector<EditableSetInfo>* profiles, |
| 786 std::vector<EditableSetInfo>* credit_cards) |
| 787 : scroll_view_(new views::ScrollView), |
| 788 scroll_contents_view_(new ScrollViewContents(profiles, credit_cards)) { |
| 789 AddChildView(scroll_view_); |
| 790 scroll_view_->SetContents(scroll_contents_view_); |
| 791 set_background(new ListBackground()); |
| 792 } |
| 793 |
| 794 ///////////////////////////////////////////////////////////////////////////// |
| 795 // AutoFillProfilesView::AutoFillScrollView, views::View implementations |
| 796 void AutoFillProfilesView::AutoFillScrollView::Layout() { |
| 797 gfx::Rect lb = GetLocalBounds(false); |
| 798 |
| 799 gfx::Size border = gfx::NativeTheme::instance()->GetThemeBorderSize( |
| 800 gfx::NativeTheme::LIST); |
| 801 lb.Inset(border.width(), border.height()); |
| 802 scroll_view_->SetBounds(lb); |
| 803 scroll_view_->Layout(); |
| 804 } |
| 805 |
OLD | NEW |