OLD | NEW |
---|---|
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/passwords/credentials_item_view.h" | 5 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 9 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
10 #include "chrome/browser/ui/views/autofill/tooltip_icon.h" | |
10 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
11 #include "chrome/grit/theme_resources.h" | 12 #include "chrome/grit/theme_resources.h" |
12 #include "components/autofill/core/common/password_form.h" | 13 #include "components/autofill/core/common/password_form.h" |
13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/color_palette.h" | |
16 #include "ui/gfx/image/image.h" | |
17 #include "ui/gfx/paint_vector_icon.h" | |
18 #include "ui/gfx/path.h" | 16 #include "ui/gfx/path.h" |
19 #include "ui/gfx/vector_icons_public.h" | |
20 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
21 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
22 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
23 #include "ui/views/layout/layout_constants.h" | 20 #include "ui/views/layout/layout_constants.h" |
24 | 21 |
25 namespace { | 22 namespace { |
26 // The default spacing between the icon and text. | 23 // The default spacing between the icon and text. |
27 const int kSpacing = 12; | 24 const int kSpacing = 12; |
28 | 25 |
29 gfx::Size GetTextLabelsSize(const views::Label* upper_label, | 26 gfx::Size GetTextLabelsSize(const views::Label* upper_label, |
(...skipping 23 matching lines...) Expand all Loading... | |
53 gfx::Path circular_mask; | 50 gfx::Path circular_mask; |
54 circular_mask.addCircle( | 51 circular_mask.addCircle( |
55 SkIntToScalar(bounds.x() + bounds.right()) / 2, | 52 SkIntToScalar(bounds.x() + bounds.right()) / 2, |
56 SkIntToScalar(bounds.y() + bounds.bottom()) / 2, | 53 SkIntToScalar(bounds.y() + bounds.bottom()) / 2, |
57 SkIntToScalar(std::min(bounds.height(), bounds.width())) / 2); | 54 SkIntToScalar(std::min(bounds.height(), bounds.width())) / 2); |
58 canvas->ClipPath(circular_mask, true); | 55 canvas->ClipPath(circular_mask, true); |
59 ImageView::OnPaint(canvas); | 56 ImageView::OnPaint(canvas); |
60 } | 57 } |
61 | 58 |
62 // An ImageView that consumes the mouse events. | 59 // An ImageView that consumes the mouse events. |
63 class InfoImageView : public views::ImageView { | 60 class InfoImageView : public autofill::TooltipIcon { |
64 public: | 61 public: |
62 using TooltipIcon::TooltipIcon; | |
65 // View: | 63 // View: |
66 bool OnMousePressed(const ui::MouseEvent& event) override { return true; } | 64 bool OnMousePressed(const ui::MouseEvent& event) override { return true; } |
67 bool OnMouseDragged(const ui::MouseEvent& event) override { return true; } | 65 bool OnMouseDragged(const ui::MouseEvent& event) override { return true; } |
68 }; | 66 }; |
Evan Stade
2017/02/10 15:43:38
disallow copy and assign
vasilii
2017/02/15 16:29:21
Done.
| |
69 | 67 |
70 } // namespace | 68 } // namespace |
71 | 69 |
72 CredentialsItemView::CredentialsItemView( | 70 CredentialsItemView::CredentialsItemView( |
73 views::ButtonListener* button_listener, | 71 views::ButtonListener* button_listener, |
74 const base::string16& upper_text, | 72 const base::string16& upper_text, |
75 const base::string16& lower_text, | 73 const base::string16& lower_text, |
76 SkColor hover_color, | 74 SkColor hover_color, |
77 const autofill::PasswordForm* form, | 75 const autofill::PasswordForm* form, |
78 net::URLRequestContextGetter* request_context) | 76 net::URLRequestContextGetter* request_context) |
79 : LabelButton(button_listener, base::string16()), | 77 : LabelButton(button_listener, base::string16()), |
Evan Stade
2017/02/10 15:43:38
why is this even a label button? It seems like you
vasilii
2017/02/15 16:29:21
Done.
| |
80 form_(form), | 78 form_(form), |
81 upper_label_(nullptr), | 79 upper_label_(nullptr), |
82 lower_label_(nullptr), | 80 lower_label_(nullptr), |
83 info_icon_(nullptr), | 81 info_icon_(nullptr), |
84 hover_color_(hover_color), | 82 hover_color_(hover_color), |
85 weak_ptr_factory_(this) { | 83 weak_ptr_factory_(this) { |
86 set_notify_enter_exit_on_child(true); | 84 set_notify_enter_exit_on_child(true); |
87 // Create an image-view for the avatar. Make sure it ignores events so that | 85 // Create an image-view for the avatar. Make sure it ignores events so that |
88 // the parent can receive the events instead. | 86 // the parent can receive the events instead. |
89 image_view_ = new CircularImageView; | 87 image_view_ = new CircularImageView; |
(...skipping 21 matching lines...) Expand all Loading... | |
111 | 109 |
112 if (!lower_text.empty()) { | 110 if (!lower_text.empty()) { |
113 lower_label_ = new views::Label( | 111 lower_label_ = new views::Label( |
114 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); | 112 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); |
115 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 113 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
116 lower_label_->SetMultiLine(true); | 114 lower_label_->SetMultiLine(true); |
117 AddChildView(lower_label_); | 115 AddChildView(lower_label_); |
118 } | 116 } |
119 | 117 |
120 if (form_->is_public_suffix_match) { | 118 if (form_->is_public_suffix_match) { |
121 info_icon_ = new InfoImageView; | 119 info_icon_ = |
122 info_icon_->SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::INFO_OUTLINE, | 120 new InfoImageView(base::UTF8ToUTF16(form_->origin.GetOrigin().spec())); |
123 kInfoIconSize, | |
124 gfx::kChromeIconGrey)); | |
125 info_icon_->SetTooltipText( | |
126 base::UTF8ToUTF16(form_->origin.GetOrigin().spec())); | |
127 AddChildView(info_icon_); | 121 AddChildView(info_icon_); |
128 } | 122 } |
129 | 123 |
130 if (!upper_text.empty() && !lower_text.empty()) | 124 if (!upper_text.empty() && !lower_text.empty()) |
131 SetAccessibleName(upper_text + base::ASCIIToUTF16("\n") + lower_text); | 125 SetAccessibleName(upper_text + base::ASCIIToUTF16("\n") + lower_text); |
132 else | 126 else |
133 SetAccessibleName(upper_text + lower_text); | 127 SetAccessibleName(upper_text + lower_text); |
134 | 128 |
135 SetFocusBehavior(FocusBehavior::ALWAYS); | 129 SetFocusBehavior(FocusBehavior::ALWAYS); |
136 } | 130 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 child_area.CenterPoint().y() - info_icon_->height() / 2)); | 196 child_area.CenterPoint().y() - info_icon_->height() / 2)); |
203 } | 197 } |
204 } | 198 } |
205 | 199 |
206 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { | 200 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { |
207 if (state() == STATE_PRESSED || state() == STATE_HOVERED) | 201 if (state() == STATE_PRESSED || state() == STATE_HOVERED) |
208 canvas->DrawColor(hover_color_); | 202 canvas->DrawColor(hover_color_); |
209 | 203 |
210 LabelButton::OnPaint(canvas); | 204 LabelButton::OnPaint(canvas); |
211 } | 205 } |
OLD | NEW |