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" 10116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/aura/window_observer.h" 11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/rect.h" 12f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "ui/views/controls/button/button.h" 13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace aura { 15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class Window; 16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace views { 19116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass Label; 200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass Widget; 210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace ash { 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class TransparentActivateWindowButton; 25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 26d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// This class represents an item in overview mode. An item can have one or more 27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// windows, of which only one can be activated by keyboard (i.e. alt+tab) but 28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// any can be selected with a pointer (touch or mouse). 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass WindowSelectorItem : public views::ButtonListener, 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public aura::WindowObserver { 31d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) public: 32d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) WindowSelectorItem(); 33d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual ~WindowSelectorItem(); 34d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // The time for the close buttons and labels to fade in when initially shown 360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // on entering overview mode. 370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch static const int kFadeInMilliseconds; 380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 39d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns the root window on which this item is shown. 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual aura::Window* GetRootWindow() = 0; 41d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns true if the window selector item has |window| as a selectable 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // window. 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual bool HasSelectableWindow(const aura::Window* window) = 0; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Returns true if |target| is contained in this WindowSelectorItem. 47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual bool Contains(const aura::Window* target) = 0; 48d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Restores |window| on exiting window overview rather than returning it 50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // to its previous state. 51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void RestoreWindowOnExit(aura::Window* window) = 0; 52d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns the |window| to activate on selecting of this item. 54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual aura::Window* SelectionWindow() = 0; 55d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Removes |window| from this item. Check empty() after calling this to see 57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // if the entire item is now empty. 58f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual void RemoveWindow(const aura::Window* window); 59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Returns true if this item has no more selectable windows (i.e. after 61d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // calling RemoveWindow for the last contained window). 62d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual bool empty() const = 0; 63d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Dispatched before beginning window overview. This will do any necessary 654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // one time actions such as restoring minimized windows. 664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void PrepareForOverview() = 0; 674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Sets the bounds of this window selector item to |target_bounds| in the 69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // |root_window| root window. 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SetBounds(aura::Window* root_window, 715c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu const gfx::Rect& target_bounds, 725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool animate); 73d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Recomputes the positions for the windows in this selection item. This is 754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // dispatched when the bounds of a window change. 764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void RecomputeWindowTransforms(); 774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 7846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Sends an a11y focus alert so that, if chromevox is enabled, the window 7946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // label is read. 8046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void SendFocusAlert() const; 8146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 82116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Sets if the item is dimmed in the overview. Changing the value will also 83116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // change the visibility of the transform windows. 84116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void SetDimmed(bool dimmed); 85116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool dimmed() const { return dimmed_; } 86116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 87f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const gfx::Rect& bounds() const { return bounds_; } 88f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const gfx::Rect& target_bounds() const { return target_bounds_; } 89f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 90f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // views::ButtonListener: 91f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) virtual void ButtonPressed(views::Button* sender, 92f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const ui::Event& event) OVERRIDE; 93d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 94116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // aura::WindowObserver: 95116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnWindowTitleChanged(aura::Window* window) OVERRIDE; 96116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) protected: 98cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Sets the bounds of this selector's items to |target_bounds| in 99cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // |root_window|. If |animate| the windows are animated from their current 100cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // location. 1011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual void SetItemBounds(aura::Window* root_window, 1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const gfx::Rect& target_bounds, 1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool animate) = 0; 104d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Sets the bounds used by the selector item's windows. 1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void set_bounds(const gfx::Rect& bounds) { bounds_ = bounds; } 1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Changes the opacity of all the windows the item owns. 109116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void SetOpacity(float opacity); 110116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 111116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // True if the item is being shown in the overview, false if it's being 112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // filtered. 113116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool dimmed_; 114116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 115d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) private: 1160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch friend class WindowSelectorTest; 1170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Creates |close_button_| if it does not exist and updates the bounds based 119f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // on GetCloseButtonTargetBounds() 120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) void UpdateCloseButtonBounds(aura::Window* root_window, bool animate); 121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Creates a label to display under the window selector item. 1235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu void UpdateWindowLabels(const gfx::Rect& target_bounds, 1245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu aura::Window* root_window, 1255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu bool animate); 1265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Initializes window_label_. 128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void CreateWindowLabel(const base::string16& title); 129116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The root window this item is being displayed on. 1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root_window_; 1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The target bounds this selector item is fit within. 1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) gfx::Rect target_bounds_; 1354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The actual bounds of the window(s) for this item. The aspect ratio of 1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // window(s) are maintained so they may not fill the target_bounds_. 138d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) gfx::Rect bounds_; 139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // True if running SetItemBounds. This prevents recursive calls resulting from 141a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // the bounds update when calling ::wm::RecreateWindowLayers to copy 1424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // a window layer for display on another monitor. 1434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool in_bounds_update_; 1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // Label under the window displaying its active tab name. 1460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch scoped_ptr<views::Widget> window_label_; 1470529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 148116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // View for the label under the window. 149116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch views::Label* window_label_view_; 150116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 151f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // An easy to access close button for the window in this item. 152f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) scoped_ptr<views::Widget> close_button_; 153f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 154cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Transparent window on top of the real windows in the overview that 155cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // activates them on click or tap. 156cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) scoped_ptr<TransparentActivateWindowButton> activate_window_button_; 157cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 158d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WindowSelectorItem); 159d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}; 160d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 161d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} // namespace ash 162d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 163d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif // ASH_WM_OVERVIEW_WINDOW_SELECTOR_ITEM_H_ 164