| 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_layout_provider.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return GetPreferredSize().height(); | 143 return GetPreferredSize().height(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 gfx::Size CredentialsItemView::GetPreferredSize() const { | 146 gfx::Size CredentialsItemView::GetPreferredSize() const { |
| 147 gfx::Size labels_size = GetTextLabelsSize(upper_label_, lower_label_); | 147 gfx::Size labels_size = GetTextLabelsSize(upper_label_, lower_label_); |
| 148 gfx::Size size = gfx::Size(kAvatarImageSize + labels_size.width(), | 148 gfx::Size size = gfx::Size(kAvatarImageSize + labels_size.width(), |
| 149 std::max(kAvatarImageSize, labels_size.height())); | 149 std::max(kAvatarImageSize, labels_size.height())); |
| 150 const gfx::Insets insets(GetInsets()); | 150 const gfx::Insets insets(GetInsets()); |
| 151 size.Enlarge(insets.width(), insets.height()); | 151 size.Enlarge(insets.width(), insets.height()); |
| 152 size.Enlarge(ChromeLayoutProvider::Get()->GetDistanceMetric( | 152 size.Enlarge(ChromeLayoutProvider::Get()->GetDistanceMetric( |
| 153 DISTANCE_UNRELATED_CONTROL_HORIZONTAL), | 153 DISTANCE_RELATED_LABEL_HORIZONTAL), |
| 154 0); | 154 0); |
| 155 | 155 |
| 156 // 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. |
| 157 size.SetToMax(border() ? border()->GetMinimumSize() : gfx::Size()); | 157 size.SetToMax(border() ? border()->GetMinimumSize() : gfx::Size()); |
| 158 return size; | 158 return size; |
| 159 } | 159 } |
| 160 | 160 |
| 161 int CredentialsItemView::GetHeightForWidth(int w) const { | 161 int CredentialsItemView::GetHeightForWidth(int w) const { |
| 162 return View::GetHeightForWidth(w); | 162 return View::GetHeightForWidth(w); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void CredentialsItemView::Layout() { | 165 void CredentialsItemView::Layout() { |
| 166 gfx::Rect child_area(GetLocalBounds()); | 166 gfx::Rect child_area(GetLocalBounds()); |
| 167 child_area.Inset(GetInsets()); | 167 child_area.Inset(GetInsets()); |
| 168 | 168 |
| 169 gfx::Size image_size(image_view_->GetPreferredSize()); | 169 gfx::Size image_size(image_view_->GetPreferredSize()); |
| 170 image_size.SetToMin(child_area.size()); | 170 image_size.SetToMin(child_area.size()); |
| 171 gfx::Point image_origin(child_area.origin()); | 171 gfx::Point image_origin(child_area.origin()); |
| 172 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); | 172 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); |
| 173 image_view_->SetBoundsRect(gfx::Rect(image_origin, image_size)); | 173 image_view_->SetBoundsRect(gfx::Rect(image_origin, image_size)); |
| 174 | 174 |
| 175 gfx::Size upper_size = | 175 gfx::Size upper_size = |
| 176 upper_label_ ? upper_label_->GetPreferredSize() : gfx::Size(); | 176 upper_label_ ? upper_label_->GetPreferredSize() : gfx::Size(); |
| 177 gfx::Size lower_size = | 177 gfx::Size lower_size = |
| 178 lower_label_ ? lower_label_->GetPreferredSize() : gfx::Size(); | 178 lower_label_ ? lower_label_->GetPreferredSize() : gfx::Size(); |
| 179 int y_offset = (child_area.height() - | 179 int y_offset = (child_area.height() - |
| 180 (upper_size.height() + lower_size.height())) / 2; | 180 (upper_size.height() + lower_size.height())) / 2; |
| 181 gfx::Point label_origin(image_origin.x() + image_size.width() + | 181 gfx::Point label_origin(image_origin.x() + image_size.width() + |
| 182 ChromeLayoutProvider::Get()->GetDistanceMetric( | 182 ChromeLayoutProvider::Get()->GetDistanceMetric( |
| 183 DISTANCE_UNRELATED_CONTROL_HORIZONTAL), | 183 DISTANCE_RELATED_LABEL_HORIZONTAL), |
| 184 child_area.origin().y() + y_offset); | 184 child_area.origin().y() + y_offset); |
| 185 if (upper_label_) | 185 if (upper_label_) |
| 186 upper_label_->SetBoundsRect(gfx::Rect(label_origin, upper_size)); | 186 upper_label_->SetBoundsRect(gfx::Rect(label_origin, upper_size)); |
| 187 if (lower_label_) { | 187 if (lower_label_) { |
| 188 label_origin.Offset(0, upper_size.height()); | 188 label_origin.Offset(0, upper_size.height()); |
| 189 lower_label_->SetBoundsRect(gfx::Rect(label_origin, lower_size)); | 189 lower_label_->SetBoundsRect(gfx::Rect(label_origin, lower_size)); |
| 190 } | 190 } |
| 191 if (info_icon_) { | 191 if (info_icon_) { |
| 192 info_icon_->SizeToPreferredSize(); | 192 info_icon_->SizeToPreferredSize(); |
| 193 info_icon_->SetPosition( | 193 info_icon_->SetPosition( |
| 194 gfx::Point(child_area.right() - info_icon_->width(), | 194 gfx::Point(child_area.right() - info_icon_->width(), |
| 195 child_area.CenterPoint().y() - info_icon_->height() / 2)); | 195 child_area.CenterPoint().y() - info_icon_->height() / 2)); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { | 199 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { |
| 200 if (state() == STATE_PRESSED || state() == STATE_HOVERED) | 200 if (state() == STATE_PRESSED || state() == STATE_HOVERED) |
| 201 canvas->DrawColor(hover_color_); | 201 canvas->DrawColor(hover_color_); |
| 202 | 202 |
| 203 CustomButton::OnPaint(canvas); | 203 CustomButton::OnPaint(canvas); |
| 204 } | 204 } |
| OLD | NEW |