| 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 "components/autofill/core/browser/suggestion.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/events/keycodes/keyboard_codes.h" | 11 #include "ui/events/keycodes/keyboard_codes.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/gfx/text_utils.h" | 17 #include "ui/gfx/text_utils.h" |
| 18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 namespace autofill { | 21 namespace autofill { |
| 22 | 22 |
| 23 AutofillPopupViewViews::AutofillPopupViewViews( | 23 AutofillPopupViewViews::AutofillPopupViewViews( |
| 24 AutofillPopupController* controller, | 24 AutofillPopupController* controller, |
| 25 views::Widget* parent_widget) | 25 views::Widget* parent_widget) |
| 26 : AutofillPopupBaseView(controller, parent_widget), | 26 : AutofillPopupBaseView(controller, parent_widget), |
| 27 view_helper_(new AutofillPopupViewHelper(controller)), |
| 27 controller_(controller) {} | 28 controller_(controller) {} |
| 28 | 29 |
| 29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | 30 AutofillPopupViewViews::~AutofillPopupViewViews() {} |
| 30 | 31 |
| 31 void AutofillPopupViewViews::Show() { | 32 void AutofillPopupViewViews::Show() { |
| 32 DoShow(); | 33 DoShow(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 void AutofillPopupViewViews::Hide() { | 36 void AutofillPopupViewViews::Hide() { |
| 36 // The controller is no longer valid after it hides us. | 37 // The controller is no longer valid after it hides us. |
| 37 controller_ = NULL; | 38 controller_ = NULL; |
| 38 | 39 |
| 39 DoHide(); | 40 DoHide(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 43 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
| 43 DoUpdateBoundsAndRedrawPopup(); | 44 DoUpdateBoundsAndRedrawPopup(); |
| 44 } | 45 } |
| 45 | 46 |
| 47 void AutofillPopupViewViews::UpdatePopupBounds() { |
| 48 view_helper_->UpdatePopupBounds(); |
| 49 } |
| 50 |
| 51 int AutofillPopupViewViews::GetAvailableWidthForRow(int row, bool with_label) { |
| 52 return view_helper_->GetAvailableWidthForRow(row, with_label); |
| 53 } |
| 54 |
| 55 int AutofillPopupViewViews::LineFromY(int y) { |
| 56 return view_helper_->LineFromY(y); |
| 57 } |
| 58 |
| 59 gfx::Rect AutofillPopupViewViews::GetPopupBounds() { |
| 60 return view_helper_->popup_bounds(); |
| 61 } |
| 62 |
| 46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 63 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| 47 if (!controller_) | 64 if (!controller_) |
| 48 return; | 65 return; |
| 49 | 66 |
| 50 canvas->DrawColor(kPopupBackground); | 67 canvas->DrawColor(kPopupBackground); |
| 51 OnPaintBorder(canvas); | 68 OnPaintBorder(canvas); |
| 52 | 69 |
| 53 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | 70 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
| 54 gfx::Rect line_rect = controller_->GetRowBounds(i); | 71 gfx::Rect line_rect = view_helper_->GetRowBounds(i); |
| 55 | 72 |
| 56 if (controller_->GetSuggestionAt(i).frontend_id == | 73 if (controller_->GetSuggestionAt(i).frontend_id == |
| 57 POPUP_ITEM_ID_SEPARATOR) { | 74 POPUP_ITEM_ID_SEPARATOR) { |
| 58 canvas->FillRect(line_rect, kItemTextColor); | 75 canvas->FillRect(line_rect, kItemTextColor); |
| 59 } else { | 76 } else { |
| 60 DrawAutofillEntry(canvas, i, line_rect); | 77 DrawAutofillEntry(canvas, i, line_rect); |
| 61 } | 78 } |
| 62 } | 79 } |
| 63 } | 80 } |
| 64 | 81 |
| 65 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 82 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| 66 SchedulePaintInRect(controller_->GetRowBounds(row)); | 83 SchedulePaintInRect(view_helper_->GetRowBounds(row)); |
| 67 } | 84 } |
| 68 | 85 |
| 69 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, | 86 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| 70 int index, | 87 int index, |
| 71 const gfx::Rect& entry_rect) { | 88 const gfx::Rect& entry_rect) { |
| 72 if (controller_->selected_line() == index) | 89 if (controller_->selected_line() == index) |
| 73 canvas->FillRect(entry_rect, kHoveredBackgroundColor); | 90 canvas->FillRect(entry_rect, kHoveredBackgroundColor); |
| 74 | 91 |
| 75 const bool is_rtl = controller_->IsRTL(); | 92 const bool is_rtl = controller_->IsRTL(); |
| 76 const int text_align = | 93 const int text_align = |
| 77 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; | 94 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; |
| 78 gfx::Rect value_rect = entry_rect; | 95 gfx::Rect value_rect = entry_rect; |
| 79 value_rect.Inset(kEndPadding, 0); | 96 value_rect.Inset(kEndPadding, 0); |
| 80 canvas->DrawStringRectWithFlags( | 97 canvas->DrawStringRectWithFlags( |
| 81 controller_->GetElidedValueAt(index), | 98 controller_->GetElidedValueAt(index), |
| 82 controller_->GetValueFontListForRow(index), | 99 controller_->GetValueFontListForRow(index), |
| 83 controller_->IsWarning(index) ? kWarningTextColor : kValueTextColor, | 100 controller_->IsWarning(index) ? kWarningTextColor : kValueTextColor, |
| 84 value_rect, text_align); | 101 value_rect, text_align); |
| 85 | 102 |
| 86 // Use this to figure out where all the other Autofill items should be placed. | 103 // Use this to figure out where all the other Autofill items should be placed. |
| 87 int x_align_left = is_rtl ? kEndPadding : entry_rect.right() - kEndPadding; | 104 int x_align_left = is_rtl ? kEndPadding : entry_rect.right() - kEndPadding; |
| 88 | 105 |
| 89 // Draw the Autofill icon, if one exists | 106 // Draw the Autofill icon, if one exists |
| 90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 107 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 91 int row_height = controller_->GetRowBounds(index).height(); | 108 int row_height = view_helper_->GetRowBounds(index).height(); |
| 92 if (!controller_->GetSuggestionAt(index).icon.empty()) { | 109 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 93 int icon = controller_->GetIconResourceID( | 110 int icon = view_helper_->GetIconResourceID( |
| 94 controller_->GetSuggestionAt(index).icon); | 111 controller_->GetSuggestionAt(index).icon); |
| 95 DCHECK_NE(-1, icon); | 112 DCHECK_NE(-1, icon); |
| 96 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon); | 113 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon); |
| 97 int icon_y = entry_rect.y() + (row_height - image->height()) / 2; | 114 int icon_y = entry_rect.y() + (row_height - image->height()) / 2; |
| 98 | 115 |
| 99 x_align_left += is_rtl ? 0 : -image->width(); | 116 x_align_left += is_rtl ? 0 : -image->width(); |
| 100 | 117 |
| 101 canvas->DrawImageInt(*image, x_align_left, icon_y); | 118 canvas->DrawImageInt(*image, x_align_left, icon_y); |
| 102 | 119 |
| 103 x_align_left += is_rtl ? image->width() + kIconPadding : -kIconPadding; | 120 x_align_left += is_rtl ? image->width() + kIconPadding : -kIconPadding; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 125 | 142 |
| 126 // If the top level widget can't be found, cancel the popup since we can't | 143 // If the top level widget can't be found, cancel the popup since we can't |
| 127 // fully set it up. | 144 // fully set it up. |
| 128 if (!observing_widget) | 145 if (!observing_widget) |
| 129 return NULL; | 146 return NULL; |
| 130 | 147 |
| 131 return new AutofillPopupViewViews(controller, observing_widget); | 148 return new AutofillPopupViewViews(controller, observing_widget); |
| 132 } | 149 } |
| 133 | 150 |
| 134 } // namespace autofill | 151 } // namespace autofill |
| OLD | NEW |