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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" 6 7 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" 8 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" 9 #include "grit/generated_resources.h" 10 #include "grit/theme_resources.h" 11 #include "ui/base/accessibility/accessible_view_state.h" 12 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/resource/resource_bundle.h" 14 15 ManagePasswordsIconView::ManagePasswordsIconView( 16 LocationBarView::Delegate* location_bar_delegate) 17 : location_bar_delegate_(location_bar_delegate) { 18 SetAccessibilityFocusable(true); 19 Update(NULL); 20 LocationBarView::InitTouchableLocationBarChildView(this); 21 } 22 23 ManagePasswordsIconView::~ManagePasswordsIconView() {} 24 25 void ManagePasswordsIconView::Update( 26 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller) { 27 SetVisible(manage_passwords_bubble_ui_controller && 28 manage_passwords_bubble_ui_controller-> 29 manage_passwords_icon_to_be_shown() && 30 !location_bar_delegate_->GetToolbarModel()->input_in_progress()); 31 if (!visible()) { 32 ManagePasswordsBubbleView::CloseBubble(); 33 return; 34 } 35 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 36 IDR_SAVE_PASSWORD)); 37 SetTooltip(manage_passwords_bubble_ui_controller->password_to_be_saved()); 38 } 39 40 void ManagePasswordsIconView::ShowBubbleIfNeeded( 41 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller) { 42 if (manage_passwords_bubble_ui_controller-> 43 manage_passwords_bubble_needs_showing() && 44 visible() && 45 !ManagePasswordsBubbleView::IsShowing()) { 46 ManagePasswordsBubbleView::ShowBubble( 47 location_bar_delegate_->GetWebContents(), this); 48 manage_passwords_bubble_ui_controller->OnBubbleShown(); 49 } 50 } 51 52 void ManagePasswordsIconView::SetTooltip(bool password_to_be_saved) { 53 SetTooltipText(l10n_util::GetStringUTF16( 54 (password_to_be_saved ? 55 IDS_PASSWORD_MANAGER_TOOLTIP_SAVE : 56 IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE))); 57 } 58 59 bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p, 60 base::string16* tooltip) const { 61 // Don't show tooltip if the password bubble is displayed. 62 return !ManagePasswordsBubbleView::IsShowing() && 63 ImageView::GetTooltipText(p, tooltip); 64 } 65 66 void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent* event) { 67 if (event->type() == ui::ET_GESTURE_TAP) { 68 ManagePasswordsBubbleView::ShowBubble( 69 location_bar_delegate_->GetWebContents(), this); 70 event->SetHandled(); 71 } 72 } 73 74 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent& event) { 75 // Do nothing until the mouse button is released. 76 return true; 77 } 78 79 void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent& event) { 80 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) 81 ManagePasswordsBubbleView::ShowBubble( 82 location_bar_delegate_->GetWebContents(), this); 83 } 84