OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 0)); | 230 0)); |
231 } | 231 } |
232 | 232 |
233 void AutofillDialogViews::AccountChooser::LinkClicked(views::Link* source, | 233 void AutofillDialogViews::AccountChooser::LinkClicked(views::Link* source, |
234 int event_flags) { | 234 int event_flags) { |
235 controller_->StartSignInFlow(); | 235 controller_->StartSignInFlow(); |
236 } | 236 } |
237 | 237 |
238 // AutofillDialogViews::NotificationArea --------------------------------------- | 238 // AutofillDialogViews::NotificationArea --------------------------------------- |
239 | 239 |
240 AutofillDialogViews::NotificationArea::NotificationArea() | 240 AutofillDialogViews::NotificationArea::NotificationArea( |
241 : checkbox_(NULL) { | 241 AutofillDialogController* controller) |
| 242 : controller_(controller), |
| 243 checkbox_(NULL) { |
242 // Reserve vertical space for the arrow (regardless of whether one exists). | 244 // Reserve vertical space for the arrow (regardless of whether one exists). |
243 set_border(views::Border::CreateEmptyBorder(kArrowHeight, 0, 0, 0)); | 245 set_border(views::Border::CreateEmptyBorder(kArrowHeight, 0, 0, 0)); |
244 | 246 |
245 views::BoxLayout* box_layout = | 247 views::BoxLayout* box_layout = |
246 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | 248 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
247 SetLayoutManager(box_layout); | 249 SetLayoutManager(box_layout); |
248 } | 250 } |
249 | 251 |
250 AutofillDialogViews::NotificationArea::~NotificationArea() {} | 252 AutofillDialogViews::NotificationArea::~NotificationArea() {} |
251 | 253 |
252 void AutofillDialogViews::NotificationArea::SetNotifications( | 254 void AutofillDialogViews::NotificationArea::SetNotifications( |
253 const std::vector<DialogNotification>& notifications) { | 255 const std::vector<DialogNotification>& notifications) { |
254 notifications_ = notifications; | 256 notifications_ = notifications; |
255 | 257 |
256 // Default checkbox to checked. Preserve checkbox state if it already exists. | |
257 bool checkbox_state = checkbox_ ? checkbox_->checked() : true; | |
258 RemoveAllChildViews(true); | 258 RemoveAllChildViews(true); |
259 checkbox_ = NULL; | 259 checkbox_ = NULL; |
260 | 260 |
261 if (notifications_.empty()) | 261 if (notifications_.empty()) |
262 return; | 262 return; |
263 | 263 |
264 for (size_t i = 0; i < notifications_.size(); ++i) { | 264 for (size_t i = 0; i < notifications_.size(); ++i) { |
265 const DialogNotification& notification = notifications_[i]; | 265 const DialogNotification& notification = notifications_[i]; |
266 | 266 |
267 scoped_ptr<views::View> view; | 267 scoped_ptr<views::View> view; |
268 if (notification.HasCheckbox()) { | 268 if (notification.HasCheckbox()) { |
269 scoped_ptr<views::Checkbox> checkbox(new views::Checkbox(string16())); | 269 scoped_ptr<views::Checkbox> checkbox(new views::Checkbox(string16())); |
270 checkbox_ = checkbox.get(); | 270 checkbox_ = checkbox.get(); |
271 // We have to do this instead of using set_border() because a border | 271 // We have to do this instead of using set_border() because a border |
272 // is being used to draw the check square. | 272 // is being used to draw the check square. |
273 static_cast<views::CheckboxNativeThemeBorder*>(checkbox->border())-> | 273 static_cast<views::CheckboxNativeThemeBorder*>(checkbox->border())-> |
274 SetCustomInsets(gfx::Insets(kNotificationPadding, | 274 SetCustomInsets(gfx::Insets(kNotificationPadding, |
275 kNotificationPadding, | 275 kNotificationPadding, |
276 kNotificationPadding, | 276 kNotificationPadding, |
277 kNotificationPadding)); | 277 kNotificationPadding)); |
278 checkbox->SetChecked(checkbox_state); | |
279 if (!notification.interactive()) | 278 if (!notification.interactive()) |
280 checkbox->SetState(views::Button::STATE_DISABLED); | 279 checkbox->SetState(views::Button::STATE_DISABLED); |
281 checkbox->SetText(notification.display_text()); | 280 checkbox->SetText(notification.display_text()); |
282 checkbox->SetMultiLine(true); | 281 checkbox->SetMultiLine(true); |
283 checkbox->set_alignment(views::TextButtonBase::ALIGN_LEFT); | 282 checkbox->set_alignment(views::TextButtonBase::ALIGN_LEFT); |
284 checkbox->SetEnabledColor(notification.GetTextColor()); | 283 checkbox->SetEnabledColor(notification.GetTextColor()); |
285 checkbox->SetHoverColor(notification.GetTextColor()); | 284 checkbox->SetHoverColor(notification.GetTextColor()); |
| 285 checkbox->SetChecked(notification.checked()); |
| 286 checkbox->set_listener(this); |
286 view.reset(checkbox.release()); | 287 view.reset(checkbox.release()); |
287 } else { | 288 } else { |
288 scoped_ptr<views::Label> label(new views::Label()); | 289 scoped_ptr<views::Label> label(new views::Label()); |
289 label->SetText(notification.display_text()); | 290 label->SetText(notification.display_text()); |
290 label->SetMultiLine(true); | 291 label->SetMultiLine(true); |
291 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 292 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
292 label->SetAutoColorReadabilityEnabled(false); | 293 label->SetAutoColorReadabilityEnabled(false); |
293 label->SetEnabledColor(notification.GetTextColor()); | 294 label->SetEnabledColor(notification.GetTextColor()); |
294 label->set_border(views::Border::CreateSolidBorder( | 295 label->set_border(views::Border::CreateSolidBorder( |
295 kNotificationPadding, notification.GetBackgroundColor())); | 296 kNotificationPadding, notification.GetBackgroundColor())); |
296 view.reset(label.release()); | 297 view.reset(label.release()); |
297 } | 298 } |
298 | 299 |
299 view->set_background(views::Background::CreateSolidBackground( | 300 view->set_background(views::Background::CreateSolidBackground( |
300 notification.GetBackgroundColor())); | 301 notification.GetBackgroundColor())); |
301 AddChildView(view.release()); | 302 AddChildView(view.release()); |
302 } | 303 } |
303 | 304 |
304 PreferredSizeChanged(); | 305 PreferredSizeChanged(); |
305 } | 306 } |
306 | 307 |
307 bool AutofillDialogViews::NotificationArea::CheckboxIsChecked() const { | |
308 return checkbox_ && checkbox_->checked(); | |
309 } | |
310 | |
311 std::string AutofillDialogViews::NotificationArea::GetClassName() const { | 308 std::string AutofillDialogViews::NotificationArea::GetClassName() const { |
312 return kNotificationAreaClassName; | 309 return kNotificationAreaClassName; |
313 } | 310 } |
314 | 311 |
315 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) { | 312 void AutofillDialogViews::NotificationArea::OnPaint(gfx::Canvas* canvas) { |
316 views::View::OnPaint(canvas); | 313 views::View::OnPaint(canvas); |
317 | 314 |
318 if (HasArrow()) { | 315 if (HasArrow()) { |
319 const int arrow_half_width = kArrowWidth / 2.0f; | 316 const int arrow_half_width = kArrowWidth / 2.0f; |
320 const int anchor_half_width = | 317 const int anchor_half_width = |
321 arrow_centering_anchor_->width() / 2.0f; | 318 arrow_centering_anchor_->width() / 2.0f; |
322 const int arrow_middle = | 319 const int arrow_middle = |
323 GetMirroredXInView(width() - anchor_half_width - arrow_half_width); | 320 GetMirroredXInView(width() - anchor_half_width - arrow_half_width); |
324 | 321 |
325 SkPath arrow; | 322 SkPath arrow; |
326 arrow.moveTo(arrow_middle - arrow_half_width, kArrowHeight); | 323 arrow.moveTo(arrow_middle - arrow_half_width, kArrowHeight); |
327 arrow.lineTo(arrow_middle + arrow_half_width, kArrowHeight); | 324 arrow.lineTo(arrow_middle + arrow_half_width, kArrowHeight); |
328 arrow.lineTo(arrow_middle, 0); | 325 arrow.lineTo(arrow_middle, 0); |
329 arrow.close(); | 326 arrow.close(); |
330 canvas->ClipPath(arrow); | 327 canvas->ClipPath(arrow); |
331 canvas->DrawColor(notifications_[0].GetBackgroundColor()); | 328 canvas->DrawColor(notifications_[0].GetBackgroundColor()); |
332 } | 329 } |
333 } | 330 } |
334 | 331 |
| 332 void AutofillDialogViews::NotificationArea::ButtonPressed( |
| 333 views::Button* sender, const ui::Event& event) { |
| 334 DCHECK_EQ(sender, checkbox_); |
| 335 controller_->NotificationCheckboxStateChanged(notifications_.front().type(), |
| 336 checkbox_->checked()); |
| 337 } |
| 338 |
335 bool AutofillDialogViews::NotificationArea::HasArrow() { | 339 bool AutofillDialogViews::NotificationArea::HasArrow() { |
336 return !notifications_.empty() && notifications_[0].HasArrow() && | 340 return !notifications_.empty() && notifications_[0].HasArrow() && |
337 arrow_centering_anchor_.get(); | 341 arrow_centering_anchor_.get(); |
338 } | 342 } |
339 | 343 |
340 // AutofillDialogViews::SectionContainer --------------------------------------- | 344 // AutofillDialogViews::SectionContainer --------------------------------------- |
341 | 345 |
342 AutofillDialogViews::SectionContainer::SectionContainer( | 346 AutofillDialogViews::SectionContainer::SectionContainer( |
343 const string16& label, | 347 const string16& label, |
344 views::View* controls, | 348 views::View* controls, |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ? | 706 DialogSection billing_section = controller_->SectionIsActive(SECTION_CC) ? |
703 SECTION_CC : SECTION_CC_BILLING; | 707 SECTION_CC : SECTION_CC_BILLING; |
704 return GroupForSection(billing_section)->suggested_info-> | 708 return GroupForSection(billing_section)->suggested_info-> |
705 decorated_textfield()->textfield()->text(); | 709 decorated_textfield()->textfield()->text(); |
706 } | 710 } |
707 | 711 |
708 bool AutofillDialogViews::UseBillingForShipping() { | 712 bool AutofillDialogViews::UseBillingForShipping() { |
709 return use_billing_for_shipping_->checked(); | 713 return use_billing_for_shipping_->checked(); |
710 } | 714 } |
711 | 715 |
712 bool AutofillDialogViews::SaveDetailsInWallet() { | |
713 return notification_area_->CheckboxIsChecked(); | |
714 } | |
715 | |
716 bool AutofillDialogViews::SaveDetailsLocally() { | 716 bool AutofillDialogViews::SaveDetailsLocally() { |
717 return save_in_chrome_checkbox_->checked(); | 717 return save_in_chrome_checkbox_->checked(); |
718 } | 718 } |
719 | 719 |
720 const content::NavigationController* AutofillDialogViews::ShowSignIn() { | 720 const content::NavigationController* AutofillDialogViews::ShowSignIn() { |
721 // TODO(abodenha) We should be able to use the WebContents of the WebView | 721 // TODO(abodenha) We should be able to use the WebContents of the WebView |
722 // to navigate instead of LoadInitialURL. Figure out why it doesn't work. | 722 // to navigate instead of LoadInitialURL. Figure out why it doesn't work. |
723 | 723 |
724 account_chooser_->SetSignInLinkEnabled(false); | 724 account_chooser_->SetSignInLinkEnabled(false); |
725 sign_in_webview_->LoadInitialURL(wallet::GetSignInUrl()); | 725 sign_in_webview_->LoadInitialURL(wallet::GetSignInUrl()); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 views::View* AutofillDialogViews::CreateMainContainer() { | 1002 views::View* AutofillDialogViews::CreateMainContainer() { |
1003 main_container_ = new views::View(); | 1003 main_container_ = new views::View(); |
1004 main_container_->SetLayoutManager( | 1004 main_container_->SetLayoutManager( |
1005 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | 1005 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
1006 views::kRelatedControlVerticalSpacing)); | 1006 views::kRelatedControlVerticalSpacing)); |
1007 | 1007 |
1008 account_chooser_ = new AccountChooser(controller_); | 1008 account_chooser_ = new AccountChooser(controller_); |
1009 if (!views::DialogDelegate::UseNewStyle()) | 1009 if (!views::DialogDelegate::UseNewStyle()) |
1010 main_container_->AddChildView(account_chooser_); | 1010 main_container_->AddChildView(account_chooser_); |
1011 | 1011 |
1012 notification_area_ = new NotificationArea(); | 1012 notification_area_ = new NotificationArea(controller_); |
1013 notification_area_->set_arrow_centering_anchor(account_chooser_->AsWeakPtr()); | 1013 notification_area_->set_arrow_centering_anchor(account_chooser_->AsWeakPtr()); |
1014 main_container_->AddChildView(notification_area_); | 1014 main_container_->AddChildView(notification_area_); |
1015 | 1015 |
1016 main_container_->AddChildView(CreateDetailsContainer()); | 1016 main_container_->AddChildView(CreateDetailsContainer()); |
1017 return main_container_; | 1017 return main_container_; |
1018 } | 1018 } |
1019 | 1019 |
1020 views::View* AutofillDialogViews::CreateDetailsContainer() { | 1020 views::View* AutofillDialogViews::CreateDetailsContainer() { |
1021 details_container_ = new views::View(); | 1021 details_container_ = new views::View(); |
1022 // A box layout is used because it respects widget visibility. | 1022 // A box layout is used because it respects widget visibility. |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 1398 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
1399 : section(section), | 1399 : section(section), |
1400 container(NULL), | 1400 container(NULL), |
1401 manual_input(NULL), | 1401 manual_input(NULL), |
1402 suggested_info(NULL), | 1402 suggested_info(NULL), |
1403 suggested_button(NULL) {} | 1403 suggested_button(NULL) {} |
1404 | 1404 |
1405 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 1405 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
1406 | 1406 |
1407 } // namespace autofill | 1407 } // namespace autofill |
OLD | NEW |