From 46c9c06b3ae8e90e1118bfc672a20de965951879 Mon Sep 17 00:00:00 2001 From: Youngsoo Choi Date: Fri, 18 Sep 2015 10:48:04 +0900 Subject: [PATCH] Implement initial native window This implements initial native window. Original CL: http://suprem.sec.samsung.net/gerrit/#/c/48867 This implements initial native webview. Change-Id: I79283c5aff50b65c477f7f696507e42b01c947b6 Signed-off-by: Youngsoo Choi --- atom/app/atom_main.cc | 9 ++ atom/browser/atom_browser_main_parts.cc | 10 +++ atom/browser/native_window.h | 6 +- atom/browser/native_window_efl.cc | 100 +++++++++++++++------ atom/browser/native_window_efl.h | 23 ++++- atom/browser/ui/accelerator_util_efl.cc | 4 +- efl/build/system.gyp | 17 ++++ electron.gyp | 2 + .../browser/inspectable_web_contents_impl.cc | 5 -- .../browser/inspectable_web_contents_view_efl.cc | 16 ++++ vendor/brightray/filenames.gypi | 1 + 11 files changed, 154 insertions(+), 39 deletions(-) create mode 100644 vendor/brightray/browser/inspectable_web_contents_view_efl.cc diff --git a/atom/app/atom_main.cc b/atom/app/atom_main.cc index 9c255db..c464de2 100644 --- a/atom/app/atom_main.cc +++ b/atom/app/atom_main.cc @@ -27,6 +27,10 @@ #include "atom/app/atom_library_main.h" #endif // defined(OS_MACOSX) +#if defined(USE_EFL) +#include "efl/init.h" +#endif + #include "atom/app/node_main.h" #include "atom/common/atom_command_line.h" #include "base/at_exit.h" @@ -124,6 +128,11 @@ int main(int argc, const char* argv[]) { return atom::NodeMain(argc, const_cast(argv)); } +#if defined(USE_EFL) + if (efl::Initialize(argc, argv)) + return 1; +#endif + atom::AtomMainDelegate delegate; content::ContentMainParams params(&delegate); params.argc = argc; diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index d3f8237..c5155be 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -30,6 +30,12 @@ #include "ui/events/devices/x11/touch_factory_x11.h" #endif +#if defined(USE_EFL) +#include "ui/display/screen_efl.h" +#endif + +#include "atom/common/node_includes.h" + namespace atom { namespace { @@ -180,6 +186,10 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { libgtkui::GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess()); #endif +#if defined(USE_EFL) + ui::InstallScreenInstance(); +#endif + #if !defined(OS_MACOSX) // The corresponding call in macOS is in AtomApplicationDelegate. Browser::Get()->WillFinishLaunching(); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index d3f18d8..654b68e 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -270,9 +270,9 @@ class NativeWindow : public base::SupportsUserData, bool is_modal() const { return is_modal_; } protected: - NativeWindow(brightray::InspectableWebContents* inspectable_web_contents, - const mate::Dictionary& options, - NativeWindow* parent); + explicit NativeWindow(brightray::InspectableWebContents* web_contents, + const mate::Dictionary& options, + NativeWindow* parent); // Convert draggable regions in raw format to SkRegion format. Caller is // responsible for deleting the returned SkRegion instance. diff --git a/atom/browser/native_window_efl.cc b/atom/browser/native_window_efl.cc index d92c00b..031d5b7 100755 --- a/atom/browser/native_window_efl.cc +++ b/atom/browser/native_window_efl.cc @@ -4,22 +4,63 @@ #include "atom/browser/native_window_efl.h" -#include "base/logging.h" +#include + +#include "atom/common/options_switches.h" +#include "base/command_line.h" +#include "content/public/browser/web_contents.h" +#include "efl/window_factory.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/image/image.h" namespace atom { +namespace { + +const int kDefaultWindowWidthDip = 800; +const int kDefaultWindowHeightDip = 600; + +} + NativeWindowEfl::NativeWindowEfl( - brightray::InspectableWebContents* web_contents, + brightray::InspectableWebContents* inspectable_web_contents, const mate::Dictionary& options, NativeWindow* parent) - : NativeWindow(web_contents, options, parent) { -} + : NativeWindow(inspectable_web_contents, options, parent) { +// options.Get(switches::kTitle, &title_); + + // Create Host window via elf::WindowFactory + window_ = efl::WindowFactory::GetHostWindow(web_contents_); + DCHECK(window_); + + gfx::Size size = gfx::Size(kDefaultWindowWidthDip, kDefaultWindowHeightDip); -NativeWindowEfl::~NativeWindowEfl() { + evas_object_smart_callback_add(window_, "delete,request", + OnWindowDeleteRequest, this); + + evas_object_resize(window_, size.width(), size.height()); + + // Add a new box to the parent. + Evas_Object* box = elm_box_add(window_); + evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(window_, box); + evas_object_show(box); + + // Add view at the end of the pack list. + Evas_Object* view = static_cast(web_contents_->GetNativeView()); + evas_object_size_hint_align_set(view, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_box_pack_end(box, view); + + web_contents_->Focus(); } void NativeWindowEfl::Close() { - NOTIMPLEMENTED(); + if(window_) + evas_object_del(window_); + window_ = nullptr; } void NativeWindowEfl::CloseImmediately() { @@ -36,7 +77,7 @@ bool NativeWindowEfl::IsFocused() { } void NativeWindowEfl::Show() { - NOTIMPLEMENTED(); + evas_object_show(window_); } void NativeWindowEfl::ShowInactive() { @@ -44,7 +85,7 @@ void NativeWindowEfl::ShowInactive() { } void NativeWindowEfl::Hide() { - NOTIMPLEMENTED(); + evas_object_hide(window_); } bool NativeWindowEfl::IsVisible() { @@ -58,16 +99,15 @@ bool NativeWindowEfl::IsEnabled() { } void NativeWindowEfl::Maximize() { - NOTIMPLEMENTED(); + elm_win_maximized_set(window_, EINA_TRUE); } void NativeWindowEfl::Unmaximize() { - NOTIMPLEMENTED(); + elm_win_maximized_set(window_, EINA_FALSE); } bool NativeWindowEfl::IsMaximized() { - NOTIMPLEMENTED(); - return true; + return elm_win_maximized_get(window_); } void NativeWindowEfl::Minimize() { @@ -79,26 +119,27 @@ void NativeWindowEfl::Restore() { } bool NativeWindowEfl::IsMinimized() { - NOTIMPLEMENTED(); - return true; + return !elm_win_maximized_get(window_); } void NativeWindowEfl::SetFullScreen(bool fullscreen) { - NOTIMPLEMENTED(); + elm_win_fullscreen_set(window_, fullscreen); } bool NativeWindowEfl::IsFullscreen() const { - NOTIMPLEMENTED(); - return true; + return elm_win_fullscreen_get(window_); } void NativeWindowEfl::SetBounds(const gfx::Rect& bounds, bool animate) { - NOTIMPLEMENTED(); + //evas_object_resize(window_, size.width(), size.height()); } + gfx::Rect NativeWindowEfl::GetBounds() { - NOTIMPLEMENTED(); return gfx::Rect(); +// int width, height; +// evas_object_geometry_get(window_, nullptr, nullptr, &width, &height); +// return gfx::Size(width, height); } void NativeWindowEfl::SetResizable(bool resizable) { @@ -175,11 +216,12 @@ void NativeWindowEfl::Invalidate() { } void NativeWindowEfl::SetTitle(const std::string& title) { - NOTIMPLEMENTED(); + title_ = title; + elm_win_title_set(window_, title.c_str()); } std::string NativeWindowEfl::GetTitle() { - NOTIMPLEMENTED(); + return title_; } void NativeWindowEfl::FlashFrame(bool flash) { NOTIMPLEMENTED(); @@ -224,8 +266,7 @@ void NativeWindowEfl::SetBrowserView(NativeBrowserView* browser_view) { } gfx::NativeWindow NativeWindowEfl::GetNativeWindow() { - NOTIMPLEMENTED(); - return gfx::NativeWindow(); + return window_; } gfx::AcceleratedWidget NativeWindowEfl::GetAcceleratedWidget() { @@ -265,11 +306,20 @@ gfx::Rect NativeWindowEfl::WindowBoundsToContentBounds(const gfx::Rect& bounds) } // static +void NativeWindowEfl::OnWindowDeleteRequest(void* data, Evas_Object*, void*) { + NativeWindowEfl* thiz = static_cast(data); + if(!elm_win_autodel_get(thiz->window_)) + thiz->Close(); + thiz->window_ = nullptr; + thiz->web_contents_->Close(); +} + +// static NativeWindow* NativeWindow::Create( - brightray::InspectableWebContents* inspectable_web_contents, + brightray::InspectableWebContents* web_contents, const mate::Dictionary& options, NativeWindow* parent) { - return new NativeWindowEfl(inspectable_web_contents, options, parent); + return new NativeWindowEfl(web_contents, options, parent); } } diff --git a/atom/browser/native_window_efl.h b/atom/browser/native_window_efl.h index bd4eb26..ea2afd4 100755 --- a/atom/browser/native_window_efl.h +++ b/atom/browser/native_window_efl.h @@ -7,17 +7,24 @@ #include "atom/browser/native_window.h" +#include + #include #include +namespace content { + +class WebContents; + +} // namespace content + namespace atom { class NativeWindowEfl : public NativeWindow { public: - NativeWindowEfl(brightray::InspectableWebContents* inspectable_web_contents, - const mate::Dictionary& options, - NativeWindow* parent); - virtual ~NativeWindowEfl() override; + explicit NativeWindowEfl(brightray::InspectableWebContents* inspectable_web_contents, + const mate::Dictionary& options, + NativeWindow* parent); void Close() override; void CloseImmediately() override; @@ -85,6 +92,14 @@ class NativeWindowEfl : public NativeWindow { // Converts between content bounds and window bounds. virtual gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) override; virtual gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) override; + ~NativeWindowEfl() override {}; + + static void OnWindowDeleteRequest(void* data, Evas_Object*, void*); + + Evas_Object* window_; + content::WebContents* web_contents_; + + std::string title_; DISALLOW_COPY_AND_ASSIGN(NativeWindowEfl); }; diff --git a/atom/browser/ui/accelerator_util_efl.cc b/atom/browser/ui/accelerator_util_efl.cc index d7b7736..41fe4a1 100644 --- a/atom/browser/ui/accelerator_util_efl.cc +++ b/atom/browser/ui/accelerator_util_efl.cc @@ -1,5 +1,5 @@ -// Copyright (c) 2013 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be +// Copyright 2017 Samsung Electronics. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "atom/browser/ui/accelerator_util.h" diff --git a/efl/build/system.gyp b/efl/build/system.gyp index e1894c0..542bf0b 100644 --- a/efl/build/system.gyp +++ b/efl/build/system.gyp @@ -69,6 +69,23 @@ ], }, # elementary { + 'target_name': 'evas', + 'type': 'none', + 'direct_dependent_settings': { + 'cflags': [ + '