| 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 AutofillPopupView(controller), |
| 27 controller_(controller) {} | 28 controller_(controller) {} |
| 28 | 29 |
| 29 AutofillPopupViewViews::~AutofillPopupViewViews() {} | |
| 30 | |
| 31 void AutofillPopupViewViews::Show() { | 30 void AutofillPopupViewViews::Show() { |
| 32 DoShow(); | 31 DoShow(); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void AutofillPopupViewViews::Hide() { | 34 void AutofillPopupViewViews::Hide() { |
| 36 // The controller is no longer valid after it hides us. | 35 // The controller is no longer valid after it hides us. |
| 37 controller_ = NULL; | 36 controller_ = NULL; |
| 38 | 37 |
| 39 DoHide(); | 38 DoHide(); |
| 40 } | 39 } |
| 41 | 40 |
| 42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 41 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
| 43 DoUpdateBoundsAndRedrawPopup(); | 42 DoUpdateBoundsAndRedrawPopup(); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 45 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
| 47 if (!controller_) | 46 if (!controller_) |
| 48 return; | 47 return; |
| 49 | 48 |
| 50 canvas->DrawColor(kPopupBackground); | 49 canvas->DrawColor(kPopupBackground); |
| 51 OnPaintBorder(canvas); | 50 OnPaintBorder(canvas); |
| 52 | 51 |
| 53 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | 52 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
| 54 gfx::Rect line_rect = controller_->GetRowBounds(i); | 53 gfx::Rect line_rect = GetRowBounds(i); |
| 55 | 54 |
| 56 if (controller_->GetSuggestionAt(i).frontend_id == | 55 if (controller_->GetSuggestionAt(i).frontend_id == |
| 57 POPUP_ITEM_ID_SEPARATOR) { | 56 POPUP_ITEM_ID_SEPARATOR) { |
| 58 canvas->FillRect(line_rect, kItemTextColor); | 57 canvas->FillRect(line_rect, kItemTextColor); |
| 59 } else { | 58 } else { |
| 60 DrawAutofillEntry(canvas, i, line_rect); | 59 DrawAutofillEntry(canvas, i, line_rect); |
| 61 } | 60 } |
| 62 } | 61 } |
| 63 } | 62 } |
| 64 | 63 |
| 65 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 64 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
| 66 SchedulePaintInRect(controller_->GetRowBounds(row)); | 65 SchedulePaintInRect(GetRowBounds(row)); |
| 67 } | 66 } |
| 68 | 67 |
| 69 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, | 68 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| 70 int index, | 69 int index, |
| 71 const gfx::Rect& entry_rect) { | 70 const gfx::Rect& entry_rect) { |
| 72 if (controller_->selected_line() == index) | 71 if (controller_->selected_line() == index) |
| 73 canvas->FillRect(entry_rect, kHoveredBackgroundColor); | 72 canvas->FillRect(entry_rect, kHoveredBackgroundColor); |
| 74 | 73 |
| 75 const bool is_rtl = controller_->IsRTL(); | 74 const bool is_rtl = controller_->IsRTL(); |
| 76 const int text_align = | 75 const int text_align = |
| 77 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; | 76 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; |
| 78 gfx::Rect value_rect = entry_rect; | 77 gfx::Rect value_rect = entry_rect; |
| 79 value_rect.Inset(kEndPadding, 0); | 78 value_rect.Inset(kEndPadding, 0); |
| 80 canvas->DrawStringRectWithFlags( | 79 canvas->DrawStringRectWithFlags( |
| 81 controller_->GetElidedValueAt(index), | 80 controller_->GetElidedValueAt(index), |
| 82 controller_->GetValueFontListForRow(index), | 81 controller_->GetValueFontListForRow(index), |
| 83 controller_->IsWarning(index) ? kWarningTextColor : kValueTextColor, | 82 controller_->IsWarning(index) ? kWarningTextColor : kValueTextColor, |
| 84 value_rect, text_align); | 83 value_rect, text_align); |
| 85 | 84 |
| 86 // Use this to figure out where all the other Autofill items should be placed. | 85 // 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; | 86 int x_align_left = is_rtl ? kEndPadding : entry_rect.right() - kEndPadding; |
| 88 | 87 |
| 89 // Draw the Autofill icon, if one exists | 88 // Draw the Autofill icon, if one exists |
| 90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 91 int row_height = controller_->GetRowBounds(index).height(); | 90 int row_height = GetRowBounds(index).height(); |
| 92 if (!controller_->GetSuggestionAt(index).icon.empty()) { | 91 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 93 int icon = controller_->GetIconResourceID( | 92 int icon = GetIconResourceID(controller_->GetSuggestionAt(index).icon); |
| 94 controller_->GetSuggestionAt(index).icon); | |
| 95 DCHECK_NE(-1, icon); | 93 DCHECK_NE(-1, icon); |
| 96 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon); | 94 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon); |
| 97 int icon_y = entry_rect.y() + (row_height - image->height()) / 2; | 95 int icon_y = entry_rect.y() + (row_height - image->height()) / 2; |
| 98 | 96 |
| 99 x_align_left += is_rtl ? 0 : -image->width(); | 97 x_align_left += is_rtl ? 0 : -image->width(); |
| 100 | 98 |
| 101 canvas->DrawImageInt(*image, x_align_left, icon_y); | 99 canvas->DrawImageInt(*image, x_align_left, icon_y); |
| 102 | 100 |
| 103 x_align_left += is_rtl ? image->width() + kIconPadding : -kIconPadding; | 101 x_align_left += is_rtl ? image->width() + kIconPadding : -kIconPadding; |
| 104 } | 102 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 125 | 123 |
| 126 // If the top level widget can't be found, cancel the popup since we can't | 124 // If the top level widget can't be found, cancel the popup since we can't |
| 127 // fully set it up. | 125 // fully set it up. |
| 128 if (!observing_widget) | 126 if (!observing_widget) |
| 129 return NULL; | 127 return NULL; |
| 130 | 128 |
| 131 return new AutofillPopupViewViews(controller, observing_widget); | 129 return new AutofillPopupViewViews(controller, observing_widget); |
| 132 } | 130 } |
| 133 | 131 |
| 134 } // namespace autofill | 132 } // namespace autofill |
| OLD | NEW |