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

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: address comments 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
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
(...skipping 10 matching lines...) Expand all
631 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, 636 virtual void OnWindowRemovingFromRootWindow(aura::Window* window,
632 aura::Window* new_root) OVERRIDE { 637 aura::Window* new_root) OVERRIDE {
633 if (window == view_->window_) { 638 if (window == view_->window_) {
634 window->GetHost()->RemoveObserver(this); 639 window->GetHost()->RemoveObserver(this);
635 #if defined(OS_WIN) 640 #if defined(OS_WIN)
636 window->GetRootWindow()->RemoveObserver(this); 641 window->GetRootWindow()->RemoveObserver(this);
637 642
638 const aura::Window::Windows& root_children = 643 const aura::Window::Windows& root_children =
639 window->GetRootWindow()->children(); 644 window->GetRootWindow()->children();
640 for (size_t i = 0; i < root_children.size(); ++i) { 645 for (size_t i = 0; i < root_children.size(); ++i) {
641 if (root_children[i] != view_->window_ && root_children[i] != parent_) 646 if (root_children[i] != view_->window_ &&
647 root_children[i] != host_window_) {
642 root_children[i]->RemoveObserver(this); 648 root_children[i]->RemoveObserver(this);
649 }
643 } 650 }
644 #endif 651 #endif
645 } 652 }
646 } 653 }
647 654
648 // Overridden WindowTreeHostObserver: 655 // Overridden WindowTreeHostObserver:
649 virtual void OnHostMoved(const aura::WindowTreeHost* host, 656 virtual void OnHostMoved(const aura::WindowTreeHost* host,
650 const gfx::Point& new_origin) OVERRIDE { 657 const gfx::Point& new_origin) OVERRIDE {
651 TRACE_EVENT1("ui", 658 TRACE_EVENT1("ui",
652 "WebContentsViewAura::WindowObserver::OnHostMoved", 659 "WebContentsViewAura::WindowObserver::OnHostMoved",
(...skipping 10 matching lines...) Expand all
663 } 670 }
664 671
665 #if defined(OS_WIN) 672 #if defined(OS_WIN)
666 void UpdateConstrainedWindows(aura::Window* exclude) { 673 void UpdateConstrainedWindows(aura::Window* exclude) {
667 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( 674 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
668 view_->web_contents_->GetRenderWidgetHostView()); 675 view_->web_contents_->GetRenderWidgetHostView());
669 if (!view) 676 if (!view)
670 return; 677 return;
671 678
672 std::vector<gfx::Rect> constrained_windows; 679 std::vector<gfx::Rect> constrained_windows;
673 if (parent_) { 680 if (host_window_) {
674 const aura::Window::Windows& children = parent_->children(); 681 const aura::Window::Windows& children = host_window_->children();
675 for (size_t i = 0; i < children.size(); ++i) { 682 for (size_t i = 0; i < children.size(); ++i) {
676 if (children[i] != view_->window_ && 683 if (!children[i]->Contains(view_->window_.get()) &&
677 children[i] != exclude && 684 children[i] != exclude &&
678 children[i]->IsVisible()) { 685 children[i]->IsVisible()) {
679 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); 686 constrained_windows.push_back(children[i]->GetBoundsInRootWindow());
680 } 687 }
681 } 688 }
682 } 689 }
683 690
684 aura::Window* root_window = view_->window_->GetRootWindow(); 691 aura::Window* root_window = view_->window_->GetRootWindow();
685 const aura::Window::Windows& root_children = root_window->children(); 692 const aura::Window::Windows& root_children = root_window->children();
686 if (root_window) { 693 if (root_window) {
687 for (size_t i = 0; i < root_children.size(); ++i) { 694 for (size_t i = 0; i < root_children.size(); ++i) {
688 if (root_children[i]->IsVisible() && 695 if (root_children[i]->IsVisible() &&
689 !root_children[i]->Contains(view_->window_.get())) { 696 !root_children[i]->Contains(view_->window_.get())) {
690 constrained_windows.push_back( 697 constrained_windows.push_back(
691 root_children[i]->GetBoundsInRootWindow()); 698 root_children[i]->GetBoundsInRootWindow());
692 } 699 }
693 } 700 }
694 } 701 }
695 702
696 view->UpdateConstrainedWindowRects(constrained_windows); 703 view->UpdateConstrainedWindowRects(constrained_windows);
697 } 704 }
698 #endif 705 #endif
699 706
700 WebContentsViewAura* view_; 707 WebContentsViewAura* view_;
701 708
702 // We cache the old parent so that we can unregister when it's not the parent 709 // The parent window that hosts the constrained windows. We cache the old host
703 // anymore. 710 // view so that we can unregister when it's not the parent anymore.
704 aura::Window* parent_; 711 aura::Window* host_window_;
705 712
706 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 713 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
707 }; 714 };
708 715
709 //////////////////////////////////////////////////////////////////////////////// 716 ////////////////////////////////////////////////////////////////////////////////
710 // WebContentsViewAura, public: 717 // WebContentsViewAura, public:
711 718
712 WebContentsViewAura::WebContentsViewAura( 719 WebContentsViewAura::WebContentsViewAura(
713 WebContentsImpl* web_contents, 720 WebContentsImpl* web_contents,
714 WebContentsViewDelegate* delegate) 721 WebContentsViewDelegate* delegate)
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, 1578 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window,
1572 bool visible) { 1579 bool visible) {
1573 // Ignore any visibility changes in the hierarchy below. 1580 // Ignore any visibility changes in the hierarchy below.
1574 if (window != window_.get() && window_->Contains(window)) 1581 if (window != window_.get() && window_->Contains(window))
1575 return; 1582 return;
1576 1583
1577 UpdateWebContentsVisibility(web_contents_, visible); 1584 UpdateWebContentsVisibility(web_contents_, visible);
1578 } 1585 }
1579 1586
1580 } // namespace content 1587 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698