| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autofill_dialog_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // It exists to circumvent shortcomings of GridLayout and BoxLayout (namely that | 158 // It exists to circumvent shortcomings of GridLayout and BoxLayout (namely that |
| 159 // the former doesn't fully respect child visibility, and that the latter won't | 159 // the former doesn't fully respect child visibility, and that the latter won't |
| 160 // expand a single child). | 160 // expand a single child). |
| 161 class SectionRowView : public views::View { | 161 class SectionRowView : public views::View { |
| 162 public: | 162 public: |
| 163 SectionRowView() { SetBorder(views::Border::CreateEmptyBorder(10, 0, 0, 0)); } | 163 SectionRowView() { SetBorder(views::Border::CreateEmptyBorder(10, 0, 0, 0)); } |
| 164 | 164 |
| 165 virtual ~SectionRowView() {} | 165 virtual ~SectionRowView() {} |
| 166 | 166 |
| 167 // views::View implementation: | 167 // views::View implementation: |
| 168 virtual gfx::Size GetPreferredSize() OVERRIDE { | 168 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 169 int height = 0; | 169 int height = 0; |
| 170 int width = 0; | 170 int width = 0; |
| 171 for (int i = 0; i < child_count(); ++i) { | 171 for (int i = 0; i < child_count(); ++i) { |
| 172 if (child_at(i)->visible()) { | 172 if (child_at(i)->visible()) { |
| 173 if (width > 0) | 173 if (width > 0) |
| 174 width += kAroundTextPadding; | 174 width += kAroundTextPadding; |
| 175 | 175 |
| 176 gfx::Size size = child_at(i)->GetPreferredSize(); | 176 gfx::Size size = child_at(i)->GetPreferredSize(); |
| 177 height = std::max(height, size.height()); | 177 height = std::max(height, size.height()); |
| 178 width += size.width(); | 178 width += size.width(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 // views::View implementation. | 311 // views::View implementation. |
| 312 virtual gfx::Insets GetInsets() const OVERRIDE { | 312 virtual gfx::Insets GetInsets() const OVERRIDE { |
| 313 int vertical_padding = kNotificationPadding; | 313 int vertical_padding = kNotificationPadding; |
| 314 if (checkbox_) | 314 if (checkbox_) |
| 315 vertical_padding -= 3; | 315 vertical_padding -= 3; |
| 316 return gfx::Insets(vertical_padding, kDialogEdgePadding, | 316 return gfx::Insets(vertical_padding, kDialogEdgePadding, |
| 317 vertical_padding, kDialogEdgePadding); | 317 vertical_padding, kDialogEdgePadding); |
| 318 } | 318 } |
| 319 | 319 |
| 320 virtual int GetHeightForWidth(int width) OVERRIDE { | 320 virtual int GetHeightForWidth(int width) const OVERRIDE { |
| 321 int label_width = width - GetInsets().width(); | 321 int label_width = width - GetInsets().width(); |
| 322 if (child_count() > 1) { | 322 if (child_count() > 1) { |
| 323 views::View* tooltip_icon = child_at(1); | 323 const views::View* tooltip_icon = child_at(1); |
| 324 label_width -= tooltip_icon->GetPreferredSize().width() + | 324 label_width -= tooltip_icon->GetPreferredSize().width() + |
| 325 kDialogEdgePadding; | 325 kDialogEdgePadding; |
| 326 } | 326 } |
| 327 | 327 |
| 328 return child_at(0)->GetHeightForWidth(label_width) + GetInsets().height(); | 328 return child_at(0)->GetHeightForWidth(label_width) + GetInsets().height(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 virtual void Layout() OVERRIDE { | 331 virtual void Layout() OVERRIDE { |
| 332 // Surprisingly, GetContentsBounds() doesn't consult GetInsets(). | 332 // Surprisingly, GetContentsBounds() doesn't consult GetInsets(). |
| 333 gfx::Rect bounds = GetLocalBounds(); | 333 gfx::Rect bounds = GetLocalBounds(); |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 const DialogNotification& notification = notifications_[i]; | 748 const DialogNotification& notification = notifications_[i]; |
| 749 scoped_ptr<NotificationView> view(new NotificationView(notification, | 749 scoped_ptr<NotificationView> view(new NotificationView(notification, |
| 750 delegate_)); | 750 delegate_)); |
| 751 | 751 |
| 752 AddChildView(view.release()); | 752 AddChildView(view.release()); |
| 753 } | 753 } |
| 754 | 754 |
| 755 PreferredSizeChanged(); | 755 PreferredSizeChanged(); |
| 756 } | 756 } |
| 757 | 757 |
| 758 gfx::Size AutofillDialogViews::NotificationArea::GetPreferredSize() { | 758 gfx::Size AutofillDialogViews::NotificationArea::GetPreferredSize() const { |
| 759 gfx::Size size = views::View::GetPreferredSize(); | 759 gfx::Size size = views::View::GetPreferredSize(); |
| 760 // Ensure that long notifications wrap and don't enlarge the dialog. | 760 // Ensure that long notifications wrap and don't enlarge the dialog. |
| 761 size.set_width(1); | 761 size.set_width(1); |
| 762 return size; | 762 return size; |
| 763 } | 763 } |
| 764 | 764 |
| 765 const char* AutofillDialogViews::NotificationArea::GetClassName() const { | 765 const char* AutofillDialogViews::NotificationArea::GetClassName() const { |
| 766 return kNotificationAreaClassName; | 766 return kNotificationAreaClassName; |
| 767 } | 767 } |
| 768 | 768 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 gfx::Insets insets = GetInsets(); | 986 gfx::Insets insets = GetInsets(); |
| 987 insets += gfx::Insets(-kFocusBorderWidth, -kFocusBorderWidth, | 987 insets += gfx::Insets(-kFocusBorderWidth, -kFocusBorderWidth, |
| 988 -kFocusBorderWidth, -kFocusBorderWidth); | 988 -kFocusBorderWidth, -kFocusBorderWidth); |
| 989 SetFocusPainter( | 989 SetFocusPainter( |
| 990 views::Painter::CreateDashedFocusPainterWithInsets(insets)); | 990 views::Painter::CreateDashedFocusPainterWithInsets(insets)); |
| 991 SetFocusable(true); | 991 SetFocusable(true); |
| 992 } | 992 } |
| 993 | 993 |
| 994 AutofillDialogViews::SuggestedButton::~SuggestedButton() {} | 994 AutofillDialogViews::SuggestedButton::~SuggestedButton() {} |
| 995 | 995 |
| 996 gfx::Size AutofillDialogViews::SuggestedButton::GetPreferredSize() { | 996 gfx::Size AutofillDialogViews::SuggestedButton::GetPreferredSize() const { |
| 997 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 997 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 998 gfx::Size size = rb.GetImageNamed(ResourceIDForState()).Size(); | 998 gfx::Size size = rb.GetImageNamed(ResourceIDForState()).Size(); |
| 999 const gfx::Insets insets = GetInsets(); | 999 const gfx::Insets insets = GetInsets(); |
| 1000 size.Enlarge(insets.width(), insets.height()); | 1000 size.Enlarge(insets.width(), insets.height()); |
| 1001 return size; | 1001 return size; |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 const char* AutofillDialogViews::SuggestedButton::GetClassName() const { | 1004 const char* AutofillDialogViews::SuggestedButton::GetClassName() const { |
| 1005 return kSuggestedButtonClassName; | 1005 return kSuggestedButtonClassName; |
| 1006 } | 1006 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 label_line_2_->SetVisible(false); | 1081 label_line_2_->SetVisible(false); |
| 1082 label_line_2_->SetLineHeight(22); | 1082 label_line_2_->SetLineHeight(22); |
| 1083 label_line_2_->SetMultiLine(true); | 1083 label_line_2_->SetMultiLine(true); |
| 1084 AddChildView(label_line_2_); | 1084 AddChildView(label_line_2_); |
| 1085 | 1085 |
| 1086 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 7)); | 1086 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 7)); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 AutofillDialogViews::SuggestionView::~SuggestionView() {} | 1089 AutofillDialogViews::SuggestionView::~SuggestionView() {} |
| 1090 | 1090 |
| 1091 gfx::Size AutofillDialogViews::SuggestionView::GetPreferredSize() { | 1091 gfx::Size AutofillDialogViews::SuggestionView::GetPreferredSize() const { |
| 1092 // There's no preferred width. The parent's layout should get the preferred | 1092 // There's no preferred width. The parent's layout should get the preferred |
| 1093 // height from GetHeightForWidth(). | 1093 // height from GetHeightForWidth(). |
| 1094 return gfx::Size(); | 1094 return gfx::Size(); |
| 1095 } | 1095 } |
| 1096 | 1096 |
| 1097 int AutofillDialogViews::SuggestionView::GetHeightForWidth(int width) { | 1097 int AutofillDialogViews::SuggestionView::GetHeightForWidth(int width) const { |
| 1098 int height = 0; | 1098 int height = 0; |
| 1099 CanUseVerticallyCompactText(width, &height); | 1099 CanUseVerticallyCompactText(width, &height); |
| 1100 return height; | 1100 return height; |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 bool AutofillDialogViews::SuggestionView::CanUseVerticallyCompactText( | 1103 bool AutofillDialogViews::SuggestionView::CanUseVerticallyCompactText( |
| 1104 int available_width, | 1104 int available_width, |
| 1105 int* resulting_height) { | 1105 int* resulting_height) const { |
| 1106 // This calculation may be costly, avoid doing it more than once per width. | 1106 // This calculation may be costly, avoid doing it more than once per width. |
| 1107 if (!calculated_heights_.count(available_width)) { | 1107 if (!calculated_heights_.count(available_width)) { |
| 1108 // Changing the state of |this| now will lead to extra layouts and | 1108 // Changing the state of |this| now will lead to extra layouts and |
| 1109 // paints we don't want, so create another SuggestionView to calculate | 1109 // paints we don't want, so create another SuggestionView to calculate |
| 1110 // which label we have room to show. | 1110 // which label we have room to show. |
| 1111 SuggestionView sizing_view(NULL); | 1111 SuggestionView sizing_view(NULL); |
| 1112 sizing_view.SetLabelText(state_.vertically_compact_text); | 1112 sizing_view.SetLabelText(state_.vertically_compact_text); |
| 1113 sizing_view.SetIcon(state_.icon); | 1113 sizing_view.SetIcon(state_.icon); |
| 1114 sizing_view.SetTextfield(state_.extra_text, state_.extra_icon); | 1114 sizing_view.SetTextfield(state_.extra_text, state_.extra_icon); |
| 1115 sizing_view.label_->SetSize(gfx::Size(available_width, 0)); | 1115 sizing_view.label_->SetSize(gfx::Size(available_width, 0)); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 | 1465 |
| 1466 void AutofillDialogViews::OnSignInResize(const gfx::Size& pref_size) { | 1466 void AutofillDialogViews::OnSignInResize(const gfx::Size& pref_size) { |
| 1467 sign_in_web_view_->SetPreferredSize(pref_size); | 1467 sign_in_web_view_->SetPreferredSize(pref_size); |
| 1468 ContentsPreferredSizeChanged(); | 1468 ContentsPreferredSizeChanged(); |
| 1469 } | 1469 } |
| 1470 | 1470 |
| 1471 void AutofillDialogViews::ValidateSection(DialogSection section) { | 1471 void AutofillDialogViews::ValidateSection(DialogSection section) { |
| 1472 ValidateGroup(*GroupForSection(section), VALIDATE_EDIT); | 1472 ValidateGroup(*GroupForSection(section), VALIDATE_EDIT); |
| 1473 } | 1473 } |
| 1474 | 1474 |
| 1475 gfx::Size AutofillDialogViews::GetPreferredSize() { | 1475 gfx::Size AutofillDialogViews::GetPreferredSize() const { |
| 1476 if (preferred_size_.IsEmpty()) | 1476 if (preferred_size_.IsEmpty()) |
| 1477 preferred_size_ = CalculatePreferredSize(false); | 1477 preferred_size_ = CalculatePreferredSize(false); |
| 1478 | 1478 |
| 1479 return preferred_size_; | 1479 return preferred_size_; |
| 1480 } | 1480 } |
| 1481 | 1481 |
| 1482 gfx::Size AutofillDialogViews::GetMinimumSize() { | 1482 gfx::Size AutofillDialogViews::GetMinimumSize() const { |
| 1483 return CalculatePreferredSize(true); | 1483 return CalculatePreferredSize(true); |
| 1484 } | 1484 } |
| 1485 | 1485 |
| 1486 void AutofillDialogViews::Layout() { | 1486 void AutofillDialogViews::Layout() { |
| 1487 const gfx::Rect content_bounds = GetContentsBounds(); | 1487 const gfx::Rect content_bounds = GetContentsBounds(); |
| 1488 if (sign_in_web_view_->visible()) { | 1488 if (sign_in_web_view_->visible()) { |
| 1489 sign_in_web_view_->SetBoundsRect(content_bounds); | 1489 sign_in_web_view_->SetBoundsRect(content_bounds); |
| 1490 return; | 1490 return; |
| 1491 } | 1491 } |
| 1492 | 1492 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1759 views::MENU_ANCHOR_TOPRIGHT, | 1759 views::MENU_ANCHOR_TOPRIGHT, |
| 1760 ui::MENU_SOURCE_NONE, | 1760 ui::MENU_SOURCE_NONE, |
| 1761 0) == views::MenuRunner::MENU_DELETED) { | 1761 0) == views::MenuRunner::MENU_DELETED) { |
| 1762 return; | 1762 return; |
| 1763 } | 1763 } |
| 1764 | 1764 |
| 1765 group->container->SetActive(false); | 1765 group->container->SetActive(false); |
| 1766 group->suggested_button->SetState(state); | 1766 group->suggested_button->SetState(state); |
| 1767 } | 1767 } |
| 1768 | 1768 |
| 1769 gfx::Size AutofillDialogViews::CalculatePreferredSize(bool get_minimum_size) { | 1769 gfx::Size AutofillDialogViews::CalculatePreferredSize( |
| 1770 bool get_minimum_size) const { |
| 1770 gfx::Insets insets = GetInsets(); | 1771 gfx::Insets insets = GetInsets(); |
| 1771 gfx::Size scroll_size = scrollable_area_->contents()->GetPreferredSize(); | 1772 gfx::Size scroll_size = scrollable_area_->contents()->GetPreferredSize(); |
| 1772 // The width is always set by the scroll area. | 1773 // The width is always set by the scroll area. |
| 1773 const int width = scroll_size.width(); | 1774 const int width = scroll_size.width(); |
| 1774 | 1775 |
| 1775 if (sign_in_web_view_->visible()) { | 1776 if (sign_in_web_view_->visible()) { |
| 1776 const gfx::Size size = static_cast<views::View*>(sign_in_web_view_)-> | 1777 const gfx::Size size = static_cast<views::View*>(sign_in_web_view_)-> |
| 1777 GetPreferredSize(); | 1778 GetPreferredSize(); |
| 1778 return gfx::Size(width + insets.width(), size.height() + insets.height()); | 1779 return gfx::Size(width + insets.width(), size.height() + insets.height()); |
| 1779 } | 1780 } |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2511 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 2512 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
| 2512 : section(section), | 2513 : section(section), |
| 2513 container(NULL), | 2514 container(NULL), |
| 2514 manual_input(NULL), | 2515 manual_input(NULL), |
| 2515 suggested_info(NULL), | 2516 suggested_info(NULL), |
| 2516 suggested_button(NULL) {} | 2517 suggested_button(NULL) {} |
| 2517 | 2518 |
| 2518 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 2519 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
| 2519 | 2520 |
| 2520 } // namespace autofill | 2521 } // namespace autofill |
| OLD | NEW |