Enable undocked devtools.
This commit is contained in:
parent
d70d24c360
commit
9a70c9bb44
2 changed files with 46 additions and 35 deletions
|
@ -22,7 +22,7 @@ class ContainerView : public views::View {
|
||||||
public:
|
public:
|
||||||
explicit ContainerView(InspectableWebContentsViewWin* web_contents_view)
|
explicit ContainerView(InspectableWebContentsViewWin* web_contents_view)
|
||||||
: container_view_created_(false),
|
: container_view_created_(false),
|
||||||
dockside_("bottom"),
|
dockside_("none"), // "none" is treated as "bottom".
|
||||||
web_view_(new views::WebView(NULL)),
|
web_view_(new views::WebView(NULL)),
|
||||||
web_contents_view_(web_contents_view) {
|
web_contents_view_(web_contents_view) {
|
||||||
set_owned_by_client();
|
set_owned_by_client();
|
||||||
|
@ -69,20 +69,18 @@ class ContainerView : public views::View {
|
||||||
return split_view_;
|
return split_view_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetDockSide(const std::string& side) {
|
void SetDockSide(const std::string& side) {
|
||||||
if (side != "bottom" && side != "right")
|
|
||||||
return false; // unsupported display location
|
|
||||||
if (dockside_ == side)
|
if (dockside_ == side)
|
||||||
return true; // no change from current location
|
return; // no change from current location
|
||||||
|
|
||||||
dockside_ = side;
|
dockside_ = side;
|
||||||
if (!IsDevToolsViewShowing())
|
if (!IsDevToolsViewShowing())
|
||||||
return true;
|
return;
|
||||||
|
|
||||||
split_view_->set_orientation(GetSplitViewOrientation());
|
split_view_->set_orientation(GetSplitViewOrientation());
|
||||||
split_view_->set_divider_offset(GetSplitVievDividerOffset());
|
split_view_->set_divider_offset(GetSplitVievDividerOffset());
|
||||||
split_view_->Layout();
|
split_view_->Layout();
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -106,17 +104,17 @@ class ContainerView : public views::View {
|
||||||
}
|
}
|
||||||
|
|
||||||
views::SingleSplitView::Orientation GetSplitViewOrientation() const {
|
views::SingleSplitView::Orientation GetSplitViewOrientation() const {
|
||||||
if (dockside_ == "bottom")
|
if (dockside_ == "right")
|
||||||
return views::SingleSplitView::VERTICAL_SPLIT;
|
|
||||||
else
|
|
||||||
return views::SingleSplitView::HORIZONTAL_SPLIT;
|
return views::SingleSplitView::HORIZONTAL_SPLIT;
|
||||||
|
else
|
||||||
|
return views::SingleSplitView::VERTICAL_SPLIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetSplitVievDividerOffset() const {
|
int GetSplitVievDividerOffset() const {
|
||||||
if (dockside_ == "bottom")
|
if (dockside_ == "right")
|
||||||
return height() * 2 / 3;
|
|
||||||
else
|
|
||||||
return width() * 2 / 3;
|
return width() * 2 / 3;
|
||||||
|
else
|
||||||
|
return height() * 2 / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// True if the container view has already been created, or false otherwise.
|
// True if the container view has already been created, or false otherwise.
|
||||||
|
@ -139,6 +137,7 @@ InspectableWebContentsView* CreateInspectableContentsView(
|
||||||
InspectableWebContentsViewWin::InspectableWebContentsViewWin(
|
InspectableWebContentsViewWin::InspectableWebContentsViewWin(
|
||||||
InspectableWebContentsImpl* inspectable_web_contents)
|
InspectableWebContentsImpl* inspectable_web_contents)
|
||||||
: inspectable_web_contents_(inspectable_web_contents),
|
: inspectable_web_contents_(inspectable_web_contents),
|
||||||
|
undocked_(false),
|
||||||
container_(new ContainerView(this)) {
|
container_(new ContainerView(this)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,31 +160,30 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsViewWin::ShowDevTools() {
|
void InspectableWebContentsViewWin::ShowDevTools() {
|
||||||
container_->ShowDevTools();
|
if (undocked_) {
|
||||||
return;
|
if (!devtools_window_) {
|
||||||
|
devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr();
|
||||||
|
devtools_window_->Init(HWND_DESKTOP, gfx::Rect());
|
||||||
|
}
|
||||||
|
|
||||||
if (!devtools_window_) {
|
auto contents_view = inspectable_web_contents_->GetWebContents()->GetView();
|
||||||
devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr();
|
auto size = contents_view->GetContainerSize();
|
||||||
devtools_window_->Init(HWND_DESKTOP, gfx::Rect());
|
size.Enlarge(-kWindowInset, -kWindowInset);
|
||||||
|
gfx::CenterAndSizeWindow(contents_view->GetNativeView(),
|
||||||
|
devtools_window_->hwnd(),
|
||||||
|
size);
|
||||||
|
|
||||||
|
ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL);
|
||||||
|
} else {
|
||||||
|
container_->ShowDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto contents_view = inspectable_web_contents_->GetWebContents()->GetView();
|
|
||||||
auto size = contents_view->GetContainerSize();
|
|
||||||
size.Enlarge(-kWindowInset, -kWindowInset);
|
|
||||||
gfx::CenterAndSizeWindow(contents_view->GetNativeView(),
|
|
||||||
devtools_window_->hwnd(),
|
|
||||||
size);
|
|
||||||
|
|
||||||
ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsViewWin::CloseDevTools() {
|
void InspectableWebContentsViewWin::CloseDevTools() {
|
||||||
container_->CloseDevTools();
|
if (undocked_)
|
||||||
return;
|
SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0);
|
||||||
|
else
|
||||||
if (!devtools_window_)
|
container_->CloseDevTools();
|
||||||
return;
|
|
||||||
SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InspectableWebContentsViewWin::IsDevToolsViewShowing() {
|
bool InspectableWebContentsViewWin::IsDevToolsViewShowing() {
|
||||||
|
@ -193,7 +191,20 @@ bool InspectableWebContentsViewWin::IsDevToolsViewShowing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) {
|
bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) {
|
||||||
return container_->SetDockSide(side);
|
if (side == "undocked") {
|
||||||
|
undocked_ = true;
|
||||||
|
container_->CloseDevTools();
|
||||||
|
} else if (side == "right" || side == "bottom") {
|
||||||
|
undocked_ = false;
|
||||||
|
if (devtools_window_)
|
||||||
|
SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0);
|
||||||
|
container_->SetDockSide(side);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowDevTools();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -40,8 +40,8 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView {
|
||||||
// Owns us.
|
// Owns us.
|
||||||
InspectableWebContentsImpl* inspectable_web_contents_;
|
InspectableWebContentsImpl* inspectable_web_contents_;
|
||||||
|
|
||||||
|
bool undocked_;
|
||||||
scoped_ptr<ContainerView> container_;
|
scoped_ptr<ContainerView> container_;
|
||||||
|
|
||||||
base::WeakPtr<DevToolsWindow> devtools_window_;
|
base::WeakPtr<DevToolsWindow> devtools_window_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin);
|
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin);
|
||||||
|
|
Loading…
Reference in a new issue