summaryrefslogtreecommitdiff
path: root/chromium/ash/wm/window_selector.h
blob: 9cd1e04fd229e4beb98725ae8df90ebe518b2879 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2013 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.

#ifndef ASH_WM_WINDOW_SELECTOR_H_
#define ASH_WM_WINDOW_SELECTOR_H_

#include <vector>

#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "ui/aura/window_observer.h"
#include "ui/base/events/event_handler.h"
#include "ui/gfx/transform.h"

namespace aura {
class RootWindow;
}

namespace ui {
class LocatedEvent;
}

namespace views {
class Widget;
}

namespace ash {

class WindowSelectorDelegate;
class WindowSelectorWindow;

// The WindowSelector shows a grid of all of your windows and allows selecting
// a window by clicking or tapping on it (OVERVIEW mode) or by alt-tabbing to
// it (CYCLE mode).
class WindowSelector : public ui::EventHandler,
                       public aura::WindowObserver {
 public:
  enum Direction {
    FORWARD,
    BACKWARD
  };
  enum Mode {
    CYCLE,
    OVERVIEW
  };

  typedef std::vector<aura::Window*> WindowList;

  WindowSelector(const WindowList& windows,
                 Mode mode,
                 WindowSelectorDelegate* delegate);
  virtual ~WindowSelector();

  // Step to the next window in |direction|.
  void Step(Direction direction);

  // Select the current window.
  void SelectWindow();

  Mode mode() { return mode_; }

  // ui::EventHandler:
  virtual void OnEvent(ui::Event* event) OVERRIDE;
  virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
  virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;

  // aura::WindowObserver:
  virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;

 private:
  // Returns the target of |event| or NULL if the event is not targeted at
  // any of the windows in the selector.
  WindowSelectorWindow* GetEventTarget(ui::LocatedEvent* event);

  // Handles a selection event for |target|.
  void HandleSelectionEvent(WindowSelectorWindow* target);

  // Position all of the windows based on the current selection mode.
  void PositionWindows();
  // Position all of the windows from |root_window| on |root_window|.
  void PositionWindowsFromRoot(aura::RootWindow* root_window);
  // Position all of the |windows| to fit on the |root_window|.
  void PositionWindowsOnRoot(aura::RootWindow* root_window,
                             const std::vector<WindowSelectorWindow*>& windows);

  void InitializeSelectionWidget();

  // Updates the selection widget's location to the currently selected window.
  // If |animate| the transition to the new location is animated.
  void UpdateSelectionLocation(bool animate);

  // The collection of windows in the overview wrapped by a helper class which
  // restores their state and helps transform them to other root windows.
  ScopedVector<WindowSelectorWindow> windows_;

  // The window selection mode.
  Mode mode_;

  // Weak pointer to the selector delegate which will be called when a
  // selection is made.
  WindowSelectorDelegate* delegate_;

  // Index of the currently selected window if the mode is CYCLE.
  size_t selected_window_;

  // Widget indicating which window is currently selected.
  scoped_ptr<views::Widget> selection_widget_;

  // In CYCLE mode, the root window in which selection is taking place.
  // NULL otherwise.
  aura::RootWindow* selection_root_;

  DISALLOW_COPY_AND_ASSIGN(WindowSelector);
};

}  // namespace ash

#endif  // ASH_WM_WINDOW_SELECTOR_H_