2017-05-19 19:35:13 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_AUTOFILL_POPUP_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_AUTOFILL_POPUP_H_
|
2017-05-19 19:35:13 +00:00
|
|
|
|
2017-05-19 19:52:18 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2017-05-26 01:38:27 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/views/autofill_popup_view.h"
|
2022-02-25 18:17:35 +00:00
|
|
|
#include "ui/color/color_id.h"
|
2017-05-19 19:35:13 +00:00
|
|
|
#include "ui/gfx/font_list.h"
|
2017-11-02 23:25:59 +00:00
|
|
|
#include "ui/views/view.h"
|
2017-11-02 23:42:30 +00:00
|
|
|
#include "ui/views/widget/widget.h"
|
2017-05-19 19:35:13 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class AutofillPopupView;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2018-04-05 00:53:51 +00:00
|
|
|
class AutofillPopup : public views::ViewObserver {
|
2017-05-19 19:35:13 +00:00
|
|
|
public:
|
2018-04-05 00:53:51 +00:00
|
|
|
AutofillPopup();
|
2018-04-17 23:03:51 +00:00
|
|
|
~AutofillPopup() override;
|
2017-05-19 19:35:13 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
AutofillPopup(const AutofillPopup&) = delete;
|
|
|
|
AutofillPopup& operator=(const AutofillPopup&) = delete;
|
|
|
|
|
2017-05-26 01:38:27 +00:00
|
|
|
void CreateView(content::RenderFrameHost* render_frame,
|
2018-06-18 15:15:37 +00:00
|
|
|
content::RenderFrameHost* embedder_frame,
|
2018-04-05 00:53:51 +00:00
|
|
|
bool offscreen,
|
|
|
|
views::View* parent,
|
|
|
|
const gfx::RectF& bounds);
|
2017-05-19 19:35:13 +00:00
|
|
|
void Hide();
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
void SetItems(const std::vector<std::u16string>& values,
|
|
|
|
const std::vector<std::u16string>& labels);
|
2018-04-05 00:53:51 +00:00
|
|
|
void UpdatePopupBounds();
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
gfx::Rect popup_bounds_in_view();
|
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
private:
|
|
|
|
friend class AutofillPopupView;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2018-04-05 00:53:51 +00:00
|
|
|
// views::ViewObserver:
|
|
|
|
void OnViewBoundsChanged(views::View* view) override;
|
|
|
|
void OnViewIsDeleting(views::View* view) override;
|
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
void AcceptSuggestion(int index);
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
int GetDesiredPopupHeight();
|
|
|
|
int GetDesiredPopupWidth();
|
|
|
|
gfx::Rect GetRowBounds(int i);
|
|
|
|
const gfx::FontList& GetValueFontListForRow(int index) const;
|
|
|
|
const gfx::FontList& GetLabelFontListForRow(int index) const;
|
2022-02-25 18:17:35 +00:00
|
|
|
ui::ColorId GetBackgroundColorIDForRow(int index) const;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2024-02-09 09:29:14 +00:00
|
|
|
int line_count() const { return values_.size(); }
|
|
|
|
const std::u16string& value_at(int i) const { return values_.at(i); }
|
|
|
|
const std::u16string& label_at(int i) const { return labels_.at(i); }
|
2017-05-19 19:35:13 +00:00
|
|
|
int LineFromY(int y) const;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
int selected_index_;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
// Popup location
|
|
|
|
gfx::Rect popup_bounds_;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
// Bounds of the autofilled element
|
|
|
|
gfx::Rect element_bounds_;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
// Datalist suggestions
|
2021-03-16 16:18:45 +00:00
|
|
|
std::vector<std::u16string> values_;
|
|
|
|
std::vector<std::u16string> labels_;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
// Font lists for the suggestions
|
|
|
|
gfx::FontList smaller_font_list_;
|
|
|
|
gfx::FontList bold_font_list_;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
|
|
|
// For sending the accepted suggestion to the render frame that
|
2017-05-19 19:35:13 +00:00
|
|
|
// asked to open the popup
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<content::RenderFrameHost> frame_host_ = nullptr;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-26 01:38:27 +00:00
|
|
|
// The popup view. The lifetime is managed by the owning Widget
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<AutofillPopupView> view_ = nullptr;
|
2018-04-05 00:53:51 +00:00
|
|
|
|
|
|
|
// The parent view that the popup view shows on. Weak ref.
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<views::View> parent_ = nullptr;
|
2017-05-19 19:35:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_AUTOFILL_POPUP_H_
|