From 3061ccf369ee2642d4d18ac396b6758acebc3509 Mon Sep 17 00:00:00 2001 From: "pfeldman@chromium.org" Date: Mon, 13 Jul 2009 14:17:49 +0000 Subject: DevTools: Toggle docked devtools window on shortcut. Review URL: http://codereview.chromium.org/149527 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20479 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser.cc | 6 +-- chrome/browser/browser.h | 2 +- chrome/browser/debugger/devtools_manager.cc | 68 +++++++++++++++++++---------- chrome/browser/debugger/devtools_manager.h | 6 +++ 4 files changed, 55 insertions(+), 27 deletions(-) (limited to 'chrome/browser') diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 3a294e5..6568032 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1075,9 +1075,9 @@ void Browser::OpenCreateShortcutsDialog() { #endif } -void Browser::OpenJavaScriptConsole() { +void Browser::ToggleJavaScriptConsole() { UserMetrics::RecordAction(L"ShowJSConsole", profile_); - DevToolsManager::GetInstance()->OpenDevToolsWindow( + DevToolsManager::GetInstance()->ToggleDevToolsWindow( GetSelectedTabContents()->render_view_host()); } @@ -1357,7 +1357,7 @@ void Browser::ExecuteCommandWithDisposition( // Show various bits of UI case IDC_OPEN_FILE: OpenFile(); break; case IDC_CREATE_SHORTCUTS: OpenCreateShortcutsDialog(); break; - case IDC_JS_CONSOLE: OpenJavaScriptConsole(); break; + case IDC_JS_CONSOLE: ToggleJavaScriptConsole(); break; case IDC_TASK_MANAGER: OpenTaskManager(); break; case IDC_SELECT_PROFILE: OpenSelectProfileDialog(); break; case IDC_NEW_PROFILE: OpenNewProfileDialog(); break; diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 4d84df7..b581f40 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -351,7 +351,7 @@ class Browser : public TabStripModelDelegate, // Show various bits of UI void OpenFile(); void OpenCreateShortcutsDialog(); - void OpenJavaScriptConsole(); + void ToggleJavaScriptConsole(); void OpenTaskManager(); void OpenSelectProfileDialog(); void OpenNewProfileDialog(); diff --git a/chrome/browser/debugger/devtools_manager.cc b/chrome/browser/debugger/devtools_manager.cc index 04c8e92..8cc56d0 100644 --- a/chrome/browser/debugger/devtools_manager.cc +++ b/chrome/browser/debugger/devtools_manager.cc @@ -105,14 +105,9 @@ void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { void DevToolsManager::CloseWindow(RenderViewHost* client_rvh) { DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); - if (!client_host) { - return; + if (client_host) { + CloseWindow(client_host); } - RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); - DCHECK(inspected_rvh); - SendDetachToAgent(inspected_rvh); - - UnregisterDevToolsClientHostFor(inspected_rvh); } void DevToolsManager::DockWindow(RenderViewHost* client_rvh) { @@ -124,22 +119,11 @@ void DevToolsManager::UndockWindow(RenderViewHost* client_rvh) { } void DevToolsManager::OpenDevToolsWindow(RenderViewHost* inspected_rvh) { - DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); - if (!host) { - bool docked = inspected_rvh->process()->profile()->GetPrefs()-> - GetBoolean(prefs::kDevToolsOpenDocked); - host = new DevToolsWindow( - inspected_rvh->site_instance()->browsing_instance()->profile(), - inspected_rvh, - docked); - RegisterDevToolsClientHostFor(inspected_rvh, host); - } - DevToolsWindow* window = host->AsDevToolsWindow(); - if (window) { - in_initial_show_ = true; - window->Show(); - in_initial_show_ = false; - } + ToggleDevToolsWindow(inspected_rvh, true); +} + +void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh) { + ToggleDevToolsWindow(inspected_rvh, false); } void DevToolsManager::InspectElement(RenderViewHost* inspected_rvh, @@ -279,3 +263,41 @@ void DevToolsManager::ReopenWindow(RenderViewHost* client_rvh, bool docked) { DCHECK(window); window->SetDocked(docked); } + +void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh, + bool force_open) { + bool do_open = force_open; + DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); + if (!host) { + bool docked = inspected_rvh->process()->profile()->GetPrefs()-> + GetBoolean(prefs::kDevToolsOpenDocked); + host = new DevToolsWindow( + inspected_rvh->site_instance()->browsing_instance()->profile(), + inspected_rvh, + docked); + RegisterDevToolsClientHostFor(inspected_rvh, host); + do_open = true; + } + DevToolsWindow* window = host->AsDevToolsWindow(); + if (!window) { + return; + } + + // If window is docked and visible, we hide it on toggle. If window is + // undocked, we show (activate) it. + if (!window->is_docked() || do_open) { + in_initial_show_ = true; + window->Show(); + in_initial_show_ = false; + } else { + CloseWindow(host); + } +} + +void DevToolsManager::CloseWindow(DevToolsClientHost* client_host) { + RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); + DCHECK(inspected_rvh); + SendDetachToAgent(inspected_rvh); + + UnregisterDevToolsClientHostFor(inspected_rvh); +} diff --git a/chrome/browser/debugger/devtools_manager.h b/chrome/browser/debugger/devtools_manager.h index 5b6261c..27ab730 100644 --- a/chrome/browser/debugger/devtools_manager.h +++ b/chrome/browser/debugger/devtools_manager.h @@ -54,6 +54,8 @@ class DevToolsManager : public DevToolsClientHost::CloseListener, void OpenDevToolsWindow(RenderViewHost* inspected_rvh); + void ToggleDevToolsWindow(RenderViewHost* inspected_rvh); + // Starts element inspection in the devtools client. // Creates one by means of OpenDevToolsWindow if no client // exists. @@ -83,8 +85,12 @@ private: DevToolsClientHost* FindOnwerDevToolsClientHost(RenderViewHost* client_rvh); + void ToggleDevToolsWindow(RenderViewHost* inspected_rvh, bool force_open); + void ReopenWindow(RenderViewHost* client_rvh, bool docked); + void CloseWindow(DevToolsClientHost* client_host); + // These two maps are for tracking dependencies between inspected tabs and // their DevToolsClientHosts. They are usful for routing devtools messages // and allow us to have at most one devtools client host per tab. We use -- cgit v1.1