diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 0aa55312f458..96178cbfdc93 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1035,8 +1035,19 @@ void WebContents::ShowAutofillPopup(content::RenderFrameHost* frame_host, const std::vector& values, const std::vector& labels) { bool offscreen = IsOffScreen() || (embedder_ && embedder_->IsOffScreen()); - CommonWebContentsDelegate::ShowAutofillPopup(offscreen, frame_host, bounds, - values, labels); + gfx::RectF popup_bounds(bounds); + 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 diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index a977e1667dc3..132162124689 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -92,8 +92,9 @@ class CommonWebContentsDelegate // Autofill related events. #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX) - void ShowAutofillPopup(bool offscreen, - content::RenderFrameHost* frame_host, + void ShowAutofillPopup(content::RenderFrameHost* frame_host, + content::RenderFrameHost* embedder_frame_host, + bool offscreen, const gfx::RectF& bounds, const std::vector& values, const std::vector& labels); diff --git a/atom/browser/common_web_contents_delegate_views.cc b/atom/browser/common_web_contents_delegate_views.cc index e81a455d6789..0c7c6a6846d1 100644 --- a/atom/browser/common_web_contents_delegate_views.cc +++ b/atom/browser/common_web_contents_delegate_views.cc @@ -4,6 +4,7 @@ #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 "base/strings/string_util.h" #include "content/public/browser/native_web_keyboard_event.h" @@ -28,8 +29,9 @@ void CommonWebContentsDelegate::HandleKeyboardEvent( } void CommonWebContentsDelegate::ShowAutofillPopup( - bool offscreen, content::RenderFrameHost* frame_host, + content::RenderFrameHost* embedder_frame_host, + bool offscreen, const gfx::RectF& bounds, const std::vector& values, const std::vector& labels) { @@ -37,8 +39,8 @@ void CommonWebContentsDelegate::ShowAutofillPopup( return; auto* window = static_cast(owner_window()); - autofill_popup_->CreateView(frame_host, offscreen, window->content_view(), - bounds); + autofill_popup_->CreateView(frame_host, embedder_frame_host, offscreen, + window->content_view(), bounds); autofill_popup_->SetItems(values, labels); } diff --git a/atom/browser/ui/autofill_popup.cc b/atom/browser/ui/autofill_popup.cc index 89b6213a49eb..89815723c759 100644 --- a/atom/browser/ui/autofill_popup.cc +++ b/atom/browser/ui/autofill_popup.cc @@ -115,6 +115,7 @@ AutofillPopup::~AutofillPopup() { } void AutofillPopup::CreateView(content::RenderFrameHost* frame_host, + content::RenderFrameHost* embedder_frame_host, bool offscreen, views::View* parent, const gfx::RectF& r) { @@ -123,6 +124,12 @@ void AutofillPopup::CreateView(content::RenderFrameHost* frame_host, frame_host_ = frame_host; 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_->AddObserver(this); @@ -131,8 +138,12 @@ void AutofillPopup::CreateView(content::RenderFrameHost* frame_host, #if defined(ENABLE_OSR) if (offscreen) { - auto* osr_rwhv = - static_cast(frame_host_->GetView()); + auto* rwhv = frame_host->GetView(); + if (embedder_frame_host != nullptr) { + rwhv = embedder_frame_host->GetView(); + } + + auto* osr_rwhv = static_cast(rwhv); view_->view_proxy_.reset(new OffscreenViewProxy(view_)); osr_rwhv->AddViewProxy(view_->view_proxy_.get()); } diff --git a/atom/browser/ui/autofill_popup.h b/atom/browser/ui/autofill_popup.h index d0fbf08068f8..5eace0b00ae3 100644 --- a/atom/browser/ui/autofill_popup.h +++ b/atom/browser/ui/autofill_popup.h @@ -24,6 +24,7 @@ class AutofillPopup : public views::ViewObserver { ~AutofillPopup() override; void CreateView(content::RenderFrameHost* render_frame, + content::RenderFrameHost* embedder_frame, bool offscreen, views::View* parent, const gfx::RectF& bounds);