Put devtools in split view.

This commit is contained in:
Cheng Zhao 2014-06-10 10:29:39 +08:00
parent 566022cb66
commit bd0f9df96c

View file

@ -6,6 +6,7 @@
#include "content/public/browser/web_contents_view.h" #include "content/public/browser/web_contents_view.h"
#include "ui/gfx/win/hwnd_util.h" #include "ui/gfx/win/hwnd_util.h"
#include "ui/views/controls/single_split_view.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
#include "ui/views/view.h" #include "ui/views/view.h"
@ -24,13 +25,48 @@ class ContainerView : public views::View {
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();
web_view_->set_owned_by_client();
web_view_->SetWebContents( web_view_->SetWebContents(
web_contents_view_->inspectable_web_contents()->GetWebContents()); web_contents_view_->inspectable_web_contents()->GetWebContents());
} }
void ShowDevTools() {
if (IsDevToolsViewShowing())
return;
RemoveChildView(web_view_.get());
devtools_view_ = new views::WebView(NULL);
devtools_view_->SetWebContents(web_contents_view_->
inspectable_web_contents()->devtools_web_contents());
split_view_.reset(new views::SingleSplitView(
web_view_.get(),
devtools_view_,
views::SingleSplitView::VERTICAL_SPLIT,
NULL));
AddChildView(split_view_.get());
Layout();
}
void CloseDevTools() {
if (!IsDevToolsViewShowing())
return;
RemoveChildView(split_view_.get());
split_view_.reset();
AddChildView(web_view_.get());
Layout();
}
bool IsDevToolsViewShowing() {
return split_view_;
}
private: private:
// views::View: // views::View:
virtual void Layout() OVERRIDE { virtual void Layout() OVERRIDE {
if (split_view_)
split_view_->SetBounds(0, 0, width(), height());
else
web_view_->SetBounds(0, 0, width(), height()); web_view_->SetBounds(0, 0, width(), height());
} }
@ -41,14 +77,16 @@ class ContainerView : public views::View {
// available when this is added to the hierarchy. // available when this is added to the hierarchy.
if (details.is_add && GetWidget() && !container_view_created_) { if (details.is_add && GetWidget() && !container_view_created_) {
container_view_created_ = true; container_view_created_ = true;
AddChildView(web_view_); AddChildView(web_view_.get());
} }
} }
// True if the container view has already been created, or false otherwise. // True if the container view has already been created, or false otherwise.
bool container_view_created_; bool container_view_created_;
views::WebView* web_view_; scoped_ptr<views::WebView> web_view_;
scoped_ptr<views::SingleSplitView> split_view_;
views::WebView* devtools_view_; // Owned by split_view_.
InspectableWebContentsViewWin* web_contents_view_; InspectableWebContentsViewWin* web_contents_view_;
}; };
@ -79,6 +117,9 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const {
} }
void InspectableWebContentsViewWin::ShowDevTools() { void InspectableWebContentsViewWin::ShowDevTools() {
container_->ShowDevTools();
return;
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()); devtools_window_->Init(HWND_DESKTOP, gfx::Rect());
@ -95,13 +136,16 @@ void InspectableWebContentsViewWin::ShowDevTools() {
} }
void InspectableWebContentsViewWin::CloseDevTools() { void InspectableWebContentsViewWin::CloseDevTools() {
container_->CloseDevTools();
return;
if (!devtools_window_) if (!devtools_window_)
return; return;
SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0);
} }
bool InspectableWebContentsViewWin::IsDevToolsViewShowing() { bool InspectableWebContentsViewWin::IsDevToolsViewShowing() {
return devtools_window_; return container_->IsDevToolsViewShowing() || devtools_window_;
} }
bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) {