Home | History | Annotate | Download | only in overview
      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/gfx/rect.h"
     11 #include "ui/views/controls/button/button.h"
     12 
     13 namespace aura {
     14 class Window;
     15 }
     16 
     17 namespace views {
     18 class Widget;
     19 }
     20 
     21 namespace ash {
     22 class TransparentActivateWindowButton;
     23 
     24 // This class represents an item in overview mode. An item can have one or more
     25 // windows, of which only one can be activated by keyboard (i.e. alt+tab) but
     26 // any can be selected with a pointer (touch or mouse).
     27 class WindowSelectorItem : public views::ButtonListener {
     28  public:
     29   WindowSelectorItem();
     30   virtual ~WindowSelectorItem();
     31 
     32   // The time for the close buttons and labels to fade in when initially shown
     33   // on entering overview mode.
     34   static const int kFadeInMilliseconds;
     35 
     36   // Returns the root window on which this item is shown.
     37   virtual aura::Window* GetRootWindow() = 0;
     38 
     39   // Returns true if the window selector item has |window| as a selectable
     40   // window.
     41   virtual bool HasSelectableWindow(const aura::Window* window) = 0;
     42 
     43   // Returns true if |target| is contained in this WindowSelectorItem.
     44   virtual bool Contains(const aura::Window* target) = 0;
     45 
     46   // Restores |window| on exiting window overview rather than returning it
     47   // to its previous state.
     48   virtual void RestoreWindowOnExit(aura::Window* window) = 0;
     49 
     50   // Returns the |window| to activate on selecting of this item.
     51   virtual aura::Window* SelectionWindow() = 0;
     52 
     53   // Removes |window| from this item. Check empty() after calling this to see
     54   // if the entire item is now empty.
     55   virtual void RemoveWindow(const aura::Window* window);
     56 
     57   // Returns true if this item has no more selectable windows (i.e. after
     58   // calling RemoveWindow for the last contained window).
     59   virtual bool empty() const = 0;
     60 
     61   // Dispatched before beginning window overview. This will do any necessary
     62   // one time actions such as restoring minimized windows.
     63   virtual void PrepareForOverview() = 0;
     64 
     65   // Sets the bounds of this window selector item to |target_bounds| in the
     66   // |root_window| root window.
     67   void SetBounds(aura::Window* root_window,
     68                  const gfx::Rect& target_bounds,
     69                  bool animate);
     70 
     71   // Recomputes the positions for the windows in this selection item. This is
     72   // dispatched when the bounds of a window change.
     73   void RecomputeWindowTransforms();
     74 
     75   // Sends an a11y focus alert so that, if chromevox is enabled, the window
     76   // label is read.
     77   void SendFocusAlert() const;
     78 
     79   const gfx::Rect& bounds() const { return bounds_; }
     80   const gfx::Rect& target_bounds() const { return target_bounds_; }
     81 
     82   // views::ButtonListener:
     83   virtual void ButtonPressed(views::Button* sender,
     84                              const ui::Event& event) OVERRIDE;
     85 
     86  protected:
     87   // Sets the bounds of this selector's items to |target_bounds| in
     88   // |root_window|. If |animate| the windows are animated from their current
     89   // location.
     90   virtual void SetItemBounds(aura::Window* root_window,
     91                              const gfx::Rect& target_bounds,
     92                              bool animate) = 0;
     93 
     94   // Sets the bounds used by the selector item's windows.
     95   void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; }
     96 
     97  private:
     98   friend class WindowSelectorTest;
     99 
    100   // Creates |close_button_| if it does not exist and updates the bounds based
    101   // on GetCloseButtonTargetBounds()
    102   void UpdateCloseButtonBounds(aura::Window* root_window, bool animate);
    103 
    104   // Creates a label to display under the window selector item.
    105   void UpdateWindowLabels(const gfx::Rect& target_bounds,
    106                           aura::Window* root_window,
    107                           bool animate);
    108 
    109   // The root window this item is being displayed on.
    110   aura::Window* root_window_;
    111 
    112   // The target bounds this selector item is fit within.
    113   gfx::Rect target_bounds_;
    114 
    115   // The actual bounds of the window(s) for this item. The aspect ratio of
    116   // window(s) are maintained so they may not fill the target_bounds_.
    117   gfx::Rect bounds_;
    118 
    119   // True if running SetItemBounds. This prevents recursive calls resulting from
    120   // the bounds update when calling ::wm::RecreateWindowLayers to copy
    121   // a window layer for display on another monitor.
    122   bool in_bounds_update_;
    123 
    124   // Label under the window displaying its active tab name.
    125   scoped_ptr<views::Widget> window_label_;
    126 
    127   // An easy to access close button for the window in this item.
    128   scoped_ptr<views::Widget> close_button_;
    129 
    130   // Transparent window on top of the real windows in the overview that
    131   // activates them on click or tap.
    132   scoped_ptr<TransparentActivateWindowButton> activate_window_button_;
    133 
    134   DISALLOW_COPY_AND_ASSIGN(WindowSelectorItem);
    135 };
    136 
    137 }  // namespace ash
    138 
    139 #endif  // ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
    140