summaryrefslogtreecommitdiffstats
path: root/chrome/browser/debugger
diff options
context:
space:
mode:
authorapavlov@chromium.org <apavlov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 11:58:48 +0000
committerapavlov@chromium.org <apavlov@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 11:58:48 +0000
commit2a8a98126b0115e0f3d137668c67b90a399f72bf (patch)
treeac1eedcdf0439b6c867cdce638d8a512d7cabaee /chrome/browser/debugger
parent8664dfb1f41cb9c51e50b3f7c4d78b24d29408d8 (diff)
downloadchromium_src-2a8a98126b0115e0f3d137668c67b90a399f72bf.zip
chromium_src-2a8a98126b0115e0f3d137668c67b90a399f72bf.tar.gz
chromium_src-2a8a98126b0115e0f3d137668c67b90a399f72bf.tar.bz2
Add "Inspect Element" shortcut to browser tabs.
If the DevTools window is closed, it gets opened, and the Inspect Element tool is enabled. If the DevTools window is opened, the inspected tab remains focused with the Inspect Element tool enabled. If the Inspect Element tool is enabled, it gets turned off. The shortcut is Ctrl-Shift-C for Win/Linux, Cmd-Shift-C for Mac BUG=29532 TEST=manual Review URL: http://codereview.chromium.org/3011002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/debugger')
-rw-r--r--chrome/browser/debugger/devtools_manager.cc24
-rw-r--r--chrome/browser/debugger/devtools_manager.h6
-rw-r--r--chrome/browser/debugger/devtools_toggle_action.h14
-rw-r--r--chrome/browser/debugger/devtools_window.cc58
-rw-r--r--chrome/browser/debugger/devtools_window.h9
5 files changed, 75 insertions, 36 deletions
diff --git a/chrome/browser/debugger/devtools_manager.cc b/chrome/browser/debugger/devtools_manager.cc
index 2965478..6b958cc 100644
--- a/chrome/browser/debugger/devtools_manager.cc
+++ b/chrome/browser/debugger/devtools_manager.cc
@@ -131,12 +131,16 @@ void DevToolsManager::RequestUndockWindow(RenderViewHost* client_rvh) {
}
void DevToolsManager::OpenDevToolsWindow(RenderViewHost* inspected_rvh) {
- ToggleDevToolsWindow(inspected_rvh, true, false);
+ ToggleDevToolsWindow(
+ inspected_rvh,
+ true,
+ DEVTOOLS_TOGGLE_ACTION_NONE);
}
-void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh,
- bool open_console) {
- ToggleDevToolsWindow(inspected_rvh, false, open_console);
+void DevToolsManager::ToggleDevToolsWindow(
+ RenderViewHost* inspected_rvh,
+ DevToolsToggleAction action) {
+ ToggleDevToolsWindow(inspected_rvh, false, action);
}
void DevToolsManager::RuntimeFeatureStateChanged(RenderViewHost* inspected_rvh,
@@ -345,9 +349,10 @@ void DevToolsManager::ReopenWindow(RenderViewHost* client_rvh, bool docked) {
window->SetDocked(docked);
}
-void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh,
- bool force_open,
- bool open_console) {
+void DevToolsManager::ToggleDevToolsWindow(
+ RenderViewHost* inspected_rvh,
+ bool force_open,
+ DevToolsToggleAction action) {
bool do_open = force_open;
DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh);
if (!host) {
@@ -368,9 +373,10 @@ void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh,
// undocked, we show (activate) it.
if (!window->is_docked() || do_open) {
AutoReset<bool> auto_reset_in_initial_show(&in_initial_show_, true);
- window->Show(open_console);
- } else
+ window->Show(action);
+ } else {
UnregisterDevToolsClientHostFor(inspected_rvh);
+ }
}
void DevToolsManager::BindClientHost(RenderViewHost* inspected_rvh,
diff --git a/chrome/browser/debugger/devtools_manager.h b/chrome/browser/debugger/devtools_manager.h
index 46b5ea6..20835af 100644
--- a/chrome/browser/debugger/devtools_manager.h
+++ b/chrome/browser/debugger/devtools_manager.h
@@ -11,6 +11,7 @@
#include "base/ref_counted.h"
#include "chrome/browser/debugger/devtools_client_host.h"
+#include "chrome/browser/debugger/devtools_toggle_action.h"
namespace IPC {
class Message;
@@ -54,7 +55,8 @@ class DevToolsManager : public DevToolsClientHost::CloseListener,
void RequestUndockWindow(RenderViewHost* client_rvn);
void OpenDevToolsWindow(RenderViewHost* inspected_rvh);
- void ToggleDevToolsWindow(RenderViewHost* inspected_rvh, bool open_console);
+ void ToggleDevToolsWindow(RenderViewHost* inspected_rvh,
+ DevToolsToggleAction action);
void RuntimeFeatureStateChanged(RenderViewHost* inspected_rvh,
const std::string& feature,
bool enabled);
@@ -103,7 +105,7 @@ class DevToolsManager : public DevToolsClientHost::CloseListener,
void ToggleDevToolsWindow(RenderViewHost* inspected_rvh,
bool force_open,
- bool open_console);
+ DevToolsToggleAction action);
void ReopenWindow(RenderViewHost* client_rvh, bool docked);
diff --git a/chrome/browser/debugger/devtools_toggle_action.h b/chrome/browser/debugger/devtools_toggle_action.h
new file mode 100644
index 0000000..a8c4c53
--- /dev/null
+++ b/chrome/browser/debugger/devtools_toggle_action.h
@@ -0,0 +1,14 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_DEBUGGER_DEVTOOLS_TOGGLE_ACTION_H_
+#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_TOGGLE_ACTION_H_
+
+enum DevToolsToggleAction {
+ DEVTOOLS_TOGGLE_ACTION_NONE,
+ DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE,
+ DEVTOOLS_TOGGLE_ACTION_INSPECT
+};
+
+#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_TOGGLE_ACTION_H_
diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc
index 56541e7..fc74431 100644
--- a/chrome/browser/debugger/devtools_window.cc
+++ b/chrome/browser/debugger/devtools_window.cc
@@ -57,11 +57,12 @@ DevToolsWindow::DevToolsWindow(Profile* profile,
browser_(NULL),
docked_(docked),
is_loaded_(false),
- open_console_on_load_(false) {
+ action_on_load_(DEVTOOLS_TOGGLE_ACTION_NONE) {
// Create TabContents with devtools.
tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL);
tab_contents_->render_view_host()->AllowBindings(BindingsPolicy::DOM_UI);
- tab_contents_->controller().LoadURL(GetDevToolsUrl(), GURL(), PageTransition::START_PAGE);
+ tab_contents_->controller().LoadURL(
+ GetDevToolsUrl(), GURL(), PageTransition::START_PAGE);
// Wipe out page icon so that the default application icon is used.
NavigationEntry* entry = tab_contents_->controller().GetActiveEntry();
@@ -115,7 +116,7 @@ void DevToolsWindow::InspectedTabClosing() {
}
}
-void DevToolsWindow::Show(bool open_console) {
+void DevToolsWindow::Show(DevToolsToggleAction action) {
if (docked_) {
// Just tell inspected browser to update splitter.
BrowserWindow* inspected_window = GetInspectedBrowserWindow();
@@ -124,8 +125,7 @@ void DevToolsWindow::Show(bool open_console) {
inspected_window->UpdateDevTools();
SetAttachedWindow();
tab_contents_->view()->SetInitialFocus();
- if (open_console)
- ScheduleOpenConsole();
+ ScheduleAction(action);
return;
} else {
// Sometimes we don't know where to dock. Stay undocked.
@@ -136,12 +136,17 @@ void DevToolsWindow::Show(bool open_console) {
if (!browser_)
CreateDevToolsBrowser();
- browser_->window()->Show();
+ // Avoid consecutive window switching if the devtools window has been opened
+ // and the Inspect Element shortcut is pressed in the inspected tab.
+ bool should_show_window =
+ !browser_ || action != DEVTOOLS_TOGGLE_ACTION_INSPECT;
+ if (should_show_window)
+ browser_->window()->Show();
SetAttachedWindow();
- tab_contents_->view()->SetInitialFocus();
+ if (should_show_window)
+ tab_contents_->view()->SetInitialFocus();
- if (open_console)
- ScheduleOpenConsole();
+ ScheduleAction(action);
}
void DevToolsWindow::Activate() {
@@ -180,7 +185,7 @@ void DevToolsWindow::SetDocked(bool docked) {
inspected_window = NULL;
}
}
- Show(false);
+ Show(DEVTOOLS_TOGGLE_ACTION_NONE);
}
RenderViewHost* DevToolsWindow::GetRenderViewHost() {
@@ -244,10 +249,7 @@ void DevToolsWindow::Observe(NotificationType type,
SetAttachedWindow();
is_loaded_ = true;
UpdateTheme();
- if (open_console_on_load_) {
- DoOpenConsole();
- open_console_on_load_ = false;
- }
+ DoAction();
} else if (type == NotificationType::TAB_CLOSING) {
if (Source<NavigationController>(source).ptr() ==
&tab_contents_->controller()) {
@@ -263,16 +265,30 @@ void DevToolsWindow::Observe(NotificationType type,
}
}
-void DevToolsWindow::ScheduleOpenConsole() {
+void DevToolsWindow::ScheduleAction(DevToolsToggleAction action) {
+ action_on_load_ = action;
if (is_loaded_)
- DoOpenConsole();
- else
- open_console_on_load_ = true;
+ DoAction();
}
-void DevToolsWindow::DoOpenConsole() {
- tab_contents_->render_view_host()->
- ExecuteJavascriptInWebFrame(L"", L"WebInspector.showConsole();");
+void DevToolsWindow::DoAction() {
+ // TODO: these messages should be pushed through the WebKit API instead.
+ switch (action_on_load_) {
+ case DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE:
+ tab_contents_->render_view_host()->
+ ExecuteJavascriptInWebFrame(L"", L"WebInspector.showConsole();");
+ break;
+ case DEVTOOLS_TOGGLE_ACTION_INSPECT:
+ tab_contents_->render_view_host()->
+ ExecuteJavascriptInWebFrame(
+ L"", L"WebInspector.toggleSearchingForNode();");
+ case DEVTOOLS_TOGGLE_ACTION_NONE:
+ // Do nothing.
+ break;
+ default:
+ NOTREACHED();
+ }
+ action_on_load_ = DEVTOOLS_TOGGLE_ACTION_NONE;
}
std::string SkColorToRGBAString(SkColor color) {
diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h
index fbd14dc..0bdcd67 100644
--- a/chrome/browser/debugger/devtools_window.h
+++ b/chrome/browser/debugger/devtools_window.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/debugger/devtools_client_host.h"
+#include "chrome/browser/debugger/devtools_toggle_action.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
@@ -40,7 +41,7 @@ class DevToolsWindow
virtual void SendMessageToClient(const IPC::Message& message);
virtual void InspectedTabClosing();
- void Show(bool open_console);
+ void Show(DevToolsToggleAction action);
void Activate();
void SetDocked(bool docked);
RenderViewHost* GetRenderViewHost();
@@ -59,8 +60,8 @@ class DevToolsWindow
const NotificationSource& source,
const NotificationDetails& details);
- void ScheduleOpenConsole();
- void DoOpenConsole();
+ void ScheduleAction(DevToolsToggleAction action);
+ void DoAction();
GURL GetDevToolsUrl();
void UpdateTheme();
@@ -96,7 +97,7 @@ class DevToolsWindow
Browser* browser_;
bool docked_;
bool is_loaded_;
- bool open_console_on_load_;
+ DevToolsToggleAction action_on_load_;
NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(DevToolsWindow);
};