OLD | NEW |
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/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" | 7 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
| 8 #include "chrome/browser/ui/view_ids.h" |
8 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" | 9 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
9 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
10 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
11 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
13 | 14 |
14 ManagePasswordsIconView::ManagePasswordsIconView( | 15 ManagePasswordsIconView::ManagePasswordsIconView( |
15 LocationBarView::Delegate* location_bar_delegate) | 16 LocationBarView::Delegate* location_bar_delegate) |
16 : location_bar_delegate_(location_bar_delegate) { | 17 : location_bar_delegate_(location_bar_delegate) { |
| 18 set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON); |
17 SetAccessibilityFocusable(true); | 19 SetAccessibilityFocusable(true); |
18 Update(NULL); | 20 SetState(ManagePasswordsIcon::INACTIVE_STATE); |
19 } | 21 } |
20 | 22 |
21 ManagePasswordsIconView::~ManagePasswordsIconView() {} | 23 ManagePasswordsIconView::~ManagePasswordsIconView() {} |
22 | 24 |
23 void ManagePasswordsIconView::Update( | 25 void ManagePasswordsIconView::SetStateInternal( |
24 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller) { | 26 ManagePasswordsIcon::State state) { |
25 SetVisible(manage_passwords_bubble_ui_controller && | 27 if (state == ManagePasswordsIcon::INACTIVE_STATE) { |
26 manage_passwords_bubble_ui_controller-> | 28 SetVisible(false); |
27 manage_passwords_icon_to_be_shown() && | 29 if (ManagePasswordsBubbleView::IsShowing()) |
28 !location_bar_delegate_->GetToolbarModel()->input_in_progress()); | 30 ManagePasswordsBubbleView::CloseBubble(); |
29 if (!visible()) { | |
30 ManagePasswordsBubbleView::CloseBubble(); | |
31 return; | 31 return; |
32 } | 32 } |
33 int icon_to_display = | 33 |
34 manage_passwords_bubble_ui_controller->autofill_blocked() | 34 // Start with the correct values for ManagePasswordsIcon::MANAGE_STATE, and |
35 ? IDR_SAVE_PASSWORD_BLACKLISTED | 35 // adjust things accordingly if we're either in BLACKLISTED_STATE or |
36 : IDR_SAVE_PASSWORD; | 36 // PENDING_STATE. |
37 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 37 int which_icon = IDR_SAVE_PASSWORD; |
38 icon_to_display)); | 38 int which_text = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE; |
39 SetTooltip(manage_passwords_bubble_ui_controller->password_to_be_saved()); | 39 if (state == ManagePasswordsIcon::BLACKLISTED_STATE) |
| 40 which_icon = IDR_SAVE_PASSWORD_BLACKLISTED; |
| 41 else if (state == ManagePasswordsIcon::PENDING_STATE) |
| 42 which_text = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE; |
| 43 |
| 44 SetVisible(true); |
| 45 SetImage( |
| 46 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(which_icon)); |
| 47 SetTooltipText(l10n_util::GetStringUTF16(which_text)); |
40 } | 48 } |
41 | 49 |
42 void ManagePasswordsIconView::ShowBubbleIfNeeded( | 50 void ManagePasswordsIconView::ShowBubbleWithoutUserInteraction() { |
43 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller) { | 51 // Suppress the bubble if the user is working in the omnibox. |
44 if (manage_passwords_bubble_ui_controller-> | 52 if (location_bar_delegate_->GetToolbarModel()->input_in_progress()) |
45 manage_passwords_bubble_needs_showing() && | 53 return; |
46 visible() && | |
47 !ManagePasswordsBubbleView::IsShowing()) { | |
48 ManagePasswordsBubbleView::ShowBubble( | |
49 location_bar_delegate_->GetWebContents(), | |
50 ManagePasswordsBubbleView::AUTOMATIC); | |
51 manage_passwords_bubble_ui_controller->OnBubbleShown(); | |
52 } | |
53 } | |
54 | 54 |
55 void ManagePasswordsIconView::SetTooltip(bool password_to_be_saved) { | 55 ManagePasswordsBubbleView::ShowBubble( |
56 SetTooltipText(l10n_util::GetStringUTF16( | 56 location_bar_delegate_->GetWebContents(), |
57 (password_to_be_saved ? | 57 ManagePasswordsBubbleView::AUTOMATIC); |
58 IDS_PASSWORD_MANAGER_TOOLTIP_SAVE : | |
59 IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE))); | |
60 } | 58 } |
61 | 59 |
62 bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p, | 60 bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p, |
63 base::string16* tooltip) const { | 61 base::string16* tooltip) const { |
64 // Don't show tooltip if the password bubble is displayed. | 62 // Don't show tooltip if the password bubble is displayed. |
65 return !ManagePasswordsBubbleView::IsShowing() && | 63 return !ManagePasswordsBubbleView::IsShowing() && |
66 ImageView::GetTooltipText(p, tooltip); | 64 ImageView::GetTooltipText(p, tooltip); |
67 } | 65 } |
68 | 66 |
69 void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent* event) { | 67 void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent* event) { |
(...skipping 10 matching lines...) Expand all Loading... |
80 return true; | 78 return true; |
81 } | 79 } |
82 | 80 |
83 void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent& event) { | 81 void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent& event) { |
84 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) { | 82 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) { |
85 ManagePasswordsBubbleView::ShowBubble( | 83 ManagePasswordsBubbleView::ShowBubble( |
86 location_bar_delegate_->GetWebContents(), | 84 location_bar_delegate_->GetWebContents(), |
87 ManagePasswordsBubbleView::USER_ACTION); | 85 ManagePasswordsBubbleView::USER_ACTION); |
88 } | 86 } |
89 } | 87 } |
OLD | NEW |