| 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 "apps/ui/views/native_app_window_views.h" | 5 #include "apps/ui/views/native_app_window_views.h" |
| 6 | 6 |
| 7 #include "apps/app_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "base/threading/sequenced_worker_pool.h" | 8 #include "base/threading/sequenced_worker_pool.h" |
| 9 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
| 10 #include "content/public/browser/render_widget_host_view.h" | 10 #include "content/public/browser/render_widget_host_view.h" |
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "extensions/common/draggable_region.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 namespace apps { | 23 namespace apps { |
| 24 | 24 |
| 25 NativeAppWindowViews::NativeAppWindowViews() | 25 NativeAppWindowViews::NativeAppWindowViews() |
| 26 : app_window_(NULL), | 26 : app_window_(NULL), |
| 27 web_view_(NULL), | 27 web_view_(NULL), |
| 28 widget_(NULL), | 28 widget_(NULL), |
| 29 frameless_(false), | 29 frameless_(false), |
| 30 transparent_background_(false), | |
| 31 resizable_(false) {} | 30 resizable_(false) {} |
| 32 | 31 |
| 33 void NativeAppWindowViews::Init(AppWindow* app_window, | 32 void NativeAppWindowViews::Init(AppWindow* app_window, |
| 34 const AppWindow::CreateParams& create_params) { | 33 const AppWindow::CreateParams& create_params) { |
| 35 app_window_ = app_window; | 34 app_window_ = app_window; |
| 36 frameless_ = create_params.frame == AppWindow::FRAME_NONE; | 35 frameless_ = create_params.frame == AppWindow::FRAME_NONE; |
| 37 transparent_background_ = create_params.transparent_background; | |
| 38 resizable_ = create_params.resizable; | 36 resizable_ = create_params.resizable; |
| 39 size_constraints_.set_minimum_size( | 37 size_constraints_.set_minimum_size( |
| 40 create_params.GetContentMinimumSize(gfx::Insets())); | 38 create_params.GetContentMinimumSize(gfx::Insets())); |
| 41 size_constraints_.set_maximum_size( | 39 size_constraints_.set_maximum_size( |
| 42 create_params.GetContentMaximumSize(gfx::Insets())); | 40 create_params.GetContentMaximumSize(gfx::Insets())); |
| 43 Observe(app_window_->web_contents()); | 41 Observe(app_window_->web_contents()); |
| 44 | 42 |
| 45 widget_ = new views::Widget; | 43 widget_ = new views::Widget; |
| 46 InitializeWindow(app_window, create_params); | 44 InitializeWindow(app_window, create_params); |
| 47 | 45 |
| 48 OnViewWasResized(); | 46 OnViewWasResized(); |
| 49 widget_->AddObserver(this); | 47 widget_->AddObserver(this); |
| 50 } | 48 } |
| 51 | 49 |
| 52 NativeAppWindowViews::~NativeAppWindowViews() { | 50 NativeAppWindowViews::~NativeAppWindowViews() { |
| 53 web_view_->SetWebContents(NULL); | 51 web_view_->SetWebContents(NULL); |
| 54 } | 52 } |
| 55 | 53 |
| 54 void NativeAppWindowViews::OnCanHaveAlphaEnabledChanged() { |
| 55 app_window_->OnNativeWindowChanged(); |
| 56 } |
| 57 |
| 56 void NativeAppWindowViews::InitializeWindow( | 58 void NativeAppWindowViews::InitializeWindow( |
| 57 AppWindow* app_window, | 59 AppWindow* app_window, |
| 58 const AppWindow::CreateParams& create_params) { | 60 const AppWindow::CreateParams& create_params) { |
| 59 // Stub implementation. See also ChromeNativeAppWindowViews. | 61 // Stub implementation. See also ChromeNativeAppWindowViews. |
| 60 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); | 62 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_WINDOW); |
| 61 init_params.delegate = this; | 63 init_params.delegate = this; |
| 62 init_params.keep_on_top = create_params.always_on_top; | 64 init_params.keep_on_top = create_params.always_on_top; |
| 63 widget_->Init(init_params); | 65 widget_->Init(init_params); |
| 64 widget_->CenterWindow( | 66 widget_->CenterWindow( |
| 65 create_params.GetInitialWindowBounds(gfx::Insets()).size()); | 67 create_params.GetInitialWindowBounds(gfx::Insets()).size()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 bool active) { | 255 bool active) { |
| 254 app_window_->OnNativeWindowChanged(); | 256 app_window_->OnNativeWindowChanged(); |
| 255 if (active) | 257 if (active) |
| 256 app_window_->OnNativeWindowActivated(); | 258 app_window_->OnNativeWindowActivated(); |
| 257 } | 259 } |
| 258 | 260 |
| 259 // WebContentsObserver implementation. | 261 // WebContentsObserver implementation. |
| 260 | 262 |
| 261 void NativeAppWindowViews::RenderViewCreated( | 263 void NativeAppWindowViews::RenderViewCreated( |
| 262 content::RenderViewHost* render_view_host) { | 264 content::RenderViewHost* render_view_host) { |
| 263 if (transparent_background_) { | 265 if (app_window_->requested_transparent_background() && |
| 266 CanHaveAlphaEnabled()) { |
| 264 content::RenderWidgetHostView* view = render_view_host->GetView(); | 267 content::RenderWidgetHostView* view = render_view_host->GetView(); |
| 265 DCHECK(view); | 268 DCHECK(view); |
| 266 view->SetBackgroundOpaque(false); | 269 view->SetBackgroundOpaque(false); |
| 267 } | 270 } |
| 268 } | 271 } |
| 269 | 272 |
| 270 void NativeAppWindowViews::RenderViewHostChanged( | 273 void NativeAppWindowViews::RenderViewHostChanged( |
| 271 content::RenderViewHost* old_host, | 274 content::RenderViewHost* old_host, |
| 272 content::RenderViewHost* new_host) { | 275 content::RenderViewHost* new_host) { |
| 273 OnViewWasResized(); | 276 OnViewWasResized(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 gfx::Size NativeAppWindowViews::GetContentMaximumSize() const { | 394 gfx::Size NativeAppWindowViews::GetContentMaximumSize() const { |
| 392 return size_constraints_.GetMaximumSize(); | 395 return size_constraints_.GetMaximumSize(); |
| 393 } | 396 } |
| 394 | 397 |
| 395 void NativeAppWindowViews::SetContentSizeConstraints( | 398 void NativeAppWindowViews::SetContentSizeConstraints( |
| 396 const gfx::Size& min_size, const gfx::Size& max_size) { | 399 const gfx::Size& min_size, const gfx::Size& max_size) { |
| 397 size_constraints_.set_minimum_size(min_size); | 400 size_constraints_.set_minimum_size(min_size); |
| 398 size_constraints_.set_maximum_size(max_size); | 401 size_constraints_.set_maximum_size(max_size); |
| 399 } | 402 } |
| 400 | 403 |
| 404 bool NativeAppWindowViews::CanHaveAlphaEnabled() const { |
| 405 return widget_->IsTranslucentWindowOpacitySupported(); |
| 406 } |
| 407 |
| 401 } // namespace apps | 408 } // namespace apps |
| OLD | NEW |