| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/views/extensions/shell_window_views.h" | 5 #include "chrome/browser/ui/views/extensions/shell_window_views.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_host.h" | 8 #include "chrome/browser/extensions/extension_host.h" |
| 9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
| 10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
| 11 #include "ui/gfx/path.h" |
| 12 #include "ui/gfx/scoped_sk_region.h" |
| 13 #include "chrome/browser/ui/extensions/native_shell_frame.h" |
| 14 #if defined(OS_WIN) |
| 15 #include "content/browser/renderer_host/render_widget_host_view_win.h" |
| 16 #include "content/browser/renderer_host/render_view_host.h" |
| 17 #endif |
| 11 | 18 |
| 12 #if defined(OS_WIN) && !defined(USE_AURA) | 19 #if defined(OS_WIN) && !defined(USE_AURA) |
| 13 #include "chrome/browser/shell_integration.h" | 20 #include "chrome/browser/shell_integration.h" |
| 14 #include "chrome/browser/web_applications/web_app.h" | 21 #include "chrome/browser/web_applications/web_app.h" |
| 15 #include "ui/base/win/shell.h" | 22 #include "ui/base/win/shell.h" |
| 16 #endif | 23 #endif |
| 17 | 24 |
| 18 ShellWindowViews::ShellWindowViews(ExtensionHost* host) | 25 ShellWindowViews::ShellWindowViews(ExtensionHost* host) |
| 19 : ShellWindow(host) { | 26 : ShellWindow(host) { |
| 20 host_->view()->SetContainer(this); | 27 host_->view()->SetContainer(this); |
| 21 window_ = new views::Widget; | 28 window_ = new views::Widget; |
| 22 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 29 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 23 params.delegate = this; | 30 params.delegate = this; |
| 24 gfx::Rect bounds(0, 0, 512, 384); | 31 gfx::Rect bounds(10, 10, 512, 384); |
| 25 params.bounds = bounds; | 32 params.bounds = bounds; |
| 33 #if defined(OS_WIN) |
| 34 params.native_widget = NativeShellFrame::CreateNativeShellFrame(window_) |
| 35 ->AsNativeWidget(); |
| 36 #endif |
| 26 window_->Init(params); | 37 window_->Init(params); |
| 27 #if defined(OS_WIN) && !defined(USE_AURA) | 38 #if defined(OS_WIN) && !defined(USE_AURA) |
| 28 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( | 39 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( |
| 29 host_->extension()->id()); | 40 host_->extension()->id()); |
| 30 ui::win::SetAppIdForWindow( | 41 ui::win::SetAppIdForWindow( |
| 31 ShellIntegration::GetAppId(UTF8ToWide(app_name), | 42 ShellIntegration::GetAppId(UTF8ToWide(app_name), |
| 32 host_->profile()->GetPath()), | 43 host_->profile()->GetPath()), |
| 33 GetWidget()->GetTopLevelWidget()->GetNativeWindow()); | 44 GetWidget()->GetTopLevelWidget()->GetNativeWindow()); |
| 34 #endif | 45 #endif |
| 35 window_->Show(); | 46 window_->Show(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 59 } | 70 } |
| 60 | 71 |
| 61 views::Widget* ShellWindowViews::GetWidget() { | 72 views::Widget* ShellWindowViews::GetWidget() { |
| 62 return window_; | 73 return window_; |
| 63 } | 74 } |
| 64 | 75 |
| 65 const views::Widget* ShellWindowViews::GetWidget() const { | 76 const views::Widget* ShellWindowViews::GetWidget() const { |
| 66 return window_; | 77 return window_; |
| 67 } | 78 } |
| 68 | 79 |
| 80 void ShellWindowViews::OnViewWasResized() { |
| 81 // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the |
| 82 // window shape in sync. |
| 83 #if defined(OS_WIN) |
| 84 gfx::Size sz = host_->view()->size(); |
| 85 int height = sz.height(), width = sz.width(); |
| 86 int radius = 1; |
| 87 gfx::Path path; |
| 88 path.moveTo(0, radius); |
| 89 path.lineTo(radius, 0); |
| 90 path.lineTo(width - radius, 0); |
| 91 path.lineTo(width, radius); |
| 92 path.lineTo(width, height - radius - 1); |
| 93 path.lineTo(width - radius - 1, height); |
| 94 path.lineTo(radius + 1, height); |
| 95 path.lineTo(0, height - radius - 1); |
| 96 path.close(); |
| 97 SetWindowRgn(host_->view()->native_view(), path.CreateNativeRegion(), 1); |
| 98 |
| 99 SkRegion* rgn = new SkRegion; |
| 100 rgn->op(0, 0, width, 20, SkRegion::kUnion_Op); |
| 101 rgn->op(0, 0, 5, height, SkRegion::kUnion_Op); |
| 102 rgn->op(width - 5, 0, width, height, SkRegion::kUnion_Op); |
| 103 rgn->op(0, height - 5, width, height, SkRegion::kUnion_Op); |
| 104 static_cast<RenderWidgetHostViewWin*>(host_->render_view_host()->view()) |
| 105 ->SetTransparentRegion(rgn); |
| 106 #endif |
| 107 } |
| 108 |
| 69 // static | 109 // static |
| 70 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { | 110 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { |
| 71 return new ShellWindowViews(host); | 111 return new ShellWindowViews(host); |
| 72 } | 112 } |
| OLD | NEW |