Chromium Code Reviews| 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/gfx/path.h" | |
| 11 #include "ui/gfx/scoped_sk_region.h" | |
| 10 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
| 13 #include "ui/views/window/non_client_view.h" | |
| 14 #if defined(OS_WIN) | |
| 15 #include "content/browser/renderer_host/render_view_host.h" | |
| 16 #include "content/browser/renderer_host/render_widget_host_view_win.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 |
| 25 class ShellWindowFrameView : public views::NonClientFrameView { | |
| 26 public: | |
| 27 explicit ShellWindowFrameView(); | |
|
Ben Goodger (Google)
2012/02/07 20:18:57
no explicit
jeremya
2012/02/08 00:35:16
Done.
| |
| 28 virtual ~ShellWindowFrameView(); | |
| 29 | |
| 30 // views::NonClientFrameView implementation. | |
| 31 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; | |
| 32 virtual gfx::Rect GetWindowBoundsForClientBounds( | |
| 33 const gfx::Rect& client_bounds) const OVERRIDE; | |
| 34 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; | |
| 35 virtual void GetWindowMask(const gfx::Size& size, | |
| 36 gfx::Path* window_mask) OVERRIDE; | |
| 37 virtual void ResetWindowControls() OVERRIDE {} | |
| 38 virtual void UpdateWindowIcon() OVERRIDE {} | |
| 39 }; | |
|
Ben Goodger (Google)
2012/02/07 20:18:57
private:
DISALLOW_COPY_AND..
jeremya
2012/02/08 00:35:16
Done.
| |
| 40 | |
| 41 ShellWindowFrameView::ShellWindowFrameView() { | |
| 42 } | |
| 43 | |
| 44 ShellWindowFrameView::~ShellWindowFrameView() { | |
| 45 } | |
| 46 | |
| 47 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { | |
| 48 return gfx::Rect(0, 0, width(), height()); | |
| 49 } | |
| 50 | |
| 51 gfx::Rect ShellWindowFrameView::GetWindowBoundsForClientBounds( | |
| 52 const gfx::Rect& client_bounds) const { | |
| 53 return client_bounds; | |
| 54 } | |
| 55 | |
| 56 int ShellWindowFrameView::NonClientHitTest(const gfx::Point& point) { | |
| 57 int x = point.x(); | |
| 58 int y = point.y(); | |
| 59 if (x <= 5) { | |
| 60 if (y <= 5) { | |
|
Ben Goodger (Google)
2012/02/07 20:18:57
nit: no braces around single line if
jeremya
2012/02/08 00:35:16
Done.
| |
| 61 return HTTOPLEFT; | |
| 62 } | |
| 63 if (y >= height() - 5) { | |
| 64 return HTBOTTOMLEFT; | |
| 65 } | |
| 66 return HTLEFT; | |
| 67 } | |
| 68 if (x >= width() - 5) { | |
| 69 if (y <= 5) { | |
| 70 return HTTOPRIGHT; | |
| 71 } | |
| 72 if (y >= height() - 5) { | |
| 73 return HTBOTTOMRIGHT; | |
| 74 } | |
| 75 return HTRIGHT; | |
| 76 } | |
| 77 if (y <= 5) { | |
| 78 return HTTOP; | |
| 79 } | |
| 80 if (y >= height() - 5) { | |
| 81 return HTBOTTOM; | |
| 82 } | |
| 83 return HTCAPTION; | |
| 84 } | |
| 85 | |
| 86 void ShellWindowFrameView::GetWindowMask(const gfx::Size& size, | |
| 87 gfx::Path* window_mask) { | |
| 88 // Don't touch it. | |
| 89 } | |
| 90 | |
| 91 | |
| 18 ShellWindowViews::ShellWindowViews(ExtensionHost* host) | 92 ShellWindowViews::ShellWindowViews(ExtensionHost* host) |
| 19 : ShellWindow(host) { | 93 : ShellWindow(host) { |
| 20 host_->view()->SetContainer(this); | 94 host_->view()->SetContainer(this); |
| 21 window_ = new views::Widget; | 95 window_ = new views::Widget; |
| 22 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 96 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 23 params.delegate = this; | 97 params.delegate = this; |
| 24 gfx::Rect bounds(0, 0, 512, 384); | 98 params.remove_standard_frame = true; |
| 99 gfx::Rect bounds(10, 10, 512, 384); | |
| 25 params.bounds = bounds; | 100 params.bounds = bounds; |
| 26 window_->Init(params); | 101 window_->Init(params); |
| 27 #if defined(OS_WIN) && !defined(USE_AURA) | 102 #if defined(OS_WIN) && !defined(USE_AURA) |
| 28 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( | 103 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( |
| 29 host_->extension()->id()); | 104 host_->extension()->id()); |
| 30 ui::win::SetAppIdForWindow( | 105 ui::win::SetAppIdForWindow( |
| 31 ShellIntegration::GetAppId(UTF8ToWide(app_name), | 106 ShellIntegration::GetAppId(UTF8ToWide(app_name), |
| 32 host_->profile()->GetPath()), | 107 host_->profile()->GetPath()), |
| 33 GetWidget()->GetTopLevelWidget()->GetNativeWindow()); | 108 GetWidget()->GetTopLevelWidget()->GetNativeWindow()); |
| 34 #endif | 109 #endif |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 47 } | 122 } |
| 48 | 123 |
| 49 bool ShellWindowViews::CanResize() const { | 124 bool ShellWindowViews::CanResize() const { |
| 50 return true; | 125 return true; |
| 51 } | 126 } |
| 52 | 127 |
| 53 views::View* ShellWindowViews::GetContentsView() { | 128 views::View* ShellWindowViews::GetContentsView() { |
| 54 return host_->view(); | 129 return host_->view(); |
| 55 } | 130 } |
| 56 | 131 |
| 132 views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView() { | |
| 133 return new ShellWindowFrameView(); | |
| 134 } | |
| 135 | |
| 57 string16 ShellWindowViews::GetWindowTitle() const { | 136 string16 ShellWindowViews::GetWindowTitle() const { |
| 58 return UTF8ToUTF16(host_->extension()->name()); | 137 return UTF8ToUTF16(host_->extension()->name()); |
| 59 } | 138 } |
| 60 | 139 |
| 61 views::Widget* ShellWindowViews::GetWidget() { | 140 views::Widget* ShellWindowViews::GetWidget() { |
| 62 return window_; | 141 return window_; |
| 63 } | 142 } |
| 64 | 143 |
| 65 const views::Widget* ShellWindowViews::GetWidget() const { | 144 const views::Widget* ShellWindowViews::GetWidget() const { |
| 66 return window_; | 145 return window_; |
| 67 } | 146 } |
| 68 | 147 |
| 148 void ShellWindowViews::OnViewWasResized() { | |
| 149 // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the | |
| 150 // window shape in sync. | |
| 151 #if defined(OS_WIN) | |
| 152 gfx::Size sz = host_->view()->size(); | |
| 153 int height = sz.height(), width = sz.width(); | |
| 154 int radius = 1; | |
| 155 gfx::Path path; | |
| 156 path.moveTo(0, radius); | |
| 157 path.lineTo(radius, 0); | |
| 158 path.lineTo(width - radius, 0); | |
| 159 path.lineTo(width, radius); | |
| 160 path.lineTo(width, height - radius - 1); | |
| 161 path.lineTo(width - radius - 1, height); | |
| 162 path.lineTo(radius + 1, height); | |
| 163 path.lineTo(0, height - radius - 1); | |
| 164 path.close(); | |
| 165 SetWindowRgn(host_->view()->native_view(), path.CreateNativeRegion(), 1); | |
| 166 | |
| 167 SkRegion* rgn = new SkRegion; | |
| 168 rgn->op(0, 0, width, 20, SkRegion::kUnion_Op); | |
| 169 rgn->op(0, 0, 5, height, SkRegion::kUnion_Op); | |
| 170 rgn->op(width - 5, 0, width, height, SkRegion::kUnion_Op); | |
| 171 rgn->op(0, height - 5, width, height, SkRegion::kUnion_Op); | |
| 172 static_cast<RenderWidgetHostViewWin*>(host_->render_view_host()->view()) | |
| 173 ->SetTransparentRegion(rgn); | |
| 174 #endif | |
| 175 } | |
| 176 | |
| 69 // static | 177 // static |
| 70 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { | 178 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { |
| 71 return new ShellWindowViews(host); | 179 return new ShellWindowViews(host); |
| 72 } | 180 } |
| OLD | NEW |