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