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

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: remove stray whitespace 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') | ui/aura/client/aura_constants.h » ('J')
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);
sky 2014/06/19 15:15:01 It's not far to assume the only place using this c
calamity 2014/06/20 07:10:39 Done.
563
564 if (host_window_)
565 host_window_->RemoveObserver(this);
563 566
564 #if defined(OS_WIN) 567 #if defined(OS_WIN)
565 if (parent_) { 568 if (host_window_) {
566 const aura::Window::Windows& children = parent_->children(); 569 const aura::Window::Windows& children = host_window_->children();
567 for (size_t i = 0; i < children.size(); ++i) 570 for (size_t i = 0; i < children.size(); ++i)
568 children[i]->RemoveObserver(this); 571 children[i]->RemoveObserver(this);
569 572
570 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( 573 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
571 view_->web_contents_->GetRenderWidgetHostView()); 574 view_->web_contents_->GetRenderWidgetHostView());
572 if (view) 575 if (view)
573 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); 576 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>());
574 } 577 }
575 578
576 // When we get parented to the root window, the code below will watch the 579 // 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 580 // 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. 581 // Windows, unregister first so that the debug check doesn't fire.
579 if (parent && parent == window->GetRootWindow()) 582 if (host_window && host_window == window->GetRootWindow())
580 parent->RemoveObserver(this); 583 host_window->RemoveObserver(this);
581 584
582 // We need to undo the above if we were parented to the root window and then 585 // 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 586 // got parented to another window. At that point, the code before the ifdef
584 // would have stopped watching the root window. 587 // would have stopped watching the root window.
585 if (window->GetRootWindow() && 588 if (window->GetRootWindow() &&
586 parent != window->GetRootWindow() && 589 host_window != window->GetRootWindow() &&
587 !window->GetRootWindow()->HasObserver(this)) { 590 !window->GetRootWindow()->HasObserver(this)) {
588 window->GetRootWindow()->AddObserver(this); 591 window->GetRootWindow()->AddObserver(this);
589 } 592 }
590 #endif 593 #endif
591 594
592 parent_ = parent; 595 host_window_ = host_window;
593 if (parent) { 596 if (host_window) {
594 parent->AddObserver(this); 597 host_window->AddObserver(this);
595 #if defined(OS_WIN) 598 #if defined(OS_WIN)
596 if (parent != window->GetRootWindow()) { 599 if (host_window != window->GetRootWindow()) {
597 const aura::Window::Windows& children = parent->children(); 600 const aura::Window::Windows& children = host_window->children();
598 for (size_t i = 0; i < children.size(); ++i) { 601 for (size_t i = 0; i < children.size(); ++i) {
599 if (children[i] != view_->window_) 602 if (!children[i]->Contains(view_->window_.get()))
600 children[i]->AddObserver(this); 603 children[i]->AddObserver(this);
601 } 604 }
602 } 605 }
603 #endif 606 #endif
604 } 607 }
605 } 608 }
606 609
607 virtual void OnWindowBoundsChanged(aura::Window* window, 610 virtual void OnWindowBoundsChanged(aura::Window* window,
608 const gfx::Rect& old_bounds, 611 const gfx::Rect& old_bounds,
609 const gfx::Rect& new_bounds) OVERRIDE { 612 const gfx::Rect& new_bounds) OVERRIDE {
610 if (window == parent_ || window == view_->window_) { 613 if (window == host_window_ || window == view_->window_) {
611 SendScreenRects(); 614 SendScreenRects();
612 if (view_->touch_editable_) 615 if (view_->touch_editable_)
613 view_->touch_editable_->UpdateEditingController(); 616 view_->touch_editable_->UpdateEditingController();
614 #if defined(OS_WIN) 617 #if defined(OS_WIN)
615 } else { 618 } else {
616 UpdateConstrainedWindows(NULL); 619 UpdateConstrainedWindows(NULL);
617 #endif 620 #endif
618 } 621 }
619 } 622 }
620 623
(...skipping 10 matching lines...) Expand all
631 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, 634 virtual void OnWindowRemovingFromRootWindow(aura::Window* window,
632 aura::Window* new_root) OVERRIDE { 635 aura::Window* new_root) OVERRIDE {
633 if (window == view_->window_) { 636 if (window == view_->window_) {
634 window->GetHost()->RemoveObserver(this); 637 window->GetHost()->RemoveObserver(this);
635 #if defined(OS_WIN) 638 #if defined(OS_WIN)
636 window->GetRootWindow()->RemoveObserver(this); 639 window->GetRootWindow()->RemoveObserver(this);
637 640
638 const aura::Window::Windows& root_children = 641 const aura::Window::Windows& root_children =
639 window->GetRootWindow()->children(); 642 window->GetRootWindow()->children();
640 for (size_t i = 0; i < root_children.size(); ++i) { 643 for (size_t i = 0; i < root_children.size(); ++i) {
641 if (root_children[i] != view_->window_ && root_children[i] != parent_) 644 if (root_children[i] != view_->window_ &&
645 root_children[i] != host_window_) {
642 root_children[i]->RemoveObserver(this); 646 root_children[i]->RemoveObserver(this);
647 }
643 } 648 }
644 #endif 649 #endif
645 } 650 }
646 } 651 }
647 652
648 // Overridden WindowTreeHostObserver: 653 // Overridden WindowTreeHostObserver:
649 virtual void OnHostMoved(const aura::WindowTreeHost* host, 654 virtual void OnHostMoved(const aura::WindowTreeHost* host,
650 const gfx::Point& new_origin) OVERRIDE { 655 const gfx::Point& new_origin) OVERRIDE {
651 TRACE_EVENT1("ui", 656 TRACE_EVENT1("ui",
652 "WebContentsViewAura::WindowObserver::OnHostMoved", 657 "WebContentsViewAura::WindowObserver::OnHostMoved",
(...skipping 10 matching lines...) Expand all
663 } 668 }
664 669
665 #if defined(OS_WIN) 670 #if defined(OS_WIN)
666 void UpdateConstrainedWindows(aura::Window* exclude) { 671 void UpdateConstrainedWindows(aura::Window* exclude) {
667 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( 672 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
668 view_->web_contents_->GetRenderWidgetHostView()); 673 view_->web_contents_->GetRenderWidgetHostView());
669 if (!view) 674 if (!view)
670 return; 675 return;
671 676
672 std::vector<gfx::Rect> constrained_windows; 677 std::vector<gfx::Rect> constrained_windows;
673 if (parent_) { 678 if (host_window_) {
674 const aura::Window::Windows& children = parent_->children(); 679 const aura::Window::Windows& children = host_window_->children();
675 for (size_t i = 0; i < children.size(); ++i) { 680 for (size_t i = 0; i < children.size(); ++i) {
676 if (children[i] != view_->window_ && 681 if (!children[i]->Contains(view_->window_.get()) &&
677 children[i] != exclude && 682 children[i] != exclude &&
678 children[i]->IsVisible()) { 683 children[i]->IsVisible()) {
679 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); 684 constrained_windows.push_back(children[i]->GetBoundsInRootWindow());
680 } 685 }
681 } 686 }
682 } 687 }
683 688
684 aura::Window* root_window = view_->window_->GetRootWindow(); 689 aura::Window* root_window = view_->window_->GetRootWindow();
685 const aura::Window::Windows& root_children = root_window->children(); 690 const aura::Window::Windows& root_children = root_window->children();
686 if (root_window) { 691 if (root_window) {
687 for (size_t i = 0; i < root_children.size(); ++i) { 692 for (size_t i = 0; i < root_children.size(); ++i) {
688 if (root_children[i]->IsVisible() && 693 if (root_children[i]->IsVisible() &&
689 !root_children[i]->Contains(view_->window_.get())) { 694 !root_children[i]->Contains(view_->window_.get())) {
690 constrained_windows.push_back( 695 constrained_windows.push_back(
691 root_children[i]->GetBoundsInRootWindow()); 696 root_children[i]->GetBoundsInRootWindow());
692 } 697 }
693 } 698 }
694 } 699 }
695 700
696 view->UpdateConstrainedWindowRects(constrained_windows); 701 view->UpdateConstrainedWindowRects(constrained_windows);
697 } 702 }
698 #endif 703 #endif
699 704
700 WebContentsViewAura* view_; 705 WebContentsViewAura* view_;
701 706
702 // We cache the old parent so that we can unregister when it's not the parent 707 // The parent window that hosts the constrained windows. We cache the old host
703 // anymore. 708 // view so that we can unregister when it's not the parent anymore.
704 aura::Window* parent_; 709 aura::Window* host_window_;
705 710
706 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 711 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
707 }; 712 };
708 713
709 //////////////////////////////////////////////////////////////////////////////// 714 ////////////////////////////////////////////////////////////////////////////////
710 // WebContentsViewAura, public: 715 // WebContentsViewAura, public:
711 716
712 WebContentsViewAura::WebContentsViewAura( 717 WebContentsViewAura::WebContentsViewAura(
713 WebContentsImpl* web_contents, 718 WebContentsImpl* web_contents,
714 WebContentsViewDelegate* delegate) 719 WebContentsViewDelegate* delegate)
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, 1576 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window,
1572 bool visible) { 1577 bool visible) {
1573 // Ignore any visibility changes in the hierarchy below. 1578 // Ignore any visibility changes in the hierarchy below.
1574 if (window != window_.get() && window_->Contains(window)) 1579 if (window != window_.get() && window_->Contains(window))
1575 return; 1580 return;
1576 1581
1577 UpdateWebContentsVisibility(web_contents_, visible); 1582 UpdateWebContentsVisibility(web_contents_, visible);
1578 } 1583 }
1579 1584
1580 } // namespace content 1585 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | ui/aura/client/aura_constants.h » ('j') | ui/aura/client/aura_constants.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698