Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datalist element support #9535

Merged
merged 8 commits into from May 29, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Expand Up @@ -17,6 +17,7 @@
#include "atom/browser/child_web_contents_tracker.h"
#include "atom/browser/lib/bluetooth_chooser.h"
#include "atom/browser/native_window.h"
#include "atom/browser/native_window_views.h"
#include "atom/browser/net/atom_network_delegate.h"
#include "atom/browser/osr/osr_output_device.h"
#include "atom/browser/osr/osr_render_widget_host_view.h"
Expand Down Expand Up @@ -83,6 +84,7 @@
#include "third_party/WebKit/public/web/WebFindOptions.h"
#include "ui/display/screen.h"
#include "ui/events/base_event_utils.h"
#include "ui/gfx/geometry/rect_f.h"

#if !defined(OS_MACOSX)
#include "ui/aura/window.h"
Expand Down Expand Up @@ -441,6 +443,8 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate,
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
content::Source<content::NavigationController>(controller));

autofill_popup_ = new AutofillPopup(web_contents->GetNativeView());

Init(isolate);
AttachAsUserData(web_contents);
}
Expand Down Expand Up @@ -740,6 +744,17 @@ void WebContents::RenderViewCreated(content::RenderViewHost* render_view_host) {
impl->disable_hidden_ = !background_throttling_;
}

void WebContents::RenderFrameCreated(content::RenderFrameHost* host) {
Send(new AtomAutofillViewHostMsg_RoutingId(
host->GetRoutingID(), routing_id()));
}

void WebContents::RenderFrameHostChanged(content::RenderFrameHost* old_host,
content::RenderFrameHost* new_host) {
Send(new AtomAutofillViewHostMsg_RoutingId(
new_host->GetRoutingID(), routing_id()));
}

void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
Emit("render-view-deleted", render_view_host->GetProcess()->GetID());
}
Expand Down Expand Up @@ -976,6 +991,8 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
OnGetZoomLevel)
IPC_MESSAGE_HANDLER_CODE(ViewHostMsg_SetCursor, OnCursorChange,
handled = false)
IPC_MESSAGE_HANDLER(AtomAutofillViewMsg_ShowPopup, OnShowAutofillPopup)
IPC_MESSAGE_HANDLER(AtomAutofillViewMsg_HidePopup, OnHideAutofillPopup)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()

Expand Down Expand Up @@ -1608,6 +1625,25 @@ void WebContents::OnCursorChange(const content::WebCursor& cursor) {
}
}

void WebContents::OnShowAutofillPopup(
int routing_id,
const gfx::RectF& bounds,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels) {
auto relay = reinterpret_cast<NativeWindowViews*>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebContents should not handle GUI related code, autofill_popup_ and its related code should be moved to NativeWindow instead.

NativeWindow::FromWebContents(web_contents()));
autofill_popup_->CreateView(
routing_id,
web_contents(),
IsOffScreen() || (embedder_ && embedder_->IsOffScreen()),
relay->widget(),
bounds);
autofill_popup_->SetItems(values, labels);
}
void WebContents::OnHideAutofillPopup() {
autofill_popup_->Hide();
}

