diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 2ac422722003..71616f36a500 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -50,6 +50,8 @@ 'browser/notification_presenter_mac.mm', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', + 'browser/win/devtools_window.cc', + 'browser/win/devtools_window.h', 'browser/win/inspectable_web_contents_view_win.cc', 'browser/win/inspectable_web_contents_view_win.h', 'common/application_info.h', diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 69513546df7f..828fc55046d8 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -171,6 +171,9 @@ 'conditions': [ ['OS=="win"', { 'target_defaults': { + 'include_dirs': [ + '<(libchromiumcontent_include_dir)/third_party/wtl/include', + ], 'defines': [ '_WIN32_WINNT=0x0602', 'WINVER=0x0602', @@ -182,6 +185,10 @@ 'CERT_CHAIN_PARA_HAS_EXTRA_FIELDS', 'WIN32_LEAN_AND_MEAN', '_ATL_NO_OPENGL', + '_SECURE_ATL', + ], + 'msvs_system_include_dirs': [ + '$(VSInstallDir)/VC/atlmfc/include', ], 'msvs_settings': { 'VCCLCompilerTool': { diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc new file mode 100644 index 000000000000..8bed3e89f7d9 --- /dev/null +++ b/brightray/browser/win/devtools_window.cc @@ -0,0 +1,47 @@ +#include "browser/win/devtools_window.h" + +#include "browser/inspectable_web_contents_impl.h" +#include "browser/win/inspectable_web_contents_view_win.h" + +#include "content/public/browser/web_contents_view.h" +#include "ui/base/win/hidden_window.h" + +namespace brightray { + +DevToolsWindow* DevToolsWindow::Create(InspectableWebContentsViewWin* controller) { + return new DevToolsWindow(controller); +} + +DevToolsWindow::DevToolsWindow(InspectableWebContentsViewWin* controller) + : controller_(controller) { +} + +DevToolsWindow::~DevToolsWindow() { +} + +LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM, BOOL&) { + SetParent(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), hwnd()); + SetWindowText(hwnd(), L"Developer Tools"); + return 0; +} + +LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&) { + SetParent(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), ui::GetHiddenWindow()); + delete this; + return 0; +} + +LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM, BOOL&) { + RECT rect; + GetClientRect(hwnd(), &rect); + + SetWindowPos(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), + nullptr, + rect.left, rect.top, + rect.right - rect.left, rect.bottom - rect.top, + SWP_NOZORDER | SWP_SHOWWINDOW); + + return 0; +} + +} diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h new file mode 100644 index 000000000000..7181ab8e4d34 --- /dev/null +++ b/brightray/browser/win/devtools_window.h @@ -0,0 +1,36 @@ +#ifndef BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ +#define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ + +#include "base/memory/weak_ptr.h" +#include "ui/base/win/window_impl.h" + +namespace brightray { + +class InspectableWebContentsViewWin; + +class DevToolsWindow : public ui::WindowImpl, public base::SupportsWeakPtr { + public: + static DevToolsWindow* Create(InspectableWebContentsViewWin*); + + BEGIN_MSG_MAP_EX(DevToolsWindow) + MESSAGE_HANDLER(WM_CREATE, OnCreate) + MESSAGE_HANDLER(WM_DESTROY, OnDestroy) + MESSAGE_HANDLER(WM_SIZE, OnSize) + END_MSG_MAP() + + private: + DevToolsWindow(InspectableWebContentsViewWin*); + ~DevToolsWindow(); + + LRESULT OnCreate(UINT message, WPARAM, LPARAM, BOOL& handled); + LRESULT OnDestroy(UINT message, WPARAM, LPARAM, BOOL& handled); + LRESULT OnSize(UINT message, WPARAM, LPARAM, BOOL& handled); + + InspectableWebContentsViewWin* controller_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); +}; + +} + +#endif diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index deab04590c09..c6161286c232 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -1,11 +1,20 @@ #include "browser/win/inspectable_web_contents_view_win.h" +#include "browser/browser_client.h" #include "browser/inspectable_web_contents_impl.h" +#include "browser/win/devtools_window.h" #include "content/public/browser/web_contents_view.h" +#include "ui/base/win/hwnd_util.h" namespace brightray { +namespace { + +const int kWindowInset = 100; + +} + InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewWin(inspectable_web_contents); } @@ -15,6 +24,8 @@ InspectableWebContentsViewWin::InspectableWebContentsViewWin(InspectableWebConte } InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { + if (devtools_window_) + DestroyWindow(devtools_window_->hwnd()); } gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { @@ -22,9 +33,23 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { } void InspectableWebContentsViewWin::ShowDevTools() { + if (!devtools_window_) { + devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr(); + devtools_window_->Init(HWND_DESKTOP, gfx::Rect()); + } + + auto contents_view = inspectable_web_contents_->GetWebContents()->GetView(); + auto size = contents_view->GetContainerSize(); + size.Enlarge(-kWindowInset, -kWindowInset); + ui::CenterAndSizeWindow(contents_view->GetNativeView(), devtools_window_->hwnd(), size); + + ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL); } void InspectableWebContentsViewWin::CloseDevTools() { + if (!devtools_window_) + return; + SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); } bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 801eb931360c..8f5816fb4e7d 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -4,9 +4,11 @@ #include "browser/inspectable_web_contents_view.h" #include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" namespace brightray { +class DevToolsWindow; class InspectableWebContentsImpl; class InspectableWebContentsViewWin : public InspectableWebContentsView { @@ -25,6 +27,8 @@ private: // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + base::WeakPtr devtools_window_; + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin); }; diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 2f53a96fc665..fc02d9380a52 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 2f53a96fc665176d7e07b67bac6d861295587ce8 +Subproject commit fc02d9380a52ed648196ea6a0d9053483f233658