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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

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

Powered by Google App Engine
This is Rietveld 408576698