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

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: "Transparent" -> "Clickthrough", fix patchset 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"
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"
11 15
12 #if defined(OS_WIN) && !defined(USE_AURA) 16 #if defined(OS_WIN) && !defined(USE_AURA)
13 #include "chrome/browser/shell_integration.h" 17 #include "chrome/browser/shell_integration.h"
14 #include "chrome/browser/web_applications/web_app.h" 18 #include "chrome/browser/web_applications/web_app.h"
19 #include "content/browser/renderer_host/render_view_host.h"
20 #include "content/public/browser/render_widget_host_view.h"
15 #include "ui/base/win/shell.h" 21 #include "ui/base/win/shell.h"
16 #endif 22 #endif
17 23
24 // Number of pixels around the edge of the window that can be dragged to
25 // resize the window.
26 static const int kResizeBorderWidth = 5;
27
28 class ShellWindowFrameView : public views::NonClientFrameView {
29 public:
30 ShellWindowFrameView();
31 virtual ~ShellWindowFrameView();
32
33 // views::NonClientFrameView implementation.
34 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
35 virtual gfx::Rect GetWindowBoundsForClientBounds(
36 const gfx::Rect& client_bounds) const OVERRIDE;
37 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
38 virtual void GetWindowMask(const gfx::Size& size,
39 gfx::Path* window_mask) OVERRIDE;
40 virtual void ResetWindowControls() OVERRIDE {}
41 virtual void UpdateWindowIcon() OVERRIDE {}
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(ShellWindowFrameView);
45 };
46
47 ShellWindowFrameView::ShellWindowFrameView() {
48 }
49
50 ShellWindowFrameView::~ShellWindowFrameView() {
51 }
52
53 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const {
54 return gfx::Rect(0, 0, width(), height());
55 }
56
57 gfx::Rect ShellWindowFrameView::GetWindowBoundsForClientBounds(
58 const gfx::Rect& client_bounds) const {
59 return client_bounds;
60 }
61
62 int ShellWindowFrameView::NonClientHitTest(const gfx::Point& point) {
63 int x = point.x();
64 int y = point.y();
65 if (x <= kResizeBorderWidth) {
66 if (y <= kResizeBorderWidth)
67 return HTTOPLEFT;
68 if (y >= height() - kResizeBorderWidth)
69 return HTBOTTOMLEFT;
70 return HTLEFT;
71 }
72 if (x >= width() - kResizeBorderWidth) {
73 if (y <= kResizeBorderWidth)
74 return HTTOPRIGHT;
75 if (y >= height() - kResizeBorderWidth)
76 return HTBOTTOMRIGHT;
77 return HTRIGHT;
78 }
79 if (y <= kResizeBorderWidth)
80 return HTTOP;
81 if (y >= height() - kResizeBorderWidth)
82 return HTBOTTOM;
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
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) && !defined(USE_AURA)
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, kResizeBorderWidth, height, SkRegion::kUnion_Op);
170 rgn->op(width - kResizeBorderWidth, 0, width, height, SkRegion::kUnion_Op);
171 rgn->op(0, height - kResizeBorderWidth, width, height, SkRegion::kUnion_Op);
172 host_->render_view_host()->view()->SetClickthroughRegion(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