Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / wm / overview / window_selector_item.h
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
6 #define ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
7
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/aura/window_observer.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/views/controls/button/button.h"
13
14 namespace aura {
15 class Window;
16 }
17
18 namespace views {
19 class Label;
20 class Widget;
21 }
22
23 namespace ash {
24 class TransparentActivateWindowButton;
25
26 // This class represents an item in overview mode. An item can have one or more
27 // windows, of which only one can be activated by keyboard (i.e. alt+tab) but
28 // any can be selected with a pointer (touch or mouse).
29 class WindowSelectorItem : public views::ButtonListener,
30                            public aura::WindowObserver {
31  public:
32   WindowSelectorItem();
33   ~WindowSelectorItem() override;
34
35   // The time for the close buttons and labels to fade in when initially shown
36   // on entering overview mode.
37   static const int kFadeInMilliseconds;
38
39   // Returns the root window on which this item is shown.
40   virtual aura::Window* GetRootWindow() = 0;
41
42   // Returns true if the window selector item has |window| as a selectable
43   // window.
44   virtual bool HasSelectableWindow(const aura::Window* window) = 0;
45
46   // Returns true if |target| is contained in this WindowSelectorItem.
47   virtual bool Contains(const aura::Window* target) = 0;
48
49   // Restores |window| on exiting window overview rather than returning it
50   // to its previous state.
51   virtual void RestoreWindowOnExit(aura::Window* window) = 0;
52
53   // Returns the |window| to activate on selecting of this item.
54   virtual aura::Window* SelectionWindow() = 0;
55
56   // Removes |window| from this item. Check empty() after calling this to see
57   // if the entire item is now empty.
58   virtual void RemoveWindow(const aura::Window* window);
59
60   // Returns true if this item has no more selectable windows (i.e. after
61   // calling RemoveWindow for the last contained window).
62   virtual bool empty() const = 0;
63
64   // Dispatched before beginning window overview. This will do any necessary
65   // one time actions such as restoring minimized windows.
66   virtual void PrepareForOverview() = 0;
67
68   // Sets the bounds of this window selector item to |target_bounds| in the
69   // |root_window| root window.
70   void SetBounds(aura::Window* root_window,
71                  const gfx::Rect& target_bounds,
72                  bool animate);
73
74   // Recomputes the positions for the windows in this selection item. This is
75   // dispatched when the bounds of a window change.
76   void RecomputeWindowTransforms();
77
78   // Sends an a11y focus alert so that, if chromevox is enabled, the window
79   // label is read.
80   void SendFocusAlert() const;
81
82   // Sets if the item is dimmed in the overview. Changing the value will also
83   // change the visibility of the transform windows.
84   virtual void SetDimmed(bool dimmed);
85   bool dimmed() const { return dimmed_; }
86
87   const gfx::Rect& bounds() const { return bounds_; }
88   const gfx::Rect& target_bounds() const { return target_bounds_; }
89
90   // views::ButtonListener:
91   void ButtonPressed(views::Button* sender, const ui::Event& event) override;
92
93   // aura::WindowObserver:
94   void OnWindowTitleChanged(aura::Window* window) override;
95
96  protected:
97   // Sets the bounds of this selector's items to |target_bounds| in
98   // |root_window|. If |animate| the windows are animated from their current
99   // location.
100   virtual void SetItemBounds(aura::Window* root_window,
101                              const gfx::Rect& target_bounds,
102                              bool animate) = 0;
103
104   // Sets the bounds used by the selector item's windows.
105   void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; }
106
107   // Changes the opacity of all the windows the item owns.
108   virtual void SetOpacity(float opacity);
109
110   // True if the item is being shown in the overview, false if it's being
111   // filtered.
112   bool dimmed_;
113
114  private:
115   friend class WindowSelectorTest;
116
117   // Creates |close_button_| if it does not exist and updates the bounds based
118   // on GetCloseButtonTargetBounds()
119   void UpdateCloseButtonBounds(aura::Window* root_window, bool animate);
120
121   // Creates a label to display under the window selector item.
122   void UpdateWindowLabels(const gfx::Rect& target_bounds,
123                           aura::Window* root_window,
124                           bool animate);
125
126   // Initializes window_label_.
127   void CreateWindowLabel(const base::string16& title);
128
129   // The root window this item is being displayed on.
130   aura::Window* root_window_;
131
132   // The target bounds this selector item is fit within.
133   gfx::Rect target_bounds_;
134
135   // The actual bounds of the window(s) for this item. The aspect ratio of
136   // window(s) are maintained so they may not fill the target_bounds_.
137   gfx::Rect bounds_;
138
139   // True if running SetItemBounds. This prevents recursive calls resulting from
140   // the bounds update when calling ::wm::RecreateWindowLayers to copy
141   // a window layer for display on another monitor.
142   bool in_bounds_update_;
143
144   // Label under the window displaying its active tab name.
145   scoped_ptr<views::Widget> window_label_;
146
147   // View for the label under the window.
148   views::Label* window_label_view_;
149
150   // An easy to access close button for the window in this item.
151   scoped_ptr<views::Widget> close_button_;
152
153   // Transparent window on top of the real windows in the overview that
154   // activates them on click or tap.
155   scoped_ptr<TransparentActivateWindowButton> activate_window_button_;
156
157   DISALLOW_COPY_AND_ASSIGN(WindowSelectorItem);
158 };
159
160 }  // namespace ash
161
162 #endif  // ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_