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

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

Powered by Google App Engine
This is Rietveld 408576698