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

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

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

Powered by Google App Engine
This is Rietveld 408576698