| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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/views/autofill/save_card_bubble_view.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" |
| 9 #include "ui/views/bubble/bubble_frame_view.h" |
| 10 #include "ui/views/controls/button/blue_button.h" |
| 11 #include "ui/views/controls/button/label_button.h" |
| 12 #include "ui/views/layout/grid_layout.h" |
| 13 #include "ui/views/layout/layout_constants.h" |
| 14 |
| 15 using views::GridLayout; |
| 16 |
| 17 namespace { |
| 18 |
| 19 // Fixed width of the column holding the message text. |
| 20 const int kWidthOfMessageText = 375; |
| 21 |
| 22 } // namespace |
| 23 |
| 24 namespace autofill { |
| 25 |
| 26 // static |
| 27 SaveCardBubbleView* SaveCardBubbleView::save_card_bubble_view_ = nullptr; |
| 28 |
| 29 SaveCardBubbleView::SaveCardBubbleView(views::View* anchor_view, |
| 30 content::WebContents* web_contents, |
| 31 SaveCardBubbleController* controller) |
| 32 : ManagedFullScreenBubbleDelegateView(anchor_view, web_contents), |
| 33 controller_(controller), |
| 34 save_button_(nullptr), |
| 35 cancel_button_(nullptr) {} |
| 36 |
| 37 SaveCardBubbleView::~SaveCardBubbleView() {} |
| 38 |
| 39 // static |
| 40 void SaveCardBubbleView::ShowBubble(views::View* anchor_view, |
| 41 content::WebContents* web_contents, |
| 42 SaveCardBubbleController* controller) { |
| 43 DCHECK_EQ(save_card_bubble_view_, static_cast<SaveCardBubbleView*>(NULL)); |
| 44 |
| 45 save_card_bubble_view_ = |
| 46 new SaveCardBubbleView(anchor_view, web_contents, controller); |
| 47 views::BubbleDelegateView::CreateBubble(save_card_bubble_view_)->Show(); |
| 48 } |
| 49 |
| 50 // static |
| 51 void SaveCardBubbleView::CloseBubble() { |
| 52 if (!save_card_bubble_view_) |
| 53 return; |
| 54 |
| 55 save_card_bubble_view_->GetWidget()->Close(); |
| 56 } |
| 57 |
| 58 // static |
| 59 SaveCardBubbleView* SaveCardBubbleView::GetCurrentBubble() { |
| 60 return save_card_bubble_view_; |
| 61 } |
| 62 |
| 63 views::View* SaveCardBubbleView::GetInitiallyFocusedView() { |
| 64 return save_button_; |
| 65 } |
| 66 |
| 67 base::string16 SaveCardBubbleView::GetWindowTitle() const { |
| 68 // TODO(bondd) before commit: Use l10n string. |
| 69 return base::ASCIIToUTF16("Do you want to save this card with Chrome?"); |
| 70 } |
| 71 |
| 72 bool SaveCardBubbleView::ShouldShowWindowTitle() const { |
| 73 return true; |
| 74 } |
| 75 |
| 76 void SaveCardBubbleView::WindowClosing() { |
| 77 DCHECK_EQ(save_card_bubble_view_, this); |
| 78 save_card_bubble_view_ = nullptr; |
| 79 controller_->OnBubbleClosed(); |
| 80 } |
| 81 |
| 82 void SaveCardBubbleView::ButtonPressed(views::Button* sender, |
| 83 const ui::Event& event) { |
| 84 if (sender == save_button_) { |
| 85 controller_->OnSaveButton(); |
| 86 } else { |
| 87 DCHECK(sender == cancel_button_); |
| 88 controller_->OnCancelButton(); |
| 89 } |
| 90 GetWidget()->Close(); |
| 91 } |
| 92 |
| 93 void SaveCardBubbleView::Init() { |
| 94 enum { |
| 95 COLUMN_SET_ID_MESSAGE, |
| 96 COLUMN_SET_ID_BUTTONS, |
| 97 }; |
| 98 |
| 99 GridLayout* layout = new GridLayout(this); |
| 100 SetLayoutManager(layout); |
| 101 |
| 102 // Set up ColumnSet that will contain the full-width message text. |
| 103 int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left(); |
| 104 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE); |
| 105 cs->AddPaddingColumn(0, horizontal_inset); |
| 106 // TODO(bondd): Current dialog layout has no message text, but future layouts |
| 107 // will. This padding column is used until then to set the dialog width. |
| 108 cs->AddPaddingColumn(1, kWidthOfMessageText); |
| 109 cs->AddPaddingColumn(0, horizontal_inset); |
| 110 |
| 111 // Set up ColumnSet that will contain the buttons. |
| 112 cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS); |
| 113 cs->AddPaddingColumn(1, 0); |
| 114 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 115 GridLayout::USE_PREF, 0, 0); |
| 116 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
| 117 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
| 118 GridLayout::USE_PREF, 0, 0); |
| 119 cs->AddPaddingColumn(0, horizontal_inset); |
| 120 |
| 121 // Create accept button and add it to layout. |
| 122 // TODO(bondd) before commit: Use l10n string. |
| 123 save_button_ = new views::BlueButton(this, base::ASCIIToUTF16("Save")); |
| 124 save_button_->SetIsDefault(true); |
| 125 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); |
| 126 layout->AddView(save_button_); |
| 127 |
| 128 // Create cancel button and add it to layout. |
| 129 // TODO(bondd) before commit: Use l10n string. |
| 130 cancel_button_ = |
| 131 new views::LabelButton(this, base::ASCIIToUTF16("No thanks")); |
| 132 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 133 layout->AddView(cancel_button_); |
| 134 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 135 |
| 136 set_margins(gfx::Insets(1, 0, 1, 0)); |
| 137 Layout(); |
| 138 } |
| 139 |
| 140 } // namespace autofill |
| OLD | NEW |