Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1100)

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_icon_view.cc

Issue 419263002: Add ManagePasswordsDecoration and unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: exclude resource IDs on Android Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
6 6
7 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/command_updater.h" 8 #include "chrome/browser/command_updater.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 9 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
10 #include "chrome/browser/ui/view_ids.h" 10 #include "chrome/browser/ui/view_ids.h"
11 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" 11 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
12 #include "components/password_manager/core/common/password_manager_ui.h" 12 #include "components/password_manager/core/common/password_manager_ui.h"
13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
17 15
18 ManagePasswordsIconView::ManagePasswordsIconView(CommandUpdater* updater) 16 ManagePasswordsIconView::ManagePasswordsIconView(CommandUpdater* updater)
19 : BubbleIconView(updater, IDC_MANAGE_PASSWORDS_FOR_PAGE), 17 : BubbleIconView(updater, IDC_MANAGE_PASSWORDS_FOR_PAGE) {
20 icon_id_(0),
21 tooltip_text_id_(0) {
22 set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON); 18 set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON);
23 SetAccessibilityFocusable(true); 19 SetAccessibilityFocusable(true);
24 UpdateVisibleUI(); 20 UpdateVisibleUI();
25 } 21 }
26 22
27 ManagePasswordsIconView::~ManagePasswordsIconView() {} 23 ManagePasswordsIconView::~ManagePasswordsIconView() {}
28 24
29 void ManagePasswordsIconView::UpdateVisibleUI() { 25 void ManagePasswordsIconView::UpdateVisibleUI() {
30 // If the icon is inactive: clear out it's image and tooltip, hide the icon,
31 // close any active bubble, and exit early.
32 if (state() == password_manager::ui::INACTIVE_STATE) { 26 if (state() == password_manager::ui::INACTIVE_STATE) {
33 icon_id_ = 0;
34 tooltip_text_id_ = 0;
35
36 SetVisible(false); 27 SetVisible(false);
37 if (ManagePasswordsBubbleView::IsShowing()) 28 if (ManagePasswordsBubbleView::IsShowing())
38 ManagePasswordsBubbleView::CloseBubble(); 29 ManagePasswordsBubbleView::CloseBubble();
39 return; 30 return;
40 } 31 }
41 32
42 // Otherwise, start with the correct values for MANAGE_STATE, and adjust
43 // things accordingly if we're either in BLACKLIST_STATE or PENDING_STATE.
44 icon_id_ = active() ? IDR_SAVE_PASSWORD_ACTIVE : IDR_SAVE_PASSWORD_INACTIVE;
45 tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE;
46 if (state() == password_manager::ui::BLACKLIST_STATE)
47 icon_id_ = active() ? IDR_SAVE_PASSWORD_DISABLED_ACTIVE
48 : IDR_SAVE_PASSWORD_DISABLED_INACTIVE;
49 else if (password_manager::ui::IsPendingState(state()))
50 tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE;
51
52 SetVisible(true); 33 SetVisible(true);
53 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); 34 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_));
54 SetTooltipText(l10n_util::GetStringUTF16(tooltip_text_id_)); 35 SetTooltipText(l10n_util::GetStringUTF16(tooltip_text_id_));
55 36
56 // We may be about to automatically pop up a ManagePasswordsBubbleView. 37 // We may be about to automatically pop up a ManagePasswordsBubbleView.
57 // Force layout of the icon's parent now; the bubble will be incorrectly 38 // Force layout of the icon's parent now; the bubble will be incorrectly
58 // positioned otherwise, as the icon won't have been drawn into position. 39 // positioned otherwise, as the icon won't have been drawn into position.
59 parent()->Layout(); 40 parent()->Layout();
60 } 41 }
61 42
62 bool ManagePasswordsIconView::IsBubbleShowing() const { 43 bool ManagePasswordsIconView::IsBubbleShowing() const {
63 // If the bubble is being destroyed, it's considered showing though it may be 44 // If the bubble is being destroyed, it's considered showing though it may be
64 // already invisible currently. 45 // already invisible currently.
65 return ManagePasswordsBubbleView::manage_password_bubble() != NULL; 46 return ManagePasswordsBubbleView::manage_password_bubble() != NULL;
66 } 47 }
67 48
68 void ManagePasswordsIconView::OnExecuting( 49 void ManagePasswordsIconView::OnExecuting(
69 BubbleIconView::ExecuteSource source) { 50 BubbleIconView::ExecuteSource source) {
70 } 51 }
71 52
72 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent& event) { 53 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent& event) {
73 bool result = BubbleIconView::OnMousePressed(event); 54 bool result = BubbleIconView::OnMousePressed(event);
74 if (IsBubbleShowing()) 55 if (IsBubbleShowing())
75 ManagePasswordsBubbleView::CloseBubble(); 56 ManagePasswordsBubbleView::CloseBubble();
76 return result; 57 return result;
77 } 58 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/passwords/manage_passwords_icon_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698