| 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_popup_view_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 8 #include "components/autofill/core/browser/popup_item_ids.h" | 8 #include "components/autofill/core/browser/popup_item_ids.h" |
| 9 #include "components/autofill/core/browser/suggestion.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/events/keycodes/keyboard_codes.h" | 11 #include "ui/events/keycodes/keyboard_codes.h" |
| 11 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
| 13 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
| 14 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
| 15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 16 #include "ui/gfx/text_utils.h" | 17 #include "ui/gfx/text_utils.h" |
| 17 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 DoUpdateBoundsAndRedrawPopup(); | 42 DoUpdateBoundsAndRedrawPopup(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 45 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| 45 if (!controller_) | 46 if (!controller_) |
| 46 return; | 47 return; |
| 47 | 48 |
| 48 canvas->DrawColor(kPopupBackground); | 49 canvas->DrawColor(kPopupBackground); |
| 49 OnPaintBorder(canvas); | 50 OnPaintBorder(canvas); |
| 50 | 51 |
| 51 for (size_t i = 0; i < controller_->names().size(); ++i) { | 52 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
| 52 gfx::Rect line_rect = controller_->GetRowBounds(i); | 53 gfx::Rect line_rect = controller_->GetRowBounds(i); |
| 53 | 54 |
| 54 if (controller_->identifiers()[i] == POPUP_ITEM_ID_SEPARATOR) { | 55 if (controller_->GetSuggestionAt(i).frontend_id == |
| 56 POPUP_ITEM_ID_SEPARATOR) { |
| 55 canvas->FillRect(line_rect, kItemTextColor); | 57 canvas->FillRect(line_rect, kItemTextColor); |
| 56 } else { | 58 } else { |
| 57 DrawAutofillEntry(canvas, i, line_rect); | 59 DrawAutofillEntry(canvas, i, line_rect); |
| 58 } | 60 } |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 | 63 |
| 62 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 64 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| 63 SchedulePaintInRect(controller_->GetRowBounds(row)); | 65 SchedulePaintInRect(controller_->GetRowBounds(row)); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, | 68 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| 67 int index, | 69 int index, |
| 68 const gfx::Rect& entry_rect) { | 70 const gfx::Rect& entry_rect) { |
| 69 if (controller_->selected_line() == index) | 71 if (controller_->selected_line() == index) |
| 70 canvas->FillRect(entry_rect, kHoveredBackgroundColor); | 72 canvas->FillRect(entry_rect, kHoveredBackgroundColor); |
| 71 | 73 |
| 72 const bool is_rtl = controller_->IsRTL(); | 74 const bool is_rtl = controller_->IsRTL(); |
| 73 const int value_text_width = | 75 const int value_text_width = |
| 74 gfx::GetStringWidth(controller_->names()[index], | 76 gfx::GetStringWidth(controller_->GetElidedValueAt(index), |
| 75 controller_->GetNameFontListForRow(index)); | 77 controller_->GetValueFontListForRow(index)); |
| 76 const int value_content_x = is_rtl ? | 78 const int value_content_x = is_rtl ? |
| 77 entry_rect.width() - value_text_width - kEndPadding : kEndPadding; | 79 entry_rect.width() - value_text_width - kEndPadding : kEndPadding; |
| 78 | 80 |
| 79 canvas->DrawStringRectWithFlags( | 81 canvas->DrawStringRectWithFlags( |
| 80 controller_->names()[index], | 82 controller_->GetElidedValueAt(index), |
| 81 controller_->GetNameFontListForRow(index), | 83 controller_->GetValueFontListForRow(index), |
| 82 controller_->IsWarning(index) ? kWarningTextColor : kValueTextColor, | 84 controller_->IsWarning(index) ? kWarningTextColor : kValueTextColor, |
| 83 gfx::Rect(value_content_x, | 85 gfx::Rect(value_content_x, |
| 84 entry_rect.y(), | 86 entry_rect.y(), |
| 85 value_text_width, | 87 value_text_width, |
| 86 entry_rect.height()), | 88 entry_rect.height()), |
| 87 gfx::Canvas::TEXT_ALIGN_CENTER); | 89 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 88 | 90 |
| 89 // Use this to figure out where all the other Autofill items should be placed. | 91 // Use this to figure out where all the other Autofill items should be placed. |
| 90 int x_align_left = is_rtl ? kEndPadding : entry_rect.width() - kEndPadding; | 92 int x_align_left = is_rtl ? kEndPadding : entry_rect.width() - kEndPadding; |
| 91 | 93 |
| 92 // Draw the Autofill icon, if one exists | 94 // Draw the Autofill icon, if one exists |
| 93 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 95 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 94 int row_height = controller_->GetRowBounds(index).height(); | 96 int row_height = controller_->GetRowBounds(index).height(); |
| 95 if (!controller_->icons()[index].empty()) { | 97 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 96 int icon = controller_->GetIconResourceID(controller_->icons()[index]); | 98 int icon = controller_->GetIconResourceID( |
| 99 controller_->GetSuggestionAt(index).icon); |
| 97 DCHECK_NE(-1, icon); | 100 DCHECK_NE(-1, icon); |
| 98 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon); | 101 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon); |
| 99 int icon_y = entry_rect.y() + (row_height - image->height()) / 2; | 102 int icon_y = entry_rect.y() + (row_height - image->height()) / 2; |
| 100 | 103 |
| 101 x_align_left += is_rtl ? 0 : -image->width(); | 104 x_align_left += is_rtl ? 0 : -image->width(); |
| 102 | 105 |
| 103 canvas->DrawImageInt(*image, x_align_left, icon_y); | 106 canvas->DrawImageInt(*image, x_align_left, icon_y); |
| 104 | 107 |
| 105 x_align_left += is_rtl ? image->width() + kIconPadding : -kIconPadding; | 108 x_align_left += is_rtl ? image->width() + kIconPadding : -kIconPadding; |
| 106 } | 109 } |
| 107 | 110 |
| 108 // Draw the name text. | 111 // Draw the label text. |
| 109 const int subtext_width = | 112 const int label_width = |
| 110 gfx::GetStringWidth(controller_->subtexts()[index], | 113 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), |
| 111 controller_->subtext_font_list()); | 114 controller_->GetLabelFontList()); |
| 112 if (!is_rtl) | 115 if (!is_rtl) |
| 113 x_align_left -= subtext_width; | 116 x_align_left -= label_width; |
| 114 | 117 |
| 115 canvas->DrawStringRectWithFlags( | 118 canvas->DrawStringRectWithFlags( |
| 116 controller_->subtexts()[index], | 119 controller_->GetElidedLabelAt(index), |
| 117 controller_->subtext_font_list(), | 120 controller_->GetLabelFontList(), |
| 118 kItemTextColor, | 121 kItemTextColor, |
| 119 gfx::Rect(x_align_left, | 122 gfx::Rect(x_align_left, |
| 120 entry_rect.y(), | 123 entry_rect.y(), |
| 121 subtext_width, | 124 label_width, |
| 122 entry_rect.height()), | 125 entry_rect.height()), |
| 123 gfx::Canvas::TEXT_ALIGN_CENTER); | 126 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 124 } | 127 } |
| 125 | 128 |
| 126 AutofillPopupView* AutofillPopupView::Create( | 129 AutofillPopupView* AutofillPopupView::Create( |
| 127 AutofillPopupController* controller) { | 130 AutofillPopupController* controller) { |
| 128 views::Widget* observing_widget = | 131 views::Widget* observing_widget = |
| 129 views::Widget::GetTopLevelWidgetForNativeView( | 132 views::Widget::GetTopLevelWidgetForNativeView( |
| 130 controller->container_view()); | 133 controller->container_view()); |
| 131 | 134 |
| 132 // If the top level widget can't be found, cancel the popup since we can't | 135 // If the top level widget can't be found, cancel the popup since we can't |
| 133 // fully set it up. | 136 // fully set it up. |
| 134 if (!observing_widget) | 137 if (!observing_widget) |
| 135 return NULL; | 138 return NULL; |
| 136 | 139 |
| 137 return new AutofillPopupViewViews(controller, observing_widget); | 140 return new AutofillPopupViewViews(controller, observing_widget); |
| 138 } | 141 } |
| 139 | 142 |
| 140 } // namespace autofill | 143 } // namespace autofill |
| OLD | NEW |