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.
5 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
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"
15 ManagePasswordsIconView::ManagePasswordsIconView(
16 LocationBarView::Delegate
* location_bar_delegate
)
17 : location_bar_delegate_(location_bar_delegate
) {
18 SetAccessibilityFocusable(true);
20 LocationBarView::InitTouchableLocationBarChildView(this);
23 ManagePasswordsIconView::~ManagePasswordsIconView() {}
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());
32 ManagePasswordsBubbleView::CloseBubble();
35 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
37 SetTooltip(manage_passwords_bubble_ui_controller
->password_to_be_saved());
40 void ManagePasswordsIconView::ShowBubbleIfNeeded(
41 ManagePasswordsBubbleUIController
* manage_passwords_bubble_ui_controller
) {
42 if (manage_passwords_bubble_ui_controller
->
43 manage_passwords_bubble_needs_showing() &&
45 !ManagePasswordsBubbleView::IsShowing()) {
46 ManagePasswordsBubbleView::ShowBubble(
47 location_bar_delegate_
->GetWebContents(), this);
48 manage_passwords_bubble_ui_controller
->OnBubbleShown();
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
)));
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
);
66 void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent
* event
) {
67 if (event
->type() == ui::ET_GESTURE_TAP
) {
68 ManagePasswordsBubbleView::ShowBubble(
69 location_bar_delegate_
->GetWebContents(), this);
74 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent
& event
) {
75 // Do nothing until the mouse button is released.
79 void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent
& event
) {
80 if (event
.IsOnlyLeftMouseButton() && HitTestPoint(event
.location()))
81 ManagePasswordsBubbleView::ShowBubble(
82 location_bar_delegate_
->GetWebContents(), this);