window_selector_item.h revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// found in the LICENSE file.
4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#ifndef ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#define ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
8d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "base/compiler_specific.h"
90529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "base/memory/scoped_ptr.h"
100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "base/strings/string16.h"
11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/rect.h"
12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace aura {
14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class Window;
15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace views {
180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass Widget;
190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace ash {
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class TransparentActivateWindowButton;
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// This class represents an item in overview mode. An item can have one or more
25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// windows, of which only one can be activated by keyboard (i.e. alt+tab) but
26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// any can be selected with a pointer (touch or mouse).
27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class WindowSelectorItem {
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) public:
29d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  WindowSelectorItem();
30d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual ~WindowSelectorItem();
31d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // The time for the close buttons and labels to fade in when initially shown
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // on entering overview mode.
340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  static const int kFadeInMilliseconds;
350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
36d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns the root window on which this item is shown.
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual aura::Window* GetRootWindow() = 0;
38d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns true if the window selector item has |window| as a selectable
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // window.
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool HasSelectableWindow(const aura::Window* window) = 0;
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
43cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Returns true if |target| is contained in this WindowSelectorItem.
44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual bool Contains(const aura::Window* target) = 0;
45d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Restores |window| on exiting window overview rather than returning it
47d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // to its previous state.
48d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void RestoreWindowOnExit(aura::Window* window) = 0;
49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns the |window| to activate on selecting of this item.
51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual aura::Window* SelectionWindow() = 0;
52d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Removes |window| from this item. Check empty() after calling this to see
54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // if the entire item is now empty.
55d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void RemoveWindow(const aura::Window* window) = 0;
56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns true if this item has no more selectable windows (i.e. after
58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // calling RemoveWindow for the last contained window).
59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual bool empty() const = 0;
60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Dispatched before beginning window overview. This will do any necessary
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // one time actions such as restoring minimized windows.
634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void PrepareForOverview() = 0;
644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Sets the bounds of this window selector item to |target_bounds| in the
66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // |root_window| root window.
671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void SetBounds(aura::Window* root_window,
685c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                 const gfx::Rect& target_bounds,
695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                 bool animate);
70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Recomputes the positions for the windows in this selection item. This is
724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // dispatched when the bounds of a window change.
734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void RecomputeWindowTransforms();
744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
7546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Sends an a11y focus alert so that, if chromevox is enabled, the window
7646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // label is read.
7746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void SendFocusAlert() const;
7846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  const gfx::Rect& bounds() { return bounds_; }
801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  const gfx::Rect& target_bounds() { return target_bounds_; }
81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) protected:
83cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Sets the bounds of this selector's items to |target_bounds| in
84cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // |root_window|. If |animate| the windows are animated from their current
85cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // location.
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void SetItemBounds(aura::Window* root_window,
874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             const gfx::Rect& target_bounds,
884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             bool animate) = 0;
89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Sets the bounds used by the selector item's windows.
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; }
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
93d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) private:
940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  friend class WindowSelectorTest;
950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Creates a label to display under the window selector item.
975c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  void UpdateWindowLabels(const gfx::Rect& target_bounds,
985c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                          aura::Window* root_window,
995c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                          bool animate);
1005c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The root window this item is being displayed on.
1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root_window_;
1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The target bounds this selector item is fit within.
1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  gfx::Rect target_bounds_;
1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The actual bounds of the window(s) for this item. The aspect ratio of
1081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // window(s) are maintained so they may not fill the target_bounds_.
109d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Rect bounds_;
110d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // True if running SetItemBounds. This prevents recursive calls resulting from
112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the bounds update when calling ::wm::RecreateWindowLayers to copy
1134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // a window layer for display on another monitor.
1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool in_bounds_update_;
1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Label under the window displaying its active tab name.
1170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  scoped_ptr<views::Widget> window_label_;
1180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
119cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Transparent window on top of the real windows in the overview that
120cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // activates them on click or tap.
121cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<TransparentActivateWindowButton> activate_window_button_;
122cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
123d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WindowSelectorItem);
124d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)};
125d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
126d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}  // namespace ash
127d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
128d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
129