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