Index: ash/focus_cycler.cc |
diff --git a/ash/focus_cycler.cc b/ash/focus_cycler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..eeada91b34f172b33f34a575d264123c1923309f |
--- /dev/null |
+++ b/ash/focus_cycler.cc |
@@ -0,0 +1,90 @@ |
+// Copyright (c) 2012 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. |
+ |
+#include "ash/focus_cycler.h" |
+ |
+#include "ash/accelerators/accelerator_controller.h" |
+#include "ash/shell.h" |
+#include "ash/shell_delegate.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/views/focus/focus_search.h" |
+#include "ui/aura/window.h" |
+#include "ui/aura/client/activation_client.h" |
+ |
+#include "ui/views/accessible_pane_view.h" |
+ |
+namespace ash { |
+ |
+FocusCycler::FocusCycler() |
+ : ctrl_forward_key_(ui::VKEY_F2, false, true, false), |
+ ctrl_back_key_(ui::VKEY_F1, false, true, false) { |
+} |
+ |
+FocusCycler::~FocusCycler() { |
+} |
+ |
+void FocusCycler::AddWidget(views::Widget* widget) { |
+ widgets_.push_back(widget); |
+ |
+ widget->GetFocusManager()->RegisterAccelerator(ctrl_forward_key_, this); |
+ widget->GetFocusManager()->RegisterAccelerator(ctrl_back_key_, this); |
+} |
+ |
+bool FocusCycler::AcceleratorPressed(const ui::Accelerator& accelerator) { |
+ switch (accelerator.key_code()) { |
+ case ui::VKEY_F1: |
+ RotateFocus(false); |
+ return true; |
+ case ui::VKEY_F2: |
+ RotateFocus(true); |
+ return true; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+bool FocusCycler::CanHandleAccelerators() const { |
sky
2012/01/31 16:38:15
Make order match that of header.
Zachary Kuznia
2012/01/31 17:57:42
Done.
|
+ return true; |
+} |
+ |
+void FocusCycler::RotateFocus(bool forwards) { |
+ int index = 0; |
+ int count = static_cast<int>(widgets_.size()); |
+ int browser_index = count; |
+ |
+ for (; index < count; ++index) { |
+ if (widgets_[index]->IsActive()) |
+ break; |
+ } |
+ |
+ count = count + 1; |
+ |
+ if (forwards) |
+ index = (index + 1) % count; |
+ else |
+ index = ((index - 1) + count) % count; |
+ |
+ if (index == browser_index) { |
+ // Activate the browser window. |
+ const std::vector<aura::Window*>& windows = |
+ Shell::GetInstance()->delegate()->GetCycleWindowList( |
+ ShellDelegate::SOURCE_LAUNCHER, ShellDelegate::ORDER_MRU); |
+ if (!windows.empty()) { |
+ aura::client::GetActivationClient()->ActivateWindow(windows[0]); |
+ return; |
sky
2012/01/31 16:38:15
remove the early return here and 85.
Zachary Kuznia
2012/01/31 17:57:42
Changed to break to exit the loop. The loop is ad
|
+ } |
+ |
+ } else { |
+ views::Widget* widget = widgets_[index]; |
+ |
+ views::AccessiblePaneView* view = |
+ static_cast<views::AccessiblePaneView*>(widget->GetContentsView()); |
+ if (view->SetPaneFocusAndFocusDefault()) { |
+ widget->Activate(); |
+ return; |
+ } |
+ } |
+} |
+ |
+} // namespace ash |