summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-04 23:28:03 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-04 23:28:03 +0000
commitfb3158d1941397fc7183021782c4bceb9a02d587 (patch)
tree282786b733bead1f15ec5d7b2bb3ac499062b453
parentd5fe92d7cd93f80591ddfe7bb27ca43e6cea2be6 (diff)
downloadchromium_src-fb3158d1941397fc7183021782c4bceb9a02d587.zip
chromium_src-fb3158d1941397fc7183021782c4bceb9a02d587.tar.gz
chromium_src-fb3158d1941397fc7183021782c4bceb9a02d587.tar.bz2
Committing pierre.lafayette patch, see:
http://codereview.chromium.org/159804 Adding support for Ctrl+Tab and Ctrl+Shift+Tab navigation of TabbedPane tabs. This will make the tabbed dialogs consistent with the TabStrip functionality. BUG=6761 TEST=none Review URL: http://codereview.chromium.org/160607 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22440 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--views/controls/tabbed_pane/tabbed_pane.cc27
-rw-r--r--views/controls/tabbed_pane/tabbed_pane.h5
2 files changed, 32 insertions, 0 deletions
diff --git a/views/controls/tabbed_pane/tabbed_pane.cc b/views/controls/tabbed_pane/tabbed_pane.cc
index 20a2e7a..78ed6d2 100644
--- a/views/controls/tabbed_pane/tabbed_pane.cc
+++ b/views/controls/tabbed_pane/tabbed_pane.cc
@@ -4,6 +4,7 @@
#include "views/controls/tabbed_pane/tabbed_pane.h"
+#include "base/logging.h"
#include "views/controls/tabbed_pane/native_tabbed_pane_wrapper.h"
namespace views {
@@ -67,9 +68,35 @@ void TabbedPane::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
if (is_add && !native_tabbed_pane_ && GetWidget()) {
CreateWrapper();
AddChildView(native_tabbed_pane_->GetView());
+ LoadAccelerators();
}
}
+bool TabbedPane::AcceleratorPressed(const views::Accelerator& accelerator) {
+ // We only accept Ctrl+Tab keyboard events.
+ DCHECK(accelerator.GetKeyCode() == VK_TAB && accelerator.IsCtrlDown());
+
+ int tab_count = GetTabCount();
+ if (tab_count <= 1)
+ return false;
+ int selected_tab_index = GetSelectedTabIndex();
+ int next_tab_index = accelerator.IsShiftDown() ?
+ (selected_tab_index - 1) % tab_count :
+ (selected_tab_index + 1) % tab_count;
+ // Wrap around.
+ if (next_tab_index < 0)
+ next_tab_index += tab_count;
+ SelectTabAt(next_tab_index);
+ return true;
+}
+
+void TabbedPane::LoadAccelerators() {
+ // Ctrl+Shift+Tab
+ AddAccelerator(views::Accelerator(VK_TAB, true, true, false));
+ // Ctrl+Tab
+ AddAccelerator(views::Accelerator(VK_TAB, false, true, false));
+}
+
void TabbedPane::Layout() {
if (native_tabbed_pane_) {
native_tabbed_pane_->GetView()->SetBounds(0, 0, width(), height());
diff --git a/views/controls/tabbed_pane/tabbed_pane.h b/views/controls/tabbed_pane/tabbed_pane.h
index f0eb5a5..e713ff8 100644
--- a/views/controls/tabbed_pane/tabbed_pane.h
+++ b/views/controls/tabbed_pane/tabbed_pane.h
@@ -65,6 +65,8 @@ class TabbedPane : public View {
// View overrides:
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
+ // Handles Ctrl+Tab and Ctrl+Shift+Tab navigation of pages.
+ virtual bool AcceleratorPressed(const views::Accelerator& accelerator);
virtual std::string GetClassName() const;
virtual void Layout();
virtual void Focus();
@@ -81,6 +83,9 @@ class TabbedPane : public View {
// Creates the native wrapper.
void CreateWrapper();
+ // We support Ctrl+Tab and Ctrl+Shift+Tab to navigate tabbed option pages.
+ void LoadAccelerators();
+
// The listener we notify about tab selection changes.
Listener* listener_;