views: Initial docked devtools implementation.
This commit is contained in:
parent
4048d491f0
commit
e574bf6d0f
5 changed files with 138 additions and 56 deletions
|
@ -0,0 +1,98 @@
|
|||
#include "browser/views/inspectable_web_contents_view_views.h"
|
||||
|
||||
#include "browser/inspectable_web_contents_impl.h"
|
||||
|
||||
#include "content/public/browser/web_contents_view.h"
|
||||
#include "ui/views/controls/webview/webview.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
InspectableWebContentsView* CreateInspectableContentsView(
|
||||
InspectableWebContentsImpl* inspectable_web_contents) {
|
||||
return new InspectableWebContentsViewViews(inspectable_web_contents);
|
||||
}
|
||||
|
||||
InspectableWebContentsViewViews::InspectableWebContentsViewViews(
|
||||
InspectableWebContentsImpl* inspectable_web_contents)
|
||||
: inspectable_web_contents_(inspectable_web_contents),
|
||||
contents_web_view_(new views::WebView(NULL)),
|
||||
devtools_web_view_(new views::WebView(NULL)) {
|
||||
set_owned_by_client();
|
||||
|
||||
devtools_web_view_->SetVisible(false);
|
||||
contents_web_view_->SetWebContents(inspectable_web_contents_->GetWebContents());
|
||||
AddChildView(devtools_web_view_);
|
||||
AddChildView(contents_web_view_);
|
||||
}
|
||||
|
||||
InspectableWebContentsViewViews::~InspectableWebContentsViewViews() {
|
||||
}
|
||||
|
||||
views::View* InspectableWebContentsViewViews::GetView() {
|
||||
return this;
|
||||
}
|
||||
|
||||
views::View* InspectableWebContentsViewViews::GetWebView() {
|
||||
return contents_web_view_;
|
||||
}
|
||||
|
||||
gfx::NativeView InspectableWebContentsViewViews::GetNativeView() const {
|
||||
return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView();
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::ShowDevTools() {
|
||||
if (devtools_web_view_->visible())
|
||||
return;
|
||||
|
||||
devtools_web_view_->SetVisible(true);
|
||||
devtools_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents());
|
||||
Layout();
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::CloseDevTools() {
|
||||
if (!devtools_web_view_->visible())
|
||||
return;
|
||||
|
||||
devtools_web_view_->SetVisible(false);
|
||||
devtools_web_view_->SetWebContents(NULL);
|
||||
Layout();
|
||||
}
|
||||
|
||||
bool InspectableWebContentsViewViews::IsDevToolsViewShowing() {
|
||||
return devtools_web_view_->visible();
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::SetIsDocked(bool docked) {
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::SetContentsResizingStrategy(
|
||||
const DevToolsContentsResizingStrategy& strategy) {
|
||||
strategy_.CopyFrom(strategy);
|
||||
Layout();
|
||||
}
|
||||
|
||||
void InspectableWebContentsViewViews::Layout() {
|
||||
if (!devtools_web_view_->visible()) {
|
||||
contents_web_view_->SetBoundsRect(GetContentsBounds());
|
||||
return;
|
||||
}
|
||||
|
||||
gfx::Size container_size(width(), height());
|
||||
gfx::Rect old_devtools_bounds(devtools_web_view_->bounds());
|
||||
gfx::Rect old_contents_bounds(contents_web_view_->bounds());
|
||||
gfx::Rect new_devtools_bounds;
|
||||
gfx::Rect new_contents_bounds;
|
||||
ApplyDevToolsContentsResizingStrategy(strategy_, container_size,
|
||||
old_devtools_bounds, old_contents_bounds,
|
||||
&new_devtools_bounds, &new_contents_bounds);
|
||||
|
||||
// DevTools cares about the specific position, so we have to compensate RTL
|
||||
// layout here.
|
||||
new_devtools_bounds.set_x(GetMirroredXForRect(new_devtools_bounds));
|
||||
new_contents_bounds.set_x(GetMirroredXForRect(new_contents_bounds));
|
||||
|
||||
devtools_web_view_->SetBoundsRect(new_devtools_bounds);
|
||||
contents_web_view_->SetBoundsRect(new_contents_bounds);
|
||||
}
|
||||
|
||||
} // namespace brightray
|
|
@ -0,0 +1,58 @@
|
|||
#ifndef BROWSER_VIEWS_INSPECTABLE_WEB_CONTENTS_VIEW_VIEWS_H_
|
||||
#define BROWSER_VIEWS_INSPECTABLE_WEB_CONTENTS_VIEW_VIEWS_H_
|
||||
|
||||
#include "browser/devtools_contents_resizing_strategy.h"
|
||||
#include "browser/inspectable_web_contents_view.h"
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "ui/views/view.h"
|
||||
|
||||
namespace views {
|
||||
class WebView;
|
||||
class Widget;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
class InspectableWebContentsImpl;
|
||||
|
||||
class InspectableWebContentsViewViews : public InspectableWebContentsView,
|
||||
public views::View {
|
||||
public:
|
||||
explicit InspectableWebContentsViewViews(
|
||||
InspectableWebContentsImpl* inspectable_web_contents_impl);
|
||||
~InspectableWebContentsViewViews();
|
||||
|
||||
// InspectableWebContentsView:
|
||||
virtual views::View* GetView() OVERRIDE;
|
||||
virtual views::View* GetWebView() OVERRIDE;
|
||||
virtual gfx::NativeView GetNativeView() const OVERRIDE;
|
||||
virtual void ShowDevTools() OVERRIDE;
|
||||
virtual void CloseDevTools() OVERRIDE;
|
||||
virtual bool IsDevToolsViewShowing() OVERRIDE;
|
||||
virtual void SetIsDocked(bool docked) OVERRIDE;
|
||||
virtual void SetContentsResizingStrategy(
|
||||
const DevToolsContentsResizingStrategy& strategy) OVERRIDE;
|
||||
|
||||
InspectableWebContentsImpl* inspectable_web_contents() {
|
||||
return inspectable_web_contents_;
|
||||
}
|
||||
|
||||
private:
|
||||
// views::View:
|
||||
virtual void Layout() OVERRIDE;
|
||||
|
||||
// Owns us.
|
||||
InspectableWebContentsImpl* inspectable_web_contents_;
|
||||
|
||||
views::WebView* contents_web_view_;
|
||||
views::WebView* devtools_web_view_;
|
||||
|
||||
DevToolsContentsResizingStrategy strategy_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews);
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
|
||||
#endif // BROWSER_VIEWS_INSPECTABLE_WEB_CONTENTS_VIEW_VIEWS_H_
|
Loading…
Add table
Add a link
Reference in a new issue