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

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: Unittests 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 help_label_ = new views::StyledLabel(controller_->HelpText(), this);
49 base::string16 learn_more_link_text = controller->LearnMoreLink(); 80 help_label_->SetBaseFontList(controller_->font_list());
50 views::StyledLabel* help_label =
51 new views::StyledLabel(help_text + learn_more_link_text, this);
52 views::StyledLabel::RangeStyleInfo default_style; 81 views::StyledLabel::RangeStyleInfo default_style;
53 default_style.color = kExplanatoryTextColor; 82 default_style.color = kExplanatoryTextColor;
54 help_label->SetDefaultStyle(default_style); 83 help_label_->SetDefaultStyle(default_style);
55 help_label->AddStyleRange( 84 help_label_->AddStyleRange(
56 gfx::Range(help_text.size(), 85 controller_->HelpTextLinkRange(),
57 help_text.size() + learn_more_link_text.size()),
58 views::StyledLabel::RangeStyleInfo::CreateForLink()); 86 views::StyledLabel::RangeStyleInfo::CreateForLink());
59 help_label->SetBoundsRect(controller->help_bounds()); 87
60 help_label->set_background( 88 help_label_->SetBoundsRect(controller_->help_bounds());
89 help_label_->set_background(
61 views::Background::CreateSolidBackground(kExplanatoryTextBackground)); 90 views::Background::CreateSolidBackground(kExplanatoryTextBackground));
62 help_label->SetBorder(views::Border::CreateEmptyBorder( 91 help_label_->SetBorder(views::Border::CreateEmptyBorder(
63 controller_->kHelpVerticalPadding - kHelpVerticalOffset, 92 controller_->kHelpVerticalPadding - kHelpVerticalOffset,
64 controller_->kHorizontalPadding, 93 controller_->kHorizontalPadding,
65 0, 94 0,
66 controller_->kHorizontalPadding)); 95 controller_->kHorizontalPadding));
67 AddChildView(help_label); 96 AddChildView(help_label_);
68 97
69 set_background(views::Background::CreateSolidBackground(kPopupBackground)); 98 set_background(views::Background::CreateSolidBackground(kPopupBackground));
70 } 99 }
71 100
72 PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {} 101 PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {}
73 102
103 void PasswordGenerationPopupViewViews::CreatePasswordView() {
104 if (password_view_)
105 return;
106
107 password_view_ = new PasswordRow(controller_->password(),
108 controller_->SuggestedText(),
109 controller_->font_list(),
110 controller_->kHorizontalPadding);
111 AddChildView(password_view_);
112 }
113
74 void PasswordGenerationPopupViewViews::Show() { 114 void PasswordGenerationPopupViewViews::Show() {
75 DoShow(); 115 DoShow();
76 } 116 }
77 117
78 void PasswordGenerationPopupViewViews::Hide() { 118 void PasswordGenerationPopupViewViews::Hide() {
79 // The controller is no longer valid after it hides us. 119 // The controller is no longer valid after it hides us.
80 controller_ = NULL; 120 controller_ = NULL;
81 121
82 DoHide(); 122 DoHide();
83 } 123 }
84 124
85 void PasswordGenerationPopupViewViews::UpdateBoundsAndRedrawPopup() { 125 void PasswordGenerationPopupViewViews::UpdateBoundsAndRedrawPopup() {
126 // Currently the UI can change from not offering a password to offering
127 // a password (e.g. the user is editing a generated password and deletes it),
128 // but it can't change the other way around.
129 if (controller_->display_password())
130 CreatePasswordView();
131
86 DoUpdateBoundsAndRedrawPopup(); 132 DoUpdateBoundsAndRedrawPopup();
87 } 133 }
88 134
135 void PasswordGenerationPopupViewViews::PasswordSelectionUpdated() {
136 if (!password_view_)
137 return;
138
139 password_view_->set_background(
140 views::Background::CreateSolidBackground(
141 controller_->password_selected() ?
142 kHoveredBackgroundColor :
143 kPopupBackground));
144 }
145
146 void PasswordGenerationPopupViewViews::Layout() {
147 if (password_view_)
148 password_view_->SetBoundsRect(controller_->password_bounds());
149
150 help_label_->SetBoundsRect(controller_->help_bounds());
151 }
152
89 void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) { 153 void PasswordGenerationPopupViewViews::OnPaint(gfx::Canvas* canvas) {
90 if (!controller_) 154 if (!controller_)
91 return; 155 return;
92 156
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. 157 // Draw border and background.
102 views::View::OnPaint(canvas); 158 views::View::OnPaint(canvas);
103 159
104 // Divider line needs to be drawn after OnPaint() otherwise the background 160 // Divider line needs to be drawn after OnPaint() otherwise the background
105 // will overwrite the divider. 161 // will overwrite the divider.
106 canvas->FillRect(controller_->divider_bounds(), kDividerColor); 162 if (password_view_)
163 canvas->FillRect(controller_->divider_bounds(), kDividerColor);
107 } 164 }
108 165
109 void PasswordGenerationPopupViewViews::StyledLabelLinkClicked( 166 void PasswordGenerationPopupViewViews::StyledLabelLinkClicked(
110 const gfx::Range& range, int event_flags) { 167 const gfx::Range& range, int event_flags) {
111 controller_->OnHelpLinkClicked(); 168 controller_->OnSavedPasswordsLinkClicked();
112 } 169 }
113 170
114 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( 171 PasswordGenerationPopupView* PasswordGenerationPopupView::Create(
115 PasswordGenerationPopupController* controller) { 172 PasswordGenerationPopupController* controller) {
116 views::Widget* observing_widget = 173 views::Widget* observing_widget =
117 views::Widget::GetTopLevelWidgetForNativeView( 174 views::Widget::GetTopLevelWidgetForNativeView(
118 controller->container_view()); 175 controller->container_view());
119 176
120 // If the top level widget can't be found, cancel the popup since we can't 177 // If the top level widget can't be found, cancel the popup since we can't
121 // fully set it up. 178 // fully set it up.
122 if (!observing_widget) 179 if (!observing_widget)
123 return NULL; 180 return NULL;
124 181
125 return new PasswordGenerationPopupViewViews(controller, observing_widget); 182 return new PasswordGenerationPopupViewViews(controller, observing_widget);
126 } 183 }
127 184
128 } // namespace autofill 185 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698