2013-05-22 20:57:32 +00:00
|
|
|
#include "browser/win/inspectable_web_contents_view_win.h"
|
|
|
|
|
2013-06-04 18:31:37 +00:00
|
|
|
#include "browser/browser_client.h"
|
2013-05-22 20:57:32 +00:00
|
|
|
#include "browser/inspectable_web_contents_impl.h"
|
2013-06-04 18:31:37 +00:00
|
|
|
#include "browser/win/devtools_window.h"
|
2013-05-22 20:57:32 +00:00
|
|
|
|
|
|
|
#include "content/public/browser/web_contents_view.h"
|
2013-12-02 16:47:58 +00:00
|
|
|
#include "ui/gfx/win/hwnd_util.h"
|
2014-06-10 01:58:28 +00:00
|
|
|
#include "ui/views/controls/webview/webview.h"
|
|
|
|
#include "ui/views/view.h"
|
2013-05-22 20:57:32 +00:00
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
2013-06-04 18:31:37 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
const int kWindowInset = 100;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-10 01:58:28 +00:00
|
|
|
class ContainerView : public views::View {
|
|
|
|
public:
|
|
|
|
explicit ContainerView(InspectableWebContentsViewWin* web_contents_view)
|
|
|
|
: container_view_created_(false),
|
|
|
|
web_view_(new views::WebView(NULL)),
|
|
|
|
web_contents_view_(web_contents_view) {
|
|
|
|
web_view_->SetWebContents(
|
|
|
|
web_contents_view_->inspectable_web_contents()->GetWebContents());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// views::View:
|
|
|
|
virtual void Layout() OVERRIDE {
|
|
|
|
web_view_->SetBounds(0, 0, width(), height());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ViewHierarchyChanged(
|
|
|
|
const ViewHierarchyChangedDetails& details) OVERRIDE {
|
|
|
|
View::ViewHierarchyChanged(details);
|
|
|
|
// We're not using child == this because a Widget may not be
|
|
|
|
// available when this is added to the hierarchy.
|
|
|
|
if (details.is_add && GetWidget() && !container_view_created_) {
|
|
|
|
container_view_created_ = true;
|
|
|
|
AddChildView(web_view_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// True if the container view has already been created, or false otherwise.
|
|
|
|
bool container_view_created_;
|
|
|
|
|
|
|
|
views::WebView* web_view_;
|
|
|
|
|
|
|
|
InspectableWebContentsViewWin* web_contents_view_;
|
|
|
|
};
|
|
|
|
|
2013-11-18 00:02:49 +00:00
|
|
|
InspectableWebContentsView* CreateInspectableContentsView(
|
|
|
|
InspectableWebContentsImpl* inspectable_web_contents) {
|
2013-05-22 20:57:32 +00:00
|
|
|
return new InspectableWebContentsViewWin(inspectable_web_contents);
|
|
|
|
}
|
|
|
|
|
2013-11-18 00:02:49 +00:00
|
|
|
InspectableWebContentsViewWin::InspectableWebContentsViewWin(
|
|
|
|
InspectableWebContentsImpl* inspectable_web_contents)
|
2014-06-10 01:58:28 +00:00
|
|
|
: inspectable_web_contents_(inspectable_web_contents),
|
|
|
|
container_(new ContainerView(this)) {
|
2013-05-22 20:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InspectableWebContentsViewWin::~InspectableWebContentsViewWin() {
|
2013-06-04 18:31:37 +00:00
|
|
|
if (devtools_window_)
|
|
|
|
DestroyWindow(devtools_window_->hwnd());
|
2013-05-22 20:57:32 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 01:58:28 +00:00
|
|
|
views::View* InspectableWebContentsViewWin::GetView() const {
|
|
|
|
return container_;
|
|
|
|
}
|
|
|
|
|
2013-05-22 20:57:32 +00:00
|
|
|
gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const {
|
2013-11-18 00:02:49 +00:00
|
|
|
auto web_contents = inspectable_web_contents_->GetWebContents();
|
|
|
|
return web_contents->GetView()->GetNativeView();
|
2013-05-22 20:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsViewWin::ShowDevTools() {
|
2013-06-04 18:31:37 +00:00
|
|
|
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);
|
2013-12-02 16:47:58 +00:00
|
|
|
gfx::CenterAndSizeWindow(contents_view->GetNativeView(),
|
|
|
|
devtools_window_->hwnd(),
|
|
|
|
size);
|
2013-06-04 18:31:37 +00:00
|
|
|
|
|
|
|
ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL);
|
2013-05-22 20:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InspectableWebContentsViewWin::CloseDevTools() {
|
2013-06-04 18:31:37 +00:00
|
|
|
if (!devtools_window_)
|
|
|
|
return;
|
|
|
|
SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0);
|
2013-05-22 20:57:32 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 12:34:44 +00:00
|
|
|
bool InspectableWebContentsViewWin::IsDevToolsViewShowing() {
|
2013-11-05 02:29:53 +00:00
|
|
|
return devtools_window_;
|
|
|
|
}
|
|
|
|
|
2013-05-22 20:57:32 +00:00
|
|
|
bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-17 23:20:17 +00:00
|
|
|
} // namespace brightray
|