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