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