| 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 ShellWindowViews::ShellWindowViews(ExtensionHost* host) | 19 ShellWindowViews::ShellWindowViews(ExtensionHost* host) |
| 13 : ShellWindow(host) { | 20 : ShellWindow(host) { |
| 14 host_->view()->SetContainer(this); | 21 host_->view()->SetContainer(this); |
| 15 window_ = new views::Widget; | 22 window_ = new views::Widget; |
| 16 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 23 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 17 params.delegate = this; | 24 params.delegate = this; |
| 18 gfx::Rect bounds(0, 0, 512, 384); | 25 gfx::Rect bounds(10, 10, 512, 384); |
| 19 params.bounds = bounds; | 26 params.bounds = bounds; |
| 27 #if defined(OS_WIN) |
| 28 params.native_widget = NativeShellFrame::CreateNativeShellFrame(window_) |
| 29 ->AsNativeWidget(); |
| 30 #endif |
| 20 window_->Init(params); | 31 window_->Init(params); |
| 21 window_->Show(); | 32 window_->Show(); |
| 22 } | 33 } |
| 23 | 34 |
| 24 ShellWindowViews::~ShellWindowViews() { | 35 ShellWindowViews::~ShellWindowViews() { |
| 25 } | 36 } |
| 26 | 37 |
| 27 void ShellWindowViews::Close() { | 38 void ShellWindowViews::Close() { |
| 28 window_->Close(); | 39 window_->Close(); |
| 29 } | 40 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 45 } | 56 } |
| 46 | 57 |
| 47 views::Widget* ShellWindowViews::GetWidget() { | 58 views::Widget* ShellWindowViews::GetWidget() { |
| 48 return window_; | 59 return window_; |
| 49 } | 60 } |
| 50 | 61 |
| 51 const views::Widget* ShellWindowViews::GetWidget() const { | 62 const views::Widget* ShellWindowViews::GetWidget() const { |
| 52 return window_; | 63 return window_; |
| 53 } | 64 } |
| 54 | 65 |
| 66 void ShellWindowViews::OnRenderViewSizeChanged() { |
| 67 // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the |
| 68 // window shape in sync. |
| 69 #if defined(OS_WIN) |
| 70 gfx::Size sz = host_->view()->size(); |
| 71 int height = sz.height(), width = sz.width(); |
| 72 int radius = 1; |
| 73 gfx::Path path; |
| 74 path.moveTo(0, radius); |
| 75 path.lineTo(radius, 0); |
| 76 path.lineTo(width - radius, 0); |
| 77 path.lineTo(width, radius); |
| 78 path.lineTo(width, height - radius - 1); |
| 79 path.lineTo(width - radius - 1, height); |
| 80 path.lineTo(radius + 1, height); |
| 81 path.lineTo(0, height - radius - 1); |
| 82 path.close(); |
| 83 SetWindowRgn(host_->view()->native_view(), path.CreateNativeRegion(), 1); |
| 84 |
| 85 SkRegion* rgn = new SkRegion; |
| 86 rgn->op(0, 0, width, 20, SkRegion::kUnion_Op); |
| 87 rgn->op(0, 0, 5, height, SkRegion::kUnion_Op); |
| 88 rgn->op(width - 5, 0, width, height, SkRegion::kUnion_Op); |
| 89 rgn->op(0, height - 5, width, height, SkRegion::kUnion_Op); |
| 90 static_cast<RenderWidgetHostViewWin*>(host_->render_view_host()->view()) |
| 91 ->SetTransparentRegion(rgn); |
| 92 #endif |
| 93 } |
| 94 |
| 55 // static | 95 // static |
| 56 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { | 96 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { |
| 57 return new ShellWindowViews(host); | 97 return new ShellWindowViews(host); |
| 58 } | 98 } |
| OLD | NEW |