From 1a80cb22b72e153514511d6ed9547d79f62de8b4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 4 Aug 2016 16:35:09 +0900 Subject: [PATCH] Show label for offscreen webview --- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- .../views/inspectable_web_contents_view_views.cc | 12 ++++++++++-- .../views/inspectable_web_contents_view_views.h | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index a83a9d8b2a..6ace243cac 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -224,11 +224,11 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( gfx::Rect display; if (web_contents->GetNativeView()) { display = display::Screen::GetScreen()-> - GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); + GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); } else { display = display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); } - + devtools_bounds_.set_x(display.x() + (display.width() - devtools_bounds_.width()) / 2); devtools_bounds_.set_y(display.y() + (display.height() - devtools_bounds_.height()) / 2); } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 1a438f200e..ccb76126d5 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -5,6 +5,7 @@ #include "browser/inspectable_web_contents_view_delegate.h" #include "base/strings/utf_string_conversions.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/webview/webview.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_delegate.h" @@ -76,14 +77,21 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews( InspectableWebContentsImpl* inspectable_web_contents) : inspectable_web_contents_(inspectable_web_contents), devtools_window_web_view_(nullptr), - contents_web_view_(new views::WebView(nullptr)), + contents_web_view_(nullptr), devtools_web_view_(new views::WebView(nullptr)), devtools_visible_(false), devtools_window_delegate_(nullptr) { set_owned_by_client(); + if (inspectable_web_contents_->GetWebContents()->GetNativeView()) { + views::WebView* contents_web_view = new views::WebView(nullptr); + contents_web_view->SetWebContents(inspectable_web_contents_->GetWebContents()); + contents_web_view_ = contents_web_view; + } else { + contents_web_view_ = new views::Label(L"No content under offscreen mode"); + } + devtools_web_view_->SetVisible(false); - contents_web_view_->SetWebContents(inspectable_web_contents_->GetWebContents()); AddChildView(devtools_web_view_); AddChildView(contents_web_view_); } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index e73ea187ff..8205cc5f06 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -56,7 +56,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, std::unique_ptr devtools_window_; views::WebView* devtools_window_web_view_; - views::WebView* contents_web_view_; + views::View* contents_web_view_; views::WebView* devtools_web_view_; DevToolsContentsResizingStrategy strategy_;