OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/passwords/manage_passwords_icon.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" |
6 | 6 |
7 #include "chrome/grit/generated_resources.h" | 7 #include "chrome/grit/generated_resources.h" |
8 #include "grit/theme_resources.h" | 8 #include "grit/theme_resources.h" |
9 | 9 |
10 ManagePasswordsIcon::ManagePasswordsIcon() | 10 ManagePasswordsIcon::ManagePasswordsIcon() |
11 : icon_id_(0), | 11 : icon_id_(0), |
12 tooltip_text_id_(0), | 12 tooltip_text_id_(0), |
13 state_(password_manager::ui::INACTIVE_STATE), | 13 state_(password_manager::ui::INACTIVE_STATE), |
14 active_(false) { | 14 active_(false) { |
15 } | 15 } |
16 | 16 |
17 ManagePasswordsIcon::~ManagePasswordsIcon() { | 17 ManagePasswordsIcon::~ManagePasswordsIcon() { |
18 } | 18 } |
19 | 19 |
20 void ManagePasswordsIcon::SetActive(bool active) { | 20 void ManagePasswordsIcon::SetActive(bool active) { |
21 if (active_ == active) | 21 if (active_ == active) |
22 return; | 22 return; |
23 active_ = active; | 23 active_ = active; |
24 UpdateIDs(); | 24 UpdateIDs(); |
25 UpdateVisibleUI(); | 25 UpdateVisibleUI(); |
26 } | 26 } |
27 | 27 |
28 void ManagePasswordsIcon::SetState(password_manager::ui::State state) { | 28 void ManagePasswordsIcon::SetState(password_manager::ui::State state) { |
29 if (state_ == state) | |
30 return; | |
31 state_ = state; | 29 state_ = state; |
32 UpdateIDs(); | 30 UpdateIDs(); |
33 UpdateVisibleUI(); | 31 UpdateVisibleUI(); |
34 } | 32 } |
35 | 33 |
36 void ManagePasswordsIcon::UpdateIDs() { | 34 void ManagePasswordsIcon::UpdateIDs() { |
37 // If the icon is inactive: clear out its image and tooltip and exit early. | 35 // If the icon is inactive: clear out its image and tooltip and exit early. |
38 if (state() == password_manager::ui::INACTIVE_STATE) { | 36 if (state() == password_manager::ui::INACTIVE_STATE) { |
39 icon_id_ = 0; | 37 icon_id_ = 0; |
40 tooltip_text_id_ = 0; | 38 tooltip_text_id_ = 0; |
41 return; | 39 return; |
42 } | 40 } |
43 | 41 |
44 // Otherwise, start with the correct values for MANAGE_STATE, and adjust | 42 // Otherwise, start with the correct values for MANAGE_STATE, and adjust |
45 // things accordingly if we're either in BLACKLIST_STATE or PENDING_STATE. | 43 // things accordingly if we're either in BLACKLIST_STATE or PENDING_STATE. |
46 // TODO(dconnelly): Figure out how to share the resources with Android. | 44 // TODO(dconnelly): Figure out how to share the resources with Android. |
47 #if !defined(OS_ANDROID) | 45 #if !defined(OS_ANDROID) |
48 icon_id_ = active() ? IDR_SAVE_PASSWORD_ACTIVE : IDR_SAVE_PASSWORD_INACTIVE; | 46 icon_id_ = active() ? IDR_SAVE_PASSWORD_ACTIVE : IDR_SAVE_PASSWORD_INACTIVE; |
49 tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE; | 47 tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE; |
50 if (state() == password_manager::ui::BLACKLIST_STATE) | 48 if (state() == password_manager::ui::BLACKLIST_STATE) |
51 icon_id_ = active() ? IDR_SAVE_PASSWORD_DISABLED_ACTIVE | 49 icon_id_ = active() ? IDR_SAVE_PASSWORD_DISABLED_ACTIVE |
52 : IDR_SAVE_PASSWORD_DISABLED_INACTIVE; | 50 : IDR_SAVE_PASSWORD_DISABLED_INACTIVE; |
53 else if (password_manager::ui::IsPendingState(state())) | 51 else if (password_manager::ui::IsPendingState(state())) |
54 tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE; | 52 tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE; |
55 #endif | 53 #endif |
56 } | 54 } |
OLD | NEW |