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.
5 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/command_updater.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
10 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
11 #include "components/password_manager/core/common/password_manager_ui.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
15 ManagePasswordsIconView::ManagePasswordsIconView(CommandUpdater
* updater
)
16 : BubbleIconView(updater
, IDC_MANAGE_PASSWORDS_FOR_PAGE
) {
21 ManagePasswordsIconView::~ManagePasswordsIconView() {}
23 void ManagePasswordsIconView::UpdateVisibleUI() {
24 if (state() == password_manager::ui::INACTIVE_STATE
) {
30 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_
));
31 SetTooltipText(l10n_util::GetStringUTF16(tooltip_text_id_
));
33 // We may be about to automatically pop up a ManagePasswordsBubbleView.
34 // Force layout of the icon's parent now; the bubble will be incorrectly
35 // positioned otherwise, as the icon won't have been drawn into position.
39 void ManagePasswordsIconView::OnChangingState() {
40 // If there is an opened bubble for the current icon it should go away.
42 ManagePasswordsBubbleView::CloseBubble();
45 void ManagePasswordsIconView::OnExecuting(
46 BubbleIconView::ExecuteSource source
) {
49 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent
& event
) {
50 bool result
= BubbleIconView::OnMousePressed(event
);
51 if (IsBubbleShowing())
52 ManagePasswordsBubbleView::CloseBubble();
56 bool ManagePasswordsIconView::OnKeyPressed(const ui::KeyEvent
& event
) {
57 // Space is always ignored because otherwise the bubble appears with the
58 // default button down. Releasing the space is equivalent to clicking this
60 if (event
.key_code() == ui::VKEY_SPACE
)
62 if (event
.key_code() == ui::VKEY_RETURN
&& active()) {
63 // If the icon is active, it should transfer its focus to the bubble.
64 // If it still somehow got this key event, the bubble shouldn't be reopened.
67 return BubbleIconView::OnKeyPressed(event
);
70 void ManagePasswordsIconView::AboutToRequestFocusFromTabTraversal(
73 ManagePasswordsBubbleView::ActivateBubble();
76 views::BubbleDelegateView
* ManagePasswordsIconView::GetBubble() const {
77 return ManagePasswordsBubbleView::manage_password_bubble();