Commit 52dc056c authored by jianli@chromium.org's avatar jianli@chromium.org

Accelerator support for browserless panels on Windows.

BUG=127323
TEST=New test


Review URL: https://chromiumcodereview.appspot.com/10825210

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150420 0039d316-1c4b-4281-b951-d872f2087c98
parent c0c7376e
...@@ -552,6 +552,16 @@ void Panel::ExecuteCommandWithDisposition(int id, ...@@ -552,6 +552,16 @@ void Panel::ExecuteCommandWithDisposition(int id,
panel_host_->StopLoading(); panel_host_->StopLoading();
break; break;
// Window management
case IDC_CLOSE_WINDOW:
content::RecordAction(UserMetricsAction("CloseWindow"));
Close();
break;
case IDC_EXIT:
content::RecordAction(UserMetricsAction("Exit"));
browser::AttemptUserExit();
break;
// Clipboard // Clipboard
case IDC_COPY: case IDC_COPY:
content::RecordAction(UserMetricsAction("Copy")); content::RecordAction(UserMetricsAction("Copy"));
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
...@@ -1579,4 +1580,37 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ...@@ -1579,4 +1580,37 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest,
panel->Close(); panel->Close();
} }
#if defined(OS_WIN)
#define MAYBE_Accelerator Accelerator
#else
#define MAYBE_Accelerator DISABLED_Accelerator
#endif
IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_Accelerator) {
PanelManager* panel_manager = PanelManager::GetInstance();
// Create a test panel with web contents loaded.
CreatePanelParams params("1", gfx::Rect(), SHOW_AS_ACTIVE);
GURL url(ui_test_utils::GetTestUrl(
FilePath(kTestDir),
FilePath(FILE_PATH_LITERAL("update-preferred-size.html"))));
params.url = url;
Panel* panel = CreatePanelWithParams(params);
EXPECT_EQ(1, panel_manager->num_panels());
// Close the panel by acclerator.
content::WindowedNotificationObserver signal(
chrome::NOTIFICATION_PANEL_CLOSED,
content::Source<Panel>(panel));
#if defined(OS_WIN)
::MSG key_msg = { NULL, WM_KEYDOWN, ui::VKEY_W, 0 };
content::NativeWebKeyboardEvent key_event(key_msg);
key_event.modifiers = content::NativeWebKeyboardEvent::ControlKey;
#else
content::NativeWebKeyboardEvent key_event;
#endif
panel->HandleKeyboardEvent(key_event);
signal.Wait();
EXPECT_EQ(0, panel_manager->num_panels());
}
#endif // OS_WIN || OS_MACOSX #endif // OS_WIN || OS_MACOSX
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/ui/panels/panel_view.h" #include "chrome/browser/ui/panels/panel_view.h"
#include "base/logging.h" #include "base/logging.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_bounds_animation.h" #include "chrome/browser/ui/panels/panel_bounds_animation.h"
#include "chrome/browser/ui/panels/panel_frame_view.h" #include "chrome/browser/ui/panels/panel_frame_view.h"
...@@ -24,6 +25,33 @@ ...@@ -24,6 +25,33 @@
namespace { namespace {
// Supported accelerators.
// Note: We can't use the acclerator table defined in chrome/browser/ui/views
// due to checkdeps violation.
struct AcceleratorMapping {
ui::KeyboardCode keycode;
int modifiers;
int command_id;
};
const AcceleratorMapping kPanelAcceleratorMap[] = {
{ ui::VKEY_W, ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW },
{ ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN, IDC_CLOSE_WINDOW },
{ ui::VKEY_F4, ui::EF_ALT_DOWN, IDC_CLOSE_WINDOW },
{ ui::VKEY_R, ui::EF_CONTROL_DOWN, IDC_RELOAD },
{ ui::VKEY_F5, ui::EF_NONE, IDC_RELOAD },
{ ui::VKEY_R, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
IDC_RELOAD_IGNORING_CACHE },
{ ui::VKEY_F5, ui::EF_CONTROL_DOWN, IDC_RELOAD_IGNORING_CACHE },
{ ui::VKEY_F5, ui::EF_SHIFT_DOWN, IDC_RELOAD_IGNORING_CACHE },
{ ui::VKEY_ESCAPE, ui::EF_NONE, IDC_STOP },
{ ui::VKEY_OEM_MINUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS },
{ ui::VKEY_SUBTRACT, ui::EF_CONTROL_DOWN, IDC_ZOOM_MINUS },
{ ui::VKEY_0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL },
{ ui::VKEY_NUMPAD0, ui::EF_CONTROL_DOWN, IDC_ZOOM_NORMAL },
{ ui::VKEY_OEM_PLUS, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS },
{ ui::VKEY_ADD, ui::EF_CONTROL_DOWN, IDC_ZOOM_PLUS },
};
// NativePanelTesting implementation. // NativePanelTesting implementation.
class NativePanelTestingWin : public NativePanelTesting { class NativePanelTestingWin : public NativePanelTesting {
public: public:
...@@ -116,6 +144,9 @@ NativePanel* Panel::CreateNativePanel(Panel* panel, const gfx::Rect& bounds) { ...@@ -116,6 +144,9 @@ NativePanel* Panel::CreateNativePanel(Panel* panel, const gfx::Rect& bounds) {
return new PanelView(panel, bounds); return new PanelView(panel, bounds);
} }
// static
std::map<ui::Accelerator, int> PanelView::accelerator_table_;
PanelView::PanelView(Panel* panel, const gfx::Rect& bounds) PanelView::PanelView(Panel* panel, const gfx::Rect& bounds)
: panel_(panel), : panel_(panel),
window_(NULL), window_(NULL),
...@@ -142,10 +173,23 @@ PanelView::PanelView(Panel* panel, const gfx::Rect& bounds) ...@@ -142,10 +173,23 @@ PanelView::PanelView(Panel* panel, const gfx::Rect& bounds)
OnViewWasResized(); OnViewWasResized();
// Do a one-time initialization for the accelerator table.
if (accelerator_table_.empty()) {
for (size_t i = 0; i < arraysize(kPanelAcceleratorMap); ++i) {
ui::Accelerator accelerator(kPanelAcceleratorMap[i].keycode,
kPanelAcceleratorMap[i].modifiers);
accelerator_table_[accelerator] = kPanelAcceleratorMap[i].command_id;
}
}
// Register accelarators supported by panels.
views::FocusManager* focus_manager = GetFocusManager(); views::FocusManager* focus_manager = GetFocusManager();
ui::Accelerator accelerator(ui::VKEY_ESCAPE, ui::EF_NONE); for (std::map<ui::Accelerator, int>::const_iterator iter =
focus_manager->RegisterAccelerator( accelerator_table_.begin();
accelerator, ui::AcceleratorManager::kNormalPriority, this); iter != accelerator_table_.end(); ++iter) {
focus_manager->RegisterAccelerator(
iter->first, ui::AcceleratorManager::kNormalPriority, this);
}
} }
PanelView::~PanelView() { PanelView::~PanelView() {
...@@ -306,6 +350,16 @@ bool PanelView::PreHandlePanelKeyboardEvent( ...@@ -306,6 +350,16 @@ bool PanelView::PreHandlePanelKeyboardEvent(
void PanelView::HandlePanelKeyboardEvent( void PanelView::HandlePanelKeyboardEvent(
const content::NativeWebKeyboardEvent& event) { const content::NativeWebKeyboardEvent& event) {
views::FocusManager* focus_manager = GetFocusManager();
if (focus_manager->shortcut_handling_suspended())
return;
ui::Accelerator accelerator(
static_cast<ui::KeyboardCode>(event.windowsKeyCode),
content::GetModifiersFromNativeWebKeyboardEvent(event));
if (event.type == WebKit::WebInputEvent::KeyUp)
accelerator.set_type(ui::ET_KEY_RELEASED);
focus_manager->ProcessAccelerator(accelerator);
} }
void PanelView::FullScreenModeChanged(bool is_full_screen) { void PanelView::FullScreenModeChanged(bool is_full_screen) {
...@@ -519,7 +573,10 @@ bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) { ...@@ -519,7 +573,10 @@ bool PanelView::AcceleratorPressed(const ui::Accelerator& accelerator) {
if (mouse_dragging_state_ == DRAGGING_STARTED) if (mouse_dragging_state_ == DRAGGING_STARTED)
return true; return true;
return views::View::AcceleratorPressed(accelerator); std::map<ui::Accelerator, int>::const_iterator iter =
accelerator_table_.find(accelerator);
DCHECK(iter != accelerator_table_.end());
return panel_->ExecuteCommandIfEnabled(iter->second);
} }
void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) { void PanelView::OnWidgetActivationChanged(views::Widget* widget, bool active) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_UI_PANELS_PANEL_VIEW_H_ #ifndef CHROME_BROWSER_UI_PANELS_PANEL_VIEW_H_
#define CHROME_BROWSER_UI_PANELS_PANEL_VIEW_H_ #define CHROME_BROWSER_UI_PANELS_PANEL_VIEW_H_
#include <map>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/panels/native_panel.h" #include "chrome/browser/ui/panels/native_panel.h"
#include "ui/base/animation/animation_delegate.h" #include "ui/base/animation/animation_delegate.h"
...@@ -191,6 +192,9 @@ class PanelView : public NativePanel, ...@@ -191,6 +192,9 @@ class PanelView : public NativePanel,
// be restored properly when a drag ends. // be restored properly when a drag ends.
views::View* old_focused_view_; views::View* old_focused_view_;
// A mapping between accelerators and commands.
static std::map<ui::Accelerator, int> accelerator_table_;
#if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA) #if defined(OS_WIN) && !defined(USE_ASH) && !defined(USE_AURA)
// Used to provide custom taskbar thumbnail for Windows 7 and later. // Used to provide custom taskbar thumbnail for Windows 7 and later.
scoped_ptr<TaskbarWindowThumbnailerWin> thumbnailer_; scoped_ptr<TaskbarWindowThumbnailerWin> thumbnailer_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment