window_selector_item.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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 {
22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// This class represents an item in overview mode. An item can have one or more
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// windows, of which only one can be activated by keyboard (i.e. alt+tab) but
25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// any can be selected with a pointer (touch or mouse).
26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class WindowSelectorItem {
27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) public:
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  WindowSelectorItem();
29d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual ~WindowSelectorItem();
30d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // The time for the close buttons and labels to fade in when initially shown
320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // on entering overview mode.
330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  static const int kFadeInMilliseconds;
340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
35d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns the root window on which this item is shown.
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual aura::Window* GetRootWindow() = 0;
37d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns true if the window selector item has |window| as a selectable
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // window.
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual bool HasSelectableWindow(const aura::Window* window) = 0;
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
42d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns the targeted window given the event |target| window.
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Returns NULL if no Window in this item was selected.
44d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual aura::Window* TargetedWindow(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)
75d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  const gfx::Rect& bounds() { return bounds_; }
761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  const gfx::Rect& target_bounds() { return target_bounds_; }
77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) protected:
794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Sets the bounds of this selector item to |target_bounds| in |root_window|.
804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // If |animate| the windows are animated from their current location.
811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void SetItemBounds(aura::Window* root_window,
824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             const gfx::Rect& target_bounds,
834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                             bool animate) = 0;
84d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Sets the bounds used by the selector item's windows.
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; }
871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) private:
890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  friend class WindowSelectorTest;
900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // Creates a label to display under the window selector item.
925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  void UpdateWindowLabels(const gfx::Rect& target_bounds,
935c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                          aura::Window* root_window,
945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                          bool animate);
955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The root window this item is being displayed on.
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* root_window_;
981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The target bounds this selector item is fit within.
1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  gfx::Rect target_bounds_;
1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The actual bounds of the window(s) for this item. The aspect ratio of
1031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // window(s) are maintained so they may not fill the target_bounds_.
104d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  gfx::Rect bounds_;
105d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // True if running SetItemBounds. This prevents recursive calls resulting from
107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the bounds update when calling ::wm::RecreateWindowLayers to copy
1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // a window layer for display on another monitor.
1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool in_bounds_update_;
1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Label under the window displaying its active tab name.
1120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  scoped_ptr<views::Widget> window_label_;
1130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
114d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WindowSelectorItem);
115d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)};
116d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
117d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}  // namespace ash
118d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
119d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif  // ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
120