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