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

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

Powered by Google App Engine
This is Rietveld 408576698