| Index: chrome/browser/ui/views/autofill/save_card_bubble_view.cc
|
| diff --git a/chrome/browser/ui/views/autofill/save_card_bubble_view.cc b/chrome/browser/ui/views/autofill/save_card_bubble_view.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..171ddfa7078f5f6e78785949d1223f5b224afdb8
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/autofill/save_card_bubble_view.cc
|
| @@ -0,0 +1,140 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/views/autofill/save_card_bubble_view.h"
|
| +
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/ui/autofill/save_card_bubble_controller.h"
|
| +#include "ui/views/bubble/bubble_frame_view.h"
|
| +#include "ui/views/controls/button/blue_button.h"
|
| +#include "ui/views/controls/button/label_button.h"
|
| +#include "ui/views/layout/grid_layout.h"
|
| +#include "ui/views/layout/layout_constants.h"
|
| +
|
| +using views::GridLayout;
|
| +
|
| +namespace {
|
| +
|
| +// Fixed width of the column holding the message text.
|
| +const int kWidthOfMessageText = 375;
|
| +
|
| +} // namespace
|
| +
|
| +namespace autofill {
|
| +
|
| +// static
|
| +SaveCardBubbleView* SaveCardBubbleView::save_card_bubble_view_ = nullptr;
|
| +
|
| +SaveCardBubbleView::SaveCardBubbleView(views::View* anchor_view,
|
| + content::WebContents* web_contents,
|
| + SaveCardBubbleController* controller)
|
| + : ManagedFullScreenBubbleDelegateView(anchor_view, web_contents),
|
| + controller_(controller),
|
| + save_button_(nullptr),
|
| + cancel_button_(nullptr) {}
|
| +
|
| +SaveCardBubbleView::~SaveCardBubbleView() {}
|
| +
|
| +// static
|
| +void SaveCardBubbleView::ShowBubble(views::View* anchor_view,
|
| + content::WebContents* web_contents,
|
| + SaveCardBubbleController* controller) {
|
| + DCHECK_EQ(save_card_bubble_view_, static_cast<SaveCardBubbleView*>(NULL));
|
| +
|
| + save_card_bubble_view_ =
|
| + new SaveCardBubbleView(anchor_view, web_contents, controller);
|
| + views::BubbleDelegateView::CreateBubble(save_card_bubble_view_)->Show();
|
| +}
|
| +
|
| +// static
|
| +void SaveCardBubbleView::CloseBubble() {
|
| + if (!save_card_bubble_view_)
|
| + return;
|
| +
|
| + save_card_bubble_view_->GetWidget()->Close();
|
| +}
|
| +
|
| +// static
|
| +SaveCardBubbleView* SaveCardBubbleView::GetCurrentBubble() {
|
| + return save_card_bubble_view_;
|
| +}
|
| +
|
| +views::View* SaveCardBubbleView::GetInitiallyFocusedView() {
|
| + return save_button_;
|
| +}
|
| +
|
| +base::string16 SaveCardBubbleView::GetWindowTitle() const {
|
| + // TODO(bondd) before commit: Use l10n string.
|
| + return base::ASCIIToUTF16("Do you want to save this card with Chrome?");
|
| +}
|
| +
|
| +bool SaveCardBubbleView::ShouldShowWindowTitle() const {
|
| + return true;
|
| +}
|
| +
|
| +void SaveCardBubbleView::WindowClosing() {
|
| + DCHECK_EQ(save_card_bubble_view_, this);
|
| + save_card_bubble_view_ = nullptr;
|
| + controller_->OnBubbleClosed();
|
| +}
|
| +
|
| +void SaveCardBubbleView::ButtonPressed(views::Button* sender,
|
| + const ui::Event& event) {
|
| + if (sender == save_button_) {
|
| + controller_->OnSaveButton();
|
| + } else {
|
| + DCHECK(sender == cancel_button_);
|
| + controller_->OnCancelButton();
|
| + }
|
| + GetWidget()->Close();
|
| +}
|
| +
|
| +void SaveCardBubbleView::Init() {
|
| + enum {
|
| + COLUMN_SET_ID_MESSAGE,
|
| + COLUMN_SET_ID_BUTTONS,
|
| + };
|
| +
|
| + GridLayout* layout = new GridLayout(this);
|
| + SetLayoutManager(layout);
|
| +
|
| + // Set up ColumnSet that will contain the full-width message text.
|
| + int horizontal_inset = GetBubbleFrameView()->GetTitleInsets().left();
|
| + views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_ID_MESSAGE);
|
| + cs->AddPaddingColumn(0, horizontal_inset);
|
| + // TODO(bondd): Current dialog layout has no message text, but future layouts
|
| + // will. This padding column is used until then to set the dialog width.
|
| + cs->AddPaddingColumn(1, kWidthOfMessageText);
|
| + cs->AddPaddingColumn(0, horizontal_inset);
|
| +
|
| + // Set up ColumnSet that will contain the buttons.
|
| + cs = layout->AddColumnSet(COLUMN_SET_ID_BUTTONS);
|
| + cs->AddPaddingColumn(1, 0);
|
| + cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
|
| + GridLayout::USE_PREF, 0, 0);
|
| + cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
|
| + cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
|
| + GridLayout::USE_PREF, 0, 0);
|
| + cs->AddPaddingColumn(0, horizontal_inset);
|
| +
|
| + // Create accept button and add it to layout.
|
| + // TODO(bondd) before commit: Use l10n string.
|
| + save_button_ = new views::BlueButton(this, base::ASCIIToUTF16("Save"));
|
| + save_button_->SetIsDefault(true);
|
| + layout->StartRow(0, COLUMN_SET_ID_BUTTONS);
|
| + layout->AddView(save_button_);
|
| +
|
| + // Create cancel button and add it to layout.
|
| + // TODO(bondd) before commit: Use l10n string.
|
| + cancel_button_ =
|
| + new views::LabelButton(this, base::ASCIIToUTF16("No thanks"));
|
| + cancel_button_->SetStyle(views::Button::STYLE_BUTTON);
|
| + layout->AddView(cancel_button_);
|
| + layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
|
| +
|
| + set_margins(gfx::Insets(1, 0, 1, 0));
|
| + Layout();
|
| +}
|
| +
|
| +} // namespace autofill
|
|
|