Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Unified Diff: chrome/browser/ui/views/autofill/save_card_bubble_views.cc

Issue 1396923003: Autofill: Replace "save credit card" infobar with a bubble (Views only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change object lifecycles + add interface classes. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/autofill/save_card_bubble_views.cc
diff --git a/chrome/browser/ui/views/autofill/save_card_bubble_views.cc b/chrome/browser/ui/views/autofill/save_card_bubble_views.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4777ed7e7e55a32ea24895821ed18acfa4687cdd
--- /dev/null
+++ b/chrome/browser/ui/views/autofill/save_card_bubble_views.cc
@@ -0,0 +1,127 @@
+// 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_views.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "components/autofill/core/browser/ui/save_card_bubble_controller.h"
+#include "grit/components_strings.h"
+#include "ui/base/l10n/l10n_util.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 {
+
+SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
+ content::WebContents* web_contents,
+ SaveCardBubbleController* controller)
+ : ManagedFullScreenBubbleDelegateView(anchor_view, web_contents),
+ controller_(controller),
+ save_button_(nullptr),
+ cancel_button_(nullptr) {
+ views::BubbleDelegateView::CreateBubble(this);
+}
+
+SaveCardBubbleViews::~SaveCardBubbleViews() {}
+
+void SaveCardBubbleViews::Show() {
+ GetWidget()->Show();
+}
+
+void SaveCardBubbleViews::Close() {
+ GetWidget()->Close();
+}
+
+void SaveCardBubbleViews::ControllerGone() {
+ controller_ = nullptr;
+ GetWidget()->Close();
+}
+
+views::View* SaveCardBubbleViews::GetInitiallyFocusedView() {
+ return save_button_;
+}
+
+base::string16 SaveCardBubbleViews::GetWindowTitle() const {
+ return l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_TITLE_LOCAL);
+}
+
+bool SaveCardBubbleViews::ShouldShowWindowTitle() const {
+ return true;
+}
+
+void SaveCardBubbleViews::WindowClosing() {
+ if (controller_)
+ controller_->OnBubbleClosed();
+}
+
+void SaveCardBubbleViews::ButtonPressed(views::Button* sender,
+ const ui::Event& event) {
+ if (sender == save_button_) {
+ controller_->OnSaveButton();
+ } else {
+ DCHECK(sender == cancel_button_);
hcarmona 2015/10/16 21:16:35 DCHECK_EQ
bondd 2015/10/22 02:15:17 Done.
+ controller_->OnCancelButton();
+ }
+ GetWidget()->Close();
+}
+
+void SaveCardBubbleViews::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.
+ save_button_ = new views::BlueButton(
+ this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_ACCEPT));
+ save_button_->SetIsDefault(true);
+ layout->StartRow(0, COLUMN_SET_ID_BUTTONS);
+ layout->AddView(save_button_);
+
+ // Create cancel button and add it to layout.
+ cancel_button_ = new views::LabelButton(
+ this, l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_BUBBLE_DENY));
+ 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

Powered by Google App Engine
This is Rietveld 408576698