OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/native_app_window/native_app_window_views.h" | 5 #include "components/native_app_window/native_app_window_views.h" |
6 | 6 |
7 #include "base/threading/sequenced_worker_pool.h" | 7 #include "base/threading/sequenced_worker_pool.h" |
| 8 #include "components/native_app_window/app_window_create_params.h" |
| 9 #include "components/native_app_window/draggable_region.h" |
8 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
9 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
10 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
11 #include "extensions/browser/app_window/app_window.h" | |
12 #include "extensions/common/draggable_region.h" | |
13 #include "third_party/skia/include/core/SkRegion.h" | 13 #include "third_party/skia/include/core/SkRegion.h" |
14 #include "ui/gfx/path.h" | 14 #include "ui/gfx/path.h" |
15 #include "ui/views/controls/webview/webview.h" | 15 #include "ui/views/controls/webview/webview.h" |
16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
17 #include "ui/views/window/non_client_view.h" | 17 #include "ui/views/window/non_client_view.h" |
18 | 18 |
19 #if defined(USE_AURA) | 19 #if defined(USE_AURA) |
20 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
21 #endif | 21 #endif |
22 | 22 |
23 using extensions::AppWindow; | |
24 | |
25 namespace native_app_window { | 23 namespace native_app_window { |
26 | 24 |
27 NativeAppWindowViews::NativeAppWindowViews() | 25 NativeAppWindowViews::NativeAppWindowViews() |
28 : app_window_(NULL), | 26 : app_window_(NULL), |
29 web_view_(NULL), | 27 web_view_(NULL), |
30 widget_(NULL), | 28 widget_(NULL), |
31 frameless_(false), | 29 frameless_(false), |
32 resizable_(false) { | 30 resizable_(false) { |
33 } | 31 } |
34 | 32 |
35 void NativeAppWindowViews::Init(AppWindow* app_window, | 33 void NativeAppWindowViews::Init(NativeAppWindowDelegate* app_window, |
36 const AppWindow::CreateParams& create_params) { | 34 const AppWindowCreateParams& create_params) { |
37 app_window_ = app_window; | 35 app_window_ = app_window; |
38 frameless_ = create_params.frame == AppWindow::FRAME_NONE; | 36 frameless_ = create_params.frame == native_app_window::FRAME_NONE; |
39 resizable_ = create_params.resizable; | 37 resizable_ = create_params.resizable; |
40 size_constraints_.set_minimum_size( | 38 size_constraints_.set_minimum_size( |
41 create_params.GetContentMinimumSize(gfx::Insets())); | 39 create_params.GetContentMinimumSize(gfx::Insets())); |
42 size_constraints_.set_maximum_size( | 40 size_constraints_.set_maximum_size( |
43 create_params.GetContentMaximumSize(gfx::Insets())); | 41 create_params.GetContentMaximumSize(gfx::Insets())); |
44 Observe(app_window_->web_contents()); | 42 Observe(app_window_->GetWebContents()); |
45 | 43 |
46 widget_ = new views::Widget; | 44 widget_ = new views::Widget; |
47 InitializeWindow(app_window, create_params); | 45 InitializeWindow(app_window, create_params); |
48 | 46 |
49 OnViewWasResized(); | 47 OnViewWasResized(); |
50 widget_->AddObserver(this); | 48 widget_->AddObserver(this); |
51 } | 49 } |
52 | 50 |
53 NativeAppWindowViews::~NativeAppWindowViews() { | 51 NativeAppWindowViews::~NativeAppWindowViews() { |
54 web_view_->SetWebContents(NULL); | 52 web_view_->SetWebContents(NULL); |
55 } | 53 } |
56 | 54 |
57 void NativeAppWindowViews::OnCanHaveAlphaEnabledChanged() { | 55 void NativeAppWindowViews::OnCanHaveAlphaEnabledChanged() { |
58 app_window_->OnNativeWindowChanged(); | 56 app_window_->OnNativeWindowChanged(); |
59 } | 57 } |
60 | 58 |
61 void NativeAppWindowViews::InitializeWindow( | 59 void NativeAppWindowViews::InitializeWindow( |
62 AppWindow* app_window, | 60 NativeAppWindowDelegate* app_window, |
63 const AppWindow::CreateParams& create_params) { | 61 const AppWindowCreateParams& create_params) { |
64 // Stub implementation. See also ChromeNativeAppWindowViews. | 62 // Stub implementation. See also ChromeNativeAppWindowViews. |
65 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 63 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
66 init_params.delegate = this; | 64 init_params.delegate = this; |
67 init_params.keep_on_top = create_params.always_on_top; | 65 init_params.keep_on_top = create_params.always_on_top; |
68 widget_->Init(init_params); | 66 widget_->Init(init_params); |
69 widget_->CenterWindow( | 67 widget_->CenterWindow( |
70 create_params.GetInitialWindowBounds(gfx::Insets()).size()); | 68 create_params.GetInitialWindowBounds(gfx::Insets()).size()); |
71 } | 69 } |
72 | 70 |
73 // ui::BaseWindow implementation. | 71 // ui::BaseWindow implementation. |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 return web_view_; | 206 return web_view_; |
209 } | 207 } |
210 | 208 |
211 bool NativeAppWindowViews::CanResize() const { | 209 bool NativeAppWindowViews::CanResize() const { |
212 return resizable_ && !size_constraints_.HasFixedSize() && | 210 return resizable_ && !size_constraints_.HasFixedSize() && |
213 !WidgetHasHitTestMask(); | 211 !WidgetHasHitTestMask(); |
214 } | 212 } |
215 | 213 |
216 bool NativeAppWindowViews::CanMaximize() const { | 214 bool NativeAppWindowViews::CanMaximize() const { |
217 return resizable_ && !size_constraints_.HasMaximumSize() && | 215 return resizable_ && !size_constraints_.HasMaximumSize() && |
218 !app_window_->window_type_is_panel() && !WidgetHasHitTestMask(); | 216 !app_window_->WindowTypeIsPanel() && !WidgetHasHitTestMask(); |
219 } | 217 } |
220 | 218 |
221 bool NativeAppWindowViews::CanMinimize() const { | 219 bool NativeAppWindowViews::CanMinimize() const { |
222 return true; | 220 return true; |
223 } | 221 } |
224 | 222 |
225 base::string16 NativeAppWindowViews::GetWindowTitle() const { | 223 base::string16 NativeAppWindowViews::GetWindowTitle() const { |
226 return app_window_->GetTitle(); | 224 return app_window_->GetTitle(); |
227 } | 225 } |
228 | 226 |
229 bool NativeAppWindowViews::ShouldShowWindowTitle() const { | 227 bool NativeAppWindowViews::ShouldShowWindowTitle() const { |
230 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | 228 return app_window_->GetWindowType() == |
| 229 native_app_window::WINDOW_TYPE_V1_PANEL; |
231 } | 230 } |
232 | 231 |
233 bool NativeAppWindowViews::ShouldShowWindowIcon() const { | 232 bool NativeAppWindowViews::ShouldShowWindowIcon() const { |
234 return app_window_->window_type() == AppWindow::WINDOW_TYPE_V1_PANEL; | 233 return app_window_->GetWindowType() == |
| 234 native_app_window::WINDOW_TYPE_V1_PANEL; |
235 } | 235 } |
236 | 236 |
237 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, | 237 void NativeAppWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, |
238 ui::WindowShowState show_state) { | 238 ui::WindowShowState show_state) { |
239 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); | 239 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
240 app_window_->OnNativeWindowChanged(); | 240 app_window_->OnNativeWindowChanged(); |
241 } | 241 } |
242 | 242 |
243 void NativeAppWindowViews::DeleteDelegate() { | 243 void NativeAppWindowViews::DeleteDelegate() { |
244 widget_->RemoveObserver(this); | 244 widget_->RemoveObserver(this); |
245 app_window_->OnNativeClose(); | 245 app_window_->OnNativeClose(); |
246 } | 246 } |
247 | 247 |
248 views::Widget* NativeAppWindowViews::GetWidget() { | 248 views::Widget* NativeAppWindowViews::GetWidget() { |
249 return widget_; | 249 return widget_; |
250 } | 250 } |
251 | 251 |
252 const views::Widget* NativeAppWindowViews::GetWidget() const { | 252 const views::Widget* NativeAppWindowViews::GetWidget() const { |
253 return widget_; | 253 return widget_; |
254 } | 254 } |
255 | 255 |
256 views::View* NativeAppWindowViews::GetContentsView() { | 256 views::View* NativeAppWindowViews::GetContentsView() { |
257 return this; | 257 return this; |
258 } | 258 } |
259 | 259 |
260 bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling( | 260 bool NativeAppWindowViews::ShouldDescendIntoChildForEventHandling( |
261 gfx::NativeView child, | 261 gfx::NativeView child, |
262 const gfx::Point& location) { | 262 const gfx::Point& location) { |
263 #if defined(USE_AURA) | 263 #if defined(USE_AURA) |
264 if (child->Contains(web_view_->web_contents()->GetNativeView())) { | 264 if (child->Contains(web_view_->GetWebContents()->GetNativeView())) { |
265 // App window should claim mouse events that fall within the draggable | 265 // App window should claim mouse events that fall within the draggable |
266 // region. | 266 // region. |
267 return !draggable_region_.get() || | 267 return !draggable_region_.get() || |
268 !draggable_region_->contains(location.x(), location.y()); | 268 !draggable_region_->contains(location.x(), location.y()); |
269 } | 269 } |
270 #endif | 270 #endif |
271 | 271 |
272 return true; | 272 return true; |
273 } | 273 } |
274 | 274 |
275 // WidgetObserver implementation. | 275 // WidgetObserver implementation. |
276 | 276 |
277 void NativeAppWindowViews::OnWidgetVisibilityChanged(views::Widget* widget, | 277 void NativeAppWindowViews::OnWidgetVisibilityChanged(views::Widget* widget, |
278 bool visible) { | 278 bool visible) { |
279 app_window_->OnNativeWindowChanged(); | 279 app_window_->OnNativeWindowChanged(); |
280 } | 280 } |
281 | 281 |
282 void NativeAppWindowViews::OnWidgetActivationChanged(views::Widget* widget, | 282 void NativeAppWindowViews::OnWidgetActivationChanged(views::Widget* widget, |
283 bool active) { | 283 bool active) { |
284 app_window_->OnNativeWindowChanged(); | 284 app_window_->OnNativeWindowChanged(); |
285 if (active) | 285 if (active) |
286 app_window_->OnNativeWindowActivated(); | 286 app_window_->OnNativeWindowActivated(); |
287 } | 287 } |
288 | 288 |
289 // WebContentsObserver implementation. | 289 // WebContentsObserver implementation. |
290 | 290 |
291 void NativeAppWindowViews::RenderViewCreated( | 291 void NativeAppWindowViews::RenderViewCreated( |
292 content::RenderViewHost* render_view_host) { | 292 content::RenderViewHost* render_view_host) { |
293 if (app_window_->requested_alpha_enabled() && CanHaveAlphaEnabled()) { | 293 if (app_window_->RequestedAlphaEnabled() && CanHaveAlphaEnabled()) { |
294 content::RenderWidgetHostView* view = render_view_host->GetView(); | 294 content::RenderWidgetHostView* view = render_view_host->GetView(); |
295 DCHECK(view); | 295 DCHECK(view); |
296 view->SetBackgroundOpaque(false); | 296 view->SetBackgroundOpaque(false); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 void NativeAppWindowViews::RenderViewHostChanged( | 300 void NativeAppWindowViews::RenderViewHostChanged( |
301 content::RenderViewHost* old_host, | 301 content::RenderViewHost* old_host, |
302 content::RenderViewHost* new_host) { | 302 content::RenderViewHost* new_host) { |
303 OnViewWasResized(); | 303 OnViewWasResized(); |
304 } | 304 } |
305 | 305 |
306 // views::View implementation. | 306 // views::View implementation. |
307 | 307 |
308 void NativeAppWindowViews::Layout() { | 308 void NativeAppWindowViews::Layout() { |
309 DCHECK(web_view_); | 309 DCHECK(web_view_); |
310 web_view_->SetBounds(0, 0, width(), height()); | 310 web_view_->SetBounds(0, 0, width(), height()); |
311 OnViewWasResized(); | 311 OnViewWasResized(); |
312 } | 312 } |
313 | 313 |
314 void NativeAppWindowViews::ViewHierarchyChanged( | 314 void NativeAppWindowViews::ViewHierarchyChanged( |
315 const ViewHierarchyChangedDetails& details) { | 315 const ViewHierarchyChangedDetails& details) { |
316 if (details.is_add && details.child == this) { | 316 if (details.is_add && details.child == this) { |
317 web_view_ = new views::WebView(NULL); | 317 web_view_ = new views::WebView(NULL); |
318 AddChildView(web_view_); | 318 AddChildView(web_view_); |
319 web_view_->SetWebContents(app_window_->web_contents()); | 319 web_view_->SetWebContents(app_window_->GetWebContents()); |
320 } | 320 } |
321 } | 321 } |
322 | 322 |
323 gfx::Size NativeAppWindowViews::GetMinimumSize() const { | 323 gfx::Size NativeAppWindowViews::GetMinimumSize() const { |
324 return size_constraints_.GetMinimumSize(); | 324 return size_constraints_.GetMinimumSize(); |
325 } | 325 } |
326 | 326 |
327 gfx::Size NativeAppWindowViews::GetMaximumSize() const { | 327 gfx::Size NativeAppWindowViews::GetMaximumSize() const { |
328 return size_constraints_.GetMaximumSize(); | 328 return size_constraints_.GetMaximumSize(); |
329 } | 329 } |
330 | 330 |
331 void NativeAppWindowViews::OnFocus() { | 331 void NativeAppWindowViews::OnFocus() { |
332 web_view_->RequestFocus(); | 332 web_view_->RequestFocus(); |
333 } | 333 } |
334 | 334 |
335 // NativeAppWindow implementation. | 335 // NativeAppWindow implementation. |
336 | 336 |
337 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { | 337 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
338 // Stub implementation. See also ChromeNativeAppWindowViews. | 338 // Stub implementation. See also ChromeNativeAppWindowViews. |
339 widget_->SetFullscreen(fullscreen_types != AppWindow::FULLSCREEN_TYPE_NONE); | 339 widget_->SetFullscreen(fullscreen_types != |
| 340 native_app_window::FULLSCREEN_TYPE_NONE); |
340 } | 341 } |
341 | 342 |
342 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 343 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
343 // Stub implementation. See also ChromeNativeAppWindowViews. | 344 // Stub implementation. See also ChromeNativeAppWindowViews. |
344 return widget_->IsFullscreen(); | 345 return widget_->IsFullscreen(); |
345 } | 346 } |
346 | 347 |
347 void NativeAppWindowViews::UpdateWindowIcon() { | 348 void NativeAppWindowViews::UpdateWindowIcon() { |
348 widget_->UpdateWindowIcon(); | 349 widget_->UpdateWindowIcon(); |
349 } | 350 } |
350 | 351 |
351 void NativeAppWindowViews::UpdateWindowTitle() { | 352 void NativeAppWindowViews::UpdateWindowTitle() { |
352 widget_->UpdateWindowTitle(); | 353 widget_->UpdateWindowTitle(); |
353 } | 354 } |
354 | 355 |
355 void NativeAppWindowViews::UpdateBadgeIcon() { | 356 void NativeAppWindowViews::UpdateBadgeIcon() { |
356 // Stub implementation. See also ChromeNativeAppWindowViews. | 357 // Stub implementation. See also ChromeNativeAppWindowViews. |
357 } | 358 } |
358 | 359 |
359 void NativeAppWindowViews::UpdateDraggableRegions( | 360 void NativeAppWindowViews::UpdateDraggableRegions( |
360 const std::vector<extensions::DraggableRegion>& regions) { | 361 const std::vector<native_app_window::DraggableRegion>& regions) { |
361 // Draggable region is not supported for non-frameless window. | 362 // Draggable region is not supported for non-frameless window. |
362 if (!frameless_) | 363 if (!frameless_) |
363 return; | 364 return; |
364 | 365 |
365 draggable_region_.reset(AppWindow::RawDraggableRegionsToSkRegion(regions)); | 366 draggable_region_.reset(RawDraggableRegionsToSkRegion(regions)); |
366 OnViewWasResized(); | 367 OnViewWasResized(); |
367 } | 368 } |
368 | 369 |
369 SkRegion* NativeAppWindowViews::GetDraggableRegion() { | 370 SkRegion* NativeAppWindowViews::GetDraggableRegion() { |
370 return draggable_region_.get(); | 371 return draggable_region_.get(); |
371 } | 372 } |
372 | 373 |
373 void NativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { | 374 void NativeAppWindowViews::UpdateShape(scoped_ptr<SkRegion> region) { |
374 // Stub implementation. See also ChromeNativeAppWindowViews. | 375 // Stub implementation. See also ChromeNativeAppWindowViews. |
375 } | 376 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 439 |
439 bool NativeAppWindowViews::CanHaveAlphaEnabled() const { | 440 bool NativeAppWindowViews::CanHaveAlphaEnabled() const { |
440 return widget_->IsTranslucentWindowOpacitySupported(); | 441 return widget_->IsTranslucentWindowOpacitySupported(); |
441 } | 442 } |
442 | 443 |
443 void NativeAppWindowViews::SetVisibleOnAllWorkspaces(bool always_visible) { | 444 void NativeAppWindowViews::SetVisibleOnAllWorkspaces(bool always_visible) { |
444 widget_->SetVisibleOnAllWorkspaces(always_visible); | 445 widget_->SetVisibleOnAllWorkspaces(always_visible); |
445 } | 446 } |
446 | 447 |
447 } // namespace native_app_window | 448 } // namespace native_app_window |
OLD | NEW |