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

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

Issue 250353003: Password bubble: refactor ManagePasswordsIconView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 7 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/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 // Suppress the bubble if the user is working in the omnibox.
markusheintz_ 2014/04/25 13:25:10 What does working mean? Is the bubble displayed a
Mike West 2014/04/25 13:31:42 I believe this method returns true if the user has
45 if (manage_passwords_bubble_ui_controller-> 53 if (location_bar_delegate_->GetToolbarModel()->input_in_progress())
46 manage_passwords_bubble_needs_showing() && 54 return;
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 55
56 void ManagePasswordsIconView::SetTooltip(bool password_to_be_saved) { 56 ManagePasswordsBubbleView::ShowBubble(
57 SetTooltipText(l10n_util::GetStringUTF16( 57 location_bar_delegate_->GetWebContents(),
58 (password_to_be_saved ? 58 ManagePasswordsBubbleView::AUTOMATIC);
59 IDS_PASSWORD_MANAGER_TOOLTIP_SAVE :
60 IDS_PASSWORD_MANAGER_TOOLTIP_MANAGE)));
61 } 59 }
62 60
63 bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p, 61 bool ManagePasswordsIconView::GetTooltipText(const gfx::Point& p,
64 base::string16* tooltip) const { 62 base::string16* tooltip) const {
65 // Don't show tooltip if the password bubble is displayed. 63 // Don't show tooltip if the password bubble is displayed.
66 return !ManagePasswordsBubbleView::IsShowing() && 64 return !ManagePasswordsBubbleView::IsShowing() &&
67 ImageView::GetTooltipText(p, tooltip); 65 ImageView::GetTooltipText(p, tooltip);
68 } 66 }
69 67
70 void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent* event) { 68 void ManagePasswordsIconView::OnGestureEvent(ui::GestureEvent* event) {
(...skipping 10 matching lines...) Expand all
81 return true; 79 return true;
82 } 80 }
83 81
84 void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent& event) { 82 void ManagePasswordsIconView::OnMouseReleased(const ui::MouseEvent& event) {
85 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) { 83 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
86 ManagePasswordsBubbleView::ShowBubble( 84 ManagePasswordsBubbleView::ShowBubble(
87 location_bar_delegate_->GetWebContents(), 85 location_bar_delegate_->GetWebContents(),
88 ManagePasswordsBubbleView::USER_ACTION); 86 ManagePasswordsBubbleView::USER_ACTION);
89 } 87 }
90 } 88 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/passwords/manage_passwords_icon_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698