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 "content/browser/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 return web_input_event_modifiers; | 470 return web_input_event_modifiers; |
471 } | 471 } |
472 | 472 |
473 } // namespace | 473 } // namespace |
474 | 474 |
475 class WebContentsViewAura::WindowObserver | 475 class WebContentsViewAura::WindowObserver |
476 : public aura::WindowObserver, public aura::WindowTreeHostObserver { | 476 : public aura::WindowObserver, public aura::WindowTreeHostObserver { |
477 public: | 477 public: |
478 explicit WindowObserver(WebContentsViewAura* view) | 478 explicit WindowObserver(WebContentsViewAura* view) |
479 : view_(view), | 479 : view_(view), |
480 host_window_(NULL) { | 480 parent_(NULL) { |
481 view_->window_->AddObserver(this); | 481 view_->window_->AddObserver(this); |
482 | 482 |
483 #if defined(OS_WIN) | 483 #if defined(OS_WIN) |
484 if (view_->window_->GetRootWindow()) | 484 if (view_->window_->GetRootWindow()) |
485 view_->window_->GetRootWindow()->AddObserver(this); | 485 view_->window_->GetRootWindow()->AddObserver(this); |
486 #endif | 486 #endif |
487 } | 487 } |
488 | 488 |
489 virtual ~WindowObserver() { | 489 virtual ~WindowObserver() { |
490 view_->window_->RemoveObserver(this); | 490 view_->window_->RemoveObserver(this); |
491 if (view_->window_->GetHost()) | 491 if (view_->window_->GetHost()) |
492 view_->window_->GetHost()->RemoveObserver(this); | 492 view_->window_->GetHost()->RemoveObserver(this); |
493 if (host_window_) | 493 if (parent_) |
494 host_window_->RemoveObserver(this); | 494 parent_->RemoveObserver(this); |
| 495 |
495 #if defined(OS_WIN) | 496 #if defined(OS_WIN) |
496 if (host_window_) { | 497 if (parent_) { |
497 const aura::Window::Windows& children = host_window_->children(); | 498 const aura::Window::Windows& children = parent_->children(); |
498 for (size_t i = 0; i < children.size(); ++i) | 499 for (size_t i = 0; i < children.size(); ++i) |
499 children[i]->RemoveObserver(this); | 500 children[i]->RemoveObserver(this); |
500 } | 501 } |
501 | 502 |
502 aura::Window* root_window = view_->window_->GetRootWindow(); | 503 aura::Window* root_window = view_->window_->GetRootWindow(); |
503 if (root_window) { | 504 if (root_window) { |
504 root_window->RemoveObserver(this); | 505 root_window->RemoveObserver(this); |
505 const aura::Window::Windows& root_children = root_window->children(); | 506 const aura::Window::Windows& root_children = root_window->children(); |
506 for (size_t i = 0; i < root_children.size(); ++i) | 507 for (size_t i = 0; i < root_children.size(); ++i) |
507 root_children[i]->RemoveObserver(this); | 508 root_children[i]->RemoveObserver(this); |
508 } | 509 } |
509 #endif | 510 #endif |
510 } | 511 } |
511 | 512 |
512 // Overridden from aura::WindowObserver: | 513 // Overridden from aura::WindowObserver: |
513 #if defined(OS_WIN) | 514 #if defined(OS_WIN) |
514 // Constrained windows are added as children of the parent's parent's view | 515 // Constrained windows are added as children of the parent's parent's view |
515 // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV | 516 // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV |
516 // so that it can update the plugins' cutout rects accordingly. | 517 // so that it can update the plugins' cutout rects accordingly. |
517 // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is | 518 // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is |
518 // going to be deprecated in a year, this is ok for now. The test for this is | 519 // going to be deprecated in a year, this is ok for now. The test for this is |
519 // PrintPreviewTest.WindowedNPAPIPluginHidden. | 520 // PrintPreviewTest.WindowedNPAPIPluginHidden. |
520 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { | 521 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { |
521 if (!new_window->Contains(view_->window_.get())) { | 522 if (new_window != view_->window_) { |
522 // Skip the case when the parent moves to the root window. | 523 // Skip the case when the parent moves to the root window. |
523 if (new_window != host_window_) { | 524 if (new_window != parent_) { |
524 // Observe sibling windows of the WebContents, or children of the root | 525 // Observe sibling windows of the WebContents, or children of the root |
525 // window. | 526 // window. |
526 if (new_window->parent() == host_window_ || | 527 if (new_window->parent() == parent_ || |
527 new_window->parent() == view_->window_->GetRootWindow()) { | 528 new_window->parent() == view_->window_->GetRootWindow()) { |
528 new_window->AddObserver(this); | 529 new_window->AddObserver(this); |
529 } | 530 } |
530 } | 531 } |
531 } | 532 } |
532 | 533 |
533 if (new_window->parent() == host_window_) { | 534 if (new_window->parent() == parent_) { |
534 UpdateConstrainedWindows(NULL); | 535 UpdateConstrainedWindows(NULL); |
535 } | 536 } |
536 } | 537 } |
537 | 538 |
538 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { | 539 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { |
539 if (window == view_->window_) | 540 if (window == view_->window_) |
540 return; | 541 return; |
541 | 542 |
542 window->RemoveObserver(this); | 543 window->RemoveObserver(this); |
543 UpdateConstrainedWindows(window); | 544 UpdateConstrainedWindows(window); |
544 } | 545 } |
545 | 546 |
546 virtual void OnWindowVisibilityChanged(aura::Window* window, | 547 virtual void OnWindowVisibilityChanged(aura::Window* window, |
547 bool visible) OVERRIDE { | 548 bool visible) OVERRIDE { |
548 if (window == view_->window_ || | 549 if (window == view_->window_ || |
549 window->parent() == host_window_ || | 550 window->parent() == parent_ || |
550 window->parent() == view_->window_->GetRootWindow()) { | 551 window->parent() == view_->window_->GetRootWindow()) { |
551 UpdateConstrainedWindows(NULL); | 552 UpdateConstrainedWindows(NULL); |
552 } | 553 } |
553 } | 554 } |
554 #endif | 555 #endif |
555 | 556 |
556 virtual void OnWindowParentChanged(aura::Window* window, | 557 virtual void OnWindowParentChanged(aura::Window* window, |
557 aura::Window* parent) OVERRIDE { | 558 aura::Window* parent) OVERRIDE { |
558 if (window != view_->window_) | 559 if (window != view_->window_) |
559 return; | 560 return; |
560 | 561 if (parent_) |
561 aura::Window* host_window = | 562 parent_->RemoveObserver(this); |
562 window->GetProperty(aura::client::kHostWindowKey); | |
563 if (!host_window) | |
564 host_window = parent; | |
565 | |
566 if (host_window_) | |
567 host_window_->RemoveObserver(this); | |
568 | 563 |
569 #if defined(OS_WIN) | 564 #if defined(OS_WIN) |
570 if (host_window_) { | 565 if (parent_) { |
571 const aura::Window::Windows& children = host_window_->children(); | 566 const aura::Window::Windows& children = parent_->children(); |
572 for (size_t i = 0; i < children.size(); ++i) | 567 for (size_t i = 0; i < children.size(); ++i) |
573 children[i]->RemoveObserver(this); | 568 children[i]->RemoveObserver(this); |
574 | 569 |
575 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | 570 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( |
576 view_->web_contents_->GetRenderWidgetHostView()); | 571 view_->web_contents_->GetRenderWidgetHostView()); |
577 if (view) | 572 if (view) |
578 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); | 573 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); |
579 } | 574 } |
580 | 575 |
581 // When we get parented to the root window, the code below will watch the | 576 // When we get parented to the root window, the code below will watch the |
582 // host window, aka root window. Since we already watch the root window on | 577 // parent, aka root window. Since we already watch the root window on |
583 // Windows, unregister first so that the debug check doesn't fire. | 578 // Windows, unregister first so that the debug check doesn't fire. |
584 if (host_window && host_window == window->GetRootWindow()) | 579 if (parent && parent == window->GetRootWindow()) |
585 host_window->RemoveObserver(this); | 580 parent->RemoveObserver(this); |
586 | 581 |
587 // We need to undo the above if we were parented to the root window and then | 582 // We need to undo the above if we were parented to the root window and then |
588 // got parented to another window. At that point, the code before the ifdef | 583 // got parented to another window. At that point, the code before the ifdef |
589 // would have stopped watching the root window. | 584 // would have stopped watching the root window. |
590 if (window->GetRootWindow() && | 585 if (window->GetRootWindow() && |
591 host_window != window->GetRootWindow() && | 586 parent != window->GetRootWindow() && |
592 !window->GetRootWindow()->HasObserver(this)) { | 587 !window->GetRootWindow()->HasObserver(this)) { |
593 window->GetRootWindow()->AddObserver(this); | 588 window->GetRootWindow()->AddObserver(this); |
594 } | 589 } |
595 #endif | 590 #endif |
596 | 591 |
597 host_window_ = host_window; | 592 parent_ = parent; |
598 if (host_window) { | 593 if (parent) { |
599 host_window->AddObserver(this); | 594 parent->AddObserver(this); |
600 #if defined(OS_WIN) | 595 #if defined(OS_WIN) |
601 if (host_window != window->GetRootWindow()) { | 596 if (parent != window->GetRootWindow()) { |
602 const aura::Window::Windows& children = host_window->children(); | 597 const aura::Window::Windows& children = parent->children(); |
603 for (size_t i = 0; i < children.size(); ++i) { | 598 for (size_t i = 0; i < children.size(); ++i) { |
604 if (!children[i]->Contains(view_->window_.get())) | 599 if (children[i] != view_->window_) |
605 children[i]->AddObserver(this); | 600 children[i]->AddObserver(this); |
606 } | 601 } |
607 } | 602 } |
608 #endif | 603 #endif |
609 } | 604 } |
610 } | 605 } |
611 | 606 |
612 virtual void OnWindowBoundsChanged(aura::Window* window, | 607 virtual void OnWindowBoundsChanged(aura::Window* window, |
613 const gfx::Rect& old_bounds, | 608 const gfx::Rect& old_bounds, |
614 const gfx::Rect& new_bounds) OVERRIDE { | 609 const gfx::Rect& new_bounds) OVERRIDE { |
615 if (window == host_window_ || window == view_->window_) { | 610 if (window == parent_ || window == view_->window_) { |
616 SendScreenRects(); | 611 SendScreenRects(); |
617 if (view_->touch_editable_) | 612 if (view_->touch_editable_) |
618 view_->touch_editable_->UpdateEditingController(); | 613 view_->touch_editable_->UpdateEditingController(); |
619 #if defined(OS_WIN) | 614 #if defined(OS_WIN) |
620 } else { | 615 } else { |
621 UpdateConstrainedWindows(NULL); | 616 UpdateConstrainedWindows(NULL); |
622 #endif | 617 #endif |
623 } | 618 } |
624 } | 619 } |
625 | 620 |
(...skipping 10 matching lines...) Expand all Loading... |
636 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, | 631 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, |
637 aura::Window* new_root) OVERRIDE { | 632 aura::Window* new_root) OVERRIDE { |
638 if (window == view_->window_) { | 633 if (window == view_->window_) { |
639 window->GetHost()->RemoveObserver(this); | 634 window->GetHost()->RemoveObserver(this); |
640 #if defined(OS_WIN) | 635 #if defined(OS_WIN) |
641 window->GetRootWindow()->RemoveObserver(this); | 636 window->GetRootWindow()->RemoveObserver(this); |
642 | 637 |
643 const aura::Window::Windows& root_children = | 638 const aura::Window::Windows& root_children = |
644 window->GetRootWindow()->children(); | 639 window->GetRootWindow()->children(); |
645 for (size_t i = 0; i < root_children.size(); ++i) { | 640 for (size_t i = 0; i < root_children.size(); ++i) { |
646 if (root_children[i] != view_->window_ && | 641 if (root_children[i] != view_->window_ && root_children[i] != parent_) |
647 root_children[i] != host_window_) { | |
648 root_children[i]->RemoveObserver(this); | 642 root_children[i]->RemoveObserver(this); |
649 } | |
650 } | 643 } |
651 #endif | 644 #endif |
652 } | 645 } |
653 } | 646 } |
654 | 647 |
655 // Overridden WindowTreeHostObserver: | 648 // Overridden WindowTreeHostObserver: |
656 virtual void OnHostMoved(const aura::WindowTreeHost* host, | 649 virtual void OnHostMoved(const aura::WindowTreeHost* host, |
657 const gfx::Point& new_origin) OVERRIDE { | 650 const gfx::Point& new_origin) OVERRIDE { |
658 TRACE_EVENT1("ui", | 651 TRACE_EVENT1("ui", |
659 "WebContentsViewAura::WindowObserver::OnHostMoved", | 652 "WebContentsViewAura::WindowObserver::OnHostMoved", |
(...skipping 10 matching lines...) Expand all Loading... |
670 } | 663 } |
671 | 664 |
672 #if defined(OS_WIN) | 665 #if defined(OS_WIN) |
673 void UpdateConstrainedWindows(aura::Window* exclude) { | 666 void UpdateConstrainedWindows(aura::Window* exclude) { |
674 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | 667 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( |
675 view_->web_contents_->GetRenderWidgetHostView()); | 668 view_->web_contents_->GetRenderWidgetHostView()); |
676 if (!view) | 669 if (!view) |
677 return; | 670 return; |
678 | 671 |
679 std::vector<gfx::Rect> constrained_windows; | 672 std::vector<gfx::Rect> constrained_windows; |
680 if (host_window_) { | 673 if (parent_) { |
681 const aura::Window::Windows& children = host_window_->children(); | 674 const aura::Window::Windows& children = parent_->children(); |
682 for (size_t i = 0; i < children.size(); ++i) { | 675 for (size_t i = 0; i < children.size(); ++i) { |
683 if (!children[i]->Contains(view_->window_.get()) && | 676 if (children[i] != view_->window_ && |
684 children[i] != exclude && | 677 children[i] != exclude && |
685 children[i]->IsVisible()) { | 678 children[i]->IsVisible()) { |
686 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); | 679 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); |
687 } | 680 } |
688 } | 681 } |
689 } | 682 } |
690 | 683 |
691 aura::Window* root_window = view_->window_->GetRootWindow(); | 684 aura::Window* root_window = view_->window_->GetRootWindow(); |
692 const aura::Window::Windows& root_children = root_window->children(); | 685 const aura::Window::Windows& root_children = root_window->children(); |
693 if (root_window) { | 686 if (root_window) { |
694 for (size_t i = 0; i < root_children.size(); ++i) { | 687 for (size_t i = 0; i < root_children.size(); ++i) { |
695 if (root_children[i]->IsVisible() && | 688 if (root_children[i]->IsVisible() && |
696 !root_children[i]->Contains(view_->window_.get())) { | 689 !root_children[i]->Contains(view_->window_.get())) { |
697 constrained_windows.push_back( | 690 constrained_windows.push_back( |
698 root_children[i]->GetBoundsInRootWindow()); | 691 root_children[i]->GetBoundsInRootWindow()); |
699 } | 692 } |
700 } | 693 } |
701 } | 694 } |
702 | 695 |
703 view->UpdateConstrainedWindowRects(constrained_windows); | 696 view->UpdateConstrainedWindowRects(constrained_windows); |
704 } | 697 } |
705 #endif | 698 #endif |
706 | 699 |
707 WebContentsViewAura* view_; | 700 WebContentsViewAura* view_; |
708 | 701 |
709 // The parent window that hosts the constrained windows. We cache the old host | 702 // We cache the old parent so that we can unregister when it's not the parent |
710 // view so that we can unregister when it's not the parent anymore. | 703 // anymore. |
711 aura::Window* host_window_; | 704 aura::Window* parent_; |
712 | 705 |
713 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | 706 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
714 }; | 707 }; |
715 | 708 |
716 //////////////////////////////////////////////////////////////////////////////// | 709 //////////////////////////////////////////////////////////////////////////////// |
717 // WebContentsViewAura, public: | 710 // WebContentsViewAura, public: |
718 | 711 |
719 WebContentsViewAura::WebContentsViewAura( | 712 WebContentsViewAura::WebContentsViewAura( |
720 WebContentsImpl* web_contents, | 713 WebContentsImpl* web_contents, |
721 WebContentsViewDelegate* delegate) | 714 WebContentsViewDelegate* delegate) |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, | 1569 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, |
1577 bool visible) { | 1570 bool visible) { |
1578 // Ignore any visibility changes in the hierarchy below. | 1571 // Ignore any visibility changes in the hierarchy below. |
1579 if (window != window_.get() && window_->Contains(window)) | 1572 if (window != window_.get() && window_->Contains(window)) |
1580 return; | 1573 return; |
1581 | 1574 |
1582 UpdateWebContentsVisibility(web_contents_, visible); | 1575 UpdateWebContentsVisibility(web_contents_, visible); |
1583 } | 1576 } |
1584 | 1577 |
1585 } // namespace content | 1578 } // namespace content |
OLD | NEW |