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

Side by Side Diff: chrome/browser/ui/views/autofill/password_generation_popup_view_views.cc

Issue 147533005: [Password Generation] Update UI to match final mocks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@replace_password_generation_ui
Patch Set: Comments Created 6 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/autofill/password_generation_popup_view_views. h" 5 #include "chrome/browser/ui/views/autofill/password_generation_popup_view_views. h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" 8 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/views/background.h" 10 #include "ui/views/background.h"
11 #include "ui/views/border.h" 11 #include "ui/views/border.h"
12 #include "ui/views/controls/label.h" 12 #include "ui/views/controls/label.h"
13 #include "ui/views/controls/styled_label.h" 13 #include "ui/views/controls/styled_label.h"
14 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
15 15
16 namespace autofill { 16 namespace autofill {
17 17
18 namespace { 18 namespace {
19 19
20 const SkColor kExplanatoryTextBackground = SkColorSetRGB(0xF5, 0xF5, 0xF5); 20 const SkColor kExplanatoryTextBackground = SkColorSetRGB(0xF5, 0xF5, 0xF5);
21 const SkColor kExplanatoryTextColor = SkColorSetRGB(0x93, 0x93, 0x93); 21 const SkColor kExplanatoryTextColor = SkColorSetRGB(0x7F, 0x7F, 0x7F);
22 const SkColor kDividerColor = SkColorSetRGB(0xE7, 0xE7, 0xE7); 22 const SkColor kDividerColor = SkColorSetRGB(0xE9, 0xE9, 0xE9);
23 23
24 // This is the amount of vertical whitespace that is left above and below the 24 // This is the amount of vertical whitespace that is left above and below the
25 // password when it is highlighted. 25 // password when it is highlighted.
26 const int kPasswordVerticalInset = 7; 26 const int kPasswordVerticalInset = 7;
Evan Stade 2014/02/07 21:45:48 why is this here but the horizontal one is in the
Garrett Casto 2014/02/10 11:02:44 Not entirely sure what you mean by horizontal one
27 27
28 // The amount of whitespace that is present when there is no padding. Used 28 // The amount of whitespace that is present when there is no padding. Used
29 // to get the proper spacing in the help section. 29 // to get the proper spacing in the help section.
30 const int kHelpVerticalOffset = 3; 30 const int kHelpVerticalOffset = 3;
31 31
32 // Class that shows the password and the suggestion side-by-side.
33 class PasswordRow : public views::View {
34 public:
35 PasswordRow(const base::string16& password,
36 const base::string16& suggestion,
37 const gfx::FontList& font_list,
38 int horizontal_border) {
39 set_clip_insets(gfx::Insets(
40 kPasswordVerticalInset, 0, kPasswordVerticalInset, 0));
41 SetBorder(
42 views::Border::CreateEmptyBorder(
43 0, horizontal_border, 0, horizontal_border));
44
45 password_label_ = new views::Label(password, font_list);
46 password_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
47 AddChildView(password_label_);
48
49 suggestion_label_ = new views::Label(suggestion, font_list);
50 suggestion_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
51 suggestion_label_->SetEnabledColor(kExplanatoryTextColor);
52 AddChildView(suggestion_label_);
53 }
54 virtual ~PasswordRow() {}
55
56 virtual void Layout() OVERRIDE {
57 password_label_->SetBoundsRect(GetContentsBounds());
58 suggestion_label_->SetBoundsRect(GetContentsBounds());
59 }
60
61 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE {
62 // Have parent do event handling.
63 return false;
64 }
65
66 private:
67 // Child views. Not owned.
68 views::Label* suggestion_label_;
69 views::Label* password_label_;
70
71 DISALLOW_COPY_AND_ASSIGN(PasswordRow);
72 };
73
32 } // namespace 74 } // namespace
33 75
34 PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews( 76 PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews(
35 PasswordGenerationPopupController* controller, 77 PasswordGenerationPopupController* controller,
36 views::Widget* observing_widget) 78 views::Widget* observing_widget)
37 : AutofillPopupBaseView(controller, observing_widget), 79 : AutofillPopupBaseView(controller, observing_widget),
80 password_view_(NULL),
38 controller_(controller) { 81 controller_(controller) {
39 password_label_ = new views::Label(controller->password()); 82 if (controller_->display_password())
40 password_label_->SetBoundsRect(controller->password_bounds()); 83 CreatePasswordView();
41 password_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
42 password_label_->set_clip_insets(gfx::Insets(
43 kPasswordVerticalInset, 0, kPasswordVerticalInset, 0));
44 password_label_->SetBorder(views::Border::CreateEmptyBorder(
45 0, controller_->kHorizontalPadding, 0, controller_->kHorizontalPadding));
46 AddChildView(password_label_);
47 84
48 base::string16 help_text = controller->HelpText(); 85 base::string16 help_text = controller_->HelpText();
49 base::string16 learn_more_link_text = controller->LearnMoreLink(); 86 base::string16 saved_passwords_link_text = controller_->SavedPasswordsLink();
50 views::StyledLabel* help_label = 87 help_label_ =
51 new views::StyledLabel(help_text + learn_more_link_text, this); 88 new views::StyledLabel(help_text + saved_passwords_link_text, this);
89 help_label_->SetFontList(controller_->font_list());
52 views::StyledLabel::RangeStyleInfo default_style; 90 views::StyledLabel::RangeStyleInfo default_style;
53 default_style.color = kExplanatoryTextColor; 91 default_style.color = kExplanatoryTextColor;
54 help_label->SetDefaultStyle(default_style); 92 help_label_->SetDefaultStyle(default_style);
55 help_label->AddStyleRange( 93
94 views::StyledLabel::RangeStyleInfo link_style =
95 views::StyledLabel::RangeStyleInfo::CreateForLink();
96 help_label_->AddStyleRange(
56 gfx::Range(help_text.size(), 97 gfx::Range(help_text.size(),
57 help_text.size() + learn_more_link_text.size()), 98 help_text.size() + saved_passwords_link_text.size()),
58 views::StyledLabel::RangeStyleInfo::CreateForLink()); 99 views::StyledLabel::RangeStyleInfo::CreateForLink());
59 help_label->SetBoundsRect(controller->help_bounds()); 100 help_label_->SetBoundsRect(controller_->help_bounds());
60 help_label->set_background( 101 help_label_->set_background(
61 views::Background::CreateSolidBackground(kExplanatoryTextBackground)); 102 views::Background::CreateSolidBackground(kExplanatoryTextBackground));
62 help_label->SetBorder(views::Border::CreateEmptyBorder( 103 help_label_->SetBorder(views::Border::CreateEmptyBorder(
63 controller_->kHelpVerticalPadding - kHelpVerticalOffset, 104 controller_->kHelpVerticalPadding - kHelpVerticalOffset,
64 controller_->kHorizontalPadding, 105 controller_->kHorizontalPadding,
65 0, 106 0,
66 controller_->kHorizontalPadding)); 107 controller_->kHorizontalPadding));
67 AddChildView(help_label); 108 AddChildView(help_label_);
68 109
69 set_background(views::Background::CreateSolidBackground(kPopupBackground)); 110 set_background(views::Background::CreateSolidBackground(kPopupBackground));
70 } 111 }
71 112
72 PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {} 113 PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {}
73 114
115 void PasswordGenerationPopupViewViews::CreatePasswordView() {
116 if (password_view_)
117 return;
118
119 password_view_ =
120 new PasswordRow(controller_->password(),
121 controller_->SuggestedText(),
122 controller_->font_list(),
123 controller_->kHorizontalPadding);
124 AddChildView(password_view_);
125 }
126
74 void PasswordGenerationPopupViewViews::Show() { 127 void PasswordGenerationPopupViewViews::Show() {
75 DoShow(); 128 DoShow();
76 } 129 }
77 130
78 void PasswordGenerationPopupViewViews::Hide() { 131 void PasswordGenerationPopupViewViews::Hide() {
79 // The controller is no longer valid after it hides us. 132 // The controller is no longer valid after it hides us.
80 controller_ = NULL; 133 controller_ = NULL;
81 134
82 DoHide(); 135 DoHide();
83 } 136 }
84 137
85 void PasswordGenerationPopupViewViews::UpdateBoundsAndRedrawPopup() { 138 void PasswordGenerationPopupViewViews::UpdateBoundsAndRedrawPopup() {
139 // Currently the UI can change from not offering a password to offering
140 // a password (e.g. the user is editing a generated password and deletes it),
141 // but it can't change the other way around.
142 if (controller_->display_password())
143 CreatePasswordView();
144
86 DoUpdateBoundsAndRedrawPopup(); 145 DoUpdateBoundsAndRedrawPopup();
87 } 146 }
88 147
148 void PasswordGenerationPopupViewViews::PasswordSelectionUpdated() {
149 if (!password_view_)
150 return;
151
152 password_view_->set_background(
153 controller_->password_selected() ?
154 views::Background::CreateSolidBackground(kHoveredBackgroundColor) :
Evan Stade 2014/02/07 21:45:48 CreateSolidBackground(foo ? bar : baz);
Garrett Casto 2014/02/10 11:02:44 Done.
155 views::Background::CreateSolidBackground(kPopupBackground));
156 }
157
158 void PasswordGenerationPopupViewViews::Layout() {
159 if (password_view_)
160 password_view_->SetBoundsRect(controller_->password_bounds());
161
162 help_label_->SetBoundsRect(controller_->help_bounds());
163 }
164
89 void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) { 165 void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) {
90 if (!controller_) 166 if (!controller_)
91 return; 167 return;
92 168
93 if (controller_->password_selected()) {
94 password_label_->set_background(
95 views::Background::CreateSolidBackground(kHoveredBackgroundColor));
96 } else {
97 password_label_->set_background(
98 views::Background::CreateSolidBackground(kPopupBackground));
99 }
100
101 // Draw border and background. 169 // Draw border and background.
102 views::View::OnPaint(canvas); 170 views::View::OnPaint(canvas);
103 171
104 // Divider line needs to be drawn after OnPaint() otherwise the background 172 // Divider line needs to be drawn after OnPaint() otherwise the background
105 // will overwrite the divider. 173 // will overwrite the divider.
106 canvas->FillRect(controller_->divider_bounds(), kDividerColor); 174 if (password_view_)
175 canvas->FillRect(controller_->divider_bounds(), kDividerColor);
107 } 176 }
108 177
109 void PasswordGenerationPopupViewViews::StyledLabelLinkClicked( 178 void PasswordGenerationPopupViewViews::StyledLabelLinkClicked(
110 const gfx::Range& range, int event_flags) { 179 const gfx::Range& range, int event_flags) {
111 controller_->OnHelpLinkClicked(); 180 controller_->OnSavedPasswordsLinkClicked();
112 } 181 }
113 182
114 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( 183 PasswordGenerationPopupView* PasswordGenerationPopupView::Create(
115 PasswordGenerationPopupController* controller) { 184 PasswordGenerationPopupController* controller) {
116 views::Widget* observing_widget = 185 views::Widget* observing_widget =
117 views::Widget::GetTopLevelWidgetForNativeView( 186 views::Widget::GetTopLevelWidgetForNativeView(
118 controller->container_view()); 187 controller->container_view());
119 188
120 // If the top level widget can't be found, cancel the popup since we can't 189 // If the top level widget can't be found, cancel the popup since we can't
121 // fully set it up. 190 // fully set it up.
122 if (!observing_widget) 191 if (!observing_widget)
123 return NULL; 192 return NULL;
124 193
125 return new PasswordGenerationPopupViewViews(controller, observing_widget); 194 return new PasswordGenerationPopupViewViews(controller, observing_widget);
126 } 195 }
127 196
128 } // namespace autofill 197 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698