void WebContents::SetSize(const SetSizeParams& params) {
if (guest_delegate_)
guest_delegate_->SetSize(params);
Expand Down
11 changes: 11 additions & 0 deletions atom/browser/api/atom_api_web_contents.h
Expand Up @@ -12,6 +12,7 @@
#include "atom/browser/api/save_page_handler.h"
#include "atom/browser/api/trackable_object.h"
#include "atom/browser/common_web_contents_delegate.h"
#include "atom/browser/ui/autofill_popup.h"
#include "content/common/cursors/webcursor.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
Expand Down Expand Up @@ -307,6 +308,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
// content::WebContentsObserver:
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
void RenderViewCreated(content::RenderViewHost*) override;
void RenderFrameCreated(content::RenderFrameHost*) override;
void RenderFrameHostChanged(content::RenderFrameHost*,
content::RenderFrameHost*) override;
void RenderViewDeleted(content::RenderViewHost*) override;
void RenderProcessGone(base::TerminationStatus status) override;
void DocumentLoadedInFrame(
Expand Down Expand Up @@ -374,6 +378,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
// Called when we receive a CursorChange message from chromium.
void OnCursorChange(const content::WebCursor& cursor);

void OnShowAutofillPopup(int routing_id,
const gfx::RectF& bounds,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels);
void OnHideAutofillPopup();

// Called when received a message from renderer.
void OnRendererMessage(const base::string16& channel,
const base::ListValue& args);
Expand All @@ -397,6 +407,7 @@ class WebContents : public mate::TrackableObject<WebContents>,

std::unique_ptr<AtomJavaScriptDialogManager> dialog_manager_;
std::unique_ptr<WebViewGuestDelegate> guest_delegate_;
AutofillPopup* autofill_popup_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be leaked? It can be managed with std::unique_ptr.


// The host webcontents that may contain this webcontents.
WebContents* embedder_;
Expand Down
8 changes: 4 additions & 4 deletions atom/browser/native_window.cc
Expand Up @@ -251,7 +251,7 @@ void NativeWindow::SetSizeConstraints(
SetContentSizeConstraints(content_constraints);
}

extensions::SizeConstraints NativeWindow::GetSizeConstraints() {
extensions::SizeConstraints NativeWindow::GetSizeConstraints() const {
extensions::SizeConstraints content_constraints = GetContentSizeConstraints();
extensions::SizeConstraints window_constraints;
if (content_constraints.HasMaximumSize()) {
Expand All @@ -272,7 +272,7 @@ void NativeWindow::SetContentSizeConstraints(
size_constraints_ = size_constraints;
}

extensions::SizeConstraints NativeWindow::GetContentSizeConstraints() {
extensions::SizeConstraints NativeWindow::GetContentSizeConstraints() const {
return size_constraints_;
}

Expand All @@ -282,7 +282,7 @@ void NativeWindow::SetMinimumSize(const gfx::Size& size) {
SetSizeConstraints(size_constraints);
}

gfx::Size NativeWindow::GetMinimumSize() {
gfx::Size NativeWindow::GetMinimumSize() const {
return GetSizeConstraints().GetMinimumSize();
}

Expand All @@ -292,7 +292,7 @@ void NativeWindow::SetMaximumSize(const gfx::Size& size) {
SetSizeConstraints(size_constraints);
}

gfx::Size NativeWindow::GetMaximumSize() {
gfx::Size NativeWindow::GetMaximumSize() const {
return GetSizeConstraints().GetMaximumSize();
}

Expand Down
20 changes: 11 additions & 9 deletions atom/browser/native_window.h
Expand Up @@ -98,14 +98,14 @@ class NativeWindow : public base::SupportsUserData,
virtual gfx::Rect GetContentBounds();
virtual void SetSizeConstraints(
const extensions::SizeConstraints& size_constraints);
virtual extensions::SizeConstraints GetSizeConstraints();
virtual extensions::SizeConstraints GetSizeConstraints() const;
virtual void SetContentSizeConstraints(
const extensions::SizeConstraints& size_constraints);
virtual extensions::SizeConstraints GetContentSizeConstraints();
virtual extensions::SizeConstraints GetContentSizeConstraints() const;
virtual void SetMinimumSize(const gfx::Size& size);
virtual gfx::Size GetMinimumSize();
virtual gfx::Size GetMinimumSize() const;
virtual void SetMaximumSize(const gfx::Size& size);
virtual gfx::Size GetMaximumSize();
virtual gfx::Size GetMaximumSize() const;
virtual void SetSheetOffset(const double offsetX, const double offsetY);
virtual double GetSheetOffsetX();
virtual double GetSheetOffsetY();
Expand Down Expand Up @@ -147,9 +147,9 @@ class NativeWindow : public base::SupportsUserData,
virtual void SetMenu(AtomMenuModel* menu);
virtual void SetParentWindow(NativeWindow* parent);
virtual void SetBrowserView(NativeBrowserView* browser_view) = 0;
virtual gfx::NativeView GetNativeView() = 0;
virtual gfx::NativeWindow GetNativeWindow() = 0;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
virtual gfx::NativeView GetNativeView() const = 0;
virtual gfx::NativeWindow GetNativeWindow() const = 0;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;

// Taskbar/Dock APIs.
enum ProgressState {
Expand Down Expand Up @@ -281,8 +281,10 @@ class NativeWindow : public base::SupportsUserData,
const std::vector<DraggableRegion>& regions);

// Converts between content bounds and window bounds.
virtual gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) = 0;
virtual gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) = 0;
virtual gfx::Rect ContentBoundsToWindowBounds(
const gfx::Rect& bounds) const = 0;
virtual gfx::Rect WindowBoundsToContentBounds(
const gfx::Rect& bounds) const = 0;

// Called when the window needs to update its draggable region.
virtual void UpdateDraggableRegions(
Expand Down
10 changes: 5 additions & 5 deletions atom/browser/native_window_mac.h
Expand Up @@ -89,9 +89,9 @@ class NativeWindowMac : public NativeWindow,
void SetContentProtection(bool enable) override;
void SetBrowserView(NativeBrowserView* browser_view) override;
void SetParentWindow(NativeWindow* parent) override;
gfx::NativeView GetNativeView() override;
gfx::NativeWindow GetNativeWindow() override;
gfx::AcceleratedWidget GetAcceleratedWidget() override;
gfx::NativeView GetNativeView() const override;
gfx::NativeWindow GetNativeWindow() const override;
gfx::AcceleratedWidget GetAcceleratedWidget() const override;
void SetProgressBar(double progress, const ProgressState state) override;
void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) override;
Expand Down Expand Up @@ -140,8 +140,8 @@ class NativeWindowMac : public NativeWindow,

private:
// NativeWindow:
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds);
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds);
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const;
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const;
void UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) override;

Expand Down
10 changes: 5 additions & 5 deletions atom/browser/native_window_mac.mm
Expand Up @@ -1314,15 +1314,15 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
[parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove];
}

gfx::NativeView NativeWindowMac::GetNativeView() {
gfx::NativeView NativeWindowMac::GetNativeView() const {
return inspectable_web_contents()->GetView()->GetNativeView();
}

gfx::NativeWindow NativeWindowMac::GetNativeWindow() {
gfx::NativeWindow NativeWindowMac::GetNativeWindow() const {
return window_;
}

gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() {
gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() const {
return inspectable_web_contents()->GetView()->GetNativeView();
}

Expand Down Expand Up @@ -1498,7 +1498,7 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
}

gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
const gfx::Rect& bounds) {
const gfx::Rect& bounds) const {
if (has_frame()) {
gfx::Rect window_bounds(
[window_ frameRectForContentRect:bounds.ToCGRect()]);
Expand All @@ -1511,7 +1511,7 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
}

gfx::Rect NativeWindowMac::WindowBoundsToContentBounds(
const gfx::Rect& bounds) {
const gfx::Rect& bounds) const {
if (has_frame()) {
gfx::Rect content_bounds(
[window_ contentRectForFrameRect:bounds.ToCGRect()]);
Expand Down
14 changes: 7 additions & 7 deletions atom/browser/native_window_views.cc
Expand Up @@ -924,11 +924,11 @@ void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
#endif
}

gfx::NativeView NativeWindowViews::GetNativeView() {
gfx::NativeView NativeWindowViews::GetNativeView() const {
return window_->GetNativeView();
}

gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
gfx::NativeWindow NativeWindowViews::GetNativeWindow() const {
return window_->GetNativeWindow();
}

Expand Down Expand Up @@ -999,7 +999,7 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
return false;
}

gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() const {
return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
}

Expand Down Expand Up @@ -1180,7 +1180,7 @@ void NativeWindowViews::OnWidgetMove() {
}

gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
const gfx::Rect& bounds) {
const gfx::Rect& bounds) const {
if (!has_frame())
return bounds;

Expand All @@ -1201,7 +1201,7 @@ gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
}

gfx::Rect NativeWindowViews::WindowBoundsToContentBounds(
const gfx::Rect& bounds) {
const gfx::Rect& bounds) const {
if (!has_frame())
return bounds;

Expand Down Expand Up @@ -1306,11 +1306,11 @@ void NativeWindowViews::Layout() {
}
}

gfx::Size NativeWindowViews::GetMinimumSize() {
gfx::Size NativeWindowViews::GetMinimumSize() const {
return NativeWindow::GetMinimumSize();
}

gfx::Size NativeWindowViews::GetMaximumSize() {
gfx::Size NativeWindowViews::GetMaximumSize() const {
return NativeWindow::GetMaximumSize();
}

Expand Down
14 changes: 7 additions & 7 deletions atom/browser/native_window_views.h
Expand Up @@ -106,8 +106,8 @@ class NativeWindowViews : public NativeWindow,
void SetMenu(AtomMenuModel* menu_model) override;
void SetBrowserView(NativeBrowserView* browser_view) override;
void SetParentWindow(NativeWindow* parent) override;
gfx::NativeView GetNativeView() override;
gfx::NativeWindow GetNativeWindow() override;
gfx::NativeView GetNativeView() const override;
gfx::NativeWindow GetNativeWindow() const override;
void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) override;
void SetProgressBar(double progress, const ProgressState state) override;
Expand All @@ -118,7 +118,7 @@ class NativeWindowViews : public NativeWindow,
void SetVisibleOnAllWorkspaces(bool visible) override;
bool IsVisibleOnAllWorkspaces() override;

gfx::AcceleratedWidget GetAcceleratedWidget() override;
gfx::AcceleratedWidget GetAcceleratedWidget() const override;

#if defined(OS_WIN)
void SetIcon(HICON small_icon, HICON app_icon);
Expand Down Expand Up @@ -171,16 +171,16 @@ class NativeWindowViews : public NativeWindow,
#endif

// NativeWindow:
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) override;
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) override;
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
void HandleKeyboardEvent(
content::WebContents*,
const content::NativeWebKeyboardEvent& event) override;

// views::View:
void Layout() override;
gfx::Size GetMinimumSize() override;
gfx::Size GetMaximumSize() override;
gfx::Size GetMinimumSize() const override;
gfx::Size GetMaximumSize() const override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;

// Register accelerators supported by the menu model.
Expand Down