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/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/command_updater.h" |
7 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" | 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
8 #include "chrome/browser/ui/view_ids.h" | 10 #include "chrome/browser/ui/view_ids.h" |
9 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" | 11 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
10 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
11 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
12 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
14 | 16 |
15 ManagePasswordsIconView::ManagePasswordsIconView( | 17 ManagePasswordsIconView::ManagePasswordsIconView( |
16 LocationBarView::Delegate* location_bar_delegate) | 18 LocationBarView::Delegate* location_bar_delegate, |
17 : location_bar_delegate_(location_bar_delegate) { | 19 CommandUpdater* command_updater) |
| 20 : BubbleIconView(command_updater, IDC_MANAGE_PASSWORDS_FOR_PAGE), |
| 21 location_bar_delegate_(location_bar_delegate), |
| 22 command_updater_(command_updater), |
| 23 icon_id_(0), |
| 24 tooltip_text_id_(0) { |
18 set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON); | 25 set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON); |
19 SetAccessibilityFocusable(true); | 26 SetAccessibilityFocusable(true); |
20 SetState(ManagePasswordsIcon::INACTIVE_STATE); | 27 UpdateVisibleUI(); |
21 } | 28 } |
22 | 29 |
23 ManagePasswordsIconView::~ManagePasswordsIconView() {} | 30 ManagePasswordsIconView::~ManagePasswordsIconView() {} |
24 | 31 |
25 void ManagePasswordsIconView::SetStateInternal( | 32 void ManagePasswordsIconView::UpdateVisibleUI() { |
26 ManagePasswordsIcon::State state) { | 33 // If the icon is inactive: clear out it's image and tooltip, hide the icon, |
27 if (state == ManagePasswordsIcon::INACTIVE_STATE) { | 34 // close any active bubble, and exit early. |
| 35 if (state() == ManagePasswordsIcon::INACTIVE_STATE) { |
| 36 icon_id_ = 0; |
| 37 tooltip_text_id_ = 0; |
| 38 |
28 SetVisible(false); | 39 SetVisible(false); |
29 if (ManagePasswordsBubbleView::IsShowing()) | 40 if (ManagePasswordsBubbleView::IsShowing()) |
30 ManagePasswordsBubbleView::CloseBubble(); | 41 ManagePasswordsBubbleView::CloseBubble(); |
31 return; | 42 return; |
32 } | 43 } |
33 | 44 |
34 // Start with the correct values for ManagePasswordsIcon::MANAGE_STATE, and | 45 // Otherwise, start with the correct values for MANAGE_STATE, and adjust |
35 // adjust things accordingly if we're either in BLACKLISTED_STATE or | 46 // things accordingly if we're either in BLACKLISTED_STATE or PENDING_STATE. |
36 // PENDING_STATE. | 47 icon_id_ = IDR_SAVE_PASSWORD; |
37 int which_icon = IDR_SAVE_PASSWORD; | 48 tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE; |
38 int which_text = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE; | 49 if (state() == ManagePasswordsIcon::BLACKLISTED_STATE) |
39 if (state == ManagePasswordsIcon::BLACKLISTED_STATE) | 50 icon_id_ = IDR_SAVE_PASSWORD_BLACKLISTED; |
40 which_icon = IDR_SAVE_PASSWORD_BLACKLISTED; | 51 else if (state() == ManagePasswordsIcon::PENDING_STATE) |
41 else if (state == ManagePasswordsIcon::PENDING_STATE) | 52 tooltip_text_id_ = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE; |
42 which_text = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE; | |
43 | 53 |
44 SetVisible(true); | 54 SetVisible(true); |
45 SetImage( | 55 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); |
46 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(which_icon)); | 56 SetTooltipText(l10n_util::GetStringUTF16(tooltip_text_id_)); |
47 SetTooltipText(l10n_util::GetStringUTF16(which_text)); | |
48 } | 57 } |
49 | 58 |
50 void ManagePasswordsIconView::ShowBubbleWithoutUserInteraction() { | 59 void ManagePasswordsIconView::ShowBubbleWithoutUserInteraction() { |
51 // Suppress the bubble if the user is working in the omnibox. | 60 // Suppress the bubble if the user is working in the omnibox. |
52 if (location_bar_delegate_->GetToolbarModel()->input_in_progress()) | 61 if (location_bar_delegate_->GetToolbarModel()->input_in_progress()) |
53 return; | 62 return; |
54 | 63 |
55 ManagePasswordsBubbleView::ShowBubble( | 64 command_updater_->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE); |
56 location_bar_delegate_->GetWebContents(), | |
57 ManagePasswordsBubbleView::AUTOMATIC); | |
58 } | 65 } |
59 | 66 |
60 bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p, | 67 bool ManagePasswordsIconView::IsBubbleShowing() const { |
61 base::string16* tooltip) const { | 68 return ManagePasswordsBubbleView::IsShowing(); |
62 // Don't show tooltip if the password bubble is displayed. | |
63 return !ManagePasswordsBubbleView::IsShowing() && | |
64 ImageView::GetTooltipText(p, tooltip); | |
65 } | 69 } |
66 | 70 |
67 void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent* event) { | 71 void ManagePasswordsIconView::OnExecuting( |
68 if (event->type() == ui::ET_GESTURE_TAP) { | 72 BubbleIconView::ExecuteSource source) { |
69 ManagePasswordsBubbleView::ShowBubble( | |
70 location_bar_delegate_->GetWebContents(), | |
71 ManagePasswordsBubbleView::USER_ACTION); | |
72 event->SetHandled(); | |
73 } | |
74 } | 73 } |
75 | |
76 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent& event) { | |
77 // Do nothing until the mouse button is released. | |
78 return true; | |
79 } | |
80 | |
81 void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent& event) { | |
82 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) { | |
83 ManagePasswordsBubbleView::ShowBubble( | |
84 location_bar_delegate_->GetWebContents(), | |
85 ManagePasswordsBubbleView::USER_ACTION); | |
86 } | |
87 } | |
OLD | NEW |