manage_password_item_view.h revision 0529e5d033099cbfc42635f6f6183833b09dff6e
1// Copyright 2013 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#ifndef CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEM_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEM_VIEW_H_
7
8#include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
9#include "components/autofill/core/common/password_form.h"
10
11class ManagePasswordsBubbleModel;
12
13namespace views {
14class GridLayout;
15class ImageButton;
16}
17
18// A custom view for credentials which allows the management of the specific
19// credentials. The view has three distinct states:
20//
21// * Present credentials to the user which she may choose to save.
22// * Present already-saved credentials to the user for management.
23// * Offer the user the ability to undo a deletion action.
24//
25// The ManagePasswordItemView serves as a container for a single view
26// representing one of these states.
27class ManagePasswordItemView : public views::View {
28 public:
29  // Render credentials in two columns: username and password.
30  class PendingView : public views::View {
31   public:
32    explicit PendingView(ManagePasswordItemView* parent);
33
34   private:
35    virtual ~PendingView();
36  };
37
38  // Render credentials in three columns: username, password, and delete.
39  class ManageView : public views::View, public views::ButtonListener {
40   public:
41    explicit ManageView(ManagePasswordItemView* parent);
42
43   private:
44    virtual ~ManageView();
45
46    // views::ButtonListener:
47    virtual void ButtonPressed(views::Button* sender,
48                               const ui::Event& event) OVERRIDE;
49
50    views::ImageButton* delete_button_;
51
52    ManagePasswordItemView* parent_;
53  };
54
55  // Render a notification to the user that a password has been removed, and
56  // offer an undo link.
57  class UndoView : public views::View, public views::LinkListener {
58   public:
59    explicit UndoView(ManagePasswordItemView* parent);
60
61   private:
62    virtual ~UndoView();
63
64    // views::LinkListener:
65    virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
66
67    views::Link* undo_link_;
68
69    ManagePasswordItemView* parent_;
70  };
71
72  enum Position { FIRST_ITEM, SUBSEQUENT_ITEM };
73
74  ManagePasswordItemView(
75      ManagePasswordsBubbleModel* manage_passwords_bubble_model,
76      autofill::PasswordForm password_form,
77      int field_1_width,
78      int field_2_width,
79      Position position);
80
81 private:
82  enum ColumnSets { TWO_COLUMN_SET = 0, THREE_COLUMN_SET };
83
84  virtual ~ManagePasswordItemView();
85
86  views::Label* GenerateUsernameLabel() const;
87  views::Label* GeneratePasswordLabel() const;
88
89  // Build a two-label column set using the widths stored in |field_1_width_|
90  // and |field_2_width_|.
91  void BuildColumnSet(views::GridLayout*, int column_set_id);
92
93  void NotifyClickedDelete();
94  void NotifyClickedUndo();
95
96  // Changes the views according to the state of |delete_password_|.
97  void Refresh();
98
99  ManagePasswordsBubbleModel* manage_passwords_bubble_model_;
100  autofill::PasswordForm password_form_;
101  bool delete_password_;
102  int field_1_width_;
103  int field_2_width_;
104
105  DISALLOW_COPY_AND_ASSIGN(ManagePasswordItemView);
106};
107
108#endif  // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORD_ITEM_VIEW_H_
109