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/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   virtual ~WindowSelectorItem();
     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   virtual void ButtonPressed(views::Button* sender,
     92                              const ui::Event& event) OVERRIDE;
     93 
     94   // aura::WindowObserver:
     95   virtual void OnWindowTitleChanged(aura::Window* window) OVERRIDE;
     96 
     97  protected:
     98   // Sets the bounds of this selector's items to |target_bounds| in
     99   // |root_window|. If |animate| the windows are animated from their current
    100   // location.
    101   virtual void SetItemBounds(aura::Window* root_window,
    102                              const gfx::Rect& target_bounds,
    103                              bool animate) = 0;
    104 
    105   // Sets the bounds used by the selector item's windows.
    106   void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; }
    107 
    108   // Changes the opacity of all the windows the item owns.
    109   virtual void SetOpacity(float opacity);
    110 
    111   // True if the item is being shown in the overview, false if it's being
    112   // filtered.
    113   bool dimmed_;
    114 
    115  private:
    116   friend class WindowSelectorTest;
    117 
    118   // Creates |close_button_| if it does not exist and updates the bounds based
    119   // on GetCloseButtonTargetBounds()
    120   void UpdateCloseButtonBounds(aura::Window* root_window, bool animate);
    121 
    122   // Creates a label to display under the window selector item.
    123   void UpdateWindowLabels(const gfx::Rect& target_bounds,
    124                           aura::Window* root_window,
    125                           bool animate);
    126 
    127   // Initializes window_label_.
    128   void CreateWindowLabel(const base::string16& title);
    129 
    130   // The root window this item is being displayed on.
    131   aura::Window* root_window_;
    132 
    133   // The target bounds this selector item is fit within.
    134   gfx::Rect target_bounds_;
    135 
    136   // The actual bounds of the window(s) for this item. The aspect ratio of
    137   // window(s) are maintained so they may not fill the target_bounds_.
    138   gfx::Rect bounds_;
    139 
    140   // True if running SetItemBounds. This prevents recursive calls resulting from
    141   // the bounds update when calling ::wm::RecreateWindowLayers to copy
    142   // a window layer for display on another monitor.
    143   bool in_bounds_update_;
    144 
    145   // Label under the window displaying its active tab name.
    146   scoped_ptr<views::Widget> window_label_;
    147 
    148   // View for the label under the window.
    149   views::Label* window_label_view_;
    150 
    151   // An easy to access close button for the window in this item.
    152   scoped_ptr<views::Widget> close_button_;
    153 
    154   // Transparent window on top of the real windows in the overview that
    155   // activates them on click or tap.
    156   scoped_ptr<TransparentActivateWindowButton> activate_window_button_;
    157 
    158   DISALLOW_COPY_AND_ASSIGN(WindowSelectorItem);
    159 };
    160 
    161 }  // namespace ash
    162 
    163 #endif  // ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_
    164