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/view_ids.h"
11 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
12 #include "components/password_manager/core/common/password_manager_ui.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
16 ManagePasswordsIconView::ManagePasswordsIconView(CommandUpdater* updater)
17 : BubbleIconView(updater, IDC_MANAGE_PASSWORDS_FOR_PAGE) {
18 set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON);
23 ManagePasswordsIconView::~ManagePasswordsIconView() {}
25 void ManagePasswordsIconView::UpdateVisibleUI() {
26 if (state() == password_manager::ui::INACTIVE_STATE) {
28 if (ManagePasswordsBubbleView::IsShowing())
29 ManagePasswordsBubbleView::CloseBubble();
34 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_));
35 SetTooltipText(l10n_util::GetStringUTF16(tooltip_text_id_));
37 // We may be about to automatically pop up a ManagePasswordsBubbleView.
38 // Force layout of the icon's parent now; the bubble will be incorrectly
39 // positioned otherwise, as the icon won't have been drawn into position.
43 bool ManagePasswordsIconView::IsBubbleShowing() const {
44 // If the bubble is being destroyed, it's considered showing though it may be
45 // already invisible currently.
46 return ManagePasswordsBubbleView::manage_password_bubble() != NULL;
49 void ManagePasswordsIconView::OnExecuting(
50 BubbleIconView::ExecuteSource source) {
53 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent& event) {
54 bool result = BubbleIconView::OnMousePressed(event);
55 if (IsBubbleShowing())
56 ManagePasswordsBubbleView::CloseBubble();
60 bool ManagePasswordsIconView::OnKeyPressed(const ui::KeyEvent& event) {
61 // Space is always ignored because otherwise the bubble appears with the
62 // default button down. Releasing the space is equivalent to clicking this
64 if (event.key_code() == ui::VKEY_SPACE)
66 if (event.key_code() == ui::VKEY_RETURN && active()) {
67 // If the icon is active, it should transfer its focus to the bubble.
68 // If it still somehow got this key event, the bubble shouldn't be reopened.
71 return BubbleIconView::OnKeyPressed(event);
74 void ManagePasswordsIconView::AboutToRequestFocusFromTabTraversal(
77 ManagePasswordsBubbleView::ActivateBubble();