Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: ash/focus_cycler.cc

Issue 9295049: Allow focus to be sent between browser window and launcher/status window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review fix Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/focus_cycler.h ('k') | ash/shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/focus_cycler.cc
diff --git a/ash/focus_cycler.cc b/ash/focus_cycler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..25f74f3b32c2b56986f09cba65108d737d7a8b4d
--- /dev/null
+++ b/ash/focus_cycler.cc
@@ -0,0 +1,101 @@
+// 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/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 {
+
+namespace internal {
+
+FocusCycler::FocusCycler() {
+}
+
+FocusCycler::~FocusCycler() {
+}
+
+void FocusCycler::AddWidget(views::Widget* widget) {
+ widgets_.push_back(widget);
+
+ widget->GetFocusManager()->RegisterAccelerator(
+ ui::Accelerator(ui::VKEY_F2, false, true, false), this);
+ widget->GetFocusManager()->RegisterAccelerator(
+ ui::Accelerator(ui::VKEY_F1, false, true, false), this);
+}
+
+void FocusCycler::RotateFocus(Direction direction) {
+ int index = 0;
+ int count = static_cast<int>(widgets_.size());
+ int browser_index = count;
+
+ for (; index < count; ++index) {
+ if (widgets_[index]->IsActive())
+ break;
+ }
+
+ int start_index = index;
+
+ count = count + 1;
+
+ for (;;) {
+ if (direction == FORWARD)
+ index = (index + 1) % count;
+ else
+ index = ((index - 1) + count) % count;
+
+ // Ensure that we don't loop more than once.
+ if (index == start_index)
+ break;
+
+ 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]);
+ break;
+ }
+ } else {
+ views::Widget* widget = widgets_[index];
+
+ views::AccessiblePaneView* view =
+ static_cast<views::AccessiblePaneView*>(widget->GetContentsView());
+ if (view->SetPaneFocusAndFocusDefault()) {
+ widget->Activate();
+ if (widget->IsActive())
+ break;
+ }
+ }
+ }
+}
+
+bool FocusCycler::AcceleratorPressed(const ui::Accelerator& accelerator) {
+ switch (accelerator.key_code()) {
+ case ui::VKEY_F1:
+ RotateFocus(BACKWARD);
+ return true;
+ case ui::VKEY_F2:
+ RotateFocus(FORWARD);
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool FocusCycler::CanHandleAccelerators() const {
+ return true;
+}
+
+} // namespace internal
+
+} // namespace ash
« no previous file with comments | « ash/focus_cycler.h ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698