Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_icon_view.cc

Issue 246393004: Password bubble: Introduce a command to open the bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: The bigger picture. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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) {
18 set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON); 23 set_id(VIEW_ID_MANAGE_PASSWORDS_ICON_BUTTON);
19 SetAccessibilityFocusable(true); 24 SetAccessibilityFocusable(true);
20 LocationBarView::InitTouchableLocationBarChildView(this); 25 LocationBarView::InitTouchableLocationBarChildView(this);
21 SetState(ManagePasswordsIcon::INACTIVE_STATE); 26 // We call the internal method here as the default state is "inactive"; this
27 // call would otherwise be deduped away.
Peter Kasting 2014/04/25 22:12:02 This is confusing. Your change must be built atop
Mike West 2014/04/28 10:52:56 This CL is based on https://codereview.chromium.or
28 SetStateInternal(ManagePasswordsIcon::INACTIVE_STATE);
22 } 29 }
23 30
24 ManagePasswordsIconView::~ManagePasswordsIconView() {} 31 ManagePasswordsIconView::~ManagePasswordsIconView() {}
25 32
26 void ManagePasswordsIconView::SetStateInternal( 33 void ManagePasswordsIconView::SetStateInternal(
27 ManagePasswordsIcon::State state) { 34 ManagePasswordsIcon::State state) {
28 if (state == ManagePasswordsIcon::INACTIVE_STATE) { 35 if (state == ManagePasswordsIcon::INACTIVE_STATE) {
29 SetVisible(false); 36 SetVisible(false);
37 command_updater_->UpdateCommandEnabled(
38 IDC_MANAGE_PASSWORDS_FOR_PAGE, false);
Peter Kasting 2014/04/25 22:12:02 Is it actually necessary to disable the command ev
Mike West 2014/04/28 10:52:56 Makes sense. There's no real need to disable the c
30 if (ManagePasswordsBubbleView::IsShowing()) 39 if (ManagePasswordsBubbleView::IsShowing())
31 ManagePasswordsBubbleView::CloseBubble(); 40 ManagePasswordsBubbleView::CloseBubble();
32 return; 41 return;
33 } 42 }
34 43
35 // Start with the correct values for ManagePasswordsIcon::MANAGE_STATE, and 44 // Start with the correct values for ManagePasswordsIcon::MANAGE_STATE, and
36 // adjust things accordingly if we're either in BLACKLISTED_STATE or 45 // adjust things accordingly if we're either in BLACKLISTED_STATE or
37 // PENDING_STATE. 46 // PENDING_STATE.
38 int which_icon = IDR_SAVE_PASSWORD; 47 int which_icon = IDR_SAVE_PASSWORD;
39 int which_text = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE; 48 int which_text = IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE;
40 if (state == ManagePasswordsIcon::BLACKLISTED_STATE) 49 if (state == ManagePasswordsIcon::BLACKLISTED_STATE)
41 which_icon = IDR_SAVE_PASSWORD_BLACKLISTED; 50 which_icon = IDR_SAVE_PASSWORD_BLACKLISTED;
42 else if (state == ManagePasswordsIcon::PENDING_STATE) 51 else if (state == ManagePasswordsIcon::PENDING_STATE)
43 which_text = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE; 52 which_text = IDS_PASSWORD_MANAGER_TOOLTIP_SAVE;
44 53
45 SetVisible(true); 54 SetVisible(true);
46 SetImage( 55 SetImage(
47 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(which_icon)); 56 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(which_icon));
48 SetTooltipText(l10n_util::GetStringUTF16(which_text)); 57 SetTooltipText(l10n_util::GetStringUTF16(which_text));
58 command_updater_->UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
49 } 59 }
50 60
51 void ManagePasswordsIconView::ShowBubbleWithoutUserInteraction() { 61 void ManagePasswordsIconView::ShowBubbleWithoutUserInteraction() {
52 // Suppress the bubble if the user is working in the omnibox. 62 // Suppress the bubble if the user is working in the omnibox.
53 if (location_bar_delegate_->GetToolbarModel()->input_in_progress()) 63 if (location_bar_delegate_->GetToolbarModel()->input_in_progress())
54 return; 64 return;
55 65
56 ManagePasswordsBubbleView::ShowBubble( 66 command_updater_->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE);
57 location_bar_delegate_->GetWebContents(),
58 ManagePasswordsBubbleView::AUTOMATIC);
59 } 67 }
60 68
61 bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p, 69 bool ManagePasswordsIconView::IsBubbleShowing() const {
62 base::string16* tooltip) const { 70 return ManagePasswordsBubbleView::IsShowing();
63 // Don't show tooltip if the password bubble is displayed.
64 return !ManagePasswordsBubbleView::IsShowing() &&
65 ImageView::GetTooltipText(p, tooltip);
66 } 71 }
67 72
68 void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent* event) { 73 void ManagePasswordsIconView::OnExecuting(
69 if (event->type() == ui::ET_GESTURE_TAP) { 74 BubbleIconView::ExecuteSource source) {
70 ManagePasswordsBubbleView::ShowBubble(
71 location_bar_delegate_->GetWebContents(),
72 ManagePasswordsBubbleView::USER_ACTION);
73 event->SetHandled();
74 }
75 } 75 }
76
77 bool ManagePasswordsIconView::OnMousePressed(const ui::MouseEvent& event) {
78 // Do nothing until the mouse button is released.
79 return true;
80 }
81
82 void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent& event) {
83 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
84 ManagePasswordsBubbleView::ShowBubble(
85 location_bar_delegate_->GetWebContents(),
86 ManagePasswordsBubbleView::USER_ACTION);
87 }
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698