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

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

Issue 342833002: [Password Generation] Update Aura UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 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 "grit/theme_resources.h"
10 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
10 #include "ui/views/background.h" 12 #include "ui/views/background.h"
11 #include "ui/views/border.h" 13 #include "ui/views/border.h"
14 #include "ui/views/controls/image_view.h"
12 #include "ui/views/controls/label.h" 15 #include "ui/views/controls/label.h"
13 #include "ui/views/controls/styled_label.h" 16 #include "ui/views/controls/styled_label.h"
14 #include "ui/views/layout/box_layout.h" 17 #include "ui/views/layout/box_layout.h"
15 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
16 19
17 namespace autofill { 20 namespace autofill {
18 21
19 namespace { 22 namespace {
20 23
21 // The amount of whitespace that is present when there is no padding. Used 24 // The amount of whitespace that is present when there is no padding. Used
22 // to get the proper spacing in the help section. 25 // to get the proper spacing in the help section.
23 const int kHelpVerticalOffset = 3; 26 const int kHelpVerticalOffset = 5;
27
28 class PasswordTextBox : public views::View {
Evan Stade 2014/06/19 00:16:35 class level comment
Garrett Casto 2014/06/20 23:47:01 Done.
29 public:
30 PasswordTextBox(const base::string16& suggestion_text,
31 const base::string16& password,
Evan Stade 2014/06/19 00:16:35 is this actually a password? that's what the var n
Garrett Casto 2014/06/20 23:47:01 Added docs.
32 const gfx::FontList& font_list) {
Evan Stade 2014/06/19 00:16:36 nit: technically, we're supposed to avoid doing co
Garrett Casto 2014/06/20 23:47:01 My understanding of this has been "Don't do things
Evan Stade 2014/06/23 18:20:40 it's also "don't call virtual methods" (or functio
Garrett Casto 2014/06/24 01:15:12 Yeah, I suppose keeping track of the viral nature
33 views::BoxLayout* box_layout = new views::BoxLayout(
34 views::BoxLayout::kVertical, 0, 13, 5);
35 box_layout->set_main_axis_alignment(
36 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
37 SetLayoutManager(box_layout);
38
39 views::Label* suggestion_label = new views::Label(
40 suggestion_text, font_list.DeriveWithStyle(gfx::Font::BOLD));
41 suggestion_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
42 AddChildView(suggestion_label);
43
44 views::Label* password_label = new views::Label(password, font_list);
45 password_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
46 AddChildView(password_label);
47 }
48
49 virtual ~PasswordTextBox() {}
50
51 // views::View:
52 virtual bool CanProcessEventsWithinSubtree() const OVERRIDE {
53 // Send events to the parent view for handling.
54 return false;
55 }
56
57 private:
58 DISALLOW_COPY_AND_ASSIGN(PasswordTextBox);
59 };
24 60
25 // Class that shows the password and the suggestion side-by-side. 61 // Class that shows the password and the suggestion side-by-side.
26 class PasswordRow : public views::View { 62 class PasswordBox : public views::View {
27 public: 63 public:
28 PasswordRow(const base::string16& password, 64 PasswordBox(const base::string16& password,
29 const base::string16& suggestion, 65 const base::string16& suggestion,
30 const gfx::FontList& font_list, 66 const gfx::FontList& font_list,
31 int horizontal_border) { 67 int horizontal_border) {
32 set_clip_insets(gfx::Insets(
33 PasswordGenerationPopupView::kPasswordVerticalInset, 0,
34 PasswordGenerationPopupView::kPasswordVerticalInset, 0));
35 views::BoxLayout* box_layout = new views::BoxLayout( 68 views::BoxLayout* box_layout = new views::BoxLayout(
36 views::BoxLayout::kHorizontal, horizontal_border, 0, 0); 69 views::BoxLayout::kHorizontal, horizontal_border, 0, 15);
37 box_layout->set_main_axis_alignment( 70 box_layout->set_main_axis_alignment(
38 views::BoxLayout::MAIN_AXIS_ALIGNMENT_FILL); 71 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
39 SetLayoutManager(box_layout); 72 SetLayoutManager(box_layout);
40 73
41 password_label_ = new views::Label(password, font_list); 74 views::ImageView* key_image = new views::ImageView();
42 password_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 75 key_image->SetImage(
43 AddChildView(password_label_); 76 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
77 IDR_GENERATE_PASSWORD_KEY).ToImageSkia());
78 AddChildView(key_image);
44 79
45 suggestion_label_ = new views::Label(suggestion, font_list); 80 PasswordTextBox* password_text_box =
46 suggestion_label_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 81 new PasswordTextBox(suggestion, password, font_list);
47 suggestion_label_->SetEnabledColor( 82 AddChildView(password_text_box);
48 PasswordGenerationPopupView::kExplanatoryTextColor);
49 AddChildView(suggestion_label_);
50 } 83 }
51 virtual ~PasswordRow() {} 84 virtual ~PasswordBox() {}
52 85
53 // views::View: 86 // views::View:
54 virtual bool CanProcessEventsWithinSubtree() const OVERRIDE { 87 virtual bool CanProcessEventsWithinSubtree() const OVERRIDE {
55 // Send events to the parent view for handling. 88 // Send events to the parent view for handling.
56 return false; 89 return false;
57 } 90 }
58 91
59 private: 92 private:
60 // Child views. Not owned. 93 DISALLOW_COPY_AND_ASSIGN(PasswordBox);
61 views::Label* suggestion_label_;
62 views::Label* password_label_;
63
64 DISALLOW_COPY_AND_ASSIGN(PasswordRow);
65 }; 94 };
66 95
67 } // namespace 96 } // namespace
68 97
69 PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews( 98 PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews(
70 PasswordGenerationPopupController* controller, 99 PasswordGenerationPopupController* controller,
71 views::Widget* observing_widget) 100 views::Widget* observing_widget)
72 : AutofillPopupBaseView(controller, observing_widget), 101 : AutofillPopupBaseView(controller, observing_widget),
73 password_view_(NULL), 102 password_view_(NULL),
74 controller_(controller) { 103 controller_(controller) {
75 if (controller_->display_password()) 104 if (controller_->display_password())
76 CreatePasswordView(); 105 CreatePasswordView();
77 106
78 help_label_ = new views::StyledLabel(controller_->HelpText(), this); 107 help_label_ = new views::StyledLabel(controller_->HelpText(), this);
79 help_label_->SetBaseFontList(controller_->font_list()); 108 help_label_->SetBaseFontList(controller_->font_list());
109 help_label_->SetInterlineSpacing(3);
80 views::StyledLabel::RangeStyleInfo default_style; 110 views::StyledLabel::RangeStyleInfo default_style;
81 default_style.color = kExplanatoryTextColor; 111 default_style.color = kExplanatoryTextColor;
82 help_label_->SetDefaultStyle(default_style); 112 help_label_->SetDefaultStyle(default_style);
83 113
84 views::StyledLabel::RangeStyleInfo link_style = 114 views::StyledLabel::RangeStyleInfo link_style =
85 views::StyledLabel::RangeStyleInfo::CreateForLink(); 115 views::StyledLabel::RangeStyleInfo::CreateForLink();
86 link_style.color = kLinkColor; 116 link_style.color = kLinkColor;
87 help_label_->AddStyleRange(controller_->HelpTextLinkRange(), link_style); 117 help_label_->AddStyleRange(controller_->HelpTextLinkRange(), link_style);
88 118
89 help_label_->SetBoundsRect(controller_->help_bounds()); 119 help_label_->SetBoundsRect(controller_->help_bounds());
90 help_label_->set_background( 120 help_label_->set_background(
91 views::Background::CreateSolidBackground( 121 views::Background::CreateSolidBackground(
92 kExplanatoryTextBackgroundColor)); 122 kExplanatoryTextBackgroundColor));
93 help_label_->SetBorder(views::Border::CreateEmptyBorder( 123 help_label_->SetBorder(views::Border::CreateEmptyBorder(
94 controller_->kHelpVerticalPadding - kHelpVerticalOffset, 124 controller_->kHelpVerticalPadding - kHelpVerticalOffset,
95 controller_->kHorizontalPadding, 125 controller_->kHorizontalPadding,
96 0, 126 0,
97 controller_->kHorizontalPadding)); 127 controller_->kHorizontalPadding));
98 AddChildView(help_label_); 128 AddChildView(help_label_);
99 129
100 set_background(views::Background::CreateSolidBackground(kPopupBackground)); 130 const SkColor kPasswordBackground = SkColorSetARGB(0xFF, 0xFB, 0xFB, 0xFB);
Evan Stade 2014/06/19 00:16:35 nit: SkColorSetRGB(0xFB, 0xFB, 0xFB); Not sure if
Garrett Casto 2014/06/20 23:47:01 Done.
Evan Stade 2014/06/23 18:20:40 with a desktop linux (not cros) build, 1. chrome:
Garrett Casto 2014/06/24 01:15:11 Yeah, so that doesn't work for the generated passw
Evan Stade 2014/06/24 21:16:58 Yea, that's better than illegible, but not as good
131 set_background(views::Background::CreateSolidBackground(kPasswordBackground));
101 } 132 }
102 133
103 PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {} 134 PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {}
104 135
105 void PasswordGenerationPopupViewViews::CreatePasswordView() { 136 void PasswordGenerationPopupViewViews::CreatePasswordView() {
106 if (password_view_) 137 if (password_view_)
107 return; 138 return;
108 139
109 password_view_ = new PasswordRow(controller_->password(), 140 password_view_ = new PasswordBox(controller_->password(),
110 controller_->SuggestedText(), 141 controller_->SuggestedText(),
111 controller_->font_list(), 142 controller_->font_list(),
112 controller_->kHorizontalPadding); 143 controller_->kHorizontalPadding);
113 AddChildView(password_view_); 144 AddChildView(password_view_);
114 } 145 }
115 146
116 void PasswordGenerationPopupViewViews::Show() { 147 void PasswordGenerationPopupViewViews::Show() {
117 DoShow(); 148 DoShow();
118 } 149 }
119 150
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 209
179 // If the top level widget can't be found, cancel the popup since we can't 210 // If the top level widget can't be found, cancel the popup since we can't
180 // fully set it up. 211 // fully set it up.
181 if (!observing_widget) 212 if (!observing_widget)
182 return NULL; 213 return NULL;
183 214
184 return new PasswordGenerationPopupViewViews(controller, observing_widget); 215 return new PasswordGenerationPopupViewViews(controller, observing_widget);
185 } 216 }
186 217
187 } // namespace autofill 218 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698