Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: chrome/browser/ui/views/extensions/shell_window_views.cc

Issue 9254046: Custom frame UI for platform apps on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rearchitect to use NonClientFrameView Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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();
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 };
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) {
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 gfx::Rect bounds(10, 10, 512, 384);
25 params.bounds = bounds; 99 params.bounds = bounds;
26 window_->Init(params); 100 window_->Init(params);
27 #if defined(OS_WIN) && !defined(USE_AURA) 101 #if defined(OS_WIN) && !defined(USE_AURA)
28 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( 102 std::string app_name = web_app::GenerateApplicationNameFromExtensionId(
29 host_->extension()->id()); 103 host_->extension()->id());
30 ui::win::SetAppIdForWindow( 104 ui::win::SetAppIdForWindow(
31 ShellIntegration::GetAppId(UTF8ToWide(app_name), 105 ShellIntegration::GetAppId(UTF8ToWide(app_name),
32 host_->profile()->GetPath()), 106 host_->profile()->GetPath()),
33 GetWidget()->GetTopLevelWidget()->GetNativeWindow()); 107 GetWidget()->GetTopLevelWidget()->GetNativeWindow());
34 #endif 108 #endif
(...skipping 12 matching lines...) Expand all
47 } 121 }
48 122
49 bool ShellWindowViews::CanResize() const { 123 bool ShellWindowViews::CanResize() const {
50 return true; 124 return true;
51 } 125 }
52 126
53 views::View* ShellWindowViews::GetContentsView() { 127 views::View* ShellWindowViews::GetContentsView() {
54 return host_->view(); 128 return host_->view();
55 } 129 }
56 130
131 views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView() {
132 return new ShellWindowFrameView();
133 }
134
57 string16 ShellWindowViews::GetWindowTitle() const { 135 string16 ShellWindowViews::GetWindowTitle() const {
58 return UTF8ToUTF16(host_->extension()->name()); 136 return UTF8ToUTF16(host_->extension()->name());
59 } 137 }
60 138
61 views::Widget* ShellWindowViews::GetWidget() { 139 views::Widget* ShellWindowViews::GetWidget() {
62 return window_; 140 return window_;
63 } 141 }
64 142
65 const views::Widget* ShellWindowViews::GetWidget() const { 143 const views::Widget* ShellWindowViews::GetWidget() const {
66 return window_; 144 return window_;
67 } 145 }
68 146
147 void ShellWindowViews::OnViewWasResized() {
148 // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the
149 // window shape in sync.
150 #if defined(OS_WIN)
151 gfx::Size sz = host_->view()->size();
152 int height = sz.height(), width = sz.width();
153 int radius = 1;
154 gfx::Path path;
155 path.moveTo(0, radius);
156 path.lineTo(radius, 0);
157 path.lineTo(width - radius, 0);
158 path.lineTo(width, radius);
159 path.lineTo(width, height - radius - 1);
160 path.lineTo(width - radius - 1, height);
161 path.lineTo(radius + 1, height);
162 path.lineTo(0, height - radius - 1);
163 path.close();
164 SetWindowRgn(host_->view()->native_view(), path.CreateNativeRegion(), 1);
165
166 SkRegion* rgn = new SkRegion;
167 rgn->op(0, 0, width, 20, SkRegion::kUnion_Op);
168 rgn->op(0, 0, 5, height, SkRegion::kUnion_Op);
169 rgn->op(width - 5, 0, width, height, SkRegion::kUnion_Op);
170 rgn->op(0, height - 5, width, height, SkRegion::kUnion_Op);
171 static_cast<RenderWidgetHostViewWin*>(host_->render_view_host()->view())
172 ->SetTransparentRegion(rgn);
173 #endif
174 }
175
69 // static 176 // static
70 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { 177 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) {
71 return new ShellWindowViews(host); 178 return new ShellWindowViews(host);
72 } 179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698