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