[Extensions] Make extension message bubble factory platform-abstract
[chromium-blink-merge.git] / chrome / browser / ui / views / passwords / manage_passwords_icon_view.cc
bloba0a54b1ea08c6ede46e2cea8cb6dc440af636258
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) {
17 SetFocusable(true);
18 UpdateVisibleUI();
21 ManagePasswordsIconView::~ManagePasswordsIconView() {}
23 void ManagePasswordsIconView::UpdateVisibleUI() {
24 if (state() == password_manager::ui::INACTIVE_STATE) {
25 SetVisible(false);
26 return;
29 SetVisible(true);
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.
36 parent()->Layout();
39 void ManagePasswordsIconView::OnChangingState() {
40 // If there is an opened bubble for the current icon it should go away.
41 if (active())
42 ManagePasswordsBubbleView::CloseBubble();
45 bool ManagePasswordsIconView::IsBubbleShowing() const {
46 // If the bubble is being destroyed, it's considered showing though it may be
47 // already invisible currently.
48 return ManagePasswordsBubbleView::manage_password_bubble() != NULL;
51 void ManagePasswordsIconView::OnExecuting(
52 BubbleIconView::ExecuteSource source) {
55 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent& event) {
56 bool result = BubbleIconView::OnMousePressed(event);
57 if (IsBubbleShowing())
58 ManagePasswordsBubbleView::CloseBubble();
59 return result;
62 bool ManagePasswordsIconView::OnKeyPressed(const ui::KeyEvent& event) {
63 // Space is always ignored because otherwise the bubble appears with the
64 // default button down. Releasing the space is equivalent to clicking this
65 // button.
66 if (event.key_code() == ui::VKEY_SPACE)
67 return true;
68 if (event.key_code() == ui::VKEY_RETURN && active()) {
69 // If the icon is active, it should transfer its focus to the bubble.
70 // If it still somehow got this key event, the bubble shouldn't be reopened.
71 return true;
73 return BubbleIconView::OnKeyPressed(event);
76 void ManagePasswordsIconView::AboutToRequestFocusFromTabTraversal(
77 bool reverse) {
78 if (active())
79 ManagePasswordsBubbleView::ActivateBubble();