Update DevToolsWindow to use views and aura
This is required to make it work in Chrome 35.
This commit is contained in:
parent
f65246b3cd
commit
e86c409e6b
3 changed files with 55 additions and 55 deletions
|
@ -4,52 +4,63 @@
|
||||||
#include "browser/win/inspectable_web_contents_view_win.h"
|
#include "browser/win/inspectable_web_contents_view_win.h"
|
||||||
|
|
||||||
#include "content/public/browser/web_contents_view.h"
|
#include "content/public/browser/web_contents_view.h"
|
||||||
#include "ui/base/win/hidden_window.h"
|
#include "ui/views/layout/fill_layout.h"
|
||||||
|
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
|
||||||
|
#include "ui/views/widget/widget_delegate.h"
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
class WidgetDelegateView : public views::WidgetDelegateView {
|
||||||
|
public:
|
||||||
|
WidgetDelegateView() {
|
||||||
|
SetLayoutManager(new views::FillLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void DeleteDelegate() OVERRIDE { delete this; }
|
||||||
|
virtual views::View* GetContentsView() OVERRIDE{ return this; }
|
||||||
|
virtual bool CanResize() const OVERRIDE { return true; }
|
||||||
|
virtual bool CanMaximize() const OVERRIDE { return true; }
|
||||||
|
virtual base::string16 GetWindowTitle() const OVERRIDE { return L"Developer Tools"; }
|
||||||
|
virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(800, 600); }
|
||||||
|
virtual gfx::Size GetMinimumSize() OVERRIDE { return gfx::Size(100, 100); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
DevToolsWindow* DevToolsWindow::Create(
|
DevToolsWindow* DevToolsWindow::Create(
|
||||||
InspectableWebContentsViewWin* controller) {
|
InspectableWebContentsViewWin* controller) {
|
||||||
return new DevToolsWindow(controller);
|
return new DevToolsWindow(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
DevToolsWindow::DevToolsWindow(InspectableWebContentsViewWin* controller)
|
DevToolsWindow::DevToolsWindow(InspectableWebContentsViewWin* controller)
|
||||||
: controller_(controller) {
|
: controller_(controller),
|
||||||
|
widget_(new views::Widget) {
|
||||||
|
auto delegate_view = new WidgetDelegateView;
|
||||||
|
views::Widget::InitParams params;
|
||||||
|
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
||||||
|
params.top_level = true;
|
||||||
|
params.native_widget = new views::DesktopNativeWidgetAura(widget_.get());
|
||||||
|
params.delegate = delegate_view;
|
||||||
|
widget_->Init(params);
|
||||||
|
delegate_view->AddChildView(controller->GetView());
|
||||||
|
delegate_view->Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
DevToolsWindow::~DevToolsWindow() {
|
DevToolsWindow::~DevToolsWindow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM) {
|
void DevToolsWindow::Show() {
|
||||||
auto devtools_web_contents =
|
widget_->Show();
|
||||||
controller_->inspectable_web_contents()->devtools_web_contents();
|
|
||||||
SetParent(devtools_web_contents->GetView()->GetNativeView(), hwnd());
|
|
||||||
SetWindowText(hwnd(), L"Developer Tools");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM) {
|
void DevToolsWindow::Close() {
|
||||||
auto devtools_web_contents =
|
widget_->Hide();
|
||||||
controller_->inspectable_web_contents()->devtools_web_contents();
|
}
|
||||||
SetParent(
|
|
||||||
devtools_web_contents->GetView()->GetNativeView(), ui::GetHiddenWindow());
|
void DevToolsWindow::Destroy() {
|
||||||
delete this;
|
delete this;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM) {
|
|
||||||
RECT rect;
|
|
||||||
GetClientRect(hwnd(), &rect);
|
|
||||||
|
|
||||||
auto devtools_web_contents =
|
|
||||||
controller_->inspectable_web_contents()->devtools_web_contents();
|
|
||||||
SetWindowPos(devtools_web_contents->GetView()->GetNativeView(),
|
|
||||||
nullptr,
|
|
||||||
rect.left, rect.top,
|
|
||||||
rect.right - rect.left, rect.bottom - rect.top,
|
|
||||||
SWP_NOZORDER | SWP_SHOWWINDOW);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -1,35 +1,33 @@
|
||||||
#ifndef BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_
|
#ifndef BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_
|
||||||
#define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_
|
#define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_
|
||||||
|
|
||||||
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "ui/gfx/win/window_impl.h"
|
|
||||||
|
namespace views {
|
||||||
|
class Widget;
|
||||||
|
}
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
class InspectableWebContentsViewWin;
|
class InspectableWebContentsViewWin;
|
||||||
|
|
||||||
class DevToolsWindow : public gfx::WindowImpl,
|
class DevToolsWindow : public base::SupportsWeakPtr<DevToolsWindow> {
|
||||||
public base::SupportsWeakPtr<DevToolsWindow> {
|
|
||||||
public:
|
public:
|
||||||
static DevToolsWindow* Create(
|
static DevToolsWindow* Create(
|
||||||
InspectableWebContentsViewWin* inspectable_web_contents_view_win);
|
InspectableWebContentsViewWin* inspectable_web_contents_view_win);
|
||||||
|
|
||||||
CR_BEGIN_MSG_MAP_EX(DevToolsWindow)
|
void Show();
|
||||||
CR_MESSAGE_HANDLER_EX(WM_CREATE, OnCreate)
|
void Close();
|
||||||
CR_MESSAGE_HANDLER_EX(WM_DESTROY, OnDestroy)
|
void Destroy();
|
||||||
CR_MESSAGE_HANDLER_EX(WM_SIZE, OnSize)
|
|
||||||
CR_END_MSG_MAP()
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit DevToolsWindow(
|
explicit DevToolsWindow(
|
||||||
InspectableWebContentsViewWin* inspectable_web_contents_view_win);
|
InspectableWebContentsViewWin* inspectable_web_contents_view_win);
|
||||||
~DevToolsWindow();
|
~DevToolsWindow();
|
||||||
|
|
||||||
LRESULT OnCreate(UINT message, WPARAM, LPARAM);
|
|
||||||
LRESULT OnDestroy(UINT message, WPARAM, LPARAM);
|
|
||||||
LRESULT OnSize(UINT message, WPARAM, LPARAM);
|
|
||||||
|
|
||||||
InspectableWebContentsViewWin* controller_;
|
InspectableWebContentsViewWin* controller_;
|
||||||
|
scoped_ptr<views::Widget> widget_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(DevToolsWindow);
|
DISALLOW_COPY_AND_ASSIGN(DevToolsWindow);
|
||||||
};
|
};
|
||||||
|
|
|
@ -143,7 +143,7 @@ InspectableWebContentsViewWin::InspectableWebContentsViewWin(
|
||||||
|
|
||||||
InspectableWebContentsViewWin::~InspectableWebContentsViewWin() {
|
InspectableWebContentsViewWin::~InspectableWebContentsViewWin() {
|
||||||
if (devtools_window_)
|
if (devtools_window_)
|
||||||
DestroyWindow(devtools_window_->hwnd());
|
devtools_window_->Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
views::View* InspectableWebContentsViewWin::GetView() const {
|
views::View* InspectableWebContentsViewWin::GetView() const {
|
||||||
|
@ -161,19 +161,10 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const {
|
||||||
|
|
||||||
void InspectableWebContentsViewWin::ShowDevTools() {
|
void InspectableWebContentsViewWin::ShowDevTools() {
|
||||||
if (undocked_) {
|
if (undocked_) {
|
||||||
if (!devtools_window_) {
|
if (!devtools_window_)
|
||||||
devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr();
|
devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr();
|
||||||
devtools_window_->Init(HWND_DESKTOP, gfx::Rect());
|
|
||||||
}
|
|
||||||
|
|
||||||
auto contents_view = inspectable_web_contents_->GetWebContents()->GetView();
|
devtools_window_->Show();
|
||||||
auto size = contents_view->GetContainerSize();
|
|
||||||
size.Enlarge(-kWindowInset, -kWindowInset);
|
|
||||||
gfx::CenterAndSizeWindow(contents_view->GetNativeView(),
|
|
||||||
devtools_window_->hwnd(),
|
|
||||||
size);
|
|
||||||
|
|
||||||
ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL);
|
|
||||||
} else {
|
} else {
|
||||||
container_->ShowDevTools();
|
container_->ShowDevTools();
|
||||||
}
|
}
|
||||||
|
@ -181,7 +172,7 @@ void InspectableWebContentsViewWin::ShowDevTools() {
|
||||||
|
|
||||||
void InspectableWebContentsViewWin::CloseDevTools() {
|
void InspectableWebContentsViewWin::CloseDevTools() {
|
||||||
if (undocked_)
|
if (undocked_)
|
||||||
SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0);
|
devtools_window_->Close();
|
||||||
else
|
else
|
||||||
container_->CloseDevTools();
|
container_->CloseDevTools();
|
||||||
}
|
}
|
||||||
|
@ -197,7 +188,7 @@ bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) {
|
||||||
} else if (side == "right" || side == "bottom") {
|
} else if (side == "right" || side == "bottom") {
|
||||||
undocked_ = false;
|
undocked_ = false;
|
||||||
if (devtools_window_)
|
if (devtools_window_)
|
||||||
SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0);
|
devtools_window_->Close();
|
||||||
container_->SetDockSide(side);
|
container_->SetDockSide(side);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue