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

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

Powered by Google App Engine
This is Rietveld 408576698