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 |
| 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILES_VIEW_WIN_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILES_VIEW_WIN_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "chrome/browser/autofill/autofill_dialog.h" |
| 11 #include "chrome/browser/autofill/autofill_profile.h" |
| 12 #include "views/controls/textfield/textfield.h" |
| 13 #include "views/view.h" |
| 14 #include "views/window/dialog_delegate.h" |
| 15 |
| 16 namespace views { |
| 17 class ScrollView; |
| 18 class Label; |
| 19 class GridLayout; |
| 20 } |
| 21 |
| 22 /////////////////////////////////////////////////////////////////////////////// |
| 23 // AutoFillProfilesView |
| 24 // |
| 25 // The contents of the "Autofill profiles" dialog window. |
| 26 // |
| 27 // Overview: has following sub-views: |
| 28 // AutoFillScrollView - scroll view that has all of the addresses and credit |
| 29 // cards. Implemented by connecting views::ScrollView to ScrollViewContents. |
| 30 // ScrollViewContents - contents of the scroll view. Has multiple |
| 31 // EditableSetViewContents views for credit cards and addresses and |
| 32 // 'Add address' and 'Add Credit Card' buttons. |
| 33 // EditableSetViewContents - set of displayed fields for address or credit card, |
| 34 // has iterator to std::vector<EditableSetInfo> vector so data could be |
| 35 // updated or notifications passes to the dialog view. |
| 36 // PhoneSubView - support view for the phone fields sets. used in |
| 37 // ScrollViewContents. |
| 38 // And there is a support data structure EditableSetInfo which encapsulates |
| 39 // editable set (address or credit card) and allows for quick addition and |
| 40 // deletion. |
| 41 class AutoFillProfilesView : public views::View, |
| 42 public views::DialogDelegate, |
| 43 public views::ButtonListener { |
| 44 public: |
| 45 virtual ~AutoFillProfilesView(); |
| 46 |
| 47 static int Show(AutoFillDialogObserver* observer, |
| 48 const std::vector<AutoFillProfile*>& profiles, |
| 49 const std::vector<CreditCard*>& credit_cards); |
| 50 |
| 51 protected: |
| 52 // views::View methods: |
| 53 virtual void Layout(); |
| 54 virtual gfx::Size GetPreferredSize(); |
| 55 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, |
| 56 views::View* child); |
| 57 |
| 58 // views::DialogDelegate methods: |
| 59 virtual int GetDialogButtons() const; |
| 60 virtual std::wstring GetDialogButtonLabel( |
| 61 MessageBoxFlags::DialogButton button) const; |
| 62 virtual bool CanResize() const { return true; } |
| 63 virtual bool CanMaximize() const { return true; } |
| 64 virtual bool IsAlwaysOnTop() const { return false; } |
| 65 virtual bool HasAlwaysOnTopMenu() const { return false; } |
| 66 virtual std::wstring GetWindowTitle() const; |
| 67 virtual void WindowClosing(); |
| 68 virtual views::View* GetContentsView(); |
| 69 virtual bool Accept(); |
| 70 |
| 71 // views::ButtonListener methods: |
| 72 virtual void ButtonPressed(views::Button* sender, |
| 73 const views::Event& event); |
| 74 |
| 75 // Helper structure to keep info on one address or credit card. |
| 76 // Keeps info on one item in EditableSetViewContents. |
| 77 // Also keeps info on opened status. Allows to quickly add and delete items, |
| 78 // and then rebuild EditableSetViewContents. |
| 79 struct EditableSetInfo { |
| 80 bool is_address; |
| 81 bool is_opened; |
| 82 // If |is_address| is true |address| has some data and |credit_card| |
| 83 // is empty, and vice versa |
| 84 AutoFillProfile address; |
| 85 CreditCard credit_card; |
| 86 |
| 87 EditableSetInfo(const AutoFillProfile* input_address, bool opened) |
| 88 : address(*input_address), |
| 89 is_address(true), |
| 90 is_opened(opened) { |
| 91 } |
| 92 EditableSetInfo(const CreditCard* input_credit_card, bool opened) |
| 93 : credit_card(*input_credit_card), |
| 94 is_address(false), |
| 95 is_opened(opened) { |
| 96 } |
| 97 }; |
| 98 |
| 99 // Callbacks, called from EditableSetViewContents and ScrollViewContents. |
| 100 // Called from ScrollViewContents when 'Add Address' (|address| is true) or |
| 101 // 'Add Credit Card' (|address| is false) is clicked. |
| 102 void AddClicked(bool address); |
| 103 // Called from EditableSetViewContents when 'Delete' is clicked. |
| 104 // |field_set_iterator| is iterator to item being deleted |
| 105 void DeleteEditableSet(std::vector<EditableSetInfo>::iterator |
| 106 field_set_iterator); |
| 107 // Called from EditableSetViewContents when header of the item is clicked |
| 108 // either to collapse or expand. |field_set_iterator| is iterator to item |
| 109 // being changed. |
| 110 void CollapseStateChanged(std::vector<EditableSetInfo>::iterator |
| 111 field_set_iterator); |
| 112 |
| 113 private: |
| 114 AutoFillProfilesView(AutoFillDialogObserver* observer, |
| 115 const std::vector<AutoFillProfile*>& profiles, |
| 116 const std::vector<CreditCard*>& credit_cards); |
| 117 void Init(); |
| 118 |
| 119 // PhoneSubView encapsulates three phone fields (country, area, and phone) |
| 120 // and label above them, so they could be used together in one grid cell. |
| 121 class PhoneSubView : public views::View { |
| 122 public: |
| 123 PhoneSubView(views::Label* label, |
| 124 views::Textfield* text_country, |
| 125 views::Textfield* text_area, |
| 126 views::Textfield* text_phone); |
| 127 virtual ~PhoneSubView() {} |
| 128 |
| 129 protected: |
| 130 // views::View methods: |
| 131 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, |
| 132 views::View* child); |
| 133 private: |
| 134 views::Label* label_; |
| 135 views::Textfield* text_country_; |
| 136 views::Textfield* text_area_; |
| 137 views::Textfield* text_phone_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(PhoneSubView); |
| 140 }; |
| 141 |
| 142 // Sub-view dealing with addresses. |
| 143 class EditableSetViewContents : public views::View, |
| 144 public views::Textfield::Controller, |
| 145 public views::ButtonListener { |
| 146 public: |
| 147 explicit EditableSetViewContents( |
| 148 std::vector<EditableSetInfo>::iterator field_set); |
| 149 virtual ~EditableSetViewContents() {} |
| 150 |
| 151 protected: |
| 152 // views::View methods: |
| 153 virtual void Layout(); |
| 154 virtual gfx::Size GetPreferredSize(); |
| 155 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, |
| 156 views::View* child); |
| 157 |
| 158 // views::Textfield::Controller methods: |
| 159 virtual void ContentsChanged(views::Textfield* sender, |
| 160 const string16& new_contents); |
| 161 virtual bool HandleKeystroke(views::Textfield* sender, |
| 162 const views::Textfield::Keystroke& keystroke); |
| 163 |
| 164 // views::ButtonListener methods: |
| 165 virtual void ButtonPressed(views::Button* sender, |
| 166 const views::Event& event); |
| 167 private: |
| 168 void InitAddressFields(views::GridLayout* layout); |
| 169 void InitCreditCardFields(views::GridLayout* layout); |
| 170 void InitLayoutGrid(views::GridLayout* layout); |
| 171 views::Label* CreateLeftAlignedLabel(int label_id); |
| 172 |
| 173 enum TextFields { |
| 174 TEXT_LABEL, |
| 175 TEXT_FIRST_NAME, |
| 176 TEXT_MIDDLE_NAME, |
| 177 TEXT_LAST_NAME, |
| 178 TEXT_EMAIL, |
| 179 TEXT_COMPANY_NAME, |
| 180 TEXT_ADDRESS_LINE_1, |
| 181 TEXT_ADDRESS_LINE_2, |
| 182 TEXT_ADDRESS_CITY, |
| 183 TEXT_ADDRESS_STATE, |
| 184 TEXT_ADDRESS_ZIP, |
| 185 TEXT_ADDRESS_COUNTRY, |
| 186 TEXT_PHONE_COUNTRY, |
| 187 TEXT_PHONE_AREA, |
| 188 TEXT_PHONE_PHONE, |
| 189 TEXT_FAX_COUNTRY, |
| 190 TEXT_FAX_AREA, |
| 191 TEXT_FAX_PHONE, |
| 192 TEXT_CC_NAME, |
| 193 TEXT_CC_NUMBER, |
| 194 TEXT_CC_EXPIRATION_MONTH, |
| 195 TEXT_CC_EXPIRATION_YEAR, |
| 196 TEXT_CC_EXPIRATION_CVC, |
| 197 // must be last |
| 198 MAX_TEXT_FIELD |
| 199 }; |
| 200 views::Textfield* text_fields_[MAX_TEXT_FIELD]; |
| 201 std::vector<EditableSetInfo>::iterator editable_fields_set_; |
| 202 views::Label* title_label_; |
| 203 views::Button* delete_button_; |
| 204 |
| 205 struct TextFieldToAutoFill { |
| 206 TextFields text_field; |
| 207 AutoFillFieldType type; |
| 208 }; |
| 209 |
| 210 static TextFieldToAutoFill address_fields_[]; |
| 211 static TextFieldToAutoFill credit_card_fields_[]; |
| 212 |
| 213 static const int double_column_fill_view_set_id_ = 0; |
| 214 static const int double_column_leading_view_set_id_ = 1; |
| 215 static const int triple_column_fill_view_set_id_ = 2; |
| 216 static const int triple_column_leading_view_set_id_ = 3; |
| 217 static const int four_column_city_state_zip_set_id_ = 4; |
| 218 static const int four_column_ccnumber_expiration_cvc_ = 5; |
| 219 |
| 220 DISALLOW_COPY_AND_ASSIGN(EditableSetViewContents); |
| 221 }; |
| 222 |
| 223 // Sub-view for scrolling credit cards and addresses |
| 224 class ScrollViewContents : public views::View, |
| 225 public views::ButtonListener { |
| 226 public: |
| 227 ScrollViewContents(std::vector<EditableSetInfo>* profiles, |
| 228 std::vector<EditableSetInfo>* credit_cards); |
| 229 virtual ~ScrollViewContents() {} |
| 230 |
| 231 protected: |
| 232 // views::View methods: |
| 233 virtual int GetLineScrollIncrement(views::ScrollView* scroll_view, |
| 234 bool is_horizontal, bool is_positive); |
| 235 virtual void Layout(); |
| 236 virtual gfx::Size GetPreferredSize(); |
| 237 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, |
| 238 views::View* child); |
| 239 // views::ButtonListener methods: |
| 240 virtual void ButtonPressed(views::Button* sender, |
| 241 const views::Event& event); |
| 242 private: |
| 243 std::vector<EditableSetInfo>* profiles_; |
| 244 std::vector<EditableSetInfo>* credit_cards_; |
| 245 views::Button* add_address_; |
| 246 views::Button* add_credit_card_; |
| 247 |
| 248 static int line_height_; |
| 249 |
| 250 DISALLOW_COPY_AND_ASSIGN(ScrollViewContents); |
| 251 }; |
| 252 |
| 253 class AutoFillScrollView : public views::View { |
| 254 public: |
| 255 AutoFillScrollView(std::vector<EditableSetInfo>* profiles, |
| 256 std::vector<EditableSetInfo>* credit_cards); |
| 257 virtual ~AutoFillScrollView() {} |
| 258 |
| 259 protected: |
| 260 // views::View overrides: |
| 261 virtual void Layout(); |
| 262 |
| 263 private: |
| 264 // The scroll view that contains list of the profiles. |
| 265 views::ScrollView* scroll_view_; |
| 266 ScrollViewContents* scroll_contents_view_; |
| 267 |
| 268 DISALLOW_COPY_AND_ASSIGN(AutoFillScrollView); |
| 269 }; |
| 270 |
| 271 AutoFillDialogObserver* observer_; |
| 272 std::vector<EditableSetInfo> profiles_set_; |
| 273 std::vector<EditableSetInfo> credit_card_set_; |
| 274 |
| 275 views::Button* save_changes_; |
| 276 AutoFillScrollView* scroll_view_; |
| 277 |
| 278 static AutoFillProfilesView* instance_; |
| 279 |
| 280 DISALLOW_COPY_AND_ASSIGN(AutoFillProfilesView); |
| 281 }; |
| 282 |
| 283 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_PROFILES_VIEW_WIN_H_ |
| 284 |
OLD | NEW |