manage_passwords_bubble_view.h revision f2477e01787aa58f445919b809d89e252beef54f
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_PASSWORDS_BUBBLE_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
7
8#include "base/basictypes.h"
9#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
10#include "ui/views/bubble/bubble_delegate.h"
11#include "ui/views/controls/button/button.h"
12#include "ui/views/controls/link.h"
13#include "ui/views/controls/link_listener.h"
14
15class ManagePasswordsIconView;
16
17namespace content {
18class WebContents;
19}
20
21namespace views {
22class BlueButton;
23class LabelButton;
24}
25
26class ManagePasswordsBubbleView : public views::BubbleDelegateView,
27                                  public views::ButtonListener,
28                                  public views::LinkListener {
29 public:
30  // Shows the bubble.
31  static void ShowBubble(content::WebContents* web_contents,
32                         ManagePasswordsIconView* icon_view);
33
34  // Closes any existing bubble.
35  static void CloseBubble();
36
37  // Whether the bubble is currently showing.
38  static bool IsShowing();
39
40 private:
41  ManagePasswordsBubbleView(views::View* anchor_view,
42                            content::WebContents* web_contents,
43                            ManagePasswordsIconView* icon_view);
44  virtual ~ManagePasswordsBubbleView();
45
46  // Returns the maximum width needed for the username or password field(s).
47  // Both can take a maximum of 22 characters. If username is set it will return
48  // the maximum width for the username, else the one for the password fields.
49  int GetMaximumUsernameOrPasswordWidth(bool username);
50
51  // If the bubble is not anchored to a view, places the bubble in the top
52  // right (left in RTL) of the |screen_bounds| that contain |web_contents_|'s
53  // browser window. Because the positioning is based on the size of the
54  // bubble, this must be called after the bubble is created.
55  void AdjustForFullscreen(const gfx::Rect& screen_bounds);
56
57  void Close();
58
59  // views::BubbleDelegateView:
60  virtual void Init() OVERRIDE;
61  virtual void WindowClosing() OVERRIDE;
62
63  // views::ButtonListener:
64  virtual void ButtonPressed(views::Button* sender,
65                             const ui::Event& event) OVERRIDE;
66
67  // views::LinkListener:
68  virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
69
70  // Singleton instance of the Password bubble. The Password bubble can only be
71  // shown on the active browser window, so there is no case in which it will be
72  // shown twice at the same time.
73  static ManagePasswordsBubbleView* manage_passwords_bubble_;
74
75  ManagePasswordsBubbleModel* manage_passwords_bubble_model_;
76  ManagePasswordsIconView* icon_view_;
77
78  // The buttons that are shown in the bubble.
79  views::BlueButton* save_button_;
80  views::LabelButton* cancel_button_;
81  views::Link* manage_link_;
82  views::LabelButton* done_button_;
83
84  DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleView);
85};
86
87#endif  // CHROME_BROWSER_UI_VIEWS_PASSWORDS_MANAGE_PASSWORDS_BUBBLE_VIEW_H_
88