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"
10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/rect.h"
11f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "ui/views/controls/button/button.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).
27f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)class WindowSelectorItem : public views::ButtonListener {
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.
55f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void RemoveWindow(const aura::Window* window);
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)
79f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const gfx::Rect& bounds() const { return bounds_; }
80f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  const gfx::Rect& target_bounds() const { return target_bounds_; }
81f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
82f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // views::ButtonListener:
83f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual void ButtonPressed(views::Button* sender,
84f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             const ui::Event& event) OVERRIDE;
85d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) protected:
87cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Sets the bounds of this selector's items to |target_bounds| in
88cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // |root_window|. If |animate| the windows are animated from their current
89cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // location.
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void SetItemBounds(aura::Window* root_window,
914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             const gfx::Rect& target_bounds,
924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             bool animate) = 0;
93d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Sets the bounds used by the selector item's windows.
951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; }
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) private:
980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  friend class WindowSelectorTest;
990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
100f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Creates |close_button_| if it does not exist and updates the bounds based
101f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // on GetCloseButtonTargetBounds()
102f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void UpdateCloseButtonBounds(aura::Window* root_window, bool animate);
103f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Creates a label to display under the window selector item.
1055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  void UpdateWindowLabels(const gfx::Rect& target_bounds,
1065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                          aura::Window* root_window,
1075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                          bool animate);
1085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The root window this item is being displayed on.
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root_window_;
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The target bounds this selector item is fit within.
1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  gfx::Rect target_bounds_;
1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The actual bounds of the window(s) for this item. The aspect ratio of
1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // window(s) are maintained so they may not fill the target_bounds_.
117d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Rect bounds_;
118d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // True if running SetItemBounds. This prevents recursive calls resulting from
120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the bounds update when calling ::wm::RecreateWindowLayers to copy
1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // a window layer for display on another monitor.
1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool in_bounds_update_;
1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Label under the window displaying its active tab name.
1250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  scoped_ptr<views::Widget> window_label_;
1260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
127f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // An easy to access close button for the window in this item.
128f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  scoped_ptr<views::Widget> close_button_;
129f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
130cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Transparent window on top of the real windows in the overview that
131cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // activates them on click or tap.
132cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  scoped_ptr<TransparentActivateWindowButton> activate_window_button_;
133cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
134d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WindowSelectorItem);
135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)};
136d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
137d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}  // namespace ash
138d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
140