autofill_popup.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_UI_AUTOFILL_POPUP_H_
  5. #define ELECTRON_SHELL_BROWSER_UI_AUTOFILL_POPUP_H_
  6. #include <vector>
  7. #include "base/memory/raw_ptr.h"
  8. #include "content/public/browser/render_frame_host.h"
  9. #include "shell/browser/ui/views/autofill_popup_view.h"
  10. #include "ui/color/color_id.h"
  11. #include "ui/gfx/font_list.h"
  12. #include "ui/views/view.h"
  13. #include "ui/views/widget/widget.h"
  14. namespace electron {
  15. class AutofillPopupView;
  16. class AutofillPopup : public views::ViewObserver {
  17. public:
  18. AutofillPopup();
  19. ~AutofillPopup() override;
  20. // disable copy
  21. AutofillPopup(const AutofillPopup&) = delete;
  22. AutofillPopup& operator=(const AutofillPopup&) = delete;
  23. void CreateView(content::RenderFrameHost* render_frame,
  24. content::RenderFrameHost* embedder_frame,
  25. bool offscreen,
  26. views::View* parent,
  27. const gfx::RectF& bounds);
  28. void Hide();
  29. void SetItems(const std::vector<std::u16string>& values,
  30. const std::vector<std::u16string>& labels);
  31. void UpdatePopupBounds();
  32. gfx::Rect popup_bounds_in_view();
  33. private:
  34. friend class AutofillPopupView;
  35. // views::ViewObserver:
  36. void OnViewBoundsChanged(views::View* view) override;
  37. void OnViewIsDeleting(views::View* view) override;
  38. void AcceptSuggestion(int index);
  39. int GetDesiredPopupHeight();
  40. int GetDesiredPopupWidth();
  41. gfx::Rect GetRowBounds(int i);
  42. const gfx::FontList& GetValueFontListForRow(int index) const;
  43. const gfx::FontList& GetLabelFontListForRow(int index) const;
  44. ui::ColorId GetBackgroundColorIDForRow(int index) const;
  45. int line_count() const { return values_.size(); }
  46. const std::u16string& value_at(int i) const { return values_.at(i); }
  47. const std::u16string& label_at(int i) const { return labels_.at(i); }
  48. int LineFromY(int y) const;
  49. int selected_index_;
  50. // Popup location
  51. gfx::Rect popup_bounds_;
  52. // Bounds of the autofilled element
  53. gfx::Rect element_bounds_;
  54. // Datalist suggestions
  55. std::vector<std::u16string> values_;
  56. std::vector<std::u16string> labels_;
  57. // Font lists for the suggestions
  58. gfx::FontList smaller_font_list_;
  59. gfx::FontList bold_font_list_;
  60. // For sending the accepted suggestion to the render frame that
  61. // asked to open the popup
  62. raw_ptr<content::RenderFrameHost> frame_host_ = nullptr;
  63. // The popup view. The lifetime is managed by the owning Widget
  64. raw_ptr<AutofillPopupView> view_ = nullptr;
  65. // The parent view that the popup view shows on. Weak ref.
  66. raw_ptr<views::View> parent_ = nullptr;
  67. };
  68. } // namespace electron
  69. #endif // ELECTRON_SHELL_BROWSER_UI_AUTOFILL_POPUP_H_