From 0ef2857534209c7b88b8cf3a2229dba58d409a9c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Aug 2015 22:43:59 +0800 Subject: [PATCH 1/2] Don't show devtools window in too small size or out of screen --- .../browser/inspectable_web_contents_impl.cc | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index d5ac488efea4..006986af6103 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -28,6 +28,7 @@ #include "net/http/http_response_headers.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher_response_writer.h" +#include "ui/gfx/screen.h" namespace brightray { @@ -72,6 +73,11 @@ void DictionaryToRect(const base::DictionaryValue& dict, gfx::Rect* bounds) { *bounds = gfx::Rect(x, y, width, height); } +bool IsPointInRect(const gfx::Point& point, const gfx::Rect& rect) { + return point.x() > rect.x() && point.x() < (rect.width() + rect.x()) && + point.y() > rect.y() && point.y() < (rect.height() + rect.y()); +} + void SetZoomLevelForWebContents(content::WebContents* web_contents, double level) { content::HostZoomMap::SetZoomLevel(web_contents, level); @@ -167,8 +173,20 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( auto context = static_cast(web_contents_->GetBrowserContext()); pref_service_ = context->prefs(); auto bounds_dict = pref_service_->GetDictionary(kDevToolsBoundsPref); - if (bounds_dict) + if (bounds_dict) { DictionaryToRect(*bounds_dict, &devtools_bounds_); + // Sometimes the devtools window is out of screen or has too small size. + if (devtools_bounds_.height() < 100 || devtools_bounds_.width() < 100) { + devtools_bounds_.set_height(600); + devtools_bounds_.set_width(800); + } + gfx::Rect display = gfx::Screen::GetNativeScreen() + ->GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); + if (!IsPointInRect(devtools_bounds_.origin(), display)) { + devtools_bounds_.set_x(0); + devtools_bounds_.set_y(0); + } + } view_.reset(CreateInspectableContentsView(this)); } From 5b4a42f7e9539fa66dad132dc3965ea024046efa Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Aug 2015 22:50:30 +0800 Subject: [PATCH 2/2] Show devtools window in the middle of display --- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 006986af6103..c3df837943e9 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -183,8 +183,8 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( gfx::Rect display = gfx::Screen::GetNativeScreen() ->GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); if (!IsPointInRect(devtools_bounds_.origin(), display)) { - devtools_bounds_.set_x(0); - devtools_bounds_.set_y(0); + devtools_bounds_.set_x(display.x() + (display.width() - devtools_bounds_.width()) / 2); + devtools_bounds_.set_y(display.y() + (display.height() - devtools_bounds_.height()) / 2); } }