c3b4cd987c
* chore: bump chromium in DEPS to 126.0.6470.0
* 5492605: Migrate TODOs referencing old crbug IDs to the new issue tracker IDs | https://chromium-review.googlesource.com/c/chromium/src/+/5492605
* 5513277: Move subresource-filter-ruleset to GCS | https://chromium-review.googlesource.com/c/chromium/src/+/5513277
* 5512656: Remove CustomizeChromeSupportsChromeRefresh2023 | https://chromium-review.googlesource.com/c/chromium/src/+/5512656
* 5516009: Accept mouse events in inactive window for Top Chrome WebUIs | https://chromium-review.googlesource.com/c/chromium/src/+/5516009
* 5376861: Change references to RWHVB in RWHIER and RenderWidgetTargeter to RWHVI. | https://chromium-review.googlesource.com/c/chromium/src/+/5376861
* 5490530: Use partition_alloc PA_BUILDFLAG(...) outside PA. #cleanup | https://chromium-review.googlesource.com/c/chromium/src/+/5490530
* 5296870: network: Allow trusted loaders to learn the sent request cookies. | https://chromium-review.googlesource.com/c/chromium/src/+/5296870
* 5453438: Delegate delegated ink trails to RWHI from RWHIER. | https://chromium-review.googlesource.com/c/chromium/src/+/5453438
* chore: update patches
* chore: bump chromium in DEPS to 126.0.6472.0
* chore: bump chromium in DEPS to 126.0.6474.0
* chore: update patches
* chore: bump chromium in DEPS to 126.0.6476.0
* chore: bump chromium in DEPS to 126.0.6478.0
* chore: bump chromium in DEPS to 126.0.6478.3
* chore: bump chromium in DEPS to 126.0.6478.8
* update patches
* only disable enterprise_cloud_content_analysis
* 5403888: [api] support v8::Data in v8::TracedReference and v8::EmbedderGraph
https://chromium-review.googlesource.com/c/v8/v8/+/5403888
* chore: bump chromium in DEPS to 127.0.6484.0
* chore: bump chromium in DEPS to 127.0.6485.0
* 5539004: Use NOTREACHED_IN_MIGRATION() in remaining chrome/ | https://chromium-review.googlesource.com/c/chromium/src/+/5539004
* src: cast to v8::Value before using v8::EmbedderGraph::V8Node | https://github.com/nodejs/node/pull/52638/files
* chore: update patches
* chore: update v8 patches
* chore: bump chromium in DEPS to 127.0.6486.0
* chore: bump chromium in DEPS to 127.0.6488.0
* chore: bump chromium in DEPS to 127.0.6490.0
* chore: bump chromium in DEPS to 127.0.6492.0
* chore: update patches
For some reason, `feat_expose_raw_response_headers_from_urlloader.patch` got messed up in an earlier commit.
* chore: update patches
printing.patch was updated due to https://chromium-review.googlesource.com/c/chromium/src/+/5535938
* 5527572: Move Connectors prefs files to components/enterprise/connectors/
https://chromium-review.googlesource.com/c/chromium/src/+/5527572
* chore: bump chromium in DEPS to 127.0.6494.0
* chore: bump chromium in DEPS to 127.0.6495.0
* chore: bump chromium in DEPS to 127.0.6496.0
* 5465511: [api] Mark v8::ObjectTemplate::SetAccessor(..) for deprecation
https://chromium-review.googlesource.com/c/v8/v8/+/5465511
* chore: revert v8 deprecation
See patch message for more details.
https://chromium-review.googlesource.com/c/v8/v8/+/5526611
* chore: update patches
* 5538771: Remove srcdoc else-if block in CalculateOrigin()
https://chromium-review.googlesource.com/c/chromium/src/+/5538771
* 5522321: [devtools] Support saving base64 encoded files via host bindings
https://chromium-review.googlesource.com/c/chromium/src/+/5522321
* 5376861: Change references to RWHVB in RWHIER and RenderWidgetTargeter to RWHVI.
https://chromium-review.googlesource.com/c/chromium/src/+/5376861
* 5530163: [media] Use VideoFrame::Plane typed enum instead of nameless enum
https://chromium-review.googlesource.com/c/chromium/src/+/5530163
* 5463431: iwa: Only create IsolatedWebAppURLLoaderFactory for subresources in IWAs
https://chromium-review.googlesource.com/c/chromium/src/+/5463431
* fixup! 5465511: [api] Mark v8::ObjectTemplate::SetAccessor(..) for deprecation https://chromium-review.googlesource.com/c/v8/v8/+/5465511
* 5512176: Remove OnEnvironmentEstimationComplete()
https://chromium-review.googlesource.com/c/chromium/src/+/5512176
* 5528282: Move Web Speech API .mojom files to //media/mojo/mojom
https://chromium-review.googlesource.com/c/chromium/src/+/5528282
* 5513740: Reland "[Extensions] Restructure extensions::ProcessMap"
https://chromium-review.googlesource.com/c/chromium/src/+/5513740
* 5483406: [PEPC] Make PEPC permission subscription take into account device status
https://chromium-review.googlesource.com/c/chromium/src/+/5483406
* 5526034: [DoH] Remove kDnsOverHttps feature flag
https://chromium-review.googlesource.com/c/chromium/src/+/5526034
The title is a bit misleading. They removed handling for the feature flag and generally intend to remove it but haven't yet.
I only changed our code to address the flag that was removed. A quick search on GitHub for `DnsOverHttpsFallback` yielded a few results, but they were all C++ chromium code or patches, 0 app code or discussion results. Since I couldn't find any evidence of this flag being used in developer applications, I've chosen to exclude this change from the breaking changes docs.
* chore: revert v8 removal
https://chromium-review.googlesource.com/c/v8/v8/+/5497515
See patch message for more details.
* chore: cherry-pick Node.js patch for V8 API removal fix
Node.js PR: https://github.com/nodejs/node/pull/52996
V8 API Removal CL: https://chromium-review.googlesource.com/c/v8/v8/+/5539888
See the patch description for more details.
* 5492183: Extensions: CodeHealth: Give enums some class
https://chromium-review.googlesource.com/c/chromium/src/+/5492183
* fixup! 5528282: Move Web Speech API .mojom files to //media/mojo/mojom https://chromium-review.googlesource.com/c/chromium/src/+/5528282
* 5514687: Reland "Add a secret handshake to the base::Feature constructor"
https://chromium-review.googlesource.com/c/chromium/src/+/5514687
* fixup! 5530163: [media] Use VideoFrame::Plane typed enum instead of nameless enum https://chromium-review.googlesource.com/c/chromium/src/+/5530163
* 5466238: PDF Viewer: add metrics to record if PDF is opened with a11y
https://chromium-review.googlesource.com/c/chromium/src/+/5466238
* 5502081: Migrate OnDisplayRemoved to OnDisplaysRemoved
https://chromium-review.googlesource.com/c/chromium/src/+/5502081
* 5539888: [api] Remove several APIs deprecated in version 12.6
https://chromium-review.googlesource.com/c/v8/v8/+/5539888
This commit essentially only removes the `only_terminate_in_safe_scope` isolate creation parameter. This undoes some work that was originally done in #35766.
* 5498236: Make browser_tests force full async initialization for OSCrypt Async
https://chromium-review.googlesource.com/c/chromium/src/+/5498236
* fixup! 5528282: Move Web Speech API .mojom files to //media/mojo/mojom https://chromium-review.googlesource.com/c/chromium/src/+/5528282
* 5545807: Migrate most remaining NOTREACHED()
https://chromium-review.googlesource.com/c/chromium/src/+/5545807
I took a systematic approach to modifying all of our uses of `NOTREACHED` that were causing errors:
* If there was a `return` or `break` (etc.) immediately after `NOTREACHED`, I removed the control flow instruction and left the `NOTREACHED` unmodified
* All other instances were migrated to `NOTREACHED_IN_MIGRATION`
We should revisit pretty much all usage of `NOTREACHED` as an upgrade follow-up item.
* fixup! 5526034: [DoH] Remove kDnsOverHttps feature flag https://chromium-review.googlesource.com/c/chromium/src/+/5526034
Turns out the feature flags were removed in the `.cc` file, but not the
`.h` feature list file. This means that the feature flags are pretty
much officially gone. (The leftover symbols in the header are likely an
oversight from what I can gather.)
We may potentially decide to put this in the breaking changes doc if we
decide this feature flag is important enough to highlight.
* chore: bump chromium in DEPS to 127.0.6498.3
* chore: bump chromium in DEPS to 127.0.6500.0
* chore: bump chromium in DEPS to 127.0.6502.0
* chore: bump chromium in DEPS to 127.0.6504.0
* chore: bump chromium in DEPS to 127.0.6505.0
* chore: bump chromium in DEPS to 127.0.6508.0
* build: use Sha256Sum in script/sysroots.json
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5506275
* chore: update chore_add_electron_deps_to_gitignores.patch
Xref: no manual changes; patch applied with fuzz 2
* chore: update feat_allow_code_cache_in_custom_schemes.patch
Xref: no manual changes; patch applied with fuzz 1
* chore: e patches all
* fixup! build: use Sha256Sum in script/sysroots.json
`sync` succeeds now
* chore: replace absl::optional with std::optional
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5253843
* chore: update CalculatePreferredSize() to new upstream semantics
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5459174
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5541220
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5514708
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5504212
Xref: https://chromium-review.googlesource.com/516542
* chore: replace absl::optional with std::optional
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5296147
* chore: add kPip to enumeration as a no-op
https://chromium-review.googlesource.com/c/chromium/src/+/5546257
* [Autofill] Remove RenderFrame::ElementBoundsInWindow()
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5553982
* chore: fix feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch
need new header to pick up definition of BLINK_PLATFORM_EXPORT macro
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5463143
* chore: bump chromium in DEPS to 127.0.6510.0
* chore: update patches
* chore: fix include path for native_web_keyboard_event.h
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5541976
* chore: add currently-unused should_include_device_status arg to GetPermissionStatusForCurrentDocument()
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5545382
* chore: bump chromium in DEPS to 127.0.6512.0
* chore: update mas_avoid_private_macos_api_usage.patch.patch
No manual changes; patch applied with fuzz 1
* chore: update feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch
No manual changes; patch applied with fuzz 1
* chore: update webview_fullscreen.patch
No manual changes; patch applied with fuzz 1
* chore=: remove cherry-pick-22db6918bac9.patch
already present upstream
* chore: remove nonexistent patchfiles from .patches
* chore: remove cherry-pick-3e037e195e50.patch
no longer needed; merged upstream
* Update namespace for files moved to //components/input
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5563251
* Require client for InitParams to always specify an ownership mode.
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5532482
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5578714
* chore: e patches all
* fixup! Update namespace for files moved to //components/input
* chore: remove profile_keyed_service_factory, profile_selections from chromium_src
already being linked in via chrome browser for printing
* chore: bump chromium in DEPS to 127.0.6515.0
* chore: bump chromium in DEPS to 127.0.6516.0
* chore: update render_widget_host_view_base.patch
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5547803
patch applied manually due to simple upstream shear
* chore: update feat_allow_code_cache_in_custom_schemes.patch
No manual changes; patch applied with fuzz 1
* chore: e patches all
* Pull RWHIER and RWT to //content/common/input.
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5397681
* chore: bump chromium in DEPS to 127.0.6517.0
* chore: update patches
* fixup: Update namespace for files moved to //components/input
* Remove 0-arg (default) constructor for views::Widget::InitParams.
https://chromium-review.googlesource.com/c/chromium/src/+/5578714
* fixup: only disable enterprise_cloud_content_analysis
The original commit a5480accc2
, was due to this CL 5527572: Move Connectors prefs files to components/enterprise/connectors/ | https://chromium-review.googlesource.com/c/chromium/src/+/5527572
* chore: bump chromium in DEPS to 127.0.6519.0
* chore: update patches
* src: do not use deprecated V8 API
https://github.com/nodejs/node/pull/53084
* src: remove dependency on wrapper-descriptor-based cpp heap
https://github.com/nodejs/node/pull/53086
* 5344413: [DevTools] Add `getHostConfig` UI binding for sending status of `base::Features` to DevTools
https://chromium-review.googlesource.com/c/chromium/src/+/5344413
* 5585788: Extensions: ManifestHandler: Separate Registry like ExtensionRegistry
https://chromium-review.googlesource.com/c/chromium/src/+/5585788
* chore: update filenames.libcxx.gni
* 5506857: Reland "Migrate clang-format to gcs first class deps"
https://chromium-review.googlesource.com/c/chromium/src/+/5506857
* fixup: 5539888: [api] Remove several APIs deprecated in version 12.6
* fixup: 5506857: Reland Migrate clang-format to gcs first class deps
* chore: bump chromium in DEPS to 127.0.6521.0
* chore: update patches
* spec: update navigator.keyboard should lock the keyboard
* Block or allow all MIDI using the existing SysEx permission
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5154368
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5499157
* spec: update test/parallel/test-v8-stats
* views: remove CalculatePreferredSize()
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5504212
* chore: update patches after rebase
* 5560288: Re-enable ChromeOS XNNPack on Intel only
https://chromium-review.googlesource.com/c/chromium/src/+/5560288
* chore: add nan patches for v8 changes
Refs
5539888: [api] Remove several APIs deprecated in version 12.6 | https://chromium-review.googlesource.com/c/v8/v8/+/5539888
and
5539852: [heap][api] Remove deprecated v8::Isolate::IdleNotificationDeadline | https://chromium-review.googlesource.com/c/v8/v8/+/5539852
* 5573603: Modularize //chrome/browser/themes
https://chromium-review.googlesource.com/c/chromium/src/+/5573603
* 5539888: [api] Remove several APIs deprecated in version 12.6
https://chromium-review.googlesource.com/c/v8/v8/+/5539888
* chore: update patches
* test: fixup navigator.keyboard.lock on Windows
* chore: remove unneeded profile target
---------
Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Keeley Hammond <khammond@slack-corp.com>
Co-authored-by: VerteDinde <vertedinde@electronjs.org>
Co-authored-by: Jeremy Rose <nornagon@nornagon.net>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
489 lines
14 KiB
C++
489 lines
14 KiB
C++
// 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.
|
|
|
|
#include "shell/browser/ui/views/autofill_popup_view.h"
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
#include "base/functional/bind.h"
|
|
#include "base/i18n/rtl.h"
|
|
#include "cc/paint/skia_paint_canvas.h"
|
|
#include "content/public/browser/render_view_host.h"
|
|
#include "ui/accessibility/ax_enums.mojom.h"
|
|
#include "ui/base/dragdrop/drag_drop_types.h"
|
|
#include "ui/color/color_provider.h"
|
|
#include "ui/events/keycodes/keyboard_codes.h"
|
|
#include "ui/gfx/canvas.h"
|
|
#include "ui/gfx/geometry/point.h"
|
|
#include "ui/gfx/geometry/rect.h"
|
|
#include "ui/gfx/text_utils.h"
|
|
#include "ui/views/border.h"
|
|
#include "ui/views/focus/focus_manager.h"
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
namespace electron {
|
|
|
|
void AutofillPopupChildView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
|
|
node_data->role = ax::mojom::Role::kMenuItem;
|
|
node_data->SetName(suggestion_);
|
|
}
|
|
|
|
BEGIN_METADATA(AutofillPopupChildView)
|
|
END_METADATA
|
|
|
|
AutofillPopupView::AutofillPopupView(AutofillPopup* popup,
|
|
views::Widget* parent_widget)
|
|
: popup_(popup), parent_widget_(parent_widget) {
|
|
CreateChildViews();
|
|
SetFocusBehavior(FocusBehavior::ALWAYS);
|
|
set_drag_controller(this);
|
|
}
|
|
|
|
AutofillPopupView::~AutofillPopupView() {
|
|
if (popup_) {
|
|
auto* host = popup_->frame_host_->GetRenderViewHost()->GetWidget();
|
|
host->RemoveKeyPressEventCallback(keypress_callback_);
|
|
popup_->view_ = nullptr;
|
|
popup_ = nullptr;
|
|
}
|
|
|
|
RemoveObserver();
|
|
|
|
if (view_proxy_.get()) {
|
|
view_proxy_->ResetView();
|
|
}
|
|
|
|
if (GetWidget()) {
|
|
GetWidget()->Close();
|
|
}
|
|
}
|
|
|
|
void AutofillPopupView::Show() {
|
|
bool visible = parent_widget_->IsVisible();
|
|
visible = visible || view_proxy_;
|
|
if (!popup_ || !visible || parent_widget_->IsClosed())
|
|
return;
|
|
|
|
const bool initialize_widget = !GetWidget();
|
|
if (initialize_widget) {
|
|
parent_widget_->AddObserver(this);
|
|
|
|
// The widget is destroyed by the corresponding NativeWidget, so we use
|
|
// a weak pointer to hold the reference and don't have to worry about
|
|
// deletion.
|
|
auto* widget = new views::Widget;
|
|
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
|
|
params.delegate = this;
|
|
params.parent = parent_widget_->GetNativeView();
|
|
params.z_order = ui::ZOrderLevel::kFloatingUIElement;
|
|
widget->Init(std::move(params));
|
|
|
|
// No animation for popup appearance (too distracting).
|
|
widget->SetVisibilityAnimationTransition(views::Widget::ANIMATE_HIDE);
|
|
|
|
show_time_ = base::Time::Now();
|
|
}
|
|
|
|
SetBorder(views::CreateSolidBorder(
|
|
kPopupBorderThickness,
|
|
GetColorProvider()->GetColor(ui::kColorUnfocusedBorder)));
|
|
|
|
DoUpdateBoundsAndRedrawPopup();
|
|
GetWidget()->Show();
|
|
|
|
if (initialize_widget)
|
|
views::WidgetFocusManager::GetInstance()->AddFocusChangeListener(this);
|
|
|
|
keypress_callback_ = base::BindRepeating(
|
|
&AutofillPopupView::HandleKeyPressEvent, base::Unretained(this));
|
|
auto* host = popup_->frame_host_->GetRenderViewHost()->GetWidget();
|
|
host->AddKeyPressEventCallback(keypress_callback_);
|
|
|
|
NotifyAccessibilityEvent(ax::mojom::Event::kMenuStart, true);
|
|
}
|
|
|
|
void AutofillPopupView::Hide() {
|
|
if (popup_) {
|
|
auto* host = popup_->frame_host_->GetRenderViewHost()->GetWidget();
|
|
host->RemoveKeyPressEventCallback(keypress_callback_);
|
|
popup_ = nullptr;
|
|
}
|
|
|
|
RemoveObserver();
|
|
NotifyAccessibilityEvent(ax::mojom::Event::kMenuEnd, true);
|
|
|
|
if (GetWidget()) {
|
|
GetWidget()->Close();
|
|
}
|
|
}
|
|
|
|
void AutofillPopupView::OnSuggestionsChanged() {
|
|
if (!popup_)
|
|
return;
|
|
|
|
CreateChildViews();
|
|
if (popup_->line_count() == 0) {
|
|
popup_->Hide();
|
|
return;
|
|
}
|
|
DoUpdateBoundsAndRedrawPopup();
|
|
}
|
|
|
|
void AutofillPopupView::WriteDragDataForView(views::View*,
|
|
const gfx::Point&,
|
|
ui::OSExchangeData*) {}
|
|
|
|
int AutofillPopupView::GetDragOperationsForView(views::View*,
|
|
const gfx::Point&) {
|
|
return ui::DragDropTypes::DRAG_NONE;
|
|
}
|
|
|
|
bool AutofillPopupView::CanStartDragForView(views::View*,
|
|
const gfx::Point&,
|
|
const gfx::Point&) {
|
|
return false;
|
|
}
|
|
|
|
void AutofillPopupView::OnSelectedRowChanged(
|
|
std::optional<int> previous_row_selection,
|
|
std::optional<int> current_row_selection) {
|
|
SchedulePaint();
|
|
|
|
if (current_row_selection) {
|
|
int selected = current_row_selection.value_or(-1);
|
|
if (selected == -1 || static_cast<size_t>(selected) >= children().size())
|
|
return;
|
|
children().at(selected)->NotifyAccessibilityEvent(
|
|
ax::mojom::Event::kSelection, true);
|
|
}
|
|
}
|
|
|
|
void AutofillPopupView::DrawAutofillEntry(gfx::Canvas* canvas,
|
|
int index,
|
|
const gfx::Rect& entry_rect) {
|
|
if (!popup_)
|
|
return;
|
|
|
|
canvas->FillRect(entry_rect, GetColorProvider()->GetColor(
|
|
popup_->GetBackgroundColorIDForRow(index)));
|
|
|
|
const bool is_rtl = base::i18n::IsRTL();
|
|
const int text_align =
|
|
is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT;
|
|
gfx::Rect value_rect = entry_rect;
|
|
value_rect.Inset(gfx::Insets::VH(0, kEndPadding));
|
|
|
|
int x_align_left = value_rect.x();
|
|
const int value_width = gfx::GetStringWidth(
|
|
popup_->value_at(index), popup_->GetValueFontListForRow(index));
|
|
int value_x_align_left = x_align_left;
|
|
value_x_align_left =
|
|
is_rtl ? value_rect.right() - value_width : value_rect.x();
|
|
|
|
canvas->DrawStringRectWithFlags(
|
|
popup_->value_at(index), popup_->GetValueFontListForRow(index),
|
|
GetColorProvider()->GetColor(ui::kColorResultsTableNormalText),
|
|
gfx::Rect(value_x_align_left, value_rect.y(), value_width,
|
|
value_rect.height()),
|
|
text_align);
|
|
|
|
// Draw the label text, if one exists.
|
|
if (auto const& label = popup_->label_at(index); !label.empty()) {
|
|
const int label_width =
|
|
gfx::GetStringWidth(label, popup_->GetLabelFontListForRow(index));
|
|
int label_x_align_left = x_align_left;
|
|
label_x_align_left =
|
|
is_rtl ? value_rect.x() : value_rect.right() - label_width;
|
|
|
|
canvas->DrawStringRectWithFlags(
|
|
label, popup_->GetLabelFontListForRow(index),
|
|
GetColorProvider()->GetColor(ui::kColorResultsTableDimmedText),
|
|
gfx::Rect(label_x_align_left, entry_rect.y(), label_width,
|
|
entry_rect.height()),
|
|
text_align);
|
|
}
|
|
}
|
|
|
|
void AutofillPopupView::CreateChildViews() {
|
|
if (!popup_)
|
|
return;
|
|
|
|
RemoveAllChildViews();
|
|
|
|
for (int i = 0; i < popup_->line_count(); ++i) {
|
|
auto* child_view = new AutofillPopupChildView(popup_->value_at(i));
|
|
child_view->set_drag_controller(this);
|
|
AddChildView(child_view);
|
|
}
|
|
}
|
|
|
|
void AutofillPopupView::DoUpdateBoundsAndRedrawPopup() {
|
|
if (!popup_)
|
|
return;
|
|
|
|
// Clamp popup_bounds_ to ensure it's never zero-width.
|
|
popup_->popup_bounds_.Union(
|
|
gfx::Rect(popup_->popup_bounds_.origin(), gfx::Size(1, 1)));
|
|
GetWidget()->SetBounds(popup_->popup_bounds_);
|
|
if (view_proxy_.get()) {
|
|
view_proxy_->SetBounds(popup_->popup_bounds_in_view());
|
|
}
|
|
SchedulePaint();
|
|
}
|
|
|
|
void AutofillPopupView::OnPaint(gfx::Canvas* canvas) {
|
|
if (!popup_ || static_cast<size_t>(popup_->line_count()) != children().size())
|
|
return;
|
|
gfx::Canvas* draw_canvas = canvas;
|
|
SkBitmap bitmap;
|
|
|
|
std::unique_ptr<cc::SkiaPaintCanvas> paint_canvas;
|
|
if (view_proxy_.get()) {
|
|
bitmap.allocN32Pixels(popup_->popup_bounds_in_view().width(),
|
|
popup_->popup_bounds_in_view().height(), true);
|
|
paint_canvas = std::make_unique<cc::SkiaPaintCanvas>(bitmap);
|
|
draw_canvas = new gfx::Canvas(paint_canvas.get(), 1.0);
|
|
}
|
|
|
|
draw_canvas->DrawColor(
|
|
GetColorProvider()->GetColor(ui::kColorResultsTableNormalBackground));
|
|
OnPaintBorder(draw_canvas);
|
|
|
|
for (int i = 0; i < popup_->line_count(); ++i) {
|
|
gfx::Rect line_rect = popup_->GetRowBounds(i);
|
|
|
|
DrawAutofillEntry(draw_canvas, i, line_rect);
|
|
}
|
|
|
|
if (view_proxy_.get()) {
|
|
view_proxy_->SetBounds(popup_->popup_bounds_in_view());
|
|
view_proxy_->SetBitmap(bitmap);
|
|
}
|
|
}
|
|
|
|
void AutofillPopupView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
|
|
node_data->role = ax::mojom::Role::kMenu;
|
|
node_data->SetName("Autofill Menu");
|
|
}
|
|
|
|
void AutofillPopupView::OnMouseCaptureLost() {
|
|
ClearSelection();
|
|
}
|
|
|
|
bool AutofillPopupView::OnMouseDragged(const ui::MouseEvent& event) {
|
|
if (HitTestPoint(event.location())) {
|
|
SetSelection(event.location());
|
|
|
|
// We must return true in order to get future OnMouseDragged and
|
|
// OnMouseReleased events.
|
|
return true;
|
|
}
|
|
|
|
// If we move off of the popup, we lose the selection.
|
|
ClearSelection();
|
|
return false;
|
|
}
|
|
|
|
void AutofillPopupView::OnMouseExited(const ui::MouseEvent& event) {
|
|
// Pressing return causes the cursor to hide, which will generate an
|
|
// OnMouseExited event. Pressing return should activate the current selection
|
|
// via AcceleratorPressed, so we need to let that run first.
|
|
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
|
|
FROM_HERE, base::BindOnce(&AutofillPopupView::ClearSelection,
|
|
weak_ptr_factory_.GetWeakPtr()));
|
|
}
|
|
|
|
void AutofillPopupView::OnMouseMoved(const ui::MouseEvent& event) {
|
|
// A synthesized mouse move will be sent when the popup is first shown.
|
|
// Don't preview a suggestion if the mouse happens to be hovering there.
|
|
#if BUILDFLAG(IS_WIN)
|
|
if (base::Time::Now() - show_time_ <= base::Milliseconds(50))
|
|
return;
|
|
#else
|
|
if (event.flags() & ui::EF_IS_SYNTHESIZED)
|
|
return;
|
|
#endif
|
|
|
|
if (HitTestPoint(event.location()))
|
|
SetSelection(event.location());
|
|
else
|
|
ClearSelection();
|
|
}
|
|
|
|
bool AutofillPopupView::OnMousePressed(const ui::MouseEvent& event) {
|
|
return event.GetClickCount() == 1;
|
|
}
|
|
|
|
void AutofillPopupView::OnMouseReleased(const ui::MouseEvent& event) {
|
|
// We only care about the left click.
|
|
if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()))
|
|
AcceptSelection(event.location());
|
|
}
|
|
|
|
void AutofillPopupView::OnGestureEvent(ui::GestureEvent* event) {
|
|
switch (event->type()) {
|
|
case ui::ET_GESTURE_TAP_DOWN:
|
|
case ui::ET_GESTURE_SCROLL_BEGIN:
|
|
case ui::ET_GESTURE_SCROLL_UPDATE:
|
|
if (HitTestPoint(event->location()))
|
|
SetSelection(event->location());
|
|
else
|
|
ClearSelection();
|
|
break;
|
|
case ui::ET_GESTURE_TAP:
|
|
case ui::ET_GESTURE_SCROLL_END:
|
|
if (HitTestPoint(event->location()))
|
|
AcceptSelection(event->location());
|
|
else
|
|
ClearSelection();
|
|
break;
|
|
case ui::ET_GESTURE_TAP_CANCEL:
|
|
case ui::ET_SCROLL_FLING_START:
|
|
ClearSelection();
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
event->SetHandled();
|
|
}
|
|
|
|
bool AutofillPopupView::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
|
if (accelerator.modifiers() != ui::EF_NONE)
|
|
return false;
|
|
|
|
if (accelerator.key_code() == ui::VKEY_ESCAPE) {
|
|
if (popup_)
|
|
popup_->Hide();
|
|
return true;
|
|
}
|
|
|
|
if (accelerator.key_code() == ui::VKEY_RETURN)
|
|
return AcceptSelectedLine();
|
|
|
|
return false;
|
|
}
|
|
|
|
bool AutofillPopupView::HandleKeyPressEvent(
|
|
const input::NativeWebKeyboardEvent& event) {
|
|
if (!popup_)
|
|
return false;
|
|
switch (event.windows_key_code) {
|
|
case ui::VKEY_UP:
|
|
SelectPreviousLine();
|
|
return true;
|
|
case ui::VKEY_DOWN:
|
|
SelectNextLine();
|
|
return true;
|
|
case ui::VKEY_PRIOR: // Page up.
|
|
SetSelectedLine(0);
|
|
return true;
|
|
case ui::VKEY_NEXT: // Page down.
|
|
SetSelectedLine(popup_->line_count() - 1);
|
|
return true;
|
|
case ui::VKEY_ESCAPE:
|
|
popup_->Hide();
|
|
return true;
|
|
case ui::VKEY_TAB:
|
|
// A tab press should cause the selected line to be accepted, but still
|
|
// return false so the tab key press propagates and changes the cursor
|
|
// location.
|
|
AcceptSelectedLine();
|
|
return false;
|
|
case ui::VKEY_RETURN:
|
|
return AcceptSelectedLine();
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void AutofillPopupView::OnNativeFocusChanged(gfx::NativeView focused_now) {
|
|
if (GetWidget() && GetWidget()->GetNativeView() != focused_now && popup_)
|
|
popup_->Hide();
|
|
}
|
|
|
|
void AutofillPopupView::OnWidgetBoundsChanged(views::Widget* widget,
|
|
const gfx::Rect& new_bounds) {
|
|
if (widget != parent_widget_)
|
|
return;
|
|
if (popup_)
|
|
popup_->Hide();
|
|
}
|
|
|
|
void AutofillPopupView::AcceptSuggestion(int index) {
|
|
if (!popup_)
|
|
return;
|
|
|
|
popup_->AcceptSuggestion(index);
|
|
popup_->Hide();
|
|
}
|
|
|
|
bool AutofillPopupView::AcceptSelectedLine() {
|
|
if (!selected_line_ || selected_line_.value() >= popup_->line_count())
|
|
return false;
|
|
|
|
AcceptSuggestion(selected_line_.value());
|
|
return true;
|
|
}
|
|
|
|
void AutofillPopupView::AcceptSelection(const gfx::Point& point) {
|
|
if (!popup_)
|
|
return;
|
|
|
|
SetSelectedLine(popup_->LineFromY(point.y()));
|
|
AcceptSelectedLine();
|
|
}
|
|
|
|
void AutofillPopupView::SetSelectedLine(std::optional<int> selected_line) {
|
|
if (!popup_)
|
|
return;
|
|
if (selected_line_ == selected_line)
|
|
return;
|
|
if (selected_line && selected_line.value() >= popup_->line_count())
|
|
return;
|
|
|
|
auto previous_selected_line(selected_line_);
|
|
selected_line_ = selected_line;
|
|
OnSelectedRowChanged(previous_selected_line, selected_line_);
|
|
}
|
|
|
|
void AutofillPopupView::SetSelection(const gfx::Point& point) {
|
|
if (!popup_)
|
|
return;
|
|
|
|
SetSelectedLine(popup_->LineFromY(point.y()));
|
|
}
|
|
|
|
void AutofillPopupView::SelectNextLine() {
|
|
if (!popup_)
|
|
return;
|
|
|
|
int new_selected_line = selected_line_ ? *selected_line_ + 1 : 0;
|
|
if (new_selected_line >= popup_->line_count())
|
|
new_selected_line = 0;
|
|
|
|
SetSelectedLine(new_selected_line);
|
|
}
|
|
|
|
void AutofillPopupView::SelectPreviousLine() {
|
|
if (!popup_)
|
|
return;
|
|
|
|
int new_selected_line = selected_line_.value_or(0) - 1;
|
|
if (new_selected_line < 0)
|
|
new_selected_line = popup_->line_count() - 1;
|
|
|
|
SetSelectedLine(new_selected_line);
|
|
}
|
|
|
|
void AutofillPopupView::ClearSelection() {
|
|
SetSelectedLine(std::nullopt);
|
|
}
|
|
|
|
void AutofillPopupView::RemoveObserver() {
|
|
parent_widget_->RemoveObserver(this);
|
|
views::WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this);
|
|
}
|
|
|
|
} // namespace electron
|