panel_view.h revision 3551c9c881056c480085172ff9840cab31610854
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/base/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 Panel; 19class PanelBoundsAnimation; 20class PanelFrameView; 21class TaskbarWindowThumbnailerWin; 22 23namespace views { 24class WebView; 25} 26 27class PanelView : public NativePanel, 28 public views::WidgetObserver, 29 public views::WidgetDelegateView, 30#if defined(OS_WIN) 31 public ui::HWNDMessageFilter, 32#endif 33 public ui::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 EnableResizeByMouse(bool enable) 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() OVERRIDE; 87 virtual gfx::Size GetMaximumSize() 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 // The panel does not show a resizing border. Instead, the inner content area 100 // can be used to trigger the mouse resizing. Return true if |mouse_location| 101 // falls within this area. 102 // |mouse_location| is in screen coordinate system. 103 bool IsWithinResizingArea(const gfx::Point& mouse_location) const; 104 105 Panel* panel() const { return panel_.get(); } 106 views::Widget* window() const { return window_; } 107 bool force_to_paint_as_inactive() const { 108 return force_to_paint_as_inactive_; 109 } 110 111 // PanelStackView might want to update the stored bounds directly since it 112 // has already taken care of updating the window bounds directly. 113 void set_cached_bounds_directly(const gfx::Rect& bounds) { bounds_ = bounds; } 114 115 private: 116 enum MouseDraggingState { 117 NO_DRAGGING, 118 DRAGGING_STARTED, 119 DRAGGING_ENDED 120 }; 121 122 // Overridden from views::WidgetDelegate: 123 virtual void OnDisplayChanged() OVERRIDE; 124 virtual void OnWorkAreaChanged() OVERRIDE; 125 virtual bool WillProcessWorkAreaChange() const OVERRIDE; 126 virtual views::View* GetContentsView() OVERRIDE; 127 virtual views::NonClientFrameView* CreateNonClientFrameView( 128 views::Widget* widget) OVERRIDE; 129 virtual bool CanResize() const OVERRIDE; 130 virtual bool CanMaximize() const OVERRIDE; 131 virtual views::Widget* GetWidget() OVERRIDE; 132 virtual const views::Widget* GetWidget() const OVERRIDE; 133 virtual string16 GetWindowTitle() const OVERRIDE; 134 virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE; 135 virtual gfx::ImageSkia GetWindowIcon() OVERRIDE; 136 virtual void WindowClosing() OVERRIDE; 137 virtual void DeleteDelegate() OVERRIDE; 138 virtual void OnWindowBeginUserBoundsChange() OVERRIDE; 139 virtual void OnWindowEndUserBoundsChange() OVERRIDE; 140 141 // Overridden from views::View: 142 virtual void Layout() OVERRIDE; 143 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; 144 145 // Overridden from views::WidgetObserver: 146 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 147 virtual void OnWidgetActivationChanged(views::Widget* widget, 148 bool active) OVERRIDE; 149 virtual void OnWidgetBoundsChanged(views::Widget* widget, 150 const gfx::Rect& new_bounds) OVERRIDE; 151 152 // Overridden from ui::HWNDMessageFilter: 153#if defined(OS_WIN) 154 virtual bool FilterMessage(HWND hwnd, 155 UINT message, 156 WPARAM w_param, 157 LPARAM l_param, 158 LRESULT* l_result) OVERRIDE; 159#endif 160 161 // Overridden from AnimationDelegate: 162 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; 163 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; 164 165 void UpdateLoadingAnimations(bool should_animate); 166 void UpdateWindowTitle(); 167 void UpdateWindowIcon(); 168 void SetBoundsInternal(const gfx::Rect& bounds, bool animate); 169 bool EndDragging(bool cancelled); 170 void OnViewWasResized(); 171 172 // Sets the bounds of the underlying window to |new_bounds|. Note that this 173 // might update the window style to work around the minimum overlapped 174 // window height limitation. 175 void SetWidgetBounds(const gfx::Rect& new_bounds); 176 177#if defined(OS_WIN) 178 // Sets |attribute_value_to_set| and/or clears |attribute_value_to_reset| for 179 // the attibute denoted by |attribute_index|. This is used to update the style 180 // or extended style for the native window. 181 void UpdateWindowAttribute(int attribute_index, 182 int attribute_value_to_set, 183 int attribute_value_to_reset, 184 bool update_frame); 185#endif 186 187 scoped_ptr<Panel> panel_; 188 gfx::Rect bounds_; 189 190 // The window that holds all panel views. Lifetime managed by native widget. 191 // See widget.h. 192 views::Widget* window_; 193 194 // Close gets called more than once, so use this to do one-time clean up once. 195 bool window_closed_; 196 197 // The view hosting the web contents. Will be destroyed when child views 198 // of this class are destroyed. 199 views::WebView* web_view_; 200 201 // True if the panel should always stay on top of other windows. 202 bool always_on_top_; 203 204 // Is the panel receiving the focus? 205 bool focused_; 206 207 // True if the user is resizing the panel. 208 bool user_resizing_; 209 210#if defined(OS_WIN) 211 // True if the user is resizing the interior edge of a stack. 212 bool user_resizing_interior_stacked_panel_edge_; 213 214 // The original full size of the resizing panel before the resizing states. 215 gfx::Size original_full_size_of_resizing_panel_; 216 217 // The original full size of the panel below the resizing panel before the 218 // resizing starts. 219 gfx::Size original_full_size_of_panel_below_resizing_panel_; 220#endif 221 222 223 // Is the mouse button currently down? 224 bool mouse_pressed_; 225 226 // Location the mouse was pressed at or dragged to last time when we process 227 // the mouse event. Used in drag-and-drop. 228 // This point is represented in the screen coordinate system. 229 gfx::Point last_mouse_location_; 230 231 // Is the titlebar currently being dragged? That is, has the cursor 232 // moved more than kDragThreshold away from its starting position? 233 MouseDraggingState mouse_dragging_state_; 234 235 // Used to animate the bounds change. 236 scoped_ptr<PanelBoundsAnimation> bounds_animator_; 237 gfx::Rect animation_start_bounds_; 238 239 // Is the panel in highlighted state to draw people's attention? 240 bool is_drawing_attention_; 241 242 // Should we force to paint the panel as inactive? This is needed when we need 243 // to capture the screenshot before an active panel goes minimized. 244 bool force_to_paint_as_inactive_; 245 246 // The last view that had focus in the panel. This is saved so that focus can 247 // be restored properly when a drag ends. 248 views::View* old_focused_view_; 249 250#if defined(OS_WIN) 251 // Used to provide custom taskbar thumbnail for Windows 7 and later. 252 scoped_ptr<TaskbarWindowThumbnailerWin> thumbnailer_; 253#endif 254 255 DISALLOW_COPY_AND_ASSIGN(PanelView); 256}; 257 258#endif // CHROME_BROWSER_UI_VIEWS_PANELS_PANEL_VIEW_H_ 259