web_contents_view_aura.cc revision 116680a4aac90f2aa7413d9095a592090648e557
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/web_contents_view_aura.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/auto_reset.h" 8bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#include "base/command_line.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/file_util.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/metrics/histogram.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/browser/browser_plugin/browser_plugin_guest.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/browser/download/drag_download_util.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/interstitial_page_impl.h" 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/navigation_entry_impl.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/dip_util.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/overscroll_controller.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/renderer_host/render_view_host_factory.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/render_view_host_impl.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_impl.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_view_aura.h" 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/browser/web_contents/aura/gesture_nav_simple.h" 23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/browser/web_contents/aura/image_window_delegate.h" 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/browser/web_contents/aura/shadow_layer_delegate.h" 26eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/browser/web_contents/aura/window_slider.h" 27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/browser/web_contents/touch_editable_impl_aura.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/web_contents/web_contents_impl.h" 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/content_browser_client.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_source.h" 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_types.h" 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/overscroll_configuration.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_view_host.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_widget_host.h" 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/render_widget_host_view.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_delegate.h" 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/web_contents_observer.h" 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_view_delegate.h" 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_drag_dest_delegate.h" 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/content_client.h" 43bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch#include "content/public/common/content_switches.h" 44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/public/common/drop_data.h" 45c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "net/base/filename_util.h" 467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebInputEvent.h" 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/aura_constants.h" 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/aura/client/window_tree_client.h" 494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/aura/env.h" 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h" 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/aura/window_observer.h" 5223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "ui/aura/window_tree_host.h" 53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_tree_host_observer.h" 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/base/clipboard/clipboard.h" 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/clipboard/custom_data_helper.h" 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/dragdrop/drag_drop_types.h" 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/dragdrop/drag_utils.h" 5868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ui/base/dragdrop/drop_target_event.h" 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/dragdrop/os_exchange_data.h" 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/hit_test.h" 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer.h" 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/compositor/scoped_layer_animation_settings.h" 63d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event.h" 64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_utils.h" 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/canvas.h" 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/image/image.h" 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/image/image_png_rep.h" 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/image/image_skia.h" 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h" 70effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/drag_drop_client.h" 71effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/drag_drop_delegate.h" 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 74010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)WebContentsView* CreateWebContentsView( 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsImpl* web_contents, 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsViewDelegate* delegate, 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHostDelegateView** render_view_host_delegate_view) { 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *render_view_host_delegate_view = rv; 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return rv; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochbool IsScrollEndEffectEnabled() { 86bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 87bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch switches::kScrollEndEffect) == "1"; 88bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch} 89bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ShouldNavigateForward(const NavigationController& controller, 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OverscrollMode mode) { 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller.CanGoForward(); 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool ShouldNavigateBack(const NavigationController& controller, 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OverscrollMode mode) { 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller.CanGoBack(); 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 102c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( 103c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderWidgetHostView* view) { 104c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!view || RenderViewHostFactory::has_factory()) 105c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. 106cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 107cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) RenderViewHost* rvh = RenderViewHost::From(view->GetRenderWidgetHost()); 108cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) rvh ? WebContents::FromRenderViewHost(rvh) : NULL); 110cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (BrowserPluginGuest::IsGuest(web_contents)) 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return NULL; 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return static_cast<RenderWidgetHostViewAura*>(view); 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The window delegate for the overscroll window. This redirects trackpad events 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// to the web-contents window. The delegate destroys itself when the window is 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// destroyed. 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)class OverscrollWindowDelegate : public ImageWindowDelegate { 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OverscrollWindowDelegate(WebContentsImpl* web_contents, 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OverscrollMode overscroll_mode) 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : web_contents_(web_contents), 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) forward_events_(true) { 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const NavigationControllerImpl& controller = web_contents->GetController(); 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const NavigationEntryImpl* entry = NULL; 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (ShouldNavigateForward(controller, overscroll_mode)) { 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller.GetEntryAtOffset(1)); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else if (ShouldNavigateBack(controller, overscroll_mode)) { 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) entry = NavigationEntryImpl::FromNavigationEntry( 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) controller.GetEntryAtOffset(-1)); 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::Image image; 1357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (entry && entry->screenshot().get()) { 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::vector<gfx::ImagePNGRep> image_reps; 137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 138cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ui::GetScaleFactorForNativeView(web_contents_window()))); 139c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) image = gfx::Image(image_reps); 140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 141c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SetImage(image); 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void stop_forwarding_events() { forward_events_ = false; } 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~OverscrollWindowDelegate() {} 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* web_contents_window() { 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return web_contents_->GetView()->GetContentNativeView(); 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Overridden from ui::EventHandler. 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE { 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (forward_events_ && web_contents_window()) 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_window()->delegate()->OnScrollEvent(event); 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (forward_events_ && web_contents_window()) 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_window()->delegate()->OnGestureEvent(event); 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 164010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) WebContentsImpl* web_contents_; 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The window is displayed both during the gesture, and after the gesture 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // while the navigation is in progress. During the gesture, it is necessary to 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // forward input events to the content page (e.g. when the overscroll window 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // slides under the cursor and starts receiving scroll events). However, once 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the gesture is complete, and the window is being displayed as an overlay 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // window during navigation, events should not be forwarded anymore. 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool forward_events_; 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate); 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Listens to all mouse drag events during a drag and drop and sends them to 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the renderer. 179c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass WebDragSourceAura : public NotificationObserver { 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : window_(window), 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_(contents) { 184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) registrar_.Add(this, 185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Source<WebContents>(contents)); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~WebDragSourceAura() { 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 192c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // NotificationObserver: 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const NotificationSource& source, 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const NotificationDetails& details) OVERRIDE { 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (type != NOTIFICATION_WEB_CONTENTS_DISCONNECTED) 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancel the drag if it is still in progress. 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::DragDropClient* dnd_client = 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::GetDragDropClient(window_->GetRootWindow()); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (dnd_client && dnd_client->IsDragDropInProgress()) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) dnd_client->DragCancel(); 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_ = NULL; 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) contents_ = NULL; 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* window() const { return window_; } 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* window_; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsImpl* contents_; 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NotificationRegistrar registrar_; 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 219effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if (!defined(OS_CHROMEOS) && defined(USE_X11)) || defined(OS_WIN) 22058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// Fill out the OSExchangeData with a file contents, synthesizing a name if 22158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)// necessary. 22258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)void PrepareDragForFileContents(const DropData& drop_data, 22358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) ui::OSExchangeData::Provider* provider) { 224effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::FilePath file_name = 225effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::FilePath::FromUTF16Unsafe(drop_data.file_description_filename); 22658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Images without ALT text will only have a file extension so we need to 22758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // synthesize one from the provided extension and URL. 22858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (file_name.BaseName().RemoveExtension().empty()) { 229effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const base::FilePath::StringType extension = file_name.Extension(); 23058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Retrieve the name from the URL. 231effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch file_name = net::GenerateFileName(drop_data.url, "", "", "", "", "") 232effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch .ReplaceExtension(extension); 23358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } 23458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) provider->SetFileContents(file_name, drop_data.file_contents); 23558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)} 236effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#endif 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 238effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if defined(OS_WIN) 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void PrepareDragForDownload( 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const DropData& drop_data, 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::OSExchangeData::Provider* provider, 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WebContentsImpl* web_contents) { 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& page_url = web_contents->GetLastCommittedURL(); 2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& page_encoding = web_contents->GetEncoding(); 2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Parse the download metadata. 2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 mime_type; 2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath file_name; 2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GURL download_url; 2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!ParseDownloadMetadata(drop_data.download_metadata, 2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &mime_type, 2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &file_name, 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &download_url)) 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Generate the file name based on both mime type and proposed file name. 2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string default_name = 2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetContentClient()->browser()->GetDefaultDownloadName(); 2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath generated_download_file_name = 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) net::GenerateFileName(download_url, 2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string(), 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string(), 2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::UTF16ToUTF8(file_name.value()), 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::UTF16ToUTF8(mime_type), 2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) default_name); 2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // http://crbug.com/332579 2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::ThreadRestrictions::ScopedAllowIO allow_file_operations; 2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath temp_dir_path; 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_drag"), 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &temp_dir_path)) 2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath download_path = 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) temp_dir_path.Append(generated_download_file_name); 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We cannot know when the target application will be done using the temporary 2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // file, so schedule it to be deleted after rebooting. 2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::DeleteFileAfterReboot(download_path); 2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::DeleteFileAfterReboot(temp_dir_path); 2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Provide the data as file (CF_HDROP). A temporary download file with the 2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Zone.Identifier ADS (Alternate Data Stream) attached will be created. 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_refptr<DragDownloadFile> download_file = 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new DragDownloadFile( 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) download_path, 288c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch base::File(), 2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) download_url, 2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Referrer(page_url, drop_data.referrer_policy), 2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) page_encoding, 2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) web_contents); 2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::OSExchangeData::DownloadFileInfo file_download(base::FilePath(), 2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) download_file.get()); 2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) provider->SetDownloadFileInfo(file_download); 2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 297effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#endif // defined(OS_WIN) 29858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 2990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Returns the CustomFormat to store file system files. 3000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochconst ui::OSExchangeData::CustomFormat& GetFileSystemFileCustomFormat() { 3010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch static const char kFormatString[] = "chromium/x-file-system-files"; 3020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch CR_DEFINE_STATIC_LOCAL(ui::OSExchangeData::CustomFormat, 3030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch format, 3040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch (ui::Clipboard::GetFormatType(kFormatString))); 3050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return format; 3060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 3070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Writes file system files to the pickle. 3090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid WriteFileSystemFilesToPickle( 3100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const std::vector<DropData::FileSystemFileInfo>& file_system_files, 3110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch Pickle* pickle) { 3120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch pickle->WriteUInt64(file_system_files.size()); 3130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch for (size_t i = 0; i < file_system_files.size(); ++i) { 3140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch pickle->WriteString(file_system_files[i].url.spec()); 3150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch pickle->WriteInt64(file_system_files[i].size); 3160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 3180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Reads file system files from the pickle. 3200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochbool ReadFileSystemFilesFromPickle( 3210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const Pickle& pickle, 3220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch std::vector<DropData::FileSystemFileInfo>* file_system_files) { 3230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch PickleIterator iter(pickle); 3240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch uint64 num_files = 0; 3260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!pickle.ReadUInt64(&iter, &num_files)) 3270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return false; 3280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch file_system_files->resize(num_files); 3290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch for (uint64 i = 0; i < num_files; ++i) { 3310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch std::string url_string; 3320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int64 size = 0; 3330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!pickle.ReadString(&iter, &url_string) || 3340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch !pickle.ReadInt64(&iter, &size)) 3350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return false; 3360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch GURL url(url_string); 3380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!url.is_valid()) 3390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return false; 3400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 3410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch (*file_system_files)[i].url = url; 3420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch (*file_system_files)[i].size = size; 3430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return true; 3450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 3460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Utility to fill a ui::OSExchangeDataProvider object from DropData. 348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid PrepareDragData(const DropData& drop_data, 3495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::OSExchangeData::Provider* provider, 3505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) WebContentsImpl* web_contents) { 351effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch provider->MarkOriginatedFromRenderer(); 35258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#if defined(OS_WIN) 3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Put download before file contents to prefer the download of a image over 3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // its thumbnail link. 3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!drop_data.download_metadata.empty()) 3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PrepareDragForDownload(drop_data, provider, web_contents); 357effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#endif 358effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#if (!defined(OS_CHROMEOS) && defined(USE_X11)) || defined(OS_WIN) 35958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // We set the file contents before the URL because the URL also sets file 36058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // contents (to a .URL shortcut). We want to prefer file content data over 36158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // a shortcut so we add it first. 36258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!drop_data.file_contents.empty()) 36358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) PrepareDragForFileContents(drop_data, provider); 36458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#endif 365116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Call SetString() before SetURL() when we actually have a custom string. 366116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // SetURL() will itself do SetString() when a string hasn't been set yet, 367116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // but we want to prefer drop_data.text.string() over the URL string if it 368116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // exists. 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!drop_data.text.string().empty()) 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider->SetString(drop_data.text.string()); 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (drop_data.url.is_valid()) 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider->SetURL(drop_data.url, drop_data.url_title); 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!drop_data.html.string().empty()) 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider->SetHtml(drop_data.html.string(), drop_data.html_base_url); 375effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!drop_data.filenames.empty()) 376effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch provider->SetFilenames(drop_data.filenames); 3770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!drop_data.file_system_files.empty()) { 3780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch Pickle pickle; 3790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch WriteFileSystemFilesToPickle(drop_data.file_system_files, &pickle); 3800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch provider->SetPickledData(GetFileSystemFileCustomFormat(), pickle); 3810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!drop_data.custom_data.empty()) { 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Pickle pickle; 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui::WriteCustomDataToPickle(drop_data.custom_data, &pickle); 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) provider->SetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pickle); 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 390eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Utility to fill a DropData object from ui::OSExchangeData. 391eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid PrepareDropData(DropData* drop_data, const ui::OSExchangeData& data) { 392effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch drop_data->did_originate_from_renderer = data.DidOriginateFromRenderer(); 393effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 394a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 plain_text; 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data.GetString(&plain_text); 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!plain_text.empty()) 3977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) drop_data->text = base::NullableString16(plain_text, false); 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL url; 400a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 url_title; 4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) data.GetURLAndTitle( 4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::OSExchangeData::DO_NOT_CONVERT_FILENAMES, &url, &url_title); 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (url.is_valid()) { 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_data->url = url; 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_data->url_title = url_title; 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 408a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 html; 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL html_base_url; 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) data.GetHtml(&html, &html_base_url); 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!html.empty()) 4127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) drop_data->html = base::NullableString16(html, false); 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (html_base_url.is_valid()) 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drop_data->html_base_url = html_base_url; 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 416effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch data.GetFilenames(&drop_data->filenames); 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Pickle pickle; 4190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch std::vector<DropData::FileSystemFileInfo> file_system_files; 4200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (data.GetPickledData(GetFileSystemFileCustomFormat(), &pickle) && 4210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch ReadFileSystemFilesFromPickle(pickle, &file_system_files)) 4220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch drop_data->file_system_files = file_system_files; 4230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 42490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) if (data.GetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), &pickle)) 42590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ui::ReadCustomDataIntoMap( 42690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) pickle.data(), pickle.size(), &drop_data->custom_data); 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 429f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Utilities to convert between blink::WebDragOperationsMask and 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ui::DragDropTypes. 431f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)int ConvertFromWeb(blink::WebDragOperationsMask ops) { 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int drag_op = ui::DragDropTypes::DRAG_NONE; 433f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (ops & blink::WebDragOperationCopy) 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_op |= ui::DragDropTypes::DRAG_COPY; 435f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (ops & blink::WebDragOperationMove) 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_op |= ui::DragDropTypes::DRAG_MOVE; 437f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (ops & blink::WebDragOperationLink) 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_op |= ui::DragDropTypes::DRAG_LINK; 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return drag_op; 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 442f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)blink::WebDragOperationsMask ConvertToWeb(int drag_op) { 443f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int web_drag_op = blink::WebDragOperationNone; 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (drag_op & ui::DragDropTypes::DRAG_COPY) 445f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) web_drag_op |= blink::WebDragOperationCopy; 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (drag_op & ui::DragDropTypes::DRAG_MOVE) 447f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) web_drag_op |= blink::WebDragOperationMove; 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (drag_op & ui::DragDropTypes::DRAG_LINK) 449f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) web_drag_op |= blink::WebDragOperationLink; 450f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return (blink::WebDragOperationsMask) web_drag_op; 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int ConvertAuraEventFlagsToWebInputEventModifiers(int aura_event_flags) { 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int web_input_event_modifiers = 0; 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (aura_event_flags & ui::EF_SHIFT_DOWN) 456f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) web_input_event_modifiers |= blink::WebInputEvent::ShiftKey; 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (aura_event_flags & ui::EF_CONTROL_DOWN) 458f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) web_input_event_modifiers |= blink::WebInputEvent::ControlKey; 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (aura_event_flags & ui::EF_ALT_DOWN) 460f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) web_input_event_modifiers |= blink::WebInputEvent::AltKey; 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (aura_event_flags & ui::EF_COMMAND_DOWN) 462f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) web_input_event_modifiers |= blink::WebInputEvent::MetaKey; 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return web_input_event_modifiers; 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WebContentsViewAura::WindowObserver 469a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) : public aura::WindowObserver, public aura::WindowTreeHostObserver { 4702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) explicit WindowObserver(WebContentsViewAura* view) 4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : view_(view), 473116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window_(NULL) { 4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) view_->window_->AddObserver(this); 475f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 476f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 477f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (view_->window_->GetRootWindow()) 478f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) view_->window_->GetRootWindow()->AddObserver(this); 479f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 4812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowObserver() { 4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) view_->window_->RemoveObserver(this); 484a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (view_->window_->GetHost()) 485a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) view_->window_->GetHost()->RemoveObserver(this); 486116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (host_window_) 487116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window_->RemoveObserver(this); 488f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 489116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (host_window_) { 490116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const aura::Window::Windows& children = host_window_->children(); 491f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) for (size_t i = 0; i < children.size(); ++i) 492f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) children[i]->RemoveObserver(this); 493f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 494f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 495f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) aura::Window* root_window = view_->window_->GetRootWindow(); 496f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (root_window) { 497f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) root_window->RemoveObserver(this); 498f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const aura::Window::Windows& root_children = root_window->children(); 499f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) for (size_t i = 0; i < root_children.size(); ++i) 500f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) root_children[i]->RemoveObserver(this); 501f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 502f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 5042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Overridden from aura::WindowObserver: 506f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 507f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Constrained windows are added as children of the parent's parent's view 508f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV 509f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // so that it can update the plugins' cutout rects accordingly. 510f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is 511f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // going to be deprecated in a year, this is ok for now. The test for this is 512f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // PrintPreviewTest.WindowedNPAPIPluginHidden. 513f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { 514116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!new_window->Contains(view_->window_.get())) { 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Skip the case when the parent moves to the root window. 516116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (new_window != host_window_) { 5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Observe sibling windows of the WebContents, or children of the root 5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // window. 519116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (new_window->parent() == host_window_ || 5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new_window->parent() == view_->window_->GetRootWindow()) { 5215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new_window->AddObserver(this); 5225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 525f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 526116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (new_window->parent() == host_window_) { 527f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) UpdateConstrainedWindows(NULL); 528f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 529f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 530f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 531f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { 532f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (window == view_->window_) 533f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return; 534f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 535f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window->RemoveObserver(this); 536f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) UpdateConstrainedWindows(window); 537f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 538f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 539f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void OnWindowVisibilityChanged(aura::Window* window, 540f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool visible) OVERRIDE { 5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (window == view_->window_ || 542116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch window->parent() == host_window_ || 543f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window->parent() == view_->window_->GetRootWindow()) { 544f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) UpdateConstrainedWindows(NULL); 545f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 546f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 547f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 548f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 5492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnWindowParentChanged(aura::Window* window, 5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* parent) OVERRIDE { 551f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (window != view_->window_) 5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 553116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 554116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Use the new parent's root window for calculating HiDPI subpixel offset. 555116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch RenderWidgetHostViewAura* rwhv = ToRenderWidgetHostViewAura( 556116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch view_->web_contents_->GetRenderWidgetHostView()); 557116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (rwhv) 558116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch rwhv->SnapToPhysicalPixelBoundary(); 559116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 560116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch aura::Window* host_window = 561116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch window->GetProperty(aura::client::kHostWindowKey); 562116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!host_window) 563116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window = parent; 564116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 565116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (host_window_) 566116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window_->RemoveObserver(this); 567f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 568f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 569116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (host_window_) { 570116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const aura::Window::Windows& children = host_window_->children(); 571f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) for (size_t i = 0; i < children.size(); ++i) 572f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) children[i]->RemoveObserver(this); 573f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 574116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (rwhv) 575116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch rwhv->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); 576f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 577f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 578f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // When we get parented to the root window, the code below will watch the 579116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // host window, aka root window. Since we already watch the root window on 580f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Windows, unregister first so that the debug check doesn't fire. 581116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (host_window && host_window == window->GetRootWindow()) 582116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window->RemoveObserver(this); 583f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 584f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // We need to undo the above if we were parented to the root window and then 585f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // got parented to another window. At that point, the code before the ifdef 586f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // would have stopped watching the root window. 587f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (window->GetRootWindow() && 588116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window != window->GetRootWindow() && 589f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) !window->GetRootWindow()->HasObserver(this)) { 590f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window->GetRootWindow()->AddObserver(this); 591f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 592f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 593f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 594116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window_ = host_window; 595116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (host_window) { 596116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window->AddObserver(this); 597f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 598116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (host_window != window->GetRootWindow()) { 599116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const aura::Window::Windows& children = host_window->children(); 600f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) for (size_t i = 0; i < children.size(); ++i) { 601116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!children[i]->Contains(view_->window_.get())) 602f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) children[i]->AddObserver(this); 603f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 604f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 605f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 606f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 6072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnWindowBoundsChanged(aura::Window* window, 6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& old_bounds, 6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& new_bounds) OVERRIDE { 612116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (window == host_window_ || window == view_->window_) { 613f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SendScreenRects(); 614f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (view_->touch_editable_) 615f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) view_->touch_editable_->UpdateEditingController(); 616f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 617f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } else { 618f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) UpdateConstrainedWindows(NULL); 619f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 620f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 623116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { 624116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (window == host_window_) { 625116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window_->RemoveObserver(this); 626116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch host_window_ = NULL; 627116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 628116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 629116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { 631f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (window == view_->window_) { 632a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->GetHost()->AddObserver(this); 633f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 634f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (!window->GetRootWindow()->HasObserver(this)) 635f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window->GetRootWindow()->AddObserver(this); 636f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 637f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 640effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch virtual void OnWindowRemovingFromRootWindow(aura::Window* window, 641effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch aura::Window* new_root) OVERRIDE { 642f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (window == view_->window_) { 643a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) window->GetHost()->RemoveObserver(this); 644f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_WIN) 645f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window->GetRootWindow()->RemoveObserver(this); 646f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 647f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const aura::Window::Windows& root_children = 648f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window->GetRootWindow()->children(); 649f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) for (size_t i = 0; i < root_children.size(); ++i) { 650116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (root_children[i] != view_->window_ && 651116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch root_children[i] != host_window_) { 652f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) root_children[i]->RemoveObserver(this); 653116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 654f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 655f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 656f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 659a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Overridden WindowTreeHostObserver: 660a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void OnHostMoved(const aura::WindowTreeHost* host, 661a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const gfx::Point& new_origin) OVERRIDE { 662f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) TRACE_EVENT1("ui", 663a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) "WebContentsViewAura::WindowObserver::OnHostMoved", 664f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) "new_origin", new_origin.ToString()); 665f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This is for the desktop case (i.e. Aura desktop). 6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendScreenRects(); 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SendScreenRects() { 6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> 6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendScreenRects(); 6742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN) 6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void UpdateConstrainedWindows(aura::Window* exclude) { 678c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( 6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) view_->web_contents_->GetRenderWidgetHostView()); 6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!view) 6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<gfx::Rect> constrained_windows; 684116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (host_window_) { 685116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const aura::Window::Windows& children = host_window_->children(); 686f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) for (size_t i = 0; i < children.size(); ++i) { 687116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!children[i]->Contains(view_->window_.get()) && 688f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) children[i] != exclude && 689f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) children[i]->IsVisible()) { 690f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); 691f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 692f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 693f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 694f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 695f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) aura::Window* root_window = view_->window_->GetRootWindow(); 696f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const aura::Window::Windows& root_children = root_window->children(); 697f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (root_window) { 698f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) for (size_t i = 0; i < root_children.size(); ++i) { 699f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) if (root_children[i]->IsVisible() && 700f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) !root_children[i]->Contains(view_->window_.get())) { 701f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) constrained_windows.push_back( 702f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) root_children[i]->GetBoundsInRootWindow()); 703f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 704f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) view->UpdateConstrainedWindowRects(constrained_windows); 7082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 709f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#endif 7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsViewAura* view_; 7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 713116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // The parent window that hosts the constrained windows. We cache the old host 714116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // view so that we can unregister when it's not the parent anymore. 715116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch aura::Window* host_window_; 716f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 717f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WindowObserver); 7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContentsViewAura, public: 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContentsViewAura::WebContentsViewAura( 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsImpl* web_contents, 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsViewDelegate* delegate) 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : web_contents_(web_contents), 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_(delegate), 728f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) current_drag_op_(blink::WebDragOperationNone), 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_dest_delegate_(NULL), 7302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_rvh_for_drag_(NULL), 7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_change_brightness_(false), 7322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_(OVERSCROLL_NONE), 733c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) completed_overscroll_gesture_(OVERSCROLL_NONE), 734116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch touch_editable_(TouchEditableImplAura::Create()), 735116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch is_or_was_visible_(false) { 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContentsViewAura, private: 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)WebContentsViewAura::~WebContentsViewAura() { 7422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!window_) 7432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 7442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_observer_.reset(); 746cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) window_->RemoveObserver(this); 747f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Window needs a valid delegate during its destructor, so we explicitly 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // delete it here. 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_.reset(); 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 753c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void WebContentsViewAura::SetTouchEditableForTest( 754c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TouchEditableImplAura* touch_editable) { 755c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) touch_editable_.reset(touch_editable); 756c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AttachTouchEditableToRenderView(); 757c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 758c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (web_contents_->GetInterstitialPage()) 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetInterstitialPage()->SetSize(size); 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostView* rwhv = 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetRenderWidgetHostView(); 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (rwhv) 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rwhv->SetSize(size); 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 768f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void WebContentsViewAura::EndDrag(blink::WebDragOperationsMask ops) { 7691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root_window = GetNativeView()->GetRootWindow(); 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point screen_loc = 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point client_loc = screen_loc; 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHost* rvh = web_contents_->GetRenderViewHost(); 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* window = rvh->GetView()->GetNativeView(); 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window::ConvertPointToTarget(root_window, window, &client_loc); 776c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!web_contents_) 777c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 778c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.y(), 779c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) screen_loc.x(), screen_loc.y(), ops); 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 782a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WebContentsViewAura::InstallOverscrollControllerDelegate( 78346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) RenderWidgetHostViewAura* view) { 784a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::string value = CommandLine::ForCurrentProcess()-> 785a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); 786a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (value == "0") { 787a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) navigation_overlay_.reset(); 788a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 789a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 790a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (value == "2") { 791a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) navigation_overlay_.reset(); 792a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!gesture_nav_simple_) 793a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gesture_nav_simple_.reset(new GestureNavSimple(web_contents_)); 79446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) view->overscroll_controller()->set_delegate(gesture_nav_simple_.get()); 795a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 796a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 79746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) view->overscroll_controller()->set_delegate(this); 798a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!navigation_overlay_) 799a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 800a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 801a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 8022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::PrepareOverscrollWindow() { 8032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If there is an existing |overscroll_window_| which is in the middle of an 8042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // animation, then destroying the window here causes the animation to be 8052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // completed immidiately, which triggers |OnImplicitAnimationsCompleted()| 8062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // callback, and that tries to reset |overscroll_window_| again, causing a 8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // double-free. So use a temporary variable here. 808c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (overscroll_window_) { 8092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::AutoReset<OverscrollMode> reset_state(¤t_overscroll_gesture_, 8102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_); 8112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<aura::Window> reset_window(overscroll_window_.release()); 8122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( 8152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_, 8162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_); 8172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_.reset(new aura::Window(overscroll_delegate)); 8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) overscroll_window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 8192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_->SetTransparent(true); 8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) overscroll_window_->Init(aura::WINDOW_LAYER_TEXTURED); 821c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) overscroll_window_->layer()->SetMasksToBounds(false); 8222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_->SetName("OverscrollOverlay"); 8232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 824c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) overscroll_change_brightness_ = overscroll_delegate->has_image(); 8252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->AddChild(overscroll_window_.get()); 8262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect bounds = gfx::Rect(window_->bounds().size()); 8282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (ShouldNavigateForward(web_contents_->GetController(), 8292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_)) { 8302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The overlay will be sliding in from the right edge towards the left in 8312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // non-RTL, or sliding in from the left edge towards the right in RTL. 8322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // So position the overlay window accordingly. 8332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0); 8342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 836c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::Window* animate_window = GetWindowToAnimateForOverscroll(); 837c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (animate_window == overscroll_window_) 838c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window_->StackChildAbove(overscroll_window_.get(), GetContentNativeView()); 839c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) else 840c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) window_->StackChildBelow(overscroll_window_.get(), GetContentNativeView()); 8412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateOverscrollWindowBrightness(0.f); 8432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_->SetBounds(bounds); 8452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_->Show(); 846c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) overscroll_shadow_.reset(new ShadowLayerDelegate(animate_window->layer())); 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::PrepareContentWindowForOverscroll() { 851b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) StopObservingImplicitAnimations(); 852c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::Window* content = GetContentNativeView(); 853b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) content->layer()->GetAnimator()->AbortAllAnimations(); 8542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content->SetTransform(gfx::Transform()); 8552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content->layer()->SetLayerBrightness(0.f); 8562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 8572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::ResetOverscrollTransform() { 8592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!web_contents_->GetRenderWidgetHostView()) 8602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* target = GetWindowToAnimateForOverscroll(); 8622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!target) 8632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 8652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator()); 8662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) settings.SetPreemptionStrategy( 8672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 868d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) settings.SetTweenType(gfx::Tween::EASE_OUT); 8692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) settings.AddObserver(this); 8702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) target->SetTransform(gfx::Transform()); 8712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 8722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) { 8732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator()); 8742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) settings.SetPreemptionStrategy( 8752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 876d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) settings.SetTweenType(gfx::Tween::EASE_OUT); 8772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateOverscrollWindowBrightness(0.f); 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::CompleteOverscrollNavigation(OverscrollMode mode) { 8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!web_contents_->GetRenderWidgetHostView()) 8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Animate out the current view first. Navigate to the requested history at 8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the end of the animation. 8872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (current_overscroll_gesture_ == OVERSCROLL_NONE) 8882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UMA_HISTOGRAM_ENUMERATION("Overscroll.Navigated", 8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_, OVERSCROLL_COUNT); 892b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>( 893b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) overscroll_window_->delegate()); 894b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) delegate->stop_forwarding_events(); 8952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completed_overscroll_gesture_ = mode; 8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* target = GetWindowToAnimateForOverscroll(); 8982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::ScopedLayerAnimationSettings settings(target->layer()->GetAnimator()); 8992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) settings.SetPreemptionStrategy( 9002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 901d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) settings.SetTweenType(gfx::Tween::EASE_OUT); 9022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) settings.AddObserver(this); 9032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Transform transform; 9042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int content_width = 9052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetRenderWidgetHostView()->GetViewBounds().width(); 9062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int translate_x = mode == OVERSCROLL_WEST ? -content_width : content_width; 9072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) transform.Translate(translate_x, 0); 9082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) target->SetTransform(transform); 9092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UpdateOverscrollWindowBrightness(translate_x); 9102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)aura::Window* WebContentsViewAura::GetWindowToAnimateForOverscroll() { 9132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (current_overscroll_gesture_ == OVERSCROLL_NONE) 9142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return NULL; 9152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return ShouldNavigateForward(web_contents_->GetController(), 9172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_) ? 918c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) overscroll_window_.get() : GetContentNativeView(); 9192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Vector2d WebContentsViewAura::GetTranslationForOverscroll(int delta_x, 9222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int delta_y) { 9232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (current_overscroll_gesture_ == OVERSCROLL_NORTH || 9242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_ == OVERSCROLL_SOUTH) { 925bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch return gfx::Vector2d(0, delta_y); 9262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 9272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // For horizontal overscroll, scroll freely if a navigation is possible. Do a 9282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // resistive scroll otherwise. 9292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const NavigationControllerImpl& controller = web_contents_->GetController(); 9302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& bounds = GetViewBounds(); 9312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (ShouldNavigateForward(controller, current_overscroll_gesture_)) 9322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return gfx::Vector2d(std::max(-bounds.width(), delta_x), 0); 9332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else if (ShouldNavigateBack(controller, current_overscroll_gesture_)) 9342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return gfx::Vector2d(std::min(bounds.width(), delta_x), 0); 9352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return gfx::Vector2d(); 9362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::PrepareOverscrollNavigationOverlay() { 9392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>( 9402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_->delegate()); 9412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_->SchedulePaintInRect( 9422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect(overscroll_window_->bounds().size())); 943eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch overscroll_window_->SetBounds(gfx::Rect(window_->bounds().size())); 944eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch overscroll_window_->SetTransform(gfx::Transform()); 9452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass(), 946eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch delegate); 9475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) navigation_overlay_->StartObserving(); 9482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 9492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::UpdateOverscrollWindowBrightness(float delta_x) { 9512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!overscroll_change_brightness_) 9522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 9532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const float kBrightnessMin = -.1f; 9552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const float kBrightnessMax = -.01f; 9562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float ratio = fabs(delta_x) / GetViewBounds().width(); 9582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ratio = std::min(1.f, ratio); 9592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (base::i18n::IsRTL()) 9602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ratio = 1.f - ratio; 9612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) float brightness = current_overscroll_gesture_ == OVERSCROLL_WEST ? 9622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kBrightnessMin + ratio * (kBrightnessMax - kBrightnessMin) : 9632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) kBrightnessMax - ratio * (kBrightnessMax - kBrightnessMin); 9642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) brightness = std::max(kBrightnessMin, brightness); 9652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) brightness = std::min(kBrightnessMax, brightness); 9662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* window = GetWindowToAnimateForOverscroll(); 9672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window->layer()->SetLayerBrightness(brightness); 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 970c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void WebContentsViewAura::AttachTouchEditableToRenderView() { 971c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!touch_editable_) 972c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 973c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) RenderWidgetHostViewAura* rwhva = ToRenderWidgetHostViewAura( 974c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) web_contents_->GetRenderWidgetHostView()); 975c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) touch_editable_->AttachToView(rwhva); 976c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 977c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 978bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdochvoid WebContentsViewAura::OverscrollUpdateForWebContentsDelegate(int delta_y) { 979bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch if (web_contents_->GetDelegate() && IsScrollEndEffectEnabled()) 980bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch web_contents_->GetDelegate()->OverscrollUpdate(delta_y); 981bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch} 982bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 9832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 9842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WebContentsViewAura, WebContentsView implementation: 9852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeView WebContentsViewAura::GetNativeView() const { 9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_.get(); 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeView WebContentsViewAura::GetContentNativeView() const { 9912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 9922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return rwhv ? rwhv->GetNativeView() : NULL; 9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeWindow WebContentsViewAura::GetTopLevelNativeWindow() const { 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return window_->GetToplevelWindow(); 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *out = window_->GetBoundsInScreen(); 10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::SizeContents(const gfx::Size& size) { 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect bounds = window_->bounds(); 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (bounds.size() != size) { 10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bounds.set_size(size); 10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->SetBounds(bounds); 10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Our size matches what we want but the renderers size may not match. 10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Pretend we were resized so that the renderers size is updated too. 10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SizeChangedCommon(size); 10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::Focus() { 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (web_contents_->GetInterstitialPage()) { 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetInterstitialPage()->Focus(); 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 10205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (delegate_.get() && delegate_->Focus()) 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (rwhv) 10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) rwhv->Focus(); 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::SetInitialFocus() { 10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (web_contents_->FocusLocationBarByDefault()) 10315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->SetFocusToLocationBar(false); 10325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 10335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Focus(); 10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::StoreFocus() { 1037c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (delegate_) 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->StoreFocus(); 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::RestoreFocus() { 1042c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (delegate_) 10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->RestoreFocus(); 10445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1046eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochDropData* WebContentsViewAura::GetDropData() const { 10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return current_drop_data_.get(); 10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Rect WebContentsViewAura::GetViewBounds() const { 10512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return window_->GetBoundsInScreen(); 10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 1055010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// WebContentsViewAura, WebContentsView implementation: 10562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::CreateView( 10582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Size& initial_size, gfx::NativeView context) { 10592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // NOTE: we ignore |initial_size| since in some cases it's wrong (such as 10602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // if the bookmark bar is not shown and you create a new tab). The right 10612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // value is set shortly after this, so its safe to ignore. 10622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1063010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) aura::Env::CreateInstance(true); 10642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_.reset(new aura::Window(this)); 10652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->set_owned_by_parent(false); 10665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 10672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetTransparent(false); 10685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); 1069cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) window_->AddObserver(this); 10701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root_window = context ? context->GetRootWindow() : NULL; 10712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (root_window) { 10722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // There are places where there is no context currently because object 10732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // hierarchies are built before they're attached to a Widget. (See 10742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // views::WebView as an example; GetWidget() returns NULL at the point 10752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // where we are created.) 10762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 10772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // It should be OK to not set a default parent since such users will 10782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // explicitly add this WebContentsViewAura to their tree after they create 10792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // us. 10802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (root_window) { 10811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::client::ParentWindowWithContext( 10821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) window_.get(), root_window, root_window->GetBoundsInScreen()); 10832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 10842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 10852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->layer()->SetMasksToBounds(true); 10862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) window_->SetName("WebContentsViewAura"); 10872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1088f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // WindowObserver is not interesting and is problematic for Browser Plugin 1089f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // guests. 1090f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The use cases for WindowObserver do not apply to Browser Plugins: 1091f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // 1) guests do not support NPAPI plugins. 1092f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // 2) guests' window bounds are supposed to come from its embedder. 1093cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!BrowserPluginGuest::IsGuest(web_contents_)) 1094f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) window_observer_.reset(new WindowObserver(this)); 10952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // delegate_->GetDragDestDelegate() creates a new delegate on every call. 10972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Hence, we save a reference to it locally. Similar model is used on other 10982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // platforms as well. 1099c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (delegate_) 11002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) drag_dest_delegate_ = delegate_->GetDragDestDelegate(); 11015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1103010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( 11042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHost* render_widget_host) { 11052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (render_widget_host->GetView()) { 11062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // During testing, the view will already be set up in most cases to the 11072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // test view, so we don't want to clobber it with a real one. To verify that 11082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this actually is happening (and somebody isn't accidentally creating the 11092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // view twice), we check for the RVH Factory, which will be set when we're 11102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // making special ones (which go along with the special views). 11112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK(RenderViewHostFactory::has_factory()); 1112010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return static_cast<RenderWidgetHostViewBase*>( 1113010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) render_widget_host->GetView()); 11142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 11152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 111646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) RenderWidgetHostViewAura* view = 111746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) new RenderWidgetHostViewAura(render_widget_host); 11182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) view->InitAsChild(NULL); 1119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) GetNativeView()->AddChild(view->GetNativeView()); 11202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (navigation_overlay_.get() && navigation_overlay_->has_window()) { 11225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) navigation_overlay_->StartObserving(); 11232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 11242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 112558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) RenderWidgetHostImpl* host_impl = 112658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) RenderWidgetHostImpl::From(render_widget_host); 112758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 112858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (!host_impl->is_hidden()) 112958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) view->Show(); 11302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // We listen to drag drop events in the newly created view's window. 11322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::client::SetDragDropDelegate(view->GetNativeView(), this); 11332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 113446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) if (view->overscroll_controller() && 11352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) (!web_contents_->GetDelegate() || 11362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetDelegate()->CanOverscrollContent())) { 113746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) InstallOverscrollControllerDelegate(view); 11382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 11392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1140c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AttachTouchEditableToRenderView(); 11412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return view; 11422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1144010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( 11452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHost* render_widget_host) { 1146010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return new RenderWidgetHostViewAura(render_widget_host); 11472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void WebContentsViewAura::SetPageTitle(const base::string16& title) { 1150116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch window_->SetTitle(title); 11512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { 11542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { 11575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (navigation_overlay_.get() && navigation_overlay_->has_window()) 11585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) navigation_overlay_->StartObserving(); 1159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AttachTouchEditableToRenderView(); 11602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::SetOverscrollControllerEnabled(bool enabled) { 116346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) RenderWidgetHostViewAura* view = 116446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) ToRenderWidgetHostViewAura(web_contents_->GetRenderWidgetHostView()); 116546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) if (view) { 116646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) view->SetOverscrollControllerEnabled(enabled); 11672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (enabled) 116846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) InstallOverscrollControllerDelegate(view); 11692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 1170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (!enabled) 1172868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) navigation_overlay_.reset(); 1173868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) else if (!navigation_overlay_) 1174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch navigation_overlay_.reset(new OverscrollNavigationOverlay(web_contents_)); 11755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 11785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContentsViewAura, RenderViewHostDelegateView implementation: 11795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void WebContentsViewAura::ShowContextMenu(RenderFrameHost* render_frame_host, 11815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ContextMenuParams& params) { 1182a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (touch_editable_) { 11835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) touch_editable_->EndTouchEditing(false); 1184a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 1185424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) if (delegate_) { 11865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate_->ShowContextMenu(render_frame_host, params); 1187424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // WARNING: we may have been deleted during the call to ShowContextMenu(). 1188424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) } 11895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 11905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::StartDragging( 1192eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const DropData& drop_data, 1193f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) blink::WebDragOperationsMask operations, 11945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::ImageSkia& image, 11955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Vector2d& image_offset, 11965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const DragEventSourceInfo& event_info) { 11971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) aura::Window* root_window = GetNativeView()->GetRootWindow(); 1198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!aura::client::GetDragDropClient(root_window)) { 1199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) web_contents_->SystemDragEnded(); 12005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 1201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 1202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 1203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (touch_editable_) 12045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) touch_editable_->EndTouchEditing(false); 12055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::OSExchangeData::Provider* provider = ui::OSExchangeData::CreateProvider(); 12075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PrepareDragData(drop_data, provider, web_contents_); 12082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ui::OSExchangeData data(provider); // takes ownership of |provider|. 12102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1211f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) if (!image.isNull()) 1212f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) drag_utils::SetDragImageOnDataObject(image, image_offset, &data); 12135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<WebDragSourceAura> drag_source( 12155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) new WebDragSourceAura(GetNativeView(), web_contents_)); 12165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We need to enable recursive tasks on the message loop so we can get 12185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // updates while in the system DoDragDrop loop. 12195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int result_op = 0; 12205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 12212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::NativeView content_native_view = GetContentNativeView(); 1222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MessageLoop::ScopedNestableTaskAllower allow( 1223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) base::MessageLoop::current()); 1224c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) result_op = aura::client::GetDragDropClient(root_window) 1225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ->StartDragAndDrop(data, 1226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) root_window, 1227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content_native_view, 1228c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) event_info.event_location, 1229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ConvertFromWeb(operations), 1230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) event_info.event_source); 12315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 12325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Bail out immediately if the contents view window is gone. Note that it is 1234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // not safe to access any class members in this case since |this| may already 1235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // be destroyed. The local variable |drag_source| will still be valid though, 1236c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // so we can use it to determine if the window is gone. 1237c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (!drag_source->window()) { 1238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Note that in this case, we don't need to call SystemDragEnded() since the 1239c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // renderer is going away. 12405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 1241c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 12425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EndDrag(ConvertToWeb(result_op)); 1244c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) web_contents_->SystemDragEnded(); 12455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 12465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1247f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void WebContentsViewAura::UpdateDragCursor(blink::WebDragOperation operation) { 12485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_drag_op_ = operation; 12495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 12505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::GotFocus() { 12525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (web_contents_->GetDelegate()) 12535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetDelegate()->WebContentsFocused(web_contents_); 12545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 12555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::TakeFocus(bool reverse) { 12575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (web_contents_->GetDelegate() && 12585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) !web_contents_->GetDelegate()->TakeFocus(web_contents_, reverse) && 12595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_.get()) { 12605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->TakeFocus(reverse); 12615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 12625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 12635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 12645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 12652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WebContentsViewAura, OverscrollControllerDelegate implementation: 12662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)gfx::Rect WebContentsViewAura::GetVisibleBounds() const { 12681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) RenderWidgetHostView* rwhv = web_contents_->GetRenderWidgetHostView(); 12691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!rwhv || !rwhv->IsShowing()) 12701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return gfx::Rect(); 12711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 12721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return rwhv->GetViewBounds(); 12731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 12741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 12752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::OnOverscrollUpdate(float delta_x, float delta_y) { 12762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (current_overscroll_gesture_ == OVERSCROLL_NONE) 12772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 12782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) aura::Window* target = GetWindowToAnimateForOverscroll(); 12802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Vector2d translate = GetTranslationForOverscroll(delta_x, delta_y); 12812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Transform transform; 12822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1283bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch // Vertical overscrolls don't participate in the navigation gesture. 1284bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch if (current_overscroll_gesture_ != OVERSCROLL_NORTH && 1285bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch current_overscroll_gesture_ != OVERSCROLL_SOUTH) { 1286bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch transform.Translate(translate.x(), translate.y()); 1287bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch target->SetTransform(transform); 1288bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch UpdateOverscrollWindowBrightness(delta_x); 1289bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch } 1290bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch 1291bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch OverscrollUpdateForWebContentsDelegate(translate.y()); 12922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 12932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 12942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::OnOverscrollComplete(OverscrollMode mode) { 12952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UMA_HISTOGRAM_ENUMERATION("Overscroll.Completed", mode, OVERSCROLL_COUNT); 1296bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch OverscrollUpdateForWebContentsDelegate(0); 12972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigationControllerImpl& controller = web_contents_->GetController(); 12982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (ShouldNavigateForward(controller, mode) || 12992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShouldNavigateBack(controller, mode)) { 13002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CompleteOverscrollNavigation(mode); 13012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 13022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 13032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ResetOverscrollTransform(); 13052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::OnOverscrollModeChange(OverscrollMode old_mode, 13082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) OverscrollMode new_mode) { 13092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Reset any in-progress overscroll animation first. 13102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ResetOverscrollTransform(); 13112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 131258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (new_mode != OVERSCROLL_NONE && touch_editable_) 131358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) touch_editable_->OverscrollStarted(); 131458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 13152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (new_mode == OVERSCROLL_NONE || 1316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) !GetContentNativeView() || 1317bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch ((new_mode == OVERSCROLL_EAST || new_mode == OVERSCROLL_WEST) && 1318bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch navigation_overlay_.get() && navigation_overlay_->has_window())) { 13192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_ = OVERSCROLL_NONE; 1320bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch OverscrollUpdateForWebContentsDelegate(0); 13212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else { 1322b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) aura::Window* target = GetWindowToAnimateForOverscroll(); 1323b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) if (target) { 1324b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) StopObservingImplicitAnimations(); 1325b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) target->layer()->GetAnimator()->AbortAllAnimations(); 1326b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } 13272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Cleanup state of the content window first, because that can reset the 13282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // value of |current_overscroll_gesture_|. 13292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PrepareContentWindowForOverscroll(); 13302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_ = new_mode; 1332bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch if (current_overscroll_gesture_ == OVERSCROLL_EAST || 1333bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch current_overscroll_gesture_ == OVERSCROLL_WEST) 1334bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch PrepareOverscrollWindow(); 13352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UMA_HISTOGRAM_ENUMERATION("Overscroll.Started", new_mode, OVERSCROLL_COUNT); 13372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 13382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completed_overscroll_gesture_ = OVERSCROLL_NONE; 13392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 13422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// WebContentsViewAura, ui::ImplicitAnimationObserver implementation: 13432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::OnImplicitAnimationsCompleted() { 1345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) overscroll_shadow_.reset(); 1346c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 13472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (ShouldNavigateForward(web_contents_->GetController(), 13482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completed_overscroll_gesture_)) { 13492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetController().GoForward(); 1350c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch PrepareOverscrollNavigationOverlay(); 13512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } else if (ShouldNavigateBack(web_contents_->GetController(), 13522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completed_overscroll_gesture_)) { 13532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) web_contents_->GetController().GoBack(); 1354c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch PrepareOverscrollNavigationOverlay(); 135558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) } else { 135658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) if (touch_editable_) 135758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) touch_editable_->OverscrollCompleted(); 13582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 13592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1360c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) aura::Window* content = GetContentNativeView(); 1361c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (content) { 1362c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content->SetTransform(gfx::Transform()); 1363c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content->layer()->SetLayerBrightness(0.f); 13642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 13652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) current_overscroll_gesture_ = OVERSCROLL_NONE; 13662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) completed_overscroll_gesture_ = OVERSCROLL_NONE; 13672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_.reset(); 13682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 13715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContentsViewAura, aura::WindowDelegate implementation: 13725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 13735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Size WebContentsViewAura::GetMinimumSize() const { 13745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::Size(); 13755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 13765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 13772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Size WebContentsViewAura::GetMaximumSize() const { 13782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return gfx::Size(); 13792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 13802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 13815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, 13825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Rect& new_bounds) { 13835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SizeChangedCommon(new_bounds.size()); 1384c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (delegate_) 13855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) delegate_->SizeChanged(new_bounds.size()); 13865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 13875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Constrained web dialogs, need to be kept centered over our content area. 13885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (size_t i = 0; i < window_->children().size(); i++) { 13895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (window_->children()[i]->GetProperty( 13905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::client::kConstrainedWindowKey)) { 13915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect bounds = window_->children()[i]->bounds(); 13925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bounds.set_origin( 13935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point((new_bounds.width() - bounds.width()) / 2, 13945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) (new_bounds.height() - bounds.height()) / 2)); 13955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_->children()[i]->SetBounds(bounds); 13965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 13975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 13985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 13995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::NativeCursor WebContentsViewAura::GetCursor(const gfx::Point& point) { 14015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gfx::kNullCursor; 14025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int WebContentsViewAura::GetNonClientComponent(const gfx::Point& point) const { 14055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return HTCLIENT; 14065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsViewAura::ShouldDescendIntoChildForEventHandling( 14095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) aura::Window* child, 14105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const gfx::Point& location) { 14115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return true; 14125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsViewAura::CanFocus() { 14158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Do not take the focus if the render widget host view aura is gone or 14168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // is in the process of shutting down because neither the view window nor 14178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // this window can handle key events. 14188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( 14198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) web_contents_->GetRenderWidgetHostView()); 14208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (view != NULL && !view->IsClosing()) 14218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return true; 14228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 14238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return false; 14245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::OnCaptureLost() { 14275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::OnPaint(gfx::Canvas* canvas) { 14305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::OnDeviceScaleFactorChanged( 14335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float device_scale_factor) { 14345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1436a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WebContentsViewAura::OnWindowDestroying(aura::Window* window) { 14372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This means the destructor is going to be called soon. If there is an 14382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // overscroll gesture in progress (i.e. |overscroll_window_| is not NULL), 14392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // then destroying it in the WebContentsViewAura destructor can trigger other 14402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So 14412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // destroy the overscroll window here. 14422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) navigation_overlay_.reset(); 14432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) overscroll_window_.reset(); 14445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1446a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { 14475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { 14505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool WebContentsViewAura::HasHitTestMask() const { 14535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return false; 14545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const { 14575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 14605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContentsViewAura, ui::EventHandler implementation: 14615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::OnKeyEvent(ui::KeyEvent* event) { 14635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void WebContentsViewAura::OnMouseEvent(ui::MouseEvent* event) { 14665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!web_contents_->GetDelegate()) 14672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return; 14685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) switch (event->type()) { 14705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ui::ET_MOUSE_PRESSED: 14715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetDelegate()->ActivateContents(web_contents_); 14725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 14735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) case ui::ET_MOUSE_MOVED: 14747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch case ui::ET_MOUSE_EXITED: 14755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetDelegate()->ContentsMouseEvent( 14765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_, 14775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 14787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch event->type() == ui::ET_MOUSE_MOVED); 14795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 14805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default: 14815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 14825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 14835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 14845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//////////////////////////////////////////////////////////////////////////////// 14865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContentsViewAura, aura::client::DragDropDelegate implementation: 14875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 14885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) { 1489cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) current_rvh_for_drag_ = web_contents_->GetRenderViewHost(); 1490eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch current_drop_data_.reset(new DropData()); 14915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1492eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch PrepareDropData(current_drop_data_.get(), event.data()); 1493f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); 14945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1495cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Give the delegate an opportunity to cancel the drag. 1496116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (web_contents_->GetDelegate() && 1497116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch !web_contents_->GetDelegate()->CanDragEnter( 1498116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch web_contents_, *current_drop_data_.get(), op)) { 1499cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) current_drop_data_.reset(NULL); 1500cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return; 1501cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 1502cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1503cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (drag_dest_delegate_) 1504cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) drag_dest_delegate_->DragInitialize(web_contents_); 1505cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 15065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point screen_pt = 15075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); 15085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetRenderViewHost()->DragTargetDragEnter( 15095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *current_drop_data_.get(), event.location(), screen_pt, op, 15105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 15115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (drag_dest_delegate_) { 15135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_dest_delegate_->OnReceiveDragData(event.data()); 15145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_dest_delegate_->OnDragEnter(); 15155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 15165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) { 15195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(current_rvh_for_drag_); 15205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) 15215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OnDragEntered(event); 15225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1523cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!current_drop_data_) 1524cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return ui::DragDropTypes::DRAG_NONE; 1525cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1526f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); 15275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point screen_pt = 15285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); 15295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetRenderViewHost()->DragTargetDragOver( 15305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.location(), screen_pt, op, 15315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 15325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (drag_dest_delegate_) 15345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_dest_delegate_->OnDragOver(); 15355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return ConvertFromWeb(current_drag_op_); 15375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void WebContentsViewAura::OnDragExited() { 15405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(current_rvh_for_drag_); 15415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) 15425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 15435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1544cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!current_drop_data_) 1545cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return; 1546cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 15475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetRenderViewHost()->DragTargetDragLeave(); 15485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (drag_dest_delegate_) 15495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_dest_delegate_->OnDragLeave(); 15505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_drop_data_.reset(); 15525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 15545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { 15555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DCHECK(current_rvh_for_drag_); 15565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) 15575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OnDragEntered(event); 15585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1559cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (!current_drop_data_) 1560cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return ui::DragDropTypes::DRAG_NONE; 1561cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 15625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) web_contents_->GetRenderViewHost()->DragTargetDrop( 15635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) event.location(), 15645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 15655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 15665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (drag_dest_delegate_) 15675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) drag_dest_delegate_->OnDrop(); 15685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) current_drop_data_.reset(); 15695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return ConvertFromWeb(current_drag_op_); 15705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 15715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1572cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void WebContentsViewAura::OnWindowParentChanged(aura::Window* window, 1573cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) aura::Window* parent) { 1574116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Ignore any visibility changes in the hierarchy below. 1575116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (window != window_.get() && window_->Contains(window)) 1576116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return; 1577116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1578cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // On Windows we will get called with a parent of NULL as part of the shut 1579cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // down process. As such we do only change the visibility when a parent gets 1580cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // set. 1581cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (parent) 1582116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch UpdateWebContentsVisibility(window->IsVisible()); 1583cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 1584cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1585cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, 1586cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool visible) { 1587cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Ignore any visibility changes in the hierarchy below. 1588cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) if (window != window_.get() && window_->Contains(window)) 1589cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) return; 1590cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1591116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch UpdateWebContentsVisibility(visible); 1592116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 1593116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1594116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid WebContentsViewAura::UpdateWebContentsVisibility(bool visible) { 1595116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!is_or_was_visible_) { 1596116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // We should not hide the web contents before it was shown the first time, 1597116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // since resources would immediately be destroyed and only re-created after 1598116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // content got loaded. In this state the window content is undefined and can 1599116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // show garbage. 1600116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // However - the page load mechanism requires an activation call through a 1601116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // visibility call to (re)load. 1602116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (visible) { 1603116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch is_or_was_visible_ = true; 1604116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch web_contents_->WasShown(); 1605116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 1606116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return; 1607116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 1608116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (visible) { 1609116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!web_contents_->should_normally_be_visible()) 1610116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch web_contents_->WasShown(); 1611116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } else { 1612116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (web_contents_->should_normally_be_visible()) 1613116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch web_contents_->WasHidden(); 1614116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 1615cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)} 1616cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 16175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace content 1618