OLD | NEW |
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/app_window_views.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | |
8 #include "chrome/browser/extensions/extension_host.h" | |
9 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
10 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | |
11 #include "chrome/common/extensions/draggable_region.h" | 7 #include "chrome/common/extensions/draggable_region.h" |
12 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
13 #include "content/public/browser/render_view_host.h" | |
14 #include "content/public/browser/render_widget_host_view.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "content/public/browser/web_contents_view.h" | |
17 #include "grit/theme_resources.h" | 9 #include "grit/theme_resources.h" |
18 #include "grit/ui_strings.h" // Accessibility names | 10 #include "grit/ui_strings.h" // Accessibility names |
19 #include "third_party/skia/include/core/SkPaint.h" | 11 #include "third_party/skia/include/core/SkPaint.h" |
20 #include "ui/base/hit_test.h" | 12 #include "ui/base/hit_test.h" |
21 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/image/image.h" | |
25 #include "ui/gfx/path.h" | 16 #include "ui/gfx/path.h" |
26 #include "ui/views/controls/button/button.h" | |
27 #include "ui/views/controls/button/image_button.h" | 17 #include "ui/views/controls/button/image_button.h" |
28 #include "ui/views/controls/webview/webview.h" | 18 #include "ui/views/controls/webview/webview.h" |
29 #include "ui/views/layout/grid_layout.h" | |
30 #include "ui/views/views_delegate.h" | |
31 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
32 #include "ui/views/window/non_client_view.h" | |
33 | 20 |
34 #if defined(OS_WIN) && !defined(USE_AURA) | 21 #if defined(OS_WIN) && !defined(USE_AURA) |
| 22 #include "base/utf_string_conversions.h" |
35 #include "chrome/browser/shell_integration.h" | 23 #include "chrome/browser/shell_integration.h" |
36 #include "chrome/browser/web_applications/web_app.h" | 24 #include "chrome/browser/web_applications/web_app.h" |
| 25 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/render_widget_host_view.h" |
37 #include "ui/base/win/shell.h" | 27 #include "ui/base/win/shell.h" |
38 #endif | 28 #endif |
39 | 29 |
40 #if defined(USE_ASH) | 30 #if defined(USE_ASH) |
41 #include "ash/ash_constants.h" | 31 #include "ash/ash_constants.h" |
42 #include "ash/wm/custom_frame_view_ash.h" | 32 #include "ash/wm/custom_frame_view_ash.h" |
43 #include "chrome/browser/ui/ash/ash_util.h" | 33 #include "chrome/browser/ui/ash/ash_util.h" |
44 #include "ui/aura/env.h" | 34 #include "ui/aura/env.h" |
45 #include "ui/aura/window.h" | 35 #include "ui/aura/window.h" |
46 #endif | 36 #endif |
47 | 37 |
48 namespace { | 38 namespace { |
| 39 |
49 const int kResizeInsideBoundsSize = 5; | 40 const int kResizeInsideBoundsSize = 5; |
50 const int kResizeAreaCornerSize = 16; | 41 const int kResizeAreaCornerSize = 16; |
51 | |
52 // Height of the chrome-style caption, in pixels. | 42 // Height of the chrome-style caption, in pixels. |
53 const int kCaptionHeight = 25; | 43 const int kCaptionHeight = 25; |
54 } // namespace | |
55 | 44 |
56 class ShellWindowFrameView : public views::NonClientFrameView, | 45 class ShellWindowFrameView : public views::NonClientFrameView, |
57 public views::ButtonListener { | 46 public views::ButtonListener { |
58 public: | 47 public: |
59 static const char kViewClassName[]; | 48 static const char kViewClassName[]; |
60 | 49 |
61 explicit ShellWindowFrameView(ShellWindowViews* window); | 50 explicit ShellWindowFrameView(AppWindowViews* window); |
62 virtual ~ShellWindowFrameView(); | 51 virtual ~ShellWindowFrameView(); |
63 | 52 |
64 void Init(views::Widget* frame); | 53 void Init(views::Widget* frame); |
65 | 54 |
66 // views::NonClientFrameView implementation. | 55 // views::NonClientFrameView implementation. |
67 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; | 56 virtual gfx::Rect GetBoundsForClientView() const OVERRIDE; |
68 virtual gfx::Rect GetWindowBoundsForClientBounds( | 57 virtual gfx::Rect GetWindowBoundsForClientBounds( |
69 const gfx::Rect& client_bounds) const OVERRIDE; | 58 const gfx::Rect& client_bounds) const OVERRIDE; |
70 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; | 59 virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE; |
71 virtual void GetWindowMask(const gfx::Size& size, | 60 virtual void GetWindowMask(const gfx::Size& size, |
72 gfx::Path* window_mask) OVERRIDE; | 61 gfx::Path* window_mask) OVERRIDE; |
73 virtual void ResetWindowControls() OVERRIDE {} | 62 virtual void ResetWindowControls() OVERRIDE {} |
74 virtual void UpdateWindowIcon() OVERRIDE {} | 63 virtual void UpdateWindowIcon() OVERRIDE {} |
75 virtual void UpdateWindowTitle() OVERRIDE {} | 64 virtual void UpdateWindowTitle() OVERRIDE {} |
76 | 65 |
77 // views::View implementation. | 66 // views::View implementation. |
78 virtual gfx::Size GetPreferredSize() OVERRIDE; | 67 virtual gfx::Size GetPreferredSize() OVERRIDE; |
79 virtual void Layout() OVERRIDE; | 68 virtual void Layout() OVERRIDE; |
80 virtual std::string GetClassName() const OVERRIDE; | 69 virtual std::string GetClassName() const OVERRIDE; |
81 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 70 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
82 virtual gfx::Size GetMinimumSize() OVERRIDE; | 71 virtual gfx::Size GetMinimumSize() OVERRIDE; |
83 virtual gfx::Size GetMaximumSize() OVERRIDE; | 72 virtual gfx::Size GetMaximumSize() OVERRIDE; |
84 | 73 |
85 private: | 74 private: |
86 // views::ButtonListener implementation. | 75 // views::ButtonListener implementation. |
87 virtual void ButtonPressed(views::Button* sender, const ui::Event& event) | 76 virtual void ButtonPressed(views::Button* sender, const ui::Event& event) |
88 OVERRIDE; | 77 OVERRIDE; |
89 | 78 |
90 ShellWindowViews* window_; | 79 AppWindowViews* window_; |
91 views::Widget* frame_; | 80 views::Widget* frame_; |
92 views::ImageButton* close_button_; | 81 views::ImageButton* close_button_; |
93 views::ImageButton* maximize_button_; | 82 views::ImageButton* maximize_button_; |
94 views::ImageButton* restore_button_; | 83 views::ImageButton* restore_button_; |
95 views::ImageButton* minimize_button_; | 84 views::ImageButton* minimize_button_; |
96 | 85 |
97 DISALLOW_COPY_AND_ASSIGN(ShellWindowFrameView); | 86 DISALLOW_COPY_AND_ASSIGN(ShellWindowFrameView); |
98 }; | 87 }; |
99 | 88 |
100 const char ShellWindowFrameView::kViewClassName[] = | 89 const char ShellWindowFrameView::kViewClassName[] = |
101 "browser/ui/views/extensions/ShellWindowFrameView"; | 90 "browser/ui/views/extensions/ShellWindowFrameView"; |
102 | 91 |
103 ShellWindowFrameView::ShellWindowFrameView(ShellWindowViews* window) | 92 ShellWindowFrameView::ShellWindowFrameView(AppWindowViews* window) |
104 : window_(window), | 93 : window_(window), |
105 frame_(NULL), | 94 frame_(NULL), |
106 close_button_(NULL) { | 95 close_button_(NULL) { |
107 } | 96 } |
108 | 97 |
109 ShellWindowFrameView::~ShellWindowFrameView() { | 98 ShellWindowFrameView::~ShellWindowFrameView() { |
110 } | 99 } |
111 | 100 |
112 void ShellWindowFrameView::Init(views::Widget* frame) { | 101 void ShellWindowFrameView::Init(views::Widget* frame) { |
113 frame_ = frame; | 102 frame_ = frame; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 if (sender == close_button_) | 377 if (sender == close_button_) |
389 frame_->Close(); | 378 frame_->Close(); |
390 else if (sender == maximize_button_) | 379 else if (sender == maximize_button_) |
391 frame_->Maximize(); | 380 frame_->Maximize(); |
392 else if (sender == restore_button_) | 381 else if (sender == restore_button_) |
393 frame_->Restore(); | 382 frame_->Restore(); |
394 else if (sender == minimize_button_) | 383 else if (sender == minimize_button_) |
395 frame_->Minimize(); | 384 frame_->Minimize(); |
396 } | 385 } |
397 | 386 |
398 ShellWindowViews::ShellWindowViews(ShellWindow* shell_window, | 387 } // namespace |
399 const ShellWindow::CreateParams& win_params) | 388 |
400 : shell_window_(shell_window), | 389 //------------------------------------------------------------------------------ |
401 web_view_(NULL), | 390 // AppWindowViews |
402 is_fullscreen_(false), | 391 |
403 frameless_(win_params.frame == ShellWindow::CreateParams::FRAME_NONE) { | 392 AppWindowViews::AppWindowViews(ShellWindow* shell_window, |
404 window_ = new views::Widget; | 393 const ShellWindow::CreateParams& win_params) |
| 394 : AppBaseWindowViews(shell_window, win_params) { |
| 395 } |
| 396 |
| 397 AppWindowViews::~AppWindowViews() { |
| 398 } |
| 399 |
| 400 void AppWindowViews::InitializeWindow(const gfx::Rect& initial_bounds) { |
405 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 401 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
406 params.delegate = this; | 402 params.delegate = this; |
407 params.remove_standard_frame = true; | 403 params.remove_standard_frame = true; |
408 params.use_system_default_icon = true; | 404 params.use_system_default_icon = true; |
409 minimum_size_ = win_params.minimum_size; | 405 window()->Init(params); |
410 maximum_size_ = win_params.maximum_size; | 406 |
411 window_->Init(params); | |
412 gfx::Rect window_bounds = | 407 gfx::Rect window_bounds = |
413 window_->non_client_view()->GetWindowBoundsForClientBounds( | 408 window()->non_client_view()->GetWindowBoundsForClientBounds( |
414 win_params.bounds); | 409 initial_bounds); |
415 // Center window if no position was specified. | 410 // Center window if no position was specified. |
416 if (win_params.bounds.x() == INT_MIN || win_params.bounds.y() == INT_MIN) { | 411 if (initial_bounds.x() == INT_MIN || initial_bounds.y() == INT_MIN) { |
417 window_->CenterWindow(window_bounds.size()); | 412 window()->CenterWindow(window_bounds.size()); |
418 } else { | 413 } else { |
419 window_->SetBounds(window_bounds); | 414 window()->SetBounds(window_bounds); |
420 } | 415 } |
| 416 |
421 #if defined(OS_WIN) && !defined(USE_AURA) | 417 #if defined(OS_WIN) && !defined(USE_AURA) |
422 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( | 418 std::string app_name = web_app::GenerateApplicationNameFromExtensionId( |
423 extension()->id()); | 419 extension()->id()); |
424 ui::win::SetAppIdForWindow( | 420 ui::win::SetAppIdForWindow( |
425 ShellIntegration::GetAppModelIdForProfile( | 421 ShellIntegration::GetAppModelIdForProfile( |
426 UTF8ToWide(app_name), shell_window_->profile()->GetPath()), | 422 UTF8ToWide(app_name), profile()->GetPath()), |
427 GetWidget()->GetTopLevelWidget()->GetNativeWindow()); | 423 GetWidget()->GetTopLevelWidget()->GetNativeWindow()); |
428 #endif | 424 #endif |
429 | |
430 extension_keybinding_registry_.reset( | |
431 new ExtensionKeybindingRegistryViews(shell_window_->profile(), | |
432 window_->GetFocusManager(), | |
433 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | |
434 shell_window_)); | |
435 | |
436 OnViewWasResized(); | |
437 } | |
438 | |
439 views::View* ShellWindowViews::GetInitiallyFocusedView() { | |
440 return web_view_; | |
441 } | |
442 | |
443 bool ShellWindowViews::ShouldDescendIntoChildForEventHandling( | |
444 gfx::NativeView child, | |
445 const gfx::Point& location) { | |
446 #if defined(USE_AURA) | |
447 DCHECK_EQ(child, web_view_->web_contents()->GetView()->GetNativeView()); | |
448 // Shell window should claim mouse events that fall within the draggable | |
449 // region. | |
450 return !draggable_region_.get() || | |
451 !draggable_region_->contains(location.x(), location.y()); | |
452 #else | |
453 return true; | |
454 #endif | |
455 } | 425 } |
456 | 426 |
457 void ShellWindowViews::OnFocus() { | 427 views::NonClientFrameView* AppWindowViews::CreateNonClientFrameView( |
458 web_view_->RequestFocus(); | |
459 } | |
460 | |
461 void ShellWindowViews::ViewHierarchyChanged( | |
462 bool is_add, views::View *parent, views::View *child) { | |
463 if (is_add && child == this) { | |
464 web_view_ = new views::WebView(NULL); | |
465 AddChildView(web_view_); | |
466 web_view_->SetWebContents(web_contents()); | |
467 } | |
468 } | |
469 | |
470 gfx::Size ShellWindowViews::GetMinimumSize() { | |
471 return minimum_size_; | |
472 } | |
473 | |
474 gfx::Size ShellWindowViews::GetMaximumSize() { | |
475 return maximum_size_; | |
476 } | |
477 | |
478 void ShellWindowViews::SetFullscreen(bool fullscreen) { | |
479 is_fullscreen_ = fullscreen; | |
480 window_->SetFullscreen(fullscreen); | |
481 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | |
482 // ever drop the window out of fullscreen in response to something that | |
483 // wasn't the app calling webkitCancelFullScreen(). | |
484 } | |
485 | |
486 bool ShellWindowViews::IsFullscreenOrPending() const { | |
487 return is_fullscreen_; | |
488 } | |
489 | |
490 ShellWindowViews::~ShellWindowViews() { | |
491 web_view_->SetWebContents(NULL); | |
492 } | |
493 | |
494 bool ShellWindowViews::IsActive() const { | |
495 return window_->IsActive(); | |
496 } | |
497 | |
498 bool ShellWindowViews::IsMaximized() const { | |
499 return window_->IsMaximized(); | |
500 } | |
501 | |
502 bool ShellWindowViews::IsMinimized() const { | |
503 return window_->IsMinimized(); | |
504 } | |
505 | |
506 bool ShellWindowViews::IsFullscreen() const { | |
507 return window_->IsFullscreen(); | |
508 } | |
509 | |
510 gfx::NativeWindow ShellWindowViews::GetNativeWindow() { | |
511 return window_->GetNativeWindow(); | |
512 } | |
513 | |
514 gfx::Rect ShellWindowViews::GetRestoredBounds() const { | |
515 return window_->GetRestoredBounds(); | |
516 } | |
517 | |
518 gfx::Rect ShellWindowViews::GetBounds() const { | |
519 return window_->GetWindowBoundsInScreen(); | |
520 } | |
521 | |
522 void ShellWindowViews::Show() { | |
523 if (window_->IsVisible()) { | |
524 window_->Activate(); | |
525 return; | |
526 } | |
527 | |
528 window_->Show(); | |
529 } | |
530 | |
531 void ShellWindowViews::ShowInactive() { | |
532 if (window_->IsVisible()) | |
533 return; | |
534 window_->ShowInactive(); | |
535 } | |
536 | |
537 void ShellWindowViews::Hide() { | |
538 window_->Hide(); | |
539 } | |
540 | |
541 void ShellWindowViews::Close() { | |
542 window_->Close(); | |
543 } | |
544 | |
545 void ShellWindowViews::Activate() { | |
546 window_->Activate(); | |
547 } | |
548 | |
549 void ShellWindowViews::Deactivate() { | |
550 window_->Deactivate(); | |
551 } | |
552 | |
553 void ShellWindowViews::Maximize() { | |
554 window_->Maximize(); | |
555 } | |
556 | |
557 void ShellWindowViews::Minimize() { | |
558 window_->Minimize(); | |
559 } | |
560 | |
561 void ShellWindowViews::Restore() { | |
562 window_->Restore(); | |
563 } | |
564 | |
565 void ShellWindowViews::SetBounds(const gfx::Rect& bounds) { | |
566 GetWidget()->SetBounds(bounds); | |
567 } | |
568 | |
569 void ShellWindowViews::FlashFrame(bool flash) { | |
570 window_->FlashFrame(flash); | |
571 } | |
572 | |
573 bool ShellWindowViews::IsAlwaysOnTop() const { | |
574 return false; | |
575 } | |
576 | |
577 void ShellWindowViews::DeleteDelegate() { | |
578 shell_window_->OnNativeClose(); | |
579 } | |
580 | |
581 bool ShellWindowViews::CanResize() const { | |
582 return maximum_size_.IsEmpty() || minimum_size_ != maximum_size_; | |
583 } | |
584 | |
585 bool ShellWindowViews::CanMaximize() const { | |
586 return maximum_size_.IsEmpty(); | |
587 } | |
588 | |
589 views::View* ShellWindowViews::GetContentsView() { | |
590 return this; | |
591 } | |
592 | |
593 views::NonClientFrameView* ShellWindowViews::CreateNonClientFrameView( | |
594 views::Widget* widget) { | 428 views::Widget* widget) { |
595 #if defined(USE_ASH) | 429 #if defined(USE_ASH) |
596 if (chrome::IsNativeViewInAsh(widget->GetNativeView()) && !frameless_) { | 430 if (chrome::IsNativeViewInAsh(widget->GetNativeView()) && !frameless()) { |
597 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); | 431 ash::CustomFrameViewAsh* frame = new ash::CustomFrameViewAsh(); |
598 frame->Init(widget); | 432 frame->Init(widget); |
599 return frame; | 433 return frame; |
600 } | 434 } |
601 #endif | 435 #endif |
602 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this); | 436 ShellWindowFrameView* frame_view = new ShellWindowFrameView(this); |
603 frame_view->Init(window_); | 437 frame_view->Init(window()); |
604 return frame_view; | 438 return frame_view; |
605 } | 439 } |
606 | 440 |
607 string16 ShellWindowViews::GetWindowTitle() const { | 441 void AppWindowViews::OnViewWasResized() { |
608 return shell_window_->GetTitle(); | |
609 } | |
610 | |
611 views::Widget* ShellWindowViews::GetWidget() { | |
612 return window_; | |
613 } | |
614 | |
615 const views::Widget* ShellWindowViews::GetWidget() const { | |
616 return window_; | |
617 } | |
618 | |
619 void ShellWindowViews::OnViewWasResized() { | |
620 // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the | 442 // TODO(jeremya): this doesn't seem like a terribly elegant way to keep the |
621 // window shape in sync. | 443 // window shape in sync. |
622 #if defined(OS_WIN) && !defined(USE_AURA) | 444 #if defined(OS_WIN) && !defined(USE_AURA) |
623 // Set the window shape of the RWHV. | 445 // Set the window shape of the RWHV. |
624 DCHECK(window_); | 446 DCHECK(window()); |
625 DCHECK(web_view_); | 447 DCHECK(web_view()); |
626 gfx::Size sz = web_view_->size(); | 448 gfx::Size sz = web_view()->size(); |
627 int height = sz.height(), width = sz.width(); | 449 int height = sz.height(), width = sz.width(); |
628 int radius = 1; | 450 int radius = 1; |
629 gfx::Path path; | 451 gfx::Path path; |
630 if (window_->IsMaximized() || window_->IsFullscreen()) { | 452 if (window()->IsMaximized() || window()->IsFullscreen()) { |
631 // Don't round the corners when the window is maximized or fullscreen. | 453 // Don't round the corners when the window is maximized or fullscreen. |
632 path.addRect(0, 0, width, height); | 454 path.addRect(0, 0, width, height); |
633 } else { | 455 } else { |
634 if (frameless_) { | 456 if (frameless()) { |
635 path.moveTo(0, radius); | 457 path.moveTo(0, radius); |
636 path.lineTo(radius, 0); | 458 path.lineTo(radius, 0); |
637 path.lineTo(width - radius, 0); | 459 path.lineTo(width - radius, 0); |
638 path.lineTo(width, radius); | 460 path.lineTo(width, radius); |
639 } else { | 461 } else { |
640 // Don't round the top corners in chrome-style frame mode. | 462 // Don't round the top corners in chrome-style frame mode. |
641 path.moveTo(0, 0); | 463 path.moveTo(0, 0); |
642 path.lineTo(width, 0); | 464 path.lineTo(width, 0); |
643 } | 465 } |
644 path.lineTo(width, height - radius - 1); | 466 path.lineTo(width, height - radius - 1); |
645 path.lineTo(width - radius - 1, height); | 467 path.lineTo(width - radius - 1, height); |
646 path.lineTo(radius + 1, height); | 468 path.lineTo(radius + 1, height); |
647 path.lineTo(0, height - radius - 1); | 469 path.lineTo(0, height - radius - 1); |
648 path.close(); | 470 path.close(); |
649 } | 471 } |
650 SetWindowRgn(web_contents()->GetNativeView(), path.CreateNativeRegion(), 1); | 472 SetWindowRgn(web_contents()->GetNativeView(), path.CreateNativeRegion(), 1); |
651 | 473 |
652 SkRegion* rgn = new SkRegion; | 474 SkRegion* rgn = new SkRegion; |
653 if (!window_->IsFullscreen()) { | 475 if (!window()->IsFullscreen()) { |
654 if (draggable_region()) | 476 if (draggable_region()) |
655 rgn->op(*draggable_region(), SkRegion::kUnion_Op); | 477 rgn->op(*draggable_region(), SkRegion::kUnion_Op); |
656 if (!window_->IsMaximized()) { | 478 if (!window()->IsMaximized()) { |
657 if (frameless_) | 479 if (frameless()) |
658 rgn->op(0, 0, width, kResizeInsideBoundsSize, SkRegion::kUnion_Op); | 480 rgn->op(0, 0, width, kResizeInsideBoundsSize, SkRegion::kUnion_Op); |
659 rgn->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); | 481 rgn->op(0, 0, kResizeInsideBoundsSize, height, SkRegion::kUnion_Op); |
660 rgn->op(width - kResizeInsideBoundsSize, 0, width, height, | 482 rgn->op(width - kResizeInsideBoundsSize, 0, width, height, |
661 SkRegion::kUnion_Op); | 483 SkRegion::kUnion_Op); |
662 rgn->op(0, height - kResizeInsideBoundsSize, width, height, | 484 rgn->op(0, height - kResizeInsideBoundsSize, width, height, |
663 SkRegion::kUnion_Op); | 485 SkRegion::kUnion_Op); |
664 } | 486 } |
665 } | 487 } |
666 if (web_contents()->GetRenderViewHost()->GetView()) | 488 if (web_contents()->GetRenderViewHost()->GetView()) |
667 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); | 489 web_contents()->GetRenderViewHost()->GetView()->SetClickthroughRegion(rgn); |
668 #endif | 490 #endif |
669 } | 491 } |
670 | |
671 gfx::ImageSkia ShellWindowViews::GetWindowAppIcon() { | |
672 gfx::Image app_icon = shell_window_->app_icon(); | |
673 if (app_icon.IsEmpty()) | |
674 return GetWindowIcon(); | |
675 else | |
676 return *app_icon.ToImageSkia(); | |
677 } | |
678 | |
679 gfx::ImageSkia ShellWindowViews::GetWindowIcon() { | |
680 content::WebContents* web_contents = shell_window_->web_contents(); | |
681 if (web_contents) { | |
682 FaviconTabHelper* favicon_tab_helper = | |
683 FaviconTabHelper::FromWebContents(web_contents); | |
684 gfx::Image app_icon = favicon_tab_helper->GetFavicon(); | |
685 if (!app_icon.IsEmpty()) | |
686 return *app_icon.ToImageSkia(); | |
687 } | |
688 return gfx::ImageSkia(); | |
689 } | |
690 | |
691 bool ShellWindowViews::ShouldShowWindowTitle() const { | |
692 return false; | |
693 } | |
694 | |
695 void ShellWindowViews::OnWidgetMove() { | |
696 shell_window_->SaveWindowPosition(); | |
697 } | |
698 | |
699 void ShellWindowViews::Layout() { | |
700 DCHECK(web_view_); | |
701 web_view_->SetBounds(0, 0, width(), height()); | |
702 OnViewWasResized(); | |
703 } | |
704 | |
705 void ShellWindowViews::UpdateWindowIcon() { | |
706 window_->UpdateWindowIcon(); | |
707 } | |
708 | |
709 void ShellWindowViews::UpdateWindowTitle() { | |
710 window_->UpdateWindowTitle(); | |
711 } | |
712 | |
713 void ShellWindowViews::UpdateDraggableRegions( | |
714 const std::vector<extensions::DraggableRegion>& regions) { | |
715 // Draggable region is not supported for non-frameless window. | |
716 if (!frameless_) | |
717 return; | |
718 | |
719 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); | |
720 OnViewWasResized(); | |
721 } | |
722 | |
723 void ShellWindowViews::HandleKeyboardEvent( | |
724 const content::NativeWebKeyboardEvent& event) { | |
725 unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, | |
726 GetFocusManager()); | |
727 } | |
728 | |
729 void ShellWindowViews::RenderViewHostChanged() { | |
730 OnViewWasResized(); | |
731 } | |
732 | |
733 void ShellWindowViews::SaveWindowPlacement(const gfx::Rect& bounds, | |
734 ui::WindowShowState show_state) { | |
735 views::WidgetDelegate::SaveWindowPlacement(bounds, show_state); | |
736 shell_window_->SaveWindowPosition(); | |
737 } | |
738 | |
739 // static | |
740 NativeShellWindow* NativeShellWindow::Create( | |
741 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | |
742 return new ShellWindowViews(shell_window, params); | |
743 } | |
OLD | NEW |