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

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

Issue 10119003: Pull shell window stuff out of ExtensionHost and put in ShellWindow (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Try jobs Created 8 years, 7 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 "content/public/browser/render_view_host.h"
11 #include "content/public/browser/render_widget_host_view.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_view.h"
10 #include "ui/base/hit_test.h" 14 #include "ui/base/hit_test.h"
11 #include "ui/gfx/path.h" 15 #include "ui/gfx/path.h"
12 #include "ui/gfx/scoped_sk_region.h" 16 #include "ui/gfx/scoped_sk_region.h"
13 #include "ui/views/layout/fill_layout.h" 17 #include "ui/views/layout/fill_layout.h"
14 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
15 #include "ui/views/window/non_client_view.h" 19 #include "ui/views/window/non_client_view.h"
16 20
17 #if defined(OS_WIN) && !defined(USE_AURA) 21 #if defined(OS_WIN) && !defined(USE_AURA)
18 #include "chrome/browser/shell_integration.h" 22 #include "chrome/browser/shell_integration.h"
19 #include "chrome/browser/web_applications/web_app.h" 23 #include "chrome/browser/web_applications/web_app.h"
20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host_view.h"
22 #include "ui/base/win/shell.h" 24 #include "ui/base/win/shell.h"
23 #endif 25 #endif
24 26
25 #if defined(USE_ASH) 27 #if defined(USE_ASH)
26 #include "ash/wm/custom_frame_view_ash.h" 28 #include "ash/wm/custom_frame_view_ash.h"
27 #endif 29 #endif
28 30
29 // Number of pixels around the edge of the window that can be dragged to 31 // Number of pixels around the edge of the window that can be dragged to
30 // resize the window. 32 // resize the window.
31 static const int kResizeBorderWidth = 5; 33 static const int kResizeBorderWidth = 5;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if (y >= height() - kResizeBorderWidth) 91 if (y >= height() - kResizeBorderWidth)
90 return HTBOTTOM; 92 return HTBOTTOM;
91 return HTCAPTION; 93 return HTCAPTION;
92 } 94 }
93 95
94 void ShellWindowFrameView::GetWindowMask(const gfx::Size& size, 96 void ShellWindowFrameView::GetWindowMask(const gfx::Size& size,
95 gfx::Path* window_mask) { 97 gfx::Path* window_mask) {
96 // Don't touch it. 98 // Don't touch it.
97 } 99 }
98 100
99 ShellWindowViews::ShellWindowViews(ExtensionHost* host) 101 ShellWindowViews::ShellWindowViews(Profile* profile,
100 : ShellWindow(host) { 102 const Extension* extension,
101 host_->view()->SetContainer(this); 103 const GURL& url)
104 : ShellWindow(profile, extension, url),
105 initialized_(false) {
102 window_ = new views::Widget; 106 window_ = new views::Widget;
103 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 107 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
104 params.delegate = this; 108 params.delegate = this;
105 params.remove_standard_frame = true; 109 params.remove_standard_frame = true;
106 gfx::Rect bounds(10, 10, kDefaultWidth, kDefaultHeight); 110 gfx::Rect bounds(10, 10, kDefaultWidth, kDefaultHeight);
107 params.bounds = bounds; 111 params.bounds = bounds;
108 window_->Init(params); 112 window_->Init(params);
109 #if defined(OS_WIN) && !defined(USE_AURA) 113 #if defined(OS_WIN) && !defined(USE_AURA)
110 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( 114 std::string app_name = web_app::GenerateApplicationNameFromExtensionId(
111 host_->extension()->id()); 115 extension->id());
112 ui::win::SetAppIdForWindow( 116 ui::win::SetAppIdForWindow(
113 ShellIntegration::GetAppId(UTF8ToWide(app_name), 117 ShellIntegration::GetAppId(UTF8ToWide(app_name),
114 host_->profile()->GetPath()), 118 profile->GetPath()),
115 GetWidget()->GetTopLevelWidget()->GetNativeWindow()); 119 GetWidget()->GetTopLevelWidget()->GetNativeWindow());
116 #endif 120 #endif
117 AddChildView(host_->view());
jeremya 2012/05/07 00:54:38 If you never add a view to the widget, how does th
benwells 2012/05/07 08:46:15 There is no need for the ExtensionView to be a chi
118 SetLayoutManager(new views::FillLayout); 121 SetLayoutManager(new views::FillLayout);
119 Layout(); 122 Layout();
120 123
121 window_->Show(); 124 window_->Show();
122 } 125 }
123 126
124 ShellWindowViews::~ShellWindowViews() { 127 ShellWindowViews::~ShellWindowViews() {
125 } 128 }
126 129
127 bool ShellWindowViews::IsActive() const { 130 bool ShellWindowViews::IsActive() const {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // aura. 230 // aura.
228 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); 231 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh();
229 frame->Init(widget); 232 frame->Init(widget);
230 return frame; 233 return frame;
231 #else 234 #else
232 return new ShellWindowFrameView(); 235 return new ShellWindowFrameView();
233 #endif 236 #endif
234 } 237 }
235 238
236 string16 ShellWindowViews::GetWindowTitle() const { 239 string16 ShellWindowViews::GetWindowTitle() const {
237 return UTF8ToUTF16(host_->extension()->name()); 240 return UTF8ToUTF16(extension()->name());
238 } 241 }
239 242
240 views::Widget* ShellWindowViews::GetWidget() { 243 views::Widget* ShellWindowViews::GetWidget() {
241 return window_; 244 return window_;
242 } 245 }
243 246
244 const views::Widget* ShellWindowViews::GetWidget() const { 247 const views::Widget* ShellWindowViews::GetWidget() const {
245 return window_; 248 return window_;
246 } 249 }
247 250
248 void ShellWindowViews::OnViewWasResized() { 251 void ShellWindowViews::OnViewWasResized() {
249 // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the 252 // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the
250 // window shape in sync. 253 // window shape in sync.
251 #if defined(OS_WIN) && !defined(USE_AURA) 254 #if defined(OS_WIN) && !defined(USE_AURA)
252 gfx::Size sz = host_->view()->size(); 255 gfx::Size sz = size();
253 int height = sz.height(), width = sz.width(); 256 int height = sz.height(), width = sz.width();
254 int radius = 1; 257 int radius = 1;
255 gfx::Path path; 258 gfx::Path path;
256 if (GetWidget()->IsMaximized()) { 259 if (GetWidget()->IsMaximized()) {
257 // Don't round the corners when the window is maximized. 260 // Don't round the corners when the window is maximized.
258 path.addRect(0, 0, width, height); 261 path.addRect(0, 0, width, height);
259 } else { 262 } else {
260 path.moveTo(0, radius); 263 path.moveTo(0, radius);
261 path.lineTo(radius, 0); 264 path.lineTo(radius, 0);
262 path.lineTo(width - radius, 0); 265 path.lineTo(width - radius, 0);
263 path.lineTo(width, radius); 266 path.lineTo(width, radius);
264 path.lineTo(width, height - radius - 1); 267 path.lineTo(width, height - radius - 1);
265 path.lineTo(width - radius - 1, height); 268 path.lineTo(width - radius - 1, height);
266 path.lineTo(radius + 1, height); 269 path.lineTo(radius + 1, height);
267 path.lineTo(0, height - radius - 1); 270 path.lineTo(0, height - radius - 1);
268 path.close(); 271 path.close();
269 } 272 }
270 SetWindowRgn(host_->view()->native_view(), path.CreateNativeRegion(), 1); 273 SetWindowRgn(native_view(), path.CreateNativeRegion(), 1);
271 274
272 SkRegion* rgn = new SkRegion; 275 SkRegion* rgn = new SkRegion;
273 if (caption_region_.Get()) 276 if (caption_region_.Get())
274 rgn->op(*caption_region_.Get(), SkRegion::kUnion_Op); 277 rgn->op(*caption_region_.Get(), SkRegion::kUnion_Op);
275 if (!GetWidget()->IsMaximized()) { 278 if (!GetWidget()->IsMaximized()) {
276 rgn->op(0, 0, width, kResizeBorderWidth, SkRegion::kUnion_Op); 279 rgn->op(0, 0, width, kResizeBorderWidth, SkRegion::kUnion_Op);
277 rgn->op(0, 0, kResizeBorderWidth, height, SkRegion::kUnion_Op); 280 rgn->op(0, 0, kResizeBorderWidth, height, SkRegion::kUnion_Op);
278 rgn->op(width - kResizeBorderWidth, 0, width, height, SkRegion::kUnion_Op); 281 rgn->op(width - kResizeBorderWidth, 0, width, height, SkRegion::kUnion_Op);
279 rgn->op(0, height - kResizeBorderWidth, width, height, SkRegion::kUnion_Op); 282 rgn->op(0, height - kResizeBorderWidth, width, height, SkRegion::kUnion_Op);
280 } 283 }
281 host_->render_view_host()->GetView()->SetClickthroughRegion(rgn); 284 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn);
282 #endif 285 #endif
283 } 286 }
284 287
288 gfx::NativeCursor ShellWindowViews::GetCursor(const views::MouseEvent& event) {
289 return gfx::kNullCursor;
290 }
291
292 void ShellWindowViews::SetVisible(bool is_visible) {
293 if (is_visible != visible()) {
294 NativeViewHost::SetVisible(is_visible);
295
296 // Also tell RenderWidgetHostView the new visibility. Despite its name, it
297 // is not part of the View hierarchy and does not know about the change
298 // unless we tell it.
299 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
300 if (rvh->GetView()) {
301 if (is_visible)
302 rvh->GetView()->Show();
303 else
304 rvh->GetView()->Hide();
305 }
306 }
307 }
308
309 void ShellWindowViews::ViewHierarchyChanged(bool is_add,
310 views::View *parent,
311 views::View *child) {
312 NativeViewHost::ViewHierarchyChanged(is_add, parent, child);
313 if (is_add && GetWidget() && !initialized_) {
314 initialized_ = true;
315 NativeViewHost::Attach(web_contents()->GetView()->GetNativeView());
316 }
317 }
318
319 void ShellWindowViews::PreferredSizeChanged() {
320 View::PreferredSizeChanged();
321 }
322
323 bool ShellWindowViews::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
324 // Let the tab key event be processed by the renderer (instead of moving the
325 // focus to the next focusable view). Also handle Backspace, since otherwise
326 // (on Windows at least), pressing Backspace, when focus is on a text field
327 // within the ExtensionView, will navigate the page back instead of erasing a
328 // character.
329 return (e.key_code() == ui::VKEY_TAB || e.key_code() == ui::VKEY_BACK);
330 }
331
332 void ShellWindowViews::OnBoundsChanged(const gfx::Rect& previous_bounds) {
333 // Propagate the new size to RenderWidgetHostView.
334 // We can't send size zero because RenderWidget DCHECKs that.
335 content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
336 if (rvh->GetView() && !bounds().IsEmpty()) {
337 rvh->GetView()->SetSize(size());
338 OnViewWasResized();
339 }
340 }
341
285 // static 342 // static
286 ShellWindow* ShellWindow::CreateShellWindow(ExtensionHost* host) { 343 ShellWindow* ShellWindow::CreateImpl(Profile* profile,
287 return new ShellWindowViews(host); 344 const Extension* extension,
345 const GURL& url) {
346 return new ShellWindowViews(profile, extension, url);
288 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698