From 171eba3524a928ee97146886d95a7bb4c1e5bc5c Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 08:14:32 +0000 Subject: [PATCH 1/2] fix: devtools allow restoring saved dock state on Windows Co-authored-by: deepak1556 --- .../browser/api/electron_api_web_contents.cc | 8 ------- shell/browser/browser_mac.mm | 7 ------ shell/browser/ui/inspectable_web_contents.cc | 23 +++++++++++++++++++ shell/common/application_info.cc | 9 ++++++++ shell/common/application_info.h | 2 ++ 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 6fb4fd30502fa..e0dc22c8b59cb 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -2671,14 +2671,6 @@ void WebContents::OpenDevTools(gin::Arguments* args) { state = "detach"; } -#if BUILDFLAG(IS_WIN) - auto* win = static_cast(owner_window()); - // Force a detached state when WCO is enabled to match Chrome - // behavior and prevent occlusion of DevTools. - if (win && win->IsWindowControlsOverlayEnabled()) - state = "detach"; -#endif - bool activate = true; if (args && args->Length() == 1) { gin_helper::Dictionary options; diff --git a/shell/browser/browser_mac.mm b/shell/browser/browser_mac.mm index d5a39991047c0..e78674957c21a 100644 --- a/shell/browser/browser_mac.mm +++ b/shell/browser/browser_mac.mm @@ -40,13 +40,6 @@ namespace { -bool IsAppRTL() { - const std::string& locale = g_browser_process->GetApplicationLocale(); - base::i18n::TextDirection text_direction = - base::i18n::GetTextDirectionForLocaleInStartUp(locale.c_str()); - return text_direction == base::i18n::RIGHT_TO_LEFT; -} - NSString* GetAppPathForProtocol(const GURL& url) { NSURL* ns_url = [NSURL URLWithString:base::SysUTF8ToNSString(url.possibly_invalid_spec())]; diff --git a/shell/browser/ui/inspectable_web_contents.cc b/shell/browser/ui/inspectable_web_contents.cc index a0406e8aeadf4..563ba8e9dad34 100644 --- a/shell/browser/ui/inspectable_web_contents.cc +++ b/shell/browser/ui/inspectable_web_contents.cc @@ -44,11 +44,13 @@ #include "services/network/public/cpp/simple_url_loader_stream_consumer.h" #include "services/network/public/cpp/wrapper_shared_url_loader_factory.h" #include "shell/browser/api/electron_api_web_contents.h" +#include "shell/browser/native_window_views.h" #include "shell/browser/net/asar/asar_url_loader_factory.h" #include "shell/browser/protocol_registry.h" #include "shell/browser/ui/inspectable_web_contents_delegate.h" #include "shell/browser/ui/inspectable_web_contents_view.h" #include "shell/browser/ui/inspectable_web_contents_view_delegate.h" +#include "shell/common/application_info.h" #include "shell/common/platform_util.h" #include "third_party/blink/public/common/logging/logging_utils.h" #include "third_party/blink/public/common/page/page_zoom.h" @@ -573,6 +575,27 @@ void InspectableWebContents::LoadCompleted() { prefs.FindString("currentDockState"); base::RemoveChars(*current_dock_state, "\"", &dock_state_); } +#if BUILDFLAG(IS_WIN) + auto* api_web_contents = api::WebContents::From(GetWebContents()); + if (api_web_contents) { + auto* win = + static_cast(api_web_contents->owner_window()); + // When WCO is enabled, undock the devtools if the current dock + // position overlaps with the position of window controls to avoid + // broken layout. + if (win && win->IsWindowControlsOverlayEnabled()) { + if (IsAppRTL()) { + if (dock_state_ == "left") { + dock_state_ = "undocked"; + } + } else { + if (dock_state_ == "right") { + dock_state_ = "undocked"; + } + } + } + } +#endif std::u16string javascript = base::UTF8ToUTF16( "UI.DockController.instance().setDockSide(\"" + dock_state_ + "\");"); GetDevToolsWebContents()->GetPrimaryMainFrame()->ExecuteJavaScript( diff --git a/shell/common/application_info.cc b/shell/common/application_info.cc index 1af2aa3776702..c1a1f0f7632be 100644 --- a/shell/common/application_info.cc +++ b/shell/common/application_info.cc @@ -4,8 +4,10 @@ #include "shell/common/application_info.h" +#include "base/i18n/rtl.h" #include "base/no_destructor.h" #include "base/strings/stringprintf.h" +#include "chrome/browser/browser_process.h" #include "chrome/common/chrome_version.h" #include "content/public/common/user_agent.h" #include "electron/electron_version.h" @@ -47,4 +49,11 @@ std::string GetApplicationUserAgent() { return content::BuildUserAgentFromProduct(user_agent); } +bool IsAppRTL() { + const std::string& locale = g_browser_process->GetApplicationLocale(); + base::i18n::TextDirection text_direction = + base::i18n::GetTextDirectionForLocaleInStartUp(locale.c_str()); + return text_direction == base::i18n::RIGHT_TO_LEFT; +} + } // namespace electron diff --git a/shell/common/application_info.h b/shell/common/application_info.h index f541e88c17a95..622c98a0562d2 100644 --- a/shell/common/application_info.h +++ b/shell/common/application_info.h @@ -25,6 +25,8 @@ std::string GetApplicationVersion(); // Returns the user agent of Electron. std::string GetApplicationUserAgent(); +bool IsAppRTL(); + #if BUILDFLAG(IS_WIN) PCWSTR GetRawAppUserModelID(); bool GetAppUserModelID(ScopedHString* app_id); From a74716e97de91d1660012265d476cd949ac64b65 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 08:14:39 +0000 Subject: [PATCH 2/2] chore: address feedback Co-authored-by: deepak1556 --- shell/browser/ui/inspectable_web_contents.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/shell/browser/ui/inspectable_web_contents.cc b/shell/browser/ui/inspectable_web_contents.cc index 563ba8e9dad34..078fd0756db54 100644 --- a/shell/browser/ui/inspectable_web_contents.cc +++ b/shell/browser/ui/inspectable_web_contents.cc @@ -584,14 +584,10 @@ void InspectableWebContents::LoadCompleted() { // position overlaps with the position of window controls to avoid // broken layout. if (win && win->IsWindowControlsOverlayEnabled()) { - if (IsAppRTL()) { - if (dock_state_ == "left") { - dock_state_ = "undocked"; - } - } else { - if (dock_state_ == "right") { - dock_state_ = "undocked"; - } + if (IsAppRTL() && dock_state_ == "left") { + dock_state_ = "undocked"; + } else if (dock_state_ == "right") { + dock_state_ = "undocked"; } } }