From 84878c4c7750664f21c40e88621d1e28284058ee Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Jul 2014 14:14:52 +0000 Subject: [PATCH] Initial work for Aura on Linux. --- atom.gyp | 6 +- atom/browser/api/atom_api_menu.h | 2 +- atom/browser/api/atom_api_menu_gtk.cc | 4 +- atom/browser/native_window_aura.cc | 202 ++++++++++++++++++++++++++ atom/browser/native_window_aura.h | 70 +++++++++ atom/browser/ui/file_dialog_gtk.cc | 3 +- atom/browser/ui/message_box_gtk.cc | 3 +- filename_rules.gypi | 4 +- vendor/brightray | 2 +- 9 files changed, 287 insertions(+), 9 deletions(-) create mode 100644 atom/browser/native_window_aura.cc create mode 100644 atom/browser/native_window_aura.h diff --git a/atom.gyp b/atom.gyp index bedaf4100634..2358f9fbe6bf 100644 --- a/atom.gyp +++ b/atom.gyp @@ -101,8 +101,10 @@ 'atom/browser/mac/atom_application_delegate.mm', 'atom/browser/native_window.cc', 'atom/browser/native_window.h', - 'atom/browser/native_window_gtk.cc', - 'atom/browser/native_window_gtk.h', + 'atom/browser/native_window_aura.cc', + 'atom/browser/native_window_aura.h', +# 'atom/browser/native_window_gtk.cc', +# 'atom/browser/native_window_gtk.h', 'atom/browser/native_window_mac.h', 'atom/browser/native_window_mac.mm', 'atom/browser/native_window_win.cc', diff --git a/atom/browser/api/atom_api_menu.h b/atom/browser/api/atom_api_menu.h index 2bd63dfab2d0..122c8bc15568 100644 --- a/atom/browser/api/atom_api_menu.h +++ b/atom/browser/api/atom_api_menu.h @@ -87,7 +87,7 @@ class Menu : public mate::Wrappable, virtual void UpdateStates() = 0; #endif -#if defined(OS_WIN) || defined(TOOLKIT_GTK) +#if defined(OS_WIN) || defined(OS_LINUX) virtual void AttachToWindow(Window* window) = 0; #endif diff --git a/atom/browser/api/atom_api_menu_gtk.cc b/atom/browser/api/atom_api_menu_gtk.cc index acaca4b2f8e8..9d45d3f86969 100644 --- a/atom/browser/api/atom_api_menu_gtk.cc +++ b/atom/browser/api/atom_api_menu_gtk.cc @@ -19,6 +19,7 @@ MenuGtk::MenuGtk() { } void MenuGtk::Popup(Window* window) { + /* uint32_t triggering_event_time; gfx::Point point; @@ -35,10 +36,11 @@ void MenuGtk::Popup(Window* window) { menu_gtk_.reset(new ::MenuGtk(this, model_.get())); menu_gtk_->PopupAsContext(point, triggering_event_time); + */ } void MenuGtk::AttachToWindow(Window* window) { - static_cast(window->window())->SetMenu(model_.get()); + // static_cast(window->window())->SetMenu(model_.get()); } // static diff --git a/atom/browser/native_window_aura.cc b/atom/browser/native_window_aura.cc new file mode 100644 index 000000000000..ada089a49751 --- /dev/null +++ b/atom/browser/native_window_aura.cc @@ -0,0 +1,202 @@ +// Copyright (c) 2014 GitHub, Inc. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/native_window_aura.h" + +#include "content/public/browser/web_contents_view.h" +#include "ui/aura/env.h" +#include "ui/aura/layout_manager.h" +#include "ui/aura/window.h" + +namespace atom { + +namespace { + +class FillLayout : public aura::LayoutManager { + public: + explicit FillLayout(aura::Window* root) + : root_(root) { + } + + virtual ~FillLayout() {} + + private: + // aura::LayoutManager: + virtual void OnWindowResized() OVERRIDE { + } + + virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { + child->SetBounds(root_->bounds()); + } + + virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { + } + + virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { + } + + virtual void OnChildWindowVisibilityChanged(aura::Window* child, + bool visible) OVERRIDE { + } + + virtual void SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) OVERRIDE { + SetChildBoundsDirect(child, requested_bounds); + } + + aura::Window* root_; + + DISALLOW_COPY_AND_ASSIGN(FillLayout); +}; + +} // namespace + +NativeWindowAura::NativeWindowAura(content::WebContents* web_contents, + const mate::Dictionary& options) + : NativeWindow(web_contents, options) { + aura::Env::CreateInstance(); + + host_.reset(aura::WindowTreeHost::Create(gfx::Rect(gfx::Size(800, 600)))); + host_->InitHost(); + host_->window()->SetLayoutManager(new FillLayout(host_->window())); + host_->window()->AddChild(web_contents->GetView()->GetNativeView()); +} + +NativeWindowAura::~NativeWindowAura() { +} + +void NativeWindowAura::Close() { +} + +void NativeWindowAura::CloseImmediately() { +} + +void NativeWindowAura::Move(const gfx::Rect& pos) { +} + +void NativeWindowAura::Focus(bool focus) { +} + +bool NativeWindowAura::IsFocused() { + return false; +} + +void NativeWindowAura::Show() { + host_->Show(); +} + +void NativeWindowAura::Hide() { + host_->Hide(); +} + +bool NativeWindowAura::IsVisible() { + return false; +} + +void NativeWindowAura::Maximize() { +} + +void NativeWindowAura::Unmaximize() { +} + +void NativeWindowAura::Minimize() { +} + +void NativeWindowAura::Restore() { +} + +void NativeWindowAura::SetFullscreen(bool fullscreen) { +} + +bool NativeWindowAura::IsFullscreen() { + return false; +} + +void NativeWindowAura::SetSize(const gfx::Size& size) { +} + +gfx::Size NativeWindowAura::GetSize() { + return gfx::Size(); +} + +void NativeWindowAura::SetContentSize(const gfx::Size& size) { +} + +gfx::Size NativeWindowAura::GetContentSize() { + return gfx::Size(); +} + +void NativeWindowAura::SetMinimumSize(const gfx::Size& size) { +} + +gfx::Size NativeWindowAura::GetMinimumSize() { + return gfx::Size(); +} + +void NativeWindowAura::SetMaximumSize(const gfx::Size& size) { +} + +gfx::Size NativeWindowAura::GetMaximumSize() { + return gfx::Size(); +} + +void NativeWindowAura::SetResizable(bool resizable) { +} + +bool NativeWindowAura::IsResizable() { + return false; +} + +void NativeWindowAura::SetAlwaysOnTop(bool top) { +} + +bool NativeWindowAura::IsAlwaysOnTop() { + return false; +} + +void NativeWindowAura::Center() { +} + +void NativeWindowAura::SetPosition(const gfx::Point& position) { +} + +gfx::Point NativeWindowAura::GetPosition() { + return gfx::Point(0, 0); +} + +void NativeWindowAura::SetTitle(const std::string& title) { +} + +std::string NativeWindowAura::GetTitle() { + return ""; +} + +void NativeWindowAura::FlashFrame(bool flash) { +} + +void NativeWindowAura::SetSkipTaskbar(bool skip) { +} + +void NativeWindowAura::SetKiosk(bool kiosk) { +} + +bool NativeWindowAura::IsKiosk() { + return false; +} + +gfx::NativeWindow NativeWindowAura::GetNativeWindow() { + return NULL; +} + +void NativeWindowAura::UpdateDraggableRegions( + const std::vector& regions) { +} + +// static +NativeWindow* NativeWindow::Create(content::WebContents* web_contents, + const mate::Dictionary& options) { + return new NativeWindowAura(web_contents, options); +} + +} // namespace atom diff --git a/atom/browser/native_window_aura.h b/atom/browser/native_window_aura.h new file mode 100644 index 000000000000..dffeb11be4c1 --- /dev/null +++ b/atom/browser/native_window_aura.h @@ -0,0 +1,70 @@ +// Copyright (c) 2014 GitHub, Inc. All rights reserved. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_NATIVE_WINDOW_AURA_H_ +#define ATOM_BROWSER_NATIVE_WINDOW_AURA_H_ + +#include "atom/browser/native_window.h" + +#include "ui/aura/window_tree_host.h" + +namespace atom { + +class NativeWindowAura : public NativeWindow { + public: + explicit NativeWindowAura(content::WebContents* web_contents, + const mate::Dictionary& options); + virtual ~NativeWindowAura(); + + // NativeWindow: + virtual void Close() OVERRIDE; + virtual void CloseImmediately() OVERRIDE; + virtual void Move(const gfx::Rect& pos) OVERRIDE; + virtual void Focus(bool focus) OVERRIDE; + virtual bool IsFocused() OVERRIDE; + virtual void Show() OVERRIDE; + virtual void Hide() OVERRIDE; + virtual bool IsVisible() OVERRIDE; + virtual void Maximize() OVERRIDE; + virtual void Unmaximize() OVERRIDE; + virtual void Minimize() OVERRIDE; + virtual void Restore() OVERRIDE; + virtual void SetFullscreen(bool fullscreen) OVERRIDE; + virtual bool IsFullscreen() OVERRIDE; + virtual void SetSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Size GetSize() OVERRIDE; + virtual void SetContentSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Size GetContentSize() OVERRIDE; + virtual void SetMinimumSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Size GetMinimumSize() OVERRIDE; + virtual void SetMaximumSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Size GetMaximumSize() OVERRIDE; + virtual void SetResizable(bool resizable) OVERRIDE; + virtual bool IsResizable() OVERRIDE; + virtual void SetAlwaysOnTop(bool top) OVERRIDE; + virtual bool IsAlwaysOnTop() OVERRIDE; + virtual void Center() OVERRIDE; + virtual void SetPosition(const gfx::Point& position) OVERRIDE; + virtual gfx::Point GetPosition() OVERRIDE; + virtual void SetTitle(const std::string& title) OVERRIDE; + virtual std::string GetTitle() OVERRIDE; + virtual void FlashFrame(bool flash) OVERRIDE; + virtual void SetSkipTaskbar(bool skip) OVERRIDE; + virtual void SetKiosk(bool kiosk) OVERRIDE; + virtual bool IsKiosk() OVERRIDE; + virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; + + private: + // NativeWindow: + virtual void UpdateDraggableRegions( + const std::vector& regions) OVERRIDE; + + scoped_ptr host_; + + DISALLOW_COPY_AND_ASSIGN(NativeWindowAura); +}; + +} // namespace atom + +#endif // ATOM_BROWSER_NATR_NATIVE_WINDOW_AURA_H_ diff --git a/atom/browser/ui/file_dialog_gtk.cc b/atom/browser/ui/file_dialog_gtk.cc index 618ec31b63df..7973fff81ba9 100644 --- a/atom/browser/ui/file_dialog_gtk.cc +++ b/atom/browser/ui/file_dialog_gtk.cc @@ -27,7 +27,8 @@ class FileChooserDialog { else if (action == GTK_FILE_CHOOSER_ACTION_OPEN) confirm_text = GTK_STOCK_OPEN; - GtkWindow* window = parent_window ? parent_window->GetNativeWindow() : NULL; + // GtkWindow* window = parent_window ? parent_window->GetNativeWindow() : NULL; + GtkWindow* window = NULL; dialog_ = gtk_file_chooser_dialog_new( title.c_str(), window, diff --git a/atom/browser/ui/message_box_gtk.cc b/atom/browser/ui/message_box_gtk.cc index 4915d099588f..3793dad33992 100644 --- a/atom/browser/ui/message_box_gtk.cc +++ b/atom/browser/ui/message_box_gtk.cc @@ -24,7 +24,8 @@ class MessageBox { const std::string& detail) : cancel_id_(0), dialog_scope_(new NativeWindow::DialogScope(parent_window)) { - GtkWindow* window = parent_window ? parent_window->GetNativeWindow() : NULL; + // GtkWindow* window = parent_window ? parent_window->GetNativeWindow() : NULL; + GtkWindow* window = NULL; dialog_ = gtk_dialog_new_with_buttons( title.c_str(), window, diff --git a/filename_rules.gypi b/filename_rules.gypi index 030080564621..5872786a97ac 100644 --- a/filename_rules.gypi +++ b/filename_rules.gypi @@ -62,8 +62,8 @@ ['exclude', '(^|/)x/'], ], }], - ['OS!="win"', { - 'sources/': [ ['exclude', '_views\\.(h|cc)$'] ] + ['OS!="linux"', { + 'sources/': [ ['exclude', '_aura\\.(h|cc)$'] ] }], ] } diff --git a/vendor/brightray b/vendor/brightray index 1e41ef63ebd7..a348865e723b 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 1e41ef63ebd7ecb1ffb3a6fec74b5a5264f20092 +Subproject commit a348865e723b73cd01d0b976f2d0b8d9b836176d