panel_stack_view.h revision 868fa2fe829687343ffae624259930155e16dbd8
1// Copyright (c) 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 CHROME_BROWSER_UI_VIEWS_PANELS_PANEL_STACK_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_PANELS_PANEL_STACK_VIEW_H_ 7 8#include <list> 9#include <map> 10#include "base/basictypes.h" 11#include "base/memory/scoped_ptr.h" 12#include "chrome/browser/ui/panels/native_panel_stack_window.h" 13#include "ui/base/animation/animation_delegate.h" 14#include "ui/views/focus/widget_focus_manager.h" 15#include "ui/views/widget/widget_delegate.h" 16#include "ui/views/widget/widget_observer.h" 17 18#if defined(OS_WIN) 19#include "chrome/browser/ui/views/panels/taskbar_window_thumbnailer_win.h" 20#endif 21 22namespace ui { 23class LinearAnimation; 24} 25namespace views { 26class Widget; 27} 28 29// A native window that acts as the owner of all panels in the stack, in order 30// to make all panels appear as a single window on the taskbar or launcher. 31class PanelStackView : public NativePanelStackWindow, 32 public views::WidgetObserver, 33 public views::WidgetDelegateView, 34 public views::WidgetFocusChangeListener, 35#if defined(OS_WIN) 36 public TaskbarWindowThumbnailerDelegateWin, 37#endif 38 public ui::AnimationDelegate { 39 public: 40 explicit PanelStackView(NativePanelStackWindowDelegate* delegate); 41 virtual ~PanelStackView(); 42 43 protected: 44 // Overridden from NativePanelStackWindow: 45 virtual void Close() OVERRIDE; 46 virtual void AddPanel(Panel* panel) OVERRIDE; 47 virtual void RemovePanel(Panel* panel) OVERRIDE; 48 virtual void MergeWith(NativePanelStackWindow* another) OVERRIDE; 49 virtual bool IsEmpty() const OVERRIDE; 50 virtual bool HasPanel(Panel* panel) const OVERRIDE; 51 virtual void MovePanelsBy(const gfx::Vector2d& delta) OVERRIDE; 52 virtual void BeginBatchUpdatePanelBounds(bool animate) OVERRIDE; 53 virtual void AddPanelBoundsForBatchUpdate( 54 Panel* panel, const gfx::Rect& new_bounds) OVERRIDE; 55 virtual void EndBatchUpdatePanelBounds() OVERRIDE; 56 virtual bool IsAnimatingPanelBounds() const OVERRIDE; 57 virtual void Minimize() OVERRIDE; 58 virtual bool IsMinimized() const OVERRIDE; 59 virtual void DrawSystemAttention(bool draw_attention) OVERRIDE; 60 virtual void OnPanelActivated(Panel* panel) OVERRIDE; 61 62 private: 63 typedef std::list<Panel*> Panels; 64 65 // The map value is old bounds of the panel. 66 typedef std::map<Panel*, gfx::Rect> BoundsUpdates; 67 68 // Overridden from views::WidgetDelegate: 69 virtual string16 GetWindowTitle() const OVERRIDE; 70 virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE; 71 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE; 72 virtual views::Widget* GetWidget() OVERRIDE; 73 virtual const views::Widget* GetWidget() const OVERRIDE; 74 virtual void DeleteDelegate() OVERRIDE; 75 76 // Overridden from views::WidgetObserver: 77 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 78 79 // Overridden from views::WidgetFocusChangeListener: 80 virtual void OnNativeFocusChange(gfx::NativeView focused_before, 81 gfx::NativeView focused_now) OVERRIDE; 82 83 // Overridden from AnimationDelegate: 84 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; 85 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; 86 87 // Updates the bounds of panels as specified in batch update data. 88 void UpdatePanelsBounds(); 89 90 // Notifies the delegate that the updates of the panel bounds are completed. 91 void NotifyBoundsUpdateCompleted(); 92 93 // Computes/updates the minimum bounds that could fit all panels. 94 gfx::Rect GetStackWindowBounds() const; 95 void UpdateStackWindowBounds(); 96 97 views::Widget* CreateWindowWithBounds(const gfx::Rect& bounds); 98 void EnsureWindowCreated(); 99 100 // Makes the stack window own the panel window such that multiple panels 101 // stacked together could appear as a single window on the taskbar or 102 // launcher. 103 static void MakeStackWindowOwnPanelWindow(Panel* panel, 104 PanelStackView* stack_window); 105 106#if defined(OS_WIN) 107 // Overridden from TaskbarWindowThumbnailerDelegateWin: 108 virtual std::vector<HWND> GetSnapshotWindowHandles() const OVERRIDE; 109 110 // Updates the live preview snapshot when something changes, like 111 // adding/removing/moving/resizing a stacked panel. 112 void RefreshLivePreviewThumbnail(); 113 114 // Updates the bounds of the widget window in a deferred way. 115 void DeferUpdateNativeWindowBounds(HDWP defer_window_pos_info, 116 views::Widget* window, 117 const gfx::Rect& bounds); 118#endif 119 120 NativePanelStackWindowDelegate* delegate_; 121 122 views::Widget* window_; // Weak pointer, own us. 123 124 bool is_closing_; 125 126 // Tracks all panels that are enclosed by this window. 127 Panels panels_; 128 129 // Is the taskbar icon of the underlying window being flashed in order to 130 // draw the user's attention? 131 bool is_drawing_attention_; 132 133#if defined(OS_WIN) 134 // The custom live preview snapshot is always provided for the stack window. 135 // This is because the system might not show the snapshot correctly for 136 // a small window, like collapsed panel. 137 scoped_ptr<TaskbarWindowThumbnailerWin> thumbnailer_; 138#endif 139 140 // For batch bounds update. 141 bool animate_bounds_updates_; 142 bool bounds_updates_started_; 143 BoundsUpdates bounds_updates_; 144 145 // Used to animate the bounds changes at a synchronized pace. 146 scoped_ptr<ui::LinearAnimation> bounds_animator_; 147 148 DISALLOW_COPY_AND_ASSIGN(PanelStackView); 149}; 150 151#endif // CHROME_BROWSER_UI_VIEWS_PANELS_PANEL_STACK_VIEW_H_ 152