 Chromium Code Reviews
 Chromium Code Reviews Issue 2684343006:
  Make the account chooser and CVC dialog use the same icon with toolip for Views.  (Closed)
    
  
    Issue 2684343006:
  Make the account chooser and CVC dialog use the same icon with toolip for Views.  (Closed) 
  | 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/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" | 
| 11 #include "chrome/grit/theme_resources.h" | 11 #include "chrome/grit/theme_resources.h" | 
| 12 #include "components/autofill/core/common/password_form.h" | 12 #include "components/autofill/core/common/password_form.h" | 
| 13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" | 
| 14 #include "ui/gfx/canvas.h" | 14 #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" | 15 #include "ui/gfx/path.h" | 
| 19 #include "ui/gfx/vector_icons_public.h" | |
| 20 #include "ui/views/border.h" | 16 #include "ui/views/border.h" | 
| 17 #include "ui/views/bubble/tooltip_icon.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, | 
| 30 const views::Label* lower_label) { | 27 const views::Label* lower_label) { | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 52 gfx::Rect bounds(GetImageBounds()); | 49 gfx::Rect bounds(GetImageBounds()); | 
| 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. | |
| 63 class InfoImageView : public views::ImageView { | |
| 64 public: | |
| 65 // View: | |
| 66 bool OnMousePressed(const ui::MouseEvent& event) override { return true; } | |
| 67 bool OnMouseDragged(const ui::MouseEvent& event) override { return true; } | |
| 68 }; | |
| 69 | |
| 70 } // namespace | 59 } // namespace | 
| 71 | 60 | 
| 72 CredentialsItemView::CredentialsItemView( | 61 CredentialsItemView::CredentialsItemView( | 
| 73 views::ButtonListener* button_listener, | 62 views::ButtonListener* button_listener, | 
| 74 const base::string16& upper_text, | 63 const base::string16& upper_text, | 
| 75 const base::string16& lower_text, | 64 const base::string16& lower_text, | 
| 76 SkColor hover_color, | 65 SkColor hover_color, | 
| 77 const autofill::PasswordForm* form, | 66 const autofill::PasswordForm* form, | 
| 78 net::URLRequestContextGetter* request_context) | 67 net::URLRequestContextGetter* request_context) | 
| 79 : LabelButton(button_listener, base::string16()), | 68 : CustomButton(button_listener), | 
| 80 form_(form), | 69 form_(form), | 
| 81 upper_label_(nullptr), | 70 upper_label_(nullptr), | 
| 82 lower_label_(nullptr), | 71 lower_label_(nullptr), | 
| 83 info_icon_(nullptr), | 72 info_icon_(nullptr), | 
| 84 hover_color_(hover_color), | 73 hover_color_(hover_color), | 
| 85 weak_ptr_factory_(this) { | 74 weak_ptr_factory_(this) { | 
| 86 set_notify_enter_exit_on_child(true); | 75 set_notify_enter_exit_on_child(true); | 
| 87 // Create an image-view for the avatar. Make sure it ignores events so that | 76 // Create an image-view for the avatar. Make sure it ignores events so that | 
| 88 // the parent can receive the events instead. | 77 // the parent can receive the events instead. | 
| 89 image_view_ = new CircularImageView; | 78 image_view_ = new CircularImageView; | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 111 | 100 | 
| 112 if (!lower_text.empty()) { | 101 if (!lower_text.empty()) { | 
| 113 lower_label_ = new views::Label( | 102 lower_label_ = new views::Label( | 
| 114 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); | 103 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); | 
| 115 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 104 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 
| 116 lower_label_->SetMultiLine(true); | 105 lower_label_->SetMultiLine(true); | 
| 117 AddChildView(lower_label_); | 106 AddChildView(lower_label_); | 
| 118 } | 107 } | 
| 119 | 108 | 
| 120 if (form_->is_public_suffix_match) { | 109 if (form_->is_public_suffix_match) { | 
| 121 info_icon_ = new InfoImageView; | 110 info_icon_ = new views::TooltipIcon( | 
| 122 info_icon_->SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::INFO_OUTLINE, | |
| 123 kInfoIconSize, | |
| 124 gfx::kChromeIconGrey)); | |
| 125 info_icon_->SetTooltipText( | |
| 126 base::UTF8ToUTF16(form_->origin.GetOrigin().spec())); | 111 base::UTF8ToUTF16(form_->origin.GetOrigin().spec())); | 
| 127 AddChildView(info_icon_); | 112 AddChildView(info_icon_); | 
| 128 } | 113 } | 
| 129 | 114 | 
| 130 if (!upper_text.empty() && !lower_text.empty()) | 115 if (!upper_text.empty() && !lower_text.empty()) | 
| 131 SetAccessibleName(upper_text + base::ASCIIToUTF16("\n") + lower_text); | 116 SetAccessibleName(upper_text + base::ASCIIToUTF16("\n") + lower_text); | 
| 132 else | 117 else | 
| 133 SetAccessibleName(upper_text + lower_text); | 118 SetAccessibleName(upper_text + lower_text); | 
| 134 | 119 | 
| 135 SetFocusBehavior(FocusBehavior::ALWAYS); | 120 SetFocusBehavior(FocusBehavior::ALWAYS); | 
| (...skipping 29 matching lines...) Expand all Loading... | |
| 165 // Make the size at least as large as the minimum size needed by the border. | 150 // Make the size at least as large as the minimum size needed by the border. | 
| 166 size.SetToMax(border() ? border()->GetMinimumSize() : gfx::Size()); | 151 size.SetToMax(border() ? border()->GetMinimumSize() : gfx::Size()); | 
| 167 return size; | 152 return size; | 
| 168 } | 153 } | 
| 169 | 154 | 
| 170 int CredentialsItemView::GetHeightForWidth(int w) const { | 155 int CredentialsItemView::GetHeightForWidth(int w) const { | 
| 171 return View::GetHeightForWidth(w); | 156 return View::GetHeightForWidth(w); | 
| 172 } | 157 } | 
| 173 | 158 | 
| 174 void CredentialsItemView::Layout() { | 159 void CredentialsItemView::Layout() { | 
| 175 gfx::Rect child_area(GetChildAreaBounds()); | 160 gfx::Rect child_area(GetLocalBounds()); | 
| 176 child_area.Inset(GetInsets()); | 161 child_area.Inset(GetInsets()); | 
| 177 | 162 | 
| 178 gfx::Size image_size(image_view_->GetPreferredSize()); | 163 gfx::Size image_size(image_view_->GetPreferredSize()); | 
| 179 image_size.SetToMin(child_area.size()); | 164 image_size.SetToMin(child_area.size()); | 
| 180 gfx::Point image_origin(child_area.origin()); | 165 gfx::Point image_origin(child_area.origin()); | 
| 181 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); | 166 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); | 
| 182 image_view_->SetBoundsRect(gfx::Rect(image_origin, image_size)); | 167 image_view_->SetBoundsRect(gfx::Rect(image_origin, image_size)); | 
| 183 | 168 | 
| 184 gfx::Size upper_size = | 169 gfx::Size upper_size = | 
| 185 upper_label_ ? upper_label_->GetPreferredSize() : gfx::Size(); | 170 upper_label_ ? upper_label_->GetPreferredSize() : gfx::Size(); | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 200 info_icon_->SetPosition( | 185 info_icon_->SetPosition( | 
| 201 gfx::Point(child_area.right() - info_icon_->width(), | 186 gfx::Point(child_area.right() - info_icon_->width(), | 
| 202 child_area.CenterPoint().y() - info_icon_->height() / 2)); | 187 child_area.CenterPoint().y() - info_icon_->height() / 2)); | 
| 203 } | 188 } | 
| 204 } | 189 } | 
| 205 | 190 | 
| 206 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { | 191 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { | 
| 207 if (state() == STATE_PRESSED || state() == STATE_HOVERED) | 192 if (state() == STATE_PRESSED || state() == STATE_HOVERED) | 
| 208 canvas->DrawColor(hover_color_); | 193 canvas->DrawColor(hover_color_); | 
| 209 | 194 | 
| 210 LabelButton::OnPaint(canvas); | 195 CustomButton::OnPaint(canvas); | 
| 211 } | 196 } | 
| 197 | |
| 198 void CredentialsItemView::NotifyClick(const ui::Event& event) { | |
| 199 if (info_icon_ == event.target()) | |
| 
msw
2017/02/15 21:06:37
nit: add a comment, eg. "Do not handle clicks on t
 
vasilii
2017/02/16 14:28:06
Removed because it doesn't work this way.
 | |
| 200 return; | |
| 201 | |
| 202 CustomButton::NotifyClick(event); | |
| 203 } | |
| OLD | NEW |