| 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/harmony/chrome_layout_provider.h" |
| 10 #include "chrome/browser/ui/views/harmony/chrome_typography.h" | 11 #include "chrome/browser/ui/views/harmony/chrome_typography.h" |
| 11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 12 #include "chrome/grit/theme_resources.h" | 13 #include "chrome/grit/theme_resources.h" |
| 13 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
| 14 #include "ui/base/material_design/material_design_controller.h" | |
| 15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/path.h" | 17 #include "ui/gfx/path.h" |
| 18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 19 #include "ui/views/bubble/tooltip_icon.h" | 19 #include "ui/views/bubble/tooltip_icon.h" |
| 20 #include "ui/views/controls/image_view.h" | 20 #include "ui/views/controls/image_view.h" |
| 21 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
| 22 #include "ui/views/layout/layout_constants.h" | 22 #include "ui/views/layout/layout_constants.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 // The default spacing between the icon and text. | |
| 26 const int kSpacing = 12; | |
| 27 | 25 |
| 28 gfx::Size GetTextLabelsSize(const views::Label* upper_label, | 26 gfx::Size GetTextLabelsSize(const views::Label* upper_label, |
| 29 const views::Label* lower_label) { | 27 const views::Label* lower_label) { |
| 30 gfx::Size upper_label_size = upper_label ? upper_label->GetPreferredSize() | 28 gfx::Size upper_label_size = upper_label ? upper_label->GetPreferredSize() |
| 31 : gfx::Size(); | 29 : gfx::Size(); |
| 32 gfx::Size lower_label_size = lower_label ? lower_label->GetPreferredSize() | 30 gfx::Size lower_label_size = lower_label ? lower_label->GetPreferredSize() |
| 33 : gfx::Size(); | 31 : gfx::Size(); |
| 34 return gfx::Size(std::max(upper_label_size.width(), lower_label_size.width()), | 32 return gfx::Size(std::max(upper_label_size.width(), lower_label_size.width()), |
| 35 upper_label_size.height() + lower_label_size.height()); | 33 upper_label_size.height() + lower_label_size.height()); |
| 36 } | 34 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 if (form_->icon_url.is_valid()) { | 85 if (form_->icon_url.is_valid()) { |
| 88 // Fetch the actual avatar. | 86 // Fetch the actual avatar. |
| 89 AccountAvatarFetcher* fetcher = new AccountAvatarFetcher( | 87 AccountAvatarFetcher* fetcher = new AccountAvatarFetcher( |
| 90 form_->icon_url, weak_ptr_factory_.GetWeakPtr()); | 88 form_->icon_url, weak_ptr_factory_.GetWeakPtr()); |
| 91 fetcher->Start(request_context); | 89 fetcher->Start(request_context); |
| 92 } | 90 } |
| 93 AddChildView(image_view_); | 91 AddChildView(image_view_); |
| 94 | 92 |
| 95 // TODO(tapted): Check these (and the STYLE_ values below) against the spec on | 93 // TODO(tapted): Check these (and the STYLE_ values below) against the spec on |
| 96 // http://crbug.com/651681. | 94 // http://crbug.com/651681. |
| 97 const int kLabelContext = | 95 const int kLabelContext = ChromeLayoutProvider::Get()->IsHarmonyMode() |
| 98 ui::MaterialDesignController::IsSecondaryUiMaterial() | 96 ? CONTEXT_BODY_TEXT_SMALL |
| 99 ? CONTEXT_BODY_TEXT_SMALL | 97 : CONTEXT_DEPRECATED_SMALL; |
| 100 : CONTEXT_DEPRECATED_SMALL; | |
| 101 | 98 |
| 102 if (!upper_text.empty()) { | 99 if (!upper_text.empty()) { |
| 103 upper_label_ = new views::Label(upper_text, kLabelContext, | 100 upper_label_ = new views::Label(upper_text, kLabelContext, |
| 104 views::style::STYLE_PRIMARY); | 101 views::style::STYLE_PRIMARY); |
| 105 upper_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 102 upper_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 106 AddChildView(upper_label_); | 103 AddChildView(upper_label_); |
| 107 } | 104 } |
| 108 | 105 |
| 109 if (!lower_text.empty()) { | 106 if (!lower_text.empty()) { |
| 110 lower_label_ = new views::Label(lower_text, kLabelContext, STYLE_SECONDARY); | 107 lower_label_ = new views::Label(lower_text, kLabelContext, STYLE_SECONDARY); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 int CredentialsItemView::GetPreferredHeight() const { | 142 int CredentialsItemView::GetPreferredHeight() const { |
| 146 return GetPreferredSize().height(); | 143 return GetPreferredSize().height(); |
| 147 } | 144 } |
| 148 | 145 |
| 149 gfx::Size CredentialsItemView::GetPreferredSize() const { | 146 gfx::Size CredentialsItemView::GetPreferredSize() const { |
| 150 gfx::Size labels_size = GetTextLabelsSize(upper_label_, lower_label_); | 147 gfx::Size labels_size = GetTextLabelsSize(upper_label_, lower_label_); |
| 151 gfx::Size size = gfx::Size(kAvatarImageSize + labels_size.width(), | 148 gfx::Size size = gfx::Size(kAvatarImageSize + labels_size.width(), |
| 152 std::max(kAvatarImageSize, labels_size.height())); | 149 std::max(kAvatarImageSize, labels_size.height())); |
| 153 const gfx::Insets insets(GetInsets()); | 150 const gfx::Insets insets(GetInsets()); |
| 154 size.Enlarge(insets.width(), insets.height()); | 151 size.Enlarge(insets.width(), insets.height()); |
| 155 size.Enlarge(kSpacing, 0); | 152 size.Enlarge(ChromeLayoutProvider::Get()->GetDistanceMetric( |
| 153 DISTANCE_UNRELATED_CONTROL_HORIZONTAL), |
| 154 0); |
| 156 | 155 |
| 157 // Make the size at least as large as the minimum size needed by the border. | 156 // Make the size at least as large as the minimum size needed by the border. |
| 158 size.SetToMax(border() ? border()->GetMinimumSize() : gfx::Size()); | 157 size.SetToMax(border() ? border()->GetMinimumSize() : gfx::Size()); |
| 159 return size; | 158 return size; |
| 160 } | 159 } |
| 161 | 160 |
| 162 int CredentialsItemView::GetHeightForWidth(int w) const { | 161 int CredentialsItemView::GetHeightForWidth(int w) const { |
| 163 return View::GetHeightForWidth(w); | 162 return View::GetHeightForWidth(w); |
| 164 } | 163 } |
| 165 | 164 |
| 166 void CredentialsItemView::Layout() { | 165 void CredentialsItemView::Layout() { |
| 167 gfx::Rect child_area(GetLocalBounds()); | 166 gfx::Rect child_area(GetLocalBounds()); |
| 168 child_area.Inset(GetInsets()); | 167 child_area.Inset(GetInsets()); |
| 169 | 168 |
| 170 gfx::Size image_size(image_view_->GetPreferredSize()); | 169 gfx::Size image_size(image_view_->GetPreferredSize()); |
| 171 image_size.SetToMin(child_area.size()); | 170 image_size.SetToMin(child_area.size()); |
| 172 gfx::Point image_origin(child_area.origin()); | 171 gfx::Point image_origin(child_area.origin()); |
| 173 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); | 172 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); |
| 174 image_view_->SetBoundsRect(gfx::Rect(image_origin, image_size)); | 173 image_view_->SetBoundsRect(gfx::Rect(image_origin, image_size)); |
| 175 | 174 |
| 176 gfx::Size upper_size = | 175 gfx::Size upper_size = |
| 177 upper_label_ ? upper_label_->GetPreferredSize() : gfx::Size(); | 176 upper_label_ ? upper_label_->GetPreferredSize() : gfx::Size(); |
| 178 gfx::Size lower_size = | 177 gfx::Size lower_size = |
| 179 lower_label_ ? lower_label_->GetPreferredSize() : gfx::Size(); | 178 lower_label_ ? lower_label_->GetPreferredSize() : gfx::Size(); |
| 180 int y_offset = (child_area.height() - | 179 int y_offset = (child_area.height() - |
| 181 (upper_size.height() + lower_size.height())) / 2; | 180 (upper_size.height() + lower_size.height())) / 2; |
| 182 gfx::Point label_origin(image_origin.x() + image_size.width() + kSpacing, | 181 gfx::Point label_origin(image_origin.x() + image_size.width() + |
| 182 ChromeLayoutProvider::Get()->GetDistanceMetric( |
| 183 DISTANCE_UNRELATED_CONTROL_HORIZONTAL), |
| 183 child_area.origin().y() + y_offset); | 184 child_area.origin().y() + y_offset); |
| 184 if (upper_label_) | 185 if (upper_label_) |
| 185 upper_label_->SetBoundsRect(gfx::Rect(label_origin, upper_size)); | 186 upper_label_->SetBoundsRect(gfx::Rect(label_origin, upper_size)); |
| 186 if (lower_label_) { | 187 if (lower_label_) { |
| 187 label_origin.Offset(0, upper_size.height()); | 188 label_origin.Offset(0, upper_size.height()); |
| 188 lower_label_->SetBoundsRect(gfx::Rect(label_origin, lower_size)); | 189 lower_label_->SetBoundsRect(gfx::Rect(label_origin, lower_size)); |
| 189 } | 190 } |
| 190 if (info_icon_) { | 191 if (info_icon_) { |
| 191 info_icon_->SizeToPreferredSize(); | 192 info_icon_->SizeToPreferredSize(); |
| 192 info_icon_->SetPosition( | 193 info_icon_->SetPosition( |
| 193 gfx::Point(child_area.right() - info_icon_->width(), | 194 gfx::Point(child_area.right() - info_icon_->width(), |
| 194 child_area.CenterPoint().y() - info_icon_->height() / 2)); | 195 child_area.CenterPoint().y() - info_icon_->height() / 2)); |
| 195 } | 196 } |
| 196 } | 197 } |
| 197 | 198 |
| 198 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { | 199 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { |
| 199 if (state() == STATE_PRESSED || state() == STATE_HOVERED) | 200 if (state() == STATE_PRESSED || state() == STATE_HOVERED) |
| 200 canvas->DrawColor(hover_color_); | 201 canvas->DrawColor(hover_color_); |
| 201 | 202 |
| 202 CustomButton::OnPaint(canvas); | 203 CustomButton::OnPaint(canvas); |
| 203 } | 204 } |
| OLD | NEW |