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