panel_view.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1// Copyright (c) 2012 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_VIEW_H_ 6#define CHROME_BROWSER_UI_VIEWS_PANELS_PANEL_VIEW_H_ 7 8#include "base/memory/scoped_ptr.h" 9#include "chrome/browser/ui/panels/native_panel.h" 10#include "ui/gfx/animation/animation_delegate.h" 11#include "ui/views/widget/widget_delegate.h" 12#include "ui/views/widget/widget_observer.h" 13 14#if defined(OS_WIN) 15#include "ui/base/win/hwnd_subclass.h" 16#endif 17 18class AutoKeepAlive; 19class Panel; 20class PanelBoundsAnimation; 21class PanelFrameView; 22class TaskbarWindowThumbnailerWin; 23 24namespace views { 25class WebView; 26} 27 28class PanelView : public NativePanel, 29 public views::WidgetObserver, 30 public views::WidgetDelegateView, 31#if defined(OS_WIN) 32 public ui::HWNDMessageFilter, 33#endif 34 public gfx::AnimationDelegate { 35 public: 36 // The size of inside area used for mouse resizing. 37 static const int kResizeInsideBoundsSize = 5; 38 39 PanelView(Panel* panel, const gfx::Rect& bounds, bool always_on_top); 40 virtual ~PanelView(); 41 42 // Overridden from NativePanel: 43 virtual void ShowPanel() OVERRIDE; 44 virtual void ShowPanelInactive() OVERRIDE; 45 virtual gfx::Rect GetPanelBounds() const OVERRIDE; 46 virtual void SetPanelBounds(const gfx::Rect& bounds) OVERRIDE; 47 virtual void SetPanelBoundsInstantly(const gfx::Rect& bounds) OVERRIDE; 48 virtual void ClosePanel() OVERRIDE; 49 virtual void ActivatePanel() OVERRIDE; 50 virtual void DeactivatePanel() OVERRIDE; 51 virtual bool IsPanelActive() const OVERRIDE; 52 virtual void PreventActivationByOS(bool prevent_activation) OVERRIDE; 53 virtual gfx::NativeWindow GetNativePanelWindow() OVERRIDE; 54 virtual void UpdatePanelTitleBar() OVERRIDE; 55 virtual void UpdatePanelLoadingAnimations(bool should_animate) OVERRIDE; 56 virtual void PanelWebContentsFocused(content::WebContents* contents) OVERRIDE; 57 virtual void PanelCut() OVERRIDE; 58 virtual void PanelCopy() OVERRIDE; 59 virtual void PanelPaste() OVERRIDE; 60 virtual void DrawAttention(bool draw_attention) OVERRIDE; 61 virtual bool IsDrawingAttention() const OVERRIDE; 62 virtual void HandlePanelKeyboardEvent( 63 const content::NativeWebKeyboardEvent& event) OVERRIDE; 64 virtual void FullScreenModeChanged(bool is_full_screen) OVERRIDE; 65 virtual bool IsPanelAlwaysOnTop() const OVERRIDE; 66 virtual void SetPanelAlwaysOnTop(bool on_top) OVERRIDE; 67 virtual void UpdatePanelMinimizeRestoreButtonVisibility() OVERRIDE; 68 virtual void SetWindowCornerStyle(panel::CornerStyle corner_style) OVERRIDE; 69 virtual void PanelExpansionStateChanging( 70 Panel::ExpansionState old_state, 71 Panel::ExpansionState new_state) OVERRIDE; 72 virtual void AttachWebContents(content::WebContents* contents) OVERRIDE; 73 virtual void DetachWebContents(content::WebContents* contents) OVERRIDE; 74 virtual gfx::Size WindowSizeFromContentSize( 75 const gfx::Size& content_size) const OVERRIDE; 76 virtual gfx::Size ContentSizeFromWindowSize( 77 const gfx::Size& window_size) const OVERRIDE; 78 virtual int TitleOnlyHeight() const OVERRIDE; 79 virtual void MinimizePanelBySystem() OVERRIDE; 80 virtual bool IsPanelMinimizedBySystem() const OVERRIDE; 81 virtual bool IsPanelShownOnActiveDesktop() const OVERRIDE; 82 virtual void ShowShadow(bool show) OVERRIDE; 83 virtual NativePanelTesting* CreateNativePanelTesting() OVERRIDE; 84 85 // Overridden from views::View: 86 virtual gfx::Size GetMinimumSize() const OVERRIDE; 87 virtual gfx::Size GetMaximumSize() const OVERRIDE; 88 89 // Return true if the mouse event is handled. 90 // |mouse_location| is in screen coordinate system. 91 bool OnTitlebarMousePressed(const gfx::Point& mouse_location); 92 bool OnTitlebarMouseDragged(const gfx::Point& mouse_location); 93 bool OnTitlebarMouseReleased(panel::ClickModifier modifier); 94 bool OnTitlebarMouseCaptureLost(); 95 96 PanelFrameView* GetFrameView() const; 97 bool IsAnimatingBounds() const; 98 99 Panel* panel() const { return panel_.get(); } 100 views::Widget* window() const { return window_; } 101 bool force_to_paint_as_inactive() const { 102 return force_to_paint_as_inactive_; 103 } 104 105 // PanelStackView might want to update the stored bounds directly since it 106 // has already taken care of updating the window bounds directly. 107 void set_cached_bounds_directly(const gfx::Rect& bounds) { bounds_ = bounds; } 108 109 private: 110 enum MouseDraggingState { 111 NO_DRAGGING, 112 DRAGGING_STARTED, 113 DRAGGING_ENDED 114 }; 115 116 // Overridden from views::WidgetDelegate: 117 virtual void OnDisplayChanged() OVERRIDE; 118 virtual void OnWorkAreaChanged() OVERRIDE; 119 virtual bool WillProcessWorkAreaChange() const OVERRIDE; 120 virtual views::View* GetContentsView() OVERRIDE; 121 virtual views::NonClientFrameView* CreateNonClientFrameView( 122 views::Widget* widget) OVERRIDE; 123 virtual bool CanResize() const OVERRIDE; 124 virtual bool CanMaximize() const OVERRIDE; 125 virtual views::Widget* GetWidget() OVERRIDE; 126 virtual const views::Widget* GetWidget() const OVERRIDE; 127 virtual base::string16 GetWindowTitle() const OVERRIDE; 128 virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE; 129 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE; 130 virtual void WindowClosing() OVERRIDE; 131 virtual void DeleteDelegate() OVERRIDE; 132 virtual void OnWindowBeginUserBoundsChange() OVERRIDE; 133 virtual void OnWindowEndUserBoundsChange() OVERRIDE; 134 135 // Overridden from views::View: 136 virtual void Layout() OVERRIDE; 137 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 138 139 // Overridden from views::WidgetObserver: 140 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 141 virtual void OnWidgetActivationChanged(views::Widget* widget, 142 bool active) OVERRIDE; 143 virtual void OnWidgetBoundsChanged(views::Widget* widget, 144 const gfx::Rect& new_bounds) OVERRIDE; 145 146 // Overridden from ui::HWNDMessageFilter: 147#if defined(OS_WIN) 148 virtual bool FilterMessage(HWND hwnd, 149 UINT message, 150 WPARAM w_param, 151 LPARAM l_param, 152 LRESULT* l_result) OVERRIDE; 153#endif 154 155 // Overridden from AnimationDelegate: 156 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 157 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 158 159 void UpdateLoadingAnimations(bool should_animate); 160 void UpdateWindowTitle(); 161 void UpdateWindowIcon(); 162 void SetBoundsInternal(const gfx::Rect& bounds, bool animate); 163 bool EndDragging(bool cancelled); 164 165 // Sets the bounds of the underlying window to |new_bounds|. Note that this 166 // might update the window style to work around the minimum overlapped 167 // window height limitation. 168 void SetWidgetBounds(const gfx::Rect& new_bounds); 169 170#if defined(OS_WIN) 171 // Sets |attribute_value_to_set| and/or clears |attribute_value_to_reset| for 172 // the attibute denoted by |attribute_index|. This is used to update the style 173 // or extended style for the native window. 174 void UpdateWindowAttribute(int attribute_index, 175 int attribute_value_to_set, 176 int attribute_value_to_reset, 177 bool update_frame); 178#endif 179 180 scoped_ptr<Panel> panel_; 181 gfx::Rect bounds_; 182 183 // The window that holds all panel views. Lifetime managed by native widget. 184 // See widget.h. 185 views::Widget* window_; 186 187 // Close gets called more than once, so use this to do one-time clean up once. 188 bool window_closed_; 189 190 // The view hosting the web contents. Will be destroyed when child views 191 // of this class are destroyed. 192 views::WebView* web_view_; 193 194 // True if the panel should always stay on top of other windows. 195 bool always_on_top_; 196 197 // Is the panel receiving the focus? 198 bool focused_; 199 200 // True if the user is resizing the panel. 201 bool user_resizing_; 202 203#if defined(OS_WIN) 204 // True if the user is resizing the interior edge of a stack. 205 bool user_resizing_interior_stacked_panel_edge_; 206 207 // The original full size of the resizing panel before the resizing states. 208 gfx::Size original_full_size_of_resizing_panel_; 209 210 // The original full size of the panel below the resizing panel before the 211 // resizing starts. 212 gfx::Size original_full_size_of_panel_below_resizing_panel_; 213#endif 214 215 216 // Is the mouse button currently down? 217 bool mouse_pressed_; 218 219 // Location the mouse was pressed at or dragged to last time when we process 220 // the mouse event. Used in drag-and-drop. 221 // This point is represented in the screen coordinate system. 222 gfx::Point last_mouse_location_; 223 224 // Is the titlebar currently being dragged? That is, has the cursor 225 // moved more than kDragThreshold away from its starting position? 226 MouseDraggingState mouse_dragging_state_; 227 228 // Used to animate the bounds change. 229 scoped_ptr<PanelBoundsAnimation> bounds_animator_; 230 gfx::Rect animation_start_bounds_; 231 232 // Is the panel in highlighted state to draw people's attention? 233 bool is_drawing_attention_; 234 235 // Should we force to paint the panel as inactive? This is needed when we need 236 // to capture the screenshot before an active panel goes minimized. 237 bool force_to_paint_as_inactive_; 238 239 // The last view that had focus in the panel. This is saved so that focus can 240 // be restored properly when a drag ends. 241 views::View* old_focused_view_; 242 243 scoped_ptr<AutoKeepAlive> keep_alive_; 244 245#if defined(OS_WIN) 246 // Used to provide custom taskbar thumbnail for Windows 7 and later. 247 scoped_ptr<TaskbarWindowThumbnailerWin> thumbnailer_; 248#endif 249 250 DISALLOW_COPY_AND_ASSIGN(PanelView); 251}; 252 253#endif // CHROME_BROWSER_UI_VIEWS_PANELS_PANEL_VIEW_H_ 254