Commit bf8d3186 authored by vasilii's avatar vasilii Committed by Commit bot

Clean up ManagePasswordsBubbleView and ManagePasswordItemView.

Removed unnecessary includes, reorder the methods, moved private classes to .cc.

Review URL: https://codereview.chromium.org/534543002

Cr-Commit-Position: refs/heads/master@{#292942}
parent bed54b15
......@@ -6,12 +6,15 @@
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/grit/generated_resources.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
......@@ -89,7 +92,15 @@ views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) {
} // namespace
// Pending View
// Render credentials in two columns: username and password.
class ManagePasswordItemView::PendingView : public views::View {
public:
explicit PendingView(ManagePasswordItemView* parent);
private:
virtual ~PendingView();
};
ManagePasswordItemView::PendingView::PendingView(
ManagePasswordItemView* parent) {
views::GridLayout* layout = new views::GridLayout(this);
......@@ -106,7 +117,23 @@ ManagePasswordItemView::PendingView::PendingView(
ManagePasswordItemView::PendingView::~PendingView() {
}
// Manage View
// Render credentials in three columns: username, password, and delete.
class ManagePasswordItemView::ManageView : public views::View,
public views::ButtonListener {
public:
explicit ManageView(ManagePasswordItemView* parent);
private:
virtual ~ManageView();
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
views::ImageButton* delete_button_;
ManagePasswordItemView* parent_;
};
ManagePasswordItemView::ManageView::ManageView(ManagePasswordItemView* parent)
: parent_(parent) {
views::GridLayout* layout = new views::GridLayout(this);
......@@ -130,16 +157,32 @@ ManagePasswordItemView::ManageView::ManageView(ManagePasswordItemView* parent)
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
}
ManagePasswordItemView::ManageView::~ManageView() {
}
void ManagePasswordItemView::ManageView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK_EQ(delete_button_, sender);
parent_->NotifyClickedDelete();
}
ManagePasswordItemView::ManageView::~ManageView() {
}
// Render a notification to the user that a password has been removed, and
// offer an undo link.
class ManagePasswordItemView::UndoView : public views::View,
public views::LinkListener {
public:
explicit UndoView(ManagePasswordItemView* parent);
private:
virtual ~UndoView();
// views::LinkListener:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
views::Link* undo_link_;
ManagePasswordItemView* parent_;
};
// Undo View
ManagePasswordItemView::UndoView::UndoView(ManagePasswordItemView* parent)
: parent_(parent) {
views::GridLayout* layout = new views::GridLayout(this);
......@@ -167,15 +210,15 @@ ManagePasswordItemView::UndoView::UndoView(ManagePasswordItemView* parent)
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
}
ManagePasswordItemView::UndoView::~UndoView() {
}
void ManagePasswordItemView::UndoView::LinkClicked(views::Link* sender,
int event_flags) {
DCHECK_EQ(undo_link_, sender);
parent_->NotifyClickedUndo();
}
ManagePasswordItemView::UndoView::~UndoView() {
}
// ManagePasswordItemView
ManagePasswordItemView::ManagePasswordItemView(
ManagePasswordsBubbleModel* manage_passwords_bubble_model,
......@@ -209,6 +252,16 @@ ManagePasswordItemView::ManagePasswordItemView(
ManagePasswordItemView::~ManagePasswordItemView() {
}
void ManagePasswordItemView::NotifyClickedDelete() {
delete_password_ = true;
Refresh();
}
void ManagePasswordItemView::NotifyClickedUndo() {
delete_password_ = false;
Refresh();
}
void ManagePasswordItemView::Refresh() {
DCHECK(!password_manager::ui::IsPendingState(model_->state()));
......@@ -226,13 +279,3 @@ void ManagePasswordItemView::Refresh() {
? ManagePasswordsBubbleModel::REMOVE_PASSWORD
: ManagePasswordsBubbleModel::ADD_PASSWORD);
}
void ManagePasswordItemView::NotifyClickedDelete() {
delete_password_ = true;
Refresh();
}
void ManagePasswordItemView::NotifyClickedUndo() {
delete_password_ = false;
Refresh();
}
......@@ -5,17 +5,12 @@
#ifndef CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEM_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEM_VIEW_H_
#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "ui/views/view.h"
class ManagePasswordsBubbleModel;
namespace views {
class GridLayout;
class ImageButton;
}
// A custom view for credentials which allows the management of the specific
// credentials. The view has three distinct states:
//
......@@ -27,53 +22,16 @@ class ImageButton;
// representing one of these states.
class ManagePasswordItemView : public views::View {
public:
// Render credentials in two columns: username and password.
class PendingView : public views::View {
public:
explicit PendingView(ManagePasswordItemView* parent);
private:
virtual ~PendingView();
};
// Render credentials in three columns: username, password, and delete.
class ManageView : public views::View, public views::ButtonListener {
public:
explicit ManageView(ManagePasswordItemView* parent);
private:
virtual ~ManageView();
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
views::ImageButton* delete_button_;
ManagePasswordItemView* parent_;
};
// Render a notification to the user that a password has been removed, and
// offer an undo link.
class UndoView : public views::View, public views::LinkListener {
public:
explicit UndoView(ManagePasswordItemView* parent);
private:
virtual ~UndoView();
// views::LinkListener:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
views::Link* undo_link_;
ManagePasswordItemView* parent_;
};
ManagePasswordItemView(
ManagePasswordsBubbleModel* manage_passwords_bubble_model,
autofill::PasswordForm password_form,
password_manager::ui::PasswordItemPosition position);
private:
class ManageView;
class PendingView;
class UndoView;
virtual ~ManagePasswordItemView();
void NotifyClickedDelete();
......
......@@ -4,31 +4,30 @@
#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
#include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
#include "chrome/grit/generated_resources.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/combobox_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/text_utils.h"
#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/controls/styled_label_listener.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
......@@ -165,6 +164,36 @@ void ShowManagePasswordsBubble(content::WebContents* web_contents) {
// ManagePasswordsBubbleView::PendingView -------------------------------------
// A view offering the user the ability to save credentials. Contains a
// single ManagePasswordItemView, along with a "Save Passwords" button
// and a rejection combobox.
class ManagePasswordsBubbleView::PendingView : public views::View,
public views::ButtonListener,
public views::ComboboxListener {
public:
explicit PendingView(ManagePasswordsBubbleView* parent);
virtual ~PendingView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
// Handles the event when the user changes an index of a combobox.
virtual void OnPerformAction(views::Combobox* source) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::BlueButton* save_button_;
// The combobox doesn't take ownership of its model. If we created a
// combobox we need to ensure that we delete the model here, and because the
// combobox uses the model in it's destructor, we need to make sure we
// delete the model _after_ the combobox itself is deleted.
scoped_ptr<SavePasswordRefusalComboboxModel> combobox_model_;
scoped_ptr<views::Combobox> refuse_combobox_;
};
ManagePasswordsBubbleView::PendingView::PendingView(
ManagePasswordsBubbleView* parent)
: parent_(parent) {
......@@ -236,6 +265,26 @@ void ManagePasswordsBubbleView::PendingView::OnPerformAction(
// ManagePasswordsBubbleView::ConfirmNeverView ---------------------------------
// A view offering the user the ability to undo her decision to never save
// passwords for a particular site.
class ManagePasswordsBubbleView::ConfirmNeverView
: public views::View,
public views::ButtonListener {
public:
explicit ConfirmNeverView(ManagePasswordsBubbleView* parent);
virtual ~ConfirmNeverView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::LabelButton* confirm_button_;
views::LabelButton* undo_button_;
};
ManagePasswordsBubbleView::ConfirmNeverView::ConfirmNeverView(
ManagePasswordsBubbleView* parent)
: parent_(parent) {
......@@ -310,6 +359,30 @@ void ManagePasswordsBubbleView::ConfirmNeverView::ButtonPressed(
// ManagePasswordsBubbleView::ManageView --------------------------------------
// A view offering the user a list of her currently saved credentials
// for the current page, along with a "Manage passwords" link and a
// "Done" button.
class ManagePasswordsBubbleView::ManageView : public views::View,
public views::ButtonListener,
public views::LinkListener {
public:
explicit ManageView(ManagePasswordsBubbleView* parent);
virtual ~ManageView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
// views::LinkListener:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::Link* manage_link_;
views::LabelButton* done_button_;
};
ManagePasswordsBubbleView::ManageView::ManageView(
ManagePasswordsBubbleView* parent)
: parent_(parent) {
......@@ -399,6 +472,26 @@ void ManagePasswordsBubbleView::ManageView::LinkClicked(views::Link* source,
// ManagePasswordsBubbleView::BlacklistedView ---------------------------------
// A view offering the user the ability to re-enable the password manager for
// a specific site after she's decided to "never save passwords".
class ManagePasswordsBubbleView::BlacklistedView
: public views::View,
public views::ButtonListener {
public:
explicit BlacklistedView(ManagePasswordsBubbleView* parent);
virtual ~BlacklistedView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::BlueButton* unblacklist_button_;
views::LabelButton* done_button_;
};
ManagePasswordsBubbleView::BlacklistedView::BlacklistedView(
ManagePasswordsBubbleView* parent)
: parent_(parent) {
......@@ -461,6 +554,30 @@ void ManagePasswordsBubbleView::BlacklistedView::ButtonPressed(
// ManagePasswordsBubbleView::SaveConfirmationView ----------------------------
// A view confirming to the user that a password was saved and offering a link
// to the Google account manager.
class ManagePasswordsBubbleView::SaveConfirmationView
: public views::View,
public views::ButtonListener,
public views::StyledLabelListener {
public:
explicit SaveConfirmationView(ManagePasswordsBubbleView* parent);
virtual ~SaveConfirmationView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
// views::StyledLabelListener implementation
virtual void StyledLabelLinkClicked(const gfx::Range& range,
int event_flags) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::LabelButton* ok_button_;
};
ManagePasswordsBubbleView::SaveConfirmationView::SaveConfirmationView(
ManagePasswordsBubbleView* parent)
: parent_(parent) {
......@@ -678,35 +795,6 @@ void ManagePasswordsBubbleView::Close() {
GetWidget()->Close();
}
void ManagePasswordsBubbleView::Init() {
views::FillLayout* layout = new views::FillLayout();
SetLayoutManager(layout);
Refresh();
}
void ManagePasswordsBubbleView::WindowClosing() {
// Close() closes the window asynchronously, so by the time we reach here,
// |manage_passwords_bubble_| may have already been reset.
if (manage_passwords_bubble_ == this)
manage_passwords_bubble_ = NULL;
}
void ManagePasswordsBubbleView::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
if (active && widget == GetWidget())
CancelFadingOut();
BubbleDelegateView::OnWidgetActivationChanged(widget, active);
}
views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() {
return initially_focused_view_;
}
void ManagePasswordsBubbleView::OnMouseEntered(const ui::MouseEvent& event) {
CancelFadingOut();
}
void ManagePasswordsBubbleView::Refresh() {
RemoveAllChildViews(true);
initially_focused_view_ = NULL;
......@@ -746,6 +834,35 @@ void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() {
Refresh();
}
void ManagePasswordsBubbleView::Init() {
views::FillLayout* layout = new views::FillLayout();
SetLayoutManager(layout);
Refresh();
}
void ManagePasswordsBubbleView::WindowClosing() {
// Close() closes the window asynchronously, so by the time we reach here,
// |manage_passwords_bubble_| may have already been reset.
if (manage_passwords_bubble_ == this)
manage_passwords_bubble_ = NULL;
}
void ManagePasswordsBubbleView::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
if (active && widget == GetWidget())
CancelFadingOut();
BubbleDelegateView::OnWidgetActivationChanged(widget, active);
}
views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() {
return initially_focused_view_;
}
void ManagePasswordsBubbleView::OnMouseEntered(const ui::MouseEvent& event) {
CancelFadingOut();
}
void ManagePasswordsBubbleView::StartFadingOut() {
if (fadeout_observer_)
return;
......
......@@ -5,16 +5,8 @@
#ifndef CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
#include "base/basictypes.h"
#include "chrome/browser/ui/passwords/manage_passwords_bubble.h"
#include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/link_listener.h"
#include "ui/views/controls/styled_label_listener.h"
class ManagePasswordsIconView;
......@@ -22,12 +14,6 @@ namespace content {
class WebContents;
}
namespace views {
class BlueButton;
class LabelButton;
class GridLayout;
}
// The ManagePasswordsBubbleView controls the contents of the bubble which
// pops up when Chrome offers to save a user's password, or when the user
// interacts with the Omnibox icon. It has two distinct states:
......@@ -39,124 +25,11 @@ class GridLayout;
class ManagePasswordsBubbleView : public ManagePasswordsBubble,
public views::BubbleDelegateView {
public:
// A view offering the user the ability to save credentials. Contains a
// single ManagePasswordItemView, along with a "Save Passwords" button
// and a rejection combobox.
class PendingView : public views::View,
public views::ButtonListener,
public views::ComboboxListener {
public:
explicit PendingView(ManagePasswordsBubbleView* parent);
virtual ~PendingView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
// Handles the event when the user changes an index of a combobox.
virtual void OnPerformAction(views::Combobox* source) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::BlueButton* save_button_;
// The combobox doesn't take ownership of its model. If we created a
// combobox we need to ensure that we delete the model here, and because the
// combobox uses the model in it's destructor, we need to make sure we
// delete the model _after_ the combobox itself is deleted.
scoped_ptr<SavePasswordRefusalComboboxModel> combobox_model_;
scoped_ptr<views::Combobox> refuse_combobox_;
};
// A view offering the user the ability to undo her decision to never save
// passwords for a particular site.
class ConfirmNeverView : public views::View, public views::ButtonListener {
public:
explicit ConfirmNeverView(ManagePasswordsBubbleView* parent);
virtual ~ConfirmNeverView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::LabelButton* confirm_button_;
views::LabelButton* undo_button_;
};
// A view offering the user a list of her currently saved credentials
// for the current page, along with a "Manage passwords" link and a
// "Done" button.
class ManageView : public views::View,
public views::ButtonListener,
public views::LinkListener {
public:
explicit ManageView(ManagePasswordsBubbleView* parent);
virtual ~ManageView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
// views::LinkListener:
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::Link* manage_link_;
views::LabelButton* done_button_;
};
// A view offering the user the ability to re-enable the password manager for
// a specific site after she's decided to "never save passwords".
class BlacklistedView : public views::View, public views::ButtonListener {
public:
explicit BlacklistedView(ManagePasswordsBubbleView* parent);
virtual ~BlacklistedView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::BlueButton* unblacklist_button_;
views::LabelButton* done_button_;
};
// A view confirming to the user that a password was saved and offering a link
// to the Google account manager.
class SaveConfirmationView : public views::View,
public views::ButtonListener,
public views::StyledLabelListener {
public:
explicit SaveConfirmationView(ManagePasswordsBubbleView* parent);
virtual ~SaveConfirmationView();
private:
// views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
// views::StyledLabelListener implementation
virtual void StyledLabelLinkClicked(const gfx::Range& range,
int event_flags) OVERRIDE;
ManagePasswordsBubbleView* parent_;
views::LabelButton* ok_button_;
};
// Shows the bubble.
static void ShowBubble(content::WebContents* web_contents,
DisplayReason reason);
// Closes any existing bubble.
// Closes the existing bubble.
static void CloseBubble();
// Makes the bubble the foreground window.
......@@ -179,6 +52,12 @@ class ManagePasswordsBubbleView : public ManagePasswordsBubble,
}
private:
class BlacklistedView;
class ConfirmNeverView;
class ManageView;
class PendingView;
class SaveConfirmationView;
ManagePasswordsBubbleView(content::WebContents* web_contents,
ManagePasswordsIconView* anchor_view,
DisplayReason reason);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment