diff --git a/atom.gyp b/atom.gyp index 82446ed48553..5b92c9395a12 100644 --- a/atom.gyp +++ b/atom.gyp @@ -103,6 +103,8 @@ 'browser/native_window.h', 'browser/native_window_mac.h', 'browser/native_window_mac.mm', + 'browser/native_window_win.cc', + 'browser/native_window_win.h', 'browser/native_window_observer.h', 'browser/node_bindings_browser_win.cc', 'browser/node_bindings_browser_win.h', diff --git a/browser/native_window_win.cc b/browser/native_window_win.cc new file mode 100644 index 000000000000..9a2185a4bd3f --- /dev/null +++ b/browser/native_window_win.cc @@ -0,0 +1,194 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/native_window_win.h" + +#include "base/values.h" +#include "common/options_switches.h" +#include "content/public/browser/native_web_keyboard_event.h" +#include "ui/views/controls/webview/webview.h" +#include "ui/views/widget/widget.h" + +namespace atom { + +NativeWindowWin::NativeWindowWin(content::WebContents* web_contents, + base::DictionaryValue* options) + : NativeWindow(web_contents, options), + window_(new views::Widget), + web_view_(new views::WebView(NULL)) { + views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + window_->Init(params); + + int width = 800, height = 600; + options->GetInteger(switches::kWidth, &width); + options->GetInteger(switches::kHeight, &height); + + gfx::Size size(width, height); + window_->CenterWindow(size); + + web_view_->SetWebContents(web_contents); + window_->SetContentsView(web_view_); +} + +NativeWindowWin::~NativeWindowWin() { +} + +void NativeWindowWin::Close() { + window_->Close(); +} + +void NativeWindowWin::CloseImmediately() { + window_->CloseNow(); +} + +void NativeWindowWin::Move(const gfx::Rect& bounds) { + window_->SetBounds(bounds); +} + +void NativeWindowWin::Focus(bool focus) { + if (focus) + window_->Activate(); + else + window_->Deactivate(); +} + +bool NativeWindowWin::IsFocused() { + return window_->IsActive(); +} + +void NativeWindowWin::Show() { + window_->Show(); +} + +void NativeWindowWin::Hide() { + window_->Hide(); +} + +void NativeWindowWin::Maximize() { + window_->Maximize(); +} + +void NativeWindowWin::Unmaximize() { + window_->Restore(); +} + +void NativeWindowWin::Minimize() { + window_->Minimize(); +} + +void NativeWindowWin::Restore() { + window_->Restore(); +} + +void NativeWindowWin::SetFullscreen(bool fullscreen) { + window_->SetFullscreen(fullscreen); +} + +bool NativeWindowWin::IsFullscreen() { + return window_->IsFullscreen(); +} + +void NativeWindowWin::SetSize(const gfx::Size& size) { + window_->SetSize(size); +} + +gfx::Size NativeWindowWin::GetSize() { + return window_->GetWindowBoundsInScreen().size(); +} + +void NativeWindowWin::SetMinimumSize(const gfx::Size& size) { + minimum_size_ = size; +} + +gfx::Size NativeWindowWin::GetMinimumSize() { + return minimum_size_; +} + +void NativeWindowWin::SetMaximumSize(const gfx::Size& size) { + maximum_size_ = size; +} + +gfx::Size NativeWindowWin::GetMaximumSize() { + return maximum_size_; +} + +void NativeWindowWin::SetResizable(bool resizable) { + resizable_ = resizable; + + // Show/Hide the maximize button. + DWORD style = ::GetWindowLong(window_->GetNativeView(), GWL_STYLE); + if (resizable) + style |= WS_MAXIMIZEBOX; + else + style &= ~WS_MAXIMIZEBOX; + ::SetWindowLong(window_->GetNativeView(), GWL_STYLE, style); +} + +bool NativeWindowWin::IsResizable() { + return resizable_; +} + +void NativeWindowWin::SetAlwaysOnTop(bool top) { + window_->SetAlwaysOnTop(top); +} + +bool NativeWindowWin::IsAlwaysOnTop() { + DWORD style = ::GetWindowLong(window_->GetNativeView(), GWL_EXSTYLE); + return style & WS_EX_TOPMOST; +} + +void NativeWindowWin::Center() { + window_->CenterWindow(GetSize()); +} + +void NativeWindowWin::SetPosition(const gfx::Point& position) { + window_->SetBounds(gfx::Rect(position, GetSize())); +} + +gfx::Point NativeWindowWin::GetPosition() { + return window_->GetWindowBoundsInScreen().origin(); +} + +void NativeWindowWin::SetTitle(const std::string& title) { + title_ = title; + window_->UpdateWindowTitle(); +} + +std::string NativeWindowWin::GetTitle() { + return title_; +} + +void NativeWindowWin::FlashFrame(bool flash) { + window_->FlashFrame(flash); +} + +void NativeWindowWin::SetKiosk(bool kiosk) { + SetFullscreen(kiosk); +} + +bool NativeWindowWin::IsKiosk() { + return IsFullscreen(); +} + +gfx::NativeWindow NativeWindowWin::GetNativeWindow() { + return window_->GetNativeView(); +} + +void NativeWindowWin::HandleKeyboardEvent( + content::WebContents*, + const content::NativeWebKeyboardEvent& event) { + // Any unhandled keyboard/character messages should be defproced. + // This allows stuff like F10, etc to work correctly. + DefWindowProc(event.os_event.hwnd, event.os_event.message, + event.os_event.wParam, event.os_event.lParam); +} + +// static +NativeWindow* NativeWindow::Create(content::WebContents* web_contents, + base::DictionaryValue* options) { + return new NativeWindowWin(web_contents, options); +} + +} // namespace atom diff --git a/browser/native_window_win.h b/browser/native_window_win.h new file mode 100644 index 000000000000..97eab6b08902 --- /dev/null +++ b/browser/native_window_win.h @@ -0,0 +1,79 @@ +// Copyright (c) 2013 GitHub, Inc. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ +#define ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ + +#include "base/memory/scoped_ptr.h" +#include "browser/native_window.h" +#include "ui/gfx/size.h" + +namespace views { +class WebView; +class Widget; +} + +namespace atom { + +class NativeWindowWin : public NativeWindow { + public: + explicit NativeWindowWin(content::WebContents* web_contents, + base::DictionaryValue* options); + virtual ~NativeWindowWin(); + + // NativeWindow implementation. + 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 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 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 SetKiosk(bool kiosk) OVERRIDE; + virtual bool IsKiosk() OVERRIDE; + virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; + + protected: + // Implementations of content::WebContentsDelegate. + virtual void HandleKeyboardEvent( + content::WebContents*, + const content::NativeWebKeyboardEvent&) OVERRIDE; + + private: + scoped_ptr window_; + views::WebView* web_view_; // managed by window_. + + bool resizable_; + std::string title_; + gfx::Size minimum_size_; + gfx::Size maximum_size_; + + DISALLOW_COPY_AND_ASSIGN(NativeWindowWin); +}; + +} // namespace atom + +#endif // ATOM_BROWSER_NATIVE_WINDOW_WIN_H_ diff --git a/vendor/brightray b/vendor/brightray index e423ed5b890d..41a889ba3637 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit e423ed5b890da4cd9d5f29fb4722cb900b17ad5c +Subproject commit 41a889ba36370c968fe220b157ecae8ca9a18100