| 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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 DISALLOW_COPY_AND_ASSIGN(ImageLayerDelegate); | 485 DISALLOW_COPY_AND_ASSIGN(ImageLayerDelegate); |
| 486 }; | 486 }; |
| 487 | 487 |
| 488 } // namespace | 488 } // namespace |
| 489 | 489 |
| 490 // When a history navigation is triggered at the end of an overscroll | 490 // When a history navigation is triggered at the end of an overscroll |
| 491 // navigation, it is necessary to show the history-screenshot until the page is | 491 // navigation, it is necessary to show the history-screenshot until the page is |
| 492 // done navigating and painting. This class accomplishes this by showing the | 492 // done navigating and painting. This class accomplishes this by showing the |
| 493 // screenshot window on top of the page until the page has completed loading and | 493 // screenshot window on top of the page until the page has completed loading and |
| 494 // painting. | 494 // painting. |
| 495 class OverscrollNavigationOverlay : | 495 class OverscrollNavigationOverlay : public WebContentsObserver, |
| 496 public RenderWidgetHostViewAura::PaintObserver, | 496 public WindowSlider::Delegate { |
| 497 public WindowSlider::Delegate { | |
| 498 public: | 497 public: |
| 499 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents) | 498 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents) |
| 500 : web_contents_(web_contents), | 499 : web_contents_(web_contents), |
| 501 image_delegate_(NULL), | 500 image_delegate_(NULL), |
| 502 view_(NULL), | |
| 503 loading_complete_(false), | 501 loading_complete_(false), |
| 504 received_paint_update_(false), | 502 received_paint_update_(false), |
| 505 compositor_updated_(false), | |
| 506 slide_direction_(SLIDE_UNKNOWN), | 503 slide_direction_(SLIDE_UNKNOWN), |
| 507 need_paint_update_(true) { | 504 need_paint_update_(true) { |
| 508 } | 505 } |
| 509 | 506 |
| 510 virtual ~OverscrollNavigationOverlay() { | 507 virtual ~OverscrollNavigationOverlay() { |
| 511 if (view_) | |
| 512 view_->set_paint_observer(NULL); | |
| 513 } | 508 } |
| 514 | 509 |
| 515 bool has_window() const { return !!window_.get(); } | 510 bool has_window() const { return !!window_.get(); } |
| 516 | 511 |
| 517 void StartObservingView(RenderWidgetHostViewAura* view) { | 512 void StartObserving() { |
| 518 if (view_) | |
| 519 view_->set_paint_observer(NULL); | |
| 520 | |
| 521 loading_complete_ = false; | 513 loading_complete_ = false; |
| 522 received_paint_update_ = false; | 514 received_paint_update_ = false; |
| 523 compositor_updated_ = false; | 515 Observe(web_contents_); |
| 524 view_ = view; | |
| 525 if (view_) | |
| 526 view_->set_paint_observer(this); | |
| 527 | 516 |
| 528 // Make sure the overlay window is on top. | 517 // Make sure the overlay window is on top. |
| 529 if (window_.get() && window_->parent()) | 518 if (window_.get() && window_->parent()) |
| 530 window_->parent()->StackChildAtTop(window_.get()); | 519 window_->parent()->StackChildAtTop(window_.get()); |
| 531 } | 520 } |
| 532 | 521 |
| 533 void SetOverlayWindow(scoped_ptr<aura::Window> window, | 522 void SetOverlayWindow(scoped_ptr<aura::Window> window, |
| 534 ImageWindowDelegate* delegate) { | 523 ImageWindowDelegate* delegate) { |
| 535 window_ = window.Pass(); | 524 window_ = window.Pass(); |
| 536 if (window_.get() && window_->parent()) | 525 if (window_.get() && window_->parent()) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 562 // as soon as there is any new painting notification. | 551 // as soon as there is any new painting notification. |
| 563 if ((need_paint_update_ && !received_paint_update_) || | 552 if ((need_paint_update_ && !received_paint_update_) || |
| 564 (image_delegate_->has_image() && !loading_complete_)) { | 553 (image_delegate_->has_image() && !loading_complete_)) { |
| 565 return; | 554 return; |
| 566 } | 555 } |
| 567 | 556 |
| 568 // If a slide is in progress, then do not destroy the window or the slide. | 557 // If a slide is in progress, then do not destroy the window or the slide. |
| 569 if (window_slider_.get() && window_slider_->IsSlideInProgress()) | 558 if (window_slider_.get() && window_slider_->IsSlideInProgress()) |
| 570 return; | 559 return; |
| 571 | 560 |
| 561 Observe(NULL); |
| 572 window_slider_.reset(); | 562 window_slider_.reset(); |
| 573 window_.reset(); | 563 window_.reset(); |
| 574 image_delegate_ = NULL; | 564 image_delegate_ = NULL; |
| 575 if (view_) { | |
| 576 view_->set_paint_observer(NULL); | |
| 577 view_ = NULL; | |
| 578 } | |
| 579 } | 565 } |
| 580 | 566 |
| 581 // Creates a layer to be used for window-slide. |offset| is the offset of the | 567 // Creates a layer to be used for window-slide. |offset| is the offset of the |
| 582 // NavigationEntry for the screenshot image to display. | 568 // NavigationEntry for the screenshot image to display. |
| 583 ui::Layer* CreateSlideLayer(int offset) { | 569 ui::Layer* CreateSlideLayer(int offset) { |
| 584 const NavigationControllerImpl& controller = web_contents_->GetController(); | 570 const NavigationControllerImpl& controller = web_contents_->GetController(); |
| 585 const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( | 571 const NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
| 586 controller.GetEntryAtOffset(offset)); | 572 controller.GetEntryAtOffset(offset)); |
| 587 | 573 |
| 588 gfx::Image image; | 574 gfx::Image image; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 // Change the image used for the overlay window. | 611 // Change the image used for the overlay window. |
| 626 image_delegate_->SetImage(layer_delegate_.image()); | 612 image_delegate_->SetImage(layer_delegate_.image()); |
| 627 window_->layer()->SetTransform(gfx::Transform()); | 613 window_->layer()->SetTransform(gfx::Transform()); |
| 628 window_->SchedulePaintInRect(gfx::Rect(window_->bounds().size())); | 614 window_->SchedulePaintInRect(gfx::Rect(window_->bounds().size())); |
| 629 | 615 |
| 630 SlideDirection direction = slide_direction_; | 616 SlideDirection direction = slide_direction_; |
| 631 slide_direction_ = SLIDE_UNKNOWN; | 617 slide_direction_ = SLIDE_UNKNOWN; |
| 632 | 618 |
| 633 // Reset state and wait for the new navigation page to complete | 619 // Reset state and wait for the new navigation page to complete |
| 634 // loading/painting. | 620 // loading/painting. |
| 635 StartObservingView(ToRenderWidgetHostViewAura( | 621 StartObserving(); |
| 636 web_contents_->GetRenderWidgetHostView())); | |
| 637 | 622 |
| 638 // Perform the navigation. | 623 // Perform the navigation. |
| 639 if (direction == SLIDE_BACK) | 624 if (direction == SLIDE_BACK) |
| 640 web_contents_->GetController().GoBack(); | 625 web_contents_->GetController().GoBack(); |
| 641 else if (direction == SLIDE_FRONT) | 626 else if (direction == SLIDE_FRONT) |
| 642 web_contents_->GetController().GoForward(); | 627 web_contents_->GetController().GoForward(); |
| 643 else | 628 else |
| 644 NOTREACHED(); | 629 NOTREACHED(); |
| 645 } | 630 } |
| 646 | 631 |
| 647 virtual void OnWindowSlideAborted() OVERRIDE { | 632 virtual void OnWindowSlideAborted() OVERRIDE { |
| 648 StopObservingIfDone(); | 633 StopObservingIfDone(); |
| 649 } | 634 } |
| 650 | 635 |
| 651 virtual void OnWindowSliderDestroyed() OVERRIDE { | 636 virtual void OnWindowSliderDestroyed() OVERRIDE { |
| 652 // The slider has just been destroyed. Release the ownership. | 637 // The slider has just been destroyed. Release the ownership. |
| 653 WindowSlider* slider ALLOW_UNUSED = window_slider_.release(); | 638 WindowSlider* slider ALLOW_UNUSED = window_slider_.release(); |
| 654 StopObservingIfDone(); | 639 StopObservingIfDone(); |
| 655 } | 640 } |
| 656 | 641 |
| 657 // Overridden from RenderWidgetHostViewAura::PaintObserver: | 642 // Overridden from WebContentsObserver: |
| 658 virtual void OnPaintComplete() OVERRIDE { | 643 virtual void DidFirstVisuallyNonEmptyPaint(int32 page_id) OVERRIDE { |
| 659 received_paint_update_ = true; | 644 received_paint_update_ = true; |
| 660 StopObservingIfDone(); | 645 StopObservingIfDone(); |
| 661 } | 646 } |
| 662 | 647 |
| 663 virtual void OnCompositingComplete() OVERRIDE { | 648 virtual void DidStopLoading(RenderViewHost* host) OVERRIDE { |
| 664 received_paint_update_ = compositor_updated_; | |
| 665 StopObservingIfDone(); | |
| 666 } | |
| 667 | |
| 668 virtual void OnUpdateCompositorContent() OVERRIDE { | |
| 669 compositor_updated_ = true; | |
| 670 } | |
| 671 | |
| 672 virtual void OnPageLoadComplete() OVERRIDE { | |
| 673 loading_complete_ = true; | 649 loading_complete_ = true; |
| 674 StopObservingIfDone(); | 650 StopObservingIfDone(); |
| 675 } | 651 } |
| 676 | 652 |
| 677 virtual void OnViewDestroyed() OVERRIDE { | |
| 678 DCHECK(view_); | |
| 679 view_->set_paint_observer(NULL); | |
| 680 view_ = NULL; | |
| 681 } | |
| 682 | |
| 683 // The WebContents which is being navigated. | 653 // The WebContents which is being navigated. |
| 684 WebContentsImpl* web_contents_; | 654 WebContentsImpl* web_contents_; |
| 685 | 655 |
| 686 scoped_ptr<aura::Window> window_; | 656 scoped_ptr<aura::Window> window_; |
| 687 | 657 |
| 688 // This is the WindowDelegate of |window_|. The delegate manages its own | 658 // This is the WindowDelegate of |window_|. The delegate manages its own |
| 689 // lifetime (destroys itself when |window_| is destroyed). | 659 // lifetime (destroys itself when |window_| is destroyed). |
| 690 ImageWindowDelegate* image_delegate_; | 660 ImageWindowDelegate* image_delegate_; |
| 691 | 661 |
| 692 RenderWidgetHostViewAura* view_; | |
| 693 bool loading_complete_; | 662 bool loading_complete_; |
| 694 bool received_paint_update_; | 663 bool received_paint_update_; |
| 695 bool compositor_updated_; | |
| 696 | 664 |
| 697 enum SlideDirection { | 665 enum SlideDirection { |
| 698 SLIDE_UNKNOWN, | 666 SLIDE_UNKNOWN, |
| 699 SLIDE_BACK, | 667 SLIDE_BACK, |
| 700 SLIDE_FRONT | 668 SLIDE_FRONT |
| 701 }; | 669 }; |
| 702 | 670 |
| 703 // The |WindowSlider| that allows sliding history layers while the page is | 671 // The |WindowSlider| that allows sliding history layers while the page is |
| 704 // being reloaded. | 672 // being reloaded. |
| 705 scoped_ptr<WindowSlider> window_slider_; | 673 scoped_ptr<WindowSlider> window_slider_; |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 | 1122 |
| 1155 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() { | 1123 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() { |
| 1156 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>( | 1124 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>( |
| 1157 overscroll_window_->delegate()); | 1125 overscroll_window_->delegate()); |
| 1158 overscroll_window_->SchedulePaintInRect( | 1126 overscroll_window_->SchedulePaintInRect( |
| 1159 gfx::Rect(overscroll_window_->bounds().size())); | 1127 gfx::Rect(overscroll_window_->bounds().size())); |
| 1160 overscroll_window_->SetBounds(gfx::Rect(window_->bounds().size())); | 1128 overscroll_window_->SetBounds(gfx::Rect(window_->bounds().size())); |
| 1161 overscroll_window_->SetTransform(gfx::Transform()); | 1129 overscroll_window_->SetTransform(gfx::Transform()); |
| 1162 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass(), | 1130 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass(), |
| 1163 delegate); | 1131 delegate); |
| 1164 navigation_overlay_->StartObservingView(ToRenderWidgetHostViewAura( | 1132 navigation_overlay_->StartObserving(); |
| 1165 web_contents_->GetRenderWidgetHostView())); | |
| 1166 } | 1133 } |
| 1167 | 1134 |
| 1168 void WebContentsViewAura::UpdateOverscrollWindowBrightness(float delta_x) { | 1135 void WebContentsViewAura::UpdateOverscrollWindowBrightness(float delta_x) { |
| 1169 if (!overscroll_change_brightness_) | 1136 if (!overscroll_change_brightness_) |
| 1170 return; | 1137 return; |
| 1171 | 1138 |
| 1172 const float kBrightnessMin = -.1f; | 1139 const float kBrightnessMin = -.1f; |
| 1173 const float kBrightnessMax = -.01f; | 1140 const float kBrightnessMax = -.01f; |
| 1174 | 1141 |
| 1175 float ratio = fabs(delta_x) / GetViewBounds().width(); | 1142 float ratio = fabs(delta_x) / GetViewBounds().width(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 DCHECK(RenderViewHostFactory::has_factory()); | 1299 DCHECK(RenderViewHostFactory::has_factory()); |
| 1333 return render_widget_host->GetView(); | 1300 return render_widget_host->GetView(); |
| 1334 } | 1301 } |
| 1335 | 1302 |
| 1336 RenderWidgetHostView* view = | 1303 RenderWidgetHostView* view = |
| 1337 RenderWidgetHostView::CreateViewForWidget(render_widget_host); | 1304 RenderWidgetHostView::CreateViewForWidget(render_widget_host); |
| 1338 view->InitAsChild(NULL); | 1305 view->InitAsChild(NULL); |
| 1339 GetNativeView()->AddChild(view->GetNativeView()); | 1306 GetNativeView()->AddChild(view->GetNativeView()); |
| 1340 | 1307 |
| 1341 if (navigation_overlay_.get() && navigation_overlay_->has_window()) { | 1308 if (navigation_overlay_.get() && navigation_overlay_->has_window()) { |
| 1342 navigation_overlay_->StartObservingView(ToRenderWidgetHostViewAura(view)); | 1309 navigation_overlay_->StartObserving(); |
| 1343 } | 1310 } |
| 1344 | 1311 |
| 1345 RenderWidgetHostImpl* host_impl = | 1312 RenderWidgetHostImpl* host_impl = |
| 1346 RenderWidgetHostImpl::From(render_widget_host); | 1313 RenderWidgetHostImpl::From(render_widget_host); |
| 1347 | 1314 |
| 1348 if (!host_impl->is_hidden()) | 1315 if (!host_impl->is_hidden()) |
| 1349 view->Show(); | 1316 view->Show(); |
| 1350 | 1317 |
| 1351 // We listen to drag drop events in the newly created view's window. | 1318 // We listen to drag drop events in the newly created view's window. |
| 1352 aura::client::SetDragDropDelegate(view->GetNativeView(), this); | 1319 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1369 } | 1336 } |
| 1370 | 1337 |
| 1371 void WebContentsViewAura::SetPageTitle(const base::string16& title) { | 1338 void WebContentsViewAura::SetPageTitle(const base::string16& title) { |
| 1372 window_->set_title(title); | 1339 window_->set_title(title); |
| 1373 } | 1340 } |
| 1374 | 1341 |
| 1375 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { | 1342 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { |
| 1376 } | 1343 } |
| 1377 | 1344 |
| 1378 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { | 1345 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { |
| 1379 if (navigation_overlay_.get() && navigation_overlay_->has_window()) { | 1346 if (navigation_overlay_.get() && navigation_overlay_->has_window()) |
| 1380 navigation_overlay_->StartObservingView( | 1347 navigation_overlay_->StartObserving(); |
| 1381 ToRenderWidgetHostViewAura(host->GetView())); | |
| 1382 } | |
| 1383 AttachTouchEditableToRenderView(); | 1348 AttachTouchEditableToRenderView(); |
| 1384 } | 1349 } |
| 1385 | 1350 |
| 1386 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { | 1351 void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { |
| 1387 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( | 1352 RenderViewHostImpl* host = static_cast<RenderViewHostImpl*>( |
| 1388 web_contents_->GetRenderViewHost()); | 1353 web_contents_->GetRenderViewHost()); |
| 1389 if (host) { | 1354 if (host) { |
| 1390 host->SetOverscrollControllerEnabled(enabled); | 1355 host->SetOverscrollControllerEnabled(enabled); |
| 1391 if (enabled) | 1356 if (enabled) |
| 1392 host->overscroll_controller()->set_delegate(this); | 1357 host->overscroll_controller()->set_delegate(this); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 event.location(), | 1757 event.location(), |
| 1793 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1758 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
| 1794 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1759 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 1795 if (drag_dest_delegate_) | 1760 if (drag_dest_delegate_) |
| 1796 drag_dest_delegate_->OnDrop(); | 1761 drag_dest_delegate_->OnDrop(); |
| 1797 current_drop_data_.reset(); | 1762 current_drop_data_.reset(); |
| 1798 return ConvertFromWeb(current_drag_op_); | 1763 return ConvertFromWeb(current_drag_op_); |
| 1799 } | 1764 } |
| 1800 | 1765 |
| 1801 } // namespace content | 1766 } // namespace content |
| OLD | NEW |