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_VIEWS_AUTOFILL_POPUP_VIEW_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_VIEWS_AUTOFILL_POPUP_VIEW_H_
|
2017-05-19 19:35:13 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/autofill_popup.h"
|
2017-05-19 19:35:13 +00:00
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2017-05-19 19:35:13 +00:00
|
|
|
#include "content/public/browser/native_web_keyboard_event.h"
|
|
|
|
#include "content/public/browser/render_widget_host.h"
|
2018-10-01 20:00:53 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2021-06-03 08:05:04 +00:00
|
|
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
2017-05-19 19:35:13 +00:00
|
|
|
#include "ui/accessibility/ax_node_data.h"
|
|
|
|
#include "ui/views/drag_controller.h"
|
|
|
|
#include "ui/views/focus/widget_focus_manager.h"
|
|
|
|
#include "ui/views/widget/widget_delegate.h"
|
|
|
|
#include "ui/views/widget/widget_observer.h"
|
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/osr/osr_view_proxy.h"
|
2018-10-01 20:00:53 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
const int kPopupBorderThickness = 1;
|
|
|
|
const int kSmallerFontSizeDelta = -1;
|
|
|
|
const int kEndPadding = 8;
|
|
|
|
const int kNamePadding = 15;
|
|
|
|
const int kRowHeight = 24;
|
|
|
|
|
|
|
|
class AutofillPopup;
|
|
|
|
|
|
|
|
// Child view only for triggering accessibility events. Rendering is handled
|
|
|
|
// by |AutofillPopupViewViews|.
|
|
|
|
class AutofillPopupChildView : public views::View {
|
|
|
|
public:
|
2021-03-16 16:18:45 +00:00
|
|
|
explicit AutofillPopupChildView(const std::u16string& suggestion)
|
2017-05-19 19:35:13 +00:00
|
|
|
: suggestion_(suggestion) {
|
|
|
|
SetFocusBehavior(FocusBehavior::ALWAYS);
|
|
|
|
}
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
AutofillPopupChildView(const AutofillPopupChildView&) = delete;
|
|
|
|
AutofillPopupChildView& operator=(const AutofillPopupChildView&) = delete;
|
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
private:
|
|
|
|
~AutofillPopupChildView() override {}
|
|
|
|
|
|
|
|
// views::Views implementation
|
2018-04-17 23:47:47 +00:00
|
|
|
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
|
2017-05-19 19:35:13 +00:00
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string suggestion_;
|
2017-05-19 19:35:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AutofillPopupView : public views::WidgetDelegateView,
|
|
|
|
public views::WidgetFocusChangeListener,
|
|
|
|
public views::WidgetObserver,
|
|
|
|
public views::DragController {
|
|
|
|
public:
|
|
|
|
explicit AutofillPopupView(AutofillPopup* popup,
|
|
|
|
views::Widget* parent_widget);
|
|
|
|
~AutofillPopupView() override;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
void Show();
|
|
|
|
void Hide();
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
void OnSuggestionsChanged();
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
int GetSelectedLine() { return selected_line_.value_or(-1); }
|
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
void WriteDragDataForView(views::View*,
|
|
|
|
const gfx::Point&,
|
2018-04-17 23:47:47 +00:00
|
|
|
ui::OSExchangeData*) override;
|
|
|
|
int GetDragOperationsForView(views::View*, const gfx::Point&) override;
|
2018-04-18 01:44:10 +00:00
|
|
|
bool CanStartDragForView(views::View*,
|
|
|
|
const gfx::Point&,
|
2018-04-17 23:47:47 +00:00
|
|
|
const gfx::Point&) override;
|
2017-05-19 19:35:13 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-21 17:55:19 +00:00
|
|
|
friend class AutofillPopup;
|
|
|
|
|
2021-06-03 08:05:04 +00:00
|
|
|
void OnSelectedRowChanged(absl::optional<int> previous_row_selection,
|
|
|
|
absl::optional<int> current_row_selection);
|
2017-05-19 19:35:13 +00:00
|
|
|
|
|
|
|
// Draw the given autofill entry in |entry_rect|.
|
|
|
|
void DrawAutofillEntry(gfx::Canvas* canvas,
|
|
|
|
int index,
|
|
|
|
const gfx::Rect& entry_rect);
|
|
|
|
|
|
|
|
// Creates child views based on the suggestions given by |controller_|. These
|
|
|
|
// child views are used for accessibility events only. We need child views to
|
|
|
|
// populate the correct |AXNodeData| when user selects a suggestion.
|
|
|
|
void CreateChildViews();
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
void DoUpdateBoundsAndRedrawPopup();
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
// views::Views implementation.
|
|
|
|
void OnPaint(gfx::Canvas* canvas) override;
|
|
|
|
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
|
|
|
|
void OnMouseCaptureLost() override;
|
|
|
|
bool OnMouseDragged(const ui::MouseEvent& event) override;
|
|
|
|
void OnMouseExited(const ui::MouseEvent& event) override;
|
|
|
|
void OnMouseMoved(const ui::MouseEvent& event) override;
|
|
|
|
bool OnMousePressed(const ui::MouseEvent& event) override;
|
|
|
|
void OnMouseReleased(const ui::MouseEvent& event) override;
|
|
|
|
void OnGestureEvent(ui::GestureEvent* event) override;
|
|
|
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
|
|
|
bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event);
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
// views::WidgetFocusChangeListener implementation.
|
|
|
|
void OnNativeFocusChanged(gfx::NativeView focused_now) override;
|
|
|
|
|
|
|
|
// views::WidgetObserver implementation.
|
|
|
|
void OnWidgetBoundsChanged(views::Widget* widget,
|
|
|
|
const gfx::Rect& new_bounds) override;
|
|
|
|
|
|
|
|
void AcceptSuggestion(int index);
|
|
|
|
bool AcceptSelectedLine();
|
|
|
|
void AcceptSelection(const gfx::Point& point);
|
2021-06-03 08:05:04 +00:00
|
|
|
void SetSelectedLine(absl::optional<int> selected_line);
|
2017-05-19 19:35:13 +00:00
|
|
|
void SetSelection(const gfx::Point& point);
|
|
|
|
void SelectNextLine();
|
|
|
|
void SelectPreviousLine();
|
|
|
|
void ClearSelection();
|
|
|
|
|
|
|
|
// Stop observing the widget.
|
|
|
|
void RemoveObserver();
|
|
|
|
|
|
|
|
// Controller for this popup. Weak reference.
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<AutofillPopup> popup_;
|
2017-05-19 19:35:13 +00:00
|
|
|
|
|
|
|
// The widget of the window that triggered this popup. Weak reference.
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<views::Widget> parent_widget_;
|
2017-05-19 19:35:13 +00:00
|
|
|
|
|
|
|
// The time when the popup was shown.
|
|
|
|
base::Time show_time_;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
// The index of the currently selected line
|
2021-06-03 08:05:04 +00:00
|
|
|
absl::optional<int> selected_line_;
|
2017-05-19 19:52:18 +00:00
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2017-05-21 17:55:19 +00:00
|
|
|
std::unique_ptr<OffscreenViewProxy> view_proxy_;
|
2017-06-26 09:13:05 +00:00
|
|
|
#endif
|
2017-05-21 17:55:19 +00:00
|
|
|
|
2017-05-19 19:35:13 +00:00
|
|
|
// The registered keypress callback, responsible for switching lines on
|
|
|
|
// key presses
|
|
|
|
content::RenderWidgetHost::KeyPressEventCallback keypress_callback_;
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<AutofillPopupView> weak_ptr_factory_{this};
|
2017-05-19 19:35:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_VIEWS_AUTOFILL_POPUP_VIEW_H_
|