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