Fix autofill popup position when the popup is spawned from a webview (#13184)
This commit is contained in:
parent
fe94bf7c1d
commit
90911a423a
5 changed files with 35 additions and 9 deletions
|
@ -1035,8 +1035,19 @@ void WebContents::ShowAutofillPopup(content::RenderFrameHost* frame_host,
|
||||||
const std::vector<base::string16>& values,
|
const std::vector<base::string16>& values,
|
||||||
const std::vector<base::string16>& labels) {
|
const std::vector<base::string16>& labels) {
|
||||||
bool offscreen = IsOffScreen() || (embedder_ && embedder_->IsOffScreen());
|
bool offscreen = IsOffScreen() || (embedder_ && embedder_->IsOffScreen());
|
||||||
CommonWebContentsDelegate::ShowAutofillPopup(offscreen, frame_host, bounds,
|
gfx::RectF popup_bounds(bounds);
|
||||||
values, labels);
|
content::RenderFrameHost* embedder_frame_host = nullptr;
|
||||||
|
if (embedder_) {
|
||||||
|
auto* embedder_view = embedder_->web_contents()->GetMainFrame()->GetView();
|
||||||
|
auto* view = web_contents()->GetMainFrame()->GetView();
|
||||||
|
auto offset = view->GetViewBounds().origin() -
|
||||||
|
embedder_view->GetViewBounds().origin();
|
||||||
|
popup_bounds.Offset(offset.x(), offset.y());
|
||||||
|
embedder_frame_host = embedder_->web_contents()->GetMainFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
CommonWebContentsDelegate::ShowAutofillPopup(
|
||||||
|
frame_host, embedder_frame_host, offscreen, popup_bounds, values, labels);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -92,8 +92,9 @@ class CommonWebContentsDelegate
|
||||||
|
|
||||||
// Autofill related events.
|
// Autofill related events.
|
||||||
#if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
|
#if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX)
|
||||||
void ShowAutofillPopup(bool offscreen,
|
void ShowAutofillPopup(content::RenderFrameHost* frame_host,
|
||||||
content::RenderFrameHost* frame_host,
|
content::RenderFrameHost* embedder_frame_host,
|
||||||
|
bool offscreen,
|
||||||
const gfx::RectF& bounds,
|
const gfx::RectF& bounds,
|
||||||
const std::vector<base::string16>& values,
|
const std::vector<base::string16>& values,
|
||||||
const std::vector<base::string16>& labels);
|
const std::vector<base::string16>& labels);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "atom/browser/common_web_contents_delegate.h"
|
#include "atom/browser/common_web_contents_delegate.h"
|
||||||
|
|
||||||
|
#include "atom/browser/api/atom_api_web_contents_view.h"
|
||||||
#include "atom/browser/native_window_views.h"
|
#include "atom/browser/native_window_views.h"
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "content/public/browser/native_web_keyboard_event.h"
|
#include "content/public/browser/native_web_keyboard_event.h"
|
||||||
|
@ -28,8 +29,9 @@ void CommonWebContentsDelegate::HandleKeyboardEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommonWebContentsDelegate::ShowAutofillPopup(
|
void CommonWebContentsDelegate::ShowAutofillPopup(
|
||||||
bool offscreen,
|
|
||||||
content::RenderFrameHost* frame_host,
|
content::RenderFrameHost* frame_host,
|
||||||
|
content::RenderFrameHost* embedder_frame_host,
|
||||||
|
bool offscreen,
|
||||||
const gfx::RectF& bounds,
|
const gfx::RectF& bounds,
|
||||||
const std::vector<base::string16>& values,
|
const std::vector<base::string16>& values,
|
||||||
const std::vector<base::string16>& labels) {
|
const std::vector<base::string16>& labels) {
|
||||||
|
@ -37,8 +39,8 @@ void CommonWebContentsDelegate::ShowAutofillPopup(
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto* window = static_cast<NativeWindowViews*>(owner_window());
|
auto* window = static_cast<NativeWindowViews*>(owner_window());
|
||||||
autofill_popup_->CreateView(frame_host, offscreen, window->content_view(),
|
autofill_popup_->CreateView(frame_host, embedder_frame_host, offscreen,
|
||||||
bounds);
|
window->content_view(), bounds);
|
||||||
autofill_popup_->SetItems(values, labels);
|
autofill_popup_->SetItems(values, labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,7 @@ AutofillPopup::~AutofillPopup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutofillPopup::CreateView(content::RenderFrameHost* frame_host,
|
void AutofillPopup::CreateView(content::RenderFrameHost* frame_host,
|
||||||
|
content::RenderFrameHost* embedder_frame_host,
|
||||||
bool offscreen,
|
bool offscreen,
|
||||||
views::View* parent,
|
views::View* parent,
|
||||||
const gfx::RectF& r) {
|
const gfx::RectF& r) {
|
||||||
|
@ -123,6 +124,12 @@ void AutofillPopup::CreateView(content::RenderFrameHost* frame_host,
|
||||||
frame_host_ = frame_host;
|
frame_host_ = frame_host;
|
||||||
element_bounds_ = gfx::ToEnclosedRect(r);
|
element_bounds_ = gfx::ToEnclosedRect(r);
|
||||||
|
|
||||||
|
gfx::Vector2d height_offset(0, element_bounds_.height());
|
||||||
|
popup_bounds_in_view_ = element_bounds_ + height_offset;
|
||||||
|
gfx::Point menu_position(element_bounds_.origin() + height_offset);
|
||||||
|
views::View::ConvertPointToScreen(parent, &menu_position);
|
||||||
|
popup_bounds_ = gfx::Rect(menu_position, element_bounds_.size());
|
||||||
|
|
||||||
parent_ = parent;
|
parent_ = parent;
|
||||||
parent_->AddObserver(this);
|
parent_->AddObserver(this);
|
||||||
|
|
||||||
|
@ -131,8 +138,12 @@ void AutofillPopup::CreateView(content::RenderFrameHost* frame_host,
|
||||||
|
|
||||||
#if defined(ENABLE_OSR)
|
#if defined(ENABLE_OSR)
|
||||||
if (offscreen) {
|
if (offscreen) {
|
||||||
auto* osr_rwhv =
|
auto* rwhv = frame_host->GetView();
|
||||||
static_cast<OffScreenRenderWidgetHostView*>(frame_host_->GetView());
|
if (embedder_frame_host != nullptr) {
|
||||||
|
rwhv = embedder_frame_host->GetView();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(rwhv);
|
||||||
view_->view_proxy_.reset(new OffscreenViewProxy(view_));
|
view_->view_proxy_.reset(new OffscreenViewProxy(view_));
|
||||||
osr_rwhv->AddViewProxy(view_->view_proxy_.get());
|
osr_rwhv->AddViewProxy(view_->view_proxy_.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ class AutofillPopup : public views::ViewObserver {
|
||||||
~AutofillPopup() override;
|
~AutofillPopup() override;
|
||||||
|
|
||||||
void CreateView(content::RenderFrameHost* render_frame,
|
void CreateView(content::RenderFrameHost* render_frame,
|
||||||
|
content::RenderFrameHost* embedder_frame,
|
||||||
bool offscreen,
|
bool offscreen,
|
||||||
views::View* parent,
|
views::View* parent,
|
||||||
const gfx::RectF& bounds);
|
const gfx::RectF& bounds);
|
||||||
|
|
Loading…
Add table
Reference in a new issue