summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorklink@chromium.org <klink@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 21:31:34 +0000
committerklink@chromium.org <klink@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-31 21:31:34 +0000
commit042811ccf79795d7847a672345770b801987c217 (patch)
tree6f59fb637cb512177dffdd530745b3beaca4f628 /chrome
parent6b1731c04c7855f0b03e0b52279f6ad114746158 (diff)
downloadchromium_src-042811ccf79795d7847a672345770b801987c217.zip
chromium_src-042811ccf79795d7847a672345770b801987c217.tar.gz
chromium_src-042811ccf79795d7847a672345770b801987c217.tar.bz2
Adds support for keyboard-triggered (through VK_APPS and SHIFT+VK_F10) right-click menu, specifically on the toolbar's back/forward buttons.
Review URL: http://codereview.chromium.org/8942 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4326 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/views/toolbar_view.cc9
-rw-r--r--chrome/browser/views/toolbar_view.h5
-rw-r--r--chrome/views/button_dropdown.cc12
-rw-r--r--chrome/views/button_dropdown.h7
-rw-r--r--chrome/views/container_win.h2
-rw-r--r--chrome/views/root_view.cc13
-rw-r--r--chrome/views/view.cc7
-rw-r--r--chrome/views/view.h10
8 files changed, 63 insertions, 2 deletions
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index d87e205..589fa98 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -315,7 +315,7 @@ void BrowserToolbarView::Layout() {
// Make sure the Page menu never overlaps the location bar.
int page_x = go_->x() + go_->width() + kMenuButtonOffset;
sz = page_menu_->GetPreferredSize();
- page_menu_->SetBounds(page_x, kControlVertOffset, sz.width(),
+ page_menu_->SetBounds(page_x, kControlVertOffset, sz.width(),
go_->height());
sz = app_menu_->GetPreferredSize();
app_menu_->SetBounds(page_menu_->x() + page_menu_->width(),
@@ -339,7 +339,7 @@ void BrowserToolbarView::DidGainFocus() {
// Set hot-tracking for child, and update focused_view for MSAA focus event.
if (acc_focused_view_) {
acc_focused_view_->SetHotTracked(true);
-
+
// Show the tooltip for the view that got the focus.
if (GetContainer()->GetTooltipManager()) {
GetContainer()->GetTooltipManager()->
@@ -640,6 +640,11 @@ int BrowserToolbarView::GetNextAccessibleViewIndex(int view_index,
return view_index;
}
+void BrowserToolbarView::ShowContextMenu(int x, int y, bool is_mouse_gesture) {
+ if (GetAccFocusedChildView())
+ GetAccFocusedChildView()->ShowContextMenu(x, y, is_mouse_gesture);
+}
+
int BrowserToolbarView::GetDragOperations(views::View* sender, int x, int y) {
DCHECK(sender == star_);
if (model_->input_in_progress() || !tab_ || !tab_->ShouldDisplayURL() ||
diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h
index a475320..6358e7a 100644
--- a/chrome/browser/views/toolbar_view.h
+++ b/chrome/browser/views/toolbar_view.h
@@ -135,6 +135,11 @@ class BrowserToolbarView : public views::View,
// Show the app menu.
void RunAppMenu(const CPoint& pt, HWND hwnd);
+ // Overridden from View, to pass keyboard triggering of the right-click
+ // context menu on to the toolbar child view that currently has the
+ // accessibility focus.
+ virtual void ShowContextMenu(int x, int y, bool is_mouse_gesture);
+
// Types of display mode this toolbar can have.
enum DisplayMode {
DISPLAYMODE_NORMAL,
diff --git a/chrome/views/button_dropdown.cc b/chrome/views/button_dropdown.cc
index eb97d8f..2b07def 100644
--- a/chrome/views/button_dropdown.cc
+++ b/chrome/views/button_dropdown.cc
@@ -104,6 +104,18 @@ bool ButtonDropDown::OnMouseDragged(const MouseEvent& e) {
//
////////////////////////////////////////////////////////////////////////////////
+void ButtonDropDown::ShowContextMenu(int x, int y, bool is_mouse_gesture) {
+ show_menu_factory_.RevokeAll();
+ // Make the button look depressed while the menu is open.
+ // NOTE: SetState() schedules a paint, but it won't occur until after the
+ // context menu message loop has terminated, so we PaintNow() to
+ // update the appearance synchronously.
+ SetState(BS_PUSHED);
+ PaintNow();
+ ShowDropDownMenu(GetContainer()->GetHWND());
+ SetState(BS_HOT);
+}
+
void ButtonDropDown::ShowDropDownMenu(HWND window) {
if (menu_delegate_) {
gfx::Rect lb = GetLocalBounds(true);
diff --git a/chrome/views/button_dropdown.h b/chrome/views/button_dropdown.h
index 4f8727d..eac7e418 100644
--- a/chrome/views/button_dropdown.h
+++ b/chrome/views/button_dropdown.h
@@ -47,6 +47,13 @@ class ButtonDropDown : public Button {
virtual void OnMouseReleased(const MouseEvent& e, bool canceled);
virtual bool OnMouseDragged(const MouseEvent& e);
+ // Overridden from View. Used to display the right-click menu, as triggered
+ // by the keyboard, for instance. Using the member function ShowDropDownMenu
+ // for the actual display.
+ virtual void ShowContextMenu(int x,
+ int y,
+ bool is_mouse_gesture);
+
// Internal function to show the dropdown menu
void ShowDropDownMenu(HWND window);
diff --git a/chrome/views/container_win.h b/chrome/views/container_win.h
index d1d1272..84309b9 100644
--- a/chrome/views/container_win.h
+++ b/chrome/views/container_win.h
@@ -198,6 +198,8 @@ class ContainerWin : public Container,
MSG_WM_INITMENUPOPUP(OnInitMenuPopup)
MSG_WM_KEYDOWN(OnKeyDown)
MSG_WM_KEYUP(OnKeyUp)
+ MSG_WM_SYSKEYDOWN(OnKeyDown)
+ MSG_WM_SYSKEYUP(OnKeyUp)
MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk)
MSG_WM_LBUTTONDOWN(OnLButtonDown)
MSG_WM_LBUTTONUP(OnLButtonUp)
diff --git a/chrome/views/root_view.cc b/chrome/views/root_view.cc
index 33597f9..11f86d0 100644
--- a/chrome/views/root_view.cc
+++ b/chrome/views/root_view.cc
@@ -797,7 +797,20 @@ bool RootView::IsViewFocusableCandidate(View* v, int skip_group_id) {
void RootView::ProcessKeyEvent(const KeyEvent& event) {
View* v;
bool consumed = false;
+
if (GetFocusedView()) {
+ // Special case to handle right-click context menus triggered by the
+ // keyboard.
+ if ((event.GetCharacter() == VK_APPS) ||
+ (event.GetCharacter() == VK_F10 && event.IsShiftDown())) {
+ v = GetFocusedView();
+ if (v->IsEnabled()) {
+ v->ShowContextMenu(v->x() + (v->width() / 2),
+ v->y() + (v->height() / 2), false);
+ return;
+ }
+ }
+
for (v = GetFocusedView();
v && v != this && !consumed; v = v->GetParent()) {
if (event.GetType() == Event::ET_KEY_PRESSED)
diff --git a/chrome/views/view.cc b/chrome/views/view.cc
index 7dff258..9fccd77 100644
--- a/chrome/views/view.cc
+++ b/chrome/views/view.cc
@@ -477,6 +477,13 @@ void View::SetContextMenuController(ContextMenuController* menu_controller) {
context_menu_controller_ = menu_controller;
}
+void View::ShowContextMenu(int x, int y, bool is_mouse_gesture) {
+ if (!context_menu_controller_)
+ return;
+
+ context_menu_controller_->ShowContextMenu(this, x, y, is_mouse_gesture);
+}
+
/////////////////////////////////////////////////////////////////////////////
//
// View - tree
diff --git a/chrome/views/view.h b/chrome/views/view.h
index ff378b7..0a6ad31 100644
--- a/chrome/views/view.h
+++ b/chrome/views/view.h
@@ -864,6 +864,16 @@ class View : public AcceleratorTarget {
return context_menu_controller_;
}
+ // Provides default implementation for context menu handling. The default
+ // implementation calls the ShowContextMenu of the current
+ // ContextMenuController (if it is not NULL). Overridden in subclassed views
+ // to provide right-click menu display triggerd by the keyboard (i.e. for the
+ // Chrome toolbar Back and Forward buttons). No source needs to be specified,
+ // as it is always equal to the current View.
+ virtual void ShowContextMenu(int x,
+ int y,
+ bool is_mouse_gesture);
+
// Set the background. The background is owned by the view after this call.
virtual void SetBackground(Background* b);